fluidex / rollup-state-manager

5 stars 6 forks source link

add balance details to decoded SpotTradeTx #219

Closed HAOYUatHZ closed 2 years ago

HAOYUatHZ commented 2 years ago

successor of https://github.com/fluidex/rollup-state-manager/issues/212


pub struct SpotTradeTx {
    ...
    account1_token_sell_old_balance
    account1_token_sell_new_balance

    account1_token_buy_old_balance
    account1_token_buy_new_balance

    account2_token_buy_old_balance
    account2_token_buy_new_balance

    account2_token_buy_old_balance
    account2_token_buy_new_balance
}
in rust struct data
account1_token_sell_old_balance order1TokenSellBalance
account1_token_sell_new_balance order1TokenSellBalance - amount_1to2
account1_token_buy_old_balance order1TokenBuyBalance
account1_token_buy_new_balance order1TokenBuyBalance + amount_2to1
account2_token_sell_old_balance order2TokenSellBalance
account2_token_sell_new_balance order2TokenSellBalance - amount_2to1
account2_token_buy_old_balance order2TokenBuyBalance
account2_token_buy_new_balance order2TokenBuyBalance + amount_1to2
data in tx_data.ts
order1TokenSellBalance balance1
order2TokenBuyBalance balance2 - amount
order2TokenSellBalance balance3
order1TokenBuyBalance balance4 - amount2
data in tx_data.ts
amount_1to2 amount
amount_2to1 amount2

conclusion(!!!):

in rust struct in tx_data.rs
account1_token_sell_old_balance balance1
account1_token_sell_new_balance balance1 - amount
account1_token_buy_old_balance balance4 - amount2
account1_token_buy_new_balance balance4
account2_token_sell_old_balance balance3
account2_token_sell_new_balance balance3 - amount2
account2_token_buy_old_balance balance2 - amount
account2_token_buy_new_balance balance2

Future work

Note that this is only compatible before https://github.com/fluidex/circuits/pull/189 After https://github.com/fluidex/circuits/pull/189, the amount is changed to amount1.