Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ coverage.json

.idea

.env
.env*
143 changes: 143 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
# Conditionally include .env or .env.automation based on OPS_LAUNCH_MODE
ifeq ($(OPS_LAUNCH_MODE),auto)
-include .env.automation
else
-include .env
endif
export

OPS_NETWORK := $(subst ",,$(OPS_NETWORK))
OPS_CHAIN_ID := $(subst ",,$(OPS_CHAIN_ID))
OPS_KYC_TOKEN_SUFFIX := $(subst ",,$(OPS_KYC_TOKEN_SUFFIX))

CURRENT_DIR := $(shell pwd)

FILE_DEPLOY_KYC_NFT := $(CURRENT_DIR)/deploy/deploy-kyc-nft.js
FILE_CONSTANTS_JSON := $(CURRENT_DIR)/config/constants.json

# New access token deployment targets
deploy-access-token:
@$(MAKE) OPS_CURRENT_DEP_FILE=$(FILE_DEPLOY_KYC_NFT) validate-access-token deploy-skip-all deploy-noskip deploy-access-token-impl deploy-skip

deploy-access-token-impl:
@{ \
yarn deploy $(OPS_NETWORK) || exit 1; \
}

# Validation targets
validate-access-token:
@{ \
if [ -z "$(OPS_NETWORK)" ]; then echo "OPS_NETWORK is not set!"; exit 1; fi; \
if [ -z "$(OPS_CHAIN_ID)" ]; then echo "OPS_CHAIN_ID is not set!"; exit 1; fi; \
if [ -z "$(OPS_CREATE3_DEPLOYER_ADDRESS)" ] && [ "$(OPS_CHAIN_ID)" != 324 ]; then echo "OPS_CREATE3_DEPLOYER_ADDRESS is not set!"; exit 1; fi; \
if [ -z "$(MAINNET_RPC_URL)" ] && [ "$(OPS_NETWORK)" = "hardhat" ]; then echo "MAINNET_RPC_URL is not set!"; exit 1; fi; \
if [ -z "$(OPS_KYC_TOKEN_OWNER_ADDRESS)" ]; then echo "OPS_KYC_TOKEN_OWNER_ADDRESS is not set!"; exit 1; fi; \
if [ -z "$(OPS_KYC_TOKEN_SALT)" ]; then echo "OPS_KYC_TOKEN_SALT is not set!"; exit 1; fi; \
$(MAKE) process-access-token-owner process-access-token-salt process-create3-deployer; \
}

# Process constant functions for new addresses
process-access-token-owner:
@$(MAKE) OPS_GEN_KEY='accessTokenOwner' OPS_GEN_VAL='$(OPS_KYC_TOKEN_OWNER_ADDRESS)' upsert-constant

process-access-token-salt:
@$(MAKE) OPS_GEN_KEY='accessTokenSalt' OPS_GEN_VAL='$(OPS_KYC_TOKEN_SALT)' upsert-constant

process-create3-deployer:
@{ \
if [ -n "$(OPS_CREATE3_DEPLOYER_ADDRESS)" ]; then \
$(MAKE) OPS_GEN_KEY='create3Deployers' OPS_GEN_VAL='$(OPS_CREATE3_DEPLOYER_ADDRESS)' upsert-constant; \
fi \
}

upsert-constant:
@{ \
if [ -z "$(OPS_GEN_VAL)" ]; then \
echo "Variable for key $(OPS_GEN_KEY) is not set!"; \
exit 1; \
fi; \
if [ -z "$(OPS_GEN_KEY)" ]; then \
echo "OPS_GEN_KEY is not set!"; \
exit 1; \
fi; \
if [ -z "$(OPS_CHAIN_ID)" ]; then \
echo "OPS_CHAIN_ID is not set!"; \
exit 1; \
fi; \
tmpfile=$$(mktemp); \
jq '.$(OPS_GEN_KEY)."$(OPS_CHAIN_ID)" = $(OPS_GEN_VAL)' $(FILE_CONSTANTS_JSON) > $$tmpfile && mv $$tmpfile $(FILE_CONSTANTS_JSON); \
echo "Updated $(OPS_GEN_KEY)[$(OPS_CHAIN_ID)] = $(OPS_GEN_VAL)"; \
}

deploy-skip-all:
@{ \
for secret in $(FILE_DEPLOY_KYC_NFT); do \
$(MAKE) OPS_CURRENT_DEP_FILE=$$secret deploy-skip; \
done \
}

deploy-skip:
@sed -i '' 's/module.exports.skip.*/module.exports.skip = async () => true;/g' $(OPS_CURRENT_DEP_FILE)

deploy-noskip:
@sed -i '' 's/module.exports.skip.*/module.exports.skip = async () => false;/g' $(OPS_CURRENT_DEP_FILE)

install: install-utils install-dependencies

install-utils:
brew install yarn wget jq

install-dependencies:
yarn

clean:
@rm -Rf $(CURRENT_DIR)/deployments/$(OPS_NETWORK)/*


# Get deployed contract addresses from deployment files
get:
@{ \
if [ -z "$(PARAMETER)" ]; then \
echo "Error: PARAMETER is not set. Usage: make get PARAMETER=OPS_AGGREGATION_EXECUTOR_SIMPLE_ADDRESS"; \
exit 1; \
fi; \
if [ -z "$(OPS_NETWORK)" ]; then \
echo "Error: OPS_NETWORK is not set"; \
exit 1; \
fi; \
CONTRACT_FILE=""; \
case "$(PARAMETER)" in \
"OPS_KYC_TOKEN_ADDRESS") CONTRACT_FILE="KycNFT.json" ;; \
*) echo "Error: Unknown parameter $(PARAMETER)"; exit 1 ;; \
esac; \
DEPLOYMENT_FILE="$(CURRENT_DIR)/deployments/$(OPS_NETWORK)/$$CONTRACT_FILE"; \
if [ ! -f "$$DEPLOYMENT_FILE" ]; then \
echo "Error: Deployment file $$DEPLOYMENT_FILE not found"; \
exit 1; \
fi; \
ADDRESS=$$(cat "$$DEPLOYMENT_FILE" | grep '"address"' | head -1 | sed 's/.*"address": *"\([^"]*\)".*/\1/'); \
echo "$$ADDRESS"; \
}

help:
@echo "Available targets:"
@echo " deploy-access-token Deploy access token contracts"
@echo " deploy-access-token-impl Deploy access token implementation"
@echo " validate-access-token Validate required environment variables"
@echo " process-access-token-owner Update access token owner constant"
@echo " process-access-token-salt Update access token salt constant"
@echo " process-create3-deployer Update create3 deployer constant"
@echo " upsert-constant Upsert constant value in JS file"
@echo " deploy-skip-all Mark all deploy files as skipped"
@echo " deploy-skip Mark current deploy file as skipped"
@echo " deploy-noskip Mark current deploy file as not skipped"
@echo " launch-hh-node Launch Hardhat node with forked RPC"
@echo " install Install utils and dependencies"
@echo " install-utils Install required utilities"
@echo " install-dependencies Install yarn dependencies"
@echo " clean Remove deployment files"
@echo " get PARAMETER=... Get deployed contract address"
@echo " help Show this help message"


.PHONY: help deploy-access-token deploy-access-token-impl validate-access-token process-access-token-owner process-access-token-salt process-create3-deployer upsert-constant deploy-skip-all deploy-skip deploy-noskip launch-hh-node install install-utils install-dependencies clean get
7 changes: 7 additions & 0 deletions config/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const constants = require('./constants.json');

module.exports = {
ACCESS_TOKEN_SALT: constants.accessTokenSalt || {},
ACCESS_TOKEN_OWNER: constants.accessTokenOwner || {},
CREATE3_DEPLOYERS: constants.create3Deployers || {},
};
25 changes: 25 additions & 0 deletions config/constants.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"accessTokenSalt": {
"31337": "0xfd0450e10366502b67f46a6037db5b90d1cad2d4a744b961f7986bf35f4d35d7"
},
"accessTokenOwner": {
"31337": "0xAA74E80De15758Fe983Cb6102176ef2cE195ECfE"
},
"create3Deployers": {
"31337": "0xaD54e5f728c167E51FBc53745055F7105Fe8B503",
"1": "0xD935a2bb926019E0ed6fb31fbD5b1Bbb7c05bf65",
"56": "0xD935a2bb926019E0ed6fb31fbD5b1Bbb7c05bf65",
"137": "0xD935a2bb926019E0ed6fb31fbD5b1Bbb7c05bf65",
"42161": "0xD935a2bb926019E0ed6fb31fbD5b1Bbb7c05bf65",
"10": "0xD935a2bb926019E0ed6fb31fbD5b1Bbb7c05bf65",
"43114": "0xD935a2bb926019E0ed6fb31fbD5b1Bbb7c05bf65",
"100": "0xD935a2bb926019E0ed6fb31fbD5b1Bbb7c05bf65",
"250": "0xD935a2bb926019E0ed6fb31fbD5b1Bbb7c05bf65",
"1313161554": "0xD935a2bb926019E0ed6fb31fbD5b1Bbb7c05bf65",
"8217": "0xD935a2bb926019E0ed6fb31fbD5b1Bbb7c05bf65",
"8453": "0xD935a2bb926019E0ed6fb31fbD5b1Bbb7c05bf65",
"59144": "0xD935a2bb926019E0ed6fb31fbD5b1Bbb7c05bf65",
"146": "0xD935a2bb926019E0ed6fb31fbD5b1Bbb7c05bf65",
"130": "0xD935a2bb926019E0ed6fb31fbD5b1Bbb7c05bf65"
}
}
47 changes: 31 additions & 16 deletions deploy/deploy-kyc-nft.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,38 @@
const { getChainId, network } = require('hardhat');
const hre = require('hardhat');
const { deployAndGetContractWithCreate3, deployAndGetContract } = require('@1inch/solidity-utils');
const constants = require('../config/constants');

const constructorArgs = [
'Resolver Access Token', // name
'RES', // symbol
'1', // version
'0x56E44874F624EbDE6efCc783eFD685f0FBDC6dcF', // owner
];
const create3Deployer = '0xD935a2bb926019E0ed6fb31fbD5b1Bbb7c05bf65';
const salt = '0xfd0450e10366502b67f46a6037db5b90d1cad2d4a744b961f7986bf35f4d35d7';
const AT_NAME = 'Resolver Access Token';
const AT_SYMBOL = 'RES';
const AT_VERSION = '1';

module.exports = async ({ getNamedAccounts, deployments }) => {
console.log('running deploy script: kyc-nft');
console.log('network id ', await getChainId());
module.exports = async ({ getNamedAccounts, deployments, config }) => {
const networkName = hre.network.name;
console.log(`running ${networkName} deploy script: kyc-nft`);
const chainId = await hre.getChainId();
console.log('network id ', chainId);

if (chainId !== hre.config.networks[networkName].chainId?.toString()) {
console.log(`network chain id: ${hre.config.networks[networkName].chainId}, your chain id ${chainId}`);
console.log('skipping wrong chain id deployment');
return;
}

const constructorArgs = [
AT_NAME,
AT_SYMBOL,
AT_VERSION,
constants.ACCESS_TOKEN_OWNER[chainId],
];

const deploymentName = config.deployOpts.kycTokenSuffix ? `KycNFT_${config.deployOpts.kycTokenSuffix}` : 'KycNFT';

if (network.name.indexOf('zksync') !== -1) {
if (networkName.indexOf('zksync') !== -1) {
// Deploy on zkSync-like networks without create3
const { deployer } = await getNamedAccounts();
await deployAndGetContract({
contractName: 'KycNFT',
deploymentName,
constructorArgs,
deployments,
deployer,
Expand All @@ -27,11 +41,12 @@ module.exports = async ({ getNamedAccounts, deployments }) => {
// Deploy with create3
await deployAndGetContractWithCreate3({
contractName: 'KycNFT',
deploymentName,
constructorArgs,
create3Deployer,
salt,
create3Deployer: constants.CREATE3_DEPLOYERS[chainId],
salt: constants.ACCESS_TOKEN_SALT[chainId],
deployments,
skipVerify: network.name === 'klaytn',
skipVerify: networkName === 'klaytn',
});
}
};
Expand Down
1 change: 1 addition & 0 deletions deployments/localhost/.chainId
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
31337
Loading
Loading