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

Low Code Carbon Credit Implementation #22

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ yarn-error.log*
target
dist
gallery/public
.eslintcache
.eslintcache

*.tsbuildinfo
2 changes: 1 addition & 1 deletion deps/concordium-rust-sdk
Submodule concordium-rust-sdk updated 79 files
+2 −2 .github/workflows/build-and-test.yaml
+0 −41 CHANGELOG.md
+11 −12 Cargo.toml
+9 −9 README.md
+1 −1 concordium-base
+105 −68 examples/block-stats.rs
+1 −1 examples/create-initial-accounts.rs
+54 −20 examples/find-account.rs
+126 −0 examples/generator.rs
+2 −3 examples/init-update-contract.rs
+5 −2 examples/list-number-account-transactions.rs
+33 −79 examples/protocol-updates.rs
+1 −1 examples/v2_banpeers.rs
+6 −6 examples/v2_contract_deploy_init_update.rs
+2 −2 examples/v2_create_initial_accounts.rs
+1 −1 examples/v2_get_account_info.rs
+1 −1 examples/v2_get_account_list.rs
+3 −2 examples/v2_get_account_non_finalized_transactions.rs
+1 −1 examples/v2_get_ancestors.rs
+1 −1 examples/v2_get_anonymity_revokers.rs
+1 −1 examples/v2_get_baker_list.rs
+1 −1 examples/v2_get_block_chain_parameters.rs
+1 −1 examples/v2_get_block_finalization_summary.rs
+11 −6 examples/v2_get_block_info.rs
+1 −1 examples/v2_get_block_item_status.rs
+1 −1 examples/v2_get_block_items.rs
+1 −1 examples/v2_get_block_special_events.rs
+1 −1 examples/v2_get_blocks_at_height.rs
+1 −1 examples/v2_get_branches.rs
+1 −1 examples/v2_get_consensus_info.rs
+1 −1 examples/v2_get_cryptographic_parameters.rs
+1 −1 examples/v2_get_election_info.rs
+1 −1 examples/v2_get_finalized_blocks.rs
+1 −1 examples/v2_get_identity_providers.rs
+1 −1 examples/v2_get_instance_info.rs
+1 −1 examples/v2_get_instance_list.rs
+1 −1 examples/v2_get_instance_state.rs
+1 −1 examples/v2_get_instances_stats.rs
+1 −1 examples/v2_get_module_list.rs
+1 −1 examples/v2_get_module_source.rs
+1 −1 examples/v2_get_next_account_sequence_number.rs
+1 −1 examples/v2_get_next_update_sequence_numbers.rs
+1 −1 examples/v2_get_node_info.rs
+1 −1 examples/v2_get_passive_delegation_info.rs
+1 −1 examples/v2_get_passive_delegators.rs
+1 −1 examples/v2_get_passive_delegators_reward_period.rs
+1 −1 examples/v2_get_peers_info.rs
+1 −1 examples/v2_get_pool_delegators.rs
+1 −1 examples/v2_get_pool_delegators_reward_period.rs
+1 −1 examples/v2_get_pool_info.rs
+1 −1 examples/v2_get_tokenomics_info.rs
+1 −1 examples/v2_instance_state_lookup.rs
+1 −1 examples/v2_invoke_instance.rs
+1 −1 examples/v2_list_cis2_contracts.rs
+1 −1 examples/v2_list_instances.rs
+1 −1 examples/v2_networkdumps.rs
+1 −1 examples/v2_peer_connect.rs
+1 −1 examples/v2_register_data.rs
+1 −1 examples/v2_send_encrypted_transfer.rs
+1 −1 examples/v2_send_transfer.rs
+1 −1 examples/v2_shutdown.rs
+1 −1 examples/v2_traverse_all_transactions.rs
+1 −2 examples/v2_update_exchange_rate.rs
+0 −14 src/cis0.rs
+238 −62 src/cis2/mod.rs
+0 −281 src/cis4.rs
+0 −249 src/contract_client.rs
+2 −7 src/internal.rs
+12 −11 src/lib.rs
+0 −1 src/postgres.rs
+15 −76 src/types/mod.rs
+18 −80 src/types/queries.rs
+1 −11 src/types/smart_contracts.rs
+0 −47 src/v1/generated/concordium.rs
+84 −290 src/v2/conversions.rs
+30 −687 src/v2/generated/concordium.v2.rs
+21 −295 src/v2/mod.rs
+1 −1 src/v2/proto_schema_version.rs
+0 −162 src/web3id.rs
133 changes: 133 additions & 0 deletions low-code-carbon-credits-marketplace/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# Concordium Carbon Credits Sample Implementation

