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

Commit

Permalink
fix(lyra-avalon): Get Lyra Avalon registry contract from addresses in…
Browse files Browse the repository at this point in the history
… GitHub (#764)
  • Loading branch information
immasandwich authored Jun 27, 2022
1 parent baaca0d commit dcb5dad
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
Binary file added src/apps/cronus-finance/assets/test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions src/apps/lyra-avalon/optimism/helpers/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,3 @@ export const OPTION_TYPES = {
3: 'Short Call Quote',
4: 'Short Put Quote',
};

// From https://github.com/lyra-finance/subgraph/blob/master/addresses/mainnet-ovm/lyra.json
export const REGISTRY_ADDRESS = '0x6555c4bebc5a7b2b2dac66bb621ce86e7e92e53f';
29 changes: 27 additions & 2 deletions src/apps/lyra-avalon/optimism/lyra-avalon.pool.token-fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
import { Inject } from '@nestjs/common';
import Axios from 'axios';
import { gql } from 'graphql-request';

import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface';
import { Register } from '~app-toolkit/decorators';
import { CacheOnInterval } from '~cache/cache-on-interval.decorator';
import { PositionFetcher } from '~position/position-fetcher.interface';
import { AppTokenPosition } from '~position/position.interface';
import { Network } from '~types/network.interface';

import { LyraAvalonContractFactory, LiquidityToken } from '../contracts';
import { LYRA_AVALON_DEFINITION } from '../lyra-avalon.definition';

import { REGISTRY_ADDRESS } from './helpers/consts';
import { runQuery } from './helpers/graph';

const appId = LYRA_AVALON_DEFINITION.id;
const groupId = LYRA_AVALON_DEFINITION.groups.pool.id;
const network = Network.OPTIMISM_MAINNET;

type LyraMainnetAddresses = Record<
string,
{
contractName: string;
source: string;
address: string;
txn: string;
blockNumber: number;
}
>;

// TODO: find better way to determine available markets
type QueryResponse = {
markets: {
Expand Down Expand Up @@ -48,9 +60,22 @@ export class OptimismLyraAvalonPoolTokenFetcher implements PositionFetcher<AppTo
@Inject(LyraAvalonContractFactory) private readonly contractFactory: LyraAvalonContractFactory,
) {}

@CacheOnInterval({
key: `studio:${appId}:${groupId}:${network}:addresses`,
timeout: 15 * 60 * 1000,
})
private async getCachedAddressConfig() {
const { data } = await Axios.get<LyraMainnetAddresses>(
'https://raw.githubusercontent.com/lyra-finance/subgraph/master/addresses/mainnet-ovm/lyra.json',
);

return data;
}

async getPositions() {
const addresses = await this.getCachedAddressConfig();
const multicall = this.appToolkit.getMulticall(network);
const registryContract = this.contractFactory.lyraRegistry({ address: REGISTRY_ADDRESS, network });
const registryContract = this.contractFactory.lyraRegistry({ address: addresses.LyraRegistry.address, network });

const baseTokens = await this.appToolkit.getBaseTokenPrices(network);
const quoteToken = baseTokens.find(token => token.symbol === 'sUSD')!;
Expand Down

0 comments on commit dcb5dad

Please sign in to comment.