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.
131 lines
5.4 KiB
TypeScript
131 lines
5.4 KiB
TypeScript
/**
|
|
* Interact with deployed IMMBOT contracts
|
|
* Usage: npx hardhat run scripts/interact-contracts.ts --network bscTestnet
|
|
*/
|
|
|
|
import { ethers } from "hardhat";
|
|
|
|
async function main() {
|
|
console.log("\n๐ Interacting with IMMBOT Contracts...\n");
|
|
|
|
// Get signer
|
|
const [signer] = await ethers.getSigners();
|
|
console.log(`Using account: ${signer.address}`);
|
|
|
|
const balance = await ethers.provider.getBalance(signer.address);
|
|
console.log(`BNB Balance: ${ethers.formatEther(balance)} BNB\n`);
|
|
|
|
// Get contract addresses from environment
|
|
const tokenAddress = process.env.IMMBOT_TOKEN_ADDRESS;
|
|
const stakingAddress = process.env.STAKING_CONTRACT_ADDRESS;
|
|
|
|
if (!tokenAddress || !stakingAddress) {
|
|
throw new Error(
|
|
"Contract addresses not set in .env. Please set IMMBOT_TOKEN_ADDRESS and STAKING_CONTRACT_ADDRESS"
|
|
);
|
|
}
|
|
|
|
console.log(`Token Address: ${tokenAddress}`);
|
|
console.log(`Staking Address: ${stakingAddress}\n`);
|
|
|
|
// Get contract instances
|
|
const token = await ethers.getContractAt("IMMBotToken", tokenAddress);
|
|
const staking = await ethers.getContractAt("IMMBotStaking", stakingAddress);
|
|
|
|
console.log("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ");
|
|
console.log("๐ Token Information");
|
|
console.log("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\n");
|
|
|
|
const name = await token.name();
|
|
const symbol = await token.symbol();
|
|
const decimals = await token.decimals();
|
|
const totalSupply = await token.totalSupply();
|
|
const userBalance = await token.balanceOf(signer.address);
|
|
|
|
console.log(`Name: ${name}`);
|
|
console.log(`Symbol: ${symbol}`);
|
|
console.log(`Decimals: ${decimals}`);
|
|
console.log(`Total Supply: ${ethers.formatEther(totalSupply)} ${symbol}`);
|
|
console.log(`Your Balance: ${ethers.formatEther(userBalance)} ${symbol}\n`);
|
|
|
|
console.log("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ");
|
|
console.log("๐ฆ Staking Information");
|
|
console.log("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\n");
|
|
|
|
const totalStaked = await staking.totalStaked();
|
|
const rewardPool = await staking.rewardPool();
|
|
const minStake = await staking.MIN_STAKE();
|
|
|
|
console.log(`Total Staked: ${ethers.formatEther(totalStaked)} ${symbol}`);
|
|
console.log(`Reward Pool: ${ethers.formatEther(rewardPool)} ${symbol}`);
|
|
console.log(`Minimum Stake: ${ethers.formatEther(minStake)} ${symbol}\n`);
|
|
|
|
console.log("Staking Tiers:");
|
|
for (let i = 0; i < 4; i++) {
|
|
try {
|
|
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 ? " โ
" : " โ"}`
|
|
);
|
|
} catch {
|
|
break;
|
|
}
|
|
}
|
|
console.log("");
|
|
|
|
// Get user stakes
|
|
const userStakes = await staking.getUserStakes(signer.address);
|
|
const pendingRewards = await staking.getPendingRewards(signer.address);
|
|
|
|
console.log(`Your Stakes: ${userStakes.length}`);
|
|
if (userStakes.length > 0) {
|
|
for (let i = 0; i < userStakes.length; i++) {
|
|
const stake = userStakes[i];
|
|
if (Number(stake.amount) > 0) {
|
|
const reward = await staking.calculateReward(signer.address, i);
|
|
const tier = await staking.tiers(stake.tier);
|
|
const durationDays = Number(tier.duration) / 86400;
|
|
const stakedTime = Math.floor(
|
|
(Date.now() / 1000 - Number(stake.stakedAt)) / 86400
|
|
);
|
|
|
|
console.log(`\n Stake #${i}:`);
|
|
console.log(` Amount: ${ethers.formatEther(stake.amount)} ${symbol}`);
|
|
console.log(` Tier: ${stake.tier} (${durationDays} days)`);
|
|
console.log(` Staked: ${stakedTime} days ago`);
|
|
console.log(` Pending Reward: ${ethers.formatEther(reward)} ${symbol}`);
|
|
}
|
|
}
|
|
}
|
|
|
|
console.log(`\nTotal Pending Rewards: ${ethers.formatEther(pendingRewards)} ${symbol}\n`);
|
|
|
|
console.log("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ");
|
|
console.log("โ๏ธ Available Actions");
|
|
console.log("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\n");
|
|
|
|
console.log("To perform actions, use these commands:\n");
|
|
|
|
console.log("1. Approve staking contract to spend tokens:");
|
|
console.log(` npx hardhat run scripts/actions/approve.ts --network bscTestnet\n`);
|
|
|
|
console.log("2. Stake tokens:");
|
|
console.log(` npx hardhat run scripts/actions/stake.ts --network bscTestnet\n`);
|
|
|
|
console.log("3. Unstake tokens:");
|
|
console.log(` npx hardhat run scripts/actions/unstake.ts --network bscTestnet\n`);
|
|
|
|
console.log("4. Add rewards to staking pool:");
|
|
console.log(` npx hardhat run scripts/actions/add-rewards.ts --network bscTestnet\n`);
|
|
}
|
|
|
|
main()
|
|
.then(() => process.exit(0))
|
|
.catch((error) => {
|
|
console.error("\nโ Error:");
|
|
console.error(error);
|
|
process.exit(1);
|
|
});
|