Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add scroll and bsc
Browse files Browse the repository at this point in the history
npty committed Jan 10, 2024
1 parent 1c21635 commit ef7ca39
Showing 1 changed file with 70 additions and 69 deletions.
139 changes: 70 additions & 69 deletions src/adapters/squid/index.ts
Original file line number Diff line number Diff line change
@@ -1,100 +1,101 @@
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";
import { fetchAssets, getTokenAddress} from "./utils";
import { fetchAssets, getTokenAddress } from "./utils";
import { axelarGatewayAddresses, squidRouterAddress } from "./constants";


const constructGatewayWithdrawalParams = (assets: any[], chain: string) => {
let GatewayWithdrawalParams: PartialContractEventParams;

return GatewayWithdrawalParams = {
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",
const constructGatewayWithdrawalParams = (assets: any[], chain: string) => {
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",
// 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) => getTokenAddress(log.symbol, chain, assets)
},
isDeposit: false,

};

}


const constructGatewayDepositParams = (assets: any[], chain: string) => {
let GatewayDepositParams: PartialContractEventParams;
},
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) => getTokenAddress(log.symbol, chain, assets),
},
isDeposit: false,
};
};

return GatewayDepositParams = {
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",
const constructGatewayDepositParams = (assets: any[], chain: string) => {
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",
// token: "token"
},
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,
};
}

},
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 constructParams = (chain: string) => {

return async (fromBlock: number, toBlock: number) => {
let eventParams = [] as PartialContractEventParams[];
// fetch all assets from axelarscan
const assets = await fetchAssets();

const GatewayDepositParams = constructGatewayDepositParams(assets, chain);
const deposit = {...GatewayDepositParams, target: axelarGatewayAddresses[chain], };

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

const GatewayWithdrawalParams = constructGatewayWithdrawalParams(assets, chain);
const withdraw = { ...GatewayWithdrawalParams, target: axelarGatewayAddresses[chain] };

eventParams.push(deposit, withdraw);

return getTxDataFromEVMEventLogs("squid", chain as Chain, fromBlock, toBlock, eventParams);
}

};
};

const adapter: BridgeAdapter = {
polygon: constructParams("polygon"),
fantom: constructParams("fantom"),
avalanche: constructParams("avax"),
// bsc: constructParams("bsc"),
bsc: constructParams("bsc"),
scroll: constructParams("scroll"),
ethereum: constructParams("ethereum"),
arbitrum: constructParams("arbitrum"),
base: constructParams("base"),

0 comments on commit ef7ca39

Please sign in to comment.