diff --git a/src/adapters/index.ts b/src/adapters/index.ts index 6df1efe4..17da78d0 100644 --- a/src/adapters/index.ts +++ b/src/adapters/index.ts @@ -73,6 +73,7 @@ import retrobridge from "./retrobridge"; import layerswap from "./layerswap"; import hyperlane from "./hyperlane"; import wormhole from "./wormhole"; +import thresholdnetwork from "./threshold-network"; export default { polygon, @@ -149,6 +150,7 @@ export default { layerswap, hyperlane, wormhole, + thresholdnetwork, } as { [bridge: string]: BridgeAdapter | AsyncBridgeAdapter; }; diff --git a/src/adapters/threshold-network/index.ts b/src/adapters/threshold-network/index.ts new file mode 100644 index 00000000..24d905ae --- /dev/null +++ b/src/adapters/threshold-network/index.ts @@ -0,0 +1,73 @@ +import { BridgeAdapter, ContractEventParams } from "../../helpers/bridgeAdapter.type"; +import { getTxDataFromEVMEventLogs } from "../../helpers/processTransactions"; +import { EventData } from "../../utils/types"; + +const bridge = "0x5e4861a80B55f035D899f66772117F00FA0E8e7B"; +const tbtc = "0x18084fbA666a33d37592fA2633fD49a74DD93a88"; +const tbtcVault = "0x9c070027cdc9dc8f82416b2e5314e11dfb4fe3cd"; + +export type ExtendedContractEventParams = ContractEventParams & { + extraData?: { [key: string]: any }; +}; + +const mintedEventParams: ContractEventParams = { + target: tbtcVault, + topic: "Minted(address,uint256)", + abi: ["event Minted(address indexed to, uint256 amount)"], + logKeys: { + blockNumber: "blockNumber", + txHash: "transactionHash", + }, + fixedEventData: { + token: tbtc, + from: bridge, + }, + argKeys: { + to: "to", + amount: "amount", + }, + isDeposit: true, +}; + +const redeemEventParams: ContractEventParams = { + target: tbtcVault, + topic: "Unminted(address,uint256)", + abi: ["event Unminted(address indexed from, uint256 amount)"], + logKeys: { + blockNumber: "blockNumber", + txHash: "transactionHash", + }, + fixedEventData: { + token: tbtc, + to: "", + }, + argKeys: { + from: "from", + amount: "amount", + }, + isDeposit: false, +}; + +const constructParams = (chain: string) => { + const eventParams = [mintedEventParams, redeemEventParams]; + return async (fromBlock: number, toBlock: number) => { + const evmEventLogs = await getTxDataFromEVMEventLogs("thresholdnetwork", chain, fromBlock, toBlock, eventParams); + + const mintAndRedeemEventLogs: EventData[] = []; + evmEventLogs.forEach((eventLog) => { + if (eventLog.isDeposit) { + !eventLog.amount.eq(0) && mintAndRedeemEventLogs.push(eventLog); + } else { + mintAndRedeemEventLogs.push(eventLog); + } + }); + + return mintAndRedeemEventLogs; + }; +}; + +const adapter: BridgeAdapter = { + ethereum: constructParams("ethereum"), +}; + +export default adapter; diff --git a/src/data/bridgeNetworkData.ts b/src/data/bridgeNetworkData.ts index 3b4e6bb9..acc5237e 100644 --- a/src/data/bridgeNetworkData.ts +++ b/src/data/bridgeNetworkData.ts @@ -1730,4 +1730,14 @@ export default [ avalanche: "avax", }, }, + { + id: 78, + displayName: "Threshold Network", + bridgeDbName: "thresholdnetwork", + iconLink: "icons:threshold-network", + largeTxThreshold: 10000, + url: "https://threshold.network/", + chains: ["Ethereum", "Bitcoin"], + destinationChain: "Bitcoin", + }, ] as BridgeNetwork[];