@shapeshiftoss/unchained-client 8.4.0 → 8.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.
@@ -0,0 +1,20 @@
1
+ import { Tx as BlockbookTx } from '@shapeshiftoss/blockbook';
2
+ import { ChainId } from '@shapeshiftoss/caip';
3
+ import { ethers } from 'ethers';
4
+ import { SubParser, TxSpecific } from '../types';
5
+ interface ParserArgs {
6
+ chainId: ChainId;
7
+ provider: ethers.providers.JsonRpcProvider;
8
+ }
9
+ export declare class Parser implements SubParser {
10
+ provider: ethers.providers.JsonRpcProvider;
11
+ readonly chainId: ChainId;
12
+ readonly erc20Interface: ethers.utils.Interface;
13
+ readonly supportedERC20Functions: {
14
+ approveSigHash: string;
15
+ };
16
+ constructor(args: ParserArgs);
17
+ parse(tx: BlockbookTx): Promise<TxSpecific | undefined>;
18
+ getAbiInterface(txSigHash: string | undefined): ethers.utils.Interface | undefined;
19
+ }
20
+ export {};
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Parser = void 0;
7
+ const caip_1 = require("@shapeshiftoss/caip");
8
+ const ethers_1 = require("ethers");
9
+ const types_1 = require("../types");
10
+ const erc20_1 = __importDefault(require("./abi/erc20"));
11
+ const utils_1 = require("./utils");
12
+ class Parser {
13
+ constructor(args) {
14
+ this.erc20Interface = new ethers_1.ethers.utils.Interface(erc20_1.default);
15
+ this.supportedERC20Functions = {
16
+ approveSigHash: this.erc20Interface.getSighash('approve')
17
+ };
18
+ this.provider = args.provider;
19
+ this.chainId = args.chainId;
20
+ }
21
+ async parse(tx) {
22
+ var _a, _b, _c, _d;
23
+ const txData = (_a = tx.ethereumSpecific) === null || _a === void 0 ? void 0 : _a.data;
24
+ if (!txData)
25
+ return;
26
+ const txSigHash = (0, utils_1.getSigHash)(txData);
27
+ const abiInterface = this.getAbiInterface(txSigHash);
28
+ if (!abiInterface)
29
+ return;
30
+ const decoded = abiInterface.parseTransaction({ data: txData });
31
+ // failed to decode input data
32
+ if (!decoded)
33
+ return;
34
+ const receiveAddress = (_d = (_c = (_b = tx.vout) === null || _b === void 0 ? void 0 : _b[0].addresses) === null || _c === void 0 ? void 0 : _c[0]) !== null && _d !== void 0 ? _d : '';
35
+ return {
36
+ data: {
37
+ assetId: receiveAddress
38
+ ? (0, caip_1.toAssetId)({
39
+ ...(0, caip_1.fromChainId)(this.chainId),
40
+ assetNamespace: 'erc20',
41
+ assetReference: receiveAddress
42
+ })
43
+ : undefined,
44
+ method: types_1.TxMethod.Approve,
45
+ parser: types_1.EthereumTxParser.ERC20Approve
46
+ }
47
+ };
48
+ }
49
+ getAbiInterface(txSigHash) {
50
+ if (Object.values(this.supportedERC20Functions).some((abi) => abi === txSigHash))
51
+ return this.erc20Interface;
52
+ return undefined;
53
+ }
54
+ }
55
+ exports.Parser = Parser;
@@ -14,6 +14,7 @@ export declare class TransactionParser {
14
14
  private readonly yearn;
15
15
  private readonly foxy;
16
16
  private readonly weth;
17
+ private readonly erc20Approve;
17
18
  private readonly parsers;
18
19
  constructor(args: TransactionParserArgs);
19
20
  getInternalAddress(inputData: string): string | undefined;
@@ -29,6 +29,7 @@ const bignumber_js_1 = require("bignumber.js");
29
29
  const ethers_1 = require("ethers");
30
30
  const types_1 = require("../../types");
31
31
  const utils_1 = require("../../utils");
32
+ const erc20Approve = __importStar(require("./erc20Approve"));
32
33
  const foxy = __importStar(require("./foxy"));
33
34
  const thor = __importStar(require("./thor"));
34
35
  const uniV2 = __importStar(require("./uniV2"));
@@ -51,7 +52,16 @@ class TransactionParser {
51
52
  this.yearn = new yearn.Parser({ provider, chainId: this.chainId });
52
53
  this.foxy = new foxy.Parser();
53
54
  this.weth = new weth.Parser({ chainId: this.chainId, provider });
54
- this.parsers = [this.zrx, this.thor, this.uniV2, this.yearn, this.foxy, this.weth];
55
+ this.erc20Approve = new erc20Approve.Parser({ chainId: this.chainId, provider });
56
+ this.parsers = [
57
+ this.zrx,
58
+ this.thor,
59
+ this.uniV2,
60
+ this.yearn,
61
+ this.foxy,
62
+ this.weth,
63
+ this.erc20Approve
64
+ ];
55
65
  }
56
66
  // return any addresses that can be detected
57
67
  getInternalAddress(inputData) {
@@ -1,5 +1,17 @@
1
1
  import { Tx as BlockbookTx } from '@shapeshiftoss/blockbook';
2
- import { StandardTx, StandardTxMetadata } from '../types';
2
+ import { BaseTxMetadata, StandardTx, StandardTxMetadata } from '../types';
3
+ export declare enum EthereumTxParser {
4
+ ERC20Approve = "erc20Approve"
5
+ }
6
+ export declare enum TxMethod {
7
+ Approve = "approve"
8
+ }
9
+ export interface ERC20ApproveTxMetadata extends BaseTxMetadata {
10
+ method: TxMethod.Approve;
11
+ parser: EthereumTxParser.ERC20Approve;
12
+ assetId?: string;
13
+ }
14
+ export declare type TxMetadata = StandardTxMetadata | ERC20ApproveTxMetadata;
3
15
  export interface InternalTx {
4
16
  blockNumber: string;
5
17
  timeStamp: string;
@@ -17,7 +29,7 @@ export interface InternalTx {
17
29
  errCode: string;
18
30
  }
19
31
  export interface ParsedTx extends StandardTx {
20
- data?: StandardTxMetadata;
32
+ data?: TxMetadata;
21
33
  }
22
34
  export declare type TxSpecific = Partial<Pick<ParsedTx, 'trade' | 'transfers' | 'data'>>;
23
35
  export interface SubParser {
@@ -1,2 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TxMethod = exports.EthereumTxParser = void 0;
4
+ var EthereumTxParser;
5
+ (function (EthereumTxParser) {
6
+ EthereumTxParser["ERC20Approve"] = "erc20Approve";
7
+ })(EthereumTxParser = exports.EthereumTxParser || (exports.EthereumTxParser = {}));
8
+ var TxMethod;
9
+ (function (TxMethod) {
10
+ TxMethod["Approve"] = "approve";
11
+ })(TxMethod = exports.TxMethod || (exports.TxMethod = {}));
@@ -20,7 +20,7 @@ exports.RequiredError = exports.BaseAPI = exports.COLLECTION_FORMATS = exports.B
20
20
  // Some imports not used depending on template conditions
21
21
  // @ts-ignore
22
22
  const axios_1 = __importDefault(require("axios"));
23
- exports.BASE_PATH = "https://dev-api.bitcoin.shapeshift.com".replace(/\/+$/, "");
23
+ exports.BASE_PATH = "https://api.bitcoin.shapeshift.com".replace(/\/+$/, "");
24
24
  /**
25
25
  *
26
26
  * @export
@@ -20,7 +20,7 @@ exports.RequiredError = exports.BaseAPI = exports.COLLECTION_FORMATS = exports.B
20
20
  // Some imports not used depending on template conditions
21
21
  // @ts-ignore
22
22
  const axios_1 = __importDefault(require("axios"));
23
- exports.BASE_PATH = "https://dev-api.ethereum.shapeshift.com".replace(/\/+$/, "");
23
+ exports.BASE_PATH = "https://api.ethereum.shapeshift.com".replace(/\/+$/, "");
24
24
  /**
25
25
  *
26
26
  * @export
package/dist/types.d.ts CHANGED
@@ -51,8 +51,11 @@ export declare enum TxParser {
51
51
  Foxy = "foxy",
52
52
  WETH = "weth"
53
53
  }
54
- export interface StandardTxMetadata {
54
+ export interface BaseTxMetadata {
55
55
  method?: string;
56
+ parser: string;
57
+ }
58
+ export interface StandardTxMetadata extends BaseTxMetadata {
56
59
  parser: TxParser;
57
60
  }
58
61
  export interface StandardTx {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/unchained-client",
3
- "version": "8.4.0",
3
+ "version": "8.6.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "source": "src/index.ts",
@@ -9,7 +9,7 @@
9
9
  "dist"
10
10
  ],
11
11
  "scripts": {
12
- "build": "yarn build:dev",
12
+ "build": "yarn build:prod",
13
13
  "build:dev": "yarn clean && yarn generate:dev && tsc -p tsconfig.build.json",
14
14
  "build:prod": "yarn clean && yarn generate:prod && tsc -p tsconfig.build.json",
15
15
  "build:local": "yarn clean && yarn generate:local && tsc -p tsconfig.build.json",
@@ -30,13 +30,13 @@
30
30
  "ws": "^8.3.0"
31
31
  },
32
32
  "peerDependencies": {
33
- "@shapeshiftoss/caip": "^5.0.0",
33
+ "@shapeshiftoss/caip": "^5.2.1",
34
34
  "@shapeshiftoss/logger": "^1.1.2",
35
35
  "@shapeshiftoss/types": "^4.3.1"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@openapitools/openapi-generator-cli": "^2.5.1",
39
- "@shapeshiftoss/caip": "^5.0.0",
39
+ "@shapeshiftoss/caip": "^5.2.1",
40
40
  "@shapeshiftoss/common-api": "^6.11.0",
41
41
  "@shapeshiftoss/logger": "^1.1.2",
42
42
  "@shapeshiftoss/types": "^4.3.1",