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

add arbitrum-nitro fees #27

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 4 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
65 changes: 65 additions & 0 deletions fees/arbitrum-nitro.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import axios from "axios";
import { Adapter, ChainBlocks, ProtocolType } from "../adapters/types";
import { CHAIN } from "../helpers/chains";
import { getBlock } from "../helpers/getBlock";
import { getTimestampAtStartOfDayUTC, getTimestampAtStartOfNextDayUTC } from "../utils/date";
import { getPrices } from "../utils/prices";


const URL = 'https://api.thegraph.com/subgraphs/name/dmihal/arbitrum-fees-collected'
interface IValue {
totalFeesETH: string;
}

interface ITx {
value: string;
}


const SEQUENCER_FEES = '0xa4b1e63cb4901e327597bc35d36fe8a23e4c253f'
const NETWORK_INFRA_FEES = '0xD345e41aE2cb00311956aA7109fC801Ae8c81a52'
const CONGESTION_FEES = '0xa4B00000000000000000000000000000000000F6'

const getWithdrawalTxs = async (address: string, startblock: number, endblock: number) => {
const url = `https://api.arbiscan.io/api?module=account&action=txlist&address=${address}&startblock=${startblock}&endblock=${endblock}`;
const data: ITx[] = await axios.get(url).then((e: any) => e.data.result).catch((err: any) => {
console.log(`error get tx list: ${err}`);
return [];
});
return data.reduce((acc, { value }) => acc + Number(value) / 1e18, 0)
};

const adapter: Adapter = {
adapter: {
[CHAIN.ARBITRUM]: {
fetch: async (timestamp: number, _: ChainBlocks) => {
const todaysTimestamp = getTimestampAtStartOfDayUTC(timestamp);
const yesterdaysTimestamp = getTimestampAtStartOfNextDayUTC(timestamp);

const todaysBlock = (await getBlock(todaysTimestamp, "arbitrum", {}));
const yesterdaysBlock = (await getBlock(yesterdaysTimestamp, "arbitrum", {}));
const [sequesnerFee, infraFee, congestionFee] = await Promise.all([
getWithdrawalTxs(SEQUENCER_FEES, todaysBlock, yesterdaysBlock),
getWithdrawalTxs(NETWORK_INFRA_FEES, todaysBlock, yesterdaysBlock),
getWithdrawalTxs(CONGESTION_FEES, todaysBlock, yesterdaysBlock),
]);
const withdrawalFee = sequesnerFee + infraFee + congestionFee;

const pricesObj = await getPrices(["coingecko:ethereum"], todaysTimestamp);
const dailyFees = (withdrawalFee) * pricesObj["coingecko:ethereum"].price

return {
timestamp,
totalFees: undefined,
0xngmi marked this conversation as resolved.
Show resolved Hide resolved
dailyFees: dailyFees.toString(),
dailyRevenue: "0",
totalRevenue: "0",
};
},
start: async () => 1622250511
},
},
protocolType: ProtocolType.CHAIN
}

export default adapter;