pontem-network / liquidswap

AMM core smart contracts
Other
169 stars 73 forks source link

[Question] convert move struct LiquidityPool to Rust struct #128

Closed crazybits closed 2 years ago

crazybits commented 2 years ago

how can i convert the following Pontem liquidity move struct to Rust any sample for reference?so i can convert this resource to Rust struct.

struct LiquidityPool<phantom X, phantom Y, phantom Curve> has key {
        coin_x_reserve: Coin<X>,
        coin_y_reserve: Coin<Y>,
        last_block_timestamp: u64,
        last_price_x_cumulative: u128,
        last_price_y_cumulative: u128,
        lp_mint_cap: coin::MintCapability<LP<X, Y, Curve>>,
        lp_burn_cap: coin::BurnCapability<LP<X, Y, Curve>>,
        // Scales are pow(10, token_decimals).
        x_scale: u64,
        y_scale: u64,
        locked: bool,
        fee: u64,           // 1 - 100 (0.01% - 1%)
        dao_fee: u64,       // 0 - 100 (0% - 100%)
    }
borispovod commented 2 years ago

Hey,

Not sure the question is clear for me.

You can look how struct looks if you request it directly from API - link.

And maybe try to convert in the same way.

crazybits commented 2 years ago

API returned value are json format, actually, i would like to know how the LiquidityPool struct(with generic and phantom type) save on Aptos state DB, if i wanner deserialize LiquidityPool from raw bytes into Rust struct, how to define the Rust struct of the LiquidityPool?

borispovod commented 2 years ago

@crazybits i think you have to look into Aptos code base and BCS (Binary Canonical Serialization).

crazybits commented 2 years ago

already solved the problem ,case closed, thanks