@shapeshiftoss/swapper 5.6.0 → 5.8.1

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.
Files changed (26) hide show
  1. package/dist/api.d.ts +2 -7
  2. package/dist/api.js +1 -0
  3. package/dist/swappercli.js +2 -1
  4. package/dist/swappers/cow/CowSwapper.d.ts +1 -2
  5. package/dist/swappers/cow/CowSwapper.js +0 -4
  6. package/dist/swappers/test/TestSwapper.d.ts +1 -2
  7. package/dist/swappers/test/TestSwapper.js +0 -4
  8. package/dist/swappers/thorchain/ThorchainSwapper.d.ts +2 -5
  9. package/dist/swappers/thorchain/ThorchainSwapper.js +4 -11
  10. package/dist/swappers/thorchain/types.d.ts +13 -0
  11. package/dist/swappers/thorchain/utils/ethereum/makeTradeTx.d.ts +23 -0
  12. package/dist/swappers/thorchain/utils/ethereum/makeTradeTx.js +81 -0
  13. package/dist/swappers/thorchain/utils/getPriceRatio/getPriceRatio.d.ts +6 -0
  14. package/dist/swappers/thorchain/utils/getPriceRatio/getPriceRatio.js +38 -0
  15. package/dist/swappers/thorchain/utils/getUsdRate/getUsdRate.d.ts +6 -0
  16. package/dist/swappers/thorchain/utils/getUsdRate/getUsdRate.js +32 -0
  17. package/dist/swappers/thorchain/utils/{makeSwapMemo.d.ts → makeSwapMemo/makeSwapMemo.d.ts} +0 -0
  18. package/dist/swappers/thorchain/utils/{makeSwapMemo.js → makeSwapMemo/makeSwapMemo.js} +1 -1
  19. package/dist/swappers/thorchain/utils/test-data/midgardResponse.d.ts +5 -14
  20. package/dist/swappers/thorchain/utils/test-data/midgardResponse.js +44 -45
  21. package/dist/swappers/thorchain/utils/thorService.d.ts +1 -0
  22. package/dist/swappers/thorchain/utils/thorService.js +15 -0
  23. package/dist/swappers/zrx/ZrxApprovalNeeded/ZrxApprovalNeeded.js +2 -5
  24. package/dist/swappers/zrx/ZrxSwapper.d.ts +1 -2
  25. package/dist/swappers/zrx/ZrxSwapper.js +0 -4
  26. package/package.json +1 -1
package/dist/api.d.ts CHANGED
@@ -123,8 +123,6 @@ export declare type GetMinMaxInput = {
123
123
  };
124
124
  export declare type ApprovalNeededOutput = {
125
125
  approvalNeeded: boolean;
126
- gas?: string;
127
- gasPrice?: string;
128
126
  };
129
127
  export declare enum SwapperType {
130
128
  Zrx = "0x",
@@ -153,7 +151,8 @@ export declare enum SwapErrorTypes {
153
151
  USD_RATE_FAILED = "USD_RATE_FAILED",
154
152
  UNSUPPORTED_CHAIN = "UNSUPPORTED_CHAIN",
155
153
  VALIDATION_FAILED = "VALIDATION_FAILED",
156
- MAKE_MEMO_FAILED = "MAKE_MEMO_FAILED"
154
+ MAKE_MEMO_FAILED = "MAKE_MEMO_FAILED",
155
+ PRICE_RATIO_FAILED = "PRICE_RATIO_FAILED"
157
156
  }
158
157
  export interface Swapper {
159
158
  /** perform any necessary async initialization */
@@ -172,10 +171,6 @@ export interface Swapper {
172
171
  * Get the usd rate from either the assets symbol or tokenId
173
172
  */
174
173
  getUsdRate(input: Pick<Asset, 'symbol' | 'tokenId'>): Promise<string>;
175
- /**
176
- * Get the minimum and maximum trade value of the sellAsset and buyAsset
177
- */
178
- getMinMax(input: GetMinMaxInput): Promise<MinMaxOutput>;
179
174
  /**
180
175
  * Execute a trade built with buildTrade by signing and broadcasting
181
176
  */
package/dist/api.js CHANGED
@@ -30,4 +30,5 @@ var SwapErrorTypes;
30
30
  SwapErrorTypes["UNSUPPORTED_CHAIN"] = "UNSUPPORTED_CHAIN";
31
31
  SwapErrorTypes["VALIDATION_FAILED"] = "VALIDATION_FAILED";
32
32
  SwapErrorTypes["MAKE_MEMO_FAILED"] = "MAKE_MEMO_FAILED";
33
+ SwapErrorTypes["PRICE_RATIO_FAILED"] = "PRICE_RATIO_FAILED";
33
34
  })(SwapErrorTypes = exports.SwapErrorTypes || (exports.SwapErrorTypes = {}));
@@ -84,7 +84,8 @@ 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/pools'
87
+ midgardUrl: 'https://midgard.thorchain.info/v2',
88
+ adapterManager: {}
88
89
  };
