@shapeshiftoss/swapper 9.2.0 → 9.2.3
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.
|
@@ -75,6 +75,11 @@ async function getCowSwapTradeQuote(deps, input) {
|
|
|
75
75
|
.div((0, bignumber_1.bn)(10).exponentiatedBy(sellAsset.precision))
|
|
76
76
|
.multipliedBy((0, bignumber_1.bnOrZero)(sellAssetUsdRate))
|
|
77
77
|
.toString();
|
|
78
|
+
// If original sellAmount is < minQuoteSellAmount, we don't want to replace it with normalizedSellAmount
|
|
79
|
+
// The purpose of this was to get a quote from CowSwap even with small amounts
|
|
80
|
+
const quoteSellAmount = (0, bignumber_1.bnOrZero)(sellAmount).lt(minQuoteSellAmount)
|
|
81
|
+
? sellAmount
|
|
82
|
+
: normalizedSellAmount;
|
|
78
83
|
return {
|
|
79
84
|
rate,
|
|
80
85
|
minimum,
|
|
@@ -90,7 +95,7 @@ async function getCowSwapTradeQuote(deps, input) {
|
|
|
90
95
|
},
|
|
91
96
|
tradeFee: tradeFeeFiat
|
|
92
97
|
},
|
|
93
|
-
sellAmount:
|
|
98
|
+
sellAmount: quoteSellAmount,
|
|
94
99
|
buyAmount: quote.buyAmount,
|
|
95
100
|
sources: constants_1.DEFAULT_SOURCE,
|
|
96
101
|
allowanceContract: constants_1.COW_SWAP_VAULT_RELAYER_ADDRESS,
|
|
@@ -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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shapeshiftoss/swapper",
|
|
3
|
-
"version": "9.2.
|
|
3
|
+
"version": "9.2.3",
|
|
4
4
|
"description": "An interface and implementations to trade coins via various protocols",
|
|
5
5
|
"repository": "https://github.com/shapeshift/lib",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,23 +30,23 @@
|
|
|
30
30
|
"web3": "1.7.4"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@shapeshiftoss/asset-service": "^7.
|
|
34
|
-
"@shapeshiftoss/caip": "^6.
|
|
35
|
-
"@shapeshiftoss/chain-adapters": "^7.
|
|
33
|
+
"@shapeshiftoss/asset-service": "^7.1.0",
|
|
34
|
+
"@shapeshiftoss/caip": "^6.7.0",
|
|
35
|
+
"@shapeshiftoss/chain-adapters": "^7.13.0",
|
|
36
36
|
"@shapeshiftoss/errors": "^1.1.2",
|
|
37
37
|
"@shapeshiftoss/hdwallet-core": "^1.27.0",
|
|
38
|
-
"@shapeshiftoss/types": "^8.
|
|
38
|
+
"@shapeshiftoss/types": "^8.1.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@shapeshiftoss/asset-service": "^7.
|
|
42
|
-
"@shapeshiftoss/caip": "^6.
|
|
43
|
-
"@shapeshiftoss/chain-adapters": "^7.
|
|
41
|
+
"@shapeshiftoss/asset-service": "^7.1.0",
|
|
42
|
+
"@shapeshiftoss/caip": "^6.7.0",
|
|
43
|
+
"@shapeshiftoss/chain-adapters": "^7.13.0",
|
|
44
44
|
"@shapeshiftoss/errors": "^1.1.2",
|
|
45
45
|
"@shapeshiftoss/hdwallet-core": "^1.27.0",
|
|
46
|
-
"@shapeshiftoss/types": "^8.
|
|
46
|
+
"@shapeshiftoss/types": "^8.1.0",
|
|
47
47
|
"@types/readline-sync": "^1.4.4",
|
|
48
48
|
"readline-sync": "^1.4.10",
|
|
49
49
|
"web3-utils": "1.7.4",
|
|
50
|
-
"@shapeshiftoss/unchained-client": "^9.0
|
|
50
|
+
"@shapeshiftoss/unchained-client": "^9.5.0"
|
|
51
51
|
}
|
|
52
52
|
}
|