@streamflow/stream 10.0.0-alpha.p313.e531e2c → 10.0.0-alpha.p313.fe2295d
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 +148 -3
- package/dist/cjs/index.cjs +129 -66
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +1 -1
- package/dist/cjs/solana/index.cjs +129 -66
- package/dist/cjs/solana/index.cjs.map +1 -1
- package/dist/cjs/solana/index.d.cts +61 -21
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +127 -66
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/solana/index.d.ts +61 -21
- package/dist/esm/solana/index.js +127 -66
- 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_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_PUBLIC_KEY, WITHDRAW_AVAILABLE_AMOUNT, buildStreamType, calculateTotalAmountToDeposit, calculateUnlockedAmount, cancelStreamInstruction, createStreamInstruction, createUncheckedStreamInstruction, decodeEndTime, decodeStream, deriveContractPDA, deriveEscrowPDA, deriveTestOraclePDA, extractSolanaErrorCode, handleContractError, isAligned, isCliffCloseToDepositedAmount, isCreateAlignedStreamData, isDynamicLock,
|
|
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';
|
|
2
2
|
export { ContractError, ICluster, getBN, getNumberFromBN } from '@streamflow/common';
|
|
3
3
|
import 'p-queue';
|
|
4
4
|
import '@solana/web3.js';
|
|
@@ -59,14 +59,11 @@ var calculateUnlockedAmount = ({
|
|
|
59
59
|
var isCliffCloseToDepositedAmount = (streamData) => {
|
|
60
60
|
return streamData.cliffAmount.gte(streamData.depositedAmount.sub(new BN3__default.default(1)));
|
|
61
61
|
};
|
|
62
|
-
var isPayment = (streamData) => {
|
|
63
|
-
return streamData.canTopup;
|
|
64
|
-
};
|
|
65
62
|
var isVesting = (streamData) => {
|
|
66
|
-
return !
|
|
63
|
+
return !isCliffCloseToDepositedAmount(streamData) && !isDynamicLock(streamData.minPrice, streamData.maxPrice, streamData.minPercentage, streamData.maxPercentage);
|
|
67
64
|
};
|
|
68
65
|
var isAligned = (stream) => {
|
|
69
|
-
return
|
|
66
|
+
return stream.isAligned;
|
|
70
67
|
};
|
|
71
68
|
var isCreateAlignedStreamData = (obj) => {
|
|
72
69
|
return "minPrice" in obj && "maxPrice" in obj && "minPercentage" in obj && "maxPercentage" in obj;
|
|
@@ -78,13 +75,10 @@ var isTokenLock = (streamData) => {
|
|
|
78
75
|
return !streamData.canTopup && !streamData.automaticWithdrawal && !streamData.cancelableBySender && !streamData.cancelableByRecipient && !streamData.transferableBySender && (isCliffCloseToDepositedAmount(streamData) || isDynamicLock(streamData.minPrice, streamData.maxPrice, streamData.minPercentage, streamData.maxPercentage));
|
|
79
76
|
};
|
|
80
77
|
var buildStreamType = (streamData) => {
|
|
81
|
-
if (isVesting(streamData)) {
|
|
82
|
-
return "vesting" /* Vesting */;
|
|
83
|
-
}
|
|
84
78
|
if (isTokenLock(streamData)) {
|
|
85
79
|
return "lock" /* Lock */;
|
|
86
80
|
}
|
|
87
|
-
return "
|
|
81
|
+
return "vesting" /* Vesting */;
|
|
88
82
|
};
|
|
89
83
|
var decodeEndTime = (endTime) => {
|
|
90
84
|
if (endTime.gt(new BN3__default.default(MAX_SAFE_UNIX_TIME_VALUE))) {
|
|
@@ -101,7 +95,6 @@ var StreamDirection = /* @__PURE__ */ ((StreamDirection2) => {
|
|
|
101
95
|
})(StreamDirection || {});
|
|
102
96
|
var StreamType = /* @__PURE__ */ ((StreamType2) => {
|
|
103
97
|
StreamType2["All"] = "all";
|
|
104
|
-
StreamType2["Payment"] = "payment";
|
|
105
98
|
StreamType2["Vesting"] = "vesting";
|
|
106
99
|
StreamType2["Lock"] = "lock";
|
|
107
100
|
return StreamType2;
|
|
@@ -258,25 +251,40 @@ var ALIGNED_UNLOCKS_PROGRAM_ID = {
|
|
|
258
251
|
[common.ICluster.Testnet]: "aSTRM2NKoKxNnkmLWk9sz3k74gKBk9t7bpPrTGxMszH",
|
|
259
252
|
[common.ICluster.Local]: "aSTRM2NKoKxNnkmLWk9sz3k74gKBk9t7bpPrTGxMszH"
|
|
260
253
|
};
|
|
254
|
+
var PARTNER_ORACLE_PROGRAM_ID = {
|
|
255
|
+
[common.ICluster.Devnet]: "pardoTarcc6HKsPcbXkVycxsJsoN9QEzrdHgVdHAGY3",
|
|
256
|
+
[common.ICluster.Mainnet]: "pardpVtPjC8nLj1Dwncew62mUzfChdCX1EaoZe8oCAa",
|
|
257
|
+
[common.ICluster.Testnet]: "pardoTarcc6HKsPcbXkVycxsJsoN9QEzrdHgVdHAGY3",
|
|
258
|
+
[common.ICluster.Local]: "pardoTarcc6HKsPcbXkVycxsJsoN9QEzrdHgVdHAGY3"
|
|
259
|
+
};
|
|
260
|
+
var FEE_ORACLE_PUBLIC_KEY = {
|
|
261
|
+
[common.ICluster.Devnet]: "Aa2JJfFzUN3V54DXUHRBJowFw416xfZHpPk9DaNy3iYs",
|
|
262
|
+
[common.ICluster.Mainnet]: "B743wFVk2pCYhV91cn287e1xY7f1vt4gdY48hhNiuQmT",
|
|
263
|
+
[common.ICluster.Testnet]: "Aa2JJfFzUN3V54DXUHRBJowFw416xfZHpPk9DaNy3iYs",
|
|
264
|
+
[common.ICluster.Local]: "Aa2JJfFzUN3V54DXUHRBJowFw416xfZHpPk9DaNy3iYs"
|
|
265
|
+
};
|
|
261
266
|
var ALIGNED_COMPUTE_LIMIT = 3e5;
|
|
262
267
|
var CONTRACT_DISCRIMINATOR = [172, 138, 115, 242, 121, 67, 183, 26];
|
|
263
268
|
var TEST_ORACLE_DISCRIMINATOR = [198, 49, 63, 134, 232, 251, 168, 28];
|
|
264
269
|
var CONTRACT_SEED = buffer.Buffer.from("contract", "utf-8");
|
|
265
270
|
var ESCROW_SEED = buffer.Buffer.from("strm", "utf-8");
|
|
266
271
|
var TEST_ORACLE_SEED = buffer.Buffer.from("test-oracle", "utf-8");
|
|
267
|
-
var PARTNER_ORACLE_PROGRAM_ID = "pardpVtPjC8nLj1Dwncew62mUzfChdCX1EaoZe8oCAa";
|
|
268
272
|
var STREAMFLOW_TREASURY_PUBLIC_KEY = new web3_js.PublicKey("5SEpbdjFK5FxwTvfsGMXVQTD2v4M2c5tyRTxhdsPkgDw");
|
|
269
|
-
var
|
|
270
|
-
var
|
|
273
|
+
var WITHDRAWOR = "wdrwhnCv4pzW8beKsbPa4S2UDZrXenjg16KJdKSpb5u";
|
|
274
|
+
var WITHDRAWOR_PUBLIC_KEY = new web3_js.PublicKey(WITHDRAWOR);
|
|
271
275
|
var AIRDROP_TEST_TOKEN = "Gssm3vfi8s65R31SBdmQRq6cKeYojGgup7whkw4VCiQj";
|
|
272
276
|
var FEES_METADATA_SEED = buffer.Buffer.from("strm_fees");
|
|
273
|
-
var
|
|
277
|
+
var DEFAULT_CREATION_FEE_SOL = 9e7;
|
|
278
|
+
var DEFAULT_AUTO_CLAIM_FEE_SOL = 19e7;
|
|
279
|
+
var DEFAULT_STREAMFLOW_FEE = 0.19;
|
|
274
280
|
var AIRDROP_AMOUNT = 1;
|
|
275
281
|
var PARTNER_SCHEMA = {
|
|
276
282
|
struct: {
|
|
277
283
|
pubkey: { array: { type: "u8", len: 32 } },
|
|
278
|
-
|
|
279
|
-
|
|
284
|
+
creation_fee: "u32",
|
|
285
|
+
auto_claim_fee: "u32",
|
|
286
|
+
token_fee_percent: "f32",
|
|
287
|
+
buffer: { array: { type: "u8", len: 16 } }
|
|
280
288
|
}
|
|
281
289
|
};
|
|
282
290
|
var PARTNERS_SCHEMA = { array: { type: PARTNER_SCHEMA } };
|
|
@@ -2529,6 +2537,8 @@ var SolanaStreamClient = class {
|
|
|
2529
2537
|
this.commitment = commitment;
|
|
2530
2538
|
this.connection = new web3_js.Connection(optionsOrClusterUrl, this.commitment);
|
|
2531
2539
|
this.programId = programId !== "" ? new web3_js.PublicKey(programId) : new web3_js.PublicKey(PROGRAM_ID[cluster]);
|
|
2540
|
+
this.partnerOracleProgramId = new web3_js.PublicKey(PARTNER_ORACLE_PROGRAM_ID[cluster]);
|
|
2541
|
+
this.feeOraclePublicKey = new web3_js.PublicKey(FEE_ORACLE_PUBLIC_KEY[cluster]);
|
|
2532
2542
|
this.schedulingParams = {
|
|
2533
2543
|
sendThrottler: sendThrottler ?? common.buildSendThrottler(sendRate)
|
|
2534
2544
|
};
|
|
@@ -2543,6 +2553,8 @@ var SolanaStreamClient = class {
|
|
|
2543
2553
|
this.commitment = commitment2;
|
|
2544
2554
|
this.connection = new web3_js.Connection(clusterUrl, this.commitment);
|
|
2545
2555
|
this.programId = programId2 !== "" ? new web3_js.PublicKey(programId2) : new web3_js.PublicKey(PROGRAM_ID[cluster2]);
|
|
2556
|
+
this.partnerOracleProgramId = new web3_js.PublicKey(PARTNER_ORACLE_PROGRAM_ID[cluster2]);
|
|
2557
|
+
this.feeOraclePublicKey = new web3_js.PublicKey(FEE_ORACLE_PUBLIC_KEY[cluster2]);
|
|
2546
2558
|
const schedulingOptions = sendScheduler && "sendRate" in sendScheduler ? sendScheduler : void 0;
|
|
2547
2559
|
const sendThrottler2 = !sendScheduler ? common.buildSendThrottler(1) : "sendRate" in sendScheduler ? common.buildSendThrottler(sendScheduler.sendRate ?? 1, sendScheduler.sendInterval) : sendScheduler;
|
|
2548
2560
|
this.schedulingParams = {
|
|
@@ -2583,7 +2595,7 @@ var SolanaStreamClient = class {
|
|
|
2583
2595
|
const { partner, amount, tokenProgramId } = data;
|
|
2584
2596
|
const { isNative, sender, customInstructions } = extParams;
|
|
2585
2597
|
common.assertHasPublicKey(sender, "Sender's PublicKey is not available, check passed wallet adapter!");
|
|
2586
|
-
const partnerPublicKey = partner ? new web3_js.PublicKey(partner) :
|
|
2598
|
+
const partnerPublicKey = partner ? new web3_js.PublicKey(partner) : sender.publicKey;
|
|
2587
2599
|
const mintPublicKey = new web3_js.PublicKey(data.tokenId);
|
|
2588
2600
|
const ixs = await this.getCreateATAInstructions(
|
|
2589
2601
|
[partnerPublicKey],
|
|
@@ -2671,7 +2683,7 @@ var SolanaStreamClient = class {
|
|
|
2671
2683
|
return { ixs, txId: signature, metadataId };
|
|
2672
2684
|
}
|
|
2673
2685
|
async prepareCreateInstructions(streamParams, extParams) {
|
|
2674
|
-
const { ixs, metadata, metadataPubKey } = isCreateAlignedStreamData(streamParams) ? await this.prepareCreateAlignedUnlockInstructions(streamParams, extParams) : await this.
|
|
2686
|
+
const { ixs, metadata, metadataPubKey } = isCreateAlignedStreamData(streamParams) ? await this.prepareCreateAlignedUnlockInstructions(streamParams, extParams) : await this.prepareCreateLinearStreamInstructions(streamParams, extParams);
|
|
2675
2687
|
return { ixs, metadata, metadataPubKey };
|
|
2676
2688
|
}
|
|
2677
2689
|
async prepareCreateAlignedUnlockInstructions(streamParams, extParams) {
|
|
@@ -2719,7 +2731,7 @@ var SolanaStreamClient = class {
|
|
|
2719
2731
|
if (!tokenProgramId) {
|
|
2720
2732
|
tokenProgramId = (await common.getMintAndProgram(this.connection, mintPublicKey)).tokenProgramId;
|
|
2721
2733
|
}
|
|
2722
|
-
const partnerPublicKey = partner ? new web3_js.PublicKey(partner) :
|
|
2734
|
+
const partnerPublicKey = partner ? new web3_js.PublicKey(partner) : sender.publicKey;
|
|
2723
2735
|
const streamflowProgramPublicKey = new web3_js.PublicKey(this.programId);
|
|
2724
2736
|
const escrowPDA = deriveEscrowPDA(streamflowProgramPublicKey, metadataPubKey);
|
|
2725
2737
|
const oracle = priceOracle ?? deriveTestOraclePDA(this.alignedProxyProgram.programId, mintPublicKey, sender.publicKey);
|
|
@@ -2766,7 +2778,7 @@ var SolanaStreamClient = class {
|
|
|
2766
2778
|
partner: partnerPublicKey,
|
|
2767
2779
|
recipient: recipientPublicKey,
|
|
2768
2780
|
withdrawor: WITHDRAWOR_PUBLIC_KEY,
|
|
2769
|
-
feeOracle:
|
|
2781
|
+
feeOracle: this.feeOraclePublicKey,
|
|
2770
2782
|
priceOracle: oracle,
|
|
2771
2783
|
tokenProgram: tokenProgramId,
|
|
2772
2784
|
streamflowProgram: this.programId
|
|
@@ -2781,7 +2793,7 @@ var SolanaStreamClient = class {
|
|
|
2781
2793
|
* @param {IPrepareCreateStreamExt} extParams - Transaction configuration including sender wallet, metadata keys, and compute settings
|
|
2782
2794
|
* @returns Create stream instructions
|
|
2783
2795
|
*/
|
|
2784
|
-
async
|
|
2796
|
+
async prepareCreateLinearStreamInstructions({
|
|
2785
2797
|
recipient,
|
|
2786
2798
|
tokenId: mint,
|
|
2787
2799
|
start,
|
|
@@ -2822,7 +2834,7 @@ var SolanaStreamClient = class {
|
|
|
2822
2834
|
const senderTokens = await common.ata(mintPublicKey, sender.publicKey, tokenProgramId);
|
|
2823
2835
|
const recipientTokens = await common.ata(mintPublicKey, recipientPublicKey, tokenProgramId);
|
|
2824
2836
|
const streamflowTreasuryTokens = await common.ata(mintPublicKey, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
|
|
2825
|
-
const partnerPublicKey = partner ? new web3_js.PublicKey(partner) :
|
|
2837
|
+
const partnerPublicKey = partner ? new web3_js.PublicKey(partner) : sender.publicKey;
|
|
2826
2838
|
const partnerTokens = await common.ata(mintPublicKey, partnerPublicKey, tokenProgramId);
|
|
2827
2839
|
ixs.push(
|
|
2828
2840
|
await createStreamInstruction(
|
|
@@ -2857,7 +2869,7 @@ var SolanaStreamClient = class {
|
|
|
2857
2869
|
partner: partnerPublicKey,
|
|
2858
2870
|
partnerTokens,
|
|
2859
2871
|
mint: new web3_js.PublicKey(mint),
|
|
2860
|
-
feeOracle:
|
|
2872
|
+
feeOracle: this.feeOraclePublicKey,
|
|
2861
2873
|
rent: web3_js.SYSVAR_RENT_PUBKEY,
|
|
2862
2874
|
timelockProgram: this.programId,
|
|
2863
2875
|
tokenProgram: tokenProgramId,
|
|
@@ -2946,7 +2958,7 @@ var SolanaStreamClient = class {
|
|
|
2946
2958
|
);
|
|
2947
2959
|
const { tokenProgramId } = await common.getMintAndProgram(this.connection, mintPublicKey);
|
|
2948
2960
|
const senderTokens = await common.ata(mintPublicKey, sender.publicKey, tokenProgramId);
|
|
2949
|
-
const partnerPublicKey = partner ? new web3_js.PublicKey(partner) :
|
|
2961
|
+
const partnerPublicKey = partner ? new web3_js.PublicKey(partner) : sender.publicKey;
|
|
2950
2962
|
const ixs = common.prepareBaseInstructions(this.connection, {
|
|
2951
2963
|
computePrice,
|
|
2952
2964
|
computeLimit
|
|
@@ -2984,7 +2996,7 @@ var SolanaStreamClient = class {
|
|
|
2984
2996
|
metadata: metadataPubKey,
|
|
2985
2997
|
escrowTokens,
|
|
2986
2998
|
mint: new web3_js.PublicKey(mint),
|
|
2987
|
-
feeOracle:
|
|
2999
|
+
feeOracle: this.feeOraclePublicKey,
|
|
2988
3000
|
rent: web3_js.SYSVAR_RENT_PUBKEY,
|
|
2989
3001
|
timelockProgram: this.programId,
|
|
2990
3002
|
tokenProgram: tokenProgramId,
|
|
@@ -3002,15 +3014,14 @@ var SolanaStreamClient = class {
|
|
|
3002
3014
|
* @param {IPrepareCreateStreamExt} extParams - Transaction configuration including sender public key, native token handling, and custom instructions
|
|
3003
3015
|
* @returns Create multiple transaction instructions
|
|
3004
3016
|
*/
|
|
3005
|
-
async buildCreateMultipleTransactionInstructions(data, extParams) {
|
|
3017
|
+
async buildCreateMultipleTransactionInstructions(data, extParams, applyCustomAfterInstructions = true) {
|
|
3006
3018
|
const { recipients, ...streamParams } = data;
|
|
3007
3019
|
const { sender, metadataPubKeys: metadataPubKeysExt, isNative, customInstructions } = extParams;
|
|
3008
3020
|
common.assertHasPublicKey(sender, "Sender's PublicKey is not available, check passed wallet adapter!");
|
|
3009
3021
|
const metadatas = [];
|
|
3010
3022
|
const metadataToRecipient = {};
|
|
3011
3023
|
const instructionsBatch = [];
|
|
3012
|
-
const
|
|
3013
|
-
const partnerPublicKey = data.partner ? new web3_js.PublicKey(data.partner) : WITHDRAWOR_PUBLIC_KEY;
|
|
3024
|
+
const partnerPublicKey = data.partner ? new web3_js.PublicKey(data.partner) : sender.publicKey;
|
|
3014
3025
|
const mintPublicKey = new web3_js.PublicKey(data.tokenId);
|
|
3015
3026
|
if (recipients.length === 0) {
|
|
3016
3027
|
throw new Error("Recipients array is empty!");
|
|
@@ -3019,14 +3030,16 @@ var SolanaStreamClient = class {
|
|
|
3019
3030
|
const recipientData = recipients[i];
|
|
3020
3031
|
const createStreamData = { ...streamParams, ...recipientData };
|
|
3021
3032
|
const createStreamExtParams = {
|
|
3022
|
-
|
|
3023
|
-
|
|
3033
|
+
...extParams,
|
|
3034
|
+
metadataPubKeys: metadataPubKeysExt?.[i] ? [metadataPubKeysExt[i]] : void 0
|
|
3024
3035
|
};
|
|
3025
3036
|
const { ixs, metadata, metadataPubKey } = await this.prepareCreateInstructions(
|
|
3026
3037
|
createStreamData,
|
|
3027
3038
|
createStreamExtParams
|
|
3028
3039
|
);
|
|
3029
|
-
|
|
3040
|
+
if (applyCustomAfterInstructions) {
|
|
3041
|
+
await this.applyCustomAfterInstructions(ixs, customInstructions, metadataPubKey);
|
|
3042
|
+
}
|
|
3030
3043
|
metadataToRecipient[metadataPubKey.toBase58()] = recipientData;
|
|
3031
3044
|
metadatas.push(metadataPubKey.toBase58());
|
|
3032
3045
|
instructionsBatch.push({
|
|
@@ -3074,9 +3087,9 @@ var SolanaStreamClient = class {
|
|
|
3074
3087
|
* @param {IPrepareCreateStreamExt} extParams - Transaction configuration including sender public key, native token handling, and custom instructions
|
|
3075
3088
|
* @returns Multiple transaction information
|
|
3076
3089
|
*/
|
|
3077
|
-
async buildCreateMultipleTransactions(data, extParams) {
|
|
3090
|
+
async buildCreateMultipleTransactions(data, extParams, applyCustomAfterInstructions = true) {
|
|
3078
3091
|
const { sender } = extParams;
|
|
3079
|
-
const { instructionsBatch, metadatas, metadataToRecipient, prepareInstructions } = await this.buildCreateMultipleTransactionInstructions(data, extParams);
|
|
3092
|
+
const { instructionsBatch, metadatas, metadataToRecipient, prepareInstructions } = await this.buildCreateMultipleTransactionInstructions(data, extParams, applyCustomAfterInstructions);
|
|
3080
3093
|
const { value: hash, context } = await this.connection.getLatestBlockhashAndContext();
|
|
3081
3094
|
const batch = [];
|
|
3082
3095
|
for (const { ixs, metadata, recipient } of instructionsBatch) {
|
|
@@ -3107,7 +3120,7 @@ var SolanaStreamClient = class {
|
|
|
3107
3120
|
if (!sender.publicKey) {
|
|
3108
3121
|
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
3109
3122
|
}
|
|
3110
|
-
const { instructionsBatch, metadatas,
|
|
3123
|
+
const { instructionsBatch, metadatas, prepareInstructions, metadataToRecipient } = await this.flatBuildCreateMultipleTransactionInstructions(data, extParams);
|
|
3111
3124
|
const errors = [];
|
|
3112
3125
|
const signatures = [];
|
|
3113
3126
|
const metadataPubKeys = metadataPubKeysExt || [];
|
|
@@ -3172,7 +3185,7 @@ var SolanaStreamClient = class {
|
|
|
3172
3185
|
if (!sender.publicKey) {
|
|
3173
3186
|
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
3174
3187
|
}
|
|
3175
|
-
const { instructionsBatch, metadatas,
|
|
3188
|
+
const { instructionsBatch, metadatas, prepareInstructions, metadataToRecipient } = await this.flatBuildCreateMultipleTransactionInstructions(data, extParams);
|
|
3176
3189
|
const errors = [];
|
|
3177
3190
|
const signatures = [];
|
|
3178
3191
|
const batch = [];
|
|
@@ -3334,7 +3347,7 @@ var SolanaStreamClient = class {
|
|
|
3334
3347
|
}
|
|
3335
3348
|
const { sender: senderPublicKey } = decodeStream(account.data);
|
|
3336
3349
|
const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey, senderPublicKey);
|
|
3337
|
-
const ixs = isAlignedUnlock ? await this.prepareCancelAlignedUnlockInstructions(cancelData, extParams) : await this.
|
|
3350
|
+
const ixs = isAlignedUnlock ? await this.prepareCancelAlignedUnlockInstructions(cancelData, extParams) : await this.prepareCancelLinearStream(cancelData, extParams);
|
|
3338
3351
|
return ixs;
|
|
3339
3352
|
}
|
|
3340
3353
|
/**
|
|
@@ -3382,7 +3395,7 @@ var SolanaStreamClient = class {
|
|
|
3382
3395
|
* @param {IPrepareStreamExt} extParams - Transaction configuration including invoker wallet, token account validation, and compute settings
|
|
3383
3396
|
* @returns Transaction instructions
|
|
3384
3397
|
*/
|
|
3385
|
-
async
|
|
3398
|
+
async prepareCancelLinearStream({ id }, { invoker, checkTokenAccounts, computePrice, computeLimit }) {
|
|
3386
3399
|
common.assertHasPublicKey(invoker, "Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
3387
3400
|
const streamPublicKey = new web3_js.PublicKey(id);
|
|
3388
3401
|
const escrowAcc = await this.connection.getAccountInfo(streamPublicKey);
|
|
@@ -3686,20 +3699,41 @@ var SolanaStreamClient = class {
|
|
|
3686
3699
|
const accounts = await this.connection.getProgramAccounts(this.programId, {
|
|
3687
3700
|
filters
|
|
3688
3701
|
});
|
|
3689
|
-
const
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3702
|
+
const decoded = this.decodeStreamsFromAccounts(accounts);
|
|
3703
|
+
const alignedEntries = this.collectAlignedEntries(decoded);
|
|
3704
|
+
const alignedProxies = await this.fetchAlignedProxiesByEntries(alignedEntries);
|
|
3705
|
+
return this.mapDecodedToProgramAccounts(decoded, alignedEntries, alignedProxies);
|
|
3706
|
+
}
|
|
3707
|
+
decodeStreamsFromAccounts(accounts) {
|
|
3708
|
+
return accounts.map(({ pubkey, account }) => ({
|
|
3709
|
+
pubkey,
|
|
3710
|
+
stream: decodeStream(account.data)
|
|
3711
|
+
}));
|
|
3712
|
+
}
|
|
3713
|
+
collectAlignedEntries(decoded) {
|
|
3714
|
+
const entries = [];
|
|
3715
|
+
decoded.forEach(({ pubkey, stream }, index) => {
|
|
3716
|
+
if (this.isAlignedUnlock(pubkey, stream.sender)) {
|
|
3717
|
+
entries.push({ index, pda: deriveContractPDA(this.alignedProxyProgram.programId, pubkey) });
|
|
3718
|
+
}
|
|
3719
|
+
});
|
|
3720
|
+
return entries;
|
|
3721
|
+
}
|
|
3722
|
+
async fetchAlignedProxiesByEntries(aligned) {
|
|
3723
|
+
if (aligned.length === 0) return [];
|
|
3724
|
+
const res = await this.alignedProxyProgram.account.contract.fetchMultiple(aligned.map((a) => a.pda));
|
|
3725
|
+
return res;
|
|
3726
|
+
}
|
|
3727
|
+
mapDecodedToProgramAccounts(decoded, alignedEntries, alignedProxies) {
|
|
3728
|
+
return decoded.map(({ pubkey, stream }, idx) => {
|
|
3729
|
+
const alignedIdx = alignedEntries.findIndex((a) => a.index === idx);
|
|
3730
|
+
if (alignedIdx !== -1) {
|
|
3731
|
+
const alignedProxy = alignedProxies[alignedIdx];
|
|
3732
|
+
common.invariant(alignedProxy, "Couldn't get aligned proxy account info");
|
|
3733
|
+
return { publicKey: pubkey, account: new AlignedContract(stream, alignedProxy) };
|
|
3734
|
+
}
|
|
3735
|
+
return { publicKey: pubkey, account: new Contract(stream) };
|
|
3736
|
+
});
|
|
3703
3737
|
}
|
|
3704
3738
|
/**
|
|
3705
3739
|
* Attempts updating the stream auto withdrawal params and amount per period
|
|
@@ -3769,35 +3803,47 @@ var SolanaStreamClient = class {
|
|
|
3769
3803
|
* @returns Fees
|
|
3770
3804
|
*/
|
|
3771
3805
|
async getFees({ address }) {
|
|
3772
|
-
const
|
|
3773
|
-
[buffer.Buffer.from(FEES_METADATA_SEED)],
|
|
3774
|
-
new web3_js.PublicKey(PARTNER_ORACLE_PROGRAM_ID)
|
|
3775
|
-
);
|
|
3776
|
-
const data = await this.connection.getAccountInfo(metadataPubKey);
|
|
3806
|
+
const data = await this.connection.getAccountInfo(this.feeOraclePublicKey);
|
|
3777
3807
|
if (!data) {
|
|
3778
3808
|
return null;
|
|
3779
3809
|
}
|
|
3780
3810
|
const partners = borsh__namespace.deserialize(PARTNERS_SCHEMA, data.data);
|
|
3781
|
-
const
|
|
3782
|
-
|
|
3783
|
-
|
|
3811
|
+
for (const partner of partners) {
|
|
3812
|
+
const partnerAddress = new web3_js.PublicKey(partner.pubkey).toString();
|
|
3813
|
+
if (partnerAddress === address) {
|
|
3814
|
+
return {
|
|
3815
|
+
creationFeeSol: Number(partner.creation_fee),
|
|
3816
|
+
autoClaimFeeSol: Number(partner.auto_claim_fee),
|
|
3817
|
+
streamflowFee: Number(partner.token_fee_percent.toFixed(4)),
|
|
3818
|
+
partnerFee: 0
|
|
3819
|
+
};
|
|
3820
|
+
}
|
|
3784
3821
|
}
|
|
3785
|
-
return
|
|
3786
|
-
streamflowFee: Number(filteredPartners[0].strm_fee.toFixed(4)),
|
|
3787
|
-
partnerFee: Number(filteredPartners[0].partner_fee.toFixed(4))
|
|
3788
|
-
};
|
|
3822
|
+
return null;
|
|
3789
3823
|
}
|
|
3790
3824
|
/**
|
|
3791
3825
|
* Gets default streamflow fee
|
|
3792
3826
|
* @returns Default streamflow fee
|
|
3793
3827
|
*/
|
|
3794
3828
|
async getDefaultStreamflowFee() {
|
|
3795
|
-
return
|
|
3829
|
+
return (await this.getDefaultFees()).streamflowFee;
|
|
3830
|
+
}
|
|
3831
|
+
/**
|
|
3832
|
+
* Get all defaults fees applied by the protocol.
|
|
3833
|
+
*
|
|
3834
|
+
* Protocol will use fees set for WITHDRAWOR as default if they are set.
|
|
3835
|
+
*/
|
|
3836
|
+
async getDefaultFees() {
|
|
3837
|
+
return await this.getFees({ address: WITHDRAWOR }) || {
|
|
3838
|
+
creationFeeSol: DEFAULT_CREATION_FEE_SOL,
|
|
3839
|
+
autoClaimFeeSol: DEFAULT_AUTO_CLAIM_FEE_SOL,
|
|
3840
|
+
streamflowFee: DEFAULT_STREAMFLOW_FEE,
|
|
3841
|
+
partnerFee: 0
|
|
3842
|
+
};
|
|
3796
3843
|
}
|
|
3797
3844
|
/**
|
|
3798
3845
|
* Returns total fee percent, streamflow fees + partner fees
|
|
3799
3846
|
* @param getFeesData structure with address for which we need to derive fee, either sender or partner usually
|
|
3800
|
-
* @param chainSpecificParams additional parameters required by chain client
|
|
3801
3847
|
* @returns fee as floating number, so if fee is 0.99%, it will return 0.99
|
|
3802
3848
|
*/
|
|
3803
3849
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -3824,6 +3870,21 @@ var SolanaStreamClient = class {
|
|
|
3824
3870
|
const pda = deriveContractPDA(this.alignedProxyProgram.programId, streamPublicKey);
|
|
3825
3871
|
return senderPublicKey.equals(pda);
|
|
3826
3872
|
}
|
|
3873
|
+
async flatBuildCreateMultipleTransactionInstructions(data, extParams) {
|
|
3874
|
+
const dataArray = Array.isArray(data) ? data : [data];
|
|
3875
|
+
const results = await Promise.all(
|
|
3876
|
+
dataArray.map((item, index) => this.buildCreateMultipleTransactionInstructions(item, extParams, index === 0))
|
|
3877
|
+
);
|
|
3878
|
+
return {
|
|
3879
|
+
instructionsBatch: results.flatMap((r) => r.instructionsBatch),
|
|
3880
|
+
metadatas: results.flatMap((r) => r.metadatas),
|
|
3881
|
+
prepareInstructions: results.flatMap((r) => r.prepareInstructions),
|
|
3882
|
+
metadataToRecipient: results.reduce(
|
|
3883
|
+
(acc, r) => Object.assign(acc, r.metadataToRecipient),
|
|
3884
|
+
{}
|
|
3885
|
+
)
|
|
3886
|
+
};
|
|
3887
|
+
}
|
|
3827
3888
|
/**
|
|
3828
3889
|
* Utility function to generate metadata for a Contract or return existing Pubkey
|
|
3829
3890
|
*/
|
|
@@ -4311,6 +4372,8 @@ exports.CONTRACT_SEED = CONTRACT_SEED;
|
|
|
4311
4372
|
exports.CREATE_PARAMS_PADDING = CREATE_PARAMS_PADDING;
|
|
4312
4373
|
exports.Contract = Contract;
|
|
4313
4374
|
exports.ContractErrorCode = ContractErrorCode;
|
|
4375
|
+
exports.DEFAULT_AUTO_CLAIM_FEE_SOL = DEFAULT_AUTO_CLAIM_FEE_SOL;
|
|
4376
|
+
exports.DEFAULT_CREATION_FEE_SOL = DEFAULT_CREATION_FEE_SOL;
|
|
4314
4377
|
exports.DEFAULT_STREAMFLOW_FEE = DEFAULT_STREAMFLOW_FEE;
|
|
4315
4378
|
exports.ESCROW_SEED = ESCROW_SEED;
|
|
4316
4379
|
exports.FEES_METADATA_SEED = FEES_METADATA_SEED;
|
|
@@ -4335,6 +4398,7 @@ exports.StreamType = StreamType;
|
|
|
4335
4398
|
exports.TEST_ORACLE_DISCRIMINATOR = TEST_ORACLE_DISCRIMINATOR;
|
|
4336
4399
|
exports.TEST_ORACLE_SEED = TEST_ORACLE_SEED;
|
|
4337
4400
|
exports.TX_FINALITY_CONFIRMED = TX_FINALITY_CONFIRMED;
|
|
4401
|
+
exports.WITHDRAWOR = WITHDRAWOR;
|
|
4338
4402
|
exports.WITHDRAWOR_PUBLIC_KEY = WITHDRAWOR_PUBLIC_KEY;
|
|
4339
4403
|
exports.WITHDRAW_AVAILABLE_AMOUNT = WITHDRAW_AVAILABLE_AMOUNT;
|
|
4340
4404
|
exports.buildStreamType = buildStreamType;
|
|
@@ -4354,7 +4418,6 @@ exports.isAligned = isAligned;
|
|
|
4354
4418
|
exports.isCliffCloseToDepositedAmount = isCliffCloseToDepositedAmount;
|
|
4355
4419
|
exports.isCreateAlignedStreamData = isCreateAlignedStreamData;
|
|
4356
4420
|
exports.isDynamicLock = isDynamicLock;
|
|
4357
|
-
exports.isPayment = isPayment;
|
|
4358
4421
|
exports.isTokenLock = isTokenLock;
|
|
4359
4422
|
exports.isVesting = isVesting;
|
|
4360
4423
|
exports.sendAndConfirmStreamRawTransaction = sendAndConfirmStreamRawTransaction;
|