89
90
  const manager = new SwapperManager_1.SwapperManager();
90
91
  const zrxSwapper = new ZrxSwapper_1.ZrxSwapper(zrxSwapperDeps);
@@ -1,6 +1,6 @@
1
1
  import { AssetId } from '@shapeshiftoss/caip';
2
2
  import { Asset, SupportedChainIds } from '@shapeshiftoss/types';
3
- import { ApprovalNeededInput, ApprovalNeededOutput, ApproveInfiniteInput, BuildTradeInput, BuyAssetBySellIdInput, ExecuteTradeInput, GetMinMaxInput, GetTradeQuoteInput, MinMaxOutput, Swapper, SwapperType, Trade, TradeQuote, TradeResult, TradeTxs } from '../../api';
3
+ import { ApprovalNeededInput, ApprovalNeededOutput, ApproveInfiniteInput, BuildTradeInput, BuyAssetBySellIdInput, ExecuteTradeInput, GetTradeQuoteInput, Swapper, SwapperType, Trade, TradeQuote, TradeResult, TradeTxs } from '../../api';
4
4
  export declare class CowSwapper implements Swapper {
5
5
  static swapperName: string;
6
6
  initialize(): Promise<void>;
@@ -8,7 +8,6 @@ export declare class CowSwapper implements Swapper {
8
8
  buildTrade(args: BuildTradeInput): Promise<Trade<SupportedChainIds>>;
9
9
  getTradeQuote(input: GetTradeQuoteInput): Promise<TradeQuote<SupportedChainIds>>;
10
10
  getUsdRate(input: Pick<Asset, 'symbol' | 'assetId'>): Promise<string>;
11
- getMinMax(input: GetMinMaxInput): Promise<MinMaxOutput>;
12
11
  executeTrade(args: ExecuteTradeInput<SupportedChainIds>): Promise<TradeResult>;
13
12
  approvalNeeded(args: ApprovalNeededInput<SupportedChainIds>): Promise<ApprovalNeededOutput>;
14
13
  approveInfinite(args: ApproveInfiniteInput<SupportedChainIds>): Promise<string>;
@@ -20,10 +20,6 @@ class CowSwapper {
20
20
  console.info(input);
21
21
  throw new Error('CowSwapper: getUsdRate unimplemented');
22
22
  }
23
- getMinMax(input) {
24
- console.info(input);
25
- throw new Error('CowSwapper: getMinMax unimplemented');
26
- }
27
23
  async executeTrade(args) {
28
24
  console.info(args);
29
25
  throw new Error('CowSwapper: executeTrade unimplemented');
@@ -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, TradeTxs } from '../../api';
3
+ import { ApprovalNeededOutput, BuyAssetBySellIdInput, 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
@@ -11,7 +11,6 @@ export declare class TestSwapper implements Swapper {
11
11
  getType(): SwapperType;
12
12
  constructor();
13
13
  getUsdRate(input: Pick<Asset, 'symbol' | 'assetId'>): Promise<string>;
14
- getMinMax(input: GetMinMaxInput): Promise<MinMaxOutput>;
15
14
  approvalNeeded(): Promise<ApprovalNeededOutput>;
16
15
  approveInfinite(): Promise<string>;
17
16
  filterBuyAssetsBySellAssetId(args: BuyAssetBySellIdInput): AssetId[];
@@ -24,10 +24,6 @@ class TestSwapper {
24
24
  console.info(input);
25
25
  throw new Error('TestSwapper: getUsdRate unimplemented');
26
26
  }
27
- getMinMax(input) {
28
- console.info(input);
29
- throw new Error('TestSwapper: getMinMax unimplemented');
30
- }
31
27
  async approvalNeeded() {
32
28
  throw new Error('TestSwapper: approvalNeeded unimplemented');
33
29
  }
@@ -1,9 +1,7 @@
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, TradeTxs } from '../../api';
4
- export declare type ThorchainSwapperDeps = {
5
- midgardUrl: string;
6
- };
3
+ import { ApprovalNeededOutput, BuyAssetBySellIdInput, Swapper, SwapperType, Trade, TradeQuote, TradeResult, TradeTxs } from '../../api';
4
+ import { ThorchainSwapperDeps } from './types';
7
5
  export declare class ThorchainSwapper implements Swapper {
8
6
  private supportedAssetIds;
9
7
  deps: ThorchainSwapperDeps;
@@ -11,7 +9,6 @@ export declare class ThorchainSwapper implements Swapper {
11
9
  initialize(): Promise<void>;
12
10
  getType(): SwapperType;
13
11
  getUsdRate(input: Pick<Asset, 'symbol' | 'assetId'>): Promise<string>;
14
- getMinMax(input: GetMinMaxInput): Promise<MinMaxOutput>;
15
12
  approvalNeeded(): Promise<ApprovalNeededOutput>;
16
13
  approveInfinite(): Promise<string>;
17
14
  filterBuyAssetsBySellAssetId(args: BuyAssetBySellIdInput): AssetId[];
@@ -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 axios_1.default.get(this.deps.midgardUrl);
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,12 +33,7 @@ class ThorchainSwapper {
35
33
  return api_1.SwapperType.Thorchain;
36
34
  }
37
35
  getUsdRate(input) {
38
- console.info(input);
39
- throw new Error('ThorchainSwapper: getUsdRate unimplemented');
40
- }
41
- getMinMax(input) {
42
- console.info(input);
43
- throw new Error('ThorchainSwapper: getMinMax unimplemented');
36
+ return (0, getUsdRate_1.getUsdRate)({ deps: this.deps, input });
44
37
  }
45
38
  async approvalNeeded() {
46
39
  throw new Error('ThorchainSwapper: approvalNeeded unimplemented');
@@ -1,3 +1,4 @@
1
+ import { ChainAdapterManager } from '@shapeshiftoss/chain-adapters';
1
2
  export declare type MidgardResponse = {
2
3
  asset: string;
3
4
  assetDepth: string;
@@ -12,3 +13,15 @@ export declare type MidgardResponse = {
12
13
  units: string;
13
14
  volume24h: string;
14
15
  };
16
+ export declare type InboundResponse = {
17
+ chain: string;
18
+ pub_key: string;
19
+ address: string;
20
+ halted: boolean;
21
+ gas_rate: string;
22
+ router?: string;
23
+ };
24
+ export declare type ThorchainSwapperDeps = {
25
+ midgardUrl: string;
26
+ adapterManager: ChainAdapterManager;
27
+ };
@@ -0,0 +1,23 @@
1
+ import { ethereum } from '@shapeshiftoss/chain-adapters';
2
+ import { ETHSignTx, HDWallet } from '@shapeshiftoss/hdwallet-core';
3
+ import { Asset, BIP44Params } from '@shapeshiftoss/types';
4
+ import BigNumber from 'bignumber.js';
5
+ import { ThorchainSwapperDeps } from '../../types';
6
+ export declare const fromBaseUnit: (value: BigNumber.Value, decimals: number, displayDecimals?: number) => string;
7
+ export declare const toBaseUnit: (amount: BigNumber.Value | undefined, precision: number) => string;
8
+ export declare const makeTradeTx: ({ wallet, bip44Params, sellAmount, buyAsset, sellAsset, destinationAddress, adapter, maxFeePerGas, maxPriorityFeePerGas, slippageTolerance, deps, gasLimit }: {
9
+ wallet: HDWallet;
10
+ bip44Params: BIP44Params;
11
+ sellAmount: string;
12
+ buyAsset: Asset;
13
+ sellAsset: Asset;
14
+ destinationAddress: string;
15
+ adapter: ethereum.ChainAdapter;
16
+ maxFeePerGas: string;
17
+ maxPriorityFeePerGas: string;
18
+ slippageTolerance: string;
19
+ deps: ThorchainSwapperDeps;
20
+ gasLimit: string;
21
+ }) => Promise<{
22
+ txToSign: ETHSignTx;
23
+ }>;
@@ -0,0 +1,81 @@
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.makeTradeTx = exports.toBaseUnit = exports.fromBaseUnit = void 0;
7
+ const caip_1 = require("@shapeshiftoss/caip");
8
+ const bignumber_js_1 = __importDefault(require("bignumber.js"));
9
+ const api_1 = require("../../../../api");
10
+ const bignumber_1 = require("../../../zrx/utils/bignumber");
11
+ const getPriceRatio_1 = require("../getPriceRatio/getPriceRatio");
12
+ const makeSwapMemo_1 = require("../makeSwapMemo/makeSwapMemo");
13
+ const thorService_1 = require("../thorService");
14
+ const routerCalldata_1 = require("./routerCalldata");
15
+ const fromBaseUnit = (value, decimals, displayDecimals = 6) => {
16
+ return (0, bignumber_1.bnOrZero)(value)
17
+ .div(`1e+${decimals}`)
18
+ .decimalPlaces(displayDecimals, bignumber_js_1.default.ROUND_DOWN)
19
+ .toString();
20
+ };
21
+ exports.fromBaseUnit = fromBaseUnit;
22
+ const toBaseUnit = (amount, precision) => {
23
+ return (0, bignumber_1.bnOrZero)(amount)
24
+ .times(new bignumber_js_1.default(10).exponentiatedBy((0, bignumber_1.bnOrZero)(precision)))
25
+ .toFixed(0);
26
+ };
27
+ exports.toBaseUnit = toBaseUnit;
28
+ const makeTradeTx = async ({ wallet, bip44Params, sellAmount, buyAsset, sellAsset, destinationAddress, adapter, maxFeePerGas, maxPriorityFeePerGas, slippageTolerance, deps, gasLimit }) => {
29
+ try {
30
+ const { assetReference } = (0, caip_1.fromAssetId)(sellAsset.assetId);
31
+ const isErc20Trade = assetReference.startsWith('0x');
32
+ const { data: inboundAddresses } = await thorService_1.thorService.get(`${deps.midgardUrl}/thorchain/inbound_addresses`);
33
+ const ethInboundAddresses = inboundAddresses.find((inbound) => inbound.chain === 'ETH');
34
+ const vault = ethInboundAddresses === null || ethInboundAddresses === void 0 ? void 0 : ethInboundAddresses.address;
35
+ const router = ethInboundAddresses === null || ethInboundAddresses === void 0 ? void 0 : ethInboundAddresses.router;
36
+ if (!vault || !router)
37
+ throw new api_1.SwapError(`[getPriceRatio]: router or vault found for ETH`, {
38
+ code: api_1.SwapErrorTypes.RESPONSE_ERROR,
39
+ details: { inboundAddresses }
40
+ });
41
+ const priceRatio = await (0, getPriceRatio_1.getPriceRatio)(deps, {
42
+ buyAssetId: buyAsset.assetId,
43
+ sellAssetId: sellAsset.assetId
44
+ });
45
+ const expectedBuyAmount = (0, exports.toBaseUnit)((0, exports.fromBaseUnit)((0, bignumber_1.bnOrZero)(sellAmount).dividedBy(priceRatio), sellAsset.precision), buyAsset.precision);
46
+ if (!(0, bignumber_1.bnOrZero)(expectedBuyAmount).gte(0) ||
47
+ !((0, bignumber_1.bnOrZero)(slippageTolerance).gte(0) && (0, bignumber_1.bnOrZero)(slippageTolerance).lte(1)))
48
+ throw new api_1.SwapError('[makeTradeTx]: bad expected buy amount or bad slippage tolerance', {
49
+ code: api_1.SwapErrorTypes.BUILD_TRADE_FAILED
50
+ });
51
+ const limit = (0, bignumber_1.bnOrZero)(expectedBuyAmount)
52
+ .times(new bignumber_js_1.default(1).minus(slippageTolerance))
53
+ .decimalPlaces(0)
54
+ .toString();
55
+ const memo = (0, makeSwapMemo_1.makeSwapMemo)({
56
+ buyAssetId: buyAsset.assetId,
57
+ destinationAddress,
58
+ limit
59
+ });
60
+ const data = await (0, routerCalldata_1.deposit)(vault, router, isErc20Trade ? assetReference : '0x0000000000000000000000000000000000000000', sellAmount, memo);
61
+ return adapter.buildCustomTx({
62
+ wallet,
63
+ bip44Params,
64
+ to: router,
65
+ gasLimit,
66
+ maxFeePerGas,
67
+ maxPriorityFeePerGas,
68
+ value: isErc20Trade ? '0' : sellAmount,
69
+ data
70
+ });
71
+ }
72
+ catch (e) {
73
+ if (e instanceof api_1.SwapError)
74
+ throw e;
75
+ throw new api_1.SwapError('[makeTradeTx]: error making trade tx', {
76
+ code: api_1.SwapErrorTypes.BUILD_TRADE_FAILED,
77
+ cause: e
78
+ });
79
+ }
80
+ };
81
+ exports.makeTradeTx = makeTradeTx;
@@ -0,0 +1,6 @@
1
+ import { AssetId } from '@shapeshiftoss/caip';
2
+ import { ThorchainSwapperDeps } from '../../types';
3
+ export declare const getPriceRatio: (deps: ThorchainSwapperDeps, input: {
4
+ buyAssetId: AssetId;
5
+ sellAssetId: AssetId;
6
+ }) => Promise<string>;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPriceRatio = void 0;
4
+ const caip_1 = require("@shapeshiftoss/caip");
5
+ const api_1 = require("../../../../api");
6
+ const bignumber_1 = require("../../../zrx/utils/bignumber");
7
+ const thorService_1 = require("../thorService");
8
+ const getPriceRatio = async (deps, input) => {
9
+ var _a, _b;
10
+ const { buyAssetId, sellAssetId } = input;
11
+ try {
12
+ const buyPoolId = caip_1.adapters.assetIdToPoolAssetId({ assetId: buyAssetId });
13
+ const sellPoolId = caip_1.adapters.assetIdToPoolAssetId({ assetId: sellAssetId });
14
+ if (!buyPoolId || !sellPoolId)
15
+ throw new api_1.SwapError(`[getPriceRatio]: No thorchain pool found`, {
16
+ code: api_1.SwapErrorTypes.RESPONSE_ERROR,
17
+ details: { buyPoolId, sellPoolId }
18
+ });
19
+ const { data: responseData } = await thorService_1.thorService.get(`${deps.midgardUrl}/pools`);
20
+ const buyUsdPrice = (_a = responseData.find((response) => response.asset === buyPoolId)) === null || _a === void 0 ? void 0 : _a.assetPrice;
21
+ const sellUsdPrice = (_b = responseData.find((response) => response.asset === sellPoolId)) === null || _b === void 0 ? void 0 : _b.assetPrice;
22
+ if (!buyUsdPrice || !sellUsdPrice)
23
+ throw new api_1.SwapError(`[getPriceRatio]: No rate found for pools`, {
24
+ code: api_1.SwapErrorTypes.RESPONSE_ERROR,
25
+ details: { buyPoolId, sellPoolId }
26
+ });
27
+ return (0, bignumber_1.bnOrZero)(buyUsdPrice).dividedBy(sellUsdPrice).toString();
28
+ }
29
+ catch (e) {
30
+ if (e instanceof api_1.SwapError)
31
+ throw e;
32
+ throw new api_1.SwapError('[getUsdRate]: Thorchain getUsdRate failed', {
33
+ code: api_1.SwapErrorTypes.PRICE_RATIO_FAILED,
34
+ cause: e
35
+ });
36
+ }
37
+ };
38
+ exports.getPriceRatio = getPriceRatio;
@@ -0,0 +1,6 @@
1
+ import { Asset } from '@shapeshiftoss/types';
2
+ import { ThorchainSwapperDeps } from '../../types';
3
+ export declare const getUsdRate: ({ deps, input }: {
4
+ deps: ThorchainSwapperDeps;
5
+ input: Pick<Asset, 'assetId'>;
6
+ }) => Promise<string>;
@@ -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;
@@ -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("../../../api");
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
- export declare const midgardResponse: {
2
- asset: string;
3
- assetDepth: string;
4
- assetPrice: string;
5
- assetPriceUSD: string;
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.midgardResponse = [
5
- {
6
- asset: 'BTC.BTC',
7
- assetDepth: '91027798705',
8
- assetPrice: '10280.68095465986',
9
- assetPriceUSD: '29850.505131750208',
10
- liquidityUnits: '536055974608843',
11
- poolAPY: '0.09305294391574037',
12
- runeDepth: '935827756491105',
13
- status: 'available',
14
- synthSupply: '3281284823',
15
- synthUnits: '9838954536080',
16
- units: '545894929144923',
17
- volume24h: '15031085906495'
18
- },
19
- {
20
- asset: 'ETH.ETH',
21
- assetDepth: '915018987646',
22
- assetPrice: '676.2118757936507',
23
- assetPriceUSD: '1963.4172247490626',
24
- liquidityUnits: '273709963437801',
25
- poolAPY: '0.10532151323548256',
26
- runeDepth: '618746706022909',
27
- status: 'available',
28
- synthSupply: '3572065751',
29
- synthUnits: '535301524652',
30
- units: '274245264962453',
31
- volume24h: '9890096673763'
32
- },
33
- {
34
- asset: 'ETH.FOX-0XC770EEFAD204B5180DF6A14EE197D99D808EE52D',
35
- assetDepth: '166650912393467',
36
- assetPrice: '0.05303710198887871',
37
- assetPriceUSD: '0.15399605260336216',
38
- liquidityUnits: '10015457121887',
39
- poolAPY: '0.2597568967423438',
40
- runeDepth: '8838681437152',
41
- status: 'available',
42
- synthSupply: '17428372569375',
43
- synthUnits: '552604585625',
44
- units: '10568061707512',
45
- volume24h: '251596933033'
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);
@@ -5,10 +5,9 @@ const caip_1 = require("@shapeshiftoss/caip");
5
5
  const api_1 = require("../../../api");
6
6
  const erc20Allowance_abi_1 = require("../utils/abi/erc20Allowance-abi");
7
7
  const bignumber_1 = require("../utils/bignumber");
8
- const constants_1 = require("../utils/constants");
9
8
  const helpers_1 = require("../utils/helpers/helpers");
10
9
  async function ZrxApprovalNeeded({ adapterManager, web3 }, { quote, wallet }) {
11
- var _a, _b;
10
+ var _a;
12
11
  const { sellAsset } = quote;
13
12
  const { assetReference: sellAssetErc20Address } = (0, caip_1.fromAssetId)(sellAsset.assetId);
14
13
  try {
@@ -46,9 +45,7 @@ async function ZrxApprovalNeeded({ adapterManager, web3 }, { quote, wallet }) {
46
45
  details: { feeData: quote.feeData }
47
46
  });
48
47
  return {
49
- approvalNeeded: allowanceOnChain.lte((0, bignumber_1.bnOrZero)(quote.sellAmount)),
50
- gas: constants_1.APPROVAL_GAS_LIMIT,
51
- gasPrice: (_b = quote.feeData.chainSpecific) === null || _b === void 0 ? void 0 : _b.gasPrice
48
+ approvalNeeded: allowanceOnChain.lte((0, bignumber_1.bnOrZero)(quote.sellAmount))
52
49
  };
53
50
  }
54
51
  catch (e) {
@@ -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, TradeTxs, ZrxTrade } from '../../api';
5
+ import { ApprovalNeededInput, ApprovalNeededOutput, ApproveInfiniteInput, BuildTradeInput, BuyAssetBySellIdInput, ExecuteTradeInput, GetTradeQuoteInput, Swapper, SwapperType, TradeQuote, TradeResult, TradeTxs, ZrxTrade } from '../../api';
6
6
  export declare type ZrxSwapperDeps = {
7
7
  adapterManager: ChainAdapterManager;
8
8
  web3: Web3;
@@ -16,7 +16,6 @@ export declare class ZrxSwapper implements Swapper {
16
16
  buildTrade(args: BuildTradeInput): Promise<ZrxTrade<SupportedChainIds>>;
17
17
  getTradeQuote(input: GetTradeQuoteInput): Promise<TradeQuote<SupportedChainIds>>;
18
18
  getUsdRate(input: Pick<Asset, 'symbol' | 'assetId'>): Promise<string>;
19
- getMinMax(input: GetMinMaxInput): Promise<MinMaxOutput>;
20
19
  executeTrade(args: ExecuteTradeInput<SupportedChainIds>): Promise<TradeResult>;
21
20
  approvalNeeded(args: ApprovalNeededInput<SupportedChainIds>): Promise<ApprovalNeededOutput>;
22
21
  approveInfinite(args: ApproveInfiniteInput<SupportedChainIds>): Promise<string>;
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ZrxSwapper = void 0;
4
4
  const api_1 = require("../../api");
5
- const getZrxMinMax_1 = require("./getZrxMinMax/getZrxMinMax");
6
5
  const getZrxTradeQuote_1 = require("./getZrxTradeQuote/getZrxTradeQuote");
7
6
  const blacklist_1 = require("./utils/blacklist");
8
7
  const helpers_1 = require("./utils/helpers/helpers");
@@ -29,9 +28,6 @@ class ZrxSwapper {
29
28
  async getUsdRate(input) {
30
29
  return (0, helpers_1.getUsdRate)(input);
31
30
  }
32
- async getMinMax(input) {
33
- return (0, getZrxMinMax_1.getZrxMinMax)(input.sellAsset, input.buyAsset);
34
- }
35
31
  async executeTrade(args) {
36
32
  return (0, zrxExecuteTrade_1.zrxExecuteTrade)(this.deps, args);
37
33
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/swapper",
3
- "version": "5.6.0",
3
+ "version": "5.8.1",
4
4
  "description": "TODO: description",
5
5
  "repository": "https://github.com/shapeshift/lib",
6
6
  "license": "MIT",