Skip to content

Commit

Permalink
Add upgrades component to contract (#65)
Browse files Browse the repository at this point in the history
* Add upgrades component to contract

* Update to use snake_case in ERC20 govtoken instead of camelCase

* Fix totalSupply too

* Polish scarb fmt

* Add camel impls to tokens

This is because current CARM has camelCase only

* Revert "Fix totalSupply too"

This reverts commit ce535b1.

* Revert "Update to use snake_case in ERC20 govtoken instead of camelCase"

This reverts commit 399dcb8.

* Fix enable accidentally disabled test
  • Loading branch information
tensojka authored Apr 26, 2024
1 parent b97bfee commit 4f41a1f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/contract.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ mod Governance {
#[abi(embed_v0)]
impl Proposals = proposals_component::ProposalsImpl<ContractState>;

#[abi(embed_v0)]
impl Upgrades = upgrades_component::UpgradesImpl<ContractState>;

#[storage]
struct Storage {
proposal_initializer_run: LegacyMap::<u64, bool>,
Expand Down
3 changes: 3 additions & 0 deletions src/token.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// This is a freely tradable ERC20 token.
// TODO upgradability

#[starknet::contract]
mod FloatingToken {
Expand All @@ -12,6 +13,8 @@ mod FloatingToken {
impl ERC20Impl = ERC20Component::ERC20Impl<ContractState>;
#[abi(embed_v0)]
impl ERC20MetadataImpl = ERC20Component::ERC20MetadataImpl<ContractState>;
#[abi(embed_v0)]
impl ERC20CamelOnlyImpl = ERC20Component::ERC20CamelOnlyImpl<ContractState>;

impl InternalImpl = ERC20Component::InternalImpl<ContractState>;

Expand Down
24 changes: 23 additions & 1 deletion src/voting_token.cairo
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// This is the locked Cairo token.
// TODO upgradability

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

Expand Down Expand Up @@ -36,6 +37,27 @@ mod VotingToken {
self.erc20._mint(recipient, fixed_supply);
}

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

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

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

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

0 comments on commit 4f41a1f

Please sign in to comment.