@shapeshiftoss/swapper 9.2.2 → 9.3.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.
@@ -75,6 +75,11 @@ async function getCowSwapTradeQuote(deps, input) {
75
75
  .div((0, bignumber_1.bn)(10).exponentiatedBy(sellAsset.precision))
76
76
  .multipliedBy((0, bignumber_1.bnOrZero)(sellAssetUsdRate))
77
77
  .toString();
78
+ // If original sellAmount is < minQuoteSellAmount, we don't want to replace it with normalizedSellAmount
79
+ // The purpose of this was to get a quote from CowSwap even with small amounts
80
+ const quoteSellAmount = (0, bignumber_1.bnOrZero)(sellAmount).lt(minQuoteSellAmount)
81
+ ? sellAmount
82
+ : normalizedSellAmount;
78
83
  return {
79
84
  rate,
80
85
  minimum,
@@ -90,7 +95,7 @@ async function getCowSwapTradeQuote(deps, input) {
90
95
  },
91
96
  tradeFee: tradeFeeFiat
92
97
  },
93
- sellAmount: normalizedSellAmount,
98
+ sellAmount: quoteSellAmount,
94
99
  buyAmount: quote.buyAmount,
95
100
  sources: constants_1.DEFAULT_SOURCE,
96
101
  allowanceContract: constants_1.COW_SWAP_VAULT_RELAYER_ADDRESS,
@@ -27,13 +27,6 @@ const getThorTradeQuote = async ({ deps, input }) => {
27
27
  code: api_1.SwapErrorTypes.UNSUPPORTED_CHAIN,
28
28
  details: { chainId }
29
29
  });
30
- const buyAssetId = buyAsset.assetId;
31
- const feeAssetId = (0, caip_1.getFeeAssetIdFromAssetId)(buyAssetId);
32
- if (!feeAssetId)
33
- throw new api_1.SwapError(`[getThorTradeQuote] - No feeAssetId found for ${buyAssetId}.`, {
34
- code: api_1.SwapErrorTypes.VALIDATION_FAILED,
35
- details: { buyAssetId }
36
- });
37
30
  const tradeRate = await (0, getTradeRate_1.getTradeRate)(sellAsset, buyAsset.assetId, sellAmount, deps);
38
31
  const rate = (0, bignumber_1.bnOrZero)(1).div(tradeRate).toString();
39
32
  const buyAmount = (0, bignumber_1.toBaseUnit)((0, bignumber_1.bnOrZero)((0, bignumber_1.fromBaseUnit)(sellAmount, sellAsset.precision)).times(tradeRate), buyAsset.precision);
@@ -16,10 +16,6 @@ const thorTradeApprovalNeeded = async ({ deps, input }) => {
16
16
  const { chainNamespace } = (0, caip_1.fromChainId)(sellAsset.chainId);
17
17
  if (chainNamespace !== caip_1.CHAIN_NAMESPACE.Ethereum)
18
18
  return { approvalNeeded: false };
19
- // No approval needed for selling a fee asset
20
- if (sellAsset.assetId === (0, caip_1.getFeeAssetIdFromAssetId)(sellAsset.assetId)) {
21
- return { approvalNeeded: false };
22
- }
23
19
  const accountNumber = quote.sellAssetAccountNumber;
24
20
  const adapter = adapterManager.get(sellAsset.chainId);
25
21
  if (!adapter)
@@ -27,6 +23,10 @@ const thorTradeApprovalNeeded = async ({ deps, input }) => {
27
23
  code: api_1.SwapErrorTypes.UNSUPPORTED_CHAIN,
28
24
  details: { chainId: sellAsset.chainId }
29
25
  });
26
+ // No approval needed for selling a fee asset
27
+ if (sellAsset.assetId === adapter.getFeeAssetId()) {
28
+ return { approvalNeeded: false };
29
+ }
30
30
  const bip44Params = adapter.buildBIP44Params({ accountNumber });
31
31
  const receiveAddress = await adapter.getAddress({ wallet, bip44Params });
