@streamflow/stream 7.0.0-alpha.11 → 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 +17 -17
- 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 +17 -17
- 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
package/dist/cjs/solana/utils.js
CHANGED
|
@@ -3,31 +3,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.extractSolanaErrorCode = exports.sendAndConfirmStreamRawTransaction = exports.signAllTransactionWithRecipients = exports.decodeStream =
|
|
6
|
+
exports.extractSolanaErrorCode = exports.sendAndConfirmStreamRawTransaction = exports.signAllTransactionWithRecipients = exports.decodeStream = void 0;
|
|
7
7
|
const web3_js_1 = require("@solana/web3.js");
|
|
8
8
|
const solana_1 = require("@streamflow/common/solana");
|
|
9
|
-
const
|
|
9
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
10
10
|
const layout_js_1 = require("./layout.js");
|
|
11
11
|
const constants_js_1 = require("./constants.js");
|
|
12
12
|
const decoder = new TextDecoder("utf-8");
|
|
13
|
-
const
|
|
14
|
-
const toUInt8 = (uintArr) => new DataView(uintArr.buffer, uintArr.byteOffset, uintArr.byteLength).getUint8(0);
|
|
15
|
-
const toBuffer = (bigNumber) => {
|
|
16
|
-
const dv = new DataView(new ArrayBuffer(8), 0);
|
|
17
|
-
dv.setBigUint64(0, BigInt(bigNumber.integerValue().toString()), true);
|
|
18
|
-
return Buffer.from(dv.buffer);
|
|
19
|
-
};
|
|
20
|
-
exports.toBuffer = toBuffer;
|
|
13
|
+
const LE = "le"; //little endian
|
|
21
14
|
const decodeStream = (buf) => {
|
|
22
15
|
const raw = layout_js_1.streamLayout.decode(buf);
|
|
23
16
|
return {
|
|
24
|
-
magic:
|
|
25
|
-
version:
|
|
26
|
-
createdAt:
|
|
27
|
-
withdrawnAmount:
|
|
28
|
-
canceledAt:
|
|
29
|
-
end:
|
|
30
|
-
lastWithdrawnAt:
|
|
17
|
+
magic: new bn_js_1.default(raw.magic, LE),
|
|
18
|
+
version: new bn_js_1.default(raw.version, LE),
|
|
19
|
+
createdAt: new bn_js_1.default(raw.created_at, LE),
|
|
20
|
+
withdrawnAmount: new bn_js_1.default(raw.withdrawn_amount, LE),
|
|
21
|
+
canceledAt: new bn_js_1.default(raw.canceled_at, LE),
|
|
22
|
+
end: new bn_js_1.default(raw.end_time, LE),
|
|
23
|
+
lastWithdrawnAt: new bn_js_1.default(raw.last_withdrawn_at, LE),
|
|
31
24
|
sender: new web3_js_1.PublicKey(raw.sender),
|
|
32
25
|
senderTokens: new web3_js_1.PublicKey(raw.sender_tokens),
|
|
33
26
|
recipient: new web3_js_1.PublicKey(raw.recipient),
|
|
@@ -36,20 +29,20 @@ const decodeStream = (buf) => {
|
|
|
36
29
|
escrowTokens: new web3_js_1.PublicKey(raw.escrow_tokens),
|
|
37
30
|
streamflowTreasury: new web3_js_1.PublicKey(raw.streamflow_treasury),
|
|
38
31
|
streamflowTreasuryTokens: new web3_js_1.PublicKey(raw.streamflow_treasury_tokens),
|
|
39
|
-
streamflowFeeTotal:
|
|
40
|
-
streamflowFeeWithdrawn:
|
|
41
|
-
streamflowFeePercent:
|
|
42
|
-
partnerFeeTotal:
|
|
43
|
-
partnerFeeWithdrawn:
|
|
44
|
-
partnerFeePercent:
|
|
32
|
+
streamflowFeeTotal: new bn_js_1.default(raw.streamflow_fee_total, LE),
|
|
33
|
+
streamflowFeeWithdrawn: new bn_js_1.default(raw.streamflow_fee_withdrawn, LE),
|
|
34
|
+
streamflowFeePercent: new bn_js_1.default(raw.streamflow_fee_percent, LE),
|
|
35
|
+
partnerFeeTotal: new bn_js_1.default(raw.partner_fee_total, LE),
|
|
36
|
+
partnerFeeWithdrawn: new bn_js_1.default(raw.partner_fee_withdrawn, LE),
|
|
37
|
+
partnerFeePercent: new bn_js_1.default(raw.partner_fee_percent, LE),
|
|
45
38
|
partner: new web3_js_1.PublicKey(raw.partner),
|
|
46
39
|
partnerTokens: new web3_js_1.PublicKey(raw.partner_tokens),
|
|
47
|
-
start:
|
|
48
|
-
depositedAmount:
|
|
49
|
-
period:
|
|
50
|
-
amountPerPeriod:
|
|
51
|
-
cliff:
|
|
52
|
-
cliffAmount:
|
|
40
|
+
start: new bn_js_1.default(raw.start_time, LE),
|
|
41
|
+
depositedAmount: new bn_js_1.default(raw.net_amount_deposited, LE),
|
|
42
|
+
period: new bn_js_1.default(raw.period, LE),
|
|
43
|
+
amountPerPeriod: new bn_js_1.default(raw.amount_per_period, LE),
|
|
44
|
+
cliff: new bn_js_1.default(raw.cliff, LE),
|
|
45
|
+
cliffAmount: new bn_js_1.default(raw.cliff_amount, LE),
|
|
53
46
|
cancelableBySender: Boolean(raw.cancelable_by_sender),
|
|
54
47
|
cancelableByRecipient: Boolean(raw.cancelable_by_recipient),
|
|
55
48
|
automaticWithdrawal: Boolean(raw.automatic_withdrawal),
|
|
@@ -57,12 +50,12 @@ const decodeStream = (buf) => {
|
|
|
57
50
|
transferableByRecipient: Boolean(raw.transferable_by_recipient),
|
|
58
51
|
canTopup: Boolean(raw.can_topup),
|
|
59
52
|
name: decoder.decode(raw.stream_name),
|
|
60
|
-
withdrawFrequency:
|
|
53
|
+
withdrawFrequency: new bn_js_1.default(raw.withdraw_frequency, LE),
|
|
61
54
|
closed: Boolean(raw.closed),
|
|
62
|
-
currentPauseStart:
|
|
63
|
-
pauseCumulative:
|
|
64
|
-
lastRateChangeTime:
|
|
65
|
-
fundsUnlockedAtLastRateChange:
|
|
55
|
+
currentPauseStart: new bn_js_1.default(raw.current_pause_start, LE),
|
|
56
|
+
pauseCumulative: new bn_js_1.default(raw.pause_cumulative, LE),
|
|
57
|
+
lastRateChangeTime: new bn_js_1.default(raw.last_rate_change_time, LE),
|
|
58
|
+
fundsUnlockedAtLastRateChange: new bn_js_1.default(raw.funds_unlocked_at_last_rate_change, LE),
|
|
66
59
|
};
|
|
67
60
|
};
|
|
68
61
|
exports.decodeStream = decodeStream;
|
|
@@ -306,7 +306,7 @@ class SuiStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
306
306
|
let coins = await this.getAllCoins(walletAddress, multipleStreamData.tokenId);
|
|
307
307
|
const totalAmount = multipleStreamData.recipients
|
|
308
308
|
.map((recipiient) => recipiient.amount)
|
|
309
|
-
.reduce((prev, current) => current.
|
|
309
|
+
.reduce((prev, current) => current.add(prev));
|
|
310
310
|
const txb = new transactions_1.TransactionBlock();
|
|
311
311
|
const coinObject = this.splitCoinObjectForAmount(txb, totalAmount, multipleStreamData.tokenId, coins, totalFee);
|
|
312
312
|
coins = [coins[0]];
|
package/dist/cjs/sui/types.js
CHANGED
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Contract = void 0;
|
|
7
|
-
const
|
|
7
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
8
8
|
const contractUtils_js_1 = require("../common/contractUtils.js");
|
|
9
9
|
const utils_js_1 = require("../common/utils.js");
|
|
10
10
|
class Contract {
|
|
@@ -14,7 +14,7 @@ class Contract {
|
|
|
14
14
|
this.magic = 0;
|
|
15
15
|
this.version = parseInt(stream.version);
|
|
16
16
|
this.createdAt = parseInt(stream.created);
|
|
17
|
-
this.withdrawnAmount =
|
|
17
|
+
this.withdrawnAmount = new bn_js_1.default(stream.withdrawn);
|
|
18
18
|
this.canceledAt = parseInt(stream.canceled_at);
|
|
19
19
|
this.end = parseInt(stream.end);
|
|
20
20
|
this.lastWithdrawnAt = parseInt(stream.last_withdrawn_at);
|
|
@@ -26,20 +26,20 @@ class Contract {
|
|
|
26
26
|
this.escrowTokens = "";
|
|
27
27
|
this.streamflowTreasury = "";
|
|
28
28
|
this.streamflowTreasuryTokens = "";
|
|
29
|
-
this.streamflowFeeTotal =
|
|
30
|
-
this.streamflowFeeWithdrawn =
|
|
29
|
+
this.streamflowFeeTotal = new bn_js_1.default(0);
|
|
30
|
+
this.streamflowFeeWithdrawn = new bn_js_1.default(0);
|
|
31
31
|
this.streamflowFeePercent = parseInt(fees.streamflow_fee_percentage) / 10000;
|
|
32
|
-
this.partnerFeeTotal =
|
|
33
|
-
this.partnerFeeWithdrawn =
|
|
32
|
+
this.partnerFeeTotal = new bn_js_1.default(0);
|
|
33
|
+
this.partnerFeeWithdrawn = new bn_js_1.default(0);
|
|
34
34
|
this.partnerFeePercent = parseInt(fees.partner_fee_percentage) / 10000;
|
|
35
35
|
this.partner = stream.partner;
|
|
36
36
|
this.partnerTokens = "";
|
|
37
37
|
this.start = parseInt(stream.start);
|
|
38
|
-
this.depositedAmount =
|
|
38
|
+
this.depositedAmount = new bn_js_1.default(stream.amount);
|
|
39
39
|
this.period = parseInt(stream.period);
|
|
40
|
-
this.amountPerPeriod =
|
|
40
|
+
this.amountPerPeriod = new bn_js_1.default(stream.amount_per_period);
|
|
41
41
|
this.cliff = parseInt(stream.start);
|
|
42
|
-
this.cliffAmount =
|
|
42
|
+
this.cliffAmount = new bn_js_1.default(stream.cliff_amount);
|
|
43
43
|
this.cancelableBySender = meta.cancelable_by_sender;
|
|
44
44
|
this.cancelableByRecipient = meta.cancelable_by_recipient;
|
|
45
45
|
this.automaticWithdrawal = meta.automatic_withdrawal;
|
|
@@ -50,9 +50,9 @@ class Contract {
|
|
|
50
50
|
this.withdrawalFrequency = parseInt(meta.withdrawal_frequency);
|
|
51
51
|
this.closed = stream.closed;
|
|
52
52
|
this.currentPauseStart = parseInt(stream.current_pause_start);
|
|
53
|
-
this.pauseCumulative =
|
|
53
|
+
this.pauseCumulative = new bn_js_1.default(stream.pause_cumulative);
|
|
54
54
|
this.lastRateChangeTime = parseInt(stream.last_rate_change_time);
|
|
55
|
-
this.fundsUnlockedAtLastRateChange =
|
|
55
|
+
this.fundsUnlockedAtLastRateChange = new bn_js_1.default(stream.funds_unlocked_at_last_rate_change);
|
|
56
56
|
this.type = (0, contractUtils_js_1.buildStreamType)(this);
|
|
57
57
|
}
|
|
58
58
|
unlocked(currentTimestamp) {
|
|
@@ -62,7 +62,7 @@ class Contract {
|
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
64
|
remaining(decimals) {
|
|
65
|
-
return (0, utils_js_1.
|
|
65
|
+
return (0, utils_js_1.getNumberFromBN)(this.depositedAmount.sub(this.withdrawnAmount), decimals);
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
exports.Contract = Contract;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BN } from "bn.js";
|
|
2
2
|
import { describe, expect, test, beforeEach, vi } from "vitest";
|
|
3
3
|
import AptosStreamClient from "../../aptos/StreamClient.js";
|
|
4
4
|
import { ICluster } from "../../common/types.js";
|
|
@@ -32,10 +32,10 @@ describe("AptosStreamClient", () => {
|
|
|
32
32
|
};
|
|
33
33
|
const mockRecipient = {
|
|
34
34
|
recipient: "0xtest",
|
|
35
|
-
amount:
|
|
35
|
+
amount: new BN(1000),
|
|
36
36
|
name: "test name",
|
|
37
|
-
cliffAmount:
|
|
38
|
-
amountPerPeriod:
|
|
37
|
+
cliffAmount: new BN(1),
|
|
38
|
+
amountPerPeriod: new BN(1),
|
|
39
39
|
};
|
|
40
40
|
const mockData = {
|
|
41
41
|
period: 100,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AptosAccount } from "aptos";
|
|
2
2
|
import { WalletContextState } from "@manahippo/aptos-wallet-adapter";
|
|
3
|
-
import
|
|
3
|
+
import BN from "bn.js";
|
|
4
4
|
import { Stream, StreamType } from "../common/types.js";
|
|
5
5
|
export interface ICreateStreamAptosExt {
|
|
6
6
|
senderWallet: WalletContextState | AptosAccount;
|
|
@@ -63,7 +63,7 @@ export declare class Contract implements Stream {
|
|
|
63
63
|
magic: number;
|
|
64
64
|
version: number;
|
|
65
65
|
createdAt: number;
|
|
66
|
-
withdrawnAmount:
|
|
66
|
+
withdrawnAmount: BN;
|
|
67
67
|
canceledAt: number;
|
|
68
68
|
end: number;
|
|
69
69
|
lastWithdrawnAt: number;
|
|
@@ -75,20 +75,20 @@ export declare class Contract implements Stream {
|
|
|
75
75
|
escrowTokens: string;
|
|
76
76
|
streamflowTreasury: string;
|
|
77
77
|
streamflowTreasuryTokens: string;
|
|
78
|
-
streamflowFeeTotal:
|
|
79
|
-
streamflowFeeWithdrawn:
|
|
78
|
+
streamflowFeeTotal: BN;
|
|
79
|
+
streamflowFeeWithdrawn: BN;
|
|
80
80
|
streamflowFeePercent: number;
|
|
81
|
-
partnerFeeTotal:
|
|
82
|
-
partnerFeeWithdrawn:
|
|
81
|
+
partnerFeeTotal: BN;
|
|
82
|
+
partnerFeeWithdrawn: BN;
|
|
83
83
|
partnerFeePercent: number;
|
|
84
84
|
partner: string;
|
|
85
85
|
partnerTokens: string;
|
|
86
86
|
start: number;
|
|
87
|
-
depositedAmount:
|
|
87
|
+
depositedAmount: BN;
|
|
88
88
|
period: number;
|
|
89
|
-
amountPerPeriod:
|
|
89
|
+
amountPerPeriod: BN;
|
|
90
90
|
cliff: number;
|
|
91
|
-
cliffAmount:
|
|
91
|
+
cliffAmount: BN;
|
|
92
92
|
cancelableBySender: boolean;
|
|
93
93
|
cancelableByRecipient: boolean;
|
|
94
94
|
automaticWithdrawal: boolean;
|
|
@@ -99,11 +99,11 @@ export declare class Contract implements Stream {
|
|
|
99
99
|
withdrawalFrequency: number;
|
|
100
100
|
closed: boolean;
|
|
101
101
|
currentPauseStart: number;
|
|
102
|
-
pauseCumulative:
|
|
102
|
+
pauseCumulative: BN;
|
|
103
103
|
lastRateChangeTime: number;
|
|
104
|
-
fundsUnlockedAtLastRateChange:
|
|
104
|
+
fundsUnlockedAtLastRateChange: BN;
|
|
105
105
|
type: StreamType;
|
|
106
106
|
constructor(stream: StreamResource, tokenId: string);
|
|
107
|
-
unlocked(currentTimestamp: number):
|
|
107
|
+
unlocked(currentTimestamp: number): BN;
|
|
108
108
|
remaining(decimals: number): number;
|
|
109
109
|
}
|
package/dist/esm/aptos/types.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BN from "bn.js";
|
|
2
2
|
import { Buffer } from "buffer";
|
|
3
3
|
import { buildStreamType, calculateUnlockedAmount } from "../common/contractUtils.js";
|
|
4
4
|
import { normalizeAptosAddress } from "./utils.js";
|
|
5
|
-
import {
|
|
5
|
+
import { getNumberFromBN } from "../common/utils.js";
|
|
6
6
|
export class Contract {
|
|
7
7
|
magic;
|
|
8
8
|
version;
|
|
@@ -51,7 +51,7 @@ export class Contract {
|
|
|
51
51
|
this.magic = 0;
|
|
52
52
|
this.version = 0;
|
|
53
53
|
this.createdAt = parseInt(stream.created);
|
|
54
|
-
this.withdrawnAmount =
|
|
54
|
+
this.withdrawnAmount = new BN(stream.withdrawn);
|
|
55
55
|
this.canceledAt = parseInt(stream.canceled_at);
|
|
56
56
|
this.end = parseInt(stream.end);
|
|
57
57
|
this.lastWithdrawnAt = parseInt(stream.last_withdrawn_at);
|
|
@@ -63,20 +63,20 @@ export class Contract {
|
|
|
63
63
|
this.escrowTokens = "";
|
|
64
64
|
this.streamflowTreasury = "";
|
|
65
65
|
this.streamflowTreasuryTokens = "";
|
|
66
|
-
this.streamflowFeeTotal =
|
|
67
|
-
this.streamflowFeeWithdrawn =
|
|
66
|
+
this.streamflowFeeTotal = new BN(0);
|
|
67
|
+
this.streamflowFeeWithdrawn = new BN(0);
|
|
68
68
|
this.streamflowFeePercent = parseInt(stream.fees.streamflow_fee_percentage) / 10000;
|
|
69
|
-
this.partnerFeeTotal =
|
|
70
|
-
this.partnerFeeWithdrawn =
|
|
69
|
+
this.partnerFeeTotal = new BN(0);
|
|
70
|
+
this.partnerFeeWithdrawn = new BN(0);
|
|
71
71
|
this.partnerFeePercent = 0;
|
|
72
72
|
this.partner = "";
|
|
73
73
|
this.partnerTokens = "";
|
|
74
74
|
this.start = parseInt(stream.start);
|
|
75
|
-
this.depositedAmount =
|
|
75
|
+
this.depositedAmount = new BN(stream.amount);
|
|
76
76
|
this.period = parseInt(stream.period);
|
|
77
|
-
this.amountPerPeriod =
|
|
77
|
+
this.amountPerPeriod = new BN(stream.amount_per_period);
|
|
78
78
|
this.cliff = parseInt(stream.start);
|
|
79
|
-
this.cliffAmount =
|
|
79
|
+
this.cliffAmount = new BN(stream.cliff_amount);
|
|
80
80
|
this.cancelableBySender = stream.meta.cancelable_by_sender;
|
|
81
81
|
this.cancelableByRecipient = stream.meta.cancelable_by_recipient;
|
|
82
82
|
this.automaticWithdrawal = stream.meta.automatic_withdrawal;
|
|
@@ -88,9 +88,9 @@ export class Contract {
|
|
|
88
88
|
this.withdrawalFrequency = parseInt(stream.meta.withdrawal_frequency);
|
|
89
89
|
this.closed = stream.closed;
|
|
90
90
|
this.currentPauseStart = parseInt(stream.current_pause_start);
|
|
91
|
-
this.pauseCumulative =
|
|
91
|
+
this.pauseCumulative = new BN(stream.pause_cumulative);
|
|
92
92
|
this.lastRateChangeTime = parseInt(stream.last_rate_change_time);
|
|
93
|
-
this.fundsUnlockedAtLastRateChange =
|
|
93
|
+
this.fundsUnlockedAtLastRateChange = new BN(stream.funds_unlocked_at_last_rate_change);
|
|
94
94
|
this.type = buildStreamType(this);
|
|
95
95
|
}
|
|
96
96
|
unlocked(currentTimestamp) {
|
|
@@ -100,6 +100,6 @@ export class Contract {
|
|
|
100
100
|
});
|
|
101
101
|
}
|
|
102
102
|
remaining(decimals) {
|
|
103
|
-
return
|
|
103
|
+
return getNumberFromBN(this.depositedAmount.sub(this.withdrawnAmount), decimals);
|
|
104
104
|
}
|
|
105
105
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BN from "bn.js";
|
|
2
2
|
export declare const BASE_FEE = 1009900;
|
|
3
|
-
export declare const WITHDRAW_AVAILABLE_AMOUNT:
|
|
3
|
+
export declare const WITHDRAW_AVAILABLE_AMOUNT: BN;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BN from "bn.js";
|
|
2
2
|
export const BASE_FEE = 1009900; // Buffer to include usual fees when calculating stream amount
|
|
3
|
-
export const WITHDRAW_AVAILABLE_AMOUNT =
|
|
3
|
+
export const WITHDRAW_AVAILABLE_AMOUNT = new BN("18446744073709551615"); // Magical number to withdraw all available amount from a Contract
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BN from "bn.js";
|
|
2
2
|
import { StreamType } from "./types.js";
|
|
3
3
|
interface ICalculateUnlockedAmount {
|
|
4
|
-
depositedAmount:
|
|
4
|
+
depositedAmount: BN;
|
|
5
5
|
cliff: number;
|
|
6
|
-
cliffAmount:
|
|
6
|
+
cliffAmount: BN;
|
|
7
7
|
end: number;
|
|
8
8
|
currentTimestamp: number;
|
|
9
9
|
lastRateChangeTime: number;
|
|
10
10
|
period: number;
|
|
11
|
-
amountPerPeriod:
|
|
12
|
-
fundsUnlockedAtLastRateChange:
|
|
11
|
+
amountPerPeriod: BN;
|
|
12
|
+
fundsUnlockedAtLastRateChange: BN;
|
|
13
13
|
}
|
|
14
|
-
export declare const calculateUnlockedAmount: ({ depositedAmount, cliff, cliffAmount, end, currentTimestamp, lastRateChangeTime, period, amountPerPeriod, fundsUnlockedAtLastRateChange, }: ICalculateUnlockedAmount) =>
|
|
14
|
+
export declare const calculateUnlockedAmount: ({ depositedAmount, cliff, cliffAmount, end, currentTimestamp, lastRateChangeTime, period, amountPerPeriod, fundsUnlockedAtLastRateChange, }: ICalculateUnlockedAmount) => BN;
|
|
15
15
|
export declare const isCliffCloseToDepositedAmount: (streamData: {
|
|
16
|
-
depositedAmount:
|
|
17
|
-
cliffAmount:
|
|
16
|
+
depositedAmount: BN;
|
|
17
|
+
cliffAmount: BN;
|
|
18
18
|
}) => boolean;
|
|
19
19
|
export declare const isPayment: (streamData: {
|
|
20
20
|
canTopup: boolean;
|
|
21
21
|
}) => boolean;
|
|
22
22
|
export declare const isVesting: (streamData: {
|
|
23
23
|
canTopup: boolean;
|
|
24
|
-
depositedAmount:
|
|
25
|
-
cliffAmount:
|
|
24
|
+
depositedAmount: BN;
|
|
25
|
+
cliffAmount: BN;
|
|
26
26
|
}) => boolean;
|
|
27
27
|
export declare const isTokenLock: (streamData: {
|
|
28
28
|
canTopup: boolean;
|
|
@@ -31,8 +31,8 @@ export declare const isTokenLock: (streamData: {
|
|
|
31
31
|
cancelableByRecipient: boolean;
|
|
32
32
|
transferableBySender: boolean;
|
|
33
33
|
transferableByRecipient: boolean;
|
|
34
|
-
depositedAmount:
|
|
35
|
-
cliffAmount:
|
|
34
|
+
depositedAmount: BN;
|
|
35
|
+
cliffAmount: BN;
|
|
36
36
|
}) => boolean;
|
|
37
37
|
export declare const buildStreamType: (streamData: {
|
|
38
38
|
canTopup: boolean;
|
|
@@ -41,7 +41,7 @@ export declare const buildStreamType: (streamData: {
|
|
|
41
41
|
cancelableByRecipient: boolean;
|
|
42
42
|
transferableBySender: boolean;
|
|
43
43
|
transferableByRecipient: boolean;
|
|
44
|
-
depositedAmount:
|
|
45
|
-
cliffAmount:
|
|
44
|
+
depositedAmount: BN;
|
|
45
|
+
cliffAmount: BN;
|
|
46
46
|
}) => StreamType;
|
|
47
47
|
export {};
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BN from "bn.js";
|
|
2
2
|
import { StreamType } from "./types.js";
|
|
3
3
|
export const calculateUnlockedAmount = ({ depositedAmount, cliff, cliffAmount, end, currentTimestamp, lastRateChangeTime, period, amountPerPeriod, fundsUnlockedAtLastRateChange, }) => {
|
|
4
4
|
const deposited = depositedAmount;
|
|
5
5
|
if (currentTimestamp < cliff)
|
|
6
|
-
return
|
|
6
|
+
return new BN(0);
|
|
7
7
|
if (currentTimestamp > end)
|
|
8
8
|
return deposited;
|
|
9
9
|
const savedUnlockedFunds = lastRateChangeTime === 0 ? cliffAmount : fundsUnlockedAtLastRateChange;
|
|
10
10
|
const savedUnlockedFundsTime = lastRateChangeTime === 0 ? cliff : lastRateChangeTime;
|
|
11
|
-
const streamed =
|
|
12
|
-
.
|
|
13
|
-
.
|
|
11
|
+
const streamed = new BN(Math.floor((currentTimestamp - savedUnlockedFundsTime) / period))
|
|
12
|
+
.mul(amountPerPeriod)
|
|
13
|
+
.add(savedUnlockedFunds);
|
|
14
14
|
return streamed.lt(deposited) ? streamed : deposited;
|
|
15
15
|
};
|
|
16
16
|
export const isCliffCloseToDepositedAmount = (streamData) => {
|
|
17
|
-
return streamData.cliffAmount.gte(streamData.depositedAmount.
|
|
17
|
+
return streamData.cliffAmount.gte(streamData.depositedAmount.sub(new BN(1)));
|
|
18
18
|
};
|
|
19
19
|
export const isPayment = (streamData) => {
|
|
20
20
|
return streamData.canTopup;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { TransactionInstruction } from "@solana/web3.js";
|
|
2
2
|
import { Types } from "aptos";
|
|
3
|
-
import
|
|
3
|
+
import BN from "bn.js";
|
|
4
4
|
export { IChain, ICluster, ContractError } from "@streamflow/common";
|
|
5
5
|
export interface IRecipient {
|
|
6
6
|
recipient: string;
|
|
7
|
-
amount:
|
|
7
|
+
amount: BN;
|
|
8
8
|
name: string;
|
|
9
|
-
cliffAmount:
|
|
10
|
-
amountPerPeriod:
|
|
9
|
+
cliffAmount: BN;
|
|
10
|
+
amountPerPeriod: BN;
|
|
11
11
|
}
|
|
12
12
|
export interface IStreamConfig {
|
|
13
13
|
period: number;
|
|
@@ -33,19 +33,19 @@ export interface IInteractData {
|
|
|
33
33
|
id: string;
|
|
34
34
|
}
|
|
35
35
|
export interface IWithdrawData extends IInteractData {
|
|
36
|
-
amount?:
|
|
36
|
+
amount?: BN;
|
|
37
37
|
}
|
|
38
38
|
export interface IUpdateData extends IInteractData {
|
|
39
39
|
enableAutomaticWithdrawal?: boolean;
|
|
40
|
-
withdrawFrequency?:
|
|
41
|
-
amountPerPeriod?:
|
|
40
|
+
withdrawFrequency?: BN;
|
|
41
|
+
amountPerPeriod?: BN;
|
|
42
42
|
}
|
|
43
43
|
export type ICancelData = IInteractData;
|
|
44
44
|
export interface ITransferData extends IInteractData {
|
|
45
45
|
newRecipient: string;
|
|
46
46
|
}
|
|
47
47
|
export interface ITopUpData extends IInteractData {
|
|
48
|
-
amount:
|
|
48
|
+
amount: BN;
|
|
49
49
|
}
|
|
50
50
|
export type IGetOneData = IInteractData;
|
|
51
51
|
export interface IGetFeesData {
|
|
@@ -184,7 +184,7 @@ export interface Stream {
|
|
|
184
184
|
magic: number;
|
|
185
185
|
version: number;
|
|
186
186
|
createdAt: number;
|
|
187
|
-
withdrawnAmount:
|
|
187
|
+
withdrawnAmount: BN;
|
|
188
188
|
canceledAt: number;
|
|
189
189
|
end: number;
|
|
190
190
|
lastWithdrawnAt: number;
|
|
@@ -196,20 +196,20 @@ export interface Stream {
|
|
|
196
196
|
escrowTokens: string;
|
|
197
197
|
streamflowTreasury: string;
|
|
198
198
|
streamflowTreasuryTokens: string;
|
|
199
|
-
streamflowFeeTotal:
|
|
200
|
-
streamflowFeeWithdrawn:
|
|
199
|
+
streamflowFeeTotal: BN;
|
|
200
|
+
streamflowFeeWithdrawn: BN;
|
|
201
201
|
streamflowFeePercent: number;
|
|
202
|
-
partnerFeeTotal:
|
|
203
|
-
partnerFeeWithdrawn:
|
|
202
|
+
partnerFeeTotal: BN;
|
|
203
|
+
partnerFeeWithdrawn: BN;
|
|
204
204
|
partnerFeePercent: number;
|
|
205
205
|
partner: string;
|
|
206
206
|
partnerTokens: string;
|
|
207
207
|
start: number;
|
|
208
|
-
depositedAmount:
|
|
208
|
+
depositedAmount: BN;
|
|
209
209
|
period: number;
|
|
210
|
-
amountPerPeriod:
|
|
210
|
+
amountPerPeriod: BN;
|
|
211
211
|
cliff: number;
|
|
212
|
-
cliffAmount:
|
|
212
|
+
cliffAmount: BN;
|
|
213
213
|
cancelableBySender: boolean;
|
|
214
214
|
cancelableByRecipient: boolean;
|
|
215
215
|
automaticWithdrawal: boolean;
|
|
@@ -220,10 +220,10 @@ export interface Stream {
|
|
|
220
220
|
withdrawalFrequency: number;
|
|
221
221
|
closed: boolean;
|
|
222
222
|
currentPauseStart: number;
|
|
223
|
-
pauseCumulative:
|
|
223
|
+
pauseCumulative: BN;
|
|
224
224
|
lastRateChangeTime: number;
|
|
225
|
-
fundsUnlockedAtLastRateChange:
|
|
225
|
+
fundsUnlockedAtLastRateChange: BN;
|
|
226
226
|
type: StreamType;
|
|
227
|
-
unlocked(currentTimestamp: number):
|
|
227
|
+
unlocked(currentTimestamp: number): BN;
|
|
228
228
|
remaining(decimals: number): number;
|
|
229
229
|
}
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BN from "bn.js";
|
|
2
2
|
/**
|
|
3
|
-
* Used for token amounts
|
|
4
|
-
* Get
|
|
5
|
-
* @param {
|
|
3
|
+
* Used for conversion of token amounts to their Big Number representation.
|
|
4
|
+
* Get Big Number representation in the smallest units from the same value in the highest units.
|
|
5
|
+
* @param {number} value - Number of tokens you want to convert to its BN representation.
|
|
6
6
|
* @param {number} decimals - Number of decimals the token has.
|
|
7
7
|
*/
|
|
8
|
-
export declare const
|
|
8
|
+
export declare const getBN: (value: number, decimals: number) => BN;
|
|
9
9
|
/**
|
|
10
|
-
* Used for
|
|
11
|
-
* Get
|
|
12
|
-
* @param {
|
|
10
|
+
* Used for token amounts conversion from their Big Number representation to number.
|
|
11
|
+
* Get value in the highest units from BN representation of the same value in the smallest units.
|
|
12
|
+
* @param {BN} value - Big Number representation of value in the smallest units.
|
|
13
13
|
* @param {number} decimals - Number of decimals the token has.
|
|
14
14
|
*/
|
|
15
|
-
export declare const
|
|
15
|
+
export declare const getNumberFromBN: (value: BN, decimals: number) => number;
|
|
16
16
|
/**
|
|
17
17
|
* Calculate total amount of a Contract including all fees.
|
|
18
|
-
* - first we convert fee floating to a
|
|
18
|
+
* - first we convert fee floating to a BN with up to 4 decimals precision
|
|
19
19
|
* - then we reverse the fee with `FEE_MULTIPLIER` to safely multiply it by depositedAmount
|
|
20
20
|
* to receive a total number and not percentage of depositedAmount
|
|
21
21
|
* @param depositedAmount deposited raw tokens
|
|
22
22
|
* @param totalFee sum of all fees in percentage as floating number, e.g. 0.99% should be supplied as 0.99
|
|
23
23
|
* @returns total tokens amount that Contract will retrieve from the Sender
|
|
24
24
|
*/
|
|
25
|
-
export declare const calculateTotalAmountToDeposit: (depositedAmount:
|
|
25
|
+
export declare const calculateTotalAmountToDeposit: (depositedAmount: BN, totalFee: number) => BN;
|
|
26
26
|
/**
|
|
27
27
|
* Used to make on chain calls to the contract and wrap raised errors if any
|
|
28
28
|
* @param func function that interacts with the contract
|
package/dist/esm/common/utils.js
CHANGED
|
@@ -1,29 +1,32 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BN from "bn.js";
|
|
2
2
|
import { ContractError } from "./types.js";
|
|
3
3
|
const FEE_PRECISION = 4;
|
|
4
4
|
const FEE_NORMALIZER = 10 ** FEE_PRECISION;
|
|
5
|
-
const FEE_MULTIPLIER =
|
|
5
|
+
const FEE_MULTIPLIER = new BN(10 ** 6);
|
|
6
6
|
/**
|
|
7
|
-
* Used for token amounts
|
|
8
|
-
* Get
|
|
9
|
-
* @param {
|
|
7
|
+
* Used for conversion of token amounts to their Big Number representation.
|
|
8
|
+
* Get Big Number representation in the smallest units from the same value in the highest units.
|
|
9
|
+
* @param {number} value - Number of tokens you want to convert to its BN representation.
|
|
10
10
|
* @param {number} decimals - Number of decimals the token has.
|
|
11
11
|
*/
|
|
12
|
-
export const
|
|
13
|
-
|
|
12
|
+
export const getBN = (value, decimals) => {
|
|
13
|
+
const decimalPart = value - Math.trunc(value);
|
|
14
|
+
const integerPart = new BN(Math.trunc(value));
|
|
15
|
+
const decimalE = new BN(decimalPart * 1e9);
|
|
16
|
+
const sum = integerPart.mul(new BN(1e9)).add(decimalE);
|
|
17
|
+
const resultE = sum.mul(new BN(10).pow(new BN(decimals)));
|
|
18
|
+
return resultE.div(new BN(1e9));
|
|
14
19
|
};
|
|
15
20
|
/**
|
|
16
|
-
* Used for
|
|
17
|
-
* Get
|
|
18
|
-
* @param {
|
|
21
|
+
* Used for token amounts conversion from their Big Number representation to number.
|
|
22
|
+
* Get value in the highest units from BN representation of the same value in the smallest units.
|
|
23
|
+
* @param {BN} value - Big Number representation of value in the smallest units.
|
|
19
24
|
* @param {number} decimals - Number of decimals the token has.
|
|
20
25
|
*/
|
|
21
|
-
export const
|
|
22
|
-
return new BigNumber(value).times(new BigNumber(10).pow(decimals));
|
|
23
|
-
};
|
|
26
|
+
export const getNumberFromBN = (value, decimals) => value.gt(new BN(2 ** 53 - 1)) ? value.div(new BN(10 ** decimals)).toNumber() : value.toNumber() / 10 ** decimals;
|
|
24
27
|
/**
|
|
25
28
|
* Calculate total amount of a Contract including all fees.
|
|
26
|
-
* - first we convert fee floating to a
|
|
29
|
+
* - first we convert fee floating to a BN with up to 4 decimals precision
|
|
27
30
|
* - then we reverse the fee with `FEE_MULTIPLIER` to safely multiply it by depositedAmount
|
|
28
31
|
* to receive a total number and not percentage of depositedAmount
|
|
29
32
|
* @param depositedAmount deposited raw tokens
|
|
@@ -31,8 +34,8 @@ export const getScaledBigNumber = (value, decimals) => {
|
|
|
31
34
|
* @returns total tokens amount that Contract will retrieve from the Sender
|
|
32
35
|
*/
|
|
33
36
|
export const calculateTotalAmountToDeposit = (depositedAmount, totalFee) => {
|
|
34
|
-
const totalFeeNormalized =
|
|
35
|
-
return depositedAmount.
|
|
37
|
+
const totalFeeNormalized = new BN(totalFee * FEE_NORMALIZER);
|
|
38
|
+
return depositedAmount.mul(totalFeeNormalized.add(FEE_MULTIPLIER)).div(FEE_MULTIPLIER);
|
|
36
39
|
};
|
|
37
40
|
/**
|
|
38
41
|
* Used to make on chain calls to the contract and wrap raised errors if any
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ethers } from "ethers";
|
|
2
|
-
import
|
|
2
|
+
import BN from "bn.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: BN): Promise<void>;
|
|
29
29
|
private generateMultiPayloads;
|
|
30
30
|
private getFeeParams;
|
|
31
31
|
private formatMetadataId;
|