GithubHelp home page GithubHelp logo

carbonable / carbon-protocol Goto Github PK

View Code? Open in Web Editor NEW
46.0 2.0 18.0 53.21 MB

Carbon Starknet Protocol written in Cairo.

License: Apache License 2.0

Cairo 97.66% Shell 2.34%
cairo carbon-offsetting starknet

carbon-protocol's People

Contributors

abdelstark avatar adrien-vieilleribiere avatar bal7hazar avatar cloudvenger avatar marchand-nicolas avatar martiangreed avatar rmzlb avatar tekkac avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

carbon-protocol's Issues

fix protostar version

Description

We do not want protostar releases to impact our CI (and our tests).

Suggested Evolution

We need to specify a fixed version of protostar to counter the current behavior of the install.sh script which installs the latest release.

Acceptance Criteria

  • When I set an oldest protostar version localy, it installs the spcified version (returned by protostar --version)

Additional context

A feature is provided by protostar in their install.sh script (source)

[Offseter] Define and Design the Carbonable Offseting Certificate

Description

Define and Design the Carbonable Offseting Certificate.

Questions

  • Which kind of Token ? (ERC-721, ERC-1155, ERC-3525, etc...)
  • How is digitalized the offset certificate of the certifier ?
  • Which data need to be on-chain ? off-chain ?
  • Where do we store the documents / information ? (IPFS, other ?)

Acceptance Criteria

  • All the questions need to be answer
  • An exhaustive list of metadata must be provided (on-chain AND off-chain)
  • The UI of the Carbonable certificate need to be done on Figma

handle whitelist with a Merkle tree

  • add a function in the smart contract to set the merkle root, callable only by owner
  • remove mapping storage
  • split the buy function in 2 functions, one for the public buy and one for the whitelisted buy. The reason is that they will take different arguments, the whitelisted buy needs the merkle proof
  • handle the verification of the merkle proof (see also cairo-merkle-distributor)

Requirements: benchmark data storage costs from other projects to evaluate the opportuniy

Note: If we decide to keep living with the current situation, we may need to add a remove_from_whitelist option to keep data as clean as possible and avoid sybil.

Opportunity: By default the storage var of the merkle root will be 0 until an update of the root, we could use this behavior to trigger the fact that the pre-sale is open.

[Yielder] Implement the retrieve function of NFTs from a Farming Project Pool during the unlock period

Description

Implement the retrieve of NFTs from a Farming Project Pool during the unlock period

Rules

  • Rule: A Carbonable NFT can be retrieved only from a Yield farming OR an Offset farming pool per period
  • Rule: The granularity in the Yielder is 1 Carbonable NFT

Acceptance Criteria

  • Implement the Rules
  • Implement unit tests for each functions
  • Implement integration tests for each functions
  • If needed, write the documentation associated with the functions and events exposed

Additional context

excalidraw - Farming schema

Smart Contract - Pausable feature

Description

Pausable feature can be useful to freeze a contract under attack for instance.

Acceptance Criteria

  • Relevant contracts can be pausablle

[Offseter] Implement the deposit of NFTs in a Farming Project Pool

Description

Implement the deposit of NFTs, received after funding a Project, in a Farming Project Pool.

Deposit one NFT by one NFT.

Rules

  • Rule: A Carbonable NFT can be deposit only in a Yield farming OR an Offset farming pool per period
  • Rule: The granularity in the Offseter is 1 Carbonable NFT

Acceptance Criteria

  • Implement the Rules
  • Implement unit tests for each functions
  • Implement integration tests for each functions
  • If needed, write the documentation associated with the functions and events exposed

Additional context

excalidraw - Farming schema

merkle root setter

  • add a function in the smart contract to set the merkle root, callable only by owner

DevOps - Add Github Project Setup

Description

To ensure consistency between Github repos of Carbonable, a common Github process and setup must be created.
This PR add configuration files of Issues Template and specifics Labels for the Issues

Acceptance Criteria

  • List of Issues Template when creating a new Issues.
  • List of Labels in Issues tab corresponding to teh labels in carbonable_labels.json

[Yielder] Implement the deposit function of NFTs in a Farming Project Pool

Description

Implement the deposit of NFTs, received after funding a Project, in a Farming Project Pool.

