Skip to content
LogoLogo

WeirollComponent

Git Source

Inherits: IWeirollComponent

Constants

MAX_BPS

Full scale value in basis points

uint256 private constant MAX_BPS = 10_000;

ACCOUNTING_OUTPUT_STATE_END

Flag to indicate end of values in the accounting output state.

bytes32 private constant ACCOUNTING_OUTPUT_STATE_END = bytes32(type(uint256).max);

MANAGED_POSITION_ID_SLOT

bytes32 private constant MANAGED_POSITION_ID_SLOT =
        0xfbb6b868544e1f69cf175881d715d83b048bd3f24bc7e327034891f3b849d600;

IS_MANAGED_POSITION_DEBT_SLOT

bytes32 private constant IS_MANAGED_POSITION_DEBT_SLOT =
        0x4e4b4e291d20f6f03003921c4d26de1006021d95c6c1641168790b4e4b3b7200;

IS_MANAGING_FLASHLOAN_SLOT

bytes32 private constant IS_MANAGING_FLASHLOAN_SLOT =
        0x8af85af09dfd26c2dc59ce2f32b0ca3422706a314bdc173e6610c5138eba2b00;

weirollVm

Address of the Weiroll VM.

address public immutable weirollVm;

Returns

NameTypeDescription
<none>address

State Variables

_lastGuardedExecTimestamps

mapping(bytes32 executionHash => uint256 timestamp) private _lastGuardedExecTimestamps;

allowedInstrRoot

Root of the Merkle tree containing allowed instructions.

bytes32 public allowedInstrRoot;

Returns

NameTypeDescription
<none>bytes32

accountingCurrency

Currency used to value positions.

If set to address(0), the reference currency of the OracleRegistry is used.

address public accountingCurrency;

Returns

NameTypeDescription
<none>address

maxPositionIncreaseLossBps

Max allowed value loss (in basis points) when increasing a position while in WALLED mode.

uint256 public maxPositionIncreaseLossBps;

Returns

NameTypeDescription
<none>uint256

maxPositionDecreaseLossBps

Max allowed value loss (in basis points) when decreasing a position while in WALLED mode.

uint256 public maxPositionDecreaseLossBps;

Returns

NameTypeDescription
<none>uint256

instrCooldownDuration

Cooldown duration for instruction executions in seconds.

uint256 public instrCooldownDuration;

Returns

NameTypeDescription
<none>uint256

Functions

constructor

constructor(address _weirollVm);

Parameters

NameTypeDescription
_weirollVmaddress

_managePosition

Manages and accounts for a position by executing the provided instructions.

function _managePosition(
        Instruction calldata mgmtInstruction,
        Instruction calldata acctInstruction,
        bool guarded,
        address safe
    ) internal returns (uint256 value, int256 change);

Parameters

NameTypeDescription
mgmtInstructionInstruction
acctInstructionInstruction
guardedbool
safeaddress

Returns

NameTypeDescription
valueuint256
changeint256

_manageFlashLoan

Manages and refunds flash loan funds.

function _manageFlashLoan(
        Instruction calldata instruction,
        address token,
        uint256 amount,
        address safe,
        address flashLoanModule
    ) internal;

Parameters

NameTypeDescription
instructionInstruction
tokenaddress
amountuint256
safeaddress
flashLoanModuleaddress

_accountForPosition

Computes the accounting value of a position.

function _accountForPosition(Instruction calldata instruction, bool checks, address safe)
        internal
        returns (uint256);

Parameters

NameTypeDescription
instructionInstruction
checksbool
safeaddress

Returns

NameTypeDescription
<none>uint256

_harvest

Internal logic to harvest one or multiple positions.

function _harvest(IWeirollComponent.Instruction calldata instruction, address safe) internal;

Parameters

NameTypeDescription
instructionIWeirollComponent.Instruction
safeaddress

_decodeAccountingOutputState

Decodes the output state of an accounting instruction into an array of amounts.

function _decodeAccountingOutputState(bytes[] memory state) internal pure returns (uint256[] memory);

Parameters

NameTypeDescription
statebytes[]

Returns

NameTypeDescription
<none>uint256[]

_checkPositionMinDelta

Checks that absolute position value change is greater than minimum value relative to affected token balance changes and loss tolerance.

function _checkPositionMinDelta(uint256 positionValChange, uint256 affectedTokensValChange, uint256 maxLossBps)
        internal
        pure;

