@zebec-network/zebec-vault-sdk 5.1.3 → 5.2.0-dev.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/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");
@@ -581,7 +581,7 @@ class ZebecVaultService {
581
581
  }
582
582
  }
583
583
  async getNextCardIndex() {
584
- const [cardConfig] = (0, pda_1.deriveCardConfigPda)(this.cardV2Program.programId);
584
+ const [cardConfig] = (0, zebec_card_v2_sdk_1.deriveCardConfigPda)(this.cardV2Program.programId);
585
585
  const decoded = await this.cardV2Program.account.card.fetch(cardConfig, "confirmed");
586
586
  return BigInt(decoded.index.addn(1).toString());
587
587
  }
@@ -595,8 +595,8 @@ class ZebecVaultService {
595
595
  const [vaultSigner] = (0, pda_1.deriveVaultSigner)(vault, this.vaultV1ProgramId);
596
596
  const usdcMint = (0, anchor_1.translateAddress)(params.usdcAddress);
597
597
  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);
598
+ const [cardConfig] = (0, zebec_card_v2_sdk_1.deriveCardConfigPda)(this.cardV2Program.programId);
599
+ const [userPurchaseRecord] = (0, zebec_card_v2_sdk_1.deriveUserPurchaseRecordPda)(vaultSigner, this.cardV2Program.programId);
600
600
  const cardConfigInfo = await this.cardV2Program.account.card.fetch(cardConfig, "confirmed");
601
601
  const cardVault = cardConfigInfo.cardVault;
602
602
  const revenueVault = cardConfigInfo.revenueVault;
@@ -642,8 +642,8 @@ class ZebecVaultService {
642
642
  const [vaultSigner] = (0, pda_1.deriveVaultSigner)(vault, this.vaultV1ProgramId);
643
643
  const usdcMint = (0, anchor_1.translateAddress)(params.usdcAddress);
644
644
  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);
645
+ const [cardConfig] = (0, zebec_card_v2_sdk_1.deriveCardConfigPda)(this.cardV2Program.programId);
646
+ const [userPurchaseRecord] = (0, zebec_card_v2_sdk_1.deriveUserPurchaseRecordPda)(vaultSigner, this.cardV2Program.programId);
647
647
  const cardConfigInfo = await this.cardV2Program.account.card.fetch(cardConfig, "confirmed");
648
648
  const cardVault = cardConfigInfo.cardVault;
649
649
  const revenueVault = cardConfigInfo.revenueVault;
@@ -691,8 +691,8 @@ class ZebecVaultService {
691
691
  const [vaultSigner] = (0, pda_1.deriveVaultSigner)(vault, this.vaultV1ProgramId);
692
692
  const inputMint = (0, anchor_1.translateAddress)(quoteInfo.inputMint);
693
693
  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);
694
+ const [userPurchaseRecord] = (0, zebec_card_v2_sdk_1.deriveUserPurchaseRecordPda)(vaultSigner, this.cardV2ProgramId);
695
+ const [cardConfig] = (0, zebec_card_v2_sdk_1.deriveCardConfigPda)(this.cardV2ProgramId);
696
696
  const cardConfigInfo = await this.cardV2Program.account.card.fetch(cardConfig, this.connection.commitment);
697
697
  const revenueVault = cardConfigInfo.revenueVault;
698
698
  const cardVault = cardConfigInfo.cardVault;
