immortal-bnb/scripts/deploy-staking.ts
Claude 6baff3455c
feat: Add comprehensive smart contract deployment infrastructure
Smart Contract Setup:
- Add hardhat.config.ts for BSC testnet and mainnet deployment
  - Configured for Solidity 0.8.20
  - Optimizer enabled (200 runs)
  - BSC testnet and mainnet network configurations
  - BscScan verification integration

Deployment Scripts:
- Add deploy-token.ts for IMMBOT token deployment
  - Deploy ERC20 token with 1 billion supply
  - Automatic tax configuration (2% tax)
  - Built-in burn and liquidity mechanics
  - Post-deployment verification instructions

- Add deploy-staking.ts for staking contract deployment
  - Deploy staking contract with 4 tiers
  - Automatic tier configuration (5%-50% APY)
  - Integration with token contract
  - Set staking contract on token automatically

- Add interact-contracts.ts for contract interaction
  - View token and staking information
  - Check user balances and stakes
  - View pending rewards
  - Display available actions

- Add setup-contracts.sh for dependency installation
  - Install Hardhat and OpenZeppelin contracts
  - Install verification and testing tools
  - Setup TypeChain for type generation

Documentation:
- Add contracts/README.md with comprehensive guide
  - Contract overview and features
  - Setup and installation instructions
  - Deployment procedures (testnet and mainnet)
  - Contract verification guide
  - Interaction examples
  - Security considerations
  - Troubleshooting section
  - Gas optimization tips

Environment Updates:
- Add contract deployment variables to .env.example
  - BSCSCAN_API_KEY for verification
  - BSC_TESTNET_RPC and BSC_MAINNET_RPC
  - STAKING_CONTRACT_ADDRESS placeholder

This infrastructure enables complete smart contract deployment
and interaction for the IMMBOT token and staking ecosystem.
2025-11-08 19:48:32 +00:00

126 lines
4.7 KiB
TypeScript

/**
* Deploy IMMBOT Staking Contract
* Usage: npx hardhat run scripts/deploy-staking.ts --network bscTestnet
*
* Prerequisites: IMMBOT Token must be deployed first
*/
import { ethers } from "hardhat";
async function main() {
console.log("\n๐Ÿš€ Deploying IMMBOT Staking Contract...\n");
// Get deployer
const [deployer] = await ethers.getSigners();
console.log(`Deploying with account: ${deployer.address}`);
// Check balance
const balance = await ethers.provider.getBalance(deployer.address);
console.log(`Account balance: ${ethers.formatEther(balance)} BNB\n`);
if (balance === 0n) {
throw new Error("Deployer account has no BNB for gas fees");
}
// Get token address from environment or prompt
const tokenAddress = process.env.IMMBOT_TOKEN_ADDRESS;
if (!tokenAddress) {
throw new Error(
"IMMBOT_TOKEN_ADDRESS not set in .env file. Deploy token first using scripts/deploy-token.ts"
);
}
console.log(`IMMBOT Token Address: ${tokenAddress}\n`);
// Verify token contract exists
const code = await ethers.provider.getCode(tokenAddress);
if (code === "0x") {
throw new Error(`No contract found at address ${tokenAddress}`);
}
// Deploy staking contract
console.log("Deploying IMMBotStaking contract...");
const IMMBotStaking = await ethers.getContractFactory("IMMBotStaking");
const staking = await IMMBotStaking.deploy(tokenAddress);
await staking.waitForDeployment();
const stakingAddress = await staking.getAddress();
console.log("\nโœ… IMMBotStaking deployed successfully!");
console.log(`โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”`);
console.log(`Contract Address: ${stakingAddress}`);
console.log(`Token Address: ${tokenAddress}`);
console.log(`Network: ${(await ethers.provider.getNetwork()).name}`);
console.log(`Chain ID: ${(await ethers.provider.getNetwork()).chainId}`);
console.log(`Deployer: ${deployer.address}`);
console.log(`โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”\n`);
// Check staking tiers
console.log("๐Ÿ“Š Default Staking Tiers:");
for (let i = 0; i < 4; i++) {
const tier = await staking.tiers(i);
const durationDays = Number(tier.duration) / 86400;
const apy = Number(tier.apyBasisPoints) / 100;
console.log(` Tier ${i}: ${durationDays} days - ${apy}% APY${tier.active ? " (Active)" : ""}`);
}
console.log("");
// Wait for block confirmations (for verification)
console.log("Waiting for 5 block confirmations...");
await staking.deploymentTransaction()?.wait(5);
console.log("โœ… Confirmed!\n");
// Display next steps
console.log("๐Ÿ“ Next Steps:");
console.log(`1. Verify contract on BscScan:`);
console.log(` npx hardhat verify --network bscTestnet ${stakingAddress} ${tokenAddress}`);
console.log(`\n2. Set staking contract in token contract:`);
console.log(` Call setStakingContract(${stakingAddress}) on token contract`);
console.log(`\n3. Add to .env file:`);
console.log(` STAKING_CONTRACT_ADDRESS=${stakingAddress}`);
console.log(`\n4. Add to frontend .env:`);
console.log(` NEXT_PUBLIC_STAKING_TESTNET=${stakingAddress}`);
console.log(`\n5. Test staking functionality:`);
console.log(` - Approve token spending`);
console.log(` - Stake tokens`);
console.log(` - Check pending rewards`);
console.log(` - Unstake tokens`);
console.log("");
// Save deployment info
const deploymentInfo = {
network: (await ethers.provider.getNetwork()).name,
chainId: Number((await ethers.provider.getNetwork()).chainId),
stakingAddress,
tokenAddress,
deployer: deployer.address,
timestamp: new Date().toISOString(),
blockNumber: await ethers.provider.getBlockNumber(),
};
console.log("\n๐Ÿ“„ Deployment Info:");
console.log(JSON.stringify(deploymentInfo, null, 2));
console.log("");
// Optional: Set staking contract on token if we have access
console.log("๐Ÿ”— Setting staking contract on token...");
try {
const token = await ethers.getContractAt("IMMBotToken", tokenAddress);
const tx = await token.setStakingContract(stakingAddress);
await tx.wait();
console.log("โœ… Staking contract set on token successfully!\n");
} catch (error) {
console.log("โš ๏ธ Could not set staking contract on token automatically.");
console.log(" You may need to call setStakingContract() manually.\n");
}
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error("\nโŒ Deployment failed:");
console.error(error);
process.exit(1);
});