Skip to content

Commit

Permalink
Merge pull request #313 from nickp96/squid_coral_implementation
Browse files Browse the repository at this point in the history
squid coral + updated gmp
  • Loading branch information
vrtnd authored Dec 12, 2024
2 parents e081563 + ca91e7d commit 95dcf47
Show file tree
Hide file tree
Showing 4 changed files with 299 additions and 38 deletions.
48 changes: 48 additions & 0 deletions src/adapters/squid/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,52 @@ export const axelarGatewayAddresses = {
immutable: "0xe432150cce91c13a887f7D836923d5597adD8E31",
} as {
[chain: string]: string;
};

export const coralSpokeAddresses = {
default: "0xA4cE01bD7Dd91DA968a7C4A8D04282a3f5eA06bB",
} as {
[chain: string]: string;
};

export const stablecoins = {
USDC: {
ethereum: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
polygon: "0x2791bca1f2de4661ed88a30c99a7a9449aa84174",
arbitrum: "0xff970a61a04b1ca14834a43f5de4533ebddb5cc8",
},
USDT: {
ethereum: "0xdac17f958d2ee523a2206206994597c13d831ec7",
polygon: "0xc2132d05d31c914a87c6611c10748aeb04b58e8f",
arbitrum: "0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9",
}
};

export const chainIdToName: { [key: string]: string } = {
"0x1": "ethereum",
"0x38": "bsc",
"0x89": "polygon",
"0xa4b1": "arbitrum",
"0xa": "optimism",
"0x2105": "base",
"0xe708": "linea",
"0x504": "moonbeam",
"0xa86a": "avalanche",
"0xfa": "fantom",
// Add other chains as needed
};

export const chainNameMapping: { [key: string]: string } = {
avax: "avalanche",
ethereum: "ethereum",
polygon: "polygon",
arbitrum: "arbitrum",
optimism: "optimism",
base: "base",
linea: "linea",
moonbeam: "moonbeam",
bsc: "bsc",
fantom: "fantom",
blast: "blast",
fraxtal: "fraxtal"
};
136 changes: 100 additions & 36 deletions src/adapters/squid/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { Chain } from "@defillama/sdk/build/general";
import { BridgeAdapter, PartialContractEventParams } from "../../helpers/bridgeAdapter.type";
import { getTxDataFromEVMEventLogs } from "../../helpers/processTransactions";
import { ethers } from "ethers";
import { fetchAssets, getTokenAddress} from "./utils";
import { axelarGatewayAddresses, squidRouterAddresses } from "./constants";
import { fetchAssets, getTokenAddress, getTokenId } from "./utils";
import { axelarGatewayAddresses, squidRouterAddresses, coralSpokeAddresses, stablecoins } from "./constants";
import { isStablecoin } from "./utils";


const constructGatewayWithdrawalParams = (assets: any[], chain: string) => {
const squidRouterAddress = squidRouterAddresses[chain as keyof typeof squidRouterAddresses] || squidRouterAddresses.default;
Expand Down Expand Up @@ -31,48 +33,111 @@ const constructGatewayWithdrawalParams = (assets: any[], chain: string) => {
},
isDeposit: false,
};
}
};

const constructGatewayDepositParams = (assets: any[], chain: string) => {
const squidRouterAddress = squidRouterAddresses[chain as keyof typeof squidRouterAddresses] || squidRouterAddresses.default;

return {
target: "",
topic: "ContractCallApprovedWithMint(bytes32,string,string,address,bytes32,string,uint256,bytes32,uint256)",
topics: [ethers.utils.id("ContractCallApprovedWithMint(bytes32,string,string,address,bytes32,string,uint256,bytes32,uint256)"), null, ethers.utils.hexZeroPad(squidRouterAddress,32)],
abi: ["event ContractCallApprovedWithMint(bytes32 indexed commandId, string sourceChain, string sourceAddress, address indexed contractAddress, bytes32 indexed payloadHash, string symbol, uint256 amount, bytes32 sourceTxHash, uint256 sourceEventIndex)"],
logKeys: {
blockNumber: "blockNumber",
txHash: "transactionHash",
},
argKeys: {
from: "sourceAddress",
amount: "amount",
to: "contractAddress",
token: "symbol"
},
argGetters: {
from: (log: any) => log.sourceAddress,
amount: (log: any) => log.amount,
to: (log: any) => log.contractAddress,
token: (log: any) => getTokenAddress(log.symbol, chain, assets)
},
isDeposit: true,
};
}
const squidRouterAddress = squidRouterAddresses[chain as keyof typeof squidRouterAddresses] || squidRouterAddresses.default;

return {
target: "",
topic: "ContractCallWithToken(address,string,string,bytes32,bytes,string,uint256)",
topics: [ethers.utils.id("ContractCallWithToken(address,string,string,bytes32,bytes,string,uint256)"), ethers.utils.hexZeroPad(squidRouterAddress,32)],
abi: ["event ContractCallWithToken(address indexed sender, string destinationChain, string destinationContractAddress, bytes32 indexed payloadHash, bytes payload, string symbol, uint256 amount)"],
logKeys: {
blockNumber: "blockNumber",
txHash: "transactionHash",
},
argKeys: {
from: "payload",
amount: "amount",
to: "destinationContractAddress",
token: "symbol"
},
argGetters: {
from: (log: any) => "0x".concat(log.payload.substr(90,40)),
amount: (log: any) => log.amount,
to: (log: any) => log.destinationContractAddress,
token: (log: any) => getTokenAddress(log.symbol, chain, assets),
is_usd_volume: (log: any) => isStablecoin(log.symbol, chain)
},
isDeposit: true,
};
};

const constructCoralWithdrawParams = (assets: any[], chain: string) => {
return {
target: coralSpokeAddresses.default,
topic: "OrderCreated(bytes32,(address,address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes32))",
topics: [ethers.utils.id("OrderCreated(bytes32,(address,address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes32))")],
abi: ["event OrderCreated(bytes32 indexed orderHash, tuple(address fromAddress, address toAddress, address filler, address fromToken, address toToken, uint256 expiry, uint256 fromAmount, uint256 fillAmount, uint256 feeRate, uint256 fromChain, uint256 toChain, bytes32 postHookHash) order)"],
logKeys: {
blockNumber: "blockNumber",
txHash: "transactionHash",
},
argKeys: {
from: "args",
amount: "args",
to: "args",
token: "args"
},
argGetters: {
from: (log: any) => log[1].fromAddress,
amount: (log: any) => log[1].fromAmount,
to: (log: any) => log[1].toAddress,
token: (log: any) => getTokenAddress(log[1].fromToken, chain, assets),
is_usd_volume: (log: any) => isStablecoin(log[1].fromToken, chain)
},
isDeposit: false,
};
};

const constructCoralDepositParams = (assets: any[], chain: string) => {
return {
target: coralSpokeAddresses.default,
topic: "OrderFilled(bytes32,(address,address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes32))",
topics: [ethers.utils.id("OrderFilled(bytes32,(address,address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes32))")],
abi: ["event OrderFilled(bytes32 indexed orderHash, tuple(address fromAddress, address toAddress, address filler, address fromToken, address toToken, uint256 expiry, uint256 fromAmount, uint256 fillAmount, uint256 feeRate, uint256 fromChain, uint256 toChain, bytes32 postHookHash) order)"],
logKeys: {
blockNumber: "blockNumber",
txHash: "transactionHash",
},
argKeys: {
from: "args",
amount: "args",
to: "args",
token: "args"
},
argGetters: {
from: (log: any) => log[1].fromAddress,
amount: (log: any) => log[1].fromAmount,
to: (log: any) => log[1].toAddress,
token: (log: any) => getTokenAddress(log[1].fromToken, chain, assets),
is_usd_volume: (log: any) => isStablecoin(log[1].fromToken, chain)
},
isDeposit: true,
};
};

const constructParams = (chain: string) => {
return async (fromBlock: number, toBlock: number) => {
let eventParams = [] as PartialContractEventParams[];
const assets = await fetchAssets();
const eventParams = [];

// Gateway params
const gatewayDepositParams = constructGatewayDepositParams(assets, chain);
const gatewayWithdrawalParams = constructGatewayWithdrawalParams(assets, chain);

const deposit = {...gatewayDepositParams, target: axelarGatewayAddresses[chain]};
const withdraw = {...gatewayWithdrawalParams, target: axelarGatewayAddresses[chain]};

const GatewayDepositParams = constructGatewayDepositParams(assets, chain);
const deposit = {...GatewayDepositParams, target: axelarGatewayAddresses[chain]};
// Coral params
const coralDepositParams = constructCoralDepositParams(assets, chain);
const coralWithdrawParams = constructCoralWithdrawParams(assets, chain);

const GatewayWithdrawalParams = constructGatewayWithdrawalParams(assets, chain);
const withdraw = {...GatewayWithdrawalParams, target: axelarGatewayAddresses[chain]};
const coralDeposit = {...coralDepositParams, target: coralSpokeAddresses.default};
const coralWithdraw = {...coralWithdrawParams, target: coralSpokeAddresses.default};

eventParams.push(deposit, withdraw);
eventParams.push(deposit, withdraw, coralDeposit, coralWithdraw);

return getTxDataFromEVMEventLogs("squid", chain as Chain, fromBlock, toBlock, eventParams);
}
Expand All @@ -93,7 +158,6 @@ const adapter: BridgeAdapter = {
filecoin: constructParams("filecoin"),
optimism: constructParams("optimism"),
mantle: constructParams("mantle"),
//new chains
scroll: constructParams("scroll"),
blast: constructParams("blast"),
fraxtal: constructParams("fraxtal"),
Expand Down
Loading

0 comments on commit 95dcf47

Please sign in to comment.