Skip to content

Commit 75fd88e

Browse files
committed
feat: expose user earned/debt APY in MarketUserState
1 parent 642adc6 commit 75fd88e

File tree

6 files changed

+114
-97
lines changed

6 files changed

+114
-97
lines changed

.changeset/short-steaks-allow.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@aave/graphql": minor
3+
"@aave/client": minor
4+
---
5+
6+
feat: expose user earned/debt APY in MarketUserState

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ examples/*/pnpm-lock.yaml
2727

2828
# local env files
2929
.env
30+
.env.local
3031

3132
# typescript
3233
*.tsbuildinfo

packages/client/src/actions/markets.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { UnexpectedError } from '@aave/core';
1+
import type { UnexpectedError } from "@aave/core";
22
import {
33
type Market,
44
MarketQuery,
@@ -8,14 +8,13 @@ import {
88
OrderDirection,
99
UserMarketStateQuery,
1010
type UserMarketStateRequest,
11-
} from '@aave/graphql';
12-
import type { ChainId, EvmAddress, ResultAsync } from '@aave/types';
13-
import type { AaveClient } from '../AaveClient';
11+
} from "@aave/graphql";
12+
import type { ChainId, EvmAddress, ResultAsync } from "@aave/types";
13+
import type { AaveClient } from "../AaveClient";
1414

15-
export const defaultMarketReservesRequestOrderBy: MarketReservesRequestOrderBy =
16-
{
17-
tokenName: OrderDirection.Asc,
18-
};
15+
export const defaultMarketReservesRequestOrderBy: MarketReservesRequestOrderBy = {
16+
tokenName: OrderDirection.Asc,
17+
};
1918

2019
export type MarketsRequest = {
2120
/**
@@ -62,7 +61,7 @@ export function markets(
6261
borrowsOrderBy = defaultMarketReservesRequestOrderBy,
6362
suppliesOrderBy = defaultMarketReservesRequestOrderBy,
6463
user,
65-
}: MarketsRequest,
64+
}: MarketsRequest
6665
): ResultAsync<Market[], UnexpectedError> {
6766
return client.query(MarketsQuery, {
6867
request: { chainIds, user },
@@ -123,7 +122,7 @@ export function market(
123122
user,
124123
borrowsOrderBy = defaultMarketReservesRequestOrderBy,
125124
suppliesOrderBy = defaultMarketReservesRequestOrderBy,
126-
}: MarketRequest,
125+
}: MarketRequest
127126
): ResultAsync<Market | null, UnexpectedError> {
128127
return client.query(MarketQuery, {
129128
request: { address, chainId, user },
@@ -149,7 +148,7 @@ export function market(
149148
*/
150149
export function userMarketState(
151150
client: AaveClient,
152-
request: UserMarketStateRequest,
151+
request: UserMarketStateRequest
153152
): ResultAsync<MarketUserState, UnexpectedError> {
154153
return client.query(UserMarketStateQuery, { request });
155154
}

