@shapeshiftoss/unchained-client 6.12.1 → 8.0.1

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,12 +1,13 @@
1
1
  import { Tx as BlockbookTx } from '@shapeshiftoss/blockbook';
2
+ import { AssetId, ChainId } from '@shapeshiftoss/caip';
2
3
  import { Tx as ParsedTx } from '../../types';
3
- import { Network } from '../types';
4
4
  export interface TransactionParserArgs {
5
- network?: Network;
5
+ chainId: ChainId;
6
6
  rpcUrl: string;
7
7
  }
8
8
  export declare class TransactionParser {
9
- network: Network;
9
+ chainId: ChainId;
10
+ assetId: AssetId;
10
11
  constructor(args: TransactionParserArgs);
11
12
  parse(tx: BlockbookTx, address: string): Promise<ParsedTx>;
12
13
  }
@@ -2,32 +2,27 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TransactionParser = void 0;
4
4
  const caip_1 = require("@shapeshiftoss/caip");
5
- const types_1 = require("@shapeshiftoss/types");
6
5
  const bignumber_js_1 = require("bignumber.js");
7
- const types_2 = require("../../types");
6
+ const types_1 = require("../../types");
8
7
  const utils_1 = require("../../utils");
9
- const utils_2 = require("./utils");
10
8
  class TransactionParser {
11
9
  constructor(args) {
12
- var _a;
13
- this.network = (_a = args.network) !== null && _a !== void 0 ? _a : 'mainnet';
10
+ this.chainId = args.chainId;
11
+ this.assetId = (0, caip_1.toAssetId)({
12
+ ...(0, caip_1.fromChainId)(this.chainId),
13
+ assetNamespace: 'slip44',
14
+ assetReference: caip_1.ASSET_REFERENCE.Bitcoin
15
+ });
14
16
  }
15
17
  async parse(tx, address) {
16
- const caip19Bitcoin = (0, caip_1.toCAIP19)({
17
- chain: types_1.ChainTypes.Bitcoin,
18
- network: (0, utils_2.toNetworkType)(this.network),
19
- assetNamespace: caip_1.AssetNamespace.Slip44,
20
- assetReference: caip_1.AssetReference.Bitcoin
21
- });
22
18
  const parsedTx = {
23
19
  address,
24
20
  blockHash: tx.blockHash,
25
21
  blockHeight: tx.blockHeight,
26
22
  blockTime: tx.blockTime,
27
- caip2: (0, caip_1.toCAIP2)({ chain: types_1.ChainTypes.Bitcoin, network: (0, utils_2.toNetworkType)(this.network) }),
28
- chainId: (0, caip_1.toCAIP2)({ chain: types_1.ChainTypes.Bitcoin, network: (0, utils_2.toNetworkType)(this.network) }),
23
+ chainId: this.chainId,
29
24
  confirmations: tx.confirmations,
30
- status: tx.confirmations > 0 ? types_2.Status.Confirmed : types_2.Status.Pending,
25
+ status: tx.confirmations > 0 ? types_1.Status.Confirmed : types_1.Status.Pending,
31
26
  transfers: [],
32
27
  txid: tx.txid
33
28
  };
@@ -37,12 +32,12 @@ class TransactionParser {
37
32
  // send amount
38
33
  const sendValue = new bignumber_js_1.BigNumber((_b = vin.value) !== null && _b !== void 0 ? _b : 0);
39
34
  if (sendValue.gt(0)) {
40
- parsedTx.transfers = (0, utils_1.aggregateTransfer)(parsedTx.transfers, types_2.TransferType.Send, caip19Bitcoin, (_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));
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));
41
36
  }
42
37
  // network fee
43
38
  const fees = new bignumber_js_1.BigNumber((_g = tx.fees) !== null && _g !== void 0 ? _g : 0);
44
39
  if (fees.gt(0)) {
45
- parsedTx.fee = { caip19: caip19Bitcoin, assetId: caip19Bitcoin, value: fees.toString(10) };
40
+ parsedTx.fee = { assetId: this.assetId, value: fees.toString(10) };
46
41
  }
47
42
  }
48
43
  });
@@ -52,7 +47,7 @@ class TransactionParser {
52
47
  // receive amount
53
48
  const receiveValue = new bignumber_js_1.BigNumber((_b = vout.value) !== null && _b !== void 0 ? _b : 0);
54
49
  if (receiveValue.gt(0)) {
55
- parsedTx.transfers = (0, utils_1.aggregateTransfer)(parsedTx.transfers, types_2.TransferType.Receive, caip19Bitcoin, (_d = (_c = tx.vin[0].addresses) === null || _c === void 0 ? void 0 : _c[0]) !== null && _d !== void 0 ? _d : '', (_f = (_e = vout.addresses) === null || _e === void 0 ? void 0 : _e[0]) !== null && _f !== void 0 ? _f : '', receiveValue.toString(10));
50
+ parsedTx.transfers = (0, utils_1.aggregateTransfer)(parsedTx.transfers, types_1.TransferType.Receive, this.assetId, (_d = (_c = tx.vin[0].addresses) === null || _c === void 0 ? void 0 : _c[0]) !== null && _d !== void 0 ? _d : '', (_f = (_e = vout.addresses) === null || _e === void 0 ? void 0 : _e[0]) !== null && _f !== void 0 ? _f : '', receiveValue.toString(10));
56
51
  }
57
52
  }
