Smart Contracts
Last updated
Last updated
Pool Token is just a regular OpenZeppelin token contract. We did not modify it. It mints Pool Tokens against the back tokens received from Liquidity Providers (in our case, a back token is DAI). The contract burns tokens when Liquidity Providers withdraw their DAI from the Pool. Keeper Adapter operations are not accompanied by any change in the Pool Token supply. Pool token exchange rate to back token should be set at the Pool deployment by sending some amount of back tokens to the Pool contract. That will be the amount for a single Pool Token. In our case if we want to set 1 to 1 rate we should send a single DAI. If we send 0.5 DAI the rate will be two Pool Tokens for a single DAI.
The Pool Contract performs a set of core functions to keep the whole protocol work. It enables Liquidity Providers to join the Pool and exit from it. A Pool Contract also forms a queue of withdrawal requests when there are active auctions or an active queue. In addition, Pool Contract allows authorized adapters to take liquidity from the pool within their allowances and provides some other important functionality. The main public methods of the contract are the following:
- join
helps to receive a back token amount (DAI in our Pool) sent to the contract by a Liquidity Provider. At the same time, PoolToken mints an equivalent amount of Pool tokens.
- exit
is an opposite function to join
and redeems Pool Tokens for back tokens.
- addWithdrawRequest
is used to put a back token withdrawal request (in a Pool Token amount) in the queue if there is a lack of liquidity in the Pool due to active auctions.
- removeWithdrawalRequest
is used to cancel a specific request by its ID from the queue.
- processWithdrawQueue
will check if there is enough liquidity in the Pool to start payments for withdrawal requests one by one. If there is enough liquidity, the method will also perform withdrawals.
- withdrawQueueIsActive
checks if there are any pending withdrawals in the Pool.
- allocate
enables an authorized Keeper Adapter (by its ID) take a back token amount from the Pool within the allowance and put this amount to the Maker JOIN_DAI contract to use for bids in auction(s).
- payback
is opposite to the allocate
method. A Keeper Adapter uses the method to return a back token amount from Maker (or from an Exchange in case of the won lot) to the Pool.
- poolTokenTotalSupply
provides the current amount of outstanding Pool tokens.
- poolBackTokenBalance
provides the current amount of liquidity in the Pool (in a back token).
- availableAmountToWithdraw
provides the current balance of the Pool (in a back token) free of the amount taken to auction(s).
This contract can register any smart contract added to the platform and, thus, authorizes them. A Registry Contract also allows for updating/ switching between contracts real time for the Pool purpose. For example, to change a bidding strategy from the currently used to a more suitable for actual market conditions during an auction, it is possible to switch from a contract with the current bidding strategy to the contract with some other one. It is also possible to switch between exchanges to be used to sell collateral. In a Registry Contract, adapter contracts (a Keeper Adapter, an Asset Manager, etc.), service contracts (a bidding strategy, an exchange, etc.), and core contracts (Pool, Pool Token) can be registered. This contract has two major methods:
- setContract
adds a new contract to the Registry with a contract name and its address.
- getContract
finds the contract added to the Registry by its name.
The main purpose of a Keeper Adapter smart contract is to participate in Maker vault collateral liquidation auctions. This happens through making bids in DAI (a Pool Base Token) previously taken from the Pool and placed to the Maker's "JOIN_DAI" contract.
Keeper Adapter Contract uses three major methods related to auctions:
- kick
is used to start an auction by "kicking" an undercollateralized vault.
- bet
is used to make bids in auctions.
- take
gets the won lot (or a Base Token amount from JOIN_DAI contract) from Maker.