@streamflow/stream 7.0.0-alpha.2 → 7.0.0-alpha.20
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 +70 -67
- 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 +28 -37
- 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 +4 -3
- package/dist/cjs/common/contractUtils.js +33 -18
- package/dist/cjs/common/types.js +30 -1
- package/dist/cjs/common/utils.js +38 -80
- 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 +759 -1090
- package/dist/cjs/solana/constants.js +44 -11
- 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 +75 -81
- package/dist/cjs/solana/layout.js +7 -8
- package/dist/cjs/solana/lib/derive-accounts.js +17 -0
- package/dist/cjs/solana/lib/utils.js +127 -0
- package/dist/cjs/solana/types.js +40 -27
- 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 +14 -14
- 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 +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/index.d.ts +9 -9
- package/dist/esm/index.js +9 -9
- package/dist/esm/solana/StreamClient.d.ts +24 -16
- package/dist/esm/solana/StreamClient.js +324 -156
- package/dist/esm/solana/constants.d.ts +17 -0
- package/dist/esm/solana/constants.js +35 -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/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 -3
- package/dist/esm/solana/{utils.js → lib/utils.js} +28 -34
- package/dist/esm/solana/types.d.ts +72 -39
- 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 +12 -10
- package/dist/cjs/solana/utils.js +0 -222
package/dist/cjs/aptos/types.js
CHANGED
|
@@ -1,31 +1,20 @@
|
|
|
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
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
16
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
6
|
exports.Contract = void 0;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
7
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
8
|
+
const buffer_1 = require("buffer");
|
|
9
|
+
const contractUtils_js_1 = require("../common/contractUtils.js");
|
|
10
|
+
const utils_js_1 = require("./utils.js");
|
|
11
|
+
const utils_js_2 = require("../common/utils.js");
|
|
12
|
+
class Contract {
|
|
13
|
+
constructor(stream, tokenId) {
|
|
25
14
|
this.magic = 0;
|
|
26
15
|
this.version = 0;
|
|
27
16
|
this.createdAt = parseInt(stream.created);
|
|
28
|
-
this.withdrawnAmount =
|
|
17
|
+
this.withdrawnAmount = new bn_js_1.default(stream.withdrawn);
|
|
29
18
|
this.canceledAt = parseInt(stream.canceled_at);
|
|
30
19
|
this.end = parseInt(stream.end);
|
|
31
20
|
this.lastWithdrawnAt = parseInt(stream.last_withdrawn_at);
|
|
@@ -37,42 +26,44 @@ var Contract = /** @class */ (function () {
|
|
|
37
26
|
this.escrowTokens = "";
|
|
38
27
|
this.streamflowTreasury = "";
|
|
39
28
|
this.streamflowTreasuryTokens = "";
|
|
40
|
-
this.streamflowFeeTotal =
|
|
41
|
-
this.streamflowFeeWithdrawn =
|
|
29
|
+
this.streamflowFeeTotal = new bn_js_1.default(0);
|
|
30
|
+
this.streamflowFeeWithdrawn = new bn_js_1.default(0);
|
|
42
31
|
this.streamflowFeePercent = parseInt(stream.fees.streamflow_fee_percentage) / 10000;
|
|
43
|
-
this.partnerFeeTotal =
|
|
44
|
-
this.partnerFeeWithdrawn =
|
|
32
|
+
this.partnerFeeTotal = new bn_js_1.default(0);
|
|
33
|
+
this.partnerFeeWithdrawn = new bn_js_1.default(0);
|
|
45
34
|
this.partnerFeePercent = 0;
|
|
46
35
|
this.partner = "";
|
|
47
36
|
this.partnerTokens = "";
|
|
48
37
|
this.start = parseInt(stream.start);
|
|
49
|
-
this.depositedAmount =
|
|
38
|
+
this.depositedAmount = new bn_js_1.default(stream.amount);
|
|
50
39
|
this.period = parseInt(stream.period);
|
|
51
|
-
this.amountPerPeriod =
|
|
40
|
+
this.amountPerPeriod = new bn_js_1.default(stream.amount_per_period);
|
|
52
41
|
this.cliff = parseInt(stream.start);
|
|
53
|
-
this.cliffAmount =
|
|
42
|
+
this.cliffAmount = new bn_js_1.default(stream.cliff_amount);
|
|
54
43
|
this.cancelableBySender = stream.meta.cancelable_by_sender;
|
|
55
44
|
this.cancelableByRecipient = stream.meta.cancelable_by_recipient;
|
|
56
45
|
this.automaticWithdrawal = stream.meta.automatic_withdrawal;
|
|
57
46
|
this.transferableBySender = stream.meta.transferable_by_sender;
|
|
58
47
|
this.transferableByRecipient = stream.meta.transferable_by_recipient;
|
|
59
48
|
this.canTopup = stream.meta.can_topup;
|
|
60
|
-
|
|
49
|
+
const name = stream.meta.contract_name.replace("0x", "");
|
|
61
50
|
this.name = buffer_1.Buffer.from(name, "hex").toString("utf8");
|
|
62
51
|
this.withdrawalFrequency = parseInt(stream.meta.withdrawal_frequency);
|
|
63
52
|
this.closed = stream.closed;
|
|
64
53
|
this.currentPauseStart = parseInt(stream.current_pause_start);
|
|
65
|
-
this.pauseCumulative =
|
|
54
|
+
this.pauseCumulative = new bn_js_1.default(stream.pause_cumulative);
|
|
66
55
|
this.lastRateChangeTime = parseInt(stream.last_rate_change_time);
|
|
67
|
-
this.fundsUnlockedAtLastRateChange =
|
|
56
|
+
this.fundsUnlockedAtLastRateChange = new bn_js_1.default(stream.funds_unlocked_at_last_rate_change);
|
|
68
57
|
this.type = (0, contractUtils_js_1.buildStreamType)(this);
|
|
69
58
|
}
|
|
70
|
-
|
|
71
|
-
return (0, contractUtils_js_1.calculateUnlockedAmount)(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
59
|
+
unlocked(currentTimestamp) {
|
|
60
|
+
return (0, contractUtils_js_1.calculateUnlockedAmount)({
|
|
61
|
+
...this,
|
|
62
|
+
currentTimestamp,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
remaining(decimals) {
|
|
66
|
+
return (0, utils_js_2.getNumberFromBN)(this.depositedAmount.sub(this.withdrawnAmount), decimals);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
78
69
|
exports.Contract = Contract;
|
package/dist/cjs/aptos/utils.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.normalizeAptosAddress = exports.extractAptosErrorCode = void 0;
|
|
4
|
-
|
|
4
|
+
const constants_js_1 = require("./constants.js");
|
|
5
5
|
function extractAptosErrorCode(errorText) {
|
|
6
|
-
|
|
6
|
+
const match = constants_js_1.APTOS_ERROR_MATCH_REGEX.exec(errorText);
|
|
7
7
|
if (!match) {
|
|
8
8
|
return null;
|
|
9
9
|
}
|
|
@@ -25,11 +25,11 @@ function normalizeAptosAddress(address) {
|
|
|
25
25
|
if (isAddressSpecial(address)) {
|
|
26
26
|
return address;
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
const length = address.length;
|
|
29
29
|
if (length === 66 || length < 3) {
|
|
30
30
|
return address;
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
const missingZeros = 66 - length;
|
|
33
33
|
return address.slice(0, 2) + "0".repeat(missingZeros) + address.slice(2);
|
|
34
34
|
}
|
|
35
35
|
exports.normalizeAptosAddress = normalizeAptosAddress;
|
package/dist/cjs/aptos/wallet.js
CHANGED
|
@@ -1,45 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
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;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
3
|
exports.AptosWalletWrapper = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
4
|
+
const aptos_1 = require("aptos");
|
|
5
|
+
class AptosWalletWrapper {
|
|
6
|
+
constructor(wallet, client) {
|
|
43
7
|
this.client = client;
|
|
44
8
|
this.wallet = wallet;
|
|
45
9
|
if (wallet instanceof aptos_1.AptosAccount) {
|
|
@@ -49,41 +13,22 @@ var AptosWalletWrapper = /** @class */ (function () {
|
|
|
49
13
|
this.address = wallet.account.address;
|
|
50
14
|
}
|
|
51
15
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
switch (_a.label) {
|
|
57
|
-
case 0:
|
|
58
|
-
if (!(this.wallet instanceof aptos_1.AptosAccount)) return [3 /*break*/, 6];
|
|
59
|
-
builder = new aptos_1.TransactionBuilderRemoteABI(this.client, {
|
|
60
|
-
sender: this.address,
|
|
61
|
-
});
|
|
62
|
-
return [4 /*yield*/, builder.build(input.function, input.type_arguments, input.arguments)];
|
|
63
|
-
case 1:
|
|
64
|
-
rawTxn = _a.sent();
|
|
65
|
-
return [4 /*yield*/, this.client.simulateTransaction(this.wallet, rawTxn)];
|
|
66
|
-
case 2:
|
|
67
|
-
res = _a.sent();
|
|
68
|
-
if (!res[0].success) {
|
|
69
|
-
throw new Error("Transaction Simulation failed: ".concat(JSON.stringify(res)));
|
|
70
|
-
}
|
|
71
|
-
return [4 /*yield*/, this.client.signTransaction(this.wallet, rawTxn)];
|
|
72
|
-
case 3:
|
|
73
|
-
signedTx = _a.sent();
|
|
74
|
-
return [4 /*yield*/, this.client.submitSignedBCSTransaction(signedTx)];
|
|
75
|
-
case 4:
|
|
76
|
-
tx = _a.sent();
|
|
77
|
-
return [4 /*yield*/, this.client.waitForTransaction(tx.hash)];
|
|
78
|
-
case 5:
|
|
79
|
-
_a.sent();
|
|
80
|
-
return [2 /*return*/, tx.hash];
|
|
81
|
-
case 6: return [4 /*yield*/, this.wallet.signAndSubmitTransaction(input)];
|
|
82
|
-
case 7: return [2 /*return*/, (_a.sent()).hash];
|
|
83
|
-
}
|
|
16
|
+
async signAndSubmitTransaction(input) {
|
|
17
|
+
if (this.wallet instanceof aptos_1.AptosAccount) {
|
|
18
|
+
const builder = new aptos_1.TransactionBuilderRemoteABI(this.client, {
|
|
19
|
+
sender: this.address,
|
|
84
20
|
});
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
21
|
+
const rawTxn = await builder.build(input.function, input.type_arguments, input.arguments);
|
|
22
|
+
const res = await this.client.simulateTransaction(this.wallet, rawTxn);
|
|
23
|
+
if (!res[0].success) {
|
|
24
|
+
throw new Error(`Transaction Simulation failed: ${JSON.stringify(res)}`);
|
|
25
|
+
}
|
|
26
|
+
const signedTx = await this.client.signTransaction(this.wallet, rawTxn);
|
|
27
|
+
const tx = await this.client.submitSignedBCSTransaction(signedTx);
|
|
28
|
+
await this.client.waitForTransaction(tx.hash);
|
|
29
|
+
return tx.hash;
|
|
30
|
+
}
|
|
31
|
+
return (await this.wallet.signAndSubmitTransaction(input)).hash;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
89
34
|
exports.AptosWalletWrapper = AptosWalletWrapper;
|
|
@@ -1,71 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
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;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
3
|
exports.BaseStreamClient = void 0;
|
|
40
|
-
|
|
41
|
-
function BaseStreamClient() {
|
|
42
|
-
}
|
|
4
|
+
class BaseStreamClient {
|
|
43
5
|
/**
|
|
44
6
|
* Returns total fee percent, streamflow fees + partner fees
|
|
45
7
|
* @param getFeesData structure with address for which we need to derive fee, either sender or partner usually
|
|
46
8
|
* @param chainSpecificParams additional parameters required by chain client
|
|
47
9
|
* @returns fee as floating number, so if fee is 0.99%, it will return 0.99
|
|
48
10
|
*/
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
fees = _a.sent();
|
|
57
|
-
if (fees) {
|
|
58
|
-
return [2 /*return*/, fees.partnerFee + fees.streamflowFee];
|
|
59
|
-
}
|
|
60
|
-
return [2 /*return*/, this.getDefaultStreamflowFee(chainSpecificParams)];
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
};
|
|
11
|
+
async getTotalFee(getFeesData, chainSpecificParams) {
|
|
12
|
+
const fees = await this.getFees(getFeesData, chainSpecificParams);
|
|
13
|
+
if (fees) {
|
|
14
|
+
return fees.partnerFee + fees.streamflowFee;
|
|
15
|
+
}
|
|
16
|
+
return this.getDefaultStreamflowFee(chainSpecificParams);
|
|
17
|
+
}
|
|
65
18
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
66
|
-
|
|
19
|
+
extractErrorCode(err) {
|
|
67
20
|
return null;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
}());
|
|
21
|
+
}
|
|
22
|
+
}
|
|
71
23
|
exports.BaseStreamClient = BaseStreamClient;
|
|
@@ -1,128 +1,102 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
3
|
+
const BaseStreamClient_js_1 = require("./BaseStreamClient.js");
|
|
4
|
+
const types_js_1 = require("./types.js");
|
|
5
|
+
const utils_js_1 = require("./utils.js");
|
|
6
|
+
const index_js_1 = require("../aptos/index.js");
|
|
7
|
+
const index_js_2 = require("../evm/index.js");
|
|
8
|
+
const index_js_3 = require("../solana/index.js");
|
|
9
|
+
const index_js_4 = require("../sui/index.js");
|
|
10
|
+
const constants_js_1 = require("./constants.js");
|
|
26
11
|
/** Generic Stream Client implementation that wrap Chain Client methods and enriches error messages if possible
|
|
27
12
|
* @property {StreamClientType} - Chain Client implementation
|
|
28
13
|
* @property {chain} - Chain
|
|
29
14
|
*/
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
_this.chain = options.chain;
|
|
15
|
+
class GenericStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
16
|
+
constructor(options) {
|
|
17
|
+
super();
|
|
18
|
+
this.chain = options.chain;
|
|
35
19
|
switch (options.chain) {
|
|
36
20
|
case types_js_1.IChain.Solana:
|
|
37
|
-
|
|
21
|
+
this.nativeStreamClient = new index_js_3.SolanaStreamClient(options.clusterUrl, options.cluster, options.commitment, options.programId, options.sendRate, options.sendThrottler);
|
|
38
22
|
break;
|
|
39
23
|
case types_js_1.IChain.Aptos:
|
|
40
|
-
|
|
24
|
+
this.nativeStreamClient = new index_js_1.AptosStreamClient(options.clusterUrl, options.cluster, options.maxGas, options.programId);
|
|
41
25
|
break;
|
|
42
26
|
case types_js_1.IChain.BNB:
|
|
43
27
|
case types_js_1.IChain.Ethereum:
|
|
44
28
|
case types_js_1.IChain.Polygon:
|
|
45
|
-
|
|
29
|
+
this.nativeStreamClient = new index_js_2.EvmStreamClient(options.clusterUrl, options.chain, options.signer, options.cluster, options.programId);
|
|
46
30
|
break;
|
|
47
31
|
case types_js_1.IChain.Sui:
|
|
48
|
-
|
|
32
|
+
this.nativeStreamClient = new index_js_4.SuiStreamClient(options.clusterUrl, options.cluster, options.ids);
|
|
49
33
|
}
|
|
50
|
-
return _this;
|
|
51
34
|
}
|
|
52
35
|
/**
|
|
53
36
|
* Creates a new stream/vesting contract.
|
|
54
37
|
*/
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
};
|
|
38
|
+
create(streamData, chainSpecificParams) {
|
|
39
|
+
return (0, utils_js_1.handleContractError)(() => this.nativeStreamClient.create(streamData, chainSpecificParams), this.nativeStreamClient.extractErrorCode);
|
|
40
|
+
}
|
|
59
41
|
/**
|
|
60
42
|
* Creates multiple stream/vesting contracts.
|
|
61
43
|
*/
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
};
|
|
44
|
+
createMultiple(multipleStreamData, chainSpecificParams) {
|
|
45
|
+
return (0, utils_js_1.handleContractError)(() => this.nativeStreamClient.createMultiple(multipleStreamData, chainSpecificParams), this.nativeStreamClient.extractErrorCode);
|
|
46
|
+
}
|
|
66
47
|
/**
|
|
67
48
|
* Attempts withdrawing from the specified stream.
|
|
68
49
|
*/
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return (0, utils_js_1.handleContractError)(function () { return _this.nativeStreamClient.withdraw({ id: id, amount: amount }, chainSpecificParams); }, this.nativeStreamClient.extractErrorCode);
|
|
73
|
-
};
|
|
50
|
+
withdraw({ id, amount = constants_js_1.WITHDRAW_AVAILABLE_AMOUNT }, chainSpecificParams) {
|
|
51
|
+
return (0, utils_js_1.handleContractError)(() => this.nativeStreamClient.withdraw({ id, amount }, chainSpecificParams), this.nativeStreamClient.extractErrorCode);
|
|
52
|
+
}
|
|
74
53
|
/**
|
|
75
54
|
* Attempts canceling the specified stream.
|
|
76
55
|
*/
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
};
|
|
56
|
+
cancel(cancelData, chainSpecificParams) {
|
|
57
|
+
return (0, utils_js_1.handleContractError)(() => this.nativeStreamClient.cancel(cancelData, chainSpecificParams), this.nativeStreamClient.extractErrorCode);
|
|
58
|
+
}
|
|
81
59
|
/**
|
|
82
60
|
* Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
|
|
83
61
|
*/
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
};
|
|
62
|
+
transfer(transferData, chainSpecificParams) {
|
|
63
|
+
return (0, utils_js_1.handleContractError)(() => this.nativeStreamClient.transfer(transferData, chainSpecificParams), this.nativeStreamClient.extractErrorCode);
|
|
64
|
+
}
|
|
88
65
|
/**
|
|
89
66
|
* Tops up stream account with specified amount.
|
|
90
67
|
*/
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
};
|
|
68
|
+
topup(topupData, chainSpecificParams) {
|
|
69
|
+
return (0, utils_js_1.handleContractError)(() => this.nativeStreamClient.topup(topupData, chainSpecificParams), this.nativeStreamClient.extractErrorCode);
|
|
70
|
+
}
|
|
95
71
|
/**
|
|
96
72
|
* Fetch stream data by its id (address).
|
|
97
73
|
*/
|
|
98
|
-
|
|
74
|
+
getOne(getOneData) {
|
|
99
75
|
return this.nativeStreamClient.getOne(getOneData);
|
|
100
|
-
}
|
|
76
|
+
}
|
|
101
77
|
/**
|
|
102
78
|
* Fetch streams by sender or recipient address.
|
|
103
79
|
*/
|
|
104
|
-
|
|
80
|
+
get(getAllData) {
|
|
105
81
|
return this.nativeStreamClient.get(getAllData);
|
|
106
|
-
}
|
|
82
|
+
}
|
|
107
83
|
/**
|
|
108
84
|
* Attempts updating the stream auto withdrawal params and amount per period
|
|
109
85
|
*/
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
};
|
|
86
|
+
update(updateData, chainSpecificParams) {
|
|
87
|
+
return (0, utils_js_1.handleContractError)(() => this.nativeStreamClient.update(updateData, chainSpecificParams), this.nativeStreamClient.extractErrorCode);
|
|
88
|
+
}
|
|
114
89
|
/**
|
|
115
90
|
* Returns streamflow and partner fees for the specific wallet in %
|
|
116
91
|
*/
|
|
117
|
-
|
|
92
|
+
getFees(getFeesData) {
|
|
118
93
|
return this.nativeStreamClient.getFees(getFeesData);
|
|
119
|
-
}
|
|
94
|
+
}
|
|
120
95
|
/**
|
|
121
96
|
* Returns default Streamflow Fee in %
|
|
122
97
|
*/
|
|
123
|
-
|
|
98
|
+
getDefaultStreamflowFee() {
|
|
124
99
|
return this.nativeStreamClient.getDefaultStreamflowFee();
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
}(BaseStreamClient_js_1.BaseStreamClient));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
128
102
|
exports.default = GenericStreamClient;
|
|
@@ -3,7 +3,8 @@ 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.WITHDRAW_AVAILABLE_AMOUNT = exports.BASE_FEE = void 0;
|
|
7
|
-
|
|
6
|
+
exports.WITHDRAW_AVAILABLE_AMOUNT = exports.BASE_FEE = exports.MAX_SAFE_UNIX_TIME_VALUE = void 0;
|
|
7
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
8
|
+
exports.MAX_SAFE_UNIX_TIME_VALUE = 8640000000000;
|
|
8
9
|
exports.BASE_FEE = 1009900; // Buffer to include usual fees when calculating stream amount
|
|
9
|
-
exports.WITHDRAW_AVAILABLE_AMOUNT =
|
|
10
|
+
exports.WITHDRAW_AVAILABLE_AMOUNT = new bn_js_1.default("18446744073709551615"); // Magical number to withdraw all available amount from a Contract
|
|
@@ -3,37 +3,45 @@ 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.buildStreamType = exports.isTokenLock = exports.isVesting = exports.isPayment = exports.isCliffCloseToDepositedAmount = exports.calculateUnlockedAmount = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
exports.decodeEndTime = exports.buildStreamType = exports.isTokenLock = exports.isCreateAlignedStreamData = exports.isAligned = exports.isVesting = exports.isPayment = exports.isCliffCloseToDepositedAmount = exports.calculateUnlockedAmount = void 0;
|
|
7
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
8
|
+
const types_js_1 = require("./types.js");
|
|
9
|
+
const constants_js_1 = require("./constants.js");
|
|
10
|
+
const calculateUnlockedAmount = ({ depositedAmount, cliff, cliffAmount, end, currentTimestamp, lastRateChangeTime, period, amountPerPeriod, fundsUnlockedAtLastRateChange, }) => {
|
|
11
|
+
const deposited = depositedAmount;
|
|
12
12
|
if (currentTimestamp < cliff)
|
|
13
|
-
return
|
|
13
|
+
return new bn_js_1.default(0);
|
|
14
14
|
if (currentTimestamp > end)
|
|
15
15
|
return deposited;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
.
|
|
20
|
-
.
|
|
16
|
+
const savedUnlockedFunds = lastRateChangeTime === 0 ? cliffAmount : fundsUnlockedAtLastRateChange;
|
|
17
|
+
const savedUnlockedFundsTime = lastRateChangeTime === 0 ? cliff : lastRateChangeTime;
|
|
18
|
+
const streamed = new bn_js_1.default(Math.floor((currentTimestamp - savedUnlockedFundsTime) / period))
|
|
19
|
+
.mul(amountPerPeriod)
|
|
20
|
+
.add(savedUnlockedFunds);
|
|
21
21
|
return streamed.lt(deposited) ? streamed : deposited;
|
|
22
22
|
};
|
|
23
23
|
exports.calculateUnlockedAmount = calculateUnlockedAmount;
|
|
24
|
-
|
|
25
|
-
return streamData.cliffAmount.gte(streamData.depositedAmount.
|
|
24
|
+
const isCliffCloseToDepositedAmount = (streamData) => {
|
|
25
|
+
return streamData.cliffAmount.gte(streamData.depositedAmount.sub(new bn_js_1.default(1)));
|
|
26
26
|
};
|
|
27
27
|
exports.isCliffCloseToDepositedAmount = isCliffCloseToDepositedAmount;
|
|
28
|
-
|
|
28
|
+
const isPayment = (streamData) => {
|
|
29
29
|
return streamData.canTopup;
|
|
30
30
|
};
|
|
31
31
|
exports.isPayment = isPayment;
|
|
32
|
-
|
|
32
|
+
const isVesting = (streamData) => {
|
|
33
33
|
return !streamData.canTopup && !(0, exports.isCliffCloseToDepositedAmount)(streamData);
|
|
34
34
|
};
|
|
35
35
|
exports.isVesting = isVesting;
|
|
36
|
-
|
|
36
|
+
const isAligned = (stream) => {
|
|
37
|
+
return "minPrice" in stream && "maxPrice" in stream && "minPercentage" in stream && "maxPercentage" in stream;
|
|
38
|
+
};
|
|
39
|
+
exports.isAligned = isAligned;
|
|
40
|
+
const isCreateAlignedStreamData = (obj) => {
|
|
41
|
+
return "minPrice" in obj && "maxPrice" in obj && "minPercentage" in obj && "maxPercentage" in obj;
|
|
42
|
+
};
|
|
43
|
+
exports.isCreateAlignedStreamData = isCreateAlignedStreamData;
|
|
44
|
+
const isTokenLock = (streamData) => {
|
|
37
45
|
return (!streamData.canTopup &&
|
|
38
46
|
!streamData.automaticWithdrawal &&
|
|
39
47
|
!streamData.cancelableBySender &&
|
|
@@ -43,7 +51,7 @@ var isTokenLock = function (streamData) {
|
|
|
43
51
|
(0, exports.isCliffCloseToDepositedAmount)(streamData));
|
|
44
52
|
};
|
|
45
53
|
exports.isTokenLock = isTokenLock;
|
|
46
|
-
|
|
54
|
+
const buildStreamType = (streamData) => {
|
|
47
55
|
if ((0, exports.isVesting)(streamData)) {
|
|
48
56
|
return types_js_1.StreamType.Vesting;
|
|
49
57
|
}
|
|
@@ -53,3 +61,10 @@ var buildStreamType = function (streamData) {
|
|
|
53
61
|
return types_js_1.StreamType.Payment;
|
|
54
62
|
};
|
|
55
63
|
exports.buildStreamType = buildStreamType;
|
|
64
|
+
const decodeEndTime = (endTime) => {
|
|
65
|
+
if (endTime.gt(new bn_js_1.default(constants_js_1.MAX_SAFE_UNIX_TIME_VALUE))) {
|
|
66
|
+
return constants_js_1.MAX_SAFE_UNIX_TIME_VALUE;
|
|
67
|
+
}
|
|
68
|
+
return endTime.toNumber();
|
|
69
|
+
};
|
|
70
|
+
exports.decodeEndTime = decodeEndTime;
|
package/dist/cjs/common/types.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SolanaContractErrorCode = exports.ContractErrorCode = exports.StreamType = exports.StreamDirection = exports.ContractError = exports.ICluster = exports.IChain = void 0;
|
|
3
|
+
exports.SolanaAlignedProxyErrorCode = exports.SolanaContractErrorCode = exports.ContractErrorCode = exports.StreamType = exports.StreamDirection = exports.ContractError = exports.ICluster = exports.IChain = void 0;
|
|
4
4
|
var common_1 = require("@streamflow/common");
|
|
5
5
|
Object.defineProperty(exports, "IChain", { enumerable: true, get: function () { return common_1.IChain; } });
|
|
6
6
|
Object.defineProperty(exports, "ICluster", { enumerable: true, get: function () { return common_1.ICluster; } });
|
|
@@ -110,3 +110,32 @@ var SolanaContractErrorCode;
|
|
|
110
110
|
/** Meta account is not rent exempt */
|
|
111
111
|
SolanaContractErrorCode["MetadataNotRentExempt"] = "MetadataNotRentExempt";
|
|
112
112
|
})(SolanaContractErrorCode || (exports.SolanaContractErrorCode = SolanaContractErrorCode = {}));
|
|
113
|
+
var SolanaAlignedProxyErrorCode;
|
|
114
|
+
(function (SolanaAlignedProxyErrorCode) {
|
|
115
|
+
/** Authority does not have permission for this action */
|
|
116
|
+
SolanaAlignedProxyErrorCode["Unauthorized"] = "Unauthorized";
|
|
117
|
+
/** Arithmetic error */
|
|
118
|
+
SolanaAlignedProxyErrorCode["ArithmeticError"] = "ArithmeticError";
|
|
119
|
+
/** Mint has unsupported Token Extensions */
|
|
120
|
+
SolanaAlignedProxyErrorCode["UnsupportedTokenExtensions"] = "UnsupportedTokenExtensions";
|
|
121
|
+
/** Provided period is too short, should be equal or more than 30 seconds */
|
|
122
|
+
SolanaAlignedProxyErrorCode["PeriodTooShort"] = "PeriodTooShort";
|
|
123
|
+
/** Provided percentage tick size is invalid */
|
|
124
|
+
SolanaAlignedProxyErrorCode["InvalidTickSize"] = "InvalidTickSize";
|
|
125
|
+
/** Provided percentage bounds are invalid */
|
|
126
|
+
SolanaAlignedProxyErrorCode["InvalidPercentageBoundaries"] = "InvalidPercentageBoundaries";
|
|
127
|
+
/** Provided price bounds are invalid */
|
|
128
|
+
SolanaAlignedProxyErrorCode["InvalidPriceBoundaries"] = "InvalidPriceBoundaries";
|
|
129
|
+
/** Unsupported price oracle */
|
|
130
|
+
SolanaAlignedProxyErrorCode["UnsupportedOracle"] = "UnsupportedOracle";
|
|
131
|
+
/** Invalid oracle account */
|
|
132
|
+
SolanaAlignedProxyErrorCode["InvalidOracleAccount"] = "InvalidOracleAccount";
|
|
133
|
+
/** Invalid oracle price */
|
|
134
|
+
SolanaAlignedProxyErrorCode["InvalidOraclePrice"] = "InvalidOraclePrice";
|
|
135
|
+
/** Invalid Stream Metadata */
|
|
136
|
+
SolanaAlignedProxyErrorCode["InvalidStreamMetadata"] = "InvalidStreamMetadata";
|
|
137
|
+
/** Release amount has already been updated in this period */
|
|
138
|
+
SolanaAlignedProxyErrorCode["AmountAlreadyUpdated"] = "AmountAlreadyUpdated";
|
|
139
|
+
/** All funds are already unlocked */
|
|
140
|
+
SolanaAlignedProxyErrorCode["AllFundsUnlocked"] = "AllFundsUnlocked";
|
|
141
|
+
})(SolanaAlignedProxyErrorCode || (exports.SolanaAlignedProxyErrorCode = SolanaAlignedProxyErrorCode = {}));
|