58
53
  });
@@ -8,10 +8,10 @@ const utils_1 = require("./utils");
8
8
  class TransactionParser {
9
9
  constructor(args) {
10
10
  this.chainId = args.chainId;
11
- this.assetId = (0, caip_1.toCAIP19)({
12
- ...(0, caip_1.fromCAIP2)(this.chainId),
13
- assetNamespace: caip_1.AssetNamespace.Slip44,
14
- assetReference: caip_1.AssetReference.Cosmos
11
+ this.assetId = (0, caip_1.toAssetId)({
12
+ ...(0, caip_1.fromChainId)(this.chainId),
13
+ assetNamespace: 'slip44',
14
+ assetReference: caip_1.ASSET_REFERENCE.Cosmos
15
15
  });
16
16
  }
17
17
  async parse(tx, address) {
@@ -21,7 +21,6 @@ class TransactionParser {
21
21
  blockHash: tx.blockHash,
22
22
  blockHeight: (_a = tx.blockHeight) !== null && _a !== void 0 ? _a : -1,
23
23
  blockTime: (_b = tx.timestamp) !== null && _b !== void 0 ? _b : Math.floor(Date.now() / 1000),
24
- caip2: this.chainId,
25
24
  chainId: this.chainId,
26
25
  confirmations: tx.confirmations,
27
26
  status: tx.confirmations > 0 ? types_1.Status.Confirmed : types_1.Status.Pending,
@@ -36,7 +35,6 @@ class TransactionParser {
36
35
  parsedTx.transfers = [
37
36
  {
38
37
  type: types_1.TransferType.Send,
39
- caip19: this.assetId,
40
38
  assetId: this.assetId,
41
39
  from,
42
40
  to,
@@ -49,7 +47,6 @@ class TransactionParser {
49
47
  parsedTx.transfers = [
50
48
  {
51
49
  type: types_1.TransferType.Receive,
52
- caip19: this.assetId,
53
50
  assetId: this.assetId,
54
51
  from,
55
52
  to,
@@ -63,7 +60,7 @@ class TransactionParser {
63
60
  // network fee
64
61
  const fees = new bignumber_js_1.BigNumber(tx.fee.amount);
65
62
  if (fees.gt(0)) {
66
- parsedTx.fee = { caip19: this.assetId, assetId: this.assetId, value: fees.toString(10) };
63
+ parsedTx.fee = { assetId: this.assetId, value: fees.toString(10) };
67
64
  }
68
65
  }
69
66
  return parsedTx;
@@ -32,7 +32,6 @@ const metaData = (msg, assetId) => {
32
32
  delegator: msg.origin,
33
33
  destinationValidator: msg.to,
34
34
  value: (_b = msg === null || msg === void 0 ? void 0 : msg.value) === null || _b === void 0 ? void 0 : _b.amount,
35
- caip19: assetId,
36
35
  assetId
37
36
  };
38
37
  case 'withdraw_delegator_reward':
@@ -41,7 +40,6 @@ const metaData = (msg, assetId) => {
41
40
  method: msg.type,
42
41
  destinationValidator: msg.to,
43
42
  value: (_c = msg === null || msg === void 0 ? void 0 : msg.value) === null || _c === void 0 ? void 0 : _c.amount,
44
- caip19: assetId,
45
43
  assetId
46
44
  };
47
45
  case 'ibc_send':
@@ -51,7 +49,6 @@ const metaData = (msg, assetId) => {
51
49
  method: msg.type,
52
50
  ibcDestination: msg.to,
53
51
  ibcSource: msg.from,
54
- caip19: assetId,
55
52
  assetId,
56
53
  value: (_d = msg === null || msg === void 0 ? void 0 : msg.value) === null || _d === void 0 ? void 0 : _d.amount
57
54
  };
@@ -4,10 +4,6 @@ export interface TxMetadata extends Omit<StandardTxMetadata, 'parser'> {
4
4
  delegator?: string;
5
5
  sourceValidator?: string;
6
6
  destinationValidator?: string;
7
- /**
8
- * @deprecated use 'assetId' instead
9
- */
10
- caip19?: string;
11
7
  assetId?: string;
12
8
  value?: string;
13
9
  ibcDestination?: string;
@@ -1,11 +1,13 @@
1
1
  import { Tx as BlockbookTx } from '@shapeshiftoss/blockbook';
2
- import { InternalTx, Network, ParsedTx } from '../types';
2
+ import { AssetId, ChainId } from '@shapeshiftoss/caip';
3
+ import { InternalTx, ParsedTx } from '../types';
3
4
  export interface TransactionParserArgs {
4
- network?: Network;
5
+ chainId: ChainId;
5
6
  rpcUrl: string;
6
7
  }
7
8
  export declare class TransactionParser {
8
- network: Network;
9
+ chainId: ChainId;
10
+ assetId: AssetId;
9
11
  private readonly thor;
10
12
  private readonly uniV2;
11
13
  private readonly zrx;
@@ -25,10 +25,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.TransactionParser = void 0;
27
27
  const caip_1 = require("@shapeshiftoss/caip");
28
- const types_1 = require("@shapeshiftoss/types");
29
28
  const bignumber_js_1 = require("bignumber.js");
30
29
  const ethers_1 = require("ethers");
31
- const types_2 = require("../../types");
30
+ const types_1 = require("../../types");
32
31
  const utils_1 = require("../../utils");
33
32
  const foxy = __importStar(require("./foxy"));
34
33
  const thor = __importStar(require("./thor"));
@@ -39,15 +38,19 @@ const yearn = __importStar(require("./yearn"));
39
38
  const zrx = __importStar(require("./zrx"));
40
39
  class TransactionParser {
41
40
  constructor(args) {
42
- var _a;
41
+ this.chainId = args.chainId;
42
+ this.assetId = (0, caip_1.toAssetId)({
43
+ ...(0, caip_1.fromChainId)(this.chainId),
44
+ assetNamespace: 'slip44',
45
+ assetReference: caip_1.ASSET_REFERENCE.Ethereum
46
+ });
43
47
  const provider = new ethers_1.ethers.providers.JsonRpcProvider(args.rpcUrl);
44
- this.network = (_a = args.network) !== null && _a !== void 0 ? _a : 'mainnet';
45
- this.thor = new thor.Parser({ network: this.network, rpcUrl: args.rpcUrl });
46
- this.uniV2 = new uniV2.Parser({ network: this.network, provider });
48
+ this.thor = new thor.Parser({ chainId: this.chainId, rpcUrl: args.rpcUrl });
49
+ this.uniV2 = new uniV2.Parser({ chainId: this.chainId, provider });
47
50
  this.zrx = new zrx.Parser();
48
- this.yearn = new yearn.Parser({ provider, network: this.network });
51
+ this.yearn = new yearn.Parser({ provider, chainId: this.chainId });
49
52
  this.foxy = new foxy.Parser();
50
- this.weth = new weth.Parser({ network: this.network, provider });
53
+ this.weth = new weth.Parser({ chainId: this.chainId, provider });
51
54
  this.parsers = [this.zrx, this.thor, this.uniV2, this.yearn, this.foxy, this.weth];
52
55
  }
53
56
  // return any addresses that can be detected
@@ -70,8 +73,7 @@ class TransactionParser {
70
73
  blockHash: tx.blockHash,
71
74
  blockHeight: tx.blockHeight,
72
75
  blockTime: tx.blockTime,
73
- caip2: (0, caip_1.toCAIP2)({ chain: types_1.ChainTypes.Ethereum, network: (0, utils_2.toNetworkType)(this.network) }),
74
- chainId: (0, caip_1.toCAIP2)({ chain: types_1.ChainTypes.Ethereum, network: (0, utils_2.toNetworkType)(this.network) }),
76
+ chainId: this.chainId,
75
77
  confirmations: tx.confirmations,
76
78
  status: TransactionParser.getStatus(tx),
77
79
  trade: contractParserResult === null || contractParserResult === void 0 ? void 0 : contractParserResult.trade,
@@ -85,40 +87,34 @@ class TransactionParser {
85
87
  var _a;
86
88
  const status = (_a = tx.ethereumSpecific) === null || _a === void 0 ? void 0 : _a.status;
87
89
  if (status === -1 && tx.confirmations <= 0)
88
- return types_2.Status.Pending;
90
+ return types_1.Status.Pending;
89
91
  if (status === 1 && tx.confirmations > 0)
90
- return types_2.Status.Confirmed;
92
+ return types_1.Status.Confirmed;
91
93
  if (status === 0)
92
- return types_2.Status.Failed;
93
- return types_2.Status.Unknown;
94
+ return types_1.Status.Failed;
95
+ return types_1.Status.Unknown;
94
96
  }
95
97
  getParsedTxWithTransfers(tx, parsedTx, address, internalTxs) {
96
98
  var _a, _b, _c, _d, _e, _f;
97
- const caip19Ethereum = (0, caip_1.toCAIP19)({
98
- chain: types_1.ChainTypes.Ethereum,
99
- network: (0, utils_2.toNetworkType)(this.network),
100
- assetNamespace: caip_1.AssetNamespace.Slip44,
101
- assetReference: caip_1.AssetReference.Ethereum
102
- });
103
99
  const sendAddress = (_b = (_a = tx.vin[0].addresses) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : '';
104
100
  const receiveAddress = (_d = (_c = tx.vout[0].addresses) === null || _c === void 0 ? void 0 : _c[0]) !== null && _d !== void 0 ? _d : '';
105
101
  if (address === sendAddress) {
106
102
  // send amount
107
103
  const sendValue = new bignumber_js_1.BigNumber(tx.value);
108
104
  if (sendValue.gt(0)) {
109
- parsedTx.transfers = (0, utils_1.aggregateTransfer)(parsedTx.transfers, types_2.TransferType.Send, caip19Ethereum, sendAddress, receiveAddress, sendValue.toString(10));
105
+ parsedTx.transfers = (0, utils_1.aggregateTransfer)(parsedTx.transfers, types_1.TransferType.Send, this.assetId, sendAddress, receiveAddress, sendValue.toString(10));
110
106
  }
111
107
  // network fee
112
108
  const fees = new bignumber_js_1.BigNumber((_e = tx.fees) !== null && _e !== void 0 ? _e : 0);
113
109
  if (fees.gt(0)) {
114
- parsedTx.fee = { caip19: caip19Ethereum, assetId: caip19Ethereum, value: fees.toString(10) };
110
+ parsedTx.fee = { assetId: this.assetId, value: fees.toString(10) };
115
111
  }
116
112
  }
117
113
  if (address === receiveAddress) {
118
114
  // receive amount
119
115
  const receiveValue = new bignumber_js_1.BigNumber(tx.value);
120
116
  if (receiveValue.gt(0)) {
121
- parsedTx.transfers = (0, utils_1.aggregateTransfer)(parsedTx.transfers, types_2.TransferType.Receive, caip19Ethereum, sendAddress, receiveAddress, receiveValue.toString(10));
117
+ parsedTx.transfers = (0, utils_1.aggregateTransfer)(parsedTx.transfers, types_1.TransferType.Receive, this.assetId, sendAddress, receiveAddress, receiveValue.toString(10));
122
118
  }
123
119
  }
124
120
  (_f = tx.tokenTransfers) === null || _f === void 0 ? void 0 : _f.forEach((transfer) => {
@@ -134,10 +130,9 @@ class TransactionParser {
134
130
  symbol: transfer.symbol
135
131
  };
136
132
  const transferArgs = [
137
- (0, caip_1.toCAIP19)({
138
- chain: types_1.ChainTypes.Ethereum,
139
- network: (0, utils_2.toNetworkType)(this.network),
140
- assetNamespace: caip_1.AssetNamespace.ERC20,
133
+ (0, caip_1.toAssetId)({
134
+ ...(0, caip_1.fromChainId)(this.chainId),
135
+ assetNamespace: 'erc20',
141
136
  assetReference: transfer.token
142
137
  }),
143
138
  transfer.from,
@@ -147,20 +142,19 @@ class TransactionParser {
147
142
  ];
148
143
  // token send amount
149
144
  if (address === transfer.from) {
150
- parsedTx.transfers = (0, utils_1.aggregateTransfer)(parsedTx.transfers, types_2.TransferType.Send, ...transferArgs);
145
+ parsedTx.transfers = (0, utils_1.aggregateTransfer)(parsedTx.transfers, types_1.TransferType.Send, ...transferArgs);
151
146
  }
152
147
  // token receive amount
153
148
  if (address === transfer.to) {
154
- parsedTx.transfers = (0, utils_1.aggregateTransfer)(parsedTx.transfers, types_2.TransferType.Receive, ...transferArgs);
149
+ parsedTx.transfers = (0, utils_1.aggregateTransfer)(parsedTx.transfers, types_1.TransferType.Receive, ...transferArgs);
155
150
  }
156
151
  });
157
152
  internalTxs === null || internalTxs === void 0 ? void 0 : internalTxs.forEach((internalTx) => {
158
153
  const transferArgs = [
159
- (0, caip_1.toCAIP19)({
160
- chain: types_1.ChainTypes.Ethereum,
161
- network: (0, utils_2.toNetworkType)(this.network),
162
- assetNamespace: caip_1.AssetNamespace.Slip44,
163
- assetReference: caip_1.AssetReference.Ethereum
154
+ (0, caip_1.toAssetId)({
155
+ ...(0, caip_1.fromChainId)(this.chainId),
156
+ assetNamespace: 'slip44',
157
+ assetReference: caip_1.ASSET_REFERENCE.Ethereum
164
158
  }),
165
159
  internalTx.from,
166
160
  internalTx.to,
@@ -168,11 +162,11 @@ class TransactionParser {
168
162
  ];
169
163
  // internal eth send
170
164
  if (address === internalTx.from) {
171
- parsedTx.transfers = (0, utils_1.aggregateTransfer)(parsedTx.transfers, types_2.TransferType.Send, ...transferArgs);
165
+ parsedTx.transfers = (0, utils_1.aggregateTransfer)(parsedTx.transfers, types_1.TransferType.Send, ...transferArgs);
172
166
  }
173
167
  // internal eth receive
174
168
  if (address === internalTx.to) {
175
- parsedTx.transfers = (0, utils_1.aggregateTransfer)(parsedTx.transfers, types_2.TransferType.Receive, ...transferArgs);
169
+ parsedTx.transfers = (0, utils_1.aggregateTransfer)(parsedTx.transfers, types_1.TransferType.Receive, ...transferArgs);
176
170
  }
177
171
  });
178
172
  return parsedTx;
@@ -1,8 +1,9 @@
1
1
  import { Tx as BlockbookTx } from '@shapeshiftoss/blockbook';
2
+ import { ChainId } from '@shapeshiftoss/caip';
2
3
  import { ethers } from 'ethers';
3
- import { Network, SubParser, TxSpecific } from '../types';
4
+ import { SubParser, TxSpecific } from '../types';
4
5
  export interface ParserArgs {
5
- network: Network;
6
+ chainId: ChainId;
6
7
  rpcUrl: string;
7
8
  }
8
9
  export declare class Parser implements SubParser {
@@ -17,11 +17,18 @@ class Parser {
17
17
  depositSigHash: this.abiInterface.getSighash('deposit'),
18
18
  transferOutSigHash: this.abiInterface.getSighash('transferOut')
19
19
  };
20
- // TODO: Router contract can change, use /inbound_addresses endpoint to determine current router contract
21
- this.routerContract = {
22
- mainnet: constants_1.THOR_ROUTER_CONTRACT_MAINNET,
23
- ropsten: constants_1.THOR_ROUTER_CONTRACT_ROPSTEN
24
- }[args.network];
20
+ // TODO: Router contract can change, use /inbound_addresses endpoint to determine current router contract.
21
+ // We will also need to know all past router contract addresses if we intend on using receive address as the means for detection
22
+ switch (args.chainId) {
23
+ case 'eip155:1':
24
+ this.routerContract = constants_1.THOR_ROUTER_CONTRACT_MAINNET;
25
+ break;
26
+ case 'eip155:3':
27
+ this.routerContract = constants_1.THOR_ROUTER_CONTRACT_ROPSTEN;
28
+ break;
29
+ default:
30
+ throw new Error('chainId is not supported. (supported chainIds: eip155:1, eip155:3)');
31
+ }
25
32
  }
26
33
  // detect address associated with transferOut internal transaction
27
34
  getInternalAddress(inputData) {
@@ -1,13 +1,14 @@
1
1
  import { Tx as BlockbookTx } from '@shapeshiftoss/blockbook';
2
+ import { ChainId } from '@shapeshiftoss/caip';
2
3
  import { ethers } from 'ethers';
3
- import { Network, SubParser, TxSpecific } from '../types';
4
+ import { SubParser, TxSpecific } from '../types';
4
5
  export interface ParserArgs {
5
- network: Network;
6
+ chainId: ChainId;
6
7
  provider: ethers.providers.JsonRpcProvider;
7
8
  }
8
9
  export declare class Parser implements SubParser {
9
- network: Network;
10
10
  provider: ethers.providers.JsonRpcProvider;
11
+ readonly chainId: ChainId;
11
12
  readonly wethContract: string;
12
13
  readonly abiInterface: ethers.utils.Interface;
13
14
  readonly supportedFunctions: {
@@ -5,9 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Parser = void 0;
7
7
  const caip_1 = require("@shapeshiftoss/caip");
8
- const types_1 = require("@shapeshiftoss/types");
9
8
  const ethers_1 = require("ethers");
10
- const types_2 = require("../../types");
9
+ const types_1 = require("../../types");
11
10
  const erc20_1 = __importDefault(require("./abi/erc20"));
12
11
  const uniV2_1 = __importDefault(require("./abi/uniV2"));
13
12
  const constants_1 = require("./constants");
@@ -19,12 +18,18 @@ class Parser {
19
18
  addLiquidityEthSigHash: this.abiInterface.getSighash('addLiquidityETH'),
20
19
  removeLiquidityEthSigHash: this.abiInterface.getSighash('removeLiquidityETH')
21
20
  };
22
- this.network = args.network;
21
+ this.chainId = args.chainId;
23
22
  this.provider = args.provider;
24
- this.wethContract = {
25
- mainnet: constants_1.WETH_CONTRACT_MAINNET,
26
- ropsten: constants_1.WETH_CONTRACT_ROPSTEN
27
- }[this.network];
23
+ switch (args.chainId) {
24
+ case 'eip155:1':
25
+ this.wethContract = constants_1.WETH_CONTRACT_MAINNET;
26
+ break;
27
+ case 'eip155:3':
28
+ this.wethContract = constants_1.WETH_CONTRACT_ROPSTEN;
29
+ break;
30
+ default:
31
+ throw new Error('chainId is not supported. (supported chainIds: eip155:1, eip155:3)');
32
+ }
28
33
  }
29
34
  async parse(tx) {
30
35
  var _a, _b, _c;
@@ -53,18 +58,16 @@ class Parser {
53
58
  const name = await contract.name();
54
59
  const symbol = await contract.symbol();
55
60
  const value = decoded.args.amountTokenDesired.toString();
56
- const assetId = (0, caip_1.toCAIP19)({
57
- chain: types_1.ChainTypes.Ethereum,
58
- network: (0, utils_1.toNetworkType)(this.network),
59
- assetNamespace: caip_1.AssetNamespace.ERC20,
61
+ const assetId = (0, caip_1.toAssetId)({
62
+ ...(0, caip_1.fromChainId)(this.chainId),
63
+ assetNamespace: 'erc20',
60
64
  assetReference: tokenAddress
61
65
  });
62
66
  return [
63
67
  {
64
- type: types_2.TransferType.Send,
68
+ type: types_1.TransferType.Send,
65
69
  from: sendAddress,
66
70
  to: lpTokenAddress,
67
- caip19: assetId,
68
71
  assetId,
69
72
  totalValue: value,
70
73
  components: [{ value }],
@@ -78,18 +81,16 @@ class Parser {
78
81
  const name = await contract.name();
79
82
  const symbol = await contract.symbol();
80
83
  const value = decoded.args.liquidity.toString();
81
- const assetId = (0, caip_1.toCAIP19)({
82
- chain: types_1.ChainTypes.Ethereum,
83
- network: (0, utils_1.toNetworkType)(this.network),
84
- assetNamespace: caip_1.AssetNamespace.ERC20,
84
+ const assetId = (0, caip_1.toAssetId)({
85
+ ...(0, caip_1.fromChainId)(this.chainId),
86
+ assetNamespace: 'erc20',
85
87
  assetReference: lpTokenAddress
86
88
  });
87
89
  return [
88
90
  {
89
- type: types_2.TransferType.Send,
91
+ type: types_1.TransferType.Send,
90
92
  from: sendAddress,
91
93
  to: lpTokenAddress,
92
- caip19: assetId,
93
94
  assetId,
94
95
  totalValue: value,
95
96
  components: [{ value }],
@@ -107,7 +108,7 @@ class Parser {
107
108
  return {
108
109
  transfers,
109
110
  data: {
110
- parser: types_2.TxParser.UniV2,
111
+ parser: types_1.TxParser.UniV2,
111
112
  method: decoded.name
112
113
  }
113
114
  };
@@ -1,7 +1,4 @@
1
1
  import { Tx as BlockbookTx } from '@shapeshiftoss/blockbook';
2
- import { NetworkTypes } from '@shapeshiftoss/types';
3
- import { Network } from '../types';
4
- export declare const toNetworkType: (network: Network) => NetworkTypes;
5
2
  export declare const getSigHash: (inputData: string | undefined) => string | undefined;
6
3
  export declare const txInteractsWithContract: (tx: BlockbookTx, contract: string) => boolean;
7
4
  export declare const SENDMULTISIG_SIG_HASH: string;
@@ -3,21 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getInternalMultisigAddress = exports.SENDMULTISIG_SIG_HASH = exports.txInteractsWithContract = exports.getSigHash = exports.toNetworkType = void 0;
7
- const types_1 = require("@shapeshiftoss/types");
6
+ exports.getInternalMultisigAddress = exports.SENDMULTISIG_SIG_HASH = exports.txInteractsWithContract = exports.getSigHash = void 0;
8
7
  const ethers_1 = require("ethers");
9
8
  const multiSig_1 = __importDefault(require("./abi/multiSig"));
10
- const toNetworkType = (network) => {
11
- switch (network) {
12
- case 'mainnet':
13
- return types_1.NetworkTypes.MAINNET;
14
- case 'ropsten':
15
- return types_1.NetworkTypes.ETH_ROPSTEN;
16
- default:
17
- throw new Error('unsupported network');
18
- }
19
- };
20
- exports.toNetworkType = toNetworkType;
21
9
  const getSigHash = (inputData) => {
22
10
  if (!inputData)
23
11
  return;
@@ -1,13 +1,14 @@
1
1
  import { Tx as BlockbookTx } from '@shapeshiftoss/blockbook';
2
+ import { ChainId } from '@shapeshiftoss/caip';
2
3
  import { ethers } from 'ethers';
3
- import { Network, SubParser, TxSpecific } from '../types';
4
+ import { SubParser, TxSpecific } from '../types';
4
5
  export interface ParserArgs {
5
- network: Network;
6
+ chainId: ChainId;
6
7
  provider: ethers.providers.JsonRpcProvider;
7
8
  }
8
9
  export declare class Parser implements SubParser {
9
10
  provider: ethers.providers.JsonRpcProvider;
10
- readonly network: Network;
11
+ readonly chainId: ChainId;
11
12
  readonly wethContract: string;
12
13
  readonly abiInterface: ethers.utils.Interface;
13
14
  readonly supportedFunctions: {
@@ -5,9 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Parser = void 0;
7
7
  const caip_1 = require("@shapeshiftoss/caip");
8
- const types_1 = require("@shapeshiftoss/types");
9
8
  const ethers_1 = require("ethers");
10
- const types_2 = require("../../types");
9
+ const types_1 = require("../../types");
11
10
  const erc20_1 = __importDefault(require("./abi/erc20"));
12
11
  const weth_1 = __importDefault(require("./abi/weth"));
13
12
  const constants_1 = require("./constants");
@@ -19,12 +18,18 @@ class Parser {
19
18
  depositSigHash: this.abiInterface.getSighash('deposit'),
20
19
  withdrawalSigHash: this.abiInterface.getSighash('withdraw')
21
20
  };
22
- this.network = args.network;
21
+ this.chainId = args.chainId;
23
22
  this.provider = args.provider;
24
- this.wethContract = {
25
- mainnet: constants_1.WETH_CONTRACT_MAINNET,
26
- ropsten: constants_1.WETH_CONTRACT_ROPSTEN
27
- }[this.network];
23
+ switch (args.chainId) {
24
+ case 'eip155:1':
25
+ this.wethContract = constants_1.WETH_CONTRACT_MAINNET;
26
+ break;
27
+ case 'eip155:3':
28
+ this.wethContract = constants_1.WETH_CONTRACT_ROPSTEN;
29
+ break;
30
+ default:
31
+ throw new Error('chainId is not supported. (supported chainIds: eip155:1, eip155:3)');
32
+ }
28
33
  }
29
34
  async parse(tx) {
30
35
  var _a, _b, _c;
@@ -42,10 +47,9 @@ class Parser {
42
47
  return;
43
48
  const sendAddress = (_c = (_b = tx.vin[0].addresses) === null || _b === void 0 ? void 0 : _b[0]) !== null && _c !== void 0 ? _c : '';
44
49
  const contract = new ethers_1.ethers.Contract(this.wethContract, erc20_1.default, this.provider);
45
- const assetId = (0, caip_1.toCAIP19)({
46
- chain: types_1.ChainTypes.Ethereum,
47
- network: (0, utils_1.toNetworkType)(this.network),
48
- assetNamespace: caip_1.AssetNamespace.ERC20,
50
+ const assetId = (0, caip_1.toAssetId)({
51
+ ...(0, caip_1.fromChainId)(this.chainId),
52
+ assetNamespace: 'erc20',
49
53
  assetReference: this.wethContract
50
54
  });
51
55
  const token = {
@@ -59,10 +63,9 @@ class Parser {
59
63
  case this.supportedFunctions.depositSigHash: {
60
64
  return [
61
65
  {
62
- type: types_2.TransferType.Receive,
66
+ type: types_1.TransferType.Receive,
63
67
  from: this.wethContract,
64
68
  to: sendAddress,
65
- caip19: assetId,
66
69
  assetId,
67
70
  totalValue: tx.value,
68
71
  components: [{ value: tx.value }],
@@ -73,10 +76,9 @@ class Parser {
73
76
  case this.supportedFunctions.withdrawalSigHash:
74
77
  return [
75
78
  {
76
- type: types_2.TransferType.Send,
79
+ type: types_1.TransferType.Send,
77
80
  from: sendAddress,
78
81
  to: this.wethContract,
79
- caip19: assetId,
80
82
  assetId,
81
83
  totalValue: decoded.args.wad.toString(),
82
84
  components: [{ value: decoded.args.wad.toString() }],
@@ -93,7 +95,7 @@ class Parser {
93
95
  return {
94
96
  transfers,
95
97
  data: {
96
- parser: types_2.TxParser.WETH,
98
+ parser: types_1.TxParser.WETH,
97
99
  method: decoded.name
98
100
  }
99
101
  };
@@ -1,14 +1,15 @@
1
1
  import { Tx as BlockbookTx } from '@shapeshiftoss/blockbook';
2
- import { ChainId, Yearn } from '@yfi/sdk';
2
+ import { ChainId } from '@shapeshiftoss/caip';
3
+ import { ChainId as YearnChainId, Yearn } from '@yfi/sdk';
3
4
  import { ethers } from 'ethers';
4
- import { Network, SubParser, TxSpecific } from '../types';
5
+ import { SubParser, TxSpecific } from '../types';
5
6
  interface ParserArgs {
6
- network: Network;
7
+ chainId: ChainId;
7
8
  provider: ethers.providers.JsonRpcProvider;
8
9
  }
9
10
  export declare class Parser implements SubParser {
10
11
  provider: ethers.providers.JsonRpcProvider;
11
- yearnSdk: Yearn<ChainId> | undefined;
12
+ yearnSdk: Yearn<YearnChainId> | undefined;
12
13
  yearnTokenVaultAddresses: string[] | undefined;
13
14
  readonly shapeShiftInterface: ethers.utils.Interface;
14
15
  readonly yearnInterface: ethers.utils.Interface;
@@ -27,7 +27,7 @@ class Parser {
27
27
  };
28
28
  this.provider = args.provider;
29
29
  // The only Yearn-supported chain we currently support is mainnet
30
- if (args.network === 'mainnet') {
30
+ if (args.chainId === 'eip155:1') {
31
31
  // 1 for EthMain (@yfi/sdk/dist/chain.d.ts)
32
32
  this.yearnSdk = new sdk_1.Yearn(1, { provider: this.provider });
33
33
  }
@@ -20,7 +20,6 @@ export interface ParsedTx extends StandardTx {
20
20
  data?: StandardTxMetadata;
21
21
  }
22
22
  export declare type TxSpecific = Partial<Pick<ParsedTx, 'trade' | 'transfers' | 'data'>>;
23
- export declare type Network = 'mainnet' | 'ropsten';
24
23
  export interface SubParser {
25
24
  parse(tx: BlockbookTx): Promise<TxSpecific | undefined>;
26
25
  }
package/dist/types.d.ts CHANGED
@@ -3,10 +3,6 @@ export declare enum Dex {
3
3
  Zrx = "zrx"
4
4
  }
5
5
  export interface Fee {
6
- /**
7
- * @deprecated use 'assetId' instead
8
- */
9
- caip19: string;
10
6
  assetId: string;
11
7
  value: string;
12
8
  }
@@ -34,10 +30,6 @@ export declare enum TradeType {
34
30
  export interface Transfer {
35
31
  from: string;
36
32
  to: string;
37
- /**
38
- * @deprecated use 'assetId' instead
39
- */
40
- caip19: string;
41
33
  assetId: string;
42
34
  type: TransferType;
43
35
  totalValue: string;
@@ -68,10 +60,6 @@ export interface StandardTx {
68
60
  blockHash?: string;
69
61
  blockHeight: number;
70
62
  blockTime: number;
71
- /**
72
- * @deprecated use 'chainId' instead
73
- */
74
- caip2: string;
75
63
  chainId: string;
76
64
  confirmations: number;
77
65
  fee?: Fee;
package/dist/utils.js CHANGED
@@ -28,7 +28,6 @@ function aggregateTransfer(transfers, type, assetId, from, to, value, token) {
28
28
  ...transfers,
29
29
  {
30
30
  type,
31
- caip19: assetId,
32
31
  assetId,
33
32
  from,
34
33
  to,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/unchained-client",
3
- "version": "6.12.1",
3
+ "version": "8.0.1",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "source": "src/index.ts",
@@ -28,15 +28,15 @@
28
28
  "ws": "^8.3.0"
29
29
  },
30
30
  "peerDependencies": {
31
- "@shapeshiftoss/caip": "^2.2.3",
31
+ "@shapeshiftoss/caip": "^4.0.0",
32
32
  "@shapeshiftoss/logger": "^1.1.2",
33
- "@shapeshiftoss/types": "3.1.3"
33
+ "@shapeshiftoss/types": "^4.0.0"
34
34
  },
35
35
  "devDependencies": {
36
- "@shapeshiftoss/caip": "^2.2.3",
36
+ "@shapeshiftoss/caip": "^4.0.0",
37
37
  "@shapeshiftoss/common-api": "^6.11.0",
38
38
  "@shapeshiftoss/logger": "^1.1.2",
39
- "@shapeshiftoss/types": "3.1.3",
39
+ "@shapeshiftoss/types": "^4.0.0",
40
40
  "@types/ws": "^8.2.1"
41
41
  }
42
42
  }
@@ -1,3 +0,0 @@
1
- import { NetworkTypes } from '@shapeshiftoss/types';
2
- import { Network } from '../types';
3
- export declare const toNetworkType: (network: Network) => NetworkTypes;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toNetworkType = void 0;
4
- const types_1 = require("@shapeshiftoss/types");
5
- const toNetworkType = (network) => {
6
- switch (network) {
7
- case 'mainnet':
8
- return types_1.NetworkTypes.MAINNET;
9
- case 'testnet':
10
- return types_1.NetworkTypes.TESTNET;
11
- default:
12
- throw new Error('unsupported network');
13
- }
14
- };
15
- exports.toNetworkType = toNetworkType;