@streamflow/stream 7.0.0-alpha.2 → 7.0.0-alpha.20
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 +70 -67
- 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 +28 -37
- 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 +4 -3
- package/dist/cjs/common/contractUtils.js +33 -18
- package/dist/cjs/common/types.js +30 -1
- package/dist/cjs/common/utils.js +38 -80
- 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 +759 -1090
- package/dist/cjs/solana/constants.js +44 -11
- package/dist/cjs/solana/descriptor/idl/streamflow_aligned_unlocks.json +1471 -0
- package/dist/cjs/solana/descriptor/streamflow_aligned_unlocks.js +2 -0
- package/dist/cjs/solana/index.js +2 -1
- package/dist/cjs/solana/instructions.js +75 -81
- package/dist/cjs/solana/layout.js +7 -8
- package/dist/cjs/solana/lib/derive-accounts.js +17 -0
- package/dist/cjs/solana/lib/utils.js +127 -0
- package/dist/cjs/solana/types.js +40 -27
- 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 +14 -14
- 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 +3 -2
- package/dist/esm/common/constants.js +3 -2
- package/dist/esm/common/contractUtils.d.ts +18 -15
- package/dist/esm/common/contractUtils.js +19 -6
- package/dist/esm/common/types.d.ts +112 -57
- package/dist/esm/common/types.js +29 -0
- package/dist/esm/common/utils.d.ts +11 -11
- package/dist/esm/common/utils.js +19 -16
- package/dist/esm/evm/StreamClient.d.ts +2 -2
- package/dist/esm/evm/StreamClient.js +7 -7
- package/dist/esm/evm/types.d.ts +14 -14
- 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 +24 -16
- package/dist/esm/solana/StreamClient.js +324 -156
- package/dist/esm/solana/constants.d.ts +17 -0
- package/dist/esm/solana/constants.js +35 -1
- package/dist/esm/solana/descriptor/idl/streamflow_aligned_unlocks.json +1471 -0
- package/dist/esm/solana/descriptor/streamflow_aligned_unlocks.d.ts +1272 -0
- package/dist/esm/solana/descriptor/streamflow_aligned_unlocks.js +1 -0
- package/dist/esm/solana/index.d.ts +2 -1
- package/dist/esm/solana/index.js +2 -1
- package/dist/esm/solana/instructions.d.ts +17 -17
- package/dist/esm/solana/instructions.js +18 -19
- package/dist/esm/solana/lib/derive-accounts.d.ts +4 -0
- package/dist/esm/solana/lib/derive-accounts.js +11 -0
- package/dist/esm/solana/{utils.d.ts → lib/utils.d.ts} +1 -3
- package/dist/esm/solana/{utils.js → lib/utils.js} +28 -34
- package/dist/esm/solana/types.d.ts +72 -39
- package/dist/esm/solana/types.js +32 -4
- package/dist/esm/sui/StreamClient.js +1 -1
- package/dist/esm/sui/types.d.ts +14 -14
- package/dist/esm/sui/types.js +13 -13
- package/package.json +12 -10
- package/dist/cjs/solana/utils.js +0 -222
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/esm/solana/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
2
|
-
import
|
|
2
|
+
import BN from "bn.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: BN;
|
|
6
|
+
depositedAmount: BN;
|
|
7
|
+
period: BN;
|
|
8
|
+
amountPerPeriod: BN;
|
|
9
|
+
cliff: BN;
|
|
10
|
+
cliffAmount: BN;
|
|
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: BN;
|
|
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: BN;
|
|
45
|
+
depositedAmount: BN;
|
|
46
|
+
period: BN;
|
|
47
|
+
amountPerPeriod: BN;
|
|
48
|
+
cliff: BN;
|
|
49
|
+
cliffAmount: BN;
|
|
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: BN;
|
|
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: BN, 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: BN, programId: PublicKey, { sender, senderTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, withdrawor, systemProgram, }: TopupAccounts) => TransactionInstruction;
|
|
142
142
|
export {};
|
|
@@ -2,7 +2,6 @@ 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";
|
|
6
5
|
const hasher = () => createHash("sha256");
|
|
7
6
|
const sha256 = {
|
|
8
7
|
digest: (data) => new Uint8Array(hasher().update(data).digest()),
|
|
@@ -44,12 +43,12 @@ export const createStreamInstruction = (data, programId, accounts) => {
|
|
|
44
43
|
const encodedUIntArray = new TextEncoder().encode(data.name);
|
|
45
44
|
const streamNameBuffer = Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
|
|
46
45
|
const decodedData = {
|
|
47
|
-
start_time:
|
|
48
|
-
net_amount_deposited:
|
|
49
|
-
period:
|
|
50
|
-
amount_per_period:
|
|
51
|
-
cliff:
|
|
52
|
-
cliff_amount:
|
|
46
|
+
start_time: data.start.toArrayLike(Buffer, "le", 8),
|
|
47
|
+
net_amount_deposited: data.depositedAmount.toArrayLike(Buffer, "le", 8),
|
|
48
|
+
period: data.period.toArrayLike(Buffer, "le", 8),
|
|
49
|
+
amount_per_period: data.amountPerPeriod.toArrayLike(Buffer, "le", 8),
|
|
50
|
+
cliff: data.cliff.toArrayLike(Buffer, "le", 8),
|
|
51
|
+
cliff_amount: data.cliffAmount.toArrayLike(Buffer, "le", 8),
|
|
53
52
|
cancelable_by_sender: Number(data.cancelableBySender),
|
|
54
53
|
cancelable_by_recipient: Number(data.cancelableByRecipient),
|
|
55
54
|
automatic_withdrawal: Number(data.automaticWithdrawal),
|
|
@@ -61,7 +60,7 @@ export const createStreamInstruction = (data, programId, accounts) => {
|
|
|
61
60
|
_can_update_rate_discriminator: 1,
|
|
62
61
|
pausable: Number(data.canPause),
|
|
63
62
|
stream_name: streamNameBuffer,
|
|
64
|
-
withdraw_frequency:
|
|
63
|
+
withdraw_frequency: data.withdrawFrequency.toArrayLike(Buffer, "le", 8),
|
|
65
64
|
};
|
|
66
65
|
const encodeLength = Layout.createStreamLayout.encode(decodedData, bufferData);
|
|
67
66
|
bufferData = bufferData.slice(0, encodeLength);
|
|
@@ -97,12 +96,12 @@ export const createUncheckedStreamInstruction = (data, programId, accounts) => {
|
|
|
97
96
|
const encodedUIntArray = new TextEncoder().encode(data.name);
|
|
98
97
|
const streamNameBuffer = Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
|
|
99
98
|
const decodedData = {
|
|
100
|
-
start_time:
|
|
101
|
-
net_amount_deposited:
|
|
102
|
-
period:
|
|
103
|
-
amount_per_period:
|
|
104
|
-
cliff:
|
|
105
|
-
cliff_amount:
|
|
99
|
+
start_time: data.start.toArrayLike(Buffer, "le", 8),
|
|
100
|
+
net_amount_deposited: data.depositedAmount.toArrayLike(Buffer, "le", 8),
|
|
101
|
+
period: data.period.toArrayLike(Buffer, "le", 8),
|
|
102
|
+
amount_per_period: data.amountPerPeriod.toArrayLike(Buffer, "le", 8),
|
|
103
|
+
cliff: data.cliff.toArrayLike(Buffer, "le", 8),
|
|
104
|
+
cliff_amount: data.cliffAmount.toArrayLike(Buffer, "le", 8),
|
|
106
105
|
cancelable_by_sender: Number(data.cancelableBySender),
|
|
107
106
|
cancelable_by_recipient: Number(data.cancelableByRecipient),
|
|
108
107
|
automatic_withdrawal: Number(data.automaticWithdrawal),
|
|
@@ -110,7 +109,7 @@ export const createUncheckedStreamInstruction = (data, programId, accounts) => {
|
|
|
110
109
|
transferable_by_recipient: Number(data.transferableByRecipient),
|
|
111
110
|
can_topup: Number(data.canTopup),
|
|
112
111
|
stream_name: streamNameBuffer,
|
|
113
|
-
withdraw_frequency:
|
|
112
|
+
withdraw_frequency: data.withdrawFrequency.toArrayLike(Buffer, "le", 8),
|
|
114
113
|
recipient: data.recipient.toBuffer(),
|
|
115
114
|
partner: data.partner.toBuffer(),
|
|
116
115
|
pausable: Number(data.canPause),
|
|
@@ -147,7 +146,7 @@ export const withdrawStreamInstruction = (amount, programId, { authority, recipi
|
|
|
147
146
|
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
148
147
|
];
|
|
149
148
|
let data = Buffer.alloc(Layout.withdrawStreamLayout.span);
|
|
150
|
-
const decodedData = { amount:
|
|
149
|
+
const decodedData = { amount: amount.toArrayLike(Buffer, "le", 8) };
|
|
151
150
|
const encodeLength = Layout.withdrawStreamLayout.encode(decodedData, data);
|
|
152
151
|
data = data.slice(0, encodeLength);
|
|
153
152
|
data = Buffer.concat([Buffer.from(sha256.digest("global:withdraw")).slice(0, 8), data, Buffer.alloc(10)]);
|
|
@@ -167,8 +166,8 @@ export const updateStreamInstruction = (params, programId, { authority, metadata
|
|
|
167
166
|
let data = Buffer.alloc(100);
|
|
168
167
|
const decodedData = {
|
|
169
168
|
enable_automatic_withdrawal: Number(params.enableAutomaticWithdrawal),
|
|
170
|
-
withdraw_frequency: params.withdrawFrequency ?
|
|
171
|
-
amount_per_period: params.amountPerPeriod ?
|
|
169
|
+
withdraw_frequency: params.withdrawFrequency ? params.withdrawFrequency.toArrayLike(Buffer, "le", 8) : undefined,
|
|
170
|
+
amount_per_period: params.amountPerPeriod ? params.amountPerPeriod.toArrayLike(Buffer, "le", 8) : undefined,
|
|
172
171
|
};
|
|
173
172
|
const encodeLength = Layout.encodeUpdateStream(decodedData, data);
|
|
174
173
|
data = data.slice(0, encodeLength);
|
|
@@ -245,7 +244,7 @@ export const topupStreamInstruction = (amount, programId, { sender, senderTokens
|
|
|
245
244
|
{ pubkey: systemProgram, isSigner: false, isWritable: false },
|
|
246
245
|
];
|
|
247
246
|
let data = Buffer.alloc(Layout.topupStreamLayout.span);
|
|
248
|
-
const decodedData = { amount:
|
|
247
|
+
const decodedData = { amount: amount.toArrayLike(Buffer, "le", 8) };
|
|
249
248
|
const encodeLength = Layout.topupStreamLayout.encode(decodedData, data);
|
|
250
249
|
data = data.slice(0, encodeLength);
|
|
251
250
|
data = Buffer.concat([Buffer.from(sha256.digest("global:topup")).slice(0, 8), data, Buffer.alloc(10)]);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
export declare const deriveContractPDA: (programId: PublicKey, streamMetadata: PublicKey) => PublicKey;
|
|
3
|
+
export declare const deriveEscrowPDA: (programId: PublicKey, streamMetadata: PublicKey) => PublicKey;
|
|
4
|
+
export declare const deriveTestOraclePDA: (programId: PublicKey, mint: PublicKey, creator: PublicKey) => PublicKey;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
import { CONTRACT_SEED, ESCROW_SEED, TEST_ORACLE_SEED } from "../constants";
|
|
3
|
+
export const deriveContractPDA = (programId, streamMetadata) => {
|
|
4
|
+
return PublicKey.findProgramAddressSync([CONTRACT_SEED, streamMetadata.toBuffer()], programId)[0];
|
|
5
|
+
};
|
|
6
|
+
export const deriveEscrowPDA = (programId, streamMetadata) => {
|
|
7
|
+
return PublicKey.findProgramAddressSync([ESCROW_SEED, streamMetadata.toBuffer()], programId)[0];
|
|
8
|
+
};
|
|
9
|
+
export const deriveTestOraclePDA = (programId, mint, creator) => {
|
|
10
|
+
return PublicKey.findProgramAddressSync([TEST_ORACLE_SEED, mint.toBuffer(), creator.toBuffer()], programId)[0];
|
|
11
|
+
};
|
|
@@ -2,9 +2,7 @@
|
|
|
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
|
|
6
|
-
import { DecodedStream, BatchItem, BatchItemResult } from "./types.js";
|
|
7
|
-
export declare const toBuffer: (bigNumber: BigNumber) => Buffer;
|
|
5
|
+
import { DecodedStream, BatchItem, BatchItemResult } from "../types.js";
|
|
8
6
|
export declare const decodeStream: (buf: Buffer) => DecodedStream;
|
|
9
7
|
/**
|
|
10
8
|
* Sign passed BatchItems with wallet request or KeyPair
|
|
@@ -1,26 +1,20 @@
|
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
|
2
2
|
import { executeTransaction, isSignerKeypair, isSignerWallet, } from "@streamflow/common/solana";
|
|
3
|
-
import
|
|
4
|
-
import { streamLayout } from "
|
|
5
|
-
import { SOLANA_ERROR_MAP, SOLANA_ERROR_MATCH_REGEX } from "
|
|
3
|
+
import BN from "bn.js";
|
|
4
|
+
import { streamLayout } from "../layout.js";
|
|
5
|
+
import { SOLANA_ERROR_MAP, SOLANA_ERROR_MATCH_REGEX } from "../constants.js";
|
|
6
6
|
const decoder = new TextDecoder("utf-8");
|
|
7
|
-
const
|
|
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
|
-
};
|
|
7
|
+
const LE = "le"; //little endian
|
|
14
8
|
export const decodeStream = (buf) => {
|
|
15
9
|
const raw = streamLayout.decode(buf);
|
|
16
10
|
return {
|
|
17
|
-
magic:
|
|
18
|
-
version:
|
|
19
|
-
createdAt:
|
|
20
|
-
withdrawnAmount:
|
|
21
|
-
canceledAt:
|
|
22
|
-
end:
|
|
23
|
-
lastWithdrawnAt:
|
|
11
|
+
magic: new BN(raw.magic, LE),
|
|
12
|
+
version: new BN(raw.version, LE),
|
|
13
|
+
createdAt: new BN(raw.created_at, LE),
|
|
14
|
+
withdrawnAmount: new BN(raw.withdrawn_amount, LE),
|
|
15
|
+
canceledAt: new BN(raw.canceled_at, LE),
|
|
16
|
+
end: new BN(raw.end_time, LE),
|
|
17
|
+
lastWithdrawnAt: new BN(raw.last_withdrawn_at, LE),
|
|
24
18
|
sender: new PublicKey(raw.sender),
|
|
25
19
|
senderTokens: new PublicKey(raw.sender_tokens),
|
|
26
20
|
recipient: new PublicKey(raw.recipient),
|
|
@@ -29,20 +23,20 @@ export const decodeStream = (buf) => {
|
|
|
29
23
|
escrowTokens: new PublicKey(raw.escrow_tokens),
|
|
30
24
|
streamflowTreasury: new PublicKey(raw.streamflow_treasury),
|
|
31
25
|
streamflowTreasuryTokens: new PublicKey(raw.streamflow_treasury_tokens),
|
|
32
|
-
streamflowFeeTotal:
|
|
33
|
-
streamflowFeeWithdrawn:
|
|
34
|
-
streamflowFeePercent:
|
|
35
|
-
partnerFeeTotal:
|
|
36
|
-
partnerFeeWithdrawn:
|
|
37
|
-
partnerFeePercent:
|
|
26
|
+
streamflowFeeTotal: new BN(raw.streamflow_fee_total, LE),
|
|
27
|
+
streamflowFeeWithdrawn: new BN(raw.streamflow_fee_withdrawn, LE),
|
|
28
|
+
streamflowFeePercent: new BN(raw.streamflow_fee_percent, LE),
|
|
29
|
+
partnerFeeTotal: new BN(raw.partner_fee_total, LE),
|
|
30
|
+
partnerFeeWithdrawn: new BN(raw.partner_fee_withdrawn, LE),
|
|
31
|
+
partnerFeePercent: new BN(raw.partner_fee_percent, LE),
|
|
38
32
|
partner: new PublicKey(raw.partner),
|
|
39
33
|
partnerTokens: new PublicKey(raw.partner_tokens),
|
|
40
|
-
start:
|
|
41
|
-
depositedAmount:
|
|
42
|
-
period:
|
|
43
|
-
amountPerPeriod:
|
|
44
|
-
cliff:
|
|
45
|
-
cliffAmount:
|
|
34
|
+
start: new BN(raw.start_time, LE),
|
|
35
|
+
depositedAmount: new BN(raw.net_amount_deposited, LE),
|
|
36
|
+
period: new BN(raw.period, LE),
|
|
37
|
+
amountPerPeriod: new BN(raw.amount_per_period, LE),
|
|
38
|
+
cliff: new BN(raw.cliff, LE),
|
|
39
|
+
cliffAmount: new BN(raw.cliff_amount, LE),
|
|
46
40
|
cancelableBySender: Boolean(raw.cancelable_by_sender),
|
|
47
41
|
cancelableByRecipient: Boolean(raw.cancelable_by_recipient),
|
|
48
42
|
automaticWithdrawal: Boolean(raw.automatic_withdrawal),
|
|
@@ -50,12 +44,12 @@ export const decodeStream = (buf) => {
|
|
|
50
44
|
transferableByRecipient: Boolean(raw.transferable_by_recipient),
|
|
51
45
|
canTopup: Boolean(raw.can_topup),
|
|
52
46
|
name: decoder.decode(raw.stream_name),
|
|
53
|
-
withdrawFrequency:
|
|
47
|
+
withdrawFrequency: new BN(raw.withdraw_frequency, LE),
|
|
54
48
|
closed: Boolean(raw.closed),
|
|
55
|
-
currentPauseStart:
|
|
56
|
-
pauseCumulative:
|
|
57
|
-
lastRateChangeTime:
|
|
58
|
-
fundsUnlockedAtLastRateChange:
|
|
49
|
+
currentPauseStart: new BN(raw.current_pause_start, LE),
|
|
50
|
+
pauseCumulative: new BN(raw.pause_cumulative, LE),
|
|
51
|
+
lastRateChangeTime: new BN(raw.last_rate_change_time, LE),
|
|
52
|
+
fundsUnlockedAtLastRateChange: new BN(raw.funds_unlocked_at_last_rate_change, LE),
|
|
59
53
|
};
|
|
60
54
|
};
|
|
61
55
|
/**
|
|
@@ -1,9 +1,25 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { SignerWalletAdapter } from "@solana/wallet-adapter-base";
|
|
3
|
-
import { AccountInfo, PublicKey, Keypair, VersionedTransaction } from "@solana/web3.js";
|
|
3
|
+
import { AccountInfo, PublicKey, Keypair, VersionedTransaction, TransactionInstruction } from "@solana/web3.js";
|
|
4
4
|
import { ITransactionSolanaExt } from "@streamflow/common/solana";
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
5
|
+
import BN from "bn.js";
|
|
6
|
+
import { type IdlTypes } from "@coral-xyz/anchor";
|
|
7
|
+
import { AlignedStream, IRecipient, LinearStream, OracleTypeName, StreamType } from "../common/types.js";
|
|
8
|
+
import { StreamflowAlignedUnlocks as AlignedUnlocksIDL } from "./descriptor/streamflow_aligned_unlocks.js";
|
|
9
|
+
export { IChain, ICluster, ContractError } from "@streamflow/common";
|
|
10
|
+
type AlignedUnlocksTypes = IdlTypes<AlignedUnlocksIDL>;
|
|
11
|
+
export type AlignedUnlocksContract = AlignedUnlocksTypes["contract"];
|
|
12
|
+
export type OracleType = AlignedUnlocksTypes["oracleType"];
|
|
13
|
+
export type TestOracle = AlignedUnlocksTypes["testOracle"];
|
|
14
|
+
export type CreateParams = AlignedUnlocksTypes["createParams"];
|
|
15
|
+
export type ChangeOracleParams = AlignedUnlocksTypes["changeOracleParams"];
|
|
16
|
+
export type CreateTestOracleParams = AlignedUnlocksTypes["createTestOracleParams"];
|
|
17
|
+
export type UpdateTestOracleParams = AlignedUnlocksTypes["updateTestOracleParams"];
|
|
18
|
+
export interface ISearchStreams {
|
|
19
|
+
mint?: string;
|
|
20
|
+
sender?: string;
|
|
21
|
+
recipient?: string;
|
|
22
|
+
}
|
|
7
23
|
export interface Account {
|
|
8
24
|
pubkey: PublicKey;
|
|
9
25
|
account: AccountInfo<Buffer>;
|
|
@@ -24,11 +40,16 @@ export interface ITopUpStreamSolanaExt extends ITransactionSolanaExt {
|
|
|
24
40
|
invoker: SignerWalletAdapter | Keypair;
|
|
25
41
|
isNative?: boolean;
|
|
26
42
|
}
|
|
27
|
-
export
|
|
43
|
+
export interface ICreateStreamInstructions {
|
|
44
|
+
ixs: TransactionInstruction[];
|
|
45
|
+
metadata: Keypair | undefined;
|
|
46
|
+
metadataPubKey: PublicKey;
|
|
47
|
+
}
|
|
48
|
+
export declare class Contract implements LinearStream {
|
|
28
49
|
magic: number;
|
|
29
50
|
version: number;
|
|
30
51
|
createdAt: number;
|
|
31
|
-
withdrawnAmount:
|
|
52
|
+
withdrawnAmount: BN;
|
|
32
53
|
canceledAt: number;
|
|
33
54
|
end: number;
|
|
34
55
|
lastWithdrawnAt: number;
|
|
@@ -40,20 +61,20 @@ export declare class Contract implements Stream {
|
|
|
40
61
|
escrowTokens: string;
|
|
41
62
|
streamflowTreasury: string;
|
|
42
63
|
streamflowTreasuryTokens: string;
|
|
43
|
-
streamflowFeeTotal:
|
|
44
|
-
streamflowFeeWithdrawn:
|
|
64
|
+
streamflowFeeTotal: BN;
|
|
65
|
+
streamflowFeeWithdrawn: BN;
|
|
45
66
|
streamflowFeePercent: number;
|
|
46
|
-
partnerFeeTotal:
|
|
47
|
-
partnerFeeWithdrawn:
|
|
67
|
+
partnerFeeTotal: BN;
|
|
68
|
+
partnerFeeWithdrawn: BN;
|
|
48
69
|
partnerFeePercent: number;
|
|
49
70
|
partner: string;
|
|
50
71
|
partnerTokens: string;
|
|
51
72
|
start: number;
|
|
52
|
-
depositedAmount:
|
|
73
|
+
depositedAmount: BN;
|
|
53
74
|
period: number;
|
|
54
|
-
amountPerPeriod:
|
|
75
|
+
amountPerPeriod: BN;
|
|
55
76
|
cliff: number;
|
|
56
|
-
cliffAmount:
|
|
77
|
+
cliffAmount: BN;
|
|
57
78
|
cancelableBySender: boolean;
|
|
58
79
|
cancelableByRecipient: boolean;
|
|
59
80
|
automaticWithdrawal: boolean;
|
|
@@ -64,22 +85,34 @@ export declare class Contract implements Stream {
|
|
|
64
85
|
withdrawalFrequency: number;
|
|
65
86
|
closed: boolean;
|
|
66
87
|
currentPauseStart: number;
|
|
67
|
-
pauseCumulative:
|
|
88
|
+
pauseCumulative: BN;
|
|
68
89
|
lastRateChangeTime: number;
|
|
69
|
-
fundsUnlockedAtLastRateChange:
|
|
90
|
+
fundsUnlockedAtLastRateChange: BN;
|
|
70
91
|
type: StreamType;
|
|
92
|
+
isAligned?: boolean;
|
|
71
93
|
constructor(stream: DecodedStream);
|
|
72
|
-
unlocked(currentTimestamp: number):
|
|
94
|
+
unlocked(currentTimestamp: number): BN;
|
|
73
95
|
remaining(decimals: number): number;
|
|
74
96
|
}
|
|
97
|
+
export declare class AlignedContract extends Contract implements AlignedStream {
|
|
98
|
+
minPrice: number;
|
|
99
|
+
maxPrice: number;
|
|
100
|
+
minPercentage: number;
|
|
101
|
+
maxPercentage: number;
|
|
102
|
+
tickSize: number;
|
|
103
|
+
proxyAddress: string;
|
|
104
|
+
priceOracle: string | undefined;
|
|
105
|
+
oracleType: OracleTypeName;
|
|
106
|
+
constructor(stream: DecodedStream, alignedProxy: AlignedUnlocksContract);
|
|
107
|
+
}
|
|
75
108
|
export interface DecodedStream {
|
|
76
|
-
magic:
|
|
77
|
-
version:
|
|
78
|
-
createdAt:
|
|
79
|
-
withdrawnAmount:
|
|
80
|
-
canceledAt:
|
|
81
|
-
end:
|
|
82
|
-
lastWithdrawnAt:
|
|
109
|
+
magic: BN;
|
|
110
|
+
version: BN;
|
|
111
|
+
createdAt: BN;
|
|
112
|
+
withdrawnAmount: BN;
|
|
113
|
+
canceledAt: BN;
|
|
114
|
+
end: BN;
|
|
115
|
+
lastWithdrawnAt: BN;
|
|
83
116
|
sender: PublicKey;
|
|
84
117
|
senderTokens: PublicKey;
|
|
85
118
|
recipient: PublicKey;
|
|
@@ -88,20 +121,20 @@ export interface DecodedStream {
|
|
|
88
121
|
escrowTokens: PublicKey;
|
|
89
122
|
streamflowTreasury: PublicKey;
|
|
90
123
|
streamflowTreasuryTokens: PublicKey;
|
|
91
|
-
streamflowFeeTotal:
|
|
92
|
-
streamflowFeeWithdrawn:
|
|
93
|
-
streamflowFeePercent:
|
|
94
|
-
partnerFeeTotal:
|
|
95
|
-
partnerFeeWithdrawn:
|
|
96
|
-
partnerFeePercent:
|
|
124
|
+
streamflowFeeTotal: BN;
|
|
125
|
+
streamflowFeeWithdrawn: BN;
|
|
126
|
+
streamflowFeePercent: BN;
|
|
127
|
+
partnerFeeTotal: BN;
|
|
128
|
+
partnerFeeWithdrawn: BN;
|
|
129
|
+
partnerFeePercent: BN;
|
|
97
130
|
partner: PublicKey;
|
|
98
131
|
partnerTokens: PublicKey;
|
|
99
|
-
start:
|
|
100
|
-
depositedAmount:
|
|
101
|
-
period:
|
|
102
|
-
amountPerPeriod:
|
|
103
|
-
cliff:
|
|
104
|
-
cliffAmount:
|
|
132
|
+
start: BN;
|
|
133
|
+
depositedAmount: BN;
|
|
134
|
+
period: BN;
|
|
135
|
+
amountPerPeriod: BN;
|
|
136
|
+
cliff: BN;
|
|
137
|
+
cliffAmount: BN;
|
|
105
138
|
cancelableBySender: boolean;
|
|
106
139
|
cancelableByRecipient: boolean;
|
|
107
140
|
automaticWithdrawal: boolean;
|
|
@@ -109,12 +142,12 @@ export interface DecodedStream {
|
|
|
109
142
|
transferableByRecipient: boolean;
|
|
110
143
|
canTopup: boolean;
|
|
111
144
|
name: string;
|
|
112
|
-
withdrawFrequency:
|
|
145
|
+
withdrawFrequency: BN;
|
|
113
146
|
closed: boolean;
|
|
114
|
-
currentPauseStart:
|
|
115
|
-
pauseCumulative:
|
|
116
|
-
lastRateChangeTime:
|
|
117
|
-
fundsUnlockedAtLastRateChange:
|
|
147
|
+
currentPauseStart: BN;
|
|
148
|
+
pauseCumulative: BN;
|
|
149
|
+
lastRateChangeTime: BN;
|
|
150
|
+
fundsUnlockedAtLastRateChange: BN;
|
|
118
151
|
}
|
|
119
152
|
export interface MetadataRecipientHashMap {
|
|
120
153
|
[metadataPubKey: string]: IRecipient;
|
package/dist/esm/solana/types.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { buildStreamType, calculateUnlockedAmount } from "../common/contractUtils.js";
|
|
2
|
-
import {
|
|
1
|
+
import { buildStreamType, calculateUnlockedAmount, decodeEndTime } from "../common/contractUtils.js";
|
|
2
|
+
import { getNumberFromBN } from "../common/utils.js";
|
|
3
|
+
import { ALIGNED_PRECISION_FACTOR_POW } from "./constants.js";
|
|
4
|
+
export { IChain, ICluster, ContractError } from "@streamflow/common";
|
|
3
5
|
export class Contract {
|
|
4
6
|
magic;
|
|
5
7
|
version;
|
|
@@ -44,13 +46,15 @@ export class Contract {
|
|
|
44
46
|
lastRateChangeTime;
|
|
45
47
|
fundsUnlockedAtLastRateChange;
|
|
46
48
|
type;
|
|
49
|
+
isAligned;
|
|
47
50
|
constructor(stream) {
|
|
48
51
|
this.magic = stream.magic.toNumber();
|
|
49
52
|
this.version = stream.version.toNumber();
|
|
50
53
|
this.createdAt = stream.createdAt.toNumber();
|
|
51
54
|
this.withdrawnAmount = stream.withdrawnAmount;
|
|
52
55
|
this.canceledAt = stream.canceledAt.toNumber();
|
|
53
|
-
|
|
56
|
+
// for aligned contracts end time can be an invalid timeValue
|
|
57
|
+
this.end = decodeEndTime(stream.end);
|
|
54
58
|
this.lastWithdrawnAt = stream.lastWithdrawnAt.toNumber();
|
|
55
59
|
this.sender = stream.sender.toBase58();
|
|
56
60
|
this.senderTokens = stream.senderTokens.toBase58();
|
|
@@ -88,6 +92,7 @@ export class Contract {
|
|
|
88
92
|
this.lastRateChangeTime = stream.lastRateChangeTime.toNumber();
|
|
89
93
|
this.fundsUnlockedAtLastRateChange = stream.fundsUnlockedAtLastRateChange;
|
|
90
94
|
this.type = buildStreamType(this);
|
|
95
|
+
this.isAligned = false;
|
|
91
96
|
}
|
|
92
97
|
unlocked(currentTimestamp) {
|
|
93
98
|
return calculateUnlockedAmount({
|
|
@@ -96,6 +101,29 @@ export class Contract {
|
|
|
96
101
|
});
|
|
97
102
|
}
|
|
98
103
|
remaining(decimals) {
|
|
99
|
-
return
|
|
104
|
+
return getNumberFromBN(this.depositedAmount.sub(this.withdrawnAmount), decimals);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
export class AlignedContract extends Contract {
|
|
108
|
+
minPrice;
|
|
109
|
+
maxPrice;
|
|
110
|
+
minPercentage;
|
|
111
|
+
maxPercentage;
|
|
112
|
+
tickSize;
|
|
113
|
+
proxyAddress;
|
|
114
|
+
priceOracle;
|
|
115
|
+
oracleType;
|
|
116
|
+
constructor(stream, alignedProxy) {
|
|
117
|
+
super(stream);
|
|
118
|
+
this.minPrice = getNumberFromBN(alignedProxy.minPrice, ALIGNED_PRECISION_FACTOR_POW);
|
|
119
|
+
this.maxPrice = getNumberFromBN(alignedProxy.maxPrice, ALIGNED_PRECISION_FACTOR_POW);
|
|
120
|
+
this.minPercentage = getNumberFromBN(alignedProxy.minPercentage, ALIGNED_PRECISION_FACTOR_POW);
|
|
121
|
+
this.maxPercentage = getNumberFromBN(alignedProxy.maxPercentage, ALIGNED_PRECISION_FACTOR_POW);
|
|
122
|
+
this.oracleType = (Object.keys(alignedProxy.priceOracleType).find((key) => !!key) || "none");
|
|
123
|
+
this.tickSize = alignedProxy.tickSize.toNumber();
|
|
124
|
+
this.priceOracle = this.oracleType === "none" ? undefined : alignedProxy.priceOracle.toBase58();
|
|
125
|
+
this.sender = alignedProxy.sender.toBase58();
|
|
126
|
+
this.canceledAt = alignedProxy.streamCanceledTime.toNumber();
|
|
127
|
+
this.proxyAddress = stream.sender.toBase58();
|
|
100
128
|
}
|
|
101
129
|
}
|
|
@@ -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.add(prev));
|
|
312
312
|
const txb = new TransactionBlock();
|
|
313
313
|
const coinObject = this.splitCoinObjectForAmount(txb, totalAmount, multipleStreamData.tokenId, coins, totalFee);
|
|
314
314
|
coins = [coins[0]];
|
package/dist/esm/sui/types.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { Keypair } from "@mysten/sui.js/cryptography";
|
|
|
2
2
|
import { WalletContextState } from "@suiet/wallet-kit";
|
|
3
3
|
import { TransactionBlock } from "@mysten/sui.js/transactions";
|
|
4
4
|
import { ExecuteTransactionRequestType, SuiTransactionBlockResponseOptions } from "@mysten/sui.js/client";
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
5
|
+
import BN from "bn.js";
|
|
6
|
+
import { LinearStream, StreamType } from "../common/types.js";
|
|
7
7
|
export interface ICreateStreamSuiExt {
|
|
8
8
|
senderWallet: WalletContextState | Keypair;
|
|
9
9
|
}
|
|
@@ -102,11 +102,11 @@ export interface FeeValueResource {
|
|
|
102
102
|
};
|
|
103
103
|
};
|
|
104
104
|
}
|
|
105
|
-
export declare class Contract implements
|
|
105
|
+
export declare class Contract implements LinearStream {
|
|
106
106
|
magic: number;
|
|
107
107
|
version: number;
|
|
108
108
|
createdAt: number;
|
|
109
|
-
withdrawnAmount:
|
|
109
|
+
withdrawnAmount: BN;
|
|
110
110
|
canceledAt: number;
|
|
111
111
|
end: number;
|
|
112
112
|
lastWithdrawnAt: number;
|
|
@@ -118,20 +118,20 @@ export declare class Contract implements Stream {
|
|
|
118
118
|
escrowTokens: string;
|
|
119
119
|
streamflowTreasury: string;
|
|
120
120
|
streamflowTreasuryTokens: string;
|
|
121
|
-
streamflowFeeTotal:
|
|
122
|
-
streamflowFeeWithdrawn:
|
|
121
|
+
streamflowFeeTotal: BN;
|
|
122
|
+
streamflowFeeWithdrawn: BN;
|
|
123
123
|
streamflowFeePercent: number;
|
|
124
|
-
partnerFeeTotal:
|
|
125
|
-
partnerFeeWithdrawn:
|
|
124
|
+
partnerFeeTotal: BN;
|
|
125
|
+
partnerFeeWithdrawn: BN;
|
|
126
126
|
partnerFeePercent: number;
|
|
127
127
|
partner: string;
|
|
128
128
|
partnerTokens: string;
|
|
129
129
|
start: number;
|
|
130
|
-
depositedAmount:
|
|
130
|
+
depositedAmount: BN;
|
|
131
131
|
period: number;
|
|
132
|
-
amountPerPeriod:
|
|
132
|
+
amountPerPeriod: BN;
|
|
133
133
|
cliff: number;
|
|
134
|
-
cliffAmount:
|
|
134
|
+
cliffAmount: BN;
|
|
135
135
|
cancelableBySender: boolean;
|
|
136
136
|
cancelableByRecipient: boolean;
|
|
137
137
|
automaticWithdrawal: boolean;
|
|
@@ -142,12 +142,12 @@ export declare class Contract implements Stream {
|
|
|
142
142
|
withdrawalFrequency: number;
|
|
143
143
|
closed: boolean;
|
|
144
144
|
currentPauseStart: number;
|
|
145
|
-
pauseCumulative:
|
|
145
|
+
pauseCumulative: BN;
|
|
146
146
|
lastRateChangeTime: number;
|
|
147
|
-
fundsUnlockedAtLastRateChange:
|
|
147
|
+
fundsUnlockedAtLastRateChange: BN;
|
|
148
148
|
type: StreamType;
|
|
149
149
|
constructor(stream: StreamResource, tokenId: string);
|
|
150
|
-
unlocked(currentTimestamp: number):
|
|
150
|
+
unlocked(currentTimestamp: number): BN;
|
|
151
151
|
remaining(decimals: number): number;
|
|
152
152
|
}
|
|
153
153
|
export interface SuiParsedError {
|