Skip to content

Commit

Permalink
add deployment scripts
Browse files Browse the repository at this point in the history
Signed-off-by: Pranay Valson <pranay.valson@gmail.com>
  • Loading branch information
noslav committed Dec 2, 2024
1 parent dd93c54 commit a57269d
Show file tree
Hide file tree
Showing 18 changed files with 1,633 additions and 1 deletion.
43 changes: 42 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ewm-light-contracts
# ewm-light-contracts

EWM light clients operator-controller NFT contracts, enabling NFT claim/mint, LC registration/delegation, rewards calculation and redemption on any EVM chain based on the [ERC4907](https://eips.ethereum.org/EIPS/eip-4907) non-transferrable "rental-nft" standard.

Expand Down Expand Up @@ -154,3 +154,44 @@ This deployment story outlines the process of setting up the entire NFT ecosyste
- Allow NFT holders to redeem their rewards
- Release stakes for expired NFTs


```bash
# deploy all the necessary contracts
npx hardhat run scripts/deployCxtTokenFaucet.js --network ${network}
npx hardhat run scripts/deployNftController.js --network ${network}
npx hardhat run scripts/deployNftClaim.js --network ${network}
npx hardhat run scripts/deployNftAllowance.js --network ${network}

# set contract metadata for use
npx hardhat run scripts/depositControllerRewardTokens.js --network ${network}
npx hardhat run scripts/setControllerNftExpiryRange.js --network ${network}
npx hardhat run scripts/setControllerNftBaseUrl.js --network ${network}

## set contracts for participation
npx hardhat run scripts/setClaimAllowanceContractsArray.js --network ${network}
npx hardhat run scripts/unpauseClaimContract.js --network ${network}
npx hardhat run scripts/distributeCxtFaucetToken.js --network ${network}
npx hardhat run scripts/setAllowanceWhitelistRootIntegerAllocation.js --network ${network}

# extras participants fns for staking and operations
npx hardhat run scripts/executeWhitelistedAllowance.js --network ${network}

## set for nft mint distribution
npx hardhat run scripts/setControllerMinterAdmin.js --network ${network}
npx hardhat run scripts/setControllerTransferWhitelistAndTime.js --network ${network}
npx hardhat run scripts/executeAdminBatchClaimAll.js --network ${network} or npx hardhat run scripts/executeAdminBatchClaimArray.js --network ${network}
npx hardhat run scripts/pauseClaimContract.js --network ${network}

## reward nft holders
npx hardhat run scripts/executeSetUserDelegateAndExpires.js --network ${network}
npx hardhat run scripts/rewardNftHolders.js --network ${network}
npx hardhat run scripts/redeemAllNftRewards.js --network ${network}

## post nfts expiry participants fns
npx hardhat run scripts/releaseStakeForExpiredNfts.js --network ${network}

# extras admin fns
npx hardhat run scripts/setClaimAdmin.js --network ${network}
npx hardhat run scripts/getAllMetadata.js --network ${network}
npx hardhat run scripts/setAllowanceExpiryTime.js --network ${network}
```
70 changes: 70 additions & 0 deletions scripts/depositControllerRewardTokens.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
const hre = require('hardhat');
const { ethers } = require('hardhat');
require('dotenv').config();
const { oneToken } = require('../test/helpers');

async function depositRewards() {
const [owner] = await ethers.getSigners();

console.log('Depositing rewards with the account:', owner.address);
console.log('Account balance:', (await owner.getBalance()).toString());

// Get addresses from environment variables
const NFT_CONTROLLER_ADDRESS = process.env.BASE_SEPOLIA_NFT_CONTROLLER;
const CXT_ADDRESS = process.env.BASE_SEPOLIA_CXT_FAUCET;

// Ensure the required environment variables are set
if (!NFT_CONTROLLER_ADDRESS || !CXT_ADDRESS) {
throw new Error('Required environment variables are not set');
}

console.log('NFT Controller Address:', NFT_CONTROLLER_ADDRESS);
console.log('CXT Address:', CXT_ADDRESS);

// Get the NFT Controller contract instance
const EwmNftController = await hre.ethers.getContractFactory('EwmNftController');
const nftController = await EwmNftController.attach(NFT_CONTROLLER_ADDRESS);

// Get the CXT token contract instance
const CXT = await hre.ethers.getContractFactory('CovalentXTokenFaucet');
const cxtToken = await CXT.attach(CXT_ADDRESS);

// Amount of tokens to deposit (e.g., 10 MIO based on 25% APY for CXT 10K LCs)
const depositAmount = oneToken.mul(10000000);

console.log('Approving CXT transfer...');
await cxtToken.connect(owner).approve(NFT_CONTROLLER_ADDRESS, depositAmount);

console.log('Depositing reward tokens...');
await nftController.connect(owner).depositRewardTokens(depositAmount);

console.log('Reward tokens deposited successfully');

// Get the contract metadata
const metadata = await nftController.getMetadata();
console.log('Contract Metadata:', metadata);

// Check if rewardPool exists and is a BigNumber
if (metadata._rewardPool && ethers.BigNumber.isBigNumber(metadata._rewardPool)) {
console.log('New reward balance:', ethers.utils.formatUnits(metadata._rewardPool, 18), 'CXT');
} else {
console.log('Reward pool balance:', metadata._rewardPool);
}
}

async function main() {
try {
await hre.run('compile');
await depositRewards();
} catch (error) {
console.error(error);
process.exit(1);
}
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
105 changes: 105 additions & 0 deletions scripts/distributeCxtFaucetToken.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
const hre = require('hardhat');
const { ethers } = require('hardhat');
const fs = require('fs');
const path = require('path');
require('dotenv').config();

async function distributeCxtTokens() {
const [owner] = await ethers.getSigners();

console.log('Distributing CXT tokens with the account:', owner.address);
console.log('Account balance:', (await owner.getBalance()).toString());

const CXT_FAUCET_ADDRESS = process.env.BASE_SEPOLIA_CXT_FAUCET;

if (!CXT_FAUCET_ADDRESS) {
throw new Error('Required environment variables are not set');
}

// Read whitelist addresses from JSON file
const whitelistFile = path.join(__dirname, 'data', 'tokenHolderWhitelistBaseSepolia.json');

let whitelistAddresses;
try {
const fileContent = fs.readFileSync(whitelistFile, 'utf8');
const fileData = JSON.parse(fileContent);
whitelistAddresses = fileData.addresses;
} catch (error) {
console.error('Error reading whitelist file:', error);
process.exit(1);
}

// Specify which indices to distribute to and their NFT counts
const distributionConfig = {
0: 366, // First address gets 67 NFTs
// 1: 67, // Second address gets 67 NFTs
// 2: 100, // Third address gets 100 NFTs
// 3: 200, // Fourth address gets 100 NFTs
};

const NFT_PRICE = ethers.utils.parseUnits('5000', 18); // 5000 CXT per NFT

// Create distribution data only for specified indices
const whitelistData = Object.entries(distributionConfig).map(([index, nftCount]) => ({
address: whitelistAddresses[index],
nftCount,
index: parseInt(index),
}));

console.log('\n=== Distribution Configuration ===');
console.log('CXT Faucet Address:', CXT_FAUCET_ADDRESS);
console.log('NFT Price:', ethers.utils.formatUnits(NFT_PRICE, 18), 'CXT');

console.log('\n=== Distribution Details ===');
whitelistData.forEach(({ address, nftCount, index }) => {
console.log(`Index ${index}: ${address} will receive tokens for ${nftCount} NFTs`);
console.log(`Amount: ${ethers.utils.formatUnits(NFT_PRICE.mul(nftCount), 18)} CXT\n`);
});

const CxtFaucet = await hre.ethers.getContractFactory('CovalentXTokenFaucet');
const cxtFaucet = await CxtFaucet.attach(CXT_FAUCET_ADDRESS);

console.log('\n=== Starting Distribution ===');
for (const { address, nftCount, index } of whitelistData) {
const distributionAmount = NFT_PRICE.mul(nftCount);

try {
const tx = await cxtFaucet.connect(owner).faucet(address, distributionAmount);
const receipt = await tx.wait();
console.log(
`✅ Index ${index}: Transferred ${ethers.utils.formatUnits(distributionAmount, 18)} CXT to ${address}`,
);
console.log(` Transaction hash: ${receipt.transactionHash}\n`);
} catch (error) {
console.error(`❌ Error transferring tokens to index ${index} (${address}):`, error.message);
}
}

console.log('\n=== Distribution Summary ===');
const balance = await cxtFaucet.balanceOf(owner.address);
console.log('Remaining CXT balance of owner:', ethers.utils.formatUnits(balance, 18));

// Calculate total distributed
const totalDistributed = whitelistData.reduce(
(acc, { nftCount }) => acc.add(NFT_PRICE.mul(nftCount)),
ethers.BigNumber.from(0),
);
console.log('Total CXT distributed:', ethers.utils.formatUnits(totalDistributed, 18));
}

async function main() {
try {
await hre.run('compile');
await distributeCxtTokens();
} catch (error) {
console.error(error);
process.exit(1);
}
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
103 changes: 103 additions & 0 deletions scripts/executeAdminBatchClaimAll.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
const hre = require('hardhat');
const { ethers } = require('hardhat');
require('dotenv').config();
const fs = require('fs');
const path = require('path');

async function adminBatchClaimNfts() {
const [, claimAdmin] = await ethers.getSigners();

console.log('Performing admin batch claim with the account:', claimAdmin.address);
console.log('Account balance:', (await claimAdmin.getBalance()).toString());

const NFT_CLAIM_ADDRESS = process.env.BASE_SEPOLIA_NFT_CLAIM;
const NFT_CONTROLLER_ADDRESS = process.env.BASE_SEPOLIA_NFT_CONTROLLER;

if (!NFT_CLAIM_ADDRESS || !NFT_CONTROLLER_ADDRESS) {
throw new Error('Required environment variables are not set');
}

console.log('NFT Claim Address:', NFT_CLAIM_ADDRESS);
console.log('NFT Controller Address:', NFT_CONTROLLER_ADDRESS);

// Read whitelist addresses from JSON file
const whitelistFile = path.join(
__dirname,
'..',
'scripts',
'data',
'tokenHolderWhitelistBaseSepolia.json',
);
let whitelistAddresses;
try {
const fileContent = fs.readFileSync(whitelistFile, 'utf8');
const fileData = JSON.parse(fileContent);
whitelistAddresses = fileData.addresses;
} catch (error) {
console.error('Error reading whitelist file:', error);
process.exit(1);
}

// Get the NFT Claim contract instance
const EwmNftClaim = await hre.ethers.getContractFactory('EwmNftClaim');
const claimContract = await EwmNftClaim.attach(NFT_CLAIM_ADDRESS);

// Get the NFT Controller contract instance
const EwmNftController = await hre.ethers.getContractFactory('EwmNftController');
const controllerContract = await EwmNftController.attach(NFT_CONTROLLER_ADDRESS);

console.log('Checking unclaimed NFT counts for each address...');
const unclaimedCounts = await Promise.all(
whitelistAddresses.map(async (address) => {
const count = await claimContract.unClaimedNftCount(address);
console.log(`Address: ${address}, Unclaimed NFT count: ${count.toString()}`);
return { address, unclaimedCount: count.toNumber() };
}),
);

// Filter out addresses with 0 unclaimed NFTs
const addressesToClaim = unclaimedCounts
.filter(({ unclaimedCount }) => unclaimedCount > 0)
.map(({ address }) => address);

if (addressesToClaim.length === 0) {
console.log('No addresses with unclaimed NFTs found.');
return;
}

console.log('Addresses to claim:', addressesToClaim);
console.log('Unclaimed counts:', unclaimedCounts);

// Perform admin batch claim
try {
const tx = await claimContract.connect(claimAdmin).adminBatchClaimAll(addressesToClaim);
await tx.wait();
console.log('Admin batch claim successful');
} catch (error) {
console.error('Error performing admin batch claim:', error.message);
return;
}

// Check NFT balances after claim
for (const address of addressesToClaim) {
const balance = await controllerContract.balanceOf(address);
console.log(`NFT balance for ${address}: ${balance.toString()}`);
}
}

async function main() {
try {
await hre.run('compile');
await adminBatchClaimNfts();
} catch (error) {
console.error(error);
process.exit(1);
}
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
Loading

0 comments on commit a57269d

Please sign in to comment.