@dorafactory/maci-sdk 0.1.2 → 0.1.3-pre.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2083 -1037
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2083 -1037
- package/dist/index.mjs.map +1 -1
- package/dist/libs/const.d.ts +1 -2
- package/dist/libs/contract/config.d.ts +12 -0
- package/dist/libs/contract/contract.d.ts +53 -2
- package/dist/libs/contract/ts/ApiMaci.client.d.ts +170 -0
- package/dist/libs/contract/ts/ApiMaci.types.d.ts +187 -0
- package/dist/libs/contract/ts/ApiSaas.client.d.ts +122 -0
- package/dist/libs/contract/ts/ApiSaas.types.d.ts +102 -0
- package/dist/libs/maci/maci.d.ts +24 -0
- package/dist/maci.d.ts +26 -2
- package/dist/types/index.d.ts +2 -2
- package/package.json +1 -1
- package/src/libs/const.ts +5 -6
- package/src/libs/contract/config.ts +36 -0
- package/src/libs/contract/contract.ts +477 -3
- package/src/libs/contract/ts/ApiMaci.client.ts +459 -0
- package/src/libs/contract/ts/ApiMaci.types.ts +188 -0
- package/src/libs/contract/ts/ApiSaas.client.ts +307 -0
- package/src/libs/contract/ts/ApiSaas.types.ts +103 -0
- package/src/libs/maci/maci.ts +153 -0
- package/src/maci.ts +66 -4
- package/src/types/index.ts +2 -2
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated by @cosmwasm/ts-codegen@1.11.1.
|
|
3
|
+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
|
4
|
+
* and run the @cosmwasm/ts-codegen generate command to regenerate this file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { CosmWasmClient, SigningCosmWasmClient, ExecuteResult } from "@cosmjs/cosmwasm-stargate";
|
|
8
|
+
import { Coin, StdFee } from "@cosmjs/amino";
|
|
9
|
+
import { Addr, InstantiateMsg, ExecuteMsg, Uint128, Uint256, Timestamp, Uint64, PubKey, RoundInfo, QueryMsg, Config, Boolean, ArrayOfOperatorInfo, OperatorInfo } from "./ApiSaas.types";
|
|
10
|
+
export interface ApiSaasReadOnlyInterface {
|
|
11
|
+
contractAddress: string;
|
|
12
|
+
config: () => Promise<Config>;
|
|
13
|
+
operators: () => Promise<ArrayOfOperatorInfo>;
|
|
14
|
+
isOperator: ({
|
|
15
|
+
address
|
|
16
|
+
}: {
|
|
17
|
+
address: Addr;
|
|
18
|
+
}) => Promise<Boolean>;
|
|
19
|
+
balance: () => Promise<Uint128>;
|
|
20
|
+
maciCodeId: () => Promise<Uint64>;
|
|
21
|
+
treasuryManager: () => Promise<Addr>;
|
|
22
|
+
}
|
|
23
|
+
export class ApiSaasQueryClient implements ApiSaasReadOnlyInterface {
|
|
24
|
+
client: CosmWasmClient;
|
|
25
|
+
contractAddress: string;
|
|
26
|
+
constructor(client: CosmWasmClient, contractAddress: string) {
|
|
27
|
+
this.client = client;
|
|
28
|
+
this.contractAddress = contractAddress;
|
|
29
|
+
this.config = this.config.bind(this);
|
|
30
|
+
this.operators = this.operators.bind(this);
|
|
31
|
+
this.isOperator = this.isOperator.bind(this);
|
|
32
|
+
this.balance = this.balance.bind(this);
|
|
33
|
+
this.maciCodeId = this.maciCodeId.bind(this);
|
|
34
|
+
this.treasuryManager = this.treasuryManager.bind(this);
|
|
35
|
+
}
|
|
36
|
+
config = async (): Promise<Config> => {
|
|
37
|
+
return this.client.queryContractSmart(this.contractAddress, {
|
|
38
|
+
config: {}
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
operators = async (): Promise<ArrayOfOperatorInfo> => {
|
|
42
|
+
return this.client.queryContractSmart(this.contractAddress, {
|
|
43
|
+
operators: {}
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
isOperator = async ({
|
|
47
|
+
address
|
|
48
|
+
}: {
|
|
49
|
+
address: Addr;
|
|
50
|
+
}): Promise<Boolean> => {
|
|
51
|
+
return this.client.queryContractSmart(this.contractAddress, {
|
|
52
|
+
is_operator: {
|
|
53
|
+
address
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
balance = async (): Promise<Uint128> => {
|
|
58
|
+
return this.client.queryContractSmart(this.contractAddress, {
|
|
59
|
+
balance: {}
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
maciCodeId = async (): Promise<Uint64> => {
|
|
63
|
+
return this.client.queryContractSmart(this.contractAddress, {
|
|
64
|
+
maci_code_id: {}
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
treasuryManager = async (): Promise<Addr> => {
|
|
68
|
+
return this.client.queryContractSmart(this.contractAddress, {
|
|
69
|
+
treasury_manager: {}
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export interface ApiSaasInterface extends ApiSaasReadOnlyInterface {
|
|
74
|
+
contractAddress: string;
|
|
75
|
+
sender: string;
|
|
76
|
+
updateConfig: ({
|
|
77
|
+
admin,
|
|
78
|
+
denom
|
|
79
|
+
}: {
|
|
80
|
+
admin?: Addr;
|
|
81
|
+
denom?: string;
|
|
82
|
+
}, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
|
|
83
|
+
updateMaciCodeId: ({
|
|
84
|
+
codeId
|
|
85
|
+
}: {
|
|
86
|
+
codeId: number;
|
|
87
|
+
}, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
|
|
88
|
+
updateAmaciRegistryContract: ({
|
|
89
|
+
registryContract
|
|
90
|
+
}: {
|
|
91
|
+
registryContract: Addr;
|
|
92
|
+
}, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
|
|
93
|
+
addOperator: ({
|
|
94
|
+
operator
|
|
95
|
+
}: {
|
|
96
|
+
operator: Addr;
|
|
97
|
+
}, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
|
|
98
|
+
removeOperator: ({
|
|
99
|
+
operator
|
|
100
|
+
}: {
|
|
101
|
+
operator: Addr;
|
|
102
|
+
}, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
|
|
103
|
+
deposit: (fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
|
|
104
|
+
withdraw: ({
|
|
105
|
+
amount,
|
|
106
|
+
recipient
|
|
107
|
+
}: {
|
|
108
|
+
amount: Uint128;
|
|
109
|
+
recipient?: Addr;
|
|
110
|
+
}, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
|
|
111
|
+
createApiMaciRound: ({
|
|
112
|
+
certificationSystem,
|
|
113
|
+
circuitType,
|
|
114
|
+
coordinator,
|
|
115
|
+
endTime,
|
|
116
|
+
maxVoters,
|
|
117
|
+
roundInfo,
|
|
118
|
+
startTime,
|
|
119
|
+
voteOptionMap,
|
|
120
|
+
whitelistBackendPubkey
|
|
121
|
+
}: {
|
|
122
|
+
certificationSystem: Uint256;
|
|
123
|
+
circuitType: Uint256;
|
|
124
|
+
coordinator: PubKey;
|
|
125
|
+
endTime: Timestamp;
|
|
126
|
+
maxVoters: number;
|
|
127
|
+
roundInfo: RoundInfo;
|
|
128
|
+
startTime: Timestamp;
|
|
129
|
+
voteOptionMap: string[];
|
|
130
|
+
whitelistBackendPubkey: string;
|
|
131
|
+
}, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
|
|
132
|
+
setRoundInfo: ({
|
|
133
|
+
contractAddr,
|
|
134
|
+
roundInfo
|
|
135
|
+
}: {
|
|
136
|
+
contractAddr: string;
|
|
137
|
+
roundInfo: RoundInfo;
|
|
138
|
+
}, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
|
|
139
|
+
setVoteOptionsMap: ({
|
|
140
|
+
contractAddr,
|
|
141
|
+
voteOptionMap
|
|
142
|
+
}: {
|
|
143
|
+
contractAddr: string;
|
|
144
|
+
voteOptionMap: string[];
|
|
145
|
+
}, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
|
|
146
|
+
}
|
|
147
|
+
export class ApiSaasClient extends ApiSaasQueryClient implements ApiSaasInterface {
|
|
148
|
+
client: SigningCosmWasmClient;
|
|
149
|
+
sender: string;
|
|
150
|
+
contractAddress: string;
|
|
151
|
+
constructor(client: SigningCosmWasmClient, sender: string, contractAddress: string) {
|
|
152
|
+
super(client, contractAddress);
|
|
153
|
+
this.client = client;
|
|
154
|
+
this.sender = sender;
|
|
155
|
+
this.contractAddress = contractAddress;
|
|
156
|
+
this.updateConfig = this.updateConfig.bind(this);
|
|
157
|
+
this.updateMaciCodeId = this.updateMaciCodeId.bind(this);
|
|
158
|
+
this.updateAmaciRegistryContract = this.updateAmaciRegistryContract.bind(this);
|
|
159
|
+
this.addOperator = this.addOperator.bind(this);
|
|
160
|
+
this.removeOperator = this.removeOperator.bind(this);
|
|
161
|
+
this.deposit = this.deposit.bind(this);
|
|
162
|
+
this.withdraw = this.withdraw.bind(this);
|
|
163
|
+
this.createApiMaciRound = this.createApiMaciRound.bind(this);
|
|
164
|
+
this.setRoundInfo = this.setRoundInfo.bind(this);
|
|
165
|
+
this.setVoteOptionsMap = this.setVoteOptionsMap.bind(this);
|
|
166
|
+
}
|
|
167
|
+
updateConfig = async ({
|
|
168
|
+
admin,
|
|
169
|
+
denom
|
|
170
|
+
}: {
|
|
171
|
+
admin?: Addr;
|
|
172
|
+
denom?: string;
|
|
173
|
+
}, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
|
|
174
|
+
return await this.client.execute(this.sender, this.contractAddress, {
|
|
175
|
+
update_config: {
|
|
176
|
+
admin,
|
|
177
|
+
denom
|
|
178
|
+
}
|
|
179
|
+
}, fee, memo, _funds);
|
|
180
|
+
};
|
|
181
|
+
updateMaciCodeId = async ({
|
|
182
|
+
codeId
|
|
183
|
+
}: {
|
|
184
|
+
codeId: number;
|
|
185
|
+
}, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
|
|
186
|
+
return await this.client.execute(this.sender, this.contractAddress, {
|
|
187
|
+
update_maci_code_id: {
|
|
188
|
+
code_id: codeId
|
|
189
|
+
}
|
|
190
|
+
}, fee, memo, _funds);
|
|
191
|
+
};
|
|
192
|
+
updateAmaciRegistryContract = async ({
|
|
193
|
+
registryContract
|
|
194
|
+
}: {
|
|
195
|
+
registryContract: Addr;
|
|
196
|
+
}, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
|
|
197
|
+
return await this.client.execute(this.sender, this.contractAddress, {
|
|
198
|
+
update_amaci_registry_contract: {
|
|
199
|
+
registry_contract: registryContract
|
|
200
|
+
}
|
|
201
|
+
}, fee, memo, _funds);
|
|
202
|
+
};
|
|
203
|
+
addOperator = async ({
|
|
204
|
+
operator
|
|
205
|
+
}: {
|
|
206
|
+
operator: Addr;
|
|
207
|
+
}, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
|
|
208
|
+
return await this.client.execute(this.sender, this.contractAddress, {
|
|
209
|
+
add_operator: {
|
|
210
|
+
operator
|
|
211
|
+
}
|
|
212
|
+
}, fee, memo, _funds);
|
|
213
|
+
};
|
|
214
|
+
removeOperator = async ({
|
|
215
|
+
operator
|
|
216
|
+
}: {
|
|
217
|
+
operator: Addr;
|
|
218
|
+
}, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
|
|
219
|
+
return await this.client.execute(this.sender, this.contractAddress, {
|
|
220
|
+
remove_operator: {
|
|
221
|
+
operator
|
|
222
|
+
}
|
|
223
|
+
}, fee, memo, _funds);
|
|
224
|
+
};
|
|
225
|
+
deposit = async (fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
|
|
226
|
+
return await this.client.execute(this.sender, this.contractAddress, {
|
|
227
|
+
deposit: {}
|
|
228
|
+
}, fee, memo, _funds);
|
|
229
|
+
};
|
|
230
|
+
withdraw = async ({
|
|
231
|
+
amount,
|
|
232
|
+
recipient
|
|
233
|
+
}: {
|
|
234
|
+
amount: Uint128;
|
|
235
|
+
recipient?: Addr;
|
|
236
|
+
}, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
|
|
237
|
+
return await this.client.execute(this.sender, this.contractAddress, {
|
|
238
|
+
withdraw: {
|
|
239
|
+
amount,
|
|
240
|
+
recipient
|
|
241
|
+
}
|
|
242
|
+
}, fee, memo, _funds);
|
|
243
|
+
};
|
|
244
|
+
createApiMaciRound = async ({
|
|
245
|
+
certificationSystem,
|
|
246
|
+
circuitType,
|
|
247
|
+
coordinator,
|
|
248
|
+
endTime,
|
|
249
|
+
maxVoters,
|
|
250
|
+
roundInfo,
|
|
251
|
+
startTime,
|
|
252
|
+
voteOptionMap,
|
|
253
|
+
whitelistBackendPubkey
|
|
254
|
+
}: {
|
|
255
|
+
certificationSystem: Uint256;
|
|
256
|
+
circuitType: Uint256;
|
|
257
|
+
coordinator: PubKey;
|
|
258
|
+
endTime: Timestamp;
|
|
259
|
+
maxVoters: number;
|
|
260
|
+
roundInfo: RoundInfo;
|
|
261
|
+
startTime: Timestamp;
|
|
262
|
+
voteOptionMap: string[];
|
|
263
|
+
whitelistBackendPubkey: string;
|
|
264
|
+
}, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
|
|
265
|
+
return await this.client.execute(this.sender, this.contractAddress, {
|
|
266
|
+
create_api_maci_round: {
|
|
267
|
+
certification_system: certificationSystem,
|
|
268
|
+
circuit_type: circuitType,
|
|
269
|
+
coordinator,
|
|
270
|
+
end_time: endTime,
|
|
271
|
+
max_voters: maxVoters,
|
|
272
|
+
round_info: roundInfo,
|
|
273
|
+
start_time: startTime,
|
|
274
|
+
vote_option_map: voteOptionMap,
|
|
275
|
+
whitelist_backend_pubkey: whitelistBackendPubkey
|
|
276
|
+
}
|
|
277
|
+
}, fee, memo, _funds);
|
|
278
|
+
};
|
|
279
|
+
setRoundInfo = async ({
|
|
280
|
+
contractAddr,
|
|
281
|
+
roundInfo
|
|
282
|
+
}: {
|
|
283
|
+
contractAddr: string;
|
|
284
|
+
roundInfo: RoundInfo;
|
|
285
|
+
}, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
|
|
286
|
+
return await this.client.execute(this.sender, this.contractAddress, {
|
|
287
|
+
set_round_info: {
|
|
288
|
+
contract_addr: contractAddr,
|
|
289
|
+
round_info: roundInfo
|
|
290
|
+
}
|
|
291
|
+
}, fee, memo, _funds);
|
|
292
|
+
};
|
|
293
|
+
setVoteOptionsMap = async ({
|
|
294
|
+
contractAddr,
|
|
295
|
+
voteOptionMap
|
|
296
|
+
}: {
|
|
297
|
+
contractAddr: string;
|
|
298
|
+
voteOptionMap: string[];
|
|
299
|
+
}, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
|
|
300
|
+
return await this.client.execute(this.sender, this.contractAddress, {
|
|
301
|
+
set_vote_options_map: {
|
|
302
|
+
contract_addr: contractAddr,
|
|
303
|
+
vote_option_map: voteOptionMap
|
|
304
|
+
}
|
|
305
|
+
}, fee, memo, _funds);
|
|
306
|
+
};
|
|
307
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated by @cosmwasm/ts-codegen@1.11.1.
|
|
3
|
+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
|
4
|
+
* and run the @cosmwasm/ts-codegen generate command to regenerate this file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export type Addr = string;
|
|
8
|
+
export interface InstantiateMsg {
|
|
9
|
+
admin: Addr;
|
|
10
|
+
denom: string;
|
|
11
|
+
maci_code_id: number;
|
|
12
|
+
registry_contract: Addr;
|
|
13
|
+
treasury_manager: Addr;
|
|
14
|
+
}
|
|
15
|
+
export type ExecuteMsg = {
|
|
16
|
+
update_config: {
|
|
17
|
+
admin?: Addr | null;
|
|
18
|
+
denom?: string | null;
|
|
19
|
+
};
|
|
20
|
+
} | {
|
|
21
|
+
update_maci_code_id: {
|
|
22
|
+
code_id: number;
|
|
23
|
+
};
|
|
24
|
+
} | {
|
|
25
|
+
update_amaci_registry_contract: {
|
|
26
|
+
registry_contract: Addr;
|
|
27
|
+
};
|
|
28
|
+
} | {
|
|
29
|
+
add_operator: {
|
|
30
|
+
operator: Addr;
|
|
31
|
+
};
|
|
32
|
+
} | {
|
|
33
|
+
remove_operator: {
|
|
34
|
+
operator: Addr;
|
|
35
|
+
};
|
|
36
|
+
} | {
|
|
37
|
+
deposit: {};
|
|
38
|
+
} | {
|
|
39
|
+
withdraw: {
|
|
40
|
+
amount: Uint128;
|
|
41
|
+
recipient?: Addr | null;
|
|
42
|
+
};
|
|
43
|
+
} | {
|
|
44
|
+
create_api_maci_round: {
|
|
45
|
+
certification_system: Uint256;
|
|
46
|
+
circuit_type: Uint256;
|
|
47
|
+
coordinator: PubKey;
|
|
48
|
+
end_time: Timestamp;
|
|
49
|
+
max_voters: number;
|
|
50
|
+
round_info: RoundInfo;
|
|
51
|
+
start_time: Timestamp;
|
|
52
|
+
vote_option_map: string[];
|
|
53
|
+
whitelist_backend_pubkey: string;
|
|
54
|
+
};
|
|
55
|
+
} | {
|
|
56
|
+
set_round_info: {
|
|
57
|
+
contract_addr: string;
|
|
58
|
+
round_info: RoundInfo;
|
|
59
|
+
};
|
|
60
|
+
} | {
|
|
61
|
+
set_vote_options_map: {
|
|
62
|
+
contract_addr: string;
|
|
63
|
+
vote_option_map: string[];
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
export type Uint128 = string;
|
|
67
|
+
export type Uint256 = string;
|
|
68
|
+
export type Timestamp = Uint64;
|
|
69
|
+
export type Uint64 = string;
|
|
70
|
+
export interface PubKey {
|
|
71
|
+
x: Uint256;
|
|
72
|
+
y: Uint256;
|
|
73
|
+
}
|
|
74
|
+
export interface RoundInfo {
|
|
75
|
+
description: string;
|
|
76
|
+
link: string;
|
|
77
|
+
title: string;
|
|
78
|
+
}
|
|
79
|
+
export type QueryMsg = {
|
|
80
|
+
config: {};
|
|
81
|
+
} | {
|
|
82
|
+
operators: {};
|
|
83
|
+
} | {
|
|
84
|
+
is_operator: {
|
|
85
|
+
address: Addr;
|
|
86
|
+
};
|
|
87
|
+
} | {
|
|
88
|
+
balance: {};
|
|
89
|
+
} | {
|
|
90
|
+
maci_code_id: {};
|
|
91
|
+
} | {
|
|
92
|
+
treasury_manager: {};
|
|
93
|
+
};
|
|
94
|
+
export interface Config {
|
|
95
|
+
admin: Addr;
|
|
96
|
+
denom: string;
|
|
97
|
+
}
|
|
98
|
+
export type Boolean = boolean;
|
|
99
|
+
export type ArrayOfOperatorInfo = OperatorInfo[];
|
|
100
|
+
export interface OperatorInfo {
|
|
101
|
+
added_at: Timestamp;
|
|
102
|
+
address: Addr;
|
|
103
|
+
}
|
package/src/libs/maci/maci.ts
CHANGED
|
@@ -514,6 +514,60 @@ export class MACI {
|
|
|
514
514
|
}
|
|
515
515
|
}
|
|
516
516
|
|
|
517
|
+
async rawSignup({
|
|
518
|
+
signer,
|
|
519
|
+
address,
|
|
520
|
+
contractAddress,
|
|
521
|
+
pubKey,
|
|
522
|
+
oracleCertificate,
|
|
523
|
+
gasStation = false,
|
|
524
|
+
fee,
|
|
525
|
+
}: {
|
|
526
|
+
signer: OfflineSigner;
|
|
527
|
+
address?: string;
|
|
528
|
+
contractAddress: string;
|
|
529
|
+
pubKey: PubKey;
|
|
530
|
+
oracleCertificate?: {
|
|
531
|
+
amount: string;
|
|
532
|
+
signature: string;
|
|
533
|
+
};
|
|
534
|
+
gasStation?: boolean;
|
|
535
|
+
fee?: StdFee | 'auto' | number;
|
|
536
|
+
}) {
|
|
537
|
+
try {
|
|
538
|
+
if (!address) {
|
|
539
|
+
address = (await signer.getAccounts())[0].address;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
const client = await this.contract.contractClient({
|
|
543
|
+
signer,
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
if (oracleCertificate) {
|
|
547
|
+
return await this.signupOracle({
|
|
548
|
+
client,
|
|
549
|
+
address,
|
|
550
|
+
pubKey,
|
|
551
|
+
contractAddress,
|
|
552
|
+
oracleCertificate,
|
|
553
|
+
gasStation,
|
|
554
|
+
fee,
|
|
555
|
+
});
|
|
556
|
+
} else {
|
|
557
|
+
return await this.signupSimple({
|
|
558
|
+
client,
|
|
559
|
+
address,
|
|
560
|
+
pubKey,
|
|
561
|
+
contractAddress,
|
|
562
|
+
gasStation,
|
|
563
|
+
fee,
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
} catch (error) {
|
|
567
|
+
throw Error(`Signup failed! ${error}`);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
|
|
517
571
|
private async processVoteOptions({
|
|
518
572
|
selectedOptions,
|
|
519
573
|
contractAddress,
|
|
@@ -673,6 +727,105 @@ export class MACI {
|
|
|
673
727
|
}
|
|
674
728
|
}
|
|
675
729
|
|
|
730
|
+
async rawVote({
|
|
731
|
+
signer,
|
|
732
|
+
address,
|
|
733
|
+
contractAddress,
|
|
734
|
+
pubKey,
|
|
735
|
+
payload,
|
|
736
|
+
gasStation = false,
|
|
737
|
+
fee = 1.8,
|
|
738
|
+
}: {
|
|
739
|
+
signer: OfflineSigner;
|
|
740
|
+
address?: string;
|
|
741
|
+
contractAddress: string;
|
|
742
|
+
pubKey: PubKey;
|
|
743
|
+
payload: {
|
|
744
|
+
msg: bigint[];
|
|
745
|
+
encPubkeys: PubKey;
|
|
746
|
+
}[];
|
|
747
|
+
gasStation?: boolean;
|
|
748
|
+
fee?: StdFee | 'auto' | number;
|
|
749
|
+
}) {
|
|
750
|
+
const stateIdx = await this.getStateIdxByPubKey({
|
|
751
|
+
contractAddress,
|
|
752
|
+
pubKey,
|
|
753
|
+
});
|
|
754
|
+
|
|
755
|
+
if (stateIdx === -1) {
|
|
756
|
+
throw new Error(
|
|
757
|
+
'State index is not set, Please signup or addNewKey first'
|
|
758
|
+
);
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
try {
|
|
762
|
+
const round = await this.indexer.getRoundWithFields(contractAddress, [
|
|
763
|
+
'maciType',
|
|
764
|
+
'voiceCreditAmount',
|
|
765
|
+
]);
|
|
766
|
+
|
|
767
|
+
if (isErrorResponse(round)) {
|
|
768
|
+
throw new Error(
|
|
769
|
+
`Failed to get round info: ${round.error.type} ${round.error.message}`
|
|
770
|
+
);
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
let voiceCreditBalance;
|
|
774
|
+
if (round.data.round.maciType === 'aMACI') {
|
|
775
|
+
const isWhiteListed = await this.isWhitelisted({
|
|
776
|
+
signer,
|
|
777
|
+
address,
|
|
778
|
+
contractAddress,
|
|
779
|
+
});
|
|
780
|
+
|
|
781
|
+
if (isWhiteListed) {
|
|
782
|
+
const round = await this.indexer.getRoundWithFields(contractAddress, [
|
|
783
|
+
'voiceCreditAmount',
|
|
784
|
+
]);
|
|
785
|
+
|
|
786
|
+
if (!isErrorResponse(round)) {
|
|
787
|
+
if (round.data.round.voiceCreditAmount) {
|
|
788
|
+
voiceCreditBalance = round.data.round.voiceCreditAmount;
|
|
789
|
+
} else {
|
|
790
|
+
voiceCreditBalance = '0';
|
|
791
|
+
}
|
|
792
|
+
} else {
|
|
793
|
+
throw new Error(
|
|
794
|
+
`Failed to query amaci voice credit: ${round.error.type} ${round.error.message}`
|
|
795
|
+
);
|
|
796
|
+
}
|
|
797
|
+
} else {
|
|
798
|
+
voiceCreditBalance = '0';
|
|
799
|
+
}
|
|
800
|
+
} else {
|
|
801
|
+
voiceCreditBalance = await this.getVoiceCreditBalance({
|
|
802
|
+
signer,
|
|
803
|
+
stateIdx,
|
|
804
|
+
contractAddress,
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
if (!address) {
|
|
809
|
+
address = (await signer.getAccounts())[0].address;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
const client = await this.contract.contractClient({
|
|
813
|
+
signer,
|
|
814
|
+
});
|
|
815
|
+
|
|
816
|
+
return await this.publishMessage({
|
|
817
|
+
client,
|
|
818
|
+
address,
|
|
819
|
+
payload,
|
|
820
|
+
contractAddress,
|
|
821
|
+
gasStation,
|
|
822
|
+
fee,
|
|
823
|
+
});
|
|
824
|
+
} catch (error) {
|
|
825
|
+
throw Error(`Vote failed! ${error}`);
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
|
|
676
829
|
async publishMessage({
|
|
677
830
|
client,
|
|
678
831
|
address,
|
package/src/maci.ts
CHANGED
|
@@ -35,9 +35,9 @@ export class MaciClient {
|
|
|
35
35
|
|
|
36
36
|
public registryAddress: string;
|
|
37
37
|
public saasAddress: string;
|
|
38
|
+
public apiSaasAddress: string;
|
|
38
39
|
public maciCodeId: number;
|
|
39
40
|
public oracleCodeId: number;
|
|
40
|
-
public saasOracleCodeId: number;
|
|
41
41
|
public feegrantOperator: string;
|
|
42
42
|
public whitelistBackendPubkey: string;
|
|
43
43
|
|
|
@@ -62,9 +62,9 @@ export class MaciClient {
|
|
|
62
62
|
apiEndpoint,
|
|
63
63
|
registryAddress,
|
|
64
64
|
saasAddress,
|
|
65
|
+
apiSaasAddress,
|
|
65
66
|
maciCodeId,
|
|
66
67
|
oracleCodeId,
|
|
67
|
-
saasOracleCodeId,
|
|
68
68
|
customFetch,
|
|
69
69
|
defaultOptions,
|
|
70
70
|
feegrantOperator,
|
|
@@ -83,9 +83,9 @@ export class MaciClient {
|
|
|
83
83
|
certificateApiEndpoint || defaultParams.certificateApiEndpoint;
|
|
84
84
|
this.registryAddress = registryAddress || defaultParams.registryAddress;
|
|
85
85
|
this.saasAddress = saasAddress || defaultParams.saasAddress;
|
|
86
|
+
this.apiSaasAddress = apiSaasAddress || defaultParams.apiSaasAddress;
|
|
86
87
|
this.maciCodeId = maciCodeId || defaultParams.maciCodeId;
|
|
87
88
|
this.oracleCodeId = oracleCodeId || defaultParams.oracleCodeId;
|
|
88
|
-
this.saasOracleCodeId = saasOracleCodeId || defaultParams.saasCodeId;
|
|
89
89
|
this.feegrantOperator =
|
|
90
90
|
feegrantOperator || defaultParams.oracleFeegrantOperator;
|
|
91
91
|
this.whitelistBackendPubkey =
|
|
@@ -109,9 +109,9 @@ export class MaciClient {
|
|
|
109
109
|
rpcEndpoint: this.rpcEndpoint,
|
|
110
110
|
registryAddress: this.registryAddress,
|
|
111
111
|
saasAddress: this.saasAddress,
|
|
112
|
+
apiSaasAddress: this.apiSaasAddress,
|
|
112
113
|
maciCodeId: this.maciCodeId,
|
|
113
114
|
oracleCodeId: this.oracleCodeId,
|
|
114
|
-
saasOracleCodeId: this.saasOracleCodeId,
|
|
115
115
|
feegrantOperator: this.feegrantOperator,
|
|
116
116
|
whitelistBackendPubkey: this.whitelistBackendPubkey,
|
|
117
117
|
});
|
|
@@ -681,4 +681,66 @@ export class MaciClient {
|
|
|
681
681
|
fee,
|
|
682
682
|
});
|
|
683
683
|
}
|
|
684
|
+
|
|
685
|
+
async rawSignup({
|
|
686
|
+
signer,
|
|
687
|
+
address,
|
|
688
|
+
contractAddress,
|
|
689
|
+
pubKey,
|
|
690
|
+
oracleCertificate,
|
|
691
|
+
gasStation = false,
|
|
692
|
+
fee,
|
|
693
|
+
}: {
|
|
694
|
+
signer?: OfflineSigner;
|
|
695
|
+
address?: string;
|
|
696
|
+
contractAddress: string;
|
|
697
|
+
pubKey: PubKey;
|
|
698
|
+
oracleCertificate?: {
|
|
699
|
+
amount: string;
|
|
700
|
+
signature: string;
|
|
701
|
+
};
|
|
702
|
+
gasStation?: boolean;
|
|
703
|
+
fee?: StdFee;
|
|
704
|
+
}) {
|
|
705
|
+
return await this.maci.rawSignup({
|
|
706
|
+
signer: this.getSigner(signer),
|
|
707
|
+
address,
|
|
708
|
+
contractAddress,
|
|
709
|
+
pubKey,
|
|
710
|
+
oracleCertificate,
|
|
711
|
+
gasStation,
|
|
712
|
+
fee,
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
async rawVote({
|
|
717
|
+
signer,
|
|
718
|
+
address,
|
|
719
|
+
contractAddress,
|
|
720
|
+
pubKey,
|
|
721
|
+
payload,
|
|
722
|
+
gasStation = false,
|
|
723
|
+
fee,
|
|
724
|
+
}: {
|
|
725
|
+
signer?: OfflineSigner;
|
|
726
|
+
address?: string;
|
|
727
|
+
contractAddress: string;
|
|
728
|
+
pubKey: PubKey;
|
|
729
|
+
payload: {
|
|
730
|
+
msg: bigint[];
|
|
731
|
+
encPubkeys: PubKey;
|
|
732
|
+
}[];
|
|
733
|
+
gasStation?: boolean;
|
|
734
|
+
fee?: StdFee | 'auto' | number;
|
|
735
|
+
}) {
|
|
736
|
+
return await this.maci.rawVote({
|
|
737
|
+
signer: this.getSigner(signer),
|
|
738
|
+
address,
|
|
739
|
+
contractAddress,
|
|
740
|
+
pubKey,
|
|
741
|
+
payload,
|
|
742
|
+
gasStation,
|
|
743
|
+
fee,
|
|
744
|
+
});
|
|
745
|
+
}
|
|
684
746
|
}
|
package/src/types/index.ts
CHANGED
|
@@ -31,9 +31,9 @@ export type ClientParams = {
|
|
|
31
31
|
certificateApiEndpoint?: string;
|
|
32
32
|
registryAddress?: string;
|
|
33
33
|
saasAddress?: string;
|
|
34
|
+
apiSaasAddress?: string;
|
|
34
35
|
maciCodeId?: number;
|
|
35
36
|
oracleCodeId?: number;
|
|
36
|
-
saasOracleCodeId?: number;
|
|
37
37
|
customFetch?: typeof fetch;
|
|
38
38
|
defaultOptions?: FetchOptions;
|
|
39
39
|
feegrantOperator?: string;
|
|
@@ -48,9 +48,9 @@ export type ContractParams = {
|
|
|
48
48
|
rpcEndpoint: string;
|
|
49
49
|
registryAddress: string;
|
|
50
50
|
saasAddress: string;
|
|
51
|
+
apiSaasAddress: string;
|
|
51
52
|
maciCodeId: number;
|
|
52
53
|
oracleCodeId: number;
|
|
53
|
-
saasOracleCodeId: number;
|
|
54
54
|
whitelistBackendPubkey: string;
|
|
55
55
|
feegrantOperator: string;
|
|
56
56
|
};
|