Aperture Finance
  • Aperture Introduction
    • ๐Ÿค–AI Powered Intents
  • $APTR Token
    • ๐Ÿ“ฌToken Info
    • ๐ŸฅงTokenomics
  • Liquidity Intents
    • ๐ŸฅžLP Tooling & Automation
    • ๐ŸŽ›๏ธSupported AMMs and Networks
    • โš–๏ธRecurring Rebalance Strategy
    • โš–๏ธAutomated Rebalance (One-time Move Range)
    • ๐ŸšชAutomated Position Closure (Prescheduled Positionย Close)
    • ๐Ÿฅ•Auto Compound
    • ๐Ÿ’ฐRevenue Earning Limit Orders
    • ๐ŸŒŠLiquidity Source
    • ๐Ÿ–๏ธDune Dashboard
    • โ”FAQ
  • MaaS (Market maker as a Service)
    • โ›ฉ๏ธIntro
    • ๐ŸฆพHow does MaaS work
  • ApertureSwap (DEX)
    • ๐ŸŒŠApertureSwap on Manta Pacific L2
  • Technical Docs
    • ๐ŸงฎOpen Source Code
    • ๐Ÿ–ฅ๏ธAPI Documentation
  • Transparency
    • ๐Ÿ’ฑFees
    • ๐ŸšœDeployed Contracts
    • ๐Ÿ”Security Audit
  • Community
    • ๐Ÿงžโ€โ™‚๏ธAnalytics
    • ๐Ÿ”—Links
  • Legacy Products
    • ๐Ÿฆ€Crab Market Leveraged Farming (Retired)
      • ๐ŸงฎRebalancer
    • ๐Ÿ‚Bull Market Leveraged Farming (Retired)
    • ๐Ÿš€Terra Classic Delta-Neutral Strategy (Retired)
      • Constant-product AMM
      • Position Open
      • Rebalance & Liquidation Protection
      • Fees & Minimum Investment Size
      • APR: A Day by Day Breakdown
    • ๐Ÿ“”Deployed Contracts
    • ๐Ÿ–ฅ๏ธIntegration Guide
      • Avalanche Pseudo-Delta-Neutral Leveraged Farming
      • Terra Classic Delta-Neutral Strategy (Retired)
  • PAST CAMPAIGN
    • โ˜๏ธINTENTional (Points) Campaign
  • Liquidity Academy
    • Tick, tick width and automation
Powered by GitBook
On this page
  • Open Position
  • Delta-neutral Strategy (Terra)
  • Query Position Ids
  • Query Position Information
  • Close Position
  1. Legacy Products
  2. Integration Guide

Terra Classic Delta-Neutral Strategy (Retired)

PreviousAvalanche Pseudo-Delta-Neutral Leveraged FarmingNextINTENTional (Points) Campaign

Last updated 2 years ago

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 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,
}
{
  "create_position": {
    "strategy": {
      "chain_id": 3,
      "strategy_id": "0"
    },
    "data": "e...",
    "assets": [
      {
        "info": {
          "native_token": {
            "denom":"uusd"
          }
        },
        "amount":"2000000000"
      }
    ]
  }
}
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"
}

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.

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"
        }
    ]
  }
}

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.
    },
}
{
  "execute_strategy": {
    "position_id": "12345",
    "action": {
      "close_position": {
        "recipient": {
          "terra_chain": {
            "recipient": "terra1..."
          }
        }
      }
    },
    "assets": []
  }
}
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.

Vec<>

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

Sample position-open tx:

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 for batch query use cases.

Vec<>

Sample position-close tx:

๐Ÿ–ฅ๏ธ
Deployed Contracts
Wormhole
https://terrasco.pe/mainnet/tx/A87F26A7A6137C87E968B02AC20CCB2F1FE2313D42349FAD3F330D3A50CA1AC8
Terra Hive
https://terrasco.pe/mainnet/tx/5F437BD5AC9DD6B038D8C1A5B2AEAF4928BE817F5BFE4A82530E5B914354E763
terraswap::asset::Asset
terraswap::asset::Asset