@shapeshiftoss/swapper 11.2.0 → 11.3.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
@@ -74,13 +74,12 @@ export declare type SupportedSellAssetsInput = {
74
74
  assetIds: AssetId[];
75
75
  };
76
76
  declare type CommonTradeInput = {
77
- bip44Params?: BIP44Params;
78
77
  sellAsset: Asset;
79
78
  buyAsset: Asset;
80
79
  sellAmount: string;
81
80
  sendMax: boolean;
82
- sellAssetAccountNumber: number;
83
81
  receiveAddress: string;
82
+ bip44Params: BIP44Params;
84
83
  };
85
84
  export declare type EvmSupportedChainIds = KnownChainIds.EthereumMainnet | KnownChainIds.AvalancheMainnet;
86
85
  export declare type CosmosSdkSupportedChainIds = KnownChainIds.CosmosMainnet | KnownChainIds.OsmosisMainnet | KnownChainIds.ThorchainMainnet;
@@ -112,7 +111,7 @@ interface TradeBase<C extends ChainId> {
112
111
  sources: SwapSource[];
113
112
  buyAsset: Asset;
114
113
  sellAsset: Asset;
115
- sellAssetAccountNumber: number;
114
+ bip44Params: BIP44Params;
116
115
  }
117
116
  export interface TradeQuote<C extends ChainId> extends TradeBase<C> {
118
117
  allowanceContract: string;
@@ -139,7 +139,6 @@ const main = async () => {
139
139
  sellAsset,
140
140
  buyAsset,
141
141
  sellAmount: sellAmountBase,
142
- sellAssetAccountNumber: 0,
143
142
  sendMax: false,
144
143
  accountType: utxoAccountType || chain_adapters_1.bitcoin.ChainAdapter.defaultUtxoAccountType,
145
144
  bip44Params,
@@ -165,7 +164,6 @@ const main = async () => {
165
164
  sendMax: false,
166
165
  sellAmount: sellAmountBase,
167
166
  sellAsset,
168
- sellAssetAccountNumber: 0,
169
167
  receiveAddress: buyAssetReceiveAddr,
170
168
  accountType: utxoAccountType || chain_adapters_1.bitcoin.ChainAdapter.defaultUtxoAccountType,
171
169
  bip44Params,
@@ -12,7 +12,7 @@ const cowService_1 = require("../utils/cowService");
12
12
  const helpers_2 = require("../utils/helpers/helpers");
13
13
  async function cowBuildTrade(deps, input) {
14
14
  try {
15
- const { sellAsset, buyAsset, sellAmount, sellAssetAccountNumber, wallet } = input;
15
+ const { sellAsset, buyAsset, sellAmount, bip44Params, wallet } = input;
16
16
  const { adapter, web3 } = deps;
17
17
  const { assetReference: sellAssetErc20Address, assetNamespace: sellAssetNamespace } = (0, caip_1.fromAssetId)(sellAsset.assetId);
18
18
  const { assetReference: buyAssetErc20Address, chainId: buyAssetChainId } = (0, caip_1.fromAssetId)(buyAsset.assetId);
@@ -86,7 +86,7 @@ async function cowBuildTrade(deps, input) {
86
86
  sources: constants_1.DEFAULT_SOURCE,
87
87
  buyAsset,
88
88
  sellAsset,
89
- sellAssetAccountNumber,
89
+ bip44Params,
90
90
  receiveAddress,
91
91
  feeAmountInSellToken: quote.feeAmount,
92
92
  sellAmountWithoutFee: quote.sellAmount,
@@ -17,7 +17,7 @@ const helpers_2 = require("../utils/helpers/helpers");
17
17
  async function getCowSwapTradeQuote(deps, input) {
18
18
  var _a, _b;
19
19
  try {
20
- const { sellAsset, buyAsset, sellAmount, sellAssetAccountNumber, receiveAddress } = input;
20
+ const { sellAsset, buyAsset, sellAmount, bip44Params, receiveAddress } = input;
21
21
  const { adapter, web3 } = deps;
22
22
  const { assetReference: sellAssetErc20Address, assetNamespace: sellAssetNamespace } = (0, caip_1.fromAssetId)(sellAsset.assetId);
23
23
  const { assetReference: buyAssetErc20Address, chainId: buyAssetChainId } = (0, caip_1.fromAssetId)(buyAsset.assetId);
@@ -113,7 +113,7 @@ async function getCowSwapTradeQuote(deps, input) {
113
113
  allowanceContract: constants_1.COW_SWAP_VAULT_RELAYER_ADDRESS,
114
114
  buyAsset,
115
115
  sellAsset,
116
- sellAssetAccountNumber,
116
+ bip44Params,
117
117
  };
118
118
  }
119
119
  catch (e) {
@@ -87,7 +87,7 @@ class OsmosisSwapper {
87
87
  return this.supportedAssetIds;
88
88
  }
89
89
  async buildTrade(args) {
90
- const { sellAsset, buyAsset, sellAmount, receiveAddress } = args;
90
+ const { sellAsset, buyAsset, sellAmount, receiveAddress, bip44Params } = args;
91
91
  if (!sellAmount) {
92
92
  throw new api_1.SwapError('sellAmount is required', {
93
93
  code: api_1.SwapErrorTypes.BUILD_TRADE_FAILED,
@@ -111,12 +111,12 @@ class OsmosisSwapper {
111
111
  receiveAddress,
112
112
  sellAmount: amountBaseSell,
113
113
  sellAsset,
114
- sellAssetAccountNumber: 0,
114
+ bip44Params,
115
115
  sources: [{ name: 'Osmosis', proportion: '100' }],
116
116
  };
117
117
  }
118
118
  async getTradeQuote(input) {
119
- const { sellAsset, buyAsset, sellAmount } = input;
119
+ const { bip44Params, sellAsset, buyAsset, sellAmount } = input;
120
120
  if (!sellAmount) {
121
121
  throw new api_1.SwapError('sellAmount is required', {
122
122
  code: api_1.SwapErrorTypes.RESPONSE_ERROR,
@@ -136,7 +136,7 @@ class OsmosisSwapper {
136
136
  feeData: { fee, tradeFee },
137
137
  maximum,
138
138
  minimum,
139
- sellAssetAccountNumber: 0,
139
+ bip44Params,
140
140
  rate,
141
141
  sellAsset,
142
142
  sellAmount,
@@ -146,7 +146,7 @@ class OsmosisSwapper {
146
146
  };
147
147
  }
148
148
  async executeTrade({ trade, wallet }) {
149
- const { sellAsset, buyAsset, sellAmount, sellAssetAccountNumber, receiveAddress } = trade;
149
+ const { sellAsset, buyAsset, sellAmount, bip44Params, receiveAddress } = trade;
150
150
  const isFromOsmo = sellAsset.assetId === caip_1.osmosisAssetId;
151
151
  const sellAssetDenom = helpers_1.symbolDenomMapping[sellAsset.symbol];
152
152
  const buyAssetDenom = helpers_1.symbolDenomMapping[buyAsset.symbol];
@@ -163,10 +163,7 @@ class OsmosisSwapper {
163
163
  let sellAddress;
164
164
  let cosmosIbcTradeId = '';
165
165
  if (!isFromOsmo) {
166
- const sellBip44Params = cosmosAdapter.buildBIP44Params({
167
- accountNumber: Number(sellAssetAccountNumber),
168
- });
169
- sellAddress = await cosmosAdapter.getAddress({ wallet, bip44Params: sellBip44Params });
166
+ sellAddress = await cosmosAdapter.getAddress({ wallet, bip44Params });
170
167
  if (!sellAddress)
171
168
  throw new api_1.SwapError('Failed to get address', {
172
169
  code: api_1.SwapErrorTypes.EXECUTE_TRADE_FAILED,
@@ -193,10 +190,7 @@ class OsmosisSwapper {
193
190
  await new Promise((resolve) => setTimeout(resolve, 5000));
194
191
  }
195
192
  else {
196
- const sellBip44Params = osmosisAdapter.buildBIP44Params({
197
- accountNumber: Number(sellAssetAccountNumber),
198
- });
199
- sellAddress = await osmosisAdapter.getAddress({ wallet, bip44Params: sellBip44Params });
193
+ sellAddress = await osmosisAdapter.getAddress({ wallet, bip44Params });
200
194
  if (!sellAddress)
201
195
  throw new api_1.SwapError('failed to get osmoAddress', {
202
196
  code: api_1.SwapErrorTypes.EXECUTE_TRADE_FAILED,
@@ -12,7 +12,7 @@ const makeTradeTx_1 = require("../utils/ethereum/makeTradeTx");
12
12
  const buildTrade = async ({ deps, input, }) => {
13
13
  var _a, _b, _c, _d;
14
14
  try {
15
- const { bip44Params, buyAsset, receiveAddress: destinationAddress, sellAmount, sellAsset, sellAssetAccountNumber, slippage: slippageTolerance = constants_1.DEFAULT_SLIPPAGE, wallet, } = input;
15
+ const { buyAsset, receiveAddress: destinationAddress, sellAmount, sellAsset, bip44Params, slippage: slippageTolerance = constants_1.DEFAULT_SLIPPAGE, wallet, } = input;
16
16
  const quote = await (0, getTradeQuote_1.getThorTradeQuote)({ deps, input });
17
17
  const sellAdapter = deps.adapterManager.get(sellAsset.chainId);
18
18
  if (!sellAdapter)
@@ -23,13 +23,10 @@ const buildTrade = async ({ deps, input, }) => {
23
23
  });
24
24
  const { chainNamespace } = (0, caip_1.fromAssetId)(sellAsset.assetId);
25
25
  if (chainNamespace === caip_1.CHAIN_NAMESPACE.Evm) {
26
- const sellAssetBip44Params = sellAdapter.buildBIP44Params({
27
- accountNumber: sellAssetAccountNumber,
28
- });
29
26
  const ethTradeTx = await (0, makeTradeTx_1.makeTradeTx)({
30
27
  wallet,
31
28
  slippageTolerance,
32
- bip44Params: sellAssetBip44Params,
29
+ bip44Params,
33
30
  sellAsset,
34
31
  buyAsset,
35
32
  adapter: sellAdapter,
@@ -15,7 +15,10 @@ const getBtcTxFees_1 = require("../utils/txFeeHelpers/btcTxFees/getBtcTxFees");
15
15
  const getEthTxFees_1 = require("../utils/txFeeHelpers/ethTxFees/getEthTxFees");
16
16
  const MINIMUM_USD_TRADE_AMOUNT = (0, bignumber_1.bn)(1);
17
17
  const getThorTradeQuote = async ({ deps, input }) => {
18
- const { sellAsset, buyAsset, sellAmount, sellAssetAccountNumber, chainId, receiveAddress } = input;
18
+ const { sellAsset, buyAsset, sellAmount, bip44Params, chainId, receiveAddress } = input;
19
+ if (!bip44Params) {
20
+ throw new Error('bip44Params required in getThorTradeQuote');
21
+ }
19
22
  try {
20
23
  const { assetReference: sellAssetReference } = (0, caip_1.fromAssetId)(sellAsset.assetId);
21
24
  const sellAdapter = deps.adapterManager.get(chainId);
@@ -44,7 +47,7 @@ const getThorTradeQuote = async ({ deps, input }) => {
44
47
  sources: [{ name: 'thorchain', proportion: '1' }],
45
48
  buyAsset,
46
49
  sellAsset,
47
- sellAssetAccountNumber,
50
+ bip44Params,
48
51
  minimum,
49
52
  };
50
53
  const { chainNamespace } = (0, caip_1.fromAssetId)(sellAsset.assetId);
@@ -10,13 +10,12 @@ const thorTradeApprovalNeeded = async ({ deps, input, }) => {
10
10
  var _a;
11
11
  try {
12
12
  const { quote, wallet } = input;
13
- const { sellAsset } = quote;
13
+ const { sellAsset, bip44Params } = quote;
14
14
  const { adapterManager, web3 } = deps;
15
15
  const { assetReference: sellAssetErc20Address } = (0, caip_1.fromAssetId)(sellAsset.assetId);
16
16
  const { chainNamespace } = (0, caip_1.fromChainId)(sellAsset.chainId);
17
17
  if (chainNamespace !== caip_1.CHAIN_NAMESPACE.Evm)
18
18
  return { approvalNeeded: false };
19
- const accountNumber = quote.sellAssetAccountNumber;
20
19
  const adapter = adapterManager.get(sellAsset.chainId);
21
20
  if (!adapter)
22
21
  throw new api_1.SwapError(`[thorTradeApprovalNeeded] - no chain adapter found for chain Id: ${sellAsset.chainId}`, {
@@ -27,7 +26,6 @@ const thorTradeApprovalNeeded = async ({ deps, input, }) => {
27
26
  if (sellAsset.assetId === adapter.getFeeAssetId()) {
28
27
  return { approvalNeeded: false };
29
28
  }
30
- const bip44Params = adapter.buildBIP44Params({ accountNumber });
31
29
  const receiveAddress = await adapter.getAddress({ wallet, bip44Params });
32
30
  if (!quote.allowanceContract) {
33
31
  throw new api_1.SwapError('[thorTradeApprovalNeeded] - allowanceTarget is required', {
@@ -56,8 +56,7 @@ const grantAllowance = async ({ quote, wallet, adapter, erc20Abi, web3, }) => {
56
56
  const approveTx = erc20Contract.methods
57
57
  .approve(quote.allowanceContract, quote.sellAmount)
58
58
  .encodeABI();
59
- const accountNumber = quote.sellAssetAccountNumber;
60
- const bip44Params = adapter.buildBIP44Params({ accountNumber });
59
+ const { bip44Params } = quote;
61
60
  const { txToSign } = await adapter.buildSendTransaction({
62
61
  wallet,
63
62
  to: sellAssetErc20Address,
@@ -10,13 +10,12 @@ export declare const setupQuote: () => {
10
10
  };
11
11
  export declare const setupBuildTrade: () => {
12
12
  buildTradeInput: {
13
- bip44Params?: import("@shapeshiftoss/types").BIP44Params | undefined;
14
13
  sellAsset: Asset;
15
14
  buyAsset: Asset;
16
15
  sellAmount: string;
17
16
  sendMax: boolean;
18
- sellAssetAccountNumber: number;
19
17
  receiveAddress: string;
18
+ bip44Params: import("@shapeshiftoss/types").BIP44Params;
20
19
  } & {
21
20
  chainId: import("../../../api").EvmSupportedChainIds;
22
21
  } & {
@@ -12,7 +12,7 @@ const setupQuote = () => {
12
12
  sellAsset,
13
13
  buyAsset,
14
14
  allowanceContract: 'allowanceContractAddress',
15
- sellAssetAccountNumber: 0,
15
+ bip44Params: { purpose: 44, coinType: 60, accountNumber: 0 },
16
16
  minimum: '0',
17
17
  maximum: '999999999999',
18
18
  feeData: { fee: '0', tradeFee: '0', chainSpecific: {} },
@@ -24,7 +24,7 @@ const setupQuote = () => {
24
24
  sellAmount: '1000000000000000000',
25
25
  sellAsset,
26
26
  buyAsset,
27
- sellAssetAccountNumber: 0,
27
+ bip44Params: { purpose: 44, coinType: 60, accountNumber: 0 },
28
28
  sendMax: false,
29
29
  receiveAddress: '0xc770eefad204b5180df6a14ee197d99d808ee52d',
30
30
  };
@@ -39,7 +39,7 @@ const setupBuildTrade = () => {
39
39
  sellAmount: '1000000000000000000',
40
40
  buyAsset,
41
41
  sendMax: false,
42
- sellAssetAccountNumber: 0,
42
+ bip44Params: { purpose: 44, coinType: 60, accountNumber: 0 },
43
43
  sellAsset,
44
44
  wallet: {},
45
45
  receiveAddress: '',
@@ -12,7 +12,7 @@ const helpers_2 = require("../utils/helpers/helpers");
12
12
  const zrxService_1 = require("../utils/zrxService");
13
13
  async function getZrxTradeQuote(input) {
14
14
  try {
15
- const { sellAsset, buyAsset, sellAmount, sellAssetAccountNumber } = input;
15
+ const { sellAsset, buyAsset, sellAmount, bip44Params } = input;
16
16
  if (buyAsset.chainId !== input.chainId || sellAsset.chainId !== input.chainId) {
17
17
  throw new api_1.SwapError('[getZrxTradeQuote] - Both assets need to be on the same supported EVM chain to use Zrx', {
18
18
  code: api_1.SwapErrorTypes.UNSUPPORTED_PAIR,
@@ -72,7 +72,7 @@ async function getZrxTradeQuote(input) {
72
72
  allowanceContract: allowanceTarget,
73
73
  buyAsset,
74
74
  sellAsset,
75
- sellAssetAccountNumber,
75
+ bip44Params,
76
76
  };
77
77
  }
78
78
  catch (e) {
@@ -17,7 +17,11 @@ export declare const setupExecuteTrade: () => {
17
17
  buyAsset: Asset;
18
18
  sellAsset: Asset;
19
19
  sendMax: boolean;
20
- sellAssetAccountNumber: number;
20
+ bip44Params: {
21
+ purpose: number;
22
+ coinType: number;
23
+ accountNumber: number;
24
+ };
21
25
  txData: string;
22
26
  depositAddress: string;
23
27
  receiveAddress: string;
@@ -33,7 +33,7 @@ const setupExecuteTrade = () => {
33
33
  buyAsset,
34
34
  sellAsset,
35
35
  sendMax: false,
36
- sellAssetAccountNumber: 0,
36
+ bip44Params: { purpose: 44, coinType: 60, accountNumber: 0 },
37
37
  txData: '0x0',
38
38
  depositAddress: '0x0',
39
39
  receiveAddress: '0x0',
@@ -21,9 +21,7 @@ async function zrxApprovalNeeded({ adapter, web3 }, { quote, wallet }) {
21
21
  if (sellAsset.assetId === adapter.getFeeAssetId()) {
22
22
  return { approvalNeeded: false };
23
23
  }
24
- const accountNumber = quote.sellAssetAccountNumber;
25
- const bip44Params = adapter.buildBIP44Params({ accountNumber });
26
- const receiveAddress = await adapter.getAddress({ wallet, bip44Params });
24
+ const receiveAddress = await adapter.getAddress({ wallet, bip44Params: quote.bip44Params });
27
25
  if (!quote.allowanceContract) {
28
26
  throw new api_1.SwapError('[zrxApprovalNeeded] - allowanceTarget is required', {
29
27
  code: api_1.SwapErrorTypes.VALIDATION_FAILED,
@@ -37,7 +37,7 @@ const helpers_2 = require("../utils/helpers/helpers");
37
37
  const zrxService_1 = require("../utils/zrxService");
38
38
  async function zrxBuildTrade({ adapter, web3 }, input) {
39
39
  var _a, _b, _c;
40
- const { sellAsset, buyAsset, sellAmount, slippage, sellAssetAccountNumber, receiveAddress } = input;
40
+ const { sellAsset, buyAsset, sellAmount, slippage, bip44Params, receiveAddress } = input;
41
41
  try {
42
42
  const { assetReference: buyAssetErc20Address, assetNamespace: buyAssetNamespace } = (0, caip_1.fromAssetId)(buyAsset.assetId);
43
43
  const { assetReference: sellAssetErc20Address, assetNamespace: sellAssetNamespace } = (0, caip_1.fromAssetId)(sellAsset.assetId);
@@ -94,7 +94,7 @@ async function zrxBuildTrade({ adapter, web3 }, input) {
94
94
  const trade = {
95
95
  sellAsset,
96
96
  buyAsset,
97
- sellAssetAccountNumber,
97
+ bip44Params,
98
98
  receiveAddress,
99
99
  rate: data.price,
100
100
  depositAddress: data.to,
@@ -6,13 +6,10 @@ const api_1 = require("../../../api");
6
6
  const helpers_1 = require("../utils/helpers/helpers");
7
7
  async function zrxExecuteTrade({ adapter }, { trade, wallet }) {
8
8
  var _a, _b, _c, _d, _e, _f;
9
- const { sellAsset } = trade;
9
+ const { bip44Params, sellAsset } = trade;
10
10
  try {
11
11
  // value is 0 for erc20s
12
12
  const value = (0, helpers_1.isNativeEvmAsset)(sellAsset.assetId) ? trade.sellAmount : '0';
13
- const bip44Params = adapter.buildBIP44Params({
14
- accountNumber: trade.sellAssetAccountNumber,
15
- });
16
13
  const buildTxResponse = await adapter.buildSendTransaction({
17
14
  value,
18
15
  wallet,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/swapper",
3
- "version": "11.2.0",
3
+ "version": "11.3.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",