@streamflow/stream 7.0.0-alpha.1 → 7.0.0-alpha.2
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 +17 -18
- package/dist/cjs/__tests__/aptos/streamClient.spec.js +4 -4
- package/dist/cjs/aptos/types.js +18 -18
- package/dist/cjs/common/constants.js +2 -2
- package/dist/cjs/common/contractUtils.js +6 -6
- package/dist/cjs/common/utils.js +18 -23
- package/dist/cjs/evm/StreamClient.js +7 -7
- package/dist/cjs/evm/types.js +12 -12
- package/dist/cjs/solana/StreamClient.js +17 -17
- package/dist/cjs/solana/instructions.js +19 -18
- package/dist/cjs/solana/types.js +1 -1
- package/dist/cjs/solana/utils.js +38 -27
- 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 +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/solana/StreamClient.js +17 -17
- package/dist/esm/solana/instructions.d.ts +17 -17
- package/dist/esm/solana/instructions.js +19 -18
- package/dist/esm/solana/types.d.ts +36 -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 +5 -6
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ethers } from "ethers";
|
|
2
|
-
import
|
|
2
|
+
import BigNumber from "bignumber.js";
|
|
3
3
|
import { BaseStreamClient } from "../common/BaseStreamClient.js";
|
|
4
4
|
import { ICancelData, IChain, ICluster, ICreateMultipleStreamData, ICreateResult, ICreateStreamData, IGetFeesData, IGetAllData, IGetOneData, IFees, IMultiTransactionResult, ITopUpData, ITransactionResult, ITransferData, IUpdateData, IWithdrawData, Stream } from "../common/types.js";
|
|
5
5
|
export default class EvmStreamClient extends BaseStreamClient {
|
|
@@ -25,7 +25,7 @@ export default class EvmStreamClient extends BaseStreamClient {
|
|
|
25
25
|
* Returns StreamClient protocol program ID.
|
|
26
26
|
*/
|
|
27
27
|
getProgramId(): string;
|
|
28
|
-
approveTokens(tokenId: string, amount:
|
|
28
|
+
approveTokens(tokenId: string, amount: BigNumber): Promise<void>;
|
|
29
29
|
private generateMultiPayloads;
|
|
30
30
|
private getFeeParams;
|
|
31
31
|
private formatMetadataId;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ethers } from "ethers";
|
|
2
|
-
import
|
|
2
|
+
import BigNumber from "bignumber.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.times(BigNumber(BASE_FEE)).div(BigNumber(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.plus(v.amount), BigNumber(0))
|
|
70
|
+
.times(BigNumber(BASE_FEE))
|
|
71
|
+
.div(BigNumber(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.times(BigNumber(BASE_FEE)).div(BigNumber(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 (BigNumber(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,27 +1,27 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { BigNumber } from "ethers";
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { BigNumber as BigNumberEvm } from "ethers";
|
|
3
3
|
import { Stream, StreamType } from "../common/types.js";
|
|
4
4
|
export interface StreamAbiResult {
|
|
5
|
-
amount:
|
|
6
|
-
amount_per_period:
|
|
7
|
-
canceled_at:
|
|
8
|
-
cliff_amount:
|
|
5
|
+
amount: BigNumberEvm;
|
|
6
|
+
amount_per_period: BigNumberEvm;
|
|
7
|
+
canceled_at: BigNumberEvm;
|
|
8
|
+
cliff_amount: BigNumberEvm;
|
|
9
9
|
closed: boolean;
|
|
10
|
-
created:
|
|
11
|
-
current_pause_start:
|
|
12
|
-
end:
|
|
10
|
+
created: BigNumberEvm;
|
|
11
|
+
current_pause_start: BigNumberEvm;
|
|
12
|
+
end: BigNumberEvm;
|
|
13
13
|
fees: {
|
|
14
|
-
streamflow_fee_percentage:
|
|
15
|
-
streamflow_fee:
|
|
16
|
-
streamflow_fee_withdrawn:
|
|
17
|
-
partner_fee_percentage:
|
|
18
|
-
partner_fee:
|
|
19
|
-
partner_fee_withdrawn:
|
|
20
|
-
tx_fee:
|
|
14
|
+
streamflow_fee_percentage: BigNumberEvm;
|
|
15
|
+
streamflow_fee: BigNumberEvm;
|
|
16
|
+
streamflow_fee_withdrawn: BigNumberEvm;
|
|
17
|
+
partner_fee_percentage: BigNumberEvm;
|
|
18
|
+
partner_fee: BigNumberEvm;
|
|
19
|
+
partner_fee_withdrawn: BigNumberEvm;
|
|
20
|
+
tx_fee: BigNumberEvm;
|
|
21
21
|
};
|
|
22
|
-
funds_unlocked_at_last_rate_change:
|
|
23
|
-
last_rate_change_time:
|
|
24
|
-
last_withdrawn_at:
|
|
22
|
+
funds_unlocked_at_last_rate_change: BigNumberEvm;
|
|
23
|
+
last_rate_change_time: BigNumberEvm;
|
|
24
|
+
last_withdrawn_at: BigNumberEvm;
|
|
25
25
|
meta: {
|
|
26
26
|
automatic_withdrawal: boolean;
|
|
27
27
|
can_topup: boolean;
|
|
@@ -32,27 +32,27 @@ export interface StreamAbiResult {
|
|
|
32
32
|
pausable: boolean;
|
|
33
33
|
transferable_by_recipient: boolean;
|
|
34
34
|
transferable_by_sender: boolean;
|
|
35
|
-
withdrawal_frequency:
|
|
35
|
+
withdrawal_frequency: BigNumberEvm;
|
|
36
36
|
};
|
|
37
|
-
pause_cumulative:
|
|
38
|
-
period:
|
|
37
|
+
pause_cumulative: BigNumberEvm;
|
|
38
|
+
period: BigNumberEvm;
|
|
39
39
|
recipient: string;
|
|
40
40
|
sender: string;
|
|
41
41
|
partner: string;
|
|
42
|
-
start:
|
|
42
|
+
start: BigNumberEvm;
|
|
43
43
|
token: string;
|
|
44
|
-
withdrawn:
|
|
44
|
+
withdrawn: BigNumberEvm;
|
|
45
45
|
}
|
|
46
46
|
export interface FeesAbiResult {
|
|
47
47
|
exists: boolean;
|
|
48
|
-
streamflow_fee:
|
|
49
|
-
partner_fee:
|
|
48
|
+
streamflow_fee: BigNumberEvm;
|
|
49
|
+
partner_fee: BigNumberEvm;
|
|
50
50
|
}
|
|
51
51
|
export declare class EvmContract implements Stream {
|
|
52
52
|
magic: number;
|
|
53
53
|
version: number;
|
|
54
54
|
createdAt: number;
|
|
55
|
-
withdrawnAmount:
|
|
55
|
+
withdrawnAmount: BigNumber;
|
|
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: BigNumber;
|
|
68
|
+
streamflowFeeWithdrawn: BigNumber;
|
|
69
69
|
streamflowFeePercent: number;
|
|
70
|
-
partnerFeeTotal:
|
|
71
|
-
partnerFeeWithdrawn:
|
|
70
|
+
partnerFeeTotal: BigNumber;
|
|
71
|
+
partnerFeeWithdrawn: BigNumber;
|
|
72
72
|
partnerFeePercent: number;
|
|
73
73
|
partner: string;
|
|
74
74
|
partnerTokens: string;
|
|
75
75
|
start: number;
|
|
76
|
-
depositedAmount:
|
|
76
|
+
depositedAmount: BigNumber;
|
|
77
77
|
period: number;
|
|
78
|
-
amountPerPeriod:
|
|
78
|
+
amountPerPeriod: BigNumber;
|
|
79
79
|
cliff: number;
|
|
80
|
-
cliffAmount:
|
|
80
|
+
cliffAmount: BigNumber;
|
|
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: BigNumber;
|
|
92
92
|
lastRateChangeTime: number;
|
|
93
|
-
fundsUnlockedAtLastRateChange:
|
|
93
|
+
fundsUnlockedAtLastRateChange: BigNumber;
|
|
94
94
|
type: StreamType;
|
|
95
95
|
constructor(stream: StreamAbiResult);
|
|
96
|
-
unlocked(currentTimestamp: number):
|
|
96
|
+
unlocked(currentTimestamp: number): BigNumber;
|
|
97
97
|
remaining(decimals: number): number;
|
|
98
98
|
}
|
package/dist/esm/evm/types.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
2
|
import { buildStreamType, calculateUnlockedAmount } from "../common/contractUtils.js";
|
|
3
|
-
import {
|
|
3
|
+
import { getNumberFromBigNumber } 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 = BigNumber(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 = BigNumber(stream.fees.streamflow_fee.toString());
|
|
65
|
+
this.streamflowFeeWithdrawn = BigNumber(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 = BigNumber(0);
|
|
68
|
+
this.partnerFeeWithdrawn = BigNumber(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 = BigNumber(stream.amount.toString());
|
|
74
74
|
this.period = stream.period.toNumber();
|
|
75
|
-
this.amountPerPeriod =
|
|
75
|
+
this.amountPerPeriod = BigNumber(stream.amount_per_period.toString());
|
|
76
76
|
this.cliff = stream.start.toNumber();
|
|
77
|
-
this.cliffAmount =
|
|
77
|
+
this.cliffAmount = BigNumber(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 = BigNumber(stream.pause_cumulative.toString());
|
|
89
89
|
this.lastRateChangeTime = stream.last_rate_change_time.toNumber();
|
|
90
|
-
this.fundsUnlockedAtLastRateChange =
|
|
90
|
+
this.fundsUnlockedAtLastRateChange = BigNumber(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 getNumberFromBigNumber(this.depositedAmount.minus(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 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";
|
|
@@ -82,12 +82,12 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
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,
|
|
@@ -172,12 +172,12 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
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,
|
|
@@ -624,12 +624,12 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
624
624
|
const partnerPublicKey = partner ? new PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
|
|
625
625
|
const partnerTokens = await ata(mintPublicKey, partnerPublicKey, tokenProgramId);
|
|
626
626
|
ixs.push(createStreamInstruction({
|
|
627
|
-
start:
|
|
627
|
+
start: BigNumber(start),
|
|
628
628
|
depositedAmount: recipient.amount,
|
|
629
|
-
period:
|
|
629
|
+
period: BigNumber(period),
|
|
630
630
|
amountPerPeriod: recipient.amountPerPeriod,
|
|
631
|
-
cliff:
|
|
632
|
-
cliffAmount: recipient.cliffAmount,
|
|
631
|
+
cliff: BigNumber(cliff),
|
|
632
|
+
cliffAmount: BigNumber(recipient.cliffAmount),
|
|
633
633
|
cancelableBySender,
|
|
634
634
|
cancelableByRecipient,
|
|
635
635
|
automaticWithdrawal,
|
|
@@ -639,7 +639,7 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
639
639
|
canUpdateRate: !!canUpdateRate,
|
|
640
640
|
canPause: !!canPause,
|
|
641
641
|
name: recipient.name,
|
|
642
|
-
withdrawFrequency:
|
|
642
|
+
withdrawFrequency: BigNumber(automaticWithdrawal ? withdrawalFrequency : period),
|
|
643
643
|
}, this.programId, {
|
|
644
644
|
sender: sender.publicKey,
|
|
645
645
|
senderTokens,
|
|
@@ -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,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 BigNumber from "bignumber.js";
|
|
6
6
|
import { IRecipient, Stream, StreamType } from "../common/types.js";
|
|
7
7
|
export interface Account {
|
|
8
8
|
pubkey: PublicKey;
|
|
@@ -28,7 +28,7 @@ export declare class Contract implements Stream {
|
|
|
28
28
|
magic: number;
|
|
29
29
|
version: number;
|
|
30
30
|
createdAt: number;
|
|
31
|
-
withdrawnAmount:
|
|
31
|
+
withdrawnAmount: BigNumber;
|
|
32
32
|
canceledAt: number;
|
|
33
33
|
end: number;
|
|
34
34
|
lastWithdrawnAt: number;
|
|
@@ -40,20 +40,20 @@ export declare class Contract implements Stream {
|
|
|
40
40
|
escrowTokens: string;
|
|
41
41
|
streamflowTreasury: string;
|
|
42
42
|
streamflowTreasuryTokens: string;
|
|
43
|
-
streamflowFeeTotal:
|
|
44
|
-
streamflowFeeWithdrawn:
|
|
43
|
+
streamflowFeeTotal: BigNumber;
|
|
44
|
+
streamflowFeeWithdrawn: BigNumber;
|
|
45
45
|
streamflowFeePercent: number;
|
|
46
|
-
partnerFeeTotal:
|
|
47
|
-
partnerFeeWithdrawn:
|
|
46
|
+
partnerFeeTotal: BigNumber;
|
|
47
|
+
partnerFeeWithdrawn: BigNumber;
|
|
48
48
|
partnerFeePercent: number;
|
|
49
49
|
partner: string;
|
|
50
50
|
partnerTokens: string;
|
|
51
51
|
start: number;
|
|
52
|
-
depositedAmount:
|
|
52
|
+
depositedAmount: BigNumber;
|
|
53
53
|
period: number;
|
|
54
|
-
amountPerPeriod:
|
|
54
|
+
amountPerPeriod: BigNumber;
|
|
55
55
|
cliff: number;
|
|
56
|
-
cliffAmount:
|
|
56
|
+
cliffAmount: BigNumber;
|
|
57
57
|
cancelableBySender: boolean;
|
|
58
58
|
cancelableByRecipient: boolean;
|
|
59
59
|
automaticWithdrawal: boolean;
|
|
@@ -64,22 +64,22 @@ export declare class Contract implements Stream {
|
|
|
64
64
|
withdrawalFrequency: number;
|
|
65
65
|
closed: boolean;
|
|
66
66
|
currentPauseStart: number;
|
|
67
|
-
pauseCumulative:
|
|
67
|
+
pauseCumulative: BigNumber;
|
|
68
68
|
lastRateChangeTime: number;
|
|
69
|
-
fundsUnlockedAtLastRateChange:
|
|
69
|
+
fundsUnlockedAtLastRateChange: BigNumber;
|
|
70
70
|
type: StreamType;
|
|
71
71
|
constructor(stream: DecodedStream);
|
|
72
|
-
unlocked(currentTimestamp: number):
|
|
72
|
+
unlocked(currentTimestamp: number): BigNumber;
|
|
73
73
|
remaining(decimals: number): number;
|
|
74
74
|
}
|
|
75
75
|
export interface DecodedStream {
|
|
76
|
-
magic:
|
|
77
|
-
version:
|
|
78
|
-
createdAt:
|
|
79
|
-
withdrawnAmount:
|
|
80
|
-
canceledAt:
|
|
81
|
-
end:
|
|
82
|
-
lastWithdrawnAt:
|
|
76
|
+
magic: BigNumber;
|
|
77
|
+
version: BigNumber;
|
|
78
|
+
createdAt: BigNumber;
|
|
79
|
+
withdrawnAmount: BigNumber;
|
|
80
|
+
canceledAt: BigNumber;
|
|
81
|
+
end: BigNumber;
|
|
82
|
+
lastWithdrawnAt: BigNumber;
|
|
83
83
|
sender: PublicKey;
|
|
84
84
|
senderTokens: PublicKey;
|
|
85
85
|
recipient: PublicKey;
|
|
@@ -88,20 +88,20 @@ export interface DecodedStream {
|
|
|
88
88
|
escrowTokens: PublicKey;
|
|
89
89
|
streamflowTreasury: PublicKey;
|
|
90
90
|
streamflowTreasuryTokens: PublicKey;
|
|
91
|
-
streamflowFeeTotal:
|
|
92
|
-
streamflowFeeWithdrawn:
|
|
93
|
-
streamflowFeePercent:
|
|
94
|
-
partnerFeeTotal:
|
|
95
|
-
partnerFeeWithdrawn:
|
|
96
|
-
partnerFeePercent:
|
|
91
|
+
streamflowFeeTotal: BigNumber;
|
|
92
|
+
streamflowFeeWithdrawn: BigNumber;
|
|
93
|
+
streamflowFeePercent: BigNumber;
|
|
94
|
+
partnerFeeTotal: BigNumber;
|
|
95
|
+
partnerFeeWithdrawn: BigNumber;
|
|
96
|
+
partnerFeePercent: BigNumber;
|
|
97
97
|
partner: PublicKey;
|
|
98
98
|
partnerTokens: PublicKey;
|
|
99
|
-
start:
|
|
100
|
-
depositedAmount:
|
|
101
|
-
period:
|
|
102
|
-
amountPerPeriod:
|
|
103
|
-
cliff:
|
|
104
|
-
cliffAmount:
|
|
99
|
+
start: BigNumber;
|
|
100
|
+
depositedAmount: BigNumber;
|
|
101
|
+
period: BigNumber;
|
|
102
|
+
amountPerPeriod: BigNumber;
|
|
103
|
+
cliff: BigNumber;
|
|
104
|
+
cliffAmount: BigNumber;
|
|
105
105
|
cancelableBySender: boolean;
|
|
106
106
|
cancelableByRecipient: boolean;
|
|
107
107
|
automaticWithdrawal: boolean;
|
|
@@ -109,12 +109,12 @@ export interface DecodedStream {
|
|
|
109
109
|
transferableByRecipient: boolean;
|
|
110
110
|
canTopup: boolean;
|
|
111
111
|
name: string;
|
|
112
|
-
withdrawFrequency:
|
|
112
|
+
withdrawFrequency: BigNumber;
|
|
113
113
|
closed: boolean;
|
|
114
|
-
currentPauseStart:
|
|
115
|
-
pauseCumulative:
|
|
116
|
-
lastRateChangeTime:
|
|
117
|
-
fundsUnlockedAtLastRateChange:
|
|
114
|
+
currentPauseStart: BigNumber;
|
|
115
|
+
pauseCumulative: BigNumber;
|
|
116
|
+
lastRateChangeTime: BigNumber;
|
|
117
|
+
fundsUnlockedAtLastRateChange: BigNumber;
|
|
118
118
|
}
|
|
119
119
|
export interface MetadataRecipientHashMap {
|
|
120
120
|
[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
|
}
|