Giter Site home page Giter Site logo

chainsafe / pint Goto Github PK

View Code? Open in Web Editor NEW
21.0 9.0 12.0 152.9 MB

A Polkadot ecosystem index for investors. A self sustaining auction treasury for parachains.

Home Page: https://polkadotindex.com/

License: GNU Lesser General Public License v3.0

Rust 91.49% Shell 0.03% Dockerfile 0.28% TypeScript 7.40% Handlebars 0.80%
polkadot pint defi parachains

pint's Introduction

Polkadot Index Network Token (PINT 🍺)

License: LGPL v3 rustdocs

A Polkadot ecosystem index for investors. A self sustaining auction treasury for parachains.

Organized by the Stateless Money validator, governed by a community that includes Polychain Capital, Hypersphere Ventures, HashKey Capital, Acala, and built by ChainSafe as a StakerDAO product.

For more information on the project please visit Polkadot Index Network Token documentation.

Current development should be considered a work in progress.

Upstream

This project is a fork of the Substrate Developer Hub Node Template.

Build & Run

Follow these steps to prepare a local Substrate development environment 🛠️

Setup

This project currently builds against Rust nightly-2021-08-01. Assuming you have rustup already insatlled set up your local environment:

rustup install nightly-2021-08-01
rustup target add wasm32-unknown-unknown --toolchain nightly-2021-08-01
rustup override set nightly-2021-08-01

Build

Once the development environment is set up, build the node template. This command will build the Wasm and native code:

cargo build --release

Note: If the build fails with (signal: 9, SIGKILL: kill) it has probably run out of memory. Try freeing some memory or build on another machine.

Run

Development Chain

You can start a standalone development chain with instant sealing:

cargo run -- --tmp --dev --instant-sealing

Use a chain spec file with pre funded Developer accounts

cargo run -- --tmp --chain ./resources/pint-dev.json --instant-sealing

NOTE: the amount of PINT in all the endowed accounts (dev accounts) of the balances pallet ( see pint-dev.json) directly affects the NAV, since this is the total amount of PINT in curculation at genesis

Or if already built

./target/release/pint --tmp --dev --instant-sealing

This will use the node/src/chain_spec/dev.rs chain spec.

Local Testnet

Polkadot (release-v0.9.x branch)

cargo build --release

./target/release/polkadot build-spec --chain rococo-local --raw --disable-default-bootnode > rococo_local.json

./target/release/polkadot --chain ./rococo_local.json -d cumulus_relay0 --validator --alice --port 9844

./target/release/polkadot --chain ./rococo_local.json -d cumulus_relay1 --validator --bob --port 9955

PINT Parachain:

# this command assumes the chain spec is in a directory named polkadot that is a sibling of the pint directory
./target/release/pint --collator --alice --chain pint-dev --ws-port 9945 --parachain-id 200 --rpc-cors all -- --execution wasm --chain ../polkadot/rococo_local.json --ws-port 9977 --rpc-cors all

Registering on Local Relay Chain

In order to produce blocks you will need to register the parachain as detailed in the Substrate Cumulus Workshop by going to

Developer -> sudo -> paraSudoWrapper -> sudoScheduleParaInitialize(id, genesis)

Ensure you set the ParaId to 200 and the parachain: Bool to Yes.

cargo build --release
# Build the Chain spec
./target/release/pint build-spec --disable-default-bootnode > ./pint-local-plain.json
# Build the raw file
./target/release/pint build-spec --chain=./pint-local-plain.json --raw --disable-default-bootnode > ./pint-local.json


# export genesis state and wasm
./target/release/pint export-genesis-state --parachain-id 200 > ./resources/para-200-genesis
./target/release/pint export-genesis-wasm > ./para-200.wasm
  • polkadot-launch can be run by dropping the proper polkadot binary in the ./bin folder and
    • Run globally
      • polkadot-launch config.json
    • Run locally, navigate into polkadot-launch,
      • yarn
      • yarn start

Documentation

Commands

  • mkdocs serve - Start the live-reloading docs server.
  • mkdocs build - Build the documentation site.
  • mkdocs -h - Print help message and exit.

pint's People

Contributors

ansermino avatar clearloop avatar dutterbutter avatar mattsse avatar redoudou avatar willemolding avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pint's Issues

Fix docker image publishing

