API Reference
This document provides detailed information about the Zhenglong Protocol's smart contract interfaces and functions.
Contract Addresses
Main Contracts
// Market Configuration
MarketConfig: {
id: "steth-usd",
name: "stETH/USD",
description: "Lido Staked ETH / US Dollar",
addresses: {
collateralToken: "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0",
feeReceiver: "0xFC69e0a5823E2AfCBEb8a35d33588360F1496a00",
genesis: "0x222D74f33b0d07687a769A44399E2272A4cB9FfE",
leveragedToken: "0x7945b0A6674b175695e5d1D08aE1e6F13744Abb0",
minter: "0x222D74f33b0d07687a769A44399E2272A4cB9FfE",
owner: "0xFC69e0a5823E2AfCBEb8a35d33588360F1496a00",
peggedToken: "0x7945b0A6674b175695e5d1D08aE1e6F13744Abb0",
priceOracle: "0x97541208c6C8ecfbe57B8A44ba86f2A88bA783e2",
stabilityPoolCollateral: "0x7c77704007C9996Ee591C516f7319828BA49d91E",
stabilityPoolLeveraged: "0x081F08945fd17C5470f7bCee23FB57aB1099428E",
reservePool: "0x91c8C745fd156d8624677aa924Cdc1Ef8173C69C"
}
}
Core Interfaces
Minter Contract
interface IMinter {
// View Functions
function collateralTokenBalance() external view returns (uint256);
function totalCollateralValue() external view returns (uint256);
function totalPeggedValue() external view returns (uint256);
function totalLeveragedValue() external view returns (uint256);
function collateralRatio() external view returns (uint256);
// Events
event LeveragedTokenMinted(
address indexed user,
uint256 collateralAmount,
uint256 tokenAmount,
uint256 timestamp
);
event LeveragedTokenRedeemed(
address indexed user,
uint256 tokenAmount,
uint256 collateralAmount,
uint256 timestamp
);
}
Stability Pool Contract
interface IStabilityPool {
// View Functions
function getDepositAmount(address user) external view returns (uint256);
function getRewards(address user) external view returns (uint256);
function getAPR() external view returns (uint256);
// State-Changing Functions
function deposit(uint256 amount) external;
function withdraw(uint256 amount) external;
function claimRewards() external;
}
Price Oracle Contract
interface IPriceOracle {
// View Functions
function getPrice(address token) external view returns (uint256);
function getRoundData(uint80 roundId) external view returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
}
Integration Examples
Reading Market Data
import { ethers } from "ethers";
import { markets } from "@zhenglong/config";
const provider = new ethers.providers.Web3Provider(window.ethereum);
const market = markets["steth-usd"];
// Get collateral ratio
const minter = new ethers.Contract(
market.addresses.minter,
minterABI,
provider
);
const collateralRatio = await minter.collateralRatio();
// Get current price
const priceOracle = new ethers.Contract(
market.addresses.priceOracle,
priceOracleABI,
provider
);
const price = await priceOracle.getPrice(market.addresses.peggedToken);
Interacting with Stability Pools
// Deposit into stability pool
const stabilityPool = new ethers.Contract(
market.addresses.stabilityPoolCollateral,
stabilityPoolABI,
signer
);
await stabilityPool.deposit(ethers.utils.parseEther("1.0"));
// Claim rewards
await stabilityPool.claimRewards();
Error Codes
enum RebalancePoolError {
ErrorWrapperSrcMismatch,
ErrorWrapperDstMismatch,
DepositZeroAmount,
DepositAmountLessThanMinimum,
WithdrawZeroAmount,
WithdrawAmountExceedsBalance,
collateralRatioTooHigh,
NotEnoughTokensToLiquidate,
InvalidLiquidationToken,
ErrorSelfSharingIsNotAllowed,
ErrorCascadedSharingIsNotAllowed,
ErrorVoteShareNotAllowed,
ErrorNoAcceptedSharedVote,
ErrorVoteOwnerCannotStake,
ErrorRepeatAcceptSharedVote,
RewardClaimFailed
}
Event Indexing
Stability Pool Events
event Deposit(
address indexed user,
uint256 amount,
uint256 timestamp
);
event Withdraw(
address indexed user,
uint256 amount,
uint256 timestamp
);
event RewardsClaimed(
address indexed user,
uint256 amount,
uint256 timestamp
);
Market Events
event PriceUpdated(
address indexed token,
uint256 price,
uint256 timestamp
);
event CollateralRatioUpdated(
uint256 oldRatio,
uint256 newRatio,
uint256 timestamp
);
Best Practices
-
Error Handling
- Always check return values
- Handle revert cases
- Implement proper error messages
- Use try-catch blocks
-
Gas Optimization
- Batch transactions when possible
- Use view functions for reading data
- Optimize storage access
- Consider gas costs
-
Security
- Validate all inputs
- Check access controls
- Implement proper checks
- Use safe math operations
-
Testing
- Write unit tests
- Test edge cases
- Implement integration tests
- Use test networks
Support
Need help with the API?
- Join our Discord