Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Erc6551 CDE support in Paima Engine #236

Merged
merged 13 commits into from
Oct 24, 2023
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# runs-on: ${{ matrix.os }}
# env:
# NODE_CACHE: 'npm'
# PARALLEL: 1
# NX_PARALLEL: 1

# strategy:
# fail-fast: false
Expand Down
4 changes: 2 additions & 2 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = [
},
},
{
files: ['**/*.{ts,tsx,cts}'],
files: ['**/*.{ts,tsx,cts,mts}'],
languageOptions: {
parser: typescriptEslintParser,
parserOptions: {
Expand All @@ -45,7 +45,7 @@ module.exports = [
},
},
{
files: ['**/*.{ts,tsx,cts}'],
files: ['**/*.{ts,tsx,cts,mts}'],
rules: {
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
Expand Down
16 changes: 16 additions & 0 deletions jest.preset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// const { getJestProjects } = require('@nx/jest');

module.exports = {
verbose: true,
resolver: '@nx/jest/plugins/resolver',
extensionsToTreatAsEsm: ['.ts'],
transform: {
'^.+\\.ts$': ['ts-jest', { useESM: true, }],
},
transformIgnorePatterns: [
'<rootDir>/node_modules/',
],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
};
8 changes: 7 additions & 1 deletion nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@
"dependsOn": ["build", "^build"]
},
"test": {
"dependsOn": ["^build"]
"dependsOn": ["^build"],
"inputs": ["default", "^default", "{workspaceRoot}/jest.preset.js"],
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "{projectRoot}/jest.config.js",
"passWithNoTests": true
}
},
"build": {
"dependsOn": ["^build"]
Expand Down
7,203 changes: 2,576 additions & 4,627 deletions package-lock.json

Large diffs are not rendered by default.

27 changes: 17 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,25 @@
"prepare": "husky install",
"lint:configs": "ts-node -P ./tsconfig.base.json ./tools/scripts/check-implicit-dependencies.ts",
"lint:versions": "syncpack list-mismatches",
"lint": "npm run prettier && npx nx affected --target=lint:eslint --parallel=${PARALLEL:-3} && npm run lint:configs && npm run lint:versions",
"cilint": "npm run cprettier && npx nx affected --target=lint:eslint --parallel=${PARALLEL:-3} && npm run lint:configs && npm run lint:versions",
"lint": "npm run prettier && npx nx affected --target=lint:eslint --parallel=${NX_PARALLEL:-3} && npm run lint:configs && npm run lint:versions",
"cilint": "npm run cprettier && npx nx affected --target=lint:eslint --parallel=${NX_PARALLEL:-3} && npm run lint:configs && npm run lint:versions",
"cprettier": "prettier --plugin=prettier-plugin-solidity --ignore-path ./.prettierignore --check '**/*.{sol,ts,tsx}'",
"prettier": "prettier --plugin=prettier-plugin-solidity --ignore-path ./.prettierignore --write '**/*.{sol,ts,tsx}'",
"prebuild": "npx nx run-many --parallel=${PARALLEL:-3} -t prebuild",
"build": "npm run lint:configs && npx nx run-many --parallel=${PARALLEL:-3} -t build",
"test": "npm run lint:configs && npx nx run-many --parallel=${PARALLEL:-3} -t test",
"prebuild": "npx nx run-many --parallel=${NX_PARALLEL:-3} -t prebuild",
"build": "npm run lint:configs && npx nx run-many --parallel=${NX_PARALLEL:-3} -t build",
"test": "npm run lint:configs && npx nx run-many --parallel=${NX_PARALLEL:-3} -t test",
"release:lib": "./wipe.sh && sh ./tools/scripts/bump-version.sh && npm run build && npm run lint && npm run test && read -p 'Enter OTP: ' otp && export NPM_CONFIG_OTP=$otp && npx nx release publish -g paima-sdk",
"release:bin": "./wipe.sh && npm run lint:configs && npx nx run-many --parallel=${PARALLEL:-3} -t release && mkdir -p ./bin && cp -r ./packages/engine/paima-standalone/packaged/@standalone/* ./bin"
"release:bin": "./wipe.sh && npm run lint:configs && npx nx run-many --parallel=${NX_PARALLEL:-3} -t release && mkdir -p ./bin && cp -r ./packages/engine/paima-standalone/packaged/@standalone/* ./bin"
},
"devDependencies": {
"@eslint/eslintrc": "^2.1.2",
"@eslint/js": "~8.50.0",
"@nx/esbuild": "16.9.1",
"@nx/js": "^16.9.1",
"@nx/jest": "16.10.0",
"@nx/js": "16.10.0",
"@nx/linter": "^16.9.1",
"@types/eslint-plugin-prettier": "^3.1.1",
"@types/jest": "^29.4.0",
"@types/node": "^18.17.1",
"@typescript-eslint/eslint-plugin": "^6.7.3",
"@typescript-eslint/parser": "^6.7.3",
Expand All @@ -35,19 +37,24 @@
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"husky": "^8.0.3",
"jest": "^29.4.1",
"json5": "^2.2.3",
"nx": "16.9.1",
"prettier": "^3.0.3",
"prettier-plugin-organize-imports": "^3.2.3",
"prettier-plugin-solidity": "^1.1.3",
"syncpack": "^11.2.1",
"typescript": "^5.2.2",
"ts-jest": "^29.1.1"
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
},
"overrides": {
"web3-eth-contract": "1.10.0"
},
"workspaces": [
"./packages/*/*"
]
],
"dependencies": {
"assert-never": "^1.2.1"
}
}
7 changes: 7 additions & 0 deletions packages/batcher/address-validator/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type { BatchedSubunit } from '@paima/concise';
import { CryptoManager } from '@paima/crypto';
import { createMessageForBatcher } from '@paima/concise';
import { initWeb3, AddressType, getReadNamespaces } from '@paima/utils';
import assertNever from 'assert-never';

