# Dolomite Margin - Events

These events are all emitted by instances of DolomiteMargin on each network Dolomite is deployed. See smart [contract addresses](https://docs.dolomite.io/smart-contract-addresses/core-immutable) to discover the address of DolomiteMargin on each network.

## Account Operation Events

These events are logged right after they occur within each [Action](https://docs.dolomite.io/dolomite-margin-glossary#actions) of an [Operation](https://docs.dolomite.io/dolomite-margin-glossary#operations)

### `BalanceUpdate` Struct

**Description:**

The `BalanceUpdate` struct represents an update to an account's balance, including changes to both token amounts and principal amounts.

**Struct Members:**

* `deltaWei` (`Types.Wei`): The change in token balance (Wei) for the account. Can be positive or negative.
* `newPar` (`Types.Par`): The new principal value for the account. Can be positive or negative.

**Struct Signature:**

```solidity
library Types {
    struct Wei {
        bool sign; // true if positive
        uint128 value;
    }

    struct Par {
        bool sign; // true if positive
        uint128 value;
    }
}

struct BalanceUpdate {
    Types.Wei deltaWei;
    Types.Par newPar;
}
```

### `LogOperation` Event

**Topic 0:** `0x91b01baeee3a24b590d112613814d86801005c7ef9353e7fc1eaeaf33ccf83b0`

**Description:**

This event is emitted at the start of an operation.

**Event Signature:**

```solidity
event LogOperation(
    address sender
);
```

* `sender` (`address`): The address of the caller of DolomiteMargin who performed the operation.

### `LogDeposit` Event

**Topic 0:** `0x2bad8bc95088af2c247b30fa2b2e6a0886f88625e0945cd3051008e0e270198f`

**Description:**

This event is emitted when tokens are deposited into an account via a [`Deposit`](https://docs.dolomite.io/dolomite-margin-glossary#deposit) Action.

**Event Signature:**

```solidity
event LogDeposit(
    address indexed accountOwner,
    uint256 accountNumber,
    uint256 market,
    BalanceUpdate update,
    address from
);
```

* `accountOwner` (`address`): The owner of the account where the deposit occurred.
* `accountNumber` (`uint256`): The account number where the deposit occurred.
* `market` (`uint256`): The market identifier where the deposit occurred.
* `update` (`BalanceUpdate`): The balance update for the account as a result of the deposit.
* `from` (`address`): The address from which the deposit was made.

### `LogWithdraw` Event

**Topic 0:** `0xbc83c08f0b269b1726990c8348ffdf1ae1696244a14868d766e542a2f18cd7d4`

**Description:**

This event is emitted when tokens are withdrawn from an account via a [`Withdraw`](https://docs.dolomite.io/dolomite-margin-glossary#withdraw) Action.

**Event Signature:**

```solidity
event LogWithdraw(
    address indexed accountOwner,
    uint256 accountNumber,
    uint256 market,
    BalanceUpdate update,
    address to
);
```

* `accountOwner` (`address`): The owner of the account from which the withdrawal occurred.
* `accountNumber` (`uint256`): The account number from which the withdrawal occurred.
* `market` (`uint256`): The market identifier from which the withdrawal occurred.
* `update` (`BalanceUpdate`): The balance update for the account as a result of the withdrawal.
* `to` (`address`): The address to which the withdrawal was sent.

### `LogTransfer` Event

**Topic 0:** `0x21281f8d59117d0399dc467dbdd321538ceffe3225e80e2bd4de6f1b3355cbc7`

**Description:**

This event is emitted when a transfer of tokens occurs between two accounts via a [`Transfer`](https://docs.dolomite.io/dolomite-margin-glossary#transfer) Action. Note this does not materialize an ERC20 transfer event since only virtual liquidity is transferred.

**Event Signature:**

```solidity
event LogTransfer(
    address indexed accountOneOwner,
    uint256 accountOneNumber,
    address indexed accountTwoOwner,
    uint256 accountTwoNumber,
    uint256 market,
    BalanceUpdate updateOne,
    BalanceUpdate updateTwo
);
```

* `accountOneOwner` (`address`): The owner of the first account involved in the transfer.
* `accountOneNumber` (`uint256`): The account number of the first account involved in the transfer.
* `accountTwoOwner` (`address`): The owner of the second account involved in the transfer.
* `accountTwoNumber` (`uint256`): The account number of the second account involved in the transfer.
* `market` (`uint256`): The market identifier where the transfer occurred.
* `updateOne` (`BalanceUpdate`): The balance update for the first account as a result of the transfer.
* `updateTwo` (`BalanceUpdate`): The balance update for the second account as a result of the transfer.

### `LogBuy` Event

**Topic 0:** `0x2e346762bf4ae4568971c30b51fcebd2138275aafcfe12d872956e9f3e120893`

**Description:**

This event is emitted when a [`Buy`](https://docs.dolomite.io/dolomite-margin-glossary#buy) Action occurs, representing a trade where one account purchases tokens via an exchange wrapper contract. Mechnically, this Action is similar to Uniswap's `swapTokensForExactTokens`.

**Event Signature:**

```solidity
event LogBuy(
    address indexed accountOwner,
    uint256 accountNumber,
    uint256 takerMarket,
    uint256 makerMarket,
    BalanceUpdate takerUpdate,
    BalanceUpdate makerUpdate,
    address exchangeWrapper
);
```

* `accountOwner` (`address`): The owner of the account that performed the buy operation.
* `accountNumber` (`uint256`): The account number that performed the buy operation.
* `takerMarket` (`uint256`): The market identifier for the taker's (buyer's) side of the trade (the `inputMarket`).
* `makerMarket` (`uint256`): The market identifier for the maker's (seller's) side of the trade (the `outputMarket`).
* `takerUpdate` (`BalanceUpdate`): The balance update for the taker's account as a result of the buy.
* `makerUpdate` (`BalanceUpdate`): The balance update for the maker's account as a result of the buy.
* `exchangeWrapper` (`address`): The address of the exchange wrapper contract involved in the buy action.

### `LogSell` Event

**Topic 0:** `0xcc3330184b6d88cad87f9e9543b4d4110a6a3eaf20164ca5252d598d0acba3f1`

**Description:**

This event is emitted when a [`Sell`](https://docs.dolomite.io/dolomite-margin-glossary#sell) Action occurs, representing a trade where one account sells tokens via an exchange wrapper contract. Mechanically, this Action is similar to Uniswap's `swapExactTokensForTokens`.

**Event Signature:**

```solidity
event LogSell(
    address indexed accountOwner,
    uint256 accountNumber,
    uint256 takerMarket,
    uint256 makerMarket,
    BalanceUpdate takerUpdate,
    BalanceUpdate makerUpdate,
    address exchangeWrapper
);
```

* `accountOwner` (`address`): The owner of the account that performed the sell operation.
* `accountNumber` (`uint256`): The account number that performed the sell operation.
* `takerMarket` (`uint256`): The market identifier for the taker's (seller's) side of the trade (the `inputMarket`).
* `makerMarket` (`uint256`): The market identifier for the maker's (buyer's) side of the trade (the `outputMarket`).
* `takerUpdate` (`BalanceUpdate`): The balance update for the taker's account as a result of the sell.
* `makerUpdate` (`BalanceUpdate`): The balance update for the maker's account as a result of the sell.
* `exchangeWrapper` (`address`): The address of the exchange wrapper contract involved in the sell action.

### `LogTrade` Event

**Topic 0:** `0x54d4cc60cf7d570631cc1a58942812cb0fc461713613400f56932040c3497d19`

**Description:**

This event is emitted when a [`Trade`](https://docs.dolomite.io/dolomite-margin-glossary#trade) Action occurs between a taker and a maker account using an auto-trader contract.

**Event Signature:**

```solidity
event LogTrade(
    address indexed takerAccountOwner,
    uint256 takerAccountNumber,
    address indexed makerAccountOwner,
    uint256 makerAccountNumber,
    uint256 inputMarket,
    uint256 outputMarket,
    BalanceUpdate takerInputUpdate,
    BalanceUpdate takerOutputUpdate,
    BalanceUpdate makerInputUpdate,
    BalanceUpdate makerOutputUpdate,
    address autoTrader
);
```

* `takerAccountOwner` (`address`): The owner of the taker account involved in the trade.
* `takerAccountNumber` (`uint256`): The account number of the taker account involved in the trade.
* `makerAccountOwner` (`address`): The owner of the maker account involved in the trade. The `makerAccountOwner` is the address that approved the trade for the auto-trader contract.
* `makerAccountNumber` (`uint256`): The account number of the maker account involved in the trade.
* `inputMarket` (`uint256`): The market identifier for the input tokens of the trade.
* `outputMarket` (`uint256`): The market identifier for the output tokens of the trade.
* `takerInputUpdate` (`BalanceUpdate`): The balance update for the taker's input tokens as a result of the trade.
* `takerOutputUpdate` (`BalanceUpdate`): The balance update for the taker's output tokens as a result of the trade.
* `makerInputUpdate` (`BalanceUpdate`): The balance update for the maker's input tokens as a result of the trade.
* `makerOutputUpdate` (`BalanceUpdate`): The balance update for the maker's output tokens as a result of the trade.
* `autoTrader` (`address`): The address of the auto-trader contract used for the trade.

### `LogCall` Event

**Topic 0:** `0xab38cdc4a831ebe6542bf277d36b65dbc5c66a4d03ec6cf56ac38de05dc30098`

**Description:**

This event is emitted when a [`Call`](https://docs.dolomite.io/dolomite-margin-glossary#call) Action occurs.

**Event Signature:**

```solidity
event LogCall(
    address indexed accountOwner,
    uint256 accountNumber,
    address callee
);
```

* `accountOwner` (`address`): The owner of the account that initiated the call.
* `accountNumber` (`uint256`): The account number of the account owner that initiated the call.
* `callee` (`address`): The address of the contract that was called.

### `LogLiquidate` Event

**Topic 0:** `0x1b9e65b359b871d74b1af1fc8b13b11635bfb097c4631b091eb762fda7e67dc7`

**Description:**

This event is emitted when a [`Liquidate`](https://docs.dolomite.io/dolomite-margin-glossary#liquidate) Action occurs, representing the process of one account liquidating another account's under-collateralized position.

**Event Signature:**

```solidity
event LogLiquidate(
    address indexed solidAccountOwner,
    uint256 solidAccountNumber,
    address indexed liquidAccountOwner,
    uint256 liquidAccountNumber,
    uint256 heldMarket,
    uint256 owedMarket,
    BalanceUpdate solidHeldUpdate,
    BalanceUpdate solidOwedUpdate,
    BalanceUpdate liquidHeldUpdate,
    BalanceUpdate liquidOwedUpdate
);
```

* `solidAccountOwner` (`address`): The owner of the account performing the liquidation.
* `solidAccountNumber` (`uint256`): The account number of the account performing the liquidation.
* `liquidAccountOwner` (`address`): The owner of the account being liquidated.
* `liquidAccountNumber` (`uint256`): The account number of the account being liquidated.
* `heldMarket` (`uint256`): The market identifier for the held (collateral) tokens.
* `owedMarket` (`uint256`): The market identifier for the owed (borrowed) tokens.
* `solidHeldUpdate` (`BalanceUpdate`): The balance update for the held tokens of the account performing the liquidation.
* `solidOwedUpdate` (`BalanceUpdate`): The balance update for the owed tokens of the account performing the liquidation.
* `liquidHeldUpdate` (`BalanceUpdate`): The balance update for the held tokens of the account being liquidated.
* `liquidOwedUpdate` (`BalanceUpdate`): The balance update for the owed tokens of the account being liquidated.

### `LogVaporize` Event

**Topic 0:** `0xefdcfda4e0be180f29bfeebc4bcb6de1e950d70b41e9ee813bff9882ee16ca91`

**Description:**

This event is emitted when a [`Vaporize`](https://docs.dolomite.io/dolomite-margin-glossary#vaporize) Action occurs, representing the process of a solid account using the admin's excess tokens to cover a vapor account's bad debt. A position's debt is considered to be bad if there is no held value (`balance == 0`) but there is still debt held in the position.

**Event Signature:**

```solidity
event LogVaporize(
    address indexed solidAccountOwner,
    uint256 solidAccountNumber,
    address indexed vaporAccountOwner,
    uint256 vaporAccountNumber,
    uint256 heldMarket,
    uint256 owedMarket,
    BalanceUpdate solidHeldUpdate,
    BalanceUpdate solidOwedUpdate,
    BalanceUpdate vaporOwedUpdate
);
```

* `solidAccountOwner` (`address`): The owner of the solid account from which the vaporization occurred.
* `solidAccountNumber` (`uint256`): The account number of the solid account from which the vaporization occurred.
* `vaporAccountOwner` (`address`): The owner of the vapor account that has bad debt
* `vaporAccountNumber` (`uint256`): The account number of the vapor account has bad debt
* `heldMarket` (`uint256`): The market identifier for the held (collateral) tokens.
* `owedMarket` (`uint256`): The market identifier for the owed (borrowed) tokens.
* `solidHeldUpdate` (`BalanceUpdate`): The balance update for the held tokens of the solid account.
* `solidOwedUpdate` (`BalanceUpdate`): The balance update for the owed tokens of the solid account.
* `vaporOwedUpdate` (`BalanceUpdate`): The balance update for the owed tokens of the vaporized account.

### `LogOperatorSet` Event

**Topic 0:** `0x4d7f317d2088d039c2a95a09fcbf9cc9191fad5905f883c937cc3d317c4a6327`

**Description:**

This event is emitted when an account adds or removes another contract (or account) as an operator for itself.

**Event Signature:**

```solidity
event LogOperatorSet(
    address indexed owner,
    address operator,
    bool trusted
);
```

* `owner` (`address`): The owner of the account for which the operator status was updated.
* `operator` (`address`): The address of the operator whose status was updated.
* `trusted` (`bool`): The new status of the operator. `true` indicates the operator is trusted, while `false` indicates the operator is untrusted.

## Market Events

### `LogIndexUpdate` Event (All Networks Except Arbitrum)

**Topic 0:** `0x247e2f5b851dd23ef755d9ad527e801ee202c4097acd70c21e82dc5602cdd879`

**Description:**

This event is emitted when an interest index is updated for a specific market, indicating a change in the accrued borrow and supply values, as well as possibly a change in the borrow and supply rates. The interest index is updated, at-most, once per block. This event is emitted at the start of an [Operation](https://docs.dolomite.io/dolomite-margin-glossary#operators), before the [Actions](https://docs.dolomite.io/dolomite-margin-glossary#actions) are processed.

**Event Signature:**

```solidity
library Interest {
    struct Index {
        uint112 borrow;
        uint112 supply;
        uint32 lastUpdate;
    }
}

event LogIndexUpdate(
    uint256 indexed market,
    Interest.Index index
);
```

* `market` (`uint256`): The identifier of the market for which the interest index was updated.
* `index` (`Interest.Index`): The updated interest index for the market, containing information about the updated borrowing and supplying values used to convert borrow or supply [Par](https://docs.dolomite.io/dolomite-margin-glossary#par) to borrow or supply [Wei](https://docs.dolomite.io/dolomite-margin-glossary#wei).

### `LogIndexUpdate` Event (Arbitrum)

**Topic 0:** `0xf4626fd1187f91e6761ffb8a6ac3e8d9235a4a92da54e43feb0c57c4a4a322ab`

**Description:**

This event is emitted when an interest index is updated for a specific market, indicating a change in the accrued borrow and supply values, as well as possibly a change in the borrow and supply rates. The interest index is updated, at-most, once per block. This event is emitted at the start of an [Operation](https://docs.dolomite.io/dolomite-margin-glossary#operators), before the [Actions](https://docs.dolomite.io/dolomite-margin-glossary#actions) are processed.

**Event Signature:**

```solidity
library Interest {
    struct Index {
        uint96 borrow;
        uint96 supply;
        uint32 lastUpdate;
    }
}

event LogIndexUpdate(
    uint256 indexed market,
    Interest.Index index
);
```

* `market` (`uint256`): The identifier of the market for which the interest index was updated.
* `index` (`Interest.Index`): The updated interest index for the market, containing information about the updated borrowing and supplying values used to convert borrow or supply [Par](https://docs.dolomite.io/dolomite-margin-glossary#par) to borrow or supply [Wei](https://docs.dolomite.io/dolomite-margin-glossary#wei).

### `LogInterestRate` Event (All Networks Except Arbitrum)

**Topic 0:** `0x97c9b8866705111329b3d1b18589bf0add9e1f1c8a1ce4a9fbf3bd32dc2e6d41`

**Description:**

This event is emitted after each [Operation](https://docs.dolomite.io/dolomite-margin-glossary#operations) and logs the current interest rate (at the time of the transaction settling) for a specific market. Assuming an interest rate model is solely dependent on the  borrow utilization of a market, this will be the interest rate that is applied to the market until the next [Operation](https://docs.dolomite.io/dolomite-margin-glossary#operations) occurs.

**Event Signature:**

```solidity
library Interest {
    struct Index {
        uint112 borrow;
        uint112 supply;
        uint32 lastUpdate;
    }
}

event LogIndexUpdate(
    uint256 indexed market,
    Interest.Rate rate
);
```

* `market` (`uint256`): The identifier of the market for which the interest index was updated.
* `rate` (`Interest.Rate`): The updated borrow interest rate for the market. This number is represented as interest accrued every second. To get a normalized borrow APR, multiply this number by `31,536,000` (the number of seconds in a year).

### `LogOraclePrice` Event

**Topic 0:** `0x223e16b9e4703ea2acd14a8caa0fcbbf4a42d3e8b7a33234e841bd1808ee9ec0`

**Description:**

This event is emitted when an oracle price is retrieved for a specific market at the start of an [Operation](https://docs.dolomite.io/dolomite-margin-glossary#operators), before the [Actions](https://docs.dolomite.io/dolomite-margin-glossary#actions) are processed. It specifies to data indexers and block explorers what the USD value of a market was during an [Operation](https://docs.dolomite.io/dolomite-margin-glossary#operators).

**Event Signature:**

```solidity
library Monetary {
    /*
     * The price of a base-unit of an asset. Has `36 - token.decimals` decimals
     */
    struct Price {
        uint256 value;
    }
}

event LogOraclePrice(
    uint256 indexed market,
    Monetary.Price price
);
```

* `market` (`uint256`): The identifier of the market for which the oracle price was updated.
* `price` (`Monetary.Price`): The oracle price for the market during an [Operation](https://docs.dolomite.io/dolomite-margin-glossary#operators). Prices have `36 - token.decimals` decimals, meaning  a value of `1000000000000000000000000000000` corresponds with $1.00 for USDC (USDC has 6 decimals of precision).
