Skip to content

Commit

Permalink
contracts: update contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
credence0x committed Feb 21, 2024
1 parent 724b975 commit 5a1296c
Show file tree
Hide file tree
Showing 15 changed files with 357 additions and 515 deletions.
44 changes: 0 additions & 44 deletions contracts/deployment.ansi

This file was deleted.

93 changes: 43 additions & 50 deletions contracts/scripts/assigned_custom.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,47 @@
export const initial_assigned_recipients = () => {
return [
0x059f9205f50528a4c6308c69c675c14e65f31c72b1f7f1d2375d04fae1eec540n,
0x059f9205f50528a4c6308c69c675c14e65f31c72b1f7f1d2375d04fae1eec541n,
0x059f9205f50528a4c6308c69c675c14e65f31c72b1f7f1d2375d04fae1eec542n,
0x059f9205f50528a4c6308c69c675c14e65f31c72b1f7f1d2375d04fae1eec543n,
0x059f9205f50528a4c6308c69c675c14e65f31c72b1f7f1d2375d04fae1eec544n,
0x059f9205f50528a4c6308c69c675c14e65f31c72b1f7f1d2375d04fae1eec545n,
0x059f9205f50528a4c6308c69c675c14e65f31c72b1f7f1d2375d04fae1eec546n,
0x059f9205f50528a4c6308c69c675c14e65f31c72b1f7f1d2375d04fae1eec547n,
0x059f9205f50528a4c6308c69c675c14e65f31c72b1f7f1d2375d04fae1eec548n,
0x059f9205f50528a4c6308c69c675c14e65f31c72b1f7f1d2375d04fae1eec549n,
0x049f9205f50528a4c6308c69c675c14e65f31c72b1f7f1d2375d04fae0eec546n,
0x049f9205f50528a4c6308c69c675c14e65f31c72b1f7f1d2375d04fae1eec546n,
0x049f9205f50528a4c6308c69c675c14e65f31c72b1f7f1d2375d04fae2eec546n,
0x049f9205f50528a4c6308c69c675c14e65f31c72b1f7f1d2375d04fae3eec546n,
0x049f9205f50528a4c6308c69c675c14e65f31c72b1f7f1d2375d04fae4eec546n,
0x049f9205f50528a4c6308c69c675c14e65f31c72b1f7f1d2375d04fae5eec546n,
0x049f9205f50528a4c6308c69c675c14e65f31c72b1f7f1d2375d04fae6eec546n,
0x049f9205f50528a4c6308c69c675c14e65f31c72b1f7f1d2375d04fae7eec546n,
0x049f9205f50528a4c6308c69c675c14e65f31c72b1f7f1d2375d04fae8eec546n,
0x049f9205f50528a4c6308c69c675c14e65f31c72b1f7f1d2375d04fae9eec546n,
0x039f9205f50528a4c6308c69c675c14e65f31c72b1f7f1d2375d04fae1eec546n,
0x039f9205f50528a4c6308c69c675c14e65f31c72b1f7f1d2375d14fae1eec546n,
0x039f9205f50528a4c6308c69c675c14e65f31c72b1f7f1d2375d24fae1eec546n,
0x039f9205f50528a4c6308c69c675c14e65f31c72b1f7f1d2375d34fae1eec546n,
0x039f9205f50528a4c6308c69c675c14e65f31c72b1f7f1d2375d44fae1eec546n,
0x039f9205f50528a4c6308c69c675c14e65f31c72b1f7f1d2375d54fae1eec546n,
0x039f9205f50528a4c6308c69c675c14e65f31c72b1f7f1d2375d64fae1eec546n,
0x039f9205f50528a4c6308c69c675c14e65f31c72b1f7f1d2375d74fae1eec546n,
0x039f9205f50528a4c6308c69c675c14e65f31c72b1f7f1d2375d84fae1eec546n,
0x039f9205f50528a4c6308c69c675c14e65f31c72b1f7f1d2375d94fae1eec546n,
0x029f9205f50528a4c6308c69c675c14e65f31c02b1f7f1d2375d04fae1eec546n,
0x029f9205f50528a4c6308c69c675c14e65f31c12b1f7f1d2375d04fae1eec546n,
0x029f9205f50528a4c6308c69c675c14e65f31c22b1f7f1d2375d04fae1eec546n,
0x029f9205f50528a4c6308c69c675c14e65f31c32b1f7f1d2375d04fae1eec546n,
0x029f9205f50528a4c6308c69c675c14e65f31c42b1f7f1d2375d04fae1eec546n,
0x029f9205f50528a4c6308c69c675c14e65f31c52b1f7f1d2375d04fae1eec546n,
0x029f9205f50528a4c6308c69c675c14e65f31c62b1f7f1d2375d04fae1eec546n,
0x029f9205f50528a4c6308c69c675c14e65f31c72b1f7f1d2375d04fae1eec546n,
0x029f9205f50528a4c6308c69c675c14e65f31c82b1f7f1d2375d04fae1eec546n,
0x029f9205f50528a4c6308c69c675c14e65f31c92b1f7f1d2375d04fae1eec546n,
0x019f9205f50528a0c6308c69c675c14e65f31c72b1f7f1d2375d04fae1eec546n,
0x019f9205f50528a1c6308c69c675c14e65f31c72b1f7f1d2375d04fae1eec546n,
0x019f9205f50528a2c6308c69c675c14e65f31c72b1f7f1d2375d04fae1eec546n,
0x019f9205f50528a3c6308c69c675c14e65f31c72b1f7f1d2375d04fae1eec546n,
0x019f9205f50528a4c6308c69c675c14e65f31c72b1f7f1d2375d04fae1eec546n,
0x019f9205f50528a5c6308c69c675c14e65f31c72b1f7f1d2375d04fae1eec546n,
0x019f9205f50528a6c6308c69c675c14e65f31c72b1f7f1d2375d04fae1eec546n,
0x019f9205f50528a7c6308c69c675c14e65f31c72b1f7f1d2375d04fae1eec546n,
0x019f9205f50528a8c6308c69c675c14e65f31c72b1f7f1d2375d04fae1eec546n,
0x019f9205f50528a9c6308c69c675c14e65f31c72b1f7f1d2375d04fae1eec546n
0x0140809B710276e2e07c06278DD8f7D4a2528acE2764Fce32200852CB3893e5Cn,
0x0140809B710276e2e07c06278DD8f7D4a2528acE2764Fce32200852CB3893e5Cn,
0x0140809B710276e2e07c06278DD8f7D4a2528acE2764Fce32200852CB3893e5Cn,
0x0140809B710276e2e07c06278DD8f7D4a2528acE2764Fce32200852CB3893e5Cn,
0x0140809B710276e2e07c06278DD8f7D4a2528acE2764Fce32200852CB3893e5Cn,
0x0140809B710276e2e07c06278DD8f7D4a2528acE2764Fce32200852CB3893e5Cn,
0x06b82A7d520520170c12dCbbaa3c6Ea1e8D92c4d5F666dA0b53B849F50BA6e34n,
0x03C63FFBBB09b7E7D74F85e95c85255829Ad79b59E3D63Cb66E635c12fFAf08bn,
0x059df66Af2E0E350842b11eA6b5a903b94640C4ff0418b04cCedCC320f531a08n,
0x03d8C60d464f955649961d25Db646a6b747f64Bf94248f318305d686EBa79222n,
0x0718297C0325F9bCc741C0a9EA4ffdAF6Da39dFfCDd3942010209f64f2dCd0c2n,
0x01fF92Ff13931e47Ef0ecF3D0a35bE357f8Cc620e22B2A4B2aaD9d788599DB00n,
0x0716e39b21fe7062421cb0056e1e3323ded9e9154915c0e89f1c9dff206ba459n,
0x04645f67e3e195420b2b4e63742153623e50c143ed8b89c91e3fb908fe87b168n,
0x027697aDf2B1c0C73008975f3CAeB75D556a0F5C480E93a9fe9E4633D68e3742n,
0x04213958BD73a06D198a1D2dD2327AaB060B7cc0E21895b5f9C72542cAd293C7n,
0x00f17Ed74a9C346194feb4EbcecABCBf41FA814fe89B6E94D2d79810074fb9B2n,
0x022AbBc2808356e8303c0704EB4204De03Ee3d50fee9bE2895c7757a80616B63n,
0x0261069892eca8e8d4d45b31a36eed8b188aaa9c3b4afc43e799f6a8ee3ff158n,
0x05b0a0def8c8eea7c4b1002502386c067d218d95a8346b0842f7b8cd53447201n,
0x066f04F184ddBc8E10D53540b724a336bDA64222d916f277030Ec9d99CF99460n,
0x01AC519950FE43b010547c9Ee01aa5D20E304e86244E18eab45605D4CfB0fb2En,
0x074f91d284351a8603933b648684b6a990126d7c78a1b867353a57a3bc2097dan,
0x007d3246639Ed9e666c5CeB9b4DC533F731aF1c866487977e0474d0465A73426n,
0x071538f6445e0c6179b786230a3e7b5ddee40b72673a9b5a395da20f4657bdcan,
0x067074c26d36f899e658e1920d2a9b0b100cea7325d4b8b9e6c90895d391b31en,
0x070d63df9b573f86ccd002d78f19b242232f7e108ae8652b7756ff46734d8b35n,
0x04649766c7c55a0ca90f18b8c6a20f990e77de5a5c65e369c75a001668f6726cn,
0x06dc505410A839B59E1D1D72d4a73f3840f4b2620b04CDdF97eC0c0c02821229n,
0x064f10de7cecb815628e63dc5c8e306c7bbcbd8d198627c191ce010fa838b383n,
0x0437f0c46545db400f40fffdbc8a34090c506d1a1bb25aeb500cc3c884c94e54n,
0x0116dC42c0112D70c747fea0289f065F99D87b48d8aECeaCea361d99B741824Cn,
0x052dCf1aD1A12A08Ad1f1352b16c71970D0c902E74E2A66745a1DD2BdE7501CCn,
0x06F490C0ec49FE17148af6F83eBEBd9d31E5a06dC46BDBE5c5E0657c23A4fF4Fn,
0x02dD93bcFc6DcB21083f9E045066c54A45e0AEFB00a6C79eB5286eE0e1801504n,
0x074c2664Cfc8aFf6B1e24beFa444488f89a060F9A58550Cd5Ef1f9c4809a80c3n,
0x03474353878b236171e4c08e52465d9f2cf6c3babf726cc292ff1566e68612c3n,
0x05c387425d73abc847ca158f6a5da1eaa34f2c024d195de70a4c522fe8eb4b5cn,
0x057C5f91dFcc92DDD02f496C9fa7994b8366f60A66a3A3E698aF5D4628f5bdE9n,
0x044c539d381e704ea8be6352f6faeb72435215d52335d56e48ed4b3a1c7f37d9n,
0x03f60afe30844f556ac1c674678ac4447840b1c6c26854a2df6a8a3d2c015610n,
0x00579ed214135f8ed807110d417e47171bdbf9f2c82823361e85428e05f00498n,
0x01204b45bec455e3219c507da28829eb0523d1ae7fae4df69284e22a287ebba2n
];
}
32 changes: 29 additions & 3 deletions contracts/src/blobert.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ trait IBlobert<TContractState> {
// contract state read
fn supply(self: @TContractState) -> Supply;
fn max_supply(self: @TContractState) -> u16;
fn whitelist_mint_count(self: @TContractState, address: ContractAddress) -> u8;
fn regular_mint_count(self: @TContractState, address: ContractAddress) -> u8;
fn content_uri(self: @TContractState, token_id: u256) -> ByteArray;
fn traits(self: @TContractState, token_id: u256) -> TokenTrait;
fn svg_image(self: @TContractState, token_id: u256) -> ByteArray;

Expand Down Expand Up @@ -119,9 +122,9 @@ mod Blobert {
const MAX_MINT_WHITELIST_TIER_4: u8 = 1;

// define weights for custom token lottery
// minter is 500 times more likely to lose than win
// minter is 300 times more likely to lose than win
const WIN_CUSTOM_TOKEN_DRAW_WEIGHT: u128 = 1;
const LOSE_CUSTOM_TOKEN_DRAW_WEIGHT: u128 = 500;
const LOSE_CUSTOM_TOKEN_DRAW_WEIGHT: u128 = 300;


mod Errors {
Expand Down Expand Up @@ -278,6 +281,18 @@ mod Blobert {
MAX_SUPPLY
}

fn whitelist_mint_count(self: @ContractState, address: ContractAddress) -> u8 {
self.num_whitelist_mints.read(
address
)
}

fn regular_mint_count(self: @ContractState, address: ContractAddress) -> u8 {
self.num_regular_mints.read(
address
)
}

fn traits(self: @ContractState, token_id: u256) -> TokenTrait {
assert(self.erc721._exists(token_id), ERC721Component::Errors::INVALID_TOKEN_ID);

Expand All @@ -291,6 +306,17 @@ mod Blobert {
}
}


fn content_uri(self: @ContractState, token_id: u256) -> ByteArray {
let traits = self.traits(token_id);
match traits {
TokenTrait::Regular(seed) => { self.descriptor_regular.read().content_uri(token_id, seed) },
TokenTrait::Custom(index) => { self.descriptor_custom.read().content_uri(token_id, index) }
}
}



fn svg_image(self: @ContractState, token_id: u256) -> ByteArray {
let traits = self.traits(token_id);
match traits {
Expand Down Expand Up @@ -538,7 +564,7 @@ mod Blobert {
recipient: ContractAddress,
collect_fee: bool
) {
// ensure that token count is less than max supply
// ensure that token count is less than or equal max supply
assert(token_id <= self.max_supply(), Errors::MAX_SUPPLY_EXCEEDED);

// type cast token_id
Expand Down
113 changes: 24 additions & 89 deletions contracts/src/descriptor/descriptor_custom.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use blob::types::seeder::Seed;
trait IDescriptorCustom<TContractState> {
fn custom_count(self: @TContractState) -> u8;
fn custom(self: @TContractState, index: u8) -> (ByteArray, ByteArray);

fn token_uri(self: @TContractState, token_id: u256, index: u8) -> ByteArray;
fn content_uri(self: @TContractState, token_id: u256, index: u8) -> ByteArray;
fn svg_image(self: @TContractState, index: u8) -> ByteArray;
}

Expand All @@ -15,6 +15,7 @@ trait IDescriptorCustom<TContractState> {
mod DescriptorCustom {
use blob::descriptor::descriptor_custom::IDescriptorCustom;
use blob::generation::{custom::image::CUSTOM_IMAGES_COUNT};
use blob::generation::{custom::image::custom_images};
use blob::types::descriptor::{ImageType, RenderType};

use blob::types::seeder::Seed;
Expand All @@ -24,24 +25,9 @@ mod DescriptorCustom {

use starknet::ContractAddress;

use super::ICustomDataDescriptorDispatcher;
use super::ICustomDataDescriptorDispatcherTrait;


#[storage]
struct Storage {
custom_data_contract_0_19: ContractAddress,
custom_data_contract_20_39: ContractAddress,
custom_data_contract_40_47: ContractAddress,
}
struct Storage {}

#[constructor]
fn constructor(ref self: ContractState, custom_data_contracts: Span<felt252>) {
assert(custom_data_contracts.len() == 3, 'expected 3 data contracts');
self.custom_data_contract_0_19.write((*custom_data_contracts[0]).try_into().unwrap());
self.custom_data_contract_20_39.write((*custom_data_contracts[1]).try_into().unwrap());
self.custom_data_contract_40_47.write((*custom_data_contracts[2]).try_into().unwrap());
}


#[abi(embed_v0)]
Expand All @@ -52,20 +38,19 @@ mod DescriptorCustom {

fn custom(self: @ContractState, index: u8) -> (ByteArray, ByteArray) {
assert(index < self.custom_count(), 'descriptor: index out of range');
let contract_address = if index < 20 {
self.custom_data_contract_0_19.read()
} else if (index < 40) {
self.custom_data_contract_20_39.read()
} else {
self.custom_data_contract_40_47.read()
};
ICustomDataDescriptorDispatcher { contract_address }.custom(index)
custom_images(index)
}

fn token_uri(self: @ContractState, token_id: u256, index: u8) -> ByteArray {
self.data_uri(token_id, index)
self.data_uri(token_id, index, include_image: true)
}

fn content_uri(self: @ContractState, token_id: u256, index: u8) -> ByteArray {
self.data_uri(token_id, index, include_image: false)
}



fn svg_image(self: @ContractState, index: u8) -> ByteArray {
let (image_bytes, _) = self.custom(index);
self.construct_image(:image_bytes, image_type: RenderType::Svg)
Expand All @@ -75,21 +60,22 @@ mod DescriptorCustom {

#[generate_trait]
impl InternalImpl of InternalTrait {
fn data_uri(self: @ContractState, token_id: u256, index: u8) -> ByteArray {
fn data_uri(self: @ContractState, token_id: u256, index: u8, include_image: bool) -> ByteArray {
let (image_bytes, image_name) = self.custom(index);

let image: ByteArray = self
.construct_image(:image_bytes, image_type: RenderType::Base64Encoded);

let attributes: Span<ByteArray> = self.construct_attributes(image_name);
let attributes: Span<ByteArray> = self.construct_attributes(image_name.clone());

let type_: ByteArray = format!("{}", ImageType::CUSTOM);

let metadata: ByteArray = JsonImpl::new()
.add("name", self.get_token_name(token_id))
.add("description", self.get_token_description(token_id))
.add("type", type_)
.add("image", image)
let metadata = JsonImpl::new()
.add("name", self.get_token_name(image_name.clone(), token_id))
.add("description", self.get_token_description(image_name.clone(), token_id))
.add("type", type_);
let metadata = if include_image {metadata.add("image", image)} else {metadata};
let metadata = metadata
.add_array("attributes", attributes)
.build();

Expand All @@ -113,6 +99,7 @@ mod DescriptorCustom {
let svg_root: Tag = TagImpl::new("svg")
.attr("xmlns", "http://www.w3.org/2000/svg")
.attr("preserveAspectRatio", "xMinYMin meet")
.attr("style", "image-rendering: pixelated")
.attr("viewBox", "0 0 350 350");

let svg = svg_root.insert(image).build();
Expand All @@ -134,64 +121,12 @@ mod DescriptorCustom {
}


fn get_token_name(self: @ContractState, token_id: u256) -> ByteArray {
return format!("Blobert #{}", token_id);
}

fn get_token_description(self: @ContractState, token_id: u256) -> ByteArray {
//todo@credence confirm this message
return format!("Blobert #{} is a member of the BibliothecaDAO", token_id);
}
}
}


#[starknet::interface]
trait ICustomDataDescriptor<TContractState> {
fn custom(self: @TContractState, index: u8) -> (ByteArray, ByteArray);
}

#[starknet::contract]
mod DescriptorCustomData1 {
use blob::generation::{custom::image::custom_images_0_19};

#[storage]
struct Storage {}

#[abi(embed_v0)]
impl CustomDataDescriptor of super::ICustomDataDescriptor<ContractState> {
fn custom(self: @ContractState, index: u8) -> (ByteArray, ByteArray) {
custom_images_0_19(index)
}
}
}

#[starknet::contract]
mod DescriptorCustomData2 {
use blob::generation::{custom::image::custom_images_20_39};

#[storage]
struct Storage {}

#[abi(embed_v0)]
impl CustomDataDescriptor of super::ICustomDataDescriptor<ContractState> {
fn custom(self: @ContractState, index: u8) -> (ByteArray, ByteArray) {
custom_images_20_39(index)
fn get_token_name(self: @ContractState, name: ByteArray, token_id: u256) -> ByteArray {
return format!("{} #{}", name, token_id);
}
}
}

#[starknet::contract]
mod DescriptorCustomData3 {
use blob::generation::{custom::image::custom_images_40_47};

#[storage]
struct Storage {}

#[abi(embed_v0)]
impl CustomDataDescriptor of super::ICustomDataDescriptor<ContractState> {
fn custom(self: @ContractState, index: u8) -> (ByteArray, ByteArray) {
custom_images_40_47(index)
fn get_token_description(self: @ContractState, name: ByteArray, token_id: u256) -> ByteArray {
return format!("{} #{} is a squire from Realms World", name, token_id);
}
}
}
Loading

0 comments on commit 5a1296c

Please sign in to comment.