Terra Classic Delta-Neutral Strategy (Retired)

This guide is intended for developers who wish to interact with Aperture contracts directly on Avalanche. Regular users are advised to use the official Aperture web app.

Please consult the Deployed Contracts page for contract addresses on various networks.

Open Position

To open a position on Aperture, interact with the Aperture Manager contract on Terra with the ExecuteMsg variant CreatePosition:

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum ExecuteMsg {
    /// Create a new position with the specified strategy.
    /// Can be called by any Terra address.
    CreatePosition {
        strategy: Strategy,
        data: Option<Binary>,
        assets: Vec<terraswap::asset::Asset>,
    }
}

/// The strategy id and chain id can uniquely identify what strategy it is
/// and on which chain is it located.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct Strategy {
    pub chain_id: u16,
    pub strategy_id: Uint64,
}
Key
Type
Description

strategy

Strategy

Specifies the strategy to use.

data

Binary

Binary representing parameters taken by the specificed strategy.

assets

Vector of assets to deposit into the position.

Delta-neutral Strategy (Terra)

Strategy JSON:

{
  "chain_id": 3,
  "strategy_id": "0"
}

Note that the chain_id value for Terra is 3. Aperture uses the same chain_id values as Wormhole.

Parameter (data) format:

The delta-neutral strategy requires a set of parameters of the following JSON format:

{
  "target_min_collateral_ratio": "2.4",
  "target_max_collateral_ratio": "2.8",
  "mirror_asset_cw20_addr": "terra1..."
}

target_min_collateral_ratio and target_max_collateral_ratio specify the target collateral ratio range with the following requirements:

  • target_min_collateral_ratio must exceed the minimum required collateral ratio for the mAsset by at least the safety margin amount. The safety margin value is configurable by the Delta-neutral Manager contract, currently set at 0.3. For example, if the minimum collateral ratio required for mAAPL is 1.5, then target_min_collateral_ratio must be at least 1.8.

  • Currently the target CR range must be 0.4 wide, i.e. the equality target_min_collateral_ratio + 0.4 = target_max_collateral_ratio must hold.

The parameter JSON should be encoded in base-64 and passed as the data field of the CreatePosition enum variant when opening a position.

Sample position-open tx: https://terrasco.pe/mainnet/tx/A87F26A7A6137C87E968B02AC20CCB2F1FE2313D42349FAD3F330D3A50CA1AC8

Query Position Ids

To get a list of position ids held by a Terra address, query the Aperture Manager contract with the following request:

{
  "get_terra_positions_by_holder": {
    "holder": "terra1..."
  }
}

Note that all position ids are returned, including active and closed positions.

Query Position Information

You may query the Delta-neutral Manager contract for detailed position information with the following request:

{
  "batch_get_position_info": {
    "positions": [
        {
            "chain_id": 3,
            "position_id": "1"
        }
    ]
  }
}

Note that you may specify multiple position ids in the positions array. However, most Terra nodes set a low query gas limit so you may receive an out-of-gas error if more than one position id is requested. It is recommended to use Terra Hive for batch query use cases.

Close Position

To open a position on Aperture, interact with the Aperture Manager contract on Terra with the ExecuteMsg variant CreatePosition:

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum ExecuteMsg {
    /// Perform an action on an existing positions held by a Terra address.
    /// Can only be called by the position holder.
    ExecuteStrategy {
        position_id: Uint128,
        action: Action,
        assets: Vec<terraswap::asset::Asset>,
    },
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum Action {
    ClosePosition {
        recipient: Recipient,
    },
    ...
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum Recipient {
    TerraChain {
        recipient: String,
    },
    ExternalChain {
      /// Details to be added prior to Aperture's cross-chain launch.
    },
}
Key
Type
Description

position_id

Uint128

Specifies the id of the position to close. The caller must be the position holder.

action

Action

Should specify the ClosePosition Action variant with the desired recipient (could be the position holder address or any other address).

assets

Must be an empty vector since no deposits are needed for the close-position action.

Sample position-close tx: https://terrasco.pe/mainnet/tx/5F437BD5AC9DD6B038D8C1A5B2AEAF4928BE817F5BFE4A82530E5B914354E763

Last updated