@zebec-network/zebec-vault-sdk 5.2.0-dev.1 → 5.2.1

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/errors.js CHANGED
@@ -7,7 +7,7 @@ class AmountOutOfRangeError extends Error {
7
7
  value;
8
8
  name = "AmountOutOfRangeError";
9
9
  constructor(minRange, maxRange, value) {
10
- super("Amount out of range: " + value + "; Must be within " + minRange + "-" + maxRange);
10
+ super(`Amount out of range: ${value}; Must be within ${minRange}-${maxRange}`);
11
11
  this.minRange = minRange;
12
12
  this.maxRange = maxRange;
13
13
  this.value = value;
@@ -19,7 +19,7 @@ class DailyCardLimitReachedError extends Error {
19
19
  requestedAmount;
20
20
  name = "DailyCardLimitReachedError";
21
21
  constructor(dailyCardLimit, requestedAmount) {
22
- super("Daily card limit reached. Limit: " + dailyCardLimit + " Requested: " + requestedAmount);
22
+ super(`Daily card limit reached. Limit: ${dailyCardLimit} Requested: ${requestedAmount}`);
23
23
  this.dailyCardLimit = dailyCardLimit;
24
24
  this.requestedAmount = requestedAmount;
25
25
  }
@@ -29,29 +29,20 @@ class InvalidUsdcAddressError extends Error {
29
29
  mintAddress;
30
30
  name = "InvalidUsdcAddressError";
31
31
  constructor(mintAddress) {
32
- super("Invalid USDC address: " + mintAddress);
32
+ super(`Invalid USDC address: ${mintAddress}`);
33
33
  this.mintAddress = mintAddress;
34
34
  }
35
35
  }
36
36
  exports.InvalidUsdcAddressError = InvalidUsdcAddressError;
37
37
  class NotEnoughBalanceError extends Error {
38
38
  name = "NotEnoughBalanceError";
39
- constructor(message) {
40
- super(message);
41
- }
42
39
  }
43
40
  exports.NotEnoughBalanceError = NotEnoughBalanceError;
44
41
  class QuoteResponseError extends Error {
45
42
  name = "QuoteResponseError";
46
- constructor(message) {
47
- super(message);
48
- }
49
43
  }
50
44
  exports.QuoteResponseError = QuoteResponseError;
51
45
  class AssociatedTokenAccountDoesNotExistsError extends Error {
52
46
  name = "AssociatedTokenAccountDoesNotExistsError";
53
- constructor(message) {
54
- super(message);
55
- }
56
47
  }
57
48
  exports.AssociatedTokenAccountDoesNotExistsError = AssociatedTokenAccountDoesNotExistsError;
package/dist/pda.js CHANGED
@@ -5,14 +5,25 @@ exports.deriveUserVault = deriveUserVault;
5
5
  const anchor_1 = require("@coral-xyz/anchor");
6
6
  const web3_js_1 = require("@solana/web3.js");
7
7
  const VAULT_PROGRAM_V1_SEEDS = {
8
- USER_VAULT: [122, 101, 98, 101, 99, 95, 117, 115, 101, 114, 95, 118, 97, 117, 108, 116],
9
- VAULT_SIGNER: [122, 101, 98, 101, 99, 95, 118, 97, 117, 108, 116, 95, 115, 105, 103, 110, 101, 114],
8
+ USER_VAULT: [
9
+ 122, 101, 98, 101, 99, 95, 117, 115, 101, 114, 95, 118, 97, 117, 108, 116,
10
+ ],
11
+ VAULT_SIGNER: [
12
+ 122, 101, 98, 101, 99, 95, 118, 97, 117, 108, 116, 95, 115, 105, 103, 110,
13
+ 101, 114,
14
+ ],
10
15
  };
11
16
  function deriveVaultSigner(vault, programId) {
12
- const addressAndBump = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(VAULT_PROGRAM_V1_SEEDS.VAULT_SIGNER), (0, anchor_1.translateAddress)(vault).toBuffer()], (0, anchor_1.translateAddress)(programId));
17
+ const addressAndBump = web3_js_1.PublicKey.findProgramAddressSync([
18
+ Buffer.from(VAULT_PROGRAM_V1_SEEDS.VAULT_SIGNER),
19
+ (0, anchor_1.translateAddress)(vault).toBuffer(),
20
+ ], (0, anchor_1.translateAddress)(programId));
13
21
  return addressAndBump;
14
22
  }
15
23
  function deriveUserVault(user, programId) {
16
- const addressAndBump = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(VAULT_PROGRAM_V1_SEEDS.USER_VAULT), (0, anchor_1.translateAddress)(user).toBuffer()], (0, anchor_1.translateAddress)(programId));
24
+ const addressAndBump = web3_js_1.PublicKey.findProgramAddressSync([
25
+ Buffer.from(VAULT_PROGRAM_V1_SEEDS.USER_VAULT),
26
+ (0, anchor_1.translateAddress)(user).toBuffer(),
27
+ ], (0, anchor_1.translateAddress)(programId));
17
28
  return addressAndBump;
18
29
  }
