@streamflow/stream 7.5.2 → 7.5.3-alpha.cffa362.20250508190445

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