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

add ignition experiment #362

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from
Open
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
31 changes: 30 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ jobs:
permissions:
contents: read
# id-token: write
needs: [build_hardhat, build_foundry]
needs: [build_hardhat]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -147,4 +147,33 @@ jobs:
env:
SKIP_VERIFICATION: true
run: hh run scripts/deploy_all.ts

deployment_ignition:
name: Execute ignition deployment on local chain
runs-on: ubuntu-latest
permissions:
contents: read
# id-token: write
needs: [build_hardhat]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Setup node environment
uses: actions/setup-node@v4
with:
node-version: 20
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: |
npm install

- name: Run deployment script
run: npx hardhat ignition deploy ignition/modules/GifCore.ts --strategy create2

4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ test_brownie/__pycache__
*.log
deployment_state_*.json
lcov.info
.*.drawio.bkp
.*.drawio.bkp

ignition/deployments/
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"editor.defaultFormatter": "esbenp.prettier-vscode",
"todo-tree.tree.scanMode": "workspace only",
"solidity.compileUsingLocalVersion": "/workspaces/gif-next/soljson-v0.8.20+commit.a1b79de6.js",
"asciidoc.antora.enableAntoraSupport": true,
"workbench.colorCustomizations": {
"activityBar.activeBackground": "#f18500",
"activityBar.background": "#f18500",
Expand All @@ -36,5 +37,4 @@
"titleBar.inactiveBackground": "#be690099",
"titleBar.inactiveForeground": "#e7e7e799"
},
"asciidoc.antora.enableAntoraSupport": true,
}
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ export SKIP_VERIFICATION=true
hh run scripts/deploy_all.ts
```

Deployment via ignition

```bash
npx hardhat ignition deploy ignition/modules/GifCore.ts
hh ignition deploy ignition/modules/GifCore.ts

hh ignition deploy ignition/modules/GifCore.ts --strategy create2
hh ignition deploy ignition/modules/GifCore.ts --strategy create2 --verify

npx hardhat ignition verify chain-84532 --network baseSepolia

```

```bash
# set appropriate values vor env variables (see below)

Expand Down
4 changes: 2 additions & 2 deletions contracts/registry/Registry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ contract Registry is
}


