-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin'
- Loading branch information
Showing
9 changed files
with
640 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.