@carrot-protocol/http-client 0.2.78-drift-apy-fix-dev-f27de8d → 0.2.78-drift-apy-fix-dev-b2f26a9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -26,6 +26,7 @@ export declare class Client {
26
26
  getReferralCodes(wallet: anchor.web3.PublicKey): Promise<GetReferralCodesResponse>;
27
27
  getCarrotBoostJitDepositIxns(request: GetCarrotBoostJitDepositIxnsRequest): Promise<GetCarrotBoostJitDepositIxnsResponse>;
28
28
  getCarrotBoostJitWithdrawIxns(request: GetCarrotBoostJitWithdrawIxnsRequest): Promise<GetCarrotBoostJitWithdrawIxnsResponse>;
29
- send(base64Tx: string): Promise<string>;
29
+ sendSignedTx(signedBase64Tx: string): Promise<string>;
30
+ private signAndSend;
30
31
  }
31
32
  export declare function prepareUnsignedTx(connection: anchor.web3.Connection, payer: anchor.web3.PublicKey, ixns: anchor.web3.TransactionInstruction[], lutAddr?: anchor.web3.PublicKey, additionalSigner?: anchor.AnchorProvider): Promise<string>;
package/dist/index.js CHANGED
@@ -228,7 +228,7 @@ class Client {
228
228
  // error if provider is undefined
229
229
  requireProvider(this.provider);
230
230
  const issueResponse = await this.prepareIssue(vault, assetMint, amount, this.provider.publicKey);
231
- const txSig = await this.send(issueResponse.tx);
231
+ const txSig = await this.signAndSend(issueResponse.tx);
232
232
  return txSig;
233
233
  }
234
234
  async prepareIssue(vault, assetMint, amount, user) {
@@ -254,7 +254,7 @@ class Client {
254
254
  // error if provider is undefined
255
255
  requireProvider(this.provider);
256
256
  const redeemResponse = await this.prepareRedeem(vault, assetMint, amount, this.provider.publicKey);
257
- const txSig = await this.send(redeemResponse.tx);
257
+ const txSig = await this.signAndSend(redeemResponse.tx);
258
258
  return txSig;
259
259
  }
260
260
  // Redeems assets from a specified vault
@@ -383,16 +383,14 @@ class Client {
383
383
  return getCarrotBoostJitWithdrawIxnsResponse;
384
384
  }
385
385
  // Sends a signed transaction to the network
386
- async send(base64Tx) {
387
- // error if provider is undefined
388
- requireProvider(this.provider);
389
- const txBytes = Buffer.from(base64Tx, "base64");
386
+ // expects a versioned tx
387
+ async sendSignedTx(signedBase64Tx) {
388
+ // extract txSig for caller
389
+ const txBytes = Buffer.from(signedBase64Tx, "base64");
390
390
  const tx = anchor.web3.VersionedTransaction.deserialize(new Uint8Array(txBytes));
391
- const signedTx = await this.provider.wallet.signTransaction(tx);
392
- const txSig = signedTx.signatures[0];
393
- const encodedAndSignedTx = Buffer.from(signedTx.serialize()).toString("base64");
391
+ const txSig = tx.signatures[0];
394
392
  const sendRequest = {
395
- tx: encodedAndSignedTx,
393
+ tx: signedBase64Tx,
396
394
  };
397
395
  const url = new URL(`${this.baseUrl}/send`);
398
396
  const response = await (0, cross_fetch_1.default)(url, {
@@ -406,6 +404,18 @@ class Client {
406
404
  }
407
405
  return (0, bs58_1.encode)(txSig);
408
406
  }
407
+ // Sends a signed transaction to the network
408
+ async signAndSend(base64Tx) {
409
+ // error if provider is undefined
410
+ requireProvider(this.provider);
411
+ const txBytes = Buffer.from(base64Tx, "base64");
412
+ const tx = anchor.web3.VersionedTransaction.deserialize(new Uint8Array(txBytes));
413
+ const signedTx = await this.provider.wallet.signTransaction(tx);
414
+ const txSig = signedTx.signatures[0];
415
+ const signedBase64Tx = Buffer.from(signedTx.serialize()).toString("base64");
416
+ await this.sendSignedTx(signedBase64Tx);
417
+ return (0, bs58_1.encode)(txSig);
418
+ }
409
419
  }
410
420
  exports.Client = Client;
411
421
  // Prepares an unsigned transaction for submission
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carrot-protocol/http-client",
3
- "version": "0.2.78-drift-apy-fix-dev-f27de8d",
3
+ "version": "0.2.78-drift-apy-fix-dev-b2f26a9",
4
4
  "description": "interact with carrot api",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",