proxy.adoc 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277
  1. :github-icon: pass:[<svg class="icon"><use href="#github-icon"/></svg>]
  2. :Proxy: pass:normal[xref:proxy.adoc#Proxy[`Proxy`]]
  3. :ERC1967Utils: pass:normal[xref:proxy.adoc#ERC1967Utils[`ERC1967Utils`]]
  4. :ERC1967Proxy: pass:normal[xref:proxy.adoc#ERC1967Proxy[`ERC1967Proxy`]]
  5. :TransparentUpgradeableProxy: pass:normal[xref:proxy.adoc#TransparentUpgradeableProxy[`TransparentUpgradeableProxy`]]
  6. :UUPSUpgradeable: pass:normal[xref:proxy.adoc#UUPSUpgradeable[`UUPSUpgradeable`]]
  7. :BeaconProxy: pass:normal[xref:proxy.adoc#BeaconProxy[`BeaconProxy`]]
  8. :UpgradeableBeacon: pass:normal[xref:proxy.adoc#UpgradeableBeacon[`UpgradeableBeacon`]]
  9. :BeaconProxy: pass:normal[xref:proxy.adoc#BeaconProxy[`BeaconProxy`]]
  10. :Clones: pass:normal[xref:proxy.adoc#Clones[`Clones`]]
  11. :TransparentUpgradeableProxy: pass:normal[xref:proxy.adoc#TransparentUpgradeableProxy[`TransparentUpgradeableProxy`]]
  12. :ERC1967Proxy: pass:normal[xref:proxy.adoc#ERC1967Proxy[`ERC1967Proxy`]]
  13. :UUPSUpgradeable: pass:normal[xref:proxy.adoc#UUPSUpgradeable[`UUPSUpgradeable`]]
  14. :xref-UUPSUpgradeable-_authorizeUpgrade-address-: xref:proxy.adoc#UUPSUpgradeable-_authorizeUpgrade-address-
  15. :TransparentUpgradeableProxy: pass:normal[xref:proxy.adoc#TransparentUpgradeableProxy[`TransparentUpgradeableProxy`]]
  16. :UUPSUpgradeable: pass:normal[xref:proxy.adoc#UUPSUpgradeable[`UUPSUpgradeable`]]
  17. :xref-Proxy-_delegate-address-: xref:proxy.adoc#Proxy-_delegate-address-
  18. :xref-Proxy-_implementation--: xref:proxy.adoc#Proxy-_implementation--
  19. :xref-Proxy-_fallback--: xref:proxy.adoc#Proxy-_fallback--
  20. :xref-Proxy-fallback--: xref:proxy.adoc#Proxy-fallback--
  21. :xref-ERC1967Proxy-constructor-address-bytes-: xref:proxy.adoc#ERC1967Proxy-constructor-address-bytes-
  22. :xref-ERC1967Proxy-_implementation--: xref:proxy.adoc#ERC1967Proxy-_implementation--
  23. :xref-Proxy-_delegate-address-: xref:proxy.adoc#Proxy-_delegate-address-
  24. :xref-Proxy-_fallback--: xref:proxy.adoc#Proxy-_fallback--
  25. :xref-Proxy-fallback--: xref:proxy.adoc#Proxy-fallback--
  26. :xref-ERC1967Utils-getImplementation--: xref:proxy.adoc#ERC1967Utils-getImplementation--
  27. :xref-ERC1967Utils-upgradeToAndCall-address-bytes-: xref:proxy.adoc#ERC1967Utils-upgradeToAndCall-address-bytes-
  28. :xref-ERC1967Utils-getAdmin--: xref:proxy.adoc#ERC1967Utils-getAdmin--
  29. :xref-ERC1967Utils-changeAdmin-address-: xref:proxy.adoc#ERC1967Utils-changeAdmin-address-
  30. :xref-ERC1967Utils-getBeacon--: xref:proxy.adoc#ERC1967Utils-getBeacon--
  31. :xref-ERC1967Utils-upgradeBeaconToAndCall-address-bytes-: xref:proxy.adoc#ERC1967Utils-upgradeBeaconToAndCall-address-bytes-
  32. :xref-ERC1967Utils-Upgraded-address-: xref:proxy.adoc#ERC1967Utils-Upgraded-address-
  33. :xref-ERC1967Utils-AdminChanged-address-address-: xref:proxy.adoc#ERC1967Utils-AdminChanged-address-address-
  34. :xref-ERC1967Utils-BeaconUpgraded-address-: xref:proxy.adoc#ERC1967Utils-BeaconUpgraded-address-
  35. :xref-ERC1967Utils-ERC1967InvalidImplementation-address-: xref:proxy.adoc#ERC1967Utils-ERC1967InvalidImplementation-address-
  36. :xref-ERC1967Utils-ERC1967InvalidAdmin-address-: xref:proxy.adoc#ERC1967Utils-ERC1967InvalidAdmin-address-
  37. :xref-ERC1967Utils-ERC1967InvalidBeacon-address-: xref:proxy.adoc#ERC1967Utils-ERC1967InvalidBeacon-address-
  38. :xref-ERC1967Utils-ERC1967NonPayable--: xref:proxy.adoc#ERC1967Utils-ERC1967NonPayable--
  39. :IERC1967-Upgraded: pass:normal[xref:interfaces.adoc#IERC1967-Upgraded-address-[`IERC1967.Upgraded`]]
  40. :IERC1967-AdminChanged: pass:normal[xref:interfaces.adoc#IERC1967-AdminChanged-address-address-[`IERC1967.AdminChanged`]]
  41. :IERC1967-BeaconUpgraded: pass:normal[xref:interfaces.adoc#IERC1967-BeaconUpgraded-address-[`IERC1967.BeaconUpgraded`]]
  42. :BeaconProxy: pass:normal[xref:proxy.adoc#BeaconProxy[`BeaconProxy`]]
  43. :ProxyAdmin: pass:normal[xref:proxy.adoc#ProxyAdmin[`ProxyAdmin`]]
  44. :ITransparentUpgradeableProxy-upgradeToAndCall: pass:normal[xref:proxy.adoc#ITransparentUpgradeableProxy-upgradeToAndCall-address-bytes-[`ITransparentUpgradeableProxy.upgradeToAndCall`]]
  45. :ProxyAdmin: pass:normal[xref:proxy.adoc#ProxyAdmin[`ProxyAdmin`]]
  46. :Context: pass:normal[xref:utils.adoc#Context[`Context`]]
  47. :ProxyAdmin: pass:normal[xref:proxy.adoc#ProxyAdmin[`ProxyAdmin`]]
  48. :ITransparentUpgradeableProxy: pass:normal[xref:proxy.adoc#ITransparentUpgradeableProxy[`ITransparentUpgradeableProxy`]]
  49. :xref-TransparentUpgradeableProxy-constructor-address-address-bytes-: xref:proxy.adoc#TransparentUpgradeableProxy-constructor-address-address-bytes-
  50. :xref-TransparentUpgradeableProxy-_proxyAdmin--: xref:proxy.adoc#TransparentUpgradeableProxy-_proxyAdmin--
  51. :xref-TransparentUpgradeableProxy-_fallback--: xref:proxy.adoc#TransparentUpgradeableProxy-_fallback--
  52. :xref-ERC1967Proxy-_implementation--: xref:proxy.adoc#ERC1967Proxy-_implementation--
  53. :xref-Proxy-_delegate-address-: xref:proxy.adoc#Proxy-_delegate-address-
  54. :xref-Proxy-fallback--: xref:proxy.adoc#Proxy-fallback--
  55. :xref-TransparentUpgradeableProxy-ProxyDeniedAdminAccess--: xref:proxy.adoc#TransparentUpgradeableProxy-ProxyDeniedAdminAccess--
  56. :ProxyAdmin: pass:normal[xref:proxy.adoc#ProxyAdmin[`ProxyAdmin`]]
  57. :ERC1967Proxy-constructor: pass:normal[xref:proxy.adoc#ERC1967Proxy-constructor-address-bytes-[`ERC1967Proxy.constructor`]]
  58. :TransparentUpgradeableProxy: pass:normal[xref:proxy.adoc#TransparentUpgradeableProxy[`TransparentUpgradeableProxy`]]
  59. :TransparentUpgradeableProxy: pass:normal[xref:proxy.adoc#TransparentUpgradeableProxy[`TransparentUpgradeableProxy`]]
  60. :xref-ProxyAdmin-constructor-address-: xref:proxy.adoc#ProxyAdmin-constructor-address-
  61. :xref-ProxyAdmin-upgradeAndCall-contract-ITransparentUpgradeableProxy-address-bytes-: xref:proxy.adoc#ProxyAdmin-upgradeAndCall-contract-ITransparentUpgradeableProxy-address-bytes-
  62. :xref-ProxyAdmin-UPGRADE_INTERFACE_VERSION-string: xref:proxy.adoc#ProxyAdmin-UPGRADE_INTERFACE_VERSION-string
  63. :xref-Ownable-owner--: xref:access.adoc#Ownable-owner--
  64. :xref-Ownable-_checkOwner--: xref:access.adoc#Ownable-_checkOwner--
  65. :xref-Ownable-renounceOwnership--: xref:access.adoc#Ownable-renounceOwnership--
  66. :xref-Ownable-transferOwnership-address-: xref:access.adoc#Ownable-transferOwnership-address-
  67. :xref-Ownable-_transferOwnership-address-: xref:access.adoc#Ownable-_transferOwnership-address-
  68. :xref-Ownable-OwnershipTransferred-address-address-: xref:access.adoc#Ownable-OwnershipTransferred-address-address-
  69. :xref-Ownable-OwnableUnauthorizedAccount-address-: xref:access.adoc#Ownable-OwnableUnauthorizedAccount-address-
  70. :xref-Ownable-OwnableInvalidOwner-address-: xref:access.adoc#Ownable-OwnableInvalidOwner-address-
  71. :TransparentUpgradeableProxy-_dispatchUpgradeToAndCall: pass:normal[xref:proxy.adoc#TransparentUpgradeableProxy-_dispatchUpgradeToAndCall--[`TransparentUpgradeableProxy._dispatchUpgradeToAndCall`]]
  72. :UpgradeableBeacon: pass:normal[xref:proxy.adoc#UpgradeableBeacon[`UpgradeableBeacon`]]
  73. :xref-BeaconProxy-constructor-address-bytes-: xref:proxy.adoc#BeaconProxy-constructor-address-bytes-
  74. :xref-BeaconProxy-_implementation--: xref:proxy.adoc#BeaconProxy-_implementation--
  75. :xref-BeaconProxy-_getBeacon--: xref:proxy.adoc#BeaconProxy-_getBeacon--
  76. :xref-Proxy-_delegate-address-: xref:proxy.adoc#Proxy-_delegate-address-
  77. :xref-Proxy-_fallback--: xref:proxy.adoc#Proxy-_fallback--
  78. :xref-Proxy-fallback--: xref:proxy.adoc#Proxy-fallback--
  79. :IBeacon: pass:normal[xref:proxy.adoc#IBeacon[`IBeacon`]]
  80. :BeaconProxy: pass:normal[xref:proxy.adoc#BeaconProxy[`BeaconProxy`]]
  81. :xref-IBeacon-implementation--: xref:proxy.adoc#IBeacon-implementation--
  82. :UpgradeableBeacon: pass:normal[xref:proxy.adoc#UpgradeableBeacon[`UpgradeableBeacon`]]
  83. :BeaconProxy: pass:normal[xref:proxy.adoc#BeaconProxy[`BeaconProxy`]]
  84. :xref-UpgradeableBeacon-constructor-address-address-: xref:proxy.adoc#UpgradeableBeacon-constructor-address-address-
  85. :xref-UpgradeableBeacon-implementation--: xref:proxy.adoc#UpgradeableBeacon-implementation--
  86. :xref-UpgradeableBeacon-upgradeTo-address-: xref:proxy.adoc#UpgradeableBeacon-upgradeTo-address-
  87. :xref-Ownable-owner--: xref:access.adoc#Ownable-owner--
  88. :xref-Ownable-_checkOwner--: xref:access.adoc#Ownable-_checkOwner--
  89. :xref-Ownable-renounceOwnership--: xref:access.adoc#Ownable-renounceOwnership--
  90. :xref-Ownable-transferOwnership-address-: xref:access.adoc#Ownable-transferOwnership-address-
  91. :xref-Ownable-_transferOwnership-address-: xref:access.adoc#Ownable-_transferOwnership-address-
  92. :xref-UpgradeableBeacon-Upgraded-address-: xref:proxy.adoc#UpgradeableBeacon-Upgraded-address-
  93. :xref-Ownable-OwnershipTransferred-address-address-: xref:access.adoc#Ownable-OwnershipTransferred-address-address-
  94. :xref-UpgradeableBeacon-BeaconInvalidImplementation-address-: xref:proxy.adoc#UpgradeableBeacon-BeaconInvalidImplementation-address-
  95. :xref-Ownable-OwnableUnauthorizedAccount-address-: xref:access.adoc#Ownable-OwnableUnauthorizedAccount-address-
  96. :xref-Ownable-OwnableInvalidOwner-address-: xref:access.adoc#Ownable-OwnableInvalidOwner-address-
  97. :xref-Clones-clone-address-: xref:proxy.adoc#Clones-clone-address-
  98. :xref-Clones-cloneDeterministic-address-bytes32-: xref:proxy.adoc#Clones-cloneDeterministic-address-bytes32-
  99. :xref-Clones-predictDeterministicAddress-address-bytes32-address-: xref:proxy.adoc#Clones-predictDeterministicAddress-address-bytes32-address-
  100. :xref-Clones-predictDeterministicAddress-address-bytes32-: xref:proxy.adoc#Clones-predictDeterministicAddress-address-bytes32-
  101. :xref-Clones-ERC1167FailedCreateClone--: xref:proxy.adoc#Clones-ERC1167FailedCreateClone--
  102. :Clones-cloneDeterministic: pass:normal[xref:proxy.adoc#Clones-cloneDeterministic-address-bytes32-[`Clones.cloneDeterministic`]]
  103. :Clones-cloneDeterministic: pass:normal[xref:proxy.adoc#Clones-cloneDeterministic-address-bytes32-[`Clones.cloneDeterministic`]]
  104. :ERC1967Proxy-constructor: pass:normal[xref:proxy.adoc#ERC1967Proxy-constructor-address-bytes-[`ERC1967Proxy.constructor`]]
  105. :xref-Initializable-initializer--: xref:proxy.adoc#Initializable-initializer--
  106. :xref-Initializable-reinitializer-uint64-: xref:proxy.adoc#Initializable-reinitializer-uint64-
  107. :xref-Initializable-onlyInitializing--: xref:proxy.adoc#Initializable-onlyInitializing--
  108. :xref-Initializable-_checkInitializing--: xref:proxy.adoc#Initializable-_checkInitializing--
  109. :xref-Initializable-_disableInitializers--: xref:proxy.adoc#Initializable-_disableInitializers--
  110. :xref-Initializable-_getInitializedVersion--: xref:proxy.adoc#Initializable-_getInitializedVersion--
  111. :xref-Initializable-_isInitializing--: xref:proxy.adoc#Initializable-_isInitializing--
  112. :xref-Initializable-Initialized-uint64-: xref:proxy.adoc#Initializable-Initialized-uint64-
  113. :xref-Initializable-InvalidInitialization--: xref:proxy.adoc#Initializable-InvalidInitialization--
  114. :xref-Initializable-NotInitializing--: xref:proxy.adoc#Initializable-NotInitializing--
  115. :ERC1967Proxy: pass:normal[xref:proxy.adoc#ERC1967Proxy[`ERC1967Proxy`]]
  116. :xref-UUPSUpgradeable-onlyProxy--: xref:proxy.adoc#UUPSUpgradeable-onlyProxy--
  117. :xref-UUPSUpgradeable-notDelegated--: xref:proxy.adoc#UUPSUpgradeable-notDelegated--
  118. :xref-UUPSUpgradeable-proxiableUUID--: xref:proxy.adoc#UUPSUpgradeable-proxiableUUID--
  119. :xref-UUPSUpgradeable-upgradeToAndCall-address-bytes-: xref:proxy.adoc#UUPSUpgradeable-upgradeToAndCall-address-bytes-
  120. :xref-UUPSUpgradeable-_checkProxy--: xref:proxy.adoc#UUPSUpgradeable-_checkProxy--
  121. :xref-UUPSUpgradeable-_checkNotDelegated--: xref:proxy.adoc#UUPSUpgradeable-_checkNotDelegated--
  122. :xref-UUPSUpgradeable-_authorizeUpgrade-address-: xref:proxy.adoc#UUPSUpgradeable-_authorizeUpgrade-address-
  123. :xref-UUPSUpgradeable-UPGRADE_INTERFACE_VERSION-string: xref:proxy.adoc#UUPSUpgradeable-UPGRADE_INTERFACE_VERSION-string
  124. :xref-UUPSUpgradeable-UUPSUnauthorizedCallContext--: xref:proxy.adoc#UUPSUpgradeable-UUPSUnauthorizedCallContext--
  125. :xref-UUPSUpgradeable-UUPSUnsupportedProxiableUUID-bytes32-: xref:proxy.adoc#UUPSUpgradeable-UUPSUnsupportedProxiableUUID-bytes32-
  126. :Ownable-onlyOwner: pass:normal[xref:access.adoc#Ownable-onlyOwner--[`Ownable.onlyOwner`]]
  127. = Proxies
  128. [.readme-notice]
  129. NOTE: This document is better viewed at https://docs.openzeppelin.com/contracts/api/proxy
  130. This is a low-level set of contracts implementing different proxy patterns with and without upgradeability. For an in-depth overview of this pattern check out the xref:upgrades-plugins::proxies.adoc[Proxy Upgrade Pattern] page.
  131. Most of the proxies below are built on an abstract base contract.
  132. - {Proxy}: Abstract contract implementing the core delegation functionality.
  133. In order to avoid clashes with the storage variables of the implementation contract behind a proxy, we use https://eips.ethereum.org/EIPS/eip-1967[EIP1967] storage slots.
  134. - {ERC1967Utils}: Internal functions to get and set the storage slots defined in EIP1967.
  135. - {ERC1967Proxy}: A proxy using EIP1967 storage slots. Not upgradeable by default.
  136. There are two alternative ways to add upgradeability to an ERC1967 proxy. Their differences are explained below in <<transparent-vs-uups>>.
  137. - {TransparentUpgradeableProxy}: A proxy with a built-in immutable admin and upgrade interface.
  138. - {UUPSUpgradeable}: An upgradeability mechanism to be included in the implementation contract.
  139. CAUTION: Using upgradeable proxies correctly and securely is a difficult task that requires deep knowledge of the proxy pattern, Solidity, and the EVM. Unless you want a lot of low level control, we recommend using the xref:upgrades-plugins::index.adoc[OpenZeppelin Upgrades Plugins] for Truffle and Hardhat.
  140. A different family of proxies are beacon proxies. This pattern, popularized by Dharma, allows multiple proxies to be upgraded to a different implementation in a single transaction.
  141. - {BeaconProxy}: A proxy that retrieves its implementation from a beacon contract.
  142. - {UpgradeableBeacon}: A beacon contract with a built in admin that can upgrade the {BeaconProxy} pointing to it.
  143. In this pattern, the proxy contract doesn't hold the implementation address in storage like an ERC1967 proxy. Instead, the address is stored in a separate beacon contract. The `upgrade` operations are sent to the beacon instead of to the proxy contract, and all proxies that follow that beacon are automatically upgraded.
  144. Outside the realm of upgradeability, proxies can also be useful to make cheap contract clones, such as those created by an on-chain factory contract that creates many instances of the same contract. These instances are designed to be both cheap to deploy, and cheap to call.
  145. - {Clones}: A library that can deploy cheap minimal non-upgradeable proxies.
  146. [[transparent-vs-uups]]
  147. == Transparent vs UUPS Proxies
  148. The original proxies included in OpenZeppelin followed the https://blog.openzeppelin.com/the-transparent-proxy-pattern/[Transparent Proxy Pattern]. While this pattern is still provided, our recommendation is now shifting towards UUPS proxies, which are both lightweight and versatile. The name UUPS comes from https://eips.ethereum.org/EIPS/eip-1822[EIP1822], which first documented the pattern.
  149. While both of these share the same interface for upgrades, in UUPS proxies the upgrade is handled by the implementation, and can eventually be removed. Transparent proxies, on the other hand, include the upgrade and admin logic in the proxy itself. This means {TransparentUpgradeableProxy} is more expensive to deploy than what is possible with UUPS proxies.
  150. UUPS proxies are implemented using an {ERC1967Proxy}. Note that this proxy is not by itself upgradeable. It is the role of the implementation to include, alongside the contract's logic, all the code necessary to update the implementation's address that is stored at a specific slot in the proxy's storage space. This is where the {UUPSUpgradeable} contract comes in. Inheriting from it (and overriding the {xref-UUPSUpgradeable-_authorizeUpgrade-address-}[`_authorizeUpgrade`] function with the relevant access control mechanism) will turn your contract into a UUPS compliant implementation.
  151. Note that since both proxies use the same storage slot for the implementation address, using a UUPS compliant implementation with a {TransparentUpgradeableProxy} might allow non-admins to perform upgrade operations.
  152. By default, the upgrade functionality included in {UUPSUpgradeable} contains a security mechanism that will prevent any upgrades to a non UUPS compliant implementation. This prevents upgrades to an implementation contract that wouldn't contain the necessary upgrade mechanism, as it would lock the upgradeability of the proxy forever. This security mechanism can be bypassed by either of:
  153. - Adding a flag mechanism in the implementation that will disable the upgrade function when triggered.
  154. - Upgrading to an implementation that features an upgrade mechanism without the additional security check, and then upgrading again to another implementation without the upgrade mechanism.
  155. The current implementation of this security mechanism uses https://eips.ethereum.org/EIPS/eip-1822[EIP1822] to detect the storage slot used by the implementation. A previous implementation, now deprecated, relied on a rollback check. It is possible to upgrade from a contract using the old mechanism to a new one. The inverse is however not possible, as old implementations (before version 4.5) did not include the `ERC1822` interface.
  156. == Core
  157. :_delegate: pass:normal[xref:#Proxy-_delegate-address-[`++_delegate++`]]
  158. :_implementation: pass:normal[xref:#Proxy-_implementation--[`++_implementation++`]]
  159. :_fallback: pass:normal[xref:#Proxy-_fallback--[`++_fallback++`]]
  160. :fallback: pass:normal[xref:#Proxy-fallback--[`++fallback++`]]
  161. [.contract]
  162. [[Proxy]]
  163. === `++Proxy++` link:https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.0.0-rc.2/contracts/proxy/Proxy.sol[{github-icon},role=heading-link]
  164. [.hljs-theme-light.nopadding]
  165. ```solidity
  166. import "@openzeppelin/contracts/proxy/Proxy.sol";
  167. ```
  168. This abstract contract provides a fallback function that delegates all calls to another contract using the EVM
  169. instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to
  170. be specified by overriding the virtual {_implementation} function.
  171. Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a
  172. different contract through the {_delegate} function.
  173. The success and return data of the delegated call will be returned back to the caller of the proxy.
  174. [.contract-index]
  175. .Functions
  176. --
  177. * {xref-Proxy-_delegate-address-}[`++_delegate(implementation)++`]
  178. * {xref-Proxy-_implementation--}[`++_implementation()++`]
  179. * {xref-Proxy-_fallback--}[`++_fallback()++`]
  180. * {xref-Proxy-fallback--}[`++fallback()++`]
  181. --
  182. [.contract-item]
  183. [[Proxy-_delegate-address-]]
  184. ==== `[.contract-item-name]#++_delegate++#++(address implementation)++` [.item-kind]#internal#
  185. Delegates the current call to `implementation`.
  186. This function does not return to its internal call site, it will return directly to the external caller.
  187. [.contract-item]
  188. [[Proxy-_implementation--]]
  189. ==== `[.contract-item-name]#++_implementation++#++() → address++` [.item-kind]#internal#
  190. This is a virtual function that should be overridden so it returns the address to which the fallback
  191. function and {_fallback} should delegate.
  192. [.contract-item]
  193. [[Proxy-_fallback--]]
  194. ==== `[.contract-item-name]#++_fallback++#++()++` [.item-kind]#internal#
  195. Delegates the current call to the address returned by `_implementation()`.
  196. This function does not return to its internal call site, it will return directly to the external caller.
  197. [.contract-item]
  198. [[Proxy-fallback--]]
  199. ==== `[.contract-item-name]#++fallback++#++()++` [.item-kind]#external#
  200. Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other
  201. function in the contract matches the call data.
  202. == ERC1967
  203. :constructor: pass:normal[xref:#ERC1967Proxy-constructor-address-bytes-[`++constructor++`]]
  204. :_implementation: pass:normal[xref:#ERC1967Proxy-_implementation--[`++_implementation++`]]
  205. [.contract]
  206. [[ERC1967Proxy]]
  207. === `++ERC1967Proxy++` link:https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.0.0-rc.2/contracts/proxy/ERC1967/ERC1967Proxy.sol[{github-icon},role=heading-link]
  208. [.hljs-theme-light.nopadding]
  209. ```solidity
  210. import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
  211. ```
  212. This contract implements an upgradeable proxy. It is upgradeable because calls are delegated to an
  213. implementation address that can be changed. This address is stored in storage in the location specified by
  214. https://eips.ethereum.org/EIPS/eip-1967[EIP1967], so that it doesn't conflict with the storage layout of the
  215. implementation behind the proxy.
  216. [.contract-index]
  217. .Functions
  218. --
  219. * {xref-ERC1967Proxy-constructor-address-bytes-}[`++constructor(implementation, _data)++`]
  220. * {xref-ERC1967Proxy-_implementation--}[`++_implementation()++`]
  221. [.contract-subindex-inherited]
  222. .Proxy
  223. * {xref-Proxy-_delegate-address-}[`++_delegate(implementation)++`]
  224. * {xref-Proxy-_fallback--}[`++_fallback()++`]
  225. * {xref-Proxy-fallback--}[`++fallback()++`]
  226. --
  227. [.contract-item]
  228. [[ERC1967Proxy-constructor-address-bytes-]]
  229. ==== `[.contract-item-name]#++constructor++#++(address implementation, bytes _data)++` [.item-kind]#public#
  230. Initializes the upgradeable proxy with an initial implementation specified by `implementation`.
  231. If `_data` is nonempty, it's used as data in a delegate call to `implementation`. This will typically be an
  232. encoded function call, and allows initializing the storage of the proxy like a Solidity constructor.
  233. Requirements:
  234. - If `data` is empty, `msg.value` must be zero.
  235. [.contract-item]
  236. [[ERC1967Proxy-_implementation--]]
  237. ==== `[.contract-item-name]#++_implementation++#++() → address++` [.item-kind]#internal#
  238. Returns the current implementation address.
  239. TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using
  240. the https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
  241. `0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc`
  242. :Upgraded: pass:normal[xref:#ERC1967Utils-Upgraded-address-[`++Upgraded++`]]
  243. :AdminChanged: pass:normal[xref:#ERC1967Utils-AdminChanged-address-address-[`++AdminChanged++`]]
  244. :BeaconUpgraded: pass:normal[xref:#ERC1967Utils-BeaconUpgraded-address-[`++BeaconUpgraded++`]]
  245. :IMPLEMENTATION_SLOT: pass:normal[xref:#ERC1967Utils-IMPLEMENTATION_SLOT-bytes32[`++IMPLEMENTATION_SLOT++`]]
  246. :ERC1967InvalidImplementation: pass:normal[xref:#ERC1967Utils-ERC1967InvalidImplementation-address-[`++ERC1967InvalidImplementation++`]]
  247. :ERC1967InvalidAdmin: pass:normal[xref:#ERC1967Utils-ERC1967InvalidAdmin-address-[`++ERC1967InvalidAdmin++`]]
  248. :ERC1967InvalidBeacon: pass:normal[xref:#ERC1967Utils-ERC1967InvalidBeacon-address-[`++ERC1967InvalidBeacon++`]]
  249. :ERC1967NonPayable: pass:normal[xref:#ERC1967Utils-ERC1967NonPayable--[`++ERC1967NonPayable++`]]
  250. :getImplementation: pass:normal[xref:#ERC1967Utils-getImplementation--[`++getImplementation++`]]
  251. :upgradeToAndCall: pass:normal[xref:#ERC1967Utils-upgradeToAndCall-address-bytes-[`++upgradeToAndCall++`]]
  252. :ADMIN_SLOT: pass:normal[xref:#ERC1967Utils-ADMIN_SLOT-bytes32[`++ADMIN_SLOT++`]]
  253. :getAdmin: pass:normal[xref:#ERC1967Utils-getAdmin--[`++getAdmin++`]]
  254. :changeAdmin: pass:normal[xref:#ERC1967Utils-changeAdmin-address-[`++changeAdmin++`]]
  255. :BEACON_SLOT: pass:normal[xref:#ERC1967Utils-BEACON_SLOT-bytes32[`++BEACON_SLOT++`]]
  256. :getBeacon: pass:normal[xref:#ERC1967Utils-getBeacon--[`++getBeacon++`]]
  257. :upgradeBeaconToAndCall: pass:normal[xref:#ERC1967Utils-upgradeBeaconToAndCall-address-bytes-[`++upgradeBeaconToAndCall++`]]
  258. [.contract]
  259. [[ERC1967Utils]]
  260. === `++ERC1967Utils++` link:https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.0.0-rc.2/contracts/proxy/ERC1967/ERC1967Utils.sol[{github-icon},role=heading-link]
  261. [.hljs-theme-light.nopadding]
  262. ```solidity
  263. import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol";
  264. ```
  265. This abstract contract provides getters and event emitting update functions for
  266. https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
  267. [.contract-index]
  268. .Functions
  269. --
  270. * {xref-ERC1967Utils-getImplementation--}[`++getImplementation()++`]
  271. * {xref-ERC1967Utils-upgradeToAndCall-address-bytes-}[`++upgradeToAndCall(newImplementation, data)++`]
  272. * {xref-ERC1967Utils-getAdmin--}[`++getAdmin()++`]
  273. * {xref-ERC1967Utils-changeAdmin-address-}[`++changeAdmin(newAdmin)++`]
  274. * {xref-ERC1967Utils-getBeacon--}[`++getBeacon()++`]
  275. * {xref-ERC1967Utils-upgradeBeaconToAndCall-address-bytes-}[`++upgradeBeaconToAndCall(newBeacon, data)++`]
  276. --
  277. [.contract-index]
  278. .Events
  279. --
  280. * {xref-ERC1967Utils-Upgraded-address-}[`++Upgraded(implementation)++`]
  281. * {xref-ERC1967Utils-AdminChanged-address-address-}[`++AdminChanged(previousAdmin, newAdmin)++`]
  282. * {xref-ERC1967Utils-BeaconUpgraded-address-}[`++BeaconUpgraded(beacon)++`]
  283. --
  284. [.contract-index]
  285. .Errors
  286. --
  287. * {xref-ERC1967Utils-ERC1967InvalidImplementation-address-}[`++ERC1967InvalidImplementation(implementation)++`]
  288. * {xref-ERC1967Utils-ERC1967InvalidAdmin-address-}[`++ERC1967InvalidAdmin(admin)++`]
  289. * {xref-ERC1967Utils-ERC1967InvalidBeacon-address-}[`++ERC1967InvalidBeacon(beacon)++`]
  290. * {xref-ERC1967Utils-ERC1967NonPayable--}[`++ERC1967NonPayable()++`]
  291. --
  292. [.contract-item]
  293. [[ERC1967Utils-getImplementation--]]
  294. ==== `[.contract-item-name]#++getImplementation++#++() → address++` [.item-kind]#internal#
  295. Returns the current implementation address.
  296. [.contract-item]
  297. [[ERC1967Utils-upgradeToAndCall-address-bytes-]]
  298. ==== `[.contract-item-name]#++upgradeToAndCall++#++(address newImplementation, bytes data)++` [.item-kind]#internal#
  299. Performs implementation upgrade with additional setup call if data is nonempty.
  300. This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
  301. to avoid stuck value in the contract.
  302. Emits an {IERC1967-Upgraded} event.
  303. [.contract-item]
  304. [[ERC1967Utils-getAdmin--]]
  305. ==== `[.contract-item-name]#++getAdmin++#++() → address++` [.item-kind]#internal#
  306. Returns the current admin.
  307. TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using
  308. the https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
  309. `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103`
  310. [.contract-item]
  311. [[ERC1967Utils-changeAdmin-address-]]
  312. ==== `[.contract-item-name]#++changeAdmin++#++(address newAdmin)++` [.item-kind]#internal#
  313. Changes the admin of the proxy.
  314. Emits an {IERC1967-AdminChanged} event.
  315. [.contract-item]
  316. [[ERC1967Utils-getBeacon--]]
  317. ==== `[.contract-item-name]#++getBeacon++#++() → address++` [.item-kind]#internal#
  318. Returns the current beacon.
  319. [.contract-item]
  320. [[ERC1967Utils-upgradeBeaconToAndCall-address-bytes-]]
  321. ==== `[.contract-item-name]#++upgradeBeaconToAndCall++#++(address newBeacon, bytes data)++` [.item-kind]#internal#
  322. Change the beacon and trigger a setup call if data is nonempty.
  323. This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
  324. to avoid stuck value in the contract.
  325. Emits an {IERC1967-BeaconUpgraded} event.
  326. CAUTION: Invoking this function has no effect on an instance of {BeaconProxy} since v5, since
  327. it uses an immutable beacon without looking at the value of the ERC-1967 beacon slot for
  328. efficiency.
  329. [.contract-item]
  330. [[ERC1967Utils-Upgraded-address-]]
  331. ==== `[.contract-item-name]#++Upgraded++#++(address indexed implementation)++` [.item-kind]#event#
  332. Emitted when the implementation is upgraded.
  333. [.contract-item]
  334. [[ERC1967Utils-AdminChanged-address-address-]]
  335. ==== `[.contract-item-name]#++AdminChanged++#++(address previousAdmin, address newAdmin)++` [.item-kind]#event#
  336. Emitted when the admin account has changed.
  337. [.contract-item]
  338. [[ERC1967Utils-BeaconUpgraded-address-]]
  339. ==== `[.contract-item-name]#++BeaconUpgraded++#++(address indexed beacon)++` [.item-kind]#event#
  340. Emitted when the beacon is changed.
  341. [.contract-item]
  342. [[ERC1967Utils-ERC1967InvalidImplementation-address-]]
  343. ==== `[.contract-item-name]#++ERC1967InvalidImplementation++#++(address implementation)++` [.item-kind]#error#
  344. The `implementation` of the proxy is invalid.
  345. [.contract-item]
  346. [[ERC1967Utils-ERC1967InvalidAdmin-address-]]
  347. ==== `[.contract-item-name]#++ERC1967InvalidAdmin++#++(address admin)++` [.item-kind]#error#
  348. The `admin` of the proxy is invalid.
  349. [.contract-item]
  350. [[ERC1967Utils-ERC1967InvalidBeacon-address-]]
  351. ==== `[.contract-item-name]#++ERC1967InvalidBeacon++#++(address beacon)++` [.item-kind]#error#
  352. The `beacon` of the proxy is invalid.
  353. [.contract-item]
  354. [[ERC1967Utils-ERC1967NonPayable--]]
  355. ==== `[.contract-item-name]#++ERC1967NonPayable++#++()++` [.item-kind]#error#
  356. An upgrade function sees `msg.value > 0` that may be lost.
  357. == Transparent Proxy
  358. :ProxyDeniedAdminAccess: pass:normal[xref:#TransparentUpgradeableProxy-ProxyDeniedAdminAccess--[`++ProxyDeniedAdminAccess++`]]
  359. :constructor: pass:normal[xref:#TransparentUpgradeableProxy-constructor-address-address-bytes-[`++constructor++`]]
  360. :_proxyAdmin: pass:normal[xref:#TransparentUpgradeableProxy-_proxyAdmin--[`++_proxyAdmin++`]]
  361. :_fallback: pass:normal[xref:#TransparentUpgradeableProxy-_fallback--[`++_fallback++`]]
  362. [.contract]
  363. [[TransparentUpgradeableProxy]]
  364. === `++TransparentUpgradeableProxy++` link:https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.0.0-rc.2/contracts/proxy/transparent/TransparentUpgradeableProxy.sol[{github-icon},role=heading-link]
  365. [.hljs-theme-light.nopadding]
  366. ```solidity
  367. import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
  368. ```
  369. This contract implements a proxy that is upgradeable through an associated {ProxyAdmin} instance.
  370. To avoid https://medium.com/nomic-labs-blog/malicious-backdoors-in-ethereum-proxies-62629adf3357[proxy selector
  371. clashing], which can potentially be used in an attack, this contract uses the
  372. https://blog.openzeppelin.com/the-transparent-proxy-pattern/[transparent proxy pattern]. This pattern implies two
  373. things that go hand in hand:
  374. 1. If any account other than the admin calls the proxy, the call will be forwarded to the implementation, even if
  375. that call matches the {ITransparentUpgradeableProxy-upgradeToAndCall} function exposed by the proxy itself.
  376. 2. If the admin calls the proxy, it can call the `upgradeToAndCall` function but any other call won't be forwarded to
  377. the implementation. If the admin tries to call a function on the implementation it will fail with an error indicating
  378. the proxy admin cannot fallback to the target implementation.
  379. These properties mean that the admin account can only be used for upgrading the proxy, so it's best if it's a
  380. dedicated account that is not used for anything else. This will avoid headaches due to sudden errors when trying to
  381. call a function from the proxy implementation. For this reason, the proxy deploys an instance of {ProxyAdmin} and
  382. allows upgrades only if they come through it. You should think of the `ProxyAdmin` instance as the administrative
  383. interface of the proxy, including the ability to change who can trigger upgrades by transferring ownership.
  384. NOTE: The real interface of this proxy is that defined in `ITransparentUpgradeableProxy`. This contract does not
  385. inherit from that interface, and instead `upgradeToAndCall` is implicitly implemented using a custom dispatch
  386. mechanism in `_fallback`. Consequently, the compiler will not produce an ABI for this contract. This is necessary to
  387. fully implement transparency without decoding reverts caused by selector clashes between the proxy and the
  388. implementation.
  389. NOTE: This proxy does not inherit from {Context} deliberately. The {ProxyAdmin} of this contract won't send a
  390. meta-transaction in any way, and any other meta-transaction setup should be made in the implementation contract.
  391. IMPORTANT: This contract avoids unnecessary storage reads by setting the admin only during construction as an
  392. immutable variable, preventing any changes thereafter. However, the admin slot defined in ERC-1967 can still be
  393. overwritten by the implementation logic pointed to by this proxy. In such cases, the contract may end up in an
  394. undesirable state where the admin slot is different from the actual admin.
  395. WARNING: It is not recommended to extend this contract to add additional external functions. If you do so, the
  396. compiler will not check that there are no selector conflicts, due to the note above. A selector clash between any new
  397. function and the functions declared in {ITransparentUpgradeableProxy} will be resolved in favor of the new one. This
  398. could render the `upgradeToAndCall` function inaccessible, preventing upgradeability and compromising transparency.
  399. [.contract-index]
  400. .Functions
  401. --
  402. * {xref-TransparentUpgradeableProxy-constructor-address-address-bytes-}[`++constructor(_logic, initialOwner, _data)++`]
  403. * {xref-TransparentUpgradeableProxy-_proxyAdmin--}[`++_proxyAdmin()++`]
  404. * {xref-TransparentUpgradeableProxy-_fallback--}[`++_fallback()++`]
  405. [.contract-subindex-inherited]
  406. .ERC1967Proxy
  407. * {xref-ERC1967Proxy-_implementation--}[`++_implementation()++`]
  408. [.contract-subindex-inherited]
  409. .Proxy
  410. * {xref-Proxy-_delegate-address-}[`++_delegate(implementation)++`]
  411. * {xref-Proxy-fallback--}[`++fallback()++`]
  412. --
  413. [.contract-index]
  414. .Errors
  415. --
  416. * {xref-TransparentUpgradeableProxy-ProxyDeniedAdminAccess--}[`++ProxyDeniedAdminAccess()++`]
  417. [.contract-subindex-inherited]
  418. .ERC1967Proxy
  419. [.contract-subindex-inherited]
  420. .Proxy
  421. --
  422. [.contract-item]
  423. [[TransparentUpgradeableProxy-constructor-address-address-bytes-]]
  424. ==== `[.contract-item-name]#++constructor++#++(address _logic, address initialOwner, bytes _data)++` [.item-kind]#public#
  425. Initializes an upgradeable proxy managed by an instance of a {ProxyAdmin} with an `initialOwner`,
  426. backed by the implementation at `_logic`, and optionally initialized with `_data` as explained in
  427. {ERC1967Proxy-constructor}.
  428. [.contract-item]
  429. [[TransparentUpgradeableProxy-_proxyAdmin--]]
  430. ==== `[.contract-item-name]#++_proxyAdmin++#++() → address++` [.item-kind]#internal#
  431. Returns the admin of this proxy.
  432. [.contract-item]
  433. [[TransparentUpgradeableProxy-_fallback--]]
  434. ==== `[.contract-item-name]#++_fallback++#++()++` [.item-kind]#internal#
  435. If caller is the admin process the call internally, otherwise transparently fallback to the proxy behavior.
  436. [.contract-item]
  437. [[TransparentUpgradeableProxy-ProxyDeniedAdminAccess--]]
  438. ==== `[.contract-item-name]#++ProxyDeniedAdminAccess++#++()++` [.item-kind]#error#
  439. The proxy caller is the current admin, and can't fallback to the proxy target.
  440. :UPGRADE_INTERFACE_VERSION: pass:normal[xref:#ProxyAdmin-UPGRADE_INTERFACE_VERSION-string[`++UPGRADE_INTERFACE_VERSION++`]]
  441. :constructor: pass:normal[xref:#ProxyAdmin-constructor-address-[`++constructor++`]]
  442. :upgradeAndCall: pass:normal[xref:#ProxyAdmin-upgradeAndCall-contract-ITransparentUpgradeableProxy-address-bytes-[`++upgradeAndCall++`]]
  443. [.contract]
  444. [[ProxyAdmin]]
  445. === `++ProxyAdmin++` link:https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.0.0-rc.2/contracts/proxy/transparent/ProxyAdmin.sol[{github-icon},role=heading-link]
  446. [.hljs-theme-light.nopadding]
  447. ```solidity
  448. import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
  449. ```
  450. This is an auxiliary contract meant to be assigned as the admin of a {TransparentUpgradeableProxy}. For an
  451. explanation of why you would want to use this see the documentation for {TransparentUpgradeableProxy}.
  452. [.contract-index]
  453. .Functions
  454. --
  455. * {xref-ProxyAdmin-constructor-address-}[`++constructor(initialOwner)++`]
  456. * {xref-ProxyAdmin-upgradeAndCall-contract-ITransparentUpgradeableProxy-address-bytes-}[`++upgradeAndCall(proxy, implementation, data)++`]
  457. * {xref-ProxyAdmin-UPGRADE_INTERFACE_VERSION-string}[`++UPGRADE_INTERFACE_VERSION()++`]
  458. [.contract-subindex-inherited]
  459. .Ownable
  460. * {xref-Ownable-owner--}[`++owner()++`]
  461. * {xref-Ownable-_checkOwner--}[`++_checkOwner()++`]
  462. * {xref-Ownable-renounceOwnership--}[`++renounceOwnership()++`]
  463. * {xref-Ownable-transferOwnership-address-}[`++transferOwnership(newOwner)++`]
  464. * {xref-Ownable-_transferOwnership-address-}[`++_transferOwnership(newOwner)++`]
  465. --
  466. [.contract-index]
  467. .Events
  468. --
  469. [.contract-subindex-inherited]
  470. .Ownable
  471. * {xref-Ownable-OwnershipTransferred-address-address-}[`++OwnershipTransferred(previousOwner, newOwner)++`]
  472. --
  473. [.contract-index]
  474. .Errors
  475. --
  476. [.contract-subindex-inherited]
  477. .Ownable
  478. * {xref-Ownable-OwnableUnauthorizedAccount-address-}[`++OwnableUnauthorizedAccount(account)++`]
  479. * {xref-Ownable-OwnableInvalidOwner-address-}[`++OwnableInvalidOwner(owner)++`]
  480. --
  481. [.contract-item]
  482. [[ProxyAdmin-constructor-address-]]
  483. ==== `[.contract-item-name]#++constructor++#++(address initialOwner)++` [.item-kind]#public#
  484. Sets the initial owner who can perform upgrades.
  485. [.contract-item]
  486. [[ProxyAdmin-upgradeAndCall-contract-ITransparentUpgradeableProxy-address-bytes-]]
  487. ==== `[.contract-item-name]#++upgradeAndCall++#++(contract ITransparentUpgradeableProxy proxy, address implementation, bytes data)++` [.item-kind]#public#
  488. Upgrades `proxy` to `implementation` and calls a function on the new implementation.
  489. See {TransparentUpgradeableProxy-_dispatchUpgradeToAndCall}.
  490. Requirements:
  491. - This contract must be the admin of `proxy`.
  492. - If `data` is empty, `msg.value` must be zero.
  493. [.contract-item]
  494. [[ProxyAdmin-UPGRADE_INTERFACE_VERSION-string]]
  495. ==== `[.contract-item-name]#++UPGRADE_INTERFACE_VERSION++#++() → string++` [.item-kind]#public#
  496. The version of the upgrade interface of the contract. If this getter is missing, both `upgrade(address)`
  497. and `upgradeAndCall(address,bytes)` are present, and `upgradeTo` must be used if no function should be called,
  498. while `upgradeAndCall` will invoke the `receive` function if the second argument is the empty byte string.
  499. If the getter returns `"5.0.0"`, only `upgradeAndCall(address,bytes)` is present, and the second argument must
  500. be the empty byte string if no function should be called, making it impossible to invoke the `receive` function
  501. during an upgrade.
  502. == Beacon
  503. :constructor: pass:normal[xref:#BeaconProxy-constructor-address-bytes-[`++constructor++`]]
  504. :_implementation: pass:normal[xref:#BeaconProxy-_implementation--[`++_implementation++`]]
  505. :_getBeacon: pass:normal[xref:#BeaconProxy-_getBeacon--[`++_getBeacon++`]]
  506. [.contract]
  507. [[BeaconProxy]]
  508. === `++BeaconProxy++` link:https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.0.0-rc.2/contracts/proxy/beacon/BeaconProxy.sol[{github-icon},role=heading-link]
  509. [.hljs-theme-light.nopadding]
  510. ```solidity
  511. import "@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol";
  512. ```
  513. This contract implements a proxy that gets the implementation address for each call from an {UpgradeableBeacon}.
  514. The beacon address can only be set once during construction, and cannot be changed afterwards. It is stored in an
  515. immutable variable to avoid unnecessary storage reads, and also in the beacon storage slot specified by
  516. https://eips.ethereum.org/EIPS/eip-1967[EIP1967] so that it can be accessed externally.
  517. CAUTION: Since the beacon address can never be changed, you must ensure that you either control the beacon, or trust
  518. the beacon to not upgrade the implementation maliciously.
  519. IMPORTANT: Do not use the implementation logic to modify the beacon storage slot. Doing so would leave the proxy in
  520. an inconsistent state where the beacon storage slot does not match the beacon address.
  521. [.contract-index]
  522. .Functions
  523. --
  524. * {xref-BeaconProxy-constructor-address-bytes-}[`++constructor(beacon, data)++`]
  525. * {xref-BeaconProxy-_implementation--}[`++_implementation()++`]
  526. * {xref-BeaconProxy-_getBeacon--}[`++_getBeacon()++`]
  527. [.contract-subindex-inherited]
  528. .Proxy
  529. * {xref-Proxy-_delegate-address-}[`++_delegate(implementation)++`]
  530. * {xref-Proxy-_fallback--}[`++_fallback()++`]
  531. * {xref-Proxy-fallback--}[`++fallback()++`]
  532. --
  533. [.contract-item]
  534. [[BeaconProxy-constructor-address-bytes-]]
  535. ==== `[.contract-item-name]#++constructor++#++(address beacon, bytes data)++` [.item-kind]#public#
  536. Initializes the proxy with `beacon`.
  537. If `data` is nonempty, it's used as data in a delegate call to the implementation returned by the beacon. This
  538. will typically be an encoded function call, and allows initializing the storage of the proxy like a Solidity
  539. constructor.
  540. Requirements:
  541. - `beacon` must be a contract with the interface {IBeacon}.
  542. - If `data` is empty, `msg.value` must be zero.
  543. [.contract-item]
  544. [[BeaconProxy-_implementation--]]
  545. ==== `[.contract-item-name]#++_implementation++#++() → address++` [.item-kind]#internal#
  546. Returns the current implementation address of the associated beacon.
  547. [.contract-item]
  548. [[BeaconProxy-_getBeacon--]]
  549. ==== `[.contract-item-name]#++_getBeacon++#++() → address++` [.item-kind]#internal#
  550. Returns the beacon.
  551. :implementation: pass:normal[xref:#IBeacon-implementation--[`++implementation++`]]
  552. [.contract]
  553. [[IBeacon]]
  554. === `++IBeacon++` link:https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.0.0-rc.2/contracts/proxy/beacon/IBeacon.sol[{github-icon},role=heading-link]
  555. [.hljs-theme-light.nopadding]
  556. ```solidity
  557. import "@openzeppelin/contracts/proxy/beacon/IBeacon.sol";
  558. ```
  559. This is the interface that {BeaconProxy} expects of its beacon.
  560. [.contract-index]
  561. .Functions
  562. --
  563. * {xref-IBeacon-implementation--}[`++implementation()++`]
  564. --
  565. [.contract-item]
  566. [[IBeacon-implementation--]]
  567. ==== `[.contract-item-name]#++implementation++#++() → address++` [.item-kind]#external#
  568. Must return an address that can be used as a delegate call target.
  569. {UpgradeableBeacon} will check that this address is a contract.
  570. :BeaconInvalidImplementation: pass:normal[xref:#UpgradeableBeacon-BeaconInvalidImplementation-address-[`++BeaconInvalidImplementation++`]]
  571. :Upgraded: pass:normal[xref:#UpgradeableBeacon-Upgraded-address-[`++Upgraded++`]]
  572. :constructor: pass:normal[xref:#UpgradeableBeacon-constructor-address-address-[`++constructor++`]]
  573. :implementation: pass:normal[xref:#UpgradeableBeacon-implementation--[`++implementation++`]]
  574. :upgradeTo: pass:normal[xref:#UpgradeableBeacon-upgradeTo-address-[`++upgradeTo++`]]
  575. [.contract]
  576. [[UpgradeableBeacon]]
  577. === `++UpgradeableBeacon++` link:https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.0.0-rc.2/contracts/proxy/beacon/UpgradeableBeacon.sol[{github-icon},role=heading-link]
  578. [.hljs-theme-light.nopadding]
  579. ```solidity
  580. import "@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol";
  581. ```
  582. This contract is used in conjunction with one or more instances of {BeaconProxy} to determine their
  583. implementation contract, which is where they will delegate all function calls.
  584. An owner is able to change the implementation the beacon points to, thus upgrading the proxies that use this beacon.
  585. [.contract-index]
  586. .Functions
  587. --
  588. * {xref-UpgradeableBeacon-constructor-address-address-}[`++constructor(implementation_, initialOwner)++`]
  589. * {xref-UpgradeableBeacon-implementation--}[`++implementation()++`]
  590. * {xref-UpgradeableBeacon-upgradeTo-address-}[`++upgradeTo(newImplementation)++`]
  591. [.contract-subindex-inherited]
  592. .Ownable
  593. * {xref-Ownable-owner--}[`++owner()++`]
  594. * {xref-Ownable-_checkOwner--}[`++_checkOwner()++`]
  595. * {xref-Ownable-renounceOwnership--}[`++renounceOwnership()++`]
  596. * {xref-Ownable-transferOwnership-address-}[`++transferOwnership(newOwner)++`]
  597. * {xref-Ownable-_transferOwnership-address-}[`++_transferOwnership(newOwner)++`]
  598. [.contract-subindex-inherited]
  599. .IBeacon
  600. --
  601. [.contract-index]
  602. .Events
  603. --
  604. * {xref-UpgradeableBeacon-Upgraded-address-}[`++Upgraded(implementation)++`]
  605. [.contract-subindex-inherited]
  606. .Ownable
  607. * {xref-Ownable-OwnershipTransferred-address-address-}[`++OwnershipTransferred(previousOwner, newOwner)++`]
  608. [.contract-subindex-inherited]
  609. .IBeacon
  610. --
  611. [.contract-index]
  612. .Errors
  613. --
  614. * {xref-UpgradeableBeacon-BeaconInvalidImplementation-address-}[`++BeaconInvalidImplementation(implementation)++`]
  615. [.contract-subindex-inherited]
  616. .Ownable
  617. * {xref-Ownable-OwnableUnauthorizedAccount-address-}[`++OwnableUnauthorizedAccount(account)++`]
  618. * {xref-Ownable-OwnableInvalidOwner-address-}[`++OwnableInvalidOwner(owner)++`]
  619. [.contract-subindex-inherited]
  620. .IBeacon
  621. --
  622. [.contract-item]
  623. [[UpgradeableBeacon-constructor-address-address-]]
  624. ==== `[.contract-item-name]#++constructor++#++(address implementation_, address initialOwner)++` [.item-kind]#public#
  625. Sets the address of the initial implementation, and the initial owner who can upgrade the beacon.
  626. [.contract-item]
  627. [[UpgradeableBeacon-implementation--]]
  628. ==== `[.contract-item-name]#++implementation++#++() → address++` [.item-kind]#public#
  629. Returns the current implementation address.
  630. [.contract-item]
  631. [[UpgradeableBeacon-upgradeTo-address-]]
  632. ==== `[.contract-item-name]#++upgradeTo++#++(address newImplementation)++` [.item-kind]#public#
  633. Upgrades the beacon to a new implementation.
  634. Emits an {Upgraded} event.
  635. Requirements:
  636. - msg.sender must be the owner of the contract.
  637. - `newImplementation` must be a contract.
  638. [.contract-item]
  639. [[UpgradeableBeacon-Upgraded-address-]]
  640. ==== `[.contract-item-name]#++Upgraded++#++(address indexed implementation)++` [.item-kind]#event#
  641. Emitted when the implementation returned by the beacon is changed.
  642. [.contract-item]
  643. [[UpgradeableBeacon-BeaconInvalidImplementation-address-]]
  644. ==== `[.contract-item-name]#++BeaconInvalidImplementation++#++(address implementation)++` [.item-kind]#error#
  645. The `implementation` of the beacon is invalid.
  646. == Minimal Clones
  647. :ERC1167FailedCreateClone: pass:normal[xref:#Clones-ERC1167FailedCreateClone--[`++ERC1167FailedCreateClone++`]]
  648. :clone: pass:normal[xref:#Clones-clone-address-[`++clone++`]]
  649. :cloneDeterministic: pass:normal[xref:#Clones-cloneDeterministic-address-bytes32-[`++cloneDeterministic++`]]
  650. :predictDeterministicAddress: pass:normal[xref:#Clones-predictDeterministicAddress-address-bytes32-address-[`++predictDeterministicAddress++`]]
  651. :predictDeterministicAddress: pass:normal[xref:#Clones-predictDeterministicAddress-address-bytes32-[`++predictDeterministicAddress++`]]
  652. [.contract]
  653. [[Clones]]
  654. === `++Clones++` link:https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.0.0-rc.2/contracts/proxy/Clones.sol[{github-icon},role=heading-link]
  655. [.hljs-theme-light.nopadding]
  656. ```solidity
  657. import "@openzeppelin/contracts/proxy/Clones.sol";
  658. ```
  659. https://eips.ethereum.org/EIPS/eip-1167[EIP 1167] is a standard for
  660. deploying minimal proxy contracts, also known as "clones".
  661. > To simply and cheaply clone contract functionality in an immutable way, this standard specifies
  662. > a minimal bytecode implementation that delegates all calls to a known, fixed address.
  663. The library includes functions to deploy a proxy using either `create` (traditional deployment) or `create2`
  664. (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the
  665. deterministic method.
  666. [.contract-index]
  667. .Functions
  668. --
  669. * {xref-Clones-clone-address-}[`++clone(implementation)++`]
  670. * {xref-Clones-cloneDeterministic-address-bytes32-}[`++cloneDeterministic(implementation, salt)++`]
  671. * {xref-Clones-predictDeterministicAddress-address-bytes32-address-}[`++predictDeterministicAddress(implementation, salt, deployer)++`]
  672. * {xref-Clones-predictDeterministicAddress-address-bytes32-}[`++predictDeterministicAddress(implementation, salt)++`]
  673. --
  674. [.contract-index]
  675. .Errors
  676. --
  677. * {xref-Clones-ERC1167FailedCreateClone--}[`++ERC1167FailedCreateClone()++`]
  678. --
  679. [.contract-item]
  680. [[Clones-clone-address-]]
  681. ==== `[.contract-item-name]#++clone++#++(address implementation) → address instance++` [.item-kind]#internal#
  682. Deploys and returns the address of a clone that mimics the behaviour of `implementation`.
  683. This function uses the create opcode, which should never revert.
  684. [.contract-item]
  685. [[Clones-cloneDeterministic-address-bytes32-]]
  686. ==== `[.contract-item-name]#++cloneDeterministic++#++(address implementation, bytes32 salt) → address instance++` [.item-kind]#internal#
  687. Deploys and returns the address of a clone that mimics the behaviour of `implementation`.
  688. This function uses the create2 opcode and a `salt` to deterministically deploy
  689. the clone. Using the same `implementation` and `salt` multiple time will revert, since
  690. the clones cannot be deployed twice at the same address.
  691. [.contract-item]
  692. [[Clones-predictDeterministicAddress-address-bytes32-address-]]
  693. ==== `[.contract-item-name]#++predictDeterministicAddress++#++(address implementation, bytes32 salt, address deployer) → address predicted++` [.item-kind]#internal#
  694. Computes the address of a clone deployed using {Clones-cloneDeterministic}.
  695. [.contract-item]
  696. [[Clones-predictDeterministicAddress-address-bytes32-]]
  697. ==== `[.contract-item-name]#++predictDeterministicAddress++#++(address implementation, bytes32 salt) → address predicted++` [.item-kind]#internal#
  698. Computes the address of a clone deployed using {Clones-cloneDeterministic}.
  699. [.contract-item]
  700. [[Clones-ERC1167FailedCreateClone--]]
  701. ==== `[.contract-item-name]#++ERC1167FailedCreateClone++#++()++` [.item-kind]#error#
  702. A clone instance deployment failed.
  703. == Utils
  704. :InitializableStorage: pass:normal[xref:#Initializable-InitializableStorage[`++InitializableStorage++`]]
  705. :InvalidInitialization: pass:normal[xref:#Initializable-InvalidInitialization--[`++InvalidInitialization++`]]
  706. :NotInitializing: pass:normal[xref:#Initializable-NotInitializing--[`++NotInitializing++`]]
  707. :Initialized: pass:normal[xref:#Initializable-Initialized-uint64-[`++Initialized++`]]
  708. :initializer: pass:normal[xref:#Initializable-initializer--[`++initializer++`]]
  709. :reinitializer: pass:normal[xref:#Initializable-reinitializer-uint64-[`++reinitializer++`]]
  710. :onlyInitializing: pass:normal[xref:#Initializable-onlyInitializing--[`++onlyInitializing++`]]
  711. :_checkInitializing: pass:normal[xref:#Initializable-_checkInitializing--[`++_checkInitializing++`]]
  712. :_disableInitializers: pass:normal[xref:#Initializable-_disableInitializers--[`++_disableInitializers++`]]
  713. :_getInitializedVersion: pass:normal[xref:#Initializable-_getInitializedVersion--[`++_getInitializedVersion++`]]
  714. :_isInitializing: pass:normal[xref:#Initializable-_isInitializing--[`++_isInitializing++`]]
  715. [.contract]
  716. [[Initializable]]
  717. === `++Initializable++` link:https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.0.0-rc.2/contracts/proxy/utils/Initializable.sol[{github-icon},role=heading-link]
  718. [.hljs-theme-light.nopadding]
  719. ```solidity
  720. import "@openzeppelin/contracts/proxy/utils/Initializable.sol";
  721. ```
  722. This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
  723. behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
  724. external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
  725. function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
  726. The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
  727. reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
  728. case an upgrade adds a module that needs to be initialized.
  729. For example:
  730. [.hljs-theme-light.nopadding]
  731. ```solidity
  732. contract MyToken is ERC20Upgradeable {
  733. function initialize() initializer public {
  734. __ERC20_init("MyToken", "MTK");
  735. }
  736. }
  737. contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
  738. function initializeV2() reinitializer(2) public {
  739. __ERC20Permit_init("MyToken");
  740. }
  741. }
  742. ```
  743. TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
  744. possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
  745. CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
  746. that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
  747. [CAUTION]
  748. ====
  749. Avoid leaving a contract uninitialized.
  750. An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
  751. contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
  752. the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
  753. [.hljs-theme-light.nopadding]
  754. ```
  755. /// @custom:oz-upgrades-unsafe-allow constructor
  756. constructor() {
  757. _disableInitializers();
  758. }
  759. ```
  760. ====
  761. [.contract-index]
  762. .Modifiers
  763. --
  764. * {xref-Initializable-initializer--}[`++initializer()++`]
  765. * {xref-Initializable-reinitializer-uint64-}[`++reinitializer(version)++`]
  766. * {xref-Initializable-onlyInitializing--}[`++onlyInitializing()++`]
  767. --
  768. [.contract-index]
  769. .Functions
  770. --
  771. * {xref-Initializable-_checkInitializing--}[`++_checkInitializing()++`]
  772. * {xref-Initializable-_disableInitializers--}[`++_disableInitializers()++`]
  773. * {xref-Initializable-_getInitializedVersion--}[`++_getInitializedVersion()++`]
  774. * {xref-Initializable-_isInitializing--}[`++_isInitializing()++`]
  775. --
  776. [.contract-index]
  777. .Events
  778. --
  779. * {xref-Initializable-Initialized-uint64-}[`++Initialized(version)++`]
  780. --
  781. [.contract-index]
  782. .Errors
  783. --
  784. * {xref-Initializable-InvalidInitialization--}[`++InvalidInitialization()++`]
  785. * {xref-Initializable-NotInitializing--}[`++NotInitializing()++`]
  786. --
  787. [.contract-item]
  788. [[Initializable-initializer--]]
  789. ==== `[.contract-item-name]#++initializer++#++()++` [.item-kind]#modifier#
  790. A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
  791. `onlyInitializing` functions can be used to initialize parent contracts.
  792. Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any
  793. number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
  794. production.
  795. Emits an {Initialized} event.
  796. [.contract-item]
  797. [[Initializable-reinitializer-uint64-]]
  798. ==== `[.contract-item-name]#++reinitializer++#++(uint64 version)++` [.item-kind]#modifier#
  799. A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
  800. contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
  801. used to initialize parent contracts.
  802. A reinitializer may be used after the original initialization step. This is essential to configure modules that
  803. are added through upgrades and that require initialization.
  804. When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
  805. cannot be nested. If one is invoked in the context of another, execution will revert.
  806. Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
  807. a contract, executing them in the right order is up to the developer or operator.
  808. WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization.
  809. Emits an {Initialized} event.
  810. [.contract-item]
  811. [[Initializable-onlyInitializing--]]
  812. ==== `[.contract-item-name]#++onlyInitializing++#++()++` [.item-kind]#modifier#
  813. Modifier to protect an initialization function so that it can only be invoked by functions with the
  814. {initializer} and {reinitializer} modifiers, directly or indirectly.
  815. [.contract-item]
  816. [[Initializable-_checkInitializing--]]
  817. ==== `[.contract-item-name]#++_checkInitializing++#++()++` [.item-kind]#internal#
  818. Reverts if the contract is not in an initializing state. See {onlyInitializing}.
  819. [.contract-item]
  820. [[Initializable-_disableInitializers--]]
  821. ==== `[.contract-item-name]#++_disableInitializers++#++()++` [.item-kind]#internal#
  822. Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
  823. Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
  824. to any version. It is recommended to use this to lock implementation contracts that are designed to be called
  825. through proxies.
  826. Emits an {Initialized} event the first time it is successfully executed.
  827. [.contract-item]
  828. [[Initializable-_getInitializedVersion--]]
  829. ==== `[.contract-item-name]#++_getInitializedVersion++#++() → uint64++` [.item-kind]#internal#
  830. Returns the highest version that has been initialized. See {reinitializer}.
  831. [.contract-item]
  832. [[Initializable-_isInitializing--]]
  833. ==== `[.contract-item-name]#++_isInitializing++#++() → bool++` [.item-kind]#internal#
  834. Returns `true` if the contract is currently initializing. See {onlyInitializing}.
  835. [.contract-item]
  836. [[Initializable-Initialized-uint64-]]
  837. ==== `[.contract-item-name]#++Initialized++#++(uint64 version)++` [.item-kind]#event#
  838. Triggered when the contract has been initialized or reinitialized.
  839. [.contract-item]
  840. [[Initializable-InvalidInitialization--]]
  841. ==== `[.contract-item-name]#++InvalidInitialization++#++()++` [.item-kind]#error#
  842. The contract is already initialized.
  843. [.contract-item]
  844. [[Initializable-NotInitializing--]]
  845. ==== `[.contract-item-name]#++NotInitializing++#++()++` [.item-kind]#error#
  846. The contract is not initializing.
  847. :UPGRADE_INTERFACE_VERSION: pass:normal[xref:#UUPSUpgradeable-UPGRADE_INTERFACE_VERSION-string[`++UPGRADE_INTERFACE_VERSION++`]]
  848. :UUPSUnauthorizedCallContext: pass:normal[xref:#UUPSUpgradeable-UUPSUnauthorizedCallContext--[`++UUPSUnauthorizedCallContext++`]]
  849. :UUPSUnsupportedProxiableUUID: pass:normal[xref:#UUPSUpgradeable-UUPSUnsupportedProxiableUUID-bytes32-[`++UUPSUnsupportedProxiableUUID++`]]
  850. :onlyProxy: pass:normal[xref:#UUPSUpgradeable-onlyProxy--[`++onlyProxy++`]]
  851. :notDelegated: pass:normal[xref:#UUPSUpgradeable-notDelegated--[`++notDelegated++`]]
  852. :proxiableUUID: pass:normal[xref:#UUPSUpgradeable-proxiableUUID--[`++proxiableUUID++`]]
  853. :upgradeToAndCall: pass:normal[xref:#UUPSUpgradeable-upgradeToAndCall-address-bytes-[`++upgradeToAndCall++`]]
  854. :_checkProxy: pass:normal[xref:#UUPSUpgradeable-_checkProxy--[`++_checkProxy++`]]
  855. :_checkNotDelegated: pass:normal[xref:#UUPSUpgradeable-_checkNotDelegated--[`++_checkNotDelegated++`]]
  856. :_authorizeUpgrade: pass:normal[xref:#UUPSUpgradeable-_authorizeUpgrade-address-[`++_authorizeUpgrade++`]]
  857. [.contract]
  858. [[UUPSUpgradeable]]
  859. === `++UUPSUpgradeable++` link:https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.0.0-rc.2/contracts/proxy/utils/UUPSUpgradeable.sol[{github-icon},role=heading-link]
  860. [.hljs-theme-light.nopadding]
  861. ```solidity
  862. import "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";
  863. ```
  864. An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
  865. {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
  866. A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
  867. reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
  868. `UUPSUpgradeable` with a custom implementation of upgrades.
  869. The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
  870. [.contract-index]
  871. .Modifiers
  872. --
  873. * {xref-UUPSUpgradeable-onlyProxy--}[`++onlyProxy()++`]
  874. * {xref-UUPSUpgradeable-notDelegated--}[`++notDelegated()++`]
  875. --
  876. [.contract-index]
  877. .Functions
  878. --
  879. * {xref-UUPSUpgradeable-proxiableUUID--}[`++proxiableUUID()++`]
  880. * {xref-UUPSUpgradeable-upgradeToAndCall-address-bytes-}[`++upgradeToAndCall(newImplementation, data)++`]
  881. * {xref-UUPSUpgradeable-_checkProxy--}[`++_checkProxy()++`]
  882. * {xref-UUPSUpgradeable-_checkNotDelegated--}[`++_checkNotDelegated()++`]
  883. * {xref-UUPSUpgradeable-_authorizeUpgrade-address-}[`++_authorizeUpgrade(newImplementation)++`]
  884. * {xref-UUPSUpgradeable-UPGRADE_INTERFACE_VERSION-string}[`++UPGRADE_INTERFACE_VERSION()++`]
  885. [.contract-subindex-inherited]
  886. .IERC1822Proxiable
  887. --
  888. [.contract-index]
  889. .Errors
  890. --
  891. * {xref-UUPSUpgradeable-UUPSUnauthorizedCallContext--}[`++UUPSUnauthorizedCallContext()++`]
  892. * {xref-UUPSUpgradeable-UUPSUnsupportedProxiableUUID-bytes32-}[`++UUPSUnsupportedProxiableUUID(slot)++`]
  893. [.contract-subindex-inherited]
  894. .IERC1822Proxiable
  895. --
  896. [.contract-item]
  897. [[UUPSUpgradeable-onlyProxy--]]
  898. ==== `[.contract-item-name]#++onlyProxy++#++()++` [.item-kind]#modifier#
  899. Check that the execution is being performed through a delegatecall call and that the execution context is
  900. a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case
  901. for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
  902. function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
  903. fail.
  904. [.contract-item]
  905. [[UUPSUpgradeable-notDelegated--]]
  906. ==== `[.contract-item-name]#++notDelegated++#++()++` [.item-kind]#modifier#
  907. Check that the execution is not being performed through a delegate call. This allows a function to be
  908. callable on the implementing contract but not through proxies.
  909. [.contract-item]
  910. [[UUPSUpgradeable-proxiableUUID--]]
  911. ==== `[.contract-item-name]#++proxiableUUID++#++() → bytes32++` [.item-kind]#external#
  912. Implementation of the ERC1822 {proxiableUUID} function. This returns the storage slot used by the
  913. implementation. It is used to validate the implementation's compatibility when performing an upgrade.
  914. IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
  915. bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
  916. function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
  917. [.contract-item]
  918. [[UUPSUpgradeable-upgradeToAndCall-address-bytes-]]
  919. ==== `[.contract-item-name]#++upgradeToAndCall++#++(address newImplementation, bytes data)++` [.item-kind]#public#
  920. Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
  921. encoded in `data`.
  922. Calls {_authorizeUpgrade}.
  923. Emits an {Upgraded} event.
  924. [.contract-item]
  925. [[UUPSUpgradeable-_checkProxy--]]
  926. ==== `[.contract-item-name]#++_checkProxy++#++()++` [.item-kind]#internal#
  927. Reverts if the execution is not performed via delegatecall or the execution
  928. context is not of a proxy with an ERC1967-compliant implementation pointing to self.
  929. See {_onlyProxy}.
  930. [.contract-item]
  931. [[UUPSUpgradeable-_checkNotDelegated--]]
  932. ==== `[.contract-item-name]#++_checkNotDelegated++#++()++` [.item-kind]#internal#
  933. Reverts if the execution is performed via delegatecall.
  934. See {notDelegated}.
  935. [.contract-item]
  936. [[UUPSUpgradeable-_authorizeUpgrade-address-]]
  937. ==== `[.contract-item-name]#++_authorizeUpgrade++#++(address newImplementation)++` [.item-kind]#internal#
  938. Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
  939. {upgradeToAndCall}.
  940. Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
  941. ```solidity
  942. function _authorizeUpgrade(address) internal onlyOwner {}
  943. ```
  944. [.contract-item]
  945. [[UUPSUpgradeable-UPGRADE_INTERFACE_VERSION-string]]
  946. ==== `[.contract-item-name]#++UPGRADE_INTERFACE_VERSION++#++() → string++` [.item-kind]#public#
  947. The version of the upgrade interface of the contract. If this getter is missing, both `upgradeTo(address)`
  948. and `upgradeToAndCall(address,bytes)` are present, and `upgradeTo` must be used if no function should be called,
  949. while `upgradeToAndCall` will invoke the `receive` function if the second argument is the empty byte string.
  950. If the getter returns `"5.0.0"`, only `upgradeToAndCall(address,bytes)` is present, and the second argument must
  951. be the empty byte string if no function should be called, making it impossible to invoke the `receive` function
  952. during an upgrade.
  953. [.contract-item]
  954. [[UUPSUpgradeable-UUPSUnauthorizedCallContext--]]
  955. ==== `[.contract-item-name]#++UUPSUnauthorizedCallContext++#++()++` [.item-kind]#error#
  956. The call is from an unauthorized context.
  957. [.contract-item]
  958. [[UUPSUpgradeable-UUPSUnsupportedProxiableUUID-bytes32-]]
  959. ==== `[.contract-item-name]#++UUPSUnsupportedProxiableUUID++#++(bytes32 slot)++` [.item-kind]#error#
  960. The storage `slot` is unsupported as a UUID.