@shapeshiftoss/swapper 5.6.0 → 5.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/swappercli.js +1 -1
- package/dist/swappers/thorchain/ThorchainSwapper.d.ts +1 -3
- package/dist/swappers/thorchain/ThorchainSwapper.js +4 -7
- package/dist/swappers/thorchain/types.d.ts +3 -0
- package/dist/swappers/thorchain/utils/getUsdRate/getUsdRate.d.ts +6 -0
- package/dist/swappers/thorchain/utils/getUsdRate/getUsdRate.js +32 -0
- package/dist/swappers/thorchain/utils/{makeSwapMemo.d.ts → makeSwapMemo/makeSwapMemo.d.ts} +0 -0
- package/dist/swappers/thorchain/utils/{makeSwapMemo.js → makeSwapMemo/makeSwapMemo.js} +1 -1
- package/dist/swappers/thorchain/utils/test-data/midgardResponse.d.ts +5 -14
- package/dist/swappers/thorchain/utils/test-data/midgardResponse.js +44 -45
- package/dist/swappers/thorchain/utils/thorService.d.ts +1 -0
- package/dist/swappers/thorchain/utils/thorService.js +15 -0
- package/package.json +1 -1
package/dist/swappercli.js
CHANGED
|
@@ -84,7 +84,7 @@ const main = async () => {
|
|
|
84
84
|
const web3 = new web3_1.default(web3Provider);
|
|
85
85
|
const zrxSwapperDeps = { wallet, adapterManager, web3 };
|
|
86
86
|
const thorchainSwapperDeps = {
|
|
87
|
-
midgardUrl: 'https://midgard.thorchain.info/v2
|
|
87
|
+
midgardUrl: 'https://midgard.thorchain.info/v2'
|
|
88
88
|
};
|
|
89
89
|
const manager = new SwapperManager_1.SwapperManager();
|
|
90
90
|
const zrxSwapper = new ZrxSwapper_1.ZrxSwapper(zrxSwapperDeps);
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { AssetId } from '@shapeshiftoss/caip';
|
|
2
2
|
import { Asset, SupportedChainIds } from '@shapeshiftoss/types';
|
|
3
3
|
import { ApprovalNeededOutput, BuyAssetBySellIdInput, GetMinMaxInput, MinMaxOutput, Swapper, SwapperType, Trade, TradeQuote, TradeResult, TradeTxs } from '../../api';
|
|
4
|
-
|
|
5
|
-
midgardUrl: string;
|
|
6
|
-
};
|
|
4
|
+
import { ThorchainSwapperDeps } from './types';
|
|
7
5
|
export declare class ThorchainSwapper implements Swapper {
|
|
8
6
|
private supportedAssetIds;
|
|
9
7
|
deps: ThorchainSwapperDeps;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.ThorchainSwapper = void 0;
|
|
7
4
|
const caip_1 = require("@shapeshiftoss/caip");
|
|
8
|
-
const axios_1 = __importDefault(require("axios"));
|
|
9
5
|
const api_1 = require("../../api");
|
|
6
|
+
const getUsdRate_1 = require("./utils/getUsdRate/getUsdRate");
|
|
7
|
+
const thorService_1 = require("./utils/thorService");
|
|
10
8
|
class ThorchainSwapper {
|
|
11
9
|
constructor(deps) {
|
|
12
10
|
this.supportedAssetIds = [];
|
|
@@ -14,7 +12,7 @@ class ThorchainSwapper {
|
|
|
14
12
|
}
|
|
15
13
|
async initialize() {
|
|
16
14
|
try {
|
|
17
|
-
const { data: responseData } = await
|
|
15
|
+
const { data: responseData } = await thorService_1.thorService.get(`${this.deps.midgardUrl}/pools`);
|
|
18
16
|
const supportedAssetIds = responseData.reduce((acc, midgardPool) => {
|
|
19
17
|
const assetId = caip_1.adapters.poolAssetIdToAssetId(midgardPool.asset);
|
|
20
18
|
if (!assetId)
|
|
@@ -35,8 +33,7 @@ class ThorchainSwapper {
|
|
|
35
33
|
return api_1.SwapperType.Thorchain;
|
|
36
34
|
}
|
|
37
35
|
getUsdRate(input) {
|
|
38
|
-
|
|
39
|
-
throw new Error('ThorchainSwapper: getUsdRate unimplemented');
|
|
36
|
+
return (0, getUsdRate_1.getUsdRate)({ deps: this.deps, input });
|
|
40
37
|
}
|
|
41
38
|
getMinMax(input) {
|
|
42
39
|
console.info(input);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getUsdRate = void 0;
|
|
4
|
+
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
|
+
const api_1 = require("../../../../api");
|
|
6
|
+
const thorService_1 = require("../thorService");
|
|
7
|
+
const getUsdRate = async ({ deps, input }) => {
|
|
8
|
+
const { assetId } = input;
|
|
9
|
+
try {
|
|
10
|
+
const thorchainPoolId = caip_1.adapters.assetIdToPoolAssetId({ assetId });
|
|
11
|
+
if (!thorchainPoolId)
|
|
12
|
+
throw new api_1.SwapError(`[getUsdRate]: No thorchainPoolId found for assetId: ${assetId}`, {
|
|
13
|
+
code: api_1.SwapErrorTypes.USD_RATE_FAILED
|
|
14
|
+
});
|
|
15
|
+
const { data: responseData } = await thorService_1.thorService.get(`${deps.midgardUrl}/pool/${thorchainPoolId}`);
|
|
16
|
+
const rate = responseData === null || responseData === void 0 ? void 0 : responseData.assetPriceUSD;
|
|
17
|
+
if (!rate)
|
|
18
|
+
throw new api_1.SwapError(`[getUsdRate]: No rate found`, {
|
|
19
|
+
code: api_1.SwapErrorTypes.USD_RATE_FAILED
|
|
20
|
+
});
|
|
21
|
+
return rate;
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
if (e instanceof api_1.SwapError)
|
|
25
|
+
throw e;
|
|
26
|
+
throw new api_1.SwapError('[getUsdRate]: Thorchain getUsdRate failed', {
|
|
27
|
+
code: api_1.SwapErrorTypes.USD_RATE_FAILED,
|
|
28
|
+
cause: e
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
exports.getUsdRate = getUsdRate;
|
|
File without changes
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.makeSwapMemo = void 0;
|
|
4
4
|
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
|
-
const api_1 = require("
|
|
5
|
+
const api_1 = require("../../../../api");
|
|
6
6
|
// BTC (and likely other utxo coins) can only support up to 80 character memos
|
|
7
7
|
const MAX_LENGTH = 80;
|
|
8
8
|
/**
|
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
liquidityUnits: string;
|
|
7
|
-
poolAPY: string;
|
|
8
|
-
runeDepth: string;
|
|
9
|
-
status: string;
|
|
10
|
-
synthSupply: string;
|
|
11
|
-
synthUnits: string;
|
|
12
|
-
units: string;
|
|
13
|
-
volume24h: string;
|
|
14
|
-
}[];
|
|
1
|
+
import { MidgardResponse } from '../../types';
|
|
2
|
+
export declare const btcMidgardPool: MidgardResponse;
|
|
3
|
+
export declare const ethMidgardPool: MidgardResponse;
|
|
4
|
+
export declare const foxMidgardPool: MidgardResponse;
|
|
5
|
+
export declare const midgardResponse: MidgardResponse[];
|
|
@@ -1,47 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.midgardResponse = void 0;
|
|
4
|
-
exports.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
];
|
|
3
|
+
exports.midgardResponse = exports.foxMidgardPool = exports.ethMidgardPool = exports.btcMidgardPool = void 0;
|
|
4
|
+
exports.btcMidgardPool = {
|
|
5
|
+
asset: 'BTC.BTC',
|
|
6
|
+
assetDepth: '91027798705',
|
|
7
|
+
assetPrice: '10280.68095465986',
|
|
8
|
+
assetPriceUSD: '29850.505131750208',
|
|
9
|
+
liquidityUnits: '536055974608843',
|
|
10
|
+
poolAPY: '0.09305294391574037',
|
|
11
|
+
runeDepth: '935827756491105',
|
|
12
|
+
status: 'available',
|
|
13
|
+
synthSupply: '3281284823',
|
|
14
|
+
synthUnits: '9838954536080',
|
|
15
|
+
units: '545894929144923',
|
|
16
|
+
volume24h: '15031085906495'
|
|
17
|
+
};
|
|
18
|
+
exports.ethMidgardPool = {
|
|
19
|
+
asset: 'ETH.ETH',
|
|
20
|
+
assetDepth: '915018987646',
|
|
21
|
+
assetPrice: '676.2118757936507',
|
|
22
|
+
assetPriceUSD: '1963.4172247490626',
|
|
23
|
+
liquidityUnits: '273709963437801',
|
|
24
|
+
poolAPY: '0.10532151323548256',
|
|
25
|
+
runeDepth: '618746706022909',
|
|
26
|
+
status: 'available',
|
|
27
|
+
synthSupply: '3572065751',
|
|
28
|
+
synthUnits: '535301524652',
|
|
29
|
+
units: '274245264962453',
|
|
30
|
+
volume24h: '9890096673763'
|
|
31
|
+
};
|
|
32
|
+
exports.foxMidgardPool = {
|
|
33
|
+
asset: 'ETH.FOX-0XC770EEFAD204B5180DF6A14EE197D99D808EE52D',
|
|
34
|
+
assetDepth: '166650912393467',
|
|
35
|
+
assetPrice: '0.05303710198887871',
|
|
36
|
+
assetPriceUSD: '0.15399605260336216',
|
|
37
|
+
liquidityUnits: '10015457121887',
|
|
38
|
+
poolAPY: '0.2597568967423438',
|
|
39
|
+
runeDepth: '8838681437152',
|
|
40
|
+
status: 'available',
|
|
41
|
+
synthSupply: '17428372569375',
|
|
42
|
+
synthUnits: '552604585625',
|
|
43
|
+
units: '10568061707512',
|
|
44
|
+
volume24h: '251596933033'
|
|
45
|
+
};
|
|
46
|
+
exports.midgardResponse = [exports.btcMidgardPool, exports.ethMidgardPool, exports.foxMidgardPool];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const thorService: import("axios").AxiosInstance;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.thorService = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const axiosConfig = {
|
|
9
|
+
timeout: 10000,
|
|
10
|
+
headers: {
|
|
11
|
+
Accept: 'application/json',
|
|
12
|
+
'Content-Type': 'application/json'
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
exports.thorService = axios_1.default.create(axiosConfig);
|