From 959d5cfb71ddfa80fb01a475ff5a7c04d9db743b Mon Sep 17 00:00:00 2001 From: Csongor Kiss Date: Wed, 6 Dec 2023 18:07:52 +0000 Subject: [PATCH] sdk/js: drop terra NFT bridge functionality --- .../src/nft_bridge/__tests__/utils/consts.ts | 2 - sdk/js/src/nft_bridge/getForeignAsset.ts | 37 ---------------- .../src/nft_bridge/getIsTransferCompleted.ts | 43 +------------------ sdk/js/src/nft_bridge/getOriginalAsset.ts | 33 -------------- sdk/js/src/nft_bridge/redeem.ts | 14 ------ sdk/js/src/nft_bridge/transfer.ts | 40 ----------------- sdk/js/src/utils/consts.ts | 2 +- 7 files changed, 2 insertions(+), 169 deletions(-) diff --git a/sdk/js/src/nft_bridge/__tests__/utils/consts.ts b/sdk/js/src/nft_bridge/__tests__/utils/consts.ts index 3e8dcd2cb..431ee71ef 100644 --- a/sdk/js/src/nft_bridge/__tests__/utils/consts.ts +++ b/sdk/js/src/nft_bridge/__tests__/utils/consts.ts @@ -35,8 +35,6 @@ export const TERRA_GAS_PRICES_URL = ci export const TERRA_PRIVATE_KEY = "quality vacuum heart guard buzz spike sight swarm shove special gym robust assume sudden deposit grid alcohol choice devote leader tilt noodle tide penalty"; export const TEST_ERC721 = "0x5b9b42d6e4B2e4Bf8d42Eba32D46918e10899B66"; -export const TERRA_CW721_CODE_ID = 7; -export const TEST_CW721 = "terra18dt935pdcn2ka6l0syy5gt20wa48n3mktvdvjj"; export const TEST_SOLANA_TOKEN = "BVxyYhm498L79r4HMQ9sxZ5bi41DmJmeWZ7SCS7Cyvna"; export const TEST_SOLANA_TOKEN3 = "AQJc65JzbzsT88JnGEXSqZaF8NFAXPo21fX4QUED4uRX"; diff --git a/sdk/js/src/nft_bridge/getForeignAsset.ts b/sdk/js/src/nft_bridge/getForeignAsset.ts index 1b93acc60..152d13c38 100644 --- a/sdk/js/src/nft_bridge/getForeignAsset.ts +++ b/sdk/js/src/nft_bridge/getForeignAsset.ts @@ -1,6 +1,5 @@ import { BN } from "@project-serum/anchor"; import { PublicKeyInitData } from "@solana/web3.js"; -import { LCDClient } from "@terra-money/terra.js"; import { ApiError, AptosClient, @@ -10,7 +9,6 @@ import { } from "aptos"; import { ethers } from "ethers"; import { isBytes } from "ethers/lib/utils"; -import { fromUint8Array } from "js-base64"; import { CHAIN_ID_SOLANA } from ".."; import { CreateTokenDataEvent } from "../aptos/types"; import { NFTBridge__factory } from "../ethers-contracts"; @@ -58,41 +56,6 @@ export async function getForeignAssetEth( } } -/** - * Returns a foreign asset address on Terra for a provided native chain and asset address - * @param nftBridgeAddress - * @param client - * @param originChain - * @param originAsset - * @returns - */ -export async function getForeignAssetTerra( - nftBridgeAddress: string, - client: LCDClient, - originChain: ChainId, - originAsset: Uint8Array -): Promise { - const originChainId = coalesceChainId(originChain); - try { - const address = - originChain == CHAIN_ID_SOLANA - ? "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE=" - : fromUint8Array(originAsset); - const result: { address: string } = await client.wasm.contractQuery( - nftBridgeAddress, - { - wrapped_registry: { - chain: originChainId, - address, - }, - } - ); - return result.address; - } catch (e) { - return null; - } -} - /** * Returns a foreign asset address on Solana for a provided native chain and asset address * @param nftBridgeAddress diff --git a/sdk/js/src/nft_bridge/getIsTransferCompleted.ts b/sdk/js/src/nft_bridge/getIsTransferCompleted.ts index 5bccffcbf..a3ef82014 100644 --- a/sdk/js/src/nft_bridge/getIsTransferCompleted.ts +++ b/sdk/js/src/nft_bridge/getIsTransferCompleted.ts @@ -1,10 +1,7 @@ import { Commitment, Connection, PublicKeyInitData } from "@solana/web3.js"; -import { LCDClient } from "@terra-money/terra.js"; import { AptosClient } from "aptos"; -import axios from "axios"; import { ethers } from "ethers"; -import { redeemOnTerra } from "."; -import { ensureHexPrefix, TERRA_REDEEMED_CHECK_WALLET_ADDRESS } from ".."; +import { ensureHexPrefix } from ".."; import { NftBridgeState } from "../aptos/types"; import { getSignedVAAHash } from "../bridge"; import { NFTBridge__factory } from "../ethers-contracts"; @@ -21,44 +18,6 @@ export async function getIsTransferCompletedEth( return await nftBridge.isTransferCompleted(signedVAAHash); } -export async function getIsTransferCompletedTerra( - nftBridgeAddress: string, - signedVAA: Uint8Array, - client: LCDClient, - gasPriceUrl: string -) { - const msg = await redeemOnTerra( - nftBridgeAddress, - TERRA_REDEEMED_CHECK_WALLET_ADDRESS, - signedVAA - ); - // TODO: remove gasPriceUrl and just use the client's gas prices - const gasPrices = await axios.get(gasPriceUrl).then((result) => result.data); - const account = await client.auth.accountInfo( - TERRA_REDEEMED_CHECK_WALLET_ADDRESS - ); - try { - await client.tx.estimateFee( - [ - { - sequenceNumber: account.getSequenceNumber(), - publicKey: account.getPublicKey(), - }, - ], - { - msgs: [msg], - memo: "already redeemed calculation", - feeDenoms: ["uluna"], - gasPrices, - } - ); - } catch (e: any) { - // redeemed if the VAA was already executed - return e.response.data.message.includes("VaaAlreadyExecuted"); - } - return false; -} - export async function getIsTransferCompletedSolana( nftBridgeAddress: PublicKeyInitData, signedVAA: SignedVaa, diff --git a/sdk/js/src/nft_bridge/getOriginalAsset.ts b/sdk/js/src/nft_bridge/getOriginalAsset.ts index 26ca8f727..ca2574d2c 100644 --- a/sdk/js/src/nft_bridge/getOriginalAsset.ts +++ b/sdk/js/src/nft_bridge/getOriginalAsset.ts @@ -4,13 +4,10 @@ import { PublicKey, PublicKeyInitData, } from "@solana/web3.js"; -import { LCDClient } from "@terra-money/terra.js"; import { AptosClient, TokenTypes, Types } from "aptos"; import { BigNumber, ethers } from "ethers"; import { arrayify, zeroPad } from "ethers/lib/utils"; -import { WormholeWrappedInfo } from ".."; import { OriginInfo } from "../aptos/types"; -import { canonicalAddress } from "../cosmos"; import { TokenImplementation__factory } from "../ethers-contracts"; import { getWrappedMeta } from "../solana/nftBridge"; import { @@ -156,36 +153,6 @@ function bigToUint8Array(big: bigint) { return u8; } -export async function getOriginalAssetTerra( - client: LCDClient, - wrappedAddress: string, - lookupChain: ChainId | ChainName -): Promise { - try { - const result: { - asset_address: string; - asset_chain: ChainId; - bridge: string; - } = await client.wasm.contractQuery(wrappedAddress, { - wrapped_asset_info: {}, - }); - if (result) { - return { - isWrapped: true, - chainId: result.asset_chain, - assetAddress: new Uint8Array( - Buffer.from(result.asset_address, "base64") - ), - }; - } - } catch (e) {} - return { - isWrapped: false, - chainId: coalesceChainId(lookupChain), - assetAddress: zeroPad(canonicalAddress(wrappedAddress), 32), - }; -} - /** * Given a token ID, returns the original asset chain and address. If this is a * native asset, the asset address will be the collection hash. diff --git a/sdk/js/src/nft_bridge/redeem.ts b/sdk/js/src/nft_bridge/redeem.ts index 9ce722ca5..4e9f76cfb 100644 --- a/sdk/js/src/nft_bridge/redeem.ts +++ b/sdk/js/src/nft_bridge/redeem.ts @@ -5,10 +5,8 @@ import { PublicKeyInitData, Transaction, } from "@solana/web3.js"; -import { MsgExecuteContract } from "@terra-money/terra.js"; import { Types } from "aptos"; import { ethers, Overrides } from "ethers"; -import { fromUint8Array } from "js-base64"; import { Bridge__factory } from "../ethers-contracts"; import { createCompleteTransferNativeInstruction, @@ -91,18 +89,6 @@ export async function createMetaOnSolana( return transaction; } -export async function redeemOnTerra( - nftBridgeAddress: string, - walletAddress: string, - signedVAA: Uint8Array -): Promise { - return new MsgExecuteContract(walletAddress, nftBridgeAddress, { - submit_vaa: { - data: fromUint8Array(signedVAA), - }, - }); -} - export async function redeemOnAptos( nftBridgeAddress: string, transferVAA: Uint8Array diff --git a/sdk/js/src/nft_bridge/transfer.ts b/sdk/js/src/nft_bridge/transfer.ts index bcff06c7c..7c70d8ba0 100644 --- a/sdk/js/src/nft_bridge/transfer.ts +++ b/sdk/js/src/nft_bridge/transfer.ts @@ -7,7 +7,6 @@ import { PublicKeyInitData, Transaction, } from "@solana/web3.js"; -import { MsgExecuteContract } from "@terra-money/terra.js"; import { Types } from "aptos"; import { ethers, Overrides } from "ethers"; import { isBytes } from "ethers/lib/utils"; @@ -131,45 +130,6 @@ export async function transferFromSolana( return transaction; } -export async function transferFromTerra( - walletAddress: string, - nftBridgeAddress: string, - tokenAddress: string, - tokenID: string, - recipientChain: ChainId | ChainName, - recipientAddress: Uint8Array -): Promise { - const recipientChainId = coalesceChainId(recipientChain); - const nonce = Math.round(Math.random() * 100000); - return [ - new MsgExecuteContract( - walletAddress, - tokenAddress, - { - approve: { - spender: nftBridgeAddress, - token_id: tokenID, - }, - }, - {} - ), - new MsgExecuteContract( - walletAddress, - nftBridgeAddress, - { - initiate_transfer: { - contract_addr: tokenAddress, - token_id: tokenID, - recipient_chain: recipientChainId, - recipient: Buffer.from(recipientAddress).toString("base64"), - nonce: nonce, - }, - }, - {} - ), - ]; -} - export function transferFromAptos( nftBridgeAddress: string, creatorAddress: string, diff --git a/sdk/js/src/utils/consts.ts b/sdk/js/src/utils/consts.ts index 0da364998..29e8551e9 100644 --- a/sdk/js/src/utils/consts.ts +++ b/sdk/js/src/utils/consts.ts @@ -534,7 +534,7 @@ const DEVNET = { terra: { core: "terra18vd8fpwxzck93qlwghaj6arh4p7c5n896xzem5", token_bridge: "terra10pyejy66429refv3g35g2t7am0was7ya7kz2a4", - nft_bridge: "terra1plju286nnfj3z54wgcggd4enwaa9fgf5kgrgzl", + nft_bridge: undefined, }, ethereum: { core: "0xC89Ce4735882C9F0f0FE26686c53074E09B0D550",