-
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 pull request #146 from fuseio/fuse-bridge
Add adapter for Fuse Bridge
- Loading branch information
Showing
3 changed files
with
136 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import { | ||
BridgeAdapter, | ||
ContractEventParams, | ||
PartialContractEventParams, | ||
} from "../../helpers/bridgeAdapter.type"; | ||
import { getTxDataFromEVMEventLogs } from "../../helpers/processTransactions"; | ||
|
||
const ercContracts = { | ||
ethereum: "0x95f51f18212c6bCFfB819fDB2035E5757954B7B9", | ||
polygon: "0x8f5D6332eD11338D2dA4fAAC6675e9A6757BeC8b", | ||
arbitrum: "0x081dF5af5d022D4A4a4520D4D0D336B8432fDBBb", | ||
optimism: "0x081dF5af5d022D4A4a4520D4D0D336B8432fDBBb", | ||
bsc: "0x081dF5af5d022D4A4a4520D4D0D336B8432fDBBb", | ||
} as { [chain: string]: string }; | ||
|
||
const nativeContracts = { | ||
polygon: "0xe453d6649643F1F460C371dC3D1da98F7922fe51", | ||
arbitrum: "0xe453d6649643F1F460C371dC3D1da98F7922fe51", | ||
optimism: "0xEEd9154F63f6F0044E6b00dDdEFD895b5B4ED580", | ||
bsc: "", | ||
ethereum: "", | ||
} as { [chain: string]: string }; | ||
|
||
const ercDepositEventParams: ContractEventParams = { | ||
target: null, | ||
topic: "SendToken(address,address,address,uint256)", | ||
abi: [ | ||
"event SendToken(address token, address from, address to, uint256 amount)", | ||
], | ||
argKeys: { | ||
token: "token", | ||
from: "from", | ||
amount: "amount", | ||
}, | ||
isDeposit: true, | ||
}; | ||
|
||
const ercWithdrawalEventParams: ContractEventParams = { | ||
target: null, | ||
topic: "ReceiveToken(address,address,uint256)", | ||
abi: [ | ||
"event ReceiveToken(address token, address to, uint256 amount)", | ||
], | ||
argKeys: { | ||
token: "token", | ||
from: "to", | ||
amount: "amount", | ||
}, | ||
isDeposit: false, | ||
}; | ||
|
||
const nativeWithdrawalEventParams: ContractEventParams = { | ||
target: null, | ||
topic: "WrapToken(address,address,uint16,address,uint256)", | ||
abi: [ | ||
"event WrapToken(address localToken, address remoteToken, uint16 remoteChainId, address to, uint256 amount)", | ||
], | ||
argKeys: { | ||
token: "localToken", | ||
from: "to", | ||
amount: "amount", | ||
}, | ||
isDeposit: false, | ||
}; | ||
|
||
const nativeDepositEventParams: ContractEventParams = { | ||
target: null, | ||
topic: "UnwrapToken(address,address,uint16,address,uint256)", | ||
abi: [ | ||
"event UnwrapToken(address localToken, address remoteToken, uint16 remoteChainId, address to, uint256 amount)", | ||
], | ||
argKeys: { | ||
token: "localToken", | ||
from: "from", | ||
amount: "amount", | ||
}, | ||
isDeposit: true, | ||
}; | ||
|
||
const constructParams = (chain: string) => { | ||
const eventParams: PartialContractEventParams[] = []; | ||
|
||
const ercContract = ercContracts[chain]; | ||
const ercDepositParams = { | ||
...ercDepositEventParams, | ||
target: ercContract, | ||
} | ||
const ercWithdrawParams = { | ||
...ercWithdrawalEventParams, | ||
target: ercContract, | ||
} | ||
const nativeContract = nativeContracts[chain]; | ||
if (nativeContract !== "") { | ||
const nativeDepositParams = { | ||
...nativeDepositEventParams, | ||
target: nativeContract, | ||
} | ||
const nativeWithdrawParams = { | ||
...nativeWithdrawalEventParams, | ||
target: nativeContract, | ||
} | ||
eventParams.push(nativeDepositParams, nativeWithdrawParams); | ||
} | ||
eventParams.push(ercDepositParams, ercWithdrawParams); | ||
return async (fromBlock: number, toBlock: number) => | ||
getTxDataFromEVMEventLogs("fuse", chain, fromBlock, toBlock, eventParams); | ||
}; | ||
|
||
const adapter: BridgeAdapter = { | ||
polygon: constructParams("polygon"), | ||
ethereum: constructParams("ethereum"), | ||
bsc: constructParams("bsc"), | ||
arbitrum: constructParams("arbitrum"), | ||
optimism: constructParams("optimism"), | ||
}; | ||
|
||
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
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