@shapeshiftoss/unchained-client 6.10.0 → 6.12.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.
Files changed (187) hide show
  1. package/README.md +3 -1
  2. package/dist/bitcoin/index.d.ts +0 -1
  3. package/dist/bitcoin/index.js +5 -2
  4. package/dist/bitcoin/parser/index.d.ts +0 -1
  5. package/dist/bitcoin/parser/index.js +43 -54
  6. package/dist/bitcoin/parser/utils.d.ts +0 -1
  7. package/dist/bitcoin/parser/utils.js +0 -1
  8. package/dist/bitcoin/types.d.ts +0 -1
  9. package/dist/bitcoin/types.js +0 -1
  10. package/dist/cosmos/index.d.ts +0 -1
  11. package/dist/cosmos/index.js +5 -2
  12. package/dist/cosmos/parser/index.d.ts +4 -5
  13. package/dist/cosmos/parser/index.js +55 -50
  14. package/dist/cosmos/parser/utils.d.ts +3 -4
  15. package/dist/cosmos/parser/utils.js +28 -25
  16. package/dist/cosmos/types.d.ts +4 -1
  17. package/dist/cosmos/types.js +0 -1
  18. package/dist/ethereum/index.d.ts +0 -1
  19. package/dist/ethereum/index.js +5 -2
  20. package/dist/ethereum/parser/abi/erc20.d.ts +0 -1
  21. package/dist/ethereum/parser/abi/erc20.js +69 -70
  22. package/dist/ethereum/parser/abi/foxyStaking.d.ts +0 -1
  23. package/dist/ethereum/parser/abi/foxyStaking.js +161 -162
  24. package/dist/ethereum/parser/abi/multiSig.d.ts +0 -1
  25. package/dist/ethereum/parser/abi/multiSig.js +79 -80
  26. package/dist/ethereum/parser/abi/shapeShiftRouter.d.ts +0 -1
  27. package/dist/ethereum/parser/abi/shapeShiftRouter.js +119 -120
  28. package/dist/ethereum/parser/abi/thor.d.ts +0 -1
  29. package/dist/ethereum/parser/abi/thor.js +28 -29
  30. package/dist/ethereum/parser/abi/uniV2.d.ts +0 -1
  31. package/dist/ethereum/parser/abi/uniV2.js +55 -56
  32. package/dist/ethereum/parser/abi/weth.d.ts +0 -1
  33. package/dist/ethereum/parser/abi/weth.js +66 -67
  34. package/dist/ethereum/parser/abi/yearnVault.d.ts +0 -1
  35. package/dist/ethereum/parser/abi/yearnVault.js +95 -96
  36. package/dist/ethereum/parser/constants.d.ts +0 -1
  37. package/dist/ethereum/parser/constants.js +0 -1
  38. package/dist/ethereum/parser/foxy.d.ts +8 -9
  39. package/dist/ethereum/parser/foxy.js +27 -59
  40. package/dist/ethereum/parser/index.d.ts +0 -1
  41. package/dist/ethereum/parser/index.js +52 -59
  42. package/dist/ethereum/parser/thor.d.ts +6 -5
  43. package/dist/ethereum/parser/thor.js +33 -49
  44. package/dist/ethereum/parser/uniV2.d.ts +5 -5
  45. package/dist/ethereum/parser/uniV2.js +75 -82
  46. package/dist/ethereum/parser/utils.d.ts +0 -1
  47. package/dist/ethereum/parser/utils.js +2 -3
  48. package/dist/ethereum/parser/weth.d.ts +6 -5
  49. package/dist/ethereum/parser/weth.js +76 -99
  50. package/dist/ethereum/parser/yearn.d.ts +11 -12
  51. package/dist/ethereum/parser/yearn.js +51 -62
  52. package/dist/ethereum/parser/zrx.d.ts +1 -2
  53. package/dist/ethereum/parser/zrx.js +18 -30
  54. package/dist/ethereum/types.d.ts +0 -1
  55. package/dist/ethereum/types.js +0 -1
  56. package/dist/generated/bitcoin/api.d.ts +117 -121
  57. package/dist/generated/bitcoin/api.js +82 -111
  58. package/dist/generated/bitcoin/base.d.ts +3 -4
  59. package/dist/generated/bitcoin/base.js +2 -3
  60. package/dist/generated/bitcoin/common.d.ts +3 -4
  61. package/dist/generated/bitcoin/common.js +23 -39
  62. package/dist/generated/bitcoin/configuration.d.ts +1 -2
  63. package/dist/generated/bitcoin/configuration.js +1 -2
  64. package/dist/generated/bitcoin/index.d.ts +1 -2
  65. package/dist/generated/bitcoin/index.js +6 -3
  66. package/dist/generated/cosmos/api.d.ts +143 -144
  67. package/dist/generated/cosmos/api.js +89 -115
  68. package/dist/generated/cosmos/base.d.ts +2 -3
  69. package/dist/generated/cosmos/base.js +0 -1
  70. package/dist/generated/cosmos/common.d.ts +2 -3
  71. package/dist/generated/cosmos/common.js +22 -38
  72. package/dist/generated/cosmos/configuration.d.ts +0 -1
  73. package/dist/generated/cosmos/configuration.js +0 -1
  74. package/dist/generated/cosmos/index.d.ts +0 -1
  75. package/dist/generated/cosmos/index.js +5 -2
  76. package/dist/generated/ethereum/api.d.ts +74 -78
  77. package/dist/generated/ethereum/api.js +74 -101
  78. package/dist/generated/ethereum/base.d.ts +3 -4
  79. package/dist/generated/ethereum/base.js +2 -3
  80. package/dist/generated/ethereum/common.d.ts +3 -4
  81. package/dist/generated/ethereum/common.js +23 -39
  82. package/dist/generated/ethereum/configuration.d.ts +1 -2
  83. package/dist/generated/ethereum/configuration.js +1 -2
  84. package/dist/generated/ethereum/index.d.ts +1 -2
  85. package/dist/generated/ethereum/index.js +6 -3
  86. package/dist/index.d.ts +0 -1
  87. package/dist/index.js +5 -2
  88. package/dist/types.d.ts +12 -2
  89. package/dist/types.js +0 -1
  90. package/dist/utils.d.ts +2 -3
  91. package/dist/utils.js +23 -23
  92. package/dist/websocket.d.ts +1 -2
  93. package/dist/websocket.js +78 -80
  94. package/package.json +21 -13
  95. package/dist/bitcoin/index.d.ts.map +0 -1
  96. package/dist/bitcoin/index.js.map +0 -1
  97. package/dist/bitcoin/parser/index.d.ts.map +0 -1
  98. package/dist/bitcoin/parser/index.js.map +0 -1
  99. package/dist/bitcoin/parser/utils.d.ts.map +0 -1
  100. package/dist/bitcoin/parser/utils.js.map +0 -1
  101. package/dist/bitcoin/types.d.ts.map +0 -1
  102. package/dist/bitcoin/types.js.map +0 -1
  103. package/dist/cosmos/index.d.ts.map +0 -1
  104. package/dist/cosmos/index.js.map +0 -1
  105. package/dist/cosmos/parser/index.d.ts.map +0 -1
  106. package/dist/cosmos/parser/index.js.map +0 -1
  107. package/dist/cosmos/parser/utils.d.ts.map +0 -1
  108. package/dist/cosmos/parser/utils.js.map +0 -1
  109. package/dist/cosmos/types.d.ts.map +0 -1
  110. package/dist/cosmos/types.js.map +0 -1
  111. package/dist/ethereum/index.d.ts.map +0 -1
  112. package/dist/ethereum/index.js.map +0 -1
  113. package/dist/ethereum/parser/abi/erc20.d.ts.map +0 -1
  114. package/dist/ethereum/parser/abi/erc20.js.map +0 -1
  115. package/dist/ethereum/parser/abi/foxyStaking.d.ts.map +0 -1
  116. package/dist/ethereum/parser/abi/foxyStaking.js.map +0 -1
  117. package/dist/ethereum/parser/abi/multiSig.d.ts.map +0 -1
  118. package/dist/ethereum/parser/abi/multiSig.js.map +0 -1
  119. package/dist/ethereum/parser/abi/shapeShiftRouter.d.ts.map +0 -1
  120. package/dist/ethereum/parser/abi/shapeShiftRouter.js.map +0 -1
  121. package/dist/ethereum/parser/abi/thor.d.ts.map +0 -1
  122. package/dist/ethereum/parser/abi/thor.js.map +0 -1
  123. package/dist/ethereum/parser/abi/uniV2.d.ts.map +0 -1
  124. package/dist/ethereum/parser/abi/uniV2.js.map +0 -1
  125. package/dist/ethereum/parser/abi/weth.d.ts.map +0 -1
  126. package/dist/ethereum/parser/abi/weth.js.map +0 -1
  127. package/dist/ethereum/parser/abi/yearnVault.d.ts.map +0 -1
  128. package/dist/ethereum/parser/abi/yearnVault.js.map +0 -1
  129. package/dist/ethereum/parser/constants.d.ts.map +0 -1
  130. package/dist/ethereum/parser/constants.js.map +0 -1
  131. package/dist/ethereum/parser/foxy.d.ts.map +0 -1
  132. package/dist/ethereum/parser/foxy.js.map +0 -1
  133. package/dist/ethereum/parser/index.d.ts.map +0 -1
  134. package/dist/ethereum/parser/index.js.map +0 -1
  135. package/dist/ethereum/parser/thor.d.ts.map +0 -1
  136. package/dist/ethereum/parser/thor.js.map +0 -1
  137. package/dist/ethereum/parser/uniV2.d.ts.map +0 -1
  138. package/dist/ethereum/parser/uniV2.js.map +0 -1
  139. package/dist/ethereum/parser/utils.d.ts.map +0 -1
  140. package/dist/ethereum/parser/utils.js.map +0 -1
  141. package/dist/ethereum/parser/weth.d.ts.map +0 -1
  142. package/dist/ethereum/parser/weth.js.map +0 -1
  143. package/dist/ethereum/parser/yearn.d.ts.map +0 -1
  144. package/dist/ethereum/parser/yearn.js.map +0 -1
  145. package/dist/ethereum/parser/zrx.d.ts.map +0 -1
  146. package/dist/ethereum/parser/zrx.js.map +0 -1
  147. package/dist/ethereum/types.d.ts.map +0 -1
  148. package/dist/ethereum/types.js.map +0 -1
  149. package/dist/generated/bitcoin/api.d.ts.map +0 -1
  150. package/dist/generated/bitcoin/api.js.map +0 -1
  151. package/dist/generated/bitcoin/base.d.ts.map +0 -1
  152. package/dist/generated/bitcoin/base.js.map +0 -1
  153. package/dist/generated/bitcoin/common.d.ts.map +0 -1
  154. package/dist/generated/bitcoin/common.js.map +0 -1
  155. package/dist/generated/bitcoin/configuration.d.ts.map +0 -1
  156. package/dist/generated/bitcoin/configuration.js.map +0 -1
  157. package/dist/generated/bitcoin/index.d.ts.map +0 -1
  158. package/dist/generated/bitcoin/index.js.map +0 -1
  159. package/dist/generated/cosmos/api.d.ts.map +0 -1
  160. package/dist/generated/cosmos/api.js.map +0 -1
  161. package/dist/generated/cosmos/base.d.ts.map +0 -1
  162. package/dist/generated/cosmos/base.js.map +0 -1
  163. package/dist/generated/cosmos/common.d.ts.map +0 -1
  164. package/dist/generated/cosmos/common.js.map +0 -1
  165. package/dist/generated/cosmos/configuration.d.ts.map +0 -1
  166. package/dist/generated/cosmos/configuration.js.map +0 -1
  167. package/dist/generated/cosmos/index.d.ts.map +0 -1
  168. package/dist/generated/cosmos/index.js.map +0 -1
  169. package/dist/generated/ethereum/api.d.ts.map +0 -1
  170. package/dist/generated/ethereum/api.js.map +0 -1
  171. package/dist/generated/ethereum/base.d.ts.map +0 -1
  172. package/dist/generated/ethereum/base.js.map +0 -1
  173. package/dist/generated/ethereum/common.d.ts.map +0 -1
  174. package/dist/generated/ethereum/common.js.map +0 -1
  175. package/dist/generated/ethereum/configuration.d.ts.map +0 -1
  176. package/dist/generated/ethereum/configuration.js.map +0 -1
  177. package/dist/generated/ethereum/index.d.ts.map +0 -1
  178. package/dist/generated/ethereum/index.js.map +0 -1
  179. package/dist/index.d.ts.map +0 -1
  180. package/dist/index.js.map +0 -1
  181. package/dist/tsconfig.tsbuildinfo +0 -4970
  182. package/dist/types.d.ts.map +0 -1
  183. package/dist/types.js.map +0 -1
  184. package/dist/utils.d.ts.map +0 -1
  185. package/dist/utils.js.map +0 -1
  186. package/dist/websocket.d.ts.map +0 -1
  187. package/dist/websocket.js.map +0 -1
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -17,114 +8,116 @@ const caip_1 = require("@shapeshiftoss/caip");
17
8
  const types_1 = require("@shapeshiftoss/types");
