diff --git a/onchain/cairo/launchpad/.snfoundry_cache/.prev_tests_failed b/onchain/cairo/launchpad/.snfoundry_cache/.prev_tests_failed index 69ec2b3b..e69de29b 100644 --- a/onchain/cairo/launchpad/.snfoundry_cache/.prev_tests_failed +++ b/onchain/cairo/launchpad/.snfoundry_cache/.prev_tests_failed @@ -1,5 +0,0 @@ -afk_launchpad::tests::launchpad_tests::launchpad_tests::test_launch_token -afk_launchpad::tests::launchpad_tests::launchpad_tests::test_set_protocol_fee_percent_non_admin -afk_launchpad::tests::liquidity_tests::liquidity_tests::test_add_liquidity_ekubo -afk_launchpad::tests::launchpad_tests::launchpad_tests::test_get_coin_amount_by_quote_amount_for_buy_steps_exp -afk_launchpad::tests::launchpad_tests::launchpad_tests::test_get_coin_amount_by_quote_amount_for_buy_steps diff --git a/onchain/cairo/launchpad/src/interfaces/launchpad.cairo b/onchain/cairo/launchpad/src/interfaces/launchpad.cairo index 91525f18..bac171e4 100644 --- a/onchain/cairo/launchpad/src/interfaces/launchpad.cairo +++ b/onchain/cairo/launchpad/src/interfaces/launchpad.cairo @@ -31,11 +31,13 @@ pub trait ILaunchpadMarketplace { initial_supply: u256, contract_address_salt: felt252, is_unruggable: bool, - bonding_type: BondingType + bonding_type: BondingType, + creator_fee_percent: u256, + creator_fee_destination: ContractAddress ) -> ContractAddress; // fn launch_token(ref self: TContractState, coin_address: ContractAddress); fn launch_token( - ref self: TContractState, coin_address: ContractAddress, bonding_type: BondingType + ref self: TContractState, coin_address: ContractAddress, bonding_type: BondingType, creator_fee_percent: u256, creator_fee_destination: ContractAddress ); fn buy_coin_by_quote_amount( ref self: TContractState, coin_address: ContractAddress, quote_amount: u256, diff --git a/onchain/cairo/launchpad/src/launchpad/launchpad.cairo b/onchain/cairo/launchpad/src/launchpad/launchpad.cairo index c40d6208..ece3d292 100644 --- a/onchain/cairo/launchpad/src/launchpad/launchpad.cairo +++ b/onchain/cairo/launchpad/src/launchpad/launchpad.cairo @@ -582,7 +582,9 @@ pub mod LaunchpadMarketplace { initial_supply: u256, contract_address_salt: felt252, is_unruggable: bool, - bonding_type: BondingType + bonding_type: BondingType, + creator_fee_percent: u256, + creator_fee_destination: ContractAddress, ) -> ContractAddress { let contract_address = get_contract_address(); let caller = get_caller_address(); @@ -599,7 +601,7 @@ pub mod LaunchpadMarketplace { ); self ._launch_token( - token_address, caller, contract_address, false, Option::Some(bonding_type) + token_address, caller, contract_address, false, Option::Some(bonding_type), creator_fee_percent, creator_fee_destination ); token_address } @@ -609,7 +611,7 @@ pub mod LaunchpadMarketplace { // 80% percent on sale and 20% for the Liquidity pool when bonding curve reached threshold // Threshold is setup by the admin and save in the pool struct (in case we change) fn launch_token( - ref self: ContractState, coin_address: ContractAddress, bonding_type: BondingType + ref self: ContractState, coin_address: ContractAddress, bonding_type: BondingType, creator_fee_percent: u256, creator_fee_destination: ContractAddress ) { let caller = get_caller_address(); let contract_address = get_contract_address(); @@ -622,7 +624,9 @@ pub mod LaunchpadMarketplace { caller, contract_address, is_unruggable, - Option::Some(bonding_type) + Option::Some(bonding_type), + creator_fee_percent, + creator_fee_destination ); } @@ -824,7 +828,7 @@ pub mod LaunchpadMarketplace { let protocol_fee_percent = self.protocol_fee_percent.read(); // TODO V2: used creator fees setup by admin/user // HIGH SECURITY RISK - let creator_fee_percent = pool.creator_fee_percent; + let creator_fee_percent=0_u256; // let creator_fee_percent = self.creator_fee_percent.read(); assert( protocol_fee_percent <= MAX_FEE_PROTOCOL @@ -858,6 +862,7 @@ pub mod LaunchpadMarketplace { let mut quote_fee_amount = 0_u256; let mut creator_fee_amount = 0_u256; + let mut creator_fee_percent = 0_u256; // println!("check fees"); // Substract fees protocol from quote amount @@ -876,7 +881,7 @@ pub mod LaunchpadMarketplace { if self.is_fees_creator_enabled.read() && self.is_fees_creator_sell_enabled.read() { // TODO V2 // add the Creator feed here setup by the user - let creator_fee_percent = self.creator_fee_percent.read(); + creator_fee_percent = pool.creator_fee_percent; // MODULAR USER MANAGEMENT // let creator_fee_percent = pool.creator_fee_percent; @@ -1219,7 +1224,9 @@ pub mod LaunchpadMarketplace { caller: ContractAddress, creator: ContractAddress, is_unruggable: bool, - bonding_type: Option + bonding_type: Option, + creator_fee_percent: u256, + creator_fee_destination: ContractAddress, ) { let caller = get_caller_address(); let token = self.token_created.read(coin_address); @@ -1252,12 +1259,13 @@ pub mod LaunchpadMarketplace { // Rounding and approximation of the percentage can lead to security vulnerabilities // let creator_fee_percent = input_creator_fee_percent; - let creator_fee_percent = self.creator_fee_percent.read(); - // assert( - // creator_fee_percent <= MAX_FEE_CREATOR - // && creator_fee_percent >= MIN_FEE_CREATOR, - // errors::CREATOR_FEE_OUT_OF_BOUNDS - // ); + // let creator_fee_percent = self.creator_fee_percent.read(); + + assert( + creator_fee_percent <= MAX_FEE_CREATOR + && creator_fee_percent >= MIN_FEE_CREATOR, + errors::CREATOR_FEE_OUT_OF_BOUNDS + ); // Set up bonding curve type let bond_type = match bonding_type { @@ -1304,7 +1312,7 @@ pub mod LaunchpadMarketplace { // TODO V2 add the creator fee selected by the user creator_fee_percent: creator_fee_percent, creator_amount_received: 0_u256, - creator_fee_destination: caller.clone(), // V2 selected by USER. + creator_fee_destination: creator_fee_destination, // V2 selected by USER. }; // TODO Check approve diff --git a/onchain/cairo/launchpad/src/tests/launchpad_tests.cairo b/onchain/cairo/launchpad/src/tests/launchpad_tests.cairo index 2a2fb423..7f681b93 100644 --- a/onchain/cairo/launchpad/src/tests/launchpad_tests.cairo +++ b/onchain/cairo/launchpad/src/tests/launchpad_tests.cairo @@ -110,6 +110,11 @@ mod launchpad_tests { // fn THRESHOLD_LIQUIDITY() -> u256 { // 10_u256 * pow_256(10, 18) // } + + fn RECEIVER_ADDRESS() -> ContractAddress { + 'receiver'.try_into().unwrap() + } + fn FACTORY_ADDRESS() -> ContractAddress { 0x01a46467a9246f45c8c340f1f155266a26a71c07bd55d36e8d1c7d0d438a2dbc.try_into().unwrap() } @@ -507,7 +512,9 @@ mod launchpad_tests { initial_supply: DEFAULT_INITIAL_SUPPLY(), contract_address_salt: SALT(), is_unruggable: false, - bonding_type: BondingType::Linear + bonding_type: BondingType::Linear, + creator_fee_percent: MID_FEE_CREATOR, + creator_fee_destination: RECEIVER_ADDRESS() ); println!("test token_address {:?}", token_address); let memecoin = IERC20Dispatcher { contract_address: token_address }; @@ -596,7 +603,9 @@ mod launchpad_tests { initial_supply: DEFAULT_INITIAL_SUPPLY(), contract_address_salt: SALT(), is_unruggable: false, - bonding_type: BondingType::Linear + bonding_type: BondingType::Linear, + creator_fee_percent: MID_FEE_CREATOR, + creator_fee_destination: RECEIVER_ADDRESS() ); println!("test token_address {:?}", token_address); let memecoin = IERC20Dispatcher { contract_address: token_address }; @@ -732,7 +741,9 @@ mod launchpad_tests { initial_supply: DEFAULT_INITIAL_SUPPLY(), contract_address_salt: SALT(), is_unruggable: false, - bonding_type: BondingType::Exponential + bonding_type: BondingType::Exponential, + creator_fee_percent: MID_FEE_CREATOR, + creator_fee_destination: RECEIVER_ADDRESS() ); println!("test token_address {:?}", token_address); let memecoin = IERC20Dispatcher { contract_address: token_address }; @@ -804,7 +815,9 @@ mod launchpad_tests { initial_supply: DEFAULT_INITIAL_SUPPLY(), contract_address_salt: SALT(), is_unruggable: false, - bonding_type: BondingType::Linear + bonding_type: BondingType::Linear, + creator_fee_percent: MID_FEE_CREATOR, + creator_fee_destination: RECEIVER_ADDRESS() ); println!("test token_address {:?}", token_address); let memecoin = IERC20Dispatcher { contract_address: token_address }; @@ -891,7 +904,9 @@ mod launchpad_tests { initial_supply: DEFAULT_INITIAL_SUPPLY(), contract_address_salt: SALT(), is_unruggable: false, - bonding_type: BondingType::Linear + bonding_type: BondingType::Linear, + creator_fee_percent: MID_FEE_CREATOR, + creator_fee_destination: RECEIVER_ADDRESS() ); println!("test token_address {:?}", token_address); let memecoin = IERC20Dispatcher { contract_address: token_address }; @@ -978,7 +993,9 @@ mod launchpad_tests { initial_supply: DEFAULT_INITIAL_SUPPLY(), contract_address_salt: SALT(), is_unruggable: false, - bonding_type: BondingType::Exponential + bonding_type: BondingType::Exponential, + creator_fee_percent: MID_FEE_CREATOR, + creator_fee_destination: RECEIVER_ADDRESS() ); println!("test token_address {:?}", token_address); let memecoin = IERC20Dispatcher { contract_address: token_address }; @@ -1083,7 +1100,7 @@ mod launchpad_tests { start_cheat_caller_address(launchpad.contract_address, sender_address); - launchpad.launch_token(token_address, bonding_type: BondingType::Linear); + launchpad.launch_token(token_address, bonding_type: BondingType::Linear, creator_fee_percent: MID_FEE_CREATOR, creator_fee_destination: RECEIVER_ADDRESS()); let amount_first_buy = 1_u256; run_buy_by_amount( @@ -1142,7 +1159,7 @@ mod launchpad_tests { start_cheat_caller_address(launchpad.contract_address, sender_address); - launchpad.launch_token(token_address, bonding_type: BondingType::Exponential); + launchpad.launch_token(token_address, bonding_type: BondingType::Exponential, creator_fee_percent: MID_FEE_CREATOR, creator_fee_destination: RECEIVER_ADDRESS()); let amount_first_buy = 1_u256; run_buy_by_amount( @@ -1186,7 +1203,9 @@ mod launchpad_tests { initial_supply: DEFAULT_INITIAL_SUPPLY(), contract_address_salt: SALT(), is_unruggable: false, - bonding_type: BondingType::Exponential + bonding_type: BondingType::Exponential, + creator_fee_percent: MID_FEE_CREATOR, + creator_fee_destination: RECEIVER_ADDRESS() ); println!("test token_address {:?}", token_address); let memecoin = IERC20Dispatcher { contract_address: token_address }; @@ -1293,7 +1312,7 @@ mod launchpad_tests { let (_, erc20, launchpad) = request_fixture(); launchpad - .launch_token(coin_address: erc20.contract_address, bonding_type: BondingType::Linear); + .launch_token(coin_address: erc20.contract_address, bonding_type: BondingType::Linear, creator_fee_percent: MID_FEE_CREATOR, creator_fee_destination: RECEIVER_ADDRESS()); } #[test] @@ -1313,7 +1332,7 @@ mod launchpad_tests { is_unruggable: false ); - launchpad.launch_token(coin_address: token_address, bonding_type: BondingType::Linear); + launchpad.launch_token(coin_address: token_address, bonding_type: BondingType::Linear, creator_fee_percent: MID_FEE_CREATOR, creator_fee_destination: RECEIVER_ADDRESS()); } #[test] @@ -1338,7 +1357,7 @@ mod launchpad_tests { let memecoin = IERC20Dispatcher { contract_address: token_address }; memecoin.approve(launchpad.contract_address, DEFAULT_INITIAL_SUPPLY()); - launchpad.launch_token(coin_address: token_address, bonding_type: BondingType::Linear); + launchpad.launch_token(coin_address: token_address, bonding_type: BondingType::Linear, creator_fee_percent: MID_FEE_CREATOR, creator_fee_destination: RECEIVER_ADDRESS()); let expected_launch_token_event = LaunchpadEvent::CreateLaunch( CreateLaunch { @@ -1380,7 +1399,7 @@ mod launchpad_tests { // Panic before dont approve allowance // The user have received the token - launchpad.launch_token(coin_address: token_address, bonding_type: BondingType::Linear); + launchpad.launch_token(coin_address: token_address, bonding_type: BondingType::Linear, creator_fee_percent: MID_FEE_CREATOR, creator_fee_destination: RECEIVER_ADDRESS()); } @@ -1421,7 +1440,9 @@ mod launchpad_tests { initial_supply: DEFAULT_INITIAL_SUPPLY(), contract_address_salt: SALT(), is_unruggable: false, - bonding_type: BondingType::Linear + bonding_type: BondingType::Linear, + creator_fee_percent: MID_FEE_CREATOR, + creator_fee_destination: RECEIVER_ADDRESS() ); let launched_token = launchpad.get_coin_launch(token_address); @@ -1451,7 +1472,9 @@ mod launchpad_tests { initial_supply: DEFAULT_INITIAL_SUPPLY(), contract_address_salt: SALT(), is_unruggable: false, - bonding_type: BondingType::Linear + bonding_type: BondingType::Linear, + creator_fee_percent: MID_FEE_CREATOR, + creator_fee_destination: RECEIVER_ADDRESS() ); let memecoin = IERC20Dispatcher { contract_address: token_address }; stop_cheat_caller_address(launchpad.contract_address); @@ -1482,7 +1505,9 @@ mod launchpad_tests { initial_supply: DEFAULT_INITIAL_SUPPLY(), contract_address_salt: SALT(), is_unruggable: false, - bonding_type: BondingType::Linear + bonding_type: BondingType::Linear, + creator_fee_percent: MID_FEE_CREATOR, + creator_fee_destination: RECEIVER_ADDRESS() ); let memecoin = IERC20Dispatcher { contract_address: token_address }; @@ -1512,7 +1537,9 @@ mod launchpad_tests { initial_supply: DEFAULT_INITIAL_SUPPLY(), contract_address_salt: SALT(), is_unruggable: false, - bonding_type: BondingType::Linear + bonding_type: BondingType::Linear, + creator_fee_percent: MID_FEE_CREATOR, + creator_fee_destination: RECEIVER_ADDRESS() ); let memecoin = IERC20Dispatcher { contract_address: token_address }; @@ -1558,7 +1585,9 @@ mod launchpad_tests { initial_supply: DEFAULT_INITIAL_SUPPLY(), contract_address_salt: SALT(), is_unruggable: false, - bonding_type: BondingType::Linear + bonding_type: BondingType::Linear, + creator_fee_percent: MID_FEE_CREATOR, + creator_fee_destination: RECEIVER_ADDRESS() ); let memecoin = IERC20Dispatcher { contract_address: token_address }; @@ -1667,7 +1696,9 @@ mod launchpad_tests { initial_supply: DEFAULT_INITIAL_SUPPLY(), contract_address_salt: SALT(), is_unruggable: false, - bonding_type: BondingType::Exponential + bonding_type: BondingType::Exponential, + creator_fee_percent: MID_FEE_CREATOR, + creator_fee_destination: RECEIVER_ADDRESS() ); let memecoin = IERC20Dispatcher { contract_address: token_address }; @@ -1792,7 +1823,9 @@ mod launchpad_tests { initial_supply: *init_supplies.at(i), contract_address_salt: SALT(), is_unruggable: false, - bonding_type: BondingType::Linear + bonding_type: BondingType::Linear, + creator_fee_percent: MID_FEE_CREATOR, + creator_fee_destination: RECEIVER_ADDRESS() ); token_addresses.append(token_address); @@ -1874,7 +1907,9 @@ mod launchpad_tests { initial_supply: *init_supplies.at(i), contract_address_salt: SALT(), is_unruggable: false, - bonding_type: BondingType::Exponential + bonding_type: BondingType::Exponential, + creator_fee_percent: MID_FEE_CREATOR, + creator_fee_destination: RECEIVER_ADDRESS() ); token_addresses.append(token_address); @@ -2192,7 +2227,9 @@ mod launchpad_tests { initial_supply: DEFAULT_INITIAL_SUPPLY(), contract_address_salt: SALT(), is_unruggable: false, - bonding_type: BondingType::Linear + bonding_type: BondingType::Linear, + creator_fee_percent: MID_FEE_CREATOR, + creator_fee_destination: RECEIVER_ADDRESS() ); // let token_address = default_token.token_address; @@ -2241,7 +2278,9 @@ mod launchpad_tests { initial_supply: DEFAULT_INITIAL_SUPPLY(), contract_address_salt: SALT(), is_unruggable: false, - bonding_type: BondingType::Exponential + bonding_type: BondingType::Exponential, + creator_fee_percent: MID_FEE_CREATOR, + creator_fee_destination: RECEIVER_ADDRESS() ); // let token_address = default_token.token_address; @@ -2285,7 +2324,9 @@ mod launchpad_tests { initial_supply: DEFAULT_INITIAL_SUPPLY(), contract_address_salt: SALT(), is_unruggable: false, - bonding_type: BondingType::Linear + bonding_type: BondingType::Linear, + creator_fee_percent: MID_FEE_CREATOR, + creator_fee_destination: RECEIVER_ADDRESS() ); let memecoin = IERC20Dispatcher { contract_address: token_address }; @@ -2336,7 +2377,9 @@ mod launchpad_tests { initial_supply: DEFAULT_INITIAL_SUPPLY(), contract_address_salt: SALT(), is_unruggable: false, - bonding_type: BondingType::Exponential + bonding_type: BondingType::Exponential, + creator_fee_percent: MID_FEE_CREATOR, + creator_fee_destination: RECEIVER_ADDRESS() ); let memecoin = IERC20Dispatcher { contract_address: token_address }; diff --git a/onchain/cairo/launchpad/src/tests/liquidity_tests.cairo b/onchain/cairo/launchpad/src/tests/liquidity_tests.cairo index e82fd5fc..7bbdecc8 100644 --- a/onchain/cairo/launchpad/src/tests/liquidity_tests.cairo +++ b/onchain/cairo/launchpad/src/tests/liquidity_tests.cairo @@ -59,6 +59,10 @@ mod liquidity_tests { // const THRESHOLD_LIQUIDITY: u256 = 10; // const THRESHOLD_LIQUIDITY: u256 = 10_000; + fn RECEIVER_ADDRESS() -> ContractAddress { + 'receiver'.try_into().unwrap() + } + const RATIO_SUPPLY_LAUNCH: u256 = 5; const LIQUIDITY_SUPPLY: u256 = INITIAL_SUPPLY_DEFAULT / RATIO_SUPPLY_LAUNCH; const BUYABLE: u256 = INITIAL_SUPPLY_DEFAULT / RATIO_SUPPLY_LAUNCH; @@ -363,7 +367,9 @@ mod liquidity_tests { initial_supply: DEFAULT_INITIAL_SUPPLY(), contract_address_salt: SALT(), is_unruggable: false, - bonding_type: BondingType::Linear + bonding_type: BondingType::Linear, + creator_fee_percent: MID_FEE_CREATOR, + creator_fee_destination: RECEIVER_ADDRESS() ); println!("token_address ekubo launch: {:?}", token_address); println!(