finance.adoc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. :github-icon: pass:[<svg class="icon"><use href="#github-icon"/></svg>]
  2. :VestingWallet: pass:normal[xref:finance.adoc#VestingWallet[`VestingWallet`]]
  3. :Ownable: pass:normal[xref:access.adoc#Ownable[`Ownable`]]
  4. :xref-VestingWallet-constructor-address-uint64-uint64-: xref:finance.adoc#VestingWallet-constructor-address-uint64-uint64-
  5. :xref-VestingWallet-receive--: xref:finance.adoc#VestingWallet-receive--
  6. :xref-VestingWallet-start--: xref:finance.adoc#VestingWallet-start--
  7. :xref-VestingWallet-duration--: xref:finance.adoc#VestingWallet-duration--
  8. :xref-VestingWallet-end--: xref:finance.adoc#VestingWallet-end--
  9. :xref-VestingWallet-released--: xref:finance.adoc#VestingWallet-released--
  10. :xref-VestingWallet-released-address-: xref:finance.adoc#VestingWallet-released-address-
  11. :xref-VestingWallet-releasable--: xref:finance.adoc#VestingWallet-releasable--
  12. :xref-VestingWallet-releasable-address-: xref:finance.adoc#VestingWallet-releasable-address-
  13. :xref-VestingWallet-release--: xref:finance.adoc#VestingWallet-release--
  14. :xref-VestingWallet-release-address-: xref:finance.adoc#VestingWallet-release-address-
  15. :xref-VestingWallet-vestedAmount-uint64-: xref:finance.adoc#VestingWallet-vestedAmount-uint64-
  16. :xref-VestingWallet-vestedAmount-address-uint64-: xref:finance.adoc#VestingWallet-vestedAmount-address-uint64-
  17. :xref-VestingWallet-_vestingSchedule-uint256-uint64-: xref:finance.adoc#VestingWallet-_vestingSchedule-uint256-uint64-
  18. :xref-Ownable-owner--: xref:access.adoc#Ownable-owner--
  19. :xref-Ownable-_checkOwner--: xref:access.adoc#Ownable-_checkOwner--
  20. :xref-Ownable-renounceOwnership--: xref:access.adoc#Ownable-renounceOwnership--
  21. :xref-Ownable-transferOwnership-address-: xref:access.adoc#Ownable-transferOwnership-address-
  22. :xref-Ownable-_transferOwnership-address-: xref:access.adoc#Ownable-_transferOwnership-address-
  23. :xref-VestingWallet-EtherReleased-uint256-: xref:finance.adoc#VestingWallet-EtherReleased-uint256-
  24. :xref-VestingWallet-ERC20Released-address-uint256-: xref:finance.adoc#VestingWallet-ERC20Released-address-uint256-
  25. :xref-Ownable-OwnershipTransferred-address-address-: xref:access.adoc#Ownable-OwnershipTransferred-address-address-
  26. :xref-Ownable-OwnableUnauthorizedAccount-address-: xref:access.adoc#Ownable-OwnableUnauthorizedAccount-address-
  27. :xref-Ownable-OwnableInvalidOwner-address-: xref:access.adoc#Ownable-OwnableInvalidOwner-address-
  28. :IERC20: pass:normal[xref:token/ERC20.adoc#IERC20[`IERC20`]]
  29. = Finance
  30. [.readme-notice]
  31. NOTE: This document is better viewed at https://docs.openzeppelin.com/contracts/api/finance
  32. This directory includes primitives for financial systems:
  33. - {VestingWallet} handles the vesting of Ether and ERC-20 tokens for a given beneficiary. Custody of multiple tokens can
  34. be given to this contract, which will release the token to the beneficiary following a given, customizable, vesting
  35. schedule.
  36. == Contracts
  37. :EtherReleased: pass:normal[xref:#VestingWallet-EtherReleased-uint256-[`++EtherReleased++`]]
  38. :ERC20Released: pass:normal[xref:#VestingWallet-ERC20Released-address-uint256-[`++ERC20Released++`]]
  39. :constructor: pass:normal[xref:#VestingWallet-constructor-address-uint64-uint64-[`++constructor++`]]
  40. :receive: pass:normal[xref:#VestingWallet-receive--[`++receive++`]]
  41. :start: pass:normal[xref:#VestingWallet-start--[`++start++`]]
  42. :duration: pass:normal[xref:#VestingWallet-duration--[`++duration++`]]
  43. :end: pass:normal[xref:#VestingWallet-end--[`++end++`]]
  44. :released: pass:normal[xref:#VestingWallet-released--[`++released++`]]
  45. :released: pass:normal[xref:#VestingWallet-released-address-[`++released++`]]
  46. :releasable: pass:normal[xref:#VestingWallet-releasable--[`++releasable++`]]
  47. :releasable: pass:normal[xref:#VestingWallet-releasable-address-[`++releasable++`]]
  48. :release: pass:normal[xref:#VestingWallet-release--[`++release++`]]
  49. :release: pass:normal[xref:#VestingWallet-release-address-[`++release++`]]
  50. :vestedAmount: pass:normal[xref:#VestingWallet-vestedAmount-uint64-[`++vestedAmount++`]]
  51. :vestedAmount: pass:normal[xref:#VestingWallet-vestedAmount-address-uint64-[`++vestedAmount++`]]
  52. :_vestingSchedule: pass:normal[xref:#VestingWallet-_vestingSchedule-uint256-uint64-[`++_vestingSchedule++`]]
  53. [.contract]
  54. [[VestingWallet]]
  55. === `++VestingWallet++` link:https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.2.0/contracts/finance/VestingWallet.sol[{github-icon},role=heading-link]
  56. [.hljs-theme-light.nopadding]
  57. ```solidity
  58. import "@openzeppelin/contracts/finance/VestingWallet.sol";
  59. ```
  60. A vesting wallet is an ownable contract that can receive native currency and ERC-20 tokens, and release these
  61. assets to the wallet owner, also referred to as "beneficiary", according to a vesting schedule.
  62. Any assets transferred to this contract will follow the vesting schedule as if they were locked from the beginning.
  63. Consequently, if the vesting has already started, any amount of tokens sent to this contract will (at least partly)
  64. be immediately releasable.
  65. By setting the duration to 0, one can configure this contract to behave like an asset timelock that hold tokens for
  66. a beneficiary until a specified time.
  67. NOTE: Since the wallet is {Ownable}, and ownership can be transferred, it is possible to sell unvested tokens.
  68. Preventing this in a smart contract is difficult, considering that: 1) a beneficiary address could be a
  69. counterfactually deployed contract, 2) there is likely to be a migration path for EOAs to become contracts in the
  70. near future.
  71. NOTE: When using this contract with any token whose balance is adjusted automatically (i.e. a rebase token), make
  72. sure to account the supply/balance adjustment in the vesting schedule to ensure the vested amount is as intended.
  73. NOTE: Chains with support for native ERC20s may allow the vesting wallet to withdraw the underlying asset as both an
  74. ERC20 and as native currency. For example, if chain C supports token A and the wallet gets deposited 100 A, then
  75. at 50% of the vesting period, the beneficiary can withdraw 50 A as ERC20 and 25 A as native currency (totaling 75 A).
  76. Consider disabling one of the withdrawal methods.
  77. [.contract-index]
  78. .Functions
  79. --
  80. * {xref-VestingWallet-constructor-address-uint64-uint64-}[`++constructor(beneficiary, startTimestamp, durationSeconds)++`]
  81. * {xref-VestingWallet-receive--}[`++receive()++`]
  82. * {xref-VestingWallet-start--}[`++start()++`]
  83. * {xref-VestingWallet-duration--}[`++duration()++`]
  84. * {xref-VestingWallet-end--}[`++end()++`]
  85. * {xref-VestingWallet-released--}[`++released()++`]
  86. * {xref-VestingWallet-released-address-}[`++released(token)++`]
  87. * {xref-VestingWallet-releasable--}[`++releasable()++`]
  88. * {xref-VestingWallet-releasable-address-}[`++releasable(token)++`]
  89. * {xref-VestingWallet-release--}[`++release()++`]
  90. * {xref-VestingWallet-release-address-}[`++release(token)++`]
  91. * {xref-VestingWallet-vestedAmount-uint64-}[`++vestedAmount(timestamp)++`]
  92. * {xref-VestingWallet-vestedAmount-address-uint64-}[`++vestedAmount(token, timestamp)++`]
  93. * {xref-VestingWallet-_vestingSchedule-uint256-uint64-}[`++_vestingSchedule(totalAllocation, timestamp)++`]
  94. [.contract-subindex-inherited]
  95. .Ownable
  96. * {xref-Ownable-owner--}[`++owner()++`]
  97. * {xref-Ownable-_checkOwner--}[`++_checkOwner()++`]
  98. * {xref-Ownable-renounceOwnership--}[`++renounceOwnership()++`]
  99. * {xref-Ownable-transferOwnership-address-}[`++transferOwnership(newOwner)++`]
  100. * {xref-Ownable-_transferOwnership-address-}[`++_transferOwnership(newOwner)++`]
  101. --
  102. [.contract-index]
  103. .Events
  104. --
  105. * {xref-VestingWallet-EtherReleased-uint256-}[`++EtherReleased(amount)++`]
  106. * {xref-VestingWallet-ERC20Released-address-uint256-}[`++ERC20Released(token, amount)++`]
  107. [.contract-subindex-inherited]
  108. .Ownable
  109. * {xref-Ownable-OwnershipTransferred-address-address-}[`++OwnershipTransferred(previousOwner, newOwner)++`]
  110. --
  111. [.contract-index]
  112. .Errors
  113. --
  114. [.contract-subindex-inherited]
  115. .Ownable
  116. * {xref-Ownable-OwnableUnauthorizedAccount-address-}[`++OwnableUnauthorizedAccount(account)++`]
  117. * {xref-Ownable-OwnableInvalidOwner-address-}[`++OwnableInvalidOwner(owner)++`]
  118. --
  119. [.contract-item]
  120. [[VestingWallet-constructor-address-uint64-uint64-]]
  121. ==== `[.contract-item-name]#++constructor++#++(address beneficiary, uint64 startTimestamp, uint64 durationSeconds)++` [.item-kind]#public#
  122. Sets the beneficiary (owner), the start timestamp and the vesting duration (in seconds) of the vesting
  123. wallet.
  124. [.contract-item]
  125. [[VestingWallet-receive--]]
  126. ==== `[.contract-item-name]#++receive++#++()++` [.item-kind]#external#
  127. The contract should be able to receive Eth.
  128. [.contract-item]
  129. [[VestingWallet-start--]]
  130. ==== `[.contract-item-name]#++start++#++() → uint256++` [.item-kind]#public#
  131. Getter for the start timestamp.
  132. [.contract-item]
  133. [[VestingWallet-duration--]]
  134. ==== `[.contract-item-name]#++duration++#++() → uint256++` [.item-kind]#public#
  135. Getter for the vesting duration.
  136. [.contract-item]
  137. [[VestingWallet-end--]]
  138. ==== `[.contract-item-name]#++end++#++() → uint256++` [.item-kind]#public#
  139. Getter for the end timestamp.
  140. [.contract-item]
  141. [[VestingWallet-released--]]
  142. ==== `[.contract-item-name]#++released++#++() → uint256++` [.item-kind]#public#
  143. Amount of eth already released
  144. [.contract-item]
  145. [[VestingWallet-released-address-]]
  146. ==== `[.contract-item-name]#++released++#++(address token) → uint256++` [.item-kind]#public#
  147. Amount of token already released
  148. [.contract-item]
  149. [[VestingWallet-releasable--]]
  150. ==== `[.contract-item-name]#++releasable++#++() → uint256++` [.item-kind]#public#
  151. Getter for the amount of releasable eth.
  152. [.contract-item]
  153. [[VestingWallet-releasable-address-]]
  154. ==== `[.contract-item-name]#++releasable++#++(address token) → uint256++` [.item-kind]#public#
  155. Getter for the amount of releasable `token` tokens. `token` should be the address of an
  156. {IERC20} contract.
  157. [.contract-item]
  158. [[VestingWallet-release--]]
  159. ==== `[.contract-item-name]#++release++#++()++` [.item-kind]#public#
  160. Release the native token (ether) that have already vested.
  161. Emits a {EtherReleased} event.
  162. [.contract-item]
  163. [[VestingWallet-release-address-]]
  164. ==== `[.contract-item-name]#++release++#++(address token)++` [.item-kind]#public#
  165. Release the tokens that have already vested.
  166. Emits a {ERC20Released} event.
  167. [.contract-item]
  168. [[VestingWallet-vestedAmount-uint64-]]
  169. ==== `[.contract-item-name]#++vestedAmount++#++(uint64 timestamp) → uint256++` [.item-kind]#public#
  170. Calculates the amount of ether that has already vested. Default implementation is a linear vesting curve.
  171. [.contract-item]
  172. [[VestingWallet-vestedAmount-address-uint64-]]
  173. ==== `[.contract-item-name]#++vestedAmount++#++(address token, uint64 timestamp) → uint256++` [.item-kind]#public#
  174. Calculates the amount of tokens that has already vested. Default implementation is a linear vesting curve.
  175. [.contract-item]
  176. [[VestingWallet-_vestingSchedule-uint256-uint64-]]
  177. ==== `[.contract-item-name]#++_vestingSchedule++#++(uint256 totalAllocation, uint64 timestamp) → uint256++` [.item-kind]#internal#
  178. Virtual implementation of the vesting formula. This returns the amount vested, as a function of time, for
  179. an asset given its total historical allocation.
  180. [.contract-item]
  181. [[VestingWallet-EtherReleased-uint256-]]
  182. ==== `[.contract-item-name]#++EtherReleased++#++(uint256 amount)++` [.item-kind]#event#
  183. [.contract-item]
  184. [[VestingWallet-ERC20Released-address-uint256-]]
  185. ==== `[.contract-item-name]#++ERC20Released++#++(address indexed token, uint256 amount)++` [.item-kind]#event#