Skip to content

Types

Qoq reads and writes Borsh. In Borsh, integers are little-endian, a Vec or a string is a u32 length and then its items, an Option is 0 for None or 1 and the value, an enum is a u8 variant index and then the variant’s fields, and a bool is one byte. Structs and tuples are their fields in order, and a HashMap is a u32 count and then its key/value pairs, sorted by key. AccountId is a string.

In Rust, these are in the amp-dex-types crate, and the types shared with the engine, like AssetId, in intear-dex-common.

AssetId, SwapRequestAmount and the other types of the engine are described in its Types. AssetId is Near (0), Nep141(AccountId) (1), Nep245(AccountId, String) (2), Nep171(AccountId, String) (3). Qoq doesn’t support Nep171.

u32, counted from 0.

u128 with 18 decimals: 1000000000000000000 is 1. The price of a whole token of a pool’s first asset in its second, or of an exchange’s price in its quote currency.

An oracle’s key: a u8 curve, 0 for Ed25519 or 1 for secp256k1, then the key’s 32 or 64 bytes, with no length. near-api-js and near-primitives write a key the same way.

The message of a swap. See The message.

struct SwapArgs {
routes: Vec<SwapRoute>,
}
struct SwapRoute {
fraction: u32, // 1000000 = 100%
pool_ids: Vec<PoolId>,
}

Messages from before fee discounts moved to the engine can have a fee discount after the routes, which is read and ignored.

What get_pool and get_pools return, and PoolUpdated events carry. A struct:

Field Type
assets (AssetWithBalance, AssetWithBalance)
decimals (u8, u8)
amplification u32
rate_source PoolRateSource
fee u32, out of 1000000
total_shares Option<u128>, None when all liquidity was removed

AssetWithBalance is asset_id: AssetId, balance: u128. See Pools.

An enum whose variant indexes start at 128, unlike the 0 of NewPoolRateSource:

Index Variant Fields
128 Oracle key: PublicKey, last_price: Price: the price of the pool’s last swap, 0 before its first
129 Fixed Price

Events from before rate sources have, instead of rate_source, the oracle as oracle_key: PublicKey and last_oracle_price: Option<Price>. Some of them also have the oracle’s fee, ((u128, u128), AccountId), between fee and total_shares. Since a PublicKey starts with 0 or 1, the first byte after amplification tells the layouts apart.

What create_pool takes. Only Qoq’s owner can call it. See Owner settings.

struct CreatePoolArgs {
assets: (AssetId, AssetId),
decimals: (u8, u8),
amplification: u32,
rate_source: NewPoolRateSource,
fee: u32,
/// The first liquidity, which the attached assets must match
initial_liquidity: (u128, u128),
/// How the owner takes its part of the pool's fees
creator_fee_payout_type: FeePayoutType,
}

NewPoolRateSource is Oracle(PublicKey) (0) or Fixed(Price) (1). It responds with CreatePoolResponse { pool_id: PoolId }.

How a liquidity provider takes its part of the pool’s fees. See Fees.

Index Variant
0 KeepBoth
1 ConvertToFirstAsset
2 ConvertToSecondAsset

Who took a fee, in a Swap event:

Index Variant Receiver
0 Pool The pool’s liquidity providers
1 Protocol Qoq’s protocol fee, qoq.intear.near
2 Oracle(AccountId) Only in events from before the engine took the fees of oracles

What get_liquidity_position returns: payout_type: FeePayoutType, uncollected_fees: (u128, u128), the fees in each of the pool’s assets that the provider hasn’t collected yet. See Fees.

The request of the OracleRequest of a swap, and what the oracle responds:

struct PricesRequest {
asset_ids: Vec<AssetId>,
}
struct PricesResponse {
exchanges: Vec<ExchangePrices>,
}
struct ExchangePrices {
exchange: String,
/// One price of a whole token for each requested asset, in their order,
/// in the exchange's quote currency
prices: Vec<Price>,
}
Struct Fields
GetPoolArgs, RegisterLiquidityArgs, CollectLiquidityFeesArgs pool_id: PoolId
GetPoolsArgs start_index: PoolId, limit: u32
GetPoolSharesArgs pool_ids: Vec<PoolId>, account_id: AccountId
GetLiquidityPositionArgs pool_id: PoolId, account_id: AccountId
AddLiquidityArgs pool_id: PoolId, min_shares_received: Option<u128>
RemoveLiquidityArgs pool_id: PoolId, shares_to_remove: Option<u128>, min_assets_received: Option<(u128, u128)>
SetLiquidityFeePayoutArgs pool_id: PoolId, payout_type: FeePayoutType
WithdrawFeesArgs assets: Vec<AssetId>
GetPendingFeesArgs account_id: AccountId, asset_ids: Vec<AssetId>
SetAmplificationArgs pool_id: PoolId, amplification: u32
SetFeeArgs pool_id: PoolId, fee: u32
SetOracleKeyArgs pool_id: PoolId, oracle_key: PublicKey

shares_to_remove can’t be Some(0).