forked from DA0-DA0/dao-dao-ui
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Cw4Group.ts
260 lines (254 loc) · 5.37 KB
/
Cw4Group.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
import { Coin, StdFee } from '@cosmjs/amino'
import {
CosmWasmClient,
ExecuteResult,
SigningCosmWasmClient,
} from '@cosmjs/cosmwasm-stargate'
import {
AdminResponse,
HooksResponse,
ListMembersResponse,
Member,
MemberResponse,
TotalWeightResponse,
} from '@dao-dao/types/contracts/Cw4Group'
import { CHAIN_GAS_MULTIPLIER } from '@dao-dao/utils'
export interface Cw4GroupReadOnlyInterface {
contractAddress: string
admin: () => Promise<AdminResponse>
totalWeight: () => Promise<TotalWeightResponse>
listMembers: ({
limit,
startAfter,
}: {
limit?: number
startAfter?: string
}) => Promise<ListMembersResponse>
member: ({
addr,
atHeight,
}: {
addr: string
atHeight?: number
}) => Promise<MemberResponse>
hooks: () => Promise<HooksResponse>
}
export class Cw4GroupQueryClient implements Cw4GroupReadOnlyInterface {
client: CosmWasmClient
contractAddress: string
constructor(client: CosmWasmClient, contractAddress: string) {
this.client = client
this.contractAddress = contractAddress
this.admin = this.admin.bind(this)
this.totalWeight = this.totalWeight.bind(this)
this.listMembers = this.listMembers.bind(this)
this.member = this.member.bind(this)
this.hooks = this.hooks.bind(this)
}
admin = async (): Promise<AdminResponse> => {
return this.client.queryContractSmart(this.contractAddress, {
admin: {},
})
}
totalWeight = async (): Promise<TotalWeightResponse> => {
return this.client.queryContractSmart(this.contractAddress, {
total_weight: {},
})
}
listMembers = async ({
limit,
startAfter,
}: {
limit?: number
startAfter?: string
}): Promise<ListMembersResponse> => {
return this.client.queryContractSmart(this.contractAddress, {
list_members: {
limit,
start_after: startAfter,
},
})
}
member = async ({
addr,
atHeight,
}: {
addr: string
atHeight?: number
}): Promise<MemberResponse> => {
return this.client.queryContractSmart(this.contractAddress, {
member: {
addr,
at_height: atHeight,
},
})
}
hooks = async (): Promise<HooksResponse> => {
return this.client.queryContractSmart(this.contractAddress, {
hooks: {},
})
}
}
export interface Cw4GroupInterface extends Cw4GroupReadOnlyInterface {
contractAddress: string
sender: string
updateAdmin: (
{
admin,
}: {
admin?: string
},
fee?: number | StdFee | 'auto',
memo?: string,
funds?: readonly Coin[]
) => Promise<ExecuteResult>
updateMembers: (
{
add,
remove,
}: {
add: Member[]
remove: string[]
},
fee?: number | StdFee | 'auto',
memo?: string,
funds?: readonly Coin[]
) => Promise<ExecuteResult>
addHook: (
{
addr,
}: {
addr: string
},
fee?: number | StdFee | 'auto',
memo?: string,
funds?: readonly Coin[]
) => Promise<ExecuteResult>
removeHook: (
{
addr,
}: {
addr: string
},
fee?: number | StdFee | 'auto',
memo?: string,
funds?: readonly Coin[]
) => Promise<ExecuteResult>
}
export class Cw4GroupClient
extends Cw4GroupQueryClient
implements Cw4GroupInterface
{
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.updateAdmin = this.updateAdmin.bind(this)
this.updateMembers = this.updateMembers.bind(this)
this.addHook = this.addHook.bind(this)
this.removeHook = this.removeHook.bind(this)
}
updateAdmin = async (
{
admin,
}: {
admin?: string
},
fee: number | StdFee | 'auto' = CHAIN_GAS_MULTIPLIER,
memo?: string,
funds?: readonly Coin[]
): Promise<ExecuteResult> => {
return await this.client.execute(
this.sender,
this.contractAddress,
{
update_admin: {
admin,
},
},
fee,
memo,
funds
)
}
updateMembers = async (
{
add,
remove,
}: {
add: Member[]
remove: string[]
},
fee: number | StdFee | 'auto' = CHAIN_GAS_MULTIPLIER,
memo?: string,
funds?: readonly Coin[]
): Promise<ExecuteResult> => {
return await this.client.execute(
this.sender,
this.contractAddress,
{
update_members: {
add,
remove,
},
},
fee,
memo,
funds
)
}
addHook = async (
{
addr,
}: {
addr: string
},
fee: number | StdFee | 'auto' = CHAIN_GAS_MULTIPLIER,
memo?: string,
funds?: readonly Coin[]
): Promise<ExecuteResult> => {
return await this.client.execute(
this.sender,
this.contractAddress,
{
add_hook: {
addr,
},
},
fee,
memo,
funds
)
}
removeHook = async (
{
addr,
}: {
addr: string
},
fee: number | StdFee | 'auto' = CHAIN_GAS_MULTIPLIER,
memo?: string,
funds?: readonly Coin[]
): Promise<ExecuteResult> => {
return await this.client.execute(
this.sender,
this.contractAddress,
{
remove_hook: {
addr,
},
},
fee,
memo,
funds
)
}
}