@zebec-network/zebec-vault-sdk 5.1.3 → 5.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/service.js CHANGED
@@ -4,8 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ZebecVaultService = void 0;
7
- const assert_1 = __importDefault(require("assert"));
8
- const bignumber_js_1 = require("bignumber.js");
9
7
  const anchor_1 = require("@coral-xyz/anchor");
10
8
  const spl_token_1 = require("@solana/spl-token");
11
9
  const web3_js_1 = require("@solana/web3.js");
@@ -14,6 +12,8 @@ const solana_common_1 = require("@zebec-network/solana-common");
14
12
  const zebec_card_v2_sdk_1 = require("@zebec-network/zebec-card-v2-sdk");
15
13
  const zebec_stake_sdk_1 = require("@zebec-network/zebec-stake-sdk");
16
14
  const zebec_stream_sdk_1 = require("@zebec-network/zebec-stream-sdk");
15
+ const assert_1 = __importDefault(require("assert"));
16
+ const bignumber_js_1 = require("bignumber.js");
17
17
  const artifacts_1 = require("./artifacts");
18
18
  const constants_1 = require("./constants");
19
19
  const errors_1 = require("./errors");
@@ -151,7 +151,9 @@ class ZebecVaultService {
151
151
  .instruction();
152
152
  }
153
153
  async createVault(params) {
154
- const payer = params.payer ? (0, anchor_1.translateAddress)(params.payer) : this.provider.publicKey;
154
+ const payer = params.payer
155
+ ? (0, anchor_1.translateAddress)(params.payer)
156
+ : this.provider.publicKey;
155
157
  if (!payer) {
156
158
  throw new Error("Either provide a payer or use AnchorProvider for provider in the service");
157
159
  }
@@ -161,7 +163,9 @@ class ZebecVaultService {
161
163
  return this._createTransactionPayload(payer, [ix]);
162
164
  }
163
165
  async depositSol(params) {
164
- const depositor = params.depositor ? (0, anchor_1.translateAddress)(params.depositor) : this.provider.publicKey;
166
+ const depositor = params.depositor
167
+ ? (0, anchor_1.translateAddress)(params.depositor)
168
+ : this.provider.publicKey;
165
169
  if (!depositor) {
166
170
  throw new Error("Either provide a depositor or use AnchorProvider for provider in the service");
167
171
  }
@@ -170,7 +174,9 @@ class ZebecVaultService {
170
174
  return this._createTransactionPayload(depositor, [ix]);
171
175
  }
172
176
  async withdrawSol(params) {
173
- const withdrawer = params.withdrawer ? (0, anchor_1.translateAddress)(params.withdrawer) : this.provider.publicKey;
177
+ const withdrawer = params.withdrawer
178
+ ? (0, anchor_1.translateAddress)(params.withdrawer)
179
+ : this.provider.publicKey;
174
180
  if (!withdrawer) {
175
181
  throw new Error("Either provide a withdrawer or use AnchorProvider for provider in the service");
176
182
  }
@@ -179,7 +185,9 @@ class ZebecVaultService {
179
185
  return this._createTransactionPayload(withdrawer, [ix]);
180
186
  }
181
187
  async deposit(params) {
182
- const depositor = params.depositor ? (0, anchor_1.translateAddress)(params.depositor) : this.provider.publicKey;
188
+ const depositor = params.depositor
189
+ ? (0, anchor_1.translateAddress)(params.depositor)
190
+ : this.provider.publicKey;
183
191
  if (!depositor) {
184
192
  throw new Error("Either provide a depositor or use AnchorProvider for provider in the service");
185
193
  }
@@ -238,7 +246,9 @@ class ZebecVaultService {
238
246
  return closeWsolAccountIx;
239
247
  }
240
248
  async withdraw(params) {
241
- const withdrawer = params.withdrawer ? (0, anchor_1.translateAddress)(params.withdrawer) : this.provider.publicKey;
249
+ const withdrawer = params.withdrawer
250
+ ? (0, anchor_1.translateAddress)(params.withdrawer)
251
+ : this.provider.publicKey;
242
252
  if (!withdrawer) {
243
253
  throw new Error("Either provide a withdrawer or use AnchorProvider for provider in the service");
244
254
  }
@@ -264,7 +274,9 @@ class ZebecVaultService {
264
274
  return this._createTransactionPayload(withdrawer, instructions);
265
275
  }
266
276
  async createProposal(params) {
267
- const proposer = params.proposer ? (0, anchor_1.translateAddress)(params.proposer) : this.provider.publicKey;
277
+ const proposer = params.proposer
278
+ ? (0, anchor_1.translateAddress)(params.proposer)
279
+ : this.provider.publicKey;
268
280
  if (!proposer) {
269
281
  throw new Error("Either provide a proposer or use AnchorProvider for provider in the service");
270
282
  }
@@ -278,7 +290,9 @@ class ZebecVaultService {
278
290
  return this._createTransactionPayload(proposer, [ix], [proposalKeypair]);
279
291
  }
280
292
  async appendActions(params) {
281
- const proposer = params.proposer ? (0, anchor_1.translateAddress)(params.proposer) : this.provider.publicKey;
293
+ const proposer = params.proposer
294
+ ? (0, anchor_1.translateAddress)(params.proposer)
295
+ : this.provider.publicKey;
282
296
  if (!proposer) {
283
297
  throw new Error("Either provide a proposer or use AnchorProvider for provider in the service");
284
298
  }
@@ -298,7 +312,9 @@ class ZebecVaultService {
298
312
  return this._createTransactionPayload(proposer, [ix]);
299
313
  }
300
314
  async deleteProposal(params) {
301
- const caller = params.caller ? (0, anchor_1.translateAddress)(params.caller) : this.provider.publicKey;
315
+ const caller = params.caller
316
+ ? (0, anchor_1.translateAddress)(params.caller)
317
+ : this.provider.publicKey;
302
318
  if (!caller) {
303
319
  throw new Error("Either provide a caller or use AnchorProvider for provider in the service");
304
320
  }
@@ -307,7 +323,9 @@ class ZebecVaultService {
307
323
  return this._createTransactionPayload(caller, [ix]);
308
324
  }
309
325
  async executeProposal(params) {
310
- const caller = params.caller ? (0, anchor_1.translateAddress)(params.caller) : this.provider.publicKey;
326
+ const caller = params.caller
327
+ ? (0, anchor_1.translateAddress)(params.caller)
328
+ : this.provider.publicKey;
311
329
  if (!caller) {
312
330
  throw new Error("Either provide a caller or use AnchorProvider for provider in the service");
313
331
  }
@@ -347,7 +365,9 @@ class ZebecVaultService {
347
365
  return this._createTransactionPayload(caller, [ix], params.partialSigners, addressLookupTableAccounts);
348
366
  }
349
367
  async executeProposalDirect(params) {
350
- const proposer = params.proposer ? (0, anchor_1.translateAddress)(params.proposer) : this.provider.publicKey;
368
+ const proposer = params.proposer
369
+ ? (0, anchor_1.translateAddress)(params.proposer)
370
+ : this.provider.publicKey;
351
371
  if (!proposer) {
352
372
  throw new Error("Either provide a caller or use AnchorProvider for provider in the service");
353
373
  }
@@ -581,12 +601,14 @@ class ZebecVaultService {
581
601
  }
582
602
  }
583
603
  async getNextCardIndex() {
584
- const [cardConfig] = (0, pda_1.deriveCardConfigPda)(this.cardV2Program.programId);
604
+ const [cardConfig] = (0, zebec_card_v2_sdk_1.deriveCardConfigPda)(this.cardV2Program.programId);
585
605
  const decoded = await this.cardV2Program.account.card.fetch(cardConfig, "confirmed");
586
606
  return BigInt(decoded.index.addn(1).toString());
587
607
  }
588
608
  async createSilverCard(params) {
589
- const vaultOwner = params.vaultOwnerAddress ? (0, anchor_1.translateAddress)(params.vaultOwnerAddress) : this.provider.publicKey;
609
+ const vaultOwner = params.vaultOwnerAddress
610
+ ? (0, anchor_1.translateAddress)(params.vaultOwnerAddress)
611
+ : this.provider.publicKey;
590
612
  if (!vaultOwner) {
591
613
  throw new Error("Either provide a caller or use AnchorProvider for provider in the service");
592
614
  }
@@ -595,14 +617,16 @@ class ZebecVaultService {
595
617
  const [vaultSigner] = (0, pda_1.deriveVaultSigner)(vault, this.vaultV1ProgramId);
596
618
  const usdcMint = (0, anchor_1.translateAddress)(params.usdcAddress);
597
619
  const amount = (0, bignumber_js_1.BigNumber)(params.amount);
598
- const [cardConfig] = (0, pda_1.deriveCardConfigPda)(this.cardV2Program.programId);
599
- const [userPurchaseRecord] = (0, pda_1.deriveUserPurchaseRecordPda)(vaultSigner, this.cardV2Program.programId);
620
+ const [cardConfig] = (0, zebec_card_v2_sdk_1.deriveCardConfigPda)(this.cardV2Program.programId);
621
+ const [userPurchaseRecord] = (0, zebec_card_v2_sdk_1.deriveUserPurchaseRecordPda)(vaultSigner, this.cardV2Program.programId);
600
622
  const cardConfigInfo = await this.cardV2Program.account.card.fetch(cardConfig, "confirmed");
601
623
  const cardVault = cardConfigInfo.cardVault;
602
624
  const revenueVault = cardConfigInfo.revenueVault;
603
625
  const cardVaultAta = (0, solana_common_1.getAssociatedTokenAddressSync)(usdcMint, cardVault, true);
604
626
  const revenueVaultAta = (0, solana_common_1.getAssociatedTokenAddressSync)(usdcMint, revenueVault, true);
605
- const parsedAmount = amount.times(solana_common_1.UNITS_PER_USDC).decimalPlaces(0, bignumber_js_1.BigNumber.ROUND_DOWN);
627
+ const parsedAmount = amount
628
+ .times(solana_common_1.UNITS_PER_USDC)
629
+ .decimalPlaces(0, bignumber_js_1.BigNumber.ROUND_DOWN);
606
630
  await this._checkAmountIsWithinProviderRange(cardConfigInfo, parsedAmount);
607
631
  await this._checkAmountIsWithinDailyCardLimit(cardConfigInfo, userPurchaseRecord, parsedAmount);
608
632
  const index = new anchor_1.BN(params.nextCardIndex.toString());
@@ -612,7 +636,9 @@ class ZebecVaultService {
612
636
  currency: params.currency,
613
637
  emailHash: Array.from(params.emailHash),
614
638
  });
615
- const actions = [(0, utils_1.transactionInstructionToPropoalAction)(ix)];
639
+ const actions = [
640
+ (0, utils_1.transactionInstructionToPropoalAction)(ix),
641
+ ];
616
642
  const remainingAccounts = actions.reduce((acc, current) => {
617
643
  const accounts = current.accountSpecs.map((spec) => ({
618
644
  pubkey: spec.pubkey,
@@ -633,7 +659,9 @@ class ZebecVaultService {
633
659
  return this._createTransactionPayload(vaultOwner, [executeProposalDirectIx], [], [lookupTableAccount]);
634
660
  }
635
661
  async loadCarbonCard(params) {
636
- const vaultOwner = params.vaultOwnerAddress ? (0, anchor_1.translateAddress)(params.vaultOwnerAddress) : this.provider.publicKey;
662
+ const vaultOwner = params.vaultOwnerAddress
663
+ ? (0, anchor_1.translateAddress)(params.vaultOwnerAddress)
664
+ : this.provider.publicKey;
637
665
  if (!vaultOwner) {
638
666
  throw new Error("Either provide a caller or use AnchorProvider for provider in the service");
639
667
  }
@@ -642,14 +670,16 @@ class ZebecVaultService {
642
670
  const [vaultSigner] = (0, pda_1.deriveVaultSigner)(vault, this.vaultV1ProgramId);
643
671
  const usdcMint = (0, anchor_1.translateAddress)(params.usdcAddress);
644
672
  const amount = (0, bignumber_js_1.BigNumber)(params.amount);
645
- const [cardConfig] = (0, pda_1.deriveCardConfigPda)(this.cardV2Program.programId);
646
- const [userPurchaseRecord] = (0, pda_1.deriveUserPurchaseRecordPda)(vaultSigner, this.cardV2Program.programId);
673
+ const [cardConfig] = (0, zebec_card_v2_sdk_1.deriveCardConfigPda)(this.cardV2Program.programId);
674
+ const [userPurchaseRecord] = (0, zebec_card_v2_sdk_1.deriveUserPurchaseRecordPda)(vaultSigner, this.cardV2Program.programId);
647
675
  const cardConfigInfo = await this.cardV2Program.account.card.fetch(cardConfig, "confirmed");
648
676
  const cardVault = cardConfigInfo.cardVault;
649
677
  const revenueVault = cardConfigInfo.revenueVault;
650
678
  const cardVaultAta = (0, solana_common_1.getAssociatedTokenAddressSync)(usdcMint, cardVault, true);
651
679
  const revenueVaultAta = (0, solana_common_1.getAssociatedTokenAddressSync)(usdcMint, revenueVault, true);
652
- const parsedAmount = amount.times(solana_common_1.UNITS_PER_USDC).decimalPlaces(0, bignumber_js_1.BigNumber.ROUND_DOWN);
680
+ const parsedAmount = amount
681
+ .times(solana_common_1.UNITS_PER_USDC)
682
+ .decimalPlaces(0, bignumber_js_1.BigNumber.ROUND_DOWN);
653
683
  await this._checkAmountIsWithinProviderRange(cardConfigInfo, parsedAmount);
654
684
  await this._checkAmountIsWithinDailyCardLimit(cardConfigInfo, userPurchaseRecord, parsedAmount);
655
685
  const index = new anchor_1.BN(params.nextCardIndex.toString());
@@ -660,7 +690,9 @@ class ZebecVaultService {
660
690
  emailHash: Array.from(params.emailHash),
661
691
  reloadCardId: params.reloadCardId,
662
692
  });
663
- const actions = [(0, utils_1.transactionInstructionToPropoalAction)(ix)];
693
+ const actions = [
694
+ (0, utils_1.transactionInstructionToPropoalAction)(ix),
695
+ ];
664
696
  const remainingAccounts = actions.reduce((acc, current) => {
665
697
  const accounts = current.accountSpecs.map((spec) => ({
666
698
  pubkey: spec.pubkey,
@@ -691,8 +723,8 @@ class ZebecVaultService {
691
723
  const [vaultSigner] = (0, pda_1.deriveVaultSigner)(vault, this.vaultV1ProgramId);
692
724
  const inputMint = (0, anchor_1.translateAddress)(quoteInfo.inputMint);
693
725
  const usdc = (0, anchor_1.translateAddress)(quoteInfo.outputMint);
694
- const [userPurchaseRecord] = (0, pda_1.deriveUserPurchaseRecordPda)(vaultSigner, this.cardV2ProgramId);
695
- const [cardConfig] = (0, pda_1.deriveCardConfigPda)(this.cardV2ProgramId);
726
+ const [userPurchaseRecord] = (0, zebec_card_v2_sdk_1.deriveUserPurchaseRecordPda)(vaultSigner, this.cardV2ProgramId);
727
+ const [cardConfig] = (0, zebec_card_v2_sdk_1.deriveCardConfigPda)(this.cardV2ProgramId);
696
728
  const cardConfigInfo = await this.cardV2Program.account.card.fetch(cardConfig, this.connection.commitment);
697
729
  const revenueVault = cardConfigInfo.revenueVault;
698
730
  const cardVault = cardConfigInfo.cardVault;
@@ -710,7 +742,7 @@ class ZebecVaultService {
710
742
  if (!inputMint.equals(solana_common_1.WSOL) || !isSolWrapUnwrapNeeded) {
711
743
  const userInputMintAtaInfo = await this.connection.getAccountInfo(userInputMintAta, this.connection.commitment);
712
744
  if (!userInputMintAtaInfo) {
713
- throw new errors_1.AssociatedTokenAccountDoesNotExistsError("User doesn't have associated token account of input mint: " + inputMint.toString());
745
+ throw new errors_1.AssociatedTokenAccountDoesNotExistsError(`User doesn't have associated token account of input mint: ${inputMint.toString()}`);
714
746
  }
715
747
  const resAndCtx = await this.connection.getTokenAccountBalance(userInputMintAta, this.connection.commitment);
716
748
  const balance = resAndCtx.value.amount;
@@ -727,7 +759,9 @@ class ZebecVaultService {
727
759
  const customTokenFees = await this.getCardCustomTokenFees();
728
760
  const customTokenFee = customTokenFees.find((tf) => tf.tokenAddress === quoteInfo.inputMint);
729
761
  const DEFAULT_SWAP_FEE = 5;
730
- const swapFee = customTokenFee ? (0, bignumber_js_1.BigNumber)(customTokenFee.fee) : (0, bignumber_js_1.BigNumber)(DEFAULT_SWAP_FEE);
762
+ const swapFee = customTokenFee
763
+ ? (0, bignumber_js_1.BigNumber)(customTokenFee.fee)
764
+ : (0, bignumber_js_1.BigNumber)(DEFAULT_SWAP_FEE);
731
765
  const amountAfterFeeDeduction = amount.minus(amount.times(swapFee.div(100)));
732
766
  await this._checkAmountIsWithinProviderRange(cardConfigInfo, amountAfterFeeDeduction);
733
767
  await this._checkAmountIsWithinDailyCardLimit(cardConfigInfo, userPurchaseRecord, amountAfterFeeDeduction);
@@ -752,15 +786,27 @@ class ZebecVaultService {
752
786
  const transaction = web3_js_1.VersionedTransaction.deserialize(swapTransactionBuf);
753
787
  // get address lookup table accounts
754
788
  const addressLookupTableAccounts = await Promise.all(transaction.message.addressTableLookups.map(async (lookup) => {
755
- const data = await this.connection.getAccountInfo(lookup.accountKey).then((res) => res.data);
789
+ const data = await this.connection
790
+ .getAccountInfo(lookup.accountKey)
791
+ .then((res) => {
792
+ if (!res) {
793
+ throw new Error(`Lookup table account not found for key: ${(0, anchor_1.translateAddress)(constants_1.CARD_LOOKUP_TABLE_ADDRESS[this.network]).toString()}`);
794
+ }
795
+ return res.data;
796
+ });
756
797
  return new web3_js_1.AddressLookupTableAccount({
757
798
  key: lookup.accountKey,
758
799
  state: web3_js_1.AddressLookupTableAccount.deserialize(data),
759
800
  });
760
801
  }));
761
- const lookupTableData = await new web3_js_1.Connection((0, web3_js_1.clusterApiUrl)("devnet"))
802
+ const lookupTableData = await this.connection
762
803
  .getAccountInfo((0, anchor_1.translateAddress)(constants_1.CARD_LOOKUP_TABLE_ADDRESS[this.network]))
763
- .then((res) => res.data);
804
+ .then((res) => {
805
+ if (!res) {
806
+ throw new Error(`Lookup table account not found for key: ${(0, anchor_1.translateAddress)(constants_1.CARD_LOOKUP_TABLE_ADDRESS[this.network]).toString()}`);
807
+ }
808
+ return res.data;
809
+ });
764
810
  addressLookupTableAccounts.push(new web3_js_1.AddressLookupTableAccount({
765
811
  key: (0, anchor_1.translateAddress)(constants_1.CARD_LOOKUP_TABLE_ADDRESS[this.network]),
766
812
  state: web3_js_1.AddressLookupTableAccount.deserialize(lookupTableData),
@@ -785,7 +831,7 @@ class ZebecVaultService {
785
831
  return this._createTransactionPayload(vaultOwner, otherIxs, [], addressLookupTableAccounts);
786
832
  }
787
833
  async swapAndLoadCarbonCard(params) {
788
- const { vaultOwnerAddress, quoteInfo, emailHash, reloadCardId, wrapAndUnwrapSol } = params;
834
+ const { vaultOwnerAddress, quoteInfo, emailHash, reloadCardId, wrapAndUnwrapSol, } = params;
789
835
  if ("error" in quoteInfo) {
790
836
  throw new Error(quoteInfo.error);
791
837
  }
@@ -795,8 +841,8 @@ class ZebecVaultService {
795
841
  const [vaultSigner] = (0, pda_1.deriveVaultSigner)(vault, this.vaultV1ProgramId);
796
842
  const inputMint = (0, anchor_1.translateAddress)(quoteInfo.inputMint);
797
843
  const usdc = (0, anchor_1.translateAddress)(quoteInfo.outputMint);
798
- const [userPurchaseRecord] = (0, pda_1.deriveUserPurchaseRecordPda)(vaultSigner, this.cardV2ProgramId);
799
- const [cardConfig] = (0, pda_1.deriveCardConfigPda)(this.cardV2ProgramId);
844
+ const [userPurchaseRecord] = (0, zebec_card_v2_sdk_1.deriveUserPurchaseRecordPda)(vaultSigner, this.cardV2ProgramId);
845
+ const [cardConfig] = (0, zebec_card_v2_sdk_1.deriveCardConfigPda)(this.cardV2ProgramId);
800
846
  const cardConfigInfo = await this.cardV2Program.account.card.fetch(cardConfig, this.connection.commitment);
801
847
  const revenueVault = cardConfigInfo.revenueVault;
802
848
  const cardVault = cardConfigInfo.cardVault;
@@ -814,7 +860,8 @@ class ZebecVaultService {
814
860
  if (!inputMint.equals(solana_common_1.WSOL) || !isSolWrapUnwrapNeeded) {
815
861
  const userInputMintAtaInfo = await this.connection.getAccountInfo(userInputMintAta, this.connection.commitment);
816
862
  if (!userInputMintAtaInfo) {
817
- throw new errors_1.AssociatedTokenAccountDoesNotExistsError("User doesn't have associated token account of input mint: " + inputMint.toString());
863
+ throw new errors_1.AssociatedTokenAccountDoesNotExistsError("User doesn't have associated token account of input mint: " +
864
+ inputMint.toString());
818
865
  }
819
866
  const resAndCtx = await this.connection.getTokenAccountBalance(userInputMintAta, this.connection.commitment);
820
867
  const balance = resAndCtx.value.amount;
@@ -831,7 +878,9 @@ class ZebecVaultService {
831
878
  const customTokenFees = await this.getCardCustomTokenFees();
832
879
  const customTokenFee = customTokenFees.find((tf) => tf.tokenAddress === quoteInfo.inputMint);
833
880
  const DEFAULT_SWAP_FEE = 5;
834
- const swapFee = customTokenFee ? (0, bignumber_js_1.BigNumber)(customTokenFee.fee) : (0, bignumber_js_1.BigNumber)(DEFAULT_SWAP_FEE);
881
+ const swapFee = customTokenFee
882
+ ? (0, bignumber_js_1.BigNumber)(customTokenFee.fee)
883
+ : (0, bignumber_js_1.BigNumber)(DEFAULT_SWAP_FEE);
835
884
  const amountAfterFeeDeduction = amount.minus(amount.times(swapFee.div(100)));
836
885
  await this._checkAmountIsWithinProviderRange(cardConfigInfo, amountAfterFeeDeduction);
837
886
  await this._checkAmountIsWithinDailyCardLimit(cardConfigInfo, userPurchaseRecord, amountAfterFeeDeduction);
@@ -856,15 +905,27 @@ class ZebecVaultService {
856
905
  const transaction = web3_js_1.VersionedTransaction.deserialize(swapTransactionBuf);
857
906
  // get address lookup table accounts
858
907
  const addressLookupTableAccounts = await Promise.all(transaction.message.addressTableLookups.map(async (lookup) => {
859
- const data = await this.connection.getAccountInfo(lookup.accountKey).then((res) => res.data);
908
+ const data = await this.connection
909
+ .getAccountInfo(lookup.accountKey)
910
+ .then((res) => {
911
+ if (!res) {
912
+ throw new Error(`Lookup table account not found for key: ${lookup.accountKey.toString()}`);
913
+ }
914
+ return res.data;
915
+ });
860
916
  return new web3_js_1.AddressLookupTableAccount({
861
917
  key: lookup.accountKey,
862
918
  state: web3_js_1.AddressLookupTableAccount.deserialize(data),
863
919
  });
864
920
  }));
865
- const lookupTableData = await new web3_js_1.Connection((0, web3_js_1.clusterApiUrl)("devnet"))
921
+ const lookupTableData = await this.connection
866
922
  .getAccountInfo((0, anchor_1.translateAddress)(constants_1.CARD_LOOKUP_TABLE_ADDRESS[this.network]))
867
- .then((res) => res.data);
923
+ .then((res) => {
924
+ if (!res) {
925
+ throw new Error(`Lookup table account not found for key: ${(0, anchor_1.translateAddress)(constants_1.CARD_LOOKUP_TABLE_ADDRESS[this.network]).toString()}`);
926
+ }
927
+ return res.data;
928
+ });
868
929
  addressLookupTableAccounts.push(new web3_js_1.AddressLookupTableAccount({
869
930
  key: (0, anchor_1.translateAddress)(constants_1.CARD_LOOKUP_TABLE_ADDRESS[this.network]),
870
931
  state: web3_js_1.AddressLookupTableAccount.deserialize(lookupTableData),
@@ -890,7 +951,7 @@ class ZebecVaultService {
890
951
  return this._createTransactionPayload(vaultOwner, otherIxs, [], addressLookupTableAccounts);
891
952
  }
892
953
  async getCardCustomTokenFees() {
893
- const [tokeFeeMapPda] = (0, pda_1.deriveTokenFeeMapPda)(this.cardV2ProgramId);
954
+ const [tokeFeeMapPda] = (0, zebec_card_v2_sdk_1.deriveTokenFeeMapPda)(this.cardV2ProgramId);
894
955
  const decoded = await this.cardV2Program.account.customFeeMap.fetch(tokeFeeMapPda, this.connection.commitment);
895
956
  const tokenFeeList = decoded.feeMap.map((item) => ({
896
957
  tokenAddress: item.tokenAddress,
@@ -898,6 +959,21 @@ class ZebecVaultService {
898
959
  }));
899
960
  return tokenFeeList;
900
961
  }
962
+ async getTransfeFeesForStreamInstruction(streamConfig, feeVault, tokenMint, vaultOwner, feeVaultTokenAccount, vault, vaultSigner, vaultSignerTokenAccount, data) {
963
+ return this.vaultV1Program.methods
964
+ .transferFees({ decimals: data.decimals, feeAmount: data.feeAmount })
965
+ .accountsPartial({
966
+ streamConfig,
967
+ feeVault,
968
+ tokenMint,
969
+ vaultOwner,
970
+ feeVaultTokenAccount,
971
+ vault,
972
+ vaultSigner,
973
+ vaultSignerTokenAccount,
974
+ })
975
+ .instruction();
976
+ }
901
977
  async getCreateStreamFromVaultInstruction(vaultOwner, vault, vaultSigner, vaultSignerAta, receiver, receiverAta, streamToken, streamMetadata, streamConfig, withdrawAccount, streamVault, streamVaultAta, zebecStreamProgram, streamData) {
902
978
  return this.vaultV1Program.methods
903
979
  .createStream({
@@ -984,6 +1060,19 @@ class ZebecVaultService {
984
1060
  })
985
1061
  .instruction();
986
1062
  }
1063
+ async getTransferFeesForStreamInstruction(feeVault, tokenMint, vaultOwner, feeVaultTokenAccount, vault, vaultSigner, vaultSignerTokenAccount, data) {
1064
+ return this.vaultV1Program.methods
1065
+ .transferFees({ decimals: data.decimals, feeAmount: data.feeAmount })
1066
+ .accountsPartial({
1067
+ feeVault,
1068
+ tokenMint,
1069
+ vaultOwner,
1070
+ feeVaultTokenAccount,
1071
+ vault,
1072
+ vaultSigner,
1073
+ vaultSignerTokenAccount,
1074
+ });
1075
+ }
987
1076
  async createStreamFromVault(params) {
988
1077
  const vaultOwner = (0, anchor_1.translateAddress)(params.vaultOwner);
989
1078
  const [vault] = (0, pda_1.deriveUserVault)(vaultOwner, this.vaultV1ProgramId);
@@ -994,15 +1083,30 @@ class ZebecVaultService {
994
1083
  const streamToken = (0, anchor_1.translateAddress)(params.streamToken);
995
1084
  const vaultSignerAta = (0, solana_common_1.getAssociatedTokenAddressSync)(streamToken, vaultSigner, true);
996
1085
  const receiverVaultSignerAta = (0, solana_common_1.getAssociatedTokenAddressSync)(streamToken, receiverVaultSigner, true);
997
- const [streamConfig] = (0, pda_1.deriveStreamConfigPda)(this.streamProgramId);
1086
+ const [streamConfig] = (0, zebec_stream_sdk_1.deriveStreamConfigPda)(params.streamConfigName, this.streamProgramId);
998
1087
  const streamConfigInfo = await this.streamProgram.account.streamConfig.fetch(streamConfig, this.connection.commitment);
999
1088
  const withdrawAccount = streamConfigInfo.withdrawAccount;
1000
1089
  const streamMetatdataKeypair = params.streamMetadataKeypair ?? web3_js_1.Keypair.generate();
1001
1090
  const streamMetadata = streamMetatdataKeypair.publicKey;
1002
- const [streamVault] = (0, pda_1.deriveStreamVaultPda)(streamMetadata, this.streamProgramId);
1091
+ const [streamVault] = (0, zebec_stream_sdk_1.deriveStreamVaultPda)(streamMetadata, this.streamProgramId);
1003
1092
  const streamVaultAta = (0, solana_common_1.getAssociatedTokenAddressSync)(streamToken, streamVault, true);
1004
1093
  const streamTokenDecimals = await (0, solana_common_1.getMintDecimals)(this.connection, streamToken);
1005
- const amount = new anchor_1.BN((0, bignumber_js_1.BigNumber)(params.amount).times(solana_common_1.TEN_BIGNUM.pow(streamTokenDecimals)).toFixed(0));
1094
+ const amount = (0, bignumber_js_1.BigNumber)(params.amount)
1095
+ .times(solana_common_1.TEN_BIGNUM.pow(streamTokenDecimals))
1096
+ .toFixed(0);
1097
+ const feeInfo = await (0, zebec_stream_sdk_1.getFeeInfoForStream)(streamToken, amount, streamTokenDecimals, this.network);
1098
+ const feeToken = (0, anchor_1.translateAddress)(feeInfo.feeToken.mintAddress);
1099
+ const feeTokenDecimals = await (0, solana_common_1.getMintDecimals)(this.connection, feeToken);
1100
+ const parsedFeeAmount = feeInfo.feeAmountRaw;
1101
+ const feeVault = streamConfigInfo.feeVault;
1102
+ const feeVaultAta = (0, solana_common_1.getAssociatedTokenAddressSync)(feeToken, feeVault, true);
1103
+ const vaultSignerFeeTokenAta = (0, solana_common_1.getAssociatedTokenAddressSync)(feeToken, vaultSigner, true);
1104
+ const ixs = [];
1105
+ const transferFeesIx = await this.getTransfeFeesForStreamInstruction(streamConfig, feeVault, feeToken, vaultOwner, feeVaultAta, vault, vaultSigner, vaultSignerFeeTokenAta, {
1106
+ decimals: feeTokenDecimals,
1107
+ feeAmount: new anchor_1.BN(parsedFeeAmount),
1108
+ });
1109
+ ixs.push(transferFeesIx);
1006
1110
  const cliffPercentage = new anchor_1.BN((0, core_utils_1.percentToBps)(params.cliffPercentage));
1007
1111
  const STREAM_NAME_BUFFER_SIZE = 128;
1008
1112
  const streamNameArray = new Uint8Array(STREAM_NAME_BUFFER_SIZE);
@@ -1011,8 +1115,8 @@ class ZebecVaultService {
1011
1115
  if (params.automaticWithdrawal && autoWithdrawFrequency <= 0) {
1012
1116
  throw new Error("autoWithdrawFrequency must be greater than 0 when automaticWithdrawal is enabled");
1013
1117
  }
1014
- const ix = await this.getCreateStreamFromVaultInstruction(vaultOwner, vault, vaultSigner, vaultSignerAta, receiverVaultSigner, receiverVaultSignerAta, streamToken, streamMetadata, streamConfig, withdrawAccount, streamVault, streamVaultAta, this.streamProgramId, {
1015
- amount,
1118
+ const createStreamIx = await this.getCreateStreamFromVaultInstruction(vaultOwner, vault, vaultSigner, vaultSignerAta, receiverVaultSigner, receiverVaultSignerAta, streamToken, streamMetadata, streamConfig, withdrawAccount, streamVault, streamVaultAta, this.streamProgramId, {
1119
+ amount: new anchor_1.BN(amount),
1016
1120
  automaticWithdrawal: params.automaticWithdrawal,
1017
1121
  autoWithdrawFrequency: new anchor_1.BN(autoWithdrawFrequency),
1018
1122
  cancelableByRecipient: params.cancelableByRecipient,
@@ -1021,7 +1125,9 @@ class ZebecVaultService {
1021
1125
  cliffPercentage,
1022
1126
  duration: new anchor_1.BN(params.duration),
1023
1127
  isPausable: params.isPausable,
1024
- numberOfWithdrawls: autoWithdrawFrequency > 0 ? new anchor_1.BN(Math.floor(params.duration / autoWithdrawFrequency)) : new anchor_1.BN(0),
1128
+ numberOfWithdrawls: autoWithdrawFrequency > 0
1129
+ ? new anchor_1.BN(Math.floor(params.duration / autoWithdrawFrequency))
1130
+ : new anchor_1.BN(0),
1025
1131
  rateUpdatable: params.rateUpdatable,
1026
1132
  startNow: params.startNow,
1027
1133
  startTime: new anchor_1.BN(params.startTime),
@@ -1029,12 +1135,39 @@ class ZebecVaultService {
1029
1135
  transferableByRecipient: params.transferableByRecipient,
1030
1136
  transferableBySender: params.transferableBySender,
1031
1137
  });
1032
- return this._createTransactionPayload(vaultOwner, [ix], [streamMetatdataKeypair]);
1138
+ const lookupTable = zebec_stream_sdk_1.STREAM_PROGRAM_LOOKUP_TABLE_ADDRESS[this.network];
1139
+ const lookupTableData = await this.connection
1140
+ .getAccountInfo((0, anchor_1.translateAddress)(lookupTable))
1141
+ .then((res) => {
1142
+ if (!res) {
1143
+ throw new Error(`Lookup table account not found for key: ${(0, anchor_1.translateAddress)(constants_1.CARD_LOOKUP_TABLE_ADDRESS[this.network]).toString()}`);
1144
+ }
1145
+ return res.data;
1146
+ });
1147
+ const addressLookupTableAccount = new web3_js_1.AddressLookupTableAccount({
1148
+ key: (0, anchor_1.translateAddress)(lookupTable),
1149
+ state: web3_js_1.AddressLookupTableAccount.deserialize(lookupTableData),
1150
+ });
1151
+ ixs.push(createStreamIx);
1152
+ return this._createTransactionPayload(vaultOwner, ixs, [streamMetatdataKeypair], [addressLookupTableAccount]);
1033
1153
  }
1034
1154
  async createMultipleStreamFromVault(params) {
1035
1155
  const vaultOwner = (0, anchor_1.translateAddress)(params.vaultOwner);
1036
1156
  const [vault] = (0, pda_1.deriveUserVault)(vaultOwner, this.vaultV1ProgramId);
1037
1157
  const [vaultSigner] = (0, pda_1.deriveVaultSigner)(vault, this.vaultV1ProgramId);
1158
+ const lookupTable = zebec_stream_sdk_1.STREAM_PROGRAM_LOOKUP_TABLE_ADDRESS[this.network];
1159
+ const lookupTableData = await this.connection
1160
+ .getAccountInfo((0, anchor_1.translateAddress)(lookupTable))
1161
+ .then((res) => {
1162
+ if (!res) {
1163
+ throw new Error(`Lookup table account not found for key: ${(0, anchor_1.translateAddress)(constants_1.CARD_LOOKUP_TABLE_ADDRESS[this.network]).toString()}`);
1164
+ }
1165
+ return res.data;
1166
+ });
1167
+ const addressLookupTableAccount = new web3_js_1.AddressLookupTableAccount({
1168
+ key: (0, anchor_1.translateAddress)(lookupTable),
1169
+ state: web3_js_1.AddressLookupTableAccount.deserialize(lookupTableData),
1170
+ });
1038
1171
  const transactionArtifacts = await Promise.all(params.streamInfo.map(async (info) => {
1039
1172
  const receiver = (0, anchor_1.translateAddress)(info.receiver);
1040
1173
  const [receiverVault] = (0, pda_1.deriveUserVault)(receiver, this.vaultV1ProgramId);
@@ -1042,15 +1175,30 @@ class ZebecVaultService {
1042
1175
  const streamToken = (0, anchor_1.translateAddress)(info.streamToken);
1043
1176
  const vaultSignerAta = (0, solana_common_1.getAssociatedTokenAddressSync)(streamToken, vaultSigner, true);
1044
1177
  const receiverVaultSignerAta = (0, solana_common_1.getAssociatedTokenAddressSync)(streamToken, receiverVaultSigner, true);
1045
- const [streamConfig] = (0, pda_1.deriveStreamConfigPda)(this.streamProgramId);
1178
+ const [streamConfig] = (0, zebec_stream_sdk_1.deriveStreamConfigPda)(params.streamConfigName, this.streamProgramId);
1046
1179
  const streamConfigInfo = await this.streamProgram.account.streamConfig.fetch(streamConfig, this.connection.commitment);
1047
1180
  const withdrawAccount = streamConfigInfo.withdrawAccount;
1048
1181
  const streamMetatdataKeypair = info.streamMetadataKeypair ?? web3_js_1.Keypair.generate();
1049
1182
  const streamMetadata = streamMetatdataKeypair.publicKey;
1050
- const [streamVault] = (0, pda_1.deriveStreamVaultPda)(streamMetadata, this.streamProgramId);
1183
+ const [streamVault] = (0, zebec_stream_sdk_1.deriveStreamVaultPda)(streamMetadata, this.streamProgramId);
1051
1184
  const streamVaultAta = (0, solana_common_1.getAssociatedTokenAddressSync)(streamToken, streamVault, true);
1052
1185
  const streamTokenDecimals = await (0, solana_common_1.getMintDecimals)(this.connection, streamToken);
1053
- const amount = new anchor_1.BN((0, bignumber_js_1.BigNumber)(info.amount).times(solana_common_1.TEN_BIGNUM.pow(streamTokenDecimals)).toFixed(0));
1186
+ const amount = (0, bignumber_js_1.BigNumber)(info.amount)
1187
+ .times(solana_common_1.TEN_BIGNUM.pow(streamTokenDecimals))
1188
+ .toFixed(0);
1189
+ const feeInfo = await (0, zebec_stream_sdk_1.getFeeInfoForStream)(streamToken, amount, streamTokenDecimals, this.network);
1190
+ const feeToken = (0, anchor_1.translateAddress)(feeInfo.feeToken.mintAddress);
1191
+ const feeTokenDecimals = await (0, solana_common_1.getMintDecimals)(this.connection, feeToken);
1192
+ const parsedFeeAmount = feeInfo.feeAmountRaw;
1193
+ const feeVault = streamConfigInfo.feeVault;
1194
+ const feeVaultAta = (0, solana_common_1.getAssociatedTokenAddressSync)(feeToken, feeVault, true);
1195
+ const vaultSignerFeeTokenAta = (0, solana_common_1.getAssociatedTokenAddressSync)(feeToken, vaultSigner, true);
1196
+ const ixs = [];
1197
+ const transferFeesIx = await this.getTransfeFeesForStreamInstruction(streamConfig, feeVault, feeToken, vaultOwner, feeVaultAta, vault, vaultSigner, vaultSignerFeeTokenAta, {
1198
+ decimals: feeTokenDecimals,
1199
+ feeAmount: new anchor_1.BN(parsedFeeAmount),
1200
+ });
1201
+ ixs.push(transferFeesIx);
1054
1202
  const cliffPercentage = new anchor_1.BN((0, core_utils_1.percentToBps)(info.cliffPercentage));
1055
1203
  const STREAM_NAME_BUFFER_SIZE = 128;
1056
1204
  const streamNameArray = new Uint8Array(STREAM_NAME_BUFFER_SIZE);
@@ -1059,8 +1207,8 @@ class ZebecVaultService {
1059
1207
  if (info.automaticWithdrawal && autoWithdrawFrequency <= 0) {
1060
1208
  throw new Error("autoWithdrawFrequency must be greater than 0 when automaticWithdrawal is enabled");
1061
1209
  }
1062
- const ix = await this.getCreateStreamFromVaultInstruction(vaultOwner, vault, vaultSigner, vaultSignerAta, receiverVaultSigner, receiverVaultSignerAta, streamToken, streamMetadata, streamConfig, withdrawAccount, streamVault, streamVaultAta, this.streamProgramId, {
1063
- amount,
1210
+ const createStreamIx = await this.getCreateStreamFromVaultInstruction(vaultOwner, vault, vaultSigner, vaultSignerAta, receiverVaultSigner, receiverVaultSignerAta, streamToken, streamMetadata, streamConfig, withdrawAccount, streamVault, streamVaultAta, this.streamProgramId, {
1211
+ amount: new anchor_1.BN(amount),
1064
1212
  automaticWithdrawal: info.automaticWithdrawal,
1065
1213
  autoWithdrawFrequency: new anchor_1.BN(autoWithdrawFrequency),
1066
1214
  cancelableByRecipient: info.cancelableByRecipient,
@@ -1069,7 +1217,9 @@ class ZebecVaultService {
1069
1217
  cliffPercentage,
1070
1218
  duration: new anchor_1.BN(info.duration),
1071
1219
  isPausable: info.isPausable,
1072
- numberOfWithdrawls: autoWithdrawFrequency > 0 ? new anchor_1.BN(Math.floor(info.duration / autoWithdrawFrequency)) : new anchor_1.BN(0),
1220
+ numberOfWithdrawls: autoWithdrawFrequency > 0
1221
+ ? new anchor_1.BN(Math.floor(info.duration / autoWithdrawFrequency))
1222
+ : new anchor_1.BN(0),
1073
1223
  rateUpdatable: info.rateUpdatable,
1074
1224
  startNow: info.startNow,
1075
1225
  startTime: new anchor_1.BN(info.startTime),
@@ -1077,15 +1227,19 @@ class ZebecVaultService {
1077
1227
  transferableByRecipient: info.transferableByRecipient,
1078
1228
  transferableBySender: info.transferableBySender,
1079
1229
  });
1230
+ ixs.push(createStreamIx);
1080
1231
  return {
1081
- instructions: [ix],
1232
+ instructions: ixs,
1082
1233
  signers: [streamMetatdataKeypair],
1234
+ addressLookupTableAccounts: [addressLookupTableAccount],
1083
1235
  };
1084
1236
  }));
1085
1237
  return this._createMultiTransactionPayload(vaultOwner, transactionArtifacts);
1086
1238
  }
1087
1239
  async cancelStream(params) {
1088
- const vaultOwner = params.vaultOwner ? (0, anchor_1.translateAddress)(params.vaultOwner) : this.provider.publicKey;
1240
+ const vaultOwner = params.vaultOwner
1241
+ ? (0, anchor_1.translateAddress)(params.vaultOwner)
1242
+ : this.provider.publicKey;
1089
1243
  if (!vaultOwner) {
1090
1244
  throw new Error("Either provide a caller or use AnchorProvider for provider in the service");
1091
1245
  }
@@ -1109,10 +1263,12 @@ class ZebecVaultService {
1109
1263
  const feePayer = vaultOwner;
1110
1264
  const userAta = (0, solana_common_1.getAssociatedTokenAddressSync)(streamToken, vaultSigner, true);
1111
1265
  const otherPartyAta = (0, solana_common_1.getAssociatedTokenAddressSync)(streamToken, otherParty, true);
1112
- const [streamVault] = (0, pda_1.deriveStreamVaultPda)(streamMetadata, this.streamProgramId);
1266
+ const [streamVault] = (0, zebec_stream_sdk_1.deriveStreamVaultPda)(streamMetadata, this.streamProgramId);
1113
1267
  const streamVaultAta = (0, solana_common_1.getAssociatedTokenAddressSync)(streamToken, streamVault, true);
1114
1268
  const ix = await this.getCancelStreamInstruction(feePayer, otherParty, otherPartyAta, vaultSigner, userAta, streamMetadata, streamToken, streamVault, streamVaultAta);
1115
- const actions = [(0, utils_1.transactionInstructionToPropoalAction)(ix)];
1269
+ const actions = [
1270
+ (0, utils_1.transactionInstructionToPropoalAction)(ix),
1271
+ ];
1116
1272
  const remainingAccounts = actions.reduce((acc, current) => {
1117
1273
  const accounts = current.accountSpecs.map((spec) => ({
1118
1274
  pubkey: spec.pubkey,
@@ -1130,7 +1286,9 @@ class ZebecVaultService {
1130
1286
  return this._createTransactionPayload(feePayer, [ixFinal]);
1131
1287
  }
1132
1288
  async pauseResumeStream(params) {
1133
- const vaultOwner = params.vaultOwner ? (0, anchor_1.translateAddress)(params.vaultOwner) : this.provider.publicKey;
1289
+ const vaultOwner = params.vaultOwner
1290
+ ? (0, anchor_1.translateAddress)(params.vaultOwner)
1291
+ : this.provider.publicKey;
1134
1292
  if (!vaultOwner) {
1135
1293
  throw new Error("Either provide a caller or use AnchorProvider for provider in the service");
1136
1294
  }
@@ -1167,7 +1325,9 @@ class ZebecVaultService {
1167
1325
  return this._createTransactionPayload(vaultOwner, [ixFinal]);
1168
1326
  }
1169
1327
  async changeStreamReceiver(params) {
1170
- const vaultOwner = params.vaultOwner ? (0, anchor_1.translateAddress)(params.vaultOwner) : this.provider.publicKey;
1328
+ const vaultOwner = params.vaultOwner
1329
+ ? (0, anchor_1.translateAddress)(params.vaultOwner)
1330
+ : this.provider.publicKey;
1171
1331
  if (!vaultOwner) {
1172
1332
  throw new Error("Either provide a vaultOwner or use AnchorProvider for provider in the service");
1173
1333
  }
@@ -1176,7 +1336,9 @@ class ZebecVaultService {
1176
1336
  const streamMetadata = (0, anchor_1.translateAddress)(params.streamMetadata);
1177
1337
  const newRecipient = (0, anchor_1.translateAddress)(params.newRecipient);
1178
1338
  const ix = await this.getChangeStreamReceiverInstruction(streamMetadata, newRecipient, vaultSigner);
1179
- const actions = [(0, utils_1.transactionInstructionToPropoalAction)(ix)];
1339
+ const actions = [
1340
+ (0, utils_1.transactionInstructionToPropoalAction)(ix),
1341
+ ];
1180
1342
  const remainingAccounts = actions.reduce((acc, current) => {
1181
1343
  const accounts = current.accountSpecs.map((spec) => ({
1182
1344
  pubkey: spec.pubkey,
@@ -1194,7 +1356,9 @@ class ZebecVaultService {
1194
1356
  return this._createTransactionPayload(vaultOwner, [ixFinal]);
1195
1357
  }
1196
1358
  async withdrawStream(params) {
1197
- const vaultOwner = params.vaultOwner ? (0, anchor_1.translateAddress)(params.vaultOwner) : this.provider.publicKey;
1359
+ const vaultOwner = params.vaultOwner
1360
+ ? (0, anchor_1.translateAddress)(params.vaultOwner)
1361
+ : this.provider.publicKey;
1198
1362
  if (!vaultOwner) {
1199
1363
  throw new Error("Either provide a caller or use AnchorProvider for provider in the service");
1200
1364
  }
@@ -1206,7 +1370,7 @@ class ZebecVaultService {
1206
1370
  const streamMetadataAccount = await this.streamProgram.account.paymentStream.fetch(streamMetadata);
1207
1371
  const streamToken = streamMetadataAccount.financials.streamToken;
1208
1372
  const vaultSignerAta = (0, solana_common_1.getAssociatedTokenAddressSync)(streamToken, vaultSigner, true);
1209
- const [streamVault] = (0, pda_1.deriveStreamVaultPda)(streamMetadata, this.streamProgramId);
1373
+ const [streamVault] = (0, zebec_stream_sdk_1.deriveStreamVaultPda)(streamMetadata, this.streamProgramId);
1210
1374
  const streamVaultAta = (0, solana_common_1.getAssociatedTokenAddressSync)(streamToken, streamVault, true);
1211
1375
  const ix = await this.getWithdrawStreamInstruction(vaultSigner, vaultSignerAta, streamMetadata, streamToken, streamVault, streamVaultAta, withdrawer, feePayer);
1212
1376
  const actions = [(0, utils_1.transactionInstructionToPropoalAction)(ix)];
@@ -1306,31 +1470,34 @@ class ZebecVaultService {
1306
1470
  .instruction();
1307
1471
  }
1308
1472
  async stake(params) {
1309
- const vaultOwner = params.vaultOwner ? (0, anchor_1.translateAddress)(params.vaultOwner) : this.provider.publicKey;
1473
+ const vaultOwner = params.vaultOwner
1474
+ ? (0, anchor_1.translateAddress)(params.vaultOwner)
1475
+ : this.provider.publicKey;
1310
1476
  if (!vaultOwner) {
1311
1477
  throw new Error("MissingArgument: Please provide either vaultOwner address or publicKey in provider");
1312
1478
  }
1313
1479
  const feePayer = vaultOwner;
1314
1480
  const [vault] = (0, pda_1.deriveUserVault)(vaultOwner, this.vaultV1ProgramId);
1315
1481
  const [vaultSigner] = (0, pda_1.deriveVaultSigner)(vault, this.vaultV1ProgramId);
1316
- const lockup = (0, pda_1.deriveLockupAddress)(params.lockupName, this.stakeProgramId);
1482
+ const lockup = (0, zebec_stake_sdk_1.deriveLockupAddress)(params.lockupName, this.stakeProgramId);
1317
1483
  const lockupAccount = await this.stakeProgram.account.lockup.fetchNullable(lockup, this.connection.commitment);
1318
1484
  if (!lockupAccount) {
1319
1485
  throw new Error("Lockup account does not exists for address: " + lockup);
1320
1486
  }
1321
1487
  const lockPeriods = lockupAccount.stakeInfo.durationMap.map((item) => item.duration.toNumber());
1322
1488
  if (!lockPeriods.includes(params.lockPeriod)) {
1323
- throw new Error("Invalid lockperiod. Available options are: " + lockPeriods.map((l) => l.toString()).concat(", "));
1489
+ throw new Error("Invalid lockperiod. Available options are: " +
1490
+ lockPeriods.map((l) => l.toString()).concat(", "));
1324
1491
  }
1325
1492
  const stakeToken = lockupAccount.stakedToken.tokenAddress;
1326
- const stakeVault = (0, pda_1.deriveStakeVaultAddress)(lockup, this.stakeProgramId);
1327
- const userNonce = (0, pda_1.deriveUserNonceAddress)(vaultSigner, lockup, this.stakeProgramId);
1493
+ const stakeVault = (0, zebec_stake_sdk_1.deriveStakeVaultAddress)(lockup, this.stakeProgramId);
1494
+ const userNonce = (0, zebec_stake_sdk_1.deriveUserNonceAddress)(vaultSigner, lockup, this.stakeProgramId);
1328
1495
  const userNonceAccount = await this.stakeProgram.account.userNonce.fetchNullable(userNonce, this.connection.commitment);
1329
1496
  let nonce = BigInt(0);
1330
1497
  if (userNonceAccount) {
1331
1498
  nonce = BigInt(userNonceAccount.nonce.toString());
1332
1499
  }
1333
- const stakePda = (0, pda_1.deriveStakeAddress)(vaultSigner, lockup, nonce, this.stakeProgramId);
1500
+ const stakePda = (0, zebec_stake_sdk_1.deriveStakeAddress)(vaultSigner, lockup, nonce, this.stakeProgramId);
1334
1501
  const stakeVaultTokenAccount = (0, solana_common_1.getAssociatedTokenAddressSync)(stakeToken, stakeVault, true);
1335
1502
  const stakeTokenDecimals = await (0, solana_common_1.getMintDecimals)(this.connection, stakeToken);
1336
1503
  const UNITS_PER_STAKE_TOKEN = solana_common_1.TEN_BIGNUM.pow(stakeTokenDecimals);
@@ -1360,24 +1527,26 @@ class ZebecVaultService {
1360
1527
  return this._createTransactionPayload(vaultOwner, [ixFinal], [], [lookupTableAccount]);
1361
1528
  }
1362
1529
  async unstake(params) {
1363
- const vaultOwner = params.vaultOwner ? (0, anchor_1.translateAddress)(params.vaultOwner) : this.provider.publicKey;
1530
+ const vaultOwner = params.vaultOwner
1531
+ ? (0, anchor_1.translateAddress)(params.vaultOwner)
1532
+ : this.provider.publicKey;
1364
1533
  if (!vaultOwner) {
1365
1534
  throw new Error("MissingArgument: Please provide either staker address or publicKey in provider");
1366
1535
  }
1367
1536
  const [vault] = (0, pda_1.deriveUserVault)(vaultOwner, this.vaultV1ProgramId);
1368
1537
  const [vaultSigner] = (0, pda_1.deriveVaultSigner)(vault, this.vaultV1ProgramId);
1369
1538
  const feePayer = vaultOwner;
1370
- const lockup = (0, pda_1.deriveLockupAddress)(params.lockupName, this.stakeProgramId);
1539
+ const lockup = (0, zebec_stake_sdk_1.deriveLockupAddress)(params.lockupName, this.stakeProgramId);
1371
1540
  const lockupAccount = await this.stakeProgram.account.lockup.fetchNullable(lockup, this.connection.commitment);
1372
1541
  if (!lockupAccount) {
1373
- throw new Error("Lockup account does not exists for address: " + lockup);
1542
+ throw new Error(`Lockup account does not exists for address: ${lockup}`);
1374
1543
  }
1375
1544
  const stakeToken = lockupAccount.stakedToken.tokenAddress;
1376
1545
  const rewardToken = lockupAccount.rewardToken.tokenAddress;
1377
1546
  const feeVault = lockupAccount.feeInfo.feeVault;
1378
- const stakePda = (0, pda_1.deriveStakeAddress)(vaultSigner, lockup, params.nonce, this.stakeProgramId);
1379
- const rewardVault = (0, pda_1.deriveRewardVaultAddress)(lockup, this.stakeProgramId);
1380
- const stakeVault = (0, pda_1.deriveStakeVaultAddress)(lockup, this.stakeProgramId);
1547
+ const stakePda = (0, zebec_stake_sdk_1.deriveStakeAddress)(vaultSigner, lockup, params.nonce, this.stakeProgramId);
1548
+ const rewardVault = (0, zebec_stake_sdk_1.deriveRewardVaultAddress)(lockup, this.stakeProgramId);
1549
+ const stakeVault = (0, zebec_stake_sdk_1.deriveStakeVaultAddress)(lockup, this.stakeProgramId);
1381
1550
  const stakerTokenAccount = (0, solana_common_1.getAssociatedTokenAddressSync)(stakeToken, vaultSigner, true);
1382
1551
  const instruction = await this.getUnstakeInstruction(feePayer, feeVault, lockup, stakePda, rewardToken, rewardVault, stakeToken, stakeVault, vaultSigner, stakerTokenAccount, new anchor_1.BN(params.nonce.toString()));
1383
1552
  const actions = [(0, utils_1.transactionInstructionToPropoalAction)(instruction)];
@@ -1404,8 +1573,8 @@ class ZebecVaultService {
1404
1573
  const vaultOwner = (0, anchor_1.translateAddress)(vaultOwnerAddress);
1405
1574
  const [vault] = (0, pda_1.deriveUserVault)(vaultOwner, this.vaultV1ProgramId);
1406
1575
  const [vaultSigner] = (0, pda_1.deriveVaultSigner)(vault, this.vaultV1ProgramId);
1407
- const lockup = (0, pda_1.deriveLockupAddress)(lockupName, this.stakeProgramId);
1408
- const userNonceAddress = (0, pda_1.deriveUserNonceAddress)(vaultSigner, lockup, this.stakeProgramId);
1576
+ const lockup = (0, zebec_stake_sdk_1.deriveLockupAddress)(lockupName, this.stakeProgramId);
1577
+ const userNonceAddress = (0, zebec_stake_sdk_1.deriveUserNonceAddress)(vaultSigner, lockup, this.stakeProgramId);
1409
1578
  const userNonceAccount = await this.stakeProgram.account.userNonce.fetchNullable(userNonceAddress, commitment ?? this.connection.commitment);
1410
1579
  if (!userNonceAccount) {
1411
1580
  return null;
@@ -1417,8 +1586,8 @@ class ZebecVaultService {
1417
1586
  }
1418
1587
  async _createTransactionPayload(payerKey, instructions, signers, addressLookupTableAccounts) {
1419
1588
  const errorMap = new Map();
1420
- this.vaultV1Program.idl.errors.forEach((error) => errorMap.set(error.code, error.msg));
1421
- let signTransaction = undefined;
1589
+ this.vaultV1Program.idl.errors.map((error) => errorMap.set(error.code, error.msg));
1590
+ let signTransaction;
1422
1591
  const provider = this.provider;
1423
1592
  if (provider instanceof anchor_1.AnchorProvider) {
1424
1593
  signTransaction = async (tx) => {
@@ -1429,8 +1598,8 @@ class ZebecVaultService {
1429
1598
  }
1430
1599
  async _createMultiTransactionPayload(payerKey, transactionArtifacts) {
1431
1600
  const errorMap = new Map();
1432
- this.vaultV1Program.idl.errors.forEach((error) => errorMap.set(error.code, error.msg));
1433
- let signAllTransactions = undefined;
1601
+ this.vaultV1Program.idl.errors.map((error) => errorMap.set(error.code, error.msg));
1602
+ let signAllTransactions;
1434
1603
  const provider = this.provider;
1435
1604
  if (provider instanceof anchor_1.AnchorProvider) {
1436
1605
  signAllTransactions = async (txns) => {
@@ -1441,6 +1610,7 @@ class ZebecVaultService {
1441
1610
  instructions: data.instructions,
1442
1611
  feePayer: payerKey,
1443
1612
  signers: data.signers,
1613
+ addressLookupTableAccounts: data.addressLookupTableAccounts,
1444
1614
  }));
1445
1615
  return new solana_common_1.MultiTransactionPayload(this.connection, errorMap, transactionData, signAllTransactions);
1446
1616
  }