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

build!: move LSP16 in its own package #857

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion config/eslint-config-custom/README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# `eslint-custom-config`
# `eslint-custom-config`
435 changes: 0 additions & 435 deletions docs/contracts/LSP16UniversalFactory/LSP16UniversalFactory.md
YamenMerhi marked this conversation as resolved.
Show resolved Hide resolved

This file was deleted.

71 changes: 71 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/LSP16UniversalFactory/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: ['custom'],
};
3 changes: 3 additions & 0 deletions packages/LSP16UniversalFactory/.gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "lib/forge-std"]
path = ../../lib/forge-std
url = https://github.com/foundry-rs/forge-std.git
25 changes: 25 additions & 0 deletions packages/LSP16UniversalFactory/.solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"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",
"no-unused-import": "error",
"no-global-import": "error",
"reason-string": ["warn", { "maxLength": 120 }],
"avoid-low-level-calls": "off",
"no-empty-blocks": ["error", { "ignoreConstructors": true }],
"custom-errors": "off"
}
}
51 changes: 51 additions & 0 deletions packages/LSP16UniversalFactory/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# LSP Package Template
YamenMerhi marked this conversation as resolved.
Show resolved Hide resolved

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.

## How to setup a LSP as a package?

1. Copy the `template/` folder and paste it under the `packages/` folder. Then rename this `template/` folder that you copied with the LSP name.

You can do so either:

- manually, by copying the folder and pasting it inside `packages` and then renaming it.
or
- by running the following command from the root of the repository.

```bash
cp -r template packages/lsp-name
```

2. Update the `"name"` and `"description"` field inside the `package.json` for this LSP package you just created.

3. Setup the dependencies

If this LSP uses external dependencies like `@openzeppelin/contracts`, put them under `dependencies` with the version number.

```json
"@openzeppelin/contracts": "^4.9.3"
```

If this LSP uses other LSP as dependencies, put each LSP dependency as shown below. This will use the current code in the package:

```json
"@lsp2": "*"
```

4. Setup the npm commands for linting, building, testing, etc... under the `"scripts"` in the `package.json`

5. Test that all commands you setup run successfully

By running the commands below, your LSP package should come up in the list of packages that Turbo is running this command for.

```bash
turbo build
turbo lint
turbo lint:solidity
turbo test
turbo test:foundry
```

6. Finally update the relevant information in the `README.md` file in the folder of the newly created package, such as the title at the top, some description, etc...
10 changes: 10 additions & 0 deletions packages/LSP16UniversalFactory/foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[profile.default]
src = 'contracts'
out = 'out'
libs = ['node_modules','lib']
cache_path = 'forge-cache'
test = 'foundry'
solc_version = "0.8.17"
[fuzz]
runs = 10_000
max_test_rejects = 200_000
134 changes: 134 additions & 0 deletions packages/LSP16UniversalFactory/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
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: 9999999,
},
metadata: {
// do not include the metadata hash, since this is machine dependent
// and we want all generated code to be deterministic
// https://docs.soliditylang.org/en/v0.7.6/metadata.html
bytecodeHash: 'none',
},
outputSelection: {
'*': {
'*': ['storageLayout'],
},
},
},
},
packager: {
// What contracts to keep the artifacts and the bindings for.
contracts: [],
YamenMerhi marked this conversation as resolved.
Show resolved Hide resolved
// 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;
44 changes: 44 additions & 0 deletions packages/LSP16UniversalFactory/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "lsp16",
"version": "0.12.1",
"description": "Package for the LSP16 Universal Factory 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'"
},
"dependencies": {
"@openzeppelin/contracts": "^4.9.2"
},
"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"
}
}
9 changes: 9 additions & 0 deletions packages/LSP16UniversalFactory/remappings.txt
YamenMerhi marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@erc725/smart-contracts/=node_modules/@erc725/smart-contracts/
@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/
@openzeppelin/contracts-upgradeable/=node_modules/@openzeppelin/contracts-upgradeable/
eth-gas-reporter/=node_modules/eth-gas-reporter/
forge-std/=lib/forge-std/src/
hardhat-deploy/=node_modules/hardhat-deploy/
hardhat/=node_modules/hardhat/
solidity-bytes-utils/=node_modules/solidity-bytes-utils/
ds-test/=lib/forge-std/lib/ds-test/src/
4 changes: 4 additions & 0 deletions packages/LSP16UniversalFactory/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "tsconfig/contracts.json",
"include": ["**/*.ts"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "forge-std/console.sol";

import {Address} from "@openzeppelin/contracts/utils/Address.sol";

import "../../../contracts/LSP16UniversalFactory/LSP16UniversalFactory.sol";
import "../../../packages/LSP16UniversalFactory/contracts/LSP16UniversalFactory.sol";
import "../../../contracts/Mocks/NonPayableFallback.sol";
import "../../../contracts/Mocks/FallbackInitializer.sol";
import "../../../contracts/LSP0ERC725Account/LSP0ERC725Account.sol";
Expand Down
Loading