@streamflow/stream 7.0.0-alpha.1 → 7.0.0-alpha.3
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/index.js +3 -3
- package/dist/cjs/aptos/types.js +18 -18
- package/dist/cjs/common/GenericStreamClient.js +8 -8
- 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/index.js +10 -10
- 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/index.d.ts +3 -3
- package/dist/esm/aptos/index.js +3 -3
- package/dist/esm/aptos/types.d.ts +12 -12
- package/dist/esm/aptos/types.js +13 -13
- package/dist/esm/common/GenericStreamClient.d.ts +4 -4
- package/dist/esm/common/GenericStreamClient.js +4 -4
- package/dist/esm/common/constants.d.ts +2 -2
- package/dist/esm/common/constants.js +2 -2
- package/dist/esm/common/contractUtils.d.ts +14 -14
- package/dist/esm/common/contractUtils.js +6 -6
- package/dist/esm/common/types.d.ts +19 -19
- package/dist/esm/common/utils.d.ts +11 -11
- package/dist/esm/common/utils.js +16 -19
- package/dist/esm/evm/StreamClient.d.ts +2 -2
- package/dist/esm/evm/StreamClient.js +7 -7
- package/dist/esm/evm/types.d.ts +37 -37
- package/dist/esm/evm/types.js +13 -13
- package/dist/esm/index.d.ts +9 -9
- package/dist/esm/index.js +9 -9
- package/dist/esm/solana/StreamClient.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
|
@@ -28,6 +28,7 @@ var buffer_1 = require("buffer");
|
|
|
28
28
|
var web3_js_1 = require("@solana/web3.js");
|
|
29
29
|
var node_crypto_1 = require("node:crypto");
|
|
30
30
|
var Layout = __importStar(require("./layout.js"));
|
|
31
|
+
var utils_js_1 = require("./utils.js");
|
|
31
32
|
var hasher = function () { return (0, node_crypto_1.createHash)("sha256"); };
|
|
32
33
|
var sha256 = {
|
|
33
34
|
digest: function (data) { return new Uint8Array(hasher().update(data).digest()); },
|
|
@@ -69,12 +70,12 @@ var createStreamInstruction = function (data, programId, accounts) {
|
|
|
69
70
|
var encodedUIntArray = new TextEncoder().encode(data.name);
|
|
70
71
|
var streamNameBuffer = buffer_1.Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
|
|
71
72
|
var decodedData = {
|
|
72
|
-
start_time:
|
|
73
|
-
net_amount_deposited:
|
|
74
|
-
period:
|
|
75
|
-
amount_per_period:
|
|
76
|
-
cliff:
|
|
77
|
-
cliff_amount:
|
|
73
|
+
start_time: (0, utils_js_1.toBuffer)(data.start),
|
|
74
|
+
net_amount_deposited: (0, utils_js_1.toBuffer)(data.depositedAmount),
|
|
75
|
+
period: (0, utils_js_1.toBuffer)(data.period),
|
|
76
|
+
amount_per_period: (0, utils_js_1.toBuffer)(data.amountPerPeriod),
|
|
77
|
+
cliff: (0, utils_js_1.toBuffer)(data.cliff),
|
|
78
|
+
cliff_amount: (0, utils_js_1.toBuffer)(data.cliffAmount),
|
|
78
79
|
cancelable_by_sender: Number(data.cancelableBySender),
|
|
79
80
|
cancelable_by_recipient: Number(data.cancelableByRecipient),
|
|
80
81
|
automatic_withdrawal: Number(data.automaticWithdrawal),
|
|
@@ -86,7 +87,7 @@ var createStreamInstruction = function (data, programId, accounts) {
|
|
|
86
87
|
_can_update_rate_discriminator: 1,
|
|
87
88
|
pausable: Number(data.canPause),
|
|
88
89
|
stream_name: streamNameBuffer,
|
|
89
|
-
withdraw_frequency:
|
|
90
|
+
withdraw_frequency: (0, utils_js_1.toBuffer)(data.withdrawFrequency),
|
|
90
91
|
};
|
|
91
92
|
var encodeLength = Layout.createStreamLayout.encode(decodedData, bufferData);
|
|
92
93
|
bufferData = bufferData.slice(0, encodeLength);
|
|
@@ -123,12 +124,12 @@ var createUncheckedStreamInstruction = function (data, programId, accounts) {
|
|
|
123
124
|
var encodedUIntArray = new TextEncoder().encode(data.name);
|
|
124
125
|
var streamNameBuffer = buffer_1.Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
|
|
125
126
|
var decodedData = {
|
|
126
|
-
start_time:
|
|
127
|
-
net_amount_deposited:
|
|
128
|
-
period:
|
|
129
|
-
amount_per_period:
|
|
130
|
-
cliff:
|
|
131
|
-
cliff_amount:
|
|
127
|
+
start_time: (0, utils_js_1.toBuffer)(data.start),
|
|
128
|
+
net_amount_deposited: (0, utils_js_1.toBuffer)(data.depositedAmount),
|
|
129
|
+
period: (0, utils_js_1.toBuffer)(data.period),
|
|
130
|
+
amount_per_period: (0, utils_js_1.toBuffer)(data.amountPerPeriod),
|
|
131
|
+
cliff: (0, utils_js_1.toBuffer)(data.cliff),
|
|
132
|
+
cliff_amount: (0, utils_js_1.toBuffer)(data.cliffAmount),
|
|
132
133
|
cancelable_by_sender: Number(data.cancelableBySender),
|
|
133
134
|
cancelable_by_recipient: Number(data.cancelableByRecipient),
|
|
134
135
|
automatic_withdrawal: Number(data.automaticWithdrawal),
|
|
@@ -136,7 +137,7 @@ var createUncheckedStreamInstruction = function (data, programId, accounts) {
|
|
|
136
137
|
transferable_by_recipient: Number(data.transferableByRecipient),
|
|
137
138
|
can_topup: Number(data.canTopup),
|
|
138
139
|
stream_name: streamNameBuffer,
|
|
139
|
-
withdraw_frequency:
|
|
140
|
+
withdraw_frequency: (0, utils_js_1.toBuffer)(data.withdrawFrequency),
|
|
140
141
|
recipient: data.recipient.toBuffer(),
|
|
141
142
|
partner: data.partner.toBuffer(),
|
|
142
143
|
pausable: Number(data.canPause),
|
|
@@ -175,7 +176,7 @@ var withdrawStreamInstruction = function (amount, programId, _a) {
|
|
|
175
176
|
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
176
177
|
];
|
|
177
178
|
var data = buffer_1.Buffer.alloc(Layout.withdrawStreamLayout.span);
|
|
178
|
-
var decodedData = { amount:
|
|
179
|
+
var decodedData = { amount: (0, utils_js_1.toBuffer)(amount) };
|
|
179
180
|
var encodeLength = Layout.withdrawStreamLayout.encode(decodedData, data);
|
|
180
181
|
data = data.slice(0, encodeLength);
|
|
181
182
|
data = buffer_1.Buffer.concat([buffer_1.Buffer.from(sha256.digest("global:withdraw")).slice(0, 8), data, buffer_1.Buffer.alloc(10)]);
|
|
@@ -197,8 +198,8 @@ var updateStreamInstruction = function (params, programId, _a) {
|
|
|
197
198
|
var data = buffer_1.Buffer.alloc(100);
|
|
198
199
|
var decodedData = {
|
|
199
200
|
enable_automatic_withdrawal: Number(params.enableAutomaticWithdrawal),
|
|
200
|
-
withdraw_frequency: params.withdrawFrequency ?
|
|
201
|
-
amount_per_period: params.amountPerPeriod ?
|
|
201
|
+
withdraw_frequency: params.withdrawFrequency ? (0, utils_js_1.toBuffer)(params.withdrawFrequency) : undefined,
|
|
202
|
+
amount_per_period: params.amountPerPeriod ? (0, utils_js_1.toBuffer)(params.amountPerPeriod) : undefined,
|
|
202
203
|
};
|
|
203
204
|
var encodeLength = Layout.encodeUpdateStream(decodedData, data);
|
|
204
205
|
data = data.slice(0, encodeLength);
|
|
@@ -281,7 +282,7 @@ var topupStreamInstruction = function (amount, programId, _a) {
|
|
|
281
282
|
{ pubkey: systemProgram, isSigner: false, isWritable: false },
|
|
282
283
|
];
|
|
283
284
|
var data = buffer_1.Buffer.alloc(Layout.topupStreamLayout.span);
|
|
284
|
-
var decodedData = { amount:
|
|
285
|
+
var decodedData = { amount: (0, utils_js_1.toBuffer)(amount) };
|
|
285
286
|
var encodeLength = Layout.topupStreamLayout.encode(decodedData, data);
|
|
286
287
|
data = data.slice(0, encodeLength);
|
|
287
288
|
data = buffer_1.Buffer.concat([buffer_1.Buffer.from(sha256.digest("global:topup")).slice(0, 8), data, buffer_1.Buffer.alloc(10)]);
|
package/dist/cjs/solana/types.js
CHANGED
|
@@ -65,7 +65,7 @@ var Contract = /** @class */ (function () {
|
|
|
65
65
|
return (0, contractUtils_js_1.calculateUnlockedAmount)(__assign(__assign({}, this), { currentTimestamp: currentTimestamp }));
|
|
66
66
|
};
|
|
67
67
|
Contract.prototype.remaining = function (decimals) {
|
|
68
|
-
return (0, utils_js_1.
|
|
68
|
+
return (0, utils_js_1.getNumberFromBigNumber)(this.depositedAmount.minus(this.withdrawnAmount), decimals);
|
|
69
69
|
};
|
|
70
70
|
return Contract;
|
|
71
71
|
}());
|
package/dist/cjs/solana/utils.js
CHANGED
|
@@ -61,24 +61,35 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
61
61
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
62
62
|
};
|
|
63
63
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
64
|
-
exports.extractSolanaErrorCode = exports.sendAndConfirmStreamRawTransaction = exports.signAllTransactionWithRecipients = exports.decodeStream = void 0;
|
|
64
|
+
exports.extractSolanaErrorCode = exports.sendAndConfirmStreamRawTransaction = exports.signAllTransactionWithRecipients = exports.decodeStream = exports.toBuffer = void 0;
|
|
65
65
|
var web3_js_1 = require("@solana/web3.js");
|
|
66
66
|
var solana_1 = require("@streamflow/common/solana");
|
|
67
|
-
var
|
|
67
|
+
var bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
68
68
|
var layout_js_1 = require("./layout.js");
|
|
69
69
|
var constants_js_1 = require("./constants.js");
|
|
70
70
|
var decoder = new TextDecoder("utf-8");
|
|
71
|
-
var
|
|
71
|
+
var toUInt64String = function (uintArr) {
|
|
72
|
+
return new DataView(uintArr.buffer, uintArr.byteOffset, uintArr.byteLength).getBigUint64(0, true).toString();
|
|
73
|
+
};
|
|
74
|
+
var toUInt8 = function (uintArr) {
|
|
75
|
+
return new DataView(uintArr.buffer, uintArr.byteOffset, uintArr.byteLength).getUint8(0);
|
|
76
|
+
};
|
|
77
|
+
var toBuffer = function (bigNumber) {
|
|
78
|
+
var dv = new DataView(new ArrayBuffer(8), 0);
|
|
79
|
+
dv.setBigUint64(0, BigInt(bigNumber.integerValue().toString()), true);
|
|
80
|
+
return Buffer.from(dv.buffer);
|
|
81
|
+
};
|
|
82
|
+
exports.toBuffer = toBuffer;
|
|
72
83
|
var decodeStream = function (buf) {
|
|
73
84
|
var raw = layout_js_1.streamLayout.decode(buf);
|
|
74
85
|
return {
|
|
75
|
-
magic:
|
|
76
|
-
version:
|
|
77
|
-
createdAt:
|
|
78
|
-
withdrawnAmount:
|
|
79
|
-
canceledAt:
|
|
80
|
-
end:
|
|
81
|
-
lastWithdrawnAt:
|
|
86
|
+
magic: (0, bignumber_js_1.default)(toUInt64String(raw.magic)),
|
|
87
|
+
version: (0, bignumber_js_1.default)(toUInt8(raw.version)),
|
|
88
|
+
createdAt: (0, bignumber_js_1.default)(toUInt64String(raw.created_at)),
|
|
89
|
+
withdrawnAmount: (0, bignumber_js_1.default)(toUInt64String(raw.withdrawn_amount)),
|
|
90
|
+
canceledAt: (0, bignumber_js_1.default)(toUInt64String(raw.canceled_at)),
|
|
91
|
+
end: (0, bignumber_js_1.default)(toUInt64String(raw.end_time)),
|
|
92
|
+
lastWithdrawnAt: (0, bignumber_js_1.default)(toUInt64String(raw.last_withdrawn_at)),
|
|
82
93
|
sender: new web3_js_1.PublicKey(raw.sender),
|
|
83
94
|
senderTokens: new web3_js_1.PublicKey(raw.sender_tokens),
|
|
84
95
|
recipient: new web3_js_1.PublicKey(raw.recipient),
|
|
@@ -87,20 +98,20 @@ var decodeStream = function (buf) {
|
|
|
87
98
|
escrowTokens: new web3_js_1.PublicKey(raw.escrow_tokens),
|
|
88
99
|
streamflowTreasury: new web3_js_1.PublicKey(raw.streamflow_treasury),
|
|
89
100
|
streamflowTreasuryTokens: new web3_js_1.PublicKey(raw.streamflow_treasury_tokens),
|
|
90
|
-
streamflowFeeTotal:
|
|
91
|
-
streamflowFeeWithdrawn:
|
|
92
|
-
streamflowFeePercent:
|
|
93
|
-
partnerFeeTotal:
|
|
94
|
-
partnerFeeWithdrawn:
|
|
95
|
-
partnerFeePercent:
|
|
101
|
+
streamflowFeeTotal: (0, bignumber_js_1.default)(toUInt64String(raw.streamflow_fee_total)),
|
|
102
|
+
streamflowFeeWithdrawn: (0, bignumber_js_1.default)(toUInt64String(raw.streamflow_fee_withdrawn)),
|
|
103
|
+
streamflowFeePercent: (0, bignumber_js_1.default)(raw.streamflow_fee_percent),
|
|
104
|
+
partnerFeeTotal: (0, bignumber_js_1.default)(toUInt64String(raw.partner_fee_total)),
|
|
105
|
+
partnerFeeWithdrawn: (0, bignumber_js_1.default)(toUInt64String(raw.partner_fee_withdrawn)),
|
|
106
|
+
partnerFeePercent: (0, bignumber_js_1.default)(raw.partner_fee_percent),
|
|
96
107
|
partner: new web3_js_1.PublicKey(raw.partner),
|
|
97
108
|
partnerTokens: new web3_js_1.PublicKey(raw.partner_tokens),
|
|
98
|
-
start:
|
|
99
|
-
depositedAmount:
|
|
100
|
-
period:
|
|
101
|
-
amountPerPeriod:
|
|
102
|
-
cliff:
|
|
103
|
-
cliffAmount:
|
|
109
|
+
start: (0, bignumber_js_1.default)(toUInt64String(raw.start_time)),
|
|
110
|
+
depositedAmount: (0, bignumber_js_1.default)(toUInt64String(raw.net_amount_deposited)),
|
|
111
|
+
period: (0, bignumber_js_1.default)(toUInt64String(raw.period)),
|
|
112
|
+
amountPerPeriod: (0, bignumber_js_1.default)(toUInt64String(raw.amount_per_period)),
|
|
113
|
+
cliff: (0, bignumber_js_1.default)(toUInt64String(raw.cliff)),
|
|
114
|
+
cliffAmount: (0, bignumber_js_1.default)(toUInt64String(raw.cliff_amount)),
|
|
104
115
|
cancelableBySender: Boolean(raw.cancelable_by_sender),
|
|
105
116
|
cancelableByRecipient: Boolean(raw.cancelable_by_recipient),
|
|
106
117
|
automaticWithdrawal: Boolean(raw.automatic_withdrawal),
|
|
@@ -108,12 +119,12 @@ var decodeStream = function (buf) {
|
|
|
108
119
|
transferableByRecipient: Boolean(raw.transferable_by_recipient),
|
|
109
120
|
canTopup: Boolean(raw.can_topup),
|
|
110
121
|
name: decoder.decode(raw.stream_name),
|
|
111
|
-
withdrawFrequency:
|
|
122
|
+
withdrawFrequency: (0, bignumber_js_1.default)(toUInt64String(raw.withdraw_frequency)),
|
|
112
123
|
closed: Boolean(raw.closed),
|
|
113
|
-
currentPauseStart:
|
|
114
|
-
pauseCumulative:
|
|
115
|
-
lastRateChangeTime:
|
|
116
|
-
fundsUnlockedAtLastRateChange:
|
|
124
|
+
currentPauseStart: (0, bignumber_js_1.default)(toUInt64String(raw.current_pause_start)),
|
|
125
|
+
pauseCumulative: (0, bignumber_js_1.default)(toUInt64String(raw.pause_cumulative)),
|
|
126
|
+
lastRateChangeTime: (0, bignumber_js_1.default)(toUInt64String(raw.last_rate_change_time)),
|
|
127
|
+
fundsUnlockedAtLastRateChange: (0, bignumber_js_1.default)(toUInt64String(raw.funds_unlocked_at_last_rate_change)),
|
|
117
128
|
};
|
|
118
129
|
};
|
|
119
130
|
exports.decodeStream = decodeStream;
|
|
@@ -535,7 +535,7 @@ var SuiStreamClient = /** @class */ (function (_super) {
|
|
|
535
535
|
coins = _a.sent();
|
|
536
536
|
totalAmount = multipleStreamData.recipients
|
|
537
537
|
.map(function (recipiient) { return recipiient.amount; })
|
|
538
|
-
.reduce(function (prev, current) { return current.
|
|
538
|
+
.reduce(function (prev, current) { return current.plus(prev); });
|
|
539
539
|
txb = new transactions_1.TransactionBlock();
|
|
540
540
|
coinObject = this.splitCoinObjectForAmount(txb, totalAmount, multipleStreamData.tokenId, coins, totalFee);
|
|
541
541
|
coins = [coins[0]];
|
package/dist/cjs/sui/types.js
CHANGED
|
@@ -40,7 +40,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
42
|
exports.Contract = void 0;
|
|
43
|
-
var
|
|
43
|
+
var bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
44
44
|
var contractUtils_js_1 = require("../common/contractUtils.js");
|
|
45
45
|
var utils_js_1 = require("../common/utils.js");
|
|
46
46
|
var Contract = /** @class */ (function () {
|
|
@@ -50,7 +50,7 @@ var Contract = /** @class */ (function () {
|
|
|
50
50
|
this.magic = 0;
|
|
51
51
|
this.version = parseInt(stream.version);
|
|
52
52
|
this.createdAt = parseInt(stream.created);
|
|
53
|
-
this.withdrawnAmount =
|
|
53
|
+
this.withdrawnAmount = (0, bignumber_js_1.default)(stream.withdrawn);
|
|
54
54
|
this.canceledAt = parseInt(stream.canceled_at);
|
|
55
55
|
this.end = parseInt(stream.end);
|
|
56
56
|
this.lastWithdrawnAt = parseInt(stream.last_withdrawn_at);
|
|
@@ -62,20 +62,20 @@ var Contract = /** @class */ (function () {
|
|
|
62
62
|
this.escrowTokens = "";
|
|
63
63
|
this.streamflowTreasury = "";
|
|
64
64
|
this.streamflowTreasuryTokens = "";
|
|
65
|
-
this.streamflowFeeTotal =
|
|
66
|
-
this.streamflowFeeWithdrawn =
|
|
65
|
+
this.streamflowFeeTotal = (0, bignumber_js_1.default)(0);
|
|
66
|
+
this.streamflowFeeWithdrawn = (0, bignumber_js_1.default)(0);
|
|
67
67
|
this.streamflowFeePercent = parseInt(fees.streamflow_fee_percentage) / 10000;
|
|
68
|
-
this.partnerFeeTotal =
|
|
69
|
-
this.partnerFeeWithdrawn =
|
|
68
|
+
this.partnerFeeTotal = (0, bignumber_js_1.default)(0);
|
|
69
|
+
this.partnerFeeWithdrawn = (0, bignumber_js_1.default)(0);
|
|
70
70
|
this.partnerFeePercent = parseInt(fees.partner_fee_percentage) / 10000;
|
|
71
71
|
this.partner = stream.partner;
|
|
72
72
|
this.partnerTokens = "";
|
|
73
73
|
this.start = parseInt(stream.start);
|
|
74
|
-
this.depositedAmount =
|
|
74
|
+
this.depositedAmount = (0, bignumber_js_1.default)(stream.amount);
|
|
75
75
|
this.period = parseInt(stream.period);
|
|
76
|
-
this.amountPerPeriod =
|
|
76
|
+
this.amountPerPeriod = (0, bignumber_js_1.default)(stream.amount_per_period);
|
|
77
77
|
this.cliff = parseInt(stream.start);
|
|
78
|
-
this.cliffAmount =
|
|
78
|
+
this.cliffAmount = (0, bignumber_js_1.default)(stream.cliff_amount);
|
|
79
79
|
this.cancelableBySender = meta.cancelable_by_sender;
|
|
80
80
|
this.cancelableByRecipient = meta.cancelable_by_recipient;
|
|
81
81
|
this.automaticWithdrawal = meta.automatic_withdrawal;
|
|
@@ -86,16 +86,16 @@ var Contract = /** @class */ (function () {
|
|
|
86
86
|
this.withdrawalFrequency = parseInt(meta.withdrawal_frequency);
|
|
87
87
|
this.closed = stream.closed;
|
|
88
88
|
this.currentPauseStart = parseInt(stream.current_pause_start);
|
|
89
|
-
this.pauseCumulative =
|
|
89
|
+
this.pauseCumulative = (0, bignumber_js_1.default)(stream.pause_cumulative);
|
|
90
90
|
this.lastRateChangeTime = parseInt(stream.last_rate_change_time);
|
|
91
|
-
this.fundsUnlockedAtLastRateChange =
|
|
91
|
+
this.fundsUnlockedAtLastRateChange = (0, bignumber_js_1.default)(stream.funds_unlocked_at_last_rate_change);
|
|
92
92
|
this.type = (0, contractUtils_js_1.buildStreamType)(this);
|
|
93
93
|
}
|
|
94
94
|
Contract.prototype.unlocked = function (currentTimestamp) {
|
|
95
95
|
return (0, contractUtils_js_1.calculateUnlockedAmount)(__assign(__assign({}, this), { currentTimestamp: currentTimestamp }));
|
|
96
96
|
};
|
|
97
97
|
Contract.prototype.remaining = function (decimals) {
|
|
98
|
-
return (0, utils_js_1.
|
|
98
|
+
return (0, utils_js_1.getNumberFromBigNumber)(this.depositedAmount.minus(this.withdrawnAmount), decimals);
|
|
99
99
|
};
|
|
100
100
|
return Contract;
|
|
101
101
|
}());
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BigNumber } from "bignumber.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: BigNumber(1000),
|
|
36
36
|
name: "test name",
|
|
37
|
-
cliffAmount:
|
|
38
|
-
amountPerPeriod:
|
|
37
|
+
cliffAmount: BigNumber(1),
|
|
38
|
+
amountPerPeriod: BigNumber(1),
|
|
39
39
|
};
|
|
40
40
|
const mockData = {
|
|
41
41
|
period: 100,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { default, default as AptosStreamClient } from "./StreamClient.js";
|
|
2
|
-
export * from "./utils";
|
|
3
|
-
export * from "./types";
|
|
4
|
-
export * as constants from "./constants";
|
|
2
|
+
export * from "./utils.js";
|
|
3
|
+
export * from "./types.js";
|
|
4
|
+
export * as constants from "./constants.js";
|
package/dist/esm/aptos/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { default, default as AptosStreamClient } from "./StreamClient.js";
|
|
2
|
-
export * from "./utils";
|
|
3
|
-
export * from "./types";
|
|
4
|
-
export * as constants from "./constants";
|
|
2
|
+
export * from "./utils.js";
|
|
3
|
+
export * from "./types.js";
|
|
4
|
+
export * as constants from "./constants.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AptosAccount } from "aptos";
|
|
2
2
|
import { WalletContextState } from "@manahippo/aptos-wallet-adapter";
|
|
3
|
-
import
|
|
3
|
+
import BigNumber from "bignumber.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: BigNumber;
|
|
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: BigNumber;
|
|
79
|
+
streamflowFeeWithdrawn: BigNumber;
|
|
80
80
|
streamflowFeePercent: number;
|
|
81
|
-
partnerFeeTotal:
|
|
82
|
-
partnerFeeWithdrawn:
|
|
81
|
+
partnerFeeTotal: BigNumber;
|
|
82
|
+
partnerFeeWithdrawn: BigNumber;
|
|
83
83
|
partnerFeePercent: number;
|
|
84
84
|
partner: string;
|
|
85
85
|
partnerTokens: string;
|
|
86
86
|
start: number;
|
|
87
|
-
depositedAmount:
|
|
87
|
+
depositedAmount: BigNumber;
|
|
88
88
|
period: number;
|
|
89
|
-
amountPerPeriod:
|
|
89
|
+
amountPerPeriod: BigNumber;
|
|
90
90
|
cliff: number;
|
|
91
|
-
cliffAmount:
|
|
91
|
+
cliffAmount: BigNumber;
|
|
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: BigNumber;
|
|
103
103
|
lastRateChangeTime: number;
|
|
104
|
-
fundsUnlockedAtLastRateChange:
|
|
104
|
+
fundsUnlockedAtLastRateChange: BigNumber;
|
|
105
105
|
type: StreamType;
|
|
106
106
|
constructor(stream: StreamResource, tokenId: string);
|
|
107
|
-
unlocked(currentTimestamp: number):
|
|
107
|
+
unlocked(currentTimestamp: number): BigNumber;
|
|
108
108
|
remaining(decimals: number): number;
|
|
109
109
|
}
|
package/dist/esm/aptos/types.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
2
|
import { Buffer } from "buffer";
|
|
3
3
|
import { buildStreamType, calculateUnlockedAmount } from "../common/contractUtils.js";
|
|
4
|
-
import { getNumberFromBN } from "../common/utils.js";
|
|
5
4
|
import { normalizeAptosAddress } from "./utils.js";
|
|
5
|
+
import { getNumberFromBigNumber } 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 = BigNumber(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 = BigNumber(0);
|
|
67
|
+
this.streamflowFeeWithdrawn = BigNumber(0);
|
|
68
68
|
this.streamflowFeePercent = parseInt(stream.fees.streamflow_fee_percentage) / 10000;
|
|
69
|
-
this.partnerFeeTotal =
|
|
70
|
-
this.partnerFeeWithdrawn =
|
|
69
|
+
this.partnerFeeTotal = BigNumber(0);
|
|
70
|
+
this.partnerFeeWithdrawn = BigNumber(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 = BigNumber(stream.amount);
|
|
76
76
|
this.period = parseInt(stream.period);
|
|
77
|
-
this.amountPerPeriod =
|
|
77
|
+
this.amountPerPeriod = BigNumber(stream.amount_per_period);
|
|
78
78
|
this.cliff = parseInt(stream.start);
|
|
79
|
-
this.cliffAmount =
|
|
79
|
+
this.cliffAmount = BigNumber(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 = BigNumber(stream.pause_cumulative);
|
|
92
92
|
this.lastRateChangeTime = parseInt(stream.last_rate_change_time);
|
|
93
|
-
this.fundsUnlockedAtLastRateChange =
|
|
93
|
+
this.fundsUnlockedAtLastRateChange = BigNumber(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 getNumberFromBigNumber(this.depositedAmount.minus(this.withdrawnAmount), decimals);
|
|
104
104
|
}
|
|
105
105
|
}
|
|
@@ -3,10 +3,10 @@ import { Signer } from "ethers";
|
|
|
3
3
|
import PQueue from "p-queue";
|
|
4
4
|
import { BaseStreamClient } from "./BaseStreamClient.js";
|
|
5
5
|
import { ICancelData, IChain, ICluster, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IUpdateData, IWithdrawData, ITransactionResult, IMultiTransactionResult, ICreateResult, IGetAllData, Stream, IFees, IGetFeesData } from "./types.js";
|
|
6
|
-
import { AptosStreamClient, ICreateStreamAptosExt, ITransactionAptosExt } from "../aptos";
|
|
7
|
-
import { EvmStreamClient } from "../evm";
|
|
8
|
-
import { SolanaStreamClient, ICreateStreamSolanaExt, IInteractStreamSolanaExt, ITopUpStreamSolanaExt } from "../solana";
|
|
9
|
-
import { ICreateStreamSuiExt, ITransactionSuiExt, ISuiIdParameters, SuiStreamClient } from "../sui";
|
|
6
|
+
import { AptosStreamClient, ICreateStreamAptosExt, ITransactionAptosExt } from "../aptos/index.js";
|
|
7
|
+
import { EvmStreamClient } from "../evm/index.js";
|
|
8
|
+
import { SolanaStreamClient, ICreateStreamSolanaExt, IInteractStreamSolanaExt, ITopUpStreamSolanaExt } from "../solana/index.js";
|
|
9
|
+
import { ICreateStreamSuiExt, ITransactionSuiExt, ISuiIdParameters, SuiStreamClient } from "../sui/index.js";
|
|
10
10
|
export interface SolanaStreamClientOptions {
|
|
11
11
|
chain: IChain.Solana;
|
|
12
12
|
clusterUrl: string;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { BaseStreamClient } from "./BaseStreamClient.js";
|
|
2
2
|
import { IChain, } from "./types.js";
|
|
3
3
|
import { handleContractError } from "./utils.js";
|
|
4
|
-
import { AptosStreamClient } from "../aptos";
|
|
5
|
-
import { EvmStreamClient } from "../evm";
|
|
6
|
-
import { SolanaStreamClient } from "../solana";
|
|
7
|
-
import { SuiStreamClient } from "../sui";
|
|
4
|
+
import { AptosStreamClient } from "../aptos/index.js";
|
|
5
|
+
import { EvmStreamClient } from "../evm/index.js";
|
|
6
|
+
import { SolanaStreamClient, } from "../solana/index.js";
|
|
7
|
+
import { SuiStreamClient } from "../sui/index.js";
|
|
8
8
|
import { WITHDRAW_AVAILABLE_AMOUNT } from "./constants.js";
|
|
9
9
|
/** Generic Stream Client implementation that wrap Chain Client methods and enriches error messages if possible
|
|
10
10
|
* @property {StreamClientType} - Chain Client implementation
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
2
|
export declare const BASE_FEE = 1009900;
|
|
3
|
-
export declare const WITHDRAW_AVAILABLE_AMOUNT:
|
|
3
|
+
export declare const WITHDRAW_AVAILABLE_AMOUNT: BigNumber;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BigNumber from "bignumber.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 = BigNumber("18446744073709551615"); // Magical number to withdraw all available amount from a Contract
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
2
|
import { StreamType } from "./types.js";
|
|
3
3
|
interface ICalculateUnlockedAmount {
|
|
4
|
-
depositedAmount:
|
|
4
|
+
depositedAmount: BigNumber;
|
|
5
5
|
cliff: number;
|
|
6
|
-
cliffAmount:
|
|
6
|
+
cliffAmount: BigNumber;
|
|
7
7
|
end: number;
|
|
8
8
|
currentTimestamp: number;
|
|
9
9
|
lastRateChangeTime: number;
|
|
10
10
|
period: number;
|
|
11
|
-
amountPerPeriod:
|
|
12
|
-
fundsUnlockedAtLastRateChange:
|
|
11
|
+
amountPerPeriod: BigNumber;
|
|
12
|
+
fundsUnlockedAtLastRateChange: BigNumber;
|
|
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) => BigNumber;
|
|
15
15
|
export declare const isCliffCloseToDepositedAmount: (streamData: {
|
|
16
|
-
depositedAmount:
|
|
17
|
-
cliffAmount:
|
|
16
|
+
depositedAmount: BigNumber;
|
|
17
|
+
cliffAmount: BigNumber;
|
|
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: BigNumber;
|
|
25
|
+
cliffAmount: BigNumber;
|
|
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: BigNumber;
|
|
35
|
+
cliffAmount: BigNumber;
|
|
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: BigNumber;
|
|
45
|
+
cliffAmount: BigNumber;
|
|
46
46
|
}) => StreamType;
|
|
47
47
|
export {};
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BigNumber from "bignumber.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 BigNumber(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 = BigNumber(Math.floor((currentTimestamp - savedUnlockedFundsTime) / period))
|
|
12
|
+
.times(amountPerPeriod)
|
|
13
|
+
.plus(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.minus(BigNumber(1)));
|
|
18
18
|
};
|
|
19
19
|
export const isPayment = (streamData) => {
|
|
20
20
|
return streamData.canTopup;
|