Skip to content

Commit

Permalink
Added valence account types.
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso committed Oct 20, 2023
1 parent 581f138 commit 6088c44
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export default {
ki: 0.2,
kd: 0.1,
},
maxLimitBps: 500,
targetOverrideStrategy: 'proportional',
}),
makeDaoProvidersDecorator(makeDaoInfo()),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -174,6 +178,7 @@ export const ConfigureRebalancerComponent: ActionComponent<
<div className="flex flex-col gap-2">
<InputLabel name={t('form.tokens')} />

{/* TODO: support minBalance */}
{tokensFields.map(({ id }, index) => {
const watchDenom = watch(
(fieldNamePrefix +
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -57,11 +58,17 @@ const useDefaults: UseDefaults<ConfigureRebalancerData> = () => {
]
: []),
],
// TODO: pick default
pid: {
kp: 0.1,
ki: 0.1,
kd: 0.1,
},
// TODO: pick default
// 5%
maxLimitBps: 500,
// TODO: pick default
targetOverrideStrategy: 'proportional',
}
}

Expand Down Expand Up @@ -189,8 +196,10 @@ const useDecodedCosmosMsg: UseDecodedCosmosMsg<ConfigureRebalancerData> = (
msg = decodedPolytone.msg
}

let serviceName: string | undefined
let data: RebalancerData | undefined
if (
!objectMatchesStructure(msg, {
objectMatchesStructure(msg, {
wasm: {
execute: {
contract_addr: {},
Expand All @@ -200,13 +209,61 @@ const useDecodedCosmosMsg: UseDecodedCosmosMsg<ConfigureRebalancerData> = (
},
})
) {
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: {},
}
}

Expand Down
52 changes: 52 additions & 0 deletions packages/types/contracts/ValenceAccount.ts
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6088c44

Please sign in to comment.