Skip to content

Commit

Permalink
feat: metadata URIs (#475)
Browse files Browse the repository at this point in the history
* feat: metadata uris

* chore: updated tests

---------

Co-authored-by: Orlando <[email protected]>
  • Loading branch information
Orland0x and Orlando authored Aug 11, 2023
1 parent 9beecd7 commit 82c1a45
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 32 deletions.
29 changes: 23 additions & 6 deletions starknet/src/authenticators/eth_sig.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ trait IEthSigAuthenticator<TContractState> {
author: EthAddress,
execution_strategy: Strategy,
user_proposal_validation_params: Array<felt252>,
metadata_URI: Array<felt252>,
salt: u256,
);
fn authenticate_vote(
Expand All @@ -24,7 +25,8 @@ trait IEthSigAuthenticator<TContractState> {
voter: EthAddress,
proposal_id: u256,
choice: Choice,
user_voting_strategies: Array<IndexedStrategy>
user_voting_strategies: Array<IndexedStrategy>,
metadata_URI: Array<felt252>,
);
fn authenticate_update_proposal(
ref self: TContractState,
Expand All @@ -35,6 +37,7 @@ trait IEthSigAuthenticator<TContractState> {
author: EthAddress,
proposal_id: u256,
execution_strategy: Strategy,
metadata_URI: Array<felt252>,
salt: u256
);
}
Expand Down Expand Up @@ -66,6 +69,7 @@ mod EthSigAuthenticator {
author: EthAddress,
execution_strategy: Strategy,
user_proposal_validation_params: Array<felt252>,
metadata_URI: Array<felt252>,
salt: u256,
) {
signatures::verify_propose_sig(
Expand All @@ -87,7 +91,8 @@ mod EthSigAuthenticator {
.propose(
UserAddress::Ethereum(author),
execution_strategy,
user_proposal_validation_params
user_proposal_validation_params,
metadata_URI
);
}

Expand All @@ -100,7 +105,8 @@ mod EthSigAuthenticator {
voter: EthAddress,
proposal_id: u256,
choice: Choice,
user_voting_strategies: Array<IndexedStrategy>
user_voting_strategies: Array<IndexedStrategy>,
metadata_URI: Array<felt252>,
) {
signatures::verify_vote_sig(
r,
Expand All @@ -111,14 +117,21 @@ mod EthSigAuthenticator {
voter,
proposal_id,
choice,
user_voting_strategies.clone()
user_voting_strategies.clone(),
);

// No need to check salts here, as double voting is prevented by the space itself.

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

fn authenticate_update_proposal(
Expand All @@ -130,6 +143,7 @@ mod EthSigAuthenticator {
author: EthAddress,
proposal_id: u256,
execution_strategy: Strategy,
metadata_URI: Array<felt252>,
salt: u256
) {
signatures::verify_update_proposal_sig(
Expand All @@ -147,7 +161,10 @@ mod EthSigAuthenticator {

ISpaceDispatcher {
contract_address: target
}.update_proposal(UserAddress::Ethereum(author), proposal_id, execution_strategy);
}
.update_proposal(
UserAddress::Ethereum(author), proposal_id, execution_strategy, metadata_URI
);
}
}

Expand Down
38 changes: 29 additions & 9 deletions starknet/src/authenticators/eth_tx.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,25 @@ trait IEthTxAuthenticator<TContractState> {
target: ContractAddress,
author: EthAddress,
execution_strategy: Strategy,
user_proposal_validation_params: Array<felt252>
user_proposal_validation_params: Array<felt252>,
metadata_URI: Array<felt252>
);
fn authenticate_vote(
ref self: TContractState,
target: ContractAddress,
voter: EthAddress,
proposal_id: u256,
choice: Choice,
user_voting_strategies: Array<IndexedStrategy>
user_voting_strategies: Array<IndexedStrategy>,
metadata_URI: Array<felt252>
);
fn authenticate_update_proposal(
ref self: TContractState,
target: ContractAddress,
author: EthAddress,
proposal_id: u256,
execution_strategy: Strategy
execution_strategy: Strategy,
metadata_URI: Array<felt252>
);
// TODO: Should L1 handlers be part of the interface?
}
Expand Down Expand Up @@ -55,14 +58,16 @@ mod EthTxAuthenticator {
target: ContractAddress,
author: EthAddress,
execution_strategy: Strategy,
user_proposal_validation_params: Array<felt252>
user_proposal_validation_params: Array<felt252>,
metadata_URI: Array<felt252>
) {
let mut payload = ArrayTrait::<felt252>::new();
target.serialize(ref payload);
PROPOSE_SELECTOR.serialize(ref payload);
author.serialize(ref payload);
execution_strategy.serialize(ref payload);
user_proposal_validation_params.serialize(ref payload);
metadata_URI.serialize(ref payload);
let payload_hash = poseidon::poseidon_hash_span(payload.span());

consume_commit(ref self, payload_hash, author);
Expand All @@ -73,7 +78,8 @@ mod EthTxAuthenticator {
.propose(
UserAddress::Ethereum(author),
execution_strategy,
user_proposal_validation_params
user_proposal_validation_params,
metadata_URI
);
}

Expand All @@ -83,7 +89,8 @@ mod EthTxAuthenticator {
voter: EthAddress,
proposal_id: u256,
choice: Choice,
user_voting_strategies: Array<IndexedStrategy>
user_voting_strategies: Array<IndexedStrategy>,
metadata_URI: Array<felt252>
) {
let mut payload = ArrayTrait::<felt252>::new();
target.serialize(ref payload);
Expand All @@ -92,35 +99,48 @@ mod EthTxAuthenticator {
proposal_id.serialize(ref payload);
choice.serialize(ref payload);
user_voting_strategies.serialize(ref payload);
metadata_URI.serialize(ref payload);
let payload_hash = poseidon::poseidon_hash_span(payload.span());

consume_commit(ref self, payload_hash, voter);

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

fn authenticate_update_proposal(
ref self: ContractState,
target: ContractAddress,
author: EthAddress,
proposal_id: u256,
execution_strategy: Strategy
execution_strategy: Strategy,
metadata_URI: Array<felt252>
) {
let mut payload = ArrayTrait::<felt252>::new();
target.serialize(ref payload);
UPDATE_PROPOSAL_SELECTOR.serialize(ref payload);
author.serialize(ref payload);
proposal_id.serialize(ref payload);
execution_strategy.serialize(ref payload);
metadata_URI.serialize(ref payload);
let payload_hash = poseidon::poseidon_hash_span(payload.span());

consume_commit(ref self, payload_hash, author);

ISpaceDispatcher {
contract_address: target
}.update_proposal(UserAddress::Ethereum(author), proposal_id, execution_strategy);
}
.update_proposal(
UserAddress::Ethereum(author), proposal_id, execution_strategy, metadata_URI
);
}
}

Expand Down
66 changes: 49 additions & 17 deletions starknet/src/space/space.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,24 @@ trait ISpace<TContractState> {
ref self: TContractState,
author: UserAddress,
execution_strategy: Strategy,
user_proposal_validation_params: Array<felt252>
user_proposal_validation_params: Array<felt252>,
metadata_URI: Array<felt252>,
);
fn vote(
ref self: TContractState,
voter: UserAddress,
proposal_id: u256,
choice: Choice,
user_voting_strategies: Array<IndexedStrategy>
user_voting_strategies: Array<IndexedStrategy>,
metadata_URI: Array<felt252>,
);
fn execute(ref self: TContractState, proposal_id: u256, execution_payload: Array<felt252>);
fn update_proposal(
ref self: TContractState,
author: UserAddress,
proposal_id: u256,
execution_strategy: Strategy
execution_strategy: Strategy,
metadata_URI: Array<felt252>,
);
fn cancel_proposal(ref self: TContractState, proposal_id: u256);
fn upgrade(ref self: TContractState, class_hash: ClassHash);
Expand Down Expand Up @@ -102,31 +105,47 @@ mod Space {
_min_voting_duration: u32,
_max_voting_duration: u32,
_proposal_validation_strategy: @Strategy,
_proposal_validation_strategy_metadata_URI: @Array<felt252>,
_voting_strategies: @Array<Strategy>,
_authenticators: @Array<ContractAddress>
_voting_strategy_metadata_URIs: @Array<Array<felt252>>,
_authenticators: @Array<ContractAddress>,
_metadata_URI: @Array<felt252>,
_dao_URI: @Array<felt252>,
) {}

#[event]
fn ProposalCreated(
_proposal_id: u256, _author: UserAddress, _proposal: @Proposal, _payload: @Array<felt252>
_proposal_id: u256,
_author: UserAddress,
_proposal: @Proposal,
_payload: @Array<felt252>,
_metadata_URI: @Array<felt252>
) {}

#[event]
fn VoteCast(_proposal_id: u256, _voter: UserAddress, _choice: Choice, _voting_power: u256) {}
fn VoteCast(
_proposal_id: u256,
_voter: UserAddress,
_choice: Choice,
_voting_power: u256,
_metadata_URI: @Array<felt252>
) {}

#[event]
fn ProposalExecuted(_proposal_id: u256) {}

#[event]
fn ProposalUpdated(_proposal_id: u256, _execution_stategy: @Strategy) {}
fn ProposalUpdated(
_proposal_id: u256, _execution_stategy: @Strategy, _metadata_URI: @Array<felt252>
) {}

#[event]
fn ProposalCancelled(_proposal_id: u256) {}

#[event]
fn VotingStrategiesAdded(
_new_voting_strategies: @Array<Strategy>,
_new_voting_strategy_metadata_uris: @Array<Array<felt252>>
_new_voting_strategy_metadata_URIs: @Array<Array<felt252>>
) {}

#[event]
Expand All @@ -139,10 +158,10 @@ mod Space {
fn AuthenticatorsRemoved(_authenticators: @Array<ContractAddress>) {}

#[event]
fn MetadataURIUpdated(_new_metadata_uri: @Array<felt252>) {}
fn MetadataURIUpdated(_new_metadata_URI: @Array<felt252>) {}

#[event]
fn DaoURIUpdated(_new_dao_uri: @Array<felt252>) {}
fn DaoURIUpdated(_new_dao_URI: @Array<felt252>) {}

#[event]
fn MaxVotingDurationUpdated(_new_max_voting_duration: u32) {}
Expand All @@ -168,7 +187,8 @@ mod Space {
ref self: ContractState,
author: UserAddress,
execution_strategy: Strategy,
user_proposal_validation_params: Array<felt252>
user_proposal_validation_params: Array<felt252>,
metadata_URI: Array<felt252>,
) {
assert_only_authenticator(@self);
let proposal_id = self._next_proposal_id.read();
Expand Down Expand Up @@ -212,15 +232,18 @@ mod Space {

self._next_proposal_id.write(proposal_id + u256 { low: 1_u128, high: 0_u128 });

ProposalCreated(proposal_id, author, snap_proposal, @execution_strategy.params);
ProposalCreated(
proposal_id, author, snap_proposal, @execution_strategy.params, @metadata_URI
);
}

fn vote(
ref self: ContractState,
voter: UserAddress,
proposal_id: u256,
choice: Choice,
user_voting_strategies: Array<IndexedStrategy>
user_voting_strategies: Array<IndexedStrategy>,
metadata_URI: Array<felt252>
) {
assert_only_authenticator(@self);
let proposal = self._proposals.read(proposal_id);
Expand Down Expand Up @@ -255,7 +278,7 @@ mod Space {
);
self._vote_registry.write((proposal_id, voter), true);

VoteCast(proposal_id, voter, choice, voting_power);
VoteCast(proposal_id, voter, choice, voting_power, @metadata_URI);
}

fn execute(ref self: ContractState, proposal_id: u256, execution_payload: Array<felt252>) {
Expand Down Expand Up @@ -284,7 +307,8 @@ mod Space {
ref self: ContractState,
author: UserAddress,
proposal_id: u256,
execution_strategy: Strategy
execution_strategy: Strategy,
metadata_URI: Array<felt252>,
) {
assert_only_authenticator(@self);
let mut proposal = self._proposals.read(proposal_id);
Expand All @@ -303,7 +327,7 @@ mod Space {

self._proposals.write(proposal_id, proposal);

ProposalUpdated(proposal_id, @execution_strategy);
ProposalUpdated(proposal_id, @execution_strategy, @metadata_URI);
}

fn cancel_proposal(ref self: ContractState, proposal_id: u256) {
Expand Down Expand Up @@ -469,8 +493,12 @@ mod Space {
_min_voting_duration: u32,
_voting_delay: u32,
_proposal_validation_strategy: Strategy,
_proposal_validation_strategy_metadata_URI: Array<felt252>,
_voting_strategies: Array<Strategy>,
_voting_strategies_metadata_URIs: Array<Array<felt252>>,
_authenticators: Array<ContractAddress>,
_metadata_URI: Array<felt252>,
_dao_URI: Array<felt252>
) {
//TODO: temporary component syntax
let mut state: Ownable::ContractState = Ownable::unsafe_new_contract_state();
Expand All @@ -490,8 +518,12 @@ mod Space {
_min_voting_duration,
_max_voting_duration,
@_proposal_validation_strategy,
@_proposal_validation_strategy_metadata_URI,
@_voting_strategies,
@_authenticators
@_voting_strategies_metadata_URIs,
@_authenticators,
@_metadata_URI,
@_dao_URI
);
}

Expand Down
Loading

0 comments on commit 82c1a45

Please sign in to comment.