constructor(RegistryAdmin admin)
InitializableCustom()
constructor(RegistryAdmin admin, address initialOwner)
InitializableCustom(initialOwner)
{
_admin = admin;
// deploy NFT
Expand Down
2 changes: 1 addition & 1 deletion contracts/registry/RegistryAdmin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ contract RegistryAdmin is
address private _stakingStore;
bool private _setupCompleted;

constructor() AccessAdmin() { }
constructor(address deployer) AccessAdmin(deployer) { }

function completeSetup(
IRegistry registry,
Expand Down
4 changes: 2 additions & 2 deletions contracts/shared/AccessAdmin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ contract AccessAdmin is
_;
}

constructor() {
_deployer = msg.sender;
constructor(address deployer) {
_deployer = deployer;
_authority = new AccessManager(address(this));

_setAuthority(address(_authority));
Expand Down
4 changes: 2 additions & 2 deletions contracts/shared/InitializableCustom.sol
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ abstract contract InitializableCustom {
/**
* @dev Constructor sets the caller of protected initializer function.
*/
constructor() {
constructor(address initialOwner) {
// solhint-disable-previous-line var-name-mixedcase
InitializableCustomStorage storage $ = _getInitializableCustomStorage();
$._initializeOwner = msg.sender;
$._initializeOwner = initialOwner;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion contracts/staking/StakingReader.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ contract StakingReader is
IStaking private _staking;
StakingStore private _store;

constructor(IRegistry registry) InitializableCustom() {
constructor(IRegistry registry, address initialOwner) InitializableCustom(initialOwner) {
_registry = registry;
}

Expand Down
43 changes: 37 additions & 6 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ import { config as dotEnvConfig } from "dotenv";
dotEnvConfig();

const config: HardhatUserConfig = {
ignition: {
strategyConfig: {
create2: {
salt: "0x0000000000000000000000000000000000000000000000000000000000000006",
}
}
},
"paths": {
"tests": "./test_hardhat",
},
solidity: {
version: "0.8.20",
settings: {
Expand All @@ -27,14 +37,15 @@ const config: HardhatUserConfig = {
chainId: 1337,
url: "http://anvil:7545",
accounts: {
mnemonic: "candy maple cake sugar pudding cream honey rich smooth crumble sweet treat",
mnemonic: process.env.WALLET_MNEMONIC || "candy maple cake sugar pudding cream honey rich smooth crumble sweet treat",
count: 20,
},
},
mumbai: {
chainId: 80001,
gasPrice: 3100000000,
url: process.env.NETWORK_URL || 'https://polygon-mumbai.infura.io/v3/' + process.env.WEB3_INFURA_PROJECT_ID,
polygonAmoy: {
chainId: 80002,
url: process.env.NETWORK_URL || 'https://rpc-amoy.polygon.technology/',
gas: 1000000000,
gasPrice: 1000000000,
accounts: {
mnemonic: process.env.WALLET_MNEMONIC || "candy maple cake sugar pudding cream honey rich smooth crumble sweet treat",
count: 20,
Expand All @@ -44,11 +55,31 @@ const config: HardhatUserConfig = {
chainId: 1,
url: process.env.NETWORK_URL || 'https://mainnet.infura.io/v3/' + process.env.WEB3_INFURA_PROJECT_ID,
},
baseSepolia: {
chainId: 84532,
url: process.env.NETWORK_URL || "https://sepolia.base.org",
gas: 200000000,
gasPrice: 2000000000,
accounts: {
mnemonic: process.env.WALLET_MNEMONIC || "candy maple cake sugar pudding cream honey rich smooth crumble sweet treat",
count: 20,
},
}
},
etherscan: {
apiKey: {
polygonMumbai: process.env.POLYGONSCAN_API_KEY || "",
polygonAmoy: process.env.POLYGONSCAN_API_KEY || "",
},
customChains: [
{
network: "polygonAmoy",
chainId: 80002,
urls: {
apiURL: "https://api-amoy.polygonscan.com/api",
browserURL: "https://amoy.polygonscan.com"
},
}
]
},
};

Expand Down
159 changes: 159 additions & 0 deletions ignition/modules/GifCore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
import LibraryModule from "./Libraries";

export default buildModule("GifCore", (m) => {
const gifAdmin = m.getAccount(0);
const gifManager = m.getAccount(0);
const stakingOwner = m.getAccount(0);

const {
amountLib,
blocknumberLib,
key32Lib,
nftIdLib,
nftIdSetLib,
objectTypeLib,
roleIdLib,
secondsLib,
selectorLib,
selectorSetLib,
stakeManagerLib,
stateIdLib,
strLib,
targetManagerLib,
timestamplib,
uFixedLib,
versionLib,
versionPartLib,
} = m.useModule(LibraryModule);

// 1) deploy dip token
const dip = m.contract("Dip", []);

// 2) deploy registry admin
const registryAdmin = m.contract("RegistryAdmin", [gifAdmin],
{
libraries: {
ObjectTypeLib: objectTypeLib,
RoleIdLib: roleIdLib,
SelectorLib: selectorLib,
SelectorSetLib: selectorSetLib,
StrLib: strLib,
TimestampLib: timestamplib,
VersionLib: versionLib,
VersionPartLib: versionPartLib,
},
}
);

// 3) deploy registry
const registry = m.contract("Registry",
[registryAdmin, stakingOwner],
{
libraries: {
NftIdLib: nftIdLib,
ObjectTypeLib: objectTypeLib,
},
}
);

// 4) deploy release manager
const releaseManager = m.contract("ReleaseManager",
[registry],
{
libraries: {
NftIdLib: nftIdLib,
SecondsLib: secondsLib,
TimestampLib: timestamplib,
VersionLib: versionLib,
VersionPartLib: versionPartLib,
},
}
);

// 5) deploy token registry
const tokenRegistry = m.contract("TokenRegistry",
[registry, dip],
{
libraries: {
VersionPartLib: versionPartLib,
},
}
);

// 6) deploy staking reader
const stakingReader = m.contract("StakingReader",
[registry, stakingOwner],
{
libraries: {
NftIdLib: nftIdLib,
},
}
);

// 7) deploy staking store
const stakingStore = m.contract("StakingStore",
[registry, stakingReader],
{
libraries: {
AmountLib: amountLib,
BlocknumberLib: blocknumberLib,
Key32Lib: key32Lib,
LibNftIdSet: nftIdSetLib,
NftIdLib: nftIdLib,
ObjectTypeLib: objectTypeLib,
StateIdLib: stateIdLib,
TargetManagerLib: targetManagerLib,
TimestampLib: timestamplib,
UFixedLib: uFixedLib,
},
}
);

// 8) deploy staking manager and staking component
const stakingManager = m.contract("StakingManager",
[registry, tokenRegistry, stakingStore, stakingOwner],
{
libraries: {
AmountLib: amountLib,
NftIdLib: nftIdLib,
StakeManagerLib: stakeManagerLib,
TargetManagerLib: targetManagerLib,
TimestampLib: timestamplib,
VersionLib: versionLib,
},
}
);

const stakingAddress = m.staticCall(stakingManager, "getStaking");
const staking = m.contractAt("Staking", stakingAddress);

// 9) initialize instance reader
const stakingReaderInitialize = m.call(stakingReader, "initialize", [staking, stakingStore], {
after: [staking],
});

// 10) intialize registry and register staking component
const registryInitialize = m.call(registry, "initialize", [releaseManager, tokenRegistry, staking], {
after: [stakingReaderInitialize],
});
const stakingLinkToRegisteredNftId = m.call(staking, "linkToRegisteredNftId", [], {
after: [registryInitialize],
});

// 11) initialize registry admin
m.call(registryAdmin, "completeSetup", [registry, gifAdmin, gifManager], {
after: [stakingLinkToRegisteredNftId]
});

return {
dipContract: dip,
registryAdminContract: registryAdmin,
registryContract: registry,
releaseManagerContract: releaseManager,
stakingManagerContract: stakingManager,
stakingStoreContract: stakingStore,
stakingReaderContract: stakingReader,
tokenRegistryContract: tokenRegistry,
};
});
Loading
Loading