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

Add tokens #63

Merged
merged 3 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ name = "MAINNET"
url = "http://34.22.208.73:6060/v0_7"
block_id.tag = "Latest"

[[tool.snforge.fork]]
name = "GOERLI"
url = "http://34.22.208.73:6061/v0_7"
block_id.tag = "Latest"

[[tool.snforge.fork]]
name = "SEPOLIA"
url = "http://34.22.208.73:6062/v0_7"
Expand Down
4 changes: 3 additions & 1 deletion src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ mod contract;
mod merkle_tree;
//mod options;
mod proposals;
mod token;
mod traits;
mod treasury;
mod types;
mod upgrades;
mod treasury;
mod voting_token;
39 changes: 39 additions & 0 deletions src/token.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// This is a freely tradable ERC20 token.

#[starknet::contract]
mod FloatingToken {
use openzeppelin::token::erc20::interface::IERC20;
use openzeppelin::token::erc20::ERC20Component;
use starknet::ContractAddress;

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

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

impl InternalImpl = ERC20Component::InternalImpl<ContractState>;

#[storage]
struct Storage {
#[substorage(v0)]
erc20: ERC20Component::Storage
}

#[event]
#[derive(Drop, starknet::Event)]
enum Event {
#[flat]
ERC20Event: ERC20Component::Event
}

#[constructor]
fn constructor(ref self: ContractState, fixed_supply: u256, recipient: ContractAddress) {
let name = "Konoha Freely Floating Token";
let symbol = "KONOHA";

self.erc20.initializer(name, symbol);
self.erc20._mint(recipient, fixed_supply);
}
}
74 changes: 74 additions & 0 deletions src/voting_token.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// This is the locked Cairo token.

#[starknet::contract]
mod VotingToken {
use openzeppelin::token::erc20::interface::IERC20;
use openzeppelin::token::erc20::ERC20Component;
use starknet::ContractAddress;

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

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

impl InternalImpl = ERC20Component::InternalImpl<ContractState>;

#[storage]
struct Storage {
#[substorage(v0)]
erc20: ERC20Component::Storage
}

#[event]
#[derive(Drop, starknet::Event)]
enum Event {
#[flat]
ERC20Event: ERC20Component::Event
}

#[constructor]
fn constructor(ref self: ContractState, fixed_supply: u256, recipient: ContractAddress) {
let name = "Konoha Sepolia Deployment Test Token";
let symbol = "KONOHA";

self.erc20.initializer(name, symbol);
self.erc20._mint(recipient, fixed_supply);
}

#[abi(embed_v0)]
impl VotingToken of IERC20<ContractState> {
fn total_supply(self: @ContractState) -> u256 {
self.erc20.total_supply()
}

fn balance_of(self: @ContractState, account: ContractAddress) -> u256 {
self.erc20.balance_of(account)
}

fn allowance(
self: @ContractState, owner: ContractAddress, spender: ContractAddress
) -> u256 {
self.erc20.allowance(owner, spender)
}

fn transfer(ref self: ContractState, recipient: ContractAddress, amount: u256) -> bool {
assert(false, 'token locked, unwrap first');
false
}

fn transfer_from(
ref self: ContractState,
sender: ContractAddress,
recipient: ContractAddress,
amount: u256
) -> bool {
assert(false, 'token locked, unwrap first');
false
}

fn approve(ref self: ContractState, spender: ContractAddress, amount: u256) -> bool {
self.erc20.approve(spender, amount)
}
}
}
15 changes: 0 additions & 15 deletions tests/basic.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,6 @@ fn test_submit_proposal() {
dispatcher.submit_proposal(0x00, 1);
}

#[test]
#[fork("GOERLI")]
fn test_forking_functionality() {
let gov_contract_addr: ContractAddress =
0x7ba1d4836a1142c09dde23cb39b2885fe350912591461b5764454a255bdbac6
.try_into()
.unwrap();
let dispatcher = IProposalsDispatcher { contract_address: gov_contract_addr };
let propdetails = dispatcher.get_proposal_details(1);
assert(
propdetails.payload == 0x78b4ccacdc1c902281f6f13d94b6d17b1f4c44ff811c01dea504d43a264f611,
'payload not match'
);
}


// Raises the prop_id to 44, fixes prop_id now 0
fn submit_44_signal_proposals() {
Expand Down
Loading