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

connext #1379

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

connext #1379

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
84 changes: 84 additions & 0 deletions fees/connext/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { FetchV2, SimpleAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import { gql, GraphQLClient } from "graphql-request";

type Transfer = {
bridgedAmt: number;
transactingAsset: string;
relayerFees: {
asset: string;
fee: number;
}[];
};
const getDailyFee = () =>
gql`
query originTransfers($startTimestamp: BigInt!, $endTimestamp: BigInt!) {
originTransfers(
where: { timestamp_gt: $startTimestamp, timestamp_lt: $endTimestamp }
) {
bridgedAmt
transactingAsset
relayerFees {
fee
asset
}
}
}
`;
const getGQLClient = (url: string) => new GraphQLClient(url);

const subgraphs = {
[CHAIN.ETHEREUM]:
"https://api.thegraph.com/subgraphs/name/connext/amarok-runtime-v0-mainnet",
[CHAIN.OPTIMISM]:
"https://api.thegraph.com/subgraphs/name/connext/amarok-runtime-v0-optimism",
[CHAIN.ARBITRUM]:
"https://api.thegraph.com/subgraphs/name/connext/amarok-runtime-v0-arbitrum-one",
[CHAIN.POLYGON]:
"https://api.thegraph.com/subgraphs/name/connext/amarok-runtime-v0-polygon",
[CHAIN.BSC]:
"https://api.thegraph.com/subgraphs/name/connext/amarok-runtime-v0-bnb",
[CHAIN.XDAI]:
"https://api.thegraph.com/subgraphs/name/connext/amarok-runtime-v0-gnosis",
// [CHAIN.LINEA]:
// "https://connext.bwarelabs.com/subgraphs/name/connext/amarok-runtime-v0-linea",
};

const fetch: FetchV2 = async ({
createBalances,
chain,
startTimestamp,
endTimestamp,
}) => {
const dailyFees = createBalances();
const dailyVolume = createBalances();
const transfers: Transfer[] = (
await getGQLClient(subgraphs[chain]).request(getDailyFee(), {
startTimestamp,
endTimestamp,
})
).originTransfers;

transfers.map((t: Transfer) => {
dailyVolume.add(t.transactingAsset, t.bridgedAmt);
t.relayerFees.map(({ asset, fee }) => {
dailyFees.add(asset, fee);
});
});
return { dailyFees, dailyVolume };
};
// ts-node --transpile-only cli/testAdapter.ts fees connext
const adapter: SimpleAdapter = {
adapter: Object.keys(subgraphs).reduce((acc, chain) => {
return {
...acc,
[chain]: {
fetch,
start: 1698660910,
},
};
}, {}),
version: 2,
};

export default adapter;
Loading