Skip to content

Commit

Permalink
feat: add OFDA, OSDA, and SDA v1.1 contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
Oighty committed May 31, 2023
1 parent 0e1305d commit 1ccb649
Show file tree
Hide file tree
Showing 15 changed files with 1,804 additions and 285 deletions.
58 changes: 36 additions & 22 deletions README.md

Large diffs are not rendered by default.

67 changes: 67 additions & 0 deletions src/BondFixedExpiryOFDA.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity 0.8.15;

import {BondBaseOFDA, IBondAggregator, Authority} from "./bases/BondBaseOFDA.sol";
import {IBondTeller} from "./interfaces/IBondTeller.sol";
import {IBondFixedExpiryTeller} from "./interfaces/IBondFixedExpiryTeller.sol";

/// @title Bond Fixed-Expiry Fixed Discount Auctioneer
/// @notice Bond Fixed-Expiry Fixed Discount Auctioneer Contract
/// @dev Bond Protocol is a permissionless system to create bond markets
/// for any token pair. Bond issuers create BondMarkets that pay out
/// a Payout Token in exchange for deposited Quote Tokens. Users can purchase
/// future-dated Payout Tokens with Quote Tokens at the current market price and
/// receive Bond Tokens to represent their position while their bond vests.
/// Once the Bond Tokens vest, they can redeem it for the Quote Tokens.
///
/// @dev An Auctioneer contract allows users to create and manage bond markets.
/// All bond pricing logic and market data is stored in the Auctioneer.
/// An Auctioneer is dependent on a Teller to serve external users and
/// an Aggregator to register new markets. The Fixed Discount Auctioneer
/// lets issuers set a Fixed Discount to an oracle price to buy a
/// target amount of quote tokens or sell a target amount of payout tokens
/// over the duration of a market.
/// See IBondOFDA.sol for price format details.
///
/// @dev The Fixed-Expiry Fixed Discount Auctioneer is an implementation of the
/// Bond Base Fixed Discount Auctioneer contract specific to creating bond markets where
/// all purchases on that market vest at a certain timestamp.
///
/// @author Oighty
contract BondFixedExpiryOFDA is BondBaseOFDA {
/* ========== CONSTRUCTOR ========== */
constructor(
IBondTeller teller_,
IBondAggregator aggregator_,
address guardian_,
Authority authority_
) BondBaseOFDA(teller_, aggregator_, guardian_, authority_) {}

/// @inheritdoc BondBaseOFDA
function createMarket(bytes calldata params_) external override returns (uint256) {
// Decode params into the struct type expected by this auctioneer
MarketParams memory params = abi.decode(params_, (MarketParams));

// Vesting is rounded to the nearest day at 0000 UTC (in seconds) since bond tokens
// are only unique to a day, not a specific timestamp.
params.vesting = (params.vesting / 1 days) * 1 days;

// Get conclusion from start time and duration
// Don't need to check valid start time or duration here since it will be checked in _createMarket
uint48 start = params.start == 0 ? uint48(block.timestamp) : params.start;
uint48 conclusion = start + params.duration;

// Check that the vesting parameter is valid for a fixed-expiry market
if (params.vesting != 0 && params.vesting < conclusion) revert Auctioneer_InvalidParams();

// Create market with provided params
uint256 marketId = _createMarket(params);

// Create bond token (ERC20 for fixed expiry) if not instant swap
if (params.vesting != 0)
IBondFixedExpiryTeller(address(_teller)).deploy(params.payoutToken, params.vesting);

// Return market ID
return marketId;
}
}
60 changes: 60 additions & 0 deletions src/BondFixedExpiryOSDA.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity ^0.8.15;

import {BondBaseOSDA, IBondAggregator, Authority} from "./bases/BondBaseOSDA.sol";
import {IBondTeller} from "./interfaces/IBondTeller.sol";
import {IBondFixedExpiryTeller} from "./interfaces/IBondFixedExpiryTeller.sol";

