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

Added bananagun.ts to fees dashboard #666

Closed
wants to merge 1 commit 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
62 changes: 62 additions & 0 deletions fees/bananagun.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { Chain } from "@defillama/sdk/build/general"
import { CHAIN } from "../helpers/chains";
import { Adapter, FetchResultFees } from "../adapters/types";
import { queryFlipside } from "../helpers/flipsidecrypto";
import { getBlock } from "../helpers/getBlock";
import { getPrices } from "../utils/prices";

type TokenId = {
[s: string | Chain]: string;
}

const gasTokenId: TokenId = {
[CHAIN.ETHEREUM]: "coingecko:ethereum",
}

const graph = (chain: Chain) => {
return async (timestamp: number): Promise<FetchResultFees> => {

const fromTimestamp = timestamp - 60 * 60 * 24
const toTimestamp = timestamp
try {
const startblock = (await getBlock(fromTimestamp, chain, {}));
const endblock = (await getBlock(toTimestamp, chain, {}));
console.log("here");
const query = `
select
${chain === "bsc"?"BNB_VALUE":"eth_value"}ba
from
${chain}.core.fact_transactions
WHERE to_address = '0xdc13700db7f7cda382e10dba643574abded4fd5b'
and BLOCK_NUMBER > ${startblock} AND BLOCK_NUMBER < ${endblock}
`
console.log(query);
const value: string[] = (await queryFlipside(query)).flat();
let amount = value.reduce((a: number, b: string) => a + Number(b), 0)
const gasId = gasTokenId[chain];
const gasIdPrice = (await getPrices([gasId], timestamp))[gasId].price;
const dailyFees = (amount * gasIdPrice)
return {
dailyFees: `${dailyFees}`,
dailyRevenue: `${dailyFees}`,
timestamp
}
} catch (err) {
console.log(err);
throw err;
}

}
}


const adapter: Adapter = {
adapter: {
[CHAIN.ETHEREUM]: {
fetch: graph(CHAIN.ETHEREUM),
start: async () => 1656633600,
}
}
}

export default adapter;
Loading