Skip to content

Commit

Permalink
Merge branch 'main' into rejected-tx
Browse files Browse the repository at this point in the history
# Conflicts:
#	packages/nextjs/scaffold.config.ts
  • Loading branch information
smithii-tech committed Apr 8, 2024
2 parents 97044d1 + 785110e commit 523b72e
Show file tree
Hide file tree
Showing 11 changed files with 872 additions and 36 deletions.
603 changes: 602 additions & 1 deletion packages/nextjs/contracts/deployedContracts.ts

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions packages/snfoundry/bash/run-devnet.sh

This file was deleted.

8 changes: 8 additions & 0 deletions packages/snfoundry/contracts/Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@ 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"
1 change: 1 addition & 0 deletions packages/snfoundry/contracts/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ edition = "2023_11"

[dependencies]
starknet = ">=2.5.4"
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.10.0" }

[[target.starknet-contract]]
casm = true
63 changes: 63 additions & 0 deletions packages/snfoundry/contracts/src/challenge0.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#[starknet::contract]
mod Challenge0 {
use openzeppelin::introspection::src5::SRC5Component;
use openzeppelin::token::erc721::ERC721Component;
use starknet::ContractAddress;

component!(path: ERC721Component, storage: erc721, event: ERC721Event);
component!(path: SRC5Component, storage: src5, event: SRC5Event);

// ERC721Mixin
#[abi(embed_v0)]
impl ERC721MixinImpl = ERC721Component::ERC721MixinImpl<ContractState>;
impl ERC721InternalImpl = ERC721Component::InternalImpl<ContractState>;

#[storage]
struct Storage {
#[substorage(v0)]
erc721: ERC721Component::Storage,
#[substorage(v0)]
src5: SRC5Component::Storage
}

#[event]
#[derive(Drop, starknet::Event)]
enum Event {
#[flat]
ERC721Event: ERC721Component::Event,
#[flat]
SRC5Event: SRC5Component::Event
}

#[constructor]
fn constructor(
ref self: ContractState,
recipient: felt252
) {
//let arr = array![1, 2, 3];
let name:ByteArray = "YourCollectible";
let symbol:ByteArray = "YCB";
let base_uri:ByteArray = "https://ipfs.io/ipfs/QmfVMAmNM1kDEBYrC2TPzQDoCRFH6F5tE1e9Mr4FkkR5Xr"; // bison nft
//let token_id = arr.span();

self.erc721.initializer(name, symbol, base_uri);
//self._mint_assets(recipient, token_id);
}

#[generate_trait]
impl InternalImpl of InternalTrait {
/// Mints `token_ids` to `recipient`.
fn _mint_assets(
ref self: ContractState, recipient: ContractAddress, mut token_ids: Span<u256>
) {
loop {
if token_ids.len() == 0 {
break;
}
let id = *token_ids.pop_front().unwrap();

self.erc721._mint(recipient, id);
}
}
}
}
39 changes: 39 additions & 0 deletions packages/snfoundry/contracts/src/challenge1.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#[starknet::contract]
mod Challenge1 {
use openzeppelin::token::erc20::ERC20Component;
use starknet::ContractAddress;

component!(path: ERC20Component, storage: erc20, event: ERC20Event);

// ERC20Mixin
#[abi(embed_v0)]
impl ERC20MixinImpl = ERC20Component::ERC20MixinImpl<ContractState>;
impl InternalImpl = ERC20Component::InternalImpl<ContractState>;

#[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);
}
}
54 changes: 54 additions & 0 deletions packages/snfoundry/contracts/src/challenge2.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#[starknet::contract]
mod Challenge2 {
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<ContractState>;
#[abi(embed_v0)]
impl ERC1155MetadataURIImpl =
ERC1155Component::ERC1155MetadataURIImpl<ContractState>;
#[abi(embed_v0)]
impl ERC1155Camel = ERC1155Component::ERC1155CamelImpl<ContractState>;
impl ERC1155InternalImpl = ERC1155Component::InternalImpl<ContractState>;

// SRC5
#[abi(embed_v0)]
impl SRC5Impl = SRC5Component::SRC5Impl<ContractState>;

#[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<u256>,
values: Span<u256>
) {
self.erc1155.initializer(base_uri);
self
.erc1155
.batch_mint_with_acceptance_check(recipient, token_ids, values, array![].span());
}
}
35 changes: 35 additions & 0 deletions packages/snfoundry/contracts/src/challenge3.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#[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<ContractState>;
impl AccountInternalImpl = AccountComponent::InternalImpl<ContractState>;

