From c3a188c7c9dce6844a7c0353b4f9db84912500ce Mon Sep 17 00:00:00 2001 From: Luis_ <73004377+Another-DevX@users.noreply.github.com> Date: Tue, 25 Jun 2024 20:50:36 -0400 Subject: [PATCH 1/3] Feat/add current supply pactv2 (#1123) Co-authored-by: AnotherDev --- packages/api/.env.development.template | 1 + .../src/controllers/v2/circulatingSupply.ts | 35 +++++++++++++++ .../routes/v2/protocol/circulatingSupply.ts | 44 +++++++++++++++++++ packages/core/src/config/index.ts | 1 + packages/core/src/config/validatenv.ts | 1 + 5 files changed, 82 insertions(+) create mode 100644 packages/api/src/controllers/v2/circulatingSupply.ts 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/controllers/v2/circulatingSupply.ts b/packages/api/src/controllers/v2/circulatingSupply.ts new file mode 100644 index 000000000..796aeebd9 --- /dev/null +++ b/packages/api/src/controllers/v2/circulatingSupply.ts @@ -0,0 +1,35 @@ +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 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); + let circulatingSupply = new BigNumber(totalSupply); + topHoldersBalances.forEach(balance => { + circulatingSupply = circulatingSupply.minus(balance.toString()); + }); + + const response = circulatingSupply.dividedBy(decimals).toNumber(); + + // answer + res.send(response.toString()); +}; 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..07cfc1032 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.PACTV2_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 51e91806b0da10503e23c6fe313477a2e879bdfd Mon Sep 17 00:00:00 2001 From: Luis_ <73004377+Another-DevX@users.noreply.github.com> Date: Tue, 25 Jun 2024 20:55:12 -0400 Subject: [PATCH 2/3] Revert "Feat/add current supply pactv2" (#1124) --- packages/api/.env.development.template | 1 - .../src/controllers/v2/circulatingSupply.ts | 35 --------------- .../routes/v2/protocol/circulatingSupply.ts | 44 ------------------- packages/core/src/config/index.ts | 1 - packages/core/src/config/validatenv.ts | 1 - 5 files changed, 82 deletions(-) delete mode 100644 packages/api/src/controllers/v2/circulatingSupply.ts delete 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 80625d43c..1c9368126 100644 --- a/packages/api/.env.development.template +++ b/packages/api/.env.development.template @@ -39,7 +39,6 @@ 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/controllers/v2/circulatingSupply.ts b/packages/api/src/controllers/v2/circulatingSupply.ts deleted file mode 100644 index 796aeebd9..000000000 --- a/packages/api/src/controllers/v2/circulatingSupply.ts +++ /dev/null @@ -1,35 +0,0 @@ -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 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); - let circulatingSupply = new BigNumber(totalSupply); - topHoldersBalances.forEach(balance => { - circulatingSupply = circulatingSupply.minus(balance.toString()); - }); - - const response = circulatingSupply.dividedBy(decimals).toNumber(); - - // answer - res.send(response.toString()); -}; diff --git a/packages/api/src/routes/v2/protocol/circulatingSupply.ts b/packages/api/src/routes/v2/protocol/circulatingSupply.ts deleted file mode 100644 index e820b8e99..000000000 --- a/packages/api/src/routes/v2/protocol/circulatingSupply.ts +++ /dev/null @@ -1,44 +0,0 @@ -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 07cfc1032..2c985410c 100644 --- a/packages/core/src/config/index.ts +++ b/packages/core/src/config/index.ts @@ -80,7 +80,6 @@ export default { /** contract addresses */ contractAddresses: { pact: validatedEnv.PACT_CONTRACT_ADDRESS, - pactV2: validatedEnv.PACTV2_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 c481dcac3..a3b35656b 100644 --- a/packages/core/src/config/validatenv.ts +++ b/packages/core/src/config/validatenv.ts @@ -90,7 +90,6 @@ 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 428ea96c19032f5ddcf11739ec55d61f0a853844 Mon Sep 17 00:00:00 2001 From: Luis_ <73004377+Another-DevX@users.noreply.github.com> Date: Tue, 25 Jun 2024 20:55:41 -0400 Subject: [PATCH 3/3] Feat/add current supply pactv2 (#1125) Co-authored-by: AnotherDev --- packages/api/.env.development.template | 1 + .../src/controllers/v2/circulatingSupply.ts | 35 +++++++++++++++ .../routes/v2/protocol/circulatingSupply.ts | 44 +++++++++++++++++++ packages/api/src/routes/v2/protocol/index.ts | 3 ++ packages/core/src/config/index.ts | 1 + packages/core/src/config/validatenv.ts | 1 + 6 files changed, 85 insertions(+) create mode 100644 packages/api/src/controllers/v2/circulatingSupply.ts 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/controllers/v2/circulatingSupply.ts b/packages/api/src/controllers/v2/circulatingSupply.ts new file mode 100644 index 000000000..796aeebd9 --- /dev/null +++ b/packages/api/src/controllers/v2/circulatingSupply.ts @@ -0,0 +1,35 @@ +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 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); + let circulatingSupply = new BigNumber(totalSupply); + topHoldersBalances.forEach(balance => { + circulatingSupply = circulatingSupply.minus(balance.toString()); + }); + + const response = circulatingSupply.dividedBy(decimals).toNumber(); + + // answer + res.send(response.toString()); +}; 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..9b4226687 --- /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 (route: Router): void => { + /** + * @swagger + * + * /protocol/circulating-supply: + * get: + * tags: + * - "generic" + * summary: Gets PACT circulating supply. + * responses: + * "200": + * description: OK + */ + route.get('/circulating-supply', cache(cacheIntervals.oneDay), circulatingSupply); + + /** + * @swagger + * + * /protocol/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 + */ + 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); + }; diff --git a/packages/core/src/config/index.ts b/packages/core/src/config/index.ts index 2c985410c..07cfc1032 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.PACTV2_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')