@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.js
CHANGED
|
@@ -5,9 +5,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
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
|
-
};
|
|
11
8
|
var __export = (target, all) => {
|
|
12
9
|
for (var name in all)
|
|
13
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -31,156 +28,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
31
28
|
));
|
|
32
29
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
33
30
|
|
|
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
|
-
|
|
184
31
|
// src/index.ts
|
|
185
32
|
var src_exports = {};
|
|
186
33
|
__export(src_exports, {
|
|
@@ -207,12 +54,372 @@ __export(src_exports, {
|
|
|
207
54
|
default: () => src_default,
|
|
208
55
|
getQuoteAndBuyCoverInputs: () => getQuoteAndBuyCoverInputs,
|
|
209
56
|
productTypes: () => product_types_default,
|
|
210
|
-
products: () => products_default
|
|
211
|
-
sumPoolCapacities: () => sumPoolCapacities
|
|
57
|
+
products: () => products_default
|
|
212
58
|
});
|
|
213
59
|
module.exports = __toCommonJS(src_exports);
|
|
214
60
|
var deployments = __toESM(require("@nexusmutual/deployments"));
|
|
215
61
|
|
|
62
|
+
// src/buyCover/index.ts
|
|
63
|
+
var buyCover_exports = {};
|
|
64
|
+
__export(buyCover_exports, {
|
|
65
|
+
calculatePremiumWithCommissionAndSlippage: () => calculatePremiumWithCommissionAndSlippage
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// src/constants/buyCover.ts
|
|
69
|
+
var CoverAsset = /* @__PURE__ */ ((CoverAsset2) => {
|
|
70
|
+
CoverAsset2[CoverAsset2["ETH"] = 0] = "ETH";
|
|
71
|
+
CoverAsset2[CoverAsset2["DAI"] = 1] = "DAI";
|
|
72
|
+
return CoverAsset2;
|
|
73
|
+
})(CoverAsset || {});
|
|
74
|
+
var CoverId = /* @__PURE__ */ ((CoverId2) => {
|
|
75
|
+
CoverId2[CoverId2["BUY"] = 0] = "BUY";
|
|
76
|
+
return CoverId2;
|
|
77
|
+
})(CoverId || {});
|
|
78
|
+
var COMMISSION_DENOMINATOR = 1e4;
|
|
79
|
+
var SLIPPAGE_DENOMINATOR = 1e4;
|
|
80
|
+
var TARGET_PRICE_DENOMINATOR = 1e4;
|
|
81
|
+
var MINIMUM_COVER_PERIOD = 28;
|
|
82
|
+
var MAXIMUM_COVER_PERIOD = 365;
|
|
83
|
+
var DEFAULT_SLIPPAGE = 10;
|
|
84
|
+
var DEFAULT_COMMISSION_RATIO = 1500;
|
|
85
|
+
var NEXUS_MUTUAL_DAO_TREASURY_ADDRESS = "0x586b9b2F8010b284A0197f392156f1A7Eb5e86e9";
|
|
86
|
+
|
|
87
|
+
// src/buyCover/calculatePremiumWithCommissionAndSlippage.ts
|
|
88
|
+
var calculatePremiumWithCommissionAndSlippage = (premium, commission = 0, slippage = 0) => {
|
|
89
|
+
const premiumWithCommission = premium * BigInt(COMMISSION_DENOMINATOR) / BigInt(COMMISSION_DENOMINATOR - commission);
|
|
90
|
+
const premiumWithCommissionAndSlippage = premiumWithCommission * BigInt(SLIPPAGE_DENOMINATOR + slippage) / BigInt(SLIPPAGE_DENOMINATOR);
|
|
91
|
+
return premiumWithCommissionAndSlippage;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// src/constants/index.ts
|
|
95
|
+
var constants_exports = {};
|
|
96
|
+
__export(constants_exports, {
|
|
97
|
+
COMMISSION_DENOMINATOR: () => COMMISSION_DENOMINATOR,
|
|
98
|
+
CoverAsset: () => CoverAsset,
|
|
99
|
+
CoverId: () => CoverId,
|
|
100
|
+
DEFAULT_COMMISSION_RATIO: () => DEFAULT_COMMISSION_RATIO,
|
|
101
|
+
DEFAULT_SLIPPAGE: () => DEFAULT_SLIPPAGE,
|
|
102
|
+
MAXIMUM_COVER_PERIOD: () => MAXIMUM_COVER_PERIOD,
|
|
103
|
+
MINIMUM_COVER_PERIOD: () => MINIMUM_COVER_PERIOD,
|
|
104
|
+
NEXUS_MUTUAL_DAO_TREASURY_ADDRESS: () => NEXUS_MUTUAL_DAO_TREASURY_ADDRESS,
|
|
105
|
+
SLIPPAGE_DENOMINATOR: () => SLIPPAGE_DENOMINATOR,
|
|
106
|
+
TARGET_PRICE_DENOMINATOR: () => TARGET_PRICE_DENOMINATOR
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// src/quote/index.ts
|
|
110
|
+
var quote_exports = {};
|
|
111
|
+
__export(quote_exports, {
|
|
112
|
+
getQuoteAndBuyCoverInputs: () => getQuoteAndBuyCoverInputs
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// src/quote/getQuoteAndBuyCoverInputs.ts
|
|
116
|
+
var import_axios = __toESM(require("axios"));
|
|
117
|
+
async function getQuoteAndBuyCoverInputs(productId, coverAmount, coverPeriod, coverAsset, coverBuyerAddress, slippage = DEFAULT_SLIPPAGE / SLIPPAGE_DENOMINATOR, ipfsCid = "", coverRouterUrl = "https://api.nexusmutual.io/v2") {
|
|
118
|
+
if (!Number.isInteger(productId) || productId <= 0) {
|
|
119
|
+
return { result: void 0, error: { message: "Invalid productId: must be a positive integer" } };
|
|
120
|
+
}
|
|
121
|
+
if (typeof coverAmount !== "string" || !/^\d+$/.test(coverAmount) || parseInt(coverAmount, 10) <= 0) {
|
|
122
|
+
return { result: void 0, error: { message: "Invalid coverAmount: must be a positive integer string" } };
|
|
123
|
+
}
|
|
124
|
+
if (!Number.isInteger(coverPeriod) || coverPeriod < MINIMUM_COVER_PERIOD || coverPeriod > MAXIMUM_COVER_PERIOD) {
|
|
125
|
+
return {
|
|
126
|
+
result: void 0,
|
|
127
|
+
error: {
|
|
128
|
+
message: `Invalid coverPeriod: must be between ${MINIMUM_COVER_PERIOD} and ${MAXIMUM_COVER_PERIOD} days`
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
const coverAssetsString = Object.keys(CoverAsset).filter((k) => isNaN(+k)).map((k) => `CoverAsset.${k}`).join(", ");
|
|
133
|
+
if (!Object.values(CoverAsset).includes(coverAsset)) {
|
|
134
|
+
return {
|
|
135
|
+
result: void 0,
|
|
136
|
+
error: {
|
|
137
|
+
message: `Invalid coverAsset: must be one of ${coverAssetsString}`
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
if (!/^0x[a-fA-F0-9]{40}$/.test(coverBuyerAddress)) {
|
|
142
|
+
return { result: void 0, error: { message: "Invalid coverBuyerAddress: must be a valid Ethereum address" } };
|
|
143
|
+
}
|
|
144
|
+
if (typeof slippage !== "number" || slippage < 0 || slippage > 1) {
|
|
145
|
+
return {
|
|
146
|
+
result: void 0,
|
|
147
|
+
error: { message: "Invalid slippage: must be a number between 0 and 1" }
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
if (typeof ipfsCid !== "string") {
|
|
151
|
+
return { result: void 0, error: { message: "Invalid ipfsCid: must be a valid IPFS CID" } };
|
|
152
|
+
}
|
|
153
|
+
slippage = slippage * SLIPPAGE_DENOMINATOR;
|
|
154
|
+
try {
|
|
155
|
+
const { quote } = await getQuote(productId, coverAmount, coverPeriod, coverAsset, coverRouterUrl);
|
|
156
|
+
const maxPremiumInAsset = calculatePremiumWithCommissionAndSlippage(
|
|
157
|
+
BigInt(quote.premiumInAsset),
|
|
158
|
+
DEFAULT_COMMISSION_RATIO,
|
|
159
|
+
slippage
|
|
160
|
+
);
|
|
161
|
+
const yearlyCostPerc = calculatePremiumWithCommissionAndSlippage(
|
|
162
|
+
BigInt(quote.annualPrice),
|
|
163
|
+
DEFAULT_COMMISSION_RATIO,
|
|
164
|
+
slippage
|
|
165
|
+
);
|
|
166
|
+
const result = {
|
|
167
|
+
displayInfo: {
|
|
168
|
+
premiumInAsset: maxPremiumInAsset.toString(),
|
|
169
|
+
coverAmount,
|
|
170
|
+
yearlyCostPerc: Number(yearlyCostPerc) / TARGET_PRICE_DENOMINATOR,
|
|
171
|
+
maxCapacity: await getProductCapacity(productId, coverPeriod, coverAsset, coverRouterUrl) ?? ""
|
|
172
|
+
},
|
|
173
|
+
buyCoverInput: {
|
|
174
|
+
buyCoverParams: {
|
|
175
|
+
coverId: 0 /* BUY */,
|
|
176
|
+
owner: coverBuyerAddress,
|
|
177
|
+
productId,
|
|
178
|
+
coverAsset,
|
|
179
|
+
amount: coverAmount,
|
|
180
|
+
period: coverPeriod * 60 * 60 * 24,
|
|
181
|
+
// seconds
|
|
182
|
+
maxPremiumInAsset: maxPremiumInAsset.toString(),
|
|
183
|
+
paymentAsset: coverAsset,
|
|
184
|
+
commissionRatio: DEFAULT_COMMISSION_RATIO,
|
|
185
|
+
commissionDestination: NEXUS_MUTUAL_DAO_TREASURY_ADDRESS,
|
|
186
|
+
ipfsData: ipfsCid
|
|
187
|
+
},
|
|
188
|
+
poolAllocationRequests: quote.poolAllocationRequests
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
return { result, error: void 0 };
|
|
192
|
+
} catch (error) {
|
|
193
|
+
const errorResponse = await handleError(error, productId, coverPeriod, coverAsset, coverRouterUrl);
|
|
194
|
+
return errorResponse;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
async function getQuote(productId, coverAmount, coverPeriod, coverAsset, coverRouterUrl) {
|
|
198
|
+
const params = { productId, amount: coverAmount, period: coverPeriod, coverAsset };
|
|
199
|
+
const response = await import_axios.default.get(coverRouterUrl + "/quote", { params });
|
|
200
|
+
if (!response.data) {
|
|
201
|
+
throw new Error("Failed to fetch cover quote");
|
|
202
|
+
}
|
|
203
|
+
return response.data;
|
|
204
|
+
}
|
|
205
|
+
async function getProductCapacity(productId, coverPeriod, coverAsset, coverRouterUrl) {
|
|
206
|
+
const params = { period: coverPeriod };
|
|
207
|
+
const capacityUrl = coverRouterUrl + `/capacity/${productId}`;
|
|
208
|
+
const response = await import_axios.default.get(capacityUrl, { params });
|
|
209
|
+
if (!response.data) {
|
|
210
|
+
throw new Error("Failed to fetch cover capacities");
|
|
211
|
+
}
|
|
212
|
+
return response.data.availableCapacity.find((av) => av.assetId === coverAsset)?.amount;
|
|
213
|
+
}
|
|
214
|
+
async function handleError(error, productId, coverPeriod, coverAsset, coverRouterUrl) {
|
|
215
|
+
const axiosError = error;
|
|
216
|
+
if (axiosError.isAxiosError) {
|
|
217
|
+
if (axiosError.response?.data?.error?.includes("Not enough capacity")) {
|
|
218
|
+
const maxCapacity = await getProductCapacity(productId, coverPeriod, coverAsset, coverRouterUrl);
|
|
219
|
+
return {
|
|
220
|
+
result: void 0,
|
|
221
|
+
error: {
|
|
222
|
+
message: axiosError.response?.data.error,
|
|
223
|
+
data: maxCapacity ? { maxCapacity } : void 0
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return {
|
|
229
|
+
result: void 0,
|
|
230
|
+
error: { message: error.message || "Something went wrong" }
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// src/swap/index.ts
|
|
235
|
+
var swap_exports = {};
|
|
236
|
+
__export(swap_exports, {
|
|
237
|
+
calculateEthForExactNxm: () => calculateEthForExactNxm,
|
|
238
|
+
calculateExactEthForNxm: () => calculateExactEthForNxm,
|
|
239
|
+
calculateExactNxmForEth: () => calculateExactNxmForEth,
|
|
240
|
+
calculateNxmForExactEth: () => calculateNxmForExactEth,
|
|
241
|
+
calculatePriceImpactA: () => calculatePriceImpactA,
|
|
242
|
+
calculatePriceImpactB: () => calculatePriceImpactB,
|
|
243
|
+
calculateSpotPrice: () => calculateSpotPrice
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
// src/swap/calculateExactNxmForEth.ts
|
|
247
|
+
var calculateExactNxmForEth = (ethIn, reserves) => {
|
|
248
|
+
if (ethIn <= 0n) {
|
|
249
|
+
throw new Error("ETH in value must be greater than 0");
|
|
250
|
+
}
|
|
251
|
+
const k = reserves.nxmA * reserves.ethReserve;
|
|
252
|
+
const ethReservesAfter = reserves.ethReserve + ethIn;
|
|
253
|
+
const nxmReservesAfter = k / ethReservesAfter;
|
|
254
|
+
const nxmOut = reserves.nxmA - nxmReservesAfter;
|
|
255
|
+
if (nxmOut < 0n) {
|
|
256
|
+
throw new Error("Cannot swap this amount");
|
|
257
|
+
}
|
|
258
|
+
return nxmOut;
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
// src/swap/calculateExactEthForNxm.ts
|
|
262
|
+
var calculateExactEthForNxm = (nxmIn, reserves) => {
|
|
263
|
+
if (nxmIn <= 0n) {
|
|
264
|
+
throw new Error("NXM in value must be greater than 0");
|
|
265
|
+
}
|
|
266
|
+
const k = reserves.nxmB * reserves.ethReserve;
|
|
267
|
+
const nxmReservesAfter = reserves.nxmB + nxmIn;
|
|
268
|
+
const ethReservesAfter = k / nxmReservesAfter;
|
|
269
|
+
const ethOut = reserves.ethReserve - ethReservesAfter;
|
|
270
|
+
if (ethOut < 0n) {
|
|
271
|
+
throw new Error("Cannot swap this amount");
|
|
272
|
+
}
|
|
273
|
+
return ethOut;
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
// src/swap/calculateNxmForExactEth.ts
|
|
277
|
+
var calculateNxmForExactEth = (ethOut, reserves) => {
|
|
278
|
+
if (ethOut <= 0n || ethOut >= reserves.ethReserve) {
|
|
279
|
+
throw new Error("ETH out value must be greater than 0 and less than the reserves");
|
|
280
|
+
}
|
|
281
|
+
const k = reserves.nxmB * reserves.ethReserve;
|
|
282
|
+
const ethReservesAfter = reserves.ethReserve - ethOut;
|
|
283
|
+
const nxmReservesAfter = k / ethReservesAfter;
|
|
284
|
+
const nxmIn = nxmReservesAfter - reserves.nxmB;
|
|
285
|
+
return nxmIn;
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
// src/swap/calculateEthForExactNxm.ts
|
|
289
|
+
var calculateEthForExactNxm = (nxmOut, reserves) => {
|
|
290
|
+
if (nxmOut <= 0n || nxmOut >= reserves.nxmA) {
|
|
291
|
+
throw new Error("NXM out value must be greater than 0 and less than the reserves");
|
|
292
|
+
}
|
|
293
|
+
const k = reserves.nxmA * reserves.ethReserve;
|
|
294
|
+
const nxmReservesAfter = reserves.nxmA - nxmOut;
|
|
295
|
+
const ethReservesAfter = k / nxmReservesAfter;
|
|
296
|
+
const ethIn = ethReservesAfter - reserves.ethReserve;
|
|
297
|
+
return ethIn;
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
// src/swap/calculateSpotPrice.ts
|
|
301
|
+
var calculateSpotPrice = (reserves) => {
|
|
302
|
+
const oneEth = BigInt(1e18);
|
|
303
|
+
return {
|
|
304
|
+
spotPriceA: oneEth * reserves.ethReserve / reserves.nxmA,
|
|
305
|
+
spotPriceB: oneEth * reserves.ethReserve / reserves.nxmB
|
|
306
|
+
};
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
// src/swap/calculatePriceImpactA.ts
|
|
310
|
+
var calculatePriceImpactA = (ethIn, reserves) => {
|
|
311
|
+
const { spotPriceA } = calculateSpotPrice(reserves);
|
|
312
|
+
const nxmOut = calculateExactNxmForEth(ethIn, reserves);
|
|
313
|
+
const nxmOutAtSpotPrice = BigInt(1e18) * ethIn / spotPriceA;
|
|
314
|
+
return BigInt(1e6) - BigInt(1e6) * nxmOut / nxmOutAtSpotPrice;
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
// src/swap/calculatePriceImpactB.ts
|
|
318
|
+
var calculatePriceImpactB = (nxmIn, reserves) => {
|
|
319
|
+
const { spotPriceB } = calculateSpotPrice(reserves);
|
|
320
|
+
const ethOut = calculateExactEthForNxm(nxmIn, reserves);
|
|
321
|
+
const ethOutAtSpotPrice = spotPriceB * nxmIn / BigInt(1e18);
|
|
322
|
+
return BigInt(1e6) - BigInt(1e6) * ethOut / ethOutAtSpotPrice;
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
// src/types/index.ts
|
|
326
|
+
var types_exports = {};
|
|
327
|
+
|
|
328
|
+
// generated/product-types.json
|
|
329
|
+
var product_types_default = [
|
|
330
|
+
{
|
|
331
|
+
id: 0,
|
|
332
|
+
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmdunFJm4A5CUW1ynM7bevsGt6UzQfw6K4ysKqvsqpjWCQ",
|
|
333
|
+
name: "Protocol",
|
|
334
|
+
gracePeriod: 3024e3,
|
|
335
|
+
claimMethod: 0
|
|
336
|
+
},
|
|
337
|
+
{
|
|
338
|
+
id: 1,
|
|
339
|
+
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmYhCNjfrNTMq8eyg8i7LbBpTkMCHfix9Sv1jrPb7dYZKd",
|
|
340
|
+
name: "Custody",
|
|
341
|
+
gracePeriod: 10368e3,
|
|
342
|
+
claimMethod: 0
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
id: 2,
|
|
346
|
+
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmcPdiLNZmBM8pjQcCzLhH8tjPuhphCVKZeP5P4SBiLx3h",
|
|
347
|
+
name: "Yield Token",
|
|
348
|
+
gracePeriod: 1209600,
|
|
349
|
+
claimMethod: 1
|
|
350
|
+
},
|
|
351
|
+
{
|
|
352
|
+
id: 3,
|
|
353
|
+
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmUTUfdfuZUjtPAiMZ4YRu77SaiyCov7jrSXTgeGeK8qt3",
|
|
354
|
+
name: "Sherlock Excess",
|
|
355
|
+
gracePeriod: 3024e3,
|
|
356
|
+
claimMethod: 0
|
|
357
|
+
},
|
|
358
|
+
{
|
|
359
|
+
id: 4,
|
|
360
|
+
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmPmwtwbyKnXBae1dmYD6jmgnewCeZGPMFGepkWMLWaiwC",
|
|
361
|
+
name: "Stakewise ETH Staking",
|
|
362
|
+
gracePeriod: 3024e3,
|
|
363
|
+
claimMethod: 0
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
id: 5,
|
|
367
|
+
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmUKhLi5ZahnzSxsMC9YQZbwwAKGhkHcoYqHUVgE31cXLe",
|
|
368
|
+
name: "Liquid Collective ETH Staking",
|
|
369
|
+
gracePeriod: 3024e3,
|
|
370
|
+
claimMethod: 0
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
id: 6,
|
|
374
|
+
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmWepFbtMYSzJt22ddF1CK9PwbrYgiLk9qJjryDrgpGuus",
|
|
375
|
+
name: "ETH Slashing",
|
|
376
|
+
gracePeriod: 3024e3,
|
|
377
|
+
claimMethod: 0
|
|
378
|
+
},
|
|
379
|
+
{
|
|
380
|
+
id: 7,
|
|
381
|
+
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmQfYgbBhyC3gJMvan9gbzUaZtd4Xy4gubEYfgTFKycBDZ",
|
|
382
|
+
name: "Sherlock Quota Share",
|
|
383
|
+
gracePeriod: 3024e3,
|
|
384
|
+
claimMethod: 0
|
|
385
|
+
},
|
|
386
|
+
{
|
|
387
|
+
id: 8,
|
|
388
|
+
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmRrKXV9RBNAB5E1ZEigWmvvT24FgrWNSZ8Yw1VNXR8E6Q",
|
|
389
|
+
name: "Native Protocol",
|
|
390
|
+
gracePeriod: 3024e3,
|
|
391
|
+
claimMethod: 0
|
|
392
|
+
},
|
|
393
|
+
{
|
|
394
|
+
id: 9,
|
|
395
|
+
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmQG8ooLgoQx2YdykwZEUYruoMZ7YP23LK9yiQbw9AGTZi",
|
|
396
|
+
name: "The Retail Mutual",
|
|
397
|
+
gracePeriod: 3672e4,
|
|
398
|
+
claimMethod: 0
|
|
399
|
+
},
|
|
400
|
+
{
|
|
401
|
+
id: 10,
|
|
402
|
+
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmWXYjBYjdKoRw6kyUvp5gYKjj2ojPPVxNYKr1gDjMLssY",
|
|
403
|
+
name: "UnoRe Quota Share",
|
|
404
|
+
gracePeriod: 3024e3,
|
|
405
|
+
claimMethod: 0
|
|
406
|
+
},
|
|
407
|
+
{
|
|
408
|
+
id: 11,
|
|
409
|
+
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmWV9woyKJirjHd73MhibV59qmqzp1w1gqfMfZBQhneSL8",
|
|
410
|
+
name: "Bundled Protocol Cover",
|
|
411
|
+
gracePeriod: 3024e3,
|
|
412
|
+
claimMethod: 0
|
|
413
|
+
},
|
|
414
|
+
{
|
|
415
|
+
id: 12,
|
|
416
|
+
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmQx2H9A51SARNc4W8Ta2D2woXv2ebkUGZMC5HZoQW8TUX",
|
|
417
|
+
name: "ETH Slashing Umbrella",
|
|
418
|
+
gracePeriod: 3024e3,
|
|
419
|
+
claimMethod: 0
|
|
420
|
+
}
|
|
421
|
+
];
|
|
422
|
+
|
|
216
423
|
// generated/products.json
|
|
217
424
|
var products_default = [
|
|
218
425
|
{
|
|
@@ -1638,7 +1845,7 @@ var products_default = [
|
|
|
1638
1845
|
"DAI"
|
|
1639
1846
|
],
|
|
1640
1847
|
isPrivate: true,
|
|
1641
|
-
timestamp:
|
|
1848
|
+
timestamp: 1704981731
|
|
1642
1849
|
},
|
|
1643
1850
|
{
|
|
1644
1851
|
id: 88,
|
|
@@ -1732,7 +1939,7 @@ var products_default = [
|
|
|
1732
1939
|
"DAI"
|
|
1733
1940
|
],
|
|
1734
1941
|
isPrivate: true,
|
|
1735
|
-
timestamp:
|
|
1942
|
+
timestamp: 1684312727
|
|
1736
1943
|
},
|
|
1737
1944
|
{
|
|
1738
1945
|
id: 94,
|
|
@@ -2381,7 +2588,7 @@ var products_default = [
|
|
|
2381
2588
|
"ETH"
|
|
2382
2589
|
],
|
|
2383
2590
|
isPrivate: false,
|
|
2384
|
-
timestamp:
|
|
2591
|
+
timestamp: 1709311739
|
|
2385
2592
|
},
|
|
2386
2593
|
{
|
|
2387
2594
|
id: 137,
|
|
@@ -2750,107 +2957,60 @@ var products_default = [
|
|
|
2750
2957
|
],
|
|
2751
2958
|
isPrivate: true,
|
|
2752
2959
|
timestamp: 1712739011
|
|
2753
|
-
}
|
|
2754
|
-
];
|
|
2755
|
-
|
|
2756
|
-
// generated/product-types.json
|
|
2757
|
-
var product_types_default = [
|
|
2758
|
-
{
|
|
2759
|
-
id: 0,
|
|
2760
|
-
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmdunFJm4A5CUW1ynM7bevsGt6UzQfw6K4ysKqvsqpjWCQ",
|
|
2761
|
-
name: "Protocol",
|
|
2762
|
-
gracePeriod: 3024e3,
|
|
2763
|
-
claimMethod: 0
|
|
2764
2960
|
},
|
|
2765
2961
|
{
|
|
2766
|
-
id:
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
id: 3,
|
|
2781
|
-
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmUTUfdfuZUjtPAiMZ4YRu77SaiyCov7jrSXTgeGeK8qt3",
|
|
2782
|
-
name: "Sherlock Excess",
|
|
2783
|
-
gracePeriod: 3024e3,
|
|
2784
|
-
claimMethod: 0
|
|
2785
|
-
},
|
|
2786
|
-
{
|
|
2787
|
-
id: 4,
|
|
2788
|
-
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmPmwtwbyKnXBae1dmYD6jmgnewCeZGPMFGepkWMLWaiwC",
|
|
2789
|
-
name: "Stakewise ETH Staking",
|
|
2790
|
-
gracePeriod: 3024e3,
|
|
2791
|
-
claimMethod: 0
|
|
2792
|
-
},
|
|
2793
|
-
{
|
|
2794
|
-
id: 5,
|
|
2795
|
-
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmUKhLi5ZahnzSxsMC9YQZbwwAKGhkHcoYqHUVgE31cXLe",
|
|
2796
|
-
name: "Liquid Collective ETH Staking",
|
|
2797
|
-
gracePeriod: 3024e3,
|
|
2798
|
-
claimMethod: 0
|
|
2799
|
-
},
|
|
2800
|
-
{
|
|
2801
|
-
id: 6,
|
|
2802
|
-
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmWepFbtMYSzJt22ddF1CK9PwbrYgiLk9qJjryDrgpGuus",
|
|
2803
|
-
name: "ETH Slashing",
|
|
2804
|
-
gracePeriod: 3024e3,
|
|
2805
|
-
claimMethod: 0
|
|
2806
|
-
},
|
|
2807
|
-
{
|
|
2808
|
-
id: 7,
|
|
2809
|
-
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmQfYgbBhyC3gJMvan9gbzUaZtd4Xy4gubEYfgTFKycBDZ",
|
|
2810
|
-
name: "Sherlock Quota Share",
|
|
2811
|
-
gracePeriod: 3024e3,
|
|
2812
|
-
claimMethod: 0
|
|
2813
|
-
},
|
|
2814
|
-
{
|
|
2815
|
-
id: 8,
|
|
2816
|
-
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmRrKXV9RBNAB5E1ZEigWmvvT24FgrWNSZ8Yw1VNXR8E6Q",
|
|
2817
|
-
name: "Native Protocol",
|
|
2818
|
-
gracePeriod: 3024e3,
|
|
2819
|
-
claimMethod: 0
|
|
2820
|
-
},
|
|
2821
|
-
{
|
|
2822
|
-
id: 9,
|
|
2823
|
-
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmQG8ooLgoQx2YdykwZEUYruoMZ7YP23LK9yiQbw9AGTZi",
|
|
2824
|
-
name: "The Retail Mutual",
|
|
2825
|
-
gracePeriod: 3672e4,
|
|
2826
|
-
claimMethod: 0
|
|
2827
|
-
},
|
|
2828
|
-
{
|
|
2829
|
-
id: 10,
|
|
2830
|
-
coverWordingURL: "https://api.nexusmutual.io/ipfs/QmWXYjBYjdKoRw6kyUvp5gYKjj2ojPPVxNYKr1gDjMLssY",
|
|
2831
|
-
name: "UnoRe Quota Share",
|
|
2832
|
-
gracePeriod: 3024e3,
|
|
2833
|
-
claimMethod: 0
|
|
2962
|
+
id: 160,
|
|
2963
|
+
name: "Etherfi (Zircuit) Pendle",
|
|
2964
|
+
productType: 11,
|
|
2965
|
+
isDeprecated: false,
|
|
2966
|
+
useFixedPrice: false,
|
|
2967
|
+
logo: "etherfi-zircuit-pendle.svg",
|
|
2968
|
+
metadata: {
|
|
2969
|
+
annex: "QmarQuziSJBVQoayRgPNuEiJdZHgf6wxDyKiGQVpsCNRnJ"
|
|
2970
|
+
},
|
|
2971
|
+
coverAssets: [
|
|
2972
|
+
"ETH"
|
|
2973
|
+
],
|
|
2974
|
+
isPrivate: false,
|
|
2975
|
+
timestamp: 1713185771
|
|
2834
2976
|
},
|
|
2835
2977
|
{
|
|
2836
|
-
id:
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2978
|
+
id: 161,
|
|
2979
|
+
name: "KelpDAO (Zircuit) Pendle",
|
|
2980
|
+
productType: 11,
|
|
2981
|
+
isDeprecated: false,
|
|
2982
|
+
useFixedPrice: false,
|
|
2983
|
+
logo: "kelpdao-zircuit-pendle.svg",
|
|
2984
|
+
metadata: {
|
|
2985
|
+
annex: "QmdseksWrvXoMjF58NGnSS6WC7dXDVk2oeZz93Bt4oMzT2"
|
|
2986
|
+
},
|
|
2987
|
+
coverAssets: [
|
|
2988
|
+
"ETH"
|
|
2989
|
+
],
|
|
2990
|
+
isPrivate: false,
|
|
2991
|
+
timestamp: 1713185771
|
|
2841
2992
|
},
|
|
2842
2993
|
{
|
|
2843
|
-
id:
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2994
|
+
id: 162,
|
|
2995
|
+
name: "Renzo (Zircuit) Pendle",
|
|
2996
|
+
productType: 11,
|
|
2997
|
+
isDeprecated: false,
|
|
2998
|
+
useFixedPrice: false,
|
|
2999
|
+
logo: "renzo-zircuit-pendle.svg",
|
|
3000
|
+
metadata: {
|
|
3001
|
+
annex: "QmeAB5RzQgQbC2DFa9W49taFEoxhZEUDgnXqvfceFUL4Xm"
|
|
3002
|
+
},
|
|
3003
|
+
coverAssets: [
|
|
3004
|
+
"ETH"
|
|
3005
|
+
],
|
|
3006
|
+
isPrivate: false,
|
|
3007
|
+
timestamp: 1713185771
|
|
2848
3008
|
}
|
|
2849
3009
|
];
|
|
2850
3010
|
|
|
2851
3011
|
// generated/types.ts
|
|
2852
|
-
var
|
|
2853
|
-
__export(
|
|
3012
|
+
var types_exports2 = {};
|
|
3013
|
+
__export(types_exports2, {
|
|
2854
3014
|
allLogoFileNames: () => allLogoFileNames,
|
|
2855
3015
|
allLogoNames: () => allLogoNames
|
|
2856
3016
|
});
|
|
@@ -3015,6 +3175,9 @@ var allLogoFileNames = [
|
|
|
3015
3175
|
"lyra-synthetix.svg",
|
|
3016
3176
|
"eigenlayer-renzo.svg",
|
|
3017
3177
|
"liquidcollective.svg",
|
|
3178
|
+
"etherfi-zircuit-pendle.svg",
|
|
3179
|
+
"kelpdao-zircuit-pendle.svg",
|
|
3180
|
+
"renzo-zircuit-pendle.svg",
|
|
3018
3181
|
"aave-v1.svg",
|
|
3019
3182
|
"akropolis.svg",
|
|
3020
3183
|
"alpha-homora.svg",
|
|
@@ -3230,6 +3393,9 @@ var allLogoNames = [
|
|
|
3230
3393
|
"lyra-synthetix",
|
|
3231
3394
|
"eigenlayer-renzo",
|
|
3232
3395
|
"liquidcollective",
|
|
3396
|
+
"etherfi-zircuit-pendle",
|
|
3397
|
+
"kelpdao-zircuit-pendle",
|
|
3398
|
+
"renzo-zircuit-pendle",
|
|
3233
3399
|
"aave-v1",
|
|
3234
3400
|
"akropolis",
|
|
3235
3401
|
"alpha-homora",
|
|
@@ -3285,289 +3451,16 @@ var allLogoNames = [
|
|
|
3285
3451
|
"zksync"
|
|
3286
3452
|
];
|
|
3287
3453
|
|
|
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
|
-
|
|
3300
|
-
// src/swap/calculateExactNxmForEth.ts
|
|
3301
|
-
var calculateExactNxmForEth = (ethIn, reserves) => {
|
|
3302
|
-
if (ethIn <= 0n)
|
|
3303
|
-
throw new Error("ETH in value must be greater than 0");
|
|
3304
|
-
const k = reserves.nxmA * reserves.ethReserve;
|
|
3305
|
-
const ethReservesAfter = reserves.ethReserve + ethIn;
|
|
3306
|
-
const nxmReservesAfter = k / ethReservesAfter;
|
|
3307
|
-
const nxmOut = reserves.nxmA - nxmReservesAfter;
|
|
3308
|
-
if (nxmOut < 0n)
|
|
3309
|
-
throw new Error("Cannot swap this amount");
|
|
3310
|
-
return nxmOut;
|
|
3311
|
-
};
|
|
3312
|
-
|
|
3313
|
-
// src/swap/calculateExactEthForNxm.ts
|
|
3314
|
-
var calculateExactEthForNxm = (nxmIn, reserves) => {
|
|
3315
|
-
if (nxmIn <= 0n)
|
|
3316
|
-
throw new Error("NXM in value must be greater than 0");
|
|
3317
|
-
const k = reserves.nxmB * reserves.ethReserve;
|
|
3318
|
-
const nxmReservesAfter = reserves.nxmB + nxmIn;
|
|
3319
|
-
const ethReservesAfter = k / nxmReservesAfter;
|
|
3320
|
-
const ethOut = reserves.ethReserve - ethReservesAfter;
|
|
3321
|
-
if (ethOut < 0n)
|
|
3322
|
-
throw new Error("Cannot swap this amount");
|
|
3323
|
-
return ethOut;
|
|
3324
|
-
};
|
|
3325
|
-
|
|
3326
|
-
// src/swap/calculateNxmForExactEth.ts
|
|
3327
|
-
var calculateNxmForExactEth = (ethOut, reserves) => {
|
|
3328
|
-
if (ethOut <= 0n || ethOut >= reserves.ethReserve)
|
|
3329
|
-
throw new Error("ETH out value must be greater than 0 and less than the reserves");
|
|
3330
|
-
const k = reserves.nxmB * reserves.ethReserve;
|
|
3331
|
-
const ethReservesAfter = reserves.ethReserve - ethOut;
|
|
3332
|
-
const nxmReservesAfter = k / ethReservesAfter;
|
|
3333
|
-
const nxmIn = nxmReservesAfter - reserves.nxmB;
|
|
3334
|
-
return nxmIn;
|
|
3335
|
-
};
|
|
3336
|
-
|
|
3337
|
-
// src/swap/calculateEthForExactNxm.ts
|
|
3338
|
-
var calculateEthForExactNxm = (nxmOut, reserves) => {
|
|
3339
|
-
if (nxmOut <= 0n || nxmOut >= reserves.nxmA)
|
|
3340
|
-
throw new Error("NXM out value must be greater than 0 and less than the reserves");
|
|
3341
|
-
const k = reserves.nxmA * reserves.ethReserve;
|
|
3342
|
-
const nxmReservesAfter = reserves.nxmA - nxmOut;
|
|
3343
|
-
const ethReservesAfter = k / nxmReservesAfter;
|
|
3344
|
-
const ethIn = ethReservesAfter - reserves.ethReserve;
|
|
3345
|
-
return ethIn;
|
|
3346
|
-
};
|
|
3347
|
-
|
|
3348
|
-
// src/swap/calculateSpotPrice.ts
|
|
3349
|
-
var calculateSpotPrice = (reserves) => {
|
|
3350
|
-
const oneEth = BigInt(1e18);
|
|
3351
|
-
return {
|
|
3352
|
-
spotPriceA: oneEth * reserves.ethReserve / reserves.nxmA,
|
|
3353
|
-
spotPriceB: oneEth * reserves.ethReserve / reserves.nxmB
|
|
3354
|
-
};
|
|
3355
|
-
};
|
|
3356
|
-
|
|
3357
|
-
// src/swap/calculatePriceImpactA.ts
|
|
3358
|
-
var calculatePriceImpactA = (ethIn, reserves) => {
|
|
3359
|
-
const { spotPriceA } = calculateSpotPrice(reserves);
|
|
3360
|
-
const nxmOut = calculateExactNxmForEth(ethIn, reserves);
|
|
3361
|
-
const nxmOutAtSpotPrice = BigInt(1e18) * ethIn / spotPriceA;
|
|
3362
|
-
return BigInt(1e6) - BigInt(1e6) * nxmOut / nxmOutAtSpotPrice;
|
|
3363
|
-
};
|
|
3364
|
-
|
|
3365
|
-
// src/swap/calculatePriceImpactB.ts
|
|
3366
|
-
var calculatePriceImpactB = (nxmIn, reserves) => {
|
|
3367
|
-
const { spotPriceB } = calculateSpotPrice(reserves);
|
|
3368
|
-
const ethOut = calculateExactEthForNxm(nxmIn, reserves);
|
|
3369
|
-
const ethOutAtSpotPrice = spotPriceB * nxmIn / BigInt(1e18);
|
|
3370
|
-
return BigInt(1e6) - BigInt(1e6) * ethOut / ethOutAtSpotPrice;
|
|
3371
|
-
};
|
|
3372
|
-
|
|
3373
|
-
// src/buyCover/index.ts
|
|
3374
|
-
var buyCover_exports = {};
|
|
3375
|
-
__export(buyCover_exports, {
|
|
3376
|
-
calculatePremiumWithCommissionAndSlippage: () => calculatePremiumWithCommissionAndSlippage
|
|
3377
|
-
});
|
|
3378
|
-
|
|
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 || {});
|
|
3389
|
-
var COMMISSION_DENOMINATOR = 1e4;
|
|
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";
|
|
3397
|
-
|
|
3398
|
-
// src/buyCover/calculatePremiumWithCommissionAndSlippage.ts
|
|
3399
|
-
var calculatePremiumWithCommissionAndSlippage = (premium, commission = 0, slippage = 0) => {
|
|
3400
|
-
const premiumWithCommission = premium * BigInt(COMMISSION_DENOMINATOR) / BigInt(COMMISSION_DENOMINATOR - commission);
|
|
3401
|
-
const premiumWithCommissionAndSlippage = premiumWithCommission * BigInt(SLIPPAGE_DENOMINATOR + slippage) / BigInt(SLIPPAGE_DENOMINATOR);
|
|
3402
|
-
return premiumWithCommissionAndSlippage;
|
|
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 / SLIPPAGE_DENOMINATOR, 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 > 1) {
|
|
3450
|
-
return {
|
|
3451
|
-
result: void 0,
|
|
3452
|
-
error: { message: "Invalid slippage: must be a number between 0 and 1" }
|
|
3453
|
-
};
|
|
3454
|
-
}
|
|
3455
|
-
if (typeof ipfsCid !== "string") {
|
|
3456
|
-
return { result: void 0, error: { message: "Invalid ipfsCid: must be a valid IPFS CID" } };
|
|
3457
|
-
}
|
|
3458
|
-
slippage = slippage * SLIPPAGE_DENOMINATOR;
|
|
3459
|
-
try {
|
|
3460
|
-
const { quote, capacities } = await getQuote(productId, coverAmount, coverPeriod, coverAsset);
|
|
3461
|
-
const maxPremiumInAsset = calculatePremiumWithCommissionAndSlippage(
|
|
3462
|
-
BigInt(quote.premiumInAsset),
|
|
3463
|
-
DEFAULT_COMMISSION_RATIO,
|
|
3464
|
-
slippage
|
|
3465
|
-
);
|
|
3466
|
-
const yearlyCostPerc = calculatePremiumWithCommissionAndSlippage(
|
|
3467
|
-
BigInt(quote.annualPrice),
|
|
3468
|
-
DEFAULT_COMMISSION_RATIO,
|
|
3469
|
-
slippage
|
|
3470
|
-
);
|
|
3471
|
-
const result = {
|
|
3472
|
-
displayInfo: {
|
|
3473
|
-
premiumInAsset: maxPremiumInAsset.toString(),
|
|
3474
|
-
coverAmount,
|
|
3475
|
-
yearlyCostPerc: Number(yearlyCostPerc) / TARGET_PRICE_DENOMINATOR,
|
|
3476
|
-
maxCapacity: sumPoolCapacities(capacities)
|
|
3477
|
-
},
|
|
3478
|
-
buyCoverInput: {
|
|
3479
|
-
buyCoverParams: {
|
|
3480
|
-
coverId: 0 /* BUY */,
|
|
3481
|
-
owner: coverBuyerAddress,
|
|
3482
|
-
productId,
|
|
3483
|
-
coverAsset,
|
|
3484
|
-
amount: coverAmount,
|
|
3485
|
-
period: coverPeriod * 60 * 60 * 24,
|
|
3486
|
-
// seconds
|
|
3487
|
-
maxPremiumInAsset: maxPremiumInAsset.toString(),
|
|
3488
|
-
paymentAsset: coverAsset,
|
|
3489
|
-
commissionRatio: DEFAULT_COMMISSION_RATIO,
|
|
3490
|
-
commissionDestination: NEXUS_MUTUAL_DAO_TREASURY_ADDRESS,
|
|
3491
|
-
ipfsData: ipfsCid
|
|
3492
|
-
},
|
|
3493
|
-
poolAllocationRequests: quote.poolAllocationRequests
|
|
3494
|
-
}
|
|
3495
|
-
};
|
|
3496
|
-
return { result, error: void 0 };
|
|
3497
|
-
} catch (error) {
|
|
3498
|
-
const errorResponse = await handleError(error, productId, coverPeriod, coverAsset);
|
|
3499
|
-
return errorResponse;
|
|
3500
|
-
}
|
|
3501
|
-
}
|
|
3502
|
-
async function getQuote(productId, coverAmount, coverPeriod, coverAsset) {
|
|
3503
|
-
const params = { productId, amount: coverAmount, period: coverPeriod, coverAsset };
|
|
3504
|
-
const response = await import_axios.default.get(process.env.COVER_ROUTER_URL + "/quote", { params });
|
|
3505
|
-
if (!response.data) {
|
|
3506
|
-
throw new Error("Failed to fetch cover quote");
|
|
3507
|
-
}
|
|
3508
|
-
return response.data;
|
|
3509
|
-
}
|
|
3510
|
-
async function getProductCapacity(productId, coverPeriod, coverAsset) {
|
|
3511
|
-
const params = { period: coverPeriod };
|
|
3512
|
-
const capacityUrl = process.env.COVER_ROUTER_URL + `/capacity/${productId}`;
|
|
3513
|
-
const response = await import_axios.default.get(capacityUrl, { params });
|
|
3514
|
-
if (!response.data) {
|
|
3515
|
-
throw new Error("Failed to fetch cover capacities");
|
|
3516
|
-
}
|
|
3517
|
-
return response.data.availableCapacity.find((av) => av.assetId === coverAsset)?.amount;
|
|
3518
|
-
}
|
|
3519
|
-
function sumPoolCapacities(capacities) {
|
|
3520
|
-
let totalAmount = BigInt(0);
|
|
3521
|
-
capacities.forEach((poolCapacity) => {
|
|
3522
|
-
poolCapacity.capacity.forEach((capacity) => totalAmount += BigInt(capacity.amount));
|
|
3523
|
-
});
|
|
3524
|
-
return totalAmount.toString();
|
|
3525
|
-
}
|
|
3526
|
-
async function handleError(error, productId, coverPeriod, coverAsset) {
|
|
3527
|
-
const axiosError = error;
|
|
3528
|
-
if (axiosError.isAxiosError) {
|
|
3529
|
-
if (axiosError.response?.data?.error?.includes("Not enough capacity")) {
|
|
3530
|
-
const maxCapacity = await getProductCapacity(productId, coverPeriod, coverAsset);
|
|
3531
|
-
return {
|
|
3532
|
-
result: void 0,
|
|
3533
|
-
error: {
|
|
3534
|
-
message: axiosError.response?.data.error,
|
|
3535
|
-
data: maxCapacity ? { maxCapacity } : void 0
|
|
3536
|
-
}
|
|
3537
|
-
};
|
|
3538
|
-
}
|
|
3539
|
-
}
|
|
3540
|
-
return {
|
|
3541
|
-
result: void 0,
|
|
3542
|
-
error: { message: error.message || "Something went wrong" }
|
|
3543
|
-
};
|
|
3544
|
-
}
|
|
3545
|
-
|
|
3546
|
-
// src/constants/index.ts
|
|
3547
|
-
var constants_exports = {};
|
|
3548
|
-
__export(constants_exports, {
|
|
3549
|
-
COMMISSION_DENOMINATOR: () => COMMISSION_DENOMINATOR,
|
|
3550
|
-
CoverAsset: () => CoverAsset,
|
|
3551
|
-
CoverId: () => CoverId,
|
|
3552
|
-
DEFAULT_COMMISSION_RATIO: () => DEFAULT_COMMISSION_RATIO,
|
|
3553
|
-
DEFAULT_SLIPPAGE: () => DEFAULT_SLIPPAGE,
|
|
3554
|
-
MAXIMUM_COVER_PERIOD: () => MAXIMUM_COVER_PERIOD,
|
|
3555
|
-
MINIMUM_COVER_PERIOD: () => MINIMUM_COVER_PERIOD,
|
|
3556
|
-
NEXUS_MUTUAL_DAO_TREASURY_ADDRESS: () => NEXUS_MUTUAL_DAO_TREASURY_ADDRESS,
|
|
3557
|
-
SLIPPAGE_DENOMINATOR: () => SLIPPAGE_DENOMINATOR,
|
|
3558
|
-
TARGET_PRICE_DENOMINATOR: () => TARGET_PRICE_DENOMINATOR
|
|
3559
|
-
});
|
|
3560
|
-
|
|
3561
3454
|
// src/index.ts
|
|
3562
3455
|
__reExport(src_exports, require("@nexusmutual/deployments"), module.exports);
|
|
3563
3456
|
var nexusSdk = {
|
|
3564
3457
|
...deployments,
|
|
3565
3458
|
products: products_default,
|
|
3566
3459
|
productTypes: product_types_default,
|
|
3567
|
-
...
|
|
3460
|
+
...types_exports2,
|
|
3568
3461
|
...swap_exports,
|
|
3569
3462
|
...buyCover_exports,
|
|
3570
|
-
...
|
|
3463
|
+
...types_exports,
|
|
3571
3464
|
...quote_exports,
|
|
3572
3465
|
...constants_exports
|
|
3573
3466
|
};
|
|
@@ -3597,7 +3490,6 @@ var src_default = nexusSdk;
|
|
|
3597
3490
|
getQuoteAndBuyCoverInputs,
|
|
3598
3491
|
productTypes,
|
|
3599
3492
|
products,
|
|
3600
|
-
sumPoolCapacities,
|
|
3601
3493
|
...require("@nexusmutual/deployments")
|
|
3602
3494
|
});
|
|
3603
3495
|
//# sourceMappingURL=index.js.map
|