/// @title Bond Fixed-Expiry Oracle-based Sequential Dutch Auctioneer
/// @notice Bond Fixed-Expiry Oracle-based Sequential Dutch Auctioneer Contract
/// @dev Bond Protocol is a permissionless system to create Olympus-style bond markets
/// for any token pair. The markets do not require maintenance and will manage
/// bond prices based on activity. Bond issuers create BondMarkets that pay out
/// a Payout Token in exchange for deposited Quote Tokens. Users can purchase
/// future-dated Payout Tokens with Quote Tokens at the current market price and
/// receive Bond Tokens to represent their position while their bond vests.
/// Once the Bond Tokens vest, they can redeem it for the Quote Tokens.
///
/// @dev The Fixed-Expiry Oracle-based SDA is an implementation of the
/// Bond Base Oracle-based SDA contract specific to creating bond markets where
/// all purchases on that market vest at a certain timestamp.
///
/// @author Oighty, Zeus, Potted Meat, indigo
contract BondFixedExpiryOSDA is BondBaseOSDA {
/* ========== CONSTRUCTOR ========== */
constructor(
IBondTeller teller_,
IBondAggregator aggregator_,
address guardian_,
Authority authority_
) BondBaseOSDA(teller_, aggregator_, guardian_, authority_) {}

/// @inheritdoc BondBaseOSDA
function createMarket(bytes calldata params_) external override returns (uint256) {
// Decode params into the struct type expected by this auctioneer
MarketParams memory params = abi.decode(params_, (MarketParams));

// Vesting is rounded to the nearest day at 0000 UTC (in seconds) since bond tokens
// are only unique to a day, not a specific timestamp.
params.vesting = (params.vesting / 1 days) * 1 days;

// Get conclusion from start time and duration
// Don't need to check valid start time or duration here since it will be checked in _createMarket
uint48 start = params.start == 0 ? uint48(block.timestamp) : params.start;
uint48 conclusion = start + params.duration;

// Check that the vesting parameter is valid for a fixed-expiry market
if (params.vesting != 0 && params.vesting < conclusion) revert Auctioneer_InvalidParams();

// Create market with provided params
uint256 marketId = _createMarket(params);

// Create bond token (ERC20 for fixed expiry) if not instant swap
if (params.vesting != 0) {
IBondFixedExpiryTeller(address(_teller)).deploy(params.payoutToken, params.vesting);
}

// Return market ID
return marketId;
}
}
10 changes: 7 additions & 3 deletions src/BondFixedExpirySDA.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {BondBaseSDA, IBondAggregator, Authority} from "./bases/BondBaseSDA.sol";
import {IBondTeller} from "./interfaces/IBondTeller.sol";
import {IBondFixedExpiryTeller} from "./interfaces/IBondFixedExpiryTeller.sol";

