@streamflow/stream 7.0.0-alpha.8 → 7.0.0
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 +22 -17
- package/dist/cjs/__tests__/aptos/streamClient.spec.js +4 -4
- package/dist/cjs/aptos/types.js +12 -12
- package/dist/cjs/aptos/utils.js +2 -3
- package/dist/cjs/common/constants.js +4 -3
- package/dist/cjs/common/contractUtils.js +23 -7
- package/dist/cjs/common/types.js +30 -1
- package/dist/cjs/common/utils.js +23 -20
- package/dist/cjs/evm/StreamClient.js +7 -7
- package/dist/cjs/evm/types.js +12 -12
- package/dist/cjs/evm/utils.js +1 -2
- package/dist/cjs/solana/StreamClient.js +303 -152
- package/dist/cjs/solana/constants.js +29 -1
- package/dist/cjs/solana/descriptor/idl/streamflow_aligned_unlocks.json +1471 -0
- package/dist/cjs/solana/descriptor/streamflow_aligned_unlocks.js +2 -0
- package/dist/cjs/solana/index.js +2 -1
- package/dist/cjs/solana/instructions.js +18 -19
- package/dist/cjs/solana/lib/derive-accounts.js +17 -0
- package/dist/cjs/solana/{utils.js → lib/utils.js} +32 -39
- package/dist/cjs/solana/types.js +26 -3
- package/dist/cjs/sui/StreamClient.js +1 -1
- package/dist/cjs/sui/types.js +12 -12
- package/dist/cjs/sui/utils.js +1 -2
- package/dist/cjs/sui/wallet.js +2 -2
- package/dist/esm/__tests__/aptos/streamClient.spec.js +4 -4
- package/dist/esm/aptos/types.d.ts +14 -14
- package/dist/esm/aptos/types.js +13 -13
- package/dist/esm/common/constants.d.ts +3 -2
- package/dist/esm/common/constants.js +3 -2
- package/dist/esm/common/contractUtils.d.ts +18 -15
- package/dist/esm/common/contractUtils.js +19 -6
- package/dist/esm/common/types.d.ts +112 -57
- package/dist/esm/common/types.js +29 -0
- package/dist/esm/common/utils.d.ts +11 -11
- package/dist/esm/common/utils.js +19 -16
- package/dist/esm/evm/StreamClient.d.ts +2 -2
- package/dist/esm/evm/StreamClient.js +7 -7
- package/dist/esm/evm/types.d.ts +14 -14
- package/dist/esm/evm/types.js +13 -13
- package/dist/esm/solana/StreamClient.d.ts +22 -16
- package/dist/esm/solana/StreamClient.js +306 -154
- package/dist/esm/solana/constants.d.ts +14 -1
- package/dist/esm/solana/constants.js +29 -1
- package/dist/esm/solana/descriptor/idl/streamflow_aligned_unlocks.json +1471 -0
- package/dist/esm/solana/descriptor/streamflow_aligned_unlocks.d.ts +1272 -0
- package/dist/esm/solana/descriptor/streamflow_aligned_unlocks.js +1 -0
- package/dist/esm/solana/index.d.ts +2 -1
- package/dist/esm/solana/index.js +2 -1
- package/dist/esm/solana/instructions.d.ts +17 -17
- package/dist/esm/solana/instructions.js +18 -19
- package/dist/esm/solana/layout.d.ts +0 -1
- package/dist/esm/solana/lib/derive-accounts.d.ts +4 -0
- package/dist/esm/solana/lib/derive-accounts.js +11 -0
- package/dist/esm/solana/{utils.d.ts → lib/utils.d.ts} +1 -4
- package/dist/esm/solana/{utils.js → lib/utils.js} +28 -34
- package/dist/esm/solana/types.d.ts +67 -40
- package/dist/esm/solana/types.js +32 -4
- package/dist/esm/sui/StreamClient.js +1 -1
- package/dist/esm/sui/types.d.ts +14 -14
- package/dist/esm/sui/types.js +13 -13
- package/package.json +11 -9
package/dist/cjs/solana/index.js
CHANGED
|
@@ -31,7 +31,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
31
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
32
|
exports.timelockIDL = exports.constants = void 0;
|
|
33
33
|
__exportStar(require("./StreamClient.js"), exports);
|
|
34
|
-
__exportStar(require("./utils.js"), exports);
|
|
34
|
+
__exportStar(require("./lib/utils.js"), exports);
|
|
35
|
+
__exportStar(require("./lib/derive-accounts.js"), exports);
|
|
35
36
|
__exportStar(require("./types.js"), exports);
|
|
36
37
|
__exportStar(require("./instructions.js"), exports);
|
|
37
38
|
exports.constants = __importStar(require("./constants.js"));
|
|
@@ -28,7 +28,6 @@ const buffer_1 = require("buffer");
|
|
|
28
28
|
const web3_js_1 = require("@solana/web3.js");
|
|
29
29
|
const node_crypto_1 = require("node:crypto");
|
|
30
30
|
const Layout = __importStar(require("./layout.js"));
|
|
31
|
-
const utils_js_1 = require("./utils.js");
|
|
32
31
|
const hasher = () => (0, node_crypto_1.createHash)("sha256");
|
|
33
32
|
const sha256 = {
|
|
34
33
|
digest: (data) => new Uint8Array(hasher().update(data).digest()),
|
|
@@ -70,12 +69,12 @@ const createStreamInstruction = (data, programId, accounts) => {
|
|
|
70
69
|
const encodedUIntArray = new TextEncoder().encode(data.name);
|
|
71
70
|
const streamNameBuffer = buffer_1.Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
|
|
72
71
|
const decodedData = {
|
|
73
|
-
start_time: (
|
|
74
|
-
net_amount_deposited: (
|
|
75
|
-
period: (
|
|
76
|
-
amount_per_period: (
|
|
77
|
-
cliff: (
|
|
78
|
-
cliff_amount: (
|
|
72
|
+
start_time: data.start.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
73
|
+
net_amount_deposited: data.depositedAmount.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
74
|
+
period: data.period.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
75
|
+
amount_per_period: data.amountPerPeriod.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
76
|
+
cliff: data.cliff.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
77
|
+
cliff_amount: data.cliffAmount.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
79
78
|
cancelable_by_sender: Number(data.cancelableBySender),
|
|
80
79
|
cancelable_by_recipient: Number(data.cancelableByRecipient),
|
|
81
80
|
automatic_withdrawal: Number(data.automaticWithdrawal),
|
|
@@ -87,7 +86,7 @@ const createStreamInstruction = (data, programId, accounts) => {
|
|
|
87
86
|
_can_update_rate_discriminator: 1,
|
|
88
87
|
pausable: Number(data.canPause),
|
|
89
88
|
stream_name: streamNameBuffer,
|
|
90
|
-
withdraw_frequency: (
|
|
89
|
+
withdraw_frequency: data.withdrawFrequency.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
91
90
|
};
|
|
92
91
|
const encodeLength = Layout.createStreamLayout.encode(decodedData, bufferData);
|
|
93
92
|
bufferData = bufferData.slice(0, encodeLength);
|
|
@@ -124,12 +123,12 @@ const createUncheckedStreamInstruction = (data, programId, accounts) => {
|
|
|
124
123
|
const encodedUIntArray = new TextEncoder().encode(data.name);
|
|
125
124
|
const streamNameBuffer = buffer_1.Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
|
|
126
125
|
const decodedData = {
|
|
127
|
-
start_time: (
|
|
128
|
-
net_amount_deposited: (
|
|
129
|
-
period: (
|
|
130
|
-
amount_per_period: (
|
|
131
|
-
cliff: (
|
|
132
|
-
cliff_amount: (
|
|
126
|
+
start_time: data.start.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
127
|
+
net_amount_deposited: data.depositedAmount.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
128
|
+
period: data.period.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
129
|
+
amount_per_period: data.amountPerPeriod.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
130
|
+
cliff: data.cliff.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
131
|
+
cliff_amount: data.cliffAmount.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
133
132
|
cancelable_by_sender: Number(data.cancelableBySender),
|
|
134
133
|
cancelable_by_recipient: Number(data.cancelableByRecipient),
|
|
135
134
|
automatic_withdrawal: Number(data.automaticWithdrawal),
|
|
@@ -137,7 +136,7 @@ const createUncheckedStreamInstruction = (data, programId, accounts) => {
|
|
|
137
136
|
transferable_by_recipient: Number(data.transferableByRecipient),
|
|
138
137
|
can_topup: Number(data.canTopup),
|
|
139
138
|
stream_name: streamNameBuffer,
|
|
140
|
-
withdraw_frequency: (
|
|
139
|
+
withdraw_frequency: data.withdrawFrequency.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
141
140
|
recipient: data.recipient.toBuffer(),
|
|
142
141
|
partner: data.partner.toBuffer(),
|
|
143
142
|
pausable: Number(data.canPause),
|
|
@@ -175,7 +174,7 @@ const withdrawStreamInstruction = (amount, programId, { authority, recipient, re
|
|
|
175
174
|
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
176
175
|
];
|
|
177
176
|
let data = buffer_1.Buffer.alloc(Layout.withdrawStreamLayout.span);
|
|
178
|
-
const decodedData = { amount: (
|
|
177
|
+
const decodedData = { amount: amount.toArrayLike(buffer_1.Buffer, "le", 8) };
|
|
179
178
|
const encodeLength = Layout.withdrawStreamLayout.encode(decodedData, data);
|
|
180
179
|
data = data.slice(0, encodeLength);
|
|
181
180
|
data = buffer_1.Buffer.concat([buffer_1.Buffer.from(sha256.digest("global:withdraw")).slice(0, 8), data, buffer_1.Buffer.alloc(10)]);
|
|
@@ -196,8 +195,8 @@ const updateStreamInstruction = (params, programId, { authority, metadata, withd
|
|
|
196
195
|
let data = buffer_1.Buffer.alloc(100);
|
|
197
196
|
const decodedData = {
|
|
198
197
|
enable_automatic_withdrawal: Number(params.enableAutomaticWithdrawal),
|
|
199
|
-
withdraw_frequency: params.withdrawFrequency ? (
|
|
200
|
-
amount_per_period: params.amountPerPeriod ? (
|
|
198
|
+
withdraw_frequency: params.withdrawFrequency ? params.withdrawFrequency.toArrayLike(buffer_1.Buffer, "le", 8) : undefined,
|
|
199
|
+
amount_per_period: params.amountPerPeriod ? params.amountPerPeriod.toArrayLike(buffer_1.Buffer, "le", 8) : undefined,
|
|
201
200
|
};
|
|
202
201
|
const encodeLength = Layout.encodeUpdateStream(decodedData, data);
|
|
203
202
|
data = data.slice(0, encodeLength);
|
|
@@ -277,7 +276,7 @@ const topupStreamInstruction = (amount, programId, { sender, senderTokens, metad
|
|
|
277
276
|
{ pubkey: systemProgram, isSigner: false, isWritable: false },
|
|
278
277
|
];
|
|
279
278
|
let data = buffer_1.Buffer.alloc(Layout.topupStreamLayout.span);
|
|
280
|
-
const decodedData = { amount: (
|
|
279
|
+
const decodedData = { amount: amount.toArrayLike(buffer_1.Buffer, "le", 8) };
|
|
281
280
|
const encodeLength = Layout.topupStreamLayout.encode(decodedData, data);
|
|
282
281
|
data = data.slice(0, encodeLength);
|
|
283
282
|
data = buffer_1.Buffer.concat([buffer_1.Buffer.from(sha256.digest("global:topup")).slice(0, 8), data, buffer_1.Buffer.alloc(10)]);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deriveTestOraclePDA = exports.deriveEscrowPDA = exports.deriveContractPDA = void 0;
|
|
4
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
const deriveContractPDA = (programId, streamMetadata) => {
|
|
7
|
+
return web3_js_1.PublicKey.findProgramAddressSync([constants_1.CONTRACT_SEED, streamMetadata.toBuffer()], programId)[0];
|
|
8
|
+
};
|
|
9
|
+
exports.deriveContractPDA = deriveContractPDA;
|
|
10
|
+
const deriveEscrowPDA = (programId, streamMetadata) => {
|
|
11
|
+
return web3_js_1.PublicKey.findProgramAddressSync([constants_1.ESCROW_SEED, streamMetadata.toBuffer()], programId)[0];
|
|
12
|
+
};
|
|
13
|
+
exports.deriveEscrowPDA = deriveEscrowPDA;
|
|
14
|
+
const deriveTestOraclePDA = (programId, mint, creator) => {
|
|
15
|
+
return web3_js_1.PublicKey.findProgramAddressSync([constants_1.TEST_ORACLE_SEED, mint.toBuffer(), creator.toBuffer()], programId)[0];
|
|
16
|
+
};
|
|
17
|
+
exports.deriveTestOraclePDA = deriveTestOraclePDA;
|
|
@@ -3,31 +3,27 @@ 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.
|
|
6
|
+
exports.decodeStream = void 0;
|
|
7
|
+
exports.signAllTransactionWithRecipients = signAllTransactionWithRecipients;
|
|
8
|
+
exports.sendAndConfirmStreamRawTransaction = sendAndConfirmStreamRawTransaction;
|
|
9
|
+
exports.extractSolanaErrorCode = extractSolanaErrorCode;
|
|
7
10
|
const web3_js_1 = require("@solana/web3.js");
|
|
8
11
|
const solana_1 = require("@streamflow/common/solana");
|
|
9
|
-
const
|
|
10
|
-
const layout_js_1 = require("
|
|
11
|
-
const constants_js_1 = require("
|
|
12
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
13
|
+
const layout_js_1 = require("../layout.js");
|
|
14
|
+
const constants_js_1 = require("../constants.js");
|
|
12
15
|
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;
|
|
16
|
+
const LE = "le"; //little endian
|
|
21
17
|
const decodeStream = (buf) => {
|
|
22
18
|
const raw = layout_js_1.streamLayout.decode(buf);
|
|
23
19
|
return {
|
|
24
|
-
magic:
|
|
25
|
-
version:
|
|
26
|
-
createdAt:
|
|
27
|
-
withdrawnAmount:
|
|
28
|
-
canceledAt:
|
|
29
|
-
end:
|
|
30
|
-
lastWithdrawnAt:
|
|
20
|
+
magic: new bn_js_1.default(raw.magic, LE),
|
|
21
|
+
version: new bn_js_1.default(raw.version, LE),
|
|
22
|
+
createdAt: new bn_js_1.default(raw.created_at, LE),
|
|
23
|
+
withdrawnAmount: new bn_js_1.default(raw.withdrawn_amount, LE),
|
|
24
|
+
canceledAt: new bn_js_1.default(raw.canceled_at, LE),
|
|
25
|
+
end: new bn_js_1.default(raw.end_time, LE),
|
|
26
|
+
lastWithdrawnAt: new bn_js_1.default(raw.last_withdrawn_at, LE),
|
|
31
27
|
sender: new web3_js_1.PublicKey(raw.sender),
|
|
32
28
|
senderTokens: new web3_js_1.PublicKey(raw.sender_tokens),
|
|
33
29
|
recipient: new web3_js_1.PublicKey(raw.recipient),
|
|
@@ -36,20 +32,20 @@ const decodeStream = (buf) => {
|
|
|
36
32
|
escrowTokens: new web3_js_1.PublicKey(raw.escrow_tokens),
|
|
37
33
|
streamflowTreasury: new web3_js_1.PublicKey(raw.streamflow_treasury),
|
|
38
34
|
streamflowTreasuryTokens: new web3_js_1.PublicKey(raw.streamflow_treasury_tokens),
|
|
39
|
-
streamflowFeeTotal:
|
|
40
|
-
streamflowFeeWithdrawn:
|
|
41
|
-
streamflowFeePercent:
|
|
42
|
-
partnerFeeTotal:
|
|
43
|
-
partnerFeeWithdrawn:
|
|
44
|
-
partnerFeePercent:
|
|
35
|
+
streamflowFeeTotal: new bn_js_1.default(raw.streamflow_fee_total, LE),
|
|
36
|
+
streamflowFeeWithdrawn: new bn_js_1.default(raw.streamflow_fee_withdrawn, LE),
|
|
37
|
+
streamflowFeePercent: new bn_js_1.default(raw.streamflow_fee_percent, LE),
|
|
38
|
+
partnerFeeTotal: new bn_js_1.default(raw.partner_fee_total, LE),
|
|
39
|
+
partnerFeeWithdrawn: new bn_js_1.default(raw.partner_fee_withdrawn, LE),
|
|
40
|
+
partnerFeePercent: new bn_js_1.default(raw.partner_fee_percent, LE),
|
|
45
41
|
partner: new web3_js_1.PublicKey(raw.partner),
|
|
46
42
|
partnerTokens: new web3_js_1.PublicKey(raw.partner_tokens),
|
|
47
|
-
start:
|
|
48
|
-
depositedAmount:
|
|
49
|
-
period:
|
|
50
|
-
amountPerPeriod:
|
|
51
|
-
cliff:
|
|
52
|
-
cliffAmount:
|
|
43
|
+
start: new bn_js_1.default(raw.start_time, LE),
|
|
44
|
+
depositedAmount: new bn_js_1.default(raw.net_amount_deposited, LE),
|
|
45
|
+
period: new bn_js_1.default(raw.period, LE),
|
|
46
|
+
amountPerPeriod: new bn_js_1.default(raw.amount_per_period, LE),
|
|
47
|
+
cliff: new bn_js_1.default(raw.cliff, LE),
|
|
48
|
+
cliffAmount: new bn_js_1.default(raw.cliff_amount, LE),
|
|
53
49
|
cancelableBySender: Boolean(raw.cancelable_by_sender),
|
|
54
50
|
cancelableByRecipient: Boolean(raw.cancelable_by_recipient),
|
|
55
51
|
automaticWithdrawal: Boolean(raw.automatic_withdrawal),
|
|
@@ -57,12 +53,12 @@ const decodeStream = (buf) => {
|
|
|
57
53
|
transferableByRecipient: Boolean(raw.transferable_by_recipient),
|
|
58
54
|
canTopup: Boolean(raw.can_topup),
|
|
59
55
|
name: decoder.decode(raw.stream_name),
|
|
60
|
-
withdrawFrequency:
|
|
56
|
+
withdrawFrequency: new bn_js_1.default(raw.withdraw_frequency, LE),
|
|
61
57
|
closed: Boolean(raw.closed),
|
|
62
|
-
currentPauseStart:
|
|
63
|
-
pauseCumulative:
|
|
64
|
-
lastRateChangeTime:
|
|
65
|
-
fundsUnlockedAtLastRateChange:
|
|
58
|
+
currentPauseStart: new bn_js_1.default(raw.current_pause_start, LE),
|
|
59
|
+
pauseCumulative: new bn_js_1.default(raw.pause_cumulative, LE),
|
|
60
|
+
lastRateChangeTime: new bn_js_1.default(raw.last_rate_change_time, LE),
|
|
61
|
+
fundsUnlockedAtLastRateChange: new bn_js_1.default(raw.funds_unlocked_at_last_rate_change, LE),
|
|
66
62
|
};
|
|
67
63
|
};
|
|
68
64
|
exports.decodeStream = decodeStream;
|
|
@@ -93,7 +89,6 @@ async function signAllTransactionWithRecipients(sender, items) {
|
|
|
93
89
|
return [];
|
|
94
90
|
}
|
|
95
91
|
}
|
|
96
|
-
exports.signAllTransactionWithRecipients = signAllTransactionWithRecipients;
|
|
97
92
|
/**
|
|
98
93
|
* Sign passed BatchItems with wallet request or KeyPair
|
|
99
94
|
* @param {Connection} connection - Solana web3 connection object.
|
|
@@ -114,7 +109,6 @@ async function sendAndConfirmStreamRawTransaction(connection, batchItem, confirm
|
|
|
114
109
|
};
|
|
115
110
|
}
|
|
116
111
|
}
|
|
117
|
-
exports.sendAndConfirmStreamRawTransaction = sendAndConfirmStreamRawTransaction;
|
|
118
112
|
function extractSolanaErrorCode(errorText, logs) {
|
|
119
113
|
let match = constants_js_1.SOLANA_ERROR_MATCH_REGEX.exec(errorText);
|
|
120
114
|
if (!match && logs) {
|
|
@@ -131,4 +125,3 @@ function extractSolanaErrorCode(errorText, logs) {
|
|
|
131
125
|
const errorCode = Number(match[1]);
|
|
132
126
|
return constants_js_1.SOLANA_ERROR_MAP[errorCode] || null;
|
|
133
127
|
}
|
|
134
|
-
exports.extractSolanaErrorCode = extractSolanaErrorCode;
|
package/dist/cjs/solana/types.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Contract = void 0;
|
|
3
|
+
exports.AlignedContract = exports.Contract = exports.ContractError = exports.ICluster = exports.IChain = void 0;
|
|
4
4
|
const contractUtils_js_1 = require("../common/contractUtils.js");
|
|
5
5
|
const utils_js_1 = require("../common/utils.js");
|
|
6
|
+
const constants_js_1 = require("./constants.js");
|
|
7
|
+
var common_1 = require("@streamflow/common");
|
|
8
|
+
Object.defineProperty(exports, "IChain", { enumerable: true, get: function () { return common_1.IChain; } });
|
|
9
|
+
Object.defineProperty(exports, "ICluster", { enumerable: true, get: function () { return common_1.ICluster; } });
|
|
10
|
+
Object.defineProperty(exports, "ContractError", { enumerable: true, get: function () { return common_1.ContractError; } });
|
|
6
11
|
class Contract {
|
|
7
12
|
constructor(stream) {
|
|
8
13
|
this.magic = stream.magic.toNumber();
|
|
@@ -10,7 +15,8 @@ class Contract {
|
|
|
10
15
|
this.createdAt = stream.createdAt.toNumber();
|
|
11
16
|
this.withdrawnAmount = stream.withdrawnAmount;
|
|
12
17
|
this.canceledAt = stream.canceledAt.toNumber();
|
|
13
|
-
|
|
18
|
+
// for aligned contracts end time can be an invalid timeValue
|
|
19
|
+
this.end = (0, contractUtils_js_1.decodeEndTime)(stream.end);
|
|
14
20
|
this.lastWithdrawnAt = stream.lastWithdrawnAt.toNumber();
|
|
15
21
|
this.sender = stream.sender.toBase58();
|
|
16
22
|
this.senderTokens = stream.senderTokens.toBase58();
|
|
@@ -48,6 +54,7 @@ class Contract {
|
|
|
48
54
|
this.lastRateChangeTime = stream.lastRateChangeTime.toNumber();
|
|
49
55
|
this.fundsUnlockedAtLastRateChange = stream.fundsUnlockedAtLastRateChange;
|
|
50
56
|
this.type = (0, contractUtils_js_1.buildStreamType)(this);
|
|
57
|
+
this.isAligned = false;
|
|
51
58
|
}
|
|
52
59
|
unlocked(currentTimestamp) {
|
|
53
60
|
return (0, contractUtils_js_1.calculateUnlockedAmount)({
|
|
@@ -56,7 +63,23 @@ class Contract {
|
|
|
56
63
|
});
|
|
57
64
|
}
|
|
58
65
|
remaining(decimals) {
|
|
59
|
-
return (0, utils_js_1.
|
|
66
|
+
return (0, utils_js_1.getNumberFromBN)(this.depositedAmount.sub(this.withdrawnAmount), decimals);
|
|
60
67
|
}
|
|
61
68
|
}
|
|
62
69
|
exports.Contract = Contract;
|
|
70
|
+
class AlignedContract extends Contract {
|
|
71
|
+
constructor(stream, alignedProxy) {
|
|
72
|
+
super(stream);
|
|
73
|
+
this.minPrice = (0, utils_js_1.getNumberFromBN)(alignedProxy.minPrice, constants_js_1.ALIGNED_PRECISION_FACTOR_POW);
|
|
74
|
+
this.maxPrice = (0, utils_js_1.getNumberFromBN)(alignedProxy.maxPrice, constants_js_1.ALIGNED_PRECISION_FACTOR_POW);
|
|
75
|
+
this.minPercentage = (0, utils_js_1.getNumberFromBN)(alignedProxy.minPercentage, constants_js_1.ALIGNED_PRECISION_FACTOR_POW);
|
|
76
|
+
this.maxPercentage = (0, utils_js_1.getNumberFromBN)(alignedProxy.maxPercentage, constants_js_1.ALIGNED_PRECISION_FACTOR_POW);
|
|
77
|
+
this.oracleType = (Object.keys(alignedProxy.priceOracleType).find((key) => !!key) || "none");
|
|
78
|
+
this.tickSize = alignedProxy.tickSize.toNumber();
|
|
79
|
+
this.priceOracle = this.oracleType === "none" ? undefined : alignedProxy.priceOracle.toBase58();
|
|
80
|
+
this.sender = alignedProxy.sender.toBase58();
|
|
81
|
+
this.canceledAt = alignedProxy.streamCanceledTime.toNumber();
|
|
82
|
+
this.proxyAddress = stream.sender.toBase58();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.AlignedContract = AlignedContract;
|
|
@@ -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;
|
package/dist/cjs/sui/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractSuiErrorInfo =
|
|
3
|
+
exports.extractSuiErrorInfo = extractSuiErrorInfo;
|
|
4
4
|
const constants_js_1 = require("./constants.js");
|
|
5
5
|
function extractSuiErrorInfo(errorText) {
|
|
6
6
|
const error = { text: errorText };
|
|
@@ -24,4 +24,3 @@ function extractSuiErrorInfo(errorText) {
|
|
|
24
24
|
}
|
|
25
25
|
return error;
|
|
26
26
|
}
|
|
27
|
-
exports.extractSuiErrorInfo = extractSuiErrorInfo;
|
package/dist/cjs/sui/wallet.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SuiWalletWrapper =
|
|
3
|
+
exports.SuiWalletWrapper = void 0;
|
|
4
|
+
exports.isSignerKeypair = isSignerKeypair;
|
|
4
5
|
const cryptography_1 = require("@mysten/sui.js/cryptography");
|
|
5
6
|
/**
|
|
6
7
|
* Utility function to check if the transaction initiator is a Wallet object
|
|
@@ -13,7 +14,6 @@ function isSignerKeypair(walletOrKeypair) {
|
|
|
13
14
|
walletOrKeypair.constructor.name === cryptography_1.Keypair.prototype.constructor.name ||
|
|
14
15
|
"export" in walletOrKeypair);
|
|
15
16
|
}
|
|
16
|
-
exports.isSignerKeypair = isSignerKeypair;
|
|
17
17
|
class SuiWalletWrapper {
|
|
18
18
|
constructor(wallet, client) {
|
|
19
19
|
this.client = client;
|
|
@@ -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,7 +1,7 @@
|
|
|
1
1
|
import { AptosAccount } from "aptos";
|
|
2
2
|
import { WalletContextState } from "@manahippo/aptos-wallet-adapter";
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
3
|
+
import BN from "bn.js";
|
|
4
|
+
import { LinearStream, StreamType } from "../common/types.js";
|
|
5
5
|
export interface ICreateStreamAptosExt {
|
|
6
6
|
senderWallet: WalletContextState | AptosAccount;
|
|
7
7
|
}
|
|
@@ -59,11 +59,11 @@ export interface ConfigResource {
|
|
|
59
59
|
tx_fee: string;
|
|
60
60
|
withdrawor: string;
|
|
61
61
|
}
|
|
62
|
-
export declare class Contract implements
|
|
62
|
+
export declare class Contract implements LinearStream {
|
|
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,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BN from "bn.js";
|
|
2
|
+
export declare const MAX_SAFE_UNIX_TIME_VALUE = 8640000000000;
|
|
2
3
|
export declare const BASE_FEE = 1009900;
|
|
3
|
-
export declare const WITHDRAW_AVAILABLE_AMOUNT:
|
|
4
|
+
export declare const WITHDRAW_AVAILABLE_AMOUNT: BN;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BN from "bn.js";
|
|
2
|
+
export const MAX_SAFE_UNIX_TIME_VALUE = 8640000000000;
|
|
2
3
|
export const BASE_FEE = 1009900; // Buffer to include usual fees when calculating stream amount
|
|
3
|
-
export const WITHDRAW_AVAILABLE_AMOUNT =
|
|
4
|
+
export const WITHDRAW_AVAILABLE_AMOUNT = new BN("18446744073709551615"); // Magical number to withdraw all available amount from a Contract
|