Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

feat: add lyra avalon #526

Merged
merged 6 commits into from
May 27, 2022
Merged

feat: add lyra avalon #526

merged 6 commits into from
May 27, 2022

Conversation

tonzgao
Copy link
Contributor

@tonzgao tonzgao commented May 27, 2022

Description

Add new lyra avalon options markets
Note: not affiliated with the project. I did submit a grant request with them for this though

tonz — Yesterday at 7:54 PM
hey, im thinking of implementing lyra avalon for zapper studio, but i have some questions.
1. is avalon stable enough for implementation? or will the contracts change a lot?
2. why are there multiple lyra markets? I assume this is for supporting different tokens? But I don't see any field specifying token address in the OptionMarket contract?
3. how do i calculate the price of an option? I assume using the OptionMarketPricer somehow? Or should I set some nominal price and then use priceAtExpiry from getSettlementParameters? or something else?
4. In option types, I see long and short quote positions, as well as "Short Call Base". What does that one mean? is this when its selling calls in eth terms? does i guess this indicates the unit of the collateral?
Thanks. you can dm me if its more convenient as well 
🌈ksett _/ l Lyra — Yesterday at 7:58 PM
Hey, definitely interested in a Zapper implimentation.
the contracts for Avalon should not change much but they are still in audit
CC @_/osh | Lyra
_/osh | Lyra — Yesterday at 9:25 PM
1. Contracts may change a tiny bit but not enough to significantly affect integrations so I'd suggest starting to build now.
2. use these deployment addresses to map addresses to different contracts https://raw.githubusercontent.com/lyra-finance/lyra-protocol/avalon/deployments/kovan-ovm/lyra.realPricing.json. Alternatively you can use our at_lyrafinance/protocol npm package: https://www.npmjs.com/package/@lyrafinance/protocol 
_/osh | Lyra — Yesterday at 9:33 PM
3. There are several ways to do this. 
- off-chain: just call optionMarket.staticCall.openPosition() - this will act as if the trade is performed but won't actually change state. It will return all the trade results which will include the final cost
- on-chain (but without fees and slippage): inherit the "VaultAdapter.sol" from the npm package and call _getPremiumForStrike(strikeId). That'll give you the pure blackScholes premium. 
- on-chain (with fees and slippage): call optionMarket.openPosition() but do this within a try/catch and just use the returned value to get price. The downside with this method is that you need balance in your msg.sender to prevent this from reverting. 

