Skip to content

Commit

Permalink
Merge pull request #37 from DefiLlama/h3lio5/master
Browse files Browse the repository at this point in the history
H3lio5/master
  • Loading branch information
vrtnd authored Aug 22, 2023
2 parents 7294890 + d434a26 commit 86d915d
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/adapters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import meson from "./meson";
import base from "./base";
import mantle from "./mantle";
import neuron from "./neuron";
import squidrouter from "./squidrouter"

export default {
polygon,
Expand Down Expand Up @@ -66,6 +67,7 @@ export default {
base,
mantle,
neuron,
squidrouter,
} as {
[bridge: string]: BridgeAdapter;
};
102 changes: 102 additions & 0 deletions src/adapters/squidrouter/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { Chain } from "@defillama/sdk/build/general";
import { BridgeAdapter, PartialContractEventParams } from "../../helpers/bridgeAdapter.type";
import { constructTransferParams } from "../../helpers/eventParams";
import { getTxDataFromEVMEventLogs } from "../../helpers/processTransactions";
import { ethers } from "ethers";

const squidRouterAddress = "0xce16F69375520ab01377ce7B88f5BA8C48F8D666";

const axelarGatewayAddresses = {
ethereum: "0x4F4495243837681061C4743b74B3eEdf548D56A5",
bsc: "0x304acf330bbE08d1e512eefaa92F6a57871fD895",
polygon: "0x6f015F16De9fC8791b234eF68D486d2bF203FBA8",
avax: "0x5029C0EFf6C34351a0CEc334542cDb22c7928f78",
fantom: "0x304acf330bbE08d1e512eefaa92F6a57871fD895",
arbitrum: "0xe432150cce91c13a887f7D836923d5597adD8E31",
base: "0xe432150cce91c13a887f7d836923d5597add8e31",
linea: "0xe432150cce91c13a887f7d836923d5597add8e31",
celo: "0xe432150cce91c13a887f7d836923d5597add8e31",
moonbeam: "0x4F4495243837681061C4743b74B3eEdf548D56A5",
kava: "0xe432150cce91c13a887f7D836923d5597adD8E31",
filecoin: "0xe432150cce91c13a887f7D836923d5597adD8E31"
} as {
[chain: string]: string;
};


const GatewayWithdrawalParams: PartialContractEventParams = {
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",
// token: "token"
},
argKeys: {
from: "payload",
amount: "amount",
to: "destinationContractAddress",
token: "symbol"
},
argGetters: {
from: (log: any) => "0x".concat(log.payload.substr(90,40)), // note: this is not the real sender address
amount: (log: any) => log.amount,
to: (log: any) => "0x".concat(log.payload.substr(log.payload.lastIndexOf(log.payload.substr(90,40)),40)),
token: (log: any) => log.symbol,
},
isDeposit: false,

};

const GatewayDepositParams: PartialContractEventParams = {
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",
// token: "token"
},
argKeys: {
from: "sourceAddress",
amount: "amount",
to: "contractAddress",
token: "symbol"
},
isDeposit: true,
};


const constructParams = (chain: string) => {
let eventParams = [] as PartialContractEventParams[];


const deposit = {...GatewayDepositParams, target: axelarGatewayAddresses[chain], };
const withdraw = {...GatewayWithdrawalParams, target: axelarGatewayAddresses[chain], };


eventParams.push(deposit, withdraw);

return async (fromBlock: number, toBlock: number) =>
await getTxDataFromEVMEventLogs("squidrouter", chain as Chain, fromBlock, toBlock, eventParams);
};

const adapter: BridgeAdapter = {
polygon: constructParams("polygon"),
fantom: constructParams("fantom"),
avalanche: constructParams("avax"),
bsc: constructParams("bsc"),
ethereum: constructParams("ethereum"),
arbitrum: constructParams("arbitrum"),
base: constructParams("base"),
linea: constructParams("linea"),
celo: constructParams("celo"),
moonbeam: constructParams("moonbeam"),
kava: constructParams("kava"),
filecoin: constructParams("filecoin")
};

export default adapter;
25 changes: 25 additions & 0 deletions src/data/bridgeNetworkData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,4 +471,29 @@ export default [
// url: "",
// chains: ["Arbitrum", "Linea", "Optimism", "Base"],
// },
{
id: 32,
displayName: "SquidRouter",
bridgeDbName: "squidrouter",
iconLink: "icons:axelar",
largeTxThreshold: 10000,
url: "",
chains: [
"Ethereum",
"Polygon",
"Avalanche",
"BSC",
"Fantom",
"Arbitrum",
"Base",
"Linea",
"Celo",
"Moonbeam",
"Kava",
"Filecoin",
],
chainMapping: {
avalanche: "avax", // this is needed temporarily, need to fix and remove
},
},
] as BridgeNetwork[];
2 changes: 2 additions & 0 deletions src/helpers/processTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ export const getTxDataFromEVMEventLogs = async (
Object.entries(argKeys).map(([eventKey, argKey]) => {
// @ts-ignore
const value = argGetters?.[eventKey](args) || get(args, argKey);
//// DEBUG
// console.log(argGetters?.[eventKey]);
if (typeof value !== EventKeyTypes[eventKey] && !Array.isArray(value)) {
throw new Error(
`Type of ${eventKey} retrieved using ${argKey} is ${typeof value} when it must be ${
Expand Down

0 comments on commit 86d915d

Please sign in to comment.