Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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*
149 changes: 149 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# Conditionally include .env or .env.automation based on OPS_LAUNCH_MODE
ifeq ($(OPS_LAUNCH_MODE),auto)
-include .env.automation
else
-include .env
endif

CURRENT_DIR=$(shell pwd)

OPS_NETWORK_=$(shell echo "$(OPS_NETWORK)" | tr -d '\"')
OPS_CHAIN_ID_=$(shell echo "$(OPS_CHAIN_ID)" | tr -d '\"')

FILE_DEPLOY_KYC_NFT=$(CURRENT_DIR)/deploy/deploy-kyc-nft.js
FILE_CREATE3_DEPLOYER=$(CURRENT_DIR)/deploy/constants/create3-deployer.js
FILE_ACCESS_TOKEN_OWNER=$(CURRENT_DIR)/deploy/constants/access-token-owner.js
FILE_ACCESS_TOKEN_SALT=$(CURRENT_DIR)/deploy/constants/access-token-salt.js

# 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_VAL='$(OPS_KYC_TOKEN_OWNER_ADDRESS)' OPS_GEN_FILE=$(FILE_ACCESS_TOKEN_OWNER) upsert-constant

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

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

upsert-constant:
@{ \
if [ -z "$(OPS_GEN_VAL)" ]; then \
echo "variable for file $(OPS_GEN_FILE) is not set!"; \
exit 1; \
fi; \
if grep -q "$(OPS_CHAIN_ID_)" $(OPS_GEN_FILE); then \
sed -i '' 's|$(OPS_CHAIN_ID_): .*|$(OPS_CHAIN_ID_): $(OPS_GEN_VAL),|' $(OPS_GEN_FILE); \
sed -i '' 's/"/'\''/g' $(OPS_GEN_FILE); \
else \
tmpfile=$$(mktemp); \
awk '1;/module.exports = {/{print " $(OPS_CHAIN_ID_): $(subst ",\",$(OPS_GEN_VAL)),"}' $(OPS_GEN_FILE) > $$tmpfile && sed -i '' 's/"/'\''/g' $$tmpfile && mv $$tmpfile $(OPS_GEN_FILE); \
fi \
}

deploy-skip-all:
@{ \
for secret in $(FILE_DEPLOY); 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)

launch-hh-node:
@{ \
if [ -z "$(NODE_RPC)" ]; then \
echo "NODE_RPC is not set!"; \
exit 1; \
fi; \
echo "Launching Hardhat node with RPC: $(NODE_RPC)"; \
npx hardhat node --fork $(NODE_RPC) --vvvv --full-trace; \
}

install: install-utils install-dependencies

install-utils:
brew install yarn wget

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
5 changes: 5 additions & 0 deletions deploy/constants/access-token-owner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
31337: '0x56E44874F624EbDE6efCc783eFD685f0FBDC6dcF',
};

module.exports.skip = async () => true;
5 changes: 5 additions & 0 deletions deploy/constants/access-token-salt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
31337: '0xfd0450e10366502b67f46a6037db5b90d1cad2d4a744b961f7986bf35f4d35d7',
};

module.exports.skip = async () => true;
19 changes: 19 additions & 0 deletions deploy/constants/create3-deployer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
31337: '0xD935a2bb926019E0ed6fb31fbD5b1Bbb7c05bf65',
1: '0xD935a2bb926019E0ed6fb31fbD5b1Bbb7c05bf65', // Mainnet
56: '0xD935a2bb926019E0ed6fb31fbD5b1Bbb7c05bf65', // BSC
137: '0xD935a2bb926019E0ed6fb31fbD5b1Bbb7c05bf65', // Matic
42161: '0xD935a2bb926019E0ed6fb31fbD5b1Bbb7c05bf65', // Arbitrum
10: '0xD935a2bb926019E0ed6fb31fbD5b1Bbb7c05bf65', // Optimistic
43114: '0xD935a2bb926019E0ed6fb31fbD5b1Bbb7c05bf65', // Avalanche
100: '0xD935a2bb926019E0ed6fb31fbD5b1Bbb7c05bf65', // xDAI
250: '0xD935a2bb926019E0ed6fb31fbD5b1Bbb7c05bf65', // FTM
1313161554: '0xD935a2bb926019E0ed6fb31fbD5b1Bbb7c05bf65', // Aurora
8217: '0xD935a2bb926019E0ed6fb31fbD5b1Bbb7c05bf65', // Klaytn
8453: '0xD935a2bb926019E0ed6fb31fbD5b1Bbb7c05bf65', // Base
59144: '0xD935a2bb926019E0ed6fb31fbD5b1Bbb7c05bf65', // Linea
146: '0xD935a2bb926019E0ed6fb31fbD5b1Bbb7c05bf65', // Sonic
130: '0xD935a2bb926019E0ed6fb31fbD5b1Bbb7c05bf65', // Unichain
};

module.exports.skip = async () => true;
11 changes: 11 additions & 0 deletions deploy/constants/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const ACCESS_TOKEN_SALT = require('./access-token-salt');
const ACCESS_TOKEN_OWNER = require('./access-token-owner');
const CREATE3_DEPLOYERS = require('./create3-deployer');

module.exports = {
ACCESS_TOKEN_SALT,
ACCESS_TOKEN_OWNER,
CREATE3_DEPLOYERS,
};

module.exports.skip = async () => true;
43 changes: 27 additions & 16 deletions deploy/deploy-kyc-nft.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
const { getChainId, network } = require('hardhat');
const hre = require('hardhat');
const { deployAndGetContractWithCreate3, deployAndGetContract } = require('@1inch/solidity-utils');
const constants = require('./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());
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],
];

if (network.name.indexOf('zksync') !== -1) {
if (networkName.indexOf('zksync') !== -1) {
// Deploy on zkSync-like networks without create3
const { deployer } = await getNamedAccounts();
await deployAndGetContract({
Expand All @@ -28,12 +39,12 @@ module.exports = async ({ getNamedAccounts, deployments }) => {
await deployAndGetContractWithCreate3({
contractName: 'KycNFT',
constructorArgs,
create3Deployer,
salt,
create3Deployer: constants.CREATE3_DEPLOYERS[chainId],
salt: constants.ACCESS_TOKEN_SALT[chainId],
deployments,
skipVerify: network.name === 'klaytn',
skipVerify: networkName === 'klaytn',
});
}
};

module.exports.skip = async () => true;
module.exports.skip = async () => false;