Skip to content

Commit

Permalink
Merge pull request #2 from gear-foundation/do-refactor
Browse files Browse the repository at this point in the history
update
  • Loading branch information
EugenWay authored Nov 3, 2023
2 parents 5c4130d + 2985275 commit 8da3671
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
19 changes: 13 additions & 6 deletions src/calculators/circulation-supply.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import {
AIRDROP_POOL,
DEVELOPER_PROJECTS_GRANTS_POOL,
FOUNDATION_AND_ECOSYSTEM_DEVELOPMENT_POOL,
INFLATION_OFFSETTING_POOL,
INITIAL_BALANCE_INFLATION_OFFSETTING_POOL,
EDUCATION_BOOTCAMP_PR_EVENT_POOL,
PROTOCOL_DEVELOPMENT_POOL,
PROTOCOL_RESERVE_POOL,
VALIDATOR_INCENTIVES_POOL,
MARKET_POOL,
CUSTODY,
AIRDROP_3RD_PARTY_1,
DECIMALS,
} from '../consts.js';
import { totalSupply } from './total-supply.js';

Expand Down Expand Up @@ -41,7 +43,7 @@ export async function totalVesting() {
const locked = withType.unwrap()[0].locked.toBigInt();
result += locked;
}
const totalVesting = result / BigInt(10 ** 12);
const totalVesting = result / BigInt(10 ** DECIMALS);
return Number(totalVesting);
}

Expand All @@ -59,7 +61,7 @@ export async function totalStaking() {
total += withType.amount.toBigInt();
}
}
const totalStaking = total / BigInt(10 ** 12);
const totalStaking = total / BigInt(10 ** DECIMALS);
return Number(totalStaking);
}

Expand All @@ -69,7 +71,7 @@ export async function totalStaking() {
// return [poolAddr, ...deriveAddr(poolAddr)];
// }

// Circulation Supply = Total Supply - (Vesting + Pools);
// Circulation Supply = Total Supply - (Vesting + Staking + Pools);
export async function circulationSupply() {
const addresses = [
EDUCATION_BOOTCAMP_PR_EVENT_POOL,
Expand All @@ -79,10 +81,11 @@ export async function circulationSupply() {
VALIDATOR_INCENTIVES_POOL,
DEVELOPER_PROJECTS_GRANTS_POOL,
AIRDROP_POOL,
INFLATION_OFFSETTING_POOL,
MARKET_POOL,
AIRDROP_3RD_PARTY_1,
...CUSTODY,
];
// INFLATION_OFFSETTING_POOL;

const [supply, vesting, staking, pools] = await Promise.all([
totalSupply(),
Expand All @@ -91,7 +94,11 @@ export async function circulationSupply() {
getBalances(addresses),
]);

const total = pools.reduce((accumulator, current) => accumulator + current, 0) + vesting + staking;
const total =
pools.reduce((accumulator, current) => accumulator + current, 0) +
vesting +
staking +
INITIAL_BALANCE_INFLATION_OFFSETTING_POOL;

return supply - total;
}
3 changes: 2 additions & 1 deletion src/calculators/total-supply.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { DECIMALS } from '../consts.js';
import { api } from '../node.js';

export async function totalSupply() {
const total = await api.query.balances.totalIssuance();

const bigint = total.toBigInt() / BigInt(10 ** 12);
const bigint = total.toBigInt() / BigInt(10 ** DECIMALS);
return Number(bigint);
}
4 changes: 4 additions & 0 deletions src/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export const MARKET_POOL = 'kGmHNw32YQrY9SFArgjFKgrgysZN13Th29ZPoPT6hJ7uhhtrs';

export const INITIAL_BALANCE_INFLATION_OFFSETTING_POOL = 1_000_000_000;

export const AIRDROP_3RD_PARTY_1 = 'kGfgqjRznfuto8Q7oxAine8ZFjDCkpcYB6XVcNCw5QHw1z6xd';

// Custody accounts

export const CUSTODY = [
Expand All @@ -24,3 +26,5 @@ export const CUSTODY = [
'kGga7DgxzLLTqn9WjtEZW5pkxYVnBPS4Rt6xK3Adqs1iKN42z',
'kGiVY7G1mJkqaAjKzLnRmwCy5GcvuGQvG5mUtojhVHdLfBd1P',
];

export const DECIMALS = 12;

0 comments on commit 8da3671

Please sign in to comment.