Rules

  • Rule: A Carbonable NFT can be deposit only in a Yield farming OR an Offset farming pool per period
  • Rule: The granularity in the Yielder is 1 Carbonable NFT

Acceptance Criteria

  • Implement the Rules
  • Implement unit tests for each functions
  • Implement integration tests for each functions
  • If needed, write the documentation associated with the functions and events exposed

Additional context

excalidraw - Farming schema

reserved supply update

To handle the case where some reserved spots won't be minted due to unexpected events (such as B2B withdrawal).

As an admin, we want the ability to move some slots from reserved supply into public supply.

To proceed, we need to be able to decrease the reserved supply (only decrease).

Three scenarios:

1. ๐ŸŽ‰

set_reserved_supply_for_mint(reserved_supply_for_mint : felt)

Which fails if the new reserved_supply_for_mint is ge to the stored one

Note: less explicit name, easier to use since math are done by the contract

2. โค๏ธ

decrease_reserved_supply_for_mint(slots : felt)

Which fails if slots is gt than the stored one

Note: more explicit name, admin needs to ensure math before the usage

3. ๐Ÿš€

set_decreased_reserved_supply_for_mint(reserved_supply_for_mint : felt)

Which fails if the new reserved_supply_for_mint is ge to the stored one

Note: name too long?

whitelist slots per user

With the current state, there is not way for the contract to know if the user has already minted his whitelisted slots or not, allowing the user to mint his slots as much as he wants.

To fix this situation we need a storage variable storing how many slots a user has already minted.
This information is then compared during the whitelist buy to ensure user to not mint more than his whitelisted slots.

Note: with this fix, the gas used to store values are spread by user (which is different from the initial situation where the contract has to setup the whole map before the whitelist sale)

Sustainable minter contract

With the current situation, and because NFT project is defined in the constructor of the Minter contract, we have to deploy a new minter contract for each NFT projects.

Allowing to change the nft contract address in the Minter contract will make it reusable for each new projects.

Note: If we decide to implement it, we have to be very careful to reset the merkle root (set to 0, as the initial state of the storage var) to "reset" the whitelist. This reset must be called each time a new NFT project address is set to reduce the risk.

EDIT:

This behavior could also be conflictual with the fact than the token owners can burn their token using the native burn ERC-721 function.

Doing a burn will result in decrease the total_supply and then allow the minter contract to mint a brand new token.

However, this ability will be available only until the minter contract is linked to the NFT contract if we implement this feature.

IERC20 transferFrom call

I don't understand why the following code is actually working:

Here is the IERC20 contract from openzepplin depencency:

@external
func transferFrom{
        syscall_ptr : felt*,
        pedersen_ptr : HashBuiltin*,
        range_check_ptr
    }(
        sender: felt,
        recipient: felt,
        amount: Uint256
    ) -> (success: felt):
    ERC20.transfer_from(sender, recipient, amount)
    return (TRUE)

And here is a call of the transferFrom function from here in the mint contract regarding the payment during the buy function.

# Do ERC20 transfer
let (transfer_success) = IERC20.transferFrom(
    payment_token_address, caller, contract_address, amount
)

So basically there are 4 arguments provided where IERC20 expects 3, but actually tests works so I'm probably misunderstanding something.

[Offseter] Implement a function : Which percentage (%) of Carbon Credit of a Project I have for my address ?

Description

Implement a function which:
Give the percentage (%) of Carbon Credit of a Project, for a given address, is entitled to receive for the current period.

This function calculates the number of NFTs deposited by the address and returns the amount of Carbon Credit it will receive for this period for this Project.

Acceptance Criteria

  • Implement the function
  • Implement unit tests for each functions
  • Implement integration tests for each functions
  • If needed, write the documentation associated with the functions and events exposed

Additional context

excalidraw - Farming schema

deploy script got incrorrect inputs

Whitelist sale open argument is not more required during the deployement of the minter contract.

Deploy script must be adapted accordingly.

payment token management

In the current version, payment token is provided to the constructor and cannot be modified later (the only way is to deploy a new contract).

To ensure the contract to not be impacted by any external news regarding which payment token we choose, we could add a setter to let the owner chose to change the payment token at any time.

Note sure if there is any political reason to not do this.

DevOps - Merkle tree tooling

  • implement script to generate the merkle tree and the root from a JSON whitelist (each leaf is the concatenation of the address and the number of whitelisted slots)
  • implement CLI tool to add whitelist entries in a JSON file
  • implement a library to generate the merkle proof from: address, number of slots and merkle tree