class PaimaAddressValidator {
private web3: Web3 | undefined;
Expand Down Expand Up @@ -75,7 +76,10 @@ class PaimaAddressValidator {
return await CryptoManager.Polkadot().verifyAddress(address);
case AddressType.ALGORAND:
return await CryptoManager.Algorand().verifyAddress(address);
case AddressType.UNKNOWN:
return false;
default:
assertNever(addressType, true);
return false;
}
};
Expand Down Expand Up @@ -117,7 +121,10 @@ class PaimaAddressValidator {
message,
input.userSignature
);
case AddressType.UNKNOWN:
return false;
default:
assertNever(addressType, true);
return false;
}
};
Expand Down
9 changes: 0 additions & 9 deletions packages/batcher/batcher-standalone/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
{
"extends": "../tsconfig.json",
"files": [],
"references": [
{ "path": "../db" },
{ "path": "../utils" },
{ "path": "../address-validator" },
{ "path": "../game-input-validator" },
{ "path": "../batcher-transaction-poster" },
{ "path": "../webserver" },
{ "path": "../runtime" }
]
}
4 changes: 4 additions & 0 deletions packages/batcher/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { TruffleConnector } from '@paima/providers';
import { GenericRejectionCode } from './types.js';

import { AddressType, wait } from '@paima/utils';
import assertNever from 'assert-never';

