From d2b74baffd5673d050e8bc8579ceedf1563e637b Mon Sep 17 00:00:00 2001 From: larry <26318510+larry0x@users.noreply.github.com> Date: Sat, 5 Aug 2023 02:41:13 +0100 Subject: [PATCH 1/2] include deposit cap in total deposit query --- contracts/params/src/msg.rs | 11 ++++++++-- contracts/params/src/query.rs | 20 +++++++++++++---- contracts/params/tests/test_deposit_cap.rs | 25 +++++++++++++++++++--- 3 files changed, 47 insertions(+), 9 deletions(-) diff --git a/contracts/params/src/msg.rs b/contracts/params/src/msg.rs index 7f192d08d..d4fbd3177 100644 --- a/contracts/params/src/msg.rs +++ b/contracts/params/src/msg.rs @@ -1,5 +1,5 @@ use cosmwasm_schema::{cw_serde, QueryResponses}; -use cosmwasm_std::{Coin, Decimal}; +use cosmwasm_std::{Decimal, Uint128}; use mars_owner::OwnerUpdate; use crate::types::{asset::AssetParamsUnchecked, vault::VaultConfigUnchecked}; @@ -57,12 +57,19 @@ pub enum QueryMsg { /// Compute the total amount deposited of the given asset across Red Bank /// and Credit Manager. - #[returns(Coin)] + #[returns(TotalDepositResponse)] TotalDeposit { denom: String, }, } +#[cw_serde] +pub struct TotalDepositResponse { + pub denom: String, + pub cap: Uint128, + pub amount: Uint128, +} + #[cw_serde] pub enum AssetParamsUpdate { AddOrUpdate { diff --git a/contracts/params/src/query.rs b/contracts/params/src/query.rs index d7a5b8256..c5e53bd0d 100644 --- a/contracts/params/src/query.rs +++ b/contracts/params/src/query.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{Addr, Coin, Deps, Env, Order, StdResult, Uint128}; +use cosmwasm_std::{Addr, Deps, Env, Order, StdResult, Uint128}; use cw_storage_plus::Bound; use mars_interest_rate::get_underlying_liquidity_amount; use mars_red_bank_types::{ @@ -7,6 +7,7 @@ use mars_red_bank_types::{ }; use crate::{ + msg::TotalDepositResponse, state::{ADDRESS_PROVIDER, ASSET_PARAMS, VAULT_CONFIGS}, types::{asset::AssetParams, vault::VaultConfig}, }; @@ -73,7 +74,11 @@ pub fn query_all_vault_configs( /// For example, when computing the deposited amount of ATOM, we only include /// ATOM deposited in RB and CM; we don't include the ATOM-OSMO LP token, or /// the ATOM-OSMO farming vault. -pub fn query_total_deposit(deps: Deps, env: &Env, denom: String) -> StdResult { +pub fn query_total_deposit( + deps: Deps, + env: &Env, + denom: String, +) -> StdResult { let current_timestamp = env.block.time.seconds(); // query contract addresses @@ -124,8 +129,15 @@ pub fn query_total_deposit(deps: Deps, env: &Env, denom: String) -> StdResult Date: Sat, 5 Aug 2023 02:46:51 +0100 Subject: [PATCH 2/2] update schema and typescript types --- schemas/mars-params/mars-params.json | 7 ++++++- scripts/types/generated/mars-params/MarsParams.client.ts | 5 +++-- .../types/generated/mars-params/MarsParams.react-query.ts | 8 +++++--- scripts/types/generated/mars-params/MarsParams.types.ts | 5 +++++ 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/schemas/mars-params/mars-params.json b/schemas/mars-params/mars-params.json index b74a5a050..e9daf2f0b 100644 --- a/schemas/mars-params/mars-params.json +++ b/schemas/mars-params/mars-params.json @@ -1341,20 +1341,25 @@ }, "total_deposit": { "$schema": "http://json-schema.org/draft-07/schema#", - "title": "Coin", + "title": "TotalDepositResponse", "type": "object", "required": [ "amount", + "cap", "denom" ], "properties": { "amount": { "$ref": "#/definitions/Uint128" }, + "cap": { + "$ref": "#/definitions/Uint128" + }, "denom": { "type": "string" } }, + "additionalProperties": false, "definitions": { "Uint128": { "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", diff --git a/scripts/types/generated/mars-params/MarsParams.client.ts b/scripts/types/generated/mars-params/MarsParams.client.ts index 610c71efe..4722ea540 100644 --- a/scripts/types/generated/mars-params/MarsParams.client.ts +++ b/scripts/types/generated/mars-params/MarsParams.client.ts @@ -36,6 +36,7 @@ import { ArrayOfVaultConfigBaseForAddr, VaultConfigBaseForAddr, OwnerResponse, + TotalDepositResponse, } from './MarsParams.types' export interface MarsParamsReadOnlyInterface { contractAddress: string @@ -57,7 +58,7 @@ export interface MarsParamsReadOnlyInterface { startAfter?: string }) => Promise targetHealthFactor: () => Promise - totalDeposit: ({ denom }: { denom: string }) => Promise + totalDeposit: ({ denom }: { denom: string }) => Promise } export class MarsParamsQueryClient implements MarsParamsReadOnlyInterface { client: CosmWasmClient @@ -127,7 +128,7 @@ export class MarsParamsQueryClient implements MarsParamsReadOnlyInterface { target_health_factor: {}, }) } - totalDeposit = async ({ denom }: { denom: string }): Promise => { + totalDeposit = async ({ denom }: { denom: string }): Promise => { return this.client.queryContractSmart(this.contractAddress, { total_deposit: { denom, diff --git a/scripts/types/generated/mars-params/MarsParams.react-query.ts b/scripts/types/generated/mars-params/MarsParams.react-query.ts index beae94e83..54b185c5b 100644 --- a/scripts/types/generated/mars-params/MarsParams.react-query.ts +++ b/scripts/types/generated/mars-params/MarsParams.react-query.ts @@ -37,6 +37,7 @@ import { ArrayOfVaultConfigBaseForAddr, VaultConfigBaseForAddr, OwnerResponse, + TotalDepositResponse, } from './MarsParams.types' import { MarsParamsQueryClient, MarsParamsClient } from './MarsParams.client' export const marsParamsQueryKeys = { @@ -79,17 +80,18 @@ export interface MarsParamsReactQuery { initialData?: undefined } } -export interface MarsParamsTotalDepositQuery extends MarsParamsReactQuery { +export interface MarsParamsTotalDepositQuery + extends MarsParamsReactQuery { args: { denom: string } } -export function useMarsParamsTotalDepositQuery({ +export function useMarsParamsTotalDepositQuery({ client, args, options, }: MarsParamsTotalDepositQuery) { - return useQuery( + return useQuery( marsParamsQueryKeys.totalDeposit(client?.contractAddress, args), () => client diff --git a/scripts/types/generated/mars-params/MarsParams.types.ts b/scripts/types/generated/mars-params/MarsParams.types.ts index 11eb13940..d27e9d118 100644 --- a/scripts/types/generated/mars-params/MarsParams.types.ts +++ b/scripts/types/generated/mars-params/MarsParams.types.ts @@ -208,3 +208,8 @@ export interface OwnerResponse { owner?: string | null proposed?: string | null } +export interface TotalDepositResponse { + amount: Uint128 + cap: Uint128 + denom: string +}