diff --git a/src/staker.cairo b/src/staker.cairo index 729251a..68762d9 100644 --- a/src/staker.cairo +++ b/src/staker.cairo @@ -57,18 +57,17 @@ pub trait IStaker { fn get_staked_seconds_at(self: @TContractState, owner: ContractAddress, timestamp: u64) -> u128; // Replaces the code at this address. This must be self-called via a governor proposal. - fn upgrade(ref self: TContractState, class_hash: ClassHash); + // fn upgrade(ref self: TContractState, class_hash: ClassHash); } #[starknet::contract] pub mod Staker { - use starknet::storage::MutableVecTrait; use core::num::traits::zero::{Zero}; use governance::interfaces::erc20::{IERC20Dispatcher, IERC20DispatcherTrait}; use starknet::storage::{ Map, StorageMapReadAccess, StorageMapWriteAccess, StoragePathEntry, StoragePointerReadAccess, StoragePointerWriteAccess, - Vec, VecTrait, + Vec, VecTrait, MutableVecTrait, }; use starknet::{ @@ -115,20 +114,20 @@ pub mod Staker { #[storage] struct Storage { token: IERC20Dispatcher, - governor: ContractAddress, + // governor: ContractAddress, // owner, delegate => amount staked: Map<(ContractAddress, ContractAddress), u128>, amount_delegated: Map, delegated_cumulative_num_snapshots: Map, delegated_cumulative_snapshot: Map>, - - staking_log: Map> + staking_log: Map>, } #[constructor] - fn constructor(ref self: ContractState, token: IERC20Dispatcher, governor: ContractAddress) { + fn constructor(ref self: ContractState, token: IERC20Dispatcher) { + // , governor: ContractAddress self.token.write(token); - self.governor.write(governor); + // self.governor.write(governor); } #[derive(starknet::Event, PartialEq, Debug, Drop)] @@ -285,11 +284,11 @@ pub mod Staker { } } - fn check_governor_call(self: @ContractState) { - assert(self.governor.read().is_non_zero(), 'GOVERNOR_UNDEFINED'); - assert(get_caller_address().is_non_zero(), 'GOVERNOR_ONLY'); - assert(get_caller_address() == self.governor.read(), 'GOVERNOR_ONLY'); - } + // fn check_governor_call(self: @ContractState) { + // assert(self.governor.read().is_non_zero(), 'GOVERNOR_UNDEFINED'); + // assert(get_caller_address().is_non_zero(), 'GOVERNOR_ONLY'); + // assert(get_caller_address() == self.governor.read(), 'GOVERNOR_ONLY'); + // } fn find_in_change_log(self: @ContractState, from: ContractAddress, timestamp: u64) -> Option { // Find first log record in an array whos timestamp is less or equal to timestamp. @@ -463,12 +462,12 @@ pub mod Staker { } } - fn upgrade(ref self: ContractState, class_hash: ClassHash) { - assert(class_hash.is_non_zero(), 'INVALID_CLASS_HASH'); - self.check_governor_call(); - replace_class_syscall(class_hash).unwrap(); + // fn upgrade(ref self: ContractState, class_hash: ClassHash) { + // assert(class_hash.is_non_zero(), 'INVALID_CLASS_HASH'); + // self.check_governor_call(); + // replace_class_syscall(class_hash).unwrap(); - // TODO(baitcode): Ideally we should emit an event here. - } + // // TODO(baitcode): Ideally we should emit an event here. + // } } } diff --git a/src/staker_test.cairo b/src/staker_test.cairo index c6e1e4a..aabbdae 100644 --- a/src/staker_test.cairo +++ b/src/staker_test.cairo @@ -7,13 +7,20 @@ use governance::staker::{ }; use governance::test::test_token::{TestToken, deploy as deploy_token}; use starknet::testing::{pop_log, set_block_timestamp}; -use starknet::{contract_address_const, get_contract_address, syscalls::deploy_syscall}; +use starknet::{ + ClassHash, + contract_address_const, + get_contract_address, + syscalls::deploy_syscall +}; pub(crate) fn setup(amount: u256) -> (IStakerDispatcher, IERC20Dispatcher) { let token = deploy_token(get_contract_address(), amount); + let classHash: ClassHash = Staker::TEST_CLASS_HASH.try_into().unwrap(); + let (staker_address, _) = deploy_syscall( - Staker::TEST_CLASS_HASH.try_into().unwrap(), + classHash, 0, array![token.contract_address.into()].span(), true,