Skip to content

kaonone/akropolis-c2fc-srml

Repository files navigation

Akropolis C2FC

Implementation of financial primitive Commitments to Future Cashflows on Substrate. C2FC is a new financial primitive and a DeFi equivalent of cashflow financing. C2FC bridges traditional finance and Web3 by providing DeFi and Web3 entrepreneurs with capital to grow. For more details read about C2FC here.

Try it out

Connect to local node:

Install Rust:

curl https://sh.rustup.rs -sSf | sh

Setup Node

#!/usr/bin/env bash
set -e
mkdir akropolis
cd akropolis
git clone https://github.com/akropolisio/akropolis-polkadot.git ./node
# or git clone git@github.com:akropolisio/akropolis-polkadot.git ./node
cd node
# Install required tools:
./scripts/init.sh
# Build the WebAssembly binary:
./scripts/build.sh
# Build all native code and install:
cargo install --force --path ./ akropolis
cd ..
# Build chain-spec and export:
akropolis build-spec --chain akropolis > spec.json

Run Node

#!/usr/bin/env bash

akropolis --chain akropolis \
    --telemetry-url wss://telemetry.polkadot.io/submit/ \
    --rpc-cors all \
    --name "AkropolisC2FC-NodeName" \
    --base-path ./base \
    --keystore-path ./keystore \
    --listen-addr /ip4/0.0.0.0/tcp/30333 \
    --bootnodes \
          /ip4/178.128.225.241/tcp/30333/p2p/QmbdSLdQ5yyRG5kCLLUCDyG7FUwbqtHngRWCJyG6yULWax \
          /ip4/157.230.35.215/tcp/30333/p2p/QmbmedQMeErSiQH2AFXyb9MSNxtUNJAdH6CY6hWcdKuXJi

How it works

Creation of C2FC

Prerequisites: You should have accounts with positive balance to test creation / transfer / exchange of C2FC (let's create this account with seed //Alice, //Bob, //Charlie).

Core elements of C2FC on Substrate implementation:

  • User accounts
  • FreePromise
  • Promise
  • Bucket
  • Resitrar (Storage-module C2FC)

Creation of C2FC consists of two steps: at first, you create Free Promise and then assign a payee to it (Promise stage). While C2FC is in the Free Promise stage, it hasn’t recipient of payments (issuer is a recipient).

  • go to Extrinsics

  • Alice creates Bucket:

    • select using the selected account => Alice
    • select submit the following extrinsic C2FC :: createBucket()
    • Submit Transaction
  • Bob creates Promise:

    • select using the selected account => Bob
    • select submit the following extrinsic C2FC :: createPromise(value, period) where
      • value: amount of regular payment
      • period: periodicity of regular payment
    • Submit Transaction
  • Bob creates temporary Promise:

    • select using the selected account => Bob
    • select submit the following extrinsic C2FC :: createPromiseUntil(value, period, until) where
      • value: amount of regular payment
      • period: periodicity of regular payment
      • until: date (block) of last payment
    • Submit Transaction
  • Bob makes changes to Promise:

    • select using the selected account => Bob
    • select submit the following extrinsic C2FC :: editPromise(promise_id, value, period) where
      • promise_id: id (hash) of Bob's promise
      • value: amount of regular payment
      • period: periodicity of regular payment
    • Submit Transaction
  • Bob stakes tokens in order to ___ the Promise:

    • select using the selected account => Bob
    • select submit the following extrinsic C2FC :: stakeToPromise(promise_id, amount) where
      • promise_id: id (hash) of Bob's promise
      • amount: size (amount) of stake
    • Submit Transaction
    • select submit the following extrinsic C2FC :: withdrawStaken(promise_id) where
      • promise_id: id (hash) of Bob's promise
    • Submit Transaction

Exchange of C2FC

  • Alice sells his Bucket:

    • select using the selected account => Alice
    • select submit the following extrinsic C2FC :: setPrice(bucket_id, new_price) where
      • bucket_id: id (hash) of Bob's promise
      • new_price: price of the Bucket
    • Submit Transaction
    • select using the selected account => Charlie
    • select submit the following extrinsic C2FC :: buyBucket(bucket_id, max_price) where
      • bucket_id: id (hash) of Alice's promise
      • max_price: Charlie's maker price
    • Submit Transaction
  • Alice transfers Bucket:

    • select using the selected account => Alice
    • select submit the following extrinsic C2FC :: transfer(to, bucket_id) where
      • to: receiver of Bucket (Charlie's account)
      • bucket_id: id (hash) of Alice's Bucket
    • Submit Transaction
  • Alice is searching Bob's Promise:

    • go to ChainState
    • select selected state query => C2FC
    • use any method with name starts with freePromise...
      • freePromisesCount(): u64: number of open Promises
      • freePromisesArray(u64): Hash: get id (hash) of open Promise by increment
      • freePromisesIndex(Hash): u64: get increment number of open Promisy by it's id (hash)
      • promises(Hash): FreePromise: get Promise by id(hash)
    • click +
  • Alica adds Bob's Promise to her Bucket:

    • select using the selected account => Alice
    • select submit the following extrinsic C2FC :: acceptPromise(promise_id, bucket_id) where:
      • promise_id: id (hash) of Bob's Promise
      • bucket_id: id (hash) of Alice's Bucket
    • Submit Transaction

Pay for commitments

  • Bob pays his commitments to Bucket Owner:
    • select using the selected account => Bob
    • select submit the following extrinsic C2FC :: fillBucket(bucket_id, deposit) where:
      • bucket_id: id (hash) of Alice's Bucket
      • deposit: funds, that trasferred from Bob's account to Bucket owner's account
    • Submit Transaction