Type alias JetMargin

JetMargin: {
    accounts: [{
        name: "marginAccount";
        type: {
            fields: [{
                name: "version";
                type: "u8";
            }, {
                name: "bumpSeed";
                type: {
                    array: ["u8", 1];
                };
            }, {
                name: "userSeed";
                type: {
                    array: ["u8", 2];
                };
            }, {
                docs: ["Data an adapter can use to check what the margin program thinks about the current invocation", "Must normally be zeroed, except during an invocation."];
                name: "invocation";
                type: {
                    defined: "Invocation";
                };
            }, {
                name: "reserved0";
                type: {
                    array: ["u8", 3];
                };
            }, {
                docs: ["The owner of this account, which generally has to sign for any changes to it"];
                name: "owner";
                type: "publicKey";
            }, {
                docs: ["The state of an active liquidation for this account"];
                name: "liquidation";
                type: "publicKey";
            }, {
                docs: ["The active liquidator for this account"];
                name: "liquidator";
                type: "publicKey";
            }, {
                docs: ["The storage for tracking account balances"];
                name: "positions";
                type: {
                    array: ["u8", 7432];
                };
            }];
            kind: "struct";
        };
    }, {
        docs: ["State of an in-progress liquidation"];
        name: "liquidationState";
        type: {
            fields: [{
                docs: ["The state object"];
                name: "state";
                type: {
                    defined: "Liquidation";
                };
            }];
            kind: "struct";
        };
    }, {
        docs: ["The configuration account specifying parameters for a token when used", "in a position within a margin account."];
        name: "tokenConfig";
        type: {
            fields: [{
                docs: ["The mint for the token"];
                name: "mint";
                type: "publicKey";
            }, {
                docs: ["The mint for the underlying token represented, if any"];
                name: "underlyingMint";
                type: "publicKey";
            }, {
                docs: ["The space this config is valid within"];
                name: "airspace";
                type: "publicKey";
            }, {
                docs: ["The adapter program in control of positions of this token", "", "If this is `None`, then the margin program is in control of this asset, and", "thus determining its price. The `oracle` field must be set to allow the margin", "program to price the asset."];
                name: "adapterProgram";
                type: {
                    option: "publicKey";
                };
            }, {
                docs: ["The oracle for the token", "", "This only has effect in the margin program when the price for the token is not", "being managed by an adapter."];
                name: "oracle";
                type: {
                    option: {
                        defined: "TokenOracle";
                    };
                };
            }, {
                docs: ["Description of this token", "", "This determines the way the margin program values a token as a position in a", "margin account."];
                name: "tokenKind";
                type: {
                    defined: "TokenKind";
                };
            }, {
                docs: ["A modifier to adjust the token value, based on the kind of token"];
                name: "valueModifier";
                type: "u16";
            }, {
                docs: ["The maximum staleness (seconds) that's acceptable for balances of this token"];
                name: "maxStaleness";
                type: "u64";
            }];
            kind: "struct";
        };
    }, {
        docs: ["Configuration for allowed liquidators"];
        name: "liquidatorConfig";
        type: {
            fields: [{
                docs: ["The airspace this liquidator is being configured to act within"];
                name: "airspace";
                type: "publicKey";
            }, {
                docs: ["The address of the liquidator allowed to act"];
                name: "liquidator";
                type: "publicKey";
            }];
            kind: "struct";
        };
    }, {
        docs: ["Configuration for allowed adapters"];
        name: "adapterConfig";
        type: {
            fields: [{
                docs: ["The airspace this adapter can be used in"];
                name: "airspace";
                type: "publicKey";
            }, {
                docs: ["The program address allowed to be called as an adapter"];
                name: "adapterProgram";
                type: "publicKey";
            }];
            kind: "struct";
        };
    }];
    constants: [{
        name: "TOKEN_CONFIG_SEED";
        type: {
            defined: "&[u8]";
        };
        value: "b\"token-config\"";
    }, {
        name: "ADAPTER_CONFIG_SEED";
        type: {
            defined: "&[u8]";
        };
        value: "b\"adapter-config\"";
    }, {
        name: "LIQUIDATOR_CONFIG_SEED";
        type: {
            defined: "&[u8]";
        };
        value: "b\"liquidator-config\"";
    }, {
        name: "MAX_ORACLE_CONFIDENCE";
        type: "u16";
        value: "5_00";
    }, {
        name: "MAX_ORACLE_STALENESS";
        type: "i64";
        value: "30";
    }, {
        name: "MAX_PRICE_QUOTE_AGE";
        type: "u64";
        value: "30";
    }, {
        name: "LIQUIDATION_TIMEOUT";
        type: {
            defined: "UnixTimestamp";
        };
        value: "60";
    }];
    docs: ["This crate documents the instructions used in the `margin` program of the", "[jet-v2 repo](https://github.com/jet-lab/jet-v2/).", "Handler functions are described for each instruction well as struct parameters", "(and their types and descriptions are listed) and any handler function", "parameters aside from parameters that exist in every instruction handler function.", "Parameters of events emitted for the purposes of data logging are also included."];
    errors: [{
        code: 141000;
        name: "NoAdapterResult";
    }, {
        code: 141001;
        msg: "The program that set the result was not the adapter";
        name: "WrongProgramAdapterResult";
    }, {
        code: 141002;
        msg: "this invocation is not authorized by the necessary accounts";
        name: "UnauthorizedInvocation";
    }, {
        code: 141003;
        msg: "the current instruction was not directly invoked by the margin program";
        name: "IndirectInvocation";
    }, {
        code: 141010;
        msg: "account cannot record any additional positions";
        name: "MaxPositions";
    }, {
        code: 141011;
        msg: "account has no record of the position";
        name: "UnknownPosition";
    }, {
        code: 141012;
        msg: "attempting to close a position that has a balance";
        name: "CloseNonZeroPosition";
    }, {
        code: 141013;
        msg: "attempting to register an existing position";
        name: "PositionAlreadyRegistered";
    }, {
        code: 141014;
        msg: "attempting to close non-empty margin account";
        name: "AccountNotEmpty";
    }, {
        code: 141015;
        msg: "attempting to use unregistered position";
        name: "PositionNotRegistered";
    }, {
        code: 141016;
        msg: "attempting to close a position that is required by the adapter";
        name: "CloseRequiredPosition";
    }, {
        code: 141017;
        msg: "registered position owner inconsistent with PositionTokenMetadata owner or token_kind";
        name: "InvalidPositionOwner";
    }, {
        code: 141018;
        msg: "dependencies are not satisfied to auto-register a required but unregistered position";
        name: "PositionNotRegisterable";
    }, {
        code: 141020;
        msg: "wrong adapter to modify the position";
        name: "InvalidPositionAdapter";
    }, {
        code: 141021;
        msg: "a position price is outdated";
        name: "OutdatedPrice";
    }, {
        code: 141022;
        msg: "an asset price is currently invalid";
        name: "InvalidPrice";
    }, {
        code: 141023;
        msg: "a position balance is outdated";
        name: "OutdatedBalance";
    }, {
        code: 141030;
        msg: "the account is not healthy";
        name: "Unhealthy";
    }, {
        code: 141031;
        msg: "the account is already healthy";
        name: "Healthy";
    }, {
        code: 141032;
        msg: "the account is being liquidated";
        name: "Liquidating";
    }, {
        code: 141033;
        msg: "the account is not being liquidated";
        name: "NotLiquidating";
    }, {
        code: 141034;
        name: "StalePositions";
    }, {
        code: 141040;
        msg: "the liquidator does not have permission to do this";
        name: "UnauthorizedLiquidator";
    }, {
        code: 141041;
        msg: "attempted to extract too much value during liquidation";
        name: "LiquidationLostValue";
    }, {
        code: 141050;
        msg: "attempting to mix entities from different airspaces";
        name: "WrongAirspace";
    }, {
        code: 141051;
        msg: "attempting to use or set invalid configuration";
        name: "InvalidConfig";
    }, {
        code: 141052;
        msg: "attempting to use or set invalid configuration";
        name: "InvalidOracle";
    }];
    events: [{
        fields: [{
            index: false;
            name: "marginAccount";
            type: "publicKey";
        }, {
            index: false;
            name: "owner";
            type: "publicKey";
        }, {
            index: false;
            name: "seed";
            type: "u16";
        }];
        name: "AccountCreated";
    }, {
        fields: [{
            index: false;
            name: "marginAccount";
            type: "publicKey";
        }];
        name: "AccountClosed";
    }, {
        fields: [{
            index: false;
            name: "marginAccount";
            type: "publicKey";
        }];
        name: "VerifiedHealthy";
    }, {
        fields: [{
            index: false;
            name: "marginAccount";
            type: "publicKey";
        }, {
            index: false;
            name: "authority";
            type: "publicKey";
        }, {
            index: false;
            name: "position";
            type: {
                defined: "AccountPosition";
            };
        }];
        name: "PositionRegistered";
    }, {
        fields: [{
            index: false;
            name: "marginAccount";
            type: "publicKey";
        }, {
            index: false;
            name: "authority";
            type: "publicKey";
        }, {
            index: false;
            name: "token";
            type: "publicKey";
        }];
        name: "PositionClosed";
    }, {
        fields: [{
            index: false;
            name: "marginAccount";
            type: "publicKey";
        }, {
            index: false;
            name: "position";
            type: {
                defined: "AccountPosition";
            };
        }];
        name: "PositionMetadataRefreshed";
    }, {
        fields: [{
            index: false;
            name: "position";
            type: {
                defined: "AccountPosition";
            };
        }];
        name: "PositionBalanceUpdated";
    }, {
        fields: [{
            index: false;
            name: "position";
            type: {
                defined: "AccountPosition";
            };
        }];
        name: "PositionTouched";
    }, {
        fields: [{
            index: false;
            name: "marginAccount";
            type: "publicKey";
        }, {
            index: false;
            name: "adapterProgram";
            type: "publicKey";
        }];
        name: "AccountingInvokeBegin";
    }, {
        fields: [];
        name: "AccountingInvokeEnd";
    }, {
        fields: [{
            index: false;
            name: "marginAccount";
            type: "publicKey";
        }, {
            index: false;
            name: "adapterProgram";
            type: "publicKey";
        }];
        name: "AdapterInvokeBegin";
    }, {
        fields: [];
        name: "AdapterInvokeEnd";
    }, {
        fields: [{
            index: false;
            name: "marginAccount";
            type: "publicKey";
        }, {
            index: false;
            name: "liquidator";
            type: "publicKey";
        }, {
            index: false;
            name: "liquidation";
            type: "publicKey";
        }, {
            index: false;
            name: "liquidationData";
            type: {
                defined: "Liquidation";
            };
        }, {
            index: false;
            name: "valuationSummary";
            type: {
                defined: "ValuationSummary";
            };
        }];
        name: "LiquidationBegun";
    }, {
        fields: [{
            index: false;
            name: "marginAccount";
            type: "publicKey";
        }, {
            index: false;
            name: "adapterProgram";
            type: "publicKey";
        }, {
            index: false;
            name: "liquidator";
            type: "publicKey";
        }];
        name: "LiquidatorInvokeBegin";
    }, {
        fields: [{
            index: false;
            name: "liquidationData";
            type: {
                defined: "Liquidation";
            };
        }, {
            index: false;
            name: "valuationSummary";
            type: {
                defined: "ValuationSummary";
            };
        }];
        name: "LiquidatorInvokeEnd";
    }, {
        fields: [{
            index: false;
            name: "marginAccount";
            type: "publicKey";
        }, {
            index: false;
            name: "authority";
            type: "publicKey";
        }, {
            index: false;
            name: "timedOut";
            type: "bool";
        }];
        name: "LiquidationEnded";
    }];
    instructions: [{
        accounts: [{
            docs: ["The owner of the new margin account"];
            isMut: false;
            isSigner: true;
            name: "owner";
        }, {
            isMut: true;
            isSigner: true;
            name: "payer";
        }, {
            docs: ["The margin account to initialize for the owner"];
            isMut: true;
            isSigner: false;
            name: "marginAccount";
        }, {
            isMut: false;
            isSigner: false;
            name: "systemProgram";
        }];
        args: [{
            name: "seed";
            type: "u16";
        }];
        docs: ["Create a new margin account for a user", "", "This instruction does the following:", "", "1. Let `account` be a mutable reference to the margin account.", "", "2. Initialize the margin account by setting the margin account version, owner,", "bump seed, user seed, and setting liquidator pubkey field to the default", "(if an account is being liquidated, the liquidator pubkey will be set here).", "", "3. Emit the `AccountCreated` event for data logging (see table below):", "", "4. Return `Ok(())`.", "", "", "**Parameters of create\\_account.rs:**", "", "| | |", "| --- | --- |", "| **Name** | **Description** |", "| `owner` | The owner of the new margin account. |", "| `payer` | The pubkey paying rent for the new margin account opening. |", "| `margin_account` | The margin account to initialize for the owner. |", "| `system_program` | The system program. |", "", "**Events emitted by create\\_account.rs:**", "", "| | |", "| --- | --- |", "| **Event Name** | **Description** |", "| [`events::AccountCreated`] | The created account (includes the margin account pubkey, the owner of margin account’s the pubkey, and the seed). |"];
        name: "createAccount";
    }, {
        accounts: [{
            docs: ["The owner of the account being closed"];
            isMut: false;
            isSigner: true;
            name: "owner";
        }, {
            docs: ["The account to get any returned rent"];
            isMut: true;
            isSigner: false;
            name: "receiver";
        }, {
            docs: ["The account being closed"];
            isMut: true;
            isSigner: false;
            name: "marginAccount";
        }];
        args: [];
        docs: ["Close a user's margin account", "", "This instruction does the following:", "", "1. Let `account`be a reference to the margin account being closed.", "", "2. Check if the loaded margin account has any open positions.", "", "a. If open positions exist, then return `ErrorCode::AccountNotEmpty`.", "", "3. Emit the `AccountClosed` event for data logging (see table below).", "", "4. Load the margin account.", "", "5. Return `Ok(())`.", "", "", "**Parameters of close\\_account.rs:**", "", "| | |", "| --- | --- |", "| **Name** | **Description** |", "| `owner` | The owner of the account being closed. |", "| `receiver` | The account to get any returned rent. |", "| `margin_account` | The account being closed. |", "", "**Events emitted by close\\_account.rs:**", "", "| | |", "| --- | --- |", "| **Event Name** | **Description** |", "| [`events::AccountClosed`] | The closed account (includes the margin account pubkey). |"];
        name: "closeAccount";
    }, {
        accounts: [{
            docs: ["The authority that can change the margin account"];
            isMut: false;
            isSigner: true;
            name: "authority";
        }, {
            docs: ["The address paying for rent"];
            isMut: true;
            isSigner: true;
            name: "payer";
        }, {
            docs: ["The margin account to register position type with"];
            isMut: true;
            isSigner: false;
            name: "marginAccount";
        }, {
            docs: ["The mint for the position token being registered"];
            isMut: false;
            isSigner: false;
            name: "positionTokenMint";
        }, {
            docs: ["The metadata account that references the correct oracle for the token"];
            isMut: false;
            isSigner: false;
            name: "metadata";
        }, {
            docs: ["The token account to store hold the position assets in the custody of the", "margin account."];
            isMut: true;
            isSigner: false;
            name: "tokenAccount";
        }, {
            isMut: false;
            isSigner: false;
            name: "tokenProgram";
        }, {
            isMut: false;
            isSigner: false;
            name: "rent";
        }, {
            isMut: false;
            isSigner: false;
            name: "systemProgram";
        }];
        args: [];
        docs: ["Register a position for some token that will be custodied by margin.", "Currently this applies to anything other than a claim.", "", "This instruction does the following:", "", "1. Register a new position that belongs to the individual margin account, allocate account space for it, and set the parameters for that asset type.", "", "2. Emit the `PositionRegistered` event for data logging (see table below).", "", "3. Return `Ok(())`.", "", "", "**Parameters of register\\_position.rs:**", "", "| | |", "| --- | --- |", "| **Name** | **Description** |", "| `authority` | The authority that can change the margin account. |", "| `payer` | The address paying for rent. |", "| `margin_account` | The margin account to register position type with. |", "| `position_token_mint` | The mint for the position token being registered. |", "| `metadata` | The metadata account that references the correct oracle for the token. |", "| `token_account` | The token account to store hold the position assets in the custody of the margin account. |", "| `token_program` | The token program of the token accounts to store for this margin account. |", "| `rent` | The rent to open the account. |", "| `system_program` | The system program. |", "", "**Events emitted by register\\_position.rs:**", "", "| | |", "| --- | --- |", "| **Event Name** | **Description** |", "| [`events::PositionRegistered`] | The position registered (includes the margin account pubkey, the authority pubkey of that margin account, and the position itself). |"];
        name: "registerPosition";
    }, {
        accounts: [{
            docs: ["The account to update"];
            isMut: true;
            isSigner: false;
            name: "marginAccount";
        }, {
            docs: ["The token account to update the balance for"];
            isMut: false;
            isSigner: false;
            name: "tokenAccount";
        }];
        args: [];
        docs: ["Update the balance of a position stored in the margin account to", "match the actual balance stored by the SPL token acount.", "", "This instruction does the following:", "", "1. Let `margin_account` be a mutable reference to the margin account.", "", "2. Let `token_account` be a reference to the token account.", "", "3. Load a margin account position and update it with `token_account`, `account`, and `balance`.", "", "4. Emit the `PositionBalanceUpdated` event for data logging (see table below).", "", "5. Return `Ok(())`.", "", "", "**Parameters of update\\_position\\_balance.rs:**", "", "| | |", "| --- | --- |", "| **Name** | **Description** |", "| `margin_account` | The margin account to update. |", "| `token_account` | The token account to update the balance for. |", "", "**Events emitted by update\\_position\\_balance.rs:**", "", "| | |", "| --- | --- |", "| **Event Name** | **Description** |", "| [`events::PositionBalanceUpdated`] | The updated position (includes the token account, margin account pubkey, and token balance). |", ""];
        name: "updatePositionBalance";
    }, {
        accounts: [{
            docs: ["The margin account with the position to be refreshed"];
            isMut: true;
            isSigner: false;
            name: "marginAccount";
        }, {
            docs: ["The metadata account for the token, which has been updated"];
            isMut: false;
            isSigner: false;
            name: "metadata";
        }];
        args: [];
        docs: ["Update the metadata for a position stored in the margin account,", "in the case where the metadata has changed after the position was", "created.", "This instruction does the following:", "", "1. Read account token metadata.", "", "2. Load the margin account.", "", "3. Update the position with refreshed metadata.", "", "4. Emit the `PositionMetadataRefreshed` event for data logging (see table below).", "", "5. Return `Ok(())`.", "", "", "**Parameters of refresh\\_position\\_metadata.rs:**", "", "| | |", "| --- | --- |", "| **Name** | **Description** |", "| `margin_account` | The margin account with the position to be refreshed. |", "| `metadata` | The metadata account for the token, which has been updated. |", "", "**Events emitted by refresh\\_position\\_metadata.rs:**", "", "| | |", "| --- | --- |", "| **Event Name** | **Description** |", "| [`events::PositionMetadataRefreshed`] | The position of which metadata was refreshed (including the margin account pubkey and the `position` itself). |"];
        name: "refreshPositionMetadata";
    }, {
        accounts: [{
            docs: ["The authority that can change the margin account"];
            isMut: false;
            isSigner: true;
            name: "authority";
        }, {
            docs: ["The receiver for the rent released"];
            isMut: true;
            isSigner: false;
            name: "receiver";
        }, {
            docs: ["The margin account with the position to close"];
            isMut: true;
            isSigner: false;
            name: "marginAccount";
        }, {
            docs: ["The mint for the position token being deregistered"];
            isMut: false;
            isSigner: false;
            name: "positionTokenMint";
        }, {
            docs: ["The token account for the position being closed"];
            isMut: true;
            isSigner: false;
            name: "tokenAccount";
        }, {
            isMut: false;
            isSigner: false;
            name: "tokenProgram";
        }];
        args: [];
        docs: ["Close out a position, freeing up space in the account.", "", "This instruction does the following:", "", "1. Let `account` be a mutable reference to the margin account.", "", "2. Verify the authority of `account`.", "", "3. Record unregistering (closing) the position in question of `account`, which involves passing the token mint account, token account, and margin account authority.", "", "4. If the token account authority of the account is the same as the authority.", "", "a. Return the token account.", "", "5. Emit the `PositionClosed` event for data logging (see table below):", "", "6. Return `Ok(())`.", "", "", "**Parameters of close\\_position.rs:**", "", "| | |", "| --- | --- |", "| **Name** | **Description** |", "| `authority` | The authority that can change the margin account. |", "| `receiver` | The receiver for the rent released. |", "| `margin_account` | The margin account with the position to close. |", "| `position_token_mint` | The mint for the position token being deregistered. |", "| `token_account` | The token account for the position being closed. |", "| `token_program` | The token program for the position being closed. |", "", "**Events emitted by close\\_position.rs:**", "", "| | |", "| --- | --- |", "| **Event Name** | **Description** |", "| [`events::PositionClosed`] | The closed position (includes the margin account authority’s pubkey and the relevant token pool’s note mint pubkey). |"];
        name: "closePosition";
    }, {
        accounts: [{
            docs: ["The account verify the health of"];
            isMut: false;
            isSigner: false;
            name: "marginAccount";
        }];
        args: [];
        docs: ["Verify that the account is healthy, by validating the collateralization", "ration is above the minimum.", "", "This instruction does the following:", "", "1. Let `account` be the loaded margin account.", "", "2. Check if all positions for that margin account are healthy.", "", "a. If there are unhealthy positions exist for this margin account, return `False`.", "", "3. Emit the `VerifiedHealthy` event for data logging (see table below).", "", "4. Return `Ok(())`.", "", "", "**Parameters of verify\\_healthy.rs:**", "", "| | |", "| --- | --- |", "| **Name** | **Description** |", "| `margin_account` | The account to verify the health of. |", "", "**Events emitted by verify\\_healthy.rs:**", "", "| | |", "| --- | --- |", "| **Event Name** | **Description** |", "|[`events::VerifiedHealthy`] | The margin account pubkeys of verified healthy accounts. |"];
        name: "verifyHealthy";
    }, {
        accounts: [{
            docs: ["The authority that owns the margin account"];
            isMut: false;
            isSigner: true;
            name: "owner";
        }, {
            docs: ["The margin account to proxy an action for"];
            isMut: true;
            isSigner: false;
            name: "marginAccount";
        }, {
            docs: ["The program to be invoked"];
            isMut: false;
            isSigner: false;
            name: "adapterProgram";
        }, {
            docs: ["The metadata about the proxy program"];
            isMut: false;
            isSigner: false;
            name: "adapterMetadata";
        }];
        args: [{
            name: "data";
            type: "bytes";
        }];
        docs: ["Perform an action by invoking other programs, allowing them to alter", "the balances of the token accounts belonging to this margin account.", "", "This instruction does the following:", "", "1. If a read account has the `liquidation` parameter set to a pubkey:", "", "a. This means that that margin account is already under liquidation by the liquidator at that pubkey.", "", "b. Return `ErrorCode::Liquidating`.", "", "2. Emit the `AdapterInvokeBegin` event for data logging (see table below).", "", "3. Check if any positions that have changed via adapters.", "", "a. For each changed position, emit each existing adapter position as an `event` (see table below).", "", "4. Emit the `AdapterInvokeEnd` event for data logging (see table below).", "", "5. Verify that margin accounts positions via adapter are healthy.", "", "6. Return `Ok(())`.", "", "", "**Parameters of adapter\\_invoke.rs:**", "", "| | |", "| --- | --- |", "| **Name** | **Description** |", "| `owner` | The authority that owns the margin account. |", "| `margin_account` | The margin account to proxy an action for. |", "| `adapter_program` | The program to be invoked. |", "| `adapter_metadata` | The metadata about the proxy program. |", "", "**Events emitted by adapter\\_invoke.rs:**", "", "| | |", "| --- | --- |", "| **Event Name** | **Description** |", "| [`events::AdapterInvokeBegin`] | Marks the start of the adapter invocation (includes the margin account pubkey and the adapter program pubkey). |", "| [`events::PositionEvent`] _(Note that each single event represents a different adapter position)_ | Each adapter position is emitted as an event (includes the margin account, the adapter program, the accounts, and a value of `true` for the field `signed`. |", "| [`events::AdapterInvokeEnd`] | Marks the ending of the adapter invocation (includes no data except for the event itself being emitted). |"];
        name: "adapterInvoke";
    }, {
        accounts: [{
            docs: ["The margin account to proxy an action for"];
            isMut: true;
            isSigner: false;
            name: "marginAccount";
        }, {
            docs: ["The program to be invoked"];
            isMut: false;
            isSigner: false;
            name: "adapterProgram";
        }, {
            docs: ["The metadata about the proxy program"];
            isMut: false;
            isSigner: false;
            name: "adapterMetadata";
        }];
        args: [{
            name: "data";
            type: "bytes";
        }];
        docs: ["Perform an action by invoking other programs, allowing them only to", "refresh the state of the margin account to be consistent with the actual", "underlying prices or positions, but not permitting new position changes.", "", "This instruction does the following:", "", "1. Emit `AccountingInvokeBegin` events for data logging (see table below).", "", "2. Check if any positions that have changed via adapters.", "", "a. For each changed position, emit each existing adapter position as an `event` (see table below).", "", "3. Emit `AccountingInvokeEnd` event for data logging (see table below).", "", "4. Return `Ok(())`.", "", "", "**Parameters of accounting\\_invoke.rs:**", "", "| | |", "| --- | --- |", "| **Name** | **Description** |", "| `margin_account` | The margin account to proxy an action for. |", "| `adapter_program` | The program to be invoked. |", "| `adapter_metadata` | The metadata about the proxy program. |", "", "**Events emitted by accounting\\_invoke.rs:**", "", "| | |", "| --- | --- |", "| **Name** | **Description** |", "| [`events::AccountingInvokeBegin`] | Signify that the accounting invocation process has begun. |", "| [`events::PositionEvent`] _(Note that each single event represents an different adapter position)_ | Each adapter position is emitted as an event (includes the margin account, the adapter program, the remaining accounts, and a value of `false` for the field `signed`. |", "| [`events::AccountingInvokeEnd`] | The margin account to proxy an action for. |"];
        name: "accountingInvoke";
    }, {
        accounts: [{
            docs: ["The account in need of liquidation"];
            isMut: true;
            isSigner: false;
            name: "marginAccount";
        }, {
            docs: ["The address paying rent"];
            isMut: true;
            isSigner: true;
            name: "payer";
        }, {
            docs: ["The liquidator account performing the liquidation actions"];
            isMut: false;
            isSigner: true;
            name: "liquidator";
        }, {
            docs: ["The metadata describing the liquidator"];
            isMut: false;
            isSigner: false;
            name: "liquidatorMetadata";
        }, {
            docs: ["Account to persist the state of the liquidation"];
            isMut: true;
            isSigner: false;
            name: "liquidation";
        }, {
            isMut: false;
            isSigner: false;
            name: "systemProgram";
        }];
        args: [];
        docs: ["Begin liquidating an account", "", "This instruction does the following:", "", "1. Read `liquidation` and `liquidator` from the account.", "", "2. Let `account` be a mutable reference to the margin account.", "", "3. Verify that the account is subject to liquidation, return `False` if not.", "", "4. Verify that the account is not already being liquidated.", "", "a. If the liquidator is already assigned to this margin account, do nothing.", "", "b. Else if there is no liquidator assigned to the unhealthy account, the liquidator can claim this unhealthy account and begin the process of liquidation.", "", "c. Otherwise return `ErrorCode::Liquidating` because it is already claimed by some other liquidator.", "", "5. Record the valuation of the account.", "", "6. Record the minimum valuation change of the account.", "", "7. Emit the `LiquidationBegun` event for data logging (see table below).", "", "8. Return `Ok(())`.", "", "", "**Parameters of liquidate\\_begin.rs:**", "", "| | |", "| --- | --- |", "| **Name** | **Description** |", "| `margin_account` | The account in need of liquidation. |", "| `payer` | The address paying rent. |", "| `liquidator` | The liquidator account performing the liquidation. |", "| `liquidator_metadata` | The metadata describing the liquidator. |", "| `liquidation` | The account to persist the state of liquidation. |", "| `system_program` | The system program. |", "", "**Events emitted by liquidate\\_begin.rs:**", "", "| | |", "| --- | --- |", "| **Event Name** | **Description** |", "| [`events::LiquidationBegun`] | The event marking the beginning of liquidation (Includes the margin account pubkey, the liquidator pubkey, the liquidation pubkey, the liquidation data, and the valuation of the margin account to be liquidated). |"];
        name: "liquidateBegin";
    }, {
        accounts: [{
            docs: ["If the liquidation is timed out, this can be any account", "If the liquidation is not timed out, this must be the liquidator, and it must be a signer"];
            isMut: true;
            isSigner: true;
            name: "authority";
        }, {
            docs: ["The account in need of liquidation"];
            isMut: true;
            isSigner: false;
            name: "marginAccount";
        }, {
            docs: ["Account to persist the state of the liquidation"];
            isMut: true;
            isSigner: false;
            name: "liquidation";
        }];
        args: [];
        docs: ["Stop liquidating an account", "", "This instruction does the following:", "", "1. Let `account` be a mutable reference to the margin account.", "", "2. Let `start_time` be the time that the liquidation on this margin account began, if it exists", "", "3. Let `timed_out` be the boolean representing the type of account:", "", "a. If the liquidation is timed out, then this can be any account.", "", "b. If the liquidation is not timed out, then this must be the liquidator, and it must be a signer.", "", "4. Check if the entity trying to end the liquidation is not the liquidator.", "", "a. If not, return `ErrorCode::UnauthorizedLiquidator`.", "", "5. Record the end of the liquidation.", "", "6. Emit the `LiquidationEnded` event for data logging (see table below).", "", "7. Return `Ok(())`.", "", "", "**Parameters of liquidate\\_end.rs:**", "", "| | |", "| --- | --- |", "| **Name** | **Description** |", "| `authority` | The pubkey calling the instruction to end liquidation. |", "| `margin_account` | The account in need of liquidation. |", "| `liquidation` | The account to persist the state of liquidation. |", "", "**Events emitted by liquidate\\_end.rs:**", "", "| | |", "| --- | --- |", "| **Event Name** | **Description** |", "| [`events::LiquidationEnded`] | The event marking the end of liquidation (Includes the margin account pubkey, the authority of the margin account pubkey, and the timed\\_out boolean that is true if the liquidation has timed out). |"];
        name: "liquidateEnd";
    }, {
        accounts: [{
            docs: ["The liquidator processing the margin account"];
            isMut: false;
            isSigner: true;
            name: "liquidator";
        }, {
            docs: ["Account to persist the state of the liquidation"];
            isMut: true;
            isSigner: false;
            name: "liquidation";
        }, {
            docs: ["The margin account to proxy an action for"];
            isMut: true;
            isSigner: false;
            name: "marginAccount";
        }, {
            docs: ["The program to be invoked"];
            isMut: false;
            isSigner: false;
            name: "adapterProgram";
        }, {
            docs: ["The metadata about the proxy program"];
            isMut: false;
            isSigner: false;
            name: "adapterMetadata";
        }];
        args: [{
            name: "data";
            type: "bytes";
        }];
        docs: ["Perform an action by invoking another program, for the purposes of", "liquidating a margin account.", "", "This instruction does the following:", "", "1. Load the margin account.", "", "2. Let `start_value` be the valuation of the margin account before invoking the liquidator.", "", "3. Emit the `LiquidatorInvokeBegin` event for data logging (see table below).", "", "4. Loop through adapter and store positions, getting and storing as `margin_account`, `adapter_program`, `accounts` and `signed`.", "", "5. Emit each adapter position as an `event` (see table below).", "", "6. Let`liquidation` be a mutable copy of the liquidated account.", "", "7. Let `end_value` be the valuation of the margin account after the liquidation attempt, after verifying that a liquidation did occur.", "", "8. Emit the `LiquidatorInvokeEnd` event for data logging (see table below).", "", "9. Return `Ok(())`.", "", "", "**Parameters of liquidator\\_invoke.rs:**", "", "| | |", "| --- | --- |", "| **Name** | **Description** |", "| `liquidator` | The liquidator processing the margin account. |", "| `liquidation` | The account to persist the state of liquidation. |", "| `margin_account` | The margin account to proxy an action for. |", "| `adapter_program` | The program to be invoked. |", "| `adapter_metadata` | The metadata about the proxy program. |", "", "**Events emitted by liquidator\\_invoke.rs:**", "", "| | |", "| --- | --- |", "| **Event Name** | **Description** |", "| [`events::LiquidatorInvokeBegin`] | Marks the beginning of this liquidation event (includes the margin account pubkey, the adapter program pubkey, and the liquidator pubkey that is liquidating that margin account or adapter position). |", "| [`events::PositionEvent`] _(Note that each single event represents an different adapter position)_ | Each adapter position is emitted as an event (includes the margin account, the adapter program, the accounts, and a value of `true` for the `signed` field. |", "| [`events::LiquidatorInvokeEnd`] | Marks the ending of this liquidator event (includes the liquidation data and the valuation of the account after liquidation has been performed). |"];
        name: "liquidatorInvoke";
    }, {
        accounts: [{
            docs: ["The margin account with the position to be refreshed"];
            isMut: true;
            isSigner: false;
            name: "marginAccount";
        }, {
            docs: ["The config account for the token, which has been updated"];
            isMut: false;
            isSigner: false;
            name: "config";
        }];
        args: [];
        docs: ["Update the config for a token position stored in the margin account,", "in the case where the token config has changed after the position was", "created."];
        name: "refreshPositionConfig";
    }, {
        accounts: [{
            docs: ["The account to update"];
            isMut: true;
            isSigner: false;
            name: "marginAccount";
        }, {
            docs: ["The margin config for the token"];
            isMut: false;
            isSigner: false;
            name: "config";
        }, {
            docs: ["The oracle for the token"];
            isMut: false;
            isSigner: false;
            name: "priceOracle";
        }];
        args: [];
        docs: ["Refresh the price/balance for a deposit position"];
        name: "refreshDepositPosition";
    }, {
        accounts: [{
            docs: ["The authority that can change the margin account"];
            isMut: false;
            isSigner: true;
            name: "authority";
        }, {
            docs: ["The address paying for rent"];
            isMut: true;
            isSigner: true;
            name: "payer";
        }, {
            docs: ["The margin account to register this deposit account with"];
            isMut: true;
            isSigner: false;
            name: "marginAccount";
        }, {
            docs: ["The mint for the token being stored in this account"];
            isMut: false;
            isSigner: false;
            name: "mint";
        }, {
            docs: ["The margin config for the token"];
            isMut: false;
            isSigner: false;
            name: "config";
        }, {
            docs: ["The token account to store deposits"];
            isMut: false;
            isSigner: false;
            name: "tokenAccount";
        }, {
            isMut: false;
            isSigner: false;
            name: "associatedTokenProgram";
        }, {
            isMut: false;
            isSigner: false;
            name: "tokenProgram";
        }, {
            isMut: false;
            isSigner: false;
            name: "rent";
        }, {
            isMut: false;
            isSigner: false;
            name: "systemProgram";
        }];
        args: [];
        docs: ["Create a new account for holding SPL token deposits directly by a margin account."];
        name: "createDepositPosition";
    }, {
        accounts: [{
            docs: ["The authority that owns the margin account"];
            isMut: false;
            isSigner: true;
            name: "owner";
        }, {
            docs: ["The margin account that the deposit account is associated with"];
            isMut: true;
            isSigner: false;
            name: "marginAccount";
        }, {
            docs: ["The authority for the source account"];
            isMut: false;
            isSigner: true;
            name: "sourceOwner";
        }, {
            docs: ["The source account to transfer tokens from"];
            isMut: true;
            isSigner: false;
            name: "source";
        }, {
            docs: ["The destination account to transfer tokens in"];
            isMut: true;
            isSigner: false;
            name: "destination";
        }, {
            isMut: false;
            isSigner: false;
            name: "tokenProgram";
        }];
        args: [{
            name: "amount";
            type: "u64";
        }];
        docs: ["Transfer tokens into or out of a token account being used for deposits."];
        name: "transferDeposit";
    }, {
        accounts: [{
            docs: ["The authority allowed to make changes to configuration"];
            isMut: false;
            isSigner: true;
            name: "authority";
        }, {
            docs: ["The airspace being modified"];
            isMut: false;
            isSigner: false;
            name: "airspace";
        }, {
            docs: ["The payer for any rent costs, if required"];
            isMut: true;
            isSigner: true;
            name: "payer";
        }, {
            docs: ["The mint for the token being configured"];
            isMut: false;
            isSigner: false;
            name: "mint";
        }, {
            docs: ["The config account to be modified"];
            isMut: true;
            isSigner: false;
            name: "tokenConfig";
        }, {
            isMut: false;
            isSigner: false;
            name: "systemProgram";
        }];
        args: [{
            name: "update";
            type: {
                option: {
                    defined: "TokenConfigUpdate";
                };
            };
        }];
        docs: ["Set the configuration for a token, which allows it to be used as a position in a margin", "account.", "", "The configuration for a token only applies for the associated airspace, and changing any", "configuration requires the airspace authority to sign.", "", "The account storing the configuration will be funded if not already. If a `None` is provided as", "the updated configuration, then the account will be defunded."];
        name: "configureToken";
    }, {
        accounts: [{
            docs: ["The authority allowed to make changes to configuration"];
            isMut: false;
            isSigner: true;
            name: "authority";
        }, {
            docs: ["The airspace being modified"];
            isMut: false;
            isSigner: false;
            name: "airspace";
        }, {
            docs: ["The payer for any rent costs, if required"];
            isMut: true;
            isSigner: true;
            name: "payer";
        }, {
            docs: ["The adapter being configured"];
            isMut: false;
            isSigner: false;
            name: "adapterProgram";
        }, {
            docs: ["The config account to be modified"];
            isMut: true;
            isSigner: false;
            name: "adapterConfig";
        }, {
            isMut: false;
            isSigner: false;
            name: "systemProgram";
        }];
        args: [{
            name: "isAdapter";
            type: "bool";
        }];
        docs: ["Set the configuration for an adapter.", "", "The configuration for a token only applies for the associated airspace, and changing any", "configuration requires the airspace authority to sign.", "", "The account storing the configuration will be funded if not already. If a `None` is provided as", "the updated configuration, then the account will be defunded."];
        name: "configureAdapter";
    }, {
        accounts: [{
            docs: ["The authority allowed to make changes to configuration"];
            isMut: false;
            isSigner: true;
            name: "authority";
        }, {
            docs: ["The airspace being modified"];
            isMut: false;
            isSigner: false;
            name: "airspace";
        }, {
            docs: ["The payer for any rent costs, if required"];
            isMut: true;
            isSigner: true;
            name: "payer";
        }, {
            docs: ["The liquidator being configured"];
            isMut: false;
            isSigner: false;
            name: "liquidator";
        }, {
            docs: ["The config account to be modified"];
            isMut: true;
            isSigner: false;
            name: "liquidatorConfig";
        }, {
            isMut: false;
            isSigner: false;
            name: "systemProgram";
        }];
        args: [{
            name: "isLiquidator";
            type: "bool";
        }];
        docs: ["Set the configuration for a liquidator.", "", "The configuration for a token only applies for the associated airspace, and changing any", "configuration requires the airspace authority to sign.", "", "The account storing the configuration will be funded if not already. If a `None` is provided as", "the updated configuration, then the account will be defunded."];
        name: "configureLiquidator";
    }];
    name: "jet_margin";
    types: [{
        name: "AdapterResult";
        type: {
            fields: [{
                docs: ["keyed by token mint, same as position"];
                name: "positionChanges";
                type: {
                    vec: {
                        defined: "(Pubkey,Vec<PositionChange>)";
                    };
                };
            }];
            kind: "struct";
        };
    }, {
        name: "PriceChangeInfo";
        type: {
            fields: [{
                docs: ["The current price of the asset"];
                name: "value";
                type: "i64";
            }, {
                docs: ["The current confidence value for the asset price"];
                name: "confidence";
                type: "u64";
            }, {
                docs: ["The recent average price"];
                name: "twap";
                type: "i64";
            }, {
                docs: ["The time that the price was published at"];
                name: "publishTime";
                type: "i64";
            }, {
                docs: ["The exponent for the price values"];
                name: "exponent";
                type: "i32";
            }];
            kind: "struct";
        };
    }, {
        name: "ValuationSummary";
        type: {
            fields: [{
                name: "equity";
                type: "i128";
            }, {
                name: "liabilities";
                type: "i128";
            }, {
                name: "requiredCollateral";
                type: "i128";
            }, {
                name: "weightedCollateral";
                type: "i128";
            }, {
                name: "effectiveCollateral";
                type: "i128";
            }, {
                name: "availableCollateral";
                type: "i128";
            }, {
                name: "pastDue";
                type: "bool";
            }];
            kind: "struct";
        };
    }, {
        name: "TokenConfigUpdate";
        type: {
            fields: [{
                docs: ["The underlying token represented, if any"];
                name: "underlyingMint";
                type: "publicKey";
            }, {
                docs: ["The adapter program in control of positions of this token"];
                name: "adapterProgram";
                type: {
                    option: "publicKey";
                };
            }, {
                docs: ["The oracle for the token"];
                name: "oracle";
                type: {
                    option: {
                        defined: "TokenOracle";
                    };
                };
            }, {
                docs: ["Description of this token"];
                name: "tokenKind";
                type: {
                    defined: "TokenKind";
                };
            }, {
                docs: ["A modifier to adjust the token value, based on the kind of token"];
                name: "valueModifier";
                type: "u16";
            }, {
                docs: ["The maximum staleness (seconds) that's acceptable for balances of this token"];
                name: "maxStaleness";
                type: "u64";
            }];
            kind: "struct";
        };
    }, {
        name: "AdapterPositionFlags";
        type: {
            fields: [{
                name: "flags";
                type: "u8";
            }];
            kind: "struct";
        };
    }, {
        name: "PriceInfo";
        type: {
            fields: [{
                docs: ["The current price"];
                name: "value";
                type: "i64";
            }, {
                docs: ["The timestamp the price was valid at"];
                name: "timestamp";
                type: "u64";
            }, {
                docs: ["The exponent for the price value"];
                name: "exponent";
                type: "i32";
            }, {
                docs: ["Flag indicating if the price is valid for the position"];
                name: "isValid";
                type: "u8";
            }, {
                name: "reserved";
                type: {
                    array: ["u8", 3];
                };
            }];
            kind: "struct";
        };
    }, {
        name: "AccountPosition";
        type: {
            fields: [{
                docs: ["The address of the token/mint of the asset"];
                name: "token";
                type: "publicKey";
            }, {
                docs: ["The address of the account holding the tokens."];
                name: "address";
                type: "publicKey";
            }, {
                docs: ["The address of the adapter managing the asset"];
                name: "adapter";
                type: "publicKey";
            }, {
                docs: ["The current value of this position, stored as a `Number128` with fixed precision."];
                name: "value";
                type: {
                    array: ["u8", 16];
                };
            }, {
                docs: ["The amount of tokens in the account"];
                name: "balance";
                type: "u64";
            }, {
                docs: ["The timestamp of the last balance update"];
                name: "balanceTimestamp";
                type: "u64";
            }, {
                docs: ["The current price/value of each token"];
                name: "price";
                type: {
                    defined: "PriceInfo";
                };
            }, {
                docs: ["The kind of balance this position contains"];
                name: "kind";
                type: "u32";
            }, {
                docs: ["The exponent for the token value"];
                name: "exponent";
                type: "i16";
            }, {
                docs: ["A weight on the value of this asset when counting collateral"];
                name: "valueModifier";
                type: "u16";
            }, {
                docs: ["The max staleness for the account balance (seconds)"];
                name: "maxStaleness";
                type: "u64";
            }, {
                docs: ["Flags that are set by the adapter"];
                name: "flags";
                type: {
                    defined: "AdapterPositionFlags";
                };
            }, {
                docs: ["Unused"];
                name: "reserved";
                type: {
                    array: ["u8", 23];
                };
            }];
            kind: "struct";
        };
    }, {
        name: "AccountPositionKey";
        type: {
            fields: [{
                docs: ["The address of the mint for the position token"];
                name: "mint";
                type: "publicKey";
            }, {
                docs: ["The array index where the data for this position is located"];
                name: "index";
                type: {
                    defined: "usize";
                };
            }];
            kind: "struct";
        };
    }, {
        name: "AccountPositionList";
        type: {
            fields: [{
                name: "length";
                type: {
                    defined: "usize";
                };
            }, {
                name: "map";
                type: {
                    array: [{
                        defined: "AccountPositionKey";
                    }, 32];
                };
            }, {
                name: "positions";
                type: {
                    array: [{
                        defined: "AccountPosition";
                    }, 32];
                };
            }];
            kind: "struct";
        };
    }, {
        name: "Liquidation";
        type: {
            fields: [{
                docs: ["time that liquidate_begin initialized this liquidation"];
                name: "startTime";
                type: "i64";
            }, {
                docs: ["cumulative change in equity caused by invocations during the liquidation so far", "negative if equity is lost"];
                name: "equityChange";
                type: "i128";
            }, {
                docs: ["lowest amount of equity change that is allowed during invoke steps", "typically negative or zero", "if equity_change goes lower than this number, liquidate_invoke should fail"];
                name: "minEquityChange";
                type: "i128";
            }];
            kind: "struct";
        };
    }, {
        name: "Invocation";
        type: {
            fields: [{
                name: "flags";
                type: "u8";
            }];
            kind: "struct";
        };
    }, {
        name: "PositionChange";
        type: {
            kind: "enum";
            variants: [{
                fields: [{
                    defined: "PriceChangeInfo";
                }];
                name: "Price";
            }, {
                fields: [{
                    defined: "AdapterPositionFlags";
                }, "bool"];
                name: "Flags";
            }, {
                fields: ["publicKey"];
                name: "Register";
            }, {
                fields: ["publicKey"];
                name: "Close";
            }];
        };
    }, {
        name: "PositionKind";
        type: {
            kind: "enum";
            variants: [{
                name: "NoValue";
            }, {
                name: "Deposit";
            }, {
                name: "Claim";
            }, {
                name: "AdapterCollateral";
            }];
        };
    }, {
        name: "Approver";
        type: {
            kind: "enum";
            variants: [{
                name: "MarginAccountAuthority";
            }, {
                fields: ["publicKey"];
                name: "Adapter";
            }];
        };
    }, {
        docs: ["Description of the token's usage"];
        name: "TokenKind";
        type: {
            kind: "enum";
            variants: [{
                name: "NoValue";
            }, {
                name: "Collateral";
            }, {
                name: "Claim";
            }, {
                name: "AdapterCollateral";
            }];
        };
    }, {
        docs: ["Information about where to find the oracle data for a token"];
        name: "TokenOracle";
        type: {
            kind: "enum";
            variants: [{
                fields: [{
                    docs: ["The pyth address containing price information for a token."];
                    name: "price";
                    type: "publicKey";
                }, {
                    docs: ["The pyth address with product information for a token"];
                    name: "product";
                    type: "publicKey";
                }];
                name: "Pyth";
            }];
        };
    }];
    version: "1.0.0";
}

