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

Circulating supply sonic #1411

Merged
merged 2 commits into from
Jan 3, 2025
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
5 changes: 5 additions & 0 deletions .changeset/nice-garlics-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'backend': patch
---

add sonic beets circulating supply endpoint
7 changes: 6 additions & 1 deletion apps/api/rest-routes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Express } from 'express';
import { beetsGetCirculatingSupply } from '../../modules/beets/lib/beets';
import { beetsGetCirculatingSupply, beetsGetCirculatingSupplySonic } from '../../modules/beets/lib/beets';

export function loadRestRoutes(app: Express) {
app.use('/health', (_, res) => res.sendStatus(200));
Expand All @@ -8,4 +8,9 @@ export function loadRestRoutes(app: Express) {
res.send(result);
});
});
app.use('/circulating_supply_sonic', (_, res) => {
beetsGetCirculatingSupplySonic().then((result) => {
res.send(result);
});
});
}
11 changes: 11 additions & 0 deletions modules/beets/beets.service.debug.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { beetsGetCirculatingSupply, beetsGetCirculatingSupplySonic } from '../../modules/beets/lib/beets';

test('retrieve updated fBeets ratio', async () => {
const fantomCirc = await beetsGetCirculatingSupply();

console.log(fantomCirc);

const sonicCirc = await beetsGetCirculatingSupplySonic();

console.log(sonicCirc);
});
27 changes: 26 additions & 1 deletion modules/beets/lib/beets.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { utils } from 'ethers';
import beetsAbi from '../abi/BeethovenxToken.json';
import { getContractAt } from '../../web3/contract';
import { getContractAt, getContractAtForNetwork } from '../../web3/contract';
import { networkContext } from '../../network/network-context.service';
import { AllNetworkConfigs } from '../../network/network-config';

const NON_CIRCULATING_ADDRESSES = [
'0xa2503804ec837d1e4699932d58a3bdb767dea505', //team linear vesting
Expand All @@ -13,6 +14,12 @@ const NON_CIRCULATING_ADDRESSES = [
'0x766ddc12447973d86092e403f85c35578dd0433d', //advisor linear vesting
];

const NON_CIRCULATING_ADDRESSES_SONIC = [
'0xc5E0250037195850E4D987CA25d6ABa68ef5fEe8', //treasury
'0x9D14fB062Cb47Da81a09c8B20437719D553e91fb', //team multisig
'0x8a81173FC726eEDd1ad6036dB6197027C77865C2', //beets minting target
];

export async function beetsGetCirculatingSupply() {
const beetsContract = getContractAt(networkContext.data.beets!.address, beetsAbi);

Expand All @@ -25,3 +32,21 @@ export async function beetsGetCirculatingSupply() {

return utils.formatUnits(totalSupply);
}

export async function beetsGetCirculatingSupplySonic() {
const sonicNetworkConfig = AllNetworkConfigs['146'];
const beetsContract = getContractAtForNetwork(
sonicNetworkConfig.data.beets!.address,
beetsAbi,
sonicNetworkConfig.provider,
);

let totalSupply = await beetsContract.totalSupply();

for (const address of NON_CIRCULATING_ADDRESSES_SONIC) {
const balance = await beetsContract.balanceOf(address);
totalSupply = totalSupply.sub(balance);
}

return utils.formatUnits(totalSupply);
}
5 changes: 5 additions & 0 deletions modules/web3/contract.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getAddress } from 'ethers/lib/utils';
import { Contract } from 'ethers';
import { networkContext } from '../network/network-context.service';
import { BaseProvider } from '@ethersproject/providers';

export function returnChecksum() {
return function (target: any, key: string, descriptor: PropertyDescriptor) {
Expand All @@ -16,3 +17,7 @@ export function returnChecksum() {
export function getContractAt<T extends Contract>(address: string, abi: any): T {
return new Contract(address, abi, networkContext.provider) as T;
}

export function getContractAtForNetwork<T extends Contract>(address: string, abi: any, provider: BaseProvider): T {
return new Contract(address, abi, provider) as T;
}
Loading