Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/add current supply pactv2 #1125

Merged
merged 6 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/api/.env.development.template
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
35 changes: 35 additions & 0 deletions packages/api/src/controllers/v2/circulatingSupply.ts
Original file line number Diff line number Diff line change
@@ -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());
};
44 changes: 44 additions & 0 deletions packages/api/src/routes/v2/protocol/circulatingSupply.ts
Original file line number Diff line number Diff line change
@@ -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));
};
3 changes: 3 additions & 0 deletions packages/api/src/routes/v2/protocol/index.ts
Original file line number Diff line number Diff line change
@@ -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);

};
1 change: 1 addition & 0 deletions packages/core/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/config/validatenv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Loading