@shapeshiftoss/swapper 7.3.1 → 7.5.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
@@ -157,7 +157,7 @@ export declare enum SwapErrorTypes {
157
157
  PRICE_RATIO_FAILED = "PRICE_RATIO_FAILED",
158
158
  POOL_NOT_FOUND = "POOL_NOT_FOUND"
159
159
  }
160
- export interface Swapper<T extends ChainId, TxType = unknown> {
160
+ export interface Swapper<T extends ChainId> {
161
161
  /** perform any necessary async initialization */
162
162
  initialize(): Promise<void>;
163
163
  /** Returns the swapper type */
@@ -194,6 +194,6 @@ export interface Swapper<T extends ChainId, TxType = unknown> {
194
194
  * Get supported sell assetIds
195
195
  */
196
196
  filterAssetIdsBySellable(assetIds: AssetId[]): AssetId[];
197
- getTradeTxs(tradeResult: TradeResult): Promise<TxType>;
197
+ getTradeTxs(tradeResult: TradeResult): Promise<TradeTxs>;
198
198
  }
199
199
  export {};
@@ -2,7 +2,7 @@ import { ethereum } from '@shapeshiftoss/chain-adapters';
2
2
  import { ETHSignTx, HDWallet } from '@shapeshiftoss/hdwallet-core';
3
3
  import { Asset, BIP44Params } from '@shapeshiftoss/types';
4
4
  import { ThorchainSwapperDeps } from '../../types';
5
- export declare const makeTradeTx: ({ wallet, bip44Params, sellAmount, buyAsset, sellAsset, destinationAddress, adapter, maxFeePerGas, maxPriorityFeePerGas, slippageTolerance, deps, gasLimit }: {
5
+ export declare const makeTradeTx: ({ wallet, bip44Params, sellAmount, buyAsset, sellAsset, destinationAddress, adapter, maxFeePerGas, maxPriorityFeePerGas, gasPrice, slippageTolerance, deps, gasLimit }: {
6
6
  wallet: HDWallet;
7
7
  bip44Params: BIP44Params;
8
8
  sellAmount: string;
@@ -10,11 +10,17 @@ export declare const makeTradeTx: ({ wallet, bip44Params, sellAmount, buyAsset,
10
10
  sellAsset: Asset;
11
11
  destinationAddress: string;
12
12
  adapter: ethereum.ChainAdapter;
13
- maxFeePerGas: string;
14
- maxPriorityFeePerGas: string;
15
13
  slippageTolerance: string;
16
14
  deps: ThorchainSwapperDeps;
17
15
  gasLimit: string;
18
- }) => Promise<{
16
+ } & ({
17
+ gasPrice: string;
18
+ maxFeePerGas?: undefined;
19
+ maxPriorityFeePerGas?: undefined;
20
+ } | {
21
+ gasPrice?: undefined;
22
+ maxFeePerGas: string;
23
+ maxPriorityFeePerGas: string;
24
+ })) => Promise<{
19
25
  txToSign: ETHSignTx;
20
26
  }>;
@@ -4,10 +4,10 @@ exports.makeTradeTx = void 0;
4
4
  const caip_1 = require("@shapeshiftoss/caip");
5
5
  const api_1 = require("../../../../api");
6
6
  const getThorTxData_1 = require("../ethereum/utils/getThorTxData");
7
- const makeTradeTx = async ({ wallet, bip44Params, sellAmount, buyAsset, sellAsset, destinationAddress, adapter, maxFeePerGas, maxPriorityFeePerGas, slippageTolerance, deps, gasLimit }) => {
7
+ const makeTradeTx = async ({ wallet, bip44Params, sellAmount, buyAsset, sellAsset, destinationAddress, adapter, maxFeePerGas, maxPriorityFeePerGas, gasPrice, slippageTolerance, deps, gasLimit }) => {
8
8
  try {
9
- const { assetReference } = (0, caip_1.fromAssetId)(sellAsset.assetId);
10
- const isErc20Trade = assetReference.startsWith('0x');
9
+ const { assetNamespace } = (0, caip_1.fromAssetId)(sellAsset.assetId);
10
+ const isErc20Trade = assetNamespace === 'erc20';
11
11
  const { data, router } = await (0, getThorTxData_1.getThorTxInfo)({
12
12
  deps,
13
13
  sellAsset,
@@ -22,8 +22,14 @@ const makeTradeTx = async ({ wallet, bip44Params, sellAmount, buyAsset, sellAsse
22
22
  bip44Params,
23
23
  to: router,
24
24
  gasLimit,
25
- maxFeePerGas,
26
- maxPriorityFeePerGas,
25
+ ...(gasPrice !== undefined
26
+ ? {
27
+ gasPrice
28
+ }
29
+ : {
30
+ maxFeePerGas,
31
+ maxPriorityFeePerGas
32
+ }),
27
33
  value: isErc20Trade ? '0' : sellAmount,
28
34
  data
29
35
  });
@@ -0,0 +1,13 @@
1
+ import { ChainAdapterManager } from '@shapeshiftoss/chain-adapters';
2
+ import { Asset } from '@shapeshiftoss/types';
3
+ import { QuoteFeeData } from '../../../../../api';
4
+ import { ThorchainSwapperDeps } from '../../../types';
5
+ export declare const getBtcTxFees: ({ deps, opReturnData, vault, buyAsset, sellAmount, adapterManager, pubkey }: {
6
+ deps: ThorchainSwapperDeps;
7
+ opReturnData: string;
8
+ vault: string;
9
+ buyAsset: Asset;
10
+ sellAmount: string;
11
+ adapterManager: ChainAdapterManager;
12
+ pubkey: string;
13
+ }) => Promise<QuoteFeeData<'bip122:000000000019d6689c085ae165831e93'>>;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getBtcTxFees = void 0;
4
+ const api_1 = require("../../../../../api");
5
+ const bignumber_1 = require("../../../../utils/bignumber");
6
+ const estimateTradeFee_1 = require("../../estimateTradeFee/estimateTradeFee");
7
+ const getBtcTxFees = async ({ deps, opReturnData, vault, buyAsset, sellAmount, adapterManager, pubkey }) => {
8
+ try {
9
+ const adapter = adapterManager.get('bip122:000000000019d6689c085ae165831e93');
10
+ if (!adapter)
11
+ throw new api_1.SwapError(`[getBtcTxFees] - No chain adapter found for ${'bip122:000000000019d6689c085ae165831e93'}.`, {
12
+ code: api_1.SwapErrorTypes.UNSUPPORTED_CHAIN,
13
+ details: { chainId: 'bip122:000000000019d6689c085ae165831e93' }
14
+ });
15
+ const feeDataOptions = await adapter.getFeeData({
16
+ to: vault,
17
+ value: sellAmount,
18
+ chainSpecific: { pubkey, opReturnData }
19
+ });
20
+ const feeData = feeDataOptions['fast'];
21
+ const tradeFee = await (0, estimateTradeFee_1.estimateTradeFee)(deps, buyAsset.assetId);
22
+ return {
23
+ fee: feeData.txFee,
24
+ tradeFee,
25
+ chainSpecific: {
26
+ satsPerByte: feeData.chainSpecific.satoshiPerByte,
27
+ byteCount: (0, bignumber_1.bn)(feeData.txFee)
28
+ .dividedBy(feeData.chainSpecific.satoshiPerByte)
29
+ .dp(0)
30
+ .toString()
31
+ }
32
+ };
33
+ }
34
+ catch (e) {
35
+ if (e instanceof api_1.SwapError)
36
+ throw e;
37
+ throw new api_1.SwapError('[getBtcTxFeess]', { cause: e, code: api_1.SwapErrorTypes.TRADE_QUOTE_FAILED });
38
+ }
39
+ };
40
+ exports.getBtcTxFees = getBtcTxFees;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/swapper",
3
- "version": "7.3.1",
3
+ "version": "7.5.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",
@@ -32,7 +32,7 @@
32
32
  "peerDependencies": {
33
33
  "@shapeshiftoss/asset-service": "^5.0.0",
34
34
  "@shapeshiftoss/caip": "^6.0.1",
35
- "@shapeshiftoss/chain-adapters": "^6.0.1",
35
+ "@shapeshiftoss/chain-adapters": "^7.0.3",
36
36
  "@shapeshiftoss/errors": "^1.1.1",
37
37
  "@shapeshiftoss/hdwallet-core": "^1.23.0",
38
38
  "@shapeshiftoss/types": "^5.0.0"
@@ -40,7 +40,7 @@
40
40
  "devDependencies": {
41
41
  "@shapeshiftoss/asset-service": "^5.0.0",
42
42
  "@shapeshiftoss/caip": "^6.0.1",
43
- "@shapeshiftoss/chain-adapters": "^6.0.1",
43
+ "@shapeshiftoss/chain-adapters": "^7.0.3",
44
44
  "@shapeshiftoss/errors": "^1.1.1",
45
45
  "@shapeshiftoss/hdwallet-core": "^1.23.0",
46
46
  "@shapeshiftoss/types": "^5.0.0",