Skip to content

shuffle_dex_modules

Peter Maksymowsky edited this page Jan 20, 2022 · 5 revisions

Using shuffle_dex_modules

Install shuffle:

Install brew: https://brew.sh/
Install deno: https://deno.land/#installation

From diem directory:

  • Install Diem dependencies including Rust, Clang, Deno, etc, by running the following script in diem root directory:
./scripts/dev_setup.sh
  • Install shuffle binary
cargo install --path shuffle/cli

Folder Structure

├── e2e                                 # Directory contains end to end tests (currently irrelevant test)
├── integration                         # Directory contains integration tests (current irrelevant tests)
├── main                                # main directory
│   ├── build                           # Build directory
│   ├── generated                       # Generated type definitions for Typescript (including our scripts)
│   ├── sources                         # Our Move modules and scripts
|   ├── devapi.ts                       # Typescript API functions (kind of useful)
|   ...
|   └── mod.ts                          # Other API functions (need to add manually)
└── stdlib                              # Move standard libarary

Getting started

  1. Run shuffle node to bring up a local testnet
  2. cd into the shuffle_dex_modules directory
  3. Run shuffle account which generates 2 accounts, our Parent VASP account for modules and a second for testing P2P transactions
  4. Run shuffle build to do a test build and see if everything works as intended
  5. Run shuffle deploy to deploy the modules once you are happy. You should see them be deployed in the output.
  6. Run shuffle console to run an interactive repl console where you can run functions from the .ts files.

Some things to run in the shuffle console

  • await devapi.accountTransactions() to get your account's transactions
  • await devapi.resources() to get the resources for your account

We will want to write code/scripts in main/mod.ts which can then be ran in the console. Helpers are generated in main/generated/diemStdlib/mod.ts.

Running Scripts

You will want to write your scripts inside the modules (don't know how to run them in the other way) like so:

    public(script) fun mint_coin_b(account: signer, amt: u64) {
        mint(amt, &account);
    }

Then run shuffle deploy and go to main.mod.ts. In there, write a new function like:

export async function mintCoinBFunction2(
  amt: bigint,
) {
  const payload = codegen.Stdlib.encodeMintCoinBScriptFunction( //This function is generated in generated/diemStdlib/mod.ts
    amt,
  );
  return await DiemHelpers.buildAndSubmitTransaction(
    defaultUserContext.address,
    await devapi.sequenceNumber(),
    await defaultUserContext.readPrivateKey(),
    payload,
  );
}

Running a Shuffle console as the TC account

shuffle console -a 0xB1E55ED -k ~/.shuffle/nodeconfig/mint.key