Skip to content

Commit

Permalink
feat(onchain): switch to weekly limit
Browse files Browse the repository at this point in the history
  • Loading branch information
0xLucqs committed Mar 13, 2024
1 parent f82e523 commit 8277c41
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 182 deletions.
26 changes: 10 additions & 16 deletions onchain/src/contracts/account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ mod Account {
use openzeppelin::introspection::src5::SRC5Component;
use starknet::account::Call;

use vault::spending_limit::daily_limit::DailyLimitComponent;
use vault::spending_limit::daily_limit::interface::IDailyLimit;
use vault::spending_limit::weekly_limit::WeeklyLimitComponent;
use vault::spending_limit::weekly_limit::interface::IWeeklyLimit;

component!(path: AccountComponent, storage: account, event: AccountEvent);
component!(path: SRC5Component, storage: src5, event: SRC5Event);
component!(path: DailyLimitComponent, storage: daily_limit, event: DailyLimitEvent);
component!(path: WeeklyLimitComponent, storage: weekly_limit, event: WeeklyLimitEvent);

// Account
#[abi(embed_v0)]
Expand All @@ -19,12 +19,10 @@ mod Account {
impl PublicKeyCamelImpl = AccountComponent::PublicKeyCamelImpl<ContractState>;
#[abi(embed_v0)]
impl DeclarerImpl = AccountComponent::DeclarerImpl<ContractState>;
#[abi(embed_v0)]
impl DeployableImpl = AccountComponent::DeployableImpl<ContractState>;
impl AccountInternalImpl = AccountComponent::InternalImpl<ContractState>;

// Daily Limit
impl DailyLimitInternalImpl = DailyLimitComponent::InternalImpl<ContractState>;
impl WeeklyLimitInternalImpl = WeeklyLimitComponent::InternalImpl<ContractState>;

// SRC5
#[abi(embed_v0)]
Expand All @@ -37,7 +35,7 @@ mod Account {
#[substorage(v0)]
src5: SRC5Component::Storage,
#[substorage(v0)]
daily_limit: DailyLimitComponent::Storage,
weekly_limit: WeeklyLimitComponent::Storage,
}

#[event]
Expand All @@ -48,7 +46,7 @@ mod Account {
#[flat]
SRC5Event: SRC5Component::Event,
#[flat]
DailyLimitEvent: DailyLimitComponent::Event,
WeeklyLimitEvent: WeeklyLimitComponent::Event,
}

//
Expand All @@ -58,7 +56,7 @@ mod Account {
#[constructor]
fn constructor(ref self: ContractState, public_key: felt252, limit: u256) {
self.account.initializer(:public_key);
self.daily_limit.initializer(:limit);
self.weekly_limit.initializer(:limit);
}

//
Expand Down Expand Up @@ -89,13 +87,9 @@ mod Account {
//

#[abi(embed_v0)]
impl DailyLimit of IDailyLimit<ContractState> {
fn get_daily_limit(self: @ContractState) -> u256 {
self.daily_limit.get_daily_limit()
}

fn set_daily_limit(ref self: ContractState, new_limit: u256) {
self.daily_limit.set_daily_limit(:new_limit);
impl WeeklyLimit of IWeeklyLimit<ContractState> {
fn get_weekly_limit(self: @ContractState) -> u256 {
self.weekly_limit.get_weekly_limit()
}
}
}
2 changes: 1 addition & 1 deletion onchain/src/spending_limit.cairo
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod daily_limit;
pub mod weekly_limit;
5 changes: 0 additions & 5 deletions onchain/src/spending_limit/daily_limit.cairo

This file was deleted.

152 changes: 0 additions & 152 deletions onchain/src/spending_limit/daily_limit/daily_limit.cairo

This file was deleted.

8 changes: 0 additions & 8 deletions onchain/src/spending_limit/daily_limit/interface.cairo

This file was deleted.

5 changes: 5 additions & 0 deletions onchain/src/spending_limit/weekly_limit.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pub mod interface;
pub mod weekly_limit;
use interface::{IWeeklyLimitDispatcher, IWeeklyLimitDispatcherTrait};

use weekly_limit::WeeklyLimitComponent;
6 changes: 6 additions & 0 deletions onchain/src/spending_limit/weekly_limit/interface.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use starknet::account::Call;

#[starknet::interface]
trait IWeeklyLimit<TState> {
fn get_weekly_limit(self: @TState) -> u256;
}
Loading

0 comments on commit 8277c41

Please sign in to comment.