@@ -710,7 +710,7 @@ class ZebecVaultService {
710
710
  if (!inputMint.equals(solana_common_1.WSOL) || !isSolWrapUnwrapNeeded) {
711
711
  const userInputMintAtaInfo = await this.connection.getAccountInfo(userInputMintAta, this.connection.commitment);
712
712
  if (!userInputMintAtaInfo) {
713
- throw new errors_1.AssociatedTokenAccountDoesNotExistsError("User doesn't have associated token account of input mint: " + inputMint.toString());
713
+ throw new errors_1.AssociatedTokenAccountDoesNotExistsError(`User doesn't have associated token account of input mint: ${inputMint.toString()}`);
714
714
  }
715
715
  const resAndCtx = await this.connection.getTokenAccountBalance(userInputMintAta, this.connection.commitment);
716
716
  const balance = resAndCtx.value.amount;
@@ -752,15 +752,25 @@ class ZebecVaultService {
752
752
  const transaction = web3_js_1.VersionedTransaction.deserialize(swapTransactionBuf);
753
753
  // get address lookup table accounts
754
754
  const addressLookupTableAccounts = await Promise.all(transaction.message.addressTableLookups.map(async (lookup) => {
755
- const data = await this.connection.getAccountInfo(lookup.accountKey).then((res) => res.data);
755
+ const data = await this.connection.getAccountInfo(lookup.accountKey).then((res) => {
756
+ 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()}`);
758
+ }
759
+ return res.data;
760
+ });
756
761
  return new web3_js_1.AddressLookupTableAccount({
757
762
  key: lookup.accountKey,
758
763
  state: web3_js_1.AddressLookupTableAccount.deserialize(data),
759
764
  });
760
765
  }));
761
- const lookupTableData = await new web3_js_1.Connection((0, web3_js_1.clusterApiUrl)("devnet"))
766
+ const lookupTableData = await this.connection
762
767
  .getAccountInfo((0, anchor_1.translateAddress)(constants_1.CARD_LOOKUP_TABLE_ADDRESS[this.network]))
763
- .then((res) => res.data);
768
+ .then((res) => {
769
+ 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()}`);
771
+ }
772
+ return res.data;
773
+ });
764
774
  addressLookupTableAccounts.push(new web3_js_1.AddressLookupTableAccount({
765
775
  key: (0, anchor_1.translateAddress)(constants_1.CARD_LOOKUP_TABLE_ADDRESS[this.network]),
766
776
  state: web3_js_1.AddressLookupTableAccount.deserialize(lookupTableData),
@@ -795,8 +805,8 @@ class ZebecVaultService {
795
805
  const [vaultSigner] = (0, pda_1.deriveVaultSigner)(vault, this.vaultV1ProgramId);
796
806
  const inputMint = (0, anchor_1.translateAddress)(quoteInfo.inputMint);
797
807
  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);
808
+ const [userPurchaseRecord] = (0, zebec_card_v2_sdk_1.deriveUserPurchaseRecordPda)(vaultSigner, this.cardV2ProgramId);
809
+ const [cardConfig] = (0, zebec_card_v2_sdk_1.deriveCardConfigPda)(this.cardV2ProgramId);
800
810
  const cardConfigInfo = await this.cardV2Program.account.card.fetch(cardConfig, this.connection.commitment);
801
811
  const revenueVault = cardConfigInfo.revenueVault;
802
812
  const cardVault = cardConfigInfo.cardVault;
@@ -856,15 +866,25 @@ class ZebecVaultService {
856
866
  const transaction = web3_js_1.VersionedTransaction.deserialize(swapTransactionBuf);
857
867
  // get address lookup table accounts
858
868
  const addressLookupTableAccounts = await Promise.all(transaction.message.addressTableLookups.map(async (lookup) => {
859
- const data = await this.connection.getAccountInfo(lookup.accountKey).then((res) => res.data);
869
+ const data = await this.connection.getAccountInfo(lookup.accountKey).then((res) => {
870
+ if (!res) {
871
+ throw new Error(`Lookup table account not found for key: ${lookup.accountKey.toString()}`);
872
+ }
873
+ return res.data;
874
+ });
860
875
  return new web3_js_1.AddressLookupTableAccount({
861
876
  key: lookup.accountKey,
862
877
  state: web3_js_1.AddressLookupTableAccount.deserialize(data),
863
878
  });
864
879
  }));
865
- const lookupTableData = await new web3_js_1.Connection((0, web3_js_1.clusterApiUrl)("devnet"))
880
+ const lookupTableData = await this.connection
866
881
  .getAccountInfo((0, anchor_1.translateAddress)(constants_1.CARD_LOOKUP_TABLE_ADDRESS[this.network]))
867
- .then((res) => res.data);
882
+ .then((res) => {
883
+ 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()}`);
885
+ }
886
+ return res.data;
887
+ });
868
888
  addressLookupTableAccounts.push(new web3_js_1.AddressLookupTableAccount({
869
889
  key: (0, anchor_1.translateAddress)(constants_1.CARD_LOOKUP_TABLE_ADDRESS[this.network]),
870
890
  state: web3_js_1.AddressLookupTableAccount.deserialize(lookupTableData),
@@ -890,7 +910,7 @@ class ZebecVaultService {
890
910
  return this._createTransactionPayload(vaultOwner, otherIxs, [], addressLookupTableAccounts);
891
911
  }
892
912
  async getCardCustomTokenFees() {
893
- const [tokeFeeMapPda] = (0, pda_1.deriveTokenFeeMapPda)(this.cardV2ProgramId);
913
+ const [tokeFeeMapPda] = (0, zebec_card_v2_sdk_1.deriveTokenFeeMapPda)(this.cardV2ProgramId);
894
914
  const decoded = await this.cardV2Program.account.customFeeMap.fetch(tokeFeeMapPda, this.connection.commitment);
895
915
  const tokenFeeList = decoded.feeMap.map((item) => ({
896
916
  tokenAddress: item.tokenAddress,
@@ -898,6 +918,21 @@ class ZebecVaultService {
898
918
  }));
899
919
  return tokenFeeList;
900
920
  }
921
+ async getTransfeFeesForStreamInstruction(streamConfig, feeVault, tokenMint, vaultOwner, feeVaultTokenAccount, vault, vaultSigner, vaultSignerTokenAccount, data) {
922
+ return this.vaultV1Program.methods
923
+ .transferFees({ decimals: data.decimals, feeAmount: data.feeAmount })
924
+ .accountsPartial({
925
+ streamConfig,
926
+ feeVault,
927
+ tokenMint,
928
+ vaultOwner,
929
+ feeVaultTokenAccount,
930
+ vault,
931
+ vaultSigner,
932
+ vaultSignerTokenAccount,
933
+ })
934
+ .instruction();
935
+ }
901
936
  async getCreateStreamFromVaultInstruction(vaultOwner, vault, vaultSigner, vaultSignerAta, receiver, receiverAta, streamToken, streamMetadata, streamConfig, withdrawAccount, streamVault, streamVaultAta, zebecStreamProgram, streamData) {
902
937
  return this.vaultV1Program.methods
903
938
  .createStream({
@@ -984,6 +1019,19 @@ class ZebecVaultService {
984
1019
  })
985
1020
  .instruction();
986
1021
  }
1022
+ async getTransferFeesForStreamInstruction(feeVault, tokenMint, vaultOwner, feeVaultTokenAccount, vault, vaultSigner, vaultSignerTokenAccount, data) {
1023
+ return this.vaultV1Program.methods
1024
+ .transferFees({ decimals: data.decimals, feeAmount: data.feeAmount })
1025
+ .accountsPartial({
1026
+ feeVault,
1027
+ tokenMint,
1028
+ vaultOwner,
1029
+ feeVaultTokenAccount,
1030
+ vault,
1031
+ vaultSigner,
1032
+ vaultSignerTokenAccount,
1033
+ });
1034
+ }
987
1035
  async createStreamFromVault(params) {
988
1036
  const vaultOwner = (0, anchor_1.translateAddress)(params.vaultOwner);
989
1037
  const [vault] = (0, pda_1.deriveUserVault)(vaultOwner, this.vaultV1ProgramId);
@@ -994,15 +1042,28 @@ class ZebecVaultService {
994
1042
  const streamToken = (0, anchor_1.translateAddress)(params.streamToken);
995
1043
  const vaultSignerAta = (0, solana_common_1.getAssociatedTokenAddressSync)(streamToken, vaultSigner, true);
996
1044
  const receiverVaultSignerAta = (0, solana_common_1.getAssociatedTokenAddressSync)(streamToken, receiverVaultSigner, true);
997
- const [streamConfig] = (0, pda_1.deriveStreamConfigPda)(this.streamProgramId);
1045
+ const [streamConfig] = (0, zebec_stream_sdk_1.deriveStreamConfigPda)(params.streamConfigName, this.streamProgramId);
998
1046
  const streamConfigInfo = await this.streamProgram.account.streamConfig.fetch(streamConfig, this.connection.commitment);
999
1047
  const withdrawAccount = streamConfigInfo.withdrawAccount;
1000
1048
  const streamMetatdataKeypair = params.streamMetadataKeypair ?? web3_js_1.Keypair.generate();
1001
1049
  const streamMetadata = streamMetatdataKeypair.publicKey;
1002
- const [streamVault] = (0, pda_1.deriveStreamVaultPda)(streamMetadata, this.streamProgramId);
1050
+ const [streamVault] = (0, zebec_stream_sdk_1.deriveStreamVaultPda)(streamMetadata, this.streamProgramId);
1003
1051
  const streamVaultAta = (0, solana_common_1.getAssociatedTokenAddressSync)(streamToken, streamVault, true);
1004
1052
  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));
1053
+ const amount = (0, bignumber_js_1.BigNumber)(params.amount).times(solana_common_1.TEN_BIGNUM.pow(streamTokenDecimals)).toFixed(0);
1054
+ const feeInfo = await (0, zebec_stream_sdk_1.getFeeInfoForStream)(streamToken, amount, streamTokenDecimals, this.network);
1055
+ const feeToken = (0, anchor_1.translateAddress)(feeInfo.feeToken.mintAddress);
1056
+ const feeTokenDecimals = await (0, solana_common_1.getMintDecimals)(this.connection, feeToken);
1057
+ const parsedFeeAmount = feeInfo.feeAmountRaw;
1058
+ const feeVault = streamConfigInfo.feeVault;
1059
+ const feeVaultAta = (0, solana_common_1.getAssociatedTokenAddressSync)(feeToken, feeVault, true);
1060
+ const vaultSignerFeeTokenAta = (0, solana_common_1.getAssociatedTokenAddressSync)(feeToken, vaultSigner, true);
1061
+ const ixs = [];
1062
+ const transferFeesIx = await this.getTransfeFeesForStreamInstruction(streamConfig, feeVault, feeToken, vaultOwner, feeVaultAta, vault, vaultSigner, vaultSignerFeeTokenAta, {
1063
+ decimals: feeTokenDecimals,
1064
+ feeAmount: new anchor_1.BN(parsedFeeAmount),
1065
+ });
1066
+ ixs.push(transferFeesIx);
1006
1067
  const cliffPercentage = new anchor_1.BN((0, core_utils_1.percentToBps)(params.cliffPercentage));
1007
1068
  const STREAM_NAME_BUFFER_SIZE = 128;
1008
1069
  const streamNameArray = new Uint8Array(STREAM_NAME_BUFFER_SIZE);
@@ -1011,8 +1072,8 @@ class ZebecVaultService {
1011
1072
  if (params.automaticWithdrawal && autoWithdrawFrequency <= 0) {
1012
1073
  throw new Error("autoWithdrawFrequency must be greater than 0 when automaticWithdrawal is enabled");
1013
1074
  }
1014
- const ix = await this.getCreateStreamFromVaultInstruction(vaultOwner, vault, vaultSigner, vaultSignerAta, receiverVaultSigner, receiverVaultSignerAta, streamToken, streamMetadata, streamConfig, withdrawAccount, streamVault, streamVaultAta, this.streamProgramId, {
1015
- amount,
1075
+ const createStreamIx = await this.getCreateStreamFromVaultInstruction(vaultOwner, vault, vaultSigner, vaultSignerAta, receiverVaultSigner, receiverVaultSignerAta, streamToken, streamMetadata, streamConfig, withdrawAccount, streamVault, streamVaultAta, this.streamProgramId, {
1076
+ amount: new anchor_1.BN(amount),
1016
1077
  automaticWithdrawal: params.automaticWithdrawal,
1017
1078
  autoWithdrawFrequency: new anchor_1.BN(autoWithdrawFrequency),
1018
1079
  cancelableByRecipient: params.cancelableByRecipient,
@@ -1029,12 +1090,35 @@ class ZebecVaultService {
1029
1090
  transferableByRecipient: params.transferableByRecipient,
1030
1091
  transferableBySender: params.transferableBySender,
1031
1092
  });
1032
- return this._createTransactionPayload(vaultOwner, [ix], [streamMetatdataKeypair]);
1093
+ 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) => {
1095
+ 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()}`);
1097
+ }
1098
+ return res.data;
1099
+ });
1100
+ const addressLookupTableAccount = new web3_js_1.AddressLookupTableAccount({
1101
+ key: (0, anchor_1.translateAddress)(lookupTable),
1102
+ state: web3_js_1.AddressLookupTableAccount.deserialize(lookupTableData),
1103
+ });
1104
+ ixs.push(createStreamIx);
1105
+ return this._createTransactionPayload(vaultOwner, ixs, [streamMetatdataKeypair], [addressLookupTableAccount]);
1033
1106
  }
1034
1107
  async createMultipleStreamFromVault(params) {
1035
1108
  const vaultOwner = (0, anchor_1.translateAddress)(params.vaultOwner);
1036
1109
  const [vault] = (0, pda_1.deriveUserVault)(vaultOwner, this.vaultV1ProgramId);
1037
1110
  const [vaultSigner] = (0, pda_1.deriveVaultSigner)(vault, this.vaultV1ProgramId);
1111
+ 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) => {
1113
+ 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()}`);
1115
+ }
1116
+ return res.data;
1117
+ });
1118
+ const addressLookupTableAccount = new web3_js_1.AddressLookupTableAccount({
1119
+ key: (0, anchor_1.translateAddress)(lookupTable),
1120
+ state: web3_js_1.AddressLookupTableAccount.deserialize(lookupTableData),
1121
+ });
1038
1122
  const transactionArtifacts = await Promise.all(params.streamInfo.map(async (info) => {
1039
1123
  const receiver = (0, anchor_1.translateAddress)(info.receiver);
1040
1124
  const [receiverVault] = (0, pda_1.deriveUserVault)(receiver, this.vaultV1ProgramId);
@@ -1042,15 +1126,28 @@ class ZebecVaultService {
1042
1126
  const streamToken = (0, anchor_1.translateAddress)(info.streamToken);
1043
1127
  const vaultSignerAta = (0, solana_common_1.getAssociatedTokenAddressSync)(streamToken, vaultSigner, true);
1044
1128
  const receiverVaultSignerAta = (0, solana_common_1.getAssociatedTokenAddressSync)(streamToken, receiverVaultSigner, true);
1045
- const [streamConfig] = (0, pda_1.deriveStreamConfigPda)(this.streamProgramId);
1129
+ const [streamConfig] = (0, zebec_stream_sdk_1.deriveStreamConfigPda)(params.streamConfigName, this.streamProgramId);
1046
1130
  const streamConfigInfo = await this.streamProgram.account.streamConfig.fetch(streamConfig, this.connection.commitment);
1047
1131
  const withdrawAccount = streamConfigInfo.withdrawAccount;
1048
1132
  const streamMetatdataKeypair = info.streamMetadataKeypair ?? web3_js_1.Keypair.generate();
1049
1133
  const streamMetadata = streamMetatdataKeypair.publicKey;
1050
- const [streamVault] = (0, pda_1.deriveStreamVaultPda)(streamMetadata, this.streamProgramId);
1134
+ const [streamVault] = (0, zebec_stream_sdk_1.deriveStreamVaultPda)(streamMetadata, this.streamProgramId);
1051
1135
  const streamVaultAta = (0, solana_common_1.getAssociatedTokenAddressSync)(streamToken, streamVault, true);
1052
1136
  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));
1137
+ const amount = (0, bignumber_js_1.BigNumber)(info.amount).times(solana_common_1.TEN_BIGNUM.pow(streamTokenDecimals)).toFixed(0);
1138
+ const feeInfo = await (0, zebec_stream_sdk_1.getFeeInfoForStream)(streamToken, amount, streamTokenDecimals, this.network);
1139
+ const feeToken = (0, anchor_1.translateAddress)(feeInfo.feeToken.mintAddress);
1140
+ const feeTokenDecimals = await (0, solana_common_1.getMintDecimals)(this.connection, feeToken);
1141
+ const parsedFeeAmount = feeInfo.feeAmountRaw;
1142
+ const feeVault = streamConfigInfo.feeVault;
1143
+ const feeVaultAta = (0, solana_common_1.getAssociatedTokenAddressSync)(feeToken, feeVault, true);
1144
+ const vaultSignerFeeTokenAta = (0, solana_common_1.getAssociatedTokenAddressSync)(feeToken, vaultSigner, true);
1145
+ const ixs = [];
1146
+ const transferFeesIx = await this.getTransfeFeesForStreamInstruction(streamConfig, feeVault, feeToken, vaultOwner, feeVaultAta, vault, vaultSigner, vaultSignerFeeTokenAta, {
1147
+ decimals: feeTokenDecimals,
1148
+ feeAmount: new anchor_1.BN(parsedFeeAmount),
1149
+ });
1150
+ ixs.push(transferFeesIx);
1054
1151
  const cliffPercentage = new anchor_1.BN((0, core_utils_1.percentToBps)(info.cliffPercentage));
1055
1152
  const STREAM_NAME_BUFFER_SIZE = 128;
1056
1153
  const streamNameArray = new Uint8Array(STREAM_NAME_BUFFER_SIZE);
@@ -1059,8 +1156,8 @@ class ZebecVaultService {
1059
1156
  if (info.automaticWithdrawal && autoWithdrawFrequency <= 0) {
1060
1157
  throw new Error("autoWithdrawFrequency must be greater than 0 when automaticWithdrawal is enabled");
1061
1158
  }
1062
- const ix = await this.getCreateStreamFromVaultInstruction(vaultOwner, vault, vaultSigner, vaultSignerAta, receiverVaultSigner, receiverVaultSignerAta, streamToken, streamMetadata, streamConfig, withdrawAccount, streamVault, streamVaultAta, this.streamProgramId, {
1063
- amount,
1159
+ const createStreamIx = await this.getCreateStreamFromVaultInstruction(vaultOwner, vault, vaultSigner, vaultSignerAta, receiverVaultSigner, receiverVaultSignerAta, streamToken, streamMetadata, streamConfig, withdrawAccount, streamVault, streamVaultAta, this.streamProgramId, {
1160
+ amount: new anchor_1.BN(amount),
1064
1161
  automaticWithdrawal: info.automaticWithdrawal,
1065
1162
  autoWithdrawFrequency: new anchor_1.BN(autoWithdrawFrequency),
1066
1163
  cancelableByRecipient: info.cancelableByRecipient,
@@ -1077,9 +1174,11 @@ class ZebecVaultService {
1077
1174
  transferableByRecipient: info.transferableByRecipient,
1078
1175
  transferableBySender: info.transferableBySender,
1079
1176
  });
1177
+ ixs.push(createStreamIx);
1080
1178
  return {
1081
- instructions: [ix],
1179
+ instructions: ixs,
1082
1180
  signers: [streamMetatdataKeypair],
1181
+ addressLookupTableAccounts: [addressLookupTableAccount],
1083
1182
  };
1084
1183
  }));
1085
1184
  return this._createMultiTransactionPayload(vaultOwner, transactionArtifacts);
@@ -1109,7 +1208,7 @@ class ZebecVaultService {
1109
1208
  const feePayer = vaultOwner;
1110
1209
  const userAta = (0, solana_common_1.getAssociatedTokenAddressSync)(streamToken, vaultSigner, true);
1111
1210
  const otherPartyAta = (0, solana_common_1.getAssociatedTokenAddressSync)(streamToken, otherParty, true);
1112
- const [streamVault] = (0, pda_1.deriveStreamVaultPda)(streamMetadata, this.streamProgramId);
1211
+ const [streamVault] = (0, zebec_stream_sdk_1.deriveStreamVaultPda)(streamMetadata, this.streamProgramId);
1113
1212
  const streamVaultAta = (0, solana_common_1.getAssociatedTokenAddressSync)(streamToken, streamVault, true);
1114
1213
  const ix = await this.getCancelStreamInstruction(feePayer, otherParty, otherPartyAta, vaultSigner, userAta, streamMetadata, streamToken, streamVault, streamVaultAta);
1115
1214
  const actions = [(0, utils_1.transactionInstructionToPropoalAction)(ix)];
@@ -1206,7 +1305,7 @@ class ZebecVaultService {
1206
1305
  const streamMetadataAccount = await this.streamProgram.account.paymentStream.fetch(streamMetadata);
1207
1306
  const streamToken = streamMetadataAccount.financials.streamToken;
1208
1307
  const vaultSignerAta = (0, solana_common_1.getAssociatedTokenAddressSync)(streamToken, vaultSigner, true);
1209
- const [streamVault] = (0, pda_1.deriveStreamVaultPda)(streamMetadata, this.streamProgramId);
1308
+ const [streamVault] = (0, zebec_stream_sdk_1.deriveStreamVaultPda)(streamMetadata, this.streamProgramId);
1210
1309
  const streamVaultAta = (0, solana_common_1.getAssociatedTokenAddressSync)(streamToken, streamVault, true);
1211
1310
  const ix = await this.getWithdrawStreamInstruction(vaultSigner, vaultSignerAta, streamMetadata, streamToken, streamVault, streamVaultAta, withdrawer, feePayer);
1212
1311
  const actions = [(0, utils_1.transactionInstructionToPropoalAction)(ix)];
@@ -1313,7 +1412,7 @@ class ZebecVaultService {
1313
1412
  const feePayer = vaultOwner;
1314
1413
  const [vault] = (0, pda_1.deriveUserVault)(vaultOwner, this.vaultV1ProgramId);
1315
1414
  const [vaultSigner] = (0, pda_1.deriveVaultSigner)(vault, this.vaultV1ProgramId);
1316
- const lockup = (0, pda_1.deriveLockupAddress)(params.lockupName, this.stakeProgramId);
1415
+ const lockup = (0, zebec_stake_sdk_1.deriveLockupAddress)(params.lockupName, this.stakeProgramId);
1317
1416
  const lockupAccount = await this.stakeProgram.account.lockup.fetchNullable(lockup, this.connection.commitment);
1318
1417
  if (!lockupAccount) {
1319
1418
  throw new Error("Lockup account does not exists for address: " + lockup);
@@ -1323,14 +1422,14 @@ class ZebecVaultService {
1323
1422
  throw new Error("Invalid lockperiod. Available options are: " + lockPeriods.map((l) => l.toString()).concat(", "));
1324
1423
  }
1325
1424
  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);
1425
+ const stakeVault = (0, zebec_stake_sdk_1.deriveStakeVaultAddress)(lockup, this.stakeProgramId);
1426
+ const userNonce = (0, zebec_stake_sdk_1.deriveUserNonceAddress)(vaultSigner, lockup, this.stakeProgramId);
1328
1427
  const userNonceAccount = await this.stakeProgram.account.userNonce.fetchNullable(userNonce, this.connection.commitment);
1329
1428
  let nonce = BigInt(0);
1330
1429
  if (userNonceAccount) {
1331
1430
  nonce = BigInt(userNonceAccount.nonce.toString());
1332
1431
  }
1333
- const stakePda = (0, pda_1.deriveStakeAddress)(vaultSigner, lockup, nonce, this.stakeProgramId);
1432
+ const stakePda = (0, zebec_stake_sdk_1.deriveStakeAddress)(vaultSigner, lockup, nonce, this.stakeProgramId);
1334
1433
  const stakeVaultTokenAccount = (0, solana_common_1.getAssociatedTokenAddressSync)(stakeToken, stakeVault, true);
1335
1434
  const stakeTokenDecimals = await (0, solana_common_1.getMintDecimals)(this.connection, stakeToken);
1336
1435
  const UNITS_PER_STAKE_TOKEN = solana_common_1.TEN_BIGNUM.pow(stakeTokenDecimals);
@@ -1367,17 +1466,17 @@ class ZebecVaultService {
1367
1466
  const [vault] = (0, pda_1.deriveUserVault)(vaultOwner, this.vaultV1ProgramId);
1368
1467
  const [vaultSigner] = (0, pda_1.deriveVaultSigner)(vault, this.vaultV1ProgramId);
1369
1468
  const feePayer = vaultOwner;
1370
- const lockup = (0, pda_1.deriveLockupAddress)(params.lockupName, this.stakeProgramId);
1469
+ const lockup = (0, zebec_stake_sdk_1.deriveLockupAddress)(params.lockupName, this.stakeProgramId);
1371
1470
  const lockupAccount = await this.stakeProgram.account.lockup.fetchNullable(lockup, this.connection.commitment);
1372
1471
  if (!lockupAccount) {
1373
- throw new Error("Lockup account does not exists for address: " + lockup);
1472
+ throw new Error(`Lockup account does not exists for address: ${lockup}`);
1374
1473
  }
1375
1474
  const stakeToken = lockupAccount.stakedToken.tokenAddress;
1376
1475
  const rewardToken = lockupAccount.rewardToken.tokenAddress;
1377
1476
  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);
1477
+ const stakePda = (0, zebec_stake_sdk_1.deriveStakeAddress)(vaultSigner, lockup, params.nonce, this.stakeProgramId);
1478
+ const rewardVault = (0, zebec_stake_sdk_1.deriveRewardVaultAddress)(lockup, this.stakeProgramId);
1479
+ const stakeVault = (0, zebec_stake_sdk_1.deriveStakeVaultAddress)(lockup, this.stakeProgramId);
1381
1480
  const stakerTokenAccount = (0, solana_common_1.getAssociatedTokenAddressSync)(stakeToken, vaultSigner, true);
1382
1481
  const instruction = await this.getUnstakeInstruction(feePayer, feeVault, lockup, stakePda, rewardToken, rewardVault, stakeToken, stakeVault, vaultSigner, stakerTokenAccount, new anchor_1.BN(params.nonce.toString()));
1383
1482
  const actions = [(0, utils_1.transactionInstructionToPropoalAction)(instruction)];
@@ -1404,8 +1503,8 @@ class ZebecVaultService {
1404
1503
  const vaultOwner = (0, anchor_1.translateAddress)(vaultOwnerAddress);
1405
1504
  const [vault] = (0, pda_1.deriveUserVault)(vaultOwner, this.vaultV1ProgramId);
1406
1505
  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);
1506
+ const lockup = (0, zebec_stake_sdk_1.deriveLockupAddress)(lockupName, this.stakeProgramId);
1507
+ const userNonceAddress = (0, zebec_stake_sdk_1.deriveUserNonceAddress)(vaultSigner, lockup, this.stakeProgramId);
1409
1508
  const userNonceAccount = await this.stakeProgram.account.userNonce.fetchNullable(userNonceAddress, commitment ?? this.connection.commitment);
1410
1509
  if (!userNonceAccount) {
1411
1510
  return null;
@@ -1417,8 +1516,8 @@ class ZebecVaultService {
1417
1516
  }
1418
1517
  async _createTransactionPayload(payerKey, instructions, signers, addressLookupTableAccounts) {
1419
1518
  const errorMap = new Map();
1420
- this.vaultV1Program.idl.errors.forEach((error) => errorMap.set(error.code, error.msg));
1421
- let signTransaction = undefined;
1519
+ this.vaultV1Program.idl.errors.map((error) => errorMap.set(error.code, error.msg));
1520
+ let signTransaction;
1422
1521
  const provider = this.provider;
1423
1522
  if (provider instanceof anchor_1.AnchorProvider) {
1424
1523
  signTransaction = async (tx) => {
@@ -1429,8 +1528,8 @@ class ZebecVaultService {
1429
1528
  }
1430
1529
  async _createMultiTransactionPayload(payerKey, transactionArtifacts) {
1431
1530
  const errorMap = new Map();
1432
- this.vaultV1Program.idl.errors.forEach((error) => errorMap.set(error.code, error.msg));
1433
- let signAllTransactions = undefined;
1531
+ this.vaultV1Program.idl.errors.map((error) => errorMap.set(error.code, error.msg));
1532
+ let signAllTransactions;
1434
1533
  const provider = this.provider;
1435
1534
  if (provider instanceof anchor_1.AnchorProvider) {
1436
1535
  signAllTransactions = async (txns) => {
@@ -1441,6 +1540,7 @@ class ZebecVaultService {
1441
1540
  instructions: data.instructions,
1442
1541
  feePayer: payerKey,
1443
1542
  signers: data.signers,
1543
+ addressLookupTableAccounts: data.addressLookupTableAccounts,
1444
1544
  }));
1445
1545
  return new solana_common_1.MultiTransactionPayload(this.connection, errorMap, transactionData, signAllTransactions);
1446
1546
  }
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Address, BN } from "@coral-xyz/anchor";
2
- import { Keypair, PublicKey } from "@solana/web3.js";
1
+ import type { Address, BN } from "@coral-xyz/anchor";
2
+ import type { Keypair, PublicKey } from "@solana/web3.js";
3
3
  export type Numeric = number | string;
4
4
  export type ProposalAction = {
5
5
  programId: PublicKey;
@@ -163,6 +163,7 @@ export type CreateStreamFromVaultParams = {
163
163
  vaultOwner: Address;
164
164
  receiver: Address;
165
165
  streamToken: Address;
166
+ streamConfigName: string;
166
167
  amount: Numeric;
167
168
  automaticWithdrawal: boolean;
168
169
  cancelableByRecipient: boolean;
@@ -182,6 +183,7 @@ export type CreateStreamFromVaultParams = {
182
183
  };
183
184
  export type createMultipleStreamFromVaultParams = {
184
185
  vaultOwner: Address;
186
+ streamConfigName: string;
185
187
  streamInfo: {
186
188
  receiver: Address;
187
189
  streamToken: Address;
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { TransactionInstruction } from "@solana/web3.js";
2
- import { ProposalAction } from "./types";
1
+ import type { TransactionInstruction } from "@solana/web3.js";
2
+ import type { ProposalAction } from "./types";
3
3
  export declare function calculateActionsSize(actions: ProposalAction[]): number;
4
4
  export declare function calculateProposalSize(name: string, actions: ProposalAction[]): number;
5
5
  export declare function transactionInstructionToPropoalAction(ix: TransactionInstruction): ProposalAction;
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "@zebec-network/solana-common": "^2.3.1",
10
10
  "@zebec-network/zebec-card-v2-sdk": "^2.5.4",
11
11
  "@zebec-network/zebec-stake-sdk": "^1.2.2",
12
- "@zebec-network/zebec-stream-sdk": "^2.1.0",
12
+ "@zebec-network/zebec-stream-sdk": "^3.1.0-dev.1",
13
13
  "bignumber.js": "^9.3.1",
14
14
  "buffer": "^6.0.3"
15
15
  },
@@ -47,5 +47,5 @@
47
47
  "test:single": "ts-mocha -p ./tsconfig.json -t 1000000000"
48
48
  },
49
49
  "types": "dist/index.d.ts",
50
- "version": "5.1.3"
50
+ "version": "5.2.0-dev.1"
51
51
  }