Skip to content

Latest commit

 

History

History
252 lines (195 loc) · 5.35 KB

File metadata and controls

252 lines (195 loc) · 5.35 KB

StakePass Smart Contract Deployment Guide

Prerequisites

  1. Install Foundry
curl -L https://foundry.paradigm.xyz | bash
foundryup
  1. Install Dependencies
cd stakepass-contract/contracts
forge install
  1. Setup Environment
cp .env.example .env
# Edit .env with your values

Local Testing

1. Start Local Network (Anvil)

# Terminal 1 - Start Anvil
anvil --fork-url https://public-en-baobab.klaytn.net

# Or without fork
anvil

2. Run Local Tests

# Run test suite
forge test -vv

# Run specific test
forge test --match-test testDeposit -vvv

# Run with gas report
forge test --gas-report

3. Deploy to Local Network

# Deploy and test locally
forge script script/LocalTest.s.sol --rpc-url http://127.0.0.1:8545 --broadcast -vvvv

Kaia Baobab Testnet Deployment

1. Get Test KLAY

  1. Visit Kaia Faucet
  2. Enter your wallet address
  3. Request test KLAY (you'll need it for gas)

2. Configure Environment

# Edit .env file
PRIVATE_KEY=your_private_key_here  # WITHOUT 0x prefix
ADMIN_ADDRESS=your_admin_address
TREASURY_ADDRESS=your_treasury_address
KAIASCAN_API_KEY=your_api_key  # Get from https://scope.klaytn.com/

3. Deploy to Baobab

# Dry run (simulation)
forge script script/DeployBaobab.s.sol --rpc-url $BAOBAB_RPC_URL -vvvv

# Deploy for real
forge script script/DeployBaobab.s.sol \
  --rpc-url $BAOBAB_RPC_URL \
  --private-key $PRIVATE_KEY \
  --broadcast \
  -vvvv

# Deploy with verification
forge script script/DeployBaobab.s.sol \
  --rpc-url $BAOBAB_RPC_URL \
  --private-key $PRIVATE_KEY \
  --broadcast \
  --verify \
  --etherscan-api-key $KAIASCAN_API_KEY \
  -vvvv

4. Save Deployment Addresses

After deployment, update your .env file with the deployed contract addresses:

BAOBAB_VAULT_ADDRESS=0x...
BAOBAB_YIELDKEY_ADDRESS=0x...
BAOBAB_PROVIDER_REGISTRY_ADDRESS=0x...
BAOBAB_AGGREGATOR_ADDRESS=0x...
BAOBAB_PRICE_ORACLE_ADDRESS=0x...
BAOBAB_KRWT_ADDRESS=0x...
BAOBAB_USDT_ADDRESS=0x...

Post-Deployment

1. Verify Contracts on Kaiascan

# Verify a specific contract
forge verify-contract \
  --chain-id 1001 \
  --compiler-version v0.8.21 \
  --num-of-optimizations 200 \
  --constructor-args $(cast abi-encode "constructor(address)" "0xYourAdminAddress") \
  0xYourContractAddress \
  ContractName \
  --etherscan-api-key $KAIASCAN_API_KEY

2. Mint Test Tokens

# Mint KRWT tokens
cast send $BAOBAB_KRWT_ADDRESS \
  "mint(address,uint256)" \
  $YOUR_ADDRESS \
  1000000000000 \
  --rpc-url $BAOBAB_RPC_URL \
  --private-key $PRIVATE_KEY

# Mint USDT tokens  
cast send $BAOBAB_USDT_ADDRESS \
  "mint(address,uint256)" \
  $YOUR_ADDRESS \
  1000000000 \
  --rpc-url $BAOBAB_RPC_URL \
  --private-key $PRIVATE_KEY

3. Test Deployment

# Check contract state
cast call $BAOBAB_VAULT_ADDRESS "admin()" --rpc-url $BAOBAB_RPC_URL

# Check token balance
cast call $BAOBAB_KRWT_ADDRESS \
  "balanceOf(address)" \
  $YOUR_ADDRESS \
  --rpc-url $BAOBAB_RPC_URL

Interacting with Deployed Contracts

Using Cast Commands

# Approve vault to spend tokens
cast send $BAOBAB_KRWT_ADDRESS \
  "approve(address,uint256)" \
  $BAOBAB_VAULT_ADDRESS \
  1000000000000 \
  --rpc-url $BAOBAB_RPC_URL \
  --private-key $PRIVATE_KEY

# Make a deposit
cast send $BAOBAB_VAULT_ADDRESS \
  "deposit((address,uint256,uint256,uint256,bytes))" \
  "($BAOBAB_KRWT_ADDRESS,100000000000,1,7776000,0x)" \
  --rpc-url $BAOBAB_RPC_URL \
  --private-key $PRIVATE_KEY

Using Forge Scripts

Create custom scripts in script/ directory for complex interactions.

Mainnet Deployment (Production)

⚠️ WARNING: Only deploy to mainnet after:

  • Complete security audit
  • Thorough testing on testnet
  • Multi-sig wallet setup
  • Emergency procedures in place
# Mainnet deployment (USE WITH EXTREME CAUTION)
forge script script/DeployMainnet.s.sol \
  --rpc-url $KAIA_MAINNET_RPC_URL \
  --private-key $PRIVATE_KEY \
  --broadcast \
  --verify \
  --etherscan-api-key $KAIASCAN_API_KEY \
  --slow \
  -vvvv

Troubleshooting

Common Issues

  1. "insufficient funds for gas"

    • Get test KLAY from faucet
    • Check your balance: cast balance $YOUR_ADDRESS --rpc-url $BAOBAB_RPC_URL
  2. "nonce too high"

    • Reset nonce: cast nonce $YOUR_ADDRESS --rpc-url $BAOBAB_RPC_URL
  3. Verification fails

    • Ensure constructor args are correct
    • Check compiler version matches
    • Verify optimizer settings
  4. RPC connection issues

Security Checklist

  • All admin keys are secured
  • Multi-sig wallet configured for production
  • Contracts audited by security firm
  • Emergency pause mechanism tested
  • Upgrade procedures documented
  • Monitoring and alerts configured
  • Incident response plan ready

Support

Contract Addresses (Testnet)

Contract Baobab Address
Vault TBD
YieldKey TBD
ProviderRegistry TBD
Aggregator TBD
PriceOracle TBD
TestKRWT TBD
TestUSDT TBD

Update this table after deployment