Skip to content

Commit

Permalink
Load rebalancer config from chain address and load valence accounts o…
Browse files Browse the repository at this point in the history
…n page instead of in static props.
  • Loading branch information
NoahSaso committed Oct 20, 2023
1 parent 4cd0893 commit 33d4444
Show file tree
Hide file tree
Showing 8 changed files with 460 additions and 136 deletions.
294 changes: 294 additions & 0 deletions packages/state/contracts/ValenceServiceRebalancer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,294 @@
import { Coin, StdFee } from '@cosmjs/amino'
import {
CosmWasmClient,
ExecuteResult,
SigningCosmWasmClient,
} from '@cosmjs/cosmwasm-stargate'

import {
RebalancerConfig,
RebalancerData,
RebalancerUpdateData,
SystemRebalanceStatus,
} from '@dao-dao/types/contracts/ValenceServiceRebalancer'

export interface ValenceServiceRebalancerReadOnlyInterface {
contractAddress: string
getConfig: ({ addr }: { addr: string }) => Promise<RebalancerConfig>
getSystemStatus: () => Promise<SystemRebalanceStatus>
}
export class ValenceServiceRebalancerQueryClient
implements ValenceServiceRebalancerReadOnlyInterface
{
client: CosmWasmClient
contractAddress: string

constructor(client: CosmWasmClient, contractAddress: string) {
this.client = client
this.contractAddress = contractAddress
this.getConfig = this.getConfig.bind(this)
this.getSystemStatus = this.getSystemStatus.bind(this)
}

getConfig = async ({ addr }: { addr: string }): Promise<RebalancerConfig> => {
return this.client.queryContractSmart(this.contractAddress, {
get_config: {
addr,
},
})
}
getSystemStatus = async (): Promise<SystemRebalanceStatus> => {
return this.client.queryContractSmart(this.contractAddress, {
get_system_status: {},
})
}
}
export interface ValenceServiceRebalancerInterface
extends ValenceServiceRebalancerReadOnlyInterface {
contractAddress: string
sender: string
systemRebalance: (
{
limit,
}: {
limit?: number
},
fee?: number | StdFee | 'auto',
memo?: string,
_funds?: Coin[]
) => Promise<ExecuteResult>
register: (
{
data,
registerFor,
}: {
data?: RebalancerData
registerFor: string
},
fee?: number | StdFee | 'auto',
memo?: string,
_funds?: Coin[]
) => Promise<ExecuteResult>
deregister: (
{
deregisterFor,
}: {
deregisterFor: string
},
fee?: number | StdFee | 'auto',
memo?: string,
_funds?: Coin[]
) => Promise<ExecuteResult>
update: (
{
data,
updateFor,
}: {
data: RebalancerUpdateData
updateFor: string
},
fee?: number | StdFee | 'auto',
memo?: string,
_funds?: Coin[]
) => Promise<ExecuteResult>
pause: (
{
pauseFor,
sender,
}: {
pauseFor: string
sender: string
},
fee?: number | StdFee | 'auto',
memo?: string,
_funds?: Coin[]
) => Promise<ExecuteResult>
resume: (
{
resumeFor,
sender,
}: {
resumeFor: string
sender: string
},
fee?: number | StdFee | 'auto',
memo?: string,
_funds?: Coin[]
) => Promise<ExecuteResult>
}
export class ValenceServiceRebalancerClient
extends ValenceServiceRebalancerQueryClient
implements ValenceServiceRebalancerInterface
{
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.systemRebalance = this.systemRebalance.bind(this)
this.register = this.register.bind(this)
this.deregister = this.deregister.bind(this)
this.update = this.update.bind(this)
this.pause = this.pause.bind(this)
this.resume = this.resume.bind(this)
}

