Skip to content
LogoLogo

MakinaXModule

Git Source

Inherits: MakinaXContext, MakinaXGovernable, OracleRegistry, WeirollComponent, SwapComponent, BridgeComponent, ReentrancyGuard, IMakinaXModule

Constants

MAX_BPS

Full scale value in basis points

uint256 private constant MAX_BPS = 10_000;

MAX_FEE_RATE

Full scale value for fee rates

uint256 private constant MAX_FEE_RATE = 1e18;

Functions

constructor

constructor(address _registry, address _weirollVm) MakinaXContext(_registry) WeirollComponent(_weirollVm);

Parameters

NameTypeDescription
_registryaddress
_weirollVmaddress

initialize

Initializes the module with the given parameters.

function initialize(MakinaXModuleInitParams calldata params, MakinaXModuleServiceParams calldata serviceParams)
        external
        override
        initializer;

Parameters

NameTypeDescription
paramsMakinaXModuleInitParamsThe strategy and risk initialization parameters.
serviceParamsMakinaXModuleServiceParamsThe protocol-controlled service initialization parameters.

receive

receive() external payable;

setFeedRoute

Sets the price feed route for a given token.

Both feeds, if set, must be Chainlink-interface-compliant. The combination of feed1 and feed2 must be able to price the token in the reference currency. If feed2 is set to address(0), the token price in the reference currency is assumed to be returned by feed1.

function setFeedRoute(
        address token,
        address feed1,
        uint256 stalenessThreshold1,
        address feed2,
        uint256 stalenessThreshold2
    ) external override nonReentrant onlySafe;

Parameters

NameTypeDescription
tokenaddressThe address of the token for which the price feed route is set.
feed1addressThe address of the first price feed.
stalenessThreshold1uint256The staleness threshold for the first price feed.
feed2addressThe address of the second price feed. Can be set to address(0).
stalenessThreshold2uint256The staleness threshold for the second price feed. Ignored if feed2 is address(0).

clearFeedRoute

Clears the price feed route for a given token.

Staleness thresholds for the route's feeds are preserved, as the feeds may be used by other routes.

function clearFeedRoute(address token) external override onlySafe;

Parameters

NameTypeDescription
tokenaddressThe address of the token for which the price feed route is cleared.

setFeedStaleThreshold

Sets the price staleness threshold for a given feed.

function setFeedStaleThreshold(address feed, uint256 newThreshold) external override onlySafe;

Parameters

NameTypeDescription
feedaddressThe address of the price feed.
newThresholduint256The value of staleness threshold.

accountForPosition

Prices a position.

function accountForPosition(IWeirollComponent.Instruction calldata instruction)
        external
        override
        nonReentrant
        whenOperational
        onlyOperator
        returns (uint256);

Parameters

NameTypeDescription
instructionIWeirollComponent.InstructionThe accounting instruction.

Returns

NameTypeDescription
<none>uint256The new position value.

accountForPositionBatch

Prices a batch of positions.

function accountForPositionBatch(IWeirollComponent.Instruction[] calldata instructions, uint256[] calldata)
        external
        override
        nonReentrant
        whenOperational
        onlyOperator
        returns (uint256[] memory);

Parameters

NameTypeDescription
instructionsIWeirollComponent.Instruction[]The array of accounting instructions.
_uint256[]Ignored parameter kept to preserve interface compatibility with Makina Core.

Returns

NameTypeDescription
<none>uint256[]The new position values.

managePosition

Manages a position's state through paired management and accounting instructions.

The WALLED mode matrix evaluates three factors to determine required validations:

  • Affected Tokens flow - Sign of the change in the Safe's aggregate value of mgmtInstruction.affectedTokens

  • Debt Position - Whether position represents protocol liability (true) vs asset (false)

  • Position Δ direction - Direction of position value change (increase/decrease/null)

┌──────────────────────┬───────────────┬──────────────────────┬───────────────────────────┐

│ Affected Tokens flow │ Debt Position │ Position Δ direction │ Action │

├──────────────────────┼───────────────┼──────────────────────┼───────────────────────────┤

│ Outflow │ No │ Decrease │ Revert: Invalid direction │

│ Outflow │ Yes │ Increase │ Revert: Invalid direction │

│ Outflow │ No │ Increase / Null │ Minimum Δ Check │

│ Outflow │ Yes │ Decrease / Null │ Minimum Δ Check │

│ Inflow / Null │ No │ Decrease │ Maximum Δ Check │

│ Inflow / Null │ Yes │ Increase │ Maximum Δ Check │

│ Inflow / Null │ No │ Increase / Null │ No check (favorable move) │

│ Inflow / Null │ Yes │ Decrease / Null │ No check (favorable move) │

