-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for taking state as an argument and for returning it (#10)
* Convert LiteralValue and ReturnValue to classes * Add support for calls that take state as input * Add support for replacing the state with a return value * Add additional check for return values that replace state * Write README * Use add instead of addCommand
- Loading branch information
Showing
3 changed files
with
145 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,50 @@ | ||
# weiroll.js | ||
The Weiroll planner for JS | ||
weiroll.js is a planner for the operation-chaining/scripting language [weiroll](https://github.com/weiroll/weiroll). | ||
|
||
It provides an easy-to-use API for generating weiroll programs that can then be passed to any compatible implementation. | ||
|
||
## Installation | ||
``` | ||
npm install --save @weiroll/weiroll.js | ||
``` | ||
|
||
## Usage | ||
|
||
### Wrapping contracts | ||
Weiroll programs consist of a sequence of delegatecalls to library functions in external contracts. Before you can start creating a weiroll program, you will need to create interfaces for at least one library contract you intend to use. | ||
|
||
The easiest way to do this is by wrapping ethers.js contract instances: | ||
|
||
``` | ||
const ethersContract = new ethers.Contract(address, abi); | ||
const contract = weiroll.Contract.fromEthersContract(ethersContract); | ||
``` | ||
|
||
You can repeat this for each library contract you wish to use. A weiroll `Contract` object can be reused across as many planner instances as you wish; there is no need to construct them again for each new program. | ||
|
||
### Planning programs | ||
First, instantiate a planner: | ||
|
||
``` | ||
const planner = new weiroll.Planner(); | ||
``` | ||
|
||
Next, add one or more commands to execute: | ||
|
||
``` | ||
const ret = planner.addCommand(contract.func(a, b)); | ||
``` | ||
|
||
Return values from one invocation can be used in another one: | ||
|
||
``` | ||
planner.addCommand(contract.func2(ret)); | ||
``` | ||
|
||
Remember to wrap each call to a contract in `planner.addCommand`. Attempting to pass the result of one contract function directly to another will not work - each one needs to be added to the planner! | ||
|
||
Once you are done planning operations, generate the program: | ||
|
||
``` | ||
const {commands, state} = planner.plan(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters