Exchange Rate

Deployed at: terra1zvsv534gx7xppq4yfstslmsgc3jmkfak4mlrv4

state.rs

Stores all relevant contract parameters.

pub struct Config {
    pub owner: HumanAddr,
}

owner: the owner address of this contract.

pub struct Token {
    pub status: Status,
    pub exchange_rate: Decimal256,
    pub epoch_period: u64,
    pub weight: Decimal256,
    pub last_updated_at: u64,
}

status: virtual exchange rate enforcement status - Neutral, Running, or Stopped

  • Neutral: logic not yet initialized, throws an error when queried

  • Running: exchange rate calculations valid, returns current exchange_rate when queried & executes update

  • Stopped: exchange rate no longer updating, returns a constant value when queried

exchange_rate: current virtual exchange rate for this pool

epoch_period: minimum time gap between update() calls.

contract.rs

Defines logic entry points for InitMsg, HandleMsg and QueryMsg calls.

Initializes a new Exchange Rate contract.

Defines HandleMsg endpoints. Calls the following functions per HandleMsg:

Update { token } : calls update(deps, env, token) defined under handler_exec.rs.

ConfigToken { token, exchange_rate, epoch_period, weight, } : calls config_token(deps, env, token, exchange_rate, epoch_period, weight, ) defined under handler_exec.rs.

AddToken { token, base_rate, period, weight, } : calls add_token(deps, env, token, base_rate, period, weight, ) defined under handler_exec.rs.

Start { tokens } : calls start(deps, env, tokens) defined under handler_exec.rs.

Stop { tokens } : calls stop(deps, env, tokens) defined under handler_exec.rs.

Defines QueryMsg endpoints. Calls the following functions per QueryMsg:

ExchangeRateOf { token, blocktime } : calls exchange_rate_of(deps, &token, blocktime) defined under handler_query.rs; Queries the current exchange_rate for token.

handler_exec.rs

Defines core contract execution logic. Functions are as follows:

update: recalculates the current virtual exchange rate for token.

config_token: updates target token profile for calculating virtual exchange rate.

add_token: adds a new target token profile for calculating virtual exchange rate.

start: enables virtual exchange rate calculation.

stop: disables virtual exchange rate calculation.

Recalculates virtual exchange rate for a particular token.

exchange_rate is calculated as:

  • count how many epochs have elapsed since last_updated_at

    • do nothing if at least one epoch has not passed

  • exchange_rate = exchange_rate * weight ^ epochs_passed

Updates virtual exchange rate parameters for token. Accepts:

  • token: address of the target token subject to exchange rate updates.

  • exchange_rate: initial exchange rate parameter to be used as a baseline. should be reset on significant deviation.

  • epoch_period: time length of a single epoch used for update calls.

  • weight: exchange rate delta enforced per epoch.

Adds a new token target profile for calculating exchange_rate. Accepts:

  • token: address of the target token subject to exchange rate updates.

  • exchange_rate: initial exchange rate parameter to be used as a baseline. should be reset on significant deviation.

  • epoch_period: time length of a single epoch used for update calls.

  • weight: exchange rate delta enforced per epoch.

Changes token.status to Running for all tokens registered with the Exchange Rate contract.

Changes token.status to Stopped for all tokens registered with the Exchange Rate contract.

Last updated

Was this helpful?