Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/erc1155 fixes #49

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/snfoundry/contracts/.tool-versions
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
scarb 2.8.4
starknet-foundry 0.31.0


2 changes: 1 addition & 1 deletion apps/snfoundry/contracts/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ casm = true
sierra = true

[tool.fmt]
sort-module-level-items = true
sort-module-level-items = true
31 changes: 31 additions & 0 deletions apps/snfoundry/contracts/src/cofi_collection.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,23 @@ pub trait ICofiCollection<TContractState> {
data: Span<felt252>,
);

/// Mints a new token item with a specific URI to a recipient.
///
/// # Arguments
/// * `recipient` - The address that will receive the minted token.
/// * `token_id` - The ID of the token to mint.
/// * `value` - The amount of tokens to mint.
/// * `data` - Additional data to accompany the minting.
/// * `uri` - The URI containing metadata for this token.
fn mint_item(
ref self: TContractState,
recipient: ContractAddress,
token_id: u256,
value: u256,
data: Span<felt252>,
uri: ByteArray
);

/// Burns `value` amount of `token_id` from `account`.
///
/// # Arguments
Expand Down Expand Up @@ -326,6 +343,20 @@ mod CofiCollection {
self.erc1155.mint_with_acceptance_check(account, token_id, value, data);
}

#[external(v0)]
fn mint_item(
ref self: ContractState,
recipient: ContractAddress,
token_id: u256,
value: u256,
data: Span<felt252>,
uri: ByteArray
) {
self.accesscontrol.assert_only_role(MINTER_ROLE);
self.erc1155.mint_with_acceptance_check(recipient, token_id, value, data);
self.erc1155._set_base_uri(uri);
}

#[external(v0)]
fn batch_mint(
ref self: ContractState,
Expand Down
21 changes: 21 additions & 0 deletions apps/snfoundry/contracts/src/test/test_cofi_collection.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -413,3 +413,24 @@ fn test_uri() {
let another_token_uri = cofi_collection.uri(another_token_id);
assert(another_token_uri == base_uri, 'Incorrect token URI');
}


#[test]
fn test_mint_item() {
let cofi_collection = deploy_cofi_collection();
let owner = OWNER();
let token_id = 1_u256;
let uri: ByteArray = "https://api.example.com/token/";
let value = 1_u256;
let data: Array<felt252> = array![];
let receiver = deploy_receiver();

start_cheat_caller_address(cofi_collection.contract_address, owner);
cofi_collection.mint_item(receiver, token_id, value, data.span(), uri.clone());

let balance = cofi_collection.balance_of(receiver, token_id);
assert(balance == value, 'Incorrect balance');

let token_uri = cofi_collection.uri(token_id);
assert(token_uri == uri, 'Incorrect token URI');
}
2 changes: 2 additions & 0 deletions apps/snfoundry/scripts-ts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import { green } from "./helpers/colorize-log";
* @returns {Promise<void>}
*/
const deployScript = async (): Promise<void> => {
console.log("🚀 Deploying with address:", green(deployer.address));

await deployContract({
contract: "cofi_collection.cairo",
contractName: "CofiCollection",
Expand Down
3 changes: 2 additions & 1 deletion apps/snfoundry/scripts-ts/helpers/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ dotenv.config({ path: path.resolve(__dirname, "../../.env") });

// devnet
const PRIVATE_KEY_DEVNET =
process.env.PRIVATE_KEY_DEVNET || "0x71d7bb07b9a64f6f78ac4c816aff4da9";
process.env.PRIVATE_KEY_DEVNET ||
"0x0000000000000000000000000000000071d7bb07b9a64f6f78ac4c816aff4da9";
const RPC_URL_DEVNET = process.env.RPC_URL_DEVNET || "http://127.0.0.1:5050";
const ACCOUNT_ADDRESS_DEVNET =
process.env.ACCOUNT_ADDRESS_DEVNET ||
Expand Down
Loading