-
Notifications
You must be signed in to change notification settings - Fork 356
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
Migrate ERC20 #581
Conversation
_balances: LegacyMap::<ContractAddress, u256>, | ||
_allowances: LegacyMap::<(ContractAddress, ContractAddress), u256>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_balances: LegacyMap::<ContractAddress, u256>, | |
_allowances: LegacyMap::<(ContractAddress, ContractAddress), u256>, | |
_balances: LegacyMap<ContractAddress, u256>, | |
_allowances: LegacyMap<(ContractAddress, ContractAddress), u256>, |
fn constructor(name: felt, symbol: felt, initial_supply: u256, recipient: ContractAddress) { | ||
initializer(name, symbol, initial_supply, recipient); | ||
} |
There was a problem hiding this comment.
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
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); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, good call
fn initializer(name_: felt, symbol_: felt, initial_supply: u256, recipient: ContractAddress) { | ||
_name::write(name_); | ||
_symbol::write(symbol_); | ||
_mint(recipient, initial_supply); | ||
} |
There was a problem hiding this comment.
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
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_); | |
} |
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); | ||
} | ||
} |
There was a problem hiding this comment.
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:
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); | |
} | |
} |
Superseded by #586 |
Continuation of #575 started by @andrew-fleming