Skip to content

Commit

Permalink
move compute max fee back onto the account
Browse files Browse the repository at this point in the history
  • Loading branch information
gaetbout committed Jun 6, 2024
1 parent 853df7a commit 96769e4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
18 changes: 16 additions & 2 deletions src/contracts/claim_account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ mod ClaimAccount {
use starknet_gifting::contracts::claim_utils::calculate_claim_account_address;
use starknet_gifting::contracts::interface::{IAccount, IGiftAccount, ClaimData, AccountConstructorArguments};
use starknet_gifting::contracts::utils::{
full_deserialize, STRK_ADDRESS, ETH_ADDRESS, TX_V1_ESTIMATE, TX_V1, TX_V3, TX_V3_ESTIMATE, compute_max_fee_v3,
execute_multicall
full_deserialize, STRK_ADDRESS, ETH_ADDRESS, TX_V1_ESTIMATE, TX_V1, TX_V3, TX_V3_ESTIMATE, execute_multicall
};
#[storage]
struct Storage {}
Expand Down Expand Up @@ -97,4 +96,19 @@ mod ClaimAccount {
assert(calculated_address == get_contract_address(), 'gift-acc/invalid-claim-address');
}
}


fn compute_max_fee_v3(mut resource_bounds: Span<ResourceBounds>, tip: u128) -> u128 {
let mut max_fee: u128 = 0;
let mut max_tip: u128 = 0;
while let Option::Some(r) = resource_bounds
.pop_front() {
let max_resource_amount: u128 = (*r.max_amount).into();
max_fee += *r.max_price_per_unit * max_resource_amount;
if *r.resource == 'L2_GAS' {
max_tip += tip * max_resource_amount;
}
};
max_fee + max_tip
}
}
15 changes: 0 additions & 15 deletions src/contracts/utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,6 @@ fn serialize<E, impl ESerde: Serde<E>>(value: @E) -> Array<felt252> {
output
}


fn compute_max_fee_v3(mut resource_bounds: Span<ResourceBounds>, tip: u128) -> u128 {
let mut max_fee: u128 = 0;
let mut max_tip: u128 = 0;
while let Option::Some(r) = resource_bounds
.pop_front() {
let max_resource_amount: u128 = (*r.max_amount).into();
max_fee += *r.max_price_per_unit * max_resource_amount;
if *r.resource == 'L2_GAS' {
max_tip += tip * max_resource_amount;
}
};
max_fee + max_tip
}

fn execute_multicall(mut calls: Span<Call>) -> Array<Span<felt252>> {
let mut result = array![];
let mut index = 0;
Expand Down

0 comments on commit 96769e4

Please sign in to comment.