Skip to content

Commit

Permalink
feat: sync upstream new tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
Vardominator committed Apr 8, 2024
1 parent 26bbf83 commit 9274260
Show file tree
Hide file tree
Showing 16 changed files with 530 additions and 251 deletions.
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"singleQuote": false,
"trailingComma": "es5"
"trailingComma": "es5",
"tabWidth": 4
}
70 changes: 36 additions & 34 deletions internal/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,45 @@ import logfmt from "logfmt";
import { SupplyFetcherResponse, supplyFetchers } from "../src";

async function main(): Promise<void> {
const marketCapData: Record<string, SupplyFetcherResponse> = {};
for (const [key, supplyFetcher] of Object.entries(supplyFetchers)) {
try {
await backOff(
async () => {
const startTime = new Date();
const data = await supplyFetcher();
marketCapData[key] = data;
const endTime = new Date();
console.info(
logfmt.stringify({
time: endTime.toISOString(),
level: "INFO",
message: "done fetch market cap for asset",
duration: `${(endTime.getTime() - startTime.getTime()) / 1000}s`,
asset: key,
total_supply: data.total,
circulating_supply: data.circulating,
})
);
},
{
retry(err, attempt): boolean {
console.error(
`fail to run fetcher for ${key}, retry ${attempt}...`,
err
const marketCapData: Record<string, SupplyFetcherResponse> = {};
for (const [key, supplyFetcher] of Object.entries(supplyFetchers)) {
try {
await backOff(
async () => {
const startTime = new Date();
const data = await supplyFetcher();
marketCapData[key] = data;
const endTime = new Date();
console.info(
logfmt.stringify({
time: endTime.toISOString(),
level: "INFO",
message: "done fetch market cap for asset",
duration: `${
(endTime.getTime() - startTime.getTime()) / 1000
}s`,
asset: key,
total_supply: data.total,
circulating_supply: data.circulating,
})
);
},
{
retry(err, attempt): boolean {
console.error(
`fail to run fetcher for ${key}, retry ${attempt}...`,
err
);
return true;
},
numOfAttempts: 3,
}
);
return true;
},
numOfAttempts: 3,
} catch (err) {
console.error(`fail to run fetcher for ${key}`, err);
}
);
} catch (err) {
console.error(`fail to run fetcher for ${key}`, err);
}
}
fs.writeFileSync("/tmp/market-cap.json", JSON.stringify(marketCapData));
fs.writeFileSync("/tmp/market-cap.json", JSON.stringify(marketCapData));
}

void main();
373 changes: 198 additions & 175 deletions src/index.ts

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions src/tokens/axo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { SupplyFetcher } from "../types";
import { defaultFetcher } from "../utils";

const fetcher: SupplyFetcher = async (fetcher = defaultFetcher) => {
const circulating = await fetcher
.axios("https://api.axo.trade/axo/circulating")
.then((res) => res.data.toString());
const total = await fetcher
.axios("https://api.axo.trade/axo/total")
.then((res) => res.data.toString());
return {
circulating,
total,
};
};

export default fetcher;
61 changes: 61 additions & 0 deletions src/tokens/boon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { SupplyFetcher } from "../types";
import { defaultFetcher } from "../utils";

const BOON =
"1cd92100fc05fce7416b3857a079780164eeaf8f5613f4b814f24e09426f6f6e436f696e";

const fetcher: SupplyFetcher = async (fetcher = defaultFetcher) => {
const total = 77_777_777_777;

const donationRaw = await fetcher.getAmountInAddresses(BOON, [
"addr1qy6up60du0r2rufjwsrf457jyssm9xnsysmgaqq934pf9gyv7h2adx0trglt75d4m0uaccftfnekt54fm9lxldfantjqyrejes",
]);

const farmingRaw = await fetcher.getAmountInAddresses(BOON, [
"addr1q8wvyukwhvykzv3tc039wyj7udygg983daz673lemq7d6h9r3vsw8l62684wlvtzrsxm27hmhl7y9ulsruaxtvmuclcqw544l5",
]);

const liquidityPoolRaw = await fetcher.getAmountInAddresses(BOON, [
"addr1qxulpxynvfzxak6t6s3483f4wzq45vqssy50s378wg4g7dlq5udt9geu2937fcpfej9m4tk72y7v8ajqka9uayrp9sdq6gkwcy",
]);

const marketingRaw = await fetcher.getAmountInAddresses(BOON, [
"addr1qyn3efzf9hmxx7ep3d4mmuu7mkgthpgxfj5t5t7ws86yj6cdr6e7utkyhethe4rylepdlf7983dwwd3ge6zpcervvdasjys8tg",
]);

const presaleRaw = await fetcher.getAmountInAddresses(BOON, [
"addr1q9cej5hv7ayne342eee3yef3zlkaxaglx2upy0r0505xmlshuewv0v8ud8ncya6uarc7vekx0260tyfrgtr272032lrqj4g88j",
]);

const reserveRaw = await fetcher.getAmountInAddresses(BOON, [
"addr1qx9z7ldyrsqxx5alw8n4cpsy2q464fud62wuwqudrk5k0k7apqpv3s6z9h8we5svv6d806p9ed6yzjtt07kq6m6t6c8qzy9zcd",
]);

const giveawayRaw = await fetcher.getAmountInAddresses(BOON, [
"addr1qx62z87cxhxvcdmkd8qraw2fswva740msqgp3nw9peu62pgz0jyzekf0xrewx2u8rfakpfty7hdp5vttsmgmg0lzhfaspua7vx",
]);

const donation = Number(donationRaw);
const farming = Number(farmingRaw);
const liquidityPool = Number(liquidityPoolRaw);
const marketing = Number(marketingRaw);
const presale = Number(presaleRaw);
const reserve = Number(reserveRaw);
const giveaway = Number(giveawayRaw);

return {
circulating: (
total -
donation -
farming -
liquidityPool -
marketing -
presale -
reserve -
giveaway
).toString(),
total: total.toString(),
};
};

export default fetcher;
16 changes: 16 additions & 0 deletions src/tokens/btn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { SupplyFetcher } from "../types";
import { defaultFetcher } from "../utils";

const BTN = "016be5325fd988fea98ad422fcfd53e5352cacfced5c106a932a35a442544e";

const fetcher: SupplyFetcher = async (fetcher = defaultFetcher) => {
const total = 25e6;
const circulating = await fetcher.getSupplyFromAssetMetadata(BTN);
const circulatingWithDecimals = Number(circulating) / 1e6;
return {
circulating: circulatingWithDecimals.toString(),
total: total.toString(),
};
};

export default fetcher;
19 changes: 19 additions & 0 deletions src/tokens/catsky.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { SupplyFetcher } from "../types";
import { defaultFetcher } from "../utils";

const CATSKY =
"9b426921a21f54600711da0be1a12b026703a9bd8eb9848d08c9d921434154534b59";

const fetcher: SupplyFetcher = async (fetcher = defaultFetcher) => {
const total = 999_999_999_997;
const treasuryRaw = await fetcher.getAmountInAddresses(CATSKY, [
"stake1uxln0cv8ne7zskyhsmuna5rx5xw9undrvx4nqxvrmcvuweskz2mje", // treasury $catbank.catsky
]);
const treasury = Number(treasuryRaw);
return {
circulating: (total - treasury).toString(),
total: total.toString(),
};
};

export default fetcher;
12 changes: 6 additions & 6 deletions src/tokens/cbtc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { defaultFetcher } from "../utils";
const CBTC = "4190b2941d9be04acc69c39739bd5acc66d60ccab480d8e20bc87e3763425443";

const fetcher: SupplyFetcher = async (fetcher = defaultFetcher) => {
const total = await fetcher.getSupplyFromAssetMetadata(CBTC);
const totalWithDecimals = Number(total) / 1e8;
return {
circulating: totalWithDecimals.toString(),
total: totalWithDecimals.toString(),
};
const total = await fetcher.getSupplyFromAssetMetadata(CBTC);
const totalWithDecimals = Number(total) / 1e8;
return {
circulating: totalWithDecimals.toString(),
total: totalWithDecimals.toString(),
};
};

export default fetcher;
27 changes: 27 additions & 0 deletions src/tokens/charly.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { SupplyFetcher } from "../types";
import { defaultFetcher } from "../utils";

const CHARLY =
"89267e9a35153a419e1b8ffa23e511ac39ea4e3b00452e9d500f2982436176616c6965724b696e67436861726c6573";

const fetcher: SupplyFetcher = async (fetcher = defaultFetcher) => {
const total = 777_777_777_777;

const treasuryRaw = await fetcher.getAmountInAddresses(CHARLY, [
"addr1vxgts9tzm59h72uetsg48m3tj4z6h0gqz3m7pdm0gapwxxslqglt9", // Cardano_Lands
"addr1v9gs0trlcmyty7jakcewjs3h00a7xrzyd5wnyfrpeg4wjts0ugx63", // Charly_bowl
"stake1uxkxtajzhlmnlglr5dhrdfx36ry597wvr2k5utlm6eu8susrny2uj", // $king-foundation
"stake1ux3q72uz5ztmyvuz7qwgv8qw3akpr2pnh4ed3wzudddt33qh67tzj", // $charly-treasury
"stake1u94eatrzsm59pnlncqtx0jds2hyv4u46pdjjgw9avus5qhq5p08fc", // $charlyfounders
"stake1u94vpc75fv6mq4vcupew454mf97wygg54shprlnwy8f5r5spul7ju", // $charlytoken
]);

const treasury = Number(treasuryRaw);

return {
circulating: (total - treasury).toString(),
total: total.toString(),
};
};

export default fetcher;
25 changes: 25 additions & 0 deletions src/tokens/lwh.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { SupplyFetcher } from "../types";
import { defaultFetcher } from "../utils";

const LWH =
"defe216460d594211631fcfbd354f361c04645d6a0cfeead3d6f62836c65767679776966686174";

const fetcher: SupplyFetcher = async (fetcher = defaultFetcher) => {
const total = Number(100_000_000);
const treasuryRaw = await fetcher.getAmountInAddresses(LWH, [
"stake1u9dz7rdqnx4rthc3rn9nt9mtvzve8tv6ek809c8z9ld89lspvnq2g",
"stake1u9u5ema2qm8wthrkf7gc8423sg24ey0ucpw6cknhymt2uysclzez4",
"stake1ux04u6ru8dduhsscza3309f2a86dxlzw6mx30va665d489gm2enja",
"stake1uyn63uqt3aqjlq7gvtqh33zdvl4u8g9dj62q9svly24l50ck7p4kh",
"addr1w8qmxkacjdffxah0l3qg8hq2pmvs58q8lcy42zy9kda2ylc6dy5r4",
"stake1u997nsgekunxnauepkhz57prz86clz7tm0fwgclnv3pupzg095yak",
"stake1u96vnsecj2dp6zeae8ywptp4u3fghkes8vrmwwpfwl47jysv8ksma",
]);
const treasury = Number(treasuryRaw);
return {
circulating: (total - treasury).toString(),
total: total.toString(),
};
};

export default fetcher;
24 changes: 24 additions & 0 deletions src/tokens/shards.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { SupplyFetcher } from "../types";
import { defaultFetcher } from "../utils";

const TOKEN =
"ea153b5d4864af15a1079a94a0e2486d6376fa28aafad272d15b243a0014df10536861726473";

const fetcher: SupplyFetcher = async (fetcher = defaultFetcher) => {
const total = 5_000_000;
const treasuryRaw = await fetcher.getAmountInAddresses(TOKEN, [
"addr1w95dsllnucgg53lj8qhdcgjnw40hlsctkeh8udt7uhud2tgjfyagq", // DripDropz Instant Rewards
"stake17yavsn3jqqxm29tcgrjpj8e960tf00hkkvzaqxv6tt8ud7s4kw5vn", // GameFi Incentives Reserves
"addr1wx4ua0djv8c4fvkl8t08z0duf3lw8fl4qujvevwx4m9c7ygma04rr", // Blockchain-wide Distribution (Cardano) & SHARDS/ADA LP Rewards
"stake17yqphvez52gkae448avqr5smpztvlrwmwsvfhgmp84laxes3zfyq0", // Private Investors
"stake178yzhvwqsw56qnz3lj4heu08m7tvl9z95zk4e2tpj4y8wkc7wmpzz", // FPS Treasury
"stake1u8yt8czlj5svzc4jvr3w230tsjklctw4tvhz43k5recvfvqwnvelg", // FPS Team Wallet
]);
const treasury = Number(treasuryRaw) / 1e6;
return {
circulating: (total - treasury).toString(),
total: total.toString(),
};
};

export default fetcher;
19 changes: 19 additions & 0 deletions src/tokens/tool.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { SupplyFetcher } from "../types";
import { defaultFetcher } from "../utils";

const TOOL =
"ac015c38917f306a84748c2d646bed90bdd64421c592163e60702d735453555255";

const fetcher: SupplyFetcher = async (fetcher = defaultFetcher) => {
const total = 1_000_000_000;
const treasuryRaw = await fetcher.getAmountInAddresses(TOOL, [
"addr1vxndsnat5pgddcaqcddu3epun8gvh42yt4z6ekcr8p58wagnl5ek7", // TOOL TREASURY
]);
const treasury = Number(treasuryRaw);
return {
circulating: (total - treasury).toString(),
total: total.toString(),
};
};

export default fetcher;
25 changes: 25 additions & 0 deletions src/tokens/wojakblue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { SupplyFetcher } from "../types";
import { defaultFetcher } from "../utils";

const WOJAKBLUE =
"a1b284d7218dd63772c67ca26ab73721a196b404929cddef595f9967574f4a414b424c5545";

const fetcher: SupplyFetcher = async (fetcher = defaultFetcher) => {
const total = 69420000000;
const treasuryRaw = [
"addr1q90m9sd7kwdt2vusmzlwprwycsys7ayjxtyagju89n3az27y9mpw78dw8u729jy27kwmz4w623qxt89nxjva06ujkwuqtpsejr",
];
const burnRaw = [
"addr1w8qmxkacjdffxah0l3qg8hq2pmvs58q8lcy42zy9kda2ylc6dy5r4",
];
const treasury = Number(
await fetcher.getAmountInAddresses(WOJAKBLUE, treasuryRaw)
);
const burn = Number(await fetcher.getAmountInAddresses(WOJAKBLUE, burnRaw));
return {
circulating: (total - treasury - burn).toString(),
total: (total - burn).toString(),
};
};

export default fetcher;
20 changes: 20 additions & 0 deletions src/tokens/xray.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { SupplyFetcher } from "../types";
import { defaultFetcher } from "../utils";

const XRAY = "86abe45be4d8fb2e8f28e8047d17d0ba5592f2a6c8c452fc88c2c14358524159";
const TREASURY_ADDRESSES = [
"addr1qyc98ysmvxunqslu3y5t9gpt2mm8dp3puylpq7n5n908jldw8w6w5nmvw86ullauxldxdjsfauyrattxw6yevxp72nnsq3lt0u", // stage2 fund
];

const fetcher: SupplyFetcher = async (fetcher = defaultFetcher) => {
const total = 324_922_240;
const treasury =
Number(await fetcher.getAmountInAddresses(XRAY, TREASURY_ADDRESSES)) /
1e6;
return {
circulating: (total - treasury).toString(),
total: total.toString(),
};
};

export default fetcher;
16 changes: 8 additions & 8 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { BlockchainIndexer } from "./utils";

export type FetcherOptions = {
/**
* Fetch timeout in milliseconds. Default to 20s
*/
timeout?: number;
/**
* Fetch timeout in milliseconds. Default to 20s
*/
timeout?: number;
};

export const defaultFetcherOptions: FetcherOptions = {
timeout: 20_000,
timeout: 20_000,
};

export type SupplyFetcherResponse = {
total?: string;
circulating?: string;
total?: string;
circulating?: string;
};

export type SupplyFetcher = (
fetcher?: BlockchainIndexer
fetcher?: BlockchainIndexer
) => Promise<SupplyFetcherResponse>;
Loading

0 comments on commit 9274260

Please sign in to comment.