For the complete documentation index, see llms.txt. This page is also available as Markdown.

State Update

Updates are generated after zkLinkTx execution, details can be found in StateUpdateResp. Parsing the updates can get some data that is only known after the transaction is executed, such as the actual withdraw amount of FullExit

AccountUpdate.

There are 4 types of AccountUpdate:

  1. AccountCreate: A new account created on the state tree;

  2. AccountChangePubkeyUpdate: The pubkey and nonce changed;

  3. BalanceUpdate: The assets of account and nonce changed;

  4. OrderUpdate: The order slot of the account has changed.

Name
Type
Description

type

String

Update Name

updateId

i32

Update id

accountId

The new accout id

address

String

The account address

Transaction that generate AccountCreate:

For Example:

{
  "type": "AccountCreate",
   "updateId": 40,
   "accountId": 42,
   "address": "0xe4efc3d7b69a19d3ae574cbc2915ddf598efe43f"
}
Name
Type
Description

type

String

Update name

updateId

i32

Update Id

accountId

Account id

oldPubkeyHash

The old pubkeyHash

newPubkeyHash

The new pubkeyHash

oldNonce

The old nonce

newNonce

The new nonce

Transaction that generate AccountChangePubkeyUpdate:

For example:

{
  "type": "AccountChangePubkeyUpdate",
  "updateId": 10,
  "accountId": 39,
  "oldPubkeyHash": "0x0000000000000000000000000000000000000000",
  "newPubkeyHash": "0xbfb4f4a68dc9e49f7785082a8c12354ed663b6e0",
  "oldNonce": 0,
  "newNonce": 1
}
Name
Type
Description

type

String

The update name

updateId

i32

The update id

accountId

The account id

subAccountId

The subaccount id

coinId

The token id

oldBalance

String

The old balance of subaccount

newBalance

String

The new balance of subaccount

oldNonce

The old nonce of subaccount

newNonce

The new nonce of subaccount

Transaction that generate BalanceUpdate:

For example

Name
Type
Description

type

String

Update name

updateId

i32

Update id

accountId

Account id

subAccountId

Subaccount id

slotId

Slot id

oldTidyOrder

OldTidyOrder

newTidyOrder

New TidyOrder

where ResponseTidyOrder is

Name
Type
Description

nonce

The slot nonce of order

residue

String

The string format of BigDecimal, the residue balance of slot

Transaction that generate OrderUpdate:

For Example:

GlobalVarUpdate

GlobalVarsUpdate is an enumeration type used to represent the update status of global variables. It includes the following 4 types:

  1. FeeAccountUpdate: The fee account of global variables changed

  2. InsuranceFundAccountUpdate: The Insurance fund account of global variables changed

  3. MarginParamsUpdate: The margin parameter of global variables changed

  4. ContractParamsUpdate: The contract parameter of global variables changed

Field
Type
Description

type

String

The update name

update_id

i32

update index

sub_account_id

sub-account ID

old_fee_account_id

Old fee account ID

new_fee_account_id

New fee account ID

Transaction that generate FeeAccountUpdate:

For Example:

Field
Type
Description

type

String

The update name

update_id

i32

update index

sub_account_id

sub-account id

old_insurance_fund_account_id

old insurance fund account id

new_insurance_fund_account_id

new insurance fund account id

Transaction that generate InsuranceFundAccountUpdate:

For example:

Field
Type
Description

type

String

The update name

update_id

i32

update index

sub_account_id

sub-account id

margin_id

margin index

old_symbol

String

Old symbol of the margin token

new_symbol

String

New symbol of the margin token

old_index_price

String

Old index price of the margin token

new_index_price

String

New index price of the margin token

old_token_id

Old margin token id of the margin_id

new_token_id

New margin token id of the margin_id

old_ratio

u8

Old margin ratio of the margin token

new_ratio

u8

New margin ratio of the margin token

Transaction that generate MarginParamsUpdate:

For example

Field
Type
Description

update_id

i32

update id

sub_account_id

sub-account id

pair_id

contract pair id

old_symbol

String

old symbol of the contract pair

new_symbol

String

new symbol of the contract pair

old_maintenance_margin_rate

u16

old maintenance margin rate of the contract pair

new_maintenance_margin_rate

u16

new maintenance margin rate of the contract pair

old_initial_margin_rate

u16

old initial margin rate of the contract pair

new_initial_margin_rate

u16

new initial margin rate of the contract pair

old_acc_funding_price

String

old accumulated funding price the contract pair

new_acc_funding_price

String

new accumulative funding price the contract pair

old_mark_price

String

old mark price of the contract pair

new_mark_price

String

new mark price of the contract pair

Transaction that generate ContractParamsUpdate:

For Example:

Deposit

Updates generated by Deposit:

[update]: this update may occur, update(account): the update related to a certain account. The account id of global_asset is 1, and the account id of fee is 0.

When the to account does not exist, a new account will be automatically created by AccountCreate.

Example

FullExit

Updates generated by FullExit:

Example

ChangePubKey

Updates generated by ChangePubKey:

Example

Transfer

Updates generated by Transfer:

Similar to Deposit, when the to account does not exist, a new account will be automatically created by AccountCreate.

Example

Withdraw

Updates generated by Withdraw:

Example

ForcedExit

Updates generated by ForcedExit:

Example

OrderMatching

Updates generated by OrderMatching:

Example

ContractMatching

Updates generated by ContractMatching:

Example

Liquidation

Updates generated by Liquidation:

Example

AutoDeleveraging

Updates generated by AutoDeleveraging:

Example

funding

Updates generated by funding:

Example

update_global_var

All updates that may be generated by update_global_var:

Example

version: fa4618

Last updated

Was this helpful?