dequanto 0.0.1 → 0.0.7

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 (886) hide show
  1. package/.circleci/config.yml +28 -0
  2. package/actions/contracts.act.ts +50 -0
  3. package/actions/logs.act.ts +7 -0
  4. package/actions/safe.act.ts +7 -0
  5. package/actions/tokens.act.ts +20 -2
  6. package/configs/defi.yml +24 -0
  7. package/configs/dequanto.yml +49 -2
  8. package/contracts/abi/gnosis/GnosisSafe.json +979 -0
  9. package/contracts/gen/base/{ERC20Base.ts → ERC20Base/ERC20Base.ts} +136 -90
  10. package/contracts/gen/eth/WETHBase.ts +35 -35
  11. package/contracts/gnosis/GnosisSafe.ts +750 -0
  12. package/contracts/openzeppelin/AccessControl.json +206 -0
  13. package/contracts/openzeppelin/AccessControl.ts +236 -0
  14. package/contracts/openzeppelin/AccessControlCrossChain.json +219 -0
  15. package/contracts/openzeppelin/AccessControlCrossChain.ts +247 -0
  16. package/contracts/openzeppelin/AccessControlEnumerable.json +249 -0
  17. package/contracts/openzeppelin/AccessControlEnumerable.ts +258 -0
  18. package/contracts/openzeppelin/Address.json +1 -0
  19. package/contracts/openzeppelin/Address.ts +83 -0
  20. package/contracts/openzeppelin/Arrays.json +1 -0
  21. package/contracts/openzeppelin/Arrays.ts +83 -0
  22. package/contracts/openzeppelin/Base64.json +1 -0
  23. package/contracts/openzeppelin/Base64.ts +83 -0
  24. package/contracts/openzeppelin/BeaconProxy.json +71 -0
  25. package/contracts/openzeppelin/BeaconProxy.ts +163 -0
  26. package/contracts/openzeppelin/BitMaps.json +1 -0
  27. package/contracts/openzeppelin/BitMaps.ts +83 -0
  28. package/contracts/openzeppelin/Checkpoints.json +1 -0
  29. package/contracts/openzeppelin/Checkpoints.ts +83 -0
  30. package/contracts/openzeppelin/Clones.json +1 -0
  31. package/contracts/openzeppelin/Clones.ts +83 -0
  32. package/contracts/openzeppelin/ConditionalEscrow.json +156 -0
  33. package/contracts/openzeppelin/ConditionalEscrow.ts +236 -0
  34. package/contracts/openzeppelin/Context.json +1 -0
  35. package/contracts/openzeppelin/Context.ts +83 -0
  36. package/contracts/openzeppelin/Counters.json +1 -0
  37. package/contracts/openzeppelin/Counters.ts +83 -0
  38. package/contracts/openzeppelin/Create2.json +1 -0
  39. package/contracts/openzeppelin/Create2.ts +83 -0
  40. package/contracts/openzeppelin/CrossChainEnabled.json +1 -0
  41. package/contracts/openzeppelin/CrossChainEnabled.ts +83 -0
  42. package/contracts/openzeppelin/CrossChainEnabledAMB.json +13 -0
  43. package/contracts/openzeppelin/CrossChainEnabledAMB.ts +83 -0
  44. package/contracts/openzeppelin/CrossChainEnabledArbitrumL1.json +1 -0
  45. package/contracts/openzeppelin/CrossChainEnabledArbitrumL1.ts +83 -0
  46. package/contracts/openzeppelin/CrossChainEnabledArbitrumL2.json +1 -0
  47. package/contracts/openzeppelin/CrossChainEnabledArbitrumL2.ts +83 -0
  48. package/contracts/openzeppelin/CrossChainEnabledOptimism.json +1 -0
  49. package/contracts/openzeppelin/CrossChainEnabledOptimism.ts +83 -0
  50. package/contracts/openzeppelin/CrossChainEnabledPolygonChild.json +30 -0
  51. package/contracts/openzeppelin/CrossChainEnabledPolygonChild.ts +90 -0
  52. package/contracts/openzeppelin/DoubleEndedQueue.json +12 -0
  53. package/contracts/openzeppelin/DoubleEndedQueue.ts +83 -0
  54. package/contracts/openzeppelin/ECDSA.json +1 -0
  55. package/contracts/openzeppelin/ECDSA.ts +83 -0
  56. package/contracts/openzeppelin/EIP712.json +1 -0
  57. package/contracts/openzeppelin/EIP712.ts +83 -0
  58. package/contracts/openzeppelin/ERC1155.json +325 -0
  59. package/contracts/openzeppelin/ERC1155.ts +276 -0
  60. package/contracts/openzeppelin/ERC1155Burnable.json +360 -0
  61. package/contracts/openzeppelin/ERC1155Burnable.ts +298 -0
  62. package/contracts/openzeppelin/ERC1155Holder.json +99 -0
  63. package/contracts/openzeppelin/ERC1155Holder.ts +112 -0
  64. package/contracts/openzeppelin/ERC1155Pausable.json +353 -0
  65. package/contracts/openzeppelin/ERC1155Pausable.ts +345 -0
  66. package/contracts/openzeppelin/ERC1155PresetMinterPauser.json +734 -0
  67. package/contracts/openzeppelin/ERC1155PresetMinterPauser.ts +608 -0
  68. package/contracts/openzeppelin/ERC1155Receiver.json +99 -0
  69. package/contracts/openzeppelin/ERC1155Receiver.ts +112 -0
  70. package/contracts/openzeppelin/ERC1155Supply.json +352 -0
  71. package/contracts/openzeppelin/ERC1155Supply.ts +298 -0
  72. package/contracts/openzeppelin/ERC1155URIStorage.json +314 -0
  73. package/contracts/openzeppelin/ERC1155URIStorage.ts +276 -0
  74. package/contracts/openzeppelin/ERC165.json +21 -0
  75. package/contracts/openzeppelin/ERC165.ts +90 -0
  76. package/contracts/openzeppelin/ERC165Checker.json +1 -0
  77. package/contracts/openzeppelin/ERC165Checker.ts +83 -0
  78. package/contracts/openzeppelin/ERC165Storage.json +21 -0
  79. package/contracts/openzeppelin/ERC165Storage.ts +90 -0
  80. package/contracts/openzeppelin/ERC1820Implementer.json +26 -0
  81. package/contracts/openzeppelin/ERC1820Implementer.ts +90 -0
  82. package/contracts/openzeppelin/ERC1967Proxy.json +71 -0
  83. package/contracts/openzeppelin/ERC1967Proxy.ts +163 -0
  84. package/contracts/openzeppelin/ERC1967Upgrade.json +47 -0
  85. package/contracts/openzeppelin/ERC1967Upgrade.ts +163 -0
  86. package/contracts/openzeppelin/ERC20.json +288 -0
  87. package/contracts/openzeppelin/ERC20.ts +251 -0
  88. package/contracts/openzeppelin/ERC20Burnable.json +303 -0
  89. package/contracts/openzeppelin/ERC20Burnable.ts +273 -0
  90. package/contracts/openzeppelin/ERC20Capped.json +285 -0
  91. package/contracts/openzeppelin/ERC20Capped.ts +262 -0
  92. package/contracts/openzeppelin/ERC20FlashMint.json +349 -0
  93. package/contracts/openzeppelin/ERC20FlashMint.ts +284 -0
  94. package/contracts/openzeppelin/ERC20Pausable.json +311 -0
  95. package/contracts/openzeppelin/ERC20Pausable.ts +320 -0
  96. package/contracts/openzeppelin/ERC20Permit.json +347 -0
  97. package/contracts/openzeppelin/ERC20Permit.ts +284 -0
  98. package/contracts/openzeppelin/ERC20PresetFixedSupply.json +329 -0
  99. package/contracts/openzeppelin/ERC20PresetFixedSupply.ts +273 -0
  100. package/contracts/openzeppelin/ERC20PresetMinterPauser.json +663 -0
  101. package/contracts/openzeppelin/ERC20PresetMinterPauser.ts +583 -0
  102. package/contracts/openzeppelin/ERC20Snapshot.json +328 -0
  103. package/contracts/openzeppelin/ERC20Snapshot.ts +302 -0
  104. package/contracts/openzeppelin/ERC20Votes.json +584 -0
  105. package/contracts/openzeppelin/ERC20Votes.ts +430 -0
  106. package/contracts/openzeppelin/ERC20VotesComp.json +627 -0
  107. package/contracts/openzeppelin/ERC20VotesComp.ts +452 -0
  108. package/contracts/openzeppelin/ERC20Wrapper.json +333 -0
  109. package/contracts/openzeppelin/ERC20Wrapper.ts +284 -0
  110. package/contracts/openzeppelin/ERC2771Context.json +21 -0
  111. package/contracts/openzeppelin/ERC2771Context.ts +90 -0
  112. package/contracts/openzeppelin/ERC2981.json +50 -0
  113. package/contracts/openzeppelin/ERC2981.ts +101 -0
  114. package/contracts/openzeppelin/ERC4626.json +662 -0
  115. package/contracts/openzeppelin/ERC4626.ts +485 -0
  116. package/contracts/openzeppelin/ERC721.json +348 -0
  117. package/contracts/openzeppelin/ERC721.ts +295 -0
  118. package/contracts/openzeppelin/ERC721Burnable.json +345 -0
  119. package/contracts/openzeppelin/ERC721Burnable.ts +306 -0
  120. package/contracts/openzeppelin/ERC721Enumerable.json +388 -0
  121. package/contracts/openzeppelin/ERC721Enumerable.ts +328 -0
  122. package/contracts/openzeppelin/ERC721Holder.json +36 -0
  123. package/contracts/openzeppelin/ERC721Holder.ts +90 -0
  124. package/contracts/openzeppelin/ERC721Pausable.json +371 -0
  125. package/contracts/openzeppelin/ERC721Pausable.ts +364 -0
  126. package/contracts/openzeppelin/ERC721PresetMinterPauserAutoId.json +742 -0
  127. package/contracts/openzeppelin/ERC721PresetMinterPauserAutoId.ts +638 -0
  128. package/contracts/openzeppelin/ERC721Royalty.json +361 -0
  129. package/contracts/openzeppelin/ERC721Royalty.ts +306 -0
  130. package/contracts/openzeppelin/ERC721URIStorage.json +332 -0
  131. package/contracts/openzeppelin/ERC721URIStorage.ts +295 -0
  132. package/contracts/openzeppelin/ERC721Votes.json +546 -0
  133. package/contracts/openzeppelin/ERC721Votes.ts +441 -0
  134. package/contracts/openzeppelin/ERC777.json +578 -0
  135. package/contracts/openzeppelin/ERC777.ts +473 -0
  136. package/contracts/openzeppelin/ERC777PresetFixedSupply.json +588 -0
  137. package/contracts/openzeppelin/ERC777PresetFixedSupply.ts +473 -0
  138. package/contracts/openzeppelin/EnumerableMap.json +1 -0
  139. package/contracts/openzeppelin/EnumerableMap.ts +83 -0
  140. package/contracts/openzeppelin/EnumerableSet.json +1 -0
  141. package/contracts/openzeppelin/EnumerableSet.ts +83 -0
  142. package/contracts/openzeppelin/Escrow.json +137 -0
  143. package/contracts/openzeppelin/Escrow.ts +225 -0
  144. package/contracts/openzeppelin/Governor.json +866 -0
  145. package/contracts/openzeppelin/Governor.ts +525 -0
  146. package/contracts/openzeppelin/GovernorCompatibilityBravo.json +1181 -0
  147. package/contracts/openzeppelin/GovernorCompatibilityBravo.ts +654 -0
  148. package/contracts/openzeppelin/GovernorCountingSimple.json +895 -0
  149. package/contracts/openzeppelin/GovernorCountingSimple.ts +536 -0
  150. package/contracts/openzeppelin/GovernorPreventLateQuorum.json +930 -0
  151. package/contracts/openzeppelin/GovernorPreventLateQuorum.ts +605 -0
  152. package/contracts/openzeppelin/GovernorProposalThreshold.json +866 -0
  153. package/contracts/openzeppelin/GovernorProposalThreshold.ts +525 -0
  154. package/contracts/openzeppelin/GovernorSettings.json +962 -0
  155. package/contracts/openzeppelin/GovernorSettings.ts +645 -0
  156. package/contracts/openzeppelin/GovernorTimelockCompound.json +990 -0
  157. package/contracts/openzeppelin/GovernorTimelockCompound.ts +638 -0
  158. package/contracts/openzeppelin/GovernorTimelockControl.json +983 -0
  159. package/contracts/openzeppelin/GovernorTimelockControl.ts +627 -0
  160. package/contracts/openzeppelin/GovernorVotes.json +879 -0
  161. package/contracts/openzeppelin/GovernorVotes.ts +536 -0
  162. package/contracts/openzeppelin/GovernorVotesComp.json +879 -0
  163. package/contracts/openzeppelin/GovernorVotesComp.ts +536 -0
  164. package/contracts/openzeppelin/GovernorVotesQuorumFraction.json +937 -0
  165. package/contracts/openzeppelin/GovernorVotesQuorumFraction.ts +598 -0
  166. package/contracts/openzeppelin/IAMB.json +327 -0
  167. package/contracts/openzeppelin/IAMB.ts +331 -0
  168. package/contracts/openzeppelin/IAccessControl.json +174 -0
  169. package/contracts/openzeppelin/IAccessControl.ts +214 -0
  170. package/contracts/openzeppelin/IAccessControlEnumerable.json +217 -0
  171. package/contracts/openzeppelin/IAccessControlEnumerable.ts +236 -0
  172. package/contracts/openzeppelin/IArbSys.json +270 -0
  173. package/contracts/openzeppelin/IArbSys.ts +233 -0
  174. package/contracts/openzeppelin/IBeacon.json +15 -0
  175. package/contracts/openzeppelin/IBeacon.ts +90 -0
  176. package/contracts/openzeppelin/IBridge.json +296 -0
  177. package/contracts/openzeppelin/IBridge.ts +287 -0
  178. package/contracts/openzeppelin/ICompoundTimelock.json +415 -0
  179. package/contracts/openzeppelin/ICompoundTimelock.ts +389 -0
  180. package/contracts/openzeppelin/ICrossDomainMessenger.json +101 -0
  181. package/contracts/openzeppelin/ICrossDomainMessenger.ts +181 -0
  182. package/contracts/openzeppelin/IERC1155.json +295 -0
  183. package/contracts/openzeppelin/IERC1155.ts +265 -0
  184. package/contracts/openzeppelin/IERC1155MetadataURI.json +314 -0
  185. package/contracts/openzeppelin/IERC1155MetadataURI.ts +276 -0
  186. package/contracts/openzeppelin/IERC1155Receiver.json +99 -0
  187. package/contracts/openzeppelin/IERC1155Receiver.ts +112 -0
  188. package/contracts/openzeppelin/IERC1271.json +26 -0
  189. package/contracts/openzeppelin/IERC1271.ts +90 -0
  190. package/contracts/openzeppelin/IERC1363.json +373 -0
  191. package/contracts/openzeppelin/IERC1363.ts +252 -0
  192. package/contracts/openzeppelin/IERC1363Receiver.json +36 -0
  193. package/contracts/openzeppelin/IERC1363Receiver.ts +90 -0
  194. package/contracts/openzeppelin/IERC1363Spender.json +31 -0
  195. package/contracts/openzeppelin/IERC1363Spender.ts +90 -0
  196. package/contracts/openzeppelin/IERC165.json +21 -0
  197. package/contracts/openzeppelin/IERC165.ts +90 -0
  198. package/contracts/openzeppelin/IERC1820Implementer.json +26 -0
  199. package/contracts/openzeppelin/IERC1820Implementer.ts +90 -0
  200. package/contracts/openzeppelin/IERC1820Registry.json +215 -0
  201. package/contracts/openzeppelin/IERC1820Registry.ts +218 -0
  202. package/contracts/openzeppelin/IERC1822Proxiable.json +15 -0
  203. package/contracts/openzeppelin/IERC1822Proxiable.ts +90 -0
  204. package/contracts/openzeppelin/IERC20.json +185 -0
  205. package/contracts/openzeppelin/IERC20.ts +196 -0
  206. package/contracts/openzeppelin/IERC20Metadata.json +224 -0
  207. package/contracts/openzeppelin/IERC20Metadata.ts +229 -0
  208. package/contracts/openzeppelin/IERC20Permit.json +77 -0
  209. package/contracts/openzeppelin/IERC20Permit.ts +112 -0
  210. package/contracts/openzeppelin/IERC2612.json +77 -0
  211. package/contracts/openzeppelin/IERC2612.ts +112 -0
  212. package/contracts/openzeppelin/IERC2981.json +50 -0
  213. package/contracts/openzeppelin/IERC2981.ts +101 -0
  214. package/contracts/openzeppelin/IERC3156FlashBorrower.json +41 -0
  215. package/contracts/openzeppelin/IERC3156FlashBorrower.ts +90 -0
  216. package/contracts/openzeppelin/IERC3156FlashLender.json +79 -0
  217. package/contracts/openzeppelin/IERC3156FlashLender.ts +112 -0
  218. package/contracts/openzeppelin/IERC4626.json +614 -0
  219. package/contracts/openzeppelin/IERC4626.ts +463 -0
  220. package/contracts/openzeppelin/IERC721.json +287 -0
  221. package/contracts/openzeppelin/IERC721.ts +262 -0
  222. package/contracts/openzeppelin/IERC721Enumerable.json +343 -0
  223. package/contracts/openzeppelin/IERC721Enumerable.ts +295 -0
  224. package/contracts/openzeppelin/IERC721Metadata.json +332 -0
  225. package/contracts/openzeppelin/IERC721Metadata.ts +295 -0
  226. package/contracts/openzeppelin/IERC721Receiver.json +36 -0
  227. package/contracts/openzeppelin/IERC721Receiver.ts +90 -0
  228. package/contracts/openzeppelin/IERC777.json +393 -0
  229. package/contracts/openzeppelin/IERC777.ts +360 -0
  230. package/contracts/openzeppelin/IERC777Recipient.json +40 -0
  231. package/contracts/openzeppelin/IERC777Recipient.ts +90 -0
  232. package/contracts/openzeppelin/IERC777Sender.json +40 -0
  233. package/contracts/openzeppelin/IERC777Sender.ts +90 -0
  234. package/contracts/openzeppelin/IFxMessageProcessor.json +25 -0
  235. package/contracts/openzeppelin/IFxMessageProcessor.ts +90 -0
  236. package/contracts/openzeppelin/IGovernor.json +683 -0
  237. package/contracts/openzeppelin/IGovernor.ts +448 -0
  238. package/contracts/openzeppelin/IGovernorCompatibilityBravo.json +913 -0
  239. package/contracts/openzeppelin/IGovernorCompatibilityBravo.ts +522 -0
  240. package/contracts/openzeppelin/IGovernorTimelock.json +768 -0
  241. package/contracts/openzeppelin/IGovernorTimelock.ts +510 -0
  242. package/contracts/openzeppelin/IInbox.json +377 -0
  243. package/contracts/openzeppelin/IInbox.ts +273 -0
  244. package/contracts/openzeppelin/IMessageProvider.json +34 -0
  245. package/contracts/openzeppelin/IMessageProvider.ts +134 -0
  246. package/contracts/openzeppelin/IOutbox.json +179 -0
  247. package/contracts/openzeppelin/IOutbox.ts +218 -0
  248. package/contracts/openzeppelin/IVotes.json +184 -0
  249. package/contracts/openzeppelin/IVotes.ts +196 -0
  250. package/contracts/openzeppelin/Initializable.json +15 -0
  251. package/contracts/openzeppelin/Initializable.ts +105 -0
  252. package/contracts/openzeppelin/LibAMB.json +1 -0
  253. package/contracts/openzeppelin/LibAMB.ts +83 -0
  254. package/contracts/openzeppelin/LibArbitrumL1.json +1 -0
  255. package/contracts/openzeppelin/LibArbitrumL1.ts +83 -0
  256. package/contracts/openzeppelin/LibArbitrumL2.json +15 -0
  257. package/contracts/openzeppelin/LibArbitrumL2.ts +90 -0
  258. package/contracts/openzeppelin/LibOptimism.json +1 -0
  259. package/contracts/openzeppelin/LibOptimism.ts +83 -0
  260. package/contracts/openzeppelin/Math.json +1 -0
  261. package/contracts/openzeppelin/Math.ts +83 -0
  262. package/contracts/openzeppelin/MerkleProof.json +1 -0
  263. package/contracts/openzeppelin/MerkleProof.ts +83 -0
  264. package/contracts/openzeppelin/MinimalForwarder.json +143 -0
  265. package/contracts/openzeppelin/MinimalForwarder.ts +112 -0
  266. package/contracts/openzeppelin/Multicall.json +21 -0
  267. package/contracts/openzeppelin/Multicall.ts +90 -0
  268. package/contracts/openzeppelin/Ownable.json +54 -0
  269. package/contracts/openzeppelin/Ownable.ts +134 -0
  270. package/contracts/openzeppelin/Pausable.json +41 -0
  271. package/contracts/openzeppelin/Pausable.ts +141 -0
  272. package/contracts/openzeppelin/PaymentSplitter.json +304 -0
  273. package/contracts/openzeppelin/PaymentSplitter.ts +281 -0
  274. package/contracts/openzeppelin/Proxy.json +10 -0
  275. package/contracts/openzeppelin/Proxy.ts +83 -0
  276. package/contracts/openzeppelin/ProxyAdmin.json +151 -0
  277. package/contracts/openzeppelin/ProxyAdmin.ts +189 -0
  278. package/contracts/openzeppelin/PullPayment.json +34 -0
  279. package/contracts/openzeppelin/PullPayment.ts +101 -0
  280. package/contracts/openzeppelin/ReentrancyGuard.json +1 -0
  281. package/contracts/openzeppelin/ReentrancyGuard.ts +83 -0
  282. package/contracts/openzeppelin/RefundEscrow.json +226 -0
  283. package/contracts/openzeppelin/RefundEscrow.ts +349 -0
  284. package/contracts/openzeppelin/SafeCast.json +1 -0
  285. package/contracts/openzeppelin/SafeCast.ts +83 -0
  286. package/contracts/openzeppelin/SafeERC20.json +1 -0
  287. package/contracts/openzeppelin/SafeERC20.ts +83 -0
  288. package/contracts/openzeppelin/SafeMath.json +1 -0
  289. package/contracts/openzeppelin/SafeMath.ts +83 -0
  290. package/contracts/openzeppelin/SignatureChecker.json +1 -0
  291. package/contracts/openzeppelin/SignatureChecker.ts +83 -0
  292. package/contracts/openzeppelin/SignedMath.json +1 -0
  293. package/contracts/openzeppelin/SignedMath.ts +83 -0
  294. package/contracts/openzeppelin/SignedSafeMath.json +1 -0
  295. package/contracts/openzeppelin/SignedSafeMath.ts +83 -0
  296. package/contracts/openzeppelin/StorageSlot.json +1 -0
  297. package/contracts/openzeppelin/StorageSlot.ts +83 -0
  298. package/contracts/openzeppelin/Strings.json +1 -0
  299. package/contracts/openzeppelin/Strings.ts +83 -0
  300. package/contracts/openzeppelin/TimelockController.json +867 -0
  301. package/contracts/openzeppelin/TimelockController.ts +583 -0
  302. package/contracts/openzeppelin/Timers.json +1 -0
  303. package/contracts/openzeppelin/Timers.ts +83 -0
  304. package/contracts/openzeppelin/TokenTimelock.json +69 -0
  305. package/contracts/openzeppelin/TokenTimelock.ts +123 -0
  306. package/contracts/openzeppelin/TransparentUpgradeableProxy.json +146 -0
  307. package/contracts/openzeppelin/TransparentUpgradeableProxy.ts +214 -0
  308. package/contracts/openzeppelin/UUPSUpgradeable.json +91 -0
  309. package/contracts/openzeppelin/UUPSUpgradeable.ts +192 -0
  310. package/contracts/openzeppelin/UpgradeableBeacon.json +104 -0
  311. package/contracts/openzeppelin/UpgradeableBeacon.ts +185 -0
  312. package/contracts/openzeppelin/VestingWallet.json +193 -0
  313. package/contracts/openzeppelin/VestingWallet.ts +208 -0
  314. package/contracts/openzeppelin/Votes.json +216 -0
  315. package/contracts/openzeppelin/Votes.ts +218 -0
  316. package/data/evm/eventHashes.json +19314 -0
  317. package/data/evm/events.json +19314 -0
  318. package/data/evm/functionHashes.json +121138 -0
  319. package/data/evm/functions.json +121140 -0
  320. package/data/tokens/coingecko.json +137409 -0
  321. package/dist/contracts/gen/base/ERC20Base/ERC20Base.js +94 -0
  322. package/dist/contracts/gnosis/GnosisSafe.js +357 -0
  323. package/dist/src/BlockchainExplorer/BlockChainExplorerFactory.js +114 -20
  324. package/dist/src/BlockchainExplorer/BlockChainExplorerProvider.js +8 -0
  325. package/dist/src/BlockchainExplorer/Bscscan.js +1 -0
  326. package/dist/src/BlockchainExplorer/Etherscan.js +14 -4
  327. package/dist/src/BlockchainExplorer/Evmscan.js +9 -0
  328. package/dist/src/BlockchainExplorer/Polyscan.js +1 -0
  329. package/dist/src/ChainAccountProvider.js +89 -0
  330. package/dist/src/ChainAccountsService.js +20 -2
  331. package/dist/src/Config.js +76 -0
  332. package/dist/src/blocks/BlockDateResolver.js +9 -8
  333. package/dist/src/bridges/hop/HopBridge.js +5 -2
  334. package/dist/src/chains/PlatformFactory.js +2 -2
  335. package/dist/src/chains/arbitrum/ArbWeb3Client.js +5 -24
  336. package/dist/src/chains/arbitrum/TokensServiceArbitrum.js +18 -0
  337. package/dist/src/chains/boba/BobaWeb3Client.js +5 -33
  338. package/dist/src/chains/xdai/XDaiWeb3Client.js +6 -30
  339. package/dist/src/class/SubjectKind.js +9 -0
  340. package/dist/src/class/SubjectStream.js +104 -0
  341. package/dist/src/class/Subscription.js +13 -0
  342. package/dist/src/clients/BscWeb3Client.js +5 -24
  343. package/dist/src/clients/ClientEventsStream.js +62 -18
  344. package/dist/src/clients/ClientPool.js +115 -55
  345. package/dist/src/clients/EthWeb3Client.js +7 -22
  346. package/dist/src/clients/EvmWeb3Client.js +25 -0
  347. package/dist/src/clients/HardhatWeb3Client.js +19 -40
  348. package/dist/src/clients/PolyWeb3Client.js +5 -51
  349. package/dist/src/clients/Web3Client.js +355 -10
  350. package/dist/src/clients/Web3ClientFactory.js +15 -0
  351. package/dist/src/clients/debug/ClientDebugMethods.js +64 -0
  352. package/dist/src/clients/utils/ClientEndpoints.js +6 -0
  353. package/dist/src/clients/utils/TxFactory.js +7 -12
  354. package/dist/src/contracts/Contract.js +2 -1
  355. package/dist/src/contracts/ContractAbiProvider.js +58 -0
  356. package/dist/src/contracts/ContractBase.js +161 -26
  357. package/dist/src/contracts/ContractReader.js +78 -2
  358. package/dist/src/contracts/ContractStorageReaderBase.js +15 -0
  359. package/dist/src/contracts/ContractStream.js +21 -8
  360. package/dist/src/contracts/ContractWriter.js +47 -20
  361. package/dist/src/contracts/TxContract.js +6 -3
  362. package/dist/src/contracts/common/ERC20.js +1 -1
  363. package/dist/src/contracts/utils/AbiDeserializer.js +15 -5
  364. package/dist/src/contracts/utils/InputDataUtils.js +5 -2
  365. package/dist/src/env/BigIntSerializer.js +2 -1
  366. package/dist/src/evm/EVM.js +214 -0
  367. package/dist/src/evm/OpcodesWalker.js +137 -0
  368. package/dist/src/evm/Stack.js +57 -0
  369. package/dist/src/evm/interfaces/IJumps.js +2 -0
  370. package/dist/src/evm/interfaces/IMemory.js +2 -0
  371. package/dist/src/evm/interfaces/IOpcode.js +2 -0
  372. package/dist/src/evm/interfaces/IStorage.js +2 -0
  373. package/dist/src/evm/opcodes/add.js +50 -0
  374. package/dist/src/evm/opcodes/addmod.js +19 -0
  375. package/dist/src/evm/opcodes/address.js +17 -0
  376. package/dist/src/evm/opcodes/and.js +56 -0
  377. package/dist/src/evm/opcodes/balance.js +22 -0
  378. package/dist/src/evm/opcodes/blockhash.js +22 -0
  379. package/dist/src/evm/opcodes/byte.js +30 -0
  380. package/dist/src/evm/opcodes/call.js +48 -0
  381. package/dist/src/evm/opcodes/callcode.js +48 -0
  382. package/dist/src/evm/opcodes/calldatacopy.js +27 -0
  383. package/dist/src/evm/opcodes/calldataload.js +33 -0
  384. package/dist/src/evm/opcodes/calldatasize.js +16 -0
  385. package/dist/src/evm/opcodes/caller.js +17 -0
  386. package/dist/src/evm/opcodes/callvalue.js +16 -0
  387. package/dist/src/evm/opcodes/codecopy.js +31 -0
  388. package/dist/src/evm/opcodes/codesize.js +16 -0
  389. package/dist/src/evm/opcodes/coinbase.js +16 -0
  390. package/dist/src/evm/opcodes/create.js +35 -0
  391. package/dist/src/evm/opcodes/create2.js +34 -0
  392. package/dist/src/evm/opcodes/delegatecall.js +44 -0
  393. package/dist/src/evm/opcodes/difficulty.js +16 -0
  394. package/dist/src/evm/opcodes/div.js +33 -0
  395. package/dist/src/evm/opcodes/dup.js +6 -0
  396. package/dist/src/evm/opcodes/eq.js +69 -0
  397. package/dist/src/evm/opcodes/exp.js +30 -0
  398. package/dist/src/evm/opcodes/extcodecopy.js +35 -0
  399. package/dist/src/evm/opcodes/extcodehash.js +22 -0
  400. package/dist/src/evm/opcodes/extcodesize.js +22 -0
  401. package/dist/src/evm/opcodes/gas.js +16 -0
  402. package/dist/src/evm/opcodes/gaslimit.js +16 -0
  403. package/dist/src/evm/opcodes/gasprice.js +16 -0
  404. package/dist/src/evm/opcodes/gt.js +36 -0
  405. package/dist/src/evm/opcodes/invalid.js +18 -0
  406. package/dist/src/evm/opcodes/iszero.js +51 -0
  407. package/dist/src/evm/opcodes/jump.js +66 -0
  408. package/dist/src/evm/opcodes/jumpdest.js +5 -0
  409. package/dist/src/evm/opcodes/jumpi.js +298 -0
  410. package/dist/src/evm/opcodes/log.js +74 -0
  411. package/dist/src/evm/opcodes/lt.js +36 -0
  412. package/dist/src/evm/opcodes/mload.js +28 -0
  413. package/dist/src/evm/opcodes/mod.js +30 -0
  414. package/dist/src/evm/opcodes/msize.js +16 -0
  415. package/dist/src/evm/opcodes/mstore.js +30 -0
  416. package/dist/src/evm/opcodes/mul.js +34 -0
  417. package/dist/src/evm/opcodes/mulmod.js +19 -0
  418. package/dist/src/evm/opcodes/not.js +28 -0
  419. package/dist/src/evm/opcodes/number.js +16 -0
  420. package/dist/src/evm/opcodes/or.js +30 -0
  421. package/dist/src/evm/opcodes/origin.js +16 -0
  422. package/dist/src/evm/opcodes/pc.js +5 -0
  423. package/dist/src/evm/opcodes/pop.js +5 -0
  424. package/dist/src/evm/opcodes/push.js +6 -0
  425. package/dist/src/evm/opcodes/return.js +70 -0
  426. package/dist/src/evm/opcodes/returndatacopy.js +31 -0
  427. package/dist/src/evm/opcodes/returndatasize.js +16 -0
  428. package/dist/src/evm/opcodes/revert.js +57 -0
  429. package/dist/src/evm/opcodes/sar.js +30 -0
  430. package/dist/src/evm/opcodes/selfdestruct.js +23 -0
  431. package/dist/src/evm/opcodes/sha3.js +56 -0
  432. package/dist/src/evm/opcodes/shl.js +35 -0
  433. package/dist/src/evm/opcodes/shr.js +30 -0
  434. package/dist/src/evm/opcodes/signextend.js +19 -0
  435. package/dist/src/evm/opcodes/sload.js +140 -0
  436. package/dist/src/evm/opcodes/sstore.js +189 -0
  437. package/dist/src/evm/opcodes/staticcall.js +44 -0
  438. package/dist/src/evm/opcodes/stop.js +17 -0
  439. package/dist/src/evm/opcodes/sub.js +30 -0
  440. package/dist/src/evm/opcodes/swap.js +6 -0
  441. package/dist/src/evm/opcodes/timestamp.js +16 -0
  442. package/dist/src/evm/opcodes/xor.js +30 -0
  443. package/dist/src/evm/opcodes.js +192 -0
  444. package/dist/src/evm/tx.class.js +154 -0
  445. package/dist/src/evm/utils/BigNumber.js +14 -0
  446. package/dist/src/evm/utils/hex.js +44 -0
  447. package/dist/src/evm/utils/opcodes.js +217 -0
  448. package/dist/src/evm/utils/stringify.js +14 -0
  449. package/dist/src/evm/utils/stringifyEvents.js +38 -0
  450. package/dist/src/evm/utils/stringifyFunctions.js +70 -0
  451. package/dist/src/evm/utils/stringifyInstructions.js +44 -0
  452. package/dist/src/evm/utils/stringifyMappings.js +62 -0
  453. package/dist/src/evm/utils/stringifyStructs.js +16 -0
  454. package/dist/src/evm/utils/stringifyVariables.js +33 -0
  455. package/dist/src/gen/ContractStorageReaderTemplate.js +11 -0
  456. package/dist/src/gen/Generator.js +37 -16
  457. package/dist/src/gen/GeneratorFromAbi.js +225 -72
  458. package/dist/src/gen/GeneratorStorageReader.js +89 -0
  459. package/dist/src/gen/utils/$gen.js +14 -0
  460. package/dist/src/gen/utils/Str.js +47 -0
  461. package/dist/src/hardhat/HardhatProvider.js +177 -0
  462. package/dist/src/indexer/BlocksTxIndexer.js +19 -7
  463. package/dist/src/indexer/handlers/BlocksWalker.js +65 -54
  464. package/dist/src/loggers/LoggerService.js +8 -5
  465. package/dist/src/models/TAccount.js +2 -0
  466. package/dist/src/ns/NameService.js +3 -0
  467. package/dist/src/ns/utils/$ns.js +6 -3
  468. package/dist/src/safe/$gnosis.js +23 -0
  469. package/dist/src/safe/GnosisSafeFactory.js +27 -0
  470. package/dist/src/safe/GnosisSafeHandler.js +361 -0
  471. package/dist/src/safe/transport/FileServiceTransport.js +92 -0
  472. package/dist/src/safe/transport/GnosisServiceTransport.js +78 -0
  473. package/dist/src/safe/transport/ISafeServiceTransport.js +2 -0
  474. package/dist/src/safe/transport/InMemoryServiceTransport.js +56 -0
  475. package/dist/src/solidity/SlotsParser.js +594 -0
  476. package/dist/src/solidity/SlotsStorage.js +158 -0
  477. package/dist/src/solidity/storage/Accessor.js +126 -0
  478. package/dist/src/solidity/storage/SlotDynamicArray.js +17 -0
  479. package/dist/src/solidity/storage/SlotFixedArray.js +28 -0
  480. package/dist/src/solidity/storage/SlotsStorageHandler.js +10 -0
  481. package/dist/src/solidity/storage/SlotsStorageTransport.js +126 -0
  482. package/dist/src/solidity/storage/handlers/SlotDynamicArrayHandler.js +47 -0
  483. package/dist/src/solidity/storage/handlers/SlotFixedArrayHandler.js +50 -0
  484. package/dist/src/solidity/storage/handlers/SlotMappingHandler.js +42 -0
  485. package/dist/src/solidity/storage/handlers/SlotStringHandler.js +109 -0
  486. package/dist/src/solidity/storage/handlers/SlotStructHandler.js +45 -0
  487. package/dist/src/solidity/storage/handlers/SlotValueHandler.js +30 -0
  488. package/dist/src/solidity/utils/$str.js +38 -0
  489. package/dist/src/solidity/utils/$types.js +22 -0
  490. package/dist/src/structs/PackedRanges.js +8 -1
  491. package/dist/src/tokens/TokenDataProvider.js +251 -0
  492. package/dist/src/tokens/TokenExchanges/AmmBase/V2/AmmPairV2Service.js +3 -1
  493. package/dist/src/tokens/TokenExchanges/AmmV2ExchangeBase.js +4 -4
  494. package/dist/src/tokens/TokenExchanges/PancakeswapExchange.js +4 -7
  495. package/dist/src/tokens/TokenExchanges/SushiswapPolygonExchange.js +4 -5
  496. package/dist/src/tokens/TokenExchanges/UniswapExchange.js +4 -7
  497. package/dist/src/tokens/TokenOracles/AmmPriceV2Oracle.js +2 -4
  498. package/dist/src/tokens/TokenOracles/CoingeckoOracle.js +12 -0
  499. package/dist/src/tokens/TokenOracles/TokenPriceStore.js +1 -1
  500. package/dist/src/tokens/TokenProviders/TPChain.js +14 -7
  501. package/dist/src/tokens/TokenProviders/TPCoingecko.js +117 -0
  502. package/dist/src/tokens/TokenProviders/TPConfig.js +46 -0
  503. package/dist/src/tokens/TokenProviders/TPExplorer.js +35 -0
  504. package/dist/src/tokens/TokenService.js +5 -2
  505. package/dist/src/tokens/TokenTransferService.js +28 -18
  506. package/dist/src/tokens/TokensService.js +32 -177
  507. package/dist/src/tokens/TokensServiceFactory.js +13 -1
  508. package/dist/src/txs/TxDataBuilder.js +54 -22
  509. package/dist/src/txs/TxLogger.js +3 -3
  510. package/dist/src/txs/TxWriter.js +169 -37
  511. package/dist/src/txs/receipt/TxLogParser.js +11 -1
  512. package/dist/src/txs/receipt/TxLogsTransfer.js +14 -13
  513. package/dist/src/txs/receipt/TxTopicProvider.js +10 -6
  514. package/dist/src/txs/sig-transports/SigFileTransport.js +48 -0
  515. package/dist/src/utils/$abiParser.js +55 -20
  516. package/dist/src/utils/$abiType.js +184 -3
  517. package/dist/src/utils/$abiUtils.js +54 -5
  518. package/dist/src/utils/$account.js +30 -0
  519. package/dist/src/utils/$address.js +8 -0
  520. package/dist/src/utils/$bigint.js +52 -3
  521. package/dist/src/utils/$block.js +16 -0
  522. package/dist/src/utils/$bloom.js +42 -0
  523. package/dist/src/utils/$buffer.js +94 -0
  524. package/dist/src/utils/$cli.js +20 -0
  525. package/dist/src/utils/$color.js +171 -0
  526. package/dist/src/utils/$config.js +65 -5
  527. package/dist/src/utils/$const.js +4 -0
  528. package/dist/src/utils/$contract.js +20 -2
  529. package/dist/src/utils/$crypto.js +25 -0
  530. package/dist/src/utils/$csv.js +17 -27
  531. package/dist/src/utils/$date.js +129 -25
  532. package/dist/src/utils/$gas.js +15 -0
  533. package/dist/src/utils/$hex.js +77 -0
  534. package/dist/src/utils/$is.js +24 -21
  535. package/dist/src/utils/$logger.js +56 -3
  536. package/dist/src/utils/$machine.js +77 -0
  537. package/dist/src/utils/$number.js +24 -1
  538. package/dist/src/utils/$path.js +17 -0
  539. package/dist/src/utils/$promise.js +81 -0
  540. package/dist/src/utils/$require.js +15 -1
  541. package/dist/src/utils/$secret.js +29 -0
  542. package/dist/src/utils/$sign.js +96 -14
  543. package/dist/src/utils/$signRaw.js +48 -0
  544. package/dist/src/utils/$signSerializer.js +5 -4
  545. package/dist/src/utils/$txData.js +19 -0
  546. package/hardhat.config.js +21 -1
  547. package/package.json +28 -14
  548. package/readme.md +21 -4
  549. package/src/BlockchainExplorer/BlockChainExplorerFactory.ts +149 -39
  550. package/src/BlockchainExplorer/BlockChainExplorerProvider.ts +10 -0
  551. package/src/BlockchainExplorer/Bscscan.ts +1 -0
  552. package/src/BlockchainExplorer/Etherscan.ts +17 -5
  553. package/src/BlockchainExplorer/Evmscan.ts +8 -0
  554. package/src/BlockchainExplorer/IBlockChainExplorer.ts +3 -2
  555. package/src/BlockchainExplorer/Polyscan.ts +1 -0
  556. package/src/ChainAccountProvider.ts +84 -0
  557. package/src/ChainAccountsService.ts +21 -2
  558. package/src/Config.ts +85 -0
  559. package/src/blocks/BlockDateResolver.ts +10 -12
  560. package/src/bridges/hop/HopBridge.ts +9 -2
  561. package/src/bridges/hop/contracts/polygon/Dai_l2AmmWrapperContract.ts +35 -35
  562. package/src/bridges/hop/contracts/polygon/Dai_l2BridgeContract.ts +35 -35
  563. package/src/bridges/hop/contracts/polygon/Dai_l2SaddleSwapContract.ts +35 -35
  564. package/src/bridges/hop/contracts/polygon/Eth_l2AmmWrapperContract.ts +35 -35
  565. package/src/bridges/hop/contracts/polygon/Eth_l2BridgeContract.ts +35 -35
  566. package/src/bridges/hop/contracts/polygon/Eth_l2SaddleSwapContract.ts +35 -35
  567. package/src/bridges/hop/contracts/polygon/Matic_l2AmmWrapperContract.ts +35 -35
  568. package/src/bridges/hop/contracts/polygon/Matic_l2BridgeContract.ts +35 -35
  569. package/src/bridges/hop/contracts/polygon/Matic_l2SaddleSwapContract.ts +35 -35
  570. package/src/bridges/hop/contracts/polygon/Usdc_l2AmmWrapperContract.ts +35 -35
  571. package/src/bridges/hop/contracts/polygon/Usdc_l2BridgeContract.ts +35 -35
  572. package/src/bridges/hop/contracts/polygon/Usdc_l2SaddleSwapContract.ts +35 -35
  573. package/src/bridges/hop/contracts/polygon/Usdt_l2AmmWrapperContract.ts +35 -35
  574. package/src/bridges/hop/contracts/polygon/Usdt_l2BridgeContract.ts +35 -35
  575. package/src/bridges/hop/contracts/polygon/Usdt_l2SaddleSwapContract.ts +35 -35
  576. package/src/bridges/hop/contracts/polygon/Wbtc_l2AmmWrapperContract.ts +35 -35
  577. package/src/bridges/hop/contracts/polygon/Wbtc_l2BridgeContract.ts +35 -35
  578. package/src/bridges/hop/contracts/polygon/Wbtc_l2SaddleSwapContract.ts +35 -35
  579. package/src/bridges/models/IBridge.ts +1 -1
  580. package/src/chains/PlatformFactory.ts +3 -2
  581. package/src/chains/arbitrum/ArbWeb3Client.ts +7 -22
  582. package/src/chains/arbitrum/TokensServiceArbitrum.ts +19 -0
  583. package/src/chains/boba/BobaWeb3Client.ts +5 -33
  584. package/src/chains/xdai/XDaiWeb3Client.ts +6 -32
  585. package/src/class/SubjectKind.ts +5 -0
  586. package/src/class/SubjectStream.ts +111 -0
  587. package/src/class/Subscription.ts +7 -0
  588. package/src/clients/BscWeb3Client.ts +5 -22
  589. package/src/clients/ClientEventsStream.ts +86 -19
  590. package/src/clients/ClientPool.ts +145 -61
  591. package/src/clients/EthWeb3Client.ts +8 -21
  592. package/src/clients/EvmWeb3Client.ts +26 -0
  593. package/src/clients/HardhatWeb3Client.ts +17 -39
  594. package/src/clients/PolyWeb3Client.ts +5 -54
  595. package/src/clients/Web3Client.ts +430 -32
  596. package/src/clients/Web3ClientFactory.ts +17 -1
  597. package/src/clients/debug/ClientDebugMethods.ts +75 -0
  598. package/src/clients/interfaces/IWeb3Client.ts +33 -5
  599. package/src/clients/interfaces/IWeb3EndpointOptions.ts +6 -0
  600. package/src/clients/utils/ClientEndpoints.ts +6 -0
  601. package/src/clients/utils/TxFactory.ts +13 -13
  602. package/src/contracts/Contract.ts +3 -2
  603. package/src/contracts/ContractAbiProvider.ts +68 -0
  604. package/src/contracts/ContractBase.ts +205 -36
  605. package/src/contracts/ContractReader.ts +116 -3
  606. package/src/contracts/ContractStorageReaderBase.ts +26 -0
  607. package/src/contracts/ContractStream.ts +24 -6
  608. package/src/contracts/ContractWriter.ts +58 -28
  609. package/src/contracts/TxContract.ts +7 -4
  610. package/src/contracts/common/ERC20.ts +1 -1
  611. package/src/contracts/utils/AbiDeserializer.ts +16 -7
  612. package/src/contracts/utils/InputDataUtils.ts +8 -6
  613. package/src/env/BigIntSerializer.ts +3 -1
  614. package/src/evm/EVM.ts +246 -0
  615. package/src/evm/OpcodesWalker.ts +149 -0
  616. package/src/evm/Stack.ts +58 -0
  617. package/src/evm/interfaces/IJumps.ts +3 -0
  618. package/src/evm/interfaces/IMemory.ts +3 -0
  619. package/src/evm/interfaces/IOpcode.ts +11 -0
  620. package/src/evm/interfaces/IStorage.ts +3 -0
  621. package/src/evm/opcodes/add.ts +49 -0
  622. package/src/evm/opcodes/addmod.ts +19 -0
  623. package/src/evm/opcodes/address.ts +22 -0
  624. package/src/evm/opcodes/and.ts +58 -0
  625. package/src/evm/opcodes/balance.ts +25 -0
  626. package/src/evm/opcodes/blockhash.ts +25 -0
  627. package/src/evm/opcodes/byte.ts +34 -0
  628. package/src/evm/opcodes/call.ts +69 -0
  629. package/src/evm/opcodes/callcode.ts +69 -0
  630. package/src/evm/opcodes/calldatacopy.ts +36 -0
  631. package/src/evm/opcodes/calldataload.ts +40 -0
  632. package/src/evm/opcodes/calldatasize.ts +21 -0
  633. package/src/evm/opcodes/caller.ts +22 -0
  634. package/src/evm/opcodes/callvalue.ts +21 -0
  635. package/src/evm/opcodes/codecopy.ts +37 -0
  636. package/src/evm/opcodes/codesize.ts +21 -0
  637. package/src/evm/opcodes/coinbase.ts +21 -0
  638. package/src/evm/opcodes/create.ts +42 -0
  639. package/src/evm/opcodes/create2.ts +41 -0
  640. package/src/evm/opcodes/delegatecall.ts +63 -0
  641. package/src/evm/opcodes/difficulty.ts +21 -0
  642. package/src/evm/opcodes/div.ts +35 -0
  643. package/src/evm/opcodes/dup.ts +7 -0
  644. package/src/evm/opcodes/eq.ts +92 -0
  645. package/src/evm/opcodes/exp.ts +34 -0
  646. package/src/evm/opcodes/extcodecopy.ts +42 -0
  647. package/src/evm/opcodes/extcodehash.ts +25 -0
  648. package/src/evm/opcodes/extcodesize.ts +25 -0
  649. package/src/evm/opcodes/gas.ts +21 -0
  650. package/src/evm/opcodes/gaslimit.ts +21 -0
  651. package/src/evm/opcodes/gasprice.ts +21 -0
  652. package/src/evm/opcodes/gt.ts +39 -0
  653. package/src/evm/opcodes/invalid.ts +24 -0
  654. package/src/evm/opcodes/iszero.ts +48 -0
  655. package/src/evm/opcodes/jump.ts +66 -0
  656. package/src/evm/opcodes/jumpdest.ts +6 -0
  657. package/src/evm/opcodes/jumpi.ts +367 -0
  658. package/src/evm/opcodes/log.ts +89 -0
  659. package/src/evm/opcodes/lt.ts +39 -0
  660. package/src/evm/opcodes/mload.ts +30 -0
  661. package/src/evm/opcodes/mod.ts +33 -0
  662. package/src/evm/opcodes/msize.ts +21 -0
  663. package/src/evm/opcodes/mstore.ts +33 -0
  664. package/src/evm/opcodes/mul.ts +38 -0
  665. package/src/evm/opcodes/mulmod.ts +19 -0
  666. package/src/evm/opcodes/not.ts +30 -0
  667. package/src/evm/opcodes/number.ts +21 -0
  668. package/src/evm/opcodes/or.ts +33 -0
  669. package/src/evm/opcodes/origin.ts +21 -0
  670. package/src/evm/opcodes/pc.ts +7 -0
  671. package/src/evm/opcodes/pop.ts +6 -0
  672. package/src/evm/opcodes/push.ts +8 -0
  673. package/src/evm/opcodes/return.ts +78 -0
  674. package/src/evm/opcodes/returndatacopy.ts +37 -0
  675. package/src/evm/opcodes/returndatasize.ts +21 -0
  676. package/src/evm/opcodes/revert.ts +64 -0
  677. package/src/evm/opcodes/sar.ts +33 -0
  678. package/src/evm/opcodes/selfdestruct.ts +26 -0
  679. package/src/evm/opcodes/sha3.ts +63 -0
  680. package/src/evm/opcodes/shl.ts +42 -0
  681. package/src/evm/opcodes/shr.ts +33 -0
  682. package/src/evm/opcodes/signextend.ts +25 -0
  683. package/src/evm/opcodes/sload.ts +190 -0
  684. package/src/evm/opcodes/sstore.ts +259 -0
  685. package/src/evm/opcodes/staticcall.ts +63 -0
  686. package/src/evm/opcodes/stop.ts +22 -0
  687. package/src/evm/opcodes/sub.ts +33 -0
  688. package/src/evm/opcodes/swap.ts +7 -0
  689. package/src/evm/opcodes/timestamp.ts +21 -0
  690. package/src/evm/opcodes/xor.ts +33 -0
  691. package/src/evm/opcodes.ts +207 -0
  692. package/src/evm/tx.class.ts +137 -0
  693. package/src/evm/utils/BigNumber.ts +9 -0
  694. package/src/evm/utils/hex.ts +37 -0
  695. package/src/evm/utils/opcodes.ts +213 -0
  696. package/src/evm/utils/stringify.ts +12 -0
  697. package/src/evm/utils/stringifyEvents.ts +37 -0
  698. package/src/evm/utils/stringifyFunctions.ts +41 -0
  699. package/src/evm/utils/stringifyInstructions.ts +38 -0
  700. package/src/evm/utils/stringifyMappings.ts +65 -0
  701. package/src/evm/utils/stringifyStructs.ts +16 -0
  702. package/src/evm/utils/stringifyVariables.ts +32 -0
  703. package/src/gen/ContractStorageReaderTemplate.ts +18 -0
  704. package/src/gen/ContractTemplate.ts +41 -7
  705. package/src/gen/Generator.ts +50 -19
  706. package/src/gen/GeneratorFromAbi.ts +239 -67
  707. package/src/gen/GeneratorStorageReader.ts +113 -0
  708. package/src/gen/utils/$gen.ts +11 -0
  709. package/src/gen/utils/Str.ts +40 -0
  710. package/src/handlers/TokenHandler.ts +1 -1
  711. package/src/hardhat/HardhatProvider.ts +207 -0
  712. package/src/indexer/BlocksTxIndexer.ts +36 -10
  713. package/src/indexer/handlers/BlocksWalker.ts +81 -62
  714. package/src/indexer/handlers/TxQueueLoader.ts +7 -7
  715. package/src/json/JsonObjectStore.ts +1 -1
  716. package/src/loggers/LoggerService.ts +9 -5
  717. package/src/loggers/TxLoggerService.ts +1 -1
  718. package/src/models/IToken.ts +9 -0
  719. package/src/models/TAccount.ts +30 -0
  720. package/src/models/TBufferLike.ts +2 -2
  721. package/src/models/TPlatform.ts +1 -1
  722. package/src/ns/NameService.ts +3 -0
  723. package/src/ns/utils/$ns.ts +3 -4
  724. package/src/safe/$gnosis.ts +20 -0
  725. package/src/safe/GnosisSafeFactory.ts +40 -0
  726. package/src/safe/GnosisSafeHandler.ts +432 -0
  727. package/src/safe/transport/FileServiceTransport.ts +115 -0
  728. package/src/safe/transport/GnosisServiceTransport.ts +83 -0
  729. package/src/safe/transport/ISafeServiceTransport.ts +26 -0
  730. package/src/safe/transport/InMemoryServiceTransport.ts +79 -0
  731. package/src/solidity/SlotsParser.ts +650 -0
  732. package/src/solidity/SlotsStorage.ts +177 -0
  733. package/src/solidity/storage/Accessor.spec.ts +45 -0
  734. package/src/solidity/storage/Accessor.ts +136 -0
  735. package/src/solidity/storage/SlotDynamicArray.ts +46 -0
  736. package/src/solidity/storage/SlotFixedArray.ts +31 -0
  737. package/src/solidity/storage/SlotsStorageHandler.ts +17 -0
  738. package/src/solidity/storage/SlotsStorageTransport.ts +152 -0
  739. package/src/solidity/storage/handlers/SlotDynamicArrayHandler.ts +52 -0
  740. package/src/solidity/storage/handlers/SlotFixedArrayHandler.ts +52 -0
  741. package/src/solidity/storage/handlers/SlotMappingHandler.ts +52 -0
  742. package/src/solidity/storage/handlers/SlotStringHandler.ts +130 -0
  743. package/src/solidity/storage/handlers/SlotStructHandler.ts +46 -0
  744. package/src/solidity/storage/handlers/SlotValueHandler.ts +36 -0
  745. package/src/solidity/utils/$str.ts +36 -0
  746. package/src/solidity/utils/$types.ts +16 -0
  747. package/src/structs/PackedRanges.ts +9 -3
  748. package/src/tokens/TokenDataProvider.ts +271 -0
  749. package/src/tokens/TokenExchanges/AmmBase/V2/AmmPairV2Service.ts +3 -1
  750. package/src/tokens/TokenExchanges/AmmV2ExchangeBase.ts +4 -3
  751. package/src/tokens/TokenExchanges/OneInchExchange.ts +1 -1
  752. package/src/tokens/TokenExchanges/PancakeswapExchange.ts +5 -10
  753. package/src/tokens/TokenExchanges/SushiswapPolygonExchange.ts +8 -5
  754. package/src/tokens/TokenExchanges/UniswapExchange.ts +6 -9
  755. package/src/tokens/TokenOracles/AmmPriceV2Oracle.ts +5 -5
  756. package/src/tokens/TokenOracles/CoingeckoOracle.ts +13 -0
  757. package/src/tokens/TokenOracles/TokenPriceStore.ts +1 -1
  758. package/src/tokens/TokenPriceService.ts +0 -1
  759. package/src/tokens/TokenProviders/ITokenProvider.ts +1 -1
  760. package/src/tokens/TokenProviders/TPChain.ts +20 -8
  761. package/src/tokens/TokenProviders/TPCoingecko.ts +121 -0
  762. package/src/tokens/TokenProviders/TPConfig.ts +53 -0
  763. package/src/tokens/TokenProviders/TPExplorer.ts +41 -0
  764. package/src/tokens/TokenService.ts +6 -3
  765. package/src/tokens/TokenSwapService.ts +1 -1
  766. package/src/tokens/TokenTransferService.ts +40 -24
  767. package/src/tokens/TokensService.ts +34 -179
  768. package/src/tokens/TokensServiceFactory.ts +13 -1
  769. package/src/tokens/defi/ISwapService.ts +1 -1
  770. package/src/tokens/defi/paraswap/Paraswap.ts +2 -1
  771. package/src/txs/ITxConfig.ts +1 -1
  772. package/src/txs/TxDataBuilder.ts +78 -34
  773. package/src/txs/TxLogger.ts +4 -4
  774. package/src/txs/TxWriter.ts +245 -48
  775. package/src/txs/conditional/GasWatcherTx.ts +0 -1
  776. package/src/txs/receipt/ITxLogItem.ts +8 -5
  777. package/src/txs/receipt/TxLogParser.ts +13 -2
  778. package/src/txs/receipt/TxLogsTransfer.ts +15 -15
  779. package/src/txs/receipt/TxTopicInMemoryProvider.ts +1 -1
  780. package/src/txs/receipt/TxTopicProvider.ts +7 -7
  781. package/src/txs/sig-transports/SigFileTransport.ts +52 -0
  782. package/src/utils/$abiParser.spec.ts +90 -0
  783. package/src/utils/$abiParser.ts +60 -25
  784. package/src/utils/$abiType.ts +195 -5
  785. package/src/utils/$abiUtils.ts +57 -6
  786. package/src/utils/$account.ts +30 -0
  787. package/src/utils/$address.ts +5 -0
  788. package/src/utils/$bigint.ts +56 -3
  789. package/src/utils/$block.ts +14 -1
  790. package/src/utils/$bloom.ts +43 -0
  791. package/src/utils/$buffer.ts +114 -0
  792. package/src/utils/$cli.ts +16 -0
  793. package/src/utils/$color.ts +211 -0
  794. package/src/utils/$config.ts +70 -7
  795. package/src/utils/$const.ts +1 -0
  796. package/src/utils/$contract.ts +21 -3
  797. package/src/utils/$crypto.ts +33 -0
  798. package/src/utils/$csv.ts +23 -7
  799. package/src/utils/$date.ts +194 -40
  800. package/src/utils/$gas.ts +17 -0
  801. package/src/utils/$hex.ts +72 -0
  802. package/src/utils/$is.ts +24 -22
  803. package/src/utils/$logger.ts +60 -2
  804. package/src/utils/$machine.ts +85 -0
  805. package/src/utils/$number.ts +24 -1
  806. package/src/utils/$path.ts +17 -1
  807. package/src/utils/$promise.ts +101 -0
  808. package/src/utils/$require.ts +15 -1
  809. package/src/utils/$secret.ts +27 -0
  810. package/src/utils/$sign.ts +115 -16
  811. package/src/utils/$signRaw.ts +50 -0
  812. package/src/utils/$signSerializer.ts +8 -6
  813. package/src/utils/$txData.ts +16 -0
  814. package/src/utils/$wallet.ts +1 -1
  815. package/test/Batch.spec.ts +89 -0
  816. package/test/BlockChainExplorer.spec.ts +33 -0
  817. package/test/ChainAccount.spec.ts +1 -1
  818. package/test/client.spec.ts +10 -11
  819. package/test/config.js +8 -0
  820. package/test/config.spec.ts +31 -0
  821. package/test/ecrecover.spec.ts +49 -0
  822. package/test/fixtures/contracts/Counter.sol +25 -0
  823. package/test/fixtures/contracts/Ecrecover.sol +33 -0
  824. package/test/fixtures/contracts/Foo.sol +32 -0
  825. package/test/fixtures/contracts/Foo.ts +78 -0
  826. package/test/fixtures/contracts/FreeToken.sol +263 -0
  827. package/test/fixtures/explorer/0xfbD2aa7efA2B46Ce3c58D7ab0D92C176c71499C0.html +2788 -0
  828. package/test/fixtures/gnosis/GnosisSafe.sol +422 -0
  829. package/test/fixtures/gnosis/GnosisSafeL2.sol +86 -0
  830. package/test/fixtures/gnosis/accessors/SimulateTxAccessor.sol +52 -0
  831. package/test/fixtures/gnosis/base/Executor.sol +27 -0
  832. package/test/fixtures/gnosis/base/FallbackManager.sol +53 -0
  833. package/test/fixtures/gnosis/base/GuardManager.sol +62 -0
  834. package/test/fixtures/gnosis/base/ModuleManager.sol +133 -0
  835. package/test/fixtures/gnosis/base/OwnerManager.sol +149 -0
  836. package/test/fixtures/gnosis/common/Enum.sol +8 -0
  837. package/test/fixtures/gnosis/common/EtherPaymentFallback.sol +13 -0
  838. package/test/fixtures/gnosis/common/SecuredTokenTransfer.sol +35 -0
  839. package/test/fixtures/gnosis/common/SelfAuthorized.sol +16 -0
  840. package/test/fixtures/gnosis/common/SignatureDecoder.sol +36 -0
  841. package/test/fixtures/gnosis/common/Singleton.sol +11 -0
  842. package/test/fixtures/gnosis/common/StorageAccessible.sol +47 -0
  843. package/test/fixtures/gnosis/external/GnosisSafeMath.sol +54 -0
  844. package/test/fixtures/gnosis/interfaces/ERC1155TokenReceiver.sol +49 -0
  845. package/test/fixtures/gnosis/interfaces/ERC721TokenReceiver.sol +24 -0
  846. package/test/fixtures/gnosis/interfaces/ERC777TokensRecipient.sol +13 -0
  847. package/test/fixtures/gnosis/interfaces/IERC165.sol +15 -0
  848. package/test/fixtures/gnosis/interfaces/ISignatureValidator.sol +20 -0
  849. package/test/fixtures/gnosis/interfaces/ViewStorageAccessible.sol +11 -0
  850. package/test/fixtures/gnosis/libraries/CreateCall.sol +30 -0
  851. package/test/fixtures/gnosis/libraries/GnosisSafeStorage.sol +21 -0
  852. package/test/fixtures/gnosis/libraries/MultiSend.sol +66 -0
  853. package/test/fixtures/gnosis/libraries/MultiSendCallOnly.sol +61 -0
  854. package/test/fixtures/gnosis/libraries/SignMessageLib.sol +34 -0
  855. package/test/fixtures/gnosis/proxies/GnosisSafeProxy.sol +44 -0
  856. package/test/fixtures/gnosis/proxies/GnosisSafeProxyFactory.sol +107 -0
  857. package/test/fixtures/gnosis/proxies/IProxyCreationCallback.sol +12 -0
  858. package/test/fixtures/scan/WETH.sol +1533 -0
  859. package/test/fixtures/slots/FooStorage.sol +8 -0
  860. package/test/fixtures/slots/FooStorageBase.sol +6 -0
  861. package/test/fixtures/slots/Vault.sol +85 -0
  862. package/test/generate/class.spec.ts +144 -6
  863. package/test/generate/evm.spec.ts +64 -0
  864. package/test/generate/openzeppelin.spec.ts +18 -0
  865. package/test/generate/slotreader.spec.ts +34 -0
  866. package/test/hardhat/TestNode.ts +37 -9
  867. package/test/hardhat/deploy.spec.ts +22 -0
  868. package/test/indexer/BlocksWalker.spec.ts +51 -0
  869. package/test/ns.spec.ts +4 -0
  870. package/test/receipt.spec.ts +1 -4
  871. package/test/safe/tx.act.ts +194 -0
  872. package/test/solidity/SlotsParser.spec.ts +186 -0
  873. package/test/solidity/SlotsReader.spec.ts +168 -0
  874. package/test/solidity/Storage.spec.ts +328 -0
  875. package/test/structs/PackedRanges.spec.ts +56 -0
  876. package/test/subscriptions.spec.ts +127 -0
  877. package/test/token.spec.ts +11 -0
  878. package/test/utils/abi-types.spec.ts +31 -0
  879. package/test/utils/abi-utils.spec.ts +23 -0
  880. package/test/utils/bigint.spec.ts +0 -1
  881. package/test/utils/date.spec.ts +3 -2
  882. package/test/utils/logbloom.spec.ts +17 -0
  883. package/test/utils/number.spec.ts +14 -3
  884. package/test/utils/sign.spec.ts +43 -7
  885. package/src/ChainAccounts.ts +0 -72
  886. package/src/structs/PackedRanges.spec.ts +0 -38
