Vault Asset Normalization
The KarakStakeViewer
contract is designed to provide stake distribution information in USD for operators registered with the DSS. It integrates oracles to fetch asset prices for converting stake values into USD. A new KarakStakeViewer
contract can be deployed or existing address can be used.
Configuration:
- The owner must configure the oracle data for each asset using the
setOracle()
function. - Currently, only Chainlink oracles are supported.
Usage:
- The
getStakeDistributionUSDForOperators
function calculates the USD value of the requested operators' active stakes across staked vaults. It iterates through the supplied list of operators, retrieves their active vaults (vaults not queued for unstaking), and identifies the active tokens in each vault (tokens not queued for withdrawal). The function then converts the vault's active token balances into USD using the associated oracle.
Example:
Deploy a new karakStakeViewer.
KarakStakeViewer karakStakeViewerProxy = KarakStakeViewer(new TransparentUpgradableProxy())
karakStakeViewerProxy.initialize(ownerAddress, coreAddress);
Set the oracle data for each asset.
// caller must be owner
Oracle memory oracle;
oracle.oracleType = OracleType.Chainlink;
oracle.maxStaleness = 3600; // 1 hour staleness
oracle.oracle = abi.encode(ChainlinkOracle(chainlinkAggregatorAddress));
karakStakeViewerProxy.setOracle(tokenAddress, oracle);
Fetching Stake Distribution for a Set of Operators
address[] memory operators = new address[](2);
operators[0] = operator1;
operators[1] = operator2;
StakeDistribution memory distribution =
karakStakeViewerProxy.getStakeDistributionUSDForOperators(dssAddress, operators, "");
struct StakeComponent {
address erc20;
address vault;
uint256 balance;
uint256 usdValue;
}
struct OperatorStake {
address operator;
uint256 totalUsdValue;
StakeComponent[] components;
}
struct StakeDistribution {
uint256 globalUsdValue;
OperatorStake[] operators;
}