@shapeshiftoss/swapper 15.0.3 → 15.1.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 +4 -4
- package/dist/swappercli.js +6 -5
- package/dist/swappers/cow/cowApprovalNeeded/cowApprovalNeeded.js +2 -1
- package/dist/swappers/cow/cowBuildTrade/cowBuildTrade.js +3 -3
- package/dist/swappers/cow/getCowSwapTradeQuote/getCowSwapTradeQuote.js +2 -2
- package/dist/swappers/osmosis/OsmosisSwapper.js +8 -9
- package/dist/swappers/osmosis/utils/helpers.js +2 -2
- package/dist/swappers/thorchain/buildThorTrade/buildThorTrade.js +4 -7
- package/dist/swappers/thorchain/getThorTradeQuote/getTradeQuote.js +2 -5
- package/dist/swappers/thorchain/thorTradeApprovalNeeded/thorTradeApprovalNeeded.js +2 -2
- package/dist/swappers/thorchain/types.d.ts +4 -0
- package/dist/swappers/thorchain/utils/cosmos/getCosmosTxData.d.ts +2 -2
- package/dist/swappers/thorchain/utils/cosmos/getCosmosTxData.js +3 -3
- package/dist/swappers/thorchain/utils/evm/makeTradeTx.d.ts +2 -3
- package/dist/swappers/thorchain/utils/evm/makeTradeTx.js +2 -2
- package/dist/swappers/thorchain/utils/test-data/responses.js +24 -8
- package/dist/swappers/thorchain/utils/test-data/setupThorswapDeps.js +0 -1
- package/dist/swappers/utils/helpers/helpers.js +2 -2
- package/dist/swappers/utils/test-data/setupSwapQuote.d.ts +1 -1
- package/dist/swappers/utils/test-data/setupSwapQuote.js +3 -3
- package/dist/swappers/zrx/getZrxTradeQuote/getZrxTradeQuote.js +2 -2
- package/dist/swappers/zrx/utils/test-data/setupZrxSwapQuote.d.ts +1 -5
- package/dist/swappers/zrx/utils/test-data/setupZrxSwapQuote.js +1 -1
- package/dist/swappers/zrx/zrxApprovalNeeded/zrxApprovalNeeded.js +2 -1
- package/dist/swappers/zrx/zrxBuildTrade/zrxBuildTrade.js +2 -2
- package/dist/swappers/zrx/zrxExecuteTrade/zrxExecuteTrade.js +2 -2
- package/package.json +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Asset } from '@shapeshiftoss/asset-service';
|
|
|
2
2
|
import { AssetId, ChainId } from '@shapeshiftoss/caip';
|
|
3
3
|
import { avalanche, cosmos, ethereum, osmosis } from '@shapeshiftoss/chain-adapters';
|
|
4
4
|
import { HDWallet } from '@shapeshiftoss/hdwallet-core';
|
|
5
|
-
import {
|
|
5
|
+
import { ChainSpecific, KnownChainIds, UtxoAccountType } from '@shapeshiftoss/types';
|
|
6
6
|
export declare const SwapError: {
|
|
7
7
|
new <V extends {
|
|
8
8
|
cause?: unknown;
|
|
@@ -80,7 +80,7 @@ declare type CommonTradeInput = {
|
|
|
80
80
|
sellAmountBeforeFeesCryptoBaseUnit: string;
|
|
81
81
|
sendMax: boolean;
|
|
82
82
|
receiveAddress: string;
|
|
83
|
-
|
|
83
|
+
accountNumber: number;
|
|
84
84
|
};
|
|
85
85
|
export declare type EvmSupportedChainIds = KnownChainIds.EthereumMainnet | KnownChainIds.AvalancheMainnet;
|
|
86
86
|
export declare type CosmosSdkSupportedChainIds = KnownChainIds.CosmosMainnet | KnownChainIds.OsmosisMainnet | KnownChainIds.ThorchainMainnet;
|
|
@@ -96,7 +96,7 @@ export declare type GetCosmosSdkTradeQuoteInput = CommonTradeInput & {
|
|
|
96
96
|
export declare type GetUtxoTradeQuoteInput = CommonTradeInput & {
|
|
97
97
|
chainId: UtxoSupportedChainIds;
|
|
98
98
|
accountType: UtxoAccountType;
|
|
99
|
-
|
|
99
|
+
accountNumber: number;
|
|
100
100
|
xpub: string;
|
|
101
101
|
};
|
|
102
102
|
export declare type GetTradeQuoteInput = GetUtxoTradeQuoteInput | GetEvmTradeQuoteInput | GetCosmosSdkTradeQuoteInput;
|
|
@@ -112,7 +112,7 @@ interface TradeBase<C extends ChainId> {
|
|
|
112
112
|
sources: SwapSource[];
|
|
113
113
|
buyAsset: Asset;
|
|
114
114
|
sellAsset: Asset;
|
|
115
|
-
|
|
115
|
+
accountNumber: number;
|
|
116
116
|
}
|
|
117
117
|
export interface TradeQuote<C extends ChainId> extends TradeBase<C> {
|
|
118
118
|
allowanceContract: string;
|
package/dist/swappercli.js
CHANGED
|
@@ -107,8 +107,9 @@ const main = async () => {
|
|
|
107
107
|
if (sellAdapter.getSupportedAccountTypes) {
|
|
108
108
|
utxoAccountType = chain_adapters_1.bitcoin.ChainAdapter.defaultUtxoAccountType;
|
|
109
109
|
}
|
|
110
|
+
const accountNumber = 0;
|
|
110
111
|
const bip44Params = sellAdapter.getBIP44Params({
|
|
111
|
-
accountNumber
|
|
112
|
+
accountNumber,
|
|
112
113
|
accountType: utxoAccountType,
|
|
113
114
|
});
|
|
114
115
|
if (!bip44Params) {
|
|
@@ -125,13 +126,13 @@ const main = async () => {
|
|
|
125
126
|
if (!utxoAccountType) {
|
|
126
127
|
throw new Error('utxoAccountType must be defined');
|
|
127
128
|
}
|
|
128
|
-
publicKey = await sellAdapter.getPublicKey(wallet,
|
|
129
|
+
publicKey = await sellAdapter.getPublicKey(wallet, accountNumber, utxoAccountType);
|
|
129
130
|
}
|
|
130
131
|
const sellAmountBeforeFeesCryptoBaseUnit = toBaseUnit(sellAmountBeforeFeesCryptoPrecision, sellAsset.precision);
|
|
131
132
|
const buyAssetReceiveAddr = await buyAdapter.getAddress({
|
|
132
133
|
wallet,
|
|
133
134
|
accountType: utxoAccountType,
|
|
134
|
-
|
|
135
|
+
accountNumber,
|
|
135
136
|
});
|
|
136
137
|
console.info(`${buyAsset.name} using receive addr ${buyAssetReceiveAddr}`);
|
|
137
138
|
let quote;
|
|
@@ -143,7 +144,7 @@ const main = async () => {
|
|
|
143
144
|
sellAmountBeforeFeesCryptoBaseUnit,
|
|
144
145
|
sendMax: false,
|
|
145
146
|
accountType: utxoAccountType || chain_adapters_1.bitcoin.ChainAdapter.defaultUtxoAccountType,
|
|
146
|
-
|
|
147
|
+
accountNumber,
|
|
147
148
|
xpub: (publicKey === null || publicKey === void 0 ? void 0 : publicKey.xpub) || '',
|
|
148
149
|
receiveAddress: buyAssetReceiveAddr,
|
|
149
150
|
});
|
|
@@ -168,7 +169,7 @@ const main = async () => {
|
|
|
168
169
|
sellAsset,
|
|
169
170
|
receiveAddress: buyAssetReceiveAddr,
|
|
170
171
|
accountType: utxoAccountType || chain_adapters_1.bitcoin.ChainAdapter.defaultUtxoAccountType,
|
|
171
|
-
|
|
172
|
+
accountNumber,
|
|
172
173
|
xpub: (publicKey === null || publicKey === void 0 ? void 0 : publicKey.xpub) || '',
|
|
173
174
|
});
|
|
174
175
|
const tradeResult = await swapper.executeTrade({ trade, wallet });
|
|
@@ -17,7 +17,8 @@ async function cowApprovalNeeded({ adapter, web3 }, { quote, wallet }) {
|
|
|
17
17
|
details: { assetNamespace },
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
|
-
const
|
|
20
|
+
const { accountNumber } = quote;
|
|
21
|
+
const receiveAddress = await adapter.getAddress({ accountNumber, wallet });
|
|
21
22
|
const allowanceResult = await (0, helpers_1.getERC20Allowance)({
|
|
22
23
|
web3,
|
|
23
24
|
erc20AllowanceAbi: erc20Allowance_abi_1.erc20AllowanceAbi,
|
|
@@ -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, sellAmountBeforeFeesCryptoBaseUnit: sellAmountExcludeFeeCryptoBaseUnit,
|
|
15
|
+
const { sellAsset, buyAsset, sellAmountBeforeFeesCryptoBaseUnit: sellAmountExcludeFeeCryptoBaseUnit, accountNumber, 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);
|
|
@@ -29,7 +29,7 @@ async function cowBuildTrade(deps, input) {
|
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
const buyToken = buyAsset.assetId !== caip_1.ethAssetId ? buyAssetErc20Address : constants_1.COW_SWAP_ETH_MARKER_ADDRESS;
|
|
32
|
-
const receiveAddress = await adapter.getAddress({
|
|
32
|
+
const receiveAddress = await adapter.getAddress({ accountNumber, wallet });
|
|
33
33
|
/**
|
|
34
34
|
* /v1/quote
|
|
35
35
|
* params: {
|
|
@@ -91,7 +91,7 @@ async function cowBuildTrade(deps, input) {
|
|
|
91
91
|
sources: constants_1.DEFAULT_SOURCE,
|
|
92
92
|
buyAsset,
|
|
93
93
|
sellAsset,
|
|
94
|
-
|
|
94
|
+
accountNumber,
|
|
95
95
|
receiveAddress,
|
|
96
96
|
feeAmountInSellTokenCryptoBaseUnit,
|
|
97
97
|
sellAmountDeductFeeCryptoBaseUnit: quoteSellAmountExcludeFeeCryptoBaseUnit,
|
|
@@ -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, sellAmountBeforeFeesCryptoBaseUnit,
|
|
20
|
+
const { sellAsset, buyAsset, sellAmountBeforeFeesCryptoBaseUnit, accountNumber, 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);
|
|
@@ -115,7 +115,7 @@ async function getCowSwapTradeQuote(deps, input) {
|
|
|
115
115
|
allowanceContract: constants_1.COW_SWAP_VAULT_RELAYER_ADDRESS,
|
|
116
116
|
buyAsset,
|
|
117
117
|
sellAsset,
|
|
118
|
-
|
|
118
|
+
accountNumber,
|
|
119
119
|
};
|
|
120
120
|
}
|
|
121
121
|
catch (e) {
|
|
@@ -87,7 +87,7 @@ class OsmosisSwapper {
|
|
|
87
87
|
return this.supportedAssetIds;
|
|
88
88
|
}
|
|
89
89
|
async buildTrade(args) {
|
|
90
|
-
const { sellAsset, buyAsset, sellAmountBeforeFeesCryptoBaseUnit: sellAmountCryptoBaseUnit, receiveAddress,
|
|
90
|
+
const { sellAsset, buyAsset, sellAmountBeforeFeesCryptoBaseUnit: sellAmountCryptoBaseUnit, receiveAddress, accountNumber, } = args;
|
|
91
91
|
if (!sellAmountCryptoBaseUnit) {
|
|
92
92
|
throw new api_1.SwapError('sellAmountCryptoPrecision is required', {
|
|
93
93
|
code: api_1.SwapErrorTypes.BUILD_TRADE_FAILED,
|
|
@@ -115,12 +115,12 @@ class OsmosisSwapper {
|
|
|
115
115
|
receiveAddress,
|
|
116
116
|
sellAmountBeforeFeesCryptoBaseUnit: sellAmountCryptoBase,
|
|
117
117
|
sellAsset,
|
|
118
|
-
|
|
118
|
+
accountNumber,
|
|
119
119
|
sources: [{ name: api_1.SwapperName.Osmosis, proportion: '100' }],
|
|
120
120
|
};
|
|
121
121
|
}
|
|
122
122
|
async getTradeQuote(input) {
|
|
123
|
-
const {
|
|
123
|
+
const { accountNumber, sellAsset, buyAsset, sellAmountBeforeFeesCryptoBaseUnit: sellAmountCryptoBaseUnit, } = input;
|
|
124
124
|
if (!sellAmountCryptoBaseUnit) {
|
|
125
125
|
throw new api_1.SwapError('sellAmount is required', {
|
|
126
126
|
code: api_1.SwapErrorTypes.RESPONSE_ERROR,
|
|
@@ -144,7 +144,7 @@ class OsmosisSwapper {
|
|
|
144
144
|
},
|
|
145
145
|
maximum,
|
|
146
146
|
minimumCryptoHuman: minimum,
|
|
147
|
-
|
|
147
|
+
accountNumber,
|
|
148
148
|
rate,
|
|
149
149
|
sellAsset,
|
|
150
150
|
sellAmountBeforeFeesCryptoBaseUnit: sellAmountCryptoBaseUnit,
|
|
@@ -154,7 +154,7 @@ class OsmosisSwapper {
|
|
|
154
154
|
};
|
|
155
155
|
}
|
|
156
156
|
async executeTrade({ trade, wallet }) {
|
|
157
|
-
const { sellAsset, buyAsset, sellAmountBeforeFeesCryptoBaseUnit: sellAmountCryptoBaseUnit,
|
|
157
|
+
const { sellAsset, buyAsset, sellAmountBeforeFeesCryptoBaseUnit: sellAmountCryptoBaseUnit, accountNumber, receiveAddress, } = trade;
|
|
158
158
|
const isFromOsmo = sellAsset.assetId === caip_1.osmosisAssetId;
|
|
159
159
|
const sellAssetDenom = helpers_1.symbolDenomMapping[sellAsset.symbol];
|
|
160
160
|
const buyAssetDenom = helpers_1.symbolDenomMapping[buyAsset.symbol];
|
|
@@ -171,7 +171,7 @@ class OsmosisSwapper {
|
|
|
171
171
|
let sellAddress;
|
|
172
172
|
let cosmosIbcTradeId = '';
|
|
173
173
|
if (!isFromOsmo) {
|
|
174
|
-
sellAddress = await cosmosAdapter.getAddress({ wallet,
|
|
174
|
+
sellAddress = await cosmosAdapter.getAddress({ wallet, accountNumber });
|
|
175
175
|
if (!sellAddress)
|
|
176
176
|
throw new api_1.SwapError('Failed to get address', {
|
|
177
177
|
code: api_1.SwapErrorTypes.EXECUTE_TRADE_FAILED,
|
|
@@ -182,9 +182,8 @@ class OsmosisSwapper {
|
|
|
182
182
|
amount: sellAmountCryptoBaseUnit,
|
|
183
183
|
};
|
|
184
184
|
const responseAccount = await cosmosAdapter.getAccount(sellAddress);
|
|
185
|
-
const accountNumber = responseAccount.chainSpecific.accountNumber || '0';
|
|
186
185
|
const sequence = responseAccount.chainSpecific.sequence || '0';
|
|
187
|
-
const { tradeId } = await (0, helpers_1.performIbcTransfer)(transfer, cosmosAdapter, wallet, this.deps.osmoUrl, 'uatom', constants_1.COSMO_OSMO_CHANNEL, feeData.fast.txFee, accountNumber, sequence, gas, 'uatom');
|
|
186
|
+
const { tradeId } = await (0, helpers_1.performIbcTransfer)(transfer, cosmosAdapter, wallet, this.deps.osmoUrl, 'uatom', constants_1.COSMO_OSMO_CHANNEL, feeData.fast.txFee, accountNumber.toString(), sequence, gas, 'uatom');
|
|
188
187
|
cosmosIbcTradeId = tradeId;
|
|
189
188
|
// wait till confirmed
|
|
190
189
|
const pollResult = await (0, helpers_1.pollForComplete)(tradeId, this.deps.cosmosUrl);
|
|
@@ -198,7 +197,7 @@ class OsmosisSwapper {
|
|
|
198
197
|
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
199
198
|
}
|
|
200
199
|
else {
|
|
201
|
-
sellAddress = await osmosisAdapter.getAddress({ wallet,
|
|
200
|
+
sellAddress = await osmosisAdapter.getAddress({ wallet, accountNumber });
|
|
202
201
|
if (!sellAddress)
|
|
203
202
|
throw new api_1.SwapError('failed to get osmoAddress', {
|
|
204
203
|
code: api_1.SwapErrorTypes.EXECUTE_TRADE_FAILED,
|
|
@@ -209,7 +209,7 @@ const performIbcTransfer = async (input, adapter, wallet, blockBaseUrl, denom, s
|
|
|
209
209
|
const signed = await adapter.signTransaction({
|
|
210
210
|
txToSign: {
|
|
211
211
|
tx,
|
|
212
|
-
addressNList: (0, chain_adapters_1.toAddressNList)(adapter.
|
|
212
|
+
addressNList: (0, chain_adapters_1.toAddressNList)(adapter.getBIP44Params({ accountNumber: 0 })),
|
|
213
213
|
chain_id: (0, caip_1.fromChainId)(adapter.getChainId()).chainReference,
|
|
214
214
|
account_number: accountNumber,
|
|
215
215
|
sequence,
|
|
@@ -262,7 +262,7 @@ const buildTradeTx = async ({ osmoAddress, adapter, buyAssetDenom, sellAssetDeno
|
|
|
262
262
|
return {
|
|
263
263
|
txToSign: {
|
|
264
264
|
tx,
|
|
265
|
-
addressNList: (0, chain_adapters_1.toAddressNList)(adapter.
|
|
265
|
+
addressNList: (0, chain_adapters_1.toAddressNList)(adapter.getBIP44Params({ accountNumber: 0 })),
|
|
266
266
|
chain_id: caip_1.CHAIN_REFERENCE.OsmosisMainnet,
|
|
267
267
|
account_number: accountNumber,
|
|
268
268
|
sequence,
|
|
@@ -12,7 +12,7 @@ const makeTradeTx_1 = require("../utils/evm/makeTradeTx");
|
|
|
12
12
|
const buildTrade = async ({ deps, input }) => {
|
|
13
13
|
var _a, _b, _c, _d;
|
|
14
14
|
try {
|
|
15
|
-
const { buyAsset, receiveAddress: destinationAddress, sellAmountBeforeFeesCryptoBaseUnit: sellAmountCryptoBaseUnit, sellAsset,
|
|
15
|
+
const { buyAsset, receiveAddress: destinationAddress, sellAmountBeforeFeesCryptoBaseUnit: sellAmountCryptoBaseUnit, sellAsset, accountNumber, slippage: slippageTolerance = constants_1.DEFAULT_SLIPPAGE, wallet, sendMax, } = 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)
|
|
@@ -26,7 +26,7 @@ const buildTrade = async ({ deps, input }) => {
|
|
|
26
26
|
const ethTradeTx = await (0, makeTradeTx_1.makeTradeTx)({
|
|
27
27
|
wallet,
|
|
28
28
|
slippageTolerance,
|
|
29
|
-
|
|
29
|
+
accountNumber,
|
|
30
30
|
sellAsset,
|
|
31
31
|
buyAsset,
|
|
32
32
|
adapter: sellAdapter,
|
|
@@ -59,7 +59,7 @@ const buildTrade = async ({ deps, input }) => {
|
|
|
59
59
|
value: sellAmountCryptoBaseUnit,
|
|
60
60
|
wallet,
|
|
61
61
|
to: vault,
|
|
62
|
-
|
|
62
|
+
accountNumber,
|
|
63
63
|
chainSpecific: {
|
|
64
64
|
accountType: input.accountType,
|
|
65
65
|
satoshiPerByte: quote.feeData.chainSpecific
|
|
@@ -76,11 +76,8 @@ const buildTrade = async ({ deps, input }) => {
|
|
|
76
76
|
};
|
|
77
77
|
}
|
|
78
78
|
else if (chainNamespace === caip_1.CHAIN_NAMESPACE.CosmosSdk) {
|
|
79
|
-
if (!bip44Params) {
|
|
80
|
-
throw new Error('bip44Params required as input');
|
|
81
|
-
}
|
|
82
79
|
const txData = await (0, getCosmosTxData_1.getCosmosTxData)({
|
|
83
|
-
|
|
80
|
+
accountNumber,
|
|
84
81
|
deps,
|
|
85
82
|
sellAdapter: sellAdapter,
|
|
86
83
|
sellAmountCryptoBaseUnit,
|
|
@@ -16,10 +16,7 @@ const getEvmTxFees_1 = require("../utils/txFeeHelpers/evmTxFees/getEvmTxFees");
|
|
|
16
16
|
const getUtxoTxFees_1 = require("../utils/txFeeHelpers/utxoTxFees/getUtxoTxFees");
|
|
17
17
|
const getSlippage_1 = require("./getSlippage");
|
|
18
18
|
const getThorTradeQuote = async ({ deps, input }) => {
|
|
19
|
-
const { sellAsset, buyAsset, sellAmountBeforeFeesCryptoBaseUnit: sellAmountCryptoBaseUnit,
|
|
20
|
-
if (!bip44Params) {
|
|
21
|
-
throw new Error('bip44Params required in getThorTradeQuote');
|
|
22
|
-
}
|
|
19
|
+
const { sellAsset, buyAsset, sellAmountBeforeFeesCryptoBaseUnit: sellAmountCryptoBaseUnit, accountNumber, chainId, receiveAddress, sendMax, } = input;
|
|
23
20
|
try {
|
|
24
21
|
const { assetReference: sellAssetReference } = (0, caip_1.fromAssetId)(sellAsset.assetId);
|
|
25
22
|
const { chainId: buyAssetChainId } = (0, caip_1.fromAssetId)(buyAsset.assetId);
|
|
@@ -65,7 +62,7 @@ const getThorTradeQuote = async ({ deps, input }) => {
|
|
|
65
62
|
sources: [{ name: api_1.SwapperName.Thorchain, proportion: '1' }],
|
|
66
63
|
buyAsset,
|
|
67
64
|
sellAsset,
|
|
68
|
-
|
|
65
|
+
accountNumber,
|
|
69
66
|
minimumCryptoHuman: minimumSellAssetAmountPaddedCryptoHuman,
|
|
70
67
|
recommendedSlippage: recommendedSlippage.toPrecision(),
|
|
71
68
|
};
|
|
@@ -10,7 +10,7 @@ const thorTradeApprovalNeeded = async ({ deps, input, }) => {
|
|
|
10
10
|
var _a;
|
|
11
11
|
try {
|
|
12
12
|
const { quote, wallet } = input;
|
|
13
|
-
const { sellAsset,
|
|
13
|
+
const { sellAsset, accountNumber } = 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);
|
|
@@ -26,7 +26,7 @@ const thorTradeApprovalNeeded = async ({ deps, input, }) => {
|
|
|
26
26
|
if (sellAsset.assetId === adapter.getFeeAssetId()) {
|
|
27
27
|
return { approvalNeeded: false };
|
|
28
28
|
}
|
|
29
|
-
const receiveAddress = await adapter.getAddress({ wallet,
|
|
29
|
+
const receiveAddress = await adapter.getAddress({ wallet, accountNumber });
|
|
30
30
|
if (!quote.allowanceContract) {
|
|
31
31
|
throw new api_1.SwapError('[thorTradeApprovalNeeded] - allowanceTarget is required', {
|
|
32
32
|
code: api_1.SwapErrorTypes.VALIDATION_FAILED,
|
|
@@ -12,8 +12,12 @@ export declare type ThornodePoolResponse = {
|
|
|
12
12
|
pending_inbound_asset: string;
|
|
13
13
|
pending_inbound_rune: string;
|
|
14
14
|
pool_units: string;
|
|
15
|
+
savers_depth: string;
|
|
16
|
+
savers_units: string;
|
|
15
17
|
status: string;
|
|
18
|
+
synth_mint_paused: boolean;
|
|
16
19
|
synth_supply: string;
|
|
20
|
+
synth_supply_remaining: string;
|
|
17
21
|
synth_units: string;
|
|
18
22
|
};
|
|
19
23
|
declare type MidgardCoins = {
|
|
@@ -2,11 +2,11 @@ import { Asset } from '@shapeshiftoss/asset-service';
|
|
|
2
2
|
import { ChainId } from '@shapeshiftoss/caip';
|
|
3
3
|
import { ChainAdapter } from '@shapeshiftoss/chain-adapters';
|
|
4
4
|
import { HDWallet } from '@shapeshiftoss/hdwallet-core';
|
|
5
|
-
import {
|
|
5
|
+
import { KnownChainIds } from '@shapeshiftoss/types';
|
|
6
6
|
import { TradeQuote } from '../../../../api';
|
|
7
7
|
import type { ThorchainSwapperDeps } from '../../types';
|
|
8
8
|
declare type GetCosmosTxDataInput = {
|
|
9
|
-
|
|
9
|
+
accountNumber: number;
|
|
10
10
|
destinationAddress: string;
|
|
11
11
|
deps: ThorchainSwapperDeps;
|
|
12
12
|
sellAmountCryptoBaseUnit: string;
|
|
@@ -8,7 +8,7 @@ const getInboundAddressDataForChain_1 = require("../getInboundAddressDataForChai
|
|
|
8
8
|
const getLimit_1 = require("../getLimit/getLimit");
|
|
9
9
|
const makeSwapMemo_1 = require("../makeSwapMemo/makeSwapMemo");
|
|
10
10
|
const getCosmosTxData = async (input) => {
|
|
11
|
-
const {
|
|
11
|
+
const { accountNumber, deps, destinationAddress, sellAmountCryptoBaseUnit, sellAsset, buyAsset, slippageTolerance, quote, wallet, sellAdapter, } = input;
|
|
12
12
|
const fromThorAsset = sellAsset.chainId == types_1.KnownChainIds.ThorchainMainnet;
|
|
13
13
|
const gaiaAddressData = await (0, getInboundAddressDataForChain_1.getInboundAddressDataForChain)(deps.daemonUrl, caip_1.cosmosAssetId);
|
|
14
14
|
const vault = gaiaAddressData === null || gaiaAddressData === void 0 ? void 0 : gaiaAddressData.address;
|
|
@@ -35,7 +35,7 @@ const getCosmosTxData = async (input) => {
|
|
|
35
35
|
switch (true) {
|
|
36
36
|
case fromThorAsset:
|
|
37
37
|
return await sellAdapter.buildDepositTransaction({
|
|
38
|
-
|
|
38
|
+
accountNumber,
|
|
39
39
|
value: sellAmountCryptoBaseUnit,
|
|
40
40
|
wallet,
|
|
41
41
|
memo,
|
|
@@ -52,7 +52,7 @@ const getCosmosTxData = async (input) => {
|
|
|
52
52
|
details: { chainId: input.chainId },
|
|
53
53
|
});
|
|
54
54
|
return await sellAdapter.buildSendTransaction({
|
|
55
|
-
|
|
55
|
+
accountNumber,
|
|
56
56
|
value: sellAmountCryptoBaseUnit,
|
|
57
57
|
wallet,
|
|
58
58
|
to: vault,
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { Asset } from '@shapeshiftoss/asset-service';
|
|
2
2
|
import { ETHSignTx, HDWallet } from '@shapeshiftoss/hdwallet-core';
|
|
3
|
-
import { BIP44Params } from '@shapeshiftoss/types';
|
|
4
3
|
import { EvmSupportedChainAdapter } from '../../../../api';
|
|
5
4
|
import type { ThorchainSwapperDeps } from '../../types';
|
|
6
5
|
declare type MakeTradeTxArgs = {
|
|
7
6
|
wallet: HDWallet;
|
|
8
|
-
|
|
7
|
+
accountNumber: number;
|
|
9
8
|
sellAmountCryptoBaseUnit: string;
|
|
10
9
|
buyAsset: Asset;
|
|
11
10
|
sellAsset: Asset;
|
|
@@ -24,7 +23,7 @@ declare type MakeTradeTxArgs = {
|
|
|
24
23
|
maxFeePerGas: string;
|
|
25
24
|
maxPriorityFeePerGas: string;
|
|
26
25
|
});
|
|
27
|
-
export declare const makeTradeTx: ({ wallet,
|
|
26
|
+
export declare const makeTradeTx: ({ wallet, accountNumber, sellAmountCryptoBaseUnit, buyAsset, sellAsset, destinationAddress, adapter, maxFeePerGas, maxPriorityFeePerGas, gasPriceCryptoBaseUnit, slippageTolerance, deps, gasLimit, buyAssetTradeFeeUsd, }: MakeTradeTxArgs) => Promise<{
|
|
28
27
|
txToSign: ETHSignTx;
|
|
29
28
|
}>;
|
|
30
29
|
export {};
|
|
@@ -5,7 +5,7 @@ const caip_1 = require("@shapeshiftoss/caip");
|
|
|
5
5
|
const web3_utils_1 = require("web3-utils");
|
|
6
6
|
const api_1 = require("../../../../api");
|
|
7
7
|
const getThorTxData_1 = require("./utils/getThorTxData");
|
|
8
|
-
const makeTradeTx = async ({ wallet,
|
|
8
|
+
const makeTradeTx = async ({ wallet, accountNumber, sellAmountCryptoBaseUnit, buyAsset, sellAsset, destinationAddress, adapter, maxFeePerGas, maxPriorityFeePerGas, gasPriceCryptoBaseUnit, slippageTolerance, deps, gasLimit, buyAssetTradeFeeUsd, }) => {
|
|
9
9
|
try {
|
|
10
10
|
const { assetNamespace } = (0, caip_1.fromAssetId)(sellAsset.assetId);
|
|
11
11
|
const isErc20Trade = assetNamespace === 'erc20';
|
|
@@ -20,7 +20,7 @@ const makeTradeTx = async ({ wallet, bip44Params, sellAmountCryptoBaseUnit, buyA
|
|
|
20
20
|
});
|
|
21
21
|
return adapter.buildCustomTx({
|
|
22
22
|
wallet,
|
|
23
|
-
|
|
23
|
+
accountNumber,
|
|
24
24
|
to: router,
|
|
25
25
|
gasLimit,
|
|
26
26
|
...(gasPriceCryptoBaseUnit !== undefined
|
|
@@ -9,9 +9,13 @@ exports.btcThornodePool = {
|
|
|
9
9
|
pending_inbound_asset: '0',
|
|
10
10
|
pending_inbound_rune: '0',
|
|
11
11
|
pool_units: '545894929144923',
|
|
12
|
+
savers_depth: '41416604834',
|
|
13
|
+
savers_units: '41128793233',
|
|
14
|
+
synth_mint_paused: false,
|
|
12
15
|
status: 'Available',
|
|
13
|
-
synth_supply: '
|
|
14
|
-
|
|
16
|
+
synth_supply: '44718623180',
|
|
17
|
+
synth_supply_remaining: '8963246519',
|
|
18
|
+
synth_units: '142965023220851',
|
|
15
19
|
};
|
|
16
20
|
exports.ethThornodePool = {
|
|
17
21
|
LP_units: '273709963437801',
|
|
@@ -21,9 +25,13 @@ exports.ethThornodePool = {
|
|
|
21
25
|
pending_inbound_asset: '0',
|
|
22
26
|
pending_inbound_rune: '0',
|
|
23
27
|
pool_units: '274245264962453',
|
|
28
|
+
savers_depth: '167028916827',
|
|
29
|
+
savers_units: '165530383978',
|
|
24
30
|
status: 'Available',
|
|
25
|
-
|
|
26
|
-
|
|
31
|
+
synth_mint_paused: false,
|
|
32
|
+
synth_supply: '218601192670',
|
|
33
|
+
synth_supply_remaining: '183106737474',
|
|
34
|
+
synth_units: '36567637964216',
|
|
27
35
|
};
|
|
28
36
|
exports.foxThornodePool = {
|
|
29
37
|
LP_units: '10015457121887',
|
|
@@ -33,9 +41,13 @@ exports.foxThornodePool = {
|
|
|
33
41
|
pending_inbound_asset: '0',
|
|
34
42
|
pending_inbound_rune: '0',
|
|
35
43
|
pool_units: '10568061707512',
|
|
44
|
+
savers_depth: '0',
|
|
45
|
+
savers_units: '0',
|
|
36
46
|
status: 'Available',
|
|
37
|
-
|
|
38
|
-
|
|
47
|
+
synth_mint_paused: false,
|
|
48
|
+
synth_supply: '3126453386967',
|
|
49
|
+
synth_supply_remaining: '161390775916374',
|
|
50
|
+
synth_units: '50300400994',
|
|
39
51
|
};
|
|
40
52
|
exports.usdcThornodePool = {
|
|
41
53
|
LP_units: '30018075345020',
|
|
@@ -45,9 +57,13 @@ exports.usdcThornodePool = {
|
|
|
45
57
|
pending_inbound_asset: '22020062300',
|
|
46
58
|
pending_inbound_rune: '0',
|
|
47
59
|
pool_units: '31954495292990',
|
|
60
|
+
savers_depth: '0',
|
|
61
|
+
savers_units: '0',
|
|
48
62
|
status: 'Available',
|
|
49
|
-
|
|
50
|
-
|
|
63
|
+
synth_mint_paused: false,
|
|
64
|
+
synth_supply: '20420358430864',
|
|
65
|
+
synth_supply_remaining: '102379864074658',
|
|
66
|
+
synth_units: '1423205664974',
|
|
51
67
|
};
|
|
52
68
|
exports.thornodePools = [
|
|
53
69
|
exports.btcThornodePool,
|
|
@@ -21,7 +21,6 @@ const setupThorswapDeps = () => {
|
|
|
21
21
|
[
|
|
22
22
|
types_1.KnownChainIds.EthereumMainnet,
|
|
23
23
|
{
|
|
24
|
-
buildBIP44Params: jest.fn(() => ({ purpose: 44, coinType: 60, accountNumber: 0 })),
|
|
25
24
|
getAddress: jest.fn(() => Promise.resolve('0xthisIsMyAddress')),
|
|
26
25
|
getFeeData: jest.fn(() => feeData),
|
|
27
26
|
getFeeAssetId: jest.fn(() => caip_1.ethAssetId),
|
|
@@ -56,11 +56,11 @@ const grantAllowance = async ({ quote, wallet, adapter, erc20Abi, web3, }) => {
|
|
|
56
56
|
const approveTx = erc20Contract.methods
|
|
57
57
|
.approve(quote.allowanceContract, quote.sellAmountBeforeFeesCryptoBaseUnit)
|
|
58
58
|
.encodeABI();
|
|
59
|
-
const {
|
|
59
|
+
const { accountNumber } = quote;
|
|
60
60
|
const { txToSign } = await adapter.buildSendTransaction({
|
|
61
61
|
wallet,
|
|
62
62
|
to: sellAssetErc20Address,
|
|
63
|
-
|
|
63
|
+
accountNumber,
|
|
64
64
|
value: '0',
|
|
65
65
|
chainSpecific: {
|
|
66
66
|
erc20ContractAddress: sellAssetErc20Address,
|
|
@@ -15,7 +15,7 @@ export declare const setupBuildTrade: () => {
|
|
|
15
15
|
sellAmountBeforeFeesCryptoBaseUnit: string;
|
|
16
16
|
sendMax: boolean;
|
|
17
17
|
receiveAddress: string;
|
|
18
|
-
|
|
18
|
+
accountNumber: number;
|
|
19
19
|
} & {
|
|
20
20
|
chainId: import("../../../api").EvmSupportedChainIds;
|
|
21
21
|
} & {
|
|
@@ -12,7 +12,7 @@ const setupQuote = () => {
|
|
|
12
12
|
sellAsset,
|
|
13
13
|
buyAsset,
|
|
14
14
|
allowanceContract: 'allowanceContractAddress',
|
|
15
|
-
|
|
15
|
+
accountNumber: 0,
|
|
16
16
|
minimumCryptoHuman: '0',
|
|
17
17
|
maximum: '999999999999',
|
|
18
18
|
feeData: {
|
|
@@ -29,7 +29,7 @@ const setupQuote = () => {
|
|
|
29
29
|
sellAmountBeforeFeesCryptoBaseUnit: '1000000000000000000',
|
|
30
30
|
sellAsset,
|
|
31
31
|
buyAsset,
|
|
32
|
-
|
|
32
|
+
accountNumber: 0,
|
|
33
33
|
sendMax: false,
|
|
34
34
|
receiveAddress: '0xc770eefad204b5180df6a14ee197d99d808ee52d',
|
|
35
35
|
};
|
|
@@ -44,7 +44,7 @@ const setupBuildTrade = () => {
|
|
|
44
44
|
sellAmountBeforeFeesCryptoBaseUnit: '1000000000000000000',
|
|
45
45
|
buyAsset,
|
|
46
46
|
sendMax: false,
|
|
47
|
-
|
|
47
|
+
accountNumber: 0,
|
|
48
48
|
sellAsset,
|
|
49
49
|
wallet: {},
|
|
50
50
|
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, sellAmountBeforeFeesCryptoBaseUnit: sellAmountCryptoBaseUnit,
|
|
15
|
+
const { sellAsset, buyAsset, sellAmountBeforeFeesCryptoBaseUnit: sellAmountCryptoBaseUnit, accountNumber, } = 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,
|
|
@@ -75,7 +75,7 @@ async function getZrxTradeQuote(input) {
|
|
|
75
75
|
allowanceContract: allowanceTarget,
|
|
76
76
|
buyAsset,
|
|
77
77
|
sellAsset,
|
|
78
|
-
|
|
78
|
+
accountNumber,
|
|
79
79
|
};
|
|
80
80
|
return tradeQuote;
|
|
81
81
|
}
|
|
@@ -17,11 +17,7 @@ export declare const setupExecuteTrade: () => {
|
|
|
17
17
|
buyAsset: Asset;
|
|
18
18
|
sellAsset: Asset;
|
|
19
19
|
sendMax: boolean;
|
|
20
|
-
|
|
21
|
-
purpose: number;
|
|
22
|
-
coinType: number;
|
|
23
|
-
accountNumber: number;
|
|
24
|
-
};
|
|
20
|
+
accountNumber: number;
|
|
25
21
|
txData: string;
|
|
26
22
|
depositAddress: string;
|
|
27
23
|
receiveAddress: string;
|
|
@@ -21,7 +21,8 @@ async function zrxApprovalNeeded({ adapter, web3 }, { quote, wallet }) {
|
|
|
21
21
|
if (sellAsset.assetId === adapter.getFeeAssetId()) {
|
|
22
22
|
return { approvalNeeded: false };
|
|
23
23
|
}
|
|
24
|
-
const
|
|
24
|
+
const { accountNumber } = quote;
|
|
25
|
+
const receiveAddress = await adapter.getAddress({ accountNumber, wallet });
|
|
25
26
|
if (!quote.allowanceContract) {
|
|
26
27
|
throw new api_1.SwapError('[zrxApprovalNeeded] - allowanceTarget is required', {
|
|
27
28
|
code: api_1.SwapErrorTypes.VALIDATION_FAILED,
|
|
@@ -36,7 +36,7 @@ const constants_2 = require("../utils/constants");
|
|
|
36
36
|
const helpers_2 = require("../utils/helpers/helpers");
|
|
37
37
|
const zrxService_1 = require("../utils/zrxService");
|
|
38
38
|
async function zrxBuildTrade({ adapter, web3 }, input) {
|
|
39
|
-
const { sellAsset, buyAsset, sellAmountBeforeFeesCryptoBaseUnit: sellAmountExcludeFeeCryptoBaseUnit, slippage,
|
|
39
|
+
const { sellAsset, buyAsset, sellAmountBeforeFeesCryptoBaseUnit: sellAmountExcludeFeeCryptoBaseUnit, slippage, accountNumber, receiveAddress, } = input;
|
|
40
40
|
try {
|
|
41
41
|
const { assetReference: buyAssetErc20Address, assetNamespace: buyAssetNamespace } = (0, caip_1.fromAssetId)(buyAsset.assetId);
|
|
42
42
|
const { assetReference: sellAssetErc20Address, assetNamespace: sellAssetNamespace } = (0, caip_1.fromAssetId)(sellAsset.assetId);
|
|
@@ -108,7 +108,7 @@ async function zrxBuildTrade({ adapter, web3 }, input) {
|
|
|
108
108
|
const trade = {
|
|
109
109
|
sellAsset,
|
|
110
110
|
buyAsset,
|
|
111
|
-
|
|
111
|
+
accountNumber,
|
|
112
112
|
receiveAddress,
|
|
113
113
|
rate: price,
|
|
114
114
|
depositAddress: to,
|
|
@@ -6,7 +6,7 @@ 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 {
|
|
9
|
+
const { accountNumber, sellAsset } = trade;
|
|
10
10
|
try {
|
|
11
11
|
// value is 0 for erc20s
|
|
12
12
|
const value = (0, helpers_1.isNativeEvmAsset)(sellAsset.assetId)
|
|
@@ -20,7 +20,7 @@ async function zrxExecuteTrade({ adapter }, { trade, wallet }) {
|
|
|
20
20
|
gasPrice: (0, web3_utils_1.numberToHex)(((_b = (_a = trade.feeData) === null || _a === void 0 ? void 0 : _a.chainSpecific) === null || _b === void 0 ? void 0 : _b.gasPriceCryptoBaseUnit) || 0),
|
|
21
21
|
gasLimit: (0, web3_utils_1.numberToHex)(((_d = (_c = trade.feeData) === null || _c === void 0 ? void 0 : _c.chainSpecific) === null || _d === void 0 ? void 0 : _d.estimatedGas) || 0),
|
|
22
22
|
},
|
|
23
|
-
|
|
23
|
+
accountNumber,
|
|
24
24
|
});
|
|
25
25
|
const { txToSign } = buildTxResponse;
|
|
26
26
|
const txWithQuoteData = { ...txToSign, data: (_e = trade.txData) !== null && _e !== void 0 ? _e : '' };
|
package/package.json
CHANGED