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, these are in the xyk-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). Plach doesn’t support Nep171.

u32. In a route, 4294967295 (u32::MAX) is the pool created last.

The message of a swap. See The message.

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

A single PoolId, 4 bytes, is read as one route of that pool. Messages from before fee discounts and referral fees moved to the engine can have a fee discount after the routes, and a Vec<(AccountId, u32)> of referral fees after that, which are read and ignored.

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
6 Launch quote_asset: AssetWithBalance, launched_asset: AssetWithBalance, fees: CurrentFees, fee_configuration: FeeConfiguration, phantom_liquidity: u128
7 Public assets: (AssetWithBalance, AssetWithBalance), fees: CurrentFees, fee_configuration: FeeConfiguration, total_shares: Option<u128>, reinvest_share_growth: Option<ShareGrowth>
  • 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.
  • reinvest_share_growth is how many shares one share of the providers who reinvest has grown into, times 10^18. It starts at 10^18. A ShareGrowth is a 256-bit number, as two u128s: the high half, then the low half. A reinvesting provider’s shares are what it had when it last collected, times this growth now, divided by the growth then: get_pool_shares already does this. It’s None only in views of older events.

Events from before the current version have the variants 0 to 3 and 5. In variants 0 to 3, the FeeConfiguration 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
5 Public as variant 7, without reinvest_share_growth

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>

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