diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 8046d021..59cc8a55 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -3,12 +3,12 @@ name: Next.js CI on: push: paths: - - 'packages/nextjs/**' + - "packages/nextjs/**" pull_request: branches: - main paths: - - 'packages/nextjs/**' + - "packages/nextjs/**" jobs: ci: @@ -27,7 +27,7 @@ jobs: uses: actions/setup-node@v3 with: node-version: ${{ matrix.node }} - cache: 'yarn' + cache: "yarn" #cache-dependency-path: packages/nextjs/yarn.lock - name: Install dependencies (Next.js) diff --git a/packages/nextjs/app/debug/_components/contract/utilsContract.tsx b/packages/nextjs/app/debug/_components/contract/utilsContract.tsx index 4f0a2959..34e9a1e2 100644 --- a/packages/nextjs/app/debug/_components/contract/utilsContract.tsx +++ b/packages/nextjs/app/debug/_components/contract/utilsContract.tsx @@ -1,5 +1,6 @@ import { AbiFunction, AbiParameter } from "~~/utils/scaffold-stark/contract"; import { uint256 } from "starknet"; +import { byteArray } from "starknet-dev"; /** * Generates a key based on function metadata */ @@ -37,6 +38,9 @@ const deepParseValues = (value: any, keyAndType?: any): any => { if (keyAndType.includes("core::integer::u256")) { return uint256.bnToUint256(value); } + if (keyAndType.includes("core::byte_array::ByteArray")) { + return byteArray.byteArrayFromString(value); + } } if (typeof value === "string") { if (isJsonString(value)) { diff --git a/packages/nextjs/contracts/deployedContracts.ts b/packages/nextjs/contracts/deployedContracts.ts index c7bca93d..25751cee 100644 --- a/packages/nextjs/contracts/deployedContracts.ts +++ b/packages/nextjs/contracts/deployedContracts.ts @@ -3,1042 +3,6 @@ * You should not edit it manually or your changes might be overwritten. */ -const deployedContracts = { - devnet: { - Challenge0: { - address: - "0x064a129d88d4a54e467afd5fb138fec224259bc3fdfb1239b8b4605bad6d8546", - abi: [ - { - type: "impl", - name: "Challenge0Impl", - interface_name: "contracts::challenge0::IChallenge0", - }, - { - type: "struct", - name: "core::integer::u256", - members: [ - { - name: "low", - type: "core::integer::u128", - }, - { - name: "high", - type: "core::integer::u128", - }, - ], - }, - { - type: "interface", - name: "contracts::challenge0::IChallenge0", - items: [ - { - type: "function", - name: "mint_item", - inputs: [ - { - name: "recipient", - type: "core::starknet::contract_address::ContractAddress", - }, - ], - outputs: [ - { - type: "core::integer::u256", - }, - ], - state_mutability: "external", - }, - { - type: "function", - name: "mint_id", - inputs: [ - { - name: "recipient", - type: "core::starknet::contract_address::ContractAddress", - }, - { - name: "id", - type: "core::integer::u256", - }, - ], - outputs: [], - state_mutability: "external", - }, - ], - }, - { - type: "impl", - name: "ERC721MixinImpl", - interface_name: "openzeppelin::token::erc721::interface::ERC721ABI", - }, - { - type: "struct", - name: "core::array::Span::", - members: [ - { - name: "snapshot", - type: "@core::array::Array::", - }, - ], - }, - { - type: "enum", - name: "core::bool", - variants: [ - { - name: "False", - type: "()", - }, - { - name: "True", - type: "()", - }, - ], - }, - { - type: "struct", - name: "core::byte_array::ByteArray", - members: [ - { - name: "data", - type: "core::array::Array::", - }, - { - name: "pending_word", - type: "core::felt252", - }, - { - name: "pending_word_len", - type: "core::integer::u32", - }, - ], - }, - { - type: "interface", - name: "openzeppelin::token::erc721::interface::ERC721ABI", - items: [ - { - type: "function", - name: "balance_of", - inputs: [ - { - name: "account", - type: "core::starknet::contract_address::ContractAddress", - }, - ], - outputs: [ - { - type: "core::integer::u256", - }, - ], - state_mutability: "view", - }, - { - type: "function", - name: "owner_of", - inputs: [ - { - name: "token_id", - type: "core::integer::u256", - }, - ], - outputs: [ - { - type: "core::starknet::contract_address::ContractAddress", - }, - ], - state_mutability: "view", - }, - { - type: "function", - name: "safe_transfer_from", - inputs: [ - { - name: "from", - type: "core::starknet::contract_address::ContractAddress", - }, - { - name: "to", - type: "core::starknet::contract_address::ContractAddress", - }, - { - name: "token_id", - type: "core::integer::u256", - }, - { - name: "data", - type: "core::array::Span::", - }, - ], - outputs: [], - state_mutability: "external", - }, - { - type: "function", - name: "transfer_from", - inputs: [ - { - name: "from", - type: "core::starknet::contract_address::ContractAddress", - }, - { - name: "to", - type: "core::starknet::contract_address::ContractAddress", - }, - { - name: "token_id", - type: "core::integer::u256", - }, - ], - outputs: [], - state_mutability: "external", - }, - { - type: "function", - name: "approve", - inputs: [ - { - name: "to", - type: "core::starknet::contract_address::ContractAddress", - }, - { - name: "token_id", - type: "core::integer::u256", - }, - ], - outputs: [], - state_mutability: "external", - }, - { - type: "function", - name: "set_approval_for_all", - inputs: [ - { - name: "operator", - type: "core::starknet::contract_address::ContractAddress", - }, - { - name: "approved", - type: "core::bool", - }, - ], - outputs: [], - state_mutability: "external", - }, - { - type: "function", - name: "get_approved", - inputs: [ - { - name: "token_id", - type: "core::integer::u256", - }, - ], - outputs: [ - { - type: "core::starknet::contract_address::ContractAddress", - }, - ], - state_mutability: "view", - }, - { - type: "function", - name: "is_approved_for_all", - inputs: [ - { - name: "owner", - type: "core::starknet::contract_address::ContractAddress", - }, - { - name: "operator", - type: "core::starknet::contract_address::ContractAddress", - }, - ], - outputs: [ - { - type: "core::bool", - }, - ], - state_mutability: "view", - }, - { - type: "function", - name: "supports_interface", - inputs: [ - { - name: "interface_id", - type: "core::felt252", - }, - ], - outputs: [ - { - type: "core::bool", - }, - ], - state_mutability: "view", - }, - { - type: "function", - name: "name", - inputs: [], - outputs: [ - { - type: "core::byte_array::ByteArray", - }, - ], - state_mutability: "view", - }, - { - type: "function", - name: "symbol", - inputs: [], - outputs: [ - { - type: "core::byte_array::ByteArray", - }, - ], - state_mutability: "view", - }, - { - type: "function", - name: "token_uri", - inputs: [ - { - name: "token_id", - type: "core::integer::u256", - }, - ], - outputs: [ - { - type: "core::byte_array::ByteArray", - }, - ], - state_mutability: "view", - }, - { - type: "function", - name: "balanceOf", - inputs: [ - { - name: "account", - type: "core::starknet::contract_address::ContractAddress", - }, - ], - outputs: [ - { - type: "core::integer::u256", - }, - ], - state_mutability: "view", - }, - { - type: "function", - name: "ownerOf", - inputs: [ - { - name: "tokenId", - type: "core::integer::u256", - }, - ], - outputs: [ - { - type: "core::starknet::contract_address::ContractAddress", - }, - ], - state_mutability: "view", - }, - { - type: "function", - name: "safeTransferFrom", - inputs: [ - { - name: "from", - type: "core::starknet::contract_address::ContractAddress", - }, - { - name: "to", - type: "core::starknet::contract_address::ContractAddress", - }, - { - name: "tokenId", - type: "core::integer::u256", - }, - { - name: "data", - type: "core::array::Span::", - }, - ], - outputs: [], - state_mutability: "external", - }, - { - type: "function", - name: "transferFrom", - inputs: [ - { - name: "from", - type: "core::starknet::contract_address::ContractAddress", - }, - { - name: "to", - type: "core::starknet::contract_address::ContractAddress", - }, - { - name: "tokenId", - type: "core::integer::u256", - }, - ], - outputs: [], - state_mutability: "external", - }, - { - type: "function", - name: "setApprovalForAll", - inputs: [ - { - name: "operator", - type: "core::starknet::contract_address::ContractAddress", - }, - { - name: "approved", - type: "core::bool", - }, - ], - outputs: [], - state_mutability: "external", - }, - { - type: "function", - name: "getApproved", - inputs: [ - { - name: "tokenId", - type: "core::integer::u256", - }, - ], - outputs: [ - { - type: "core::starknet::contract_address::ContractAddress", - }, - ], - state_mutability: "view", - }, - { - type: "function", - name: "isApprovedForAll", - inputs: [ - { - name: "owner", - type: "core::starknet::contract_address::ContractAddress", - }, - { - name: "operator", - type: "core::starknet::contract_address::ContractAddress", - }, - ], - outputs: [ - { - type: "core::bool", - }, - ], - state_mutability: "view", - }, - { - type: "function", - name: "tokenURI", - inputs: [ - { - name: "tokenId", - type: "core::integer::u256", - }, - ], - outputs: [ - { - type: "core::byte_array::ByteArray", - }, - ], - state_mutability: "view", - }, - ], - }, - { - type: "constructor", - name: "constructor", - inputs: [], - }, - { - type: "event", - name: "openzeppelin::token::erc721::erc721::ERC721Component::Transfer", - kind: "struct", - members: [ - { - name: "from", - type: "core::starknet::contract_address::ContractAddress", - kind: "key", - }, - { - name: "to", - type: "core::starknet::contract_address::ContractAddress", - kind: "key", - }, - { - name: "token_id", - type: "core::integer::u256", - kind: "key", - }, - ], - }, - { - type: "event", - name: "openzeppelin::token::erc721::erc721::ERC721Component::Approval", - kind: "struct", - members: [ - { - name: "owner", - type: "core::starknet::contract_address::ContractAddress", - kind: "key", - }, - { - name: "approved", - type: "core::starknet::contract_address::ContractAddress", - kind: "key", - }, - { - name: "token_id", - type: "core::integer::u256", - kind: "key", - }, - ], - }, - { - type: "event", - name: "openzeppelin::token::erc721::erc721::ERC721Component::ApprovalForAll", - kind: "struct", - members: [ - { - name: "owner", - type: "core::starknet::contract_address::ContractAddress", - kind: "key", - }, - { - name: "operator", - type: "core::starknet::contract_address::ContractAddress", - kind: "key", - }, - { - name: "approved", - type: "core::bool", - kind: "data", - }, - ], - }, - { - type: "event", - name: "openzeppelin::token::erc721::erc721::ERC721Component::Event", - kind: "enum", - variants: [ - { - name: "Transfer", - type: "openzeppelin::token::erc721::erc721::ERC721Component::Transfer", - kind: "nested", - }, - { - name: "Approval", - type: "openzeppelin::token::erc721::erc721::ERC721Component::Approval", - kind: "nested", - }, - { - name: "ApprovalForAll", - type: "openzeppelin::token::erc721::erc721::ERC721Component::ApprovalForAll", - kind: "nested", - }, - ], - }, - { - type: "event", - name: "openzeppelin::introspection::src5::SRC5Component::Event", - kind: "enum", - variants: [], - }, - { - type: "event", - name: "contracts::challenge0::Challenge0::Event", - kind: "enum", - variants: [ - { - name: "ERC721Event", - type: "openzeppelin::token::erc721::erc721::ERC721Component::Event", - kind: "flat", - }, - { - name: "SRC5Event", - type: "openzeppelin::introspection::src5::SRC5Component::Event", - kind: "flat", - }, - ], - }, - ], - }, - }, - mainnet: { - HelloStarknet: { - address: - "0x0750aa622d77436d69d58c91dbc73a6d0d25db0b7076c1377cdda15e13fd632b", - abi: [ - { - type: "impl", - name: "HelloStarknetImpl", - interface_name: "contracts::helloStarknet::IHelloStarknet", - }, - { - type: "interface", - name: "contracts::helloStarknet::IHelloStarknet", - items: [ - { - type: "function", - name: "increase_balance", - inputs: [ - { - name: "amount", - type: "core::integer::u32", - }, - ], - outputs: [], - state_mutability: "external", - }, - { - type: "function", - name: "get_balance", - inputs: [], - outputs: [ - { - type: "core::integer::u32", - }, - ], - state_mutability: "view", - }, - { - type: "function", - name: "get_balance_increment", - inputs: [ - { - name: "amount", - type: "core::integer::u32", - }, - ], - outputs: [ - { - type: "core::integer::u32", - }, - ], - state_mutability: "view", - }, - ], - }, - { - type: "event", - name: "contracts::helloStarknet::HelloStarknet::Event", - kind: "enum", - variants: [], - }, - ], - }, - }, - sepolia: { - HelloStarknet: { - address: - "0x07e6136fbfaae09a09f491c97c127c661b9e2edb553be28e1966d1ac1724d98c", - abi: [ - { - type: "impl", - name: "HelloStarknetImpl", - interface_name: "contracts::helloStarknet::IHelloStarknet", - }, - { - type: "interface", - name: "contracts::helloStarknet::IHelloStarknet", - items: [ - { - type: "function", - name: "increase_balance", - inputs: [ - { - name: "amount", - type: "core::integer::u32", - }, - ], - outputs: [], - state_mutability: "external", - }, - { - type: "function", - name: "get_balance", - inputs: [], - outputs: [ - { - type: "core::integer::u32", - }, - ], - state_mutability: "view", - }, - { - type: "function", - name: "get_balance_increment", - inputs: [ - { - name: "amount", - type: "core::integer::u32", - }, - ], - outputs: [ - { - type: "core::integer::u32", - }, - ], - state_mutability: "view", - }, - ], - }, - { - type: "event", - name: "contracts::helloStarknet::HelloStarknet::Event", - kind: "enum", - variants: [], - }, - ], - }, - SimpleStorage: { - address: - "0x072c40ba7d070bfd6aaa7532743f635cc432748ab1f7e8e4254c4238975858f3", - abi: [ - { - type: "impl", - name: "SimpleStorageImpl", - interface_name: "contracts::simpleStorage::ISimpleStorage", - }, - { - type: "interface", - name: "contracts::simpleStorage::ISimpleStorage", - items: [ - { - type: "function", - name: "get_name", - inputs: [], - outputs: [ - { - type: "core::felt252", - }, - ], - state_mutability: "view", - }, - { - type: "function", - name: "set_name", - inputs: [ - { - name: "name", - type: "core::felt252", - }, - ], - outputs: [], - state_mutability: "external", - }, - ], - }, - { - type: "constructor", - name: "constructor", - inputs: [ - { - name: "name", - type: "core::felt252", - }, - ], - }, - { - type: "event", - name: "contracts::simpleStorage::SimpleStorage::Event", - kind: "enum", - variants: [], - }, - ], - }, - Vote: { - address: - "0x04c394c4fc87a9a62f04205ac456f6811b6bcb0465e339f95308332cbff7364f", - abi: [ - { - type: "impl", - name: "VoteImpl", - interface_name: "contracts::vote::VoteTrait", - }, - { - type: "enum", - name: "core::bool", - variants: [ - { - name: "False", - type: "()", - }, - { - name: "True", - type: "()", - }, - ], - }, - { - type: "interface", - name: "contracts::vote::VoteTrait", - items: [ - { - type: "function", - name: "get_vote_status", - inputs: [], - outputs: [ - { - type: "(core::integer::u8, core::integer::u8, core::integer::u8, core::integer::u8)", - }, - ], - state_mutability: "view", - }, - { - type: "function", - name: "voter_can_vote", - inputs: [ - { - name: "user_address", - type: "core::starknet::contract_address::ContractAddress", - }, - ], - outputs: [ - { - type: "core::bool", - }, - ], - state_mutability: "view", - }, - { - type: "function", - name: "is_voter_registered", - inputs: [ - { - name: "address", - type: "core::starknet::contract_address::ContractAddress", - }, - ], - outputs: [ - { - type: "core::bool", - }, - ], - state_mutability: "view", - }, - { - type: "function", - name: "vote", - inputs: [ - { - name: "vote", - type: "core::integer::u8", - }, - ], - outputs: [], - state_mutability: "external", - }, - ], - }, - { - type: "constructor", - name: "constructor", - inputs: [ - { - name: "voter_1", - type: "core::starknet::contract_address::ContractAddress", - }, - { - name: "voter_2", - type: "core::starknet::contract_address::ContractAddress", - }, - { - name: "voter_3", - type: "core::starknet::contract_address::ContractAddress", - }, - ], - }, - { - type: "event", - name: "contracts::vote::Vote::VoteCast", - kind: "struct", - members: [ - { - name: "voter", - type: "core::starknet::contract_address::ContractAddress", - kind: "data", - }, - { - name: "vote", - type: "core::integer::u8", - kind: "data", - }, - ], - }, - { - type: "event", - name: "contracts::vote::Vote::UnauthorizedAttempt", - kind: "struct", - members: [ - { - name: "unauthorized_address", - type: "core::starknet::contract_address::ContractAddress", - kind: "data", - }, - ], - }, - { - type: "event", - name: "contracts::vote::Vote::Event", - kind: "enum", - variants: [ - { - name: "VoteCast", - type: "contracts::vote::Vote::VoteCast", - kind: "nested", - }, - { - name: "UnauthorizedAttempt", - type: "contracts::vote::Vote::UnauthorizedAttempt", - kind: "nested", - }, - ], - }, - ], - }, - Ownable: { - address: - "0x07b0a115eb4111e34607418ff37015e8f60149541d3af39b094d19eea2ec5ad4", - abi: [ - { - type: "impl", - name: "OwnableDataImpl", - interface_name: "contracts::IData", - }, - { - type: "interface", - name: "contracts::IData", - items: [ - { - type: "function", - name: "get_data", - inputs: [], - outputs: [ - { - type: "core::integer::u64", - }, - ], - state_mutability: "view", - }, - { - type: "function", - name: "set_data", - inputs: [ - { - name: "new_value", - type: "core::integer::u64", - }, - ], - outputs: [], - state_mutability: "external", - }, - ], - }, - { - type: "impl", - name: "OwnableImpl", - interface_name: "contracts::IOwnable", - }, - { - type: "interface", - name: "contracts::IOwnable", - items: [ - { - type: "function", - name: "transfer_ownership", - inputs: [ - { - name: "new_owner", - type: "core::starknet::contract_address::ContractAddress", - }, - ], - outputs: [], - state_mutability: "external", - }, - { - type: "function", - name: "owner", - inputs: [], - outputs: [ - { - type: "core::starknet::contract_address::ContractAddress", - }, - ], - state_mutability: "view", - }, - ], - }, - { - type: "constructor", - name: "constructor", - inputs: [ - { - name: "initial_owner", - type: "core::starknet::contract_address::ContractAddress", - }, - ], - }, - { - type: "event", - name: "contracts::ownable_component::OwnershipTransferred", - kind: "struct", - members: [ - { - name: "previous_owner", - type: "core::starknet::contract_address::ContractAddress", - kind: "key", - }, - { - name: "new_owner", - type: "core::starknet::contract_address::ContractAddress", - kind: "data", - }, - ], - }, - { - type: "event", - name: "contracts::ownable_component::Event", - kind: "enum", - variants: [ - { - name: "OwnershipTransferred", - type: "contracts::ownable_component::OwnershipTransferred", - kind: "nested", - }, - ], - }, - { - type: "event", - name: "contracts::Ownable::Event", - kind: "enum", - variants: [ - { - name: "OwnableEvent", - type: "contracts::ownable_component::Event", - kind: "nested", - }, - ], - }, - ], - }, - }, -} as const; +const deployedContracts = {} as const; export default deployedContracts; diff --git a/packages/nextjs/hooks/scaffold-stark/useSwitchNetwork.ts b/packages/nextjs/hooks/scaffold-stark/useSwitchNetwork.ts index 791253fc..702e4483 100644 --- a/packages/nextjs/hooks/scaffold-stark/useSwitchNetwork.ts +++ b/packages/nextjs/hooks/scaffold-stark/useSwitchNetwork.ts @@ -5,7 +5,9 @@ export const useSwitchNetwork = () => { await window.starknet.request({ type: "wallet_switchStarknetChain", params: { - chainId: `SN_${network == "mainnet" ? "MAIN" : network.toUpperCase()}`, + chainId: `SN_${ + network == "mainnet" ? "MAIN" : network.toUpperCase() + }`, }, }); } diff --git a/packages/nextjs/scaffold.config.ts b/packages/nextjs/scaffold.config.ts index b57feb3a..9d010910 100644 --- a/packages/nextjs/scaffold.config.ts +++ b/packages/nextjs/scaffold.config.ts @@ -8,7 +8,7 @@ export type ScaffoldConfig = { }; const scaffoldConfig = { - targetNetworks: [chains.sepolia], + targetNetworks: [chains.devnet], // Only show the Burner Wallet when running on devnet onlyLocalBurnerWallet: false, rpcProviderUrl: process.env.NEXT_PUBLIC_PROVIDER_URL || "", diff --git a/packages/snfoundry/contracts/src/challenge0.cairo b/packages/snfoundry/contracts/src/challenge0.cairo index 80e0abe6..22ac713b 100644 --- a/packages/snfoundry/contracts/src/challenge0.cairo +++ b/packages/snfoundry/contracts/src/challenge0.cairo @@ -1,32 +1,41 @@ use starknet::ContractAddress; #[starknet::interface] -pub trait IChallenge0 { - fn mint_item(ref self: T, recipient: ContractAddress) -> u256; - fn mint_id(ref self: T, recipient: ContractAddress, id: u256); +trait IChallenge0 { + fn mint_item(ref self: T, recipient: ContractAddress, uri: ByteArray) -> u256; + fn token_id_counter(self: @T) -> u256; } #[starknet::contract] mod Challenge0 { - use super::IChallenge0; + use super::{IChallenge0, ContractAddress}; use openzeppelin::introspection::src5::SRC5Component; use openzeppelin::token::erc721::ERC721Component; - use starknet::ContractAddress; + use openzeppelin::access::ownable::OwnableComponent; + use openzeppelin::token::erc721::interface::IERC721Metadata; component!(path: ERC721Component, storage: erc721, event: ERC721Event); component!(path: SRC5Component, storage: src5, event: SRC5Event); + component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); - // ERC721Mixin + + #[abi(embed_v0)] + impl ERC721Impl = ERC721Component::ERC721Impl; #[abi(embed_v0)] - impl ERC721MixinImpl = ERC721Component::ERC721MixinImpl; - //pub impl ERC721MetadataImpl = ERC721Component::ERC721MetadataImpl; + impl OwnableImpl = OwnableComponent::OwnableImpl; + impl ERC721InternalImpl = ERC721Component::InternalImpl; + impl OwnableInternalImpl = OwnableComponent::InternalImpl; #[storage] struct Storage { #[substorage(v0)] erc721: ERC721Component::Storage, #[substorage(v0)] - src5: SRC5Component::Storage + src5: SRC5Component::Storage, + #[substorage(v0)] + ownable: OwnableComponent::Storage, + counter: u256, + token_uris: LegacyMap, } #[event] @@ -35,28 +44,67 @@ mod Challenge0 { #[flat] ERC721Event: ERC721Component::Event, #[flat] - SRC5Event: SRC5Component::Event + SRC5Event: SRC5Component::Event, + #[flat] + OwnableEvent: OwnableComponent::Event } #[constructor] - fn constructor(ref self: ContractState) { + fn constructor(ref self: ContractState, owner: ContractAddress) { let name: ByteArray = "YourCollectible"; let symbol: ByteArray = "YCB"; - let base_uri: ByteArray = - "https://ipfs.io/ipfs/QmfVMAmNM1kDEBYrC2TPzQDoCRFH6F5tE1e9Mr4FkkR5Xr"; // bison nft + let base_uri: ByteArray = "https://ipfs.io/"; self.erc721.initializer(name, symbol, base_uri); + self.ownable.initializer(owner); + } + + #[abi(embed_v0)] + impl WrappedIERC721MetadataImpl of IERC721Metadata { + fn token_uri(self: @ContractState, token_id: u256) -> ByteArray { + self._token_uri(token_id) + } + fn name(self: @ContractState) -> ByteArray { + self.erc721.name() + } + fn symbol(self: @ContractState) -> ByteArray { + self.erc721.symbol() + } } #[abi(embed_v0)] - pub impl Challenge0Impl of IChallenge0 { - fn mint_item(ref self: ContractState, recipient: ContractAddress) -> u256 { - let id: u256 = 1; - self.erc721._mint(recipient, id); // _mint include _setTokenURI() - id - } - fn mint_id(ref self: ContractState, recipient: ContractAddress, id: u256) { - self.erc721._mint(recipient, id); + impl Challenge0Impl of IChallenge0 { + fn mint_item(ref self: ContractState, recipient: ContractAddress, uri: ByteArray) -> u256 { + self._increment(); + let token_id = self._current(); + self.erc721._mint(recipient, token_id); + self._set_token_uri(token_id, uri); + token_id + } + fn token_id_counter(self: @ContractState) -> u256 { + self._current() + } + } + + #[generate_trait] + impl InternalImpl of InternalTrait { + fn _increment(ref self: ContractState) { + self.counter.write(self.counter.read() + 1); + } + + fn _current(self: @ContractState) -> u256 { + self.counter.read() + } + + fn _token_uri(self: @ContractState, token_id: u256) -> ByteArray { + assert(self.erc721._exists(token_id), ERC721Component::Errors::INVALID_TOKEN_ID); + let base_uri = self.erc721._base_uri(); + let uri = self.token_uris.read(token_id); + format!("{}{}", base_uri, uri) + } + + fn _set_token_uri(ref self: ContractState, token_id: u256, uri: ByteArray) { + self.token_uris.write(token_id, uri); } } } diff --git a/packages/snfoundry/scripts_js/deploy.js b/packages/snfoundry/scripts_js/deploy.js index 2c4a12db..b0b1beb8 100644 --- a/packages/snfoundry/scripts_js/deploy.js +++ b/packages/snfoundry/scripts_js/deploy.js @@ -10,28 +10,26 @@ const { CallData } = require("starknet-dev"); const deployContract = require("./deploy_contract"); const deployScript = async () => { - const { - classHash: helloStarknetClassHash, - abi: helloStarknetAbi, - address: ContractAddress, - } = await deployContract(null, "HelloStarknet"); // can pass another argument for the exported contract name - await deployContract( - { - name: 1, - }, - "SimpleStorage" - ); - + // const { + // classHash: helloStarknetClassHash, + // abi: helloStarknetAbi, + // address: ContractAddress, + // } = await deployContract(null, "HelloStarknet"); // can pass another argument for the exported contract name // await deployContract( // { - // name: "MARQUIS", - // symbol: "MARQ", - // recipient: deployer.address, - // fixed_supply: 100, + // name: 1, // }, - // "Challenge1" + // "SimpleStorage" // ); + await deployContract( + { + owner: + "0x4b3f4ba8c00a02b66142a4b1dd41a4dfab4f92650922a3280977b0f03c75ee1", + }, // last account in devnet accounts + "Challenge0", + ); + // await deployContract( // { // name: 1, diff --git a/packages/snfoundry/scripts_js/helpers/deploy-wrapper.js b/packages/snfoundry/scripts_js/helpers/deploy-wrapper.js index 4a301fcc..29ca328d 100644 --- a/packages/snfoundry/scripts_js/helpers/deploy-wrapper.js +++ b/packages/snfoundry/scripts_js/helpers/deploy-wrapper.js @@ -9,5 +9,5 @@ require("child_process").execSync( "cd contracts && scarb build && node ../scripts_js/deploy.js --network " + process.env.NETWORK + " && node ../scripts_js/helpers/parseDeployments.js", - { stdio: "inherit" } + { stdio: "inherit" }, ); diff --git a/packages/snfoundry/scripts_js/helpers/networks.js b/packages/snfoundry/scripts_js/helpers/networks.js index 4330075b..61bb61d2 100644 --- a/packages/snfoundry/scripts_js/helpers/networks.js +++ b/packages/snfoundry/scripts_js/helpers/networks.js @@ -33,7 +33,7 @@ const deployerGoerli = providerGoerli, process.env.ACCOUNT_ADDRESS_GOERLI, process.env.PRIVATE_KEY_GOERLI, - 1 + 1, ); // sepolia @@ -49,7 +49,7 @@ const deployerSepolia = providerSepolia, process.env.ACCOUNT_ADDRESS_SEPOLIA, process.env.PRIVATE_KEY_SEPOLIA, - 1 + 1, ); // mainnet @@ -65,7 +65,7 @@ const deployerMainnet = providerMainnet, process.env.ACCOUNT_ADDRESS_MAINNET, process.env.PRIVATE_KEY_MAINNET, - 1 + 1, ); module.exports = { diff --git a/packages/snfoundry/scripts_js/helpers/parseDeployments.js b/packages/snfoundry/scripts_js/helpers/parseDeployments.js index 90d827c3..9eb86d0f 100644 --- a/packages/snfoundry/scripts_js/helpers/parseDeployments.js +++ b/packages/snfoundry/scripts_js/helpers/parseDeployments.js @@ -24,7 +24,7 @@ const getContractDataFromDeployments = () => { try { const abiFilePath = path.join( __dirname, - `../../contracts/target/dev/contracts_${contractData.contract}.contract_class.json` + `../../contracts/target/dev/contracts_${contractData.contract}.contract_class.json`, ); const abiContent = JSON.parse(fs.readFileSync(abiFilePath, "utf8")); @@ -51,7 +51,7 @@ const generateTsAbis = () => { // Use chainId directly as it is already a hex string return `${content}${chainId}:${JSON.stringify(chainConfig, null, 2)},`; }, - "" + "", ); if (!fs.existsSync(TARGET_DIR)) { @@ -64,12 +64,12 @@ const generateTsAbis = () => { `${generatedContractComment}\n\nconst deployedContracts = {${fileContent}} as const;\n\nexport default deployedContracts;`, { parser: "typescript", - } - ) + }, + ), ); console.log( - `📝 Updated TypeScript contract definition file on ${TARGET_DIR}/deployedContracts.ts` + `📝 Updated TypeScript contract definition file on ${TARGET_DIR}/deployedContracts.ts`, ); };