Creditors

Overview

Arcadia enables the integration of custom creditors with its Margin Accounts system, actively encouraging teams to build new financial products and protocols on top of Arcadia Accounts. These could include perpetuals, options, lending platforms, or other innovative solutions that leverage the infrastructure provided by Arcadia. By leveraging Arcadia Margin Accounts, creditors can build their own logic tailored to their application while adhering to the interface required by Arcadia Accounts. This guide outlines the requirements and best practices for developing a creditor for Arcadia Accounts.

Note: This guide is based on AccountV1.sol from Arcadia Finance. While this document provides a detailed explanation of the integration process, note that other versions of Arcadia Margin Accounts may differ slightly in their implementation.

Minimum logic required for a Creditor

  1. Open Margin Accounts: Enable accounts to borrow funds from the creditor.

  2. Close Margin Accounts: Ensure liabilities are zero before an account can close its creditor relationship.

  3. Debt Tracking: Allow accounts to query their open positions with the creditor.

  4. Liquidation Mechanism: Provide functionality to initiate liquidation when the margin requirement is not met.

  5. Flash Action Callback: Implement callbacks for flash actions initiated by the creditor.

Workflow

1. Opening a Margin Account

To open a margin account, the creditor must implement the openMarginAccount() function, which will be called by an Arcadia Account when initiating a new creditor:

function openMarginAccount(uint256 accountVersion)
    external
    returns (bool success, address numeraire, address liquidator_, uint256 minimumMargin_);
  • Parameters:

    • accountVersion: The version of the Arcadia Account attempting to open a margin account.

  • Returns:

    • success: Indicates whether the account satisfies the creditor's requirements.

    • numeraire: The asset that will serve as the borrowed asset.

    • liquidator_: The address responsible for liquidating the account.

    • minimumMargin_: The minimum collateral required to open a position.

Behavior:

  • The creditor should validate that the provided accountVersion is supported.

  • Return the required parameters for the Arcadia Account to proceed.


2. Closing a Margin Account

When an account wants to close its relationship with the creditor, the closeMarginAccount() function is called:

function closeMarginAccount(address account) external;
  • Parameters:

    • account: The address of the Arcadia Account.

Behavior:

  • Ensure that the liabilities (open positions) are zero before allowing the account to close.

  • If the open debt is non-zero, the transaction should revert.


3. Querying Open Positions

The creditor must provide a way to query the debt of an account:

function getOpenPosition(address account) external view returns (uint256 openPosition);
  • Parameters:

    • account: The address of the Arcadia Account.

  • Returns:

    • openPosition: The outstanding debt of the account.

Behavior:

  • Return the current open position (debt) the account has with the creditor.


4. Starting Liquidation

Liquidation is initiated by an initiator in the Account itself, in which the startLiquidation function in the creditor is called when the margin requirement is not met:

function startLiquidation(address initiator, uint256 minimumMargin_)
    external
    returns (uint256 startDebt);
  • Parameters:

    • initiator: The address initiating the liquidation.

    • minimumMargin_: The minimum margin required for the account.

  • Returns:

    • startDebt: The outstanding debt at the time of liquidation initiation.

Behavior:

  • Verify that the liquidation conditions are met.

  • Begin the liquidation process and return the debt amount.


5. Flash Action Callback

The creditor must implement a callback function to handle flash actions, if needed:

function flashActionCallback(bytes calldata callbackData) external;
  • Parameters:

    • callbackData: Data containing the actions to be executed during the flash action.

Behavior:

  • Execute the required logic for the flash action.

  • For example, a creditor could use this function to reimburse the debt of a previous creditor and take over the account’s debt.

Interface for Creditors

The following interface outlines the required functions for a creditor interacting with Arcadia Accounts:

See ICreditor.

/**
 * @title Creditor implementation.
 * @notice This contract contains the minimum functionality a Creditor needs to implement for Arcadia Accounts.
 */
interface ICreditor {
    function openMarginAccount(uint256 accountVersion) external returns (bool, address, address, uint256);
    function closeMarginAccount(address account) external;
    function getOpenPosition(address account) external view returns (uint256);
    function riskManager() external view returns (address riskManager);
    function flashActionCallback(bytes calldata callbackData) external;
    function startLiquidation(address initiator, uint256 minimumMargin) external returns (uint256);
}

Last updated