From 6835bcfa09904ef726869e1d14a30911a0e383d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sojka?= <8470346+tensojka@users.noreply.github.com> Date: Wed, 17 Apr 2024 16:41:19 +0200 Subject: [PATCH] Add tokens (#63) * Add tokens * Fix format * Remove Goerli from stale tests --- Scarb.toml | 5 --- src/lib.cairo | 4 ++- src/token.cairo | 39 ++++++++++++++++++++++ src/voting_token.cairo | 74 ++++++++++++++++++++++++++++++++++++++++++ tests/basic.cairo | 15 --------- 5 files changed, 116 insertions(+), 21 deletions(-) create mode 100644 src/token.cairo create mode 100644 src/voting_token.cairo diff --git a/Scarb.toml b/Scarb.toml index 46c50e4c..1b813207 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -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" diff --git a/src/lib.cairo b/src/lib.cairo index 45044e1d..44a80fc1 100644 --- a/src/lib.cairo +++ b/src/lib.cairo @@ -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; diff --git a/src/token.cairo b/src/token.cairo new file mode 100644 index 00000000..9c4b257b --- /dev/null +++ b/src/token.cairo @@ -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; + #[abi(embed_v0)] + impl ERC20MetadataImpl = ERC20Component::ERC20MetadataImpl; + + impl InternalImpl = ERC20Component::InternalImpl; + + #[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); + } +} diff --git a/src/voting_token.cairo b/src/voting_token.cairo new file mode 100644 index 00000000..681aa921 --- /dev/null +++ b/src/voting_token.cairo @@ -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; + #[abi(embed_v0)] + impl ERC20MetadataImpl = ERC20Component::ERC20MetadataImpl; + + impl InternalImpl = ERC20Component::InternalImpl; + + #[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 { + 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) + } + } +} diff --git a/tests/basic.cairo b/tests/basic.cairo index 39f932fa..04f238d3 100644 --- a/tests/basic.cairo +++ b/tests/basic.cairo @@ -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() {