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

adding v3p5 events to across adapter #330

Open
wants to merge 2 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
68 changes: 68 additions & 0 deletions src/adapters/across/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Chain } from "@defillama/sdk/build/general";
import { BridgeAdapter, PartialContractEventParams } from "../../helpers/bridgeAdapter.type";
import { getTxDataFromEVMEventLogs } from "../../helpers/processTransactions";
import { ethers } from "ethers";

/*
Contracts: https://github.com/across-protocol/contracts-v2/blob/master/deployments/README.md
Expand Down Expand Up @@ -64,6 +65,56 @@ const contracts = {

type SupportedChains = keyof typeof contracts;

// Add helper function
function bytes32ToAddress(bytes32: string) {
return ethers.utils.getAddress('0x' + bytes32.slice(26));
}

// "Version 3.5" events
const depositParamsv3p5: PartialContractEventParams = {
target: "",
topic: "FundsDeposited(bytes32,bytes32,uint256,uint256,uint256,uint256,uint32,uint32,uint32,bytes32,bytes32,bytes32,bytes)",
abi: [
"event FundsDeposited(bytes32 inputToken, bytes32 outputToken, uint256 inputAmount, uint256 outputAmount, uint256 indexed destinationChainId, uint256 indexed depositId, uint32 quoteTimestamp, uint32 fillDeadline, uint32 exclusivityDeadline, bytes32 indexed depositor, bytes32 recipient, bytes32 exclusiveRelayer, bytes message)"
],
logKeys: {
blockNumber: "blockNumber",
txHash: "transactionHash",
},
argKeys: {
amount: "inputAmount",
token: "inputToken",
},
argGetters: {
to: (logArgs: any) => bytes32ToAddress(logArgs.recipient),
from: (logArgs: any) => bytes32ToAddress(logArgs.depositor),
},
isDeposit: true,
};

const relaysParamsv3p5: PartialContractEventParams = {
target: "",
topic:
"FilledRelay(bytes32,bytes32,uint256,uint256,uint256,uint256,uint256,uint32,uint32,bytes32,bytes32,bytes32,bytes32,bytes32,(bytes32,bytes32,uint256,uint8))",
abi: [
"event FilledRelay(bytes32 inputToken, bytes32 outputToken, uint256 inputAmount, uint256 outputAmount, uint256 repaymentChainId, uint256 indexed originChainId, uint256 indexed depositId, uint32 fillDeadline, uint32 exclusivityDeadline, bytes32 exclusiveRelayer, bytes32 indexed relayer, bytes32 depositor, bytes32 recipient, bytes32 messageHash, tuple(bytes32 updatedRecipient, bytes32 updatedMessageHash, uint256 updatedOutputAmount, uint8 fillType) relayExecutionInfo)"
],
logKeys: {
blockNumber: "blockNumber",
txHash: "transactionHash",
},
argKeys: {
amount: "outputAmount",
token: "outputToken",
},
argGetters: {
to: (logArgs: any) => bytes32ToAddress(logArgs.recipient),
from: (logArgs: any) => bytes32ToAddress(logArgs.depositor),
},
isDeposit: false,
};

// "Version 3" events
const depositParamsv3: PartialContractEventParams = {
target: "",
topic: "V3FundsDeposited(address,address,uint256,uint256,uint256,uint32,uint32,uint32,uint32,address,address,address,bytes)",
Expand Down Expand Up @@ -103,6 +154,7 @@ const relaysParamsv3: PartialContractEventParams = {
isDeposit: false,
};

// "Version 2.5" events
const depositParamsv2p5: PartialContractEventParams = {
target: "",
topic: "FundsDeposited(uint256,uint256,uint256,int64,uint32,uint32,address,address,address,bytes)",
Expand Down Expand Up @@ -142,6 +194,7 @@ const relaysParamsv2p5: PartialContractEventParams = {
isDeposit: false,
};

// "Version 2" events
const depositParamsv2: PartialContractEventParams = {
target: "",
topic: "FundsDeposited(uint256,uint256,uint256,uint64,uint32,uint32,address,address,address)",
Expand Down Expand Up @@ -230,6 +283,21 @@ const constructParams = (chain: SupportedChains) => {
target: chainConfig.spokePoolv2p5,
};
eventParams.push(finalRelaysParamsv3);

// "Version 3.5" events
// The v2.5 spoke pools are ProxyContracts that can be upgraded -- Across
// reuses these spoke addresses for v3.5 with the modified events
const finalDepositParamsv3p5 = {
...depositParamsv3p5,
target: chainConfig.spokePoolv2p5,
};
eventParams.push(finalDepositParamsv3p5);

const finalRelaysParamsv3p5 = {
...relaysParamsv3p5,
target: chainConfig.spokePoolv2p5,
};
eventParams.push(finalRelaysParamsv3p5);
}

return async (fromBlock: number, toBlock: number) =>
Expand Down