From 69f9bb849e08b71f0449945d2bcee47f79fd2606 Mon Sep 17 00:00:00 2001 From: jolestar Date: Tue, 21 Jan 2025 18:06:55 +0800 Subject: [PATCH] add admin util --- apps/rooch_dex/Move.toml | 5 ++++ apps/rooch_dex/sources/admin_util.move | 30 +++++++++++++++++++ .../sources/liquidity_incentive.move | 2 +- crates/testsuite/features/dex.feature | 2 +- 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 apps/rooch_dex/sources/admin_util.move diff --git a/apps/rooch_dex/Move.toml b/apps/rooch_dex/Move.toml index 3a32d4fde7..0d4d0e5bca 100644 --- a/apps/rooch_dex/Move.toml +++ b/apps/rooch_dex/Move.toml @@ -14,3 +14,8 @@ app_admin = "_" std = "0x1" moveos_std = "0x2" rooch_framework = "0x3" + +[dev-addresses] +rooch_dex = "0x42" +app_admin = "0x43" + diff --git a/apps/rooch_dex/sources/admin_util.move b/apps/rooch_dex/sources/admin_util.move new file mode 100644 index 0000000000..3f7064ee7f --- /dev/null +++ b/apps/rooch_dex/sources/admin_util.move @@ -0,0 +1,30 @@ +module rooch_dex::admin_util { + + use moveos_std::object::{Object}; + use moveos_std::signer; + use app_admin::admin::AdminCap; + use rooch_dex::liquid_xp::LiquidXP; + use rooch_dex::liquidity_incentive::{Self, FarmingAsset}; + + struct Witness{} + + //any account with AdminCap can call this function to create LiquidXP incentive + public entry fun create_xp_incentive_pool( + release_per_second: u128, + coin_amount: u256, + start_time_in_seconds: u64, + _admin_cap: &mut Object, + ){ + let module_signer = signer::module_signer(); + liquidity_incentive::create_pool(&module_signer, release_per_second, coin_amount, start_time_in_seconds); + } + + public entry fun add_xp_incentive( + farming_asset_obj: &mut Object>, + amount: u256, + _admin_cap: &mut Object, + ){ + let module_signer = signer::module_signer(); + liquidity_incentive::add_incentive(&module_signer, farming_asset_obj, amount); + } +} \ No newline at end of file diff --git a/apps/rooch_dex/sources/liquidity_incentive.move b/apps/rooch_dex/sources/liquidity_incentive.move index 47c05b1acd..3a22a146f2 100644 --- a/apps/rooch_dex/sources/liquidity_incentive.move +++ b/apps/rooch_dex/sources/liquidity_incentive.move @@ -195,7 +195,7 @@ module rooch_dex::liquidity_incentive { coin: Coin, start_time: u64, ) { - let end_time = (coin::value(&coin) / (release_per_second as u256) as u64); + let end_time = start_time + (coin::value(&coin) / (release_per_second as u256) as u64); let coin_store = coin_store::create_coin_store(); coin_store::deposit(&mut coin_store, coin); if (swap_utils::sort_token_type()) { diff --git a/crates/testsuite/features/dex.feature b/crates/testsuite/features/dex.feature index 67ff41c902..22e302df27 100644 --- a/crates/testsuite/features/dex.feature +++ b/crates/testsuite/features/dex.feature @@ -58,7 +58,7 @@ Feature: RoochDAO Apps contract tests Then assert: "{{$.account[-1].FSC.balance}} != 0" #Create incentive pool - Then cmd: "move run --function default::liquidity_incentive::create_pool --type-args 0x3::gas_coin::RGas --type-args default::fixed_supply_coin::FSC --type-args default::liquid_xp::LiquidXP --args u128:10000 --args u256:10000000000 --args u64:0 --json" + Then cmd: "move run --function default::admin_util::create_xp_incentive_pool --type-args 0x3::gas_coin::RGas --type-args default::fixed_supply_coin::FSC --args u128:10000 --args u256:10000000000 --args u64:0 --args object:{{$.object[0].data[0].id}} --json" Then assert: "{{$.move[-1].execution_info.status.type}} == executed" Then cmd: "object -t 'default::liquidity_incentive::FarmingAsset<0x3::gas_coin::RGas,default::fixed_supply_coin::FSC,default::liquid_xp::LiquidXP>'"