Skip to content

Commit

Permalink
revert upgrade code for now
Browse files Browse the repository at this point in the history
  • Loading branch information
baitcode committed Dec 11, 2024
1 parent c3c0244 commit 692c36a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
37 changes: 18 additions & 19 deletions src/staker.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,17 @@ pub trait IStaker<TContractState> {
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::{
Expand Down Expand Up @@ -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<ContractAddress, u128>,
delegated_cumulative_num_snapshots: Map<ContractAddress, u64>,
delegated_cumulative_snapshot: Map<ContractAddress, Map<u64, DelegatedSnapshot>>,

staking_log: Map<ContractAddress, Vec<StakingLogRecord>>
staking_log: Map<ContractAddress, Vec<StakingLogRecord>>,
}

#[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)]
Expand Down Expand Up @@ -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<StakingLogRecord> {
// Find first log record in an array whos timestamp is less or equal to timestamp.
Expand Down Expand Up @@ -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.
// }
}
}
11 changes: 9 additions & 2 deletions src/staker_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 692c36a

Please sign in to comment.