@streamflow/stream 7.0.0-alpha.10 → 7.0.0-alpha.12
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 +15 -15
- package/dist/cjs/__tests__/aptos/streamClient.spec.js +4 -4
- package/dist/cjs/aptos/types.js +12 -12
- package/dist/cjs/common/constants.js +2 -2
- package/dist/cjs/common/contractUtils.js +6 -6
- package/dist/cjs/common/utils.js +22 -19
- package/dist/cjs/evm/StreamClient.js +7 -7
- package/dist/cjs/evm/types.js +12 -12
- package/dist/cjs/solana/StreamClient.js +19 -19
- package/dist/cjs/solana/instructions.js +18 -19
- package/dist/cjs/solana/types.js +1 -1
- package/dist/cjs/solana/utils.js +27 -34
- package/dist/cjs/sui/StreamClient.js +1 -1
- package/dist/cjs/sui/types.js +12 -12
- package/dist/esm/__tests__/aptos/streamClient.spec.js +4 -4
- package/dist/esm/aptos/types.d.ts +12 -12
- package/dist/esm/aptos/types.js +13 -13
- 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 +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 +12 -12
- package/dist/esm/evm/types.js +13 -13
- package/dist/esm/solana/StreamClient.js +19 -19
- package/dist/esm/solana/instructions.d.ts +17 -17
- package/dist/esm/solana/instructions.js +18 -19
- package/dist/esm/solana/types.d.ts +36 -36
- package/dist/esm/solana/types.js +2 -2
- package/dist/esm/solana/utils.d.ts +0 -2
- package/dist/esm/solana/utils.js +26 -32
- 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 +6 -5
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ethers } from "ethers";
|
|
2
|
-
import
|
|
2
|
+
import BN from "bn.js";
|
|
3
3
|
import { toChecksumAddress } from "ethereum-checksum-address";
|
|
4
4
|
import { BaseStreamClient } from "../common/BaseStreamClient.js";
|
|
5
5
|
import { IChain, ICluster, StreamDirection, } from "../common/types.js";
|
|
@@ -49,7 +49,7 @@ export default class EvmStreamClient extends BaseStreamClient {
|
|
|
49
49
|
};
|
|
50
50
|
const fees = await this.readContract.getWithdrawalFees(...this.getFeeParams(multiParams));
|
|
51
51
|
const args = (await this.generateMultiPayloads(multiParams))[0];
|
|
52
|
-
const sum = streamData.amount.
|
|
52
|
+
const sum = streamData.amount.mul(new BN(BASE_FEE)).div(new BN(1000000));
|
|
53
53
|
await this.approveTokens(streamData.tokenId, sum);
|
|
54
54
|
const result = await this.writeContract.create(...args, {
|
|
55
55
|
value: fees.value,
|
|
@@ -66,9 +66,9 @@ export default class EvmStreamClient extends BaseStreamClient {
|
|
|
66
66
|
const fees = await this.readContract.getWithdrawalFees(...this.getFeeParams(multipleStreamData));
|
|
67
67
|
const args = await this.generateMultiPayloads(multipleStreamData);
|
|
68
68
|
const sum = multipleStreamData.recipients
|
|
69
|
-
.reduce((acc, v) => acc.
|
|
70
|
-
.
|
|
71
|
-
.div(
|
|
69
|
+
.reduce((acc, v) => acc.add(v.amount), new BN(0))
|
|
70
|
+
.mul(new BN(BASE_FEE))
|
|
71
|
+
.div(new BN(1000000));
|
|
72
72
|
await this.approveTokens(multipleStreamData.tokenId, sum);
|
|
73
73
|
const creationPromises = args.map((item) => this.writeContract.create(...item, { value: fees.value }));
|
|
74
74
|
const signatures = [];
|
|
@@ -120,7 +120,7 @@ export default class EvmStreamClient extends BaseStreamClient {
|
|
|
120
120
|
}
|
|
121
121
|
async topup(topupData) {
|
|
122
122
|
const fees = await this.readContract.getTopUpWithdrawalFees(topupData.id, topupData.amount.toString());
|
|
123
|
-
const sum = topupData.amount.
|
|
123
|
+
const sum = topupData.amount.mul(new BN(BASE_FEE)).div(new BN(1000000));
|
|
124
124
|
const stream = await this.getOne({ id: topupData.id });
|
|
125
125
|
await this.approveTokens(stream.mint, sum);
|
|
126
126
|
const result = await this.writeContract.topUp(topupData.id, topupData.amount.toString(), {
|
|
@@ -185,7 +185,7 @@ export default class EvmStreamClient extends BaseStreamClient {
|
|
|
185
185
|
const tokenContract = new ethers.Contract(tokenId, ercAbi, this.signer);
|
|
186
186
|
const address = await this.signer.getAddress();
|
|
187
187
|
const allowance = await tokenContract.allowance(address, this.programId);
|
|
188
|
-
if (
|
|
188
|
+
if (new BN(allowance.toString()).gte(amount)) {
|
|
189
189
|
return;
|
|
190
190
|
}
|
|
191
191
|
const approvalTx = await tokenContract.approve(this.programId, amount.toString());
|
package/dist/esm/evm/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BN from "bn.js";
|
|
2
2
|
import { BigNumber as BigNumberEvm } from "ethers";
|
|
3
3
|
import { Stream, StreamType } from "../common/types.js";
|
|
4
4
|
export interface StreamAbiResult {
|
|
@@ -52,7 +52,7 @@ export declare class EvmContract implements Stream {
|
|
|
52
52
|
magic: number;
|
|
53
53
|
version: number;
|
|
54
54
|
createdAt: number;
|
|
55
|
-
withdrawnAmount:
|
|
55
|
+
withdrawnAmount: BN;
|
|
56
56
|
canceledAt: number;
|
|
57
57
|
end: number;
|
|
58
58
|
lastWithdrawnAt: number;
|
|
@@ -64,20 +64,20 @@ export declare class EvmContract implements Stream {
|
|
|
64
64
|
escrowTokens: string;
|
|
65
65
|
streamflowTreasury: string;
|
|
66
66
|
streamflowTreasuryTokens: string;
|
|
67
|
-
streamflowFeeTotal:
|
|
68
|
-
streamflowFeeWithdrawn:
|
|
67
|
+
streamflowFeeTotal: BN;
|
|
68
|
+
streamflowFeeWithdrawn: BN;
|
|
69
69
|
streamflowFeePercent: number;
|
|
70
|
-
partnerFeeTotal:
|
|
71
|
-
partnerFeeWithdrawn:
|
|
70
|
+
partnerFeeTotal: BN;
|
|
71
|
+
partnerFeeWithdrawn: BN;
|
|
72
72
|
partnerFeePercent: number;
|
|
73
73
|
partner: string;
|
|
74
74
|
partnerTokens: string;
|
|
75
75
|
start: number;
|
|
76
|
-
depositedAmount:
|
|
76
|
+
depositedAmount: BN;
|
|
77
77
|
period: number;
|
|
78
|
-
amountPerPeriod:
|
|
78
|
+
amountPerPeriod: BN;
|
|
79
79
|
cliff: number;
|
|
80
|
-
cliffAmount:
|
|
80
|
+
cliffAmount: BN;
|
|
81
81
|
cancelableBySender: boolean;
|
|
82
82
|
cancelableByRecipient: boolean;
|
|
83
83
|
automaticWithdrawal: boolean;
|
|
@@ -88,11 +88,11 @@ export declare class EvmContract implements Stream {
|
|
|
88
88
|
withdrawalFrequency: number;
|
|
89
89
|
closed: boolean;
|
|
90
90
|
currentPauseStart: number;
|
|
91
|
-
pauseCumulative:
|
|
91
|
+
pauseCumulative: BN;
|
|
92
92
|
lastRateChangeTime: number;
|
|
93
|
-
fundsUnlockedAtLastRateChange:
|
|
93
|
+
fundsUnlockedAtLastRateChange: BN;
|
|
94
94
|
type: StreamType;
|
|
95
95
|
constructor(stream: StreamAbiResult);
|
|
96
|
-
unlocked(currentTimestamp: number):
|
|
96
|
+
unlocked(currentTimestamp: number): BN;
|
|
97
97
|
remaining(decimals: number): number;
|
|
98
98
|
}
|
package/dist/esm/evm/types.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BN from "bn.js";
|
|
2
2
|
import { buildStreamType, calculateUnlockedAmount } from "../common/contractUtils.js";
|
|
3
|
-
import {
|
|
3
|
+
import { getNumberFromBN } from "../common/utils.js";
|
|
4
4
|
export class EvmContract {
|
|
5
5
|
magic;
|
|
6
6
|
version;
|
|
@@ -49,7 +49,7 @@ export class EvmContract {
|
|
|
49
49
|
this.magic = 0;
|
|
50
50
|
this.version = 0;
|
|
51
51
|
this.createdAt = stream.created.toNumber();
|
|
52
|
-
this.withdrawnAmount =
|
|
52
|
+
this.withdrawnAmount = new BN(stream.withdrawn.toString());
|
|
53
53
|
this.canceledAt = stream.canceled_at.toNumber();
|
|
54
54
|
this.end = stream.end.toNumber();
|
|
55
55
|
this.lastWithdrawnAt = stream.last_withdrawn_at.toNumber();
|
|
@@ -61,20 +61,20 @@ export class EvmContract {
|
|
|
61
61
|
this.escrowTokens = "";
|
|
62
62
|
this.streamflowTreasury = "";
|
|
63
63
|
this.streamflowTreasuryTokens = "";
|
|
64
|
-
this.streamflowFeeTotal =
|
|
65
|
-
this.streamflowFeeWithdrawn =
|
|
64
|
+
this.streamflowFeeTotal = new BN(stream.fees.streamflow_fee.toString());
|
|
65
|
+
this.streamflowFeeWithdrawn = new BN(stream.fees.streamflow_fee_withdrawn.toString());
|
|
66
66
|
this.streamflowFeePercent = stream.fees.streamflow_fee_percentage.toNumber() / 10000;
|
|
67
|
-
this.partnerFeeTotal =
|
|
68
|
-
this.partnerFeeWithdrawn =
|
|
67
|
+
this.partnerFeeTotal = new BN(0);
|
|
68
|
+
this.partnerFeeWithdrawn = new BN(0);
|
|
69
69
|
this.partnerFeePercent = 0;
|
|
70
70
|
this.partner = "";
|
|
71
71
|
this.partnerTokens = "";
|
|
72
72
|
this.start = stream.start.toNumber();
|
|
73
|
-
this.depositedAmount =
|
|
73
|
+
this.depositedAmount = new BN(stream.amount.toString());
|
|
74
74
|
this.period = stream.period.toNumber();
|
|
75
|
-
this.amountPerPeriod =
|
|
75
|
+
this.amountPerPeriod = new BN(stream.amount_per_period.toString());
|
|
76
76
|
this.cliff = stream.start.toNumber();
|
|
77
|
-
this.cliffAmount =
|
|
77
|
+
this.cliffAmount = new BN(stream.cliff_amount.toString());
|
|
78
78
|
this.cancelableBySender = stream.meta.cancelable_by_sender;
|
|
79
79
|
this.cancelableByRecipient = stream.meta.cancelable_by_recipient;
|
|
80
80
|
this.automaticWithdrawal = stream.meta.automatic_withdrawal;
|
|
@@ -85,9 +85,9 @@ export class EvmContract {
|
|
|
85
85
|
this.withdrawalFrequency = stream.meta.withdrawal_frequency.toNumber();
|
|
86
86
|
this.closed = stream.closed;
|
|
87
87
|
this.currentPauseStart = stream.current_pause_start.toNumber();
|
|
88
|
-
this.pauseCumulative =
|
|
88
|
+
this.pauseCumulative = new BN(stream.pause_cumulative.toString());
|
|
89
89
|
this.lastRateChangeTime = stream.last_rate_change_time.toNumber();
|
|
90
|
-
this.fundsUnlockedAtLastRateChange =
|
|
90
|
+
this.fundsUnlockedAtLastRateChange = new BN(stream.funds_unlocked_at_last_rate_change.toString());
|
|
91
91
|
this.type = buildStreamType(this);
|
|
92
92
|
}
|
|
93
93
|
unlocked(currentTimestamp) {
|
|
@@ -97,6 +97,6 @@ export class EvmContract {
|
|
|
97
97
|
});
|
|
98
98
|
}
|
|
99
99
|
remaining(decimals) {
|
|
100
|
-
return
|
|
100
|
+
return getNumberFromBN(this.depositedAmount.sub(this.withdrawnAmount), decimals);
|
|
101
101
|
}
|
|
102
102
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Latest version of the SDK that does not use Anchor. It supports raw instructions.
|
|
2
|
-
import
|
|
2
|
+
import BN from "bn.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";
|
|
@@ -76,18 +76,18 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
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: new BN(start),
|
|
86
86
|
depositedAmount,
|
|
87
|
-
period:
|
|
87
|
+
period: new BN(period),
|
|
88
88
|
amountPerPeriod,
|
|
89
|
-
cliff:
|
|
90
|
-
cliffAmount:
|
|
89
|
+
cliff: new BN(cliff),
|
|
90
|
+
cliffAmount: new BN(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: new BN(automaticWithdrawal ? withdrawalFrequency : period),
|
|
101
101
|
}, this.programId, {
|
|
102
102
|
sender: sender.publicKey,
|
|
103
103
|
senderTokens,
|
|
@@ -167,17 +167,17 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
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: new BN(start),
|
|
176
176
|
depositedAmount,
|
|
177
|
-
period:
|
|
177
|
+
period: new BN(period),
|
|
178
178
|
amountPerPeriod,
|
|
179
|
-
cliff:
|
|
180
|
-
cliffAmount:
|
|
179
|
+
cliff: new BN(cliff),
|
|
180
|
+
cliffAmount: new BN(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: new BN(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.add(acc), new BN(0));
|
|
256
256
|
const nativeInstructions = await prepareWrappedAccount(this.connection, sender.publicKey, totalDepositedAmount);
|
|
257
257
|
const messageV0 = new TransactionMessage({
|
|
258
258
|
payerKey: sender.publicKey,
|
|
@@ -640,12 +640,12 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
640
640
|
const partnerPublicKey = partner ? new PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
|
|
641
641
|
const partnerTokens = await ata(mintPublicKey, partnerPublicKey, tokenProgramId);
|
|
642
642
|
ixs.push(createStreamInstruction({
|
|
643
|
-
start:
|
|
643
|
+
start: new BN(start),
|
|
644
644
|
depositedAmount: recipient.amount,
|
|
645
|
-
period:
|
|
645
|
+
period: new BN(period),
|
|
646
646
|
amountPerPeriod: recipient.amountPerPeriod,
|
|
647
|
-
cliff:
|
|
648
|
-
cliffAmount:
|
|
647
|
+
cliff: new BN(cliff),
|
|
648
|
+
cliffAmount: new BN(recipient.cliffAmount),
|
|
649
649
|
cancelableBySender,
|
|
650
650
|
cancelableByRecipient,
|
|
651
651
|
automaticWithdrawal,
|
|
@@ -655,7 +655,7 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
655
655
|
canUpdateRate: !!canUpdateRate,
|
|
656
656
|
canPause: !!canPause,
|
|
657
657
|
name: recipient.name,
|
|
658
|
-
withdrawFrequency:
|
|
658
|
+
withdrawFrequency: new BN(automaticWithdrawal ? withdrawalFrequency : period),
|
|
659
659
|
}, this.programId, {
|
|
660
660
|
sender: sender.publicKey,
|
|
661
661
|
senderTokens,
|
|
@@ -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)]);
|
|
@@ -2,7 +2,7 @@
|
|
|
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 BN from "bn.js";
|
|
6
6
|
import { IRecipient, Stream, StreamType } from "../common/types.js";
|
|
7
7
|
export interface ISearchStreams {
|
|
8
8
|
mint?: string;
|
|
@@ -33,7 +33,7 @@ export declare class Contract implements Stream {
|
|
|
33
33
|
magic: number;
|
|
34
34
|
version: number;
|
|
35
35
|
createdAt: number;
|
|
36
|
-
withdrawnAmount:
|
|
36
|
+
withdrawnAmount: BN;
|
|
37
37
|
canceledAt: number;
|
|
38
38
|
end: number;
|
|
39
39
|
lastWithdrawnAt: number;
|
|
@@ -45,20 +45,20 @@ export declare class Contract implements Stream {
|
|
|
45
45
|
escrowTokens: string;
|
|
46
46
|
streamflowTreasury: string;
|
|
47
47
|
streamflowTreasuryTokens: string;
|
|
48
|
-
streamflowFeeTotal:
|
|
49
|
-
streamflowFeeWithdrawn:
|
|
48
|
+
streamflowFeeTotal: BN;
|
|
49
|
+
streamflowFeeWithdrawn: BN;
|
|
50
50
|
streamflowFeePercent: number;
|
|
51
|
-
partnerFeeTotal:
|
|
52
|
-
partnerFeeWithdrawn:
|
|
51
|
+
partnerFeeTotal: BN;
|
|
52
|
+
partnerFeeWithdrawn: BN;
|
|
53
53
|
partnerFeePercent: number;
|
|
54
54
|
partner: string;
|
|
55
55
|
partnerTokens: string;
|
|
56
56
|
start: number;
|
|
57
|
-
depositedAmount:
|
|
57
|
+
depositedAmount: BN;
|
|
58
58
|
period: number;
|
|
59
|
-
amountPerPeriod:
|
|
59
|
+
amountPerPeriod: BN;
|
|
60
60
|
cliff: number;
|
|
61
|
-
cliffAmount:
|
|
61
|
+
cliffAmount: BN;
|
|
62
62
|
cancelableBySender: boolean;
|
|
63
63
|
cancelableByRecipient: boolean;
|
|
64
64
|
automaticWithdrawal: boolean;
|
|
@@ -69,22 +69,22 @@ export declare class Contract implements Stream {
|
|
|
69
69
|
withdrawalFrequency: number;
|
|
70
70
|
closed: boolean;
|
|
71
71
|
currentPauseStart: number;
|
|
72
|
-
pauseCumulative:
|
|
72
|
+
pauseCumulative: BN;
|
|
73
73
|
lastRateChangeTime: number;
|
|
74
|
-
fundsUnlockedAtLastRateChange:
|
|
74
|
+
fundsUnlockedAtLastRateChange: BN;
|
|
75
75
|
type: StreamType;
|
|
76
76
|
constructor(stream: DecodedStream);
|
|
77
|
-
unlocked(currentTimestamp: number):
|
|
77
|
+
unlocked(currentTimestamp: number): BN;
|
|
78
78
|
remaining(decimals: number): number;
|
|
79
79
|
}
|
|
80
80
|
export interface DecodedStream {
|
|
81
|
-
magic:
|
|
82
|
-
version:
|
|
83
|
-
createdAt:
|
|
84
|
-
withdrawnAmount:
|
|
85
|
-
canceledAt:
|
|
86
|
-
end:
|
|
87
|
-
lastWithdrawnAt:
|
|
81
|
+
magic: BN;
|
|
82
|
+
version: BN;
|
|
83
|
+
createdAt: BN;
|
|
84
|
+
withdrawnAmount: BN;
|
|
85
|
+
canceledAt: BN;
|
|
86
|
+
end: BN;
|
|
87
|
+
lastWithdrawnAt: BN;
|
|
88
88
|
sender: PublicKey;
|
|
89
89
|
senderTokens: PublicKey;
|
|
90
90
|
recipient: PublicKey;
|
|
@@ -93,20 +93,20 @@ export interface DecodedStream {
|
|
|
93
93
|
escrowTokens: PublicKey;
|
|
94
94
|
streamflowTreasury: PublicKey;
|
|
95
95
|
streamflowTreasuryTokens: PublicKey;
|
|
96
|
-
streamflowFeeTotal:
|
|
97
|
-
streamflowFeeWithdrawn:
|
|
98
|
-
streamflowFeePercent:
|
|
99
|
-
partnerFeeTotal:
|
|
100
|
-
partnerFeeWithdrawn:
|
|
101
|
-
partnerFeePercent:
|
|
96
|
+
streamflowFeeTotal: BN;
|
|
97
|
+
streamflowFeeWithdrawn: BN;
|
|
98
|
+
streamflowFeePercent: BN;
|
|
99
|
+
partnerFeeTotal: BN;
|
|
100
|
+
partnerFeeWithdrawn: BN;
|
|
101
|
+
partnerFeePercent: BN;
|
|
102
102
|
partner: PublicKey;
|
|
103
103
|
partnerTokens: PublicKey;
|
|
104
|
-
start:
|
|
105
|
-
depositedAmount:
|
|
106
|
-
period:
|
|
107
|
-
amountPerPeriod:
|
|
108
|
-
cliff:
|
|
109
|
-
cliffAmount:
|
|
104
|
+
start: BN;
|
|
105
|
+
depositedAmount: BN;
|
|
106
|
+
period: BN;
|
|
107
|
+
amountPerPeriod: BN;
|
|
108
|
+
cliff: BN;
|
|
109
|
+
cliffAmount: BN;
|
|
110
110
|
cancelableBySender: boolean;
|
|
111
111
|
cancelableByRecipient: boolean;
|
|
112
112
|
automaticWithdrawal: boolean;
|
|
@@ -114,12 +114,12 @@ export interface DecodedStream {
|
|
|
114
114
|
transferableByRecipient: boolean;
|
|
115
115
|
canTopup: boolean;
|
|
116
116
|
name: string;
|
|
117
|
-
withdrawFrequency:
|
|
117
|
+
withdrawFrequency: BN;
|
|
118
118
|
closed: boolean;
|
|
119
|
-
currentPauseStart:
|
|
120
|
-
pauseCumulative:
|
|
121
|
-
lastRateChangeTime:
|
|
122
|
-
fundsUnlockedAtLastRateChange:
|
|
119
|
+
currentPauseStart: BN;
|
|
120
|
+
pauseCumulative: BN;
|
|
121
|
+
lastRateChangeTime: BN;
|
|
122
|
+
fundsUnlockedAtLastRateChange: BN;
|
|
123
123
|
}
|
|
124
124
|
export interface MetadataRecipientHashMap {
|
|
125
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 { getNumberFromBN } 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 getNumberFromBN(this.depositedAmount.sub(this.withdrawnAmount), decimals);
|
|
100
100
|
}
|
|
101
101
|
}
|
|
@@ -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 BigNumber from "bignumber.js";
|
|
6
5
|
import { DecodedStream, BatchItem, BatchItemResult } from "./types.js";
|
|
7
|
-
export declare const toBuffer: (bigNumber: BigNumber) => Buffer;
|
|
8
6
|
export declare const decodeStream: (buf: Buffer) => DecodedStream;
|
|
9
7
|
/**
|
|
10
8
|
* Sign passed BatchItems with wallet request or KeyPair
|