@nexusmutual/sdk 0.3.3 → 0.3.5
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/products.json +5 -5
- package/dist/index.d.mts +43 -47
- package/dist/index.d.ts +43 -47
- package/dist/index.js +375 -537
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +367 -556
- package/dist/index.mjs.map +1 -1
- package/dist/logos/etherfi-zircuit-pendle.svg +1 -1
- package/dist/scripts/copy-logos.cjs +2 -3
- package/package.json +4 -2
package/dist/index.mjs
CHANGED
|
@@ -1,192 +1,372 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
8
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
9
|
-
}) : x)(function(x) {
|
|
10
|
-
if (typeof require !== "undefined")
|
|
11
|
-
return require.apply(this, arguments);
|
|
12
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
13
|
-
});
|
|
14
|
-
var __commonJS = (cb, mod) => function __require2() {
|
|
15
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
16
|
-
};
|
|
17
2
|
var __export = (target, all) => {
|
|
18
3
|
for (var name in all)
|
|
19
4
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
20
5
|
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
6
|
+
|
|
7
|
+
// src/index.ts
|
|
8
|
+
import * as deployments from "@nexusmutual/deployments";
|
|
9
|
+
|
|
10
|
+
// src/buyCover/index.ts
|
|
11
|
+
var buyCover_exports = {};
|
|
12
|
+
__export(buyCover_exports, {
|
|
13
|
+
calculatePremiumWithCommissionAndSlippage: () => calculatePremiumWithCommissionAndSlippage
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
// src/constants/buyCover.ts
|
|
17
|
+
var CoverAsset = /* @__PURE__ */ ((CoverAsset2) => {
|
|
18
|
+
CoverAsset2[CoverAsset2["ETH"] = 0] = "ETH";
|
|
19
|
+
CoverAsset2[CoverAsset2["DAI"] = 1] = "DAI";
|
|
20
|
+
return CoverAsset2;
|
|
21
|
+
})(CoverAsset || {});
|
|
22
|
+
var CoverId = /* @__PURE__ */ ((CoverId2) => {
|
|
23
|
+
CoverId2[CoverId2["BUY"] = 0] = "BUY";
|
|
24
|
+
return CoverId2;
|
|
25
|
+
})(CoverId || {});
|
|
26
|
+
var COMMISSION_DENOMINATOR = 1e4;
|
|
27
|
+
var SLIPPAGE_DENOMINATOR = 1e4;
|
|
28
|
+
var TARGET_PRICE_DENOMINATOR = 1e4;
|
|
29
|
+
var MINIMUM_COVER_PERIOD = 28;
|
|
30
|
+
var MAXIMUM_COVER_PERIOD = 365;
|
|
31
|
+
var DEFAULT_SLIPPAGE = 10;
|
|
32
|
+
var DEFAULT_COMMISSION_RATIO = 1500;
|
|
33
|
+
var NEXUS_MUTUAL_DAO_TREASURY_ADDRESS = "0x586b9b2F8010b284A0197f392156f1A7Eb5e86e9";
|
|
34
|
+
|
|
35
|
+
// src/buyCover/calculatePremiumWithCommissionAndSlippage.ts
|
|
36
|
+
var calculatePremiumWithCommissionAndSlippage = (premium, commission = 0, slippage = 0) => {
|
|
37
|
+
const premiumWithCommission = premium * BigInt(COMMISSION_DENOMINATOR) / BigInt(COMMISSION_DENOMINATOR - commission);
|
|
38
|
+
const premiumWithCommissionAndSlippage = premiumWithCommission * BigInt(SLIPPAGE_DENOMINATOR + slippage) / BigInt(SLIPPAGE_DENOMINATOR);
|
|
39
|
+
return premiumWithCommissionAndSlippage;
|
|
28
40
|
};
|
|
29
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
30
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
31
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
32
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
33
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
34
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
35
|
-
mod
|
|
36
|
-
));
|
|
37
41
|
|
|
38
|
-
//
|
|
39
|
-
var
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
},
|
|
74
|
-
keywords: [
|
|
75
|
-
"dotenv",
|
|
76
|
-
"env",
|
|
77
|
-
".env",
|
|
78
|
-
"environment",
|
|
79
|
-
"variables",
|
|
80
|
-
"config",
|
|
81
|
-
"settings"
|
|
82
|
-
],
|
|
83
|
-
readmeFilename: "README.md",
|
|
84
|
-
license: "BSD-2-Clause",
|
|
85
|
-
devDependencies: {
|
|
86
|
-
"@types/node": "^17.0.9",
|
|
87
|
-
decache: "^4.6.1",
|
|
88
|
-
dtslint: "^3.7.0",
|
|
89
|
-
sinon: "^12.0.1",
|
|
90
|
-
standard: "^16.0.4",
|
|
91
|
-
"standard-markdown": "^7.1.0",
|
|
92
|
-
"standard-version": "^9.3.2",
|
|
93
|
-
tap: "^15.1.6",
|
|
94
|
-
tar: "^6.1.11",
|
|
95
|
-
typescript: "^4.5.4"
|
|
96
|
-
},
|
|
97
|
-
engines: {
|
|
98
|
-
node: ">=12"
|
|
42
|
+
// src/constants/index.ts
|
|
43
|
+
var constants_exports = {};
|
|
44
|
+
__export(constants_exports, {
|
|
45
|
+
COMMISSION_DENOMINATOR: () => COMMISSION_DENOMINATOR,
|
|
46
|
+
CoverAsset: () => CoverAsset,
|
|
47
|
+
CoverId: () => CoverId,
|
|
48
|
+
DEFAULT_COMMISSION_RATIO: () => DEFAULT_COMMISSION_RATIO,
|
|
49
|
+
DEFAULT_SLIPPAGE: () => DEFAULT_SLIPPAGE,
|
|
50
|
+
MAXIMUM_COVER_PERIOD: () => MAXIMUM_COVER_PERIOD,
|
|
51
|
+
MINIMUM_COVER_PERIOD: () => MINIMUM_COVER_PERIOD,
|
|
52
|
+
NEXUS_MUTUAL_DAO_TREASURY_ADDRESS: () => NEXUS_MUTUAL_DAO_TREASURY_ADDRESS,
|
|
53
|
+
SLIPPAGE_DENOMINATOR: () => SLIPPAGE_DENOMINATOR,
|
|
54
|
+
TARGET_PRICE_DENOMINATOR: () => TARGET_PRICE_DENOMINATOR
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// src/quote/index.ts
|
|
58
|
+
var quote_exports = {};
|
|
59
|
+
__export(quote_exports, {
|
|
60
|
+
getQuoteAndBuyCoverInputs: () => getQuoteAndBuyCoverInputs
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// src/quote/getQuoteAndBuyCoverInputs.ts
|
|
64
|
+
import axios from "axios";
|
|
65
|
+
async function getQuoteAndBuyCoverInputs(productId, coverAmount, coverPeriod, coverAsset, coverBuyerAddress, slippage = DEFAULT_SLIPPAGE / SLIPPAGE_DENOMINATOR, ipfsCid = "", coverRouterUrl = "https://api.nexusmutual.io/v2") {
|
|
66
|
+
if (!Number.isInteger(productId) || productId <= 0) {
|
|
67
|
+
return { result: void 0, error: { message: "Invalid productId: must be a positive integer" } };
|
|
68
|
+
}
|
|
69
|
+
if (typeof coverAmount !== "string" || !/^\d+$/.test(coverAmount) || parseInt(coverAmount, 10) <= 0) {
|
|
70
|
+
return { result: void 0, error: { message: "Invalid coverAmount: must be a positive integer string" } };
|
|
71
|
+
}
|
|
72
|
+
if (!Number.isInteger(coverPeriod) || coverPeriod < MINIMUM_COVER_PERIOD || coverPeriod > MAXIMUM_COVER_PERIOD) {
|
|
73
|
+
return {
|
|
74
|
+
result: void 0,
|
|
75
|
+
error: {
|
|
76
|
+
message: `Invalid coverPeriod: must be between ${MINIMUM_COVER_PERIOD} and ${MAXIMUM_COVER_PERIOD} days`
|
|
99
77
|
}
|
|
100
78
|
};
|
|
101
79
|
}
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
var fs = __require("fs");
|
|
109
|
-
var path = __require("path");
|
|
110
|
-
var os = __require("os");
|
|
111
|
-
var packageJson = require_package();
|
|
112
|
-
var version = packageJson.version;
|
|
113
|
-
var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
|
|
114
|
-
function parse(src) {
|
|
115
|
-
const obj = {};
|
|
116
|
-
let lines = src.toString();
|
|
117
|
-
lines = lines.replace(/\r\n?/mg, "\n");
|
|
118
|
-
let match;
|
|
119
|
-
while ((match = LINE.exec(lines)) != null) {
|
|
120
|
-
const key = match[1];
|
|
121
|
-
let value = match[2] || "";
|
|
122
|
-
value = value.trim();
|
|
123
|
-
const maybeQuote = value[0];
|
|
124
|
-
value = value.replace(/^(['"`])([\s\S]*)\1$/mg, "$2");
|
|
125
|
-
if (maybeQuote === '"') {
|
|
126
|
-
value = value.replace(/\\n/g, "\n");
|
|
127
|
-
value = value.replace(/\\r/g, "\r");
|
|
128
|
-
}
|
|
129
|
-
obj[key] = value;
|
|
80
|
+
const coverAssetsString = Object.keys(CoverAsset).filter((k) => isNaN(+k)).map((k) => `CoverAsset.${k}`).join(", ");
|
|
81
|
+
if (!Object.values(CoverAsset).includes(coverAsset)) {
|
|
82
|
+
return {
|
|
83
|
+
result: void 0,
|
|
84
|
+
error: {
|
|
85
|
+
message: `Invalid coverAsset: must be one of ${coverAssetsString}`
|
|
130
86
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
if (!/^0x[a-fA-F0-9]{40}$/.test(coverBuyerAddress)) {
|
|
90
|
+
return { result: void 0, error: { message: "Invalid coverBuyerAddress: must be a valid Ethereum address" } };
|
|
91
|
+
}
|
|
92
|
+
if (typeof slippage !== "number" || slippage < 0 || slippage > 1) {
|
|
93
|
+
return {
|
|
94
|
+
result: void 0,
|
|
95
|
+
error: { message: "Invalid slippage: must be a number between 0 and 1" }
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
if (typeof ipfsCid !== "string") {
|
|
99
|
+
return { result: void 0, error: { message: "Invalid ipfsCid: must be a valid IPFS CID" } };
|
|
100
|
+
}
|
|
101
|
+
slippage = slippage * SLIPPAGE_DENOMINATOR;
|
|
102
|
+
try {
|
|
103
|
+
const { quote } = await getQuote(productId, coverAmount, coverPeriod, coverAsset, coverRouterUrl);
|
|
104
|
+
const maxPremiumInAsset = calculatePremiumWithCommissionAndSlippage(
|
|
105
|
+
BigInt(quote.premiumInAsset),
|
|
106
|
+
DEFAULT_COMMISSION_RATIO,
|
|
107
|
+
slippage
|
|
108
|
+
);
|
|
109
|
+
const yearlyCostPerc = calculatePremiumWithCommissionAndSlippage(
|
|
110
|
+
BigInt(quote.annualPrice),
|
|
111
|
+
DEFAULT_COMMISSION_RATIO,
|
|
112
|
+
slippage
|
|
113
|
+
);
|
|
114
|
+
const result = {
|
|
115
|
+
displayInfo: {
|
|
116
|
+
premiumInAsset: maxPremiumInAsset.toString(),
|
|
117
|
+
coverAmount,
|
|
118
|
+
yearlyCostPerc: Number(yearlyCostPerc) / TARGET_PRICE_DENOMINATOR,
|
|
119
|
+
maxCapacity: await getProductCapacity(productId, coverPeriod, coverAsset, coverRouterUrl) ?? ""
|
|
120
|
+
},
|
|
121
|
+
buyCoverInput: {
|
|
122
|
+
buyCoverParams: {
|
|
123
|
+
coverId: 0 /* BUY */,
|
|
124
|
+
owner: coverBuyerAddress,
|
|
125
|
+
productId,
|
|
126
|
+
coverAsset,
|
|
127
|
+
amount: coverAmount,
|
|
128
|
+
period: coverPeriod * 60 * 60 * 24,
|
|
129
|
+
// seconds
|
|
130
|
+
maxPremiumInAsset: maxPremiumInAsset.toString(),
|
|
131
|
+
paymentAsset: coverAsset,
|
|
132
|
+
commissionRatio: DEFAULT_COMMISSION_RATIO,
|
|
133
|
+
commissionDestination: NEXUS_MUTUAL_DAO_TREASURY_ADDRESS,
|
|
134
|
+
ipfsData: ipfsCid
|
|
135
|
+
},
|
|
136
|
+
poolAllocationRequests: quote.poolAllocationRequests
|
|
151
137
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
138
|
+
};
|
|
139
|
+
return { result, error: void 0 };
|
|
140
|
+
} catch (error) {
|
|
141
|
+
const errorResponse = await handleError(error, productId, coverPeriod, coverAsset, coverRouterUrl);
|
|
142
|
+
return errorResponse;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
async function getQuote(productId, coverAmount, coverPeriod, coverAsset, coverRouterUrl) {
|
|
146
|
+
const params = { productId, amount: coverAmount, period: coverPeriod, coverAsset };
|
|
147
|
+
const response = await axios.get(coverRouterUrl + "/quote", { params });
|
|
148
|
+
if (!response.data) {
|
|
149
|
+
throw new Error("Failed to fetch cover quote");
|
|
150
|
+
}
|
|
151
|
+
return response.data;
|
|
152
|
+
}
|
|
153
|
+
async function getProductCapacity(productId, coverPeriod, coverAsset, coverRouterUrl) {
|
|
154
|
+
const params = { period: coverPeriod };
|
|
155
|
+
const capacityUrl = coverRouterUrl + `/capacity/${productId}`;
|
|
156
|
+
const response = await axios.get(capacityUrl, { params });
|
|
157
|
+
if (!response.data) {
|
|
158
|
+
throw new Error("Failed to fetch cover capacities");
|
|
159
|
+
}
|
|
160
|
+
return response.data.availableCapacity.find((av) => av.assetId === coverAsset)?.amount;
|
|
161
|
+
}
|
|
162
|
+
async function handleError(error, productId, coverPeriod, coverAsset, coverRouterUrl) {
|
|
163
|
+
const axiosError = error;
|
|
164
|
+
if (axiosError.isAxiosError) {
|
|
165
|
+
if (axiosError.response?.data?.error?.includes("Not enough capacity")) {
|
|
166
|
+
const maxCapacity = await getProductCapacity(productId, coverPeriod, coverAsset, coverRouterUrl);
|
|
167
|
+
return {
|
|
168
|
+
result: void 0,
|
|
169
|
+
error: {
|
|
170
|
+
message: axiosError.response?.data.error,
|
|
171
|
+
data: maxCapacity ? { maxCapacity } : void 0
|
|
174
172
|
}
|
|
175
|
-
|
|
176
|
-
}
|
|
173
|
+
};
|
|
177
174
|
}
|
|
178
|
-
var DotenvModule = {
|
|
179
|
-
config,
|
|
180
|
-
parse
|
|
181
|
-
};
|
|
182
|
-
module.exports.config = DotenvModule.config;
|
|
183
|
-
module.exports.parse = DotenvModule.parse;
|
|
184
|
-
module.exports = DotenvModule;
|
|
185
175
|
}
|
|
176
|
+
return {
|
|
177
|
+
result: void 0,
|
|
178
|
+
error: { message: error.message || "Something went wrong" }
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// src/swap/index.ts
|
|
183
|
+
var swap_exports = {};
|
|
184
|
+
__export(swap_exports, {
|
|
185
|
+
calculateEthForExactNxm: () => calculateEthForExactNxm,
|
|
186
|
+
calculateExactEthForNxm: () => calculateExactEthForNxm,
|
|
187
|
+
calculateExactNxmForEth: () => calculateExactNxmForEth,
|
|
188
|
+
calculateNxmForExactEth: () => calculateNxmForExactEth,
|
|
189
|
+
calculatePriceImpactA: () => calculatePriceImpactA,
|
|
190
|
+
calculatePriceImpactB: () => calculatePriceImpactB,
|
|
191
|
+
calculateSpotPrice: () => calculateSpotPrice
|
|
186
192
|
});
|
|
187
193
|
|
|
188
|
-
// src/
|
|
189
|
-
|
|
194
|
+
// src/swap/calculateExactNxmForEth.ts
|
|
195
|
+
var calculateExactNxmForEth = (ethIn, reserves) => {
|
|
196
|
+
if (ethIn <= 0n) {
|
|
197
|
+
throw new Error("ETH in value must be greater than 0");
|
|
198
|
+
}
|
|
199
|
+
const k = reserves.nxmA * reserves.ethReserve;
|
|
200
|
+
const ethReservesAfter = reserves.ethReserve + ethIn;
|
|
201
|
+
const nxmReservesAfter = k / ethReservesAfter;
|
|
202
|
+
const nxmOut = reserves.nxmA - nxmReservesAfter;
|
|
203
|
+
if (nxmOut < 0n) {
|
|
204
|
+
throw new Error("Cannot swap this amount");
|
|
205
|
+
}
|
|
206
|
+
return nxmOut;
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
// src/swap/calculateExactEthForNxm.ts
|
|
210
|
+
var calculateExactEthForNxm = (nxmIn, reserves) => {
|
|
211
|
+
if (nxmIn <= 0n) {
|
|
212
|
+
throw new Error("NXM in value must be greater than 0");
|
|
213
|
+
}
|
|
214
|
+
const k = reserves.nxmB * reserves.ethReserve;
|
|
215
|
+
const nxmReservesAfter = reserves.nxmB + nxmIn;
|
|
216
|
+
const ethReservesAfter = k / nxmReservesAfter;
|
|
217
|
+
const ethOut = reserves.ethReserve - ethReservesAfter;
|
|
218
|
+
if (ethOut < 0n) {
|
|
219
|
+
throw new Error("Cannot swap this amount");
|
|
220
|
+
}
|
|
221
|
+
return ethOut;
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
// src/swap/calculateNxmForExactEth.ts
|
|
225
|
+
var calculateNxmForExactEth = (ethOut, reserves) => {
|
|
226
|
+
if (ethOut <= 0n || ethOut >= reserves.ethReserve) {
|
|
227
|
+
throw new Error("ETH out value must be greater than 0 and less than the reserves");
|
|
228
|
+
}
|
|
229
|
+
const k = reserves.nxmB * reserves.ethReserve;
|
|
230
|
+
const ethReservesAfter = reserves.ethReserve - ethOut;
|
|
231
|
+
const nxmReservesAfter = k / ethReservesAfter;
|
|
232
|
+
const nxmIn = nxmReservesAfter - reserves.nxmB;
|
|
233
|
+
return nxmIn;
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
// src/swap/calculateEthForExactNxm.ts
|
|
237
|
+
var calculateEthForExactNxm = (nxmOut, reserves) => {
|
|
238
|
+
if (nxmOut <= 0n || nxmOut >= reserves.nxmA) {
|
|
239
|
+
throw new Error("NXM out value must be greater than 0 and less than the reserves");
|
|
240
|
+
}
|
|
241
|
+
const k = reserves.nxmA * reserves.ethReserve;
|
|
242
|
+
const nxmReservesAfter = reserves.nxmA - nxmOut;
|
|
243
|
+
const ethReservesAfter = k / nxmReservesAfter;
|
|
244
|
+
const ethIn = ethReservesAfter - reserves.ethReserve;
|
|
245
|
+
return ethIn;
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
// src/swap/calculateSpotPrice.ts
|
|
249
|
+
var calculateSpotPrice = (reserves) => {
|
|
250
|
+
const oneEth = BigInt(1e18);
|
|
251
|
+
return {
|
|
252
|
+
spotPriceA: oneEth * reserves.ethReserve / reserves.nxmA,
|
|
253
|
+
spotPriceB: oneEth * reserves.ethReserve / reserves.nxmB
|
|
254
|
+
};
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
// src/swap/calculatePriceImpactA.ts
|
|
258
|
+
var calculatePriceImpactA = (ethIn, reserves) => {
|
|
259
|
+
const { spotPriceA } = calculateSpotPrice(reserves);
|
|
260
|
+
const nxmOut = calculateExactNxmForEth(ethIn, reserves);
|
|
261
|
+
const nxmOutAtSpotPrice = BigInt(1e18) * ethIn / spotPriceA;
|
|
262
|
+
return BigInt(1e6) - BigInt(1e6) * nxmOut / nxmOutAtSpotPrice;
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
// src/swap/calculatePriceImpactB.ts
|
|
266
|
+
var calculatePriceImpactB = (nxmIn, reserves) => {
|
|
267
|
+
const { spotPriceB } = calculateSpotPrice(reserves);
|
|
268
|
+
const ethOut = calculateExactEthForNxm(nxmIn, reserves);
|
|
269
|
+
const ethOutAtSpotPrice = spotPriceB * nxmIn / BigInt(1e18);
|
|
270
|
+
return BigInt(1e6) - BigInt(1e6) * ethOut / ethOutAtSpotPrice;
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
// src/types/index.ts
|
|
274
|
+
var types_exports = {};
|
|
275
|
+
|
|
276
|
+
// generated/product-types.json
|
|
277
|
+
var product_types_default = [
|
|
278
|
+
{
|
|
279
|
+
id: 0,
|
|
280
|
+
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmdunFJm4A5CUW1ynM7bevsGt6UzQfw6K4ysKqvsqpjWCQ",
|
|
281
|
+
name: "Protocol",
|
|
282
|
+
gracePeriod: 3024e3,
|
|
283
|
+
claimMethod: 0
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
id: 1,
|
|
287
|
+
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmYhCNjfrNTMq8eyg8i7LbBpTkMCHfix9Sv1jrPb7dYZKd",
|
|
288
|
+
name: "Custody",
|
|
289
|
+
gracePeriod: 10368e3,
|
|
290
|
+
claimMethod: 0
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
id: 2,
|
|
294
|
+
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmcPdiLNZmBM8pjQcCzLhH8tjPuhphCVKZeP5P4SBiLx3h",
|
|
295
|
+
name: "Yield Token",
|
|
296
|
+
gracePeriod: 1209600,
|
|
297
|
+
claimMethod: 1
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
id: 3,
|
|
301
|
+
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmUTUfdfuZUjtPAiMZ4YRu77SaiyCov7jrSXTgeGeK8qt3",
|
|
302
|
+
name: "Sherlock Excess",
|
|
303
|
+
gracePeriod: 3024e3,
|
|
304
|
+
claimMethod: 0
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
id: 4,
|
|
308
|
+
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmPmwtwbyKnXBae1dmYD6jmgnewCeZGPMFGepkWMLWaiwC",
|
|
309
|
+
name: "Stakewise ETH Staking",
|
|
310
|
+
gracePeriod: 3024e3,
|
|
311
|
+
claimMethod: 0
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
id: 5,
|
|
315
|
+
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmUKhLi5ZahnzSxsMC9YQZbwwAKGhkHcoYqHUVgE31cXLe",
|
|
316
|
+
name: "Liquid Collective ETH Staking",
|
|
317
|
+
gracePeriod: 3024e3,
|
|
318
|
+
claimMethod: 0
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
id: 6,
|
|
322
|
+
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmWepFbtMYSzJt22ddF1CK9PwbrYgiLk9qJjryDrgpGuus",
|
|
323
|
+
name: "ETH Slashing",
|
|
324
|
+
gracePeriod: 3024e3,
|
|
325
|
+
claimMethod: 0
|
|
326
|
+
},
|
|
327
|
+
{
|
|
328
|
+
id: 7,
|
|
329
|
+
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmQfYgbBhyC3gJMvan9gbzUaZtd4Xy4gubEYfgTFKycBDZ",
|
|
330
|
+
name: "Sherlock Quota Share",
|
|
331
|
+
gracePeriod: 3024e3,
|
|
332
|
+
claimMethod: 0
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
id: 8,
|
|
336
|
+
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmRrKXV9RBNAB5E1ZEigWmvvT24FgrWNSZ8Yw1VNXR8E6Q",
|
|
337
|
+
name: "Native Protocol",
|
|
338
|
+
gracePeriod: 3024e3,
|
|
339
|
+
claimMethod: 0
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
id: 9,
|
|
343
|
+
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmQG8ooLgoQx2YdykwZEUYruoMZ7YP23LK9yiQbw9AGTZi",
|
|
344
|
+
name: "The Retail Mutual",
|
|
345
|
+
gracePeriod: 3672e4,
|
|
346
|
+
claimMethod: 0
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
id: 10,
|
|
350
|
+
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmWXYjBYjdKoRw6kyUvp5gYKjj2ojPPVxNYKr1gDjMLssY",
|
|
351
|
+
name: "UnoRe Quota Share",
|
|
352
|
+
gracePeriod: 3024e3,
|
|
353
|
+
claimMethod: 0
|
|
354
|
+
},
|
|
355
|
+
{
|
|
356
|
+
id: 11,
|
|
357
|
+
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmWV9woyKJirjHd73MhibV59qmqzp1w1gqfMfZBQhneSL8",
|
|
358
|
+
name: "Bundled Protocol Cover",
|
|
359
|
+
gracePeriod: 3024e3,
|
|
360
|
+
claimMethod: 0
|
|
361
|
+
},
|
|
362
|
+
{
|
|
363
|
+
id: 12,
|
|
364
|
+
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmQx2H9A51SARNc4W8Ta2D2woXv2ebkUGZMC5HZoQW8TUX",
|
|
365
|
+
name: "ETH Slashing Umbrella",
|
|
366
|
+
gracePeriod: 3024e3,
|
|
367
|
+
claimMethod: 0
|
|
368
|
+
}
|
|
369
|
+
];
|
|
190
370
|
|
|
191
371
|
// generated/products.json
|
|
192
372
|
var products_default = [
|
|
@@ -1551,7 +1731,7 @@ var products_default = [
|
|
|
1551
1731
|
"DAI"
|
|
1552
1732
|
],
|
|
1553
1733
|
isPrivate: true,
|
|
1554
|
-
timestamp:
|
|
1734
|
+
timestamp: 1684312727
|
|
1555
1735
|
},
|
|
1556
1736
|
{
|
|
1557
1737
|
id: 84,
|
|
@@ -1613,7 +1793,7 @@ var products_default = [
|
|
|
1613
1793
|
"DAI"
|
|
1614
1794
|
],
|
|
1615
1795
|
isPrivate: true,
|
|
1616
|
-
timestamp:
|
|
1796
|
+
timestamp: 1704981731
|
|
1617
1797
|
},
|
|
1618
1798
|
{
|
|
1619
1799
|
id: 88,
|
|
@@ -1630,7 +1810,7 @@ var products_default = [
|
|
|
1630
1810
|
"DAI"
|
|
1631
1811
|
],
|
|
1632
1812
|
isPrivate: true,
|
|
1633
|
-
timestamp:
|
|
1813
|
+
timestamp: 1684312727
|
|
1634
1814
|
},
|
|
1635
1815
|
{
|
|
1636
1816
|
id: 89,
|
|
@@ -1891,7 +2071,7 @@ var products_default = [
|
|
|
1891
2071
|
"DAI"
|
|
1892
2072
|
],
|
|
1893
2073
|
isPrivate: true,
|
|
1894
|
-
timestamp:
|
|
2074
|
+
timestamp: 1689782903
|
|
1895
2075
|
},
|
|
1896
2076
|
{
|
|
1897
2077
|
id: 106,
|
|
@@ -2013,7 +2193,7 @@ var products_default = [
|
|
|
2013
2193
|
"DAI"
|
|
2014
2194
|
],
|
|
2015
2195
|
isPrivate: true,
|
|
2016
|
-
timestamp:
|
|
2196
|
+
timestamp: 1691493035
|
|
2017
2197
|
},
|
|
2018
2198
|
{
|
|
2019
2199
|
id: 114,
|
|
@@ -2768,112 +2948,17 @@ var products_default = [
|
|
|
2768
2948
|
metadata: {
|
|
2769
2949
|
annex: "QmeAB5RzQgQbC2DFa9W49taFEoxhZEUDgnXqvfceFUL4Xm"
|
|
2770
2950
|
},
|
|
2771
|
-
coverAssets: [
|
|
2772
|
-
"ETH"
|
|
2773
|
-
],
|
|
2774
|
-
isPrivate: false,
|
|
2775
|
-
timestamp: 1713185771
|
|
2776
|
-
}
|
|
2777
|
-
];
|
|
2778
|
-
|
|
2779
|
-
// generated/product-types.json
|
|
2780
|
-
var product_types_default = [
|
|
2781
|
-
{
|
|
2782
|
-
id: 0,
|
|
2783
|
-
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmdunFJm4A5CUW1ynM7bevsGt6UzQfw6K4ysKqvsqpjWCQ",
|
|
2784
|
-
name: "Protocol",
|
|
2785
|
-
gracePeriod: 3024e3,
|
|
2786
|
-
claimMethod: 0
|
|
2787
|
-
},
|
|
2788
|
-
{
|
|
2789
|
-
id: 1,
|
|
2790
|
-
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmYhCNjfrNTMq8eyg8i7LbBpTkMCHfix9Sv1jrPb7dYZKd",
|
|
2791
|
-
name: "Custody",
|
|
2792
|
-
gracePeriod: 10368e3,
|
|
2793
|
-
claimMethod: 0
|
|
2794
|
-
},
|
|
2795
|
-
{
|
|
2796
|
-
id: 2,
|
|
2797
|
-
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmcPdiLNZmBM8pjQcCzLhH8tjPuhphCVKZeP5P4SBiLx3h",
|
|
2798
|
-
name: "Yield Token",
|
|
2799
|
-
gracePeriod: 1209600,
|
|
2800
|
-
claimMethod: 1
|
|
2801
|
-
},
|
|
2802
|
-
{
|
|
2803
|
-
id: 3,
|
|
2804
|
-
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmUTUfdfuZUjtPAiMZ4YRu77SaiyCov7jrSXTgeGeK8qt3",
|
|
2805
|
-
name: "Sherlock Excess",
|
|
2806
|
-
gracePeriod: 3024e3,
|
|
2807
|
-
claimMethod: 0
|
|
2808
|
-
},
|
|
2809
|
-
{
|
|
2810
|
-
id: 4,
|
|
2811
|
-
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmPmwtwbyKnXBae1dmYD6jmgnewCeZGPMFGepkWMLWaiwC",
|
|
2812
|
-
name: "Stakewise ETH Staking",
|
|
2813
|
-
gracePeriod: 3024e3,
|
|
2814
|
-
claimMethod: 0
|
|
2815
|
-
},
|
|
2816
|
-
{
|
|
2817
|
-
id: 5,
|
|
2818
|
-
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmUKhLi5ZahnzSxsMC9YQZbwwAKGhkHcoYqHUVgE31cXLe",
|
|
2819
|
-
name: "Liquid Collective ETH Staking",
|
|
2820
|
-
gracePeriod: 3024e3,
|
|
2821
|
-
claimMethod: 0
|
|
2822
|
-
},
|
|
2823
|
-
{
|
|
2824
|
-
id: 6,
|
|
2825
|
-
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmWepFbtMYSzJt22ddF1CK9PwbrYgiLk9qJjryDrgpGuus",
|
|
2826
|
-
name: "ETH Slashing",
|
|
2827
|
-
gracePeriod: 3024e3,
|
|
2828
|
-
claimMethod: 0
|
|
2829
|
-
},
|
|
2830
|
-
{
|
|
2831
|
-
id: 7,
|
|
2832
|
-
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmQfYgbBhyC3gJMvan9gbzUaZtd4Xy4gubEYfgTFKycBDZ",
|
|
2833
|
-
name: "Sherlock Quota Share",
|
|
2834
|
-
gracePeriod: 3024e3,
|
|
2835
|
-
claimMethod: 0
|
|
2836
|
-
},
|
|
2837
|
-
{
|
|
2838
|
-
id: 8,
|
|
2839
|
-
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmRrKXV9RBNAB5E1ZEigWmvvT24FgrWNSZ8Yw1VNXR8E6Q",
|
|
2840
|
-
name: "Native Protocol",
|
|
2841
|
-
gracePeriod: 3024e3,
|
|
2842
|
-
claimMethod: 0
|
|
2843
|
-
},
|
|
2844
|
-
{
|
|
2845
|
-
id: 9,
|
|
2846
|
-
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmQG8ooLgoQx2YdykwZEUYruoMZ7YP23LK9yiQbw9AGTZi",
|
|
2847
|
-
name: "The Retail Mutual",
|
|
2848
|
-
gracePeriod: 3672e4,
|
|
2849
|
-
claimMethod: 0
|
|
2850
|
-
},
|
|
2851
|
-
{
|
|
2852
|
-
id: 10,
|
|
2853
|
-
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmWXYjBYjdKoRw6kyUvp5gYKjj2ojPPVxNYKr1gDjMLssY",
|
|
2854
|
-
name: "UnoRe Quota Share",
|
|
2855
|
-
gracePeriod: 3024e3,
|
|
2856
|
-
claimMethod: 0
|
|
2857
|
-
},
|
|
2858
|
-
{
|
|
2859
|
-
id: 11,
|
|
2860
|
-
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmWV9woyKJirjHd73MhibV59qmqzp1w1gqfMfZBQhneSL8",
|
|
2861
|
-
name: "Bundled Protocol Cover",
|
|
2862
|
-
gracePeriod: 3024e3,
|
|
2863
|
-
claimMethod: 0
|
|
2864
|
-
},
|
|
2865
|
-
{
|
|
2866
|
-
id: 12,
|
|
2867
|
-
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmQx2H9A51SARNc4W8Ta2D2woXv2ebkUGZMC5HZoQW8TUX",
|
|
2868
|
-
name: "ETH Slashing Umbrella",
|
|
2869
|
-
gracePeriod: 3024e3,
|
|
2870
|
-
claimMethod: 0
|
|
2951
|
+
coverAssets: [
|
|
2952
|
+
"ETH"
|
|
2953
|
+
],
|
|
2954
|
+
isPrivate: false,
|
|
2955
|
+
timestamp: 1713185771
|
|
2871
2956
|
}
|
|
2872
2957
|
];
|
|
2873
2958
|
|
|
2874
2959
|
// generated/types.ts
|
|
2875
|
-
var
|
|
2876
|
-
__export(
|
|
2960
|
+
var types_exports2 = {};
|
|
2961
|
+
__export(types_exports2, {
|
|
2877
2962
|
allLogoFileNames: () => allLogoFileNames,
|
|
2878
2963
|
allLogoNames: () => allLogoNames
|
|
2879
2964
|
});
|
|
@@ -3314,289 +3399,16 @@ var allLogoNames = [
|
|
|
3314
3399
|
"zksync"
|
|
3315
3400
|
];
|
|
3316
3401
|
|
|
3317
|
-
// src/swap/index.ts
|
|
3318
|
-
var swap_exports = {};
|
|
3319
|
-
__export(swap_exports, {
|
|
3320
|
-
calculateEthForExactNxm: () => calculateEthForExactNxm,
|
|
3321
|
-
calculateExactEthForNxm: () => calculateExactEthForNxm,
|
|
3322
|
-
calculateExactNxmForEth: () => calculateExactNxmForEth,
|
|
3323
|
-
calculateNxmForExactEth: () => calculateNxmForExactEth,
|
|
3324
|
-
calculatePriceImpactA: () => calculatePriceImpactA,
|
|
3325
|
-
calculatePriceImpactB: () => calculatePriceImpactB,
|
|
3326
|
-
calculateSpotPrice: () => calculateSpotPrice
|
|
3327
|
-
});
|
|
3328
|
-
|
|
3329
|
-
// src/swap/calculateExactNxmForEth.ts
|
|
3330
|
-
var calculateExactNxmForEth = (ethIn, reserves) => {
|
|
3331
|
-
if (ethIn <= 0n)
|
|
3332
|
-
throw new Error("ETH in value must be greater than 0");
|
|
3333
|
-
const k = reserves.nxmA * reserves.ethReserve;
|
|
3334
|
-
const ethReservesAfter = reserves.ethReserve + ethIn;
|
|
3335
|
-
const nxmReservesAfter = k / ethReservesAfter;
|
|
3336
|
-
const nxmOut = reserves.nxmA - nxmReservesAfter;
|
|
3337
|
-
if (nxmOut < 0n)
|
|
3338
|
-
throw new Error("Cannot swap this amount");
|
|
3339
|
-
return nxmOut;
|
|
3340
|
-
};
|
|
3341
|
-
|
|
3342
|
-
// src/swap/calculateExactEthForNxm.ts
|
|
3343
|
-
var calculateExactEthForNxm = (nxmIn, reserves) => {
|
|
3344
|
-
if (nxmIn <= 0n)
|
|
3345
|
-
throw new Error("NXM in value must be greater than 0");
|
|
3346
|
-
const k = reserves.nxmB * reserves.ethReserve;
|
|
3347
|
-
const nxmReservesAfter = reserves.nxmB + nxmIn;
|
|
3348
|
-
const ethReservesAfter = k / nxmReservesAfter;
|
|
3349
|
-
const ethOut = reserves.ethReserve - ethReservesAfter;
|
|
3350
|
-
if (ethOut < 0n)
|
|
3351
|
-
throw new Error("Cannot swap this amount");
|
|
3352
|
-
return ethOut;
|
|
3353
|
-
};
|
|
3354
|
-
|
|
3355
|
-
// src/swap/calculateNxmForExactEth.ts
|
|
3356
|
-
var calculateNxmForExactEth = (ethOut, reserves) => {
|
|
3357
|
-
if (ethOut <= 0n || ethOut >= reserves.ethReserve)
|
|
3358
|
-
throw new Error("ETH out value must be greater than 0 and less than the reserves");
|
|
3359
|
-
const k = reserves.nxmB * reserves.ethReserve;
|
|
3360
|
-
const ethReservesAfter = reserves.ethReserve - ethOut;
|
|
3361
|
-
const nxmReservesAfter = k / ethReservesAfter;
|
|
3362
|
-
const nxmIn = nxmReservesAfter - reserves.nxmB;
|
|
3363
|
-
return nxmIn;
|
|
3364
|
-
};
|
|
3365
|
-
|
|
3366
|
-
// src/swap/calculateEthForExactNxm.ts
|
|
3367
|
-
var calculateEthForExactNxm = (nxmOut, reserves) => {
|
|
3368
|
-
if (nxmOut <= 0n || nxmOut >= reserves.nxmA)
|
|
3369
|
-
throw new Error("NXM out value must be greater than 0 and less than the reserves");
|
|
3370
|
-
const k = reserves.nxmA * reserves.ethReserve;
|
|
3371
|
-
const nxmReservesAfter = reserves.nxmA - nxmOut;
|
|
3372
|
-
const ethReservesAfter = k / nxmReservesAfter;
|
|
3373
|
-
const ethIn = ethReservesAfter - reserves.ethReserve;
|
|
3374
|
-
return ethIn;
|
|
3375
|
-
};
|
|
3376
|
-
|
|
3377
|
-
// src/swap/calculateSpotPrice.ts
|
|
3378
|
-
var calculateSpotPrice = (reserves) => {
|
|
3379
|
-
const oneEth = BigInt(1e18);
|
|
3380
|
-
return {
|
|
3381
|
-
spotPriceA: oneEth * reserves.ethReserve / reserves.nxmA,
|
|
3382
|
-
spotPriceB: oneEth * reserves.ethReserve / reserves.nxmB
|
|
3383
|
-
};
|
|
3384
|
-
};
|
|
3385
|
-
|
|
3386
|
-
// src/swap/calculatePriceImpactA.ts
|
|
3387
|
-
var calculatePriceImpactA = (ethIn, reserves) => {
|
|
3388
|
-
const { spotPriceA } = calculateSpotPrice(reserves);
|
|
3389
|
-
const nxmOut = calculateExactNxmForEth(ethIn, reserves);
|
|
3390
|
-
const nxmOutAtSpotPrice = BigInt(1e18) * ethIn / spotPriceA;
|
|
3391
|
-
return BigInt(1e6) - BigInt(1e6) * nxmOut / nxmOutAtSpotPrice;
|
|
3392
|
-
};
|
|
3393
|
-
|
|
3394
|
-
// src/swap/calculatePriceImpactB.ts
|
|
3395
|
-
var calculatePriceImpactB = (nxmIn, reserves) => {
|
|
3396
|
-
const { spotPriceB } = calculateSpotPrice(reserves);
|
|
3397
|
-
const ethOut = calculateExactEthForNxm(nxmIn, reserves);
|
|
3398
|
-
const ethOutAtSpotPrice = spotPriceB * nxmIn / BigInt(1e18);
|
|
3399
|
-
return BigInt(1e6) - BigInt(1e6) * ethOut / ethOutAtSpotPrice;
|
|
3400
|
-
};
|
|
3401
|
-
|
|
3402
|
-
// src/buyCover/index.ts
|
|
3403
|
-
var buyCover_exports = {};
|
|
3404
|
-
__export(buyCover_exports, {
|
|
3405
|
-
calculatePremiumWithCommissionAndSlippage: () => calculatePremiumWithCommissionAndSlippage
|
|
3406
|
-
});
|
|
3407
|
-
|
|
3408
|
-
// src/constants/buyCover.ts
|
|
3409
|
-
var CoverAsset = /* @__PURE__ */ ((CoverAsset2) => {
|
|
3410
|
-
CoverAsset2[CoverAsset2["ETH"] = 0] = "ETH";
|
|
3411
|
-
CoverAsset2[CoverAsset2["DAI"] = 1] = "DAI";
|
|
3412
|
-
return CoverAsset2;
|
|
3413
|
-
})(CoverAsset || {});
|
|
3414
|
-
var CoverId = /* @__PURE__ */ ((CoverId2) => {
|
|
3415
|
-
CoverId2[CoverId2["BUY"] = 0] = "BUY";
|
|
3416
|
-
return CoverId2;
|
|
3417
|
-
})(CoverId || {});
|
|
3418
|
-
var COMMISSION_DENOMINATOR = 1e4;
|
|
3419
|
-
var SLIPPAGE_DENOMINATOR = 1e4;
|
|
3420
|
-
var TARGET_PRICE_DENOMINATOR = 1e4;
|
|
3421
|
-
var MINIMUM_COVER_PERIOD = 28;
|
|
3422
|
-
var MAXIMUM_COVER_PERIOD = 365;
|
|
3423
|
-
var DEFAULT_SLIPPAGE = 10;
|
|
3424
|
-
var DEFAULT_COMMISSION_RATIO = 1500;
|
|
3425
|
-
var NEXUS_MUTUAL_DAO_TREASURY_ADDRESS = "0x586b9b2F8010b284A0197f392156f1A7Eb5e86e9";
|
|
3426
|
-
|
|
3427
|
-
// src/buyCover/calculatePremiumWithCommissionAndSlippage.ts
|
|
3428
|
-
var calculatePremiumWithCommissionAndSlippage = (premium, commission = 0, slippage = 0) => {
|
|
3429
|
-
const premiumWithCommission = premium * BigInt(COMMISSION_DENOMINATOR) / BigInt(COMMISSION_DENOMINATOR - commission);
|
|
3430
|
-
const premiumWithCommissionAndSlippage = premiumWithCommission * BigInt(SLIPPAGE_DENOMINATOR + slippage) / BigInt(SLIPPAGE_DENOMINATOR);
|
|
3431
|
-
return premiumWithCommissionAndSlippage;
|
|
3432
|
-
};
|
|
3433
|
-
|
|
3434
|
-
// src/types/index.ts
|
|
3435
|
-
var types_exports2 = {};
|
|
3436
|
-
|
|
3437
|
-
// src/quote/index.ts
|
|
3438
|
-
var quote_exports = {};
|
|
3439
|
-
__export(quote_exports, {
|
|
3440
|
-
getQuoteAndBuyCoverInputs: () => getQuoteAndBuyCoverInputs,
|
|
3441
|
-
sumPoolCapacities: () => sumPoolCapacities
|
|
3442
|
-
});
|
|
3443
|
-
|
|
3444
|
-
// src/quote/getQuoteAndBuyCoverInputs.ts
|
|
3445
|
-
var import_dotenv = __toESM(require_main());
|
|
3446
|
-
import axios from "axios";
|
|
3447
|
-
import_dotenv.default.config();
|
|
3448
|
-
async function getQuoteAndBuyCoverInputs(productId, coverAmount, coverPeriod, coverAsset, coverBuyerAddress, slippage = DEFAULT_SLIPPAGE / SLIPPAGE_DENOMINATOR, ipfsCid = "") {
|
|
3449
|
-
if (!process.env.COVER_ROUTER_URL) {
|
|
3450
|
-
return { result: void 0, error: { message: "Missing COVER_ROUTER_URL env var" } };
|
|
3451
|
-
}
|
|
3452
|
-
if (!Number.isInteger(productId) || productId <= 0) {
|
|
3453
|
-
return { result: void 0, error: { message: "Invalid productId: must be a positive integer" } };
|
|
3454
|
-
}
|
|
3455
|
-
if (typeof coverAmount !== "string" || !/^\d+$/.test(coverAmount) || parseInt(coverAmount, 10) <= 0) {
|
|
3456
|
-
return { result: void 0, error: { message: "Invalid coverAmount: must be a positive integer string" } };
|
|
3457
|
-
}
|
|
3458
|
-
if (!Number.isInteger(coverPeriod) || coverPeriod < MINIMUM_COVER_PERIOD || coverPeriod > MAXIMUM_COVER_PERIOD) {
|
|
3459
|
-
return {
|
|
3460
|
-
result: void 0,
|
|
3461
|
-
error: {
|
|
3462
|
-
message: `Invalid coverPeriod: must be between ${MINIMUM_COVER_PERIOD} and ${MAXIMUM_COVER_PERIOD} days`
|
|
3463
|
-
}
|
|
3464
|
-
};
|
|
3465
|
-
}
|
|
3466
|
-
const coverAssetsString = Object.keys(CoverAsset).filter((k) => isNaN(+k)).map((k) => `CoverAsset.${k}`).join(", ");
|
|
3467
|
-
if (!Object.values(CoverAsset).includes(coverAsset)) {
|
|
3468
|
-
return {
|
|
3469
|
-
result: void 0,
|
|
3470
|
-
error: {
|
|
3471
|
-
message: `Invalid coverAsset: must be one of ${coverAssetsString}`
|
|
3472
|
-
}
|
|
3473
|
-
};
|
|
3474
|
-
}
|
|
3475
|
-
if (!/^0x[a-fA-F0-9]{40}$/.test(coverBuyerAddress)) {
|
|
3476
|
-
return { result: void 0, error: { message: "Invalid coverBuyerAddress: must be a valid Ethereum address" } };
|
|
3477
|
-
}
|
|
3478
|
-
if (typeof slippage !== "number" || slippage < 0 || slippage > 1) {
|
|
3479
|
-
return {
|
|
3480
|
-
result: void 0,
|
|
3481
|
-
error: { message: "Invalid slippage: must be a number between 0 and 1" }
|
|
3482
|
-
};
|
|
3483
|
-
}
|
|
3484
|
-
if (typeof ipfsCid !== "string") {
|
|
3485
|
-
return { result: void 0, error: { message: "Invalid ipfsCid: must be a valid IPFS CID" } };
|
|
3486
|
-
}
|
|
3487
|
-
slippage = slippage * SLIPPAGE_DENOMINATOR;
|
|
3488
|
-
try {
|
|
3489
|
-
const { quote, capacities } = await getQuote(productId, coverAmount, coverPeriod, coverAsset);
|
|
3490
|
-
const maxPremiumInAsset = calculatePremiumWithCommissionAndSlippage(
|
|
3491
|
-
BigInt(quote.premiumInAsset),
|
|
3492
|
-
DEFAULT_COMMISSION_RATIO,
|
|
3493
|
-
slippage
|
|
3494
|
-
);
|
|
3495
|
-
const yearlyCostPerc = calculatePremiumWithCommissionAndSlippage(
|
|
3496
|
-
BigInt(quote.annualPrice),
|
|
3497
|
-
DEFAULT_COMMISSION_RATIO,
|
|
3498
|
-
slippage
|
|
3499
|
-
);
|
|
3500
|
-
const result = {
|
|
3501
|
-
displayInfo: {
|
|
3502
|
-
premiumInAsset: maxPremiumInAsset.toString(),
|
|
3503
|
-
coverAmount,
|
|
3504
|
-
yearlyCostPerc: Number(yearlyCostPerc) / TARGET_PRICE_DENOMINATOR,
|
|
3505
|
-
maxCapacity: sumPoolCapacities(capacities)
|
|
3506
|
-
},
|
|
3507
|
-
buyCoverInput: {
|
|
3508
|
-
buyCoverParams: {
|
|
3509
|
-
coverId: 0 /* BUY */,
|
|
3510
|
-
owner: coverBuyerAddress,
|
|
3511
|
-
productId,
|
|
3512
|
-
coverAsset,
|
|
3513
|
-
amount: coverAmount,
|
|
3514
|
-
period: coverPeriod * 60 * 60 * 24,
|
|
3515
|
-
// seconds
|
|
3516
|
-
maxPremiumInAsset: maxPremiumInAsset.toString(),
|
|
3517
|
-
paymentAsset: coverAsset,
|
|
3518
|
-
commissionRatio: DEFAULT_COMMISSION_RATIO,
|
|
3519
|
-
commissionDestination: NEXUS_MUTUAL_DAO_TREASURY_ADDRESS,
|
|
3520
|
-
ipfsData: ipfsCid
|
|
3521
|
-
},
|
|
3522
|
-
poolAllocationRequests: quote.poolAllocationRequests
|
|
3523
|
-
}
|
|
3524
|
-
};
|
|
3525
|
-
return { result, error: void 0 };
|
|
3526
|
-
} catch (error) {
|
|
3527
|
-
const errorResponse = await handleError(error, productId, coverPeriod, coverAsset);
|
|
3528
|
-
return errorResponse;
|
|
3529
|
-
}
|
|
3530
|
-
}
|
|
3531
|
-
async function getQuote(productId, coverAmount, coverPeriod, coverAsset) {
|
|
3532
|
-
const params = { productId, amount: coverAmount, period: coverPeriod, coverAsset };
|
|
3533
|
-
const response = await axios.get(process.env.COVER_ROUTER_URL + "/quote", { params });
|
|
3534
|
-
if (!response.data) {
|
|
3535
|
-
throw new Error("Failed to fetch cover quote");
|
|
3536
|
-
}
|
|
3537
|
-
return response.data;
|
|
3538
|
-
}
|
|
3539
|
-
async function getProductCapacity(productId, coverPeriod, coverAsset) {
|
|
3540
|
-
const params = { period: coverPeriod };
|
|
3541
|
-
const capacityUrl = process.env.COVER_ROUTER_URL + `/capacity/${productId}`;
|
|
3542
|
-
const response = await axios.get(capacityUrl, { params });
|
|
3543
|
-
if (!response.data) {
|
|
3544
|
-
throw new Error("Failed to fetch cover capacities");
|
|
3545
|
-
}
|
|
3546
|
-
return response.data.availableCapacity.find((av) => av.assetId === coverAsset)?.amount;
|
|
3547
|
-
}
|
|
3548
|
-
function sumPoolCapacities(capacities) {
|
|
3549
|
-
let totalAmount = BigInt(0);
|
|
3550
|
-
capacities.forEach((poolCapacity) => {
|
|
3551
|
-
poolCapacity.capacity.forEach((capacity) => totalAmount += BigInt(capacity.amount));
|
|
3552
|
-
});
|
|
3553
|
-
return totalAmount.toString();
|
|
3554
|
-
}
|
|
3555
|
-
async function handleError(error, productId, coverPeriod, coverAsset) {
|
|
3556
|
-
const axiosError = error;
|
|
3557
|
-
if (axiosError.isAxiosError) {
|
|
3558
|
-
if (axiosError.response?.data?.error?.includes("Not enough capacity")) {
|
|
3559
|
-
const maxCapacity = await getProductCapacity(productId, coverPeriod, coverAsset);
|
|
3560
|
-
return {
|
|
3561
|
-
result: void 0,
|
|
3562
|
-
error: {
|
|
3563
|
-
message: axiosError.response?.data.error,
|
|
3564
|
-
data: maxCapacity ? { maxCapacity } : void 0
|
|
3565
|
-
}
|
|
3566
|
-
};
|
|
3567
|
-
}
|
|
3568
|
-
}
|
|
3569
|
-
return {
|
|
3570
|
-
result: void 0,
|
|
3571
|
-
error: { message: error.message || "Something went wrong" }
|
|
3572
|
-
};
|
|
3573
|
-
}
|
|
3574
|
-
|
|
3575
|
-
// src/constants/index.ts
|
|
3576
|
-
var constants_exports = {};
|
|
3577
|
-
__export(constants_exports, {
|
|
3578
|
-
COMMISSION_DENOMINATOR: () => COMMISSION_DENOMINATOR,
|
|
3579
|
-
CoverAsset: () => CoverAsset,
|
|
3580
|
-
CoverId: () => CoverId,
|
|
3581
|
-
DEFAULT_COMMISSION_RATIO: () => DEFAULT_COMMISSION_RATIO,
|
|
3582
|
-
DEFAULT_SLIPPAGE: () => DEFAULT_SLIPPAGE,
|
|
3583
|
-
MAXIMUM_COVER_PERIOD: () => MAXIMUM_COVER_PERIOD,
|
|
3584
|
-
MINIMUM_COVER_PERIOD: () => MINIMUM_COVER_PERIOD,
|
|
3585
|
-
NEXUS_MUTUAL_DAO_TREASURY_ADDRESS: () => NEXUS_MUTUAL_DAO_TREASURY_ADDRESS,
|
|
3586
|
-
SLIPPAGE_DENOMINATOR: () => SLIPPAGE_DENOMINATOR,
|
|
3587
|
-
TARGET_PRICE_DENOMINATOR: () => TARGET_PRICE_DENOMINATOR
|
|
3588
|
-
});
|
|
3589
|
-
|
|
3590
3402
|
// src/index.ts
|
|
3591
3403
|
export * from "@nexusmutual/deployments";
|
|
3592
3404
|
var nexusSdk = {
|
|
3593
3405
|
...deployments,
|
|
3594
3406
|
products: products_default,
|
|
3595
3407
|
productTypes: product_types_default,
|
|
3596
|
-
...
|
|
3408
|
+
...types_exports2,
|
|
3597
3409
|
...swap_exports,
|
|
3598
3410
|
...buyCover_exports,
|
|
3599
|
-
...
|
|
3411
|
+
...types_exports,
|
|
3600
3412
|
...quote_exports,
|
|
3601
3413
|
...constants_exports
|
|
3602
3414
|
};
|
|
@@ -3625,7 +3437,6 @@ export {
|
|
|
3625
3437
|
src_default as default,
|
|
3626
3438
|
getQuoteAndBuyCoverInputs,
|
|
3627
3439
|
product_types_default as productTypes,
|
|
3628
|
-
products_default as products
|
|
3629
|
-
sumPoolCapacities
|
|
3440
|
+
products_default as products
|
|
3630
3441
|
};
|
|
3631
3442
|
//# sourceMappingURL=index.mjs.map
|