Skip to main content

SettlementTokenRegistry.sol

SettlementTokenRegistry

struct SettlementTokenRegistry {
EnumerableSet.AddressSet _tokens;
mapping(address => address) _oracleProviders;
mapping(address => InterestRate.Record[]) _interestRateRecords;
mapping(address => uint256) _minimumMargins;
mapping(address => uint256) _flashLoanFeeRates;
mapping(address => uint256) _earningDistributionThresholds;
mapping(address => uint24) _uniswapFeeTiers;
}

A registry for managing settlement tokens and their associated parameters.

NameTypeDescription
_tokensEnumerableSet.AddressSetSet of registered settlement tokens
_oracleProvidersmapping(address => address)Mapping of settlement tokens to their oracle provider address
_interestRateRecordsmapping(address => InterestRate.Record[])Mapping of settlement tokens to their interest rate records
_minimumMarginsmapping(address => uint256)Mapping of settlement tokens to their minimum margins
_flashLoanFeeRatesmapping(address => uint256)Mapping of settlement tokens to their flash loan fee rates
_earningDistributionThresholdsmapping(address => uint256)Mapping of settlement tokens to their earning distribution thresholds
_uniswapFeeTiersmapping(address => uint24)Mapping of settlement tokens to their Uniswap fee tiers

SettlementTokenRegistryLib

Library for managing the settlement token registry.

registeredOnly

modifier registeredOnly(struct SettlementTokenRegistry self, address token)

Modifier to check if a token is registered in the settlement token registry.

Throws an error with the code Errors.UNREGISTERED_TOKEN if the settlement token is not registered.

  • Parameters:

    NameTypeDescription
    selfstruct SettlementTokenRegistryThe SettlementTokenRegistry storage.
    tokenaddressThe address of the token to check.

register

function register(struct SettlementTokenRegistry self, address token, address oracleProvider, uint256 minimumMargin, uint256 interestRate, uint256 flashLoanFeeRate, uint256 earningDistributionThreshold, uint24 uniswapFeeTier) internal

Registers a token in the settlement token registry.

Throws an error with the code Errors.ALREADY_REGISTERED_TOKEN if the settlement token is already registered.

  • Parameters:

    NameTypeDescription
    selfstruct SettlementTokenRegistryThe SettlementTokenRegistry storage.
    tokenaddressThe address of the token to register.
    oracleProvideraddressThe oracle provider address for the token.
    minimumMarginuint256The minimum margin for the token.
    interestRateuint256The initial interest rate for the token.
    flashLoanFeeRateuint256The flash loan fee rate for the token.
    earningDistributionThresholduint256The earning distribution threshold for the token.
    uniswapFeeTieruint24The Uniswap fee tier for the token.

settlementTokens

function settlementTokens(struct SettlementTokenRegistry self) internal view returns (address[])

Returns an array of all registered settlement tokens.

  • Parameters:

    NameTypeDescription
    selfstruct SettlementTokenRegistryThe SettlementTokenRegistry storage.
  • Return Values:

    NameTypeDescription
    [0]address[]An array of addresses representing the registered settlement tokens.

isRegistered

function isRegistered(struct SettlementTokenRegistry self, address token) internal view returns (bool)

Checks if a token is registered in the settlement token registry.

  • Parameters:

    NameTypeDescription
    selfstruct SettlementTokenRegistryThe SettlementTokenRegistry storage.
    tokenaddressThe address of the token to check.
  • Return Values:

    NameTypeDescription
    [0]boolbool Whether the token is registered.

getOracleProvider

function getOracleProvider(struct SettlementTokenRegistry self, address token) internal view returns (address)

Retrieves the oracle provider address for a settlement token.

  • Parameters:

    NameTypeDescription
    selfstruct SettlementTokenRegistryThe SettlementTokenRegistry storage.
    tokenaddressThe address of the settlement token.
  • Return Values:

    NameTypeDescription
    [0]addressaddress The oralce provider address for the settlement token.

setOracleProvider

function setOracleProvider(struct SettlementTokenRegistry self, address token, address oracleProvider) internal

Sets the oracle provider address for a settlement token.

  • Parameters:

    NameTypeDescription
    selfstruct SettlementTokenRegistryThe SettlementTokenRegistry storage.
    tokenaddressThe address of the settlement token.
    oracleProvideraddressThe new oracle provider address for the settlement token.

getMinimumMargin

function getMinimumMargin(struct SettlementTokenRegistry self, address token) internal view returns (uint256)

Retrieves the minimum margin for a settlement token.

  • Parameters:

    NameTypeDescription
    selfstruct SettlementTokenRegistryThe SettlementTokenRegistry storage.
    tokenaddressThe address of the settlement token.
  • Return Values:

    NameTypeDescription
    [0]uint256uint256 The minimum margin for the settlement token.

setMinimumMargin

function setMinimumMargin(struct SettlementTokenRegistry self, address token, uint256 minimumMargin) internal

Sets the minimum margin for a settlement token.

  • Parameters:

    NameTypeDescription
    selfstruct SettlementTokenRegistryThe SettlementTokenRegistry storage.
    tokenaddressThe address of the settlement token.
    minimumMarginuint256The new minimum margin for the settlement token.

getFlashLoanFeeRate

function getFlashLoanFeeRate(struct SettlementTokenRegistry self, address token) internal view returns (uint256)