/// @title Bond Fixed-Expiry Sequential Dutch Auctioneer
/// @title Bond Fixed-Expiry Sequential Dutch Auctioneer v1.1
/// @notice Bond Fixed-Expiry Sequential Dutch Auctioneer Contract
/// @dev Bond Protocol is a permissionless system to create Olympus-style bond markets
/// for any token pair. The markets do not require maintenance and will manage
Expand Down Expand Up @@ -38,9 +38,13 @@ contract BondFixedExpirySDA is BondBaseSDA {
// are only unique to a day, not a specific timestamp.
params.vesting = (params.vesting / 1 days) * 1 days;

// Get conclusion from start time and duration
// Don't need to check valid start time or duration here since it will be checked in _createMarket
uint48 start = params.start == 0 ? uint48(block.timestamp) : params.start;
uint48 conclusion = start + uint48(params.duration);

// Check that the vesting parameter is valid for a fixed-expiry market
if (params.vesting != 0 && params.vesting < params.conclusion)
revert Auctioneer_InvalidParams();
if (params.vesting != 0 && params.vesting < conclusion) revert Auctioneer_InvalidParams();

// Create market with provided params
uint256 marketId = _createMarket(params);
Expand Down
52 changes: 52 additions & 0 deletions src/BondFixedTermOFDA.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity 0.8.15;

import {BondBaseOFDA, IBondAggregator, Authority} from "./bases/BondBaseOFDA.sol";
import {IBondTeller} from "./interfaces/IBondTeller.sol";

/// @title Bond Fixed-Term Fixed Discount Auctioneer
/// @notice Bond Fixed-Term Fixed Discount Auctioneer Contract
/// @dev Bond Protocol is a permissionless system to create bond markets
/// for any token pair. Bond issuers create BondMarkets that pay out
/// a Payout Token in exchange for deposited Quote Tokens. Users can purchase
/// future-dated Payout Tokens with Quote Tokens at the current market price and
/// receive Bond Tokens to represent their position while their bond vests.
/// Once the Bond Tokens vest, they can redeem it for the Quote Tokens.
///
/// @dev An Auctioneer contract allows users to create and manage bond markets.
/// All bond pricing logic and market data is stored in the Auctioneer.
/// An Auctioneer is dependent on a Teller to serve external users and
/// an Aggregator to register new markets. The Fixed Discount Auctioneer
/// lets issuers set a Fixed Discount to an oracle price to buy a
/// target amount of quote tokens or sell a target amount of payout tokens
/// over the duration of a market.
/// See IBondOFDA.sol for price format details.
///
/// @dev The Fixed-Term Fixed Discount Auctioneer is an implementation of the
/// Bond Bas Fixed Discount Auctioneer contract specific to creating bond markets where
/// purchases vest in a fixed amount of time after purchased (rounded to the day).
///
/// @author Oighty
contract BondFixedTermOFDA is BondBaseOFDA {
/* ========== CONSTRUCTOR ========== */
constructor(
IBondTeller teller_,
IBondAggregator aggregator_,
address guardian_,
Authority authority_
) BondBaseOFDA(teller_, aggregator_, guardian_, authority_) {}

/* ========== MARKET FUNCTIONS ========== */
/// @inheritdoc BondBaseOFDA
function createMarket(bytes calldata params_) external override returns (uint256) {
// Decode params into the struct type expected by this auctioneer
MarketParams memory params = abi.decode(params_, (MarketParams));

// Check that the vesting parameter is valid for a fixed-term market
if (params.vesting != 0 && (params.vesting < 1 days || params.vesting > MAX_FIXED_TERM))
revert Auctioneer_InvalidParams();

// Create market and return market ID
return _createMarket(params);
}
}
44 changes: 44 additions & 0 deletions src/BondFixedTermOSDA.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity ^0.8.15;

import {BondBaseOSDA, IBondAggregator, Authority} from "./bases/BondBaseOSDA.sol";
import {IBondTeller} from "./interfaces/IBondTeller.sol";

/// @title Bond Fixed-Term Oracle-based Sequential Dutch Auctioneer
/// @notice Bond Fixed-Term Oracle-based Sequential Dutch Auctioneer Contract
/// @dev Bond Protocol is a permissionless system to create Olympus-style bond markets
/// for any token pair. The markets do not require maintenance and will manage
/// bond prices based on activity. Bond issuers create BondMarkets that pay out
/// a Payout Token in exchange for deposited Quote Tokens. Users can purchase
/// future-dated Payout Tokens with Quote Tokens at the current market price and
/// receive Bond Tokens to represent their position while their bond vests.
/// Once the Bond Tokens vest, they can redeem it for the Quote Tokens.
///
/// @dev The Fixed-Term Oracle-based SDA is an implementation of the
/// Bond Base OSDA contract specific to creating bond markets where
/// purchases vest in a fixed amount of time after purchased (rounded to the day).
///
/// @author Oighty, Zeus, Potted Meat, indigo
contract BondFixedTermOSDA is BondBaseOSDA {
/* ========== CONSTRUCTOR ========== */
constructor(
IBondTeller teller_,
IBondAggregator aggregator_,
address guardian_,
Authority authority_
) BondBaseOSDA(teller_, aggregator_, guardian_, authority_) {}

/* ========== MARKET FUNCTIONS ========== */
/// @inheritdoc BondBaseOSDA
function createMarket(bytes calldata params_) external override returns (uint256) {
// Decode params into the struct type expected by this auctioneer
MarketParams memory params = abi.decode(params_, (MarketParams));

// Check that the vesting parameter is valid for a fixed-term market
if (params.vesting != 0 && (params.vesting < 1 days || params.vesting > MAX_FIXED_TERM))
revert Auctioneer_InvalidParams();

// Create market and return market ID
return _createMarket(params);
}
}
44 changes: 0 additions & 44 deletions src/BondSampleCallback.sol

This file was deleted.

Loading

0 comments on commit 1ccb649

Please sign in to comment.