Skip to content

Commit

Permalink
Merge pull request #330 from rjt-uma/patch-2
Browse files Browse the repository at this point in the history
adding v3p5 events to across adapter
  • Loading branch information
0xngmi authored Feb 6, 2025
2 parents 7972328 + 37ef1f4 commit 6d64d74
Showing 1 changed file with 68 additions and 0 deletions.
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

0 comments on commit 6d64d74

Please sign in to comment.