Skip to content

Commit

Permalink
Randomness: Values check (#98)
Browse files Browse the repository at this point in the history
* code format

* oracle check

* gas optimisation: remove range check
  • Loading branch information
JordyRo1 authored Dec 17, 2023
1 parent 79157ee commit 3946329
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/randomness/example_randomness.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ mod ExampleRandomness {
.try_into()
.unwrap()
};
eth_dispatcher.approve(randomness_contract_address, callback_fee_limit.into());
eth_dispatcher
.approve(
randomness_contract_address,
(callback_fee_limit + callback_fee_limit / 5).into()
);

// Request the randomness
let randomness_dispatcher = IRandomnessDispatcher {
Expand Down
4 changes: 3 additions & 1 deletion src/randomness/randomness.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ mod Randomness {
const REQUEST_NOT_RECEIVED: felt252 = 'request not received';
const SAME_ADMIN_ADDRESS: felt252 = 'Same admin address';
const ADMIN_ADDRESS_CANNOT_BE_ZERO: felt252 = 'Admin address cannot be zero';
const FETCHING_PRICE_ERROR: felt252 = 'Error fetching price';
}

#[derive(Drop, starknet::Event)]
Expand Down Expand Up @@ -244,13 +245,14 @@ mod Randomness {
let token_dispatcher = ERC20CamelABIDispatcher { contract_address: token_address };
// get the balance of the caller
let user_balance = token_dispatcher.balanceOf(caller_address);
assert(user_balance != 0, Errors::INSUFFICIENT_BALANCE);
// compute the premium fee
let premium_fee = IRandomnessImpl::compute_premium_fee(@self, caller_address);
let oracle_dispatcher = IOracleABIDispatcher {
contract_address: self.oracle_address.read()
};
let response = oracle_dispatcher.get_data_median(DataType::SpotEntry('ETH/USD'));

assert(response.price > 0, Errors::FETCHING_PRICE_ERROR);
// Convert the premium fee in dollar to wei
let wei_premium_fee = dollar_to_wei(premium_fee, response.price, response.decimals);
// Check if the balance is greater than premium fee
Expand Down

0 comments on commit 3946329

Please sign in to comment.