Skip to content

Commit

Permalink
wip: updating to cairo 2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Th0rgal committed Aug 25, 2023
1 parent 8274e34 commit 9f4d679
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 45 deletions.
4 changes: 2 additions & 2 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ version = "0.1.0"
# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest

[dependencies]
starknet = "2.1.0"
openzeppelin = { version = ">=0.7.0-rc.0", git = "https://github.com/OpenZeppelin/cairo-contracts.git", branch = "cairo-2" }
starknet = "2.2.0"
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", branch = "cairo-2" }
identity = { git = "https://github.com/starknet-id/identity.git", branch = "master" }

[[target.starknet-contract]]
Expand Down
60 changes: 26 additions & 34 deletions src/naming/main.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,12 @@ mod Naming {
fn resolve(self: @ContractState, domain: Span<felt252>, field: felt252) -> felt252 {
let (resolver, parent_start) = self.domain_to_resolver(domain, 0);
if (resolver != ContractAddressZeroable::zero()) {
IResolverDispatcher {
contract_address: resolver
}.resolve(domain.slice(parent_start, domain.len() - parent_start), field)
IResolverDispatcher { contract_address: resolver }
.resolve(domain.slice(parent_start, domain.len() - parent_start), field)
} else {
let domain_data = self._domain_data.read(self.hash_domain(domain));
IIdentityDispatcher {
contract_address: self.starknetid_contract.read()
}.get_crosschecked_user_data(domain_data.owner, field)
IIdentityDispatcher { contract_address: self.starknetid_contract.read() }
.get_crosschecked_user_data(domain_data.owner, field)
}
}

Expand All @@ -139,9 +137,8 @@ mod Naming {
if data.address.into() != 0 {
return data.address;
}
IIdentityDispatcher {
contract_address: self.starknetid_contract.read()
}.owner_of(data.owner)
IIdentityDispatcher { contract_address: self.starknetid_contract.read() }
.owner_of(data.owner)
}

// This returns the identity (StarknetID) owning the domain
Expand Down Expand Up @@ -229,12 +226,10 @@ mod Naming {
)
);

IIdentityDispatcher {
contract_address: self.starknetid_contract.read()
}.set_verifier_data(current_domain_data.owner, 'name', 0, 0);
IIdentityDispatcher {
contract_address: self.starknetid_contract.read()
}.set_verifier_data(target_id, 'name', hashed_domain, 0);
IIdentityDispatcher { contract_address: self.starknetid_contract.read() }
.set_verifier_data(current_domain_data.owner, 'name', 0, 0);
IIdentityDispatcher { contract_address: self.starknetid_contract.read() }
.set_verifier_data(target_id, 'name', hashed_domain, 0);
return;
}

Expand All @@ -248,9 +243,8 @@ mod Naming {

fn claim_balance(ref self: ContractState, erc20: ContractAddress) {
assert(get_caller_address() == self._admin_address.read(), 'you are not admin');
let balance = IERC20Dispatcher {
contract_address: erc20
}.balance_of(get_contract_address());
let balance = IERC20Dispatcher { contract_address: erc20 }
.balance_of(get_contract_address());
IERC20Dispatcher { contract_address: erc20 }.transfer(get_caller_address(), balance);
}

Expand All @@ -262,7 +256,7 @@ mod Naming {
fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {
// todo: use components
assert(!new_class_hash.is_zero(), 'Class hash cannot be zero');
starknet::replace_class_syscall(new_class_hash).unwrap_syscall();
starknet::replace_class_syscall(new_class_hash).unwrap();
}
}

Expand All @@ -275,7 +269,7 @@ mod Naming {
let new_len = domain.len() - 1;
let x = *domain[new_len];
let y = self.hash_domain(domain.slice(0, new_len));
let hashed_domain = pedersen(x, y);
let hashed_domain = pedersen::pedersen(x, y);
return hashed_domain;
}

Expand Down Expand Up @@ -332,9 +326,8 @@ mod Naming {
let owner = if data.owner == 0 {
ContractAddressZeroable::zero()
} else {
IIdentityDispatcher {
contract_address: self.starknetid_contract.read()
}.owner_of(data.owner)
IIdentityDispatcher { contract_address: self.starknetid_contract.read() }
.owner_of(data.owner)
};

// if caller owns the starknet id, he owns the domain, we return the key
Expand All @@ -359,7 +352,8 @@ mod Naming {
fn assert_id_availability(self: @ContractState, identity: u128, timestamp: u64) {
let id_hashed_domain = IIdentityDispatcher {
contract_address: self.starknetid_contract.read()
}.get_verifier_data(identity, 'name', get_contract_address(), 0);
}
.get_verifier_data(identity, 'name', get_contract_address(), 0);
assert(
id_hashed_domain == 0
|| self._domain_data.read(id_hashed_domain).expiry < timestamp,
Expand Down Expand Up @@ -413,7 +407,8 @@ mod Naming {
// find domain cost
let (erc20, price) = IPricingDispatcher {
contract_address: self._pricing_contract.read()
}.compute_buy_price(domain_len, days);
}
.compute_buy_price(domain_len, days);

// check the discount
let discounted_price = if (discount_id == 0) {
Expand All @@ -433,14 +428,12 @@ mod Naming {
};

// pay the price
IERC20Dispatcher {
contract_address: erc20
}.transfer_from(get_caller_address(), get_contract_address(), discounted_price);
IERC20Dispatcher { contract_address: erc20 }
.transfer_from(get_caller_address(), get_contract_address(), discounted_price);
// add sponsor commission if eligible
if sponsor.into() != 0 {
IReferralDispatcher {
contract_address: self._referral_contract.read()
}.add_commission(discounted_price, sponsor);
IReferralDispatcher { contract_address: self._referral_contract.read() }
.add_commission(discounted_price, sponsor);
}
}

Expand Down Expand Up @@ -470,9 +463,8 @@ mod Naming {
)
);

IIdentityDispatcher {
contract_address: self.starknetid_contract.read()
}.set_verifier_data(id, 'name', hashed_domain, 0);
IIdentityDispatcher { contract_address: self.starknetid_contract.read() }
.set_verifier_data(id, 'name', hashed_domain, 0);
if (resolver.into() != 0) {
self
.emit(
Expand Down
13 changes: 4 additions & 9 deletions src/tests/naming/common.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,9 @@ fn deploy() -> (IERC20Dispatcher, IPricingDispatcher, IIdentityDispatcher, INami
Naming::TEST_CLASS_HASH, array![identity.into(), pricing.into(), 0, admin]
);
(
IERC20Dispatcher {
contract_address: eth
}, IPricingDispatcher {
contract_address: pricing
}, IIdentityDispatcher {
contract_address: identity
}, INamingDispatcher {
contract_address: address
}
IERC20Dispatcher { contract_address: eth },
IPricingDispatcher { contract_address: pricing },
IIdentityDispatcher { contract_address: identity },
INamingDispatcher { contract_address: address }
)
}

0 comments on commit 9f4d679

Please sign in to comment.