-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
14 changed files
with
150 additions
and
47 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,37 @@ | ||
import { JsonRpcProvider } from '@ethersproject/providers'; | ||
import { Wallet } from 'ethers'; | ||
import { parseUnits } from 'ethers/lib/utils'; | ||
import assert from 'assert'; | ||
import dotenv from 'dotenv'; | ||
|
||
import { ETH_RPC } from '../src/consts'; | ||
import { bridgeToken } from './utils'; | ||
|
||
dotenv.config(); | ||
|
||
(async () => { | ||
const key = process.env.ACALA_PRIVATE_KEY; | ||
assert(key, 'KEY is required'); | ||
|
||
const provider = new JsonRpcProvider(ETH_RPC.BSC); | ||
const wallet = new Wallet(key, provider); | ||
|
||
const srcChain = 'bsc'; | ||
const dstChain = 'acala'; | ||
const dstAddr = '0xb0D205eB2355795e7F95B02E23e030FacEa1E002'; | ||
const DAI_BSC_ADDR = '0x3413a030EF81a3dD5a302F4B4D11d911e12ed337'; | ||
const DAI_DECIMALS = 18; | ||
const amount = parseUnits('10.2', DAI_DECIMALS); | ||
|
||
const receipt = await bridgeToken( | ||
wallet, | ||
srcChain, | ||
dstChain, | ||
dstAddr, | ||
DAI_BSC_ADDR, | ||
amount, | ||
); | ||
|
||
console.log(`txHash: ${receipt.transactionHash}`); | ||
assert(receipt.status === 1, 'tx failed!'); | ||
})(); |
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,30 @@ | ||
import { BigNumberish, ContractReceipt, Wallet } from 'ethers'; | ||
import { CONTRACTS, ChainName, hexToUint8Array, transferFromEth, tryNativeToHexString } from '@certusone/wormhole-sdk'; | ||
import assert from 'assert'; | ||
|
||
export const bridgeToken = async ( | ||
signer: Wallet, | ||
srcChain: ChainName, | ||
dstChain: ChainName, | ||
dstAddr: string, | ||
sourceTokenAddr: string, | ||
amount: BigNumberish, | ||
): Promise<ContractReceipt> => { | ||
const dstChainHex = tryNativeToHexString(dstAddr, dstChain); | ||
const dstChainUint8 = hexToUint8Array(dstChainHex); | ||
|
||
const tokenBridgeAddr = CONTRACTS.MAINNET[srcChain].token_bridge; | ||
assert(tokenBridgeAddr, 'token bridge address not found'); | ||
|
||
console.log(`sending bridging tx with wallet ${signer.address} and amount ${amount} ...`); | ||
const receipt = await transferFromEth( | ||
tokenBridgeAddr, | ||
signer, | ||
sourceTokenAddr, | ||
amount, | ||
dstChain, | ||
dstChainUint8, | ||
); | ||
|
||
return receipt; | ||
}; |
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
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
Oops, something went wrong.