Issue summary

  • The Publish Tagged Docker Image step in the ci currently fails with
#!/bin/bash -eo pipefail
IMAGE_TAG=${CIRCLE_TAG/v/''}
docker tag $IMAGE_NAME:latest $IMAGE_NAME:$IMAGE_TAG
docker push $IMAGE_NAME:latest
docker push $IMAGE_NAME:$IMAGE_TAG
Error parsing reference: "chainsafe/pint:" is not a valid repository/tag: invalid reference format

Exited with code exit status 1
CircleCI received exit code 1

Other information and links

  • I think the expected tag has this format $DOCKER_REGISTRY_URL/$APPLICATION_NAME:$IMAGE_VERSION_DEV;, so perhaps only the version is missing

Setup GitHub Actions CI

Setup CI to run a series of checks and protection rules prior to changes being included into main branch.

Checks may include but not limited to:

  • linter
  • tests
  • docker build and push
  • slack notifications
  • codeowners file

Update design doc to reflect current status

Implementation details

We need to update the design doc to reflect any changes in the actual implementation. It would be good to discuss a general process for doing so. Perhaps we make appropriate changes during each sprint planning session.

Testing details

Acceptance Criteria

Display clippy check comments on PRs

Issue summary

After moving forward to CircleCI in #49, we lost the comments of clippy-check on PRs.

This issue has low priority, I'll back here when I'm free, or if there are any rust projects in ChainSafe that have the same demand, welcome to develop this feature together~

Potential Solutions

Upload artifacts with the JSON output of clippy-check in CircleCI, fork actions-rs/clippy-check downloading the JSON output and apply to PRs.

Use Github Actions ( not recommend )

Other information and links

RemoteAssetManager pallet

Implementation details

Provides capabilities to bond/unbond and transfer assets on other chains. Utilized by the AssetIndex to interact with assets on other parachains.

Acceptance Criteria

The completed pallet should have the following functionality:

  • transfer
  • bond
  • unbond

LocalTreasury Pallet

The completion of this Epic requires the LocalTreasury pallet to be completed with intended features and tested.

Implementation details

At a high-level the Treasury is simply an AccountId. It maintains ownership of various assets and is controlled by the Governance Committee. Deposits to the Treasury can be done by simply transferring funds to its AccountId. The committee can execute proposals to withdraw funds from the Treasury. The PINT treasury will hold DOT and PINT exclusively.

The PINT runtime will contain two separate treasury pallets because DOT and PINT each have different requirements. The LocalTreasury will operate within the runtime and manage PINT. The RemoteTreasury will be responsible for DOT, which will be controlled through XCMP on the relay chain.

Acceptance Criteria

The completed pallet should have the following functionality:

  • withdraw

Implement `withdraw` API call

Implement withdraw API call detailed in the specification under AssetIndex Pallet.

Implementation details

  • Queries PriceFeed for NAV of index token and calculates proportions of underlying assets to be withdrawn
  • Dispatches calls to other chains to unbond underlying assets
  • Updates index. If this reduces the total supply of any asset to 0, removes asset type from index entirely
  • Burns an amount of the index token specified by its NAV
  • Amount of index token must be above MinimumRedemption threshold
Param Type Desc
amount Balance Amount of the index token being withdrawn

Testing details

Acceptance Criteria

Implement the `AssetTransactor` type required for the XcmConfig

Issue summary

  • The AssetTransactor will handle withdrawing and depositing assets upon received XCM
  • This will require several conversions
    • from MultiLocation to Asset
    • from AccountId32 to AccountId
  • and handling of deposit/withdraw for the sender's holding account.

Other information and links

SAFTRegistry Pallet

The completion of this Epic requires the SAFTRegistry pallet to be completed with intended features and tested.

Implementation details

Records of off-chain SAFTs are placed on-chain using the SAFTRegistry pallet. Each SAFT consists of:

  • Asset ID - a unique identifier for the asset
  • Units - how many units of the asset are included in the SAFT
  • NAV - Net asset value of the SAFT

Acceptance Criteria

The completed pallet should have the following functionality:

  • add_saft
  • remove_saft
  • report_nav

Implement `transfer` API call

Implement transfer API call detailed in the specification under RemoteAssetManager Pallet.

Implementation Details

Dispatch XCM message to transfer asset between caller account and recipient

