@shapeshiftoss/swapper 9.2.1 → 9.2.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.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.estimateTradeFee = void 0;
|
|
4
|
+
const asset_service_1 = require("@shapeshiftoss/asset-service");
|
|
4
5
|
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
6
|
const api_1 = require("../../../../api");
|
|
6
7
|
const bignumber_1 = require("../../../utils/bignumber");
|
|
@@ -40,28 +41,35 @@ const estimateTradeFee = async (deps, buyAsset) => {
|
|
|
40
41
|
details: { thorPoolChainId }
|
|
41
42
|
});
|
|
42
43
|
const gasRate = inboundInfo.gas_rate;
|
|
43
|
-
const { chainId, assetNamespace } = (0, caip_1.fromAssetId)(buyAsset.assetId);
|
|
44
|
-
const
|
|
45
|
-
if (!
|
|
44
|
+
const { chainId: buyChainId, assetNamespace } = (0, caip_1.fromAssetId)(buyAsset.assetId);
|
|
45
|
+
const buyAdapter = deps.adapterManager.get(buyChainId);
|
|
46
|
+
if (!buyAdapter)
|
|
47
|
+
throw new api_1.SwapError('[estimateTradeFee] - unable to get buy asset adapter', {
|
|
48
|
+
code: api_1.SwapErrorTypes.VALIDATION_FAILED,
|
|
49
|
+
details: { buyChainId }
|
|
50
|
+
});
|
|
51
|
+
const buyFeeAssetId = buyAdapter.getFeeAssetId();
|
|
52
|
+
if (!buyFeeAssetId)
|
|
46
53
|
throw new api_1.SwapError('[estimateTradeFee] - no fee assetId', {
|
|
47
54
|
code: api_1.SwapErrorTypes.VALIDATION_FAILED,
|
|
48
55
|
details: { buyAssetId: buyAsset.assetId }
|
|
49
56
|
});
|
|
50
|
-
const feeAssetRatio = buyAsset.assetId !==
|
|
57
|
+
const feeAssetRatio = buyAsset.assetId !== buyFeeAssetId
|
|
51
58
|
? await (0, getPriceRatio_1.getPriceRatio)(deps, {
|
|
52
59
|
sellAssetId: buyAsset.assetId,
|
|
53
|
-
buyAssetId:
|
|
60
|
+
buyAssetId: buyFeeAssetId
|
|
54
61
|
})
|
|
55
62
|
: '1';
|
|
56
|
-
|
|
63
|
+
const buyFeeAsset = new asset_service_1.AssetService().getAll()[buyFeeAssetId];
|
|
64
|
+
switch (buyChainId) {
|
|
57
65
|
case 'bip122:000000000019d6689c085ae165831e93':
|
|
58
|
-
return (0, bignumber_1.fromBaseUnit)((0, bignumber_1.bnOrZero)(btcEstimate(gasRate)).times(feeAssetRatio).dp(0),
|
|
66
|
+
return (0, bignumber_1.fromBaseUnit)((0, bignumber_1.bnOrZero)(btcEstimate(gasRate)).times(feeAssetRatio).dp(0), buyFeeAsset.precision);
|
|
59
67
|
case 'eip155:1':
|
|
60
68
|
switch (assetNamespace) {
|
|
61
69
|
case 'slip44':
|
|
62
|
-
return (0, bignumber_1.fromBaseUnit)((0, bignumber_1.bnOrZero)(ethEstimate(gasRate)).times(feeAssetRatio).dp(0),
|
|
70
|
+
return (0, bignumber_1.fromBaseUnit)((0, bignumber_1.bnOrZero)(ethEstimate(gasRate)).times(feeAssetRatio).dp(0), buyFeeAsset.precision);
|
|
63
71
|
case 'erc20':
|
|
64
|
-
return (0, bignumber_1.fromBaseUnit)((0, bignumber_1.bnOrZero)(erc20Estimate(gasRate)).times(feeAssetRatio).dp(0),
|
|
72
|
+
return (0, bignumber_1.fromBaseUnit)((0, bignumber_1.bnOrZero)(erc20Estimate(gasRate)).times(feeAssetRatio).dp(0), buyFeeAsset.precision);
|
|
65
73
|
default:
|
|
66
74
|
throw new api_1.SwapError('[estimateTradeFee] - unsupported asset namespace', {
|
|
67
75
|
code: api_1.SwapErrorTypes.VALIDATION_FAILED,
|
|
@@ -71,7 +79,7 @@ const estimateTradeFee = async (deps, buyAsset) => {
|
|
|
71
79
|
default:
|
|
72
80
|
throw new api_1.SwapError('[estimateTradeFee] - unsupported chain id', {
|
|
73
81
|
code: api_1.SwapErrorTypes.VALIDATION_FAILED,
|
|
74
|
-
details: { chainId }
|
|
82
|
+
details: { chainId: buyChainId }
|
|
75
83
|
});
|
|
76
84
|
}
|
|
77
85
|
};
|
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.setupThorswapDeps = void 0;
|
|
7
|
+
const caip_1 = require("@shapeshiftoss/caip");
|
|
7
8
|
const chain_adapters_1 = require("@shapeshiftoss/chain-adapters");
|
|
8
9
|
const web3_1 = __importDefault(require("web3"));
|
|
9
10
|
jest.mock('web3');
|
|
@@ -22,6 +23,7 @@ const setupThorswapDeps = () => {
|
|
|
22
23
|
buildBIP44Params: jest.fn(() => ({ purpose: 44, coinType: 60, accountNumber: 0 })),
|
|
23
24
|
getAddress: jest.fn(() => Promise.resolve('0xthisIsMyAddress')),
|
|
24
25
|
getFeeData: jest.fn(() => feeData),
|
|
26
|
+
getFeeAssetId: jest.fn(() => caip_1.ethAssetId),
|
|
25
27
|
getGasFeeData: jest.fn(() => ({
|
|
26
28
|
[chain_adapters_1.FeeDataKey.Slow]: {
|
|
27
29
|
gasPrice: '1',
|
package/package.json
CHANGED