Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ligustah committed Apr 26, 2024
1 parent ecf9293 commit 3fccd41
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/premints/zora_premint/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
68 changes: 68 additions & 0 deletions src/premints/zora_premint/erc20v1.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,75 @@
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
// because they impact signature generation
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)
}
}
6 changes: 3 additions & 3 deletions src/premints/zora_premint/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use crate::{ignore, reject, typed_rule};

// create premint v2 rule implementations here

pub async fn is_authorized_to_create_premint<T: Reader>(
premint: &ZoraPremintV2,
pub async fn is_authorized_to_create_premint<T: Reader, P>(
premint: &P,
context: &RuleContext<T>,
) -> eyre::Result<Evaluation> {
let rpc = match context.rpc {
Expand Down Expand Up @@ -73,7 +73,7 @@ pub async fn premint_version_supported<T: Reader>(

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"),
}
Expand Down

0 comments on commit 3fccd41

Please sign in to comment.