@shapeshiftoss/swapper 9.4.0 → 9.6.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.
package/dist/api.d.ts CHANGED
@@ -42,6 +42,9 @@ declare type ChainSpecificQuoteFeeData<T extends ChainId> = ChainSpecific<T, {
42
42
  byteCount: string;
43
43
  satsPerByte: string;
44
44
  };
45
+ [KnownChainIds.CosmosMainnet]: {
46
+ estimatedGas: string;
47
+ };
45
48
  }>;
46
49
  export declare type QuoteFeeData<T extends ChainId> = {
47
50
  fee: string;
@@ -165,7 +168,8 @@ export declare enum SwapErrorTypes {
165
168
  MAKE_MEMO_FAILED = "MAKE_MEMO_FAILED",
166
169
  PRICE_RATIO_FAILED = "PRICE_RATIO_FAILED",
167
170
  POOL_NOT_FOUND = "POOL_NOT_FOUND",
168
- GET_TRADE_TXS_FAILED = "GET_TRADE_TXS_FAILED"
171
+ GET_TRADE_TXS_FAILED = "GET_TRADE_TXS_FAILED",
172
+ TRADE_FAILED = "TRADE_FAILED"
169
173
  }
170
174
  export interface Swapper<T extends ChainId> {
171
175
  /** Human readable swapper name */
package/dist/api.js CHANGED
@@ -37,4 +37,5 @@ var SwapErrorTypes;
37
37
  SwapErrorTypes["PRICE_RATIO_FAILED"] = "PRICE_RATIO_FAILED";
38
38
  SwapErrorTypes["POOL_NOT_FOUND"] = "POOL_NOT_FOUND";
39
39
  SwapErrorTypes["GET_TRADE_TXS_FAILED"] = "GET_TRADE_TXS_FAILED";
40
+ SwapErrorTypes["TRADE_FAILED"] = "TRADE_FAILED";
40
41
  })(SwapErrorTypes = exports.SwapErrorTypes || (exports.SwapErrorTypes = {}));
