Structured, dependable legos for Starknet development.

Overview

cairomate • Tests Lints GitHub GitHub package.json version

Structured, dependable legos for starknet development.

Directory Structure

contracts
├─ defi
│  ├─ ChainlinkPriceOracle"Simple price oracle using Chainlink's V3 Aggregator"
│  └─ StakingRewards"Flexible, stripped staking rewards measured by blocks"
├─ interfaces
│  ├─ IAccount"Account Interface"
│  ├─ IAggregatorV3"Chainlink V3 Aggregator Interface"
│  ├─ IERC20"ERC20 Contract Interface"
│  ├─ IERC165"ERC165 Contract Interface"
│  ├─ IERC721"ERC721 Contract Interface"
|  ├─ INERC721"N-ERC721 Contract Interface (felt-based ERC721)"
│  └─ IERC1155"ERC1155 Contract Interface"
├─ tokens
│  ├─ ERC20"Modern and gas efficient ERC20 + EIP-2612 implementation"
│  ├─ ERC721
│  │  ├─ ERC721 - "Modern and gas efficient ERC721 | Uint256-based + EIP-2612 implementation"
│  │  └─ N-ERC721 - "Modern and gas efficient ERC721 | felt-based + EIP-2612 implementation"
│  └─ ERC1155"Modern and gas efficient ERC1155 + EIP-165 implementation"
├─ utils
│  ├─ Account"Stripped account"
│  ├─ Ownable"Minimal, ownable contract instance"
│  ├─ Context"Port of OZ's Solidity Context Abstraction"
│  └─ Pausible"Pausible Solidity Functionality"
tests
├─ test_StakingRewards — "Flexible, stripped staking rewards measured by blocks"
├─ test_ERC20 - "Test ERC20 contract"
├─ test_ERC721 - "Test ERC721 contract"
└─ test_Ownable - "Test Ownable contract"

Installation

First time?

Further installation instructions provided in the cairo-lang docs

Before installing Cairo on your machine, you need to install gmp:

sudo apt install -y libgmp3-dev # linux
brew install gmp # mac

If you have any troubles installing gmp on your Apple M1 computer, here’s a list of potential solutions.

For VSCode support:

Download cairo-0.6.2.vsix from https://github.com/starkware-libs/cairo-lang/releases/tag/v0.6.2

And run:

code --install-extension cairo-0.6.2.vsix

Set up the project

Clone the repository

git clone [email protected]:abigger87/cairomate.git

cd into it and create a Python virtual environment:

cd cairomate
python3 -m venv env
source env/bin/activate

Install the Nile dev environment and then run install to get the Cairo language, a local network, and a testing framework.

pip3 install cairo-nile
nile install

Usage

Compile the contracts

nile compile

Run tests

pytest

Running a specific test file (eg tests/test_ERC20.py):

pytest tests/test_ERC20.py

Test a specific test case:

pytest tests/test_ERC20.py -k 'test_mint'

Extending Cairo contracts

There's no clear contract extensibility pattern for Cairo smart contracts yet. In the meantime the best way to extend our contracts is copypasting and modifying them at your own risk. Remember this contracts are still under development and they have not gone through any audit or security review whatsoever.

Acknowledgements

Big thanks to:

Security

This project is still in a very early and experimental phase. It has never been audited nor thoroughly reviewed for security vulnerabilities. Do not use in production.

Please report any security issues you find by opening up an issue in this reposisitory.

License

Cairomate Contracts are released under the AGPL-3.0-only.

