yearn / risk-framework

2 stars 0 forks source link

Risk Framework Onchain

How to Calculate the Scores in Uint

Let's say, we want to score a target address using these 7 scores:

Scores: 5, 4, 3, 2, 1, 2, and 3.

If we convert each score into binary, each one is:

Scores: 00101, 00100, 00011, 00010, 00001, 00010 and 00011

But if we join all the binary values in one number:

101001000001100010000010001000011

The decimal representation is: 5506139203

That is the value we use to call the Risk Framework onchain.

The values are manipulated by bitwise operators in the library ScoresLib.sol.

Considerations

Scores

The scores must be set in this order:

How to Get the Decimal Score from List of Scores

How to Get the List of Scores from Decimal Score

Deployment Scripts

RiskFramework Contract

forge create --rpc-url <your_rpc_url> --constructor-args 0x757f29A77D90a45b188c095A04aFa19F497c8B0E 0x757f29A77D90a45b188c095A04aFa19F497c8B0E 6 --private-key <your_private_key> --etherscan-api-key <your_etherscan_api_key> --verify contracts/RiskFramework.sol:RiskFramework

ImpactCalculator Contract

This script uses the create2 opcode to pre-defined the contract address:

forge script ./script/ImpactCalculator.s.sol:ImpactCalculatorScript --rpc-url <rpc-url> --etherscan-api-key <etherscan-api-key> --broadcast --verify -vvvv

forge create --rpc-url <your_rpc_url> --private-key <your_private_key> --etherscan-api-key <your_etherscan_api_key> --verify contracts/lens/ImpactCalculator.sol:ImpactCalculator

Deployment Addresses

More info here.

Scripts

More info here.

Network IDs

How to Verify Whether a Target is Supported in The ORF or Not

uint256 networkId = ...;
address target = 0x...;
(
    uint128 scores,
    uint8[] memory scoresList,
    uint128 averageScore,
    bytes32[] memory tagsList,
    bool isActive
) = riskFramework.getTargetInfo(networkId, target);
require(scores > 0 && isActive);