diff --git a/precompile/binaries/minlib/dex.mv b/precompile/binaries/minlib/dex.mv index 2b02537a..23faf031 100644 Binary files a/precompile/binaries/minlib/dex.mv and b/precompile/binaries/minlib/dex.mv differ diff --git a/precompile/binaries/stdlib/dex.mv b/precompile/binaries/stdlib/dex.mv index 2b02537a..23faf031 100644 Binary files a/precompile/binaries/stdlib/dex.mv and b/precompile/binaries/stdlib/dex.mv differ diff --git a/precompile/modules/initia_stdlib/sources/dex.move b/precompile/modules/initia_stdlib/sources/dex.move index 50dd2f86..cbc3edf4 100644 --- a/precompile/modules/initia_stdlib/sources/dex.move +++ b/precompile/modules/initia_stdlib/sources/dex.move @@ -119,6 +119,11 @@ module initia_std::dex { coin_b_weight: Decimal128, } + struct PairMetadataResponse has drop { + coin_a_metadata: Object, + coin_b_metadata: Object, + } + #[event] struct CreatePairEvent has drop, store { coin_a: address, @@ -198,25 +203,17 @@ module initia_std::dex { const MAX_FEE_RATE: u128 = 50_000_000_000_000_000; // 5% #[view] - public fun pool_info(pair: Object, lbp_assertion: bool): (u64, u64, Decimal128, Decimal128, Decimal128) acquires Config, Pool { - let pair_addr = object::object_address(pair); - let config = borrow_global(pair_addr); - if (lbp_assertion) { - // assert LBP start time - let (_, timestamp) = get_block_info(); - assert!(timestamp >= config.weights.weights_before.timestamp, error::invalid_state(ELBP_NOT_STARTED)); - }; - - let pool = borrow_global(pair_addr); - let (coin_a_weight, coin_b_weight) = get_weight(&config.weights); + public fun get_pair_metadata( + pair: Object, + ): PairMetadataResponse acquires Pool { + let pool = borrow_global_mut(object::object_address(pair)); + let coin_a_metadata = fungible_asset::store_metadata(pool.coin_a_store); + let coin_b_metadata = fungible_asset::store_metadata(pool.coin_b_store); - ( - fungible_asset::balance(pool.coin_a_store), - fungible_asset::balance(pool.coin_b_store), - coin_a_weight, - coin_b_weight, - config.swap_fee_rate, - ) + PairMetadataResponse { + coin_a_metadata, + coin_b_metadata, + } } #[view] @@ -1186,6 +1183,28 @@ module initia_std::dex { } } + /// get all pool info at once (a_amount, b_amount, a_weight, b_weight, fee_rate) + public fun pool_info(pair: Object, lbp_assertion: bool): (u64, u64, Decimal128, Decimal128, Decimal128) acquires Config, Pool { + let pair_addr = object::object_address(pair); + let config = borrow_global(pair_addr); + if (lbp_assertion) { + // assert LBP start time + let (_, timestamp) = get_block_info(); + assert!(timestamp >= config.weights.weights_before.timestamp, error::invalid_state(ELBP_NOT_STARTED)); + }; + + let pool = borrow_global(pair_addr); + let (coin_a_weight, coin_b_weight) = get_weight(&config.weights); + + ( + fungible_asset::balance(pool.coin_a_store), + fungible_asset::balance(pool.coin_b_store), + coin_a_weight, + coin_b_weight, + config.swap_fee_rate, + ) + } + /// Calculate out amount /// https://balancer.fi/whitepaper.pdf (15) /// return (return_amount, fee_amount) diff --git a/precompile/modules/minitia_stdlib/sources/dex.move b/precompile/modules/minitia_stdlib/sources/dex.move index ea0cf44c..412a2b7f 100644 --- a/precompile/modules/minitia_stdlib/sources/dex.move +++ b/precompile/modules/minitia_stdlib/sources/dex.move @@ -119,6 +119,11 @@ module minitia_std::dex { coin_b_weight: Decimal128, } + struct PairMetadataResponse has drop { + coin_a_metadata: Object, + coin_b_metadata: Object, + } + #[event] struct CreatePairEvent has drop, store { coin_a: address, @@ -198,25 +203,17 @@ module minitia_std::dex { const MAX_FEE_RATE: u128 = 50_000_000_000_000_000; // 5% #[view] - public fun pool_info(pair: Object, lbp_assertion: bool): (u64, u64, Decimal128, Decimal128, Decimal128) acquires Config, Pool { - let pair_addr = object::object_address(pair); - let config = borrow_global(pair_addr); - if (lbp_assertion) { - // assert LBP start time - let (_, timestamp) = get_block_info(); - assert!(timestamp >= config.weights.weights_before.timestamp, error::invalid_state(ELBP_NOT_STARTED)); - }; - - let pool = borrow_global(pair_addr); - let (coin_a_weight, coin_b_weight) = get_weight(&config.weights); + public fun get_pair_metadata( + pair: Object, + ): PairMetadataResponse acquires Pool { + let pool = borrow_global_mut(object::object_address(pair)); + let coin_a_metadata = fungible_asset::store_metadata(pool.coin_a_store); + let coin_b_metadata = fungible_asset::store_metadata(pool.coin_b_store); - ( - fungible_asset::balance(pool.coin_a_store), - fungible_asset::balance(pool.coin_b_store), - coin_a_weight, - coin_b_weight, - config.swap_fee_rate, - ) + PairMetadataResponse { + coin_a_metadata, + coin_b_metadata, + } } #[view] @@ -1186,6 +1183,28 @@ module minitia_std::dex { } } + /// get all pool info at once (a_amount, b_amount, a_weight, b_weight, fee_rate) + public fun pool_info(pair: Object, lbp_assertion: bool): (u64, u64, Decimal128, Decimal128, Decimal128) acquires Config, Pool { + let pair_addr = object::object_address(pair); + let config = borrow_global(pair_addr); + if (lbp_assertion) { + // assert LBP start time + let (_, timestamp) = get_block_info(); + assert!(timestamp >= config.weights.weights_before.timestamp, error::invalid_state(ELBP_NOT_STARTED)); + }; + + let pool = borrow_global(pair_addr); + let (coin_a_weight, coin_b_weight) = get_weight(&config.weights); + + ( + fungible_asset::balance(pool.coin_a_store), + fungible_asset::balance(pool.coin_b_store), + coin_a_weight, + coin_b_weight, + config.swap_fee_rate, + ) + } + /// Calculate out amount /// https://balancer.fi/whitepaper.pdf (15) /// return (return_amount, fee_amount)