@streamflow/stream 7.0.0-alpha.1 → 7.0.0-alpha.10
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 +65 -68
- package/dist/cjs/__tests__/aptos/streamClient.spec.js +83 -134
- package/dist/cjs/__tests__/common/GenericStreamClient.spec.js +9 -9
- package/dist/cjs/aptos/StreamClient.js +162 -367
- package/dist/cjs/aptos/constants.js +7 -8
- package/dist/cjs/aptos/index.js +3 -3
- package/dist/cjs/aptos/types.js +32 -41
- package/dist/cjs/aptos/utils.js +4 -4
- package/dist/cjs/aptos/wallet.js +20 -75
- package/dist/cjs/common/BaseStreamClient.js +11 -59
- package/dist/cjs/common/GenericStreamClient.js +46 -72
- package/dist/cjs/common/constants.js +2 -2
- package/dist/cjs/common/contractUtils.js +16 -17
- package/dist/cjs/common/utils.js +34 -84
- package/dist/cjs/evm/StreamClient.js +198 -456
- package/dist/cjs/evm/constants.js +19 -20
- package/dist/cjs/evm/types.js +25 -34
- package/dist/cjs/evm/utils.js +2 -2
- package/dist/cjs/index.js +10 -10
- package/dist/cjs/solana/StreamClient.js +608 -1090
- package/dist/cjs/solana/constants.js +16 -11
- package/dist/cjs/solana/instructions.js +76 -80
- package/dist/cjs/solana/layout.js +7 -8
- package/dist/cjs/solana/types.js +15 -25
- package/dist/cjs/solana/utils.js +77 -154
- package/dist/cjs/sui/StreamClient.js +325 -571
- package/dist/cjs/sui/constants.js +19 -20
- package/dist/cjs/sui/types.js +28 -62
- package/dist/cjs/sui/utils.js +7 -7
- package/dist/cjs/sui/wallet.js +13 -63
- 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.d.ts +3 -1
- package/dist/esm/solana/StreamClient.js +36 -20
- package/dist/esm/solana/constants.d.ts +3 -0
- package/dist/esm/solana/constants.js +6 -0
- package/dist/esm/solana/instructions.d.ts +17 -17
- package/dist/esm/solana/instructions.js +19 -18
- package/dist/esm/solana/types.d.ts +41 -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 +10 -11
package/dist/cjs/solana/utils.js
CHANGED
|
@@ -1,84 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
var __values = (this && this.__values) || function(o) {
|
|
50
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
51
|
-
if (m) return m.call(o);
|
|
52
|
-
if (o && typeof o.length === "number") return {
|
|
53
|
-
next: function () {
|
|
54
|
-
if (o && i >= o.length) o = void 0;
|
|
55
|
-
return { value: o && o[i++], done: !o };
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
59
|
-
};
|
|
60
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
61
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
62
4
|
};
|
|
63
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
64
|
-
exports.extractSolanaErrorCode = exports.sendAndConfirmStreamRawTransaction = exports.signAllTransactionWithRecipients = exports.decodeStream = void 0;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
6
|
+
exports.extractSolanaErrorCode = exports.sendAndConfirmStreamRawTransaction = exports.signAllTransactionWithRecipients = exports.decodeStream = exports.toBuffer = void 0;
|
|
7
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
8
|
+
const solana_1 = require("@streamflow/common/solana");
|
|
9
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
10
|
+
const layout_js_1 = require("./layout.js");
|
|
11
|
+
const constants_js_1 = require("./constants.js");
|
|
12
|
+
const decoder = new TextDecoder("utf-8");
|
|
13
|
+
const toUInt64String = (uintArr) => new DataView(uintArr.buffer, uintArr.byteOffset, uintArr.byteLength).getBigUint64(0, true).toString();
|
|
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;
|
|
21
|
+
const decodeStream = (buf) => {
|
|
22
|
+
const raw = layout_js_1.streamLayout.decode(buf);
|
|
74
23
|
return {
|
|
75
|
-
magic:
|
|
76
|
-
version:
|
|
77
|
-
createdAt:
|
|
78
|
-
withdrawnAmount:
|
|
79
|
-
canceledAt:
|
|
80
|
-
end:
|
|
81
|
-
lastWithdrawnAt:
|
|
24
|
+
magic: (0, bignumber_js_1.default)(toUInt64String(raw.magic)),
|
|
25
|
+
version: (0, bignumber_js_1.default)(toUInt8(raw.version)),
|
|
26
|
+
createdAt: (0, bignumber_js_1.default)(toUInt64String(raw.created_at)),
|
|
27
|
+
withdrawnAmount: (0, bignumber_js_1.default)(toUInt64String(raw.withdrawn_amount)),
|
|
28
|
+
canceledAt: (0, bignumber_js_1.default)(toUInt64String(raw.canceled_at)),
|
|
29
|
+
end: (0, bignumber_js_1.default)(toUInt64String(raw.end_time)),
|
|
30
|
+
lastWithdrawnAt: (0, bignumber_js_1.default)(toUInt64String(raw.last_withdrawn_at)),
|
|
82
31
|
sender: new web3_js_1.PublicKey(raw.sender),
|
|
83
32
|
senderTokens: new web3_js_1.PublicKey(raw.sender_tokens),
|
|
84
33
|
recipient: new web3_js_1.PublicKey(raw.recipient),
|
|
@@ -87,20 +36,20 @@ var decodeStream = function (buf) {
|
|
|
87
36
|
escrowTokens: new web3_js_1.PublicKey(raw.escrow_tokens),
|
|
88
37
|
streamflowTreasury: new web3_js_1.PublicKey(raw.streamflow_treasury),
|
|
89
38
|
streamflowTreasuryTokens: new web3_js_1.PublicKey(raw.streamflow_treasury_tokens),
|
|
90
|
-
streamflowFeeTotal:
|
|
91
|
-
streamflowFeeWithdrawn:
|
|
92
|
-
streamflowFeePercent:
|
|
93
|
-
partnerFeeTotal:
|
|
94
|
-
partnerFeeWithdrawn:
|
|
95
|
-
partnerFeePercent:
|
|
39
|
+
streamflowFeeTotal: (0, bignumber_js_1.default)(toUInt64String(raw.streamflow_fee_total)),
|
|
40
|
+
streamflowFeeWithdrawn: (0, bignumber_js_1.default)(toUInt64String(raw.streamflow_fee_withdrawn)),
|
|
41
|
+
streamflowFeePercent: (0, bignumber_js_1.default)(raw.streamflow_fee_percent),
|
|
42
|
+
partnerFeeTotal: (0, bignumber_js_1.default)(toUInt64String(raw.partner_fee_total)),
|
|
43
|
+
partnerFeeWithdrawn: (0, bignumber_js_1.default)(toUInt64String(raw.partner_fee_withdrawn)),
|
|
44
|
+
partnerFeePercent: (0, bignumber_js_1.default)(raw.partner_fee_percent),
|
|
96
45
|
partner: new web3_js_1.PublicKey(raw.partner),
|
|
97
46
|
partnerTokens: new web3_js_1.PublicKey(raw.partner_tokens),
|
|
98
|
-
start:
|
|
99
|
-
depositedAmount:
|
|
100
|
-
period:
|
|
101
|
-
amountPerPeriod:
|
|
102
|
-
cliff:
|
|
103
|
-
cliffAmount:
|
|
47
|
+
start: (0, bignumber_js_1.default)(toUInt64String(raw.start_time)),
|
|
48
|
+
depositedAmount: (0, bignumber_js_1.default)(toUInt64String(raw.net_amount_deposited)),
|
|
49
|
+
period: (0, bignumber_js_1.default)(toUInt64String(raw.period)),
|
|
50
|
+
amountPerPeriod: (0, bignumber_js_1.default)(toUInt64String(raw.amount_per_period)),
|
|
51
|
+
cliff: (0, bignumber_js_1.default)(toUInt64String(raw.cliff)),
|
|
52
|
+
cliffAmount: (0, bignumber_js_1.default)(toUInt64String(raw.cliff_amount)),
|
|
104
53
|
cancelableBySender: Boolean(raw.cancelable_by_sender),
|
|
105
54
|
cancelableByRecipient: Boolean(raw.cancelable_by_recipient),
|
|
106
55
|
automaticWithdrawal: Boolean(raw.automatic_withdrawal),
|
|
@@ -108,12 +57,12 @@ var decodeStream = function (buf) {
|
|
|
108
57
|
transferableByRecipient: Boolean(raw.transferable_by_recipient),
|
|
109
58
|
canTopup: Boolean(raw.can_topup),
|
|
110
59
|
name: decoder.decode(raw.stream_name),
|
|
111
|
-
withdrawFrequency:
|
|
60
|
+
withdrawFrequency: (0, bignumber_js_1.default)(toUInt64String(raw.withdraw_frequency)),
|
|
112
61
|
closed: Boolean(raw.closed),
|
|
113
|
-
currentPauseStart:
|
|
114
|
-
pauseCumulative:
|
|
115
|
-
lastRateChangeTime:
|
|
116
|
-
fundsUnlockedAtLastRateChange:
|
|
62
|
+
currentPauseStart: (0, bignumber_js_1.default)(toUInt64String(raw.current_pause_start)),
|
|
63
|
+
pauseCumulative: (0, bignumber_js_1.default)(toUInt64String(raw.pause_cumulative)),
|
|
64
|
+
lastRateChangeTime: (0, bignumber_js_1.default)(toUInt64String(raw.last_rate_change_time)),
|
|
65
|
+
fundsUnlockedAtLastRateChange: (0, bignumber_js_1.default)(toUInt64String(raw.funds_unlocked_at_last_rate_change)),
|
|
117
66
|
};
|
|
118
67
|
};
|
|
119
68
|
exports.decodeStream = decodeStream;
|
|
@@ -123,31 +72,26 @@ exports.decodeStream = decodeStream;
|
|
|
123
72
|
* @param {BatchItem[]} items - Multiple recipient contracts split into separate items
|
|
124
73
|
* @return {BatchItem[]} - Returns items with signatures.
|
|
125
74
|
*/
|
|
126
|
-
function signAllTransactionWithRecipients(sender, items) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
isWallet = (0, solana_1.isSignerWallet)(sender);
|
|
134
|
-
if (!isKeypair) return [3 /*break*/, 1];
|
|
135
|
-
return [2 /*return*/, items.map(function (t) {
|
|
136
|
-
t.tx.sign([sender]);
|
|
137
|
-
return { tx: t.tx, recipient: t.recipient };
|
|
138
|
-
})];
|
|
139
|
-
case 1:
|
|
140
|
-
if (!isWallet) return [3 /*break*/, 3];
|
|
141
|
-
return [4 /*yield*/, sender.signAllTransactions(items.map(function (t) { return t.tx; }))];
|
|
142
|
-
case 2:
|
|
143
|
-
signedTxs_1 = _a.sent();
|
|
144
|
-
return [2 /*return*/, items.map(function (item, index) { return (__assign(__assign({}, item), { tx: signedTxs_1[index] })); })];
|
|
145
|
-
case 3:
|
|
146
|
-
// If signer is not passed
|
|
147
|
-
return [2 /*return*/, []];
|
|
148
|
-
}
|
|
75
|
+
async function signAllTransactionWithRecipients(sender, items) {
|
|
76
|
+
const isKeypair = (0, solana_1.isSignerKeypair)(sender);
|
|
77
|
+
const isWallet = (0, solana_1.isSignerWallet)(sender);
|
|
78
|
+
if (isKeypair) {
|
|
79
|
+
return items.map((t) => {
|
|
80
|
+
t.tx.sign([sender]);
|
|
81
|
+
return { tx: t.tx, recipient: t.recipient };
|
|
149
82
|
});
|
|
150
|
-
}
|
|
83
|
+
}
|
|
84
|
+
else if (isWallet) {
|
|
85
|
+
const signedTxs = await sender.signAllTransactions(items.map((t) => t.tx));
|
|
86
|
+
return items.map((item, index) => ({
|
|
87
|
+
...item,
|
|
88
|
+
tx: signedTxs[index],
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
// If signer is not passed
|
|
93
|
+
return [];
|
|
94
|
+
}
|
|
151
95
|
}
|
|
152
96
|
exports.signAllTransactionWithRecipients = signAllTransactionWithRecipients;
|
|
153
97
|
/**
|
|
@@ -158,54 +102,33 @@ exports.signAllTransactionWithRecipients = signAllTransactionWithRecipients;
|
|
|
158
102
|
* @param throttleParams - rate or throttler instance to throttle TX sending - to not spam the blockchain too much
|
|
159
103
|
* @return {Promise<BatchItemResult>} - Returns settled transaction item
|
|
160
104
|
*/
|
|
161
|
-
function sendAndConfirmStreamRawTransaction(connection, batchItem, confirmationParams, throttleParams) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
return
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
case 2:
|
|
173
|
-
error_1 = _a.sent();
|
|
174
|
-
throw {
|
|
175
|
-
recipient: batchItem.recipient,
|
|
176
|
-
error: error_1,
|
|
177
|
-
};
|
|
178
|
-
case 3: return [2 /*return*/];
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
});
|
|
105
|
+
async function sendAndConfirmStreamRawTransaction(connection, batchItem, confirmationParams, throttleParams) {
|
|
106
|
+
try {
|
|
107
|
+
const completedTxSignature = await (0, solana_1.executeTransaction)(connection, batchItem.tx, confirmationParams, throttleParams);
|
|
108
|
+
return { ...batchItem, signature: completedTxSignature };
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
throw {
|
|
112
|
+
recipient: batchItem.recipient,
|
|
113
|
+
error,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
182
116
|
}
|
|
183
117
|
exports.sendAndConfirmStreamRawTransaction = sendAndConfirmStreamRawTransaction;
|
|
184
118
|
function extractSolanaErrorCode(errorText, logs) {
|
|
185
|
-
|
|
186
|
-
var match = constants_js_1.SOLANA_ERROR_MATCH_REGEX.exec(errorText);
|
|
119
|
+
let match = constants_js_1.SOLANA_ERROR_MATCH_REGEX.exec(errorText);
|
|
187
120
|
if (!match && logs) {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
if (match !== null) {
|
|
193
|
-
break;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
198
|
-
finally {
|
|
199
|
-
try {
|
|
200
|
-
if (logs_1_1 && !logs_1_1.done && (_a = logs_1.return)) _a.call(logs_1);
|
|
121
|
+
for (const logLine of logs) {
|
|
122
|
+
match = constants_js_1.SOLANA_ERROR_MATCH_REGEX.exec(logLine);
|
|
123
|
+
if (match !== null) {
|
|
124
|
+
break;
|
|
201
125
|
}
|
|
202
|
-
finally { if (e_1) throw e_1.error; }
|
|
203
126
|
}
|
|
204
127
|
}
|
|
205
128
|
if (!match) {
|
|
206
129
|
return null;
|
|
207
130
|
}
|
|
208
|
-
|
|
131
|
+
const errorCode = Number(match[1]);
|
|
209
132
|
return constants_js_1.SOLANA_ERROR_MAP[errorCode] || null;
|
|
210
133
|
}
|
|
211
134
|
exports.extractSolanaErrorCode = extractSolanaErrorCode;
|