@0dotxyz/p0-ts-sdk 2.2.0-beta.2 → 2.2.0

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/vendor.cjs CHANGED
@@ -513,12 +513,36 @@ function createMemoInstruction(memo, signerPubkeys) {
513
513
  });
514
514
  }
515
515
  var TokenInstruction = /* @__PURE__ */ ((TokenInstruction2) => {
516
+ TokenInstruction2[TokenInstruction2["Approve"] = 4] = "Approve";
516
517
  TokenInstruction2[TokenInstruction2["InitializeAccount"] = 1] = "InitializeAccount";
517
518
  TokenInstruction2[TokenInstruction2["TransferChecked"] = 12] = "TransferChecked";
518
519
  TokenInstruction2[TokenInstruction2["CloseAccount"] = 9] = "CloseAccount";
519
520
  TokenInstruction2[TokenInstruction2["SyncNative"] = 17] = "SyncNative";
520
521
  return TokenInstruction2;
521
522
  })(TokenInstruction || {});
523
+ var approveInstructionData = bufferLayout.struct([
524
+ bufferLayout.u8("instruction"),
525
+ bufferLayoutUtils.u64("amount")
526
+ ]);
527
+ function createApproveInstruction(account, delegate, owner, amount, multiSigners = [], programId = TOKEN_PROGRAM_ID) {
528
+ const keys = addSigners(
529
+ [
530
+ { pubkey: account, isSigner: false, isWritable: true },
531
+ { pubkey: delegate, isSigner: false, isWritable: false }
532
+ ],
533
+ owner,
534
+ multiSigners
535
+ );
536
+ const data = buffer.Buffer.alloc(approveInstructionData.span);
537
+ approveInstructionData.encode(
538
+ {
539
+ instruction: 4 /* Approve */,
540
+ amount: BigInt(amount)
541
+ },
542
+ data
543
+ );
544
+ return new web3_js.TransactionInstruction({ keys, programId, data });
545
+ }
522
546
  var initializeAccountInstructionData = bufferLayout.struct([
523
547
  bufferLayout.u8("instruction")
524
548
  ]);
@@ -672,6 +696,7 @@ var SinglePoolInstruction = {
672
696
  },
673
697
  depositStake: async (pool, userStakeAccount, userTokenAccount, userLamportAccount) => {
674
698
  const stake = findPoolStakeAddress(pool);
699
+ const onRamp = findPoolOnRampAddress(pool);
675
700
  const mint = findPoolMintAddress(pool);
676
701
  const stakeAuthority = findPoolStakeAuthorityAddress(pool);
677
702
  const mintAuthority = findPoolMintAuthorityAddress(pool);
@@ -680,6 +705,7 @@ var SinglePoolInstruction = {
680
705
  [
681
706
  { pubkey: pool, isSigner: false, isWritable: false },
682
707
  { pubkey: stake, isSigner: false, isWritable: true },
708
+ { pubkey: onRamp, isSigner: false, isWritable: false },
683
709
  { pubkey: mint, isSigner: false, isWritable: true },
684
710
  { pubkey: stakeAuthority, isSigner: false, isWritable: false },
685
711
  { pubkey: mintAuthority, isSigner: false, isWritable: false },
@@ -696,6 +722,7 @@ var SinglePoolInstruction = {
696
722
  },
697
723
  withdrawStake: async (pool, userStakeAccount, userStakeAuthority, userTokenAccount, tokenAmount) => {
698
724
  const stake = findPoolStakeAddress(pool);
725
+ const onRamp = findPoolOnRampAddress(pool);
699
726
  const mint = findPoolMintAddress(pool);
700
727
  const stakeAuthority = findPoolStakeAuthorityAddress(pool);
701
728
  const mintAuthority = findPoolMintAuthorityAddress(pool);
@@ -710,6 +737,7 @@ var SinglePoolInstruction = {
710
737
  [
711
738
  { pubkey: pool, isSigner: false, isWritable: false },
712
739
  { pubkey: stake, isSigner: false, isWritable: true },
740
+ { pubkey: onRamp, isSigner: false, isWritable: false },
713
741
  { pubkey: mint, isSigner: false, isWritable: true },
714
742
  { pubkey: stakeAuthority, isSigner: false, isWritable: false },
715
743
  { pubkey: mintAuthority, isSigner: false, isWritable: false },
@@ -29233,12 +29261,28 @@ var V1Client = class _V1Client {
29233
29261
  return new Promise((resolve, reject) => {
29234
29262
  const ws = new WebSocket__default.default(url, [SUBPROTOCOL]);
29235
29263
  ws.binaryType = "arraybuffer";
29236
- ws.on("open", () => {
29264
+ const onOpen = () => {
29265
+ ws.off("error", onError);
29266
+ ws.off("close", onClose);
29237
29267
  resolve(new _V1Client(ws));
29238
- });
29239
- ws.on("error", (err) => {
29268
+ };
29269
+ const onError = (err) => {
29270
+ ws.off("open", onOpen);
29271
+ ws.off("close", onClose);
29240
29272
  reject(err);
29241
- });
29273
+ };
29274
+ const onClose = (code, reason) => {
29275
+ ws.off("open", onOpen);
29276
+ ws.off("error", onError);
29277
+ reject(
29278
+ new Error(
29279
+ `WebSocket closed before open (code=${code}${reason.length ? `, reason=${reason.toString()}` : ""})`
29280
+ )
29281
+ );
29282
+ };
29283
+ ws.once("open", onOpen);
29284
+ ws.once("error", onError);
29285
+ ws.once("close", onClose);
29242
29286
  });
29243
29287
  }
29244
29288
  // --- Constructor ---
@@ -29606,6 +29650,7 @@ exports.TokenUnsupportedInstructionError = TokenUnsupportedInstructionError;
29606
29650
  exports.V1Client = V1Client;
29607
29651
  exports.ZERO = ZERO;
29608
29652
  exports.addSigners = addSigners;
29653
+ exports.approveInstructionData = approveInstructionData;
29609
29654
  exports.buildSwapQuoteResult = buildSwapQuoteResult;
29610
29655
  exports.calculateAPYFromAPR = calculateAPYFromAPR;
29611
29656
  exports.calculateDriftBorrowAPR = calculateDriftBorrowAPR;
@@ -29632,6 +29677,7 @@ exports.calculateSlotAdjustmentFactor = calculateSlotAdjustmentFactor;
29632
29677
  exports.calculateUtilizationRatio = calculateUtilizationRatio;
29633
29678
  exports.closeAccountInstructionData = closeAccountInstructionData;
29634
29679
  exports.createAccountIx = createAccountIx;
29680
+ exports.createApproveInstruction = createApproveInstruction;
29635
29681
  exports.createAssociatedTokenAccountIdempotentInstruction = createAssociatedTokenAccountIdempotentInstruction;
29636
29682
  exports.createAssociatedTokenAccountInstruction = createAssociatedTokenAccountInstruction;
29637
29683
  exports.createCloseAccountInstruction = createCloseAccountInstruction;