Skip to content

Commit

Permalink
chore: start moving LSP2 in its own package
Browse files Browse the repository at this point in the history
  • Loading branch information
CJ42 committed Jan 17, 2024
1 parent 7df5889 commit 71dc8a5
Show file tree
Hide file tree
Showing 15 changed files with 515 additions and 3 deletions.
4 changes: 4 additions & 0 deletions packages/LSP2ERC725YJSONSchema/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: ['custom'],
};
22 changes: 22 additions & 0 deletions packages/LSP2ERC725YJSONSchema/.solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extends": "solhint:recommended",
"rules": {
"avoid-sha3": "error",
"avoid-suicide": "error",
"avoid-throw": "error",
"avoid-tx-origin": "error",
"check-send-result": "error",
"compiler-version": ["error", "^0.8.0"],
"func-visibility": ["error", { "ignoreConstructors": true }],
"not-rely-on-block-hash": "error",
"not-rely-on-time": "error",
"reentrancy": "error",
"constructor-syntax": "error",
"private-vars-leading-underscore": ["error", { "strict": false }],
"imports-on-top": "error",
"visibility-modifier-order": "error",
"reason-string": ["warn", { "maxLength": 120 }],
"avoid-low-level-calls": "off",
"no-empty-blocks": "off"
}
}
5 changes: 5 additions & 0 deletions packages/LSP2ERC725YJSONSchema/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# LSP Template

This project can be used as a skeleton to build a package for a LSP implementation in Solidity (LUKSO Standard Proposal)

It is based on Hardhat.
128 changes: 128 additions & 0 deletions packages/LSP2ERC725YJSONSchema/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import { HardhatUserConfig } from 'hardhat/config';
import { NetworkUserConfig } from 'hardhat/types';
import { config as dotenvConfig } from 'dotenv';
import { resolve } from 'path';

/**
* this package includes:
* - @nomiclabs/hardhat-ethers
* - @nomicfoundation/hardhat-chai-matchers
* - @nomicfoundation/hardhat-network-helpers
* - @nomiclabs/hardhat-etherscan
* - hardhat-gas-reporter (is this true? Why do we have it as a separate dependency?)
* - @typechain/hardhat
* - solidity-coverage
*/
import '@nomicfoundation/hardhat-toolbox';

// additional hardhat plugins
import 'hardhat-packager';
import 'hardhat-contract-sizer';
import 'hardhat-deploy';

// custom built hardhat plugins and scripts
// can be imported here (e.g: docs generation, gas benchmark, etc...)

dotenvConfig({ path: resolve(__dirname, './.env') });

function getTestnetChainConfig(): NetworkUserConfig {
const config: NetworkUserConfig = {
live: true,
url: 'https://rpc.testnet.lukso.network',
chainId: 4201,
};

if (process.env.CONTRACT_VERIFICATION_TESTNET_PK !== undefined) {
config['accounts'] = [process.env.CONTRACT_VERIFICATION_TESTNET_PK];
}

return config;
}

const config: HardhatUserConfig = {
defaultNetwork: 'hardhat',
networks: {
hardhat: {
live: false,
saveDeployments: false,
allowBlocksWithSameTimestamp: true,
},
luksoTestnet: getTestnetChainConfig(),
},
namedAccounts: {
owner: 0,
},
// uncomment if the contracts from this LSP package must be deployed at deterministic
// // addresses across multiple chains
// deterministicDeployment: {
// luksoTestnet: {
// // Nick Factory. See https://github.com/Arachnid/deterministic-deployment-proxy
// factory: '0x4e59b44847b379578588920ca78fbf26c0b4956c',
// deployer: '0x3fab184622dc19b6109349b94811493bf2a45362',
// funding: '0x0000000000000000000000000000000000000000000000000000000000000000',
// signedTx:
// '0xf8a58085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf31ba02222222222222222222222222222222222222222222222222222222222222222a02222222222222222222222222222222222222222222222222222222222222222',
// },
// },
etherscan: {
apiKey: 'no-api-key-needed',
customChains: [
{
network: 'luksoTestnet',
chainId: 4201,
urls: {
apiURL: 'https://api.explorer.execution.testnet.lukso.network/api',
browserURL: 'https://explorer.execution.testnet.lukso.network/',
},
},
],
},
gasReporter: {
enabled: true,
currency: 'USD',
gasPrice: 21,
excludeContracts: ['Helpers/'],
src: './contracts',
showMethodSig: true,
},
solidity: {
version: '0.8.17',
settings: {
optimizer: {
enabled: true,
/**
* Optimize for how many times you intend to run the code.
* Lower values will optimize more for initial deployment cost, higher
* values will optimize more for high-frequency usage.
* @see https://docs.soliditylang.org/en/v0.8.6/internals/optimizer.html#opcode-based-optimizer-module
*/
runs: 1000,
},
outputSelection: {
'*': {
'*': ['storageLayout'],
},
},
},
},
packager: {
// What contracts to keep the artifacts and the bindings for.
contracts: [],
// Whether to include the TypeChain factories or not.
// If this is enabled, you need to run the TypeChain files through the TypeScript compiler before shipping to the registry.
includeFactories: true,
},
paths: {
artifacts: 'artifacts',
tests: 'tests',
},
typechain: {
outDir: 'types',
target: 'ethers-v5',
},
mocha: {
timeout: 10000000,
},
};

