@shapeshiftoss/swapper 5.2.1 → 5.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 +8 -2
- package/dist/api.js +1 -0
- package/dist/swappers/test/TestSwapper.d.ts +2 -1
- package/dist/swappers/test/TestSwapper.js +4 -1
- package/dist/swappers/thorchain/ThorchainSwapper.d.ts +2 -1
- package/dist/swappers/thorchain/ThorchainSwapper.js +3 -0
- package/dist/swappers/thorchain/utils/makeSwapMemo.d.ts +9 -0
- package/dist/swappers/thorchain/utils/makeSwapMemo.js +36 -0
- package/dist/swappers/zrx/ZrxSwapper.d.ts +2 -1
- package/dist/swappers/zrx/ZrxSwapper.js +6 -0
- package/dist/swappers/zrx/zrxExecuteTrade/zrxExecuteTrade.js +2 -2
- package/package.json +3 -3
package/dist/api.d.ts
CHANGED
|
@@ -90,7 +90,7 @@ export declare type ExecuteTradeInput<C extends SupportedChainIds> = {
|
|
|
90
90
|
wallet: HDWallet;
|
|
91
91
|
};
|
|
92
92
|
export declare type TradeResult = {
|
|
93
|
-
|
|
93
|
+
tradeId: string;
|
|
94
94
|
};
|
|
95
95
|
export declare type ApproveInfiniteInput<C extends SupportedChainIds> = {
|
|
96
96
|
quote: TradeQuote<C>;
|
|
@@ -122,6 +122,10 @@ export declare enum SwapperType {
|
|
|
122
122
|
Thorchain = "Thorchain",
|
|
123
123
|
Test = "Test"
|
|
124
124
|
}
|
|
125
|
+
export declare type TradeTxs = {
|
|
126
|
+
sellTxid: string;
|
|
127
|
+
buyTxid?: string;
|
|
128
|
+
};
|
|
125
129
|
export declare enum SwapErrorTypes {
|
|
126
130
|
ALLOWANCE_REQUIRED_FAILED = "ALLOWANCE_REQUIRED_FAILED",
|
|
127
131
|
APPROVE_INFINITE_FAILED = "APPROVE_INFINITE_FAILED",
|
|
@@ -137,7 +141,8 @@ export declare enum SwapErrorTypes {
|
|
|
137
141
|
UNSUPPORTED_PAIR = "UNSUPPORTED_PAIR",
|
|
138
142
|
USD_RATE_FAILED = "USD_RATE_FAILED",
|
|
139
143
|
UNSUPPORTED_CHAIN = "UNSUPPORTED_CHAIN",
|
|
140
|
-
VALIDATION_FAILED = "VALIDATION_FAILED"
|
|
144
|
+
VALIDATION_FAILED = "VALIDATION_FAILED",
|
|
145
|
+
MAKE_MEMO_FAILED = "MAKE_MEMO_FAILED"
|
|
141
146
|
}
|
|
142
147
|
export interface Swapper {
|
|
143
148
|
/** perform any necessary async initialization */
|
|
@@ -180,5 +185,6 @@ export interface Swapper {
|
|
|
180
185
|
* Get supported sell assetIds
|
|
181
186
|
*/
|
|
182
187
|
filterAssetIdsBySellable(assetIds: AssetId[]): AssetId[];
|
|
188
|
+
getTradeTxs(tradeResult: TradeResult): Promise<TradeTxs>;
|
|
183
189
|
}
|
|
184
190
|
export {};
|
package/dist/api.js
CHANGED
|
@@ -27,4 +27,5 @@ var SwapErrorTypes;
|
|
|
27
27
|
SwapErrorTypes["USD_RATE_FAILED"] = "USD_RATE_FAILED";
|
|
28
28
|
SwapErrorTypes["UNSUPPORTED_CHAIN"] = "UNSUPPORTED_CHAIN";
|
|
29
29
|
SwapErrorTypes["VALIDATION_FAILED"] = "VALIDATION_FAILED";
|
|
30
|
+
SwapErrorTypes["MAKE_MEMO_FAILED"] = "MAKE_MEMO_FAILED";
|
|
30
31
|
})(SwapErrorTypes = exports.SwapErrorTypes || (exports.SwapErrorTypes = {}));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AssetId } from '@shapeshiftoss/caip';
|
|
2
2
|
import { Asset, SupportedChainIds } from '@shapeshiftoss/types';
|
|
3
|
-
import { ApprovalNeededOutput, BuyAssetBySellIdInput, GetMinMaxInput, MinMaxOutput, Swapper, SwapperType, Trade, TradeQuote, TradeResult } from '../../api';
|
|
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
|
|
@@ -19,4 +19,5 @@ export declare class TestSwapper implements Swapper {
|
|
|
19
19
|
buildTrade(): Promise<Trade<SupportedChainIds>>;
|
|
20
20
|
getTradeQuote(): Promise<TradeQuote<SupportedChainIds>>;
|
|
21
21
|
executeTrade(): Promise<TradeResult>;
|
|
22
|
+
getTradeTxs(): Promise<TradeTxs>;
|
|
22
23
|
}
|
|
@@ -9,7 +9,7 @@ const api_1 = require("../../api");
|
|
|
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
|
];
|
|
@@ -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
2
|
import { Asset, SupportedChainIds } from '@shapeshiftoss/types';
|
|
3
|
-
import { ApprovalNeededOutput, GetMinMaxInput, MinMaxOutput, Swapper, SwapperType, Trade, TradeQuote, TradeResult } from '../../api';
|
|
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>;
|
|
@@ -13,4 +13,5 @@ export declare class ThorchainSwapper implements Swapper {
|
|
|
13
13
|
buildTrade(): Promise<Trade<SupportedChainIds>>;
|
|
14
14
|
getTradeQuote(): Promise<TradeQuote<SupportedChainIds>>;
|
|
15
15
|
executeTrade(): Promise<TradeResult>;
|
|
16
|
+
getTradeTxs(): Promise<TradeTxs>;
|
|
16
17
|
}
|
|
@@ -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;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @returns thorchain memo shortened to a max of 80 characters as described:
|
|
3
|
+
* https://dev.thorchain.org/thorchain-dev/memos#mechanism-for-transaction-intent
|
|
4
|
+
*/
|
|
5
|
+
export declare const makeSwapMemo: ({ buyAssetId, destinationAddress, limit }: {
|
|
6
|
+
buyAssetId: string;
|
|
7
|
+
destinationAddress: string;
|
|
8
|
+
limit: string;
|
|
9
|
+
}) => string;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeSwapMemo = void 0;
|
|
4
|
+
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
|
+
const api_1 = require("../../../api");
|
|
6
|
+
// BTC (and likely other utxo coins) can only support up to 80 character memos
|
|
7
|
+
const MAX_LENGTH = 80;
|
|
8
|
+
/**
|
|
9
|
+
* @returns thorchain memo shortened to a max of 80 characters as described:
|
|
10
|
+
* https://dev.thorchain.org/thorchain-dev/memos#mechanism-for-transaction-intent
|
|
11
|
+
*/
|
|
12
|
+
const makeSwapMemo = ({ buyAssetId, destinationAddress, limit }) => {
|
|
13
|
+
const thorId = caip_1.adapters.assetIdToPoolAssetId({ assetId: buyAssetId });
|
|
14
|
+
if (!thorId)
|
|
15
|
+
throw new api_1.SwapError('[makeSwapMemo] - undefined thorId for given buyAssetId', {
|
|
16
|
+
code: api_1.SwapErrorTypes.MAKE_MEMO_FAILED,
|
|
17
|
+
details: { buyAssetId }
|
|
18
|
+
});
|
|
19
|
+
const memo = `s:${thorId}:${destinationAddress}:${limit}`;
|
|
20
|
+
if (memo.length <= MAX_LENGTH)
|
|
21
|
+
return memo;
|
|
22
|
+
const abbreviationAmount = memo.length - MAX_LENGTH;
|
|
23
|
+
if (abbreviationAmount > 39)
|
|
24
|
+
throw new api_1.SwapError('[makeSwapMemo] - too much abbreviation for accurate matching', {
|
|
25
|
+
code: api_1.SwapErrorTypes.MAKE_MEMO_FAILED
|
|
26
|
+
});
|
|
27
|
+
// delimeter between ticker and id allowing us to abbreviate the id: https://dev.thorchain.org/thorchain-dev/memos#asset-notation
|
|
28
|
+
const delimeterIndex = memo.indexOf('-') + 1;
|
|
29
|
+
if (!delimeterIndex) {
|
|
30
|
+
throw new api_1.SwapError('[makeSwapMemo] - unable to abbreviate asset, no delimeter found', {
|
|
31
|
+
code: api_1.SwapErrorTypes.MAKE_MEMO_FAILED
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return memo.replace(memo.slice(delimeterIndex, delimeterIndex + abbreviationAmount), '');
|
|
35
|
+
};
|
|
36
|
+
exports.makeSwapMemo = makeSwapMemo;
|
|
@@ -2,7 +2,7 @@ import { AssetId } from '@shapeshiftoss/caip';
|
|
|
2
2
|
import { ChainAdapterManager } from '@shapeshiftoss/chain-adapters';
|
|
3
3
|
import { Asset, SupportedChainIds } from '@shapeshiftoss/types';
|
|
4
4
|
import Web3 from 'web3';
|
|
5
|
-
import { ApprovalNeededInput, ApprovalNeededOutput, ApproveInfiniteInput, BuildTradeInput, BuyAssetBySellIdInput, ExecuteTradeInput, GetMinMaxInput, GetTradeQuoteInput, MinMaxOutput, Swapper, SwapperType, TradeQuote, TradeResult, 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;
|
|
@@ -22,4 +22,5 @@ export declare class ZrxSwapper implements Swapper {
|
|
|
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
|
}
|
|
@@ -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]', {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shapeshiftoss/swapper",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.0",
|
|
4
4
|
"description": "TODO: description",
|
|
5
5
|
"repository": "https://github.com/shapeshift/lib",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"@shapeshiftoss/asset-service": "^4.2.4",
|
|
34
|
-
"@shapeshiftoss/caip": "^5.
|
|
34
|
+
"@shapeshiftoss/caip": "^5.2.1",
|
|
35
35
|
"@shapeshiftoss/chain-adapters": "^4.3.3",
|
|
36
36
|
"@shapeshiftoss/hdwallet-core": "1.20.0",
|
|
37
37
|
"@shapeshiftoss/types": "^4.3.1",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@shapeshiftoss/asset-service": "^4.2.4",
|
|
42
|
-
"@shapeshiftoss/caip": "^5.
|
|
42
|
+
"@shapeshiftoss/caip": "^5.2.1",
|
|
43
43
|
"@shapeshiftoss/chain-adapters": "^4.3.3",
|
|
44
44
|
"@shapeshiftoss/hdwallet-core": "^1.20.0",
|
|
45
45
|
"@shapeshiftoss/types": "^4.3.1",
|