|
| 1 | +/// Test-only Autonomous Buyback contract for unit testing |
| 2 | +/// This is identical to the preset in game_components_presets but defined here |
| 3 | +/// so tokenomics tests can use `declare("AutonomousBuyback")`. |
| 4 | +#[starknet::contract] |
| 5 | +pub mod AutonomousBuyback { |
| 6 | + use game_components_interfaces::tokenomics::buyback::{ |
| 7 | + GlobalBuybackConfig, IBuybackAdmin, TokenBuybackConfig, |
| 8 | + }; |
| 9 | + use game_components_tokenomics::buyback::BuybackComponent; |
| 10 | + use openzeppelin_access::ownable::OwnableComponent; |
| 11 | + use starknet::ContractAddress; |
| 12 | + |
| 13 | + component!(path: BuybackComponent, storage: buyback, event: BuybackEvent); |
| 14 | + component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); |
| 15 | + |
| 16 | + #[abi(embed_v0)] |
| 17 | + impl BuybackImpl = BuybackComponent::BuybackImpl<ContractState>; |
| 18 | + impl BuybackInternalImpl = BuybackComponent::InternalImpl<ContractState>; |
| 19 | + |
| 20 | + #[abi(embed_v0)] |
| 21 | + impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl<ContractState>; |
| 22 | + impl OwnableInternalImpl = OwnableComponent::InternalImpl<ContractState>; |
| 23 | + |
| 24 | + #[storage] |
| 25 | + struct Storage { |
| 26 | + #[substorage(v0)] |
| 27 | + buyback: BuybackComponent::Storage, |
| 28 | + #[substorage(v0)] |
| 29 | + ownable: OwnableComponent::Storage, |
| 30 | + } |
| 31 | + |
| 32 | + #[event] |
| 33 | + #[derive(Drop, starknet::Event)] |
| 34 | + enum Event { |
| 35 | + #[flat] |
| 36 | + BuybackEvent: BuybackComponent::Event, |
| 37 | + #[flat] |
| 38 | + OwnableEvent: OwnableComponent::Event, |
| 39 | + } |
| 40 | + |
| 41 | + #[constructor] |
| 42 | + fn constructor( |
| 43 | + ref self: ContractState, |
| 44 | + owner: ContractAddress, |
| 45 | + global_config: GlobalBuybackConfig, |
| 46 | + positions_address: ContractAddress, |
| 47 | + extension_address: ContractAddress, |
| 48 | + ) { |
| 49 | + self.ownable.initializer(owner); |
| 50 | + self.buyback.initializer(global_config, positions_address, extension_address); |
| 51 | + } |
| 52 | + |
| 53 | + #[abi(embed_v0)] |
| 54 | + impl BuybackAdminImpl of IBuybackAdmin<ContractState> { |
| 55 | + fn set_global_config(ref self: ContractState, config: GlobalBuybackConfig) { |
| 56 | + self.ownable.assert_only_owner(); |
| 57 | + self.buyback.set_global_config(config); |
| 58 | + } |
| 59 | + |
| 60 | + fn set_token_config( |
| 61 | + ref self: ContractState, |
| 62 | + sell_token: ContractAddress, |
| 63 | + config: Option<TokenBuybackConfig>, |
| 64 | + ) { |
| 65 | + self.ownable.assert_only_owner(); |
| 66 | + self.buyback.set_token_config(sell_token, config); |
| 67 | + } |
| 68 | + } |
| 69 | +} |
0 commit comments