Skip to content

Commit

Permalink
fix(lyra-newport): Linting (Zapper-fi#2321)
Browse files Browse the repository at this point in the history
  • Loading branch information
wpoulin authored and 0xdapper committed Feb 28, 2023
1 parent 1bd7c95 commit c6c0528
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
} from '~position/template/contract-position.template.types';

import { LyraNewportContractFactory, LyraOptionToken } from '../contracts';
import { BigNumber } from 'ethers';

const OPTION_TYPES = {
0: 'Long Call',
Expand Down Expand Up @@ -145,8 +144,8 @@ export class ArbitrumLyraNewportOptionsContractPositionFetcher extends ContractP
baseAddress: market.baseAddress,
quoteAddress: market.quoteAddress,
tokenAddress: market.optionToken.id,
callPrice: Number(strike.callOption.latestOptionPriceAndGreeks.optionPrice)/1e18,
putPrice: Number(strike.putOption.latestOptionPriceAndGreeks.optionPrice)/1e18,
callPrice: Number(strike.callOption.latestOptionPriceAndGreeks.optionPrice) / 1e18,
putPrice: Number(strike.putOption.latestOptionPriceAndGreeks.optionPrice) / 1e18,
strikePriceReadable: strike.strikePriceReadable,
}));
});
Expand Down Expand Up @@ -204,7 +203,11 @@ export class ArbitrumLyraNewportOptionsContractPositionFetcher extends ContractP

async getDataProps({
definition,
}: GetDataPropsParams<LyraOptionToken, LyraNewportOptionContractPositionDataProps, LyraNewportOptionTokenDefinition>) {
}: GetDataPropsParams<
LyraOptionToken,
LyraNewportOptionContractPositionDataProps,
LyraNewportOptionTokenDefinition
>) {
return { ...omit(definition, 'address'), positionKey: `${definition.optionType}:${definition.strikeId}` };
}

Expand Down Expand Up @@ -238,14 +241,19 @@ export class ArbitrumLyraNewportOptionsContractPositionFetcher extends ContractP
if (!userPosition) return [];

// Find amount of position
const quoteToken = contractPosition.tokens[0];
const price = OPTION_TYPES[optionType].includes('Call') ? callPrice : putPrice;
const amountRaw = ((Number(price) * Number(userPosition.amount)/ (10 ** (18 - contractPosition.tokens[0].decimals))) ).toString();
const amountRaw = (
(Number(price) * Number(userPosition.amount)) /
10 ** (18 - contractPosition.tokens[0].decimals)
).toString();

if (optionType === 0 || optionType === 1) return [amountRaw];

const decimals = optionType == 2 ? 10 ** (18 - contractPosition.tokens[1].decimals) : 10 ** (18 - contractPosition.tokens[0].decimals)
const positionCollateral = userPosition.collateral.div(decimals)
const decimals =
optionType == 2
? 10 ** (18 - contractPosition.tokens[1].decimals)
: 10 ** (18 - contractPosition.tokens[0].decimals);
const positionCollateral = userPosition.collateral.div(decimals);
return [amountRaw, positionCollateral];
}
}
16 changes: 2 additions & 14 deletions src/apps/lyra-newport/arbitrum/lyra-newport.pool.token-fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Inject } from '@nestjs/common';
import Axios from 'axios';
import { gql } from 'graphql-request';

import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface';
Expand All @@ -15,17 +14,6 @@ import {

import { LyraNewportContractFactory, LyraLiquidityToken } from '../contracts';

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 @@ -67,7 +55,7 @@ export class ArbitrumLyraNewportPoolTokenFetcher extends AppTokenTemplatePositio

async getAddresses({ multicall }: GetAddressesParams<DefaultAppTokenDefinition>) {
const registryContract = this.contractFactory.lyraRegistry({
address: "0x6c87e4364Fd44B0D425ADfD0328e56b89b201329",
address: '0x6c87e4364fd44b0d425adfd0328e56b89b201329',
network: this.network,
});

Expand All @@ -88,14 +76,14 @@ export class ArbitrumLyraNewportPoolTokenFetcher extends AppTokenTemplatePositio
}

async getPricePerShare({
appToken,
contract,
multicall,
}: GetPricePerShareParams<LyraLiquidityToken, DefaultAppTokenDataProps, DefaultAppTokenDefinition>) {
const pool = await contract.liquidityPool();
const poolContract = this.contractFactory.lyraLiquidityPool({ address: pool, network: this.network });
const ratioRaw = await multicall.wrap(poolContract).getTokenPrice();
const ratio = Number(ratioRaw) / 10 ** 18;

return [ratio];
}
}
5 changes: 2 additions & 3 deletions src/apps/lyra-newport/lyra-newport.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { Module } from '@nestjs/common';

import { AbstractApp } from '~app/app.dynamic-module';

import { LyraNewportContractFactory } from './contracts';
import { ArbitrumLyraNewportOptionsContractPositionFetcher } from './arbitrum/lyra-newport.options.contract-position-fetcher';
import { ArbitrumLyraNewportPoolTokenFetcher } from './arbitrum/lyra-newport.pool.token-fetcher';
import { LyraNewportContractFactory } from './contracts';

@Module({
providers: [
Expand All @@ -13,5 +13,4 @@ import { ArbitrumLyraNewportPoolTokenFetcher } from './arbitrum/lyra-newport.poo
ArbitrumLyraNewportPoolTokenFetcher,
],
})
export class LyraNewportAppModule extends AbstractApp() { }

export class LyraNewportAppModule extends AbstractApp() {}

0 comments on commit c6c0528

Please sign in to comment.