@shapeshiftoss/swapper 2.1.0 → 2.2.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 +9 -2
- package/dist/manager/SwapperManager.d.ts +9 -4
- package/dist/manager/SwapperManager.js +13 -4
- package/dist/swappers/index.d.ts +1 -0
- package/dist/swappers/index.js +1 -0
- package/dist/swappers/test/TestSwapper.d.ts +23 -0
- package/dist/swappers/test/TestSwapper.js +59 -0
- package/dist/swappers/thorchain/ThorchainSwapper.js +2 -2
- package/dist/swappers/zrx/ZrxSwapper.js +3 -4
- package/package.json +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import { CAIP19 } from '@shapeshiftoss/caip';
|
|
2
2
|
import { HDWallet } from '@shapeshiftoss/hdwallet-core';
|
|
3
3
|
import { ApprovalNeededInput, ApprovalNeededOutput, ApproveInfiniteInput, Asset, BuildQuoteTxInput, ChainTypes, ExecQuoteInput, ExecQuoteOutput, GetQuoteInput, MinMaxOutput, Quote, SendMaxAmountInput, SwapperType } from '@shapeshiftoss/types';
|
|
4
|
+
export declare type SupportedAssetInput = {
|
|
5
|
+
assetIds: CAIP19[];
|
|
6
|
+
};
|
|
7
|
+
export declare type ByPairInput = {
|
|
8
|
+
sellAssetId: CAIP19;
|
|
9
|
+
buyAssetId: CAIP19;
|
|
10
|
+
};
|
|
4
11
|
export declare type BuyAssetBySellIdInput = {
|
|
5
12
|
sellAssetId: CAIP19;
|
|
6
|
-
|
|
13
|
+
assetIds: CAIP19[];
|
|
7
14
|
};
|
|
8
15
|
export declare type SupportedSellAssetsInput = {
|
|
9
|
-
|
|
16
|
+
assetIds: CAIP19[];
|
|
10
17
|
};
|
|
11
18
|
export declare class SwapError extends Error {
|
|
12
19
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { GetQuoteInput, SwapperType } from '@shapeshiftoss/types';
|
|
2
|
-
import { Swapper } from '..';
|
|
3
|
-
import { BuyAssetBySellIdInput, SupportedSellAssetsInput } from '../api';
|
|
2
|
+
import { BuyAssetBySellIdInput, ByPairInput, SupportedSellAssetsInput, Swapper } from '..';
|
|
4
3
|
export declare class SwapperError extends Error {
|
|
5
4
|
constructor(message: string);
|
|
6
5
|
}
|
|
@@ -27,6 +26,12 @@ export declare class SwapperManager {
|
|
|
27
26
|
*/
|
|
28
27
|
removeSwapper(swapperType: SwapperType): this;
|
|
29
28
|
getBestSwapper(quoteParams: GetQuoteInput): Promise<SwapperType>;
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* @param pair type {GetQuoteInput}
|
|
32
|
+
* @returns {SwapperType}
|
|
33
|
+
*/
|
|
34
|
+
getSwappersByPair(pair: ByPairInput): Swapper[];
|
|
35
|
+
getSupportedBuyAssetIdsFromSellId(args: BuyAssetBySellIdInput): string[];
|
|
36
|
+
getSupportedSellableAssetIds(args: SupportedSellAssetsInput): string[];
|
|
32
37
|
}
|
|
@@ -63,12 +63,21 @@ class SwapperManager {
|
|
|
63
63
|
quoteParams; // noop to shut up linter
|
|
64
64
|
return types_1.SwapperType.Zrx; // TODO: implement getBestSwapper
|
|
65
65
|
}
|
|
66
|
-
|
|
66
|
+
/**
|
|
67
|
+
*
|
|
68
|
+
* @param pair type {GetQuoteInput}
|
|
69
|
+
* @returns {SwapperType}
|
|
70
|
+
*/
|
|
71
|
+
getSwappersByPair(pair) {
|
|
72
|
+
const { sellAssetId, buyAssetId } = pair;
|
|
73
|
+
return Array.from(this.swappers.values()).filter((swapper) => swapper.filterBuyAssetsBySellAssetId({ sellAssetId, assetIds: [buyAssetId] }).length);
|
|
74
|
+
}
|
|
75
|
+
getSupportedBuyAssetIdsFromSellId(args) {
|
|
67
76
|
return (0, uniq_1.default)(Array.from(this.swappers.values()).flatMap((swapper) => swapper.filterBuyAssetsBySellAssetId(args)));
|
|
68
77
|
}
|
|
69
|
-
|
|
70
|
-
const {
|
|
71
|
-
return (0, uniq_1.default)(Array.from(this.swappers.values()).flatMap((swapper) => swapper.filterAssetIdsBySellable(
|
|
78
|
+
getSupportedSellableAssetIds(args) {
|
|
79
|
+
const { assetIds } = args;
|
|
80
|
+
return (0, uniq_1.default)(Array.from(this.swappers.values()).flatMap((swapper) => swapper.filterAssetIdsBySellable(assetIds)));
|
|
72
81
|
}
|
|
73
82
|
}
|
|
74
83
|
exports.SwapperManager = SwapperManager;
|
package/dist/swappers/index.d.ts
CHANGED
package/dist/swappers/index.js
CHANGED
|
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./zrx/ZrxSwapper"), exports);
|
|
18
18
|
__exportStar(require("./thorchain/ThorchainSwapper"), exports);
|
|
19
|
+
__exportStar(require("./test/TestSwapper"), exports);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CAIP19 } from '@shapeshiftoss/caip';
|
|
2
|
+
import { ApprovalNeededOutput, Asset, ChainTypes, ExecQuoteOutput, GetQuoteInput, MinMaxOutput, Quote, SwapperType } from '@shapeshiftoss/types';
|
|
3
|
+
import { BuyAssetBySellIdInput, Swapper } from '../../api';
|
|
4
|
+
/**
|
|
5
|
+
* Playground for testing different scenarios of multiple swappers in the manager.
|
|
6
|
+
* Meant for local testing only
|
|
7
|
+
*/
|
|
8
|
+
export declare class TestSwapper implements Swapper {
|
|
9
|
+
supportAssets: string[];
|
|
10
|
+
getType(): SwapperType;
|
|
11
|
+
constructor();
|
|
12
|
+
getQuote(): Promise<Quote<ChainTypes, SwapperType>>;
|
|
13
|
+
buildQuoteTx(): Promise<Quote<ChainTypes, SwapperType>>;
|
|
14
|
+
getUsdRate(input: Pick<Asset, 'symbol' | 'tokenId'>): Promise<string>;
|
|
15
|
+
getMinMax(input: GetQuoteInput): Promise<MinMaxOutput>;
|
|
16
|
+
executeQuote(): Promise<ExecQuoteOutput>;
|
|
17
|
+
getDefaultPair(): [CAIP19, CAIP19];
|
|
18
|
+
approvalNeeded(): Promise<ApprovalNeededOutput>;
|
|
19
|
+
approveInfinite(): Promise<string>;
|
|
20
|
+
getSendMaxAmount(): Promise<string>;
|
|
21
|
+
filterBuyAssetsBySellAssetId(args: BuyAssetBySellIdInput): CAIP19[];
|
|
22
|
+
filterAssetIdsBySellable(): CAIP19[];
|
|
23
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TestSwapper = void 0;
|
|
4
|
+
const types_1 = require("@shapeshiftoss/types");
|
|
5
|
+
/**
|
|
6
|
+
* Playground for testing different scenarios of multiple swappers in the manager.
|
|
7
|
+
* Meant for local testing only
|
|
8
|
+
*/
|
|
9
|
+
class TestSwapper {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.supportAssets = [
|
|
12
|
+
'bip122:000000000933ea01ad0ee984209779ba/slip44:0',
|
|
13
|
+
'cosmos:cosmoshub-4/slip44:118',
|
|
14
|
+
'eip155:1/erc20:0xc770eefad204b5180df6a14ee197d99d808ee52d'
|
|
15
|
+
];
|
|
16
|
+
}
|
|
17
|
+
getType() {
|
|
18
|
+
return types_1.SwapperType.Test;
|
|
19
|
+
}
|
|
20
|
+
async getQuote() {
|
|
21
|
+
throw new Error('TestSwapper: getQuote unimplemented');
|
|
22
|
+
}
|
|
23
|
+
async buildQuoteTx() {
|
|
24
|
+
throw new Error('TestSwapper: getQuote unimplemented');
|
|
25
|
+
}
|
|
26
|
+
getUsdRate(input) {
|
|
27
|
+
console.info(input);
|
|
28
|
+
throw new Error('TestSwapper: getUsdRate unimplemented');
|
|
29
|
+
}
|
|
30
|
+
getMinMax(input) {
|
|
31
|
+
console.info(input);
|
|
32
|
+
throw new Error('TestSwapper: getMinMax unimplemented');
|
|
33
|
+
}
|
|
34
|
+
async executeQuote() {
|
|
35
|
+
throw new Error('TestSwapper: executeQuote unimplemented');
|
|
36
|
+
}
|
|
37
|
+
getDefaultPair() {
|
|
38
|
+
throw new Error('TestSwapper: getDefaultPair unimplemented');
|
|
39
|
+
}
|
|
40
|
+
async approvalNeeded() {
|
|
41
|
+
throw new Error('TestSwapper: approvalNeeded unimplemented');
|
|
42
|
+
}
|
|
43
|
+
async approveInfinite() {
|
|
44
|
+
throw new Error('TestSwapper: approveInfinite unimplemented');
|
|
45
|
+
}
|
|
46
|
+
async getSendMaxAmount() {
|
|
47
|
+
throw new Error('TestSwapper: getSendMaxAmount unimplemented');
|
|
48
|
+
}
|
|
49
|
+
filterBuyAssetsBySellAssetId(args) {
|
|
50
|
+
const { sellAssetId } = args;
|
|
51
|
+
if (!this.supportAssets.includes(sellAssetId))
|
|
52
|
+
return [];
|
|
53
|
+
return this.supportAssets;
|
|
54
|
+
}
|
|
55
|
+
filterAssetIdsBySellable() {
|
|
56
|
+
return this.supportAssets;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.TestSwapper = TestSwapper;
|
|
@@ -36,10 +36,10 @@ class ThorchainSwapper {
|
|
|
36
36
|
throw new Error('ThorchainSwapper: getSendMaxAmount unimplemented');
|
|
37
37
|
}
|
|
38
38
|
filterBuyAssetsBySellAssetId() {
|
|
39
|
-
|
|
39
|
+
return [];
|
|
40
40
|
}
|
|
41
41
|
filterAssetIdsBySellable() {
|
|
42
|
-
|
|
42
|
+
return [];
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
exports.ThorchainSwapper = ThorchainSwapper;
|
|
@@ -54,13 +54,12 @@ class ZrxSwapper {
|
|
|
54
54
|
return (0, getZrxSendMaxAmount_1.getZrxSendMaxAmount)(this.deps, args);
|
|
55
55
|
}
|
|
56
56
|
filterBuyAssetsBySellAssetId(args) {
|
|
57
|
-
const {
|
|
57
|
+
const { assetIds, sellAssetId } = args;
|
|
58
58
|
// TODO: pending changes to caip lib, we may want to import caip2 value instead.
|
|
59
|
-
return
|
|
59
|
+
return assetIds.filter((id) => id.startsWith('eip155:1') && sellAssetId.startsWith('eip155:1'));
|
|
60
60
|
}
|
|
61
61
|
filterAssetIdsBySellable(assetIds) {
|
|
62
|
-
|
|
63
|
-
return this.filterBuyAssetsBySellAssetId({ buyAssetIds: assetIds, sellAssetId: '' });
|
|
62
|
+
return assetIds.filter((id) => id.startsWith('eip155:1'));
|
|
64
63
|
}
|
|
65
64
|
}
|
|
66
65
|
exports.ZrxSwapper = ZrxSwapper;
|