@zebec-network/zebec-vault-sdk 5.3.0 → 5.3.2

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/service.d.ts CHANGED
@@ -81,13 +81,13 @@ export declare class ZebecVaultService {
81
81
  getProposalsInfoOfVault(vaultAddress: Address): Promise<ProposalInfo[]>;
82
82
  getCreateSilverCardInstruction(feePayer: PublicKey, cardVault: PublicKey, cardVaultAta: PublicKey, inputMint: PublicKey, revenueVault: PublicKey, revenueVaultAta: PublicKey, usdcToken: PublicKey, user: PublicKey, createSilverCardData: CreateSilverCardInstructionData): Promise<TransactionInstruction>;
83
83
  getLoadCarbonCardInstruction(feePayer: PublicKey, cardVault: PublicKey, cardVaultAta: PublicKey, inputMint: PublicKey, revenueVault: PublicKey, revenueVaultAta: PublicKey, usdcToken: PublicKey, user: PublicKey, createCarbonCardData: LoadCarbonCardInstructionData): Promise<TransactionInstruction>;
84
- getSwapAndCreateSilverCardInstruction(cardVault: PublicKey, cardVaultAta: PublicKey, inputMint: PublicKey, inputMintProgram: PublicKey, outputMint: PublicKey, revenueVault: PublicKey, revenueVaultAta: PublicKey, vaultOwner: PublicKey, data: {
84
+ getSwapAndCreateSilverCardInstruction(cardVault: PublicKey, cardVaultAta: PublicKey, inputMint: PublicKey, outputMint: PublicKey, revenueVault: PublicKey, revenueVaultAta: PublicKey, vaultOwner: PublicKey, cardPda: PublicKey, cardPurchasePda: PublicKey, feeMapPda: PublicKey, userPurchaseRecordPda: PublicKey, data: {
85
85
  currency: string;
86
86
  emailHash: number[];
87
87
  index: BN;
88
88
  swapData: Buffer;
89
89
  }, remainingAccounts: AccountMeta[]): Promise<TransactionInstruction>;
90
- getSwapAndLoadCarbonCardInstruction(cardVault: PublicKey, cardVaultAta: PublicKey, inputMint: PublicKey, inputMintProgram: PublicKey, outputMint: PublicKey, revenueVault: PublicKey, revenueVaultAta: PublicKey, vaultOwner: PublicKey, data: {
90
+ getSwapAndLoadCarbonCardInstruction(cardVault: PublicKey, cardVaultAta: PublicKey, inputMint: PublicKey, outputMint: PublicKey, revenueVault: PublicKey, revenueVaultAta: PublicKey, vaultOwner: PublicKey, cardPda: PublicKey, cardPurchasePda: PublicKey, feeMapPda: PublicKey, userPurchaseRecordPda: PublicKey, data: {
91
91
  currency: string;
92
92
  emailHash: number[];
93
93
  index: BN;
package/dist/service.js CHANGED
@@ -1,4 +1,7 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.ZebecVaultService = void 0;
4
7
  const anchor_1 = require("@coral-xyz/anchor");
@@ -9,7 +12,7 @@ const solana_common_1 = require("@zebec-network/solana-common");
9
12
  const zebec_card_v2_sdk_1 = require("@zebec-network/zebec-card-v2-sdk");
10
13
  const zebec_stake_sdk_1 = require("@zebec-network/zebec-stake-sdk");
11
14
  const zebec_stream_sdk_1 = require("@zebec-network/zebec-stream-sdk");
12
- const bignumber_js_1 = require("bignumber.js");
15
+ const bignumber_js_1 = __importDefault(require("bignumber.js"));
13
16
  const artifacts_1 = require("./artifacts");
14
17
  const errors_1 = require("./errors");
15
18
  const pda_1 = require("./pda");
@@ -524,7 +527,7 @@ class ZebecVaultService {
524
527
  })
525
528
  .instruction();
526
529
  }
527
- async getSwapAndCreateSilverCardInstruction(cardVault, cardVaultAta, inputMint, inputMintProgram, outputMint, revenueVault, revenueVaultAta, vaultOwner, data, remainingAccounts) {
530
+ async getSwapAndCreateSilverCardInstruction(cardVault, cardVaultAta, inputMint, outputMint, revenueVault, revenueVaultAta, vaultOwner, cardPda, cardPurchasePda, feeMapPda, userPurchaseRecordPda, data, remainingAccounts) {
528
531
  const { currency, emailHash, index, swapData } = data;
529
532
  return this.vaultV1Program.methods
530
533
  .swapAndCreateSilverCard({
@@ -533,21 +536,25 @@ class ZebecVaultService {
533
536
  index,
534
537
  swapData,
535
538
  })
536
- .accounts({
539
+ .accountsPartial({
537
540
  cardVault,
538
541
  cardVaultAta,
539
542
  inputMint,
540
- inputMintProgram,
543
+ inputMintProgram: solana_common_1.TOKEN_PROGRAM_ID,
541
544
  outputMint,
542
545
  outputMintProgram: solana_common_1.TOKEN_PROGRAM_ID,
543
546
  revenueVault,
544
547
  revenueVaultAta,
545
548
  vaultOwner,
549
+ cardPda,
550
+ cardPurchasePda,
551
+ feeMapPda,
552
+ userPurchaseRecordPda,
546
553
  })
547
554
  .remainingAccounts(remainingAccounts)
548
555
  .instruction();
549
556
  }
550
- async getSwapAndLoadCarbonCardInstruction(cardVault, cardVaultAta, inputMint, inputMintProgram, outputMint, revenueVault, revenueVaultAta, vaultOwner, data, remainingAccounts) {
557
+ async getSwapAndLoadCarbonCardInstruction(cardVault, cardVaultAta, inputMint, outputMint, revenueVault, revenueVaultAta, vaultOwner, cardPda, cardPurchasePda, feeMapPda, userPurchaseRecordPda, data, remainingAccounts) {
551
558
  const { currency, emailHash, index, swapData, reloadCardId } = data;
552
559
  return this.vaultV1Program.methods
553
560
  .swapAndLoadCarbonCard({
@@ -561,18 +568,22 @@ class ZebecVaultService {
561
568
  cardVault,
562
569
  cardVaultAta,
563
570
  inputMint,
564
- inputMintProgram,
571
+ inputMintProgram: solana_common_1.TOKEN_PROGRAM_ID,
565
572
  outputMint,
566
573
  outputMintProgram: solana_common_1.TOKEN_PROGRAM_ID,
567
574
  revenueVault,
568
575
  revenueVaultAta,
569
576
  vaultOwner,
577
+ cardPda,
578
+ cardPurchasePda,
579
+ feeMapPda,
580
+ userPurchaseRecordPda,
570
581
  })
571
582
  .remainingAccounts(remainingAccounts)
572
583
  .instruction();
573
584
  }
574
585
  async _checkAmountIsWithinDailyCardLimit(cardConfigInfo, userPurchaseRecord, amount) {
575
- const dailyCardBuyLimit = (0, bignumber_js_1.BigNumber)(cardConfigInfo.dailyCardBuyLimit.toString());
586
+ const dailyCardBuyLimit = (0, bignumber_js_1.default)(cardConfigInfo.dailyCardBuyLimit.toString());
576
587
  console.debug("dailyCardBuyLimit:", dailyCardBuyLimit.toFixed());
577
588
  const today = new Date();
578
589
  const userPurchaseRecordInfo = await this.cardV2Program.account.userPurchaseRecord.fetchNullable(userPurchaseRecord, "confirmed");
@@ -581,9 +592,9 @@ class ZebecVaultService {
581
592
  return;
582
593
  }
583
594
  const lastCardBoughtDate = new Date(userPurchaseRecordInfo.dateTimeInUnix.toNumber() * 1000);
584
- let cardBoughtInADay = (0, bignumber_js_1.BigNumber)(0);
595
+ let cardBoughtInADay = (0, bignumber_js_1.default)(0);
585
596
  if ((0, core_utils_1.areDatesOfSameDay)(today, lastCardBoughtDate)) {
586
- cardBoughtInADay = (0, bignumber_js_1.BigNumber)(userPurchaseRecordInfo.totalBoughtPerDay.toString()).plus(amount);
597
+ cardBoughtInADay = (0, bignumber_js_1.default)(userPurchaseRecordInfo.totalBoughtPerDay.toString()).plus(amount);
587
598
  }
588
599
  else {
589
600
  cardBoughtInADay = amount;
@@ -593,8 +604,8 @@ class ZebecVaultService {
593
604
  }
594
605
  }
595
606
  async _checkAmountIsWithinProviderRange(cardConfigInfo, amount) {
596
- const minRange = (0, bignumber_js_1.BigNumber)(cardConfigInfo.providerConfig.minCardAmount.toString());
597
- const maxRange = (0, bignumber_js_1.BigNumber)(cardConfigInfo.providerConfig.maxCardAmount.toString());
607
+ const minRange = (0, bignumber_js_1.default)(cardConfigInfo.providerConfig.minCardAmount.toString());
608
+ const maxRange = (0, bignumber_js_1.default)(cardConfigInfo.providerConfig.maxCardAmount.toString());
598
609
  if (amount.isLessThan(minRange) || amount.isGreaterThan(maxRange)) {
599
610
  throw new errors_1.AmountOutOfRangeError(minRange.div(solana_common_1.UNITS_PER_USDC).toFixed(), maxRange.div(solana_common_1.UNITS_PER_USDC).toFixed(), amount.div(solana_common_1.UNITS_PER_USDC).toFixed());
600
611
  }
@@ -615,7 +626,7 @@ class ZebecVaultService {
615
626
  const [vault] = (0, pda_1.deriveUserVault)(vaultOwner, this.vaultV1ProgramId);
616
627
  const [vaultSigner] = (0, pda_1.deriveVaultSigner)(vault, this.vaultV1ProgramId);
617
628
  const usdcMint = (0, anchor_1.translateAddress)(params.usdcAddress);
618
- const amount = (0, bignumber_js_1.BigNumber)(params.amount);
629
+ const amount = (0, bignumber_js_1.default)(params.amount);
619
630
  const [cardConfig] = (0, zebec_card_v2_sdk_1.deriveCardConfigPda)(this.cardV2Program.programId);
620
631
  const [userPurchaseRecord] = (0, zebec_card_v2_sdk_1.deriveUserPurchaseRecordPda)(vaultSigner, this.cardV2Program.programId);
621
632
  const cardConfigInfo = await this.cardV2Program.account.card.fetch(cardConfig, "confirmed");
@@ -625,7 +636,7 @@ class ZebecVaultService {
625
636
  const revenueVaultAta = (0, solana_common_1.getAssociatedTokenAddressSync)(usdcMint, revenueVault, true);
626
637
  const parsedAmount = amount
627
638
  .times(solana_common_1.UNITS_PER_USDC)
628
- .decimalPlaces(0, bignumber_js_1.BigNumber.ROUND_DOWN);
639
+ .decimalPlaces(0, bignumber_js_1.default.ROUND_DOWN);
629
640
  await this._checkAmountIsWithinProviderRange(cardConfigInfo, parsedAmount);
630
641
  await this._checkAmountIsWithinDailyCardLimit(cardConfigInfo, userPurchaseRecord, parsedAmount);
631
642
  const index = new anchor_1.BN(params.nextCardIndex.toString());
@@ -669,7 +680,7 @@ class ZebecVaultService {
669
680
  const [vault] = (0, pda_1.deriveUserVault)(vaultOwner, this.vaultV1ProgramId);
670
681
  const [vaultSigner] = (0, pda_1.deriveVaultSigner)(vault, this.vaultV1ProgramId);
671
682
  const usdcMint = (0, anchor_1.translateAddress)(params.usdcAddress);
672
- const amount = (0, bignumber_js_1.BigNumber)(params.amount);
683
+ const amount = (0, bignumber_js_1.default)(params.amount);
673
684
  const [cardConfig] = (0, zebec_card_v2_sdk_1.deriveCardConfigPda)(this.cardV2Program.programId);
674
685
  const [userPurchaseRecord] = (0, zebec_card_v2_sdk_1.deriveUserPurchaseRecordPda)(vaultSigner, this.cardV2Program.programId);
675
686
  const cardConfigInfo = await this.cardV2Program.account.card.fetch(cardConfig, "confirmed");
@@ -679,7 +690,7 @@ class ZebecVaultService {
679
690
  const revenueVaultAta = (0, solana_common_1.getAssociatedTokenAddressSync)(usdcMint, revenueVault, true);
680
691
  const parsedAmount = amount
681
692
  .times(solana_common_1.UNITS_PER_USDC)
682
- .decimalPlaces(0, bignumber_js_1.BigNumber.ROUND_DOWN);
693
+ .decimalPlaces(0, bignumber_js_1.default.ROUND_DOWN);
683
694
  await this._checkAmountIsWithinProviderRange(cardConfigInfo, parsedAmount);
684
695
  await this._checkAmountIsWithinDailyCardLimit(cardConfigInfo, userPurchaseRecord, parsedAmount);
685
696
  const index = new anchor_1.BN(params.nextCardIndex.toString());
@@ -714,7 +725,7 @@ class ZebecVaultService {
714
725
  return this._createTransactionPayload(vaultOwner, [executeProposalDirectIx], [], [lookupTableAccount]);
715
726
  }
716
727
  async swapAndCreateSilverCard(params) {
717
- const { vaultOwnerAddress, quoteInfo, emailHash, wrapAndUnwrapSol } = params;
728
+ const { vaultOwnerAddress, quoteInfo, emailHash } = params;
718
729
  if ("error" in quoteInfo) {
719
730
  throw new Error(quoteInfo.error);
720
731
  }
@@ -722,6 +733,7 @@ class ZebecVaultService {
722
733
  const vaultOwner = (0, anchor_1.translateAddress)(vaultOwnerAddress);
723
734
  const [vault] = (0, pda_1.deriveUserVault)(vaultOwner, this.vaultV1ProgramId);
724
735
  const [vaultSigner] = (0, pda_1.deriveVaultSigner)(vault, this.vaultV1ProgramId);
736
+ // console.debug("vault signer:", vaultSigner.toString());
725
737
  const inputMint = (0, anchor_1.translateAddress)(quoteInfo.inputMint);
726
738
  const usdc = (0, anchor_1.translateAddress)(quoteInfo.outputMint);
727
739
  const [userPurchaseRecord] = (0, zebec_card_v2_sdk_1.deriveUserPurchaseRecordPda)(vaultSigner, this.cardV2ProgramId);
@@ -732,37 +744,37 @@ class ZebecVaultService {
732
744
  const cardVaultAta = (0, solana_common_1.getAssociatedTokenAddressSync)(usdc, cardVault, true);
733
745
  const revenueVaultAta = (0, solana_common_1.getAssociatedTokenAddressSync)(usdc, revenueVault, true);
734
746
  const amount = quoteInfo.swapMode === "ExactIn"
735
- ? new bignumber_js_1.BigNumber(quoteInfo.otherAmountThreshold)
736
- : new bignumber_js_1.BigNumber(quoteInfo.outAmount);
747
+ ? new bignumber_js_1.default(quoteInfo.otherAmountThreshold)
748
+ : new bignumber_js_1.default(quoteInfo.outAmount);
737
749
  if (!usdc.equals(cardConfigInfo.usdcMint)) {
738
750
  throw new Error(`Invalid usdc: ${usdc.toString()}`);
739
751
  }
740
- const userInputMintAta = (0, solana_common_1.getAssociatedTokenAddressSync)(inputMint, vaultSigner, true);
741
- const isSolWrapUnwrapNeeded = inputMint.equals(solana_common_1.WSOL) && wrapAndUnwrapSol;
752
+ const [cardPurchase] = (0, zebec_card_v2_sdk_1.deriveCardPurchasePda)(vaultSigner, params.nextCardCounter, this.cardV2ProgramId);
753
+ const [feeMapPda] = (0, zebec_card_v2_sdk_1.deriveTokenFeeMapPda)(this.cardV2ProgramId);
754
+ const vaultSignerInputMintAta = (0, solana_common_1.getAssociatedTokenAddressSync)(inputMint, vaultSigner, true);
742
755
  // check if user has enough balance
743
- if (!inputMint.equals(solana_common_1.WSOL) || !isSolWrapUnwrapNeeded) {
744
- const userInputMintAtaInfo = await this.connection.getAccountInfo(userInputMintAta, this.connection.commitment);
745
- if (!userInputMintAtaInfo) {
746
- throw new errors_1.AssociatedTokenAccountDoesNotExistsError(`User doesn't have associated token account of input mint: ${inputMint.toString()}`);
747
- }
748
- const resAndCtx = await this.connection.getTokenAccountBalance(userInputMintAta, this.connection.commitment);
749
- const balance = resAndCtx.value.amount;
750
- if (balance === "" || (0, bignumber_js_1.BigNumber)(balance).lt(quoteInfo.inAmount)) {
751
- throw new errors_1.NotEnoughBalanceError("User doesn't have enough input mint balance");
752
- }
756
+ const vaultSignerInputMintAtaInfo = await this.connection.getAccountInfo(vaultSignerInputMintAta, this.connection.commitment);
757
+ if (!vaultSignerInputMintAtaInfo) {
758
+ throw new errors_1.AssociatedTokenAccountDoesNotExistsError(`User doesn't have associated token account of input mint: ${inputMint.toString()}`);
753
759
  }
754
- else {
755
- const balance = await this.connection.getBalance(vaultSigner, "confirmed");
756
- if ((0, bignumber_js_1.BigNumber)(balance).lt(quoteInfo.inAmount)) {
757
- throw new errors_1.NotEnoughBalanceError("User doesn't have enough SOL balance");
758
- }
760
+ const resAndCtx = await this.connection.getTokenAccountBalance(vaultSignerInputMintAta, this.connection.commitment);
761
+ const balance = resAndCtx.value.amount;
762
+ if (balance === "" || (0, bignumber_js_1.default)(balance).lt(quoteInfo.inAmount)) {
763
+ throw new errors_1.NotEnoughBalanceError("User doesn't have enough input mint balance");
759
764
  }
760
765
  const customTokenFees = await this.getCardCustomTokenFees();
761
766
  const customTokenFee = customTokenFees.find((tf) => tf.tokenAddress === quoteInfo.inputMint);
767
+ const vaultSignerOutputMintAta = (0, solana_common_1.getAssociatedTokenAddressSync)(usdc, vaultSigner, true);
768
+ const vaultSignerOutputMintAtaInfo = await this.connection.getAccountInfo(vaultSignerOutputMintAta, this.connection.commitment);
769
+ const instructions = [];
770
+ if (!vaultSignerOutputMintAtaInfo) {
771
+ const createVaultSignerOutputMintAtaInstruction = (0, solana_common_1.createAssociatedTokenAccountInstruction)(vaultOwner, vaultSignerOutputMintAta, vaultSigner, usdc);
772
+ instructions.push(createVaultSignerOutputMintAtaInstruction);
773
+ }
762
774
  const DEFAULT_SWAP_FEE = 5;
763
775
  const swapFee = customTokenFee
764
- ? (0, bignumber_js_1.BigNumber)(customTokenFee.fee)
765
- : (0, bignumber_js_1.BigNumber)(DEFAULT_SWAP_FEE);
776
+ ? (0, bignumber_js_1.default)(customTokenFee.fee)
777
+ : (0, bignumber_js_1.default)(DEFAULT_SWAP_FEE);
766
778
  const amountAfterFeeDeduction = amount.minus(amount.times(swapFee.div(100)));
767
779
  await this._checkAmountIsWithinProviderRange(cardConfigInfo, amountAfterFeeDeduction);
768
780
  await this._checkAmountIsWithinDailyCardLimit(cardConfigInfo, userPurchaseRecord, amountAfterFeeDeduction);
@@ -818,22 +830,31 @@ class ZebecVaultService {
818
830
  addressLookupTableAccounts: addressLookupTableAccounts,
819
831
  });
820
832
  const swapInstruction = message.instructions.find((ix) => ix.programId.equals((0, anchor_1.translateAddress)(zebec_card_v2_sdk_1.JUPITER_AGGREGATOR_PROGRAM_ID)));
821
- if (!swapInstruction)
833
+ if (!swapInstruction) {
822
834
  throw new Error("Swap instruction not found in the transaction message");
823
- const otherIxs = message.instructions.filter((ix) => !ix.programId.equals((0, anchor_1.translateAddress)(zebec_card_v2_sdk_1.JUPITER_AGGREGATOR_PROGRAM_ID)) &&
824
- !ix.programId.equals(web3_js_1.ComputeBudgetProgram.programId));
835
+ }
825
836
  const index = new anchor_1.BN(params.nextCardCounter.toString());
826
- const swapAndCreateSilverCardIx = await this.getSwapAndCreateSilverCardInstruction(vaultOwner, cardVault, cardVaultAta, revenueVault, revenueVaultAta, inputMint, usdc, vaultSigner, {
837
+ const swapAndCreateSilverCardIx = await this.getSwapAndCreateSilverCardInstruction(cardVault, cardVaultAta, inputMint, usdc, revenueVault, revenueVaultAta, vaultOwner, cardConfig, cardPurchase, feeMapPda, userPurchaseRecord, {
827
838
  index,
828
839
  currency: params.currency,
829
840
  emailHash: Array.from(emailHash),
830
841
  swapData: swapInstruction.data,
831
- }, swapInstruction.keys);
832
- otherIxs.push(swapAndCreateSilverCardIx);
833
- return this._createTransactionPayload(vaultOwner, otherIxs, [], addressLookupTableAccounts);
842
+ }, swapInstruction.keys.map((key) => ({
843
+ ...key,
844
+ isSigner: key.pubkey.equals(vaultSigner) ? false : key.isSigner,
845
+ })));
846
+ instructions.push(swapAndCreateSilverCardIx);
847
+ // console.debug(
848
+ // JSON.stringify(
849
+ // instructions.map((ix) => ({ ...ix, data: null })),
850
+ // null,
851
+ // 2,
852
+ // ),
853
+ // );
854
+ return this._createTransactionPayload(vaultOwner, instructions, [], addressLookupTableAccounts);
834
855
  }
835
856
  async swapAndLoadCarbonCard(params) {
836
- const { vaultOwnerAddress, quoteInfo, emailHash, reloadCardId, wrapAndUnwrapSol, } = params;
857
+ const { vaultOwnerAddress, quoteInfo, emailHash, reloadCardId } = params;
837
858
  if ("error" in quoteInfo) {
838
859
  throw new Error(quoteInfo.error);
839
860
  }
@@ -851,38 +872,38 @@ class ZebecVaultService {
851
872
  const cardVaultAta = (0, solana_common_1.getAssociatedTokenAddressSync)(usdc, cardVault, true);
852
873
  const revenueVaultAta = (0, solana_common_1.getAssociatedTokenAddressSync)(usdc, revenueVault, true);
853
874
  const amount = quoteInfo.swapMode === "ExactIn"
854
- ? new bignumber_js_1.BigNumber(quoteInfo.otherAmountThreshold)
855
- : new bignumber_js_1.BigNumber(quoteInfo.outAmount);
875
+ ? new bignumber_js_1.default(quoteInfo.otherAmountThreshold)
876
+ : new bignumber_js_1.default(quoteInfo.outAmount);
856
877
  if (!usdc.equals(cardConfigInfo.usdcMint)) {
857
878
  throw new Error(`Invalid usdc: ${usdc.toString()}`);
858
879
  }
859
- const userInputMintAta = (0, solana_common_1.getAssociatedTokenAddressSync)(inputMint, vaultSigner, true);
860
- const isSolWrapUnwrapNeeded = inputMint.equals(solana_common_1.WSOL) && wrapAndUnwrapSol;
880
+ const [cardPurchase] = (0, zebec_card_v2_sdk_1.deriveCardPurchasePda)(vaultSigner, params.nextCardCounter, this.cardV2ProgramId);
881
+ const [feeMapPda] = (0, zebec_card_v2_sdk_1.deriveTokenFeeMapPda)(this.cardV2ProgramId);
882
+ const vaultSignerInputMintAta = (0, solana_common_1.getAssociatedTokenAddressSync)(inputMint, vaultSigner, true);
861
883
  // check if user has enough balance
862
- if (!inputMint.equals(solana_common_1.WSOL) || !isSolWrapUnwrapNeeded) {
863
- const userInputMintAtaInfo = await this.connection.getAccountInfo(userInputMintAta, this.connection.commitment);
864
- if (!userInputMintAtaInfo) {
865
- throw new errors_1.AssociatedTokenAccountDoesNotExistsError("User doesn't have associated token account of input mint: " +
866
- inputMint.toString());
867
- }
868
- const resAndCtx = await this.connection.getTokenAccountBalance(userInputMintAta, this.connection.commitment);
869
- const balance = resAndCtx.value.amount;
870
- if (balance === "" || (0, bignumber_js_1.BigNumber)(balance).lt(quoteInfo.inAmount)) {
871
- throw new errors_1.NotEnoughBalanceError("User doesn't have enough input mint balance");
872
- }
884
+ const vaultSignerInputMintAtaInfo = await this.connection.getAccountInfo(vaultSignerInputMintAta, this.connection.commitment);
885
+ if (!vaultSignerInputMintAtaInfo) {
886
+ throw new errors_1.AssociatedTokenAccountDoesNotExistsError("User doesn't have associated token account of input mint: " +
887
+ inputMint.toString());
873
888
  }
874
- else {
875
- const balance = await this.connection.getBalance(vaultSigner, "confirmed");
876
- if ((0, bignumber_js_1.BigNumber)(balance).lt(quoteInfo.inAmount)) {
877
- throw new errors_1.NotEnoughBalanceError("User doesn't have enough SOL balance");
878
- }
889
+ const resAndCtx = await this.connection.getTokenAccountBalance(vaultSignerInputMintAta, this.connection.commitment);
890
+ const balance = resAndCtx.value.amount;
891
+ if (balance === "" || (0, bignumber_js_1.default)(balance).lt(quoteInfo.inAmount)) {
892
+ throw new errors_1.NotEnoughBalanceError("User doesn't have enough input mint balance");
893
+ }
894
+ const vaultSignerOutputMintAta = (0, solana_common_1.getAssociatedTokenAddressSync)(usdc, vaultSigner, true);
895
+ const vaultSignerOutputMintAtaInfo = await this.connection.getAccountInfo(vaultSignerOutputMintAta, this.connection.commitment);
896
+ const instructions = [];
897
+ if (!vaultSignerOutputMintAtaInfo) {
898
+ const createVaultSignerOutputMintAtaInstruction = (0, solana_common_1.createAssociatedTokenAccountInstruction)(vaultOwner, vaultSignerOutputMintAta, vaultSigner, usdc);
899
+ instructions.push(createVaultSignerOutputMintAtaInstruction);
879
900
  }
880
901
  const customTokenFees = await this.getCardCustomTokenFees();
881
902
  const customTokenFee = customTokenFees.find((tf) => tf.tokenAddress === quoteInfo.inputMint);
882
903
  const DEFAULT_SWAP_FEE = 5;
883
904
  const swapFee = customTokenFee
884
- ? (0, bignumber_js_1.BigNumber)(customTokenFee.fee)
885
- : (0, bignumber_js_1.BigNumber)(DEFAULT_SWAP_FEE);
905
+ ? (0, bignumber_js_1.default)(customTokenFee.fee)
906
+ : (0, bignumber_js_1.default)(DEFAULT_SWAP_FEE);
886
907
  const amountAfterFeeDeduction = amount.minus(amount.times(swapFee.div(100)));
887
908
  await this._checkAmountIsWithinProviderRange(cardConfigInfo, amountAfterFeeDeduction);
888
909
  await this._checkAmountIsWithinDailyCardLimit(cardConfigInfo, userPurchaseRecord, amountAfterFeeDeduction);
@@ -938,20 +959,22 @@ class ZebecVaultService {
938
959
  addressLookupTableAccounts: addressLookupTableAccounts,
939
960
  });
940
961
  const swapInstruction = message.instructions.find((ix) => ix.programId.equals((0, anchor_1.translateAddress)(zebec_card_v2_sdk_1.JUPITER_AGGREGATOR_PROGRAM_ID)));
941
- if (!swapInstruction)
962
+ if (!swapInstruction) {
942
963
  throw new Error("Swap instruction not found in the transaction message");
943
- const otherIxs = message.instructions.filter((ix) => !ix.programId.equals((0, anchor_1.translateAddress)(zebec_card_v2_sdk_1.JUPITER_AGGREGATOR_PROGRAM_ID)) &&
944
- !ix.programId.equals(web3_js_1.ComputeBudgetProgram.programId));
964
+ }
945
965
  const index = new anchor_1.BN(params.nextCardCounter.toString());
946
- const swapAndLoadCarbonCardIx = await this.getSwapAndLoadCarbonCardInstruction(cardVault, cardVaultAta, inputMint, solana_common_1.TOKEN_PROGRAM_ID, usdc, revenueVault, revenueVaultAta, vaultOwner, {
966
+ const swapAndLoadCarbonCardIx = await this.getSwapAndLoadCarbonCardInstruction(cardVault, cardVaultAta, inputMint, usdc, revenueVault, revenueVaultAta, vaultOwner, cardConfig, cardPurchase, feeMapPda, userPurchaseRecord, {
947
967
  index,
948
968
  currency: params.currency,
949
969
  emailHash: Array.from(emailHash),
950
970
  swapData: swapInstruction.data,
951
971
  reloadCardId,
952
- }, swapInstruction.keys);
953
- otherIxs.push(swapAndLoadCarbonCardIx);
954
- return this._createTransactionPayload(vaultOwner, otherIxs, [], addressLookupTableAccounts);
972
+ }, swapInstruction.keys.map((key) => ({
973
+ ...key,
974
+ isSigner: key.pubkey.equals(vaultSigner) ? false : key.isSigner,
975
+ })));
976
+ instructions.push(swapAndLoadCarbonCardIx);
977
+ return this._createTransactionPayload(vaultOwner, instructions, [], addressLookupTableAccounts);
955
978
  }
956
979
  async getCardCustomTokenFees() {
957
980
  const [tokeFeeMapPda] = (0, zebec_card_v2_sdk_1.deriveTokenFeeMapPda)(this.cardV2ProgramId);
@@ -1096,7 +1119,7 @@ class ZebecVaultService {
1096
1119
  const [streamVault] = (0, zebec_stream_sdk_1.deriveStreamVaultPda)(streamMetadata, this.streamProgramId);
1097
1120
  const streamVaultAta = (0, solana_common_1.getAssociatedTokenAddressSync)(streamToken, streamVault, true);
1098
1121
  const streamTokenDecimals = await (0, solana_common_1.getMintDecimals)(this.connection, streamToken);
1099
- const amount = (0, bignumber_js_1.BigNumber)(params.amount)
1122
+ const amount = (0, bignumber_js_1.default)(params.amount)
1100
1123
  .times(solana_common_1.TEN_BIGNUM.pow(streamTokenDecimals))
1101
1124
  .toFixed(0);
1102
1125
  const feeInfo = await (0, zebec_stream_sdk_1.getFeeInfoForStream)(streamToken, amount, streamTokenDecimals, this.network);
@@ -1189,7 +1212,7 @@ class ZebecVaultService {
1189
1212
  const [streamVault] = (0, zebec_stream_sdk_1.deriveStreamVaultPda)(streamMetadata, this.streamProgramId);
1190
1213
  const streamVaultAta = (0, solana_common_1.getAssociatedTokenAddressSync)(streamToken, streamVault, true);
1191
1214
  const streamTokenDecimals = await (0, solana_common_1.getMintDecimals)(this.connection, streamToken);
1192
- const amount = (0, bignumber_js_1.BigNumber)(info.amount)
1215
+ const amount = (0, bignumber_js_1.default)(info.amount)
1193
1216
  .times(solana_common_1.TEN_BIGNUM.pow(streamTokenDecimals))
1194
1217
  .toFixed(0);
1195
1218
  const feeInfo = await (0, zebec_stream_sdk_1.getFeeInfoForStream)(streamToken, amount, streamTokenDecimals, this.network);
@@ -1402,10 +1425,10 @@ class ZebecVaultService {
1402
1425
  const streamToken = metadataInfo.financials.streamToken;
1403
1426
  const streamTokenDecimals = await (0, solana_common_1.getMintDecimals)(this.connection, streamToken);
1404
1427
  const unitsPerStreamToken = solana_common_1.TEN_BIGNUM.pow(streamTokenDecimals);
1405
- const depositedAmount = (0, bignumber_js_1.BigNumber)(metadataInfo.financials.depositedAmount.toString())
1428
+ const depositedAmount = (0, bignumber_js_1.default)(metadataInfo.financials.depositedAmount.toString())
1406
1429
  .div(unitsPerStreamToken)
1407
1430
  .toFixed();
1408
- const withdrawnAmount = (0, bignumber_js_1.BigNumber)(metadataInfo.financials.withdrawnAmount.toString())
1431
+ const withdrawnAmount = (0, bignumber_js_1.default)(metadataInfo.financials.withdrawnAmount.toString())
1409
1432
  .div(unitsPerStreamToken)
1410
1433
  .toFixed();
1411
1434
  const cliffPercentage = Number((0, core_utils_1.bpsToPercent)(metadataInfo.financials.cliffPercentage.toNumber()));
@@ -1514,7 +1537,7 @@ class ZebecVaultService {
1514
1537
  const stakeTokenDecimals = await (0, solana_common_1.getMintDecimals)(this.connection, stakeToken);
1515
1538
  const UNITS_PER_STAKE_TOKEN = solana_common_1.TEN_BIGNUM.pow(stakeTokenDecimals);
1516
1539
  const instruction = await this.getStakeInstruction(feePayer, lockup, stakeToken, stakeVault, vaultSigner, userNonce, stakePda, stakeVaultTokenAccount, {
1517
- amount: new anchor_1.BN((0, bignumber_js_1.BigNumber)(params.amount).times(UNITS_PER_STAKE_TOKEN).toFixed(0)),
1540
+ amount: new anchor_1.BN((0, bignumber_js_1.default)(params.amount).times(UNITS_PER_STAKE_TOKEN).toFixed(0)),
1518
1541
  lockPeriod: new anchor_1.BN(params.lockPeriod),
1519
1542
  nonce: new anchor_1.BN(params.nonce.toString()),
1520
1543
  });
package/dist/types.d.ts CHANGED
@@ -104,7 +104,6 @@ export type SwapAndCreateSilverCardParams = {
104
104
  nextCardCounter: bigint;
105
105
  emailHash: Buffer;
106
106
  currency: string;
107
- wrapAndUnwrapSol?: boolean;
108
107
  };
109
108
  export type SwapAndLoadCarbonCardParams = {
110
109
  quoteInfo: QuoteInfo;
@@ -113,7 +112,6 @@ export type SwapAndLoadCarbonCardParams = {
113
112
  currency: string;
114
113
  reloadCardId: string;
115
114
  vaultOwnerAddress: Address;
116
- wrapAndUnwrapSol?: boolean;
117
115
  };
118
116
  /**
119
117
  * Juptier quote info
package/package.json CHANGED
@@ -5,25 +5,24 @@
5
5
  "@solana/spl-token": "^0.4.14",
6
6
  "@solana/web3.js": "^1.98.2",
7
7
  "@types/bn.js": "^5.2.0",
8
- "@zebec-network/core-utils": "^1.1.1",
9
- "@zebec-network/solana-common": "^2.3.1",
10
- "@zebec-network/zebec-card-v2-sdk": "^2.6.0",
11
- "@zebec-network/zebec-stake-sdk": "^1.3.1",
12
- "@zebec-network/zebec-stream-sdk": "^3.3.1",
13
- "bignumber.js": "^9.3.1",
8
+ "@zebec-network/core-utils": "^1.3.0",
9
+ "@zebec-network/solana-common": "^2.6.0",
10
+ "@zebec-network/zebec-card-v2-sdk": "^2.8.2",
11
+ "@zebec-network/zebec-stake-sdk": "^1.3.2",
12
+ "@zebec-network/zebec-stream-sdk": "^3.3.3",
13
+ "bignumber.js": "^11.1.1",
14
14
  "buffer": "^6.0.3"
15
15
  },
16
16
  "description": "An SDK for zebec vault solana program",
17
17
  "devDependencies": {
18
18
  "@types/mocha": "^10.0.10",
19
- "@types/node": "^24.3.1",
20
- "dotenv": "^17.2.2",
21
- "mocha": "^11.7.2",
22
- "prettier": "^3.6.2",
23
- "rimraf": "^6.0.1",
19
+ "@types/node": "^25.9.1",
20
+ "dotenv": "^17.4.2",
21
+ "mocha": "^11.7.6",
22
+ "rimraf": "^6.1.3",
24
23
  "ts-mocha": "^11.1.0",
25
24
  "ts-node": "^10.9.2",
26
- "typescript": "^5.9.2"
25
+ "typescript": "^6.0.3"
27
26
  },
28
27
  "files": [
29
28
  "dist",
@@ -43,10 +42,10 @@
43
42
  "build": "npm run clean && tsc",
44
43
  "clean": "rimraf ./dist",
45
44
  "format": "npx @biomejs/biome format --write ",
46
- "prepare": "npm run build",
45
+ "prepare": "npm run format && npm run build",
47
46
  "test": "ts-mocha -p ./tsconfig.json -b -t 1000000000 test/**/*.test.ts",
48
47
  "test:single": "ts-mocha -p ./tsconfig.json -t 1000000000"
49
48
  },
50
49
  "types": "dist/index.d.ts",
51
- "version": "5.3.0"
50
+ "version": "5.3.2"
52
51
  }