finance.adoc 11 KB

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