18
9
  const ethers_1 = require("ethers");
19
10
  const types_2 = require("../../types");
20
- const uniV2_1 = __importDefault(require("./abi/uniV2"));
21
11
  const erc20_1 = __importDefault(require("./abi/erc20"));
22
- const utils_1 = require("./utils");
12
+ const uniV2_1 = __importDefault(require("./abi/uniV2"));
23
13
  const constants_1 = require("./constants");
14
+ const utils_1 = require("./utils");
24
15
  class Parser {
25
16
  constructor(args) {
26
17
  this.abiInterface = new ethers_1.ethers.utils.Interface(uniV2_1.default);
18
+ this.supportedFunctions = {
19
+ addLiquidityEthSigHash: this.abiInterface.getSighash('addLiquidityETH'),
20
+ removeLiquidityEthSigHash: this.abiInterface.getSighash('removeLiquidityETH')
21
+ };
27
22
  this.network = args.network;
28
23
  this.provider = args.provider;
29
- this.addLiquidityEthSigHash = this.abiInterface.getSighash('addLiquidityETH');
30
- this.removeLiquidityEthSigHash = this.abiInterface.getSighash('removeLiquidityETH');
31
24
  this.wethContract = {
32
25
  mainnet: constants_1.WETH_CONTRACT_MAINNET,
33
- ropsten: constants_1.WETH_CONTRACT_ROPSTEN,
26
+ ropsten: constants_1.WETH_CONTRACT_ROPSTEN
34
27
  }[this.network];
35
28
  }
36
- parse(tx) {
37
- var _a;
38
- return __awaiter(this, void 0, void 0, function* () {
39
- if (!((_a = tx.ethereumSpecific) === null || _a === void 0 ? void 0 : _a.data))
40
- return;
41
- if (!utils_1.txInteractsWithContract(tx, constants_1.UNI_V2_ROUTER_CONTRACT))
42
- return;
43
- if (!(tx.confirmations === 0))
44
- return;
45
- const transfers = yield this.getTransfers(tx);
46
- const decoded = this.abiInterface.parseTransaction({ data: tx.ethereumSpecific.data });
47
- return {
48
- transfers,
49
- data: {
50
- parser: types_2.TxParser.UniV2,
51
- method: decoded.name,
52
- },
53
- };
54
- });
55
- }
56
- static pairFor(tokenA, tokenB) {
57
- const [token0, token1] = tokenA < tokenB ? [tokenA, tokenB] : [tokenB, tokenA];
58
- const factoryContract = '0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f';
59
- const salt = ethers_1.ethers.utils.solidityKeccak256(['address', 'address'], [token0, token1]);
60
- const initCodeHash = '0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f'; // https://github.com/Uniswap/v2-periphery/blob/dda62473e2da448bc9cb8f4514dadda4aeede5f4/contracts/libraries/UniswapV2Library.sol#L24
61
- return ethers_1.ethers.utils.getCreate2Address(factoryContract, salt, initCodeHash);
62
- }
63
- getTransfers(tx) {
29
+ async parse(tx) {
64
30
  var _a, _b, _c;
65
- return __awaiter(this, void 0, void 0, function* () {
66
- const data = (_a = tx.ethereumSpecific) === null || _a === void 0 ? void 0 : _a.data;
67
- if (!data)
68
- return;
69
- const sendAddress = (_c = (_b = tx.vin[0].addresses) === null || _b === void 0 ? void 0 : _b[0]) !== null && _c !== void 0 ? _c : '';
70
- switch (utils_1.getSigHash(data)) {
71
- case this.addLiquidityEthSigHash: {
72
- const result = this.abiInterface.decodeFunctionData(this.addLiquidityEthSigHash, data);
73
- const tokenAddress = ethers_1.ethers.utils.getAddress(result.token.toLowerCase());
74
- const lpTokenAddress = Parser.pairFor(tokenAddress, this.wethContract);
31
+ const txData = (_a = tx.ethereumSpecific) === null || _a === void 0 ? void 0 : _a.data;
32
+ if (!(0, utils_1.txInteractsWithContract)(tx, constants_1.UNI_V2_ROUTER_CONTRACT))
33
+ return;
34
+ if (!txData)
35
+ return;
36
+ if (tx.confirmations)
37
+ return;
38
+ const txSigHash = (0, utils_1.getSigHash)(txData);
39
+ if (!Object.values(this.supportedFunctions).some((hash) => hash === txSigHash))
40
+ return;
41
+ const decoded = this.abiInterface.parseTransaction({ data: txData });
42
+ // failed to decode input data
43
+ if (!decoded)
44
+ return;
45
+ const sendAddress = (_c = (_b = tx.vin[0].addresses) === null || _b === void 0 ? void 0 : _b[0]) !== null && _c !== void 0 ? _c : '';
46
+ const tokenAddress = ethers_1.ethers.utils.getAddress(decoded.args.token.toLowerCase());
47
+ const lpTokenAddress = Parser.pairFor(tokenAddress, this.wethContract);
48
+ const transfers = await (async () => {
49
+ switch ((0, utils_1.getSigHash)(txData)) {
50
+ case this.supportedFunctions.addLiquidityEthSigHash: {
75
51
  const contract = new ethers_1.ethers.Contract(tokenAddress, erc20_1.default, this.provider);
76
- const decimals = yield contract.decimals();
77
- const name = yield contract.name();
78
- const symbol = yield contract.symbol();
79
- const value = result.amountTokenDesired.toString();
52
+ const decimals = await contract.decimals();
53
+ const name = await contract.name();
54
+ const symbol = await contract.symbol();
55
+ 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,
60
+ assetReference: tokenAddress
61
+ });
80
62
  return [
81
63
  {
82
64
  type: types_2.TransferType.Send,
83
65
  from: sendAddress,
84
66
  to: lpTokenAddress,
85
- caip19: caip_1.caip19.toCAIP19({
86
- chain: types_1.ChainTypes.Ethereum,
87
- network: utils_1.toNetworkType(this.network),
88
- assetNamespace: caip_1.AssetNamespace.ERC20,
89
- assetReference: tokenAddress,
90
- }),
67
+ caip19: assetId,
68
+ assetId,
91
69
  totalValue: value,
92
70
  components: [{ value }],
93
- token: { contract: tokenAddress, decimals, name, symbol },
94
- },
71
+ token: { contract: tokenAddress, decimals, name, symbol }
72
+ }
95
73
  ];
96
74
  }
97
- case this.removeLiquidityEthSigHash: {
98
- const result = this.abiInterface.decodeFunctionData(this.removeLiquidityEthSigHash, data);
99
- const tokenAddress = ethers_1.ethers.utils.getAddress(result.token.toLowerCase());
100
- const lpTokenAddress = Parser.pairFor(tokenAddress, this.wethContract);
75
+ case this.supportedFunctions.removeLiquidityEthSigHash: {
101
76
  const contract = new ethers_1.ethers.Contract(lpTokenAddress, erc20_1.default, this.provider);
102
- const decimals = yield contract.decimals();
103
- const name = yield contract.name();
104
- const symbol = yield contract.symbol();
105
- const value = result.liquidity.toString();
77
+ const decimals = await contract.decimals();
78
+ const name = await contract.name();
79
+ const symbol = await contract.symbol();
80
+ 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,
85
+ assetReference: lpTokenAddress
86
+ });
106
87
  return [
107
88
  {
108
89
  type: types_2.TransferType.Send,
109
90
  from: sendAddress,
110
91
  to: lpTokenAddress,
111
- caip19: caip_1.caip19.toCAIP19({
112
- chain: types_1.ChainTypes.Ethereum,
113
- network: utils_1.toNetworkType(this.network),
114
- assetNamespace: caip_1.AssetNamespace.ERC20,
115
- assetReference: lpTokenAddress,
116
- }),
92
+ caip19: assetId,
93
+ assetId,
117
94
  totalValue: value,
118
95
  components: [{ value }],
119
- token: { contract: lpTokenAddress, decimals, name, symbol },
120
- },
96
+ token: { contract: lpTokenAddress, decimals, name, symbol }
97
+ }
121
98
  ];
122
99
  }
123
100
  default:
124
101
  return;
125
102
  }
126
- });
103
+ })();
104
+ // no supported function detected
105
+ if (!transfers)
106
+ return;
107
+ return {
108
+ transfers,
109
+ data: {
110
+ parser: types_2.TxParser.UniV2,
111
+ method: decoded.name
112
+ }
113
+ };
114
+ }
115
+ static pairFor(tokenA, tokenB) {
116
+ const [token0, token1] = tokenA < tokenB ? [tokenA, tokenB] : [tokenB, tokenA];
117
+ const factoryContract = '0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f';
118
+ const salt = ethers_1.ethers.utils.solidityKeccak256(['address', 'address'], [token0, token1]);
119
+ const initCodeHash = '0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f'; // https://github.com/Uniswap/v2-periphery/blob/dda62473e2da448bc9cb8f4514dadda4aeede5f4/contracts/libraries/UniswapV2Library.sol#L24
120
+ return ethers_1.ethers.utils.getCreate2Address(factoryContract, salt, initCodeHash);
127
121
  }
