A comprehensive smart contract for distributing multiple token types (ICX, BALN, BNUSD) to users on the ICON blockchain. This repository contains the smart contract source code and management scripts for deploying, funding, and distributing rewards.
- Multi-Token Support: Distribute ICX, BALN, and BNUSD tokens
- Admin Management: Secure admin system with role-based access control
- Batch Operations: Efficiently add rewards to multiple users
- Automatic Claiming: Users can claim their rewards directly
- Contract Recovery: Admins can recover contract balances
- Event Logging: Comprehensive event tracking for all operations
- Smart Contract Methods
- Quick Start
- Installation & Setup
- Contract Management
- Scripts Reference
- Configuration
- Testing
Returns the BALN token contract address.
Returns the BNUSD token contract address.
Returns true
if the address is an admin, false
otherwise.
Returns the claimable ICX amount for the given user (in loop units).
Returns the claimable BALN amount for the given user (in loop units).
Returns the claimable BNUSD amount for the given user (in loop units).
Sets the BALN token contract address. Admin only.
Sets the BNUSD token contract address. Admin only.
Adds an admin to the contract. Contract owner only.
Removes an admin from the contract. Contract owner only.
Adds an ICX claim for a user. Admin only.
Adds a BALN claim for a user. Admin only.
Adds a BNUSD claim for a user. Admin only.
Claims ICX rewards for the caller.
Claims BALN rewards for the caller.
Claims BNUSD rewards for the caller.
Recovers ICX from contract to owner. Admin only.
Recovers BALN from contract to owner. Admin only.
Recovers BNUSD from contract to owner. Admin only.
# 1. Clone and install
git clone <repository-url>
cd rewards-distribution-javascore
npm install
# 2. Set up environment
cp .env.example .env
# Edit .env with your private key and network
# 3. Deploy contract
npm run deploy
# 4. Update .env with deployed contract address
# 5. Setup contracts (sets token addresses)
npm run setup-contract
# 6. Fund the contract
npm run icx-fund-contract
npm run baln-fund-contract
npm run bnusd-fund-contract
# 7. Add rewards to users
npm run add-icx-rewards
npm run add-baln-rewards
npm run add-bnusd-rewards
- Node.js (v14 or higher)
- Java 11 or higher
- Gradle
- ICON wallet with sufficient balance
Create a .env
file in the project root:
# Required: Your wallet private key
PRIVATE_KEY="your_private_key_here"
# Required: Network to deploy to
NETWORK="mainnet" # or "lisbon"
# Required: Contract address (set after deployment)
CONTRACT_ADDRESS=""
# Navigate to smart contract directory
cd smart-contract
# Compile using Gradle
./gradlew clean build optimizedJar
# Or use the provided Makefile
make clean-build
npm run deploy
Requirements:
- Valid private key in
.env
- Sufficient ICX balance (recommended: 200+ ICX)
- Correct network configuration
npm run setup-contract
This script:
- Sets the BALN token contract address
- Sets the BNUSD token contract address
- Validates the setup
npm run icx-fund-contract
npm run baln-fund-contract
npm run bnusd-fund-contract
Note: Update the FUND_AMOUNT
variable in the respective script files before running.
Edit data/users.json
:
[
{
"address": "hx0169...063",
"amount": "10"
},
{
"address": "hxf859...c62",
"amount": "20"
}
]
# Add ICX rewards
npm run add-icx-rewards
# Add BALN rewards
npm run add-baln-rewards
# Add BNUSD rewards
npm run add-bnusd-rewards
Script | Description | Usage |
---|---|---|
deploy |
Deploy the smart contract | npm run deploy |
update-contract |
Update existing contract | npm run update-contract |
setup-contract |
Configure token contracts | npm run setup-contract |
icx-fund-contract |
Fund contract with ICX | npm run icx-fund-contract |
baln-fund-contract |
Fund contract with BALN | npm run baln-fund-contract |
bnusd-fund-contract |
Fund contract with BNUSD | npm run bnusd-fund-contract |
add-icx-rewards |
Add ICX rewards to users | npm run add-icx-rewards |
add-baln-rewards |
Add BALN rewards to users | npm run add-baln-rewards |
add-bnusd-rewards |
Add BNUSD rewards to users | npm run add-bnusd-rewards |
Token addresses are configured in utils/config.js
:
token: {
BALN: {
mainnet: "cxf61cd5a45dc9f91c15aa65831a30a90d59a09619",
lisbon: "cxc3c552054ba6823107b56086134c2afc26ab1dfa"
},
BNUSD: {
mainnet: "cxf61cd5a45dc9f91c15aa65831a30a90d59a09619",
lisbon: "cx87f7f8ceaa054d46ba7343a2ecd21208e12913c6"
}
}
endpoint: {
mainnet: {
url: "ctz.solidwallet.io",
nid: 1
},
lisbon: {
url: "lisbon.net.solidwallet.io",
nid: 2
}
}
cd smart-contract
./gradlew clean test
The test suite covers:
- β ICX token functionality
- β BALN token functionality
- β BNUSD token functionality
- β Admin management
- β Access control
- β Error handling
- β Edge cases
- Role-based Access Control: Only admins can add claims
- Owner-only Admin Management: Only contract owner can add/remove admins
- Input Validation: All inputs are validated
- Event Logging: All operations emit events for transparency
- Safe Math: Uses BigInteger for precise calculations
The contract emits the following events:
AdminAdded(Address admin)
- When an admin is addedAdminRemoved(Address admin)
- When an admin is removedContractAdded(Address contract)
- When a token contract is setClaimAdded(Address user, BigInteger amount, String token)
- When a claim is addedClaimed(Address user, BigInteger amount, String token)
- When a user claims rewardsOwnerClaimed(Address owner, BigInteger amount, String token)
- When admin recovers funds
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
This project is licensed under the ISC License.
For issues and questions:
- Check the Issues page
- Review the test files for usage examples
- Consult the ICON documentation
Note: Always test on the Lisbon testnet before deploying to mainnet. Ensure you have sufficient balance for deployment and operations.