Param Type Desc
id AssetId Assets being transferred
units Balance Assets being transferred
recipient AccountId Recipient of transfer

Implement `remove_asset` API call

Implement remove_asset API call detailed in the specification under AssetIndex Pallet.

Implementation details

  • Dispatches transfer to move assets out of the index’s account, if a liquid asset is specified
  • Updates the index to reflect the removed assets
Param Type Desc
id AssetId Unique identifier of the asset being added
units Balance Amount of asset being added
recipient Option If removing liquid assets, the recipient of them

Testing details

Acceptance Criteria

Implement `report_nav` API call

Implementation details

Implement report_nav API call detailed in the specification under SAFTRegistry Pallet.

The NAV of a SAFT is subject to change over time. Custodians of SAFTs will be responsible for submitting proposals to the Governance Committee to update the NAV of a SAFT at regular intervals. This will also be reflected in the index.

Testing details

Acceptance Criteria

Implement `deposit` API call

Implement deposit API call detailed in the specification under AssetIndex Pallet.

Implementation details

  • Dispatches transfer Call to relay chain to move DOTs into the PINT Index account
  • Fetches PINT NAV and DOT price from price feed
  • Mints PINT proportional to DOT deposit
  • Updates index to reflect deposit
Param Type Desc
amount Balance Amount of DOT being deposited

Testing details

Acceptance Criteria

Implement `add_asset` API call

Implement add_asset API call detailed in the specification under AssetIndex Pallet.

Implementation details

  • Index updated to include added assets
  • Caller balance is updated to allocate the correct amount of the IndexToken
  • Creates IndexAssetData if it doesn’t exist, otherwise adds to list of deposits
Param Type Desc
id AssetId Unique identifier of the asset being added
units Balance Amount of asset being added
availability AssetAvailability The availability of the asset (SAFT or Liquid)
value Balance Amount of IndexToken to mint

Testing details

Acceptance Criteria

AssetIndex Pallet

The completion of this Epic requires the AssetIndex pallet to be completed with intended features and tested.

Implementation details

The AssetIndex pallet is responsible for tracking a set of assets and representing them in the form of an index. For each asset it stores a record containing:

  • Asset ID - a unique identifier for the asset
  • Location - where the asset exists (ie. which chain)
  • Units - how many units of the asset are in the index
  • Availability - whether the asset is liquid or not

Acceptance Criteria

The completed pallet should have the following functionality:

  • add_asset
  • remove_asset
  • deposit
  • withdraw
  • complete_withdrawal

Failed to produce block on local rococo testnet

Describe the bug

Test Machine
OSX Big Sur 11.2.3 (M1 chip)

PINT can not produce block after being registered as a parachain on the local rococo testnet

Expected Behavior

Follow the guide of substrate parachain template, PINT should be able to print logs like

2021-04-01 16:31:09 [Relaychain] 💤 Idle (2 peers), best: #243 (0x46d8…f394), finalized #192 (0x9fb4…4b28), ⬇ 1.0kiB/s ⬆ 3.2kiB/s    
2021-04-01 16:31:09 [Parachain] 💤 Idle (0 peers), best: #90 (0x85c6…45be), finalized #64 (0x10af…4ede), ⬇ 1.1kiB/s ⬆ 1.0kiB/s    
2021-04-01 16:31:12 [Relaychain] ✨ Imported #244 (0xe861…d99d)    
2021-04-01 16:31:14 [Relaychain] 💤 Idle (2 peers), best: #244 (0xe861…d99d), finalized #193 (0x9225…85f1), ⬇ 2.0kiB/s ⬆ 1.6kiB/s    
2021-04-01 16:31:14 [Parachain] 💤 Idle (0 peers), best: #90 (0x85c6…45be), finalized #65 (0xdd20…d44a), ⬇ 1.6kiB/s ⬆ 1.4kiB/s    

Notice here is ...best: #90..., finalized #65...

Current Behavior

