@shapeshiftoss/unchained-client 8.5.0 → 9.0.0-alpha.2

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.
@@ -1,13 +1,12 @@
1
- import { Tx as BlockbookTx } from '@shapeshiftoss/blockbook';
2
1
  import { AssetId, ChainId } from '@shapeshiftoss/caip';
2
+ import { BitcoinTx } from '../../generated/bitcoin';
3
3
  import { Tx as ParsedTx } from '../../types';
4
4
  export interface TransactionParserArgs {
5
5
  chainId: ChainId;
6
- rpcUrl: string;
7
6
  }
8
7
  export declare class TransactionParser {
9
8
  chainId: ChainId;
10
9
  assetId: AssetId;
11
10
  constructor(args: TransactionParserArgs);
12
- parse(tx: BlockbookTx, address: string): Promise<ParsedTx>;
11
+ parse(tx: BitcoinTx, address: string): Promise<ParsedTx>;
13
12
  }
@@ -19,7 +19,7 @@ class TransactionParser {
19
19
  address,
20
20
  blockHash: tx.blockHash,
21
21
  blockHeight: tx.blockHeight,
22
- blockTime: tx.blockTime,
22
+ blockTime: tx.timestamp,
23
23
  chainId: this.chainId,
24
24
  confirmations: tx.confirmations,
25
25
  status: tx.confirmations > 0 ? types_1.Status.Confirmed : types_1.Status.Pending,
@@ -28,14 +28,14 @@ class TransactionParser {
28
28
  };
29
29
  tx.vin.forEach((vin) => {
30
30
  var _a, _b, _c, _d, _e, _f, _g;
31
- if (vin.isAddress && ((_a = vin.addresses) === null || _a === void 0 ? void 0 : _a.includes(address))) {
31
+ if ((_a = vin.addresses) === null || _a === void 0 ? void 0 : _a.includes(address)) {
32
32
  // send amount
33
33
  const sendValue = new bignumber_js_1.BigNumber((_b = vin.value) !== null && _b !== void 0 ? _b : 0);
34
34
  if (sendValue.gt(0)) {
35
35
  parsedTx.transfers = (0, utils_1.aggregateTransfer)(parsedTx.transfers, types_1.TransferType.Send, this.assetId, (_d = (_c = vin.addresses) === null || _c === void 0 ? void 0 : _c[0]) !== null && _d !== void 0 ? _d : '', (_f = (_e = tx.vout[0].addresses) === null || _e === void 0 ? void 0 : _e[0]) !== null && _f !== void 0 ? _f : '', sendValue.toString(10));
36
36
  }
37
37
  // network fee
38
- const fees = new bignumber_js_1.BigNumber((_g = tx.fees) !== null && _g !== void 0 ? _g : 0);
38
+ const fees = new bignumber_js_1.BigNumber((_g = tx.fee) !== null && _g !== void 0 ? _g : 0);
39
39
  if (fees.gt(0)) {
40
40
  parsedTx.fee = { assetId: this.assetId, value: fees.toString(10) };
41
41
  }
@@ -43,7 +43,7 @@ class TransactionParser {
43
43
  });
44
44
  tx.vout.forEach((vout) => {
45
45
  var _a, _b, _c, _d, _e, _f;
46
- if (vout.isAddress && ((_a = vout.addresses) === null || _a === void 0 ? void 0 : _a.includes(address))) {
46
+ if ((_a = vout.addresses) === null || _a === void 0 ? void 0 : _a.includes(address)) {
47
47
  // receive amount
48
48
  const receiveValue = new bignumber_js_1.BigNumber((_b = vout.value) !== null && _b !== void 0 ? _b : 0);
49
49
  if (receiveValue.gt(0)) {
@@ -1,5 +1,5 @@
1
- import { Tx as BlockbookTx } from '@shapeshiftoss/blockbook';
2
1
  import { ethers } from 'ethers';
2
+ import { EthereumTx } from '../../generated/ethereum';
3
3
  import { SubParser, TxSpecific } from '../types';
4
4
  export declare class Parser implements SubParser {
5
5
  readonly abiInterface: ethers.utils.Interface;
@@ -9,5 +9,5 @@ export declare class Parser implements SubParser {
9
9
  instantUnstakeSigHash: string;
10
10
  claimWithdrawSigHash: string;
11
11
  };
12
- parse(tx: BlockbookTx): Promise<TxSpecific | undefined>;
12
+ parse(tx: EthereumTx): Promise<TxSpecific | undefined>;
13
13
  }
@@ -20,16 +20,14 @@ class Parser {
20
20
  };
21
21
  }
22
22
  async parse(tx) {
23
- var _a;
24
- const txData = (_a = tx.ethereumSpecific) === null || _a === void 0 ? void 0 : _a.data;
25
23
  if (!(0, utils_1.txInteractsWithContract)(tx, constants_1.FOXY_STAKING_CONTRACT))
26
24
  return;
27
- if (!txData)
25
+ if (!tx.inputData)
28
26
  return;
29
- const txSigHash = (0, utils_1.getSigHash)(txData);
27
+ const txSigHash = (0, utils_1.getSigHash)(tx.inputData);
30
28
  if (!Object.values(this.supportedFunctions).some((hash) => hash === txSigHash))
31
29
  return;
32
- const decoded = this.abiInterface.parseTransaction({ data: txData });
30
+ const decoded = this.abiInterface.parseTransaction({ data: tx.inputData });
33
31
  // failed to decode input data
34
32
  if (!decoded)
35
33
  return;
@@ -1,6 +1,6 @@
1
- import { Tx as BlockbookTx } from '@shapeshiftoss/blockbook';
2
1
  import { AssetId, ChainId } from '@shapeshiftoss/caip';
3
- import { InternalTx, ParsedTx } from '../types';
2
+ import { EthereumTx } from '../../generated/ethereum';
3
+ import { ParsedTx } from '../types';
4
4
  export interface TransactionParserArgs {
5
5
  chainId: ChainId;
6
6
  rpcUrl: string;
@@ -16,8 +16,7 @@ export declare class TransactionParser {
16
16
  private readonly weth;
17
17
  private readonly parsers;
18
18
  constructor(args: TransactionParserArgs);
19
- getInternalAddress(inputData: string): string | undefined;
20
- parse(tx: BlockbookTx, address: string, internalTxs?: Array<InternalTx>): Promise<ParsedTx>;
19
+ parse(tx: EthereumTx, address: string): Promise<ParsedTx>;
21
20
  private static getStatus;
22
21
  private getParsedTxWithTransfers;
23
22
  }
@@ -32,7 +32,6 @@ const utils_1 = require("../../utils");
32
32
  const foxy = __importStar(require("./foxy"));
33
33
  const thor = __importStar(require("./thor"));
34
34
  const uniV2 = __importStar(require("./uniV2"));
35
- const utils_2 = require("./utils");
36
35
  const weth = __importStar(require("./weth"));
37
36
  const yearn = __importStar(require("./yearn"));
38
37
  const zrx = __importStar(require("./zrx"));
@@ -51,28 +50,19 @@ class TransactionParser {
51
50
  this.yearn = new yearn.Parser({ provider, chainId: this.chainId });
52
51
  this.foxy = new foxy.Parser();
53
52
  this.weth = new weth.Parser({ chainId: this.chainId, provider });
54
- this.parsers = [this.zrx, this.thor, this.uniV2, this.yearn, this.foxy, this.weth];
53
+ // order here matters currently as weth and yearn have the same sigHash for deposit() and the weth parser is stricter resulting in faster processing times
54
+ this.parsers = [this.zrx, this.thor, this.uniV2, this.weth, this.foxy, this.yearn];
55
55
  }
56
- // return any addresses that can be detected
57
- getInternalAddress(inputData) {
58
- switch ((0, utils_2.getSigHash)(inputData)) {
59
- case this.thor.supportedFunctions.transferOutSigHash:
60
- return this.thor.getInternalAddress(inputData);
61
- case utils_2.SENDMULTISIG_SIG_HASH:
62
- return (0, utils_2.getInternalMultisigAddress)(inputData);
63
- default:
64
- return;
65
- }
66
- }
67
- async parse(tx, address, internalTxs) {
56
+ async parse(tx, address) {
68
57
  var _a;
58
+ address = ethers_1.ethers.utils.getAddress(address);
69
59
  // We expect only one Parser to return a result. If multiple do, we take the first and early exit.
70
60
  const contractParserResult = await (0, utils_1.findAsyncSequential)(this.parsers, async (parser) => await parser.parse(tx));
71
61
  const parsedTx = {
72
62
  address,
73
63
  blockHash: tx.blockHash,
74
64
  blockHeight: tx.blockHeight,
75
- blockTime: tx.blockTime,
65
+ blockTime: tx.timestamp,
76
66
  chainId: this.chainId,
77
67
  confirmations: tx.confirmations,
78
68
  status: TransactionParser.getStatus(tx),
@@ -81,11 +71,10 @@ class TransactionParser {
81
71
  txid: tx.txid,
82
72
  data: contractParserResult === null || contractParserResult === void 0 ? void 0 : contractParserResult.data
83
73
  };
84
- return this.getParsedTxWithTransfers(tx, parsedTx, address, internalTxs);
74
+ return this.getParsedTxWithTransfers(tx, parsedTx, address);
85
75
  }
86
76
  static getStatus(tx) {
87
- var _a;
88
- const status = (_a = tx.ethereumSpecific) === null || _a === void 0 ? void 0 : _a.status;
77
+ const status = tx.status;
89
78
  if (status === -1 && tx.confirmations <= 0)
90
79
  return types_1.Status.Pending;
91
80
  if (status === 1 && tx.confirmations > 0)
@@ -94,37 +83,35 @@ class TransactionParser {
94
83
  return types_1.Status.Failed;
95
84
  return types_1.Status.Unknown;
96
85
  }
97
- getParsedTxWithTransfers(tx, parsedTx, address, internalTxs) {
98
- var _a, _b, _c, _d, _e, _f;
99
- const sendAddress = (_b = (_a = tx.vin[0].addresses) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : '';
100
- const receiveAddress = (_d = (_c = tx.vout[0].addresses) === null || _c === void 0 ? void 0 : _c[0]) !== null && _d !== void 0 ? _d : '';
101
- if (address === sendAddress) {
86
+ getParsedTxWithTransfers(tx, parsedTx, address) {
87
+ var _a, _b;
88
+ if (address === tx.from) {
102
89
  // send amount
103
90
  const sendValue = new bignumber_js_1.BigNumber(tx.value);
104
91
  if (sendValue.gt(0)) {
105
- parsedTx.transfers = (0, utils_1.aggregateTransfer)(parsedTx.transfers, types_1.TransferType.Send, this.assetId, sendAddress, receiveAddress, sendValue.toString(10));
92
+ parsedTx.transfers = (0, utils_1.aggregateTransfer)(parsedTx.transfers, types_1.TransferType.Send, this.assetId, tx.from, tx.to, sendValue.toString(10));
106
93
  }
107
94
  // network fee
108
- const fees = new bignumber_js_1.BigNumber((_e = tx.fees) !== null && _e !== void 0 ? _e : 0);
95
+ const fees = new bignumber_js_1.BigNumber(tx.fee);
109
96
  if (fees.gt(0)) {
110
97
  parsedTx.fee = { assetId: this.assetId, value: fees.toString(10) };
111
98
  }
112
99
  }
113
- if (address === receiveAddress) {
100
+ if (address === tx.to) {
114
101
  // receive amount
115
102
  const receiveValue = new bignumber_js_1.BigNumber(tx.value);
116
103
  if (receiveValue.gt(0)) {
117
- parsedTx.transfers = (0, utils_1.aggregateTransfer)(parsedTx.transfers, types_1.TransferType.Receive, this.assetId, sendAddress, receiveAddress, receiveValue.toString(10));
104
+ parsedTx.transfers = (0, utils_1.aggregateTransfer)(parsedTx.transfers, types_1.TransferType.Receive, this.assetId, tx.from, tx.to, receiveValue.toString(10));
118
105
  }
119
106
  }
120
- (_f = tx.tokenTransfers) === null || _f === void 0 ? void 0 : _f.forEach((transfer) => {
107
+ (_a = tx.tokenTransfers) === null || _a === void 0 ? void 0 : _a.forEach((transfer) => {
121
108
  // FTX Token (FTT) name and symbol was set backwards on the ERC20 contract
122
- if (transfer.token === '0x50D1c9771902476076eCFc8B2A83Ad6b9355a4c9') {
109
+ if (transfer.contract === '0x50D1c9771902476076eCFc8B2A83Ad6b9355a4c9') {
123
110
  transfer.name = transfer.symbol;
124
111
  transfer.symbol = transfer.name;
125
112
  }
126
113
  const token = {
127
- contract: transfer.token,
114
+ contract: transfer.contract,
128
115
  decimals: transfer.decimals,
129
116
  name: transfer.name,
130
117
  symbol: transfer.symbol
@@ -133,7 +120,7 @@ class TransactionParser {
133
120
  (0, caip_1.toAssetId)({
134
121
  ...(0, caip_1.fromChainId)(this.chainId),
135
122
  assetNamespace: 'erc20',
136
- assetReference: transfer.token
123
+ assetReference: transfer.contract
137
124
  }),
138
125
  transfer.from,
139
126
  transfer.to,
@@ -149,7 +136,7 @@ class TransactionParser {
149
136
  parsedTx.transfers = (0, utils_1.aggregateTransfer)(parsedTx.transfers, types_1.TransferType.Receive, ...transferArgs);
150
137
  }
151
138
  });
152
- internalTxs === null || internalTxs === void 0 ? void 0 : internalTxs.forEach((internalTx) => {
139
+ (_b = tx.internalTxs) === null || _b === void 0 ? void 0 : _b.forEach((internalTx) => {
153
140
  const transferArgs = [
154
141
  (0, caip_1.toAssetId)({
155
142
  ...(0, caip_1.fromChainId)(this.chainId),
@@ -1,6 +1,6 @@
1
- import { Tx as BlockbookTx } from '@shapeshiftoss/blockbook';
2
1
  import { ChainId } from '@shapeshiftoss/caip';
3
2
  import { ethers } from 'ethers';
3
+ import { EthereumTx } from '../../generated/ethereum';
4
4
  import { SubParser, TxSpecific } from '../types';
5
5
  export interface ParserArgs {
6
6
  chainId: ChainId;
@@ -14,6 +14,5 @@ export declare class Parser implements SubParser {
14
14
  transferOutSigHash: string;
15
15
  };
16
16
  constructor(args: ParserArgs);
17
- getInternalAddress(inputData: string): string | undefined;
18
- parse(tx: BlockbookTx): Promise<TxSpecific | undefined>;
17
+ parse(tx: EthereumTx): Promise<TxSpecific | undefined>;
19
18
  }
@@ -30,27 +30,15 @@ class Parser {
30
30
  throw new Error('chainId is not supported. (supported chainIds: eip155:1, eip155:3)');
31
31
  }
32
32
  }
33
- // detect address associated with transferOut internal transaction
34
- getInternalAddress(inputData) {
35
- if ((0, utils_1.getSigHash)(inputData) !== this.supportedFunctions.transferOutSigHash)
36
- return;
37
- const result = this.abiInterface.decodeFunctionData(this.supportedFunctions.transferOutSigHash, inputData);
38
- const [type] = result.memo.split(':');
39
- if (type !== 'OUT' || type !== 'REFUND')
40
- return;
41
- return result.to;
42
- }
43
33
  async parse(tx) {
44
- var _a;
45
- const txData = (_a = tx.ethereumSpecific) === null || _a === void 0 ? void 0 : _a.data;
46
34
  if (!(0, utils_1.txInteractsWithContract)(tx, this.routerContract))
47
35
  return;
48
- if (!txData)
36
+ if (!tx.inputData)
49
37
  return;
50
- const txSigHash = (0, utils_1.getSigHash)(txData);
38
+ const txSigHash = (0, utils_1.getSigHash)(tx.inputData);
51
39
  if (!Object.values(this.supportedFunctions).some((hash) => hash === txSigHash))
52
40
  return;
53
- const decoded = this.abiInterface.parseTransaction({ data: txData });
41
+ const decoded = this.abiInterface.parseTransaction({ data: tx.inputData });
54
42
  // failed to decode input data
55
43
  if (!decoded)
56
44
  return;
@@ -1,6 +1,6 @@
1
- import { Tx as BlockbookTx } from '@shapeshiftoss/blockbook';
2
1
  import { ChainId } from '@shapeshiftoss/caip';
3
2
  import { ethers } from 'ethers';
3
+ import { EthereumTx } from '../../generated/ethereum';
4
4
  import { SubParser, TxSpecific } from '../types';
5
5
  export interface ParserArgs {
6
6
  chainId: ChainId;
@@ -21,8 +21,8 @@ export declare class Parser implements SubParser {
21
21
  exitSigHash: string;
22
22
  };
23
23
  constructor(args: ParserArgs);
24
- parseUniV2(tx: BlockbookTx): Promise<TxSpecific | undefined>;
25
- parseStakingRewards(tx: BlockbookTx): Promise<TxSpecific | undefined>;
26
- parse(tx: BlockbookTx): Promise<TxSpecific | undefined>;
24
+ parseUniV2(tx: EthereumTx): Promise<TxSpecific | undefined>;
25
+ parseStakingRewards(tx: EthereumTx): Promise<TxSpecific | undefined>;
26
+ parse(tx: EthereumTx): Promise<TxSpecific | undefined>;
27
27
  private static pairFor;
28
28
  }
@@ -38,24 +38,21 @@ class Parser {
38
38
  }
39
39
  }
40
40
  async parseUniV2(tx) {
41
- var _a, _b, _c;
42
- const txData = (_a = tx.ethereumSpecific) === null || _a === void 0 ? void 0 : _a.data;
43
- if (!txData)
41
+ if (!tx.inputData)
44
42
  return;
45
43
  if (tx.confirmations)
46
44
  return;
47
- const txSigHash = (0, utils_1.getSigHash)(txData);
45
+ const txSigHash = (0, utils_1.getSigHash)(tx.inputData);
48
46
  if (!Object.values(this.supportedFunctions).some((hash) => hash === txSigHash))
49
47
  return;
50
- const decoded = this.abiInterface.parseTransaction({ data: txData });
48
+ const decoded = this.abiInterface.parseTransaction({ data: tx.inputData });
51
49
  // failed to decode input data
52
50
  if (!decoded)
53
51
  return;
54
- const sendAddress = (_c = (_b = tx.vin[0].addresses) === null || _b === void 0 ? void 0 : _b[0]) !== null && _c !== void 0 ? _c : '';
55
52
  const tokenAddress = ethers_1.ethers.utils.getAddress(decoded.args.token.toLowerCase());
56
53
  const lpTokenAddress = Parser.pairFor(tokenAddress, this.wethContract);
57
54
  const transfers = await (async () => {
58
- switch ((0, utils_1.getSigHash)(txData)) {
55
+ switch ((0, utils_1.getSigHash)(tx.inputData)) {
59
56
  case this.supportedFunctions.addLiquidityEthSigHash: {
60
57
  const contract = new ethers_1.ethers.Contract(tokenAddress, erc20_1.default, this.provider);
61
58
  const decimals = await contract.decimals();
@@ -70,7 +67,7 @@ class Parser {
70
67
  return [
71
68
  {
72
69
  type: types_1.TransferType.Send,
73
- from: sendAddress,
70
+ from: tx.from,
74
71
  to: lpTokenAddress,
75
72
  assetId,
76
73
  totalValue: value,
@@ -93,7 +90,7 @@ class Parser {
93
90
  return [
94
91
  {
95
92
  type: types_1.TransferType.Send,
96
- from: sendAddress,
93
+ from: tx.from,
97
94
  to: lpTokenAddress,
98
95
  assetId,
99
96
  totalValue: value,
@@ -118,14 +115,12 @@ class Parser {
118
115
  };
119
116
  }
120
117
  async parseStakingRewards(tx) {
121
- var _a;
122
- const txData = (_a = tx.ethereumSpecific) === null || _a === void 0 ? void 0 : _a.data;
123
- if (!txData)
118
+ if (!tx.inputData)
124
119
  return;
125
- const txSigHash = (0, utils_1.getSigHash)(txData);
120
+ const txSigHash = (0, utils_1.getSigHash)(tx.inputData);
126
121
  if (!Object.values(this.supportedStakingRewardsFunctions).some((hash) => hash === txSigHash))
127
122
  return;
128
- const decoded = this.stakingRewardsInterface.parseTransaction({ data: txData });
123
+ const decoded = this.stakingRewardsInterface.parseTransaction({ data: tx.inputData });
129
124
  // failed to decode input data
130
125
  if (!decoded)
131
126
  return;
@@ -1,5 +1,3 @@
1
- import { Tx as BlockbookTx } from '@shapeshiftoss/blockbook';
1
+ import { EthereumTx } from '../../generated/ethereum';
2
2
  export declare const getSigHash: (inputData: string | undefined) => string | undefined;
3
- export declare const txInteractsWithContract: (tx: BlockbookTx, contract: string) => boolean;
4
- export declare const SENDMULTISIG_SIG_HASH: string;
5
- export declare const getInternalMultisigAddress: (inputData: string) => string | undefined;
3
+ export declare const txInteractsWithContract: (tx: EthereumTx, contract: string) => boolean;
@@ -1,11 +1,6 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getInternalMultisigAddress = exports.SENDMULTISIG_SIG_HASH = exports.txInteractsWithContract = exports.getSigHash = void 0;
7
- const ethers_1 = require("ethers");
8
- const multiSig_1 = __importDefault(require("./abi/multiSig"));
3
+ exports.txInteractsWithContract = exports.getSigHash = void 0;
9
4
  const getSigHash = (inputData) => {
10
5
  if (!inputData)
11
6
  return;
@@ -14,21 +9,6 @@ const getSigHash = (inputData) => {
14
9
  };
15
10
  exports.getSigHash = getSigHash;
16
11
  const txInteractsWithContract = (tx, contract) => {
17
- var _a, _b;
18
- const receiveAddress = (_b = (_a = tx.vout[0].addresses) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : '';
19
- return receiveAddress === contract;
12
+ return tx.to === contract;
20
13
  };
21
14
  exports.txInteractsWithContract = txInteractsWithContract;
22
- exports.SENDMULTISIG_SIG_HASH = (() => {
23
- const abiInterface = new ethers_1.ethers.utils.Interface(multiSig_1.default);
24
- return abiInterface.getSighash('sendMultiSig');
25
- })();
26
- // detect address associated with sendMultiSig internal transaction
27
- const getInternalMultisigAddress = (inputData) => {
28
- const abiInterface = new ethers_1.ethers.utils.Interface(multiSig_1.default);
29
- if ((0, exports.getSigHash)(inputData) !== exports.SENDMULTISIG_SIG_HASH)
30
- return;
31
- const result = abiInterface.decodeFunctionData(exports.SENDMULTISIG_SIG_HASH, inputData);
32
- return result.toAddress;
33
- };
34
- exports.getInternalMultisigAddress = getInternalMultisigAddress;
@@ -1,6 +1,6 @@
1
- import { Tx as BlockbookTx } from '@shapeshiftoss/blockbook';
2
1
  import { ChainId } from '@shapeshiftoss/caip';
3
2
  import { ethers } from 'ethers';
3
+ import { EthereumTx } from '../../generated/ethereum';
4
4
  import { SubParser, TxSpecific } from '../types';
5
5
  export interface ParserArgs {
6
6
  chainId: ChainId;
@@ -8,6 +8,7 @@ export interface ParserArgs {
8
8
  }
9
9
  export declare class Parser implements SubParser {
10
10
  provider: ethers.providers.JsonRpcProvider;
11
+ readonly name = "weth";
11
12
  readonly chainId: ChainId;
12
13
  readonly wethContract: string;
13
14
  readonly abiInterface: ethers.utils.Interface;
@@ -16,5 +17,5 @@ export declare class Parser implements SubParser {
16
17
  withdrawalSigHash: string;
17
18
  };
18
19
  constructor(args: ParserArgs);
19
- parse(tx: BlockbookTx): Promise<TxSpecific | undefined>;
20
+ parse(tx: EthereumTx): Promise<TxSpecific | undefined>;
20
21
  }
@@ -7,12 +7,12 @@ exports.Parser = void 0;
7
7
  const caip_1 = require("@shapeshiftoss/caip");
8
8
  const ethers_1 = require("ethers");
9
9
  const types_1 = require("../../types");
10
- const erc20_1 = __importDefault(require("./abi/erc20"));
11
10
  const weth_1 = __importDefault(require("./abi/weth"));
12
11
  const constants_1 = require("./constants");
13
12
  const utils_1 = require("./utils");
14
13
  class Parser {
15
14
  constructor(args) {
15
+ this.name = 'weth';
16
16
  this.abiInterface = new ethers_1.ethers.utils.Interface(weth_1.default);
17
17
  this.supportedFunctions = {
18
18
  depositSigHash: this.abiInterface.getSighash('deposit'),
@@ -32,21 +32,17 @@ class Parser {
32
32
  }
33
33
  }
34
34
  async parse(tx) {
35
- var _a, _b, _c;
36
- const txData = (_a = tx.ethereumSpecific) === null || _a === void 0 ? void 0 : _a.data;
37
35
  if (!(0, utils_1.txInteractsWithContract)(tx, this.wethContract))
38
36
  return;
39
- if (!txData)
37
+ if (!tx.inputData)
40
38
  return;
41
- const txSigHash = (0, utils_1.getSigHash)(txData);
39
+ const txSigHash = (0, utils_1.getSigHash)(tx.inputData);
42
40
  if (!Object.values(this.supportedFunctions).some((hash) => hash === txSigHash))
43
41
  return;
44
- const decoded = this.abiInterface.parseTransaction({ data: txData });
42
+ const decoded = this.abiInterface.parseTransaction({ data: tx.inputData });
45
43
  // failed to decode input data
46
44
  if (!decoded)
47
45
  return;
48
- const sendAddress = (_c = (_b = tx.vin[0].addresses) === null || _b === void 0 ? void 0 : _b[0]) !== null && _c !== void 0 ? _c : '';
49
- const contract = new ethers_1.ethers.Contract(this.wethContract, erc20_1.default, this.provider);
50
46
  const assetId = (0, caip_1.toAssetId)({
51
47
  ...(0, caip_1.fromChainId)(this.chainId),
52
48
  assetNamespace: 'erc20',
@@ -54,9 +50,9 @@ class Parser {
54
50
  });
55
51
  const token = {
56
52
  contract: this.wethContract,
57
- decimals: await contract.decimals(),
58
- name: await contract.name(),
59
- symbol: await contract.symbol()
53
+ decimals: 18,
54
+ name: 'Wrapped Ether',
55
+ symbol: 'WETH'
60
56
  };
61
57
  const transfers = (() => {
62
58
  switch (txSigHash) {
@@ -65,7 +61,7 @@ class Parser {
65
61
  {
66
62
  type: types_1.TransferType.Receive,
67
63
  from: this.wethContract,
68
- to: sendAddress,
64
+ to: tx.from,
69
65
  assetId,
70
66
  totalValue: tx.value,
71
67
  components: [{ value: tx.value }],
@@ -77,7 +73,7 @@ class Parser {
77
73
  return [
78
74
  {
79
75
  type: types_1.TransferType.Send,
80
- from: sendAddress,
76
+ from: tx.from,
81
77
  to: this.wethContract,
82
78
  assetId,
83
79
  totalValue: decoded.args.wad.toString(),
@@ -1,7 +1,7 @@
1
- import { Tx as BlockbookTx } from '@shapeshiftoss/blockbook';
2
1
  import { ChainId } from '@shapeshiftoss/caip';
3
2
  import { ChainId as YearnChainId, Yearn } from '@yfi/sdk';
4
3
  import { ethers } from 'ethers';
4
+ import { EthereumTx } from '../../generated/ethereum';
5
5
  import { SubParser, TxSpecific } from '../types';
6
6
  interface ParserArgs {
7
7
  chainId: ChainId;
@@ -24,7 +24,7 @@ export declare class Parser implements SubParser {
24
24
  depositSigHash: string;
25
25
  };
26
26
  constructor(args: ParserArgs);
27
- parse(tx: BlockbookTx): Promise<TxSpecific | undefined>;
27
+ parse(tx: EthereumTx): Promise<TxSpecific | undefined>;
28
28
  getAbiInterface(txSigHash: string | undefined): ethers.utils.Interface | undefined;
29
29
  }
30
30
  export {};
@@ -33,37 +33,35 @@ class Parser {
33
33
  }
34
34
  }
35
35
  async parse(tx) {
36
- var _a, _b, _c, _d, _e;
37
- const txData = (_a = tx.ethereumSpecific) === null || _a === void 0 ? void 0 : _a.data;
38
- if (!txData)
36
+ var _a, _b;
37
+ if (!tx.inputData)
39
38
  return;
40
- const txSigHash = (0, utils_1.getSigHash)(txData);
39
+ const txSigHash = (0, utils_1.getSigHash)(tx.inputData);
41
40
  const abiInterface = this.getAbiInterface(txSigHash);
42
41
  if (!abiInterface)
43
42
  return;
44
43
  if (!this.yearnTokenVaultAddresses) {
45
- const vaults = await ((_b = this.yearnSdk) === null || _b === void 0 ? void 0 : _b.vaults.get());
44
+ const vaults = await ((_a = this.yearnSdk) === null || _a === void 0 ? void 0 : _a.vaults.get());
46
45
  this.yearnTokenVaultAddresses = vaults === null || vaults === void 0 ? void 0 : vaults.map((vault) => vault.address);
47
46
  }
48
- const decoded = abiInterface.parseTransaction({ data: txData });
47
+ const decoded = abiInterface.parseTransaction({ data: tx.inputData });
49
48
  // failed to decode input data
50
49
  if (!decoded)
51
50
  return;
52
- const receiveAddress = (_d = (_c = tx.vout) === null || _c === void 0 ? void 0 : _c[0].addresses) === null || _d === void 0 ? void 0 : _d[0];
53
51
  switch (txSigHash) {
54
52
  case this.supportedYearnFunctions.approveSigHash:
55
53
  if ((decoded === null || decoded === void 0 ? void 0 : decoded.args._spender) !== constants_1.SHAPE_SHIFT_ROUTER_CONTRACT)
56
54
  return;
57
55
  break;
58
56
  case this.supportedShapeShiftFunctions.depositSigHash:
59
- if (receiveAddress !== constants_1.SHAPE_SHIFT_ROUTER_CONTRACT)
57
+ if (tx.to !== constants_1.SHAPE_SHIFT_ROUTER_CONTRACT)
60
58
  return;
61
59
  break;
62
60
  case this.supportedYearnFunctions.withdrawSigHash:
63
61
  case this.supportedYearnFunctions.depositSigHash:
64
62
  case this.supportedYearnFunctions.depositAmountSigHash:
65
63
  case this.supportedYearnFunctions.depositAmountAndRecipientSigHash:
66
- if (receiveAddress && !((_e = this.yearnTokenVaultAddresses) === null || _e === void 0 ? void 0 : _e.includes(receiveAddress)))
64
+ if (tx.to && !((_b = this.yearnTokenVaultAddresses) === null || _b === void 0 ? void 0 : _b.includes(tx.to)))
67
65
  return;
68
66
  break;
69
67
  default:
@@ -1,5 +1,5 @@
1
- import { Tx as BlockbookTx } from '@shapeshiftoss/blockbook';
1
+ import { EthereumTx } from '../../generated/ethereum';
2
2
  import { SubParser, TxSpecific } from '../types';
3
3
  export declare class Parser implements SubParser {
4
- parse(tx: BlockbookTx): Promise<TxSpecific | undefined>;
4
+ parse(tx: EthereumTx): Promise<TxSpecific | undefined>;
5
5
  }
@@ -1,25 +1,9 @@
1
- import { Tx as BlockbookTx } from '@shapeshiftoss/blockbook';
1
+ import { EthereumTx } from '../generated/ethereum';
2
2
  import { StandardTx, StandardTxMetadata } from '../types';
3
- export interface InternalTx {
4
- blockNumber: string;
5
- timeStamp: string;
6
- hash: string;
7
- from: string;
8
- to: string;
9
- value: string;
10
- contractAddress: string;
11
- input: string;
12
- type: string;
13
- gas: string;
14
- gasUsed: string;
15
- traceId: string;
16
- isError: string;
17
- errCode: string;
18
- }
19
3
  export interface ParsedTx extends StandardTx {
20
4
  data?: StandardTxMetadata;
21
5
  }
22
6
  export declare type TxSpecific = Partial<Pick<ParsedTx, 'trade' | 'transfers' | 'data'>>;
23
7
  export interface SubParser {
24
- parse(tx: BlockbookTx): Promise<TxSpecific | undefined>;
8
+ parse(tx: EthereumTx): Promise<TxSpecific | undefined>;
25
9
  }