Avalanche Pseudo-Delta-Neutral Leveraged Farming
Query Position IDs For Wallet Address
const managerABI =
["function getPositionsExt(address) view returns (tuple(uint128,uint16,uint64)[])"];
const apertureManager = new ethers.Contract(addr, managerABI, provider);
// `getPositionsExt` returns a list of tuple of:
// uint128 positionId -> This is the position id.
// uint16 chainId -> Used for cross chain communication. Likely not relevant for partner integration.
// uint64 strategyId -> The strategy id (a.k.a. vault id) to identify which
// strategy a position belongs to.
const positions = await apertureManager.getPositionsExt(ownerAddr);from web3 import Web3
w3 = Web3(Web3.HTTPProvider('https://api.avax.network/ext/bc/C/rpc'))
manager_abi = '[{ "inputs": [ { "internalType": "address", "name": "user", "type": "address" } ], "name": "getPositionsExt", "outputs": [ { "components": [ { "internalType": "uint128", "name": "positionId", "type": "uint128" }, { "internalType": "uint16", "name": "chainId", "type": "uint16" }, { "internalType": "uint64", "name": "strategyId", "type": "uint64" } ], "internalType": "struct PositionInfoExt[]", "name": "", "type": "tuple[]" } ], "stateMutability": "view", "type": "function" }]'
# Look up manager address from Deployed Contract section of this doc.
contract = w3.eth.contract('0xeD380115259FcC9088c187Be1279678e23a6E565', abi=manager_abi)
owner = '0x6c3723d56bF091675FC7c327ee263a4D836E8055'
# `getPositionsExt` returns a list of tuple of:
# uint128 positionId -> This is the position id.
# uint16 chainId -> Used for cross chain communication. Likely not relevant for partner integration.
# uint64 strategyId -> The strategy id (a.k.a. vault id) to identify which
# strategy a position belongs to.
print(contract.functions.getPositionsExt(owner).call())const vaultABI = [
"function vaultState() view returns (uint256, uint256)",
"function getEquityETHValue() view returns (uint256)",
"function pendingRewardStable() view returns (uint256)",
"function positions(uint16,uint128) view returns (uint256)"
"function pairInfo() view returns (address, address, address, address)"];
const AVAXChainId = 6; // Aperture uses Wormhole chain id.
// `getETHPx` returns the price of a token in the native token. For Ethereum, it would be
// ether. For Avalanche, it would be AVAX token. The final price is scaled to 2^112.
const oracleABI = ["function getETHPx(address) view returns (uint256)"];
const vault = new ethers.Contract(addr, vaultABI, provider);
const oracle = new ethers.Contract(addr, oracleABI, provider);
// 2^112, a very large number used by oracle.
const multiplier = BigNumber.from(2).pow(112);
// Get total shares from the vault.
const vaultShare = (await vault.vaultState())[0]; // The first item is total vault shares.
// Get how many shares a position owns.
const positionShare = await vault.position(AVAXChainId, positionId);
// This is the token address user deposits into the vault.
const mainTokenAddr = (await vault.pairInfo())[0]; // First item is the main token address.
// Retrieve vault equity expressed in AVAX token. Note that this is different from TVL of
// the vault. TVL includes leverage, however, equity is (total_position_worth - liability).
// For example, equity of $1 is equivalent to $1 * leverage in terms of TVL of the vault.
const equityETH = await vault.getEquityETHValue();
// Convert equity to be dominated in the main vault token.
const mainTokenETHPrice = await oracle.getETHPx(mainTokenAddr);
const pendingRewards = await vault.pendingRewardStable();
// Vault's equity expressed in main token.
const equityMainTotal = equityETH.mul(multiplier).div(mainTokenETHPrice).add(pendingRewards);
const equityMain = equityMainTotal.mul(positionShare).div(vaultShare);
// Compute the final position value expressed in the main vault token.
const result = ethers.utils.formatUnits(equityMain, mainTokenDecimal);Last updated