@shapeshiftoss/swapper 7.4.0 → 7.6.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
@@ -1,6 +1,6 @@
1
1
  import { AssetId, ChainId } from '@shapeshiftoss/caip';
2
2
  import { BTCSignTx, ETHSignTx, HDWallet } from '@shapeshiftoss/hdwallet-core';
3
- import { Asset, ChainSpecific, KnownChainIds } from '@shapeshiftoss/types';
3
+ import { Asset, BIP44Params, ChainSpecific, KnownChainIds, UtxoAccountType } from '@shapeshiftoss/types';
4
4
  export declare const SwapError: {
5
5
  new <V extends {
6
6
  cause?: unknown;
@@ -58,8 +58,17 @@ export declare type CommonTradeInput = {
58
58
  sellAssetAccountNumber: number;
59
59
  wallet?: HDWallet;
60
60
  };
61
- export declare type GetTradeQuoteInput = CommonTradeInput;
62
- export declare type BuildTradeInput = CommonTradeInput & {
61
+ export declare type GetEthTradeQuoteInput = CommonTradeInput & {
62
+ chainId: 'eip155:1';
63
+ };
64
+ export declare type GetBtcTradeQuoteInput = CommonTradeInput & {
65
+ chainId: 'bip122:000000000019d6689c085ae165831e93';
66
+ accountType: UtxoAccountType;
67
+ bip44Params: BIP44Params;
68
+ wallet: HDWallet;
69
+ };
70
+ export declare type GetTradeQuoteInput = GetEthTradeQuoteInput | GetBtcTradeQuoteInput;
71
+ export declare type BuildTradeInput = GetTradeQuoteInput & {
63
72
  buyAssetAccountNumber: number;
64
73
  slippage?: string;
65
74
  wallet: HDWallet;
@@ -157,7 +166,7 @@ export declare enum SwapErrorTypes {
157
166
  PRICE_RATIO_FAILED = "PRICE_RATIO_FAILED",
158
167
  POOL_NOT_FOUND = "POOL_NOT_FOUND"
159
168
  }
160
- export interface Swapper<T extends ChainId, TxType = unknown> {
169
+ export interface Swapper<T extends ChainId> {
161
170
  /** perform any necessary async initialization */
162
171
  initialize(): Promise<void>;
163
172
  /** Returns the swapper type */
@@ -194,6 +203,6 @@ export interface Swapper<T extends ChainId, TxType = unknown> {
194
203
  * Get supported sell assetIds
195
204
  */
196
205
  filterAssetIdsBySellable(assetIds: AssetId[]): AssetId[];
197
- getTradeTxs(tradeResult: TradeResult): Promise<TxType>;
206
+ getTradeTxs(tradeResult: TradeResult): Promise<TradeTxs>;
198
207
  }
199
208
  export {};
@@ -109,11 +109,11 @@ const main = async () => {
109
109
  let quote;
110
110
  try {
111
111
  quote = await swapper.getTradeQuote({
112
+ chainId: 'eip155:1',
112
113
  sellAsset,
113
114
  buyAsset,
114
115
  sellAmount: sellAmountBase,
115
116
  sellAssetAccountNumber: 0,
116
- wallet,
117
117
  sendMax: false
118
118
  });
119
119
  }
@@ -128,6 +128,7 @@ const main = async () => {
128
128
  const answer = readline_sync_1.default.question(`Swap ${sellAmount} ${sellAsset.symbol} for ${buyAmount} ${buyAsset.symbol} on ${swapper.getType()}? (y/n): `);
129
129
  if (answer === 'y') {
130
130
  const trade = await swapper.buildTrade({
131
+ chainId: 'eip155:1',
131
132
  wallet,
132
133
  buyAsset,
133
134
  sendMax: false,
@@ -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
  });
@@ -1,7 +1,7 @@
1
1
  import { Asset } from '@shapeshiftoss/types';
2
2
  import { TradeQuote } from '../../../api';
3
3
  export declare const setupQuote: () => {
4
- quoteInput: import("../../../api").CommonTradeInput;
4
+ quoteInput: import("../../../api").GetEthTradeQuoteInput;
5
5
  tradeQuote: TradeQuote<"eip155:1">;
6
6
  buyAsset: Asset;
7
7
  sellAsset: Asset;
@@ -19,6 +19,7 @@ const setupQuote = () => {
19
19
  sources: []
20
20
  };
21
21
  const quoteInput = {
22
+ chainId: 'eip155:1',
22
23
  sellAmount: '1000000000000000000',
23
24
  sellAsset,
24
25
  buyAsset,
@@ -1,3 +1,4 @@
1
+ import { HDWallet } from '@shapeshiftoss/hdwallet-core';
1
2
  import { Asset } from '@shapeshiftoss/types';
2
3
  import { ZrxQuoteResponse } from '../../types';
3
4
  export declare const setupZrxTradeQuoteResponse: () => {
@@ -6,17 +7,12 @@ export declare const setupZrxTradeQuoteResponse: () => {
6
7
  sellAsset: Asset;
7
8
  };
8
9
  export declare const setupBuildTrade: () => {
9
- buildTradeInput: {
10
- sellAmount: string;
11
- allowanceTarget: string;
12
- price: string;
13
- to: string;
14
- buyAmount: string;
15
- buyAsset: Asset;
16
- sendMax: boolean;
17
- sellAssetAccountNumber: number;
10
+ buildTradeInput: import("../../../../api").CommonTradeInput & {
11
+ chainId: "eip155:1";
12
+ } & {
18
13
  buyAssetAccountNumber: number;
19
- sellAsset: Asset;
14
+ slippage?: string | undefined;
15
+ wallet: HDWallet;
20
16
  };
21
17
  buyAsset: Asset;
22
18
  sellAsset: Asset;
@@ -23,16 +23,14 @@ const setupBuildTrade = () => {
23
23
  const sellAsset = { ...assets_1.FOX };
24
24
  const buyAsset = { ...assets_1.WETH };
25
25
  const buildTradeInput = {
26
+ chainId: 'eip155:1',
26
27
  sellAmount: '1000000000000000000',
27
- allowanceTarget: 'allowanceTargetAddress',
28
- price: '1',
29
- to: '0x123',
30
- buyAmount: '',
31
28
  buyAsset,
32
29
  sendMax: false,
33
30
  sellAssetAccountNumber: 0,
34
31
  buyAssetAccountNumber: 0,
35
- sellAsset
32
+ sellAsset,
33
+ wallet: {}
36
34
  };
37
35
  return { buildTradeInput, buyAsset, sellAsset };
38
36
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/swapper",
3
- "version": "7.4.0",
3
+ "version": "7.6.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",