Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate ERC20 #581

Closed
wants to merge 4 commits into from
Closed

Migrate ERC20 #581

wants to merge 4 commits into from

Conversation

martriay
Copy link
Contributor

@martriay martriay commented Mar 7, 2023

Continuation of #575 started by @andrew-fleming

@Amxx Amxx mentioned this pull request Mar 20, 2023
3 tasks
Comment on lines +25 to +26
_balances: LegacyMap::<ContractAddress, u256>,
_allowances: LegacyMap::<(ContractAddress, ContractAddress), u256>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_balances: LegacyMap::<ContractAddress, u256>,
_allowances: LegacyMap::<(ContractAddress, ContractAddress), u256>,
_balances: LegacyMap<ContractAddress, u256>,
_allowances: LegacyMap<(ContractAddress, ContractAddress), u256>,

Comment on lines +81 to +83
fn constructor(name: felt, symbol: felt, initial_supply: u256, recipient: ContractAddress) {
initializer(name, symbol, initial_supply, recipient);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In understand that we may want the constructor to mint an initial supply, but I'm not sure that should be part of the initializer

Suggested change
fn constructor(name: felt, symbol: felt, initial_supply: u256, recipient: ContractAddress) {
initializer(name, symbol, initial_supply, recipient);
}
fn constructor(name: felt, symbol: felt, initial_supply: u256, recipient: ContractAddress) {
initializer(name, symbol);
_mint(recipient, initial_supply);
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, good call

Comment on lines +144 to +148
fn initializer(name_: felt, symbol_: felt, initial_supply: u256, recipient: ContractAddress) {
_name::write(name_);
_symbol::write(symbol_);
_mint(recipient, initial_supply);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment in the constructor

Suggested change
fn initializer(name_: felt, symbol_: felt, initial_supply: u256, recipient: ContractAddress) {
_name::write(name_);
_symbol::write(symbol_);
_mint(recipient, initial_supply);
}
fn initializer(name_: felt, symbol_: felt) {
_name::write(name_);
_symbol::write(symbol_);
}

@andrew-fleming andrew-fleming mentioned this pull request Mar 20, 2023
3 tasks
Comment on lines +191 to +199
fn _spend_allowance(owner: ContractAddress, spender: ContractAddress, amount: u256) {
let current_allowance = _allowances::read((owner, spender));
let ONES_MASK = 0xffffffffffffffffffffffffffffffff_u128;
let is_unlimited_allowance =
current_allowance.low == ONES_MASK & current_allowance.high == ONES_MASK;
if !is_unlimited_allowance {
_approve(owner, spender, current_allowance - amount);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this proposal starkware-libs/cairo#2563 we could do:

Suggested change
fn _spend_allowance(owner: ContractAddress, spender: ContractAddress, amount: u256) {
let current_allowance = _allowances::read((owner, spender));
let ONES_MASK = 0xffffffffffffffffffffffffffffffff_u128;
let is_unlimited_allowance =
current_allowance.low == ONES_MASK & current_allowance.high == ONES_MASK;
if !is_unlimited_allowance {
_approve(owner, spender, current_allowance - amount);
}
}
fn _spend_allowance(owner: ContractAddress, spender: ContractAddress, amount: u256) {
let current_allowance = _allowances::read((owner, spender));
if is_unlimited_allowance != max_uint256() {
_approve(owner, spender, current_allowance - amount);
}
}

@martriay
Copy link
Contributor Author

Superseded by #586

@martriay martriay closed this Mar 20, 2023
@martriay martriay deleted the erc20 branch November 22, 2023 04:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants