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 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
56 changes: 56 additions & 0 deletions fees/arbitrum-nitro.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
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";

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.etherscan.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: {
["arbitrum-nitro"]: {
fetch: async (timestamp: number, _: ChainBlocks) => {
const todaysTimestamp = timestamp
const yesterdaysTimestamp = getTimestampAtStartOfDayUTC(timestamp)

const todaysBlock = (await getBlock(todaysTimestamp, "ethereum", {}));
const yesterdaysBlock = (await getBlock(yesterdaysTimestamp, "ethereum", {}));
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,
dailyFees: dailyFees.toString(),
};
},
start: async () => 1622250511
},
},
protocolType: ProtocolType.CHAIN
}

export default adapter;