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

Start Working on Creation of Profile Svg #111

Merged
merged 16 commits into from
Sep 20, 2024
1 change: 1 addition & 0 deletions src/base/token_uris.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod follow_token_uri;
mod handle_token_uri;
mod profile_token_uri;
mod traits;
52 changes: 49 additions & 3 deletions src/base/token_uris/handle_token_uri.cairo
Original file line number Diff line number Diff line change
@@ -1,10 +1,56 @@
// TODO: https://github.com/lens-protocol/core/blob/master/contracts/misc/token-uris/HandleTokenURI.sol

pub mod HandleTokenUri {
use core::array::ArrayTrait;
use alexandria_bytes::{Bytes, BytesTrait};
use karst::base::utils::byte_array_extra::FeltTryIntoByteArray;
use karst::base::utils::base64_extended::{convert_into_byteArray , get_base64_encode } ;
use karst::base::token_uris::traits::profile::ProfileSvg::gen_profile_svg ;
pub fn get_token_uri(token_id: u256, local_name: felt252, namespace: felt252 ) -> ByteArray {
PavitraAgarwal21 marked this conversation as resolved.
Show resolved Hide resolved
let baseuri = 'data:image/svg+xml;base64,';
/// TODO what are feaature include in the svg
PavitraAgarwal21 marked this conversation as resolved.
Show resolved Hide resolved
// let mut svg_byte_array: ByteArray = get_svg(token_id, local_name , namespace);
let mut svg_byte_array = gen_profile_svg() ;
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
}

pub fn get_token_uri(token_id: u256, local_name: felt252, namespace: felt252) -> ByteArray {
"TODO"
fn get_attributes(token_id: u256,ref svg_encoded_byteArray : ByteArray ,local_name: felt252 , namespace : felt252 ) -> ByteArray {
let token_id_felt: felt252 = token_id.try_into().unwrap();
let token_id_byte: ByteArray = token_id_felt.try_into().unwrap();
let token_id_byte_len: felt252 = token_id_byte.len().try_into().unwrap();
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)
}
}
}


// cvonver the byteArray into the base64 encoded byteArray //