packages/graphql/schema.graphql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,12 @@ type MarketUserState {
566566
"""The user's net annual percentage yield across all positions"""
567567
netAPY: PercentValue!
568568

569+
"""The user's earned annual percentage yield across all supply positions"""
570+
userEarnedAPY: PercentValue!
571+
572+
"""The user's debt annual percentage yield across all borrow positions"""
573+
userDebtAPY: PercentValue!
574+
569575
"""
570576
The user's health factor (risk metric for liquidation) - if null, the user does not have a borrow
571577
"""
@@ -679,7 +685,7 @@ enum OperationType {
679685
VAULT_FEE_UPDATED
680686
VAULT_FEE_WITHDRAWN
681687
VAULT_WITHDRAW
682-
VAULT_TRANSFER
688+
VAULT_OWNERSHIP_TRANSFERRED
683689
REVENUE_SPLITTER_OWNER_DEPLOYED
684690
REVENUE_SPLITTER_OWNER_TRANSFER
685691
LIQUIDATION
Lines changed: 88 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,108 @@
1-
import type { FragmentOf } from 'gql.tada';
2-
import { graphql } from '../graphql';
3-
import { ChainFragment } from './chain';
4-
import { CurrencyFragment, PercentValueFragment } from './common';
5-
import { ReserveFragment } from './reserve';
1+
import type { FragmentOf } from "gql.tada";
2+
import { graphql } from "../graphql";
3+
import { ChainFragment } from "./chain";
4+
import { CurrencyFragment, PercentValueFragment } from "./common";
5+
import { ReserveFragment } from "./reserve";
66

77
export const MarketUserStateFragment = graphql(
8-
`fragment MarketUserState on MarketUserState {
9-
__typename
10-
netWorth
11-
netAPY {
12-
...PercentValue
8+
`
9+
fragment MarketUserState on MarketUserState {
10+
__typename
11+
netWorth
12+
netAPY {
13+
...PercentValue
14+
}
15+
userEarnedAPY {
16+
...PercentValue
17+
}
18+
userDebtAPY {
19+
...PercentValue
20+
}
21+
healthFactor
22+
eModeEnabled
23+
totalCollateralBase
24+
totalDebtBase
25+
availableBorrowsBase
26+
currentLiquidationThreshold {
27+
...PercentValue
28+
}
29+
ltv {
30+
...PercentValue
31+
}
32+
isInIsolationMode
1333
}
14-
healthFactor
15-
eModeEnabled
16-
totalCollateralBase
17-
totalDebtBase
18-
availableBorrowsBase
19-
currentLiquidationThreshold {
20-
...PercentValue
21-
}
22-
ltv {
23-
...PercentValue
24-
}
25-
isInIsolationMode
26-
}`,
27-
[PercentValueFragment],
34+
`,
35+
[PercentValueFragment]
2836
);
2937
export type MarketUserState = FragmentOf<typeof MarketUserStateFragment>;
3038

3139
export const EmodeMarketReserveInfoFragment = graphql(
32-
`fragment EmodeMarketReserveInfo on EmodeMarketReserveInfo {
33-
__typename
34-
underlyingToken {
35-
...Currency
40+
`
41+
fragment EmodeMarketReserveInfo on EmodeMarketReserveInfo {
42+
__typename
43+
underlyingToken {
44+
...Currency
45+
}
46+
canBeCollateral
47+
canBeBorrowed
3648
}
37-
canBeCollateral
38-
canBeBorrowed
39-
}`,
40-
[CurrencyFragment],
49+
`,
50+
[CurrencyFragment]
4151
);
42-
export type EmodeMarketReserveInfo = FragmentOf<
43-
typeof EmodeMarketReserveInfoFragment
44-
>;
52+
export type EmodeMarketReserveInfo = FragmentOf<typeof EmodeMarketReserveInfoFragment>;
4553

4654
export const EmodeMarketCategoryFragment = graphql(
47-
`fragment EmodeMarketCategory on EmodeMarketCategory {
48-
__typename
49-
id
50-
label
51-
maxLTV {
52-
...PercentValue
53-
}
54-
liquidationThreshold {
55-
...PercentValue
56-
}
57-
liquidationPenalty {
58-
...PercentValue
59-
}
60-
reserves {
61-
...EmodeMarketReserveInfo
55+
`
56+
fragment EmodeMarketCategory on EmodeMarketCategory {
57+
__typename
58+
id
59+
label
60+
maxLTV {
61+
...PercentValue
62+
}
63+
liquidationThreshold {
64+
...PercentValue
65+
}
66+
liquidationPenalty {
67+
...PercentValue
68+
}
69+
reserves {
70+
...EmodeMarketReserveInfo
71+
}
6272
}
63-
}`,
64-
[PercentValueFragment, EmodeMarketReserveInfoFragment],
73+
`,
74+
[PercentValueFragment, EmodeMarketReserveInfoFragment]
6575
);
66-
export type EmodeMarketCategory = FragmentOf<
67-
typeof EmodeMarketCategoryFragment
68-
>;
76+
export type EmodeMarketCategory = FragmentOf<typeof EmodeMarketCategoryFragment>;
6977

7078
export const MarketFragment = graphql(
71-
`fragment Market on Market {
72-
__typename
73-
name
74-
chain {
75-
...Chain
76-
}
77-
address
78-
icon
79-
totalMarketSize
80-
totalAvailableLiquidity
81-
eModeCategories {
82-
...EmodeMarketCategory
83-
}
84-
userState {
85-
...MarketUserState
86-
}
79+
`
80+
fragment Market on Market {
81+
__typename
82+
name
83+
chain {
84+
...Chain
85+
}
86+
address
87+
icon
88+
totalMarketSize
89+
totalAvailableLiquidity
90+
eModeCategories {
91+
...EmodeMarketCategory
92+
}
93+
userState {
94+
...MarketUserState
95+
}
8796
88-
borrowReserves: reserves(request: { reserveType: BORROW, orderBy: $borrowsOrderBy }) {
89-
...Reserve
90-
}
97+
borrowReserves: reserves(request: { reserveType: BORROW, orderBy: $borrowsOrderBy }) {
98+
...Reserve
99+
}
91100
92-
supplyReserves: reserves(request: { reserveType: SUPPLY, orderBy: $suppliesOrderBy }) {
93-
...Reserve
101+
supplyReserves: reserves(request: { reserveType: SUPPLY, orderBy: $suppliesOrderBy }) {
102+
...Reserve
103+
}
94104
}
95-
}`,
96-
[
97-
ChainFragment,
98-
EmodeMarketCategoryFragment,
99-
ReserveFragment,
100-
MarketUserStateFragment,
101-
],
105+
`,
106+
[ChainFragment, EmodeMarketCategoryFragment, ReserveFragment, MarketUserStateFragment]
102107
);
103108
export type Market = FragmentOf<typeof MarketFragment>;

