Migrator

Git Source

Inherits: ExponentialNoError

Title: Migrator

Author: Merge Layers Inc.

Contract for migrating positions from Mendi to Malda

State Variables

MENDI_COMPTROLLER

Mendi Comptroller address

address public constant MENDI_COMPTROLLER = 0x1b4d3b0421dDc1eB216D230Bc01527422Fb93103

MALDA_OPERATOR

Malda Operator address

address public immutable MALDA_OPERATOR

allowedMarkets

Mapping of allowed markets

mapping(address market => bool allowed) public allowedMarkets

Functions

constructor

Initializes the migrator with the operator address

constructor(address _operator) ;

Parameters

NameTypeDescription
_operatoraddressAddress of the Malda operator

getAllPositions

Get all migratable positions from Mendi to Malda for user

function getAllPositions(address user) external returns (Position[] memory positions);

Parameters

NameTypeDescription
useraddressThe user address

Returns

NameTypeDescription
positionsPosition[]Array of positions

migrateAllPositions

Migrates all positions from Mendi to Malda

function migrateAllPositions() external;

getAllCollateralMarkets

Get all markets where user has collateral in on Mendi

function getAllCollateralMarkets(address user) external view returns (address[] memory markets);

Parameters

NameTypeDescription
useraddressThe user address

Returns

NameTypeDescription
marketsaddress[]Array of market addresses

_mintAll

Mints in v2 markets for all positions with collateral

function _mintAll(Position[] memory positions) private;

Parameters

NameTypeDescription
positionsPosition[]Positions to process

_borrowAll

Borrows in v2 markets for all positions requiring debt

function _borrowAll(Position[] memory positions) private;

Parameters

NameTypeDescription
positionsPosition[]Positions to process

_repayAll

Repays debts in v1 markets for all positions

function _repayAll(Position[] memory positions) private;

Parameters

NameTypeDescription
positionsPosition[]Positions to process

_withdrawAll

Withdraws collateral from v1 and transfers to v2 for all positions

function _withdrawAll(Position[] memory positions) private;

Parameters

NameTypeDescription
positionsPosition[]Positions to process

_collectMendiPositions

Collects all user positions from Mendi

function _collectMendiPositions(address user) private returns (Position[] memory);

Parameters

NameTypeDescription
useraddressThe user address

Returns

NameTypeDescription
<none>Position[]Array of positions

_getMaldaMarket

Gets corresponding Malda market for a given underlying

function _getMaldaMarket(address underlying) private view returns (address);

Parameters

NameTypeDescription
underlyingaddressThe underlying token address

Returns

NameTypeDescription
<none>addressThe Malda market address

Errors

Migrator_AddressNotValid

Error thrown when address is not valid

error Migrator_AddressNotValid();

Migrator_RedeemAmountNotValid

Error thrown when redeem amount is not valid

error Migrator_RedeemAmountNotValid();

Structs

Position

struct Position {
    address mendiMarket;
    address maldaMarket;
    uint256 collateralUnderlyingAmount;
    uint256 borrowAmount;
}