Finance
Smart contract finance utilities and implementations
Outdated Version
This directory includes primitives for financial systems:
PaymentSplitter
allows to split Ether and ERC20 payments among a group of accounts. The sender does not need to be aware that the assets will be split in this way, since it is handled transparently by the contract. The split can be in equal parts or in any other arbitrary proportion.VestingWallet
handles the vesting of Ether and ERC20 tokens for a given beneficiary. Custody of multiple tokens can be given to this contract, which will release the token to the beneficiary following a given, customizable, vesting schedule.
Contracts
import "@openzeppelin/contracts/finance/PaymentSplitter.sol";
This contract allows to split Ether payments among a group of accounts. The sender does not need to be aware that the Ether will be split in this way, since it is handled transparently by the contract.
The split can be in equal parts or in any other arbitrary proportion. The way this is specified is by assigning each account to a number of shares. Of all the Ether that this contract receives, each account will then be able to claim an amount proportional to the percentage of total shares they were assigned. The distribution of shares is set at the time of contract deployment and can't be updated thereafter.
PaymentSplitter
follows a pull payment model. This means that payments are not automatically forwarded to the
accounts but kept in this contract, and the actual transfer is triggered as a separate step by calling the PaymentSplitter.release
function.
NOTE: This contract assumes that ERC20 tokens will behave similarly to native tokens (Ether). Rebasing tokens, and tokens that apply fees during transfers, are likely to not be supported as expected. If in doubt, we encourage you to run tests before sending real value to this contract.
Functions
Events
constructor(address[] payees, uint256[] shares_)
public
#Creates an instance of PaymentSplitter
where each account in payees
is assigned the number of shares at
the matching position in the shares
array.
All addresses in payees
must be non-zero. Both arrays must have the same non-zero length, and there must be no
duplicates in payees
.
receive()
external
#The Ether received will be logged with PaymentSplitter.PaymentReceived
events. Note that these events are not fully
reliable: it's possible for a contract to receive Ether without triggering this function. This only affects the
reliability of the events, and not the actual splitting of Ether.
To learn more about this see the Solidity documentation for fallback functions.
totalShares() → uint256
public
#Getter for the total shares held by payees.
totalReleased() → uint256
public
#Getter for the total amount of Ether already released.
totalReleased(contract IERC20 token) → uint256
public
#Getter for the total amount of token
already released. token
should be the address of an IERC20
contract.
shares(address account) → uint256
public
#Getter for the amount of shares held by an account.
released(address account) → uint256
public
#Getter for the amount of Ether already released to a payee.
released(contract IERC20 token, address account) → uint256
public
#Getter for the amount of token
tokens already released to a payee. token
should be the address of an
IERC20 contract.
payee(uint256 index) → address
public
#Getter for the address of the payee number index
.
releasable(address account) → uint256
public
#Getter for the amount of payee's releasable Ether.
releasable(contract IERC20 token, address account) → uint256
public
#Getter for the amount of payee's releasable token
tokens. token
should be the address of an
IERC20 contract.
release(address payable account)
public
#Triggers a transfer to account
of the amount of Ether they are owed, according to their percentage of the
total shares and their previous withdrawals.
release(contract IERC20 token, address account)
public
#Triggers a transfer to account
of the amount of token
tokens they are owed, according to their
percentage of the total shares and their previous withdrawals. token
must be the address of an IERC20
contract.
PayeeAdded(address account, uint256 shares)
event
#PaymentReleased(address to, uint256 amount)
event
#ERC20PaymentReleased(contract IERC20 indexed token, address to, uint256 amount)
event
#PaymentReceived(address from, uint256 amount)
event
#import "@openzeppelin/contracts/finance/VestingWallet.sol";
This contract handles the vesting of Eth and ERC20 tokens for a given beneficiary. Custody of multiple tokens
can be given to this contract, which will release the token to the beneficiary following a given vesting schedule.
The vesting schedule is customizable through the VestingWallet.vestedAmount
function.
Any token transferred to this contract will follow the vesting schedule as if they were locked from the beginning. Consequently, if the vesting has already started, any amount of tokens sent to this contract will (at least partly) be immediately releasable.
Functions
constructor(address beneficiaryAddress, uint64 startTimestamp, uint64 durationSeconds)
public
#Set the beneficiary, start timestamp and vesting duration of the vesting wallet.
receive()
external
#The contract should be able to receive Eth.
beneficiary() → address
public
#Getter for the beneficiary address.
start() → uint256
public
#Getter for the start timestamp.
duration() → uint256
public
#Getter for the vesting duration.
released() → uint256
public
#Amount of eth already released
released(address token) → uint256
public
#Amount of token already released
releasable() → uint256
public
#Getter for the amount of releasable eth.
releasable(address token) → uint256
public
#Getter for the amount of releasable token
tokens. token
should be the address of an
IERC20 contract.
release()
public
#Release the native token (ether) that have already vested.
Emits a VestingWallet.EtherReleased
event.
release(address token)
public
#Release the tokens that have already vested.
Emits a VestingWallet.ERC20Released
event.
vestedAmount(uint64 timestamp) → uint256
public
#Calculates the amount of ether that has already vested. Default implementation is a linear vesting curve.
vestedAmount(address token, uint64 timestamp) → uint256
public
#Calculates the amount of tokens that has already vested. Default implementation is a linear vesting curve.
_vestingSchedule(uint256 totalAllocation, uint64 timestamp) → uint256
internal
#Virtual implementation of the vesting formula. This returns the amount vested, as a function of time, for an asset given its total historical allocation.
EtherReleased(uint256 amount)
event
#ERC20Released(address indexed token, uint256 amount)
event
#