@streamflow/stream 7.5.3 → 8.0.0-alpha.p287.5172056

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.
Files changed (154) hide show
  1. package/dist/cjs/BaseStreamClient-CQOC8m8V.d.cts +542 -0
  2. package/dist/cjs/aptos/index.cjs +456 -0
  3. package/dist/cjs/aptos/index.cjs.map +1 -0
  4. package/dist/cjs/aptos/index.d.cts +14 -0
  5. package/dist/cjs/evm/index.cjs +1915 -0
  6. package/dist/cjs/evm/index.cjs.map +1 -0
  7. package/dist/cjs/evm/index.d.cts +13 -0
  8. package/dist/cjs/index-CYu6i--S.d.cts +136 -0
  9. package/dist/cjs/index-DUVcpIhD.d.cts +203 -0
  10. package/dist/cjs/index-b7Qo5mCj.d.cts +664 -0
  11. package/dist/cjs/index-fNLnPKzv.d.cts +213 -0
  12. package/dist/cjs/index.cjs +7189 -0
  13. package/dist/cjs/index.cjs.map +1 -0
  14. package/dist/cjs/index.d.cts +192 -0
  15. package/dist/cjs/solana/descriptor/streamflow_aligned_unlocks.cjs +4 -0
  16. package/dist/cjs/solana/descriptor/streamflow_aligned_unlocks.cjs.map +1 -0
  17. package/dist/cjs/solana/descriptor/streamflow_aligned_unlocks.d.cts +1234 -0
  18. package/dist/cjs/solana/index.cjs +3749 -0
  19. package/dist/cjs/solana/index.cjs.map +1 -0
  20. package/dist/cjs/solana/index.d.cts +17 -0
  21. package/dist/cjs/sui/index.cjs +1021 -0
  22. package/dist/cjs/sui/index.cjs.map +1 -0
  23. package/dist/cjs/sui/index.d.cts +13 -0
  24. package/dist/esm/BaseStreamClient-CQOC8m8V.d.ts +542 -0
  25. package/dist/esm/aptos/index.d.ts +14 -4
  26. package/dist/esm/aptos/index.js +443 -4
  27. package/dist/esm/aptos/index.js.map +1 -0
  28. package/dist/esm/evm/index.d.ts +13 -5
  29. package/dist/esm/evm/index.js +1902 -5
  30. package/dist/esm/evm/index.js.map +1 -0
  31. package/dist/esm/index-BEo0O2IG.d.ts +664 -0
  32. package/dist/esm/index-CWmb3-x9.d.ts +136 -0
  33. package/dist/esm/index-Cgv37xlG.d.ts +213 -0
  34. package/dist/esm/index-D6QYg8hn.d.ts +203 -0
  35. package/dist/esm/index.d.ts +192 -10
  36. package/dist/esm/index.js +7096 -10
  37. package/dist/esm/index.js.map +1 -0
  38. package/dist/esm/solana/descriptor/idl/streamflow_aligned_unlocks.json +917 -1368
  39. package/dist/esm/solana/descriptor/streamflow_aligned_unlocks.d.ts +3 -1
  40. package/dist/esm/solana/descriptor/streamflow_aligned_unlocks.js +3 -1
  41. package/dist/esm/solana/descriptor/streamflow_aligned_unlocks.js.map +1 -0
  42. package/dist/esm/solana/index.d.ts +17 -7
  43. package/dist/esm/solana/index.js +3693 -7
  44. package/dist/esm/solana/index.js.map +1 -0
  45. package/dist/esm/sui/index.d.ts +13 -4
  46. package/dist/esm/sui/index.js +1011 -4
  47. package/dist/esm/sui/index.js.map +1 -0
  48. package/package.json +57 -27
  49. package/dist/cjs/__tests__/aptos/streamClient.spec.js +0 -111
  50. package/dist/cjs/__tests__/common/GenericStreamClient.spec.js +0 -45
  51. package/dist/cjs/aptos/StreamClient.js +0 -226
  52. package/dist/cjs/aptos/constants.js +0 -27
  53. package/dist/cjs/aptos/index.js +0 -38
  54. package/dist/cjs/aptos/types.js +0 -69
  55. package/dist/cjs/aptos/utils.js +0 -34
  56. package/dist/cjs/aptos/wallet.js +0 -34
  57. package/dist/cjs/common/BaseStreamClient.js +0 -23
  58. package/dist/cjs/common/GenericStreamClient.js +0 -102
  59. package/dist/cjs/common/constants.js +0 -10
  60. package/dist/cjs/common/contractUtils.js +0 -77
  61. package/dist/cjs/common/types.js +0 -141
  62. package/dist/cjs/common/utils.js +0 -69
  63. package/dist/cjs/evm/StreamClient.js +0 -238
  64. package/dist/cjs/evm/abi.js +0 -1257
  65. package/dist/cjs/evm/constants.js +0 -38
  66. package/dist/cjs/evm/ercAbi.js +0 -224
  67. package/dist/cjs/evm/index.js +0 -40
  68. package/dist/cjs/evm/types.js +0 -66
  69. package/dist/cjs/evm/utils.js +0 -11
  70. package/dist/cjs/index.js +0 -43
  71. package/dist/cjs/solana/StreamClient.js +0 -1042
  72. package/dist/cjs/solana/constants.js +0 -95
  73. package/dist/cjs/solana/descriptor/idl/streamflow_aligned_unlocks.json +0 -1437
  74. package/dist/cjs/solana/descriptor/streamflow_aligned_unlocks.js +0 -2
  75. package/dist/cjs/solana/index.js +0 -40
  76. package/dist/cjs/solana/instructionTypes.js +0 -2
  77. package/dist/cjs/solana/instructions.js +0 -298
  78. package/dist/cjs/solana/layout.js +0 -182
  79. package/dist/cjs/solana/lib/derive-accounts.js +0 -17
  80. package/dist/cjs/solana/lib/utils.js +0 -127
  81. package/dist/cjs/solana/timelockIDL.js +0 -422
  82. package/dist/cjs/solana/types.js +0 -93
  83. package/dist/cjs/sui/StreamClient.js +0 -416
  84. package/dist/cjs/sui/constants.js +0 -42
  85. package/dist/cjs/sui/index.js +0 -37
  86. package/dist/cjs/sui/types.js +0 -68
  87. package/dist/cjs/sui/utils.js +0 -46
  88. package/dist/cjs/sui/wallet.js +0 -40
  89. package/dist/esm/__tests__/aptos/streamClient.spec.d.ts +0 -1
  90. package/dist/esm/__tests__/aptos/streamClient.spec.js +0 -106
  91. package/dist/esm/__tests__/common/GenericStreamClient.spec.d.ts +0 -1
  92. package/dist/esm/__tests__/common/GenericStreamClient.spec.js +0 -40
  93. package/dist/esm/aptos/StreamClient.d.ts +0 -53
  94. package/dist/esm/aptos/StreamClient.js +0 -226
  95. package/dist/esm/aptos/constants.d.ts +0 -8
  96. package/dist/esm/aptos/constants.js +0 -24
  97. package/dist/esm/aptos/types.d.ts +0 -109
  98. package/dist/esm/aptos/types.js +0 -105
  99. package/dist/esm/aptos/utils.d.ts +0 -7
  100. package/dist/esm/aptos/utils.js +0 -30
  101. package/dist/esm/aptos/wallet.d.ts +0 -9
  102. package/dist/esm/aptos/wallet.js +0 -33
  103. package/dist/esm/common/BaseStreamClient.d.ts +0 -22
  104. package/dist/esm/common/BaseStreamClient.js +0 -19
  105. package/dist/esm/common/GenericStreamClient.d.ts +0 -72
  106. package/dist/esm/common/GenericStreamClient.js +0 -101
  107. package/dist/esm/common/constants.d.ts +0 -4
  108. package/dist/esm/common/constants.js +0 -4
  109. package/dist/esm/common/contractUtils.d.ts +0 -63
  110. package/dist/esm/common/contractUtils.js +0 -61
  111. package/dist/esm/common/types.d.ts +0 -353
  112. package/dist/esm/common/types.js +0 -135
  113. package/dist/esm/common/utils.d.ts +0 -32
  114. package/dist/esm/common/utils.js +0 -59
  115. package/dist/esm/evm/StreamClient.d.ts +0 -32
  116. package/dist/esm/evm/StreamClient.js +0 -237
  117. package/dist/esm/evm/abi.d.ts +0 -111
  118. package/dist/esm/evm/abi.js +0 -1255
  119. package/dist/esm/evm/constants.d.ts +0 -20
  120. package/dist/esm/evm/constants.js +0 -35
  121. package/dist/esm/evm/ercAbi.d.ts +0 -39
  122. package/dist/esm/evm/ercAbi.js +0 -222
  123. package/dist/esm/evm/types.d.ts +0 -98
  124. package/dist/esm/evm/types.js +0 -102
  125. package/dist/esm/evm/utils.d.ts +0 -1
  126. package/dist/esm/evm/utils.js +0 -8
  127. package/dist/esm/solana/StreamClient.d.ts +0 -150
  128. package/dist/esm/solana/StreamClient.js +0 -1017
  129. package/dist/esm/solana/constants.d.ts +0 -70
  130. package/dist/esm/solana/constants.js +0 -92
  131. package/dist/esm/solana/instructionTypes.d.ts +0 -101
  132. package/dist/esm/solana/instructionTypes.js +0 -1
  133. package/dist/esm/solana/instructions.d.ts +0 -142
  134. package/dist/esm/solana/instructions.js +0 -265
  135. package/dist/esm/solana/layout.d.ts +0 -27
  136. package/dist/esm/solana/layout.js +0 -155
  137. package/dist/esm/solana/lib/derive-accounts.d.ts +0 -4
  138. package/dist/esm/solana/lib/derive-accounts.js +0 -11
  139. package/dist/esm/solana/lib/utils.d.ts +0 -22
  140. package/dist/esm/solana/lib/utils.js +0 -117
  141. package/dist/esm/solana/timelockIDL.d.ts +0 -22
  142. package/dist/esm/solana/timelockIDL.js +0 -420
  143. package/dist/esm/solana/types.d.ts +0 -180
  144. package/dist/esm/solana/types.js +0 -142
  145. package/dist/esm/sui/StreamClient.d.ts +0 -82
  146. package/dist/esm/sui/StreamClient.js +0 -417
  147. package/dist/esm/sui/constants.d.ts +0 -10
  148. package/dist/esm/sui/constants.js +0 -39
  149. package/dist/esm/sui/types.d.ts +0 -167
  150. package/dist/esm/sui/types.js +0 -104
  151. package/dist/esm/sui/utils.d.ts +0 -11
  152. package/dist/esm/sui/utils.js +0 -39
  153. package/dist/esm/sui/wallet.d.ts +0 -17
  154. package/dist/esm/sui/wallet.js +0 -38