Lmk if any of these suggestions don't match your usecase since we're open to adding new ways to make integrations easier
_/osh | Lyra — Yesterday at 9:33 PM
4. yup that's exactly correct. SHORT_CALL_BASE is an ETH collateralized short call. The premium is still paid in sUSD but collateral is stored in base.
I also added you to our js SDK and protocol SDK channel for any package related questions.
tonz — Yesterday at 10:24 PM
is VaultAdapter deployed anywhere? I cant find the address
_/Ethboi_/ — Yesterday at 10:48 PM
Hey tonz, if you put together a proposal for a grant for your work, the grantsDao could fund you for this.
https://grants.lyra.finance/ <= more info
Lyra on Notion
Lyra Grants
Welcome to the Lyra Grants homepage. This page will be used to track RFPs, funding, grant progress and planning.
Application form here: https://grants.lyra.finance/Application-Form-3b7a83477d034017878310296d73a161
Lyra on Notion
Application Form
A new tool for teams & individuals that blends everyday work apps into one.
tonz — Yesterday at 11:39 PM
What does that mean, it isnt deployed and you want me to? the reason I ask is when I try using 
optionMarket.staticCall.openPosition({
  strikeId: 11,
  positionId: 109,
  iterations: 1,
  optionType: 1,
  amount: BigNumber { _hex: '0x01', _isBigNumber: true },
  setCollateralTo: BigNumber { _hex: '0x00', _isBigNumber: true },
  minTotalCost: BigNumber { _hex: '0x00', _isBigNumber: true },
  maxTotalCost: BigNumber {
    _hex: '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
    _isBigNumber: true
  }
}


i get an error

[Nest] 3459  - 05/26/2022, 11:36:42 PM   ERROR [CacheOnIntervalService] Error: missing revert data in call exception [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (error={"reason":"processing response error","code":"SERVER_ERROR","body":"{\"jsonrpc\":\"2.0\",\"error\":{\"code\":-32000,\"message\":\"execution reverted\"},\"id\":50}\n","error":{"code":-32000},"requestBody":"{\"method\":\"eth_call\",\"params\":[{\"to\":\"0xf24ecf73fd8e7fc9d8f94cd9df4f03107704d309\",\"data\":\"0x0037f2bc000000000000000000000000000000000000000000000000000000000000000b000000000000000000000000000000000000000000000000000000000000006d00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\"},\"latest\"],\"id\":50,\"jsonrpc\":\"2.0\"}","requestMethod":"POST","url":"https://mainnet.optimism.io"}, data="0x", code=CALL_EXCEPTION, version=providers/5.6.2)


not sure if this is due to the position id (which im not sure how to select it), the board closing, or something else.
_/osh | Lyra — Yesterday at 11:51 PM
the VaultAdapter is a base contract which you would inherit when deploying your own contract that would trade against Lyra. To me it sounds like using the staticCall method might fit your needs better 
_/osh | Lyra — Yesterday at 11:51 PM
since you're just trying to quote the cost, set positionId -> 0. The call you're making right now is trying to "add" amount = 1 to a position=109 which might not exist or might not be owned by you 
Check this out for a guide on using optionMarket.openPosition directly: https://github.com/lyra-finance/lyra-avalon-interfaces/blob/master/examples/Trading.md
_/osh | Lyra — Yesterday at 11:54 PM
another option is using our subgraph https://thegraph.com/hosted-service/subgraph/lyra-finance/mainnet to query prices

Checklist

  • I have followed the Contributing Guidelines
  • (optional) As a contributor, my Ethereum address/ENS is: 0x4E190B3D31d96e0cD11a1520185a77b57A0182f2
  • (optional) As a contributor, my Twitter handle is:

How to test?

curl -X 'GET'
'http://localhost:5001/apps/lyra-avalon/balances?network=optimism&addresses%5B%5D=0x4E190B3D31d96e0cD11a1520185a77b57A0182f2'
-H 'accept: /'

https://thegraph.com/hosted-service/subgraph/lyra-finance/mainnet

registry contract: https://optimistic.etherscan.io/address/0x7c7abddbcb6c731237f7546d3e4c5165531fb0c1#readContract


export const LYRA_AVALON_DEFINITION = appDefinition({
id: 'lyra-avalon',
name: 'Lyra',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name: 'Lyra',
name: 'Lyra Avalon',

if (!market?.strikes) return [];

// Extract information from contract position
const [, optionType, , strikeId] = (contractPosition.displayProps.secondaryLabel as string).split(' ');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use dataProps in src/apps/lyra-avalon/optimism/lyra-avalon.options.contract-position-fetcher.ts to supplement the token with any additional information (like the strike, option type, etc). Type it as well as LyraAvalonOptionContractPositionDataProps.

Then you'll have access to the typed data proper if you do the following:

return this.appToolkit.helpers.contractPositionBalanceHelper.getContractPositionBalances<LyraAvalonOptionContractPositionDataProps>({
  // ...
  resolveBalances: async({ contractPosition }) => {
    const { strike, optionType }  = contractPosition.dataProps; // This will be typed to LyraAvalonOptionContractPositionDataProps
  }
});

@tonzgao tonzgao requested a review from immasandwich May 27, 2022 15:41
// Determine price of the contract position strike
const strike = market.strikes.find(strike => Number(strike.strikeId) === strikeId);
if (!strike) return [];
const price = (OPTION_TYPES[optionType].includes('Call') ? strike.callOption : strike.putOption)
Copy link
Contributor

@immasandwich immasandwich May 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can put the option price on the data props as well. Try to put as much relevant information in the data props as possible.

Copy link
Contributor Author

@tonzgao tonzgao May 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you want this in a separate pr? i see this one is merged already

edit: I took a look, the main issue seems to be that the market addresses are not set, so we either have to make a query anyways to get the market addresses first, or we have to call the markets to get the user positions as we find them in the contract positions, which could be a little messy. I'm fine with either method, but im not sure if its worth the effort.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants