Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ERC20 types #50

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/premints/zora_premint/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ sol! {
"src/premints/zora_premint/zora1155PremintExecutor_erc20v1.json"
}

sol! {
#[derive(Debug, Serialize, Deserialize, PartialEq)]
IZoraPremintV2,
"src/premints/zora_premint/zora1155PremintExecutor_v2.json"
}

pub trait ZoraPremint {
const VERSION: &'static str;

fn collection_address(&self) -> Address;
fn chain_id(&self) -> u64;
fn signature(&self) -> String;
}

pub async fn contract_call<T>(call: T, provider: &Arc<ChainListProvider>) -> eyre::Result<T::Return>
where
T: SolCall,
Expand Down
75 changes: 75 additions & 0 deletions src/premints/zora_premint/erc20v1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +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)
}
}
11 changes: 6 additions & 5 deletions src/premints/zora_premint/rules.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::str::FromStr;

use alloy_primitives::{address, Address, Signature};
use alloy_primitives::Signature;
use alloy_sol_types::SolStruct;

use crate::chain::view_contract_call;
use crate::premints::zora_premint::contract::{IZoraPremintV2, PREMINT_FACTORY_ADDR};
use crate::premints::zora_premint::v2::ZoraPremintV2;
use crate::rules::Evaluation::Accept;
use crate::rules::{Evaluation, Rule, RuleContext};
Expand All @@ -13,16 +14,16 @@ 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 {
None => return ignore!("Rule requires RPC call"),
Some(ref rpc) => rpc,
};

let call = ZoraPremintV2::isAuthorizedToCreatePremintCall {
let call = IZoraPremintV2::isAuthorizedToCreatePremintCall {
contractAddress: premint.collection_address,
signer: premint.collection.contractAdmin,
premintContractConfigContractAdmin: premint.collection.contractAdmin,
Expand Down Expand Up @@ -73,7 +74,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
Loading