diff --git a/src/premints/zora_premint/contract.rs b/src/premints/zora_premint/contract.rs index 481758f..d72fe88 100644 --- a/src/premints/zora_premint/contract.rs +++ b/src/premints/zora_premint/contract.rs @@ -25,6 +25,8 @@ sol! { } pub trait ZoraPremint { + const VERSION: &'static str; + fn collection_address(&self) -> Address; fn chain_id(&self) -> u64; fn signature(&self) -> String; diff --git a/src/premints/zora_premint/erc20v1.rs b/src/premints/zora_premint/erc20v1.rs index df47a17..597611b 100644 --- a/src/premints/zora_premint/erc20v1.rs +++ b/src/premints/zora_premint/erc20v1.rs @@ -1,3 +1,10 @@ +use std::borrow::Cow; + +use alloy::sol_types::private::U256; +use alloy_primitives::Address; +use alloy_sol_types::Eip712Domain; +use serde::{Deserialize, Serialize}; + use crate::premints::zora_premint::contract::IZoraPremintERC20V1; // aliasing the types here for readability. the original name need to stay @@ -5,3 +12,64 @@ use crate::premints::zora_premint::contract::IZoraPremintERC20V1; pub type PremintConfigERC20V1 = IZoraPremintERC20V1::CreatorAttribution; pub type TokenCreationConfigERC20V1 = IZoraPremintERC20V1::TokenCreationConfig; pub type ContractCreationConfigERC20V1 = IZoraPremintERC20V1::ContractCreationConfig; + +// modelled after the PremintRequest API type +#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] +#[serde(rename_all = "camelCase")] +pub struct ZoraPremintERC20V1 { + pub collection: ContractCreationConfigERC20V1, + pub premint: PremintConfigERC20V1, + pub collection_address: Address, + pub chain_id: u64, + pub signature: String, +} + +impl Default for ZoraPremintERC20V1 { + fn default() -> Self { + Self { + collection: ContractCreationConfigERC20V1 { + contractAdmin: Default::default(), + contractURI: "".to_string(), + contractName: "".to_string(), + }, + premint: PremintConfigERC20V1 { + tokenConfig: TokenCreationConfigERC20V1 { + tokenURI: "".to_string(), + maxSupply: Default::default(), + maxTokensPerAddress: 0, + currency: Default::default(), + pricePerToken: U256::try_from(0).unwrap(), + mintStart: 0, + mintDuration: 0, + royaltyBPS: 0, + payoutRecipient: Default::default(), + createReferral: Default::default(), + erc20Minter: Default::default(), + }, + uid: 0, + version: 0, + deleted: false, + }, + collection_address: Address::default(), + chain_id: 0, + signature: String::default(), + } + } +} + +impl ZoraPremintERC20V1 { + pub fn eip712_domain(&self) -> Eip712Domain { + Eip712Domain { + name: Some(Cow::from("Preminter")), + version: Some(Cow::from("ERC20_1")), + chain_id: Some(U256::from(self.chain_id)), + verifying_contract: Some(self.collection_address), + salt: None, + } + } + + /// Recreate a deterministic GUID for a premint + fn event_to_guid(chain_id: u64, event: &IZoraPremintERC20V1::Preminted) -> String { + format!("{:?}:{:?}:{:?}", chain_id, event.contractAddress, event.uid) + } +} diff --git a/src/premints/zora_premint/rules.rs b/src/premints/zora_premint/rules.rs index 97c4029..eeeee71 100644 --- a/src/premints/zora_premint/rules.rs +++ b/src/premints/zora_premint/rules.rs @@ -13,8 +13,8 @@ use crate::{ignore, reject, typed_rule}; // create premint v2 rule implementations here -pub async fn is_authorized_to_create_premint( - premint: &ZoraPremintV2, +pub async fn is_authorized_to_create_premint( + premint: &P, context: &RuleContext, ) -> eyre::Result { let rpc = match context.rpc { @@ -73,7 +73,7 @@ pub async fn premint_version_supported( let result = view_contract_call(call, rpc, PREMINT_FACTORY_ADDR).await?; - match result.versions.contains(&"2".to_string()) { + match result.versions.contains(&"ERC20_1".to_string()) { true => Ok(Accept), false => reject!("Premint version 2 not supported by contract"), }