export * from './config.js';
export * from './config-validation.js';
Expand Down Expand Up @@ -71,7 +72,10 @@ export function addressTypeName(addressType: AddressType): string {
return 'Astar / Polkadot';
case AddressType.ALGORAND:
return 'Algorand';
case AddressType.UNKNOWN:
return 'Unknown address type';
default:
assertNever(addressType, true);
return 'Unknown address type';
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts/nft/deploy-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
},
"Erc20NftSale": {
"currencies": {
"USDT": "0x7d3B9AeC4F57C1F10bfd1668612c3E586498E4BE",
"USDC": "0x63D403E115213A66fE41a8605FFB1af8ab481593"
"USDT": "",
"USDC": ""
},
"owner": ""
},
Expand Down
8 changes: 4 additions & 4 deletions packages/contracts/nft/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ function main() {
function getTargetNetwork() {
if [ -z ${TARGET_NETWORK+x} ]; then
echo ""
echo "Which network would you like to deploy to?"
echo " 1. Milkomeda C1 Mainnet"
echo " 2. Milkomeda C1 Testnet"
echo "Which network from your truffle config would you like to deploy to?"
echo " 1. Mainnet"
echo " 2. Testnet"
read -p "Please enter your choice (1-2): " choice

case $choice in
Expand All @@ -22,7 +22,7 @@ function getTargetNetwork() {
TARGET_NETWORK="testnet"
;;
*)
echo "Invalid choice! Defaulting to Milkomeda C1 Testnet."
echo "Invalid choice! Defaulting to Testnet."
TARGET_NETWORK="testnet"
;;
esac
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ module.exports = async function (deployer, network, accounts) {

const currenciesArray = [];
for (const key in currencies) {
currenciesArray.push(currencies[key]);
// filter out default "" values
if (currencies[key].length > 0) {
currenciesArray.push(currencies[key]);
}
}

await deployer.deploy(proxy, nftSaleAddress, currenciesArray, owner, nftAddress, price.toString(10));
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/nft/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
"@truffle/hdwallet-provider": "^2.1.15",
"@types/mocha": "^9.1.1",
"truffle": "^5.11.5",
"ts-node": "^10.8.1"
"ts-node": "^10.9.1"
}
}
3 changes: 3 additions & 0 deletions packages/contracts/nft/src/BaseState.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.13;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract BaseState {
Expand Down
2 changes: 2 additions & 0 deletions packages/contracts/nft/src/ERC1967.sol
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.7;

import "@openzeppelin/contracts/utils/Address.sol";
Expand Down
2 changes: 2 additions & 0 deletions packages/contracts/nft/src/Erc20NftSale.sol
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.13;

import "./Nft.sol";
Expand Down
2 changes: 2 additions & 0 deletions packages/contracts/nft/src/GenericPayment.sol
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.13;

import "./ERC1967.sol";
Expand Down
2 changes: 2 additions & 0 deletions packages/contracts/nft/src/NativeNftSale.sol
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.13;

import "./Nft.sol";
Expand Down
3 changes: 3 additions & 0 deletions packages/contracts/nft/src/Nft.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.13;

import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
Expand Down
2 changes: 2 additions & 0 deletions packages/contracts/nft/src/NftType.sol
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.13;

enum NftType {
Expand Down
2 changes: 2 additions & 0 deletions packages/contracts/nft/src/NftTypeMapper.sol
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.13;

import {NftType} from "./NftType.sol";
Expand Down
2 changes: 2 additions & 0 deletions packages/contracts/nft/src/Proxy/GenericPaymentProxy.sol
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.7;

import "../ERC1967.sol";
Expand Down
2 changes: 2 additions & 0 deletions packages/contracts/nft/src/Proxy/NativeProxy.sol
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.7;

import "../ERC1967.sol";
Expand Down
2 changes: 2 additions & 0 deletions packages/contracts/nft/src/Proxy/Proxy.sol
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.7;

import "../ERC1967.sol";
Expand Down
3 changes: 3 additions & 0 deletions packages/contracts/nft/src/State.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.13;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract State {
Expand Down
2 changes: 2 additions & 0 deletions packages/contracts/nft/src/dev/ERC721Dev.sol
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.13;

import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
Expand Down
2 changes: 2 additions & 0 deletions packages/contracts/nft/src/dev/Erc20Dev.sol
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.13;

import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
Expand Down
2 changes: 2 additions & 0 deletions packages/contracts/nft/src/dev/NativeNftSaleUpgradeDev.sol
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.13;

import "../NativeNftSale.sol";
Expand Down
2 changes: 2 additions & 0 deletions packages/contracts/nft/src/dev/NftSaleUpgradeDev.sol
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.13;

import "../Erc20NftSale.sol";
Expand Down
2 changes: 2 additions & 0 deletions packages/contracts/nft/src/dev/Token.sol
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.13;

import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
Expand Down
2 changes: 2 additions & 0 deletions packages/contracts/nft/src/dev/UpgradeDev.sol
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.13;

/// @dev For testing upgradeability.
Expand Down
8 changes: 4 additions & 4 deletions packages/contracts/paima-l2-contract/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ function main() {
function getTargetNetwork() {
if [ -z ${TARGET_NETWORK+x} ]; then
echo ""
echo "Which network would you like to deploy to?"
echo " 1. Milkomeda C1 Mainnet"
echo " 2. Milkomeda C1 Testnet"
echo "Which network from your truffle config would you like to deploy to??"
echo " 1. Mainnet"
echo " 2. Testnet"
read -p "Please enter your choice (1-2): " choice

case $choice in
Expand All @@ -22,7 +22,7 @@ function getTargetNetwork() {
TARGET_NETWORK="testnet"
;;
*)
echo "Invalid choice! Defaulting to Milkomeda C1 Testnet."
echo "Invalid choice! Defaulting to Testnet."
TARGET_NETWORK="testnet"
;;
esac
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/paima-l2-contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
"chai": "^4.3.6",
"mocha": "^9.2.2",
"truffle": "^5.11.5",
"ts-node": "^10.8.1"
"ts-node": "^10.9.1"
}
}
1 change: 1 addition & 0 deletions packages/engine/paima-funnel/src/cde/erc20Deposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default async function getCdeData(
// https://github.com/dethcrypto/TypeChain/issues/767
const events = (await timeout(
extension.contract.getPastEvents('Transfer', {
filter: { to: extension.depositAddress.toLocaleLowerCase() },
fromBlock: fromBlock,
toBlock: toBlock,
}),
Expand Down
Loading