bridge_ui: terra transaction fee modifications
Change-Id: Ie7afb2439efaa334d33264080125da9337bf914a
This commit is contained in:
parent
cff4d928b6
commit
6a0c788804
|
@ -50,7 +50,7 @@ import { isEVMChain } from "../utils/ethereum";
|
||||||
import { getSignedVAAWithRetry } from "../utils/getSignedVAAWithRetry";
|
import { getSignedVAAWithRetry } from "../utils/getSignedVAAWithRetry";
|
||||||
import parseError from "../utils/parseError";
|
import parseError from "../utils/parseError";
|
||||||
import { signSendAndConfirm } from "../utils/solana";
|
import { signSendAndConfirm } from "../utils/solana";
|
||||||
import { waitForTerraExecution } from "../utils/terra";
|
import { postWithFees, waitForTerraExecution } from "../utils/terra";
|
||||||
|
|
||||||
async function evm(
|
async function evm(
|
||||||
dispatch: any,
|
dispatch: any,
|
||||||
|
@ -160,11 +160,12 @@ async function terra(
|
||||||
) {
|
) {
|
||||||
dispatch(setIsSending(true));
|
dispatch(setIsSending(true));
|
||||||
try {
|
try {
|
||||||
const result = await attestFromTerra(
|
const msg = await attestFromTerra(
|
||||||
TERRA_TOKEN_BRIDGE_ADDRESS,
|
TERRA_TOKEN_BRIDGE_ADDRESS,
|
||||||
wallet,
|
wallet.terraAddress,
|
||||||
asset
|
asset
|
||||||
);
|
);
|
||||||
|
const result = await postWithFees(wallet, [msg], "Create Wrapped");
|
||||||
const info = await waitForTerraExecution(result);
|
const info = await waitForTerraExecution(result);
|
||||||
dispatch(setAttestTx({ id: info.txhash, block: info.height }));
|
dispatch(setAttestTx({ id: info.txhash, block: info.height }));
|
||||||
enqueueSnackbar(null, {
|
enqueueSnackbar(null, {
|
||||||
|
|
|
@ -36,6 +36,7 @@ import { isEVMChain } from "../utils/ethereum";
|
||||||
import parseError from "../utils/parseError";
|
import parseError from "../utils/parseError";
|
||||||
import { signSendAndConfirm } from "../utils/solana";
|
import { signSendAndConfirm } from "../utils/solana";
|
||||||
import { Alert } from "@material-ui/lab";
|
import { Alert } from "@material-ui/lab";
|
||||||
|
import { postWithFees } from "../utils/terra";
|
||||||
|
|
||||||
async function evm(
|
async function evm(
|
||||||
dispatch: any,
|
dispatch: any,
|
||||||
|
@ -119,10 +120,11 @@ async function terra(
|
||||||
wallet.terraAddress,
|
wallet.terraAddress,
|
||||||
signedVAA
|
signedVAA
|
||||||
);
|
);
|
||||||
const result = await wallet.post({
|
const result = await postWithFees(
|
||||||
msgs: [msg],
|
wallet,
|
||||||
memo: "Wormhole - Create Wrapped",
|
[msg],
|
||||||
});
|
"Wormhole - Create Wrapped"
|
||||||
|
);
|
||||||
dispatch(
|
dispatch(
|
||||||
setCreateTx({ id: result.result.txhash, block: result.result.height })
|
setCreateTx({ id: result.result.txhash, block: result.result.height })
|
||||||
);
|
);
|
||||||
|
|
|
@ -38,6 +38,7 @@ import { isEVMChain } from "../utils/ethereum";
|
||||||
import parseError from "../utils/parseError";
|
import parseError from "../utils/parseError";
|
||||||
import { signSendAndConfirm } from "../utils/solana";
|
import { signSendAndConfirm } from "../utils/solana";
|
||||||
import { Alert } from "@material-ui/lab";
|
import { Alert } from "@material-ui/lab";
|
||||||
|
import { postWithFees } from "../utils/terra";
|
||||||
|
|
||||||
async function evm(
|
async function evm(
|
||||||
dispatch: any,
|
dispatch: any,
|
||||||
|
@ -138,10 +139,11 @@ async function terra(
|
||||||
wallet.terraAddress,
|
wallet.terraAddress,
|
||||||
signedVAA
|
signedVAA
|
||||||
);
|
);
|
||||||
const result = await wallet.post({
|
const result = await postWithFees(
|
||||||
msgs: [msg],
|
wallet,
|
||||||
memo: "Wormhole - Complete Transfer",
|
[msg],
|
||||||
});
|
"Wormhole - Complete Transfer"
|
||||||
|
);
|
||||||
dispatch(
|
dispatch(
|
||||||
setRedeemTx({ id: result.result.txhash, block: result.result.height })
|
setRedeemTx({ id: result.result.txhash, block: result.result.height })
|
||||||
);
|
);
|
||||||
|
|
|
@ -59,7 +59,7 @@ import { isEVMChain } from "../utils/ethereum";
|
||||||
import { getSignedVAAWithRetry } from "../utils/getSignedVAAWithRetry";
|
import { getSignedVAAWithRetry } from "../utils/getSignedVAAWithRetry";
|
||||||
import parseError from "../utils/parseError";
|
import parseError from "../utils/parseError";
|
||||||
import { signSendAndConfirm } from "../utils/solana";
|
import { signSendAndConfirm } from "../utils/solana";
|
||||||
import { waitForTerraExecution } from "../utils/terra";
|
import { postWithFees, waitForTerraExecution } from "../utils/terra";
|
||||||
import useTransferTargetAddressHex from "./useTransferTargetAddress";
|
import useTransferTargetAddressHex from "./useTransferTargetAddress";
|
||||||
|
|
||||||
async function evm(
|
async function evm(
|
||||||
|
@ -229,10 +229,13 @@ async function terra(
|
||||||
targetChain,
|
targetChain,
|
||||||
targetAddress
|
targetAddress
|
||||||
);
|
);
|
||||||
const result = await wallet.post({
|
|
||||||
msgs: [...msgs],
|
const result = await postWithFees(
|
||||||
memo: "Wormhole - Initiate Transfer",
|
wallet,
|
||||||
});
|
msgs,
|
||||||
|
"Wormhole - Initiate Transfer"
|
||||||
|
);
|
||||||
|
|
||||||
const info = await waitForTerraExecution(result);
|
const info = await waitForTerraExecution(result);
|
||||||
dispatch(setTransferTx({ id: info.txhash, block: info.height }));
|
dispatch(setTransferTx({ id: info.txhash, block: info.height }));
|
||||||
enqueueSnackbar(null, {
|
enqueueSnackbar(null, {
|
||||||
|
|
|
@ -153,13 +153,13 @@ export const TERRA_HOST =
|
||||||
}
|
}
|
||||||
: CLUSTER === "testnet"
|
: CLUSTER === "testnet"
|
||||||
? {
|
? {
|
||||||
URL: "https://tequila-lcd.terra.dev",
|
URL: "https://bombay-lcd.terra.dev",
|
||||||
chainID: "tequila-0004",
|
chainID: "bombay-0005",
|
||||||
name: "testnet",
|
name: "testnet",
|
||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
URL: "http://localhost:1317",
|
URL: "http://localhost:1317",
|
||||||
chainID: "columbus-4",
|
chainID: "columbus-5",
|
||||||
name: "localterra",
|
name: "localterra",
|
||||||
};
|
};
|
||||||
export const ETH_BRIDGE_ADDRESS = getAddress(
|
export const ETH_BRIDGE_ADDRESS = getAddress(
|
||||||
|
@ -541,3 +541,11 @@ export const getMigrationAssetMap = (chainId: ChainId) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const SUPPORTED_TERRA_TOKENS = ["uluna", "uusd"];
|
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`;
|
||||||
|
|
|
@ -5,9 +5,10 @@ import {
|
||||||
} from "@certusone/wormhole-sdk";
|
} from "@certusone/wormhole-sdk";
|
||||||
import { formatUnits } from "@ethersproject/units";
|
import { formatUnits } from "@ethersproject/units";
|
||||||
import { LCDClient } from "@terra-money/terra.js";
|
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 { TerraTokenMetadata } from "../hooks/useTerraTokenMap";
|
||||||
import { TERRA_HOST } from "./consts";
|
import { TERRA_GAS_PRICES_URL, TERRA_HOST } from "./consts";
|
||||||
|
|
||||||
export const NATIVE_TERRA_DECIMALS = 6;
|
export const NATIVE_TERRA_DECIMALS = 6;
|
||||||
|
|
||||||
|
@ -55,3 +56,36 @@ export const isValidTerraAddress = (address: string) => {
|
||||||
return false;
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
# Changelog
|
# 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
|
## 0.0.6
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@certusone/wormhole-sdk",
|
"name": "@certusone/wormhole-sdk",
|
||||||
"version": "0.0.6",
|
"version": "0.0.7",
|
||||||
"description": "SDK for interacting with Wormhole",
|
"description": "SDK for interacting with Wormhole",
|
||||||
"homepage": "https://wormholenetwork.com",
|
"homepage": "https://wormholenetwork.com",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
|
|
|
@ -20,17 +20,12 @@ export async function attestFromEth(
|
||||||
|
|
||||||
export async function attestFromTerra(
|
export async function attestFromTerra(
|
||||||
tokenBridgeAddress: string,
|
tokenBridgeAddress: string,
|
||||||
wallet: TerraConnectedWallet,
|
walletAddress: string,
|
||||||
asset: string
|
asset: string
|
||||||
) {
|
) {
|
||||||
const nonce = Math.round(Math.random() * 100000);
|
const nonce = Math.round(Math.random() * 100000);
|
||||||
const isNativeAsset = isNativeDenom(asset);
|
const isNativeAsset = isNativeDenom(asset);
|
||||||
return await wallet.post({
|
return new MsgExecuteContract(walletAddress, tokenBridgeAddress, {
|
||||||
msgs: [
|
|
||||||
new MsgExecuteContract(
|
|
||||||
wallet.terraAddress,
|
|
||||||
tokenBridgeAddress,
|
|
||||||
{
|
|
||||||
create_asset_meta: {
|
create_asset_meta: {
|
||||||
asset_info: isNativeAsset
|
asset_info: isNativeAsset
|
||||||
? {
|
? {
|
||||||
|
@ -43,11 +38,6 @@ export async function attestFromTerra(
|
||||||
},
|
},
|
||||||
nonce: nonce,
|
nonce: nonce,
|
||||||
},
|
},
|
||||||
},
|
|
||||||
{ uluna: 10000 }
|
|
||||||
),
|
|
||||||
],
|
|
||||||
memo: "Create Wrapped",
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,16 +22,11 @@ export async function createWrappedOnTerra(
|
||||||
walletAddress: string,
|
walletAddress: string,
|
||||||
signedVAA: Uint8Array
|
signedVAA: Uint8Array
|
||||||
) {
|
) {
|
||||||
return new MsgExecuteContract(
|
return new MsgExecuteContract(walletAddress, tokenBridgeAddress, {
|
||||||
walletAddress,
|
|
||||||
tokenBridgeAddress,
|
|
||||||
{
|
|
||||||
submit_vaa: {
|
submit_vaa: {
|
||||||
data: fromUint8Array(signedVAA),
|
data: fromUint8Array(signedVAA),
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
{ uluna: 1000 }
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createWrappedOnSolana(
|
export async function createWrappedOnSolana(
|
||||||
|
|
|
@ -47,16 +47,11 @@ export async function redeemOnTerra(
|
||||||
walletAddress: string,
|
walletAddress: string,
|
||||||
signedVAA: Uint8Array
|
signedVAA: Uint8Array
|
||||||
) {
|
) {
|
||||||
return new MsgExecuteContract(
|
return new MsgExecuteContract(walletAddress, tokenBridgeAddress, {
|
||||||
walletAddress,
|
|
||||||
tokenBridgeAddress,
|
|
||||||
{
|
|
||||||
submit_vaa: {
|
submit_vaa: {
|
||||||
data: fromUint8Array(signedVAA),
|
data: fromUint8Array(signedVAA),
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
{ uluna: 1000 }
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function redeemAndUnwrapOnSolana(
|
export async function redeemAndUnwrapOnSolana(
|
||||||
|
|
Loading…
Reference in New Issue