Skip to content

Commit

Permalink
Merge pull request #1 from own-protocol/simpleXToken
Browse files Browse the repository at this point in the history
feat: update xToken design
  • Loading branch information
bhargavaparoksham authored Jan 15, 2025
2 parents 332ddd6 + d698948 commit 71833b3
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 219 deletions.
58 changes: 41 additions & 17 deletions src/interfaces/IAssetPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,24 @@ pragma solidity ^0.8.20;
import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import {IXToken} from "./IXToken.sol";
import {ILPRegistry} from "./ILPRegistry.sol";
import {IAssetOracle} from "./IAssetOracle.sol";

interface IAssetPool {
enum CycleState {
ACTIVE, // Normal operation
REBALANCING // LPs rebalancing reserves
REBALANCING // LPs rebalancing reserves
}

// --------------------------------------------------------------------------------
// EVENTS
// --------------------------------------------------------------------------------
event DepositRequested(address indexed user, uint256 amount, uint256 indexed cycleIndex);
event DepositCancelled(address indexed user, uint256 amount, uint256 indexed cycleIndex);
event AssetClaimed(address indexed user, uint256 amount, uint256 indexed cycleIndex);
event BurnRequested(address indexed user, uint256 xTokenAmount, uint256 indexed cycleIndex);
event BurnCancelled(address indexed user, uint256 amount, uint256 indexed cycleIndex);
event ReserveWithdrawn(address indexed user, uint256 amount, uint256 indexed cycleIndex);
event Rebalanced(address indexed lp, uint256 amount, bool isDeficit, uint256 indexed cycleIndex);
event Rebalanced(address indexed lp, uint256 amount, bool isDeposit, uint256 indexed cycleIndex);
event CycleStarted(uint256 indexed cycleIndex, uint256 timestamp);
event CycleTimeUpdated(uint256 newCycleTime);
event RebalanceTimeUpdated(uint256 newRebalanceTime);
Expand All @@ -30,6 +34,9 @@ interface IAssetPool {
int256 rebalanceAmount
);

// --------------------------------------------------------------------------------
// ERRORS
// --------------------------------------------------------------------------------
error InvalidAmount();
error InsufficientBalance();
error NotLP();
Expand All @@ -39,28 +46,36 @@ interface IAssetPool {
error ZeroAddress();
error NothingToClaim();
error NothingToCancel();
error MintOrBurnPending();

// User actions
// --------------------------------------------------------------------------------
// USER ACTIONS
// --------------------------------------------------------------------------------
function depositReserve(uint256 amount) external;
function cancelDeposit() external;
function mintAsset(address user) external;
function burnAsset(uint256 xTokenAmount) external;
function burnAsset(uint256 assetAmount) external;
function cancelBurn() external;
function withdrawReserve(address user) external;

// LP actions
// --------------------------------------------------------------------------------
// LP ACTIONS
// --------------------------------------------------------------------------------
function initiateRebalance() external;
function rebalancePool(address lp, uint256 amount, bool isDeposit) external;

// Governance actions
// --------------------------------------------------------------------------------
// GOVERNANCE ACTIONS
// --------------------------------------------------------------------------------
function updateCycleTime(uint256 newCycleTime) external;
function updateRebalanceTime(uint256 newRebalanceTime) external;
function pausePool() external;
function unpausePool() external;

// View functions
// --------------------------------------------------------------------------------
// VIEW FUNCTIONS
// --------------------------------------------------------------------------------
function getGeneralInfo() external view returns (
uint256 _reserveBalance,
uint256 _xTokenSupply,
CycleState _cycleState,
uint256 _cycleIndex,
Expand All @@ -76,25 +91,34 @@ interface IAssetPool {
int256 _rebalanceAmount
);

// State getters
// --------------------------------------------------------------------------------
// STATE GETTERS
// --------------------------------------------------------------------------------
function reserveToken() external view returns (IERC20);
function assetToken() external view returns (IXToken);
function lpRegistry() external view returns (ILPRegistry);
function assetOracle() external view returns (IAssetOracle);

function cycleIndex() external view returns (uint256);
function cycleState() external view returns (CycleState);
function nextRebalanceStartDate() external view returns (uint256);
function nextRebalanceEndDate() external view returns (uint256);
function cycleTime() external view returns (uint256);
function rebalanceTime() external view returns (uint256);
function reserveBalance() external view returns (uint256);
function totalDepositRequests() external view returns (uint256);
function totalRedemptionRequests() external view returns (uint256);
function totalRedemptionScaledRequests() external view returns (uint256);

function totalReserveBalance() external view returns (uint256);
function newReserveSupply() external view returns (uint256);
function newAssetSupply() external view returns (uint256);
function netReserveDelta() external view returns (int256);
function rebalanceAmount() external view returns (int256);

function rebalancedLPs() external view returns (uint256);
function hasRebalanced(address lp) external view returns (bool);
function depositRequests(address user) external view returns (uint256);
function redemptionScaledRequests(address user) external view returns (uint256);

function cycleTotalDepositRequests(uint256 cycle) external view returns (uint256);
function cycleTotalRedemptionRequests(uint256 cycle) external view returns (uint256);
function cycleDepositRequests(uint256 cycle, address user) external view returns (uint256);
function cycleRedemptionRequests(uint256 cycle, address user) external view returns (uint256);
function lastActionCycle(address user) external view returns (uint256);
function cycleRebalancePrice(uint256 _cycleIndex) external view returns (uint256);
}
function cycleRebalancePrice(uint256 cycle) external view returns (uint256);
}
74 changes: 27 additions & 47 deletions src/interfaces/IXToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
// author: bhargavaparoksham

pragma solidity ^0.8.20;

import {IERC20} from 'openzeppelin-contracts/contracts/token/ERC20/IERC20.sol';
import {IAssetOracle} from './IAssetOracle.sol';

interface IXToken {
/**
interface IXToken is IERC20 {

/**
* @dev Thrown when a caller is not the pool contract
*/
error NotPool();
Expand All @@ -15,11 +18,6 @@ interface IXToken {
*/
error ZeroAddress();

/**
* @dev Thrown when asset price is invalid (zero)
*/
error InvalidPrice();

/**
* @dev Thrown when account has insufficient balance for an operation
*/
Expand All @@ -34,82 +32,64 @@ interface IXToken {
* @dev Emitted after the mint action
* @param account The address receiving the minted tokens
* @param value The amount being minted
* @param price The price at which the tokens are minted
* @param reserve The amount of reserve tokens which is backing the minted xTokens
**/
event Mint(address indexed account, uint256 value, uint256 price);
event Mint(address indexed account, uint256 value, uint256 reserve);

/**
* @dev Emitted after xTokens are burned
* @param account The owner of the xTokens, getting burned
* @param value The amount being burned
* @param reserve The amount of reserve tokens
**/
event Burn(address indexed account, uint256 value);

/**
* @dev Returns the scaled balance of the user. The scaled balance represents the user's balance
* normalized by the underlying asset price, maintaining constant purchasing power.
* @param user The user whose balance is calculated
* @return The scaled balance of the user
**/
function scaledBalanceOf(address user) external view returns (uint256);

/**
* @dev Returns the scaled total supply of the token. Represents the total supply
* normalized by the asset price.
* @return The scaled total supply
**/
function scaledTotalSupply() external view returns (uint256);

/**
* @dev Returns the market value of a user's tokens.
* @param user The user whose balance is calculated
* @return The market value of a user's tokens
**/
function marketValue(address user) external view returns (uint256);

/**
* @dev Returns the total market value of all the tokens.
* @return The total market value of all the tokens
**/
function totalMarketValue() external view returns (uint256);
event Burn(address indexed account, uint256 value, uint256 reserve);

/**
* @dev Returns the version of the xToken implementation
* @return The version number
**/
function XTOKEN_VERSION() external view returns (uint256);

/**
* @dev Returns the oracle contract address used for price feeds
* @return The address of the oracle contract
**/
function oracle() external view returns (IAssetOracle);

/**
* @dev Returns the pool contract address that manages this token
* @return The address of the pool contract
**/
function pool() external view returns (address);

/**
* @dev Returns the reserve balance of the user that is backing the xTokens.
* @param user The user whose balance is calculated
* @return The reserve balance of the user
**/
function reserveBalanceOf(address user) external view returns (uint256);

/**
* @dev Returns the reserve total supply of the token.
* @return The reserve total supply
**/
function totalReserveSupply() external view returns (uint256);

/**
* @dev Mints `amount` xTokens to `account`
* @param account The address receiving the minted tokens
* @param amount The amount of tokens getting minted
* @param price The price at which the tokens are minted
* @param reserve The amount of reserve tokens which is backing the minted xTokens
*/
function mint(
address account,
uint256 amount,
uint256 price
uint256 reserve
) external;

/**
* @dev Burns xTokens from `account`
* @param account The owner of the xTokens, getting burned
* @param amount The amount being burned
* @param reserve The amount of reserve tokens
**/
function burn(
address account,
uint256 amount
uint256 amount,
uint256 reserve
) external;
}
Loading

0 comments on commit 71833b3

Please sign in to comment.