2021-04-22 21:03:24  [Relaychain] 💤 Idle (2 peers), best: #295 (0xd339…84bc), finalized #292 (0xb3eb…aed3), ⬇ 2.3kiB/s ⬆ 2.0kiB/s    
2021-04-22 21:03:24  [Parachain] 💤 Idle (0 peers), best: #0 (0xd0be…fc70), finalized #0 (0xd0be…fc70), ⬇ 2.3kiB/s ⬆ 2.0kiB/s    
2021-04-22 21:03:29  [Relaychain] 💤 Idle (2 peers), best: #295 (0xd339…84bc), finalized #293 (0x2799…efa4), ⬇ 1.0kiB/s ⬆ 0.8kiB/s    
2021-04-22 21:03:29  [Parachain] 💤 Idle (0 peers), best: #0 (0xd0be…fc70), finalized #0 (0xd0be…fc70), ⬇ 0 ⬆ 0 

...best: #0..., finalized #0...

Possible Solution

Check the runtime configuration of PINT.

To Reproduce

Just follow the substrate-parachain-template, but replace the template with PINT.

Implement `add_saft` API call

Implementation details

Implement add_saft API call detailed in the specification under SAFTRegistry Pallet.

The addition of a SAFT can be presented to the Governance Committee as a proposal of the form:

SAFTRegistry::add_saft(asset_id, nav, units)

The proposal will include an initial NAV for the SAFT. If approved, the SAFT is added to the registry. This will result in the index also being updated to include the assets promised by the SAFT.

Testing details

Acceptance Criteria

Implement `execute` API call

Implementation details

  • Dispatches the provided call over XCMP to the configured location
Param Type Desc
call RemoteCall The Call being dispatched

Acceptance Criteria

Implement e2e testing

Implementation details

Implement e2e testing to ensure everything works collectively (e.g. register assets, oracle setup, adding/depositing/withdrawing assets).

Testing details

Acceptance Criteria

Implement constituent committee to `Committee` Pallet

Implementation details

PINT governance will be administered in two layers: the PINT Council and the Constituent Committee. The PINT Council will consist of 7 representatives, while the Constituent Committee will consist of one representative from each project that has assets included in the index.

The Constituent Committee retains veto power over the decisions of the PINT Council. If the majority of the Constituent Committee votes "nay" following a PINT Council Governance vote, the action will fail. If there is no majority "nay" vote from the Constituent Committee, the action will pass.

Testing details

Acceptance Criteria

  • Second layer of governance to be included
  • veto power
  • council selection

RemoteTreasury pallet

Implementation details

Similar to LocalTreasury with extra functionality to control assets on other chains via XCMP. The RemoteTreasury will be responsible for DOT, which will be controlled through XCMP on the relay chain.

Acceptance Criteria

The completed pallet should have the following functionality:

  • execute

Add licenses

Implementation details

We are using LGPL V3 and should indicate that appropriately.

Testing details

N/A

Acceptance Criteria

  • Automatic license check
  • Cargo.toml's updated
  • SPDX Headers
  • Updated README

Use `PINT` or `IndexToken` in our code documentation?

Issue summary

When people talk about PINT, people regard PINT as the token/currency of this project as our wishes.

Currently, we are using a namespace IndexToken in our code (docs) which is standard in development but easy to make the concepts mixed up for developers/contributors —— We already have too many concepts about tokens in PINT, it is necessary to simplify them.

I'm thinking that we can:

  1. Use one namespace only, replace IndexToken with PINT in the code.
  2. Keep two namespaces, doc the IndexToken that it is PINT we are commonly talking about.

Test PINT with `--all-features` in CI

Summary

Should we test --all-features in our CI?

It seems some features could not be compiled in pallet-collective and pallet-xcm, I found this problem in #45

error[E0046]: not all trait items implemented, missing: `successful_origin`
   --> /Users/clearloop/.cargo/git/checkouts/substrate-7e08433d4c370a21/68cfc32/frame/collective/src/lib.rs:884:1
    |
884 | / impl<
885 | |     O: Into<Result<RawOrigin<AccountId, I>, O>> + From<RawOrigin<AccountId, I>>,
886 | |     AccountId: Default,
887 | |     I,
...   |
900 | |     }
901 | | }
    | |_^ missing `successful_origin` in implementation
    |
    = help: implement the missing item: `fn successful_origin() -> OuterOrigin { todo!() }`

error[E0046]: not all trait items implemented, missing: `successful_origin`
   --> /Users/clearloop/.cargo/git/checkouts/substrate-7e08433d4c370a21/68cfc32/frame/collective/src/lib.rs:904:1
    |
