@shapeshiftoss/swapper 9.5.0 → 9.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
@@ -168,7 +168,8 @@ export declare enum SwapErrorTypes {
168
168
  MAKE_MEMO_FAILED = "MAKE_MEMO_FAILED",
169
169
  PRICE_RATIO_FAILED = "PRICE_RATIO_FAILED",
170
170
  POOL_NOT_FOUND = "POOL_NOT_FOUND",
171
- GET_TRADE_TXS_FAILED = "GET_TRADE_TXS_FAILED"
171
+ GET_TRADE_TXS_FAILED = "GET_TRADE_TXS_FAILED",
172
+ TRADE_FAILED = "TRADE_FAILED"
172
173
  }
173
174
  export interface Swapper<T extends ChainId> {
174
175
  /** Human readable swapper name */
package/dist/api.js CHANGED
@@ -37,4 +37,5 @@ var SwapErrorTypes;
37
37
  SwapErrorTypes["PRICE_RATIO_FAILED"] = "PRICE_RATIO_FAILED";
38
38
  SwapErrorTypes["POOL_NOT_FOUND"] = "POOL_NOT_FOUND";
39
39
  SwapErrorTypes["GET_TRADE_TXS_FAILED"] = "GET_TRADE_TXS_FAILED";
40
+ SwapErrorTypes["TRADE_FAILED"] = "TRADE_FAILED";
40
41
  })(SwapErrorTypes = exports.SwapErrorTypes || (exports.SwapErrorTypes = {}));
@@ -23,6 +23,7 @@ class ThorchainSwapper {
23
23
  [types_1.KnownChainIds.BitcoinMainnet]: true,
24
24
  [types_1.KnownChainIds.DogecoinMainnet]: true,
25
25
  [types_1.KnownChainIds.LitecoinMainnet]: true,
26
+ [types_1.KnownChainIds.BitcoinCashMainnet]: true,
26
27
  [types_1.KnownChainIds.CosmosMainnet]: true
27
28
  };
28
29
  this.supportedSellAssetIds = [];
@@ -132,11 +133,35 @@ class ThorchainSwapper {
132
133
  }
133
134
  }
134
135
  async getTradeTxs(tradeResult) {
135
- // TODO poll midgard for the correct buyTxid
136
- return {
137
- sellTxid: tradeResult.tradeId,
138
- buyTxid: tradeResult.tradeId
139
- };
136
+ var _a, _b, _c, _d;
137
+ try {
138
+ const midgardTxid = tradeResult.tradeId.startsWith('0x')
139
+ ? tradeResult.tradeId.slice(2)
140
+ : tradeResult.tradeId;
141
+ const { data: responseData } = await thorService_1.thorService.get(`${this.deps.midgardUrl}/actions?txid=${midgardTxid}`);
142
+ const buyTxid = ((_a = responseData === null || responseData === void 0 ? void 0 : responseData.actions[0]) === null || _a === void 0 ? void 0 : _a.status) === 'success' && ((_b = responseData === null || responseData === void 0 ? void 0 : responseData.actions[0]) === null || _b === void 0 ? void 0 : _b.type) === 'swap'
143
+ ? responseData === null || responseData === void 0 ? void 0 : responseData.actions[0].out[0].txID
144
+ : '';
145
+ // This will detect all the errors I have seen.
146
+ if (((_c = responseData === null || responseData === void 0 ? void 0 : responseData.actions[0]) === null || _c === void 0 ? void 0 : _c.status) === 'success' &&
147
+ ((_d = responseData === null || responseData === void 0 ? void 0 : responseData.actions[0]) === null || _d === void 0 ? void 0 : _d.type) !== 'swap')
148
+ throw new api_1.SwapError('[getTradeTxs]: trade failed', {
149
+ code: api_1.SwapErrorTypes.TRADE_FAILED,
150
+ cause: responseData
151
+ });
152
+ return {
153
+ sellTxid: tradeResult.tradeId,
154
+ buyTxid: buyTxid.toLowerCase()
155
+ };
156
+ }
157
+ catch (e) {
158
+ if (e instanceof api_1.SwapError)
159
+ throw e;
160
+ throw new api_1.SwapError('[getTradeTxs]: error', {
161
+ code: api_1.SwapErrorTypes.GET_TRADE_TXS_FAILED,
162
+ cause: e
163
+ });
164
+ }
140
165
  }
141
166
  }
142
167
  exports.ThorchainSwapper = ThorchainSwapper;
@@ -18,6 +18,19 @@ export declare type PoolResponse = {
18
18
  units: string;
19
19
  volume24h: string;
20
20
  };
21
+ declare type MidgardActionOut = {
22
+ txID: string;
23
+ };
24
+ declare type MidgardAction = {
25
+ date: string;
26
+ height: string;
27
+ out: MidgardActionOut[];
28
+ status: string;
29
+ type: string;
30
+ };
31
+ export declare type MidgardActionsResponse = {
32
+ actions: MidgardAction[];
33
+ };
21
34
  export declare type InboundResponse = {
22
35
  chain: string;
23
36
  pub_key: string;
@@ -44,3 +57,4 @@ export interface CosmosThorTrade<C extends ChainId> extends Trade<C> {
44
57
  txData: CosmosSignTx;
45
58
  }
46
59
  export declare type ThorTrade<C extends ChainId> = BtcThorTrade<C> | EthThorTrade<C> | CosmosThorTrade<C>;
60
+ export {};
@@ -20,6 +20,7 @@ exports.THOR_TRADE_FEE_MULTIPLIERS = {
20
20
  [types_1.KnownChainIds.BitcoinMainnet]: (0, bignumber_1.bn)(0.00002),
21
21
  [types_1.KnownChainIds.DogecoinMainnet]: (0, bignumber_1.bn)(0.00002),
22
22
  [types_1.KnownChainIds.LitecoinMainnet]: (0, bignumber_1.bn)(0.000005),
23
+ [types_1.KnownChainIds.BitcoinCashMainnet]: (0, bignumber_1.bn)(0.00003),
23
24
  [types_1.KnownChainIds.CosmosMainnet]: (0, bignumber_1.bn)(0.00000002),
24
25
  [types_1.KnownChainIds.EthereumMainnet]: (0, bignumber_1.bn)(0.00024) // A value that "works". Discord recommended value (80,000 gas * 2 or 160k) is often too low
25
26
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/swapper",
3
- "version": "9.5.0",
3
+ "version": "9.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",