@streamflow/stream 11.0.0-alpha.p334.fcf4225 → 11.0.1
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/dist/cjs/index.cjs +58 -19
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +1 -1
- package/dist/cjs/solana/index.cjs +58 -19
- package/dist/cjs/solana/index.cjs.map +1 -1
- package/dist/cjs/solana/index.d.cts +15 -3
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +57 -20
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/solana/index.d.ts +15 -3
- package/dist/esm/solana/index.js +57 -20
- package/dist/esm/solana/index.js.map +1 -1
- package/package.json +4 -4
package/dist/cjs/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { AIRDROP_AMOUNT, AIRDROP_TEST_TOKEN, ALIGNED_COMPUTE_LIMIT, ALIGNED_PRECISION_FACTOR_POW, ALIGNED_UNLOCKS_PROGRAM_ID, Account, AlignedContract, AlignedProxyErrorCode, AlignedStream, AlignedStreamData, AlignedUnlocksContract, BatchItem, BatchItemError, BatchItemResult, BatchItemSuccess, CONTRACT_DISCRIMINATOR, CONTRACT_SEED, CREATE_PARAMS_PADDING, ChangeOracleParams, ClientCreationOptions, Contract, ContractErrorCode, CreateParams, CreateTestOracleParams, DEFAULT_AUTO_CLAIM_FEE_SOL, DEFAULT_CREATION_FEE_SOL, DEFAULT_STREAMFLOW_FEE, DecodedStream, ESCROW_SEED, FEES_METADATA_SEED, FEE_ORACLE_PUBLIC_KEY, IAlignedStreamConfig, IBaseStreamConfig, ICancelData, ICreateAlignedStreamData, ICreateExt, ICreateLinearStreamData, ICreateMultiError, ICreateMultipleAlignedStreamData, ICreateMultipleLinearStreamData, ICreateMultipleStreamData, ICreateResult, ICreateStreamData, ICreateStreamExt, ICreateStreamInstructions, IFees, IGetAllData, IGetFeesData, IGetOneData, IInteractData, IInteractStreamExt, IMultiTransactionResult, IPrepareCreateStreamExt, IPrepareStreamExt, IRecipient, ISearchStreams, ITopUpData, ITopUpStreamExt, ITransactionExtWithInstructions, ITransactionResult, ITransferData, IUpdateData, IWithdrawData, InstructionGenerator, LinearStream, MAX_SAFE_UNIX_TIME_VALUE, MetadataRecipientHashMap, ORIGINAL_CONTRACT_SENDER_OFFSET, OracleType, OracleTypeName, 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, Stream, StreamClientOptions, StreamDirection, StreamType, TEST_ORACLE_DISCRIMINATOR, TEST_ORACLE_SEED, TX_FINALITY_CONFIRMED, TestOracle, TransactionSchedulingOptions, UpdateTestOracleParams, WITHDRAWOR, WITHDRAWOR_PUBLIC_KEY, WITHDRAW_AVAILABLE_AMOUNT, buildStreamType, calculateTotalAmountToDeposit, calculateUnlockedAmount, cancelStreamInstruction, createStreamInstruction, createUncheckedStreamInstruction, decodeEndTime, decodeStream, deriveContractPDA, deriveEscrowPDA, deriveTestOraclePDA, extractSolanaErrorCode, handleContractError, isAligned, isCliffCloseToDepositedAmount, isCreateAlignedStreamData, isDynamicLock, isTokenLock, isVesting, sendAndConfirmStreamRawTransaction, signAllTransactionWithRecipients, timelockIDL, topupStreamInstruction, transferStreamInstruction, updateStreamInstruction, withdrawStreamInstruction } from './solana/index.cjs';
|
|
1
|
+
export { AIRDROP_AMOUNT, AIRDROP_TEST_TOKEN, ALIGNED_COMPUTE_LIMIT, ALIGNED_PRECISION_FACTOR_POW, ALIGNED_UNLOCKS_PROGRAM_ID, Account, AlignedContract, AlignedProxyErrorCode, AlignedStream, AlignedStreamData, AlignedUnlocksContract, BatchItem, BatchItemError, BatchItemResult, BatchItemSuccess, CONTRACT_DISCRIMINATOR, CONTRACT_SEED, CREATE_PARAMS_PADDING, ChangeOracleParams, ClientCreationOptions, Contract, ContractErrorCode, CreateParams, CreateTestOracleParams, DEFAULT_AUTO_CLAIM_FEE_SOL, DEFAULT_CREATION_FEE_SOL, DEFAULT_STREAMFLOW_FEE, DecodedStream, ESCROW_SEED, FEES_METADATA_SEED, FEE_ORACLE_PUBLIC_KEY, IAlignedStreamConfig, IBaseStreamConfig, ICancelData, ICreateAlignedStreamData, ICreateExt, ICreateLinearStreamData, ICreateMultiError, ICreateMultipleAlignedStreamData, ICreateMultipleLinearStreamData, ICreateMultipleStreamData, ICreateResult, ICreateStreamData, ICreateStreamExt, ICreateStreamInstructions, IFees, IGetAllData, IGetFeesData, IGetOneData, IInteractData, IInteractStreamExt, IMultiTransactionResult, IPrepareCreateStreamExt, IPrepareStreamExt, IRecipient, ISearchStreams, ITopUpData, ITopUpStreamExt, ITransactionExtWithInstructions, ITransactionResult, ITransferData, IUpdateData, IWithdrawData, InstructionGenerator, LinearStream, MAX_SAFE_UNIX_TIME_VALUE, MetadataRecipientHashMap, ORIGINAL_CONTRACT_SENDER_OFFSET, OracleType, OracleTypeName, 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_OLD_METADATA_KEY, STREAM_STRUCT_OFFSET_RECIPIENT, STREAM_STRUCT_OFFSET_SENDER, SolanaStreamClient, Stream, StreamClientOptions, StreamDirection, StreamType, TEST_ORACLE_DISCRIMINATOR, TEST_ORACLE_SEED, TX_FINALITY_CONFIRMED, TestOracle, TransactionSchedulingOptions, UpdateTestOracleParams, WITHDRAWOR, WITHDRAWOR_PUBLIC_KEY, WITHDRAW_AVAILABLE_AMOUNT, buildStreamType, calculateTotalAmountToDeposit, calculateUnlockedAmount, cancelStreamInstruction, createStreamInstruction, createUncheckedStreamInstruction, decodeEndTime, decodeStream, deriveContractPDA, deriveEscrowPDA, deriveTestOraclePDA, extractSolanaErrorCode, getMetadataKey, handleContractError, isAligned, isCliffCloseToDepositedAmount, isCreateAlignedStreamData, isDynamicLock, isTokenLock, isVesting, sendAndConfirmStreamRawTransaction, signAllTransactionWithRecipients, timelockIDL, topupStreamInstruction, transferStreamInstruction, updateStreamInstruction, withdrawStreamInstruction } from './solana/index.cjs';
|
|
2
2
|
export { ContractError, ICluster, getBN, getNumberFromBN } from '@streamflow/common';
|
|
3
3
|
import 'p-queue';
|
|
4
4
|
import '@solana/web3.js';
|
|
@@ -185,6 +185,7 @@ var Contract = class {
|
|
|
185
185
|
this.pauseCumulative = stream.pauseCumulative;
|
|
186
186
|
this.lastRateChangeTime = stream.lastRateChangeTime.toNumber();
|
|
187
187
|
this.fundsUnlockedAtLastRateChange = stream.fundsUnlockedAtLastRateChange;
|
|
188
|
+
this.oldMetadata = stream.oldMetadata;
|
|
188
189
|
this.type = buildStreamType(this);
|
|
189
190
|
this.isAligned = false;
|
|
190
191
|
}
|
|
@@ -229,6 +230,7 @@ var STREAM_STRUCT_OFFSET_SENDER = 49;
|
|
|
229
230
|
var STREAM_STRUCT_OFFSET_RECIPIENT = 113;
|
|
230
231
|
var STREAM_STRUCT_OFFSET_MINT = 177;
|
|
231
232
|
var STREAM_STRUCT_OFFSET_CLOSED = 671;
|
|
233
|
+
var STREAM_STRUCT_OFFSET_OLD_METADATA_KEY = 714;
|
|
232
234
|
var MAX_SAFE_UNIX_TIME_VALUE2 = 864e10;
|
|
233
235
|
var WITHDRAW_AVAILABLE_AMOUNT = new BN3__default.default("18446744073709551615");
|
|
234
236
|
var ALIGNED_PRECISION_FACTOR_POW2 = 9;
|
|
@@ -377,7 +379,12 @@ var streamLayout = BufferLayout__namespace.struct([
|
|
|
377
379
|
BufferLayout__namespace.blob(8, "current_pause_start"),
|
|
378
380
|
BufferLayout__namespace.blob(8, "pause_cumulative"),
|
|
379
381
|
BufferLayout__namespace.blob(8, "last_rate_change_time"),
|
|
380
|
-
BufferLayout__namespace.blob(8, "funds_unlocked_at_last_rate_change")
|
|
382
|
+
BufferLayout__namespace.blob(8, "funds_unlocked_at_last_rate_change"),
|
|
383
|
+
BufferLayout__namespace.u32("creation_fee"),
|
|
384
|
+
BufferLayout__namespace.u8("creation_fee_claimed"),
|
|
385
|
+
BufferLayout__namespace.u32("auto_claim_fee"),
|
|
386
|
+
BufferLayout__namespace.u8("auto_claim_fee_claimed"),
|
|
387
|
+
BufferLayout__namespace.blob(32, "old_metadata")
|
|
381
388
|
]);
|
|
382
389
|
BufferLayout__namespace.struct([
|
|
383
390
|
BufferLayout__namespace.blob(32, "pubkey"),
|
|
@@ -488,6 +495,12 @@ var encodeUpdateStream = (values, data) => {
|
|
|
488
495
|
var topupStreamLayout = BufferLayout__namespace.struct([
|
|
489
496
|
BufferLayout__namespace.blob(8, "amount")
|
|
490
497
|
]);
|
|
498
|
+
var getMetadataKey = (streamPubkey, oldMetadata) => {
|
|
499
|
+
if (web3_js.PublicKey.default.equals(oldMetadata)) {
|
|
500
|
+
return streamPubkey;
|
|
501
|
+
}
|
|
502
|
+
return oldMetadata;
|
|
503
|
+
};
|
|
491
504
|
var FEE_PRECISION = 4;
|
|
492
505
|
var FEE_NORMALIZER = 10 ** FEE_PRECISION;
|
|
493
506
|
var FEE_MULTIPLIER = new BN3__default.default(10 ** 6);
|
|
@@ -541,7 +554,8 @@ var decodeStream = (buf) => {
|
|
|
541
554
|
currentPauseStart: new BN3__default.default(raw.current_pause_start, LE),
|
|
542
555
|
pauseCumulative: new BN3__default.default(raw.pause_cumulative, LE),
|
|
543
556
|
lastRateChangeTime: new BN3__default.default(raw.last_rate_change_time, LE),
|
|
544
|
-
fundsUnlockedAtLastRateChange: new BN3__default.default(raw.funds_unlocked_at_last_rate_change, LE)
|
|
557
|
+
fundsUnlockedAtLastRateChange: new BN3__default.default(raw.funds_unlocked_at_last_rate_change, LE),
|
|
558
|
+
oldMetadata: new web3_js.PublicKey(raw.old_metadata)
|
|
545
559
|
};
|
|
546
560
|
};
|
|
547
561
|
async function signAllTransactionWithRecipients(sender, items) {
|
|
@@ -3345,8 +3359,8 @@ var SolanaStreamClient = class {
|
|
|
3345
3359
|
if (!account) {
|
|
3346
3360
|
throw new Error("Impossible to cancel a stream contract that does not exist");
|
|
3347
3361
|
}
|
|
3348
|
-
const
|
|
3349
|
-
const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey,
|
|
3362
|
+
const decoded = decodeStream(account.data);
|
|
3363
|
+
const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey, decoded.sender, decoded.oldMetadata);
|
|
3350
3364
|
const ixs = isAlignedUnlock ? await this.prepareCancelAlignedUnlockInstructions(cancelData, extParams) : await this.prepareCancelLinearStream(cancelData, extParams);
|
|
3351
3365
|
return ixs;
|
|
3352
3366
|
}
|
|
@@ -3568,13 +3582,31 @@ var SolanaStreamClient = class {
|
|
|
3568
3582
|
async getOne({ id }) {
|
|
3569
3583
|
const streamPublicKey = new web3_js.PublicKey(id);
|
|
3570
3584
|
const escrow = await this.connection.getAccountInfo(streamPublicKey, TX_FINALITY_CONFIRMED);
|
|
3571
|
-
if (
|
|
3585
|
+
if (escrow?.data) {
|
|
3586
|
+
return this.decodeStreamAccount(streamPublicKey, escrow.data);
|
|
3587
|
+
}
|
|
3588
|
+
const migrated = await this.connection.getProgramAccounts(this.programId, {
|
|
3589
|
+
filters: [
|
|
3590
|
+
{ dataSize: METADATA_ACC_SIZE },
|
|
3591
|
+
{
|
|
3592
|
+
memcmp: {
|
|
3593
|
+
offset: STREAM_STRUCT_OFFSET_OLD_METADATA_KEY,
|
|
3594
|
+
bytes: id
|
|
3595
|
+
}
|
|
3596
|
+
}
|
|
3597
|
+
]
|
|
3598
|
+
});
|
|
3599
|
+
if (migrated.length === 0) {
|
|
3572
3600
|
throw new Error("Couldn't get account info.");
|
|
3573
3601
|
}
|
|
3574
|
-
|
|
3575
|
-
|
|
3602
|
+
return this.decodeStreamAccount(migrated[0].pubkey, migrated[0].account.data);
|
|
3603
|
+
}
|
|
3604
|
+
async decodeStreamAccount(pubkey, data) {
|
|
3605
|
+
const stream = decodeStream(data);
|
|
3606
|
+
const metadataKey = getMetadataKey(pubkey, stream.oldMetadata);
|
|
3607
|
+
if (this.isAlignedUnlock(pubkey, stream.sender, stream.oldMetadata)) {
|
|
3576
3608
|
const alignedProxy = await this.alignedProxyProgram.account.contract.fetch(
|
|
3577
|
-
deriveContractPDA(this.alignedProxyProgram.programId,
|
|
3609
|
+
deriveContractPDA(this.alignedProxyProgram.programId, metadataKey)
|
|
3578
3610
|
);
|
|
3579
3611
|
if (!alignedProxy) {
|
|
3580
3612
|
throw new Error("Couldn't get proxy account info.");
|
|
@@ -3614,9 +3646,11 @@ var SolanaStreamClient = class {
|
|
|
3614
3646
|
async getIncomingAlignedStreams(streamRecord) {
|
|
3615
3647
|
const streams = {};
|
|
3616
3648
|
const alignedStreamsPubKeys = Object.keys(streamRecord);
|
|
3617
|
-
const alignedProxyPDAs = alignedStreamsPubKeys.map(
|
|
3618
|
-
|
|
3619
|
-
|
|
3649
|
+
const alignedProxyPDAs = alignedStreamsPubKeys.map((streamPubKey) => {
|
|
3650
|
+
const pubkey = new web3_js.PublicKey(streamPubKey);
|
|
3651
|
+
const metadataKey = getMetadataKey(pubkey, streamRecord[streamPubKey].oldMetadata);
|
|
3652
|
+
return deriveContractPDA(this.alignedProxyProgram.programId, metadataKey);
|
|
3653
|
+
});
|
|
3620
3654
|
const alignedProxyAccounts = await common.getMultipleAccountsInfoBatched(this.connection, alignedProxyPDAs);
|
|
3621
3655
|
alignedProxyAccounts.forEach((account, index) => {
|
|
3622
3656
|
if (account && account.data.length === ALIGNED_METADATA_ACC_SIZE) {
|
|
@@ -3668,7 +3702,7 @@ var SolanaStreamClient = class {
|
|
|
3668
3702
|
const allIncomingStreams = allIncomingAccounts.map((account) => decodeStream(account.account.data));
|
|
3669
3703
|
const alignedDecoded = {};
|
|
3670
3704
|
allIncomingAccounts.forEach((account, index) => {
|
|
3671
|
-
if (this.isAlignedUnlock(account.pubkey, allIncomingStreams[index].sender)) {
|
|
3705
|
+
if (this.isAlignedUnlock(account.pubkey, allIncomingStreams[index].sender, allIncomingStreams[index].oldMetadata)) {
|
|
3672
3706
|
alignedDecoded[account.pubkey.toBase58()] = allIncomingStreams[index];
|
|
3673
3707
|
} else {
|
|
3674
3708
|
streams[account.pubkey.toBase58()] = new Contract(allIncomingStreams[index]);
|
|
@@ -3713,8 +3747,9 @@ var SolanaStreamClient = class {
|
|
|
3713
3747
|
collectAlignedEntries(decoded) {
|
|
3714
3748
|
const entries = [];
|
|
3715
3749
|
decoded.forEach(({ pubkey, stream }, index) => {
|
|
3716
|
-
if (this.isAlignedUnlock(pubkey, stream.sender)) {
|
|
3717
|
-
|
|
3750
|
+
if (this.isAlignedUnlock(pubkey, stream.sender, stream.oldMetadata)) {
|
|
3751
|
+
const metadataKey = getMetadataKey(pubkey, stream.oldMetadata);
|
|
3752
|
+
entries.push({ index, pda: deriveContractPDA(this.alignedProxyProgram.programId, metadataKey) });
|
|
3718
3753
|
}
|
|
3719
3754
|
});
|
|
3720
3755
|
return entries;
|
|
@@ -3774,8 +3809,8 @@ var SolanaStreamClient = class {
|
|
|
3774
3809
|
const streamPublicKey = new web3_js.PublicKey(data.id);
|
|
3775
3810
|
const escrow = await this.connection.getAccountInfo(streamPublicKey);
|
|
3776
3811
|
common.invariant(escrow, "Couldn't get account info");
|
|
3777
|
-
const
|
|
3778
|
-
const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey,
|
|
3812
|
+
const decoded = decodeStream(escrow.data);
|
|
3813
|
+
const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey, decoded.sender, decoded.oldMetadata);
|
|
3779
3814
|
if (isAlignedUnlock && (data.enableAutomaticWithdrawal !== void 0 || data.amountPerPeriod !== void 0)) {
|
|
3780
3815
|
throw new Error("Automatic withdrawal and rate update are not possible in price-based vesting!");
|
|
3781
3816
|
}
|
|
@@ -3866,10 +3901,12 @@ var SolanaStreamClient = class {
|
|
|
3866
3901
|
return extractSolanaErrorCode(err.toString() ?? "Unknown error!", logs);
|
|
3867
3902
|
}
|
|
3868
3903
|
/**
|
|
3869
|
-
* Utility function that checks whether the associated stream address is an aligned unlock contract, indicated by whether the sender/creator is a PDA
|
|
3904
|
+
* Utility function that checks whether the associated stream address is an aligned unlock contract, indicated by whether the sender/creator is a PDA.
|
|
3905
|
+
* For migrated streams, the PDA was derived from the old metadata key.
|
|
3870
3906
|
*/
|
|
3871
|
-
isAlignedUnlock(streamPublicKey, senderPublicKey) {
|
|
3872
|
-
const
|
|
3907
|
+
isAlignedUnlock(streamPublicKey, senderPublicKey, oldMetadata) {
|
|
3908
|
+
const metadataKey = oldMetadata ? getMetadataKey(streamPublicKey, oldMetadata) : streamPublicKey;
|
|
3909
|
+
const pda = deriveContractPDA(this.alignedProxyProgram.programId, metadataKey);
|
|
3873
3910
|
return senderPublicKey.equals(pda);
|
|
3874
3911
|
}
|
|
3875
3912
|
async flatBuildCreateMultipleTransactionInstructions(data, extParams) {
|
|
@@ -4392,6 +4429,7 @@ exports.STREAMFLOW_TREASURY_PUBLIC_KEY = STREAMFLOW_TREASURY_PUBLIC_KEY;
|
|
|
4392
4429
|
exports.STREAM_STRUCT_OFFSETS = STREAM_STRUCT_OFFSETS;
|
|
4393
4430
|
exports.STREAM_STRUCT_OFFSET_CLOSED = STREAM_STRUCT_OFFSET_CLOSED;
|
|
4394
4431
|
exports.STREAM_STRUCT_OFFSET_MINT = STREAM_STRUCT_OFFSET_MINT;
|
|
4432
|
+
exports.STREAM_STRUCT_OFFSET_OLD_METADATA_KEY = STREAM_STRUCT_OFFSET_OLD_METADATA_KEY;
|
|
4395
4433
|
exports.STREAM_STRUCT_OFFSET_RECIPIENT = STREAM_STRUCT_OFFSET_RECIPIENT;
|
|
4396
4434
|
exports.STREAM_STRUCT_OFFSET_SENDER = STREAM_STRUCT_OFFSET_SENDER;
|
|
4397
4435
|
exports.SolanaStreamClient = SolanaStreamClient;
|
|
@@ -4415,6 +4453,7 @@ exports.deriveContractPDA = deriveContractPDA;
|
|
|
4415
4453
|
exports.deriveEscrowPDA = deriveEscrowPDA;
|
|
4416
4454
|
exports.deriveTestOraclePDA = deriveTestOraclePDA;
|
|
4417
4455
|
exports.extractSolanaErrorCode = extractSolanaErrorCode;
|
|
4456
|
+
exports.getMetadataKey = getMetadataKey;
|
|
4418
4457
|
exports.handleContractError = handleContractError;
|
|
4419
4458
|
exports.isAligned = isAligned;
|
|
4420
4459
|
exports.isCliffCloseToDepositedAmount = isCliffCloseToDepositedAmount;
|