瀏覽代碼

sdk/js: Updated terra dependencies

Changed devnet terra tax rate to zero to reflect mainnet and testnet
Kevin Peters 3 年之前
父節點
當前提交
27e8952c8b

+ 10 - 0
sdk/js/CHANGELOG.md

@@ -1,5 +1,15 @@
 # Changelog
 
+## 0.2.0
+
+### Changed
+
+Updated @terra-money/terra.js to 3.0.7
+
+Removed @terra-money/wallet-provider
+
+Removed walletAddress parameter from getIsTransferCompletedTerra
+
 ## 0.1.7
 
 ### Added

文件差異過大導致無法顯示
+ 65 - 553
sdk/js/package-lock.json


+ 2 - 3
sdk/js/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@certusone/wormhole-sdk",
-  "version": "0.1.6",
+  "version": "0.2.0",
   "description": "SDK for interacting with Wormhole",
   "homepage": "https://wormholenetwork.com",
   "main": "./lib/cjs/index.js",
@@ -60,8 +60,7 @@
     "@improbable-eng/grpc-web": "^0.14.0",
     "@solana/spl-token": "^0.1.8",
     "@solana/web3.js": "^1.24.0",
-    "@terra-money/terra.js": "^2.0.14",
-    "@terra-money/wallet-provider": "^2.2.0",
+    "@terra-money/terra.js": "^3.0.7",
     "axios": "^0.24.0",
     "bech32": "^2.0.0",
     "js-base64": "^3.6.1",

+ 12 - 8
sdk/js/src/nft_bridge/__tests__/integration.ts

@@ -1,4 +1,4 @@
-import { BlockTxBroadcastResult, Coins, LCDClient, MnemonicKey, Msg, MsgExecuteContract, StdFee, TxInfo, Wallet } from "@terra-money/terra.js";
+import { BlockTxBroadcastResult, Coins, LCDClient, MnemonicKey, Msg, MsgExecuteContract, Fee, TxInfo, Wallet, isTxError } from "@terra-money/terra.js";
 import axios from "axios";
 import Web3 from 'web3';
 import { NodeHttpTransport } from "@improbable-eng/grpc-web-node-http-transport";
@@ -214,7 +214,7 @@ describe("Integration Tests", () => {
       }
     })();
   });
