-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #310 from evandrosaturnino/threshold-network-bridge
Add threshold network
- Loading branch information
Showing
3 changed files
with
85 additions
and
0 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
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; |
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