@shapeshiftoss/swapper 3.0.2 → 3.0.5
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/api.d.ts +0 -4
- package/dist/swappers/test/TestSwapper.d.ts +0 -1
- package/dist/swappers/test/TestSwapper.js +0 -3
- package/dist/swappers/thorchain/ThorchainSwapper.d.ts +0 -1
- package/dist/swappers/thorchain/ThorchainSwapper.js +0 -3
- package/dist/swappers/zrx/ZrxBuildQuoteTx/ZrxBuildQuoteTx.js +6 -13
- package/dist/swappers/zrx/ZrxSwapper.d.ts +0 -1
- package/dist/swappers/zrx/ZrxSwapper.js +0 -5
- package/dist/swappers/zrx/getZrxMinMax/getZrxMinMax.js +1 -1
- package/dist/swappers/zrx/getZrxQuote/getZrxQuote.js +9 -25
- package/package.json +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -32,10 +32,6 @@ export interface Swapper {
|
|
|
32
32
|
* Get the usd rate from either the assets symbol or tokenId
|
|
33
33
|
*/
|
|
34
34
|
getUsdRate(input: Pick<Asset, 'symbol' | 'tokenId'>): Promise<string>;
|
|
35
|
-
/**
|
|
36
|
-
* Get the default pair of the swapper
|
|
37
|
-
*/
|
|
38
|
-
getDefaultPair(): [CAIP19, CAIP19];
|
|
39
35
|
/**
|
|
40
36
|
* Get the minimum and maximum trade value of the sellAsset and buyAsset
|
|
41
37
|
*/
|
|
@@ -14,7 +14,6 @@ export declare class TestSwapper implements Swapper {
|
|
|
14
14
|
getUsdRate(input: Pick<Asset, 'symbol' | 'tokenId'>): Promise<string>;
|
|
15
15
|
getMinMax(input: GetQuoteInput): Promise<MinMaxOutput>;
|
|
16
16
|
executeQuote(): Promise<ExecQuoteOutput>;
|
|
17
|
-
getDefaultPair(): [CAIP19, CAIP19];
|
|
18
17
|
approvalNeeded(): Promise<ApprovalNeededOutput>;
|
|
19
18
|
approveInfinite(): Promise<string>;
|
|
20
19
|
filterBuyAssetsBySellAssetId(args: BuyAssetBySellIdInput): CAIP19[];
|
|
@@ -34,9 +34,6 @@ class TestSwapper {
|
|
|
34
34
|
async executeQuote() {
|
|
35
35
|
throw new Error('TestSwapper: executeQuote unimplemented');
|
|
36
36
|
}
|
|
37
|
-
getDefaultPair() {
|
|
38
|
-
throw new Error('TestSwapper: getDefaultPair unimplemented');
|
|
39
|
-
}
|
|
40
37
|
async approvalNeeded() {
|
|
41
38
|
throw new Error('TestSwapper: approvalNeeded unimplemented');
|
|
42
39
|
}
|
|
@@ -8,7 +8,6 @@ export declare class ThorchainSwapper implements Swapper {
|
|
|
8
8
|
getUsdRate(input: Pick<Asset, 'symbol' | 'tokenId'>): Promise<string>;
|
|
9
9
|
getMinMax(input: GetQuoteInput): Promise<MinMaxOutput>;
|
|
10
10
|
executeQuote(): Promise<ExecQuoteOutput>;
|
|
11
|
-
getDefaultPair(): [CAIP19, CAIP19];
|
|
12
11
|
approvalNeeded(): Promise<ApprovalNeededOutput>;
|
|
13
12
|
approveInfinite(): Promise<string>;
|
|
14
13
|
filterBuyAssetsBySellAssetId(): CAIP19[];
|
|
@@ -23,9 +23,6 @@ class ThorchainSwapper {
|
|
|
23
23
|
async executeQuote() {
|
|
24
24
|
throw new Error('ThorchainSwapper: executeQuote unimplemented');
|
|
25
25
|
}
|
|
26
|
-
getDefaultPair() {
|
|
27
|
-
throw new Error('ThorchainSwapper: getDefaultPair unimplemented');
|
|
28
|
-
}
|
|
29
26
|
async approvalNeeded() {
|
|
30
27
|
throw new Error('ThorchainSwapper: approvalNeeded unimplemented');
|
|
31
28
|
}
|
|
@@ -37,8 +37,8 @@ const constants_1 = require("../utils/constants");
|
|
|
37
37
|
const helpers_1 = require("../utils/helpers/helpers");
|
|
38
38
|
const zrxService_1 = require("../utils/zrxService");
|
|
39
39
|
async function ZrxBuildQuoteTx({ adapterManager, web3 }, { input, wallet }) {
|
|
40
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j
|
|
41
|
-
const { sellAsset, buyAsset, sellAmount, buyAmount, slippage, sellAssetAccountId, buyAssetAccountId
|
|
40
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
41
|
+
const { sellAsset, buyAsset, sellAmount, buyAmount, slippage, sellAssetAccountId, buyAssetAccountId } = input;
|
|
42
42
|
if ((buyAmount && sellAmount) || (!buyAmount && !sellAmount)) {
|
|
43
43
|
throw new __1.SwapError('ZrxSwapper:ZrxBuildQuoteTx Exactly one of buyAmount or sellAmount is required');
|
|
44
44
|
}
|
|
@@ -112,9 +112,7 @@ async function ZrxBuildQuoteTx({ adapterManager, web3 }, { input, wallet }) {
|
|
|
112
112
|
sellAssetAccountId,
|
|
113
113
|
buyAssetAccountId,
|
|
114
114
|
receiveAddress,
|
|
115
|
-
slippage,
|
|
116
115
|
success: true,
|
|
117
|
-
statusCode: 0,
|
|
118
116
|
rate: data.price,
|
|
119
117
|
depositAddress: data.to,
|
|
120
118
|
feeData: {
|
|
@@ -129,18 +127,15 @@ async function ZrxBuildQuoteTx({ adapterManager, web3 }, { input, wallet }) {
|
|
|
129
127
|
txData: data.data,
|
|
130
128
|
sellAmount: data.sellAmount,
|
|
131
129
|
buyAmount: data.buyAmount,
|
|
132
|
-
guaranteedPrice: data.guaranteedPrice,
|
|
133
130
|
allowanceContract: data.allowanceTarget,
|
|
134
|
-
sources: ((_a = data.sources) === null || _a === void 0 ? void 0 : _a.filter((s) => parseFloat(s.proportion) > 0)) || constants_1.DEFAULT_SOURCE
|
|
135
|
-
priceImpact
|
|
131
|
+
sources: ((_a = data.sources) === null || _a === void 0 ? void 0 : _a.filter((s) => parseFloat(s.proportion) > 0)) || constants_1.DEFAULT_SOURCE
|
|
136
132
|
};
|
|
137
133
|
const allowanceRequired = await (0, helpers_1.getAllowanceRequired)({
|
|
138
134
|
quote,
|
|
139
135
|
web3,
|
|
140
136
|
erc20AllowanceAbi: erc20Allowance_abi_1.erc20AllowanceAbi
|
|
141
137
|
});
|
|
142
|
-
|
|
143
|
-
if (quote.allowanceGrantRequired) {
|
|
138
|
+
if (allowanceRequired) {
|
|
144
139
|
quote.feeData = {
|
|
145
140
|
fee: ((_b = quote.feeData) === null || _b === void 0 ? void 0 : _b.fee) || '0',
|
|
146
141
|
chainSpecific: {
|
|
@@ -152,15 +147,13 @@ async function ZrxBuildQuoteTx({ adapterManager, web3 }, { input, wallet }) {
|
|
|
152
147
|
return quote;
|
|
153
148
|
}
|
|
154
149
|
catch (e) {
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
((_q = (_p = e === null || e === void 0 ? void 0 : e.response) === null || _p === void 0 ? void 0 : _p.data) === null || _q === void 0 ? void 0 : _q.reason) ||
|
|
150
|
+
const statusReason = ((_g = (_f = (_e = (_d = e === null || e === void 0 ? void 0 : e.response) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.validationErrors) === null || _f === void 0 ? void 0 : _f[0]) === null || _g === void 0 ? void 0 : _g.reason) ||
|
|
151
|
+
((_j = (_h = e === null || e === void 0 ? void 0 : e.response) === null || _h === void 0 ? void 0 : _h.data) === null || _j === void 0 ? void 0 : _j.reason) ||
|
|
158
152
|
'Unknown Error';
|
|
159
153
|
return {
|
|
160
154
|
sellAsset,
|
|
161
155
|
buyAsset,
|
|
162
156
|
success: false,
|
|
163
|
-
statusCode,
|
|
164
157
|
statusReason
|
|
165
158
|
};
|
|
166
159
|
}
|
|
@@ -19,7 +19,6 @@ export declare class ZrxSwapper implements Swapper {
|
|
|
19
19
|
getQuote(input: GetQuoteInput): Promise<Quote<ChainTypes>>;
|
|
20
20
|
getUsdRate(input: Pick<Asset, 'symbol' | 'tokenId'>): Promise<string>;
|
|
21
21
|
getMinMax(input: GetQuoteInput): Promise<MinMaxOutput>;
|
|
22
|
-
getDefaultPair(): [CAIP19, CAIP19];
|
|
23
22
|
executeQuote(args: ExecQuoteInput<ChainTypes>): Promise<ExecQuoteOutput>;
|
|
24
23
|
approvalNeeded(args: ApprovalNeededInput<ChainTypes>): Promise<ApprovalNeededOutput>;
|
|
25
24
|
approveInfinite(args: ApproveInfiniteInput<ChainTypes>): Promise<string>;
|
|
@@ -35,11 +35,6 @@ class ZrxSwapper {
|
|
|
35
35
|
async getMinMax(input) {
|
|
36
36
|
return (0, getZrxMinMax_1.getZrxMinMax)(input);
|
|
37
37
|
}
|
|
38
|
-
getDefaultPair() {
|
|
39
|
-
const ETH = 'eip155:1/slip44:60';
|
|
40
|
-
const FOX = 'eip155:1/erc20:0xc770eefad204b5180df6a14ee197d99d808ee52d';
|
|
41
|
-
return [ETH, FOX];
|
|
42
|
-
}
|
|
43
38
|
async executeQuote(args) {
|
|
44
39
|
return (0, ZrxExecuteQuote_1.ZrxExecuteQuote)(this.deps, args);
|
|
45
40
|
}
|
|
@@ -21,7 +21,7 @@ const getZrxMinMax = async (input) => {
|
|
|
21
21
|
const minimum = new bignumber_js_1.default(1).dividedBy(new bignumber_js_1.default(usdRate)).toString();
|
|
22
22
|
return {
|
|
23
23
|
minimum,
|
|
24
|
-
maximum: constants_1.MAX_ZRX_TRADE
|
|
24
|
+
maximum: constants_1.MAX_ZRX_TRADE // Arbitrarily large value. 10e+28 here.
|
|
25
25
|
};
|
|
26
26
|
};
|
|
27
27
|
exports.getZrxMinMax = getZrxMinMax;
|
|
@@ -6,13 +6,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.getZrxQuote = void 0;
|
|
7
7
|
const types_1 = require("@shapeshiftoss/types");
|
|
8
8
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
9
|
+
const getZrxMinMax_1 = require("../getZrxMinMax/getZrxMinMax");
|
|
10
|
+
const bignumber_1 = require("../utils/bignumber");
|
|
9
11
|
const constants_1 = require("../utils/constants");
|
|
10
12
|
const helpers_1 = require("../utils/helpers/helpers");
|
|
11
13
|
const zrxService_1 = require("../utils/zrxService");
|
|
12
14
|
const ZrxSwapper_1 = require("../ZrxSwapper");
|
|
13
15
|
async function getZrxQuote(input) {
|
|
14
|
-
var _a, _b, _c, _d, _e, _f, _g
|
|
15
|
-
const { sellAsset, buyAsset, sellAmount, buyAmount
|
|
16
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
17
|
+
const { sellAsset, buyAsset, sellAmount, buyAmount } = input;
|
|
16
18
|
if (!buyAsset) {
|
|
17
19
|
throw new ZrxSwapper_1.ZrxError('getQuote - Missing buyAsset');
|
|
18
20
|
}
|
|
@@ -28,10 +30,8 @@ async function getZrxQuote(input) {
|
|
|
28
30
|
const useSellAmount = !!sellAmount;
|
|
29
31
|
const buyToken = buyAsset.tokenId || buyAsset.symbol;
|
|
30
32
|
const sellToken = sellAsset.tokenId || sellAsset.symbol;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
minQuoteSellAmountWei = new bignumber_js_1.default(minQuoteSellAmount).times(new bignumber_js_1.default(10).exponentiatedBy(sellAsset.precision));
|
|
34
|
-
}
|
|
33
|
+
const { minimum: minQuoteSellAmount, maximum: maxSellAmount } = await (0, getZrxMinMax_1.getZrxMinMax)(input);
|
|
34
|
+
const minQuoteSellAmountWei = (0, bignumber_1.bnOrZero)(minQuoteSellAmount).times((0, bignumber_1.bnOrZero)(10).exponentiatedBy(sellAsset.precision));
|
|
35
35
|
const amount = useSellAmount ? { sellAmount } : { buyAmount };
|
|
36
36
|
const amountKey = Object.keys(amount)[0];
|
|
37
37
|
const amountValue = Object.values(amount)[0];
|
|
@@ -42,7 +42,6 @@ async function getZrxQuote(input) {
|
|
|
42
42
|
if (!normalizedAmount || normalizedAmount === '0') {
|
|
43
43
|
throw new ZrxSwapper_1.ZrxError('getQuote - Must have valid sellAmount, buyAmount or minimum amount');
|
|
44
44
|
}
|
|
45
|
-
const slippagePercentage = slippage ? new bignumber_js_1.default(slippage).div(100).toString() : undefined;
|
|
46
45
|
try {
|
|
47
46
|
/**
|
|
48
47
|
* /swap/v1/price
|
|
@@ -57,17 +56,10 @@ async function getZrxQuote(input) {
|
|
|
57
56
|
params: {
|
|
58
57
|
sellToken,
|
|
59
58
|
buyToken,
|
|
60
|
-
slippagePercentage,
|
|
61
59
|
[amountKey]: normalizedAmount
|
|
62
60
|
}
|
|
63
61
|
});
|
|
64
62
|
const { data } = quoteResponse;
|
|
65
|
-
const quotePrice = new bignumber_js_1.default(data.price);
|
|
66
|
-
const priceDifference = quotePrice.minus(minimumPrice);
|
|
67
|
-
const priceImpact = priceDifference
|
|
68
|
-
.dividedBy(minimumPrice)
|
|
69
|
-
.abs()
|
|
70
|
-
.valueOf();
|
|
71
63
|
const estimatedGas = data.estimatedGas
|
|
72
64
|
? new bignumber_js_1.default(data.estimatedGas).times(1.5)
|
|
73
65
|
: new bignumber_js_1.default(0);
|
|
@@ -75,13 +67,10 @@ async function getZrxQuote(input) {
|
|
|
75
67
|
return {
|
|
76
68
|
sellAsset,
|
|
77
69
|
buyAsset,
|
|
78
|
-
priceImpact,
|
|
79
|
-
slippage,
|
|
80
70
|
success: true,
|
|
81
|
-
statusCode: 0,
|
|
82
71
|
rate,
|
|
83
72
|
minimum: minQuoteSellAmount,
|
|
84
|
-
maximum:
|
|
73
|
+
maximum: maxSellAmount,
|
|
85
74
|
feeData: {
|
|
86
75
|
fee: new bignumber_js_1.default(estimatedGas || 0)
|
|
87
76
|
.multipliedBy(new bignumber_js_1.default(data.gasPrice || 0))
|
|
@@ -95,23 +84,18 @@ async function getZrxQuote(input) {
|
|
|
95
84
|
},
|
|
96
85
|
sellAmount: data.sellAmount,
|
|
97
86
|
buyAmount: data.buyAmount,
|
|
98
|
-
guaranteedPrice: data.guaranteedPrice,
|
|
99
87
|
sources: ((_a = data.sources) === null || _a === void 0 ? void 0 : _a.filter((s) => parseFloat(s.proportion) > 0)) || constants_1.DEFAULT_SOURCE,
|
|
100
88
|
allowanceContract: data.allowanceTarget
|
|
101
89
|
};
|
|
102
90
|
}
|
|
103
91
|
catch (e) {
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
((_o = (_m = e === null || e === void 0 ? void 0 : e.response) === null || _m === void 0 ? void 0 : _m.data) === null || _o === void 0 ? void 0 : _o.reason) ||
|
|
92
|
+
const statusReason = ((_e = (_d = (_c = (_b = e === null || e === void 0 ? void 0 : e.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.validationErrors) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.reason) ||
|
|
93
|
+
((_g = (_f = e === null || e === void 0 ? void 0 : e.response) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.reason) ||
|
|
107
94
|
'Unknown Error';
|
|
108
95
|
return {
|
|
109
96
|
sellAsset,
|
|
110
97
|
buyAsset,
|
|
111
|
-
minimum: minQuoteSellAmount,
|
|
112
|
-
maximum: constants_1.MAX_ZRX_TRADE,
|
|
113
98
|
success: false,
|
|
114
|
-
statusCode,
|
|
115
99
|
statusReason
|
|
116
100
|
};
|
|
117
101
|
}
|