Skip to content

Commit

Permalink
Move things around
Browse files Browse the repository at this point in the history
  • Loading branch information
ligustah committed Apr 23, 2024
1 parent 5828068 commit 33dcf9f
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 55 deletions.
22 changes: 0 additions & 22 deletions src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,8 @@ use futures_util::StreamExt;

use crate::chain_list::{ChainListProvider, CHAINS};
use crate::controller::{ControllerCommands, ControllerInterface};
use crate::premints::zora_premint::types::PREMINT_FACTORY_ADDR;
use crate::types::{InclusionClaim, Premint, PremintTypes};

pub async fn contract_call<T>(call: T, provider: &Arc<ChainListProvider>) -> eyre::Result<T::Return>
where
T: SolCall,
{
provider
.call(
&TransactionRequest {
to: Some(PREMINT_FACTORY_ADDR),
input: TransactionInput::new(Bytes::from(call.abi_encode())),
..Default::default()
},
None,
)
.await
.map_err(|err| eyre::eyre!("Error calling contract: {:?}", err))
.and_then(|response| {
T::abi_decode_returns(&response, false)
.map_err(|err| eyre::eyre!("Error decoding contract response: {:?}", err))
})
}

/// Checks for new premints being brought onchain then sends to controller to handle
pub struct MintChecker {
chain_id: u64,
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clap::Parser;
use mintpool::api;
use mintpool::premints::zora_premint::types::ZoraPremintV2;
use mintpool::premints::zora_premint::v2::ZoraPremintV2;
use mintpool::rules::RulesEngine;
use mintpool::run::{start_p2p_services, start_watch_chain};
use mintpool::stdin::watch_stdin;
Expand Down
40 changes: 40 additions & 0 deletions src/premints/zora_premint/contract.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use std::sync::Arc;

use alloy::rpc::types::eth::{TransactionInput, TransactionRequest};
use alloy_primitives::{address, Address, Bytes};
use alloy_provider::Provider;
use alloy_sol_macro::sol;
use alloy_sol_types::SolCall;
use futures_util::StreamExt;
use serde::{Deserialize, Serialize};

use crate::chain_list::ChainListProvider;

pub static PREMINT_FACTORY_ADDR: Address = address!("7777773606e7e46C8Ba8B98C08f5cD218e31d340");

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

pub async fn contract_call<T>(call: T, provider: &Arc<ChainListProvider>) -> eyre::Result<T::Return>
where
T: SolCall,
{
provider
.call(
&TransactionRequest {
to: Some(PREMINT_FACTORY_ADDR),
input: TransactionInput::new(Bytes::from(call.abi_encode())),
..Default::default()
},
None,
)
.await
.map_err(|err| eyre::eyre!("Error calling contract: {:?}", err))
.and_then(|response| {
T::abi_decode_returns(&response, false)
.map_err(|err| eyre::eyre!("Error decoding contract response: {:?}", err))
})
}
4 changes: 3 additions & 1 deletion src/premints/zora_premint/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
pub mod contract;
pub mod erc20v1;
pub mod rules;
pub mod types;
pub mod v2;
6 changes: 3 additions & 3 deletions src/premints/zora_premint/rules.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::str::FromStr;

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

use crate::chain::contract_call;
use crate::premints::zora_premint::types::{IZoraPremintV2, ZoraPremintV2};
use crate::premints::zora_premint::contract::{contract_call, IZoraPremintV2};
use crate::premints::zora_premint::v2::ZoraPremintV2;
use crate::rules::Evaluation::Accept;
use crate::rules::{Evaluation, Rule, RuleContext};
use crate::storage::Reader;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
use std::borrow::Cow;

use crate::premints::zora_premint::types::IZoraPremintV2::PremintedV2;
use crate::types::{InclusionClaim, Premint, PremintMetadata, PremintName};
use alloy::rpc::types::eth::{Filter, Log, TransactionReceipt};
use alloy::sol_types::private::U256;
use alloy_primitives::{address, Address};
use alloy_sol_macro::sol;
use alloy_primitives::Address;
use alloy_sol_types::{Eip712Domain, SolEvent};
use async_trait::async_trait;
use serde::{Deserialize, Serialize};

sol! {
#[derive(Debug, Serialize, Deserialize, PartialEq)]
IZoraPremintV2,
"src/premints/zora_premint/zora1155PremintExecutor.json"
}
use crate::premints::zora_premint::contract::IZoraPremintV2::PremintedV2;
use crate::premints::zora_premint::contract::{IZoraPremintV2, ZoraPremint, PREMINT_FACTORY_ADDR};
use crate::types::{InclusionClaim, Premint, PremintMetadata, PremintName};

// aliasing the types here for readability. the original name need to stay
// because they impact signature generation
pub type PremintConfig = IZoraPremintV2::CreatorAttribution;
pub type TokenCreationConfig = IZoraPremintV2::TokenCreationConfig;
pub type ContractCreationConfig = IZoraPremintV2::ContractCreationConfig;
pub type PremintConfigV2 = IZoraPremintV2::CreatorAttribution;
pub type TokenCreationConfigV2 = IZoraPremintV2::TokenCreationConfig;
pub type ContractCreationConfigV2 = IZoraPremintV2::ContractCreationConfig;

// modelled after the PremintRequest API type
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct ZoraPremintV2 {
pub collection: ContractCreationConfig,
pub premint: PremintConfig,
pub collection: ContractCreationConfigV2,
pub premint: PremintConfigV2,
pub collection_address: Address,
pub chain_id: u64,
pub signature: String,
Expand All @@ -36,13 +31,13 @@ pub struct ZoraPremintV2 {
impl Default for ZoraPremintV2 {
fn default() -> Self {
Self {
collection: ContractCreationConfig {
collection: ContractCreationConfigV2 {
contractAdmin: Default::default(),
contractURI: "".to_string(),
contractName: "".to_string(),
},
premint: PremintConfig {
tokenConfig: TokenCreationConfig {
premint: PremintConfigV2 {
tokenConfig: TokenCreationConfigV2 {
tokenURI: "".to_string(),
maxSupply: Default::default(),
maxTokensPerAddress: 0,
Expand All @@ -65,8 +60,6 @@ impl Default for ZoraPremintV2 {
}
}

pub static PREMINT_FACTORY_ADDR: Address = address!("7777773606e7e46C8Ba8B98C08f5cD218e31d340");

impl ZoraPremintV2 {
pub fn eip712_domain(&self) -> Eip712Domain {
Eip712Domain {
Expand Down Expand Up @@ -167,3 +160,17 @@ impl Premint for ZoraPremintV2 {
}
}
}

impl ZoraPremint for ZoraPremintV2 {
fn collection_address(&self) -> Address {
self.collection_address
}

fn chain_id(&self) -> u64 {
self.chain_id
}

fn signature(&self) -> String {
self.signature.clone()
}
}
2 changes: 1 addition & 1 deletion src/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ mod general {

#[cfg(test)]
mod test {
use crate::premints::zora_premint::types::ZoraPremintV2;
use crate::premints::zora_premint::v2::ZoraPremintV2;
use crate::rules::general::existing_token_uri;
use crate::rules::Evaluation::{Accept, Reject};
use crate::storage::{PremintStorage, Writer};
Expand Down
2 changes: 1 addition & 1 deletion src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ mod test {
use sqlx::Row;

use crate::config::Config;
use crate::premints::zora_premint::types::ZoraPremintV2;
use crate::premints::zora_premint::v2::ZoraPremintV2;
use crate::storage;
use crate::storage::{
list_all, list_all_with_options, PremintStorage, QueryOptions, Reader, Writer,
Expand Down
6 changes: 3 additions & 3 deletions src/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::premints::zora_premint::types::ZoraPremintV2;
use crate::premints::zora_premint::v2::ZoraPremintV2;
use alloy::rpc::types::eth::{Filter, Log, TransactionReceipt};
use alloy_primitives::{Address, B256, U256};
use async_trait::async_trait;
Expand Down Expand Up @@ -178,10 +178,10 @@ pub struct PeerInclusionClaim {
#[cfg(test)]
mod test {
use super::*;
use crate::premints::zora_premint::types::IZoraPremintV2::{
use crate::premints::zora_premint::contract::IZoraPremintV2::{
ContractCreationConfig, CreatorAttribution, TokenCreationConfig,
};
use crate::premints::zora_premint::types::{IZoraPremintV2, PREMINT_FACTORY_ADDR};
use crate::premints::zora_premint::contract::{IZoraPremintV2, PREMINT_FACTORY_ADDR};
use alloy::rpc::types::eth::ReceiptEnvelope;
use alloy_primitives::{Bytes, LogData};
use alloy_sol_types::SolEvent;
Expand Down
7 changes: 3 additions & 4 deletions tests/e2e_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ use alloy_transport::TransportErrorKind;
use mintpool::api::admin::node_info;
use mintpool::config::{ChainInclusionMode, Config};
use mintpool::controller::{ControllerCommands, DBQuery};
use mintpool::premints::zora_premint::types::IZoraPremintV2::MintArguments;
use mintpool::premints::zora_premint::types::{
IZoraPremintV2, ZoraPremintV2, PREMINT_FACTORY_ADDR,
};
use mintpool::premints::zora_premint::contract::IZoraPremintV2::MintArguments;
use mintpool::premints::zora_premint::contract::{IZoraPremintV2, PREMINT_FACTORY_ADDR};
use mintpool::premints::zora_premint::v2::ZoraPremintV2;
use mintpool::rules::RulesEngine;
use mintpool::run;
use mintpool::types::PremintTypes;
Expand Down

0 comments on commit 33dcf9f

Please sign in to comment.