dequanto 0.0.1 → 0.1.3
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.
- package/.circleci/config.yml +51 -0
- package/.github/workflows/npm-publish.yml +32 -0
- package/.vscode/settings.json +42 -11
- package/actions/chains.act.ts +136 -0
- package/actions/contracts.act.ts +178 -0
- package/actions/gen.act.ts +38 -38
- package/actions/logs.act.ts +7 -0
- package/actions/rpc.act.ts +918 -0
- package/actions/safe.act.ts +7 -0
- package/actions/tokens.act.ts +41 -12
- package/configs/defi.yml +28 -0
- package/configs/dequanto.yml +377 -51
- package/data/cex/eth.csv +356 -356
- package/data/chainlink/feeds.json +3674 -0
- package/data/chains/chains.json +972 -0
- package/data/evm/eventHashes.json +19314 -0
- package/data/evm/events.json +19314 -0
- package/data/evm/functionHashes.json +121138 -0
- package/data/evm/functions.json +121140 -0
- package/data/rpc/coregeth.json +1786 -0
- package/data/rpc/eth.json +5873 -0
- package/data/rpc/flashbots.json +662 -0
- package/data/rpc/metamask.json +3673 -0
- package/data/rpc/overrides.json +104 -0
- package/data/tokens/1inch.json +11107 -4733
- package/data/tokens/arbitrum.json +1 -1
- package/data/tokens/coingecko.json +118642 -0
- package/data/tokens/sushi.json +6067 -48632
- package/exports/core.lib.ts +103 -0
- package/hardhat.config.js +41 -1
- package/importmap.json +27 -0
- package/package-bundler.json +181 -0
- package/package.json +121 -49
- package/readme.md +22 -4
- package/src/ChainAccountService.ts +216 -0
- package/src/abi/$abiCoder.ts +62 -0
- package/src/abi/$rlp.ts +126 -0
- package/src/abi/Logger.ts +24 -0
- package/src/abi/_version.ts +1 -0
- package/src/abi/abi-coder-packed.ts +90 -0
- package/src/abi/abi-coder.ts +163 -0
- package/src/abi/coders/abstract-coder.ts +455 -0
- package/src/abi/coders/address.ts +39 -0
- package/src/abi/coders/anonymous.ts +29 -0
- package/src/abi/coders/array.ts +190 -0
- package/src/abi/coders/boolean.ts +25 -0
- package/src/abi/coders/bytes.ts +41 -0
- package/src/abi/coders/fixed-bytes.ts +36 -0
- package/src/abi/coders/null.ts +28 -0
- package/src/abi/coders/number.ts +59 -0
- package/src/abi/coders/string.ts +23 -0
- package/src/abi/coders/tuple.ts +61 -0
- package/src/abi/fragments.ts +1632 -0
- package/src/blocks/BlockDateResolver.ts +159 -149
- package/src/bridges/BridgeFactory.ts +16 -16
- package/src/bridges/hop/HopAddresses.ts +1 -1
- package/src/bridges/hop/HopBridge.ts +437 -430
- package/src/bridges/hop/contracts/gen.act.ts +51 -50
- package/src/bridges/models/IBridge.ts +44 -43
- package/src/chains/PlatformFactory.ts +46 -45
- package/src/chains/arbitrum/ArbTokenProvider.ts +39 -39
- package/src/chains/arbitrum/ArbWeb3Client.ts +21 -39
- package/src/chains/arbitrum/Arbiscan.ts +21 -24
- package/src/chains/arbitrum/TokensServiceArbitrum.ts +19 -0
- package/src/chains/boba/BobaWeb3Client.ts +21 -49
- package/src/chains/boba/Bobascan.ts +22 -25
- package/src/chains/xdai/XDaiWeb3Client.ts +56 -82
- package/src/chains/xdai/XDaiscan.ts +21 -24
- package/src/class/PackedRanges.ts +213 -0
- package/src/class/PromiseEvent.ts +21 -0
- package/src/class/SubjectKind.ts +5 -0
- package/src/class/SubjectStream.ts +137 -0
- package/src/class/Subscription.ts +7 -0
- package/src/clients/BscWeb3Client.ts +21 -38
- package/src/clients/ClientEventsStream.ts +95 -33
- package/src/clients/ClientPool.ts +616 -207
- package/src/clients/ClientPoolStats.ts +70 -64
- package/src/clients/EthWeb3Client.ts +23 -36
- package/src/clients/EvmWeb3Client.ts +26 -0
- package/src/clients/PolyWeb3Client.ts +42 -91
- package/src/clients/Web3BatchRequests.ts +119 -0
- package/src/clients/Web3Client.ts +700 -134
- package/src/clients/Web3ClientFactory.ts +31 -1
- package/src/clients/compatibility/Web3.ts +186 -0
- package/src/clients/debug/ClientDebugMethods.ts +100 -0
- package/src/clients/handlers/RateLimitGuard.ts +353 -0
- package/src/clients/interfaces/IWeb3Client.ts +63 -14
- package/src/clients/interfaces/IWeb3ClientStatus.ts +21 -23
- package/src/clients/interfaces/IWeb3EndpointOptions.ts +16 -9
- package/src/clients/model/ClientStatus.ts +6 -5
- package/src/clients/model/PromiEventWrap.ts +62 -61
- package/src/clients/model/SubscriptionWrap.ts +53 -53
- package/src/clients/utils/$web3Abi.ts +29 -0
- package/src/clients/utils/ClientEndpoints.ts +32 -26
- package/src/clients/utils/ClientErrorUtil.ts +29 -26
- package/src/clients/utils/TxFactory.ts +5 -17
- package/src/config/AConfigBase.ts +35 -0
- package/src/config/Config.ts +45 -0
- package/src/config/ConfigProvider.ts +4 -0
- package/src/config/ConfigProviderBrowser.ts +21 -0
- package/src/config/ConfigProviderIsoPlatform.ts +90 -0
- package/src/config/dequanto.d.ts +5 -0
- package/src/config/interface/IConfigData.ts +63 -0
- package/src/contracts/BscContract.ts +28 -28
- package/src/contracts/Contract.ts +120 -126
- package/src/contracts/ContractAbiProvider.ts +69 -0
- package/src/contracts/ContractBase.ts +496 -60
- package/src/contracts/ContractClassFactory.ts +114 -0
- package/src/contracts/ContractCreationResolver.ts +85 -0
- package/src/contracts/ContractProvider.ts +55 -55
- package/src/contracts/ContractReader.ts +339 -87
- package/src/contracts/ContractStorageReaderBase.ts +29 -0
- package/src/contracts/ContractStream.ts +34 -18
- package/src/contracts/ContractWriter.ts +139 -97
- package/src/contracts/EthContract.ts +29 -29
- package/src/contracts/TxContract.ts +39 -43
- package/src/contracts/deploy/ContractDeployer.ts +155 -0
- package/src/contracts/deploy/ContractDeployment.ts +53 -0
- package/src/contracts/deploy/ContractSource.ts +3 -0
- package/src/contracts/deploy/Deployments.ts +672 -0
- package/src/contracts/deploy/proxy/$proxyDeploy.ts +302 -0
- package/src/contracts/deploy/proxy/ProxyDeployment.ts +401 -0
- package/src/contracts/deploy/storage/DeploymentsStorage.ts +368 -0
- package/src/contracts/utils/AbiDeserializer.ts +111 -98
- package/src/contracts/utils/ContractBaseUtils.ts +105 -0
- package/src/contracts/utils/ConvertUtils.ts +16 -16
- package/src/contracts/utils/InputDataUtils.ts +32 -93
- package/src/contracts/utils/TypeUtils.ts +21 -21
- package/src/contracts/wrappers/FnRequestWrapper.ts +15 -0
- package/src/contracts/wrappers/FnSignedWrapper.ts +42 -0
- package/src/env/BigIntSerializer.ts +19 -18
- package/src/erc4337/Erc4337Factory.ts +54 -0
- package/src/erc4337/Erc4337Service.ts +219 -0
- package/src/erc4337/Erc4337TxWriter.ts +169 -0
- package/src/erc4337/models/Erc4337Abi.ts +7 -0
- package/src/erc4337/models/IErc4337Info.ts +8 -0
- package/src/erc4337/models/UserOperation.ts +18 -0
- package/src/erc4337/utils/$erc4337.ts +31 -0
- package/src/evm/EvmBytecode.ts +298 -0
- package/src/evm/OpcodesInfo.ts +211 -0
- package/src/evm/OpcodesWalker.ts +156 -0
- package/src/evm/Stack.ts +58 -0
- package/src/evm/functions/$opcodes.ts +122 -0
- package/src/evm/functions/opcodes.spec.ts +47 -0
- package/src/evm/interfaces/IJumps.ts +3 -0
- package/src/evm/interfaces/IMemory.ts +3 -0
- package/src/evm/interfaces/IOpcode.ts +11 -0
- package/src/evm/interfaces/IStorage.ts +3 -0
- package/src/evm/opcodes/add.ts +49 -0
- package/src/evm/opcodes/addmod.ts +19 -0
- package/src/evm/opcodes/address.ts +22 -0
- package/src/evm/opcodes/and.ts +58 -0
- package/src/evm/opcodes/balance.ts +25 -0
- package/src/evm/opcodes/blockhash.ts +25 -0
- package/src/evm/opcodes/byte.ts +34 -0
- package/src/evm/opcodes/call.ts +69 -0
- package/src/evm/opcodes/callcode.ts +69 -0
- package/src/evm/opcodes/calldatacopy.ts +36 -0
- package/src/evm/opcodes/calldataload.ts +40 -0
- package/src/evm/opcodes/calldatasize.ts +21 -0
- package/src/evm/opcodes/caller.ts +22 -0
- package/src/evm/opcodes/callvalue.ts +21 -0
- package/src/evm/opcodes/codecopy.ts +37 -0
- package/src/evm/opcodes/codesize.ts +21 -0
- package/src/evm/opcodes/coinbase.ts +21 -0
- package/src/evm/opcodes/create.ts +42 -0
- package/src/evm/opcodes/create2.ts +41 -0
- package/src/evm/opcodes/delegatecall.ts +63 -0
- package/src/evm/opcodes/difficulty.ts +21 -0
- package/src/evm/opcodes/div.ts +35 -0
- package/src/evm/opcodes/dup.ts +7 -0
- package/src/evm/opcodes/eq.ts +92 -0
- package/src/evm/opcodes/exp.ts +34 -0
- package/src/evm/opcodes/extcodecopy.ts +42 -0
- package/src/evm/opcodes/extcodehash.ts +25 -0
- package/src/evm/opcodes/extcodesize.ts +25 -0
- package/src/evm/opcodes/gas.ts +21 -0
- package/src/evm/opcodes/gaslimit.ts +21 -0
- package/src/evm/opcodes/gasprice.ts +21 -0
- package/src/evm/opcodes/gt.ts +39 -0
- package/src/evm/opcodes/invalid.ts +24 -0
- package/src/evm/opcodes/iszero.ts +48 -0
- package/src/evm/opcodes/jump.ts +66 -0
- package/src/evm/opcodes/jumpdest.ts +6 -0
- package/src/evm/opcodes/jumpi.ts +367 -0
- package/src/evm/opcodes/log.ts +89 -0
- package/src/evm/opcodes/lt.ts +39 -0
- package/src/evm/opcodes/mload.ts +30 -0
- package/src/evm/opcodes/mod.ts +33 -0
- package/src/evm/opcodes/msize.ts +21 -0
- package/src/evm/opcodes/mstore.ts +33 -0
- package/src/evm/opcodes/mul.ts +38 -0
- package/src/evm/opcodes/mulmod.ts +19 -0
- package/src/evm/opcodes/not.ts +30 -0
- package/src/evm/opcodes/number.ts +21 -0
- package/src/evm/opcodes/or.ts +33 -0
- package/src/evm/opcodes/origin.ts +21 -0
- package/src/evm/opcodes/pc.ts +7 -0
- package/src/evm/opcodes/pop.ts +6 -0
- package/src/evm/opcodes/push.ts +8 -0
- package/src/evm/opcodes/return.ts +78 -0
- package/src/evm/opcodes/returndatacopy.ts +37 -0
- package/src/evm/opcodes/returndatasize.ts +21 -0
- package/src/evm/opcodes/revert.ts +64 -0
- package/src/evm/opcodes/sar.ts +33 -0
- package/src/evm/opcodes/selfdestruct.ts +26 -0
- package/src/evm/opcodes/sha3.ts +63 -0
- package/src/evm/opcodes/shl.ts +42 -0
- package/src/evm/opcodes/shr.ts +33 -0
- package/src/evm/opcodes/signextend.ts +25 -0
- package/src/evm/opcodes/sload.ts +190 -0
- package/src/evm/opcodes/sstore.ts +259 -0
- package/src/evm/opcodes/staticcall.ts +63 -0
- package/src/evm/opcodes/stop.ts +22 -0
- package/src/evm/opcodes/sub.ts +33 -0
- package/src/evm/opcodes/swap.ts +7 -0
- package/src/evm/opcodes/timestamp.ts +21 -0
- package/src/evm/opcodes/xor.ts +33 -0
- package/src/evm/utils/$bytecode.ts +76 -0
- package/src/evm/utils/BigNumber.ts +9 -0
- package/src/evm/utils/hex.ts +37 -0
- package/src/evm/utils/opcodes.ts +213 -0
- package/src/evm/utils/stringify.ts +12 -0
- package/src/evm/utils/stringifyEvents.ts +37 -0
- package/src/evm/utils/stringifyFunctions.ts +41 -0
- package/src/evm/utils/stringifyInstructions.ts +38 -0
- package/src/evm/utils/stringifyMappings.ts +65 -0
- package/src/evm/utils/stringifyStructs.ts +16 -0
- package/src/evm/utils/stringifyVariables.ts +32 -0
- package/src/explorer/BlockChainExplorerFactory.ts +644 -0
- package/src/explorer/BlockChainExplorerProvider.ts +57 -0
- package/src/explorer/BlockChainExplorerStorage.ts +124 -0
- package/src/explorer/BlockNumberCache.ts +47 -0
- package/src/explorer/Bscscan.ts +24 -0
- package/src/explorer/ContractVerifier.ts +289 -0
- package/src/explorer/ContractVerifierHtml.ts +207 -0
- package/src/explorer/Etherscan.ts +37 -0
- package/src/explorer/Evmscan.ts +8 -0
- package/src/explorer/IAbiProvider.ts +5 -0
- package/src/explorer/IBlockChainExplorer.ts +69 -0
- package/src/explorer/Polyscan.ts +24 -0
- package/src/explorer/verifiers/FsHtmlVerifier.ts +195 -0
- package/src/explorer/verifiers/IVerifier.ts +14 -0
- package/src/flashbots/FlashbotWeb3Client.ts +24 -0
- package/src/flashbots/FlashbotsProvider.ts +163 -0
- package/src/gen/Ast.ts +12 -12
- package/src/gen/ContractStorageReaderTemplate.ts +18 -0
- package/src/gen/ContractTemplate.ts +134 -36
- package/src/gen/Generator.ts +414 -227
- package/src/gen/GeneratorFromAbi.ts +451 -128
- package/src/gen/GeneratorStorageReader.ts +114 -0
- package/src/gen/utils/$gen.ts +11 -0
- package/src/gen/utils/Str.ts +40 -0
- package/src/handlers/TokenHandler.ts +77 -78
- package/src/hardhat/HardhatProvider.ts +469 -0
- package/src/hardhat/HardhatWeb3Client.ts +66 -0
- package/src/indexer/BlocksTxIndexer.ts +116 -69
- package/src/indexer/EventsIndexer.ts +379 -0
- package/src/indexer/PendingTxIndexer.ts +123 -124
- package/src/indexer/handlers/BlocksWalker.ts +420 -390
- package/src/indexer/handlers/TxQueueLoader.ts +144 -143
- package/src/indexer/storage/FsEventsIndexerStore.ts +182 -0
- package/src/indexer/storage/FsEventsMetaStore.ts +65 -0
- package/src/indexer/storage/FsEventsStoreUtils.ts +43 -0
- package/src/indexer/storage/interfaces.ts +25 -0
- package/src/json/JsonArrayMultiStore.ts +219 -0
- package/src/json/JsonArrayStore.ts +193 -310
- package/src/json/JsonObjectStore.ts +78 -239
- package/src/json/JsonStoreFs.ts +187 -0
- package/src/loggers/ILogger.ts +6 -3
- package/src/loggers/LoggerService.ts +83 -39
- package/src/loggers/TxLoggerService.ts +144 -146
- package/src/models/IContractDetails.ts +10 -8
- package/src/models/IToken.ts +35 -11
- package/src/models/ITokenGlob.ts +14 -14
- package/src/models/ITransactionDetails.ts +10 -11
- package/src/models/TAccount.ts +53 -0
- package/src/models/TAddress.ts +2 -1
- package/src/models/TBufferLike.ts +2 -2
- package/src/models/TError.ts +4 -0
- package/src/models/TEth.ts +223 -0
- package/src/models/THex.ts +1 -1
- package/src/models/TPlatform.ts +16 -1
- package/src/models/TResult.ts +6 -6
- package/src/models/TTx.ts +42 -0
- package/src/ns/NameService.ts +54 -21
- package/src/ns/providers/ANsProvider.ts +110 -0
- package/src/ns/providers/EnsProvider.ts +109 -45
- package/src/ns/providers/INsProvider.ts +31 -6
- package/src/ns/providers/SpaceIdProvider.ts +17 -0
- package/src/ns/providers/UDProvider.ts +77 -49
- package/src/ns/utils/$ns.ts +27 -15
- package/src/prebuilt/1inch/OneInchRouterContract/OneInchRouterContract.ts +313 -0
- package/src/prebuilt/amm/AmmFactoryV2Contract/AmmFactoryV2Contract.ts +298 -0
- package/src/prebuilt/amm/AmmMasterChefV2Contract/AmmMasterChefV2Contract.ts +642 -0
- package/src/prebuilt/amm/AmmPairV2Contract/AmmPairV2Contract.ts +700 -0
- package/src/prebuilt/amm/AmmPairV3Contract/AmmPairV3Contract.ts +686 -0
- package/src/prebuilt/amm/AmmRouterV2Contract/AmmRouterV2Contract.ts +404 -0
- package/src/prebuilt/amm/AmmVaultV2Contract/AmmVaultV2Contract.ts +818 -0
- package/src/prebuilt/ens/EnsBaseRegistrar/EnsBaseRegistrar.ts +711 -0
- package/src/prebuilt/ens/EnsDnsRegistrar/EnsDnsRegistrar.ts +333 -0
- package/src/prebuilt/ens/EnsEthRegistrarController/EnsEthRegistrarController.ts +477 -0
- package/src/prebuilt/ens/EnsNameWrapper/EnsNameWrapper.ts +1003 -0
- package/src/prebuilt/ens/EnsPublicResolver/EnsPublicResolver.ts +873 -0
- package/src/prebuilt/ens/EnsRegistry/EnsRegistry.ts +415 -0
- package/src/prebuilt/ens/EnsReverseRegistrar/EnsReverseRegistrar.ts +407 -0
- package/src/prebuilt/erc4337/EntryPoint/EntryPoint.ts +640 -0
- package/src/prebuilt/erc4337/SimpleAccount/SimpleAccount.ts +501 -0
- package/src/prebuilt/erc4337/SimpleAccountFactory/SimpleAccountFactory.ts +184 -0
- package/src/prebuilt/openzeppelin/AccessControl.json +206 -0
- package/src/prebuilt/openzeppelin/AccessControl.ts +257 -0
- package/src/prebuilt/openzeppelin/AccessControlCrossChain.json +219 -0
- package/src/prebuilt/openzeppelin/AccessControlCrossChain.ts +266 -0
- package/src/prebuilt/openzeppelin/AccessControlDefaultAdminRules.json +391 -0
- package/src/prebuilt/openzeppelin/AccessControlDefaultAdminRules.ts +450 -0
- package/src/prebuilt/openzeppelin/AccessControlEnumerable.json +249 -0
- package/src/prebuilt/openzeppelin/AccessControlEnumerable.ts +275 -0
- package/src/prebuilt/openzeppelin/ConditionalEscrow.json +156 -0
- package/src/prebuilt/openzeppelin/ConditionalEscrow.ts +259 -0
- package/src/prebuilt/openzeppelin/CrossChainEnabledPolygonChild.json +30 -0
- package/src/prebuilt/openzeppelin/CrossChainEnabledPolygonChild.ts +150 -0
- package/src/prebuilt/openzeppelin/EIP712.json +67 -0
- package/src/prebuilt/openzeppelin/EIP712.ts +170 -0
- package/src/prebuilt/openzeppelin/ERC1155.json +325 -0
- package/src/prebuilt/openzeppelin/ERC1155.ts +291 -0
- package/src/prebuilt/openzeppelin/ERC1155Burnable.json +360 -0
- package/src/prebuilt/openzeppelin/ERC1155Burnable.ts +309 -0
- package/src/prebuilt/openzeppelin/ERC1155Holder.json +99 -0
- package/src/prebuilt/openzeppelin/ERC1155Holder.ts +163 -0
- package/src/prebuilt/openzeppelin/ERC1155Pausable.json +353 -0
- package/src/prebuilt/openzeppelin/ERC1155Pausable.ts +338 -0
- package/src/prebuilt/openzeppelin/ERC1155PresetMinterPauser.json +734 -0
- package/src/prebuilt/openzeppelin/ERC1155PresetMinterPauser.ts +567 -0
- package/src/prebuilt/openzeppelin/ERC1155Receiver.json +99 -0
- package/src/prebuilt/openzeppelin/ERC1155Receiver.ts +163 -0
- package/src/prebuilt/openzeppelin/ERC1155Supply.json +352 -0
- package/src/prebuilt/openzeppelin/ERC1155Supply.ts +305 -0
- package/src/prebuilt/openzeppelin/ERC1155URIStorage.json +314 -0
- package/src/prebuilt/openzeppelin/ERC1155URIStorage.ts +287 -0
- package/src/prebuilt/openzeppelin/ERC165.json +21 -0
- package/src/prebuilt/openzeppelin/ERC165.ts +143 -0
- package/src/prebuilt/openzeppelin/ERC165Storage.json +21 -0
- package/src/prebuilt/openzeppelin/ERC165Storage.ts +143 -0
- package/src/prebuilt/openzeppelin/ERC1820Implementer.json +26 -0
- package/src/prebuilt/openzeppelin/ERC1820Implementer.ts +143 -0
- package/src/prebuilt/openzeppelin/ERC20.json +288 -0
- package/src/prebuilt/openzeppelin/ERC20.ts +280 -0
- package/src/prebuilt/openzeppelin/ERC20Burnable.json +303 -0
- package/src/prebuilt/openzeppelin/ERC20Burnable.ts +298 -0
- package/src/prebuilt/openzeppelin/ERC20Capped.json +285 -0
- package/src/prebuilt/openzeppelin/ERC20Capped.ts +285 -0
- package/src/prebuilt/openzeppelin/ERC20FlashMint.json +349 -0
- package/src/prebuilt/openzeppelin/ERC20FlashMint.ts +305 -0
- package/src/prebuilt/openzeppelin/ERC20Pausable.json +311 -0
- package/src/prebuilt/openzeppelin/ERC20Pausable.ts +327 -0
- package/src/prebuilt/openzeppelin/ERC20Permit.json +412 -0
- package/src/prebuilt/openzeppelin/ERC20Permit.ts +348 -0
- package/src/prebuilt/openzeppelin/ERC20PresetFixedSupply.json +329 -0
- package/src/prebuilt/openzeppelin/ERC20PresetFixedSupply.ts +302 -0
- package/src/prebuilt/openzeppelin/ERC20PresetMinterPauser.json +663 -0
- package/src/prebuilt/openzeppelin/ERC20PresetMinterPauser.ts +554 -0
- package/src/prebuilt/openzeppelin/ERC20Snapshot.json +328 -0
- package/src/prebuilt/openzeppelin/ERC20Snapshot.ts +315 -0
- package/src/prebuilt/openzeppelin/ERC20Votes.json +675 -0
- package/src/prebuilt/openzeppelin/ERC20Votes.ts +484 -0
- package/src/prebuilt/openzeppelin/ERC20VotesComp.json +718 -0
- package/src/prebuilt/openzeppelin/ERC20VotesComp.ts +502 -0
- package/src/prebuilt/openzeppelin/ERC20Wrapper.json +333 -0
- package/src/prebuilt/openzeppelin/ERC20Wrapper.ts +307 -0
- package/src/prebuilt/openzeppelin/ERC2771Context.json +21 -0
- package/src/prebuilt/openzeppelin/ERC2771Context.ts +143 -0
- package/src/prebuilt/openzeppelin/ERC2981.json +50 -0
- package/src/prebuilt/openzeppelin/ERC2981.ts +152 -0
- package/src/prebuilt/openzeppelin/ERC4626.json +662 -0
- package/src/prebuilt/openzeppelin/ERC4626.ts +470 -0
- package/src/prebuilt/openzeppelin/ERC721.json +348 -0
- package/src/prebuilt/openzeppelin/ERC721.ts +314 -0
- package/src/prebuilt/openzeppelin/ERC721Burnable.json +345 -0
- package/src/prebuilt/openzeppelin/ERC721Burnable.ts +321 -0
- package/src/prebuilt/openzeppelin/ERC721Consecutive.json +363 -0
- package/src/prebuilt/openzeppelin/ERC721Consecutive.ts +331 -0
- package/src/prebuilt/openzeppelin/ERC721Enumerable.json +388 -0
- package/src/prebuilt/openzeppelin/ERC721Enumerable.ts +337 -0
- package/src/prebuilt/openzeppelin/ERC721Holder.json +36 -0
- package/src/prebuilt/openzeppelin/ERC721Holder.ts +143 -0
- package/src/prebuilt/openzeppelin/ERC721Pausable.json +371 -0
- package/src/prebuilt/openzeppelin/ERC721Pausable.ts +361 -0
- package/src/prebuilt/openzeppelin/ERC721PresetMinterPauserAutoId.json +742 -0
- package/src/prebuilt/openzeppelin/ERC721PresetMinterPauserAutoId.ts +595 -0
- package/src/prebuilt/openzeppelin/ERC721Royalty.json +361 -0
- package/src/prebuilt/openzeppelin/ERC721Royalty.ts +319 -0
- package/src/prebuilt/openzeppelin/ERC721URIStorage.json +364 -0
- package/src/prebuilt/openzeppelin/ERC721URIStorage.ts +352 -0
- package/src/prebuilt/openzeppelin/ERC721Votes.json +637 -0
- package/src/prebuilt/openzeppelin/ERC721Votes.ts +489 -0
- package/src/prebuilt/openzeppelin/ERC721Wrapper.json +427 -0
- package/src/prebuilt/openzeppelin/ERC721Wrapper.ts +352 -0
- package/src/prebuilt/openzeppelin/ERC777.json +578 -0
- package/src/prebuilt/openzeppelin/ERC777.ts +456 -0
- package/src/prebuilt/openzeppelin/ERC777PresetFixedSupply.json +588 -0
- package/src/prebuilt/openzeppelin/ERC777PresetFixedSupply.ts +456 -0
- package/src/prebuilt/openzeppelin/Escrow.json +137 -0
- package/src/prebuilt/openzeppelin/Escrow.ts +250 -0
- package/src/prebuilt/openzeppelin/Governor.json +1010 -0
- package/src/prebuilt/openzeppelin/Governor.ts +590 -0
- package/src/prebuilt/openzeppelin/GovernorCompatibilityBravo.json +1325 -0
- package/src/prebuilt/openzeppelin/GovernorCompatibilityBravo.ts +700 -0
- package/src/prebuilt/openzeppelin/GovernorCountingSimple.json +1039 -0
- package/src/prebuilt/openzeppelin/GovernorCountingSimple.ts +599 -0
- package/src/prebuilt/openzeppelin/GovernorPreventLateQuorum.json +1074 -0
- package/src/prebuilt/openzeppelin/GovernorPreventLateQuorum.ts +652 -0
- package/src/prebuilt/openzeppelin/GovernorProposalThreshold.json +1010 -0
- package/src/prebuilt/openzeppelin/GovernorProposalThreshold.ts +590 -0
- package/src/prebuilt/openzeppelin/GovernorSettings.json +1106 -0
- package/src/prebuilt/openzeppelin/GovernorSettings.ts +686 -0
- package/src/prebuilt/openzeppelin/GovernorTimelockCompound.json +1134 -0
- package/src/prebuilt/openzeppelin/GovernorTimelockCompound.ts +683 -0
- package/src/prebuilt/openzeppelin/GovernorTimelockControl.json +1127 -0
- package/src/prebuilt/openzeppelin/GovernorTimelockControl.ts +672 -0
- package/src/prebuilt/openzeppelin/GovernorVotes.json +1023 -0
- package/src/prebuilt/openzeppelin/GovernorVotes.ts +599 -0
- package/src/prebuilt/openzeppelin/GovernorVotesComp.json +1023 -0
- package/src/prebuilt/openzeppelin/GovernorVotesComp.ts +599 -0
- package/src/prebuilt/openzeppelin/GovernorVotesQuorumFraction.json +1100 -0
- package/src/prebuilt/openzeppelin/GovernorVotesQuorumFraction.ts +653 -0
- package/src/prebuilt/openzeppelin/IAMB.json +327 -0
- package/src/prebuilt/openzeppelin/IAMB.ts +330 -0
- package/src/prebuilt/openzeppelin/IAccessControl.json +174 -0
- package/src/prebuilt/openzeppelin/IAccessControl.ts +239 -0
- package/src/prebuilt/openzeppelin/IAccessControlDefaultAdminRules.json +346 -0
- package/src/prebuilt/openzeppelin/IAccessControlDefaultAdminRules.ts +423 -0
- package/src/prebuilt/openzeppelin/IAccessControlEnumerable.json +217 -0
- package/src/prebuilt/openzeppelin/IAccessControlEnumerable.ts +257 -0
- package/src/prebuilt/openzeppelin/IArbSys.json +355 -0
- package/src/prebuilt/openzeppelin/IArbSys.ts +300 -0
- package/src/prebuilt/openzeppelin/IBeacon.json +15 -0
- package/src/prebuilt/openzeppelin/IBeacon.ts +143 -0
- package/src/prebuilt/openzeppelin/IBridge.json +529 -0
- package/src/prebuilt/openzeppelin/IBridge.ts +430 -0
- package/src/prebuilt/openzeppelin/ICompoundTimelock.json +415 -0
- package/src/prebuilt/openzeppelin/ICompoundTimelock.ts +380 -0
- package/src/prebuilt/openzeppelin/ICrossDomainMessenger.json +101 -0
- package/src/prebuilt/openzeppelin/ICrossDomainMessenger.ts +208 -0
- package/src/prebuilt/openzeppelin/IERC1155.json +295 -0
- package/src/prebuilt/openzeppelin/IERC1155.ts +278 -0
- package/src/prebuilt/openzeppelin/IERC1155MetadataURI.json +314 -0
- package/src/prebuilt/openzeppelin/IERC1155MetadataURI.ts +287 -0
- package/src/prebuilt/openzeppelin/IERC1155Receiver.json +99 -0
- package/src/prebuilt/openzeppelin/IERC1155Receiver.ts +163 -0
- package/src/prebuilt/openzeppelin/IERC1271.json +26 -0
- package/src/prebuilt/openzeppelin/IERC1271.ts +143 -0
- package/src/prebuilt/openzeppelin/IERC1363.json +373 -0
- package/src/prebuilt/openzeppelin/IERC1363.ts +287 -0
- package/src/prebuilt/openzeppelin/IERC1363Receiver.json +36 -0
- package/src/prebuilt/openzeppelin/IERC1363Receiver.ts +143 -0
- package/src/prebuilt/openzeppelin/IERC1363Spender.json +31 -0
- package/src/prebuilt/openzeppelin/IERC1363Spender.ts +143 -0
- package/src/prebuilt/openzeppelin/IERC165.json +21 -0
- package/src/prebuilt/openzeppelin/IERC165.ts +143 -0
- package/src/prebuilt/openzeppelin/IERC1820Implementer.json +26 -0
- package/src/prebuilt/openzeppelin/IERC1820Implementer.ts +143 -0
- package/src/prebuilt/openzeppelin/IERC1820Registry.json +215 -0
- package/src/prebuilt/openzeppelin/IERC1820Registry.ts +245 -0
- package/src/prebuilt/openzeppelin/IERC1822Proxiable.json +15 -0
- package/src/prebuilt/openzeppelin/IERC1822Proxiable.ts +143 -0
- package/src/prebuilt/openzeppelin/IERC20.json +185 -0
- package/src/prebuilt/openzeppelin/IERC20.ts +227 -0
- package/src/prebuilt/openzeppelin/IERC20Metadata.json +224 -0
- package/src/prebuilt/openzeppelin/IERC20Metadata.ts +254 -0
- package/src/prebuilt/openzeppelin/IERC20Permit.json +77 -0
- package/src/prebuilt/openzeppelin/IERC20Permit.ts +161 -0
- package/src/prebuilt/openzeppelin/IERC2612.json +77 -0
- package/src/prebuilt/openzeppelin/IERC2612.ts +161 -0
- package/src/prebuilt/openzeppelin/IERC2981.json +50 -0
- package/src/prebuilt/openzeppelin/IERC2981.ts +152 -0
- package/src/prebuilt/openzeppelin/IERC3156FlashBorrower.json +41 -0
- package/src/prebuilt/openzeppelin/IERC3156FlashBorrower.ts +143 -0
- package/src/prebuilt/openzeppelin/IERC3156FlashLender.json +79 -0
- package/src/prebuilt/openzeppelin/IERC3156FlashLender.ts +161 -0
- package/src/prebuilt/openzeppelin/IERC4626.json +614 -0
- package/src/prebuilt/openzeppelin/IERC4626.ts +448 -0
- package/src/prebuilt/openzeppelin/IERC4906.json +319 -0
- package/src/prebuilt/openzeppelin/IERC4906.ts +325 -0
- package/src/prebuilt/openzeppelin/IERC5267.json +51 -0
- package/src/prebuilt/openzeppelin/IERC5267.ts +157 -0
- package/src/prebuilt/openzeppelin/IERC5313.json +15 -0
- package/src/prebuilt/openzeppelin/IERC5313.ts +143 -0
- package/src/prebuilt/openzeppelin/IERC5805.json +210 -0
- package/src/prebuilt/openzeppelin/IERC5805.ts +243 -0
- package/src/prebuilt/openzeppelin/IERC6372.json +28 -0
- package/src/prebuilt/openzeppelin/IERC6372.ts +152 -0
- package/src/prebuilt/openzeppelin/IERC721.json +287 -0
- package/src/prebuilt/openzeppelin/IERC721.ts +283 -0
- package/src/prebuilt/openzeppelin/IERC721Enumerable.json +343 -0
- package/src/prebuilt/openzeppelin/IERC721Enumerable.ts +310 -0
- package/src/prebuilt/openzeppelin/IERC721Metadata.json +332 -0
- package/src/prebuilt/openzeppelin/IERC721Metadata.ts +310 -0
- package/src/prebuilt/openzeppelin/IERC721Receiver.json +36 -0
- package/src/prebuilt/openzeppelin/IERC721Receiver.ts +143 -0
- package/src/prebuilt/openzeppelin/IERC777.json +393 -0
- package/src/prebuilt/openzeppelin/IERC777.ts +359 -0
- package/src/prebuilt/openzeppelin/IERC777Recipient.json +40 -0
- package/src/prebuilt/openzeppelin/IERC777Recipient.ts +143 -0
- package/src/prebuilt/openzeppelin/IERC777Sender.json +40 -0
- package/src/prebuilt/openzeppelin/IERC777Sender.ts +143 -0
- package/src/prebuilt/openzeppelin/IFxMessageProcessor.json +25 -0
- package/src/prebuilt/openzeppelin/IFxMessageProcessor.ts +143 -0
- package/src/prebuilt/openzeppelin/IGovernor.json +762 -0
- package/src/prebuilt/openzeppelin/IGovernor.ts +471 -0
- package/src/prebuilt/openzeppelin/IGovernorCompatibilityBravo.json +992 -0
- package/src/prebuilt/openzeppelin/IGovernorCompatibilityBravo.ts +536 -0
- package/src/prebuilt/openzeppelin/IGovernorTimelock.json +847 -0
- package/src/prebuilt/openzeppelin/IGovernorTimelock.ts +521 -0
- package/src/prebuilt/openzeppelin/IInbox.json +444 -0
- package/src/prebuilt/openzeppelin/IInbox.ts +337 -0
- package/src/prebuilt/openzeppelin/IOutbox.json +410 -0
- package/src/prebuilt/openzeppelin/IOutbox.ts +317 -0
- package/src/prebuilt/openzeppelin/ITransparentUpgradeableProxy.json +117 -0
- package/src/prebuilt/openzeppelin/ITransparentUpgradeableProxy.ts +239 -0
- package/src/prebuilt/openzeppelin/IVotes.json +184 -0
- package/src/prebuilt/openzeppelin/IVotes.ts +225 -0
- package/src/prebuilt/openzeppelin/LibArbitrumL2.json +15 -0
- package/src/prebuilt/openzeppelin/LibArbitrumL2.ts +143 -0
- package/src/prebuilt/openzeppelin/MinimalForwarder.json +208 -0
- package/src/prebuilt/openzeppelin/MinimalForwarder.ts +201 -0
- package/src/prebuilt/openzeppelin/Multicall.json +21 -0
- package/src/prebuilt/openzeppelin/Multicall.ts +143 -0
- package/src/prebuilt/openzeppelin/Ownable.json +54 -0
- package/src/prebuilt/openzeppelin/Ownable.ts +177 -0
- package/src/prebuilt/openzeppelin/Ownable2Step.json +93 -0
- package/src/prebuilt/openzeppelin/Ownable2Step.ts +218 -0
- package/src/prebuilt/openzeppelin/Pausable.json +41 -0
- package/src/prebuilt/openzeppelin/Pausable.ts +178 -0
- package/src/prebuilt/openzeppelin/PaymentSplitter.json +304 -0
- package/src/prebuilt/openzeppelin/PaymentSplitter.ts +296 -0
- package/src/prebuilt/openzeppelin/ProxyAdmin.json +151 -0
- package/src/prebuilt/openzeppelin/ProxyAdmin.ts +228 -0
- package/src/prebuilt/openzeppelin/PullPayment.json +34 -0
- package/src/prebuilt/openzeppelin/PullPayment.ts +152 -0
- package/src/prebuilt/openzeppelin/RefundEscrow.json +226 -0
- package/src/prebuilt/openzeppelin/RefundEscrow.ts +356 -0
- package/src/prebuilt/openzeppelin/TimelockController.json +891 -0
- package/src/prebuilt/openzeppelin/TimelockController.ts +573 -0
- package/src/prebuilt/openzeppelin/TokenTimelock.json +69 -0
- package/src/prebuilt/openzeppelin/TokenTimelock.ts +174 -0
- package/src/prebuilt/openzeppelin/UUPSUpgradeable.json +91 -0
- package/src/prebuilt/openzeppelin/UUPSUpgradeable.ts +219 -0
- package/src/prebuilt/openzeppelin/UpgradeableBeacon.json +104 -0
- package/src/prebuilt/openzeppelin/UpgradeableBeacon.ts +222 -0
- package/src/prebuilt/openzeppelin/VestingWallet.json +225 -0
- package/src/prebuilt/openzeppelin/VestingWallet.ts +254 -0
- package/src/prebuilt/openzeppelin/Votes.json +307 -0
- package/src/prebuilt/openzeppelin/Votes.ts +304 -0
- package/src/prebuilt/openzeppelin/compiled/TransparentUpgradeableProxy/TransparentUpgradeableProxy.ts +214 -0
- package/src/prebuilt/safe/CreateCall.ts +168 -0
- package/src/prebuilt/safe/GnosisSafe.ts +683 -0
- package/src/prebuilt/safe/MultiSend.ts +147 -0
- package/src/prebuilt/safe/Safe.ts +742 -0
- package/src/prebuilt/safe/SafeL2.ts +780 -0
- package/src/prebuilt/safe/SafeProxyFactory.ts +197 -0
- package/src/prebuilt/weth/WETH/WETH.ts +390 -0
- package/src/rpc/$rpc.ts +124 -0
- package/src/rpc/Rpc.ts +3010 -0
- package/src/rpc/RpcBase.ts +154 -0
- package/src/rpc/RpcContract.ts +179 -0
- package/src/rpc/RpcError.ts +41 -0
- package/src/rpc/RpcFunction.ts +42 -0
- package/src/rpc/RpcHandler.ts +3 -0
- package/src/rpc/RpcModelMiddleware.ts +110 -0
- package/src/rpc/RpcSubscription.ts +46 -0
- package/src/rpc/transports/HttpTransport.ts +54 -0
- package/src/rpc/transports/ITransport.ts +87 -0
- package/src/rpc/transports/MessageBasedTransport.ts +133 -0
- package/src/rpc/transports/RpcTransport.ts +66 -0
- package/src/rpc/transports/WsTransport.ts +87 -0
- package/src/rpc/transports/WsTransportIsomorphic.ts +26 -0
- package/src/rpc/transports/compatibility/EIP1193Transport.ts +38 -0
- package/src/rpc/transports/compatibility/Web3Transport.ts +35 -0
- package/src/safe/$gnosis.ts +7 -0
- package/src/safe/GnosisSafeFactory.ts +104 -0
- package/src/safe/GnosisSafeHandler.ts +472 -0
- package/src/safe/GnosisSafeService.ts +86 -0
- package/src/safe/SafeTx.ts +93 -0
- package/src/safe/abi/GnosisSafe.json +979 -0
- package/src/safe/abi/v1_4_1/CreateCall.json +68 -0
- package/src/safe/abi/v1_4_1/MultiSend.json +20 -0
- package/src/safe/abi/v1_4_1/Safe.json +999 -0
- package/src/safe/abi/v1_4_1/SafeL2.json +1104 -0
- package/src/safe/abi/v1_4_1/SafeProxyFactory.json +139 -0
- package/src/safe/transport/FileServiceTransport.ts +109 -0
- package/src/safe/transport/ISafeServiceTransport.ts +20 -0
- package/src/safe/transport/InMemoryServiceTransport.ts +84 -0
- package/src/safe/transport/SafeServiceTransport.ts +148 -0
- package/src/safe/types/SafeServiceTypes.ts +326 -0
- package/src/services/TimelockService.ts +666 -0
- package/src/solidity/SlotsDump.ts +245 -0
- package/src/solidity/SlotsParser/Ast.ts +601 -0
- package/src/solidity/SlotsParser/MappingSettersResolver.ts +681 -0
- package/src/solidity/SlotsParser/SourceFile.ts +240 -0
- package/src/solidity/SlotsParser/models.ts +32 -0
- package/src/solidity/SlotsParser.ts +497 -0
- package/src/solidity/SlotsStorage.ts +209 -0
- package/src/solidity/SolidityParser.ts +108 -0
- package/src/solidity/SourceCodeProvider.ts +83 -0
- package/src/solidity/storage/Accessor.spec.ts +45 -0
- package/src/solidity/storage/Accessor.ts +136 -0
- package/src/solidity/storage/MappingKeysLoader.ts +112 -0
- package/src/solidity/storage/SlotDynamicArray.ts +46 -0
- package/src/solidity/storage/SlotFixedArray.ts +31 -0
- package/src/solidity/storage/SlotsStorageHandler.ts +18 -0
- package/src/solidity/storage/SlotsStorageTransport.ts +215 -0
- package/src/solidity/storage/handlers/SlotBytesHandler.ts +135 -0
- package/src/solidity/storage/handlers/SlotDynamicArrayHandler.ts +58 -0
- package/src/solidity/storage/handlers/SlotFixedArrayHandler.ts +58 -0
- package/src/solidity/storage/handlers/SlotMappingHandler.ts +75 -0
- package/src/solidity/storage/handlers/SlotStringHandler.ts +27 -0
- package/src/solidity/storage/handlers/SlotStructHandler.ts +47 -0
- package/src/solidity/storage/handlers/SlotValueConstantHandler.ts +30 -0
- package/src/solidity/storage/handlers/SlotValueHandler.ts +36 -0
- package/src/solidity/storage/handlers/SlotValueImmutableHandler.ts +49 -0
- package/src/solidity/utils/$str.ts +73 -0
- package/src/solidity/utils/$types.ts +61 -0
- package/src/tokens/TokenDataProvider.ts +284 -0
- package/src/tokens/TokenExchangeService.ts +129 -126
- package/src/tokens/TokenExchanges/AmmBase/AmmUtilts.ts +16 -16
- package/src/tokens/TokenExchanges/AmmBase/V2/AmmPairV2Service.ts +228 -208
- package/src/tokens/TokenExchanges/AmmV2ExchangeBase.ts +242 -242
- package/src/tokens/TokenExchanges/AmmV2PriceQuote.ts +433 -0
- package/src/tokens/TokenExchanges/OneInchExchange.ts +114 -111
- package/src/tokens/TokenExchanges/PancakeswapExchange.ts +25 -30
- package/src/tokens/TokenExchanges/SushiswapPolygonExchange.ts +33 -30
- package/src/tokens/TokenExchanges/UniswapV2Exchange.ts +28 -0
- package/src/tokens/TokenOracles/IOracle.ts +36 -0
- package/src/tokens/TokenOracles/TokenPriceStore.ts +130 -129
- package/src/tokens/TokenOracles/amm/AmmV1Oracle.ts +219 -0
- package/src/tokens/TokenOracles/amm/AmmV2Oracle.ts +57 -0
- package/src/tokens/TokenOracles/chainlink/ChainlinkFeedProvider.ts +133 -0
- package/src/tokens/TokenOracles/chainlink/ChainlinkOracle.ts +135 -0
- package/src/tokens/TokenOracles/coingecko/CoingeckoOracle.ts +121 -0
- package/src/tokens/TokenOracles/coingecko/CoingeckoTokenProvider.ts +51 -0
- package/src/tokens/TokenPriceService.ts +273 -276
- package/src/tokens/TokenPriceServiceProvider.ts +36 -36
- package/src/tokens/TokenProviders/ITokenProvider.ts +9 -9
- package/src/tokens/TokenProviders/TPChain.ts +53 -41
- package/src/tokens/TokenProviders/TPCoingecko.ts +177 -0
- package/src/tokens/TokenProviders/TPCoinmarketcap.ts +82 -82
- package/src/tokens/TokenProviders/TPConfig.ts +53 -0
- package/src/tokens/TokenProviders/TPExplorer.ts +41 -0
- package/src/tokens/TokenProviders/TPOneInch.ts +71 -71
- package/src/tokens/TokenProviders/TPSushiswap.ts +88 -96
- package/src/tokens/TokenProviders/TPUniswap.ts +87 -85
- package/src/tokens/TokenService.ts +142 -128
- package/src/tokens/TokenSwapService.ts +44 -47
- package/src/tokens/TokenTransferService.ts +233 -216
- package/src/tokens/TokensService.ts +42 -186
- package/src/tokens/TokensServiceBsc.ts +17 -17
- package/src/tokens/TokensServiceEth.ts +9 -9
- package/src/tokens/TokensServiceFactory.ts +15 -1
- package/src/tokens/TokensServicePolygon.ts +17 -17
- package/src/tokens/TokensServiceXDai.ts +26 -26
- package/src/tokens/defi/ISwapService.ts +12 -12
- package/src/tokens/defi/paraswap/Paraswap.ts +242 -244
- package/src/tokens/utils/TokenUtils.ts +63 -63
- package/src/txs/ITxBuilderOptions.ts +41 -0
- package/src/txs/TxDataBuilder.ts +308 -207
- package/src/txs/TxLogger.ts +120 -121
- package/src/txs/TxNonceManager.ts +86 -0
- package/src/txs/TxProvider.ts +70 -68
- package/src/txs/TxService.ts +20 -19
- package/src/txs/TxWriter.ts +342 -78
- package/src/txs/agents/Erc4337Agent.ts +32 -0
- package/src/txs/agents/SafeAgent.ts +20 -0
- package/src/txs/agents/TxWriterAccountAgents.ts +27 -0
- package/src/txs/conditional/GasWatcherLogger.ts +57 -57
- package/src/txs/conditional/GasWatcherService.ts +116 -117
- package/src/txs/conditional/GasWatcherStore.ts +41 -40
- package/src/txs/conditional/GasWatcherTx.ts +142 -143
- package/src/txs/receipt/ITxLogItem.ts +31 -25
- package/src/txs/receipt/TxLogParser.ts +56 -29
- package/src/txs/receipt/TxLogsTransfer.ts +61 -61
- package/src/txs/receipt/TxTopicInMemoryProvider.ts +45 -45
- package/src/txs/receipt/TxTopicProvider.ts +29 -29
- package/src/txs/sig-transports/SigFileTransport.ts +49 -0
- package/src/types/TAbi.ts +32 -0
- package/src/utils/$abiParser.ts +245 -179
- package/src/utils/$abiType.ts +277 -85
- package/src/utils/$abiUtils.ts +332 -38
- package/src/utils/$account.ts +48 -0
- package/src/utils/$address.ts +71 -37
- package/src/utils/$array.ts +113 -57
- package/src/utils/$base.ts +67 -0
- package/src/utils/$bigfloat.ts +562 -0
- package/src/utils/$bigint.ts +238 -127
- package/src/utils/$block.ts +20 -7
- package/src/utils/$bloom.ts +43 -0
- package/src/utils/$buffer.ts +196 -0
- package/src/utils/$cache.ts +7 -0
- package/src/utils/$class.ts +8 -8
- package/src/utils/$cli.ts +42 -0
- package/src/utils/$color.ts +213 -0
- package/src/utils/$config.ts +80 -17
- package/src/utils/$const.ts +1 -0
- package/src/utils/$contract.ts +309 -67
- package/src/utils/$crypto.ts +223 -0
- package/src/utils/$csv.ts +70 -54
- package/src/utils/$date.ts +697 -473
- package/src/utils/$error.ts +16 -0
- package/src/utils/$fn.ts +134 -134
- package/src/utils/$gas.ts +26 -0
- package/src/utils/$hex.ts +133 -0
- package/src/utils/$http.ts +219 -0
- package/src/utils/$is.ts +73 -37
- package/src/utils/$logger.ts +216 -10
- package/src/utils/$machine.ts +85 -0
- package/src/utils/$number.ts +135 -89
- package/src/utils/$object.ts +95 -95
- package/src/utils/$path.ts +76 -32
- package/src/utils/$perf.ts +20 -0
- package/src/utils/$platform.ts +5 -0
- package/src/utils/$promise.ts +154 -7
- package/src/utils/$regexp.ts +16 -0
- package/src/utils/$require.ts +212 -118
- package/src/utils/$secret.ts +27 -0
- package/src/utils/$semver.ts +27 -0
- package/src/utils/$sig.ts +722 -0
- package/src/utils/$sign.ts +136 -36
- package/src/utils/$signRaw.ts +50 -0
- package/src/utils/$signRawNative.ts +105 -0
- package/src/utils/$signSerializer.ts +27 -21
- package/src/utils/$txData.ts +23 -0
- package/src/utils/$wallet.ts +3 -10
- package/src/utils/types.ts +58 -29
- package/src/wallets/Wallet.ts +33 -33
- package/src/wallets/WalletBsc.ts +13 -13
- package/src/wallets/WalletService.ts +43 -43
- package/test/Batch.spec.ts +89 -0
- package/test/BlockChainExplorer.spec.ts +24 -0
- package/test/ChainAccount.spec.ts +52 -9
- package/test/Fixtures.ts +36 -0
- package/test/Web3Client.spec.ts +81 -0
- package/test/browser/block.spec.ts +9 -0
- package/test/client/block.spec.ts +19 -0
- package/test/config.js +68 -0
- package/test/config.spec.ts +31 -0
- package/test/config.yml +4 -0
- package/test/contracts/ContractCreationResolver.spec.ts +26 -0
- package/test/ecrecover.spec.ts +63 -0
- package/test/erc2612/PermitToken.sol +10 -0
- package/test/erc4337/erc4337.spec.ts +407 -0
- package/test/fixtures/DaiTokenContract.ts +13 -13
- package/test/fixtures/abi/deployments.json +105 -0
- package/test/fixtures/abi/encode.json +23798 -0
- package/test/fixtures/abi/encodePacked.json +34586 -0
- package/test/fixtures/artifacts/AnyERC20/AnyERC20.json +340 -0
- package/test/fixtures/artifacts/AnyERC20/AnyERC20.sol +15 -0
- package/test/fixtures/contracts/AlphaKlimaSimple.sol +36 -0
- package/test/fixtures/contracts/Counter.sol +25 -0
- package/test/fixtures/contracts/Ecrecover.sol +33 -0
- package/test/fixtures/contracts/Foo.sol +49 -0
- package/test/fixtures/contracts/FooErc20.sol +7 -0
- package/test/fixtures/contracts/FooNestedModel.sol +6 -0
- package/test/fixtures/contracts/FreeToken.sol +263 -0
- package/test/fixtures/deployments/DeploymentsFoo.sol +14 -0
- package/test/fixtures/deployments/DeploymentsFooV2.sol +11 -0
- package/test/fixtures/deployments/DeploymentsFooV3.sol +12 -0
- package/test/fixtures/erc4337/core/BaseAccount.sol +107 -0
- package/test/fixtures/erc4337/core/BasePaymaster.sol +112 -0
- package/test/fixtures/erc4337/core/EntryPoint.sol +631 -0
- package/test/fixtures/erc4337/core/Helpers.sol +81 -0
- package/test/fixtures/erc4337/core/NonceManager.sol +40 -0
- package/test/fixtures/erc4337/core/SenderCreator.sol +28 -0
- package/test/fixtures/erc4337/core/StakeManager.sol +124 -0
- package/test/fixtures/erc4337/interfaces/IAccount.sol +34 -0
- package/test/fixtures/erc4337/interfaces/IAggregator.sol +36 -0
- package/test/fixtures/erc4337/interfaces/IEntryPoint.sol +205 -0
- package/test/fixtures/erc4337/interfaces/INonceManager.sol +27 -0
- package/test/fixtures/erc4337/interfaces/IPaymaster.sol +51 -0
- package/test/fixtures/erc4337/interfaces/IStakeManager.sol +104 -0
- package/test/fixtures/erc4337/interfaces/UserOperation.sol +91 -0
- package/test/fixtures/erc4337/samples/DepositPaymaster.sol +167 -0
- package/test/fixtures/erc4337/samples/IOracle.sol +11 -0
- package/test/fixtures/erc4337/samples/SimpleAccount.sol +138 -0
- package/test/fixtures/erc4337/samples/SimpleAccountFactory.sol +52 -0
- package/test/fixtures/erc4337/samples/TokenPaymaster.sol +113 -0
- package/test/fixtures/erc4337/samples/VerifyingPaymaster.sol +104 -0
- package/test/fixtures/erc4337/samples/bls/BLSAccount.sol +64 -0
- package/test/fixtures/erc4337/samples/bls/BLSAccountFactory.sol +61 -0
- package/test/fixtures/erc4337/samples/bls/BLSHelper.sol +232 -0
- package/test/fixtures/erc4337/samples/bls/BLSSignatureAggregator.sol +164 -0
- package/test/fixtures/erc4337/samples/bls/IBLSAccount.sol +16 -0
- package/test/fixtures/erc4337/samples/bls/lib/BLSOpen.sol +64 -0
- package/test/fixtures/erc4337/samples/bls/lib/hubble-contracts/contracts/libs/BLS.sol +440 -0
- package/test/fixtures/erc4337/samples/bls/lib/hubble-contracts/contracts/libs/BNPairingPrecompileCostEstimator.sol +108 -0
- package/test/fixtures/erc4337/samples/bls/lib/hubble-contracts/contracts/libs/ModExp.sol +652 -0
- package/test/fixtures/erc4337/samples/callback/TokenCallbackHandler.sol +61 -0
- package/test/fixtures/erc4337/utils/Exec.sol +70 -0
- package/test/fixtures/explorer/0xfbD2aa7efA2B46Ce3c58D7ab0D92C176c71499C0.html +2788 -0
- package/test/fixtures/gnosis/GnosisSafe.sol +422 -0
- package/test/fixtures/gnosis/GnosisSafeL2.sol +86 -0
- package/test/fixtures/gnosis/accessors/SimulateTxAccessor.sol +52 -0
- package/test/fixtures/gnosis/base/Executor.sol +27 -0
- package/test/fixtures/gnosis/base/FallbackManager.sol +53 -0
- package/test/fixtures/gnosis/base/GuardManager.sol +62 -0
- package/test/fixtures/gnosis/base/ModuleManager.sol +133 -0
- package/test/fixtures/gnosis/base/OwnerManager.sol +149 -0
- package/test/fixtures/gnosis/common/Enum.sol +8 -0
- package/test/fixtures/gnosis/common/EtherPaymentFallback.sol +13 -0
- package/test/fixtures/gnosis/common/SecuredTokenTransfer.sol +35 -0
- package/test/fixtures/gnosis/common/SelfAuthorized.sol +16 -0
- package/test/fixtures/gnosis/common/SignatureDecoder.sol +36 -0
- package/test/fixtures/gnosis/common/Singleton.sol +11 -0
- package/test/fixtures/gnosis/common/StorageAccessible.sol +47 -0
- package/test/fixtures/gnosis/external/GnosisSafeMath.sol +54 -0
- package/test/fixtures/gnosis/interfaces/ERC1155TokenReceiver.sol +49 -0
- package/test/fixtures/gnosis/interfaces/ERC721TokenReceiver.sol +24 -0
- package/test/fixtures/gnosis/interfaces/ERC777TokensRecipient.sol +13 -0
- package/test/fixtures/gnosis/interfaces/IERC165.sol +15 -0
- package/test/fixtures/gnosis/interfaces/ISignatureValidator.sol +20 -0
- package/test/fixtures/gnosis/interfaces/ViewStorageAccessible.sol +11 -0
- package/test/fixtures/gnosis/libraries/CreateCall.sol +30 -0
- package/test/fixtures/gnosis/libraries/GnosisSafeStorage.sol +21 -0
- package/test/fixtures/gnosis/libraries/MultiSend.sol +66 -0
- package/test/fixtures/gnosis/libraries/MultiSendCallOnly.sol +61 -0
- package/test/fixtures/gnosis/libraries/SignMessageLib.sol +34 -0
- package/test/fixtures/gnosis/proxies/GnosisSafeProxy.sol +44 -0
- package/test/fixtures/gnosis/proxies/GnosisSafeProxyFactory.sol +107 -0
- package/test/fixtures/gnosis/proxies/IProxyCreationCallback.sol +12 -0
- package/test/fixtures/mapping-setters/GTC.sol +611 -0
- package/test/fixtures/mapping-setters/UniswapV3Staker/Address.sol +189 -0
- package/test/fixtures/mapping-setters/UniswapV3Staker/FullMath.sol +124 -0
- package/test/fixtures/mapping-setters/UniswapV3Staker/IERC165.sol +24 -0
- package/test/fixtures/mapping-setters/UniswapV3Staker/IERC20.sol +77 -0
- package/test/fixtures/mapping-setters/UniswapV3Staker/IERC20Minimal.sol +52 -0
- package/test/fixtures/mapping-setters/UniswapV3Staker/IERC721.sol +129 -0
- package/test/fixtures/mapping-setters/UniswapV3Staker/IERC721Enumerable.sol +29 -0
- package/test/fixtures/mapping-setters/UniswapV3Staker/IERC721Metadata.sol +27 -0
- package/test/fixtures/mapping-setters/UniswapV3Staker/IERC721Permit.sol +32 -0
- package/test/fixtures/mapping-setters/UniswapV3Staker/IERC721Receiver.sol +21 -0
- package/test/fixtures/mapping-setters/UniswapV3Staker/IMulticall.sol +13 -0
- package/test/fixtures/mapping-setters/UniswapV3Staker/INonfungiblePositionManager.sol +180 -0
- package/test/fixtures/mapping-setters/UniswapV3Staker/IPeripheryImmutableState.sol +12 -0
- package/test/fixtures/mapping-setters/UniswapV3Staker/IPeripheryPayments.sol +28 -0
- package/test/fixtures/mapping-setters/UniswapV3Staker/IPoolInitializer.sol +22 -0
- package/test/fixtures/mapping-setters/UniswapV3Staker/IUniswapV3Factory.sol +78 -0
- package/test/fixtures/mapping-setters/UniswapV3Staker/IUniswapV3Pool.sol +24 -0
- package/test/fixtures/mapping-setters/UniswapV3Staker/IUniswapV3PoolActions.sol +103 -0
- package/test/fixtures/mapping-setters/UniswapV3Staker/IUniswapV3PoolDerivedState.sol +40 -0
- package/test/fixtures/mapping-setters/UniswapV3Staker/IUniswapV3PoolEvents.sol +121 -0
- package/test/fixtures/mapping-setters/UniswapV3Staker/IUniswapV3PoolImmutables.sol +35 -0
- package/test/fixtures/mapping-setters/UniswapV3Staker/IUniswapV3PoolOwnerActions.sol +23 -0
- package/test/fixtures/mapping-setters/UniswapV3Staker/IUniswapV3PoolState.sol +116 -0
- package/test/fixtures/mapping-setters/UniswapV3Staker/IUniswapV3Staker.sol +183 -0
- package/test/fixtures/mapping-setters/UniswapV3Staker/IncentiveId.sol +14 -0
- package/test/fixtures/mapping-setters/UniswapV3Staker/Math.sol +31 -0
- package/test/fixtures/mapping-setters/UniswapV3Staker/Multicall.sol +28 -0
- package/test/fixtures/mapping-setters/UniswapV3Staker/NFTPositionInfo.sol +47 -0
- package/test/fixtures/mapping-setters/UniswapV3Staker/PoolAddress.sol +48 -0
- package/test/fixtures/mapping-setters/UniswapV3Staker/RewardMath.sol +42 -0
- package/test/fixtures/mapping-setters/UniswapV3Staker/TransferHelper.sol +60 -0
- package/test/fixtures/mapping-setters/UniswapV3Staker/TransferHelperExtended.sol +39 -0
- package/test/fixtures/mapping-setters/UniswapV3Staker/UniswapV3Staker.sol +350 -0
- package/test/fixtures/openzeppelin/Proxy.sol +11 -0
- package/test/fixtures/openzeppelin/ProxyAdmin.sol +11 -0
- package/test/fixtures/openzeppelin/beacon/BeaconProxy.sol +11 -0
- package/test/fixtures/openzeppelin/beacon/UpgradeableBeacon.sol +11 -0
- package/test/fixtures/parser/AlphaKlima.sol +36 -0
- package/test/fixtures/parser/CToken/CErc20.sol +228 -0
- package/test/fixtures/parser/CToken/CErc20Delegate.sol +44 -0
- package/test/fixtures/parser/CToken/CErc20Delegator.sol +476 -0
- package/test/fixtures/parser/CToken/CToken.sol +1156 -0
- package/test/fixtures/parser/CToken/CTokenInterfaces.sol +293 -0
- package/test/fixtures/parser/CToken/ComptrollerInterface.sol +72 -0
- package/test/fixtures/parser/CToken/EIP20Interface.sol +63 -0
- package/test/fixtures/parser/CToken/EIP20NonStandardInterface.sol +71 -0
- package/test/fixtures/parser/CToken/ErrorReporter.sol +127 -0
- package/test/fixtures/parser/CToken/ExponentialNoError.sol +171 -0
- package/test/fixtures/parser/CToken/InterestRateModel.sol +30 -0
- package/test/fixtures/parser/DAI.sol +194 -0
- package/test/fixtures/parser/PriceOracle.sol +1964 -0
- package/test/fixtures/parser/SAFE/Context.sol +24 -0
- package/test/fixtures/parser/SAFE/ERC20.sol +383 -0
- package/test/fixtures/parser/SAFE/IERC20.sol +82 -0
- package/test/fixtures/parser/SAFE/IERC20Metadata.sol +28 -0
- package/test/fixtures/parser/SAFE/Ownable.sol +76 -0
- package/test/fixtures/parser/SAFE/Pausable.sol +91 -0
- package/test/fixtures/parser/SAFE/SafeToken.sol +48 -0
- package/test/fixtures/parser/SAFE/TokenRescuer.sol +29 -0
- package/test/fixtures/parser/SomeERC20/Context.sol +24 -0
- package/test/fixtures/parser/SomeERC20/ERC20.sol +389 -0
- package/test/fixtures/parser/SomeERC20/IERC20.sol +82 -0
- package/test/fixtures/parser/SomeERC20/IERC20Metadata.sol +28 -0
- package/test/fixtures/parser/SomeERC20/Ownable.sol +83 -0
- package/test/fixtures/parser/SomeERC20/SomeToken.sol +210 -0
- package/test/fixtures/parser/TetherToken.sol +447 -0
- package/test/fixtures/parser/USDC.sol +2231 -0
- package/test/fixtures/parser/v04/ENJToken.sol +493 -0
- package/test/fixtures/parser/v04/MultiSigWallet.sol +371 -0
- package/test/fixtures/receipts/swap.json +93 -93
- package/test/fixtures/scan/WETH.sol +1533 -0
- package/test/fixtures/slots/FooStorage.sol +8 -0
- package/test/fixtures/slots/FooStorageBase.sol +6 -0
- package/test/fixtures/slots/Vault.sol +85 -0
- package/test/flashbots/flashbots.spec.ts +79 -0
- package/test/generate/class.spec.ts +293 -5
- package/test/generate/evm.spec.ts +71 -0
- package/test/generate/gen.spec.ts +69 -0
- package/test/generate/openzeppelin.spec.ts +22 -0
- package/test/generate/slotreader.spec.ts +34 -0
- package/test/hardhat/TestNode.ts +76 -61
- package/test/hardhat/compile.spec.ts +22 -0
- package/test/hardhat/deploy.spec.ts +579 -0
- package/test/hardhat/deployments/deployments.spec.ts +233 -0
- package/test/hardhat/deployments/proxy-layout.spec.ts +296 -0
- package/test/hardhat/forked.spec.ts +56 -0
- package/test/hardhat/gas.spec.ts +40 -0
- package/test/hardhat/permit.ts +33 -0
- package/test/hardhat/revert.spec.ts +30 -0
- package/test/indexer/BlocksWalker.spec.ts +51 -0
- package/test/indexer/EventsIndexer.spec.ts +170 -0
- package/test/json/JsonStore.spec.ts +170 -0
- package/test/node/block.spec.ts +11 -0
- package/test/ns.spec.ts +67 -30
- package/test/perf/calldata.spec.ts +93 -0
- package/test/receipt.spec.ts +52 -27
- package/test/rpc/rpc.spec.ts +353 -0
- package/test/rpc/rpcUtil.spec.ts +31 -0
- package/test/safe/safe.spec.ts +352 -0
- package/test/services/timelock.spec.ts +97 -0
- package/test/solidity/AbiExtractor.spec.ts +468 -0
- package/test/solidity/MappingSettersResolver.spec.ts +516 -0
- package/test/solidity/SlotsDump.spec.ts +154 -0
- package/test/solidity/SlotsParser.spec.ts +536 -0
- package/test/solidity/SlotsReader.spec.ts +388 -0
- package/test/solidity/Storage.spec.ts +404 -0
- package/test/structs/PackedRanges.spec.ts +56 -0
- package/test/subscriptions.spec.ts +127 -0
- package/test/token.spec.ts +17 -0
- package/test/tokens/oracles.spec.ts +51 -0
- package/test/utils/abi-parser-args.spec.ts +143 -0
- package/test/utils/abi-parser.spec.ts +141 -117
- package/test/utils/abi-types.spec.ts +31 -0
- package/test/utils/abi-utils.spec.ts +23 -0
- package/test/utils/abi.spec.ts +178 -0
- package/test/utils/address.spec.ts +66 -0
- package/test/utils/bigfloat/div.spec.ts +1919 -0
- package/test/utils/bigfloat/mod.spec.ts +1745 -0
- package/test/utils/bigfloat/mul.spec.ts +2085 -0
- package/test/utils/bigfloat/round.spec.ts +174 -0
- package/test/utils/bigfloat/sqrt.spec.ts +420 -0
- package/test/utils/bigint.spec.ts +39 -40
- package/test/utils/bytecode.spec.ts +107 -0
- package/test/utils/crypto.spec.ts +37 -0
- package/test/utils/date.spec.ts +9 -8
- package/test/utils/fn.spec.ts +39 -39
- package/test/utils/logbloom.spec.ts +17 -0
- package/test/utils/number.spec.ts +52 -41
- package/test/utils/rlp.spec.ts +142 -0
- package/test/utils/sign.spec.ts +327 -22
- package/tools/build-dts.ts +111 -0
- package/tools/copy-dts.ts +48 -0
- package/tsconfig-build.json +24 -24
- package/tsconfig-src.json +44 -36
- package/tsconfig.esm.json +12 -0
- package/tsconfig.json +34 -27
- package/tsconfig.umd.json +28 -0
- package/typings/globals/axios/index.d.ts +6 -6
- package/typings.json +6 -6
- package/contracts/abi/erc20.abi.json +0 -222
- package/contracts/gen/amm/AmmFactoryV2ContractBase.ts +0 -66
- package/contracts/gen/amm/AmmMasterChefV2ContractBase.ts +0 -158
- package/contracts/gen/amm/AmmPairContractV2Base.ts +0 -158
- package/contracts/gen/amm/AmmPairContractV3Base.ts +0 -125
- package/contracts/gen/amm/AmmRouterV2ContractBase.ts +0 -124
- package/contracts/gen/amm/AmmVaultV2ContractBase.ts +0 -214
- package/contracts/gen/base/ERC20Base.ts +0 -90
- package/contracts/gen/bsc/OneInchRouterV3Base.ts +0 -57
- package/contracts/gen/eth/WETHBase/WETHBase.sol +0 -756
- package/contracts/gen/eth/WETHBase.ts +0 -136
- package/contracts/gen/polygon/ERC20PolygonBase.ts +0 -305
- package/contracts/gen/polygon/WormholeBridgeContractBase/Address.sol +0 -216
- package/contracts/gen/polygon/WormholeBridgeContractBase/BeaconProxy.sol +0 -61
- package/contracts/gen/polygon/WormholeBridgeContractBase/Bridge.sol +0 -437
- package/contracts/gen/polygon/WormholeBridgeContractBase/BridgeGetters.sol +0 -70
- package/contracts/gen/polygon/WormholeBridgeContractBase/BridgeGovernance.sol +0 -142
- package/contracts/gen/polygon/WormholeBridgeContractBase/BridgeImplementation.sol +0 -34
- package/contracts/gen/polygon/WormholeBridgeContractBase/BridgeSetters.sol +0 -57
- package/contracts/gen/polygon/WormholeBridgeContractBase/BridgeState.sol +0 -52
- package/contracts/gen/polygon/WormholeBridgeContractBase/BridgeStructs.sol +0 -66
- package/contracts/gen/polygon/WormholeBridgeContractBase/BytesLib.sol +0 -510
- package/contracts/gen/polygon/WormholeBridgeContractBase/Context.sol +0 -23
- package/contracts/gen/polygon/WormholeBridgeContractBase/ERC1967Proxy.sol +0 -32
- package/contracts/gen/polygon/WormholeBridgeContractBase/ERC1967Upgrade.sol +0 -193
- package/contracts/gen/polygon/WormholeBridgeContractBase/IBeacon.sol +0 -15
- package/contracts/gen/polygon/WormholeBridgeContractBase/IERC20.sol +0 -81
- package/contracts/gen/polygon/WormholeBridgeContractBase/IWormhole.sol +0 -42
- package/contracts/gen/polygon/WormholeBridgeContractBase/Ownable.sol +0 -71
- package/contracts/gen/polygon/WormholeBridgeContractBase/Proxy.sol +0 -85
- package/contracts/gen/polygon/WormholeBridgeContractBase/SafeERC20.sol +0 -98
- package/contracts/gen/polygon/WormholeBridgeContractBase/StorageSlot.sol +0 -83
- package/contracts/gen/polygon/WormholeBridgeContractBase/Structs.sol +0 -40
- package/contracts/gen/polygon/WormholeBridgeContractBase/Token.sol +0 -12
- package/contracts/gen/polygon/WormholeBridgeContractBase/TokenBridge.sol +0 -15
- package/contracts/gen/polygon/WormholeBridgeContractBase/TokenImplementation.sol +0 -177
- package/contracts/gen/polygon/WormholeBridgeContractBase/TokenState.sol +0 -31
- package/contracts/gen/polygon/WormholeBridgeContractBase.ts +0 -231
- package/contracts/gen/xdai/WXDaiTokenContractBase.ts +0 -136
- package/dist/contracts/gen/amm/AmmFactoryV2ContractBase.js +0 -53
- package/dist/contracts/gen/amm/AmmMasterChefV2ContractBase.js +0 -122
- package/dist/contracts/gen/amm/AmmPairContractV2Base.js +0 -122
- package/dist/contracts/gen/amm/AmmPairContractV3Base.js +0 -98
- package/dist/contracts/gen/amm/AmmRouterV2ContractBase.js +0 -95
- package/dist/contracts/gen/amm/AmmVaultV2ContractBase.js +0 -164
- package/dist/contracts/gen/base/ERC20Base.js +0 -64
- package/dist/contracts/gen/bsc/OneInchRouterV3Base.js +0 -47
- package/dist/contracts/gen/eth/WETHBase.js +0 -96
- package/dist/contracts/gen/polygon/ERC20PolygonBase.js +0 -233
- package/dist/contracts/gen/polygon/WormholeBridgeContractBase.js +0 -172
- package/dist/contracts/gen/xdai/WXDaiTokenContractBase.js +0 -96
- package/dist/src/BlockchainExplorer/BlockChainExplorerFactory.js +0 -227
- package/dist/src/BlockchainExplorer/BlockChainExplorerProvider.js +0 -32
- package/dist/src/BlockchainExplorer/BlockNumberCache.js +0 -33
- package/dist/src/BlockchainExplorer/Bscscan.js +0 -27
- package/dist/src/BlockchainExplorer/Etherscan.js +0 -27
- package/dist/src/BlockchainExplorer/IAbiProvider.js +0 -2
- package/dist/src/BlockchainExplorer/IBlockChainExplorer.js +0 -2
- package/dist/src/BlockchainExplorer/Polyscan.js +0 -27
- package/dist/src/ChainAccounts.js +0 -69
- package/dist/src/ChainAccountsService.js +0 -75
- package/dist/src/Config.js +0 -7
- package/dist/src/blocks/BlockDateResolver.js +0 -125
- package/dist/src/bridges/BridgeFactory.js +0 -19
- package/dist/src/bridges/hop/HopAddresses.js +0 -520
- package/dist/src/bridges/hop/HopBridge.js +0 -327
- package/dist/src/bridges/hop/contracts/gen.act.js +0 -43
- package/dist/src/bridges/hop/contracts/polygon/Dai_l2AmmWrapperContract.js +0 -52
- package/dist/src/bridges/hop/contracts/polygon/Dai_l2BridgeContract.js +0 -319
- package/dist/src/bridges/hop/contracts/polygon/Dai_l2SaddleSwapContract.js +0 -178
- package/dist/src/bridges/hop/contracts/polygon/Eth_l2AmmWrapperContract.js +0 -52
- package/dist/src/bridges/hop/contracts/polygon/Eth_l2BridgeContract.js +0 -319
- package/dist/src/bridges/hop/contracts/polygon/Eth_l2SaddleSwapContract.js +0 -178
- package/dist/src/bridges/hop/contracts/polygon/Matic_l2AmmWrapperContract.js +0 -52
- package/dist/src/bridges/hop/contracts/polygon/Matic_l2BridgeContract.js +0 -319
- package/dist/src/bridges/hop/contracts/polygon/Matic_l2SaddleSwapContract.js +0 -178
- package/dist/src/bridges/hop/contracts/polygon/Usdc_l2AmmWrapperContract.js +0 -52
- package/dist/src/bridges/hop/contracts/polygon/Usdc_l2BridgeContract.js +0 -319
- package/dist/src/bridges/hop/contracts/polygon/Usdc_l2SaddleSwapContract.js +0 -178
- package/dist/src/bridges/hop/contracts/polygon/Usdt_l2AmmWrapperContract.js +0 -52
- package/dist/src/bridges/hop/contracts/polygon/Usdt_l2BridgeContract.js +0 -319
- package/dist/src/bridges/hop/contracts/polygon/Usdt_l2SaddleSwapContract.js +0 -178
- package/dist/src/bridges/hop/contracts/polygon/Wbtc_l2AmmWrapperContract.js +0 -52
- package/dist/src/bridges/hop/contracts/polygon/Wbtc_l2BridgeContract.js +0 -319
- package/dist/src/bridges/hop/contracts/polygon/Wbtc_l2SaddleSwapContract.js +0 -178
- package/dist/src/bridges/models/IBridge.js +0 -2
- package/dist/src/bridges/wormhole/contracts/WormholeBridgeContract.js +0 -15
- package/dist/src/chains/PlatformFactory.js +0 -42
- package/dist/src/chains/arbitrum/ArbTokenProvider.js +0 -40
- package/dist/src/chains/arbitrum/ArbWeb3Client.js +0 -39
- package/dist/src/chains/arbitrum/Arbiscan.js +0 -27
- package/dist/src/chains/boba/BobaWeb3Client.js +0 -47
- package/dist/src/chains/boba/Bobascan.js +0 -28
- package/dist/src/chains/xdai/XDaiWeb3Client.js +0 -87
- package/dist/src/chains/xdai/XDaiscan.js +0 -27
- package/dist/src/chains/xdai/tokens/WXDaiTokenContract.js +0 -15
- package/dist/src/clients/BscWeb3Client.js +0 -38
- package/dist/src/clients/ClientEventsStream.js +0 -34
- package/dist/src/clients/ClientPool.js +0 -560
- package/dist/src/clients/ClientPoolStats.js +0 -52
- package/dist/src/clients/EthWeb3Client.js +0 -35
- package/dist/src/clients/HardhatWeb3Client.js +0 -56
- package/dist/src/clients/PolyWeb3Client.js +0 -77
- package/dist/src/clients/Web3Client.js +0 -186
- package/dist/src/clients/Web3ClientFactory.js +0 -32
- package/dist/src/clients/interfaces/IWeb3Client.js +0 -2
- package/dist/src/clients/interfaces/IWeb3ClientStatus.js +0 -2
- package/dist/src/clients/interfaces/IWeb3EndpointOptions.js +0 -2
- package/dist/src/clients/model/ClientStatus.js +0 -9
- package/dist/src/clients/model/PromiEventWrap.js +0 -52
- package/dist/src/clients/model/SubscriptionWrap.js +0 -42
- package/dist/src/clients/utils/ClientEndpoints.js +0 -27
- package/dist/src/clients/utils/ClientErrorUtil.js +0 -30
- package/dist/src/clients/utils/TxFactory.js +0 -14
- package/dist/src/contracts/BscContract.js +0 -30
- package/dist/src/contracts/Contract.js +0 -90
- package/dist/src/contracts/ContractBase.js +0 -139
- package/dist/src/contracts/ContractFactory.js +0 -17
- package/dist/src/contracts/ContractProvider.js +0 -40
- package/dist/src/contracts/ContractReader.js +0 -76
- package/dist/src/contracts/ContractStream.js +0 -20
- package/dist/src/contracts/ContractWriter.js +0 -62
- package/dist/src/contracts/EthContract.js +0 -31
- package/dist/src/contracts/TxContract.js +0 -37
- package/dist/src/contracts/common/ERC20.js +0 -14
- package/dist/src/contracts/common/ERC20Polygon.js +0 -14
- package/dist/src/contracts/common/PoolPair.js +0 -23
- package/dist/src/contracts/utils/AbiDeserializer.js +0 -89
- package/dist/src/contracts/utils/ConvertUtils.js +0 -21
- package/dist/src/contracts/utils/InputDataUtils.js +0 -87
- package/dist/src/contracts/utils/TypeUtils.js +0 -24
- package/dist/src/defi/OneInch/OneInchRouter.js +0 -14
- package/dist/src/env/BigIntSerializer.js +0 -19
- package/dist/src/gen/Ast.js +0 -12
- package/dist/src/gen/ContractTemplate.js +0 -27
- package/dist/src/gen/Generator.js +0 -180
- package/dist/src/gen/GeneratorFromAbi.js +0 -361
- package/dist/src/handlers/TokenHandler.js +0 -69
- package/dist/src/indexer/BlocksTxIndexer.js +0 -52
- package/dist/src/indexer/PendingTxIndexer.js +0 -96
- package/dist/src/indexer/handlers/BlocksWalker.js +0 -306
- package/dist/src/indexer/handlers/TxQueueLoader.js +0 -117
- package/dist/src/json/JsonArrayStore.js +0 -296
- package/dist/src/json/JsonObjectStore.js +0 -214
- package/dist/src/json/JsonStore.spec.js +0 -83
- package/dist/src/loggers/ILogger.js +0 -2
- package/dist/src/loggers/LoggerService.js +0 -34
- package/dist/src/loggers/TxLoggerService.js +0 -122
- package/dist/src/models/IContractDetails.js +0 -2
- package/dist/src/models/IToken.js +0 -2
- package/dist/src/models/ITokenGlob.js +0 -6
- package/dist/src/models/ITransactionDetails.js +0 -2
- package/dist/src/models/TAddress.js +0 -2
- package/dist/src/models/TBufferLike.js +0 -2
- package/dist/src/models/THex.js +0 -2
- package/dist/src/models/TPlatform.js +0 -2
- package/dist/src/models/TResult.js +0 -2
- package/dist/src/ns/NameService.js +0 -19
- package/dist/src/ns/providers/EnsProvider.js +0 -41
- package/dist/src/ns/providers/INsProvider.js +0 -2
- package/dist/src/ns/providers/UDProvider.js +0 -39
- package/dist/src/ns/utils/$ns.js +0 -17
- package/dist/src/structs/PackedRanges.js +0 -186
- package/dist/src/structs/PackedRanges.spec.js +0 -30
- package/dist/src/tokens/TokenExchangeService.js +0 -110
- package/dist/src/tokens/TokenExchanges/AmmBase/AmmUtilts.js +0 -17
- package/dist/src/tokens/TokenExchanges/AmmBase/V2/AmmFactoryV2Contract.js +0 -15
- package/dist/src/tokens/TokenExchanges/AmmBase/V2/AmmMasterChefV2Contract.js +0 -15
- package/dist/src/tokens/TokenExchanges/AmmBase/V2/AmmPairV2Contract.js +0 -16
- package/dist/src/tokens/TokenExchanges/AmmBase/V2/AmmPairV2Service.js +0 -144
- package/dist/src/tokens/TokenExchanges/AmmBase/V2/AmmRouterV2Contract.js +0 -15
- package/dist/src/tokens/TokenExchanges/AmmBase/V2/AmmVaultV2Contract.js +0 -15
- package/dist/src/tokens/TokenExchanges/AmmBase/V3/AmmPairV3Contract.js +0 -22
- package/dist/src/tokens/TokenExchanges/AmmV2ExchangeBase.js +0 -194
- package/dist/src/tokens/TokenExchanges/OneInchExchange.js +0 -92
- package/dist/src/tokens/TokenExchanges/PancakeswapExchange.js +0 -28
- package/dist/src/tokens/TokenExchanges/SushiswapPolygonExchange.js +0 -28
- package/dist/src/tokens/TokenExchanges/UniswapExchange.js +0 -28
- package/dist/src/tokens/TokenOracles/AmmPriceV2Oracle.js +0 -319
- package/dist/src/tokens/TokenOracles/TokenPriceStore.js +0 -108
- package/dist/src/tokens/TokenPriceService.js +0 -196
- package/dist/src/tokens/TokenPriceServiceProvider.js +0 -31
- package/dist/src/tokens/TokenProviders/ATokenProvider.js +0 -38
- package/dist/src/tokens/TokenProviders/ITokenProvider.js +0 -2
- package/dist/src/tokens/TokenProviders/TPChain.js +0 -35
- package/dist/src/tokens/TokenProviders/TPCoinmarketcap.js +0 -63
- package/dist/src/tokens/TokenProviders/TPOneInch.js +0 -65
- package/dist/src/tokens/TokenProviders/TPSushiswap.js +0 -89
- package/dist/src/tokens/TokenProviders/TPUniswap.js +0 -84
- package/dist/src/tokens/TokenService.js +0 -115
- package/dist/src/tokens/TokenSwapService.js +0 -37
- package/dist/src/tokens/TokenTransferService.js +0 -189
- package/dist/src/tokens/TokensService.js +0 -236
- package/dist/src/tokens/TokensServiceBsc.js +0 -18
- package/dist/src/tokens/TokensServiceEth.js +0 -15
- package/dist/src/tokens/TokensServiceFactory.js +0 -29
- package/dist/src/tokens/TokensServicePolygon.js +0 -18
- package/dist/src/tokens/TokensServiceXDai.js +0 -24
- package/dist/src/tokens/defi/ISwapService.js +0 -2
- package/dist/src/tokens/defi/paraswap/Paraswap.js +0 -135
- package/dist/src/tokens/erc20/eth/WETH.js +0 -14
- package/dist/src/tokens/utils/TokenUtils.js +0 -66
- package/dist/src/txs/ITxConfig.js +0 -2
- package/dist/src/txs/TxDataBuilder.js +0 -159
- package/dist/src/txs/TxLogger.js +0 -119
- package/dist/src/txs/TxProvider.js +0 -73
- package/dist/src/txs/TxService.js +0 -19
- package/dist/src/txs/TxWriter.js +0 -287
- package/dist/src/txs/conditional/GasWatcherLogger.js +0 -61
- package/dist/src/txs/conditional/GasWatcherService.js +0 -103
- package/dist/src/txs/conditional/GasWatcherStore.js +0 -25
- package/dist/src/txs/conditional/GasWatcherTx.js +0 -126
- package/dist/src/txs/receipt/ITxLogItem.js +0 -2
- package/dist/src/txs/receipt/TxLogParser.js +0 -27
- package/dist/src/txs/receipt/TxLogsTransfer.js +0 -50
- package/dist/src/txs/receipt/TxTopicInMemoryProvider.js +0 -41
- package/dist/src/txs/receipt/TxTopicProvider.js +0 -25
- package/dist/src/utils/$abiParser.js +0 -159
- package/dist/src/utils/$abiType.js +0 -77
- package/dist/src/utils/$abiUtils.js +0 -43
- package/dist/src/utils/$address.js +0 -41
- package/dist/src/utils/$array.js +0 -60
- package/dist/src/utils/$bigint.js +0 -130
- package/dist/src/utils/$block.js +0 -10
- package/dist/src/utils/$class.js +0 -13
- package/dist/src/utils/$config.js +0 -18
- package/dist/src/utils/$contract.js +0 -67
- package/dist/src/utils/$csv.js +0 -79
- package/dist/src/utils/$date.js +0 -496
- package/dist/src/utils/$fn.js +0 -117
- package/dist/src/utils/$is.js +0 -40
- package/dist/src/utils/$logger.js +0 -15
- package/dist/src/utils/$number.js +0 -95
- package/dist/src/utils/$object.js +0 -82
- package/dist/src/utils/$path.js +0 -33
- package/dist/src/utils/$promise.js +0 -13
- package/dist/src/utils/$require.js +0 -127
- package/dist/src/utils/$sign.js +0 -35
- package/dist/src/utils/$signSerializer.js +0 -264
- package/dist/src/utils/$wallet.js +0 -13
- package/dist/src/utils/types.js +0 -2
- package/dist/src/wallets/Wallet.js +0 -26
- package/dist/src/wallets/WalletBsc.js +0 -17
- package/dist/src/wallets/WalletService.js +0 -35
- package/dist/src/www/utils/BlockChainExplorerFormatter.js +0 -15
- package/src/BlockchainExplorer/BlockChainExplorerFactory.ts +0 -273
- package/src/BlockchainExplorer/BlockChainExplorerProvider.ts +0 -26
- package/src/BlockchainExplorer/BlockNumberCache.ts +0 -46
- package/src/BlockchainExplorer/Bscscan.ts +0 -23
- package/src/BlockchainExplorer/Etherscan.ts +0 -25
- package/src/BlockchainExplorer/IAbiProvider.ts +0 -5
- package/src/BlockchainExplorer/IBlockChainExplorer.ts +0 -37
- package/src/BlockchainExplorer/Polyscan.ts +0 -23
- package/src/ChainAccounts.ts +0 -72
- package/src/ChainAccountsService.ts +0 -74
- package/src/Config.ts +0 -34
- package/src/bridges/hop/contracts/polygon/Dai_l2AmmWrapperContract.ts +0 -69
- package/src/bridges/hop/contracts/polygon/Dai_l2BridgeContract.ts +0 -453
- package/src/bridges/hop/contracts/polygon/Dai_l2SaddleSwapContract.ts +0 -264
- package/src/bridges/hop/contracts/polygon/Eth_l2AmmWrapperContract.ts +0 -69
- package/src/bridges/hop/contracts/polygon/Eth_l2BridgeContract.ts +0 -453
- package/src/bridges/hop/contracts/polygon/Eth_l2SaddleSwapContract.ts +0 -264
- package/src/bridges/hop/contracts/polygon/Matic_l2AmmWrapperContract.ts +0 -69
- package/src/bridges/hop/contracts/polygon/Matic_l2BridgeContract.ts +0 -453
- package/src/bridges/hop/contracts/polygon/Matic_l2SaddleSwapContract.ts +0 -264
- package/src/bridges/hop/contracts/polygon/Usdc_l2AmmWrapperContract.ts +0 -69
- package/src/bridges/hop/contracts/polygon/Usdc_l2BridgeContract.ts +0 -453
- package/src/bridges/hop/contracts/polygon/Usdc_l2SaddleSwapContract.ts +0 -264
- package/src/bridges/hop/contracts/polygon/Usdt_l2AmmWrapperContract.ts +0 -69
- package/src/bridges/hop/contracts/polygon/Usdt_l2BridgeContract.ts +0 -453
- package/src/bridges/hop/contracts/polygon/Usdt_l2SaddleSwapContract.ts +0 -264
- package/src/bridges/hop/contracts/polygon/Wbtc_l2AmmWrapperContract.ts +0 -69
- package/src/bridges/hop/contracts/polygon/Wbtc_l2BridgeContract.ts +0 -453
- package/src/bridges/hop/contracts/polygon/Wbtc_l2SaddleSwapContract.ts +0 -264
- package/src/bridges/wormhole/contracts/WormholeBridgeContract.ts +0 -14
- package/src/chains/xdai/tokens/WXDaiTokenContract.json +0 -279
- package/src/chains/xdai/tokens/WXDaiTokenContract.ts +0 -14
- package/src/clients/HardhatWeb3Client.ts +0 -60
- package/src/contracts/ContractFactory.ts +0 -19
- package/src/contracts/common/ERC20.ts +0 -13
- package/src/contracts/common/ERC20Polygon.ts +0 -13
- package/src/contracts/common/PoolPair.ts +0 -22
- package/src/defi/OneInch/OneInchRouter.ts +0 -13
- package/src/json/JsonStore.spec.ts +0 -98
- package/src/structs/PackedRanges.spec.ts +0 -38
- package/src/structs/PackedRanges.ts +0 -207
- package/src/tokens/TokenExchanges/AmmBase/V2/AmmFactoryV2Contract.ts +0 -15
- package/src/tokens/TokenExchanges/AmmBase/V2/AmmMasterChefV2Contract.ts +0 -15
- package/src/tokens/TokenExchanges/AmmBase/V2/AmmPairV2Contract.ts +0 -17
- package/src/tokens/TokenExchanges/AmmBase/V2/AmmRouterV2Contract.ts +0 -15
- package/src/tokens/TokenExchanges/AmmBase/V2/AmmVaultV2Contract.ts +0 -15
- package/src/tokens/TokenExchanges/AmmBase/V3/AmmPairV3Contract.ts +0 -24
- package/src/tokens/TokenExchanges/UniswapExchange.ts +0 -31
- package/src/tokens/TokenOracles/AmmPriceV2Oracle.ts +0 -440
- package/src/tokens/erc20/eth/WETH.ts +0 -13
- package/src/txs/ITxConfig.ts +0 -27
- package/src/www/utils/BlockChainExplorerFormatter.ts +0 -13
- package/test/client.spec.ts +0 -59
|
@@ -0,0 +1,1156 @@
|
|
|
1
|
+
// SPDX-License-Identifier: BSD-3-Clause
|
|
2
|
+
pragma solidity ^0.8.10;
|
|
3
|
+
|
|
4
|
+
import "./ComptrollerInterface.sol";
|
|
5
|
+
import "./CTokenInterfaces.sol";
|
|
6
|
+
import "./ErrorReporter.sol";
|
|
7
|
+
import "./EIP20Interface.sol";
|
|
8
|
+
import "./InterestRateModel.sol";
|
|
9
|
+
import "./ExponentialNoError.sol";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @title Compound's CToken Contract
|
|
13
|
+
* @notice Abstract base for CTokens
|
|
14
|
+
* @author Compound
|
|
15
|
+
*/
|
|
16
|
+
abstract contract CToken is CTokenInterface, ExponentialNoError, TokenErrorReporter {
|
|
17
|
+
/**
|
|
18
|
+
* @notice Initialize the money market
|
|
19
|
+
* @param comptroller_ The address of the Comptroller
|
|
20
|
+
* @param interestRateModel_ The address of the interest rate model
|
|
21
|
+
* @param initialExchangeRateMantissa_ The initial exchange rate, scaled by 1e18
|
|
22
|
+
* @param name_ EIP-20 name of this token
|
|
23
|
+
* @param symbol_ EIP-20 symbol of this token
|
|
24
|
+
* @param decimals_ EIP-20 decimal precision of this token
|
|
25
|
+
*/
|
|
26
|
+
function initialize(ComptrollerInterface comptroller_,
|
|
27
|
+
InterestRateModel interestRateModel_,
|
|
28
|
+
uint initialExchangeRateMantissa_,
|
|
29
|
+
string memory name_,
|
|
30
|
+
string memory symbol_,
|
|
31
|
+
uint8 decimals_) public {
|
|
32
|
+
require(msg.sender == admin, "only admin may initialize the market");
|
|
33
|
+
require(accrualBlockNumber == 0 && borrowIndex == 0, "market may only be initialized once");
|
|
34
|
+
|
|
35
|
+
// Set initial exchange rate
|
|
36
|
+
initialExchangeRateMantissa = initialExchangeRateMantissa_;
|
|
37
|
+
require(initialExchangeRateMantissa > 0, "initial exchange rate must be greater than zero.");
|
|
38
|
+
|
|
39
|
+
// Set the comptroller
|
|
40
|
+
uint err = _setComptroller(comptroller_);
|
|
41
|
+
require(err == NO_ERROR, "setting comptroller failed");
|
|
42
|
+
|
|
43
|
+
// Initialize block number and borrow index (block number mocks depend on comptroller being set)
|
|
44
|
+
accrualBlockNumber = getBlockNumber();
|
|
45
|
+
borrowIndex = mantissaOne;
|
|
46
|
+
|
|
47
|
+
// Set the interest rate model (depends on block number / borrow index)
|
|
48
|
+
err = _setInterestRateModelFresh(interestRateModel_);
|
|
49
|
+
require(err == NO_ERROR, "setting interest rate model failed");
|
|
50
|
+
|
|
51
|
+
name = name_;
|
|
52
|
+
symbol = symbol_;
|
|
53
|
+
decimals = decimals_;
|
|
54
|
+
|
|
55
|
+
// The counter starts true to prevent changing it from zero to non-zero (i.e. smaller cost/refund)
|
|
56
|
+
_notEntered = true;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @notice Transfer `tokens` tokens from `src` to `dst` by `spender`
|
|
61
|
+
* @dev Called by both `transfer` and `transferFrom` internally
|
|
62
|
+
* @param spender The address of the account performing the transfer
|
|
63
|
+
* @param src The address of the source account
|
|
64
|
+
* @param dst The address of the destination account
|
|
65
|
+
* @param tokens The number of tokens to transfer
|
|
66
|
+
* @return 0 if the transfer succeeded, else revert
|
|
67
|
+
*/
|
|
68
|
+
function transferTokens(address spender, address src, address dst, uint tokens) internal returns (uint) {
|
|
69
|
+
/* Fail if transfer not allowed */
|
|
70
|
+
uint allowed = comptroller.transferAllowed(address(this), src, dst, tokens);
|
|
71
|
+
if (allowed != 0) {
|
|
72
|
+
revert TransferComptrollerRejection(allowed);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/* Do not allow self-transfers */
|
|
76
|
+
if (src == dst) {
|
|
77
|
+
revert TransferNotAllowed();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/* Get the allowance, infinite for the account owner */
|
|
81
|
+
uint startingAllowance = 0;
|
|
82
|
+
if (spender == src) {
|
|
83
|
+
startingAllowance = type(uint).max;
|
|
84
|
+
} else {
|
|
85
|
+
startingAllowance = transferAllowances[src][spender];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/* Do the calculations, checking for {under,over}flow */
|
|
89
|
+
uint allowanceNew = startingAllowance - tokens;
|
|
90
|
+
uint srcTokensNew = accountTokens[src] - tokens;
|
|
91
|
+
uint dstTokensNew = accountTokens[dst] + tokens;
|
|
92
|
+
|
|
93
|
+
/////////////////////////
|
|
94
|
+
// EFFECTS & INTERACTIONS
|
|
95
|
+
// (No safe failures beyond this point)
|
|
96
|
+
|
|
97
|
+
accountTokens[src] = srcTokensNew;
|
|
98
|
+
accountTokens[dst] = dstTokensNew;
|
|
99
|
+
|
|
100
|
+
/* Eat some of the allowance (if necessary) */
|
|
101
|
+
if (startingAllowance != type(uint).max) {
|
|
102
|
+
transferAllowances[src][spender] = allowanceNew;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/* We emit a Transfer event */
|
|
106
|
+
emit Transfer(src, dst, tokens);
|
|
107
|
+
|
|
108
|
+
// unused function
|
|
109
|
+
// comptroller.transferVerify(address(this), src, dst, tokens);
|
|
110
|
+
|
|
111
|
+
return NO_ERROR;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* @notice Transfer `amount` tokens from `msg.sender` to `dst`
|
|
116
|
+
* @param dst The address of the destination account
|
|
117
|
+
* @param amount The number of tokens to transfer
|
|
118
|
+
* @return Whether or not the transfer succeeded
|
|
119
|
+
*/
|
|
120
|
+
function transfer(address dst, uint256 amount) override external nonReentrant returns (bool) {
|
|
121
|
+
return transferTokens(msg.sender, msg.sender, dst, amount) == NO_ERROR;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* @notice Transfer `amount` tokens from `src` to `dst`
|
|
126
|
+
* @param src The address of the source account
|
|
127
|
+
* @param dst The address of the destination account
|
|
128
|
+
* @param amount The number of tokens to transfer
|
|
129
|
+
* @return Whether or not the transfer succeeded
|
|
130
|
+
*/
|
|
131
|
+
function transferFrom(address src, address dst, uint256 amount) override external nonReentrant returns (bool) {
|
|
132
|
+
return transferTokens(msg.sender, src, dst, amount) == NO_ERROR;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @notice Approve `spender` to transfer up to `amount` from `src`
|
|
137
|
+
* @dev This will overwrite the approval amount for `spender`
|
|
138
|
+
* and is subject to issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve)
|
|
139
|
+
* @param spender The address of the account which may transfer tokens
|
|
140
|
+
* @param amount The number of tokens that are approved (uint256.max means infinite)
|
|
141
|
+
* @return Whether or not the approval succeeded
|
|
142
|
+
*/
|
|
143
|
+
function approve(address spender, uint256 amount) override external returns (bool) {
|
|
144
|
+
address src = msg.sender;
|
|
145
|
+
transferAllowances[src][spender] = amount;
|
|
146
|
+
emit Approval(src, spender, amount);
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* @notice Get the current allowance from `owner` for `spender`
|
|
152
|
+
* @param owner The address of the account which owns the tokens to be spent
|
|
153
|
+
* @param spender The address of the account which may transfer tokens
|
|
154
|
+
* @return The number of tokens allowed to be spent (-1 means infinite)
|
|
155
|
+
*/
|
|
156
|
+
function allowance(address owner, address spender) override external view returns (uint256) {
|
|
157
|
+
return transferAllowances[owner][spender];
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* @notice Get the token balance of the `owner`
|
|
162
|
+
* @param owner The address of the account to query
|
|
163
|
+
* @return The number of tokens owned by `owner`
|
|
164
|
+
*/
|
|
165
|
+
function balanceOf(address owner) override external view returns (uint256) {
|
|
166
|
+
return accountTokens[owner];
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* @notice Get the underlying balance of the `owner`
|
|
171
|
+
* @dev This also accrues interest in a transaction
|
|
172
|
+
* @param owner The address of the account to query
|
|
173
|
+
* @return The amount of underlying owned by `owner`
|
|
174
|
+
*/
|
|
175
|
+
function balanceOfUnderlying(address owner) override external returns (uint) {
|
|
176
|
+
Exp memory exchangeRate = Exp({mantissa: exchangeRateCurrent()});
|
|
177
|
+
return mul_ScalarTruncate(exchangeRate, accountTokens[owner]);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* @notice Get a snapshot of the account's balances, and the cached exchange rate
|
|
182
|
+
* @dev This is used by comptroller to more efficiently perform liquidity checks.
|
|
183
|
+
* @param account Address of the account to snapshot
|
|
184
|
+
* @return (possible error, token balance, borrow balance, exchange rate mantissa)
|
|
185
|
+
*/
|
|
186
|
+
function getAccountSnapshot(address account) override external view returns (uint, uint, uint, uint) {
|
|
187
|
+
return (
|
|
188
|
+
NO_ERROR,
|
|
189
|
+
accountTokens[account],
|
|
190
|
+
borrowBalanceStoredInternal(account),
|
|
191
|
+
exchangeRateStoredInternal()
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* @dev Function to simply retrieve block number
|
|
197
|
+
* This exists mainly for inheriting test contracts to stub this result.
|
|
198
|
+
*/
|
|
199
|
+
function getBlockNumber() virtual internal view returns (uint) {
|
|
200
|
+
return block.number;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* @notice Returns the current per-block borrow interest rate for this cToken
|
|
205
|
+
* @return The borrow interest rate per block, scaled by 1e18
|
|
206
|
+
*/
|
|
207
|
+
function borrowRatePerBlock() override external view returns (uint) {
|
|
208
|
+
return interestRateModel.getBorrowRate(getCashPrior(), totalBorrows, totalReserves);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* @notice Returns the current per-block supply interest rate for this cToken
|
|
213
|
+
* @return The supply interest rate per block, scaled by 1e18
|
|
214
|
+
*/
|
|
215
|
+
function supplyRatePerBlock() override external view returns (uint) {
|
|
216
|
+
return interestRateModel.getSupplyRate(getCashPrior(), totalBorrows, totalReserves, reserveFactorMantissa);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* @notice Returns the current total borrows plus accrued interest
|
|
221
|
+
* @return The total borrows with interest
|
|
222
|
+
*/
|
|
223
|
+
function totalBorrowsCurrent() override external nonReentrant returns (uint) {
|
|
224
|
+
accrueInterest();
|
|
225
|
+
return totalBorrows;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* @notice Accrue interest to updated borrowIndex and then calculate account's borrow balance using the updated borrowIndex
|
|
230
|
+
* @param account The address whose balance should be calculated after updating borrowIndex
|
|
231
|
+
* @return The calculated balance
|
|
232
|
+
*/
|
|
233
|
+
function borrowBalanceCurrent(address account) override external nonReentrant returns (uint) {
|
|
234
|
+
accrueInterest();
|
|
235
|
+
return borrowBalanceStored(account);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* @notice Return the borrow balance of account based on stored data
|
|
240
|
+
* @param account The address whose balance should be calculated
|
|
241
|
+
* @return The calculated balance
|
|
242
|
+
*/
|
|
243
|
+
function borrowBalanceStored(address account) override public view returns (uint) {
|
|
244
|
+
return borrowBalanceStoredInternal(account);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* @notice Return the borrow balance of account based on stored data
|
|
249
|
+
* @param account The address whose balance should be calculated
|
|
250
|
+
* @return (error code, the calculated balance or 0 if error code is non-zero)
|
|
251
|
+
*/
|
|
252
|
+
function borrowBalanceStoredInternal(address account) internal view returns (uint) {
|
|
253
|
+
/* Get borrowBalance and borrowIndex */
|
|
254
|
+
BorrowSnapshot storage borrowSnapshot = accountBorrows[account];
|
|
255
|
+
|
|
256
|
+
/* If borrowBalance = 0 then borrowIndex is likely also 0.
|
|
257
|
+
* Rather than failing the calculation with a division by 0, we immediately return 0 in this case.
|
|
258
|
+
*/
|
|
259
|
+
if (borrowSnapshot.principal == 0) {
|
|
260
|
+
return 0;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/* Calculate new borrow balance using the interest index:
|
|
264
|
+
* recentBorrowBalance = borrower.borrowBalance * market.borrowIndex / borrower.borrowIndex
|
|
265
|
+
*/
|
|
266
|
+
uint principalTimesIndex = borrowSnapshot.principal * borrowIndex;
|
|
267
|
+
return principalTimesIndex / borrowSnapshot.interestIndex;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* @notice Accrue interest then return the up-to-date exchange rate
|
|
272
|
+
* @return Calculated exchange rate scaled by 1e18
|
|
273
|
+
*/
|
|
274
|
+
function exchangeRateCurrent() override public nonReentrant returns (uint) {
|
|
275
|
+
accrueInterest();
|
|
276
|
+
return exchangeRateStored();
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* @notice Calculates the exchange rate from the underlying to the CToken
|
|
281
|
+
* @dev This function does not accrue interest before calculating the exchange rate
|
|
282
|
+
* @return Calculated exchange rate scaled by 1e18
|
|
283
|
+
*/
|
|
284
|
+
function exchangeRateStored() override public view returns (uint) {
|
|
285
|
+
return exchangeRateStoredInternal();
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* @notice Calculates the exchange rate from the underlying to the CToken
|
|
290
|
+
* @dev This function does not accrue interest before calculating the exchange rate
|
|
291
|
+
* @return calculated exchange rate scaled by 1e18
|
|
292
|
+
*/
|
|
293
|
+
function exchangeRateStoredInternal() virtual internal view returns (uint) {
|
|
294
|
+
uint _totalSupply = totalSupply;
|
|
295
|
+
if (_totalSupply == 0) {
|
|
296
|
+
/*
|
|
297
|
+
* If there are no tokens minted:
|
|
298
|
+
* exchangeRate = initialExchangeRate
|
|
299
|
+
*/
|
|
300
|
+
return initialExchangeRateMantissa;
|
|
301
|
+
} else {
|
|
302
|
+
/*
|
|
303
|
+
* Otherwise:
|
|
304
|
+
* exchangeRate = (totalCash + totalBorrows - totalReserves) / totalSupply
|
|
305
|
+
*/
|
|
306
|
+
uint totalCash = getCashPrior();
|
|
307
|
+
uint cashPlusBorrowsMinusReserves = totalCash + totalBorrows - totalReserves;
|
|
308
|
+
uint exchangeRate = cashPlusBorrowsMinusReserves * expScale / _totalSupply;
|
|
309
|
+
|
|
310
|
+
return exchangeRate;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* @notice Get cash balance of this cToken in the underlying asset
|
|
316
|
+
* @return The quantity of underlying asset owned by this contract
|
|
317
|
+
*/
|
|
318
|
+
function getCash() override external view returns (uint) {
|
|
319
|
+
return getCashPrior();
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* @notice Applies accrued interest to total borrows and reserves
|
|
324
|
+
* @dev This calculates interest accrued from the last checkpointed block
|
|
325
|
+
* up to the current block and writes new checkpoint to storage.
|
|
326
|
+
*/
|
|
327
|
+
function accrueInterest() virtual override public returns (uint) {
|
|
328
|
+
/* Remember the initial block number */
|
|
329
|
+
uint currentBlockNumber = getBlockNumber();
|
|
330
|
+
uint accrualBlockNumberPrior = accrualBlockNumber;
|
|
331
|
+
|
|
332
|
+
/* Short-circuit accumulating 0 interest */
|
|
333
|
+
if (accrualBlockNumberPrior == currentBlockNumber) {
|
|
334
|
+
return NO_ERROR;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/* Read the previous values out of storage */
|
|
338
|
+
uint cashPrior = getCashPrior();
|
|
339
|
+
uint borrowsPrior = totalBorrows;
|
|
340
|
+
uint reservesPrior = totalReserves;
|
|
341
|
+
uint borrowIndexPrior = borrowIndex;
|
|
342
|
+
|
|
343
|
+
/* Calculate the current borrow interest rate */
|
|
344
|
+
uint borrowRateMantissa = interestRateModel.getBorrowRate(cashPrior, borrowsPrior, reservesPrior);
|
|
345
|
+
require(borrowRateMantissa <= borrowRateMaxMantissa, "borrow rate is absurdly high");
|
|
346
|
+
|
|
347
|
+
/* Calculate the number of blocks elapsed since the last accrual */
|
|
348
|
+
uint blockDelta = currentBlockNumber - accrualBlockNumberPrior;
|
|
349
|
+
|
|
350
|
+
/*
|
|
351
|
+
* Calculate the interest accumulated into borrows and reserves and the new index:
|
|
352
|
+
* simpleInterestFactor = borrowRate * blockDelta
|
|
353
|
+
* interestAccumulated = simpleInterestFactor * totalBorrows
|
|
354
|
+
* totalBorrowsNew = interestAccumulated + totalBorrows
|
|
355
|
+
* totalReservesNew = interestAccumulated * reserveFactor + totalReserves
|
|
356
|
+
* borrowIndexNew = simpleInterestFactor * borrowIndex + borrowIndex
|
|
357
|
+
*/
|
|
358
|
+
|
|
359
|
+
Exp memory simpleInterestFactor = mul_(Exp({mantissa: borrowRateMantissa}), blockDelta);
|
|
360
|
+
uint interestAccumulated = mul_ScalarTruncate(simpleInterestFactor, borrowsPrior);
|
|
361
|
+
uint totalBorrowsNew = interestAccumulated + borrowsPrior;
|
|
362
|
+
uint totalReservesNew = mul_ScalarTruncateAddUInt(Exp({mantissa: reserveFactorMantissa}), interestAccumulated, reservesPrior);
|
|
363
|
+
uint borrowIndexNew = mul_ScalarTruncateAddUInt(simpleInterestFactor, borrowIndexPrior, borrowIndexPrior);
|
|
364
|
+
|
|
365
|
+
/////////////////////////
|
|
366
|
+
// EFFECTS & INTERACTIONS
|
|
367
|
+
// (No safe failures beyond this point)
|
|
368
|
+
|
|
369
|
+
/* We write the previously calculated values into storage */
|
|
370
|
+
accrualBlockNumber = currentBlockNumber;
|
|
371
|
+
borrowIndex = borrowIndexNew;
|
|
372
|
+
totalBorrows = totalBorrowsNew;
|
|
373
|
+
totalReserves = totalReservesNew;
|
|
374
|
+
|
|
375
|
+
/* We emit an AccrueInterest event */
|
|
376
|
+
emit AccrueInterest(cashPrior, interestAccumulated, borrowIndexNew, totalBorrowsNew);
|
|
377
|
+
|
|
378
|
+
return NO_ERROR;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* @notice Sender supplies assets into the market and receives cTokens in exchange
|
|
383
|
+
* @dev Accrues interest whether or not the operation succeeds, unless reverted
|
|
384
|
+
* @param mintAmount The amount of the underlying asset to supply
|
|
385
|
+
*/
|
|
386
|
+
function mintInternal(uint mintAmount) internal nonReentrant {
|
|
387
|
+
accrueInterest();
|
|
388
|
+
// mintFresh emits the actual Mint event if successful and logs on errors, so we don't need to
|
|
389
|
+
mintFresh(msg.sender, mintAmount);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* @notice User supplies assets into the market and receives cTokens in exchange
|
|
394
|
+
* @dev Assumes interest has already been accrued up to the current block
|
|
395
|
+
* @param minter The address of the account which is supplying the assets
|
|
396
|
+
* @param mintAmount The amount of the underlying asset to supply
|
|
397
|
+
*/
|
|
398
|
+
function mintFresh(address minter, uint mintAmount) internal {
|
|
399
|
+
/* Fail if mint not allowed */
|
|
400
|
+
uint allowed = comptroller.mintAllowed(address(this), minter, mintAmount);
|
|
401
|
+
if (allowed != 0) {
|
|
402
|
+
revert MintComptrollerRejection(allowed);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/* Verify market's block number equals current block number */
|
|
406
|
+
if (accrualBlockNumber != getBlockNumber()) {
|
|
407
|
+
revert MintFreshnessCheck();
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
Exp memory exchangeRate = Exp({mantissa: exchangeRateStoredInternal()});
|
|
411
|
+
|
|
412
|
+
/////////////////////////
|
|
413
|
+
// EFFECTS & INTERACTIONS
|
|
414
|
+
// (No safe failures beyond this point)
|
|
415
|
+
|
|
416
|
+
/*
|
|
417
|
+
* We call `doTransferIn` for the minter and the mintAmount.
|
|
418
|
+
* Note: The cToken must handle variations between ERC-20 and ETH underlying.
|
|
419
|
+
* `doTransferIn` reverts if anything goes wrong, since we can't be sure if
|
|
420
|
+
* side-effects occurred. The function returns the amount actually transferred,
|
|
421
|
+
* in case of a fee. On success, the cToken holds an additional `actualMintAmount`
|
|
422
|
+
* of cash.
|
|
423
|
+
*/
|
|
424
|
+
uint actualMintAmount = doTransferIn(minter, mintAmount);
|
|
425
|
+
|
|
426
|
+
/*
|
|
427
|
+
* We get the current exchange rate and calculate the number of cTokens to be minted:
|
|
428
|
+
* mintTokens = actualMintAmount / exchangeRate
|
|
429
|
+
*/
|
|
430
|
+
|
|
431
|
+
uint mintTokens = div_(actualMintAmount, exchangeRate);
|
|
432
|
+
|
|
433
|
+
/*
|
|
434
|
+
* We calculate the new total supply of cTokens and minter token balance, checking for overflow:
|
|
435
|
+
* totalSupplyNew = totalSupply + mintTokens
|
|
436
|
+
* accountTokensNew = accountTokens[minter] + mintTokens
|
|
437
|
+
* And write them into storage
|
|
438
|
+
*/
|
|
439
|
+
totalSupply = totalSupply + mintTokens;
|
|
440
|
+
accountTokens[minter] = accountTokens[minter] + mintTokens;
|
|
441
|
+
|
|
442
|
+
/* We emit a Mint event, and a Transfer event */
|
|
443
|
+
emit Mint(minter, actualMintAmount, mintTokens);
|
|
444
|
+
emit Transfer(address(this), minter, mintTokens);
|
|
445
|
+
|
|
446
|
+
/* We call the defense hook */
|
|
447
|
+
// unused function
|
|
448
|
+
// comptroller.mintVerify(address(this), minter, actualMintAmount, mintTokens);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* @notice Sender redeems cTokens in exchange for the underlying asset
|
|
453
|
+
* @dev Accrues interest whether or not the operation succeeds, unless reverted
|
|
454
|
+
* @param redeemTokens The number of cTokens to redeem into underlying
|
|
455
|
+
*/
|
|
456
|
+
function redeemInternal(uint redeemTokens) internal nonReentrant {
|
|
457
|
+
accrueInterest();
|
|
458
|
+
// redeemFresh emits redeem-specific logs on errors, so we don't need to
|
|
459
|
+
redeemFresh(payable(msg.sender), redeemTokens, 0);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* @notice Sender redeems cTokens in exchange for a specified amount of underlying asset
|
|
464
|
+
* @dev Accrues interest whether or not the operation succeeds, unless reverted
|
|
465
|
+
* @param redeemAmount The amount of underlying to receive from redeeming cTokens
|
|
466
|
+
*/
|
|
467
|
+
function redeemUnderlyingInternal(uint redeemAmount) internal nonReentrant {
|
|
468
|
+
accrueInterest();
|
|
469
|
+
// redeemFresh emits redeem-specific logs on errors, so we don't need to
|
|
470
|
+
redeemFresh(payable(msg.sender), 0, redeemAmount);
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* @notice User redeems cTokens in exchange for the underlying asset
|
|
475
|
+
* @dev Assumes interest has already been accrued up to the current block
|
|
476
|
+
* @param redeemer The address of the account which is redeeming the tokens
|
|
477
|
+
* @param redeemTokensIn The number of cTokens to redeem into underlying (only one of redeemTokensIn or redeemAmountIn may be non-zero)
|
|
478
|
+
* @param redeemAmountIn The number of underlying tokens to receive from redeeming cTokens (only one of redeemTokensIn or redeemAmountIn may be non-zero)
|
|
479
|
+
*/
|
|
480
|
+
function redeemFresh(address payable redeemer, uint redeemTokensIn, uint redeemAmountIn) internal {
|
|
481
|
+
require(redeemTokensIn == 0 || redeemAmountIn == 0, "one of redeemTokensIn or redeemAmountIn must be zero");
|
|
482
|
+
|
|
483
|
+
/* exchangeRate = invoke Exchange Rate Stored() */
|
|
484
|
+
Exp memory exchangeRate = Exp({mantissa: exchangeRateStoredInternal() });
|
|
485
|
+
|
|
486
|
+
uint redeemTokens;
|
|
487
|
+
uint redeemAmount;
|
|
488
|
+
/* If redeemTokensIn > 0: */
|
|
489
|
+
if (redeemTokensIn > 0) {
|
|
490
|
+
/*
|
|
491
|
+
* We calculate the exchange rate and the amount of underlying to be redeemed:
|
|
492
|
+
* redeemTokens = redeemTokensIn
|
|
493
|
+
* redeemAmount = redeemTokensIn x exchangeRateCurrent
|
|
494
|
+
*/
|
|
495
|
+
redeemTokens = redeemTokensIn;
|
|
496
|
+
redeemAmount = mul_ScalarTruncate(exchangeRate, redeemTokensIn);
|
|
497
|
+
} else {
|
|
498
|
+
/*
|
|
499
|
+
* We get the current exchange rate and calculate the amount to be redeemed:
|
|
500
|
+
* redeemTokens = redeemAmountIn / exchangeRate
|
|
501
|
+
* redeemAmount = redeemAmountIn
|
|
502
|
+
*/
|
|
503
|
+
redeemTokens = div_(redeemAmountIn, exchangeRate);
|
|
504
|
+
redeemAmount = redeemAmountIn;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/* Fail if redeem not allowed */
|
|
508
|
+
uint allowed = comptroller.redeemAllowed(address(this), redeemer, redeemTokens);
|
|
509
|
+
if (allowed != 0) {
|
|
510
|
+
revert RedeemComptrollerRejection(allowed);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/* Verify market's block number equals current block number */
|
|
514
|
+
if (accrualBlockNumber != getBlockNumber()) {
|
|
515
|
+
revert RedeemFreshnessCheck();
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
/* Fail gracefully if protocol has insufficient cash */
|
|
519
|
+
if (getCashPrior() < redeemAmount) {
|
|
520
|
+
revert RedeemTransferOutNotPossible();
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/////////////////////////
|
|
524
|
+
// EFFECTS & INTERACTIONS
|
|
525
|
+
// (No safe failures beyond this point)
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
/*
|
|
529
|
+
* We write the previously calculated values into storage.
|
|
530
|
+
* Note: Avoid token reentrancy attacks by writing reduced supply before external transfer.
|
|
531
|
+
*/
|
|
532
|
+
totalSupply = totalSupply - redeemTokens;
|
|
533
|
+
accountTokens[redeemer] = accountTokens[redeemer] - redeemTokens;
|
|
534
|
+
|
|
535
|
+
/*
|
|
536
|
+
* We invoke doTransferOut for the redeemer and the redeemAmount.
|
|
537
|
+
* Note: The cToken must handle variations between ERC-20 and ETH underlying.
|
|
538
|
+
* On success, the cToken has redeemAmount less of cash.
|
|
539
|
+
* doTransferOut reverts if anything goes wrong, since we can't be sure if side effects occurred.
|
|
540
|
+
*/
|
|
541
|
+
doTransferOut(redeemer, redeemAmount);
|
|
542
|
+
|
|
543
|
+
/* We emit a Transfer event, and a Redeem event */
|
|
544
|
+
emit Transfer(redeemer, address(this), redeemTokens);
|
|
545
|
+
emit Redeem(redeemer, redeemAmount, redeemTokens);
|
|
546
|
+
|
|
547
|
+
/* We call the defense hook */
|
|
548
|
+
comptroller.redeemVerify(address(this), redeemer, redeemAmount, redeemTokens);
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* @notice Sender borrows assets from the protocol to their own address
|
|
553
|
+
* @param borrowAmount The amount of the underlying asset to borrow
|
|
554
|
+
*/
|
|
555
|
+
function borrowInternal(uint borrowAmount) internal nonReentrant {
|
|
556
|
+
accrueInterest();
|
|
557
|
+
// borrowFresh emits borrow-specific logs on errors, so we don't need to
|
|
558
|
+
borrowFresh(payable(msg.sender), borrowAmount);
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* @notice Users borrow assets from the protocol to their own address
|
|
563
|
+
* @param borrowAmount The amount of the underlying asset to borrow
|
|
564
|
+
*/
|
|
565
|
+
function borrowFresh(address payable borrower, uint borrowAmount) internal {
|
|
566
|
+
/* Fail if borrow not allowed */
|
|
567
|
+
uint allowed = comptroller.borrowAllowed(address(this), borrower, borrowAmount);
|
|
568
|
+
if (allowed != 0) {
|
|
569
|
+
revert BorrowComptrollerRejection(allowed);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/* Verify market's block number equals current block number */
|
|
573
|
+
if (accrualBlockNumber != getBlockNumber()) {
|
|
574
|
+
revert BorrowFreshnessCheck();
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/* Fail gracefully if protocol has insufficient underlying cash */
|
|
578
|
+
if (getCashPrior() < borrowAmount) {
|
|
579
|
+
revert BorrowCashNotAvailable();
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
/*
|
|
583
|
+
* We calculate the new borrower and total borrow balances, failing on overflow:
|
|
584
|
+
* accountBorrowNew = accountBorrow + borrowAmount
|
|
585
|
+
* totalBorrowsNew = totalBorrows + borrowAmount
|
|
586
|
+
*/
|
|
587
|
+
uint accountBorrowsPrev = borrowBalanceStoredInternal(borrower);
|
|
588
|
+
uint accountBorrowsNew = accountBorrowsPrev + borrowAmount;
|
|
589
|
+
uint totalBorrowsNew = totalBorrows + borrowAmount;
|
|
590
|
+
|
|
591
|
+
/////////////////////////
|
|
592
|
+
// EFFECTS & INTERACTIONS
|
|
593
|
+
// (No safe failures beyond this point)
|
|
594
|
+
|
|
595
|
+
/*
|
|
596
|
+
* We write the previously calculated values into storage.
|
|
597
|
+
* Note: Avoid token reentrancy attacks by writing increased borrow before external transfer.
|
|
598
|
+
`*/
|
|
599
|
+
accountBorrows[borrower].principal = accountBorrowsNew;
|
|
600
|
+
accountBorrows[borrower].interestIndex = borrowIndex;
|
|
601
|
+
totalBorrows = totalBorrowsNew;
|
|
602
|
+
|
|
603
|
+
/*
|
|
604
|
+
* We invoke doTransferOut for the borrower and the borrowAmount.
|
|
605
|
+
* Note: The cToken must handle variations between ERC-20 and ETH underlying.
|
|
606
|
+
* On success, the cToken borrowAmount less of cash.
|
|
607
|
+
* doTransferOut reverts if anything goes wrong, since we can't be sure if side effects occurred.
|
|
608
|
+
*/
|
|
609
|
+
doTransferOut(borrower, borrowAmount);
|
|
610
|
+
|
|
611
|
+
/* We emit a Borrow event */
|
|
612
|
+
emit Borrow(borrower, borrowAmount, accountBorrowsNew, totalBorrowsNew);
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* @notice Sender repays their own borrow
|
|
617
|
+
* @param repayAmount The amount to repay, or -1 for the full outstanding amount
|
|
618
|
+
*/
|
|
619
|
+
function repayBorrowInternal(uint repayAmount) internal nonReentrant {
|
|
620
|
+
accrueInterest();
|
|
621
|
+
// repayBorrowFresh emits repay-borrow-specific logs on errors, so we don't need to
|
|
622
|
+
repayBorrowFresh(msg.sender, msg.sender, repayAmount);
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
/**
|
|
626
|
+
* @notice Sender repays a borrow belonging to borrower
|
|
627
|
+
* @param borrower the account with the debt being payed off
|
|
628
|
+
* @param repayAmount The amount to repay, or -1 for the full outstanding amount
|
|
629
|
+
*/
|
|
630
|
+
function repayBorrowBehalfInternal(address borrower, uint repayAmount) internal nonReentrant {
|
|
631
|
+
accrueInterest();
|
|
632
|
+
// repayBorrowFresh emits repay-borrow-specific logs on errors, so we don't need to
|
|
633
|
+
repayBorrowFresh(msg.sender, borrower, repayAmount);
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* @notice Borrows are repaid by another user (possibly the borrower).
|
|
638
|
+
* @param payer the account paying off the borrow
|
|
639
|
+
* @param borrower the account with the debt being payed off
|
|
640
|
+
* @param repayAmount the amount of underlying tokens being returned, or -1 for the full outstanding amount
|
|
641
|
+
* @return (uint) the actual repayment amount.
|
|
642
|
+
*/
|
|
643
|
+
function repayBorrowFresh(address payer, address borrower, uint repayAmount) internal returns (uint) {
|
|
644
|
+
/* Fail if repayBorrow not allowed */
|
|
645
|
+
uint allowed = comptroller.repayBorrowAllowed(address(this), payer, borrower, repayAmount);
|
|
646
|
+
if (allowed != 0) {
|
|
647
|
+
revert RepayBorrowComptrollerRejection(allowed);
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
/* Verify market's block number equals current block number */
|
|
651
|
+
if (accrualBlockNumber != getBlockNumber()) {
|
|
652
|
+
revert RepayBorrowFreshnessCheck();
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
/* We fetch the amount the borrower owes, with accumulated interest */
|
|
656
|
+
uint accountBorrowsPrev = borrowBalanceStoredInternal(borrower);
|
|
657
|
+
|
|
658
|
+
/* If repayAmount == -1, repayAmount = accountBorrows */
|
|
659
|
+
uint repayAmountFinal = repayAmount == type(uint).max ? accountBorrowsPrev : repayAmount;
|
|
660
|
+
|
|
661
|
+
/////////////////////////
|
|
662
|
+
// EFFECTS & INTERACTIONS
|
|
663
|
+
// (No safe failures beyond this point)
|
|
664
|
+
|
|
665
|
+
/*
|
|
666
|
+
* We call doTransferIn for the payer and the repayAmount
|
|
667
|
+
* Note: The cToken must handle variations between ERC-20 and ETH underlying.
|
|
668
|
+
* On success, the cToken holds an additional repayAmount of cash.
|
|
669
|
+
* doTransferIn reverts if anything goes wrong, since we can't be sure if side effects occurred.
|
|
670
|
+
* it returns the amount actually transferred, in case of a fee.
|
|
671
|
+
*/
|
|
672
|
+
uint actualRepayAmount = doTransferIn(payer, repayAmountFinal);
|
|
673
|
+
|
|
674
|
+
/*
|
|
675
|
+
* We calculate the new borrower and total borrow balances, failing on underflow:
|
|
676
|
+
* accountBorrowsNew = accountBorrows - actualRepayAmount
|
|
677
|
+
* totalBorrowsNew = totalBorrows - actualRepayAmount
|
|
678
|
+
*/
|
|
679
|
+
uint accountBorrowsNew = accountBorrowsPrev - actualRepayAmount;
|
|
680
|
+
uint totalBorrowsNew = totalBorrows - actualRepayAmount;
|
|
681
|
+
|
|
682
|
+
/* We write the previously calculated values into storage */
|
|
683
|
+
accountBorrows[borrower].principal = accountBorrowsNew;
|
|
684
|
+
accountBorrows[borrower].interestIndex = borrowIndex;
|
|
685
|
+
totalBorrows = totalBorrowsNew;
|
|
686
|
+
|
|
687
|
+
/* We emit a RepayBorrow event */
|
|
688
|
+
emit RepayBorrow(payer, borrower, actualRepayAmount, accountBorrowsNew, totalBorrowsNew);
|
|
689
|
+
|
|
690
|
+
return actualRepayAmount;
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* @notice The sender liquidates the borrowers collateral.
|
|
695
|
+
* The collateral seized is transferred to the liquidator.
|
|
696
|
+
* @param borrower The borrower of this cToken to be liquidated
|
|
697
|
+
* @param cTokenCollateral The market in which to seize collateral from the borrower
|
|
698
|
+
* @param repayAmount The amount of the underlying borrowed asset to repay
|
|
699
|
+
*/
|
|
700
|
+
function liquidateBorrowInternal(address borrower, uint repayAmount, CTokenInterface cTokenCollateral) internal nonReentrant {
|
|
701
|
+
accrueInterest();
|
|
702
|
+
|
|
703
|
+
uint error = cTokenCollateral.accrueInterest();
|
|
704
|
+
if (error != NO_ERROR) {
|
|
705
|
+
// accrueInterest emits logs on errors, but we still want to log the fact that an attempted liquidation failed
|
|
706
|
+
revert LiquidateAccrueCollateralInterestFailed(error);
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
// liquidateBorrowFresh emits borrow-specific logs on errors, so we don't need to
|
|
710
|
+
liquidateBorrowFresh(msg.sender, borrower, repayAmount, cTokenCollateral);
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
/**
|
|
714
|
+
* @notice The liquidator liquidates the borrowers collateral.
|
|
715
|
+
* The collateral seized is transferred to the liquidator.
|
|
716
|
+
* @param borrower The borrower of this cToken to be liquidated
|
|
717
|
+
* @param liquidator The address repaying the borrow and seizing collateral
|
|
718
|
+
* @param cTokenCollateral The market in which to seize collateral from the borrower
|
|
719
|
+
* @param repayAmount The amount of the underlying borrowed asset to repay
|
|
720
|
+
*/
|
|
721
|
+
function liquidateBorrowFresh(address liquidator, address borrower, uint repayAmount, CTokenInterface cTokenCollateral) internal {
|
|
722
|
+
/* Fail if liquidate not allowed */
|
|
723
|
+
uint allowed = comptroller.liquidateBorrowAllowed(address(this), address(cTokenCollateral), liquidator, borrower, repayAmount);
|
|
724
|
+
if (allowed != 0) {
|
|
725
|
+
revert LiquidateComptrollerRejection(allowed);
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
/* Verify market's block number equals current block number */
|
|
729
|
+
if (accrualBlockNumber != getBlockNumber()) {
|
|
730
|
+
revert LiquidateFreshnessCheck();
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
/* Verify cTokenCollateral market's block number equals current block number */
|
|
734
|
+
if (cTokenCollateral.accrualBlockNumber() != getBlockNumber()) {
|
|
735
|
+
revert LiquidateCollateralFreshnessCheck();
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
/* Fail if borrower = liquidator */
|
|
739
|
+
if (borrower == liquidator) {
|
|
740
|
+
revert LiquidateLiquidatorIsBorrower();
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
/* Fail if repayAmount = 0 */
|
|
744
|
+
if (repayAmount == 0) {
|
|
745
|
+
revert LiquidateCloseAmountIsZero();
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
/* Fail if repayAmount = -1 */
|
|
749
|
+
if (repayAmount == type(uint).max) {
|
|
750
|
+
revert LiquidateCloseAmountIsUintMax();
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
/* Fail if repayBorrow fails */
|
|
754
|
+
uint actualRepayAmount = repayBorrowFresh(liquidator, borrower, repayAmount);
|
|
755
|
+
|
|
756
|
+
/////////////////////////
|
|
757
|
+
// EFFECTS & INTERACTIONS
|
|
758
|
+
// (No safe failures beyond this point)
|
|
759
|
+
|
|
760
|
+
/* We calculate the number of collateral tokens that will be seized */
|
|
761
|
+
(uint amountSeizeError, uint seizeTokens) = comptroller.liquidateCalculateSeizeTokens(address(this), address(cTokenCollateral), actualRepayAmount);
|
|
762
|
+
require(amountSeizeError == NO_ERROR, "LIQUIDATE_COMPTROLLER_CALCULATE_AMOUNT_SEIZE_FAILED");
|
|
763
|
+
|
|
764
|
+
/* Revert if borrower collateral token balance < seizeTokens */
|
|
765
|
+
require(cTokenCollateral.balanceOf(borrower) >= seizeTokens, "LIQUIDATE_SEIZE_TOO_MUCH");
|
|
766
|
+
|
|
767
|
+
// If this is also the collateral, run seizeInternal to avoid re-entrancy, otherwise make an external call
|
|
768
|
+
if (address(cTokenCollateral) == address(this)) {
|
|
769
|
+
seizeInternal(address(this), liquidator, borrower, seizeTokens);
|
|
770
|
+
} else {
|
|
771
|
+
require(cTokenCollateral.seize(liquidator, borrower, seizeTokens) == NO_ERROR, "token seizure failed");
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
/* We emit a LiquidateBorrow event */
|
|
775
|
+
emit LiquidateBorrow(liquidator, borrower, actualRepayAmount, address(cTokenCollateral), seizeTokens);
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
/**
|
|
779
|
+
* @notice Transfers collateral tokens (this market) to the liquidator.
|
|
780
|
+
* @dev Will fail unless called by another cToken during the process of liquidation.
|
|
781
|
+
* Its absolutely critical to use msg.sender as the borrowed cToken and not a parameter.
|
|
782
|
+
* @param liquidator The account receiving seized collateral
|
|
783
|
+
* @param borrower The account having collateral seized
|
|
784
|
+
* @param seizeTokens The number of cTokens to seize
|
|
785
|
+
* @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
|
|
786
|
+
*/
|
|
787
|
+
function seize(address liquidator, address borrower, uint seizeTokens) override external nonReentrant returns (uint) {
|
|
788
|
+
seizeInternal(msg.sender, liquidator, borrower, seizeTokens);
|
|
789
|
+
|
|
790
|
+
return NO_ERROR;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
/**
|
|
794
|
+
* @notice Transfers collateral tokens (this market) to the liquidator.
|
|
795
|
+
* @dev Called only during an in-kind liquidation, or by liquidateBorrow during the liquidation of another CToken.
|
|
796
|
+
* Its absolutely critical to use msg.sender as the seizer cToken and not a parameter.
|
|
797
|
+
* @param seizerToken The contract seizing the collateral (i.e. borrowed cToken)
|
|
798
|
+
* @param liquidator The account receiving seized collateral
|
|
799
|
+
* @param borrower The account having collateral seized
|
|
800
|
+
* @param seizeTokens The number of cTokens to seize
|
|
801
|
+
*/
|
|
802
|
+
function seizeInternal(address seizerToken, address liquidator, address borrower, uint seizeTokens) internal {
|
|
803
|
+
/* Fail if seize not allowed */
|
|
804
|
+
uint allowed = comptroller.seizeAllowed(address(this), seizerToken, liquidator, borrower, seizeTokens);
|
|
805
|
+
if (allowed != 0) {
|
|
806
|
+
revert LiquidateSeizeComptrollerRejection(allowed);
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
/* Fail if borrower = liquidator */
|
|
810
|
+
if (borrower == liquidator) {
|
|
811
|
+
revert LiquidateSeizeLiquidatorIsBorrower();
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
/*
|
|
815
|
+
* We calculate the new borrower and liquidator token balances, failing on underflow/overflow:
|
|
816
|
+
* borrowerTokensNew = accountTokens[borrower] - seizeTokens
|
|
817
|
+
* liquidatorTokensNew = accountTokens[liquidator] + seizeTokens
|
|
818
|
+
*/
|
|
819
|
+
uint protocolSeizeTokens = mul_(seizeTokens, Exp({mantissa: protocolSeizeShareMantissa}));
|
|
820
|
+
uint liquidatorSeizeTokens = seizeTokens - protocolSeizeTokens;
|
|
821
|
+
Exp memory exchangeRate = Exp({mantissa: exchangeRateStoredInternal()});
|
|
822
|
+
uint protocolSeizeAmount = mul_ScalarTruncate(exchangeRate, protocolSeizeTokens);
|
|
823
|
+
uint totalReservesNew = totalReserves + protocolSeizeAmount;
|
|
824
|
+
|
|
825
|
+
|
|
826
|
+
/////////////////////////
|
|
827
|
+
// EFFECTS & INTERACTIONS
|
|
828
|
+
// (No safe failures beyond this point)
|
|
829
|
+
|
|
830
|
+
/* We write the calculated values into storage */
|
|
831
|
+
totalReserves = totalReservesNew;
|
|
832
|
+
totalSupply = totalSupply - protocolSeizeTokens;
|
|
833
|
+
accountTokens[borrower] = accountTokens[borrower] - seizeTokens;
|
|
834
|
+
accountTokens[liquidator] = accountTokens[liquidator] + liquidatorSeizeTokens;
|
|
835
|
+
|
|
836
|
+
/* Emit a Transfer event */
|
|
837
|
+
emit Transfer(borrower, liquidator, liquidatorSeizeTokens);
|
|
838
|
+
emit Transfer(borrower, address(this), protocolSeizeTokens);
|
|
839
|
+
emit ReservesAdded(address(this), protocolSeizeAmount, totalReservesNew);
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
|
|
843
|
+
/*** Admin Functions ***/
|
|
844
|
+
|
|
845
|
+
/**
|
|
846
|
+
* @notice Begins transfer of admin rights. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer.
|
|
847
|
+
* @dev Admin function to begin change of admin. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer.
|
|
848
|
+
* @param newPendingAdmin New pending admin.
|
|
849
|
+
* @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
|
|
850
|
+
*/
|
|
851
|
+
function _setPendingAdmin(address payable newPendingAdmin) override external returns (uint) {
|
|
852
|
+
// Check caller = admin
|
|
853
|
+
if (msg.sender != admin) {
|
|
854
|
+
revert SetPendingAdminOwnerCheck();
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
// Save current value, if any, for inclusion in log
|
|
858
|
+
address oldPendingAdmin = pendingAdmin;
|
|
859
|
+
|
|
860
|
+
// Store pendingAdmin with value newPendingAdmin
|
|
861
|
+
pendingAdmin = newPendingAdmin;
|
|
862
|
+
|
|
863
|
+
// Emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin)
|
|
864
|
+
emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin);
|
|
865
|
+
|
|
866
|
+
return NO_ERROR;
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
/**
|
|
870
|
+
* @notice Accepts transfer of admin rights. msg.sender must be pendingAdmin
|
|
871
|
+
* @dev Admin function for pending admin to accept role and update admin
|
|
872
|
+
* @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
|
|
873
|
+
*/
|
|
874
|
+
function _acceptAdmin() override external returns (uint) {
|
|
875
|
+
// Check caller is pendingAdmin and pendingAdmin ≠ address(0)
|
|
876
|
+
if (msg.sender != pendingAdmin || msg.sender == address(0)) {
|
|
877
|
+
revert AcceptAdminPendingAdminCheck();
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
// Save current values for inclusion in log
|
|
881
|
+
address oldAdmin = admin;
|
|
882
|
+
address oldPendingAdmin = pendingAdmin;
|
|
883
|
+
|
|
884
|
+
// Store admin with value pendingAdmin
|
|
885
|
+
admin = pendingAdmin;
|
|
886
|
+
|
|
887
|
+
// Clear the pending value
|
|
888
|
+
pendingAdmin = payable(address(0));
|
|
889
|
+
|
|
890
|
+
emit NewAdmin(oldAdmin, admin);
|
|
891
|
+
emit NewPendingAdmin(oldPendingAdmin, pendingAdmin);
|
|
892
|
+
|
|
893
|
+
return NO_ERROR;
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
/**
|
|
897
|
+
* @notice Sets a new comptroller for the market
|
|
898
|
+
* @dev Admin function to set a new comptroller
|
|
899
|
+
* @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
|
|
900
|
+
*/
|
|
901
|
+
function _setComptroller(ComptrollerInterface newComptroller) override public returns (uint) {
|
|
902
|
+
// Check caller is admin
|
|
903
|
+
if (msg.sender != admin) {
|
|
904
|
+
revert SetComptrollerOwnerCheck();
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
ComptrollerInterface oldComptroller = comptroller;
|
|
908
|
+
// Ensure invoke comptroller.isComptroller() returns true
|
|
909
|
+
require(newComptroller.isComptroller(), "marker method returned false");
|
|
910
|
+
|
|
911
|
+
// Set market's comptroller to newComptroller
|
|
912
|
+
comptroller = newComptroller;
|
|
913
|
+
|
|
914
|
+
// Emit NewComptroller(oldComptroller, newComptroller)
|
|
915
|
+
emit NewComptroller(oldComptroller, newComptroller);
|
|
916
|
+
|
|
917
|
+
return NO_ERROR;
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
/**
|
|
921
|
+
* @notice accrues interest and sets a new reserve factor for the protocol using _setReserveFactorFresh
|
|
922
|
+
* @dev Admin function to accrue interest and set a new reserve factor
|
|
923
|
+
* @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
|
|
924
|
+
*/
|
|
925
|
+
function _setReserveFactor(uint newReserveFactorMantissa) override external nonReentrant returns (uint) {
|
|
926
|
+
accrueInterest();
|
|
927
|
+
// _setReserveFactorFresh emits reserve-factor-specific logs on errors, so we don't need to.
|
|
928
|
+
return _setReserveFactorFresh(newReserveFactorMantissa);
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
/**
|
|
932
|
+
* @notice Sets a new reserve factor for the protocol (*requires fresh interest accrual)
|
|
933
|
+
* @dev Admin function to set a new reserve factor
|
|
934
|
+
* @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
|
|
935
|
+
*/
|
|
936
|
+
function _setReserveFactorFresh(uint newReserveFactorMantissa) internal returns (uint) {
|
|
937
|
+
// Check caller is admin
|
|
938
|
+
if (msg.sender != admin) {
|
|
939
|
+
revert SetReserveFactorAdminCheck();
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
// Verify market's block number equals current block number
|
|
943
|
+
if (accrualBlockNumber != getBlockNumber()) {
|
|
944
|
+
revert SetReserveFactorFreshCheck();
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
// Check newReserveFactor ≤ maxReserveFactor
|
|
948
|
+
if (newReserveFactorMantissa > reserveFactorMaxMantissa) {
|
|
949
|
+
revert SetReserveFactorBoundsCheck();
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
uint oldReserveFactorMantissa = reserveFactorMantissa;
|
|
953
|
+
reserveFactorMantissa = newReserveFactorMantissa;
|
|
954
|
+
|
|
955
|
+
emit NewReserveFactor(oldReserveFactorMantissa, newReserveFactorMantissa);
|
|
956
|
+
|
|
957
|
+
return NO_ERROR;
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
/**
|
|
961
|
+
* @notice Accrues interest and reduces reserves by transferring from msg.sender
|
|
962
|
+
* @param addAmount Amount of addition to reserves
|
|
963
|
+
* @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
|
|
964
|
+
*/
|
|
965
|
+
function _addReservesInternal(uint addAmount) internal nonReentrant returns (uint) {
|
|
966
|
+
accrueInterest();
|
|
967
|
+
|
|
968
|
+
// _addReservesFresh emits reserve-addition-specific logs on errors, so we don't need to.
|
|
969
|
+
_addReservesFresh(addAmount);
|
|
970
|
+
return NO_ERROR;
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
/**
|
|
974
|
+
* @notice Add reserves by transferring from caller
|
|
975
|
+
* @dev Requires fresh interest accrual
|
|
976
|
+
* @param addAmount Amount of addition to reserves
|
|
977
|
+
* @return (uint, uint) An error code (0=success, otherwise a failure (see ErrorReporter.sol for details)) and the actual amount added, net token fees
|
|
978
|
+
*/
|
|
979
|
+
function _addReservesFresh(uint addAmount) internal returns (uint, uint) {
|
|
980
|
+
// totalReserves + actualAddAmount
|
|
981
|
+
uint totalReservesNew;
|
|
982
|
+
uint actualAddAmount;
|
|
983
|
+
|
|
984
|
+
// We fail gracefully unless market's block number equals current block number
|
|
985
|
+
if (accrualBlockNumber != getBlockNumber()) {
|
|
986
|
+
revert AddReservesFactorFreshCheck(actualAddAmount);
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
/////////////////////////
|
|
990
|
+
// EFFECTS & INTERACTIONS
|
|
991
|
+
// (No safe failures beyond this point)
|
|
992
|
+
|
|
993
|
+
/*
|
|
994
|
+
* We call doTransferIn for the caller and the addAmount
|
|
995
|
+
* Note: The cToken must handle variations between ERC-20 and ETH underlying.
|
|
996
|
+
* On success, the cToken holds an additional addAmount of cash.
|
|
997
|
+
* doTransferIn reverts if anything goes wrong, since we can't be sure if side effects occurred.
|
|
998
|
+
* it returns the amount actually transferred, in case of a fee.
|
|
999
|
+
*/
|
|
1000
|
+
|
|
1001
|
+
actualAddAmount = doTransferIn(msg.sender, addAmount);
|
|
1002
|
+
|
|
1003
|
+
totalReservesNew = totalReserves + actualAddAmount;
|
|
1004
|
+
|
|
1005
|
+
// Store reserves[n+1] = reserves[n] + actualAddAmount
|
|
1006
|
+
totalReserves = totalReservesNew;
|
|
1007
|
+
|
|
1008
|
+
/* Emit NewReserves(admin, actualAddAmount, reserves[n+1]) */
|
|
1009
|
+
emit ReservesAdded(msg.sender, actualAddAmount, totalReservesNew);
|
|
1010
|
+
|
|
1011
|
+
/* Return (NO_ERROR, actualAddAmount) */
|
|
1012
|
+
return (NO_ERROR, actualAddAmount);
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
|
|
1016
|
+
/**
|
|
1017
|
+
* @notice Accrues interest and reduces reserves by transferring to admin
|
|
1018
|
+
* @param reduceAmount Amount of reduction to reserves
|
|
1019
|
+
* @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
|
|
1020
|
+
*/
|
|
1021
|
+
function _reduceReserves(uint reduceAmount) override external nonReentrant returns (uint) {
|
|
1022
|
+
accrueInterest();
|
|
1023
|
+
// _reduceReservesFresh emits reserve-reduction-specific logs on errors, so we don't need to.
|
|
1024
|
+
return _reduceReservesFresh(reduceAmount);
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
/**
|
|
1028
|
+
* @notice Reduces reserves by transferring to admin
|
|
1029
|
+
* @dev Requires fresh interest accrual
|
|
1030
|
+
* @param reduceAmount Amount of reduction to reserves
|
|
1031
|
+
* @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
|
|
1032
|
+
*/
|
|
1033
|
+
function _reduceReservesFresh(uint reduceAmount) internal returns (uint) {
|
|
1034
|
+
// totalReserves - reduceAmount
|
|
1035
|
+
uint totalReservesNew;
|
|
1036
|
+
|
|
1037
|
+
// Check caller is admin
|
|
1038
|
+
if (msg.sender != admin) {
|
|
1039
|
+
revert ReduceReservesAdminCheck();
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
// We fail gracefully unless market's block number equals current block number
|
|
1043
|
+
if (accrualBlockNumber != getBlockNumber()) {
|
|
1044
|
+
revert ReduceReservesFreshCheck();
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
// Fail gracefully if protocol has insufficient underlying cash
|
|
1048
|
+
if (getCashPrior() < reduceAmount) {
|
|
1049
|
+
revert ReduceReservesCashNotAvailable();
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
// Check reduceAmount ≤ reserves[n] (totalReserves)
|
|
1053
|
+
if (reduceAmount > totalReserves) {
|
|
1054
|
+
revert ReduceReservesCashValidation();
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
/////////////////////////
|
|
1058
|
+
// EFFECTS & INTERACTIONS
|
|
1059
|
+
// (No safe failures beyond this point)
|
|
1060
|
+
|
|
1061
|
+
totalReservesNew = totalReserves - reduceAmount;
|
|
1062
|
+
|
|
1063
|
+
// Store reserves[n+1] = reserves[n] - reduceAmount
|
|
1064
|
+
totalReserves = totalReservesNew;
|
|
1065
|
+
|
|
1066
|
+
// doTransferOut reverts if anything goes wrong, since we can't be sure if side effects occurred.
|
|
1067
|
+
doTransferOut(admin, reduceAmount);
|
|
1068
|
+
|
|
1069
|
+
emit ReservesReduced(admin, reduceAmount, totalReservesNew);
|
|
1070
|
+
|
|
1071
|
+
return NO_ERROR;
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
/**
|
|
1075
|
+
* @notice accrues interest and updates the interest rate model using _setInterestRateModelFresh
|
|
1076
|
+
* @dev Admin function to accrue interest and update the interest rate model
|
|
1077
|
+
* @param newInterestRateModel the new interest rate model to use
|
|
1078
|
+
* @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
|
|
1079
|
+
*/
|
|
1080
|
+
function _setInterestRateModel(InterestRateModel newInterestRateModel) override public returns (uint) {
|
|
1081
|
+
accrueInterest();
|
|
1082
|
+
// _setInterestRateModelFresh emits interest-rate-model-update-specific logs on errors, so we don't need to.
|
|
1083
|
+
return _setInterestRateModelFresh(newInterestRateModel);
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
/**
|
|
1087
|
+
* @notice updates the interest rate model (*requires fresh interest accrual)
|
|
1088
|
+
* @dev Admin function to update the interest rate model
|
|
1089
|
+
* @param newInterestRateModel the new interest rate model to use
|
|
1090
|
+
* @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
|
|
1091
|
+
*/
|
|
1092
|
+
function _setInterestRateModelFresh(InterestRateModel newInterestRateModel) internal returns (uint) {
|
|
1093
|
+
|
|
1094
|
+
// Used to store old model for use in the event that is emitted on success
|
|
1095
|
+
InterestRateModel oldInterestRateModel;
|
|
1096
|
+
|
|
1097
|
+
// Check caller is admin
|
|
1098
|
+
if (msg.sender != admin) {
|
|
1099
|
+
revert SetInterestRateModelOwnerCheck();
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
// We fail gracefully unless market's block number equals current block number
|
|
1103
|
+
if (accrualBlockNumber != getBlockNumber()) {
|
|
1104
|
+
revert SetInterestRateModelFreshCheck();
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
// Track the market's current interest rate model
|
|
1108
|
+
oldInterestRateModel = interestRateModel;
|
|
1109
|
+
|
|
1110
|
+
// Ensure invoke newInterestRateModel.isInterestRateModel() returns true
|
|
1111
|
+
require(newInterestRateModel.isInterestRateModel(), "marker method returned false");
|
|
1112
|
+
|
|
1113
|
+
// Set the interest rate model to newInterestRateModel
|
|
1114
|
+
interestRateModel = newInterestRateModel;
|
|
1115
|
+
|
|
1116
|
+
// Emit NewMarketInterestRateModel(oldInterestRateModel, newInterestRateModel)
|
|
1117
|
+
emit NewMarketInterestRateModel(oldInterestRateModel, newInterestRateModel);
|
|
1118
|
+
|
|
1119
|
+
return NO_ERROR;
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
/*** Safe Token ***/
|
|
1123
|
+
|
|
1124
|
+
/**
|
|
1125
|
+
* @notice Gets balance of this contract in terms of the underlying
|
|
1126
|
+
* @dev This excludes the value of the current message, if any
|
|
1127
|
+
* @return The quantity of underlying owned by this contract
|
|
1128
|
+
*/
|
|
1129
|
+
function getCashPrior() virtual internal view returns (uint);
|
|
1130
|
+
|
|
1131
|
+
/**
|
|
1132
|
+
* @dev Performs a transfer in, reverting upon failure. Returns the amount actually transferred to the protocol, in case of a fee.
|
|
1133
|
+
* This may revert due to insufficient balance or insufficient allowance.
|
|
1134
|
+
*/
|
|
1135
|
+
function doTransferIn(address from, uint amount) virtual internal returns (uint);
|
|
1136
|
+
|
|
1137
|
+
/**
|
|
1138
|
+
* @dev Performs a transfer out, ideally returning an explanatory error code upon failure rather than reverting.
|
|
1139
|
+
* If caller has not called checked protocol's balance, may revert due to insufficient cash held in the contract.
|
|
1140
|
+
* If caller has checked protocol's balance, and verified it is >= amount, this should not revert in normal conditions.
|
|
1141
|
+
*/
|
|
1142
|
+
function doTransferOut(address payable to, uint amount) virtual internal;
|
|
1143
|
+
|
|
1144
|
+
|
|
1145
|
+
/*** Reentrancy Guard ***/
|
|
1146
|
+
|
|
1147
|
+
/**
|
|
1148
|
+
* @dev Prevents a contract from calling itself, directly or indirectly.
|
|
1149
|
+
*/
|
|
1150
|
+
modifier nonReentrant() {
|
|
1151
|
+
require(_notEntered, "re-entered");
|
|
1152
|
+
_notEntered = false;
|
|
1153
|
+
_;
|
|
1154
|
+
_notEntered = true; // get a gas-refund post-Istanbul
|
|
1155
|
+
}
|
|
1156
|
+
}
|