bridge_ui: terra transaction fee modifications

Change-Id: Ie7afb2439efaa334d33264080125da9337bf914a
This commit is contained in:
Chase Moran 2021-10-22 12:33:05 -04:00 committed by Evan Gray
parent cff4d928b6
commit 6a0c788804
11 changed files with 101 additions and 63 deletions

View File

@ -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, {

View File

@ -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 })
);

View File

@ -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 })
);

View File

@ -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, {

View File

@ -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`;

View File

@ -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();
}
}

View File

@ -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

View File

@ -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",

View File

@ -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,
},
});
}

View File

@ -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(

View File

@ -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(