Skip to content

Commit df7f0bb

Browse files
✨ Allow route's percent to support 10 decimals (#20)
1 parent 0273a08 commit df7f0bb

File tree

2 files changed

+50
-47
lines changed

2 files changed

+50
-47
lines changed

src/exchange.cairo

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ mod Exchange {
5353
use starknet::{SyscallResultTrait, replace_class_syscall, ContractAddress, ClassHash, get_caller_address, get_contract_address};
5454
use super::IExchange;
5555

56+
// 100 * 10 ** 10 => (10 decimals)
57+
const MAX_ROUTE_PERCENT: u128 = 1000000000000;
5658
const MAX_AVNU_FEES_BPS: u128 = 100;
5759
const MAX_INTEGRATOR_FEES_BPS: u128 = 500;
5860

@@ -500,11 +502,11 @@ mod Exchange {
500502
let route: Route = routes.pop_front().unwrap();
501503

502504
// Calculating tokens to be passed to the exchange
503-
// percentage should be 2 for 2%
505+
// percentage should be 2 * 10**10 for 2%
504506
assert(route.percent > 0, 'Invalid route percent');
505-
assert(route.percent <= 100, 'Invalid route percent');
507+
assert(route.percent <= MAX_ROUTE_PERCENT, 'Invalid route percent');
506508
let token_from_balance = IERC20Dispatcher { contract_address: route.token_from }.balanceOf(contract_address);
507-
let (token_from_amount, overflows) = muldiv(token_from_balance, route.percent.into(), 100_u256, false);
509+
let (token_from_amount, overflows) = muldiv(token_from_balance, route.percent.into(), MAX_ROUTE_PERCENT.into(), false);
508510
assert(overflows == false, 'Overflow: Invalid percent');
509511

510512
// Get adapter class hash

0 commit comments

Comments
 (0)