forked from DA0-DA0/dao-dao-ui
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CwPayrollFactory.ts
366 lines (360 loc) · 8.53 KB
/
CwPayrollFactory.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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
import { Coin, StdFee } from '@cosmjs/amino'
import {
CosmWasmClient,
ExecuteResult,
SigningCosmWasmClient,
} from '@cosmjs/cosmwasm-stargate'
import { Binary, Uint128, Uint64 } from '@dao-dao/types'
import { ArrayOfVestingContract } from '@dao-dao/types/contracts/CwPayrollFactory'
import {
InstantiateMsg,
OwnershipForAddr,
} from '@dao-dao/types/contracts/CwVesting'
import { CHAIN_GAS_MULTIPLIER } from '@dao-dao/utils'
export interface CwPayrollFactoryReadOnlyInterface {
contractAddress: string
listVestingContracts: ({
limit,
startAfter,
}: {
limit?: number
startAfter?: string
}) => Promise<ArrayOfVestingContract>
listVestingContractsReverse: ({
limit,
startBefore,
}: {
limit?: number
startBefore?: string
}) => Promise<ArrayOfVestingContract>
listVestingContractsByInstantiator: ({
instantiator,
limit,
startAfter,
}: {
instantiator: string
limit?: number
startAfter?: string
}) => Promise<ArrayOfVestingContract>
listVestingContractsByInstantiatorReverse: ({
instantiator,
limit,
startBefore,
}: {
instantiator: string
limit?: number
startBefore?: string
}) => Promise<ArrayOfVestingContract>
listVestingContractsByRecipient: ({
limit,
recipient,
startAfter,
}: {
limit?: number
recipient: string
startAfter?: string
}) => Promise<ArrayOfVestingContract>
listVestingContractsByRecipientReverse: ({
limit,
recipient,
startBefore,
}: {
limit?: number
recipient: string
startBefore?: string
}) => Promise<ArrayOfVestingContract>
ownership: () => Promise<OwnershipForAddr>
codeId: () => Promise<Uint64>
}
export class CwPayrollFactoryQueryClient
implements CwPayrollFactoryReadOnlyInterface
{
client: CosmWasmClient
contractAddress: string
constructor(client: CosmWasmClient, contractAddress: string) {
this.client = client
this.contractAddress = contractAddress
this.listVestingContracts = this.listVestingContracts.bind(this)
this.listVestingContractsReverse =
this.listVestingContractsReverse.bind(this)
this.listVestingContractsByInstantiator =
this.listVestingContractsByInstantiator.bind(this)
this.listVestingContractsByInstantiatorReverse =
this.listVestingContractsByInstantiatorReverse.bind(this)
this.listVestingContractsByRecipient =
this.listVestingContractsByRecipient.bind(this)
this.listVestingContractsByRecipientReverse =
this.listVestingContractsByRecipientReverse.bind(this)
this.ownership = this.ownership.bind(this)
this.codeId = this.codeId.bind(this)
}
listVestingContracts = async ({
limit,
startAfter,
}: {
limit?: number
startAfter?: string
}): Promise<ArrayOfVestingContract> => {
return this.client.queryContractSmart(this.contractAddress, {
list_vesting_contracts: {
limit,
start_after: startAfter,
},
})
}
listVestingContractsReverse = async ({
limit,
startBefore,
}: {
limit?: number
startBefore?: string
}): Promise<ArrayOfVestingContract> => {
return this.client.queryContractSmart(this.contractAddress, {
list_vesting_contracts_reverse: {
limit,
start_before: startBefore,
},
})
}
listVestingContractsByInstantiator = async ({
instantiator,
limit,
startAfter,
}: {
instantiator: string
limit?: number
startAfter?: string
}): Promise<ArrayOfVestingContract> => {
return this.client.queryContractSmart(this.contractAddress, {
list_vesting_contracts_by_instantiator: {
instantiator,
limit,
start_after: startAfter,
},
})
}
listVestingContractsByInstantiatorReverse = async ({
instantiator,
limit,
startBefore,
}: {
instantiator: string
limit?: number
startBefore?: string
}): Promise<ArrayOfVestingContract> => {
return this.client.queryContractSmart(this.contractAddress, {
list_vesting_contracts_by_instantiator_reverse: {
instantiator,
limit,
start_before: startBefore,
},
})
}
listVestingContractsByRecipient = async ({
limit,
recipient,
startAfter,
}: {
limit?: number
recipient: string
startAfter?: string
}): Promise<ArrayOfVestingContract> => {
return this.client.queryContractSmart(this.contractAddress, {
list_vesting_contracts_by_recipient: {
limit,
recipient,
start_after: startAfter,
},
})
}
listVestingContractsByRecipientReverse = async ({
limit,
recipient,
startBefore,
}: {
limit?: number
recipient: string
startBefore?: string
}): Promise<ArrayOfVestingContract> => {
return this.client.queryContractSmart(this.contractAddress, {
list_vesting_contracts_by_recipient_reverse: {
limit,
recipient,
start_before: startBefore,
},
})
}
ownership = async (): Promise<OwnershipForAddr> => {
return this.client.queryContractSmart(this.contractAddress, {
ownership: {},
})
}
codeId = async (): Promise<Uint64> => {
return this.client.queryContractSmart(this.contractAddress, {
code_id: {},
})
}
}
export interface CwPayrollFactoryInterface
extends CwPayrollFactoryReadOnlyInterface {
contractAddress: string
sender: string
receive: (
{
amount,
msg,
sender,
}: {
amount: Uint128
msg: Binary
sender: string
},
fee?: number | StdFee | 'auto',
memo?: string,
funds?: Coin[]
) => Promise<ExecuteResult>
instantiateNativePayrollContract: (
{
instantiateMsg,
label,
}: {
instantiateMsg: InstantiateMsg
label: string
},
fee?: number | StdFee | 'auto',
memo?: string,
funds?: Coin[]
) => Promise<ExecuteResult>
updateCodeId: (
{
vestingCodeId,
}: {
vestingCodeId: number
},
fee?: number | StdFee | 'auto',
memo?: string,
funds?: Coin[]
) => Promise<ExecuteResult>
updateOwnership: (
fee?: number | StdFee | 'auto',
memo?: string,
funds?: Coin[]
) => Promise<ExecuteResult>
}
export class CwPayrollFactoryClient
extends CwPayrollFactoryQueryClient
implements CwPayrollFactoryInterface
{
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.receive = this.receive.bind(this)
this.instantiateNativePayrollContract =
this.instantiateNativePayrollContract.bind(this)
this.updateCodeId = this.updateCodeId.bind(this)
this.updateOwnership = this.updateOwnership.bind(this)
}
receive = async (
{
amount,
msg,
sender,
}: {
amount: Uint128
msg: Binary
sender: string
},
fee: number | StdFee | 'auto' = CHAIN_GAS_MULTIPLIER,
memo?: string,
funds?: Coin[]
): Promise<ExecuteResult> => {
return await this.client.execute(
this.sender,
this.contractAddress,
{
receive: {
amount,
msg,
sender,
},
},
fee,
memo,
funds
)
}
instantiateNativePayrollContract = async (
{
instantiateMsg,
label,
}: {
instantiateMsg: InstantiateMsg
label: string
},
fee: number | StdFee | 'auto' = CHAIN_GAS_MULTIPLIER,
memo?: string,
funds?: Coin[]
): Promise<ExecuteResult> => {
return await this.client.execute(
this.sender,
this.contractAddress,
{
instantiate_native_payroll_contract: {
instantiate_msg: instantiateMsg,
label,
},
},
fee,
memo,
funds
)
}
updateCodeId = async (
{
vestingCodeId,
}: {
vestingCodeId: number
},
fee: number | StdFee | 'auto' = CHAIN_GAS_MULTIPLIER,
memo?: string,
funds?: Coin[]
): Promise<ExecuteResult> => {
return await this.client.execute(
this.sender,
this.contractAddress,
{
update_code_id: {
vesting_code_id: vestingCodeId,
},
},
fee,
memo,
funds
)
}
updateOwnership = async (
fee: number | StdFee | 'auto' = CHAIN_GAS_MULTIPLIER,
memo?: string,
funds?: Coin[]
): Promise<ExecuteResult> => {
return await this.client.execute(
this.sender,
this.contractAddress,
{
update_ownership: {},
},
fee,
memo,
funds
)
}
}