## Project structure

1. [Smart Contracts](./contracts/README.md)
1. `project_token` : CIS2 Token contract implementation for Carbon Credits Projects.
2. `carbon_credits` : CIS2 Token contract implementation for Carbon Credits.
3. `carbon_credits_market` : Reference marketplace implementation for Carbon Projects & Carbon Credits.
2. [Events Listener / Indexer](./indexer/server/src/listener.ts) : a node js application which listens to events from the concordium node and stores them in a mongodb database.
3. [Web Backend](./indexer/server/src/web.ts) : a node js application which provides REST APIs to query the data stored in the mongodb database.
4. [Web Frontend](./market-ui/src/App.tsx) : a react application which provides a UI to interact with the smart contracts and utilizes the apis provided by the web backend.

## Process

### User Roles

#### Admin

Represents the governance of the system. The role is responsible for setting up the system and adding verifiers to the system.

#### Project Owner

Represents the owner of the Carbon Credit Project. Can mint / retract a carbon credit project or can fractionalize a carbon credit project into carbon credit tokens.

#### Verifier

Responsible for verification of a carbon credit project. Only Verified & Mature projects can be retired.

#### Buyer

Any Account which wants to buy a Carbon Credit / Carbon Credit Token from the marketplace contract.

### Process Flow

1. *Admin* sets up the system by deploying the smart contracts and adding verifiers to the system.
2. **Project Tokens**
1. *Project Owner* can use the web frontend to create a carbon credit project. Which basically mints a project token in the `project_token` contract and assigns it to the project owner.
1. Project Owner needs to specify the maturity date of the project. The project is considered *mature* after the maturity date.
2. As the project is created it is assigned a unique project id which is used to identify the project in the system. This id is shown on the ui right after minting the project.
3. As the project is minted its open for verification by any verifiers which have been added by admin.
2. *Verifier* can use the web frontend to verify a carbon credit project. Which basically marks the project token as verified in the `project_token` contract.
3. Any unverified or immature project can be **retracted** by the project owner or the verifier.
4. Any verified & mature project can be **retired** by the project owner.
5. Project Owner can use the web frontend to send the token to marketplace contract to list it for sale.
6. Project Owner can use the web frontend to fractionalize the project into carbon credits.

3. **Carbon Credits**
If the project owner wants to fractionalize a carbon credit project into carbon credits he can do so by using the web frontend. Which basically sends the project token to the `carbon_credits` contract and mints carbon credit tokens in the `carbon_credits` contract. The project token is locked in the `carbon_credits` contract.

1. Only verified projects can be fractionalized.
2. Any immature carbon credit can be **retracted** by the project owner or the verifier.
3. Any mature carbon credit can be **retired** by the project owner.
4. **Marketplace**
Any token can be sent to the marketplace contract to list it for sale. The marketplace contract is responsible for managing the sale of the tokens. The marketplace contract has the following functionality.
1. `list` : Can be used to list a carbon project / credit on the marketplace for a price.
2. `transfer` : Can be called with a specified amount to transfer a carbon project / credit to the payer.

## Run

