Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin'
Browse files Browse the repository at this point in the history
  • Loading branch information
vrtnd committed Feb 27, 2024
2 parents a2b84ff + 06f1d38 commit 477e00b
Show file tree
Hide file tree
Showing 9 changed files with 640 additions and 9 deletions.
55 changes: 55 additions & 0 deletions src/adapters/across/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,45 @@ const contracts = {

type SupportedChains = keyof typeof contracts;

const depositParamsv3: PartialContractEventParams = {
target: "",
topic: "V3FundsDeposited(address,address,uint256,uint256,uint256,uint32,uint32,uint32,uint32,address,address,address,bytes)",
abi: [
"event V3FundsDeposited(address inputToken,address outputToken,uint256 inputAmount,uint256 outputAmount,uint256 indexed destinationChainId,uint32 indexed depositId,uint32 quoteTimestamp,uint32 fillDeadline,uint32 exclusivityDeadline,address indexed depositor,address recipient,address exclusiveRelayer,bytes message)"
],
logKeys: {
blockNumber: "blockNumber",
txHash: "transactionHash",
},
argKeys: {
amount: "inputAmount",
to: "recipient",
from: "depositor",
token: "inputToken",
},
isDeposit: true,
};

const relaysParamsv3: PartialContractEventParams = {
target: "",
topic:
"FilledV3Relay(address,address,uint256,uint256,uint256,uint256,uint32,uint32,uint32,address,address,address,address,bytes,(address,bytes,uint256,uint8))",
abi: [
"event FilledV3Relay(address inputToken, address outputToken, uint256 inputAmount, uint256 outputAmount, uint256 repaymentChainId, uint256 indexed originChainId, uint32 indexed depositId, uint32 fillDeadline, uint32 exclusivityDeadline, address exclusiveRelayer, address indexed relayer, address depositor, address recipient, bytes message, tuple(address updatedRecipient, bytes updatedMessage, uint256 updatedOutputAmount, uint8 fillType) relayExecutionInfo)"
],
logKeys: {
blockNumber: "blockNumber",
txHash: "transactionHash",
},
argKeys: {
amount: "outputAmount",
to: "recipient",
from: "depositor",
token: "outputToken",
},
isDeposit: false,
};

const depositParamsv2p5: PartialContractEventParams = {
target: "",
topic: "FundsDeposited(uint256,uint256,uint256,int64,uint32,uint32,address,address,address,bytes)",
Expand Down Expand Up @@ -138,6 +177,7 @@ const constructParams = (chain: SupportedChains) => {

// New Spoke Pools
if ("spokePoolv2p5" in chainConfig) {
// "Version 2.5" events
const finalDepositParamsv2p5 = {
...depositParamsv2p5,
target: chainConfig.spokePoolv2p5,
Expand All @@ -149,6 +189,21 @@ const constructParams = (chain: SupportedChains) => {
target: chainConfig.spokePoolv2p5,
};
eventParams.push(finalRelaysParamsv2p5);

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

const finalRelaysParamsv3 = {
...relaysParamsv3,
target: chainConfig.spokePoolv2p5,
};
eventParams.push(finalRelaysParamsv3);
}

return async (fromBlock: number, toBlock: number) =>
Expand Down
4 changes: 4 additions & 0 deletions src/adapters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ import circle from "./circle";
import garden from "./garden";
import rootstock from "./rootstock";
import mode from "./mode";
import router from "./router";
import tokenbridge from "./rootstock-token-bridge";

export default {
polygon,
Expand Down Expand Up @@ -98,6 +100,8 @@ export default {
rootstock,
mode,
circle,
router,
tokenbridge,
} as {
[bridge: string]: BridgeAdapter;
};
130 changes: 130 additions & 0 deletions src/adapters/owlto/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import { BridgeAdapter, PartialContractEventParams } from "../../helpers/bridgeAdapter.type";
import { getTxDataFromEVMEventLogs } from "../../helpers/processTransactions";
import { constructTransferParams } from "../../helpers/eventParams";
import { Chain } from "@defillama/sdk/build/general";
import { getProvider } from "../../utils/provider";
import { EventData } from "../../utils/types";
import { PromisePool } from "@supercharge/promise-pool";

const retry = require("async-retry");

export const bridgesAddress = {
arbitrum: ["0x45A318273749d6eb00f5F6cA3bC7cD3De26D642A", "0x5e809A85Aa182A9921EDD10a4163745bb3e36284"],
arbitrum_nova: ["0x45A318273749d6eb00f5F6cA3bC7cD3De26D642A", "0x5e809A85Aa182A9921EDD10a4163745bb3e36284"],
ethereum: ["0x45A318273749d6eb00f5F6cA3bC7cD3De26D642A", "0x5e809A85Aa182A9921EDD10a4163745bb3e36284"],
bsc: ["0x45A318273749d6eb00f5F6cA3bC7cD3De26D642A", "0x5e809A85Aa182A9921EDD10a4163745bb3e36284"],
polygon: ["0x45A318273749d6eb00f5F6cA3bC7cD3De26D642A", "0x5e809A85Aa182A9921EDD10a4163745bb3e36284"],
optimism: ["0x45A318273749d6eb00f5F6cA3bC7cD3De26D642A", "0x5e809A85Aa182A9921EDD10a4163745bb3e36284"],
era: ["0x45A318273749d6eb00f5F6cA3bC7cD3De26D642A", "0x5e809A85Aa182A9921EDD10a4163745bb3e36284"],
polygon_zkevm: ["0x45A318273749d6eb00f5F6cA3bC7cD3De26D642A", "0x5e809A85Aa182A9921EDD10a4163745bb3e36284"],

base: ["0x45A318273749d6eb00f5F6cA3bC7cD3De26D642A", "0x5e809A85Aa182A9921EDD10a4163745bb3e36284"],
linea: ["0x45A318273749d6eb00f5F6cA3bC7cD3De26D642A", "0x5e809A85Aa182A9921EDD10a4163745bb3e36284"],
manta: ["0x45A318273749d6eb00f5F6cA3bC7cD3De26D642A", "0x5e809A85Aa182A9921EDD10a4163745bb3e36284"],
scroll: ["0x45A318273749d6eb00f5F6cA3bC7cD3De26D642A", "0x5e809A85Aa182A9921EDD10a4163745bb3e36284"],
mantle: ["0x45A318273749d6eb00f5F6cA3bC7cD3De26D642A", "0x5e809A85Aa182A9921EDD10a4163745bb3e36284"],

metis: ["0x45A318273749d6eb00f5F6cA3bC7cD3De26D642A", "0x5e809A85Aa182A9921EDD10a4163745bb3e36284"],
mode: ["0x45A318273749d6eb00f5F6cA3bC7cD3De26D642A", "0x5e809A85Aa182A9921EDD10a4163745bb3e36284"]

} as const;

type SupportedChains = keyof typeof bridgesAddress;

export const getNativeTokenTransfersFromHash = async (
chain: Chain,
hashes: string[],
address_old: string,
address_new: string,
nativeToken: string
) => {
const provider = getProvider(chain) as any;
const transactions = (
await Promise.all(
hashes.map(async (hash) => {
// TODO: add timeout
const tx = await provider.getTransaction(hash);
if (!tx) {
return;
}
const { blockNumber, from, to, value } = tx;
if (value <= 0) {
return;
}
if (!(address_old === from || address_old === to || address_new === from || address_new === to)) {
return;
}
const isDeposit = (address_old === to || address_new == to);
return {
blockNumber: blockNumber,
txHash: hash,
from: from,
to: to,
token: nativeToken,
amount: value,
isDeposit: isDeposit,
} as EventData;
})
)
).filter((tx) => tx) as EventData[];
return transactions;
};

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

const oldDepositParams = constructTransferParams(bridgeAddress[0], true, {}, {}, chain);
const oldWithdrawParams = constructTransferParams(bridgeAddress[0], false, {}, {}, chain);

const newDepositParams = constructTransferParams(bridgeAddress[1], true, {}, {}, chain);
const newWithdrawParams = constructTransferParams(bridgeAddress[1], false, {}, {}, chain);

eventParams = [oldDepositParams, oldWithdrawParams, newDepositParams, newWithdrawParams];

return async (fromBlock: number, toBlock: number) => {
const provider = getProvider(chain) as any;
const results: EventData[] = [];
const data = {} as any;
const blocknums = []
for (let i = fromBlock; i <= toBlock; i++) {
blocknums.push(i);
}

await PromisePool.withConcurrency(10)
.for(blocknums)
.process(async (blocknum) => {
const block = await retry(async () => provider.getBlock(blocknum), { retries: 3 });
const r = await getNativeTokenTransfersFromHash(chain as Chain, block.transactions, bridgeAddress[0], bridgeAddress[1], "0x0000000000000000000000000000000000000000")
data[blocknum] = r;
});
const eventDatas = Object.values(data) as EventData[][];
for (const eventData of eventDatas) {
results.push(...eventData);
}
const r = await getTxDataFromEVMEventLogs("owlto", chain as Chain, fromBlock, toBlock, eventParams);
results.push(...r);
return results;
};
}


const adapter: BridgeAdapter = {
arbitrum: constructParams("arbitrum"),
"arbitrum nova": constructParams("arbitrum_nova"),
ethereum: constructParams("ethereum"),
optimism: constructParams("optimism"),
metis: constructParams("metis"),
polygon: constructParams("polygon"),
"polygon zkevm": constructParams("polygon_zkevm"),
"zksync era": constructParams("era"),
bsc: constructParams("bsc"),

base: constructParams("base"),
linea: constructParams("linea"),
scroll: constructParams("scroll"),
mantle: constructParams("mantle"),
manta: constructParams("manta"),
};

export default adapter;
72 changes: 72 additions & 0 deletions src/adapters/rootstock-token-bridge/constant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
export const supportedTokens = {
DAI: {
address: {
ethereum: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
rootstock: "0x6b1a73d547f4009a26b8485b63d7015d248ad406", // For Rootstock it is rDAI
},
decimal: {
ethereum: 18,
rootstock: 18
}
},
USDC: {
address: {
ethereum: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
rootstock: "0x1BDa44fda023F2af8280a16FD1b01D1A493BA6c4", // For Rootstock it is rUSDC
},
decimal: {
ethereum: 6,
rootstock: 18
}
},
USDT: {
address: {
ethereum: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
rootstock: "0xef213441a85df4d7acbdae0cf78004e1e486bb96", // For Rootstock it is rUSDT
},
decimal: {
ethereum: 6,
rootstock: 18
}
},
LINK: {
address: {
ethereum: "0x514910771AF9Ca656af840dff83E8264EcF986CA",
rootstock: "0x14adae34bef7ca957ce2dde5add97ea050123827", // For Rootstock it is rLINK
},
decimal: {
ethereum: 18,
rootstock: 18
}
},
BUND: {
address: {
ethereum: "0x8D3E855f3f55109D473735aB76F753218400fe96",
rootstock: "0x4991516DF6053121121274397A8C1DAD608bc95B", // For Rootstock it is rBUND
},
decimal: {
ethereum: 18,
rootstock: 18
}
},
DOC: {
address: {
ethereum: "0x69f6d4D4813F8e2e618DAE7572e04b6D5329E207", // For Ethereum it is eDOC
rootstock: "0xE700691Da7B9851F2F35f8b8182C69C53ccad9DB", // For Rootstock it is DOC
},
decimal: {
ethereum: 18,
rootstock: 18
}
},
RIF: {
address: {
ethereum: "0x73c08467E23F7DCB7dDBbc8d05041B74467A498A", // For Ethereum it is eRIF
rootstock: "0x2aCc95758f8b5F583470bA265Eb685a8f45fC9D5", // For Rootstock it is RIF
},
decimal: {
ethereum: 18,
rootstock: 18
}
},
}
85 changes: 85 additions & 0 deletions src/adapters/rootstock-token-bridge/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import BigNumber from "bignumber.js";
import { BridgeAdapter, ContractEventParams } from "../../helpers/bridgeAdapter.type";
import { getTxDataFromEVMEventLogs } from "../../helpers/processTransactions";
import { supportedTokens} from "./constant";
import { ethers } from "ethers";

const bridge = "0x9d11937e2179dc5270aa86a3f8143232d6da0e69";

const getSupportedToken = (token: string) => {
if (token) {
return Object.values(supportedTokens).find( st => st.address.ethereum == token || st.address.rootstock == token)
}
}

const crossEventParams: ContractEventParams = {
target: bridge,
topic: "Cross(address,address,address,uint256,bytes)",
abi: ["event Cross(address indexed _tokenAddress, address indexed _from, address indexed _to, uint256 _amount, bytes _userData)"],
logKeys: {
blockNumber: "blockNumber",
txHash: "transactionHash",
},
fixedEventData: {
to: bridge
},
argKeys: {
from: "_from",
amount: "_amount",
},
inputDataExtraction: {
inputDataABI: [
"function receiveTokensTo(address tokenToUse, address to, uint256 amount)",
],
inputDataFnName: "receiveTokensTo",
inputDataKeys: {
token: "tokenToUse",
},
},
isDeposit: false,
};


const claimedEventParams: ContractEventParams = {
target: bridge,
topic: "Claimed(bytes32,address,address,address,uint256,bytes32,uint256,address,address,uint256)",
abi: ["event Claimed(bytes32 indexed _transactionHash, address indexed _originalTokenAddress, address indexed _to, address _sender, uint256 _amount, bytes32 _blockHash, uint256 _logIndex, address _reciever, address _relayer, uint256 _fee)"],
logKeys: {
blockNumber: "blockNumber",
txHash: "transactionHash",
},
fixedEventData: {
from: bridge,
},
argKeys: {
amount: "_amount",
to: "_to",
token: "_originalTokenAddress"
},
isDeposit: true,
};

const constructParams = () => {
const eventParams = [crossEventParams, claimedEventParams];
return async (fromBlock: number, toBlock: number) => {
const logs = await getTxDataFromEVMEventLogs("tokenbridge", "rsk", fromBlock, toBlock, eventParams);

logs.forEach((log) => {
const supportedToken = getSupportedToken(log.token)
if (log.isDeposit && supportedToken) {
log.token = supportedToken.address.rootstock;
const decimals = supportedToken.decimal.rootstock - supportedToken.decimal.ethereum;
log.amount = log.amount?.mul(ethers.BigNumber.from(10).pow(decimals));
}
log.token = logs[0]?.token.toLowerCase();
});

return logs;
};
};

const adapter: BridgeAdapter = {
rootstock: constructParams(),
};

export default adapter;
Loading

0 comments on commit 477e00b

Please sign in to comment.