ManagedWeightStrategy

Git Source

Inherits: WeightStrategy, AccessControlEnumerable

A custom weight strategy that allows manual setting of target weights for a basket.

Inherits from WeightStrategy and AccessControlEnumerable for role-based access control.

State Variables

targetWeights

Maps each rebalance bit flag to the corresponding target weights.

mapping(uint256 bitFlag => uint64[] weights) public targetWeights;

lastUpdated

Maps each bit flag to the last updated epoch and timestamp.

mapping(uint256 bitFlag => LastUpdated) public lastUpdated;

_MANAGER_ROLE

Role identifier for the manager role.

bytes32 internal constant _MANAGER_ROLE = keccak256("MANAGER_ROLE");

_WEIGHT_PRECISION

Precision for weights. All results from getTargetWeights() should sum to _WEIGHT_PRECISION.

uint64 internal constant _WEIGHT_PRECISION = 1e18;

_basketManager

Address of the BasketManager contract associated with this strategy.

address internal immutable _basketManager;

Functions

constructor

Constructor for the ManagedWeightStrategy contract.

constructor(address admin, address basketManager) payable;

Parameters

NameTypeDescription
adminaddressThe address of the admin who will have DEFAULT_ADMIN_ROLE and MANAGER_ROLE.
basketManageraddressThe address of the BasketManager contract associated with this strategy.

setTargetWeights

Sets the target weights for the assets for the next epoch. If a rebalance is in progress, the weights will apply to the next epoch.

Only callable by accounts with the MANAGER_ROLE.

function setTargetWeights(uint256 bitFlag, uint64[] calldata newTargetWeights) external onlyRole(_MANAGER_ROLE);

Parameters

NameTypeDescription
bitFlaguint256The bit flag representing the assets.
newTargetWeightsuint64[]The array of target weights for each asset.

getTargetWeights

Retrieves the target weights for the assets in the basket for a given epoch and bit flag.

function getTargetWeights(uint256 bitFlag) public view override returns (uint64[] memory weights);

Parameters

NameTypeDescription
bitFlaguint256The bit flag representing the assets.

Returns

NameTypeDescription
weightsuint64[]The target weights for the assets.

supportsBitFlag

Checks if the strategy supports the given bit flag, representing a list of assets.

function supportsBitFlag(uint256 bitFlag) public view virtual override returns (bool);

Parameters

NameTypeDescription
bitFlaguint256The bit flag representing the assets.

Returns

NameTypeDescription
<none>boolA boolean indicating whether the strategy supports the given bit flag.

Events

TargetWeightsUpdated

Emitted when target weights are updated.

event TargetWeightsUpdated(uint256 indexed bitFlag, uint256 indexed epoch, uint256 timestamp, uint64[] newWeights);

Parameters

NameTypeDescription
bitFlaguint256The bit flag representing the assets.
epochuint256The epoch for which the weights are updated for.
timestampuint256The timestamp of the update.
newWeightsuint64[]The new target weights.

Errors

UnsupportedBitFlag

Error thrown when an unsupported bit flag is provided.

error UnsupportedBitFlag();

InvalidWeightsLength

Error thrown when the length of the weights array does not match the number of assets.

error InvalidWeightsLength();

WeightsSumMismatch

Error thrown when the sum of the weights does not equal _WEIGHT_PRECISION (100%).

error WeightsSumMismatch();

NoTargetWeights

Error thrown when no target weights are set for the given epoch and bit flag.

error NoTargetWeights();

Structs

LastUpdated

Struct to store the last updated epoch and timestamp for a bit flag.

struct LastUpdated {
    uint40 epoch;
    uint40 timestamp;
}