1. Prerequisites
1. Install [Yarn](https://yarnpkg.com/)
2. Install [Docker](https://docs.docker.com/get-docker/)
3. Install [Docker Compose](https://docs.docker.com/compose/install/)
4. Install [Node.js](https://nodejs.org/en/download/)
5. Install [Concordium Client](https://developer.concordium.software/#/concordium-client)
6. Install [cargo-concordium](https://developer.concordium.software/en/mainnet/smart-contracts/guides/setup-tools.html)

2. Build

```bash
yarn && yarn build
```

3. Deploy Smart Contracts

```bash
yarn deploy:contracts wallet-account
```

**wallet-account** is the name of the account setup in the Concordium Client.

4. Setup
1. Setting enviornment variables for
1. [Events Listener](indexer/server/.env) & [Web Backend](indexer/server/.env)
* `DB_CONN_STRING` : Connection string for the mongodb database. The default value already present in the file is for the [docker-compose](./indexer/docker-compose.yml) setup.
* `NODE_ENDPOINT` : Endpoint of concordium node.
* `NODE_PORT` : Port of concordium node.
* `STARTING_BLOCK_HASH` : Hash of the block at which the the indexer would start listening.
* `APP_PORT`: Port at which web backend would listen for requests.
* `BASE_ACCOUNT_ADDRESS`: Address of the account which will be used to create aliases in case users want to use email address instead of concordium account.
* `GOOGLE_CLIENT_ID`: Client ID of the google app which will be used for authentication.
* `MODULE_REF`: Module reference of the deployed smart contract. This can be found in the output of the deploy command.
* `MODULE_SCHEMA`: base64 encoded schema of the deployed smart contract. This can be found in the [file](./contracts/schema_base64.txt)
2. [Web Frontend](./market-ui/.env)
* `REACT_APP_DEFAULT_PROJECT_TOKEN_ADDRESS_INDEX` : default index of the `project_token` contract
* `REACT_APP_DEFAULT_CARBON_CREDIT_ADDRESS_INDEX` : default index of the `carbon_credit` contract.
* `REACT_APP_DEFAULT_MARKET_ADDRESS_INDEX` : default index of the `carbon_credit_market` contract.
* `REACT_APP_DEFAULT_MARKET_ADDRESS_SUBINDEX` : default subindex of the `carbon_credit_market` contract.
* `REACT_APP_DEFAULT_CARBON_CREDIT_ADDRESS_SUBINDEX` : default subindex of the `carbon_credit` contract.
* `REACT_APP_DEFAULT_PROJECT_TOKEN_ADDRESS_SUBINDEX` : default subindex of the `project_token` contract.
* `REACT_APP_MARKET_CONTRACT_NAME`: name of the `carbon_credit_market` contract.
* `REACT_APP_CARBON_CREDIT_CONTRACT_NAME` : name of the `carbon_credit` contract.
* `REACT_APP_PROJECT_TOKEN_CONTRACT_NAME` : name of the `project_token` contract.
* `REACT_APP_CONCORDIUM_NODE_ENDPOINT` : Endpoint of concordium node.
* `REACT_APP_CONCORDIUM_NODE_PORT`: Port of concordium node.
* `REACT_APP_EXPLORER_URL_TXN_HASH` : URL of the explorer to view transaction details.
* `REACT_APP_WERT_PARTNER_ID` : ID of the wert partner.
* `REACT_APP_WERT_NETWORK` : Network of the wert partner.
* `REACT_APP_WERT_ORIGIN` : Origin of the wert partner.
* `REACT_APP_GOOGLE_CLIENT_ID` : Client ID of the google app which will be used for authentication.
* `REACT_APP_IPFS_GATEWAY_URL` : URL of the IPFS gateway.
* `REACT_APP_INDEXER_API_URL` : URL of the indexer / listener API.
* `REACT_APP_MODULE_REF` : Module reference of the deployed smart contract. This can be found in the output of the deploy command.
* `REACT_APP_MODULE_SCHEMA` : base64 encoded schema of the deployed smart contract. This can be found in the [file](./contracts/schema_base64.txt)

5. Run
1. Run [Events Listener Backend](./indexer/server/src/listener.ts)
abizjak marked this conversation as resolved.
Show resolved Hide resolved

```bash
yarn debug:listener
```

2. Run [Web Backend](./indexer/server/src/web.ts)

```bash
yarn debug:web
```

3. Run [Web Frontend](./market-ui/README.md)

```bash
yarn start:ui
```
3 changes: 3 additions & 0 deletions low-code-carbon-credits-marketplace/contracts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target
module.wasm
schema_base64.txt
215 changes: 215 additions & 0 deletions low-code-carbon-credits-marketplace/contracts/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions low-code-carbon-credits-marketplace/contracts/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "carbon-credit-module"
version = "0.1.0"
authors = ["Stactrace Solutions <[email protected]>"]
edition = "2021"
license = "MPL-2.0"
rust-version = "1.65.0"

[features]
default = ["std", "wee_alloc"]
std = ["concordium-std/std", "concordium-cis2/std"]
wee_alloc = ["concordium-std/wee_alloc"]

[dependencies]
concordium-std = { version="8.0.0", default-features = false }
concordium-cis2 = { version="5.0.0", default-features = false }
hex = "0.4.3"

[lib]
crate-type = ["cdylib", "rlib"]

[profile.release]
codegen-units = 1
opt-level = "s"
Loading
Loading