@@ -0,0 +1,1533 @@
1
+ /*
2
+ * https://firebird.finance DeFi multi-chain yield farms deployer & DEXs aggregator.
3
+ */
4
+ // File: @openzeppelin/contracts/GSN/Context.sol
5
+
6
+ // SPDX-License-Identifier: MIT
7
+
8
+ pragma solidity ^0.6.0;
9
+
10
+ /*
11
+ * @dev Provides information about the current execution context, including the
12
+ * sender of the transaction and its data. While these are generally available
13
+ * via msg.sender and msg.data, they should not be accessed in such a direct
14
+ * manner, since when dealing with GSN meta-transactions the account sending and
15
+ * paying for execution may not be the actual sender (as far as an application
16
+ * is concerned).
17
+ *
18
+ * This contract is only required for intermediate, library-like contracts.
19
+ */
20
+ abstract contract Context {
21
+ function _msgSender() internal view virtual returns (address payable) {
22
+ return msg.sender;
23
+ }
24
+
25
+ function _msgData() internal view virtual returns (bytes memory) {
26
+ this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
27
+ return msg.data;
28
+ }
29
+ }
30
+
31
+ // File: @openzeppelin/contracts/token/ERC20/IERC20.sol
32
+
33
+ // SPDX-License-Identifier: MIT
34
+
35
+ pragma solidity ^0.6.0;
36
+
37
+ /**
38
+ * @dev Interface of the ERC20 standard as defined in the EIP.
39
+ */
40
+ interface IERC20 {
41
+ /**
42
+ * @dev Returns the amount of tokens in existence.
43
+ */
44
+ function totalSupply() external view returns (uint256);
45
+
46
+ /**
47
+ * @dev Returns the amount of tokens owned by `account`.
48
+ */
49
+ function balanceOf(address account) external view returns (uint256);
50
+
51
+ /**
52
+ * @dev Moves `amount` tokens from the caller's account to `recipient`.
53
+ *
54
+ * Returns a boolean value indicating whether the operation succeeded.
55
+ *
56
+ * Emits a {Transfer} event.
57
+ */
58
+ function transfer(address recipient, uint256 amount) external returns (bool);
59
+
60
+ /**
61
+ * @dev Returns the remaining number of tokens that `spender` will be
62
+ * allowed to spend on behalf of `owner` through {transferFrom}. This is
63
+ * zero by default.
64
+ *
65
+ * This value changes when {approve} or {transferFrom} are called.
66
+ */
67
+ function allowance(address owner, address spender) external view returns (uint256);
68
+
69
+ /**
70
+ * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
71
+ *
72
+ * Returns a boolean value indicating whether the operation succeeded.
73
+ *
74
+ * IMPORTANT: Beware that changing an allowance with this method brings the risk
75
+ * that someone may use both the old and the new allowance by unfortunate
76
+ * transaction ordering. One possible solution to mitigate this race
77
+ * condition is to first reduce the spender's allowance to 0 and set the
78
+ * desired value afterwards:
79
+ * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
80
+ *
81
+ * Emits an {Approval} event.
82
+ */
83
+ function approve(address spender, uint256 amount) external returns (bool);
84
+
85
+ /**
86
+ * @dev Moves `amount` tokens from `sender` to `recipient` using the
87
+ * allowance mechanism. `amount` is then deducted from the caller's
88
+ * allowance.
89
+ *
90
+ * Returns a boolean value indicating whether the operation succeeded.
91
+ *
92
+ * Emits a {Transfer} event.
93
+ */
94
+ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
95
+
96
+ /**
97
+ * @dev Emitted when `value` tokens are moved from one account (`from`) to
98
+ * another (`to`).
99
+ *
100
+ * Note that `value` may be zero.
101
+ */
102
+ event Transfer(address indexed from, address indexed to, uint256 value);
103
+
104
+ /**
105
+ * @dev Emitted when the allowance of a `spender` for an `owner` is set by
106
+ * a call to {approve}. `value` is the new allowance.
107
+ */
108
+ event Approval(address indexed owner, address indexed spender, uint256 value);
109
+ }
110
+
111
+ // File: @openzeppelin/contracts/math/SafeMath.sol
112
+
113
+ // SPDX-License-Identifier: MIT
114
+
115
+ pragma solidity ^0.6.0;
116
+
117
+ /**
118
+ * @dev Wrappers over Solidity's arithmetic operations with added overflow
119
+ * checks.
120
+ *
121
+ * Arithmetic operations in Solidity wrap on overflow. This can easily result
122
+ * in bugs, because programmers usually assume that an overflow raises an
123
+ * error, which is the standard behavior in high level programming languages.
124
+ * `SafeMath` restores this intuition by reverting the transaction when an
125
+ * operation overflows.
126
+ *
127
+ * Using this library instead of the unchecked operations eliminates an entire
128
+ * class of bugs, so it's recommended to use it always.
129
+ */
130
+ library SafeMath {
131
+ /**
132
+ * @dev Returns the addition of two unsigned integers, reverting on
133
+ * overflow.
134
+ *
135
+ * Counterpart to Solidity's `+` operator.
136
+ *
137
+ * Requirements:
138
+ *
139
+ * - Addition cannot overflow.
140
+ */
141
+ function add(uint256 a, uint256 b) internal pure returns (uint256) {
142
+ uint256 c = a + b;
143
+ require(c >= a, "SafeMath: addition overflow");
144
+
145
+ return c;
146
+ }
147
+
148
+ /**
149
+ * @dev Returns the subtraction of two unsigned integers, reverting on
150
+ * overflow (when the result is negative).
151
+ *
152
+ * Counterpart to Solidity's `-` operator.
153
+ *
154
+ * Requirements:
155
+ *
156
+ * - Subtraction cannot overflow.
157
+ */
158
+ function sub(uint256 a, uint256 b) internal pure returns (uint256) {
159
+ return sub(a, b, "SafeMath: subtraction overflow");
160
+ }
161
+
162
+ /**
163
+ * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
164
+ * overflow (when the result is negative).
165
+ *
166
+ * Counterpart to Solidity's `-` operator.
167
+ *
168
+ * Requirements:
169
+ *
170
+ * - Subtraction cannot overflow.
171
+ */
172
+ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
173
+ require(b <= a, errorMessage);
174
+ uint256 c = a - b;
175
+
176
+ return c;
177
+ }
178
+
179
+ /**
180
+ * @dev Returns the multiplication of two unsigned integers, reverting on
181
+ * overflow.
182
+ *
183
+ * Counterpart to Solidity's `*` operator.
184
+ *
185
+ * Requirements:
186
+ *
187
+ * - Multiplication cannot overflow.
188
+ */
189
+ function mul(uint256 a, uint256 b) internal pure returns (uint256) {
190
+ // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
191
+ // benefit is lost if 'b' is also tested.
192
+ // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
193
+ if (a == 0) {
194
+ return 0;
195
+ }
196
+
197
+ uint256 c = a * b;
198
+ require(c / a == b, "SafeMath: multiplication overflow");
199
+
200
+ return c;
201
+ }
202
+
203
+ /**
204
+ * @dev Returns the integer division of two unsigned integers. Reverts on
205
+ * division by zero. The result is rounded towards zero.
206
+ *
207
+ * Counterpart to Solidity's `/` operator. Note: this function uses a
208
+ * `revert` opcode (which leaves remaining gas untouched) while Solidity
209
+ * uses an invalid opcode to revert (consuming all remaining gas).
210
+ *
211
+ * Requirements:
212
+ *
213
+ * - The divisor cannot be zero.
214
+ */
215
+ function div(uint256 a, uint256 b) internal pure returns (uint256) {
216
+ return div(a, b, "SafeMath: division by zero");
217
+ }
218
+
219
+ /**
220
+ * @dev Returns the integer division of two unsigned integers. Reverts with custom message on
221
+ * division by zero. The result is rounded towards zero.
222
+ *
223
+ * Counterpart to Solidity's `/` operator. Note: this function uses a
224
+ * `revert` opcode (which leaves remaining gas untouched) while Solidity
225
+ * uses an invalid opcode to revert (consuming all remaining gas).
226
+ *
227
+ * Requirements:
228
+ *
229
+ * - The divisor cannot be zero.
230
+ */
231
+ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
232
+ require(b > 0, errorMessage);
233
+ uint256 c = a / b;
234
+ // assert(a == b * c + a % b); // There is no case in which this doesn't hold
235
+
236
+ return c;
237
+ }
238
+
239
+ /**
240
+ * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
241
+ * Reverts when dividing by zero.
242
+ *
243
+ * Counterpart to Solidity's `%` operator. This function uses a `revert`
244
+ * opcode (which leaves remaining gas untouched) while Solidity uses an
245
+ * invalid opcode to revert (consuming all remaining gas).
246
+ *
247
+ * Requirements:
248
+ *
249
+ * - The divisor cannot be zero.
250
+ */
251
+ function mod(uint256 a, uint256 b) internal pure returns (uint256) {
252
+ return mod(a, b, "SafeMath: modulo by zero");
253
+ }
254
+
255
+ /**
256
+ * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
257
+ * Reverts with custom message when dividing by zero.
258
+ *
259
+ * Counterpart to Solidity's `%` operator. This function uses a `revert`
260
+ * opcode (which leaves remaining gas untouched) while Solidity uses an
261
+ * invalid opcode to revert (consuming all remaining gas).
262
+ *
263
+ * Requirements:
264
+ *
265
+ * - The divisor cannot be zero.
266
+ */
267
+ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
268
+ require(b != 0, errorMessage);
269
+ return a % b;
270
+ }
271
+ }
272
+
273
+ // File: @openzeppelin/contracts/utils/Address.sol
274
+
275
+ // SPDX-License-Identifier: MIT
276
+
277
+ pragma solidity ^0.6.2;
278
+
279
+ /**
280
+ * @dev Collection of functions related to the address type
281
+ */
282
+ library Address {
283
+ /**
284
+ * @dev Returns true if `account` is a contract.
285
+ *
286
+ * [IMPORTANT]
287
+ * ====
288
+ * It is unsafe to assume that an address for which this function returns
289
+ * false is an externally-owned account (EOA) and not a contract.
290
+ *
291
+ * Among others, `isContract` will return false for the following
292
+ * types of addresses:
293
+ *
294
+ * - an externally-owned account
295
+ * - a contract in construction
296
+ * - an address where a contract will be created
297
+ * - an address where a contract lived, but was destroyed
298
+ * ====
299
+ */
300
+ function isContract(address account) internal view returns (bool) {
301
+ // According to EIP-1052, 0x0 is the value returned for not-yet created accounts
302
+ // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
303
+ // for accounts without code, i.e. `keccak256('')`
304
+ bytes32 codehash;
305
+ bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
306
+ // solhint-disable-next-line no-inline-assembly
307
+ assembly { codehash := extcodehash(account) }
308
+ return (codehash != accountHash && codehash != 0x0);
309
+ }
310
+
311
+ /**
312
+ * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
313
+ * `recipient`, forwarding all available gas and reverting on errors.
314
+ *
315
+ * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
316
+ * of certain opcodes, possibly making contracts go over the 2300 gas limit
317
+ * imposed by `transfer`, making them unable to receive funds via
318
+ * `transfer`. {sendValue} removes this limitation.
319
+ *
320
+ * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
321
+ *
322
+ * IMPORTANT: because control is transferred to `recipient`, care must be
323
+ * taken to not create reentrancy vulnerabilities. Consider using
324
+ * {ReentrancyGuard} or the
325
+ * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
326
+ */
327
+ function sendValue(address payable recipient, uint256 amount) internal {
328
+ require(address(this).balance >= amount, "Address: insufficient balance");
329
+
330
+ // solhint-disable-next-line avoid-low-level-calls, avoid-call-value
331
+ (bool success, ) = recipient.call{ value: amount }("");
332
+ require(success, "Address: unable to send value, recipient may have reverted");
333
+ }
334
+
335
+ /**
336
+ * @dev Performs a Solidity function call using a low level `call`. A
337
+ * plain`call` is an unsafe replacement for a function call: use this
338
+ * function instead.
339
+ *
340
+ * If `target` reverts with a revert reason, it is bubbled up by this
341
+ * function (like regular Solidity function calls).
342
+ *
343
+ * Returns the raw returned data. To convert to the expected return value,
344
+ * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
345
+ *
346
+ * Requirements:
347
+ *
348
+ * - `target` must be a contract.
349
+ * - calling `target` with `data` must not revert.
350
+ *
351
+ * _Available since v3.1._
352
+ */
353
+ function functionCall(address target, bytes memory data) internal returns (bytes memory) {
354
+ return functionCall(target, data, "Address: low-level call failed");
355
+ }
356
+
357
+ /**
358
+ * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
359
+ * `errorMessage` as a fallback revert reason when `target` reverts.
360
+ *
361
+ * _Available since v3.1._
362
+ */
363
+ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
364
+ return _functionCallWithValue(target, data, 0, errorMessage);
365
+ }
366
+
367
+ /**
368
+ * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
369
+ * but also transferring `value` wei to `target`.
370
+ *
371
+ * Requirements:
372
+ *
373
+ * - the calling contract must have an ETH balance of at least `value`.
374
+ * - the called Solidity function must be `payable`.
375
+ *
376
+ * _Available since v3.1._
377
+ */
378
+ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
379
+ return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
380
+ }
381
+
382
+ /**
383
+ * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
384
+ * with `errorMessage` as a fallback revert reason when `target` reverts.
385
+ *
386
+ * _Available since v3.1._
387
+ */
388
+ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
389
+ require(address(this).balance >= value, "Address: insufficient balance for call");
390
+ return _functionCallWithValue(target, data, value, errorMessage);
391
+ }
392
+
393
+ function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
394
+ require(isContract(target), "Address: call to non-contract");
395
+
396
+ // solhint-disable-next-line avoid-low-level-calls
397
+ (bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
398
+ if (success) {
399
+ return returndata;
400
+ } else {
401
+ // Look for revert reason and bubble it up if present
402
+ if (returndata.length > 0) {
403
+ // The easiest way to bubble the revert reason is using memory via assembly
404
+
405
+ // solhint-disable-next-line no-inline-assembly
406
+ assembly {
407
+ let returndata_size := mload(returndata)
408
+ revert(add(32, returndata), returndata_size)
409
+ }
410
+ } else {
411
+ revert(errorMessage);
412
+ }
413
+ }
414
+ }
415
+ }
416
+
417
+ // File: @openzeppelin/contracts/token/ERC20/ERC20.sol
418
+
419
+ // SPDX-License-Identifier: MIT
420
+
421
+ pragma solidity ^0.6.0;
422
+
423
+
424
+
425
+
426
+
427
+ /**
428
+ * @dev Implementation of the {IERC20} interface.
429
+ *
430
+ * This implementation is agnostic to the way tokens are created. This means
431
+ * that a supply mechanism has to be added in a derived contract using {_mint}.
432
+ * For a generic mechanism see {ERC20PresetMinterPauser}.
433
+ *
434
+ * TIP: For a detailed writeup see our guide
435
+ * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
436
+ * to implement supply mechanisms].
437
+ *
438
+ * We have followed general OpenZeppelin guidelines: functions revert instead
439
+ * of returning `false` on failure. This behavior is nonetheless conventional
440
+ * and does not conflict with the expectations of ERC20 applications.
441
+ *
442
+ * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
443
+ * This allows applications to reconstruct the allowance for all accounts just
444
+ * by listening to said events. Other implementations of the EIP may not emit
445
+ * these events, as it isn't required by the specification.
446
+ *
447
+ * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
448
+ * functions have been added to mitigate the well-known issues around setting
449
+ * allowances. See {IERC20-approve}.
450
+ */
451
+ contract ERC20 is Context, IERC20 {
452
+ using SafeMath for uint256;
453
+ using Address for address;
454
+
455
+ mapping (address => uint256) private _balances;
456
+
457
+ mapping (address => mapping (address => uint256)) private _allowances;
458
+
459
+ uint256 private _totalSupply;
460
+
461
+ string private _name;
462
+ string private _symbol;
463
+ uint8 private _decimals;
464
+
465
+ /**
466
+ * @dev Sets the values for {name} and {symbol}, initializes {decimals} with
467
+ * a default value of 18.
468
+ *
469
+ * To select a different value for {decimals}, use {_setupDecimals}.
470
+ *
471
+ * All three of these values are immutable: they can only be set once during
472
+ * construction.
473
+ */
474
+ constructor (string memory name, string memory symbol) public {
475
+ _name = name;
476
+ _symbol = symbol;
477
+ _decimals = 18;
478
+ }
479
+
480
+ /**
481
+ * @dev Returns the name of the token.
482
+ */
483
+ function name() public view returns (string memory) {
484
+ return _name;
485
+ }
486
+
487
+ /**
488
+ * @dev Returns the symbol of the token, usually a shorter version of the
489
+ * name.
490
+ */
491
+ function symbol() public view returns (string memory) {
492
+ return _symbol;
493
+ }
494
+
495
+ /**
496
+ * @dev Returns the number of decimals used to get its user representation.
497
+ * For example, if `decimals` equals `2`, a balance of `505` tokens should
498
+ * be displayed to a user as `5,05` (`505 / 10 ** 2`).
499
+ *
500
+ * Tokens usually opt for a value of 18, imitating the relationship between
501
+ * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
502
+ * called.
503
+ *
504
+ * NOTE: This information is only used for _display_ purposes: it in
505
+ * no way affects any of the arithmetic of the contract, including
506
+ * {IERC20-balanceOf} and {IERC20-transfer}.
507
+ */
508
+ function decimals() public view returns (uint8) {
509
+ return _decimals;
510
+ }
511
+
512
+ /**
513
+ * @dev See {IERC20-totalSupply}.
514
+ */
515
+ function totalSupply() public view override returns (uint256) {
516
+ return _totalSupply;
517
+ }
518
+
519
+ /**
520
+ * @dev See {IERC20-balanceOf}.
521
+ */
522
+ function balanceOf(address account) public view override returns (uint256) {
523
+ return _balances[account];
524
+ }
525
+
526
+ /**
527
+ * @dev See {IERC20-transfer}.
528
+ *
529
+ * Requirements:
530
+ *
531
+ * - `recipient` cannot be the zero address.
532
+ * - the caller must have a balance of at least `amount`.
533
+ */
534
+ function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
535
+ _transfer(_msgSender(), recipient, amount);
536
+ return true;
537
+ }
538
+
539
+ /**
540
+ * @dev See {IERC20-allowance}.
541
+ */
542
+ function allowance(address owner, address spender) public view virtual override returns (uint256) {
543
+ return _allowances[owner][spender];
544
+ }
545
+
546
+ /**
547
+ * @dev See {IERC20-approve}.
548
+ *
549
+ * Requirements:
550
+ *
551
+ * - `spender` cannot be the zero address.
552
+ */
553
+ function approve(address spender, uint256 amount) public virtual override returns (bool) {
554
+ _approve(_msgSender(), spender, amount);
555
+ return true;
556
+ }
557
+
558
+ /**
559
+ * @dev See {IERC20-transferFrom}.
560
+ *
561
+ * Emits an {Approval} event indicating the updated allowance. This is not
562
+ * required by the EIP. See the note at the beginning of {ERC20};
563
+ *
564
+ * Requirements:
565
+ * - `sender` and `recipient` cannot be the zero address.
566
+ * - `sender` must have a balance of at least `amount`.
567
+ * - the caller must have allowance for ``sender``'s tokens of at least
568
+ * `amount`.
569
+ */
570
+ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
571
+ _transfer(sender, recipient, amount);
572
+ _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
573
+ return true;
574
+ }
575
+
576
+ /**
577
+ * @dev Atomically increases the allowance granted to `spender` by the caller.
578
+ *
579
+ * This is an alternative to {approve} that can be used as a mitigation for
580
+ * problems described in {IERC20-approve}.
581
+ *
582
+ * Emits an {Approval} event indicating the updated allowance.
583
+ *
584
+ * Requirements:
585
+ *
586
+ * - `spender` cannot be the zero address.
587
+ */
588
+ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
589
+ _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
590
+ return true;
591
+ }
592
+
593
+ /**
594
+ * @dev Atomically decreases the allowance granted to `spender` by the caller.
595
+ *
596
+ * This is an alternative to {approve} that can be used as a mitigation for
597
+ * problems described in {IERC20-approve}.
598
+ *
599
+ * Emits an {Approval} event indicating the updated allowance.
600
+ *
601
+ * Requirements:
602
+ *
603
+ * - `spender` cannot be the zero address.
604
+ * - `spender` must have allowance for the caller of at least
605
+ * `subtractedValue`.
606
+ */
607
+ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
608
+ _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
609
+ return true;
610
+ }
611
+
612
+ /**
613
+ * @dev Moves tokens `amount` from `sender` to `recipient`.
614
+ *
615
+ * This is internal function is equivalent to {transfer}, and can be used to
616
+ * e.g. implement automatic token fees, slashing mechanisms, etc.
617
+ *
618
+ * Emits a {Transfer} event.
619
+ *
620
+ * Requirements:
621
+ *
622
+ * - `sender` cannot be the zero address.
623
+ * - `recipient` cannot be the zero address.
624
+ * - `sender` must have a balance of at least `amount`.
625
+ */
626
+ function _transfer(address sender, address recipient, uint256 amount) internal virtual {
627
+ require(sender != address(0), "ERC20: transfer from the zero address");
628
+ require(recipient != address(0), "ERC20: transfer to the zero address");
629
+
630
+ _beforeTokenTransfer(sender, recipient, amount);
631
+
632
+ _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
633
+ _balances[recipient] = _balances[recipient].add(amount);
634
+ emit Transfer(sender, recipient, amount);
635
+ }
636
+
637
+ /** @dev Creates `amount` tokens and assigns them to `account`, increasing
638
+ * the total supply.
639
+ *
640
+ * Emits a {Transfer} event with `from` set to the zero address.
641
+ *
642
+ * Requirements
643
+ *
644
+ * - `to` cannot be the zero address.
645
+ */
646
+ function _mint(address account, uint256 amount) internal virtual {
647
+ require(account != address(0), "ERC20: mint to the zero address");
648
+
649
+ _beforeTokenTransfer(address(0), account, amount);
650
+
651
+ _totalSupply = _totalSupply.add(amount);
652
+ _balances[account] = _balances[account].add(amount);
653
+ emit Transfer(address(0), account, amount);
654
+ }
655
+
656
+ /**
657
+ * @dev Destroys `amount` tokens from `account`, reducing the
658
+ * total supply.
659
+ *
660
+ * Emits a {Transfer} event with `to` set to the zero address.
661
+ *
662
+ * Requirements
663
+ *
664
+ * - `account` cannot be the zero address.
665
+ * - `account` must have at least `amount` tokens.
666
+ */
667
+ function _burn(address account, uint256 amount) internal virtual {
668
+ require(account != address(0), "ERC20: burn from the zero address");
669
+
670
+ _beforeTokenTransfer(account, address(0), amount);
671
+
672
+ _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
673
+ _totalSupply = _totalSupply.sub(amount);
674
+ emit Transfer(account, address(0), amount);
675
+ }
676
+
677
+ /**
678
+ * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
679
+ *
680
+ * This is internal function is equivalent to `approve`, and can be used to
681
+ * e.g. set automatic allowances for certain subsystems, etc.
682
+ *
683
+ * Emits an {Approval} event.
684
+ *
685
+ * Requirements:
686
+ *
687
+ * - `owner` cannot be the zero address.
688
+ * - `spender` cannot be the zero address.
689
+ */
690
+ function _approve(address owner, address spender, uint256 amount) internal virtual {
691
+ require(owner != address(0), "ERC20: approve from the zero address");
692
+ require(spender != address(0), "ERC20: approve to the zero address");
693
+
694
+ _allowances[owner][spender] = amount;
695
+ emit Approval(owner, spender, amount);
696
+ }
697
+
698
+ /**
699
+ * @dev Sets {decimals} to a value other than the default one of 18.
700
+ *
701
+ * WARNING: This function should only be called from the constructor. Most
702
+ * applications that interact with token contracts will not expect
703
+ * {decimals} to ever change, and may work incorrectly if it does.
704
+ */
705
+ function _setupDecimals(uint8 decimals_) internal {
706
+ _decimals = decimals_;
707
+ }
708
+
709
+ /**
710
+ * @dev Hook that is called before any transfer of tokens. This includes
711
+ * minting and burning.
712
+ *
713
+ * Calling conditions:
714
+ *
715
+ * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
716
+ * will be to transferred to `to`.
717
+ * - when `from` is zero, `amount` tokens will be minted for `to`.
718
+ * - when `to` is zero, `amount` of ``from``'s tokens will be burned.
719
+ * - `from` and `to` are never both zero.
720
+ *
721
+ * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
722
+ */
723
+ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
724
+ }
725
+
726
+ // File: @openzeppelin/contracts/utils/EnumerableSet.sol
727
+
728
+ // SPDX-License-Identifier: MIT
729
+
730
+ pragma solidity ^0.6.0;
731
+
732
+ /**
733
+ * @dev Library for managing
734
+ * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
735
+ * types.
736
+ *
737
+ * Sets have the following properties:
738
+ *
739
+ * - Elements are added, removed, and checked for existence in constant time
740
+ * (O(1)).
741
+ * - Elements are enumerated in O(n). No guarantees are made on the ordering.
742
+ *
743
+ * ```
744
+ * contract Example {
745
+ * // Add the library methods
746
+ * using EnumerableSet for EnumerableSet.AddressSet;
747
+ *
748
+ * // Declare a set state variable
749
+ * EnumerableSet.AddressSet private mySet;
750
+ * }
751
+ * ```
752
+ *
753
+ * As of v3.0.0, only sets of type `address` (`AddressSet`) and `uint256`
754
+ * (`UintSet`) are supported.
755
+ */
756
+ library EnumerableSet {
757
+ // To implement this library for multiple types with as little code
758
+ // repetition as possible, we write it in terms of a generic Set type with
759
+ // bytes32 values.
760
+ // The Set implementation uses private functions, and user-facing
761
+ // implementations (such as AddressSet) are just wrappers around the
762
+ // underlying Set.
763
+ // This means that we can only create new EnumerableSets for types that fit
764
+ // in bytes32.
765
+
766
+ struct Set {
767
+ // Storage of set values
768
+ bytes32[] _values;
769
+
770
+ // Position of the value in the `values` array, plus 1 because index 0
771
+ // means a value is not in the set.
772
+ mapping (bytes32 => uint256) _indexes;
773
+ }
774
+
775
+ /**
776
+ * @dev Add a value to a set. O(1).
777
+ *
778
+ * Returns true if the value was added to the set, that is if it was not
779
+ * already present.
780
+ */
781
+ function _add(Set storage set, bytes32 value) private returns (bool) {
782
+ if (!_contains(set, value)) {
783
+ set._values.push(value);
784
+ // The value is stored at length-1, but we add 1 to all indexes
785
+ // and use 0 as a sentinel value
786
+ set._indexes[value] = set._values.length;
787
+ return true;
788
+ } else {
789
+ return false;
790
+ }
791
+ }
792
+
793
+ /**
794
+ * @dev Removes a value from a set. O(1).
795
+ *
796
+ * Returns true if the value was removed from the set, that is if it was
797
+ * present.
798
+ */
799
+ function _remove(Set storage set, bytes32 value) private returns (bool) {
800
+ // We read and store the value's index to prevent multiple reads from the same storage slot
801
+ uint256 valueIndex = set._indexes[value];
802
+
803
+ if (valueIndex != 0) { // Equivalent to contains(set, value)
804
+ // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
805
+ // the array, and then remove the last element (sometimes called as 'swap and pop').
806
+ // This modifies the order of the array, as noted in {at}.
807
+
808
+ uint256 toDeleteIndex = valueIndex - 1;
809
+ uint256 lastIndex = set._values.length - 1;
810
+
811
+ // When the value to delete is the last one, the swap operation is unnecessary. However, since this occurs
812
+ // so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement.
813
+
814
+ bytes32 lastvalue = set._values[lastIndex];
815
+
816
+ // Move the last value to the index where the value to delete is
817
+ set._values[toDeleteIndex] = lastvalue;
818
+ // Update the index for the moved value
819
+ set._indexes[lastvalue] = toDeleteIndex + 1; // All indexes are 1-based
820
+
821
+ // Delete the slot where the moved value was stored
822
+ set._values.pop();
823
+
824
+ // Delete the index for the deleted slot
825
+ delete set._indexes[value];
826
+
827
+ return true;
828
+ } else {
829
+ return false;
830
+ }
831
+ }
832
+
833
+ /**
834
+ * @dev Returns true if the value is in the set. O(1).
835
+ */
836
+ function _contains(Set storage set, bytes32 value) private view returns (bool) {
837
+ return set._indexes[value] != 0;
838
+ }
839
+
840
+ /**
841
+ * @dev Returns the number of values on the set. O(1).
842
+ */
843
+ function _length(Set storage set) private view returns (uint256) {
844
+ return set._values.length;
845
+ }
846
+
847
+ /**
848
+ * @dev Returns the value stored at position `index` in the set. O(1).
849
+ *
850
+ * Note that there are no guarantees on the ordering of values inside the
851
+ * array, and it may change when more values are added or removed.
852
+ *
853
+ * Requirements:
854
+ *
855
+ * - `index` must be strictly less than {length}.
856
+ */
857
+ function _at(Set storage set, uint256 index) private view returns (bytes32) {
858
+ require(set._values.length > index, "EnumerableSet: index out of bounds");
859
+ return set._values[index];
860
+ }
861
+
862
+ // AddressSet
863
+
864
+ struct AddressSet {
865
+ Set _inner;
866
+ }
867
+
868
+ /**
869
+ * @dev Add a value to a set. O(1).
870
+ *
871
+ * Returns true if the value was added to the set, that is if it was not
872
+ * already present.
873
+ */
874
+ function add(AddressSet storage set, address value) internal returns (bool) {
875
+ return _add(set._inner, bytes32(uint256(value)));
876
+ }
877
+
878
+ /**
879
+ * @dev Removes a value from a set. O(1).
880
+ *
881
+ * Returns true if the value was removed from the set, that is if it was
882
+ * present.
883
+ */
884
+ function remove(AddressSet storage set, address value) internal returns (bool) {
885
+ return _remove(set._inner, bytes32(uint256(value)));
886
+ }
887
+
888
+ /**
889
+ * @dev Returns true if the value is in the set. O(1).
890
+ */
891
+ function contains(AddressSet storage set, address value) internal view returns (bool) {
892
+ return _contains(set._inner, bytes32(uint256(value)));
893
+ }
894
+
895
+ /**
896
+ * @dev Returns the number of values in the set. O(1).
897
+ */
898
+ function length(AddressSet storage set) internal view returns (uint256) {
899
+ return _length(set._inner);
900
+ }
901
+
902
+ /**
903
+ * @dev Returns the value stored at position `index` in the set. O(1).
904
+ *
905
+ * Note that there are no guarantees on the ordering of values inside the
906
+ * array, and it may change when more values are added or removed.
907
+ *
908
+ * Requirements:
909
+ *
910
+ * - `index` must be strictly less than {length}.
911
+ */
912
+ function at(AddressSet storage set, uint256 index) internal view returns (address) {
913
+ return address(uint256(_at(set._inner, index)));
914
+ }
915
+
916
+
917
+ // UintSet
918
+
919
+ struct UintSet {
920
+ Set _inner;
921
+ }
922
+
923
+ /**
924
+ * @dev Add a value to a set. O(1).
925
+ *
926
+ * Returns true if the value was added to the set, that is if it was not
927
+ * already present.
928
+ */
929
+ function add(UintSet storage set, uint256 value) internal returns (bool) {
930
+ return _add(set._inner, bytes32(value));
931
+ }
932
+
933
+ /**
934
+ * @dev Removes a value from a set. O(1).
935
+ *
936
+ * Returns true if the value was removed from the set, that is if it was
937
+ * present.
938
+ */
939
+ function remove(UintSet storage set, uint256 value) internal returns (bool) {
940
+ return _remove(set._inner, bytes32(value));
941
+ }
942
+
943
+ /**
944
+ * @dev Returns true if the value is in the set. O(1).
945
+ */
946
+ function contains(UintSet storage set, uint256 value) internal view returns (bool) {
947
+ return _contains(set._inner, bytes32(value));
948
+ }
949
+
950
+ /**
951
+ * @dev Returns the number of values on the set. O(1).
952
+ */
953
+ function length(UintSet storage set) internal view returns (uint256) {
954
+ return _length(set._inner);
955
+ }
956
+
957
+ /**
958
+ * @dev Returns the value stored at position `index` in the set. O(1).
959
+ *
960
+ * Note that there are no guarantees on the ordering of values inside the
961
+ * array, and it may change when more values are added or removed.
962
+ *
963
+ * Requirements:
964
+ *
965
+ * - `index` must be strictly less than {length}.
966
+ */
967
+ function at(UintSet storage set, uint256 index) internal view returns (uint256) {
968
+ return uint256(_at(set._inner, index));
969
+ }
970
+ }
971
+
972
+ // File: @openzeppelin/contracts/access/AccessControl.sol
973
+
974
+ // SPDX-License-Identifier: MIT
975
+
976
+ pragma solidity ^0.6.0;
977
+
978
+
979
+
980
+
981
+ /**
982
+ * @dev Contract module that allows children to implement role-based access
983
+ * control mechanisms.
984
+ *
985
+ * Roles are referred to by their `bytes32` identifier. These should be exposed
986
+ * in the external API and be unique. The best way to achieve this is by
987
+ * using `public constant` hash digests:
988
+ *
989
+ * ```
990
+ * bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
991
+ * ```
992
+ *
993
+ * Roles can be used to represent a set of permissions. To restrict access to a
994
+ * function call, use {hasRole}:
995
+ *
996
+ * ```
997
+ * function foo() public {
998
+ * require(hasRole(MY_ROLE, msg.sender));
999
+ * ...
1000
+ * }
1001
+ * ```
1002
+ *
1003
+ * Roles can be granted and revoked dynamically via the {grantRole} and
1004
+ * {revokeRole} functions. Each role has an associated admin role, and only
1005
+ * accounts that have a role's admin role can call {grantRole} and {revokeRole}.
1006
+ *
1007
+ * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
1008
+ * that only accounts with this role will be able to grant or revoke other
1009
+ * roles. More complex role relationships can be created by using
1010
+ * {_setRoleAdmin}.
1011
+ *
1012
+ * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
1013
+ * grant and revoke this role. Extra precautions should be taken to secure
1014
+ * accounts that have been granted it.
1015
+ */
1016
+ abstract contract AccessControl is Context {
1017
+ using EnumerableSet for EnumerableSet.AddressSet;
1018
+ using Address for address;
1019
+
1020
+ struct RoleData {
1021
+ EnumerableSet.AddressSet members;
1022
+ bytes32 adminRole;
1023
+ }
1024
+
1025
+ mapping (bytes32 => RoleData) private _roles;
1026
+
1027
+ bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
1028
+
1029
+ /**
1030
+ * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
1031
+ *
1032
+ * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
1033
+ * {RoleAdminChanged} not being emitted signaling this.
1034
+ *
1035
+ * _Available since v3.1._
1036
+ */
1037
+ event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
1038
+
1039
+ /**
1040
+ * @dev Emitted when `account` is granted `role`.
1041
+ *
1042
+ * `sender` is the account that originated the contract call, an admin role
1043
+ * bearer except when using {_setupRole}.
1044
+ */
1045
+ event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
1046
+
1047
+ /**
1048
+ * @dev Emitted when `account` is revoked `role`.
1049
+ *
1050
+ * `sender` is the account that originated the contract call:
1051
+ * - if using `revokeRole`, it is the admin role bearer
1052
+ * - if using `renounceRole`, it is the role bearer (i.e. `account`)
1053
+ */
1054
+ event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
1055
+
1056
+ /**
1057
+ * @dev Returns `true` if `account` has been granted `role`.
1058
+ */
1059
+ function hasRole(bytes32 role, address account) public view returns (bool) {
1060
+ return _roles[role].members.contains(account);
1061
+ }
1062
+
1063
+ /**
1064
+ * @dev Returns the number of accounts that have `role`. Can be used
1065
+ * together with {getRoleMember} to enumerate all bearers of a role.
1066
+ */
1067
+ function getRoleMemberCount(bytes32 role) public view returns (uint256) {
1068
+ return _roles[role].members.length();
1069
+ }
1070
+
1071
+ /**
1072
+ * @dev Returns one of the accounts that have `role`. `index` must be a
1073
+ * value between 0 and {getRoleMemberCount}, non-inclusive.
1074
+ *
1075
+ * Role bearers are not sorted in any particular way, and their ordering may
1076
+ * change at any point.
1077
+ *
1078
+ * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
1079
+ * you perform all queries on the same block. See the following
1080
+ * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
1081
+ * for more information.
1082
+ */
1083
+ function getRoleMember(bytes32 role, uint256 index) public view returns (address) {
1084
+ return _roles[role].members.at(index);
1085
+ }
1086
+
1087
+ /**
1088
+ * @dev Returns the admin role that controls `role`. See {grantRole} and
1089
+ * {revokeRole}.
1090
+ *
1091
+ * To change a role's admin, use {_setRoleAdmin}.
1092
+ */
1093
+ function getRoleAdmin(bytes32 role) public view returns (bytes32) {
1094
+ return _roles[role].adminRole;
1095
+ }
1096
+
1097
+ /**
1098
+ * @dev Grants `role` to `account`.
1099
+ *
1100
+ * If `account` had not been already granted `role`, emits a {RoleGranted}
1101
+ * event.
1102
+ *
1103
+ * Requirements:
1104
+ *
1105
+ * - the caller must have ``role``'s admin role.
1106
+ */
1107
+ function grantRole(bytes32 role, address account) public virtual {
1108
+ require(hasRole(_roles[role].adminRole, _msgSender()), "AccessControl: sender must be an admin to grant");
1109
+
1110
+ _grantRole(role, account);
1111
+ }
1112
+
1113
+ /**
1114
+ * @dev Revokes `role` from `account`.
1115
+ *
1116
+ * If `account` had been granted `role`, emits a {RoleRevoked} event.
1117
+ *
1118
+ * Requirements:
1119
+ *
1120
+ * - the caller must have ``role``'s admin role.
1121
+ */
1122
+ function revokeRole(bytes32 role, address account) public virtual {
1123
+ require(hasRole(_roles[role].adminRole, _msgSender()), "AccessControl: sender must be an admin to revoke");
1124
+
1125
+ _revokeRole(role, account);
1126
+ }
1127
+
1128
+ /**
1129
+ * @dev Revokes `role` from the calling account.
1130
+ *
1131
+ * Roles are often managed via {grantRole} and {revokeRole}: this function's
1132
+ * purpose is to provide a mechanism for accounts to lose their privileges
1133
+ * if they are compromised (such as when a trusted device is misplaced).
1134
+ *
1135
+ * If the calling account had been granted `role`, emits a {RoleRevoked}
1136
+ * event.
1137
+ *
1138
+ * Requirements:
1139
+ *
1140
+ * - the caller must be `account`.
1141
+ */
1142
+ function renounceRole(bytes32 role, address account) public virtual {
1143
+ require(account == _msgSender(), "AccessControl: can only renounce roles for self");
1144
+
1145
+ _revokeRole(role, account);
1146
+ }
1147
+
1148
+ /**
1149
+ * @dev Grants `role` to `account`.
1150
+ *
1151
+ * If `account` had not been already granted `role`, emits a {RoleGranted}
1152
+ * event. Note that unlike {grantRole}, this function doesn't perform any
1153
+ * checks on the calling account.
1154
+ *
1155
+ * [WARNING]
1156
+ * ====
1157
+ * This function should only be called from the constructor when setting
1158
+ * up the initial roles for the system.
1159
+ *
1160
+ * Using this function in any other way is effectively circumventing the admin
1161
+ * system imposed by {AccessControl}.
1162
+ * ====
1163
+ */
1164
+ function _setupRole(bytes32 role, address account) internal virtual {
1165
+ _grantRole(role, account);
1166
+ }
1167
+
1168
+ /**
1169
+ * @dev Sets `adminRole` as ``role``'s admin role.
1170
+ *
1171
+ * Emits a {RoleAdminChanged} event.
1172
+ */
1173
+ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
1174
+ emit RoleAdminChanged(role, _roles[role].adminRole, adminRole);
1175
+ _roles[role].adminRole = adminRole;
1176
+ }
1177
+
1178
+ function _grantRole(bytes32 role, address account) private {
1179
+ if (_roles[role].members.add(account)) {
1180
+ emit RoleGranted(role, account, _msgSender());
1181
+ }
1182
+ }
1183
+
1184
+ function _revokeRole(bytes32 role, address account) private {
1185
+ if (_roles[role].members.remove(account)) {
1186
+ emit RoleRevoked(role, account, _msgSender());
1187
+ }
1188
+ }
1189
+ }
1190
+
1191
+ // File: contracts/common/AccessControlMixin.sol
1192
+
1193
+ pragma solidity 0.6.6;
1194
+
1195
+
1196
+ contract AccessControlMixin is AccessControl {
1197
+ string private _revertMsg;
1198
+ function _setupContractId(string memory contractId) internal {
1199
+ _revertMsg = string(abi.encodePacked(contractId, ": INSUFFICIENT_PERMISSIONS"));
1200
+ }
1201
+
1202
+ modifier only(bytes32 role) {
1203
+ require(
1204
+ hasRole(role, _msgSender()),
1205
+ _revertMsg
1206
+ );
1207
+ _;
1208
+ }
1209
+ }
1210
+
1211
+ // File: contracts/child/ChildToken/IChildToken.sol
1212
+
1213
+ pragma solidity 0.6.6;
1214
+
1215
+ interface IChildToken {
1216
+ function deposit(address user, bytes calldata depositData) external;
1217
+ }
1218
+
1219
+ // File: contracts/common/Initializable.sol
1220
+
1221
+ pragma solidity 0.6.6;
1222
+
1223
+ contract Initializable {
1224
+ bool inited = false;
1225
+
1226
+ modifier initializer() {
1227
+ require(!inited, "already inited");
1228
+ _;
1229
+ inited = true;
1230
+ }
1231
+ }
1232
+
1233
+ // File: contracts/common/EIP712Base.sol
1234
+
1235
+ pragma solidity 0.6.6;
1236
+
1237
+
1238
+ contract EIP712Base is Initializable {
1239
+ struct EIP712Domain {
1240
+ string name;
1241
+ string version;
1242
+ address verifyingContract;
1243
+ bytes32 salt;
1244
+ }
1245
+
1246
+ bytes32 internal constant EIP712_DOMAIN_TYPEHASH = keccak256(
1247
+ bytes(
1248
+ "EIP712Domain(string name,string version,address verifyingContract,bytes32 salt)"
1249
+ )
1250
+ );
1251
+ bytes32 internal domainSeperator;
1252
+
1253
+ // supposed to be called once while initializing.
1254
+ // one of the contractsa that inherits this contract follows proxy pattern
1255
+ // so it is not possible to do this in a constructor
1256
+ function _initializeEIP712(
1257
+ string memory name,
1258
+ string memory version
1259
+ )
1260
+ internal
1261
+ initializer
1262
+ {
1263
+ _setDomainSeperator(name, version);
1264
+ }
1265
+
1266
+ function _setDomainSeperator(string memory name, string memory version) internal {
1267
+ domainSeperator = keccak256(
1268
+ abi.encode(
1269
+ EIP712_DOMAIN_TYPEHASH,
1270
+ keccak256(bytes(name)),
1271
+ keccak256(bytes(version)),
1272
+ address(this),
1273
+ bytes32(getChainId())
1274
+ )
1275
+ );
1276
+ }
1277
+
1278
+ function getDomainSeperator() public view returns (bytes32) {
1279
+ return domainSeperator;
1280
+ }
1281
+
1282
+ function getChainId() public pure returns (uint256) {
1283
+ uint256 id;
1284
+ assembly {
1285
+ id := chainid()
1286
+ }
1287
+ return id;
1288
+ }
1289
+
1290
+ /**
1291
+ * Accept message hash and returns hash message in EIP712 compatible form
1292
+ * So that it can be used to recover signer from signature signed using EIP712 formatted data
1293
+ * https://eips.ethereum.org/EIPS/eip-712
1294
+ * "\\x19" makes the encoding deterministic
1295
+ * "\\x01" is the version byte to make it compatible to EIP-191
1296
+ */
1297
+ function toTypedMessageHash(bytes32 messageHash)
1298
+ internal
1299
+ view
1300
+ returns (bytes32)
1301
+ {
1302
+ return
1303
+ keccak256(
1304
+ abi.encodePacked("\x19\x01", getDomainSeperator(), messageHash)
1305
+ );
1306
+ }
1307
+ }
1308
+
1309
+ // File: contracts/common/NativeMetaTransaction.sol
1310
+
1311
+ pragma solidity 0.6.6;
1312
+
1313
+
1314
+
1315
+ contract NativeMetaTransaction is EIP712Base {
1316
+ using SafeMath for uint256;
1317
+ bytes32 private constant META_TRANSACTION_TYPEHASH = keccak256(
1318
+ bytes(
1319
+ "MetaTransaction(uint256 nonce,address from,bytes functionSignature)"
1320
+ )
1321
+ );
1322
+ event MetaTransactionExecuted(
1323
+ address userAddress,
1324
+ address payable relayerAddress,
1325
+ bytes functionSignature
1326
+ );
1327
+ mapping(address => uint256) nonces;
1328
+
1329
+ /*
1330
+ * Meta transaction structure.
1331
+ * No point of including value field here as if user is doing value transfer then he has the funds to pay for gas
1332
+ * He should call the desired function directly in that case.
1333
+ */
1334
+ struct MetaTransaction {
1335
+ uint256 nonce;
1336
+ address from;
1337
+ bytes functionSignature;
1338
+ }
1339
+
1340
+ function executeMetaTransaction(
1341
+ address userAddress,
1342
+ bytes memory functionSignature,
1343
+ bytes32 sigR,
1344
+ bytes32 sigS,
1345
+ uint8 sigV
1346
+ ) public payable returns (bytes memory) {
1347
+ MetaTransaction memory metaTx = MetaTransaction({
1348
+ nonce: nonces[userAddress],
1349
+ from: userAddress,
1350
+ functionSignature: functionSignature
1351
+ });
1352
+
1353
+ require(
1354
+ verify(userAddress, metaTx, sigR, sigS, sigV),
1355
+ "Signer and signature do not match"
1356
+ );
1357
+
1358
+ // increase nonce for user (to avoid re-use)
1359
+ nonces[userAddress] = nonces[userAddress].add(1);
1360
+
1361
+ emit MetaTransactionExecuted(
1362
+ userAddress,
1363
+ msg.sender,
1364
+ functionSignature
1365
+ );
1366
+
1367
+ // Append userAddress and relayer address at the end to extract it from calling context
1368
+ (bool success, bytes memory returnData) = address(this).call(
1369
+ abi.encodePacked(functionSignature, userAddress)
1370
+ );
1371
+ require(success, "Function call not successful");
1372
+
1373
+ return returnData;
1374
+ }
1375
+
1376
+ function hashMetaTransaction(MetaTransaction memory metaTx)
1377
+ internal
1378
+ pure
1379
+ returns (bytes32)
1380
+ {
1381
+ return
1382
+ keccak256(
1383
+ abi.encode(
1384
+ META_TRANSACTION_TYPEHASH,
1385
+ metaTx.nonce,
1386
+ metaTx.from,
1387
+ keccak256(metaTx.functionSignature)
1388
+ )
1389
+ );
1390
+ }
1391
+
1392
+ function getNonce(address user) public view returns (uint256 nonce) {
1393
+ nonce = nonces[user];
1394
+ }
1395
+
1396
+ function verify(
1397
+ address signer,
1398
+ MetaTransaction memory metaTx,
1399
+ bytes32 sigR,
1400
+ bytes32 sigS,
1401
+ uint8 sigV
1402
+ ) internal view returns (bool) {
1403
+ require(signer != address(0), "NativeMetaTransaction: INVALID_SIGNER");
1404
+ return
1405
+ signer ==
1406
+ ecrecover(
1407
+ toTypedMessageHash(hashMetaTransaction(metaTx)),
1408
+ sigV,
1409
+ sigR,
1410
+ sigS
1411
+ );
1412
+ }
1413
+ }
1414
+
1415
+ // File: contracts/ChainConstants.sol
1416
+
1417
+ pragma solidity 0.6.6;
1418
+
1419
+ contract ChainConstants {
1420
+ string constant public ERC712_VERSION = "1";
1421
+
1422
+ uint256 constant public ROOT_CHAIN_ID = 1;
1423
+ bytes constant public ROOT_CHAIN_ID_BYTES = hex"01";
1424
+
1425
+ uint256 constant public CHILD_CHAIN_ID = 137;
1426
+ bytes constant public CHILD_CHAIN_ID_BYTES = hex"89";
1427
+ }
1428
+
1429
+ // File: contracts/common/ContextMixin.sol
1430
+
1431
+ pragma solidity 0.6.6;
1432
+
1433
+ abstract contract ContextMixin {
1434
+ function msgSender()
1435
+ internal
1436
+ view
1437
+ returns (address payable sender)
1438
+ {
1439
+ if (msg.sender == address(this)) {
1440
+ bytes memory array = msg.data;
1441
+ uint256 index = msg.data.length;
1442
+ assembly {
1443
+ // Load the 32 bytes word from memory with the address on the lower 20 bytes, and mask those.
1444
+ sender := and(
1445
+ mload(add(array, index)),
1446
+ 0xffffffffffffffffffffffffffffffffffffffff
1447
+ )
1448
+ }
1449
+ } else {
1450
+ sender = msg.sender;
1451
+ }
1452
+ return sender;
1453
+ }
1454
+ }
1455
+
1456
+ // File: contracts/child/ChildToken/ChildERC20.sol
1457
+
1458
+ pragma solidity 0.6.6;
1459
+
1460
+
1461
+
1462
+
1463
+
1464
+
1465
+
1466
+
1467
+ contract ChildERC20 is
1468
+ ERC20,
1469
+ IChildToken,
1470
+ AccessControlMixin,
1471
+ NativeMetaTransaction,
1472
+ ChainConstants,
1473
+ ContextMixin
1474
+ {
1475
+ bytes32 public constant DEPOSITOR_ROLE = keccak256("DEPOSITOR_ROLE");
1476
+
1477
+ constructor(
1478
+ string memory name_,
1479
+ string memory symbol_,
1480
+ uint8 decimals_,
1481
+ address childChainManager
1482
+ ) public ERC20(name_, symbol_) {
1483
+ _setupContractId("ChildERC20");
1484
+ _setupDecimals(decimals_);
1485
+ _setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
1486
+ _setupRole(DEPOSITOR_ROLE, childChainManager);
1487
+ _initializeEIP712(name_, ERC712_VERSION);
1488
+ }
1489
+
1490
+ function _msgSender()
1491
+ internal
1492
+ override
1493
+ view
1494
+ returns (address payable sender)
1495
+ {
1496
+ return ContextMixin.msgSender();
1497
+ }
1498
+
1499
+ /**
1500
+ * @notice called when token is deposited on root chain
1501
+ * @dev Should be callable only by ChildChainManager
1502
+ * Should handle deposit by minting the required amount for user
1503
+ * Make sure minting is done only by this function
1504
+ * @param user user address for whom deposit is being done
1505
+ * @param depositData abi encoded amount
1506
+ */
1507
+ function deposit(address user, bytes calldata depositData)
1508
+ external
1509
+ override
1510
+ only(DEPOSITOR_ROLE)
1511
+ {
1512
+ uint256 amount = abi.decode(depositData, (uint256));
1513
+ _mint(user, amount);
1514
+ }
1515
+
1516
+ /**
1517
+ * @notice called when user wants to withdraw tokens back to root chain
1518
+ * @dev Should burn user's tokens. This transaction will be verified when exiting on root chain
1519
+ * @param amount amount of tokens to withdraw
1520
+ */
1521
+ function withdraw(uint256 amount) external {
1522
+ _burn(_msgSender(), amount);
1523
+ }
1524
+ }
1525
+
1526
+ // File: contracts/child/ChildToken/MaticWETH.sol
1527
+
1528
+ pragma solidity 0.6.6;
1529
+
1530
+
1531
+ contract MaticWETH is ChildERC20 {
1532
+ constructor(address childChainManager) public ChildERC20("Wrapped Ether", "WETH", 18, childChainManager) {}
1533
+ }