Type declaration

  • accounts: [{
        name: "marginAccount";
        type: {
            fields: [{
                name: "version";
                type: "u8";
            }, {
                name: "bumpSeed";
                type: {
                    array: ["u8", 1];
                };
            }, {
                name: "userSeed";
                type: {
                    array: ["u8", 2];
                };
            }, {
                docs: ["Data an adapter can use to check what the margin program thinks about the current invocation", "Must normally be zeroed, except during an invocation."];
                name: "invocation";
                type: {
                    defined: "Invocation";
                };
            }, {
                name: "reserved0";
                type: {
                    array: ["u8", 3];
                };
            }, {
                docs: ["The owner of this account, which generally has to sign for any changes to it"];
                name: "owner";
                type: "publicKey";
            }, {
                docs: ["The state of an active liquidation for this account"];
                name: "liquidation";
                type: "publicKey";
            }, {
                docs: ["The active liquidator for this account"];
                name: "liquidator";
                type: "publicKey";
            }, {
                docs: ["The storage for tracking account balances"];
                name: "positions";
                type: {
                    array: ["u8", 7432];
                };
            }];
            kind: "struct";
        };
    }, {
        docs: ["State of an in-progress liquidation"];
        name: "liquidationState";
        type: {
            fields: [{
                docs: ["The state object"];
                name: "state";
                type: {
                    defined: "Liquidation";
                };
            }];
            kind: "struct";
        };
    }, {
        docs: ["The configuration account specifying parameters for a token when used", "in a position within a margin account."];
        name: "tokenConfig";
        type: {
            fields: [{
                docs: ["The mint for the token"];
                name: "mint";
                type: "publicKey";
            }, {
                docs: ["The mint for the underlying token represented, if any"];
                name: "underlyingMint";
                type: "publicKey";
            }, {
                docs: ["The space this config is valid within"];
                name: "airspace";
                type: "publicKey";
            }, {
                docs: ["The adapter program in control of positions of this token", "", "If this is `None`, then the margin program is in control of this asset, and", "thus determining its price. The `oracle` field must be set to allow the margin", "program to price the asset."];
                name: "adapterProgram";
                type: {
                    option: "publicKey";
                };
            }, {
                docs: ["The oracle for the token", "", "This only has effect in the margin program when the price for the token is not", "being managed by an adapter."];
                name: "oracle";
                type: {
                    option: {
                        defined: "TokenOracle";
                    };
                };
            }, {
                docs: ["Description of this token", "", "This determines the way the margin program values a token as a position in a", "margin account."];
                name: "tokenKind";
                type: {
                    defined: "TokenKind";
                };
            }, {
                docs: ["A modifier to adjust the token value, based on the kind of token"];
                name: "valueModifier";
                type: "u16";
            }, {
                docs: ["The maximum staleness (seconds) that's acceptable for balances of this token"];
                name: "maxStaleness";
                type: "u64";
            }];
            kind: "struct";
        };
    }, {
        docs: ["Configuration for allowed liquidators"];
        name: "liquidatorConfig";
        type: {
            fields: [{
                docs: ["The airspace this liquidator is being configured to act within"];
                name: "airspace";
                type: "publicKey";
            }, {
                docs: ["The address of the liquidator allowed to act"];
                name: "liquidator";
                type: "publicKey";
            }];
            kind: "struct";
        };
    }, {
        docs: ["Configuration for allowed adapters"];
        name: "adapterConfig";
        type: {
            fields: [{
                docs: ["The airspace this adapter can be used in"];
                name: "airspace";
                type: "publicKey";
            }, {
                docs: ["The program address allowed to be called as an adapter"];
                name: "adapterProgram";
                type: "publicKey";
            }];
            kind: "struct";
        };
    }]
  • constants: [{
        name: "TOKEN_CONFIG_SEED";
        type: {
            defined: "&[u8]";
        };
        value: "b\"token-config\"";
    }, {
        name: "ADAPTER_CONFIG_SEED";
        type: {
            defined: "&[u8]";
        };
        value: "b\"adapter-config\"";
    }, {
        name: "LIQUIDATOR_CONFIG_SEED";
        type: {
            defined: "&[u8]";
        };
        value: "b\"liquidator-config\"";
    }, {
        name: "MAX_ORACLE_CONFIDENCE";
        type: "u16";
        value: "5_00";
    }, {
        name: "MAX_ORACLE_STALENESS";
        type: "i64";
        value: "30";
    }, {
        name: "MAX_PRICE_QUOTE_AGE";
        type: "u64";
        value: "30";
    }, {
        name: "LIQUIDATION_TIMEOUT";
        type: {
            defined: "UnixTimestamp";
        };
        value: "60";
    }]
  • docs: ["This crate documents the instructions used in the `margin` program of the", "[jet-v2 repo](https://github.com/jet-lab/jet-v2/).", "Handler functions are described for each instruction well as struct parameters", "(and their types and descriptions are listed) and any handler function", "parameters aside from parameters that exist in every instruction handler function.", "Parameters of events emitted for the purposes of data logging are also included."]
  • errors: [{
        code: 141000;
        name: "NoAdapterResult";
    }, {
        code: 141001;
        msg: "The program that set the result was not the adapter";
        name: "WrongProgramAdapterResult";
    }, {
        code: 141002;
        msg: "this invocation is not authorized by the necessary accounts";
        name: "UnauthorizedInvocation";
    }, {
        code: 141003;
        msg: "the current instruction was not directly invoked by the margin program";
        name: "IndirectInvocation";
    }, {
        code: 141010;
        msg: "account cannot record any additional positions";
        name: "MaxPositions";
    }, {
        code: 141011;
        msg: "account has no record of the position";
        name: "UnknownPosition";
    }, {
        code: 141012;
        msg: "attempting to close a position that has a balance";
        name: "CloseNonZeroPosition";
    }, {
        code: 141013;
        msg: "attempting to register an existing position";
        name: "PositionAlreadyRegistered";
    }, {
        code: 141014;
        msg: "attempting to close non-empty margin account";
        name: "AccountNotEmpty";
    }, {
        code: 141015;
        msg: "attempting to use unregistered position";
        name: "PositionNotRegistered";
    }, {
        code: 141016;
        msg: "attempting to close a position that is required by the adapter";
        name: "CloseRequiredPosition";
    }, {
        code: 141017;
        msg: "registered position owner inconsistent with PositionTokenMetadata owner or token_kind";
        name: "InvalidPositionOwner";
    }, {
        code: 141018;
        msg: "dependencies are not satisfied to auto-register a required but unregistered position";
        name: "PositionNotRegisterable";
    }, {
        code: 141020;
        msg: "wrong adapter to modify the position";
        name: "InvalidPositionAdapter";
    }, {
        code: 141021;
        msg: "a position price is outdated";
        name: "OutdatedPrice";
    }, {
        code: 141022;
        msg: "an asset price is currently invalid";
        name: "InvalidPrice";
    }, {
        code: 141023;
        msg: "a position balance is outdated";
        name: "OutdatedBalance";
    }, {
        code: 141030;
        msg: "the account is not healthy";
        name: "Unhealthy";
    }, {
        code: 141031;
        msg: "the account is already healthy";
        name: "Healthy";
    }, {
        code: 141032;
        msg: "the account is being liquidated";
        name: "Liquidating";
    }, {
        code: 141033;
        msg: "the account is not being liquidated";
        name: "NotLiquidating";
    }, {
        code: 141034;
        name: "StalePositions";
    }, {
        code: 141040;
        msg: "the liquidator does not have permission to do this";
        name: "UnauthorizedLiquidator";
    }, {
        code: 141041;
        msg: "attempted to extract too much value during liquidation";
        name: "LiquidationLostValue";
    }, {
        code: 141050;
        msg: "attempting to mix entities from different airspaces";
        name: "WrongAirspace";
    }, {
        code: 141051;
        msg: "attempting to use or set invalid configuration";
        name: "InvalidConfig";
    }, {
        code: 141052;
        msg: "attempting to use or set invalid configuration";
        name: "InvalidOracle";
    }]
  • events: [{
        fields: [{
            index: false;
            name: "marginAccount";
            type: "publicKey";
        }, {
            index: false;
            name: "owner";
            type: "publicKey";
        }, {
            index: false;
            name: "seed";
            type: "u16";
        }];
        name: "AccountCreated";
    }, {
        fields: [{
            index: false;
            name: "marginAccount";
            type: "publicKey";
        }];
        name: "AccountClosed";
    }, {
        fields: [{
            index: false;
            name: "marginAccount";
            type: "publicKey";
        }];
        name: "VerifiedHealthy";
    }, {
        fields: [{
            index: false;
            name: "marginAccount";
            type: "publicKey";
        }, {
            index: false;
            name: "authority";
            type: "publicKey";
        }, {
            index: false;
            name: "position";
            type: {
                defined: "AccountPosition";
            };
        }];
        name: "PositionRegistered";
    }, {
        fields: [{
            index: false;
            name: "marginAccount";
            type: "publicKey";
        }, {
            index: false;
            name: "authority";
            type: "publicKey";
        }, {
            index: false;
            name: "token";
            type: "publicKey";
        }];
        name: "PositionClosed";
    }, {
        fields: [{
            index: false;
            name: "marginAccount";
            type: "publicKey";
        }, {
            index: false;
            name: "position";
            type: {
                defined: "AccountPosition";
            };
        }];
        name: "PositionMetadataRefreshed";
    }, {
        fields: [{
            index: false;
            name: "position";
            type: {
                defined: "AccountPosition";
            };
        }];
        name: "PositionBalanceUpdated";
    }, {
        fields: [{
            index: false;
            name: "position";
            type: {
                defined: "AccountPosition";
            };
        }];
        name: "PositionTouched";
    }, {
        fields: [{
            index: false;
            name: "marginAccount";
            type: "publicKey";
        }, {
            index: false;
            name: "adapterProgram";
            type: "publicKey";
        }];
        name: "AccountingInvokeBegin";
    }, {
        fields: [];
        name: "AccountingInvokeEnd";
    }, {
        fields: [{
            index: false;
            name: "marginAccount";
            type: "publicKey";
        }, {
            index: false;
            name: "adapterProgram";
            type: "publicKey";
        }];
        name: "AdapterInvokeBegin";
    }, {
        fields: [];
        name: "AdapterInvokeEnd";
    }, {
        fields: [{
            index: false;
            name: "marginAccount";
            type: "publicKey";
        }, {
            index: false;
            name: "liquidator";
            type: "publicKey";
        }, {
            index: false;
            name: "liquidation";
            type: "publicKey";
        }, {
            index: false;
            name: "liquidationData";
            type: {
                defined: "Liquidation";
            };
        }, {
            index: false;
            name: "valuationSummary";
            type: {
                defined: "ValuationSummary";
            };
        }];
        name: "LiquidationBegun";
    }, {
        fields: [{
            index: false;
            name: "marginAccount";
            type: "publicKey";
        }, {
            index: false;
            name: "adapterProgram";
            type: "publicKey";
        }, {
            index: false;
            name: "liquidator";
            type: "publicKey";
        }];
        name: "LiquidatorInvokeBegin";
    }, {
        fields: [{
            index: false;
            name: "liquidationData";
            type: {
                defined: "Liquidation";
            };
        }, {
            index: false;
            name: "valuationSummary";
            type: {
                defined: "ValuationSummary";
            };
        }];
        name: "LiquidatorInvokeEnd";
    }, {
        fields: [{
            index: false;
            name: "marginAccount";
            type: "publicKey";
        }, {
            index: false;
            name: "authority";
            type: "publicKey";
        }, {
            index: false;
            name: "timedOut";
            type: "bool";
        }];
        name: "LiquidationEnded";
    }]
  • instructions: [{
        accounts: [{
            docs: ["The owner of the new margin account"];
            isMut: false;
            isSigner: true;
            name: "owner";
        }, {
            isMut: true;
            isSigner: true;
            name: "payer";
        }, {
            docs: ["The margin account to initialize for the owner"];
            isMut: true;
            isSigner: false;
            name: "marginAccount";
        }, {
            isMut: false;
            isSigner: false;
            name: "systemProgram";
        }];
        args: [{
            name: "seed";
            type: "u16";
        }];
        docs: ["Create a new margin account for a user", "", "This instruction does the following:", "", "1. Let `account` be a mutable reference to the margin account.", "", "2. Initialize the margin account by setting the margin account version, owner,", "bump seed, user seed, and setting liquidator pubkey field to the default", "(if an account is being liquidated, the liquidator pubkey will be set here).", "", "3. Emit the `AccountCreated` event for data logging (see table below):", "", "4. Return `Ok(())`.", "", "", "**Parameters of create\\_account.rs:**", "", "| | |", "| --- | --- |", "| **Name** | **Description** |", "| `owner` | The owner of the new margin account. |", "| `payer` | The pubkey paying rent for the new margin account opening. |", "| `margin_account` | The margin account to initialize for the owner. |", "| `system_program` | The system program. |", "", "**Events emitted by create\\_account.rs:**", "", "| | |", "| --- | --- |", "| **Event Name** | **Description** |", "| [`events::AccountCreated`] | The created account (includes the margin account pubkey, the owner of margin account’s the pubkey, and the seed). |"];
        name: "createAccount";
    }, {
        accounts: [{
            docs: ["The owner of the account being closed"];
            isMut: false;
            isSigner: true;
            name: "owner";
        }, {
            docs: ["The account to get any returned rent"];
            isMut: true;
            isSigner: false;
            name: "receiver";
        }, {
            docs: ["The account being closed"];
            isMut: true;
            isSigner: false;
            name: "marginAccount";
        }];
        args: [];
        docs: ["Close a user's margin account", "", "This instruction does the following:", "", "1. Let `account`be a reference to the margin account being closed.", "", "2. Check if the loaded margin account has any open positions.", "", "a. If open positions exist, then return `ErrorCode::AccountNotEmpty`.", "", "3. Emit the `AccountClosed` event for data logging (see table below).", "", "4. Load the margin account.", "", "5. Return `Ok(())`.", "", "", "**Parameters of close\\_account.rs:**", "", "| | |", "| --- | --- |", "| **Name** | **Description** |", "| `owner` | The owner of the account being closed. |", "| `receiver` | The account to get any returned rent. |", "| `margin_account` | The account being closed. |", "", "**Events emitted by close\\_account.rs:**", "", "| | |", "| --- | --- |", "| **Event Name** | **Description** |", "| [`events::AccountClosed`] | The closed account (includes the margin account pubkey). |"];
        name: "closeAccount";
    }, {
        accounts: [{
            docs: ["The authority that can change the margin account"];
            isMut: false;
            isSigner: true;
            name: "authority";
        }, {
            docs: ["The address paying for rent"];
            isMut: true;
            isSigner: true;
            name: "payer";
        }, {
            docs: ["The margin account to register position type with"];
            isMut: true;
            isSigner: false;
            name: "marginAccount";
        }, {
            docs: ["The mint for the position token being registered"];
            isMut: false;
            isSigner: false;
            name: "positionTokenMint";
        }, {
            docs: ["The metadata account that references the correct oracle for the token"];
            isMut: false;
            isSigner: false;
            name: "metadata";
        }, {
            docs: ["The token account to store hold the position assets in the custody of the", "margin account."];
            isMut: true;
            isSigner: false;
            name: "tokenAccount";
        }, {
            isMut: false;
            isSigner: false;
            name: "tokenProgram";
        }, {
            isMut: false;
            isSigner: false;
            name: "rent";
        }, {
            isMut: false;
            isSigner: false;
            name: "systemProgram";
        }];
        args: [];
        docs: ["Register a position for some token that will be custodied by margin.", "Currently this applies to anything other than a claim.", "", "This instruction does the following:", "", "1. Register a new position that belongs to the individual margin account, allocate account space for it, and set the parameters for that asset type.", "", "2. Emit the `PositionRegistered` event for data logging (see table below).", "", "3. Return `Ok(())`.", "", "", "**Parameters of register\\_position.rs:**", "", "| | |", "| --- | --- |", "| **Name** | **Description** |", "| `authority` | The authority that can change the margin account. |", "| `payer` | The address paying for rent. |", "| `margin_account` | The margin account to register position type with. |", "| `position_token_mint` | The mint for the position token being registered. |", "| `metadata` | The metadata account that references the correct oracle for the token. |", "| `token_account` | The token account to store hold the position assets in the custody of the margin account. |", "| `token_program` | The token program of the token accounts to store for this margin account. |", "| `rent` | The rent to open the account. |", "| `system_program` | The system program. |", "", "**Events emitted by register\\_position.rs:**", "", "| | |", "| --- | --- |", "| **Event Name** | **Description** |", "| [`events::PositionRegistered`] | The position registered (includes the margin account pubkey, the authority pubkey of that margin account, and the position itself). |"];
        name: "registerPosition";
    }, {
        accounts: [{
            docs: ["The account to update"];
            isMut: true;
            isSigner: false;
            name: "marginAccount";
        }, {
            docs: ["The token account to update the balance for"];
            isMut: false;
            isSigner: false;
            name: "tokenAccount";
        }];
        args: [];
        docs: ["Update the balance of a position stored in the margin account to", "match the actual balance stored by the SPL token acount.", "", "This instruction does the following:", "", "1. Let `margin_account` be a mutable reference to the margin account.", "", "2. Let `token_account` be a reference to the token account.", "", "3. Load a margin account position and update it with `token_account`, `account`, and `balance`.", "", "4. Emit the `PositionBalanceUpdated` event for data logging (see table below).", "", "5. Return `Ok(())`.", "", "", "**Parameters of update\\_position\\_balance.rs:**", "", "| | |", "| --- | --- |", "| **Name** | **Description** |", "| `margin_account` | The margin account to update. |", "| `token_account` | The token account to update the balance for. |", "", "**Events emitted by update\\_position\\_balance.rs:**", "", "| | |", "| --- | --- |", "| **Event Name** | **Description** |", "| [`events::PositionBalanceUpdated`] | The updated position (includes the token account, margin account pubkey, and token balance). |", ""];
        name: "updatePositionBalance";
    }, {
        accounts: [{
            docs: ["The margin account with the position to be refreshed"];
            isMut: true;
            isSigner: false;
            name: "marginAccount";
        }, {
            docs: ["The metadata account for the token, which has been updated"];
            isMut: false;
            isSigner: false;
            name: "metadata";
        }];
        args: [];
        docs: ["Update the metadata for a position stored in the margin account,", "in the case where the metadata has changed after the position was", "created.", "This instruction does the following:", "", "1. Read account token metadata.", "", "2. Load the margin account.", "", "3. Update the position with refreshed metadata.", "", "4. Emit the `PositionMetadataRefreshed` event for data logging (see table below).", "", "5. Return `Ok(())`.", "", "", "**Parameters of refresh\\_position\\_metadata.rs:**", "", "| | |", "| --- | --- |", "| **Name** | **Description** |", "| `margin_account` | The margin account with the position to be refreshed. |", "| `metadata` | The metadata account for the token, which has been updated. |", "", "**Events emitted by refresh\\_position\\_metadata.rs:**", "", "| | |", "| --- | --- |", "| **Event Name** | **Description** |", "| [`events::PositionMetadataRefreshed`] | The position of which metadata was refreshed (including the margin account pubkey and the `position` itself). |"];
        name: "refreshPositionMetadata";
    }, {
        accounts: [{
            docs: ["The authority that can change the margin account"];
            isMut: false;
            isSigner: true;
            name: "authority";
        }, {
            docs: ["The receiver for the rent released"];
            isMut: true;
            isSigner: false;
            name: "receiver";
        }, {
            docs: ["The margin account with the position to close"];
            isMut: true;
            isSigner: false;
            name: "marginAccount";
        }, {
            docs: ["The mint for the position token being deregistered"];
            isMut: false;
            isSigner: false;
            name: "positionTokenMint";
        }, {
            docs: ["The token account for the position being closed"];
            isMut: true;
            isSigner: false;
            name: "tokenAccount";
        }, {
            isMut: false;
            isSigner: false;
            name: "tokenProgram";
        }];
        args: [];
        docs: ["Close out a position, freeing up space in the account.", "", "This instruction does the following:", "", "1. Let `account` be a mutable reference to the margin account.", "", "2. Verify the authority of `account`.", "", "3. Record unregistering (closing) the position in question of `account`, which involves passing the token mint account, token account, and margin account authority.", "", "4. If the token account authority of the account is the same as the authority.", "", "a. Return the token account.", "", "5. Emit the `PositionClosed` event for data logging (see table below):", "", "6. Return `Ok(())`.", "", "", "**Parameters of close\\_position.rs:**", "", "| | |", "| --- | --- |", "| **Name** | **Description** |", "| `authority` | The authority that can change the margin account. |", "| `receiver` | The receiver for the rent released. |", "| `margin_account` | The margin account with the position to close. |", "| `position_token_mint` | The mint for the position token being deregistered. |", "| `token_account` | The token account for the position being closed. |", "| `token_program` | The token program for the position being closed. |", "", "**Events emitted by close\\_position.rs:**", "", "| | |", "| --- | --- |", "| **Event Name** | **Description** |", "| [`events::PositionClosed`] | The closed position (includes the margin account authority’s pubkey and the relevant token pool’s note mint pubkey). |"];
        name: "closePosition";
    }, {
        accounts: [{
            docs: ["The account verify the health of"];
            isMut: false;
            isSigner: false;
            name: "marginAccount";
        }];
        args: [];
        docs: ["Verify that the account is healthy, by validating the collateralization", "ration is above the minimum.", "", "This instruction does the following:", "", "1. Let `account` be the loaded margin account.", "", "2. Check if all positions for that margin account are healthy.", "", "a. If there are unhealthy positions exist for this margin account, return `False`.", "", "3. Emit the `VerifiedHealthy` event for data logging (see table below).", "", "4. Return `Ok(())`.", "", "", "**Parameters of verify\\_healthy.rs:**", "", "| | |", "| --- | --- |", "| **Name** | **Description** |", "| `margin_account` | The account to verify the health of. |", "", "**Events emitted by verify\\_healthy.rs:**", "", "| | |", "| --- | --- |", "| **Event Name** | **Description** |", "|[`events::VerifiedHealthy`] | The margin account pubkeys of verified healthy accounts. |"];
        name: "verifyHealthy";
    }, {
        accounts: [{
            docs: ["The authority that owns the margin account"];
            isMut: false;
            isSigner: true;
            name: "owner";
        }, {
            docs: ["The margin account to proxy an action for"];
            isMut: true;
            isSigner: false;
            name: "marginAccount";
        }, {
            docs: ["The program to be invoked"];
            isMut: false;
            isSigner: false;
            name: "adapterProgram";
        }, {
            docs: ["The metadata about the proxy program"];
            isMut: false;
            isSigner: false;
            name: "adapterMetadata";
        }];
        args: [{
            name: "data";
            type: "bytes";
        }];
        docs: ["Perform an action by invoking other programs, allowing them to alter", "the balances of the token accounts belonging to this margin account.", "", "This instruction does the following:", "", "1. If a read account has the `liquidation` parameter set to a pubkey:", "", "a. This means that that margin account is already under liquidation by the liquidator at that pubkey.", "", "b. Return `ErrorCode::Liquidating`.", "", "2. Emit the `AdapterInvokeBegin` event for data logging (see table below).", "", "3. Check if any positions that have changed via adapters.", "", "a. For each changed position, emit each existing adapter position as an `event` (see table below).", "", "4. Emit the `AdapterInvokeEnd` event for data logging (see table below).", "", "5. Verify that margin accounts positions via adapter are healthy.", "", "6. Return `Ok(())`.", "", "", "**Parameters of adapter\\_invoke.rs:**", "", "| | |", "| --- | --- |", "| **Name** | **Description** |", "| `owner` | The authority that owns the margin account. |", "| `margin_account` | The margin account to proxy an action for. |", "| `adapter_program` | The program to be invoked. |", "| `adapter_metadata` | The metadata about the proxy program. |", "", "**Events emitted by adapter\\_invoke.rs:**", "", "| | |", "| --- | --- |", "| **Event Name** | **Description** |", "| [`events::AdapterInvokeBegin`] | Marks the start of the adapter invocation (includes the margin account pubkey and the adapter program pubkey). |", "| [`events::PositionEvent`] _(Note that each single event represents a different adapter position)_ | Each adapter position is emitted as an event (includes the margin account, the adapter program, the accounts, and a value of `true` for the field `signed`. |", "| [`events::AdapterInvokeEnd`] | Marks the ending of the adapter invocation (includes no data except for the event itself being emitted). |"];
        name: "adapterInvoke";
    }, {
        accounts: [{
            docs: ["The margin account to proxy an action for"];
            isMut: true;
            isSigner: false;
            name: "marginAccount";
        }, {
            docs: ["The program to be invoked"];
            isMut: false;
            isSigner: false;
            name: "adapterProgram";
        }, {
            docs: ["The metadata about the proxy program"];
            isMut: false;
            isSigner: false;
            name: "adapterMetadata";
        }];
        args: [{
            name: "data";
            type: "bytes";
        }];
        docs: ["Perform an action by invoking other programs, allowing them only to", "refresh the state of the margin account to be consistent with the actual", "underlying prices or positions, but not permitting new position changes.", "", "This instruction does the following:", "", "1. Emit `AccountingInvokeBegin` events for data logging (see table below).", "", "2. Check if any positions that have changed via adapters.", "", "a. For each changed position, emit each existing adapter position as an `event` (see table below).", "", "3. Emit `AccountingInvokeEnd` event for data logging (see table below).", "", "4. Return `Ok(())`.", "", "", "**Parameters of accounting\\_invoke.rs:**", "", "| | |", "| --- | --- |", "| **Name** | **Description** |", "| `margin_account` | The margin account to proxy an action for. |", "| `adapter_program` | The program to be invoked. |", "| `adapter_metadata` | The metadata about the proxy program. |", "", "**Events emitted by accounting\\_invoke.rs:**", "", "| | |", "| --- | --- |", "| **Name** | **Description** |", "| [`events::AccountingInvokeBegin`] | Signify that the accounting invocation process has begun. |", "| [`events::PositionEvent`] _(Note that each single event represents an different adapter position)_ | Each adapter position is emitted as an event (includes the margin account, the adapter program, the remaining accounts, and a value of `false` for the field `signed`. |", "| [`events::AccountingInvokeEnd`] | The margin account to proxy an action for. |"];
        name: "accountingInvoke";
    }, {
        accounts: [{
            docs: ["The account in need of liquidation"];
            isMut: true;
            isSigner: false;
            name: "marginAccount";
        }, {
            docs: ["The address paying rent"];
            isMut: true;
            isSigner: true;
            name: "payer";
        }, {
            docs: ["The liquidator account performing the liquidation actions"];
            isMut: false;
            isSigner: true;
            name: "liquidator";
        }, {
            docs: ["The metadata describing the liquidator"];
            isMut: false;
            isSigner: false;
            name: "liquidatorMetadata";
        }, {
            docs: ["Account to persist the state of the liquidation"];
            isMut: true;
            isSigner: false;
            name: "liquidation";
        }, {
            isMut: false;
            isSigner: false;
            name: "systemProgram";
        }];
        args: [];
        docs: ["Begin liquidating an account", "", "This instruction does the following:", "", "1. Read `liquidation` and `liquidator` from the account.", "", "2. Let `account` be a mutable reference to the margin account.", "", "3. Verify that the account is subject to liquidation, return `False` if not.", "", "4. Verify that the account is not already being liquidated.", "", "a. If the liquidator is already assigned to this margin account, do nothing.", "", "b. Else if there is no liquidator assigned to the unhealthy account, the liquidator can claim this unhealthy account and begin the process of liquidation.", "", "c. Otherwise return `ErrorCode::Liquidating` because it is already claimed by some other liquidator.", "", "5. Record the valuation of the account.", "", "6. Record the minimum valuation change of the account.", "", "7. Emit the `LiquidationBegun` event for data logging (see table below).", "", "8. Return `Ok(())`.", "", "", "**Parameters of liquidate\\_begin.rs:**", "", "| | |", "| --- | --- |", "| **Name** | **Description** |", "| `margin_account` | The account in need of liquidation. |", "| `payer` | The address paying rent. |", "| `liquidator` | The liquidator account performing the liquidation. |", "| `liquidator_metadata` | The metadata describing the liquidator. |", "| `liquidation` | The account to persist the state of liquidation. |", "| `system_program` | The system program. |", "", "**Events emitted by liquidate\\_begin.rs:**", "", "| | |", "| --- | --- |", "| **Event Name** | **Description** |", "| [`events::LiquidationBegun`] | The event marking the beginning of liquidation (Includes the margin account pubkey, the liquidator pubkey, the liquidation pubkey, the liquidation data, and the valuation of the margin account to be liquidated). |"];
        name: "liquidateBegin";
    }, {
        accounts: [{
            docs: ["If the liquidation is timed out, this can be any account", "If the liquidation is not timed out, this must be the liquidator, and it must be a signer"];
            isMut: true;
            isSigner: true;
            name: "authority";
        }, {
            docs: ["The account in need of liquidation"];
            isMut: true;
            isSigner: false;
            name: "marginAccount";
        }, {
            docs: ["Account to persist the state of the liquidation"];
            isMut: true;
            isSigner: false;
            name: "liquidation";
        }];
        args: [];
        docs: ["Stop liquidating an account", "", "This instruction does the following:", "", "1. Let `account` be a mutable reference to the margin account.", "", "2. Let `start_time` be the time that the liquidation on this margin account began, if it exists", "", "3. Let `timed_out` be the boolean representing the type of account:", "", "a. If the liquidation is timed out, then this can be any account.", "", "b. If the liquidation is not timed out, then this must be the liquidator, and it must be a signer.", "", "4. Check if the entity trying to end the liquidation is not the liquidator.", "", "a. If not, return `ErrorCode::UnauthorizedLiquidator`.", "", "5. Record the end of the liquidation.", "", "6. Emit the `LiquidationEnded` event for data logging (see table below).", "", "7. Return `Ok(())`.", "", "", "**Parameters of liquidate\\_end.rs:**", "", "| | |", "| --- | --- |", "| **Name** | **Description** |", "| `authority` | The pubkey calling the instruction to end liquidation. |", "| `margin_account` | The account in need of liquidation. |", "| `liquidation` | The account to persist the state of liquidation. |", "", "**Events emitted by liquidate\\_end.rs:**", "", "| | |", "| --- | --- |", "| **Event Name** | **Description** |", "| [`events::LiquidationEnded`] | The event marking the end of liquidation (Includes the margin account pubkey, the authority of the margin account pubkey, and the timed\\_out boolean that is true if the liquidation has timed out). |"];
        name: "liquidateEnd";
    }, {
        accounts: [{
            docs: ["The liquidator processing the margin account"];
            isMut: false;
            isSigner: true;
            name: "liquidator";
        }, {
            docs: ["Account to persist the state of the liquidation"];
            isMut: true;
            isSigner: false;
            name: "liquidation";
        }, {
            docs: ["The margin account to proxy an action for"];
            isMut: true;
            isSigner: false;
            name: "marginAccount";
        }, {
            docs: ["The program to be invoked"];
            isMut: false;
            isSigner: false;
            name: "adapterProgram";
        }, {
            docs: ["The metadata about the proxy program"];
            isMut: false;
            isSigner: false;
            name: "adapterMetadata";
        }];
        args: [{
            name: "data";
            type: "bytes";
        }];
        docs: ["Perform an action by invoking another program, for the purposes of", "liquidating a margin account.", "", "This instruction does the following:", "", "1. Load the margin account.", "", "2. Let `start_value` be the valuation of the margin account before invoking the liquidator.", "", "3. Emit the `LiquidatorInvokeBegin` event for data logging (see table below).", "", "4. Loop through adapter and store positions, getting and storing as `margin_account`, `adapter_program`, `accounts` and `signed`.", "", "5. Emit each adapter position as an `event` (see table below).", "", "6. Let`liquidation` be a mutable copy of the liquidated account.", "", "7. Let `end_value` be the valuation of the margin account after the liquidation attempt, after verifying that a liquidation did occur.", "", "8. Emit the `LiquidatorInvokeEnd` event for data logging (see table below).", "", "9. Return `Ok(())`.", "", "", "**Parameters of liquidator\\_invoke.rs:**", "", "| | |", "| --- | --- |", "| **Name** | **Description** |", "| `liquidator` | The liquidator processing the margin account. |", "| `liquidation` | The account to persist the state of liquidation. |", "| `margin_account` | The margin account to proxy an action for. |", "| `adapter_program` | The program to be invoked. |", "| `adapter_metadata` | The metadata about the proxy program. |", "", "**Events emitted by liquidator\\_invoke.rs:**", "", "| | |", "| --- | --- |", "| **Event Name** | **Description** |", "| [`events::LiquidatorInvokeBegin`] | Marks the beginning of this liquidation event (includes the margin account pubkey, the adapter program pubkey, and the liquidator pubkey that is liquidating that margin account or adapter position). |", "| [`events::PositionEvent`] _(Note that each single event represents an different adapter position)_ | Each adapter position is emitted as an event (includes the margin account, the adapter program, the accounts, and a value of `true` for the `signed` field. |", "| [`events::LiquidatorInvokeEnd`] | Marks the ending of this liquidator event (includes the liquidation data and the valuation of the account after liquidation has been performed). |"];
        name: "liquidatorInvoke";
    }, {
        accounts: [{
            docs: ["The margin account with the position to be refreshed"];
            isMut: true;
            isSigner: false;
            name: "marginAccount";
        }, {
            docs: ["The config account for the token, which has been updated"];
            isMut: false;
            isSigner: false;
            name: "config";
        }];
        args: [];
        docs: ["Update the config for a token position stored in the margin account,", "in the case where the token config has changed after the position was", "created."];
        name: "refreshPositionConfig";
    }, {
        accounts: [{
            docs: ["The account to update"];
            isMut: true;
            isSigner: false;
            name: "marginAccount";
        }, {
            docs: ["The margin config for the token"];
            isMut: false;
            isSigner: false;
            name: "config";
        }, {
            docs: ["The oracle for the token"];
            isMut: false;
            isSigner: false;
            name: "priceOracle";
        }];
        args: [];
        docs: ["Refresh the price/balance for a deposit position"];
        name: "refreshDepositPosition";
    }, {
        accounts: [{
            docs: ["The authority that can change the margin account"];
            isMut: false;
            isSigner: true;
            name: "authority";
        }, {
            docs: ["The address paying for rent"];
            isMut: true;
            isSigner: true;
            name: "payer";
        }, {
            docs: ["The margin account to register this deposit account with"];
            isMut: true;
            isSigner: false;
            name: "marginAccount";
        }, {
            docs: ["The mint for the token being stored in this account"];
            isMut: false;
            isSigner: false;
            name: "mint";
        }, {
            docs: ["The margin config for the token"];
            isMut: false;
            isSigner: false;
            name: "config";
        }, {
            docs: ["The token account to store deposits"];
            isMut: false;
            isSigner: false;
            name: "tokenAccount";
        }, {
            isMut: false;
            isSigner: false;
            name: "associatedTokenProgram";
        }, {
            isMut: false;
            isSigner: false;
            name: "tokenProgram";
        }, {
            isMut: false;
            isSigner: false;
            name: "rent";
        }, {
            isMut: false;
            isSigner: false;
            name: "systemProgram";
        }];
        args: [];
        docs: ["Create a new account for holding SPL token deposits directly by a margin account."];
        name: "createDepositPosition";
    }, {
        accounts: [{
            docs: ["The authority that owns the margin account"];
            isMut: false;
            isSigner: true;
            name: "owner";
        }, {
            docs: ["The margin account that the deposit account is associated with"];
            isMut: true;
            isSigner: false;
            name: "marginAccount";
        }, {
            docs: ["The authority for the source account"];
            isMut: false;
            isSigner: true;
            name: "sourceOwner";
        }, {
            docs: ["The source account to transfer tokens from"];
            isMut: true;
            isSigner: false;
            name: "source";
        }, {
            docs: ["The destination account to transfer tokens in"];
            isMut: true;
            isSigner: false;
            name: "destination";
        }, {
            isMut: false;
            isSigner: false;
            name: "tokenProgram";
        }];
        args: [{
            name: "amount";
            type: "u64";
        }];
        docs: ["Transfer tokens into or out of a token account being used for deposits."];
        name: "transferDeposit";
    }, {
        accounts: [{
            docs: ["The authority allowed to make changes to configuration"];
            isMut: false;
            isSigner: true;
            name: "authority";
        }, {
            docs: ["The airspace being modified"];
            isMut: false;
            isSigner: false;
            name: "airspace";
        }, {
            docs: ["The payer for any rent costs, if required"];
            isMut: true;
            isSigner: true;
            name: "payer";
        }, {
            docs: ["The mint for the token being configured"];
            isMut: false;
            isSigner: false;
            name: "mint";
        }, {
            docs: ["The config account to be modified"];
            isMut: true;
            isSigner: false;
            name: "tokenConfig";
        }, {
            isMut: false;
            isSigner: false;
            name: "systemProgram";
        }];
        args: [{
            name: "update";
            type: {
                option: {
                    defined: "TokenConfigUpdate";
                };
            };
        }];
        docs: ["Set the configuration for a token, which allows it to be used as a position in a margin", "account.", "", "The configuration for a token only applies for the associated airspace, and changing any", "configuration requires the airspace authority to sign.", "", "The account storing the configuration will be funded if not already. If a `None` is provided as", "the updated configuration, then the account will be defunded."];
        name: "configureToken";
    }, {
        accounts: [{
            docs: ["The authority allowed to make changes to configuration"];
            isMut: false;
            isSigner: true;
            name: "authority";
        }, {
            docs: ["The airspace being modified"];
            isMut: false;
            isSigner: false;
            name: "airspace";
        }, {
            docs: ["The payer for any rent costs, if required"];
            isMut: true;
            isSigner: true;
            name: "payer";
        }, {
            docs: ["The adapter being configured"];
            isMut: false;
            isSigner: false;
            name: "adapterProgram";
        }, {
            docs: ["The config account to be modified"];
            isMut: true;
            isSigner: false;
            name: "adapterConfig";
        }, {
            isMut: false;
            isSigner: false;
            name: "systemProgram";
        }];
        args: [{
            name: "isAdapter";
            type: "bool";
        }];
        docs: ["Set the configuration for an adapter.", "", "The configuration for a token only applies for the associated airspace, and changing any", "configuration requires the airspace authority to sign.", "", "The account storing the configuration will be funded if not already. If a `None` is provided as", "the updated configuration, then the account will be defunded."];
        name: "configureAdapter";
    }, {
        accounts: [{
            docs: ["The authority allowed to make changes to configuration"];
            isMut: false;
            isSigner: true;
            name: "authority";
        }, {
            docs: ["The airspace being modified"];
            isMut: false;
            isSigner: false;
            name: "airspace";
        }, {
            docs: ["The payer for any rent costs, if required"];
            isMut: true;
            isSigner: true;
            name: "payer";
        }, {
            docs: ["The liquidator being configured"];
            isMut: false;
            isSigner: false;
            name: "liquidator";
        }, {
            docs: ["The config account to be modified"];
            isMut: true;
            isSigner: false;
            name: "liquidatorConfig";
        }, {
            isMut: false;
            isSigner: false;
            name: "systemProgram";
        }];
        args: [{
            name: "isLiquidator";
            type: "bool";
        }];
        docs: ["Set the configuration for a liquidator.", "", "The configuration for a token only applies for the associated airspace, and changing any", "configuration requires the airspace authority to sign.", "", "The account storing the configuration will be funded if not already. If a `None` is provided as", "the updated configuration, then the account will be defunded."];
        name: "configureLiquidator";
    }]
  • name: "jet_margin"
  • types: [{
        name: "AdapterResult";
        type: {
            fields: [{
                docs: ["keyed by token mint, same as position"];
                name: "positionChanges";
                type: {
                    vec: {
                        defined: "(Pubkey,Vec<PositionChange>)";
                    };
                };
            }];
            kind: "struct";
        };
    }, {
        name: "PriceChangeInfo";
        type: {
            fields: [{
                docs: ["The current price of the asset"];
                name: "value";
                type: "i64";
            }, {
                docs: ["The current confidence value for the asset price"];
                name: "confidence";
                type: "u64";
            }, {
                docs: ["The recent average price"];
                name: "twap";
                type: "i64";
            }, {
                docs: ["The time that the price was published at"];
                name: "publishTime";
                type: "i64";
            }, {
                docs: ["The exponent for the price values"];
                name: "exponent";
                type: "i32";
            }];
            kind: "struct";
        };
    }, {
        name: "ValuationSummary";
        type: {
            fields: [{
                name: "equity";
                type: "i128";
            }, {
                name: "liabilities";
                type: "i128";
            }, {
                name: "requiredCollateral";
                type: "i128";
            }, {
                name: "weightedCollateral";
                type: "i128";
            }, {
                name: "effectiveCollateral";
                type: "i128";
            }, {
                name: "availableCollateral";
                type: "i128";
            }, {
                name: "pastDue";
                type: "bool";
            }];
            kind: "struct";
        };
    }, {
        name: "TokenConfigUpdate";
        type: {
            fields: [{
                docs: ["The underlying token represented, if any"];
                name: "underlyingMint";
                type: "publicKey";
            }, {
                docs: ["The adapter program in control of positions of this token"];
                name: "adapterProgram";
                type: {
                    option: "publicKey";
                };
            }, {
                docs: ["The oracle for the token"];
                name: "oracle";
                type: {
                    option: {
                        defined: "TokenOracle";
                    };
                };
            }, {
                docs: ["Description of this token"];
                name: "tokenKind";
                type: {
                    defined: "TokenKind";
                };
            }, {
                docs: ["A modifier to adjust the token value, based on the kind of token"];
                name: "valueModifier";
                type: "u16";
            }, {
                docs: ["The maximum staleness (seconds) that's acceptable for balances of this token"];
                name: "maxStaleness";
                type: "u64";
            }];
            kind: "struct";
        };
    }, {
        name: "AdapterPositionFlags";
        type: {
            fields: [{
                name: "flags";
                type: "u8";
            }];
            kind: "struct";
        };
    }, {
        name: "PriceInfo";
        type: {
            fields: [{
                docs: ["The current price"];
                name: "value";
                type: "i64";
            }, {
                docs: ["The timestamp the price was valid at"];
                name: "timestamp";
                type: "u64";
            }, {
                docs: ["The exponent for the price value"];
                name: "exponent";
                type: "i32";
            }, {
                docs: ["Flag indicating if the price is valid for the position"];
                name: "isValid";
                type: "u8";
            }, {
                name: "reserved";
                type: {
                    array: ["u8", 3];
                };
            }];
            kind: "struct";
        };
    }, {
        name: "AccountPosition";
        type: {
            fields: [{
                docs: ["The address of the token/mint of the asset"];
                name: "token";
                type: "publicKey";
            }, {
                docs: ["The address of the account holding the tokens."];
                name: "address";
                type: "publicKey";
            }, {
                docs: ["The address of the adapter managing the asset"];
                name: "adapter";
                type: "publicKey";
            }, {
                docs: ["The current value of this position, stored as a `Number128` with fixed precision."];
                name: "value";
                type: {
                    array: ["u8", 16];
                };
            }, {
                docs: ["The amount of tokens in the account"];
                name: "balance";
                type: "u64";
            }, {
                docs: ["The timestamp of the last balance update"];
                name: "balanceTimestamp";
                type: "u64";
            }, {
                docs: ["The current price/value of each token"];
                name: "price";
                type: {
                    defined: "PriceInfo";
                };
            }, {
                docs: ["The kind of balance this position contains"];
                name: "kind";
                type: "u32";
            }, {
                docs: ["The exponent for the token value"];
                name: "exponent";
                type: "i16";
            }, {
                docs: ["A weight on the value of this asset when counting collateral"];
                name: "valueModifier";
                type: "u16";
            }, {
                docs: ["The max staleness for the account balance (seconds)"];
                name: "maxStaleness";
                type: "u64";
            }, {
                docs: ["Flags that are set by the adapter"];
                name: "flags";
                type: {
                    defined: "AdapterPositionFlags";
                };
            }, {
                docs: ["Unused"];
                name: "reserved";
                type: {
                    array: ["u8", 23];
                };
            }];
            kind: "struct";
        };
    }, {
        name: "AccountPositionKey";
        type: {
            fields: [{
                docs: ["The address of the mint for the position token"];
                name: "mint";
                type: "publicKey";
            }, {
                docs: ["The array index where the data for this position is located"];
                name: "index";
                type: {
                    defined: "usize";
                };
            }];
            kind: "struct";
        };
    }, {
        name: "AccountPositionList";
        type: {
            fields: [{
                name: "length";
                type: {
                    defined: "usize";
                };
            }, {
                name: "map";
                type: {
                    array: [{
                        defined: "AccountPositionKey";
                    }, 32];
                };
            }, {
                name: "positions";
                type: {
                    array: [{
                        defined: "AccountPosition";
                    }, 32];
                };
            }];
            kind: "struct";
        };
    }, {
        name: "Liquidation";
        type: {
            fields: [{
                docs: ["time that liquidate_begin initialized this liquidation"];
                name: "startTime";
                type: "i64";
            }, {
                docs: ["cumulative change in equity caused by invocations during the liquidation so far", "negative if equity is lost"];
                name: "equityChange";
                type: "i128";
            }, {
                docs: ["lowest amount of equity change that is allowed during invoke steps", "typically negative or zero", "if equity_change goes lower than this number, liquidate_invoke should fail"];
                name: "minEquityChange";
                type: "i128";
            }];
            kind: "struct";
        };
    }, {
        name: "Invocation";
        type: {
            fields: [{
                name: "flags";
                type: "u8";
            }];
            kind: "struct";
        };
    }, {
        name: "PositionChange";
        type: {
            kind: "enum";
            variants: [{
                fields: [{
                    defined: "PriceChangeInfo";
                }];
                name: "Price";
            }, {
                fields: [{
                    defined: "AdapterPositionFlags";
                }, "bool"];
                name: "Flags";
            }, {
                fields: ["publicKey"];
                name: "Register";
            }, {
                fields: ["publicKey"];
                name: "Close";
            }];
        };
    }, {
        name: "PositionKind";
        type: {
            kind: "enum";
            variants: [{
                name: "NoValue";
            }, {
                name: "Deposit";
            }, {
                name: "Claim";
            }, {
                name: "AdapterCollateral";
            }];
        };
    }, {
        name: "Approver";
        type: {
            kind: "enum";
            variants: [{
                name: "MarginAccountAuthority";
            }, {
                fields: ["publicKey"];
                name: "Adapter";
            }];
        };
    }, {
        docs: ["Description of the token's usage"];
        name: "TokenKind";
        type: {
            kind: "enum";
            variants: [{
                name: "NoValue";
            }, {
                name: "Collateral";
            }, {
                name: "Claim";
            }, {
                name: "AdapterCollateral";
            }];
        };
    }, {
        docs: ["Information about where to find the oracle data for a token"];
        name: "TokenOracle";
        type: {
            kind: "enum";
            variants: [{
                fields: [{
                    docs: ["The pyth address containing price information for a token."];
                    name: "price";
                    type: "publicKey";
                }, {
                    docs: ["The pyth address with product information for a token"];
                    name: "product";
                    type: "publicKey";
                }];
                name: "Pyth";
            }];
        };
    }]
  • version: "1.0.0"

Generated using TypeDoc