Skip to content

Commit

Permalink
Merge pull request #380 from BibliothecaDAO/feat/arcade-intro
Browse files Browse the repository at this point in the history
Feat/arcade intro
  • Loading branch information
starknetdev authored Oct 9, 2023
2 parents 164e699 + ed23a13 commit e9503e0
Show file tree
Hide file tree
Showing 55 changed files with 3,995 additions and 3,836 deletions.
1 change: 1 addition & 0 deletions contracts/lords/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
11 changes: 11 additions & 0 deletions contracts/lords/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "lords"
version = "0.1.0"

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

[[target.starknet-contract]]
allowed-libfuncs-list.name = "experimental"
allowed-libfuncs = true
284 changes: 284 additions & 0 deletions contracts/lords/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,284 @@
//! SPDX-License-Identifier: MIT
//! OpenZeppelin Contracts for Cairo v0.7.0 (token/erc20/erc20.cairo)
//!
//! # ERC20 Contract and Implementation
//!
//! This ERC20 contract includes both a library and a basic preset implementation.
//! The library is agnostic regarding how tokens are created; however,
//! the preset implementation sets the initial supply in the constructor.
//! A derived contract can use [_mint](_mint) to create a different supply mechanism.
#[starknet::contract]
mod ERC20 {
use integer::BoundedInt;
use starknet::ContractAddress;
use starknet::get_caller_address;

#[storage]
struct Storage {
ERC20_name: felt252,
ERC20_symbol: felt252,
ERC20_total_supply: u256,
ERC20_balances: LegacyMap<ContractAddress, u256>,
ERC20_allowances: LegacyMap<(ContractAddress, ContractAddress), u256>,
}

#[event]
#[derive(Drop, starknet::Event)]
enum Event {
Transfer: Transfer,
Approval: Approval,
}

/// Emitted when tokens are moved from address `from` to address `to`.
#[derive(Drop, starknet::Event)]
struct Transfer {
#[key]
from: ContractAddress,
#[key]
to: ContractAddress,
value: u256
}

/// Emitted when the allowance of a `spender` for an `owner` is set by a call
/// to [approve](approve). `value` is the new allowance.
#[derive(Drop, starknet::Event)]
struct Approval {
#[key]
owner: ContractAddress,
#[key]
spender: ContractAddress,
value: u256
}

mod Errors {
const APPROVE_FROM_ZERO: felt252 = 'ERC20: approve from 0';
const APPROVE_TO_ZERO: felt252 = 'ERC20: approve to 0';
const TRANSFER_FROM_ZERO: felt252 = 'ERC20: transfer from 0';
const TRANSFER_TO_ZERO: felt252 = 'ERC20: transfer to 0';
const BURN_FROM_ZERO: felt252 = 'ERC20: burn from 0';
const MINT_TO_ZERO: felt252 = 'ERC20: mint to 0';
}

/// Initializes the state of the ERC20 contract. This includes setting the
/// initial supply of tokens as well as the recipient of the initial supply.
#[constructor]
fn constructor(
ref self: ContractState,
name: felt252,
symbol: felt252,
initial_supply: u256,
recipient: ContractAddress
) {
self.initializer(name, symbol);
self._mint(recipient, initial_supply);
}

//
// External
//

#[external(v0)]
fn name(self: @ContractState) -> felt252 {
self.ERC20_name.read()
}

#[external(v0)]
/// Returns the ticker symbol of the token, usually a shorter version of the name.
fn symbol(self: @ContractState) -> felt252 {
self.ERC20_symbol.read()
}

#[external(v0)]
/// Returns the number of decimals used to get its user representation.
fn decimals(self: @ContractState) -> u8 {
18
}

#[external(v0)]
/// Returns the value of tokens in existence.
fn total_supply(self: @ContractState) -> u256 {
self.ERC20_total_supply.read()
}

#[external(v0)]
/// Returns the amount of tokens owned by `account`.
fn balance_of(self: @ContractState, account: ContractAddress) -> u256 {
self.ERC20_balances.read(account)
}

#[external(v0)]
/// Returns the remaining number of tokens that `spender` is
/// allowed to spend on behalf of `owner` through [transfer_from](transfer_from).
/// This is zero by default.
/// This value changes when [approve](approve) or [transfer_from](transfer_from)
/// are called.
fn allowance(
self: @ContractState, owner: ContractAddress, spender: ContractAddress
) -> u256 {
self.ERC20_allowances.read((owner, spender))
}

#[external(v0)]
/// Moves `amount` tokens from the caller's token balance to `to`.
/// Emits a [Transfer](Transfer) event.
fn transfer(ref self: ContractState, recipient: ContractAddress, amount: u256) -> bool {
let sender = get_caller_address();
self._transfer(sender, recipient, amount);
true
}

#[external(v0)]
/// Moves `amount` tokens from `from` to `to` using the allowance mechanism.
/// `amount` is then deducted from the caller's allowance.
/// Emits a [Transfer](Transfer) event.
fn transfer_from(
ref self: ContractState,
sender: ContractAddress,
recipient: ContractAddress,
amount: u256
) -> bool {
let caller = get_caller_address();
self._spend_allowance(sender, caller, amount);
self._transfer(sender, recipient, amount);
true
}

#[external(v0)]
/// Sets `amount` as the allowance of `spender` over the caller’s tokens.
fn approve(ref self: ContractState, spender: ContractAddress, amount: u256) -> bool {
let caller = get_caller_address();
self._approve(caller, spender, amount);
true
}

/// TEST: Mint function that allows anyone to mint test LORDS
#[external(v0)]
fn mint(ref self: ContractState, recipient: ContractAddress, amount: u256) {
self._mint(recipient, amount);
}

/// Camel case support.
/// See [total_supply](total-supply).
#[external(v0)]
fn totalSupply(self: @ContractState) -> u256 {
total_supply(self)
}

/// Camel case support.
/// See [balance_of](balance_of).
#[external(v0)]
fn balanceOf(self: @ContractState, account: ContractAddress) -> u256 {
balance_of(self, account)
}

/// Camel case support.
/// See [transfer_from](transfer_from).
#[external(v0)]
fn transferFrom(
ref self: ContractState,
sender: ContractAddress,
recipient: ContractAddress,
amount: u256
) -> bool {
transfer_from(ref self, sender, recipient, amount)
}

//
// Internal
//

#[generate_trait]
impl InternalImpl of InternalTrait {
/// Initializes the contract by setting the token name and symbol.
/// To prevent reinitialization, this should only be used inside of a contract's constructor.
fn initializer(ref self: ContractState, name: felt252, symbol: felt252) {
self.ERC20_name.write(name);
self.ERC20_symbol.write(symbol);
}

/// Internal method that moves an `amount` of tokens from `from` to `to`.
/// Emits a [Transfer](Transfer) event.
fn _transfer(
ref self: ContractState,
sender: ContractAddress,
recipient: ContractAddress,
amount: u256
) {
assert(!sender.is_zero(), Errors::TRANSFER_FROM_ZERO);
assert(!recipient.is_zero(), Errors::TRANSFER_TO_ZERO);
self.ERC20_balances.write(sender, self.ERC20_balances.read(sender) - amount);
self.ERC20_balances.write(recipient, self.ERC20_balances.read(recipient) + amount);
self.emit(Transfer { from: sender, to: recipient, value: amount });
}

/// Internal method that sets `amount` as the allowance of `spender` over the
/// `owner`s tokens.
/// Emits an [Approval](Approval) event.
fn _approve(
ref self: ContractState, owner: ContractAddress, spender: ContractAddress, amount: u256
) {
assert(!owner.is_zero(), Errors::APPROVE_FROM_ZERO);
assert(!spender.is_zero(), Errors::APPROVE_TO_ZERO);
self.ERC20_allowances.write((owner, spender), amount);
self.emit(Approval { owner, spender, value: amount });
}

/// Creates a `value` amount of tokens and assigns them to `account`.
/// Emits a [Transfer](Transfer) event with `from` set to the zero address.
fn _mint(ref self: ContractState, recipient: ContractAddress, amount: u256) {
assert(!recipient.is_zero(), Errors::MINT_TO_ZERO);
self.ERC20_total_supply.write(self.ERC20_total_supply.read() + amount);
self.ERC20_balances.write(recipient, self.ERC20_balances.read(recipient) + amount);
self.emit(Transfer { from: Zeroable::zero(), to: recipient, value: amount });
}

/// Destroys a `value` amount of tokens from `account`.
/// Emits a [Transfer](Transfer) event with `to` set to the zero address.
fn _burn(ref self: ContractState, account: ContractAddress, amount: u256) {
assert(!account.is_zero(), Errors::BURN_FROM_ZERO);
self.ERC20_total_supply.write(self.ERC20_total_supply.read() - amount);
self.ERC20_balances.write(account, self.ERC20_balances.read(account) - amount);
self.emit(Transfer { from: account, to: Zeroable::zero(), value: amount });
}

/// Internal method for the external [increase_allowance](increase_allowance).
/// Emits an [Approval](Approval) event indicating the updated allowance.
fn _increase_allowance(
ref self: ContractState, spender: ContractAddress, added_value: u256
) -> bool {
let caller = get_caller_address();
self
._approve(
caller, spender, self.ERC20_allowances.read((caller, spender)) + added_value
);
true
}

/// Internal method for the external [decrease_allowance](decrease_allowance).
/// Emits an [Approval](Approval) event indicating the updated allowance.
fn _decrease_allowance(
ref self: ContractState, spender: ContractAddress, subtracted_value: u256
) -> bool {
let caller = get_caller_address();
self
._approve(
caller,
spender,
self.ERC20_allowances.read((caller, spender)) - subtracted_value
);
true
}

/// Updates `owner`s allowance for `spender` based on spent `amount`.
/// Does not update the allowance value in case of infinite allowance.
/// Possibly emits an [Approval](Approval) event.
fn _spend_allowance(
ref self: ContractState, owner: ContractAddress, spender: ContractAddress, amount: u256
) {
let current_allowance = self.ERC20_allowances.read((owner, spender));
if current_allowance != BoundedInt::max() {
self._approve(owner, spender, current_allowance - amount);
}
}
}
}
Binary file added ui/public/coin-sprites.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ui/public/scenes/intro/arcade-account.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 0 additions & 5 deletions ui/src/app/SpriteAnimation.css

This file was deleted.

Loading

1 comment on commit e9503e0

@vercel
Copy link

@vercel vercel bot commented on e9503e0 Oct 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.