Skip to content

Commit

Permalink
feat: update to cairo 2.6.3 (#31)
Browse files Browse the repository at this point in the history
* feat: update to cairo 2.6.3

* fix: scarb version

* fix: signatures
  • Loading branch information
Th0rgal authored Apr 23, 2024
1 parent 69c5222 commit 8abe7e0
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: CI Tests
on: [push, pull_request, pull_request_target]

env:
SCARB_VERSION: 2.3.1
SCARB_VERSION: 2.6.4

jobs:
scarb-tests:
Expand Down
10 changes: 5 additions & 5 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ version = "0.1.0"
# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest

[dependencies]
starknet = "2.3.1"
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", rev = "f3e2a5f0547a429c716f32471b06df729cbdfb9f" }
storage_read = { git = "https://github.com/starknet-id/storage_read_component.git", rev = "c6c69e15d34abfc39ac51dc21b96724e2e19ff31" }
identity = { git = "https://github.com/starknet-id/identity.git", rev = "eb37846330b78e1410cf5e3e17a5dcca5652f921" }
wadray = { git = "https://github.com/lindy-labs/wadray.git", rev = "ea1fa019e7c7c60878ac1e613bc81693524436f5" }
starknet = "2.6.3"
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", rev = "0697004db74502ce49900edef37331dd03531356" }
storage_read = { git = "https://github.com/starknet-id/storage_read_component.git", rev = "6440184cc078188d1efeab1283d1698738cde435" }
identity = { git = "https://github.com/starknet-id/identity.git", rev = "5ae7fafdd20abf4b1e789b83af5db7e23ad39a7c" }
wadray = { git = "https://github.com/lindy-labs/wadray.git", rev = "9b1f0e21abac6811b09d8a9e861b5d53e6a52d9c" }

[[target.starknet-contract]]
# Enable Sierra codegen.
Expand Down
8 changes: 3 additions & 5 deletions src/naming/asserts.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ use naming::{
naming::main::{
Naming,
Naming::{
ContractStateEventEmitter, _hash_to_domain, _hash_to_domainContractMemberStateTrait,
_domain_data, _domain_dataContractMemberStateTrait, starknetid_contract,
starknetid_contractContractMemberStateTrait, discounts,
discountsContractMemberStateTrait, _address_to_domain,
_address_to_domainContractMemberStateTrait, _referral_contract,
ContractStateEventEmitter, _hash_to_domainContractMemberStateTrait,
_domain_dataContractMemberStateTrait, starknetid_contractContractMemberStateTrait,
discountsContractMemberStateTrait, _address_to_domainContractMemberStateTrait,
_referral_contractContractMemberStateTrait,
}
},
Expand Down
8 changes: 3 additions & 5 deletions src/naming/internal.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ use naming::{
naming::main::{
Naming,
Naming::{
ContractStateEventEmitter, _hash_to_domain, _hash_to_domainContractMemberStateTrait,
_domain_data, _domain_dataContractMemberStateTrait, starknetid_contract,
starknetid_contractContractMemberStateTrait, discounts,
discountsContractMemberStateTrait, _address_to_domain,
_address_to_domainContractMemberStateTrait, _referral_contract,
ContractStateEventEmitter, _hash_to_domainContractMemberStateTrait,
_domain_dataContractMemberStateTrait, starknetid_contractContractMemberStateTrait,
discountsContractMemberStateTrait, _address_to_domainContractMemberStateTrait,
_referral_contractContractMemberStateTrait,
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/naming/main.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ mod Naming {
#[abi(embed_v0)]
impl StorageReadComponent = storage_read_component::StorageRead<ContractState>;

#[external(v0)]
#[abi(embed_v0)]
impl NamingImpl of INaming<ContractState> {
// VIEW

Expand Down Expand Up @@ -233,11 +233,12 @@ mod Naming {
}

// This function allows to find which domain to use to display an account
fn address_to_domain(self: @ContractState, address: ContractAddress, hint: Span<felt252>) -> Span<felt252> {
fn address_to_domain(
self: @ContractState, address: ContractAddress, hint: Span<felt252>
) -> Span<felt252> {
let mut domain = ArrayTrait::new();
self.read_address_to_domain(address, ref domain);
if domain.len() != 0
&& self.domain_to_address(domain.span(), hint) == address {
if domain.len() != 0 && self.domain_to_address(domain.span(), hint) == address {
domain.span()
} else {
let identity = IIdentityDispatcher {
Expand Down Expand Up @@ -583,12 +584,11 @@ mod Naming {


// will override your main id
fn set_address_to_domain(ref self: ContractState, domain: Span<felt252>, hint: Span<felt252>) {
fn set_address_to_domain(
ref self: ContractState, domain: Span<felt252>, hint: Span<felt252>
) {
let address = get_caller_address();
assert(
self.domain_to_address(domain, hint) == address,
'domain not pointing back'
);
assert(self.domain_to_address(domain, hint) == address, 'domain not pointing back');
self.emit(Event::AddressToDomainUpdate(AddressToDomainUpdate { address, domain }));
self.set_address_to_domain_util(address, domain);
}
Expand Down
4 changes: 1 addition & 3 deletions src/naming/utils.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use core::array::SpanTrait;
use naming::{
naming::main::{Naming, Naming::{_hash_to_domain, _hash_to_domainContractMemberStateTrait}}
};
use naming::{naming::main::{Naming, Naming::_hash_to_domainContractMemberStateTrait}};
use integer::{u256_safe_divmod, u256_as_non_zero};
use wadray::{Wad, WAD_SCALE};

Expand Down
2 changes: 1 addition & 1 deletion src/pricing.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ mod Pricing {
self.erc20.write(erc20_address);
}

#[external(v0)]
#[abi(embed_v0)]
impl PricingImpl of IPricing<ContractState> {
fn compute_buy_price(
self: @ContractState, domain_len: usize, days: u16
Expand Down
12 changes: 7 additions & 5 deletions src/tests/naming/common.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,22 @@ use naming::pricing::Pricing;

#[starknet::contract]
mod ERC20 {
use openzeppelin::token::erc20::erc20::ERC20Component::InternalTrait;
use openzeppelin::{token::erc20::{ERC20Component, dual20::DualCaseERC20Impl}};
use openzeppelin::token::erc20::erc20::ERC20Component::InternalTrait as ERC20InternalTrait;
use openzeppelin::{
token::erc20::{ERC20Component, dual20::DualCaseERC20Impl, ERC20HooksEmptyImpl}
};

component!(path: ERC20Component, storage: erc20, event: ERC20Event);

#[abi(embed_v0)]
impl ERC20Impl = ERC20Component::ERC20Impl<ContractState>;
#[abi(embed_v0)]
impl ERC20CamelOnlyImpl = ERC20Component::ERC20CamelOnlyImpl<ContractState>;
impl ERC20InternalImpl = ERC20Component::InternalImpl<ContractState>;

#[constructor]
fn constructor(ref self: ContractState) {
self.erc20.initializer('ether', 'ETH');
self.erc20.initializer("ether", "ETH");
let target = starknet::contract_address_const::<0x123>();
self.erc20._mint(target, 0x100000000000000000000000000000000);
}
Expand All @@ -54,7 +57,6 @@ mod ERC20 {
}
}


fn deploy() -> (IERC20CamelDispatcher, IPricingDispatcher, IIdentityDispatcher, INamingDispatcher) {
//erc20
// 0, 1 = low and high of ETH supply
Expand All @@ -64,7 +66,7 @@ fn deploy() -> (IERC20CamelDispatcher, IPricingDispatcher, IIdentityDispatcher,
let pricing = utils::deploy(Pricing::TEST_CLASS_HASH, array![eth.into()]);

// identity
let identity = utils::deploy(Identity::TEST_CLASS_HASH, array![0x123, 0]);
let identity = utils::deploy(Identity::TEST_CLASS_HASH, array![0x123, 0, 0, 0]);

// naming
let admin = 0x123;
Expand Down
2 changes: 1 addition & 1 deletion src/tests/naming/test_abuses.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use super::common::deploy;

#[test]
#[available_gas(2000000000)]
#[should_panic(expected: ('u256_sub Overflow', 'ENTRYPOINT_FAILED', 'ENTRYPOINT_FAILED'))]
#[should_panic(expected: ('ERC20: insufficient balance', 'ENTRYPOINT_FAILED', 'ENTRYPOINT_FAILED'))]
fn test_not_enough_eth() {
// setup
let (eth, pricing, identity, naming) = deploy();
Expand Down
Loading

0 comments on commit 8abe7e0

Please sign in to comment.