-  test("Send Solana SPL to Terra to Etheretum to Solana", (done) => {
+  test("Send Solana SPL to Terra to Ethereum to Solana", (done) => {
     (async () => {
       try {
         const { parse_vaa } = await importCoreWasm();
@@ -367,11 +367,16 @@ async function getGasPrices() {
     .then((result) => result.data);
 }
 
-async function estimateTerraFee(gasPrices: Coins.Input, msgs: Msg[]): Promise<StdFee> {
+async function estimateTerraFee(gasPrices: Coins.Input, msgs: Msg[]): Promise<Fee> {
   const feeEstimate = await lcd.tx.estimateFee(
-    terraWallet.key.accAddress,
-    msgs,
+    [
+      {
+        sequenceNumber: await terraWallet.sequence(), 
+        publicKey: terraWallet.key.publicKey 
+      }
+    ],
     {
+      msgs,
       memo: "localhost",
       feeDenoms: ["uluna"],
       gasPrices,
@@ -455,7 +460,7 @@ async function mint_cw721(contract_address: string, token_id: string, token_uri:
         ),
       ],
       memo: "",
-      fee: new StdFee(2000000, {
+      fee: new Fee(2000000, {
         uluna: "100000",
       }),
     })
@@ -472,7 +477,7 @@ async function waitForTerraExecution(txHash: string): Promise<TxInfo> {
       console.error(e);
     }
   }
-  if (info.code !== undefined) {
+  if (isTxError(info)) {
     // error code
     throw new Error(
       `Tx ${txHash}: error code ${info.code}: ${info.raw_log}`
@@ -486,7 +491,6 @@ async function expectReceivedOnTerra(signedVAA: Uint8Array) {
     await nft_bridge.getIsTransferCompletedTerra(
       TERRA_NFT_BRIDGE_ADDRESS,
       signedVAA,
-      terraWallet.key.accAddress,
       lcd,
       TERRA_GAS_PRICES_URL
     )

+ 24 - 8
sdk/js/src/nft_bridge/getIsTransferCompleted.ts

@@ -6,6 +6,7 @@ import { Connection, PublicKey } from "@solana/web3.js";
 import { LCDClient } from "@terra-money/terra.js";
 import axios from "axios";
 import { redeemOnTerra } from ".";
+import { TERRA_REDEEMED_CHECK_WALLET_ADDRESS } from "..";
 
 export async function getIsTransferCompletedEth(
   nftBridgeAddress: string,
@@ -20,22 +21,37 @@ export async function getIsTransferCompletedEth(
 export async function getIsTransferCompletedTerra(
   nftBridgeAddress: string,
   signedVAA: Uint8Array,
-  walletAddress: string,
   client: LCDClient,
   gasPriceUrl: string
 ) {
-  const msg = await redeemOnTerra(nftBridgeAddress, walletAddress, signedVAA);
+  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(walletAddress, [msg], {
-      memo: "already redeemed calculation",
-      feeDenoms: ["uluna"],
-      gasPrices,
-    });
+    await client.tx.estimateFee(
+      [
+        {
+          sequenceNumber: account.getSequenceNumber(),
+          publicKey: account.getPublicKey(),
+        },
+      ],
+      {
+        msgs: [msg],
+        memo: "already redeemed calculation",
+        feeDenoms: ["uluna"],
+        gasPrices,
+      }
+    );
   } catch (e) {
     // redeemed if the VAA was already executed
-    return e.response.data.error.includes("VaaAlreadyExecuted");
+    return e.response.data.message.includes("VaaAlreadyExecuted");
   }
   return false;
 }

+ 43 - 16
sdk/js/src/token_bridge/__tests__/integration.ts

@@ -482,9 +482,14 @@ describe("Integration Tests", () => {
             .get(TERRA_GAS_PRICES_URL)
             .then((result) => result.data);
           const feeEstimate = await lcd.tx.estimateFee(
-            wallet.key.accAddress,
-            [msg],
+            [
+              {
+                sequenceNumber: await wallet.sequence(),
+                publicKey: wallet.key.publicKey,
+              },
+            ],
             {
+              msgs: [msg],
               feeDenoms: ["uluna"],
               gasPrices,
             }
@@ -561,7 +566,6 @@ describe("Integration Tests", () => {
             await getIsTransferCompletedTerra(
               TERRA_TOKEN_BRIDGE_ADDRESS,
               signedVAA,
-              wallet.key.accAddress,
               lcd,
               TERRA_GAS_PRICES_URL
             )
@@ -575,9 +579,14 @@ describe("Integration Tests", () => {
             .get(TERRA_GAS_PRICES_URL)
             .then((result) => result.data);
           const feeEstimate = await lcd.tx.estimateFee(
-            wallet.key.accAddress,
-            [msg],
+            [
+              {
+                sequenceNumber: await wallet.sequence(),
+                publicKey: wallet.key.publicKey,
+              },
+            ],
             {
+              msgs: [msg],
               memo: "localhost",
               feeDenoms: ["uluna"],
               gasPrices,
@@ -595,7 +604,6 @@ describe("Integration Tests", () => {
             await getIsTransferCompletedTerra(
               TERRA_TOKEN_BRIDGE_ADDRESS,
               signedVAA,
-              wallet.key.accAddress,
               lcd,
               TERRA_GAS_PRICES_URL
             )
@@ -636,9 +644,14 @@ describe("Integration Tests", () => {
               { uusd: "900000087654321" }
             );
             const feeEstimate = await lcd.tx.estimateFee(
-              wallet.key.accAddress,
-              [deposit],
+              [
+                {
+                  sequenceNumber: await wallet.sequence(),
+                  publicKey: wallet.key.publicKey,
+                },
+              ],
               {
+                msgs: [deposit],
                 memo: "localhost",
                 feeDenoms: ["uluna"],
                 gasPrices,
@@ -679,13 +692,22 @@ describe("Integration Tests", () => {
           );
           let error = false;
           try {
-            await lcd.tx.estimateFee(wallet.key.accAddress, [transfer], {
-              memo: "localhost",
-              feeDenoms: ["uluna"],
-              gasPrices,
-            });
+            await lcd.tx.estimateFee(
+              [
+                {
+                  sequenceNumber: await wallet.sequence(),
+                  publicKey: wallet.key.publicKey,
+                },
+              ],
+              {
+                msgs: [transfer],
+                memo: "localhost",
+                feeDenoms: ["uluna"],
+                gasPrices,
+              }
+            );
           } catch (e) {
-            error = e.response.data.error.includes("Overflow: Cannot Sub");
+            error = e.response.data.message.includes("Overflow: Cannot Sub");
           }
           expect(error).toEqual(true);
           // withdraw the tokens we deposited
@@ -704,9 +726,14 @@ describe("Integration Tests", () => {
             {}
           );
           const feeEstimate = await lcd.tx.estimateFee(
-            wallet.key.accAddress,
-            [withdraw],
+            [
+              {
+                sequenceNumber: await wallet.sequence(),
+                publicKey: wallet.key.publicKey,
+              },
+            ],
             {
+              msgs: [withdraw],
               memo: "localhost",
               feeDenoms: ["uluna"],
               gasPrices,

+ 24 - 8
sdk/js/src/token_bridge/getIsTransferCompleted.ts

@@ -6,6 +6,7 @@ import { Connection, PublicKey } from "@solana/web3.js";
 import { LCDClient } from "@terra-money/terra.js";
 import axios from "axios";
 import { redeemOnTerra } from ".";
+import { TERRA_REDEEMED_CHECK_WALLET_ADDRESS } from "..";
 
 export async function getIsTransferCompletedEth(
   tokenBridgeAddress: string,
@@ -20,22 +21,37 @@ export async function getIsTransferCompletedEth(
 export async function getIsTransferCompletedTerra(
   tokenBridgeAddress: string,
   signedVAA: Uint8Array,
-  walletAddress: string,
   client: LCDClient,
   gasPriceUrl: string
 ) {
-  const msg = await redeemOnTerra(tokenBridgeAddress, walletAddress, signedVAA);
+  const msg = await redeemOnTerra(
+    tokenBridgeAddress,
+    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(walletAddress, [msg], {
-      memo: "already redeemed calculation",
-      feeDenoms: ["uluna"],
-      gasPrices,
-    });
+    await client.tx.estimateFee(
+      [
+        {
+          sequenceNumber: account.getSequenceNumber(),
+          publicKey: account.getPublicKey(),
+        },
+      ],
+      {
+        msgs: [msg],
+        memo: "already redeemed calculation",
+        feeDenoms: ["uluna"],
+        gasPrices,
+      }
+    );
   } catch (e) {
     // redeemed if the VAA was already executed
-    return e.response.data.error.includes("VaaAlreadyExecuted");
+    return e.response.data.message.includes("VaaAlreadyExecuted");
   }
   return false;
 }

+ 2 - 2
sdk/js/src/token_bridge/getIsWrappedAsset.ts

@@ -1,7 +1,7 @@
 import { Connection, PublicKey } from "@solana/web3.js";
+import { LCDClient } from "@terra-money/terra.js";
 import { ethers } from "ethers";
 import { Bridge__factory } from "../ethers-contracts";
-import { ConnectedWallet as TerraConnectedWallet } from "@terra-money/wallet-provider";
 import { importTokenWasm } from "../solana/wasm";
 
 /**
@@ -23,7 +23,7 @@ export async function getIsWrappedAssetEth(
 
 export async function getIsWrappedAssetTerra(
   tokenBridgeAddress: string,
-  wallet: TerraConnectedWallet,
+  client: LCDClient,
   assetAddress: string
 ) {
   return false;

+ 3 - 0
sdk/js/src/utils/consts.ts

@@ -14,3 +14,6 @@ export const CHAIN_ID_ETHEREUM_ROPSTEN: ChainId = 10001;
 export const WSOL_ADDRESS = "So11111111111111111111111111111111111111112";
 export const WSOL_DECIMALS = 9;
 export const MAX_VAA_DECIMALS = 8;
+
+export const TERRA_REDEEMED_CHECK_WALLET_ADDRESS =
+  "terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v";

+ 4 - 4
terra/devnet/config/genesis.json

@@ -667,13 +667,13 @@
     "treasury": {
       "params": {
         "tax_policy": {
-          "rate_min": "0.000500000000000000",
-          "rate_max": "0.010000000000000000",
+          "rate_min": "0.000000000000000000",
+          "rate_max": "0.000000000000000000",
           "cap": {
             "denom": "usdr",
-            "amount": "1000000"
+            "amount": "0"
           },
-          "change_rate_max": "0.000250000000000000"
+          "change_rate_max": "0.000000000000000000"
         },
         "reward_policy": {
           "rate_min": "0.000000000000000000",

部分文件因文件數量過多而無法顯示