@nexusmutual/sdk 0.3.2 → 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 +51 -3
- package/dist/index.d.mts +93 -49
- package/dist/index.d.ts +93 -49
- package/dist/index.js +417 -525
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +408 -543
- package/dist/index.mjs.map +1 -1
- package/dist/logos/etherfi-zircuit-pendle.svg +1 -0
- package/dist/logos/kelpdao-zircuit-pendle.svg +1 -0
- package/dist/logos/renzo-zircuit-pendle.svg +1 -0
- 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 = [
|
|
@@ -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,
|
|
@@ -1707,7 +1887,7 @@ var products_default = [
|
|
|
1707
1887
|
"DAI"
|
|
1708
1888
|
],
|
|
1709
1889
|
isPrivate: true,
|
|
1710
|
-
timestamp:
|
|
1890
|
+
timestamp: 1684312727
|
|
1711
1891
|
},
|
|
1712
1892
|
{
|
|
1713
1893
|
id: 94,
|
|
@@ -2356,7 +2536,7 @@ var products_default = [
|
|
|
2356
2536
|
"ETH"
|
|
2357
2537
|
],
|
|
2358
2538
|
isPrivate: false,
|
|
2359
|
-
timestamp:
|
|
2539
|
+
timestamp: 1709311739
|
|
2360
2540
|
},
|
|
2361
2541
|
{
|
|
2362
2542
|
id: 137,
|
|
@@ -2725,107 +2905,60 @@ var products_default = [
|
|
|
2725
2905
|
],
|
|
2726
2906
|
isPrivate: true,
|
|
2727
2907
|
timestamp: 1712739011
|
|
2728
|
-
}
|
|
2729
|
-
];
|
|
2730
|
-
|
|
2731
|
-
// generated/product-types.json
|
|
2732
|
-
var product_types_default = [
|
|
2733
|
-
{
|
|
2734
|
-
id: 0,
|
|
2735
|
-
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmdunFJm4A5CUW1ynM7bevsGt6UzQfw6K4ysKqvsqpjWCQ",
|
|
2736
|
-
name: "Protocol",
|
|
2737
|
-
gracePeriod: 3024e3,
|
|
2738
|
-
claimMethod: 0
|
|
2739
|
-
},
|
|
2740
|
-
{
|
|
2741
|
-
id: 1,
|
|
2742
|
-
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmYhCNjfrNTMq8eyg8i7LbBpTkMCHfix9Sv1jrPb7dYZKd",
|
|
2743
|
-
name: "Custody",
|
|
2744
|
-
gracePeriod: 10368e3,
|
|
2745
|
-
claimMethod: 0
|
|
2746
|
-
},
|
|
2747
|
-
{
|
|
2748
|
-
id: 2,
|
|
2749
|
-
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmcPdiLNZmBM8pjQcCzLhH8tjPuhphCVKZeP5P4SBiLx3h",
|
|
2750
|
-
name: "Yield Token",
|
|
2751
|
-
gracePeriod: 1209600,
|
|
2752
|
-
claimMethod: 1
|
|
2753
|
-
},
|
|
2754
|
-
{
|
|
2755
|
-
id: 3,
|
|
2756
|
-
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmUTUfdfuZUjtPAiMZ4YRu77SaiyCov7jrSXTgeGeK8qt3",
|
|
2757
|
-
name: "Sherlock Excess",
|
|
2758
|
-
gracePeriod: 3024e3,
|
|
2759
|
-
claimMethod: 0
|
|
2760
|
-
},
|
|
2761
|
-
{
|
|
2762
|
-
id: 4,
|
|
2763
|
-
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmPmwtwbyKnXBae1dmYD6jmgnewCeZGPMFGepkWMLWaiwC",
|
|
2764
|
-
name: "Stakewise ETH Staking",
|
|
2765
|
-
gracePeriod: 3024e3,
|
|
2766
|
-
claimMethod: 0
|
|
2767
|
-
},
|
|
2768
|
-
{
|
|
2769
|
-
id: 5,
|
|
2770
|
-
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmUKhLi5ZahnzSxsMC9YQZbwwAKGhkHcoYqHUVgE31cXLe",
|
|
2771
|
-
name: "Liquid Collective ETH Staking",
|
|
2772
|
-
gracePeriod: 3024e3,
|
|
2773
|
-
claimMethod: 0
|
|
2774
|
-
},
|
|
2775
|
-
{
|
|
2776
|
-
id: 6,
|
|
2777
|
-
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmWepFbtMYSzJt22ddF1CK9PwbrYgiLk9qJjryDrgpGuus",
|
|
2778
|
-
name: "ETH Slashing",
|
|
2779
|
-
gracePeriod: 3024e3,
|
|
2780
|
-
claimMethod: 0
|
|
2781
2908
|
},
|
|
2782
2909
|
{
|
|
2783
|
-
id:
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
id: 9,
|
|
2798
|
-
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmQG8ooLgoQx2YdykwZEUYruoMZ7YP23LK9yiQbw9AGTZi",
|
|
2799
|
-
name: "The Retail Mutual",
|
|
2800
|
-
gracePeriod: 3672e4,
|
|
2801
|
-
claimMethod: 0
|
|
2802
|
-
},
|
|
2803
|
-
{
|
|
2804
|
-
id: 10,
|
|
2805
|
-
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmWXYjBYjdKoRw6kyUvp5gYKjj2ojPPVxNYKr1gDjMLssY",
|
|
2806
|
-
name: "UnoRe Quota Share",
|
|
2807
|
-
gracePeriod: 3024e3,
|
|
2808
|
-
claimMethod: 0
|
|
2910
|
+
id: 160,
|
|
2911
|
+
name: "Etherfi (Zircuit) Pendle",
|
|
2912
|
+
productType: 11,
|
|
2913
|
+
isDeprecated: false,
|
|
2914
|
+
useFixedPrice: false,
|
|
2915
|
+
logo: "etherfi-zircuit-pendle.svg",
|
|
2916
|
+
metadata: {
|
|
2917
|
+
annex: "QmarQuziSJBVQoayRgPNuEiJdZHgf6wxDyKiGQVpsCNRnJ"
|
|
2918
|
+
},
|
|
2919
|
+
coverAssets: [
|
|
2920
|
+
"ETH"
|
|
2921
|
+
],
|
|
2922
|
+
isPrivate: false,
|
|
2923
|
+
timestamp: 1713185771
|
|
2809
2924
|
},
|
|
2810
2925
|
{
|
|
2811
|
-
id:
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2926
|
+
id: 161,
|
|
2927
|
+
name: "KelpDAO (Zircuit) Pendle",
|
|
2928
|
+
productType: 11,
|
|
2929
|
+
isDeprecated: false,
|
|
2930
|
+
useFixedPrice: false,
|
|
2931
|
+
logo: "kelpdao-zircuit-pendle.svg",
|
|
2932
|
+
metadata: {
|
|
2933
|
+
annex: "QmdseksWrvXoMjF58NGnSS6WC7dXDVk2oeZz93Bt4oMzT2"
|
|
2934
|
+
},
|
|
2935
|
+
coverAssets: [
|
|
2936
|
+
"ETH"
|
|
2937
|
+
],
|
|
2938
|
+
isPrivate: false,
|
|
2939
|
+
timestamp: 1713185771
|
|
2816
2940
|
},
|
|
2817
2941
|
{
|
|
2818
|
-
id:
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2942
|
+
id: 162,
|
|
2943
|
+
name: "Renzo (Zircuit) Pendle",
|
|
2944
|
+
productType: 11,
|
|
2945
|
+
isDeprecated: false,
|
|
2946
|
+
useFixedPrice: false,
|
|
2947
|
+
logo: "renzo-zircuit-pendle.svg",
|
|
2948
|
+
metadata: {
|
|
2949
|
+
annex: "QmeAB5RzQgQbC2DFa9W49taFEoxhZEUDgnXqvfceFUL4Xm"
|
|
2950
|
+
},
|
|
2951
|
+
coverAssets: [
|
|
2952
|
+
"ETH"
|
|
2953
|
+
],
|
|
2954
|
+
isPrivate: false,
|
|
2955
|
+
timestamp: 1713185771
|
|
2823
2956
|
}
|
|
2824
2957
|
];
|
|
2825
2958
|
|
|
2826
2959
|
// generated/types.ts
|
|
2827
|
-
var
|
|
2828
|
-
__export(
|
|
2960
|
+
var types_exports2 = {};
|
|
2961
|
+
__export(types_exports2, {
|
|
2829
2962
|
allLogoFileNames: () => allLogoFileNames,
|
|
2830
2963
|
allLogoNames: () => allLogoNames
|
|
2831
2964
|
});
|
|
@@ -2990,6 +3123,9 @@ var allLogoFileNames = [
|
|
|
2990
3123
|
"lyra-synthetix.svg",
|
|
2991
3124
|
"eigenlayer-renzo.svg",
|
|
2992
3125
|
"liquidcollective.svg",
|
|
3126
|
+
"etherfi-zircuit-pendle.svg",
|
|
3127
|
+
"kelpdao-zircuit-pendle.svg",
|
|
3128
|
+
"renzo-zircuit-pendle.svg",
|
|
2993
3129
|
"aave-v1.svg",
|
|
2994
3130
|
"akropolis.svg",
|
|
2995
3131
|
"alpha-homora.svg",
|
|
@@ -3205,6 +3341,9 @@ var allLogoNames = [
|
|
|
3205
3341
|
"lyra-synthetix",
|
|
3206
3342
|
"eigenlayer-renzo",
|
|
3207
3343
|
"liquidcollective",
|
|
3344
|
+
"etherfi-zircuit-pendle",
|
|
3345
|
+
"kelpdao-zircuit-pendle",
|
|
3346
|
+
"renzo-zircuit-pendle",
|
|
3208
3347
|
"aave-v1",
|
|
3209
3348
|
"akropolis",
|
|
3210
3349
|
"alpha-homora",
|
|
@@ -3260,289 +3399,16 @@ var allLogoNames = [
|
|
|
3260
3399
|
"zksync"
|
|
3261
3400
|
];
|
|
3262
3401
|
|
|
3263
|
-
// src/swap/index.ts
|
|
3264
|
-
var swap_exports = {};
|
|
3265
|
-
__export(swap_exports, {
|
|
3266
|
-
calculateEthForExactNxm: () => calculateEthForExactNxm,
|
|
3267
|
-
calculateExactEthForNxm: () => calculateExactEthForNxm,
|
|
3268
|
-
calculateExactNxmForEth: () => calculateExactNxmForEth,
|
|
3269
|
-
calculateNxmForExactEth: () => calculateNxmForExactEth,
|
|
3270
|
-
calculatePriceImpactA: () => calculatePriceImpactA,
|
|
3271
|
-
calculatePriceImpactB: () => calculatePriceImpactB,
|
|
3272
|
-
calculateSpotPrice: () => calculateSpotPrice
|
|
3273
|
-
});
|
|
3274
|
-
|
|
3275
|
-
// src/swap/calculateExactNxmForEth.ts
|
|
3276
|
-
var calculateExactNxmForEth = (ethIn, reserves) => {
|
|
3277
|
-
if (ethIn <= 0n)
|
|
3278
|
-
throw new Error("ETH in value must be greater than 0");
|
|
3279
|
-
const k = reserves.nxmA * reserves.ethReserve;
|
|
3280
|
-
const ethReservesAfter = reserves.ethReserve + ethIn;
|
|
3281
|
-
const nxmReservesAfter = k / ethReservesAfter;
|
|
3282
|
-
const nxmOut = reserves.nxmA - nxmReservesAfter;
|
|
3283
|
-
if (nxmOut < 0n)
|
|
3284
|
-
throw new Error("Cannot swap this amount");
|
|
3285
|
-
return nxmOut;
|
|
3286
|
-
};
|
|
3287
|
-
|
|
3288
|
-
// src/swap/calculateExactEthForNxm.ts
|
|
3289
|
-
var calculateExactEthForNxm = (nxmIn, reserves) => {
|
|
3290
|
-
if (nxmIn <= 0n)
|
|
3291
|
-
throw new Error("NXM in value must be greater than 0");
|
|
3292
|
-
const k = reserves.nxmB * reserves.ethReserve;
|
|
3293
|
-
const nxmReservesAfter = reserves.nxmB + nxmIn;
|
|
3294
|
-
const ethReservesAfter = k / nxmReservesAfter;
|
|
3295
|
-
const ethOut = reserves.ethReserve - ethReservesAfter;
|
|
3296
|
-
if (ethOut < 0n)
|
|
3297
|
-
throw new Error("Cannot swap this amount");
|
|
3298
|
-
return ethOut;
|
|
3299
|
-
};
|
|
3300
|
-
|
|
3301
|
-
// src/swap/calculateNxmForExactEth.ts
|
|
3302
|
-
var calculateNxmForExactEth = (ethOut, reserves) => {
|
|
3303
|
-
if (ethOut <= 0n || ethOut >= reserves.ethReserve)
|
|
3304
|
-
throw new Error("ETH out value must be greater than 0 and less than the reserves");
|
|
3305
|
-
const k = reserves.nxmB * reserves.ethReserve;
|
|
3306
|
-
const ethReservesAfter = reserves.ethReserve - ethOut;
|
|
3307
|
-
const nxmReservesAfter = k / ethReservesAfter;
|
|
3308
|
-
const nxmIn = nxmReservesAfter - reserves.nxmB;
|
|
3309
|
-
return nxmIn;
|
|
3310
|
-
};
|
|
3311
|
-
|
|
3312
|
-
// src/swap/calculateEthForExactNxm.ts
|
|
3313
|
-
var calculateEthForExactNxm = (nxmOut, reserves) => {
|
|
3314
|
-
if (nxmOut <= 0n || nxmOut >= reserves.nxmA)
|
|
3315
|
-
throw new Error("NXM out value must be greater than 0 and less than the reserves");
|
|
3316
|
-
const k = reserves.nxmA * reserves.ethReserve;
|
|
3317
|
-
const nxmReservesAfter = reserves.nxmA - nxmOut;
|
|
3318
|
-
const ethReservesAfter = k / nxmReservesAfter;
|
|
3319
|
-
const ethIn = ethReservesAfter - reserves.ethReserve;
|
|
3320
|
-
return ethIn;
|
|
3321
|
-
};
|
|
3322
|
-
|
|
3323
|
-
// src/swap/calculateSpotPrice.ts
|
|
3324
|
-
var calculateSpotPrice = (reserves) => {
|
|
3325
|
-
const oneEth = BigInt(1e18);
|
|
3326
|
-
return {
|
|
3327
|
-
spotPriceA: oneEth * reserves.ethReserve / reserves.nxmA,
|
|
3328
|
-
spotPriceB: oneEth * reserves.ethReserve / reserves.nxmB
|
|
3329
|
-
};
|
|
3330
|
-
};
|
|
3331
|
-
|
|
3332
|
-
// src/swap/calculatePriceImpactA.ts
|
|
3333
|
-
var calculatePriceImpactA = (ethIn, reserves) => {
|
|
3334
|
-
const { spotPriceA } = calculateSpotPrice(reserves);
|
|
3335
|
-
const nxmOut = calculateExactNxmForEth(ethIn, reserves);
|
|
3336
|
-
const nxmOutAtSpotPrice = BigInt(1e18) * ethIn / spotPriceA;
|
|
3337
|
-
return BigInt(1e6) - BigInt(1e6) * nxmOut / nxmOutAtSpotPrice;
|
|
3338
|
-
};
|
|
3339
|
-
|
|
3340
|
-
// src/swap/calculatePriceImpactB.ts
|
|
3341
|
-
var calculatePriceImpactB = (nxmIn, reserves) => {
|
|
3342
|
-
const { spotPriceB } = calculateSpotPrice(reserves);
|
|
3343
|
-
const ethOut = calculateExactEthForNxm(nxmIn, reserves);
|
|
3344
|
-
const ethOutAtSpotPrice = spotPriceB * nxmIn / BigInt(1e18);
|
|
3345
|
-
return BigInt(1e6) - BigInt(1e6) * ethOut / ethOutAtSpotPrice;
|
|
3346
|
-
};
|
|
3347
|
-
|
|
3348
|
-
// src/buyCover/index.ts
|
|
3349
|
-
var buyCover_exports = {};
|
|
3350
|
-
__export(buyCover_exports, {
|
|
3351
|
-
calculatePremiumWithCommissionAndSlippage: () => calculatePremiumWithCommissionAndSlippage
|
|
3352
|
-
});
|
|
3353
|
-
|
|
3354
|
-
// src/constants/buyCover.ts
|
|
3355
|
-
var CoverAsset = /* @__PURE__ */ ((CoverAsset2) => {
|
|
3356
|
-
CoverAsset2[CoverAsset2["ETH"] = 0] = "ETH";
|
|
3357
|
-
CoverAsset2[CoverAsset2["DAI"] = 1] = "DAI";
|
|
3358
|
-
return CoverAsset2;
|
|
3359
|
-
})(CoverAsset || {});
|
|
3360
|
-
var CoverId = /* @__PURE__ */ ((CoverId2) => {
|
|
3361
|
-
CoverId2[CoverId2["BUY"] = 0] = "BUY";
|
|
3362
|
-
return CoverId2;
|
|
3363
|
-
})(CoverId || {});
|
|
3364
|
-
var COMMISSION_DENOMINATOR = 1e4;
|
|
3365
|
-
var SLIPPAGE_DENOMINATOR = 1e4;
|
|
3366
|
-
var TARGET_PRICE_DENOMINATOR = 1e4;
|
|
3367
|
-
var MINIMUM_COVER_PERIOD = 28;
|
|
3368
|
-
var MAXIMUM_COVER_PERIOD = 365;
|
|
3369
|
-
var DEFAULT_SLIPPAGE = 10;
|
|
3370
|
-
var DEFAULT_COMMISSION_RATIO = 1500;
|
|
3371
|
-
var NEXUS_MUTUAL_DAO_TREASURY_ADDRESS = "0x586b9b2F8010b284A0197f392156f1A7Eb5e86e9";
|
|
3372
|
-
|
|
3373
|
-
// src/buyCover/calculatePremiumWithCommissionAndSlippage.ts
|
|
3374
|
-
var calculatePremiumWithCommissionAndSlippage = (premium, commission = 0, slippage = 0) => {
|
|
3375
|
-
const premiumWithCommission = premium * BigInt(COMMISSION_DENOMINATOR) / BigInt(COMMISSION_DENOMINATOR - commission);
|
|
3376
|
-
const premiumWithCommissionAndSlippage = premiumWithCommission * BigInt(SLIPPAGE_DENOMINATOR + slippage) / BigInt(SLIPPAGE_DENOMINATOR);
|
|
3377
|
-
return premiumWithCommissionAndSlippage;
|
|
3378
|
-
};
|
|
3379
|
-
|
|
3380
|
-
// src/types/index.ts
|
|
3381
|
-
var types_exports2 = {};
|
|
3382
|
-
|
|
3383
|
-
// src/quote/index.ts
|
|
3384
|
-
var quote_exports = {};
|
|
3385
|
-
__export(quote_exports, {
|
|
3386
|
-
getQuoteAndBuyCoverInputs: () => getQuoteAndBuyCoverInputs,
|
|
3387
|
-
sumPoolCapacities: () => sumPoolCapacities
|
|
3388
|
-
});
|
|
3389
|
-
|
|
3390
|
-
// src/quote/getQuoteAndBuyCoverInputs.ts
|
|
3391
|
-
var import_dotenv = __toESM(require_main());
|
|
3392
|
-
import axios from "axios";
|
|
3393
|
-
import_dotenv.default.config();
|
|
3394
|
-
async function getQuoteAndBuyCoverInputs(productId, coverAmount, coverPeriod, coverAsset, coverBuyerAddress, slippage = DEFAULT_SLIPPAGE / SLIPPAGE_DENOMINATOR, ipfsCid = "") {
|
|
3395
|
-
if (!process.env.COVER_ROUTER_URL) {
|
|
3396
|
-
return { result: void 0, error: { message: "Missing COVER_ROUTER_URL env var" } };
|
|
3397
|
-
}
|
|
3398
|
-
if (!Number.isInteger(productId) || productId <= 0) {
|
|
3399
|
-
return { result: void 0, error: { message: "Invalid productId: must be a positive integer" } };
|
|
3400
|
-
}
|
|
3401
|
-
if (typeof coverAmount !== "string" || !/^\d+$/.test(coverAmount) || parseInt(coverAmount, 10) <= 0) {
|
|
3402
|
-
return { result: void 0, error: { message: "Invalid coverAmount: must be a positive integer string" } };
|
|
3403
|
-
}
|
|
3404
|
-
if (!Number.isInteger(coverPeriod) || coverPeriod < MINIMUM_COVER_PERIOD || coverPeriod > MAXIMUM_COVER_PERIOD) {
|
|
3405
|
-
return {
|
|
3406
|
-
result: void 0,
|
|
3407
|
-
error: {
|
|
3408
|
-
message: `Invalid coverPeriod: must be between ${MINIMUM_COVER_PERIOD} and ${MAXIMUM_COVER_PERIOD} days`
|
|
3409
|
-
}
|
|
3410
|
-
};
|
|
3411
|
-
}
|
|
3412
|
-
const coverAssetsString = Object.keys(CoverAsset).filter((k) => isNaN(+k)).map((k) => `CoverAsset.${k}`).join(", ");
|
|
3413
|
-
if (!Object.values(CoverAsset).includes(coverAsset)) {
|
|
3414
|
-
return {
|
|
3415
|
-
result: void 0,
|
|
3416
|
-
error: {
|
|
3417
|
-
message: `Invalid coverAsset: must be one of ${coverAssetsString}`
|
|
3418
|
-
}
|
|
3419
|
-
};
|
|
3420
|
-
}
|
|
3421
|
-
if (!/^0x[a-fA-F0-9]{40}$/.test(coverBuyerAddress)) {
|
|
3422
|
-
return { result: void 0, error: { message: "Invalid coverBuyerAddress: must be a valid Ethereum address" } };
|
|
3423
|
-
}
|
|
3424
|
-
if (typeof slippage !== "number" || slippage < 0 || slippage > 1) {
|
|
3425
|
-
return {
|
|
3426
|
-
result: void 0,
|
|
3427
|
-
error: { message: "Invalid slippage: must be a number between 0 and 1" }
|
|
3428
|
-
};
|
|
3429
|
-
}
|
|
3430
|
-
if (typeof ipfsCid !== "string") {
|
|
3431
|
-
return { result: void 0, error: { message: "Invalid ipfsCid: must be a valid IPFS CID" } };
|
|
3432
|
-
}
|
|
3433
|
-
slippage = slippage * SLIPPAGE_DENOMINATOR;
|
|
3434
|
-
try {
|
|
3435
|
-
const { quote, capacities } = await getQuote(productId, coverAmount, coverPeriod, coverAsset);
|
|
3436
|
-
const maxPremiumInAsset = calculatePremiumWithCommissionAndSlippage(
|
|
3437
|
-
BigInt(quote.premiumInAsset),
|
|
3438
|
-
DEFAULT_COMMISSION_RATIO,
|
|
3439
|
-
slippage
|
|
3440
|
-
);
|
|
3441
|
-
const yearlyCostPerc = calculatePremiumWithCommissionAndSlippage(
|
|
3442
|
-
BigInt(quote.annualPrice),
|
|
3443
|
-
DEFAULT_COMMISSION_RATIO,
|
|
3444
|
-
slippage
|
|
3445
|
-
);
|
|
3446
|
-
const result = {
|
|
3447
|
-
displayInfo: {
|
|
3448
|
-
premiumInAsset: maxPremiumInAsset.toString(),
|
|
3449
|
-
coverAmount,
|
|
3450
|
-
yearlyCostPerc: Number(yearlyCostPerc) / TARGET_PRICE_DENOMINATOR,
|
|
3451
|
-
maxCapacity: sumPoolCapacities(capacities)
|
|
3452
|
-
},
|
|
3453
|
-
buyCoverInput: {
|
|
3454
|
-
buyCoverParams: {
|
|
3455
|
-
coverId: 0 /* BUY */,
|
|
3456
|
-
owner: coverBuyerAddress,
|
|
3457
|
-
productId,
|
|
3458
|
-
coverAsset,
|
|
3459
|
-
amount: coverAmount,
|
|
3460
|
-
period: coverPeriod * 60 * 60 * 24,
|
|
3461
|
-
// seconds
|
|
3462
|
-
maxPremiumInAsset: maxPremiumInAsset.toString(),
|
|
3463
|
-
paymentAsset: coverAsset,
|
|
3464
|
-
commissionRatio: DEFAULT_COMMISSION_RATIO,
|
|
3465
|
-
commissionDestination: NEXUS_MUTUAL_DAO_TREASURY_ADDRESS,
|
|
3466
|
-
ipfsData: ipfsCid
|
|
3467
|
-
},
|
|
3468
|
-
poolAllocationRequests: quote.poolAllocationRequests
|
|
3469
|
-
}
|
|
3470
|
-
};
|
|
3471
|
-
return { result, error: void 0 };
|
|
3472
|
-
} catch (error) {
|
|
3473
|
-
const errorResponse = await handleError(error, productId, coverPeriod, coverAsset);
|
|
3474
|
-
return errorResponse;
|
|
3475
|
-
}
|
|
3476
|
-
}
|
|
3477
|
-
async function getQuote(productId, coverAmount, coverPeriod, coverAsset) {
|
|
3478
|
-
const params = { productId, amount: coverAmount, period: coverPeriod, coverAsset };
|
|
3479
|
-
const response = await axios.get(process.env.COVER_ROUTER_URL + "/quote", { params });
|
|
3480
|
-
if (!response.data) {
|
|
3481
|
-
throw new Error("Failed to fetch cover quote");
|
|
3482
|
-
}
|
|
3483
|
-
return response.data;
|
|
3484
|
-
}
|
|
3485
|
-
async function getProductCapacity(productId, coverPeriod, coverAsset) {
|
|
3486
|
-
const params = { period: coverPeriod };
|
|
3487
|
-
const capacityUrl = process.env.COVER_ROUTER_URL + `/capacity/${productId}`;
|
|
3488
|
-
const response = await axios.get(capacityUrl, { params });
|
|
3489
|
-
if (!response.data) {
|
|
3490
|
-
throw new Error("Failed to fetch cover capacities");
|
|
3491
|
-
}
|
|
3492
|
-
return response.data.availableCapacity.find((av) => av.assetId === coverAsset)?.amount;
|
|
3493
|
-
}
|
|
3494
|
-
function sumPoolCapacities(capacities) {
|
|
3495
|
-
let totalAmount = BigInt(0);
|
|
3496
|
-
capacities.forEach((poolCapacity) => {
|
|
3497
|
-
poolCapacity.capacity.forEach((capacity) => totalAmount += BigInt(capacity.amount));
|
|
3498
|
-
});
|
|
3499
|
-
return totalAmount.toString();
|
|
3500
|
-
}
|
|
3501
|
-
async function handleError(error, productId, coverPeriod, coverAsset) {
|
|
3502
|
-
const axiosError = error;
|
|
3503
|
-
if (axiosError.isAxiosError) {
|
|
3504
|
-
if (axiosError.response?.data?.error?.includes("Not enough capacity")) {
|
|
3505
|
-
const maxCapacity = await getProductCapacity(productId, coverPeriod, coverAsset);
|
|
3506
|
-
return {
|
|
3507
|
-
result: void 0,
|
|
3508
|
-
error: {
|
|
3509
|
-
message: axiosError.response?.data.error,
|
|
3510
|
-
data: maxCapacity ? { maxCapacity } : void 0
|
|
3511
|
-
}
|
|
3512
|
-
};
|
|
3513
|
-
}
|
|
3514
|
-
}
|
|
3515
|
-
return {
|
|
3516
|
-
result: void 0,
|
|
3517
|
-
error: { message: error.message || "Something went wrong" }
|
|
3518
|
-
};
|
|
3519
|
-
}
|
|
3520
|
-
|
|
3521
|
-
// src/constants/index.ts
|
|
3522
|
-
var constants_exports = {};
|
|
3523
|
-
__export(constants_exports, {
|
|
3524
|
-
COMMISSION_DENOMINATOR: () => COMMISSION_DENOMINATOR,
|
|
3525
|
-
CoverAsset: () => CoverAsset,
|
|
3526
|
-
CoverId: () => CoverId,
|
|
3527
|
-
DEFAULT_COMMISSION_RATIO: () => DEFAULT_COMMISSION_RATIO,
|
|
3528
|
-
DEFAULT_SLIPPAGE: () => DEFAULT_SLIPPAGE,
|
|
3529
|
-
MAXIMUM_COVER_PERIOD: () => MAXIMUM_COVER_PERIOD,
|
|
3530
|
-
MINIMUM_COVER_PERIOD: () => MINIMUM_COVER_PERIOD,
|
|
3531
|
-
NEXUS_MUTUAL_DAO_TREASURY_ADDRESS: () => NEXUS_MUTUAL_DAO_TREASURY_ADDRESS,
|
|
3532
|
-
SLIPPAGE_DENOMINATOR: () => SLIPPAGE_DENOMINATOR,
|
|
3533
|
-
TARGET_PRICE_DENOMINATOR: () => TARGET_PRICE_DENOMINATOR
|
|
3534
|
-
});
|
|
3535
|
-
|
|
3536
3402
|
// src/index.ts
|
|
3537
3403
|
export * from "@nexusmutual/deployments";
|
|
3538
3404
|
var nexusSdk = {
|
|
3539
3405
|
...deployments,
|
|
3540
3406
|
products: products_default,
|
|
3541
3407
|
productTypes: product_types_default,
|
|
3542
|
-
...
|
|
3408
|
+
...types_exports2,
|
|
3543
3409
|
...swap_exports,
|
|
3544
3410
|
...buyCover_exports,
|
|
3545
|
-
...
|
|
3411
|
+
...types_exports,
|
|
3546
3412
|
...quote_exports,
|
|
3547
3413
|
...constants_exports
|
|
3548
3414
|
};
|
|
@@ -3571,7 +3437,6 @@ export {
|
|
|
3571
3437
|
src_default as default,
|
|
3572
3438
|
getQuoteAndBuyCoverInputs,
|
|
3573
3439
|
product_types_default as productTypes,
|
|
3574
|
-
products_default as products
|
|
3575
|
-
sumPoolCapacities
|
|
3440
|
+
products_default as products
|
|
3576
3441
|
};
|
|
3577
3442
|
//# sourceMappingURL=index.mjs.map
|