diff --git a/dnas/grant_pools/zomes/integrity/grants/src/agent_to_evm_wallet.rs b/dnas/grant_pools/zomes/integrity/grants/src/agent_to_evm_wallet.rs index 5edd4da..6412ead 100644 --- a/dnas/grant_pools/zomes/integrity/grants/src/agent_to_evm_wallet.rs +++ b/dnas/grant_pools/zomes/integrity/grants/src/agent_to_evm_wallet.rs @@ -2,22 +2,26 @@ use alloy_primitives::Address; use hdi::prelude::*; pub fn validate_create_link_agent_to_evm_wallet( - _action: CreateLink, + action: CreateLink, base_address: AnyLinkableHash, target_address: AnyLinkableHash, _tag: LinkTag, ) -> ExternResult { + let author_pubkey = base_address + .into_agent_pub_key() + .ok_or(wasm_error!("Base address must be an AgentPubKey"))?; + if action.author != author_pubkey { + return Ok(ValidateCallbackResult::Invalid( + "Cannot add wallet for another agent besides yourself".to_string(), + )); + } let evm_address = String::from_utf8(target_address.into_inner()).map_err(|e| { wasm_error!(WasmErrorInner::Guest(format!( "Error converting target address to string: {:?}", e ))) })?; - if !AgentPubKey::try_from(base_address).is_ok() { - return Ok(ValidateCallbackResult::Invalid( - "Can only link wallet from an AgentPubKey".to_string(), - )); - } + if !Address::parse_checksummed(&evm_address, None).is_ok() { return Ok(ValidateCallbackResult::Invalid( "Can only link to valid evm address".to_string(), diff --git a/dnas/grant_pools/zomes/integrity/grants/src/grant_pool.rs b/dnas/grant_pools/zomes/integrity/grants/src/grant_pool.rs index f1e53ac..a257c8d 100644 --- a/dnas/grant_pools/zomes/integrity/grants/src/grant_pool.rs +++ b/dnas/grant_pools/zomes/integrity/grants/src/grant_pool.rs @@ -41,6 +41,17 @@ pub fn validate_create_grant_pool( "Evaluators cannot be empty".to_string(), )); } + if grant_pool.amount_range.min > grant_pool.amount_range.min { + return Ok(ValidateCallbackResult::Invalid( + "Amount range max must be greater than min".to_string(), + )); + } + if grant_pool.evaluators.len() == 0 { + return Ok(ValidateCallbackResult::Invalid( + "Must have at least one evaluator".to_string(), + )); + } + let record = must_get_valid_record(grant_pool.time_period.clone())?; let _time_period: crate::TimePeriod = record .entry() diff --git a/dnas/grant_pools/zomes/integrity/grants/src/grant_pool_to_applications.rs b/dnas/grant_pools/zomes/integrity/grants/src/grant_pool_to_applications.rs index 5071531..e89bb54 100644 --- a/dnas/grant_pools/zomes/integrity/grants/src/grant_pool_to_applications.rs +++ b/dnas/grant_pools/zomes/integrity/grants/src/grant_pool_to_applications.rs @@ -5,12 +5,13 @@ pub fn validate_create_link_grant_pool_to_application( target_address: AnyLinkableHash, _tag: LinkTag, ) -> ExternResult { - let action_hash = base_address - .into_action_hash() - .ok_or(wasm_error!(WasmErrorInner::Guest(String::from( - "No action hash associated with link" - ))))?; - let record = must_get_valid_record(action_hash)?; + let base_action_hash = + base_address + .into_action_hash() + .ok_or(wasm_error!(WasmErrorInner::Guest(String::from( + "No action hash associated with link" + ))))?; + let record = must_get_valid_record(base_action_hash.clone())?; let _grant_pool: crate::GrantPool = record .entry() .to_app_option() @@ -25,13 +26,18 @@ pub fn validate_create_link_grant_pool_to_application( "No action hash associated with link" ))))?; let record = must_get_valid_record(action_hash)?; - let _application: crate::Application = record + let application: crate::Application = record .entry() .to_app_option() .map_err(|e| wasm_error!(e))? .ok_or(wasm_error!(WasmErrorInner::Guest(String::from( "Linked action must reference an entry" ))))?; + if application.grant_pool != base_action_hash { + return Ok(ValidateCallbackResult::Invalid( + "Base address must be the Grant Pool action hash".to_string(), + )); + } Ok(ValidateCallbackResult::Valid) } pub fn validate_delete_link_grant_pool_to_applications( diff --git a/dnas/grant_pools/zomes/integrity/grants/src/sponsor_to_grant_pools.rs b/dnas/grant_pools/zomes/integrity/grants/src/sponsor_to_grant_pools.rs index c7801f8..8593881 100644 --- a/dnas/grant_pools/zomes/integrity/grants/src/sponsor_to_grant_pools.rs +++ b/dnas/grant_pools/zomes/integrity/grants/src/sponsor_to_grant_pools.rs @@ -1,11 +1,19 @@ use alloy_primitives::U256; use hdi::prelude::*; pub fn validate_create_link_sponsor_to_grant_pool( - _action: CreateLink, - _base_address: AnyLinkableHash, + action: CreateLink, + base_address: AnyLinkableHash, target_address: AnyLinkableHash, tag: LinkTag, ) -> ExternResult { + let author_pubkey = base_address + .into_agent_pub_key() + .ok_or(wasm_error!("Base address must be an AgentPubKey"))?; + if action.author != author_pubkey { + return Ok(ValidateCallbackResult::Invalid( + "Author not valid, can only add yourself as a sponsor".to_string(), + )); + } if U256::from_le_slice(&tag.into_inner()) == U256::from(0) { return Ok(ValidateCallbackResult::Invalid( "amount cannot be zero".to_string(),