@shapeshiftoss/swapper 2.2.0 → 2.3.0
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 +1 -5
- package/dist/manager/SwapperManager.d.ts +2 -2
- package/dist/manager/SwapperManager.js +4 -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/ZrxSwapper.d.ts +1 -2
- package/dist/swappers/zrx/ZrxSwapper.js +0 -4
- package/dist/swappers/zrx/utils/test-data/assets.js +6 -0
- package/package.json +1 -1
- package/dist/swappers/zrx/getZrxSendMaxAmount/getZrxSendMaxAmount.d.ts +0 -3
- package/dist/swappers/zrx/getZrxSendMaxAmount/getZrxSendMaxAmount.js +0 -63
package/dist/api.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CAIP19 } from '@shapeshiftoss/caip';
|
|
2
2
|
import { HDWallet } from '@shapeshiftoss/hdwallet-core';
|
|
3
|
-
import { ApprovalNeededInput, ApprovalNeededOutput, ApproveInfiniteInput, Asset, BuildQuoteTxInput, ChainTypes, ExecQuoteInput, ExecQuoteOutput, GetQuoteInput, MinMaxOutput, Quote,
|
|
3
|
+
import { ApprovalNeededInput, ApprovalNeededOutput, ApproveInfiniteInput, Asset, BuildQuoteTxInput, ChainTypes, ExecQuoteInput, ExecQuoteOutput, GetQuoteInput, MinMaxOutput, Quote, SwapperType } from '@shapeshiftoss/types';
|
|
4
4
|
export declare type SupportedAssetInput = {
|
|
5
5
|
assetIds: CAIP19[];
|
|
6
6
|
};
|
|
@@ -52,10 +52,6 @@ export interface Swapper {
|
|
|
52
52
|
* Get the txid of an approve infinite transaction
|
|
53
53
|
*/
|
|
54
54
|
approveInfinite(args: ApproveInfiniteInput<ChainTypes, SwapperType>): Promise<string>;
|
|
55
|
-
/**
|
|
56
|
-
* Get max swap balance (minus fees) for sell asset
|
|
57
|
-
*/
|
|
58
|
-
getSendMaxAmount(args: SendMaxAmountInput): Promise<string>;
|
|
59
55
|
/**
|
|
60
56
|
* Get supported buyAssetId's by sellAssetId
|
|
61
57
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SwapperType } from '@shapeshiftoss/types';
|
|
2
2
|
import { BuyAssetBySellIdInput, ByPairInput, SupportedSellAssetsInput, Swapper } from '..';
|
|
3
3
|
export declare class SwapperError extends Error {
|
|
4
4
|
constructor(message: string);
|
|
@@ -25,7 +25,7 @@ export declare class SwapperManager {
|
|
|
25
25
|
* @returns {SwapperManager}
|
|
26
26
|
*/
|
|
27
27
|
removeSwapper(swapperType: SwapperType): this;
|
|
28
|
-
getBestSwapper(
|
|
28
|
+
getBestSwapper(args: ByPairInput): Promise<Swapper>;
|
|
29
29
|
/**
|
|
30
30
|
*
|
|
31
31
|
* @param pair type {GetQuoteInput}
|
|
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.SwapperManager = exports.SwapperError = void 0;
|
|
7
|
-
const types_1 = require("@shapeshiftoss/types");
|
|
8
7
|
const uniq_1 = __importDefault(require("lodash/uniq"));
|
|
9
8
|
class SwapperError extends Error {
|
|
10
9
|
constructor(message) {
|
|
@@ -59,9 +58,10 @@ class SwapperManager {
|
|
|
59
58
|
this.swappers.delete(swapperType);
|
|
60
59
|
return this;
|
|
61
60
|
}
|
|
62
|
-
async getBestSwapper(
|
|
63
|
-
|
|
64
|
-
return
|
|
61
|
+
async getBestSwapper(args) {
|
|
62
|
+
// TODO: This will eventually have logic to determine the best swapper.
|
|
63
|
+
// For now we return the first swapper we get from getSwappersByPair
|
|
64
|
+
return this.getSwappersByPair(args)[0];
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
67
|
*
|
|
@@ -17,7 +17,6 @@ export declare class TestSwapper implements Swapper {
|
|
|
17
17
|
getDefaultPair(): [CAIP19, CAIP19];
|
|
18
18
|
approvalNeeded(): Promise<ApprovalNeededOutput>;
|
|
19
19
|
approveInfinite(): Promise<string>;
|
|
20
|
-
getSendMaxAmount(): Promise<string>;
|
|
21
20
|
filterBuyAssetsBySellAssetId(args: BuyAssetBySellIdInput): CAIP19[];
|
|
22
21
|
filterAssetIdsBySellable(): CAIP19[];
|
|
23
22
|
}
|
|
@@ -43,9 +43,6 @@ class TestSwapper {
|
|
|
43
43
|
async approveInfinite() {
|
|
44
44
|
throw new Error('TestSwapper: approveInfinite unimplemented');
|
|
45
45
|
}
|
|
46
|
-
async getSendMaxAmount() {
|
|
47
|
-
throw new Error('TestSwapper: getSendMaxAmount unimplemented');
|
|
48
|
-
}
|
|
49
46
|
filterBuyAssetsBySellAssetId(args) {
|
|
50
47
|
const { sellAssetId } = args;
|
|
51
48
|
if (!this.supportAssets.includes(sellAssetId))
|
|
@@ -11,7 +11,6 @@ export declare class ThorchainSwapper implements Swapper {
|
|
|
11
11
|
getDefaultPair(): [CAIP19, CAIP19];
|
|
12
12
|
approvalNeeded(): Promise<ApprovalNeededOutput>;
|
|
13
13
|
approveInfinite(): Promise<string>;
|
|
14
|
-
getSendMaxAmount(): Promise<string>;
|
|
15
14
|
filterBuyAssetsBySellAssetId(): CAIP19[];
|
|
16
15
|
filterAssetIdsBySellable(): CAIP19[];
|
|
17
16
|
}
|
|
@@ -32,9 +32,6 @@ class ThorchainSwapper {
|
|
|
32
32
|
async approveInfinite() {
|
|
33
33
|
throw new Error('ThorchainSwapper: approveInfinite unimplemented');
|
|
34
34
|
}
|
|
35
|
-
async getSendMaxAmount() {
|
|
36
|
-
throw new Error('ThorchainSwapper: getSendMaxAmount unimplemented');
|
|
37
|
-
}
|
|
38
35
|
filterBuyAssetsBySellAssetId() {
|
|
39
36
|
return [];
|
|
40
37
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CAIP19 } from '@shapeshiftoss/caip';
|
|
2
2
|
import { ChainAdapterManager } from '@shapeshiftoss/chain-adapters';
|
|
3
|
-
import { ApprovalNeededInput, ApprovalNeededOutput, ApproveInfiniteInput, Asset, BuildQuoteTxInput, ChainTypes, ExecQuoteInput, ExecQuoteOutput, GetQuoteInput, MinMaxOutput, Quote,
|
|
3
|
+
import { ApprovalNeededInput, ApprovalNeededOutput, ApproveInfiniteInput, Asset, BuildQuoteTxInput, ChainTypes, ExecQuoteInput, ExecQuoteOutput, GetQuoteInput, MinMaxOutput, Quote, SwapperType } from '@shapeshiftoss/types';
|
|
4
4
|
import Web3 from 'web3';
|
|
5
5
|
import { BuyAssetBySellIdInput, Swapper } from '../../api';
|
|
6
6
|
export declare type ZrxSwapperDeps = {
|
|
@@ -23,7 +23,6 @@ export declare class ZrxSwapper implements Swapper {
|
|
|
23
23
|
executeQuote(args: ExecQuoteInput<ChainTypes, SwapperType>): Promise<ExecQuoteOutput>;
|
|
24
24
|
approvalNeeded(args: ApprovalNeededInput<ChainTypes, SwapperType>): Promise<ApprovalNeededOutput>;
|
|
25
25
|
approveInfinite(args: ApproveInfiniteInput<ChainTypes, SwapperType>): Promise<string>;
|
|
26
|
-
getSendMaxAmount(args: SendMaxAmountInput): Promise<string>;
|
|
27
26
|
filterBuyAssetsBySellAssetId(args: BuyAssetBySellIdInput): CAIP19[];
|
|
28
27
|
filterAssetIdsBySellable(assetIds: CAIP19[]): CAIP19[];
|
|
29
28
|
}
|
|
@@ -4,7 +4,6 @@ exports.ZrxSwapper = exports.ZrxError = void 0;
|
|
|
4
4
|
const types_1 = require("@shapeshiftoss/types");
|
|
5
5
|
const getZrxMinMax_1 = require("./getZrxMinMax/getZrxMinMax");
|
|
6
6
|
const getZrxQuote_1 = require("./getZrxQuote/getZrxQuote");
|
|
7
|
-
const getZrxSendMaxAmount_1 = require("./getZrxSendMaxAmount/getZrxSendMaxAmount");
|
|
8
7
|
const helpers_1 = require("./utils/helpers/helpers");
|
|
9
8
|
const ZrxApprovalNeeded_1 = require("./ZrxApprovalNeeded/ZrxApprovalNeeded");
|
|
10
9
|
const ZrxApproveInfinite_1 = require("./ZrxApproveInfinite/ZrxApproveInfinite");
|
|
@@ -50,9 +49,6 @@ class ZrxSwapper {
|
|
|
50
49
|
async approveInfinite(args) {
|
|
51
50
|
return (0, ZrxApproveInfinite_1.ZrxApproveInfinite)(this.deps, args);
|
|
52
51
|
}
|
|
53
|
-
async getSendMaxAmount(args) {
|
|
54
|
-
return (0, getZrxSendMaxAmount_1.getZrxSendMaxAmount)(this.deps, args);
|
|
55
|
-
}
|
|
56
52
|
filterBuyAssetsBySellAssetId(args) {
|
|
57
53
|
const { assetIds, sellAssetId } = args;
|
|
58
54
|
// TODO: pending changes to caip lib, we may want to import caip2 value instead.
|
|
@@ -4,6 +4,8 @@ exports.FOX = exports.WETH = exports.BTC = void 0;
|
|
|
4
4
|
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
5
|
const types_1 = require("@shapeshiftoss/types");
|
|
6
6
|
exports.BTC = {
|
|
7
|
+
assetId: 'bip122:000000000019d6689c085ae165831e93/slip44:0',
|
|
8
|
+
chainId: 'bip122:000000000019d6689c085ae165831e93',
|
|
7
9
|
caip19: 'bip122:000000000019d6689c085ae165831e93/slip44:0',
|
|
8
10
|
caip2: 'bip122:000000000019d6689c085ae165831e93',
|
|
9
11
|
name: 'bitcoin',
|
|
@@ -24,6 +26,8 @@ exports.BTC = {
|
|
|
24
26
|
symbol: 'BTC'
|
|
25
27
|
};
|
|
26
28
|
exports.WETH = {
|
|
29
|
+
assetId: 'eip155:1/erc20:0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
30
|
+
chainId: 'eip155:1',
|
|
27
31
|
caip19: 'eip155:1/erc20:0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
28
32
|
caip2: 'eip155:1',
|
|
29
33
|
name: 'WETH',
|
|
@@ -45,6 +49,8 @@ exports.WETH = {
|
|
|
45
49
|
symbol: 'WETH'
|
|
46
50
|
};
|
|
47
51
|
exports.FOX = {
|
|
52
|
+
assetId: 'eip155:1/erc20:0xc770eefad204b5180df6a14ee197d99d808ee52d',
|
|
53
|
+
chainId: 'eip155:1',
|
|
48
54
|
caip19: 'eip155:1/erc20:0xc770eefad204b5180df6a14ee197d99d808ee52d',
|
|
49
55
|
caip2: 'eip155:1',
|
|
50
56
|
name: 'FOX',
|
package/package.json
CHANGED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { SendMaxAmountInput } from '@shapeshiftoss/types';
|
|
2
|
-
import { ZrxSwapperDeps } from '../ZrxSwapper';
|
|
3
|
-
export declare function getZrxSendMaxAmount({ adapterManager }: ZrxSwapperDeps, { wallet, quote, sellAssetAccountId, feeEstimateKey }: SendMaxAmountInput): Promise<string>;
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getZrxSendMaxAmount = void 0;
|
|
7
|
-
const caip_1 = require("@shapeshiftoss/caip");
|
|
8
|
-
const types_1 = require("@shapeshiftoss/types");
|
|
9
|
-
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
10
|
-
const api_1 = require("../../../api");
|
|
11
|
-
const bignumber_1 = require("../utils/bignumber");
|
|
12
|
-
const constants_1 = require("../utils/constants");
|
|
13
|
-
async function getZrxSendMaxAmount({ adapterManager }, { wallet, quote, sellAssetAccountId, feeEstimateKey = types_1.chainAdapters.FeeDataKey.Average }) {
|
|
14
|
-
var _a, _b, _c;
|
|
15
|
-
const adapter = adapterManager.byChain(types_1.ChainTypes.Ethereum);
|
|
16
|
-
const bip44Params = adapter.buildBIP44Params({
|
|
17
|
-
accountNumber: (0, bignumber_1.bnOrZero)(sellAssetAccountId).toNumber()
|
|
18
|
-
});
|
|
19
|
-
const ethAddress = await adapter.getAddress({ wallet, bip44Params });
|
|
20
|
-
const account = await adapter.getAccount(ethAddress);
|
|
21
|
-
if (!quote.sellAsset) {
|
|
22
|
-
throw new api_1.SwapError('quote.sellAsset is required');
|
|
23
|
-
}
|
|
24
|
-
const tokenId = (_a = quote.sellAsset) === null || _a === void 0 ? void 0 : _a.tokenId;
|
|
25
|
-
let balance;
|
|
26
|
-
if (tokenId) {
|
|
27
|
-
balance = (_c = (_b = account.chainSpecific.tokens) === null || _b === void 0 ? void 0 : _b.find((token) => {
|
|
28
|
-
return caip_1.caip19.fromCAIP19(token.caip19).assetReference === tokenId.toLowerCase();
|
|
29
|
-
})) === null || _c === void 0 ? void 0 : _c.balance;
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
balance = account.balance;
|
|
33
|
-
}
|
|
34
|
-
if (!balance) {
|
|
35
|
-
throw new api_1.SwapError(`No balance found for ${tokenId ? quote.sellAsset.symbol : 'ETH'}`);
|
|
36
|
-
}
|
|
37
|
-
// return the erc20 token balance. No need to subtract the fee.
|
|
38
|
-
if (tokenId && new bignumber_js_1.default(balance).gt(0)) {
|
|
39
|
-
return balance;
|
|
40
|
-
}
|
|
41
|
-
if (!quote.txData) {
|
|
42
|
-
throw new api_1.SwapError('quote.txData is required to get correct fee estimate');
|
|
43
|
-
}
|
|
44
|
-
const feeEstimates = await adapter.getFeeData({
|
|
45
|
-
to: quote.depositAddress,
|
|
46
|
-
value: (0, bignumber_1.bnOrZero)(quote.sellAmount).toString(),
|
|
47
|
-
chainSpecific: {
|
|
48
|
-
from: ethAddress,
|
|
49
|
-
contractData: quote.txData
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
const estimatedFee = feeEstimates[feeEstimateKey].txFee;
|
|
53
|
-
// (ryankk) We need to pad the fee for ETH max sends because the fee estimate is based off
|
|
54
|
-
// of a minimum quote value (quote.sellAmount) and not the users full ETH balance.
|
|
55
|
-
const paddedFee = new bignumber_js_1.default(estimatedFee).times(constants_1.ETH_FEE_ESTIMATE_PADDING);
|
|
56
|
-
const sendMaxAmount = new bignumber_js_1.default(balance).minus(paddedFee);
|
|
57
|
-
// gte covers if sendMaxAmount is NaN
|
|
58
|
-
if (!sendMaxAmount.gte(0)) {
|
|
59
|
-
throw new api_1.SwapError('ETH balance is less than estimated fee');
|
|
60
|
-
}
|
|
61
|
-
return sendMaxAmount.toString();
|
|
62
|
-
}
|
|
63
|
-
exports.getZrxSendMaxAmount = getZrxSendMaxAmount;
|