Skip to content

Commit

Permalink
document precompiles
Browse files Browse the repository at this point in the history
  • Loading branch information
ecioppettini committed Jul 16, 2024
1 parent e54a790 commit 446eb0c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
6 changes: 4 additions & 2 deletions docs/home/300-react-to-events/1-scheduled-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ There are three common usages of timers in Paima
## 1. Durations

There are two functions for scheduling events
- `createScheduledData(inputData: string, blockHeight: number): SQLUpdate`
- `createScheduledData(inputData: string, blockHeight: number, precompileName: string ): SQLUpdate`
- `deleteScheduledData(inputData: string, blockHeight: number | null): SQLUpdate`

These can be used to schedule an event that happens in 5 minutes (ex: a potion whose status wears off eventually)
These can be used to schedule an event that happens in 5 minutes (ex: a potion whose status wears off eventually).

The `precompileName` argument in `createScheduledData` needs to be one of the keys of the object defined through [paima precompiles](../50-smart-contracts/300-precompiles/100-introduction.md). The associated address will be used as the `userAddress` when the event is triggered.

### Time limits

Expand Down
39 changes: 39 additions & 0 deletions docs/home/50-smart-contracts/300-precompiles/100-introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Setup

Paima precompiles allow games to define specific addresses that are only part of
the rollup, instead of belonging to any of the underlying chains (or users).


When using the templates, these can be defined in a `precompiles` directory in
the game by using the `generatePrecompile` function, and then set up with the
esbuild template through the configuration.

## Definitions
```ts
// precompiles/index.ts

export const precompiles = {
...generatePrecompile("foo"),
} as const;
```

## Esbuild configuration

```ts
const esbuild = require("esbuild");
const {
generateConfig,
} = require("@paima/build-utils/standalone-esbuildconfig.template");

const { config, outFiles, workspace } = generateConfig(
"api",
"state-transition",
"precompiles"
);
esbuild.build(config);
```

This will generate a `precompiles.cjs` package in the `packaged` folder. Paima
Engine will load this file on startup.


3 changes: 3 additions & 0 deletions docs/home/50-smart-contracts/300-precompiles/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"label": "Paima Precompiles"
}

0 comments on commit 446eb0c

Please sign in to comment.