diff --git a/bridge_ui/src/hooks/useHandleAttest.tsx b/bridge_ui/src/hooks/useHandleAttest.tsx index d343a7ab2..f46ade1ea 100644 --- a/bridge_ui/src/hooks/useHandleAttest.tsx +++ b/bridge_ui/src/hooks/useHandleAttest.tsx @@ -50,7 +50,7 @@ import { isEVMChain } from "../utils/ethereum"; import { getSignedVAAWithRetry } from "../utils/getSignedVAAWithRetry"; import parseError from "../utils/parseError"; import { signSendAndConfirm } from "../utils/solana"; -import { waitForTerraExecution } from "../utils/terra"; +import { postWithFees, waitForTerraExecution } from "../utils/terra"; async function evm( dispatch: any, @@ -160,11 +160,12 @@ async function terra( ) { dispatch(setIsSending(true)); try { - const result = await attestFromTerra( + const msg = await attestFromTerra( TERRA_TOKEN_BRIDGE_ADDRESS, - wallet, + wallet.terraAddress, asset ); + const result = await postWithFees(wallet, [msg], "Create Wrapped"); const info = await waitForTerraExecution(result); dispatch(setAttestTx({ id: info.txhash, block: info.height })); enqueueSnackbar(null, { diff --git a/bridge_ui/src/hooks/useHandleCreateWrapped.tsx b/bridge_ui/src/hooks/useHandleCreateWrapped.tsx index 602fd043b..8b875acc1 100644 --- a/bridge_ui/src/hooks/useHandleCreateWrapped.tsx +++ b/bridge_ui/src/hooks/useHandleCreateWrapped.tsx @@ -36,6 +36,7 @@ import { isEVMChain } from "../utils/ethereum"; import parseError from "../utils/parseError"; import { signSendAndConfirm } from "../utils/solana"; import { Alert } from "@material-ui/lab"; +import { postWithFees } from "../utils/terra"; async function evm( dispatch: any, @@ -119,10 +120,11 @@ async function terra( wallet.terraAddress, signedVAA ); - const result = await wallet.post({ - msgs: [msg], - memo: "Wormhole - Create Wrapped", - }); + const result = await postWithFees( + wallet, + [msg], + "Wormhole - Create Wrapped" + ); dispatch( setCreateTx({ id: result.result.txhash, block: result.result.height }) ); diff --git a/bridge_ui/src/hooks/useHandleRedeem.tsx b/bridge_ui/src/hooks/useHandleRedeem.tsx index 6866707ef..fc3cde7f6 100644 --- a/bridge_ui/src/hooks/useHandleRedeem.tsx +++ b/bridge_ui/src/hooks/useHandleRedeem.tsx @@ -38,6 +38,7 @@ import { isEVMChain } from "../utils/ethereum"; import parseError from "../utils/parseError"; import { signSendAndConfirm } from "../utils/solana"; import { Alert } from "@material-ui/lab"; +import { postWithFees } from "../utils/terra"; async function evm( dispatch: any, @@ -138,10 +139,11 @@ async function terra( wallet.terraAddress, signedVAA ); - const result = await wallet.post({ - msgs: [msg], - memo: "Wormhole - Complete Transfer", - }); + const result = await postWithFees( + wallet, + [msg], + "Wormhole - Complete Transfer" + ); dispatch( setRedeemTx({ id: result.result.txhash, block: result.result.height }) ); diff --git a/bridge_ui/src/hooks/useHandleTransfer.tsx b/bridge_ui/src/hooks/useHandleTransfer.tsx index 2f54375f2..574f53737 100644 --- a/bridge_ui/src/hooks/useHandleTransfer.tsx +++ b/bridge_ui/src/hooks/useHandleTransfer.tsx @@ -59,7 +59,7 @@ import { isEVMChain } from "../utils/ethereum"; import { getSignedVAAWithRetry } from "../utils/getSignedVAAWithRetry"; import parseError from "../utils/parseError"; import { signSendAndConfirm } from "../utils/solana"; -import { waitForTerraExecution } from "../utils/terra"; +import { postWithFees, waitForTerraExecution } from "../utils/terra"; import useTransferTargetAddressHex from "./useTransferTargetAddress"; async function evm( @@ -229,10 +229,13 @@ async function terra( targetChain, targetAddress ); - const result = await wallet.post({ - msgs: [...msgs], - memo: "Wormhole - Initiate Transfer", - }); + + const result = await postWithFees( + wallet, + msgs, + "Wormhole - Initiate Transfer" + ); + const info = await waitForTerraExecution(result); dispatch(setTransferTx({ id: info.txhash, block: info.height })); enqueueSnackbar(null, { diff --git a/bridge_ui/src/utils/consts.ts b/bridge_ui/src/utils/consts.ts index 3210e42cb..18d7cf302 100644 --- a/bridge_ui/src/utils/consts.ts +++ b/bridge_ui/src/utils/consts.ts @@ -153,13 +153,13 @@ export const TERRA_HOST = } : CLUSTER === "testnet" ? { - URL: "https://tequila-lcd.terra.dev", - chainID: "tequila-0004", + URL: "https://bombay-lcd.terra.dev", + chainID: "bombay-0005", name: "testnet", } : { URL: "http://localhost:1317", - chainID: "columbus-4", + chainID: "columbus-5", name: "localterra", }; export const ETH_BRIDGE_ADDRESS = getAddress( @@ -541,3 +541,11 @@ export const getMigrationAssetMap = (chainId: ChainId) => { }; export const SUPPORTED_TERRA_TOKENS = ["uluna", "uusd"]; + +export const TERRA_FCD_BASE = + CLUSTER === "mainnet" + ? "https://fcd.terra.dev/" + : CLUSTER === "testnet" + ? "https://bombay-fcd.terra.dev" + : "http://localhost:3060"; +export const TERRA_GAS_PRICES_URL = `${TERRA_FCD_BASE}/v1/txs/gas_prices`; diff --git a/bridge_ui/src/utils/terra.ts b/bridge_ui/src/utils/terra.ts index 954465579..9e1914161 100644 --- a/bridge_ui/src/utils/terra.ts +++ b/bridge_ui/src/utils/terra.ts @@ -5,9 +5,10 @@ import { } from "@certusone/wormhole-sdk"; import { formatUnits } from "@ethersproject/units"; import { LCDClient } from "@terra-money/terra.js"; -import { TxResult } from "@terra-money/wallet-provider"; +import { ConnectedWallet, TxResult } from "@terra-money/wallet-provider"; +import axios from "axios"; // import { TerraTokenMetadata } from "../hooks/useTerraTokenMap"; -import { TERRA_HOST } from "./consts"; +import { TERRA_GAS_PRICES_URL, TERRA_HOST } from "./consts"; export const NATIVE_TERRA_DECIMALS = 6; @@ -55,3 +56,36 @@ export const isValidTerraAddress = (address: string) => { return false; } }; + +export async function postWithFees( + wallet: ConnectedWallet, + msgs: any[], + memo: string +) { + try { + const lcd = new LCDClient(TERRA_HOST); + //let gasPrices = await lcd.config.gasPrices //Unsure if the values returned from this are hardcoded or not. + //Thus, we are going to pull it directly from the current FCD. + let gasPrices = await axios + .get(TERRA_GAS_PRICES_URL) + .then((result) => result.data); + + const feeEstimate = await lcd.tx.estimateFee( + wallet.walletAddress, + [...msgs], + { memo, feeDenoms: ["uluna"], gasPrices } + ); + + const result = await wallet.post({ + msgs: [...msgs], + memo, + feeDenoms: ["uluna"], + gasPrices, + fee: feeEstimate, + }); + + return result; + } catch (e) { + return Promise.reject(); + } +} diff --git a/sdk/js/CHANGELOG.md b/sdk/js/CHANGELOG.md index 51e461c41..b06177624 100644 --- a/sdk/js/CHANGELOG.md +++ b/sdk/js/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 0.0.7 + +### Changed + +Changed function signature of attestFromTerra to be consistent with other terra functions + +Removed hardcoded fees on terra transactions + ## 0.0.6 ### Changed diff --git a/sdk/js/package.json b/sdk/js/package.json index 238a78ab0..41c39bddc 100644 --- a/sdk/js/package.json +++ b/sdk/js/package.json @@ -1,6 +1,6 @@ { "name": "@certusone/wormhole-sdk", - "version": "0.0.6", + "version": "0.0.7", "description": "SDK for interacting with Wormhole", "homepage": "https://wormholenetwork.com", "main": "lib/index.js", diff --git a/sdk/js/src/token_bridge/attest.ts b/sdk/js/src/token_bridge/attest.ts index 08c7227fb..8c2dd6f8f 100644 --- a/sdk/js/src/token_bridge/attest.ts +++ b/sdk/js/src/token_bridge/attest.ts @@ -20,34 +20,24 @@ export async function attestFromEth( export async function attestFromTerra( tokenBridgeAddress: string, - wallet: TerraConnectedWallet, + walletAddress: string, asset: string ) { const nonce = Math.round(Math.random() * 100000); const isNativeAsset = isNativeDenom(asset); - return await wallet.post({ - msgs: [ - new MsgExecuteContract( - wallet.terraAddress, - tokenBridgeAddress, - { - create_asset_meta: { - asset_info: isNativeAsset - ? { - native_token: { denom: asset }, - } - : { - token: { - contract_addr: asset, - }, - }, - nonce: nonce, + return new MsgExecuteContract(walletAddress, tokenBridgeAddress, { + create_asset_meta: { + asset_info: isNativeAsset + ? { + native_token: { denom: asset }, + } + : { + token: { + contract_addr: asset, + }, }, - }, - { uluna: 10000 } - ), - ], - memo: "Create Wrapped", + nonce: nonce, + }, }); } diff --git a/sdk/js/src/token_bridge/createWrapped.ts b/sdk/js/src/token_bridge/createWrapped.ts index 8c3e6c173..f99a3ef27 100644 --- a/sdk/js/src/token_bridge/createWrapped.ts +++ b/sdk/js/src/token_bridge/createWrapped.ts @@ -22,16 +22,11 @@ export async function createWrappedOnTerra( walletAddress: string, signedVAA: Uint8Array ) { - return new MsgExecuteContract( - walletAddress, - tokenBridgeAddress, - { - submit_vaa: { - data: fromUint8Array(signedVAA), - }, + return new MsgExecuteContract(walletAddress, tokenBridgeAddress, { + submit_vaa: { + data: fromUint8Array(signedVAA), }, - { uluna: 1000 } - ); + }); } export async function createWrappedOnSolana( diff --git a/sdk/js/src/token_bridge/redeem.ts b/sdk/js/src/token_bridge/redeem.ts index ddbf4ebea..72e8375bb 100644 --- a/sdk/js/src/token_bridge/redeem.ts +++ b/sdk/js/src/token_bridge/redeem.ts @@ -47,16 +47,11 @@ export async function redeemOnTerra( walletAddress: string, signedVAA: Uint8Array ) { - return new MsgExecuteContract( - walletAddress, - tokenBridgeAddress, - { - submit_vaa: { - data: fromUint8Array(signedVAA), - }, + return new MsgExecuteContract(walletAddress, tokenBridgeAddress, { + submit_vaa: { + data: fromUint8Array(signedVAA), }, - { uluna: 1000 } - ); + }); } export async function redeemAndUnwrapOnSolana(