@shapeshiftoss/swapper 6.2.0 → 6.2.1
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 +3 -3
- package/dist/manager/SwapperManager.d.ts +2 -2
- package/dist/swappercli.js +3 -3
- package/dist/swappers/zrx/ZrxApprovalNeeded/ZrxApprovalNeeded.js +1 -1
- package/dist/swappers/zrx/getZrxTradeQuote/getZrxTradeQuote.js +2 -2
- package/dist/swappers/zrx/utils/helpers/helpers.js +1 -1
- package/dist/swappers/zrx/utils/test-data/setupSwapQuote.d.ts +3 -3
- package/dist/swappers/zrx/utils/test-data/setupSwapQuote.js +5 -5
- package/dist/swappers/zrx/zrxBuildTrade/zrxBuildTrade.js +3 -3
- package/dist/swappers/zrx/zrxExecuteTrade/zrxExecuteTrade.js +1 -2
- package/package.json +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -58,11 +58,11 @@ export declare type CommonTradeInput = {
|
|
|
58
58
|
buyAsset: Asset;
|
|
59
59
|
sellAmount: string;
|
|
60
60
|
sendMax: boolean;
|
|
61
|
-
|
|
61
|
+
sellAssetAccountNumber: number;
|
|
62
62
|
};
|
|
63
63
|
export declare type GetTradeQuoteInput = CommonTradeInput;
|
|
64
64
|
export declare type BuildTradeInput = CommonTradeInput & {
|
|
65
|
-
|
|
65
|
+
buyAssetAccountNumber: number;
|
|
66
66
|
slippage?: string;
|
|
67
67
|
wallet: HDWallet;
|
|
68
68
|
};
|
|
@@ -74,7 +74,7 @@ interface TradeBase<C extends SupportedChainIds> {
|
|
|
74
74
|
sources: Array<SwapSource>;
|
|
75
75
|
buyAsset: Asset;
|
|
76
76
|
sellAsset: Asset;
|
|
77
|
-
|
|
77
|
+
sellAssetAccountNumber: number;
|
|
78
78
|
}
|
|
79
79
|
export interface TradeQuote<C extends SupportedChainIds> extends TradeBase<C> {
|
|
80
80
|
allowanceContract: string;
|
|
@@ -30,6 +30,6 @@ export declare class SwapperManager {
|
|
|
30
30
|
* @returns {SwapperType}
|
|
31
31
|
*/
|
|
32
32
|
getSwappersByPair(pair: ByPairInput): Swapper[];
|
|
33
|
-
getSupportedBuyAssetIdsFromSellId(args: BuyAssetBySellIdInput):
|
|
34
|
-
getSupportedSellableAssetIds(args: SupportedSellAssetsInput):
|
|
33
|
+
getSupportedBuyAssetIdsFromSellId(args: BuyAssetBySellIdInput): import("@shapeshiftoss/caip").AssetId[];
|
|
34
|
+
getSupportedSellableAssetIds(args: SupportedSellAssetsInput): import("@shapeshiftoss/caip").AssetId[];
|
|
35
35
|
}
|
package/dist/swappercli.js
CHANGED
|
@@ -95,7 +95,7 @@ const main = async () => {
|
|
|
95
95
|
sellAsset,
|
|
96
96
|
buyAsset,
|
|
97
97
|
sellAmount: sellAmountBase,
|
|
98
|
-
|
|
98
|
+
sellAssetAccountNumber: 0,
|
|
99
99
|
sendMax: false
|
|
100
100
|
});
|
|
101
101
|
}
|
|
@@ -115,8 +115,8 @@ const main = async () => {
|
|
|
115
115
|
sendMax: false,
|
|
116
116
|
sellAmount: sellAmountBase,
|
|
117
117
|
sellAsset,
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
sellAssetAccountNumber: 0,
|
|
119
|
+
buyAssetAccountNumber: 0
|
|
120
120
|
});
|
|
121
121
|
const txid = await swapper.executeTrade({ trade, wallet });
|
|
122
122
|
console.info('broadcast tx with id: ', txid);
|
|
@@ -21,7 +21,7 @@ async function ZrxApprovalNeeded({ adapterManager, web3 }, { quote, wallet }) {
|
|
|
21
21
|
if (sellAsset.assetId === (0, caip_1.getFeeAssetIdFromAssetId)(sellAsset.assetId)) {
|
|
22
22
|
return { approvalNeeded: false };
|
|
23
23
|
}
|
|
24
|
-
const accountNumber =
|
|
24
|
+
const accountNumber = quote.sellAssetAccountNumber;
|
|
25
25
|
const adapter = await adapterManager.byChainId(sellAsset.chainId);
|
|
26
26
|
const bip44Params = adapter.buildBIP44Params({ accountNumber });
|
|
27
27
|
const receiveAddress = await adapter.getAddress({ wallet, bip44Params });
|
|
@@ -11,7 +11,7 @@ const zrxService_1 = require("../utils/zrxService");
|
|
|
11
11
|
async function getZrxTradeQuote(input) {
|
|
12
12
|
var _a;
|
|
13
13
|
try {
|
|
14
|
-
const { sellAsset, buyAsset, sellAmount,
|
|
14
|
+
const { sellAsset, buyAsset, sellAmount, sellAssetAccountNumber } = input;
|
|
15
15
|
if (buyAsset.chainId !== 'eip155:1' || sellAsset.chainId !== 'eip155:1') {
|
|
16
16
|
throw new api_1.SwapError('[getZrxTradeQuote] - Both assets need to be on the Ethereum chain to use Zrx', {
|
|
17
17
|
code: api_1.SwapErrorTypes.UNSUPPORTED_PAIR,
|
|
@@ -65,7 +65,7 @@ async function getZrxTradeQuote(input) {
|
|
|
65
65
|
allowanceContract: data.allowanceTarget,
|
|
66
66
|
buyAsset,
|
|
67
67
|
sellAsset,
|
|
68
|
-
|
|
68
|
+
sellAssetAccountNumber
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
71
|
catch (e) {
|
|
@@ -99,7 +99,7 @@ const grantAllowance = async ({ quote, wallet, adapterManager, erc20Abi, web3 })
|
|
|
99
99
|
const approveTx = erc20Contract.methods
|
|
100
100
|
.approve(quote.allowanceContract, quote.sellAmount)
|
|
101
101
|
.encodeABI();
|
|
102
|
-
const accountNumber =
|
|
102
|
+
const accountNumber = quote.sellAssetAccountNumber;
|
|
103
103
|
const bip44Params = adapter.buildBIP44Params({ accountNumber });
|
|
104
104
|
const { txToSign } = await adapter.buildSendTransaction({
|
|
105
105
|
wallet,
|
|
@@ -21,8 +21,8 @@ export declare const setupBuildTrade: () => {
|
|
|
21
21
|
buyAmount: string;
|
|
22
22
|
buyAsset: Asset;
|
|
23
23
|
sendMax: boolean;
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
sellAssetAccountNumber: number;
|
|
25
|
+
buyAssetAccountNumber: number;
|
|
26
26
|
sellAsset: Asset;
|
|
27
27
|
};
|
|
28
28
|
buyAsset: Asset;
|
|
@@ -40,7 +40,7 @@ export declare const setupExecuteTrade: () => {
|
|
|
40
40
|
buyAsset: Asset;
|
|
41
41
|
sellAsset: Asset;
|
|
42
42
|
sendMax: boolean;
|
|
43
|
-
|
|
43
|
+
sellAssetAccountNumber: number;
|
|
44
44
|
txData: string;
|
|
45
45
|
depositAddress: string;
|
|
46
46
|
receiveAddress: string;
|
|
@@ -11,7 +11,7 @@ const setupQuote = () => {
|
|
|
11
11
|
sellAsset,
|
|
12
12
|
buyAsset,
|
|
13
13
|
allowanceContract: 'allowanceContractAddress',
|
|
14
|
-
|
|
14
|
+
sellAssetAccountNumber: 0,
|
|
15
15
|
minimum: '0',
|
|
16
16
|
maximum: '999999999999',
|
|
17
17
|
feeData: { fee: '0', tradeFee: '0', chainSpecific: {} },
|
|
@@ -22,7 +22,7 @@ const setupQuote = () => {
|
|
|
22
22
|
sellAmount: '1000000000000000000',
|
|
23
23
|
sellAsset,
|
|
24
24
|
buyAsset,
|
|
25
|
-
|
|
25
|
+
sellAssetAccountNumber: 0,
|
|
26
26
|
sendMax: false
|
|
27
27
|
};
|
|
28
28
|
return { quoteInput, tradeQuote, buyAsset, sellAsset };
|
|
@@ -56,8 +56,8 @@ const setupBuildTrade = () => {
|
|
|
56
56
|
buyAmount: '',
|
|
57
57
|
buyAsset,
|
|
58
58
|
sendMax: false,
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
sellAssetAccountNumber: 0,
|
|
60
|
+
buyAssetAccountNumber: 0,
|
|
61
61
|
sellAsset
|
|
62
62
|
};
|
|
63
63
|
return { buildTradeInput, buyAsset, sellAsset };
|
|
@@ -77,7 +77,7 @@ const setupExecuteTrade = () => {
|
|
|
77
77
|
buyAsset,
|
|
78
78
|
sellAsset,
|
|
79
79
|
sendMax: false,
|
|
80
|
-
|
|
80
|
+
sellAssetAccountNumber: 0,
|
|
81
81
|
txData: '0x0',
|
|
82
82
|
depositAddress: '0x0',
|
|
83
83
|
receiveAddress: '0x0',
|
|
@@ -35,7 +35,7 @@ const helpers_1 = require("../utils/helpers/helpers");
|
|
|
35
35
|
const zrxService_1 = require("../utils/zrxService");
|
|
36
36
|
async function zrxBuildTrade({ adapterManager, web3 }, input) {
|
|
37
37
|
var _a, _b, _c;
|
|
38
|
-
const { sellAsset, buyAsset, sellAmount, slippage,
|
|
38
|
+
const { sellAsset, buyAsset, sellAmount, slippage, sellAssetAccountNumber, buyAssetAccountNumber, wallet } = input;
|
|
39
39
|
try {
|
|
40
40
|
const { assetReference: buyAssetErc20Address, assetNamespace: buyAssetNamespace } = (0, caip_1.fromAssetId)(buyAsset.assetId);
|
|
41
41
|
const { assetReference: sellAssetErc20Address, assetNamespace: sellAssetNamespace } = (0, caip_1.fromAssetId)(sellAsset.assetId);
|
|
@@ -48,7 +48,7 @@ async function zrxBuildTrade({ adapterManager, web3 }, input) {
|
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
50
|
const adapter = await adapterManager.byChainId(buyAsset.chainId);
|
|
51
|
-
const bip44Params = adapter.buildBIP44Params({ accountNumber:
|
|
51
|
+
const bip44Params = adapter.buildBIP44Params({ accountNumber: buyAssetAccountNumber });
|
|
52
52
|
const receiveAddress = await adapter.getAddress({ wallet, bip44Params });
|
|
53
53
|
const slippagePercentage = slippage ? (0, bignumber_1.bnOrZero)(slippage).div(100).toString() : constants_1.DEFAULT_SLIPPAGE;
|
|
54
54
|
/**
|
|
@@ -92,7 +92,7 @@ async function zrxBuildTrade({ adapterManager, web3 }, input) {
|
|
|
92
92
|
const trade = {
|
|
93
93
|
sellAsset,
|
|
94
94
|
buyAsset,
|
|
95
|
-
|
|
95
|
+
sellAssetAccountNumber,
|
|
96
96
|
receiveAddress,
|
|
97
97
|
rate: data.price,
|
|
98
98
|
depositAddress: data.to,
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.zrxExecuteTrade = void 0;
|
|
4
4
|
const web3_utils_1 = require("web3-utils");
|
|
5
5
|
const api_1 = require("../../../api");
|
|
6
|
-
const bignumber_1 = require("../../utils/bignumber");
|
|
7
6
|
async function zrxExecuteTrade({ adapterManager }, { trade, wallet }) {
|
|
8
7
|
var _a, _b, _c, _d, _e, _f;
|
|
9
8
|
const zrxTrade = trade;
|
|
@@ -13,7 +12,7 @@ async function zrxExecuteTrade({ adapterManager }, { trade, wallet }) {
|
|
|
13
12
|
const value = sellAsset.assetId === 'eip155:1/slip44:60' ? trade.sellAmount : '0';
|
|
14
13
|
const adapter = await adapterManager.byChainId(sellAsset.chainId);
|
|
15
14
|
const bip44Params = adapter.buildBIP44Params({
|
|
16
|
-
accountNumber:
|
|
15
|
+
accountNumber: trade.sellAssetAccountNumber
|
|
17
16
|
});
|
|
18
17
|
const buildTxResponse = await adapter.buildSendTransaction({
|
|
19
18
|
value,
|