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

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