Skip to content

Commit

Permalink
Merge branch 'develop' into refactor/ts-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonard-Pat committed Jun 6, 2024
2 parents 5ed73a6 + 0a6c3bc commit c031352
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 30 deletions.
12 changes: 6 additions & 6 deletions gas-report.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ Summary:
┌───────────────────────┬─────────────────────┬─────────┬────────────────┬────────────────┬─────────────────┬───────────┬──────────────┬──────────────────────────────┬───────────────┬────────┬─────────┐
│ (index) │ Actual fee │ Fee usd │ Fee without DA │ Gas without DA │ Computation gas │ Event gas │ Calldata gas │ Max computation per Category │ Storage diffs │ DA fee │ DA mode │
├───────────────────────┼─────────────────────┼─────────┼────────────────┼────────────────┼─────────────────┼───────────┼──────────────┼──────────────────────────────┼───────────────┼────────┼─────────┤
│ Deposit (txV3: false) │ '1.152.000.000.352' │ 0.004611520000000003231 │ 4 │ 1 │ 'steps' │ 4 │ 352 │ 'BLOB' │
│ Deposit (txV3: false) │ '1.116.000.000.352' │ 0.004411160000000003130 │ 4 │ 1 │ 'steps' │ 4 │ 352 │ 'BLOB' │
│ Claim (txV3: false) │ '1.260.000.000.192' │ 0.005 │ 1260000000000 │ 35 │ 34 │ 2 │ 1 │ 'steps' │ 3 │ 192 │ 'BLOB' │
│ Deposit (txV3: true) │ '1.152.000.000.480' │ 0.004611520000000003231 │ 4 │ 1 │ 'steps' │ 5 │ 480 │ 'BLOB' │
│ Deposit (txV3: true) │ '1.116.000.000.480' │ 0.004411160000000003130 │ 4 │ 1 │ 'steps' │ 5 │ 480 │ 'BLOB' │
│ Claim (txV3: true) │ '1.260.000.000.192' │ 0 │ 1260000000000 │ 35 │ 34 │ 2 │ 1 │ 'steps' │ 3 │ 192 │ 'BLOB' │
└───────────────────────┴─────────────────────┴─────────┴────────────────┴────────────────┴─────────────────┴───────────┴──────────────┴──────────────────────────────┴───────────────┴────────┴─────────┘
Resources:
┌───────────────────────┬─────────┬───────┬───────┬────────┬──────────┬──────────┬─────────────┬───────┐
│ (index) │ bitwise │ ec_op │ ecdsa │ keccak │ pedersen │ poseidon │ range_check │ steps │
├───────────────────────┼─────────┼───────┼───────┼────────┼──────────┼──────────┼─────────────┼───────┤
│ Deposit (txV3: false) │ 0 │ 3 │ 0 │ 0 │ 38 │ 0 │ 27712098
│ Claim (txV3: false) │ 0 │ 3 │ 0 │ 0 │ 71 │ 0 │ 456 │ 13231
│ Deposit (txV3: true) │ 0 │ 3 │ 0 │ 0 │ 38 │ 0 │ 27712099
│ Claim (txV3: true) │ 0 │ 3 │ 0 │ 0 │ 71 │ 0 │ 490 │ 13429
│ Deposit (txV3: false) │ 0 │ 3 │ 0 │ 0 │ 38 │ 0 │ 27311991
│ Claim (txV3: false) │ 0 │ 3 │ 0 │ 0 │ 71 │ 0 │ 456 │ 13228
│ Deposit (txV3: true) │ 0 │ 3 │ 0 │ 0 │ 38 │ 0 │ 27311992
│ Claim (txV3: true) │ 0 │ 3 │ 0 │ 0 │ 71 │ 0 │ 490 │ 13426
└───────────────────────┴─────────┴───────┴───────┴────────┴──────────┴──────────┴─────────────┴───────┘
2 changes: 1 addition & 1 deletion scripts/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const factory = await manager.deployContract("GiftFactory", {
});

