Skip to content

Commit

Permalink
Merge pull request #310 from evandrosaturnino/threshold-network-bridge
Browse files Browse the repository at this point in the history
Add threshold network
  • Loading branch information
vrtnd authored Dec 5, 2024
2 parents f7232f4 + 8b8ccf2 commit ed3597e
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/adapters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -149,6 +150,7 @@ export default {
layerswap,
hyperlane,
wormhole,
thresholdnetwork,
} as {
[bridge: string]: BridgeAdapter | AsyncBridgeAdapter;
};
73 changes: 73 additions & 0 deletions src/adapters/threshold-network/index.ts
Original file line number Diff line number Diff line change
@@ -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;
10 changes: 10 additions & 0 deletions src/data/bridgeNetworkData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];

0 comments on commit ed3597e

Please sign in to comment.