Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 0 additions & 43 deletions .env.devnet

This file was deleted.

37 changes: 0 additions & 37 deletions .env.mainnet

This file was deleted.

2 changes: 1 addition & 1 deletion api/src/controllers/allConfigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class userConfigsController extends Controller {
@Get()
public async get(@Query() creator: string): Promise<UserConfigsResponse> {
const pool = requirePool();
creator = (await getMainAddress(creator, pool)).address;
//creator = (await getMainAddress(creator, pool)).address;
const configs = await getUserConfigs.run({ creator }, pool);
return { configs };
}
Expand Down
2 changes: 1 addition & 1 deletion api/src/controllers/openLobbies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class openLobbiesController extends Controller {
throw new ValidateError({ count: { message: 'invalid number' } }, '');
}

wallet = (await getMainAddress(wallet, pool)).address;
//wallet = (await getMainAddress(wallet, pool)).address;
const p = valPage.right;
const c = valCount.right;
const offset = (p - 1) * c;
Expand Down
2 changes: 1 addition & 1 deletion api/src/controllers/searchOpenLobbies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class SearchOpenLobbiesController extends Controller {
if (searchQuery.length < MIN_SEARCH_LENGTH || searchQuery.length > LOBBY_ID_LENGTH)
return emptyResponse;

wallet = (await getMainAddress(wallet, pool)).address;
//wallet = (await getMainAddress(wallet, pool)).address;

if (searchQuery.length == LOBBY_ID_LENGTH) {
const lobbies = await getOpenLobbyById.run({ searchQuery, wallet }, pool);
Expand Down
2 changes: 1 addition & 1 deletion api/src/controllers/userFinishedLobbies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class UserFinishedLobbiesController extends Controller {
}

// after typecheck, valid data output is given in .right
wallet = (await getMainAddress(wallet, pool)).address;
//wallet = (await getMainAddress(wallet, pool)).address;
const p = valPage.right;
const c = valCount.right;
const offset = (p - 1) * c;
Expand Down
2 changes: 1 addition & 1 deletion api/src/controllers/userLobbies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class UserLobbiesController extends Controller {
}

// after typecheck, valid data output is given in .right
wallet = (await getMainAddress(wallet, pool)).address;
//wallet = (await getMainAddress(wallet, pool)).address;
const p = valPage.right;
const c = valCount.right;
const offset = (p - 1) * c;
Expand Down
2 changes: 1 addition & 1 deletion api/src/controllers/userLobbiesBlockheight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class UserLobbiesBlockheightController extends Controller {
@Get()
public async get(@Query() wallet: string, @Query() blockHeight: number): Promise<UserLobbiesBlockheightResponse> {
const pool = requirePool();
wallet = (await getMainAddress(wallet, pool)).address;
//wallet = (await getMainAddress(wallet, pool)).address;
const valBH = psqlNum.decode(blockHeight);
if (isLeft(valBH)) {
throw new ValidateError({ blockHeight: { message: 'invalid number' } }, '');
Expand Down
2 changes: 1 addition & 1 deletion api/src/controllers/userNFT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class userNFTController extends Controller {
@Get()
public async get(@Query() wallet: string): Promise<UserNftResponse> {
const pool = requirePool();
wallet = (await getMainAddress(wallet, pool)).address;
//wallet = (await getMainAddress(wallet, pool)).address;
const [nft] = await getLatestUserNft.run({ wallet }, pool);
return { nft };
}
Expand Down
2 changes: 1 addition & 1 deletion api/src/controllers/userStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class userStatsController extends Controller {
@Get()
public async get(@Query() wallet: string): Promise<UserStatsResponse> {
const pool = requirePool();
wallet = (await getMainAddress(wallet, pool)).address;
//wallet = (await getMainAddress(wallet, pool)).address;
const [stats] = await getUserStats.run({ wallet }, pool);
return { stats };
}
Expand Down
26 changes: 26 additions & 0 deletions backend/esbuildconfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { build } from 'esbuild';

await build({
outfile: 'build/index.bundle.js',
// JS output from previous compilation step used here instead of index.ts to have more control over the TS build process
entryPoints: ['build/index.js'],

bundle: true,
format: 'esm',
platform: 'node',

minify: true,
treeShaking: true,
sourcemap: true,
// source map is just for crash stack traces, so source content isn't needed
sourcesContent: false,

define: {
__dirname: 'import.meta.dirname',
__filename: 'import.meta.filename',
},

banner: {
js: "import { createRequire } from 'module'; const require = createRequire(import.meta.url);",
},
});
10 changes: 8 additions & 2 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@
"name": "@tower-defense/backend",
"version": "1.0.0",
"description": "",
"main": "build/index.js",
"types": "build/index.d.ts",
"type": "module",
"author": "",
"license": "ISC",
"scripts": {
"prepack": "(cd .. && npm run build) && node ./esbuildconfig.js && cp $(npm ls --parseable @dcspark/cardano-multiplatform-lib-nodejs | head -1)/cardano_multiplatform_lib_bg.wasm build/"
},
"files": [
"build/index.bundle.js",
"build/index.bundle.js.map",
"build/cardano_multiplatform_lib_bg.wasm"
],
"dependencies": {
"@paima/db": "5.0.0",
"@paima/executors": "^5.0.0",
Expand Down
2 changes: 1 addition & 1 deletion backend/src/stf/v2/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const createdLobby: ParserRecord<CreatedLobbyInput> = {
value => conciseFactionMap[value as RoleSettingConcise]
),
numOfRounds: PaimaParser.NumberParser(3, 1000),
roundLength: PaimaParser.DefaultRoundLength(parseInt(process.env.BLOCK_TIME || '4', 0)),
roundLength: PaimaParser.DefaultRoundLength(/* always in units of 2s regardless of real block speed */ 2),
isHidden: PaimaParser.TrueFalseParser(false),
map: PaimaParser.EnumParser(maps),
isPractice: PaimaParser.TrueFalseParser(false),
Expand Down
5 changes: 3 additions & 2 deletions backend/src/stf/v2/persist/lobby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { blankStats } from './stats.js';
import { practiceRound } from '../transition.js';
import { persistNewRound } from './match.js';
import { generateMatchState } from '@tower-defense/game-logic';
import { ENV } from '@paima/utils';

// Persist creation of a lobby
export function persistLobbyCreation(
Expand All @@ -34,7 +35,7 @@ export function persistLobbyCreation(
lobby_creator_token_id: tokenId,
creator_faction: inputData.creatorFaction,
num_of_rounds: inputData.numOfRounds,
round_length: inputData.roundLength,
round_length: inputData.roundLength * 2 / ENV.BLOCK_TIME, // convert from 2-second units to BLOCK_TIME-second units
current_round: 0,
creation_block_height: blockHeight,
map: inputData.map,
Expand Down Expand Up @@ -70,7 +71,7 @@ export function persistPracticeLobbyCreation(
lobby_creator_token_id: tokenId,
creator_faction: inputData.creatorFaction,
num_of_rounds: inputData.numOfRounds,
round_length: inputData.roundLength,
round_length: inputData.roundLength * 2 / ENV.BLOCK_TIME, // convert from 2-second units to BLOCK_TIME-second units
current_round: 0,
creation_block_height: blockHeight,
map: inputData.map,
Expand Down
23 changes: 19 additions & 4 deletions contracts/evm/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import 'hardhat-dependency-compiler';
import 'hardhat-interact';
import { task, type HardhatUserConfig } from 'hardhat/config';
import { type HardhatRuntimeEnvironment } from 'hardhat/types';
import * as dotenv from 'dotenv';

const xai: Record<string, string> = {};
dotenv.config({ path: '../../.env.xai', processEnv: xai });

const config: HardhatUserConfig = {
solidity: '0.8.20',
Expand All @@ -27,9 +31,18 @@ const config: HardhatUserConfig = {
chainId: 31337,
mining: {
auto: true,
interval: 2000,
// Xai runs at *approximately* 250ms per block, but if we ask Hardhat to
// produce multiple blocks per second, it pushes timestamps into the future
// instead of allowing them to repeat like Xai does, causing the emulated
// funnel to also run into the future, so we can't simulate Xai exactly.
interval: 1000,
},
},
xai: {
chainId: 660279,
url: 'https://xai-chain.net/rpc',
accounts: xai.DEPLOYER_PRIVATE_KEY ? [xai.DEPLOYER_PRIVATE_KEY] : [],
},
},
dependencyCompiler: {
paths: [
Expand Down Expand Up @@ -63,9 +76,11 @@ task('node').setAction(async (args, hre: HardhatRuntimeEnvironment, runSuper) =>
'ignition',
'deploy',
'./ignition/modules/deploy.ts',
'--parameters', './ignition/parameters.json',
'--network', 'localhost',
'--reset', // So we don't have to manually rm -rf the deploy journal.
'--parameters',
'./ignition/parameters.json',
'--network',
'localhost',
'--reset', // So we don't have to manually rm -rf the deploy journal.
],
{
stdio: 'inherit',
Expand Down
2 changes: 2 additions & 0 deletions contracts/evm/ignition/modules/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// A Hardhat module representing what should be deployed locally.
// Includes a Genesis Trainer contract so we have something to test against.
import { buildModule } from '@nomicfoundation/hardhat-ignition/modules';
import type { IgnitionModuleBuilder } from '@nomicfoundation/ignition-core';

Expand Down
12 changes: 12 additions & 0 deletions contracts/evm/ignition/modules/xai.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// A Hardhat module that represents what TD should actually deploy to Xai.
// Excludes Tarochi Genesis Trainers because that contract's deployment is
// not Tower Defense's responsibility.
import { buildModule } from '@nomicfoundation/hardhat-ignition/modules';
import type { IgnitionModuleBuilder } from '@nomicfoundation/ignition-core';

export default buildModule('L2Contract', (m: IgnitionModuleBuilder) => {
// https://github.com/NomicFoundation/hardhat-ignition/issues/673
const l2Contract = m.contract('PaimaL2Contract', [m.getAccount(0), 1]);

return { l2Contract };
});
1 change: 1 addition & 0 deletions contracts/evm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@nomicfoundation/hardhat-ignition-viem": "^0.15.1",
"@nomicfoundation/hardhat-toolbox-viem": "^3.0.0",
"@openzeppelin/contracts": "^5.0.2",
"dotenv": "^16.4.1",
"hardhat": "^2.19.4",
"hardhat-abi-exporter": "github:paimaStudios/hardhat-abi-exporter#export-ts-wrapper",
"hardhat-dependency-compiler": "^1.1.3",
Expand Down
16 changes: 16 additions & 0 deletions middleware/debug-build
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
# middleware/debug-build: copy paimaMiddleware.js, source map, and env.js into
# a Unity build output directory.
# $1 = where to put the files
# $NETWORK = what .env to use, default `localhost`
set -euo pipefail

dest="${1:?first argument should be destination directory}"
if ! test -f "$dest/index.html"; then
printf "destination directory should already contain 'index.html' from Unity build" >&2
exit 1
fi
set -x
npm -w middleware run build
cp middleware/packaged/paimaMiddleware.js{,.map} "$dest"
middleware/make-env-json ".env.${NETWORK:-localhost}" >"$dest/env.js"
31 changes: 0 additions & 31 deletions middleware/esbuildconfig.cjs

This file was deleted.

28 changes: 28 additions & 0 deletions middleware/esbuildconfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { NodeModulesPolyfillPlugin } from '@esbuild-plugins/node-modules-polyfill';
import { build } from 'esbuild';

await build({
outfile: 'packaged/paimaMiddleware.js',
// JS output from previous compilation step used here instead of index.ts to have more control over the TS build process
entryPoints: ['build/index.js'],

bundle: true,
format: 'esm',

minify: true,
treeShaking: true,
sourcemap: true,
// source map is for browser debugging, so include source content
sourcesContent: true,

define: {
global: 'window',
'process.env': 'PaimaProcessEnv',
},

plugins: [NodeModulesPolyfillPlugin()],

banner: {
js: "import PaimaProcessEnv from './env.js';",
},
});
Loading