@dorafactory/maci-sdk 0.0.27 → 0.0.28
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/browser.d.mts +42 -1
- package/dist/browser.d.ts +42 -1
- package/dist/browser.js +476 -336
- package/dist/browser.js.map +1 -1
- package/dist/browser.mjs +476 -336
- package/dist/browser.mjs.map +1 -1
- package/dist/index.d.mts +42 -1
- package/dist/index.d.ts +42 -1
- package/dist/index.js +148 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +148 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/libs/const.ts +5 -2
- package/src/libs/errors/types.ts +3 -1
- package/src/libs/indexer/indexer.ts +15 -0
- package/src/libs/maci/maci.ts +29 -5
- package/src/libs/query/round.ts +112 -0
- package/src/maci.ts +15 -0
- package/src/types/index.ts +18 -0
package/dist/index.mjs
CHANGED
|
@@ -233,7 +233,9 @@ var ERROR = {
|
|
|
233
233
|
ERROR_ROUNDS_NOT_FOUND: "ERROR_ROUNDS_NOT_FOUND",
|
|
234
234
|
ERROR_TRANSACTION_NOT_FOUND: "ERROR_TRANSACTION_NOT_FOUND",
|
|
235
235
|
ERROR_TRANSACTIONS_NOT_FOUND: "ERROR_TRANSACTIONS_NOT_FOUND",
|
|
236
|
-
ERROR_SIGN_UP_EVENTS_NOT_FOUND: "ERROR_SIGN_UP_EVENTS_NOT_FOUND"
|
|
236
|
+
ERROR_SIGN_UP_EVENTS_NOT_FOUND: "ERROR_SIGN_UP_EVENTS_NOT_FOUND",
|
|
237
|
+
ERROR_INVALID_FIELDS: "ERROR_INVALID_FIELDS",
|
|
238
|
+
ERROR_CLAIM_INFOS_NOT_FOUND: "ERROR_CLAIM_INFOS_NOT_FOUND"
|
|
237
239
|
};
|
|
238
240
|
|
|
239
241
|
// src/libs/query/account.ts
|
|
@@ -413,10 +415,11 @@ function getDefaultParams(network = "mainnet") {
|
|
|
413
415
|
registryAddress: "dora1smg5qp5trjdkcekdjssqpjehdjf6n4cjss0clyvqcud3t3u3948s8rmgg4",
|
|
414
416
|
maciCodeId: 106,
|
|
415
417
|
// oracleCodeId: 116,// 9-4-3-625
|
|
416
|
-
oracleCodeId:
|
|
418
|
+
oracleCodeId: 119,
|
|
417
419
|
// 6-3-3-125
|
|
418
420
|
oracleWhitelistBackendPubkey: "A61YtCv2ibMZmDeM02nEElil8wlHx1tLKogBk5dPgf/Q",
|
|
419
|
-
oracleFeegrantOperator: "dora16s9tljk8dy9ae335yvyzlm8gvkypx9228q8pq8"
|
|
421
|
+
oracleFeegrantOperator: "dora16s9tljk8dy9ae335yvyzlm8gvkypx9228q8pq8",
|
|
422
|
+
oracleCodeIds: ["101", "116", "117", "119"]
|
|
420
423
|
};
|
|
421
424
|
case "testnet":
|
|
422
425
|
return {
|
|
@@ -429,10 +432,11 @@ function getDefaultParams(network = "mainnet") {
|
|
|
429
432
|
registryAddress: "dora13c8aecstyxrhax9znvvh5zey89edrmd2k5va57pxvpe3fxtfsfeqlhsjnd",
|
|
430
433
|
maciCodeId: 107,
|
|
431
434
|
// oracleCodeId: 113, // 9-4-3-625
|
|
432
|
-
oracleCodeId:
|
|
435
|
+
oracleCodeId: 123,
|
|
433
436
|
// 6-3-3-125
|
|
434
437
|
oracleWhitelistBackendPubkey: "AoYo/zENN/JquagPdG0/NMbWBBYxOM8BVN677mBXJKJQ",
|
|
435
|
-
oracleFeegrantOperator: "dora1xp0twdzsdeq4qg3c64v66552deax8zmvq4zw78"
|
|
438
|
+
oracleFeegrantOperator: "dora1xp0twdzsdeq4qg3c64v66552deax8zmvq4zw78",
|
|
439
|
+
oracleCodeIds: ["102", "105", "108", "110", "113", "115", "123"]
|
|
436
440
|
};
|
|
437
441
|
}
|
|
438
442
|
}
|
|
@@ -1142,6 +1146,102 @@ var Round = class {
|
|
|
1142
1146
|
return handleError(error);
|
|
1143
1147
|
}
|
|
1144
1148
|
}
|
|
1149
|
+
/**
|
|
1150
|
+
* Get round information with selective fields
|
|
1151
|
+
* @param address Round address
|
|
1152
|
+
* @param fields Array of fields to return, returns all fields if empty
|
|
1153
|
+
* @returns Round information response
|
|
1154
|
+
*/
|
|
1155
|
+
async getRoundWithFields(address, fields) {
|
|
1156
|
+
try {
|
|
1157
|
+
if (!isValidAddress(address)) {
|
|
1158
|
+
return {
|
|
1159
|
+
code: 400,
|
|
1160
|
+
error: {
|
|
1161
|
+
message: "Invalid round address format",
|
|
1162
|
+
type: ERROR.ERROR_ROUND_INVALID_ADDRESS
|
|
1163
|
+
}
|
|
1164
|
+
};
|
|
1165
|
+
}
|
|
1166
|
+
const defaultFields = [
|
|
1167
|
+
"id",
|
|
1168
|
+
"blockHeight",
|
|
1169
|
+
"txHash",
|
|
1170
|
+
"caller",
|
|
1171
|
+
"admin",
|
|
1172
|
+
"operator",
|
|
1173
|
+
"contractAddress",
|
|
1174
|
+
"circuitName",
|
|
1175
|
+
"timestamp",
|
|
1176
|
+
"votingStart",
|
|
1177
|
+
"votingEnd",
|
|
1178
|
+
"status",
|
|
1179
|
+
"period",
|
|
1180
|
+
"actionType",
|
|
1181
|
+
"roundTitle",
|
|
1182
|
+
"roundDescription",
|
|
1183
|
+
"roundLink",
|
|
1184
|
+
"coordinatorPubkeyX",
|
|
1185
|
+
"coordinatorPubkeyY",
|
|
1186
|
+
"voteOptionMap",
|
|
1187
|
+
"results",
|
|
1188
|
+
"allResult",
|
|
1189
|
+
"gasStationEnable",
|
|
1190
|
+
"totalGrant",
|
|
1191
|
+
"baseGrant",
|
|
1192
|
+
"totalBond",
|
|
1193
|
+
"circuitType",
|
|
1194
|
+
"circuitPower",
|
|
1195
|
+
"certificationSystem",
|
|
1196
|
+
"codeId",
|
|
1197
|
+
"maciType",
|
|
1198
|
+
"voiceCreditAmount",
|
|
1199
|
+
"preDeactivateRoot",
|
|
1200
|
+
"identity",
|
|
1201
|
+
"funds"
|
|
1202
|
+
];
|
|
1203
|
+
if (fields && fields.length > 0) {
|
|
1204
|
+
const invalidFields = fields.filter(
|
|
1205
|
+
(field) => !defaultFields.includes(field)
|
|
1206
|
+
);
|
|
1207
|
+
if (invalidFields.length > 0) {
|
|
1208
|
+
return {
|
|
1209
|
+
code: 400,
|
|
1210
|
+
error: {
|
|
1211
|
+
message: `Invalid fields: ${invalidFields.join(", ")}`,
|
|
1212
|
+
type: ERROR.ERROR_INVALID_FIELDS
|
|
1213
|
+
}
|
|
1214
|
+
};
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
const selectedFields = fields && fields.length > 0 ? fields : defaultFields;
|
|
1218
|
+
const fieldString = selectedFields.join("\n ");
|
|
1219
|
+
const ROUND_QUERY = `query {
|
|
1220
|
+
round(id: "${address}") {
|
|
1221
|
+
${fieldString}
|
|
1222
|
+
}
|
|
1223
|
+
}`;
|
|
1224
|
+
const response = await this.http.fetchGraphql(
|
|
1225
|
+
ROUND_QUERY,
|
|
1226
|
+
""
|
|
1227
|
+
);
|
|
1228
|
+
if (!response || !response.data || !response.data.round) {
|
|
1229
|
+
return {
|
|
1230
|
+
code: 404,
|
|
1231
|
+
error: {
|
|
1232
|
+
message: `No round data found for address ${address}`,
|
|
1233
|
+
type: ERROR.ERROR_ROUND_NOT_FOUND
|
|
1234
|
+
}
|
|
1235
|
+
};
|
|
1236
|
+
}
|
|
1237
|
+
return {
|
|
1238
|
+
code: 200,
|
|
1239
|
+
data: response.data
|
|
1240
|
+
};
|
|
1241
|
+
} catch (error) {
|
|
1242
|
+
return handleError(error);
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1145
1245
|
async getRounds(after, limit) {
|
|
1146
1246
|
try {
|
|
1147
1247
|
const ROUND_HISTORY_QUERY = `query ($limit: Int, $after: Cursor) {
|
|
@@ -1809,6 +1909,16 @@ var Indexer = class {
|
|
|
1809
1909
|
async getRoundById(id) {
|
|
1810
1910
|
return await this.round.getRoundById(id);
|
|
1811
1911
|
}
|
|
1912
|
+
/**
|
|
1913
|
+
* @method getRoundWithFields
|
|
1914
|
+
* @description Get a round by its address with selective fields.
|
|
1915
|
+
* @param {string} address - The address of the round.
|
|
1916
|
+
* @param {string[]} [fields] - The fields to retrieve.
|
|
1917
|
+
* @returns {Promise<SelectiveRoundResponse>} The round response.
|
|
1918
|
+
*/
|
|
1919
|
+
async getRoundWithFields(address, fields) {
|
|
1920
|
+
return await this.round.getRoundWithFields(address, fields);
|
|
1921
|
+
}
|
|
1812
1922
|
/**
|
|
1813
1923
|
* @method getRounds
|
|
1814
1924
|
* @description Get multiple rounds.
|
|
@@ -4736,6 +4846,20 @@ var MACI = class {
|
|
|
4736
4846
|
};
|
|
4737
4847
|
}
|
|
4738
4848
|
}
|
|
4849
|
+
async hasFeegrant({
|
|
4850
|
+
address,
|
|
4851
|
+
contractAddress
|
|
4852
|
+
}) {
|
|
4853
|
+
try {
|
|
4854
|
+
const response = await this.oracleCertificate.feegrantAllowance(
|
|
4855
|
+
contractAddress,
|
|
4856
|
+
address
|
|
4857
|
+
);
|
|
4858
|
+
return response.spend_limit.length > 0;
|
|
4859
|
+
} catch (error) {
|
|
4860
|
+
return false;
|
|
4861
|
+
}
|
|
4862
|
+
}
|
|
4739
4863
|
// only for maci and oracle maci, amaci will set the voice credit when deploy the contract
|
|
4740
4864
|
async queryWhitelistBalanceOf({
|
|
4741
4865
|
signer,
|
|
@@ -4751,9 +4875,15 @@ var MACI = class {
|
|
|
4751
4875
|
contractAddress
|
|
4752
4876
|
});
|
|
4753
4877
|
if (isWhiteListed) {
|
|
4754
|
-
const round = await this.indexer.
|
|
4878
|
+
const round = await this.indexer.getRoundWithFields(contractAddress, [
|
|
4879
|
+
"voiceCreditAmount"
|
|
4880
|
+
]);
|
|
4755
4881
|
if (!isErrorResponse(round)) {
|
|
4756
|
-
|
|
4882
|
+
if (round.data.round.voiceCreditAmount) {
|
|
4883
|
+
return round.data.round.voiceCreditAmount;
|
|
4884
|
+
} else {
|
|
4885
|
+
return "0";
|
|
4886
|
+
}
|
|
4757
4887
|
} else {
|
|
4758
4888
|
throw new Error(
|
|
4759
4889
|
`Failed to query amaci voice credit: ${round.error.type} ${round.error.message}`
|
|
@@ -4811,7 +4941,7 @@ var MACI = class {
|
|
|
4811
4941
|
return snapshotHeight;
|
|
4812
4942
|
}
|
|
4813
4943
|
async getRoundInfo({ contractAddress }) {
|
|
4814
|
-
const roundInfo = await this.indexer.
|
|
4944
|
+
const roundInfo = await this.indexer.getRoundWithFields(contractAddress);
|
|
4815
4945
|
if (isErrorResponse(roundInfo)) {
|
|
4816
4946
|
throw new Error(
|
|
4817
4947
|
`Failed to get round info: ${roundInfo.error.type} ${roundInfo.error.message}`
|
|
@@ -5306,6 +5436,16 @@ var MaciClient2 = class {
|
|
|
5306
5436
|
async getRoundById(id) {
|
|
5307
5437
|
return await this.indexer.round.getRoundById(id);
|
|
5308
5438
|
}
|
|
5439
|
+
/**
|
|
5440
|
+
* @method getRoundWithFields
|
|
5441
|
+
* @description Get a round by its address with selective fields.
|
|
5442
|
+
* @param {string} address - The address of the round.
|
|
5443
|
+
* @param {string[]} [fields] - The fields to retrieve.
|
|
5444
|
+
* @returns {Promise<SelectiveRoundResponse>} The round response.
|
|
5445
|
+
*/
|
|
5446
|
+
async getRoundWithFields(address, fields) {
|
|
5447
|
+
return await this.indexer.round.getRoundWithFields(address, fields);
|
|
5448
|
+
}
|
|
5309
5449
|
/**
|
|
5310
5450
|
* @method getRounds
|
|
5311
5451
|
* @description Get multiple rounds.
|