@xchainjs/xchain-thorchain-query 0.2.4 → 0.2.6
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/lib/index.esm.js +81 -19
- package/lib/index.js +81 -19
- package/lib/types.d.ts +2 -0
- package/package.json +3 -3
package/lib/index.esm.js
CHANGED
|
@@ -2208,7 +2208,17 @@ class ThorchainQuery {
|
|
|
2208
2208
|
estimateAddSaver(addAmount) {
|
|
2209
2209
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2210
2210
|
let errors = [];
|
|
2211
|
+
// check for errors before sending quote
|
|
2211
2212
|
errors = yield this.getAddSaversEstimateErrors(addAmount);
|
|
2213
|
+
// request param amount should always be in 1e8 which is why we pass in adjusted decimals if chain decimals != 8
|
|
2214
|
+
const newAddAmount = addAmount.baseAmount.decimal != 8 ? getBaseAmountWithDiffDecimals(addAmount, 8) : addAmount.baseAmount.amount();
|
|
2215
|
+
// Fetch quote
|
|
2216
|
+
const depositQuote = yield this.thorchainCache.thornode.getSaversDepositQuote(assetToString(addAmount.asset), newAddAmount.toNumber());
|
|
2217
|
+
// error handling
|
|
2218
|
+
const response = JSON.parse(JSON.stringify(depositQuote));
|
|
2219
|
+
if (response.error)
|
|
2220
|
+
errors.push(`Thornode request quote failed: ${response.error}`);
|
|
2221
|
+
// Return errors if there is any
|
|
2212
2222
|
if (errors.length > 0) {
|
|
2213
2223
|
return {
|
|
2214
2224
|
assetAmount: addAmount,
|
|
@@ -2228,29 +2238,27 @@ class ThorchainQuery {
|
|
|
2228
2238
|
errors,
|
|
2229
2239
|
};
|
|
2230
2240
|
}
|
|
2231
|
-
// request param amount should always be in 1e8 which is why we pass in adjusted decimals if chain decimals != 8
|
|
2232
|
-
const newAddAmount = addAmount.baseAmount.decimal != 8 ? getBaseAmountWithDiffDecimals(addAmount, 8) : addAmount.baseAmount.amount();
|
|
2233
|
-
const depositQuote = yield this.thorchainCache.thornode.getSaversDepositQuote(assetToString(addAmount.asset), newAddAmount.toNumber());
|
|
2234
2241
|
// Calculate transaction expiry time of the vault address
|
|
2235
2242
|
const currentDatetime = new Date();
|
|
2236
2243
|
const minutesToAdd = 15;
|
|
2237
2244
|
const expiryDatetime = new Date(currentDatetime.getTime() + minutesToAdd * 60000);
|
|
2245
|
+
// Calculate seconds
|
|
2238
2246
|
const estimatedWait = depositQuote.inbound_confirmation_seconds
|
|
2239
2247
|
? depositQuote.inbound_confirmation_seconds
|
|
2240
2248
|
: yield this.confCounting(addAmount);
|
|
2241
2249
|
const pool = (yield this.thorchainCache.getPoolForAsset(addAmount.asset)).pool;
|
|
2242
|
-
|
|
2243
|
-
errors.push(`Amount being added to savers can't pay for fees`);
|
|
2250
|
+
// Organise fees
|
|
2244
2251
|
const saverFees = {
|
|
2245
2252
|
affiliate: new CryptoAmount(baseAmount(depositQuote.fees.affiliate), addAmount.asset),
|
|
2246
2253
|
asset: assetFromStringEx(depositQuote.fees.asset),
|
|
2247
2254
|
outbound: new CryptoAmount(baseAmount(depositQuote.fees.outbound), addAmount.asset),
|
|
2248
2255
|
};
|
|
2256
|
+
// define savers cap
|
|
2249
2257
|
const saverCap = 0.3 * +pool.assetDepth;
|
|
2250
2258
|
const saverCapFilledPercent = (+pool.saversDepth / saverCap) * 100;
|
|
2251
2259
|
const estimateAddSaver = {
|
|
2252
2260
|
assetAmount: new CryptoAmount(baseAmount(depositQuote.expected_amount_out), addAmount.asset),
|
|
2253
|
-
estimatedDepositValue: new CryptoAmount(baseAmount(depositQuote.
|
|
2261
|
+
estimatedDepositValue: new CryptoAmount(baseAmount(depositQuote.expected_amount_deposit), addAmount.asset),
|
|
2254
2262
|
fee: saverFees,
|
|
2255
2263
|
expiry: expiryDatetime,
|
|
2256
2264
|
toAddress: depositQuote.inbound_address,
|
|
@@ -2271,12 +2279,56 @@ class ThorchainQuery {
|
|
|
2271
2279
|
*/
|
|
2272
2280
|
estimateWithdrawSaver(withdrawParams) {
|
|
2273
2281
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2282
|
+
const errors = [];
|
|
2283
|
+
// return error if Asset in is incorrect
|
|
2274
2284
|
if (isAssetRuneNative(withdrawParams.asset) || withdrawParams.asset.synth)
|
|
2275
|
-
|
|
2285
|
+
errors.push(`Native Rune and synth assets are not supported only L1's`);
|
|
2286
|
+
const inboundDetails = yield this.thorchainCache.getInboundDetails();
|
|
2287
|
+
// Check to see if there is a position before calling withdraw quote
|
|
2288
|
+
const checkPositon = yield this.getSaverPosition(withdrawParams);
|
|
2289
|
+
if (checkPositon.errors.length > 0) {
|
|
2290
|
+
for (let i = 0; i < checkPositon.errors.length; i++) {
|
|
2291
|
+
errors.push(checkPositon.errors[i]);
|
|
2292
|
+
}
|
|
2293
|
+
return {
|
|
2294
|
+
expectedAssetAmount: new CryptoAmount(assetToBase(assetAmount(checkPositon.redeemableValue.assetAmount.amount())), withdrawParams.asset),
|
|
2295
|
+
fee: {
|
|
2296
|
+
affiliate: new CryptoAmount(assetToBase(assetAmount(0)), withdrawParams.asset),
|
|
2297
|
+
asset: withdrawParams.asset,
|
|
2298
|
+
outbound: new CryptoAmount(assetToBase(assetAmount(calcOutboundFee(withdrawParams.asset, inboundDetails[withdrawParams.asset.chain]).assetAmount.amount())), withdrawParams.asset),
|
|
2299
|
+
},
|
|
2300
|
+
expiry: new Date(0),
|
|
2301
|
+
toAddress: '',
|
|
2302
|
+
memo: '',
|
|
2303
|
+
estimatedWaitTime: -1,
|
|
2304
|
+
slipBasisPoints: -1,
|
|
2305
|
+
dustAmount: new CryptoAmount(baseAmount(0), withdrawParams.asset),
|
|
2306
|
+
errors,
|
|
2307
|
+
};
|
|
2308
|
+
}
|
|
2309
|
+
// Request withdraw quote
|
|
2276
2310
|
const withdrawQuote = yield this.thorchainCache.thornode.getSaversWithdrawQuote(withdrawParams);
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2311
|
+
// error handling
|
|
2312
|
+
const response = JSON.parse(JSON.stringify(withdrawQuote));
|
|
2313
|
+
if (response.error)
|
|
2314
|
+
errors.push(`Thornode request quote failed: ${response.error}`);
|
|
2315
|
+
if (errors.length > 0) {
|
|
2316
|
+
return {
|
|
2317
|
+
expectedAssetAmount: new CryptoAmount(assetToBase(assetAmount(0)), withdrawParams.asset),
|
|
2318
|
+
fee: {
|
|
2319
|
+
affiliate: new CryptoAmount(assetToBase(assetAmount(0)), withdrawParams.asset),
|
|
2320
|
+
asset: withdrawParams.asset,
|
|
2321
|
+
outbound: new CryptoAmount(assetToBase(assetAmount(0)), withdrawParams.asset),
|
|
2322
|
+
},
|
|
2323
|
+
expiry: new Date(0),
|
|
2324
|
+
toAddress: '',
|
|
2325
|
+
memo: '',
|
|
2326
|
+
estimatedWaitTime: -1,
|
|
2327
|
+
slipBasisPoints: -1,
|
|
2328
|
+
dustAmount: new CryptoAmount(baseAmount(0), withdrawParams.asset),
|
|
2329
|
+
errors,
|
|
2330
|
+
};
|
|
2331
|
+
}
|
|
2280
2332
|
// Calculate transaction expiry time of the vault address
|
|
2281
2333
|
const currentDatetime = new Date();
|
|
2282
2334
|
const minutesToAdd = 15;
|
|
@@ -2296,6 +2348,7 @@ class ThorchainQuery {
|
|
|
2296
2348
|
estimatedWaitTime: estimatedWait,
|
|
2297
2349
|
slipBasisPoints: withdrawQuote.slippage_bps,
|
|
2298
2350
|
dustAmount: new CryptoAmount(baseAmount(withdrawQuote.dust_amount), withdrawParams.asset),
|
|
2351
|
+
errors,
|
|
2299
2352
|
};
|
|
2300
2353
|
return estimateWithdrawSaver;
|
|
2301
2354
|
});
|
|
@@ -2307,31 +2360,37 @@ class ThorchainQuery {
|
|
|
2307
2360
|
*/
|
|
2308
2361
|
getSaverPosition(params) {
|
|
2309
2362
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2363
|
+
const errors = [];
|
|
2364
|
+
const inboundDetails = yield this.thorchainCache.getInboundDetails();
|
|
2310
2365
|
const blockData = (yield this.thorchainCache.thornode.getLastBlock()).find((item) => item.chain === params.asset.chain);
|
|
2311
2366
|
const savers = (yield this.thorchainCache.thornode.getSavers(`${params.asset.chain}.${params.asset.ticker}`)).find((item) => item.asset_address === params.address);
|
|
2312
2367
|
const pool = (yield this.thorchainCache.getPoolForAsset(params.asset)).pool;
|
|
2313
2368
|
if (!savers)
|
|
2314
|
-
|
|
2315
|
-
if (!savers.last_add_height)
|
|
2316
|
-
|
|
2369
|
+
errors.push(`Could not find position for ${params.address}`);
|
|
2370
|
+
if (!(savers === null || savers === void 0 ? void 0 : savers.last_add_height))
|
|
2371
|
+
errors.push(`Could not find position for ${params.address}`);
|
|
2317
2372
|
if (!(blockData === null || blockData === void 0 ? void 0 : blockData.thorchain))
|
|
2318
|
-
|
|
2319
|
-
const
|
|
2320
|
-
|
|
2373
|
+
errors.push(`Could not get thorchain block height`);
|
|
2374
|
+
const outboundFee = yield calcOutboundFee(params.asset, inboundDetails[params.asset.chain]);
|
|
2375
|
+
if (Number(savers === null || savers === void 0 ? void 0 : savers.asset_redeem_value) < outboundFee.baseAmount.amount().toNumber())
|
|
2376
|
+
errors.push(`Unlikely to withdraw balance as outbound fee is greater than redeemable amount`);
|
|
2377
|
+
const ownerUnits = Number(savers === null || savers === void 0 ? void 0 : savers.units);
|
|
2378
|
+
const lastAdded = Number(savers === null || savers === void 0 ? void 0 : savers.last_add_height);
|
|
2321
2379
|
const saverUnits = Number(pool.saversUnits);
|
|
2322
2380
|
const assetDepth = Number(pool.saversDepth);
|
|
2323
2381
|
const redeemableValue = (ownerUnits / saverUnits) * assetDepth;
|
|
2324
|
-
const depositAmount = new CryptoAmount(baseAmount(savers.asset_deposit_value), params.asset);
|
|
2382
|
+
const depositAmount = new CryptoAmount(baseAmount(savers === null || savers === void 0 ? void 0 : savers.asset_deposit_value), params.asset);
|
|
2325
2383
|
const redeemableAssetAmount = new CryptoAmount(baseAmount(redeemableValue), params.asset);
|
|
2326
|
-
const saversAge = ((blockData === null || blockData === void 0 ? void 0 : blockData.thorchain) - lastAdded) / ((365 * 86400) / 6);
|
|
2384
|
+
const saversAge = (Number(blockData === null || blockData === void 0 ? void 0 : blockData.thorchain) - lastAdded) / ((365 * 86400) / 6);
|
|
2327
2385
|
const saverGrowth = redeemableAssetAmount.minus(depositAmount).div(depositAmount).times(100);
|
|
2328
2386
|
const saversPos = {
|
|
2329
2387
|
depositValue: depositAmount,
|
|
2330
2388
|
redeemableValue: redeemableAssetAmount,
|
|
2331
|
-
lastAddHeight: savers.last_add_height,
|
|
2389
|
+
lastAddHeight: Number(savers === null || savers === void 0 ? void 0 : savers.last_add_height),
|
|
2332
2390
|
percentageGrowth: saverGrowth.assetAmount.amount().toNumber(),
|
|
2333
2391
|
ageInYears: saversAge,
|
|
2334
2392
|
ageInDays: saversAge * 365,
|
|
2393
|
+
errors,
|
|
2335
2394
|
};
|
|
2336
2395
|
return saversPos;
|
|
2337
2396
|
});
|
|
@@ -2350,6 +2409,9 @@ class ThorchainQuery {
|
|
|
2350
2409
|
const pool = (yield this.thorchainCache.getPoolForAsset(addAmount.asset)).pool;
|
|
2351
2410
|
if (pool.status.toLowerCase() !== 'available')
|
|
2352
2411
|
errors.push(`Pool is not available for this asset ${assetToString(addAmount.asset)}`);
|
|
2412
|
+
const inboundFee = calcNetworkFee(addAmount.asset, inboundDetails[addAmount.asset.chain]);
|
|
2413
|
+
if (addAmount.lte(inboundFee))
|
|
2414
|
+
errors.push(`Add amount does not cover fees`);
|
|
2353
2415
|
return errors;
|
|
2354
2416
|
});
|
|
2355
2417
|
}
|
package/lib/index.js
CHANGED
|
@@ -2217,7 +2217,17 @@ class ThorchainQuery {
|
|
|
2217
2217
|
estimateAddSaver(addAmount) {
|
|
2218
2218
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2219
2219
|
let errors = [];
|
|
2220
|
+
// check for errors before sending quote
|
|
2220
2221
|
errors = yield this.getAddSaversEstimateErrors(addAmount);
|
|
2222
|
+
// request param amount should always be in 1e8 which is why we pass in adjusted decimals if chain decimals != 8
|
|
2223
|
+
const newAddAmount = addAmount.baseAmount.decimal != 8 ? getBaseAmountWithDiffDecimals(addAmount, 8) : addAmount.baseAmount.amount();
|
|
2224
|
+
// Fetch quote
|
|
2225
|
+
const depositQuote = yield this.thorchainCache.thornode.getSaversDepositQuote(xchainUtil.assetToString(addAmount.asset), newAddAmount.toNumber());
|
|
2226
|
+
// error handling
|
|
2227
|
+
const response = JSON.parse(JSON.stringify(depositQuote));
|
|
2228
|
+
if (response.error)
|
|
2229
|
+
errors.push(`Thornode request quote failed: ${response.error}`);
|
|
2230
|
+
// Return errors if there is any
|
|
2221
2231
|
if (errors.length > 0) {
|
|
2222
2232
|
return {
|
|
2223
2233
|
assetAmount: addAmount,
|
|
@@ -2237,29 +2247,27 @@ class ThorchainQuery {
|
|
|
2237
2247
|
errors,
|
|
2238
2248
|
};
|
|
2239
2249
|
}
|
|
2240
|
-
// request param amount should always be in 1e8 which is why we pass in adjusted decimals if chain decimals != 8
|
|
2241
|
-
const newAddAmount = addAmount.baseAmount.decimal != 8 ? getBaseAmountWithDiffDecimals(addAmount, 8) : addAmount.baseAmount.amount();
|
|
2242
|
-
const depositQuote = yield this.thorchainCache.thornode.getSaversDepositQuote(xchainUtil.assetToString(addAmount.asset), newAddAmount.toNumber());
|
|
2243
2250
|
// Calculate transaction expiry time of the vault address
|
|
2244
2251
|
const currentDatetime = new Date();
|
|
2245
2252
|
const minutesToAdd = 15;
|
|
2246
2253
|
const expiryDatetime = new Date(currentDatetime.getTime() + minutesToAdd * 60000);
|
|
2254
|
+
// Calculate seconds
|
|
2247
2255
|
const estimatedWait = depositQuote.inbound_confirmation_seconds
|
|
2248
2256
|
? depositQuote.inbound_confirmation_seconds
|
|
2249
2257
|
: yield this.confCounting(addAmount);
|
|
2250
2258
|
const pool = (yield this.thorchainCache.getPoolForAsset(addAmount.asset)).pool;
|
|
2251
|
-
|
|
2252
|
-
errors.push(`Amount being added to savers can't pay for fees`);
|
|
2259
|
+
// Organise fees
|
|
2253
2260
|
const saverFees = {
|
|
2254
2261
|
affiliate: new CryptoAmount(xchainUtil.baseAmount(depositQuote.fees.affiliate), addAmount.asset),
|
|
2255
2262
|
asset: xchainUtil.assetFromStringEx(depositQuote.fees.asset),
|
|
2256
2263
|
outbound: new CryptoAmount(xchainUtil.baseAmount(depositQuote.fees.outbound), addAmount.asset),
|
|
2257
2264
|
};
|
|
2265
|
+
// define savers cap
|
|
2258
2266
|
const saverCap = 0.3 * +pool.assetDepth;
|
|
2259
2267
|
const saverCapFilledPercent = (+pool.saversDepth / saverCap) * 100;
|
|
2260
2268
|
const estimateAddSaver = {
|
|
2261
2269
|
assetAmount: new CryptoAmount(xchainUtil.baseAmount(depositQuote.expected_amount_out), addAmount.asset),
|
|
2262
|
-
estimatedDepositValue: new CryptoAmount(xchainUtil.baseAmount(depositQuote.
|
|
2270
|
+
estimatedDepositValue: new CryptoAmount(xchainUtil.baseAmount(depositQuote.expected_amount_deposit), addAmount.asset),
|
|
2263
2271
|
fee: saverFees,
|
|
2264
2272
|
expiry: expiryDatetime,
|
|
2265
2273
|
toAddress: depositQuote.inbound_address,
|
|
@@ -2280,12 +2288,56 @@ class ThorchainQuery {
|
|
|
2280
2288
|
*/
|
|
2281
2289
|
estimateWithdrawSaver(withdrawParams) {
|
|
2282
2290
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2291
|
+
const errors = [];
|
|
2292
|
+
// return error if Asset in is incorrect
|
|
2283
2293
|
if (isAssetRuneNative(withdrawParams.asset) || withdrawParams.asset.synth)
|
|
2284
|
-
|
|
2294
|
+
errors.push(`Native Rune and synth assets are not supported only L1's`);
|
|
2295
|
+
const inboundDetails = yield this.thorchainCache.getInboundDetails();
|
|
2296
|
+
// Check to see if there is a position before calling withdraw quote
|
|
2297
|
+
const checkPositon = yield this.getSaverPosition(withdrawParams);
|
|
2298
|
+
if (checkPositon.errors.length > 0) {
|
|
2299
|
+
for (let i = 0; i < checkPositon.errors.length; i++) {
|
|
2300
|
+
errors.push(checkPositon.errors[i]);
|
|
2301
|
+
}
|
|
2302
|
+
return {
|
|
2303
|
+
expectedAssetAmount: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(checkPositon.redeemableValue.assetAmount.amount())), withdrawParams.asset),
|
|
2304
|
+
fee: {
|
|
2305
|
+
affiliate: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), withdrawParams.asset),
|
|
2306
|
+
asset: withdrawParams.asset,
|
|
2307
|
+
outbound: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(calcOutboundFee(withdrawParams.asset, inboundDetails[withdrawParams.asset.chain]).assetAmount.amount())), withdrawParams.asset),
|
|
2308
|
+
},
|
|
2309
|
+
expiry: new Date(0),
|
|
2310
|
+
toAddress: '',
|
|
2311
|
+
memo: '',
|
|
2312
|
+
estimatedWaitTime: -1,
|
|
2313
|
+
slipBasisPoints: -1,
|
|
2314
|
+
dustAmount: new CryptoAmount(xchainUtil.baseAmount(0), withdrawParams.asset),
|
|
2315
|
+
errors,
|
|
2316
|
+
};
|
|
2317
|
+
}
|
|
2318
|
+
// Request withdraw quote
|
|
2285
2319
|
const withdrawQuote = yield this.thorchainCache.thornode.getSaversWithdrawQuote(withdrawParams);
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2320
|
+
// error handling
|
|
2321
|
+
const response = JSON.parse(JSON.stringify(withdrawQuote));
|
|
2322
|
+
if (response.error)
|
|
2323
|
+
errors.push(`Thornode request quote failed: ${response.error}`);
|
|
2324
|
+
if (errors.length > 0) {
|
|
2325
|
+
return {
|
|
2326
|
+
expectedAssetAmount: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), withdrawParams.asset),
|
|
2327
|
+
fee: {
|
|
2328
|
+
affiliate: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), withdrawParams.asset),
|
|
2329
|
+
asset: withdrawParams.asset,
|
|
2330
|
+
outbound: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), withdrawParams.asset),
|
|
2331
|
+
},
|
|
2332
|
+
expiry: new Date(0),
|
|
2333
|
+
toAddress: '',
|
|
2334
|
+
memo: '',
|
|
2335
|
+
estimatedWaitTime: -1,
|
|
2336
|
+
slipBasisPoints: -1,
|
|
2337
|
+
dustAmount: new CryptoAmount(xchainUtil.baseAmount(0), withdrawParams.asset),
|
|
2338
|
+
errors,
|
|
2339
|
+
};
|
|
2340
|
+
}
|
|
2289
2341
|
// Calculate transaction expiry time of the vault address
|
|
2290
2342
|
const currentDatetime = new Date();
|
|
2291
2343
|
const minutesToAdd = 15;
|
|
@@ -2305,6 +2357,7 @@ class ThorchainQuery {
|
|
|
2305
2357
|
estimatedWaitTime: estimatedWait,
|
|
2306
2358
|
slipBasisPoints: withdrawQuote.slippage_bps,
|
|
2307
2359
|
dustAmount: new CryptoAmount(xchainUtil.baseAmount(withdrawQuote.dust_amount), withdrawParams.asset),
|
|
2360
|
+
errors,
|
|
2308
2361
|
};
|
|
2309
2362
|
return estimateWithdrawSaver;
|
|
2310
2363
|
});
|
|
@@ -2316,31 +2369,37 @@ class ThorchainQuery {
|
|
|
2316
2369
|
*/
|
|
2317
2370
|
getSaverPosition(params) {
|
|
2318
2371
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2372
|
+
const errors = [];
|
|
2373
|
+
const inboundDetails = yield this.thorchainCache.getInboundDetails();
|
|
2319
2374
|
const blockData = (yield this.thorchainCache.thornode.getLastBlock()).find((item) => item.chain === params.asset.chain);
|
|
2320
2375
|
const savers = (yield this.thorchainCache.thornode.getSavers(`${params.asset.chain}.${params.asset.ticker}`)).find((item) => item.asset_address === params.address);
|
|
2321
2376
|
const pool = (yield this.thorchainCache.getPoolForAsset(params.asset)).pool;
|
|
2322
2377
|
if (!savers)
|
|
2323
|
-
|
|
2324
|
-
if (!savers.last_add_height)
|
|
2325
|
-
|
|
2378
|
+
errors.push(`Could not find position for ${params.address}`);
|
|
2379
|
+
if (!(savers === null || savers === void 0 ? void 0 : savers.last_add_height))
|
|
2380
|
+
errors.push(`Could not find position for ${params.address}`);
|
|
2326
2381
|
if (!(blockData === null || blockData === void 0 ? void 0 : blockData.thorchain))
|
|
2327
|
-
|
|
2328
|
-
const
|
|
2329
|
-
|
|
2382
|
+
errors.push(`Could not get thorchain block height`);
|
|
2383
|
+
const outboundFee = yield calcOutboundFee(params.asset, inboundDetails[params.asset.chain]);
|
|
2384
|
+
if (Number(savers === null || savers === void 0 ? void 0 : savers.asset_redeem_value) < outboundFee.baseAmount.amount().toNumber())
|
|
2385
|
+
errors.push(`Unlikely to withdraw balance as outbound fee is greater than redeemable amount`);
|
|
2386
|
+
const ownerUnits = Number(savers === null || savers === void 0 ? void 0 : savers.units);
|
|
2387
|
+
const lastAdded = Number(savers === null || savers === void 0 ? void 0 : savers.last_add_height);
|
|
2330
2388
|
const saverUnits = Number(pool.saversUnits);
|
|
2331
2389
|
const assetDepth = Number(pool.saversDepth);
|
|
2332
2390
|
const redeemableValue = (ownerUnits / saverUnits) * assetDepth;
|
|
2333
|
-
const depositAmount = new CryptoAmount(xchainUtil.baseAmount(savers.asset_deposit_value), params.asset);
|
|
2391
|
+
const depositAmount = new CryptoAmount(xchainUtil.baseAmount(savers === null || savers === void 0 ? void 0 : savers.asset_deposit_value), params.asset);
|
|
2334
2392
|
const redeemableAssetAmount = new CryptoAmount(xchainUtil.baseAmount(redeemableValue), params.asset);
|
|
2335
|
-
const saversAge = ((blockData === null || blockData === void 0 ? void 0 : blockData.thorchain) - lastAdded) / ((365 * 86400) / 6);
|
|
2393
|
+
const saversAge = (Number(blockData === null || blockData === void 0 ? void 0 : blockData.thorchain) - lastAdded) / ((365 * 86400) / 6);
|
|
2336
2394
|
const saverGrowth = redeemableAssetAmount.minus(depositAmount).div(depositAmount).times(100);
|
|
2337
2395
|
const saversPos = {
|
|
2338
2396
|
depositValue: depositAmount,
|
|
2339
2397
|
redeemableValue: redeemableAssetAmount,
|
|
2340
|
-
lastAddHeight: savers.last_add_height,
|
|
2398
|
+
lastAddHeight: Number(savers === null || savers === void 0 ? void 0 : savers.last_add_height),
|
|
2341
2399
|
percentageGrowth: saverGrowth.assetAmount.amount().toNumber(),
|
|
2342
2400
|
ageInYears: saversAge,
|
|
2343
2401
|
ageInDays: saversAge * 365,
|
|
2402
|
+
errors,
|
|
2344
2403
|
};
|
|
2345
2404
|
return saversPos;
|
|
2346
2405
|
});
|
|
@@ -2359,6 +2418,9 @@ class ThorchainQuery {
|
|
|
2359
2418
|
const pool = (yield this.thorchainCache.getPoolForAsset(addAmount.asset)).pool;
|
|
2360
2419
|
if (pool.status.toLowerCase() !== 'available')
|
|
2361
2420
|
errors.push(`Pool is not available for this asset ${xchainUtil.assetToString(addAmount.asset)}`);
|
|
2421
|
+
const inboundFee = calcNetworkFee(addAmount.asset, inboundDetails[addAmount.asset.chain]);
|
|
2422
|
+
if (addAmount.lte(inboundFee))
|
|
2423
|
+
errors.push(`Add amount does not cover fees`);
|
|
2362
2424
|
return errors;
|
|
2363
2425
|
});
|
|
2364
2426
|
}
|
package/lib/types.d.ts
CHANGED
|
@@ -204,6 +204,7 @@ export declare type EstimateWithdrawSaver = {
|
|
|
204
204
|
estimatedWaitTime: number;
|
|
205
205
|
slipBasisPoints: number;
|
|
206
206
|
dustAmount: CryptoAmount;
|
|
207
|
+
errors: string[];
|
|
207
208
|
};
|
|
208
209
|
export declare type SaverFees = {
|
|
209
210
|
affiliate: CryptoAmount;
|
|
@@ -217,6 +218,7 @@ export declare type SaversPosition = {
|
|
|
217
218
|
percentageGrowth: number;
|
|
218
219
|
ageInYears: number;
|
|
219
220
|
ageInDays: number;
|
|
221
|
+
errors: string[];
|
|
220
222
|
};
|
|
221
223
|
export declare type SaversWithdraw = {
|
|
222
224
|
height?: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xchainjs/xchain-thorchain-query",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Thorchain query module that is resposible for estimating swap calculations and add/remove liquidity for thorchain ",
|
|
6
6
|
"keywords": [
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@xchainjs/xchain-client": "^0.13.7",
|
|
37
37
|
"@xchainjs/xchain-midgard": "^0.4.3",
|
|
38
|
-
"@xchainjs/xchain-thornode": "^0.2.
|
|
38
|
+
"@xchainjs/xchain-thornode": "^0.2.3",
|
|
39
39
|
"@xchainjs/xchain-util": "^0.12.0",
|
|
40
40
|
"axios": "^0.25.0",
|
|
41
41
|
"axios-retry": "^3.2.5",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"@xchainjs/xchain-client": "^0.13.7",
|
|
47
47
|
"@xchainjs/xchain-midgard": "^0.4.3",
|
|
48
|
-
"@xchainjs/xchain-thornode": "^0.2.
|
|
48
|
+
"@xchainjs/xchain-thornode": "^0.2.3",
|
|
49
49
|
"@xchainjs/xchain-util": "^0.12.0",
|
|
50
50
|
"axios": "^0.25.0",
|
|
51
51
|
"axios-retry": "^3.2.5",
|