-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Gen-codecs from carbon 42559b8 branch * Add alias for bridge module * Add bridge to carbon query client * Add bridge queries and scaffolding for Axelar Bridge Client * WIP deposit test script * revert devnet changes * integrate Axelar bridge into existing getBridges * test deposit * Fix build error * Implement AxelarBridgeClient Withdraw rpc * sync codecs * Deposit with custom network * Add mantle rpc url * Refactor getBridges * gen codec for v2.47.0 * Fix mantle network * v0.11.13-beta.1 * Fix amino WithdrawTokenTx * Fix rpc url * Remove test script * Remove unnecessary code * Fix PR comments * Revert devnet network rpc changes * Fix hydrogen bridge blockchain * Update blockchain constants * Revert amino changes * Fix return type * Remove unused imports * Fix hydrogen transfers result formatter * Add fallback to formattedBlockchainName * Add error catching to axelar bridge connections query * Add test axelar withdraw script * Add bridge module * fix duration parsing for amino + fix duration to be string in eip712 types * remove old code for amino duration type parsing * Refactor common variable and withdraw params * Add typeCheck for Duration interface, remove duplicate code * Fix testnet config * Add relay fees query * Feat/2.50.0 codec (#516) * update verifyingContract hex due to validation from metamask * v0.11.15 * generate codec for v2.50.0 * regenerate bridge alias for new refund address msgs * remove deprecated oracleId field from assAsset msg in cdp --------- Co-authored-by: Randy <[email protected]> * revert rpcurls for devnet * v0.11.16-beta.1 * regen codec for new poly blacklist query (#518) * Refactor axelar bridge from connections * v0.11.16-beta.2 --------- Co-authored-by: huy9x101 <[email protected]> Co-authored-by: yan-soon <[email protected]> Co-authored-by: Thong Yuan Yu Sarah <[email protected]> Co-authored-by: Randy <[email protected]> Co-authored-by: Soon Xiang, Yan <[email protected]> Co-authored-by: Randy <[email protected]>
- Loading branch information
1 parent
8ef492f
commit 993fc0d
Showing
45 changed files
with
15,994 additions
and
723 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,51 @@ | ||
import BigNumber from "bignumber.js"; | ||
import * as BIP39 from "bip39"; | ||
import Long from "long"; | ||
import { BridgeModule, CarbonSDK, CoinModule } from "./_sdk"; | ||
import "./_setup"; | ||
|
||
(async () => { | ||
const mnemonics = process.env.MNEMONICS ?? BIP39.generateMnemonic(); | ||
console.log("mnemonics", mnemonics); | ||
|
||
const sdk = await CarbonSDK.instanceWithMnemonic(mnemonics, { network: CarbonSDK.Network.LocalHost }); | ||
console.log('sdk initialized') | ||
|
||
const externalTokensResult = await sdk.query.bridge.ExternalTokenAll({ bridgeId: new Long(0), chainId: '', denom: '' }) | ||
|
||
const externalToken = externalTokensResult.externalTokens[0] | ||
const externalTokenCarbonDenom = externalToken?.denom ?? '' | ||
|
||
const body = JSON.stringify({ | ||
address: sdk?.wallet?.bech32Address, | ||
coins: ['1000000000swth'], | ||
}) | ||
await fetch(sdk.networkConfig.faucetUrl, { method: 'POST', body }) | ||
console.log('Minted SWTH for gas') | ||
|
||
const tokenDp = sdk.token.getDecimals(externalTokenCarbonDenom) ?? 0 | ||
const params: CoinModule.MintTokenParams = { | ||
amount: new BigNumber(10000).shiftedBy(tokenDp), | ||
denom: externalTokenCarbonDenom, | ||
} | ||
const mintBrdgToken = await sdk.coin.mintToken(params) | ||
console.log('Minted brdg tokens', mintBrdgToken) | ||
|
||
const balancesResult = await sdk.query.coin.Balances({ address: sdk.wallet.bech32Address }) | ||
console.log('balances:', balancesResult) | ||
|
||
const withdrawParams: BridgeModule.WithdrawParams = { | ||
connectionId: externalToken?.connectionId ?? '', | ||
receiver: sdk.wallet.evmHexAddress, | ||
tokenDenom: externalToken?.denom ?? '', | ||
tokenAmount: new BigNumber(10).shiftedBy(tokenDp), | ||
relayDenom: 'swth', | ||
relayAmount: new BigNumber(100), | ||
expirySeconds: 1000, | ||
} | ||
const result = await sdk.bridge.withdraw(withdrawParams) | ||
|
||
console.log('withdraw tokens:', result); | ||
})().catch((e) => { | ||
console.log({ e }) | ||
}).finally(() => process.exit(0)); |
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
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,53 @@ | ||
import { NetworkConfigProvider } from "@carbon-sdk/constant"; | ||
import { ABIs } from "@carbon-sdk/eth"; | ||
import BigNumber from "bignumber.js"; | ||
import { ethers } from "ethers"; | ||
|
||
export interface AxelarBridgeClientOpts { | ||
configProvider: NetworkConfigProvider; | ||
} | ||
|
||
export interface DepositParams { | ||
contractAddress: string; | ||
senderAddress: string; | ||
receiverAddress: string; | ||
amount: BigNumber; | ||
depositTokenExternalAddress: string; | ||
rpcUrl: string; | ||
gasPriceGwei?: BigNumber; | ||
gasLimit?: BigNumber; | ||
signer: ethers.Signer; | ||
nonce?: number | ||
} | ||
|
||
export interface EthersTransactionResponse extends ethers.Transaction { | ||
wait: () => Promise<ethers.Transaction>; | ||
} | ||
|
||
export class AxelarBridgeClient { | ||
|
||
private constructor( | ||
public readonly configProvider: NetworkConfigProvider, | ||
) { } | ||
|
||
public static instance(opts: AxelarBridgeClientOpts) { | ||
const { configProvider } = opts | ||
return new AxelarBridgeClient(configProvider) | ||
} | ||
|
||
// lock deposit | ||
public async deposit(params: DepositParams): Promise<EthersTransactionResponse> { | ||
const { contractAddress, senderAddress, receiverAddress, depositTokenExternalAddress, amount, signer, rpcUrl } = params; | ||
const rpcProvider = new ethers.providers.JsonRpcProvider(rpcUrl) | ||
const contract = new ethers.Contract(contractAddress, ABIs.axelarBridge, rpcProvider) | ||
|
||
return await contract.connect(signer).deposit( | ||
senderAddress, // tokenSender | ||
receiverAddress, // carbonReceiver bech32Address | ||
depositTokenExternalAddress, // asset | ||
amount.toString(10), | ||
) | ||
} | ||
} | ||
|
||
export default AxelarBridgeClient |
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.