Epoch Manager

The Epoch Manager is a contract which sole purpose is to create epochs on MANTRA, acting like a clock for the other contracts.

An Epoch is a period of time that is defined by the duration parameter on EpochConfig, and they are used by other contracts to take timely actions. For example, the Farm Manager uses epochs to calculate the farm rewards for its users.

How it works

The epoch configuration is set up when the contract is instantiated. The epoch configuration defines the duration of an epoch and when the genesis epoch is going to take place, i.e. the first epoch.

Once the genesis epoch is created, after the epoch duration has passed, anyone can create a new epoch by calling the CreateEpoch message. This action will create a new epoch by increasing the epoch id by one, adjust the start time for the new epoch and alert the contracts that have registered for the hook.

Epoch Hook

There are two actions that only the owner of the Epoch Manager can execute: AddHook and RemoveHook. These add or remove a contract to the HOOKS list.

These contracts must implement the EpochChangedHookMsg interface, which is the signature of the message that will be executed on the hooks when a new epoch is created. The hook contains the current Epoch, specifying the id and start_time.

#[cw_serde]
pub struct EpochChangedHookMsg {
    // The current epoch
    pub current_epoch: Epoch,
}

#[cw_serde]
#[derive(Default)]
pub struct Epoch {
    // Epoch identifier
    pub id: u64,
    // Epoch start time
    pub start_time: Timestamp,
}

Instantiate

Instantiates an instance of the epoch manager contract

{
  "start_epoch": {
    "id": 0,
    "start_time": "1571797419879305533"
  },
  "epoch_config": {
    "duration": "86400000000000",
    "genesis_epoch": "1571797419879305533"
  }
}
KeyTypeDescription

start_epoch

Epoch

The initial epoch to start the contract with

epoch_config

EpochConfig

The configuration for the epochs

ExecuteMsg

CreateEpoch

Creates a new epoch. It's permissionless. A new epoch can only be created after the current one has ended.

{
  "create_epoch": {}
}

AddHook

Adds a new hook to the hook registry, i.e. adds a contract to be notified when a new epoch is created.

{
  "add_hook": {
    "contract_addr": "mantra1..."
  }
}
KeyTypeDescription

contract_addr

String

The address of the contract to be added to the hook registry

RemoveHook

Removes a hook from the hook registry.

{
  "remove_hook": {
    "contract_addr": "mantra1..."
  }
}
KeyTypeDescription

contract_addr

String

The address of the contract to be added to the hook registry

UpdateConfig

Updates the contract configuration.

{
  "update_config": {
    "owner": "mantra1...",
    "epoch_config": {
      "duration": "86400000000000",
      "genesis_epoch": "1571797419879305533"
    }
  }
}
KeyTypeDescription

owner

Option<String>

The new owner of the contract

epoch_config

Option<EpochConfig>

The new epoch configuration

QueryMsg

Config

Returns the configuration of the contract.

{
  "config": {}
}

CurrentEpoch

Returns the current epoch, which is the last on the EPOCHS map

{
  "current_epoch": {}
}

Epoch

Returns the epoch with the given ID.

{
  "epoch": {
    "id": 100
  }
}

Hooks

Returns the hooks in the registry.

{
  "hooks": {}
}

Hook

Returns whether a hook has been registered.

{
  "hook": {
    "hook": "mantra1..."
  }
}

QueryMsg

Config

Returns the configuration of the contract.

{
  "config": {}
}

CurrentEpoch

Returns the current epoch, which is the last on the EPOCHS map.

{
  "current_epoch": {}
}

Epoch

Returns the epoch with the given id.

{
  "epoch": {
    "id": 100
  }
}

Hooks

Returns the hooks in the registry.

{
  "hooks": {}
}

Hook

Returns whether a hook has been registered.

{
  "hook": {
    "hook": "mantra1..."
  }
}

MigrateMsg

Message to migrate the contract to a new code ID.

{}

Last updated