Skip to main content

bex

Abstract​

This document specifies the x/bex module, which allows defining coin exchange pairs for Guru station.

This module has been designed to define exchange pairs with liquidity and exchange rates for coin exchange operation through Guru station.

For enabling the coin exchange through Guru station, the exchange pairs need to be registered in the x/bex module by the exchange admins and liquidity must be maintained.

Contents​

  1. Concepts
  2. State
  3. Keeper
  4. Hooks
  5. Events
  6. Clients

Concepts​

Exchanges​

The Exchange defines the type for registering the coin pairs for enabling the inter-chain exchanges through Guru station.

Registering Exchanges​

The admins can register new exchanges and maintain them. The basic exchange structure is as follows:

{
"id": "1",
"attributes": [
{
"key": "attributeKey",
"value": "attrfibuteValue"
}
...
]
}

Required attributes for registering a new exchange:

  • admin_address: admin address hosuld be same as the sender
  • reserve_address: account address for maintaining the liquidity for the pair
  • coin_a_ibc_denom: IBC denom for the first coin (ibc/F3CAC1552411B7B2B093AE360B0AD88DD672B8E2DDB4EF055AC25F8FCC5308B3)
  • coin_a_short_denom: short denom for the first coin (ausgx)
  • coin_b_ibc_denom: IBC denom for the secodn coin
  • coin_b_short_denom: short deno for the second coin
  • coin_a_port: first coin IBC port (exchange)
  • coin_b_port: first coin IBC channel (channel-0)
  • coin_a_channel: second coin IBC port
  • coin_b_channel: second coin IBC channel
  • a_to_b_rate: exchange rate from first to second coin
  • b_to_a_rate: exchange rate froms econd to first coin

Roles​

  • moderator: has right for registering and managing the admins
  • admin: has the right for registering and managing the exchanges

State​

The x/bex module keeps in the state variables for maintaining the exchanges history:

DescriptionKeyValueStore
ModeratorAddressmodule moderator address[]byte{1}[]byte{string}KV
ExchangesList fo available exchanges[]byte{2}[]ExchnageKV

Genesis​

Moderator Address​

If the moderator_address is not defined at the genesis state, the gov module address is defined as the default moderator.

Keeper​

The x/bex module provides this exported keeper that can be passed to other modules, which require access to exchanges.

type Keeper interface {
GetModeratorAddress(ctx sdk.Context) string
GetRatemeter(ctx sdk.Context) (*types.Ratemeter, error)
GetExchange(ctx sdk.Context, id math.Int) (*types.Exchange, error)
GetPaginatedExchanges(ctx sdk.Context, pagination *query.PageRequest) ([]types.Exchange, *query.PageResponse, error)
GetExchangeAttribute(ctx sdk.Context, id math.Int, key string) (types.Attribute, error)
GetNextExchangeId(ctx sdk.Context) math.Int
GetPaginatedAdmins(ctx sdk.Context, pagination *query.PageRequest) ([]string, *query.PageResponse, error)
IsAdminRegistered(ctx sdk.Context, adminAddr string) bool
}

Hooks​

The bex module implements the AfterOracleEnd hooks from the x/oracle module.

The hook is used to update the bex module state by resetting the exchange rates for the pairs.

Events​

The x/bex module emits the following events:

MsgRegisterAdmin​

TypeAttribute KeyAttribute Value
register_adminmoderator{moderatorAddress}
register_adminadmin{adminAddress}

MsgRemoveAdmin​

TypeAttribute KeyAttribute Value
remove_adminmoderator{moderatorAddress}
remove_adminadmin{adminAddress}

MsgRegisterExchange​

TypeAttribute KeyAttribute Value
register_exchangeadmin{adminAddress}
register_exchangeexchange_id{exchangeId}

MsgUpdateExchange​

TypeAttribute KeyAttribute Value
update_exchangeadmin{adminAddress}
update_exchangeexchange_id{exchangeId}

MsgChangeModerator​

TypeAttribute KeyAttribute Value
change_moderator_addressmoderator{moderatorAddress}
change_moderator_addressaddress{newModeratorAddress}

Clients​

CLI​

A user can query and interact with the bex module using the CLI.

Queries​

The query commands allow users to query bex state.

CommandSubcommandDescription
query bexexchangesGet all exchanges
query bexadminsGet all admins
query bexis_admins [address]Check if the address is admin
query bexnext_exchange_idGet next exchange id
query bexmoderator_addressGet current moderator address

Transactions​

The tx commands allow the moderator ad admins to change the bex state.

CommandSubcommandDescription
tx bexregister_exchangeRegister new exchange from json file
tx bexupdate_exchangeupdate existing exhcnage
tx bexregister_adminRegister new admin
tx bexremove_adminRemove existing admin
tx bexupdate_ratemeterUpdate the ratemeter params
tx bexchange_moderatorChange the moderator address