npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@kosu/subcontract-sdk

v0.1.1

Published

Kosu SubContract building utilities.

Downloads

18

Readme

Kosu SubContractSDK

This SDK is designed to provide a entry point for custom settlement logic for orders transmitted though the Kosu Order Stream Network. The SubContract provides the standard methods that the Kosu system uses to encode input data for submission to the Ethereum blockchain.

Implementation of custom settlement logic compatible with the Kosu platform will require the extension of the SubContract to include the required functions to enable proper configuration of the standardized input for the participation transaction.

SubContract

makerArguments

The maker arguments will be leveraged by TODO-connect to provide a translation from a human readable Kosu order into SubContract participate bytes32 array input.

takerArguments

The taker arguments will be leveraged by TODO-connect to define required arguments for the user participating in the terms defined by the Kosu order and provide a translation of that input into the SubContract bytes32 array input.

participate

The participate function will be called to initiate the financial exchange transaction. The contract creator is going to be responsible for transforming the input bytes32 more appropriate types based on the maker and taker arguments they have defined. After a successful exchange a boolean true may be returned.

isValid

The isValid function will be called to determine if an order is still valid. The function should transform the input data then run validation to determine if the order still has available balances to exchange and is signed correctly.

amountRemaining

The amountRemaining function will be called to deterimine how many tokens are still available. The function should take the maker information and use the internal accounting to look up how many of the offered tokens remain unclaimed.

Example implementations of popular settlement logic frameworks created by the Paradigm team are located here.

Creating a Kosu SubContract

Installation

npm i @kosu/subcontract-sdk

Usage

Import the SubContract
import "@kosu/subcontract-sdk/contracts/SubContract.sol";
Extend SubContract
contract YourContract is SubContract {

}
Implement the required methods
//Optional, but the maker and taker arguments must be set before use.
constructor(_makerArguments, _takerArguments) {
  makerArguments = _makerArguments;
  takerArguments = _takerArguments;
}

function participate(bytes32[] makerData, bytes32[) takerData) public returns (bool) {
    //Your settlement implementation
    return true;
}

function isValid(bytes32[] makerData) public view returns (bool) {
    //Your validation implementation
    return false;
}

function amountRemaining(bytes32[] makerData) public view returns (uint) {
    //Your accounting implementation
    return 0;
}
Defining arguments
The arguments are a JSON string that is of the following structure:

Arguments are an ordered list where the array index in this json object correspond to the contracts bytes32 input index.

[
  {
    "dataType": "address", //The solidity data type the variable will be expected to
    "name":"maker" //The name of the key in the Kosu Connect input
  }, //index 0 of bytes32 input
  { "dataType": "uint", "name": "count" }, //index 1 of bytes32 input
  { "dataType": "address", "name": "taker" } //index 2 of bytes32 input
]
The arguments above would correspond to input in the following format
{
  "maker": "0x01234abc...",
  "count": "2000",
  "taker": "0x0321cba..."
}
Typecasting solidity function input

Assuming the example arguments were defined as the makerArguments. Usage of them in the solidity may look like:

function participate(bytes32[] makerData, bytes32[) takerData) public returns (bool) {
    address maker = address(makerData[0]);
    uint count = uint(makerData[1]);
    address taker = address(makerData[2]);

    //Boolean values don't have a casting mechanism I'm aware of, but are represented as a 0
    //or 1 when cast to a uint.
    bool boolean = uint(takerData[0]) > 0

    return true;
}