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

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