From c18f94865bdec697fd5d079bbb00c9f6e611c90d Mon Sep 17 00:00:00 2001 From: Peter Date: Fri, 19 Jul 2024 12:33:10 +0200 Subject: [PATCH] Remove galachain --- apps/api/scripts/script.ts | 1 - apps/api/scripts/src/galachain.ts | 83 ------- .../app/connection-profiles/cpp-curator.json | 37 ---- .../app/connection-profiles/cpp-partner.json | 41 ---- .../app/connection-profiles/cpp-users.json | 59 ----- .../erc1155/token/list.controller.ts | 9 +- .../erc721/token/list.controller.ts | 10 +- .../app/controllers/pools/get.controller.ts | 7 - .../pools/rewards/list.controller.ts | 5 +- .../pools/rewards/post.controller.ts | 9 - .../controllers/rewards/list.controller.ts | 4 +- apps/api/src/app/jobs/updateCampaignRanks.ts | 3 +- .../20240321144151-galachain-pkey.js | 24 -- .../migrations/20240522145618-supply-limit.js | 1 - apps/api/src/app/models/Pool.ts | 1 - apps/api/src/app/models/RewardGalachain.ts | 26 --- .../src/app/models/RewardGalachainPayment.ts | 16 -- apps/api/src/app/models/index.ts | 2 - apps/api/src/app/services/AnalyticsService.ts | 25 --- apps/api/src/app/services/ERC20Service.ts | 8 +- apps/api/src/app/services/GalachainService.ts | 205 ------------------ .../src/app/services/NotificationService.ts | 13 +- apps/api/src/app/services/QuestService.ts | 8 +- .../app/services/RewardGalachainService.ts | 154 ------------- apps/api/src/app/services/RewardService.ts | 19 +- apps/api/src/app/services/index.ts | 2 - .../app/services/interfaces/IGalaService.ts | 26 --- apps/api/src/app/util/galachain.ts | 48 ---- apps/api/src/app/util/index.ts | 1 + apps/api/src/app/util/promise.ts | 15 ++ apps/app/components.d.ts | 2 - .../src/components/card/BaseCardGalachain.vue | 35 --- .../src/components/card/BaseCardReward.vue | 1 - .../card/BaseCardRewardGalachain.vue | 21 -- .../src/components/card/BaseCardRewards.vue | 13 +- .../modal/BaseModalRewardPayment.vue | 2 +- apps/app/src/stores/Reward.ts | 5 +- apps/app/src/stores/Wallet.ts | 8 - apps/app/src/types/enums/rewards.ts | 1 - apps/app/src/types/interfaces/rewards.d.ts | 16 -- apps/app/src/types/interfaces/wallet.d.ts | 1 - apps/app/src/views/campaign/Quests.vue | 3 - apps/app/src/views/campaign/Rewards.vue | 3 - libs/common/src/lib/enums/RewardVariant.ts | 1 - libs/common/src/lib/types/Galachain.d.ts | 13 -- libs/common/src/lib/types/Pool.d.ts | 1 - libs/common/src/lib/types/Reward.d.ts | 5 +- .../common/src/lib/types/RewardGalachain.d.ts | 12 - .../src/lib/types/RewardGalachainPayment.d.ts | 3 - 49 files changed, 54 insertions(+), 954 deletions(-) delete mode 100644 apps/api/scripts/src/galachain.ts delete mode 100644 apps/api/src/app/connection-profiles/cpp-curator.json delete mode 100644 apps/api/src/app/connection-profiles/cpp-partner.json delete mode 100644 apps/api/src/app/connection-profiles/cpp-users.json delete mode 100644 apps/api/src/app/migrations/20240321144151-galachain-pkey.js delete mode 100644 apps/api/src/app/models/RewardGalachain.ts delete mode 100644 apps/api/src/app/models/RewardGalachainPayment.ts delete mode 100644 apps/api/src/app/services/GalachainService.ts delete mode 100644 apps/api/src/app/services/RewardGalachainService.ts delete mode 100644 apps/api/src/app/services/interfaces/IGalaService.ts delete mode 100644 apps/api/src/app/util/galachain.ts create mode 100644 apps/api/src/app/util/promise.ts delete mode 100644 apps/app/src/components/card/BaseCardGalachain.vue delete mode 100644 apps/app/src/components/card/BaseCardRewardGalachain.vue delete mode 100644 libs/common/src/lib/types/Galachain.d.ts delete mode 100644 libs/common/src/lib/types/RewardGalachain.d.ts delete mode 100644 libs/common/src/lib/types/RewardGalachainPayment.d.ts diff --git a/apps/api/scripts/script.ts b/apps/api/scripts/script.ts index 6b41977b9..41142b4a3 100644 --- a/apps/api/scripts/script.ts +++ b/apps/api/scripts/script.ts @@ -3,7 +3,6 @@ import db from '@thxnetwork/api/util/database'; // import main from './src/veTransfer'; // import main from './src/veRewards'; // import main from './src/time'; -// import main from './src/galachain'; // import main from './src/sdk'; // import main from './src/vethx'; // import main from './src/ipfs'; diff --git a/apps/api/scripts/src/galachain.ts b/apps/api/scripts/src/galachain.ts deleted file mode 100644 index a1b34faf8..000000000 --- a/apps/api/scripts/src/galachain.ts +++ /dev/null @@ -1,83 +0,0 @@ -import { ethers } from 'ethers'; -import { AllowanceType } from '@gala-chain/api'; -import { GalachainContract, getContract } from '../../src/app/util/galachain'; -import GalachainService from '../../src/app/services/GalachainService'; -import BigNumber from 'bignumber.js'; - -const PRIVATE_KEY_ADMIN = '62172f65ecab45f423f7088128eee8946c5b3c03911cb0b061b1dd9032337271'; -const PRIVATE_KEY_DISTRIBUTOR = '096b2543a26e164e5f8887c737fe31d04734abe657416eacf0b5a52e6c5fa684'; -const PRIVATE_KEY_USER = '97093724e1748ebfa6aa2d2ec4ec68df8678423ab9a12eb2d27ddc74e35e5db9'; - -export default async function main() { - const nftClassKey = { - collection: 'Weapons', - category: 'Blades', - type: 'none', - additionalKey: 'none', - }; - // Define coin class key - const tokenInfo = { - decimals: 0, - tokenClass: nftClassKey, - name: 'Sting', - symbol: 'WBSting', - description: 'This collection holds weapons of any sort!', - image: 'https://pbs.twimg.com/profile_images/1640708099177877505/4U-ya--t_400x400.jpg', - isNonFungible: true, - maxSupply: new BigNumber(100), - }; - const profileContract = getContract(GalachainContract.PublicKeyContract); - const tokenContract = getContract(GalachainContract.GalaChainToken); - - // Generate random wallet - const walletAdmin = new ethers.Wallet(PRIVATE_KEY_ADMIN); - console.log({ walletAdmin }); - - const walletDistributor = new ethers.Wallet(PRIVATE_KEY_DISTRIBUTOR); - console.log({ walletDistributor }); - - const walletUser = new ethers.Wallet(PRIVATE_KEY_USER); - console.log({ walletUser }); - - // Register distributor - const distributor = await GalachainService.registerUser( - profileContract, - walletDistributor.publicKey, - PRIVATE_KEY_ADMIN, - ); - console.log(distributor); - - // Register user - const user = await GalachainService.registerUser(profileContract, walletUser.publicKey, PRIVATE_KEY_ADMIN); - console.log(user); - - // Admin creates an NFT - const nft = await GalachainService.create(tokenContract, tokenInfo, nftClassKey, PRIVATE_KEY_ADMIN); - console.log(nft); - - // Approve minting of maxsupply for admin - const result = await GalachainService.approve( - tokenContract, - nftClassKey, - walletDistributor.address, - 100, - AllowanceType.Mint, - PRIVATE_KEY_ADMIN, - ); - console.log(result); - - // Distributor mints 5 tokens - await GalachainService.mint(tokenContract, nftClassKey, walletDistributor.address, 5, PRIVATE_KEY_DISTRIBUTOR); - - // Get balance of tokens for distributor - const balances = (await GalachainService.balanceOf(tokenContract, nftClassKey, PRIVATE_KEY_DISTRIBUTOR)) as { - quantity: number; - }[]; - console.log(balances); - - // Balance of the user - const [balanceUser] = (await GalachainService.balanceOf(tokenContract, nftClassKey, PRIVATE_KEY_USER)) as { - quantity: number; - }[]; - console.log(balanceUser); -} diff --git a/apps/api/src/app/connection-profiles/cpp-curator.json b/apps/api/src/app/connection-profiles/cpp-curator.json deleted file mode 100644 index 36719936d..000000000 --- a/apps/api/src/app/connection-profiles/cpp-curator.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "name": "test-network-CuratorOrg", - "version": "1.0.0", - "client": { - "organization": "CuratorOrg" - }, - "organizations": { - "CuratorOrg": { - "mspid": "CuratorOrg", - "peers": ["peer0.curator.local"], - "certificateAuthorities": ["ca.curator.local"] - } - }, - "peers": { - "peer0.curator.local": { - "url": "grpcs://localhost:7041", - "tlsCACerts": { - "path": "/Users/peterpolman/Sites/galachain/test-network/fablo-target/fabric-config/crypto-config/peerOrganizations/curator.local/peers/peer0.curator.local/tls/ca.crt" - }, - "grpcOptions": { - "ssl-target-name-override": "peer0.curator.local" - } - } - }, - "certificateAuthorities": { - "ca.curator.local": { - "url": "https://localhost:7040", - "caName": "ca.curator.local", - "tlsCACerts": { - "path": "/Users/peterpolman/Sites/galachain/test-network/fablo-target/fabric-config/crypto-config/peerOrganizations/curator.local/peers/ca.curator.local/tls/ca.crt" - }, - "httpOptions": { - "verify": false - } - } - } -} diff --git a/apps/api/src/app/connection-profiles/cpp-partner.json b/apps/api/src/app/connection-profiles/cpp-partner.json deleted file mode 100644 index 4afcd6ebc..000000000 --- a/apps/api/src/app/connection-profiles/cpp-partner.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "name": "test-network-PartnerOrg1", - "version": "1.0.0", - "client": { - "organization": "PartnerOrg1" - }, - "organizations": { - "PartnerOrg1": { - "mspid": "PartnerOrg1", - "peers": [ - "peer0.partner1.local" - ], - "certificateAuthorities": [ - "ca.partner1.local" - ] - } - }, - "peers": { - "peer0.partner1.local": { - "url": "grpcs://localhost:7061", - "tlsCACerts": { - "path": "/Users/peterpolman/Sites/galachain/test-network/fablo-target/fabric-config/crypto-config/peerOrganizations/partner1.local/peers/peer0.partner1.local/tls/ca.crt" - }, - "grpcOptions": { - "ssl-target-name-override": "peer0.partner1.local" - } - } - }, - "certificateAuthorities": { - "ca.partner1.local": { - "url": "https://localhost:7060", - "caName": "ca.partner1.local", - "tlsCACerts": { - "path": "/Users/peterpolman/Sites/galachain/test-network/fablo-target/fabric-config/crypto-config/peerOrganizations/partner1.local/peers/ca.partner1.local/tls/ca.crt" - }, - "httpOptions": { - "verify": false - } - } - } -} \ No newline at end of file diff --git a/apps/api/src/app/connection-profiles/cpp-users.json b/apps/api/src/app/connection-profiles/cpp-users.json deleted file mode 100644 index f95a21cca..000000000 --- a/apps/api/src/app/connection-profiles/cpp-users.json +++ /dev/null @@ -1,59 +0,0 @@ -{ - "name": "test-network-UsersOrg1", - "version": "1.0.0", - "client": { - "organization": "UsersOrg1" - }, - "organizations": { - "CuratorOrg": { - "mspid": "CuratorOrg", - "peers": [ - "peer0.curator.local" - ] - }, - "PartnerOrg1": { - "mspid": "PartnerOrg1", - "peers": [ - "peer0.partner1.local" - ] - }, - "UsersOrg1": { - "mspid": "UsersOrg1", - "certificateAuthorities": [ - "ca.users1.local" - ] - } - }, - "peers": { - "peer0.curator.local": { - "url": "grpcs://localhost:7041", - "tlsCACerts": { - "path": "/Users/peterpolman/Sites/galachain/test-network/fablo-target/fabric-config/crypto-config/peerOrganizations/curator.local/peers/peer0.curator.local/tls/ca.crt" - }, - "grpcOptions": { - "ssl-target-name-override": "peer0.curator.local" - } - }, - "peer0.partner1.local": { - "url": "grpcs://localhost:7061", - "tlsCACerts": { - "path": "/Users/peterpolman/Sites/galachain/test-network/fablo-target/fabric-config/crypto-config/peerOrganizations/partner1.local/peers/peer0.partner1.local/tls/ca.crt" - }, - "grpcOptions": { - "ssl-target-name-override": "peer0.partner1.local" - } - } - }, - "certificateAuthorities": { - "ca.users1.local": { - "url": "https://localhost:7080", - "caName": "ca.users1.local", - "tlsCACerts": { - "path": "/Users/peterpolman/Sites/galachain/test-network/fablo-target/fabric-config/crypto-config/peerOrganizations/users1.local/peers/ca.users1.local/tls/ca.crt" - }, - "httpOptions": { - "verify": false - } - } - } -} \ No newline at end of file diff --git a/apps/api/src/app/controllers/erc1155/token/list.controller.ts b/apps/api/src/app/controllers/erc1155/token/list.controller.ts index 866f8022a..cdf24d8d9 100644 --- a/apps/api/src/app/controllers/erc1155/token/list.controller.ts +++ b/apps/api/src/app/controllers/erc1155/token/list.controller.ts @@ -2,6 +2,7 @@ import { Request, Response } from 'express'; import { ERC1155Token, ERC1155TokenDocument } from '@thxnetwork/api/models/ERC1155Token'; import { query } from 'express-validator'; import { BadRequestError } from '@thxnetwork/api/util/errors'; +import { PromiseParser } from '@thxnetwork/api/util'; import SafeService from '@thxnetwork/api/services/SafeService'; import ERC1155Service from '@thxnetwork/api/services/ERC1155Service'; @@ -13,7 +14,7 @@ const controller = async (req: Request, res: Response) => { if (!wallet) throw new BadRequestError('Wallet not found'); const tokens = await ERC1155Token.find({ walletId: wallet._id, chainId }); - const results = await Promise.allSettled( + const results = await PromiseParser.parse( tokens.map(async (token: ERC1155TokenDocument) => { const erc1155 = await ERC1155Service.findById(token.erc1155Id); if (!erc1155) throw new BadRequestError('ERC1155 not found'); @@ -24,12 +25,8 @@ const controller = async (req: Request, res: Response) => { return Object.assign(token.toJSON() as TERC1155Token, { metadata, nft: erc1155 }); }), ); - const response = results - .reverse() - .filter((result) => result.status === 'fulfilled') - .map((result: any) => result.value); - res.json(response); + res.json(results.reverse()); }; export { controller, validation }; diff --git a/apps/api/src/app/controllers/erc721/token/list.controller.ts b/apps/api/src/app/controllers/erc721/token/list.controller.ts index 40a67ea8b..a12b04f4b 100644 --- a/apps/api/src/app/controllers/erc721/token/list.controller.ts +++ b/apps/api/src/app/controllers/erc721/token/list.controller.ts @@ -4,6 +4,7 @@ import { ERC721Token, ERC721TokenDocument, ERC721Metadata } from '@thxnetwork/ap import { BadRequestError } from '@thxnetwork/api/util/errors'; import ERC721Service from '@thxnetwork/api/services/ERC721Service'; import SafeService from '@thxnetwork/api/services/SafeService'; +import { PromiseParser } from '@thxnetwork/api/util'; const validation = [query('walletId').isMongoId(), query('chainId').isInt()]; @@ -13,7 +14,7 @@ const controller = async (req: Request, res: Response) => { if (!wallet) throw new BadRequestError('Wallet not found'); const tokens = await ERC721Token.find({ walletId: wallet.id, chainId }); - const results = await Promise.allSettled( + const results = await PromiseParser.parse( tokens.map(async (token: ERC721TokenDocument) => { const erc721 = await ERC721Service.findById(token.erc721Id); if (!erc721) return; @@ -25,12 +26,7 @@ const controller = async (req: Request, res: Response) => { }), ); - const response = results - .reverse() - .filter((result) => result.status === 'fulfilled') - .map((result: any) => result.value); - - res.json(response); + res.json(results.reverse()); }; export { controller, validation }; diff --git a/apps/api/src/app/controllers/pools/get.controller.ts b/apps/api/src/app/controllers/pools/get.controller.ts index b1f506698..93dd2a3c7 100644 --- a/apps/api/src/app/controllers/pools/get.controller.ts +++ b/apps/api/src/app/controllers/pools/get.controller.ts @@ -1,7 +1,6 @@ import { Request, Response } from 'express'; import { param } from 'express-validator'; import { Participant, Widget, Wallet, Event, Identity } from '@thxnetwork/api/models'; -import { ethers } from 'ethers'; import PoolService from '@thxnetwork/api/services/PoolService'; import BrandService from '@thxnetwork/api/services/BrandService'; @@ -10,12 +9,6 @@ const validation = [param('id').isMongoId()]; const controller = async (req: Request, res: Response) => { const pool = await PoolService.getById(req.params.id); - // Create a galachain private key if none exists - if (!pool.settings.galachainPrivateKey) { - const privateKey = ethers.Wallet.createRandom().privateKey; - await pool.updateOne({ 'settings.galachainPrivateKey': privateKey }); - } - // Fetch all other campaign entities const [widget, brand, wallets, collaborators, owner, events, identities, subscriberCount] = await Promise.all([ Widget.findOne({ poolId: req.params.id }), diff --git a/apps/api/src/app/controllers/pools/rewards/list.controller.ts b/apps/api/src/app/controllers/pools/rewards/list.controller.ts index 41cd8c959..c6283cd95 100644 --- a/apps/api/src/app/controllers/pools/rewards/list.controller.ts +++ b/apps/api/src/app/controllers/pools/rewards/list.controller.ts @@ -7,14 +7,12 @@ import { RewardCoin, RewardDiscordRole, RewardCustom, - RewardGalachain, ERC20, ERC721, ERC1155, } from '@thxnetwork/api/models'; -import { ChainId, RewardVariant } from '@thxnetwork/common/enums'; +import { RewardVariant } from '@thxnetwork/common/enums'; import PoolService from '@thxnetwork/api/services/PoolService'; -import ERC20Service from '@thxnetwork/api/services/ERC20Service'; import SafeService from '@thxnetwork/api/services/SafeService'; const validation = [ @@ -39,7 +37,6 @@ const controller = async (req: Request, res: Response) => { { $unionWith: { coll: RewardCoupon.collection.name } }, { $unionWith: { coll: RewardCustom.collection.name } }, { $unionWith: { coll: RewardDiscordRole.collection.name } }, - { $unionWith: { coll: RewardGalachain.collection.name } }, { $match }, ]; const arr = await Promise.all( diff --git a/apps/api/src/app/controllers/pools/rewards/post.controller.ts b/apps/api/src/app/controllers/pools/rewards/post.controller.ts index aeb30d571..b133b5437 100644 --- a/apps/api/src/app/controllers/pools/rewards/post.controller.ts +++ b/apps/api/src/app/controllers/pools/rewards/post.controller.ts @@ -32,15 +32,6 @@ const validationBaseQuest = [ body('metadata').optional().isString(), // DiscordRole body('discordRoleId').optional().isString(), - // Galachain - body('contractChannelName').optional().isString(), - body('contractChaincodeName').optional().isString(), - body('contractContractName').optional().isString(), - body('tokenCollection').optional().isString(), - body('tokenCategory').optional().isString(), - body('tokenType').optional().isString(), - body('tokenAdditionalKey').optional().isString(), - body('amount').optional().isInt({ gt: 0 }), ]; const validation = [param('id').isMongoId(), ...validationBaseQuest]; diff --git a/apps/api/src/app/controllers/rewards/list.controller.ts b/apps/api/src/app/controllers/rewards/list.controller.ts index a8815d7ab..17cd22022 100644 --- a/apps/api/src/app/controllers/rewards/list.controller.ts +++ b/apps/api/src/app/controllers/rewards/list.controller.ts @@ -11,12 +11,12 @@ const controller = async (req: Request, res: Response) => { const pool = await PoolService.getById(req.header('X-PoolId')); const account = sub && (await AccountProxy.findById(sub)); - const [coin, nft, custom, coupon, discordRole, galachain] = await RewardService.list({ + const [coin, nft, custom, coupon, discordRole] = await RewardService.list({ pool, account, }); - res.json({ coin, nft, custom, coupon, discordRole, galachain }); + res.json({ coin, nft, custom, coupon, discordRole }); }; export { controller }; diff --git a/apps/api/src/app/jobs/updateCampaignRanks.ts b/apps/api/src/app/jobs/updateCampaignRanks.ts index a34e1fe71..6e957c067 100644 --- a/apps/api/src/app/jobs/updateCampaignRanks.ts +++ b/apps/api/src/app/jobs/updateCampaignRanks.ts @@ -5,7 +5,6 @@ import { RewardCustom, RewardCoupon, RewardDiscordRole, - RewardGalachain, QuestDaily, QuestInvite, QuestSocial, @@ -19,7 +18,7 @@ import { logger } from '../util/logger'; export async function updateCampaignRanks() { try { const questModels = [QuestDaily, QuestInvite, QuestSocial, QuestCustom, QuestWeb3, QuestGitcoin]; - const rewardModels = [RewardCoin, RewardNFT, RewardCustom, RewardCoupon, RewardDiscordRole, RewardGalachain]; + const rewardModels = [RewardCoin, RewardNFT, RewardCustom, RewardCoupon, RewardDiscordRole]; const questLookupStages = questModels.map((model) => { return { $lookup: { diff --git a/apps/api/src/app/migrations/20240321144151-galachain-pkey.js b/apps/api/src/app/migrations/20240321144151-galachain-pkey.js deleted file mode 100644 index ebae8457a..000000000 --- a/apps/api/src/app/migrations/20240321144151-galachain-pkey.js +++ /dev/null @@ -1,24 +0,0 @@ -const { ethers } = require('ethers'); - -module.exports = { - async up(db, client) { - const poolsColl = db.collection('pool'); - const pools = await (await poolsColl.find({})).toArray(); - const operations = pools.map((pool) => { - const privateKey = ethers.Wallet.createRandom().privateKey; - return { - updateOne: { - filter: { _id: pool._id }, - update: { - $set: { 'settings.galachainPrivateKey': privateKey }, - }, - }, - }; - }); - await poolsColl.bulkWrite(operations); - }, - - async down(db, client) { - // - }, -}; diff --git a/apps/api/src/app/migrations/20240522145618-supply-limit.js b/apps/api/src/app/migrations/20240522145618-supply-limit.js index 067c34220..f24205c88 100644 --- a/apps/api/src/app/migrations/20240522145618-supply-limit.js +++ b/apps/api/src/app/migrations/20240522145618-supply-limit.js @@ -5,7 +5,6 @@ module.exports = { await db.collection('rewardcoupon').updateMany({}, [{ $set: { limitSupply: '$limit', limit: 0 } }]); await db.collection('rewardcustom').updateMany({}, [{ $set: { limitSupply: '$limit', limit: 0 } }]); await db.collection('rewarddiscordrole').updateMany({}, [{ $set: { limitSupply: '$limit', limit: 0 } }]); - await db.collection('rewardgalachain').updateMany({}, [{ $set: { limitSupply: '$limit', limit: 0 } }]); }, async down() { diff --git a/apps/api/src/app/models/Pool.ts b/apps/api/src/app/models/Pool.ts index 4adea6da2..f5cb7358e 100644 --- a/apps/api/src/app/models/Pool.ts +++ b/apps/api/src/app/models/Pool.ts @@ -19,7 +19,6 @@ const schema = new mongoose.Schema( slug: String, description: String, leaderboardInWeeks: Number, - galachainPrivateKey: String, isPublished: { type: Boolean, default: false }, isWeeklyDigestEnabled: { type: Boolean, default: true }, authenticationMethods: [Number], diff --git a/apps/api/src/app/models/RewardGalachain.ts b/apps/api/src/app/models/RewardGalachain.ts deleted file mode 100644 index 75aec01c8..000000000 --- a/apps/api/src/app/models/RewardGalachain.ts +++ /dev/null @@ -1,26 +0,0 @@ -import mongoose from 'mongoose'; -import { rewardSchema } from './Reward'; -import { RewardVariant } from '@thxnetwork/common/enums'; - -export type RewardGalachainDocument = mongoose.Document & TRewardGalachain; - -export const RewardGalachain = mongoose.model( - 'RewardGalachain', - new mongoose.Schema( - { - ...rewardSchema, - variant: { type: Number, default: RewardVariant.Galachain }, - amount: String, - contractChannelName: { type: String, required: true }, - contractChaincodeName: { type: String, required: true }, - contractContractName: { type: String, required: true }, - tokenCollection: { type: String, required: true }, - tokenCategory: { type: String, required: true }, - tokenType: { type: String, required: true }, - tokenAdditionalKey: { type: String, required: true }, - tokenInstance: { type: Number, required: true }, - }, - { timestamps: true }, - ), - 'rewardgalachain', -); diff --git a/apps/api/src/app/models/RewardGalachainPayment.ts b/apps/api/src/app/models/RewardGalachainPayment.ts deleted file mode 100644 index de4bf79e6..000000000 --- a/apps/api/src/app/models/RewardGalachainPayment.ts +++ /dev/null @@ -1,16 +0,0 @@ -import mongoose from 'mongoose'; -import { rewardPaymentSchema } from './Reward'; - -export type RewardGalachainPaymentDocument = mongoose.Document & TRewardGalachainPayment; - -export const RewardGalachainPayment = mongoose.model( - 'RewardGalachainPayment', - new mongoose.Schema( - { - ...rewardPaymentSchema, - amount: String, - }, - { timestamps: true }, - ), - 'rewardgalachainpayment', -); diff --git a/apps/api/src/app/models/index.ts b/apps/api/src/app/models/index.ts index 2157fa93f..543c02fb7 100644 --- a/apps/api/src/app/models/index.ts +++ b/apps/api/src/app/models/index.ts @@ -48,8 +48,6 @@ export { RewardDiscordRole, RewardDiscordRoleDocument } from './RewardDiscordRol export { RewardDiscordRolePayment, RewardDiscordRolePaymentDocument } from './RewardDiscordRolePayment'; export { RewardNFT, RewardNFTDocument } from './RewardNFT'; export { RewardNFTPayment, RewardNFTPaymentDocument } from './RewardNFTPayment'; -export { RewardGalachain, RewardGalachainDocument } from './RewardGalachain'; -export { RewardGalachainPayment, RewardGalachainPaymentDocument } from './RewardGalachainPayment'; export { Transaction, TransactionDocument } from './Transaction'; export { TwitterFollower, TwitterFollowerDocument } from './TwitterFollower'; export { TwitterLike, TwitterLikeDocument } from './TwitterLike'; diff --git a/apps/api/src/app/services/AnalyticsService.ts b/apps/api/src/app/services/AnalyticsService.ts index c2660db02..9c1cd3f99 100644 --- a/apps/api/src/app/services/AnalyticsService.ts +++ b/apps/api/src/app/services/AnalyticsService.ts @@ -31,10 +31,7 @@ import { QuestDaily, QuestGitcoin, QuestGitcoinEntry, - RewardGalachainDocument, - RewardGalachain, QuestGitcoinDocument, - RewardGalachainPayment, QuestWebhookEntry, QuestWebhook, QuestWebhookDocument, @@ -46,10 +43,6 @@ import { logger } from '../util/logger'; class AnalyticsService { public leaderboards: { [poolId: string]: TLeaderboardEntry[] } = {}; - constructor() { - // - } - // Triggered when a quest entry is added async updateLeaderboardJob(job: TJob) { logger.debug('UpdateLeaderboard Start', job.attrs.data); @@ -152,7 +145,6 @@ class AnalyticsService { customRewardsQueryResult, couponRewardsQueryResult, discordRoleRewardsQueryResult, - galachainRewardsQueryResult, ] = await Promise.all([ this.queryRewardRedemptions({ collectionName: 'rewardcoinpayment', @@ -194,14 +186,6 @@ class AnalyticsService { startDate, endDate, }), - this.queryRewardRedemptions({ - collectionName: 'rewargalachainpayment', - key: 'rewardId', - model: RewardGalachain, - poolId: String(pool._id), - startDate, - endDate, - }), ]); // Quests @@ -306,12 +290,6 @@ class AnalyticsService { totalAmount: x.total_amount, }; }), - galachainRewards: galachainRewardsQueryResult.map((x) => { - return { - day: x._id, - totalAmount: x.total_amount, - }; - }), // dailyRewards: dailyRewardsQueryResult.map((x) => { return { @@ -373,7 +351,6 @@ class AnalyticsService { RewardCustomPayment, RewardCouponPayment, RewardDiscordRolePayment, - RewardGalachainPayment, ]; const [ dailyQuest, @@ -388,7 +365,6 @@ class AnalyticsService { customReward, couponReward, discordRoleReward, - galachainReward, ] = await Promise.all( collections.map(async (Model) => { const $match = { poolId: String(pool._id) }; @@ -444,7 +420,6 @@ class AnalyticsService { customReward, couponReward, discordRoleReward, - galachainReward, }; } diff --git a/apps/api/src/app/services/ERC20Service.ts b/apps/api/src/app/services/ERC20Service.ts index 74c334a1c..887228560 100644 --- a/apps/api/src/app/services/ERC20Service.ts +++ b/apps/api/src/app/services/ERC20Service.ts @@ -19,6 +19,7 @@ import { import TransactionService from './TransactionService'; import PoolService from './PoolService'; import { fromWei } from 'web3-utils'; +import { PromiseParser } from '@thxnetwork/api/util'; async function decorate(token: ERC20TokenDocument, wallet: WalletDocument) { const erc20 = await getById(token.erc20Id); @@ -153,8 +154,7 @@ export const getTokensForSub = (sub: string) => { export const getTokensForWallet = async (wallet: WalletDocument, chainId: ChainId) => { const tokens = await ERC20Token.find({ sub: wallet.sub, walletId: wallet.id }); - const result = await Promise.allSettled(tokens.map((token) => decorate(token, wallet))); - const erc20Tokens = result.filter((r) => r.status === 'fulfilled').map((r: any) => r.value); + const erc20Tokens = await PromiseParser.parse(tokens.map((token) => decorate(token, wallet))); // We add additional veTHX related tokens for Polygon and Hardhat const defaults = await findDefaultTokens(wallet, chainId); @@ -291,7 +291,7 @@ async function findDefaultTokens(wallet: WalletDocument, chainId: ChainId) { }, ]; - const promise = await Promise.allSettled( + return await PromiseParser.parse( defaultContracts.map(async (erc20) => { const { web3 } = NetworkService.getProvider(erc20.chainId); const contract = new web3.eth.Contract(getArtifact('THXERC20_LimitedSupply').abi, erc20.address); @@ -306,8 +306,6 @@ async function findDefaultTokens(wallet: WalletDocument, chainId: ChainId) { }; }), ); - - return promise.filter((r) => r.status === 'fulfilled').map((r: any) => r.value); } export default { diff --git a/apps/api/src/app/services/GalachainService.ts b/apps/api/src/app/services/GalachainService.ts deleted file mode 100644 index 228f55a20..000000000 --- a/apps/api/src/app/services/GalachainService.ts +++ /dev/null @@ -1,205 +0,0 @@ -import axios from 'axios'; -import { instanceToPlain, plainToInstance } from 'class-transformer'; -import { BigNumber } from 'bignumber.js'; -import { logger } from '../util/logger'; -import { BadRequestError } from '../util/errors'; -import { - ChainCallDTO, - TokenInstance, - TokenClassKey, - TokenInstanceKey, - createValidDTO, - CreateTokenClassDto, - GalaChainResponse, - GetMyProfileDto, - MintTokenDto, - GrantAllowanceDto, - AllowanceType, - FetchBalancesDto, - TransferTokenDto, - RegisterUserDto, -} from '@gala-chain/api'; -import { GalachainRole, getClient } from '../util/galachain'; -import { Wallet } from 'ethers'; -import { NODE_ENV } from '../config/secrets'; - -const GALACHAIN_URL = 'https://gateway.stage.galachain.com/api'; -const identityKey = (address: string) => `eth|${address.replace(/^0x/, '')}`; - -export default class GalachainService { - static evaluateTransaction( - methodName: string, - contract: TGalachainContract, - dto: ChainCallDTO, - privateKey: string, - ) { - const methodMap = { - development: this.evaluateTransactionLocal.bind(this), - production: this.submitTransactonREST.bind(this), - }; - return methodMap[NODE_ENV](methodName, contract, dto, privateKey); - } - - static submitTransaction(methodName: string, contract: TGalachainContract, dto: ChainCallDTO, privateKey: string) { - const methodMap = { - development: this.submitTransactionLocal.bind(this), - production: this.submitTransactonREST.bind(this), - }; - return methodMap[NODE_ENV](methodName, contract, dto, privateKey); - } - - static async evaluateTransactionLocal( - methodName: string, - contract: TGalachainContract, - dto: ChainCallDTO, - privateKey: string, - ) { - const client = getClient(GalachainRole.Curator); // TODO Make this dynamic - const response = await client.forContract(contract).evaluateTransaction(methodName, dto.signed(privateKey)); - - if (GalaChainResponse.isError(response)) { - throw new Error(`${response.Message} (${response.ErrorKey})`); - } else { - return response.Data; - } - } - - static async submitTransactionLocal( - methodName: string, - contract: TGalachainContract, - dto: ChainCallDTO, - privateKey: string, - ) { - const client = getClient(GalachainRole.Curator); // TODO Make this dynamic - const response = await client.forContract(contract).submitTransaction(methodName, dto.signed(privateKey)); - - if (GalaChainResponse.isError(response)) { - throw new BadRequestError(`${response.Message} (${response.ErrorKey})`); - } else { - return response.Data; - } - } - - static async submitTransactonREST( - methodName: string, - contract: TGalachainContract, - dto: ChainCallDTO, - privateKey: string, - ) { - const signedDto = dto.signed(privateKey); - const url = new URL(GALACHAIN_URL); - url.pathname = `${url.pathname}/${contract.channelName}/${contract.chaincodeName}-${contract.contractName}/${methodName}`; - - try { - const res = await axios({ - method: 'POST', - url: url.toString(), - headers: {}, - data: instanceToPlain(signedDto), - }); - return res.data; - } catch (error) { - logger.error(error.response.data); - throw new BadRequestError(error.response.data.message); - } - } - - static getProfile(contract: TGalachainContract, privateKey: string) { - const dto = new GetMyProfileDto().signed(privateKey, false); - return this.evaluateTransaction('GetMyProfile', contract, dto, privateKey); - } - - static registerUser(contract: TGalachainContract, publicKey: string, privateKey: string) { - const dto = new RegisterUserDto(); - dto.publicKey = publicKey; - dto.sign(privateKey, false); - - return this.submitTransaction('RegisterEthUser', contract, dto, privateKey); - } - - static async balanceOf(contract: TGalachainContract, tokenClassKey: TGalachainToken, privateKey: string) { - const tokenClass = plainToInstance(TokenInstanceKey, tokenClassKey); - const owner = new Wallet(privateKey).address; - const dto = await createValidDTO(FetchBalancesDto, { - owner: identityKey(owner), - ...tokenClass, - }); - return this.evaluateTransaction('FetchBalances', contract, dto, privateKey); - } - - static async create( - contract: TGalachainContract, - tokenInfo: { - image: string; - name: string; - description: string; - symbol: string; - decimals: number; - maxSupply: any; - }, - tokenClassKey: TGalachainToken, - privateKey: string, - ) { - const tokenClass = plainToInstance(TokenClassKey, tokenClassKey); - const dto = await createValidDTO(CreateTokenClassDto, { - tokenClass, - ...tokenInfo, - }); - - return this.submitTransaction('CreateTokenClass', contract, dto, privateKey); - } - - static async mint( - contract: TGalachainContract, - tokenClassKey: TGalachainToken, - to: string, - amount: number, - privateKey: string, - ) { - const tokenClass = plainToInstance(TokenClassKey, tokenClassKey); - const dto = await createValidDTO(MintTokenDto, { - owner: identityKey(to), - tokenClass, - quantity: new BigNumber(amount) as any, - }); - - return this.submitTransaction('MintToken', contract, dto, privateKey); - } - - static async approve( - contract: TGalachainContract, - tokenClassKey: TGalachainToken, - spender: string, - amount: number, - allowanceType: AllowanceType, - privateKey: string, - ) { - const dto = await createValidDTO(GrantAllowanceDto, { - tokenInstance: TokenInstanceKey.nftKey(tokenClassKey, TokenInstance.FUNGIBLE_TOKEN_INSTANCE).toQueryKey(), - allowanceType, - quantities: [{ user: identityKey(spender), quantity: new BigNumber(amount) as any }], - uses: new BigNumber(amount) as any, - }); - - return this.submitTransaction('GrantAllowance', contract, dto, privateKey); - } - - static async transfer( - contract: TGalachainContract, - tokenClassKey: TGalachainToken, - to: string, - amount: number, - instance: BigNumber, - privateKey: string, - ) { - const tokenInstance = plainToInstance(TokenInstanceKey, { ...tokenClassKey, instance }); - const dto = await createValidDTO(TransferTokenDto, { - from: identityKey(new Wallet(privateKey).address), - to: identityKey(to), - tokenInstance, - quantity: new BigNumber(amount) as any, - }); - - return this.submitTransaction('TransferToken', contract, dto, privateKey); - } -} diff --git a/apps/api/src/app/services/NotificationService.ts b/apps/api/src/app/services/NotificationService.ts index 12a40cdee..a3b7121c8 100644 --- a/apps/api/src/app/services/NotificationService.ts +++ b/apps/api/src/app/services/NotificationService.ts @@ -255,7 +255,6 @@ export async function sendWeeklyDigestJob() { customReward, couponReward, discordRoleReward, - galachainReward, } = await AnalyticsService.getPoolMetrics(pool, options); const leaderboardCache = await PoolService.getLeaderboardFromCache(pool, options); @@ -266,14 +265,10 @@ export async function sendWeeklyDigestJob() { 0, ); - const paymentCount = [ - coinReward, - nftReward, - customReward, - couponReward, - discordRoleReward, - galachainReward, - ].reduce((acc, payment) => acc + payment.totalCreated, 0); + const paymentCount = [coinReward, nftReward, customReward, couponReward, discordRoleReward].reduce( + (acc, payment) => acc + payment.totalCreated, + 0, + ); // Skip if nothing happened. if (!entryCount && !paymentCount) continue; diff --git a/apps/api/src/app/services/QuestService.ts b/apps/api/src/app/services/QuestService.ts index ebdcf0961..a70bdbfbc 100644 --- a/apps/api/src/app/services/QuestService.ts +++ b/apps/api/src/app/services/QuestService.ts @@ -15,6 +15,7 @@ import ImageService from './ImageService'; import AccountProxy from '../proxies/AccountProxy'; import ParticipantService from './ParticipantService'; import THXService from './THXService'; +import { PromiseParser } from '../util/promise'; export default class QuestService { static async count({ poolId }) { @@ -259,8 +260,9 @@ export default class QuestService { const subs = entries.map((entry) => entry.sub); const accounts = await AccountProxy.find({ subs }); const participants = await Participant.find({ poolId: quest.poolId }); - const promises = entries.map(async (entry) => ParticipantService.decorate(entry, { accounts, participants })); - const results = await Promise.allSettled(promises); + const results = await PromiseParser.parse( + entries.map(async (entry) => ParticipantService.decorate(entry, { accounts, participants })), + ); const meta = await serviceMap[quest.variant].findEntryMetadata({ quest }); return { @@ -268,7 +270,7 @@ export default class QuestService { limit, page, meta, - results: results.filter((result) => result.status === 'fulfilled').map((result: any) => result.value), + results, }; } } diff --git a/apps/api/src/app/services/RewardGalachainService.ts b/apps/api/src/app/services/RewardGalachainService.ts deleted file mode 100644 index d6042ebbc..000000000 --- a/apps/api/src/app/services/RewardGalachainService.ts +++ /dev/null @@ -1,154 +0,0 @@ -import { RewardGalachain, RewardGalachainPayment, WalletDocument } from '../models'; -import GalachainService from './GalachainService'; -import { IRewardService } from './interfaces/IRewardService'; -import { BigNumber } from 'bignumber.js'; -import PoolService from './PoolService'; - -export default class RewardGalachainService implements IRewardService { - models = { - reward: RewardGalachain, - payment: RewardGalachainPayment, - }; - - async decorate({ reward }: { reward: TRewardGalachain; account?: TAccount }): Promise { - const contract = { - channelName: reward.contractChannelName, - chaincodeName: reward.contractChaincodeName, - contractName: reward.contractContractName, - }; - const token = { - collection: reward.tokenCollection, - category: reward.tokenCategory, - type: reward.tokenType, - additionalKey: reward.tokenAdditionalKey, - instance: new BigNumber(0), - }; - const pool = await PoolService.getById(reward.poolId); - const [balance] = (await GalachainService.balanceOf( - contract, - token, - pool.settings.galachainPrivateKey, - )) as any[]; - const paymentCount = await this.models.payment.countDocuments({ - rewardId: reward._id, - }); - const progress = { - count: paymentCount, - limit: Number(balance.quantity) + paymentCount, - }; - - return { ...reward.toJSON(), progress, limit: balance.quantity }; - } - - async decoratePayment(payment: TRewardPayment): Promise { - const reward = await this.models.reward.findById(payment.rewardId); - return { reward, ...payment.toJSON() }; - } - - async getValidationResult({ reward }: { reward: any; account?: TAccount }): Promise { - const { tokenCollection, tokenCategory, tokenType, tokenAdditionalKey } = reward; - const token = { - collection: tokenCollection, - category: tokenCategory, - type: tokenType, - additionalKey: tokenAdditionalKey, - instance: new BigNumber(0), - }; - const contract = { - channelName: reward.contractChannelName, - chaincodeName: reward.contractChaincodeName, - contractName: reward.contractContractName, - methodName: 'TransferToken', - }; - const pool = await PoolService.getById(reward.poolId); - - // Check balance of the distributor - const [balance] = (await GalachainService.balanceOf( - contract, - token, - pool.settings.galachainPrivateKey, - )) as any[]; - - if (Number(balance.quantity) < reward.amount) { - return { result: false, reason: 'Distributor has an insufficient balance' }; - } - - return { result: true, reason: '' }; - } - - create(data: any): Promise { - return this.models.reward.create(data); - } - - update(reward: TReward, updates: Partial): Promise { - return this.models.reward.findByIdAndUpdate(reward, updates, { new: true }); - } - - remove(reward: TReward): Promise { - return this.models.reward.findByIdAndDelete(reward._id); - } - - findById(id: string) { - return this.models.reward.findById(id); - } - - async createPayment({ - reward, - wallet, - }: { - reward: TRewardGalachain; - wallet?: WalletDocument; - }): Promise { - const token = this.getToken(reward); - const contract = this.getContract(reward); - const pool = await PoolService.getById(reward.poolId); - - // Get first token from balance - const instanceId = await this.getInstance(contract, token, pool); - - // Transfer token to user wallet - await GalachainService.transfer( - contract, - token, - wallet.address, - Number(reward.amount), - instanceId, - pool.settings.galachainPrivateKey, - ); - - // Register payment - await this.models.payment.create({ - sub: wallet.sub, - walletId: wallet._id, - rewardId: reward._id, - amount: reward.amount, - }); - } - - private async getInstance(contract: TGalachainContract, token: TGalachainToken, pool: TPool) { - const [balance] = (await GalachainService.balanceOf( - contract, - token, - pool.settings.galachainPrivateKey, - )) as any[]; - const [instanceId] = balance.instanceIds; - return instanceId; - } - - private getToken(reward: TRewardGalachain) { - return { - collection: reward.tokenCollection, - category: reward.tokenCategory, - type: reward.tokenType, - additionalKey: reward.tokenAdditionalKey, - }; - } - - private getContract(reward: TRewardGalachain) { - return { - channelName: reward.contractChannelName, - chaincodeName: reward.contractChaincodeName, - contractName: reward.contractContractName, - }; - } -} diff --git a/apps/api/src/app/services/RewardService.ts b/apps/api/src/app/services/RewardService.ts index 9fbbc099a..578d48094 100644 --- a/apps/api/src/app/services/RewardService.ts +++ b/apps/api/src/app/services/RewardService.ts @@ -4,6 +4,7 @@ import { Participant, QRCodeEntry, Wallet, WalletDocument } from '@thxnetwork/ap import { v4 } from 'uuid'; import { logger } from '../util/logger'; import { Job } from '@hokify/agenda'; +import { PromiseParser } from '../util'; import RewardCoinService from './RewardCoinService'; import LockService from './LockService'; import AccountProxy from '../proxies/AccountProxy'; @@ -15,7 +16,6 @@ import PointBalanceService from './PointBalanceService'; import MailService from './MailService'; import RewardDiscordRoleService from './RewardDiscordRoleService'; import RewardCustomService from './RewardCustomService'; -import RewardGalachainService from './RewardGalachainService'; import PoolService from './PoolService'; const serviceMap = { @@ -24,7 +24,6 @@ const serviceMap = { [RewardVariant.Custom]: new RewardCustomService(), [RewardVariant.Coupon]: new RewardCouponService(), [RewardVariant.DiscordRole]: new RewardDiscordRoleService(), - [RewardVariant.Galachain]: new RewardGalachainService(), }; export default class RewardService { @@ -152,22 +151,23 @@ export default class RewardService { query.length > 3 ? await this.findPaymentsBySub(reward, { skip, limit, query }) : await this.findPaymentsByReward(reward, { skip, limit, query }); - const promises = payments.map(async (payment: Document & TRewardPayment) => - ParticipantService.decorate(payment, { accounts, participants }), + const results = await PromiseParser.parse( + payments.map(async (payment: Document & TRewardPayment) => + ParticipantService.decorate(payment, { accounts, participants }), + ), ); - const results = await Promise.allSettled(promises); return { total, limit, page, - results: results.filter((result) => result.status === 'fulfilled').map((result: any) => result.value), + results, }; } static async findPaymentsForSub(sub: string) { const rewardVariants: string[] = Object.keys(RewardVariant).filter((v) => !isNaN(Number(v))); - const payments = await Promise.allSettled( + const payments = await PromiseParser.parse( rewardVariants.map(async (variant: string) => { const rewardVariant = Number(variant); const payments = await serviceMap[rewardVariant].models.payment.find({ sub }); @@ -178,10 +178,7 @@ export default class RewardService { return await Promise.all(callback); }), ); - return payments - .filter((result) => result.status === 'fulfilled') - .map((result: any) => result.value) - .flat(); + return payments.flat(); } static async createPaymentJob(job: Job) { diff --git a/apps/api/src/app/services/index.ts b/apps/api/src/app/services/index.ts index 782d6af6f..f587d3a33 100644 --- a/apps/api/src/app/services/index.ts +++ b/apps/api/src/app/services/index.ts @@ -8,7 +8,6 @@ export * as DiscordService from './DiscordService'; export * as ERC1155Service from './ERC1155Service'; export * as ERC20Service from './ERC20Service'; export * as ERC721Service from './ERC721Service'; -export * as GalachainService from './GalachainService'; export * as GitcoinService from './GitcoinService'; export * as IPFSService from './IPFSService'; export * as IdentityService from './IdentityService'; @@ -36,7 +35,6 @@ export * as RewardCoinService from './RewardCoinService'; export * as RewardCouponService from './RewardCouponService'; export * as RewardCustomService from './RewardCustomService'; export * as RewardDiscordRoleService from './RewardDiscordRoleService'; -export * as RewardGalachainService from './RewardGalachainService'; export * as RewardNFTService from './RewardNFTService'; export * as RewardService from './RewardService'; export * as SafeService from './SafeService'; diff --git a/apps/api/src/app/services/interfaces/IGalaService.ts b/apps/api/src/app/services/interfaces/IGalaService.ts deleted file mode 100644 index 67731f3cd..000000000 --- a/apps/api/src/app/services/interfaces/IGalaService.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { TokenInstanceKey, TokenClassKey, RegisterUserDto, UserProfile } from '@gala-chain/api'; - -interface CustomProfileAPI { - GetProfile(privateKey: string): Promise; - RegisterEthUser(publicKey: string): Promise; -} - -interface CustomTokenAPI { - CoinBalanceOf({ tokenInstance, owner }: { tokenInstance: TokenInstanceKey; owner: string }): Promise; - CoinCreate( - tokenInfo: { - image: string; - name: string; - description: string; - symbol: string; - decimals: number; - maxSupply: any; - }, - privateKey: string, - ): Promise; - CoinApprove(options: { spender: string; amount: number }, privateKey: string): Promise; - CoinMint(options: { to: string; amount: number }, privateKey: string): Promise; - CoinTransfer(options: { to: string; amount: number }, privateKey: string): Promise; -} - -export { CustomProfileAPI, CustomTokenAPI }; diff --git a/apps/api/src/app/util/galachain.ts b/apps/api/src/app/util/galachain.ts deleted file mode 100644 index 1f6593422..000000000 --- a/apps/api/src/app/util/galachain.ts +++ /dev/null @@ -1,48 +0,0 @@ -import path from 'path'; -import { CWD } from '../config/secrets'; -import { gcclient, HFClientConfig } from '@gala-chain/client'; - -enum GalachainRole { - Partner = 0, - Curator = 1, - User = 2, -} - -enum GalachainContract { - PublicKeyContract = 'PublicKeyContract', - GalaChainToken = 'GalaChainToken', -} - -const credentials: { [role: number]: HFClientConfig } = { - [GalachainRole.Partner]: { - orgMsp: 'PartnerOrg', - userId: 'admin', - userSecret: 'adminpw', - connectionProfilePath: path.resolve(CWD, 'app/connection-profiles/cpp-partner.json'), - }, - [GalachainRole.Curator]: { - orgMsp: 'CuratorOrg', - userId: 'admin', - userSecret: 'adminpw', - connectionProfilePath: path.resolve(CWD, 'app/connection-profiles/cpp-curator.json'), - }, - [GalachainRole.User]: { - orgMsp: 'UserOrg', - userId: 'admin', - userSecret: 'adminpw', - connectionProfilePath: path.resolve(CWD, 'app/connection-profiles/cpp-user.json'), - }, -}; - -const getClient = (role: GalachainRole) => { - const params = credentials[role]; - return gcclient.forConnectionProfile(params); -}; - -const getContract = (variant: GalachainContract) => ({ - channelName: 'product-channel', - chaincodeName: 'basic-product', - contractName: variant, -}); - -export { getContract, getClient, GalachainRole, GalachainContract }; diff --git a/apps/api/src/app/util/index.ts b/apps/api/src/app/util/index.ts index c5f595cf9..085b628ed 100644 --- a/apps/api/src/app/util/index.ts +++ b/apps/api/src/app/util/index.ts @@ -1 +1,2 @@ export * from './helpers'; +export * from './promise'; diff --git a/apps/api/src/app/util/promise.ts b/apps/api/src/app/util/promise.ts new file mode 100644 index 000000000..84d3c11e1 --- /dev/null +++ b/apps/api/src/app/util/promise.ts @@ -0,0 +1,15 @@ +import { logger } from './logger'; + +export class PromiseParser { + static async parse(callback) { + const results = await Promise.allSettled(callback); + return results.reduce((acc, result) => { + if (result.status === 'fulfilled') { + acc.push(result.value); + } else { + logger.error('Token decoration failed:', result.reason); + } + return acc; + }, []); + } +} diff --git a/apps/app/components.d.ts b/apps/app/components.d.ts index 6f6a831d1..dc0227b16 100644 --- a/apps/app/components.d.ts +++ b/apps/app/components.d.ts @@ -38,7 +38,6 @@ declare module 'vue' { BaseCardDiscordRole: typeof import('./src/components/card/BaseCardDiscordRole.vue')['default'] BaseCardERC20: typeof import('./src/components/card/BaseCardERC20.vue')['default'] BaseCardERC721: typeof import('./src/components/card/BaseCardERC721.vue')['default'] - BaseCardGalachain: typeof import('./src/components/card/BaseCardGalachain.vue')['default'] BaseCardHeader: typeof import('./src/components/card/BaseCardHeader.vue')['default'] BaseCardHeaderHome: typeof import('./src/components/card/BaseCardHeaderHome.vue')['default'] BaseCardLeaderboard: typeof import('./src/components/card/BaseCardLeaderboard.vue')['default'] @@ -62,7 +61,6 @@ declare module 'vue' { BaseCardRewardCoupon: typeof import('./src/components/card/BaseCardRewardCoupon.vue')['default'] BaseCardRewardCustom: typeof import('./src/components/card/BaseCardRewardCustom.vue')['default'] BaseCardRewardDiscordRole: typeof import('./src/components/card/BaseCardRewardDiscordRole.vue')['default'] - BaseCardRewardGalachain: typeof import('./src/components/card/BaseCardRewardGalachain.vue')['default'] BaseCardRewardNFT: typeof import('./src/components/card/BaseCardRewardNFT.vue')['default'] BaseCardRewards: typeof import('./src/components/card/BaseCardRewards.vue')['default'] BaseCardSnapshotProposal: typeof import('./src/components/card/BaseCardSnapshotProposal.vue')['default'] diff --git a/apps/app/src/components/card/BaseCardGalachain.vue b/apps/app/src/components/card/BaseCardGalachain.vue deleted file mode 100644 index 935695263..000000000 --- a/apps/app/src/components/card/BaseCardGalachain.vue +++ /dev/null @@ -1,35 +0,0 @@ - - - diff --git a/apps/app/src/components/card/BaseCardReward.vue b/apps/app/src/components/card/BaseCardReward.vue index 0f1539515..90825be0f 100644 --- a/apps/app/src/components/card/BaseCardReward.vue +++ b/apps/app/src/components/card/BaseCardReward.vue @@ -106,7 +106,6 @@ export const iconMap = { [RewardVariant.Coupon]: 'fas fa-tags', [RewardVariant.Custom]: 'fas fa-gift', [RewardVariant.DiscordRole]: 'fab fa-discord', - [RewardVariant.Galachain]: 'fas fa-box', } as { [variant: string]: string }; export default defineComponent({ diff --git a/apps/app/src/components/card/BaseCardRewardGalachain.vue b/apps/app/src/components/card/BaseCardRewardGalachain.vue deleted file mode 100644 index 610c65cd6..000000000 --- a/apps/app/src/components/card/BaseCardRewardGalachain.vue +++ /dev/null @@ -1,21 +0,0 @@ - - - diff --git a/apps/app/src/components/card/BaseCardRewards.vue b/apps/app/src/components/card/BaseCardRewards.vue index 5000d964f..ec94e81f6 100644 --- a/apps/app/src/components/card/BaseCardRewards.vue +++ b/apps/app/src/components/card/BaseCardRewards.vue @@ -30,7 +30,6 @@ import BaseCardERC20 from '../../components/card/BaseCardERC20.vue'; import BaseCardERC721 from '../../components/card/BaseCardERC721.vue'; import BaseCardCouponCode from '../../components/card/BaseCardCouponCode.vue'; import BaseCardDiscordRole from '../../components/card/BaseCardDiscordRole.vue'; -import BaseCardGalachain from '../../components/card/BaseCardGalachain.vue'; export default defineComponent({ name: 'BaseViewWallet', @@ -39,7 +38,6 @@ export default defineComponent({ BaseCardERC721, BaseCardCouponCode, BaseCardDiscordRole, - BaseCardGalachain, }, data() { return { @@ -69,10 +67,6 @@ export default defineComponent({ label: 'Codes', key: [RewardVariant.Coupon], }, - { - label: 'Galachain', - key: [RewardVariant.Galachain], - }, ] as { label: string; key: number[] }[], }; }, @@ -80,12 +74,11 @@ export default defineComponent({ ...mapStores(useAuthStore, useAccountStore, useWalletStore), list() { return [ - ...this.walletStore.erc20, - ...this.walletStore.erc721, - ...this.walletStore.erc1155, + ...this.walletStore.erc20.filter((item) => item.chainId === this.walletStore.chainId), + ...this.walletStore.erc721.filter((item) => item.chainId === this.walletStore.chainId), + ...this.walletStore.erc1155.filter((item) => item.chainId === this.walletStore.chainId), ...this.walletStore.couponCodes, ...this.walletStore.discordRoles, - ...this.walletStore.galachain, ] .filter((item) => { if (!this.activeFilter.key.length) return true; diff --git a/apps/app/src/components/modal/BaseModalRewardPayment.vue b/apps/app/src/components/modal/BaseModalRewardPayment.vue index bedecacb7..953745dd6 100644 --- a/apps/app/src/components/modal/BaseModalRewardPayment.vue +++ b/apps/app/src/components/modal/BaseModalRewardPayment.vue @@ -121,7 +121,7 @@ export default defineComponent({ return !!this.error; }, isWalletRequired() { - return [RewardVariant.Coin, RewardVariant.NFT, RewardVariant.Galachain].includes(this.reward.variant); + return [RewardVariant.Coin, RewardVariant.NFT].includes(this.reward.variant); }, }, watch: { diff --git a/apps/app/src/stores/Reward.ts b/apps/app/src/stores/Reward.ts index 4aed09278..205e6b9de 100644 --- a/apps/app/src/stores/Reward.ts +++ b/apps/app/src/stores/Reward.ts @@ -23,7 +23,6 @@ export const useRewardStore = defineStore('reward', { [RewardVariant.Coupon]: 'coupon reward redemption', [RewardVariant.Custom]: 'custom reward redemption', [RewardVariant.DiscordRole]: 'discord role reward redemption', - [RewardVariant.Galachain]: 'galachain reward redemption', }; track('UserCreates', [account?.sub, eventMap[variant], { poolId }]); }, @@ -44,8 +43,8 @@ export const useRewardStore = defineStore('reward', { const { api } = useAccountStore(); this.isLoading = true; - const { coin, nft, custom, coupon, discordRole, galachain } = await api.rewards.list(poolId); - this.rewards = [...coin, ...nft, ...custom, ...coupon, ...discordRole, ...galachain] + const { coin, nft, custom, coupon, discordRole } = await api.rewards.list(poolId); + this.rewards = [...coin, ...nft, ...custom, ...coupon, ...discordRole] .sort((a: any, b: any) => toNumber(b.createdAt) - toNumber(a.createdAt)) .sort((a: any, b: any) => toNumber(b.isPromoted) - toNumber(a.isPromoted)); this.isLoading = false; diff --git a/apps/app/src/stores/Wallet.ts b/apps/app/src/stores/Wallet.ts index 8c26c21bf..3901e92e8 100644 --- a/apps/app/src/stores/Wallet.ts +++ b/apps/app/src/stores/Wallet.ts @@ -69,7 +69,6 @@ export const useWalletStore = defineStore('wallet', { erc1155: [], couponCodes: [], discordRoles: [], - galachain: [], pendingPoints: 0, wallets: [], wallet: null, @@ -89,7 +88,6 @@ export const useWalletStore = defineStore('wallet', { this.erc1155 = []; this.couponCodes = []; this.discordRoles = []; - this.galachain = []; this.pendingPoints = 0; this.wallets = []; this.wallet = null; @@ -264,12 +262,6 @@ export const useWalletStore = defineStore('wallet', { ...t, component: 'BaseCardDiscordRole', })); - this.galachain = payments - .filter((p: { rewardVariant: RewardVariant }) => p.rewardVariant === RewardVariant.Galachain) - .map((t: TRewardGalachainPayment[]) => ({ - ...t, - component: 'BaseCardGalachain', - })); this.isLoading = false; }, diff --git a/apps/app/src/types/enums/rewards.ts b/apps/app/src/types/enums/rewards.ts index 16ab2ac71..e73b727a8 100644 --- a/apps/app/src/types/enums/rewards.ts +++ b/apps/app/src/types/enums/rewards.ts @@ -23,7 +23,6 @@ export enum RewardVariant { Custom = 2, Coupon = 3, DiscordRole = 4, - Galachain = 5, } export enum RewardConditionPlatform { diff --git a/apps/app/src/types/interfaces/rewards.d.ts b/apps/app/src/types/interfaces/rewards.d.ts index 36df9d002..1d3ab49be 100644 --- a/apps/app/src/types/interfaces/rewards.d.ts +++ b/apps/app/src/types/interfaces/rewards.d.ts @@ -59,22 +59,6 @@ type TBaseRewardPayment = { createdAt: Date; }; -type TRewardGalachain = TReward & { - contractChannelName: string; - contractChaincodeName: string; - contractContractName: string; - tokenCollection: string; - tokenCategory: string; - tokenType: string; - tokenAdditionalKey: string; - amount: string; - privateKey: string; -}; - -type TRewardGalachainPayment = TBaseRewardPayment & { - amount: string; -}; - type TRewardCoinPayment = TBaseRewardPayment & { // }; diff --git a/apps/app/src/types/interfaces/wallet.d.ts b/apps/app/src/types/interfaces/wallet.d.ts index 7bbd58a69..7fb6391cd 100644 --- a/apps/app/src/types/interfaces/wallet.d.ts +++ b/apps/app/src/types/interfaces/wallet.d.ts @@ -47,7 +47,6 @@ type TWalletState = { balances: { [tokenAddress: string]: string }; couponCodes: any[]; discordRoles: any[]; - galachain: TRewardGalachainPayment[]; pendingPoints: number; isLoading: boolean; isModalWalletCreateShown: boolean; diff --git a/apps/app/src/views/campaign/Quests.vue b/apps/app/src/views/campaign/Quests.vue index 16e20e5f8..51073ffa6 100644 --- a/apps/app/src/views/campaign/Quests.vue +++ b/apps/app/src/views/campaign/Quests.vue @@ -95,7 +95,6 @@ import BaseCardRewardNFT from '../../components/card/BaseCardRewardNFT.vue'; import BaseCardRewardCustom from '../../components/card/BaseCardRewardCustom.vue'; import BaseCardRewardCoupon from '../../components/card/BaseCardRewardCoupon.vue'; import BaseCardRewardDiscordRole from '../../components/card/BaseCardRewardDiscordRole.vue'; -import BaseCardRewardGalachain from '../../components/card/BaseCardRewardGalachain.vue'; const componentMap: { [variant: string]: string } = { [RewardVariant.Coin]: 'BaseCardRewardCoin', @@ -103,7 +102,6 @@ const componentMap: { [variant: string]: string } = { [RewardVariant.Custom]: 'BaseCardRewardCustom', [RewardVariant.Coupon]: 'BaseCardRewardCoupon', [RewardVariant.DiscordRole]: 'BaseCardRewardDiscordRole', - [RewardVariant.Galachain]: 'BaseCardRewardGalachain', }; export default defineComponent({ @@ -121,7 +119,6 @@ export default defineComponent({ BaseCardRewardCustom, BaseCardRewardCoupon, BaseCardRewardDiscordRole, - BaseCardRewardGalachain, }, data() { return { diff --git a/apps/app/src/views/campaign/Rewards.vue b/apps/app/src/views/campaign/Rewards.vue index 4a1ffeace..ae72ee6d7 100644 --- a/apps/app/src/views/campaign/Rewards.vue +++ b/apps/app/src/views/campaign/Rewards.vue @@ -25,7 +25,6 @@ import BaseCardRewardNFT from '../../components/card/BaseCardRewardNFT.vue'; import BaseCardRewardCustom from '../../components/card/BaseCardRewardCustom.vue'; import BaseCardRewardCoupon from '../../components/card/BaseCardRewardCoupon.vue'; import BaseCardRewardDiscordRole from '../../components/card/BaseCardRewardDiscordRole.vue'; -import BaseCardRewardGalachain from '../../components/card/BaseCardRewardGalachain.vue'; const componentMap: { [variant: string]: string } = { [RewardVariant.Coin]: 'BaseCardRewardCoin', @@ -33,7 +32,6 @@ const componentMap: { [variant: string]: string } = { [RewardVariant.Custom]: 'BaseCardRewardCustom', [RewardVariant.Coupon]: 'BaseCardRewardCoupon', [RewardVariant.DiscordRole]: 'BaseCardRewardDiscordRole', - [RewardVariant.Galachain]: 'BaseCardRewardGalachain', }; export default defineComponent({ @@ -44,7 +42,6 @@ export default defineComponent({ BaseCardRewardCustom, BaseCardRewardCoupon, BaseCardRewardDiscordRole, - BaseCardRewardGalachain, }, data() { return { diff --git a/libs/common/src/lib/enums/RewardVariant.ts b/libs/common/src/lib/enums/RewardVariant.ts index cc6ee7a8d..4e5253431 100644 --- a/libs/common/src/lib/enums/RewardVariant.ts +++ b/libs/common/src/lib/enums/RewardVariant.ts @@ -4,7 +4,6 @@ export enum RewardVariant { Custom = 2, Coupon = 3, DiscordRole = 4, - Galachain = 5, } export enum QuestVariant { diff --git a/libs/common/src/lib/types/Galachain.d.ts b/libs/common/src/lib/types/Galachain.d.ts deleted file mode 100644 index e870fc82a..000000000 --- a/libs/common/src/lib/types/Galachain.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -type TGalachainContract = { - channelName: string; - chaincodeName: string; - contractName: string; - methodName?: string; -}; - -type TGalachainToken = { - collection: string; - category: string; - type: string; - additionalKey: string; -}; diff --git a/libs/common/src/lib/types/Pool.d.ts b/libs/common/src/lib/types/Pool.d.ts index ee81dedf9..a07af3426 100644 --- a/libs/common/src/lib/types/Pool.d.ts +++ b/libs/common/src/lib/types/Pool.d.ts @@ -50,7 +50,6 @@ type TPoolSettings = { leaderboardInWeeks: number; isPublished: boolean; isWeeklyDigestEnabled: boolean; - galachainPrivateKey: string; authenticationMethods: AccountVariant[]; }; diff --git a/libs/common/src/lib/types/Reward.d.ts b/libs/common/src/lib/types/Reward.d.ts index 07b0a7d84..da91274da 100644 --- a/libs/common/src/lib/types/Reward.d.ts +++ b/libs/common/src/lib/types/Reward.d.ts @@ -4,7 +4,7 @@ type TInfoLink = { }; type TQuestLock = { variant: QuestVariant; questId: string }; -type TReward = TRewardCoin | TRewardNFT | TRewardCustom | TRewardCoupon | TRewardDiscordRole | TRewardGalachain; +type TReward = TRewardCoin | TRewardNFT | TRewardCustom | TRewardCoupon | TRewardDiscordRole; type TBaseReward = { _id: string; variant: RewardVariant; @@ -42,5 +42,4 @@ type TRewardPayment = | TRewardNFTPayment | TRewardCustomPayment | TRewardCouponPayment - | TRewardDiscordRolePayment - | TRewardGalachainPayment; + | TRewardDiscordRolePayment; diff --git a/libs/common/src/lib/types/RewardGalachain.d.ts b/libs/common/src/lib/types/RewardGalachain.d.ts deleted file mode 100644 index b5eb381a5..000000000 --- a/libs/common/src/lib/types/RewardGalachain.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -type TRewardGalachain = TReward & { - contractChannelName: string; - contractChaincodeName: string; - contractContractName: string; - tokenCollection: string; - tokenCategory: string; - tokenType: string; - tokenAdditionalKey: string; - tokenInstance: number; - amount: string; - privateKey: string; -}; diff --git a/libs/common/src/lib/types/RewardGalachainPayment.d.ts b/libs/common/src/lib/types/RewardGalachainPayment.d.ts deleted file mode 100644 index dfe338574..000000000 --- a/libs/common/src/lib/types/RewardGalachainPayment.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -type TRewardGalachainPayment = TBaseRewardPayment & { - amount: string; -};