GithubHelp home page GithubHelp logo

novadev94 / helios Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hyperion-bt/helios

0.0 1.0 0.0 3.35 MB

Helios Lang reference compiler

License: The Unlicense

JavaScript 99.99% Makefile 0.01%

helios's Introduction

Helios Lang

Helios is a Domain Specific Language that compiles to Plutus-Core (i.e. Cardano on-chain validator scripts). Helios is a non-Haskell alternative to Plutus.

Helios is purely functional, strongly typed, and has a simple curly braces syntax. It notably supports closures, compile-time evaluation, and enums as tagged unions.

The Helios library contains a reference compiler for the Helios language, as well as transaction building functions. Everything is written in Javascript.

Use the following tutorial to learn how to use Helios with cardano-cli:

  1. Cardano-node setup
  2. Wallet setup and funding
  3. Always Succeeds contract
  4. Time Lock contract
  5. Subscription contract
  6. Minting policy scripts
  7. English Auction contract

We are in the process of migrating these tutorials here. There is an online coding playground.

Acknowledgements

Quick start examples

1. Vesting contract example

The following Helios example is equivalent to the Plutus vesting contract from the Plutus playground:

spending vesting

struct VestingTranche {
    time:  Time // 'amount' is available after 'time'
    amount: Value

    func available_from(self, time: Time) -> Value {
        if (time >= self.time) {
            self.amount
        } else {
            Value::ZERO
        }
    }

    func remaining_from(self, time: Time) -> Value {
        self.amount - self.available_from(time)
    }
}

struct VestingParams {
    tranche1: VestingTranche
    tranche2: VestingTranche
    owner:    PubKeyHash

    func remaining_from(self, time: Time) -> Value {
        self.tranche1.remaining_from(time) + self.tranche2.remaining_from(time)
    }
}

const PARAMS: VestingParams = VestingParams{
    /*parameters interpolated from surrounding js*/
}

// the compiler is smart enough to add an empty Datum and empty Redeemer as arguments to the actual main entrypoint function
func main(ctx: ScriptContext) -> Bool {
    tx: Tx = ctx.tx;
    now: Time = tx.now();
    remaining_actual: Value = tx.value_locked_by(ctx.get_current_validator_hash());
    remaining_expected: Value = PARAMS.remaining_from(now);
    remaining_actual >= remaining_expected && tx.is_signed_by(PARAMS.owner)
}

You can compile this source into Plutus-Core using the helios.js library:

import * as helios from "helios.js"

const src = `struct VestingTranche {
...
...
`;

console.log(helios.Program.new(src).compile().serialize());
// the output can be saved to a file, and that file can be used directly by cardano-cli

You can explore this example on the Helios playground.

2. Deserialize Plutus-Core

import * as helios from "helios.js"

const plutusCoreJson = `{"type": "PlutusScriptV1", ...}`;

// dump Plutus-Core AST
console.log(helios.deserializePlutusCore(plutusCoreJson));

Helios user guide and language reference

Can be found here.

helios's People

Contributors

christianschmitz avatar

Watchers

 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.