@streamflow/stream 6.5.0 → 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 +17 -22
- package/dist/cjs/__tests__/aptos/streamClient.spec.js +111 -0
- package/dist/cjs/__tests__/common/GenericStreamClient.spec.js +45 -0
- package/dist/cjs/aptos/StreamClient.js +226 -0
- package/dist/cjs/aptos/constants.js +27 -0
- package/dist/{aptos → cjs/aptos}/index.js +6 -6
- package/dist/cjs/aptos/types.js +69 -0
- package/dist/{aptos → cjs/aptos}/utils.js +4 -4
- package/dist/cjs/aptos/wallet.js +34 -0
- package/dist/cjs/common/BaseStreamClient.js +23 -0
- package/dist/cjs/common/GenericStreamClient.js +102 -0
- package/dist/{common → cjs/common}/constants.js +2 -2
- package/dist/{common → cjs/common}/contractUtils.js +19 -20
- package/dist/cjs/common/utils.js +66 -0
- package/dist/cjs/evm/StreamClient.js +238 -0
- package/dist/cjs/evm/constants.js +38 -0
- package/dist/{evm → cjs/evm}/index.js +8 -8
- package/dist/{evm → cjs/evm}/types.js +26 -35
- package/dist/{evm → cjs/evm}/utils.js +2 -2
- package/dist/{index.js → cjs/index.js} +10 -10
- package/dist/cjs/solana/StreamClient.js +737 -0
- package/dist/{solana → cjs/solana}/constants.js +33 -33
- package/dist/cjs/solana/index.js +39 -0
- package/dist/{solana → cjs/solana}/instructions.js +83 -83
- package/dist/{solana → cjs/solana}/layout.js +8 -9
- package/dist/{solana → cjs/solana}/types.js +16 -26
- package/dist/cjs/solana/utils.js +134 -0
- package/dist/cjs/sui/StreamClient.js +402 -0
- package/dist/cjs/sui/constants.js +42 -0
- package/dist/{sui → cjs/sui}/index.js +5 -5
- package/dist/cjs/sui/types.js +68 -0
- package/dist/{sui → cjs/sui}/utils.js +7 -7
- package/dist/cjs/sui/wallet.js +40 -0
- package/dist/esm/__tests__/aptos/streamClient.spec.js +106 -0
- package/dist/esm/__tests__/common/GenericStreamClient.spec.js +40 -0
- package/dist/{aptos → esm/aptos}/StreamClient.d.ts +3 -3
- package/dist/esm/aptos/StreamClient.js +226 -0
- package/dist/{aptos → esm/aptos}/constants.d.ts +1 -1
- package/dist/esm/aptos/constants.js +24 -0
- package/dist/esm/aptos/index.d.ts +4 -0
- package/dist/esm/aptos/index.js +4 -0
- package/dist/{aptos → esm/aptos}/types.d.ts +13 -13
- package/dist/esm/aptos/types.js +105 -0
- package/dist/esm/aptos/utils.js +30 -0
- package/dist/esm/aptos/wallet.js +33 -0
- package/dist/{common → esm/common}/BaseStreamClient.d.ts +1 -1
- package/dist/esm/common/BaseStreamClient.js +19 -0
- package/dist/{common → esm/common}/GenericStreamClient.d.ts +6 -6
- package/dist/esm/common/GenericStreamClient.js +101 -0
- package/dist/esm/common/constants.d.ts +3 -0
- package/dist/esm/common/constants.js +3 -0
- package/dist/{common → esm/common}/contractUtils.d.ts +15 -15
- package/dist/esm/common/contractUtils.js +42 -0
- package/dist/{common → esm/common}/types.d.ts +19 -19
- package/dist/esm/common/types.js +106 -0
- package/dist/{common → esm/common}/utils.d.ts +11 -12
- package/dist/esm/common/utils.js +56 -0
- package/dist/{evm → esm/evm}/StreamClient.d.ts +4 -4
- package/dist/esm/evm/StreamClient.js +237 -0
- package/dist/esm/evm/abi.js +1255 -0
- package/dist/{evm → esm/evm}/constants.d.ts +1 -1
- package/dist/esm/evm/constants.js +35 -0
- package/dist/esm/evm/ercAbi.js +222 -0
- package/dist/esm/evm/index.d.ts +5 -0
- package/dist/esm/evm/index.js +5 -0
- package/dist/{evm → esm/evm}/types.d.ts +38 -38
- package/dist/esm/evm/types.js +102 -0
- package/dist/esm/evm/utils.js +8 -0
- package/dist/esm/index.d.ts +9 -0
- package/dist/esm/index.js +9 -0
- package/dist/{solana → esm/solana}/StreamClient.d.ts +4 -4
- package/dist/esm/solana/StreamClient.js +711 -0
- package/dist/{solana → esm/solana}/constants.d.ts +3 -1
- package/dist/esm/solana/constants.js +62 -0
- package/dist/esm/solana/index.d.ts +6 -0
- package/dist/esm/solana/index.js +6 -0
- package/dist/esm/solana/instructionTypes.js +1 -0
- package/dist/{solana → esm/solana}/instructions.d.ts +18 -18
- package/dist/esm/solana/instructions.js +257 -0
- package/dist/{solana → esm/solana}/layout.d.ts +2 -1
- package/dist/esm/solana/layout.js +155 -0
- package/dist/esm/solana/timelockIDL.js +420 -0
- package/dist/{solana → esm/solana}/types.d.ts +38 -37
- package/dist/esm/solana/types.js +101 -0
- package/dist/{solana → esm/solana}/utils.d.ts +4 -1
- package/dist/esm/solana/utils.js +123 -0
- package/dist/{sui → esm/sui}/StreamClient.d.ts +3 -3
- package/dist/esm/sui/StreamClient.js +403 -0
- package/dist/{sui → esm/sui}/constants.d.ts +1 -1
- package/dist/esm/sui/constants.js +39 -0
- package/dist/esm/sui/index.d.ts +4 -0
- package/dist/esm/sui/index.js +4 -0
- package/dist/{sui → esm/sui}/types.d.ts +13 -13
- package/dist/esm/sui/types.js +104 -0
- package/dist/{sui → esm/sui}/utils.d.ts +1 -1
- package/dist/esm/sui/utils.js +23 -0
- package/dist/{sui → esm/sui}/wallet.d.ts +1 -1
- package/dist/esm/sui/wallet.js +38 -0
- package/package.json +37 -35
- package/dist/__tests__/aptos/streamClient.spec.js +0 -161
- package/dist/__tests__/common/GenericStreamClient.spec.js +0 -44
- package/dist/aptos/StreamClient.js +0 -431
- package/dist/aptos/constants.js +0 -28
- package/dist/aptos/index.d.ts +0 -4
- package/dist/aptos/types.js +0 -77
- package/dist/aptos/wallet.js +0 -89
- package/dist/common/BaseStreamClient.js +0 -71
- package/dist/common/GenericStreamClient.js +0 -128
- package/dist/common/constants.d.ts +0 -3
- package/dist/common/utils.js +0 -118
- package/dist/evm/StreamClient.js +0 -496
- package/dist/evm/constants.js +0 -39
- package/dist/evm/index.d.ts +0 -5
- package/dist/index.d.ts +0 -9
- package/dist/solana/StreamClient.js +0 -1253
- package/dist/solana/index.d.ts +0 -7
- package/dist/solana/index.js +0 -43
- package/dist/solana/utils.js +0 -211
- package/dist/sui/StreamClient.js +0 -648
- package/dist/sui/constants.js +0 -43
- package/dist/sui/index.d.ts +0 -4
- package/dist/sui/types.js +0 -102
- package/dist/sui/wallet.js +0 -90
- /package/dist/{common → cjs/common}/types.js +0 -0
- /package/dist/{evm → cjs/evm}/abi.js +0 -0
- /package/dist/{evm → cjs/evm}/ercAbi.js +0 -0
- /package/dist/{solana → cjs/solana}/instructionTypes.js +0 -0
- /package/dist/{solana → cjs/solana}/timelockIDL.js +0 -0
- /package/dist/{__tests__ → esm/__tests__}/aptos/streamClient.spec.d.ts +0 -0
- /package/dist/{__tests__ → esm/__tests__}/common/GenericStreamClient.spec.d.ts +0 -0
- /package/dist/{aptos → esm/aptos}/utils.d.ts +0 -0
- /package/dist/{aptos → esm/aptos}/wallet.d.ts +0 -0
- /package/dist/{evm → esm/evm}/abi.d.ts +0 -0
- /package/dist/{evm → esm/evm}/ercAbi.d.ts +0 -0
- /package/dist/{evm → esm/evm}/utils.d.ts +0 -0
- /package/dist/{solana → esm/solana}/instructionTypes.d.ts +0 -0
- /package/dist/{solana → esm/solana}/timelockIDL.d.ts +0 -0
|
@@ -1,71 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.BaseStreamClient = void 0;
|
|
40
|
-
var BaseStreamClient = /** @class */ (function () {
|
|
41
|
-
function BaseStreamClient() {
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Returns total fee percent, streamflow fees + partner fees
|
|
45
|
-
* @param getFeesData structure with address for which we need to derive fee, either sender or partner usually
|
|
46
|
-
* @param chainSpecificParams additional parameters required by chain client
|
|
47
|
-
* @returns fee as floating number, so if fee is 0.99%, it will return 0.99
|
|
48
|
-
*/
|
|
49
|
-
BaseStreamClient.prototype.getTotalFee = function (getFeesData, chainSpecificParams) {
|
|
50
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
51
|
-
var fees;
|
|
52
|
-
return __generator(this, function (_a) {
|
|
53
|
-
switch (_a.label) {
|
|
54
|
-
case 0: return [4 /*yield*/, this.getFees(getFeesData, chainSpecificParams)];
|
|
55
|
-
case 1:
|
|
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
|
-
};
|
|
65
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
66
|
-
BaseStreamClient.prototype.extractErrorCode = function (err) {
|
|
67
|
-
return null;
|
|
68
|
-
};
|
|
69
|
-
return BaseStreamClient;
|
|
70
|
-
}());
|
|
71
|
-
exports.BaseStreamClient = BaseStreamClient;
|
|
@@ -1,128 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
var BaseStreamClient_1 = require("./BaseStreamClient");
|
|
19
|
-
var types_1 = require("./types");
|
|
20
|
-
var utils_1 = require("./utils");
|
|
21
|
-
var aptos_1 = require("../aptos");
|
|
22
|
-
var evm_1 = require("../evm");
|
|
23
|
-
var solana_1 = require("../solana");
|
|
24
|
-
var sui_1 = require("../sui");
|
|
25
|
-
var constants_1 = require("./constants");
|
|
26
|
-
/** Generic Stream Client implementation that wrap Chain Client methods and enriches error messages if possible
|
|
27
|
-
* @property {StreamClientType} - Chain Client implementation
|
|
28
|
-
* @property {chain} - Chain
|
|
29
|
-
*/
|
|
30
|
-
var GenericStreamClient = /** @class */ (function (_super) {
|
|
31
|
-
__extends(GenericStreamClient, _super);
|
|
32
|
-
function GenericStreamClient(options) {
|
|
33
|
-
var _this = _super.call(this) || this;
|
|
34
|
-
_this.chain = options.chain;
|
|
35
|
-
switch (options.chain) {
|
|
36
|
-
case types_1.IChain.Solana:
|
|
37
|
-
_this.nativeStreamClient = new solana_1.SolanaStreamClient(options.clusterUrl, options.cluster, options.commitment, options.programId, options.sendRate, options.sendThrottler);
|
|
38
|
-
break;
|
|
39
|
-
case types_1.IChain.Aptos:
|
|
40
|
-
_this.nativeStreamClient = new aptos_1.AptosStreamClient(options.clusterUrl, options.cluster, options.maxGas, options.programId);
|
|
41
|
-
break;
|
|
42
|
-
case types_1.IChain.BNB:
|
|
43
|
-
case types_1.IChain.Ethereum:
|
|
44
|
-
case types_1.IChain.Polygon:
|
|
45
|
-
_this.nativeStreamClient = new evm_1.EvmStreamClient(options.clusterUrl, options.chain, options.signer, options.cluster, options.programId);
|
|
46
|
-
break;
|
|
47
|
-
case types_1.IChain.Sui:
|
|
48
|
-
_this.nativeStreamClient = new sui_1.SuiStreamClient(options.clusterUrl, options.cluster, options.ids);
|
|
49
|
-
}
|
|
50
|
-
return _this;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Creates a new stream/vesting contract.
|
|
54
|
-
*/
|
|
55
|
-
GenericStreamClient.prototype.create = function (streamData, chainSpecificParams) {
|
|
56
|
-
var _this = this;
|
|
57
|
-
return (0, utils_1.handleContractError)(function () { return _this.nativeStreamClient.create(streamData, chainSpecificParams); }, this.nativeStreamClient.extractErrorCode);
|
|
58
|
-
};
|
|
59
|
-
/**
|
|
60
|
-
* Creates multiple stream/vesting contracts.
|
|
61
|
-
*/
|
|
62
|
-
GenericStreamClient.prototype.createMultiple = function (multipleStreamData, chainSpecificParams) {
|
|
63
|
-
var _this = this;
|
|
64
|
-
return (0, utils_1.handleContractError)(function () { return _this.nativeStreamClient.createMultiple(multipleStreamData, chainSpecificParams); }, this.nativeStreamClient.extractErrorCode);
|
|
65
|
-
};
|
|
66
|
-
/**
|
|
67
|
-
* Attempts withdrawing from the specified stream.
|
|
68
|
-
*/
|
|
69
|
-
GenericStreamClient.prototype.withdraw = function (_a, chainSpecificParams) {
|
|
70
|
-
var _this = this;
|
|
71
|
-
var id = _a.id, _b = _a.amount, amount = _b === void 0 ? constants_1.WITHDRAW_AVAILABLE_AMOUNT : _b;
|
|
72
|
-
return (0, utils_1.handleContractError)(function () { return _this.nativeStreamClient.withdraw({ id: id, amount: amount }, chainSpecificParams); }, this.nativeStreamClient.extractErrorCode);
|
|
73
|
-
};
|
|
74
|
-
/**
|
|
75
|
-
* Attempts canceling the specified stream.
|
|
76
|
-
*/
|
|
77
|
-
GenericStreamClient.prototype.cancel = function (cancelData, chainSpecificParams) {
|
|
78
|
-
var _this = this;
|
|
79
|
-
return (0, utils_1.handleContractError)(function () { return _this.nativeStreamClient.cancel(cancelData, chainSpecificParams); }, this.nativeStreamClient.extractErrorCode);
|
|
80
|
-
};
|
|
81
|
-
/**
|
|
82
|
-
* Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
|
|
83
|
-
*/
|
|
84
|
-
GenericStreamClient.prototype.transfer = function (transferData, chainSpecificParams) {
|
|
85
|
-
var _this = this;
|
|
86
|
-
return (0, utils_1.handleContractError)(function () { return _this.nativeStreamClient.transfer(transferData, chainSpecificParams); }, this.nativeStreamClient.extractErrorCode);
|
|
87
|
-
};
|
|
88
|
-
/**
|
|
89
|
-
* Tops up stream account with specified amount.
|
|
90
|
-
*/
|
|
91
|
-
GenericStreamClient.prototype.topup = function (topupData, chainSpecificParams) {
|
|
92
|
-
var _this = this;
|
|
93
|
-
return (0, utils_1.handleContractError)(function () { return _this.nativeStreamClient.topup(topupData, chainSpecificParams); }, this.nativeStreamClient.extractErrorCode);
|
|
94
|
-
};
|
|
95
|
-
/**
|
|
96
|
-
* Fetch stream data by its id (address).
|
|
97
|
-
*/
|
|
98
|
-
GenericStreamClient.prototype.getOne = function (getOneData) {
|
|
99
|
-
return this.nativeStreamClient.getOne(getOneData);
|
|
100
|
-
};
|
|
101
|
-
/**
|
|
102
|
-
* Fetch streams by sender or recipient address.
|
|
103
|
-
*/
|
|
104
|
-
GenericStreamClient.prototype.get = function (getAllData) {
|
|
105
|
-
return this.nativeStreamClient.get(getAllData);
|
|
106
|
-
};
|
|
107
|
-
/**
|
|
108
|
-
* Attempts updating the stream auto withdrawal params and amount per period
|
|
109
|
-
*/
|
|
110
|
-
GenericStreamClient.prototype.update = function (updateData, chainSpecificParams) {
|
|
111
|
-
var _this = this;
|
|
112
|
-
return (0, utils_1.handleContractError)(function () { return _this.nativeStreamClient.update(updateData, chainSpecificParams); }, this.nativeStreamClient.extractErrorCode);
|
|
113
|
-
};
|
|
114
|
-
/**
|
|
115
|
-
* Returns streamflow and partner fees for the specific wallet in %
|
|
116
|
-
*/
|
|
117
|
-
GenericStreamClient.prototype.getFees = function (getFeesData) {
|
|
118
|
-
return this.nativeStreamClient.getFees(getFeesData);
|
|
119
|
-
};
|
|
120
|
-
/**
|
|
121
|
-
* Returns default Streamflow Fee in %
|
|
122
|
-
*/
|
|
123
|
-
GenericStreamClient.prototype.getDefaultStreamflowFee = function () {
|
|
124
|
-
return this.nativeStreamClient.getDefaultStreamflowFee();
|
|
125
|
-
};
|
|
126
|
-
return GenericStreamClient;
|
|
127
|
-
}(BaseStreamClient_1.BaseStreamClient));
|
|
128
|
-
exports.default = GenericStreamClient;
|
package/dist/common/utils.js
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.normalizeAptosAddress = exports.handleContractError = exports.calculateTotalAmountToDeposit = exports.getNumberFromBN = exports.getBN = void 0;
|
|
43
|
-
var bn_js_1 = __importDefault(require("bn.js"));
|
|
44
|
-
var types_1 = require("./types");
|
|
45
|
-
var FEE_PRECISION = 4;
|
|
46
|
-
var FEE_NORMALIZER = Math.pow(10, FEE_PRECISION);
|
|
47
|
-
var FEE_MULTIPLIER = new bn_js_1.default(Math.pow(10, 6));
|
|
48
|
-
/**
|
|
49
|
-
* Used for conversion of token amounts to their Big Number representation.
|
|
50
|
-
* Get Big Number representation in the smallest units from the same value in the highest units.
|
|
51
|
-
* @param {number} value - Number of tokens you want to convert to its BN representation.
|
|
52
|
-
* @param {number} decimals - Number of decimals the token has.
|
|
53
|
-
*/
|
|
54
|
-
var getBN = function (value, decimals) {
|
|
55
|
-
var decimalPart = value - Math.trunc(value);
|
|
56
|
-
var integerPart = new bn_js_1.default(Math.trunc(value));
|
|
57
|
-
var decimalE = new bn_js_1.default(decimalPart * 1e9);
|
|
58
|
-
var sum = integerPart.mul(new bn_js_1.default(1e9)).add(decimalE);
|
|
59
|
-
var resultE = sum.mul(new bn_js_1.default(10).pow(new bn_js_1.default(decimals)));
|
|
60
|
-
return resultE.div(new bn_js_1.default(1e9));
|
|
61
|
-
};
|
|
62
|
-
exports.getBN = getBN;
|
|
63
|
-
/**
|
|
64
|
-
* Used for token amounts conversion from their Big Number representation to number.
|
|
65
|
-
* Get value in the highest units from BN representation of the same value in the smallest units.
|
|
66
|
-
* @param {BN} value - Big Number representation of value in the smallest units.
|
|
67
|
-
* @param {number} decimals - Number of decimals the token has.
|
|
68
|
-
*/
|
|
69
|
-
var getNumberFromBN = function (value, decimals) {
|
|
70
|
-
return value.gt(new bn_js_1.default(Math.pow(2, 53) - 1)) ? value.div(new bn_js_1.default(Math.pow(10, decimals))).toNumber() : value.toNumber() / Math.pow(10, decimals);
|
|
71
|
-
};
|
|
72
|
-
exports.getNumberFromBN = getNumberFromBN;
|
|
73
|
-
/**
|
|
74
|
-
* Calculate total amount of a Contract including all fees.
|
|
75
|
-
* - first we convert fee floating to a BN with up to 4 decimals precision
|
|
76
|
-
* - then we reverse the fee with `FEE_MULTIPLIER` to safely multiply it by depositedAmount
|
|
77
|
-
* to receive a total number and not percentage of depositedAmount
|
|
78
|
-
* @param depositedAmount deposited raw tokens
|
|
79
|
-
* @param totalFee sum of all fees in percentage as floating number, e.g. 0.99% should be supplied as 0.99
|
|
80
|
-
* @returns total tokens amount that Contract will retrieve from the Sender
|
|
81
|
-
*/
|
|
82
|
-
var calculateTotalAmountToDeposit = function (depositedAmount, totalFee) {
|
|
83
|
-
var totalFeeNormalized = new bn_js_1.default(totalFee * FEE_NORMALIZER);
|
|
84
|
-
return depositedAmount.mul(totalFeeNormalized.add(FEE_MULTIPLIER)).div(FEE_MULTIPLIER);
|
|
85
|
-
};
|
|
86
|
-
exports.calculateTotalAmountToDeposit = calculateTotalAmountToDeposit;
|
|
87
|
-
/**
|
|
88
|
-
* Used to make on chain calls to the contract and wrap raised errors if any
|
|
89
|
-
* @param func function that interacts with the contract
|
|
90
|
-
* @param callback callback that may be used to extract error code
|
|
91
|
-
* @returns {T}
|
|
92
|
-
*/
|
|
93
|
-
function handleContractError(func, callback) {
|
|
94
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
95
|
-
var err_1;
|
|
96
|
-
return __generator(this, function (_a) {
|
|
97
|
-
switch (_a.label) {
|
|
98
|
-
case 0:
|
|
99
|
-
_a.trys.push([0, 2, , 3]);
|
|
100
|
-
return [4 /*yield*/, func()];
|
|
101
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
102
|
-
case 2:
|
|
103
|
-
err_1 = _a.sent();
|
|
104
|
-
if (err_1 instanceof Error) {
|
|
105
|
-
if (callback) {
|
|
106
|
-
throw new types_1.ContractError(err_1, callback(err_1));
|
|
107
|
-
}
|
|
108
|
-
throw new types_1.ContractError(err_1);
|
|
109
|
-
}
|
|
110
|
-
throw err_1;
|
|
111
|
-
case 3: return [2 /*return*/];
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
exports.handleContractError = handleContractError;
|
|
117
|
-
var utils_1 = require("../aptos/utils");
|
|
118
|
-
Object.defineProperty(exports, "normalizeAptosAddress", { enumerable: true, get: function () { return utils_1.normalizeAptosAddress; } });
|