Skip to content

Commit

Permalink
first draft
Browse files Browse the repository at this point in the history
  • Loading branch information
gaetbout committed Jun 7, 2024
1 parent 581b65f commit af37827
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
10 changes: 4 additions & 6 deletions src/contracts/claim_account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,17 @@ mod ClaimAccount {
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?
// Like if the gas is not enough?
// Nonce will be incremented and the account will be unusable
assert(tx_info.nonce == 0, 'gift-acc/invalid-claim-nonce');
let execution_hash = tx_info.transaction_hash;
let signature = tx_info.signature;
assert(signature.len() == 2, 'gift-acc/invalid-signature-len');
// Should we allow while in estimation?
let tx_version = tx_info.version;
assert(
check_ecdsa_signature(execution_hash, claim.claim_pubkey, *signature[0], *signature[1]),
check_ecdsa_signature(execution_hash, claim.claim_pubkey, *signature[0], *signature[1])
|| tx_version == TX_V3_ESTIMATE
|| tx_version == TX_V1_ESTIMATE,
'invalid-signature'
);
let tx_version = tx_info.version;
if claim.token == STRK_ADDRESS() {
assert(tx_version == TX_V3 || tx_version == TX_V3_ESTIMATE, 'gift-acc/invalid-tx3-version');
let tx_fee = compute_max_fee_v3(tx_info, tx_info.tip);
Expand Down
14 changes: 9 additions & 5 deletions src/contracts/gift_factory.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ mod GiftFactory {
TimelockUpgradeEvent: TimelockUpgradeComponent::Event,
GiftCreated: GiftCreated,
GiftClaimed: GiftClaimed,
GiftClaimedExternal: GiftClaimedExternal,
GiftCanceled: GiftCanceled,
}

Expand All @@ -75,17 +76,20 @@ mod GiftFactory {
token: ContractAddress,
}

// TODO Do we need a different event for external claims?
#[derive(Drop, starknet::Event)]
struct GiftClaimed {
#[key]
receiver: ContractAddress
}

#[derive(Drop, starknet::Event)]
struct GiftCanceled {}
struct GiftClaimedExternal {
#[key]
receiver: ContractAddress
}

// TODO replace all fields with NonZero<T>
#[derive(Drop, starknet::Event)]
struct GiftCanceled {}

#[constructor]
fn constructor(ref self: ContractState, claim_class_hash: ClassHash, owner: ContractAddress) {
Expand All @@ -104,7 +108,7 @@ mod GiftFactory {

let sender = get_caller_address();
let factory = get_contract_address();
// TODO We could manually serialize for better performance
// TODO We could manually serialize for better performance but then we loose the type safety
let class_hash = self.claim_class_hash.read();
let constructor_arguments = AccountConstructorArguments { sender, amount, max_fee, token, claim_pubkey };
let (claim_contract, _) = deploy_syscall(
Expand Down Expand Up @@ -147,7 +151,7 @@ mod GiftFactory {
let balance = IERC20Dispatcher { contract_address: claim.token }.balance_of(claim_address);
assert(balance >= claim.amount, 'gift/already-claimed-or-cancel');
self.transfer_from_account(claim, claim_address, claim.token, balance, receiver);
self.emit(GiftClaimed { receiver });
self.emit(GiftClaimedExternal { receiver });
}

fn cancel(ref self: ContractState, claim: ClaimData) {
Expand Down

0 comments on commit af37827

Please sign in to comment.