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

fmg-simple-adjudicator

v0.3.8

Published

Simple adjudicator for force-move games

Downloads

4

Readme

Simple Adjudicator

The simple adjudicator is the on-chain contract that is responsible for holding the funds deposited by the parties and for managing on-chain challenges.

The simple adjudicator can only support a single state channel game, meaning that a new on-chain deposit is required for each game played by the participants. We provide this adjudicator as a usable but inefficient proof-of-principal. In the long term, we would want to see adjudicators that support ledger channels and virtual channels.

Usage

Here we go over some example happy-case useage for the simple adjudicator. There ~are~ will soon be more comprehensive examples in the tests.

Note: In what follows we interact with a StateWallet object. This is for illustration purposes only - the StateWallet isn't written yet. Ultimately it will be responsible for signing and storing states, as well as making sure that the state transitions are allowed according to the rules of the game being played.

Pre-funding setup

Before putting any funds into the adjudicator both A and B need to be holding signed agreements of their intent to start the game with pre-agreed balances. These agreements give them the capability (through a force-move) to recover any funds that they have deposited in the case that the opponent stalls.

import { Channel } from 'fmg-core';
import { MyGame } from 'my-game';

// the contract describing MyGame should be installed on-chain in a single global location
let myGameContract = MyGameContract.deployed();
// participants are defined by their addresses
let participants = [addressOfA, addressOfB];
// choose the channelNonce to make (myGameContract.address, channelNonce, participants) unique
let channelNonce = 12345678; 
// starting amounts
let aBal = Number(web3.toWei(6, "ether"));
let bBal = Number(web3.toWei(4, "ether"));
let resolution = [aBal, bBal];

// In a's client:
let startPos = { /* ... */ } // the game state that a wants to start in
let channel = new Channel(myGameContract.address, channelNonce, participants);
let state0A = MyGame.preFundSetup({ channel, turnNum: 0, stateCount: 0, resolution, startPos });
let message0A = StateWalletA.sign(state0A);

// a ---> message0A ----> b

// In b's client:
StateWalletB.receive(message0A);
let move0A = MyGame.fromMessage(message0A);
let state1B = MyGame.preFundSetup({ ...move0A, turnNum: 1, stateCount: 1 });
let message1B = StateWalletB.sign(state1B);

// b ---> message1B ----> a

// In a's client:
StateWalletA.receive(message1B);

Funding the channel with the simple adjudicator

At this point both players hold two signed messages signifying their agreement to commence the game in the specified start state. They can now fund the project:

// In a's client:
let adj = await SimpleAdjudicator.new(channel.id).address; // deploy adjudicator with channelId
await web3.eth.sendTransaction({ to: adj, value: aBal }); // fund contract

// a ---> adj ---> b

// In b's client:
assert(Number(web3.eth.getBalance(adj)) == aBal); // check that a deposited the right amount
await web3.eth.sendTransaction({ to: adj, value: bBal }); // fund contract

// b ----> "done" ---> a

// In a's client:
assert(Number(web3.eth.getBalance(adj)) == aBal + bBal); // check that a deposited the right amount

let state2A = MyGame.postFundSetup({ channel, turnNum: 2, stateCount: 0, resolution, startPos });
let message2A = StateWalletA.sign(state2A);

// a ---> message2A ---> b

// In b's client
StateWalletB.receive(message2A);
let state3B = MyGame.postFundSetup({ channel, turnNum: 3, stateCount: 1, resolution, startPos });
let message3B = StateWalletB.sign(state3B);

At this point, the adjudicator is funded and both participants have confirmed. They are now free to proceed with the game, starting from the agreed starting position.