@streamflow/stream 7.0.0-alpha.1 → 7.0.0-alpha.11
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 +65 -68
- package/dist/cjs/__tests__/aptos/streamClient.spec.js +83 -134
- package/dist/cjs/__tests__/common/GenericStreamClient.spec.js +9 -9
- package/dist/cjs/aptos/StreamClient.js +162 -367
- package/dist/cjs/aptos/constants.js +7 -8
- package/dist/cjs/aptos/index.js +3 -3
- package/dist/cjs/aptos/types.js +32 -41
- package/dist/cjs/aptos/utils.js +4 -4
- package/dist/cjs/aptos/wallet.js +20 -75
- package/dist/cjs/common/BaseStreamClient.js +11 -59
- package/dist/cjs/common/GenericStreamClient.js +46 -72
- package/dist/cjs/common/constants.js +2 -2
- package/dist/cjs/common/contractUtils.js +16 -17
- package/dist/cjs/common/utils.js +34 -84
- package/dist/cjs/evm/StreamClient.js +198 -456
- package/dist/cjs/evm/constants.js +19 -20
- package/dist/cjs/evm/types.js +25 -34
- package/dist/cjs/evm/utils.js +2 -2
- package/dist/cjs/index.js +10 -10
- package/dist/cjs/solana/StreamClient.js +608 -1090
- package/dist/cjs/solana/constants.js +16 -11
- package/dist/cjs/solana/instructions.js +76 -80
- package/dist/cjs/solana/layout.js +7 -8
- package/dist/cjs/solana/types.js +15 -25
- package/dist/cjs/solana/utils.js +77 -154
- package/dist/cjs/sui/StreamClient.js +325 -571
- package/dist/cjs/sui/constants.js +19 -20
- package/dist/cjs/sui/types.js +28 -62
- package/dist/cjs/sui/utils.js +7 -7
- package/dist/cjs/sui/wallet.js +13 -63
- package/dist/esm/__tests__/aptos/streamClient.spec.js +4 -4
- package/dist/esm/aptos/index.d.ts +3 -3
- package/dist/esm/aptos/index.js +3 -3
- package/dist/esm/aptos/types.d.ts +12 -12
- package/dist/esm/aptos/types.js +13 -13
- package/dist/esm/common/GenericStreamClient.d.ts +4 -4
- package/dist/esm/common/GenericStreamClient.js +4 -4
- package/dist/esm/common/constants.d.ts +2 -2
- package/dist/esm/common/constants.js +2 -2
- package/dist/esm/common/contractUtils.d.ts +14 -14
- package/dist/esm/common/contractUtils.js +6 -6
- package/dist/esm/common/types.d.ts +19 -19
- package/dist/esm/common/utils.d.ts +11 -11
- package/dist/esm/common/utils.js +16 -19
- package/dist/esm/evm/StreamClient.d.ts +2 -2
- package/dist/esm/evm/StreamClient.js +7 -7
- package/dist/esm/evm/types.d.ts +37 -37
- package/dist/esm/evm/types.js +13 -13
- package/dist/esm/index.d.ts +9 -9
- package/dist/esm/index.js +9 -9
- package/dist/esm/solana/StreamClient.d.ts +3 -1
- package/dist/esm/solana/StreamClient.js +38 -22
- package/dist/esm/solana/constants.d.ts +3 -0
- package/dist/esm/solana/constants.js +6 -0
- package/dist/esm/solana/instructions.d.ts +17 -17
- package/dist/esm/solana/instructions.js +19 -18
- package/dist/esm/solana/types.d.ts +41 -36
- package/dist/esm/solana/types.js +2 -2
- package/dist/esm/solana/utils.d.ts +2 -0
- package/dist/esm/solana/utils.js +32 -26
- package/dist/esm/sui/StreamClient.js +1 -1
- package/dist/esm/sui/types.d.ts +12 -12
- package/dist/esm/sui/types.js +13 -13
- package/package.json +10 -11
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Latest version of the SDK that does not use Anchor. It supports raw instructions.
|
|
2
|
-
import
|
|
2
|
+
import BigNumber from "bignumber.js";
|
|
3
3
|
import { Buffer } from "buffer";
|
|
4
4
|
import { ASSOCIATED_TOKEN_PROGRAM_ID, NATIVE_MINT } from "@solana/spl-token";
|
|
5
5
|
import { Connection, Keypair, PublicKey, SystemProgram, SYSVAR_RENT_PUBKEY, TransactionMessage, VersionedTransaction, } from "@solana/web3.js";
|
|
@@ -7,7 +7,7 @@ import { ata, checkOrCreateAtaBatch, signAndExecuteTransaction, getProgramAccoun
|
|
|
7
7
|
import * as borsh from "borsh";
|
|
8
8
|
import { Contract, } from "./types.js";
|
|
9
9
|
import { decodeStream, extractSolanaErrorCode, sendAndConfirmStreamRawTransaction, signAllTransactionWithRecipients, } from "./utils.js";
|
|
10
|
-
import { PROGRAM_ID, STREAMFLOW_TREASURY_PUBLIC_KEY, STREAM_STRUCT_OFFSET_RECIPIENT, STREAM_STRUCT_OFFSET_SENDER, TX_FINALITY_CONFIRMED, WITHDRAWOR_PUBLIC_KEY, FEE_ORACLE_PUBLIC_KEY, DEFAULT_STREAMFLOW_FEE, PARTNER_ORACLE_PROGRAM_ID, FEES_METADATA_SEED, PARTNERS_SCHEMA, } from "./constants.js";
|
|
10
|
+
import { PROGRAM_ID, STREAMFLOW_TREASURY_PUBLIC_KEY, STREAM_STRUCT_OFFSET_RECIPIENT, STREAM_STRUCT_OFFSET_SENDER, TX_FINALITY_CONFIRMED, WITHDRAWOR_PUBLIC_KEY, FEE_ORACLE_PUBLIC_KEY, DEFAULT_STREAMFLOW_FEE, PARTNER_ORACLE_PROGRAM_ID, FEES_METADATA_SEED, PARTNERS_SCHEMA, STREAM_STRUCT_OFFSETS, } from "./constants.js";
|
|
11
11
|
import { withdrawStreamInstruction, cancelStreamInstruction, transferStreamInstruction, topupStreamInstruction, createStreamInstruction, createUncheckedStreamInstruction, updateStreamInstruction, } from "./instructions.js";
|
|
12
12
|
import { ICluster, StreamDirection, StreamType, } from "../common/types.js";
|
|
13
13
|
import { BaseStreamClient } from "../common/BaseStreamClient.js";
|
|
@@ -72,22 +72,22 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
72
72
|
const senderTokens = await ata(mintPublicKey, sender.publicKey, tokenProgramId);
|
|
73
73
|
const recipientTokens = await ata(mintPublicKey, recipientPublicKey, tokenProgramId);
|
|
74
74
|
const streamflowTreasuryTokens = await ata(mintPublicKey, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
|
|
75
|
-
const partnerPublicKey = partner ? new PublicKey(partner) :
|
|
75
|
+
const partnerPublicKey = partner ? new PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
|
|
76
76
|
const partnerTokens = await ata(mintPublicKey, partnerPublicKey, tokenProgramId);
|
|
77
77
|
if (isNative) {
|
|
78
78
|
const totalFee = await this.getTotalFee({
|
|
79
|
-
address:
|
|
79
|
+
address: partnerPublicKey.toString(),
|
|
80
80
|
});
|
|
81
81
|
const totalAmount = calculateTotalAmountToDeposit(depositedAmount, totalFee);
|
|
82
82
|
ixs.push(...(await prepareWrappedAccount(this.connection, sender.publicKey, totalAmount)));
|
|
83
83
|
}
|
|
84
84
|
ixs.push(createStreamInstruction({
|
|
85
|
-
start:
|
|
85
|
+
start: BigNumber(start),
|
|
86
86
|
depositedAmount,
|
|
87
|
-
period:
|
|
87
|
+
period: BigNumber(period),
|
|
88
88
|
amountPerPeriod,
|
|
89
|
-
cliff:
|
|
90
|
-
cliffAmount,
|
|
89
|
+
cliff: BigNumber(cliff),
|
|
90
|
+
cliffAmount: BigNumber(cliffAmount),
|
|
91
91
|
cancelableBySender,
|
|
92
92
|
cancelableByRecipient,
|
|
93
93
|
automaticWithdrawal,
|
|
@@ -97,7 +97,7 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
97
97
|
canUpdateRate: !!canUpdateRate,
|
|
98
98
|
canPause: !!canPause,
|
|
99
99
|
name,
|
|
100
|
-
withdrawFrequency:
|
|
100
|
+
withdrawFrequency: BigNumber(automaticWithdrawal ? withdrawalFrequency : period),
|
|
101
101
|
}, this.programId, {
|
|
102
102
|
sender: sender.publicKey,
|
|
103
103
|
senderTokens,
|
|
@@ -161,23 +161,23 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
161
161
|
const [escrowTokens] = PublicKey.findProgramAddressSync([Buffer.from("strm"), metadataPubKey.toBuffer()], this.programId);
|
|
162
162
|
const { tokenProgramId } = await getMintAndProgram(this.connection, mintPublicKey);
|
|
163
163
|
const senderTokens = await ata(mintPublicKey, sender.publicKey, tokenProgramId);
|
|
164
|
-
const partnerPublicKey = partner ? new PublicKey(partner) :
|
|
164
|
+
const partnerPublicKey = partner ? new PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
|
|
165
165
|
const ixs = prepareBaseInstructions(this.connection, {
|
|
166
166
|
computePrice,
|
|
167
167
|
computeLimit,
|
|
168
168
|
});
|
|
169
169
|
if (isNative) {
|
|
170
|
-
const totalFee = await this.getTotalFee({ address:
|
|
170
|
+
const totalFee = await this.getTotalFee({ address: partnerPublicKey.toString() });
|
|
171
171
|
const totalAmount = calculateTotalAmountToDeposit(depositedAmount, totalFee);
|
|
172
172
|
ixs.push(...(await prepareWrappedAccount(this.connection, sender.publicKey, totalAmount)));
|
|
173
173
|
}
|
|
174
174
|
const createInstruction = createUncheckedStreamInstruction({
|
|
175
|
-
start:
|
|
175
|
+
start: BigNumber(start),
|
|
176
176
|
depositedAmount,
|
|
177
|
-
period:
|
|
177
|
+
period: BigNumber(period),
|
|
178
178
|
amountPerPeriod,
|
|
179
|
-
cliff:
|
|
180
|
-
cliffAmount,
|
|
179
|
+
cliff: BigNumber(cliff),
|
|
180
|
+
cliffAmount: BigNumber(cliffAmount),
|
|
181
181
|
cancelableBySender,
|
|
182
182
|
cancelableByRecipient,
|
|
183
183
|
automaticWithdrawal,
|
|
@@ -187,7 +187,7 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
187
187
|
canUpdateRate: !!canUpdateRate,
|
|
188
188
|
canPause: !!canPause,
|
|
189
189
|
name,
|
|
190
|
-
withdrawFrequency:
|
|
190
|
+
withdrawFrequency: BigNumber(automaticWithdrawal ? withdrawalFrequency : period),
|
|
191
191
|
recipient: recipientPublicKey,
|
|
192
192
|
partner: partnerPublicKey,
|
|
193
193
|
}, this.programId, {
|
|
@@ -252,7 +252,7 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
252
252
|
batch.push({ tx, recipient });
|
|
253
253
|
}
|
|
254
254
|
if (isNative) {
|
|
255
|
-
const totalDepositedAmount = recipients.reduce((acc, recipient) => recipient.amount.
|
|
255
|
+
const totalDepositedAmount = recipients.reduce((acc, recipient) => recipient.amount.plus(acc), BigNumber(0));
|
|
256
256
|
const nativeInstructions = await prepareWrappedAccount(this.connection, sender.publicKey, totalDepositedAmount);
|
|
257
257
|
const messageV0 = new TransactionMessage({
|
|
258
258
|
payerKey: sender.publicKey,
|
|
@@ -537,6 +537,22 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
537
537
|
return sortedStreams;
|
|
538
538
|
return sortedStreams.filter((stream) => stream[1].type === type);
|
|
539
539
|
}
|
|
540
|
+
async searchStreams(data) {
|
|
541
|
+
const filters = Object.entries(data)
|
|
542
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
543
|
+
.filter(([_, value]) => value) // Only keep entries where the value is truthy
|
|
544
|
+
.map(([key, value]) => ({
|
|
545
|
+
memcmp: {
|
|
546
|
+
offset: STREAM_STRUCT_OFFSETS[key],
|
|
547
|
+
bytes: value,
|
|
548
|
+
},
|
|
549
|
+
}));
|
|
550
|
+
const accounts = await this.connection.getProgramAccounts(this.programId, { filters });
|
|
551
|
+
return accounts.map(({ pubkey, account }) => ({
|
|
552
|
+
publicKey: pubkey,
|
|
553
|
+
account: new Contract(decodeStream(account.data)),
|
|
554
|
+
}));
|
|
555
|
+
}
|
|
540
556
|
/**
|
|
541
557
|
* Attempts updating the stream auto withdrawal params and amount per period
|
|
542
558
|
*/
|
|
@@ -624,12 +640,12 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
624
640
|
const partnerPublicKey = partner ? new PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
|
|
625
641
|
const partnerTokens = await ata(mintPublicKey, partnerPublicKey, tokenProgramId);
|
|
626
642
|
ixs.push(createStreamInstruction({
|
|
627
|
-
start:
|
|
643
|
+
start: BigNumber(start),
|
|
628
644
|
depositedAmount: recipient.amount,
|
|
629
|
-
period:
|
|
645
|
+
period: BigNumber(period),
|
|
630
646
|
amountPerPeriod: recipient.amountPerPeriod,
|
|
631
|
-
cliff:
|
|
632
|
-
cliffAmount: recipient.cliffAmount,
|
|
647
|
+
cliff: BigNumber(cliff),
|
|
648
|
+
cliffAmount: BigNumber(recipient.cliffAmount),
|
|
633
649
|
cancelableBySender,
|
|
634
650
|
cancelableByRecipient,
|
|
635
651
|
automaticWithdrawal,
|
|
@@ -639,7 +655,7 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
639
655
|
canUpdateRate: !!canUpdateRate,
|
|
640
656
|
canPause: !!canPause,
|
|
641
657
|
name: recipient.name,
|
|
642
|
-
withdrawFrequency:
|
|
658
|
+
withdrawFrequency: BigNumber(automaticWithdrawal ? withdrawalFrequency : period),
|
|
643
659
|
}, this.programId, {
|
|
644
660
|
sender: sender.publicKey,
|
|
645
661
|
senderTokens,
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { PublicKey } from "@solana/web3.js";
|
|
3
3
|
import { Buffer } from "buffer";
|
|
4
|
+
import { ISearchStreams } from "./types.js";
|
|
4
5
|
export declare const TX_FINALITY_CONFIRMED = "confirmed";
|
|
5
6
|
export declare const STREAM_STRUCT_OFFSET_SENDER = 49;
|
|
6
7
|
export declare const STREAM_STRUCT_OFFSET_RECIPIENT = 113;
|
|
8
|
+
export declare const STREAM_STRUCT_OFFSET_MINT = 177;
|
|
9
|
+
export declare const STREAM_STRUCT_OFFSETS: Record<keyof ISearchStreams, number>;
|
|
7
10
|
export declare const CREATE_PARAMS_PADDING = 126;
|
|
8
11
|
export declare const PROGRAM_ID: {
|
|
9
12
|
devnet: string;
|
|
@@ -4,6 +4,12 @@ import { ICluster, SolanaContractErrorCode } from "../common/types.js";
|
|
|
4
4
|
export const TX_FINALITY_CONFIRMED = "confirmed";
|
|
5
5
|
export const STREAM_STRUCT_OFFSET_SENDER = 49;
|
|
6
6
|
export const STREAM_STRUCT_OFFSET_RECIPIENT = 113;
|
|
7
|
+
export const STREAM_STRUCT_OFFSET_MINT = 177;
|
|
8
|
+
export const STREAM_STRUCT_OFFSETS = {
|
|
9
|
+
mint: STREAM_STRUCT_OFFSET_MINT,
|
|
10
|
+
recipient: STREAM_STRUCT_OFFSET_RECIPIENT,
|
|
11
|
+
sender: STREAM_STRUCT_OFFSET_SENDER,
|
|
12
|
+
};
|
|
7
13
|
// Defined: https://github.com/streamflow-finance/protocol/blob/main/programs/protocol/src/state.rs#L25
|
|
8
14
|
export const CREATE_PARAMS_PADDING = 126;
|
|
9
15
|
export const PROGRAM_ID = {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
2
|
-
import
|
|
2
|
+
import BigNumber from "bignumber.js";
|
|
3
3
|
import { IUpdateData } from "../common/types.js";
|
|
4
4
|
interface CreateStreamData {
|
|
5
|
-
start:
|
|
6
|
-
depositedAmount:
|
|
7
|
-
period:
|
|
8
|
-
amountPerPeriod:
|
|
9
|
-
cliff:
|
|
10
|
-
cliffAmount:
|
|
5
|
+
start: BigNumber;
|
|
6
|
+
depositedAmount: BigNumber;
|
|
7
|
+
period: BigNumber;
|
|
8
|
+
amountPerPeriod: BigNumber;
|
|
9
|
+
cliff: BigNumber;
|
|
10
|
+
cliffAmount: BigNumber;
|
|
11
11
|
cancelableBySender: boolean;
|
|
12
12
|
cancelableByRecipient: boolean;
|
|
13
13
|
automaticWithdrawal: boolean;
|
|
@@ -17,7 +17,7 @@ interface CreateStreamData {
|
|
|
17
17
|
canUpdateRate: boolean;
|
|
18
18
|
canPause: boolean;
|
|
19
19
|
name: string;
|
|
20
|
-
withdrawFrequency:
|
|
20
|
+
withdrawFrequency: BigNumber;
|
|
21
21
|
}
|
|
22
22
|
interface CreateStreamAccounts {
|
|
23
23
|
sender: PublicKey;
|
|
@@ -41,12 +41,12 @@ interface CreateStreamAccounts {
|
|
|
41
41
|
}
|
|
42
42
|
export declare const createStreamInstruction: (data: CreateStreamData, programId: PublicKey, accounts: CreateStreamAccounts) => TransactionInstruction;
|
|
43
43
|
interface CreateUncheckedStreamData {
|
|
44
|
-
start:
|
|
45
|
-
depositedAmount:
|
|
46
|
-
period:
|
|
47
|
-
amountPerPeriod:
|
|
48
|
-
cliff:
|
|
49
|
-
cliffAmount:
|
|
44
|
+
start: BigNumber;
|
|
45
|
+
depositedAmount: BigNumber;
|
|
46
|
+
period: BigNumber;
|
|
47
|
+
amountPerPeriod: BigNumber;
|
|
48
|
+
cliff: BigNumber;
|
|
49
|
+
cliffAmount: BigNumber;
|
|
50
50
|
cancelableBySender: boolean;
|
|
51
51
|
cancelableByRecipient: boolean;
|
|
52
52
|
automaticWithdrawal: boolean;
|
|
@@ -56,7 +56,7 @@ interface CreateUncheckedStreamData {
|
|
|
56
56
|
canUpdateRate: boolean;
|
|
57
57
|
canPause: boolean;
|
|
58
58
|
name: string;
|
|
59
|
-
withdrawFrequency:
|
|
59
|
+
withdrawFrequency: BigNumber;
|
|
60
60
|
recipient: PublicKey;
|
|
61
61
|
partner: PublicKey;
|
|
62
62
|
}
|
|
@@ -88,7 +88,7 @@ interface WithdrawAccounts {
|
|
|
88
88
|
mint: PublicKey;
|
|
89
89
|
tokenProgram: PublicKey;
|
|
90
90
|
}
|
|
91
|
-
export declare const withdrawStreamInstruction: (amount:
|
|
91
|
+
export declare const withdrawStreamInstruction: (amount: BigNumber, programId: PublicKey, { authority, recipient, recipientTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, }: WithdrawAccounts) => TransactionInstruction;
|
|
92
92
|
interface UpdateAccounts {
|
|
93
93
|
authority: PublicKey;
|
|
94
94
|
metadata: PublicKey;
|
|
@@ -138,5 +138,5 @@ interface TopupAccounts {
|
|
|
138
138
|
withdrawor: PublicKey;
|
|
139
139
|
systemProgram: PublicKey;
|
|
140
140
|
}
|
|
141
|
-
export declare const topupStreamInstruction: (amount:
|
|
141
|
+
export declare const topupStreamInstruction: (amount: BigNumber, programId: PublicKey, { sender, senderTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, withdrawor, systemProgram, }: TopupAccounts) => TransactionInstruction;
|
|
142
142
|
export {};
|
|
@@ -2,6 +2,7 @@ import { Buffer } from "buffer";
|
|
|
2
2
|
import { TransactionInstruction } from "@solana/web3.js";
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
4
|
import * as Layout from "./layout.js";
|
|
5
|
+
import { toBuffer } from "./utils.js";
|
|
5
6
|
const hasher = () => createHash("sha256");
|
|
6
7
|
const sha256 = {
|
|
7
8
|
digest: (data) => new Uint8Array(hasher().update(data).digest()),
|
|
@@ -43,12 +44,12 @@ export const createStreamInstruction = (data, programId, accounts) => {
|
|
|
43
44
|
const encodedUIntArray = new TextEncoder().encode(data.name);
|
|
44
45
|
const streamNameBuffer = Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
|
|
45
46
|
const decodedData = {
|
|
46
|
-
start_time: data.start
|
|
47
|
-
net_amount_deposited: data.depositedAmount
|
|
48
|
-
period: data.period
|
|
49
|
-
amount_per_period: data.amountPerPeriod
|
|
50
|
-
cliff: data.cliff
|
|
51
|
-
cliff_amount: data.cliffAmount
|
|
47
|
+
start_time: toBuffer(data.start),
|
|
48
|
+
net_amount_deposited: toBuffer(data.depositedAmount),
|
|
49
|
+
period: toBuffer(data.period),
|
|
50
|
+
amount_per_period: toBuffer(data.amountPerPeriod),
|
|
51
|
+
cliff: toBuffer(data.cliff),
|
|
52
|
+
cliff_amount: toBuffer(data.cliffAmount),
|
|
52
53
|
cancelable_by_sender: Number(data.cancelableBySender),
|
|
53
54
|
cancelable_by_recipient: Number(data.cancelableByRecipient),
|
|
54
55
|
automatic_withdrawal: Number(data.automaticWithdrawal),
|
|
@@ -60,7 +61,7 @@ export const createStreamInstruction = (data, programId, accounts) => {
|
|
|
60
61
|
_can_update_rate_discriminator: 1,
|
|
61
62
|
pausable: Number(data.canPause),
|
|
62
63
|
stream_name: streamNameBuffer,
|
|
63
|
-
withdraw_frequency: data.withdrawFrequency
|
|
64
|
+
withdraw_frequency: toBuffer(data.withdrawFrequency),
|
|
64
65
|
};
|
|
65
66
|
const encodeLength = Layout.createStreamLayout.encode(decodedData, bufferData);
|
|
66
67
|
bufferData = bufferData.slice(0, encodeLength);
|
|
@@ -96,12 +97,12 @@ export const createUncheckedStreamInstruction = (data, programId, accounts) => {
|
|
|
96
97
|
const encodedUIntArray = new TextEncoder().encode(data.name);
|
|
97
98
|
const streamNameBuffer = Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
|
|
98
99
|
const decodedData = {
|
|
99
|
-
start_time: data.start
|
|
100
|
-
net_amount_deposited: data.depositedAmount
|
|
101
|
-
period: data.period
|
|
102
|
-
amount_per_period: data.amountPerPeriod
|
|
103
|
-
cliff: data.cliff
|
|
104
|
-
cliff_amount: data.cliffAmount
|
|
100
|
+
start_time: toBuffer(data.start),
|
|
101
|
+
net_amount_deposited: toBuffer(data.depositedAmount),
|
|
102
|
+
period: toBuffer(data.period),
|
|
103
|
+
amount_per_period: toBuffer(data.amountPerPeriod),
|
|
104
|
+
cliff: toBuffer(data.cliff),
|
|
105
|
+
cliff_amount: toBuffer(data.cliffAmount),
|
|
105
106
|
cancelable_by_sender: Number(data.cancelableBySender),
|
|
106
107
|
cancelable_by_recipient: Number(data.cancelableByRecipient),
|
|
107
108
|
automatic_withdrawal: Number(data.automaticWithdrawal),
|
|
@@ -109,7 +110,7 @@ export const createUncheckedStreamInstruction = (data, programId, accounts) => {
|
|
|
109
110
|
transferable_by_recipient: Number(data.transferableByRecipient),
|
|
110
111
|
can_topup: Number(data.canTopup),
|
|
111
112
|
stream_name: streamNameBuffer,
|
|
112
|
-
withdraw_frequency: data.withdrawFrequency
|
|
113
|
+
withdraw_frequency: toBuffer(data.withdrawFrequency),
|
|
113
114
|
recipient: data.recipient.toBuffer(),
|
|
114
115
|
partner: data.partner.toBuffer(),
|
|
115
116
|
pausable: Number(data.canPause),
|
|
@@ -146,7 +147,7 @@ export const withdrawStreamInstruction = (amount, programId, { authority, recipi
|
|
|
146
147
|
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
147
148
|
];
|
|
148
149
|
let data = Buffer.alloc(Layout.withdrawStreamLayout.span);
|
|
149
|
-
const decodedData = { amount: amount
|
|
150
|
+
const decodedData = { amount: toBuffer(amount) };
|
|
150
151
|
const encodeLength = Layout.withdrawStreamLayout.encode(decodedData, data);
|
|
151
152
|
data = data.slice(0, encodeLength);
|
|
152
153
|
data = Buffer.concat([Buffer.from(sha256.digest("global:withdraw")).slice(0, 8), data, Buffer.alloc(10)]);
|
|
@@ -166,8 +167,8 @@ export const updateStreamInstruction = (params, programId, { authority, metadata
|
|
|
166
167
|
let data = Buffer.alloc(100);
|
|
167
168
|
const decodedData = {
|
|
168
169
|
enable_automatic_withdrawal: Number(params.enableAutomaticWithdrawal),
|
|
169
|
-
withdraw_frequency: params.withdrawFrequency ? params.withdrawFrequency
|
|
170
|
-
amount_per_period: params.amountPerPeriod ? params.amountPerPeriod
|
|
170
|
+
withdraw_frequency: params.withdrawFrequency ? toBuffer(params.withdrawFrequency) : undefined,
|
|
171
|
+
amount_per_period: params.amountPerPeriod ? toBuffer(params.amountPerPeriod) : undefined,
|
|
171
172
|
};
|
|
172
173
|
const encodeLength = Layout.encodeUpdateStream(decodedData, data);
|
|
173
174
|
data = data.slice(0, encodeLength);
|
|
@@ -244,7 +245,7 @@ export const topupStreamInstruction = (amount, programId, { sender, senderTokens
|
|
|
244
245
|
{ pubkey: systemProgram, isSigner: false, isWritable: false },
|
|
245
246
|
];
|
|
246
247
|
let data = Buffer.alloc(Layout.topupStreamLayout.span);
|
|
247
|
-
const decodedData = { amount: amount
|
|
248
|
+
const decodedData = { amount: toBuffer(amount) };
|
|
248
249
|
const encodeLength = Layout.topupStreamLayout.encode(decodedData, data);
|
|
249
250
|
data = data.slice(0, encodeLength);
|
|
250
251
|
data = Buffer.concat([Buffer.from(sha256.digest("global:topup")).slice(0, 8), data, Buffer.alloc(10)]);
|
|
@@ -2,8 +2,13 @@
|
|
|
2
2
|
import { SignerWalletAdapter } from "@solana/wallet-adapter-base";
|
|
3
3
|
import { AccountInfo, PublicKey, Keypair, VersionedTransaction } from "@solana/web3.js";
|
|
4
4
|
import { ITransactionSolanaExt } from "@streamflow/common/solana";
|
|
5
|
-
import
|
|
5
|
+
import BigNumber from "bignumber.js";
|
|
6
6
|
import { IRecipient, Stream, StreamType } from "../common/types.js";
|
|
7
|
+
export interface ISearchStreams {
|
|
8
|
+
mint?: string;
|
|
9
|
+
sender?: string;
|
|
10
|
+
recipient?: string;
|
|
11
|
+
}
|
|
7
12
|
export interface Account {
|
|
8
13
|
pubkey: PublicKey;
|
|
9
14
|
account: AccountInfo<Buffer>;
|
|
@@ -28,7 +33,7 @@ export declare class Contract implements Stream {
|
|
|
28
33
|
magic: number;
|
|
29
34
|
version: number;
|
|
30
35
|
createdAt: number;
|
|
31
|
-
withdrawnAmount:
|
|
36
|
+
withdrawnAmount: BigNumber;
|
|
32
37
|
canceledAt: number;
|
|
33
38
|
end: number;
|
|
34
39
|
lastWithdrawnAt: number;
|
|
@@ -40,20 +45,20 @@ export declare class Contract implements Stream {
|
|
|
40
45
|
escrowTokens: string;
|
|
41
46
|
streamflowTreasury: string;
|
|
42
47
|
streamflowTreasuryTokens: string;
|
|
43
|
-
streamflowFeeTotal:
|
|
44
|
-
streamflowFeeWithdrawn:
|
|
48
|
+
streamflowFeeTotal: BigNumber;
|
|
49
|
+
streamflowFeeWithdrawn: BigNumber;
|
|
45
50
|
streamflowFeePercent: number;
|
|
46
|
-
partnerFeeTotal:
|
|
47
|
-
partnerFeeWithdrawn:
|
|
51
|
+
partnerFeeTotal: BigNumber;
|
|
52
|
+
partnerFeeWithdrawn: BigNumber;
|
|
48
53
|
partnerFeePercent: number;
|
|
49
54
|
partner: string;
|
|
50
55
|
partnerTokens: string;
|
|
51
56
|
start: number;
|
|
52
|
-
depositedAmount:
|
|
57
|
+
depositedAmount: BigNumber;
|
|
53
58
|
period: number;
|
|
54
|
-
amountPerPeriod:
|
|
59
|
+
amountPerPeriod: BigNumber;
|
|
55
60
|
cliff: number;
|
|
56
|
-
cliffAmount:
|
|
61
|
+
cliffAmount: BigNumber;
|
|
57
62
|
cancelableBySender: boolean;
|
|
58
63
|
cancelableByRecipient: boolean;
|
|
59
64
|
automaticWithdrawal: boolean;
|
|
@@ -64,22 +69,22 @@ export declare class Contract implements Stream {
|
|
|
64
69
|
withdrawalFrequency: number;
|
|
65
70
|
closed: boolean;
|
|
66
71
|
currentPauseStart: number;
|
|
67
|
-
pauseCumulative:
|
|
72
|
+
pauseCumulative: BigNumber;
|
|
68
73
|
lastRateChangeTime: number;
|
|
69
|
-
fundsUnlockedAtLastRateChange:
|
|
74
|
+
fundsUnlockedAtLastRateChange: BigNumber;
|
|
70
75
|
type: StreamType;
|
|
71
76
|
constructor(stream: DecodedStream);
|
|
72
|
-
unlocked(currentTimestamp: number):
|
|
77
|
+
unlocked(currentTimestamp: number): BigNumber;
|
|
73
78
|
remaining(decimals: number): number;
|
|
74
79
|
}
|
|
75
80
|
export interface DecodedStream {
|
|
76
|
-
magic:
|
|
77
|
-
version:
|
|
78
|
-
createdAt:
|
|
79
|
-
withdrawnAmount:
|
|
80
|
-
canceledAt:
|
|
81
|
-
end:
|
|
82
|
-
lastWithdrawnAt:
|
|
81
|
+
magic: BigNumber;
|
|
82
|
+
version: BigNumber;
|
|
83
|
+
createdAt: BigNumber;
|
|
84
|
+
withdrawnAmount: BigNumber;
|
|
85
|
+
canceledAt: BigNumber;
|
|
86
|
+
end: BigNumber;
|
|
87
|
+
lastWithdrawnAt: BigNumber;
|
|
83
88
|
sender: PublicKey;
|
|
84
89
|
senderTokens: PublicKey;
|
|
85
90
|
recipient: PublicKey;
|
|
@@ -88,20 +93,20 @@ export interface DecodedStream {
|
|
|
88
93
|
escrowTokens: PublicKey;
|
|
89
94
|
streamflowTreasury: PublicKey;
|
|
90
95
|
streamflowTreasuryTokens: PublicKey;
|
|
91
|
-
streamflowFeeTotal:
|
|
92
|
-
streamflowFeeWithdrawn:
|
|
93
|
-
streamflowFeePercent:
|
|
94
|
-
partnerFeeTotal:
|
|
95
|
-
partnerFeeWithdrawn:
|
|
96
|
-
partnerFeePercent:
|
|
96
|
+
streamflowFeeTotal: BigNumber;
|
|
97
|
+
streamflowFeeWithdrawn: BigNumber;
|
|
98
|
+
streamflowFeePercent: BigNumber;
|
|
99
|
+
partnerFeeTotal: BigNumber;
|
|
100
|
+
partnerFeeWithdrawn: BigNumber;
|
|
101
|
+
partnerFeePercent: BigNumber;
|
|
97
102
|
partner: PublicKey;
|
|
98
103
|
partnerTokens: PublicKey;
|
|
99
|
-
start:
|
|
100
|
-
depositedAmount:
|
|
101
|
-
period:
|
|
102
|
-
amountPerPeriod:
|
|
103
|
-
cliff:
|
|
104
|
-
cliffAmount:
|
|
104
|
+
start: BigNumber;
|
|
105
|
+
depositedAmount: BigNumber;
|
|
106
|
+
period: BigNumber;
|
|
107
|
+
amountPerPeriod: BigNumber;
|
|
108
|
+
cliff: BigNumber;
|
|
109
|
+
cliffAmount: BigNumber;
|
|
105
110
|
cancelableBySender: boolean;
|
|
106
111
|
cancelableByRecipient: boolean;
|
|
107
112
|
automaticWithdrawal: boolean;
|
|
@@ -109,12 +114,12 @@ export interface DecodedStream {
|
|
|
109
114
|
transferableByRecipient: boolean;
|
|
110
115
|
canTopup: boolean;
|
|
111
116
|
name: string;
|
|
112
|
-
withdrawFrequency:
|
|
117
|
+
withdrawFrequency: BigNumber;
|
|
113
118
|
closed: boolean;
|
|
114
|
-
currentPauseStart:
|
|
115
|
-
pauseCumulative:
|
|
116
|
-
lastRateChangeTime:
|
|
117
|
-
fundsUnlockedAtLastRateChange:
|
|
119
|
+
currentPauseStart: BigNumber;
|
|
120
|
+
pauseCumulative: BigNumber;
|
|
121
|
+
lastRateChangeTime: BigNumber;
|
|
122
|
+
fundsUnlockedAtLastRateChange: BigNumber;
|
|
118
123
|
}
|
|
119
124
|
export interface MetadataRecipientHashMap {
|
|
120
125
|
[metadataPubKey: string]: IRecipient;
|
package/dist/esm/solana/types.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { buildStreamType, calculateUnlockedAmount } from "../common/contractUtils.js";
|
|
2
|
-
import {
|
|
2
|
+
import { getNumberFromBigNumber } from "../common/utils.js";
|
|
3
3
|
export class Contract {
|
|
4
4
|
magic;
|
|
5
5
|
version;
|
|
@@ -96,6 +96,6 @@ export class Contract {
|
|
|
96
96
|
});
|
|
97
97
|
}
|
|
98
98
|
remaining(decimals) {
|
|
99
|
-
return
|
|
99
|
+
return getNumberFromBigNumber(this.depositedAmount.minus(this.withdrawnAmount), decimals);
|
|
100
100
|
}
|
|
101
101
|
}
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
import { SignerWalletAdapter } from "@solana/wallet-adapter-base";
|
|
3
3
|
import { Connection, Keypair } from "@solana/web3.js";
|
|
4
4
|
import { ConfirmationParams, ThrottleParams } from "@streamflow/common/solana";
|
|
5
|
+
import BigNumber from "bignumber.js";
|
|
5
6
|
import { DecodedStream, BatchItem, BatchItemResult } from "./types.js";
|
|
7
|
+
export declare const toBuffer: (bigNumber: BigNumber) => Buffer;
|
|
6
8
|
export declare const decodeStream: (buf: Buffer) => DecodedStream;
|
|
7
9
|
/**
|
|
8
10
|
* Sign passed BatchItems with wallet request or KeyPair
|
package/dist/esm/solana/utils.js
CHANGED
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
|
2
2
|
import { executeTransaction, isSignerKeypair, isSignerWallet, } from "@streamflow/common/solana";
|
|
3
|
-
import
|
|
3
|
+
import BigNumber from "bignumber.js";
|
|
4
4
|
import { streamLayout } from "./layout.js";
|
|
5
5
|
import { SOLANA_ERROR_MAP, SOLANA_ERROR_MATCH_REGEX } from "./constants.js";
|
|
6
6
|
const decoder = new TextDecoder("utf-8");
|
|
7
|
-
const
|
|
7
|
+
const toUInt64String = (uintArr) => new DataView(uintArr.buffer, uintArr.byteOffset, uintArr.byteLength).getBigUint64(0, true).toString();
|
|
8
|
+
const toUInt8 = (uintArr) => new DataView(uintArr.buffer, uintArr.byteOffset, uintArr.byteLength).getUint8(0);
|
|
9
|
+
export const toBuffer = (bigNumber) => {
|
|
10
|
+
const dv = new DataView(new ArrayBuffer(8), 0);
|
|
11
|
+
dv.setBigUint64(0, BigInt(bigNumber.integerValue().toString()), true);
|
|
12
|
+
return Buffer.from(dv.buffer);
|
|
13
|
+
};
|
|
8
14
|
export const decodeStream = (buf) => {
|
|
9
15
|
const raw = streamLayout.decode(buf);
|
|
10
16
|
return {
|
|
11
|
-
magic:
|
|
12
|
-
version:
|
|
13
|
-
createdAt:
|
|
14
|
-
withdrawnAmount:
|
|
15
|
-
canceledAt:
|
|
16
|
-
end:
|
|
17
|
-
lastWithdrawnAt:
|
|
17
|
+
magic: BigNumber(toUInt64String(raw.magic)),
|
|
18
|
+
version: BigNumber(toUInt8(raw.version)),
|
|
19
|
+
createdAt: BigNumber(toUInt64String(raw.created_at)),
|
|
20
|
+
withdrawnAmount: BigNumber(toUInt64String(raw.withdrawn_amount)),
|
|
21
|
+
canceledAt: BigNumber(toUInt64String(raw.canceled_at)),
|
|
22
|
+
end: BigNumber(toUInt64String(raw.end_time)),
|
|
23
|
+
lastWithdrawnAt: BigNumber(toUInt64String(raw.last_withdrawn_at)),
|
|
18
24
|
sender: new PublicKey(raw.sender),
|
|
19
25
|
senderTokens: new PublicKey(raw.sender_tokens),
|
|
20
26
|
recipient: new PublicKey(raw.recipient),
|
|
@@ -23,20 +29,20 @@ export const decodeStream = (buf) => {
|
|
|
23
29
|
escrowTokens: new PublicKey(raw.escrow_tokens),
|
|
24
30
|
streamflowTreasury: new PublicKey(raw.streamflow_treasury),
|
|
25
31
|
streamflowTreasuryTokens: new PublicKey(raw.streamflow_treasury_tokens),
|
|
26
|
-
streamflowFeeTotal:
|
|
27
|
-
streamflowFeeWithdrawn:
|
|
28
|
-
streamflowFeePercent:
|
|
29
|
-
partnerFeeTotal:
|
|
30
|
-
partnerFeeWithdrawn:
|
|
31
|
-
partnerFeePercent:
|
|
32
|
+
streamflowFeeTotal: BigNumber(toUInt64String(raw.streamflow_fee_total)),
|
|
33
|
+
streamflowFeeWithdrawn: BigNumber(toUInt64String(raw.streamflow_fee_withdrawn)),
|
|
34
|
+
streamflowFeePercent: BigNumber(raw.streamflow_fee_percent),
|
|
35
|
+
partnerFeeTotal: BigNumber(toUInt64String(raw.partner_fee_total)),
|
|
36
|
+
partnerFeeWithdrawn: BigNumber(toUInt64String(raw.partner_fee_withdrawn)),
|
|
37
|
+
partnerFeePercent: BigNumber(raw.partner_fee_percent),
|
|
32
38
|
partner: new PublicKey(raw.partner),
|
|
33
39
|
partnerTokens: new PublicKey(raw.partner_tokens),
|
|
34
|
-
start:
|
|
35
|
-
depositedAmount:
|
|
36
|
-
period:
|
|
37
|
-
amountPerPeriod:
|
|
38
|
-
cliff:
|
|
39
|
-
cliffAmount:
|
|
40
|
+
start: BigNumber(toUInt64String(raw.start_time)),
|
|
41
|
+
depositedAmount: BigNumber(toUInt64String(raw.net_amount_deposited)),
|
|
42
|
+
period: BigNumber(toUInt64String(raw.period)),
|
|
43
|
+
amountPerPeriod: BigNumber(toUInt64String(raw.amount_per_period)),
|
|
44
|
+
cliff: BigNumber(toUInt64String(raw.cliff)),
|
|
45
|
+
cliffAmount: BigNumber(toUInt64String(raw.cliff_amount)),
|
|
40
46
|
cancelableBySender: Boolean(raw.cancelable_by_sender),
|
|
41
47
|
cancelableByRecipient: Boolean(raw.cancelable_by_recipient),
|
|
42
48
|
automaticWithdrawal: Boolean(raw.automatic_withdrawal),
|
|
@@ -44,12 +50,12 @@ export const decodeStream = (buf) => {
|
|
|
44
50
|
transferableByRecipient: Boolean(raw.transferable_by_recipient),
|
|
45
51
|
canTopup: Boolean(raw.can_topup),
|
|
46
52
|
name: decoder.decode(raw.stream_name),
|
|
47
|
-
withdrawFrequency:
|
|
53
|
+
withdrawFrequency: BigNumber(toUInt64String(raw.withdraw_frequency)),
|
|
48
54
|
closed: Boolean(raw.closed),
|
|
49
|
-
currentPauseStart:
|
|
50
|
-
pauseCumulative:
|
|
51
|
-
lastRateChangeTime:
|
|
52
|
-
fundsUnlockedAtLastRateChange:
|
|
55
|
+
currentPauseStart: BigNumber(toUInt64String(raw.current_pause_start)),
|
|
56
|
+
pauseCumulative: BigNumber(toUInt64String(raw.pause_cumulative)),
|
|
57
|
+
lastRateChangeTime: BigNumber(toUInt64String(raw.last_rate_change_time)),
|
|
58
|
+
fundsUnlockedAtLastRateChange: BigNumber(toUInt64String(raw.funds_unlocked_at_last_rate_change)),
|
|
53
59
|
};
|
|
54
60
|
};
|
|
55
61
|
/**
|
|
@@ -308,7 +308,7 @@ export default class SuiStreamClient extends BaseStreamClient {
|
|
|
308
308
|
let coins = await this.getAllCoins(walletAddress, multipleStreamData.tokenId);
|
|
309
309
|
const totalAmount = multipleStreamData.recipients
|
|
310
310
|
.map((recipiient) => recipiient.amount)
|
|
311
|
-
.reduce((prev, current) => current.
|
|
311
|
+
.reduce((prev, current) => current.plus(prev));
|
|
312
312
|
const txb = new TransactionBlock();
|
|
313
313
|
const coinObject = this.splitCoinObjectForAmount(txb, totalAmount, multipleStreamData.tokenId, coins, totalFee);
|
|
314
314
|
coins = [coins[0]];
|