@nexusmutual/sdk 0.2.31 → 0.3.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/dist/data/abis/Cover.json +13 -0
- package/dist/data/abis/CoverBroker.json +338 -0
- package/dist/data/abis/ERC20.json +58 -19
- package/dist/data/abis/MemberRoles.json +19 -0
- package/dist/data/abis/SwapOperator.json +228 -13
- package/dist/data/addresses.json +2 -1
- package/dist/data/products.json +8 -8
- package/dist/index.d.mts +36188 -46
- package/dist/index.d.ts +36188 -46
- package/dist/index.js +395 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +407 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -2
package/dist/index.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
};
|
|
6
11
|
var __export = (target, all) => {
|
|
7
12
|
for (var name in all)
|
|
8
13
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -16,11 +21,179 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
21
|
return to;
|
|
17
22
|
};
|
|
18
23
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
24
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
25
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
26
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
27
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
30
|
+
mod
|
|
31
|
+
));
|
|
19
32
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
33
|
|
|
34
|
+
// node_modules/dotenv/package.json
|
|
35
|
+
var require_package = __commonJS({
|
|
36
|
+
"node_modules/dotenv/package.json"(exports, module2) {
|
|
37
|
+
module2.exports = {
|
|
38
|
+
name: "dotenv",
|
|
39
|
+
version: "16.0.3",
|
|
40
|
+
description: "Loads environment variables from .env file",
|
|
41
|
+
main: "lib/main.js",
|
|
42
|
+
types: "lib/main.d.ts",
|
|
43
|
+
exports: {
|
|
44
|
+
".": {
|
|
45
|
+
require: "./lib/main.js",
|
|
46
|
+
types: "./lib/main.d.ts",
|
|
47
|
+
default: "./lib/main.js"
|
|
48
|
+
},
|
|
49
|
+
"./config": "./config.js",
|
|
50
|
+
"./config.js": "./config.js",
|
|
51
|
+
"./lib/env-options": "./lib/env-options.js",
|
|
52
|
+
"./lib/env-options.js": "./lib/env-options.js",
|
|
53
|
+
"./lib/cli-options": "./lib/cli-options.js",
|
|
54
|
+
"./lib/cli-options.js": "./lib/cli-options.js",
|
|
55
|
+
"./package.json": "./package.json"
|
|
56
|
+
},
|
|
57
|
+
scripts: {
|
|
58
|
+
"dts-check": "tsc --project tests/types/tsconfig.json",
|
|
59
|
+
lint: "standard",
|
|
60
|
+
"lint-readme": "standard-markdown",
|
|
61
|
+
pretest: "npm run lint && npm run dts-check",
|
|
62
|
+
test: "tap tests/*.js --100 -Rspec",
|
|
63
|
+
prerelease: "npm test",
|
|
64
|
+
release: "standard-version"
|
|
65
|
+
},
|
|
66
|
+
repository: {
|
|
67
|
+
type: "git",
|
|
68
|
+
url: "git://github.com/motdotla/dotenv.git"
|
|
69
|
+
},
|
|
70
|
+
keywords: [
|
|
71
|
+
"dotenv",
|
|
72
|
+
"env",
|
|
73
|
+
".env",
|
|
74
|
+
"environment",
|
|
75
|
+
"variables",
|
|
76
|
+
"config",
|
|
77
|
+
"settings"
|
|
78
|
+
],
|
|
79
|
+
readmeFilename: "README.md",
|
|
80
|
+
license: "BSD-2-Clause",
|
|
81
|
+
devDependencies: {
|
|
82
|
+
"@types/node": "^17.0.9",
|
|
83
|
+
decache: "^4.6.1",
|
|
84
|
+
dtslint: "^3.7.0",
|
|
85
|
+
sinon: "^12.0.1",
|
|
86
|
+
standard: "^16.0.4",
|
|
87
|
+
"standard-markdown": "^7.1.0",
|
|
88
|
+
"standard-version": "^9.3.2",
|
|
89
|
+
tap: "^15.1.6",
|
|
90
|
+
tar: "^6.1.11",
|
|
91
|
+
typescript: "^4.5.4"
|
|
92
|
+
},
|
|
93
|
+
engines: {
|
|
94
|
+
node: ">=12"
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// node_modules/dotenv/lib/main.js
|
|
101
|
+
var require_main = __commonJS({
|
|
102
|
+
"node_modules/dotenv/lib/main.js"(exports, module2) {
|
|
103
|
+
"use strict";
|
|
104
|
+
var fs = require("fs");
|
|
105
|
+
var path = require("path");
|
|
106
|
+
var os = require("os");
|
|
107
|
+
var packageJson = require_package();
|
|
108
|
+
var version = packageJson.version;
|
|
109
|
+
var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
|
|
110
|
+
function parse(src) {
|
|
111
|
+
const obj = {};
|
|
112
|
+
let lines = src.toString();
|
|
113
|
+
lines = lines.replace(/\r\n?/mg, "\n");
|
|
114
|
+
let match;
|
|
115
|
+
while ((match = LINE.exec(lines)) != null) {
|
|
116
|
+
const key = match[1];
|
|
117
|
+
let value = match[2] || "";
|
|
118
|
+
value = value.trim();
|
|
119
|
+
const maybeQuote = value[0];
|
|
120
|
+
value = value.replace(/^(['"`])([\s\S]*)\1$/mg, "$2");
|
|
121
|
+
if (maybeQuote === '"') {
|
|
122
|
+
value = value.replace(/\\n/g, "\n");
|
|
123
|
+
value = value.replace(/\\r/g, "\r");
|
|
124
|
+
}
|
|
125
|
+
obj[key] = value;
|
|
126
|
+
}
|
|
127
|
+
return obj;
|
|
128
|
+
}
|
|
129
|
+
function _log(message) {
|
|
130
|
+
console.log(`[dotenv@${version}][DEBUG] ${message}`);
|
|
131
|
+
}
|
|
132
|
+
function _resolveHome(envPath) {
|
|
133
|
+
return envPath[0] === "~" ? path.join(os.homedir(), envPath.slice(1)) : envPath;
|
|
134
|
+
}
|
|
135
|
+
function config(options) {
|
|
136
|
+
let dotenvPath = path.resolve(process.cwd(), ".env");
|
|
137
|
+
let encoding = "utf8";
|
|
138
|
+
const debug = Boolean(options && options.debug);
|
|
139
|
+
const override = Boolean(options && options.override);
|
|
140
|
+
if (options) {
|
|
141
|
+
if (options.path != null) {
|
|
142
|
+
dotenvPath = _resolveHome(options.path);
|
|
143
|
+
}
|
|
144
|
+
if (options.encoding != null) {
|
|
145
|
+
encoding = options.encoding;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
try {
|
|
149
|
+
const parsed = DotenvModule.parse(fs.readFileSync(dotenvPath, { encoding }));
|
|
150
|
+
Object.keys(parsed).forEach(function(key) {
|
|
151
|
+
if (!Object.prototype.hasOwnProperty.call(process.env, key)) {
|
|
152
|
+
process.env[key] = parsed[key];
|
|
153
|
+
} else {
|
|
154
|
+
if (override === true) {
|
|
155
|
+
process.env[key] = parsed[key];
|
|
156
|
+
}
|
|
157
|
+
if (debug) {
|
|
158
|
+
if (override === true) {
|
|
159
|
+
_log(`"${key}" is already defined in \`process.env\` and WAS overwritten`);
|
|
160
|
+
} else {
|
|
161
|
+
_log(`"${key}" is already defined in \`process.env\` and was NOT overwritten`);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
return { parsed };
|
|
167
|
+
} catch (e) {
|
|
168
|
+
if (debug) {
|
|
169
|
+
_log(`Failed to load ${dotenvPath} ${e.message}`);
|
|
170
|
+
}
|
|
171
|
+
return { error: e };
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
var DotenvModule = {
|
|
175
|
+
config,
|
|
176
|
+
parse
|
|
177
|
+
};
|
|
178
|
+
module2.exports.config = DotenvModule.config;
|
|
179
|
+
module2.exports.parse = DotenvModule.parse;
|
|
180
|
+
module2.exports = DotenvModule;
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
|
|
21
184
|
// src/index.ts
|
|
22
185
|
var src_exports = {};
|
|
23
186
|
__export(src_exports, {
|
|
187
|
+
COMMISSION_DENOMINATOR: () => COMMISSION_DENOMINATOR,
|
|
188
|
+
CoverAsset: () => CoverAsset,
|
|
189
|
+
CoverId: () => CoverId,
|
|
190
|
+
DEFAULT_COMMISSION_RATIO: () => DEFAULT_COMMISSION_RATIO,
|
|
191
|
+
DEFAULT_SLIPPAGE: () => DEFAULT_SLIPPAGE,
|
|
192
|
+
MAXIMUM_COVER_PERIOD: () => MAXIMUM_COVER_PERIOD,
|
|
193
|
+
MINIMUM_COVER_PERIOD: () => MINIMUM_COVER_PERIOD,
|
|
194
|
+
NEXUS_MUTUAL_DAO_TREASURY_ADDRESS: () => NEXUS_MUTUAL_DAO_TREASURY_ADDRESS,
|
|
195
|
+
SLIPPAGE_DENOMINATOR: () => SLIPPAGE_DENOMINATOR,
|
|
196
|
+
TARGET_PRICE_DENOMINATOR: () => TARGET_PRICE_DENOMINATOR,
|
|
24
197
|
allLogoFileNames: () => allLogoFileNames,
|
|
25
198
|
allLogoNames: () => allLogoNames,
|
|
26
199
|
calculateEthForExactNxm: () => calculateEthForExactNxm,
|
|
@@ -31,11 +204,14 @@ __export(src_exports, {
|
|
|
31
204
|
calculatePriceImpactA: () => calculatePriceImpactA,
|
|
32
205
|
calculatePriceImpactB: () => calculatePriceImpactB,
|
|
33
206
|
calculateSpotPrice: () => calculateSpotPrice,
|
|
207
|
+
default: () => src_default,
|
|
208
|
+
getQuoteAndBuyCoverInputs: () => getQuoteAndBuyCoverInputs,
|
|
34
209
|
productTypes: () => product_types_default,
|
|
35
|
-
products: () => products_default
|
|
210
|
+
products: () => products_default,
|
|
211
|
+
sumPoolCapacities: () => sumPoolCapacities
|
|
36
212
|
});
|
|
37
213
|
module.exports = __toCommonJS(src_exports);
|
|
38
|
-
|
|
214
|
+
var deployments = __toESM(require("@nexusmutual/deployments"));
|
|
39
215
|
|
|
40
216
|
// generated/products.json
|
|
41
217
|
var products_default = [
|
|
@@ -1400,7 +1576,7 @@ var products_default = [
|
|
|
1400
1576
|
"DAI"
|
|
1401
1577
|
],
|
|
1402
1578
|
isPrivate: true,
|
|
1403
|
-
timestamp:
|
|
1579
|
+
timestamp: 1704981731
|
|
1404
1580
|
},
|
|
1405
1581
|
{
|
|
1406
1582
|
id: 84,
|
|
@@ -1462,7 +1638,7 @@ var products_default = [
|
|
|
1462
1638
|
"DAI"
|
|
1463
1639
|
],
|
|
1464
1640
|
isPrivate: true,
|
|
1465
|
-
timestamp:
|
|
1641
|
+
timestamp: 1704981731
|
|
1466
1642
|
},
|
|
1467
1643
|
{
|
|
1468
1644
|
id: 88,
|
|
@@ -1556,7 +1732,7 @@ var products_default = [
|
|
|
1556
1732
|
"DAI"
|
|
1557
1733
|
],
|
|
1558
1734
|
isPrivate: true,
|
|
1559
|
-
timestamp:
|
|
1735
|
+
timestamp: 1704981731
|
|
1560
1736
|
},
|
|
1561
1737
|
{
|
|
1562
1738
|
id: 94,
|
|
@@ -1740,7 +1916,7 @@ var products_default = [
|
|
|
1740
1916
|
"DAI"
|
|
1741
1917
|
],
|
|
1742
1918
|
isPrivate: true,
|
|
1743
|
-
timestamp:
|
|
1919
|
+
timestamp: 1704980411
|
|
1744
1920
|
},
|
|
1745
1921
|
{
|
|
1746
1922
|
id: 106,
|
|
@@ -2205,7 +2381,7 @@ var products_default = [
|
|
|
2205
2381
|
"ETH"
|
|
2206
2382
|
],
|
|
2207
2383
|
isPrivate: false,
|
|
2208
|
-
timestamp:
|
|
2384
|
+
timestamp: 1709310707
|
|
2209
2385
|
},
|
|
2210
2386
|
{
|
|
2211
2387
|
id: 137,
|
|
@@ -2531,7 +2707,7 @@ var products_default = [
|
|
|
2531
2707
|
productType: 11,
|
|
2532
2708
|
isDeprecated: false,
|
|
2533
2709
|
useFixedPrice: false,
|
|
2534
|
-
logo: "
|
|
2710
|
+
logo: "lyra-synthetix.svg",
|
|
2535
2711
|
metadata: {
|
|
2536
2712
|
annex: "QmYfSDbuQLqJ2MAG3ATRjUPVFQubAhAM5oiYuuu9Kfs8RY"
|
|
2537
2713
|
},
|
|
@@ -2548,7 +2724,7 @@ var products_default = [
|
|
|
2548
2724
|
productType: 11,
|
|
2549
2725
|
isDeprecated: false,
|
|
2550
2726
|
useFixedPrice: false,
|
|
2551
|
-
logo: "
|
|
2727
|
+
logo: "eigenlayer-renzo.svg",
|
|
2552
2728
|
metadata: {
|
|
2553
2729
|
annex: "QmWWBqHBumXtHTkD6coEio8rWCJ68s9xheCqFS4kMRpW2R"
|
|
2554
2730
|
},
|
|
@@ -2572,7 +2748,7 @@ var products_default = [
|
|
|
2572
2748
|
"ETH",
|
|
2573
2749
|
"DAI"
|
|
2574
2750
|
],
|
|
2575
|
-
isPrivate:
|
|
2751
|
+
isPrivate: true,
|
|
2576
2752
|
timestamp: 1712739011
|
|
2577
2753
|
}
|
|
2578
2754
|
];
|
|
@@ -2673,6 +2849,11 @@ var product_types_default = [
|
|
|
2673
2849
|
];
|
|
2674
2850
|
|
|
2675
2851
|
// generated/types.ts
|
|
2852
|
+
var types_exports = {};
|
|
2853
|
+
__export(types_exports, {
|
|
2854
|
+
allLogoFileNames: () => allLogoFileNames,
|
|
2855
|
+
allLogoNames: () => allLogoNames
|
|
2856
|
+
});
|
|
2676
2857
|
var allLogoFileNames = [
|
|
2677
2858
|
"zerox.svg",
|
|
2678
2859
|
"oneinch.svg",
|
|
@@ -2831,8 +3012,8 @@ var allLogoFileNames = [
|
|
|
2831
3012
|
"eigenlayer-renzo-pendle.svg",
|
|
2832
3013
|
"eigenlayer-swell-pendle.svg",
|
|
2833
3014
|
"arcadia.svg",
|
|
2834
|
-
"eigenlayer-renzo.svg",
|
|
2835
3015
|
"lyra-synthetix.svg",
|
|
3016
|
+
"eigenlayer-renzo.svg",
|
|
2836
3017
|
"liquidcollective.svg",
|
|
2837
3018
|
"aave-v1.svg",
|
|
2838
3019
|
"akropolis.svg",
|
|
@@ -3046,8 +3227,8 @@ var allLogoNames = [
|
|
|
3046
3227
|
"eigenlayer-renzo-pendle",
|
|
3047
3228
|
"eigenlayer-swell-pendle",
|
|
3048
3229
|
"arcadia",
|
|
3049
|
-
"eigenlayer-renzo",
|
|
3050
3230
|
"lyra-synthetix",
|
|
3231
|
+
"eigenlayer-renzo",
|
|
3051
3232
|
"liquidcollective",
|
|
3052
3233
|
"aave-v1",
|
|
3053
3234
|
"akropolis",
|
|
@@ -3104,6 +3285,18 @@ var allLogoNames = [
|
|
|
3104
3285
|
"zksync"
|
|
3105
3286
|
];
|
|
3106
3287
|
|
|
3288
|
+
// src/swap/index.ts
|
|
3289
|
+
var swap_exports = {};
|
|
3290
|
+
__export(swap_exports, {
|
|
3291
|
+
calculateEthForExactNxm: () => calculateEthForExactNxm,
|
|
3292
|
+
calculateExactEthForNxm: () => calculateExactEthForNxm,
|
|
3293
|
+
calculateExactNxmForEth: () => calculateExactNxmForEth,
|
|
3294
|
+
calculateNxmForExactEth: () => calculateNxmForExactEth,
|
|
3295
|
+
calculatePriceImpactA: () => calculatePriceImpactA,
|
|
3296
|
+
calculatePriceImpactB: () => calculatePriceImpactB,
|
|
3297
|
+
calculateSpotPrice: () => calculateSpotPrice
|
|
3298
|
+
});
|
|
3299
|
+
|
|
3107
3300
|
// src/swap/calculateExactNxmForEth.ts
|
|
3108
3301
|
var calculateExactNxmForEth = (ethIn, reserves) => {
|
|
3109
3302
|
if (ethIn <= 0n)
|
|
@@ -3177,9 +3370,30 @@ var calculatePriceImpactB = (nxmIn, reserves) => {
|
|
|
3177
3370
|
return BigInt(1e6) - BigInt(1e6) * ethOut / ethOutAtSpotPrice;
|
|
3178
3371
|
};
|
|
3179
3372
|
|
|
3373
|
+
// src/buyCover/index.ts
|
|
3374
|
+
var buyCover_exports = {};
|
|
3375
|
+
__export(buyCover_exports, {
|
|
3376
|
+
calculatePremiumWithCommissionAndSlippage: () => calculatePremiumWithCommissionAndSlippage
|
|
3377
|
+
});
|
|
3378
|
+
|
|
3180
3379
|
// src/constants/buyCover.ts
|
|
3380
|
+
var CoverAsset = /* @__PURE__ */ ((CoverAsset2) => {
|
|
3381
|
+
CoverAsset2[CoverAsset2["ETH"] = 0] = "ETH";
|
|
3382
|
+
CoverAsset2[CoverAsset2["DAI"] = 1] = "DAI";
|
|
3383
|
+
return CoverAsset2;
|
|
3384
|
+
})(CoverAsset || {});
|
|
3385
|
+
var CoverId = /* @__PURE__ */ ((CoverId2) => {
|
|
3386
|
+
CoverId2[CoverId2["BUY"] = 0] = "BUY";
|
|
3387
|
+
return CoverId2;
|
|
3388
|
+
})(CoverId || {});
|
|
3181
3389
|
var COMMISSION_DENOMINATOR = 1e4;
|
|
3182
3390
|
var SLIPPAGE_DENOMINATOR = 1e4;
|
|
3391
|
+
var TARGET_PRICE_DENOMINATOR = 1e4;
|
|
3392
|
+
var MINIMUM_COVER_PERIOD = 28;
|
|
3393
|
+
var MAXIMUM_COVER_PERIOD = 365;
|
|
3394
|
+
var DEFAULT_SLIPPAGE = 10;
|
|
3395
|
+
var DEFAULT_COMMISSION_RATIO = 1500;
|
|
3396
|
+
var NEXUS_MUTUAL_DAO_TREASURY_ADDRESS = "0x586b9b2F8010b284A0197f392156f1A7Eb5e86e9";
|
|
3183
3397
|
|
|
3184
3398
|
// src/buyCover/calculatePremiumWithCommissionAndSlippage.ts
|
|
3185
3399
|
var calculatePremiumWithCommissionAndSlippage = (premium, commission = 0, slippage = 0) => {
|
|
@@ -3187,8 +3401,175 @@ var calculatePremiumWithCommissionAndSlippage = (premium, commission = 0, slippa
|
|
|
3187
3401
|
const premiumWithCommissionAndSlippage = premiumWithCommission * BigInt(SLIPPAGE_DENOMINATOR + slippage) / BigInt(SLIPPAGE_DENOMINATOR);
|
|
3188
3402
|
return premiumWithCommissionAndSlippage;
|
|
3189
3403
|
};
|
|
3404
|
+
|
|
3405
|
+
// src/types/index.ts
|
|
3406
|
+
var types_exports2 = {};
|
|
3407
|
+
|
|
3408
|
+
// src/quote/index.ts
|
|
3409
|
+
var quote_exports = {};
|
|
3410
|
+
__export(quote_exports, {
|
|
3411
|
+
getQuoteAndBuyCoverInputs: () => getQuoteAndBuyCoverInputs,
|
|
3412
|
+
sumPoolCapacities: () => sumPoolCapacities
|
|
3413
|
+
});
|
|
3414
|
+
|
|
3415
|
+
// src/quote/getQuoteAndBuyCoverInputs.ts
|
|
3416
|
+
var import_axios = __toESM(require("axios"));
|
|
3417
|
+
var import_dotenv = __toESM(require_main());
|
|
3418
|
+
import_dotenv.default.config();
|
|
3419
|
+
async function getQuoteAndBuyCoverInputs(productId, coverAmount, coverPeriod, coverAsset, coverBuyerAddress, slippage = DEFAULT_SLIPPAGE, ipfsCid = "") {
|
|
3420
|
+
if (!process.env.COVER_ROUTER_URL) {
|
|
3421
|
+
return { result: void 0, error: { message: "Missing COVER_ROUTER_URL env var" } };
|
|
3422
|
+
}
|
|
3423
|
+
if (!Number.isInteger(productId) || productId <= 0) {
|
|
3424
|
+
return { result: void 0, error: { message: "Invalid productId: must be a positive integer" } };
|
|
3425
|
+
}
|
|
3426
|
+
if (typeof coverAmount !== "string" || !/^\d+$/.test(coverAmount) || parseInt(coverAmount, 10) <= 0) {
|
|
3427
|
+
return { result: void 0, error: { message: "Invalid coverAmount: must be a positive integer string" } };
|
|
3428
|
+
}
|
|
3429
|
+
if (!Number.isInteger(coverPeriod) || coverPeriod < MINIMUM_COVER_PERIOD || coverPeriod > MAXIMUM_COVER_PERIOD) {
|
|
3430
|
+
return {
|
|
3431
|
+
result: void 0,
|
|
3432
|
+
error: {
|
|
3433
|
+
message: `Invalid coverPeriod: must be between ${MINIMUM_COVER_PERIOD} and ${MAXIMUM_COVER_PERIOD} days`
|
|
3434
|
+
}
|
|
3435
|
+
};
|
|
3436
|
+
}
|
|
3437
|
+
const coverAssetsString = Object.keys(CoverAsset).filter((k) => isNaN(+k)).map((k) => `CoverAsset.${k}`).join(", ");
|
|
3438
|
+
if (!Object.values(CoverAsset).includes(coverAsset)) {
|
|
3439
|
+
return {
|
|
3440
|
+
result: void 0,
|
|
3441
|
+
error: {
|
|
3442
|
+
message: `Invalid coverAsset: must be one of ${coverAssetsString}`
|
|
3443
|
+
}
|
|
3444
|
+
};
|
|
3445
|
+
}
|
|
3446
|
+
if (!/^0x[a-fA-F0-9]{40}$/.test(coverBuyerAddress)) {
|
|
3447
|
+
return { result: void 0, error: { message: "Invalid coverBuyerAddress: must be a valid Ethereum address" } };
|
|
3448
|
+
}
|
|
3449
|
+
if (typeof slippage !== "number" || slippage < 0 || slippage > SLIPPAGE_DENOMINATOR) {
|
|
3450
|
+
return {
|
|
3451
|
+
result: void 0,
|
|
3452
|
+
error: { message: `Invalid slippage: must be a number between 0 and ${SLIPPAGE_DENOMINATOR}` }
|
|
3453
|
+
};
|
|
3454
|
+
}
|
|
3455
|
+
if (typeof ipfsCid !== "string") {
|
|
3456
|
+
return { result: void 0, error: { message: "Invalid ipfsCid: must be a valid IPFS CID" } };
|
|
3457
|
+
}
|
|
3458
|
+
try {
|
|
3459
|
+
const { quote, capacities } = await getQuote(productId, coverAmount, coverPeriod, coverAsset);
|
|
3460
|
+
const maxPremiumInAsset = calculatePremiumWithCommissionAndSlippage(
|
|
3461
|
+
BigInt(quote.premiumInAsset),
|
|
3462
|
+
DEFAULT_COMMISSION_RATIO,
|
|
3463
|
+
slippage
|
|
3464
|
+
);
|
|
3465
|
+
const yearlyCostPerc = calculatePremiumWithCommissionAndSlippage(
|
|
3466
|
+
BigInt(quote.annualPrice),
|
|
3467
|
+
DEFAULT_COMMISSION_RATIO,
|
|
3468
|
+
slippage
|
|
3469
|
+
);
|
|
3470
|
+
const result = {
|
|
3471
|
+
displayInfo: {
|
|
3472
|
+
premiumInAsset: maxPremiumInAsset.toString(),
|
|
3473
|
+
coverAmount,
|
|
3474
|
+
yearlyCostPerc: Number(yearlyCostPerc) / TARGET_PRICE_DENOMINATOR,
|
|
3475
|
+
maxCapacity: sumPoolCapacities(capacities)
|
|
3476
|
+
},
|
|
3477
|
+
buyCoverInput: {
|
|
3478
|
+
buyCoverParams: {
|
|
3479
|
+
coverId: 0 /* BUY */,
|
|
3480
|
+
owner: coverBuyerAddress,
|
|
3481
|
+
productId,
|
|
3482
|
+
coverAsset,
|
|
3483
|
+
amount: coverAmount,
|
|
3484
|
+
period: coverPeriod * 60 * 60 * 24,
|
|
3485
|
+
// seconds
|
|
3486
|
+
maxPremiumInAsset: maxPremiumInAsset.toString(),
|
|
3487
|
+
paymentAsset: coverAsset,
|
|
3488
|
+
commissionRatio: DEFAULT_COMMISSION_RATIO,
|
|
3489
|
+
commissionDestination: NEXUS_MUTUAL_DAO_TREASURY_ADDRESS,
|
|
3490
|
+
ipfsData: ipfsCid
|
|
3491
|
+
},
|
|
3492
|
+
poolAllocationRequests: quote.poolAllocationRequests
|
|
3493
|
+
}
|
|
3494
|
+
};
|
|
3495
|
+
return { result, error: void 0 };
|
|
3496
|
+
} catch (error) {
|
|
3497
|
+
return handleError(error);
|
|
3498
|
+
}
|
|
3499
|
+
}
|
|
3500
|
+
async function getQuote(productId, coverAmount, coverPeriod, coverAsset) {
|
|
3501
|
+
const params = { productId, amount: coverAmount, period: coverPeriod, coverAsset };
|
|
3502
|
+
const response = await import_axios.default.get(process.env.COVER_ROUTER_URL + "/quote", { params });
|
|
3503
|
+
return response.data;
|
|
3504
|
+
}
|
|
3505
|
+
function sumPoolCapacities(capacities) {
|
|
3506
|
+
let totalAmount = BigInt(0);
|
|
3507
|
+
capacities.forEach((poolCapacity) => {
|
|
3508
|
+
poolCapacity.capacity.forEach((capacity) => totalAmount += BigInt(capacity.amount));
|
|
3509
|
+
});
|
|
3510
|
+
return totalAmount.toString();
|
|
3511
|
+
}
|
|
3512
|
+
async function handleError(error) {
|
|
3513
|
+
const axiosError = error;
|
|
3514
|
+
if (axiosError.isAxiosError) {
|
|
3515
|
+
console.log("axiosError.response.data: ", require("util").inspect(axiosError.response?.data, { depth: null }));
|
|
3516
|
+
if (axiosError.response?.data?.error?.includes("Not enough capacity")) {
|
|
3517
|
+
return {
|
|
3518
|
+
result: void 0,
|
|
3519
|
+
error: {
|
|
3520
|
+
message: axiosError.response?.data.error,
|
|
3521
|
+
data: {}
|
|
3522
|
+
}
|
|
3523
|
+
};
|
|
3524
|
+
}
|
|
3525
|
+
}
|
|
3526
|
+
return {
|
|
3527
|
+
result: void 0,
|
|
3528
|
+
error: { message: "Something went wrong" }
|
|
3529
|
+
};
|
|
3530
|
+
}
|
|
3531
|
+
|
|
3532
|
+
// src/constants/index.ts
|
|
3533
|
+
var constants_exports = {};
|
|
3534
|
+
__export(constants_exports, {
|
|
3535
|
+
COMMISSION_DENOMINATOR: () => COMMISSION_DENOMINATOR,
|
|
3536
|
+
CoverAsset: () => CoverAsset,
|
|
3537
|
+
CoverId: () => CoverId,
|
|
3538
|
+
DEFAULT_COMMISSION_RATIO: () => DEFAULT_COMMISSION_RATIO,
|
|
3539
|
+
DEFAULT_SLIPPAGE: () => DEFAULT_SLIPPAGE,
|
|
3540
|
+
MAXIMUM_COVER_PERIOD: () => MAXIMUM_COVER_PERIOD,
|
|
3541
|
+
MINIMUM_COVER_PERIOD: () => MINIMUM_COVER_PERIOD,
|
|
3542
|
+
NEXUS_MUTUAL_DAO_TREASURY_ADDRESS: () => NEXUS_MUTUAL_DAO_TREASURY_ADDRESS,
|
|
3543
|
+
SLIPPAGE_DENOMINATOR: () => SLIPPAGE_DENOMINATOR,
|
|
3544
|
+
TARGET_PRICE_DENOMINATOR: () => TARGET_PRICE_DENOMINATOR
|
|
3545
|
+
});
|
|
3546
|
+
|
|
3547
|
+
// src/index.ts
|
|
3548
|
+
__reExport(src_exports, require("@nexusmutual/deployments"), module.exports);
|
|
3549
|
+
var nexusSdk = {
|
|
3550
|
+
...deployments,
|
|
3551
|
+
products: products_default,
|
|
3552
|
+
productTypes: product_types_default,
|
|
3553
|
+
...types_exports,
|
|
3554
|
+
...swap_exports,
|
|
3555
|
+
...buyCover_exports,
|
|
3556
|
+
...types_exports2,
|
|
3557
|
+
...quote_exports,
|
|
3558
|
+
...constants_exports
|
|
3559
|
+
};
|
|
3560
|
+
var src_default = nexusSdk;
|
|
3190
3561
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3191
3562
|
0 && (module.exports = {
|
|
3563
|
+
COMMISSION_DENOMINATOR,
|
|
3564
|
+
CoverAsset,
|
|
3565
|
+
CoverId,
|
|
3566
|
+
DEFAULT_COMMISSION_RATIO,
|
|
3567
|
+
DEFAULT_SLIPPAGE,
|
|
3568
|
+
MAXIMUM_COVER_PERIOD,
|
|
3569
|
+
MINIMUM_COVER_PERIOD,
|
|
3570
|
+
NEXUS_MUTUAL_DAO_TREASURY_ADDRESS,
|
|
3571
|
+
SLIPPAGE_DENOMINATOR,
|
|
3572
|
+
TARGET_PRICE_DENOMINATOR,
|
|
3192
3573
|
allLogoFileNames,
|
|
3193
3574
|
allLogoNames,
|
|
3194
3575
|
calculateEthForExactNxm,
|
|
@@ -3199,8 +3580,10 @@ var calculatePremiumWithCommissionAndSlippage = (premium, commission = 0, slippa
|
|
|
3199
3580
|
calculatePriceImpactA,
|
|
3200
3581
|
calculatePriceImpactB,
|
|
3201
3582
|
calculateSpotPrice,
|
|
3583
|
+
getQuoteAndBuyCoverInputs,
|
|
3202
3584
|
productTypes,
|
|
3203
3585
|
products,
|
|
3586
|
+
sumPoolCapacities,
|
|
3204
3587
|
...require("@nexusmutual/deployments")
|
|
3205
3588
|
});
|
|
3206
3589
|
//# sourceMappingURL=index.js.map
|