└──────────────────────┴───────────────┴──────────────────────┴───────────────────────────┘

If acctInstruction is provided, it is executed before and after the management instruction to compute the new position value and its signed delta.

In WALLED mode, acctInstruction must be provided and value preservation checks are applied using a validation matrix to prevent economic inconsistencies between position changes and token flows.

function managePosition(
        IWeirollComponent.Instruction calldata mgmtInstruction,
        IWeirollComponent.Instruction calldata acctInstruction
    ) external override nonReentrant whenOperational onlyOperator returns (uint256, int256);

Parameters

NameTypeDescription
mgmtInstructionIWeirollComponent.InstructionThe management instruction.
acctInstructionIWeirollComponent.InstructionThe accounting instruction.

Returns

NameTypeDescription
<none>uint256The new position value, or 0 if acctInstruction was not provided.
<none>int256The signed position value delta, or 0 if acctInstruction was not provided.

managePositionBatch

Manages a batch of positions.

Convenience function to manage multiple positions in a single transaction.

function managePositionBatch(
        IWeirollComponent.Instruction[] calldata mgmtInstructions,
        IWeirollComponent.Instruction[] calldata acctInstructions
    ) external override nonReentrant whenOperational onlyOperator returns (uint256[] memory, int256[] memory);

Parameters

NameTypeDescription
mgmtInstructionsIWeirollComponent.Instruction[]The array of management instructions.
acctInstructionsIWeirollComponent.Instruction[]The array of accounting instructions.

Returns

NameTypeDescription
<none>uint256[]The new position values.
<none>int256[]The changes in the position values.

manageFlashLoan

Manages flash loan funds.

function manageFlashLoan(IWeirollComponent.Instruction calldata instruction, address token, uint256 amount)
        external
        override;

Parameters

NameTypeDescription
instructionIWeirollComponent.InstructionThe flash loan management instruction.
tokenaddressThe loan token.
amountuint256The loan amount.

harvest

Harvests one or multiple positions.

function harvest(IWeirollComponent.Instruction calldata instruction, ISwapComponent.SwapOrder[] calldata swapOrders)
        external
        override
        nonReentrant
        whenOperational
        onlyOperator;

Parameters

NameTypeDescription
instructionIWeirollComponent.InstructionThe harvest instruction.
swapOrdersISwapComponent.SwapOrder[]The array of swap orders to be executed after the harvest.

setAllowedInstrRoot

Sets the root of the Merkle tree containing allowed instructions.

function setAllowedInstrRoot(bytes32 newAllowedInstrRoot) external override onlySafe;

Parameters

NameTypeDescription
newAllowedInstrRootbytes32The new Merkle root.

setAccountingCurrency

Sets the currency used to value positions.

function setAccountingCurrency(address newAccountingCurrency) external override nonReentrant onlySafe;

Parameters

NameTypeDescription
newAccountingCurrencyaddressThe new currency.

setMaxPositionIncreaseLossBps

Sets the maximum allowed relative value loss for position increases while in WALLED mode.

function setMaxPositionIncreaseLossBps(uint256 newMaxPositionIncreaseLossBps) external override onlySafe;

Parameters

NameTypeDescription
newMaxPositionIncreaseLossBpsuint256The new maximum value loss in basis points.

setMaxPositionDecreaseLossBps

Sets the maximum allowed relative value loss for position decreases while in WALLED mode.

function setMaxPositionDecreaseLossBps(uint256 newMaxPositionDecreaseLossBps) external override onlySafe;

Parameters

NameTypeDescription
newMaxPositionDecreaseLossBpsuint256The new maximum value loss in basis points.

setInstrCooldownDuration

Sets the cooldown duration for instruction executions while in WALLED mode.

function setInstrCooldownDuration(uint256 newInstrCooldownDuration) external override onlySafe;

Parameters

NameTypeDescription
newInstrCooldownDurationuint256The new cooldown duration in seconds.

swap

Swaps tokens on behalf of the Safe using a given swapper.

function swap(ISwapComponent.SwapOrder calldata order) external override nonReentrant whenOperational onlyOperator;

Parameters

NameTypeDescription
orderISwapComponent.SwapOrderThe swap params.

setMaxSwapLossBps

Sets the maximum allowed relative value loss for token swaps while in FENCED or WALLED mode.

function setMaxSwapLossBps(uint256 newMaxSwapLossBps) external override onlySafe;

Parameters

NameTypeDescription
newMaxSwapLossBpsuint256The new maximum value loss in basis points.

setSwapCooldownDuration

Sets the cooldown duration for token swaps while in FENCED or WALLED mode.

function setSwapCooldownDuration(uint256 newSwapCooldownDuration) external override onlySafe;

Parameters

NameTypeDescription
newSwapCooldownDurationuint256The new cooldown duration in seconds.