@@ -15,13 +15,15 @@ class ThorchainSwapper {
15
15
  this.name = 'Thorchain';
16
16
  this.sellSupportedChainIds = {
17
17
  [types_1.KnownChainIds.EthereumMainnet]: true,
18
- [types_1.KnownChainIds.BitcoinMainnet]: true
18
+ [types_1.KnownChainIds.BitcoinMainnet]: true,
19
+ [types_1.KnownChainIds.CosmosMainnet]: true
19
20
  };
20
21
  this.buySupportedChainIds = {
21
22
  [types_1.KnownChainIds.EthereumMainnet]: true,
22
23
  [types_1.KnownChainIds.BitcoinMainnet]: true,
23
24
  [types_1.KnownChainIds.DogecoinMainnet]: true,
24
25
  [types_1.KnownChainIds.LitecoinMainnet]: true,
26
+ [types_1.KnownChainIds.BitcoinCashMainnet]: true,
25
27
  [types_1.KnownChainIds.CosmosMainnet]: true
26
28
  };
27
29
  this.supportedSellAssetIds = [];
@@ -106,6 +108,14 @@ class ThorchainSwapper {
106
108
  const txid = await adapter.broadcastTransaction(signedTx);
107
109
  return { tradeId: txid };
108
110
  }
111
+ else if (trade.sellAsset.chainId === types_1.KnownChainIds.CosmosMainnet) {
112
+ const signedTx = await adapter.signTransaction({
113
+ txToSign: trade.txData,
114
+ wallet
115
+ });
116
+ const txid = await adapter.broadcastTransaction(signedTx);
117
+ return { tradeId: txid };
118
+ }
109
119
  else {
110
120
  throw new api_1.SwapError('[executeTrade]: unsupported trade', {
111
121
  code: api_1.SwapErrorTypes.SIGN_AND_BROADCAST_FAILED,
@@ -123,11 +133,38 @@ class ThorchainSwapper {
123
133
  }
124
134
  }
125
135
  async getTradeTxs(tradeResult) {
126
- // TODO poll midgard for the correct buyTxid
127
- return {
128
- sellTxid: tradeResult.tradeId,
129
- buyTxid: tradeResult.tradeId
130
- };
136
+ var _a, _b, _c, _d, _e, _f, _g;
137
+ try {
138
+ const midgardTxid = tradeResult.tradeId.startsWith('0x')
139
+ ? tradeResult.tradeId.slice(2)
140
+ : tradeResult.tradeId;
141
+ const { data: responseData } = await thorService_1.thorService.get(`${this.deps.midgardUrl}/actions?txid=${midgardTxid}`);
142
+ const buyTxid = ((_a = responseData === null || responseData === void 0 ? void 0 : responseData.actions[0]) === null || _a === void 0 ? void 0 : _a.status) === 'success' && ((_b = responseData === null || responseData === void 0 ? void 0 : responseData.actions[0]) === null || _b === void 0 ? void 0 : _b.type) === 'swap'
143
+ ? responseData === null || responseData === void 0 ? void 0 : responseData.actions[0].out[0].txID
144
+ : '';
145
+ // This will detect all the errors I have seen.
146
+ if (((_c = responseData === null || responseData === void 0 ? void 0 : responseData.actions[0]) === null || _c === void 0 ? void 0 : _c.status) === 'success' &&
147
+ ((_d = responseData === null || responseData === void 0 ? void 0 : responseData.actions[0]) === null || _d === void 0 ? void 0 : _d.type) !== 'swap')
148
+ throw new api_1.SwapError('[getTradeTxs]: trade failed', {
149
+ code: api_1.SwapErrorTypes.TRADE_FAILED,
150
+ cause: responseData
151
+ });
152
+ const standardBuyTxid = ((_g = (_f = (_e = responseData === null || responseData === void 0 ? void 0 : responseData.actions[0]) === null || _e === void 0 ? void 0 : _e.out[0]) === null || _f === void 0 ? void 0 : _f.coins[0]) === null || _g === void 0 ? void 0 : _g.asset.startsWith('ETH.'))
153
+ ? `0x${buyTxid}`
154
+ : buyTxid;
155
+ return {
156
+ sellTxid: tradeResult.tradeId,
157
+ buyTxid: standardBuyTxid.toLowerCase()
158
+ };
159
+ }
160
+ catch (e) {
161
+ if (e instanceof api_1.SwapError)
162
+ throw e;
163
+ throw new api_1.SwapError('[getTradeTxs]: error', {
164
+ code: api_1.SwapErrorTypes.GET_TRADE_TXS_FAILED,
165
+ cause: e
166
+ });
167
+ }
131
168
  }
132
169
  }
133
170
  exports.ThorchainSwapper = ThorchainSwapper;
@@ -6,6 +6,7 @@ const api_1 = require("../../../api");
6
6
  const constants_1 = require("../../utils/constants");
7
7
  const getTradeQuote_1 = require("../getThorTradeQuote/getTradeQuote");
8
8
  const getThorTxData_1 = require("../utils/bitcoin/utils/getThorTxData");
9
+ const cosmosTxData_1 = require("../utils/cosmos/cosmosTxData");
9
10
  const makeTradeTx_1 = require("../utils/ethereum/makeTradeTx");
10
11
  const buildTrade = async ({ deps, input }) => {
11
12
  var _a, _b, _c, _d;
@@ -75,6 +76,26 @@ const buildTrade = async ({ deps, input }) => {
75
76
  txData: buildTxResponse.txToSign
76
77
  };
77
78
  }
79
+ else if (input.chainId === types_1.KnownChainIds.CosmosMainnet) {
80
+ const txData = await (0, cosmosTxData_1.cosmosTxData)({
81
+ deps,
82
+ sellAdapter: sellAdapter,
83
+ sellAmount,
84
+ sellAsset,
85
+ slippageTolerance,
86
+ chainId: input.chainId,
87
+ buyAsset,
88
+ wallet,
89
+ destinationAddress,
90
+ quote: quote
91
+ });
92
+ return {
93
+ chainId: types_1.KnownChainIds.CosmosMainnet,
94
+ ...quote,
95
+ receiveAddress: destinationAddress,
96
+ txData
97
+ };
98
+ }
78
99
  else {
79
100
  throw new api_1.SwapError('[buildTrade]: unsupported chain id', {
80
101
  code: api_1.SwapErrorTypes.BUILD_TRADE_FAILED,
@@ -21,8 +21,8 @@ const getThorTradeQuote = async ({ deps, input }) => {
21
21
  });
22
22
  try {
23
23
  const { assetReference: sellAssetErc20Address } = (0, caip_1.fromAssetId)(sellAsset.assetId);
24
- const adapter = deps.adapterManager.get(chainId);
25
- if (!adapter)
24
+ const sellAdapter = deps.adapterManager.get(chainId);
25
+ if (!sellAdapter)
26
26
  throw new api_1.SwapError(`[getThorTradeQuote] - No chain adapter found for ${chainId}.`, {
27
27
  code: api_1.SwapErrorTypes.UNSUPPORTED_CHAIN,
28
28
  details: { chainId }
@@ -97,6 +97,19 @@ const getThorTradeQuote = async ({ deps, input }) => {
97
97
  feeData
98
98
  };
99
99
  })();
100
+ case types_1.KnownChainIds.CosmosMainnet:
101
+ return (async () => {
102
+ const feeData = await sellAdapter.getFeeData({});
103
+ return {
104
+ ...commonQuoteFields,
105
+ allowanceContract: '0x0',
106
+ feeData: {
107
+ fee: feeData.fast.txFee,
108
+ tradeFee,
109
+ chainSpecific: { estimatedGas: feeData.fast.chainSpecific.gasLimit }
110
+ }
111
+ };
112
+ })();
100
113
  default:
101
114
  throw new api_1.SwapError('[getThorTradeQuote] - Asset chainId is not supported.', {
102
115
  code: api_1.SwapErrorTypes.UNSUPPORTED_CHAIN,
@@ -1,6 +1,6 @@
1
1
  import { ChainId } from '@shapeshiftoss/caip';
2
2
  import { ChainAdapterManager } from '@shapeshiftoss/chain-adapters';
3
- import { BTCSignTx, ETHSignTx } from '@shapeshiftoss/hdwallet-core';
3
+ import { BTCSignTx, CosmosSignTx, ETHSignTx } from '@shapeshiftoss/hdwallet-core';
4
4
  import { KnownChainIds } from '@shapeshiftoss/types';
5
5
  import type Web3 from 'web3';
6
6
  import { Trade } from '../../api';
@@ -18,6 +18,23 @@ export declare type PoolResponse = {
18
18
  units: string;
19
19
  volume24h: string;
20
20
  };
21
+ declare type MidardCoins = {
22
+ asset: string;
23
+ }[];
24
+ declare type MidgardActionOut = {
25
+ coins: MidardCoins;
26
+ txID: string;
27
+ };
28
+ declare type MidgardAction = {
29
+ date: string;
30
+ height: string;
31
+ out: MidgardActionOut[];
32
+ status: string;
33
+ type: string;
34
+ };
35
+ export declare type MidgardActionsResponse = {
36
+ actions: MidgardAction[];
37
+ };
21
38
  export declare type InboundResponse = {
22
39
  chain: string;
23
40
  pub_key: string;
@@ -39,4 +56,9 @@ export interface EthThorTrade<C extends ChainId> extends Trade<C> {
39
56
  chainId: KnownChainIds.EthereumMainnet;
40
57
  txData: ETHSignTx;
41
58
  }
42
- export declare type ThorTrade<C extends ChainId> = BtcThorTrade<C> | EthThorTrade<C>;
59
+ export interface CosmosThorTrade<C extends ChainId> extends Trade<C> {
60
+ chainId: KnownChainIds.CosmosMainnet;
61
+ txData: CosmosSignTx;
62
+ }
63
+ export declare type ThorTrade<C extends ChainId> = BtcThorTrade<C> | EthThorTrade<C> | CosmosThorTrade<C>;
64
+ export {};
@@ -3,9 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getThorTxInfo = void 0;
4
4
  const caip_1 = require("@shapeshiftoss/caip");
5
5
  const api_1 = require("../../../../../api");
6
- const bignumber_1 = require("../../../../utils/bignumber");
7
- const constants_1 = require("../../constants");
8
- const getTradeRate_1 = require("../../getTradeRate/getTradeRate");
6
+ const getLimit_1 = require("../../getLimit/getLimit");
9
7
  const makeSwapMemo_1 = require("../../makeSwapMemo/makeSwapMemo");
10
8
  const thorService_1 = require("../../thorService");
11
9
  const getThorTxInfo = async ({ deps, sellAsset, buyAsset, sellAmount, slippageTolerance, destinationAddress, wallet, bip44Params, accountType, tradeFee }) => {
@@ -18,20 +16,16 @@ const getThorTxInfo = async ({ deps, sellAsset, buyAsset, sellAmount, slippageTo
18
16
  code: api_1.SwapErrorTypes.RESPONSE_ERROR,
19
17
  details: { inboundAddresses }
20
18
  });
21
- const tradeRate = await (0, getTradeRate_1.getTradeRate)(sellAsset, buyAsset.assetId, sellAmount, deps);
22
- const expectedBuyAmountPrecision8 = (0, bignumber_1.toBaseUnit)((0, bignumber_1.fromBaseUnit)((0, bignumber_1.bnOrZero)(sellAmount).times(tradeRate), sellAsset.precision), constants_1.THORCHAIN_FIXED_PRECISION);
23
- const isValidSlippageRange = (0, bignumber_1.bnOrZero)(slippageTolerance).gte(0) && (0, bignumber_1.bnOrZero)(slippageTolerance).lte(1);
24
- if ((0, bignumber_1.bnOrZero)(expectedBuyAmountPrecision8).lt(0) || !isValidSlippageRange)
25
- throw new api_1.SwapError('[getThorTxInfo]: bad expected buy amount or bad slippage tolerance', {
26
- code: api_1.SwapErrorTypes.BUILD_TRADE_FAILED,
27
- details: { expectedBuyAmountPrecision8, slippageTolerance }
28
- });
29
- const tradeFeePrecision8 = (0, bignumber_1.toBaseUnit)((0, bignumber_1.bnOrZero)(tradeFee), constants_1.THORCHAIN_FIXED_PRECISION);
30
- const limit = (0, bignumber_1.bnOrZero)(expectedBuyAmountPrecision8)
31
- .times((0, bignumber_1.bn)(1).minus(slippageTolerance))
32
- .minus((0, bignumber_1.bnOrZero)(tradeFeePrecision8))
33
- .decimalPlaces(0)
34
- .toString();
19
+ const limit = await (0, getLimit_1.getLimit)({
20
+ buyAssetId: buyAsset.assetId,
21
+ destinationAddress,
22
+ sellAmount,
23
+ sellAsset,
24
+ buyAsset,
25
+ slippageTolerance,
26
+ deps,
27
+ tradeFee
28
+ });
35
29
  const memo = (0, makeSwapMemo_1.makeSwapMemo)({
36
30
  buyAssetId: buyAsset.assetId,
37
31
  destinationAddress,
@@ -20,6 +20,7 @@ exports.THOR_TRADE_FEE_MULTIPLIERS = {
20
20
  [types_1.KnownChainIds.BitcoinMainnet]: (0, bignumber_1.bn)(0.00002),
21
21
  [types_1.KnownChainIds.DogecoinMainnet]: (0, bignumber_1.bn)(0.00002),
22
22
  [types_1.KnownChainIds.LitecoinMainnet]: (0, bignumber_1.bn)(0.000005),
23
+ [types_1.KnownChainIds.BitcoinCashMainnet]: (0, bignumber_1.bn)(0.00003),
23
24
  [types_1.KnownChainIds.CosmosMainnet]: (0, bignumber_1.bn)(0.00000002),
24
25
  [types_1.KnownChainIds.EthereumMainnet]: (0, bignumber_1.bn)(0.00024) // A value that "works". Discord recommended value (80,000 gas * 2 or 160k) is often too low
25
26
  };
@@ -0,0 +1,19 @@
1
+ import { Asset } from '@shapeshiftoss/asset-service';
2
+ import { ChainId } from '@shapeshiftoss/caip';
3
+ import { ChainAdapter } from '@shapeshiftoss/chain-adapters';
4
+ import { HDWallet } from '@shapeshiftoss/hdwallet-core';
5
+ import { KnownChainIds } from '@shapeshiftoss/types';
6
+ import { TradeQuote } from '../../../../api';
7
+ import { ThorchainSwapperDeps } from '../../types';
8
+ export declare const cosmosTxData: (input: {
9
+ destinationAddress: string;
10
+ deps: ThorchainSwapperDeps;
11
+ sellAmount: string;
12
+ sellAsset: Asset;
13
+ buyAsset: Asset;
14
+ slippageTolerance: string;
15
+ wallet: HDWallet;
16
+ quote: TradeQuote<KnownChainIds.CosmosMainnet>;
17
+ chainId: ChainId;
18
+ sellAdapter: ChainAdapter<KnownChainIds.CosmosMainnet>;
19
+ }) => Promise<import("@shapeshiftoss/hdwallet-core").CosmosSignTx>;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cosmosTxData = void 0;
4
+ const api_1 = require("../../../../api");
5
+ const getLimit_1 = require("../getLimit/getLimit");
6
+ const makeSwapMemo_1 = require("../makeSwapMemo/makeSwapMemo");
7
+ const thorService_1 = require("../thorService");
8
+ const cosmosTxData = async (input) => {
9
+ const { deps, destinationAddress, sellAmount, sellAsset, buyAsset, slippageTolerance, quote, wallet, sellAdapter } = input;
10
+ const { data: inboundAddresses } = await thorService_1.thorService.get(`${deps.midgardUrl}/thorchain/inbound_addresses`);
11
+ const atomInboundAddresses = inboundAddresses.find((inbound) => inbound.chain === 'GAIA');
12
+ const vault = atomInboundAddresses === null || atomInboundAddresses === void 0 ? void 0 : atomInboundAddresses.address;
13
+ if (!vault)
14
+ throw new api_1.SwapError('[buildTrade]: no vault for chain', {
15
+ code: api_1.SwapErrorTypes.BUILD_TRADE_FAILED,
16
+ fn: 'buildTrade',
17
+ details: { chainId: input.chainId }
18
+ });
19
+ const limit = await (0, getLimit_1.getLimit)({
20
+ buyAssetId: buyAsset.assetId,
21
+ destinationAddress,
22
+ sellAmount,
23
+ sellAsset,
24
+ buyAsset,
25
+ slippageTolerance,
26
+ deps,
27
+ tradeFee: quote.feeData.tradeFee
28
+ });
29
+ const memo = (0, makeSwapMemo_1.makeSwapMemo)({
30
+ buyAssetId: buyAsset.assetId,
31
+ destinationAddress,
32
+ limit
33
+ });
34
+ const buildTxResponse = await sellAdapter.buildSendTransaction({
35
+ value: sellAmount,
36
+ wallet,
37
+ to: vault,
38
+ memo,
39
+ chainSpecific: {
40
+ gas: quote.feeData.chainSpecific.estimatedGas,
41
+ fee: quote.feeData.fee
42
+ }
43
+ });
44
+ return buildTxResponse.txToSign;
45
+ };
46
+ exports.cosmosTxData = cosmosTxData;
@@ -3,9 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getThorTxInfo = void 0;
4
4
  const caip_1 = require("@shapeshiftoss/caip");
5
5
  const api_1 = require("../../../../../api");
6
- const bignumber_1 = require("../../../../utils/bignumber");
7
- const getTradeRate_1 = require("../../../utils/getTradeRate/getTradeRate");
8
- const constants_1 = require("../../constants");
6
+ const getLimit_1 = require("../../getLimit/getLimit");
9
7
  const makeSwapMemo_1 = require("../../makeSwapMemo/makeSwapMemo");
10
8
  const thorService_1 = require("../../thorService");
11
9
  const routerCalldata_1 = require("../routerCalldata");
@@ -22,20 +20,16 @@ const getThorTxInfo = async ({ deps, sellAsset, buyAsset, sellAmount, slippageTo
22
20
  code: api_1.SwapErrorTypes.RESPONSE_ERROR,
23
21
  details: { inboundAddresses }
24
22
  });
25
- const tradeRate = await (0, getTradeRate_1.getTradeRate)(sellAsset, buyAsset.assetId, sellAmount, deps);
26
- const expectedBuyAmountPrecision8 = (0, bignumber_1.toBaseUnit)((0, bignumber_1.fromBaseUnit)((0, bignumber_1.bnOrZero)(sellAmount).times(tradeRate), sellAsset.precision), constants_1.THORCHAIN_FIXED_PRECISION);
27
- const tradeFeePrecision8 = (0, bignumber_1.toBaseUnit)((0, bignumber_1.bnOrZero)(tradeFee), constants_1.THORCHAIN_FIXED_PRECISION);
28
- const isValidSlippageRange = (0, bignumber_1.bnOrZero)(slippageTolerance).gte(0) && (0, bignumber_1.bnOrZero)(slippageTolerance).lte(1);
29
- if ((0, bignumber_1.bnOrZero)(expectedBuyAmountPrecision8).lt(0) || !isValidSlippageRange)
30
- throw new api_1.SwapError('[makeTradeTx]: bad expected buy amount or bad slippage tolerance', {
31
- code: api_1.SwapErrorTypes.BUILD_TRADE_FAILED,
32
- details: { expectedBuyAmountPrecision8, slippageTolerance }
33
- });
34
- const limit = (0, bignumber_1.bnOrZero)(expectedBuyAmountPrecision8)
35
- .times((0, bignumber_1.bn)(1).minus(slippageTolerance))
36
- .minus((0, bignumber_1.bnOrZero)(tradeFeePrecision8))
37
- .decimalPlaces(0)
38
- .toString();
23
+ const limit = await (0, getLimit_1.getLimit)({
24
+ buyAssetId: buyAsset.assetId,
25
+ destinationAddress,
26
+ sellAmount,
27
+ sellAsset,
28
+ buyAsset,
29
+ slippageTolerance,
30
+ deps,
31
+ tradeFee
32
+ });
39
33
  const memo = (0, makeSwapMemo_1.makeSwapMemo)({
40
34
  buyAssetId: buyAsset.assetId,
41
35
  destinationAddress,
@@ -0,0 +1,12 @@
1
+ import { Asset } from '@shapeshiftoss/asset-service';
2
+ import { ThorchainSwapperDeps } from '../../types';
3
+ export declare const getLimit: ({ sellAsset, buyAsset, sellAmount, deps, slippageTolerance, tradeFee }: {
4
+ buyAssetId: string;
5
+ destinationAddress: string;
6
+ sellAsset: Asset;
7
+ buyAsset: Asset;
8
+ sellAmount: string;
9
+ deps: ThorchainSwapperDeps;
10
+ slippageTolerance: string;
11
+ tradeFee: string;
12
+ }) => Promise<string>;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLimit = void 0;
4
+ const api_1 = require("../../../../api");
5
+ const bignumber_1 = require("../../../utils/bignumber");
6
+ const constants_1 = require("../constants");
7
+ const getTradeRate_1 = require("../getTradeRate/getTradeRate");
8
+ const getLimit = async ({ sellAsset, buyAsset, sellAmount, deps, slippageTolerance, tradeFee }) => {
9
+ const tradeRate = await (0, getTradeRate_1.getTradeRate)(sellAsset, buyAsset.assetId, sellAmount, deps);
10
+ const expectedBuyAmountPrecision8 = (0, bignumber_1.toBaseUnit)((0, bignumber_1.fromBaseUnit)((0, bignumber_1.bnOrZero)(sellAmount).times(tradeRate), sellAsset.precision), constants_1.THORCHAIN_FIXED_PRECISION);
11
+ const isValidSlippageRange = (0, bignumber_1.bnOrZero)(slippageTolerance).gte(0) && (0, bignumber_1.bnOrZero)(slippageTolerance).lte(1);
12
+ if ((0, bignumber_1.bnOrZero)(expectedBuyAmountPrecision8).lt(0) || !isValidSlippageRange)
13
+ throw new api_1.SwapError('[getThorTxInfo]: bad expected buy amount or bad slippage tolerance', {
14
+ code: api_1.SwapErrorTypes.BUILD_TRADE_FAILED,
15
+ details: { expectedBuyAmountPrecision8, slippageTolerance }
16
+ });
17
+ const tradeFeePrecision8 = (0, bignumber_1.toBaseUnit)((0, bignumber_1.bnOrZero)(tradeFee), constants_1.THORCHAIN_FIXED_PRECISION);
18
+ return (0, bignumber_1.bnOrZero)(expectedBuyAmountPrecision8)
19
+ .times((0, bignumber_1.bn)(1).minus(slippageTolerance))
20
+ .minus((0, bignumber_1.bnOrZero)(tradeFeePrecision8))
21
+ .decimalPlaces(0)
22
+ .toString();
23
+ };
24
+ exports.getLimit = getLimit;
@@ -17,7 +17,14 @@ const makeSwapMemo = ({ buyAssetId, destinationAddress, limit }) => {
17
17
  code: api_1.SwapErrorTypes.MAKE_MEMO_FAILED,
18
18
  details: { buyAssetId }
19
19
  });
20
- const memo = `s:${thorId}:${destinationAddress}:${limit}:${constants_1.THORCHAIN_AFFILIATE_NAME}:${constants_1.THORCHAIN_AFFILIATE_BIPS}`;
20
+ // bch hack
21
+ // Our bitcoin cash addresses are prefixed with `bitcoincash:`
22
+ // But thorchain memos need to be short (under 80 bytes for utxo)
23
+ // For this reason thorchain doesnt allow / need bitcoincash: in the memo
24
+ const parsedDestinationAddress = destinationAddress.includes('bitcoincash:')
25
+ ? destinationAddress.replace('bitcoincash:', '')
26
+ : destinationAddress;
27
+ const memo = `s:${thorId}:${parsedDestinationAddress}:${limit}:${constants_1.THORCHAIN_AFFILIATE_NAME}:${constants_1.THORCHAIN_AFFILIATE_BIPS}`;
21
28
  if (memo.length <= MAX_LENGTH)
22
29
  return memo;
23
30
  const abbreviationAmount = memo.length - MAX_LENGTH;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/swapper",
3
- "version": "9.4.0",
3
+ "version": "9.6.1",
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",