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.
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.
SwapArgs
Section titled “SwapArgs”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.
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 |
Use the Latest variants for new pools.
FeeConfiguration
Section titled “FeeConfiguration”| Index | Variant | Fields |
|---|---|---|
| 0 | V1 |
receivers: Vec<(FeeReceiver, u32)> |
| 1 | V2 |
receivers: Vec<(FeeReceiver, FeeAmount)> |
FeeReceiver
Section titled “FeeReceiver”| Index | Variant | Fields |
|---|---|---|
| 0 | Account |
AccountId |
| 1 | Pool |
|
| 2 | Community |
AccountId |
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)>,}For launch pools, the first asset is the quote asset. See Create a pool.
PoolView
Section titled “PoolView”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 |
AssetWithBalanceisasset_id: AssetId,balance: u128.CurrentFeesisreceivers: Vec<(FeeReceiver, u32)>: the fees of a swap right now, with the protocol fee last. A referral fee isn’t included.fee_configurationis the pool’s own configuration, without the protocol fee.Launchis a V1 launch pool, always quoted in NEAR. The balance of NEAR isnear_amount.total_sharesisNonewhen all liquidity was removed.
ReferralFees
Section titled “ReferralFees”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%).
Arguments of calls and views
Section titled “Arguments of calls and views”| 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).