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, 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, 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. In a route, 4294967295 (u32::MAX) is the pool created last.

The key of set_fee_discount_signer and get_fee_discount_signer. In Borsh it’s a Vec<u8>: a u32 length (33 for Ed25519, 65 for secp256k1), then the curve (0 for Ed25519, 1 for secp256k1) and the key. near-api-js and near-primitives write a key without the length, so their layout doesn’t work here.

The message of a swap. See The message.

struct SwapArgs {
routes: Vec<SwapRoute>,
fee_discount: Option<SignedFeeDiscount>,
}
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. Messages from before referral fees moved to the engine can have a Vec<(AccountId, u32)> of them after fee_discount, which is read and ignored. 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
9 PublicV3

Use the Latest variants for new pools. The others create a pool of the current version of their kind too. See Older pool types.

A struct, receivers: Vec<(FeeReceiver, FeeAmount)>. In Rust it’s FeeConfigurationV2. It used to be an enum of V1 and V2 with a variant index first, which is only in older events now.

Index Variant Fields
1 Pool
3 Account account_id: AccountId, payout_type: FeePayoutType, claim_mode: ClaimMode
4 Protocol Only in the fees of a swap, never in a fee configuration

Indexes 0 and 2 are the receivers of older versions, Account(AccountId) and Community(AccountId). Plach still reads them, as an Account with KeepBoth and OnlyOwner, and with KeepBoth and Anyone, but never writes them.

Index Variant
0 KeepBoth
1 ConvertToFirstAsset
2 ConvertToSecondAsset
3 Reinvest, only for liquidity providers

See The asset a fee is paid in.

Index Variant
0 OnlyOwner
1 Anyone

See Collected fees.

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)>,
creator_fee_payout_type: Option<FeePayoutType>,
}

For launch pools, the first asset is the quote asset. creator_fee_payout_type is required for public pools, and must be None for others. See Create a pool.

What get_pool and get_pools return, and PoolUpdated events carry.

Index Variant Fields
4 Private assets: (AssetWithBalance, AssetWithBalance), fees: CurrentFees, fee_configuration: FeeConfiguration, owner_id: AccountId, locked: bool
5 Public assets: (AssetWithBalance, AssetWithBalance), fees: CurrentFees, fee_configuration: FeeConfiguration, total_shares: Option<u128>
6 Launch 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, each receiver’s share after the protocol fee, and the protocol fee last, as Protocol.
  • fee_configuration is the pool’s own configuration, before the protocol takes its share.
  • A Launch pool’s quote balance includes the phantom liquidity.
  • total_shares is None when all liquidity was removed.

Events from before the current version have the variants 0 to 3, with a FeeConfiguration that starts with its variant index (0 for V1, a Vec<(FeeReceiver, u32)>, and 1 for V2):

Index Variant Fields
0 Private as variant 4
1 Public as variant 5
2 Launch near_amount: u128, launched_asset: AssetWithBalance, fees: CurrentFees, fee_configuration, phantom_liquidity_near: u128. A launch pool quoted in NEAR
3 LaunchV2 as variant 6

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 Liquidity.

Struct Fields
GetPoolArgs, RegisterLiquidityArgs, LockPoolArgs, 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
SetLiquidityFeePayoutArgs pool_id: PoolId, payout_type: FeePayoutType
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>
GetPendingFeesArgs, GetClaimableFeesArgs, ClaimFeesArgs account_id: AccountId, asset_ids: Vec<AssetId>
SetFeeDiscountSignerArgs fee_discount_signer_public_key: Option<PublicKey>

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