export default config;
47 changes: 47 additions & 0 deletions packages/LSP2ERC725YJSONSchema/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "lsp2",
"version": "0.12.1",
"description": "Package for the LSP2 ERC725Y JSON Schema standard",
"license": "Apache-2.0",
"author": "",
"keywords": [
"LUKSO",
"LSP",
"Blockchain",
"Standards",
"Smart Contracts",
"Ethereum",
"EVM",
"Solidity"
],
"scripts": {
"build": "hardhat compile --show-stack-traces",
"clean": "hardhat clean",
"format": "prettier --write .",
"lint": "eslint . --ext .ts,.js",
"lint:solidity": "solhint 'contracts/**/*.sol' && prettier --check 'contracts/**/*.sol'",
"test": "hardhat test --no-compile tests/LSP6/*.test.ts",
"test:coverage": "hardhat coverage"
},
"dependencies": {
"@erc725/smart-contracts": "^6.0.0",
"@openzeppelin/contracts": "^4.9.3"
},
"devDependencies": {
"@nomicfoundation/hardhat-toolbox": "^2.0.2",
"@typechain/ethers-v5": "^10.2.0",
"dotenv": "^16.0.3",
"eslint-config-custom": "*",
"ethers": "^5.7.2",
"hardhat": "^2.13.0",
"hardhat-contract-sizer": "^2.8.0",
"hardhat-deploy": "^0.11.25",
"hardhat-gas-reporter": "^1.0.9",
"hardhat-packager": "^1.4.2",
"solhint": "^3.3.6",
"ts-node": "^10.2.0",
"tsconfig": "*",
"typechain": "^8.0.0",
"typescript": "^4.9.5"
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { expect } from 'chai';
import { ethers } from 'hardhat';
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { LSP2UtilsLibraryTester, LSP2UtilsLibraryTester__factory } from '../../types';
import { LSP2UtilsLibraryTester, LSP2UtilsLibraryTester__factory } from '../../../types';

import { encodeCompactBytesArray } from '../utils/helpers';
import { encodeCompactBytesArray } from '../../../tests/utils/helpers';

describe('LSP2Utils', () => {
let accounts: SignerWithAddress[];
Expand Down
4 changes: 4 additions & 0 deletions packages/LSP2ERC725YJSONSchema/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "tsconfig/contracts.json",
"include": ["**/*.ts"]
}
45 changes: 45 additions & 0 deletions packages/lsp17-extensions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name": "lsp17-extensions",
"version": "0.12.1",
"description": "Pluggable Extension contracts based on the LSP17 standard",
"license": "Apache-2.0",
"author": "",
"keywords": [
"LUKSO",
"LSP",
"Blockchain",
"Standards",
"Smart Contracts",
"Ethereum",
"EVM",
"Solidity"
],
"scripts": {
"build": "hardhat compile --show-stack-traces",
"clean": "hardhat clean",
"format": "prettier --write .",
"lint": "eslint . --ext .ts,.js",
"lint:solidity": "solhint 'contracts/**/*.sol' && prettier --check 'contracts/**/*.sol'",
"test": "hardhat test --no-compile tests/LSP6/*.test.ts",
"test:coverage": "hardhat coverage"
},
"dependencies": {
"@account-abstraction/contracts": "^0.6.0",
"@erc725/smart-contracts": "^5.1.0",
"@openzeppelin/contracts": "^4.9.3"
},
"devDependencies": {
"@nomicfoundation/hardhat-toolbox": "^2.0.2",
"@typechain/ethers-v5": "^10.2.0",
"eslint-config-custom": "*",
"ethers": "^5.7.2",
"hardhat": "^2.13.0",
"hardhat-gas-reporter": "^1.0.9",
"hardhat-packager": "^1.4.2",
"solhint": "^3.3.6",
"ts-node": "^10.2.0",
"tsconfig": "*",
"typechain": "^8.0.0",
"typescript": "^4.9.5"
}
}
92 changes: 92 additions & 0 deletions scripts/typesTs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/usr/bin/env bash

# This script will gather `types/` files from all pkgs & aggregate them into 1 `types/index.ts` file
# This script runs automatically after each `npm run build`

# output file
outputFileType="./types/index.ts"

# create file if not exists
if [ ! -f "$outputFileType" ]; then
mkdir ./types
echo "" >> $outputFileType
fi

# file headers
echo -e "/* File generated by scripts/typesTs.sh. Do not edit manually. */\n/* tslint:disable */\n/* eslint-disable */\n" > $outputFileType

# Helper function to loop through a directory and add each ts file in the outputFileType
# Parameter:
# 1) path to directory
# 2) type of path (contract or factory)
# 3) depth to search in the directory
# Return:
# nothing, output is in the outputFileType
loop_through () {
local searchPath="$1"
local exportType="$2"
local noDepth="$3"
# Check if the given path is a directory
if [ -d "$searchPath" ]; then
# wether to just search in the given directory ...
if [ "$noDepth" = "true" ]; then
cmd=$(find "$searchPath" -type f -regex ".*ts$" ! -regex ".*index\.ts" ! -regex ".*common\.ts" ! -regex ".*hardhat\.d\.ts" -maxdepth 1)
# ... or in all subdirectories
else
cmd=$(find "$searchPath" -type f -regex ".*ts$" ! -regex ".*index\.ts" ! -regex ".*common\.ts" ! -regex ".*hardhat\.d\.ts")
fi
# Loop through all .ts files in the directory & sub-directories
for tsFile in $cmd; do
# replace ./ by ../
itemPath=${tsFile/.\//../}
# remove .ts extention
pathNoExt=${itemPath/.ts/}
# module name only
moduleName=$(basename $pathNoExt)
echo "🔁 Processing '${pathNoExt}'"
if [ "$exportType" = "factory" ]; then
echo -e "export { ${moduleName} } from \"${pathNoExt}\";" >> $outputFileType
else
echo -e "export type { ${moduleName} } from \"${pathNoExt}\";" >> $outputFileType
fi
done
fi
}

# integration-tests folder
testFolder="./integration-tests"
if [[ -d "${testFolder}/types/contracts" && -d "${testFolder}/types/factories/contracts" ]]; then
loop_through "$testFolder/types/contracts" "contract" "false"
loop_through "$testFolder/types/factories/contracts" "factory" "false"
fi

# For all folders in packages/ except lsp-utils
for dir in $(find ./packages -type d -maxdepth 1 ! -regex '.*lsp-utils.*'); do
# if 'types' folder doesn't exists, continue
if [ ! -d "${dir}/types" ]; then
echo "📂❌ Directory ${dir} has no types. skipping"
continue
fi
# if 'types/contracts' folder exists, process it
if [ -d "${dir}/types/contracts" ]; then
echo "📂 Processing '${dir}' 📑"
loop_through "$dir/types/contracts" "contract" "false"
# 'types' folder exists, but no 'contracts' folder in it
# process the root folder (depth 1)
else
echo "📂 No 'contracts' directory in ${dir}/types. Processing root."
loop_through "$dir/types" "contract" "true"
fi

# if 'types/factories/contracts' folder exists, process it
if [ -d "${dir}/types/factories/contracts" ]; then
echo "📂 Processing '${dir}' 🏭"
loop_through "$dir/types/factories/contracts" "factory" "false"
# 'types' folder exists, but no 'contracts' folder in it
# process the root folder (depth 1)
else
echo "📂 No 'contracts' directory in ${dir}/types/factories. Processing root."
loop_through "$dir/types/factories" "contract" "true"
fi
done

4 changes: 4 additions & 0 deletions template/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: ['custom'],
};
22 changes: 22 additions & 0 deletions template/.solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extends": "solhint:recommended",
"rules": {
"avoid-sha3": "error",
"avoid-suicide": "error",
"avoid-throw": "error",
"avoid-tx-origin": "error",
"check-send-result": "error",
"compiler-version": ["error", "^0.8.0"],
"func-visibility": ["error", { "ignoreConstructors": true }],
"not-rely-on-block-hash": "error",
"not-rely-on-time": "error",
"reentrancy": "error",
"constructor-syntax": "error",
"private-vars-leading-underscore": ["error", { "strict": false }],
"imports-on-top": "error",
"visibility-modifier-order": "error",
"reason-string": ["warn", { "maxLength": 120 }],
"avoid-low-level-calls": "off",
"no-empty-blocks": "off"
}
}
Loading

0 comments on commit 71dc8a5

Please sign in to comment.