@shapeshiftoss/swapper 7.6.0 → 7.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.
@@ -1,6 +1,6 @@
1
1
  import { AssetId, ChainId } from '@shapeshiftoss/caip';
2
2
  import type { Asset } from '@shapeshiftoss/types';
3
- import { ApprovalNeededInput, ApprovalNeededOutput, BuyAssetBySellIdInput, ExecuteTradeInput, GetTradeQuoteInput, Swapper, SwapperType, Trade, TradeQuote, TradeResult, TradeTxs } from '../../api';
3
+ import { ApprovalNeededInput, ApprovalNeededOutput, ApproveInfiniteInput, BuyAssetBySellIdInput, ExecuteTradeInput, GetTradeQuoteInput, Swapper, SwapperType, Trade, TradeQuote, TradeResult, TradeTxs } from '../../api';
4
4
  import { ThorchainSwapperDeps } from './types';
5
5
  export declare class ThorchainSwapper implements Swapper<ChainId> {
6
6
  private swapSupportedChainIds;
@@ -11,7 +11,7 @@ export declare class ThorchainSwapper implements Swapper<ChainId> {
11
11
  getType(): SwapperType;
12
12
  getUsdRate(input: Pick<Asset, 'symbol' | 'assetId'>): Promise<string>;
13
13
  approvalNeeded(input: ApprovalNeededInput<'eip155:1'>): Promise<ApprovalNeededOutput>;
14
- approveInfinite(): Promise<string>;
14
+ approveInfinite(input: ApproveInfiniteInput<'eip155:1'>): Promise<string>;
15
15
  filterBuyAssetsBySellAssetId(args: BuyAssetBySellIdInput): AssetId[];
16
16
  filterAssetIdsBySellable(): AssetId[];
17
17
  buildTrade(): Promise<Trade<ChainId>>;
@@ -5,6 +5,7 @@ const caip_1 = require("@shapeshiftoss/caip");
5
5
  const api_1 = require("../../api");
6
6
  const getTradeQuote_1 = require("./getThorTradeQuote/getTradeQuote");
7
7
  const thorTradeApprovalNeeded_1 = require("./thorTradeApprovalNeeded/thorTradeApprovalNeeded");
8
+ const thorTradeApproveInfinite_1 = require("./thorTradeApproveInfinite/thorTradeApproveInfinite");
8
9
  const getUsdRate_1 = require("./utils/getUsdRate/getUsdRate");
9
10
  const thorService_1 = require("./utils/thorService");
10
11
  class ThorchainSwapper {
@@ -44,8 +45,8 @@ class ThorchainSwapper {
44
45
  async approvalNeeded(input) {
45
46
  return (0, thorTradeApprovalNeeded_1.thorTradeApprovalNeeded)({ deps: this.deps, input });
46
47
  }
47
- async approveInfinite() {
48
- throw new Error('ThorchainSwapper: approveInfinite unimplemented');
48
+ async approveInfinite(input) {
49
+ return (0, thorTradeApproveInfinite_1.thorTradeApproveInfinite)({ deps: this.deps, input });
49
50
  }
50
51
  filterBuyAssetsBySellAssetId(args) {
51
52
  const { assetIds = [], sellAssetId } = args;
@@ -0,0 +1,6 @@
1
+ import { ApproveInfiniteInput } from '../../../api';
2
+ import { ThorchainSwapperDeps } from '../types';
3
+ export declare const thorTradeApproveInfinite: ({ deps, input }: {
4
+ deps: ThorchainSwapperDeps;
5
+ input: ApproveInfiniteInput<'eip155:1'>;
6
+ }) => Promise<string>;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.thorTradeApproveInfinite = void 0;
4
+ const types_1 = require("@shapeshiftoss/types");
5
+ const api_1 = require("../../../api");
6
+ const erc20_abi_1 = require("../../utils/abi/erc20-abi");
7
+ const helpers_1 = require("../../utils/helpers/helpers");
8
+ const constants_1 = require("../utils/constants");
9
+ const thorTradeApproveInfinite = async ({ deps, input }) => {
10
+ try {
11
+ const { adapterManager, web3 } = deps;
12
+ const { quote, wallet } = input;
13
+ const sellAssetChainId = quote.sellAsset.chainId;
14
+ const adapter = adapterManager.get(types_1.KnownChainIds.EthereumMainnet);
15
+ if (!adapter)
16
+ throw new api_1.SwapError(`[thorTradeApproveInfinite] - No chain adapter found for ${sellAssetChainId}.`, {
17
+ code: api_1.SwapErrorTypes.UNSUPPORTED_CHAIN,
18
+ details: { sellAssetChainId }
19
+ });
20
+ const allowanceGrantRequired = await (0, helpers_1.grantAllowance)({
21
+ quote: {
22
+ ...quote,
23
+ sellAmount: constants_1.MAX_ALLOWANCE
24
+ },
25
+ wallet,
26
+ adapter,
27
+ erc20Abi: erc20_abi_1.erc20Abi,
28
+ web3
29
+ });
30
+ return allowanceGrantRequired;
31
+ }
32
+ catch (e) {
33
+ if (e instanceof api_1.SwapError)
34
+ throw e;
35
+ throw new api_1.SwapError('[ZrxApproveInfinite]', {
36
+ cause: e,
37
+ code: api_1.SwapErrorTypes.APPROVE_INFINITE_FAILED
38
+ });
39
+ }
40
+ };
41
+ exports.thorTradeApproveInfinite = thorTradeApproveInfinite;
@@ -1 +1,2 @@
1
1
  export declare const MAX_THORCHAIN_TRADE = "100000000000000000000000000";
2
+ export declare const MAX_ALLOWANCE = "100000000000000000000000000";
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MAX_THORCHAIN_TRADE = void 0;
3
+ exports.MAX_ALLOWANCE = exports.MAX_THORCHAIN_TRADE = void 0;
4
4
  exports.MAX_THORCHAIN_TRADE = '100000000000000000000000000';
5
+ exports.MAX_ALLOWANCE = '100000000000000000000000000';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/swapper",
3
- "version": "7.6.0",
3
+ "version": "7.7.0",
4
4
  "description": "An interface and implementations to trade coins via various protocols",
5
5
  "repository": "https://github.com/shapeshift/lib",
6
6
  "license": "MIT",