32
32
  if (!quote.allowanceContract) {
@@ -3,5 +3,7 @@ export declare const MAX_ALLOWANCE = "100000000000000000000000000";
3
3
  export declare const THOR_MINIMUM_PADDING = 1.2;
4
4
  export declare const THOR_ETH_GAS_LIMIT = "100000";
5
5
  export declare const THORCHAIN_FIXED_PRECISION = 8;
6
+ export declare const THORCHAIN_AFFILIATE_NAME = "ss";
7
+ export declare const THORCHAIN_AFFILIATE_BIPS = "0";
6
8
  export declare const THOR_TRADE_FEE_BTC_SIZE = 1000;
7
9
  export declare const THOR_TRADE_FEE_ETH_GAS = 120000;
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.THOR_TRADE_FEE_ETH_GAS = exports.THOR_TRADE_FEE_BTC_SIZE = exports.THORCHAIN_FIXED_PRECISION = exports.THOR_ETH_GAS_LIMIT = exports.THOR_MINIMUM_PADDING = exports.MAX_ALLOWANCE = exports.MAX_THORCHAIN_TRADE = void 0;
3
+ exports.THOR_TRADE_FEE_ETH_GAS = exports.THOR_TRADE_FEE_BTC_SIZE = exports.THORCHAIN_AFFILIATE_BIPS = exports.THORCHAIN_AFFILIATE_NAME = exports.THORCHAIN_FIXED_PRECISION = exports.THOR_ETH_GAS_LIMIT = exports.THOR_MINIMUM_PADDING = exports.MAX_ALLOWANCE = exports.MAX_THORCHAIN_TRADE = void 0;
4
4
  exports.MAX_THORCHAIN_TRADE = '100000000000000000000000000';
5
5
  exports.MAX_ALLOWANCE = '100000000000000000000000000';
6
6
  exports.THOR_MINIMUM_PADDING = 1.2;
7
7
  exports.THOR_ETH_GAS_LIMIT = '100000'; // for sends of eth / erc20 into thorchain router
8
8
  exports.THORCHAIN_FIXED_PRECISION = 8; // limit values are precision 8 regardless of the chain
9
+ exports.THORCHAIN_AFFILIATE_NAME = 'ss';
10
+ exports.THORCHAIN_AFFILIATE_BIPS = '0'; // affiliate fee in basis points (100 = 1%)
9
11
  // These are different from THOR_ETH_GAS_LIMIT
10
12
  // Used to estimate the fee thorchain will take out of the buyAsset
11
13
  exports.THOR_TRADE_FEE_BTC_SIZE = 1000; // used for estimating thorchain side fees
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makeSwapMemo = void 0;
4
4
  const caip_1 = require("@shapeshiftoss/caip");
5
5
  const api_1 = require("../../../../api");
6
+ const constants_1 = require("../constants");
6
7
  // BTC (and likely other utxo coins) can only support up to 80 character memos
7
8
  const MAX_LENGTH = 80;
8
9
  /**
@@ -16,7 +17,7 @@ const makeSwapMemo = ({ buyAssetId, destinationAddress, limit }) => {
16
17
  code: api_1.SwapErrorTypes.MAKE_MEMO_FAILED,
17
18
  details: { buyAssetId }
18
19
  });
19
- const memo = `s:${thorId}:${destinationAddress}:${limit}`;
20
+ const memo = `s:${thorId}:${destinationAddress}:${limit}:${constants_1.THORCHAIN_AFFILIATE_NAME}:${constants_1.THORCHAIN_AFFILIATE_BIPS}`;
20
21
  if (memo.length <= MAX_LENGTH)
21
22
  return memo;
22
23
  const abbreviationAmount = memo.length - MAX_LENGTH;
@@ -18,7 +18,7 @@ async function zrxApprovalNeeded({ adapter, web3 }, { quote, wallet }) {
18
18
  });
19
19
  }
20
20
  // No approval needed for selling a fee asset
21
- if (sellAsset.assetId === (0, caip_1.getFeeAssetIdFromAssetId)(sellAsset.assetId)) {
21
+ if (sellAsset.assetId === adapter.getFeeAssetId()) {
22
22
  return { approvalNeeded: false };
23
23
  }
24
24
  const accountNumber = quote.sellAssetAccountNumber;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/swapper",
3
- "version": "9.2.2",
3
+ "version": "9.3.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",