@@ -0,0 +1,3749 @@
1
+ 'use strict';
2
+
3
+ var BN4 = require('bn.js');
4
+ var bs58 = require('bs58');
5
+ var buffer = require('buffer');
6
+ var splToken = require('@solana/spl-token');
7
+ var web3_js = require('@solana/web3.js');
8
+ var solana = require('@streamflow/common/solana');
9
+ var borsh = require('borsh');
10
+ var anchor = require('@coral-xyz/anchor');
11
+ var common = require('@streamflow/common');
12
+ var BufferLayout = require('@solana/buffer-layout');
13
+
14
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
15
+
16
+ function _interopNamespace(e) {
17
+ if (e && e.__esModule) return e;
18
+ var n = Object.create(null);
19
+ if (e) {
20
+ Object.keys(e).forEach(function (k) {
21
+ if (k !== 'default') {
22
+ var d = Object.getOwnPropertyDescriptor(e, k);
23
+ Object.defineProperty(n, k, d.get ? d : {
24
+ enumerable: true,
25
+ get: function () { return e[k]; }
26
+ });
27
+ }
28
+ });
29
+ }
30
+ n.default = e;
31
+ return Object.freeze(n);
32
+ }
33
+
34
+ var BN4__default = /*#__PURE__*/_interopDefault(BN4);
35
+ var bs58__default = /*#__PURE__*/_interopDefault(bs58);
36
+ var borsh__namespace = /*#__PURE__*/_interopNamespace(borsh);
37
+ var BufferLayout__namespace = /*#__PURE__*/_interopNamespace(BufferLayout);
38
+
39
+ var __defProp = Object.defineProperty;
40
+ var __export = (target, all) => {
41
+ for (var name in all)
42
+ __defProp(target, name, { get: all[name], enumerable: true });
43
+ };
44
+ var MAX_SAFE_UNIX_TIME_VALUE = 864e10;
45
+ var WITHDRAW_AVAILABLE_AMOUNT = new BN4__default.default("18446744073709551615");
46
+
47
+ // common/contractUtils.ts
48
+ var calculateUnlockedAmount = ({
49
+ depositedAmount,
50
+ cliff,
51
+ cliffAmount,
52
+ end,
53
+ currentTimestamp,
54
+ lastRateChangeTime,
55
+ period,
56
+ amountPerPeriod,
57
+ fundsUnlockedAtLastRateChange
58
+ }) => {
59
+ const deposited = depositedAmount;
60
+ if (currentTimestamp < cliff) return new BN4__default.default(0);
61
+ if (currentTimestamp > end) return deposited;
62
+ const savedUnlockedFunds = lastRateChangeTime === 0 ? cliffAmount : fundsUnlockedAtLastRateChange;
63
+ const savedUnlockedFundsTime = lastRateChangeTime === 0 ? cliff : lastRateChangeTime;
64
+ const streamed = new BN4__default.default(Math.floor((currentTimestamp - savedUnlockedFundsTime) / period)).mul(amountPerPeriod).add(savedUnlockedFunds);
65
+ return streamed.lt(deposited) ? streamed : deposited;
66
+ };
67
+ var isCliffCloseToDepositedAmount = (streamData) => {
68
+ return streamData.cliffAmount.gte(streamData.depositedAmount.sub(new BN4__default.default(1)));
69
+ };
70
+ var isVesting = (streamData) => {
71
+ return !streamData.canTopup && !isCliffCloseToDepositedAmount(streamData) && !isDynamicLock(streamData.minPrice, streamData.maxPrice, streamData.minPercentage, streamData.maxPercentage);
72
+ };
73
+ var isCreateAlignedStreamData = (obj) => {
74
+ return "minPrice" in obj && "maxPrice" in obj && "minPercentage" in obj && "maxPercentage" in obj;
75
+ };
76
+ var isDynamicLock = (minPrice, maxPrice, minPercentage, maxPercentage) => {
77
+ return !!minPrice && !!maxPrice && minPrice > 0 && maxPrice - minPrice <= 1 && minPercentage === 0 && maxPercentage === 100;
78
+ };
79
+ var isTokenLock = (streamData) => {
80
+ return !streamData.canTopup && !streamData.automaticWithdrawal && !streamData.cancelableBySender && !streamData.cancelableByRecipient && !streamData.transferableBySender && !streamData.transferableByRecipient && (isCliffCloseToDepositedAmount(streamData) || isDynamicLock(streamData.minPrice, streamData.maxPrice, streamData.minPercentage, streamData.maxPercentage));
81
+ };
82
+ var buildStreamType = (streamData) => {
83
+ if (isVesting(streamData)) {
84
+ return "vesting" /* Vesting */;
85
+ }
86
+ if (isTokenLock(streamData)) {
87
+ return "lock" /* Lock */;
88
+ }
89
+ return "payment" /* Payment */;
90
+ };
91
+ var decodeEndTime = (endTime) => {
92
+ if (endTime.gt(new BN4__default.default(MAX_SAFE_UNIX_TIME_VALUE))) {
93
+ return MAX_SAFE_UNIX_TIME_VALUE;
94
+ }
95
+ return endTime.toNumber();
96
+ };
97
+ var FEE_PRECISION = 4;
98
+ var FEE_NORMALIZER = 10 ** FEE_PRECISION;
99
+ var FEE_MULTIPLIER = new BN4__default.default(10 ** 6);
100
+ var getNumberFromBN = (value, decimals) => value.gt(new BN4__default.default(2 ** 53 - 1)) ? value.div(new BN4__default.default(10 ** decimals)).toNumber() : value.toNumber() / 10 ** decimals;
101
+ var calculateTotalAmountToDeposit = (depositedAmount, totalFee) => {
102
+ const totalFeeNormalized = new BN4__default.default(totalFee * FEE_NORMALIZER);
103
+ return depositedAmount.mul(totalFeeNormalized.add(FEE_MULTIPLIER)).div(FEE_MULTIPLIER);
104
+ };
105
+
106
+ // solana/constants.ts
107
+ var constants_exports = {};
108
+ __export(constants_exports, {
109
+ AIRDROP_AMOUNT: () => AIRDROP_AMOUNT,
110
+ AIRDROP_TEST_TOKEN: () => AIRDROP_TEST_TOKEN,
111
+ ALIGNED_COMPUTE_LIMIT: () => ALIGNED_COMPUTE_LIMIT,
112
+ ALIGNED_PRECISION_FACTOR_POW: () => ALIGNED_PRECISION_FACTOR_POW,
113
+ ALIGNED_UNLOCKS_PROGRAM_ID: () => ALIGNED_UNLOCKS_PROGRAM_ID,
114
+ CONTRACT_DISCRIMINATOR: () => CONTRACT_DISCRIMINATOR,
115
+ CONTRACT_SEED: () => CONTRACT_SEED,
116
+ CREATE_PARAMS_PADDING: () => CREATE_PARAMS_PADDING,
117
+ DEFAULT_STREAMFLOW_FEE: () => DEFAULT_STREAMFLOW_FEE,
118
+ ESCROW_SEED: () => ESCROW_SEED,
119
+ FEES_METADATA_SEED: () => FEES_METADATA_SEED,
120
+ FEE_ORACLE_PUBLIC_KEY: () => FEE_ORACLE_PUBLIC_KEY,
121
+ ORIGINAL_CONTRACT_SENDER_OFFSET: () => ORIGINAL_CONTRACT_SENDER_OFFSET,
122
+ PARTNERS_SCHEMA: () => PARTNERS_SCHEMA,
123
+ PARTNER_ORACLE_PROGRAM_ID: () => PARTNER_ORACLE_PROGRAM_ID,
124
+ PARTNER_SCHEMA: () => PARTNER_SCHEMA,
125
+ PROGRAM_ID: () => PROGRAM_ID,
126
+ SOLANA_ERROR_MAP: () => SOLANA_ERROR_MAP,
127
+ SOLANA_ERROR_MATCH_REGEX: () => SOLANA_ERROR_MATCH_REGEX,
128
+ STREAMFLOW_TREASURY_PUBLIC_KEY: () => STREAMFLOW_TREASURY_PUBLIC_KEY,
129
+ STREAM_STRUCT_OFFSETS: () => STREAM_STRUCT_OFFSETS,
130
+ STREAM_STRUCT_OFFSET_CLOSED: () => STREAM_STRUCT_OFFSET_CLOSED,
131
+ STREAM_STRUCT_OFFSET_MINT: () => STREAM_STRUCT_OFFSET_MINT,
132
+ STREAM_STRUCT_OFFSET_RECIPIENT: () => STREAM_STRUCT_OFFSET_RECIPIENT,
133
+ STREAM_STRUCT_OFFSET_SENDER: () => STREAM_STRUCT_OFFSET_SENDER,
134
+ TEST_ORACLE_DISCRIMINATOR: () => TEST_ORACLE_DISCRIMINATOR,
135
+ TEST_ORACLE_SEED: () => TEST_ORACLE_SEED,
136
+ TX_FINALITY_CONFIRMED: () => TX_FINALITY_CONFIRMED,
137
+ WITHDRAWOR_PUBLIC_KEY: () => WITHDRAWOR_PUBLIC_KEY
138
+ });
139
+ var TX_FINALITY_CONFIRMED = "confirmed";
140
+ var ORIGINAL_CONTRACT_SENDER_OFFSET = 9;
141
+ var STREAM_STRUCT_OFFSET_SENDER = 49;
142
+ var STREAM_STRUCT_OFFSET_RECIPIENT = 113;
143
+ var STREAM_STRUCT_OFFSET_MINT = 177;
144
+ var STREAM_STRUCT_OFFSET_CLOSED = 671;
145
+ var ALIGNED_PRECISION_FACTOR_POW = 9;
146
+ var STREAM_STRUCT_OFFSETS = {
147
+ mint: STREAM_STRUCT_OFFSET_MINT,
148
+ recipient: STREAM_STRUCT_OFFSET_RECIPIENT,
149
+ sender: STREAM_STRUCT_OFFSET_SENDER,
150
+ closed: STREAM_STRUCT_OFFSET_CLOSED
151
+ };
152
+ var CREATE_PARAMS_PADDING = 126;
153
+ var PROGRAM_ID = {
154
+ [common.ICluster.Devnet]: "HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ",
155
+ [common.ICluster.Mainnet]: "strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m",
156
+ [common.ICluster.Testnet]: "HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ",
157
+ [common.ICluster.Local]: "HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ"
158
+ };
159
+ var ALIGNED_UNLOCKS_PROGRAM_ID = {
160
+ [common.ICluster.Devnet]: "aSTRM2NKoKxNnkmLWk9sz3k74gKBk9t7bpPrTGxMszH",
161
+ [common.ICluster.Mainnet]: "aSTRM2NKoKxNnkmLWk9sz3k74gKBk9t7bpPrTGxMszH",
162
+ [common.ICluster.Testnet]: "aSTRM2NKoKxNnkmLWk9sz3k74gKBk9t7bpPrTGxMszH",
163
+ [common.ICluster.Local]: "aSTRM2NKoKxNnkmLWk9sz3k74gKBk9t7bpPrTGxMszH"
164
+ };
165
+ var ALIGNED_COMPUTE_LIMIT = 3e5;
166
+ var CONTRACT_DISCRIMINATOR = [172, 138, 115, 242, 121, 67, 183, 26];
167
+ var TEST_ORACLE_DISCRIMINATOR = [198, 49, 63, 134, 232, 251, 168, 28];
168
+ var CONTRACT_SEED = buffer.Buffer.from("contract", "utf-8");
169
+ var ESCROW_SEED = buffer.Buffer.from("strm", "utf-8");
170
+ var TEST_ORACLE_SEED = buffer.Buffer.from("test-oracle", "utf-8");
171
+ var PARTNER_ORACLE_PROGRAM_ID = "pardpVtPjC8nLj1Dwncew62mUzfChdCX1EaoZe8oCAa";
172
+ var STREAMFLOW_TREASURY_PUBLIC_KEY = new web3_js.PublicKey("5SEpbdjFK5FxwTvfsGMXVQTD2v4M2c5tyRTxhdsPkgDw");
173
+ var WITHDRAWOR_PUBLIC_KEY = new web3_js.PublicKey("wdrwhnCv4pzW8beKsbPa4S2UDZrXenjg16KJdKSpb5u");
174
+ var FEE_ORACLE_PUBLIC_KEY = new web3_js.PublicKey("B743wFVk2pCYhV91cn287e1xY7f1vt4gdY48hhNiuQmT");
175
+ var AIRDROP_TEST_TOKEN = "Gssm3vfi8s65R31SBdmQRq6cKeYojGgup7whkw4VCiQj";
176
+ var FEES_METADATA_SEED = buffer.Buffer.from("strm_fees");
177
+ var DEFAULT_STREAMFLOW_FEE = 0.99;
178
+ var AIRDROP_AMOUNT = 1;
179
+ var PARTNER_SCHEMA = {
180
+ struct: {
181
+ pubkey: { array: { type: "u8", len: 32 } },
182
+ partner_fee: "f32",
183
+ strm_fee: "f32"
184
+ }
185
+ };
186
+ var PARTNERS_SCHEMA = { array: { type: PARTNER_SCHEMA } };
187
+ var SOLANA_ERROR_MATCH_REGEX = /custom program error: (0x\d{2})/;
188
+ var SOLANA_ERROR_MAP = {
189
+ 96: "AccountsNotWritable" /* AccountsNotWritable */,
190
+ 97: "InvalidMetadata" /* InvalidMetadata */,
191
+ 98: "InvalidMetadataAccount" /* InvalidMetadataAccount */,
192
+ 99: "MetadataAccountMismatch" /* MetadataAccountMismatch */,
193
+ 100: "InvalidEscrowAccount" /* InvalidEscrowAccount */,
194
+ 101: "NotAssociated" /* NotAssociated */,
195
+ 102: "MintMismatch" /* MintMismatch */,
196
+ 103: "TransferNotAllowed" /* TransferNotAllowed */,
197
+ 104: "ContractClosed" /* ContractClosed */,
198
+ 105: "InvalidTreasury" /* InvalidTreasury */,
199
+ 112: "InvalidTimestamps" /* InvalidTimestamps */,
200
+ 113: "InvalidDepositConfiguration" /* InvalidDepositConfiguration */,
201
+ 114: "AmountIsZero" /* AmountIsZero */,
202
+ 115: "AmountMoreThanAvailable" /* AmountMoreThanAvailable */,
203
+ 116: "AmountAvailableIsZero" /* AmountAvailableIsZero */,
204
+ 128: "ArithmeticError" /* ArithmeticError */,
205
+ 129: "InvalidMetadataSize" /* InvalidMetadataSize */,
206
+ 130: "UninitializedMetadata" /* UninitializedMetadata */,
207
+ 131: "Unauthorized" /* Unauthorized */,
208
+ 132: "SelfTransfer" /* SelfTransfer */,
209
+ 133: "AlreadyPaused" /* AlreadyPaused */,
210
+ 134: "NotPaused" /* NotPaused */,
211
+ 135: "MetadataNotRentExempt" /* MetadataNotRentExempt */,
212
+ 6e3: "Unauthorized" /* Unauthorized */,
213
+ 6001: "ArithmeticError" /* ArithmeticError */,
214
+ 6002: "UnsupportedTokenExtensions" /* UnsupportedTokenExtensions */,
215
+ 6003: "PeriodTooShort" /* PeriodTooShort */,
216
+ 6004: "InvalidTickSize" /* InvalidTickSize */,
217
+ 6005: "InvalidPercentageBoundaries" /* InvalidPercentageBoundaries */,
218
+ 6006: "InvalidPriceBoundaries" /* InvalidPriceBoundaries */,
219
+ 6007: "UnsupportedOracle" /* UnsupportedOracle */,
220
+ 6008: "InvalidOracleAccount" /* InvalidOracleAccount */,
221
+ 6009: "InvalidOraclePrice" /* InvalidOraclePrice */,
222
+ 6010: "InvalidStreamMetadata" /* InvalidStreamMetadata */,
223
+ 6011: "AmountAlreadyUpdated" /* AmountAlreadyUpdated */,
224
+ 6012: "AllFundsUnlocked" /* AllFundsUnlocked */
225
+ };
226
+ var Contract = class {
227
+ constructor(stream) {
228
+ this.magic = stream.magic.toNumber();
229
+ this.version = stream.version.toNumber();
230
+ this.createdAt = stream.createdAt.toNumber();
231
+ this.withdrawnAmount = stream.withdrawnAmount;
232
+ this.canceledAt = stream.canceledAt.toNumber();
233
+ this.end = decodeEndTime(stream.end);
234
+ this.lastWithdrawnAt = stream.lastWithdrawnAt.toNumber();
235
+ this.sender = stream.sender.toBase58();
236
+ this.senderTokens = stream.senderTokens.toBase58();
237
+ this.recipient = stream.recipient.toBase58();
238
+ this.recipientTokens = stream.recipientTokens.toBase58();
239
+ this.mint = stream.mint.toBase58();
240
+ this.escrowTokens = stream.escrowTokens.toBase58();
241
+ this.streamflowTreasury = stream.streamflowTreasury.toBase58();
242
+ this.streamflowTreasuryTokens = stream.streamflowTreasuryTokens.toBase58();
243
+ this.streamflowFeeTotal = stream.streamflowFeeTotal;
244
+ this.streamflowFeeWithdrawn = stream.streamflowFeeWithdrawn;
245
+ this.streamflowFeePercent = stream.streamflowFeePercent.toNumber();
246
+ this.partnerFeeTotal = stream.partnerFeeTotal;
247
+ this.partnerFeeWithdrawn = stream.partnerFeeWithdrawn;
248
+ this.partnerFeePercent = stream.partnerFeePercent.toNumber();
249
+ this.partner = stream.partner.toBase58();
250
+ this.partnerTokens = stream.partnerTokens?.toBase58();
251
+ this.start = stream.start.toNumber();
252
+ this.depositedAmount = stream.depositedAmount;
253
+ this.period = stream.period.toNumber();
254
+ this.amountPerPeriod = stream.amountPerPeriod;
255
+ this.cliff = stream.cliff.toNumber();
256
+ this.cliffAmount = stream.cliffAmount;
257
+ this.cancelableBySender = stream.cancelableBySender;
258
+ this.cancelableByRecipient = stream.cancelableByRecipient;
259
+ this.automaticWithdrawal = stream.automaticWithdrawal;
260
+ this.transferableBySender = stream.transferableBySender;
261
+ this.transferableByRecipient = stream.transferableByRecipient;
262
+ this.canTopup = stream.canTopup;
263
+ this.name = stream.name;
264
+ this.withdrawalFrequency = stream.withdrawFrequency.toNumber();
265
+ this.closed = stream.closed;
266
+ this.currentPauseStart = stream.currentPauseStart.toNumber();
267
+ this.pauseCumulative = stream.pauseCumulative;
268
+ this.lastRateChangeTime = stream.lastRateChangeTime.toNumber();
269
+ this.fundsUnlockedAtLastRateChange = stream.fundsUnlockedAtLastRateChange;
270
+ this.type = buildStreamType(this);
271
+ this.isAligned = false;
272
+ }
273
+ unlocked(currentTimestamp) {
274
+ return calculateUnlockedAmount({
275
+ ...this,
276
+ currentTimestamp
277
+ });
278
+ }
279
+ remaining(decimals) {
280
+ return getNumberFromBN(this.depositedAmount.sub(this.withdrawnAmount), decimals);
281
+ }
282
+ };
283
+ var AlignedContract = class extends Contract {
284
+ constructor(stream, alignedProxy) {
285
+ super(stream);
286
+ this.minPrice = getNumberFromBN(alignedProxy.minPrice, ALIGNED_PRECISION_FACTOR_POW);
287
+ this.maxPrice = getNumberFromBN(alignedProxy.maxPrice, ALIGNED_PRECISION_FACTOR_POW);
288
+ this.minPercentage = getNumberFromBN(alignedProxy.minPercentage, ALIGNED_PRECISION_FACTOR_POW);
289
+ this.maxPercentage = getNumberFromBN(alignedProxy.maxPercentage, ALIGNED_PRECISION_FACTOR_POW);
290
+ this.oracleType = Object.keys(alignedProxy.priceOracleType).find((key) => !!key) || "none";
291
+ this.tickSize = alignedProxy.tickSize.toNumber();
292
+ this.priceOracle = this.oracleType === "none" ? void 0 : alignedProxy.priceOracle.toBase58();
293
+ this.sender = alignedProxy.sender.toBase58();
294
+ this.canceledAt = alignedProxy.streamCanceledTime.toNumber();
295
+ this.proxyAddress = stream.sender.toBase58();
296
+ this.initialAmountPerPeriod = alignedProxy.initialAmountPerPeriod;
297
+ this.initialPrice = getNumberFromBN(alignedProxy.initialPrice, ALIGNED_PRECISION_FACTOR_POW);
298
+ this.lastPrice = getNumberFromBN(alignedProxy.lastPrice, ALIGNED_PRECISION_FACTOR_POW);
299
+ this.lastAmountUpdateTime = alignedProxy.lastAmountUpdateTime.toNumber();
300
+ this.initialNetAmount = alignedProxy.initialNetAmount;
301
+ this.type = buildStreamType(this);
302
+ this.isAligned = true;
303
+ }
304
+ };
305
+ var streamLayout = BufferLayout__namespace.struct([
306
+ BufferLayout__namespace.blob(8, "magic"),
307
+ BufferLayout__namespace.blob(1, "version"),
308
+ BufferLayout__namespace.blob(8, "created_at"),
309
+ BufferLayout__namespace.blob(8, "withdrawn_amount"),
310
+ BufferLayout__namespace.blob(8, "canceled_at"),
311
+ BufferLayout__namespace.blob(8, "end_time"),
312
+ BufferLayout__namespace.blob(8, "last_withdrawn_at"),
313
+ BufferLayout__namespace.blob(32, "sender"),
314
+ BufferLayout__namespace.blob(32, "sender_tokens"),
315
+ BufferLayout__namespace.blob(32, "recipient"),
316
+ BufferLayout__namespace.blob(32, "recipient_tokens"),
317
+ BufferLayout__namespace.blob(32, "mint"),
318
+ BufferLayout__namespace.blob(32, "escrow_tokens"),
319
+ BufferLayout__namespace.blob(32, "streamflow_treasury"),
320
+ BufferLayout__namespace.blob(32, "streamflow_treasury_tokens"),
321
+ BufferLayout__namespace.blob(8, "streamflow_fee_total"),
322
+ BufferLayout__namespace.blob(8, "streamflow_fee_withdrawn"),
323
+ BufferLayout__namespace.f32("streamflow_fee_percent"),
324
+ BufferLayout__namespace.blob(32, "partner"),
325
+ BufferLayout__namespace.blob(32, "partner_tokens"),
326
+ BufferLayout__namespace.blob(8, "partner_fee_total"),
327
+ BufferLayout__namespace.blob(8, "partner_fee_withdrawn"),
328
+ BufferLayout__namespace.f32("partner_fee_percent"),
329
+ BufferLayout__namespace.blob(8, "start_time"),
330
+ BufferLayout__namespace.blob(8, "net_amount_deposited"),
331
+ BufferLayout__namespace.blob(8, "period"),
332
+ BufferLayout__namespace.blob(8, "amount_per_period"),
333
+ BufferLayout__namespace.blob(8, "cliff"),
334
+ BufferLayout__namespace.blob(8, "cliff_amount"),
335
+ BufferLayout__namespace.u8("cancelable_by_sender"),
336
+ BufferLayout__namespace.u8("cancelable_by_recipient"),
337
+ BufferLayout__namespace.u8("automatic_withdrawal"),
338
+ BufferLayout__namespace.u8("transferable_by_sender"),
339
+ BufferLayout__namespace.u8("transferable_by_recipient"),
340
+ BufferLayout__namespace.u8("can_topup"),
341
+ BufferLayout__namespace.blob(64, "stream_name"),
342
+ BufferLayout__namespace.blob(8, "withdraw_frequency"),
343
+ // Unused, kept for backward compatibility™
344
+ BufferLayout__namespace.blob(4, "ghost"),
345
+ BufferLayout__namespace.u8("pausable"),
346
+ BufferLayout__namespace.u8("can_update_rate"),
347
+ BufferLayout__namespace.blob(4, "create_stream_params_padding_length"),
348
+ BufferLayout__namespace.seq(BufferLayout__namespace.u8(), CREATE_PARAMS_PADDING, "create_params_padding"),
349
+ BufferLayout__namespace.u8("closed"),
350
+ BufferLayout__namespace.blob(8, "current_pause_start"),
351
+ BufferLayout__namespace.blob(8, "pause_cumulative"),
352
+ BufferLayout__namespace.blob(8, "last_rate_change_time"),
353
+ BufferLayout__namespace.blob(8, "funds_unlocked_at_last_rate_change")
354
+ ]);
355
+ BufferLayout__namespace.struct([
356
+ BufferLayout__namespace.blob(32, "pubkey"),
357
+ BufferLayout__namespace.f32("partner_fee"),
358
+ BufferLayout__namespace.f32("strm_fee")
359
+ ]);
360
+ var createStreamLayout = BufferLayout__namespace.struct([
361
+ BufferLayout__namespace.blob(8, "start_time"),
362
+ BufferLayout__namespace.blob(8, "net_amount_deposited"),
363
+ BufferLayout__namespace.blob(8, "period"),
364
+ BufferLayout__namespace.blob(8, "amount_per_period"),
365
+ BufferLayout__namespace.blob(8, "cliff"),
366
+ BufferLayout__namespace.blob(8, "cliff_amount"),
367
+ BufferLayout__namespace.u8("cancelable_by_sender"),
368
+ BufferLayout__namespace.u8("cancelable_by_recipient"),
369
+ BufferLayout__namespace.u8("automatic_withdrawal"),
370
+ BufferLayout__namespace.u8("transferable_by_sender"),
371
+ BufferLayout__namespace.u8("transferable_by_recipient"),
372
+ BufferLayout__namespace.u8("can_topup"),
373
+ BufferLayout__namespace.blob(64, "stream_name"),
374
+ BufferLayout__namespace.blob(8, "withdraw_frequency"),
375
+ // discriminator for optional field
376
+ BufferLayout__namespace.u8("_pausable_discriminator"),
377
+ BufferLayout__namespace.u8("pausable"),
378
+ // discriminator for optional field
379
+ BufferLayout__namespace.u8("_can_update_rate_discriminator"),
380
+ BufferLayout__namespace.u8("can_update_rate")
381
+ ]);
382
+ var createUncheckedStreamLayout = BufferLayout__namespace.struct([
383
+ BufferLayout__namespace.blob(8, "start_time"),
384
+ BufferLayout__namespace.blob(8, "net_amount_deposited"),
385
+ BufferLayout__namespace.blob(8, "period"),
386
+ BufferLayout__namespace.blob(8, "amount_per_period"),
387
+ BufferLayout__namespace.blob(8, "cliff"),
388
+ BufferLayout__namespace.blob(8, "cliff_amount"),
389
+ BufferLayout__namespace.u8("cancelable_by_sender"),
390
+ BufferLayout__namespace.u8("cancelable_by_recipient"),
391
+ BufferLayout__namespace.u8("automatic_withdrawal"),
392
+ BufferLayout__namespace.u8("transferable_by_sender"),
393
+ BufferLayout__namespace.u8("transferable_by_recipient"),
394
+ BufferLayout__namespace.u8("can_topup"),
395
+ BufferLayout__namespace.blob(64, "stream_name"),
396
+ BufferLayout__namespace.blob(8, "withdraw_frequency"),
397
+ BufferLayout__namespace.blob(32, "recipient"),
398
+ BufferLayout__namespace.blob(32, "partner"),
399
+ BufferLayout__namespace.u8("pausable"),
400
+ BufferLayout__namespace.u8("can_update_rate")
401
+ ]);
402
+ var withdrawStreamLayout = BufferLayout__namespace.struct([
403
+ BufferLayout__namespace.blob(8, "amount")
404
+ ]);
405
+ var encodeUpdateStream = (values, data) => {
406
+ const structs = [];
407
+ if (values.enable_automatic_withdrawal) {
408
+ structs.push(BufferLayout__namespace.u8("enable_automatic_withdrawal_exists"));
409
+ structs.push(BufferLayout__namespace.u8("enable_automatic_withdrawal"));
410
+ } else {
411
+ structs.push(BufferLayout__namespace.u8("enable_automatic_withdrawal_exists"));
412
+ }
413
+ if (values.withdraw_frequency) {
414
+ structs.push(BufferLayout__namespace.u8("withdraw_frequency_exists"));
415
+ structs.push(BufferLayout__namespace.blob(8, "withdraw_frequency"));
416
+ } else {
417
+ structs.push(BufferLayout__namespace.u8("withdraw_frequency_exists"));
418
+ }
419
+ if (values.amount_per_period) {
420
+ structs.push(BufferLayout__namespace.u8("amount_per_period_exists"));
421
+ structs.push(BufferLayout__namespace.blob(8, "amount_per_period"));
422
+ } else {
423
+ structs.push(BufferLayout__namespace.u8("amount_per_period_exists"));
424
+ }
425
+ return BufferLayout__namespace.struct(structs).encode(
426
+ {
427
+ enable_automatic_withdrawal_exists: values.enable_automatic_withdrawal ? 1 : 0,
428
+ enable_automatic_withdrawal: values.enable_automatic_withdrawal ?? 0,
429
+ withdraw_frequency_exists: values.withdraw_frequency ? 1 : 0,
430
+ withdraw_frequency: values.withdraw_frequency ?? 0,
431
+ amount_per_period_exists: values.amount_per_period ? 1 : 0,
432
+ amount_per_period: values.amount_per_period ?? 0
433
+ },
434
+ data
435
+ );
436
+ };
437
+ var topupStreamLayout = BufferLayout__namespace.struct([
438
+ BufferLayout__namespace.blob(8, "amount")
439
+ ]);
440
+
441
+ // solana/lib/utils.ts
442
+ var decoder = new TextDecoder("utf-8");
443
+ var LE = "le";
444
+ var decodeStream = (buf) => {
445
+ const raw = streamLayout.decode(buf);
446
+ return {
447
+ magic: new BN4__default.default(raw.magic, LE),
448
+ version: new BN4__default.default(raw.version, LE),
449
+ createdAt: new BN4__default.default(raw.created_at, LE),
450
+ withdrawnAmount: new BN4__default.default(raw.withdrawn_amount, LE),
451
+ canceledAt: new BN4__default.default(raw.canceled_at, LE),
452
+ end: new BN4__default.default(raw.end_time, LE),
453
+ lastWithdrawnAt: new BN4__default.default(raw.last_withdrawn_at, LE),
454
+ sender: new web3_js.PublicKey(raw.sender),
455
+ senderTokens: new web3_js.PublicKey(raw.sender_tokens),
456
+ recipient: new web3_js.PublicKey(raw.recipient),
457
+ recipientTokens: new web3_js.PublicKey(raw.recipient_tokens),
458
+ mint: new web3_js.PublicKey(raw.mint),
459
+ escrowTokens: new web3_js.PublicKey(raw.escrow_tokens),
460
+ streamflowTreasury: new web3_js.PublicKey(raw.streamflow_treasury),
461
+ streamflowTreasuryTokens: new web3_js.PublicKey(raw.streamflow_treasury_tokens),
462
+ streamflowFeeTotal: new BN4__default.default(raw.streamflow_fee_total, LE),
463
+ streamflowFeeWithdrawn: new BN4__default.default(raw.streamflow_fee_withdrawn, LE),
464
+ streamflowFeePercent: new BN4__default.default(raw.streamflow_fee_percent, LE),
465
+ partnerFeeTotal: new BN4__default.default(raw.partner_fee_total, LE),
466
+ partnerFeeWithdrawn: new BN4__default.default(raw.partner_fee_withdrawn, LE),
467
+ partnerFeePercent: new BN4__default.default(raw.partner_fee_percent, LE),
468
+ partner: new web3_js.PublicKey(raw.partner),
469
+ partnerTokens: new web3_js.PublicKey(raw.partner_tokens),
470
+ start: new BN4__default.default(raw.start_time, LE),
471
+ depositedAmount: new BN4__default.default(raw.net_amount_deposited, LE),
472
+ period: new BN4__default.default(raw.period, LE),
473
+ amountPerPeriod: new BN4__default.default(raw.amount_per_period, LE),
474
+ cliff: new BN4__default.default(raw.cliff, LE),
475
+ cliffAmount: new BN4__default.default(raw.cliff_amount, LE),
476
+ cancelableBySender: Boolean(raw.cancelable_by_sender),
477
+ cancelableByRecipient: Boolean(raw.cancelable_by_recipient),
478
+ automaticWithdrawal: Boolean(raw.automatic_withdrawal),
479
+ transferableBySender: Boolean(raw.transferable_by_sender),
480
+ transferableByRecipient: Boolean(raw.transferable_by_recipient),
481
+ canTopup: Boolean(raw.can_topup),
482
+ name: decoder.decode(raw.stream_name),
483
+ withdrawFrequency: new BN4__default.default(raw.withdraw_frequency, LE),
484
+ closed: Boolean(raw.closed),
485
+ currentPauseStart: new BN4__default.default(raw.current_pause_start, LE),
486
+ pauseCumulative: new BN4__default.default(raw.pause_cumulative, LE),
487
+ lastRateChangeTime: new BN4__default.default(raw.last_rate_change_time, LE),
488
+ fundsUnlockedAtLastRateChange: new BN4__default.default(raw.funds_unlocked_at_last_rate_change, LE)
489
+ };
490
+ };
491
+ async function signAllTransactionWithRecipients(sender, items) {
492
+ const isKeypair = solana.isSignerKeypair(sender);
493
+ const isWallet = solana.isSignerWallet(sender);
494
+ if (isKeypair) {
495
+ return items.map((t) => {
496
+ t.tx.sign([sender]);
497
+ return { tx: t.tx, recipient: t.recipient };
498
+ });
499
+ } else if (isWallet) {
500
+ const signedTxs = await sender.signAllTransactions(items.map((t) => t.tx));
501
+ return items.map((item, index) => ({
502
+ ...item,
503
+ tx: signedTxs[index]
504
+ }));
505
+ } else {
506
+ return [];
507
+ }
508
+ }
509
+ async function sendAndConfirmStreamRawTransaction(connection, batchItem, confirmationParams, throttleParams) {
510
+ try {
511
+ const completedTxSignature = await solana.executeTransaction(connection, batchItem.tx, confirmationParams, throttleParams);
512
+ return { ...batchItem, signature: completedTxSignature };
513
+ } catch (error) {
514
+ throw {
515
+ recipient: batchItem.recipient,
516
+ error
517
+ };
518
+ }
519
+ }
520
+ function extractSolanaErrorCode(errorText, logs) {
521
+ let match = SOLANA_ERROR_MATCH_REGEX.exec(errorText);
522
+ if (!match && logs) {
523
+ for (const logLine of logs) {
524
+ match = SOLANA_ERROR_MATCH_REGEX.exec(logLine);
525
+ if (match !== null) {
526
+ break;
527
+ }
528
+ }
529
+ }
530
+ if (!match) {
531
+ return null;
532
+ }
533
+ const errorCode = Number(match[1]);
534
+ return SOLANA_ERROR_MAP[errorCode] || null;
535
+ }
536
+ var sha256 = {
537
+ digest: async (data) => {
538
+ const dataBuffer = new TextEncoder().encode(data);
539
+ const hashBuffer = await globalThis.crypto.subtle.digest("SHA-256", dataBuffer);
540
+ return new Uint8Array(hashBuffer);
541
+ }
542
+ };
543
+ var createStreamInstruction = async (data, programId, accounts) => {
544
+ const keys = [
545
+ { pubkey: accounts.sender, isSigner: true, isWritable: true },
546
+ { pubkey: accounts.senderTokens, isSigner: false, isWritable: true },
547
+ { pubkey: accounts.recipient, isSigner: false, isWritable: true },
548
+ { pubkey: accounts.metadata, isSigner: true, isWritable: true },
549
+ { pubkey: accounts.escrowTokens, isSigner: false, isWritable: true },
550
+ { pubkey: accounts.recipientTokens, isSigner: false, isWritable: true },
551
+ {
552
+ pubkey: accounts.streamflowTreasury,
553
+ isSigner: false,
554
+ isWritable: true
555
+ },
556
+ {
557
+ pubkey: accounts.streamflowTreasuryTokens,
558
+ isSigner: false,
559
+ isWritable: true
560
+ },
561
+ { pubkey: accounts.withdrawor, isSigner: false, isWritable: true },
562
+ { pubkey: accounts.partner, isSigner: false, isWritable: true },
563
+ { pubkey: accounts.partnerTokens, isSigner: false, isWritable: true },
564
+ { pubkey: accounts.mint, isSigner: false, isWritable: false },
565
+ { pubkey: accounts.feeOracle, isSigner: false, isWritable: false },
566
+ { pubkey: accounts.rent, isSigner: false, isWritable: false },
567
+ { pubkey: accounts.timelockProgram, isSigner: false, isWritable: false },
568
+ { pubkey: accounts.tokenProgram, isSigner: false, isWritable: false },
569
+ {
570
+ pubkey: accounts.associatedTokenProgram,
571
+ isSigner: false,
572
+ isWritable: false
573
+ },
574
+ { pubkey: accounts.systemProgram, isSigner: false, isWritable: false }
575
+ ];
576
+ let bufferData = buffer.Buffer.alloc(createStreamLayout.span);
577
+ const encodedUIntArray = new TextEncoder().encode(data.name);
578
+ const streamNameBuffer = buffer.Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
579
+ const decodedData = {
580
+ start_time: data.start.toArrayLike(buffer.Buffer, "le", 8),
581
+ net_amount_deposited: data.depositedAmount.toArrayLike(buffer.Buffer, "le", 8),
582
+ period: data.period.toArrayLike(buffer.Buffer, "le", 8),
583
+ amount_per_period: data.amountPerPeriod.toArrayLike(buffer.Buffer, "le", 8),
584
+ cliff: data.cliff.toArrayLike(buffer.Buffer, "le", 8),
585
+ cliff_amount: data.cliffAmount.toArrayLike(buffer.Buffer, "le", 8),
586
+ cancelable_by_sender: Number(data.cancelableBySender),
587
+ cancelable_by_recipient: Number(data.cancelableByRecipient),
588
+ automatic_withdrawal: Number(data.automaticWithdrawal),
589
+ transferable_by_sender: Number(data.transferableBySender),
590
+ transferable_by_recipient: Number(data.transferableByRecipient),
591
+ can_topup: Number(data.canTopup),
592
+ _pausable_discriminator: 1,
593
+ can_update_rate: Number(data.canUpdateRate),
594
+ _can_update_rate_discriminator: 1,
595
+ pausable: Number(data.canPause),
596
+ stream_name: streamNameBuffer,
597
+ withdraw_frequency: data.withdrawFrequency.toArrayLike(buffer.Buffer, "le", 8)
598
+ };
599
+ const encodeLength = createStreamLayout.encode(decodedData, bufferData);
600
+ bufferData = bufferData.slice(0, encodeLength);
601
+ bufferData = buffer.Buffer.concat([
602
+ buffer.Buffer.from(await sha256.digest("global:create")).slice(0, 8),
603
+ bufferData,
604
+ buffer.Buffer.alloc(10)
605
+ ]);
606
+ return new web3_js.TransactionInstruction({
607
+ keys,
608
+ programId,
609
+ data: bufferData
610
+ });
611
+ };
612
+ var createUncheckedStreamInstruction = async (data, programId, accounts) => {
613
+ const keys = [
614
+ { pubkey: accounts.sender, isSigner: true, isWritable: true },
615
+ { pubkey: accounts.senderTokens, isSigner: false, isWritable: true },
616
+ { pubkey: accounts.metadata, isSigner: false, isWritable: true },
617
+ { pubkey: accounts.escrowTokens, isSigner: false, isWritable: true },
618
+ { pubkey: accounts.withdrawor, isSigner: false, isWritable: true },
619
+ { pubkey: accounts.mint, isSigner: false, isWritable: false },
620
+ { pubkey: accounts.feeOracle, isSigner: false, isWritable: false },
621
+ { pubkey: accounts.rent, isSigner: false, isWritable: false },
622
+ { pubkey: accounts.timelockProgram, isSigner: false, isWritable: false },
623
+ { pubkey: accounts.tokenProgram, isSigner: false, isWritable: false },
624
+ { pubkey: accounts.systemProgram, isSigner: false, isWritable: false }
625
+ ];
626
+ if (accounts.payer) {
627
+ keys.unshift({
628
+ pubkey: accounts.payer,
629
+ isSigner: true,
630
+ isWritable: true
631
+ });
632
+ }
633
+ let bufferData = buffer.Buffer.alloc(createUncheckedStreamLayout.span);
634
+ const encodedUIntArray = new TextEncoder().encode(data.name);
635
+ const streamNameBuffer = buffer.Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
636
+ const decodedData = {
637
+ start_time: data.start.toArrayLike(buffer.Buffer, "le", 8),
638
+ net_amount_deposited: data.depositedAmount.toArrayLike(buffer.Buffer, "le", 8),
639
+ period: data.period.toArrayLike(buffer.Buffer, "le", 8),
640
+ amount_per_period: data.amountPerPeriod.toArrayLike(buffer.Buffer, "le", 8),
641
+ cliff: data.cliff.toArrayLike(buffer.Buffer, "le", 8),
642
+ cliff_amount: data.cliffAmount.toArrayLike(buffer.Buffer, "le", 8),
643
+ cancelable_by_sender: Number(data.cancelableBySender),
644
+ cancelable_by_recipient: Number(data.cancelableByRecipient),
645
+ automatic_withdrawal: Number(data.automaticWithdrawal),
646
+ transferable_by_sender: Number(data.transferableBySender),
647
+ transferable_by_recipient: Number(data.transferableByRecipient),
648
+ can_topup: Number(data.canTopup),
649
+ stream_name: streamNameBuffer,
650
+ withdraw_frequency: data.withdrawFrequency.toArrayLike(buffer.Buffer, "le", 8),
651
+ recipient: data.recipient.toBuffer(),
652
+ partner: data.partner.toBuffer(),
653
+ pausable: Number(data.canPause),
654
+ can_update_rate: Number(data.canUpdateRate)
655
+ };
656
+ const encodeLength = createUncheckedStreamLayout.encode(decodedData, bufferData);
657
+ bufferData = bufferData.slice(0, encodeLength);
658
+ const digest = accounts.payer ? await sha256.digest("global:create_unchecked_with_payer") : await sha256.digest("global:create_unchecked");
659
+ bufferData = buffer.Buffer.concat([buffer.Buffer.from(digest).slice(0, 8), bufferData, buffer.Buffer.alloc(10)]);
660
+ return new web3_js.TransactionInstruction({
661
+ keys,
662
+ programId,
663
+ data: bufferData
664
+ });
665
+ };
666
+ var withdrawStreamInstruction = async (amount, programId, {
667
+ authority,
668
+ recipient,
669
+ recipientTokens,
670
+ metadata,
671
+ escrowTokens,
672
+ streamflowTreasury,
673
+ streamflowTreasuryTokens,
674
+ partner,
675
+ partnerTokens,
676
+ mint,
677
+ tokenProgram
678
+ }) => {
679
+ const keys = [
680
+ { pubkey: authority, isSigner: true, isWritable: true },
681
+ { pubkey: recipient, isSigner: false, isWritable: true },
682
+ { pubkey: recipientTokens, isSigner: false, isWritable: true },
683
+ { pubkey: metadata, isSigner: false, isWritable: true },
684
+ { pubkey: escrowTokens, isSigner: false, isWritable: true },
685
+ {
686
+ pubkey: streamflowTreasury,
687
+ isSigner: false,
688
+ isWritable: true
689
+ },
690
+ { pubkey: streamflowTreasuryTokens, isSigner: false, isWritable: true },
691
+ { pubkey: partner, isSigner: false, isWritable: true },
692
+ { pubkey: partnerTokens, isSigner: false, isWritable: true },
693
+ { pubkey: mint, isSigner: false, isWritable: true },
694
+ { pubkey: tokenProgram, isSigner: false, isWritable: false }
695
+ ];
696
+ let data = buffer.Buffer.alloc(withdrawStreamLayout.span);
697
+ const decodedData = { amount: amount.toArrayLike(buffer.Buffer, "le", 8) };
698
+ const encodeLength = withdrawStreamLayout.encode(decodedData, data);
699
+ data = data.slice(0, encodeLength);
700
+ data = buffer.Buffer.concat([buffer.Buffer.from(await sha256.digest("global:withdraw")).slice(0, 8), data, buffer.Buffer.alloc(10)]);
701
+ return new web3_js.TransactionInstruction({
702
+ keys,
703
+ programId,
704
+ data
705
+ });
706
+ };
707
+ var updateStreamInstruction = async (params, programId, { authority, metadata, withdrawor, systemProgram }) => {
708
+ const keys = [
709
+ { pubkey: authority, isSigner: true, isWritable: true },
710
+ { pubkey: metadata, isSigner: false, isWritable: true },
711
+ { pubkey: withdrawor, isSigner: false, isWritable: true },
712
+ { pubkey: systemProgram, isSigner: false, isWritable: false }
713
+ ];
714
+ let data = buffer.Buffer.alloc(100);
715
+ const decodedData = {
716
+ enable_automatic_withdrawal: Number(params.enableAutomaticWithdrawal),
717
+ withdraw_frequency: params.withdrawFrequency ? params.withdrawFrequency.toArrayLike(buffer.Buffer, "le", 8) : void 0,
718
+ amount_per_period: params.amountPerPeriod ? params.amountPerPeriod.toArrayLike(buffer.Buffer, "le", 8) : void 0
719
+ };
720
+ const encodeLength = encodeUpdateStream(decodedData, data);
721
+ data = data.slice(0, encodeLength);
722
+ data = buffer.Buffer.concat([buffer.Buffer.from(await sha256.digest("global:update")).slice(0, 8), data, buffer.Buffer.alloc(20)]);
723
+ return new web3_js.TransactionInstruction({
724
+ keys,
725
+ programId,
726
+ data
727
+ });
728
+ };
729
+ var cancelStreamInstruction = async (programId, {
730
+ authority,
731
+ sender,
732
+ senderTokens,
733
+ recipient,
734
+ recipientTokens,
735
+ metadata,
736
+ escrowTokens,
737
+ streamflowTreasury,
738
+ streamflowTreasuryTokens,
739
+ partner,
740
+ partnerTokens,
741
+ mint,
742
+ tokenProgram
743
+ }) => {
744
+ const keys = [
745
+ { pubkey: authority, isSigner: true, isWritable: false },
746
+ { pubkey: sender, isSigner: false, isWritable: true },
747
+ { pubkey: senderTokens, isSigner: false, isWritable: true },
748
+ { pubkey: recipient, isSigner: false, isWritable: true },
749
+ { pubkey: recipientTokens, isSigner: false, isWritable: true },
750
+ { pubkey: metadata, isSigner: false, isWritable: true },
751
+ { pubkey: escrowTokens, isSigner: false, isWritable: true },
752
+ {
753
+ pubkey: streamflowTreasury,
754
+ isSigner: false,
755
+ isWritable: true
756
+ },
757
+ { pubkey: streamflowTreasuryTokens, isSigner: false, isWritable: true },
758
+ { pubkey: partner, isSigner: false, isWritable: true },
759
+ { pubkey: partnerTokens, isSigner: false, isWritable: true },
760
+ { pubkey: mint, isSigner: false, isWritable: true },
761
+ { pubkey: tokenProgram, isSigner: false, isWritable: false }
762
+ ];
763
+ const data = buffer.Buffer.concat([buffer.Buffer.from(await sha256.digest("global:cancel")).slice(0, 8), buffer.Buffer.alloc(10)]);
764
+ return new web3_js.TransactionInstruction({
765
+ keys,
766
+ programId,
767
+ data
768
+ });
769
+ };
770
+ var transferStreamInstruction = async (programId, {
771
+ authority,
772
+ newRecipient,
773
+ newRecipientTokens,
774
+ metadata,
775
+ mint,
776
+ rent,
777
+ tokenProgram,
778
+ associatedTokenProgram,
779
+ systemProgram
780
+ }) => {
781
+ const keys = [
782
+ { pubkey: authority, isSigner: true, isWritable: true },
783
+ { pubkey: newRecipient, isSigner: false, isWritable: true },
784
+ { pubkey: newRecipientTokens, isSigner: false, isWritable: true },
785
+ { pubkey: metadata, isSigner: false, isWritable: true },
786
+ { pubkey: mint, isSigner: false, isWritable: false },
787
+ { pubkey: rent, isSigner: false, isWritable: false },
788
+ { pubkey: tokenProgram, isSigner: false, isWritable: false },
789
+ { pubkey: associatedTokenProgram, isSigner: false, isWritable: false },
790
+ { pubkey: systemProgram, isSigner: false, isWritable: false }
791
+ ];
792
+ const data = buffer.Buffer.concat([
793
+ buffer.Buffer.from(await sha256.digest("global:transfer_recipient")).slice(0, 8),
794
+ buffer.Buffer.alloc(10)
795
+ ]);
796
+ return new web3_js.TransactionInstruction({
797
+ keys,
798
+ programId,
799
+ data
800
+ });
801
+ };
802
+ var topupStreamInstruction = async (amount, programId, {
803
+ sender,
804
+ senderTokens,
805
+ metadata,
806
+ escrowTokens,
807
+ streamflowTreasury,
808
+ streamflowTreasuryTokens,
809
+ partner,
810
+ partnerTokens,
811
+ mint,
812
+ tokenProgram,
813
+ withdrawor,
814
+ systemProgram
815
+ }) => {
816
+ const keys = [
817
+ { pubkey: sender, isSigner: true, isWritable: true },
818
+ { pubkey: senderTokens, isSigner: false, isWritable: true },
819
+ { pubkey: metadata, isSigner: false, isWritable: true },
820
+ { pubkey: escrowTokens, isSigner: false, isWritable: true },
821
+ {
822
+ pubkey: streamflowTreasury,
823
+ isSigner: false,
824
+ isWritable: true
825
+ },
826
+ { pubkey: streamflowTreasuryTokens, isSigner: false, isWritable: true },
827
+ { pubkey: withdrawor, isSigner: false, isWritable: true },
828
+ { pubkey: partner, isSigner: false, isWritable: true },
829
+ { pubkey: partnerTokens, isSigner: false, isWritable: true },
830
+ { pubkey: mint, isSigner: false, isWritable: false },
831
+ { pubkey: tokenProgram, isSigner: false, isWritable: false },
832
+ { pubkey: systemProgram, isSigner: false, isWritable: false }
833
+ ];
834
+ let data = buffer.Buffer.alloc(topupStreamLayout.span);
835
+ const decodedData = { amount: amount.toArrayLike(buffer.Buffer, "le", 8) };
836
+ const encodeLength = topupStreamLayout.encode(decodedData, data);
837
+ data = data.slice(0, encodeLength);
838
+ data = buffer.Buffer.concat([buffer.Buffer.from(await sha256.digest("global:topup")).slice(0, 8), data, buffer.Buffer.alloc(10)]);
839
+ return new web3_js.TransactionInstruction({
840
+ keys,
841
+ programId,
842
+ data
843
+ });
844
+ };
845
+
846
+ // common/BaseStreamClient.ts
847
+ var BaseStreamClient = class {
848
+ /**
849
+ * Returns total fee percent, streamflow fees + partner fees
850
+ * @param getFeesData structure with address for which we need to derive fee, either sender or partner usually
851
+ * @param chainSpecificParams additional parameters required by chain client
852
+ * @returns fee as floating number, so if fee is 0.99%, it will return 0.99
853
+ */
854
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
855
+ async getTotalFee(getFeesData, chainSpecificParams) {
856
+ const fees = await this.getFees(getFeesData, chainSpecificParams);
857
+ if (fees) {
858
+ return fees.partnerFee + fees.streamflowFee;
859
+ }
860
+ return this.getDefaultStreamflowFee(chainSpecificParams);
861
+ }
862
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
863
+ extractErrorCode(err) {
864
+ return null;
865
+ }
866
+ };
867
+
868
+ // solana/descriptor/idl/streamflow_aligned_unlocks.json
869
+ var streamflow_aligned_unlocks_default = {
870
+ address: "aSTRM2NKoKxNnkmLWk9sz3k74gKBk9t7bpPrTGxMszH",
871
+ metadata: {
872
+ name: "streamflow_aligned_unlocks",
873
+ version: "1.1.1",
874
+ spec: "0.1.0",
875
+ description: "Proxy to update unlock amount within Streamflow vesting protocol according to Token performance and other metrics"
876
+ },
877
+ instructions: [
878
+ {
879
+ name: "cancel",
880
+ discriminator: [232, 219, 223, 41, 219, 236, 220, 190],
881
+ accounts: [
882
+ {
883
+ name: "sender",
884
+ writable: true,
885
+ signer: true
886
+ },
887
+ {
888
+ name: "sender_tokens",
889
+ docs: ["Associated token account address of `sender`."],
890
+ writable: true,
891
+ pda: {
892
+ seeds: [
893
+ {
894
+ kind: "account",
895
+ path: "sender"
896
+ },
897
+ {
898
+ kind: "account",
899
+ path: "token_program"
900
+ },
901
+ {
902
+ kind: "account",
903
+ path: "mint"
904
+ }
905
+ ],
906
+ program: {
907
+ kind: "const",
908
+ value: [
909
+ 140,
910
+ 151,
911
+ 37,
912
+ 143,
913
+ 78,
914
+ 36,
915
+ 137,
916
+ 241,
917
+ 187,
918
+ 61,
919
+ 16,
920
+ 41,
921
+ 20,
922
+ 142,
923
+ 13,
924
+ 131,
925
+ 11,
926
+ 90,
927
+ 19,
928
+ 153,
929
+ 218,
930
+ 255,
931
+ 16,
932
+ 132,
933
+ 4,
934
+ 142,
935
+ 123,
936
+ 216,
937
+ 219,
938
+ 233,
939
+ 248,
940
+ 89
941
+ ]
942
+ }
943
+ }
944
+ },
945
+ {
946
+ name: "recipient",
947
+ writable: true
948
+ },
949
+ {
950
+ name: "recipient_tokens",
951
+ docs: ["CHECK; Associated token account address of `recipient`."],
952
+ writable: true,
953
+ pda: {
954
+ seeds: [
955
+ {
956
+ kind: "account",
957
+ path: "recipient"
958
+ },
959
+ {
960
+ kind: "account",
961
+ path: "token_program"
962
+ },
963
+ {
964
+ kind: "account",
965
+ path: "mint"
966
+ }
967
+ ],
968
+ program: {
969
+ kind: "const",
970
+ value: [
971
+ 140,
972
+ 151,
973
+ 37,
974
+ 143,
975
+ 78,
976
+ 36,
977
+ 137,
978
+ 241,
979
+ 187,
980
+ 61,
981
+ 16,
982
+ 41,
983
+ 20,
984
+ 142,
985
+ 13,
986
+ 131,
987
+ 11,
988
+ 90,
989
+ 19,
990
+ 153,
991
+ 218,
992
+ 255,
993
+ 16,
994
+ 132,
995
+ 4,
996
+ 142,
997
+ 123,
998
+ 216,
999
+ 219,
1000
+ 233,
1001
+ 248,
1002
+ 89
1003
+ ]
1004
+ }
1005
+ }
1006
+ },
1007
+ {
1008
+ name: "proxy_metadata",
1009
+ docs: ["Proxy Contract"],
1010
+ writable: true,
1011
+ pda: {
1012
+ seeds: [
1013
+ {
1014
+ kind: "const",
1015
+ value: [99, 111, 110, 116, 114, 97, 99, 116]
1016
+ },
1017
+ {
1018
+ kind: "account",
1019
+ path: "stream_metadata"
1020
+ }
1021
+ ]
1022
+ }
1023
+ },
1024
+ {
1025
+ name: "proxy_tokens",
1026
+ writable: true,
1027
+ pda: {
1028
+ seeds: [
1029
+ {
1030
+ kind: "account",
1031
+ path: "proxy_metadata"
1032
+ },
1033
+ {
1034
+ kind: "account",
1035
+ path: "token_program"
1036
+ },
1037
+ {
1038
+ kind: "account",
1039
+ path: "mint"
1040
+ }
1041
+ ],
1042
+ program: {
1043
+ kind: "const",
1044
+ value: [
1045
+ 140,
1046
+ 151,
1047
+ 37,
1048
+ 143,
1049
+ 78,
1050
+ 36,
1051
+ 137,
1052
+ 241,
1053
+ 187,
1054
+ 61,
1055
+ 16,
1056
+ 41,
1057
+ 20,
1058
+ 142,
1059
+ 13,
1060
+ 131,
1061
+ 11,
1062
+ 90,
1063
+ 19,
1064
+ 153,
1065
+ 218,
1066
+ 255,
1067
+ 16,
1068
+ 132,
1069
+ 4,
1070
+ 142,
1071
+ 123,
1072
+ 216,
1073
+ 219,
1074
+ 233,
1075
+ 248,
1076
+ 89
1077
+ ]
1078
+ }
1079
+ }
1080
+ },
1081
+ {
1082
+ name: "stream_metadata",
1083
+ writable: true
1084
+ },
1085
+ {
1086
+ name: "escrow_tokens",
1087
+ writable: true
1088
+ },
1089
+ {
1090
+ name: "streamflow_treasury",
1091
+ writable: true
1092
+ },
1093
+ {
1094
+ name: "streamflow_treasury_tokens",
1095
+ writable: true,
1096
+ pda: {
1097
+ seeds: [
1098
+ {
1099
+ kind: "account",
1100
+ path: "streamflow_treasury"
1101
+ },
1102
+ {
1103
+ kind: "account",
1104
+ path: "token_program"
1105
+ },
1106
+ {
1107
+ kind: "account",
1108
+ path: "mint"
1109
+ }
1110
+ ],
1111
+ program: {
1112
+ kind: "const",
1113
+ value: [
1114
+ 140,
1115
+ 151,
1116
+ 37,
1117
+ 143,
1118
+ 78,
1119
+ 36,
1120
+ 137,
1121
+ 241,
1122
+ 187,
1123
+ 61,
1124
+ 16,
1125
+ 41,
1126
+ 20,
1127
+ 142,
1128
+ 13,
1129
+ 131,
1130
+ 11,
1131
+ 90,
1132
+ 19,
1133
+ 153,
1134
+ 218,
1135
+ 255,
1136
+ 16,
1137
+ 132,
1138
+ 4,
1139
+ 142,
1140
+ 123,
1141
+ 216,
1142
+ 219,
1143
+ 233,
1144
+ 248,
1145
+ 89
1146
+ ]
1147
+ }
1148
+ }
1149
+ },
1150
+ {
1151
+ name: "partner",
1152
+ writable: true
1153
+ },
1154
+ {
1155
+ name: "partner_tokens",
1156
+ writable: true,
1157
+ pda: {
1158
+ seeds: [
1159
+ {
1160
+ kind: "account",
1161
+ path: "partner"
1162
+ },
1163
+ {
1164
+ kind: "account",
1165
+ path: "token_program"
1166
+ },
1167
+ {
1168
+ kind: "account",
1169
+ path: "mint"
1170
+ }
1171
+ ],
1172
+ program: {
1173
+ kind: "const",
1174
+ value: [
1175
+ 140,
1176
+ 151,
1177
+ 37,
1178
+ 143,
1179
+ 78,
1180
+ 36,
1181
+ 137,
1182
+ 241,
1183
+ 187,
1184
+ 61,
1185
+ 16,
1186
+ 41,
1187
+ 20,
1188
+ 142,
1189
+ 13,
1190
+ 131,
1191
+ 11,
1192
+ 90,
1193
+ 19,
1194
+ 153,
1195
+ 218,
1196
+ 255,
1197
+ 16,
1198
+ 132,
1199
+ 4,
1200
+ 142,
1201
+ 123,
1202
+ 216,
1203
+ 219,
1204
+ 233,
1205
+ 248,
1206
+ 89
1207
+ ]
1208
+ }
1209
+ }
1210
+ },
1211
+ {
1212
+ name: "mint",
1213
+ docs: ["The SPL token mint account."],
1214
+ writable: true
1215
+ },
1216
+ {
1217
+ name: "streamflow_program",
1218
+ address: "strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m"
1219
+ },
1220
+ {
1221
+ name: "token_program",
1222
+ docs: ["The SPL program needed in case an associated account", "for the new recipient is being created."]
1223
+ }
1224
+ ],
1225
+ args: []
1226
+ },
1227
+ {
1228
+ name: "change_oracle",
1229
+ discriminator: [177, 227, 230, 103, 13, 72, 141, 248],
1230
+ accounts: [
1231
+ {
1232
+ name: "sender",
1233
+ writable: true,
1234
+ signer: true
1235
+ },
1236
+ {
1237
+ name: "proxy_metadata",
1238
+ docs: ["Proxy Contract"],
1239
+ writable: true
1240
+ },
1241
+ {
1242
+ name: "new_price_oracle"
1243
+ }
1244
+ ],
1245
+ args: [
1246
+ {
1247
+ name: "params",
1248
+ type: {
1249
+ defined: {
1250
+ name: "ChangeOracleParams"
1251
+ }
1252
+ }
1253
+ }
1254
+ ]
1255
+ },
1256
+ {
1257
+ name: "create",
1258
+ discriminator: [24, 30, 200, 40, 5, 28, 7, 119],
1259
+ accounts: [
1260
+ {
1261
+ name: "payer",
1262
+ docs: ["Rent payer"],
1263
+ writable: true,
1264
+ signer: true
1265
+ },
1266
+ {
1267
+ name: "sender",
1268
+ writable: true,
1269
+ signer: true
1270
+ },
1271
+ {
1272
+ name: "sender_tokens",
1273
+ docs: ["Associated token account address of `payer`."],
1274
+ writable: true,
1275
+ pda: {
1276
+ seeds: [
1277
+ {
1278
+ kind: "account",
1279
+ path: "sender"
1280
+ },
1281
+ {
1282
+ kind: "account",
1283
+ path: "token_program"
1284
+ },
1285
+ {
1286
+ kind: "account",
1287
+ path: "mint"
1288
+ }
1289
+ ],
1290
+ program: {
1291
+ kind: "const",
1292
+ value: [
1293
+ 140,
1294
+ 151,
1295
+ 37,
1296
+ 143,
1297
+ 78,
1298
+ 36,
1299
+ 137,
1300
+ 241,
1301
+ 187,
1302
+ 61,
1303
+ 16,
1304
+ 41,
1305
+ 20,
1306
+ 142,
1307
+ 13,
1308
+ 131,
1309
+ 11,
1310
+ 90,
1311
+ 19,
1312
+ 153,
1313
+ 218,
1314
+ 255,
1315
+ 16,
1316
+ 132,
1317
+ 4,
1318
+ 142,
1319
+ 123,
1320
+ 216,
1321
+ 219,
1322
+ 233,
1323
+ 248,
1324
+ 89
1325
+ ]
1326
+ }
1327
+ }
1328
+ },
1329
+ {
1330
+ name: "recipient"
1331
+ },
1332
+ {
1333
+ name: "recipient_tokens",
1334
+ pda: {
1335
+ seeds: [
1336
+ {
1337
+ kind: "account",
1338
+ path: "recipient"
1339
+ },
1340
+ {
1341
+ kind: "account",
1342
+ path: "token_program"
1343
+ },
1344
+ {
1345
+ kind: "account",
1346
+ path: "mint"
1347
+ }
1348
+ ],
1349
+ program: {
1350
+ kind: "const",
1351
+ value: [
1352
+ 140,
1353
+ 151,
1354
+ 37,
1355
+ 143,
1356
+ 78,
1357
+ 36,
1358
+ 137,
1359
+ 241,
1360
+ 187,
1361
+ 61,
1362
+ 16,
1363
+ 41,
1364
+ 20,
1365
+ 142,
1366
+ 13,
1367
+ 131,
1368
+ 11,
1369
+ 90,
1370
+ 19,
1371
+ 153,
1372
+ 218,
1373
+ 255,
1374
+ 16,
1375
+ 132,
1376
+ 4,
1377
+ 142,
1378
+ 123,
1379
+ 216,
1380
+ 219,
1381
+ 233,
1382
+ 248,
1383
+ 89
1384
+ ]
1385
+ }
1386
+ }
1387
+ },
1388
+ {
1389
+ name: "proxy_metadata",
1390
+ writable: true,
1391
+ pda: {
1392
+ seeds: [
1393
+ {
1394
+ kind: "const",
1395
+ value: [99, 111, 110, 116, 114, 97, 99, 116]
1396
+ },
1397
+ {
1398
+ kind: "account",
1399
+ path: "stream_metadata"
1400
+ }
1401
+ ]
1402
+ }
1403
+ },
1404
+ {
1405
+ name: "proxy_tokens",
1406
+ writable: true,
1407
+ pda: {
1408
+ seeds: [
1409
+ {
1410
+ kind: "account",
1411
+ path: "proxy_metadata"
1412
+ },
1413
+ {
1414
+ kind: "account",
1415
+ path: "token_program"
1416
+ },
1417
+ {
1418
+ kind: "account",
1419
+ path: "mint"
1420
+ }
1421
+ ],
1422
+ program: {
1423
+ kind: "const",
1424
+ value: [
1425
+ 140,
1426
+ 151,
1427
+ 37,
1428
+ 143,
1429
+ 78,
1430
+ 36,
1431
+ 137,
1432
+ 241,
1433
+ 187,
1434
+ 61,
1435
+ 16,
1436
+ 41,
1437
+ 20,
1438
+ 142,
1439
+ 13,
1440
+ 131,
1441
+ 11,
1442
+ 90,
1443
+ 19,
1444
+ 153,
1445
+ 218,
1446
+ 255,
1447
+ 16,
1448
+ 132,
1449
+ 4,
1450
+ 142,
1451
+ 123,
1452
+ 216,
1453
+ 219,
1454
+ 233,
1455
+ 248,
1456
+ 89
1457
+ ]
1458
+ }
1459
+ }
1460
+ },
1461
+ {
1462
+ name: "stream_metadata",
1463
+ writable: true,
1464
+ signer: true
1465
+ },
1466
+ {
1467
+ name: "escrow_tokens",
1468
+ writable: true
1469
+ },
1470
+ {
1471
+ name: "withdrawor",
1472
+ writable: true
1473
+ },
1474
+ {
1475
+ name: "partner"
1476
+ },
1477
+ {
1478
+ name: "mint"
1479
+ },
1480
+ {
1481
+ name: "fee_oracle"
1482
+ },
1483
+ {
1484
+ name: "price_oracle"
1485
+ },
1486
+ {
1487
+ name: "rent",
1488
+ address: "SysvarRent111111111111111111111111111111111"
1489
+ },
1490
+ {
1491
+ name: "streamflow_program",
1492
+ address: "strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m"
1493
+ },
1494
+ {
1495
+ name: "token_program"
1496
+ },
1497
+ {
1498
+ name: "associated_token_program",
1499
+ address: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
1500
+ },
1501
+ {
1502
+ name: "system_program",
1503
+ address: "11111111111111111111111111111111"
1504
+ }
1505
+ ],
1506
+ args: [
1507
+ {
1508
+ name: "ix",
1509
+ type: {
1510
+ defined: {
1511
+ name: "CreateParams"
1512
+ }
1513
+ }
1514
+ }
1515
+ ]
1516
+ },
1517
+ {
1518
+ name: "create_test_oracle",
1519
+ discriminator: [183, 110, 4, 11, 131, 220, 84, 12],
1520
+ accounts: [
1521
+ {
1522
+ name: "creator",
1523
+ writable: true,
1524
+ signer: true
1525
+ },
1526
+ {
1527
+ name: "mint"
1528
+ },
1529
+ {
1530
+ name: "test_oracle",
1531
+ writable: true,
1532
+ pda: {
1533
+ seeds: [
1534
+ {
1535
+ kind: "const",
1536
+ value: [116, 101, 115, 116, 45, 111, 114, 97, 99, 108, 101]
1537
+ },
1538
+ {
1539
+ kind: "account",
1540
+ path: "mint"
1541
+ },
1542
+ {
1543
+ kind: "account",
1544
+ path: "creator"
1545
+ }
1546
+ ]
1547
+ }
1548
+ },
1549
+ {
1550
+ name: "system_program",
1551
+ address: "11111111111111111111111111111111"
1552
+ }
1553
+ ],
1554
+ args: [
1555
+ {
1556
+ name: "params",
1557
+ type: {
1558
+ defined: {
1559
+ name: "CreateTestOracleParams"
1560
+ }
1561
+ }
1562
+ }
1563
+ ]
1564
+ },
1565
+ {
1566
+ name: "set_test_oracle_authority",
1567
+ discriminator: [26, 66, 233, 99, 38, 118, 181, 247],
1568
+ accounts: [
1569
+ {
1570
+ name: "authority",
1571
+ writable: true,
1572
+ signer: true
1573
+ },
1574
+ {
1575
+ name: "test_oracle",
1576
+ writable: true
1577
+ },
1578
+ {
1579
+ name: "new_authority"
1580
+ }
1581
+ ],
1582
+ args: []
1583
+ },
1584
+ {
1585
+ name: "update_amount",
1586
+ discriminator: [212, 178, 69, 133, 251, 180, 212, 71],
1587
+ accounts: [
1588
+ {
1589
+ name: "authority",
1590
+ docs: ["Wallet authorised to call this method"],
1591
+ writable: true,
1592
+ signer: true
1593
+ },
1594
+ {
1595
+ name: "proxy_metadata",
1596
+ writable: true,
1597
+ pda: {
1598
+ seeds: [
1599
+ {
1600
+ kind: "const",
1601
+ value: [99, 111, 110, 116, 114, 97, 99, 116]
1602
+ },
1603
+ {
1604
+ kind: "account",
1605
+ path: "stream_metadata"
1606
+ }
1607
+ ]
1608
+ }
1609
+ },
1610
+ {
1611
+ name: "stream_metadata",
1612
+ writable: true
1613
+ },
1614
+ {
1615
+ name: "withdrawor",
1616
+ writable: true
1617
+ },
1618
+ {
1619
+ name: "price_oracle",
1620
+ relations: ["proxy_metadata"]
1621
+ },
1622
+ {
1623
+ name: "streamflow_program",
1624
+ address: "strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m"
1625
+ },
1626
+ {
1627
+ name: "system_program",
1628
+ address: "11111111111111111111111111111111"
1629
+ }
1630
+ ],
1631
+ args: []
1632
+ },
1633
+ {
1634
+ name: "update_test_oracle",
1635
+ discriminator: [158, 147, 215, 74, 34, 123, 80, 76],
1636
+ accounts: [
1637
+ {
1638
+ name: "authority",
1639
+ writable: true,
1640
+ signer: true
1641
+ },
1642
+ {
1643
+ name: "test_oracle",
1644
+ writable: true
1645
+ }
1646
+ ],
1647
+ args: [
1648
+ {
1649
+ name: "params",
1650
+ type: {
1651
+ defined: {
1652
+ name: "UpdateTestOracleParams"
1653
+ }
1654
+ }
1655
+ }
1656
+ ]
1657
+ }
1658
+ ],
1659
+ accounts: [
1660
+ {
1661
+ name: "Contract",
1662
+ discriminator: [172, 138, 115, 242, 121, 67, 183, 26]
1663
+ },
1664
+ {
1665
+ name: "TestOracle",
1666
+ discriminator: [198, 49, 63, 134, 232, 251, 168, 28]
1667
+ }
1668
+ ],
1669
+ errors: [
1670
+ {
1671
+ code: 6e3,
1672
+ name: "Unauthorized",
1673
+ msg: "Authority does not have permission for this action"
1674
+ },
1675
+ {
1676
+ code: 6001,
1677
+ name: "ArithmeticError",
1678
+ msg: "Arithmetic error"
1679
+ },
1680
+ {
1681
+ code: 6002,
1682
+ name: "UnsupportedTokenExtensions",
1683
+ msg: "Mint has unsupported Token Extensions"
1684
+ },
1685
+ {
1686
+ code: 6003,
1687
+ name: "PeriodTooShort",
1688
+ msg: "Provided period is too short, should be equal or more than 30 seconds"
1689
+ },
1690
+ {
1691
+ code: 6004,
1692
+ name: "InvalidTickSize",
1693
+ msg: "Provided percentage tick size is invalid"
1694
+ },
1695
+ {
1696
+ code: 6005,
1697
+ name: "InvalidPercentageBoundaries",
1698
+ msg: "Provided percentage bounds are invalid"
1699
+ },
1700
+ {
1701
+ code: 6006,
1702
+ name: "InvalidPriceBoundaries",
1703
+ msg: "Provided price bounds are invalid"
1704
+ },
1705
+ {
1706
+ code: 6007,
1707
+ name: "UnsupportedOracle",
1708
+ msg: "Unsupported price oracle"
1709
+ },
1710
+ {
1711
+ code: 6008,
1712
+ name: "InvalidOracleAccount",
1713
+ msg: "Invalid oracle account"
1714
+ },
1715
+ {
1716
+ code: 6009,
1717
+ name: "InvalidOraclePrice",
1718
+ msg: "Invalid oracle price"
1719
+ },
1720
+ {
1721
+ code: 6010,
1722
+ name: "InvalidStreamMetadata",
1723
+ msg: "Invalid Stream Metadata"
1724
+ },
1725
+ {
1726
+ code: 6011,
1727
+ name: "AmountAlreadyUpdated",
1728
+ msg: "Release amount has already been updated in this period"
1729
+ },
1730
+ {
1731
+ code: 6012,
1732
+ name: "AllFundsUnlocked",
1733
+ msg: "All funds are already unlocked"
1734
+ }
1735
+ ],
1736
+ types: [
1737
+ {
1738
+ name: "ChangeOracleParams",
1739
+ type: {
1740
+ kind: "struct",
1741
+ fields: [
1742
+ {
1743
+ name: "oracle_type",
1744
+ type: {
1745
+ defined: {
1746
+ name: "OracleType"
1747
+ }
1748
+ }
1749
+ }
1750
+ ]
1751
+ }
1752
+ },
1753
+ {
1754
+ name: "Contract",
1755
+ type: {
1756
+ kind: "struct",
1757
+ fields: [
1758
+ {
1759
+ name: "bump",
1760
+ docs: ["Bump Seed used to sign transactions"],
1761
+ type: "u8"
1762
+ },
1763
+ {
1764
+ name: "sender",
1765
+ docs: ["Original Contract sender"],
1766
+ type: "pubkey"
1767
+ },
1768
+ {
1769
+ name: "sender_tokens",
1770
+ docs: ["Original Contract sender tokens address"],
1771
+ type: "pubkey"
1772
+ },
1773
+ {
1774
+ name: "stream",
1775
+ docs: ["Vesting Stream address"],
1776
+ type: "pubkey"
1777
+ },
1778
+ {
1779
+ name: "price_oracle_type",
1780
+ docs: ["Type of the Oracle used to derive Token Price"],
1781
+ type: {
1782
+ defined: {
1783
+ name: "OracleType"
1784
+ }
1785
+ }
1786
+ },
1787
+ {
1788
+ name: "price_oracle",
1789
+ docs: ["Address of the Price Oracle"],
1790
+ type: "pubkey"
1791
+ },
1792
+ {
1793
+ name: "min_price",
1794
+ docs: ["Min price boundary"],
1795
+ type: "u64"
1796
+ },
1797
+ {
1798
+ name: "max_price",
1799
+ docs: ["Max price boundary"],
1800
+ type: "u64"
1801
+ },
1802
+ {
1803
+ name: "min_percentage",
1804
+ docs: ["Min percentage boundary, can be 0 that equals 1 Raw Token"],
1805
+ type: "u64"
1806
+ },
1807
+ {
1808
+ name: "max_percentage",
1809
+ docs: ["Max percentage boundary"],
1810
+ type: "u64"
1811
+ },
1812
+ {
1813
+ name: "tick_size",
1814
+ docs: ["Ticket size for percentage boundaries"],
1815
+ type: "u64"
1816
+ },
1817
+ {
1818
+ name: "start_time",
1819
+ docs: [
1820
+ "unlock_start from Stream contract for our worker to be able to fetch it in one call with the proxy contract"
1821
+ ],
1822
+ type: "u64"
1823
+ },
1824
+ {
1825
+ name: "end_time",
1826
+ docs: [
1827
+ "Copy end_time from Stream contract for our worker to be able to fetch it in one call with the proxy contract"
1828
+ ],
1829
+ type: "u64"
1830
+ },
1831
+ {
1832
+ name: "period",
1833
+ docs: [
1834
+ "Copy period from Stream contract for our worker to be able to fetch it in one call with the proxy contract"
1835
+ ],
1836
+ type: "u64"
1837
+ },
1838
+ {
1839
+ name: "last_amount_update_time",
1840
+ docs: [
1841
+ "Copy last_rate_change_time from Stream contract for our worker to be able to fetch it in one call with the proxy contract"
1842
+ ],
1843
+ type: "u64"
1844
+ },
1845
+ {
1846
+ name: "last_price",
1847
+ docs: ["Price used on last amount calculation"],
1848
+ type: "u64"
1849
+ },
1850
+ {
1851
+ name: "stream_canceled_time",
1852
+ docs: ["Timestamp when stream was cancelled"],
1853
+ type: "u64"
1854
+ },
1855
+ {
1856
+ name: "initial_amount_per_period",
1857
+ docs: ["Amount per period to use as base for calculations"],
1858
+ type: "u64"
1859
+ },
1860
+ {
1861
+ name: "initial_price",
1862
+ docs: ["Initial token price at the time of Contract creation"],
1863
+ type: "u64"
1864
+ },
1865
+ {
1866
+ name: "initial_net_amount",
1867
+ docs: ["Initial deposited amount"],
1868
+ type: "u64"
1869
+ },
1870
+ {
1871
+ name: "mint",
1872
+ docs: ["Mint for which the contract was created"],
1873
+ type: "pubkey"
1874
+ },
1875
+ {
1876
+ name: "buffer",
1877
+ docs: ["Buffer for additional fields"],
1878
+ type: {
1879
+ array: ["u8", 32]
1880
+ }
1881
+ }
1882
+ ]
1883
+ }
1884
+ },
1885
+ {
1886
+ name: "CreateParams",
1887
+ type: {
1888
+ kind: "struct",
1889
+ fields: [
1890
+ {
1891
+ name: "start_time",
1892
+ docs: ["Timestamp when the tokens start vesting"],
1893
+ type: "u64"
1894
+ },
1895
+ {
1896
+ name: "net_amount_deposited",
1897
+ docs: ["Deposited amount of tokens"],
1898
+ type: "u64"
1899
+ },
1900
+ {
1901
+ name: "period",
1902
+ docs: ["Time step (period) in seconds per which the vesting/release occurs"],
1903
+ type: "u64"
1904
+ },
1905
+ {
1906
+ name: "amount_per_period",
1907
+ docs: ["Base Amount released per period. Combined with `period`, we get a release rate."],
1908
+ type: "u64"
1909
+ },
1910
+ {
1911
+ name: "cliff",
1912
+ docs: ['Vesting contract "cliff" timestamp'],
1913
+ type: "u64"
1914
+ },
1915
+ {
1916
+ name: "cliff_amount",
1917
+ docs: ['Amount unlocked at the "cliff" timestamp'],
1918
+ type: "u64"
1919
+ },
1920
+ {
1921
+ name: "cancelable_by_sender",
1922
+ docs: ["Whether a stream can be canceled by a sender"],
1923
+ type: "bool"
1924
+ },
1925
+ {
1926
+ name: "cancelable_by_recipient",
1927
+ docs: ["Whether a stream can be canceled by a recipient"],
1928
+ type: "bool"
1929
+ },
1930
+ {
1931
+ name: "transferable_by_sender",
1932
+ docs: ["Whether the sender can transfer the stream"],
1933
+ type: "bool"
1934
+ },
1935
+ {
1936
+ name: "transferable_by_recipient",
1937
+ docs: ["Whether the recipient can transfer the stream"],
1938
+ type: "bool"
1939
+ },
1940
+ {
1941
+ name: "can_topup",
1942
+ docs: ["Whether topup is enabled"],
1943
+ type: "bool"
1944
+ },
1945
+ {
1946
+ name: "stream_name",
1947
+ docs: ["The name of this stream"],
1948
+ type: {
1949
+ array: ["u8", 64]
1950
+ }
1951
+ },
1952
+ {
1953
+ name: "min_price",
1954
+ type: "u64"
1955
+ },
1956
+ {
1957
+ name: "max_price",
1958
+ type: "u64"
1959
+ },
1960
+ {
1961
+ name: "min_percentage",
1962
+ type: "u64"
1963
+ },
1964
+ {
1965
+ name: "max_percentage",
1966
+ type: "u64"
1967
+ },
1968
+ {
1969
+ name: "tick_size",
1970
+ type: "u64"
1971
+ },
1972
+ {
1973
+ name: "skip_initial",
1974
+ docs: ["Whether to skip initial calculation of amount per period"],
1975
+ type: "bool"
1976
+ },
1977
+ {
1978
+ name: "oracle_type",
1979
+ docs: ["Type of Oracle to use to derive Token Price"],
1980
+ type: {
1981
+ defined: {
1982
+ name: "OracleType"
1983
+ }
1984
+ }
1985
+ }
1986
+ ]
1987
+ }
1988
+ },
1989
+ {
1990
+ name: "CreateTestOracleParams",
1991
+ type: {
1992
+ kind: "struct",
1993
+ fields: [
1994
+ {
1995
+ name: "price",
1996
+ type: "u64"
1997
+ },
1998
+ {
1999
+ name: "expo",
2000
+ type: "i32"
2001
+ },
2002
+ {
2003
+ name: "conf",
2004
+ type: "u64"
2005
+ },
2006
+ {
2007
+ name: "publish_time",
2008
+ type: "i64"
2009
+ }
2010
+ ]
2011
+ }
2012
+ },
2013
+ {
2014
+ name: "OracleType",
2015
+ type: {
2016
+ kind: "enum",
2017
+ variants: [
2018
+ {
2019
+ name: "None"
2020
+ },
2021
+ {
2022
+ name: "Test"
2023
+ },
2024
+ {
2025
+ name: "Pyth"
2026
+ },
2027
+ {
2028
+ name: "Switchboard"
2029
+ }
2030
+ ]
2031
+ }
2032
+ },
2033
+ {
2034
+ name: "TestOracle",
2035
+ type: {
2036
+ kind: "struct",
2037
+ fields: [
2038
+ {
2039
+ name: "price",
2040
+ type: "u64"
2041
+ },
2042
+ {
2043
+ name: "expo",
2044
+ type: "i32"
2045
+ },
2046
+ {
2047
+ name: "conf",
2048
+ type: "u64"
2049
+ },
2050
+ {
2051
+ name: "publish_time",
2052
+ type: "i64"
2053
+ },
2054
+ {
2055
+ name: "creator",
2056
+ type: "pubkey"
2057
+ },
2058
+ {
2059
+ name: "authority",
2060
+ type: "pubkey"
2061
+ },
2062
+ {
2063
+ name: "mint",
2064
+ type: "pubkey"
2065
+ }
2066
+ ]
2067
+ }
2068
+ },
2069
+ {
2070
+ name: "UpdateTestOracleParams",
2071
+ type: {
2072
+ kind: "struct",
2073
+ fields: [
2074
+ {
2075
+ name: "price",
2076
+ type: "u64"
2077
+ },
2078
+ {
2079
+ name: "expo",
2080
+ type: "i32"
2081
+ },
2082
+ {
2083
+ name: "conf",
2084
+ type: "u64"
2085
+ },
2086
+ {
2087
+ name: "publish_time",
2088
+ type: "i64"
2089
+ }
2090
+ ]
2091
+ }
2092
+ }
2093
+ ]
2094
+ };
2095
+ var deriveContractPDA = (programId, streamMetadata) => {
2096
+ return web3_js.PublicKey.findProgramAddressSync([CONTRACT_SEED, streamMetadata.toBuffer()], programId)[0];
2097
+ };
2098
+ var deriveEscrowPDA = (programId, streamMetadata) => {
2099
+ return web3_js.PublicKey.findProgramAddressSync([ESCROW_SEED, streamMetadata.toBuffer()], programId)[0];
2100
+ };
2101
+ var deriveTestOraclePDA = (programId, mint, creator) => {
2102
+ return web3_js.PublicKey.findProgramAddressSync([TEST_ORACLE_SEED, mint.toBuffer(), creator.toBuffer()], programId)[0];
2103
+ };
2104
+
2105
+ // solana/StreamClient.ts
2106
+ var METADATA_ACC_SIZE = 1104;
2107
+ var ALIGNED_METADATA_ACC_SIZE = 320;
2108
+ var SolanaStreamClient = class extends BaseStreamClient {
2109
+ /**
2110
+ * Create Stream instance
2111
+ */
2112
+ constructor(optionsOrClusterUrl, cluster = common.ICluster.Mainnet, commitment = "confirmed", programId = "", sendRate = 1, sendThrottler) {
2113
+ super();
2114
+ if (typeof optionsOrClusterUrl === "string") {
2115
+ this.commitment = commitment;
2116
+ this.connection = new web3_js.Connection(optionsOrClusterUrl, this.commitment);
2117
+ this.programId = programId !== "" ? new web3_js.PublicKey(programId) : new web3_js.PublicKey(PROGRAM_ID[cluster]);
2118
+ this.schedulingParams = {
2119
+ sendThrottler: sendThrottler ?? solana.buildSendThrottler(sendRate)
2120
+ };
2121
+ } else {
2122
+ const {
2123
+ clusterUrl,
2124
+ cluster: cluster2 = common.ICluster.Mainnet,
2125
+ commitment: commitment2 = "confirmed",
2126
+ programId: programId2 = "",
2127
+ sendScheduler
2128
+ } = optionsOrClusterUrl;
2129
+ this.commitment = commitment2;
2130
+ this.connection = new web3_js.Connection(clusterUrl, this.commitment);
2131
+ this.programId = programId2 !== "" ? new web3_js.PublicKey(programId2) : new web3_js.PublicKey(PROGRAM_ID[cluster2]);
2132
+ const schedulingOptions = sendScheduler && "sendRate" in sendScheduler ? sendScheduler : void 0;
2133
+ const sendThrottler2 = !sendScheduler ? solana.buildSendThrottler(1) : "sendRate" in sendScheduler ? solana.buildSendThrottler(sendScheduler.sendRate ?? 1, sendScheduler.sendInterval) : sendScheduler;
2134
+ this.schedulingParams = {
2135
+ ...schedulingOptions,
2136
+ sendThrottler: sendThrottler2
2137
+ };
2138
+ }
2139
+ const alignedUnlocksProgram = {
2140
+ ...streamflow_aligned_unlocks_default,
2141
+ address: streamflow_aligned_unlocks_default.address
2142
+ };
2143
+ this.alignedProxyProgram = new anchor.Program(alignedUnlocksProgram, { connection: this.connection });
2144
+ }
2145
+ getConnection() {
2146
+ return this.connection;
2147
+ }
2148
+ getCommitment() {
2149
+ return typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
2150
+ }
2151
+ getProgramId() {
2152
+ return this.programId.toBase58();
2153
+ }
2154
+ /**
2155
+ * Creates a new stream/vesting contract.
2156
+ * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
2157
+ */
2158
+ async create(data, extParams) {
2159
+ const { partner, amount, tokenProgramId } = data;
2160
+ const { isNative, sender, customInstructions } = extParams;
2161
+ const partnerPublicKey = partner ? new web3_js.PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
2162
+ const mintPublicKey = new web3_js.PublicKey(data.tokenId);
2163
+ if (!sender.publicKey) {
2164
+ throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
2165
+ }
2166
+ const ixs = await this.getCreateATAInstructions(
2167
+ [STREAMFLOW_TREASURY_PUBLIC_KEY, partnerPublicKey],
2168
+ mintPublicKey,
2169
+ sender,
2170
+ true,
2171
+ tokenProgramId ? new web3_js.PublicKey(tokenProgramId) : void 0
2172
+ );
2173
+ const { ixs: createIxs, metadata, metadataPubKey } = await this.prepareCreateInstructions(data, extParams);
2174
+ ixs.push(...createIxs);
2175
+ if (isNative) {
2176
+ const totalFee = await this.getTotalFee({
2177
+ address: partnerPublicKey.toString()
2178
+ });
2179
+ const totalAmount = calculateTotalAmountToDeposit(amount, totalFee);
2180
+ ixs.push(...await solana.prepareWrappedAccount(this.connection, sender.publicKey, totalAmount));
2181
+ }
2182
+ await this.applyCustomAfterInstructions(ixs, customInstructions, metadataPubKey);
2183
+ const { tx, hash, context } = await solana.prepareTransaction(this.connection, ixs, sender.publicKey, void 0, [
2184
+ metadata
2185
+ ]);
2186
+ const signature = await solana.signAndExecuteTransaction(
2187
+ this.connection,
2188
+ extParams.sender,
2189
+ tx,
2190
+ {
2191
+ hash,
2192
+ context,
2193
+ commitment: this.getCommitment()
2194
+ },
2195
+ this.schedulingParams
2196
+ );
2197
+ return { ixs, txId: signature, metadataId: metadataPubKey.toBase58() };
2198
+ }
2199
+ async prepareCreateInstructions(streamParams, extParams) {
2200
+ const { ixs, metadata, metadataPubKey } = isCreateAlignedStreamData(streamParams) ? await this.prepareCreateAlignedUnlockInstructions(streamParams, extParams) : await this.prepareCreateStreamInstructions(streamParams, extParams);
2201
+ return { ixs, metadata, metadataPubKey };
2202
+ }
2203
+ async prepareCreateAlignedUnlockInstructions(streamParams, extParams) {
2204
+ const {
2205
+ tokenId: mint,
2206
+ start,
2207
+ period,
2208
+ cliff,
2209
+ canTopup,
2210
+ cancelableBySender,
2211
+ cancelableByRecipient,
2212
+ transferableBySender,
2213
+ transferableByRecipient,
2214
+ partner,
2215
+ recipient,
2216
+ cliffAmount,
2217
+ amountPerPeriod,
2218
+ amount: depositedAmount,
2219
+ name: streamName,
2220
+ minPrice,
2221
+ maxPercentage,
2222
+ minPercentage,
2223
+ maxPrice,
2224
+ skipInitial,
2225
+ tickSize,
2226
+ priceOracle,
2227
+ oracleType,
2228
+ tokenProgramId: streamTokenProgramId
2229
+ } = streamParams;
2230
+ const { isNative, sender, computeLimit, computePrice, metadataPubKeys } = extParams;
2231
+ if (!sender.publicKey) {
2232
+ throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
2233
+ }
2234
+ if (!priceOracle && oracleType && oracleType !== "none") {
2235
+ throw new Error("Price oracle is required for the specified oracle type");
2236
+ }
2237
+ const recipientPublicKey = new web3_js.PublicKey(recipient);
2238
+ const mintPublicKey = isNative ? splToken.NATIVE_MINT : new web3_js.PublicKey(mint);
2239
+ const metadata = !metadataPubKeys ? web3_js.Keypair.generate() : void 0;
2240
+ const metadataPubKey = metadata ? metadata.publicKey : metadataPubKeys[0];
2241
+ if (!metadataPubKey) {
2242
+ throw new Error("Metadata public key is required");
2243
+ }
2244
+ let tokenProgramId = streamTokenProgramId ? new web3_js.PublicKey(streamTokenProgramId) : void 0;
2245
+ if (!tokenProgramId) {
2246
+ tokenProgramId = (await solana.getMintAndProgram(this.connection, mintPublicKey)).tokenProgramId;
2247
+ }
2248
+ const partnerPublicKey = partner ? new web3_js.PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
2249
+ const streamflowProgramPublicKey = new web3_js.PublicKey(this.programId);
2250
+ const escrowPDA = deriveEscrowPDA(streamflowProgramPublicKey, metadataPubKey);
2251
+ const oracle = priceOracle ?? deriveTestOraclePDA(this.alignedProxyProgram.programId, mintPublicKey, sender.publicKey);
2252
+ const ixs = solana.prepareBaseInstructions(this.connection, {
2253
+ computePrice,
2254
+ computeLimit: computeLimit ?? ALIGNED_COMPUTE_LIMIT
2255
+ });
2256
+ ixs.push(
2257
+ ...await this.getCreateATAInstructions([recipientPublicKey], mintPublicKey, sender, true, tokenProgramId)
2258
+ );
2259
+ const encodedUIntArray = new TextEncoder().encode(streamName);
2260
+ const streamNameArray = Array.from(encodedUIntArray);
2261
+ const createIx = await this.alignedProxyProgram.methods.create({
2262
+ startTime: new BN4__default.default(start),
2263
+ netAmountDeposited: depositedAmount,
2264
+ period: new BN4__default.default(period),
2265
+ amountPerPeriod,
2266
+ cliff: new BN4__default.default(cliff),
2267
+ cliffAmount,
2268
+ transferableBySender,
2269
+ transferableByRecipient,
2270
+ cancelableByRecipient,
2271
+ cancelableBySender,
2272
+ canTopup,
2273
+ oracleType: !!oracleType ? { [oracleType]: {} } : { none: {} },
2274
+ streamName: streamNameArray,
2275
+ minPrice: minPrice instanceof BN4__default.default ? minPrice : common.getBN(minPrice, ALIGNED_PRECISION_FACTOR_POW),
2276
+ maxPrice: maxPrice instanceof BN4__default.default ? maxPrice : common.getBN(maxPrice, ALIGNED_PRECISION_FACTOR_POW),
2277
+ minPercentage: minPercentage instanceof BN4__default.default ? minPercentage : common.getBN(minPercentage, ALIGNED_PRECISION_FACTOR_POW),
2278
+ maxPercentage: maxPercentage instanceof BN4__default.default ? maxPercentage : common.getBN(maxPercentage, ALIGNED_PRECISION_FACTOR_POW),
2279
+ tickSize: new BN4__default.default(tickSize || 1),
2280
+ skipInitial: skipInitial ?? false
2281
+ }).accountsPartial({
2282
+ payer: sender.publicKey,
2283
+ sender: sender.publicKey,
2284
+ streamMetadata: metadataPubKey,
2285
+ escrowTokens: escrowPDA,
2286
+ mint: mintPublicKey,
2287
+ partner: partnerPublicKey,
2288
+ recipient: recipientPublicKey,
2289
+ withdrawor: WITHDRAWOR_PUBLIC_KEY,
2290
+ feeOracle: FEE_ORACLE_PUBLIC_KEY,
2291
+ priceOracle: oracle,
2292
+ tokenProgram: tokenProgramId,
2293
+ streamflowProgram: this.programId
2294
+ }).instruction();
2295
+ ixs.push(createIx);
2296
+ return { ixs, metadata, metadataPubKey };
2297
+ }
2298
+ /**
2299
+ * Creates a new stream/vesting contract.
2300
+ * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
2301
+ */
2302
+ async prepareCreateStreamInstructions({
2303
+ recipient,
2304
+ tokenId: mint,
2305
+ start,
2306
+ amount: depositedAmount,
2307
+ period,
2308
+ cliff,
2309
+ cliffAmount,
2310
+ amountPerPeriod,
2311
+ name,
2312
+ canPause,
2313
+ canUpdateRate,
2314
+ canTopup,
2315
+ cancelableBySender,
2316
+ cancelableByRecipient,
2317
+ transferableBySender,
2318
+ transferableByRecipient,
2319
+ automaticWithdrawal = false,
2320
+ withdrawalFrequency = 0,
2321
+ partner,
2322
+ tokenProgramId: streamTokenProgramId
2323
+ }, { sender, metadataPubKeys, isNative = false, computePrice, computeLimit }) {
2324
+ if (!sender.publicKey) {
2325
+ throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
2326
+ }
2327
+ const ixs = solana.prepareBaseInstructions(this.connection, {
2328
+ computePrice,
2329
+ computeLimit
2330
+ });
2331
+ const mintPublicKey = isNative ? splToken.NATIVE_MINT : new web3_js.PublicKey(mint);
2332
+ const recipientPublicKey = new web3_js.PublicKey(recipient);
2333
+ const { metadata, metadataPubKey } = this.getOrCreateStreamMetadata(metadataPubKeys);
2334
+ const [escrowTokens] = web3_js.PublicKey.findProgramAddressSync(
2335
+ [buffer.Buffer.from("strm"), metadataPubKey.toBuffer()],
2336
+ this.programId
2337
+ );
2338
+ let tokenProgramId = streamTokenProgramId ? new web3_js.PublicKey(streamTokenProgramId) : void 0;
2339
+ if (!tokenProgramId) {
2340
+ tokenProgramId = (await solana.getMintAndProgram(this.connection, mintPublicKey)).tokenProgramId;
2341
+ }
2342
+ const senderTokens = await solana.ata(mintPublicKey, sender.publicKey, tokenProgramId);
2343
+ const recipientTokens = await solana.ata(mintPublicKey, recipientPublicKey, tokenProgramId);
2344
+ const streamflowTreasuryTokens = await solana.ata(mintPublicKey, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
2345
+ const partnerPublicKey = partner ? new web3_js.PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
2346
+ const partnerTokens = await solana.ata(mintPublicKey, partnerPublicKey, tokenProgramId);
2347
+ ixs.push(
2348
+ await createStreamInstruction(
2349
+ {
2350
+ start: new BN4__default.default(start),
2351
+ depositedAmount,
2352
+ period: new BN4__default.default(period),
2353
+ amountPerPeriod,
2354
+ cliff: new BN4__default.default(cliff),
2355
+ cliffAmount: new BN4__default.default(cliffAmount),
2356
+ cancelableBySender,
2357
+ cancelableByRecipient,
2358
+ automaticWithdrawal,
2359
+ transferableBySender,
2360
+ transferableByRecipient,
2361
+ canTopup,
2362
+ canUpdateRate: !!canUpdateRate,
2363
+ canPause: !!canPause,
2364
+ name,
2365
+ withdrawFrequency: new BN4__default.default(automaticWithdrawal ? withdrawalFrequency : period)
2366
+ },
2367
+ this.programId,
2368
+ {
2369
+ sender: sender.publicKey,
2370
+ senderTokens,
2371
+ recipient: new web3_js.PublicKey(recipient),
2372
+ metadata: metadataPubKey,
2373
+ escrowTokens,
2374
+ recipientTokens,
2375
+ streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
2376
+ streamflowTreasuryTokens,
2377
+ partner: partnerPublicKey,
2378
+ partnerTokens,
2379
+ mint: new web3_js.PublicKey(mint),
2380
+ feeOracle: FEE_ORACLE_PUBLIC_KEY,
2381
+ rent: web3_js.SYSVAR_RENT_PUBKEY,
2382
+ timelockProgram: this.programId,
2383
+ tokenProgram: tokenProgramId,
2384
+ associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
2385
+ withdrawor: WITHDRAWOR_PUBLIC_KEY,
2386
+ systemProgram: web3_js.SystemProgram.programId
2387
+ }
2388
+ )
2389
+ );
2390
+ return { ixs, metadata, metadataPubKey };
2391
+ }
2392
+ /**
2393
+ * Creates a new stream/vesting contract using unchecked instruction.
2394
+ *
2395
+ * Unchecked instruction differs from the regular in:
2396
+ * - does not check for initialized associated token account (wallets with no control over their ATA should not be used
2397
+ * as sender/recipient/partner or there are risks of funds being locked in the contract)
2398
+ * - initialized contract PDA off chain
2399
+ *
2400
+ * If you are not sure if you should use create or create_unchecked, go for create to be safer.
2401
+ */
2402
+ async createUnchecked(data, extParams) {
2403
+ const { ixs, metadata, metadataPubKey } = await this.prepareCreateUncheckedInstructions(data, extParams);
2404
+ const { tx, hash, context } = await solana.prepareTransaction(
2405
+ this.connection,
2406
+ ixs,
2407
+ extParams.sender.publicKey,
2408
+ void 0,
2409
+ [metadata]
2410
+ );
2411
+ const signature = await solana.signAndExecuteTransaction(
2412
+ this.connection,
2413
+ extParams.sender,
2414
+ tx,
2415
+ {
2416
+ hash,
2417
+ context,
2418
+ commitment: this.getCommitment()
2419
+ },
2420
+ this.schedulingParams
2421
+ );
2422
+ return { ixs, txId: signature, metadataId: metadataPubKey.toBase58() };
2423
+ }
2424
+ /**
2425
+ * Create Transaction instructions for `createUnchecked`
2426
+ */
2427
+ async prepareCreateUncheckedInstructions({
2428
+ recipient,
2429
+ tokenId: mint,
2430
+ start,
2431
+ amount: depositedAmount,
2432
+ period,
2433
+ cliff,
2434
+ cliffAmount,
2435
+ amountPerPeriod,
2436
+ name,
2437
+ canTopup,
2438
+ canUpdateRate,
2439
+ canPause,
2440
+ cancelableBySender,
2441
+ cancelableByRecipient,
2442
+ transferableBySender,
2443
+ transferableByRecipient,
2444
+ automaticWithdrawal = false,
2445
+ withdrawalFrequency = 0,
2446
+ partner
2447
+ }, { sender, metadataPubKeys, isNative = false, computePrice, computeLimit }) {
2448
+ if (!sender.publicKey) {
2449
+ throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
2450
+ }
2451
+ const mintPublicKey = new web3_js.PublicKey(mint);
2452
+ const recipientPublicKey = new web3_js.PublicKey(recipient);
2453
+ const { metadata, metadataPubKey } = this.getOrCreateStreamMetadata(metadataPubKeys);
2454
+ const rentToExempt = await this.connection.getMinimumBalanceForRentExemption(METADATA_ACC_SIZE);
2455
+ const createMetadataInstruction = web3_js.SystemProgram.createAccount({
2456
+ programId: this.programId,
2457
+ space: METADATA_ACC_SIZE,
2458
+ lamports: rentToExempt,
2459
+ fromPubkey: sender?.publicKey,
2460
+ newAccountPubkey: metadataPubKey
2461
+ });
2462
+ const [escrowTokens] = web3_js.PublicKey.findProgramAddressSync(
2463
+ [buffer.Buffer.from("strm"), metadataPubKey.toBuffer()],
2464
+ this.programId
2465
+ );
2466
+ const { tokenProgramId } = await solana.getMintAndProgram(this.connection, mintPublicKey);
2467
+ const senderTokens = await solana.ata(mintPublicKey, sender.publicKey, tokenProgramId);
2468
+ const partnerPublicKey = partner ? new web3_js.PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
2469
+ const ixs = solana.prepareBaseInstructions(this.connection, {
2470
+ computePrice,
2471
+ computeLimit
2472
+ });
2473
+ if (isNative) {
2474
+ const totalFee = await this.getTotalFee({ address: partnerPublicKey.toString() });
2475
+ const totalAmount = calculateTotalAmountToDeposit(depositedAmount, totalFee);
2476
+ ixs.push(...await solana.prepareWrappedAccount(this.connection, sender.publicKey, totalAmount));
2477
+ }
2478
+ const createInstruction = await createUncheckedStreamInstruction(
2479
+ {
2480
+ start: new BN4__default.default(start),
2481
+ depositedAmount,
2482
+ period: new BN4__default.default(period),
2483
+ amountPerPeriod,
2484
+ cliff: new BN4__default.default(cliff),
2485
+ cliffAmount: new BN4__default.default(cliffAmount),
2486
+ cancelableBySender,
2487
+ cancelableByRecipient,
2488
+ automaticWithdrawal,
2489
+ transferableBySender,
2490
+ transferableByRecipient,
2491
+ canTopup,
2492
+ canUpdateRate: !!canUpdateRate,
2493
+ canPause: !!canPause,
2494
+ name,
2495
+ withdrawFrequency: new BN4__default.default(automaticWithdrawal ? withdrawalFrequency : period),
2496
+ recipient: recipientPublicKey,
2497
+ partner: partnerPublicKey
2498
+ },
2499
+ this.programId,
2500
+ {
2501
+ sender: sender.publicKey,
2502
+ senderTokens,
2503
+ metadata: metadataPubKey,
2504
+ escrowTokens,
2505
+ mint: new web3_js.PublicKey(mint),
2506
+ feeOracle: FEE_ORACLE_PUBLIC_KEY,
2507
+ rent: web3_js.SYSVAR_RENT_PUBKEY,
2508
+ timelockProgram: this.programId,
2509
+ tokenProgram: tokenProgramId,
2510
+ withdrawor: WITHDRAWOR_PUBLIC_KEY,
2511
+ systemProgram: web3_js.SystemProgram.programId
2512
+ }
2513
+ );
2514
+ ixs.push(createMetadataInstruction, createInstruction);
2515
+ return { ixs, metadata, metadataPubKey };
2516
+ }
2517
+ /**
2518
+ * Creates multiple stream/vesting contracts.
2519
+ * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
2520
+ */
2521
+ async createMultiple(data, extParams) {
2522
+ const { recipients, ...streamParams } = data;
2523
+ const {
2524
+ sender,
2525
+ metadataPubKeys: metadataPubKeysExt,
2526
+ isNative,
2527
+ computePrice,
2528
+ computeLimit,
2529
+ customInstructions
2530
+ } = extParams;
2531
+ const metadatas = [];
2532
+ const metadataToRecipient = {};
2533
+ const errors = [];
2534
+ const signatures = [];
2535
+ const batch = [];
2536
+ const instructionsBatch = [];
2537
+ const metadataPubKeys = metadataPubKeysExt || [];
2538
+ const partnerPublicKey = data.partner ? new web3_js.PublicKey(data.partner) : WITHDRAWOR_PUBLIC_KEY;
2539
+ const mintPublicKey = new web3_js.PublicKey(data.tokenId);
2540
+ if (recipients.length === 0) {
2541
+ throw new Error("Recipients array is empty!");
2542
+ }
2543
+ if (!sender.publicKey) {
2544
+ throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
2545
+ }
2546
+ for (let i = 0; i < recipients.length; i++) {
2547
+ const recipientData = recipients[i];
2548
+ const createStreamData = { ...streamParams, ...recipientData };
2549
+ const createStreamExtParams = {
2550
+ sender,
2551
+ metadataPubKeys: metadataPubKeys[i] ? [metadataPubKeys[i]] : void 0,
2552
+ computePrice,
2553
+ computeLimit,
2554
+ customInstructions
2555
+ };
2556
+ const { ixs, metadata, metadataPubKey } = await this.prepareCreateInstructions(
2557
+ createStreamData,
2558
+ createStreamExtParams
2559
+ );
2560
+ await this.applyCustomAfterInstructions(ixs, customInstructions, metadataPubKey);
2561
+ metadataToRecipient[metadataPubKey.toBase58()] = recipientData;
2562
+ metadatas.push(metadataPubKey.toBase58());
2563
+ instructionsBatch.push({
2564
+ ixs,
2565
+ metadata,
2566
+ recipient: recipientData.recipient
2567
+ });
2568
+ }
2569
+ const { value: hash, context } = await this.connection.getLatestBlockhashAndContext();
2570
+ for (const { ixs, metadata, recipient } of instructionsBatch) {
2571
+ batch.push({ tx: solana.createVersionedTransaction(ixs, sender.publicKey, hash.blockhash, [metadata]), recipient });
2572
+ }
2573
+ const prepareInstructions = await this.getCreateATAInstructions(
2574
+ [STREAMFLOW_TREASURY_PUBLIC_KEY, partnerPublicKey],
2575
+ mintPublicKey,
2576
+ sender,
2577
+ true
2578
+ );
2579
+ if (isNative) {
2580
+ const totalDepositedAmount = recipients.reduce((acc, recipient) => recipient.amount.add(acc), new BN4__default.default(0));
2581
+ const nativeInstructions = await solana.prepareWrappedAccount(this.connection, sender.publicKey, totalDepositedAmount);
2582
+ prepareInstructions.push(...nativeInstructions);
2583
+ }
2584
+ if (prepareInstructions.length > 0) {
2585
+ batch.push({
2586
+ tx: solana.createVersionedTransaction(prepareInstructions, sender.publicKey, hash.blockhash),
2587
+ recipient: sender.publicKey.toBase58()
2588
+ });
2589
+ }
2590
+ const signedBatch = await signAllTransactionWithRecipients(sender, batch);
2591
+ if (prepareInstructions.length > 0) {
2592
+ const prepareTx = signedBatch.pop();
2593
+ await sendAndConfirmStreamRawTransaction(this.connection, prepareTx, { hash, context }, this.schedulingParams);
2594
+ }
2595
+ const responses = [];
2596
+ if (metadataPubKeys.length > 0) {
2597
+ for (const batchTx of signedBatch) {
2598
+ responses.push(
2599
+ ...await Promise.allSettled([
2600
+ solana.executeTransaction(this.connection, batchTx.tx, { hash, context }, this.schedulingParams)
2601
+ ])
2602
+ );
2603
+ }
2604
+ } else {
2605
+ responses.push(
2606
+ ...await solana.executeMultipleTransactions(
2607
+ this.connection,
2608
+ signedBatch.map((item) => item.tx),
2609
+ { hash, context },
2610
+ this.schedulingParams
2611
+ )
2612
+ );
2613
+ }
2614
+ responses.forEach((item, index) => {
2615
+ if (item.status === "fulfilled") {
2616
+ signatures.push(item.value);
2617
+ } else {
2618
+ errors.push({
2619
+ recipient: signedBatch[index].recipient,
2620
+ error: item.reason,
2621
+ contractErrorCode: this.extractErrorCode(item.reason) || void 0
2622
+ });
2623
+ }
2624
+ });
2625
+ return { txs: signatures, metadatas, metadataToRecipient, errors };
2626
+ }
2627
+ /**
2628
+ * Creates multiple stream/vesting contracts, and send all transactions sequentially.
2629
+ * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
2630
+ * In most cases, createMultiple should be used instead.
2631
+ */
2632
+ async createMultipleSequential(data, extParams) {
2633
+ const { recipients, ...streamParams } = data;
2634
+ const {
2635
+ sender,
2636
+ metadataPubKeys: metadataPubKeysExt,
2637
+ isNative,
2638
+ computePrice,
2639
+ computeLimit,
2640
+ customInstructions
2641
+ } = extParams;
2642
+ const metadatas = [];
2643
+ const metadataToRecipient = {};
2644
+ const errors = [];
2645
+ const signatures = [];
2646
+ const batch = [];
2647
+ const instructionsBatch = [];
2648
+ const metadataPubKeys = metadataPubKeysExt || [];
2649
+ const partnerPublicKey = data.partner ? new web3_js.PublicKey(data.partner) : WITHDRAWOR_PUBLIC_KEY;
2650
+ const mintPublicKey = new web3_js.PublicKey(data.tokenId);
2651
+ if (recipients.length === 0) {
2652
+ throw new Error("Recipients array is empty!");
2653
+ }
2654
+ if (!sender.publicKey) {
2655
+ throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
2656
+ }
2657
+ for (let i = 0; i < recipients.length; i++) {
2658
+ const recipientData = recipients[i];
2659
+ const createStreamData = { ...streamParams, ...recipientData };
2660
+ const createStreamExtParams = {
2661
+ sender,
2662
+ metadataPubKeys: metadataPubKeys[i] ? [metadataPubKeys[i]] : void 0,
2663
+ computePrice,
2664
+ computeLimit,
2665
+ customInstructions
2666
+ };
2667
+ const { ixs, metadata, metadataPubKey } = await this.prepareCreateInstructions(
2668
+ createStreamData,
2669
+ createStreamExtParams
2670
+ );
2671
+ await this.applyCustomAfterInstructions(ixs, customInstructions, metadataPubKey);
2672
+ metadataToRecipient[metadataPubKey.toBase58()] = recipientData;
2673
+ metadatas.push(metadataPubKey.toBase58());
2674
+ instructionsBatch.push({
2675
+ ixs,
2676
+ metadata,
2677
+ recipient: recipientData.recipient
2678
+ });
2679
+ }
2680
+ const { value: hash, context } = await this.connection.getLatestBlockhashAndContext();
2681
+ for (const { ixs, metadata, recipient } of instructionsBatch) {
2682
+ const messageV0 = new web3_js.TransactionMessage({
2683
+ payerKey: sender.publicKey,
2684
+ recentBlockhash: hash.blockhash,
2685
+ instructions: ixs
2686
+ }).compileToV0Message();
2687
+ const tx = new web3_js.VersionedTransaction(messageV0);
2688
+ if (metadata) {
2689
+ tx.sign([metadata]);
2690
+ }
2691
+ batch.push({ tx, recipient });
2692
+ }
2693
+ const prepareInstructions = await this.getCreateATAInstructions(
2694
+ [STREAMFLOW_TREASURY_PUBLIC_KEY, partnerPublicKey],
2695
+ mintPublicKey,
2696
+ sender,
2697
+ true
2698
+ );
2699
+ if (isNative) {
2700
+ const totalDepositedAmount = recipients.reduce((acc, recipient) => recipient.amount.add(acc), new BN4__default.default(0));
2701
+ const nativeInstructions = await solana.prepareWrappedAccount(this.connection, sender.publicKey, totalDepositedAmount);
2702
+ prepareInstructions.push(...nativeInstructions);
2703
+ }
2704
+ if (prepareInstructions.length > 0) {
2705
+ const messageV0 = new web3_js.TransactionMessage({
2706
+ payerKey: sender.publicKey,
2707
+ recentBlockhash: hash.blockhash,
2708
+ instructions: prepareInstructions
2709
+ }).compileToV0Message();
2710
+ const tx = new web3_js.VersionedTransaction(messageV0);
2711
+ batch.push({
2712
+ tx,
2713
+ recipient: sender.publicKey.toBase58()
2714
+ });
2715
+ }
2716
+ const signedBatch = await signAllTransactionWithRecipients(sender, batch);
2717
+ if (prepareInstructions.length > 0) {
2718
+ const prepareTx = signedBatch.shift();
2719
+ await sendAndConfirmStreamRawTransaction(this.connection, prepareTx, { hash, context }, this.schedulingParams);
2720
+ }
2721
+ const responses = [];
2722
+ for (const batchTx of signedBatch) {
2723
+ responses.push(
2724
+ ...await Promise.allSettled([
2725
+ solana.executeTransaction(this.connection, batchTx.tx, { hash, context }, this.schedulingParams)
2726
+ ])
2727
+ );
2728
+ }
2729
+ responses.forEach((item, index) => {
2730
+ if (item.status === "fulfilled") {
2731
+ signatures.push(item.value);
2732
+ } else {
2733
+ errors.push({
2734
+ recipient: signedBatch[index].recipient,
2735
+ error: item.reason,
2736
+ contractErrorCode: this.extractErrorCode(item.reason) || void 0
2737
+ });
2738
+ }
2739
+ });
2740
+ return { txs: signatures, metadatas, metadataToRecipient, errors };
2741
+ }
2742
+ /**
2743
+ * Attempts withdrawing from the specified stream.
2744
+ */
2745
+ async withdraw({ id, amount = WITHDRAW_AVAILABLE_AMOUNT }, extParams) {
2746
+ const { invoker, customInstructions } = extParams;
2747
+ if (!invoker.publicKey) {
2748
+ throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
2749
+ }
2750
+ const ixs = await this.prepareWithdrawInstructions({ id, amount }, extParams);
2751
+ const metadata = new web3_js.PublicKey(id);
2752
+ await this.applyCustomAfterInstructions(ixs, customInstructions, metadata);
2753
+ const { tx, hash, context } = await solana.prepareTransaction(this.connection, ixs, invoker.publicKey);
2754
+ const signature = await solana.signAndExecuteTransaction(
2755
+ this.connection,
2756
+ extParams.invoker,
2757
+ tx,
2758
+ {
2759
+ hash,
2760
+ context,
2761
+ commitment: this.getCommitment()
2762
+ },
2763
+ this.schedulingParams
2764
+ );
2765
+ return { ixs, txId: signature };
2766
+ }
2767
+ /**
2768
+ * Creates Transaction Instructions for withdrawal
2769
+ */
2770
+ async prepareWithdrawInstructions({ id, amount = WITHDRAW_AVAILABLE_AMOUNT }, { invoker, checkTokenAccounts, computePrice, computeLimit }) {
2771
+ if (!invoker.publicKey) {
2772
+ throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
2773
+ }
2774
+ const ixs = solana.prepareBaseInstructions(this.connection, {
2775
+ computePrice,
2776
+ computeLimit
2777
+ });
2778
+ const streamPublicKey = new web3_js.PublicKey(id);
2779
+ const escrow = await this.connection.getAccountInfo(streamPublicKey);
2780
+ if (!escrow?.data) {
2781
+ throw new Error("Couldn't get account info");
2782
+ }
2783
+ const data = decodeStream(escrow.data);
2784
+ const { sender, recipient, mint, streamflowTreasury, partner, recipientTokens, escrowTokens } = data;
2785
+ const { tokenProgramId } = await solana.getMintAndProgram(this.connection, mint);
2786
+ const streamflowTreasuryTokens = await solana.ata(mint, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
2787
+ const partnerTokens = await solana.ata(mint, partner, tokenProgramId);
2788
+ const ataIx = await this.getCreateATAInstructions(
2789
+ [sender, recipient, streamflowTreasury, partner],
2790
+ mint,
2791
+ invoker,
2792
+ checkTokenAccounts,
2793
+ tokenProgramId
2794
+ );
2795
+ ixs.push(
2796
+ ...ataIx,
2797
+ await withdrawStreamInstruction(amount, this.programId, {
2798
+ partner,
2799
+ partnerTokens,
2800
+ mint,
2801
+ streamflowTreasuryTokens,
2802
+ recipientTokens,
2803
+ escrowTokens,
2804
+ authority: invoker.publicKey,
2805
+ recipient: invoker.publicKey,
2806
+ metadata: streamPublicKey,
2807
+ streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
2808
+ tokenProgram: tokenProgramId
2809
+ })
2810
+ );
2811
+ return ixs;
2812
+ }
2813
+ /**
2814
+ * Attempts canceling the specified stream.
2815
+ */
2816
+ async cancel(cancelData, extParams) {
2817
+ const ixs = await this.prepareCancelInstructions(cancelData, extParams);
2818
+ const { tx, hash, context } = await solana.prepareTransaction(this.connection, ixs, extParams.invoker.publicKey);
2819
+ const signature = await solana.signAndExecuteTransaction(
2820
+ this.connection,
2821
+ extParams.invoker,
2822
+ tx,
2823
+ {
2824
+ hash,
2825
+ context,
2826
+ commitment: this.getCommitment()
2827
+ },
2828
+ this.schedulingParams
2829
+ );
2830
+ return { ixs, txId: signature };
2831
+ }
2832
+ async prepareCancelInstructions(cancelData, extParams) {
2833
+ const streamPublicKey = new web3_js.PublicKey(cancelData.id);
2834
+ const account = await this.connection.getAccountInfo(streamPublicKey);
2835
+ if (!account) {
2836
+ throw new Error("Impossible to cancel a stream contract that does not exist");
2837
+ }
2838
+ const { sender: senderPublicKey } = decodeStream(account.data);
2839
+ const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey, senderPublicKey);
2840
+ const ixs = isAlignedUnlock ? await this.prepareCancelAlignedUnlockInstructions(cancelData, extParams) : await this.prepareCancelStreamInstructions(cancelData, extParams);
2841
+ return ixs;
2842
+ }
2843
+ async prepareCancelAlignedUnlockInstructions({ id }, { invoker, checkTokenAccounts, computePrice, computeLimit }) {
2844
+ if (!invoker.publicKey) {
2845
+ throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
2846
+ }
2847
+ const streamPublicKey = new web3_js.PublicKey(id);
2848
+ const escrowAcc = await this.connection.getAccountInfo(streamPublicKey);
2849
+ if (!escrowAcc?.data) {
2850
+ throw new Error("Couldn't get account info");
2851
+ }
2852
+ const streamData = decodeStream(escrowAcc.data);
2853
+ const { sender, recipient, mint, streamflowTreasury, partner, escrowTokens } = streamData;
2854
+ const { tokenProgramId } = await solana.getMintAndProgram(this.connection, mint);
2855
+ const ixs = solana.prepareBaseInstructions(this.connection, {
2856
+ computePrice,
2857
+ computeLimit: computeLimit ?? ALIGNED_COMPUTE_LIMIT
2858
+ });
2859
+ const ataIx = await this.getCreateATAInstructions(
2860
+ [sender, recipient, partner, streamflowTreasury],
2861
+ mint,
2862
+ invoker,
2863
+ checkTokenAccounts,
2864
+ tokenProgramId
2865
+ );
2866
+ const cancelIx = await this.alignedProxyProgram.methods.cancel().accountsPartial({
2867
+ mint,
2868
+ partner,
2869
+ recipient,
2870
+ escrowTokens,
2871
+ sender: invoker.publicKey,
2872
+ streamMetadata: streamPublicKey,
2873
+ streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
2874
+ tokenProgram: tokenProgramId,
2875
+ streamflowProgram: this.programId
2876
+ }).instruction();
2877
+ ixs.push(...ataIx, cancelIx);
2878
+ return ixs;
2879
+ }
2880
+ /**
2881
+ * Creates Transaction Instructions for cancel
2882
+ */
2883
+ async prepareCancelStreamInstructions({ id }, { invoker, checkTokenAccounts, computePrice, computeLimit }) {
2884
+ if (!invoker.publicKey) {
2885
+ throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
2886
+ }
2887
+ const streamPublicKey = new web3_js.PublicKey(id);
2888
+ const escrowAcc = await this.connection.getAccountInfo(streamPublicKey);
2889
+ if (!escrowAcc?.data) {
2890
+ throw new Error("Couldn't get account info");
2891
+ }
2892
+ const data = decodeStream(escrowAcc.data);
2893
+ const { sender, recipient, partner, streamflowTreasury, mint, senderTokens, recipientTokens, escrowTokens } = data;
2894
+ const { tokenProgramId } = await solana.getMintAndProgram(this.connection, mint);
2895
+ const streamflowTreasuryTokens = await solana.ata(mint, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
2896
+ const partnerTokens = await solana.ata(mint, partner, tokenProgramId);
2897
+ const ixs = solana.prepareBaseInstructions(this.connection, {
2898
+ computePrice,
2899
+ computeLimit
2900
+ });
2901
+ const ixsAta = await this.getCreateATAInstructions(
2902
+ [sender, recipient, partner, streamflowTreasury],
2903
+ mint,
2904
+ invoker,
2905
+ checkTokenAccounts,
2906
+ tokenProgramId
2907
+ );
2908
+ ixs.push(
2909
+ ...ixsAta,
2910
+ await cancelStreamInstruction(this.programId, {
2911
+ sender,
2912
+ senderTokens,
2913
+ recipient,
2914
+ recipientTokens,
2915
+ streamflowTreasuryTokens,
2916
+ partner,
2917
+ partnerTokens,
2918
+ mint,
2919
+ escrowTokens,
2920
+ authority: invoker.publicKey,
2921
+ metadata: streamPublicKey,
2922
+ streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
2923
+ tokenProgram: tokenProgramId
2924
+ })
2925
+ );
2926
+ return ixs;
2927
+ }
2928
+ /**
2929
+ * Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
2930
+ * Potential associated token account rent fee (to make it rent-exempt) is paid by the transaction initiator.
2931
+ */
2932
+ async transfer({ id, newRecipient }, extParams) {
2933
+ const ixs = await this.prepareTransferInstructions({ id, newRecipient }, extParams);
2934
+ const { tx, hash, context } = await solana.prepareTransaction(this.connection, ixs, extParams.invoker.publicKey);
2935
+ const signature = await solana.signAndExecuteTransaction(
2936
+ this.connection,
2937
+ extParams.invoker,
2938
+ tx,
2939
+ {
2940
+ hash,
2941
+ context,
2942
+ commitment: this.getCommitment()
2943
+ },
2944
+ this.schedulingParams
2945
+ );
2946
+ return { ixs, txId: signature };
2947
+ }
2948
+ /**
2949
+ * Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
2950
+ * Potential associated token account rent fee (to make it rent-exempt) is paid by the transaction initiator.
2951
+ */
2952
+ async prepareTransferInstructions({ id, newRecipient }, { invoker, computePrice, computeLimit = 100001 }) {
2953
+ if (!invoker.publicKey) {
2954
+ throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
2955
+ }
2956
+ const ixs = solana.prepareBaseInstructions(this.connection, {
2957
+ computePrice,
2958
+ computeLimit
2959
+ });
2960
+ const stream = new web3_js.PublicKey(id);
2961
+ const newRecipientPublicKey = new web3_js.PublicKey(newRecipient);
2962
+ const escrow = await this.connection.getAccountInfo(stream);
2963
+ if (!escrow?.data) {
2964
+ throw new Error("Couldn't get account info");
2965
+ }
2966
+ const { mint } = decodeStream(escrow?.data);
2967
+ const { tokenProgramId } = await solana.getMintAndProgram(this.connection, mint);
2968
+ const newRecipientTokens = await solana.ata(mint, newRecipientPublicKey, tokenProgramId);
2969
+ ixs.push(
2970
+ await transferStreamInstruction(this.programId, {
2971
+ authority: invoker.publicKey,
2972
+ newRecipient: newRecipientPublicKey,
2973
+ newRecipientTokens,
2974
+ metadata: stream,
2975
+ mint,
2976
+ rent: web3_js.SYSVAR_RENT_PUBKEY,
2977
+ tokenProgram: tokenProgramId,
2978
+ associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
2979
+ systemProgram: web3_js.SystemProgram.programId
2980
+ })
2981
+ );
2982
+ return ixs;
2983
+ }
2984
+ /**
2985
+ * Tops up stream account with specified amount.
2986
+ */
2987
+ async topup({ id, amount }, extParams) {
2988
+ const ixs = await this.prepareTopupInstructions({ id, amount }, extParams);
2989
+ const { tx, hash, context } = await solana.prepareTransaction(this.connection, ixs, extParams.invoker.publicKey);
2990
+ const signature = await solana.signAndExecuteTransaction(
2991
+ this.connection,
2992
+ extParams.invoker,
2993
+ tx,
2994
+ {
2995
+ hash,
2996
+ context,
2997
+ commitment: this.getCommitment()
2998
+ },
2999
+ this.schedulingParams
3000
+ );
3001
+ return { ixs, txId: signature };
3002
+ }
3003
+ /**
3004
+ * Create Transaction instructions for topup
3005
+ */
3006
+ async prepareTopupInstructions({ id, amount }, { invoker, isNative, computePrice, computeLimit }) {
3007
+ if (!invoker.publicKey) {
3008
+ throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
3009
+ }
3010
+ const ixs = solana.prepareBaseInstructions(this.connection, {
3011
+ computePrice,
3012
+ computeLimit
3013
+ });
3014
+ const streamPublicKey = new web3_js.PublicKey(id);
3015
+ const escrow = await this.connection.getAccountInfo(streamPublicKey);
3016
+ if (!escrow?.data) {
3017
+ throw new Error("Couldn't get account info");
3018
+ }
3019
+ const { mint, partner, senderTokens, escrowTokens } = decodeStream(escrow?.data);
3020
+ const { tokenProgramId } = await solana.getMintAndProgram(this.connection, mint);
3021
+ const streamflowTreasuryTokens = await solana.ata(mint, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
3022
+ const partnerTokens = await solana.ata(mint, partner, tokenProgramId);
3023
+ if (isNative) {
3024
+ ixs.push(...await solana.prepareWrappedAccount(this.connection, invoker.publicKey, amount));
3025
+ }
3026
+ ixs.push(
3027
+ await topupStreamInstruction(amount, this.programId, {
3028
+ sender: invoker.publicKey,
3029
+ senderTokens,
3030
+ metadata: streamPublicKey,
3031
+ escrowTokens,
3032
+ streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
3033
+ streamflowTreasuryTokens,
3034
+ partner,
3035
+ partnerTokens,
3036
+ mint,
3037
+ tokenProgram: tokenProgramId,
3038
+ withdrawor: WITHDRAWOR_PUBLIC_KEY,
3039
+ systemProgram: web3_js.SystemProgram.programId
3040
+ })
3041
+ );
3042
+ return ixs;
3043
+ }
3044
+ /**
3045
+ * Fetch stream data by its id (address).
3046
+ */
3047
+ async getOne({ id }) {
3048
+ const streamPublicKey = new web3_js.PublicKey(id);
3049
+ const escrow = await this.connection.getAccountInfo(streamPublicKey, TX_FINALITY_CONFIRMED);
3050
+ if (!escrow?.data) {
3051
+ throw new Error("Couldn't get account info.");
3052
+ }
3053
+ const stream = decodeStream(escrow.data);
3054
+ if (this.isAlignedUnlock(streamPublicKey, stream.sender)) {
3055
+ const alignedProxy = await this.alignedProxyProgram.account.contract.fetch(
3056
+ deriveContractPDA(this.alignedProxyProgram.programId, streamPublicKey)
3057
+ );
3058
+ if (!alignedProxy) {
3059
+ throw new Error("Couldn't get proxy account info.");
3060
+ }
3061
+ return new AlignedContract(stream, alignedProxy);
3062
+ }
3063
+ return new Contract(stream);
3064
+ }
3065
+ /**
3066
+ * Fetch all aligned outgoing streams/contracts by the provided public key.
3067
+ */
3068
+ async getOutgoingAlignedStreams(sender) {
3069
+ const streams = {};
3070
+ const alignedOutgoingProgramAccounts = await this.alignedProxyProgram.account.contract.all([
3071
+ {
3072
+ memcmp: {
3073
+ offset: ORIGINAL_CONTRACT_SENDER_OFFSET,
3074
+ bytes: sender
3075
+ }
3076
+ },
3077
+ {
3078
+ dataSize: ALIGNED_METADATA_ACC_SIZE
3079
+ }
3080
+ ]);
3081
+ const streamPubKeys = alignedOutgoingProgramAccounts.map((account) => account.account.stream);
3082
+ const streamAccounts = await solana.getMultipleAccountsInfoBatched(this.connection, streamPubKeys, TX_FINALITY_CONFIRMED);
3083
+ streamAccounts.forEach((account, index) => {
3084
+ if (account) {
3085
+ const alignedData = alignedOutgoingProgramAccounts[index].account;
3086
+ streams[streamPubKeys[index].toBase58()] = new AlignedContract(decodeStream(account.data), alignedData);
3087
+ }
3088
+ });
3089
+ return streams;
3090
+ }
3091
+ async getIncomingAlignedStreams(streamRecord) {
3092
+ const streams = {};
3093
+ const alignedStreamsPubKeys = Object.keys(streamRecord);
3094
+ const alignedProxyPDAs = alignedStreamsPubKeys.map(
3095
+ (streamPubKey) => deriveContractPDA(this.alignedProxyProgram.programId, new web3_js.PublicKey(streamPubKey))
3096
+ );
3097
+ const alignedProxyAccounts = await solana.getMultipleAccountsInfoBatched(this.connection, alignedProxyPDAs);
3098
+ alignedProxyAccounts.forEach((account, index) => {
3099
+ if (account && account.data.length === ALIGNED_METADATA_ACC_SIZE) {
3100
+ const alignedData = streamRecord[alignedStreamsPubKeys[index]];
3101
+ streams[alignedStreamsPubKeys[index]] = new AlignedContract(
3102
+ alignedData,
3103
+ this.alignedProxyProgram.account.contract.coder.accounts.decode("contract", account.data)
3104
+ );
3105
+ }
3106
+ });
3107
+ return streams;
3108
+ }
3109
+ /**
3110
+ * Fetch streams/contracts by providing direction.
3111
+ * Streams are sorted by start time in ascending order.
3112
+ */
3113
+ async get({
3114
+ address,
3115
+ type = "all" /* All */,
3116
+ direction = "all" /* All */
3117
+ }) {
3118
+ const publicKey = new web3_js.PublicKey(address);
3119
+ let streams = {};
3120
+ const shouldFetchAligned = type === "all" /* All */ || type === "vesting" /* Vesting */;
3121
+ if (direction !== "incoming" /* Incoming */) {
3122
+ const outgoingStreamAccounts = await solana.getProgramAccounts(
3123
+ this.connection,
3124
+ publicKey,
3125
+ STREAM_STRUCT_OFFSET_SENDER,
3126
+ this.programId
3127
+ );
3128
+ outgoingStreamAccounts.forEach((account) => {
3129
+ streams[account.pubkey.toBase58()] = new Contract(decodeStream(account.account.data));
3130
+ });
3131
+ if (shouldFetchAligned) {
3132
+ const alignedStreams = await this.getOutgoingAlignedStreams(address);
3133
+ streams = { ...streams, ...alignedStreams };
3134
+ }
3135
+ }
3136
+ if (direction !== "outgoing" /* Outgoing */) {
3137
+ const allIncomingAccounts = await solana.getProgramAccounts(
3138
+ this.connection,
3139
+ publicKey,
3140
+ STREAM_STRUCT_OFFSET_RECIPIENT,
3141
+ this.programId
3142
+ );
3143
+ const allIncomingStreams = allIncomingAccounts.map((account) => decodeStream(account.account.data));
3144
+ const alignedDecoded = {};
3145
+ allIncomingAccounts.forEach((account, index) => {
3146
+ if (this.isAlignedUnlock(account.pubkey, allIncomingStreams[index].sender)) {
3147
+ alignedDecoded[account.pubkey.toBase58()] = allIncomingStreams[index];
3148
+ } else {
3149
+ streams[account.pubkey.toBase58()] = new Contract(allIncomingStreams[index]);
3150
+ }
3151
+ });
3152
+ if (shouldFetchAligned) {
3153
+ const incomingAlignedStreams = await this.getIncomingAlignedStreams(alignedDecoded);
3154
+ streams = { ...streams, ...incomingAlignedStreams };
3155
+ }
3156
+ }
3157
+ const sortedStreams = Object.entries(streams).sort(([, stream1], [, stream2]) => stream2.start - stream1.start);
3158
+ if (type === "all" /* All */) return sortedStreams;
3159
+ return sortedStreams.filter((stream) => stream[1].type === type);
3160
+ }
3161
+ async searchStreams(data) {
3162
+ const filters = Object.entries(data).filter(([_, value]) => value !== void 0).map(([key, value]) => ({
3163
+ memcmp: {
3164
+ offset: STREAM_STRUCT_OFFSETS[key],
3165
+ bytes: typeof value === "boolean" ? bs58__default.default.encode([Number(value)]) : value.toString()
3166
+ }
3167
+ }));
3168
+ filters.push({ dataSize: METADATA_ACC_SIZE });
3169
+ const accounts = await this.connection.getProgramAccounts(this.programId, {
3170
+ filters
3171
+ });
3172
+ return accounts.map(({ pubkey, account }) => ({
3173
+ publicKey: pubkey,
3174
+ account: new Contract(decodeStream(account.data))
3175
+ }));
3176
+ }
3177
+ /**
3178
+ * Attempts updating the stream auto withdrawal params and amount per period
3179
+ */
3180
+ async update(data, extParams) {
3181
+ const ixs = await this.prepareUpdateInstructions(data, extParams);
3182
+ const { tx, hash, context } = await solana.prepareTransaction(this.connection, ixs, extParams.invoker.publicKey);
3183
+ const signature = await solana.signAndExecuteTransaction(
3184
+ this.connection,
3185
+ extParams.invoker,
3186
+ tx,
3187
+ {
3188
+ hash,
3189
+ context,
3190
+ commitment: this.getCommitment()
3191
+ },
3192
+ this.schedulingParams
3193
+ );
3194
+ return {
3195
+ ixs,
3196
+ txId: signature
3197
+ };
3198
+ }
3199
+ /**
3200
+ * Create Transaction instructions for update
3201
+ */
3202
+ async prepareUpdateInstructions(data, { invoker, computePrice, computeLimit }) {
3203
+ if (!invoker.publicKey) {
3204
+ throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
3205
+ }
3206
+ const streamPublicKey = new web3_js.PublicKey(data.id);
3207
+ const escrow = await this.connection.getAccountInfo(streamPublicKey);
3208
+ if (!escrow) {
3209
+ throw new Error("Couldn't get account info");
3210
+ }
3211
+ const ixs = solana.prepareBaseInstructions(this.connection, {
3212
+ computePrice,
3213
+ computeLimit
3214
+ });
3215
+ ixs.push(
3216
+ await updateStreamInstruction(data, this.programId, {
3217
+ authority: invoker.publicKey,
3218
+ metadata: streamPublicKey,
3219
+ withdrawor: WITHDRAWOR_PUBLIC_KEY,
3220
+ systemProgram: web3_js.SystemProgram.programId
3221
+ })
3222
+ );
3223
+ return ixs;
3224
+ }
3225
+ async getFees({ address }) {
3226
+ const [metadataPubKey] = web3_js.PublicKey.findProgramAddressSync(
3227
+ [buffer.Buffer.from(FEES_METADATA_SEED)],
3228
+ new web3_js.PublicKey(PARTNER_ORACLE_PROGRAM_ID)
3229
+ );
3230
+ const data = await this.connection.getAccountInfo(metadataPubKey);
3231
+ if (!data) {
3232
+ return null;
3233
+ }
3234
+ const partners = borsh__namespace.deserialize(PARTNERS_SCHEMA, data.data);
3235
+ const filteredPartners = partners.filter((item) => new web3_js.PublicKey(item.pubkey).toString() === address);
3236
+ if (filteredPartners.length === 0) {
3237
+ return null;
3238
+ }
3239
+ return {
3240
+ streamflowFee: Number(filteredPartners[0].strm_fee.toFixed(4)),
3241
+ partnerFee: Number(filteredPartners[0].partner_fee.toFixed(4))
3242
+ };
3243
+ }
3244
+ async getDefaultStreamflowFee() {
3245
+ return DEFAULT_STREAMFLOW_FEE;
3246
+ }
3247
+ extractErrorCode(err) {
3248
+ const logs = "logs" in err && Array.isArray(err.logs) ? err.logs : void 0;
3249
+ return extractSolanaErrorCode(err.toString() ?? "Unknown error!", logs);
3250
+ }
3251
+ /**
3252
+ * Utility function to generate metadata for a Contract or return existing Pubkey
3253
+ */
3254
+ getOrCreateStreamMetadata(metadataPubKeys) {
3255
+ let metadata;
3256
+ let metadataPubKey;
3257
+ if (!metadataPubKeys) {
3258
+ metadata = web3_js.Keypair.generate();
3259
+ metadataPubKey = metadata.publicKey;
3260
+ } else {
3261
+ metadataPubKey = metadataPubKeys[0];
3262
+ }
3263
+ return { metadata, metadataPubKey };
3264
+ }
3265
+ /**
3266
+ * Utility function that checks whether the associated stream address is an aligned unlock contract, indicated by whether the sender/creator is a PDA
3267
+ */
3268
+ isAlignedUnlock(streamPublicKey, senderPublicKey) {
3269
+ const pda = deriveContractPDA(this.alignedProxyProgram.programId, streamPublicKey);
3270
+ return senderPublicKey.equals(pda);
3271
+ }
3272
+ /**
3273
+ * Returns insrtuctions for creating associated token accounts for the provided owners
3274
+ */
3275
+ async getCreateATAInstructions(owners, mint, invoker, checkTokenAccounts, programId) {
3276
+ if (!checkTokenAccounts) {
3277
+ return [];
3278
+ }
3279
+ const uniqueOwners = Array.from(new Set(owners.map((owner) => owner.toBase58()))).map(
3280
+ (pkString) => new web3_js.PublicKey(pkString)
3281
+ );
3282
+ return solana.checkOrCreateAtaBatch(this.connection, uniqueOwners, mint, invoker, programId);
3283
+ }
3284
+ async applyCustomAfterInstructions(ixs, customInstructions, metadata) {
3285
+ if (customInstructions?.after) {
3286
+ const afterInstructions = typeof customInstructions.after === "function" ? await customInstructions.after({
3287
+ instructions: ixs,
3288
+ metadata
3289
+ }) : customInstructions.after;
3290
+ ixs.push(...afterInstructions);
3291
+ }
3292
+ }
3293
+ };
3294
+
3295
+ // solana/timelockIDL.ts
3296
+ var timelockIDL_default = {
3297
+ version: "0.1.0",
3298
+ name: "timelock",
3299
+ instructions: [
3300
+ {
3301
+ name: "create",
3302
+ accounts: [
3303
+ {
3304
+ name: "sender",
3305
+ isMut: true,
3306
+ isSigner: true
3307
+ },
3308
+ {
3309
+ name: "senderTokens",
3310
+ isMut: true,
3311
+ isSigner: false
3312
+ },
3313
+ {
3314
+ name: "recipient",
3315
+ isMut: true,
3316
+ isSigner: false
3317
+ },
3318
+ {
3319
+ name: "metadata",
3320
+ isMut: true,
3321
+ isSigner: true
3322
+ },
3323
+ {
3324
+ name: "escrowTokens",
3325
+ isMut: true,
3326
+ isSigner: false
3327
+ },
3328
+ {
3329
+ name: "recipientTokens",
3330
+ isMut: true,
3331
+ isSigner: false
3332
+ },
3333
+ {
3334
+ name: "streamflowTreasury",
3335
+ isMut: true,
3336
+ isSigner: false
3337
+ },
3338
+ {
3339
+ name: "streamflowTreasuryTokens",
3340
+ isMut: true,
3341
+ isSigner: false
3342
+ },
3343
+ {
3344
+ name: "withdrawor",
3345
+ isMut: true,
3346
+ isSigner: false
3347
+ },
3348
+ {
3349
+ name: "partner",
3350
+ isMut: true,
3351
+ isSigner: false
3352
+ },
3353
+ {
3354
+ name: "partnerTokens",
3355
+ isMut: true,
3356
+ isSigner: false
3357
+ },
3358
+ {
3359
+ name: "mint",
3360
+ isMut: false,
3361
+ isSigner: false
3362
+ },
3363
+ {
3364
+ name: "feeOracle",
3365
+ isMut: false,
3366
+ isSigner: false
3367
+ },
3368
+ {
3369
+ name: "rent",
3370
+ isMut: false,
3371
+ isSigner: false
3372
+ },
3373
+ {
3374
+ name: "timelockProgram",
3375
+ isMut: false,
3376
+ isSigner: false
3377
+ },
3378
+ {
3379
+ name: "tokenProgram",
3380
+ isMut: false,
3381
+ isSigner: false
3382
+ },
3383
+ {
3384
+ name: "associatedTokenProgram",
3385
+ isMut: false,
3386
+ isSigner: false
3387
+ },
3388
+ {
3389
+ name: "systemProgram",
3390
+ isMut: false,
3391
+ isSigner: false
3392
+ }
3393
+ ],
3394
+ args: [
3395
+ {
3396
+ name: "startTime",
3397
+ type: "u64"
3398
+ },
3399
+ {
3400
+ name: "netAmountDeposited",
3401
+ type: "u64"
3402
+ },
3403
+ {
3404
+ name: "period",
3405
+ type: "u64"
3406
+ },
3407
+ {
3408
+ name: "amountPerPeriod",
3409
+ type: "u64"
3410
+ },
3411
+ {
3412
+ name: "cliff",
3413
+ type: "u64"
3414
+ },
3415
+ {
3416
+ name: "cliffAmount",
3417
+ type: "u64"
3418
+ },
3419
+ {
3420
+ name: "cancelableBySender",
3421
+ type: "bool"
3422
+ },
3423
+ {
3424
+ name: "cancelableByRecipient",
3425
+ type: "bool"
3426
+ },
3427
+ {
3428
+ name: "automaticWithdrawal",
3429
+ type: "bool"
3430
+ },
3431
+ {
3432
+ name: "transferableBySender",
3433
+ type: "bool"
3434
+ },
3435
+ {
3436
+ name: "transferableByRecipient",
3437
+ type: "bool"
3438
+ },
3439
+ {
3440
+ name: "canTopup",
3441
+ type: "bool"
3442
+ },
3443
+ {
3444
+ name: "streamName",
3445
+ type: {
3446
+ array: ["u8", 64]
3447
+ }
3448
+ },
3449
+ {
3450
+ name: "withdrawFrequency",
3451
+ type: "u64"
3452
+ }
3453
+ ]
3454
+ },
3455
+ {
3456
+ name: "withdraw",
3457
+ accounts: [
3458
+ {
3459
+ name: "authority",
3460
+ isMut: false,
3461
+ isSigner: true
3462
+ },
3463
+ {
3464
+ name: "recipient",
3465
+ isMut: true,
3466
+ isSigner: false
3467
+ },
3468
+ {
3469
+ name: "recipientTokens",
3470
+ isMut: true,
3471
+ isSigner: false
3472
+ },
3473
+ {
3474
+ name: "metadata",
3475
+ isMut: true,
3476
+ isSigner: false
3477
+ },
3478
+ {
3479
+ name: "escrowTokens",
3480
+ isMut: true,
3481
+ isSigner: false
3482
+ },
3483
+ {
3484
+ name: "streamflowTreasury",
3485
+ isMut: true,
3486
+ isSigner: false
3487
+ },
3488
+ {
3489
+ name: "streamflowTreasuryTokens",
3490
+ isMut: true,
3491
+ isSigner: false
3492
+ },
3493
+ {
3494
+ name: "partner",
3495
+ isMut: true,
3496
+ isSigner: false
3497
+ },
3498
+ {
3499
+ name: "partnerTokens",
3500
+ isMut: true,
3501
+ isSigner: false
3502
+ },
3503
+ {
3504
+ name: "mint",
3505
+ isMut: false,
3506
+ isSigner: false
3507
+ },
3508
+ {
3509
+ name: "tokenProgram",
3510
+ isMut: false,
3511
+ isSigner: false
3512
+ }
3513
+ ],
3514
+ args: [
3515
+ {
3516
+ name: "amount",
3517
+ type: "u64"
3518
+ }
3519
+ ]
3520
+ },
3521
+ {
3522
+ name: "cancel",
3523
+ accounts: [
3524
+ {
3525
+ name: "authority",
3526
+ isMut: false,
3527
+ isSigner: true
3528
+ },
3529
+ {
3530
+ name: "sender",
3531
+ isMut: true,
3532
+ isSigner: false
3533
+ },
3534
+ {
3535
+ name: "senderTokens",
3536
+ isMut: true,
3537
+ isSigner: false
3538
+ },
3539
+ {
3540
+ name: "recipient",
3541
+ isMut: true,
3542
+ isSigner: false
3543
+ },
3544
+ {
3545
+ name: "recipientTokens",
3546
+ isMut: true,
3547
+ isSigner: false
3548
+ },
3549
+ {
3550
+ name: "metadata",
3551
+ isMut: true,
3552
+ isSigner: false
3553
+ },
3554
+ {
3555
+ name: "escrowTokens",
3556
+ isMut: true,
3557
+ isSigner: false
3558
+ },
3559
+ {
3560
+ name: "streamflowTreasury",
3561
+ isMut: true,
3562
+ isSigner: false
3563
+ },
3564
+ {
3565
+ name: "streamflowTreasuryTokens",
3566
+ isMut: true,
3567
+ isSigner: false
3568
+ },
3569
+ {
3570
+ name: "partner",
3571
+ isMut: true,
3572
+ isSigner: false
3573
+ },
3574
+ {
3575
+ name: "partnerTokens",
3576
+ isMut: true,
3577
+ isSigner: false
3578
+ },
3579
+ {
3580
+ name: "mint",
3581
+ isMut: false,
3582
+ isSigner: false
3583
+ },
3584
+ {
3585
+ name: "tokenProgram",
3586
+ isMut: false,
3587
+ isSigner: false
3588
+ }
3589
+ ],
3590
+ args: []
3591
+ },
3592
+ {
3593
+ name: "transferRecipient",
3594
+ accounts: [
3595
+ {
3596
+ name: "authority",
3597
+ isMut: true,
3598
+ isSigner: true
3599
+ },
3600
+ {
3601
+ name: "newRecipient",
3602
+ isMut: true,
3603
+ isSigner: false
3604
+ },
3605
+ {
3606
+ name: "newRecipientTokens",
3607
+ isMut: true,
3608
+ isSigner: false
3609
+ },
3610
+ {
3611
+ name: "metadata",
3612
+ isMut: true,
3613
+ isSigner: false
3614
+ },
3615
+ {
3616
+ name: "mint",
3617
+ isMut: false,
3618
+ isSigner: false
3619
+ },
3620
+ {
3621
+ name: "rent",
3622
+ isMut: false,
3623
+ isSigner: false
3624
+ },
3625
+ {
3626
+ name: "tokenProgram",
3627
+ isMut: false,
3628
+ isSigner: false
3629
+ },
3630
+ {
3631
+ name: "associatedTokenProgram",
3632
+ isMut: false,
3633
+ isSigner: false
3634
+ },
3635
+ {
3636
+ name: "systemProgram",
3637
+ isMut: false,
3638
+ isSigner: false
3639
+ }
3640
+ ],
3641
+ args: []
3642
+ },
3643
+ {
3644
+ name: "topup",
3645
+ accounts: [
3646
+ {
3647
+ name: "sender",
3648
+ isMut: true,
3649
+ isSigner: true
3650
+ },
3651
+ {
3652
+ name: "senderTokens",
3653
+ isMut: true,
3654
+ isSigner: false
3655
+ },
3656
+ {
3657
+ name: "metadata",
3658
+ isMut: true,
3659
+ isSigner: false
3660
+ },
3661
+ {
3662
+ name: "escrowTokens",
3663
+ isMut: true,
3664
+ isSigner: false
3665
+ },
3666
+ {
3667
+ name: "streamflowTreasury",
3668
+ isMut: true,
3669
+ isSigner: false
3670
+ },
3671
+ {
3672
+ name: "streamflowTreasuryTokens",
3673
+ isMut: true,
3674
+ isSigner: false
3675
+ },
3676
+ {
3677
+ name: "withdrawor",
3678
+ isMut: true,
3679
+ isSigner: false
3680
+ },
3681
+ {
3682
+ name: "partner",
3683
+ isMut: true,
3684
+ isSigner: false
3685
+ },
3686
+ {
3687
+ name: "partnerTokens",
3688
+ isMut: true,
3689
+ isSigner: false
3690
+ },
3691
+ {
3692
+ name: "mint",
3693
+ isMut: false,
3694
+ isSigner: false
3695
+ },
3696
+ {
3697
+ name: "tokenProgram",
3698
+ isMut: false,
3699
+ isSigner: false
3700
+ },
3701
+ {
3702
+ name: "systemProgram",
3703
+ isMut: false,
3704
+ isSigner: false
3705
+ }
3706
+ ],
3707
+ args: [
3708
+ {
3709
+ name: "amount",
3710
+ type: "u64"
3711
+ }
3712
+ ]
3713
+ }
3714
+ ]
3715
+ };
3716
+
3717
+ Object.defineProperty(exports, "ContractError", {
3718
+ enumerable: true,
3719
+ get: function () { return common.ContractError; }
3720
+ });
3721
+ Object.defineProperty(exports, "IChain", {
3722
+ enumerable: true,
3723
+ get: function () { return common.IChain; }
3724
+ });
3725
+ Object.defineProperty(exports, "ICluster", {
3726
+ enumerable: true,
3727
+ get: function () { return common.ICluster; }
3728
+ });
3729
+ exports.AlignedContract = AlignedContract;
3730
+ exports.Contract = Contract;
3731
+ exports.SolanaStreamClient = SolanaStreamClient;
3732
+ exports.cancelStreamInstruction = cancelStreamInstruction;
3733
+ exports.constants = constants_exports;
3734
+ exports.createStreamInstruction = createStreamInstruction;
3735
+ exports.createUncheckedStreamInstruction = createUncheckedStreamInstruction;
3736
+ exports.decodeStream = decodeStream;
3737
+ exports.deriveContractPDA = deriveContractPDA;
3738
+ exports.deriveEscrowPDA = deriveEscrowPDA;
3739
+ exports.deriveTestOraclePDA = deriveTestOraclePDA;
3740
+ exports.extractSolanaErrorCode = extractSolanaErrorCode;
3741
+ exports.sendAndConfirmStreamRawTransaction = sendAndConfirmStreamRawTransaction;
3742
+ exports.signAllTransactionWithRecipients = signAllTransactionWithRecipients;
3743
+ exports.timelockIDL = timelockIDL_default;
3744
+ exports.topupStreamInstruction = topupStreamInstruction;
3745
+ exports.transferStreamInstruction = transferStreamInstruction;
3746
+ exports.updateStreamInstruction = updateStreamInstruction;
3747
+ exports.withdrawStreamInstruction = withdrawStreamInstruction;
3748
+ //# sourceMappingURL=index.cjs.map
3749
+ //# sourceMappingURL=index.cjs.map