Base Callback

The Base Callback contract is an optional feature of the Bond system. Callbacks allow issuers (market creators) to apply custom logic on receipt and payout of tokens.

In addition to the Callback Interface, the Base Callback is also implemented to provide a secure starting point for creating a Callback contract.

The base handles permissioning of Tellers (and specific markets served by the Teller) to avoid unauthorized contracts from accessing the callback function.

Additionally, the setup and data storage for getting data from an Aggregator.

Finally, the external callback function is implemented to ensure the Teller is providing the stated amount of Quote Tokens prior to disbursing Payout Tokens. Issuer-specific logic can be implemented in the _callback internal function which is called by the external one.

The Callback must be created prior to market creation and the address passed in as an argument. The Callback depends on the Aggregator contract for the Auctioneer that the market is created to get market data. Without a Callback contract, payout tokens are transferred directly from the market owner on each bond purchase (market owners must approve the Teller serving that market for the amount of Payout Tokens equivalent to the capacity of a market when created.

Methods

amountsForMarket

function amountsForMarket(uint256 id_) external view returns (uint256 in_, uint256 out_)

Returns the number of quote tokens received and payout tokens paid out for a market

Parameters

NameTypeDescription

id_

uint256

ID of the market

Returns

NameTypeDescription

in_

uint256

Amount of quote tokens bonded to the market

out_

uint256

Amount of payout tokens paid out to the market

approvedMarkets

function approvedMarkets(address, uint256) external view returns (bool)

Parameters

NameTypeDescription

teller_

address

Address of the Teller contract

id_

uint256

ID of the market

Returns

NameTypeDescription

approved

bool

Whether the Teller and Market ID combination are approved on the callback

callback

function callback(uint256 id_, uint256 inputAmount_, uint256 outputAmount_) external nonpayable

Send payout tokens to Teller while allowing market owners to perform custom logic on received or paid out tokensMarket ID on Teller must be whitelisted

Must transfer the output amount of payout tokens back to the TellerShould check that the quote tokens have been transferred to the contract in the _callback function

Parameters

NameTypeDescription

id_

uint256

ID of the market

inputAmount_

uint256

Amount of quote tokens bonded to the market

outputAmount_

uint256

Amount of payout tokens to be paid out to the market

deposit

function deposit(contract ERC20 token_, uint256 amount_) external nonpayable

Deposit tokens to the callback and update balancesOnly callback owner

Parameters

NameTypeDescription

token_

contract ERC20

Address of the token to deposit

amount_

uint256

Amount of tokens to deposit

owner

function owner() external view returns (address)

Returns the address of the current owner.

Returns

NameTypeDescription

owner

address

Owner of the callback with admin privileges

renounceOwnership

function renounceOwnership() external nonpayable

Leaves the contract without owner. It will not be possible to call onlyOwner functions anymore. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby removing any functionality that is only available to the owner.

transferOwnership

function transferOwnership(address newOwner) external nonpayable

Transfers ownership of the contract to a new account (newOwner). Can only be called by the current owner.

Parameters

NameTypeDescription

newOwner

address

Address to transfer ownership to

whitelist

function whitelist(address teller_, uint256 id_) external nonpayable

Whitelist a teller and market ID combinationMust be callback owner

Parameters

NameTypeDescription

teller_

address

Address of the Teller contract which serves the market

id_

uint256

ID of the market

withdraw

function withdraw(address to_, contract ERC20 token_, uint256 amount_) external nonpayable

Withdraw tokens from the callback and update balancesOnly callback owner

Parameters

NameTypeDescription

to_

address

Address of the recipient

token_

contract ERC20

Address of the token to withdraw

amount_

uint256

Amount of tokens to withdraw

Events

OwnershipTransferred

event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)

Parameters

NameTypeDescription

previousOwner indexed

address

Address of previous owner

newOwner indexed

address

Address of new owner

Errors

Callback_MarketNotSupported

error Callback_MarketNotSupported(uint256 id)

Parameters

NameTypeDescription

id

uint256

ID of market

Callback_TokensNotReceived

error Callback_TokensNotReceived()