Types
This page is also Markdown, for agents: /plach/reference/types.md, and /llms.txt lists every page.
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.
Shared with the engine
Section titled “Shared with the engine”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.
PoolId
Section titled “PoolId”u32. In a route, 4294967295 (u32::MAX) is the pool created last.
SwapArgs
Section titled “SwapArgs”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.
PoolType
Section titled “PoolType”| 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.
FeeConfiguration
Section titled “FeeConfiguration”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.
FeeReceiver
Section titled “FeeReceiver”| 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.
FeePayoutType
Section titled “FeePayoutType”| Index | Variant |
|---|---|
| 0 | KeepBoth |
| 1 | ConvertToFirstAsset |
| 2 | ConvertToSecondAsset |
| 3 | Reinvest, only for liquidity providers |
See The asset a fee is paid in.
ClaimMode
Section titled “ClaimMode”| Index | Variant |
|---|---|
| 0 | OnlyOwner |
| 1 | Anyone |
See Collected fees.
FeeAmount
Section titled “FeeAmount”| 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.
CreatePoolArgs
Section titled “CreatePoolArgs”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.
PoolView
Section titled “PoolView”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> |
AssetWithBalanceisasset_id: AssetId,balance: u128.CurrentFeesisreceivers: Vec<(FeeReceiver, u32)>: the fees of a swap right now, each receiver’s share after the protocol fee, and the protocol fee last, asProtocol.fee_configurationis the pool’s own configuration, before the protocol takes its share.- A
Launchpool’s quote balance includes the phantom liquidity. total_sharesisNonewhen all liquidity was removed.reinvest_share_growthis how many shares one share of the providers who reinvest has grown into, times 10^18. It starts at 10^18. AShareGrowthis a 256-bit number, as twou128s: 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_sharesalready does this. It’sNoneonly in views of older events.
Older pool views
Section titled “Older pool views”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 |
LiquidityPositionView
Section titled “LiquidityPositionView”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.
Arguments of calls and views
Section titled “Arguments of calls and views”| 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).