@@ -1,5 +1,5 @@
1
- import { Address, AnchorProvider } from "@coral-xyz/anchor";
2
- import { ConfirmOptions, Connection, PublicKey, Transaction, VersionedTransaction } from "@solana/web3.js";
1
+ import { type Address, AnchorProvider } from "@coral-xyz/anchor";
2
+ import type { ConfirmOptions, Connection, PublicKey, Transaction, VersionedTransaction } from "@solana/web3.js";
3
3
  export declare class ReadonlyProvider {
4
4
  readonly connection: Connection;
5
5
  readonly walletAddress?: PublicKey;
package/dist/providers.js CHANGED
@@ -9,7 +9,9 @@ class ReadonlyProvider {
9
9
  walletAddress;
10
10
  constructor(connection, walletAddress) {
11
11
  this.connection = connection;
12
- this.walletAddress = walletAddress ? (0, anchor_1.translateAddress)(walletAddress) : undefined;
12
+ this.walletAddress = walletAddress
13
+ ? (0, anchor_1.translateAddress)(walletAddress)
14
+ : undefined;
13
15
  }
14
16
  }
15
17
  exports.ReadonlyProvider = ReadonlyProvider;
package/dist/service.d.ts CHANGED
@@ -5,7 +5,7 @@ import { type ZebecCardV2Idl } from "@zebec-network/zebec-card-v2-sdk";
5
5
  import { type ZebecStakeIdlV1 } from "@zebec-network/zebec-stake-sdk";
6
6
  import { type ZebecStreamIdl } from "@zebec-network/zebec-stream-sdk";
7
7
  import { type ZebecVaultV1Idl } from "./artifacts";
8
- import { type RpcNetwork } from "./constants";
8
+ import type { RpcNetwork } from "./constants";
9
9
  import type { CancelStreamParams, ChangeStreamReceiverParams, CreateSilverCardInstructionData, CreateSilverCardParams, CreateStreamFromVaultParams, createMultipleStreamFromVaultParams, LoadCarbonCardInstructionData, LoadCarbonCardParams, Numeric, PauseResumeStreamParams, ProposalAction, ProposalInfo, StakeInstructionData, StakeUserNonceInfo, StreamMetadataInfo, SwapAndCreateSilverCardParams, SwapAndLoadCarbonCardParams, TokenFeeRecord, VaultInfo, WithdrawStreamParams } from "./types";
10
10
  export declare class ZebecVaultService {
11
11
  readonly provider: Provider;
package/dist/service.js CHANGED
@@ -15,7 +15,6 @@ const zebec_stream_sdk_1 = require("@zebec-network/zebec-stream-sdk");
15
15
  const assert_1 = __importDefault(require("assert"));
16
16
  const bignumber_js_1 = require("bignumber.js");
17
17
  const artifacts_1 = require("./artifacts");
18
- const constants_1 = require("./constants");
19
18
  const errors_1 = require("./errors");
20
19
  const pda_1 = require("./pda");
21
20
  const utils_1 = require("./utils");
@@ -151,7 +150,9 @@ class ZebecVaultService {
151
150
  .instruction();
152
151
  }
153
152
  async createVault(params) {
154
- const payer = params.payer ? (0, anchor_1.translateAddress)(params.payer) : this.provider.publicKey;
153
+ const payer = params.payer
154
+ ? (0, anchor_1.translateAddress)(params.payer)
155
+ : this.provider.publicKey;
155
156
  if (!payer) {
156
157
  throw new Error("Either provide a payer or use AnchorProvider for provider in the service");
157
158
  }
@@ -161,7 +162,9 @@ class ZebecVaultService {
161
162
  return this._createTransactionPayload(payer, [ix]);
162
163
  }
163
164
  async depositSol(params) {
164
- const depositor = params.depositor ? (0, anchor_1.translateAddress)(params.depositor) : this.provider.publicKey;
165
+ const depositor = params.depositor
166
+ ? (0, anchor_1.translateAddress)(params.depositor)
167
+ : this.provider.publicKey;
165
168
  if (!depositor) {
166
169
  throw new Error("Either provide a depositor or use AnchorProvider for provider in the service");
167
170
  }
@@ -170,7 +173,9 @@ class ZebecVaultService {
170
173
  return this._createTransactionPayload(depositor, [ix]);
171
174
  }
172
175
  async withdrawSol(params) {
173
- const withdrawer = params.withdrawer ? (0, anchor_1.translateAddress)(params.withdrawer) : this.provider.publicKey;
176
+ const withdrawer = params.withdrawer
177
+ ? (0, anchor_1.translateAddress)(params.withdrawer)
178
+ : this.provider.publicKey;
174
179
  if (!withdrawer) {
175
180
  throw new Error("Either provide a withdrawer or use AnchorProvider for provider in the service");
176
181
  }
@@ -179,7 +184,9 @@ class ZebecVaultService {
179
184
  return this._createTransactionPayload(withdrawer, [ix]);
180
185
  }
181
186
  async deposit(params) {
182
- const depositor = params.depositor ? (0, anchor_1.translateAddress)(params.depositor) : this.provider.publicKey;
187
+ const depositor = params.depositor
188
+ ? (0, anchor_1.translateAddress)(params.depositor)
189
+ : this.provider.publicKey;
183
190
  if (!depositor) {
184
191
  throw new Error("Either provide a depositor or use AnchorProvider for provider in the service");
185
192
  }
@@ -238,7 +245,9 @@ class ZebecVaultService {
238
245
  return closeWsolAccountIx;
239
246
  }
240
247
  async withdraw(params) {
241
- const withdrawer = params.withdrawer ? (0, anchor_1.translateAddress)(params.withdrawer) : this.provider.publicKey;
248
+ const withdrawer = params.withdrawer
249
+ ? (0, anchor_1.translateAddress)(params.withdrawer)
250
+ : this.provider.publicKey;
242
251
  if (!withdrawer) {
243
252
  throw new Error("Either provide a withdrawer or use AnchorProvider for provider in the service");
244
253
  }
@@ -264,7 +273,9 @@ class ZebecVaultService {
264
273
  return this._createTransactionPayload(withdrawer, instructions);
265
274
  }
266
275
  async createProposal(params) {
267
- const proposer = params.proposer ? (0, anchor_1.translateAddress)(params.proposer) : this.provider.publicKey;
276
+ const proposer = params.proposer
277
+ ? (0, anchor_1.translateAddress)(params.proposer)
278
+ : this.provider.publicKey;
268
279
  if (!proposer) {
269
280
  throw new Error("Either provide a proposer or use AnchorProvider for provider in the service");
270
281
  }
@@ -278,7 +289,9 @@ class ZebecVaultService {
278
289
  return this._createTransactionPayload(proposer, [ix], [proposalKeypair]);
279
290
  }
280
291
  async appendActions(params) {
281
- const proposer = params.proposer ? (0, anchor_1.translateAddress)(params.proposer) : this.provider.publicKey;
292
+ const proposer = params.proposer
293
+ ? (0, anchor_1.translateAddress)(params.proposer)
294
+ : this.provider.publicKey;
282
295
  if (!proposer) {
283
296
  throw new Error("Either provide a proposer or use AnchorProvider for provider in the service");
284
297
  }
@@ -298,7 +311,9 @@ class ZebecVaultService {
298
311
  return this._createTransactionPayload(proposer, [ix]);
299
312
  }
300
313
  async deleteProposal(params) {
301
- const caller = params.caller ? (0, anchor_1.translateAddress)(params.caller) : this.provider.publicKey;
314
+ const caller = params.caller
315
+ ? (0, anchor_1.translateAddress)(params.caller)
316
+ : this.provider.publicKey;
302
317
  if (!caller) {
303
318
  throw new Error("Either provide a caller or use AnchorProvider for provider in the service");
304
319
  }
@@ -307,7 +322,9 @@ class ZebecVaultService {
307
322
  return this._createTransactionPayload(caller, [ix]);
308
323
  }
309
324
  async executeProposal(params) {
310
- const caller = params.caller ? (0, anchor_1.translateAddress)(params.caller) : this.provider.publicKey;
325
+ const caller = params.caller
326
+ ? (0, anchor_1.translateAddress)(params.caller)
327
+ : this.provider.publicKey;
311
328
  if (!caller) {
312
329
  throw new Error("Either provide a caller or use AnchorProvider for provider in the service");
313
330
  }
@@ -347,7 +364,9 @@ class ZebecVaultService {
347
364
  return this._createTransactionPayload(caller, [ix], params.partialSigners, addressLookupTableAccounts);
348
365
  }
349
366
  async executeProposalDirect(params) {
350
- const proposer = params.proposer ? (0, anchor_1.translateAddress)(params.proposer) : this.provider.publicKey;
367
+ const proposer = params.proposer
368
+ ? (0, anchor_1.translateAddress)(params.proposer)
369
+ : this.provider.publicKey;
351
370
  if (!proposer) {
352
371
  throw new Error("Either provide a caller or use AnchorProvider for provider in the service");
353
372
  }
@@ -586,7 +605,9 @@ class ZebecVaultService {
586
605
  return BigInt(decoded.index.addn(1).toString());
587
606
  }
588
607
  async createSilverCard(params) {
589
- const vaultOwner = params.vaultOwnerAddress ? (0, anchor_1.translateAddress)(params.vaultOwnerAddress) : this.provider.publicKey;
608
+ const vaultOwner = params.vaultOwnerAddress
609
+ ? (0, anchor_1.translateAddress)(params.vaultOwnerAddress)
610
+ : this.provider.publicKey;
590
611
  if (!vaultOwner) {
591
612
  throw new Error("Either provide a caller or use AnchorProvider for provider in the service");
592
613
  }
@@ -602,7 +623,9 @@ class ZebecVaultService {
602
623
  const revenueVault = cardConfigInfo.revenueVault;
603
624
  const cardVaultAta = (0, solana_common_1.getAssociatedTokenAddressSync)(usdcMint, cardVault, true);
604
625
  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);
626
+ const parsedAmount = amount
627
+ .times(solana_common_1.UNITS_PER_USDC)
628
+ .decimalPlaces(0, bignumber_js_1.BigNumber.ROUND_DOWN);
606
629
  await this._checkAmountIsWithinProviderRange(cardConfigInfo, parsedAmount);
607
630
  await this._checkAmountIsWithinDailyCardLimit(cardConfigInfo, userPurchaseRecord, parsedAmount);
608
631
  const index = new anchor_1.BN(params.nextCardIndex.toString());
@@ -612,7 +635,9 @@ class ZebecVaultService {
612
635
  currency: params.currency,
613
636
  emailHash: Array.from(params.emailHash),
614
637
  });
615
- const actions = [(0, utils_1.transactionInstructionToPropoalAction)(ix)];
638
+ const actions = [
639
+ (0, utils_1.transactionInstructionToPropoalAction)(ix),
640
+ ];
616
641
  const remainingAccounts = actions.reduce((acc, current) => {
617
642
  const accounts = current.accountSpecs.map((spec) => ({
618
643
  pubkey: spec.pubkey,
@@ -626,14 +651,16 @@ class ZebecVaultService {
626
651
  });
627
652
  return acc;
628
653
  }, []);
629
- const lookupTables = await this.connection.getAddressLookupTable((0, anchor_1.translateAddress)(constants_1.CARD_LOOKUP_TABLE_ADDRESS[this.network]));
654
+ const lookupTables = await this.connection.getAddressLookupTable((0, anchor_1.translateAddress)(zebec_card_v2_sdk_1.CARD_LOOKUP_TABLE_ADDRESS[this.network]));
630
655
  const lookupTableAccount = lookupTables.value;
631
656
  (0, assert_1.default)(lookupTableAccount, "Lookup table account not found");
632
657
  const executeProposalDirectIx = await this.getExecuteProposalDirectInstruction(vaultOwner, actions, remainingAccounts);
633
658
  return this._createTransactionPayload(vaultOwner, [executeProposalDirectIx], [], [lookupTableAccount]);
634
659
  }
635
660
  async loadCarbonCard(params) {
636
- const vaultOwner = params.vaultOwnerAddress ? (0, anchor_1.translateAddress)(params.vaultOwnerAddress) : this.provider.publicKey;
661
+ const vaultOwner = params.vaultOwnerAddress
662
+ ? (0, anchor_1.translateAddress)(params.vaultOwnerAddress)
663
+ : this.provider.publicKey;
637
664
  if (!vaultOwner) {
638
665
  throw new Error("Either provide a caller or use AnchorProvider for provider in the service");
639
666
  }
@@ -649,7 +676,9 @@ class ZebecVaultService {
649
676
  const revenueVault = cardConfigInfo.revenueVault;
650
677
  const cardVaultAta = (0, solana_common_1.getAssociatedTokenAddressSync)(usdcMint, cardVault, true);
651
678
  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);
679
+ const parsedAmount = amount
680
+ .times(solana_common_1.UNITS_PER_USDC)
681
+ .decimalPlaces(0, bignumber_js_1.BigNumber.ROUND_DOWN);
653
682
  await this._checkAmountIsWithinProviderRange(cardConfigInfo, parsedAmount);
654
683
  await this._checkAmountIsWithinDailyCardLimit(cardConfigInfo, userPurchaseRecord, parsedAmount);
655
684
  const index = new anchor_1.BN(params.nextCardIndex.toString());
@@ -660,7 +689,9 @@ class ZebecVaultService {
660
689
  emailHash: Array.from(params.emailHash),
661
690
  reloadCardId: params.reloadCardId,
662
691
  });
663
- const actions = [(0, utils_1.transactionInstructionToPropoalAction)(ix)];
692
+ const actions = [
693
+ (0, utils_1.transactionInstructionToPropoalAction)(ix),
694
+ ];
664
695
  const remainingAccounts = actions.reduce((acc, current) => {
665
696
  const accounts = current.accountSpecs.map((spec) => ({
666
697
  pubkey: spec.pubkey,
@@ -674,7 +705,7 @@ class ZebecVaultService {
674
705
  });
675
706
  return acc;
676
707
  }, []);
677
- const lookupTables = await this.connection.getAddressLookupTable((0, anchor_1.translateAddress)(constants_1.CARD_LOOKUP_TABLE_ADDRESS[this.network]));
708
+ const lookupTables = await this.connection.getAddressLookupTable((0, anchor_1.translateAddress)(zebec_card_v2_sdk_1.CARD_LOOKUP_TABLE_ADDRESS[this.network]));
678
709
  const lookupTableAccount = lookupTables.value;
679
710
  (0, assert_1.default)(lookupTableAccount, "Lookup table account not found");
680
711
  const executeProposalDirectIx = await this.getExecuteProposalDirectInstruction(vaultOwner, actions, remainingAccounts);
@@ -727,11 +758,13 @@ class ZebecVaultService {
727
758
  const customTokenFees = await this.getCardCustomTokenFees();
728
759
  const customTokenFee = customTokenFees.find((tf) => tf.tokenAddress === quoteInfo.inputMint);
729
760
  const DEFAULT_SWAP_FEE = 5;
730
- const swapFee = customTokenFee ? (0, bignumber_js_1.BigNumber)(customTokenFee.fee) : (0, bignumber_js_1.BigNumber)(DEFAULT_SWAP_FEE);
761
+ const swapFee = customTokenFee
762
+ ? (0, bignumber_js_1.BigNumber)(customTokenFee.fee)
763
+ : (0, bignumber_js_1.BigNumber)(DEFAULT_SWAP_FEE);
731
764
  const amountAfterFeeDeduction = amount.minus(amount.times(swapFee.div(100)));
732
765
  await this._checkAmountIsWithinProviderRange(cardConfigInfo, amountAfterFeeDeduction);
733
766
  await this._checkAmountIsWithinDailyCardLimit(cardConfigInfo, userPurchaseRecord, amountAfterFeeDeduction);
734
- const { swapTransaction } = await (await fetch(constants_1.JUPITER_SWAP_API, {
767
+ const { swapTransaction } = await (await fetch(zebec_card_v2_sdk_1.JUPITER_SWAP_API, {
735
768
  method: "POST",
736
769
  headers: {
737
770
  "Content-Type": "application/json",
@@ -752,9 +785,11 @@ class ZebecVaultService {
752
785
  const transaction = web3_js_1.VersionedTransaction.deserialize(swapTransactionBuf);
753
786
  // get address lookup table accounts
754
787
  const addressLookupTableAccounts = await Promise.all(transaction.message.addressTableLookups.map(async (lookup) => {
755
- const data = await this.connection.getAccountInfo(lookup.accountKey).then((res) => {
788
+ const data = await this.connection
789
+ .getAccountInfo(lookup.accountKey)
790
+ .then((res) => {
756
791
  if (!res) {
757
- throw new Error(`Lookup table account not found for key: ${(0, anchor_1.translateAddress)(constants_1.CARD_LOOKUP_TABLE_ADDRESS[this.network]).toString()}`);
792
+ throw new Error(`Lookup table account not found for key: ${(0, anchor_1.translateAddress)(zebec_card_v2_sdk_1.CARD_LOOKUP_TABLE_ADDRESS[this.network]).toString()}`);
758
793
  }
759
794
  return res.data;
760
795
  });
@@ -764,15 +799,15 @@ class ZebecVaultService {
764
799
  });
765
800
  }));
766
801
  const lookupTableData = await this.connection
767
- .getAccountInfo((0, anchor_1.translateAddress)(constants_1.CARD_LOOKUP_TABLE_ADDRESS[this.network]))
802
+ .getAccountInfo((0, anchor_1.translateAddress)(zebec_card_v2_sdk_1.CARD_LOOKUP_TABLE_ADDRESS[this.network]))
768
803
  .then((res) => {
769
804
  if (!res) {
770
- throw new Error(`Lookup table account not found for key: ${(0, anchor_1.translateAddress)(constants_1.CARD_LOOKUP_TABLE_ADDRESS[this.network]).toString()}`);
805
+ throw new Error(`Lookup table account not found for key: ${(0, anchor_1.translateAddress)(zebec_card_v2_sdk_1.CARD_LOOKUP_TABLE_ADDRESS[this.network]).toString()}`);
771
806
  }
772
807
  return res.data;
773
808
  });
774
809
  addressLookupTableAccounts.push(new web3_js_1.AddressLookupTableAccount({
775
- key: (0, anchor_1.translateAddress)(constants_1.CARD_LOOKUP_TABLE_ADDRESS[this.network]),
810
+ key: (0, anchor_1.translateAddress)(zebec_card_v2_sdk_1.CARD_LOOKUP_TABLE_ADDRESS[this.network]),
776
811
  state: web3_js_1.AddressLookupTableAccount.deserialize(lookupTableData),
777
812
  }));
778
813
  // console.log("address lookup table:\n", addressLookupTableAccounts);
@@ -780,9 +815,9 @@ class ZebecVaultService {
780
815
  const message = web3_js_1.TransactionMessage.decompile(transaction.message, {
781
816
  addressLookupTableAccounts: addressLookupTableAccounts,
782
817
  });
783
- const swapInstruction = message.instructions.find((ix) => ix.programId.equals((0, anchor_1.translateAddress)(constants_1.JUPITER_AGGREGATOR_PROGRAM_ID)));
818
+ const swapInstruction = message.instructions.find((ix) => ix.programId.equals((0, anchor_1.translateAddress)(zebec_card_v2_sdk_1.JUPITER_AGGREGATOR_PROGRAM_ID)));
784
819
  (0, assert_1.default)(swapInstruction, "Swap instruction not found in the transaction message");
785
- const otherIxs = message.instructions.filter((ix) => !ix.programId.equals((0, anchor_1.translateAddress)(constants_1.JUPITER_AGGREGATOR_PROGRAM_ID)) &&
820
+ const otherIxs = message.instructions.filter((ix) => !ix.programId.equals((0, anchor_1.translateAddress)(zebec_card_v2_sdk_1.JUPITER_AGGREGATOR_PROGRAM_ID)) &&
786
821
  !ix.programId.equals(web3_js_1.ComputeBudgetProgram.programId));
787
822
  const index = new anchor_1.BN(params.nextCardCounter.toString());
788
823
  const swapAndCreateSilverCardIx = await this.getSwapAndCreateSilverCardInstruction(vaultOwner, cardVault, cardVaultAta, revenueVault, revenueVaultAta, inputMint, usdc, vaultSigner, {
@@ -795,7 +830,7 @@ class ZebecVaultService {
795
830
  return this._createTransactionPayload(vaultOwner, otherIxs, [], addressLookupTableAccounts);
796
831
  }
797
832
  async swapAndLoadCarbonCard(params) {
798
- const { vaultOwnerAddress, quoteInfo, emailHash, reloadCardId, wrapAndUnwrapSol } = params;
833
+ const { vaultOwnerAddress, quoteInfo, emailHash, reloadCardId, wrapAndUnwrapSol, } = params;
799
834
  if ("error" in quoteInfo) {
800
835
  throw new Error(quoteInfo.error);
801
836
  }
@@ -824,7 +859,8 @@ class ZebecVaultService {
824
859
  if (!inputMint.equals(solana_common_1.WSOL) || !isSolWrapUnwrapNeeded) {
825
860
  const userInputMintAtaInfo = await this.connection.getAccountInfo(userInputMintAta, this.connection.commitment);
826
861
  if (!userInputMintAtaInfo) {
827
- throw new errors_1.AssociatedTokenAccountDoesNotExistsError("User doesn't have associated token account of input mint: " + inputMint.toString());
862
+ throw new errors_1.AssociatedTokenAccountDoesNotExistsError("User doesn't have associated token account of input mint: " +
863
+ inputMint.toString());
828
864
  }
829
865
  const resAndCtx = await this.connection.getTokenAccountBalance(userInputMintAta, this.connection.commitment);
830
866
  const balance = resAndCtx.value.amount;
@@ -841,11 +877,13 @@ class ZebecVaultService {
841
877
  const customTokenFees = await this.getCardCustomTokenFees();
842
878
  const customTokenFee = customTokenFees.find((tf) => tf.tokenAddress === quoteInfo.inputMint);
843
879
  const DEFAULT_SWAP_FEE = 5;
844
- const swapFee = customTokenFee ? (0, bignumber_js_1.BigNumber)(customTokenFee.fee) : (0, bignumber_js_1.BigNumber)(DEFAULT_SWAP_FEE);
880
+ const swapFee = customTokenFee
881
+ ? (0, bignumber_js_1.BigNumber)(customTokenFee.fee)
882
+ : (0, bignumber_js_1.BigNumber)(DEFAULT_SWAP_FEE);
845
883
  const amountAfterFeeDeduction = amount.minus(amount.times(swapFee.div(100)));
846
884
  await this._checkAmountIsWithinProviderRange(cardConfigInfo, amountAfterFeeDeduction);
847
885
  await this._checkAmountIsWithinDailyCardLimit(cardConfigInfo, userPurchaseRecord, amountAfterFeeDeduction);
848
- const { swapTransaction } = await (await fetch(constants_1.JUPITER_SWAP_API, {
886
+ const { swapTransaction } = await (await fetch(zebec_card_v2_sdk_1.JUPITER_SWAP_API, {
849
887
  method: "POST",
850
888
  headers: {
851
889
  "Content-Type": "application/json",
@@ -866,7 +904,9 @@ class ZebecVaultService {
866
904
  const transaction = web3_js_1.VersionedTransaction.deserialize(swapTransactionBuf);
867
905
  // get address lookup table accounts
868
906
  const addressLookupTableAccounts = await Promise.all(transaction.message.addressTableLookups.map(async (lookup) => {
869
- const data = await this.connection.getAccountInfo(lookup.accountKey).then((res) => {
907
+ const data = await this.connection
908
+ .getAccountInfo(lookup.accountKey)
909
+ .then((res) => {
870
910
  if (!res) {
871
911
  throw new Error(`Lookup table account not found for key: ${lookup.accountKey.toString()}`);
872
912
  }
@@ -878,15 +918,15 @@ class ZebecVaultService {
878
918
  });
879
919
  }));
880
920
  const lookupTableData = await this.connection
881
- .getAccountInfo((0, anchor_1.translateAddress)(constants_1.CARD_LOOKUP_TABLE_ADDRESS[this.network]))
921
+ .getAccountInfo((0, anchor_1.translateAddress)(zebec_card_v2_sdk_1.CARD_LOOKUP_TABLE_ADDRESS[this.network]))
882
922
  .then((res) => {
883
923
  if (!res) {
884
- throw new Error(`Lookup table account not found for key: ${(0, anchor_1.translateAddress)(constants_1.CARD_LOOKUP_TABLE_ADDRESS[this.network]).toString()}`);
924
+ throw new Error(`Lookup table account not found for key: ${(0, anchor_1.translateAddress)(zebec_card_v2_sdk_1.CARD_LOOKUP_TABLE_ADDRESS[this.network]).toString()}`);
885
925
  }
886
926
  return res.data;
887
927
  });
888
928
  addressLookupTableAccounts.push(new web3_js_1.AddressLookupTableAccount({
889
- key: (0, anchor_1.translateAddress)(constants_1.CARD_LOOKUP_TABLE_ADDRESS[this.network]),
929
+ key: (0, anchor_1.translateAddress)(zebec_card_v2_sdk_1.CARD_LOOKUP_TABLE_ADDRESS[this.network]),
890
930
  state: web3_js_1.AddressLookupTableAccount.deserialize(lookupTableData),
891
931
  }));
892
932
  // console.log("address lookup table:\n", addressLookupTableAccounts);
@@ -894,9 +934,9 @@ class ZebecVaultService {
894
934
  const message = web3_js_1.TransactionMessage.decompile(transaction.message, {
895
935
  addressLookupTableAccounts: addressLookupTableAccounts,
896
936
  });
897
- const swapInstruction = message.instructions.find((ix) => ix.programId.equals((0, anchor_1.translateAddress)(constants_1.JUPITER_AGGREGATOR_PROGRAM_ID)));
937
+ const swapInstruction = message.instructions.find((ix) => ix.programId.equals((0, anchor_1.translateAddress)(zebec_card_v2_sdk_1.JUPITER_AGGREGATOR_PROGRAM_ID)));
898
938
  (0, assert_1.default)(swapInstruction, "Swap instruction not found in the transaction message");
899
- const otherIxs = message.instructions.filter((ix) => !ix.programId.equals((0, anchor_1.translateAddress)(constants_1.JUPITER_AGGREGATOR_PROGRAM_ID)) &&
939
+ const otherIxs = message.instructions.filter((ix) => !ix.programId.equals((0, anchor_1.translateAddress)(zebec_card_v2_sdk_1.JUPITER_AGGREGATOR_PROGRAM_ID)) &&
900
940
  !ix.programId.equals(web3_js_1.ComputeBudgetProgram.programId));
901
941
  const index = new anchor_1.BN(params.nextCardCounter.toString());
902
942
  const swapAndLoadCarbonCardIx = await this.getSwapAndLoadCarbonCardInstruction(cardVault, cardVaultAta, inputMint, solana_common_1.TOKEN_PROGRAM_ID, usdc, revenueVault, revenueVaultAta, vaultOwner, {
@@ -1050,7 +1090,9 @@ class ZebecVaultService {
1050
1090
  const [streamVault] = (0, zebec_stream_sdk_1.deriveStreamVaultPda)(streamMetadata, this.streamProgramId);
1051
1091
  const streamVaultAta = (0, solana_common_1.getAssociatedTokenAddressSync)(streamToken, streamVault, true);
1052
1092
  const streamTokenDecimals = await (0, solana_common_1.getMintDecimals)(this.connection, streamToken);
1053
- const amount = (0, bignumber_js_1.BigNumber)(params.amount).times(solana_common_1.TEN_BIGNUM.pow(streamTokenDecimals)).toFixed(0);
1093
+ const amount = (0, bignumber_js_1.BigNumber)(params.amount)
1094
+ .times(solana_common_1.TEN_BIGNUM.pow(streamTokenDecimals))
1095
+ .toFixed(0);
1054
1096
  const feeInfo = await (0, zebec_stream_sdk_1.getFeeInfoForStream)(streamToken, amount, streamTokenDecimals, this.network);
1055
1097
  const feeToken = (0, anchor_1.translateAddress)(feeInfo.feeToken.mintAddress);
1056
1098
  const feeTokenDecimals = await (0, solana_common_1.getMintDecimals)(this.connection, feeToken);
@@ -1082,7 +1124,9 @@ class ZebecVaultService {
1082
1124
  cliffPercentage,
1083
1125
  duration: new anchor_1.BN(params.duration),
1084
1126
  isPausable: params.isPausable,
1085
- numberOfWithdrawls: autoWithdrawFrequency > 0 ? new anchor_1.BN(Math.floor(params.duration / autoWithdrawFrequency)) : new anchor_1.BN(0),
1127
+ numberOfWithdrawls: autoWithdrawFrequency > 0
1128
+ ? new anchor_1.BN(Math.floor(params.duration / autoWithdrawFrequency))
1129
+ : new anchor_1.BN(0),
1086
1130
  rateUpdatable: params.rateUpdatable,
1087
1131
  startNow: params.startNow,
1088
1132
  startTime: new anchor_1.BN(params.startTime),
@@ -1091,9 +1135,11 @@ class ZebecVaultService {
1091
1135
  transferableBySender: params.transferableBySender,
1092
1136
  });
1093
1137
  const lookupTable = zebec_stream_sdk_1.STREAM_PROGRAM_LOOKUP_TABLE_ADDRESS[this.network];
1094
- const lookupTableData = await this.connection.getAccountInfo((0, anchor_1.translateAddress)(lookupTable)).then((res) => {
1138
+ const lookupTableData = await this.connection
1139
+ .getAccountInfo((0, anchor_1.translateAddress)(lookupTable))
1140
+ .then((res) => {
1095
1141
  if (!res) {
1096
- throw new Error(`Lookup table account not found for key: ${(0, anchor_1.translateAddress)(constants_1.CARD_LOOKUP_TABLE_ADDRESS[this.network]).toString()}`);
1142
+ throw new Error(`Lookup table account not found for key: ${(0, anchor_1.translateAddress)(zebec_card_v2_sdk_1.CARD_LOOKUP_TABLE_ADDRESS[this.network]).toString()}`);
1097
1143
  }
1098
1144
  return res.data;
1099
1145
  });
@@ -1109,9 +1155,11 @@ class ZebecVaultService {
1109
1155
  const [vault] = (0, pda_1.deriveUserVault)(vaultOwner, this.vaultV1ProgramId);
1110
1156
  const [vaultSigner] = (0, pda_1.deriveVaultSigner)(vault, this.vaultV1ProgramId);
1111
1157
  const lookupTable = zebec_stream_sdk_1.STREAM_PROGRAM_LOOKUP_TABLE_ADDRESS[this.network];
1112
- const lookupTableData = await this.connection.getAccountInfo((0, anchor_1.translateAddress)(lookupTable)).then((res) => {
1158
+ const lookupTableData = await this.connection
1159
+ .getAccountInfo((0, anchor_1.translateAddress)(lookupTable))
1160
+ .then((res) => {
1113
1161
  if (!res) {
1114
- throw new Error(`Lookup table account not found for key: ${(0, anchor_1.translateAddress)(constants_1.CARD_LOOKUP_TABLE_ADDRESS[this.network]).toString()}`);
1162
+ throw new Error(`Lookup table account not found for key: ${(0, anchor_1.translateAddress)(zebec_card_v2_sdk_1.CARD_LOOKUP_TABLE_ADDRESS[this.network]).toString()}`);
1115
1163
  }
1116
1164
  return res.data;
1117
1165
  });
@@ -1134,7 +1182,9 @@ class ZebecVaultService {
1134
1182
  const [streamVault] = (0, zebec_stream_sdk_1.deriveStreamVaultPda)(streamMetadata, this.streamProgramId);
1135
1183
  const streamVaultAta = (0, solana_common_1.getAssociatedTokenAddressSync)(streamToken, streamVault, true);
1136
1184
  const streamTokenDecimals = await (0, solana_common_1.getMintDecimals)(this.connection, streamToken);
1137
- const amount = (0, bignumber_js_1.BigNumber)(info.amount).times(solana_common_1.TEN_BIGNUM.pow(streamTokenDecimals)).toFixed(0);
1185
+ const amount = (0, bignumber_js_1.BigNumber)(info.amount)
1186
+ .times(solana_common_1.TEN_BIGNUM.pow(streamTokenDecimals))
1187
+ .toFixed(0);
1138
1188
  const feeInfo = await (0, zebec_stream_sdk_1.getFeeInfoForStream)(streamToken, amount, streamTokenDecimals, this.network);
1139
1189
  const feeToken = (0, anchor_1.translateAddress)(feeInfo.feeToken.mintAddress);
1140
1190
  const feeTokenDecimals = await (0, solana_common_1.getMintDecimals)(this.connection, feeToken);
@@ -1166,7 +1216,9 @@ class ZebecVaultService {
1166
1216
  cliffPercentage,
1167
1217
  duration: new anchor_1.BN(info.duration),
1168
1218
  isPausable: info.isPausable,
1169
- numberOfWithdrawls: autoWithdrawFrequency > 0 ? new anchor_1.BN(Math.floor(info.duration / autoWithdrawFrequency)) : new anchor_1.BN(0),
1219
+ numberOfWithdrawls: autoWithdrawFrequency > 0
1220
+ ? new anchor_1.BN(Math.floor(info.duration / autoWithdrawFrequency))
1221
+ : new anchor_1.BN(0),
1170
1222
  rateUpdatable: info.rateUpdatable,
1171
1223
  startNow: info.startNow,
1172
1224
  startTime: new anchor_1.BN(info.startTime),
@@ -1184,7 +1236,9 @@ class ZebecVaultService {
1184
1236
  return this._createMultiTransactionPayload(vaultOwner, transactionArtifacts);
1185
1237
  }
1186
1238
  async cancelStream(params) {
1187
- const vaultOwner = params.vaultOwner ? (0, anchor_1.translateAddress)(params.vaultOwner) : this.provider.publicKey;
1239
+ const vaultOwner = params.vaultOwner
1240
+ ? (0, anchor_1.translateAddress)(params.vaultOwner)
1241
+ : this.provider.publicKey;
1188
1242
  if (!vaultOwner) {
1189
1243
  throw new Error("Either provide a caller or use AnchorProvider for provider in the service");
1190
1244
  }
@@ -1211,7 +1265,9 @@ class ZebecVaultService {
1211
1265
  const [streamVault] = (0, zebec_stream_sdk_1.deriveStreamVaultPda)(streamMetadata, this.streamProgramId);
1212
1266
  const streamVaultAta = (0, solana_common_1.getAssociatedTokenAddressSync)(streamToken, streamVault, true);
1213
1267
  const ix = await this.getCancelStreamInstruction(feePayer, otherParty, otherPartyAta, vaultSigner, userAta, streamMetadata, streamToken, streamVault, streamVaultAta);
1214
- const actions = [(0, utils_1.transactionInstructionToPropoalAction)(ix)];
1268
+ const actions = [
1269
+ (0, utils_1.transactionInstructionToPropoalAction)(ix),
1270
+ ];
1215
1271
  const remainingAccounts = actions.reduce((acc, current) => {
1216
1272
  const accounts = current.accountSpecs.map((spec) => ({
1217
1273
  pubkey: spec.pubkey,
@@ -1229,7 +1285,9 @@ class ZebecVaultService {
1229
1285
  return this._createTransactionPayload(feePayer, [ixFinal]);
1230
1286
  }
1231
1287
  async pauseResumeStream(params) {
1232
- const vaultOwner = params.vaultOwner ? (0, anchor_1.translateAddress)(params.vaultOwner) : this.provider.publicKey;
1288
+ const vaultOwner = params.vaultOwner
1289
+ ? (0, anchor_1.translateAddress)(params.vaultOwner)
1290
+ : this.provider.publicKey;
1233
1291
  if (!vaultOwner) {
1234
1292
  throw new Error("Either provide a caller or use AnchorProvider for provider in the service");
1235
1293
  }
@@ -1266,7 +1324,9 @@ class ZebecVaultService {
1266
1324
  return this._createTransactionPayload(vaultOwner, [ixFinal]);
1267
1325
  }
1268
1326
  async changeStreamReceiver(params) {
1269
- const vaultOwner = params.vaultOwner ? (0, anchor_1.translateAddress)(params.vaultOwner) : this.provider.publicKey;
1327
+ const vaultOwner = params.vaultOwner
1328
+ ? (0, anchor_1.translateAddress)(params.vaultOwner)
1329
+ : this.provider.publicKey;
1270
1330
  if (!vaultOwner) {
1271
1331
  throw new Error("Either provide a vaultOwner or use AnchorProvider for provider in the service");
1272
1332
  }
@@ -1275,7 +1335,9 @@ class ZebecVaultService {
1275
1335
  const streamMetadata = (0, anchor_1.translateAddress)(params.streamMetadata);
1276
1336
  const newRecipient = (0, anchor_1.translateAddress)(params.newRecipient);
1277
1337
  const ix = await this.getChangeStreamReceiverInstruction(streamMetadata, newRecipient, vaultSigner);
1278
- const actions = [(0, utils_1.transactionInstructionToPropoalAction)(ix)];
1338
+ const actions = [
1339
+ (0, utils_1.transactionInstructionToPropoalAction)(ix),
1340
+ ];
1279
1341
  const remainingAccounts = actions.reduce((acc, current) => {
1280
1342
  const accounts = current.accountSpecs.map((spec) => ({
1281
1343
  pubkey: spec.pubkey,
@@ -1293,7 +1355,9 @@ class ZebecVaultService {
1293
1355
  return this._createTransactionPayload(vaultOwner, [ixFinal]);
1294
1356
  }
1295
1357
  async withdrawStream(params) {
1296
- const vaultOwner = params.vaultOwner ? (0, anchor_1.translateAddress)(params.vaultOwner) : this.provider.publicKey;
1358
+ const vaultOwner = params.vaultOwner
1359
+ ? (0, anchor_1.translateAddress)(params.vaultOwner)
1360
+ : this.provider.publicKey;
1297
1361
  if (!vaultOwner) {
1298
1362
  throw new Error("Either provide a caller or use AnchorProvider for provider in the service");
1299
1363
  }
@@ -1405,7 +1469,9 @@ class ZebecVaultService {
1405
1469
  .instruction();
1406
1470
  }
1407
1471
  async stake(params) {
1408
- const vaultOwner = params.vaultOwner ? (0, anchor_1.translateAddress)(params.vaultOwner) : this.provider.publicKey;
1472
+ const vaultOwner = params.vaultOwner
1473
+ ? (0, anchor_1.translateAddress)(params.vaultOwner)
1474
+ : this.provider.publicKey;
1409
1475
  if (!vaultOwner) {
1410
1476
  throw new Error("MissingArgument: Please provide either vaultOwner address or publicKey in provider");
1411
1477
  }
@@ -1419,7 +1485,8 @@ class ZebecVaultService {
1419
1485
  }
1420
1486
  const lockPeriods = lockupAccount.stakeInfo.durationMap.map((item) => item.duration.toNumber());
1421
1487
  if (!lockPeriods.includes(params.lockPeriod)) {
1422
- throw new Error("Invalid lockperiod. Available options are: " + lockPeriods.map((l) => l.toString()).concat(", "));
1488
+ throw new Error("Invalid lockperiod. Available options are: " +
1489
+ lockPeriods.map((l) => l.toString()).concat(", "));
1423
1490
  }
1424
1491
  const stakeToken = lockupAccount.stakedToken.tokenAddress;
1425
1492
  const stakeVault = (0, zebec_stake_sdk_1.deriveStakeVaultAddress)(lockup, this.stakeProgramId);
@@ -1453,13 +1520,15 @@ class ZebecVaultService {
1453
1520
  return acc;
1454
1521
  }, []);
1455
1522
  const ixFinal = await this.getExecuteProposalDirectInstruction(vaultOwner, actions, remainingAccounts);
1456
- const lookupTables = await this.connection.getAddressLookupTable((0, anchor_1.translateAddress)(constants_1.STAKE_LOOKUP_TABLE_ADDRESS[this.network]));
1523
+ const lookupTables = await this.connection.getAddressLookupTable((0, anchor_1.translateAddress)(zebec_stake_sdk_1.STAKE_LOOKUP_TABLE_ADDRESS[this.network]));
1457
1524
  const lookupTableAccount = lookupTables.value;
1458
1525
  (0, assert_1.default)(lookupTableAccount, "Lookup table account not found");
1459
1526
  return this._createTransactionPayload(vaultOwner, [ixFinal], [], [lookupTableAccount]);
1460
1527
  }
1461
1528
  async unstake(params) {
1462
- const vaultOwner = params.vaultOwner ? (0, anchor_1.translateAddress)(params.vaultOwner) : this.provider.publicKey;
1529
+ const vaultOwner = params.vaultOwner
1530
+ ? (0, anchor_1.translateAddress)(params.vaultOwner)
1531
+ : this.provider.publicKey;
1463
1532
  if (!vaultOwner) {
1464
1533
  throw new Error("MissingArgument: Please provide either staker address or publicKey in provider");
1465
1534
  }
@@ -1494,7 +1563,7 @@ class ZebecVaultService {
1494
1563
  return acc;
1495
1564
  }, []);
1496
1565
  const ixFinal = await this.getExecuteProposalDirectInstruction(vaultOwner, actions, remainingAccounts);
1497
- const lookupTables = await this.connection.getAddressLookupTable((0, anchor_1.translateAddress)(constants_1.STAKE_LOOKUP_TABLE_ADDRESS[this.network]));
1566
+ const lookupTables = await this.connection.getAddressLookupTable((0, anchor_1.translateAddress)(zebec_stake_sdk_1.STAKE_LOOKUP_TABLE_ADDRESS[this.network]));
1498
1567
  const lookupTableAccount = lookupTables.value;
1499
1568
  (0, assert_1.default)(lookupTableAccount, "Lookup table account not found");
1500
1569
  return this._createTransactionPayload(vaultOwner, [ixFinal], [], [lookupTableAccount]);