diff --git a/packages/nextjs/font/codec.ttf b/packages/nextjs/font/codec.ttf deleted file mode 100644 index 26331c9..0000000 Binary files a/packages/nextjs/font/codec.ttf and /dev/null differ diff --git a/packages/snfoundry/.env.example b/packages/snfoundry/.env.example deleted file mode 100644 index 07dbd08..0000000 --- a/packages/snfoundry/.env.example +++ /dev/null @@ -1,9 +0,0 @@ -## Devnet -PRIVATE_KEY_DEVNET=0x57b2f8431c772e647712ae93cc616638 -RPC_URL_DEVNET=http://127.0.0.1:5050 -ACCOUNT_ADDRESS_DEVNET=0x4b3f4ba8c00a02b66142a4b1dd41a4dfab4f92650922a3280977b0f03c75ee1 // last staknet devnet account address - -## Sepolia -PRIVATE_KEY_SEPOLIA= -RPC_URL_SEPOLIA=https://starknet-sepolia.infura.io/v3/47279f22f9954d6facd977b57c932b6a -ACCOUNT_ADDRESS_SEPOLIA= diff --git a/packages/snfoundry/.gitignore b/packages/snfoundry/.gitignore deleted file mode 100644 index 3615796..0000000 --- a/packages/snfoundry/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -target -.snfoundry_cache/ -.env -local-devnet \ No newline at end of file diff --git a/packages/snfoundry/contracts/Scarb.lock b/packages/snfoundry/contracts/Scarb.lock deleted file mode 100644 index 5edbcf7..0000000 --- a/packages/snfoundry/contracts/Scarb.lock +++ /dev/null @@ -1,14 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "contracts" -version = "0.1.0" -dependencies = [ - "openzeppelin", -] - -[[package]] -name = "openzeppelin" -version = "0.10.0" -source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.10.0#d77082732daab2690ba50742ea41080eb23299d3" diff --git a/packages/snfoundry/contracts/Scarb.toml b/packages/snfoundry/contracts/Scarb.toml deleted file mode 100644 index d851aaa..0000000 --- a/packages/snfoundry/contracts/Scarb.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "contracts" -version = "0.1.0" -edition = "2023_11" - - -# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html - -[dependencies] -starknet = ">=2.5.4" -openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.10.0" } - -[[target.starknet-contract]] -casm = true - - -[tool.fmt] -sort-module-level-items = true diff --git a/packages/snfoundry/contracts/src/challenge0.cairo b/packages/snfoundry/contracts/src/challenge0.cairo deleted file mode 100644 index 2fd45ca..0000000 --- a/packages/snfoundry/contracts/src/challenge0.cairo +++ /dev/null @@ -1,231 +0,0 @@ -use starknet::ContractAddress; - -#[starknet::interface] -trait IChallenge0 { - fn mint_item(ref self: T, recipient: ContractAddress, uri: ByteArray) -> u256; -} - -#[starknet::interface] -trait ICounter { - fn token_id_counter(self: @T) -> u256; -} - -#[starknet::interface] -trait IERC721Enumerable { - fn token_of_owner_by_index(self: @T, owner: ContractAddress, index: u256) -> u256; - fn total_supply(self: @T) -> u256; -} - -#[starknet::contract] -mod Challenge0 { - use core::traits::TryInto; - use core::traits::Into; - use super::{IChallenge0, ContractAddress, IERC721Enumerable, ICounter}; - use core::num::traits::zero::Zero; - use openzeppelin::introspection::src5::SRC5Component; - use openzeppelin::token::erc721::ERC721Component; - 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); - - - #[abi(embed_v0)] - impl ERC721Impl = ERC721Component::ERC721Impl; - #[abi(embed_v0)] - 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, - #[substorage(v0)] - ownable: OwnableComponent::Storage, - // ICounter variables - counter: u256, - // ERC721URIStorage variables - // Mapping for token URIs - token_uris: LegacyMap, - // IERC721Enumerable variables - // Mapping from owner to list of owned token IDs - owned_tokens: LegacyMap<(ContractAddress, u256), u256>, - // Mapping from token ID to index of the owner tokens list - owned_tokens_index: LegacyMap, - // Mapping with all token ids, - all_tokens: LegacyMap, - // Counter for all tokens, used for enumeration - all_tokens_counter: u256, - // Mapping from token id to position in the allTokens array - all_tokens_index: LegacyMap - } - - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - #[flat] - ERC721Event: ERC721Component::Event, - #[flat] - SRC5Event: SRC5Component::Event, - #[flat] - OwnableEvent: OwnableComponent::Event - } - - #[constructor] - fn constructor(ref self: ContractState, owner: ContractAddress) { - let name: ByteArray = "YourCollectible"; - let symbol: ByteArray = "YCB"; - let base_uri: ByteArray = "https://ipfs.io/"; - - self.erc721.initializer(name, symbol, base_uri); - self.ownable.initializer(owner); - } - - #[abi(embed_v0)] - impl Challenge0Impl of IChallenge0 { - fn mint_item(ref self: ContractState, recipient: ContractAddress, uri: ByteArray) -> u256 { - self._increment(); - let token_id = self._current(); - self._mint(recipient, token_id); - self._set_token_uri(token_id, uri); - token_id - } - } - - #[abi(embed_v0)] - impl ICounterImpl of ICounter { - fn token_id_counter(self: @ContractState) -> u256 { - self._current() - } - } - - #[abi(embed_v0)] - impl WrappedIERC721MetadataImpl of IERC721Metadata { - // Override token_uri to use the internal ERC721URIStorage _token_uri function - 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)] - impl IERC721EnumerableImpl of IERC721Enumerable { - fn token_of_owner_by_index( - self: @ContractState, owner: ContractAddress, index: u256 - ) -> u256 { - assert(index < self.erc721.balance_of(owner), 'Owner index out of bounds'); - self.owned_tokens.read((owner, index)) - } - fn total_supply(self: @ContractState) -> u256 { - self.all_tokens_counter.read() - } - } - - #[generate_trait] - impl InternalImpl of InternalTrait { - // IChallenge0 internal functions - fn _mint(ref self: ContractState, recipient: ContractAddress, token_id: u256) { - assert(!recipient.is_zero(), ERC721Component::Errors::INVALID_RECEIVER); - assert(!self.erc721._exists(token_id), ERC721Component::Errors::ALREADY_MINTED); - self._before_token_transfer(Zero::zero(), recipient, token_id, 1); - self.erc721._mint(recipient, token_id); - } - - // ICounter internal functions - fn _increment(ref self: ContractState) { - self.counter.write(self.counter.read() + 1); - } - fn _current(self: @ContractState) -> u256 { - self.counter.read() - } - - // ERC721URIStorage internal functions - 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); - } - - // IERC721Enumerable internal functions - fn _add_token_to_owner_enumeration( - ref self: ContractState, recipient: ContractAddress, token_id: u256 - ) { - let length = self.erc721.balance_of(recipient); - self.owned_tokens.write((recipient, length), token_id); - self.owned_tokens_index.write(token_id, length); - } - fn _remove_token_from_owner_enumeration( - ref self: ContractState, from: ContractAddress, token_id: u256 - ) { - // To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and - // then delete the last slot (swap and pop). - let last_token_index = self.erc721.balance_of(from) - 1; - let token_index = self.owned_tokens_index.read(token_id); - - // When the token to delete is the last token, the swap operation is unnecessary - if (token_index != last_token_index) { - let last_token_id = self.owned_tokens.read((from, last_token_index)); - // Move the last token to the slot of the to-delete token - self.owned_tokens.write((from, token_index), last_token_id); - // Update the moved token's index - self.owned_tokens_index.write(last_token_id, token_index); - } - - // Clear the last slot - self.owned_tokens.write((from, last_token_index), 0); - self.owned_tokens_index.write(token_id, 0); - } - fn _remove_token_from_all_tokens_enumeration(ref self: ContractState, token_id: u256) { - let last_token_index = self.all_tokens_counter.read() - 1; - let token_index = self.all_tokens_index.read(token_id); - - let last_token_id = self.all_tokens.read(last_token_index); - - self.all_tokens.write(token_index, last_token_id); - self.all_tokens_index.write(last_token_id, token_index); - - self.all_tokens_index.write(token_id, 0); - self.all_tokens.write(last_token_index, 0); - self.all_tokens_counter.write(last_token_index); - } - fn _add_token_to_all_tokens_enumeration(ref self: ContractState, token_id: u256) { - let length = self.all_tokens_counter.read(); - self.all_tokens_index.write(token_id, length); - self.all_tokens.write(length, token_id); - self.all_tokens_counter.write(length + 1); - } - fn _before_token_transfer( - ref self: ContractState, - from: ContractAddress, - to: ContractAddress, - first_token_id: u256, - batch_size: u256 - ) { - assert(batch_size <= 1, 'Consecutive transfers error'); - if (from == Zero::zero()) { - self._add_token_to_all_tokens_enumeration(first_token_id); - } else if (from != to) { - self._remove_token_from_owner_enumeration(from, first_token_id); - } - if (to == Zero::zero()) { //self._remove_token_from_all_tokens_enumeration(first_token_id); - } else if (to != from) { - self._add_token_to_owner_enumeration(to, first_token_id); - } - } - } -} diff --git a/packages/snfoundry/contracts/src/challenge1.cairo b/packages/snfoundry/contracts/src/challenge1.cairo deleted file mode 100644 index 2675d0b..0000000 --- a/packages/snfoundry/contracts/src/challenge1.cairo +++ /dev/null @@ -1,138 +0,0 @@ -use starknet::ContractAddress; -#[starknet::interface] -pub trait IChallenge1 { - fn execute(ref self: T); - fn stake(ref self: T, amount: u256); - fn withdraw(ref self: T); - fn balances(self: @T, account: ContractAddress) -> u256; - fn completed(self: @T) -> bool; - fn deadline(self: @T) -> u64; - fn example_external_contract(self: @T) -> ContractAddress; - fn open_for_withdraw(self: @T) -> bool; - fn threshold(self: @T) -> u256; - fn total_balance(self: @T) -> u256; - fn time_left(self: @T) -> u64; -} - -#[starknet::contract] -mod Challenge1 { - use contracts::exampleExternalContract::{ - IExampleExternalContractDispatcher, IExampleExternalContractDispatcherTrait - }; - use super::{ContractAddress, IChallenge1}; - use starknet::{get_block_timestamp, get_caller_address, get_contract_address}; - use openzeppelin::token::erc20::interface::{IERC20CamelDispatcher, IERC20CamelDispatcherTrait}; - - pub const THRESHOLD: u256 = 100000000000000000; // ONE_ETH_IN_WEI: 10 ^ 18; - #[storage] - struct Storage { - token: IERC20CamelDispatcher, - balances: LegacyMap, - deadline: u64, - open_for_withdraw: bool, - external_contract_address: ContractAddress, - } - - #[constructor] - fn constructor( - ref self: ContractState, - external_contract_address: ContractAddress, - eth_contract_address: ContractAddress - ) { - self.token.write(IERC20CamelDispatcher { contract_address: eth_contract_address }); - self.deadline.write(get_block_timestamp() + 100); // 45 seconds - self.external_contract_address.write(external_contract_address); - } - - #[abi(embed_v0)] - impl Challenge1Impl of IChallenge1 { - fn stake(ref self: ContractState, amount: u256) { - // ToDo in UI: Sender should approve to transfer the amount to the staker contract - self._not_completed(); - assert(get_block_timestamp() < self.deadline.read(), 'Staking period has ended'); - let sender = get_caller_address(); - let sender_current_amount = self.balances.read(sender); - self.token.read().transferFrom(sender, get_contract_address(), amount); - self.balances.write(sender, sender_current_amount + amount); - } - - // Function to execute the transfer or allow withdrawals after the deadline - fn execute(ref self: ContractState) { - self._not_completed(); - assert(get_block_timestamp() >= self.deadline.read(), 'Staking period has not ended'); - let staked_amount = self.token.read().balanceOf(get_contract_address()); - if (staked_amount >= THRESHOLD) { - self._complete_transfer(staked_amount); - } else { - self.open_for_withdraw.write(true); - } - } - - fn withdraw(ref self: ContractState) { - // Todo in UI: Staker contract should approve to transfer back the sender_amount to the sender - assert(self.open_for_withdraw.read(), 'Withdrawal not allowed'); - let sender = get_caller_address(); - let sender_amount = self.balances.read(sender); - assert(sender_amount > 0, 'No balance to withdraw'); - self.token.read().transferFrom(get_contract_address(), sender, sender_amount); - self.balances.write(sender, 0); - } - - fn balances(self: @ContractState, account: ContractAddress) -> u256 { - self.balances.read(account) - } - - fn total_balance(self: @ContractState) -> u256 { - self.balances.read(get_contract_address()) - } - - fn deadline(self: @ContractState) -> u64 { - self.deadline.read() - } - - fn threshold(self: @ContractState) -> u256 { - THRESHOLD - } - - fn open_for_withdraw(self: @ContractState) -> bool { - self.open_for_withdraw.read() - } - - fn example_external_contract(self: @ContractState) -> ContractAddress { - self.external_contract_address.read() - } - - fn completed(self: @ContractState) -> bool { - let external_contract = IExampleExternalContractDispatcher { - contract_address: self.external_contract_address.read() - }; - external_contract.completed() - } - - fn time_left(self: @ContractState) -> u64 { - let current_time = get_block_timestamp(); - let deadline = self.deadline.read(); - if current_time < deadline { - deadline - current_time - } else { - 0 - } - } - } - - #[generate_trait] - impl InternalImpl of InternalTrait { - fn _complete_transfer(ref self: ContractState, amount: u256) { - let external_contract_address = self.external_contract_address.read(); - let external_contract_dispatcher = IExampleExternalContractDispatcher { - contract_address: external_contract_address - }; - // Todo in UI: Staker contract should approve to transfer the staked_amount to the external contract - self.token.read().transfer(external_contract_address, amount); - external_contract_dispatcher.complete(amount); - } - fn _not_completed(ref self: ContractState) { - assert(!self.completed(), 'Action already completed'); - } - } -} diff --git a/packages/snfoundry/contracts/src/challenge3.cairo b/packages/snfoundry/contracts/src/challenge3.cairo deleted file mode 100644 index 0ce5425..0000000 --- a/packages/snfoundry/contracts/src/challenge3.cairo +++ /dev/null @@ -1,35 +0,0 @@ -#[starknet::contract(account)] -mod Challenge3 { - use openzeppelin::account::AccountComponent; - use openzeppelin::introspection::src5::SRC5Component; - - component!(path: AccountComponent, storage: account, event: AccountEvent); - component!(path: SRC5Component, storage: src5, event: SRC5Event); - - // AccountMixin - #[abi(embed_v0)] - impl AccountMixinImpl = AccountComponent::AccountMixinImpl; - impl AccountInternalImpl = AccountComponent::InternalImpl; - - #[storage] - struct Storage { - #[substorage(v0)] - account: AccountComponent::Storage, - #[substorage(v0)] - src5: SRC5Component::Storage - } - - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - #[flat] - AccountEvent: AccountComponent::Event, - #[flat] - SRC5Event: SRC5Component::Event - } - - #[constructor] - fn constructor(ref self: ContractState, public_key: felt252) { - self.account.initializer(public_key); - } -} \ No newline at end of file diff --git a/packages/snfoundry/contracts/src/exampleExternalContract.cairo b/packages/snfoundry/contracts/src/exampleExternalContract.cairo deleted file mode 100644 index edc5b49..0000000 --- a/packages/snfoundry/contracts/src/exampleExternalContract.cairo +++ /dev/null @@ -1,25 +0,0 @@ -#[starknet::interface] -pub trait IExampleExternalContract { - fn complete(ref self: T, amount: u256); - fn completed(ref self: T) -> bool; -} - -#[starknet::contract] -mod ExampleExternalContract { - #[storage] - struct Storage { - completed: bool, - balance: u256, - } - - #[abi(embed_v0)] - impl ExampleExternalContractImpl of super::IExampleExternalContract { - fn complete(ref self: ContractState, amount: u256) { - self.completed.write(true); - self.balance.write(self.balance.read() + amount); - } - fn completed(ref self: ContractState) -> bool { - self.completed.read() - } - } -} diff --git a/packages/snfoundry/contracts/src/helloStarknet.cairo b/packages/snfoundry/contracts/src/helloStarknet.cairo deleted file mode 100644 index dd14088..0000000 --- a/packages/snfoundry/contracts/src/helloStarknet.cairo +++ /dev/null @@ -1,30 +0,0 @@ -#[starknet::interface] -pub trait IHelloStarknet { - fn increase_balance(ref self: TContractState, amount: u32); - fn get_balance(self: @TContractState) -> u32; - fn get_balance_increment(self: @TContractState, amount: u32) -> u32; -} - -#[starknet::contract] -mod HelloStarknet { - #[storage] - struct Storage { - balance: u32, - } - - #[abi(embed_v0)] - impl HelloStarknetImpl of super::IHelloStarknet { - fn increase_balance(ref self: ContractState, amount: u32) { - assert(amount !=0, 'amount cannot be 0'); - self.balance.write(self.balance.read() + amount); - } - - fn get_balance(self: @ContractState) -> u32 { - self.balance.read() - } - - fn get_balance_increment(self: @ContractState, amount: u32) -> u32 { - self.balance.read() + amount - } - } -} diff --git a/packages/snfoundry/contracts/src/lib.cairo b/packages/snfoundry/contracts/src/lib.cairo deleted file mode 100644 index 5cdce45..0000000 --- a/packages/snfoundry/contracts/src/lib.cairo +++ /dev/null @@ -1,129 +0,0 @@ -mod helloStarknet; -mod simpleStorage; -mod vote; -mod challenge0; -mod challenge1; -mod presetERC1155; -mod challenge3; -mod presetERC20; -mod exampleExternalContract; -mod transferETH; - -use starknet::ContractAddress; - -#[starknet::interface] -trait IData { - fn get_data(self: @T) -> u64; - fn set_data(ref self: T, new_value: u64); -} - -#[starknet::interface] -trait IOwnable { - fn transfer_ownership(ref self: T, new_owner: ContractAddress); - fn owner(self: @T) -> ContractAddress; -} - -#[starknet::component] -pub mod ownable_component { - use super::{ContractAddress, IOwnable}; - use starknet::get_caller_address; - use core::num::traits::Zero; - - #[storage] - struct Storage { - owner: ContractAddress - } - - #[event] - #[derive(Drop, starknet::Event)] - pub enum Event { - OwnershipTransferred: OwnershipTransferred - } - - #[derive(Drop, starknet::Event)] - struct OwnershipTransferred { - #[key] - previous_owner: ContractAddress, - new_owner: ContractAddress, - } - - #[embeddable_as(Ownable)] - impl OwnableImpl< - TContractState, +HasComponent - > of IOwnable> { - fn transfer_ownership( - ref self: ComponentState, new_owner: ContractAddress - ) { - self.only_owner(); - self._transfer_ownership(new_owner); - } - fn owner(self: @ComponentState) -> ContractAddress { - self.owner.read() - } - } - - #[generate_trait] - pub impl InternalImpl< - TContractState, +HasComponent - > of InternalTrait { - fn only_owner(self: @ComponentState) { - let owner: ContractAddress = self.owner.read(); - let caller: ContractAddress = get_caller_address(); - assert(caller.is_non_zero(), 'ZERO_ADDRESS_CALLER'); - assert(caller == owner, 'NOT_OWNER'); - } - - fn _transfer_ownership( - ref self: ComponentState, new_owner: ContractAddress - ) { - let previous_owner: ContractAddress = self.owner.read(); - self.owner.write(new_owner); - self - .emit( - OwnershipTransferred { previous_owner: previous_owner, new_owner: new_owner } - ); - } - } -} - -#[starknet::contract] -mod Ownable { - use contracts::ownable_component; - use super::{ContractAddress, IData}; - - component!(path: ownable_component, storage: ownable, event: OwnableEvent); - - #[abi(embed_v0)] - impl OwnableImpl = ownable_component::Ownable; - - impl OwnableInternalImpl = ownable_component::InternalImpl; - - #[storage] - struct Storage { - data: u64, - #[substorage(v0)] - ownable: ownable_component::Storage - } - - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - OwnableEvent: ownable_component::Event - } - - #[constructor] - fn constructor(ref self: ContractState, initial_owner: ContractAddress) { - self.ownable.owner.write(initial_owner); - self.data.write(1); - } - #[abi(embed_v0)] - impl OwnableDataImpl of IData { - fn get_data(self: @ContractState) -> u64 { - self.data.read() - } - fn set_data(ref self: ContractState, new_value: u64) { - self.ownable.only_owner(); - self.data.write(new_value); - } - } -} diff --git a/packages/snfoundry/contracts/src/presetERC1155.cairo b/packages/snfoundry/contracts/src/presetERC1155.cairo deleted file mode 100644 index e67b7fd..0000000 --- a/packages/snfoundry/contracts/src/presetERC1155.cairo +++ /dev/null @@ -1,65 +0,0 @@ -#[starknet::contract] -mod PresetERC1155 { - use core::num::traits::zero::Zero; - use openzeppelin::introspection::src5::SRC5Component; - use openzeppelin::token::erc1155::ERC1155Component; - use starknet::ContractAddress; - - component!(path: ERC1155Component, storage: erc1155, event: ERC1155Event); - component!(path: SRC5Component, storage: src5, event: SRC5Event); - - // ERC1155 - #[abi(embed_v0)] - impl ERC1155Impl = ERC1155Component::ERC1155Impl; - #[abi(embed_v0)] - impl ERC1155MetadataURIImpl = - ERC1155Component::ERC1155MetadataURIImpl; - - impl ERC1155InternalImpl = ERC1155Component::InternalImpl; - - // SRC5 - #[abi(embed_v0)] - impl SRC5Impl = SRC5Component::SRC5Impl; - - #[storage] - struct Storage { - #[substorage(v0)] - erc1155: ERC1155Component::Storage, - #[substorage(v0)] - src5: SRC5Component::Storage - } - - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - #[flat] - ERC1155Event: ERC1155Component::Event, - #[flat] - SRC5Event: SRC5Component::Event - } - - #[constructor] - fn constructor( - ref self: ContractState, - base_uri: ByteArray, - recipient: ContractAddress, - token_ids: Span, - values: Span - ) { - self.erc1155.initializer(base_uri); - self.batch_mint(recipient, token_ids, values); //unsafe_batch_mint() - } - - #[generate_trait] - impl InternalImpl of InternalTrait { - fn batch_mint( - ref self: ContractState, - recipient: ContractAddress, - token_ids: Span, - values: Span - ) { - assert(recipient.is_non_zero(), ERC1155Component::Errors::INVALID_RECEIVER); - self.erc1155.update(Zero::zero(), recipient, token_ids, values); - } - } -} diff --git a/packages/snfoundry/contracts/src/presetERC20.cairo b/packages/snfoundry/contracts/src/presetERC20.cairo deleted file mode 100644 index cd05528..0000000 --- a/packages/snfoundry/contracts/src/presetERC20.cairo +++ /dev/null @@ -1,39 +0,0 @@ -#[starknet::contract] -mod PresertERC20 { - use openzeppelin::token::erc20::ERC20Component; - use starknet::ContractAddress; - - component!(path: ERC20Component, storage: erc20, event: ERC20Event); - - // ERC20Mixin - #[abi(embed_v0)] - impl ERC20MixinImpl = ERC20Component::ERC20MixinImpl; - impl InternalImpl = ERC20Component::InternalImpl; - - #[storage] - struct Storage { - #[substorage(v0)] - erc20: ERC20Component::Storage - } - - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - #[flat] - ERC20Event: ERC20Component::Event - } - - /// Sets the token `name` and `symbol`. - /// Mints `fixed_supply` tokens to `recipient`. - #[constructor] - fn constructor( - ref self: ContractState, - name: ByteArray, - symbol: ByteArray, - fixed_supply: u256, - recipient: ContractAddress - ) { - self.erc20.initializer(name, symbol); - self.erc20._mint(recipient, fixed_supply); - } -} diff --git a/packages/snfoundry/contracts/src/simpleStorage.cairo b/packages/snfoundry/contracts/src/simpleStorage.cairo deleted file mode 100644 index 08f0615..0000000 --- a/packages/snfoundry/contracts/src/simpleStorage.cairo +++ /dev/null @@ -1,29 +0,0 @@ -#[starknet::interface] -trait ISimpleStorage { - fn get_name(self: @T) -> felt252; - fn set_name(ref self: T, name: felt252); -} - -#[starknet::contract] -mod SimpleStorage { - #[storage] - struct Storage { - name: felt252, - } - - #[constructor] - fn constructor(ref self: ContractState, name: felt252) { - self.name.write(name); - } - - #[abi(embed_v0)] - impl SimpleStorageImpl of super::ISimpleStorage { - fn get_name(self: @ContractState) -> felt252 { - self.name.read() - } - - fn set_name(ref self: ContractState, name: felt252) { - self.name.write(name); - } - } -} diff --git a/packages/snfoundry/contracts/src/transferETH.cairo b/packages/snfoundry/contracts/src/transferETH.cairo deleted file mode 100644 index 4d9539b..0000000 --- a/packages/snfoundry/contracts/src/transferETH.cairo +++ /dev/null @@ -1,71 +0,0 @@ -use starknet::ContractAddress; -#[starknet::interface] -trait ITransferETH { - fn read_balance_contract(self: @T) -> u256; - fn read_balance_account(self: @T, account: ContractAddress) -> u256; - fn caller_and_contract(self: @T) -> (ContractAddress, ContractAddress); - fn transfer_to_contract(ref self: T, amount: u256); - fn approve(ref self: T, spender: ContractAddress, amount: u256) -> bool; - fn allowance(self: @T, owner: ContractAddress, spender: ContractAddress) -> u256; -} - -#[starknet::contract] -mod TransferETH { - use openzeppelin::token::erc20::interface::{IERC20CamelDispatcher, IERC20CamelDispatcherTrait}; - use starknet::{get_caller_address, get_contract_address, ContractAddress}; - #[storage] - struct Storage { - token: IERC20CamelDispatcher, - } - - #[constructor] - fn constructor(ref self: ContractState //, external_contract_address: ContractAddress - ) { - self - .token - .write( - IERC20CamelDispatcher { - contract_address: 0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7 - .try_into() - .unwrap() - } - ); - } - - #[abi(embed_v0)] - impl TransferETHImpl of super::ITransferETH { - fn read_balance_contract(self: @ContractState) -> u256 { - self.token.read().balanceOf(get_contract_address()) - } - fn read_balance_account(self: @ContractState, account: ContractAddress) -> u256 { - self.token.read().balanceOf(account) - } - - fn caller_and_contract(self: @ContractState) -> (ContractAddress, ContractAddress) { - (get_caller_address(), get_contract_address()) - } - - fn approve(ref self: ContractState, spender: ContractAddress, amount: u256) -> bool { - //self.token.read().approve(spender, amount) - let dispatcher = IERC20CamelDispatcher { - contract_address: 0x64b48806902a367c8598f4f95c305e8c1a1acba5f082d294a43793113115691 - .try_into() - .unwrap() - }; - dispatcher.approve(spender, amount) - } - - fn allowance( - self: @ContractState, owner: ContractAddress, spender: ContractAddress - ) -> u256 { - self.token.read().allowance(owner, spender) - } - - fn transfer_to_contract(ref self: ContractState, amount: u256) { - let caller = 0x64b48806902a367c8598f4f95c305e8c1a1acba5f082d294a43793113115691 - .try_into() - .unwrap(); - self.token.read().transferFrom(caller, get_contract_address(), amount); - } - } -} diff --git a/packages/snfoundry/contracts/src/vote.cairo b/packages/snfoundry/contracts/src/vote.cairo deleted file mode 100644 index ba5d19d..0000000 --- a/packages/snfoundry/contracts/src/vote.cairo +++ /dev/null @@ -1,171 +0,0 @@ -/// @dev Core Library Imports for the Traits outside the Starknet Contract -use starknet::ContractAddress; - -/// @dev Trait defining the functions that can be implemented or called by the Starknet Contract -#[starknet::interface] -trait VoteTrait { - /// @dev Function that returns the current vote status - fn get_vote_status(self: @T) -> (u8, u8, u8, u8); - /// @dev Function that checks if the user at the specified address is allowed to vote - fn voter_can_vote(self: @T, user_address: ContractAddress) -> bool; - /// @dev Function that checks if the specified address is registered as a voter - fn is_voter_registered(self: @T, address: ContractAddress) -> bool; - /// @dev Function that allows a user to vote - fn vote(ref self: T, vote: u8); -} - -/// @dev Starknet Contract allowing three registered voters to vote on a proposal -#[starknet::contract] -mod Vote { - use super::ContractAddress; - use starknet::get_caller_address; - - const YES: u8 = 1_u8; - const NO: u8 = 0_u8; - - /// @dev Structure that stores vote counts and voter states - #[storage] - struct Storage { - yes_votes: u8, - no_votes: u8, - can_vote: LegacyMap::, - registered_voter: LegacyMap::, - } - - /// @dev Contract constructor initializing the contract with a list of registered voters and 0 vote count - #[constructor] - fn constructor( - ref self: ContractState, - voter_1: ContractAddress, - voter_2: ContractAddress, - voter_3: ContractAddress - ) { - // Register all voters by calling the _register_voters function - self._register_voters(voter_1, voter_2, voter_3); - } - - /// @dev Event that gets emitted when a vote is cast - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - VoteCast: VoteCast, - UnauthorizedAttempt: UnauthorizedAttempt, - } - - /// @dev Represents a vote that was cast - #[derive(Drop, starknet::Event)] - struct VoteCast { - voter: ContractAddress, - vote: u8, - } - - /// @dev Represents an unauthorized attempt to vote - #[derive(Drop, starknet::Event)] - struct UnauthorizedAttempt { - unauthorized_address: ContractAddress, - } - - /// @dev Implementation of VoteTrait for ContractState - #[abi(embed_v0)] - impl VoteImpl of super::VoteTrait { - /// @dev Returns the voting results - fn get_vote_status(self: @ContractState) -> (u8, u8, u8, u8) { - let (n_yes, n_no) = self._get_voting_result(); - let (yes_percentage, no_percentage) = self._get_voting_result_in_percentage(); - (n_yes, n_no, yes_percentage, no_percentage) - } - - /// @dev Check whether a voter is allowed to vote - fn voter_can_vote(self: @ContractState, user_address: ContractAddress) -> bool { - self.can_vote.read(user_address) - } - - /// @dev Check whether an address is registered as a voter - fn is_voter_registered(self: @ContractState, address: ContractAddress) -> bool { - self.registered_voter.read(address) - } - - /// @dev Submit a vote - fn vote(ref self: ContractState, vote: u8) { - assert(vote == NO || vote == YES, 'VOTE_0_OR_1'); - let caller: ContractAddress = get_caller_address(); - self._assert_allowed(caller); - self.can_vote.write(caller, false); - - if (vote == NO) { - self.no_votes.write(self.no_votes.read() + 1_u8); - } - if (vote == YES) { - self.yes_votes.write(self.yes_votes.read() + 1_u8); - } - - self.emit(VoteCast { voter: caller, vote: vote, }); - } - } - - /// @dev Internal Functions implementation for the Vote contract - #[generate_trait] - impl InternalFunctions of InternalFunctionsTrait { - /// @dev Registers the voters and initializes their voting status to true (can vote) - fn _register_voters( - ref self: ContractState, - voter_1: ContractAddress, - voter_2: ContractAddress, - voter_3: ContractAddress - ) { - self.registered_voter.write(voter_1, true); - self.can_vote.write(voter_1, true); - - self.registered_voter.write(voter_2, true); - self.can_vote.write(voter_2, true); - - self.registered_voter.write(voter_3, true); - self.can_vote.write(voter_3, true); - } - } - - /// @dev Asserts implementation for the Vote contract - #[generate_trait] - impl AssertsImpl of AssertsTrait { - // @dev Internal function that checks if an address is allowed to vote - fn _assert_allowed(ref self: ContractState, address: ContractAddress) { - let is_voter: bool = self.registered_voter.read((address)); - let can_vote: bool = self.can_vote.read((address)); - - if (!can_vote) { // can_vote == false - self.emit(UnauthorizedAttempt { unauthorized_address: address, }); - } - - assert(is_voter, 'USER_NOT_REGISTERED'); - assert(can_vote, 'USER_ALREADY_VOTED'); - } - } - - /// @dev Implement the VotingResultTrait for the Vote contract - #[generate_trait] - impl VoteResultFunctionsImpl of VoteResultFunctionsTrait { - // @dev Internal function to get the voting results (yes and no vote counts) - fn _get_voting_result(self: @ContractState) -> (u8, u8) { - let n_yes: u8 = self.yes_votes.read(); - let n_no: u8 = self.no_votes.read(); - - (n_yes, n_no) - } - - // @dev Internal function to calculate the voting results in percentage - fn _get_voting_result_in_percentage(self: @ContractState) -> (u8, u8) { - let n_yes: u8 = self.yes_votes.read(); - let n_no: u8 = self.no_votes.read(); - - let total_votes: u8 = n_yes + n_no; - - if (total_votes == 0_u8) { - return (0, 0); - } - let yes_percentage: u8 = (n_yes * 100_u8) / (total_votes); - let no_percentage: u8 = (n_no * 100_u8) / (total_votes); - - (yes_percentage, no_percentage) - } - } -} diff --git a/packages/snfoundry/deployments/.gitignore b/packages/snfoundry/deployments/.gitignore deleted file mode 100644 index c96a04f..0000000 --- a/packages/snfoundry/deployments/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore \ No newline at end of file diff --git a/packages/snfoundry/local-devnet b/packages/snfoundry/local-devnet deleted file mode 160000 index 46e0ec0..0000000 --- a/packages/snfoundry/local-devnet +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 46e0ec032956f0e7cbe0330f32b6b31eff824087 diff --git a/packages/snfoundry/localhost.accounts.json b/packages/snfoundry/localhost.accounts.json deleted file mode 100644 index dbb27fa..0000000 --- a/packages/snfoundry/localhost.accounts.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "alpha-goerli": { - "deployer_devnet": { - "address": "0x64b48806902a367c8598f4f95c305e8c1a1acba5f082d294a43793113115691", - "class_hash": "0x40eb847952726e600b41f8195a26a667f610cfd62083eee9ec24b612b53b503", - "deployed": true, - "private_key": "0x71d7bb07b9a64f6f78ac4c816aff4da9", - "public_key": "0x39d9e6ce352ad4530a0ef5d5a18fd3303c3606a7fa6ac5b620020ad681cc33b", - "salt": "0x1" - } - } -} diff --git a/packages/snfoundry/package.json b/packages/snfoundry/package.json deleted file mode 100644 index 6179c51..0000000 --- a/packages/snfoundry/package.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "name": "@ss-2/snfoundry", - "version": "0.0.1", - "scripts": { - "chain": "cd local-devnet && cargo run -- --seed 0 --account-class cairo1", - "deploy": "node scripts_js/helpers/deploy-wrapper.js", - "prev-deploy": "scarb build && node scripts_js/deploy.js ${1} > ./scripts_js/deployOutput.txt && node ./scripts_js/parseDeployOutput.js", - "bare-deploy": "scripts_js/deploy.js", - "format": "cd local-devnet/scripts && sh format.sh" - }, - "devDependencies": { - "@types/prettier": "^2", - "yargs": "^17.7.2" - }, - "dependencies": { - "dotenv": "^16.3.1", - "envfile": "^6.18.0", - "prettier": "^2.8.8", - "starknet": "5.25.0", - "starknet-dev": "npm:starknet@6.7.0", - "toml": "^3.0.0", - "tslib": "^2.6.2" - } -} diff --git a/packages/snfoundry/scripts_cairo/deploy/Scarb.lock b/packages/snfoundry/scripts_cairo/deploy/Scarb.lock deleted file mode 100644 index 93918e9..0000000 --- a/packages/snfoundry/scripts_cairo/deploy/Scarb.lock +++ /dev/null @@ -1,19 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "contracts" -version = "0.1.0" - -[[package]] -name = "deploy" -version = "0.1.0" -dependencies = [ - "contracts", - "sncast_std", -] - -[[package]] -name = "sncast_std" -version = "0.19.0" -source = "git+https://github.com/foundry-rs/starknet-foundry?tag=v0.19.0#a3391dce5bdda51c63237032e6cfc64fb7a346d4" diff --git a/packages/snfoundry/scripts_cairo/deploy/Scarb.toml b/packages/snfoundry/scripts_cairo/deploy/Scarb.toml deleted file mode 100644 index 2ff06e5..0000000 --- a/packages/snfoundry/scripts_cairo/deploy/Scarb.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "deploy" -version = "0.1.0" -edition = "2023_11" - -# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html - -[dependencies] -sncast_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.19.0" } -starknet = "2.5.4" -contracts = { path = "../../../snfoundry" } - -[lib] -sierra = true -casm = true - -[[target.starknet-contract]] -sierra = true -casm = true -build-external-contracts = [ - "contracts::HelloStarknet" -] \ No newline at end of file diff --git a/packages/snfoundry/scripts_cairo/deploy/src/deploy.cairo b/packages/snfoundry/scripts_cairo/deploy/src/deploy.cairo deleted file mode 100644 index f23cdf2..0000000 --- a/packages/snfoundry/scripts_cairo/deploy/src/deploy.cairo +++ /dev/null @@ -1,37 +0,0 @@ -use sncast_std::{ - declare, deploy, invoke, call, DeclareResult, DeployResult, InvokeResult, CallResult, get_nonce, DisplayContractAddress, DisplayClassHash -}; - -fn main() { - let max_fee = 9999999999999999999; - let salt = 0x3; - - let declare_result = declare("HelloStarknet", Option::Some(max_fee), Option::None).expect('declare failed'); - - let nonce = get_nonce('latest'); - let class_hash = declare_result.class_hash; - - println!("Class hash of the declared contract: {}", class_hash); - - let deploy_result = deploy( - class_hash, ArrayTrait::new(), Option::Some(salt), true, Option::Some(max_fee), Option::Some(nonce) - ).expect('deploy failed'); - - println!("Deployed the contract to address: {}", deploy_result.contract_address); - - let call_result = call(deploy_result.contract_address, selector!("get_balance"), array![]).expect('call failed'); - assert(call_result.data == array![0x0], *call_result.data.at(0)); - println!("Call result: {}", call_result); - - let invoke_nonce = get_nonce('pending'); - let invoke_result = invoke( - deploy_result.contract_address, selector!("increase_balance"), array![0x1], Option::Some(max_fee), Option::Some(invoke_nonce) - ).expect('invoke failed'); - - println!("Invoke tx hash is: {}", invoke_result.transaction_hash); - - let call_result = call(deploy_result.contract_address, selector!("get_balance"), array![]).expect('call failed'); - - println!("Call result: {}", call_result); - assert(call_result.data == array![0x1], *call_result.data.at(0)); -} \ No newline at end of file diff --git a/packages/snfoundry/scripts_cairo/deploy/src/lib.cairo b/packages/snfoundry/scripts_cairo/deploy/src/lib.cairo deleted file mode 100644 index aab060a..0000000 --- a/packages/snfoundry/scripts_cairo/deploy/src/lib.cairo +++ /dev/null @@ -1 +0,0 @@ -mod deploy; diff --git a/packages/snfoundry/scripts_js/deploy.js b/packages/snfoundry/scripts_js/deploy.js deleted file mode 100644 index cf79ad5..0000000 --- a/packages/snfoundry/scripts_js/deploy.js +++ /dev/null @@ -1,10 +0,0 @@ -const { deployer, deployContract } = require("./deploy_contract"); -const deployScript = async () => { - await deployContract(null, "HelloStarknet"); -}; - -deployScript() - .then(() => { - console.log("All Setup Done"); - }) - .catch(console.error); diff --git a/packages/snfoundry/scripts_js/deploy_contract.js b/packages/snfoundry/scripts_js/deploy_contract.js deleted file mode 100644 index cd3257c..0000000 --- a/packages/snfoundry/scripts_js/deploy_contract.js +++ /dev/null @@ -1,126 +0,0 @@ -const fs = require("fs"); -const path = require("path"); -const networks = require("./helpers/networks"); -const argv = require("yargs/yargs")(process.argv.slice(2)).argv; -const { hash, TransactionStatus } = require("starknet"); -const { CallData } = require("starknet-dev"); - -const networkName = argv.network; - -const { provider, deployer } = networks[networkName]; -const deployContract = async ( - constructorArgs, - contractName, - exportContractName -) => { - const compiledContractCasm = JSON.parse( - fs - .readFileSync( - path.resolve( - __dirname, - `../contracts/target/dev/contracts_${contractName}.compiled_contract_class.json` - ) - ) - .toString("ascii") - ); - - const compiledContractSierra = JSON.parse( - fs - .readFileSync( - path.resolve( - __dirname, - `../contracts/target/dev/contracts_${contractName}.contract_class.json` - ) - ) - .toString("ascii") - ); - - let classHash; - let existingClass; - let contractAddress; - - const precomputedClassHash = hash.computeSierraContractClassHash( - compiledContractSierra - ); - const contractCalldata = new CallData(compiledContractSierra.abi); - const constructorCalldata = constructorArgs - ? contractCalldata.compile("constructor", constructorArgs) - : []; - console.log("Deploying Contract ", contractName); - - let totalFee = 0n; - - try { - const { suggestedMaxFee: estimatedFeeDeclare } = - await deployer.estimateDeclareFee( - { - contract: compiledContractSierra, - casm: compiledContractCasm, - }, - {} - ); - totalFee = estimatedFeeDeclare * 2n; - } catch (e) { - const { suggestedMaxFee: estimatedFeeDeploy } = - await deployer.estimateDeployFee({ - classHash: precomputedClassHash, - constructorCalldata, - }); - totalFee = estimatedFeeDeploy * 2n; - } - - try { - const tryDeclareAndDeploy = await deployer.declareAndDeploy( - { - contract: compiledContractSierra, - casm: compiledContractCasm, - constructorCalldata, - }, - { - maxFee: totalFee * 20n, // this optional max fee serves when error AccountValidation Failed or small fee on public networks , try 5n , 10n, 20n, 50n, 100n - } - ); - const debug = await provider.waitForTransaction( - tryDeclareAndDeploy.deploy.transaction_hash, - { - successStates: [TransactionStatus.ACCEPTED_ON_L2], - // retryInterval: 10000, // we can retry in 10 seconds - } - ); - classHash = tryDeclareAndDeploy.declare.class_hash; - existingClass = await provider.getClassByHash(classHash); - contractAddress = tryDeclareAndDeploy.deploy.address; - contractAddress = "0x" + contractAddress.slice(2).padStart(64, "0"); - } catch (e) { - console.log("Error", e); - } - console.log("Deployed contract ", contractName, " at: ", contractAddress); - const chainIdPath = path.resolve( - __dirname, - `../deployments/${networkName}.json` - ); - let deployments = {}; - if (fs.existsSync(chainIdPath)) { - deployments = JSON.parse(fs.readFileSync(chainIdPath).toString()); - } - - let finalContractName = exportContractName || contractName; - - deployments[finalContractName] = { - classHash: classHash, - address: contractAddress, - contract: contractName, - }; - - fs.writeFileSync(chainIdPath, JSON.stringify(deployments, null, 2)); - - return { - classHash: classHash, - abi: JSON.stringify(existingClass.abi), - address: contractAddress, - }; -}; - -module.exports = { - deployContract, deployer -}; diff --git a/packages/snfoundry/scripts_js/helpers/deploy-wrapper.js b/packages/snfoundry/scripts_js/helpers/deploy-wrapper.js deleted file mode 100644 index 29ca328..0000000 --- a/packages/snfoundry/scripts_js/helpers/deploy-wrapper.js +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env node -var argv = require("yargs/yargs")(process.argv.slice(2)).parse(); - -// Set the NETWORK environment variable based on the --network argument -process.env.NETWORK = argv.network || "devnet"; - -// Execute the deploy script -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" }, -); diff --git a/packages/snfoundry/scripts_js/helpers/networks.js b/packages/snfoundry/scripts_js/helpers/networks.js deleted file mode 100644 index 61bb61d..0000000 --- a/packages/snfoundry/scripts_js/helpers/networks.js +++ /dev/null @@ -1,88 +0,0 @@ -const { RpcProvider, Account } = require("starknet"); -const path = require("path"); -const dotenv = require("dotenv"); -dotenv.config({ path: path.resolve(__dirname, "../../.env") }); - -// devnet -const PRIVATE_KEY_DEVNET = - process.env.PRIVATE_KEY_DEVNET || "0x71d7bb07b9a64f6f78ac4c816aff4da9"; -const RPC_URL_DEVNET = process.env.RPC_URL_DEVNET || "http://127.0.0.1:5050"; -const ACCOUNT_ADDRESS_DEVNET = - process.env.ACCOUNT_ADDRESS_DEVNET || - "0x64b48806902a367c8598f4f95c305e8c1a1acba5f082d294a43793113115691"; - -const providerDevnet = - RPC_URL_DEVNET && - new RpcProvider({ - nodeUrl: RPC_URL_DEVNET, - }); -const deployerDevnet = - ACCOUNT_ADDRESS_DEVNET && - PRIVATE_KEY_DEVNET && - new Account(providerDevnet, ACCOUNT_ADDRESS_DEVNET, PRIVATE_KEY_DEVNET, 1); -// goerli -const providerGoerli = - process.env.RPC_URL_GOERLI && - new RpcProvider({ - nodeUrl: process.env.RPC_URL_GOERLI, - }); -const deployerGoerli = - process.env.ACCOUNT_ADDRESS_GOERLI && - process.env.PRIVATE_KEY_GOERLI && - new Account( - providerGoerli, - process.env.ACCOUNT_ADDRESS_GOERLI, - process.env.PRIVATE_KEY_GOERLI, - 1, - ); - -// sepolia -const providerSepolia = - process.env.RPC_URL_SEPOLIA && - new RpcProvider({ - nodeUrl: process.env.RPC_URL_SEPOLIA, - }); -const deployerSepolia = - process.env.ACCOUNT_ADDRESS_SEPOLIA && - process.env.PRIVATE_KEY_SEPOLIA && - new Account( - providerSepolia, - process.env.ACCOUNT_ADDRESS_SEPOLIA, - process.env.PRIVATE_KEY_SEPOLIA, - 1, - ); - -// mainnet -const providerMainnet = - process.env.RPC_URL_MAINNET && - new RpcProvider({ - nodeUrl: process.env.RPC_URL_MAINNET, - }); -const deployerMainnet = - process.env.ACCOUNT_ADDRESS_MAINNET && - process.env.PRIVATE_KEY_MAINNET && - new Account( - providerMainnet, - process.env.ACCOUNT_ADDRESS_MAINNET, - process.env.PRIVATE_KEY_MAINNET, - 1, - ); - -module.exports = { - devnet: { - provider: providerDevnet, - deployer: deployerDevnet, - }, - goerli: { - provider: providerGoerli, - deployer: deployerGoerli, - }, - sepolia: { - provider: providerSepolia, - deployer: deployerSepolia, - }, - mainnet: { - provider: providerMainnet, - deployer: deployerMainnet, - }, -}; diff --git a/packages/snfoundry/scripts_js/helpers/parseDeployments.js b/packages/snfoundry/scripts_js/helpers/parseDeployments.js deleted file mode 100644 index 9eb86d0..0000000 --- a/packages/snfoundry/scripts_js/helpers/parseDeployments.js +++ /dev/null @@ -1,76 +0,0 @@ -const fs = require("fs"); -const path = require("path"); -const prettier = require("prettier"); - -const TARGET_DIR = path.join(__dirname, "../../../nextjs/contracts"); -const deploymentsDir = path.join(__dirname, "../../deployments"); -const files = fs.readdirSync(deploymentsDir); - -const generatedContractComment = `/** - * This file is autogenerated by Scaffold-Stark. - * You should not edit it manually or your changes might be overwritten. - */`; - -const getContractDataFromDeployments = () => { - const allContractsData = {}; - - files.forEach((file) => { - if (path.extname(file) === ".json") { - const filePath = path.join(deploymentsDir, file); - const content = JSON.parse(fs.readFileSync(filePath, "utf8")); - const chainId = path.basename(file, ".json"); - - Object.entries(content).forEach(([contractName, contractData]) => { - try { - const abiFilePath = path.join( - __dirname, - `../../contracts/target/dev/contracts_${contractData.contract}.contract_class.json`, - ); - const abiContent = JSON.parse(fs.readFileSync(abiFilePath, "utf8")); - - allContractsData[chainId] = { - ...allContractsData[chainId], - [contractName]: { - address: contractData.address, - abi: abiContent.abi, - }, - }; - } catch (e) {} - }); - } - }); - - return allContractsData; -}; - -const generateTsAbis = () => { - const allContractsData = getContractDataFromDeployments(); - - const fileContent = Object.entries(allContractsData).reduce( - (content, [chainId, chainConfig]) => { - // Use chainId directly as it is already a hex string - return `${content}${chainId}:${JSON.stringify(chainConfig, null, 2)},`; - }, - "", - ); - - if (!fs.existsSync(TARGET_DIR)) { - fs.mkdirSync(TARGET_DIR); - } - - fs.writeFileSync( - path.join(TARGET_DIR, "deployedContracts.ts"), - prettier.format( - `${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`, - ); -}; - -generateTsAbis(); diff --git a/yarn.lock b/yarn.lock index 90e75e0..ea8246c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1630,22 +1630,6 @@ __metadata: languageName: unknown linkType: soft -"@ss-2/snfoundry@workspace:packages/snfoundry": - version: 0.0.0-use.local - resolution: "@ss-2/snfoundry@workspace:packages/snfoundry" - dependencies: - "@types/prettier": ^2 - dotenv: ^16.3.1 - envfile: ^6.18.0 - prettier: ^2.8.8 - starknet: 5.25.0 - starknet-dev: "npm:starknet@6.7.0" - toml: ^3.0.0 - tslib: ^2.6.2 - yargs: ^17.7.2 - languageName: unknown - linkType: soft - "@starknet-react/chains@npm:^0.1.7": version: 0.1.7 resolution: "@starknet-react/chains@npm:0.1.7" @@ -1831,13 +1815,6 @@ __metadata: languageName: node linkType: hard -"@types/prettier@npm:^2": - version: 2.7.3 - resolution: "@types/prettier@npm:2.7.3" - checksum: 705384209cea6d1433ff6c187c80dcc0b95d99d5c5ce21a46a9a58060c527973506822e428789d842761e0280d25e3359300f017fbe77b9755bc772ab3dc2f83 - languageName: node - linkType: hard - "@types/prop-types@npm:*": version: 15.7.12 resolution: "@types/prop-types@npm:15.7.12" @@ -3255,13 +3232,6 @@ __metadata: languageName: node linkType: hard -"dotenv@npm:^16.3.1": - version: 16.4.5 - resolution: "dotenv@npm:16.4.5" - checksum: 301a12c3d44fd49888b74eb9ccf9f07a1f5df43f489e7fcb89647a2edcd84c42d6bc349dc8df099cd18f07c35c7b04685c1a4f3e6a6a9e6b30f8d48c15b7f49c - languageName: node - linkType: hard - "eastasianwidth@npm:^0.2.0": version: 0.2.0 resolution: "eastasianwidth@npm:0.2.0" @@ -3353,15 +3323,6 @@ __metadata: languageName: node linkType: hard -"envfile@npm:^6.18.0": - version: 6.22.0 - resolution: "envfile@npm:6.22.0" - bin: - envfile: bin.cjs - checksum: 95e29f82be5f1365bf3dc3b324576c5df69fbc9b28238cf876cff08124307693e49cf0d9df6ba8735d42b35b6f59ec01fda28435b839319652e9618a1430aa6b - languageName: node - linkType: hard - "err-code@npm:^2.0.2": version: 2.0.3 resolution: "err-code@npm:2.0.3" @@ -6763,15 +6724,6 @@ __metadata: languageName: node linkType: hard -"prettier@npm:^2.8.8": - version: 2.8.8 - resolution: "prettier@npm:2.8.8" - bin: - prettier: bin-prettier.js - checksum: b49e409431bf129dd89238d64299ba80717b57ff5a6d1c1a8b1a28b590d998a34e083fa13573bc732bb8d2305becb4c9a4407f8486c81fa7d55100eb08263cf8 - languageName: node - linkType: hard - "prettier@npm:^3.2.5": version: 3.2.5 resolution: "prettier@npm:3.2.5" @@ -7899,13 +7851,6 @@ __metadata: languageName: node linkType: hard -"toml@npm:^3.0.0": - version: 3.0.0 - resolution: "toml@npm:3.0.0" - checksum: 5d7f1d8413ad7780e9bdecce8ea4c3f5130dd53b0a4f2e90b93340979a137739879d7b9ce2ce05c938b8cc828897fe9e95085197342a1377dd8850bf5125f15f - languageName: node - linkType: hard - "tough-cookie@npm:^4.0.0": version: 4.1.3 resolution: "tough-cookie@npm:4.1.3" @@ -8038,7 +7983,7 @@ __metadata: languageName: node linkType: hard -"tslib@npm:^2.0.0, tslib@npm:^2.1.0, tslib@npm:^2.4.0, tslib@npm:^2.6.2": +"tslib@npm:^2.0.0, tslib@npm:^2.1.0, tslib@npm:^2.4.0": version: 2.6.2 resolution: "tslib@npm:2.6.2" checksum: 329ea56123005922f39642318e3d1f0f8265d1e7fcb92c633e0809521da75eeaca28d2cf96d7248229deb40e5c19adf408259f4b9640afd20d13aecc1430f3ad