@streamflow/stream 7.1.1 → 7.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/common/GenericStreamClient.js +1 -1
- package/dist/cjs/common/types.js +2 -2
- package/dist/cjs/solana/StreamClient.js +30 -11
- package/dist/esm/__tests__/common/GenericStreamClient.spec.js +2 -2
- package/dist/esm/common/GenericStreamClient.d.ts +2 -34
- package/dist/esm/common/GenericStreamClient.js +1 -1
- package/dist/esm/common/types.d.ts +58 -2
- package/dist/esm/common/types.js +1 -1
- package/dist/esm/solana/StreamClient.d.ts +14 -3
- package/dist/esm/solana/StreamClient.js +30 -11
- package/package.json +4 -4
|
@@ -18,7 +18,7 @@ class GenericStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
18
18
|
this.chain = options.chain;
|
|
19
19
|
switch (options.chain) {
|
|
20
20
|
case types_js_1.IChain.Solana:
|
|
21
|
-
this.nativeStreamClient = new index_js_3.SolanaStreamClient(options
|
|
21
|
+
this.nativeStreamClient = new index_js_3.SolanaStreamClient(options);
|
|
22
22
|
break;
|
|
23
23
|
case types_js_1.IChain.Aptos:
|
|
24
24
|
this.nativeStreamClient = new index_js_1.AptosStreamClient(options.clusterUrl, options.cluster, options.maxGas, options.programId);
|
package/dist/cjs/common/types.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SolanaAlignedProxyErrorCode = exports.SolanaContractErrorCode = exports.ContractErrorCode = exports.StreamType = exports.StreamDirection = exports.
|
|
3
|
+
exports.SolanaAlignedProxyErrorCode = exports.SolanaContractErrorCode = exports.ContractErrorCode = exports.StreamType = exports.StreamDirection = exports.ICluster = exports.IChain = exports.ContractError = void 0;
|
|
4
4
|
var common_1 = require("@streamflow/common");
|
|
5
|
+
Object.defineProperty(exports, "ContractError", { enumerable: true, get: function () { return common_1.ContractError; } });
|
|
5
6
|
Object.defineProperty(exports, "IChain", { enumerable: true, get: function () { return common_1.IChain; } });
|
|
6
7
|
Object.defineProperty(exports, "ICluster", { enumerable: true, get: function () { return common_1.ICluster; } });
|
|
7
|
-
Object.defineProperty(exports, "ContractError", { enumerable: true, get: function () { return common_1.ContractError; } });
|
|
8
8
|
var StreamDirection;
|
|
9
9
|
(function (StreamDirection) {
|
|
10
10
|
StreamDirection["Outgoing"] = "outgoing";
|
|
@@ -53,12 +53,25 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
53
53
|
/**
|
|
54
54
|
* Create Stream instance
|
|
55
55
|
*/
|
|
56
|
-
constructor(
|
|
56
|
+
constructor(optionsOrClusterUrl, cluster = types_js_2.ICluster.Mainnet, commitment = "confirmed", programId = "", sendRate = 1, sendThrottler) {
|
|
57
57
|
super();
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
if (typeof optionsOrClusterUrl === "string") {
|
|
59
|
+
this.commitment = commitment;
|
|
60
|
+
this.connection = new web3_js_1.Connection(optionsOrClusterUrl, this.commitment);
|
|
61
|
+
this.programId = programId !== "" ? new web3_js_1.PublicKey(programId) : new web3_js_1.PublicKey(constants_js_1.PROGRAM_ID[cluster]);
|
|
62
|
+
this.sendThrottler = sendThrottler ?? (0, solana_1.buildSendThrottler)(sendRate);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
const { clusterUrl, cluster = types_js_2.ICluster.Mainnet, commitment = "confirmed", programId = "", sendScheduler, } = optionsOrClusterUrl;
|
|
66
|
+
this.commitment = commitment;
|
|
67
|
+
this.connection = new web3_js_1.Connection(clusterUrl, this.commitment);
|
|
68
|
+
this.programId = programId !== "" ? new web3_js_1.PublicKey(programId) : new web3_js_1.PublicKey(constants_js_1.PROGRAM_ID[cluster]);
|
|
69
|
+
this.sendThrottler = !sendScheduler
|
|
70
|
+
? (0, solana_1.buildSendThrottler)(1)
|
|
71
|
+
: "sendRate" in sendScheduler
|
|
72
|
+
? (0, solana_1.buildSendThrottler)(sendScheduler.sendRate ?? 1, sendScheduler.sendInterval)
|
|
73
|
+
: sendScheduler;
|
|
74
|
+
}
|
|
62
75
|
const alignedUnlocksProgram = {
|
|
63
76
|
...streamflow_aligned_unlocks_json_1.default,
|
|
64
77
|
address: streamflow_aligned_unlocks_json_1.default.address,
|
|
@@ -79,14 +92,14 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
79
92
|
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
|
|
80
93
|
*/
|
|
81
94
|
async create(data, extParams) {
|
|
82
|
-
const { partner, amount } = data;
|
|
95
|
+
const { partner, amount, tokenProgramId } = data;
|
|
83
96
|
const { isNative, sender } = extParams;
|
|
84
97
|
const partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_js_1.WITHDRAWOR_PUBLIC_KEY;
|
|
85
98
|
const mintPublicKey = new web3_js_1.PublicKey(data.tokenId);
|
|
86
99
|
if (!sender.publicKey) {
|
|
87
100
|
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
88
101
|
}
|
|
89
|
-
const ixs = await this.getCreateATAInstructions([constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY, partnerPublicKey], mintPublicKey, sender, true);
|
|
102
|
+
const ixs = await this.getCreateATAInstructions([constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY, partnerPublicKey], mintPublicKey, sender, true, tokenProgramId ? new web3_js_1.PublicKey(tokenProgramId) : undefined);
|
|
90
103
|
const { ixs: createIxs, metadata, metadataPubKey } = await this.prepareCreateInstructions(data, extParams);
|
|
91
104
|
ixs.push(...createIxs);
|
|
92
105
|
if (isNative) {
|
|
@@ -111,7 +124,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
111
124
|
return { ixs, metadata, metadataPubKey };
|
|
112
125
|
}
|
|
113
126
|
async prepareCreateAlignedUnlockInstructions(streamParams, extParams) {
|
|
114
|
-
const { tokenId: mint, start, period, cliff, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, partner, recipient, cliffAmount, amountPerPeriod, amount: depositedAmount, name: streamName, minPrice, maxPercentage, minPercentage, maxPrice, skipInitial, tickSize, priceOracle, oracleType, } = streamParams;
|
|
127
|
+
const { tokenId: mint, start, period, cliff, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, partner, recipient, cliffAmount, amountPerPeriod, amount: depositedAmount, name: streamName, minPrice, maxPercentage, minPercentage, maxPrice, skipInitial, tickSize, priceOracle, oracleType, tokenProgramId: streamTokenProgramId, } = streamParams;
|
|
115
128
|
const { isNative, sender, computeLimit, computePrice, metadataPubKeys } = extParams;
|
|
116
129
|
if (!sender.publicKey) {
|
|
117
130
|
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
@@ -123,7 +136,10 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
123
136
|
const mintPublicKey = isNative ? spl_token_1.NATIVE_MINT : new web3_js_1.PublicKey(mint);
|
|
124
137
|
const metadata = !metadataPubKeys ? web3_js_1.Keypair.generate() : undefined;
|
|
125
138
|
const metadataPubKey = metadata ? metadata.publicKey : metadataPubKeys[0];
|
|
126
|
-
|
|
139
|
+
let tokenProgramId = streamTokenProgramId ? new web3_js_1.PublicKey(streamTokenProgramId) : undefined;
|
|
140
|
+
if (!tokenProgramId) {
|
|
141
|
+
tokenProgramId = (await (0, solana_1.getMintAndProgram)(this.connection, mintPublicKey)).tokenProgramId;
|
|
142
|
+
}
|
|
127
143
|
const partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_js_1.WITHDRAWOR_PUBLIC_KEY;
|
|
128
144
|
const streamflowProgramPublicKey = new web3_js_1.PublicKey(this.programId);
|
|
129
145
|
const escrowPDA = (0, derive_accounts_js_1.deriveEscrowPDA)(streamflowProgramPublicKey, metadataPubKey);
|
|
@@ -178,7 +194,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
178
194
|
* Creates a new stream/vesting contract.
|
|
179
195
|
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
|
|
180
196
|
*/
|
|
181
|
-
async prepareCreateStreamInstructions({ recipient, tokenId: mint, start, amount: depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canPause, canUpdateRate, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal = false, withdrawalFrequency = 0, partner, }, { sender, metadataPubKeys, isNative = false, computePrice, computeLimit }) {
|
|
197
|
+
async prepareCreateStreamInstructions({ recipient, tokenId: mint, start, amount: depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canPause, canUpdateRate, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal = false, withdrawalFrequency = 0, partner, tokenProgramId: streamTokenProgramId, }, { sender, metadataPubKeys, isNative = false, computePrice, computeLimit }) {
|
|
182
198
|
if (!sender.publicKey) {
|
|
183
199
|
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
184
200
|
}
|
|
@@ -190,7 +206,10 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
190
206
|
const recipientPublicKey = new web3_js_1.PublicKey(recipient);
|
|
191
207
|
const { metadata, metadataPubKey } = this.getOrCreateStreamMetadata(metadataPubKeys);
|
|
192
208
|
const [escrowTokens] = web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from("strm"), metadataPubKey.toBuffer()], this.programId);
|
|
193
|
-
|
|
209
|
+
let tokenProgramId = streamTokenProgramId ? new web3_js_1.PublicKey(streamTokenProgramId) : undefined;
|
|
210
|
+
if (!tokenProgramId) {
|
|
211
|
+
tokenProgramId = (await (0, solana_1.getMintAndProgram)(this.connection, mintPublicKey)).tokenProgramId;
|
|
212
|
+
}
|
|
194
213
|
const senderTokens = await (0, solana_1.ata)(mintPublicKey, sender.publicKey, tokenProgramId);
|
|
195
214
|
const recipientTokens = await (0, solana_1.ata)(mintPublicKey, recipientPublicKey, tokenProgramId);
|
|
196
215
|
const streamflowTreasuryTokens = await (0, solana_1.ata)(mintPublicKey, constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Wallet } from "ethers";
|
|
2
2
|
import { describe, expect, test } from "vitest";
|
|
3
3
|
import { StreamflowAptos, StreamflowEVM, StreamflowSolana, StreamflowSui } from "../../index.js";
|
|
4
|
-
import { default as GenericStreamClient
|
|
5
|
-
import { IChain, ICluster } from "../../common/types.js";
|
|
4
|
+
import { default as GenericStreamClient } from "../../common/GenericStreamClient.js";
|
|
5
|
+
import { IChain, ICluster, } from "../../common/types.js";
|
|
6
6
|
describe("GenericStreamClient", () => {
|
|
7
7
|
describe.each([
|
|
8
8
|
{
|
|
@@ -1,41 +1,9 @@
|
|
|
1
|
-
import { Commitment, ConnectionConfig } from "@solana/web3.js";
|
|
2
|
-
import { Signer } from "ethers";
|
|
3
|
-
import PQueue from "p-queue";
|
|
4
1
|
import { BaseStreamClient } from "./BaseStreamClient.js";
|
|
5
|
-
import { ICancelData, IChain,
|
|
2
|
+
import { ICancelData, IChain, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IUpdateData, IWithdrawData, ITransactionResult, IMultiTransactionResult, ICreateResult, IGetAllData, Stream, IFees, IGetFeesData, AptosStreamClientOptions, SuiStreamClientOptions, EvmStreamClientOptions, SolanaStreamClientOptions } from "./types.js";
|
|
6
3
|
import { AptosStreamClient, ICreateStreamAptosExt, ITransactionAptosExt } from "../aptos/index.js";
|
|
7
4
|
import { EvmStreamClient } from "../evm/index.js";
|
|
8
5
|
import { SolanaStreamClient, ICreateStreamSolanaExt, IInteractStreamSolanaExt, ITopUpStreamSolanaExt } from "../solana/index.js";
|
|
9
|
-
import { ICreateStreamSuiExt, ITransactionSuiExt,
|
|
10
|
-
export interface SolanaStreamClientOptions {
|
|
11
|
-
chain: IChain.Solana;
|
|
12
|
-
clusterUrl: string;
|
|
13
|
-
cluster?: ICluster;
|
|
14
|
-
programId?: string;
|
|
15
|
-
commitment?: Commitment | ConnectionConfig;
|
|
16
|
-
sendRate?: number;
|
|
17
|
-
sendThrottler?: PQueue;
|
|
18
|
-
}
|
|
19
|
-
export interface AptosStreamClientOptions {
|
|
20
|
-
chain: IChain.Aptos;
|
|
21
|
-
clusterUrl: string;
|
|
22
|
-
cluster?: ICluster;
|
|
23
|
-
programId?: string;
|
|
24
|
-
maxGas?: string;
|
|
25
|
-
}
|
|
26
|
-
export interface EvmStreamClientOptions {
|
|
27
|
-
chain: IChain.Ethereum | IChain.BNB | IChain.Polygon;
|
|
28
|
-
clusterUrl: string;
|
|
29
|
-
signer: Signer;
|
|
30
|
-
cluster?: ICluster;
|
|
31
|
-
programId?: string;
|
|
32
|
-
}
|
|
33
|
-
export interface SuiStreamClientOptions {
|
|
34
|
-
chain: IChain.Sui;
|
|
35
|
-
clusterUrl: string;
|
|
36
|
-
cluster?: ICluster;
|
|
37
|
-
ids?: ISuiIdParameters;
|
|
38
|
-
}
|
|
6
|
+
import { ICreateStreamSuiExt, ITransactionSuiExt, SuiStreamClient } from "../sui/index.js";
|
|
39
7
|
/** Type referencing options for specific Chain Client */
|
|
40
8
|
type StreamClientOptions<T extends IChain> = T extends IChain.Solana ? SolanaStreamClientOptions : T extends IChain.Aptos ? AptosStreamClientOptions : T extends IChain.Sui ? SuiStreamClientOptions : EvmStreamClientOptions;
|
|
41
9
|
/** Type referencing Chain Client implementation */
|
|
@@ -18,7 +18,7 @@ export default class GenericStreamClient extends BaseStreamClient {
|
|
|
18
18
|
this.chain = options.chain;
|
|
19
19
|
switch (options.chain) {
|
|
20
20
|
case IChain.Solana:
|
|
21
|
-
this.nativeStreamClient = new SolanaStreamClient(options
|
|
21
|
+
this.nativeStreamClient = new SolanaStreamClient(options);
|
|
22
22
|
break;
|
|
23
23
|
case IChain.Aptos:
|
|
24
24
|
this.nativeStreamClient = new AptosStreamClient(options.clusterUrl, options.cluster, options.maxGas, options.programId);
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { Address } from "@coral-xyz/anchor";
|
|
2
|
-
import { TransactionInstruction } from "@solana/web3.js";
|
|
2
|
+
import { Commitment, ConnectionConfig, PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
3
|
+
import { IChain, ICluster } from "@streamflow/common";
|
|
3
4
|
import { Types } from "aptos";
|
|
4
5
|
import BN from "bn.js";
|
|
5
|
-
|
|
6
|
+
import type { Signer } from "ethers";
|
|
7
|
+
import type { default as PQueue } from "p-queue";
|
|
8
|
+
import { ISuiIdParameters } from "../sui/index.js";
|
|
9
|
+
export { ContractError, IChain, ICluster } from "@streamflow/common";
|
|
6
10
|
export interface IRecipient {
|
|
7
11
|
recipient: string;
|
|
8
12
|
amount: BN;
|
|
@@ -25,6 +29,7 @@ export interface IBaseStreamConfig {
|
|
|
25
29
|
canPause?: boolean;
|
|
26
30
|
canUpdateRate?: boolean;
|
|
27
31
|
partner?: string;
|
|
32
|
+
tokenProgramId?: string | PublicKey;
|
|
28
33
|
}
|
|
29
34
|
export type IAlignedStreamConfig = {
|
|
30
35
|
minPrice: number;
|
|
@@ -282,3 +287,54 @@ export declare enum SolanaAlignedProxyErrorCode {
|
|
|
282
287
|
/** All funds are already unlocked */
|
|
283
288
|
AllFundsUnlocked = "AllFundsUnlocked"
|
|
284
289
|
}
|
|
290
|
+
/**
|
|
291
|
+
* @interface
|
|
292
|
+
*/
|
|
293
|
+
export interface SolanaStreamClientOptions {
|
|
294
|
+
chain: IChain.Solana;
|
|
295
|
+
clusterUrl: string;
|
|
296
|
+
cluster?: ICluster;
|
|
297
|
+
programId?: string;
|
|
298
|
+
commitment?: Commitment | ConnectionConfig;
|
|
299
|
+
sendRate?: number;
|
|
300
|
+
sendThrottler?: PQueue;
|
|
301
|
+
sendScheduler?: PQueue | {
|
|
302
|
+
/**
|
|
303
|
+
* concurrency rate for scheduling
|
|
304
|
+
*/
|
|
305
|
+
sendRate: number;
|
|
306
|
+
/**
|
|
307
|
+
* time interval between consecutive sends
|
|
308
|
+
*/
|
|
309
|
+
sendInterval?: number;
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* @interface
|
|
314
|
+
*/
|
|
315
|
+
export interface AptosStreamClientOptions {
|
|
316
|
+
chain: IChain.Aptos;
|
|
317
|
+
clusterUrl: string;
|
|
318
|
+
cluster?: ICluster;
|
|
319
|
+
programId?: string;
|
|
320
|
+
maxGas?: string;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* @interface
|
|
324
|
+
*/
|
|
325
|
+
export interface EvmStreamClientOptions {
|
|
326
|
+
chain: IChain.Ethereum | IChain.BNB | IChain.Polygon;
|
|
327
|
+
clusterUrl: string;
|
|
328
|
+
signer: Signer;
|
|
329
|
+
cluster?: ICluster;
|
|
330
|
+
programId?: string;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* @interface
|
|
334
|
+
*/
|
|
335
|
+
export interface SuiStreamClientOptions {
|
|
336
|
+
chain: IChain.Sui;
|
|
337
|
+
clusterUrl: string;
|
|
338
|
+
cluster?: ICluster;
|
|
339
|
+
ids?: ISuiIdParameters;
|
|
340
|
+
}
|
package/dist/esm/common/types.js
CHANGED
|
@@ -2,8 +2,15 @@ import PQueue from "p-queue";
|
|
|
2
2
|
import { Connection, Keypair, PublicKey, TransactionInstruction, Commitment, ConnectionConfig } from "@solana/web3.js";
|
|
3
3
|
import { IProgramAccount } from "@streamflow/common/solana";
|
|
4
4
|
import { ICreateStreamSolanaExt, IInteractStreamSolanaExt, ITopUpStreamSolanaExt, ISearchStreams, ICreateStreamInstructions } from "./types.js";
|
|
5
|
-
import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateResult, ICreateStreamData, IGetAllData, IGetFeesData, IGetOneData, IFees, IMultiTransactionResult, ITopUpData, ITransactionResult, ITransferData, IUpdateData, IWithdrawData, Stream, ICreateAlignedStreamData } from "../common/types.js";
|
|
5
|
+
import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateResult, ICreateStreamData, IGetAllData, IGetFeesData, IGetOneData, IFees, IMultiTransactionResult, ITopUpData, ITransactionResult, ITransferData, IUpdateData, IWithdrawData, Stream, ICreateAlignedStreamData, SolanaStreamClientOptions } from "../common/types.js";
|
|
6
6
|
import { BaseStreamClient } from "../common/BaseStreamClient.js";
|
|
7
|
+
/**
|
|
8
|
+
* Solana Client creation options
|
|
9
|
+
* @property cluster {@link ICluster} cluster type
|
|
10
|
+
* @property clusterUrl cluster url
|
|
11
|
+
* @interface ClientCreationOptions
|
|
12
|
+
*/
|
|
13
|
+
export type ClientCreationOptions = Omit<SolanaStreamClientOptions, "chain" | "sendRate" | "sendThrottler">;
|
|
7
14
|
export declare class SolanaStreamClient extends BaseStreamClient {
|
|
8
15
|
private connection;
|
|
9
16
|
private programId;
|
|
@@ -11,9 +18,13 @@ export declare class SolanaStreamClient extends BaseStreamClient {
|
|
|
11
18
|
private sendThrottler;
|
|
12
19
|
private alignedProxyProgram;
|
|
13
20
|
/**
|
|
14
|
-
* Create Stream instance
|
|
21
|
+
* Create Stream instance with flat arguments
|
|
15
22
|
*/
|
|
16
23
|
constructor(clusterUrl: string, cluster?: ICluster, commitment?: Commitment | ConnectionConfig, programId?: string, sendRate?: number, sendThrottler?: PQueue);
|
|
24
|
+
/**
|
|
25
|
+
* Create Stream instance with options
|
|
26
|
+
*/
|
|
27
|
+
constructor(options: ClientCreationOptions);
|
|
17
28
|
getConnection(): Connection;
|
|
18
29
|
getCommitment(): Commitment | undefined;
|
|
19
30
|
getProgramId(): string;
|
|
@@ -28,7 +39,7 @@ export declare class SolanaStreamClient extends BaseStreamClient {
|
|
|
28
39
|
* Creates a new stream/vesting contract.
|
|
29
40
|
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
|
|
30
41
|
*/
|
|
31
|
-
prepareCreateStreamInstructions({ recipient, tokenId: mint, start, amount: depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canPause, canUpdateRate, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, withdrawalFrequency, partner, }: ICreateStreamData, { sender, metadataPubKeys, isNative, computePrice, computeLimit }: ICreateStreamSolanaExt): Promise<ICreateStreamInstructions>;
|
|
42
|
+
prepareCreateStreamInstructions({ recipient, tokenId: mint, start, amount: depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canPause, canUpdateRate, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, withdrawalFrequency, partner, tokenProgramId: streamTokenProgramId, }: ICreateStreamData, { sender, metadataPubKeys, isNative, computePrice, computeLimit }: ICreateStreamSolanaExt): Promise<ICreateStreamInstructions>;
|
|
32
43
|
/**
|
|
33
44
|
* Creates a new stream/vesting contract using unchecked instruction.
|
|
34
45
|
*
|
|
@@ -29,12 +29,25 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
29
29
|
/**
|
|
30
30
|
* Create Stream instance
|
|
31
31
|
*/
|
|
32
|
-
constructor(
|
|
32
|
+
constructor(optionsOrClusterUrl, cluster = ICluster.Mainnet, commitment = "confirmed", programId = "", sendRate = 1, sendThrottler) {
|
|
33
33
|
super();
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
if (typeof optionsOrClusterUrl === "string") {
|
|
35
|
+
this.commitment = commitment;
|
|
36
|
+
this.connection = new Connection(optionsOrClusterUrl, this.commitment);
|
|
37
|
+
this.programId = programId !== "" ? new PublicKey(programId) : new PublicKey(PROGRAM_ID[cluster]);
|
|
38
|
+
this.sendThrottler = sendThrottler ?? buildSendThrottler(sendRate);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
const { clusterUrl, cluster = ICluster.Mainnet, commitment = "confirmed", programId = "", sendScheduler, } = optionsOrClusterUrl;
|
|
42
|
+
this.commitment = commitment;
|
|
43
|
+
this.connection = new Connection(clusterUrl, this.commitment);
|
|
44
|
+
this.programId = programId !== "" ? new PublicKey(programId) : new PublicKey(PROGRAM_ID[cluster]);
|
|
45
|
+
this.sendThrottler = !sendScheduler
|
|
46
|
+
? buildSendThrottler(1)
|
|
47
|
+
: "sendRate" in sendScheduler
|
|
48
|
+
? buildSendThrottler(sendScheduler.sendRate ?? 1, sendScheduler.sendInterval)
|
|
49
|
+
: sendScheduler;
|
|
50
|
+
}
|
|
38
51
|
const alignedUnlocksProgram = {
|
|
39
52
|
...StreamflowAlignedUnlocksIDL,
|
|
40
53
|
address: StreamflowAlignedUnlocksIDL.address,
|
|
@@ -55,14 +68,14 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
55
68
|
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
|
|
56
69
|
*/
|
|
57
70
|
async create(data, extParams) {
|
|
58
|
-
const { partner, amount } = data;
|
|
71
|
+
const { partner, amount, tokenProgramId } = data;
|
|
59
72
|
const { isNative, sender } = extParams;
|
|
60
73
|
const partnerPublicKey = partner ? new PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
|
|
61
74
|
const mintPublicKey = new PublicKey(data.tokenId);
|
|
62
75
|
if (!sender.publicKey) {
|
|
63
76
|
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
64
77
|
}
|
|
65
|
-
const ixs = await this.getCreateATAInstructions([STREAMFLOW_TREASURY_PUBLIC_KEY, partnerPublicKey], mintPublicKey, sender, true);
|
|
78
|
+
const ixs = await this.getCreateATAInstructions([STREAMFLOW_TREASURY_PUBLIC_KEY, partnerPublicKey], mintPublicKey, sender, true, tokenProgramId ? new PublicKey(tokenProgramId) : undefined);
|
|
66
79
|
const { ixs: createIxs, metadata, metadataPubKey } = await this.prepareCreateInstructions(data, extParams);
|
|
67
80
|
ixs.push(...createIxs);
|
|
68
81
|
if (isNative) {
|
|
@@ -87,7 +100,7 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
87
100
|
return { ixs, metadata, metadataPubKey };
|
|
88
101
|
}
|
|
89
102
|
async prepareCreateAlignedUnlockInstructions(streamParams, extParams) {
|
|
90
|
-
const { tokenId: mint, start, period, cliff, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, partner, recipient, cliffAmount, amountPerPeriod, amount: depositedAmount, name: streamName, minPrice, maxPercentage, minPercentage, maxPrice, skipInitial, tickSize, priceOracle, oracleType, } = streamParams;
|
|
103
|
+
const { tokenId: mint, start, period, cliff, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, partner, recipient, cliffAmount, amountPerPeriod, amount: depositedAmount, name: streamName, minPrice, maxPercentage, minPercentage, maxPrice, skipInitial, tickSize, priceOracle, oracleType, tokenProgramId: streamTokenProgramId, } = streamParams;
|
|
91
104
|
const { isNative, sender, computeLimit, computePrice, metadataPubKeys } = extParams;
|
|
92
105
|
if (!sender.publicKey) {
|
|
93
106
|
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
@@ -99,7 +112,10 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
99
112
|
const mintPublicKey = isNative ? NATIVE_MINT : new PublicKey(mint);
|
|
100
113
|
const metadata = !metadataPubKeys ? Keypair.generate() : undefined;
|
|
101
114
|
const metadataPubKey = metadata ? metadata.publicKey : metadataPubKeys[0];
|
|
102
|
-
|
|
115
|
+
let tokenProgramId = streamTokenProgramId ? new PublicKey(streamTokenProgramId) : undefined;
|
|
116
|
+
if (!tokenProgramId) {
|
|
117
|
+
tokenProgramId = (await getMintAndProgram(this.connection, mintPublicKey)).tokenProgramId;
|
|
118
|
+
}
|
|
103
119
|
const partnerPublicKey = partner ? new PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
|
|
104
120
|
const streamflowProgramPublicKey = new PublicKey(this.programId);
|
|
105
121
|
const escrowPDA = deriveEscrowPDA(streamflowProgramPublicKey, metadataPubKey);
|
|
@@ -154,7 +170,7 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
154
170
|
* Creates a new stream/vesting contract.
|
|
155
171
|
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
|
|
156
172
|
*/
|
|
157
|
-
async prepareCreateStreamInstructions({ recipient, tokenId: mint, start, amount: depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canPause, canUpdateRate, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal = false, withdrawalFrequency = 0, partner, }, { sender, metadataPubKeys, isNative = false, computePrice, computeLimit }) {
|
|
173
|
+
async prepareCreateStreamInstructions({ recipient, tokenId: mint, start, amount: depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canPause, canUpdateRate, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal = false, withdrawalFrequency = 0, partner, tokenProgramId: streamTokenProgramId, }, { sender, metadataPubKeys, isNative = false, computePrice, computeLimit }) {
|
|
158
174
|
if (!sender.publicKey) {
|
|
159
175
|
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
160
176
|
}
|
|
@@ -166,7 +182,10 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
166
182
|
const recipientPublicKey = new PublicKey(recipient);
|
|
167
183
|
const { metadata, metadataPubKey } = this.getOrCreateStreamMetadata(metadataPubKeys);
|
|
168
184
|
const [escrowTokens] = PublicKey.findProgramAddressSync([Buffer.from("strm"), metadataPubKey.toBuffer()], this.programId);
|
|
169
|
-
|
|
185
|
+
let tokenProgramId = streamTokenProgramId ? new PublicKey(streamTokenProgramId) : undefined;
|
|
186
|
+
if (!tokenProgramId) {
|
|
187
|
+
tokenProgramId = (await getMintAndProgram(this.connection, mintPublicKey)).tokenProgramId;
|
|
188
|
+
}
|
|
170
189
|
const senderTokens = await ata(mintPublicKey, sender.publicKey, tokenProgramId);
|
|
171
190
|
const recipientTokens = await ata(mintPublicKey, recipientPublicKey, tokenProgramId);
|
|
172
191
|
const streamflowTreasuryTokens = await ata(mintPublicKey, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamflow/stream",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.2.0",
|
|
4
4
|
"description": "JavaScript SDK to interact with Streamflow protocol.",
|
|
5
5
|
"homepage": "https://github.com/streamflow-finance/js-sdk/",
|
|
6
6
|
"main": "./dist/esm/index.js",
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
"lint": "eslint --fix .",
|
|
43
43
|
"prepublishOnly": "pnpm run lint && pnpm run test run && pnpm run build"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "e56411e57d702a9f74d9611317fffa7e0a827c8c",
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@streamflow/eslint-config": "7.
|
|
47
|
+
"@streamflow/eslint-config": "7.2.0",
|
|
48
48
|
"@types/bn.js": "5.1.1",
|
|
49
49
|
"@types/ethereum-checksum-address": "^0.0.0",
|
|
50
50
|
"date-fns": "2.28.0",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"@solana/spl-token": "0.4.9",
|
|
60
60
|
"@solana/wallet-adapter-base": "0.9.19",
|
|
61
61
|
"@solana/web3.js": "1.95.4",
|
|
62
|
-
"@streamflow/common": "7.
|
|
62
|
+
"@streamflow/common": "7.2.0",
|
|
63
63
|
"@suiet/wallet-kit": "0.2.22",
|
|
64
64
|
"aptos": "1.21.0",
|
|
65
65
|
"bn.js": "5.2.1",
|