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

[Stale] abcdefx - add fantom #560

Closed
wants to merge 3 commits into from
Closed
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
36 changes: 21 additions & 15 deletions fees/abcdefx.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { FetchResultFees, SimpleAdapter } from "../adapters/types";

Check failure on line 1 in fees/abcdefx.ts

View workflow job for this annotation

GitHub Actions / ts-check

Type 'Promise<FetchResultFees>' is not assignable to type 'Fetch'.

Check failure on line 1 in fees/abcdefx.ts

View workflow job for this annotation

GitHub Actions / ts-check

Expected 2 arguments, but got 1.

Check failure on line 1 in fees/abcdefx.ts

View workflow job for this annotation

GitHub Actions / ts-check

Type 'Promise<FetchResultFees>' is not assignable to type 'Fetch'.

Check failure on line 1 in fees/abcdefx.ts

View workflow job for this annotation

GitHub Actions / ts-check

Expected 2 arguments, but got 1.

Check failure on line 1 in fees/abcdefx.ts

View workflow job for this annotation

GitHub Actions / ts-check

Type 'Promise<FetchResultFees>' is not assignable to type 'Fetch'.

Check failure on line 1 in fees/abcdefx.ts

View workflow job for this annotation

GitHub Actions / ts-check

Expected 2 arguments, but got 1.

Check failure on line 1 in fees/abcdefx.ts

View workflow job for this annotation

GitHub Actions / ts-check

Type 'Promise<FetchResultFees>' is not assignable to type 'Fetch'.

Check failure on line 1 in fees/abcdefx.ts

View workflow job for this annotation

GitHub Actions / ts-check

Expected 2 arguments, but got 1.
import { CHAIN } from "../helpers/chains";
import * as sdk from "@defillama/sdk";
import { getBlock } from "../helpers/getBlock";
import { getPrices } from "../utils/prices";
import { Chain } from "@defillama/sdk/build/general";

interface ILog {
data: string;
Expand All @@ -14,6 +15,7 @@
}

const topic0 = '0x112c256902bf554b6ed882d2936687aaeb4225e8cd5b51303c90ca6cf43a8602';
//const chains = ['fantom', 'kcc', 'echelon', 'multivac', 'kava']
const FACTORY_ADDRESS = '0x01f43d2a7f4554468f77e06757e707150e39130c';

type TABI = {
Expand Down Expand Up @@ -73,14 +75,14 @@
};


const fetch = async (timestamp: number): Promise<FetchResultFees> => {
const fetch = async (timestamp: number, chain: Chain): Promise<FetchResultFees> => {
const fromTimestamp = timestamp - 60 * 60 * 24
const toTimestamp = timestamp

try {
const poolLength = (await sdk.api.abi.call({
target: FACTORY_ADDRESS,
chain: 'kava',
chain: chain,
abi: ABIs.allPairsLength,
})).output;

Expand All @@ -90,7 +92,7 @@
target: FACTORY_ADDRESS,
params: i,
})),
chain: 'kava'
chain: chain
});

const lpTokens = poolsRes.output
Expand All @@ -103,33 +105,33 @@
calls: lpTokens.map((address: string) => ({
target: address,
})),
chain: 'kava'
chain: chain
})
)
);

const tokens0 = underlyingToken0.output.map((res: any) => res.output);
const tokens1 = underlyingToken1.output.map((res: any) => res.output);
const fromBlock = (await getBlock(fromTimestamp, 'kava', {}));
const toBlock = (await getBlock(toTimestamp, 'kava', {}));
const fromBlock = (await getBlock(fromTimestamp, chain, {}));
const toBlock = (await getBlock(toTimestamp, chain, {}));
const logs: ILog[][] = (await Promise.all(lpTokens.map((address: string) => sdk.api.util.getLogs({
target: address,
topic: '',
toBlock: toBlock,
fromBlock: fromBlock,
keys: [],
chain: 'kava',
chain: chain,
topics: [topic0]
}))))
.map((p: any) => p)
.map((a: any) => a.output);

const rawCoins = [...tokens0, ...tokens1].map((e: string) => `kava:${e}`);
const rawCoins = [...tokens0, ...tokens1].map((e: string) => chain+`:${e}`);
const coins = [...new Set(rawCoins)]
const prices = await getPrices(coins, timestamp);
const fees: number[] = lpTokens.map((_: string, index: number) => {
const token0Decimals = (prices[`kava:${tokens0[index]}`]?.decimals || 0)
const token1Decimals = (prices[`kava:${tokens1[index]}`]?.decimals || 0)
const token0Decimals = (prices[chain+`:${tokens0[index]}`]?.decimals || 0)
const token1Decimals = (prices[chain+`:${tokens1[index]}`]?.decimals || 0)
const log: IAmount[] = logs[index]
.map((e: ILog) => { return { ...e, data: e.data.replace('0x', '') } })
.map((p: ILog) => {
Expand All @@ -140,8 +142,8 @@
amount1
} as IAmount
}) as IAmount[];
const token0Price = (prices[`kava:${tokens0[index]}`]?.price || 0);
const token1Price = (prices[`kava:${tokens1[index]}`]?.price || 0);
const token0Price = (prices[chain+`:${tokens0[index]}`]?.price || 0);
const token1Price = (prices[chain+`:${tokens1[index]}`]?.price || 0);

const feesAmount0 = log
.reduce((a: number, b: IAmount) => Number(b.amount0) + a, 0) * token0Price;
Expand All @@ -167,10 +169,14 @@

const adapter: SimpleAdapter = {
adapter: {
[CHAIN.KAVA]: {
fetch,
start: async () => 1675000000,
[CHAIN.FANTOM]: {
fetch: fetch(CHAIN.FANTOM),
start: async () => 1677000000,
},
[CHAIN.KAVA]: {
fetch: fetch(CHAIN.ARBITRUM),
start: async () => 1677000000,
}
}
};

Expand Down
Loading