@streamflow/stream 10.0.0-alpha.p311.10f340e → 10.0.0-alpha.p313.3ce4d29
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.
- package/README.md +8 -64
- package/dist/cjs/index.cjs +440 -3794
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +3 -182
- package/dist/cjs/solana/index.cjs +393 -309
- package/dist/cjs/solana/index.cjs.map +1 -1
- package/dist/cjs/solana/index.d.cts +1134 -17
- package/dist/esm/index.d.ts +3 -182
- package/dist/esm/index.js +258 -3626
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/solana/index.d.ts +1134 -17
- package/dist/esm/solana/index.js +274 -240
- package/dist/esm/solana/index.js.map +1 -1
- package/package.json +4 -43
- package/dist/cjs/BaseStreamClient-Dvs8yWEE.d.cts +0 -550
- package/dist/cjs/aptos/index.cjs +0 -450
- package/dist/cjs/aptos/index.cjs.map +0 -1
- package/dist/cjs/aptos/index.d.cts +0 -14
- package/dist/cjs/evm/index.cjs +0 -1909
- package/dist/cjs/evm/index.cjs.map +0 -1
- package/dist/cjs/evm/index.d.cts +0 -13
- package/dist/cjs/index-BHKWsVnx.d.cts +0 -849
- package/dist/cjs/index-CGNg22mO.d.cts +0 -203
- package/dist/cjs/index-Dk1hKzM3.d.cts +0 -213
- package/dist/cjs/index-dSxy_PVV.d.cts +0 -136
- package/dist/cjs/sui/index.cjs +0 -1015
- package/dist/cjs/sui/index.cjs.map +0 -1
- package/dist/cjs/sui/index.d.cts +0 -13
- package/dist/esm/BaseStreamClient-Dvs8yWEE.d.ts +0 -550
- package/dist/esm/aptos/index.d.ts +0 -14
- package/dist/esm/aptos/index.js +0 -437
- package/dist/esm/aptos/index.js.map +0 -1
- package/dist/esm/evm/index.d.ts +0 -13
- package/dist/esm/evm/index.js +0 -1896
- package/dist/esm/evm/index.js.map +0 -1
- package/dist/esm/index-CRXW7eZy.d.ts +0 -203
- package/dist/esm/index-CgDmuCzv.d.ts +0 -849
- package/dist/esm/index-DED7TgAo.d.ts +0 -136
- package/dist/esm/index-li6QZ_tF.d.ts +0 -213
- package/dist/esm/sui/index.d.ts +0 -13
- package/dist/esm/sui/index.js +0 -1005
- package/dist/esm/sui/index.js.map +0 -1
package/dist/esm/solana/index.js
CHANGED
|
@@ -1,24 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BN3 from 'bn.js';
|
|
2
2
|
import bs58 from 'bs58';
|
|
3
3
|
import { Buffer } from 'buffer';
|
|
4
4
|
import { NATIVE_MINT, ASSOCIATED_TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
|
5
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
|
|
6
|
+
import { ICluster, getNumberFromBN, isSignerKeypair, isSignerWallet, executeTransaction, ContractError, buildSendThrottler, assertHasPublicKey, prepareWrappedAccount, prepareTransaction, signAndExecuteTransaction, invariant, getMintAndProgram, prepareBaseInstructions, getBN, ata, createVersionedTransaction, executeMultipleTransactions, getMultipleAccountsInfoBatched, getProgramAccounts, checkOrCreateAtaBatch } from '@streamflow/common';
|
|
7
|
+
export { ContractError, ICluster, getBN, getNumberFromBN } from '@streamflow/common';
|
|
7
8
|
import * as borsh from 'borsh';
|
|
8
9
|
import { Program } from '@coral-xyz/anchor';
|
|
9
|
-
import { ICluster, assertHasPublicKey, invariant, getBN } from '@streamflow/common';
|
|
10
|
-
export { ContractError, IChain, ICluster } from '@streamflow/common';
|
|
11
10
|
import * as BufferLayout from '@solana/buffer-layout';
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
var __export = (target, all) => {
|
|
15
|
-
for (var name in all)
|
|
16
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
-
};
|
|
12
|
+
// solana/StreamClient.ts
|
|
18
13
|
var MAX_SAFE_UNIX_TIME_VALUE = 864e10;
|
|
19
|
-
var WITHDRAW_AVAILABLE_AMOUNT = new BN4("18446744073709551615");
|
|
20
|
-
|
|
21
|
-
// common/contractUtils.ts
|
|
22
14
|
var calculateUnlockedAmount = ({
|
|
23
15
|
depositedAmount,
|
|
24
16
|
cliff,
|
|
@@ -31,15 +23,24 @@ var calculateUnlockedAmount = ({
|
|
|
31
23
|
fundsUnlockedAtLastRateChange
|
|
32
24
|
}) => {
|
|
33
25
|
const deposited = depositedAmount;
|
|
34
|
-
if (currentTimestamp < cliff) return new
|
|
26
|
+
if (currentTimestamp < cliff) return new BN3(0);
|
|
35
27
|
if (currentTimestamp > end) return deposited;
|
|
36
28
|
const savedUnlockedFunds = lastRateChangeTime === 0 ? cliffAmount : fundsUnlockedAtLastRateChange;
|
|
37
29
|
const savedUnlockedFundsTime = lastRateChangeTime === 0 ? cliff : lastRateChangeTime;
|
|
38
|
-
const streamed = new
|
|
30
|
+
const streamed = new BN3(Math.floor((currentTimestamp - savedUnlockedFundsTime) / period)).mul(amountPerPeriod).add(savedUnlockedFunds);
|
|
39
31
|
return streamed.lt(deposited) ? streamed : deposited;
|
|
40
32
|
};
|
|
41
33
|
var isCliffCloseToDepositedAmount = (streamData) => {
|
|
42
|
-
return streamData.cliffAmount.gte(streamData.depositedAmount.sub(new
|
|
34
|
+
return streamData.cliffAmount.gte(streamData.depositedAmount.sub(new BN3(1)));
|
|
35
|
+
};
|
|
36
|
+
var isPayment = (streamData) => {
|
|
37
|
+
return streamData.canTopup;
|
|
38
|
+
};
|
|
39
|
+
var isVesting = (streamData) => {
|
|
40
|
+
return !streamData.canTopup && !isCliffCloseToDepositedAmount(streamData) && !isDynamicLock(streamData.minPrice, streamData.maxPrice, streamData.minPercentage, streamData.maxPercentage);
|
|
41
|
+
};
|
|
42
|
+
var isAligned = (stream) => {
|
|
43
|
+
return "minPrice" in stream && "maxPrice" in stream && "minPercentage" in stream && "maxPercentage" in stream;
|
|
43
44
|
};
|
|
44
45
|
var isCreateAlignedStreamData = (obj) => {
|
|
45
46
|
return "minPrice" in obj && "maxPrice" in obj && "minPercentage" in obj && "maxPercentage" in obj;
|
|
@@ -51,66 +52,167 @@ var isTokenLock = (streamData) => {
|
|
|
51
52
|
return !streamData.canTopup && !streamData.automaticWithdrawal && !streamData.cancelableBySender && !streamData.cancelableByRecipient && !streamData.transferableBySender && (isCliffCloseToDepositedAmount(streamData) || isDynamicLock(streamData.minPrice, streamData.maxPrice, streamData.minPercentage, streamData.maxPercentage));
|
|
52
53
|
};
|
|
53
54
|
var buildStreamType = (streamData) => {
|
|
55
|
+
if (isVesting(streamData)) {
|
|
56
|
+
return "vesting" /* Vesting */;
|
|
57
|
+
}
|
|
54
58
|
if (isTokenLock(streamData)) {
|
|
55
59
|
return "lock" /* Lock */;
|
|
56
60
|
}
|
|
57
|
-
return "
|
|
61
|
+
return "payment" /* Payment */;
|
|
58
62
|
};
|
|
59
63
|
var decodeEndTime = (endTime) => {
|
|
60
|
-
if (endTime.gt(new
|
|
64
|
+
if (endTime.gt(new BN3(MAX_SAFE_UNIX_TIME_VALUE))) {
|
|
61
65
|
return MAX_SAFE_UNIX_TIME_VALUE;
|
|
62
66
|
}
|
|
63
67
|
return endTime.toNumber();
|
|
64
68
|
};
|
|
65
|
-
var
|
|
66
|
-
var
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
var ALIGNED_PRECISION_FACTOR_POW = 9;
|
|
70
|
+
var StreamDirection = /* @__PURE__ */ ((StreamDirection2) => {
|
|
71
|
+
StreamDirection2["Outgoing"] = "outgoing";
|
|
72
|
+
StreamDirection2["Incoming"] = "incoming";
|
|
73
|
+
StreamDirection2["All"] = "all";
|
|
74
|
+
return StreamDirection2;
|
|
75
|
+
})(StreamDirection || {});
|
|
76
|
+
var StreamType = /* @__PURE__ */ ((StreamType2) => {
|
|
77
|
+
StreamType2["All"] = "all";
|
|
78
|
+
StreamType2["Payment"] = "payment";
|
|
79
|
+
StreamType2["Vesting"] = "vesting";
|
|
80
|
+
StreamType2["Lock"] = "lock";
|
|
81
|
+
return StreamType2;
|
|
82
|
+
})(StreamType || {});
|
|
83
|
+
var ContractErrorCode = /* @__PURE__ */ ((ContractErrorCode2) => {
|
|
84
|
+
ContractErrorCode2["AccountsNotWritable"] = "AccountsNotWritable";
|
|
85
|
+
ContractErrorCode2["InvalidMetadata"] = "InvalidMetadata";
|
|
86
|
+
ContractErrorCode2["InvalidMetadataAccount"] = "InvalidMetadataAccount";
|
|
87
|
+
ContractErrorCode2["MetadataAccountMismatch"] = "MetadataAccountMismatch";
|
|
88
|
+
ContractErrorCode2["InvalidEscrowAccount"] = "InvalidEscrowAccount";
|
|
89
|
+
ContractErrorCode2["NotAssociated"] = "NotAssociated";
|
|
90
|
+
ContractErrorCode2["MintMismatch"] = "MintMismatch";
|
|
91
|
+
ContractErrorCode2["TransferNotAllowed"] = "TransferNotAllowed";
|
|
92
|
+
ContractErrorCode2["ContractClosed"] = "ContractClosed";
|
|
93
|
+
ContractErrorCode2["InvalidTreasury"] = "InvalidTreasury";
|
|
94
|
+
ContractErrorCode2["InvalidTimestamps"] = "InvalidTimestamps";
|
|
95
|
+
ContractErrorCode2["InvalidDepositConfiguration"] = "InvalidDepositConfiguration";
|
|
96
|
+
ContractErrorCode2["AmountIsZero"] = "AmountIsZero";
|
|
97
|
+
ContractErrorCode2["AmountMoreThanAvailable"] = "AmountMoreThanAvailable";
|
|
98
|
+
ContractErrorCode2["AmountAvailableIsZero"] = "AmountAvailableIsZero";
|
|
99
|
+
ContractErrorCode2["ArithmeticError"] = "ArithmeticError";
|
|
100
|
+
ContractErrorCode2["InvalidMetadataSize"] = "InvalidMetadataSize";
|
|
101
|
+
ContractErrorCode2["UninitializedMetadata"] = "UninitializedMetadata";
|
|
102
|
+
ContractErrorCode2["Unauthorized"] = "Unauthorized";
|
|
103
|
+
ContractErrorCode2["SelfTransfer"] = "SelfTransfer";
|
|
104
|
+
ContractErrorCode2["AlreadyPaused"] = "AlreadyPaused";
|
|
105
|
+
ContractErrorCode2["NotPaused"] = "NotPaused";
|
|
106
|
+
ContractErrorCode2["MetadataNotRentExempt"] = "MetadataNotRentExempt";
|
|
107
|
+
return ContractErrorCode2;
|
|
108
|
+
})(ContractErrorCode || {});
|
|
109
|
+
var AlignedProxyErrorCode = /* @__PURE__ */ ((AlignedProxyErrorCode2) => {
|
|
110
|
+
AlignedProxyErrorCode2["Unauthorized"] = "Unauthorized";
|
|
111
|
+
AlignedProxyErrorCode2["ArithmeticError"] = "ArithmeticError";
|
|
112
|
+
AlignedProxyErrorCode2["UnsupportedTokenExtensions"] = "UnsupportedTokenExtensions";
|
|
113
|
+
AlignedProxyErrorCode2["PeriodTooShort"] = "PeriodTooShort";
|
|
114
|
+
AlignedProxyErrorCode2["InvalidTickSize"] = "InvalidTickSize";
|
|
115
|
+
AlignedProxyErrorCode2["InvalidPercentageBoundaries"] = "InvalidPercentageBoundaries";
|
|
116
|
+
AlignedProxyErrorCode2["InvalidPriceBoundaries"] = "InvalidPriceBoundaries";
|
|
117
|
+
AlignedProxyErrorCode2["UnsupportedOracle"] = "UnsupportedOracle";
|
|
118
|
+
AlignedProxyErrorCode2["InvalidOracleAccount"] = "InvalidOracleAccount";
|
|
119
|
+
AlignedProxyErrorCode2["InvalidOraclePrice"] = "InvalidOraclePrice";
|
|
120
|
+
AlignedProxyErrorCode2["InvalidStreamMetadata"] = "InvalidStreamMetadata";
|
|
121
|
+
AlignedProxyErrorCode2["AmountAlreadyUpdated"] = "AmountAlreadyUpdated";
|
|
122
|
+
AlignedProxyErrorCode2["AllFundsUnlocked"] = "AllFundsUnlocked";
|
|
123
|
+
return AlignedProxyErrorCode2;
|
|
124
|
+
})(AlignedProxyErrorCode || {});
|
|
125
|
+
var Contract = class {
|
|
126
|
+
constructor(stream) {
|
|
127
|
+
this.magic = stream.magic.toNumber();
|
|
128
|
+
this.version = stream.version.toNumber();
|
|
129
|
+
this.createdAt = stream.createdAt.toNumber();
|
|
130
|
+
this.withdrawnAmount = stream.withdrawnAmount;
|
|
131
|
+
this.canceledAt = stream.canceledAt.toNumber();
|
|
132
|
+
this.end = decodeEndTime(stream.end);
|
|
133
|
+
this.lastWithdrawnAt = stream.lastWithdrawnAt.toNumber();
|
|
134
|
+
this.sender = stream.sender.toBase58();
|
|
135
|
+
this.senderTokens = stream.senderTokens.toBase58();
|
|
136
|
+
this.recipient = stream.recipient.toBase58();
|
|
137
|
+
this.recipientTokens = stream.recipientTokens.toBase58();
|
|
138
|
+
this.mint = stream.mint.toBase58();
|
|
139
|
+
this.escrowTokens = stream.escrowTokens.toBase58();
|
|
140
|
+
this.streamflowTreasury = stream.streamflowTreasury.toBase58();
|
|
141
|
+
this.streamflowTreasuryTokens = stream.streamflowTreasuryTokens.toBase58();
|
|
142
|
+
this.streamflowFeeTotal = stream.streamflowFeeTotal;
|
|
143
|
+
this.streamflowFeeWithdrawn = stream.streamflowFeeWithdrawn;
|
|
144
|
+
this.streamflowFeePercent = stream.streamflowFeePercent;
|
|
145
|
+
this.partnerFeeTotal = stream.partnerFeeTotal;
|
|
146
|
+
this.partnerFeeWithdrawn = stream.partnerFeeWithdrawn;
|
|
147
|
+
this.partnerFeePercent = stream.partnerFeePercent;
|
|
148
|
+
this.partner = stream.partner.toBase58();
|
|
149
|
+
this.partnerTokens = stream.partnerTokens?.toBase58();
|
|
150
|
+
this.start = stream.start.toNumber();
|
|
151
|
+
this.depositedAmount = stream.depositedAmount;
|
|
152
|
+
this.period = stream.period.toNumber();
|
|
153
|
+
this.amountPerPeriod = stream.amountPerPeriod;
|
|
154
|
+
this.cliff = stream.cliff.toNumber();
|
|
155
|
+
this.cliffAmount = stream.cliffAmount;
|
|
156
|
+
this.cancelableBySender = stream.cancelableBySender;
|
|
157
|
+
this.cancelableByRecipient = stream.cancelableByRecipient;
|
|
158
|
+
this.automaticWithdrawal = stream.automaticWithdrawal;
|
|
159
|
+
this.transferableBySender = stream.transferableBySender;
|
|
160
|
+
this.transferableByRecipient = stream.transferableByRecipient;
|
|
161
|
+
this.canTopup = stream.canTopup;
|
|
162
|
+
this.name = stream.name;
|
|
163
|
+
this.withdrawalFrequency = stream.withdrawFrequency.toNumber();
|
|
164
|
+
this.closed = stream.closed;
|
|
165
|
+
this.currentPauseStart = stream.currentPauseStart.toNumber();
|
|
166
|
+
this.pauseCumulative = stream.pauseCumulative;
|
|
167
|
+
this.lastRateChangeTime = stream.lastRateChangeTime.toNumber();
|
|
168
|
+
this.fundsUnlockedAtLastRateChange = stream.fundsUnlockedAtLastRateChange;
|
|
169
|
+
this.type = buildStreamType(this);
|
|
170
|
+
this.isAligned = false;
|
|
171
|
+
}
|
|
172
|
+
unlocked(currentTimestamp) {
|
|
173
|
+
return calculateUnlockedAmount({
|
|
174
|
+
...this,
|
|
175
|
+
currentTimestamp
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
remaining(decimals) {
|
|
179
|
+
return getNumberFromBN(this.depositedAmount.sub(this.withdrawnAmount), decimals);
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
var AlignedContract = class extends Contract {
|
|
183
|
+
constructor(stream, alignedProxy) {
|
|
184
|
+
super(stream);
|
|
185
|
+
this.minPrice = getNumberFromBN(alignedProxy.minPrice, ALIGNED_PRECISION_FACTOR_POW);
|
|
186
|
+
this.maxPrice = getNumberFromBN(alignedProxy.maxPrice, ALIGNED_PRECISION_FACTOR_POW);
|
|
187
|
+
this.minPercentage = getNumberFromBN(alignedProxy.minPercentage, ALIGNED_PRECISION_FACTOR_POW);
|
|
188
|
+
this.maxPercentage = getNumberFromBN(alignedProxy.maxPercentage, ALIGNED_PRECISION_FACTOR_POW);
|
|
189
|
+
this.oracleType = Object.keys(alignedProxy.priceOracleType).find((key) => !!key) || "none";
|
|
190
|
+
this.tickSize = alignedProxy.tickSize.toNumber();
|
|
191
|
+
this.priceOracle = this.oracleType === "none" ? void 0 : alignedProxy.priceOracle.toBase58();
|
|
192
|
+
this.sender = alignedProxy.sender.toBase58();
|
|
193
|
+
this.canceledAt = alignedProxy.streamCanceledTime.toNumber();
|
|
194
|
+
this.proxyAddress = stream.sender.toBase58();
|
|
195
|
+
this.initialAmountPerPeriod = alignedProxy.initialAmountPerPeriod;
|
|
196
|
+
this.initialPrice = getNumberFromBN(alignedProxy.initialPrice, ALIGNED_PRECISION_FACTOR_POW);
|
|
197
|
+
this.lastPrice = getNumberFromBN(alignedProxy.lastPrice, ALIGNED_PRECISION_FACTOR_POW);
|
|
198
|
+
this.lastAmountUpdateTime = alignedProxy.lastAmountUpdateTime.toNumber();
|
|
199
|
+
this.initialNetAmount = alignedProxy.initialNetAmount;
|
|
200
|
+
this.expiryTime = alignedProxy.expiryTime.toNumber();
|
|
201
|
+
this.expiryPercentage = getNumberFromBN(alignedProxy.expiryPercentage, ALIGNED_PRECISION_FACTOR_POW);
|
|
202
|
+
this.floorPrice = getNumberFromBN(alignedProxy.floorPrice, ALIGNED_PRECISION_FACTOR_POW);
|
|
203
|
+
this.type = buildStreamType(this);
|
|
204
|
+
this.isAligned = true;
|
|
205
|
+
}
|
|
72
206
|
};
|
|
73
|
-
|
|
74
|
-
// solana/constants.ts
|
|
75
|
-
var constants_exports = {};
|
|
76
|
-
__export(constants_exports, {
|
|
77
|
-
AIRDROP_AMOUNT: () => AIRDROP_AMOUNT,
|
|
78
|
-
AIRDROP_TEST_TOKEN: () => AIRDROP_TEST_TOKEN,
|
|
79
|
-
ALIGNED_COMPUTE_LIMIT: () => ALIGNED_COMPUTE_LIMIT,
|
|
80
|
-
ALIGNED_PRECISION_FACTOR_POW: () => ALIGNED_PRECISION_FACTOR_POW,
|
|
81
|
-
ALIGNED_UNLOCKS_PROGRAM_ID: () => ALIGNED_UNLOCKS_PROGRAM_ID,
|
|
82
|
-
CONTRACT_DISCRIMINATOR: () => CONTRACT_DISCRIMINATOR,
|
|
83
|
-
CONTRACT_SEED: () => CONTRACT_SEED,
|
|
84
|
-
CREATE_PARAMS_PADDING: () => CREATE_PARAMS_PADDING,
|
|
85
|
-
DEFAULT_STREAMFLOW_FEE: () => DEFAULT_STREAMFLOW_FEE,
|
|
86
|
-
ESCROW_SEED: () => ESCROW_SEED,
|
|
87
|
-
FEES_METADATA_SEED: () => FEES_METADATA_SEED,
|
|
88
|
-
FEE_ORACLE_PUBLIC_KEY: () => FEE_ORACLE_PUBLIC_KEY,
|
|
89
|
-
ORIGINAL_CONTRACT_SENDER_OFFSET: () => ORIGINAL_CONTRACT_SENDER_OFFSET,
|
|
90
|
-
PARTNERS_SCHEMA: () => PARTNERS_SCHEMA,
|
|
91
|
-
PARTNER_ORACLE_PROGRAM_ID: () => PARTNER_ORACLE_PROGRAM_ID,
|
|
92
|
-
PARTNER_SCHEMA: () => PARTNER_SCHEMA,
|
|
93
|
-
PROGRAM_ID: () => PROGRAM_ID,
|
|
94
|
-
SOLANA_ERROR_MAP: () => SOLANA_ERROR_MAP,
|
|
95
|
-
SOLANA_ERROR_MATCH_REGEX: () => SOLANA_ERROR_MATCH_REGEX,
|
|
96
|
-
STREAMFLOW_TREASURY_PUBLIC_KEY: () => STREAMFLOW_TREASURY_PUBLIC_KEY,
|
|
97
|
-
STREAM_STRUCT_OFFSETS: () => STREAM_STRUCT_OFFSETS,
|
|
98
|
-
STREAM_STRUCT_OFFSET_CLOSED: () => STREAM_STRUCT_OFFSET_CLOSED,
|
|
99
|
-
STREAM_STRUCT_OFFSET_MINT: () => STREAM_STRUCT_OFFSET_MINT,
|
|
100
|
-
STREAM_STRUCT_OFFSET_RECIPIENT: () => STREAM_STRUCT_OFFSET_RECIPIENT,
|
|
101
|
-
STREAM_STRUCT_OFFSET_SENDER: () => STREAM_STRUCT_OFFSET_SENDER,
|
|
102
|
-
TEST_ORACLE_DISCRIMINATOR: () => TEST_ORACLE_DISCRIMINATOR,
|
|
103
|
-
TEST_ORACLE_SEED: () => TEST_ORACLE_SEED,
|
|
104
|
-
TX_FINALITY_CONFIRMED: () => TX_FINALITY_CONFIRMED,
|
|
105
|
-
WITHDRAWOR_PUBLIC_KEY: () => WITHDRAWOR_PUBLIC_KEY
|
|
106
|
-
});
|
|
107
207
|
var TX_FINALITY_CONFIRMED = "confirmed";
|
|
108
208
|
var ORIGINAL_CONTRACT_SENDER_OFFSET = 9;
|
|
109
209
|
var STREAM_STRUCT_OFFSET_SENDER = 49;
|
|
110
210
|
var STREAM_STRUCT_OFFSET_RECIPIENT = 113;
|
|
111
211
|
var STREAM_STRUCT_OFFSET_MINT = 177;
|
|
112
212
|
var STREAM_STRUCT_OFFSET_CLOSED = 671;
|
|
113
|
-
var
|
|
213
|
+
var MAX_SAFE_UNIX_TIME_VALUE2 = 864e10;
|
|
214
|
+
var WITHDRAW_AVAILABLE_AMOUNT = new BN3("18446744073709551615");
|
|
215
|
+
var ALIGNED_PRECISION_FACTOR_POW2 = 9;
|
|
114
216
|
var STREAM_STRUCT_OFFSETS = {
|
|
115
217
|
mint: STREAM_STRUCT_OFFSET_MINT,
|
|
116
218
|
recipient: STREAM_STRUCT_OFFSET_RECIPIENT,
|
|
@@ -191,88 +293,8 @@ var SOLANA_ERROR_MAP = {
|
|
|
191
293
|
6011: "AmountAlreadyUpdated" /* AmountAlreadyUpdated */,
|
|
192
294
|
6012: "AllFundsUnlocked" /* AllFundsUnlocked */
|
|
193
295
|
};
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
this.magic = stream.magic.toNumber();
|
|
197
|
-
this.version = stream.version.toNumber();
|
|
198
|
-
this.createdAt = stream.createdAt.toNumber();
|
|
199
|
-
this.withdrawnAmount = stream.withdrawnAmount;
|
|
200
|
-
this.canceledAt = stream.canceledAt.toNumber();
|
|
201
|
-
this.end = decodeEndTime(stream.end);
|
|
202
|
-
this.lastWithdrawnAt = stream.lastWithdrawnAt.toNumber();
|
|
203
|
-
this.sender = stream.sender.toBase58();
|
|
204
|
-
this.senderTokens = stream.senderTokens.toBase58();
|
|
205
|
-
this.recipient = stream.recipient.toBase58();
|
|
206
|
-
this.recipientTokens = stream.recipientTokens.toBase58();
|
|
207
|
-
this.mint = stream.mint.toBase58();
|
|
208
|
-
this.escrowTokens = stream.escrowTokens.toBase58();
|
|
209
|
-
this.streamflowTreasury = stream.streamflowTreasury.toBase58();
|
|
210
|
-
this.streamflowTreasuryTokens = stream.streamflowTreasuryTokens.toBase58();
|
|
211
|
-
this.streamflowFeeTotal = stream.streamflowFeeTotal;
|
|
212
|
-
this.streamflowFeeWithdrawn = stream.streamflowFeeWithdrawn;
|
|
213
|
-
this.streamflowFeePercent = stream.streamflowFeePercent;
|
|
214
|
-
this.partnerFeeTotal = stream.partnerFeeTotal;
|
|
215
|
-
this.partnerFeeWithdrawn = stream.partnerFeeWithdrawn;
|
|
216
|
-
this.partnerFeePercent = stream.partnerFeePercent;
|
|
217
|
-
this.partner = stream.partner.toBase58();
|
|
218
|
-
this.partnerTokens = stream.partnerTokens?.toBase58();
|
|
219
|
-
this.start = stream.start.toNumber();
|
|
220
|
-
this.depositedAmount = stream.depositedAmount;
|
|
221
|
-
this.period = stream.period.toNumber();
|
|
222
|
-
this.amountPerPeriod = stream.amountPerPeriod;
|
|
223
|
-
this.cliff = stream.cliff.toNumber();
|
|
224
|
-
this.cliffAmount = stream.cliffAmount;
|
|
225
|
-
this.cancelableBySender = stream.cancelableBySender;
|
|
226
|
-
this.cancelableByRecipient = stream.cancelableByRecipient;
|
|
227
|
-
this.automaticWithdrawal = stream.automaticWithdrawal;
|
|
228
|
-
this.transferableBySender = stream.transferableBySender;
|
|
229
|
-
this.transferableByRecipient = stream.transferableByRecipient;
|
|
230
|
-
this.canTopup = stream.canTopup;
|
|
231
|
-
this.name = stream.name;
|
|
232
|
-
this.withdrawalFrequency = stream.withdrawFrequency.toNumber();
|
|
233
|
-
this.closed = stream.closed;
|
|
234
|
-
this.currentPauseStart = stream.currentPauseStart.toNumber();
|
|
235
|
-
this.pauseCumulative = stream.pauseCumulative;
|
|
236
|
-
this.lastRateChangeTime = stream.lastRateChangeTime.toNumber();
|
|
237
|
-
this.fundsUnlockedAtLastRateChange = stream.fundsUnlockedAtLastRateChange;
|
|
238
|
-
this.type = buildStreamType(this);
|
|
239
|
-
this.isAligned = false;
|
|
240
|
-
}
|
|
241
|
-
unlocked(currentTimestamp) {
|
|
242
|
-
return calculateUnlockedAmount({
|
|
243
|
-
...this,
|
|
244
|
-
currentTimestamp
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
remaining(decimals) {
|
|
248
|
-
return getNumberFromBN(this.depositedAmount.sub(this.withdrawnAmount), decimals);
|
|
249
|
-
}
|
|
250
|
-
};
|
|
251
|
-
var AlignedContract = class extends Contract {
|
|
252
|
-
constructor(stream, alignedProxy) {
|
|
253
|
-
super(stream);
|
|
254
|
-
this.minPrice = getNumberFromBN(alignedProxy.minPrice, ALIGNED_PRECISION_FACTOR_POW);
|
|
255
|
-
this.maxPrice = getNumberFromBN(alignedProxy.maxPrice, ALIGNED_PRECISION_FACTOR_POW);
|
|
256
|
-
this.minPercentage = getNumberFromBN(alignedProxy.minPercentage, ALIGNED_PRECISION_FACTOR_POW);
|
|
257
|
-
this.maxPercentage = getNumberFromBN(alignedProxy.maxPercentage, ALIGNED_PRECISION_FACTOR_POW);
|
|
258
|
-
this.oracleType = Object.keys(alignedProxy.priceOracleType).find((key) => !!key) || "none";
|
|
259
|
-
this.tickSize = alignedProxy.tickSize.toNumber();
|
|
260
|
-
this.priceOracle = this.oracleType === "none" ? void 0 : alignedProxy.priceOracle.toBase58();
|
|
261
|
-
this.sender = alignedProxy.sender.toBase58();
|
|
262
|
-
this.canceledAt = alignedProxy.streamCanceledTime.toNumber();
|
|
263
|
-
this.proxyAddress = stream.sender.toBase58();
|
|
264
|
-
this.initialAmountPerPeriod = alignedProxy.initialAmountPerPeriod;
|
|
265
|
-
this.initialPrice = getNumberFromBN(alignedProxy.initialPrice, ALIGNED_PRECISION_FACTOR_POW);
|
|
266
|
-
this.lastPrice = getNumberFromBN(alignedProxy.lastPrice, ALIGNED_PRECISION_FACTOR_POW);
|
|
267
|
-
this.lastAmountUpdateTime = alignedProxy.lastAmountUpdateTime.toNumber();
|
|
268
|
-
this.initialNetAmount = alignedProxy.initialNetAmount;
|
|
269
|
-
this.expiryTime = alignedProxy.expiryTime.toNumber();
|
|
270
|
-
this.expiryPercentage = getNumberFromBN(alignedProxy.expiryPercentage, ALIGNED_PRECISION_FACTOR_POW);
|
|
271
|
-
this.floorPrice = getNumberFromBN(alignedProxy.floorPrice, ALIGNED_PRECISION_FACTOR_POW);
|
|
272
|
-
this.type = buildStreamType(this);
|
|
273
|
-
this.isAligned = true;
|
|
274
|
-
}
|
|
275
|
-
};
|
|
296
|
+
|
|
297
|
+
// solana/layout.ts
|
|
276
298
|
var streamLayout = BufferLayout.struct([
|
|
277
299
|
BufferLayout.blob(8, "magic"),
|
|
278
300
|
BufferLayout.blob(1, "version"),
|
|
@@ -432,20 +454,25 @@ var encodeUpdateStream = (values, data) => {
|
|
|
432
454
|
var topupStreamLayout = BufferLayout.struct([
|
|
433
455
|
BufferLayout.blob(8, "amount")
|
|
434
456
|
]);
|
|
435
|
-
|
|
436
|
-
|
|
457
|
+
var FEE_PRECISION = 4;
|
|
458
|
+
var FEE_NORMALIZER = 10 ** FEE_PRECISION;
|
|
459
|
+
var FEE_MULTIPLIER = new BN3(10 ** 6);
|
|
437
460
|
var decoder = new TextDecoder("utf-8");
|
|
438
461
|
var LE = "le";
|
|
462
|
+
var calculateTotalAmountToDeposit = (depositedAmount, totalFee) => {
|
|
463
|
+
const totalFeeNormalized = new BN3(totalFee * FEE_NORMALIZER);
|
|
464
|
+
return depositedAmount.mul(totalFeeNormalized.add(FEE_MULTIPLIER)).div(FEE_MULTIPLIER);
|
|
465
|
+
};
|
|
439
466
|
var decodeStream = (buf) => {
|
|
440
467
|
const raw = streamLayout.decode(buf);
|
|
441
468
|
return {
|
|
442
|
-
magic: new
|
|
443
|
-
version: new
|
|
444
|
-
createdAt: new
|
|
445
|
-
withdrawnAmount: new
|
|
446
|
-
canceledAt: new
|
|
447
|
-
end: new
|
|
448
|
-
lastWithdrawnAt: new
|
|
469
|
+
magic: new BN3(raw.magic, LE),
|
|
470
|
+
version: new BN3(raw.version, LE),
|
|
471
|
+
createdAt: new BN3(raw.created_at, LE),
|
|
472
|
+
withdrawnAmount: new BN3(raw.withdrawn_amount, LE),
|
|
473
|
+
canceledAt: new BN3(raw.canceled_at, LE),
|
|
474
|
+
end: new BN3(raw.end_time, LE),
|
|
475
|
+
lastWithdrawnAt: new BN3(raw.last_withdrawn_at, LE),
|
|
449
476
|
sender: new PublicKey(raw.sender),
|
|
450
477
|
senderTokens: new PublicKey(raw.sender_tokens),
|
|
451
478
|
recipient: new PublicKey(raw.recipient),
|
|
@@ -454,20 +481,20 @@ var decodeStream = (buf) => {
|
|
|
454
481
|
escrowTokens: new PublicKey(raw.escrow_tokens),
|
|
455
482
|
streamflowTreasury: new PublicKey(raw.streamflow_treasury),
|
|
456
483
|
streamflowTreasuryTokens: new PublicKey(raw.streamflow_treasury_tokens),
|
|
457
|
-
streamflowFeeTotal: new
|
|
458
|
-
streamflowFeeWithdrawn: new
|
|
484
|
+
streamflowFeeTotal: new BN3(raw.streamflow_fee_total, LE),
|
|
485
|
+
streamflowFeeWithdrawn: new BN3(raw.streamflow_fee_withdrawn, LE),
|
|
459
486
|
streamflowFeePercent: raw.streamflow_fee_percent,
|
|
460
|
-
partnerFeeTotal: new
|
|
461
|
-
partnerFeeWithdrawn: new
|
|
487
|
+
partnerFeeTotal: new BN3(raw.partner_fee_total, LE),
|
|
488
|
+
partnerFeeWithdrawn: new BN3(raw.partner_fee_withdrawn, LE),
|
|
462
489
|
partnerFeePercent: raw.partner_fee_percent,
|
|
463
490
|
partner: new PublicKey(raw.partner),
|
|
464
491
|
partnerTokens: new PublicKey(raw.partner_tokens),
|
|
465
|
-
start: new
|
|
466
|
-
depositedAmount: new
|
|
467
|
-
period: new
|
|
468
|
-
amountPerPeriod: new
|
|
469
|
-
cliff: new
|
|
470
|
-
cliffAmount: new
|
|
492
|
+
start: new BN3(raw.start_time, LE),
|
|
493
|
+
depositedAmount: new BN3(raw.net_amount_deposited, LE),
|
|
494
|
+
period: new BN3(raw.period, LE),
|
|
495
|
+
amountPerPeriod: new BN3(raw.amount_per_period, LE),
|
|
496
|
+
cliff: new BN3(raw.cliff, LE),
|
|
497
|
+
cliffAmount: new BN3(raw.cliff_amount, LE),
|
|
471
498
|
cancelableBySender: Boolean(raw.cancelable_by_sender),
|
|
472
499
|
cancelableByRecipient: Boolean(raw.cancelable_by_recipient),
|
|
473
500
|
automaticWithdrawal: Boolean(raw.automatic_withdrawal),
|
|
@@ -475,12 +502,12 @@ var decodeStream = (buf) => {
|
|
|
475
502
|
transferableByRecipient: Boolean(raw.transferable_by_recipient),
|
|
476
503
|
canTopup: Boolean(raw.can_topup),
|
|
477
504
|
name: decoder.decode(raw.stream_name),
|
|
478
|
-
withdrawFrequency: new
|
|
505
|
+
withdrawFrequency: new BN3(raw.withdraw_frequency, LE),
|
|
479
506
|
closed: Boolean(raw.closed),
|
|
480
|
-
currentPauseStart: new
|
|
481
|
-
pauseCumulative: new
|
|
482
|
-
lastRateChangeTime: new
|
|
483
|
-
fundsUnlockedAtLastRateChange: new
|
|
507
|
+
currentPauseStart: new BN3(raw.current_pause_start, LE),
|
|
508
|
+
pauseCumulative: new BN3(raw.pause_cumulative, LE),
|
|
509
|
+
lastRateChangeTime: new BN3(raw.last_rate_change_time, LE),
|
|
510
|
+
fundsUnlockedAtLastRateChange: new BN3(raw.funds_unlocked_at_last_rate_change, LE)
|
|
484
511
|
};
|
|
485
512
|
};
|
|
486
513
|
async function signAllTransactionWithRecipients(sender, items) {
|
|
@@ -512,6 +539,19 @@ async function sendAndConfirmStreamRawTransaction(connection, batchItem, confirm
|
|
|
512
539
|
};
|
|
513
540
|
}
|
|
514
541
|
}
|
|
542
|
+
async function handleContractError(func, callback) {
|
|
543
|
+
try {
|
|
544
|
+
return await func();
|
|
545
|
+
} catch (err) {
|
|
546
|
+
if (err instanceof Error) {
|
|
547
|
+
if (callback) {
|
|
548
|
+
throw new ContractError(err, callback(err));
|
|
549
|
+
}
|
|
550
|
+
throw new ContractError(err);
|
|
551
|
+
}
|
|
552
|
+
throw err;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
515
555
|
function extractSolanaErrorCode(errorText, logs) {
|
|
516
556
|
let match = SOLANA_ERROR_MATCH_REGEX.exec(errorText);
|
|
517
557
|
if (!match && logs) {
|
|
@@ -841,28 +881,6 @@ var topupStreamInstruction = async (amount, programId, {
|
|
|
841
881
|
});
|
|
842
882
|
};
|
|
843
883
|
|
|
844
|
-
// common/BaseStreamClient.ts
|
|
845
|
-
var BaseStreamClient = class {
|
|
846
|
-
/**
|
|
847
|
-
* Returns total fee percent, streamflow fees + partner fees
|
|
848
|
-
* @param getFeesData structure with address for which we need to derive fee, either sender or partner usually
|
|
849
|
-
* @param chainSpecificParams additional parameters required by chain client
|
|
850
|
-
* @returns fee as floating number, so if fee is 0.99%, it will return 0.99
|
|
851
|
-
*/
|
|
852
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
853
|
-
async getTotalFee(getFeesData, chainSpecificParams) {
|
|
854
|
-
const fees = await this.getFees(getFeesData, chainSpecificParams);
|
|
855
|
-
if (fees) {
|
|
856
|
-
return fees.partnerFee + fees.streamflowFee;
|
|
857
|
-
}
|
|
858
|
-
return this.getDefaultStreamflowFee(chainSpecificParams);
|
|
859
|
-
}
|
|
860
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
861
|
-
extractErrorCode(err) {
|
|
862
|
-
return null;
|
|
863
|
-
}
|
|
864
|
-
};
|
|
865
|
-
|
|
866
884
|
// solana/descriptor/idl/streamflow_aligned_unlocks.json
|
|
867
885
|
var streamflow_aligned_unlocks_default = {
|
|
868
886
|
address: "aSTRM2NKoKxNnkmLWk9sz3k74gKBk9t7bpPrTGxMszH",
|
|
@@ -2376,12 +2394,11 @@ var deriveTestOraclePDA = (programId, mint, creator) => {
|
|
|
2376
2394
|
// solana/StreamClient.ts
|
|
2377
2395
|
var METADATA_ACC_SIZE = 1104;
|
|
2378
2396
|
var ALIGNED_METADATA_ACC_SIZE = 320;
|
|
2379
|
-
var SolanaStreamClient = class
|
|
2397
|
+
var SolanaStreamClient = class {
|
|
2380
2398
|
/**
|
|
2381
2399
|
* Create Stream instance
|
|
2382
2400
|
*/
|
|
2383
2401
|
constructor(optionsOrClusterUrl, cluster = ICluster.Mainnet, commitment = "confirmed", programId = "", sendRate = 1, sendThrottler) {
|
|
2384
|
-
super();
|
|
2385
2402
|
if (typeof optionsOrClusterUrl === "string") {
|
|
2386
2403
|
this.commitment = commitment;
|
|
2387
2404
|
this.connection = new Connection(optionsOrClusterUrl, this.commitment);
|
|
@@ -2422,6 +2439,9 @@ var SolanaStreamClient = class extends BaseStreamClient {
|
|
|
2422
2439
|
getProgramId() {
|
|
2423
2440
|
return this.programId.toBase58();
|
|
2424
2441
|
}
|
|
2442
|
+
getAlignedProxyProgramId() {
|
|
2443
|
+
return this.alignedProxyProgram.programId.toBase58();
|
|
2444
|
+
}
|
|
2425
2445
|
/**
|
|
2426
2446
|
* Builds transaction instructions for creating a new stream/vesting contract without creating a transaction.
|
|
2427
2447
|
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
|
|
@@ -2430,7 +2450,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
|
|
|
2430
2450
|
* (before stream creation) to ensure the WSOL account exists when the stream creation instruction executes.
|
|
2431
2451
|
*
|
|
2432
2452
|
* @param {ICreateStreamData} data - Stream parameters including recipient, token, amount, schedule, and permissions
|
|
2433
|
-
* @param {Omit<
|
|
2453
|
+
* @param {Omit<ICreateStreamExt, "sender"> & { senderPublicKey: PublicKey }} extParams - Transaction configuration including sender public key, native token handling, and custom instructions
|
|
2434
2454
|
* @returns Transaction instructions and metadata ID
|
|
2435
2455
|
*/
|
|
2436
2456
|
async buildCreateTransactionInstructions(data, extParams) {
|
|
@@ -2477,7 +2497,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
|
|
|
2477
2497
|
* (before stream creation) to ensure the WSOL account exists when the stream creation instruction executes.
|
|
2478
2498
|
*
|
|
2479
2499
|
* @param {ICreateStreamData} data - Stream parameters including recipient, token, amount, schedule, and permissions
|
|
2480
|
-
* @param {Omit<
|
|
2500
|
+
* @param {Omit<ICreateStreamExt, "sender"> & { senderPublicKey: PublicKey }} extParams - Transaction configuration including sender public key, native token handling, and custom instructions
|
|
2481
2501
|
* @returns Transaction and metadata information
|
|
2482
2502
|
*/
|
|
2483
2503
|
async buildCreateTransaction(data, extParams) {
|
|
@@ -2498,7 +2518,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
|
|
|
2498
2518
|
* Creates a new stream/vesting contract.
|
|
2499
2519
|
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
|
|
2500
2520
|
* @param {ICreateStreamData} data - Stream parameters including recipient, token, amount, schedule, and permissions
|
|
2501
|
-
* @param {
|
|
2521
|
+
* @param {ICreateStreamExt} extParams - Transaction configuration including sender wallet, native token handling, and compute settings
|
|
2502
2522
|
* @returns Create result
|
|
2503
2523
|
*/
|
|
2504
2524
|
async create(data, extParams) {
|
|
@@ -2586,11 +2606,11 @@ var SolanaStreamClient = class extends BaseStreamClient {
|
|
|
2586
2606
|
const encodedUIntArray = new TextEncoder().encode(streamName);
|
|
2587
2607
|
const streamNameArray = Array.from(encodedUIntArray);
|
|
2588
2608
|
const createIx = await this.alignedProxyProgram.methods.create({
|
|
2589
|
-
startTime: new
|
|
2609
|
+
startTime: new BN3(start),
|
|
2590
2610
|
netAmountDeposited: depositedAmount,
|
|
2591
|
-
period: new
|
|
2611
|
+
period: new BN3(period),
|
|
2592
2612
|
amountPerPeriod,
|
|
2593
|
-
cliff: new
|
|
2613
|
+
cliff: new BN3(cliff),
|
|
2594
2614
|
cliffAmount,
|
|
2595
2615
|
transferableBySender,
|
|
2596
2616
|
transferableByRecipient,
|
|
@@ -2599,15 +2619,15 @@ var SolanaStreamClient = class extends BaseStreamClient {
|
|
|
2599
2619
|
canTopup,
|
|
2600
2620
|
oracleType: !!oracleType ? { [oracleType]: {} } : { none: {} },
|
|
2601
2621
|
streamName: streamNameArray,
|
|
2602
|
-
minPrice: typeof minPrice === "number" ? getBN(minPrice,
|
|
2603
|
-
maxPrice: typeof maxPrice === "number" ? getBN(maxPrice,
|
|
2604
|
-
minPercentage: typeof minPercentage === "number" ? getBN(minPercentage,
|
|
2605
|
-
maxPercentage: typeof maxPercentage === "number" ? getBN(maxPercentage,
|
|
2606
|
-
tickSize: new
|
|
2622
|
+
minPrice: typeof minPrice === "number" ? getBN(minPrice, ALIGNED_PRECISION_FACTOR_POW2) : minPrice,
|
|
2623
|
+
maxPrice: typeof maxPrice === "number" ? getBN(maxPrice, ALIGNED_PRECISION_FACTOR_POW2) : maxPrice,
|
|
2624
|
+
minPercentage: typeof minPercentage === "number" ? getBN(minPercentage, ALIGNED_PRECISION_FACTOR_POW2) : minPercentage,
|
|
2625
|
+
maxPercentage: typeof maxPercentage === "number" ? getBN(maxPercentage, ALIGNED_PRECISION_FACTOR_POW2) : maxPercentage,
|
|
2626
|
+
tickSize: new BN3(tickSize || 1),
|
|
2607
2627
|
skipInitial: skipInitial ?? false,
|
|
2608
|
-
expiryTime: new
|
|
2609
|
-
expiryPercentage: typeof expiryPercentage === "number" ? getBN(expiryPercentage,
|
|
2610
|
-
floorPrice: typeof floorPrice === "number" ? getBN(floorPrice,
|
|
2628
|
+
expiryTime: new BN3(expiryTime ?? 0),
|
|
2629
|
+
expiryPercentage: typeof expiryPercentage === "number" ? getBN(expiryPercentage, ALIGNED_PRECISION_FACTOR_POW2) : expiryPercentage ?? new BN3(0),
|
|
2630
|
+
floorPrice: typeof floorPrice === "number" ? getBN(floorPrice, ALIGNED_PRECISION_FACTOR_POW2) : floorPrice ?? new BN3(0)
|
|
2611
2631
|
}).accountsPartial({
|
|
2612
2632
|
payer: sender.publicKey,
|
|
2613
2633
|
sender: sender.publicKey,
|
|
@@ -2629,7 +2649,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
|
|
|
2629
2649
|
* Creates a new stream/vesting contract.
|
|
2630
2650
|
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
|
|
2631
2651
|
* @param {ICreateStreamData} data - Stream parameters including recipient, token, amount, schedule, and permissions
|
|
2632
|
-
* @param {
|
|
2652
|
+
* @param {IPrepareCreateStreamExt} extParams - Transaction configuration including sender wallet, metadata keys, and compute settings
|
|
2633
2653
|
* @returns Create stream instructions
|
|
2634
2654
|
*/
|
|
2635
2655
|
async prepareCreateStreamInstructions({
|
|
@@ -2678,12 +2698,12 @@ var SolanaStreamClient = class extends BaseStreamClient {
|
|
|
2678
2698
|
ixs.push(
|
|
2679
2699
|
await createStreamInstruction(
|
|
2680
2700
|
{
|
|
2681
|
-
start: new
|
|
2701
|
+
start: new BN3(start),
|
|
2682
2702
|
depositedAmount,
|
|
2683
|
-
period: new
|
|
2703
|
+
period: new BN3(period),
|
|
2684
2704
|
amountPerPeriod,
|
|
2685
|
-
cliff: new
|
|
2686
|
-
cliffAmount: new
|
|
2705
|
+
cliff: new BN3(cliff),
|
|
2706
|
+
cliffAmount: new BN3(cliffAmount),
|
|
2687
2707
|
cancelableBySender,
|
|
2688
2708
|
cancelableByRecipient,
|
|
2689
2709
|
automaticWithdrawal,
|
|
@@ -2693,7 +2713,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
|
|
|
2693
2713
|
canUpdateRate: !!canUpdateRate,
|
|
2694
2714
|
canPause: !!canPause,
|
|
2695
2715
|
name,
|
|
2696
|
-
withdrawFrequency: new
|
|
2716
|
+
withdrawFrequency: new BN3(automaticWithdrawal ? withdrawalFrequency : period)
|
|
2697
2717
|
},
|
|
2698
2718
|
this.programId,
|
|
2699
2719
|
{
|
|
@@ -2730,7 +2750,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
|
|
|
2730
2750
|
*
|
|
2731
2751
|
* If you are not sure if you should use create or create_unchecked, go for create to be safer.
|
|
2732
2752
|
* @param {ICreateStreamData} data - Stream parameters including recipient, token, amount, schedule, and permissions
|
|
2733
|
-
* @param {
|
|
2753
|
+
* @param {ICreateStreamExt} extParams - Transaction configuration including sender wallet, metadata keys, and compute settings
|
|
2734
2754
|
* @returns Create result
|
|
2735
2755
|
*/
|
|
2736
2756
|
async createUnchecked(data, extParams) {
|
|
@@ -2812,12 +2832,12 @@ var SolanaStreamClient = class extends BaseStreamClient {
|
|
|
2812
2832
|
}
|
|
2813
2833
|
const createInstruction = await createUncheckedStreamInstruction(
|
|
2814
2834
|
{
|
|
2815
|
-
start: new
|
|
2835
|
+
start: new BN3(start),
|
|
2816
2836
|
depositedAmount,
|
|
2817
|
-
period: new
|
|
2837
|
+
period: new BN3(period),
|
|
2818
2838
|
amountPerPeriod,
|
|
2819
|
-
cliff: new
|
|
2820
|
-
cliffAmount: new
|
|
2839
|
+
cliff: new BN3(cliff),
|
|
2840
|
+
cliffAmount: new BN3(cliffAmount),
|
|
2821
2841
|
cancelableBySender,
|
|
2822
2842
|
cancelableByRecipient,
|
|
2823
2843
|
automaticWithdrawal,
|
|
@@ -2827,7 +2847,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
|
|
|
2827
2847
|
canUpdateRate: !!canUpdateRate,
|
|
2828
2848
|
canPause: !!canPause,
|
|
2829
2849
|
name,
|
|
2830
|
-
withdrawFrequency: new
|
|
2850
|
+
withdrawFrequency: new BN3(automaticWithdrawal ? withdrawalFrequency : period),
|
|
2831
2851
|
recipient: recipientPublicKey,
|
|
2832
2852
|
partner: partnerPublicKey
|
|
2833
2853
|
},
|
|
@@ -2853,7 +2873,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
|
|
|
2853
2873
|
* Builds transaction instructions for creating multiple stream/vesting contracts without creating transactions.
|
|
2854
2874
|
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
|
|
2855
2875
|
* @param {ICreateMultipleStreamData} data - Stream base parameters and array of recipients with individual amounts and settings
|
|
2856
|
-
* @param {
|
|
2876
|
+
* @param {IPrepareCreateStreamExt} extParams - Transaction configuration including sender public key, native token handling, and custom instructions
|
|
2857
2877
|
* @returns Create multiple transaction instructions
|
|
2858
2878
|
*/
|
|
2859
2879
|
async buildCreateMultipleTransactionInstructions(data, extParams) {
|
|
@@ -2896,7 +2916,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
|
|
|
2896
2916
|
true
|
|
2897
2917
|
);
|
|
2898
2918
|
if (isNative) {
|
|
2899
|
-
const totalDepositedAmount = recipients.reduce((acc, recipient) => recipient.amount.add(acc), new
|
|
2919
|
+
const totalDepositedAmount = recipients.reduce((acc, recipient) => recipient.amount.add(acc), new BN3(0));
|
|
2900
2920
|
const nativeInstructions = await prepareWrappedAccount(
|
|
2901
2921
|
this.connection,
|
|
2902
2922
|
sender.publicKey,
|
|
@@ -2934,7 +2954,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
|
|
|
2934
2954
|
* ```
|
|
2935
2955
|
*
|
|
2936
2956
|
* @param {ICreateMultipleStreamData} data - Stream base parameters and array of recipients with individual amounts and settings
|
|
2937
|
-
* @param {
|
|
2957
|
+
* @param {IPrepareCreateStreamExt} extParams - Transaction configuration including sender public key, native token handling, and custom instructions
|
|
2938
2958
|
* @returns Multiple transaction information
|
|
2939
2959
|
*/
|
|
2940
2960
|
async buildCreateMultipleTransactions(data, extParams) {
|
|
@@ -2962,7 +2982,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
|
|
|
2962
2982
|
* Creates multiple stream/vesting contracts.
|
|
2963
2983
|
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
|
|
2964
2984
|
* @param {ICreateMultipleStreamData} data - Stream base parameters and array of recipients with individual amounts and settings
|
|
2965
|
-
* @param {
|
|
2985
|
+
* @param {ICreateStreamExt} extParams - Transaction configuration including sender wallet, metadata keys, and compute settings
|
|
2966
2986
|
* @returns Multiple transaction information
|
|
2967
2987
|
*/
|
|
2968
2988
|
async createMultiple(data, extParams) {
|
|
@@ -3027,7 +3047,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
|
|
|
3027
3047
|
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
|
|
3028
3048
|
* In most cases, createMultiple should be used instead.
|
|
3029
3049
|
* @param {ICreateMultipleStreamData} data - Stream base parameters and array of recipients with individual amounts and settings
|
|
3030
|
-
* @param {
|
|
3050
|
+
* @param {ICreateStreamExt} extParams - Transaction configuration including sender wallet, metadata keys, and compute settings
|
|
3031
3051
|
* @returns Multiple transaction information
|
|
3032
3052
|
*/
|
|
3033
3053
|
async createMultipleSequential(data, extParams) {
|
|
@@ -3093,7 +3113,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
|
|
|
3093
3113
|
/**
|
|
3094
3114
|
* Attempts withdrawing from the specified stream.
|
|
3095
3115
|
* @param {IWithdrawData} withdrawData - Withdrawal parameters including stream ID and amount to withdraw
|
|
3096
|
-
* @param {
|
|
3116
|
+
* @param {IInteractStreamExt} extParams - Transaction configuration including invoker wallet, token account validation, and compute settings
|
|
3097
3117
|
* @returns Transaction result
|
|
3098
3118
|
*/
|
|
3099
3119
|
async withdraw({ id, amount = WITHDRAW_AVAILABLE_AMOUNT }, extParams) {
|
|
@@ -3122,7 +3142,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
|
|
|
3122
3142
|
/**
|
|
3123
3143
|
* Creates Transaction Instructions for withdrawal
|
|
3124
3144
|
* @param {IWithdrawData} withdrawData - Withdrawal parameters including stream ID and amount to withdraw
|
|
3125
|
-
* @param {
|
|
3145
|
+
* @param {IPrepareStreamExt} extParams - Transaction configuration including invoker wallet address, token account validation, and compute settings
|
|
3126
3146
|
* @returns Transaction instructions
|
|
3127
3147
|
*/
|
|
3128
3148
|
async prepareWithdrawInstructions({ id, amount = WITHDRAW_AVAILABLE_AMOUNT }, { invoker, checkTokenAccounts, computePrice, computeLimit }) {
|
|
@@ -3167,7 +3187,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
|
|
|
3167
3187
|
/**
|
|
3168
3188
|
* Attempts canceling the specified stream.
|
|
3169
3189
|
* @param {ICancelData} cancelData - Cancellation parameters including stream ID
|
|
3170
|
-
* @param {
|
|
3190
|
+
* @param {IInteractStreamExt} extParams - Transaction configuration including invoker wallet, token account validation, and compute settings
|
|
3171
3191
|
* @returns Transaction result
|
|
3172
3192
|
*/
|
|
3173
3193
|
async cancel(cancelData, extParams) {
|
|
@@ -3189,7 +3209,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
|
|
|
3189
3209
|
/**
|
|
3190
3210
|
* Creates Transaction Instructions for cancel
|
|
3191
3211
|
* @param {ICancelData} cancelData - Cancellation parameters including stream ID
|
|
3192
|
-
* @param {
|
|
3212
|
+
* @param {IPrepareStreamExt} extParams - Transaction configuration including invoker wallet address, token account validation, and compute settings
|
|
3193
3213
|
* @returns Transaction instructions
|
|
3194
3214
|
*/
|
|
3195
3215
|
async prepareCancelInstructions(cancelData, extParams) {
|
|
@@ -3206,7 +3226,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
|
|
|
3206
3226
|
/**
|
|
3207
3227
|
* Creates Transaction Instructions for cancel
|
|
3208
3228
|
* @param {ICancelData} cancelData - Cancellation parameters including stream ID
|
|
3209
|
-
* @param {
|
|
3229
|
+
* @param {IPrepareStreamExt} extParams - Transaction configuration including invoker wallet, token account validation, and compute settings
|
|
3210
3230
|
* @returns Transaction instructions
|
|
3211
3231
|
*/
|
|
3212
3232
|
async prepareCancelAlignedUnlockInstructions({ id }, { invoker, checkTokenAccounts, computePrice, computeLimit }) {
|
|
@@ -3245,7 +3265,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
|
|
|
3245
3265
|
/**
|
|
3246
3266
|
* Creates Transaction Instructions for cancel
|
|
3247
3267
|
* @param {ICancelData} cancelData - Cancellation parameters including stream ID
|
|
3248
|
-
* @param {
|
|
3268
|
+
* @param {IPrepareStreamExt} extParams - Transaction configuration including invoker wallet, token account validation, and compute settings
|
|
3249
3269
|
* @returns Transaction instructions
|
|
3250
3270
|
*/
|
|
3251
3271
|
async prepareCancelStreamInstructions({ id }, { invoker, checkTokenAccounts, computePrice, computeLimit }) {
|
|
@@ -3293,7 +3313,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
|
|
|
3293
3313
|
* Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
|
|
3294
3314
|
* Potential associated token account rent fee (to make it rent-exempt) is paid by the transaction initiator.
|
|
3295
3315
|
* @param {ITransferData} transferData - Transfer parameters including stream ID and new recipient address
|
|
3296
|
-
* @param {
|
|
3316
|
+
* @param {IInteractStreamExt} extParams - Transaction configuration including invoker wallet and compute settings
|
|
3297
3317
|
* @returns Transaction result
|
|
3298
3318
|
*/
|
|
3299
3319
|
async transfer({ id, newRecipient }, extParams) {
|
|
@@ -3316,7 +3336,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
|
|
|
3316
3336
|
* Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
|
|
3317
3337
|
* Potential associated token account rent fee (to make it rent-exempt) is paid by the transaction initiator.
|
|
3318
3338
|
* @param {ITransferData} transferData - Transfer parameters including stream ID and new recipient address
|
|
3319
|
-
* @param {
|
|
3339
|
+
* @param {IPrepareStreamExt} extParams - Transaction configuration including invoker wallet and compute settings
|
|
3320
3340
|
* @returns Transaction instructions
|
|
3321
3341
|
*/
|
|
3322
3342
|
async prepareTransferInstructions({ id, newRecipient }, { invoker, computePrice, computeLimit = 100001 }) {
|
|
@@ -3350,7 +3370,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
|
|
|
3350
3370
|
/**
|
|
3351
3371
|
* Tops up stream account with specified amount.
|
|
3352
3372
|
* @param {ITopUpData} topupData - Top-up parameters including stream ID and amount to add
|
|
3353
|
-
* @param {
|
|
3373
|
+
* @param {ITopUpStreamExt} extParams - Transaction configuration including invoker wallet, native token handling, and compute settings
|
|
3354
3374
|
* @returns Transaction result
|
|
3355
3375
|
*/
|
|
3356
3376
|
async topup({ id, amount }, extParams) {
|
|
@@ -3372,7 +3392,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
|
|
|
3372
3392
|
/**
|
|
3373
3393
|
* Create Transaction instructions for topup
|
|
3374
3394
|
* @param {ITopUpData} topupData - Top-up parameters including stream ID and amount to add
|
|
3375
|
-
* @param {
|
|
3395
|
+
* @param {ITopUpStreamExt} extParams - Transaction configuration including invoker wallet, native token handling, and compute settings
|
|
3376
3396
|
* @returns Transaction instructions
|
|
3377
3397
|
*/
|
|
3378
3398
|
async prepareTopupInstructions({ id, amount }, { invoker, isNative, computePrice, computeLimit }) {
|
|
@@ -3560,7 +3580,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
|
|
|
3560
3580
|
/**
|
|
3561
3581
|
* Attempts updating the stream auto withdrawal params and amount per period
|
|
3562
3582
|
* @param {IUpdateData} data - Update parameters including stream ID and new settings
|
|
3563
|
-
* @param {
|
|
3583
|
+
* @param {IInteractStreamExt} extParams - Transaction configuration including invoker wallet and compute settings
|
|
3564
3584
|
* @returns Transaction result
|
|
3565
3585
|
*/
|
|
3566
3586
|
async update(data, extParams) {
|
|
@@ -3588,7 +3608,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
|
|
|
3588
3608
|
/**
|
|
3589
3609
|
* Create Transaction instructions for update
|
|
3590
3610
|
* @param {IUpdateData} data - Update parameters including stream ID and new settings
|
|
3591
|
-
* @param {
|
|
3611
|
+
* @param {IPrepareStreamExt} extParams - Transaction configuration including invoker wallet and compute settings
|
|
3592
3612
|
* @returns Transaction instructions
|
|
3593
3613
|
*/
|
|
3594
3614
|
async prepareUpdateInstructions(data, { invoker, computePrice, computeLimit }) {
|
|
@@ -3641,6 +3661,20 @@ var SolanaStreamClient = class extends BaseStreamClient {
|
|
|
3641
3661
|
async getDefaultStreamflowFee() {
|
|
3642
3662
|
return DEFAULT_STREAMFLOW_FEE;
|
|
3643
3663
|
}
|
|
3664
|
+
/**
|
|
3665
|
+
* Returns total fee percent, streamflow fees + partner fees
|
|
3666
|
+
* @param getFeesData structure with address for which we need to derive fee, either sender or partner usually
|
|
3667
|
+
* @param chainSpecificParams additional parameters required by chain client
|
|
3668
|
+
* @returns fee as floating number, so if fee is 0.99%, it will return 0.99
|
|
3669
|
+
*/
|
|
3670
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3671
|
+
async getTotalFee(getFeesData) {
|
|
3672
|
+
const fees = await this.getFees(getFeesData);
|
|
3673
|
+
if (fees) {
|
|
3674
|
+
return fees.partnerFee + fees.streamflowFee;
|
|
3675
|
+
}
|
|
3676
|
+
return this.getDefaultStreamflowFee();
|
|
3677
|
+
}
|
|
3644
3678
|
/**
|
|
3645
3679
|
* Extracts error code from an error
|
|
3646
3680
|
* @param {Error} err - Error
|
|
@@ -3650,6 +3684,13 @@ var SolanaStreamClient = class extends BaseStreamClient {
|
|
|
3650
3684
|
const logs = "logs" in err && Array.isArray(err.logs) ? err.logs : void 0;
|
|
3651
3685
|
return extractSolanaErrorCode(err.toString() ?? "Unknown error!", logs);
|
|
3652
3686
|
}
|
|
3687
|
+
/**
|
|
3688
|
+
* Utility function that checks whether the associated stream address is an aligned unlock contract, indicated by whether the sender/creator is a PDA
|
|
3689
|
+
*/
|
|
3690
|
+
isAlignedUnlock(streamPublicKey, senderPublicKey) {
|
|
3691
|
+
const pda = deriveContractPDA(this.alignedProxyProgram.programId, streamPublicKey);
|
|
3692
|
+
return senderPublicKey.equals(pda);
|
|
3693
|
+
}
|
|
3653
3694
|
/**
|
|
3654
3695
|
* Utility function to generate metadata for a Contract or return existing Pubkey
|
|
3655
3696
|
*/
|
|
@@ -3664,13 +3705,6 @@ var SolanaStreamClient = class extends BaseStreamClient {
|
|
|
3664
3705
|
}
|
|
3665
3706
|
return { metadata, metadataPubKey };
|
|
3666
3707
|
}
|
|
3667
|
-
/**
|
|
3668
|
-
* Utility function that checks whether the associated stream address is an aligned unlock contract, indicated by whether the sender/creator is a PDA
|
|
3669
|
-
*/
|
|
3670
|
-
isAlignedUnlock(streamPublicKey, senderPublicKey) {
|
|
3671
|
-
const pda = deriveContractPDA(this.alignedProxyProgram.programId, streamPublicKey);
|
|
3672
|
-
return senderPublicKey.equals(pda);
|
|
3673
|
-
}
|
|
3674
3708
|
/**
|
|
3675
3709
|
* Returns insrtuctions for creating associated token accounts for the provided owners
|
|
3676
3710
|
*/
|
|
@@ -4116,6 +4150,6 @@ var timelockIDL_default = {
|
|
|
4116
4150
|
]
|
|
4117
4151
|
};
|
|
4118
4152
|
|
|
4119
|
-
export { AlignedContract, Contract,
|
|
4153
|
+
export { AIRDROP_AMOUNT, AIRDROP_TEST_TOKEN, ALIGNED_COMPUTE_LIMIT, ALIGNED_PRECISION_FACTOR_POW2 as ALIGNED_PRECISION_FACTOR_POW, ALIGNED_UNLOCKS_PROGRAM_ID, AlignedContract, AlignedProxyErrorCode, CONTRACT_DISCRIMINATOR, CONTRACT_SEED, CREATE_PARAMS_PADDING, Contract, ContractErrorCode, DEFAULT_STREAMFLOW_FEE, ESCROW_SEED, FEES_METADATA_SEED, FEE_ORACLE_PUBLIC_KEY, MAX_SAFE_UNIX_TIME_VALUE2 as MAX_SAFE_UNIX_TIME_VALUE, ORIGINAL_CONTRACT_SENDER_OFFSET, PARTNERS_SCHEMA, PARTNER_ORACLE_PROGRAM_ID, PARTNER_SCHEMA, PROGRAM_ID, SOLANA_ERROR_MAP, SOLANA_ERROR_MATCH_REGEX, STREAMFLOW_TREASURY_PUBLIC_KEY, STREAM_STRUCT_OFFSETS, STREAM_STRUCT_OFFSET_CLOSED, STREAM_STRUCT_OFFSET_MINT, STREAM_STRUCT_OFFSET_RECIPIENT, STREAM_STRUCT_OFFSET_SENDER, SolanaStreamClient, StreamDirection, StreamType, TEST_ORACLE_DISCRIMINATOR, TEST_ORACLE_SEED, TX_FINALITY_CONFIRMED, WITHDRAWOR_PUBLIC_KEY, WITHDRAW_AVAILABLE_AMOUNT, buildStreamType, calculateTotalAmountToDeposit, calculateUnlockedAmount, cancelStreamInstruction, createStreamInstruction, createUncheckedStreamInstruction, decodeEndTime, decodeStream, deriveContractPDA, deriveEscrowPDA, deriveTestOraclePDA, extractSolanaErrorCode, handleContractError, isAligned, isCliffCloseToDepositedAmount, isCreateAlignedStreamData, isDynamicLock, isPayment, isTokenLock, isVesting, sendAndConfirmStreamRawTransaction, signAllTransactionWithRecipients, timelockIDL_default as timelockIDL, topupStreamInstruction, transferStreamInstruction, updateStreamInstruction, withdrawStreamInstruction };
|
|
4120
4154
|
//# sourceMappingURL=index.js.map
|
|
4121
4155
|
//# sourceMappingURL=index.js.map
|