@shapeshiftoss/swapper 5.2.3 → 5.3.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
@@ -141,7 +141,8 @@ export declare enum SwapErrorTypes {
141
141
  UNSUPPORTED_PAIR = "UNSUPPORTED_PAIR",
142
142
  USD_RATE_FAILED = "USD_RATE_FAILED",
143
143
  UNSUPPORTED_CHAIN = "UNSUPPORTED_CHAIN",
144
- VALIDATION_FAILED = "VALIDATION_FAILED"
144
+ VALIDATION_FAILED = "VALIDATION_FAILED",
145
+ MAKE_MEMO_FAILED = "MAKE_MEMO_FAILED"
145
146
  }
146
147
  export interface Swapper {
147
148
  /** perform any necessary async initialization */
package/dist/api.js CHANGED
@@ -27,4 +27,5 @@ var SwapErrorTypes;
27
27
  SwapErrorTypes["USD_RATE_FAILED"] = "USD_RATE_FAILED";
28
28
  SwapErrorTypes["UNSUPPORTED_CHAIN"] = "UNSUPPORTED_CHAIN";
29
29
  SwapErrorTypes["VALIDATION_FAILED"] = "VALIDATION_FAILED";
30
+ SwapErrorTypes["MAKE_MEMO_FAILED"] = "MAKE_MEMO_FAILED";
30
31
  })(SwapErrorTypes = exports.SwapErrorTypes || (exports.SwapErrorTypes = {}));
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @returns thorchain memo shortened to a max of 80 characters as described:
3
+ * https://dev.thorchain.org/thorchain-dev/memos#mechanism-for-transaction-intent
4
+ */
5
+ export declare const makeSwapMemo: ({ buyAssetId, destinationAddress, limit }: {
6
+ buyAssetId: string;
7
+ destinationAddress: string;
8
+ limit: string;
9
+ }) => string;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeSwapMemo = void 0;
4
+ const caip_1 = require("@shapeshiftoss/caip");
5
+ const api_1 = require("../../../api");
6
+ // BTC (and likely other utxo coins) can only support up to 80 character memos
7
+ const MAX_LENGTH = 80;
8
+ /**
9
+ * @returns thorchain memo shortened to a max of 80 characters as described:
10
+ * https://dev.thorchain.org/thorchain-dev/memos#mechanism-for-transaction-intent
11
+ */
12
+ const makeSwapMemo = ({ buyAssetId, destinationAddress, limit }) => {
13
+ const thorId = caip_1.adapters.assetIdToPoolAssetId({ assetId: buyAssetId });
14
+ if (!thorId)
15
+ throw new api_1.SwapError('[makeSwapMemo] - undefined thorId for given buyAssetId', {
16
+ code: api_1.SwapErrorTypes.MAKE_MEMO_FAILED,
17
+ details: { buyAssetId }
18
+ });
19
+ const memo = `s:${thorId}:${destinationAddress}:${limit}`;
20
+ if (memo.length <= MAX_LENGTH)
21
+ return memo;
22
+ const abbreviationAmount = memo.length - MAX_LENGTH;
23
+ if (abbreviationAmount > 39)
24
+ throw new api_1.SwapError('[makeSwapMemo] - too much abbreviation for accurate matching', {
25
+ code: api_1.SwapErrorTypes.MAKE_MEMO_FAILED
26
+ });
27
+ // delimeter between ticker and id allowing us to abbreviate the id: https://dev.thorchain.org/thorchain-dev/memos#asset-notation
28
+ const delimeterIndex = memo.indexOf('-') + 1;
29
+ if (!delimeterIndex) {
30
+ throw new api_1.SwapError('[makeSwapMemo] - unable to abbreviate asset, no delimeter found', {
31
+ code: api_1.SwapErrorTypes.MAKE_MEMO_FAILED
32
+ });
33
+ }
34
+ return memo.replace(memo.slice(delimeterIndex, delimeterIndex + abbreviationAmount), '');
35
+ };
36
+ exports.makeSwapMemo = makeSwapMemo;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/swapper",
3
- "version": "5.2.3",
3
+ "version": "5.3.0",
4
4
  "description": "TODO: description",
5
5
  "repository": "https://github.com/shapeshift/lib",
6
6
  "license": "MIT",
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "peerDependencies": {
33
33
  "@shapeshiftoss/asset-service": "^4.2.4",
34
- "@shapeshiftoss/caip": "^5.0.0",
34
+ "@shapeshiftoss/caip": "^5.2.1",
35
35
  "@shapeshiftoss/chain-adapters": "^4.3.3",
36
36
  "@shapeshiftoss/hdwallet-core": "1.20.0",
37
37
  "@shapeshiftoss/types": "^4.3.1",
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "devDependencies": {
41
41
  "@shapeshiftoss/asset-service": "^4.2.4",
42
- "@shapeshiftoss/caip": "^5.0.0",
42
+ "@shapeshiftoss/caip": "^5.2.1",
43
43
  "@shapeshiftoss/chain-adapters": "^4.3.3",
44
44
  "@shapeshiftoss/hdwallet-core": "^1.20.0",
45
45
  "@shapeshiftoss/types": "^4.3.1",