GithubHelp home page GithubHelp logo

zeitgeistpm / ink-library Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jboetticher/ztg-runtime-lib

0.0 0.0 0.0 1.63 MB

An ink! library that allows smart contracts to make runtime calls to Zeitgeist's pallets.

License: Other

Rust 31.92% TypeScript 68.08%

ink-library's Introduction

Zeitgeist Runtime Library

The Zeitgeist Runtime Library allows ink! developers to make runtime calls to Zeitgeist's special pallets with ease.

This library was built in ink! version 4.3.0.

Features

Runtime calls in ink! are made with enums that map a pallet's index and extrinsics. This library provides you with a RuntimeCall enum that encodes extrinsics from ten pallets:

  • AssetManager (Incomplete)
  • Authorized
  • Court
  • Swaps (Legacy)
  • PredictionMarkets
  • Styx
  • GlobalDisputes
  • NeoSwaps
  • Orderbook
  • Parimutuel

Zeitgeist specific data structures are also available for developers to use when making these runtime calls.

Examples

You can make a runtime call in the following format:

const result = self.env()
    .call_runtime(&RuntimeCall::AssetManager(AssetManagerCall::Transfer {
        dest: dest.into(),
        currency_id: ZeitgeistAsset::Ztg,
    amount
}));

For an example of every runtime call being made, reference the ztg_runtime_example ink! smart contract. This contract has one function for each runtime call. Note that not every runtime call can be successfully made as some extrinsics must be called via sudo, through a committee, or are otherwise disabled.

Tests

The testing environment for this package manually tests the calls within a live Zeitgeist development node. The tests themselves are written in TypeScript with the Mocha framework.

Setup

The testing folder is in ts. Install dependencies with Node (v18):

cargo contract build
cd ts
npm install

To set up the testing environment, you must set environment variables & generate a chain spec.

There are three environment variables that must be set within a new file ts/.env, each with require a complete path:

PATH_TO_NODE=[COMPLETE_PATH_TO_ZEITGEIST_NODE]
PATH_TO_CUSTOM_SPEC=[COMPLETE_PATH_TO_ZEITGEIST_SPEC]
PATH_TO_CUSTOM_RAW_SPEC=[COMPLETE_PATH_TO_ZEITGEIST_RAW_SPEC]

Then, to generate a chain spec, run the following command:

npm run spec

A custom chain spec is required as there are assumptions within the TypeScript tests that the chain spec satisfy.

Running

The TypeScript tests will automatically run and shut off instances of the Zeitgeist node, so long as the environment variables were correctly set. You can run the tests with the following:

npm run test

Skipped Tests

Some tests will be skipped. Some require either SUDO or a committee call to be completed, so in effect the runtime call will never be used by a smart contract. The swaps tests are skipped due to current versions of the Zeitgeist runtime locking them.

Contribution

There are still areas of contribution:

  • Implement storage layout for the Range type
  • Implement storage layout for [u8; 50]
  • Implement storage layout for RangeInclusive
  • Upgrade to ink! v5

ink-library's People

Contributors

jboetticher avatar

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.