-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade tools, get rid of deps (#179)
* upgrade scarb, snforge * get rid of deps * fmt * missing files * speling * fmt * fmt * fmt * fmt
- Loading branch information
Showing
12 changed files
with
568 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,14 @@ | ||
# Code generated by scarb DO NOT EDIT. | ||
version = 1 | ||
|
||
[[package]] | ||
name = "alexandria_bytes" | ||
version = "0.1.0" | ||
source = "git+https://github.com/keep-starknet-strange/alexandria.git#78b0d5114e7dbd71e79c4504e8ecb56d9b5c6995" | ||
dependencies = [ | ||
"alexandria_data_structures", | ||
"alexandria_math", | ||
] | ||
|
||
[[package]] | ||
name = "alexandria_data_structures" | ||
version = "0.2.0" | ||
source = "git+https://github.com/keep-starknet-strange/alexandria.git#78b0d5114e7dbd71e79c4504e8ecb56d9b5c6995" | ||
dependencies = [ | ||
"alexandria_encoding", | ||
] | ||
|
||
[[package]] | ||
name = "alexandria_encoding" | ||
version = "0.1.0" | ||
source = "git+https://github.com/keep-starknet-strange/alexandria.git#78b0d5114e7dbd71e79c4504e8ecb56d9b5c6995" | ||
dependencies = [ | ||
"alexandria_bytes", | ||
"alexandria_math", | ||
"alexandria_numeric", | ||
] | ||
|
||
[[package]] | ||
name = "alexandria_math" | ||
version = "0.2.0" | ||
source = "git+https://github.com/keep-starknet-strange/alexandria.git#78b0d5114e7dbd71e79c4504e8ecb56d9b5c6995" | ||
dependencies = [ | ||
"alexandria_data_structures", | ||
] | ||
|
||
[[package]] | ||
name = "alexandria_numeric" | ||
version = "0.1.0" | ||
source = "git+https://github.com/keep-starknet-strange/alexandria.git#78b0d5114e7dbd71e79c4504e8ecb56d9b5c6995" | ||
dependencies = [ | ||
"alexandria_math", | ||
"alexandria_searching", | ||
] | ||
|
||
[[package]] | ||
name = "alexandria_searching" | ||
version = "0.1.0" | ||
source = "git+https://github.com/keep-starknet-strange/alexandria.git#78b0d5114e7dbd71e79c4504e8ecb56d9b5c6995" | ||
dependencies = [ | ||
"alexandria_data_structures", | ||
] | ||
|
||
[[package]] | ||
name = "joyboy" | ||
version = "0.1.0" | ||
dependencies = [ | ||
"alexandria_math", | ||
"openzeppelin", | ||
"snforge_std", | ||
] | ||
|
||
[[package]] | ||
name = "openzeppelin" | ||
version = "0.13.0" | ||
source = "git+https://github.com/openzeppelin/cairo-contracts?branch=main#978b4e75209da355667d8954d2450e32bd71fe49" | ||
|
||
[[package]] | ||
name = "snforge_std" | ||
version = "0.24.0" | ||
source = "git+https://github.com/foundry-rs/starknet-foundry?tag=v0.24.0#95e9fb09cb91b3c05295915179ee1b55bf923653" | ||
version = "0.25.0" | ||
source = "git+https://github.com/foundry-rs/starknet-foundry?tag=v0.25.0#5b366e24821e530fea97f11b211d220e8493fbea" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
use starknet::ContractAddress; | ||
|
||
#[starknet::interface] | ||
pub trait IERC20<TContractState> { | ||
fn name(self: @TContractState) -> felt252; | ||
fn symbol(self: @TContractState) -> felt252; | ||
fn decimals(self: @TContractState) -> u8; | ||
fn total_supply(self: @TContractState) -> u256; | ||
fn balance_of(self: @TContractState, account: ContractAddress) -> u256; | ||
fn allowance(self: @TContractState, owner: ContractAddress, spender: ContractAddress) -> u256; | ||
fn transfer(ref self: TContractState, recipient: ContractAddress, amount: u256); | ||
fn transfer_from( | ||
ref self: TContractState, sender: ContractAddress, recipient: ContractAddress, amount: u256 | ||
); | ||
fn approve(ref self: TContractState, spender: ContractAddress, amount: u256); | ||
fn increase_allowance(ref self: TContractState, spender: ContractAddress, added_value: u256); | ||
fn decrease_allowance( | ||
ref self: TContractState, spender: ContractAddress, subtracted_value: u256 | ||
); | ||
} | ||
|
||
#[starknet::contract] | ||
pub mod ERC20 { | ||
use core::num::traits::Zero; | ||
use starknet::ContractAddress; | ||
use starknet::contract_address_const; | ||
use starknet::get_caller_address; | ||
|
||
#[storage] | ||
struct Storage { | ||
name: felt252, | ||
symbol: felt252, | ||
decimals: u8, | ||
total_supply: u256, | ||
balances: LegacyMap::<ContractAddress, u256>, | ||
allowances: LegacyMap::<(ContractAddress, ContractAddress), u256>, | ||
} | ||
|
||
#[event] | ||
#[derive(Drop, starknet::Event)] | ||
enum Event { | ||
Transfer: Transfer, | ||
Approval: Approval, | ||
} | ||
#[derive(Drop, starknet::Event)] | ||
struct Transfer { | ||
from: ContractAddress, | ||
to: ContractAddress, | ||
value: u256, | ||
} | ||
#[derive(Drop, starknet::Event)] | ||
struct Approval { | ||
owner: ContractAddress, | ||
spender: ContractAddress, | ||
value: u256, | ||
} | ||
|
||
#[constructor] | ||
fn constructor( | ||
ref self: ContractState, | ||
name: felt252, | ||
symbol: felt252, | ||
initial_supply: u256, | ||
recipient: ContractAddress, | ||
decimals: u8, | ||
) { | ||
self.name.write(name); | ||
self.symbol.write(symbol); | ||
self.decimals.write(decimals); | ||
assert(!recipient.is_zero(), 'ERC20: mint to the 0 address'); | ||
self.total_supply.write(initial_supply); | ||
self.balances.write(recipient, initial_supply); | ||
self | ||
.emit( | ||
Event::Transfer( | ||
Transfer { | ||
from: contract_address_const::<0>(), to: recipient, value: initial_supply | ||
} | ||
) | ||
); | ||
} | ||
|
||
#[abi(embed_v0)] | ||
impl IERC20Impl of super::IERC20<ContractState> { | ||
fn name(self: @ContractState) -> felt252 { | ||
self.name.read() | ||
} | ||
|
||
fn symbol(self: @ContractState) -> felt252 { | ||
self.symbol.read() | ||
} | ||
|
||
fn decimals(self: @ContractState) -> u8 { | ||
self.decimals.read() | ||
} | ||
|
||
fn total_supply(self: @ContractState) -> u256 { | ||
self.total_supply.read() | ||
} | ||
|
||
fn balance_of(self: @ContractState, account: ContractAddress) -> u256 { | ||
self.balances.read(account) | ||
} | ||
|
||
fn allowance( | ||
self: @ContractState, owner: ContractAddress, spender: ContractAddress | ||
) -> u256 { | ||
self.allowances.read((owner, spender)) | ||
} | ||
|
||
fn transfer(ref self: ContractState, recipient: ContractAddress, amount: u256) { | ||
let sender = get_caller_address(); | ||
self.transfer_helper(sender, recipient, amount); | ||
} | ||
|
||
fn transfer_from( | ||
ref self: ContractState, | ||
sender: ContractAddress, | ||
recipient: ContractAddress, | ||
amount: u256 | ||
) { | ||
let caller = get_caller_address(); | ||
self.spend_allowance(sender, caller, amount); | ||
self.transfer_helper(sender, recipient, amount); | ||
} | ||
|
||
fn approve(ref self: ContractState, spender: ContractAddress, amount: u256) { | ||
let caller = get_caller_address(); | ||
self.approve_helper(caller, spender, amount); | ||
} | ||
|
||
fn increase_allowance( | ||
ref self: ContractState, spender: ContractAddress, added_value: u256 | ||
) { | ||
let caller = get_caller_address(); | ||
self | ||
.approve_helper( | ||
caller, spender, self.allowances.read((caller, spender)) + added_value | ||
); | ||
} | ||
|
||
fn decrease_allowance( | ||
ref self: ContractState, spender: ContractAddress, subtracted_value: u256 | ||
) { | ||
let caller = get_caller_address(); | ||
self | ||
.approve_helper( | ||
caller, spender, self.allowances.read((caller, spender)) - subtracted_value | ||
); | ||
} | ||
} | ||
|
||
#[generate_trait] | ||
impl InternalImpl of InternalTrait { | ||
fn transfer_helper( | ||
ref self: ContractState, | ||
sender: ContractAddress, | ||
recipient: ContractAddress, | ||
amount: u256 | ||
) { | ||
assert(!sender.is_zero(), 'ERC20: transfer from 0'); | ||
assert(!recipient.is_zero(), 'ERC20: transfer to 0'); | ||
self.balances.write(sender, self.balances.read(sender) - amount); | ||
self.balances.write(recipient, self.balances.read(recipient) + amount); | ||
self.emit(Transfer { from: sender, to: recipient, value: amount }); | ||
} | ||
fn spend_allowance( | ||
ref self: ContractState, owner: ContractAddress, spender: ContractAddress, amount: u256 | ||
) { | ||
let current_allowance = self.allowances.read((owner, spender)); | ||
assert(current_allowance >= amount, 'not enough allowance'); | ||
self.allowances.write((owner, spender), current_allowance - amount); | ||
} | ||
|
||
fn approve_helper( | ||
ref self: ContractState, owner: ContractAddress, spender: ContractAddress, amount: u256 | ||
) { | ||
assert(!spender.is_zero(), 'ERC20: approve from 0'); | ||
self.allowances.write((owner, spender), amount); | ||
self.emit(Approval { owner, spender, value: amount }); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
pub mod bip340; | ||
pub mod erc20; | ||
pub mod sha256; | ||
pub mod social; | ||
pub mod utils; |
Oops, something went wrong.