#[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);
}
}
4 changes: 4 additions & 0 deletions packages/snfoundry/contracts/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
mod helloStarknet;
mod simpleStorage;
mod vote;
mod challenge0;
mod challenge1;
mod challenge2;
mod challenge3;

use starknet::ContractAddress;

Expand Down
2 changes: 1 addition & 1 deletion packages/snfoundry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@ss-2/snfoundry",
"version": "0.0.1",
"scripts": {
"chain": "cd bash && ./run-devnet.sh",
"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"
Expand Down
97 changes: 65 additions & 32 deletions packages/snfoundry/scripts_js/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {
ContractAddress,
getChecksumAddress,
CallData,
validateChecksumAddress,
TransactionStatus,
addAddressPadding,
} = require("starknet");
const { hash } = require("starknet");
Expand Down Expand Up @@ -77,19 +77,17 @@ const deployContract = async (
}

try {
const tryDeclareAndDeploy = await deployer.declareAndDeploy(
{
contract: compiledContractSierra,
casm: compiledContractCasm,
constructorCalldata,
},
const tryDeclareAndDeploy = await deployer.declareAndDeploy({
contract: compiledContractSierra,
casm: compiledContractCasm,
constructorCalldata,
});
await provider.waitForTransaction(
tryDeclareAndDeploy.deploy.transaction_hash,
{
maxFee: totalFee,
successStates: [TransactionStatus.ACCEPTED_ON_L2],
}
);
await provider.waitForTransaction(
tryDeclareAndDeploy.deploy.transaction_hash
);
classHash = tryDeclareAndDeploy.declare.class_hash;
existingClass = await provider.getClassByHash(classHash);
contractAddress = tryDeclareAndDeploy.deploy.address;
Expand Down Expand Up @@ -132,30 +130,65 @@ const deployScript = async () => {
} = await deployContract(null, "HelloStarknet"); // can pass another argument for the exported contract name
await deployContract(
{
name: 1
name: 1,
},
"SimpleStorage"
); // simple storage receives an argument in the constructor
await deployContract(
{
voter_1: addAddressPadding(
"0x06072Bb27d275a0bC1deBf1753649b8721CF845B681A48443Ac46baF45769f8E"
),
voter_2: addAddressPadding(
"0x06072Bb27d275a0bC1deBf1753649b8721CF845B681A48443Ac46baF45769f8E"
),
voter_3: addAddressPadding(
"0x06072Bb27d275a0bC1deBf1753649b8721CF845B681A48443Ac46baF45769f8E"
),
},
"Vote"
);
await deployContract(
{
initial_owner: addAddressPadding("0x64b48806902a367c8598f4f95c305e8c1a1acba5f082d294a43793113115691"),
},
"Ownable"
); // simple storage receives an argument in the constructor
// await deployContract(
// {
// recipient: 1,
// },
// "Challenge0"
// );

// await deployContract(
// {
// name: 1,
// symbol: 2,
// fixed_supply: 10,
// recipient:
// "0x06072Bb27d275a0bC1deBf1753649b8721CF845B681A48443Ac46baF45769f8E",
// },
// "Challenge1"
// );

// await deployContract(
// {
// base_uri: CallData.byteArrayFromString("https://example.com/"),
// // recipient:
// // "0x06072Bb27d275a0bC1deBf1753649b8721CF845B681A48443Ac46baF45769f8E",
// // token_ids: 2,
// // values: 100,
// },
// "Challenge2"
// );

// await deployContract(
// {
// public_key: "0x6e4fd4f9d6442e10cf8e20a799be3533be3756c5ea4d13e16a297d7d2717039",
// },
// "Challenge3"
// );

// await deployContract(
// {
// voter_1:
// "0x06072Bb27d275a0bC1deBf1753649b8721CF845B681A48443Ac46baF45769f8E",
// voter_2:
// "0x06072Bb27d275a0bC1deBf1753649b8721CF845B681A48443Ac46baF45769f8E",
// voter_3:
// "0x06072Bb27d275a0bC1deBf1753649b8721CF845B681A48443Ac46baF45769f8E",
// },
// "Vote"
// );
// await deployContract(
// {
// initial_owner: addAddressPadding(
// "0x64b48806902a367c8598f4f95c305e8c1a1acba5f082d294a43793113115691"
// ),
// },
// "Ownable"
// ); // simple storage receives an argument in the constructor
};

deployScript()
Expand Down

0 comments on commit 523b72e

Please sign in to comment.