Skip to content

Commit

Permalink
Merge branch 'main' into feat/metamorpho-v1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubilmax authored Jan 10, 2025
2 parents 51d42e4 + 0d0aa4a commit a1f337f
Show file tree
Hide file tree
Showing 6 changed files with 235 additions and 9 deletions.
66 changes: 63 additions & 3 deletions packages/blue-api-sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export type Asset = {
oraclePriceUsd: Maybe<Scalars["Float"]["output"]>;
/** Current price in USD, for display purpose. */
priceUsd: Maybe<Scalars["Float"]["output"]>;
/** Risk related data on the asset */
riskAnalysis: Maybe<Array<RiskAnalysis>>;
/** Current spot price in ETH. */
spotPriceEth: Maybe<Scalars["Float"]["output"]>;
symbol: Scalars["String"]["output"];
Expand Down Expand Up @@ -90,6 +92,11 @@ export type AssetSpotPriceEthArgs = {
timestamp?: InputMaybe<Scalars["Float"]["input"]>;
};

export enum AssetOrderBy {
Address = "Address",
CredoraRiskScore = "CredoraRiskScore",
}

/** Asset yield */
export type AssetYield = {
__typename?: "AssetYield";
Expand All @@ -102,6 +109,10 @@ export type AssetsFilters = {
address_in?: InputMaybe<Array<Scalars["String"]["input"]>>;
/** Filter by chain id */
chainId_in?: InputMaybe<Array<Scalars["Int"]["input"]>>;
/** Filter by credora risk score greater than or equal to given value */
credoraRiskScore_gte?: InputMaybe<Scalars["Float"]["input"]>;
/** Filter by credora risk score lower than or equal to given value */
credoraRiskScore_lte?: InputMaybe<Scalars["Float"]["input"]>;
/** Filter by asset id */
id_in?: InputMaybe<Array<Scalars["String"]["input"]>>;
search?: InputMaybe<Scalars["String"]["input"]>;
Expand Down Expand Up @@ -212,6 +223,8 @@ export type Market = {
realizedBadDebt: Maybe<MarketBadDebt>;
/** Underlying amount of assets that can be reallocated to this market */
reallocatableLiquidityAssets: Maybe<Scalars["BigInt"]["output"]>;
/** Risk related data on the market */
riskAnalysis: Maybe<Array<RiskAnalysis>>;
/** Current state */
state: Maybe<MarketState>;
/** Vaults with the market in supply queue */
Expand Down Expand Up @@ -311,6 +324,10 @@ export type MarketFilters = {
/** Filter by collateral asset tags. */
collateralAssetTags_in?: InputMaybe<Array<Scalars["String"]["input"]>>;
countryCode?: InputMaybe<Scalars["String"]["input"]>;
/** Filter by credora risk score greater than or equal to given value */
credoraRiskScore_gte?: InputMaybe<Scalars["Float"]["input"]>;
/** Filter by credora risk score lower than or equal to given value */
credoraRiskScore_lte?: InputMaybe<Scalars["Float"]["input"]>;
/** Filter by greater than or equal to given fee rate */
fee_gte?: InputMaybe<Scalars["Float"]["input"]>;
/** Filter by lower than or equal to given fee rate */
Expand Down Expand Up @@ -746,6 +763,7 @@ export enum MarketOrderBy {
BorrowAssetsUsd = "BorrowAssetsUsd",
BorrowShares = "BorrowShares",
CollateralAssetSymbol = "CollateralAssetSymbol",
CredoraRiskScore = "CredoraRiskScore",
DailyBorrowApy = "DailyBorrowApy",
DailyNetBorrowApy = "DailyNetBorrowApy",
Fee = "Fee",
Expand Down Expand Up @@ -1483,6 +1501,7 @@ export type Query = {
publicAllocators: PaginatedPublicAllocator;
search: SearchResults;
transaction: Transaction;
/** @deprecated Multiple Transaction entities correspond to a single hash, because a Transaction entity corresponds to an onchain event. */
transactionByHash: Transaction;
transactions: PaginatedTransactions;
user: User;
Expand All @@ -1507,6 +1526,8 @@ export type QueryAssetByAddressArgs = {

export type QueryAssetsArgs = {
first?: InputMaybe<Scalars["Int"]["input"]>;
orderBy?: InputMaybe<AssetOrderBy>;
orderDirection?: InputMaybe<OrderDirection>;
skip?: InputMaybe<Scalars["Int"]["input"]>;
where?: InputMaybe<AssetsFilters>;
};
Expand Down Expand Up @@ -1709,6 +1730,19 @@ export type QueryVaultsArgs = {
where?: InputMaybe<VaultFilters>;
};

/** Risk analysis */
export type RiskAnalysis = {
__typename?: "RiskAnalysis";
isUnderReview: Scalars["Boolean"]["output"];
provider: RiskProvider;
score: Scalars["Float"]["output"];
timestamp: Scalars["Float"]["output"];
};

export enum RiskProvider {
Credora = "CREDORA",
}

/** Global search results */
export type SearchResults = {
__typename?: "SearchResults";
Expand Down Expand Up @@ -1756,7 +1790,8 @@ export type TransactionData =
| MarketCollateralTransferTransactionData
| MarketLiquidationTransactionData
| MarketTransferTransactionData
| VaultTransactionData;
| VaultTransactionData
| VaultTransferTransactionData;

/** Filtering options for transactions. AND operator is used for multiple filters, while OR operator is used for multiple values in the same filter. */
export type TransactionFilters = {
Expand Down Expand Up @@ -1847,6 +1882,7 @@ export enum TransactionType {
MarketWithdrawCollateral = "MarketWithdrawCollateral",
MetaMorphoDeposit = "MetaMorphoDeposit",
MetaMorphoFee = "MetaMorphoFee",
MetaMorphoTransfer = "MetaMorphoTransfer",
MetaMorphoWithdraw = "MetaMorphoWithdraw",
}

Expand All @@ -1870,7 +1906,7 @@ export type User = {
__typename?: "User";
address: Scalars["Address"]["output"];
chain: Chain;
historicalState: Array<UserHistory>;
historicalState: UserHistory;
id: Scalars["ID"]["output"];
marketPositions: Array<MarketPosition>;
state: UserState;
Expand All @@ -1888,6 +1924,16 @@ export type UserHistory = {
vaultsPnlUsd: Maybe<Array<FloatDataPoint>>;
};

/** User state history */
export type UserHistoryMarketsPnlUsdArgs = {
options?: InputMaybe<TimeseriesOptions>;
};

/** User state history */
export type UserHistoryVaultsPnlUsdArgs = {
options?: InputMaybe<TimeseriesOptions>;
};

/** User state */
export type UserState = {
__typename?: "UserState";
Expand Down Expand Up @@ -1961,6 +2007,8 @@ export type Vault = {
pendingCaps: Maybe<Array<VaultPendingCap>>;
/** Public allocator configuration */
publicAllocatorConfig: Maybe<PublicAllocatorConfig>;
/** Risk related data on the vault */
riskAnalysis: Maybe<Array<RiskAnalysis>>;
state: Maybe<VaultState>;
symbol: Scalars["String"]["output"];
/** Vault warnings */
Expand Down Expand Up @@ -2080,6 +2128,10 @@ export type VaultFilters = {
countryCode?: InputMaybe<Scalars["String"]["input"]>;
/** Filter by MetaMorpho creator address */
creatorAddress_in?: InputMaybe<Array<Scalars["String"]["input"]>>;
/** Filter by credora risk score greater than or equal to given value */
credoraRiskScore_gte?: InputMaybe<Scalars["Float"]["input"]>;
/** Filter by credora risk score lower than or equal to given value */
credoraRiskScore_lte?: InputMaybe<Scalars["Float"]["input"]>;
/** Filter by MetaMorpho current curator address */
curatorAddress_in?: InputMaybe<Array<Scalars["String"]["input"]>>;
/** Filter by greater than or equal to given fee rate. */
Expand Down Expand Up @@ -2337,6 +2389,7 @@ export type VaultMetadataCurator = {
export enum VaultOrderBy {
Address = "Address",
Apy = "Apy",
CredoraRiskScore = "CredoraRiskScore",
Curator = "Curator",
DailyApy = "DailyApy",
DailyNetApy = "DailyNetApy",
Expand Down Expand Up @@ -2602,7 +2655,7 @@ export type VaultStateReward = {
yearlySupplyTokens: Scalars["BigInt"]["output"];
};

/** Meta Morpho vault transfer transaction data */
/** Meta Morpho vault transaction data */
export type VaultTransactionData = {
__typename?: "VaultTransactionData";
assets: Scalars["BigInt"]["output"];
Expand All @@ -2611,6 +2664,13 @@ export type VaultTransactionData = {
vault: Vault;
};

/** Meta Morpho vault transfer transaction data */
export type VaultTransferTransactionData = {
__typename?: "VaultTransferTransactionData";
shares: Scalars["BigInt"]["output"];
vault: Vault;
};

/** Vault warning */
export type VaultWarning = {
__typename?: "VaultWarning";
Expand Down
2 changes: 2 additions & 0 deletions packages/blue-api-sdk/src/warnings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export enum MarketWarningType {
IncorrectCollateralExchangeRate = "incorrect_collateral_exchange_rate",
IncorrectLoanExchangeRate = "incorrect_loan_exchange_rate",
NonWhitelisted = "not_whitelisted",
OracleNotFromFactory = "oracle_not_from_factory",
MisconfiguredOracleDecimals = "misconfigured_oracle_decimals",
}

export enum VaultWarningType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,8 @@ export const check = async <
.filter(
(seizedAssets) =>
collateralToken.toUsd(seizedAssets)! > parseEther("1000") ||
(accrualPosition.collateral === seizedAssets &&
loanToken.toUsd(accrualPosition.borrowAssets)! >
parseEther("1000")),
) // Do not try seizing less than $1000 collateral, except if we can realize more than $1000 bad debt.
accrualPosition.collateral === seizedAssets,
) // Do not try seizing less than $1000 collateral, except if we can realize debt.
.map(async (seizedAssets) => {
const repaidShares =
market.getLiquidationRepaidShares(seizedAssets)!;
Expand Down Expand Up @@ -175,6 +173,9 @@ export const check = async <
triedLiquidity.map(
async ({ seizedAssets, repaidAssets, withdrawnAssets }) => {
try {
const badDebtRealization =
seizedAssets === accrualPosition.collateral;

let srcToken =
collateralUnderlyingAsset ?? market.params.collateralToken;
let srcAmount = withdrawnAssets ?? seizedAssets;
Expand Down Expand Up @@ -252,8 +253,9 @@ export const check = async <
srcToken,
srcAmount,
market.params,
slippage,
slippage / 10n ** 16n,
repaidAssets,
client.account.address,
);

if (result) {
Expand Down Expand Up @@ -322,7 +324,7 @@ export const check = async <
);
const profitUsd = loanToken.toUsd(dstAmount - repaidAssets)!;

if (gasLimitUsd > profitUsd)
if (!badDebtRealization && gasLimitUsd > profitUsd)
throw Error(
`gas cost ($${gasLimitUsd.formatWad(
2,
Expand Down
4 changes: 4 additions & 0 deletions packages/liquidation-sdk-viem/src/LiquidationEncoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ export class LiquidationEncoder<
marketParams: MarketParams,
slippage: bigint,
repaidAssets: bigint,
origin: Address,
) {
let srcToken = initialSrcToken;
const srcAmount = initialSrcAmount;
Expand All @@ -476,6 +477,7 @@ export class LiquidationEncoder<
amount: srcAmount,
from: this.address,
slippage,
origin,
includeTokensInfo: false,
includeProtocols: false,
includeGas: false,
Expand Down Expand Up @@ -513,6 +515,7 @@ export class LiquidationEncoder<
dst: marketParams.loanToken,
amount: halfAmount,
from: this.address,
origin,
slippage,
includeTokensInfo: false,
includeProtocols: false,
Expand All @@ -529,6 +532,7 @@ export class LiquidationEncoder<
dst: marketParams.loanToken,
amount: halfAmount,
from: this.address,
origin,
slippage,
includeTokensInfo: false,
includeProtocols: false,
Expand Down
1 change: 1 addition & 0 deletions packages/liquidation-sdk-viem/src/swap/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface SwapParams {
dst: string;
amount: BigIntish;
from: string;
origin: string;
slippage: BigIntish;
protocols?: string;
fee?: BigIntish;
Expand Down
Loading

0 comments on commit a1f337f

Please sign in to comment.