37 changes: 2 additions & 35 deletions src/base/token_uris/profile_token_uri.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ pub mod ProfileTokenUri {
use core::array::ArrayTrait;
use alexandria_bytes::{Bytes, BytesTrait};
use karst::base::utils::byte_array_extra::FeltTryIntoByteArray;
use alexandria_encoding::base64::{Base64UrlEncoder};

use karst::base::utils::base64_extended:: { get_base64_encode , convert_into_byteArray };
use karst::base::token_uris::traits::profile::ProfileSvg::gen_profile_svg ;
// get svg according to the token id and mint timestamp
fn get_svg(token_id: u256, mint_timestamp: u64) -> Array<felt252> {
let mut svg = ArrayTrait::<felt252>::new();
Expand Down Expand Up @@ -55,39 +55,6 @@ pub mod ProfileTokenUri {
json
}

fn convert_into_byteArray(ref svg: Array<felt252>) -> ByteArray {
let mut res: ByteArray = Default::default();
// converting felt252 array to byte array
while (!svg.is_empty()) {
let each_felt: felt252 = svg.pop_front().unwrap();
let word: ByteArray = each_felt.try_into().unwrap();
res.append(@word);
};
res
}

fn get_base64_encode(res: ByteArray) -> ByteArray {
let mut res_arr_u8 = ArrayTrait::<u8>::new();
let mut i = 0;
while i < res
.len() {
let mut res_data = res.at(i);
res_arr_u8.append(res_data.unwrap());
i += 1;
};
// encoding the array of u8 to base64url
let mut encoded_val = Base64UrlEncoder::encode(res_arr_u8);
// converting array of u8 to byte array
let mut res_final: ByteArray = Default::default();
let mut j = 0;
while j < encoded_val
.len() {
let encoded_val_data = encoded_val.at(j);
res_final.append_byte(*encoded_val_data);
j += 1;
};
res_final
}

pub fn get_token_uri(token_id: u256, mint_timestamp: u64) -> ByteArray {
let baseuri = 'data:image/svg+xml;base64,';
Expand Down
7 changes: 7 additions & 0 deletions src/base/token_uris/traits.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
mod head;
mod glass;
mod color;
mod beard;
mod background;
mod cloth;
mod profile ;
47 changes: 47 additions & 0 deletions src/base/token_uris/traits/background.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// let make the face of the profile svg

mod background {
use core::traits::TryInto;
use karst::base::token_uris::traits::color::karstColors;
use karst::base::utils::byte_array_extra::FeltTryIntoByteArray;

#[derive(Drop)]
enum BackgroundVariants {
BACKGROUND1, // 1
BACKGROUND2, // 2
BACKGROUND3, // 3
BACKGROUND4, // 4
BACKGROUND5, // 5
}

pub fn backgroundSvgStart() -> ByteArray {
getBackgroundVariant(BackgroundVariants::BACKGROUND1)
}

pub fn getBackgroundVariant(backgroundVariant: BackgroundVariants) -> ByteArray {
let mut decidedbackground: ByteArray = Default::default();
match backgroundVariant {
BackgroundVariants::BACKGROUND1 => {
decidedbackground =
" style=\"clip-rule:evenodd;fill-rule:evenodd;image-rendering:optimizeQuality;shape-rendering:geometricPrecision;text-rendering:geometricPrecision\" xml:space=\"preserve\" xmlns=\"http://www.w3.org/2000/svg\"><g style=\"display:inline\"><path style=\"opacity:1;fill:#556378;fill-opacity:1;stroke:#020503;stroke-width:.377995;stroke-dasharray:none;stroke-opacity:1\" d=\"M-1.701 2.299h199.622v199.622H-1.701z\"/></g>"
},
BackgroundVariants::BACKGROUND2 => {
decidedbackground =
" style=\"clip-rule:evenodd;fill-rule:evenodd;image-rendering:optimizeQuality;shape-rendering:geometricPrecision;text-rendering:geometricPrecision\" xml:space=\"preserve\" xmlns=\"http://www.w3.org/2000/svg\"><g style=\"display:inline\"><path style=\"opacity:1;fill:#556378;fill-opacity:1;stroke:#020503;stroke-width:.377995;stroke-dasharray:none;stroke-opacity:1\" d=\"M-1.701 2.299h199.622v199.622H-1.701z\"/></g>"
},
BackgroundVariants::BACKGROUND3 => {
decidedbackground =
" style=\"clip-rule:evenodd;fill-rule:evenodd;image-rendering:optimizeQuality;shape-rendering:geometricPrecision;text-rendering:geometricPrecision\" xml:space=\"preserve\" xmlns=\"http://www.w3.org/2000/svg\"><g style=\"display:inline\"><path style=\"opacity:1;fill:#556378;fill-opacity:1;stroke:#020503;stroke-width:.377995;stroke-dasharray:none;stroke-opacity:1\" d=\"M-1.701 2.299h199.622v199.622H-1.701z\"/></g>"
},
BackgroundVariants::BACKGROUND4 => {
decidedbackground =
" style=\"clip-rule:evenodd;fill-rule:evenodd;image-rendering:optimizeQuality;shape-rendering:geometricPrecision;text-rendering:geometricPrecision\" xml:space=\"preserve\" xmlns=\"http://www.w3.org/2000/svg\"><g style=\"display:inline\"><path style=\"opacity:1;fill:#556378;fill-opacity:1;stroke:#020503;stroke-width:.377995;stroke-dasharray:none;stroke-opacity:1\" d=\"M-1.701 2.299h199.622v199.622H-1.701z\"/></g>"
},
BackgroundVariants::BACKGROUND5 => {
decidedbackground =
" style=\"clip-rule:evenodd;fill-rule:evenodd;image-rendering:optimizeQuality;shape-rendering:geometricPrecision;text-rendering:geometricPrecision\" xml:space=\"preserve\" xmlns=\"http://www.w3.org/2000/svg\"><g style=\"display:inline\"><path style=\"opacity:1;fill:#556378;fill-opacity:1;stroke:#020503;stroke-width:.377995;stroke-dasharray:none;stroke-opacity:1\" d=\"M-1.701 2.299h199.622v199.622H-1.701z\"/></g>"
}
}
decidedbackground
}
}
47 changes: 47 additions & 0 deletions src/base/token_uris/traits/beard.cairo

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions src/base/token_uris/traits/cloth.cairo

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions src/base/token_uris/traits/color.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// SPDX-License-Identifier: MIT

mod karstColors {
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';

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 const darkGreen: felt252 = '#93A97D';
pub const darkPink: felt252 = '#EAAEC7';
pub const darkPurple: felt252 = '#C3B3D5';
pub const darkBlue: felt252 = '#ACB5DD';
pub const darkGold: felt252 = '#B96326';

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';
}
Loading
Loading