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

Feat/token uris #145

Merged
merged 5 commits into from
Feb 9, 2025
Merged
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
5,573 changes: 2,809 additions & 2,764 deletions scripts/src/abi/hub.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions scripts/src/contracts/community.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ const execute_create_community = async() =>{
}

const execute_create_channel = async() =>{
let community_id = cairo.uint256(7);
let channel_id = cairo.uint256(15);
let community_id = cairo.uint256(9);

let call: Call = {
to: coloniz_HUB_CONTRACT_ADDRESS, //coloniz_HUB_CONTRACT_ADDRESS,
selector:"0x033a3cd19c446a4483d4288f10983bf9316ce813aa8ee81acae99b36fc6022d0",
calldata: CallData.compile([community_id])
calldata: CallData.compile([channel_id, community_id])
}

try {
Expand Down
59 changes: 57 additions & 2 deletions src/base/token_uris/community_token_uri.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,60 @@
pub mod CommunityTokenUri {
pub fn get_token_uri(token_id: u256, mint_timestamp: u64) -> ByteArray {
"TODO"
use coloniz::base::utils::byte_array_extra::FeltTryIntoByteArray;
use coloniz::base::utils::base64_extended::get_base64_encode;
use coloniz::base::token_uris::traits::community::community::get_svg_community;

pub fn get_token_uri(token_id: u256, community_id: u256, timestamp: u64) -> ByteArray {
let baseuri = 'data:image/svg+xml;base64,';

let mut svg_byte_array: ByteArray = get_svg_community(token_id, community_id);
let mut svg_encoded: ByteArray = get_base64_encode(svg_byte_array);

let mut attribute_byte_array: ByteArray = get_attributes(
token_id, ref svg_encoded, community_id, timestamp
);

let mut token_uri: ByteArray = baseuri.try_into().unwrap();
token_uri.append(@attribute_byte_array);
token_uri
}

fn get_attributes(
token_id: u256, ref svg_encoded_byteArray: ByteArray, community_id: u256, timestamp: u64
) -> ByteArray {
let token_id_to_felt: felt252 = token_id.low.into();
let community_id_to_felt: felt252 = community_id.low.into();
let timestamp_to_felt: felt252 = timestamp.try_into().unwrap();

let mut attributespre: ByteArray = Default::default();
let mut attributespost: ByteArray = Default::default();

attributespre.append(@"{\"name\":\"Community #");
attributespre.append(@format!("{}", community_id_to_felt));
attributespre.append(@"\",\"description\":\" ");
attributespre.append(@"Coloniz - #");
attributespre.append(@format!("{}", token_id_to_felt));
attributespre.append(@" of Community ");
attributespre.append(@format!("{}", community_id_to_felt));
attributespre.append(@"\",\"image\":\"data:image");
attributespre.append(@"/svg+xml;base64,");

//post base64 follow svg
attributespost.append(@"\",\"attributes\":[{\"display");
attributespost.append(@"_type\":\"number\",\"trait_type");
attributespost.append(@"\":\"ID\",\"value\":\"");
attributespost.append(@format!("{}", token_id_to_felt));
attributespost.append(@"\"},{\"trait_type\":\"mint");
attributespost.append(@"_timestamp\",\"value\":\"");
attributespost.append(@format!("{}", timestamp_to_felt));
attributespost.append(@"\"},{\"trait_type\":\"community");
attributespost.append(@"_id\",\"value\":\"");
attributespost.append(@format!("{}", community_id_to_felt));
attributespost.append(@"\"}]}");

attributespre.append(@svg_encoded_byteArray);
attributespre.append(@attributespost);

get_base64_encode(attributespre)
}
}

72 changes: 36 additions & 36 deletions src/base/token_uris/follow_token_uri.cairo
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
pub mod FollowTokenUri {
use starknet::ContractAddress;
use coloniz::base::utils::byte_array_extra::FeltTryIntoByteArray;
use coloniz::base::utils::base64_extended::{convert_into_byteArray, get_base64_encode};
use coloniz::base::utils::base64_extended::get_base64_encode;
use coloniz::base::token_uris::traits::follow::follow::get_svg_follow;

pub fn get_token_uri(
follow_token_id: u256, followed_profile_address: ContractAddress, follow_timestamp: u64
) -> ByteArray {
let baseuri = 'data:image/svg+xml;base64,';
/// TODO what are feaature include in the svg

let mut svg_byte_array: ByteArray = get_svg_follow(follow_token_id);
let mut svg_encoded: ByteArray = get_base64_encode(svg_byte_array);

let mut attribute_byte_array: ByteArray = get_attributes(
follow_token_id, ref svg_encoded, followed_profile_address, follow_timestamp
);

let mut token_uri: ByteArray = baseuri.try_into().unwrap();
token_uri.append(@attribute_byte_array);
token_uri
Expand All @@ -26,40 +28,38 @@ pub mod FollowTokenUri {
follow_timestamp: u64
) -> ByteArray {
let token_id_felt: felt252 = token_id.try_into().unwrap();
let follow_profile_address_felt: felt252 = followed_profile_address.try_into().unwrap();
let follow_prfile_address_byte: ByteArray = follow_profile_address_felt.try_into().unwrap();
let follow_prfile_address_byte_len: felt252 = follow_prfile_address_byte
.len()
.try_into()
.unwrap();
let mut attributespre = ArrayTrait::<felt252>::new();
let mut attributespost = ArrayTrait::<felt252>::new();
attributespre.append('{"name":"Follower #');
attributespre.append(token_id_felt);
attributespre.append('","description":"Lens ');
attributespre.append('Protocol - Follower @');
attributespre.append(token_id_felt);
attributespre.append(' of Profile #');
attributespre.append(follow_profile_address_felt);
attributespre.append('","image":"data:image');
attributespre.append('/svg+xml;base64,');
let followed_profile_address_felt: felt252 = followed_profile_address.try_into().unwrap();
let follow_timestamp_felt: felt252 = follow_timestamp.try_into().unwrap();

let mut attributespre: ByteArray = Default::default();
let mut attributespost: ByteArray = Default::default();

attributespre.append(@"{\"name\":\"Follower #");
attributespre.append(@format!("{}", token_id_felt));
attributespre.append(@"\",\"description\":\" ");
attributespre.append(@"Coloniz - Follower #");
attributespre.append(@format!("{}", token_id_felt));
attributespre.append(@" of Profile ");
attributespre.append(@format!("{}", followed_profile_address_felt));
attributespre.append(@"\",\"image\":\"data:image");
attributespre.append(@"/svg+xml;base64,");

//post base64 follow svg
attributespost.append('","attributes":[{"display');
attributespost.append('_type":"number","trait_type');
attributespost.append('":"ID","value":"');
attributespost.append(token_id_felt);
attributespost.append('"},{"trait_type":"DIGITS"');
attributespost.append(',"value":"');
attributespost.append(follow_prfile_address_byte_len);
attributespost.append('"},{"display_type":"date');
attributespost.append('","trait_type":"MINTED AT"');
attributespost.append(',"value":"');
attributespost.append(follow_timestamp.try_into().unwrap());
attributespost.append('"}]}');
let mut attributespre_bytearray = convert_into_byteArray(ref attributespre);
let mut attributespost_bytearray = convert_into_byteArray(ref attributespost);
attributespre_bytearray.append(@svg_encoded_byteArray);
attributespre_bytearray.append(@attributespost_bytearray);
get_base64_encode(attributespre_bytearray)
attributespost.append(@"\",\"attributes\":[{\"display");
attributespost.append(@"_type\":\"number\",\"trait_type");
attributespost.append(@"\":\"ID\",\"value\":\"");
attributespost.append(@format!("{}", token_id_felt));
attributespost.append(@"\"},{\"trait_type\":\"mint");
attributespost.append(@"_timestamp\",\"value\":\"");
attributespost.append(@format!("{}", follow_timestamp_felt));
attributespost.append(@"\"},{\"trait_type\":\"followed");
attributespost.append(@"_profile\",\"value\":\"");
attributespost.append(@format!("{}", followed_profile_address_felt));
attributespost.append(@"\"}]}");

attributespre.append(@svg_encoded_byteArray);
attributespre.append(@attributespost);

get_base64_encode(attributespre)
}
}
60 changes: 31 additions & 29 deletions src/base/token_uris/handle_token_uri.cairo
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
pub mod HandleTokenUri {
use core::array::ArrayTrait;
use coloniz::base::utils::byte_array_extra::FeltTryIntoByteArray;
use coloniz::base::utils::base64_extended::{convert_into_byteArray, get_base64_encode};
use coloniz::base::utils::base64_extended::get_base64_encode;
use coloniz::base::token_uris::traits::handle::handle::get_svg_handle;

pub fn get_token_uri(token_id: u256, local_name: felt252, namespace: felt252) -> ByteArray {
let baseuri = 'data:image/svg+xml;base64,';
/// TODO what are feaature include in the svg
let mut svg_byte_array: ByteArray = get_svg_handle(token_id, local_name, namespace);

let mut svg_byte_array: ByteArray = get_svg_handle(token_id, local_name);
let mut svg_encoded: ByteArray = get_base64_encode(svg_byte_array);

let mut attribute_byte_array: ByteArray = get_attributes(
token_id, ref svg_encoded, local_name, namespace
);

let mut token_uri: ByteArray = baseuri.try_into().unwrap();
token_uri.append(@attribute_byte_array);
token_uri
Expand All @@ -23,31 +24,32 @@ pub mod HandleTokenUri {
local_name: felt252,
namespace: felt252
) -> ByteArray {
let mut attributespre = ArrayTrait::<felt252>::new();
let mut attributespost = ArrayTrait::<felt252>::new();
attributespre.append('{"name":"@');
attributespre.append(local_name);
attributespre.append('","description":"Lens ');
attributespre.append('Protocol - Handle @');
attributespre.append(local_name);
attributespre.append('","image":"data:image');
attributespre.append('/svg+xml;base64,');
attributespost.append('","attributes":[{"display');
attributespost.append('_type":"number","trait_type');
attributespost.append('":"ID","value":"');
attributespost.append(token_id.try_into().unwrap());
attributespost.append('"},{"trait_type":"NAMES');
attributespost.append('PACE","value":"');
attributespost.append(namespace);
attributespost.append('"},{"trait_type":"');
attributespost.append('LENGTH","value":"');
attributespost.append('token_id_byte_len');
attributespost.append('"}]}');
let mut attributespre_bytearray = convert_into_byteArray(ref attributespre);
let mut attributespost_bytearray = convert_into_byteArray(ref attributespost);
attributespre_bytearray.append(@svg_encoded_byteArray);
attributespre_bytearray.append(@attributespost_bytearray);
get_base64_encode(attributespre_bytearray)
let token_id_to_felt: felt252 = token_id.low.into();

let mut attributespre: ByteArray = Default::default();
let mut attributespost: ByteArray = Default::default();

attributespre.append(@"{\"name\":\"@");
attributespre.append(@local_name.try_into().unwrap());
attributespre.append(@"\",\"description\":\" ");
attributespre.append(@"Coloniz - Handle @");
attributespre.append(@local_name.try_into().unwrap());
attributespre.append(@"\",\"image\":\"data:image");
attributespre.append(@"/svg+xml;base64,");

attributespost.append(@"\",\"attributes\":[{\"display");
attributespost.append(@"_type\":\"number\",\"trait_type");
attributespost.append(@"\":\"ID\",\"value\":\"");
attributespost.append(@format!("{}", token_id_to_felt));
attributespost.append(@"\"},{\"trait_type\":\"NAMES");
attributespost.append(@"PACE\",\"value\":\"");
attributespost.append(@namespace.try_into().unwrap());
attributespost.append(@"\"}]}");

attributespre.append(@svg_encoded_byteArray);
attributespre.append(@attributespost);

get_base64_encode(attributespre)
}
}

1 change: 1 addition & 0 deletions src/base/token_uris/traits.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod color;
pub mod handle;
pub mod follow;
pub mod community;
54 changes: 29 additions & 25 deletions src/base/token_uris/traits/color.cairo
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
pub mod colonizColors {
pub const baseGreen: felt252 = '#A0D170';
pub const basePink: felt252 = '#FFD2DD';
pub const basePurple: felt252 = '#EAD7FF';
pub const baseBlue: felt252 = '#D9E0FF';
pub const baseGold: felt252 = '#F8C944';
use core::array::ArrayTrait;

pub const lightGreen: felt252 = '#F4FFDC';
pub const lightPink: felt252 = '#FFE7F0';
pub const lightPurple: felt252 = '#F3EAFF';
pub const lightBlue: felt252 = '#ECF0FF';
pub const lightGold: felt252 = '#FFEE93';
pub fn get_random_color(seed: u256) -> felt252 {
let colors = array![
'#A0D170',
'#FFD2DD',
'#EAD7FF',
'#D9E0FF',
'#F8C944',
'#F4FFDC',
'#FFE7F0',
'#F3EAFF',
'#ECF0FF',
'#93A97D',
'#EAAEC7',
'#C3B3D5',
'#ACB5DD',
'#B96326',
'#575757',
'#DBDBDB',
'#000',
'#E3F7FF',
'#FF88A5',
'#FFDFE7',
'#FFCFEC'
];

pub const darkGreen: felt252 = '#93A97D';
pub const darkPink: felt252 = '#EAAEC7';
pub const darkPurple: felt252 = '#C3B3D5';
pub const darkBlue: felt252 = '#ACB5DD';
pub const darkGold: felt252 = '#B96326';
let len: u256 = colors.len().try_into().unwrap();
let randomIndex: u32 = (seed % len).try_into().unwrap();

pub const dark: felt252 = '#575757';
pub const gray: felt252 = '#DBDBDB';
pub const lightGray: felt252 = '#EAEAEA';
pub const white: felt252 = '#FFF';
pub const black: felt252 = '#000';

pub const tears: felt252 = '#E3F7FF';
pub const heartEyes: felt252 = '#FF88A5';
pub const tongue: felt252 = '#FFDFE7';
pub const bubbleGum: felt252 = '#FFCFEC';
return *colors.at(randomIndex);
}
}
43 changes: 43 additions & 0 deletions src/base/token_uris/traits/community.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
pub mod community {
use coloniz::base::utils::byte_array_extra::FeltTryIntoByteArray;
use coloniz::base::token_uris::traits::color::colonizColors::get_random_color;

pub fn get_svg_community(token_id: u256, community_id: u256) -> ByteArray {
let mut svg: ByteArray = Default::default();

let color_code: ByteArray = get_random_color(token_id).try_into().unwrap();

/// construct the SVG as ByteArray
svg
.append(
@"<svg width=\"300\" height=\"300\" viewBox=\"0 0 300 300\" xmlns=\"http://www.w3.org/2000/svg\">
<rect width=\"300\" height=\"300\" fill=\"white\"/>
<circle cx=\"150\" cy=\"150\" r=\"60\" fill=\""
);

svg.append(@color_code);

svg
.append(
@"\" stroke=\"black\" stroke-width=\"4\"/>
<circle cx=\"90\" cy=\"120\" r=\"15\" fill=\"black\" stroke=\"black\" stroke-width=\"3\"/>
<circle cx=\"210\" cy=\"120\" r=\"15\" fill=\"black\" stroke=\"black\" stroke-width=\"3\"/>
<circle cx=\"120\" cy=\"200\" r=\"15\" fill=\"black\" stroke=\"black\" stroke-width=\"3\"/>
<circle cx=\"180\" cy=\"200\" r=\"15\" fill=\"black\" stroke=\"black\" stroke-width=\"3\"/>
<line x1=\"150\" y1=\"150\" x2=\"90\" y2=\"120\" stroke=\"black\" stroke-width=\"3\"/>
<line x1=\"150\" y1=\"150\" x2=\"210\" y2=\"120\" stroke=\"black\" stroke-width=\"3\"/>
<line x1=\"150\" y1=\"150\" x2=\"120\" y2=\"200\" stroke=\"black\" stroke-width=\"3\"/>
<line x1=\"150\" y1=\"150\" x2=\"180\" y2=\"200\" stroke=\"black\" stroke-width=\"3\"/>
<text x=\"50%\" y=\"270\" font-family=\"Arial\" font-size=\"22\" fill=\"black\" text-anchor=\"middle\" font-weight=\"bold\">COMMUNITY #
"
);

let community_id_to_felt = community_id.into();
svg.append(@format!("{}", community_id_to_felt));

svg.append(@"</text>
</svg>");

svg
}
}
Loading