@across-protocol/contracts 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/LICENSE +661 -0
- package/README.md +53 -0
- package/artifacts/@eth-optimism/contracts/L2/messaging/IL2ERC20Bridge.sol/IL2ERC20Bridge.dbg.json +4 -0
- package/artifacts/@eth-optimism/contracts/L2/messaging/IL2ERC20Bridge.sol/IL2ERC20Bridge.json +252 -0
- package/artifacts/@eth-optimism/contracts/libraries/bridge/CrossDomainEnabled.sol/CrossDomainEnabled.dbg.json +4 -0
- package/artifacts/@eth-optimism/contracts/libraries/bridge/CrossDomainEnabled.sol/CrossDomainEnabled.json +35 -0
- package/artifacts/@eth-optimism/contracts/libraries/bridge/ICrossDomainMessenger.sol/ICrossDomainMessenger.dbg.json +4 -0
- package/artifacts/@eth-optimism/contracts/libraries/bridge/ICrossDomainMessenger.sol/ICrossDomainMessenger.json +110 -0
- package/artifacts/@eth-optimism/contracts/libraries/constants/Lib_PredeployAddresses.sol/Lib_PredeployAddresses.dbg.json +4 -0
- package/artifacts/@eth-optimism/contracts/libraries/constants/Lib_PredeployAddresses.sol/Lib_PredeployAddresses.json +10 -0
- package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.json +215 -0
- package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/IAccessControl.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/IAccessControl.json +108 -0
- package/artifacts/@openzeppelin/contracts/access/Ownable.sol/Ownable.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/access/Ownable.sol/Ownable.json +63 -0
- package/artifacts/@openzeppelin/contracts/security/Pausable.sol/Pausable.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/security/Pausable.sol/Pausable.json +50 -0
- package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.json +297 -0
- package/artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.json +194 -0
- package/artifacts/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol/IERC20Metadata.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol/IERC20Metadata.json +233 -0
- package/artifacts/@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol/SafeERC20.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol/SafeERC20.json +10 -0
- package/artifacts/@openzeppelin/contracts/utils/Address.sol/Address.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/utils/Address.sol/Address.json +10 -0
- package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.json +10 -0
- package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.json +10 -0
- package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.json +30 -0
- package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.json +30 -0
- package/artifacts/@openzeppelin/contracts/utils/math/SafeMath.sol/SafeMath.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/utils/math/SafeMath.sol/SafeMath.json +10 -0
- package/artifacts/@openzeppelin/contracts/utils/math/SignedSafeMath.sol/SignedSafeMath.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/utils/math/SignedSafeMath.sol/SignedSafeMath.json +10 -0
- package/artifacts/@uma/core/contracts/common/implementation/Lockable.sol/Lockable.dbg.json +4 -0
- package/artifacts/@uma/core/contracts/common/implementation/Lockable.sol/Lockable.json +16 -0
- package/artifacts/@uma/core/contracts/cross-chain-oracle/chain-adapters/Arbitrum_ParentMessenger.sol/Arbitrum_ParentMessenger.dbg.json +4 -0
- package/artifacts/@uma/core/contracts/cross-chain-oracle/chain-adapters/Arbitrum_ParentMessenger.sol/Arbitrum_ParentMessenger.json +611 -0
- package/artifacts/@uma/core/contracts/cross-chain-oracle/chain-adapters/ParentMessengerBase.sol/ParentMessengerBase.dbg.json +4 -0
- package/artifacts/@uma/core/contracts/cross-chain-oracle/chain-adapters/ParentMessengerBase.sol/ParentMessengerBase.json +297 -0
- package/artifacts/@uma/core/contracts/cross-chain-oracle/interfaces/ParentMessengerConsumerInterface.sol/ParentMessengerConsumerInterface.dbg.json +4 -0
- package/artifacts/@uma/core/contracts/cross-chain-oracle/interfaces/ParentMessengerConsumerInterface.sol/ParentMessengerConsumerInterface.json +29 -0
- package/artifacts/@uma/core/contracts/cross-chain-oracle/interfaces/ParentMessengerInterface.sol/ParentMessengerInterface.dbg.json +4 -0
- package/artifacts/@uma/core/contracts/cross-chain-oracle/interfaces/ParentMessengerInterface.sol/ParentMessengerInterface.json +37 -0
- package/artifacts/@uma/core/contracts/external/avm/interfaces/iArbitrum_Inbox.sol/IBridge.dbg.json +4 -0
- package/artifacts/@uma/core/contracts/external/avm/interfaces/iArbitrum_Inbox.sol/IBridge.json +24 -0
- package/artifacts/@uma/core/contracts/external/avm/interfaces/iArbitrum_Inbox.sol/iArbitrum_Inbox.dbg.json +4 -0
- package/artifacts/@uma/core/contracts/external/avm/interfaces/iArbitrum_Inbox.sol/iArbitrum_Inbox.json +78 -0
- package/artifacts/@uma/core/contracts/external/avm/interfaces/iArbitrum_Outbox.sol/iArbitrum_Outbox.dbg.json +4 -0
- package/artifacts/@uma/core/contracts/external/avm/interfaces/iArbitrum_Outbox.sol/iArbitrum_Outbox.json +24 -0
- package/artifacts/@uma/core/contracts/insured-bridge/avm/Arbitrum_CrossDomainEnabled.sol/Arbitrum_CrossDomainEnabled.dbg.json +4 -0
- package/artifacts/@uma/core/contracts/insured-bridge/avm/Arbitrum_CrossDomainEnabled.sol/Arbitrum_CrossDomainEnabled.json +24 -0
- package/artifacts/build-info/1cd64db7a8ac0a153df93d26826ad4e9.json +1653 -0
- package/artifacts/build-info/1f738b56edd7602183f2f8d2f23f6e90.json +1592 -0
- package/artifacts/build-info/343b9221be36acd9ddaca3f3b83d2e75.json +3943 -0
- package/artifacts/build-info/622e561692c193f4cd0ff989b5a231e2.json +5661 -0
- package/artifacts/build-info/8e408b49e0ff2873bc28d45221a7ff71.json +277715 -0
- package/artifacts/build-info/9d1a3182633612bd337d811d567d5d60.json +2072 -0
- package/artifacts/build-info/a8cd9c443d245fe513d6650634b60f93.json +23776 -0
- package/artifacts/build-info/d302d9d63fbafb5c8d635cc62cb1cc7c.json +167529 -0
- package/artifacts/contracts/common/implementation/AncillaryData.sol/AncillaryData.dbg.json +4 -0
- package/artifacts/contracts/common/implementation/AncillaryData.sol/AncillaryData.json +10 -0
- package/artifacts/contracts/common/implementation/FixedPoint.sol/FixedPoint.dbg.json +4 -0
- package/artifacts/contracts/common/implementation/FixedPoint.sol/FixedPoint.json +10 -0
- package/artifacts/contracts/common/implementation/Lockable.sol/Lockable.dbg.json +4 -0
- package/artifacts/contracts/common/implementation/Lockable.sol/Lockable.json +16 -0
- package/artifacts/contracts/common/implementation/MultiCaller.sol/MultiCaller.dbg.json +4 -0
- package/artifacts/contracts/common/implementation/MultiCaller.sol/MultiCaller.json +30 -0
- package/artifacts/contracts/common/implementation/Testable.sol/Testable.dbg.json +4 -0
- package/artifacts/contracts/common/implementation/Testable.sol/Testable.json +50 -0
- package/artifacts/contracts/common/implementation/Timer.sol/Timer.dbg.json +4 -0
- package/artifacts/contracts/common/implementation/Timer.sol/Timer.json +42 -0
- package/artifacts/contracts/common/interfaces/AddressWhitelistInterface.sol/AddressWhitelistInterface.dbg.json +4 -0
- package/artifacts/contracts/common/interfaces/AddressWhitelistInterface.sol/AddressWhitelistInterface.json +69 -0
- package/artifacts/contracts/external/avm/AVM_CrossDomainEnabled.sol/AVM_CrossDomainEnabled.dbg.json +4 -0
- package/artifacts/contracts/external/avm/AVM_CrossDomainEnabled.sol/AVM_CrossDomainEnabled.json +42 -0
- package/artifacts/contracts/external/avm/interfaces/ArbSys.sol/ArbSys.dbg.json +4 -0
- package/artifacts/contracts/external/avm/interfaces/ArbSys.sol/ArbSys.json +235 -0
- package/artifacts/contracts/external/avm/interfaces/iArbitrum_Inbox.sol/IBridge.dbg.json +4 -0
- package/artifacts/contracts/external/avm/interfaces/iArbitrum_Inbox.sol/IBridge.json +24 -0
- package/artifacts/contracts/external/avm/interfaces/iArbitrum_Inbox.sol/iArbitrum_Inbox.dbg.json +4 -0
- package/artifacts/contracts/external/avm/interfaces/iArbitrum_Inbox.sol/iArbitrum_Inbox.json +78 -0
- package/artifacts/contracts/external/avm/interfaces/iArbitrum_Outbox.sol/iArbitrum_Outbox.dbg.json +4 -0
- package/artifacts/contracts/external/avm/interfaces/iArbitrum_Outbox.sol/iArbitrum_Outbox.json +24 -0
- package/artifacts/contracts/external/chainbridge/Bridge.sol/Bridge.dbg.json +4 -0
- package/artifacts/contracts/external/chainbridge/Bridge.sol/Bridge.json +1019 -0
- package/artifacts/contracts/external/chainbridge/handlers/GenericHandler.sol/GenericHandler.dbg.json +4 -0
- package/artifacts/contracts/external/chainbridge/handlers/GenericHandler.sol/GenericHandler.json +314 -0
- package/artifacts/contracts/external/chainbridge/interfaces/IBridge.sol/IBridge.dbg.json +4 -0
- package/artifacts/contracts/external/chainbridge/interfaces/IBridge.sol/IBridge.json +47 -0
- package/artifacts/contracts/external/chainbridge/interfaces/IDepositExecute.sol/IDepositExecute.dbg.json +4 -0
- package/artifacts/contracts/external/chainbridge/interfaces/IDepositExecute.sol/IDepositExecute.json +62 -0
- package/artifacts/contracts/external/chainbridge/interfaces/IERCHandler.sol/IERCHandler.dbg.json +4 -0
- package/artifacts/contracts/external/chainbridge/interfaces/IERCHandler.sol/IERCHandler.json +65 -0
- package/artifacts/contracts/external/chainbridge/interfaces/IGenericHandler.sol/IGenericHandler.dbg.json +4 -0
- package/artifacts/contracts/external/chainbridge/interfaces/IGenericHandler.sol/IGenericHandler.json +39 -0
- package/artifacts/contracts/external/ovm/OVM_CrossDomainEnabled.sol/OVM_CrossDomainEnabled.dbg.json +4 -0
- package/artifacts/contracts/external/ovm/OVM_CrossDomainEnabled.sol/OVM_CrossDomainEnabled.json +35 -0
- package/artifacts/contracts/external/ovm/OVM_CrossDomainEnabled.sol/iOVM_CrossDomainMessenger.dbg.json +4 -0
- package/artifacts/contracts/external/ovm/OVM_CrossDomainEnabled.sol/iOVM_CrossDomainMessenger.json +86 -0
- package/artifacts/contracts/external/polygon/lib/Merkle.sol/Merkle.dbg.json +4 -0
- package/artifacts/contracts/external/polygon/lib/Merkle.sol/Merkle.json +10 -0
- package/artifacts/contracts/external/polygon/lib/MerklePatriciaProof.sol/MerklePatriciaProof.dbg.json +4 -0
- package/artifacts/contracts/external/polygon/lib/MerklePatriciaProof.sol/MerklePatriciaProof.json +10 -0
- package/artifacts/contracts/external/polygon/lib/RLPReader.sol/RLPReader.dbg.json +4 -0
- package/artifacts/contracts/external/polygon/lib/RLPReader.sol/RLPReader.json +10 -0
- package/artifacts/contracts/external/polygon/test/FxChildMock.sol/FxChildMock.dbg.json +4 -0
- package/artifacts/contracts/external/polygon/test/FxChildMock.sol/FxChildMock.json +104 -0
- package/artifacts/contracts/external/polygon/test/FxChildMock.sol/IFxMessageProcessor.dbg.json +4 -0
- package/artifacts/contracts/external/polygon/test/FxChildMock.sol/IFxMessageProcessor.json +34 -0
- package/artifacts/contracts/external/polygon/test/FxChildMock.sol/IStateReceiver.dbg.json +4 -0
- package/artifacts/contracts/external/polygon/test/FxChildMock.sol/IStateReceiver.json +29 -0
- package/artifacts/contracts/external/polygon/test/FxRootMock.sol/FxRootMock.dbg.json +4 -0
- package/artifacts/contracts/external/polygon/test/FxRootMock.sol/FxRootMock.json +79 -0
- package/artifacts/contracts/external/polygon/test/FxRootMock.sol/IFxStateSender.dbg.json +4 -0
- package/artifacts/contracts/external/polygon/test/FxRootMock.sol/IFxStateSender.json +29 -0
- package/artifacts/contracts/external/polygon/test/FxRootMock.sol/IStateSender.dbg.json +4 -0
- package/artifacts/contracts/external/polygon/test/FxRootMock.sol/IStateSender.json +29 -0
- package/artifacts/contracts/external/polygon/test/StateSyncMock.sol/StateSyncMock.dbg.json +4 -0
- package/artifacts/contracts/external/polygon/test/StateSyncMock.sol/StateSyncMock.json +54 -0
- package/artifacts/contracts/external/polygon/tunnel/FxBaseChildTunnel.sol/FxBaseChildTunnel.dbg.json +4 -0
- package/artifacts/contracts/external/polygon/tunnel/FxBaseChildTunnel.sol/FxBaseChildTunnel.json +86 -0
- package/artifacts/contracts/external/polygon/tunnel/FxBaseChildTunnel.sol/IFxMessageProcessor.dbg.json +4 -0
- package/artifacts/contracts/external/polygon/tunnel/FxBaseChildTunnel.sol/IFxMessageProcessor.json +34 -0
- package/artifacts/contracts/external/polygon/tunnel/FxBaseRootTunnel.sol/FxBaseRootTunnel.dbg.json +4 -0
- package/artifacts/contracts/external/polygon/tunnel/FxBaseRootTunnel.sol/FxBaseRootTunnel.json +108 -0
- package/artifacts/contracts/external/polygon/tunnel/FxBaseRootTunnel.sol/ICheckpointManager.dbg.json +4 -0
- package/artifacts/contracts/external/polygon/tunnel/FxBaseRootTunnel.sol/ICheckpointManager.json +50 -0
- package/artifacts/contracts/external/polygon/tunnel/FxBaseRootTunnel.sol/IFxStateSender.dbg.json +4 -0
- package/artifacts/contracts/external/polygon/tunnel/FxBaseRootTunnel.sol/IFxStateSender.json +29 -0
- package/artifacts/contracts/insured-bridge/BridgeAdmin.sol/BridgeAdmin.dbg.json +4 -0
- package/artifacts/contracts/insured-bridge/BridgeAdmin.sol/BridgeAdmin.json +662 -0
- package/artifacts/contracts/insured-bridge/BridgeDepositBox.sol/BridgeDepositBox.dbg.json +4 -0
- package/artifacts/contracts/insured-bridge/BridgeDepositBox.sol/BridgeDepositBox.json +391 -0
- package/artifacts/contracts/insured-bridge/BridgeDepositBox.sol/TokenLike.dbg.json +4 -0
- package/artifacts/contracts/insured-bridge/BridgeDepositBox.sol/TokenLike.json +30 -0
- package/artifacts/contracts/insured-bridge/BridgeDepositBox.sol/WETH9Like.dbg.json +4 -0
- package/artifacts/contracts/insured-bridge/BridgeDepositBox.sol/WETH9Like.json +31 -0
- package/artifacts/contracts/insured-bridge/BridgePool.sol/BridgePool.dbg.json +4 -0
- package/artifacts/contracts/insured-bridge/BridgePool.sol/BridgePool.json +1709 -0
- package/artifacts/contracts/insured-bridge/BridgePool.sol/BridgePoolProd.dbg.json +4 -0
- package/artifacts/contracts/insured-bridge/BridgePool.sol/BridgePoolProd.json +1709 -0
- package/artifacts/contracts/insured-bridge/BridgePool.sol/WETH9Like.dbg.json +4 -0
- package/artifacts/contracts/insured-bridge/BridgePool.sol/WETH9Like.json +31 -0
- package/artifacts/contracts/insured-bridge/avm/AVM_BridgeDepositBox.sol/AVM_BridgeDepositBox.dbg.json +4 -0
- package/artifacts/contracts/insured-bridge/avm/AVM_BridgeDepositBox.sol/AVM_BridgeDepositBox.json +564 -0
- package/artifacts/contracts/insured-bridge/avm/AVM_BridgeDepositBox.sol/StandardBridgeLike.dbg.json +4 -0
- package/artifacts/contracts/insured-bridge/avm/AVM_BridgeDepositBox.sol/StandardBridgeLike.json +45 -0
- package/artifacts/contracts/insured-bridge/avm/Arbitrum_CrossDomainEnabled.sol/Arbitrum_CrossDomainEnabled.dbg.json +4 -0
- package/artifacts/contracts/insured-bridge/avm/Arbitrum_CrossDomainEnabled.sol/Arbitrum_CrossDomainEnabled.json +24 -0
- package/artifacts/contracts/insured-bridge/avm/Arbitrum_Messenger.sol/Arbitrum_Messenger.dbg.json +4 -0
- package/artifacts/contracts/insured-bridge/avm/Arbitrum_Messenger.sol/Arbitrum_Messenger.json +191 -0
- package/artifacts/contracts/insured-bridge/interfaces/BridgeAdminInterface.sol/BridgeAdminInterface.dbg.json +4 -0
- package/artifacts/contracts/insured-bridge/interfaces/BridgeAdminInterface.sol/BridgeAdminInterface.json +319 -0
- package/artifacts/contracts/insured-bridge/interfaces/BridgePoolInterface.sol/BridgePoolInterface.dbg.json +4 -0
- package/artifacts/contracts/insured-bridge/interfaces/BridgePoolInterface.sol/BridgePoolInterface.json +63 -0
- package/artifacts/contracts/insured-bridge/interfaces/MessengerInterface.sol/MessengerInterface.dbg.json +4 -0
- package/artifacts/contracts/insured-bridge/interfaces/MessengerInterface.sol/MessengerInterface.json +54 -0
- package/artifacts/contracts/insured-bridge/ovm/OVM_BridgeDepositBox.sol/OVM_BridgeDepositBox.dbg.json +4 -0
- package/artifacts/contracts/insured-bridge/ovm/OVM_BridgeDepositBox.sol/OVM_BridgeDepositBox.json +528 -0
- package/artifacts/contracts/insured-bridge/ovm/OVM_CrossDomainEnabled.sol/OVM_CrossDomainEnabled.dbg.json +4 -0
- package/artifacts/contracts/insured-bridge/ovm/OVM_CrossDomainEnabled.sol/OVM_CrossDomainEnabled.json +35 -0
- package/artifacts/contracts/insured-bridge/ovm/OVM_OETH_BridgeDepositBox.sol/OVM_OETH_BridgeDepositBox.dbg.json +4 -0
- package/artifacts/contracts/insured-bridge/ovm/OVM_OETH_BridgeDepositBox.sol/OVM_OETH_BridgeDepositBox.json +572 -0
- package/artifacts/contracts/insured-bridge/ovm/Optimism_Messenger.sol/Optimism_Messenger.dbg.json +4 -0
- package/artifacts/contracts/insured-bridge/ovm/Optimism_Messenger.sol/Optimism_Messenger.json +130 -0
- package/artifacts/contracts/insured-bridge/ovm/Optimism_Wrapper.sol/Optimism_Wrapper.dbg.json +4 -0
- package/artifacts/contracts/insured-bridge/ovm/Optimism_Wrapper.sol/Optimism_Wrapper.json +142 -0
- package/artifacts/contracts/insured-bridge/ovm/Optimism_Wrapper.sol/WETH9Like.dbg.json +4 -0
- package/artifacts/contracts/insured-bridge/ovm/Optimism_Wrapper.sol/WETH9Like.json +55 -0
- package/artifacts/contracts/insured-bridge/ovm/iOVM_CrossDomainMessenger.sol/iOVM_CrossDomainMessenger.dbg.json +4 -0
- package/artifacts/contracts/insured-bridge/ovm/iOVM_CrossDomainMessenger.sol/iOVM_CrossDomainMessenger.json +86 -0
- package/artifacts/contracts/insured-bridge/test/Arbitrum_InboxMock.sol/Arbitrum_BridgeMock.dbg.json +4 -0
- package/artifacts/contracts/insured-bridge/test/Arbitrum_InboxMock.sol/Arbitrum_BridgeMock.json +68 -0
- package/artifacts/contracts/insured-bridge/test/Arbitrum_InboxMock.sol/Arbitrum_InboxMock.dbg.json +4 -0
- package/artifacts/contracts/insured-bridge/test/Arbitrum_InboxMock.sol/Arbitrum_InboxMock.json +78 -0
- package/artifacts/contracts/insured-bridge/test/Arbitrum_InboxMock.sol/Arbitrum_OutboxMock.dbg.json +4 -0
- package/artifacts/contracts/insured-bridge/test/Arbitrum_InboxMock.sol/Arbitrum_OutboxMock.json +24 -0
- package/artifacts/contracts/insured-bridge/test/BridgeDepositBoxMock.sol/BridgeDepositBoxMock.dbg.json +4 -0
- package/artifacts/contracts/insured-bridge/test/BridgeDepositBoxMock.sol/BridgeDepositBoxMock.json +510 -0
- package/artifacts/contracts/insured-bridge/test/MessengerMock.sol/MessengerMock.dbg.json +4 -0
- package/artifacts/contracts/insured-bridge/test/MessengerMock.sol/MessengerMock.json +85 -0
- package/artifacts/contracts/insured-bridge/test/OVM_L1CrossDomainMessengerMock.sol/OVM_L1CrossDomainMessengerMock.dbg.json +4 -0
- package/artifacts/contracts/insured-bridge/test/OVM_L1CrossDomainMessengerMock.sol/OVM_L1CrossDomainMessengerMock.json +110 -0
- package/artifacts/contracts/oracle/implementation/Constants.sol/OptimisticOracleConstraints.dbg.json +4 -0
- package/artifacts/contracts/oracle/implementation/Constants.sol/OptimisticOracleConstraints.json +24 -0
- package/artifacts/contracts/oracle/implementation/Constants.sol/OracleInterfaces.dbg.json +4 -0
- package/artifacts/contracts/oracle/implementation/Constants.sol/OracleInterfaces.json +141 -0
- package/artifacts/contracts/oracle/interfaces/FinderInterface.sol/FinderInterface.dbg.json +4 -0
- package/artifacts/contracts/oracle/interfaces/FinderInterface.sol/FinderInterface.json +48 -0
- package/artifacts/contracts/oracle/interfaces/IdentifierWhitelistInterface.sol/IdentifierWhitelistInterface.dbg.json +4 -0
- package/artifacts/contracts/oracle/interfaces/IdentifierWhitelistInterface.sol/IdentifierWhitelistInterface.json +56 -0
- package/artifacts/contracts/oracle/interfaces/OptimisticOracleInterface.sol/OptimisticOracleInterface.dbg.json +4 -0
- package/artifacts/contracts/oracle/interfaces/OptimisticOracleInterface.sol/OptimisticOracleInterface.json +555 -0
- package/artifacts/contracts/oracle/interfaces/SkinnyOptimisticOracleInterface.sol/SkinnyOptimisticOracleInterface.dbg.json +4 -0
- package/artifacts/contracts/oracle/interfaces/SkinnyOptimisticOracleInterface.sol/SkinnyOptimisticOracleInterface.json +853 -0
- package/artifacts/contracts/oracle/interfaces/StoreInterface.sol/StoreInterface.dbg.json +4 -0
- package/artifacts/contracts/oracle/interfaces/StoreInterface.sol/StoreInterface.json +124 -0
- package/contracts/common/implementation/AncillaryData.sol +144 -0
- package/contracts/common/implementation/FixedPoint.sol +763 -0
- package/contracts/common/implementation/Lockable.sol +61 -0
- package/contracts/common/implementation/MultiCaller.sol +27 -0
- package/contracts/common/implementation/Testable.sol +52 -0
- package/contracts/common/implementation/Timer.sol +30 -0
- package/contracts/common/interfaces/AddressWhitelistInterface.sol +12 -0
- package/contracts/external/avm/AVM_CrossDomainEnabled.sol +43 -0
- package/contracts/external/avm/interfaces/ArbSys.sol +79 -0
- package/contracts/external/avm/interfaces/iArbitrum_Inbox.sol +28 -0
- package/contracts/external/avm/interfaces/iArbitrum_Outbox.sol +26 -0
- package/contracts/external/chainbridge/Bridge.sol +454 -0
- package/contracts/external/chainbridge/handlers/GenericHandler.sol +237 -0
- package/contracts/external/chainbridge/interfaces/IBridge.sol +20 -0
- package/contracts/external/chainbridge/interfaces/IDepositExecute.sol +29 -0
- package/contracts/external/chainbridge/interfaces/IERCHandler.sol +33 -0
- package/contracts/external/chainbridge/interfaces/IGenericHandler.sol +23 -0
- package/contracts/external/ovm/OVM_CrossDomainEnabled.sol +114 -0
- package/contracts/external/polygon/lib/Merkle.sol +36 -0
- package/contracts/external/polygon/lib/MerklePatriciaProof.sol +139 -0
- package/contracts/external/polygon/lib/RLPReader.sol +251 -0
- package/contracts/external/polygon/test/FxChildMock.sol +42 -0
- package/contracts/external/polygon/test/FxRootMock.sol +32 -0
- package/contracts/external/polygon/test/StateSyncMock.sol +26 -0
- package/contracts/external/polygon/tunnel/FxBaseChildTunnel.sol +80 -0
- package/contracts/external/polygon/tunnel/FxBaseRootTunnel.sol +185 -0
- package/contracts/insured-bridge/BridgeAdmin.sol +394 -0
- package/contracts/insured-bridge/BridgeDepositBox.sol +245 -0
- package/contracts/insured-bridge/BridgePool.sol +980 -0
- package/contracts/insured-bridge/avm/AVM_BridgeDepositBox.sol +144 -0
- package/contracts/insured-bridge/avm/Arbitrum_CrossDomainEnabled.sol +67 -0
- package/contracts/insured-bridge/avm/Arbitrum_Messenger.sol +72 -0
- package/contracts/insured-bridge/interfaces/BridgeAdminInterface.sol +44 -0
- package/contracts/insured-bridge/interfaces/BridgePoolInterface.sol +14 -0
- package/contracts/insured-bridge/interfaces/MessengerInterface.sol +18 -0
- package/contracts/insured-bridge/ovm/OVM_BridgeDepositBox.sol +135 -0
- package/contracts/insured-bridge/ovm/OVM_CrossDomainEnabled.sol +84 -0
- package/contracts/insured-bridge/ovm/OVM_OETH_BridgeDepositBox.sol +89 -0
- package/contracts/insured-bridge/ovm/Optimism_Messenger.sol +34 -0
- package/contracts/insured-bridge/ovm/Optimism_Wrapper.sol +59 -0
- package/contracts/insured-bridge/ovm/iOVM_CrossDomainMessenger.sol +41 -0
- package/contracts/insured-bridge/test/Arbitrum_InboxMock.sol +50 -0
- package/contracts/insured-bridge/test/BridgeDepositBoxMock.sol +113 -0
- package/contracts/insured-bridge/test/MessengerMock.sol +32 -0
- package/contracts/insured-bridge/test/OVM_L1CrossDomainMessengerMock.sol +16 -0
- package/contracts/oracle/implementation/Constants.sol +29 -0
- package/contracts/oracle/interfaces/FinderInterface.sol +22 -0
- package/contracts/oracle/interfaces/IdentifierWhitelistInterface.sol +28 -0
- package/contracts/oracle/interfaces/OptimisticOracleInterface.sol +263 -0
- package/contracts/oracle/interfaces/SkinnyOptimisticOracleInterface.sol +251 -0
- package/contracts/oracle/interfaces/StoreInterface.sol +46 -0
- package/package.json +60 -0
|
@@ -0,0 +1,763 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
|
|
5
|
+
import "@openzeppelin/contracts/utils/math/SignedSafeMath.sol";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @title Library for fixed point arithmetic on uints
|
|
9
|
+
*/
|
|
10
|
+
library FixedPoint {
|
|
11
|
+
using SafeMath for uint256;
|
|
12
|
+
using SignedSafeMath for int256;
|
|
13
|
+
|
|
14
|
+
// Supports 18 decimals. E.g., 1e18 represents "1", 5e17 represents "0.5".
|
|
15
|
+
// For unsigned values:
|
|
16
|
+
// This can represent a value up to (2^256 - 1)/10^18 = ~10^59. 10^59 will be stored internally as uint256 10^77.
|
|
17
|
+
uint256 private constant FP_SCALING_FACTOR = 10**18;
|
|
18
|
+
|
|
19
|
+
// --------------------------------------- UNSIGNED -----------------------------------------------------------------------------
|
|
20
|
+
struct Unsigned {
|
|
21
|
+
uint256 rawValue;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @notice Constructs an `Unsigned` from an unscaled uint, e.g., `b=5` gets stored internally as `5*(10**18)`.
|
|
26
|
+
* @param a uint to convert into a FixedPoint.
|
|
27
|
+
* @return the converted FixedPoint.
|
|
28
|
+
*/
|
|
29
|
+
function fromUnscaledUint(uint256 a) internal pure returns (Unsigned memory) {
|
|
30
|
+
return Unsigned(a.mul(FP_SCALING_FACTOR));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @notice Whether `a` is equal to `b`.
|
|
35
|
+
* @param a a FixedPoint.
|
|
36
|
+
* @param b a uint256.
|
|
37
|
+
* @return True if equal, or False.
|
|
38
|
+
*/
|
|
39
|
+
function isEqual(Unsigned memory a, uint256 b) internal pure returns (bool) {
|
|
40
|
+
return a.rawValue == fromUnscaledUint(b).rawValue;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @notice Whether `a` is equal to `b`.
|
|
45
|
+
* @param a a FixedPoint.
|
|
46
|
+
* @param b a FixedPoint.
|
|
47
|
+
* @return True if equal, or False.
|
|
48
|
+
*/
|
|
49
|
+
function isEqual(Unsigned memory a, Unsigned memory b) internal pure returns (bool) {
|
|
50
|
+
return a.rawValue == b.rawValue;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @notice Whether `a` is greater than `b`.
|
|
55
|
+
* @param a a FixedPoint.
|
|
56
|
+
* @param b a FixedPoint.
|
|
57
|
+
* @return True if `a > b`, or False.
|
|
58
|
+
*/
|
|
59
|
+
function isGreaterThan(Unsigned memory a, Unsigned memory b) internal pure returns (bool) {
|
|
60
|
+
return a.rawValue > b.rawValue;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @notice Whether `a` is greater than `b`.
|
|
65
|
+
* @param a a FixedPoint.
|
|
66
|
+
* @param b a uint256.
|
|
67
|
+
* @return True if `a > b`, or False.
|
|
68
|
+
*/
|
|
69
|
+
function isGreaterThan(Unsigned memory a, uint256 b) internal pure returns (bool) {
|
|
70
|
+
return a.rawValue > fromUnscaledUint(b).rawValue;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @notice Whether `a` is greater than `b`.
|
|
75
|
+
* @param a a uint256.
|
|
76
|
+
* @param b a FixedPoint.
|
|
77
|
+
* @return True if `a > b`, or False.
|
|
78
|
+
*/
|
|
79
|
+
function isGreaterThan(uint256 a, Unsigned memory b) internal pure returns (bool) {
|
|
80
|
+
return fromUnscaledUint(a).rawValue > b.rawValue;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @notice Whether `a` is greater than or equal to `b`.
|
|
85
|
+
* @param a a FixedPoint.
|
|
86
|
+
* @param b a FixedPoint.
|
|
87
|
+
* @return True if `a >= b`, or False.
|
|
88
|
+
*/
|
|
89
|
+
function isGreaterThanOrEqual(Unsigned memory a, Unsigned memory b) internal pure returns (bool) {
|
|
90
|
+
return a.rawValue >= b.rawValue;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @notice Whether `a` is greater than or equal to `b`.
|
|
95
|
+
* @param a a FixedPoint.
|
|
96
|
+
* @param b a uint256.
|
|
97
|
+
* @return True if `a >= b`, or False.
|
|
98
|
+
*/
|
|
99
|
+
function isGreaterThanOrEqual(Unsigned memory a, uint256 b) internal pure returns (bool) {
|
|
100
|
+
return a.rawValue >= fromUnscaledUint(b).rawValue;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* @notice Whether `a` is greater than or equal to `b`.
|
|
105
|
+
* @param a a uint256.
|
|
106
|
+
* @param b a FixedPoint.
|
|
107
|
+
* @return True if `a >= b`, or False.
|
|
108
|
+
*/
|
|
109
|
+
function isGreaterThanOrEqual(uint256 a, Unsigned memory b) internal pure returns (bool) {
|
|
110
|
+
return fromUnscaledUint(a).rawValue >= b.rawValue;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* @notice Whether `a` is less than `b`.
|
|
115
|
+
* @param a a FixedPoint.
|
|
116
|
+
* @param b a FixedPoint.
|
|
117
|
+
* @return True if `a < b`, or False.
|
|
118
|
+
*/
|
|
119
|
+
function isLessThan(Unsigned memory a, Unsigned memory b) internal pure returns (bool) {
|
|
120
|
+
return a.rawValue < b.rawValue;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* @notice Whether `a` is less than `b`.
|
|
125
|
+
* @param a a FixedPoint.
|
|
126
|
+
* @param b a uint256.
|
|
127
|
+
* @return True if `a < b`, or False.
|
|
128
|
+
*/
|
|
129
|
+
function isLessThan(Unsigned memory a, uint256 b) internal pure returns (bool) {
|
|
130
|
+
return a.rawValue < fromUnscaledUint(b).rawValue;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* @notice Whether `a` is less than `b`.
|
|
135
|
+
* @param a a uint256.
|
|
136
|
+
* @param b a FixedPoint.
|
|
137
|
+
* @return True if `a < b`, or False.
|
|
138
|
+
*/
|
|
139
|
+
function isLessThan(uint256 a, Unsigned memory b) internal pure returns (bool) {
|
|
140
|
+
return fromUnscaledUint(a).rawValue < b.rawValue;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* @notice Whether `a` is less than or equal to `b`.
|
|
145
|
+
* @param a a FixedPoint.
|
|
146
|
+
* @param b a FixedPoint.
|
|
147
|
+
* @return True if `a <= b`, or False.
|
|
148
|
+
*/
|
|
149
|
+
function isLessThanOrEqual(Unsigned memory a, Unsigned memory b) internal pure returns (bool) {
|
|
150
|
+
return a.rawValue <= b.rawValue;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* @notice Whether `a` is less than or equal to `b`.
|
|
155
|
+
* @param a a FixedPoint.
|
|
156
|
+
* @param b a uint256.
|
|
157
|
+
* @return True if `a <= b`, or False.
|
|
158
|
+
*/
|
|
159
|
+
function isLessThanOrEqual(Unsigned memory a, uint256 b) internal pure returns (bool) {
|
|
160
|
+
return a.rawValue <= fromUnscaledUint(b).rawValue;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* @notice Whether `a` is less than or equal to `b`.
|
|
165
|
+
* @param a a uint256.
|
|
166
|
+
* @param b a FixedPoint.
|
|
167
|
+
* @return True if `a <= b`, or False.
|
|
168
|
+
*/
|
|
169
|
+
function isLessThanOrEqual(uint256 a, Unsigned memory b) internal pure returns (bool) {
|
|
170
|
+
return fromUnscaledUint(a).rawValue <= b.rawValue;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* @notice The minimum of `a` and `b`.
|
|
175
|
+
* @param a a FixedPoint.
|
|
176
|
+
* @param b a FixedPoint.
|
|
177
|
+
* @return the minimum of `a` and `b`.
|
|
178
|
+
*/
|
|
179
|
+
function min(Unsigned memory a, Unsigned memory b) internal pure returns (Unsigned memory) {
|
|
180
|
+
return a.rawValue < b.rawValue ? a : b;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* @notice The maximum of `a` and `b`.
|
|
185
|
+
* @param a a FixedPoint.
|
|
186
|
+
* @param b a FixedPoint.
|
|
187
|
+
* @return the maximum of `a` and `b`.
|
|
188
|
+
*/
|
|
189
|
+
function max(Unsigned memory a, Unsigned memory b) internal pure returns (Unsigned memory) {
|
|
190
|
+
return a.rawValue > b.rawValue ? a : b;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* @notice Adds two `Unsigned`s, reverting on overflow.
|
|
195
|
+
* @param a a FixedPoint.
|
|
196
|
+
* @param b a FixedPoint.
|
|
197
|
+
* @return the sum of `a` and `b`.
|
|
198
|
+
*/
|
|
199
|
+
function add(Unsigned memory a, Unsigned memory b) internal pure returns (Unsigned memory) {
|
|
200
|
+
return Unsigned(a.rawValue.add(b.rawValue));
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* @notice Adds an `Unsigned` to an unscaled uint, reverting on overflow.
|
|
205
|
+
* @param a a FixedPoint.
|
|
206
|
+
* @param b a uint256.
|
|
207
|
+
* @return the sum of `a` and `b`.
|
|
208
|
+
*/
|
|
209
|
+
function add(Unsigned memory a, uint256 b) internal pure returns (Unsigned memory) {
|
|
210
|
+
return add(a, fromUnscaledUint(b));
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* @notice Subtracts two `Unsigned`s, reverting on overflow.
|
|
215
|
+
* @param a a FixedPoint.
|
|
216
|
+
* @param b a FixedPoint.
|
|
217
|
+
* @return the difference of `a` and `b`.
|
|
218
|
+
*/
|
|
219
|
+
function sub(Unsigned memory a, Unsigned memory b) internal pure returns (Unsigned memory) {
|
|
220
|
+
return Unsigned(a.rawValue.sub(b.rawValue));
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* @notice Subtracts an unscaled uint256 from an `Unsigned`, reverting on overflow.
|
|
225
|
+
* @param a a FixedPoint.
|
|
226
|
+
* @param b a uint256.
|
|
227
|
+
* @return the difference of `a` and `b`.
|
|
228
|
+
*/
|
|
229
|
+
function sub(Unsigned memory a, uint256 b) internal pure returns (Unsigned memory) {
|
|
230
|
+
return sub(a, fromUnscaledUint(b));
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* @notice Subtracts an `Unsigned` from an unscaled uint256, reverting on overflow.
|
|
235
|
+
* @param a a uint256.
|
|
236
|
+
* @param b a FixedPoint.
|
|
237
|
+
* @return the difference of `a` and `b`.
|
|
238
|
+
*/
|
|
239
|
+
function sub(uint256 a, Unsigned memory b) internal pure returns (Unsigned memory) {
|
|
240
|
+
return sub(fromUnscaledUint(a), b);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* @notice Multiplies two `Unsigned`s, reverting on overflow.
|
|
245
|
+
* @dev This will "floor" the product.
|
|
246
|
+
* @param a a FixedPoint.
|
|
247
|
+
* @param b a FixedPoint.
|
|
248
|
+
* @return the product of `a` and `b`.
|
|
249
|
+
*/
|
|
250
|
+
function mul(Unsigned memory a, Unsigned memory b) internal pure returns (Unsigned memory) {
|
|
251
|
+
// There are two caveats with this computation:
|
|
252
|
+
// 1. Max output for the represented number is ~10^41, otherwise an intermediate value overflows. 10^41 is
|
|
253
|
+
// stored internally as a uint256 ~10^59.
|
|
254
|
+
// 2. Results that can't be represented exactly are truncated not rounded. E.g., 1.4 * 2e-18 = 2.8e-18, which
|
|
255
|
+
// would round to 3, but this computation produces the result 2.
|
|
256
|
+
// No need to use SafeMath because FP_SCALING_FACTOR != 0.
|
|
257
|
+
return Unsigned(a.rawValue.mul(b.rawValue) / FP_SCALING_FACTOR);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* @notice Multiplies an `Unsigned` and an unscaled uint256, reverting on overflow.
|
|
262
|
+
* @dev This will "floor" the product.
|
|
263
|
+
* @param a a FixedPoint.
|
|
264
|
+
* @param b a uint256.
|
|
265
|
+
* @return the product of `a` and `b`.
|
|
266
|
+
*/
|
|
267
|
+
function mul(Unsigned memory a, uint256 b) internal pure returns (Unsigned memory) {
|
|
268
|
+
return Unsigned(a.rawValue.mul(b));
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* @notice Multiplies two `Unsigned`s and "ceil's" the product, reverting on overflow.
|
|
273
|
+
* @param a a FixedPoint.
|
|
274
|
+
* @param b a FixedPoint.
|
|
275
|
+
* @return the product of `a` and `b`.
|
|
276
|
+
*/
|
|
277
|
+
function mulCeil(Unsigned memory a, Unsigned memory b) internal pure returns (Unsigned memory) {
|
|
278
|
+
uint256 mulRaw = a.rawValue.mul(b.rawValue);
|
|
279
|
+
uint256 mulFloor = mulRaw / FP_SCALING_FACTOR;
|
|
280
|
+
uint256 mod = mulRaw.mod(FP_SCALING_FACTOR);
|
|
281
|
+
if (mod != 0) {
|
|
282
|
+
return Unsigned(mulFloor.add(1));
|
|
283
|
+
} else {
|
|
284
|
+
return Unsigned(mulFloor);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* @notice Multiplies an `Unsigned` and an unscaled uint256 and "ceil's" the product, reverting on overflow.
|
|
290
|
+
* @param a a FixedPoint.
|
|
291
|
+
* @param b a FixedPoint.
|
|
292
|
+
* @return the product of `a` and `b`.
|
|
293
|
+
*/
|
|
294
|
+
function mulCeil(Unsigned memory a, uint256 b) internal pure returns (Unsigned memory) {
|
|
295
|
+
// Since b is an uint, there is no risk of truncation and we can just mul it normally
|
|
296
|
+
return Unsigned(a.rawValue.mul(b));
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* @notice Divides one `Unsigned` by an `Unsigned`, reverting on overflow or division by 0.
|
|
301
|
+
* @dev This will "floor" the quotient.
|
|
302
|
+
* @param a a FixedPoint numerator.
|
|
303
|
+
* @param b a FixedPoint denominator.
|
|
304
|
+
* @return the quotient of `a` divided by `b`.
|
|
305
|
+
*/
|
|
306
|
+
function div(Unsigned memory a, Unsigned memory b) internal pure returns (Unsigned memory) {
|
|
307
|
+
// There are two caveats with this computation:
|
|
308
|
+
// 1. Max value for the number dividend `a` represents is ~10^41, otherwise an intermediate value overflows.
|
|
309
|
+
// 10^41 is stored internally as a uint256 10^59.
|
|
310
|
+
// 2. Results that can't be represented exactly are truncated not rounded. E.g., 2 / 3 = 0.6 repeating, which
|
|
311
|
+
// would round to 0.666666666666666667, but this computation produces the result 0.666666666666666666.
|
|
312
|
+
return Unsigned(a.rawValue.mul(FP_SCALING_FACTOR).div(b.rawValue));
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* @notice Divides one `Unsigned` by an unscaled uint256, reverting on overflow or division by 0.
|
|
317
|
+
* @dev This will "floor" the quotient.
|
|
318
|
+
* @param a a FixedPoint numerator.
|
|
319
|
+
* @param b a uint256 denominator.
|
|
320
|
+
* @return the quotient of `a` divided by `b`.
|
|
321
|
+
*/
|
|
322
|
+
function div(Unsigned memory a, uint256 b) internal pure returns (Unsigned memory) {
|
|
323
|
+
return Unsigned(a.rawValue.div(b));
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* @notice Divides one unscaled uint256 by an `Unsigned`, reverting on overflow or division by 0.
|
|
328
|
+
* @dev This will "floor" the quotient.
|
|
329
|
+
* @param a a uint256 numerator.
|
|
330
|
+
* @param b a FixedPoint denominator.
|
|
331
|
+
* @return the quotient of `a` divided by `b`.
|
|
332
|
+
*/
|
|
333
|
+
function div(uint256 a, Unsigned memory b) internal pure returns (Unsigned memory) {
|
|
334
|
+
return div(fromUnscaledUint(a), b);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* @notice Divides one `Unsigned` by an `Unsigned` and "ceil's" the quotient, reverting on overflow or division by 0.
|
|
339
|
+
* @param a a FixedPoint numerator.
|
|
340
|
+
* @param b a FixedPoint denominator.
|
|
341
|
+
* @return the quotient of `a` divided by `b`.
|
|
342
|
+
*/
|
|
343
|
+
function divCeil(Unsigned memory a, Unsigned memory b) internal pure returns (Unsigned memory) {
|
|
344
|
+
uint256 aScaled = a.rawValue.mul(FP_SCALING_FACTOR);
|
|
345
|
+
uint256 divFloor = aScaled.div(b.rawValue);
|
|
346
|
+
uint256 mod = aScaled.mod(b.rawValue);
|
|
347
|
+
if (mod != 0) {
|
|
348
|
+
return Unsigned(divFloor.add(1));
|
|
349
|
+
} else {
|
|
350
|
+
return Unsigned(divFloor);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* @notice Divides one `Unsigned` by an unscaled uint256 and "ceil's" the quotient, reverting on overflow or division by 0.
|
|
356
|
+
* @param a a FixedPoint numerator.
|
|
357
|
+
* @param b a uint256 denominator.
|
|
358
|
+
* @return the quotient of `a` divided by `b`.
|
|
359
|
+
*/
|
|
360
|
+
function divCeil(Unsigned memory a, uint256 b) internal pure returns (Unsigned memory) {
|
|
361
|
+
// Because it is possible that a quotient gets truncated, we can't just call "Unsigned(a.rawValue.div(b))"
|
|
362
|
+
// similarly to mulCeil with a uint256 as the second parameter. Therefore we need to convert b into an Unsigned.
|
|
363
|
+
// This creates the possibility of overflow if b is very large.
|
|
364
|
+
return divCeil(a, fromUnscaledUint(b));
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* @notice Raises an `Unsigned` to the power of an unscaled uint256, reverting on overflow. E.g., `b=2` squares `a`.
|
|
369
|
+
* @dev This will "floor" the result.
|
|
370
|
+
* @param a a FixedPoint numerator.
|
|
371
|
+
* @param b a uint256 denominator.
|
|
372
|
+
* @return output is `a` to the power of `b`.
|
|
373
|
+
*/
|
|
374
|
+
function pow(Unsigned memory a, uint256 b) internal pure returns (Unsigned memory output) {
|
|
375
|
+
output = fromUnscaledUint(1);
|
|
376
|
+
for (uint256 i = 0; i < b; i = i.add(1)) {
|
|
377
|
+
output = mul(output, a);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// ------------------------------------------------- SIGNED -------------------------------------------------------------
|
|
382
|
+
// Supports 18 decimals. E.g., 1e18 represents "1", 5e17 represents "0.5".
|
|
383
|
+
// For signed values:
|
|
384
|
+
// This can represent a value up (or down) to +-(2^255 - 1)/10^18 = ~10^58. 10^58 will be stored internally as int256 10^76.
|
|
385
|
+
int256 private constant SFP_SCALING_FACTOR = 10**18;
|
|
386
|
+
|
|
387
|
+
struct Signed {
|
|
388
|
+
int256 rawValue;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
function fromSigned(Signed memory a) internal pure returns (Unsigned memory) {
|
|
392
|
+
require(a.rawValue >= 0, "Negative value provided");
|
|
393
|
+
return Unsigned(uint256(a.rawValue));
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function fromUnsigned(Unsigned memory a) internal pure returns (Signed memory) {
|
|
397
|
+
require(a.rawValue <= uint256(type(int256).max), "Unsigned too large");
|
|
398
|
+
return Signed(int256(a.rawValue));
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* @notice Constructs a `Signed` from an unscaled int, e.g., `b=5` gets stored internally as `5*(10**18)`.
|
|
403
|
+
* @param a int to convert into a FixedPoint.Signed.
|
|
404
|
+
* @return the converted FixedPoint.Signed.
|
|
405
|
+
*/
|
|
406
|
+
function fromUnscaledInt(int256 a) internal pure returns (Signed memory) {
|
|
407
|
+
return Signed(a.mul(SFP_SCALING_FACTOR));
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* @notice Whether `a` is equal to `b`.
|
|
412
|
+
* @param a a FixedPoint.Signed.
|
|
413
|
+
* @param b a int256.
|
|
414
|
+
* @return True if equal, or False.
|
|
415
|
+
*/
|
|
416
|
+
function isEqual(Signed memory a, int256 b) internal pure returns (bool) {
|
|
417
|
+
return a.rawValue == fromUnscaledInt(b).rawValue;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* @notice Whether `a` is equal to `b`.
|
|
422
|
+
* @param a a FixedPoint.Signed.
|
|
423
|
+
* @param b a FixedPoint.Signed.
|
|
424
|
+
* @return True if equal, or False.
|
|
425
|
+
*/
|
|
426
|
+
function isEqual(Signed memory a, Signed memory b) internal pure returns (bool) {
|
|
427
|
+
return a.rawValue == b.rawValue;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* @notice Whether `a` is greater than `b`.
|
|
432
|
+
* @param a a FixedPoint.Signed.
|
|
433
|
+
* @param b a FixedPoint.Signed.
|
|
434
|
+
* @return True if `a > b`, or False.
|
|
435
|
+
*/
|
|
436
|
+
function isGreaterThan(Signed memory a, Signed memory b) internal pure returns (bool) {
|
|
437
|
+
return a.rawValue > b.rawValue;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* @notice Whether `a` is greater than `b`.
|
|
442
|
+
* @param a a FixedPoint.Signed.
|
|
443
|
+
* @param b an int256.
|
|
444
|
+
* @return True if `a > b`, or False.
|
|
445
|
+
*/
|
|
446
|
+
function isGreaterThan(Signed memory a, int256 b) internal pure returns (bool) {
|
|
447
|
+
return a.rawValue > fromUnscaledInt(b).rawValue;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* @notice Whether `a` is greater than `b`.
|
|
452
|
+
* @param a an int256.
|
|
453
|
+
* @param b a FixedPoint.Signed.
|
|
454
|
+
* @return True if `a > b`, or False.
|
|
455
|
+
*/
|
|
456
|
+
function isGreaterThan(int256 a, Signed memory b) internal pure returns (bool) {
|
|
457
|
+
return fromUnscaledInt(a).rawValue > b.rawValue;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* @notice Whether `a` is greater than or equal to `b`.
|
|
462
|
+
* @param a a FixedPoint.Signed.
|
|
463
|
+
* @param b a FixedPoint.Signed.
|
|
464
|
+
* @return True if `a >= b`, or False.
|
|
465
|
+
*/
|
|
466
|
+
function isGreaterThanOrEqual(Signed memory a, Signed memory b) internal pure returns (bool) {
|
|
467
|
+
return a.rawValue >= b.rawValue;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* @notice Whether `a` is greater than or equal to `b`.
|
|
472
|
+
* @param a a FixedPoint.Signed.
|
|
473
|
+
* @param b an int256.
|
|
474
|
+
* @return True if `a >= b`, or False.
|
|
475
|
+
*/
|
|
476
|
+
function isGreaterThanOrEqual(Signed memory a, int256 b) internal pure returns (bool) {
|
|
477
|
+
return a.rawValue >= fromUnscaledInt(b).rawValue;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* @notice Whether `a` is greater than or equal to `b`.
|
|
482
|
+
* @param a an int256.
|
|
483
|
+
* @param b a FixedPoint.Signed.
|
|
484
|
+
* @return True if `a >= b`, or False.
|
|
485
|
+
*/
|
|
486
|
+
function isGreaterThanOrEqual(int256 a, Signed memory b) internal pure returns (bool) {
|
|
487
|
+
return fromUnscaledInt(a).rawValue >= b.rawValue;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* @notice Whether `a` is less than `b`.
|
|
492
|
+
* @param a a FixedPoint.Signed.
|
|
493
|
+
* @param b a FixedPoint.Signed.
|
|
494
|
+
* @return True if `a < b`, or False.
|
|
495
|
+
*/
|
|
496
|
+
function isLessThan(Signed memory a, Signed memory b) internal pure returns (bool) {
|
|
497
|
+
return a.rawValue < b.rawValue;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* @notice Whether `a` is less than `b`.
|
|
502
|
+
* @param a a FixedPoint.Signed.
|
|
503
|
+
* @param b an int256.
|
|
504
|
+
* @return True if `a < b`, or False.
|
|
505
|
+
*/
|
|
506
|
+
function isLessThan(Signed memory a, int256 b) internal pure returns (bool) {
|
|
507
|
+
return a.rawValue < fromUnscaledInt(b).rawValue;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* @notice Whether `a` is less than `b`.
|
|
512
|
+
* @param a an int256.
|
|
513
|
+
* @param b a FixedPoint.Signed.
|
|
514
|
+
* @return True if `a < b`, or False.
|
|
515
|
+
*/
|
|
516
|
+
function isLessThan(int256 a, Signed memory b) internal pure returns (bool) {
|
|
517
|
+
return fromUnscaledInt(a).rawValue < b.rawValue;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
/**
|
|
521
|
+
* @notice Whether `a` is less than or equal to `b`.
|
|
522
|
+
* @param a a FixedPoint.Signed.
|
|
523
|
+
* @param b a FixedPoint.Signed.
|
|
524
|
+
* @return True if `a <= b`, or False.
|
|
525
|
+
*/
|
|
526
|
+
function isLessThanOrEqual(Signed memory a, Signed memory b) internal pure returns (bool) {
|
|
527
|
+
return a.rawValue <= b.rawValue;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* @notice Whether `a` is less than or equal to `b`.
|
|
532
|
+
* @param a a FixedPoint.Signed.
|
|
533
|
+
* @param b an int256.
|
|
534
|
+
* @return True if `a <= b`, or False.
|
|
535
|
+
*/
|
|
536
|
+
function isLessThanOrEqual(Signed memory a, int256 b) internal pure returns (bool) {
|
|
537
|
+
return a.rawValue <= fromUnscaledInt(b).rawValue;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* @notice Whether `a` is less than or equal to `b`.
|
|
542
|
+
* @param a an int256.
|
|
543
|
+
* @param b a FixedPoint.Signed.
|
|
544
|
+
* @return True if `a <= b`, or False.
|
|
545
|
+
*/
|
|
546
|
+
function isLessThanOrEqual(int256 a, Signed memory b) internal pure returns (bool) {
|
|
547
|
+
return fromUnscaledInt(a).rawValue <= b.rawValue;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
/**
|
|
551
|
+
* @notice The minimum of `a` and `b`.
|
|
552
|
+
* @param a a FixedPoint.Signed.
|
|
553
|
+
* @param b a FixedPoint.Signed.
|
|
554
|
+
* @return the minimum of `a` and `b`.
|
|
555
|
+
*/
|
|
556
|
+
function min(Signed memory a, Signed memory b) internal pure returns (Signed memory) {
|
|
557
|
+
return a.rawValue < b.rawValue ? a : b;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* @notice The maximum of `a` and `b`.
|
|
562
|
+
* @param a a FixedPoint.Signed.
|
|
563
|
+
* @param b a FixedPoint.Signed.
|
|
564
|
+
* @return the maximum of `a` and `b`.
|
|
565
|
+
*/
|
|
566
|
+
function max(Signed memory a, Signed memory b) internal pure returns (Signed memory) {
|
|
567
|
+
return a.rawValue > b.rawValue ? a : b;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* @notice Adds two `Signed`s, reverting on overflow.
|
|
572
|
+
* @param a a FixedPoint.Signed.
|
|
573
|
+
* @param b a FixedPoint.Signed.
|
|
574
|
+
* @return the sum of `a` and `b`.
|
|
575
|
+
*/
|
|
576
|
+
function add(Signed memory a, Signed memory b) internal pure returns (Signed memory) {
|
|
577
|
+
return Signed(a.rawValue.add(b.rawValue));
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* @notice Adds an `Signed` to an unscaled int, reverting on overflow.
|
|
582
|
+
* @param a a FixedPoint.Signed.
|
|
583
|
+
* @param b an int256.
|
|
584
|
+
* @return the sum of `a` and `b`.
|
|
585
|
+
*/
|
|
586
|
+
function add(Signed memory a, int256 b) internal pure returns (Signed memory) {
|
|
587
|
+
return add(a, fromUnscaledInt(b));
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
/**
|
|
591
|
+
* @notice Subtracts two `Signed`s, reverting on overflow.
|
|
592
|
+
* @param a a FixedPoint.Signed.
|
|
593
|
+
* @param b a FixedPoint.Signed.
|
|
594
|
+
* @return the difference of `a` and `b`.
|
|
595
|
+
*/
|
|
596
|
+
function sub(Signed memory a, Signed memory b) internal pure returns (Signed memory) {
|
|
597
|
+
return Signed(a.rawValue.sub(b.rawValue));
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
/**
|
|
601
|
+
* @notice Subtracts an unscaled int256 from an `Signed`, reverting on overflow.
|
|
602
|
+
* @param a a FixedPoint.Signed.
|
|
603
|
+
* @param b an int256.
|
|
604
|
+
* @return the difference of `a` and `b`.
|
|
605
|
+
*/
|
|
606
|
+
function sub(Signed memory a, int256 b) internal pure returns (Signed memory) {
|
|
607
|
+
return sub(a, fromUnscaledInt(b));
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
/**
|
|
611
|
+
* @notice Subtracts an `Signed` from an unscaled int256, reverting on overflow.
|
|
612
|
+
* @param a an int256.
|
|
613
|
+
* @param b a FixedPoint.Signed.
|
|
614
|
+
* @return the difference of `a` and `b`.
|
|
615
|
+
*/
|
|
616
|
+
function sub(int256 a, Signed memory b) internal pure returns (Signed memory) {
|
|
617
|
+
return sub(fromUnscaledInt(a), b);
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* @notice Multiplies two `Signed`s, reverting on overflow.
|
|
622
|
+
* @dev This will "floor" the product.
|
|
623
|
+
* @param a a FixedPoint.Signed.
|
|
624
|
+
* @param b a FixedPoint.Signed.
|
|
625
|
+
* @return the product of `a` and `b`.
|
|
626
|
+
*/
|
|
627
|
+
function mul(Signed memory a, Signed memory b) internal pure returns (Signed memory) {
|
|
628
|
+
// There are two caveats with this computation:
|
|
629
|
+
// 1. Max output for the represented number is ~10^41, otherwise an intermediate value overflows. 10^41 is
|
|
630
|
+
// stored internally as an int256 ~10^59.
|
|
631
|
+
// 2. Results that can't be represented exactly are truncated not rounded. E.g., 1.4 * 2e-18 = 2.8e-18, which
|
|
632
|
+
// would round to 3, but this computation produces the result 2.
|
|
633
|
+
// No need to use SafeMath because SFP_SCALING_FACTOR != 0.
|
|
634
|
+
return Signed(a.rawValue.mul(b.rawValue) / SFP_SCALING_FACTOR);
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* @notice Multiplies an `Signed` and an unscaled int256, reverting on overflow.
|
|
639
|
+
* @dev This will "floor" the product.
|
|
640
|
+
* @param a a FixedPoint.Signed.
|
|
641
|
+
* @param b an int256.
|
|
642
|
+
* @return the product of `a` and `b`.
|
|
643
|
+
*/
|
|
644
|
+
function mul(Signed memory a, int256 b) internal pure returns (Signed memory) {
|
|
645
|
+
return Signed(a.rawValue.mul(b));
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
/**
|
|
649
|
+
* @notice Multiplies two `Signed`s and "ceil's" the product, reverting on overflow.
|
|
650
|
+
* @param a a FixedPoint.Signed.
|
|
651
|
+
* @param b a FixedPoint.Signed.
|
|
652
|
+
* @return the product of `a` and `b`.
|
|
653
|
+
*/
|
|
654
|
+
function mulAwayFromZero(Signed memory a, Signed memory b) internal pure returns (Signed memory) {
|
|
655
|
+
int256 mulRaw = a.rawValue.mul(b.rawValue);
|
|
656
|
+
int256 mulTowardsZero = mulRaw / SFP_SCALING_FACTOR;
|
|
657
|
+
// Manual mod because SignedSafeMath doesn't support it.
|
|
658
|
+
int256 mod = mulRaw % SFP_SCALING_FACTOR;
|
|
659
|
+
if (mod != 0) {
|
|
660
|
+
bool isResultPositive = isLessThan(a, 0) == isLessThan(b, 0);
|
|
661
|
+
int256 valueToAdd = isResultPositive ? int256(1) : int256(-1);
|
|
662
|
+
return Signed(mulTowardsZero.add(valueToAdd));
|
|
663
|
+
} else {
|
|
664
|
+
return Signed(mulTowardsZero);
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* @notice Multiplies an `Signed` and an unscaled int256 and "ceil's" the product, reverting on overflow.
|
|
670
|
+
* @param a a FixedPoint.Signed.
|
|
671
|
+
* @param b a FixedPoint.Signed.
|
|
672
|
+
* @return the product of `a` and `b`.
|
|
673
|
+
*/
|
|
674
|
+
function mulAwayFromZero(Signed memory a, int256 b) internal pure returns (Signed memory) {
|
|
675
|
+
// Since b is an int, there is no risk of truncation and we can just mul it normally
|
|
676
|
+
return Signed(a.rawValue.mul(b));
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
/**
|
|
680
|
+
* @notice Divides one `Signed` by an `Signed`, reverting on overflow or division by 0.
|
|
681
|
+
* @dev This will "floor" the quotient.
|
|
682
|
+
* @param a a FixedPoint numerator.
|
|
683
|
+
* @param b a FixedPoint denominator.
|
|
684
|
+
* @return the quotient of `a` divided by `b`.
|
|
685
|
+
*/
|
|
686
|
+
function div(Signed memory a, Signed memory b) internal pure returns (Signed memory) {
|
|
687
|
+
// There are two caveats with this computation:
|
|
688
|
+
// 1. Max value for the number dividend `a` represents is ~10^41, otherwise an intermediate value overflows.
|
|
689
|
+
// 10^41 is stored internally as an int256 10^59.
|
|
690
|
+
// 2. Results that can't be represented exactly are truncated not rounded. E.g., 2 / 3 = 0.6 repeating, which
|
|
691
|
+
// would round to 0.666666666666666667, but this computation produces the result 0.666666666666666666.
|
|
692
|
+
return Signed(a.rawValue.mul(SFP_SCALING_FACTOR).div(b.rawValue));
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
/**
|
|
696
|
+
* @notice Divides one `Signed` by an unscaled int256, reverting on overflow or division by 0.
|
|
697
|
+
* @dev This will "floor" the quotient.
|
|
698
|
+
* @param a a FixedPoint numerator.
|
|
699
|
+
* @param b an int256 denominator.
|
|
700
|
+
* @return the quotient of `a` divided by `b`.
|
|
701
|
+
*/
|
|
702
|
+
function div(Signed memory a, int256 b) internal pure returns (Signed memory) {
|
|
703
|
+
return Signed(a.rawValue.div(b));
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
/**
|
|
707
|
+
* @notice Divides one unscaled int256 by an `Signed`, reverting on overflow or division by 0.
|
|
708
|
+
* @dev This will "floor" the quotient.
|
|
709
|
+
* @param a an int256 numerator.
|
|
710
|
+
* @param b a FixedPoint denominator.
|
|
711
|
+
* @return the quotient of `a` divided by `b`.
|
|
712
|
+
*/
|
|
713
|
+
function div(int256 a, Signed memory b) internal pure returns (Signed memory) {
|
|
714
|
+
return div(fromUnscaledInt(a), b);
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
/**
|
|
718
|
+
* @notice Divides one `Signed` by an `Signed` and "ceil's" the quotient, reverting on overflow or division by 0.
|
|
719
|
+
* @param a a FixedPoint numerator.
|
|
720
|
+
* @param b a FixedPoint denominator.
|
|
721
|
+
* @return the quotient of `a` divided by `b`.
|
|
722
|
+
*/
|
|
723
|
+
function divAwayFromZero(Signed memory a, Signed memory b) internal pure returns (Signed memory) {
|
|
724
|
+
int256 aScaled = a.rawValue.mul(SFP_SCALING_FACTOR);
|
|
725
|
+
int256 divTowardsZero = aScaled.div(b.rawValue);
|
|
726
|
+
// Manual mod because SignedSafeMath doesn't support it.
|
|
727
|
+
int256 mod = aScaled % b.rawValue;
|
|
728
|
+
if (mod != 0) {
|
|
729
|
+
bool isResultPositive = isLessThan(a, 0) == isLessThan(b, 0);
|
|
730
|
+
int256 valueToAdd = isResultPositive ? int256(1) : int256(-1);
|
|
731
|
+
return Signed(divTowardsZero.add(valueToAdd));
|
|
732
|
+
} else {
|
|
733
|
+
return Signed(divTowardsZero);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
/**
|
|
738
|
+
* @notice Divides one `Signed` by an unscaled int256 and "ceil's" the quotient, reverting on overflow or division by 0.
|
|
739
|
+
* @param a a FixedPoint numerator.
|
|
740
|
+
* @param b an int256 denominator.
|
|
741
|
+
* @return the quotient of `a` divided by `b`.
|
|
742
|
+
*/
|
|
743
|
+
function divAwayFromZero(Signed memory a, int256 b) internal pure returns (Signed memory) {
|
|
744
|
+
// Because it is possible that a quotient gets truncated, we can't just call "Signed(a.rawValue.div(b))"
|
|
745
|
+
// similarly to mulCeil with an int256 as the second parameter. Therefore we need to convert b into an Signed.
|
|
746
|
+
// This creates the possibility of overflow if b is very large.
|
|
747
|
+
return divAwayFromZero(a, fromUnscaledInt(b));
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
/**
|
|
751
|
+
* @notice Raises an `Signed` to the power of an unscaled uint256, reverting on overflow. E.g., `b=2` squares `a`.
|
|
752
|
+
* @dev This will "floor" the result.
|
|
753
|
+
* @param a a FixedPoint.Signed.
|
|
754
|
+
* @param b a uint256 (negative exponents are not allowed).
|
|
755
|
+
* @return output is `a` to the power of `b`.
|
|
756
|
+
*/
|
|
757
|
+
function pow(Signed memory a, uint256 b) internal pure returns (Signed memory output) {
|
|
758
|
+
output = fromUnscaledInt(1);
|
|
759
|
+
for (uint256 i = 0; i < b; i = i.add(1)) {
|
|
760
|
+
output = mul(output, a);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
}
|