From 364978ed3fdb302f9e49d84ef41716de30d8742e Mon Sep 17 00:00:00 2001 From: AnotherDev Date: Tue, 25 Jun 2024 18:49:46 -0500 Subject: [PATCH 1/6] feat: add pactv2 address support --- packages/api/.env.development.template | 1 + .../routes/v2/protocol/circulatingSupply.ts | 44 +++++++++++++++++++ packages/core/src/config/index.ts | 1 + packages/core/src/config/validatenv.ts | 1 + 4 files changed, 47 insertions(+) create mode 100644 packages/api/src/routes/v2/protocol/circulatingSupply.ts diff --git a/packages/api/.env.development.template b/packages/api/.env.development.template index 1c9368126..80625d43c 100644 --- a/packages/api/.env.development.template +++ b/packages/api/.env.development.template @@ -39,6 +39,7 @@ MASTER_KEY= MINIMAL_MOBILE_APP_VERSION= NODE_ENV= PACT_CONTRACT_ADDRESS= +PACTV2_CONTRACT_ADDRESS= PORT=5002 POSITION_STACK_API_BASE_URL= POSITION_STACK_API_KEY= diff --git a/packages/api/src/routes/v2/protocol/circulatingSupply.ts b/packages/api/src/routes/v2/protocol/circulatingSupply.ts new file mode 100644 index 000000000..e820b8e99 --- /dev/null +++ b/packages/api/src/routes/v2/protocol/circulatingSupply.ts @@ -0,0 +1,44 @@ +import { Request, Response, Router } from 'express'; + +import { cache } from '../../../middlewares/cache-redis'; +import { cacheIntervals } from '../../../utils/api'; +import { circulatingSupply } from '~controllers/v2/circulatingSupply'; + +export default (app: Router): void => { + /** + * @swagger + * + * /circulating-supply: + * get: + * tags: + * - "generic" + * summary: Gets PACT circulating supply. + * responses: + * "200": + * description: OK + */ + app.get('/circulating-supply', cache(cacheIntervals.oneDay), circulatingSupply); + + /** + * @swagger + * + * /total-supply: + * get: + * tags: + * - "generic" + * summary: Gets total PACT supply. + * responses: + * "200": + * description: OK + * content: + * application/json: + * schema: + * type: object + * properties: + * success: + * type: boolean + * data: + * type: number + */ + app.get('/total-supply', (_req: Request, res: Response) => res.send(100_000_000_000)); +}; diff --git a/packages/core/src/config/index.ts b/packages/core/src/config/index.ts index 2c985410c..ecaf053a1 100644 --- a/packages/core/src/config/index.ts +++ b/packages/core/src/config/index.ts @@ -80,6 +80,7 @@ export default { /** contract addresses */ contractAddresses: { pact: validatedEnv.PACT_CONTRACT_ADDRESS, + pactV2: validatedEnv.PACT_V2_CONTRACT_ADDRESS, airgrab: validatedEnv.AIRGRAB_CONTRACT_ADDRESS, donationMiner: validatedEnv.DONATION_MINER_CONTRACT_ADDRESS, impactLabs: validatedEnv.IMPACTLABS_CONTRACT_ADDRESS, diff --git a/packages/core/src/config/validatenv.ts b/packages/core/src/config/validatenv.ts index a3b35656b..c481dcac3 100644 --- a/packages/core/src/config/validatenv.ts +++ b/packages/core/src/config/validatenv.ts @@ -90,6 +90,7 @@ function validateEnv() { DEFAULT_LIMIT: num({ default: 10 }), DEFAULT_OFFSET: num({ default: 0 }), PACT_CONTRACT_ADDRESS: str({ devDefault: onlyOnTestEnv('xyz') }), + PACTV2_CONTRACT_ADDRESS: str({ devDefault: onlyOnTestEnv('xyz') }), AIRGRAB_CONTRACT_ADDRESS: str({ devDefault: onlyOnTestEnv('xyz') }), DONATION_MINER_CONTRACT_ADDRESS: str({ devDefault: onlyOnTestEnv('xyz') From 90cdbed2851f55956dfe6b884598ca3c3e83da65 Mon Sep 17 00:00:00 2001 From: AnotherDev Date: Tue, 25 Jun 2024 18:50:42 -0500 Subject: [PATCH 2/6] feat: add circulatingSupply controler --- .../src/controllers/v2/circulatingSupply.ts | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 packages/api/src/controllers/v2/circulatingSupply.ts diff --git a/packages/api/src/controllers/v2/circulatingSupply.ts b/packages/api/src/controllers/v2/circulatingSupply.ts new file mode 100644 index 000000000..06310e934 --- /dev/null +++ b/packages/api/src/controllers/v2/circulatingSupply.ts @@ -0,0 +1,31 @@ +import { BigNumber } from 'bignumber.js'; +import { Contract } from '@ethersproject/contracts'; +import { JsonRpcProvider } from '@ethersproject/providers'; +import { Request, Response } from 'express'; +import { config, contracts } from '@impactmarket/core'; + +// this is required for external services to access the circulating supply +export const circulatingSupply = async (_req: Request, res: Response) => { + const decimals = new BigNumber(10).pow(18); + const pact = new Contract( + config.contractAddresses.pact, + contracts.ERC20ABI, + new JsonRpcProvider(config.jsonRpcUrl) + ); + const airgrabPACTBalance = await pact.balanceOf(config.contractAddresses.airgrab); + const daoPACTBalance = await pact.balanceOf(config.contractAddresses.dao); + const donationMinerPACTBalance = await pact.balanceOf(config.contractAddresses.donationMiner); + const impactLabsPACTBalance = await pact.balanceOf(config.contractAddresses.impactLabs); + const idoPACTBalance = await pact.balanceOf(config.contractAddresses.ido); + const totalSupply = new BigNumber(100_000_000_000).multipliedBy(decimals); + const circulatingSupply = new BigNumber(totalSupply) + .minus(airgrabPACTBalance.toString()) + .minus(daoPACTBalance.toString()) + .minus(donationMinerPACTBalance.toString()) + .minus(impactLabsPACTBalance.toString()) + .minus(idoPACTBalance.toString()); + const response = circulatingSupply.dividedBy(decimals).toNumber(); + + // answer + res.send(response.toString()); +}; From cfd0f29c841d331f2dbecfe79fdf03f622fbd0e8 Mon Sep 17 00:00:00 2001 From: AnotherDev Date: Tue, 25 Jun 2024 18:52:33 -0500 Subject: [PATCH 3/6] fix: typo --- packages/core/src/config/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/config/index.ts b/packages/core/src/config/index.ts index ecaf053a1..07cfc1032 100644 --- a/packages/core/src/config/index.ts +++ b/packages/core/src/config/index.ts @@ -80,7 +80,7 @@ export default { /** contract addresses */ contractAddresses: { pact: validatedEnv.PACT_CONTRACT_ADDRESS, - pactV2: validatedEnv.PACT_V2_CONTRACT_ADDRESS, + pactV2: validatedEnv.PACTV2_CONTRACT_ADDRESS, airgrab: validatedEnv.AIRGRAB_CONTRACT_ADDRESS, donationMiner: validatedEnv.DONATION_MINER_CONTRACT_ADDRESS, impactLabs: validatedEnv.IMPACTLABS_CONTRACT_ADDRESS, From fc2f76fa8f56bc9f0898e9dd2bef65ef70bc13fb Mon Sep 17 00:00:00 2001 From: AnotherDev Date: Tue, 25 Jun 2024 19:33:11 -0500 Subject: [PATCH 4/6] feat: add top holders modification --- .../src/controllers/v2/circulatingSupply.ts | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/packages/api/src/controllers/v2/circulatingSupply.ts b/packages/api/src/controllers/v2/circulatingSupply.ts index 06310e934..7dca4d65c 100644 --- a/packages/api/src/controllers/v2/circulatingSupply.ts +++ b/packages/api/src/controllers/v2/circulatingSupply.ts @@ -12,18 +12,24 @@ export const circulatingSupply = async (_req: Request, res: Response) => { contracts.ERC20ABI, new JsonRpcProvider(config.jsonRpcUrl) ); - const airgrabPACTBalance = await pact.balanceOf(config.contractAddresses.airgrab); - const daoPACTBalance = await pact.balanceOf(config.contractAddresses.dao); - const donationMinerPACTBalance = await pact.balanceOf(config.contractAddresses.donationMiner); - const impactLabsPACTBalance = await pact.balanceOf(config.contractAddresses.impactLabs); - const idoPACTBalance = await pact.balanceOf(config.contractAddresses.ido); + const topHolders = [ + '0xBD11CaeA0a854ba328e202ceD2F0269fD8027c6e', + '0x59aAc0b8bd03b7Ba9D391Eb989c3Ea8CdE638144', + '0x73cD8626b3cD47B009E68380720CFE6679A3Ec3D', + '0x3844cb665cf676B1Eb7C896E04D3E9eC3BAB5a75', + '0x213962Ba8e4cef1D618c88d62D2FFA39eC5Eb22D', + '0x1854c78e5401A501A8F32f3a9DFae3d356Fb9A9E' + ] + const topHoldersBalances = await Promise.all( + topHolders.map(holder => pact.balanceOf(holder)) + ); + const totalSupply = new BigNumber(100_000_000_000).multipliedBy(decimals); - const circulatingSupply = new BigNumber(totalSupply) - .minus(airgrabPACTBalance.toString()) - .minus(daoPACTBalance.toString()) - .minus(donationMinerPACTBalance.toString()) - .minus(impactLabsPACTBalance.toString()) - .minus(idoPACTBalance.toString()); + let circulatingSupply = new BigNumber(totalSupply) + topHoldersBalances.forEach(balance => { + circulatingSupply = circulatingSupply.minus(balance.toString()); + }); + const response = circulatingSupply.dividedBy(decimals).toNumber(); // answer From 282818c542fa8cdc9d8b0fd64280ef7863f156a3 Mon Sep 17 00:00:00 2001 From: AnotherDev Date: Tue, 25 Jun 2024 19:44:13 -0500 Subject: [PATCH 5/6] fix: lint --- packages/api/src/controllers/v2/circulatingSupply.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/api/src/controllers/v2/circulatingSupply.ts b/packages/api/src/controllers/v2/circulatingSupply.ts index 7dca4d65c..796aeebd9 100644 --- a/packages/api/src/controllers/v2/circulatingSupply.ts +++ b/packages/api/src/controllers/v2/circulatingSupply.ts @@ -19,13 +19,11 @@ export const circulatingSupply = async (_req: Request, res: Response) => { '0x3844cb665cf676B1Eb7C896E04D3E9eC3BAB5a75', '0x213962Ba8e4cef1D618c88d62D2FFA39eC5Eb22D', '0x1854c78e5401A501A8F32f3a9DFae3d356Fb9A9E' - ] - const topHoldersBalances = await Promise.all( - topHolders.map(holder => pact.balanceOf(holder)) - ); + ]; + const topHoldersBalances = await Promise.all(topHolders.map(holder => pact.balanceOf(holder))); const totalSupply = new BigNumber(100_000_000_000).multipliedBy(decimals); - let circulatingSupply = new BigNumber(totalSupply) + let circulatingSupply = new BigNumber(totalSupply); topHoldersBalances.forEach(balance => { circulatingSupply = circulatingSupply.minus(balance.toString()); }); From f6376efe00098c4b4c94e54809539eeff2e07b1e Mon Sep 17 00:00:00 2001 From: AnotherDev Date: Tue, 25 Jun 2024 19:53:40 -0500 Subject: [PATCH 6/6] fix: handle route --- .../api/src/routes/v2/protocol/circulatingSupply.ts | 10 +++++----- packages/api/src/routes/v2/protocol/index.ts | 3 +++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/api/src/routes/v2/protocol/circulatingSupply.ts b/packages/api/src/routes/v2/protocol/circulatingSupply.ts index e820b8e99..9b4226687 100644 --- a/packages/api/src/routes/v2/protocol/circulatingSupply.ts +++ b/packages/api/src/routes/v2/protocol/circulatingSupply.ts @@ -4,11 +4,11 @@ import { cache } from '../../../middlewares/cache-redis'; import { cacheIntervals } from '../../../utils/api'; import { circulatingSupply } from '~controllers/v2/circulatingSupply'; -export default (app: Router): void => { +export default (route: Router): void => { /** * @swagger * - * /circulating-supply: + * /protocol/circulating-supply: * get: * tags: * - "generic" @@ -17,12 +17,12 @@ export default (app: Router): void => { * "200": * description: OK */ - app.get('/circulating-supply', cache(cacheIntervals.oneDay), circulatingSupply); + route.get('/circulating-supply', cache(cacheIntervals.oneDay), circulatingSupply); /** * @swagger * - * /total-supply: + * /protocol/total-supply: * get: * tags: * - "generic" @@ -40,5 +40,5 @@ export default (app: Router): void => { * data: * type: number */ - app.get('/total-supply', (_req: Request, res: Response) => res.send(100_000_000_000)); + route.get('/total-supply', (_req: Request, res: Response) => res.send(100_000_000_000)); }; diff --git a/packages/api/src/routes/v2/protocol/index.ts b/packages/api/src/routes/v2/protocol/index.ts index 3bd1d2e5a..8f84772f7 100644 --- a/packages/api/src/routes/v2/protocol/index.ts +++ b/packages/api/src/routes/v2/protocol/index.ts @@ -1,10 +1,13 @@ import { Router } from 'express'; import microcredit from './microcredit'; +import circulatingSupply from './circulatingSupply'; export default (app: Router): void => { const route = Router(); app.use('/protocol', route); microcredit(route); + circulatingSupply(route); + };