Bond

A custom ERC20 token that can be used to issue bonds.The contract handles issuance, payment, conversion, and redemption.

Events

Approval

address indexed

owner

address indexed

spender

uint256

value

CollateralWithdraw

Emitted when collateral is withdrawn.

address indexed

from

address indexed

receiver

address indexed

token

uint256

amount

Convert

Emitted when bond shares are converted by a Bond holder.

address indexed

from

address indexed

collateralToken

uint256

amountOfBondsConverted

uint256

amountOfCollateralTokens

ExcessPaymentWithdraw

Emitted when payment over the required amount is withdrawn.

address indexed

from

address indexed

receiver

address indexed

token

uint256

amount

Initialized

OwnershipTransferred

address indexed

previousOwner

address indexed

newOwner

Payment

Emitted when a portion of the Bond's principal is paid.

address indexed

from

uint256

amount

Redeem

Emitted when a bond share is redeemed.

address indexed

from

address indexed

paymentToken

address indexed

collateralToken

uint256

amountOfBondsRedeemed

uint256

amountOfPaymentTokensReceived

uint256

amountOfCollateralTokens

TokenSweep

Emitted when a token is swept by the contract owner.

addressfrom

address indexed

receiver

contract IERC20Metadata

token

uint256

amount

Transfer

address indexed

from

address indexed

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

function allowance(address owner, address spender) external view returns (uint256)

Parameters

addressowner

address

spender

Returns

amountUnpaid

function amountUnpaid() external view returns (uint256 paymentTokens)

The amount of paymentTokens required to fully pay the contract.

Returns

approve

function approve(address spender, uint256 amount) external nonpayable returns (bool)

Parameters

addressspender

uint256

amount

Returns

balanceOf

function balanceOf(address account) external view returns (uint256)

Parameters

Returns

burn

function burn(uint256 amount) external nonpayable

Parameters

burnFrom

function burnFrom(address account, uint256 amount) external nonpayable

Parameters

addressaccount

uint256

amount

collateralBalance

function collateralBalance() external view returns (uint256 collateralTokens)

The external balance of the ERC20 collateral token.

Returns

collateralRatio

function collateralRatio() external view returns (uint256)

The number of collateralTokens per Bond.

Returns

collateralToken

function collateralToken() external view returns (address)

The ERC20 token used as collateral backing the bond.

Returns

convert

function convert(uint256 bonds) external nonpayable

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

function convertibleRatio() external view returns (uint256)

The number of convertibleTokens the bonds will convert into.

Returns

decimals

function decimals() external view returns (uint8)

Returns

decreaseAllowance

function decreaseAllowance(address spender, uint256 subtractedValue) external nonpayable returns (bool)

Parameters

addressspender

uint256

subtractedValue

Returns

gracePeriodEnd

function gracePeriodEnd() external view returns (uint256 gracePeriodEndTimestamp)

One week after the maturity date. Bond collateral can be redeemed after this date.

Returns

increaseAllowance

function increaseAllowance(address spender, uint256 addedValue) external nonpayable returns (bool)

Parameters

addressspender

uint256

addedValue

Returns

initialize

function initialize(string bondName, string bondSymbol, address bondOwner, uint256 _maturity, address _paymentToken, address _collateralToken, uint256 _collateralRatio, uint256 _convertibleRatio, uint256 maxSupply) external nonpayable

This one-time setup initiated by the BondFactory initializes the Bond with the given configuration.

Parameters

stringbondNamePassed 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

function isMature() external view returns (bool isBondMature)

Checks if the maturity timestamp has passed.

Returns

maturity

function maturity() external view returns (uint256)

A date set at Bond creation when the Bond will mature.

Returns

name

function name() external view returns (string)

Returns

owner

function owner() external view returns (address)

Returns

pay

function pay(uint256 amount) external nonpayable

Allows the owner to pay the bond by depositing paymentTokens.

Parameters

paymentBalance

function paymentBalance() external view returns (uint256 paymentTokens)

Gets the external balance of the ERC20 paymentToken.

Returns

paymentToken

function paymentToken() external view returns (address)

This is the token the borrower deposits into the contract and what the Bond holders will receive when redeemed.

Returns

previewConvertBeforeMaturity

function previewConvertBeforeMaturity(uint256 bonds) external view returns (uint256 collateralTokens)

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

function previewRedeemAtMaturity(uint256 bonds) external view returns (uint256 paymentTokensToSend, uint256 collateralTokensToSend)

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

uint256The number of paymentTokens that the bond shares would be redeemed for.

uint256

The number of collateralTokens that would be redeemed for.

previewWithdrawExcessCollateral

function previewWithdrawExcessCollateral() external view returns (uint256 collateralTokens)

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

function previewWithdrawExcessCollateralAfterPayment(uint256 payment) external view returns (uint256 collateralTokens)

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

function previewWithdrawExcessPayment() external view returns (uint256 paymentTokens)

The number of excess paymentTokens that the owner would be able to withdraw from the contract.

Returns

redeem

function redeem(uint256 bonds) external nonpayable

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

function renounceOwnership() external nonpayable

sweep

function sweep(contract IERC20Metadata sweepingToken, address receiver) external nonpayable

Sends ERC20 tokens to the owner that are in this contract.

Parameters

contract IERC20MetadatasweepingTokenThe ERC20 token to sweep and send to the receiver.

address

receiver

The address that is transferred the swept token.

symbol

function symbol() external view returns (string)

Returns

totalSupply

function totalSupply() external view returns (uint256)

Returns

transfer

function transfer(address to, uint256 amount) external nonpayable returns (bool)

Parameters

addressto

uint256

amount

Returns

transferFrom

function transferFrom(address from, address to, uint256 amount) external nonpayable returns (bool)

Parameters

addressfrom

address

to

uint256

amount

Returns

transferOwnership

function transferOwnership(address newOwner) external nonpayable

Parameters

withdrawExcessCollateral

function withdrawExcessCollateral(uint256 amount, address receiver) external nonpayable

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

uint256amountThe 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

function withdrawExcessPayment(address receiver) external nonpayable

The owner can withdraw any excess paymentToken in the contract.

Parameters

Last updated