904 | / impl<
905 | |     O: Into<Result<RawOrigin<AccountId, I>, O>> + From<RawOrigin<AccountId, I>>,
906 | |     N: U32,
907 | |     AccountId,
...   |
921 | |     }
922 | | }
    | |_^ missing `successful_origin` in implementation
    |
    = help: implement the missing item: `fn successful_origin() -> OuterOrigin { todo!() }`

error[E0046]: not all trait items implemented, missing: `successful_origin`
   --> /Users/clearloop/.cargo/git/checkouts/substrate-7e08433d4c370a21/68cfc32/frame/collective/src/lib.rs:927:1
    |
927 | / impl<
928 | |     O: Into<Result<RawOrigin<AccountId, I>, O>> + From<RawOrigin<AccountId, I>>,
929 | |     N: U32,
930 | |     D: U32,
...   |
945 | |     }
946 | | }
    | |_^ missing `successful_origin` in implementation
    |
    = help: implement the missing item: `fn successful_origin() -> OuterOrigin { todo!() }`

error[E0046]: not all trait items implemented, missing: `successful_origin`
   --> /Users/clearloop/.cargo/git/checkouts/substrate-7e08433d4c370a21/68cfc32/frame/collective/src/lib.rs:951:1
    |
951 | / impl<
952 | |     O: Into<Result<RawOrigin<AccountId, I>, O>> + From<RawOrigin<AccountId, I>>,
953 | |     N: U32,
954 | |     D: U32,
...   |
969 | |     }
970 | | }
    | |_^ missing `successful_origin` in implementation
    |
    = help: implement the missing item: `fn successful_origin() -> OuterOrigin { todo!() }`

   Compiling pallet-multisig v3.0.0 (https://github.com/paritytech/substrate.git?branch=rococo-v1#68cfc326)
error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0046`.
error: could not compile `pallet-collective`

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error[E0046]: not all trait items implemented, missing: `successful_origin`
   --> /Users/clearloop/.cargo/git/checkouts/polkadot-4038f27d5e4ea2e8/943038a/xcm/pallet-xcm/src/lib.rs:162:1
    |
162 | / impl<O: OriginTrait + From<Origin>, F: Filter<MultiLocation>> EnsureOrigin<O> for EnsureXcm<F>
163 | |     where O::PalletsOrigin: From<Origin> + TryInto<Origin, Error=O::PalletsOrigin>
164 | | {
165 | |     type Success = MultiLocation;
...   |
181 | |     }
182 | | }
    | |_^ missing `successful_origin` in implementation
    |
    = help: implement the missing item: `fn successful_origin() -> OuterOrigin { todo!() }`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0046`.
error: build failed

Repreduce

$ cargo test --all-features

Implement `complete_withdrawal` API call

Implement complete_withdrawal API call detailed in the specification under AssetIndex Pallet.

Implementation details

  • Checks every pending withdrawal within PendingWithdrawals mapping
  • Asserts that LockupPeriod has passed since withdrawal was initiated
  • Completes unbonding process on other parachains (withdraw_unbonded)
  • If successful, transfers assets to owner and delete pending withdrawal from system
  • If it fails, keep withdrawal record and allow the caller to retry

Testing details

Acceptance Criteria

Committee Pallet

The completion of this Epic requires the Committee pallet to be completed with intended features and tested.

Implementation details

The PINT Committee utilizes the Committee pallet to manage on-chain proposals.

Acceptance Criteria

The completed pallet should have the following functionality:

  • propose
  • vote
  • close

Implement `bond` API call

Implement bond API call detailed in the specification under RemoteAssetManager Pallet.

Implementation Details

Dispatch XCM message to bond assets in callers account

Param Type Desc
id AssetId Asset being bonded
units Balance Amount to bond

Testing details

Acceptance Criteria

Implement `unbond` API call

Implement unbond API call detailed in the specification under RemoteAssetManager Pallet.

Implementation details

Dispatch XCM message to unbond assets in callers account

Param Type Desc
id AssetId Assed being unbonded
units Balance Amount to unbond

Testing details

Acceptance Criteria

Implement `remove_saft` API call

Implementation details

Implement remove_saft API call detailed in the specification under SAFTRegistry Pallet.

A SAFT may be removed from the registry at the discretion of the Governance Committee. In almost all cases, this will be paired with the addition of the liquid assets to the index. This two step process will be executed atomically to remove any discrepancies in the present contents of the index.

Testing details

Acceptance Criteria

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.