Comments
  • token_uri feature added to ERC721

    token_uri feature added to ERC721

    This PR adds support for basic token_uri support and slight changes to events naming (first letter is upper case now) in order to follow as closely as possible the standard on Ethereum (bonus : transfer event was conflicting with the function).

    Quick overview :

    • Two new structs
    struct baseURI:
        member prefix : felt
        member suffix : felt
    end
    
    struct tokenURI:
        member prefix : felt
        member suffix : felt
        member token_id : felt
    end
    

    baseURI has two fields, allowing a 62 bytes long string, to accomodate for IPFS (cid is 46 bytes long). It is set once in the constructor, possibility to change it later is left to the user.

    tokenURI is only returned in the token_uri-token_id) function. Potential to eventually swap the prefix and suffix fields for a baseURI struct.

    • New storage var
    @storage_var
    func _base_uri() -> (base_uri: baseURI):
    end
    
    • New view function
    @view
    func token_uri{
        syscall_ptr: felt*,
        pedersen_ptr: HashBuiltin*,
        range_check_ptr
    }(token_id: felt) -> (token_uri: tokenURI):
        let (base_uri : baseURI) = _base_uri.read()
        let token_uri = tokenURI(base_uri.prefix, base_uri.suffix, token_id)
        return (token_uri)
    end
    
    opened by exp-table 0
  • :building_construction: erc20 events :tada:

    :building_construction: erc20 events :tada:

    Events Added

    • [x] /contracts/tokens/ERC721/ERC721.cairo
    • [x] /contracts/tokens/ERC721/N-ERC721.cairo
    • [x] /contracts/tokens/ERC20.cairo

    :x: /contracts/tokens/ERC1155.cairo (TODO in ERC-1155 PR)

    Events Tested ...

    enhancement 
    opened by refcell 0
  • ERC721.cairo test suite - incomplete

    ERC721.cairo test suite - incomplete

    An incomplete serie of tests for ERC721.cairo, because it misses tokenURI tests and all safe features.

    Also small fix of uint, the upper bits were set while it should have been the lower bits.

    bug enhancement tests 
    opened by exp-table 0
  • ERC721: coherent token_id type

    ERC721: coherent token_id type

    I made the necessary adjustements to not only enforce the Uint256 type for token_id, but to also remove and replace amount occurences, since it refers to ERC20 quantities.

    enhancement 
    opened by exp-table 0
  • :recycle: EIP 2612 :package:

    :recycle: EIP 2612 :package:

    Implement EIP-2612

    Implement the EIP-2612 as per the specifications.

    Starter

    #############################################
    ##             EIP 2612 STORE              ##
    #############################################
    
    ## TODO: EIP-2612
    
    # bytes32 public constant PERMIT_TYPEHASH =
    #     keccak256("Permit(address spender,uint256 token_id,uint256 nonce,uint256 deadline)");
    # bytes32 public constant PERMIT_ALL_TYPEHASH =
    #     keccak256("Permit(address owner,address spender,uint256 nonce,uint256 deadline)");
    # uint256 internal immutable INITIAL_CHAIN_ID;
    # bytes32 internal immutable INITIAL_DOMAIN_SEPARATOR;
    # mapping(uint256 => uint256) public nonces;
    # mapping(address => uint256) public noncesForAll;
    
    
    enhancement help wanted eip-support 
    opened by refcell 0
  • Add safeTransferFrom to ERC721

    Add safeTransferFrom to ERC721

    We assume readers will know the difference of how accounts are handled between Ethereum and Starknet (non-smart contracts vs smart-contracts).

    Since we cannot rely on examining the bytecode of the recipient to determine if it's an Account or another type of contract, one way to differentiate them, in order to determine how the safe transfer and mint have to behave, is to try to call the get_public_key of the assumed Account, and then if it holds a non-zero felt, it means it's OK, otherwise we call onERC721Received.

    Except it's not possible. If the target recipient doesn't implement get_public_key (because it's not an Account but it handles ERC721s), the whole transaction will be reverted naturally.

    opened by exp-table 0
Owner
andreas
andreas
A StarkNet project template based on a Pythonic environment

StarkNet Project Template This is an opinionated StarkNet project template. It is based around the Python's ecosystem and best practices. tox to manag

Francesco Ceccon 5 Apr 21, 2022
A minimalist starknet amm adapted from StarkWare's amm.

viscus • A minimalist starknet amm adapted from StarkWare's amm. Directory Structure contracts

Alucard 4 Dec 27, 2021
Cairo-math-64x61 - Fixed point 64.61 math library for Cairo / Starknet

Cairo Math 64x61 A fixed point 64.61 math library for Cairo & Starknet Signed 64

Influence 63 Dec 5, 2022
A command line interface tool converting starknet warp transpiled outputs into readable cairo contracts.

warp-to-cairo warp-to-cairo is a simple tool converting starknet warp outputs (NethermindEth/warp) outputs into readable cairo contracts. The warp out

Michael K 5 Jun 10, 2022
Tutorials for on-ramping to StarkNet

Full-Stack StarkNet Repo containing the code for a short tutorial series I wrote while diving into StarkNet and learning Cairo. Aims to onramp existin

Sam Barnes 71 Dec 7, 2022
SEH-Helper - Binary Ninja plugin for exploring Structured Exception Handlers

SEH Helper Author: EliseZeroTwo A Binary Ninja helper for exploring structured e

Elise 74 Dec 26, 2022
A lightweight solution for local Particle development.

neopo A lightweight solution for local Particle development. Features Builds Particle projects locally without any overhead. Compatible with Particle

Nathan Robinson 19 Jan 1, 2023
NES development tool made with Python and Lua

NES Builder NES development and romhacking tool made with Python and Lua Current Stage: Alpha Features Open source "Build" project, which exports vari

null 10 Aug 19, 2022
Shell Trality API for local development.

Trality Simulator Intro This package is a work in progress. It allows local development of Trality bots in an IDE such as VS Code. The package provide

CrypTrality 1 Nov 17, 2021
Step by step development of a vending coffee machine project, including tkinter, sqlite3, simulation, etc.

Step by step development of a vending coffee machine project, including tkinter, sqlite3, simulation, etc.

Nikolaos Avouris 2 Dec 5, 2021
This an Anki add on that automatically converts Notion notes into Anki flash cards. Currently in development!

NotionFlash This is an Anki add on in development that will allow automatically convert your Notion study notes into Anki flash cards. The Anki deck c

Neeraj Patel 10 Oct 7, 2022
Tracking development of the Class Schedule Siri Shortcut, an iOS program that checks the type of school day and tells you class scheduling.

Class Schedule Shortcut Tracking development of the Class Schedule Siri Shortcut, an iOS program that checks the type of school day and tells you clas

null 3 Jun 28, 2022
Traditionally, there is considerable friction for developers when setting up development environments

This self-led, half-day training will teach participants the patterns and best practices for working with GitHub Codespaces

CSE Labs at Spark 12 Dec 2, 2022
World Happiness Report is a publication of the Sustainable Development Solutions Network

World-Happiness-Report We are going to visualise what are the factors and which

Shubh Almal 1 Jan 3, 2023
Research using python - Guide for development of research code (using Anaconda Python)

Guide for development of research code (using Anaconda Python) TL;DR: One time s

Ziv Yaniv 1 Feb 1, 2022
Gba-free-fonts - Free font resources for GBA game development

gba-free-fonts Free font resources for GBA game development This repo contains m

null 28 Dec 30, 2022
VRF-StarkNet - Contracts for verifiable randomness on StarkNet

VRF-StarkNet Contracts for verifiable randomness on StarkNet Motivation Deployed

Non 32 Oct 30, 2022
Lightwood is Legos for Machine Learning.

Lightwood is like Legos for Machine Learning. A Pytorch based framework that breaks down machine learning problems into smaller blocks that can be glu

MindsDB Inc 312 Jan 8, 2023
Dante, my discord bot. Open source project in development and not optimized for other filesystems, install and setup script in development

DanteMode (In private development for ~6 months) Dante, my discord bot. Open source project in development and not optimized for other filesystems, in

null 2 Nov 5, 2021