@shapeshiftoss/swapper 7.5.0 → 7.7.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 +14 -5
- package/dist/swappercli.js +2 -1
- package/dist/swappers/thorchain/ThorchainSwapper.d.ts +2 -2
- package/dist/swappers/thorchain/ThorchainSwapper.js +3 -2
- package/dist/swappers/thorchain/thorTradeApproveInfinite/thorTradeApproveInfinite.d.ts +6 -0
- package/dist/swappers/thorchain/thorTradeApproveInfinite/thorTradeApproveInfinite.js +41 -0
- package/dist/swappers/thorchain/utils/constants.d.ts +1 -0
- package/dist/swappers/thorchain/utils/constants.js +2 -1
- package/dist/swappers/utils/test-data/setupSwapQuote.d.ts +1 -1
- package/dist/swappers/utils/test-data/setupSwapQuote.js +1 -0
- package/dist/swappers/zrx/utils/test-data/setupZrxSwapQuote.d.ts +6 -10
- package/dist/swappers/zrx/utils/test-data/setupZrxSwapQuote.js +3 -5
- package/package.json +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AssetId, ChainId } from '@shapeshiftoss/caip';
|
|
2
2
|
import { BTCSignTx, ETHSignTx, HDWallet } from '@shapeshiftoss/hdwallet-core';
|
|
3
|
-
import { Asset, ChainSpecific, KnownChainIds } from '@shapeshiftoss/types';
|
|
3
|
+
import { Asset, BIP44Params, ChainSpecific, KnownChainIds, UtxoAccountType } from '@shapeshiftoss/types';
|
|
4
4
|
export declare const SwapError: {
|
|
5
5
|
new <V extends {
|
|
6
6
|
cause?: unknown;
|
|
@@ -58,8 +58,17 @@ export declare type CommonTradeInput = {
|
|
|
58
58
|
sellAssetAccountNumber: number;
|
|
59
59
|
wallet?: HDWallet;
|
|
60
60
|
};
|
|
61
|
-
export declare type
|
|
62
|
-
|
|
61
|
+
export declare type GetEthTradeQuoteInput = CommonTradeInput & {
|
|
62
|
+
chainId: 'eip155:1';
|
|
63
|
+
};
|
|
64
|
+
export declare type GetBtcTradeQuoteInput = CommonTradeInput & {
|
|
65
|
+
chainId: 'bip122:000000000019d6689c085ae165831e93';
|
|
66
|
+
accountType: UtxoAccountType;
|
|
67
|
+
bip44Params: BIP44Params;
|
|
68
|
+
wallet: HDWallet;
|
|
69
|
+
};
|
|
70
|
+
export declare type GetTradeQuoteInput = GetEthTradeQuoteInput | GetBtcTradeQuoteInput;
|
|
71
|
+
export declare type BuildTradeInput = GetTradeQuoteInput & {
|
|
63
72
|
buyAssetAccountNumber: number;
|
|
64
73
|
slippage?: string;
|
|
65
74
|
wallet: HDWallet;
|
|
@@ -157,7 +166,7 @@ export declare enum SwapErrorTypes {
|
|
|
157
166
|
PRICE_RATIO_FAILED = "PRICE_RATIO_FAILED",
|
|
158
167
|
POOL_NOT_FOUND = "POOL_NOT_FOUND"
|
|
159
168
|
}
|
|
160
|
-
export interface Swapper<T extends ChainId
|
|
169
|
+
export interface Swapper<T extends ChainId> {
|
|
161
170
|
/** perform any necessary async initialization */
|
|
162
171
|
initialize(): Promise<void>;
|
|
163
172
|
/** Returns the swapper type */
|
|
@@ -194,6 +203,6 @@ export interface Swapper<T extends ChainId, TxType = unknown> {
|
|
|
194
203
|
* Get supported sell assetIds
|
|
195
204
|
*/
|
|
196
205
|
filterAssetIdsBySellable(assetIds: AssetId[]): AssetId[];
|
|
197
|
-
getTradeTxs(tradeResult: TradeResult): Promise<
|
|
206
|
+
getTradeTxs(tradeResult: TradeResult): Promise<TradeTxs>;
|
|
198
207
|
}
|
|
199
208
|
export {};
|
package/dist/swappercli.js
CHANGED
|
@@ -109,11 +109,11 @@ const main = async () => {
|
|
|
109
109
|
let quote;
|
|
110
110
|
try {
|
|
111
111
|
quote = await swapper.getTradeQuote({
|
|
112
|
+
chainId: 'eip155:1',
|
|
112
113
|
sellAsset,
|
|
113
114
|
buyAsset,
|
|
114
115
|
sellAmount: sellAmountBase,
|
|
115
116
|
sellAssetAccountNumber: 0,
|
|
116
|
-
wallet,
|
|
117
117
|
sendMax: false
|
|
118
118
|
});
|
|
119
119
|
}
|
|
@@ -128,6 +128,7 @@ const main = async () => {
|
|
|
128
128
|
const answer = readline_sync_1.default.question(`Swap ${sellAmount} ${sellAsset.symbol} for ${buyAmount} ${buyAsset.symbol} on ${swapper.getType()}? (y/n): `);
|
|
129
129
|
if (answer === 'y') {
|
|
130
130
|
const trade = await swapper.buildTrade({
|
|
131
|
+
chainId: 'eip155:1',
|
|
131
132
|
wallet,
|
|
132
133
|
buyAsset,
|
|
133
134
|
sendMax: false,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AssetId, ChainId } from '@shapeshiftoss/caip';
|
|
2
2
|
import type { Asset } from '@shapeshiftoss/types';
|
|
3
|
-
import { ApprovalNeededInput, ApprovalNeededOutput, BuyAssetBySellIdInput, ExecuteTradeInput, GetTradeQuoteInput, Swapper, SwapperType, Trade, TradeQuote, TradeResult, TradeTxs } from '../../api';
|
|
3
|
+
import { ApprovalNeededInput, ApprovalNeededOutput, ApproveInfiniteInput, BuyAssetBySellIdInput, ExecuteTradeInput, GetTradeQuoteInput, Swapper, SwapperType, Trade, TradeQuote, TradeResult, TradeTxs } from '../../api';
|
|
4
4
|
import { ThorchainSwapperDeps } from './types';
|
|
5
5
|
export declare class ThorchainSwapper implements Swapper<ChainId> {
|
|
6
6
|
private swapSupportedChainIds;
|
|
@@ -11,7 +11,7 @@ export declare class ThorchainSwapper implements Swapper<ChainId> {
|
|
|
11
11
|
getType(): SwapperType;
|
|
12
12
|
getUsdRate(input: Pick<Asset, 'symbol' | 'assetId'>): Promise<string>;
|
|
13
13
|
approvalNeeded(input: ApprovalNeededInput<'eip155:1'>): Promise<ApprovalNeededOutput>;
|
|
14
|
-
approveInfinite(): Promise<string>;
|
|
14
|
+
approveInfinite(input: ApproveInfiniteInput<'eip155:1'>): Promise<string>;
|
|
15
15
|
filterBuyAssetsBySellAssetId(args: BuyAssetBySellIdInput): AssetId[];
|
|
16
16
|
filterAssetIdsBySellable(): AssetId[];
|
|
17
17
|
buildTrade(): Promise<Trade<ChainId>>;
|
|
@@ -5,6 +5,7 @@ const caip_1 = require("@shapeshiftoss/caip");
|
|
|
5
5
|
const api_1 = require("../../api");
|
|
6
6
|
const getTradeQuote_1 = require("./getThorTradeQuote/getTradeQuote");
|
|
7
7
|
const thorTradeApprovalNeeded_1 = require("./thorTradeApprovalNeeded/thorTradeApprovalNeeded");
|
|
8
|
+
const thorTradeApproveInfinite_1 = require("./thorTradeApproveInfinite/thorTradeApproveInfinite");
|
|
8
9
|
const getUsdRate_1 = require("./utils/getUsdRate/getUsdRate");
|
|
9
10
|
const thorService_1 = require("./utils/thorService");
|
|
10
11
|
class ThorchainSwapper {
|
|
@@ -44,8 +45,8 @@ class ThorchainSwapper {
|
|
|
44
45
|
async approvalNeeded(input) {
|
|
45
46
|
return (0, thorTradeApprovalNeeded_1.thorTradeApprovalNeeded)({ deps: this.deps, input });
|
|
46
47
|
}
|
|
47
|
-
async approveInfinite() {
|
|
48
|
-
|
|
48
|
+
async approveInfinite(input) {
|
|
49
|
+
return (0, thorTradeApproveInfinite_1.thorTradeApproveInfinite)({ deps: this.deps, input });
|
|
49
50
|
}
|
|
50
51
|
filterBuyAssetsBySellAssetId(args) {
|
|
51
52
|
const { assetIds = [], sellAssetId } = args;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ApproveInfiniteInput } from '../../../api';
|
|
2
|
+
import { ThorchainSwapperDeps } from '../types';
|
|
3
|
+
export declare const thorTradeApproveInfinite: ({ deps, input }: {
|
|
4
|
+
deps: ThorchainSwapperDeps;
|
|
5
|
+
input: ApproveInfiniteInput<'eip155:1'>;
|
|
6
|
+
}) => Promise<string>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.thorTradeApproveInfinite = void 0;
|
|
4
|
+
const types_1 = require("@shapeshiftoss/types");
|
|
5
|
+
const api_1 = require("../../../api");
|
|
6
|
+
const erc20_abi_1 = require("../../utils/abi/erc20-abi");
|
|
7
|
+
const helpers_1 = require("../../utils/helpers/helpers");
|
|
8
|
+
const constants_1 = require("../utils/constants");
|
|
9
|
+
const thorTradeApproveInfinite = async ({ deps, input }) => {
|
|
10
|
+
try {
|
|
11
|
+
const { adapterManager, web3 } = deps;
|
|
12
|
+
const { quote, wallet } = input;
|
|
13
|
+
const sellAssetChainId = quote.sellAsset.chainId;
|
|
14
|
+
const adapter = adapterManager.get(types_1.KnownChainIds.EthereumMainnet);
|
|
15
|
+
if (!adapter)
|
|
16
|
+
throw new api_1.SwapError(`[thorTradeApproveInfinite] - No chain adapter found for ${sellAssetChainId}.`, {
|
|
17
|
+
code: api_1.SwapErrorTypes.UNSUPPORTED_CHAIN,
|
|
18
|
+
details: { sellAssetChainId }
|
|
19
|
+
});
|
|
20
|
+
const allowanceGrantRequired = await (0, helpers_1.grantAllowance)({
|
|
21
|
+
quote: {
|
|
22
|
+
...quote,
|
|
23
|
+
sellAmount: constants_1.MAX_ALLOWANCE
|
|
24
|
+
},
|
|
25
|
+
wallet,
|
|
26
|
+
adapter,
|
|
27
|
+
erc20Abi: erc20_abi_1.erc20Abi,
|
|
28
|
+
web3
|
|
29
|
+
});
|
|
30
|
+
return allowanceGrantRequired;
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
if (e instanceof api_1.SwapError)
|
|
34
|
+
throw e;
|
|
35
|
+
throw new api_1.SwapError('[ZrxApproveInfinite]', {
|
|
36
|
+
cause: e,
|
|
37
|
+
code: api_1.SwapErrorTypes.APPROVE_INFINITE_FAILED
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
exports.thorTradeApproveInfinite = thorTradeApproveInfinite;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MAX_THORCHAIN_TRADE = void 0;
|
|
3
|
+
exports.MAX_ALLOWANCE = exports.MAX_THORCHAIN_TRADE = void 0;
|
|
4
4
|
exports.MAX_THORCHAIN_TRADE = '100000000000000000000000000';
|
|
5
|
+
exports.MAX_ALLOWANCE = '100000000000000000000000000';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Asset } from '@shapeshiftoss/types';
|
|
2
2
|
import { TradeQuote } from '../../../api';
|
|
3
3
|
export declare const setupQuote: () => {
|
|
4
|
-
quoteInput: import("../../../api").
|
|
4
|
+
quoteInput: import("../../../api").GetEthTradeQuoteInput;
|
|
5
5
|
tradeQuote: TradeQuote<"eip155:1">;
|
|
6
6
|
buyAsset: Asset;
|
|
7
7
|
sellAsset: Asset;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { HDWallet } from '@shapeshiftoss/hdwallet-core';
|
|
1
2
|
import { Asset } from '@shapeshiftoss/types';
|
|
2
3
|
import { ZrxQuoteResponse } from '../../types';
|
|
3
4
|
export declare const setupZrxTradeQuoteResponse: () => {
|
|
@@ -6,17 +7,12 @@ export declare const setupZrxTradeQuoteResponse: () => {
|
|
|
6
7
|
sellAsset: Asset;
|
|
7
8
|
};
|
|
8
9
|
export declare const setupBuildTrade: () => {
|
|
9
|
-
buildTradeInput: {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
price: string;
|
|
13
|
-
to: string;
|
|
14
|
-
buyAmount: string;
|
|
15
|
-
buyAsset: Asset;
|
|
16
|
-
sendMax: boolean;
|
|
17
|
-
sellAssetAccountNumber: number;
|
|
10
|
+
buildTradeInput: import("../../../../api").CommonTradeInput & {
|
|
11
|
+
chainId: "eip155:1";
|
|
12
|
+
} & {
|
|
18
13
|
buyAssetAccountNumber: number;
|
|
19
|
-
|
|
14
|
+
slippage?: string | undefined;
|
|
15
|
+
wallet: HDWallet;
|
|
20
16
|
};
|
|
21
17
|
buyAsset: Asset;
|
|
22
18
|
sellAsset: Asset;
|
|
@@ -23,16 +23,14 @@ const setupBuildTrade = () => {
|
|
|
23
23
|
const sellAsset = { ...assets_1.FOX };
|
|
24
24
|
const buyAsset = { ...assets_1.WETH };
|
|
25
25
|
const buildTradeInput = {
|
|
26
|
+
chainId: 'eip155:1',
|
|
26
27
|
sellAmount: '1000000000000000000',
|
|
27
|
-
allowanceTarget: 'allowanceTargetAddress',
|
|
28
|
-
price: '1',
|
|
29
|
-
to: '0x123',
|
|
30
|
-
buyAmount: '',
|
|
31
28
|
buyAsset,
|
|
32
29
|
sendMax: false,
|
|
33
30
|
sellAssetAccountNumber: 0,
|
|
34
31
|
buyAssetAccountNumber: 0,
|
|
35
|
-
sellAsset
|
|
32
|
+
sellAsset,
|
|
33
|
+
wallet: {}
|
|
36
34
|
};
|
|
37
35
|
return { buildTradeInput, buyAsset, sellAsset };
|
|
38
36
|
};
|
package/package.json
CHANGED