@streamflow/stream 7.1.0 → 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 +37 -14
- package/dist/cjs/solana/constants.js +3 -1
- 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 +37 -14
- package/dist/esm/solana/constants.d.ts +1 -0
- package/dist/esm/solana/constants.js +2 -0
- package/dist/esm/solana/types.d.ts +1 -0
- 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";
|
|
@@ -29,6 +29,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
30
|
exports.SolanaStreamClient = void 0;
|
|
31
31
|
const bn_js_1 = __importDefault(require("bn.js"));
|
|
32
|
+
const bs58_1 = __importDefault(require("bs58"));
|
|
32
33
|
const buffer_1 = require("buffer");
|
|
33
34
|
const spl_token_1 = require("@solana/spl-token");
|
|
34
35
|
const web3_js_1 = require("@solana/web3.js");
|
|
@@ -52,12 +53,25 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
52
53
|
/**
|
|
53
54
|
* Create Stream instance
|
|
54
55
|
*/
|
|
55
|
-
constructor(
|
|
56
|
+
constructor(optionsOrClusterUrl, cluster = types_js_2.ICluster.Mainnet, commitment = "confirmed", programId = "", sendRate = 1, sendThrottler) {
|
|
56
57
|
super();
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
+
}
|
|
61
75
|
const alignedUnlocksProgram = {
|
|
62
76
|
...streamflow_aligned_unlocks_json_1.default,
|
|
63
77
|
address: streamflow_aligned_unlocks_json_1.default.address,
|
|
@@ -78,14 +92,14 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
78
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).
|
|
79
93
|
*/
|
|
80
94
|
async create(data, extParams) {
|
|
81
|
-
const { partner, amount } = data;
|
|
95
|
+
const { partner, amount, tokenProgramId } = data;
|
|
82
96
|
const { isNative, sender } = extParams;
|
|
83
97
|
const partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_js_1.WITHDRAWOR_PUBLIC_KEY;
|
|
84
98
|
const mintPublicKey = new web3_js_1.PublicKey(data.tokenId);
|
|
85
99
|
if (!sender.publicKey) {
|
|
86
100
|
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
87
101
|
}
|
|
88
|
-
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);
|
|
89
103
|
const { ixs: createIxs, metadata, metadataPubKey } = await this.prepareCreateInstructions(data, extParams);
|
|
90
104
|
ixs.push(...createIxs);
|
|
91
105
|
if (isNative) {
|
|
@@ -110,7 +124,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
110
124
|
return { ixs, metadata, metadataPubKey };
|
|
111
125
|
}
|
|
112
126
|
async prepareCreateAlignedUnlockInstructions(streamParams, extParams) {
|
|
113
|
-
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;
|
|
114
128
|
const { isNative, sender, computeLimit, computePrice, metadataPubKeys } = extParams;
|
|
115
129
|
if (!sender.publicKey) {
|
|
116
130
|
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
@@ -122,7 +136,10 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
122
136
|
const mintPublicKey = isNative ? spl_token_1.NATIVE_MINT : new web3_js_1.PublicKey(mint);
|
|
123
137
|
const metadata = !metadataPubKeys ? web3_js_1.Keypair.generate() : undefined;
|
|
124
138
|
const metadataPubKey = metadata ? metadata.publicKey : metadataPubKeys[0];
|
|
125
|
-
|
|
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
|
+
}
|
|
126
143
|
const partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_js_1.WITHDRAWOR_PUBLIC_KEY;
|
|
127
144
|
const streamflowProgramPublicKey = new web3_js_1.PublicKey(this.programId);
|
|
128
145
|
const escrowPDA = (0, derive_accounts_js_1.deriveEscrowPDA)(streamflowProgramPublicKey, metadataPubKey);
|
|
@@ -177,7 +194,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
177
194
|
* Creates a new stream/vesting contract.
|
|
178
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).
|
|
179
196
|
*/
|
|
180
|
-
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 }) {
|
|
181
198
|
if (!sender.publicKey) {
|
|
182
199
|
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
183
200
|
}
|
|
@@ -189,7 +206,10 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
189
206
|
const recipientPublicKey = new web3_js_1.PublicKey(recipient);
|
|
190
207
|
const { metadata, metadataPubKey } = this.getOrCreateStreamMetadata(metadataPubKeys);
|
|
191
208
|
const [escrowTokens] = web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from("strm"), metadataPubKey.toBuffer()], this.programId);
|
|
192
|
-
|
|
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
|
+
}
|
|
193
213
|
const senderTokens = await (0, solana_1.ata)(mintPublicKey, sender.publicKey, tokenProgramId);
|
|
194
214
|
const recipientTokens = await (0, solana_1.ata)(mintPublicKey, recipientPublicKey, tokenProgramId);
|
|
195
215
|
const streamflowTreasuryTokens = await (0, solana_1.ata)(mintPublicKey, constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
|
|
@@ -872,14 +892,17 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
872
892
|
async searchStreams(data) {
|
|
873
893
|
const filters = Object.entries(data)
|
|
874
894
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
875
|
-
.filter(([_, value]) => value) // Only keep entries where the value is truthy
|
|
895
|
+
.filter(([_, value]) => value !== undefined) // Only keep entries where the value is truthy
|
|
876
896
|
.map(([key, value]) => ({
|
|
877
897
|
memcmp: {
|
|
878
898
|
offset: constants_js_1.STREAM_STRUCT_OFFSETS[key],
|
|
879
|
-
bytes: value,
|
|
899
|
+
bytes: typeof value === "boolean" ? bs58_1.default.encode([Number(value)]) : value.toString(),
|
|
880
900
|
},
|
|
881
901
|
}));
|
|
882
|
-
|
|
902
|
+
filters.push({ dataSize: METADATA_ACC_SIZE });
|
|
903
|
+
const accounts = await this.connection.getProgramAccounts(this.programId, {
|
|
904
|
+
filters,
|
|
905
|
+
});
|
|
883
906
|
return accounts.map(({ pubkey, account }) => ({
|
|
884
907
|
publicKey: pubkey,
|
|
885
908
|
account: new types_js_1.Contract((0, utils_js_1.decodeStream)(account.data)),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SOLANA_ERROR_MAP = exports.SOLANA_ERROR_MATCH_REGEX = exports.PARTNERS_SCHEMA = exports.PARTNER_SCHEMA = exports.AIRDROP_AMOUNT = exports.DEFAULT_STREAMFLOW_FEE = exports.FEES_METADATA_SEED = exports.AIRDROP_TEST_TOKEN = exports.FEE_ORACLE_PUBLIC_KEY = exports.WITHDRAWOR_PUBLIC_KEY = exports.STREAMFLOW_TREASURY_PUBLIC_KEY = exports.PARTNER_ORACLE_PROGRAM_ID = exports.TEST_ORACLE_SEED = exports.ESCROW_SEED = exports.CONTRACT_SEED = exports.TEST_ORACLE_DISCRIMINATOR = exports.CONTRACT_DISCRIMINATOR = exports.ALIGNED_COMPUTE_LIMIT = exports.ALIGNED_UNLOCKS_PROGRAM_ID = exports.PROGRAM_ID = exports.CREATE_PARAMS_PADDING = exports.STREAM_STRUCT_OFFSETS = exports.ALIGNED_PRECISION_FACTOR_POW = exports.STREAM_STRUCT_OFFSET_MINT = exports.STREAM_STRUCT_OFFSET_RECIPIENT = exports.STREAM_STRUCT_OFFSET_SENDER = exports.ORIGINAL_CONTRACT_SENDER_OFFSET = exports.TX_FINALITY_CONFIRMED = void 0;
|
|
3
|
+
exports.SOLANA_ERROR_MAP = exports.SOLANA_ERROR_MATCH_REGEX = exports.PARTNERS_SCHEMA = exports.PARTNER_SCHEMA = exports.AIRDROP_AMOUNT = exports.DEFAULT_STREAMFLOW_FEE = exports.FEES_METADATA_SEED = exports.AIRDROP_TEST_TOKEN = exports.FEE_ORACLE_PUBLIC_KEY = exports.WITHDRAWOR_PUBLIC_KEY = exports.STREAMFLOW_TREASURY_PUBLIC_KEY = exports.PARTNER_ORACLE_PROGRAM_ID = exports.TEST_ORACLE_SEED = exports.ESCROW_SEED = exports.CONTRACT_SEED = exports.TEST_ORACLE_DISCRIMINATOR = exports.CONTRACT_DISCRIMINATOR = exports.ALIGNED_COMPUTE_LIMIT = exports.ALIGNED_UNLOCKS_PROGRAM_ID = exports.PROGRAM_ID = exports.CREATE_PARAMS_PADDING = exports.STREAM_STRUCT_OFFSETS = exports.ALIGNED_PRECISION_FACTOR_POW = exports.STREAM_STRUCT_OFFSET_CLOSED = exports.STREAM_STRUCT_OFFSET_MINT = exports.STREAM_STRUCT_OFFSET_RECIPIENT = exports.STREAM_STRUCT_OFFSET_SENDER = exports.ORIGINAL_CONTRACT_SENDER_OFFSET = exports.TX_FINALITY_CONFIRMED = void 0;
|
|
4
4
|
const web3_js_1 = require("@solana/web3.js");
|
|
5
5
|
const buffer_1 = require("buffer");
|
|
6
6
|
const types_js_1 = require("../common/types.js");
|
|
@@ -9,11 +9,13 @@ exports.ORIGINAL_CONTRACT_SENDER_OFFSET = 9;
|
|
|
9
9
|
exports.STREAM_STRUCT_OFFSET_SENDER = 49;
|
|
10
10
|
exports.STREAM_STRUCT_OFFSET_RECIPIENT = 113;
|
|
11
11
|
exports.STREAM_STRUCT_OFFSET_MINT = 177;
|
|
12
|
+
exports.STREAM_STRUCT_OFFSET_CLOSED = 671;
|
|
12
13
|
exports.ALIGNED_PRECISION_FACTOR_POW = 9;
|
|
13
14
|
exports.STREAM_STRUCT_OFFSETS = {
|
|
14
15
|
mint: exports.STREAM_STRUCT_OFFSET_MINT,
|
|
15
16
|
recipient: exports.STREAM_STRUCT_OFFSET_RECIPIENT,
|
|
16
17
|
sender: exports.STREAM_STRUCT_OFFSET_SENDER,
|
|
18
|
+
closed: exports.STREAM_STRUCT_OFFSET_CLOSED,
|
|
17
19
|
};
|
|
18
20
|
// Defined: https://github.com/streamflow-finance/protocol/blob/main/programs/protocol/src/state.rs#L25
|
|
19
21
|
exports.CREATE_PARAMS_PADDING = 126;
|
|
@@ -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
|
*
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Latest version of the SDK that does not use Anchor. It supports raw instructions.
|
|
2
2
|
import BN from "bn.js";
|
|
3
|
+
import bs58 from "bs58";
|
|
3
4
|
import { Buffer } from "buffer";
|
|
4
5
|
import { ASSOCIATED_TOKEN_PROGRAM_ID, NATIVE_MINT } from "@solana/spl-token";
|
|
5
6
|
import { Connection, Keypair, PublicKey, SystemProgram, SYSVAR_RENT_PUBKEY, TransactionMessage, VersionedTransaction, } from "@solana/web3.js";
|
|
@@ -28,12 +29,25 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
28
29
|
/**
|
|
29
30
|
* Create Stream instance
|
|
30
31
|
*/
|
|
31
|
-
constructor(
|
|
32
|
+
constructor(optionsOrClusterUrl, cluster = ICluster.Mainnet, commitment = "confirmed", programId = "", sendRate = 1, sendThrottler) {
|
|
32
33
|
super();
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
+
}
|
|
37
51
|
const alignedUnlocksProgram = {
|
|
38
52
|
...StreamflowAlignedUnlocksIDL,
|
|
39
53
|
address: StreamflowAlignedUnlocksIDL.address,
|
|
@@ -54,14 +68,14 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
54
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).
|
|
55
69
|
*/
|
|
56
70
|
async create(data, extParams) {
|
|
57
|
-
const { partner, amount } = data;
|
|
71
|
+
const { partner, amount, tokenProgramId } = data;
|
|
58
72
|
const { isNative, sender } = extParams;
|
|
59
73
|
const partnerPublicKey = partner ? new PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
|
|
60
74
|
const mintPublicKey = new PublicKey(data.tokenId);
|
|
61
75
|
if (!sender.publicKey) {
|
|
62
76
|
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
63
77
|
}
|
|
64
|
-
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);
|
|
65
79
|
const { ixs: createIxs, metadata, metadataPubKey } = await this.prepareCreateInstructions(data, extParams);
|
|
66
80
|
ixs.push(...createIxs);
|
|
67
81
|
if (isNative) {
|
|
@@ -86,7 +100,7 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
86
100
|
return { ixs, metadata, metadataPubKey };
|
|
87
101
|
}
|
|
88
102
|
async prepareCreateAlignedUnlockInstructions(streamParams, extParams) {
|
|
89
|
-
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;
|
|
90
104
|
const { isNative, sender, computeLimit, computePrice, metadataPubKeys } = extParams;
|
|
91
105
|
if (!sender.publicKey) {
|
|
92
106
|
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
@@ -98,7 +112,10 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
98
112
|
const mintPublicKey = isNative ? NATIVE_MINT : new PublicKey(mint);
|
|
99
113
|
const metadata = !metadataPubKeys ? Keypair.generate() : undefined;
|
|
100
114
|
const metadataPubKey = metadata ? metadata.publicKey : metadataPubKeys[0];
|
|
101
|
-
|
|
115
|
+
let tokenProgramId = streamTokenProgramId ? new PublicKey(streamTokenProgramId) : undefined;
|
|
116
|
+
if (!tokenProgramId) {
|
|
117
|
+
tokenProgramId = (await getMintAndProgram(this.connection, mintPublicKey)).tokenProgramId;
|
|
118
|
+
}
|
|
102
119
|
const partnerPublicKey = partner ? new PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
|
|
103
120
|
const streamflowProgramPublicKey = new PublicKey(this.programId);
|
|
104
121
|
const escrowPDA = deriveEscrowPDA(streamflowProgramPublicKey, metadataPubKey);
|
|
@@ -153,7 +170,7 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
153
170
|
* Creates a new stream/vesting contract.
|
|
154
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).
|
|
155
172
|
*/
|
|
156
|
-
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 }) {
|
|
157
174
|
if (!sender.publicKey) {
|
|
158
175
|
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
159
176
|
}
|
|
@@ -165,7 +182,10 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
165
182
|
const recipientPublicKey = new PublicKey(recipient);
|
|
166
183
|
const { metadata, metadataPubKey } = this.getOrCreateStreamMetadata(metadataPubKeys);
|
|
167
184
|
const [escrowTokens] = PublicKey.findProgramAddressSync([Buffer.from("strm"), metadataPubKey.toBuffer()], this.programId);
|
|
168
|
-
|
|
185
|
+
let tokenProgramId = streamTokenProgramId ? new PublicKey(streamTokenProgramId) : undefined;
|
|
186
|
+
if (!tokenProgramId) {
|
|
187
|
+
tokenProgramId = (await getMintAndProgram(this.connection, mintPublicKey)).tokenProgramId;
|
|
188
|
+
}
|
|
169
189
|
const senderTokens = await ata(mintPublicKey, sender.publicKey, tokenProgramId);
|
|
170
190
|
const recipientTokens = await ata(mintPublicKey, recipientPublicKey, tokenProgramId);
|
|
171
191
|
const streamflowTreasuryTokens = await ata(mintPublicKey, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
|
|
@@ -848,14 +868,17 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
848
868
|
async searchStreams(data) {
|
|
849
869
|
const filters = Object.entries(data)
|
|
850
870
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
851
|
-
.filter(([_, value]) => value) // Only keep entries where the value is truthy
|
|
871
|
+
.filter(([_, value]) => value !== undefined) // Only keep entries where the value is truthy
|
|
852
872
|
.map(([key, value]) => ({
|
|
853
873
|
memcmp: {
|
|
854
874
|
offset: STREAM_STRUCT_OFFSETS[key],
|
|
855
|
-
bytes: value,
|
|
875
|
+
bytes: typeof value === "boolean" ? bs58.encode([Number(value)]) : value.toString(),
|
|
856
876
|
},
|
|
857
877
|
}));
|
|
858
|
-
|
|
878
|
+
filters.push({ dataSize: METADATA_ACC_SIZE });
|
|
879
|
+
const accounts = await this.connection.getProgramAccounts(this.programId, {
|
|
880
|
+
filters,
|
|
881
|
+
});
|
|
859
882
|
return accounts.map(({ pubkey, account }) => ({
|
|
860
883
|
publicKey: pubkey,
|
|
861
884
|
account: new Contract(decodeStream(account.data)),
|
|
@@ -6,6 +6,7 @@ export declare const ORIGINAL_CONTRACT_SENDER_OFFSET = 9;
|
|
|
6
6
|
export declare const STREAM_STRUCT_OFFSET_SENDER = 49;
|
|
7
7
|
export declare const STREAM_STRUCT_OFFSET_RECIPIENT = 113;
|
|
8
8
|
export declare const STREAM_STRUCT_OFFSET_MINT = 177;
|
|
9
|
+
export declare const STREAM_STRUCT_OFFSET_CLOSED = 671;
|
|
9
10
|
export declare const ALIGNED_PRECISION_FACTOR_POW = 9;
|
|
10
11
|
export declare const STREAM_STRUCT_OFFSETS: Record<keyof ISearchStreams, number>;
|
|
11
12
|
export declare const CREATE_PARAMS_PADDING = 126;
|
|
@@ -6,11 +6,13 @@ export const ORIGINAL_CONTRACT_SENDER_OFFSET = 9;
|
|
|
6
6
|
export const STREAM_STRUCT_OFFSET_SENDER = 49;
|
|
7
7
|
export const STREAM_STRUCT_OFFSET_RECIPIENT = 113;
|
|
8
8
|
export const STREAM_STRUCT_OFFSET_MINT = 177;
|
|
9
|
+
export const STREAM_STRUCT_OFFSET_CLOSED = 671;
|
|
9
10
|
export const ALIGNED_PRECISION_FACTOR_POW = 9;
|
|
10
11
|
export const STREAM_STRUCT_OFFSETS = {
|
|
11
12
|
mint: STREAM_STRUCT_OFFSET_MINT,
|
|
12
13
|
recipient: STREAM_STRUCT_OFFSET_RECIPIENT,
|
|
13
14
|
sender: STREAM_STRUCT_OFFSET_SENDER,
|
|
15
|
+
closed: STREAM_STRUCT_OFFSET_CLOSED,
|
|
14
16
|
};
|
|
15
17
|
// Defined: https://github.com/streamflow-finance/protocol/blob/main/programs/protocol/src/state.rs#L25
|
|
16
18
|
export const CREATE_PARAMS_PADDING = 126;
|
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",
|