128
122
  }
129
123
  exports.Parser = Parser;
130
- //# sourceMappingURL=uniV2.js.map
@@ -6,4 +6,3 @@ export declare const getSigHash: (inputData: string | undefined) => string | und
6
6
  export declare const txInteractsWithContract: (tx: BlockbookTx, contract: string) => boolean;
7
7
  export declare const SENDMULTISIG_SIG_HASH: string;
8
8
  export declare const getInternalMultisigAddress: (inputData: string) => string | undefined;
9
- //# sourceMappingURL=utils.d.ts.map
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getInternalMultisigAddress = exports.SENDMULTISIG_SIG_HASH = exports.txInteractsWithContract = exports.getSigHash = exports.toNetworkType = void 0;
7
- const ethers_1 = require("ethers");
8
7
  const types_1 = require("@shapeshiftoss/types");
8
+ const ethers_1 = require("ethers");
9
9
  const multiSig_1 = __importDefault(require("./abi/multiSig"));
10
10
  const toNetworkType = (network) => {
11
11
  switch (network) {
@@ -38,10 +38,9 @@ exports.SENDMULTISIG_SIG_HASH = (() => {
38
38
  // detect address associated with sendMultiSig internal transaction
39
39
  const getInternalMultisigAddress = (inputData) => {
40
40
  const abiInterface = new ethers_1.ethers.utils.Interface(multiSig_1.default);
41
- if (exports.getSigHash(inputData) !== exports.SENDMULTISIG_SIG_HASH)
41
+ if ((0, exports.getSigHash)(inputData) !== exports.SENDMULTISIG_SIG_HASH)
42
42
  return;
43
43
  const result = abiInterface.decodeFunctionData(exports.SENDMULTISIG_SIG_HASH, inputData);
44
44
  return result.toAddress;
45
45
  };
46
46
  exports.getInternalMultisigAddress = getInternalMultisigAddress;
47
- //# sourceMappingURL=utils.js.map
@@ -6,13 +6,14 @@ export interface ParserArgs {
6
6
  provider: ethers.providers.JsonRpcProvider;
7
7
  }
8
8
  export declare class Parser implements SubParser {
9
- abiInterface: ethers.utils.Interface;
10
- network: Network;
11
9
  provider: ethers.providers.JsonRpcProvider;
12
- readonly depositSigHash: string;
13
- readonly withdrawalSigHash: string;
10
+ readonly network: Network;
14
11
  readonly wethContract: string;
12
+ readonly abiInterface: ethers.utils.Interface;
13
+ readonly supportedFunctions: {
14
+ depositSigHash: string;
15
+ withdrawalSigHash: string;
16
+ };
15
17
  constructor(args: ParserArgs);
16
18
  parse(tx: BlockbookTx): Promise<TxSpecific | undefined>;
17
19
  }
18
- //# sourceMappingURL=weth.d.ts.map
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -17,109 +8,95 @@ const caip_1 = require("@shapeshiftoss/caip");
17
8
  const types_1 = require("@shapeshiftoss/types");
18
9
  const ethers_1 = require("ethers");
19
10
  const types_2 = require("../../types");
11
+ const erc20_1 = __importDefault(require("./abi/erc20"));
20
12
  const weth_1 = __importDefault(require("./abi/weth"));
21
- const utils_1 = require("./utils");
22
13
  const constants_1 = require("./constants");
23
- const erc20_1 = __importDefault(require("./abi/erc20"));
14
+ const utils_1 = require("./utils");
24
15
  class Parser {
25
16
  constructor(args) {
26
17
  this.abiInterface = new ethers_1.ethers.utils.Interface(weth_1.default);
18
+ this.supportedFunctions = {
19
+ depositSigHash: this.abiInterface.getSighash('deposit'),
20
+ withdrawalSigHash: this.abiInterface.getSighash('withdraw')
21
+ };
27
22
  this.network = args.network;
28
23
  this.provider = args.provider;
29
- this.depositSigHash = this.abiInterface.getSighash('deposit');
30
- this.withdrawalSigHash = this.abiInterface.getSighash('withdraw');
31
24
  this.wethContract = {
32
25
  mainnet: constants_1.WETH_CONTRACT_MAINNET,
33
- ropsten: constants_1.WETH_CONTRACT_ROPSTEN,
26
+ ropsten: constants_1.WETH_CONTRACT_ROPSTEN
34
27
  }[this.network];
35
28
  }
36
- parse(tx) {
37
- var _a, _b, _c, _d, _e, _f;
38
- return __awaiter(this, void 0, void 0, function* () {
39
- const txData = (_a = tx.ethereumSpecific) === null || _a === void 0 ? void 0 : _a.data;
40
- if (!utils_1.txInteractsWithContract(tx, this.wethContract))
41
- return;
42
- if (!txData)
43
- return;
44
- const decoded = this.abiInterface.parseTransaction({ data: txData });
45
- const contract = new ethers_1.ethers.Contract(this.wethContract, erc20_1.default, this.provider);
46
- const sendAddress = (_c = (_b = tx.vin[0].addresses) === null || _b === void 0 ? void 0 : _b[0]) !== null && _c !== void 0 ? _c : '';
47
- const receiveAddress = (_f = (_e = (_d = tx.vout) === null || _d === void 0 ? void 0 : _d[0].addresses) === null || _e === void 0 ? void 0 : _e[0]) !== null && _f !== void 0 ? _f : '';
48
- const decimals = yield contract.decimals();
49
- const name = yield contract.name();
50
- const symbol = yield contract.symbol();
51
- const transfers = (() => {
52
- switch (utils_1.getSigHash(txData)) {
53
- case this.depositSigHash: {
54
- if (receiveAddress !== this.wethContract)
55
- return undefined;
56
- const value = tx.value;
57
- return [
58
- {
59
- type: types_2.TransferType.Receive,
60
- from: this.wethContract,
61
- to: sendAddress,
62
- caip19: caip_1.caip19.toCAIP19({
63
- chain: types_1.ChainTypes.Ethereum,
64
- network: utils_1.toNetworkType(this.network),
65
- assetNamespace: caip_1.AssetNamespace.ERC20,
66
- assetReference: this.wethContract,
67
- }),
68
- totalValue: value,
69
- components: [{ value }],
70
- token: {
71
- contract: this.wethContract,
72
- decimals,
73
- name,
74
- symbol,
75
- },
76
- },
77
- ];
78
- }
79
- case this.withdrawalSigHash: {
80
- if (receiveAddress !== this.wethContract)
81
- return undefined;
82
- const result = this.abiInterface.decodeFunctionData(this.withdrawalSigHash, txData);
83
- const value = result.wad.toString();
84
- return [
85
- {
86
- type: types_2.TransferType.Send,
87
- from: sendAddress,
88
- to: this.wethContract,
89
- caip19: caip_1.caip19.toCAIP19({
90
- chain: types_1.ChainTypes.Ethereum,
91
- network: utils_1.toNetworkType(this.network),
92
- assetNamespace: caip_1.AssetNamespace.ERC20,
93
- assetReference: this.wethContract,
94
- }),
95
- totalValue: value,
96
- components: [{ value }],
97
- token: {
98
- contract: this.wethContract,
99
- decimals,
100
- name,
101
- symbol,
102
- },
103
- },
104
- ];
105
- }
106
- default:
107
- return undefined;
29
+ async parse(tx) {
30
+ var _a, _b, _c;
31
+ const txData = (_a = tx.ethereumSpecific) === null || _a === void 0 ? void 0 : _a.data;
32
+ if (!(0, utils_1.txInteractsWithContract)(tx, this.wethContract))
33
+ return;
34
+ if (!txData)
35
+ return;
36
+ const txSigHash = (0, utils_1.getSigHash)(txData);
37
+ if (!Object.values(this.supportedFunctions).some((hash) => hash === txSigHash))
38
+ return;
39
+ const decoded = this.abiInterface.parseTransaction({ data: txData });
40
+ // failed to decode input data
41
+ if (!decoded)
42
+ return;
43
+ const sendAddress = (_c = (_b = tx.vin[0].addresses) === null || _b === void 0 ? void 0 : _b[0]) !== null && _c !== void 0 ? _c : '';
44
+ 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,
49
+ assetReference: this.wethContract
50
+ });
51
+ const token = {
52
+ contract: this.wethContract,
53
+ decimals: await contract.decimals(),
54
+ name: await contract.name(),
55
+ symbol: await contract.symbol()
56
+ };
57
+ const transfers = (() => {
58
+ switch (txSigHash) {
59
+ case this.supportedFunctions.depositSigHash: {
60
+ return [
61
+ {
62
+ type: types_2.TransferType.Receive,
63
+ from: this.wethContract,
64
+ to: sendAddress,
65
+ caip19: assetId,
66
+ assetId,
67
+ totalValue: tx.value,
68
+ components: [{ value: tx.value }],
69
+ token
70
+ }
71
+ ];
108
72
  }
109
- })();
110
- // We didn't recognise the sigHash - exit
111
- if (!transfers)
112
- return;
113
- const data = {
73
+ case this.supportedFunctions.withdrawalSigHash:
74
+ return [
75
+ {
76
+ type: types_2.TransferType.Send,
77
+ from: sendAddress,
78
+ to: this.wethContract,
79
+ caip19: assetId,
80
+ assetId,
81
+ totalValue: decoded.args.wad.toString(),
82
+ components: [{ value: decoded.args.wad.toString() }],
83
+ token
84
+ }
85
+ ];
86
+ default:
87
+ return;
88
+ }
89
+ })();
90
+ // no supported function detected
91
+ if (!transfers)
92
+ return;
93
+ return {
94
+ transfers,
95
+ data: {
114
96
  parser: types_2.TxParser.WETH,
115
- method: decoded.name,
116
- };
117
- return {
118
- transfers,
119
- data,
120
- };
121
- });
97
+ method: decoded.name
98
+ }
99
+ };
122
100
  }
123
101
  }
124
102
  exports.Parser = Parser;
125
- //# sourceMappingURL=weth.js.map
@@ -1,5 +1,5 @@
1
- import { ChainId, Yearn } from '@yfi/sdk';
2
1
  import { Tx as BlockbookTx } from '@shapeshiftoss/blockbook';
2
+ import { ChainId, Yearn } from '@yfi/sdk';
3
3
  import { ethers } from 'ethers';
4
4
  import { Network, SubParser, TxSpecific } from '../types';
5
5
  interface ParserArgs {
@@ -10,21 +10,20 @@ export declare class Parser implements SubParser {
10
10
  provider: ethers.providers.JsonRpcProvider;
11
11
  yearnSdk: Yearn<ChainId> | undefined;
12
12
  yearnTokenVaultAddresses: string[] | undefined;
13
- shapeShiftInterface: ethers.utils.Interface;
14
- yearnInterface: ethers.utils.Interface;
15
- supportedYearnFunctions: {
16
- yearnApprovalSigHash: string;
17
- yearnDepositSigHash: string;
18
- yearnDepositWithAmountSigHash: string;
19
- yearnDepositWithAmountAndRecipientSigHash: string;
20
- yearnWithdrawSigHash: string;
13
+ readonly shapeShiftInterface: ethers.utils.Interface;
14
+ readonly yearnInterface: ethers.utils.Interface;
15
+ readonly supportedYearnFunctions: {
16
+ approveSigHash: string;
17
+ depositSigHash: string;
18
+ depositAmountSigHash: string;
19
+ depositAmountAndRecipientSigHash: string;
20
+ withdrawSigHash: string;
21
21
  };
22
- supportedShapeShiftFunctions: {
23
- shapeShiftDepositSigHash: string;
22
+ readonly supportedShapeShiftFunctions: {
23
+ depositSigHash: string;
24
24
  };
25
25
  constructor(args: ParserArgs);
26
26
  parse(tx: BlockbookTx): Promise<TxSpecific | undefined>;
27
27
  getAbiInterface(txSigHash: string | undefined): ethers.utils.Interface | undefined;
28
28
  }
29
29
  export {};
30
- //# sourceMappingURL=yearn.d.ts.map
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -15,76 +6,75 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
6
  exports.Parser = void 0;
16
7
  const sdk_1 = require("@yfi/sdk");
17
8
  const ethers_1 = require("ethers");
18
- const constants_1 = require("./constants");
19
- const utils_1 = require("./utils");
9
+ const types_1 = require("../../types");
20
10
  const shapeShiftRouter_1 = __importDefault(require("./abi/shapeShiftRouter"));
21
11
  const yearnVault_1 = __importDefault(require("./abi/yearnVault"));
22
- const types_1 = require("../../types");
12
+ const constants_1 = require("./constants");
13
+ const utils_1 = require("./utils");
23
14
  class Parser {
24
15
  constructor(args) {
25
16
  this.shapeShiftInterface = new ethers_1.ethers.utils.Interface(shapeShiftRouter_1.default);
26
17
  this.yearnInterface = new ethers_1.ethers.utils.Interface(yearnVault_1.default);
27
18
  this.supportedYearnFunctions = {
28
- yearnApprovalSigHash: this.yearnInterface.getSighash('approve'),
29
- yearnDepositSigHash: '0xd0e30db0',
30
- yearnDepositWithAmountSigHash: '0xb6b55f25',
31
- yearnDepositWithAmountAndRecipientSigHash: '0x6e553f65',
32
- yearnWithdrawSigHash: '0x00f714ce',
19
+ approveSigHash: this.yearnInterface.getSighash('approve'),
20
+ depositSigHash: this.yearnInterface.getSighash('deposit()'),
21
+ depositAmountSigHash: this.yearnInterface.getSighash('deposit(uint256)'),
22
+ depositAmountAndRecipientSigHash: this.yearnInterface.getSighash('deposit(uint256,address)'),
23
+ withdrawSigHash: this.yearnInterface.getSighash('withdraw(uint256,address)')
33
24
  };
34
25
  this.supportedShapeShiftFunctions = {
35
- shapeShiftDepositSigHash: '0x20e8c565',
26
+ depositSigHash: this.shapeShiftInterface.getSighash('deposit(address,address,uint256,uint256)')
36
27
  };
37
28
  this.provider = args.provider;
38
29
  // The only Yearn-supported chain we currently support is mainnet
39
- if (args.network == 'mainnet') {
30
+ if (args.network === 'mainnet') {
40
31
  // 1 for EthMain (@yfi/sdk/dist/chain.d.ts)
41
- this.yearnSdk = new sdk_1.Yearn(1, { provider: this.provider, disableAllowlist: true });
32
+ this.yearnSdk = new sdk_1.Yearn(1, { provider: this.provider });
42
33
  }
43
34
  }
44
- parse(tx) {
35
+ async parse(tx) {
45
36
  var _a, _b, _c, _d, _e;
46
- return __awaiter(this, void 0, void 0, function* () {
47
- const { yearnApprovalSigHash, yearnWithdrawSigHash, yearnDepositSigHash, yearnDepositWithAmountSigHash, yearnDepositWithAmountAndRecipientSigHash, } = this.supportedYearnFunctions;
48
- const { shapeShiftDepositSigHash } = this.supportedShapeShiftFunctions;
49
- const data = (_a = tx.ethereumSpecific) === null || _a === void 0 ? void 0 : _a.data;
50
- if (!data)
51
- return;
52
- const txSigHash = utils_1.getSigHash(data);
53
- const abiInterface = this.getAbiInterface(txSigHash);
54
- if (!abiInterface)
55
- return;
56
- const decoded = abiInterface.parseTransaction({ data });
57
- const receiveAddress = (_c = (_b = tx.vout) === null || _b === void 0 ? void 0 : _b[0].addresses) === null || _c === void 0 ? void 0 : _c[0];
58
- if (!this.yearnTokenVaultAddresses) {
59
- const vaults = yield ((_d = this.yearnSdk) === null || _d === void 0 ? void 0 : _d.vaults.get());
60
- this.yearnTokenVaultAddresses = vaults === null || vaults === void 0 ? void 0 : vaults.map((vault) => vault.address);
61
- }
62
- switch (txSigHash) {
63
- case yearnApprovalSigHash:
64
- if ((decoded === null || decoded === void 0 ? void 0 : decoded.args._spender) !== constants_1.SHAPE_SHIFT_ROUTER_CONTRACT)
65
- return;
66
- break;
67
- case shapeShiftDepositSigHash:
68
- if (receiveAddress !== constants_1.SHAPE_SHIFT_ROUTER_CONTRACT)
69
- return;
70
- break;
71
- case yearnWithdrawSigHash:
72
- case yearnDepositSigHash:
73
- case yearnDepositWithAmountSigHash:
74
- case yearnDepositWithAmountAndRecipientSigHash:
75
- if (receiveAddress && !((_e = this.yearnTokenVaultAddresses) === null || _e === void 0 ? void 0 : _e.includes(receiveAddress)))
76
- return;
77
- break;
78
- default:
37
+ const txData = (_a = tx.ethereumSpecific) === null || _a === void 0 ? void 0 : _a.data;
38
+ if (!txData)
39
+ return;
40
+ const txSigHash = (0, utils_1.getSigHash)(txData);
41
+ const abiInterface = this.getAbiInterface(txSigHash);
42
+ if (!abiInterface)
43
+ return;
44
+ if (!this.yearnTokenVaultAddresses) {
45
+ const vaults = await ((_b = this.yearnSdk) === null || _b === void 0 ? void 0 : _b.vaults.get());
46
+ this.yearnTokenVaultAddresses = vaults === null || vaults === void 0 ? void 0 : vaults.map((vault) => vault.address);
47
+ }
48
+ const decoded = abiInterface.parseTransaction({ data: txData });
49
+ // failed to decode input data
50
+ if (!decoded)
51
+ 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
+ switch (txSigHash) {
54
+ case this.supportedYearnFunctions.approveSigHash:
55
+ if ((decoded === null || decoded === void 0 ? void 0 : decoded.args._spender) !== constants_1.SHAPE_SHIFT_ROUTER_CONTRACT)
56
+ return;
57
+ break;
58
+ case this.supportedShapeShiftFunctions.depositSigHash:
59
+ if (receiveAddress !== constants_1.SHAPE_SHIFT_ROUTER_CONTRACT)
79
60
  return;
61
+ break;
62
+ case this.supportedYearnFunctions.withdrawSigHash:
63
+ case this.supportedYearnFunctions.depositSigHash:
64
+ case this.supportedYearnFunctions.depositAmountSigHash:
65
+ case this.supportedYearnFunctions.depositAmountAndRecipientSigHash:
66
+ if (receiveAddress && !((_e = this.yearnTokenVaultAddresses) === null || _e === void 0 ? void 0 : _e.includes(receiveAddress)))
67
+ return;
68
+ break;
69
+ default:
70
+ return;
71
+ }
72
+ return {
73
+ data: {
74
+ method: decoded.name,
75
+ parser: types_1.TxParser.Yearn
80
76
  }
81
- return {
82
- data: {
83
- method: decoded === null || decoded === void 0 ? void 0 : decoded.name,
84
- parser: types_1.TxParser.Yearn,
85
- },
86
- };
87
- });
77
+ };
88
78
  }
89
79
  getAbiInterface(txSigHash) {
90
80
  if (Object.values(this.supportedYearnFunctions).some((abi) => abi === txSigHash))
@@ -95,4 +85,3 @@ class Parser {
95
85
  }
96
86
  }
97
87
  exports.Parser = Parser;
98
- //# sourceMappingURL=yearn.js.map