Skip to content

Commit

Permalink
Fix circ supply (#10)
Browse files Browse the repository at this point in the history
* fix circ supply

* change totalStaking calc

* fix

* change api url

* recalculate pools

* remove address

* add new addresses

* add new address

* add new address
  • Loading branch information
EugenWay authored Feb 22, 2024
1 parent 3cd7b85 commit a53d872
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 32 deletions.
54 changes: 26 additions & 28 deletions src/calculators/circulation-supply.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { api, getBalances } from '../node.js';
import { api, deriveAddr, getBalances } from '../node.js';

import {
AIRDROP_POOL,
DEVELOPER_PROJECTS_GRANTS_POOL,
Expand All @@ -11,14 +12,17 @@ import {
MARKET_POOL,
CUSTODY,
AIRDROP_3RD_PARTY_1,
COMMUNITY_AIRDROP_2,
DECIMALS,
CB_COLD_WALLETS,
TYAN,
CB_REWARDS,
DELTA,
GEAR_FOUNDATION_V,
GEAR_TECH_V,
REWARD_DISTRIBUTION_MULTISIG
} from '../consts.js';
import { totalSupply } from './total-supply.js';

const STAKING_HEX = '0x7374616b696e6720';

async function getKeys(prefix, startKey = null) {
const result = await api.rpc.state.getKeysPaged(prefix, 1000, startKey);
if (result.length === 1000) {
Expand Down Expand Up @@ -49,46 +53,40 @@ export async function totalVesting() {
return Number(totalVesting);
}

export async function totalStaking() {
const currentEra = (await api.query.staking.currentEra()).toHuman();
const staking = await api.query.staking.erasTotalStake(currentEra);
const total = staking.toBigInt() / BigInt(10 ** DECIMALS)

return Number(total)
// Each pool additionally has 10 or 15 derived accounts (indexes from 1 to 15)
function getPoolAddresses(poolAddr, index) {
return [poolAddr, ...deriveAddr(poolAddr, index)];
}

// Get all pool addresses
// Each pool additionally has 10 derived accounts (indexes from 1 to 10)
// function getPoolAddresses(poolAddr) {
// return [poolAddr, ...deriveAddr(poolAddr)];
// }

// Circulation Supply = Total Supply - (Vesting + Staking + Pools);
// Circulation Supply = Total Supply - (Vesting + Pools);
export async function circulationSupply() {
const addresses = [
EDUCATION_BOOTCAMP_PR_EVENT_POOL,
PROTOCOL_RESERVE_POOL,
FOUNDATION_AND_ECOSYSTEM_DEVELOPMENT_POOL,
PROTOCOL_DEVELOPMENT_POOL,
VALIDATOR_INCENTIVES_POOL,
DEVELOPER_PROJECTS_GRANTS_POOL,
AIRDROP_POOL,
...getPoolAddresses(EDUCATION_BOOTCAMP_PR_EVENT_POOL, 15),
...getPoolAddresses(PROTOCOL_RESERVE_POOL),
...getPoolAddresses(FOUNDATION_AND_ECOSYSTEM_DEVELOPMENT_POOL),
...getPoolAddresses(PROTOCOL_DEVELOPMENT_POOL, 15),
...getPoolAddresses(VALIDATOR_INCENTIVES_POOL, 12),
...getPoolAddresses(DEVELOPER_PROJECTS_GRANTS_POOL, 15),
...getPoolAddresses(AIRDROP_POOL),
MARKET_POOL,
AIRDROP_3RD_PARTY_1,
COMMUNITY_AIRDROP_2,
INFLATION_OFFSETTING_POOL,
TYAN,
...CUSTODY,
...CB_COLD_WALLETS,
CB_REWARDS,
GEAR_TECH_V,
GEAR_FOUNDATION_V,
REWARD_DISTRIBUTION_MULTISIG
];

const [supply, vesting, staking, pools] = await Promise.all([
const [supply, vesting, pools] = await Promise.all([
totalSupply(),
totalVesting(),
totalStaking(),
getBalances(addresses),
]);

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

return supply - total;
}
10 changes: 9 additions & 1 deletion src/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const MARKET_POOL = 'kGmHNw32YQrY9SFArgjFKgrgysZN13Th29ZPoPT6hJ7uhhtrs';
export const INITIAL_BALANCE_INFLATION_OFFSETTING_POOL = 1_000_000_000;

export const AIRDROP_3RD_PARTY_1 = 'kGfgqjRznfuto8Q7oxAine8ZFjDCkpcYB6XVcNCw5QHw1z6xd';
export const COMMUNITY_AIRDROP_2 = 'kGgmH1HoD2qkwGN3uG17eG5ND3tgQTWS3MpTsF9yVzY4KVAAL';

// Custody accounts

Expand All @@ -34,6 +35,13 @@ export const CB_COLD_WALLETS = [
'kGhzLBaaHM66zJrFPqCrA4MJc2jhiKKdndB5cNCeGVpY7wpG2',
];

export const TYAN = 'kGgYvzyAgbd9j7QvLQ3iEyuWEJYZroTxSraQD8d4NCSTdVX7i';
export const CB_REWARDS = 'kGgH6TyfMQmjVLoDxTXUEjnYoa63eBwLK9D8XM2PtZ8tr6KND';

// Undistributed community airdrop
export const DELTA = 132000000;

export const GEAR_FOUNDATION_V = 'kGiKi96jKfPzvvBCuPbBQeBNrUV5nNUVBxTeGJ5hgs3R3Di5e';
export const GEAR_TECH_V = 'kGhYV2BWXtbspqGFhzhkx7Pur2Y7TWtaU9yPa8atXpMt33ExK';
export const REWARD_DISTRIBUTION_MULTISIG = 'kGjbw9qJBN7PMHxFonwpMig3obvbPLqyf8fp4L7CRn8HjXXfk';

export const DECIMALS = 12;
4 changes: 2 additions & 2 deletions src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ export async function getBalances(addresses) {
return result;
}

export const deriveAddr = (addr) => {
export const deriveAddr = (addr, deriveCount = 10) => {
const accounts = [];
for (let deriveIndex = 1; deriveIndex <= 10; deriveIndex++) {
for (let deriveIndex = 1; deriveIndex <= deriveCount; deriveIndex++) {
accounts.push(encodeAddress(encodeDerivedAddress(addr, deriveIndex), 137));
}
return accounts;
Expand Down
1 change: 0 additions & 1 deletion src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import config from './config.js';
import {
circulationSupply,
tokensSentFromInflationPool,
totalStaking,
totalSupply,
totalVesting,
stakingRoi
Expand Down

0 comments on commit a53d872

Please sign in to comment.