Technology:

  • JS as much as possible to be usable by the front, here a sample allowing to manage the hashing method (which must match the cairo way to verify prooves).
  • Python else

Test refactoring

Proposition

The propopsition is mainly motivated by the growth of new features and SOC.
Since we are adding more and more contracts and features, it could be interesting to refactor tests.

Integration tests

Integration tests focus on nominal usages by default, this is what aim the test_nominal_cases files of each contract.

We also want to test specific behaviors by chaining actions between contracts, this will be the purpose of the test_specific_cases file of each contract.

Notes:

  • I think protostar generate a single instance of what the __setup__ returns for each test files which could slow down tests and increase memory usage
  • we need to check how to factorize the __setup__ cheatcode

Unit tests

Unit tests focus on the nominal cases and expect revert tests, since several tests are required per new functionnality (according to the number of exception raised by the function), there is an opportunity to spread tests per functionnality.

Note: A new library.cairo file could store shared code (as the one in the integration tests).

Folder structure diagram

tests/
โ”œโ”€โ”€ integrations/
โ”‚   โ”œโ”€โ”€ library.cairo
โ”‚   โ”œโ”€โ”€ minter/
โ”‚   โ”‚   โ””โ”€โ”€ test_nominal_cases.cairo
โ”‚   โ”‚   โ””โ”€โ”€ test_specific_cases.cairo
โ”‚   โ”œโ”€โ”€ yielder/
โ”‚   โ”‚   โ””โ”€โ”€ test_nominal_cases.cairo
โ”‚   โ”‚   โ””โ”€โ”€ test_specific_cases.cairo
โ”‚   โ”œโ”€โ”€ .../
โ”œโ”€โ”€ mocks/
โ”‚   โ””โ”€โ”€ erc20.cairo
โ”œโ”€โ”€ units/
โ”‚   โ”œโ”€โ”€ library.cairo
โ”‚   โ”œโ”€โ”€ minter/
โ”‚   โ”‚   โ”œโ”€โ”€ test_decrease_reserved_supply_for_mint.cairo
โ”‚   โ”‚   โ”œโ”€โ”€ test_...
โ”‚   โ”‚   โ”œโ”€โ”€ test_airdrop.cairo
โ”‚   โ”‚   โ”œโ”€โ”€ test_whitelist_buy.cairo
โ”‚   โ”‚   โ””โ”€โ”€ test_public_buy.cairo
โ”‚   โ”œโ”€โ”€ yielder/
โ”‚   โ”‚   โ””โ”€โ”€ test_...

integrations tests

  • Create integration tests (benchmark from starkvest) for the mechanism and reproduce the same scenarios that unit tests.

[Farmer] Implement Locking and Unlocking Period system

Description

Implement Locking and Unlocking Period for Farming Project Pool.

Rules

  • Rule: When a Farming pool period start, Users can NOT retrieve their Carbonable NFT until they are unlock by the Yield farming pool
  • Rule: before the end of the current period, User can claimed their Carbonable NFT
  • Rule: If User does NOT claim their Carbonable NFT of the current period, the same configuration will be apply for the next period for this Farming Project Pool

Acceptance Criteria

  • Implement the Rules
  • Implement unit tests for each functions
  • Implement integration tests for each functions
  • If needed, write the documentation associated with the functions and events exposed

Additional context

Add any other context or screenshots about the feature request here.

