@shapeshiftoss/swapper 15.3.1 → 15.3.3
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.
|
@@ -183,8 +183,9 @@ class OsmosisSwapper {
|
|
|
183
183
|
amount: sellAmountCryptoBaseUnit,
|
|
184
184
|
};
|
|
185
185
|
const responseAccount = await cosmosAdapter.getAccount(sellAddress);
|
|
186
|
+
const ibcAccountNumber = parseInt(responseAccount.chainSpecific.accountNumber || '0');
|
|
186
187
|
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');
|
|
188
|
+
const { tradeId } = await (0, helpers_1.performIbcTransfer)(transfer, cosmosAdapter, wallet, this.deps.osmoUrl, 'uatom', constants_1.COSMO_OSMO_CHANNEL, feeData.fast.txFee, accountNumber, ibcAccountNumber, sequence, gas, 'uatom');
|
|
188
189
|
cosmosIbcTradeId = tradeId;
|
|
189
190
|
// wait till confirmed
|
|
190
191
|
const pollResult = await (0, helpers_1.pollForComplete)(tradeId, this.deps.cosmosUrl);
|
|
@@ -240,7 +241,7 @@ class OsmosisSwapper {
|
|
|
240
241
|
pubkey: cosmosAddress,
|
|
241
242
|
pageSize: 1,
|
|
242
243
|
});
|
|
243
|
-
await (0, helpers_1.performIbcTransfer)(transfer, osmosisAdapter, wallet, this.deps.cosmosUrl, buyAssetDenom, constants_1.OSMO_COSMO_CHANNEL, '0', ibcAccountNumber, ibcSequence, gas, 'uosmo');
|
|
244
|
+
await (0, helpers_1.performIbcTransfer)(transfer, osmosisAdapter, wallet, this.deps.cosmosUrl, buyAssetDenom, constants_1.OSMO_COSMO_CHANNEL, '0', accountNumber, ibcAccountNumber, ibcSequence, gas, 'uosmo');
|
|
244
245
|
return { tradeId, previousCosmosTxid: (_a = cosmosTxHistory.transactions[0]) === null || _a === void 0 ? void 0 : _a.txid, cosmosAddress };
|
|
245
246
|
}
|
|
246
247
|
return { tradeId, previousCosmosTxid: cosmosIbcTradeId };
|
|
@@ -21,7 +21,7 @@ export declare const getRateInfo: (sellAsset: string, buyAsset: string, sellAmou
|
|
|
21
21
|
buyAssetTradeFeeUsd: string;
|
|
22
22
|
buyAmountCryptoBaseUnit: string;
|
|
23
23
|
}>;
|
|
24
|
-
export declare const performIbcTransfer: (input: IbcTransferInput, adapter: CosmosSdkSupportedChainAdapters, wallet: HDWallet, blockBaseUrl: string, denom: string, sourceChannel: string, feeAmount: string, accountNumber: number, sequence: string, gas: string, feeDenom: string) => Promise<TradeResult>;
|
|
24
|
+
export declare const performIbcTransfer: (input: IbcTransferInput, adapter: CosmosSdkSupportedChainAdapters, wallet: HDWallet, blockBaseUrl: string, denom: string, sourceChannel: string, feeAmount: string, accountNumber: number, ibcAccountNumber: number, sequence: string, gas: string, feeDenom: string) => Promise<TradeResult>;
|
|
25
25
|
export declare const buildTradeTx: ({ osmoAddress, adapter, accountNumber, buyAssetDenom, sellAssetDenom, sellAmount, gas, wallet, }: {
|
|
26
26
|
osmoAddress: string;
|
|
27
27
|
adapter: osmosis.ChainAdapter;
|
|
@@ -9,8 +9,19 @@ const chain_adapters_1 = require("@shapeshiftoss/chain-adapters");
|
|
|
9
9
|
const axios_1 = __importDefault(require("axios"));
|
|
10
10
|
const lodash_1 = require("lodash");
|
|
11
11
|
const api_1 = require("../../../api");
|
|
12
|
+
const utils_1 = require("../../../utils");
|
|
12
13
|
const bignumber_1 = require("../../utils/bignumber");
|
|
13
14
|
const constants_1 = require("./constants");
|
|
15
|
+
// Create cached axios service for pools endpoint because it gets called a LOT
|
|
16
|
+
const cache = (0, utils_1.createCache)(3000, ['/osmosis/gamm/v1beta1/pools/']);
|
|
17
|
+
const osmoPoolsService = axios_1.default.create({
|
|
18
|
+
timeout: 10000,
|
|
19
|
+
headers: {
|
|
20
|
+
Accept: 'application/json',
|
|
21
|
+
'Content-Type': 'application/json',
|
|
22
|
+
},
|
|
23
|
+
adapter: cache.adapter,
|
|
24
|
+
});
|
|
14
25
|
exports.symbolDenomMapping = {
|
|
15
26
|
OSMO: 'uosmo',
|
|
16
27
|
ATOM: 'ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2',
|
|
@@ -102,10 +113,12 @@ exports.pollForAtomChannelBalance = pollForAtomChannelBalance;
|
|
|
102
113
|
const findPool = async (sellAssetSymbol, buyAssetSymbol, osmoUrl) => {
|
|
103
114
|
const sellAssetDenom = exports.symbolDenomMapping[sellAssetSymbol];
|
|
104
115
|
const buyAssetDenom = exports.symbolDenomMapping[buyAssetSymbol];
|
|
105
|
-
|
|
116
|
+
// pagination.limit can be small because we only care about the osmo/atom pool right now
|
|
117
|
+
// this will need to increase when adding new pools
|
|
118
|
+
const poolsUrl = osmoUrl + '/osmosis/gamm/v1beta1/pools?pagination.limit=10';
|
|
106
119
|
const poolsResponse = await (async () => {
|
|
107
120
|
try {
|
|
108
|
-
return
|
|
121
|
+
return osmoPoolsService.get(poolsUrl);
|
|
109
122
|
}
|
|
110
123
|
catch (e) {
|
|
111
124
|
throw new api_1.SwapError('failed to get pool', {
|
|
@@ -161,7 +174,7 @@ const getRateInfo = async (sellAsset, buyAsset, sellAmount, osmoUrl) => {
|
|
|
161
174
|
};
|
|
162
175
|
exports.getRateInfo = getRateInfo;
|
|
163
176
|
// TODO: move to chain adapters
|
|
164
|
-
const performIbcTransfer = async (input, adapter, wallet, blockBaseUrl, denom, sourceChannel, feeAmount, accountNumber, sequence, gas, feeDenom) => {
|
|
177
|
+
const performIbcTransfer = async (input, adapter, wallet, blockBaseUrl, denom, sourceChannel, feeAmount, accountNumber, ibcAccountNumber, sequence, gas, feeDenom) => {
|
|
165
178
|
const { sender, receiver, amount } = input;
|
|
166
179
|
const responseLatestBlock = await (async () => {
|
|
167
180
|
try {
|
|
@@ -212,7 +225,7 @@ const performIbcTransfer = async (input, adapter, wallet, blockBaseUrl, denom, s
|
|
|
212
225
|
tx,
|
|
213
226
|
addressNList: (0, chain_adapters_1.toAddressNList)(bip44Params),
|
|
214
227
|
chain_id: (0, caip_1.fromChainId)(adapter.getChainId()).chainReference,
|
|
215
|
-
account_number:
|
|
228
|
+
account_number: ibcAccountNumber.toString(),
|
|
216
229
|
sequence,
|
|
217
230
|
},
|
|
218
231
|
wallet,
|
package/package.json
CHANGED