Skip to content

Commit

Permalink
feat: stark tx auth (#477)
Browse files Browse the repository at this point in the history
* feat: stark tx authenticator

* chore: test stark tx auth

* chore: removed double underscore

---------

Co-authored-by: Orlando <orlando@snapshot.org>
  • Loading branch information
Orland0x and Orlando authored Aug 15, 2023
1 parent 15d783d commit 831369d
Show file tree
Hide file tree
Showing 4 changed files with 424 additions and 0 deletions.
2 changes: 2 additions & 0 deletions starknet/src/authenticators.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ mod vanilla;
mod eth_tx;

mod eth_sig;

mod stark_tx;
108 changes: 108 additions & 0 deletions starknet/src/authenticators/stark_tx.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
use starknet::{ContractAddress};
use sx::types::{Strategy, IndexedStrategy, Choice};

#[starknet::interface]
trait IStarkTxAuthenticator<TContractState> {
fn authenticate_propose(
ref self: TContractState,
space: ContractAddress,
author: ContractAddress,
execution_strategy: Strategy,
user_proposal_validation_params: Array<felt252>,
metadata_URI: Array<felt252>
);
fn authenticate_vote(
ref self: TContractState,
space: ContractAddress,
voter: ContractAddress,
proposal_id: u256,
choice: Choice,
user_voting_strategies: Array<IndexedStrategy>,
metadata_URI: Array<felt252>
);
fn authenticate_update_proposal(
ref self: TContractState,
space: ContractAddress,
author: ContractAddress,
proposal_id: u256,
execution_strategy: Strategy,
metadata_URI: Array<felt252>
);
}

#[starknet::contract]
mod StarkTxAuthenticator {
use super::IStarkTxAuthenticator;
use starknet::{ContractAddress, info};
use core::array::ArrayTrait;
use sx::space::space::{ISpaceDispatcher, ISpaceDispatcherTrait};
use sx::types::{UserAddress, Strategy, IndexedStrategy, Choice};

#[storage]
struct Storage {}

#[external(v0)]
impl StarkTxAuthenticator of IStarkTxAuthenticator<ContractState> {
fn authenticate_propose(
ref self: ContractState,
space: ContractAddress,
author: ContractAddress,
execution_strategy: Strategy,
user_proposal_validation_params: Array<felt252>,
metadata_URI: Array<felt252>
) {
assert(info::get_caller_address() == author, 'Invalid Caller');

ISpaceDispatcher {
contract_address: space
}
.propose(
UserAddress::Starknet(author),
execution_strategy,
user_proposal_validation_params,
metadata_URI
);
}

fn authenticate_vote(
ref self: ContractState,
space: ContractAddress,
voter: ContractAddress,
proposal_id: u256,
choice: Choice,
user_voting_strategies: Array<IndexedStrategy>,
metadata_URI: Array<felt252>
) {
assert(info::get_caller_address() == voter, 'Invalid Caller');

ISpaceDispatcher {
contract_address: space
}
.vote(
UserAddress::Starknet(voter),
proposal_id,
choice,
user_voting_strategies,
metadata_URI
);
}

fn authenticate_update_proposal(
ref self: ContractState,
space: ContractAddress,
author: ContractAddress,
proposal_id: u256,
execution_strategy: Strategy,
metadata_URI: Array<felt252>
) {
assert(info::get_caller_address() == author, 'Invalid Caller');

ISpaceDispatcher {
contract_address: space
}
.update_proposal(
UserAddress::Starknet(author), proposal_id, execution_strategy, metadata_URI
);
}
}
}
1 change: 1 addition & 0 deletions starknet/src/tests.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod test_merkle_whitelist;
mod test_factory;
mod test_space;
mod test_upgrade;
mod test_stark_tx_auth;

mod mocks;
mod setup;
Expand Down
Loading

0 comments on commit 831369d

Please sign in to comment.