@shapeshiftoss/swapper 5.2.0 → 5.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.
- package/dist/api.d.ts +30 -7
- package/dist/api.js +7 -1
- package/dist/manager/SwapperManager.d.ts +1 -1
- package/dist/swappercli.js +2 -1
- package/dist/swappers/test/TestSwapper.d.ts +4 -3
- package/dist/swappers/test/TestSwapper.js +6 -3
- package/dist/swappers/thorchain/ThorchainSwapper.d.ts +4 -3
- package/dist/swappers/thorchain/ThorchainSwapper.js +5 -2
- package/dist/swappers/zrx/ZrxApprovalNeeded/ZrxApprovalNeeded.d.ts +2 -2
- package/dist/swappers/zrx/ZrxSwapper.d.ts +4 -3
- package/dist/swappers/zrx/ZrxSwapper.js +8 -2
- package/dist/swappers/zrx/getZrxMinMax/getZrxMinMax.d.ts +2 -1
- package/dist/swappers/zrx/zrxExecuteTrade/zrxExecuteTrade.js +2 -2
- package/package.json +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AssetId } from '@shapeshiftoss/caip';
|
|
2
2
|
import { HDWallet } from '@shapeshiftoss/hdwallet-core';
|
|
3
|
-
import {
|
|
3
|
+
import { Asset, ChainSpecific, SupportedChainIds } from '@shapeshiftoss/types';
|
|
4
4
|
export declare const SwapError: {
|
|
5
5
|
new <V extends {
|
|
6
6
|
cause?: unknown;
|
|
@@ -90,11 +90,7 @@ export declare type ExecuteTradeInput<C extends SupportedChainIds> = {
|
|
|
90
90
|
wallet: HDWallet;
|
|
91
91
|
};
|
|
92
92
|
export declare type TradeResult = {
|
|
93
|
-
|
|
94
|
-
};
|
|
95
|
-
export declare type SwapSource = {
|
|
96
|
-
name: string;
|
|
97
|
-
proportion: string;
|
|
93
|
+
tradeId: string;
|
|
98
94
|
};
|
|
99
95
|
export declare type ApproveInfiniteInput<C extends SupportedChainIds> = {
|
|
100
96
|
quote: TradeQuote<C>;
|
|
@@ -104,6 +100,32 @@ export declare type ApprovalNeededInput<C extends SupportedChainIds> = {
|
|
|
104
100
|
quote: TradeQuote<C>;
|
|
105
101
|
wallet: HDWallet;
|
|
106
102
|
};
|
|
103
|
+
export declare type SwapSource = {
|
|
104
|
+
name: string;
|
|
105
|
+
proportion: string;
|
|
106
|
+
};
|
|
107
|
+
export interface MinMaxOutput {
|
|
108
|
+
minimum: string;
|
|
109
|
+
maximum: string;
|
|
110
|
+
}
|
|
111
|
+
export declare type GetMinMaxInput = {
|
|
112
|
+
sellAsset: Asset;
|
|
113
|
+
buyAsset: Asset;
|
|
114
|
+
};
|
|
115
|
+
export declare type ApprovalNeededOutput = {
|
|
116
|
+
approvalNeeded: boolean;
|
|
117
|
+
gas?: string;
|
|
118
|
+
gasPrice?: string;
|
|
119
|
+
};
|
|
120
|
+
export declare enum SwapperType {
|
|
121
|
+
Zrx = "0x",
|
|
122
|
+
Thorchain = "Thorchain",
|
|
123
|
+
Test = "Test"
|
|
124
|
+
}
|
|
125
|
+
export declare type TradeTxs = {
|
|
126
|
+
sellTxid: string;
|
|
127
|
+
buyTxid?: string;
|
|
128
|
+
};
|
|
107
129
|
export declare enum SwapErrorTypes {
|
|
108
130
|
ALLOWANCE_REQUIRED_FAILED = "ALLOWANCE_REQUIRED_FAILED",
|
|
109
131
|
APPROVE_INFINITE_FAILED = "APPROVE_INFINITE_FAILED",
|
|
@@ -145,7 +167,7 @@ export interface Swapper {
|
|
|
145
167
|
/**
|
|
146
168
|
* Execute a trade built with buildTrade by signing and broadcasting
|
|
147
169
|
*/
|
|
148
|
-
executeTrade(args: ExecuteTradeInput<SupportedChainIds>): Promise<
|
|
170
|
+
executeTrade(args: ExecuteTradeInput<SupportedChainIds>): Promise<TradeResult>;
|
|
149
171
|
/**
|
|
150
172
|
* Get a boolean if a quote needs approval
|
|
151
173
|
*/
|
|
@@ -162,5 +184,6 @@ export interface Swapper {
|
|
|
162
184
|
* Get supported sell assetIds
|
|
163
185
|
*/
|
|
164
186
|
filterAssetIdsBySellable(assetIds: AssetId[]): AssetId[];
|
|
187
|
+
getTradeTxs(tradeResult: TradeResult): Promise<TradeTxs>;
|
|
165
188
|
}
|
|
166
189
|
export {};
|
package/dist/api.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SwapErrorTypes = exports.SwapError = void 0;
|
|
3
|
+
exports.SwapErrorTypes = exports.SwapperType = exports.SwapError = void 0;
|
|
4
4
|
const errors_1 = require("@shapeshiftoss/errors");
|
|
5
5
|
exports.SwapError = (0, errors_1.createErrorClass)('SwapError');
|
|
6
|
+
var SwapperType;
|
|
7
|
+
(function (SwapperType) {
|
|
8
|
+
SwapperType["Zrx"] = "0x";
|
|
9
|
+
SwapperType["Thorchain"] = "Thorchain";
|
|
10
|
+
SwapperType["Test"] = "Test";
|
|
11
|
+
})(SwapperType = exports.SwapperType || (exports.SwapperType = {}));
|
|
6
12
|
// Swap Errors
|
|
7
13
|
var SwapErrorTypes;
|
|
8
14
|
(function (SwapErrorTypes) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SwapperType } from '@shapeshiftoss/types';
|
|
2
1
|
import { BuyAssetBySellIdInput, ByPairInput, SupportedSellAssetsInput, Swapper } from '..';
|
|
2
|
+
import { SwapperType } from '../api';
|
|
3
3
|
export declare class SwapperManager {
|
|
4
4
|
swappers: Map<SwapperType, Swapper>;
|
|
5
5
|
constructor();
|
package/dist/swappercli.js
CHANGED
|
@@ -11,6 +11,7 @@ const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
|
11
11
|
const dotenv_1 = __importDefault(require("dotenv"));
|
|
12
12
|
const readline_sync_1 = __importDefault(require("readline-sync"));
|
|
13
13
|
const web3_1 = __importDefault(require("web3"));
|
|
14
|
+
const api_1 = require("./api");
|
|
14
15
|
const SwapperManager_1 = require("./manager/SwapperManager");
|
|
15
16
|
const ZrxSwapper_1 = require("./swappers/zrx/ZrxSwapper");
|
|
16
17
|
dotenv_1.default.config();
|
|
@@ -83,7 +84,7 @@ const main = async () => {
|
|
|
83
84
|
const zrxSwapperDeps = { wallet, adapterManager, web3 };
|
|
84
85
|
const manager = new SwapperManager_1.SwapperManager();
|
|
85
86
|
const zrxSwapper = new ZrxSwapper_1.ZrxSwapper(zrxSwapperDeps);
|
|
86
|
-
manager.addSwapper(
|
|
87
|
+
manager.addSwapper(api_1.SwapperType.Zrx, zrxSwapper);
|
|
87
88
|
const swapper = await manager.getBestSwapper({
|
|
88
89
|
sellAssetId: 'eip155:1/slip44:60',
|
|
89
90
|
buyAssetId: 'eip155:1/erc20:0xc770eefad204b5180df6a14ee197d99d808ee52d'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AssetId } from '@shapeshiftoss/caip';
|
|
2
|
-
import {
|
|
3
|
-
import { BuyAssetBySellIdInput, Swapper, Trade, TradeQuote } from '../../api';
|
|
2
|
+
import { Asset, SupportedChainIds } from '@shapeshiftoss/types';
|
|
3
|
+
import { ApprovalNeededOutput, BuyAssetBySellIdInput, GetMinMaxInput, MinMaxOutput, Swapper, SwapperType, Trade, TradeQuote, TradeResult, TradeTxs } from '../../api';
|
|
4
4
|
/**
|
|
5
5
|
* Playground for testing different scenarios of multiple swappers in the manager.
|
|
6
6
|
* Meant for local testing only
|
|
@@ -18,5 +18,6 @@ export declare class TestSwapper implements Swapper {
|
|
|
18
18
|
filterAssetIdsBySellable(): AssetId[];
|
|
19
19
|
buildTrade(): Promise<Trade<SupportedChainIds>>;
|
|
20
20
|
getTradeQuote(): Promise<TradeQuote<SupportedChainIds>>;
|
|
21
|
-
executeTrade(): Promise<
|
|
21
|
+
executeTrade(): Promise<TradeResult>;
|
|
22
|
+
getTradeTxs(): Promise<TradeTxs>;
|
|
22
23
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TestSwapper = void 0;
|
|
4
|
-
const
|
|
4
|
+
const api_1 = require("../../api");
|
|
5
5
|
/**
|
|
6
6
|
* Playground for testing different scenarios of multiple swappers in the manager.
|
|
7
7
|
* Meant for local testing only
|
|
@@ -9,7 +9,7 @@ const types_1 = require("@shapeshiftoss/types");
|
|
|
9
9
|
class TestSwapper {
|
|
10
10
|
constructor() {
|
|
11
11
|
this.supportAssets = [
|
|
12
|
-
'bip122:
|
|
12
|
+
'bip122:000000000019d6689c085ae165831e93/slip44:0',
|
|
13
13
|
'cosmos:cosmoshub-4/slip44:118',
|
|
14
14
|
'eip155:1/erc20:0xc770eefad204b5180df6a14ee197d99d808ee52d'
|
|
15
15
|
];
|
|
@@ -18,7 +18,7 @@ class TestSwapper {
|
|
|
18
18
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
19
19
|
async initialize() { }
|
|
20
20
|
getType() {
|
|
21
|
-
return
|
|
21
|
+
return api_1.SwapperType.Test;
|
|
22
22
|
}
|
|
23
23
|
getUsdRate(input) {
|
|
24
24
|
console.info(input);
|
|
@@ -52,5 +52,8 @@ class TestSwapper {
|
|
|
52
52
|
async executeTrade() {
|
|
53
53
|
throw new Error('TestSwapper: executeTrade unimplemented');
|
|
54
54
|
}
|
|
55
|
+
async getTradeTxs() {
|
|
56
|
+
throw new Error('TestSwapper: executeTrade unimplemented');
|
|
57
|
+
}
|
|
55
58
|
}
|
|
56
59
|
exports.TestSwapper = TestSwapper;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AssetId } from '@shapeshiftoss/caip';
|
|
2
|
-
import {
|
|
3
|
-
import { Swapper, Trade, TradeQuote } from '../../api';
|
|
2
|
+
import { Asset, SupportedChainIds } from '@shapeshiftoss/types';
|
|
3
|
+
import { ApprovalNeededOutput, GetMinMaxInput, MinMaxOutput, Swapper, SwapperType, Trade, TradeQuote, TradeResult, TradeTxs } from '../../api';
|
|
4
4
|
export declare class ThorchainSwapper implements Swapper {
|
|
5
5
|
getType(): SwapperType;
|
|
6
6
|
initialize(): Promise<void>;
|
|
@@ -12,5 +12,6 @@ export declare class ThorchainSwapper implements Swapper {
|
|
|
12
12
|
filterAssetIdsBySellable(): AssetId[];
|
|
13
13
|
buildTrade(): Promise<Trade<SupportedChainIds>>;
|
|
14
14
|
getTradeQuote(): Promise<TradeQuote<SupportedChainIds>>;
|
|
15
|
-
executeTrade(): Promise<
|
|
15
|
+
executeTrade(): Promise<TradeResult>;
|
|
16
|
+
getTradeTxs(): Promise<TradeTxs>;
|
|
16
17
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ThorchainSwapper = void 0;
|
|
4
|
-
const
|
|
4
|
+
const api_1 = require("../../api");
|
|
5
5
|
class ThorchainSwapper {
|
|
6
6
|
getType() {
|
|
7
|
-
return
|
|
7
|
+
return api_1.SwapperType.Thorchain;
|
|
8
8
|
}
|
|
9
9
|
// TODO populate supported assets from midgard
|
|
10
10
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
@@ -38,5 +38,8 @@ class ThorchainSwapper {
|
|
|
38
38
|
async executeTrade() {
|
|
39
39
|
throw new Error('ThorchainSwapper: executeTrade unimplemented');
|
|
40
40
|
}
|
|
41
|
+
async getTradeTxs() {
|
|
42
|
+
throw new Error('ThorchainSwapper: executeTrade unimplemented');
|
|
43
|
+
}
|
|
41
44
|
}
|
|
42
45
|
exports.ThorchainSwapper = ThorchainSwapper;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ApprovalNeededInput } from '../../../api';
|
|
1
|
+
import { SupportedChainIds } from '@shapeshiftoss/types';
|
|
2
|
+
import { ApprovalNeededInput, ApprovalNeededOutput } from '../../../api';
|
|
3
3
|
import { ZrxSwapperDeps } from '../ZrxSwapper';
|
|
4
4
|
export declare function ZrxApprovalNeeded({ adapterManager, web3 }: ZrxSwapperDeps, { quote, wallet }: ApprovalNeededInput<SupportedChainIds>): Promise<ApprovalNeededOutput>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { AssetId } from '@shapeshiftoss/caip';
|
|
2
2
|
import { ChainAdapterManager } from '@shapeshiftoss/chain-adapters';
|
|
3
|
-
import {
|
|
3
|
+
import { Asset, SupportedChainIds } from '@shapeshiftoss/types';
|
|
4
4
|
import Web3 from 'web3';
|
|
5
|
-
import { ApprovalNeededInput, ApproveInfiniteInput, BuildTradeInput, BuyAssetBySellIdInput, ExecuteTradeInput, GetTradeQuoteInput, Swapper, TradeQuote, ZrxTrade } from '../../api';
|
|
5
|
+
import { ApprovalNeededInput, ApprovalNeededOutput, ApproveInfiniteInput, BuildTradeInput, BuyAssetBySellIdInput, ExecuteTradeInput, GetMinMaxInput, GetTradeQuoteInput, MinMaxOutput, Swapper, SwapperType, TradeQuote, TradeResult, TradeTxs, ZrxTrade } from '../../api';
|
|
6
6
|
export declare type ZrxSwapperDeps = {
|
|
7
7
|
adapterManager: ChainAdapterManager;
|
|
8
8
|
web3: Web3;
|
|
@@ -17,9 +17,10 @@ export declare class ZrxSwapper implements Swapper {
|
|
|
17
17
|
getTradeQuote(input: GetTradeQuoteInput): Promise<TradeQuote<SupportedChainIds>>;
|
|
18
18
|
getUsdRate(input: Pick<Asset, 'symbol' | 'assetId'>): Promise<string>;
|
|
19
19
|
getMinMax(input: GetMinMaxInput): Promise<MinMaxOutput>;
|
|
20
|
-
executeTrade(args: ExecuteTradeInput<SupportedChainIds>): Promise<
|
|
20
|
+
executeTrade(args: ExecuteTradeInput<SupportedChainIds>): Promise<TradeResult>;
|
|
21
21
|
approvalNeeded(args: ApprovalNeededInput<SupportedChainIds>): Promise<ApprovalNeededOutput>;
|
|
22
22
|
approveInfinite(args: ApproveInfiniteInput<SupportedChainIds>): Promise<string>;
|
|
23
23
|
filterBuyAssetsBySellAssetId(args: BuyAssetBySellIdInput): AssetId[];
|
|
24
24
|
filterAssetIdsBySellable(assetIds?: AssetId[]): AssetId[];
|
|
25
|
+
getTradeTxs(tradeResult: TradeResult): Promise<TradeTxs>;
|
|
25
26
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ZrxSwapper = void 0;
|
|
4
|
-
const
|
|
4
|
+
const api_1 = require("../../api");
|
|
5
5
|
const getZrxMinMax_1 = require("./getZrxMinMax/getZrxMinMax");
|
|
6
6
|
const getZrxTradeQuote_1 = require("./getZrxTradeQuote/getZrxTradeQuote");
|
|
7
7
|
const blacklist_1 = require("./utils/blacklist");
|
|
@@ -18,7 +18,7 @@ class ZrxSwapper {
|
|
|
18
18
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
19
19
|
async initialize() { }
|
|
20
20
|
getType() {
|
|
21
|
-
return
|
|
21
|
+
return api_1.SwapperType.Zrx;
|
|
22
22
|
}
|
|
23
23
|
async buildTrade(args) {
|
|
24
24
|
return (0, zrxBuildTrade_1.zrxBuildTrade)(this.deps, args);
|
|
@@ -50,6 +50,12 @@ class ZrxSwapper {
|
|
|
50
50
|
filterAssetIdsBySellable(assetIds = []) {
|
|
51
51
|
return assetIds.filter((id) => id.startsWith('eip155:1') && !blacklist_1.UNSUPPORTED_ASSETS.includes(id));
|
|
52
52
|
}
|
|
53
|
+
async getTradeTxs(tradeResult) {
|
|
54
|
+
return {
|
|
55
|
+
sellTxid: tradeResult.tradeId,
|
|
56
|
+
buyTxid: tradeResult.tradeId
|
|
57
|
+
};
|
|
58
|
+
}
|
|
53
59
|
}
|
|
54
60
|
exports.ZrxSwapper = ZrxSwapper;
|
|
55
61
|
ZrxSwapper.swapperName = 'ZrxSwapper';
|
|
@@ -30,14 +30,14 @@ async function zrxExecuteTrade({ adapterManager }, { trade, wallet }) {
|
|
|
30
30
|
if (wallet.supportsOfflineSigning()) {
|
|
31
31
|
const signedTx = await adapter.signTransaction({ txToSign: txWithQuoteData, wallet });
|
|
32
32
|
const txid = await adapter.broadcastTransaction(signedTx);
|
|
33
|
-
return { txid };
|
|
33
|
+
return { tradeId: txid };
|
|
34
34
|
}
|
|
35
35
|
else if (wallet.supportsBroadcast() && adapter.signAndBroadcastTransaction) {
|
|
36
36
|
const txid = await ((_f = adapter.signAndBroadcastTransaction) === null || _f === void 0 ? void 0 : _f.call(adapter, {
|
|
37
37
|
txToSign: txWithQuoteData,
|
|
38
38
|
wallet
|
|
39
39
|
}));
|
|
40
|
-
return { txid };
|
|
40
|
+
return { tradeId: txid };
|
|
41
41
|
}
|
|
42
42
|
else {
|
|
43
43
|
throw new api_1.SwapError('[zrxExecuteTrade]', {
|