Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

Cerebellum-Network/ddc-smart-contract

Repository files navigation

DDC Smart Contract On Ink!

This smart contract takes deposit from DDC node wallet; then accepts data metrics reported by the paying node; then store and increment the metrics in a hashmap.

This doc will explain:

  • How to create Smart Contract artifacts
  • How to start using it

Release Notes

vNext

v2.2.3

  • Downgraded cargo-contract to ^0.12

v2.2.2

  • Fixed binaryen version

v2.2.1

  • Updated Dockerfile
  • Added script to extract artifacts from the docker image

v2.2.0

  • Added DDN permissions.

v2.1.0

  • Added DDN manager role and methods for its management
  • Allow DDN manager to add/remove DDC nodes
  • Refactored tests

v2.0.0

  • Added metric validation
  • Attached period to reporter
  • Added metrics per DDN
  • Added DDN status tracking
  • Changed tier configuration
  • Changed metrics format [breaking]
  • Added refund functionality
  • Added subscription details function
  • Minor improvements
  • Refactored repo structure

v1.1.0

  • Clean up the contract
  • Added DDC Nodes API: add/list/delete
  • Removed revoke_membership
  • Removed token

v1.0.0

  • DDC Smart Contract v1.0.0
    • Basic functionality added
  • Derivative Assets Smart Contrat v0.1.0

How to create Smart Contract Artificats

  1. Clone this repository
  2. Install build tools (ink setup):
    rustup component add rust-src --toolchain nightly-2021-09-06 && \
    rustup target add wasm32-unknown-unknown --toolchain nightly-2021-09-06 && \
    cargo install cargo-contract --version 0.14.0 --force --locked
    
    # Wasm tools (https://github.com/WebAssembly/binaryen/releases)
    # Ubuntu. Install default then upgrade to version >= 99.
    sudo apt install binaryen
    wget http://de.archive.ubuntu.com/ubuntu/pool/universe/b/binaryen/binaryen_99-3_amd64.deb
    sudo dpkg -i binaryen_99-3_amd64.deb
    # MacOS
    brew install binaryen
  3. Now you can either test or build artifacts:
    • Test Smart Contract Source Code
    cargo +nightly test
    In case of any issues, try to specify version:
    cargo +nightly-2020-10-06 test
    • Build Smart Contract
    cargo +nightly contract build

Deploy Smart Contract and test it

In order to deploy and test Smart Contract use Quick Start Guide.

Test smart contract artifacts wit pos-node and e2e tests

  • check pos-node repository workflow results with new version of artifacts here
  • check ddc-e2e-tests repository workflow results with new version of artifacts here

How to copy artifacts from latest DDC SC image

  • To copy the latest artifacts use (If you any other version )
    sudo . ./copy-ddc-sc.sh dir_path_to image_tag
    sudo . ./copy-ddc-sc.sh (default: dir_path_to --> ./ directory, image_tag --> latest)

How to run integration test locally (integration tests run on every pull request)

  • To run tests locally use command
    . ./scripts/run-integration-tests.sh POS_NODE_VERSION DDC_E2E_TEST_VERSION \

Specification

See Specification

Endowment

The endowment is the balance the deployer give to the contract upon deployment

Substrate's official recommendation is 1000 endowments - 1000 cere coins

Unlike Ethereum, the contract's balance seems to be this endowment

If someone pays 10 Cere subscription fee, the contract balance doesn't change, it is still 1000 endowment, not 1010;

It seems that when you refund a customer, say, paying back 10 Cere, this balance will be deducted from the endowment, now the endowment becomes 990

It seems the endowment is eroded (decreased) every block, see this official document

line #702 /// Query how many blocks the contract stays alive given that the amount endowment

https://github.com/paritytech/substrate/blob/master/frame/contracts/src/lib.rs

lacks official explanation, the only useful info found is this function

/// Query how many blocks the contract stays alive given that the amount endowment /// and consumed storage does not change. pub fn rent_projection(address: T::AccountId) -> RentProjectionResult<T::BlockNumber> { Rent::<T, PrefabWasmModule>::compute_projection(&address) }