From 8afa3b2d5a3b8fae626e9627ec82548b64dc9958 Mon Sep 17 00:00:00 2001 From: Othala Date: Fri, 20 Feb 2026 12:36:20 +0000 Subject: [PATCH 1/2] start chat-1771590980836 From 1d19d88e8716003eed961c15a54cab290d68b534 Mon Sep 17 00:00:00 2001 From: 0xMugen Date: Fri, 20 Feb 2026 12:44:35 +0000 Subject: [PATCH 2/2] task chat-1771590980836: save pending changes --- src/guild/guild.cairo | 4 ++++ src/guild/guild_contract.cairo | 12 ++++++++++ src/interfaces/guild.cairo | 1 + src/interfaces/ponziland.cairo | 1 + src/mocks/ponziland.cairo | 12 ++++++++++ tests/test_treasury.cairo | 40 ++++++++++++++++++++++++++++++++++ 6 files changed, 70 insertions(+) diff --git a/src/guild/guild.cairo b/src/guild/guild.cairo index be3d0d7..5e8ec9e 100644 --- a/src/guild/guild.cairo +++ b/src/guild/guild.cairo @@ -113,6 +113,10 @@ pub mod Guild { self.guild.ponzi_buy_land(land_location, token_for_sale, sell_price, amount_to_stake); } + fn ponzi_sell_land(ref self: ContractState, land_location: u16) { + self.guild.ponzi_sell_land(land_location); + } + fn ponzi_set_price(ref self: ContractState, land_location: u16, new_price: u256) { self.guild.ponzi_set_price(land_location, new_price); } diff --git a/src/guild/guild_contract.cairo b/src/guild/guild_contract.cairo index e2ccdfd..5c71aa4 100644 --- a/src/guild/guild_contract.cairo +++ b/src/guild/guild_contract.cairo @@ -603,6 +603,18 @@ pub mod GuildComponent { .buy(land_location, token_for_sale, sell_price, amount_to_stake); } + fn ponzi_sell_land(ref self: ComponentState, land_location: u16) { + let caller = get_caller_address(); + self.check_permission(caller, ActionType::PONZI_SELL_LAND, 0); + + let config = self.plugins.read('ponziland'); + assert!(config.target_contract != Zero::zero(), "{}", Errors::PONZILAND_NOT_REGISTERED); + assert!(config.enabled, "{}", Errors::PLUGIN_DISABLED); + + IPonziLandActionsDispatcher { contract_address: config.target_contract } + .sell(land_location); + } + fn ponzi_set_price( ref self: ComponentState, land_location: u16, new_price: u256, ) { diff --git a/src/interfaces/guild.cairo b/src/interfaces/guild.cairo index 4bfa9f7..ecfc662 100644 --- a/src/interfaces/guild.cairo +++ b/src/interfaces/guild.cairo @@ -68,6 +68,7 @@ pub trait IGuild { sell_price: u256, amount_to_stake: u256, ); + fn ponzi_sell_land(ref self: TState, land_location: u16); fn ponzi_set_price(ref self: TState, land_location: u16, new_price: u256); fn ponzi_claim_yield(ref self: TState, land_location: u16); fn ponzi_increase_stake(ref self: TState, land_location: u16, amount_to_stake: u256); diff --git a/src/interfaces/ponziland.cairo b/src/interfaces/ponziland.cairo index 39992fa..8de9a6f 100644 --- a/src/interfaces/ponziland.cairo +++ b/src/interfaces/ponziland.cairo @@ -9,6 +9,7 @@ pub trait IPonziLandActions { sell_price: u256, amount_to_stake: u256, ); + fn sell(ref self: TState, land_location: u16); fn increase_price(ref self: TState, land_location: u16, new_price: u256); fn claim(ref self: TState, land_location: u16); fn increase_stake(ref self: TState, land_location: u16, amount_to_stake: u256); diff --git a/src/mocks/ponziland.cairo b/src/mocks/ponziland.cairo index 644fa23..f8207b1 100644 --- a/src/mocks/ponziland.cairo +++ b/src/mocks/ponziland.cairo @@ -9,6 +9,7 @@ pub mod PonziLandMock { last_buy_price: u256, last_buy_stake_amount: u256, last_buy_token_for_sale: ContractAddress, + last_sell_location: u16, last_claim_location: u16, last_set_price_location: u16, last_set_price_value: u256, @@ -36,6 +37,12 @@ pub mod PonziLandMock { self.call_count.write(self.call_count.read() + 1); } + #[external(v0)] + fn sell(ref self: ContractState, land_location: u16) { + self.last_sell_location.write(land_location); + self.call_count.write(self.call_count.read() + 1); + } + #[external(v0)] fn increase_price(ref self: ContractState, land_location: u16, new_price: u256) { self.last_set_price_location.write(land_location); @@ -77,6 +84,11 @@ pub mod PonziLandMock { self.last_buy_location.read() } + #[external(v0)] + fn get_last_sell_location(self: @ContractState) -> u16 { + self.last_sell_location.read() + } + #[external(v0)] fn get_last_set_price_location(self: @ContractState) -> u16 { self.last_set_price_location.read() diff --git a/tests/test_treasury.cairo b/tests/test_treasury.cairo index 192e165..84e9442 100644 --- a/tests/test_treasury.cairo +++ b/tests/test_treasury.cairo @@ -650,6 +650,46 @@ fn test_get_guild_name_returns_name() { assert!(view.get_guild_name() == 'TreasuryGuild'); } +#[test] +fn test_ponzi_sell_land_with_permission() { + let (guild_address, guild, _) = deploy_guild(); + let ponzi_address = deploy_ponziland(); + register_ponziland_plugin(guild_address, guild, ponzi_address); + create_member_and_join( + guild_address, guild, ALICE(), member_role(ActionType::PONZI_SELL_LAND, 0), + ); + + start_cheat_caller_address(guild_address, ALICE()); + guild.ponzi_sell_land(15); + + assert!(ponzi_u32(ponzi_address, selector!("get_call_count")) == 1); + assert!(ponzi_u16(ponzi_address, selector!("get_last_sell_location")) == 15); +} + +#[test] +#[should_panic] +fn test_ponzi_sell_land_fails_no_permission() { + let (guild_address, guild, _) = deploy_guild(); + let ponzi_address = deploy_ponziland(); + register_ponziland_plugin(guild_address, guild, ponzi_address); + create_member_and_join(guild_address, guild, ALICE(), member_role(0, 500)); + + start_cheat_caller_address(guild_address, ALICE()); + guild.ponzi_sell_land(15); +} + +#[test] +#[should_panic] +fn test_ponzi_sell_land_fails_plugin_not_registered() { + let (guild_address, guild, _) = deploy_guild(); + create_member_and_join( + guild_address, guild, ALICE(), member_role(ActionType::PONZI_SELL_LAND, 0), + ); + + start_cheat_caller_address(guild_address, ALICE()); + guild.ponzi_sell_land(15); +} + #[test] fn test_view_functions_return_correct_data() { let (guild_address, guild, view) = deploy_guild();