-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load rebalancer config from chain address and load valence accounts o…
…n page instead of in static props.
- Loading branch information
Showing
8 changed files
with
460 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
packages/state/recoil/selectors/contracts/ValenceServiceRebalancer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.