@shapeshiftoss/swapper 9.16.1 → 9.17.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 +1 -2
- package/dist/swappercli.js +0 -1
- package/dist/swappers/cow/cowApprovalNeeded/cowApprovalNeeded.js +1 -1
- package/dist/swappers/cow/getCowSwapTradeQuote/getCowSwapTradeQuote.js +1 -2
- package/dist/swappers/osmosis/OsmosisSwapper.d.ts +4 -4
- package/dist/swappers/osmosis/OsmosisSwapper.js +39 -10
- package/dist/swappers/osmosis/utils/helpers.d.ts +1 -1
- package/dist/swappers/osmosis/utils/helpers.js +2 -2
- package/dist/swappers/osmosis/utils/types.d.ts +5 -0
- package/dist/swappers/thorchain/buildThorTrade/buildThorTrade.js +1 -3
- package/dist/swappers/thorchain/getThorTradeQuote/getTradeQuote.js +2 -8
- package/dist/swappers/thorchain/thorTradeApprovalNeeded/thorTradeApprovalNeeded.js +1 -1
- package/dist/swappers/thorchain/utils/bitcoin/utils/getThorTxData.d.ts +1 -5
- package/dist/swappers/thorchain/utils/bitcoin/utils/getThorTxData.js +2 -4
- package/dist/swappers/utils/test-data/setupSwapQuote.d.ts +0 -1
- package/dist/swappers/utils/test-data/setupSwapQuote.js +0 -1
- package/dist/swappers/zrx/zrxApprovalNeeded/zrxApprovalNeeded.js +1 -1
- package/package.json +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -79,7 +79,6 @@ declare type CommonTradeInput = {
|
|
|
79
79
|
sellAmount: string;
|
|
80
80
|
sendMax: boolean;
|
|
81
81
|
sellAssetAccountNumber: number;
|
|
82
|
-
wallet: HDWallet;
|
|
83
82
|
receiveAddress: string;
|
|
84
83
|
};
|
|
85
84
|
export declare type EvmSupportedChainIds = KnownChainIds.EthereumMainnet | KnownChainIds.AvalancheMainnet;
|
|
@@ -97,7 +96,7 @@ export declare type GetUtxoTradeQuoteInput = CommonTradeInput & {
|
|
|
97
96
|
chainId: UtxoSupportedChainIds;
|
|
98
97
|
accountType: UtxoAccountType;
|
|
99
98
|
bip44Params: BIP44Params;
|
|
100
|
-
|
|
99
|
+
xpub: string;
|
|
101
100
|
};
|
|
102
101
|
export declare type GetTradeQuoteInput = GetUtxoTradeQuoteInput | GetEvmTradeQuoteInput | GetCosmosSdkTradeQuoteInput;
|
|
103
102
|
export declare type BuildTradeInput = GetTradeQuoteInput & {
|
package/dist/swappercli.js
CHANGED
|
@@ -27,7 +27,7 @@ async function cowApprovalNeeded({ adapter, web3 }, { quote, wallet }) {
|
|
|
27
27
|
});
|
|
28
28
|
const allowanceOnChain = (0, bignumber_1.bnOrZero)(allowanceResult);
|
|
29
29
|
return {
|
|
30
|
-
approvalNeeded: allowanceOnChain.
|
|
30
|
+
approvalNeeded: allowanceOnChain.lt((0, bignumber_1.bnOrZero)(quote.sellAmount)),
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
catch (e) {
|
|
@@ -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,
|
|
20
|
+
const { sellAsset, buyAsset, sellAmount, sellAssetAccountNumber, 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);
|
|
@@ -68,7 +68,6 @@ async function getCowSwapTradeQuote(deps, input) {
|
|
|
68
68
|
const buyCryptoAmount = (0, bignumber_1.bn)(quote.buyAmount).div((0, bignumber_1.bn)(10).exponentiatedBy(buyAsset.precision));
|
|
69
69
|
const sellCryptoAmount = (0, bignumber_1.bn)(quote.sellAmount).div((0, bignumber_1.bn)(10).exponentiatedBy(sellAsset.precision));
|
|
70
70
|
const rate = buyCryptoAmount.div(sellCryptoAmount).toString();
|
|
71
|
-
const receiveAddress = wallet ? await adapter.getAddress({ wallet }) : constants_1.DEFAULT_ADDRESS;
|
|
72
71
|
const data = (0, helpers_1.getApproveContractData)({
|
|
73
72
|
web3,
|
|
74
73
|
spenderAddress: constants_1.COW_SWAP_VAULT_RELAYER_ADDRESS,
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Asset } from '@shapeshiftoss/asset-service';
|
|
2
2
|
import { AssetId, ChainId } from '@shapeshiftoss/caip';
|
|
3
|
-
import { ApprovalNeededOutput, BuildTradeInput, BuyAssetBySellIdInput, ExecuteTradeInput, GetTradeQuoteInput, MinMaxOutput, Swapper, SwapperType, Trade, TradeQuote,
|
|
4
|
-
import { OsmoSwapperDeps } from './utils/types';
|
|
3
|
+
import { ApprovalNeededOutput, BuildTradeInput, BuyAssetBySellIdInput, ExecuteTradeInput, GetTradeQuoteInput, MinMaxOutput, Swapper, SwapperType, Trade, TradeQuote, TradeTxs } from '../../api';
|
|
4
|
+
import { OsmosisTradeResult, OsmoSwapperDeps } from './utils/types';
|
|
5
5
|
export declare class OsmosisSwapper implements Swapper<ChainId> {
|
|
6
6
|
readonly name = "Osmosis";
|
|
7
7
|
supportedAssetIds: string[];
|
|
8
8
|
deps: OsmoSwapperDeps;
|
|
9
9
|
getType(): SwapperType;
|
|
10
10
|
constructor(deps: OsmoSwapperDeps);
|
|
11
|
-
getTradeTxs(tradeResult:
|
|
11
|
+
getTradeTxs(tradeResult: OsmosisTradeResult): Promise<TradeTxs>;
|
|
12
12
|
getUsdRate(input: Pick<Asset, 'symbol' | 'assetId'>): Promise<string>;
|
|
13
13
|
getMinMax(input: {
|
|
14
14
|
sellAsset: Asset;
|
|
@@ -20,5 +20,5 @@ export declare class OsmosisSwapper implements Swapper<ChainId> {
|
|
|
20
20
|
filterAssetIdsBySellable(): AssetId[];
|
|
21
21
|
buildTrade(args: BuildTradeInput): Promise<Trade<ChainId>>;
|
|
22
22
|
getTradeQuote(input: GetTradeQuoteInput): Promise<TradeQuote<ChainId>>;
|
|
23
|
-
executeTrade({ trade, wallet }: ExecuteTradeInput<ChainId>): Promise<
|
|
23
|
+
executeTrade({ trade, wallet }: ExecuteTradeInput<ChainId>): Promise<OsmosisTradeResult>;
|
|
24
24
|
}
|
|
@@ -16,10 +16,31 @@ class OsmosisSwapper {
|
|
|
16
16
|
return api_1.SwapperType.Osmosis;
|
|
17
17
|
}
|
|
18
18
|
async getTradeTxs(tradeResult) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
if (tradeResult.cosmosAddress) {
|
|
20
|
+
const cosmosAdapter = this.deps.adapterManager.get(caip_1.cosmosChainId);
|
|
21
|
+
if (!cosmosAdapter)
|
|
22
|
+
throw new api_1.SwapError('OsmosisSwapper: couldnt get cosmos adapter', {
|
|
23
|
+
code: api_1.SwapErrorTypes.GET_TRADE_TXS_FAILED,
|
|
24
|
+
});
|
|
25
|
+
const cosmosTxHistory = await cosmosAdapter.getTxHistory({
|
|
26
|
+
pubkey: tradeResult.cosmosAddress,
|
|
27
|
+
pageSize: 1,
|
|
28
|
+
});
|
|
29
|
+
const currentCosmosTxid = cosmosTxHistory === null || cosmosTxHistory === void 0 ? void 0 : cosmosTxHistory.transactions[0].txid;
|
|
30
|
+
return {
|
|
31
|
+
sellTxid: tradeResult.tradeId,
|
|
32
|
+
// This logic assumes there are the next cosmos tx will be the correct ibc transfer
|
|
33
|
+
// a random incoming tx COULD cause this logic to fail but its unlikely
|
|
34
|
+
// TODO find a better solution (may require unchained and parser additions)
|
|
35
|
+
buyTxid: currentCosmosTxid !== tradeResult.previousCosmosTxid ? currentCosmosTxid : '',
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
return {
|
|
40
|
+
sellTxid: tradeResult.previousCosmosTxid,
|
|
41
|
+
buyTxid: tradeResult.tradeId,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
23
44
|
}
|
|
24
45
|
async getUsdRate(input) {
|
|
25
46
|
const { symbol } = input;
|
|
@@ -137,9 +158,10 @@ class OsmosisSwapper {
|
|
|
137
158
|
code: api_1.SwapErrorTypes.EXECUTE_TRADE_FAILED,
|
|
138
159
|
});
|
|
139
160
|
}
|
|
140
|
-
let sellAddress;
|
|
141
161
|
const feeData = await osmosisAdapter.getFeeData({});
|
|
142
162
|
const gas = feeData.fast.chainSpecific.gasLimit;
|
|
163
|
+
let sellAddress;
|
|
164
|
+
let cosmosIbcTradeId = '';
|
|
143
165
|
if (!isFromOsmo) {
|
|
144
166
|
const sellBip44Params = cosmosAdapter.buildBIP44Params({
|
|
145
167
|
accountNumber: Number(sellAssetAccountNumber),
|
|
@@ -157,7 +179,8 @@ class OsmosisSwapper {
|
|
|
157
179
|
const responseAccount = await cosmosAdapter.getAccount(sellAddress);
|
|
158
180
|
const accountNumber = responseAccount.chainSpecific.accountNumber || '0';
|
|
159
181
|
const sequence = responseAccount.chainSpecific.sequence || '0';
|
|
160
|
-
const { tradeId } = await (0, helpers_1.performIbcTransfer)(transfer, cosmosAdapter, wallet, this.deps.osmoUrl, 'uatom', constants_1.COSMO_OSMO_CHANNEL,
|
|
182
|
+
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');
|
|
183
|
+
cosmosIbcTradeId = tradeId;
|
|
161
184
|
// wait till confirmed
|
|
162
185
|
const pollResult = await (0, helpers_1.pollForComplete)(tradeId, this.deps.cosmosUrl);
|
|
163
186
|
if (pollResult !== 'success')
|
|
@@ -167,7 +190,7 @@ class OsmosisSwapper {
|
|
|
167
190
|
ibcSellAmount = await (0, helpers_1.pollForAtomChannelBalance)(receiveAddress, this.deps.osmoUrl);
|
|
168
191
|
// delay to ensure all nodes we interact with are up to date at this point
|
|
169
192
|
// seeing intermittent bugs that suggest the balances and sequence numbers were sometimes off
|
|
170
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
193
|
+
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
171
194
|
}
|
|
172
195
|
else {
|
|
173
196
|
const sellBip44Params = osmosisAdapter.buildBIP44Params({
|
|
@@ -180,6 +203,7 @@ class OsmosisSwapper {
|
|
|
180
203
|
});
|
|
181
204
|
}
|
|
182
205
|
const osmoAddress = isFromOsmo ? sellAddress : receiveAddress;
|
|
206
|
+
const cosmosAddress = isFromOsmo ? receiveAddress : sellAddress;
|
|
183
207
|
const signTxInput = await (0, helpers_1.buildTradeTx)({
|
|
184
208
|
osmoAddress,
|
|
185
209
|
adapter: osmosisAdapter,
|
|
@@ -208,10 +232,15 @@ class OsmosisSwapper {
|
|
|
208
232
|
const ibcSequence = ibcResponseAccount.chainSpecific.sequence || '0';
|
|
209
233
|
// delay to ensure all nodes we interact with are up to date at this point
|
|
210
234
|
// seeing intermittent bugs that suggest the balances and sequence numbers were sometimes off
|
|
211
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
212
|
-
|
|
235
|
+
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
236
|
+
const cosmosTxHistory = await cosmosAdapter.getTxHistory({
|
|
237
|
+
pubkey: cosmosAddress,
|
|
238
|
+
pageSize: 1,
|
|
239
|
+
});
|
|
240
|
+
await (0, helpers_1.performIbcTransfer)(transfer, osmosisAdapter, wallet, this.deps.cosmosUrl, buyAssetDenom, constants_1.OSMO_COSMO_CHANNEL, '0', ibcAccountNumber, ibcSequence, gas, 'uosmo');
|
|
241
|
+
return { tradeId, previousCosmosTxid: cosmosTxHistory.transactions[0].txid, cosmosAddress };
|
|
213
242
|
}
|
|
214
|
-
return { tradeId:
|
|
243
|
+
return { tradeId, previousCosmosTxid: cosmosIbcTradeId };
|
|
215
244
|
}
|
|
216
245
|
}
|
|
217
246
|
exports.OsmosisSwapper = OsmosisSwapper;
|
|
@@ -21,7 +21,7 @@ export declare const getRateInfo: (sellAsset: string, buyAsset: string, sellAmou
|
|
|
21
21
|
tradeFee: string;
|
|
22
22
|
buyAmount: string;
|
|
23
23
|
}>;
|
|
24
|
-
export declare const performIbcTransfer: (input: IbcTransferInput, adapter: CosmosSdkSupportedChainAdapters, wallet: HDWallet, blockBaseUrl: string, denom: string, sourceChannel: string, feeAmount: string, accountNumber: string, sequence: string, gas: string) => Promise<TradeResult>;
|
|
24
|
+
export declare const performIbcTransfer: (input: IbcTransferInput, adapter: CosmosSdkSupportedChainAdapters, wallet: HDWallet, blockBaseUrl: string, denom: string, sourceChannel: string, feeAmount: string, accountNumber: string, sequence: string, gas: string, feeDenom: string) => Promise<TradeResult>;
|
|
25
25
|
export declare const buildTradeTx: ({ osmoAddress, adapter, buyAssetDenom, sellAssetDenom, sellAmount, gas, wallet, }: {
|
|
26
26
|
osmoAddress: string;
|
|
27
27
|
adapter: osmosis.ChainAdapter;
|
|
@@ -160,7 +160,7 @@ const getRateInfo = async (sellAsset, buyAsset, sellAmount, osmoUrl) => {
|
|
|
160
160
|
};
|
|
161
161
|
exports.getRateInfo = getRateInfo;
|
|
162
162
|
// TODO: move to chain adapters
|
|
163
|
-
const performIbcTransfer = async (input, adapter, wallet, blockBaseUrl, denom, sourceChannel, feeAmount, accountNumber, sequence, gas) => {
|
|
163
|
+
const performIbcTransfer = async (input, adapter, wallet, blockBaseUrl, denom, sourceChannel, feeAmount, accountNumber, sequence, gas, feeDenom) => {
|
|
164
164
|
const { sender, receiver, amount } = input;
|
|
165
165
|
const responseLatestBlock = await (async () => {
|
|
166
166
|
try {
|
|
@@ -184,7 +184,7 @@ const performIbcTransfer = async (input, adapter, wallet, blockBaseUrl, denom, s
|
|
|
184
184
|
amount: [
|
|
185
185
|
{
|
|
186
186
|
amount: feeAmount.toString(),
|
|
187
|
-
denom:
|
|
187
|
+
denom: feeDenom,
|
|
188
188
|
},
|
|
189
189
|
],
|
|
190
190
|
gas,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ChainAdapterManager } from '@shapeshiftoss/chain-adapters';
|
|
2
|
+
import { TradeResult } from '../../../api';
|
|
2
3
|
export declare type OsmoSwapperDeps = {
|
|
3
4
|
adapterManager: ChainAdapterManager;
|
|
4
5
|
osmoUrl: string;
|
|
@@ -20,3 +21,7 @@ export declare type PoolAssetInfo = {
|
|
|
20
21
|
amount: string;
|
|
21
22
|
};
|
|
22
23
|
};
|
|
24
|
+
export interface OsmosisTradeResult extends TradeResult {
|
|
25
|
+
previousCosmosTxid: string;
|
|
26
|
+
cosmosAddress?: string;
|
|
27
|
+
}
|
|
@@ -55,9 +55,7 @@ const buildTrade = async ({ deps, input, }) => {
|
|
|
55
55
|
sellAmount,
|
|
56
56
|
slippageTolerance,
|
|
57
57
|
destinationAddress,
|
|
58
|
-
|
|
59
|
-
bip44Params: input.bip44Params,
|
|
60
|
-
accountType: input.accountType,
|
|
58
|
+
xpub: input.xpub,
|
|
61
59
|
tradeFee: quote.feeData.tradeFee,
|
|
62
60
|
});
|
|
63
61
|
const buildTxResponse = await sellAdapter.buildSendTransaction({
|
|
@@ -13,11 +13,7 @@ const getTradeRate_1 = require("../utils/getTradeRate/getTradeRate");
|
|
|
13
13
|
const getBtcTxFees_1 = require("../utils/txFeeHelpers/btcTxFees/getBtcTxFees");
|
|
14
14
|
const getEthTxFees_1 = require("../utils/txFeeHelpers/ethTxFees/getEthTxFees");
|
|
15
15
|
const getThorTradeQuote = async ({ deps, input }) => {
|
|
16
|
-
const { sellAsset, buyAsset, sellAmount, sellAssetAccountNumber,
|
|
17
|
-
if (!wallet)
|
|
18
|
-
throw new api_1.SwapError('[getThorTradeQuote] - wallet is required', {
|
|
19
|
-
code: api_1.SwapErrorTypes.VALIDATION_FAILED,
|
|
20
|
-
});
|
|
16
|
+
const { sellAsset, buyAsset, sellAmount, sellAssetAccountNumber, chainId, receiveAddress } = input;
|
|
21
17
|
try {
|
|
22
18
|
const { assetReference: sellAssetErc20Address } = (0, caip_1.fromAssetId)(sellAsset.assetId);
|
|
23
19
|
const sellAdapter = deps.adapterManager.get(chainId);
|
|
@@ -77,9 +73,7 @@ const getThorTradeQuote = async ({ deps, input }) => {
|
|
|
77
73
|
sellAmount,
|
|
78
74
|
slippageTolerance: constants_1.DEFAULT_SLIPPAGE,
|
|
79
75
|
destinationAddress: receiveAddress,
|
|
80
|
-
|
|
81
|
-
bip44Params: input.bip44Params,
|
|
82
|
-
accountType: input.accountType,
|
|
76
|
+
xpub: input.xpub,
|
|
83
77
|
tradeFee,
|
|
84
78
|
});
|
|
85
79
|
const feeData = await (0, getBtcTxFees_1.getBtcTxFees)({
|
|
@@ -49,7 +49,7 @@ const thorTradeApprovalNeeded = async ({ deps, input, }) => {
|
|
|
49
49
|
details: { feeData: quote.feeData },
|
|
50
50
|
});
|
|
51
51
|
return {
|
|
52
|
-
approvalNeeded: allowanceOnChain.
|
|
52
|
+
approvalNeeded: allowanceOnChain.lt((0, bignumber_1.bnOrZero)(quote.sellAmount)),
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
55
|
catch (e) {
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { Asset } from '@shapeshiftoss/asset-service';
|
|
2
|
-
import { HDWallet } from '@shapeshiftoss/hdwallet-core';
|
|
3
|
-
import { BIP44Params, UtxoAccountType } from '@shapeshiftoss/types';
|
|
4
2
|
import { ThorchainSwapperDeps } from '../../../types';
|
|
5
3
|
declare type GetBtcThorTxInfoArgs = {
|
|
6
4
|
deps: ThorchainSwapperDeps;
|
|
@@ -9,9 +7,7 @@ declare type GetBtcThorTxInfoArgs = {
|
|
|
9
7
|
sellAmount: string;
|
|
10
8
|
slippageTolerance: string;
|
|
11
9
|
destinationAddress: string;
|
|
12
|
-
|
|
13
|
-
bip44Params: BIP44Params;
|
|
14
|
-
accountType: UtxoAccountType;
|
|
10
|
+
xpub: string;
|
|
15
11
|
tradeFee: string;
|
|
16
12
|
};
|
|
17
13
|
declare type GetBtcThorTxInfoReturn = Promise<{
|
|
@@ -5,7 +5,7 @@ const api_1 = require("../../../../../api");
|
|
|
5
5
|
const getLimit_1 = require("../../getLimit/getLimit");
|
|
6
6
|
const makeSwapMemo_1 = require("../../makeSwapMemo/makeSwapMemo");
|
|
7
7
|
const thorService_1 = require("../../thorService");
|
|
8
|
-
const getThorTxInfo = async ({ deps, sellAsset, buyAsset, sellAmount, slippageTolerance, destinationAddress,
|
|
8
|
+
const getThorTxInfo = async ({ deps, sellAsset, buyAsset, sellAmount, slippageTolerance, destinationAddress, xpub, tradeFee, }) => {
|
|
9
9
|
try {
|
|
10
10
|
const { data: inboundAddresses } = await thorService_1.thorService.get(`${deps.midgardUrl}/thorchain/inbound_addresses`);
|
|
11
11
|
const sellAssetInboundAddresses = inboundAddresses.find((inbound) => inbound.chain === sellAsset.symbol.toUpperCase());
|
|
@@ -30,12 +30,10 @@ const getThorTxInfo = async ({ deps, sellAsset, buyAsset, sellAmount, slippageTo
|
|
|
30
30
|
destinationAddress,
|
|
31
31
|
limit,
|
|
32
32
|
});
|
|
33
|
-
const adapter = deps.adapterManager.get(sellAsset.chainId);
|
|
34
|
-
const pubkey = await adapter.getPublicKey(wallet, bip44Params, accountType);
|
|
35
33
|
return {
|
|
36
34
|
opReturnData: memo,
|
|
37
35
|
vault,
|
|
38
|
-
pubkey:
|
|
36
|
+
pubkey: xpub,
|
|
39
37
|
};
|
|
40
38
|
}
|
|
41
39
|
catch (e) {
|
|
@@ -44,7 +44,7 @@ async function zrxApprovalNeeded({ adapter, web3 }, { quote, wallet }) {
|
|
|
44
44
|
details: { feeData: quote.feeData },
|
|
45
45
|
});
|
|
46
46
|
return {
|
|
47
|
-
approvalNeeded: allowanceOnChain.
|
|
47
|
+
approvalNeeded: allowanceOnChain.lt((0, bignumber_1.bnOrZero)(quote.sellAmount)),
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
50
|
catch (e) {
|
package/package.json
CHANGED