Skip to content

Types

Plach 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, and an enum is a u8 variant index and then the variant’s fields. Structs are their fields in order. AccountId is a string.

In Rust, all of these are in the xyk-dex-types crate.

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). Plach doesn’t support Nep171.

u32.

The message of a swap. See The message.

struct SwapArgs {
routes: Vec<SwapRoute>,
fee_discount: Option<SignedFeeDiscount>,
referral_fees: ReferralFees, // left out when empty
}
struct SwapRoute {
fraction: u32, // 1000000 = 100%
pool_ids: Vec<PoolId>,
}

A single PoolId, 4 bytes, is read as one route of that pool with no fee discount and no referral fees. A message that ends after fee_discount has no referral fees. SignedFeeDiscount is in Fee discounts.

Index Variant Fields
0 PrivateLatest
1 PublicLatest
2 LaunchLatest phantom_liquidity: u128
3 LaunchV1 phantom_liquidity_near: u128
4 PrivateV1
5 PublicV1
6 PrivateV2
7 PublicV2
8 LaunchV2 phantom_liquidity: u128

Use the Latest variants for new pools.

Index Variant Fields
0 V1 receivers: Vec<(FeeReceiver, u32)>
1 V2 receivers: Vec<(FeeReceiver, FeeAmount)>
Index Variant Fields
0 Account AccountId
1 Pool
2 Community AccountId
Index Variant Fields
0 Fixed u32
1 Scheduled start: (u64, u32), end: (u64, u32), curve: ScheduledFeeCurve
2 Dynamic min: u32, max: u32. Not supported yet

ScheduledFeeCurve has one variant, Linear (0). Times are in nanoseconds. See Pool fees.

struct CreatePoolArgs {
assets: (AssetId, AssetId),
fees: FeeConfiguration,
pool_type: PoolType,
initial_liquidity: Option<(u128, u128)>,
}

For launch pools, the first asset is the quote asset. See Create a pool.

What get_pool and get_pools return, and PoolUpdated events carry.

Index Variant Fields
0 Private assets: (AssetWithBalance, AssetWithBalance), fees: CurrentFees, fee_configuration: FeeConfiguration, owner_id: AccountId, locked: bool
1 Public assets: (AssetWithBalance, AssetWithBalance), fees: CurrentFees, fee_configuration: FeeConfiguration, total_shares: Option<u128>
2 Launch near_amount: u128, launched_asset: AssetWithBalance, fees: CurrentFees, fee_configuration: FeeConfiguration, phantom_liquidity_near: u128
3 LaunchV2 quote_asset: AssetWithBalance, launched_asset: AssetWithBalance, fees: CurrentFees, fee_configuration: FeeConfiguration, phantom_liquidity: u128
  • AssetWithBalance is asset_id: AssetId, balance: u128.
  • CurrentFees is receivers: Vec<(FeeReceiver, u32)>: the fees of a swap right now, with the protocol fee last. A referral fee isn’t included.
  • fee_configuration is the pool’s own configuration, without the protocol fee.
  • Launch is a V1 launch pool, always quoted in NEAR. The balance of NEAR is near_amount.
  • total_shares is None when all liquidity was removed.

Vec<(AccountId, u32)>: the accounts a swap pays referral fees to, and the fee of each, 1000000 = 100%. At most 5 accounts, each listed once, adding up to at most 50000 (5%).

Struct Fields
GetPoolArgs, RegisterLiquidityArgs, LockPoolArgs, UpgradePoolArgs, PoolNeedsUpgradeArgs pool_id: PoolId
GetPoolsArgs start_index: PoolId, limit: PoolId
GetPoolSharesArgs pool_ids: Vec<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)>
EditFeesArgs pool_id: PoolId, fees: FeeConfiguration
RegisterFeeAssetsArgs asset_ids: Vec<AssetId>
WithdrawFeesArgs assets: Vec<AssetId>
WithdrawCommunityFeeArgs, GetCommunityOwnedFeesArgs account_id: AccountId
GetPendingFeesArgs account_id: AccountId, asset_ids: Vec<AssetId>

min_shares_received and shares_to_remove can’t be Some(0).