Bond
A custom ERC20 token that can be used to issue bonds.The contract handles issuance, payment, conversion, and redemption.
Events
Approval
address | owner |
address | spender |
uint256 | value |
CollateralWithdraw
Emitted when collateral is withdrawn.
address | from |
address | receiver |
address | token |
uint256 | amount |
Convert
Emitted when bond shares are converted by a Bond holder.
address | from |
address | collateralToken |
uint256 | amountOfBondsConverted |
uint256 | amountOfCollateralTokens |
ExcessPaymentWithdraw
Emitted when payment over the required amount is withdrawn.
address | from |
address | receiver |
address | token |
uint256 | amount |
Initialized
OwnershipTransferred
address | previousOwner |
address | newOwner |
Payment
Emitted when a portion of the Bond's principal is paid.
address | from |
uint256 | amount |
Redeem
Emitted when a bond share is redeemed.
address | from |
address | paymentToken |
address | collateralToken |
uint256 | amountOfBondsRedeemed |
uint256 | amountOfPaymentTokensReceived |
uint256 | amountOfCollateralTokens |
TokenSweep
Emitted when a token is swept by the contract owner.
address | from |
---|---|
address | receiver |
contract IERC20Metadata | token |
uint256 | amount |
Transfer
address | from |
address | to |
uint256 | value |
Errors
BondBeforeGracePeriodAndNotPaid
Bond redemption is impossible because the grace period has not yet passed and the bond has not been fully paid.
BondPastMaturity
Operation restricted because the Bond has matured.
NoPaymentToWithdraw
Attempted to withdraw with no excess payment in the contract.
NotEnoughCollateral
Attempted to withdraw more collateral than available.
PaymentAlreadyMet
Attempted to pay after payment was met.
SweepDisallowedForToken
Attempted to sweep a token used in the contract.
ZeroAmount
Attempted to perform an action that would do nothing.
Methods
allowance
Parameters
address | owner |
---|---|
address | spender |
Returns
amountUnpaid
The amount of paymentTokens required to fully pay the contract.
Returns
approve
Parameters
address | spender |
---|---|
uint256 | amount |
Returns
balanceOf
Parameters
Returns
burn
Parameters
burnFrom
Parameters
address | account |
---|---|
uint256 | amount |
collateralBalance
The external balance of the ERC20 collateral token.
Returns
collateralRatio
The number of collateralTokens per Bond.
Returns
collateralToken
The ERC20 token used as collateral backing the bond.
Returns
convert
For convertible Bonds (ones with a convertibilityRatio > 0), the Bond holder may convert their bond to underlying collateral at the convertibleRatio. The bond must also have not past maturity for this to be possible.
Parameters
convertibleRatio
The number of convertibleTokens the bonds will convert into.
Returns
decimals
Returns
decreaseAllowance
Parameters
address | spender |
---|---|
uint256 | subtractedValue |
Returns
gracePeriodEnd
One week after the maturity date. Bond collateral can be redeemed after this date.
Returns
increaseAllowance
Parameters
address | spender |
---|---|
uint256 | addedValue |
Returns
initialize
This one-time setup initiated by the BondFactory initializes the Bond with the given configuration.
Parameters
string | bondName | Passed into the ERC20 token to define the name. |
---|---|---|
string | bondSymbol | Passed into the ERC20 token to define the symbol. |
address | bondOwner | Ownership of the created Bond is transferred to this address by way of _transferOwnership and also the address that tokens are minted to. See `initialize` in `Bond`. |
uint256 | _maturity | The timestamp at which the Bond will mature. |
address | _paymentToken | The ERC20 token address the Bond is redeemable for. |
address | _collateralToken | The ERC20 token address the Bond is backed by. |
uint256 | _collateralRatio | The amount of collateral tokens per bond. |
uint256 | _convertibleRatio | The amount of convertible tokens per bond. |
uint256 | maxSupply | The amount of Bonds given to the owner during the one- time mint during this initialization. |
isMature
Checks if the maturity timestamp has passed.
Returns
maturity
A date set at Bond creation when the Bond will mature.
Returns
name
Returns
owner
Returns
pay
Allows the owner to pay the bond by depositing paymentTokens.
Parameters
paymentBalance
Gets the external balance of the ERC20 paymentToken.
Returns
paymentToken
This is the token the borrower deposits into the contract and what the Bond holders will receive when redeemed.
Returns
previewConvertBeforeMaturity
Before maturity, if the given bonds are converted, this would be the number of collateralTokens received. This function rounds down the number of returned collateral.
Parameters
Returns
previewRedeemAtMaturity
At maturity, if the given bond shares are redeemed, this would be the number of collateralTokens and paymentTokens received by the bond holder. The number of paymentTokens to receive is rounded down.
Parameters
Returns
uint256 | The number of paymentTokens that the bond shares would be redeemed for. |
---|---|
uint256 | The number of collateralTokens that would be redeemed for. |
previewWithdrawExcessCollateral
The number of collateralTokens that the owner would be able to withdraw from the contract. This does not take into account an amount of payment like previewWithdrawExcessCollateralAfterPayment
does. See that function for more information.
Returns
previewWithdrawExcessCollateralAfterPayment
The number of collateralTokens that the owner would be able to withdraw from the contract. This function rounds up the number of collateralTokens required in the contract and therefore may round down the amount received.
Parameters
Returns
previewWithdrawExcessPayment
The number of excess paymentTokens that the owner would be able to withdraw from the contract.
Returns
redeem
The Bond holder can burn bond shares in return for their portion of paymentTokens and collateralTokens backing the Bonds. These portions of tokens depends on the number of paymentTokens deposited. When the Bond is fully paid, redemption will result in all paymentTokens. If the Bond has reached maturity without being fully paid, a portion of the collateralTokens will be available.
Parameters
renounceOwnership
sweep
Sends ERC20 tokens to the owner that are in this contract.
Parameters
contract IERC20Metadata | sweepingToken | The ERC20 token to sweep and send to the receiver. |
---|---|---|
address | receiver | The address that is transferred the swept token. |
symbol
Returns
totalSupply
Returns
transfer
Parameters
address | to |
---|---|
uint256 | amount |
Returns
transferFrom
Parameters
address | from |
---|---|
address | to |
uint256 | amount |
Returns
transferOwnership
Parameters
withdrawExcessCollateral
The Owner may withdraw excess collateral from the Bond contract. The number of collateralTokens remaining in the contract must be enough to cover the total supply of Bonds in accordance to both the collateralRatio and convertibleRatio.
Parameters
uint256 | amount | The number of collateralTokens to withdraw. Reverts if the amount is greater than available in the contract. |
---|---|---|
address | receiver | The address transferred the excess collateralTokens. |
withdrawExcessPayment
The owner can withdraw any excess paymentToken in the contract.
Parameters
Last updated