@shapeshiftoss/swapper 12.1.0 → 13.0.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/api.d.ts CHANGED
@@ -62,10 +62,6 @@ export declare type QuoteFeeData<T extends ChainId> = {
62
62
  networkFee: string;
63
63
  buyAssetTradeFeeUsd: string;
64
64
  sellAssetTradeFeeUsd?: string;
65
- /** @deprecated Use networkFee instead */
66
- fee: string;
67
- /** @deprecated Use sellAssetTradeFeeUsd instead */
68
- tradeFee: string;
69
65
  } & ChainSpecificQuoteFeeData<T>;
70
66
  export declare type ByPairInput = {
71
67
  sellAssetId: AssetId;
@@ -79,13 +79,11 @@ async function cowBuildTrade(deps, input) {
79
79
  const trade = {
80
80
  rate,
81
81
  feeData: {
82
- fee: '0',
83
82
  networkFee: '0',
84
83
  chainSpecific: {
85
84
  estimatedGas: feeData.chainSpecific.gasLimit,
86
85
  gasPrice: feeData.chainSpecific.gasPrice,
87
86
  },
88
- tradeFee: '0',
89
87
  buyAssetTradeFeeUsd: '0',
90
88
  sellAssetTradeFeeUsd,
91
89
  },
@@ -99,7 +97,7 @@ async function cowBuildTrade(deps, input) {
99
97
  feeAmountInSellToken: quote.feeAmount,
100
98
  sellAmountWithoutFee: quote.sellAmount,
101
99
  };
102
- const allowanceRequired = await (0, helpers_1.getAllowanceRequired)({
100
+ const approvalRequired = await (0, helpers_1.isApprovalRequired)({
103
101
  adapter,
104
102
  sellAsset,
105
103
  allowanceContract: constants_1.COW_SWAP_VAULT_RELAYER_ADDRESS,
@@ -108,7 +106,7 @@ async function cowBuildTrade(deps, input) {
108
106
  web3: deps.web3,
109
107
  erc20AllowanceAbi: erc20Allowance_abi_1.erc20AllowanceAbi,
110
108
  });
111
- if (!allowanceRequired.isZero()) {
109
+ if (approvalRequired) {
112
110
  trade.feeData.chainSpecific.approvalFee = (0, bignumber_1.bnOrZero)(feeData.chainSpecific.gasLimit)
113
111
  .multipliedBy((0, bignumber_1.bnOrZero)(feeData.chainSpecific.gasPrice))
114
112
  .toString();
@@ -96,7 +96,6 @@ async function getCowSwapTradeQuote(deps, input) {
96
96
  minimum,
97
97
  maximum,
98
98
  feeData: {
99
- fee: '0',
100
99
  networkFee: '0',
101
100
  chainSpecific: {
102
101
  estimatedGas: feeData.chainSpecific.gasLimit,
@@ -105,7 +104,6 @@ async function getCowSwapTradeQuote(deps, input) {
105
104
  .multipliedBy((0, bignumber_1.bnOrZero)(feeData.chainSpecific.gasPrice))
106
105
  .toString(),
107
106
  },
108
- tradeFee: '0',
109
107
  buyAssetTradeFeeUsd: '0',
110
108
  sellAssetTradeFeeUsd,
111
109
  },
@@ -107,8 +107,6 @@ class OsmosisSwapper {
107
107
  buyAmount,
108
108
  buyAsset,
109
109
  feeData: {
110
- fee,
111
- tradeFee: buyAssetTradeFeeUsd,
112
110
  networkFee: fee,
113
111
  sellAssetTradeFeeUsd: '0',
114
112
  buyAssetTradeFeeUsd,
@@ -140,8 +138,6 @@ class OsmosisSwapper {
140
138
  return {
141
139
  buyAsset,
142
140
  feeData: {
143
- fee,
144
- tradeFee: buyAssetTradeFeeUsd,
145
141
  networkFee: fee,
146
142
  sellAssetTradeFeeUsd: '0',
147
143
  buyAssetTradeFeeUsd,
@@ -126,9 +126,7 @@ const getThorTradeQuote = async ({ deps, input }) => {
126
126
  ...commonQuoteFields,
127
127
  allowanceContract: '0x0',
128
128
  feeData: {
129
- fee: feeData.fast.txFee,
130
129
  networkFee: feeData.fast.txFee,
131
- tradeFee: buyAssetTradeFeeUsdOrDefault,
132
130
  buyAssetTradeFeeUsd: buyAssetTradeFeeUsdOrDefault,
133
131
  sellAssetTradeFeeUsd: '0',
134
132
  chainSpecific: { estimatedGas: feeData.fast.chainSpecific.gasLimit },
@@ -40,7 +40,7 @@ const cosmosTxData = async (input) => {
40
40
  wallet,
41
41
  memo,
42
42
  gas: quote.feeData.chainSpecific.estimatedGas,
43
- fee: quote.feeData.fee,
43
+ fee: quote.feeData.networkFee,
44
44
  });
45
45
  return buildTxResponse.txToSign;
46
46
  }
@@ -58,7 +58,7 @@ const cosmosTxData = async (input) => {
58
58
  memo,
59
59
  chainSpecific: {
60
60
  gas: quote.feeData.chainSpecific.estimatedGas,
61
- fee: quote.feeData.fee,
61
+ fee: quote.feeData.networkFee,
62
62
  },
63
63
  });
64
64
  return buildTxResponse.txToSign;
@@ -23,9 +23,7 @@ const getBtcTxFees = async ({ opReturnData, vault, sellAmount, sellAdapter, pubk
23
23
  const networkFee = feeMultiplier.times(feeData.txFee).dp(0).toString();
24
24
  const satsPerByte = feeMultiplier.times(feeData.chainSpecific.satoshiPerByte).dp(0).toString();
25
25
  return {
26
- fee: networkFee,
27
26
  networkFee,
28
- tradeFee: buyAssetTradeFeeUsd,
29
27
  buyAssetTradeFeeUsd,
30
28
  sellAssetTradeFeeUsd: '0',
31
29
  chainSpecific: {
@@ -31,7 +31,6 @@ const getEthTxFees = async ({ adapterManager, sellAssetReference, buyAssetTradeF
31
31
  };
32
32
  const feeData = feeDataOptions['fast'];
33
33
  return {
34
- fee: feeData.txFee,
35
34
  networkFee: feeData.txFee,
36
35
  chainSpecific: {
37
36
  estimatedGas: feeData.chainSpecific.gasLimit,
@@ -41,7 +40,6 @@ const getEthTxFees = async ({ adapterManager, sellAssetReference, buyAssetTradeF
41
40
  .multipliedBy((0, bignumber_1.bnOrZero)(feeData.chainSpecific.gasPrice))
42
41
  .toString(),
43
42
  },
44
- tradeFee: buyAssetTradeFeeUsd,
45
43
  buyAssetTradeFeeUsd,
46
44
  sellAssetTradeFeeUsd: '0',
47
45
  };
@@ -1,11 +1,10 @@
1
1
  import { Asset } from '@shapeshiftoss/asset-service';
2
2
  import { HDWallet } from '@shapeshiftoss/hdwallet-core';
3
- import BigNumber from 'bignumber.js';
4
3
  import Web3 from 'web3';
5
4
  import { AbiItem } from 'web3-utils';
6
5
  import { EvmSupportedChainAdapters, EvmSupportedChainIds, TradeQuote } from '../../../api';
7
6
  import { BN } from '../bignumber';
8
- export declare type GetAllowanceRequiredArgs = {
7
+ export declare type IsApprovalRequiredArgs = {
9
8
  adapter: EvmSupportedChainAdapters;
10
9
  receiveAddress: string;
11
10
  allowanceContract: string;
@@ -34,7 +33,7 @@ declare type GrantAllowanceArgs<T extends EvmSupportedChainIds> = {
34
33
  web3: Web3;
35
34
  };
36
35
  export declare const getERC20Allowance: ({ erc20AllowanceAbi, web3, sellAssetErc20Address, ownerAddress, spenderAddress, }: GetERC20AllowanceArgs) => Promise<any>;
37
- export declare const getAllowanceRequired: ({ adapter, receiveAddress, allowanceContract, sellAsset, sellAmount, web3, erc20AllowanceAbi, }: GetAllowanceRequiredArgs) => Promise<BigNumber>;
36
+ export declare const isApprovalRequired: ({ adapter, receiveAddress, allowanceContract, sellAsset, sellAmount, web3, erc20AllowanceAbi, }: IsApprovalRequiredArgs) => Promise<boolean>;
38
37
  export declare const grantAllowance: <T extends EvmSupportedChainIds>({ quote, wallet, adapter, erc20Abi, web3, }: GrantAllowanceArgs<T>) => Promise<string>;
39
38
  /**
40
39
  * This function keeps 17 significant digits, so even if we try to trade 1 Billion of an
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getApproveContractData = exports.normalizeIntegerAmount = exports.normalizeAmount = exports.grantAllowance = exports.getAllowanceRequired = exports.getERC20Allowance = void 0;
3
+ exports.getApproveContractData = exports.normalizeIntegerAmount = exports.normalizeAmount = exports.grantAllowance = exports.isApprovalRequired = exports.getERC20Allowance = void 0;
4
4
  const caip_1 = require("@shapeshiftoss/caip");
5
5
  const web3_utils_1 = require("web3-utils");
6
6
  const api_1 = require("../../../api");
@@ -12,10 +12,10 @@ const getERC20Allowance = async ({ erc20AllowanceAbi, web3, sellAssetErc20Addres
12
12
  return erc20Contract.methods.allowance(ownerAddress, spenderAddress).call();
13
13
  };
14
14
  exports.getERC20Allowance = getERC20Allowance;
15
- const getAllowanceRequired = async ({ adapter, receiveAddress, allowanceContract, sellAsset, sellAmount, web3, erc20AllowanceAbi, }) => {
15
+ const isApprovalRequired = async ({ adapter, receiveAddress, allowanceContract, sellAsset, sellAmount, web3, erc20AllowanceAbi, }) => {
16
16
  try {
17
17
  if (sellAsset.assetId === adapter.getFeeAssetId()) {
18
- return (0, bignumber_1.bn)(0);
18
+ return false;
19
19
  }
20
20
  const ownerAddress = receiveAddress;
21
21
  const spenderAddress = allowanceContract;
@@ -27,27 +27,27 @@ const getAllowanceRequired = async ({ adapter, receiveAddress, allowanceContract
27
27
  spenderAddress,
28
28
  sellAssetErc20Address,
29
29
  });
30
- if (allowanceOnChain === '0')
31
- return (0, bignumber_1.bnOrZero)(sellAmount);
32
30
  if (!allowanceOnChain) {
33
- throw new api_1.SwapError(`[getAllowanceRequired] - No allowance data`, {
31
+ throw new api_1.SwapError(`[isApprovalRequired] - No allowance data`, {
34
32
  details: { allowanceContract, receiveAddress },
35
33
  code: api_1.SwapErrorTypes.RESPONSE_ERROR,
36
34
  });
37
35
  }
36
+ if ((0, bignumber_1.bn)(allowanceOnChain).isZero())
37
+ return true;
38
38
  const allowanceRequired = (0, bignumber_1.bnOrZero)(sellAmount).minus(allowanceOnChain);
39
- return allowanceRequired.lt(0) ? (0, bignumber_1.bn)(0) : allowanceRequired;
39
+ return allowanceRequired.gt(0);
40
40
  }
41
41
  catch (e) {
42
42
  if (e instanceof api_1.SwapError)
43
43
  throw e;
44
- throw new api_1.SwapError('[getAllowanceRequired]', {
44
+ throw new api_1.SwapError('[isApprovalRequired]', {
45
45
  cause: e,
46
46
  code: api_1.SwapErrorTypes.ALLOWANCE_REQUIRED_FAILED,
47
47
  });
48
48
  }
49
49
  };
50
- exports.getAllowanceRequired = getAllowanceRequired;
50
+ exports.isApprovalRequired = isApprovalRequired;
51
51
  const grantAllowance = async ({ quote, wallet, adapter, erc20Abi, web3, }) => {
52
52
  var _a, _b, _c, _d, _e;
53
53
  try {
@@ -16,8 +16,6 @@ const setupQuote = () => {
16
16
  minimum: '0',
17
17
  maximum: '999999999999',
18
18
  feeData: {
19
- fee: '0',
20
- tradeFee: '0',
21
19
  chainSpecific: {},
22
20
  sellAssetTradeFeeUsd: '0',
23
21
  networkFee: '0',
@@ -58,13 +58,11 @@ async function getZrxTradeQuote(input) {
58
58
  minimum,
59
59
  maximum,
60
60
  feeData: {
61
- fee,
62
61
  chainSpecific: {
63
62
  estimatedGas: estimatedGas.toString(),
64
63
  gasPrice,
65
64
  approvalFee,
66
65
  },
67
- tradeFee: '0',
68
66
  networkFee: fee,
69
67
  buyAssetTradeFeeUsd: '0',
70
68
  sellAssetTradeFeeUsd: '0',
@@ -26,9 +26,7 @@ export declare const setupExecuteTrade: () => {
26
26
  depositAddress: string;
27
27
  receiveAddress: string;
28
28
  feeData: {
29
- fee: string;
30
29
  chainSpecific: {};
31
- tradeFee: string;
32
30
  buyAssetTradeFeeUsd: string;
33
31
  sellAssetTradeFeeUsd: string;
34
32
  networkFee: string;
@@ -38,9 +38,7 @@ const setupExecuteTrade = () => {
38
38
  depositAddress: '0x0',
39
39
  receiveAddress: '0x0',
40
40
  feeData: {
41
- fee: '0',
42
41
  chainSpecific: {},
43
- tradeFee: '0',
44
42
  buyAssetTradeFeeUsd: '0',
45
43
  sellAssetTradeFeeUsd: '0',
46
44
  networkFee: '0',
@@ -92,7 +92,7 @@ async function zrxBuildTrade({ adapter, web3 }, input) {
92
92
  const { data } = quoteResponse;
93
93
  const estimatedGas = (0, bignumber_1.bnOrZero)(data.gas || 0);
94
94
  const networkFee = (0, bignumber_1.bnOrZero)(estimatedGas).multipliedBy((0, bignumber_1.bnOrZero)(data.gasPrice)).toString();
95
- const allowanceRequired = await (0, helpers_1.getAllowanceRequired)({
95
+ const approvalRequired = await (0, helpers_1.isApprovalRequired)({
96
96
  adapter,
97
97
  sellAsset,
98
98
  allowanceContract: data.allowanceTarget,
@@ -112,13 +112,11 @@ async function zrxBuildTrade({ adapter, web3 }, input) {
112
112
  rate: data.price,
113
113
  depositAddress: data.to,
114
114
  feeData: {
115
- fee: networkFee,
116
115
  chainSpecific: {
117
116
  estimatedGas: estimatedGas.toString(),
118
117
  gasPrice: data.gasPrice,
119
- approvalFee: allowanceRequired.gt(0) ? approvalFee : undefined,
118
+ approvalFee: approvalRequired ? approvalFee : undefined,
120
119
  },
121
- tradeFee: '0',
122
120
  networkFee,
123
121
  buyAssetTradeFeeUsd: '0',
124
122
  sellAssetTradeFeeUsd: '0',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/swapper",
3
- "version": "12.1.0",
3
+ "version": "13.0.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",