|
1 | | -import { fromUint8Array } from "js-base64"; |
2 | 1 | import { |
3 | 2 | Coin, |
4 | 3 | LCDClient, |
|
7 | 6 | Msg, |
8 | 7 | MsgExecuteContract, |
9 | 8 | } from "@terra-money/terra.js"; |
10 | | -import { hexToUint8Array } from "@certusone/wormhole-sdk"; |
11 | 9 | import axios from "axios"; |
12 | 10 | import { logger } from "../helpers"; |
13 | 11 |
|
@@ -67,6 +65,9 @@ export class TerraRelay implements Relay { |
67 | 65 |
|
68 | 66 | const wallet = lcdClient.wallet(mk); |
69 | 67 |
|
| 68 | + logger.debug("TIME: Querying fee"); |
| 69 | + let fee: Coin = await this.getUpdateFee(signedVAAs); |
| 70 | + |
70 | 71 | logger.debug("TIME: creating messages"); |
71 | 72 |
|
72 | 73 | let base64VAAs = []; |
@@ -182,18 +183,33 @@ export class TerraRelay implements Relay { |
182 | 183 | logger.info("Querying terra for price info for priceId [" + priceId + "]"); |
183 | 184 |
|
184 | 185 | const lcdClient = new LCDClient(this.lcdConfig); |
185 | | - |
186 | | - const mk = new MnemonicKey({ |
187 | | - mnemonic: this.walletPrivateKey, |
188 | | - }); |
189 | | - |
190 | 186 | return await lcdClient.wasm.contractQuery(this.contractAddress, { |
191 | 187 | price_feed: { |
192 | 188 | id: priceId, |
193 | 189 | }, |
194 | 190 | }); |
195 | 191 | } |
196 | 192 |
|
| 193 | + async getUpdateFee(hexVAAs: Array<string>): Promise<Coin> { |
| 194 | + const lcdClient = new LCDClient(this.lcdConfig); |
| 195 | + |
| 196 | + let base64VAAs = []; |
| 197 | + for (let idx = 0; idx < hexVAAs.length; ++idx) { |
| 198 | + base64VAAs.push(Buffer.from(hexVAAs[idx], "hex").toString("base64")); |
| 199 | + } |
| 200 | + |
| 201 | + let result = await lcdClient.wasm.contractQuery<Coin.Data>( |
| 202 | + this.contractAddress, |
| 203 | + { |
| 204 | + get_update_fee: { |
| 205 | + vaas: base64VAAs, |
| 206 | + }, |
| 207 | + } |
| 208 | + ); |
| 209 | + |
| 210 | + return Coin.fromData(result); |
| 211 | + } |
| 212 | + |
197 | 213 | async getPayerInfo(): Promise<{ address: string; balance: bigint }> { |
198 | 214 | const lcdClient = new LCDClient(this.lcdConfig); |
199 | 215 |
|
|
0 commit comments