Skip to content

Commit

Permalink
Update references to new @paima/sdk package
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienGllmt committed Oct 3, 2023
1 parent 3a965a9 commit 4ae5cf5
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 34 deletions.
24 changes: 6 additions & 18 deletions docs/home/1-setup/1-how-to-use-paima-engine.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,21 @@ If you do not have Paima Engine yet, but want to follow along, you can find publ

## Initializing Your Project

When starting a new project with Paima Engine, the developer can choose to either go completely barebones (by only initializing `paima-sdk`) or use an included template to bootstrap with all of the essentials. Initializing the SDK by itself may also be useful in cases where the developer is upgrading their project to use a new version of Paima Engine which has introduced new incompatibilities in the SDK.

You can see the available options by using:

```
./paima-engine init
```
When starting a new project with Paima Engine, you can choose to either go completely barebones, or use an included template to bootstrap with all of the essentials

Option A: To initialize a game using a basic game template use the following command and select the `generic` template:

```
./paima-engine init template
```

Option B: To initialize a game using the `paima-sdk`:
```
./paima-engine init sdk
cd paima-sdk
npm ci
```
Option B: Create everything from scratch and add [@paima/sdk](https://www.npmjs.com/package/@paima/sdk) to your project

Once the command has finished, you will notice two new folders have been created, `paima-sdk` and `generic-game-template` (name varies based on template selected). The SDK is directly used by the game template, and so all code you write will be in the `generic-game-template` folder.
Once the command has finished, you will notice a new folder have been created called `generic-game-template` (name varies based on template selected). The SDK is directly used by the game template, and so all code you write will be in the `generic-game-template` folder.

Lastly to finish the initialization process off, simply go into the `generic-game-template` folder and run `npm run initialize`. This will install all of the packages and set the project up to be ready for you to start coding.

Of note, feel free to rename the `generic-game-template` folder to the name of your game (or whatever you prefer), but make sure to not change the folder name of `paima-sdk`.
Of note, feel free to rename the `generic-game-template` folder to the name of your game (or whatever you prefer)

## Packing Your Game Code

Expand Down Expand Up @@ -86,7 +75,7 @@ One side note, as you begin writing your game logic (or when building a template

When you update your DB schema or you want to add or edit some of the queries in the `db/` directory of your game, you will want to use the `pgtyped` tool to process the `.sql` code to generate `.ts` code for the queries to be used by your game and the engine. To do this, simply navigate to the `db/` directory and execute `npm run compile`. Note that you will need to provide the credentials of a running Postgres DB initialized with your schema in the `db/pgtypedconfig.json` file.

Furthermore, note that the version of `@pgtyped/query` in `db/package.json` is set to a specific value, which should be the same as the version specified in `paima-sdk/paima-db/package.json`. These versions need to stay the same to avoid compatibility issues.
Furthermore, note that the version of `@pgtyped/runtime` in `db/package.json` is set to a specific value, which should be the same as the version specified in `@paima/db/package.json`. These versions need to stay the same to avoid compatibility issues.

## Deploying Your Game's L2 Smart Contract

Expand Down Expand Up @@ -147,7 +136,7 @@ If you wish to deploy your game on a server/move into a production environment,
- `.env.*` (Your game node config)
- `paima-engine` (The Paima Engine executable)

In other words, you do not require your unpacked game code or `paima-sdk`, allowing you to easily run your game node wherever you deem best (without even needing node installed or any external dependencies).
In other words, you do not require your unpacked game code, allowing you to easily run your game node wherever you deem best (without even needing node installed or any external dependencies).

## Snapshots

Expand Down Expand Up @@ -202,7 +191,6 @@ File structure:

```
root_folder
| --- paima-sdk
| --- paima-engine-{linux|macos}
| --- packaged
| --- endpoints.cjs
Expand Down
6 changes: 3 additions & 3 deletions docs/home/1-setup/4-environment-config-values.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sidebar_position: 4

# Environment Configuration Variables

The following is a list of possible environment variables that can be configured for your project. These variables are read in the ENV class, located in `paima-sdk/paima-utils/config.js`. Please refer to that file for more information on default values.
The following is a list of possible environment variables that can be configured for your project. These variables are read in the ENV class, located in `@paima/utils/config.js`. Please refer to that file for more information on default values.

## Required Variables

Expand Down Expand Up @@ -42,7 +42,7 @@ This section includes optional environment variables that have sensible default
- `ENABLE_DRY_RUN`: Adds a `GET /dry_run` endpoint for input testing. Use it to post game inputs to validate them without modifying the game state.
- `DEFAULT_FUNNEL_GROUP_SIZE`: The number of blocks queried in one funnel sync step. If not set, a value of 100 is used. Generally no need to change this value.
- `NODE_ENV`: Used across modules to determine which .env file to read (`.env.$NODE_ENV`). Must be set separately if needed.
- `FORCE_INVALID_PAIMA_DB_TABLE_DELETION`: Instead of failing during DB initialization, it deletes invalid tables and recreates them (without the previous content). If turned off, resync from scratch is needed after a major `paima-sdk` update that affects internal tables.
- `FORCE_INVALID_PAIMA_DB_TABLE_DELETION`: Instead of failing during DB initialization, it deletes invalid tables and recreates them (without the previous content). If turned off, resync from scratch is needed after a major `@paima/sdk` update that affects internal tables.
- `STORE_HISTORICAL_GAME_INPUTS`: If enabled, one of the internal tables stores all of the posted game inputs. Note that the table is currently accessible only through a direct DB connection.
- `POLLING_RATE`: The frequency at which to check for new block data. If not filled in, a value of `BLOCK_TIME - 0.1` is used.
- `STOP_BLOCKHEIGHT`: The block at which the funnel stops syncing. This can be useful during development or tests.
Expand All @@ -51,7 +51,7 @@ This section includes optional environment variables that have sensible default
## Other Variables

- `DEPLOYMENT`: was used in the past to determine how often new blocks are emitted. It is now _deprecated_ and replaced with `BLOCK_TIME`.
- `GAME_NODE_VERSION`: defined statically in paima-sdk. Check used to ensure your game node is running with a compatible version of paima-engine. After a major upgrade and necessary adjustments, you should adjust the version on your side.
- `GAME_NODE_VERSION`: defined statically in `@paima/sdk`. Check used to ensure your game node is running with a compatible version of paima-engine. After a major upgrade and necessary adjustments, you should adjust the version on your side.
- `NATIVE_NFT_SALE_PROXY`: used in the NFT LvlUp template. It represents the contract address for your NFT sale proxy. See [deploying-your-stateful-nft](./3-deploying-your-stateful-nft.md)
- [Chain data extensions](../3-react-to-events/2-chain-data-extensions/1-introduction.md):
- `DEFAULT_PRESYNC_STEP_SIZE`: number of blocks to process in each step during initial presync phase. If not provided, a value of 1000 is used. Generally no need to change this value.
Expand Down
14 changes: 7 additions & 7 deletions docs/home/2-read-write-L2-state/1-base-format.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ Paima has its own format for representing L2 data called Paima Concise that rese
Paima comes with two classes to help generate these bar-separated strings
```javascript
// create the bar-separated string
import { builder } from 'paima-engine/paima-concise';
import { builder } from '@paimas/sdk/concise';
// parse the bar-separated string
import { consumer } from 'paima-engine/paima-concise';
import { consumer } from '@paima/sdk/concise';
```

## Read data
Expand All @@ -28,8 +28,8 @@ We allow defining more complex grammars on top of this notation using `PaimaPars
2. Define how to parse tokens in this grammar (recursively defined)

```typescript
import type { ParserRecord } from 'paima-sdk/paima-concise';
import { PaimaParser } from 'paima-sdk/paima-concise';
import type { ParserRecord } from '@paima/concise';
import { PaimaParser } from '@paima/sdk/concise';

// First, define your grammar which Paima will turn into EBNF form internally
const myGrammar = `
Expand Down Expand Up @@ -113,7 +113,7 @@ If you want to define your own parse functions, we suggest the [parsimmon](https

```typescript
import P from 'parsimmon';
import { consumer } from 'paima-engine/paima-concise';
import { consumer } from '@paima/sdk/concise';

const pRoundNumber = P.digits.map(Number).chain(n => {
if (n >= 1 && n <= 1000) return P.succeed(n);
Expand Down Expand Up @@ -164,13 +164,13 @@ The `PaimaParser` grammar supports UTF8, but generally has the following reserve
Writing data is much simpler

```typescript
import { builder } from 'paima-engine/paima-concise';
import { builder } from '@paima/sdk/concise';
import {
awaitBlock,
getActiveAddress,
PaimaMiddlewareErrorCode,
postConciseData,
} from 'paima-sdk/paima-mw-core';
} from '@paima/sdk/mw-core';


const conciseBuilder = builder.initialize();
Expand Down
8 changes: 4 additions & 4 deletions docs/home/2-read-write-L2-state/3-error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ Errors are unavoidable. Notably, be sure to take into accounts the following err
To handle errors, Paima has a system to allow define error codes for your application that extend the built-in error handling in Paima

```typescript
import type { ErrorMessageFxn } from 'paima-sdk/paima-utils';
import { buildErrorCodeTranslator } from 'paima-sdk/paima-utils';
import type { EndpointErrorFxn } from 'paima-sdk/paima-mw-core';
import type { ErrorMessageFxn } from '@paima/sdk/utils';
import { buildErrorCodeTranslator } from '@paima/sdk/utils';
import type { EndpointErrorFxn } from '@paima/sdk/mw-core';
import {
PaimaMiddlewareErrorCode,
PAIMA_MIDDLEWARE_ERROR_MESSAGES,
buildAbstractEndpointErrorFxn,
} from 'paima-sdk/paima-mw-core';
} from '@paima/sdk/mw-core';

export const enum MiddlewareErrorCode {
// start your error codes after the reserved namespace for Paima Engine's internal system
Expand Down
2 changes: 1 addition & 1 deletion docs/home/4-randomness/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Seeds such as those stored in blocks can be combined with a utility class called
Note this also means that you can to be careful using Prando if your game is leveraging [parallelism](../2-read-write-L2-state/2-parallelism.md) or optimistic updates.

```typescript
import Prando from '@paima/prando';
import Prando from '@paima/sdk/prando';

const prando = new Prando(block.seed);
const diceRoll = prando.nextInt(1, 6);
Expand Down
2 changes: 1 addition & 1 deletion docs/home/6-releasing-a-game/2-versioning.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ TBD. This is still in development: https://github.com/PaimaStudios/paima-engine/
It's up to you as a developer to check if the versions match in the place that makes the most sense for your game, and handle it the way you want.

```typescript
import { localRemoteVersionsCompatible } from 'paima-sdk/paima-mw-core';
import { localRemoteVersionsCompatible } from '@paima/sdk/mw-core';

async function someAction() {
// check if versions match
Expand Down

0 comments on commit 4ae5cf5

Please sign in to comment.