@streamflow/stream 7.5.3 → 8.0.0-alpha.p284.726ba98

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 +7202 -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 +3762 -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 +7109 -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 +3706 -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,3762 @@
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, metadata);
2184
+ const signature = await solana.signAndExecuteTransaction(
2185
+ this.connection,
2186
+ extParams.sender,
2187
+ tx,
2188
+ {
2189
+ hash,
2190
+ context,
2191
+ commitment: this.getCommitment()
2192
+ },
2193
+ this.schedulingParams
2194
+ );
2195
+ return { ixs, txId: signature, metadataId: metadataPubKey.toBase58() };
2196
+ }
2197
+ async prepareCreateInstructions(streamParams, extParams) {
2198
+ const { ixs, metadata, metadataPubKey } = isCreateAlignedStreamData(streamParams) ? await this.prepareCreateAlignedUnlockInstructions(streamParams, extParams) : await this.prepareCreateStreamInstructions(streamParams, extParams);
2199
+ return { ixs, metadata, metadataPubKey };
2200
+ }
2201
+ async prepareCreateAlignedUnlockInstructions(streamParams, extParams) {
2202
+ const {
2203
+ tokenId: mint,
2204
+ start,
2205
+ period,
2206
+ cliff,
2207
+ canTopup,
2208
+ cancelableBySender,
2209
+ cancelableByRecipient,
2210
+ transferableBySender,
2211
+ transferableByRecipient,
2212
+ partner,
2213
+ recipient,
2214
+ cliffAmount,
2215
+ amountPerPeriod,
2216
+ amount: depositedAmount,
2217
+ name: streamName,
2218
+ minPrice,
2219
+ maxPercentage,
2220
+ minPercentage,
2221
+ maxPrice,
2222
+ skipInitial,
2223
+ tickSize,
2224
+ priceOracle,
2225
+ oracleType,
2226
+ tokenProgramId: streamTokenProgramId
2227
+ } = streamParams;
2228
+ const { isNative, sender, computeLimit, computePrice, metadataPubKeys } = extParams;
2229
+ if (!sender.publicKey) {
2230
+ throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
2231
+ }
2232
+ if (!priceOracle && oracleType && oracleType !== "none") {
2233
+ throw new Error("Price oracle is required for the specified oracle type");
2234
+ }
2235
+ const recipientPublicKey = new web3_js.PublicKey(recipient);
2236
+ const mintPublicKey = isNative ? splToken.NATIVE_MINT : new web3_js.PublicKey(mint);
2237
+ const metadata = !metadataPubKeys ? web3_js.Keypair.generate() : void 0;
2238
+ const metadataPubKey = metadata ? metadata.publicKey : metadataPubKeys[0];
2239
+ if (!metadataPubKey) {
2240
+ throw new Error("Metadata public key is required");
2241
+ }
2242
+ let tokenProgramId = streamTokenProgramId ? new web3_js.PublicKey(streamTokenProgramId) : void 0;
2243
+ if (!tokenProgramId) {
2244
+ tokenProgramId = (await solana.getMintAndProgram(this.connection, mintPublicKey)).tokenProgramId;
2245
+ }
2246
+ const partnerPublicKey = partner ? new web3_js.PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
2247
+ const streamflowProgramPublicKey = new web3_js.PublicKey(this.programId);
2248
+ const escrowPDA = deriveEscrowPDA(streamflowProgramPublicKey, metadataPubKey);
2249
+ const oracle = priceOracle ?? deriveTestOraclePDA(this.alignedProxyProgram.programId, mintPublicKey, sender.publicKey);
2250
+ const ixs = solana.prepareBaseInstructions(this.connection, {
2251
+ computePrice,
2252
+ computeLimit: computeLimit ?? ALIGNED_COMPUTE_LIMIT
2253
+ });
2254
+ ixs.push(
2255
+ ...await this.getCreateATAInstructions([recipientPublicKey], mintPublicKey, sender, true, tokenProgramId)
2256
+ );
2257
+ const encodedUIntArray = new TextEncoder().encode(streamName);
2258
+ const streamNameArray = Array.from(encodedUIntArray);
2259
+ const createIx = await this.alignedProxyProgram.methods.create({
2260
+ startTime: new BN4__default.default(start),
2261
+ netAmountDeposited: depositedAmount,
2262
+ period: new BN4__default.default(period),
2263
+ amountPerPeriod,
2264
+ cliff: new BN4__default.default(cliff),
2265
+ cliffAmount,
2266
+ transferableBySender,
2267
+ transferableByRecipient,
2268
+ cancelableByRecipient,
2269
+ cancelableBySender,
2270
+ canTopup,
2271
+ oracleType: !!oracleType ? { [oracleType]: {} } : { none: {} },
2272
+ streamName: streamNameArray,
2273
+ minPrice: minPrice instanceof BN4__default.default ? minPrice : common.getBN(minPrice, ALIGNED_PRECISION_FACTOR_POW),
2274
+ maxPrice: maxPrice instanceof BN4__default.default ? maxPrice : common.getBN(maxPrice, ALIGNED_PRECISION_FACTOR_POW),
2275
+ minPercentage: minPercentage instanceof BN4__default.default ? minPercentage : common.getBN(minPercentage, ALIGNED_PRECISION_FACTOR_POW),
2276
+ maxPercentage: maxPercentage instanceof BN4__default.default ? maxPercentage : common.getBN(maxPercentage, ALIGNED_PRECISION_FACTOR_POW),
2277
+ tickSize: new BN4__default.default(tickSize || 1),
2278
+ skipInitial: skipInitial ?? false
2279
+ }).accountsPartial({
2280
+ payer: sender.publicKey,
2281
+ sender: sender.publicKey,
2282
+ streamMetadata: metadataPubKey,
2283
+ escrowTokens: escrowPDA,
2284
+ mint: mintPublicKey,
2285
+ partner: partnerPublicKey,
2286
+ recipient: recipientPublicKey,
2287
+ withdrawor: WITHDRAWOR_PUBLIC_KEY,
2288
+ feeOracle: FEE_ORACLE_PUBLIC_KEY,
2289
+ priceOracle: oracle,
2290
+ tokenProgram: tokenProgramId,
2291
+ streamflowProgram: this.programId
2292
+ }).instruction();
2293
+ ixs.push(createIx);
2294
+ return { ixs, metadata, metadataPubKey };
2295
+ }
2296
+ /**
2297
+ * Creates a new stream/vesting contract.
2298
+ * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
2299
+ */
2300
+ async prepareCreateStreamInstructions({
2301
+ recipient,
2302
+ tokenId: mint,
2303
+ start,
2304
+ amount: depositedAmount,
2305
+ period,
2306
+ cliff,
2307
+ cliffAmount,
2308
+ amountPerPeriod,
2309
+ name,
2310
+ canPause,
2311
+ canUpdateRate,
2312
+ canTopup,
2313
+ cancelableBySender,
2314
+ cancelableByRecipient,
2315
+ transferableBySender,
2316
+ transferableByRecipient,
2317
+ automaticWithdrawal = false,
2318
+ withdrawalFrequency = 0,
2319
+ partner,
2320
+ tokenProgramId: streamTokenProgramId
2321
+ }, { sender, metadataPubKeys, isNative = false, computePrice, computeLimit }) {
2322
+ if (!sender.publicKey) {
2323
+ throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
2324
+ }
2325
+ const ixs = solana.prepareBaseInstructions(this.connection, {
2326
+ computePrice,
2327
+ computeLimit
2328
+ });
2329
+ const mintPublicKey = isNative ? splToken.NATIVE_MINT : new web3_js.PublicKey(mint);
2330
+ const recipientPublicKey = new web3_js.PublicKey(recipient);
2331
+ const { metadata, metadataPubKey } = this.getOrCreateStreamMetadata(metadataPubKeys);
2332
+ const [escrowTokens] = web3_js.PublicKey.findProgramAddressSync(
2333
+ [buffer.Buffer.from("strm"), metadataPubKey.toBuffer()],
2334
+ this.programId
2335
+ );
2336
+ let tokenProgramId = streamTokenProgramId ? new web3_js.PublicKey(streamTokenProgramId) : void 0;
2337
+ if (!tokenProgramId) {
2338
+ tokenProgramId = (await solana.getMintAndProgram(this.connection, mintPublicKey)).tokenProgramId;
2339
+ }
2340
+ const senderTokens = await solana.ata(mintPublicKey, sender.publicKey, tokenProgramId);
2341
+ const recipientTokens = await solana.ata(mintPublicKey, recipientPublicKey, tokenProgramId);
2342
+ const streamflowTreasuryTokens = await solana.ata(mintPublicKey, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
2343
+ const partnerPublicKey = partner ? new web3_js.PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
2344
+ const partnerTokens = await solana.ata(mintPublicKey, partnerPublicKey, tokenProgramId);
2345
+ ixs.push(
2346
+ await createStreamInstruction(
2347
+ {
2348
+ start: new BN4__default.default(start),
2349
+ depositedAmount,
2350
+ period: new BN4__default.default(period),
2351
+ amountPerPeriod,
2352
+ cliff: new BN4__default.default(cliff),
2353
+ cliffAmount: new BN4__default.default(cliffAmount),
2354
+ cancelableBySender,
2355
+ cancelableByRecipient,
2356
+ automaticWithdrawal,
2357
+ transferableBySender,
2358
+ transferableByRecipient,
2359
+ canTopup,
2360
+ canUpdateRate: !!canUpdateRate,
2361
+ canPause: !!canPause,
2362
+ name,
2363
+ withdrawFrequency: new BN4__default.default(automaticWithdrawal ? withdrawalFrequency : period)
2364
+ },
2365
+ this.programId,
2366
+ {
2367
+ sender: sender.publicKey,
2368
+ senderTokens,
2369
+ recipient: new web3_js.PublicKey(recipient),
2370
+ metadata: metadataPubKey,
2371
+ escrowTokens,
2372
+ recipientTokens,
2373
+ streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
2374
+ streamflowTreasuryTokens,
2375
+ partner: partnerPublicKey,
2376
+ partnerTokens,
2377
+ mint: new web3_js.PublicKey(mint),
2378
+ feeOracle: FEE_ORACLE_PUBLIC_KEY,
2379
+ rent: web3_js.SYSVAR_RENT_PUBKEY,
2380
+ timelockProgram: this.programId,
2381
+ tokenProgram: tokenProgramId,
2382
+ associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
2383
+ withdrawor: WITHDRAWOR_PUBLIC_KEY,
2384
+ systemProgram: web3_js.SystemProgram.programId
2385
+ }
2386
+ )
2387
+ );
2388
+ return { ixs, metadata, metadataPubKey };
2389
+ }
2390
+ /**
2391
+ * Creates a new stream/vesting contract using unchecked instruction.
2392
+ *
2393
+ * Unchecked instruction differs from the regular in:
2394
+ * - does not check for initialized associated token account (wallets with no control over their ATA should not be used
2395
+ * as sender/recipient/partner or there are risks of funds being locked in the contract)
2396
+ * - initialized contract PDA off chain
2397
+ *
2398
+ * If you are not sure if you should use create or create_unchecked, go for create to be safer.
2399
+ */
2400
+ async createUnchecked(data, extParams) {
2401
+ const { ixs, metadata, metadataPubKey } = await this.prepareCreateUncheckedInstructions(data, extParams);
2402
+ const { tx, hash, context } = await solana.prepareTransaction(
2403
+ this.connection,
2404
+ ixs,
2405
+ extParams.sender.publicKey,
2406
+ void 0,
2407
+ metadata
2408
+ );
2409
+ const signature = await solana.signAndExecuteTransaction(
2410
+ this.connection,
2411
+ extParams.sender,
2412
+ tx,
2413
+ {
2414
+ hash,
2415
+ context,
2416
+ commitment: this.getCommitment()
2417
+ },
2418
+ this.schedulingParams
2419
+ );
2420
+ return { ixs, txId: signature, metadataId: metadataPubKey.toBase58() };
2421
+ }
2422
+ /**
2423
+ * Create Transaction instructions for `createUnchecked`
2424
+ */
2425
+ async prepareCreateUncheckedInstructions({
2426
+ recipient,
2427
+ tokenId: mint,
2428
+ start,
2429
+ amount: depositedAmount,
2430
+ period,
2431
+ cliff,
2432
+ cliffAmount,
2433
+ amountPerPeriod,
2434
+ name,
2435
+ canTopup,
2436
+ canUpdateRate,
2437
+ canPause,
2438
+ cancelableBySender,
2439
+ cancelableByRecipient,
2440
+ transferableBySender,
2441
+ transferableByRecipient,
2442
+ automaticWithdrawal = false,
2443
+ withdrawalFrequency = 0,
2444
+ partner
2445
+ }, { sender, metadataPubKeys, isNative = false, computePrice, computeLimit }) {
2446
+ if (!sender.publicKey) {
2447
+ throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
2448
+ }
2449
+ const mintPublicKey = new web3_js.PublicKey(mint);
2450
+ const recipientPublicKey = new web3_js.PublicKey(recipient);
2451
+ const { metadata, metadataPubKey } = this.getOrCreateStreamMetadata(metadataPubKeys);
2452
+ const rentToExempt = await this.connection.getMinimumBalanceForRentExemption(METADATA_ACC_SIZE);
2453
+ const createMetadataInstruction = web3_js.SystemProgram.createAccount({
2454
+ programId: this.programId,
2455
+ space: METADATA_ACC_SIZE,
2456
+ lamports: rentToExempt,
2457
+ fromPubkey: sender?.publicKey,
2458
+ newAccountPubkey: metadataPubKey
2459
+ });
2460
+ const [escrowTokens] = web3_js.PublicKey.findProgramAddressSync(
2461
+ [buffer.Buffer.from("strm"), metadataPubKey.toBuffer()],
2462
+ this.programId
2463
+ );
2464
+ const { tokenProgramId } = await solana.getMintAndProgram(this.connection, mintPublicKey);
2465
+ const senderTokens = await solana.ata(mintPublicKey, sender.publicKey, tokenProgramId);
2466
+ const partnerPublicKey = partner ? new web3_js.PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
2467
+ const ixs = solana.prepareBaseInstructions(this.connection, {
2468
+ computePrice,
2469
+ computeLimit
2470
+ });
2471
+ if (isNative) {
2472
+ const totalFee = await this.getTotalFee({ address: partnerPublicKey.toString() });
2473
+ const totalAmount = calculateTotalAmountToDeposit(depositedAmount, totalFee);
2474
+ ixs.push(...await solana.prepareWrappedAccount(this.connection, sender.publicKey, totalAmount));
2475
+ }
2476
+ const createInstruction = await createUncheckedStreamInstruction(
2477
+ {
2478
+ start: new BN4__default.default(start),
2479
+ depositedAmount,
2480
+ period: new BN4__default.default(period),
2481
+ amountPerPeriod,
2482
+ cliff: new BN4__default.default(cliff),
2483
+ cliffAmount: new BN4__default.default(cliffAmount),
2484
+ cancelableBySender,
2485
+ cancelableByRecipient,
2486
+ automaticWithdrawal,
2487
+ transferableBySender,
2488
+ transferableByRecipient,
2489
+ canTopup,
2490
+ canUpdateRate: !!canUpdateRate,
2491
+ canPause: !!canPause,
2492
+ name,
2493
+ withdrawFrequency: new BN4__default.default(automaticWithdrawal ? withdrawalFrequency : period),
2494
+ recipient: recipientPublicKey,
2495
+ partner: partnerPublicKey
2496
+ },
2497
+ this.programId,
2498
+ {
2499
+ sender: sender.publicKey,
2500
+ senderTokens,
2501
+ metadata: metadataPubKey,
2502
+ escrowTokens,
2503
+ mint: new web3_js.PublicKey(mint),
2504
+ feeOracle: FEE_ORACLE_PUBLIC_KEY,
2505
+ rent: web3_js.SYSVAR_RENT_PUBKEY,
2506
+ timelockProgram: this.programId,
2507
+ tokenProgram: tokenProgramId,
2508
+ withdrawor: WITHDRAWOR_PUBLIC_KEY,
2509
+ systemProgram: web3_js.SystemProgram.programId
2510
+ }
2511
+ );
2512
+ ixs.push(createMetadataInstruction, createInstruction);
2513
+ return { ixs, metadata, metadataPubKey };
2514
+ }
2515
+ /**
2516
+ * Creates multiple stream/vesting contracts.
2517
+ * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
2518
+ */
2519
+ async createMultiple(data, extParams) {
2520
+ const { recipients, ...streamParams } = data;
2521
+ const {
2522
+ sender,
2523
+ metadataPubKeys: metadataPubKeysExt,
2524
+ isNative,
2525
+ computePrice,
2526
+ computeLimit,
2527
+ customInstructions
2528
+ } = extParams;
2529
+ const metadatas = [];
2530
+ const metadataToRecipient = {};
2531
+ const errors = [];
2532
+ const signatures = [];
2533
+ const batch = [];
2534
+ const instructionsBatch = [];
2535
+ const metadataPubKeys = metadataPubKeysExt || [];
2536
+ const partnerPublicKey = data.partner ? new web3_js.PublicKey(data.partner) : WITHDRAWOR_PUBLIC_KEY;
2537
+ const mintPublicKey = new web3_js.PublicKey(data.tokenId);
2538
+ if (recipients.length === 0) {
2539
+ throw new Error("Recipients array is empty!");
2540
+ }
2541
+ if (!sender.publicKey) {
2542
+ throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
2543
+ }
2544
+ for (let i = 0; i < recipients.length; i++) {
2545
+ const recipientData = recipients[i];
2546
+ const createStreamData = { ...streamParams, ...recipientData };
2547
+ const createStreamExtParams = {
2548
+ sender,
2549
+ metadataPubKeys: metadataPubKeys[i] ? [metadataPubKeys[i]] : void 0,
2550
+ computePrice,
2551
+ computeLimit,
2552
+ customInstructions
2553
+ };
2554
+ const { ixs, metadata, metadataPubKey } = await this.prepareCreateInstructions(
2555
+ createStreamData,
2556
+ createStreamExtParams
2557
+ );
2558
+ await this.applyCustomAfterInstructions(ixs, customInstructions, metadataPubKey);
2559
+ metadataToRecipient[metadataPubKey.toBase58()] = recipientData;
2560
+ metadatas.push(metadataPubKey.toBase58());
2561
+ instructionsBatch.push({
2562
+ ixs,
2563
+ metadata,
2564
+ recipient: recipientData.recipient
2565
+ });
2566
+ }
2567
+ const { value: hash, context } = await this.connection.getLatestBlockhashAndContext();
2568
+ for (const { ixs, metadata, recipient } of instructionsBatch) {
2569
+ const messageV0 = new web3_js.TransactionMessage({
2570
+ payerKey: sender.publicKey,
2571
+ recentBlockhash: hash.blockhash,
2572
+ instructions: ixs
2573
+ }).compileToV0Message();
2574
+ const tx = new web3_js.VersionedTransaction(messageV0);
2575
+ if (metadata) {
2576
+ tx.sign([metadata]);
2577
+ }
2578
+ batch.push({ tx, recipient });
2579
+ }
2580
+ const prepareInstructions = await this.getCreateATAInstructions(
2581
+ [STREAMFLOW_TREASURY_PUBLIC_KEY, partnerPublicKey],
2582
+ mintPublicKey,
2583
+ sender,
2584
+ true
2585
+ );
2586
+ if (isNative) {
2587
+ const totalDepositedAmount = recipients.reduce((acc, recipient) => recipient.amount.add(acc), new BN4__default.default(0));
2588
+ const nativeInstructions = await solana.prepareWrappedAccount(this.connection, sender.publicKey, totalDepositedAmount);
2589
+ prepareInstructions.push(...nativeInstructions);
2590
+ }
2591
+ if (prepareInstructions.length > 0) {
2592
+ const messageV0 = new web3_js.TransactionMessage({
2593
+ payerKey: sender.publicKey,
2594
+ recentBlockhash: hash.blockhash,
2595
+ instructions: prepareInstructions
2596
+ }).compileToV0Message();
2597
+ const tx = new web3_js.VersionedTransaction(messageV0);
2598
+ batch.push({
2599
+ tx,
2600
+ recipient: sender.publicKey.toBase58()
2601
+ });
2602
+ }
2603
+ const signedBatch = await signAllTransactionWithRecipients(sender, batch);
2604
+ if (prepareInstructions.length > 0) {
2605
+ const prepareTx = signedBatch.pop();
2606
+ await sendAndConfirmStreamRawTransaction(this.connection, prepareTx, { hash, context }, this.schedulingParams);
2607
+ }
2608
+ const responses = [];
2609
+ if (metadataPubKeys.length > 0) {
2610
+ for (const batchTx of signedBatch) {
2611
+ responses.push(
2612
+ ...await Promise.allSettled([
2613
+ solana.executeTransaction(this.connection, batchTx.tx, { hash, context }, this.schedulingParams)
2614
+ ])
2615
+ );
2616
+ }
2617
+ } else {
2618
+ responses.push(
2619
+ ...await solana.executeMultipleTransactions(
2620
+ this.connection,
2621
+ signedBatch.map((item) => item.tx),
2622
+ { hash, context },
2623
+ this.schedulingParams
2624
+ )
2625
+ );
2626
+ }
2627
+ responses.forEach((item, index) => {
2628
+ if (item.status === "fulfilled") {
2629
+ signatures.push(item.value);
2630
+ } else {
2631
+ errors.push({
2632
+ recipient: signedBatch[index].recipient,
2633
+ error: item.reason,
2634
+ contractErrorCode: this.extractErrorCode(item.reason) || void 0
2635
+ });
2636
+ }
2637
+ });
2638
+ return { txs: signatures, metadatas, metadataToRecipient, errors };
2639
+ }
2640
+ /**
2641
+ * Creates multiple stream/vesting contracts, and send all transactions sequentially.
2642
+ * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
2643
+ * In most cases, createMultiple should be used instead.
2644
+ */
2645
+ async createMultipleSequential(data, extParams) {
2646
+ const { recipients, ...streamParams } = data;
2647
+ const {
2648
+ sender,
2649
+ metadataPubKeys: metadataPubKeysExt,
2650
+ isNative,
2651
+ computePrice,
2652
+ computeLimit,
2653
+ customInstructions
2654
+ } = extParams;
2655
+ const metadatas = [];
2656
+ const metadataToRecipient = {};
2657
+ const errors = [];
2658
+ const signatures = [];
2659
+ const batch = [];
2660
+ const instructionsBatch = [];
2661
+ const metadataPubKeys = metadataPubKeysExt || [];
2662
+ const partnerPublicKey = data.partner ? new web3_js.PublicKey(data.partner) : WITHDRAWOR_PUBLIC_KEY;
2663
+ const mintPublicKey = new web3_js.PublicKey(data.tokenId);
2664
+ if (recipients.length === 0) {
2665
+ throw new Error("Recipients array is empty!");
2666
+ }
2667
+ if (!sender.publicKey) {
2668
+ throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
2669
+ }
2670
+ for (let i = 0; i < recipients.length; i++) {
2671
+ const recipientData = recipients[i];
2672
+ const createStreamData = { ...streamParams, ...recipientData };
2673
+ const createStreamExtParams = {
2674
+ sender,
2675
+ metadataPubKeys: metadataPubKeys[i] ? [metadataPubKeys[i]] : void 0,
2676
+ computePrice,
2677
+ computeLimit,
2678
+ customInstructions
2679
+ };
2680
+ const { ixs, metadata, metadataPubKey } = await this.prepareCreateInstructions(
2681
+ createStreamData,
2682
+ createStreamExtParams
2683
+ );
2684
+ await this.applyCustomAfterInstructions(ixs, customInstructions, metadataPubKey);
2685
+ metadataToRecipient[metadataPubKey.toBase58()] = recipientData;
2686
+ metadatas.push(metadataPubKey.toBase58());
2687
+ instructionsBatch.push({
2688
+ ixs,
2689
+ metadata,
2690
+ recipient: recipientData.recipient
2691
+ });
2692
+ }
2693
+ const { value: hash, context } = await this.connection.getLatestBlockhashAndContext();
2694
+ for (const { ixs, metadata, recipient } of instructionsBatch) {
2695
+ const messageV0 = new web3_js.TransactionMessage({
2696
+ payerKey: sender.publicKey,
2697
+ recentBlockhash: hash.blockhash,
2698
+ instructions: ixs
2699
+ }).compileToV0Message();
2700
+ const tx = new web3_js.VersionedTransaction(messageV0);
2701
+ if (metadata) {
2702
+ tx.sign([metadata]);
2703
+ }
2704
+ batch.push({ tx, recipient });
2705
+ }
2706
+ const prepareInstructions = await this.getCreateATAInstructions(
2707
+ [STREAMFLOW_TREASURY_PUBLIC_KEY, partnerPublicKey],
2708
+ mintPublicKey,
2709
+ sender,
2710
+ true
2711
+ );
2712
+ if (isNative) {
2713
+ const totalDepositedAmount = recipients.reduce((acc, recipient) => recipient.amount.add(acc), new BN4__default.default(0));
2714
+ const nativeInstructions = await solana.prepareWrappedAccount(this.connection, sender.publicKey, totalDepositedAmount);
2715
+ prepareInstructions.push(...nativeInstructions);
2716
+ }
2717
+ if (prepareInstructions.length > 0) {
2718
+ const messageV0 = new web3_js.TransactionMessage({
2719
+ payerKey: sender.publicKey,
2720
+ recentBlockhash: hash.blockhash,
2721
+ instructions: prepareInstructions
2722
+ }).compileToV0Message();
2723
+ const tx = new web3_js.VersionedTransaction(messageV0);
2724
+ batch.push({
2725
+ tx,
2726
+ recipient: sender.publicKey.toBase58()
2727
+ });
2728
+ }
2729
+ const signedBatch = await signAllTransactionWithRecipients(sender, batch);
2730
+ if (prepareInstructions.length > 0) {
2731
+ const prepareTx = signedBatch.shift();
2732
+ await sendAndConfirmStreamRawTransaction(this.connection, prepareTx, { hash, context }, this.schedulingParams);
2733
+ }
2734
+ const responses = [];
2735
+ for (const batchTx of signedBatch) {
2736
+ responses.push(
2737
+ ...await Promise.allSettled([
2738
+ solana.executeTransaction(this.connection, batchTx.tx, { hash, context }, this.schedulingParams)
2739
+ ])
2740
+ );
2741
+ }
2742
+ responses.forEach((item, index) => {
2743
+ if (item.status === "fulfilled") {
2744
+ signatures.push(item.value);
2745
+ } else {
2746
+ errors.push({
2747
+ recipient: signedBatch[index].recipient,
2748
+ error: item.reason,
2749
+ contractErrorCode: this.extractErrorCode(item.reason) || void 0
2750
+ });
2751
+ }
2752
+ });
2753
+ return { txs: signatures, metadatas, metadataToRecipient, errors };
2754
+ }
2755
+ /**
2756
+ * Attempts withdrawing from the specified stream.
2757
+ */
2758
+ async withdraw({ id, amount = WITHDRAW_AVAILABLE_AMOUNT }, extParams) {
2759
+ const { invoker, customInstructions } = extParams;
2760
+ if (!invoker.publicKey) {
2761
+ throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
2762
+ }
2763
+ const ixs = await this.prepareWithdrawInstructions({ id, amount }, extParams);
2764
+ const metadata = new web3_js.PublicKey(id);
2765
+ await this.applyCustomAfterInstructions(ixs, customInstructions, metadata);
2766
+ const { tx, hash, context } = await solana.prepareTransaction(this.connection, ixs, invoker.publicKey);
2767
+ const signature = await solana.signAndExecuteTransaction(
2768
+ this.connection,
2769
+ extParams.invoker,
2770
+ tx,
2771
+ {
2772
+ hash,
2773
+ context,
2774
+ commitment: this.getCommitment()
2775
+ },
2776
+ this.schedulingParams
2777
+ );
2778
+ return { ixs, txId: signature };
2779
+ }
2780
+ /**
2781
+ * Creates Transaction Instructions for withdrawal
2782
+ */
2783
+ async prepareWithdrawInstructions({ id, amount = WITHDRAW_AVAILABLE_AMOUNT }, { invoker, checkTokenAccounts, computePrice, computeLimit }) {
2784
+ if (!invoker.publicKey) {
2785
+ throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
2786
+ }
2787
+ const ixs = solana.prepareBaseInstructions(this.connection, {
2788
+ computePrice,
2789
+ computeLimit
2790
+ });
2791
+ const streamPublicKey = new web3_js.PublicKey(id);
2792
+ const escrow = await this.connection.getAccountInfo(streamPublicKey);
2793
+ if (!escrow?.data) {
2794
+ throw new Error("Couldn't get account info");
2795
+ }
2796
+ const data = decodeStream(escrow.data);
2797
+ const { sender, recipient, mint, streamflowTreasury, partner, recipientTokens, escrowTokens } = data;
2798
+ const { tokenProgramId } = await solana.getMintAndProgram(this.connection, mint);
2799
+ const streamflowTreasuryTokens = await solana.ata(mint, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
2800
+ const partnerTokens = await solana.ata(mint, partner, tokenProgramId);
2801
+ const ataIx = await this.getCreateATAInstructions(
2802
+ [sender, recipient, streamflowTreasury, partner],
2803
+ mint,
2804
+ invoker,
2805
+ checkTokenAccounts,
2806
+ tokenProgramId
2807
+ );
2808
+ ixs.push(
2809
+ ...ataIx,
2810
+ await withdrawStreamInstruction(amount, this.programId, {
2811
+ partner,
2812
+ partnerTokens,
2813
+ mint,
2814
+ streamflowTreasuryTokens,
2815
+ recipientTokens,
2816
+ escrowTokens,
2817
+ authority: invoker.publicKey,
2818
+ recipient: invoker.publicKey,
2819
+ metadata: streamPublicKey,
2820
+ streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
2821
+ tokenProgram: tokenProgramId
2822
+ })
2823
+ );
2824
+ return ixs;
2825
+ }
2826
+ /**
2827
+ * Attempts canceling the specified stream.
2828
+ */
2829
+ async cancel(cancelData, extParams) {
2830
+ const ixs = await this.prepareCancelInstructions(cancelData, extParams);
2831
+ const { tx, hash, context } = await solana.prepareTransaction(this.connection, ixs, extParams.invoker.publicKey);
2832
+ const signature = await solana.signAndExecuteTransaction(
2833
+ this.connection,
2834
+ extParams.invoker,
2835
+ tx,
2836
+ {
2837
+ hash,
2838
+ context,
2839
+ commitment: this.getCommitment()
2840
+ },
2841
+ this.schedulingParams
2842
+ );
2843
+ return { ixs, txId: signature };
2844
+ }
2845
+ async prepareCancelInstructions(cancelData, extParams) {
2846
+ const streamPublicKey = new web3_js.PublicKey(cancelData.id);
2847
+ const account = await this.connection.getAccountInfo(streamPublicKey);
2848
+ if (!account) {
2849
+ throw new Error("Impossible to cancel a stream contract that does not exist");
2850
+ }
2851
+ const { sender: senderPublicKey } = decodeStream(account.data);
2852
+ const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey, senderPublicKey);
2853
+ const ixs = isAlignedUnlock ? await this.prepareCancelAlignedUnlockInstructions(cancelData, extParams) : await this.prepareCancelStreamInstructions(cancelData, extParams);
2854
+ return ixs;
2855
+ }
2856
+ async prepareCancelAlignedUnlockInstructions({ id }, { invoker, checkTokenAccounts, computePrice, computeLimit }) {
2857
+ if (!invoker.publicKey) {
2858
+ throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
2859
+ }
2860
+ const streamPublicKey = new web3_js.PublicKey(id);
2861
+ const escrowAcc = await this.connection.getAccountInfo(streamPublicKey);
2862
+ if (!escrowAcc?.data) {
2863
+ throw new Error("Couldn't get account info");
2864
+ }
2865
+ const streamData = decodeStream(escrowAcc.data);
2866
+ const { sender, recipient, mint, streamflowTreasury, partner, escrowTokens } = streamData;
2867
+ const { tokenProgramId } = await solana.getMintAndProgram(this.connection, mint);
2868
+ const ixs = solana.prepareBaseInstructions(this.connection, {
2869
+ computePrice,
2870
+ computeLimit: computeLimit ?? ALIGNED_COMPUTE_LIMIT
2871
+ });
2872
+ const ataIx = await this.getCreateATAInstructions(
2873
+ [sender, recipient, partner, streamflowTreasury],
2874
+ mint,
2875
+ invoker,
2876
+ checkTokenAccounts,
2877
+ tokenProgramId
2878
+ );
2879
+ const cancelIx = await this.alignedProxyProgram.methods.cancel().accountsPartial({
2880
+ mint,
2881
+ partner,
2882
+ recipient,
2883
+ escrowTokens,
2884
+ sender: invoker.publicKey,
2885
+ streamMetadata: streamPublicKey,
2886
+ streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
2887
+ tokenProgram: tokenProgramId,
2888
+ streamflowProgram: this.programId
2889
+ }).instruction();
2890
+ ixs.push(...ataIx, cancelIx);
2891
+ return ixs;
2892
+ }
2893
+ /**
2894
+ * Creates Transaction Instructions for cancel
2895
+ */
2896
+ async prepareCancelStreamInstructions({ id }, { invoker, checkTokenAccounts, computePrice, computeLimit }) {
2897
+ if (!invoker.publicKey) {
2898
+ throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
2899
+ }
2900
+ const streamPublicKey = new web3_js.PublicKey(id);
2901
+ const escrowAcc = await this.connection.getAccountInfo(streamPublicKey);
2902
+ if (!escrowAcc?.data) {
2903
+ throw new Error("Couldn't get account info");
2904
+ }
2905
+ const data = decodeStream(escrowAcc.data);
2906
+ const { sender, recipient, partner, streamflowTreasury, mint, senderTokens, recipientTokens, escrowTokens } = data;
2907
+ const { tokenProgramId } = await solana.getMintAndProgram(this.connection, mint);
2908
+ const streamflowTreasuryTokens = await solana.ata(mint, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
2909
+ const partnerTokens = await solana.ata(mint, partner, tokenProgramId);
2910
+ const ixs = solana.prepareBaseInstructions(this.connection, {
2911
+ computePrice,
2912
+ computeLimit
2913
+ });
2914
+ const ixsAta = await this.getCreateATAInstructions(
2915
+ [sender, recipient, partner, streamflowTreasury],
2916
+ mint,
2917
+ invoker,
2918
+ checkTokenAccounts,
2919
+ tokenProgramId
2920
+ );
2921
+ ixs.push(
2922
+ ...ixsAta,
2923
+ await cancelStreamInstruction(this.programId, {
2924
+ sender,
2925
+ senderTokens,
2926
+ recipient,
2927
+ recipientTokens,
2928
+ streamflowTreasuryTokens,
2929
+ partner,
2930
+ partnerTokens,
2931
+ mint,
2932
+ escrowTokens,
2933
+ authority: invoker.publicKey,
2934
+ metadata: streamPublicKey,
2935
+ streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
2936
+ tokenProgram: tokenProgramId
2937
+ })
2938
+ );
2939
+ return ixs;
2940
+ }
2941
+ /**
2942
+ * Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
2943
+ * Potential associated token account rent fee (to make it rent-exempt) is paid by the transaction initiator.
2944
+ */
2945
+ async transfer({ id, newRecipient }, extParams) {
2946
+ const ixs = await this.prepareTransferInstructions({ id, newRecipient }, extParams);
2947
+ const { tx, hash, context } = await solana.prepareTransaction(this.connection, ixs, extParams.invoker.publicKey);
2948
+ const signature = await solana.signAndExecuteTransaction(
2949
+ this.connection,
2950
+ extParams.invoker,
2951
+ tx,
2952
+ {
2953
+ hash,
2954
+ context,
2955
+ commitment: this.getCommitment()
2956
+ },
2957
+ this.schedulingParams
2958
+ );
2959
+ return { ixs, txId: signature };
2960
+ }
2961
+ /**
2962
+ * Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
2963
+ * Potential associated token account rent fee (to make it rent-exempt) is paid by the transaction initiator.
2964
+ */
2965
+ async prepareTransferInstructions({ id, newRecipient }, { invoker, computePrice, computeLimit = 100001 }) {
2966
+ if (!invoker.publicKey) {
2967
+ throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
2968
+ }
2969
+ const ixs = solana.prepareBaseInstructions(this.connection, {
2970
+ computePrice,
2971
+ computeLimit
2972
+ });
2973
+ const stream = new web3_js.PublicKey(id);
2974
+ const newRecipientPublicKey = new web3_js.PublicKey(newRecipient);
2975
+ const escrow = await this.connection.getAccountInfo(stream);
2976
+ if (!escrow?.data) {
2977
+ throw new Error("Couldn't get account info");
2978
+ }
2979
+ const { mint } = decodeStream(escrow?.data);
2980
+ const { tokenProgramId } = await solana.getMintAndProgram(this.connection, mint);
2981
+ const newRecipientTokens = await solana.ata(mint, newRecipientPublicKey, tokenProgramId);
2982
+ ixs.push(
2983
+ await transferStreamInstruction(this.programId, {
2984
+ authority: invoker.publicKey,
2985
+ newRecipient: newRecipientPublicKey,
2986
+ newRecipientTokens,
2987
+ metadata: stream,
2988
+ mint,
2989
+ rent: web3_js.SYSVAR_RENT_PUBKEY,
2990
+ tokenProgram: tokenProgramId,
2991
+ associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
2992
+ systemProgram: web3_js.SystemProgram.programId
2993
+ })
2994
+ );
2995
+ return ixs;
2996
+ }
2997
+ /**
2998
+ * Tops up stream account with specified amount.
2999
+ */
3000
+ async topup({ id, amount }, extParams) {
3001
+ const ixs = await this.prepareTopupInstructions({ id, amount }, extParams);
3002
+ const { tx, hash, context } = await solana.prepareTransaction(this.connection, ixs, extParams.invoker.publicKey);
3003
+ const signature = await solana.signAndExecuteTransaction(
3004
+ this.connection,
3005
+ extParams.invoker,
3006
+ tx,
3007
+ {
3008
+ hash,
3009
+ context,
3010
+ commitment: this.getCommitment()
3011
+ },
3012
+ this.schedulingParams
3013
+ );
3014
+ return { ixs, txId: signature };
3015
+ }
3016
+ /**
3017
+ * Create Transaction instructions for topup
3018
+ */
3019
+ async prepareTopupInstructions({ id, amount }, { invoker, isNative, computePrice, computeLimit }) {
3020
+ if (!invoker.publicKey) {
3021
+ throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
3022
+ }
3023
+ const ixs = solana.prepareBaseInstructions(this.connection, {
3024
+ computePrice,
3025
+ computeLimit
3026
+ });
3027
+ const streamPublicKey = new web3_js.PublicKey(id);
3028
+ const escrow = await this.connection.getAccountInfo(streamPublicKey);
3029
+ if (!escrow?.data) {
3030
+ throw new Error("Couldn't get account info");
3031
+ }
3032
+ const { mint, partner, senderTokens, escrowTokens } = decodeStream(escrow?.data);
3033
+ const { tokenProgramId } = await solana.getMintAndProgram(this.connection, mint);
3034
+ const streamflowTreasuryTokens = await solana.ata(mint, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
3035
+ const partnerTokens = await solana.ata(mint, partner, tokenProgramId);
3036
+ if (isNative) {
3037
+ ixs.push(...await solana.prepareWrappedAccount(this.connection, invoker.publicKey, amount));
3038
+ }
3039
+ ixs.push(
3040
+ await topupStreamInstruction(amount, this.programId, {
3041
+ sender: invoker.publicKey,
3042
+ senderTokens,
3043
+ metadata: streamPublicKey,
3044
+ escrowTokens,
3045
+ streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
3046
+ streamflowTreasuryTokens,
3047
+ partner,
3048
+ partnerTokens,
3049
+ mint,
3050
+ tokenProgram: tokenProgramId,
3051
+ withdrawor: WITHDRAWOR_PUBLIC_KEY,
3052
+ systemProgram: web3_js.SystemProgram.programId
3053
+ })
3054
+ );
3055
+ return ixs;
3056
+ }
3057
+ /**
3058
+ * Fetch stream data by its id (address).
3059
+ */
3060
+ async getOne({ id }) {
3061
+ const streamPublicKey = new web3_js.PublicKey(id);
3062
+ const escrow = await this.connection.getAccountInfo(streamPublicKey, TX_FINALITY_CONFIRMED);
3063
+ if (!escrow?.data) {
3064
+ throw new Error("Couldn't get account info.");
3065
+ }
3066
+ const stream = decodeStream(escrow.data);
3067
+ if (this.isAlignedUnlock(streamPublicKey, stream.sender)) {
3068
+ const alignedProxy = await this.alignedProxyProgram.account.contract.fetch(
3069
+ deriveContractPDA(this.alignedProxyProgram.programId, streamPublicKey)
3070
+ );
3071
+ if (!alignedProxy) {
3072
+ throw new Error("Couldn't get proxy account info.");
3073
+ }
3074
+ return new AlignedContract(stream, alignedProxy);
3075
+ }
3076
+ return new Contract(stream);
3077
+ }
3078
+ /**
3079
+ * Fetch all aligned outgoing streams/contracts by the provided public key.
3080
+ */
3081
+ async getOutgoingAlignedStreams(sender) {
3082
+ const streams = {};
3083
+ const alignedOutgoingProgramAccounts = await this.alignedProxyProgram.account.contract.all([
3084
+ {
3085
+ memcmp: {
3086
+ offset: ORIGINAL_CONTRACT_SENDER_OFFSET,
3087
+ bytes: sender
3088
+ }
3089
+ },
3090
+ {
3091
+ dataSize: ALIGNED_METADATA_ACC_SIZE
3092
+ }
3093
+ ]);
3094
+ const streamPubKeys = alignedOutgoingProgramAccounts.map((account) => account.account.stream);
3095
+ const streamAccounts = await solana.getMultipleAccountsInfoBatched(this.connection, streamPubKeys, TX_FINALITY_CONFIRMED);
3096
+ streamAccounts.forEach((account, index) => {
3097
+ if (account) {
3098
+ const alignedData = alignedOutgoingProgramAccounts[index].account;
3099
+ streams[streamPubKeys[index].toBase58()] = new AlignedContract(decodeStream(account.data), alignedData);
3100
+ }
3101
+ });
3102
+ return streams;
3103
+ }
3104
+ async getIncomingAlignedStreams(streamRecord) {
3105
+ const streams = {};
3106
+ const alignedStreamsPubKeys = Object.keys(streamRecord);
3107
+ const alignedProxyPDAs = alignedStreamsPubKeys.map(
3108
+ (streamPubKey) => deriveContractPDA(this.alignedProxyProgram.programId, new web3_js.PublicKey(streamPubKey))
3109
+ );
3110
+ const alignedProxyAccounts = await solana.getMultipleAccountsInfoBatched(this.connection, alignedProxyPDAs);
3111
+ alignedProxyAccounts.forEach((account, index) => {
3112
+ if (account && account.data.length === ALIGNED_METADATA_ACC_SIZE) {
3113
+ const alignedData = streamRecord[alignedStreamsPubKeys[index]];
3114
+ streams[alignedStreamsPubKeys[index]] = new AlignedContract(
3115
+ alignedData,
3116
+ this.alignedProxyProgram.account.contract.coder.accounts.decode("contract", account.data)
3117
+ );
3118
+ }
3119
+ });
3120
+ return streams;
3121
+ }
3122
+ /**
3123
+ * Fetch streams/contracts by providing direction.
3124
+ * Streams are sorted by start time in ascending order.
3125
+ */
3126
+ async get({
3127
+ address,
3128
+ type = "all" /* All */,
3129
+ direction = "all" /* All */
3130
+ }) {
3131
+ const publicKey = new web3_js.PublicKey(address);
3132
+ let streams = {};
3133
+ const shouldFetchAligned = type === "all" /* All */ || type === "vesting" /* Vesting */;
3134
+ if (direction !== "incoming" /* Incoming */) {
3135
+ const outgoingStreamAccounts = await solana.getProgramAccounts(
3136
+ this.connection,
3137
+ publicKey,
3138
+ STREAM_STRUCT_OFFSET_SENDER,
3139
+ this.programId
3140
+ );
3141
+ outgoingStreamAccounts.forEach((account) => {
3142
+ streams[account.pubkey.toBase58()] = new Contract(decodeStream(account.account.data));
3143
+ });
3144
+ if (shouldFetchAligned) {
3145
+ const alignedStreams = await this.getOutgoingAlignedStreams(address);
3146
+ streams = { ...streams, ...alignedStreams };
3147
+ }
3148
+ }
3149
+ if (direction !== "outgoing" /* Outgoing */) {
3150
+ const allIncomingAccounts = await solana.getProgramAccounts(
3151
+ this.connection,
3152
+ publicKey,
3153
+ STREAM_STRUCT_OFFSET_RECIPIENT,
3154
+ this.programId
3155
+ );
3156
+ const allIncomingStreams = allIncomingAccounts.map((account) => decodeStream(account.account.data));
3157
+ const alignedDecoded = {};
3158
+ allIncomingAccounts.forEach((account, index) => {
3159
+ if (this.isAlignedUnlock(account.pubkey, allIncomingStreams[index].sender)) {
3160
+ alignedDecoded[account.pubkey.toBase58()] = allIncomingStreams[index];
3161
+ } else {
3162
+ streams[account.pubkey.toBase58()] = new Contract(allIncomingStreams[index]);
3163
+ }
3164
+ });
3165
+ if (shouldFetchAligned) {
3166
+ const incomingAlignedStreams = await this.getIncomingAlignedStreams(alignedDecoded);
3167
+ streams = { ...streams, ...incomingAlignedStreams };
3168
+ }
3169
+ }
3170
+ const sortedStreams = Object.entries(streams).sort(([, stream1], [, stream2]) => stream2.start - stream1.start);
3171
+ if (type === "all" /* All */) return sortedStreams;
3172
+ return sortedStreams.filter((stream) => stream[1].type === type);
3173
+ }
3174
+ async searchStreams(data) {
3175
+ const filters = Object.entries(data).filter(([_, value]) => value !== void 0).map(([key, value]) => ({
3176
+ memcmp: {
3177
+ offset: STREAM_STRUCT_OFFSETS[key],
3178
+ bytes: typeof value === "boolean" ? bs58__default.default.encode([Number(value)]) : value.toString()
3179
+ }
3180
+ }));
3181
+ filters.push({ dataSize: METADATA_ACC_SIZE });
3182
+ const accounts = await this.connection.getProgramAccounts(this.programId, {
3183
+ filters
3184
+ });
3185
+ return accounts.map(({ pubkey, account }) => ({
3186
+ publicKey: pubkey,
3187
+ account: new Contract(decodeStream(account.data))
3188
+ }));
3189
+ }
3190
+ /**
3191
+ * Attempts updating the stream auto withdrawal params and amount per period
3192
+ */
3193
+ async update(data, extParams) {
3194
+ const ixs = await this.prepareUpdateInstructions(data, extParams);
3195
+ const { tx, hash, context } = await solana.prepareTransaction(this.connection, ixs, extParams.invoker.publicKey);
3196
+ const signature = await solana.signAndExecuteTransaction(
3197
+ this.connection,
3198
+ extParams.invoker,
3199
+ tx,
3200
+ {
3201
+ hash,
3202
+ context,
3203
+ commitment: this.getCommitment()
3204
+ },
3205
+ this.schedulingParams
3206
+ );
3207
+ return {
3208
+ ixs,
3209
+ txId: signature
3210
+ };
3211
+ }
3212
+ /**
3213
+ * Create Transaction instructions for update
3214
+ */
3215
+ async prepareUpdateInstructions(data, { invoker, computePrice, computeLimit }) {
3216
+ if (!invoker.publicKey) {
3217
+ throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
3218
+ }
3219
+ const streamPublicKey = new web3_js.PublicKey(data.id);
3220
+ const escrow = await this.connection.getAccountInfo(streamPublicKey);
3221
+ if (!escrow) {
3222
+ throw new Error("Couldn't get account info");
3223
+ }
3224
+ const ixs = solana.prepareBaseInstructions(this.connection, {
3225
+ computePrice,
3226
+ computeLimit
3227
+ });
3228
+ ixs.push(
3229
+ await updateStreamInstruction(data, this.programId, {
3230
+ authority: invoker.publicKey,
3231
+ metadata: streamPublicKey,
3232
+ withdrawor: WITHDRAWOR_PUBLIC_KEY,
3233
+ systemProgram: web3_js.SystemProgram.programId
3234
+ })
3235
+ );
3236
+ return ixs;
3237
+ }
3238
+ async getFees({ address }) {
3239
+ const [metadataPubKey] = web3_js.PublicKey.findProgramAddressSync(
3240
+ [buffer.Buffer.from(FEES_METADATA_SEED)],
3241
+ new web3_js.PublicKey(PARTNER_ORACLE_PROGRAM_ID)
3242
+ );
3243
+ const data = await this.connection.getAccountInfo(metadataPubKey);
3244
+ if (!data) {
3245
+ return null;
3246
+ }
3247
+ const partners = borsh__namespace.deserialize(PARTNERS_SCHEMA, data.data);
3248
+ const filteredPartners = partners.filter((item) => new web3_js.PublicKey(item.pubkey).toString() === address);
3249
+ if (filteredPartners.length === 0) {
3250
+ return null;
3251
+ }
3252
+ return {
3253
+ streamflowFee: Number(filteredPartners[0].strm_fee.toFixed(4)),
3254
+ partnerFee: Number(filteredPartners[0].partner_fee.toFixed(4))
3255
+ };
3256
+ }
3257
+ async getDefaultStreamflowFee() {
3258
+ return DEFAULT_STREAMFLOW_FEE;
3259
+ }
3260
+ extractErrorCode(err) {
3261
+ const logs = "logs" in err && Array.isArray(err.logs) ? err.logs : void 0;
3262
+ return extractSolanaErrorCode(err.toString() ?? "Unknown error!", logs);
3263
+ }
3264
+ /**
3265
+ * Utility function to generate metadata for a Contract or return existing Pubkey
3266
+ */
3267
+ getOrCreateStreamMetadata(metadataPubKeys) {
3268
+ let metadata;
3269
+ let metadataPubKey;
3270
+ if (!metadataPubKeys) {
3271
+ metadata = web3_js.Keypair.generate();
3272
+ metadataPubKey = metadata.publicKey;
3273
+ } else {
3274
+ metadataPubKey = metadataPubKeys[0];
3275
+ }
3276
+ return { metadata, metadataPubKey };
3277
+ }
3278
+ /**
3279
+ * Utility function that checks whether the associated stream address is an aligned unlock contract, indicated by whether the sender/creator is a PDA
3280
+ */
3281
+ isAlignedUnlock(streamPublicKey, senderPublicKey) {
3282
+ const pda = deriveContractPDA(this.alignedProxyProgram.programId, streamPublicKey);
3283
+ return senderPublicKey.equals(pda);
3284
+ }
3285
+ /**
3286
+ * Returns insrtuctions for creating associated token accounts for the provided owners
3287
+ */
3288
+ async getCreateATAInstructions(owners, mint, invoker, checkTokenAccounts, programId) {
3289
+ if (!checkTokenAccounts) {
3290
+ return [];
3291
+ }
3292
+ const uniqueOwners = Array.from(new Set(owners.map((owner) => owner.toBase58()))).map(
3293
+ (pkString) => new web3_js.PublicKey(pkString)
3294
+ );
3295
+ return solana.checkOrCreateAtaBatch(this.connection, uniqueOwners, mint, invoker, programId);
3296
+ }
3297
+ async applyCustomAfterInstructions(ixs, customInstructions, metadata) {
3298
+ if (customInstructions?.after) {
3299
+ const afterInstructions = typeof customInstructions.after === "function" ? await customInstructions.after({
3300
+ instructions: ixs,
3301
+ metadata
3302
+ }) : customInstructions.after;
3303
+ ixs.push(...afterInstructions);
3304
+ }
3305
+ }
3306
+ };
3307
+
3308
+ // solana/timelockIDL.ts
3309
+ var timelockIDL_default = {
3310
+ version: "0.1.0",
3311
+ name: "timelock",
3312
+ instructions: [
3313
+ {
3314
+ name: "create",
3315
+ accounts: [
3316
+ {
3317
+ name: "sender",
3318
+ isMut: true,
3319
+ isSigner: true
3320
+ },
3321
+ {
3322
+ name: "senderTokens",
3323
+ isMut: true,
3324
+ isSigner: false
3325
+ },
3326
+ {
3327
+ name: "recipient",
3328
+ isMut: true,
3329
+ isSigner: false
3330
+ },
3331
+ {
3332
+ name: "metadata",
3333
+ isMut: true,
3334
+ isSigner: true
3335
+ },
3336
+ {
3337
+ name: "escrowTokens",
3338
+ isMut: true,
3339
+ isSigner: false
3340
+ },
3341
+ {
3342
+ name: "recipientTokens",
3343
+ isMut: true,
3344
+ isSigner: false
3345
+ },
3346
+ {
3347
+ name: "streamflowTreasury",
3348
+ isMut: true,
3349
+ isSigner: false
3350
+ },
3351
+ {
3352
+ name: "streamflowTreasuryTokens",
3353
+ isMut: true,
3354
+ isSigner: false
3355
+ },
3356
+ {
3357
+ name: "withdrawor",
3358
+ isMut: true,
3359
+ isSigner: false
3360
+ },
3361
+ {
3362
+ name: "partner",
3363
+ isMut: true,
3364
+ isSigner: false
3365
+ },
3366
+ {
3367
+ name: "partnerTokens",
3368
+ isMut: true,
3369
+ isSigner: false
3370
+ },
3371
+ {
3372
+ name: "mint",
3373
+ isMut: false,
3374
+ isSigner: false
3375
+ },
3376
+ {
3377
+ name: "feeOracle",
3378
+ isMut: false,
3379
+ isSigner: false
3380
+ },
3381
+ {
3382
+ name: "rent",
3383
+ isMut: false,
3384
+ isSigner: false
3385
+ },
3386
+ {
3387
+ name: "timelockProgram",
3388
+ isMut: false,
3389
+ isSigner: false
3390
+ },
3391
+ {
3392
+ name: "tokenProgram",
3393
+ isMut: false,
3394
+ isSigner: false
3395
+ },
3396
+ {
3397
+ name: "associatedTokenProgram",
3398
+ isMut: false,
3399
+ isSigner: false
3400
+ },
3401
+ {
3402
+ name: "systemProgram",
3403
+ isMut: false,
3404
+ isSigner: false
3405
+ }
3406
+ ],
3407
+ args: [
3408
+ {
3409
+ name: "startTime",
3410
+ type: "u64"
3411
+ },
3412
+ {
3413
+ name: "netAmountDeposited",
3414
+ type: "u64"
3415
+ },
3416
+ {
3417
+ name: "period",
3418
+ type: "u64"
3419
+ },
3420
+ {
3421
+ name: "amountPerPeriod",
3422
+ type: "u64"
3423
+ },
3424
+ {
3425
+ name: "cliff",
3426
+ type: "u64"
3427
+ },
3428
+ {
3429
+ name: "cliffAmount",
3430
+ type: "u64"
3431
+ },
3432
+ {
3433
+ name: "cancelableBySender",
3434
+ type: "bool"
3435
+ },
3436
+ {
3437
+ name: "cancelableByRecipient",
3438
+ type: "bool"
3439
+ },
3440
+ {
3441
+ name: "automaticWithdrawal",
3442
+ type: "bool"
3443
+ },
3444
+ {
3445
+ name: "transferableBySender",
3446
+ type: "bool"
3447
+ },
3448
+ {
3449
+ name: "transferableByRecipient",
3450
+ type: "bool"
3451
+ },
3452
+ {
3453
+ name: "canTopup",
3454
+ type: "bool"
3455
+ },
3456
+ {
3457
+ name: "streamName",
3458
+ type: {
3459
+ array: ["u8", 64]
3460
+ }
3461
+ },
3462
+ {
3463
+ name: "withdrawFrequency",
3464
+ type: "u64"
3465
+ }
3466
+ ]
3467
+ },
3468
+ {
3469
+ name: "withdraw",
3470
+ accounts: [
3471
+ {
3472
+ name: "authority",
3473
+ isMut: false,
3474
+ isSigner: true
3475
+ },
3476
+ {
3477
+ name: "recipient",
3478
+ isMut: true,
3479
+ isSigner: false
3480
+ },
3481
+ {
3482
+ name: "recipientTokens",
3483
+ isMut: true,
3484
+ isSigner: false
3485
+ },
3486
+ {
3487
+ name: "metadata",
3488
+ isMut: true,
3489
+ isSigner: false
3490
+ },
3491
+ {
3492
+ name: "escrowTokens",
3493
+ isMut: true,
3494
+ isSigner: false
3495
+ },
3496
+ {
3497
+ name: "streamflowTreasury",
3498
+ isMut: true,
3499
+ isSigner: false
3500
+ },
3501
+ {
3502
+ name: "streamflowTreasuryTokens",
3503
+ isMut: true,
3504
+ isSigner: false
3505
+ },
3506
+ {
3507
+ name: "partner",
3508
+ isMut: true,
3509
+ isSigner: false
3510
+ },
3511
+ {
3512
+ name: "partnerTokens",
3513
+ isMut: true,
3514
+ isSigner: false
3515
+ },
3516
+ {
3517
+ name: "mint",
3518
+ isMut: false,
3519
+ isSigner: false
3520
+ },
3521
+ {
3522
+ name: "tokenProgram",
3523
+ isMut: false,
3524
+ isSigner: false
3525
+ }
3526
+ ],
3527
+ args: [
3528
+ {
3529
+ name: "amount",
3530
+ type: "u64"
3531
+ }
3532
+ ]
3533
+ },
3534
+ {
3535
+ name: "cancel",
3536
+ accounts: [
3537
+ {
3538
+ name: "authority",
3539
+ isMut: false,
3540
+ isSigner: true
3541
+ },
3542
+ {
3543
+ name: "sender",
3544
+ isMut: true,
3545
+ isSigner: false
3546
+ },
3547
+ {
3548
+ name: "senderTokens",
3549
+ isMut: true,
3550
+ isSigner: false
3551
+ },
3552
+ {
3553
+ name: "recipient",
3554
+ isMut: true,
3555
+ isSigner: false
3556
+ },
3557
+ {
3558
+ name: "recipientTokens",
3559
+ isMut: true,
3560
+ isSigner: false
3561
+ },
3562
+ {
3563
+ name: "metadata",
3564
+ isMut: true,
3565
+ isSigner: false
3566
+ },
3567
+ {
3568
+ name: "escrowTokens",
3569
+ isMut: true,
3570
+ isSigner: false
3571
+ },
3572
+ {
3573
+ name: "streamflowTreasury",
3574
+ isMut: true,
3575
+ isSigner: false
3576
+ },
3577
+ {
3578
+ name: "streamflowTreasuryTokens",
3579
+ isMut: true,
3580
+ isSigner: false
3581
+ },
3582
+ {
3583
+ name: "partner",
3584
+ isMut: true,
3585
+ isSigner: false
3586
+ },
3587
+ {
3588
+ name: "partnerTokens",
3589
+ isMut: true,
3590
+ isSigner: false
3591
+ },
3592
+ {
3593
+ name: "mint",
3594
+ isMut: false,
3595
+ isSigner: false
3596
+ },
3597
+ {
3598
+ name: "tokenProgram",
3599
+ isMut: false,
3600
+ isSigner: false
3601
+ }
3602
+ ],
3603
+ args: []
3604
+ },
3605
+ {
3606
+ name: "transferRecipient",
3607
+ accounts: [
3608
+ {
3609
+ name: "authority",
3610
+ isMut: true,
3611
+ isSigner: true
3612
+ },
3613
+ {
3614
+ name: "newRecipient",
3615
+ isMut: true,
3616
+ isSigner: false
3617
+ },
3618
+ {
3619
+ name: "newRecipientTokens",
3620
+ isMut: true,
3621
+ isSigner: false
3622
+ },
3623
+ {
3624
+ name: "metadata",
3625
+ isMut: true,
3626
+ isSigner: false
3627
+ },
3628
+ {
3629
+ name: "mint",
3630
+ isMut: false,
3631
+ isSigner: false
3632
+ },
3633
+ {
3634
+ name: "rent",
3635
+ isMut: false,
3636
+ isSigner: false
3637
+ },
3638
+ {
3639
+ name: "tokenProgram",
3640
+ isMut: false,
3641
+ isSigner: false
3642
+ },
3643
+ {
3644
+ name: "associatedTokenProgram",
3645
+ isMut: false,
3646
+ isSigner: false
3647
+ },
3648
+ {
3649
+ name: "systemProgram",
3650
+ isMut: false,
3651
+ isSigner: false
3652
+ }
3653
+ ],
3654
+ args: []
3655
+ },
3656
+ {
3657
+ name: "topup",
3658
+ accounts: [
3659
+ {
3660
+ name: "sender",
3661
+ isMut: true,
3662
+ isSigner: true
3663
+ },
3664
+ {
3665
+ name: "senderTokens",
3666
+ isMut: true,
3667
+ isSigner: false
3668
+ },
3669
+ {
3670
+ name: "metadata",
3671
+ isMut: true,
3672
+ isSigner: false
3673
+ },
3674
+ {
3675
+ name: "escrowTokens",
3676
+ isMut: true,
3677
+ isSigner: false
3678
+ },
3679
+ {
3680
+ name: "streamflowTreasury",
3681
+ isMut: true,
3682
+ isSigner: false
3683
+ },
3684
+ {
3685
+ name: "streamflowTreasuryTokens",
3686
+ isMut: true,
3687
+ isSigner: false
3688
+ },
3689
+ {
3690
+ name: "withdrawor",
3691
+ isMut: true,
3692
+ isSigner: false
3693
+ },
3694
+ {
3695
+ name: "partner",
3696
+ isMut: true,
3697
+ isSigner: false
3698
+ },
3699
+ {
3700
+ name: "partnerTokens",
3701
+ isMut: true,
3702
+ isSigner: false
3703
+ },
3704
+ {
3705
+ name: "mint",
3706
+ isMut: false,
3707
+ isSigner: false
3708
+ },
3709
+ {
3710
+ name: "tokenProgram",
3711
+ isMut: false,
3712
+ isSigner: false
3713
+ },
3714
+ {
3715
+ name: "systemProgram",
3716
+ isMut: false,
3717
+ isSigner: false
3718
+ }
3719
+ ],
3720
+ args: [
3721
+ {
3722
+ name: "amount",
3723
+ type: "u64"
3724
+ }
3725
+ ]
3726
+ }
3727
+ ]
3728
+ };
3729
+
3730
+ Object.defineProperty(exports, "ContractError", {
3731
+ enumerable: true,
3732
+ get: function () { return common.ContractError; }
3733
+ });
3734
+ Object.defineProperty(exports, "IChain", {
3735
+ enumerable: true,
3736
+ get: function () { return common.IChain; }
3737
+ });
3738
+ Object.defineProperty(exports, "ICluster", {
3739
+ enumerable: true,
3740
+ get: function () { return common.ICluster; }
3741
+ });
3742
+ exports.AlignedContract = AlignedContract;
3743
+ exports.Contract = Contract;
3744
+ exports.SolanaStreamClient = SolanaStreamClient;
3745
+ exports.cancelStreamInstruction = cancelStreamInstruction;
3746
+ exports.constants = constants_exports;
3747
+ exports.createStreamInstruction = createStreamInstruction;
3748
+ exports.createUncheckedStreamInstruction = createUncheckedStreamInstruction;
3749
+ exports.decodeStream = decodeStream;
3750
+ exports.deriveContractPDA = deriveContractPDA;
3751
+ exports.deriveEscrowPDA = deriveEscrowPDA;
3752
+ exports.deriveTestOraclePDA = deriveTestOraclePDA;
3753
+ exports.extractSolanaErrorCode = extractSolanaErrorCode;
3754
+ exports.sendAndConfirmStreamRawTransaction = sendAndConfirmStreamRawTransaction;
3755
+ exports.signAllTransactionWithRecipients = signAllTransactionWithRecipients;
3756
+ exports.timelockIDL = timelockIDL_default;
3757
+ exports.topupStreamInstruction = topupStreamInstruction;
3758
+ exports.transferStreamInstruction = transferStreamInstruction;
3759
+ exports.updateStreamInstruction = updateStreamInstruction;
3760
+ exports.withdrawStreamInstruction = withdrawStreamInstruction;
3761
+ //# sourceMappingURL=index.cjs.map
3762
+ //# sourceMappingURL=index.cjs.map