From 6088c4495d5b22e4dd0c06e63e7e0ec4dbcc0cab Mon Sep 17 00:00:00 2001 From: Noah Saso Date: Thu, 19 Oct 2023 17:05:59 -0700 Subject: [PATCH] Added valence account types. --- .../ConfigureRebalancer/Component.stories.tsx | 2 + .../ConfigureRebalancer/Component.tsx | 5 ++ .../treasury/ConfigureRebalancer/index.tsx | 61 ++++++++++++++++++- packages/types/contracts/ValenceAccount.ts | 52 ++++++++++++++++ 4 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 packages/types/contracts/ValenceAccount.ts diff --git a/packages/stateful/actions/core/treasury/ConfigureRebalancer/Component.stories.tsx b/packages/stateful/actions/core/treasury/ConfigureRebalancer/Component.stories.tsx index 263ed6287..c7e313304 100644 --- a/packages/stateful/actions/core/treasury/ConfigureRebalancer/Component.stories.tsx +++ b/packages/stateful/actions/core/treasury/ConfigureRebalancer/Component.stories.tsx @@ -37,6 +37,8 @@ export default { ki: 0.2, kd: 0.1, }, + maxLimitBps: 500, + targetOverrideStrategy: 'proportional', }), makeDaoProvidersDecorator(makeDaoInfo()), ], diff --git a/packages/stateful/actions/core/treasury/ConfigureRebalancer/Component.tsx b/packages/stateful/actions/core/treasury/ConfigureRebalancer/Component.tsx index cf874d760..c143c328e 100644 --- a/packages/stateful/actions/core/treasury/ConfigureRebalancer/Component.tsx +++ b/packages/stateful/actions/core/treasury/ConfigureRebalancer/Component.tsx @@ -36,16 +36,20 @@ export type ConfigureRebalancerData = { // has the address. valenceAccount?: ValenceAccount chainId: string + trustee?: string baseDenom: string tokens: { denom: string percent: number + minBalance?: number }[] pid: { kp: number ki: number kd: number } + maxLimitBps?: number + targetOverrideStrategy: string } export type ConfigureRebalancerOptions = { @@ -174,6 +178,7 @@ export const ConfigureRebalancerComponent: ActionComponent<
+ {/* TODO: support minBalance */} {tokensFields.map(({ id }, index) => { const watchDenom = watch( (fieldNamePrefix + diff --git a/packages/stateful/actions/core/treasury/ConfigureRebalancer/index.tsx b/packages/stateful/actions/core/treasury/ConfigureRebalancer/index.tsx index 57d7c700c..4817c56c0 100644 --- a/packages/stateful/actions/core/treasury/ConfigureRebalancer/index.tsx +++ b/packages/stateful/actions/core/treasury/ConfigureRebalancer/index.tsx @@ -1,3 +1,4 @@ +import { fromBase64, fromUtf8 } from '@cosmjs/encoding' import { useCallback } from 'react' import { useFormContext } from 'react-hook-form' import { useRecoilValueLoadable, waitForAll } from 'recoil' @@ -57,11 +58,17 @@ const useDefaults: UseDefaults = () => { ] : []), ], + // TODO: pick default pid: { kp: 0.1, ki: 0.1, kd: 0.1, }, + // TODO: pick default + // 5% + maxLimitBps: 500, + // TODO: pick default + targetOverrideStrategy: 'proportional', } } @@ -189,8 +196,10 @@ const useDecodedCosmosMsg: UseDecodedCosmosMsg = ( msg = decodedPolytone.msg } + let serviceName: string | undefined + let data: RebalancerData | undefined if ( - !objectMatchesStructure(msg, { + objectMatchesStructure(msg, { wasm: { execute: { contract_addr: {}, @@ -200,13 +209,61 @@ const useDecodedCosmosMsg: UseDecodedCosmosMsg = ( }, }) ) { + if ( + objectMatchesStructure(msg.wasm.execute.msg, { + register_to_service: { + service_name: {}, + data: {}, + }, + }) + ) { + serviceName = msg.wasm.execute.msg.register_to_service + .service_name as string + data = JSON.parse( + fromUtf8( + fromBase64(msg.wasm.execute.msg.register_to_service.data as string) + ) + ) + } else if ( + objectMatchesStructure(msg.wasm.execute.msg, { + update_service: { + service_name: {}, + data: {}, + }, + }) + ) { + serviceName = msg.wasm.execute.msg.update_service.service_name as string + data = JSON.parse( + fromUtf8(fromBase64(msg.wasm.execute.msg.update_service.data as string)) + ) + } else { + return { + match: false, + } + } + + if ( + serviceName !== 'rebalancer' || + !objectMatchesStructure(data, { + base_denom: {}, + targets: {}, + pid: {}, + target_override_strategy: {}, + }) + ) { + return { + match: false, + } + } + } else { return { match: false, } } return { - match: false, + match: true, + data: {}, } } diff --git a/packages/types/contracts/ValenceAccount.ts b/packages/types/contracts/ValenceAccount.ts new file mode 100644 index 000000000..83c3f47a7 --- /dev/null +++ b/packages/types/contracts/ValenceAccount.ts @@ -0,0 +1,52 @@ +import { Binary, CosmosMsgForEmpty } from './common' + +export interface InstantiateMsg { + services_manager: string +} +export type ExecuteMsg = + | { + register_to_service: { + data?: Binary | null + service_name: ValenceServices + } + } + | { + deregister_from_service: { + service_name: ValenceServices + } + } + | { + update_service: { + data: Binary + service_name: ValenceServices + } + } + | { + pause_service: { + service_name: ValenceServices + } + } + | { + resume_service: { + service_name: ValenceServices + } + } + | { + send_funds_by_service: { + atomic: boolean + msgs: CosmosMsgForEmpty[] + } + } + | { + execute_by_service: { + atomic: boolean + msgs: CosmosMsgForEmpty[] + } + } + | { + execute_by_admin: { + msgs: CosmosMsgForEmpty[] + } + } +export type ValenceServices = 'rebalancer' | 'test' +export type QueryMsg = string