sdk/js: Use is_vaa_redeemed query in getIsTransferCompletedTerra2
This does not require a transaction simulation, and should serve as the basis for future cosmwasm sdk functions in the `getIsTransferCompleted*` family.
This commit is contained in:
parent
d10072a33e
commit
cf5c390fc6
|
@ -14,6 +14,7 @@ import {
|
|||
getEmitterAddressEth,
|
||||
getEmitterAddressTerra,
|
||||
getIsTransferCompletedTerra,
|
||||
getIsTransferCompletedTerra2,
|
||||
parseSequenceFromLogEth,
|
||||
parseSequenceFromLogTerra,
|
||||
redeemOnEth,
|
||||
|
@ -32,7 +33,6 @@ import { approveEth, transferFromEth, transferFromTerra } from "../transfer";
|
|||
import {
|
||||
ETH_NODE_URL,
|
||||
ETH_PRIVATE_KEY2,
|
||||
TERRA2_GAS_PRICES_URL,
|
||||
TERRA2_NODE_URL,
|
||||
TERRA2_PRIVATE_KEY,
|
||||
TERRA_CHAIN_ID,
|
||||
|
@ -207,13 +207,19 @@ test("Attest and transfer token from Ethereum to Terra2", async () => {
|
|||
terraWalletAddress,
|
||||
transferSignedVaa
|
||||
);
|
||||
await terraBroadcastAndWaitForExecution([redeemMsg], terraWallet);
|
||||
expect(
|
||||
await getIsTransferCompletedTerra(
|
||||
await getIsTransferCompletedTerra2(
|
||||
CONTRACTS.DEVNET.terra2.token_bridge,
|
||||
transferSignedVaa,
|
||||
lcd,
|
||||
)
|
||||
).toBe(false);
|
||||
await terraBroadcastAndWaitForExecution([redeemMsg], terraWallet);
|
||||
expect(
|
||||
await getIsTransferCompletedTerra2(
|
||||
CONTRACTS.DEVNET.terra2.token_bridge,
|
||||
transferSignedVaa,
|
||||
lcd,
|
||||
TERRA2_GAS_PRICES_URL
|
||||
)
|
||||
).toBe(true);
|
||||
});
|
||||
|
|
|
@ -3,6 +3,7 @@ import { LCDClient } from "@terra-money/terra.js";
|
|||
import { Algodv2, bigIntToBytes } from "algosdk";
|
||||
import axios from "axios";
|
||||
import { ethers } from "ethers";
|
||||
import { fromUint8Array } from "js-base64";
|
||||
import { redeemOnTerra } from ".";
|
||||
import { TERRA_REDEEMED_CHECK_WALLET_ADDRESS } from "..";
|
||||
import {
|
||||
|
@ -26,6 +27,9 @@ export async function getIsTransferCompletedEth(
|
|||
return await tokenBridge.isTransferCompleted(signedVAAHash);
|
||||
}
|
||||
|
||||
// Note: this function is the legacy implementation for terra classic. New
|
||||
// cosmwasm sdk functions should instead be based on
|
||||
// `getIsTransferCompletedTerra2`.
|
||||
export async function getIsTransferCompletedTerra(
|
||||
tokenBridgeAddress: string,
|
||||
signedVAA: Uint8Array,
|
||||
|
@ -64,6 +68,30 @@ export async function getIsTransferCompletedTerra(
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is used to check if a VAA has been redeemed on terra2 by
|
||||
* querying the token bridge contract.
|
||||
* @param tokenBridgeAddress The token bridge address (bech32)
|
||||
* @param signedVAA The signed VAA byte array
|
||||
* @param client The LCD client. Only used for querying, not transactions will
|
||||
* be signed
|
||||
*/
|
||||
export async function getIsTransferCompletedTerra2(
|
||||
tokenBridgeAddress: string,
|
||||
signedVAA: Uint8Array,
|
||||
client: LCDClient,
|
||||
): Promise<boolean> {
|
||||
const result: { is_redeemed: boolean } = await client.wasm.contractQuery(
|
||||
tokenBridgeAddress,
|
||||
{
|
||||
is_vaa_redeemed: {
|
||||
vaa: fromUint8Array(signedVAA),
|
||||
},
|
||||
}
|
||||
);
|
||||
return result.is_redeemed;
|
||||
}
|
||||
|
||||
export async function getIsTransferCompletedSolana(
|
||||
tokenBridgeAddress: string,
|
||||
signedVAA: Uint8Array,
|
||||
|
|
Loading…
Reference in New Issue