Skip to content

Commit

Permalink
Merge branch 'alpha/arbitrum' into v3/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffywu committed Apr 15, 2024
2 parents b9ca116 + adfb8bd commit 2f940de
Show file tree
Hide file tree
Showing 15 changed files with 158 additions and 23 deletions.
4 changes: 2 additions & 2 deletions apps/accounts/src/registry-client-do.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import { BaseDO, MetricType } from '@notional-finance/durable-objects';
import {
calculateAccountIRR,
currentContestId,
// currentContestId,
excludedAccounts,
} from './factors/calculations';
import { Env } from '.';
Expand Down Expand Up @@ -80,7 +80,7 @@ export class RegistryClientDO extends BaseDO<Env> {
await this.saveYieldData(network);
if (network === Network.arbitrum) {
await this.checkDBMonitors(network);
await this.saveContestIRR(network, currentContestId);
// await this.saveContestIRR(network, currentContestId);
}
await this.saveAccountRiskProfiles(network);
}
Expand Down
4 changes: 2 additions & 2 deletions apps/rewards/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
getProviderFromNetwork,
} from '@notional-finance/util';
import { BigNumber, PopulatedTransaction, ethers } from 'ethers';
import { vaults, minTokenAmount, ARB_ETH, ARB_WETH, Vault } from './vaults';
import { vaults, minTokenAmount, ETH, wEthMapper, Vault } from './vaults';
import {
get0xData,
sendTxThroughRelayer,
Expand Down Expand Up @@ -231,7 +231,7 @@ const getTrades = async (
if (!amount.eq(0)) {
const tradeData = await get0xData({
sellToken,
buyToken: token == ARB_ETH ? ARB_WETH : token,
buyToken: token == ETH ? wEthMapper[env.NETWORK] : token,
sellAmount: amount,
slippagePercentage: SLIPPAGE_PERCENT * slippageMultiplier++,
env,
Expand Down
29 changes: 25 additions & 4 deletions apps/rewards/src/vaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Network } from '@notional-finance/util';

// all addresses must be properly checksummed
// mainnet
const WETH = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2';
const rETH = '0xae78736Cd615f374D3085123A210448E74Fc6393';
const PYUSD = '0x6c3ea9036406852006290770BEdFcAbA0e23A0e8';
const USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
const USDT = '0xdAC17F958D2ee523a2206206994597C13D831ec7';
Expand All @@ -11,7 +13,10 @@ const CRV = '0xd533a949740bb3306d119cc777fa900ba034cd52';
const CVX = '0x4e3fbd56cd56c3e72c1403e103b45db9da5b9d2b';
const BAL = '0xba100000625a3754423978a60c9317c58a424e3D';
const AURA = '0xc0c293ce456ff0ed870add98a0828dd4d2903dbf';
const ezETH = '0xbf5495Efe5DB9ce00f80364C8B423567e58d2110';
const weETH = '0xCd5fE23C85820F7B72D0926FC9b05b43E359b7ee';
// arbitrum
const ARB_WETH = '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1';
const ARB_BAL = '0x040d1EdC9569d4Bab2D15287Dc5A4F10F56a56B8';
const ARB_AURA = '0x1509706a6c66CA549ff0cB464de88231DDBe213B';
const ARB_CRV = '0x11cDb42B0EB46D95f990BeDD4695A6e3fA034978';
Expand All @@ -25,8 +30,12 @@ const ARB_USDT = '0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9';
const ARB_wstETH = '0x5979D7b546E38E414F7E9822514be443A4800529';
const ARB_cbETH = '0x1DEBd73E752bEaF79865Fd6446b0c970EaE7732f';

export const ARB_ETH = '0x0000000000000000000000000000000000000000';
export const ARB_WETH = '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1';
export const ETH = '0x0000000000000000000000000000000000000000';

export const wEthMapper: Partial<Record<Network, string>> = {
mainnet: WETH,
arbitrum: ARB_WETH
}

// set minimum values for tokens that are going to be claim/sell (~$15 for arbitrum, ~$150 for mainnet)
// if token is also pool token it won't be sold
Expand Down Expand Up @@ -77,6 +86,18 @@ export const vaults: Partial<Record<Network, Array<Vault>>> = {
poolTokens: [GHO, '0x8353157092ED8Be69a9DF8F95af097bbF33Cb2aF', USDC, USDT],
tokenWeights: [33, 0, 33, 33],
},
{
address: '0x914255c0c289aea36e378ebb5e28293b5ed278ca',
rewardTokens: [BAL, AURA],
poolTokens: ['0x596192bB6e41802428Ac943D2f1476C1Af25CC0E', ezETH, ETH],
tokenWeights: [0, 50, 50],
},
{
address: '0x32d82a1c8618c7be7fe85b2f1c44357a871d52d1',
rewardTokens: [BAL, AURA],
poolTokens: ['0x05ff47AFADa98a98982113758878F9A8B9FddA0a,', rETH, weETH],
tokenWeights: [0, 50, 50],
},
],
arbitrum: [
{
Expand All @@ -94,7 +115,7 @@ export const vaults: Partial<Record<Network, Array<Vault>>> = {
{
address: '0x3Df035433cFACE65b6D68b77CC916085d020C8B8',
rewardTokens: [ARB, ARB_BAL, ARB_AURA],
poolTokens: [ARB_ETH, '0xadE4A71BB62bEc25154CFc7e6ff49A513B491E81', ARB_RETH],
poolTokens: [ETH, '0xadE4A71BB62bEc25154CFc7e6ff49A513B491E81', ARB_RETH],
tokenWeights: [50, 0, 50],
},
{
Expand All @@ -106,7 +127,7 @@ export const vaults: Partial<Record<Network, Array<Vault>>> = {
{
address: '0x0e8c1a069f40d0e8fa861239d3e62003cbf3dcb2',
rewardTokens: [ARB, ARB_BAL, ARB_AURA],
poolTokens: [ARB_wstETH, ARB_ETH, '0x9791d590788598535278552EEcD4b211bFc790CB'],
poolTokens: [ARB_wstETH, ETH, '0x9791d590788598535278552EEcD4b211bFc790CB'],
tokenWeights: [50, 50, 0],
},
{
Expand Down
7 changes: 6 additions & 1 deletion gcp/data-service/src/DataService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ import {
ProtocolName,
} from './types';
import { aggregate } from '@notional-finance/multicall';
import { ApolloClient, HttpLink, InMemoryCache, gql } from '@apollo/client';
import {
ApolloClient,
HttpLink,
InMemoryCache,
gql,
} from '@apollo/client/core';
import { graphQueries } from './graphQueries';

// TODO: fetch from DB
Expand Down
2 changes: 1 addition & 1 deletion gcp/data-service/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
GenericDataConfig,
} from './types';
import { GenericDataWriter, TokenBalanceDataWriter } from './DataWriter';
import { gql } from '@apollo/client';
import { gql } from '@apollo/client/core';
import { configDefs as GenericConfig } from './config/GenericConfig';
import { Balancer_Config } from './config/balancer';
import { Curve_Config } from './config/convex';
Expand Down
23 changes: 23 additions & 0 deletions gcp/data-service/src/config/balancer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,27 @@ export const Balancer_Config = [
),
]
),
getComposablePoolConfig(
'0xb61371ab661b1acec81c699854d2f911070c059e000000000000000000000516',
'0xb61371ab661b1acec81c699854d2f911070c059e',
'0x7c4a6b0c16ca99e65822cc531403ce2f8a20a912',
'0xcd41bc6dc6e9821c4c36848ff3397493e458a5d1',
Network.arbitrum,
Strategy.Arb_Balancer_ezETH_wstETH,
[ArbTokenConfig['ezETH'], ArbTokenConfig['wstETH']],
[
getOracleValue(
Network.arbitrum,
Strategy.Arb_Balancer_ezETH_wstETH,
'ezETH to ETH Price',
'0x11E1836bFF2ce9d6A5bec9cA79dc998210f3886d'
),
getOracleValue(
Network.arbitrum,
Strategy.Arb_Balancer_ezETH_wstETH,
'wstETH to ETH Price',
'0x8910333436c7FD1fEa39e8Aef3264471755772F8'
),
]
),
].flatMap((_) => _);
5 changes: 5 additions & 0 deletions gcp/data-service/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ export const ArbTokenConfig = {
symbol: 'crvUSD',
decimals: 18,
},
ezETH: {
address: '0x2416092f143378750bb29b79eD961ab195CcEea5',
symbol: 'ezETH',
decimals: 18,
},
} as const;

export const EthTokenConfig = {
Expand Down
1 change: 1 addition & 0 deletions gcp/data-service/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export enum Strategy {
Arb_Convex_crvUSD_USDC = 24,
Arb_Convex_crvUSD_USDT = 25,
Eth_Balancer_ezETH_WETH = 26,
Arb_Balancer_ezETH_wstETH = 27,
}

export interface MulticallConfig {
Expand Down
5 changes: 4 additions & 1 deletion packages/core-entities/src/.graphclient/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9020,7 +9020,7 @@ export type AllAccountsQuery = { accounts: Array<(
)>> }
) }>>, profitLossLineItems?: Maybe<Array<(
Pick<ProfitLossLineItem, 'timestamp' | 'blockNumber' | 'tokenAmount' | 'underlyingAmountRealized' | 'underlyingAmountSpot' | 'realizedPrice' | 'spotPrice' | 'impliedFixedRate' | 'isTransientLineItem'>
& { transactionHash: Pick<Transaction, 'id'>, token: Pick<Token, 'id' | 'tokenType'>, underlyingToken: Pick<Token, 'id'>, bundle: Pick<TransferBundle, 'bundleName'> }
& { account: Pick<Account, 'id'>, transactionHash: Pick<Transaction, 'id'>, token: Pick<Token, 'id' | 'tokenType'>, underlyingToken: Pick<Token, 'id'>, bundle: Pick<TransferBundle, 'bundleName'> }
)>> }
)> };

Expand Down Expand Up @@ -9332,6 +9332,9 @@ export const AllAccountsDocument = gql`
orderBy: blockNumber
orderDirection: desc
) {
account {
id
}
timestamp
blockNumber
transactionHash {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,15 @@ export class AnalyticsRegistryClient extends ClientRegistry<unknown> {
return this._fetch(network, 'analytics');
}

async getPointPrices() {
return this.getView<{ points: string; price: string }>(
Network.all,
'points_prices'
).then((m) =>
m.map(({ points, price }) => ({ points, price: parseFloat(price) || 0 }))
);
}

async getView<T>(network: Network, viewName: string) {
return this._fetch<T[]>(network, viewName);
}
Expand Down
8 changes: 8 additions & 0 deletions packages/core-entities/src/client/yield-registry-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,14 @@ export class YieldRegistryClient extends ClientRegistry<YieldData> {
vaultAPYs.length > 0
? vaultAPYs.reduce((t, a) => t + a, 0) / vaultAPYs.length
: 0;
try {
// If the vault debt is not found then skip generating the yield for
// this vault
if (v.vaultAddress && v.maturity)
tokens.getVaultDebt(network, v.vaultAddress, v.maturity);
} catch (e) {
return [];
}

const vaultShareYield: YieldData = {
token: v,
Expand Down
1 change: 1 addition & 0 deletions packages/core-entities/src/queries/AllAccounts.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ query AllAccounts($skip: Int) {
]}}
first: 1000, orderBy: blockNumber, orderDirection: desc
) {
account { id }
timestamp
blockNumber
transactionHash { id }
Expand Down
2 changes: 1 addition & 1 deletion packages/features/vault/src/vault-view/vault-summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const VaultSummary = () => {
decimals: 2,
},
{
title: 'Unused Debt Capacity',
title: 'Remaining Borrow Capacity',
value: totalCapacityRemaining?.toFloat(),
suffix: ` ${totalCapacityRemaining?.symbol || ''}`,
decimals: 0,
Expand Down
19 changes: 17 additions & 2 deletions packages/shared/notionable-hooks/src/use-market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
SupportedNetworks,
unique,
} from '@notional-finance/util';
import { useCallback, useMemo } from 'react';
import { useNotionalContext } from './use-notional';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { useAnalyticsReady, useNotionalContext } from './use-notional';
import { exchangeToLocalPrime } from '@notional-finance/transaction';

export interface MaturityData {
Expand Down Expand Up @@ -346,3 +346,18 @@ export function useTradedValue(amount: TokenBalance | undefined) {
return undefined;
}
}

export function usePointPrices() {
const analyticsReady = useAnalyticsReady(Network.all);
const [pointPrices, setPointPrices] = useState<
{ points: string; price: number }[] | undefined
>();

useEffect(() => {
if (analyticsReady && pointPrices === undefined) {
Registry.getAnalyticsRegistry().getPointPrices().then(setPointPrices);
}
}, [analyticsReady, pointPrices]);

return pointPrices;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ import {
TradeSummaryContainer,
TradeActionTitle,
H4,
InfoTooltip,
Caption,
} from '@notional-finance/mui';
import { BaseTradeState, isLeveragedTrade } from '@notional-finance/notionable';
import { TransactionHeadings } from '../transaction-sidebar/components/transaction-headings';
import { FormattedMessage, defineMessage } from 'react-intl';
import { useAllMarkets } from '@notional-finance/notionable-hooks';
import {
useAllMarkets,
usePointPrices,
} from '@notional-finance/notionable-hooks';
import {
LeverageInfoRow,
LiquidityYieldInfo,
Expand Down Expand Up @@ -58,6 +63,7 @@ export function TradeActionSummary({
const isLeveraged =
isLeveragedTrade(tradeType) || priorVaultFactors !== undefined;
const collateral = state.collateral || priorVaultFactors?.vaultShare;
const pointPrices = usePointPrices();

const apySuffix = isLeveraged ? (
<FormattedMessage defaultMessage={'Total APY'} />
Expand Down Expand Up @@ -145,14 +151,52 @@ export function TradeActionSummary({
}
/>
{points && (
<H4 sx={{ marginTop: theme.spacing(1) }} accent>{`${Object.keys(
points
)
.map(
(k) =>
`${pointsMultiple(points[k], leverageRatio).toFixed(2)}x ${k}`
)
.join(' & ')} Points`}</H4>
<Box
sx={{
marginTop: theme.spacing(1),
display: 'flex',
alignItems: 'center',
}}
>
{Object.keys(points).map((k) => (
<Box marginRight={theme.spacing(1)} display="flex">
<H4>
{`${pointsMultiple(points[k], leverageRatio).toFixed(
2
)}x ${k} Points:`}
&nbsp;
</H4>
{pointPrices && (
<H4 light>{`$${
pointPrices
.find((p) => p.points.includes(k))
?.price.toFixed(4) || '-'
}/point`}</H4>
)}
</Box>
))}
<InfoTooltip
iconSize={theme.spacing(2)}
iconColor={theme.palette.info.dark}
toolTipText={defineMessage({
defaultMessage:
'Point prices are pulled from: <a>app.whales.market/points-markets</a>',
values: {
a: (a: string) => (
<Caption
accent
href="https://app.whales.market/points-markets"
>
{a}
</Caption>
),
},
})}
sx={{
marginLeft: theme.spacing(0.5),
}}
/>
</Box>
)}
{liquidityYieldData && (
<LiquidityYieldInfo liquidityYieldData={liquidityYieldData} />
Expand Down

0 comments on commit 2f940de

Please sign in to comment.