@shapeshiftoss/swapper 9.5.0 → 9.7.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 = {}));
@@ -25,3 +25,4 @@ export declare class CowSwapper implements Swapper<KnownChainIds.EthereumMainnet
25
25
  filterAssetIdsBySellable(assetIds: AssetId[]): AssetId[];
26
26
  getTradeTxs(args: TradeResult): Promise<TradeTxs>;
27
27
  }
28
+ export * from './types';
@@ -1,4 +1,18 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
17
  exports.CowSwapper = void 0;
4
18
  const caip_1 = require("@shapeshiftoss/caip");
@@ -55,3 +69,4 @@ class CowSwapper {
55
69
  }
56
70
  }
57
71
  exports.CowSwapper = CowSwapper;
72
+ __exportStar(require("./types"), exports);
@@ -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,38 @@ 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, _e, _f, _g;
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
+ const standardBuyTxid = ((_g = (_f = (_e = responseData === null || responseData === void 0 ? void 0 : responseData.actions[0]) === null || _e === void 0 ? void 0 : _e.out[0]) === null || _f === void 0 ? void 0 : _f.coins[0]) === null || _g === void 0 ? void 0 : _g.asset.startsWith('ETH.'))
153
+ ? `0x${buyTxid}`
154
+ : buyTxid;
155
+ return {
156
+ sellTxid: tradeResult.tradeId,
157
+ buyTxid: standardBuyTxid.toLowerCase()
158
+ };
159
+ }
160
+ catch (e) {
161
+ if (e instanceof api_1.SwapError)
162
+ throw e;
163
+ throw new api_1.SwapError('[getTradeTxs]: error', {
164
+ code: api_1.SwapErrorTypes.GET_TRADE_TXS_FAILED,
165
+ cause: e
166
+ });
167
+ }
140
168
  }
141
169
  }
142
170
  exports.ThorchainSwapper = ThorchainSwapper;
@@ -18,6 +18,23 @@ export declare type PoolResponse = {
18
18
  units: string;
19
19
  volume24h: string;
20
20
  };
21
+ declare type MidardCoins = {
22
+ asset: string;
23
+ }[];
24
+ declare type MidgardActionOut = {
25
+ coins: MidardCoins;
26
+ txID: string;
27
+ };
28
+ declare type MidgardAction = {
29
+ date: string;
30
+ height: string;
31
+ out: MidgardActionOut[];
32
+ status: string;
33
+ type: string;
34
+ };
35
+ export declare type MidgardActionsResponse = {
36
+ actions: MidgardAction[];
37
+ };
21
38
  export declare type InboundResponse = {
22
39
  chain: string;
23
40
  pub_key: string;
@@ -44,3 +61,4 @@ export interface CosmosThorTrade<C extends ChainId> extends Trade<C> {
44
61
  txData: CosmosSignTx;
45
62
  }
46
63
  export declare type ThorTrade<C extends ChainId> = BtcThorTrade<C> | EthThorTrade<C> | CosmosThorTrade<C>;
64
+ 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
  };
@@ -17,7 +17,14 @@ const makeSwapMemo = ({ buyAssetId, destinationAddress, limit }) => {
17
17
  code: api_1.SwapErrorTypes.MAKE_MEMO_FAILED,
18
18
  details: { buyAssetId }
19
19
  });
20
- const memo = `s:${thorId}:${destinationAddress}:${limit}:${constants_1.THORCHAIN_AFFILIATE_NAME}:${constants_1.THORCHAIN_AFFILIATE_BIPS}`;
20
+ // bch hack
21
+ // Our bitcoin cash addresses are prefixed with `bitcoincash:`
22
+ // But thorchain memos need to be short (under 80 bytes for utxo)
23
+ // For this reason thorchain doesnt allow / need bitcoincash: in the memo
24
+ const parsedDestinationAddress = destinationAddress.includes('bitcoincash:')
25
+ ? destinationAddress.replace('bitcoincash:', '')
26
+ : destinationAddress;
27
+ const memo = `s:${thorId}:${parsedDestinationAddress}:${limit}:${constants_1.THORCHAIN_AFFILIATE_NAME}:${constants_1.THORCHAIN_AFFILIATE_BIPS}`;
21
28
  if (memo.length <= MAX_LENGTH)
22
29
  return memo;
23
30
  const abbreviationAmount = memo.length - MAX_LENGTH;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/swapper",
3
- "version": "9.5.0",
3
+ "version": "9.7.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",