packages/graphql/src/graphql-env.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ export type introspection_types = {
5656
'MarketReservesRequestType': { name: 'MarketReservesRequestType'; enumValues: 'SUPPLY' | 'BORROW' | 'BOTH'; };
5757
'MarketUserReserveBorrowPosition': { kind: 'OBJECT'; name: 'MarketUserReserveBorrowPosition'; fields: { 'apy': { name: 'apy'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'PercentValue'; ofType: null; }; } }; 'currency': { name: 'currency'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'Currency'; ofType: null; }; } }; 'debt': { name: 'debt'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'TokenAmount'; ofType: null; }; } }; 'market': { name: 'market'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'MarketInfo'; ofType: null; }; } }; }; };
5858
'MarketUserReserveSupplyPosition': { kind: 'OBJECT'; name: 'MarketUserReserveSupplyPosition'; fields: { 'apy': { name: 'apy'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'PercentValue'; ofType: null; }; } }; 'balance': { name: 'balance'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'TokenAmount'; ofType: null; }; } }; 'canBeCollateral': { name: 'canBeCollateral'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Boolean'; ofType: null; }; } }; 'currency': { name: 'currency'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'Currency'; ofType: null; }; } }; 'isCollateral': { name: 'isCollateral'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Boolean'; ofType: null; }; } }; 'market': { name: 'market'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'MarketInfo'; ofType: null; }; } }; }; };
59-
'MarketUserState': { kind: 'OBJECT'; name: 'MarketUserState'; fields: { 'availableBorrowsBase': { name: 'availableBorrowsBase'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'BigDecimal'; ofType: null; }; } }; 'currentLiquidationThreshold': { name: 'currentLiquidationThreshold'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'PercentValue'; ofType: null; }; } }; 'eModeEnabled': { name: 'eModeEnabled'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Boolean'; ofType: null; }; } }; 'healthFactor': { name: 'healthFactor'; type: { kind: 'SCALAR'; name: 'BigDecimal'; ofType: null; } }; 'isInIsolationMode': { name: 'isInIsolationMode'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Boolean'; ofType: null; }; } }; 'ltv': { name: 'ltv'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'PercentValue'; ofType: null; }; } }; 'netAPY': { name: 'netAPY'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'PercentValue'; ofType: null; }; } }; 'netWorth': { name: 'netWorth'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'BigDecimal'; ofType: null; }; } }; 'totalCollateralBase': { name: 'totalCollateralBase'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'BigDecimal'; ofType: null; }; } }; 'totalDebtBase': { name: 'totalDebtBase'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'BigDecimal'; ofType: null; }; } }; }; };
59+
'MarketUserState': { kind: 'OBJECT'; name: 'MarketUserState'; fields: { 'availableBorrowsBase': { name: 'availableBorrowsBase'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'BigDecimal'; ofType: null; }; } }; 'currentLiquidationThreshold': { name: 'currentLiquidationThreshold'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'PercentValue'; ofType: null; }; } }; 'eModeEnabled': { name: 'eModeEnabled'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Boolean'; ofType: null; }; } }; 'healthFactor': { name: 'healthFactor'; type: { kind: 'SCALAR'; name: 'BigDecimal'; ofType: null; } }; 'isInIsolationMode': { name: 'isInIsolationMode'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Boolean'; ofType: null; }; } }; 'ltv': { name: 'ltv'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'PercentValue'; ofType: null; }; } }; 'netAPY': { name: 'netAPY'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'PercentValue'; ofType: null; }; } }; 'netWorth': { name: 'netWorth'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'BigDecimal'; ofType: null; }; } }; 'totalCollateralBase': { name: 'totalCollateralBase'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'BigDecimal'; ofType: null; }; } }; 'totalDebtBase': { name: 'totalDebtBase'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'BigDecimal'; ofType: null; }; } }; 'userDebtAPY': { name: 'userDebtAPY'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'PercentValue'; ofType: null; }; } }; 'userEarnedAPY': { name: 'userEarnedAPY'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'PercentValue'; ofType: null; }; } }; }; };
6060
'MarketsRequest': { kind: 'INPUT_OBJECT'; name: 'MarketsRequest'; isOneOf: false; inputFields: [{ name: 'chainIds'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'LIST'; name: never; ofType: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'ChainId'; ofType: null; }; }; }; }; defaultValue: null }, { name: 'user'; type: { kind: 'SCALAR'; name: 'EvmAddress'; ofType: null; }; defaultValue: null }]; };
6161
'MeritBorrowAndSupplyIncentiveCondition': { kind: 'OBJECT'; name: 'MeritBorrowAndSupplyIncentiveCondition'; fields: { 'borrowToken': { name: 'borrowToken'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'Currency'; ofType: null; }; } }; 'claimLink': { name: 'claimLink'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'URL'; ofType: null; }; } }; 'extraApr': { name: 'extraApr'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'PercentValue'; ofType: null; }; } }; 'supplyToken': { name: 'supplyToken'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'Currency'; ofType: null; }; } }; }; };
6262
'MeritBorrowIncentive': { kind: 'OBJECT'; name: 'MeritBorrowIncentive'; fields: { 'borrowAprDiscount': { name: 'borrowAprDiscount'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'PercentValue'; ofType: null; }; } }; 'claimLink': { name: 'claimLink'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'URL'; ofType: null; }; } }; }; };
6363
'MeritSupplyIncentive': { kind: 'OBJECT'; name: 'MeritSupplyIncentive'; fields: { 'claimLink': { name: 'claimLink'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'URL'; ofType: null; }; } }; 'extraSupplyApr': { name: 'extraSupplyApr'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'PercentValue'; ofType: null; }; } }; }; };
6464
'MessageData': { kind: 'OBJECT'; name: 'MessageData'; fields: { 'deadline': { name: 'deadline'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Int'; ofType: null; }; } }; 'nonce': { name: 'nonce'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'BigInt'; ofType: null; }; } }; 'owner': { name: 'owner'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'EvmAddress'; ofType: null; }; } }; 'spender': { name: 'spender'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'EvmAddress'; ofType: null; }; } }; 'value': { name: 'value'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'BigInt'; ofType: null; }; } }; }; };
6565
'NativeCurrency': { kind: 'OBJECT'; name: 'NativeCurrency'; fields: { 'chainId': { name: 'chainId'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'ChainId'; ofType: null; }; } }; 'decimals': { name: 'decimals'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Int'; ofType: null; }; } }; 'imageUrl': { name: 'imageUrl'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'String'; ofType: null; }; } }; 'name': { name: 'name'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'String'; ofType: null; }; } }; 'symbol': { name: 'symbol'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'String'; ofType: null; }; } }; 'wrappedToken': { name: 'wrappedToken'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'EvmAddress'; ofType: null; }; } }; }; };
66-
'OperationType': { name: 'OperationType'; enumValues: 'BORROW' | 'REPAY' | 'RESERVE_USED_AS_COLLATERAL_ENABLED' | 'RESERVE_USED_AS_COLLATERAL_DISABLED' | 'SUPPLY' | 'USER_EMODE_SET' | 'WITHDRAW' | 'VAULT_DEPLOYED' | 'VAULT_DEPOSIT' | 'VAULT_FEE_UPDATED' | 'VAULT_FEE_WITHDRAWN' | 'VAULT_WITHDRAW' | 'VAULT_TRANSFER' | 'REVENUE_SPLITTER_OWNER_DEPLOYED' | 'REVENUE_SPLITTER_OWNER_TRANSFER' | 'LIQUIDATION'; };
66+
'OperationType': { name: 'OperationType'; enumValues: 'BORROW' | 'REPAY' | 'RESERVE_USED_AS_COLLATERAL_ENABLED' | 'RESERVE_USED_AS_COLLATERAL_DISABLED' | 'SUPPLY' | 'USER_EMODE_SET' | 'WITHDRAW' | 'VAULT_DEPLOYED' | 'VAULT_DEPOSIT' | 'VAULT_FEE_UPDATED' | 'VAULT_FEE_WITHDRAWN' | 'VAULT_WITHDRAW' | 'VAULT_OWNERSHIP_TRANSFERRED' | 'REVENUE_SPLITTER_OWNER_DEPLOYED' | 'REVENUE_SPLITTER_OWNER_TRANSFER' | 'LIQUIDATION'; };
6767
'OrderDirection': { name: 'OrderDirection'; enumValues: 'ASC' | 'DESC'; };
6868
'PageSize': { name: 'PageSize'; enumValues: 'TEN' | 'FIFTY'; };
6969
'PaginatedResultInfo': { kind: 'OBJECT'; name: 'PaginatedResultInfo'; fields: { 'next': { name: 'next'; type: { kind: 'SCALAR'; name: 'Cursor'; ofType: null; } }; 'prev': { name: 'prev'; type: { kind: 'SCALAR'; name: 'Cursor'; ofType: null; } }; }; };

0 commit comments

Comments
 (0)