sdk/js: drop terra NFT bridge functionality

This commit is contained in:
Csongor Kiss 2023-12-06 18:07:52 +00:00
parent 0cc1f677e5
commit 959d5cfb71
7 changed files with 2 additions and 169 deletions

View File

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

View File

@ -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<string | null> {
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

View File

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

View File

@ -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<WormholeWrappedInfo> {
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.

View File

@ -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<MsgExecuteContract> {
return new MsgExecuteContract(walletAddress, nftBridgeAddress, {
submit_vaa: {
data: fromUint8Array(signedVAA),
},
});
}
export async function redeemOnAptos(
nftBridgeAddress: string,
transferVAA: Uint8Array

View File

@ -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<MsgExecuteContract[]> {
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,

View File

@ -534,7 +534,7 @@ const DEVNET = {
terra: {
core: "terra18vd8fpwxzck93qlwghaj6arh4p7c5n896xzem5",
token_bridge: "terra10pyejy66429refv3g35g2t7am0was7ya7kz2a4",
nft_bridge: "terra1plju286nnfj3z54wgcggd4enwaa9fgf5kgrgzl",
nft_bridge: undefined,
},
ethereum: {
core: "0xC89Ce4735882C9F0f0FE26686c53074E09B0D550",