Skip to content

Commit

Permalink
Merge pull request #179 from PaimaStudios/generic-cde
Browse files Browse the repository at this point in the history
Generic CDE
  • Loading branch information
robkorn authored Jun 30, 2023
2 parents 83633ef + 1e8268f commit 899c553
Show file tree
Hide file tree
Showing 36 changed files with 1,032 additions and 136 deletions.
158 changes: 133 additions & 25 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@
"typescript": "^4.8.4"
},
"dependencies": {
"@pgtyped/cli": "^1.0.2",
"@pgtyped/query": "^1.0.1",
"pg": "^8.8.0",
"pg-tx": "^1.0.1",
"web3": "1.8.1"
Expand Down
3 changes: 3 additions & 0 deletions paima-db/migrations/down.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
DROP TABLE cde_erc20_data;
DROP TABLE cde_erc721_data;
DROP TABLE cde_erc20_deposit_data;
DROP TABLE cde_generic_data;
DROP TABLE cde_config_generic;
DROP TABLE cde_config_erc20_deposit;
DROP TABLE chain_data_extensions;
DROP TABLE cde_tracking;
DROP TABLE historical_game_inputs;
Expand Down
24 changes: 21 additions & 3 deletions paima-db/migrations/up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,18 @@ CREATE TABLE chain_data_extensions (
cde_name TEXT NOT NULL,
contract_address TEXT NOT NULL,
start_blockheight INTEGER NOT NULL,
scheduled_prefix TEXT,
deposit_address TEXT
scheduled_prefix TEXT
);

CREATE TABLE cde_config_erc20_deposit (
cde_id INTEGER PRIMARY KEY,
deposit_address TEXT NOT NULL
);

CREATE TABLE cde_config_generic (
cde_id INTEGER PRIMARY KEY,
event_signature TEXT NOT NULL,
contract_abi TEXT NOT NULL
);

CREATE TABLE cde_erc20_data (
Expand All @@ -57,4 +67,12 @@ CREATE TABLE cde_erc20_deposit_data (
wallet_address TEXT NOT NULL,
total_deposited TEXT NOT NULL,
PRIMARY KEY (cde_id, wallet_address)
);
);

CREATE TABLE cde_generic_data (
cde_id INTEGER NOT NULL,
id SERIAL,
block_height INTEGER NOT NULL,
event_data JSON NOT NULL,
PRIMARY KEY (cde_id, id)
);
1 change: 1 addition & 0 deletions paima-db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"lint": "prettier --write '**/*.ts'"
},
"devDependencies": {
"@pgtyped/cli": "^1.0.2",
"@types/node": "^17.0.25"
},
"dependencies": {
Expand Down
8 changes: 8 additions & 0 deletions paima-db/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,17 @@ export * from './sql/nonces.queries';
export * from './sql/historical.queries';
export * from './sql/cde-tracking.queries';
export * from './sql/extensions.queries';
// pgtyped keeps regenerating the Json type, so we can't just export * or we get conflicts:
export {
getCdeConfigGeneric,
getSpecificCdeConfigGeneric,
registerCdeConfigGeneric,
} from './sql/cde-config-generic.queries';
export * from './sql/cde-config-erc20-deposit.queries';
export * from './sql/cde-erc20.queries';
export * from './sql/cde-erc721.queries';
export * from './sql/cde-erc20-deposit.queries';
export * from './sql/cde-generic.queries';

export {
tx,
Expand Down
68 changes: 65 additions & 3 deletions paima-db/src/paima-tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ CREATE TABLE chain_data_extensions (
cde_name TEXT NOT NULL,
contract_address TEXT NOT NULL,
start_blockheight INTEGER NOT NULL,
scheduled_prefix TEXT,
deposit_address TEXT
scheduled_prefix TEXT
);
`;

Expand All @@ -123,12 +122,49 @@ const TABLE_DATA_CDE: TableData = {
['contract_address', 'text', 'NO', ''],
['start_blockheight', 'integer', 'NO', ''],
['scheduled_prefix', 'text', 'YES', ''],
['deposit_address', 'text', 'YES', ''],
]),
serialColumns: [],
creationQuery: QUERY_CREATE_TABLE_CDE,
};

const QUERY_CREATE_TABLE_CDE_CONFIG_ERC20_DEPOSIT = `
CREATE TABLE cde_config_erc20_deposit (
cde_id INTEGER PRIMARY KEY,
deposit_address TEXT NOT NULL
);
`;

const TABLE_DATA_CDE_CONFIG_ERC20_DEPOSIT: TableData = {
tableName: 'cde_config_erc20_deposit',
primaryKeyColumns: ['cde_id'],
columnData: packTuples([
['cde_id', 'integer', 'NO', ''],
['deposit_address', 'text', 'NO', ''],
]),
serialColumns: [],
creationQuery: QUERY_CREATE_TABLE_CDE_CONFIG_ERC20_DEPOSIT,
};

const QUERY_CREATE_TABLE_CDE_CONFIG_GENERIC = `
CREATE TABLE cde_config_generic (
cde_id INTEGER PRIMARY KEY,
event_signature TEXT NOT NULL,
contract_abi TEXT NOT NULL
);
`;

const TABLE_DATA_CDE_CONFIG_GENERIC: TableData = {
tableName: 'cde_config_generic',
primaryKeyColumns: ['cde_id'],
columnData: packTuples([
['cde_id', 'integer', 'NO', ''],
['event_signature', 'text', 'NO', ''],
['contract_abi', 'text', 'NO', ''],
]),
serialColumns: [],
creationQuery: QUERY_CREATE_TABLE_CDE_CONFIG_GENERIC,
};

const QUERY_CREATE_TABLE_CDE_ERC20 = `
CREATE TABLE cde_erc20_data (
cde_id INTEGER NOT NULL,
Expand Down Expand Up @@ -192,14 +228,40 @@ const TABLE_DATA_CDE_ERC20_DEPOSIT: TableData = {
creationQuery: QUERY_CREATE_TABLE_CDE_ERC20_DEPOSIT,
};

const QUERY_CREATE_TABLE_CDE_GENERIC_DATA = `
CREATE TABLE cde_generic_data (
cde_id INTEGER NOT NULL,
id SERIAL,
block_height INTEGER NOT NULL,
event_data JSON NOT NULL,
PRIMARY KEY (cde_id, id)
);
`;

const TABLE_DATA_CDE_GENERIC_DATA: TableData = {
tableName: 'cde_generic_data',
primaryKeyColumns: ['cde_id', 'id'],
columnData: packTuples([
['cde_id', 'integer', 'NO', ''],
['id', 'integer', 'NO', ''],
['block_height', 'integer', 'NO', ''],
['event_data', 'json', 'NO', ''],
]),
serialColumns: ['id'],
creationQuery: QUERY_CREATE_TABLE_CDE_GENERIC_DATA,
};

export const TABLES: TableData[] = [
TABLE_DATA_BLOCKHEIGHTS,
TABLE_DATA_NONCES,
TABLE_DATA_SCHEDULED,
TABLE_DATA_HISTORICAL,
TABLE_DATA_CDE_TRACKING,
TABLE_DATA_CDE,
TABLE_DATA_CDE_CONFIG_ERC20_DEPOSIT,
TABLE_DATA_CDE_CONFIG_GENERIC,
TABLE_DATA_CDE_ERC20,
TABLE_DATA_CDE_ERC721,
TABLE_DATA_CDE_ERC20_DEPOSIT,
TABLE_DATA_CDE_GENERIC_DATA,
];
90 changes: 90 additions & 0 deletions paima-db/src/sql/cde-config-erc20-deposit.queries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/** Types generated for queries found in "src/sql/cde-config-erc20-deposit.sql" */
import { PreparedQuery } from '@pgtyped/query';

/** 'GetCdeConfigErc20Deposit' parameters type */
export type IGetCdeConfigErc20DepositParams = void;

/** 'GetCdeConfigErc20Deposit' return type */
export interface IGetCdeConfigErc20DepositResult {
cde_id: number;
deposit_address: string;
}

/** 'GetCdeConfigErc20Deposit' query type */
export interface IGetCdeConfigErc20DepositQuery {
params: IGetCdeConfigErc20DepositParams;
result: IGetCdeConfigErc20DepositResult;
}

const getCdeConfigErc20DepositIR: any = {"usedParamSet":{},"params":[],"statement":"SELECT * FROM cde_config_erc20_deposit"};

/**
* Query generated from SQL:
* ```
* SELECT * FROM cde_config_erc20_deposit
* ```
*/
export const getCdeConfigErc20Deposit = new PreparedQuery<IGetCdeConfigErc20DepositParams,IGetCdeConfigErc20DepositResult>(getCdeConfigErc20DepositIR);


/** 'GetSpecificCdeConfigErc20Deposit' parameters type */
export interface IGetSpecificCdeConfigErc20DepositParams {
cde_id: number | null | void;
}

/** 'GetSpecificCdeConfigErc20Deposit' return type */
export interface IGetSpecificCdeConfigErc20DepositResult {
cde_id: number;
deposit_address: string;
}

/** 'GetSpecificCdeConfigErc20Deposit' query type */
export interface IGetSpecificCdeConfigErc20DepositQuery {
params: IGetSpecificCdeConfigErc20DepositParams;
result: IGetSpecificCdeConfigErc20DepositResult;
}

const getSpecificCdeConfigErc20DepositIR: any = {"usedParamSet":{"cde_id":true},"params":[{"name":"cde_id","required":false,"transform":{"type":"scalar"},"locs":[{"a":54,"b":60}]}],"statement":"SELECT * FROM cde_config_erc20_deposit\nWHERE cde_id = :cde_id"};

/**
* Query generated from SQL:
* ```
* SELECT * FROM cde_config_erc20_deposit
* WHERE cde_id = :cde_id
* ```
*/
export const getSpecificCdeConfigErc20Deposit = new PreparedQuery<IGetSpecificCdeConfigErc20DepositParams,IGetSpecificCdeConfigErc20DepositResult>(getSpecificCdeConfigErc20DepositIR);


/** 'RegisterCdeConfigErc20Deposit' parameters type */
export interface IRegisterCdeConfigErc20DepositParams {
cde_id: number;
deposit_address: string;
}

/** 'RegisterCdeConfigErc20Deposit' return type */
export type IRegisterCdeConfigErc20DepositResult = void;

/** 'RegisterCdeConfigErc20Deposit' query type */
export interface IRegisterCdeConfigErc20DepositQuery {
params: IRegisterCdeConfigErc20DepositParams;
result: IRegisterCdeConfigErc20DepositResult;
}

const registerCdeConfigErc20DepositIR: any = {"usedParamSet":{"cde_id":true,"deposit_address":true},"params":[{"name":"cde_id","required":true,"transform":{"type":"scalar"},"locs":[{"a":85,"b":92}]},{"name":"deposit_address","required":true,"transform":{"type":"scalar"},"locs":[{"a":99,"b":115}]}],"statement":"INSERT INTO cde_config_erc20_deposit(\n cde_id,\n deposit_address\n) VALUES (\n :cde_id!,\n :deposit_address!\n)"};

/**
* Query generated from SQL:
* ```
* INSERT INTO cde_config_erc20_deposit(
* cde_id,
* deposit_address
* ) VALUES (
* :cde_id!,
* :deposit_address!
* )
* ```
*/
export const registerCdeConfigErc20Deposit = new PreparedQuery<IRegisterCdeConfigErc20DepositParams,IRegisterCdeConfigErc20DepositResult>(registerCdeConfigErc20DepositIR);


15 changes: 15 additions & 0 deletions paima-db/src/sql/cde-config-erc20-deposit.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* @name getCdeConfigErc20Deposit */
SELECT * FROM cde_config_erc20_deposit;

/* @name getSpecificCdeConfigErc20Deposit */
SELECT * FROM cde_config_erc20_deposit
WHERE cde_id = :cde_id;

/* @name registerCdeConfigErc20Deposit */
INSERT INTO cde_config_erc20_deposit(
cde_id,
deposit_address
) VALUES (
:cde_id!,
:deposit_address!
);
95 changes: 95 additions & 0 deletions paima-db/src/sql/cde-config-generic.queries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/** Types generated for queries found in "src/sql/cde-config-generic.sql" */
import { PreparedQuery } from '@pgtyped/query';

/** 'GetCdeConfigGeneric' parameters type */
export type IGetCdeConfigGenericParams = void;

/** 'GetCdeConfigGeneric' return type */
export interface IGetCdeConfigGenericResult {
cde_id: number;
contract_abi: string;
event_signature: string;
}

/** 'GetCdeConfigGeneric' query type */
export interface IGetCdeConfigGenericQuery {
params: IGetCdeConfigGenericParams;
result: IGetCdeConfigGenericResult;
}

const getCdeConfigGenericIR: any = {"usedParamSet":{},"params":[],"statement":"SELECT * FROM cde_config_generic"};

/**
* Query generated from SQL:
* ```
* SELECT * FROM cde_config_generic
* ```
*/
export const getCdeConfigGeneric = new PreparedQuery<IGetCdeConfigGenericParams,IGetCdeConfigGenericResult>(getCdeConfigGenericIR);


/** 'GetSpecificCdeConfigGeneric' parameters type */
export interface IGetSpecificCdeConfigGenericParams {
cde_id: number | null | void;
}

/** 'GetSpecificCdeConfigGeneric' return type */
export interface IGetSpecificCdeConfigGenericResult {
cde_id: number;
contract_abi: string;
event_signature: string;
}

/** 'GetSpecificCdeConfigGeneric' query type */
export interface IGetSpecificCdeConfigGenericQuery {
params: IGetSpecificCdeConfigGenericParams;
result: IGetSpecificCdeConfigGenericResult;
}

const getSpecificCdeConfigGenericIR: any = {"usedParamSet":{"cde_id":true},"params":[{"name":"cde_id","required":false,"transform":{"type":"scalar"},"locs":[{"a":48,"b":54}]}],"statement":"SELECT * FROM cde_config_generic\nWHERE cde_id = :cde_id"};

/**
* Query generated from SQL:
* ```
* SELECT * FROM cde_config_generic
* WHERE cde_id = :cde_id
* ```
*/
export const getSpecificCdeConfigGeneric = new PreparedQuery<IGetSpecificCdeConfigGenericParams,IGetSpecificCdeConfigGenericResult>(getSpecificCdeConfigGenericIR);


/** 'RegisterCdeConfigGeneric' parameters type */
export interface IRegisterCdeConfigGenericParams {
cde_id: number;
contract_abi: string;
event_signature: string;
}

/** 'RegisterCdeConfigGeneric' return type */
export type IRegisterCdeConfigGenericResult = void;

/** 'RegisterCdeConfigGeneric' query type */
export interface IRegisterCdeConfigGenericQuery {
params: IRegisterCdeConfigGenericParams;
result: IRegisterCdeConfigGenericResult;
}

const registerCdeConfigGenericIR: any = {"usedParamSet":{"cde_id":true,"event_signature":true,"contract_abi":true},"params":[{"name":"cde_id","required":true,"transform":{"type":"scalar"},"locs":[{"a":97,"b":104}]},{"name":"event_signature","required":true,"transform":{"type":"scalar"},"locs":[{"a":111,"b":127}]},{"name":"contract_abi","required":true,"transform":{"type":"scalar"},"locs":[{"a":134,"b":147}]}],"statement":"INSERT INTO cde_config_generic(\n cde_id,\n event_signature,\n contract_abi\n) VALUES (\n :cde_id!,\n :event_signature!,\n :contract_abi!\n)"};

/**
* Query generated from SQL:
* ```
* INSERT INTO cde_config_generic(
* cde_id,
* event_signature,
* contract_abi
* ) VALUES (
* :cde_id!,
* :event_signature!,
* :contract_abi!
* )
* ```
*/
export const registerCdeConfigGeneric = new PreparedQuery<IRegisterCdeConfigGenericParams,IRegisterCdeConfigGenericResult>(registerCdeConfigGenericIR);


Loading

0 comments on commit 899c553

Please sign in to comment.