Sequential Dutch Auctioneer (SDA)
The Base SDA contract is an implementation of the Auctioneer Interface that uses a Sequential Dutch Auction pricing system to buy a target amount of quote tokens or sell a target amount of base tokens over the duration of a market.
The contract is abstract since it leaves final implementation of the createMarket
function to a contract that inherits it.
Data Structures (Structs)
MarketParams
Parameters to create a new SDA market. Encoded as bytes and provided as input to createMarket
.
Calculating Formatted Price and Scale Adjustment
In order to support a broad range of tokens, with different decimal configurations and prices, we calculate an optimal scaling factor for each market. Specifically, the scale adjustment allows the SDA to support tokens with 6 to 18 configured decimals and with prices that differ by up to 24 decimal places (if the tokens have the configured decimals, less if not). To implement this, the market creator must provide a scale adjustment factor and format the price correctly.
First, you need the price of each token in a common unit, e.g. dollars or ether.
where:
Now, using the price values and the configured number of decimals for each token, we can calculate the scale adjustment.
where:
Example:
Once we have the scale adjustment, we can format the initial price using the variables defined above. We're starting the market at the current market price by using the token prices at the time of creation. This is optimal in most situations, but there may be circumstances where it makes sense to choose a different starting price (e.g. you want delayed activity or activity only if the price increases in the short-term).
Example: Continuing with the WETH and OHM example from above, we format the initial price as:
The difference between the scale and the full decimal difference can result in the price ratio shifting some decimal places. However, we can find the appropriate price factor by considering what we expect the ratio to be from the initial prices. 10 / 1500 = 0.00666.., so we can see the proper price factor is 10^37.
Any alternative way to confirm your minimum price is correct is to redo the same calculation as used to determine initial price, with an updated minimum price for the payout token. Using the 0.005 WETH per OHM value, that would be an OHM price of $7.5 ($1500 x 0.005 = $7.5).
BondMarket
The BondMarket struct contains the core data about a bond market.
BondTerms
BondMetadata
Methods
closeMarket
Disable existing bond marketMust be market owner
Parameters
createMarket
Creates a new bond market
See specific auctioneer implementations for details on encoding the parameters.
Parameters
Returns
currentCapacity
Returns current capacity of a market
Parameters
Returns
currentControlVariable
Up to date control variable
Accounts for control variable adjustment
Parameters
Returns
currentDebt
Calculate debt factoring in decay
Accounts for debt decay since last deposit
Parameters
Returns
getAggregator
Returns the Aggregator that services the Auctioneer
Returns
getMarketInfoForPurchase
Provides information for the Teller to execute purchases on a Market
Parameters
Returns
getTeller
Returns the Teller that services the Auctioneer
Returns
isInstantSwap
Does market send payout immediately
Parameters
Returns
isLive
Is a given market accepting deposits
Parameters
Returns
marketPrice
Calculate current market price of payout token in quote tokens
Accounts for debt and control variable decay since last deposit (vs _marketPrice())
Parameters
Returns
marketScale
Scale value to use when converting between quote token and payout token amounts with marketPrice()
Parameters
Returns
maxAmountAccepted
Returns maximum amount of quote token accepted by the market
Parameters
Returns
ownerOf
Returns the address of the market owner
Parameters
Returns
payoutFor
Payout due for amount of quote tokens
Accounts for debt and control variable decay so it is up to date
Parameters
Returns
pullOwnership
Accept ownership of a marketMust be market newOwner
The existing owner must call pushOwnership prior to the newOwner calling this function
Parameters
purchaseBond
Exchange quote tokens for a bond in a specified marketMust be teller
Parameters
Returns
pushOwnership
Designate a new owner of a market. Must be existing market owner to call.
Doesn't change permissions until newOwner calls pullOwnership
Parameters
setAllowNewMarkets
Change the status of the auctioneer to allow creation of new markets
Setting to false and allowing active markets to end will sunset the auctioneer
Parameters
setCallbackAuthStatus
Change whether a market creator is allowed to use a callback address in their markets or notMust be guardian
Callback is believed to be safe, but a whitelist is implemented to prevent abuse
Parameters
setDefaults
Set the auctioneer defaultsMust be policy
The defaults set here are important to avoid edge cases in market behavior, e.g. a very short market reacts doesn't tune wellOnly applies to new markets that are created after the change
Parameters
setIntervals
Set market intervals to different values than the defaultsMust be market owner
Changing the intervals could cause markets to behave in unexpected way tuneInterval should be greater than tuneAdjustmentDelay
Parameters
Last updated