@streamflow/stream 11.1.0 → 11.2.0
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 +313 -97
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +1 -1
- package/dist/cjs/solana/index.cjs +313 -97
- package/dist/cjs/solana/index.cjs.map +1 -1
- package/dist/cjs/solana/index.d.cts +65 -4
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +311 -99
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/solana/descriptor/idl/streamflow.json +1440 -0
- package/dist/esm/solana/index.d.ts +65 -4
- package/dist/esm/solana/index.js +311 -99
- 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, ApiClient, ApiClientOptions, BatchItem, BatchItemError, BatchItemResult, BatchItemSuccess, CONTRACT_DISCRIMINATOR, CONTRACT_SEED, CREATE_PARAMS_PADDING, Chain, ChangeOracleParams, ClientCreationOptions, Contract, ContractErrorCode, ContractSchema, ContractType, CreateParams, CreateTestOracleParams, DEFAULT_AUTO_CLAIM_FEE_SOL, DEFAULT_CREATION_FEE_SOL, DEFAULT_STREAMFLOW_FEE, DecodedStream, DynamicContractSchema, ESCROW_SEED, FEES_METADATA_SEED, FEE_ORACLE_PUBLIC_KEY, GetContractsOptions, 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, PriceOracleType, REPOPULATED_METADATA_SEED, 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, TabulariumContract, TestOracle, TransactionSchedulingOptions, UpdateTestOracleParams, WITHDRAWOR, WITHDRAWOR_PUBLIC_KEY, WITHDRAW_AVAILABLE_AMOUNT, buildStreamType, calculateTotalAmountToDeposit, calculateUnlockedAmount, cancelStreamInstruction, createClient, createStreamInstruction, createUncheckedStreamInstruction, decodeEndTime, decodeStream, deriveContractPDA, deriveEscrowPDA, deriveRepopulatedMetadataPDA, deriveTestOraclePDA, extractSolanaErrorCode, getMetadataKey, handleContractError, isAligned, isCliffCloseToDepositedAmount, isCreateAlignedStreamData, isDynamicLock, isTokenLock, isVesting, sendAndConfirmStreamRawTransaction, signAllTransactionWithRecipients, timelockIDL, topupStreamInstruction, transferStreamInstruction, transformContract, 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, ApiClient, ApiClientOptions, BatchItem, BatchItemError, BatchItemResult, BatchItemSuccess, CONTRACT_DISCRIMINATOR, CONTRACT_SEED, CREATE_PARAMS_PADDING, Chain, ChangeOracleParams, ClientCreationOptions, Contract, ContractErrorCode, ContractSchema, ContractType, CreateParams, CreateTestOracleParams, DEFAULT_AUTO_CLAIM_FEE_SOL, DEFAULT_CREATION_FEE_SOL, DEFAULT_STREAMFLOW_FEE, DecodedStream, DynamicContractSchema, ESCROW_SEED, FEES_METADATA_SEED, FEE_ORACLE_PUBLIC_KEY, GetContractsOptions, 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, METADATA_SEED, MetadataRecipientHashMap, ORIGINAL_CONTRACT_SENDER_OFFSET, OracleType, OracleTypeName, PARTNERS_SCHEMA, PARTNER_ORACLE_PROGRAM_ID, PARTNER_SCHEMA, PROGRAM_ID, PriceOracleType, REPOPULATED_METADATA_SEED, 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, TabulariumContract, TestOracle, TransactionSchedulingOptions, UpdateTestOracleParams, WITHDRAWOR, WITHDRAWOR_PUBLIC_KEY, WITHDRAW_AVAILABLE_AMOUNT, buildStreamType, calculateTotalAmountToDeposit, calculateUnlockedAmount, cancelStreamInstruction, createClient, createStreamInstruction, createStreamV2Instruction, createUncheckedStreamInstruction, createUncheckedStreamV2Instruction, decodeEndTime, decodeStream, deriveContractPDA, deriveEscrowPDA, deriveRepopulatedMetadataPDA, deriveStreamMetadataPDA, deriveTestOraclePDA, extractSolanaErrorCode, getMetadataKey, handleContractError, isAligned, isCliffCloseToDepositedAmount, isCreateAlignedStreamData, isDynamicLock, isTokenLock, isVesting, sendAndConfirmStreamRawTransaction, signAllTransactionWithRecipients, timelockIDL, topupStreamInstruction, transferStreamInstruction, transformContract, 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';
|
|
@@ -180,12 +180,16 @@ var Contract = class {
|
|
|
180
180
|
this.canTopup = stream.canTopup;
|
|
181
181
|
this.name = stream.name;
|
|
182
182
|
this.withdrawalFrequency = stream.withdrawFrequency.toNumber();
|
|
183
|
+
this.isPda = stream.isPda;
|
|
184
|
+
this.nonce = stream.nonce;
|
|
183
185
|
this.closed = stream.closed;
|
|
184
186
|
this.currentPauseStart = stream.currentPauseStart.toNumber();
|
|
185
187
|
this.pauseCumulative = stream.pauseCumulative;
|
|
186
188
|
this.lastRateChangeTime = stream.lastRateChangeTime.toNumber();
|
|
187
189
|
this.fundsUnlockedAtLastRateChange = stream.fundsUnlockedAtLastRateChange;
|
|
188
190
|
this.oldMetadata = stream.oldMetadata;
|
|
191
|
+
this.payer = stream.payer.toBase58();
|
|
192
|
+
this.bump = stream.bump;
|
|
189
193
|
this.type = buildStreamType(this);
|
|
190
194
|
this.isAligned = false;
|
|
191
195
|
}
|
|
@@ -240,7 +244,7 @@ var STREAM_STRUCT_OFFSETS = {
|
|
|
240
244
|
sender: STREAM_STRUCT_OFFSET_SENDER,
|
|
241
245
|
closed: STREAM_STRUCT_OFFSET_CLOSED
|
|
242
246
|
};
|
|
243
|
-
var CREATE_PARAMS_PADDING =
|
|
247
|
+
var CREATE_PARAMS_PADDING = 121;
|
|
244
248
|
var PROGRAM_ID = {
|
|
245
249
|
[common.ICluster.Devnet]: "HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ",
|
|
246
250
|
[common.ICluster.Mainnet]: "strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m",
|
|
@@ -271,6 +275,7 @@ var TEST_ORACLE_DISCRIMINATOR = [198, 49, 63, 134, 232, 251, 168, 28];
|
|
|
271
275
|
var CONTRACT_SEED = buffer.Buffer.from("contract", "utf-8");
|
|
272
276
|
var ESCROW_SEED = buffer.Buffer.from("strm", "utf-8");
|
|
273
277
|
var TEST_ORACLE_SEED = buffer.Buffer.from("test-oracle", "utf-8");
|
|
278
|
+
var METADATA_SEED = buffer.Buffer.from("strm-met", "utf-8");
|
|
274
279
|
var REPOPULATED_METADATA_SEED = buffer.Buffer.from("strm-rep", "utf-8");
|
|
275
280
|
var STREAMFLOW_TREASURY_PUBLIC_KEY = new web3_js.PublicKey("5SEpbdjFK5FxwTvfsGMXVQTD2v4M2c5tyRTxhdsPkgDw");
|
|
276
281
|
var WITHDRAWOR = "wdrwhnCv4pzW8beKsbPa4S2UDZrXenjg16KJdKSpb5u";
|
|
@@ -374,7 +379,9 @@ var streamLayout = BufferLayout__namespace.struct([
|
|
|
374
379
|
BufferLayout__namespace.blob(4, "ghost"),
|
|
375
380
|
BufferLayout__namespace.u8("pausable"),
|
|
376
381
|
BufferLayout__namespace.u8("can_update_rate"),
|
|
377
|
-
BufferLayout__namespace.blob(4, "
|
|
382
|
+
BufferLayout__namespace.blob(4, "ghost2"),
|
|
383
|
+
BufferLayout__namespace.u8("is_pda"),
|
|
384
|
+
BufferLayout__namespace.u32("nonce"),
|
|
378
385
|
BufferLayout__namespace.seq(BufferLayout__namespace.u8(), CREATE_PARAMS_PADDING, "create_params_padding"),
|
|
379
386
|
BufferLayout__namespace.u8("closed"),
|
|
380
387
|
BufferLayout__namespace.blob(8, "current_pause_start"),
|
|
@@ -385,7 +392,9 @@ var streamLayout = BufferLayout__namespace.struct([
|
|
|
385
392
|
BufferLayout__namespace.u8("creation_fee_claimed"),
|
|
386
393
|
BufferLayout__namespace.u32("auto_claim_fee"),
|
|
387
394
|
BufferLayout__namespace.u8("auto_claim_fee_claimed"),
|
|
388
|
-
BufferLayout__namespace.blob(32, "old_metadata")
|
|
395
|
+
BufferLayout__namespace.blob(32, "old_metadata"),
|
|
396
|
+
BufferLayout__namespace.blob(32, "payer"),
|
|
397
|
+
BufferLayout__namespace.u8("bump")
|
|
389
398
|
]);
|
|
390
399
|
BufferLayout__namespace.struct([
|
|
391
400
|
BufferLayout__namespace.blob(32, "pubkey"),
|
|
@@ -414,6 +423,25 @@ var createStreamLayout = BufferLayout__namespace.struct([
|
|
|
414
423
|
BufferLayout__namespace.u8("_can_update_rate_discriminator"),
|
|
415
424
|
BufferLayout__namespace.u8("can_update_rate")
|
|
416
425
|
]);
|
|
426
|
+
var createStreamV2Layout = BufferLayout__namespace.struct([
|
|
427
|
+
BufferLayout__namespace.blob(8, "start_time"),
|
|
428
|
+
BufferLayout__namespace.blob(8, "net_amount_deposited"),
|
|
429
|
+
BufferLayout__namespace.blob(8, "period"),
|
|
430
|
+
BufferLayout__namespace.blob(8, "amount_per_period"),
|
|
431
|
+
BufferLayout__namespace.blob(8, "cliff"),
|
|
432
|
+
BufferLayout__namespace.blob(8, "cliff_amount"),
|
|
433
|
+
BufferLayout__namespace.u8("cancelable_by_sender"),
|
|
434
|
+
BufferLayout__namespace.u8("cancelable_by_recipient"),
|
|
435
|
+
BufferLayout__namespace.u8("automatic_withdrawal"),
|
|
436
|
+
BufferLayout__namespace.u8("transferable_by_sender"),
|
|
437
|
+
BufferLayout__namespace.u8("transferable_by_recipient"),
|
|
438
|
+
BufferLayout__namespace.u8("can_topup"),
|
|
439
|
+
BufferLayout__namespace.blob(64, "stream_name"),
|
|
440
|
+
BufferLayout__namespace.blob(8, "withdraw_frequency"),
|
|
441
|
+
BufferLayout__namespace.u8("pausable"),
|
|
442
|
+
BufferLayout__namespace.u8("can_update_rate"),
|
|
443
|
+
BufferLayout__namespace.u32("nonce")
|
|
444
|
+
]);
|
|
417
445
|
var createUncheckedStreamLayout = BufferLayout__namespace.struct([
|
|
418
446
|
BufferLayout__namespace.blob(8, "start_time"),
|
|
419
447
|
BufferLayout__namespace.blob(8, "net_amount_deposited"),
|
|
@@ -434,6 +462,27 @@ var createUncheckedStreamLayout = BufferLayout__namespace.struct([
|
|
|
434
462
|
BufferLayout__namespace.u8("pausable"),
|
|
435
463
|
BufferLayout__namespace.u8("can_update_rate")
|
|
436
464
|
]);
|
|
465
|
+
var createUncheckedStreamV2Layout = BufferLayout__namespace.struct([
|
|
466
|
+
BufferLayout__namespace.blob(8, "start_time"),
|
|
467
|
+
BufferLayout__namespace.blob(8, "net_amount_deposited"),
|
|
468
|
+
BufferLayout__namespace.blob(8, "period"),
|
|
469
|
+
BufferLayout__namespace.blob(8, "amount_per_period"),
|
|
470
|
+
BufferLayout__namespace.blob(8, "cliff"),
|
|
471
|
+
BufferLayout__namespace.blob(8, "cliff_amount"),
|
|
472
|
+
BufferLayout__namespace.u8("cancelable_by_sender"),
|
|
473
|
+
BufferLayout__namespace.u8("cancelable_by_recipient"),
|
|
474
|
+
BufferLayout__namespace.u8("automatic_withdrawal"),
|
|
475
|
+
BufferLayout__namespace.u8("transferable_by_sender"),
|
|
476
|
+
BufferLayout__namespace.u8("transferable_by_recipient"),
|
|
477
|
+
BufferLayout__namespace.u8("can_topup"),
|
|
478
|
+
BufferLayout__namespace.blob(64, "stream_name"),
|
|
479
|
+
BufferLayout__namespace.blob(8, "withdraw_frequency"),
|
|
480
|
+
BufferLayout__namespace.blob(32, "recipient"),
|
|
481
|
+
BufferLayout__namespace.blob(32, "partner"),
|
|
482
|
+
BufferLayout__namespace.u8("pausable"),
|
|
483
|
+
BufferLayout__namespace.u8("can_update_rate"),
|
|
484
|
+
BufferLayout__namespace.u32("nonce")
|
|
485
|
+
]);
|
|
437
486
|
var withdrawStreamLayout = BufferLayout__namespace.struct([
|
|
438
487
|
BufferLayout__namespace.blob(8, "amount")
|
|
439
488
|
]);
|
|
@@ -551,12 +600,16 @@ var decodeStream = (buf) => {
|
|
|
551
600
|
canTopup: Boolean(raw.can_topup),
|
|
552
601
|
name: decoder.decode(raw.stream_name),
|
|
553
602
|
withdrawFrequency: new BN3__default.default(raw.withdraw_frequency, LE),
|
|
603
|
+
isPda: Boolean(raw.is_pda),
|
|
604
|
+
nonce: raw.nonce,
|
|
554
605
|
closed: Boolean(raw.closed),
|
|
555
606
|
currentPauseStart: new BN3__default.default(raw.current_pause_start, LE),
|
|
556
607
|
pauseCumulative: new BN3__default.default(raw.pause_cumulative, LE),
|
|
557
608
|
lastRateChangeTime: new BN3__default.default(raw.last_rate_change_time, LE),
|
|
558
609
|
fundsUnlockedAtLastRateChange: new BN3__default.default(raw.funds_unlocked_at_last_rate_change, LE),
|
|
559
|
-
oldMetadata: new web3_js.PublicKey(raw.old_metadata)
|
|
610
|
+
oldMetadata: new web3_js.PublicKey(raw.old_metadata),
|
|
611
|
+
payer: new web3_js.PublicKey(raw.payer),
|
|
612
|
+
bump: raw.bump
|
|
560
613
|
};
|
|
561
614
|
};
|
|
562
615
|
async function signAllTransactionWithRecipients(sender, items) {
|
|
@@ -747,6 +800,133 @@ var createUncheckedStreamInstruction = async (data, programId, accounts) => {
|
|
|
747
800
|
data: bufferData
|
|
748
801
|
});
|
|
749
802
|
};
|
|
803
|
+
var createStreamV2Instruction = async (data, programId, accounts) => {
|
|
804
|
+
const keys = [
|
|
805
|
+
{ pubkey: accounts.sender, isSigner: true, isWritable: true },
|
|
806
|
+
{ pubkey: accounts.senderTokens, isSigner: false, isWritable: true },
|
|
807
|
+
{ pubkey: accounts.recipient, isSigner: false, isWritable: true },
|
|
808
|
+
{ pubkey: accounts.metadata, isSigner: false, isWritable: true },
|
|
809
|
+
{ pubkey: accounts.escrowTokens, isSigner: false, isWritable: true },
|
|
810
|
+
{ pubkey: accounts.recipientTokens, isSigner: false, isWritable: true },
|
|
811
|
+
{
|
|
812
|
+
pubkey: accounts.streamflowTreasury,
|
|
813
|
+
isSigner: false,
|
|
814
|
+
isWritable: true
|
|
815
|
+
},
|
|
816
|
+
{
|
|
817
|
+
pubkey: accounts.streamflowTreasuryTokens,
|
|
818
|
+
isSigner: false,
|
|
819
|
+
isWritable: true
|
|
820
|
+
},
|
|
821
|
+
{ pubkey: accounts.withdrawor, isSigner: false, isWritable: true },
|
|
822
|
+
{ pubkey: accounts.partner, isSigner: false, isWritable: true },
|
|
823
|
+
{ pubkey: accounts.partnerTokens, isSigner: false, isWritable: true },
|
|
824
|
+
{ pubkey: accounts.mint, isSigner: false, isWritable: false },
|
|
825
|
+
{ pubkey: accounts.feeOracle, isSigner: false, isWritable: false },
|
|
826
|
+
{ pubkey: accounts.rent, isSigner: false, isWritable: false },
|
|
827
|
+
{ pubkey: accounts.timelockProgram, isSigner: false, isWritable: false },
|
|
828
|
+
{ pubkey: accounts.tokenProgram, isSigner: false, isWritable: false },
|
|
829
|
+
{
|
|
830
|
+
pubkey: accounts.associatedTokenProgram,
|
|
831
|
+
isSigner: false,
|
|
832
|
+
isWritable: false
|
|
833
|
+
},
|
|
834
|
+
{ pubkey: accounts.systemProgram, isSigner: false, isWritable: false }
|
|
835
|
+
];
|
|
836
|
+
let bufferData = buffer.Buffer.alloc(createStreamV2Layout.span);
|
|
837
|
+
const encodedUIntArray = new TextEncoder().encode(data.name);
|
|
838
|
+
const streamNameBuffer = buffer.Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
|
|
839
|
+
const nonceBuffer = buffer.Buffer.alloc(4);
|
|
840
|
+
nonceBuffer.writeUInt32LE(data.nonce);
|
|
841
|
+
const decodedData = {
|
|
842
|
+
start_time: data.start.toArrayLike(buffer.Buffer, "le", 8),
|
|
843
|
+
net_amount_deposited: data.depositedAmount.toArrayLike(buffer.Buffer, "le", 8),
|
|
844
|
+
period: data.period.toArrayLike(buffer.Buffer, "le", 8),
|
|
845
|
+
amount_per_period: data.amountPerPeriod.toArrayLike(buffer.Buffer, "le", 8),
|
|
846
|
+
cliff: data.cliff.toArrayLike(buffer.Buffer, "le", 8),
|
|
847
|
+
cliff_amount: data.cliffAmount.toArrayLike(buffer.Buffer, "le", 8),
|
|
848
|
+
cancelable_by_sender: Number(data.cancelableBySender),
|
|
849
|
+
cancelable_by_recipient: Number(data.cancelableByRecipient),
|
|
850
|
+
automatic_withdrawal: Number(data.automaticWithdrawal),
|
|
851
|
+
transferable_by_sender: Number(data.transferableBySender),
|
|
852
|
+
transferable_by_recipient: Number(data.transferableByRecipient),
|
|
853
|
+
can_topup: Number(data.canTopup),
|
|
854
|
+
stream_name: streamNameBuffer,
|
|
855
|
+
withdraw_frequency: data.withdrawFrequency.toArrayLike(buffer.Buffer, "le", 8),
|
|
856
|
+
pausable: Number(data.canPause),
|
|
857
|
+
can_update_rate: Number(data.canUpdateRate),
|
|
858
|
+
nonce: nonceBuffer
|
|
859
|
+
};
|
|
860
|
+
const encodeLength = createStreamV2Layout.encode(decodedData, bufferData);
|
|
861
|
+
bufferData = bufferData.slice(0, encodeLength);
|
|
862
|
+
bufferData = buffer.Buffer.concat([
|
|
863
|
+
buffer.Buffer.from(await sha256.digest("global:create_v2")).slice(0, 8),
|
|
864
|
+
bufferData,
|
|
865
|
+
buffer.Buffer.alloc(10)
|
|
866
|
+
]);
|
|
867
|
+
return new web3_js.TransactionInstruction({
|
|
868
|
+
keys,
|
|
869
|
+
programId,
|
|
870
|
+
data: bufferData
|
|
871
|
+
});
|
|
872
|
+
};
|
|
873
|
+
var createUncheckedStreamV2Instruction = async (data, programId, accounts) => {
|
|
874
|
+
const keys = [
|
|
875
|
+
{ pubkey: accounts.sender, isSigner: true, isWritable: true },
|
|
876
|
+
{ pubkey: accounts.senderTokens, isSigner: false, isWritable: true },
|
|
877
|
+
{ pubkey: accounts.metadata, isSigner: false, isWritable: true },
|
|
878
|
+
{ pubkey: accounts.escrowTokens, isSigner: false, isWritable: true },
|
|
879
|
+
{ pubkey: accounts.withdrawor, isSigner: false, isWritable: true },
|
|
880
|
+
{ pubkey: accounts.mint, isSigner: false, isWritable: false },
|
|
881
|
+
{ pubkey: accounts.feeOracle, isSigner: false, isWritable: false },
|
|
882
|
+
{ pubkey: accounts.rent, isSigner: false, isWritable: false },
|
|
883
|
+
{ pubkey: accounts.timelockProgram, isSigner: false, isWritable: false },
|
|
884
|
+
{ pubkey: accounts.tokenProgram, isSigner: false, isWritable: false },
|
|
885
|
+
{ pubkey: accounts.systemProgram, isSigner: false, isWritable: false }
|
|
886
|
+
];
|
|
887
|
+
if (accounts.payer) {
|
|
888
|
+
keys.unshift({
|
|
889
|
+
pubkey: accounts.payer,
|
|
890
|
+
isSigner: true,
|
|
891
|
+
isWritable: true
|
|
892
|
+
});
|
|
893
|
+
}
|
|
894
|
+
let bufferData = buffer.Buffer.alloc(createUncheckedStreamV2Layout.span);
|
|
895
|
+
const encodedUIntArray = new TextEncoder().encode(data.name);
|
|
896
|
+
const streamNameBuffer = buffer.Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
|
|
897
|
+
const nonceBuffer = buffer.Buffer.alloc(4);
|
|
898
|
+
nonceBuffer.writeUInt32LE(data.nonce);
|
|
899
|
+
const decodedData = {
|
|
900
|
+
start_time: data.start.toArrayLike(buffer.Buffer, "le", 8),
|
|
901
|
+
net_amount_deposited: data.depositedAmount.toArrayLike(buffer.Buffer, "le", 8),
|
|
902
|
+
period: data.period.toArrayLike(buffer.Buffer, "le", 8),
|
|
903
|
+
amount_per_period: data.amountPerPeriod.toArrayLike(buffer.Buffer, "le", 8),
|
|
904
|
+
cliff: data.cliff.toArrayLike(buffer.Buffer, "le", 8),
|
|
905
|
+
cliff_amount: data.cliffAmount.toArrayLike(buffer.Buffer, "le", 8),
|
|
906
|
+
cancelable_by_sender: Number(data.cancelableBySender),
|
|
907
|
+
cancelable_by_recipient: Number(data.cancelableByRecipient),
|
|
908
|
+
automatic_withdrawal: Number(data.automaticWithdrawal),
|
|
909
|
+
transferable_by_sender: Number(data.transferableBySender),
|
|
910
|
+
transferable_by_recipient: Number(data.transferableByRecipient),
|
|
911
|
+
can_topup: Number(data.canTopup),
|
|
912
|
+
stream_name: streamNameBuffer,
|
|
913
|
+
withdraw_frequency: data.withdrawFrequency.toArrayLike(buffer.Buffer, "le", 8),
|
|
914
|
+
recipient: data.recipient.toBuffer(),
|
|
915
|
+
partner: data.partner.toBuffer(),
|
|
916
|
+
pausable: Number(data.canPause),
|
|
917
|
+
can_update_rate: Number(data.canUpdateRate),
|
|
918
|
+
nonce: nonceBuffer
|
|
919
|
+
};
|
|
920
|
+
const encodeLength = createUncheckedStreamV2Layout.encode(decodedData, bufferData);
|
|
921
|
+
bufferData = bufferData.slice(0, encodeLength);
|
|
922
|
+
const digest = accounts.payer ? await sha256.digest("global:create_unchecked_with_payer_v2") : await sha256.digest("global:create_unchecked_v2");
|
|
923
|
+
bufferData = buffer.Buffer.concat([buffer.Buffer.from(digest).slice(0, 8), bufferData, buffer.Buffer.alloc(10)]);
|
|
924
|
+
return new web3_js.TransactionInstruction({
|
|
925
|
+
keys,
|
|
926
|
+
programId,
|
|
927
|
+
data: bufferData
|
|
928
|
+
});
|
|
929
|
+
};
|
|
750
930
|
var withdrawStreamInstruction = async (amount, programId, {
|
|
751
931
|
authority,
|
|
752
932
|
recipient,
|
|
@@ -2539,6 +2719,12 @@ var deriveEscrowPDA = (programId, streamMetadata) => {
|
|
|
2539
2719
|
var deriveTestOraclePDA = (programId, mint, creator) => {
|
|
2540
2720
|
return web3_js.PublicKey.findProgramAddressSync([TEST_ORACLE_SEED, mint.toBuffer(), creator.toBuffer()], programId)[0];
|
|
2541
2721
|
};
|
|
2722
|
+
var deriveStreamMetadataPDA = (programId, mint, sender, nonce) => {
|
|
2723
|
+
return web3_js.PublicKey.findProgramAddressSync(
|
|
2724
|
+
[METADATA_SEED, mint.toBuffer(), sender.toBuffer(), new BN3__default.default(nonce).toArrayLike(buffer.Buffer, "le", 4)],
|
|
2725
|
+
programId
|
|
2726
|
+
)[0];
|
|
2727
|
+
};
|
|
2542
2728
|
var deriveRepopulatedMetadataPDA = (programId, streamMetadata) => {
|
|
2543
2729
|
return web3_js.PublicKey.findProgramAddressSync([REPOPULATED_METADATA_SEED, streamMetadata.toBuffer()], programId)[0];
|
|
2544
2730
|
};
|
|
@@ -2597,6 +2783,7 @@ async function toDecodedStream(schema) {
|
|
|
2597
2783
|
const sender = common.pk(schema.sender);
|
|
2598
2784
|
const recipient = common.pk(schema.recipient);
|
|
2599
2785
|
const partner = schema.partner ? common.pk(schema.partner) : sender;
|
|
2786
|
+
const payer = schema.payer ? common.pk(schema.payer) : web3_js.PublicKey.default;
|
|
2600
2787
|
const [senderTokens, recipientTokens, partnerTokens, streamflowTreasuryTokens] = await Promise.all([
|
|
2601
2788
|
common.ata(mint, sender),
|
|
2602
2789
|
common.ata(mint, recipient),
|
|
@@ -2641,12 +2828,16 @@ async function toDecodedStream(schema) {
|
|
|
2641
2828
|
canTopup: schema.canTopup,
|
|
2642
2829
|
name: schema.name,
|
|
2643
2830
|
withdrawFrequency: toBN(schema.autoClaimPeriod),
|
|
2831
|
+
isPda: schema.isPda,
|
|
2832
|
+
nonce: schema.nonce ? schema.nonce : 0,
|
|
2644
2833
|
closed: schema.isClosed,
|
|
2645
2834
|
currentPauseStart: toBN(0),
|
|
2646
2835
|
pauseCumulative: toBN(schema.pauseCumulative),
|
|
2647
2836
|
lastRateChangeTime: toBN(isoToUnix(schema.lastRateUpdateDt)),
|
|
2648
2837
|
fundsUnlockedAtLastRateChange: toBN(schema.amountUnlockedAtLastRateUpdate),
|
|
2649
|
-
oldMetadata: web3_js.PublicKey.default
|
|
2838
|
+
oldMetadata: web3_js.PublicKey.default,
|
|
2839
|
+
payer,
|
|
2840
|
+
bump: schema.bump ? schema.bump : 0
|
|
2650
2841
|
};
|
|
2651
2842
|
}
|
|
2652
2843
|
function toPrecisionBN(value, precision = ALIGNED_PRECISION_FACTOR_POW2) {
|
|
@@ -2974,7 +3165,8 @@ var SolanaStreamClient = class {
|
|
|
2974
3165
|
automaticWithdrawal = false,
|
|
2975
3166
|
withdrawalFrequency = 0,
|
|
2976
3167
|
partner,
|
|
2977
|
-
tokenProgramId: streamTokenProgramId
|
|
3168
|
+
tokenProgramId: streamTokenProgramId,
|
|
3169
|
+
nonce
|
|
2978
3170
|
}, { sender, metadataPubKeys, isNative = false, computePrice, computeLimit }) {
|
|
2979
3171
|
common.assertHasPublicKey(sender, "Sender's PublicKey is not available, check passed wallet adapter!");
|
|
2980
3172
|
const ixs = common.prepareBaseInstructions(this.connection, {
|
|
@@ -2983,7 +3175,13 @@ var SolanaStreamClient = class {
|
|
|
2983
3175
|
});
|
|
2984
3176
|
const mintPublicKey = isNative ? splToken.NATIVE_MINT : new web3_js.PublicKey(mint);
|
|
2985
3177
|
const recipientPublicKey = new web3_js.PublicKey(recipient);
|
|
2986
|
-
|
|
3178
|
+
let metadata;
|
|
3179
|
+
let metadataPubKey;
|
|
3180
|
+
if (nonce != null) {
|
|
3181
|
+
metadataPubKey = deriveStreamMetadataPDA(this.programId, mintPublicKey, sender.publicKey, nonce);
|
|
3182
|
+
} else {
|
|
3183
|
+
({ metadata, metadataPubKey } = this.getOrCreateStreamMetadata(metadataPubKeys));
|
|
3184
|
+
}
|
|
2987
3185
|
const [escrowTokens] = web3_js.PublicKey.findProgramAddressSync(
|
|
2988
3186
|
[buffer.Buffer.from("strm"), metadataPubKey.toBuffer()],
|
|
2989
3187
|
this.programId
|
|
@@ -2997,49 +3195,49 @@ var SolanaStreamClient = class {
|
|
|
2997
3195
|
const streamflowTreasuryTokens = await common.ata(mintPublicKey, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
|
|
2998
3196
|
const partnerPublicKey = partner ? new web3_js.PublicKey(partner) : sender.publicKey;
|
|
2999
3197
|
const partnerTokens = await common.ata(mintPublicKey, partnerPublicKey, tokenProgramId);
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
)
|
|
3042
|
-
|
|
3198
|
+
const accounts = {
|
|
3199
|
+
sender: sender.publicKey,
|
|
3200
|
+
senderTokens,
|
|
3201
|
+
recipient: new web3_js.PublicKey(recipient),
|
|
3202
|
+
metadata: metadataPubKey,
|
|
3203
|
+
escrowTokens,
|
|
3204
|
+
recipientTokens,
|
|
3205
|
+
streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
|
|
3206
|
+
streamflowTreasuryTokens,
|
|
3207
|
+
partner: partnerPublicKey,
|
|
3208
|
+
partnerTokens,
|
|
3209
|
+
mint: new web3_js.PublicKey(mint),
|
|
3210
|
+
feeOracle: this.feeOraclePublicKey,
|
|
3211
|
+
rent: web3_js.SYSVAR_RENT_PUBKEY,
|
|
3212
|
+
timelockProgram: this.programId,
|
|
3213
|
+
tokenProgram: tokenProgramId,
|
|
3214
|
+
associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
3215
|
+
withdrawor: WITHDRAWOR_PUBLIC_KEY,
|
|
3216
|
+
systemProgram: web3_js.SystemProgram.programId
|
|
3217
|
+
};
|
|
3218
|
+
const baseData = {
|
|
3219
|
+
start: new BN3__default.default(start),
|
|
3220
|
+
depositedAmount,
|
|
3221
|
+
period: new BN3__default.default(period),
|
|
3222
|
+
amountPerPeriod,
|
|
3223
|
+
cliff: new BN3__default.default(cliff),
|
|
3224
|
+
cliffAmount: new BN3__default.default(cliffAmount),
|
|
3225
|
+
cancelableBySender,
|
|
3226
|
+
cancelableByRecipient,
|
|
3227
|
+
automaticWithdrawal,
|
|
3228
|
+
transferableBySender,
|
|
3229
|
+
transferableByRecipient,
|
|
3230
|
+
canTopup,
|
|
3231
|
+
canUpdateRate: !!canUpdateRate,
|
|
3232
|
+
canPause: !!canPause,
|
|
3233
|
+
name,
|
|
3234
|
+
withdrawFrequency: new BN3__default.default(automaticWithdrawal ? withdrawalFrequency : period)
|
|
3235
|
+
};
|
|
3236
|
+
if (nonce != null) {
|
|
3237
|
+
ixs.push(await createStreamV2Instruction({ ...baseData, nonce }, this.programId, accounts));
|
|
3238
|
+
} else {
|
|
3239
|
+
ixs.push(await createStreamInstruction(baseData, this.programId, accounts));
|
|
3240
|
+
}
|
|
3043
3241
|
return { ixs, metadata, metadataPubKey };
|
|
3044
3242
|
}
|
|
3045
3243
|
/**
|
|
@@ -3099,20 +3297,19 @@ var SolanaStreamClient = class {
|
|
|
3099
3297
|
transferableByRecipient,
|
|
3100
3298
|
automaticWithdrawal = false,
|
|
3101
3299
|
withdrawalFrequency = 0,
|
|
3102
|
-
partner
|
|
3300
|
+
partner,
|
|
3301
|
+
nonce
|
|
3103
3302
|
}, { sender, metadataPubKeys, isNative = false, computePrice, computeLimit }) {
|
|
3104
3303
|
common.assertHasPublicKey(sender, "Sender's PublicKey is not available, check passed wallet adapter!");
|
|
3105
3304
|
const mintPublicKey = new web3_js.PublicKey(mint);
|
|
3106
3305
|
const recipientPublicKey = new web3_js.PublicKey(recipient);
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
newAccountPubkey: metadataPubKey
|
|
3115
|
-
});
|
|
3306
|
+
let metadata;
|
|
3307
|
+
let metadataPubKey;
|
|
3308
|
+
if (nonce != null) {
|
|
3309
|
+
metadataPubKey = deriveStreamMetadataPDA(this.programId, mintPublicKey, sender.publicKey, nonce);
|
|
3310
|
+
} else {
|
|
3311
|
+
({ metadata, metadataPubKey } = this.getOrCreateStreamMetadata(metadataPubKeys));
|
|
3312
|
+
}
|
|
3116
3313
|
const [escrowTokens] = web3_js.PublicKey.findProgramAddressSync(
|
|
3117
3314
|
[buffer.Buffer.from("strm"), metadataPubKey.toBuffer()],
|
|
3118
3315
|
this.programId
|
|
@@ -3129,43 +3326,58 @@ var SolanaStreamClient = class {
|
|
|
3129
3326
|
const totalAmount = calculateTotalAmountToDeposit(depositedAmount, totalFee);
|
|
3130
3327
|
ixs.push(...await common.prepareWrappedAccount(this.connection, sender.publicKey, totalAmount));
|
|
3131
3328
|
}
|
|
3132
|
-
const
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3329
|
+
const accounts = {
|
|
3330
|
+
sender: sender.publicKey,
|
|
3331
|
+
senderTokens,
|
|
3332
|
+
metadata: metadataPubKey,
|
|
3333
|
+
escrowTokens,
|
|
3334
|
+
mint: new web3_js.PublicKey(mint),
|
|
3335
|
+
feeOracle: this.feeOraclePublicKey,
|
|
3336
|
+
rent: web3_js.SYSVAR_RENT_PUBKEY,
|
|
3337
|
+
timelockProgram: this.programId,
|
|
3338
|
+
tokenProgram: tokenProgramId,
|
|
3339
|
+
withdrawor: WITHDRAWOR_PUBLIC_KEY,
|
|
3340
|
+
systemProgram: web3_js.SystemProgram.programId
|
|
3341
|
+
};
|
|
3342
|
+
const baseData = {
|
|
3343
|
+
start: new BN3__default.default(start),
|
|
3344
|
+
depositedAmount,
|
|
3345
|
+
period: new BN3__default.default(period),
|
|
3346
|
+
amountPerPeriod,
|
|
3347
|
+
cliff: new BN3__default.default(cliff),
|
|
3348
|
+
cliffAmount: new BN3__default.default(cliffAmount),
|
|
3349
|
+
cancelableBySender,
|
|
3350
|
+
cancelableByRecipient,
|
|
3351
|
+
automaticWithdrawal,
|
|
3352
|
+
transferableBySender,
|
|
3353
|
+
transferableByRecipient,
|
|
3354
|
+
canTopup,
|
|
3355
|
+
canUpdateRate: !!canUpdateRate,
|
|
3356
|
+
canPause: !!canPause,
|
|
3357
|
+
name,
|
|
3358
|
+
withdrawFrequency: new BN3__default.default(automaticWithdrawal ? withdrawalFrequency : period),
|
|
3359
|
+
recipient: recipientPublicKey,
|
|
3360
|
+
partner: partnerPublicKey
|
|
3361
|
+
};
|
|
3362
|
+
if (nonce != null) {
|
|
3363
|
+
const createInstruction = await createUncheckedStreamV2Instruction(
|
|
3364
|
+
{ ...baseData, nonce },
|
|
3365
|
+
this.programId,
|
|
3366
|
+
accounts
|
|
3367
|
+
);
|
|
3368
|
+
ixs.push(createInstruction);
|
|
3369
|
+
} else {
|
|
3370
|
+
const rentToExempt = await this.connection.getMinimumBalanceForRentExemption(METADATA_ACC_SIZE);
|
|
3371
|
+
const createMetadataInstruction = web3_js.SystemProgram.createAccount({
|
|
3372
|
+
programId: this.programId,
|
|
3373
|
+
space: METADATA_ACC_SIZE,
|
|
3374
|
+
lamports: rentToExempt,
|
|
3375
|
+
fromPubkey: sender.publicKey,
|
|
3376
|
+
newAccountPubkey: metadataPubKey
|
|
3377
|
+
});
|
|
3378
|
+
const createInstruction = await createUncheckedStreamInstruction(baseData, this.programId, accounts);
|
|
3379
|
+
ixs.push(createMetadataInstruction, createInstruction);
|
|
3380
|
+
}
|
|
3169
3381
|
return { ixs, metadata, metadataPubKey };
|
|
3170
3382
|
}
|
|
3171
3383
|
/**
|
|
@@ -4604,6 +4816,7 @@ exports.ESCROW_SEED = ESCROW_SEED;
|
|
|
4604
4816
|
exports.FEES_METADATA_SEED = FEES_METADATA_SEED;
|
|
4605
4817
|
exports.FEE_ORACLE_PUBLIC_KEY = FEE_ORACLE_PUBLIC_KEY;
|
|
4606
4818
|
exports.MAX_SAFE_UNIX_TIME_VALUE = MAX_SAFE_UNIX_TIME_VALUE2;
|
|
4819
|
+
exports.METADATA_SEED = METADATA_SEED;
|
|
4607
4820
|
exports.ORIGINAL_CONTRACT_SENDER_OFFSET = ORIGINAL_CONTRACT_SENDER_OFFSET;
|
|
4608
4821
|
exports.PARTNERS_SCHEMA = PARTNERS_SCHEMA;
|
|
4609
4822
|
exports.PARTNER_ORACLE_PROGRAM_ID = PARTNER_ORACLE_PROGRAM_ID;
|
|
@@ -4634,12 +4847,15 @@ exports.calculateUnlockedAmount = calculateUnlockedAmount;
|
|
|
4634
4847
|
exports.cancelStreamInstruction = cancelStreamInstruction;
|
|
4635
4848
|
exports.createClient = createClient;
|
|
4636
4849
|
exports.createStreamInstruction = createStreamInstruction;
|
|
4850
|
+
exports.createStreamV2Instruction = createStreamV2Instruction;
|
|
4637
4851
|
exports.createUncheckedStreamInstruction = createUncheckedStreamInstruction;
|
|
4852
|
+
exports.createUncheckedStreamV2Instruction = createUncheckedStreamV2Instruction;
|
|
4638
4853
|
exports.decodeEndTime = decodeEndTime;
|
|
4639
4854
|
exports.decodeStream = decodeStream;
|
|
4640
4855
|
exports.deriveContractPDA = deriveContractPDA;
|
|
4641
4856
|
exports.deriveEscrowPDA = deriveEscrowPDA;
|
|
4642
4857
|
exports.deriveRepopulatedMetadataPDA = deriveRepopulatedMetadataPDA;
|
|
4858
|
+
exports.deriveStreamMetadataPDA = deriveStreamMetadataPDA;
|
|
4643
4859
|
exports.deriveTestOraclePDA = deriveTestOraclePDA;
|
|
4644
4860
|
exports.extractSolanaErrorCode = extractSolanaErrorCode;
|
|
4645
4861
|
exports.getMetadataKey = getMetadataKey;
|