airdrop feature

  • add a number of reserved slot for aidrop (manage another storage var to handle this reserved slots number, don't forget to take it into account while buying)
  • add airdrop function, callable only by owner, with parameters: quantity, recipient. Something like:
func airdrop{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}(
    to : felt, quantity : felt
) -> (success : felt):
    ...
    something similar to buy function wihtout ERC20 transfers
    ...
    call mint_n
    ...
    transfer from owner to to
    ...
end

withdraw

  • add missing withdraw function
  • add corresponding unit test and add a step in the e2e test

[Offseter] Implement a function, for an address, to trigger the Offseting of his Carbon Credit

Description

Implement a function, for an address, to trigger the Offseting of his Carbon Credit.

Questions

  • The address need to Offset for each of his project ?
  • Can we trigger the Offseting for all the Projects in the same time ?

Acceptance Criteria

  • Implement unit tests for each functions
  • Implement integration tests for each functions
  • If needed, write the documentation associated with the functions and events exposed

Additional context

excalidraw - Farming schema

[Offseter] Implement the retrieve function of NFTs from a Farming Project Pool during the unlock period

Description

Implement the retrieve of NFTs from a Farming Project Pool during the unlock period

Rules

  • Rule: A Carbonable NFT can be retrieved only from a Yield farming OR an Offset farming pool per period
  • Rule: The granularity in the Yielder is 1 Carbonable NFT

Acceptance Criteria

  • Implement the Rules
  • Implement unit tests for each functions
  • Implement integration tests for each functions
  • If needed, write the documentation associated with the functions and events exposed

Additional context

excalidraw - Farming schema

Smart Contract - Add metadata to erc721 collection

Since the future stacking contract will probably need information about NFT metadata, we will need to have these information on chain and linked to the ERC-721 collection.

Proposition:

A struct that handle attributes

struct Metadata:
    member image_url : felt*
    member external_url : felt
    member description : felt*
    member name : felt*
    member holder : felt*
    member certifier : felt*
    member country : felt*
    member expiration : felt
    member background_color: felt
    member animation_url: felt*
    member background_color: felt*
    member youtube_url: felt*
end

A variable storage to store the metadata

@storage_var
func metadata() -> (res : Metadata):
end

A view for each attribute

@view
func image_url() -> (res : felt*):
end

@view
func external_url() -> (res : felt):
end

All attributes set once in the constructor.

Note: source to existing metadata (Juno contracts)

EDIT - Benchmark about long string management in cairo

DevOps - Add metadata settings in deploy script

According to the #45 PR, we will need to set up all metadata settings into the carbonable project before the ownership transfer.

Inputs could be set in the deploy config file to be updated easily.

EDIT : add an option to avoid to transfer the ownership from admin to minter, such as --no-transfer

Improve deploy script to manage owners

In the current situation all deployed contracts are owned by the admin address, therefore we have to manually transfer the ownership of the nft contract from admin to minter contract.

Using starknet invoke we should be able to handle thise automatically after deployments.

Upgrade to latest protostar version

Description

A new version of protostar has been released, we must upgrade it.

What code could be improved?

Github workflows mainly

Acceptance Criteria

  • CI test keeps working

[Yielder] Implement a function : Which percentage (%) of share of a Project I have for my address ?

Description

Implement a function which:
Give the percentage (%) of share of a Project, for a given address, is entitled to receive for the current period.

This function calculates the number of NFTs deposited by the address and returns the amount of share it will receive for this period for this Project.

Acceptance Criteria

  • Implement the function
  • Implement unit tests for each functions
  • Implement integration tests for each functions
  • If needed, write the documentation associated with the functions and events exposed

Additional context

excalidraw - Farming schema

Smart Contract - Implement badge contracts

Description

To reward community, we want to propose on chain status such a badges.

We are going to use ERC-1155 to support badges.

Acceptance Criteria

  • As a user I can receive/mint (TBD) as badge for a duty.

Additional context

Smart Contract - Refactoring code and dependancies upgrade

Description

With the new Cairo 0.10.0 we have to update our smart contract code to keep up-to-date.

Because we will have to go through all the code, it could be a good opportunity to refactor additionnal code according to latest guidelines.

Upgrade the following deps:

Few ideas:

  • Move protostar version from secrets to job env (to avoid to have failing CIs in PRs)
  • Add unit_256 checks for all Uint256 inputs (see function in OZ ERC-1155)
  • Re-entrancy security improvment (guard feature when interfaces are used in contracts)
  • Check-Effect-Interaction compliance when transfer ERC-20 tokens
  • Constructor to Initializer for libraries
  • _iter suffix for loops
  • Move owner assertions from library to contracts

What code could be improved?

All cairo files and python files (Cairo 0.10.0 also change python version from 3.7 to 3.9)

Acceptance Criteria

  • Tests on refactored code succeed
  • Deployements on refactored code succeed

Additional context

OZ released a new version of their contracts according to the new cairo version.
A new version of protostar has been released supporting cairo version.

We need a new release of Cairopen before the migration.

Add contract URI

Description

Market places need contractURI view to display collection metadata

Acceptance Criteria

  • Collection images (banner and image) are displayed correctly on marketplaces

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.