setSwapFeeRate

Sets the swap fee rate.

function setSwapFeeRate(uint256 newSwapFeeRate) external override onlyProvider;

Parameters

NameTypeDescription
newSwapFeeRateuint256The new swap fee rate, 1e18 = 100%.

setSwapperTargets

Sets approval and execution targets for a given swapper ID.

function setSwapperTargets(uint16 swapperId, address approvalTarget, address executionTarget)
        external
        override
        onlySafe;

Parameters

NameTypeDescription
swapperIduint16The swapper ID.
approvalTargetaddressThe approval target.
executionTargetaddressThe execution target.

sendOutBridgeTransfer

Executes an outgoing bridge transfer.

function sendOutBridgeTransfer(IBridgeComponent.BridgeOrder calldata order)
        external
        override
        nonReentrant
        whenOperational
        onlyOperator;

Parameters

NameTypeDescription
orderIBridgeComponent.BridgeOrderThe bridge transfer params.

setMaxBridgeLossBps

Sets the maximum allowed relative value loss for transfers via this bridge while in FENCED or WALLED mode.

function setMaxBridgeLossBps(uint16 bridgeId, uint256 newMaxBridgeLossBps) external override onlySafe;

Parameters

NameTypeDescription
bridgeIduint16The ID of the bridge.
newMaxBridgeLossBpsuint256The new maximum value loss in basis points.

setBridgeCooldownDuration

Sets the cooldown duration for bridge transfers while in FENCED or WALLED mode.

function setBridgeCooldownDuration(uint256 newBridgeCooldownDuration) external override onlySafe;

Parameters

NameTypeDescription
newBridgeCooldownDurationuint256The new cooldown duration in seconds.

addRecipient

Adds a whitelisted recipient for bridge transfer to a given foreign chain while in FENCED or WALLED mode.

function addRecipient(uint256 foreignChainId, address recipient) external override onlySafe;

Parameters

NameTypeDescription
foreignChainIduint256The foreign chain ID.
recipientaddressThe address of the recipient.

removeRecipient

Removes a whitelisted recipient for bridge transfer to a given foreign chain while in FENCED or WALLED mode.

function removeRecipient(uint256 foreignChainId, address recipient) external override onlySafe;

Parameters

NameTypeDescription
foreignChainIduint256The foreign chain ID.
recipientaddressThe address of the recipient.

sweepERC20

Sweeps the entire balance of a given ERC20 token to the Safe.

function sweepERC20(address token) external nonReentrant onlySafe;

Parameters

NameTypeDescription
tokenaddressThe address of the ERC20 token to sweep.

sweepERC721

Sweeps a given ERC721 token to the Safe.

function sweepERC721(address token, uint256 tokenId) external nonReentrant onlySafe;

Parameters

NameTypeDescription
tokenaddressThe address of the ERC721 collection to sweep from.
tokenIduint256The id of the ERC721 token to sweep.

sweepERC6909

Sweeps the entire balance of a given ERC6909 token of type id to the Safe.

function sweepERC6909(address token, uint256 id) external nonReentrant onlySafe;

Parameters

NameTypeDescription
tokenaddressThe address of the ERC6909 token contract.
iduint256The type of the ERC6909 token to sweep.

sweepNative

Sweeps the entire native currency balance (e.g. ETH) to the Safe.

function sweepNative() external nonReentrant onlySafe;

_swapForSafe

Internal logic to execute token swaps on behalf of the Safe using a given swapper.

function _swapForSafe(ISwapComponent.SwapOrder calldata order) internal;

Parameters

NameTypeDescription
orderISwapComponent.SwapOrder

_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
        override(WeirollComponent, SwapComponent)
        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 override;

Parameters

NameTypeDescription
tokenaddress
amountuint256
flashLoanModuleaddress

_pullERC20FromSafe

Transfers amount of ERC20 token from the Safe to the given recipient via a module call.

function _pullERC20FromSafe(address token, uint256 amount, address recipient) internal;

Parameters

NameTypeDescription
tokenaddress
amountuint256
recipientaddress

_checkBps

Performs sanity check on a basis points value.

function _checkBps(uint256 bpsValue) internal pure;

Parameters

NameTypeDescription
bpsValueuint256

_checkFeeRate

Performs sanity check on a fee rate.

function _checkFeeRate(uint256 rate) internal pure;

Parameters

NameTypeDescription
rateuint256

_chargeSwapFee

Computes the fee for a given swap output, transfers it to the fee collector, and returns it.

function _chargeSwapFee(address tokenOut, uint256 amountOut) internal returns (uint256);

Parameters

NameTypeDescription
tokenOutaddress
amountOutuint256

Returns

NameTypeDescription
<none>uint256