Retrieves the flash loan fee rate for a settlement token.

  • Parameters:

    NameTypeDescription
    selfstruct SettlementTokenRegistryThe SettlementTokenRegistry storage.
    tokenaddressThe address of the settlement token.
  • Return Values:

    NameTypeDescription
    [0]uint256uint256 The flash loan fee rate for the settlement token.

setFlashLoanFeeRate

function setFlashLoanFeeRate(struct SettlementTokenRegistry self, address token, uint256 flashLoanFeeRate) internal

Sets the flash loan fee rate for a settlement token.

  • Parameters:

    NameTypeDescription
    selfstruct SettlementTokenRegistryThe SettlementTokenRegistry storage.
    tokenaddressThe address of the settlement token.
    flashLoanFeeRateuint256The new flash loan fee rate for the settlement token.

getEarningDistributionThreshold

function getEarningDistributionThreshold(struct SettlementTokenRegistry self, address token) internal view returns (uint256)

Retrieves the earning distribution threshold for a settlement token.

  • Parameters:

    NameTypeDescription
    selfstruct SettlementTokenRegistryThe SettlementTokenRegistry storage.
    tokenaddressThe address of the settlement token.
  • Return Values:

    NameTypeDescription
    [0]uint256uint256 The earning distribution threshold for the token.

setEarningDistributionThreshold

function setEarningDistributionThreshold(struct SettlementTokenRegistry self, address token, uint256 earningDistributionThreshold) internal

Sets the earning distribution threshold for a settlement token.

  • Parameters:

    NameTypeDescription
    selfstruct SettlementTokenRegistryThe SettlementTokenRegistry storage.
    tokenaddressThe address of the settlement token.
    earningDistributionThresholduint256The new earning distribution threshold for the settlement token.

getUniswapFeeTier

function getUniswapFeeTier(struct SettlementTokenRegistry self, address token) internal view returns (uint24)

Retrieves the Uniswap fee tier for a settlement token.

  • Parameters:

    NameTypeDescription
    selfstruct SettlementTokenRegistryThe SettlementTokenRegistry storage.
    tokenaddressThe address of the settlement token.
  • Return Values:

    NameTypeDescription
    [0]uint24uint24 The Uniswap fee tier for the settlement token.

setUniswapFeeTier

function setUniswapFeeTier(struct SettlementTokenRegistry self, address token, uint24 uniswapFeeTier) internal

Sets the Uniswap fee tier for a settlement token.

  • Parameters:

    NameTypeDescription
    selfstruct SettlementTokenRegistryThe SettlementTokenRegistry storage.
    tokenaddressThe address of the settlement token.
    uniswapFeeTieruint24The new Uniswap fee tier for the settlement token.

appendInterestRateRecord

function appendInterestRateRecord(struct SettlementTokenRegistry self, address token, uint256 annualRateBPS, uint256 beginTimestamp) internal

Appends an interest rate record for a settlement token.

Throws an error if the settlement token is not registered.

  • Parameters:

    NameTypeDescription
    selfstruct SettlementTokenRegistryThe SettlementTokenRegistry storage.
    tokenaddressThe address of the settlement token.
    annualRateBPSuint256The annual interest rate in basis points.
    beginTimestampuint256The timestamp when the interest rate begins.

removeLastInterestRateRecord

function removeLastInterestRateRecord(struct SettlementTokenRegistry self, address token) internal returns (bool removed, struct InterestRate.Record record)

Removes the last interest rate record for a settlement token.

The current time must be less than the begin timestamp of the last record. Throws an error with the code Errors.INTEREST_RATE_ALREADY_APPLIED if not. Throws an error if the settlement token is not registered.

  • Parameters:

    NameTypeDescription
    selfstruct SettlementTokenRegistryThe SettlementTokenRegistry storage.
    tokenaddressThe address of the settlement token.
  • Return Values:

    NameTypeDescription
    removedboolWhether the removal was successful
    recordstruct InterestRate.RecordThe removed interest rate record.

currentInterestRate

function currentInterestRate(struct SettlementTokenRegistry self, address token) internal view returns (uint256 annualRateBPS)

Retrieves the current interest rate for a settlement token.

Throws an error if the settlement token is not registered.

  • Parameters:

    NameTypeDescription
    selfstruct SettlementTokenRegistryThe SettlementTokenRegistry storage.
    tokenaddressThe address of the settlement token.
  • Return Values:

    NameTypeDescription
    annualRateBPSuint256The current annual interest rate in basis points.

calculateInterest

function calculateInterest(struct SettlementTokenRegistry self, address token, uint256 amount, uint256 from, uint256 to) internal view returns (uint256)

Calculates the interest accrued for a settlement token within a specified time range.

Throws an error if the token is not registered.

  • Parameters:

    NameTypeDescription
    selfstruct SettlementTokenRegistryThe SettlementTokenRegistry storage.
    tokenaddressThe address of the settlement token.
    amountuint256The amount of settlement tokens to calculate interest for.
    fromuint256The starting timestamp of the interest calculation (inclusive).
    touint256The ending timestamp of the interest calculation (exclusive).
  • Return Values:

    NameTypeDescription
    [0]uint256uint256 The calculated interest amount.

getInterestRateRecords

function getInterestRateRecords(struct SettlementTokenRegistry self, address token) internal view returns (struct InterestRate.Record[])

Retrieves the array of interest rate records for a settlement token.

  • Parameters:

    NameTypeDescription
    selfstruct SettlementTokenRegistryThe SettlementTokenRegistry storage.
    tokenaddressThe address of the settlement token.
  • Return Values:

    NameTypeDescription
    [0]struct InterestRate.Record[]The array of interest rate records.