systemRebalance = async (
{
limit,
}: {
limit?: number
},
fee: number | StdFee | 'auto' = 'auto',
memo?: string,
_funds?: Coin[]
): Promise<ExecuteResult> => {
return await this.client.execute(
this.sender,
this.contractAddress,
{
system_rebalance: {
limit,
},
},
fee,
memo,
_funds
)
}
register = async (
{
data,
registerFor,
}: {
data?: RebalancerData
registerFor: string
},
fee: number | StdFee | 'auto' = 'auto',
memo?: string,
_funds?: Coin[]
): Promise<ExecuteResult> => {
return await this.client.execute(
this.sender,
this.contractAddress,
{
register: {
data,
register_for: registerFor,
},
},
fee,
memo,
_funds
)
}
deregister = async (
{
deregisterFor,
}: {
deregisterFor: string
},
fee: number | StdFee | 'auto' = 'auto',
memo?: string,
_funds?: Coin[]
): Promise<ExecuteResult> => {
return await this.client.execute(
this.sender,
this.contractAddress,
{
deregister: {
deregister_for: deregisterFor,
},
},
fee,
memo,
_funds
)
}
update = async (
{
data,
updateFor,
}: {
data: RebalancerUpdateData
updateFor: string
},
fee: number | StdFee | 'auto' = 'auto',
memo?: string,
_funds?: Coin[]
): Promise<ExecuteResult> => {
return await this.client.execute(
this.sender,
this.contractAddress,
{
update: {
data,
update_for: updateFor,
},
},
fee,
memo,
_funds
)
}
pause = async (
{
pauseFor,
sender,
}: {
pauseFor: string
sender: string
},
fee: number | StdFee | 'auto' = 'auto',
memo?: string,
_funds?: Coin[]
): Promise<ExecuteResult> => {
return await this.client.execute(
this.sender,
this.contractAddress,
{
pause: {
pause_for: pauseFor,
sender,
},
},
fee,
memo,
_funds
)
}
resume = async (
{
resumeFor,
sender,
}: {
resumeFor: string
sender: string
},
fee: number | StdFee | 'auto' = 'auto',
memo?: string,
_funds?: Coin[]
): Promise<ExecuteResult> => {
return await this.client.execute(
this.sender,
this.contractAddress,
{
resume: {
resume_for: resumeFor,
sender,
},
},
fee,
memo,
_funds
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* This file was automatically generated by @cosmwasm/[email protected].
* 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 { selectorFamily } from 'recoil'

import { ValenceServiceRebalancerQueryClient } from '@dao-dao/state/contracts/ValenceServiceRebalancer'
import { WithChainId } from '@dao-dao/types'
import {
RebalancerConfig,
SystemRebalanceStatus,
} from '@dao-dao/types/contracts/ValenceServiceRebalancer'

import { cosmWasmClientForChainSelector } from '../chain'

type QueryClientParams = WithChainId<{
contractAddress: string
}>

export const queryClient = selectorFamily<
ValenceServiceRebalancerQueryClient,
QueryClientParams
>({
key: 'valenceServiceRebalancerQueryClient',
get:
({ contractAddress, chainId }) =>
({ get }) => {
const client = get(cosmWasmClientForChainSelector(chainId))
return new ValenceServiceRebalancerQueryClient(client, contractAddress)
},
dangerouslyAllowMutability: true,
})

export const getConfigSelector = selectorFamily<
RebalancerConfig,
QueryClientParams & {
params: Parameters<ValenceServiceRebalancerQueryClient['getConfig']>
}
>({
key: 'valenceServiceRebalancerGetConfig',
get:
({ params, ...queryClientParams }) =>
async ({ get }) => {
const client = get(queryClient(queryClientParams))
return await client.getConfig(...params)
},
})
export const getSystemStatusSelector = selectorFamily<
SystemRebalanceStatus,
QueryClientParams & {
params: Parameters<ValenceServiceRebalancerQueryClient['getSystemStatus']>
}
>({
key: 'valenceServiceRebalancerGetSystemStatus',
get:
({ params, ...queryClientParams }) =>
async ({ get }) => {
const client = get(queryClient(queryClientParams))
return await client.getSystemStatus(...params)
},
})
1 change: 1 addition & 0 deletions packages/state/recoil/selectors/contracts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ export * as PolytoneListenerSelectors from './PolytoneListener'
export * as PolytoneNoteSelectors from './PolytoneNote'
export * as PolytoneProxySelectors from './PolytoneProxy'
export * as Sg721BaseSelectors from './Sg721Base'
export * as ValenceServiceRebalancerSelectors from './ValenceServiceRebalancer'
export * as WyndexFactorySelectors from './WyndexFactory'
export * as WyndexMultiHopSelectors from './WyndexMultiHop'
Loading

0 comments on commit 33d4444

Please sign in to comment.