Parameters

NameTypeDescription
positionValChangeuint256
affectedTokensValChangeuint256
maxLossBpsuint256

_checkPositionMaxDelta

Checks that absolute position value change is less than maximum value relative to affected token balance changes and loss tolerance.

function _checkPositionMaxDelta(uint256 positionValChange, uint256 affectedTokensValChange, uint256 maxLossBps)
        internal
        pure;

Parameters

NameTypeDescription
positionValChangeuint256
affectedTokensValChangeuint256
maxLossBpsuint256

_checkInstructionIsAllowed

Checks if the given instruction is allowed by verifying its Merkle proof against the allowed instructions root.

function _checkInstructionIsAllowed(Instruction calldata instruction) internal view;

Parameters

NameTypeDescription
instructionInstructionThe instruction to check.

_getStateHash

Computes a hash of the state array, selectively including elements as specified by a bitmap. This enables a Weiroll script to have both fixed and variable parameters.

function _getStateHash(bytes[] calldata state, uint128 bitmap) internal pure returns (bytes32);

Parameters

NameTypeDescription
statebytes[]The state array to hash.
bitmapuint128The bitmap where each bit determines whether the corresponding element in state is included or ignored in the hash computation.

Returns

NameTypeDescription
<none>bytes32hash The hash of the state array.

_aggregateTokensValue

Computes the total value of the token balances held by the Safe, priced in given currency.

function _aggregateTokensValue(address[] calldata tokens, address safe) internal view returns (uint256);

Parameters

NameTypeDescription
tokensaddress[]
safeaddress

Returns

NameTypeDescription
<none>uint256

_setAllowedInstrRoot

Internal logic to set the root of the Merkle tree containing allowed instructions.

function _setAllowedInstrRoot(bytes32 newAllowedInstrRoot) internal;

Parameters

NameTypeDescription
newAllowedInstrRootbytes32

_setAccountingCurrency

Internal logic to set the accounting currency.

function _setAccountingCurrency(address newAccountingCurrency) internal;

Parameters

NameTypeDescription
newAccountingCurrencyaddress

_setMaxPositionIncreaseLossBps

Internal logic to set the maximum allowed relative value loss for position increases.

function _setMaxPositionIncreaseLossBps(uint256 newMaxPositionIncreaseLossBps) internal;

Parameters

NameTypeDescription
newMaxPositionIncreaseLossBpsuint256

_setMaxPositionDecreaseLossBps

Internal logic to set the maximum allowed relative value loss for position decreases.

function _setMaxPositionDecreaseLossBps(uint256 newMaxPositionDecreaseLossBps) internal;

Parameters

NameTypeDescription
newMaxPositionDecreaseLossBpsuint256

_setInstrCooldownDuration

Internal logic to set the cooldown duration for instruction executions.

function _setInstrCooldownDuration(uint256 newInstrCooldownDuration) internal;

Parameters

NameTypeDescription
newInstrCooldownDurationuint256

_execute

Instructs the Safe to execute a set of commands via a delegatecall to the Weiroll VM.

function _execute(bytes32[] calldata commands, bytes[] memory state, address safe)
        internal
        returns (bytes[] memory);

Parameters

NameTypeDescription
commandsbytes32[]The commands to execute.
statebytes[]The state to pass to the VM.
safeaddressThe Safe to dispatch the delegatecall.

Returns

NameTypeDescription
<none>bytes[]outState The new state after executing the commands.

_checkAndSetCooldown

Checks cooldown for a given guarded execution and updates its last timestamp.

function _checkAndSetCooldown(bytes32 executionHash) internal;

Parameters

NameTypeDescription
executionHashbytes32

_valueOf

Returns the value of baseTokenAmount of baseToken denominated in quoteToken, using the registered price route.

function _valueOf(address baseToken, address quoteToken, uint256 baseTokenAmount)
        internal
        view
        virtual
        returns (uint256);

Parameters

NameTypeDescription
baseTokenaddress
quoteTokenaddress
baseTokenAmountuint256

Returns

NameTypeDescription
<none>uint256

_refundFlashLoan

Transfers amount of ERC20 token from the Safe to the flash loan module via a module call.

function _refundFlashLoan(address token, uint256 amount, address flashLoanModule) internal virtual;

Parameters

NameTypeDescription
tokenaddress
amountuint256
flashLoanModuleaddress