@nexusmutual/sdk 0.3.1 → 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 +4 -4
- package/dist/index.d.mts +20 -6
- package/dist/index.d.ts +20 -6
- package/dist/index.js +22 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +22 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/data/products.json
CHANGED
|
@@ -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,
|
|
@@ -1439,7 +1439,7 @@
|
|
|
1439
1439
|
"DAI"
|
|
1440
1440
|
],
|
|
1441
1441
|
"isPrivate": true,
|
|
1442
|
-
"timestamp":
|
|
1442
|
+
"timestamp": 1684312727
|
|
1443
1443
|
},
|
|
1444
1444
|
{
|
|
1445
1445
|
"id": 89,
|
|
@@ -1683,7 +1683,7 @@
|
|
|
1683
1683
|
"DAI"
|
|
1684
1684
|
],
|
|
1685
1685
|
"isPrivate": true,
|
|
1686
|
-
"timestamp":
|
|
1686
|
+
"timestamp": 1689782903
|
|
1687
1687
|
},
|
|
1688
1688
|
{
|
|
1689
1689
|
"id": 105,
|
|
@@ -2165,7 +2165,7 @@
|
|
|
2165
2165
|
"ETH"
|
|
2166
2166
|
],
|
|
2167
2167
|
"isPrivate": false,
|
|
2168
|
-
"timestamp":
|
|
2168
|
+
"timestamp": 1709310707
|
|
2169
2169
|
},
|
|
2170
2170
|
{
|
|
2171
2171
|
"id": 137,
|
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;
|
|
@@ -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,
|
|
@@ -1655,7 +1669,7 @@ var products = [
|
|
|
1655
1669
|
"DAI"
|
|
1656
1670
|
],
|
|
1657
1671
|
isPrivate: true,
|
|
1658
|
-
timestamp:
|
|
1672
|
+
timestamp: 1684312727
|
|
1659
1673
|
},
|
|
1660
1674
|
{
|
|
1661
1675
|
id: 89,
|
|
@@ -1911,7 +1925,7 @@ var products = [
|
|
|
1911
1925
|
"DAI"
|
|
1912
1926
|
],
|
|
1913
1927
|
isPrivate: true,
|
|
1914
|
-
timestamp:
|
|
1928
|
+
timestamp: 1689782903
|
|
1915
1929
|
},
|
|
1916
1930
|
{
|
|
1917
1931
|
id: 105,
|
|
@@ -2422,7 +2436,7 @@ var products = [
|
|
|
2422
2436
|
"ETH"
|
|
2423
2437
|
],
|
|
2424
2438
|
isPrivate: false,
|
|
2425
|
-
timestamp:
|
|
2439
|
+
timestamp: 1709310707
|
|
2426
2440
|
},
|
|
2427
2441
|
{
|
|
2428
2442
|
id: 137,
|
|
@@ -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;
|
|
@@ -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,
|
|
@@ -1655,7 +1669,7 @@ var products = [
|
|
|
1655
1669
|
"DAI"
|
|
1656
1670
|
],
|
|
1657
1671
|
isPrivate: true,
|
|
1658
|
-
timestamp:
|
|
1672
|
+
timestamp: 1684312727
|
|
1659
1673
|
},
|
|
1660
1674
|
{
|
|
1661
1675
|
id: 89,
|
|
@@ -1911,7 +1925,7 @@ var products = [
|
|
|
1911
1925
|
"DAI"
|
|
1912
1926
|
],
|
|
1913
1927
|
isPrivate: true,
|
|
1914
|
-
timestamp:
|
|
1928
|
+
timestamp: 1689782903
|
|
1915
1929
|
},
|
|
1916
1930
|
{
|
|
1917
1931
|
id: 105,
|
|
@@ -2422,7 +2436,7 @@ var products = [
|
|
|
2422
2436
|
"ETH"
|
|
2423
2437
|
],
|
|
2424
2438
|
isPrivate: false,
|
|
2425
|
-
timestamp:
|
|
2439
|
+
timestamp: 1709310707
|
|
2426
2440
|
},
|
|
2427
2441
|
{
|
|
2428
2442
|
id: 137,
|
|
@@ -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
|
@@ -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,
|
|
@@ -1655,7 +1655,7 @@ var products_default = [
|
|
|
1655
1655
|
"DAI"
|
|
1656
1656
|
],
|
|
1657
1657
|
isPrivate: true,
|
|
1658
|
-
timestamp:
|
|
1658
|
+
timestamp: 1684312727
|
|
1659
1659
|
},
|
|
1660
1660
|
{
|
|
1661
1661
|
id: 89,
|
|
@@ -1899,7 +1899,7 @@ var products_default = [
|
|
|
1899
1899
|
"DAI"
|
|
1900
1900
|
],
|
|
1901
1901
|
isPrivate: true,
|
|
1902
|
-
timestamp:
|
|
1902
|
+
timestamp: 1689782903
|
|
1903
1903
|
},
|
|
1904
1904
|
{
|
|
1905
1905
|
id: 105,
|
|
@@ -2381,7 +2381,7 @@ var products_default = [
|
|
|
2381
2381
|
"ETH"
|
|
2382
2382
|
],
|
|
2383
2383
|
isPrivate: false,
|
|
2384
|
-
timestamp:
|
|
2384
|
+
timestamp: 1709310707
|
|
2385
2385
|
},
|
|
2386
2386
|
{
|
|
2387
2387
|
id: 137,
|
|
@@ -3495,14 +3495,27 @@ async function getQuoteAndBuyCoverInputs(productId, coverAmount, coverPeriod, co
|
|
|
3495
3495
|
};
|
|
3496
3496
|
return { result, error: void 0 };
|
|
3497
3497
|
} catch (error) {
|
|
3498
|
-
|
|
3498
|
+
const errorResponse = await handleError(error, productId, coverPeriod, coverAsset);
|
|
3499
|
+
return errorResponse;
|
|
3499
3500
|
}
|
|
3500
3501
|
}
|
|
3501
3502
|
async function getQuote(productId, coverAmount, coverPeriod, coverAsset) {
|
|
3502
3503
|
const params = { productId, amount: coverAmount, period: coverPeriod, coverAsset };
|
|
3503
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
|
+
}
|
|
3504
3508
|
return response.data;
|
|
3505
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
|
+
}
|
|
3506
3519
|
function sumPoolCapacities(capacities) {
|
|
3507
3520
|
let totalAmount = BigInt(0);
|
|
3508
3521
|
capacities.forEach((poolCapacity) => {
|
|
@@ -3510,23 +3523,23 @@ function sumPoolCapacities(capacities) {
|
|
|
3510
3523
|
});
|
|
3511
3524
|
return totalAmount.toString();
|
|
3512
3525
|
}
|
|
3513
|
-
async function handleError(error) {
|
|
3526
|
+
async function handleError(error, productId, coverPeriod, coverAsset) {
|
|
3514
3527
|
const axiosError = error;
|
|
3515
3528
|
if (axiosError.isAxiosError) {
|
|
3516
|
-
console.log("axiosError.response.data: ", require("util").inspect(axiosError.response?.data, { depth: null }));
|
|
3517
3529
|
if (axiosError.response?.data?.error?.includes("Not enough capacity")) {
|
|
3530
|
+
const maxCapacity = await getProductCapacity(productId, coverPeriod, coverAsset);
|
|
3518
3531
|
return {
|
|
3519
3532
|
result: void 0,
|
|
3520
3533
|
error: {
|
|
3521
3534
|
message: axiosError.response?.data.error,
|
|
3522
|
-
data: {}
|
|
3535
|
+
data: maxCapacity ? { maxCapacity } : void 0
|
|
3523
3536
|
}
|
|
3524
3537
|
};
|
|
3525
3538
|
}
|
|
3526
3539
|
}
|
|
3527
3540
|
return {
|
|
3528
3541
|
result: void 0,
|
|
3529
|
-
error: { message: "Something went wrong" }
|
|
3542
|
+
error: { message: error.message || "Something went wrong" }
|
|
3530
3543
|
};
|
|
3531
3544
|
}
|
|
3532
3545
|
|