diff --git a/src/hooks/useHealthComputer.tsx b/src/hooks/useHealthComputer.tsx index d9be8ad6..101966bd 100644 --- a/src/hooks/useHealthComputer.tsx +++ b/src/hooks/useHealthComputer.tsx @@ -85,19 +85,7 @@ export default function useHealthComputer(account?: Account) { () => assetParams.reduce( (prev, curr) => { - const params: AssetParamsBaseForAddr = { - ...curr, - // The following overrides are required as testnet is 'broken' and new contracts are not updated yet - // These overrides are not used by the healthcomputer internally, so they're not important anyways. - protocol_liquidation_fee: '1', - liquidation_bonus: { - max_lb: '1', - min_lb: '1', - slope: '1', - starting_lb: '1', - }, - } - prev[params.denom] = params + prev[curr.denom] = curr return prev }, @@ -144,12 +132,8 @@ export default function useHealthComputer(account?: Account) { }, [priceData, denomsData, vaultConfigsData, vaultPositionValues, positions]) useEffect(() => { - async function computeHealthWasm() { - if (!healthComputer) return - setHealth(Number((await compute_health_js(healthComputer)).max_ltv_health_factor) || 0) - } - // TODO: Health computer throwing error. Should be aligned with new contracts: https://delphilabs.atlassian.net/browse/MP-3238 - // computeHealthWasm() + if (!healthComputer) return + setHealth(Number(compute_health_js(healthComputer).max_ltv_health_factor) || 0) }, [healthComputer]) const computeMaxBorrowAmount = useCallback( diff --git a/src/types/generated/mars-rover-health-types/MarsRoverHealthTypes.client.ts b/src/types/generated/mars-rover-health-types/MarsRoverHealthTypes.client.ts new file mode 100644 index 00000000..a5aad0a3 --- /dev/null +++ b/src/types/generated/mars-rover-health-types/MarsRoverHealthTypes.client.ts @@ -0,0 +1,175 @@ +// @ts-nocheck +/** + * This file was automatically generated by @cosmwasm/ts-codegen@0.33.0. + * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, + * and run the @cosmwasm/ts-codegen generate command to regenerate this file. + */ + +import { CosmWasmClient, SigningCosmWasmClient, ExecuteResult } from '@cosmjs/cosmwasm-stargate' +import { Coin, StdFee } from '@cosmjs/amino' +import { + InstantiateMsg, + ExecuteMsg, + OwnerUpdate, + QueryMsg, + ActionKind, + AccountKind, + ConfigResponse, + OwnerResponse, + HealthState, + Decimal, + Uint128, + HealthValuesResponse, +} from './MarsRoverHealthTypes.types' +export interface MarsRoverHealthTypesReadOnlyInterface { + contractAddress: string + healthValues: ({ + accountId, + action, + kind, + }: { + accountId: string + action: ActionKind + kind: AccountKind + }) => Promise + healthState: ({ + accountId, + action, + kind, + }: { + accountId: string + action: ActionKind + kind: AccountKind + }) => Promise + config: () => Promise +} +export class MarsRoverHealthTypesQueryClient implements MarsRoverHealthTypesReadOnlyInterface { + client: CosmWasmClient + contractAddress: string + + constructor(client: CosmWasmClient, contractAddress: string) { + this.client = client + this.contractAddress = contractAddress + this.healthValues = this.healthValues.bind(this) + this.healthState = this.healthState.bind(this) + this.config = this.config.bind(this) + } + + healthValues = async ({ + accountId, + action, + kind, + }: { + accountId: string + action: ActionKind + kind: AccountKind + }): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + health_values: { + account_id: accountId, + action, + kind, + }, + }) + } + healthState = async ({ + accountId, + action, + kind, + }: { + accountId: string + action: ActionKind + kind: AccountKind + }): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + health_state: { + account_id: accountId, + action, + kind, + }, + }) + } + config = async (): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + config: {}, + }) + } +} +export interface MarsRoverHealthTypesInterface extends MarsRoverHealthTypesReadOnlyInterface { + contractAddress: string + sender: string + updateOwner: ( + ownerUpdate: OwnerUpdate, + fee?: number | StdFee | 'auto', + memo?: string, + _funds?: Coin[], + ) => Promise + updateConfig: ( + { + creditManager, + }: { + creditManager: string + }, + fee?: number | StdFee | 'auto', + memo?: string, + _funds?: Coin[], + ) => Promise +} +export class MarsRoverHealthTypesClient + extends MarsRoverHealthTypesQueryClient + implements MarsRoverHealthTypesInterface +{ + client: SigningCosmWasmClient + sender: string + contractAddress: string + + constructor(client: SigningCosmWasmClient, sender: string, contractAddress: string) { + super(client, contractAddress) + this.client = client + this.sender = sender + this.contractAddress = contractAddress + this.updateOwner = this.updateOwner.bind(this) + this.updateConfig = this.updateConfig.bind(this) + } + + updateOwner = async ( + ownerUpdate: OwnerUpdate, + fee: number | StdFee | 'auto' = 'auto', + memo?: string, + _funds?: Coin[], + ): Promise => { + return await this.client.execute( + this.sender, + this.contractAddress, + { + update_owner: ownerUpdate, + }, + fee, + memo, + _funds, + ) + } + updateConfig = async ( + { + creditManager, + }: { + creditManager: string + }, + fee: number | StdFee | 'auto' = 'auto', + memo?: string, + _funds?: Coin[], + ): Promise => { + return await this.client.execute( + this.sender, + this.contractAddress, + { + update_config: { + credit_manager: creditManager, + }, + }, + fee, + memo, + _funds, + ) + } +} diff --git a/src/types/generated/mars-rover-health-types/MarsRoverHealthTypes.message-composer.ts b/src/types/generated/mars-rover-health-types/MarsRoverHealthTypes.message-composer.ts new file mode 100644 index 00000000..6a04f642 --- /dev/null +++ b/src/types/generated/mars-rover-health-types/MarsRoverHealthTypes.message-composer.ts @@ -0,0 +1,89 @@ +// @ts-nocheck +/** + * This file was automatically generated by @cosmwasm/ts-codegen@0.33.0. + * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, + * and run the @cosmwasm/ts-codegen generate command to regenerate this file. + */ + +import { Coin } from '@cosmjs/amino' +import { MsgExecuteContractEncodeObject } from '@cosmjs/cosmwasm-stargate' +import { MsgExecuteContract } from 'cosmjs-types/cosmwasm/wasm/v1/tx' +import { toUtf8 } from '@cosmjs/encoding' +import { + InstantiateMsg, + ExecuteMsg, + OwnerUpdate, + QueryMsg, + ActionKind, + AccountKind, + ConfigResponse, + OwnerResponse, + HealthState, + Decimal, + Uint128, + HealthValuesResponse, +} from './MarsRoverHealthTypes.types' +export interface MarsRoverHealthTypesMessage { + contractAddress: string + sender: string + updateOwner: (ownerUpdate: OwnerUpdate, _funds?: Coin[]) => MsgExecuteContractEncodeObject + updateConfig: ( + { + creditManager, + }: { + creditManager: string + }, + _funds?: Coin[], + ) => MsgExecuteContractEncodeObject +} +export class MarsRoverHealthTypesMessageComposer implements MarsRoverHealthTypesMessage { + sender: string + contractAddress: string + + constructor(sender: string, contractAddress: string) { + this.sender = sender + this.contractAddress = contractAddress + this.updateOwner = this.updateOwner.bind(this) + this.updateConfig = this.updateConfig.bind(this) + } + + updateOwner = (ownerUpdate: OwnerUpdate, _funds?: Coin[]): MsgExecuteContractEncodeObject => { + return { + typeUrl: '/cosmwasm.wasm.v1.MsgExecuteContract', + value: MsgExecuteContract.fromPartial({ + sender: this.sender, + contract: this.contractAddress, + msg: toUtf8( + JSON.stringify({ + update_owner: ownerUpdate, + }), + ), + funds: _funds, + }), + } + } + updateConfig = ( + { + creditManager, + }: { + creditManager: string + }, + _funds?: Coin[], + ): MsgExecuteContractEncodeObject => { + return { + typeUrl: '/cosmwasm.wasm.v1.MsgExecuteContract', + value: MsgExecuteContract.fromPartial({ + sender: this.sender, + contract: this.contractAddress, + msg: toUtf8( + JSON.stringify({ + update_config: { + credit_manager: creditManager, + }, + }), + ), + funds: _funds, + }), + } + } +} diff --git a/src/types/generated/mars-rover-health-types/MarsRoverHealthTypes.react-query.ts b/src/types/generated/mars-rover-health-types/MarsRoverHealthTypes.react-query.ts new file mode 100644 index 00000000..078bebe9 --- /dev/null +++ b/src/types/generated/mars-rover-health-types/MarsRoverHealthTypes.react-query.ts @@ -0,0 +1,173 @@ +// @ts-nocheck +/** + * This file was automatically generated by @cosmwasm/ts-codegen@0.33.0. + * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, + * and run the @cosmwasm/ts-codegen generate command to regenerate this file. + */ + +import { UseQueryOptions, useQuery, useMutation, UseMutationOptions } from '@tanstack/react-query' +import { ExecuteResult } from '@cosmjs/cosmwasm-stargate' +import { StdFee, Coin } from '@cosmjs/amino' +import { + InstantiateMsg, + ExecuteMsg, + OwnerUpdate, + QueryMsg, + ActionKind, + AccountKind, + ConfigResponse, + OwnerResponse, + HealthState, + Decimal, + Uint128, + HealthValuesResponse, +} from './MarsRoverHealthTypes.types' +import { + MarsRoverHealthTypesQueryClient, + MarsRoverHealthTypesClient, +} from './MarsRoverHealthTypes.client' +export const marsRoverHealthTypesQueryKeys = { + contract: [ + { + contract: 'marsRoverHealthTypes', + }, + ] as const, + address: (contractAddress: string | undefined) => + [{ ...marsRoverHealthTypesQueryKeys.contract[0], address: contractAddress }] as const, + healthValues: (contractAddress: string | undefined, args?: Record) => + [ + { + ...marsRoverHealthTypesQueryKeys.address(contractAddress)[0], + method: 'health_values', + args, + }, + ] as const, + healthState: (contractAddress: string | undefined, args?: Record) => + [ + { + ...marsRoverHealthTypesQueryKeys.address(contractAddress)[0], + method: 'health_state', + args, + }, + ] as const, + config: (contractAddress: string | undefined, args?: Record) => + [ + { ...marsRoverHealthTypesQueryKeys.address(contractAddress)[0], method: 'config', args }, + ] as const, +} +export interface MarsRoverHealthTypesReactQuery { + client: MarsRoverHealthTypesQueryClient | undefined + options?: Omit< + UseQueryOptions, + "'queryKey' | 'queryFn' | 'initialData'" + > & { + initialData?: undefined + } +} +export interface MarsRoverHealthTypesConfigQuery + extends MarsRoverHealthTypesReactQuery {} +export function useMarsRoverHealthTypesConfigQuery({ + client, + options, +}: MarsRoverHealthTypesConfigQuery) { + return useQuery( + marsRoverHealthTypesQueryKeys.config(client?.contractAddress), + () => (client ? client.config() : Promise.reject(new Error('Invalid client'))), + { ...options, enabled: !!client && (options?.enabled != undefined ? options.enabled : true) }, + ) +} +export interface MarsRoverHealthTypesHealthStateQuery + extends MarsRoverHealthTypesReactQuery { + args: { + accountId: string + action: ActionKind + kind: AccountKind + } +} +export function useMarsRoverHealthTypesHealthStateQuery({ + client, + args, + options, +}: MarsRoverHealthTypesHealthStateQuery) { + return useQuery( + marsRoverHealthTypesQueryKeys.healthState(client?.contractAddress, args), + () => + client + ? client.healthState({ + accountId: args.accountId, + action: args.action, + kind: args.kind, + }) + : Promise.reject(new Error('Invalid client')), + { ...options, enabled: !!client && (options?.enabled != undefined ? options.enabled : true) }, + ) +} +export interface MarsRoverHealthTypesHealthValuesQuery + extends MarsRoverHealthTypesReactQuery { + args: { + accountId: string + action: ActionKind + kind: AccountKind + } +} +export function useMarsRoverHealthTypesHealthValuesQuery({ + client, + args, + options, +}: MarsRoverHealthTypesHealthValuesQuery) { + return useQuery( + marsRoverHealthTypesQueryKeys.healthValues(client?.contractAddress, args), + () => + client + ? client.healthValues({ + accountId: args.accountId, + action: args.action, + kind: args.kind, + }) + : Promise.reject(new Error('Invalid client')), + { ...options, enabled: !!client && (options?.enabled != undefined ? options.enabled : true) }, + ) +} +export interface MarsRoverHealthTypesUpdateConfigMutation { + client: MarsRoverHealthTypesClient + msg: { + creditManager: string + } + args?: { + fee?: number | StdFee | 'auto' + memo?: string + funds?: Coin[] + } +} +export function useMarsRoverHealthTypesUpdateConfigMutation( + options?: Omit< + UseMutationOptions, + 'mutationFn' + >, +) { + return useMutation( + ({ client, msg, args: { fee, memo, funds } = {} }) => + client.updateConfig(msg, fee, memo, funds), + options, + ) +} +export interface MarsRoverHealthTypesUpdateOwnerMutation { + client: MarsRoverHealthTypesClient + msg: OwnerUpdate + args?: { + fee?: number | StdFee | 'auto' + memo?: string + funds?: Coin[] + } +} +export function useMarsRoverHealthTypesUpdateOwnerMutation( + options?: Omit< + UseMutationOptions, + 'mutationFn' + >, +) { + return useMutation( + ({ client, msg, args: { fee, memo, funds } = {} }) => client.updateOwner(msg, fee, memo, funds), + options, + ) +} diff --git a/src/types/generated/mars-rover-health-types/MarsRoverHealthTypes.types.ts b/src/types/generated/mars-rover-health-types/MarsRoverHealthTypes.types.ts new file mode 100644 index 00000000..2baa48f3 --- /dev/null +++ b/src/types/generated/mars-rover-health-types/MarsRoverHealthTypes.types.ts @@ -0,0 +1,84 @@ +// @ts-nocheck +/** + * This file was automatically generated by @cosmwasm/ts-codegen@0.33.0. + * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, + * and run the @cosmwasm/ts-codegen generate command to regenerate this file. + */ + +export interface InstantiateMsg { + owner: string +} +export type ExecuteMsg = + | { + update_owner: OwnerUpdate + } + | { + update_config: { + credit_manager: string + } + } +export type OwnerUpdate = + | { + propose_new_owner: { + proposed: string + } + } + | 'clear_proposed' + | 'accept_proposed' + | 'abolish_owner_role' + | { + set_emergency_owner: { + emergency_owner: string + } + } + | 'clear_emergency_owner' +export type QueryMsg = + | { + health_values: { + account_id: string + action: ActionKind + kind: AccountKind + } + } + | { + health_state: { + account_id: string + action: ActionKind + kind: AccountKind + } + } + | { + config: {} + } +export type ActionKind = 'default' | 'liquidation' +export type AccountKind = 'default' | 'high_levered_strategy' +export interface ConfigResponse { + credit_manager?: string | null + owner_response: OwnerResponse +} +export interface OwnerResponse { + abolished: boolean + emergency_owner?: string | null + initialized: boolean + owner?: string | null + proposed?: string | null +} +export type HealthState = + | 'healthy' + | { + unhealthy: { + max_ltv_health_factor: Decimal + } + } +export type Decimal = string +export type Uint128 = string +export interface HealthValuesResponse { + above_max_ltv: boolean + liquidatable: boolean + liquidation_health_factor?: Decimal | null + liquidation_threshold_adjusted_collateral: Uint128 + max_ltv_adjusted_collateral: Uint128 + max_ltv_health_factor?: Decimal | null + total_collateral_value: Uint128 + total_debt_value: Uint128 +} diff --git a/src/types/generated/mars-rover-health-types/bundle.ts b/src/types/generated/mars-rover-health-types/bundle.ts new file mode 100644 index 00000000..3b5018ea --- /dev/null +++ b/src/types/generated/mars-rover-health-types/bundle.ts @@ -0,0 +1,14 @@ +// @ts-nocheck +/** + * This file was automatically generated by @cosmwasm/ts-codegen@0.33.0. + * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, + * and run the @cosmwasm/ts-codegen generate command to regenerate this file. + */ + +import * as _36 from './MarsRoverHealthTypes.types' +import * as _37 from './MarsRoverHealthTypes.client' +import * as _38 from './MarsRoverHealthTypes.message-composer' +import * as _39 from './MarsRoverHealthTypes.react-query' +export namespace contracts { + export const MarsRoverHealthTypes = { ..._36, ..._37, ..._38, ..._39 } +} diff --git a/src/utils/health_computer/index_bg.wasm b/src/utils/health_computer/index_bg.wasm index b2901832..14db4831 100644 Binary files a/src/utils/health_computer/index_bg.wasm and b/src/utils/health_computer/index_bg.wasm differ