for (const useTxV3 of [false, true]) {
const signer = new LegacyStarknetKeyPair();
const signer = new LegacyStarknetKeyPair(12n);
const claimPubkey = signer.publicKey;
const amount = 1000000000000000n;
const maxFee = 50000000000000n;
Expand Down
22 changes: 8 additions & 14 deletions src/contracts/claim_account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@
mod ClaimAccount {
use core::ecdsa::check_ecdsa_signature;
use core::num::traits::Zero;
use core::starknet::event::EventEmitter;
use core::traits::TryInto;
use openzeppelin::token::erc20::interface::{IERC20, IERC20DispatcherTrait, IERC20Dispatcher};
use starknet::{
ClassHash, account::Call, VALIDATED, call_contract_syscall, ContractAddress, get_contract_address,
get_caller_address, contract_address::contract_address_const, get_execution_info, info::v2::ResourceBounds,
account::Call, VALIDATED, call_contract_syscall, ContractAddress, get_contract_address, get_caller_address,
get_execution_info, info::v2::ResourceBounds,
};
use starknet_gifting::contracts::claim_hash::{ClaimExternal, IOffChainMessageHashRev1};
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, execute_multicall
};

#[storage]
struct Storage {}

Expand All @@ -36,7 +33,7 @@ mod ClaimAccount {
let (claim, _): (ClaimData, ContractAddress) = full_deserialize(*calldata)
.expect('gift-acc/invalid-calldata');
assert(*to == claim.factory, 'gift-acc/invalid-call-to');
self.assert_valid_claim(claim);
assert_valid_claim(claim);

let tx_info = execution_info.tx_info.unbox();
// Isn't it an issue if for some reason it fails during execution?
Expand Down Expand Up @@ -83,18 +80,15 @@ mod ClaimAccount {
fn execute_factory_calls(
ref self: ContractState, claim: ClaimData, mut calls: Array<Call>
) -> Array<Span<felt252>> {
self.assert_valid_claim(claim);
assert_valid_claim(claim);
assert(get_caller_address() == claim.factory, 'gift/only-factory');
execute_multicall(calls.span())
}
}

#[generate_trait]
impl Private of PrivateTrait {
fn assert_valid_claim(self: @ContractState, claim: ClaimData) {
let calculated_address = calculate_claim_account_address(claim);
assert(calculated_address == get_contract_address(), 'gift-acc/invalid-claim-address');
}
fn assert_valid_claim(claim: ClaimData) {
let calculated_address = calculate_claim_account_address(claim);
assert(calculated_address == get_contract_address(), 'gift-acc/invalid-claim-address');
}

fn compute_max_fee_v3(mut resource_bounds: Span<ResourceBounds>, tip: u128) -> u128 {
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/claim_utils.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use openzeppelin::utils::deployments::calculate_contract_address_from_deploy_syscall;
use starknet::{ContractAddress, contract_address_const};
use starknet::ContractAddress;
use starknet_gifting::contracts::interface::{ClaimData, AccountConstructorArguments};
use starknet_gifting::contracts::utils::serialize;

Expand Down
12 changes: 4 additions & 8 deletions src/contracts/gift_factory.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,15 @@ mod GiftFactory {
use openzeppelin::access::ownable::OwnableComponent;
use openzeppelin::security::PausableComponent;
use openzeppelin::token::erc20::interface::{IERC20, IERC20DispatcherTrait, IERC20Dispatcher};
use openzeppelin::utils::deployments::calculate_contract_address_from_deploy_syscall;
use starknet::{
ClassHash, ContractAddress, deploy_syscall, get_caller_address, get_contract_address,
contract_address::contract_address_const, account::Call
};
use starknet::{ClassHash, ContractAddress, deploy_syscall, get_caller_address, get_contract_address, account::Call};
use starknet_gifting::contracts::claim_hash::{ClaimExternal, IOffChainMessageHashRev1};
use starknet_gifting::contracts::claim_utils::{calculate_claim_account_address};

use starknet_gifting::contracts::interface::{
IGiftAccount, IGiftAccountDispatcherTrait, IGiftFactory, ClaimData, AccountConstructorArguments,
IGiftAccountDispatcher, ITimelockUpgradeCallback
IGiftAccountDispatcherTrait, IGiftFactory, ClaimData, AccountConstructorArguments, IGiftAccountDispatcher,
ITimelockUpgradeCallback
};
use starknet_gifting::contracts::timelock_upgrade::{TimelockUpgradeComponent};
use starknet_gifting::contracts::timelock_upgrade::TimelockUpgradeComponent;
use starknet_gifting::contracts::utils::{STRK_ADDRESS, ETH_ADDRESS, serialize, full_deserialize};

// Ownable
Expand Down

0 comments on commit c031352

Please sign in to comment.