@nexusmutual/sdk 0.3.0 → 0.3.2
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 +3 -3
- package/dist/index.d.mts +20 -6
- package/dist/index.d.ts +20 -6
- package/dist/index.js +25 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +25 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/data/products.json
CHANGED
|
@@ -1360,7 +1360,7 @@
|
|
|
1360
1360
|
"DAI"
|
|
1361
1361
|
],
|
|
1362
1362
|
"isPrivate": true,
|
|
1363
|
-
"timestamp":
|
|
1363
|
+
"timestamp": 1684312727
|
|
1364
1364
|
},
|
|
1365
1365
|
{
|
|
1366
1366
|
"id": 84,
|
|
@@ -1422,7 +1422,7 @@
|
|
|
1422
1422
|
"DAI"
|
|
1423
1423
|
],
|
|
1424
1424
|
"isPrivate": true,
|
|
1425
|
-
"timestamp":
|
|
1425
|
+
"timestamp": 1684312727
|
|
1426
1426
|
},
|
|
1427
1427
|
{
|
|
1428
1428
|
"id": 88,
|
|
@@ -1700,7 +1700,7 @@
|
|
|
1700
1700
|
"DAI"
|
|
1701
1701
|
],
|
|
1702
1702
|
"isPrivate": true,
|
|
1703
|
-
"timestamp":
|
|
1703
|
+
"timestamp": 1689782903
|
|
1704
1704
|
},
|
|
1705
1705
|
{
|
|
1706
1706
|
"id": 106,
|
package/dist/index.d.mts
CHANGED
|
@@ -71,9 +71,13 @@ type Address = string;
|
|
|
71
71
|
*/
|
|
72
72
|
type Integer = number;
|
|
73
73
|
/**
|
|
74
|
-
* Integer
|
|
74
|
+
* Integer value in string format
|
|
75
75
|
*/
|
|
76
76
|
type IntString = string;
|
|
77
|
+
/**
|
|
78
|
+
* Float value in string format
|
|
79
|
+
*/
|
|
80
|
+
type FloatString = string;
|
|
77
81
|
|
|
78
82
|
type BuyCoverParams = {
|
|
79
83
|
coverId: Integer;
|
|
@@ -97,6 +101,16 @@ type CoverRouterQuoteResponse = {
|
|
|
97
101
|
quote: Quote;
|
|
98
102
|
capacities: PoolCapacity[];
|
|
99
103
|
};
|
|
104
|
+
type CoverRouterProductCapacityResponse = {
|
|
105
|
+
productId: Integer;
|
|
106
|
+
availableCapacity: Array<{
|
|
107
|
+
assetId: Integer;
|
|
108
|
+
amount: IntString;
|
|
109
|
+
}>;
|
|
110
|
+
allocatedNxm: IntString;
|
|
111
|
+
minAnnualPrice: FloatString;
|
|
112
|
+
maxAnnualPrice: FloatString;
|
|
113
|
+
};
|
|
100
114
|
type Quote = {
|
|
101
115
|
totalCoverAmountInAsset: IntString;
|
|
102
116
|
annualPrice: IntString;
|
|
@@ -137,7 +151,7 @@ type GetQuoteApiResponse = ApiResponse<GetQuoteResponse, undefined>;
|
|
|
137
151
|
* @param {Integer} coverPeriod - The duration of the cover in days (28-365).
|
|
138
152
|
* @param {CoverAsset} coverAsset - The asset for which cover is being purchased (the cover must be purchased using the same asset)
|
|
139
153
|
* @param {Address} coverBuyerAddress - The Ethereum address of the buyer.
|
|
140
|
-
* @param {number} slippage - The acceptable slippage percentage. Must be between 0
|
|
154
|
+
* @param {number} slippage - The acceptable slippage percentage. Must be between 0-1 (Defaults to 0.001 ~ 0.1%)
|
|
141
155
|
* @param {string} ipfsCid - The IPFS CID for additional data (optional).
|
|
142
156
|
* @return {Promise<GetQuoteApiResponse | ErrorApiResponse>} Returns a successful quote response or an error response.
|
|
143
157
|
*/
|
|
@@ -1573,7 +1587,7 @@ var products = [
|
|
|
1573
1587
|
"DAI"
|
|
1574
1588
|
],
|
|
1575
1589
|
isPrivate: true,
|
|
1576
|
-
timestamp:
|
|
1590
|
+
timestamp: 1684312727
|
|
1577
1591
|
},
|
|
1578
1592
|
{
|
|
1579
1593
|
id: 84,
|
|
@@ -1638,7 +1652,7 @@ var products = [
|
|
|
1638
1652
|
"DAI"
|
|
1639
1653
|
],
|
|
1640
1654
|
isPrivate: true,
|
|
1641
|
-
timestamp:
|
|
1655
|
+
timestamp: 1684312727
|
|
1642
1656
|
},
|
|
1643
1657
|
{
|
|
1644
1658
|
id: 88,
|
|
@@ -1928,7 +1942,7 @@ var products = [
|
|
|
1928
1942
|
"DAI"
|
|
1929
1943
|
],
|
|
1930
1944
|
isPrivate: true,
|
|
1931
|
-
timestamp:
|
|
1945
|
+
timestamp: 1689782903
|
|
1932
1946
|
},
|
|
1933
1947
|
{
|
|
1934
1948
|
id: 106,
|
|
@@ -38933,4 +38947,4 @@ declare const nexusSdk: {
|
|
|
38933
38947
|
}];
|
|
38934
38948
|
};
|
|
38935
38949
|
|
|
38936
|
-
export { Address, ApiResponse, BuyCoverInput, BuyCoverParams, COMMISSION_DENOMINATOR, Capacity, CoverAsset, CoverId, CoverRouterQuoteResponse, DEFAULT_COMMISSION_RATIO, DEFAULT_SLIPPAGE, ErrorApiResponse, ErrorResponse, GetQuoteApiResponse, GetQuoteResponse, IntString, Integer, LogoFileName, LogoName, MAXIMUM_COVER_PERIOD, MINIMUM_COVER_PERIOD, NEXUS_MUTUAL_DAO_TREASURY_ADDRESS, PoolAllocationRequest, PoolCapacity, Quote, QuoteDisplayInfo, Reserves, SLIPPAGE_DENOMINATOR, TARGET_PRICE_DENOMINATOR, allLogoFileNames, allLogoNames, calculateEthForExactNxm, calculateExactEthForNxm, calculateExactNxmForEth, calculateNxmForExactEth, calculatePremiumWithCommissionAndSlippage, calculatePriceImpactA, calculatePriceImpactB, calculateSpotPrice, nexusSdk as default, getQuoteAndBuyCoverInputs, productTypes, products, sumPoolCapacities };
|
|
38950
|
+
export { Address, ApiResponse, BuyCoverInput, BuyCoverParams, COMMISSION_DENOMINATOR, Capacity, CoverAsset, CoverId, CoverRouterProductCapacityResponse, CoverRouterQuoteResponse, DEFAULT_COMMISSION_RATIO, DEFAULT_SLIPPAGE, ErrorApiResponse, ErrorResponse, FloatString, GetQuoteApiResponse, GetQuoteResponse, IntString, Integer, LogoFileName, LogoName, MAXIMUM_COVER_PERIOD, MINIMUM_COVER_PERIOD, NEXUS_MUTUAL_DAO_TREASURY_ADDRESS, PoolAllocationRequest, PoolCapacity, Quote, QuoteDisplayInfo, Reserves, SLIPPAGE_DENOMINATOR, TARGET_PRICE_DENOMINATOR, allLogoFileNames, allLogoNames, calculateEthForExactNxm, calculateExactEthForNxm, calculateExactNxmForEth, calculateNxmForExactEth, calculatePremiumWithCommissionAndSlippage, calculatePriceImpactA, calculatePriceImpactB, calculateSpotPrice, nexusSdk as default, getQuoteAndBuyCoverInputs, productTypes, products, sumPoolCapacities };
|
package/dist/index.d.ts
CHANGED
|
@@ -71,9 +71,13 @@ type Address = string;
|
|
|
71
71
|
*/
|
|
72
72
|
type Integer = number;
|
|
73
73
|
/**
|
|
74
|
-
* Integer
|
|
74
|
+
* Integer value in string format
|
|
75
75
|
*/
|
|
76
76
|
type IntString = string;
|
|
77
|
+
/**
|
|
78
|
+
* Float value in string format
|
|
79
|
+
*/
|
|
80
|
+
type FloatString = string;
|
|
77
81
|
|
|
78
82
|
type BuyCoverParams = {
|
|
79
83
|
coverId: Integer;
|
|
@@ -97,6 +101,16 @@ type CoverRouterQuoteResponse = {
|
|
|
97
101
|
quote: Quote;
|
|
98
102
|
capacities: PoolCapacity[];
|
|
99
103
|
};
|
|
104
|
+
type CoverRouterProductCapacityResponse = {
|
|
105
|
+
productId: Integer;
|
|
106
|
+
availableCapacity: Array<{
|
|
107
|
+
assetId: Integer;
|
|
108
|
+
amount: IntString;
|
|
109
|
+
}>;
|
|
110
|
+
allocatedNxm: IntString;
|
|
111
|
+
minAnnualPrice: FloatString;
|
|
112
|
+
maxAnnualPrice: FloatString;
|
|
113
|
+
};
|
|
100
114
|
type Quote = {
|
|
101
115
|
totalCoverAmountInAsset: IntString;
|
|
102
116
|
annualPrice: IntString;
|
|
@@ -137,7 +151,7 @@ type GetQuoteApiResponse = ApiResponse<GetQuoteResponse, undefined>;
|
|
|
137
151
|
* @param {Integer} coverPeriod - The duration of the cover in days (28-365).
|
|
138
152
|
* @param {CoverAsset} coverAsset - The asset for which cover is being purchased (the cover must be purchased using the same asset)
|
|
139
153
|
* @param {Address} coverBuyerAddress - The Ethereum address of the buyer.
|
|
140
|
-
* @param {number} slippage - The acceptable slippage percentage. Must be between 0
|
|
154
|
+
* @param {number} slippage - The acceptable slippage percentage. Must be between 0-1 (Defaults to 0.001 ~ 0.1%)
|
|
141
155
|
* @param {string} ipfsCid - The IPFS CID for additional data (optional).
|
|
142
156
|
* @return {Promise<GetQuoteApiResponse | ErrorApiResponse>} Returns a successful quote response or an error response.
|
|
143
157
|
*/
|
|
@@ -1573,7 +1587,7 @@ var products = [
|
|
|
1573
1587
|
"DAI"
|
|
1574
1588
|
],
|
|
1575
1589
|
isPrivate: true,
|
|
1576
|
-
timestamp:
|
|
1590
|
+
timestamp: 1684312727
|
|
1577
1591
|
},
|
|
1578
1592
|
{
|
|
1579
1593
|
id: 84,
|
|
@@ -1638,7 +1652,7 @@ var products = [
|
|
|
1638
1652
|
"DAI"
|
|
1639
1653
|
],
|
|
1640
1654
|
isPrivate: true,
|
|
1641
|
-
timestamp:
|
|
1655
|
+
timestamp: 1684312727
|
|
1642
1656
|
},
|
|
1643
1657
|
{
|
|
1644
1658
|
id: 88,
|
|
@@ -1928,7 +1942,7 @@ var products = [
|
|
|
1928
1942
|
"DAI"
|
|
1929
1943
|
],
|
|
1930
1944
|
isPrivate: true,
|
|
1931
|
-
timestamp:
|
|
1945
|
+
timestamp: 1689782903
|
|
1932
1946
|
},
|
|
1933
1947
|
{
|
|
1934
1948
|
id: 106,
|
|
@@ -38933,4 +38947,4 @@ declare const nexusSdk: {
|
|
|
38933
38947
|
}];
|
|
38934
38948
|
};
|
|
38935
38949
|
|
|
38936
|
-
export { Address, ApiResponse, BuyCoverInput, BuyCoverParams, COMMISSION_DENOMINATOR, Capacity, CoverAsset, CoverId, CoverRouterQuoteResponse, DEFAULT_COMMISSION_RATIO, DEFAULT_SLIPPAGE, ErrorApiResponse, ErrorResponse, GetQuoteApiResponse, GetQuoteResponse, IntString, Integer, LogoFileName, LogoName, MAXIMUM_COVER_PERIOD, MINIMUM_COVER_PERIOD, NEXUS_MUTUAL_DAO_TREASURY_ADDRESS, PoolAllocationRequest, PoolCapacity, Quote, QuoteDisplayInfo, Reserves, SLIPPAGE_DENOMINATOR, TARGET_PRICE_DENOMINATOR, allLogoFileNames, allLogoNames, calculateEthForExactNxm, calculateExactEthForNxm, calculateExactNxmForEth, calculateNxmForExactEth, calculatePremiumWithCommissionAndSlippage, calculatePriceImpactA, calculatePriceImpactB, calculateSpotPrice, nexusSdk as default, getQuoteAndBuyCoverInputs, productTypes, products, sumPoolCapacities };
|
|
38950
|
+
export { Address, ApiResponse, BuyCoverInput, BuyCoverParams, COMMISSION_DENOMINATOR, Capacity, CoverAsset, CoverId, CoverRouterProductCapacityResponse, CoverRouterQuoteResponse, DEFAULT_COMMISSION_RATIO, DEFAULT_SLIPPAGE, ErrorApiResponse, ErrorResponse, FloatString, GetQuoteApiResponse, GetQuoteResponse, IntString, Integer, LogoFileName, LogoName, MAXIMUM_COVER_PERIOD, MINIMUM_COVER_PERIOD, NEXUS_MUTUAL_DAO_TREASURY_ADDRESS, PoolAllocationRequest, PoolCapacity, Quote, QuoteDisplayInfo, Reserves, SLIPPAGE_DENOMINATOR, TARGET_PRICE_DENOMINATOR, allLogoFileNames, allLogoNames, calculateEthForExactNxm, calculateExactEthForNxm, calculateExactNxmForEth, calculateNxmForExactEth, calculatePremiumWithCommissionAndSlippage, calculatePriceImpactA, calculatePriceImpactB, calculateSpotPrice, nexusSdk as default, getQuoteAndBuyCoverInputs, productTypes, products, sumPoolCapacities };
|
package/dist/index.js
CHANGED
|
@@ -1576,7 +1576,7 @@ var products_default = [
|
|
|
1576
1576
|
"DAI"
|
|
1577
1577
|
],
|
|
1578
1578
|
isPrivate: true,
|
|
1579
|
-
timestamp:
|
|
1579
|
+
timestamp: 1684312727
|
|
1580
1580
|
},
|
|
1581
1581
|
{
|
|
1582
1582
|
id: 84,
|
|
@@ -1638,7 +1638,7 @@ var products_default = [
|
|
|
1638
1638
|
"DAI"
|
|
1639
1639
|
],
|
|
1640
1640
|
isPrivate: true,
|
|
1641
|
-
timestamp:
|
|
1641
|
+
timestamp: 1684312727
|
|
1642
1642
|
},
|
|
1643
1643
|
{
|
|
1644
1644
|
id: 88,
|
|
@@ -1916,7 +1916,7 @@ var products_default = [
|
|
|
1916
1916
|
"DAI"
|
|
1917
1917
|
],
|
|
1918
1918
|
isPrivate: true,
|
|
1919
|
-
timestamp:
|
|
1919
|
+
timestamp: 1689782903
|
|
1920
1920
|
},
|
|
1921
1921
|
{
|
|
1922
1922
|
id: 106,
|
|
@@ -3416,7 +3416,7 @@ __export(quote_exports, {
|
|
|
3416
3416
|
var import_axios = __toESM(require("axios"));
|
|
3417
3417
|
var import_dotenv = __toESM(require_main());
|
|
3418
3418
|
import_dotenv.default.config();
|
|
3419
|
-
async function getQuoteAndBuyCoverInputs(productId, coverAmount, coverPeriod, coverAsset, coverBuyerAddress, slippage = DEFAULT_SLIPPAGE, ipfsCid = "") {
|
|
3419
|
+
async function getQuoteAndBuyCoverInputs(productId, coverAmount, coverPeriod, coverAsset, coverBuyerAddress, slippage = DEFAULT_SLIPPAGE / SLIPPAGE_DENOMINATOR, ipfsCid = "") {
|
|
3420
3420
|
if (!process.env.COVER_ROUTER_URL) {
|
|
3421
3421
|
return { result: void 0, error: { message: "Missing COVER_ROUTER_URL env var" } };
|
|
3422
3422
|
}
|
|
@@ -3446,15 +3446,16 @@ async function getQuoteAndBuyCoverInputs(productId, coverAmount, coverPeriod, co
|
|
|
3446
3446
|
if (!/^0x[a-fA-F0-9]{40}$/.test(coverBuyerAddress)) {
|
|
3447
3447
|
return { result: void 0, error: { message: "Invalid coverBuyerAddress: must be a valid Ethereum address" } };
|
|
3448
3448
|
}
|
|
3449
|
-
if (typeof slippage !== "number" || slippage < 0 || slippage >
|
|
3449
|
+
if (typeof slippage !== "number" || slippage < 0 || slippage > 1) {
|
|
3450
3450
|
return {
|
|
3451
3451
|
result: void 0,
|
|
3452
|
-
error: { message:
|
|
3452
|
+
error: { message: "Invalid slippage: must be a number between 0 and 1" }
|
|
3453
3453
|
};
|
|
3454
3454
|
}
|
|
3455
3455
|
if (typeof ipfsCid !== "string") {
|
|
3456
3456
|
return { result: void 0, error: { message: "Invalid ipfsCid: must be a valid IPFS CID" } };
|
|
3457
3457
|
}
|
|
3458
|
+
slippage = slippage * SLIPPAGE_DENOMINATOR;
|
|
3458
3459
|
try {
|
|
3459
3460
|
const { quote, capacities } = await getQuote(productId, coverAmount, coverPeriod, coverAsset);
|
|
3460
3461
|
const maxPremiumInAsset = calculatePremiumWithCommissionAndSlippage(
|
|
@@ -3494,14 +3495,27 @@ async function getQuoteAndBuyCoverInputs(productId, coverAmount, coverPeriod, co
|
|
|
3494
3495
|
};
|
|
3495
3496
|
return { result, error: void 0 };
|
|
3496
3497
|
} catch (error) {
|
|
3497
|
-
|
|
3498
|
+
const errorResponse = await handleError(error, productId, coverPeriod, coverAsset);
|
|
3499
|
+
return errorResponse;
|
|
3498
3500
|
}
|
|
3499
3501
|
}
|
|
3500
3502
|
async function getQuote(productId, coverAmount, coverPeriod, coverAsset) {
|
|
3501
3503
|
const params = { productId, amount: coverAmount, period: coverPeriod, coverAsset };
|
|
3502
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
|
+
}
|
|
3503
3508
|
return response.data;
|
|
3504
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
|
+
}
|
|
3505
3519
|
function sumPoolCapacities(capacities) {
|
|
3506
3520
|
let totalAmount = BigInt(0);
|
|
3507
3521
|
capacities.forEach((poolCapacity) => {
|
|
@@ -3509,23 +3523,23 @@ function sumPoolCapacities(capacities) {
|
|
|
3509
3523
|
});
|
|
3510
3524
|
return totalAmount.toString();
|
|
3511
3525
|
}
|
|
3512
|
-
async function handleError(error) {
|
|
3526
|
+
async function handleError(error, productId, coverPeriod, coverAsset) {
|
|
3513
3527
|
const axiosError = error;
|
|
3514
3528
|
if (axiosError.isAxiosError) {
|
|
3515
|
-
console.log("axiosError.response.data: ", require("util").inspect(axiosError.response?.data, { depth: null }));
|
|
3516
3529
|
if (axiosError.response?.data?.error?.includes("Not enough capacity")) {
|
|
3530
|
+
const maxCapacity = await getProductCapacity(productId, coverPeriod, coverAsset);
|
|
3517
3531
|
return {
|
|
3518
3532
|
result: void 0,
|
|
3519
3533
|
error: {
|
|
3520
3534
|
message: axiosError.response?.data.error,
|
|
3521
|
-
data: {}
|
|
3535
|
+
data: maxCapacity ? { maxCapacity } : void 0
|
|
3522
3536
|
}
|
|
3523
3537
|
};
|
|
3524
3538
|
}
|
|
3525
3539
|
}
|
|
3526
3540
|
return {
|
|
3527
3541
|
result: void 0,
|
|
3528
|
-
error: { message: "Something went wrong" }
|
|
3542
|
+
error: { message: error.message || "Something went wrong" }
|
|
3529
3543
|
};
|
|
3530
3544
|
}
|
|
3531
3545
|
|