@dorafactory/maci-sdk 0.0.19 → 0.0.21
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 +99 -6
- package/dist/browser.d.ts +99 -6
- package/dist/browser.js +411 -26
- package/dist/browser.js.map +1 -1
- package/dist/browser.mjs +411 -26
- package/dist/browser.mjs.map +1 -1
- package/dist/index.d.mts +99 -6
- package/dist/index.d.ts +99 -6
- package/dist/index.js +411 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +411 -26
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/libs/contract/contract.ts +32 -21
- package/src/libs/contract/types.ts +4 -4
- package/src/libs/contract/utils.ts +26 -6
- package/src/libs/errors/types.ts +3 -0
- package/src/libs/http/http.ts +2 -1
- package/src/libs/indexer/indexer.ts +21 -0
- package/src/libs/maci/maci.ts +82 -0
- package/src/libs/oracle-certificate/oracle-certificate.ts +16 -0
- package/src/libs/oracle-certificate/types.ts +9 -0
- package/src/libs/query/operator.ts +338 -0
- package/src/types/index.ts +86 -0
package/dist/browser.js
CHANGED
|
@@ -25983,11 +25983,12 @@ var Http = class {
|
|
|
25983
25983
|
);
|
|
25984
25984
|
}
|
|
25985
25985
|
}
|
|
25986
|
-
async fetchRest(path) {
|
|
25986
|
+
async fetchRest(path, options) {
|
|
25987
25987
|
try {
|
|
25988
25988
|
const fetchFn = this.getFetch();
|
|
25989
25989
|
const response = await fetchFn(`${this.restEndpoint}${path}`, {
|
|
25990
|
-
...this.defaultOptions
|
|
25990
|
+
...this.defaultOptions,
|
|
25991
|
+
...options
|
|
25991
25992
|
});
|
|
25992
25993
|
if (!response.ok) {
|
|
25993
25994
|
throw new HttpError(
|
|
@@ -26025,6 +26026,8 @@ var ERROR = {
|
|
|
26025
26026
|
ERROR_CIRCUIT_NOT_FOUND: "ERROR_CIRCUIT_NOT_FOUND",
|
|
26026
26027
|
ERROR_OPERATOR_INVALID_ADDRESS: "ERROR_OPERATOR_INVALID_ADDRESS",
|
|
26027
26028
|
ERROR_OPERATOR_NOT_FOUND: "ERROR_OPERATOR_NOT_FOUND",
|
|
26029
|
+
ERROR_OPERATOR_DELAY_HISTORY_NOT_FOUND: "ERROR_OPERATOR_DELAY_HISTORY_NOT_FOUND",
|
|
26030
|
+
ERROR_QUERY_MISS_RATE_FAILED: "ERROR_QUERY_MISS_RATE_FAILED",
|
|
26028
26031
|
ERROR_OPERATORS_NOT_FOUND: "ERROR_OPERATORS_NOT_FOUND",
|
|
26029
26032
|
ERROR_PROOF_NOT_FOUND: "ERROR_PROOF_NOT_FOUND",
|
|
26030
26033
|
ERROR_ROUND_INVALID_ADDRESS: "ERROR_ROUND_INVALID_ADDRESS",
|
|
@@ -26459,6 +26462,64 @@ var Operator = class {
|
|
|
26459
26462
|
return handleError(error);
|
|
26460
26463
|
}
|
|
26461
26464
|
}
|
|
26465
|
+
async getOperatorDelayOperationsByAddress(address, after, limit) {
|
|
26466
|
+
try {
|
|
26467
|
+
if (!isValidAddress(address)) {
|
|
26468
|
+
return {
|
|
26469
|
+
code: 400,
|
|
26470
|
+
error: {
|
|
26471
|
+
message: "Invalid operator address format",
|
|
26472
|
+
type: ERROR.ERROR_OPERATOR_INVALID_ADDRESS
|
|
26473
|
+
}
|
|
26474
|
+
};
|
|
26475
|
+
}
|
|
26476
|
+
const OPERATORS_QUERY = `query ($limit: Int, $after: Cursor) {
|
|
26477
|
+
operatorDelayOperations(first: $limit, after: $after, filter: {operatorAddress: {equalTo: "${address}"}}, orderBy: [TIMESTAMP_DESC]) {
|
|
26478
|
+
pageInfo {
|
|
26479
|
+
endCursor
|
|
26480
|
+
hasNextPage
|
|
26481
|
+
}
|
|
26482
|
+
totalCount
|
|
26483
|
+
edges {
|
|
26484
|
+
cursor
|
|
26485
|
+
node {
|
|
26486
|
+
blockHeight
|
|
26487
|
+
delayProcessDmsgCount
|
|
26488
|
+
delayDuration
|
|
26489
|
+
delayReason
|
|
26490
|
+
delayType
|
|
26491
|
+
id
|
|
26492
|
+
nodeId
|
|
26493
|
+
operatorAddress
|
|
26494
|
+
timestamp
|
|
26495
|
+
roundAddress
|
|
26496
|
+
}
|
|
26497
|
+
}
|
|
26498
|
+
}
|
|
26499
|
+
}`;
|
|
26500
|
+
const response = await this.http.fetchGraphql(
|
|
26501
|
+
OPERATORS_QUERY,
|
|
26502
|
+
after,
|
|
26503
|
+
limit
|
|
26504
|
+
);
|
|
26505
|
+
if (!response || !response.data || !response.data.operatorDelayOperations || !response.data.operatorDelayOperations.edges || response.data.operatorDelayOperations.edges.length === 0) {
|
|
26506
|
+
return {
|
|
26507
|
+
code: 404,
|
|
26508
|
+
error: {
|
|
26509
|
+
message: `No operatorDelayOperations found for address ${address}`,
|
|
26510
|
+
type: ERROR.ERROR_OPERATOR_DELAY_HISTORY_NOT_FOUND
|
|
26511
|
+
}
|
|
26512
|
+
};
|
|
26513
|
+
}
|
|
26514
|
+
const operator = {
|
|
26515
|
+
code: 200,
|
|
26516
|
+
data: response.data
|
|
26517
|
+
};
|
|
26518
|
+
return operator;
|
|
26519
|
+
} catch (error) {
|
|
26520
|
+
return handleError(error);
|
|
26521
|
+
}
|
|
26522
|
+
}
|
|
26462
26523
|
async getOperators(after, limit) {
|
|
26463
26524
|
try {
|
|
26464
26525
|
const OPERATORS_QUERY = `query ($limit: Int, $after: Cursor) {
|
|
@@ -26562,6 +26623,228 @@ var Operator = class {
|
|
|
26562
26623
|
return handleError(error);
|
|
26563
26624
|
}
|
|
26564
26625
|
}
|
|
26626
|
+
async queryMissRate(address, durationDay) {
|
|
26627
|
+
try {
|
|
26628
|
+
const now = /* @__PURE__ */ new Date();
|
|
26629
|
+
const startTime = new Date(
|
|
26630
|
+
now.getTime() - durationDay * 24 * 60 * 60 * 1e3
|
|
26631
|
+
);
|
|
26632
|
+
const startTimestamp = Math.floor(startTime.getTime() / 1e3);
|
|
26633
|
+
const endNanosTimestamp = Math.floor(startTime.getTime() * 1e6);
|
|
26634
|
+
const txTimestamp = Math.floor(startTime.getTime());
|
|
26635
|
+
const QUERY = `query ($limit: Int, $after: Cursor) {
|
|
26636
|
+
operatorDelayOperations(
|
|
26637
|
+
first: $limit,
|
|
26638
|
+
after: $after,
|
|
26639
|
+
filter: {
|
|
26640
|
+
operatorAddress: {equalTo: "${address}"},
|
|
26641
|
+
timestamp: { greaterThanOrEqualTo: "${startTimestamp}" }
|
|
26642
|
+
},
|
|
26643
|
+
orderBy: [TIMESTAMP_DESC]
|
|
26644
|
+
) {
|
|
26645
|
+
edges {
|
|
26646
|
+
node {
|
|
26647
|
+
blockHeight
|
|
26648
|
+
delayProcessDmsgCount
|
|
26649
|
+
delayDuration
|
|
26650
|
+
delayReason
|
|
26651
|
+
delayType
|
|
26652
|
+
id
|
|
26653
|
+
nodeId
|
|
26654
|
+
operatorAddress
|
|
26655
|
+
timestamp
|
|
26656
|
+
roundAddress
|
|
26657
|
+
}
|
|
26658
|
+
}
|
|
26659
|
+
}
|
|
26660
|
+
}`;
|
|
26661
|
+
const ROUNDS_QUERY = `query ($limit: Int, $after: Cursor) {
|
|
26662
|
+
rounds(first: $limit, after: $after,
|
|
26663
|
+
filter: {
|
|
26664
|
+
operator: {equalTo: "${address}"},
|
|
26665
|
+
votingEnd: { greaterThanOrEqualTo: "${endNanosTimestamp}" }
|
|
26666
|
+
},
|
|
26667
|
+
orderBy: [TIMESTAMP_DESC]
|
|
26668
|
+
){
|
|
26669
|
+
pageInfo {
|
|
26670
|
+
endCursor
|
|
26671
|
+
hasNextPage
|
|
26672
|
+
}
|
|
26673
|
+
totalCount
|
|
26674
|
+
edges {
|
|
26675
|
+
node {
|
|
26676
|
+
id
|
|
26677
|
+
blockHeight
|
|
26678
|
+
txHash
|
|
26679
|
+
caller
|
|
26680
|
+
admin
|
|
26681
|
+
operator
|
|
26682
|
+
contractAddress
|
|
26683
|
+
circuitName
|
|
26684
|
+
timestamp
|
|
26685
|
+
votingStart
|
|
26686
|
+
votingEnd
|
|
26687
|
+
status
|
|
26688
|
+
period
|
|
26689
|
+
actionType
|
|
26690
|
+
roundTitle
|
|
26691
|
+
roundDescription
|
|
26692
|
+
roundLink
|
|
26693
|
+
coordinatorPubkeyX
|
|
26694
|
+
coordinatorPubkeyY
|
|
26695
|
+
voteOptionMap
|
|
26696
|
+
results
|
|
26697
|
+
allResult
|
|
26698
|
+
gasStationEnable
|
|
26699
|
+
totalGrant
|
|
26700
|
+
baseGrant
|
|
26701
|
+
totalBond
|
|
26702
|
+
circuitType
|
|
26703
|
+
circuitPower
|
|
26704
|
+
certificationSystem
|
|
26705
|
+
codeId
|
|
26706
|
+
maciType
|
|
26707
|
+
voiceCreditAmount
|
|
26708
|
+
preDeactivateRoot
|
|
26709
|
+
}
|
|
26710
|
+
cursor
|
|
26711
|
+
}
|
|
26712
|
+
}
|
|
26713
|
+
}
|
|
26714
|
+
`;
|
|
26715
|
+
const roundsResponse = await this.http.fetchGraphql(
|
|
26716
|
+
ROUNDS_QUERY,
|
|
26717
|
+
"",
|
|
26718
|
+
9999
|
|
26719
|
+
);
|
|
26720
|
+
const roundContractAddresses = roundsResponse?.data?.rounds?.edges?.map(
|
|
26721
|
+
(edge) => edge.node.contractAddress
|
|
26722
|
+
) || [];
|
|
26723
|
+
const TRANSACTIONS_QUERY = `query transactions($limit: Int, $after: Cursor) {
|
|
26724
|
+
transactions(first: $limit, after: $after,
|
|
26725
|
+
filter: {
|
|
26726
|
+
timestamp: { greaterThanOrEqualTo: "${txTimestamp}" },
|
|
26727
|
+
type: { equalTo: "op:procDeactivate" },
|
|
26728
|
+
contractAddress: { in: ${JSON.stringify(roundContractAddresses)} }
|
|
26729
|
+
},
|
|
26730
|
+
orderBy: [TIMESTAMP_DESC]
|
|
26731
|
+
){
|
|
26732
|
+
pageInfo {
|
|
26733
|
+
endCursor
|
|
26734
|
+
hasNextPage
|
|
26735
|
+
}
|
|
26736
|
+
totalCount
|
|
26737
|
+
edges {
|
|
26738
|
+
cursor
|
|
26739
|
+
node {
|
|
26740
|
+
id
|
|
26741
|
+
blockHeight
|
|
26742
|
+
txHash
|
|
26743
|
+
timestamp
|
|
26744
|
+
type
|
|
26745
|
+
status
|
|
26746
|
+
circuitName
|
|
26747
|
+
fee
|
|
26748
|
+
gasUsed
|
|
26749
|
+
gasWanted
|
|
26750
|
+
caller
|
|
26751
|
+
contractAddress
|
|
26752
|
+
}
|
|
26753
|
+
}
|
|
26754
|
+
}
|
|
26755
|
+
}`;
|
|
26756
|
+
const [delayResponse, transactionsResponse] = await Promise.all([
|
|
26757
|
+
this.http.fetchGraphql(
|
|
26758
|
+
QUERY,
|
|
26759
|
+
"",
|
|
26760
|
+
9999
|
|
26761
|
+
),
|
|
26762
|
+
this.http.fetchGraphql(
|
|
26763
|
+
TRANSACTIONS_QUERY,
|
|
26764
|
+
"",
|
|
26765
|
+
9999
|
|
26766
|
+
)
|
|
26767
|
+
]);
|
|
26768
|
+
const dailyStats = /* @__PURE__ */ new Map();
|
|
26769
|
+
const endDate = /* @__PURE__ */ new Date();
|
|
26770
|
+
for (let i = 0; i < durationDay; i++) {
|
|
26771
|
+
const date = new Date(endDate.getTime() - i * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
|
|
26772
|
+
dailyStats.set(date, {
|
|
26773
|
+
delayCount: 0,
|
|
26774
|
+
deactivateDelay: {
|
|
26775
|
+
count: 0,
|
|
26776
|
+
dmsgCount: 0
|
|
26777
|
+
},
|
|
26778
|
+
tallyDelay: {
|
|
26779
|
+
count: 0
|
|
26780
|
+
},
|
|
26781
|
+
totalDelayDuration: 0,
|
|
26782
|
+
avgDelayDuration: 0,
|
|
26783
|
+
tallyCount: 0,
|
|
26784
|
+
deactivateCount: 0,
|
|
26785
|
+
missRate: 0
|
|
26786
|
+
});
|
|
26787
|
+
}
|
|
26788
|
+
delayResponse.data.operatorDelayOperations.edges.forEach(({ node }) => {
|
|
26789
|
+
const date = new Date(parseInt(node.timestamp) * 1e3).toISOString().split("T")[0];
|
|
26790
|
+
if (dailyStats.has(date)) {
|
|
26791
|
+
const stats = dailyStats.get(date);
|
|
26792
|
+
stats.delayCount++;
|
|
26793
|
+
stats.totalDelayDuration += parseInt(node.delayDuration);
|
|
26794
|
+
if (node.delayType === "deactivate_delay") {
|
|
26795
|
+
stats.deactivateDelay.count++;
|
|
26796
|
+
stats.deactivateDelay.dmsgCount += node.delayProcessDmsgCount;
|
|
26797
|
+
} else if (node.delayType === "tally_delay") {
|
|
26798
|
+
stats.tallyDelay.count++;
|
|
26799
|
+
}
|
|
26800
|
+
}
|
|
26801
|
+
});
|
|
26802
|
+
if (roundsResponse?.data?.rounds?.edges) {
|
|
26803
|
+
roundsResponse.data.rounds.edges.forEach(({ node }) => {
|
|
26804
|
+
const date = new Date(parseInt(node.votingEnd) / 1e6).toISOString().split("T")[0];
|
|
26805
|
+
if (dailyStats.has(date)) {
|
|
26806
|
+
const stats = dailyStats.get(date);
|
|
26807
|
+
stats.tallyCount++;
|
|
26808
|
+
}
|
|
26809
|
+
});
|
|
26810
|
+
}
|
|
26811
|
+
if (transactionsResponse?.data?.transactions?.edges) {
|
|
26812
|
+
transactionsResponse.data.transactions.edges.forEach(({ node }) => {
|
|
26813
|
+
const date = new Date(parseInt(node.timestamp)).toISOString().split("T")[0];
|
|
26814
|
+
if (dailyStats.has(date)) {
|
|
26815
|
+
const stats = dailyStats.get(date);
|
|
26816
|
+
stats.deactivateCount++;
|
|
26817
|
+
}
|
|
26818
|
+
});
|
|
26819
|
+
}
|
|
26820
|
+
return {
|
|
26821
|
+
code: 200,
|
|
26822
|
+
data: {
|
|
26823
|
+
missRate: Array.from(dailyStats.entries()).map(([date, stats]) => ({
|
|
26824
|
+
date,
|
|
26825
|
+
delayCount: stats.delayCount,
|
|
26826
|
+
deactivateDelay: stats.deactivateDelay,
|
|
26827
|
+
tallyDelay: stats.tallyDelay,
|
|
26828
|
+
totalDelayDuration: stats.totalDelayDuration,
|
|
26829
|
+
avgDelayDuration: stats.delayCount > 0 ? stats.totalDelayDuration / stats.delayCount : 0,
|
|
26830
|
+
tallyCount: stats.tallyCount,
|
|
26831
|
+
deactivateCount: stats.deactivateCount,
|
|
26832
|
+
missRate: stats.deactivateCount + stats.tallyCount > 0 ? parseFloat(
|
|
26833
|
+
((stats.deactivateDelay.count + stats.tallyDelay.count) / (stats.deactivateCount + stats.tallyCount)).toFixed(2)
|
|
26834
|
+
) : 0
|
|
26835
|
+
})).sort((a, b) => b.date.localeCompare(a.date))
|
|
26836
|
+
}
|
|
26837
|
+
};
|
|
26838
|
+
} catch (error) {
|
|
26839
|
+
return {
|
|
26840
|
+
code: 404,
|
|
26841
|
+
error: {
|
|
26842
|
+
message: "Query miss rate failed",
|
|
26843
|
+
type: ERROR.ERROR_QUERY_MISS_RATE_FAILED
|
|
26844
|
+
}
|
|
26845
|
+
};
|
|
26846
|
+
}
|
|
26847
|
+
}
|
|
26565
26848
|
};
|
|
26566
26849
|
|
|
26567
26850
|
// src/libs/query/round.ts
|
|
@@ -27397,6 +27680,16 @@ var Indexer = class {
|
|
|
27397
27680
|
async getOperatorByAddress(address) {
|
|
27398
27681
|
return await this.operator.getOperatorByAddress(address);
|
|
27399
27682
|
}
|
|
27683
|
+
async getOperatorDelayOperationsByAddress(address, after, limit) {
|
|
27684
|
+
return await this.operator.getOperatorDelayOperationsByAddress(
|
|
27685
|
+
address,
|
|
27686
|
+
after,
|
|
27687
|
+
limit
|
|
27688
|
+
);
|
|
27689
|
+
}
|
|
27690
|
+
async queryMissRate(address, durationDay) {
|
|
27691
|
+
return await this.operator.queryMissRate(address, durationDay);
|
|
27692
|
+
}
|
|
27400
27693
|
/**
|
|
27401
27694
|
* @method getOperators
|
|
27402
27695
|
* @description Get multiple operators.
|
|
@@ -29549,7 +29842,7 @@ function getContractParams(type, circuitType, proofSystem, maxVoter, maxOption)
|
|
|
29549
29842
|
`Invalid proof system ${proofSystem}, only support GROTH16 and PLONK`
|
|
29550
29843
|
);
|
|
29551
29844
|
}
|
|
29552
|
-
if (
|
|
29845
|
+
if (maxVoter <= 25 && maxOption <= 5) {
|
|
29553
29846
|
parameters = CIRCUIT_INFO["2-1-1-5"].parameter;
|
|
29554
29847
|
if (proofSystem === "groth16" /* GROTH16 */) {
|
|
29555
29848
|
groth16ProcessVkey = CIRCUIT_INFO["2-1-1-5"]["groth16"].process_vkey;
|
|
@@ -29558,7 +29851,7 @@ function getContractParams(type, circuitType, proofSystem, maxVoter, maxOption)
|
|
|
29558
29851
|
plonkProcessVkey = CIRCUIT_INFO["2-1-1-5"]["plonk"]?.process_vkey;
|
|
29559
29852
|
plonkTallyVkey = CIRCUIT_INFO["2-1-1-5"]["plonk"]?.tally_vkey;
|
|
29560
29853
|
}
|
|
29561
|
-
} else if (
|
|
29854
|
+
} else if (maxVoter <= 625 && maxOption <= 25) {
|
|
29562
29855
|
parameters = CIRCUIT_INFO["4-2-2-25"].parameter;
|
|
29563
29856
|
if (proofSystem === "groth16" /* GROTH16 */) {
|
|
29564
29857
|
groth16ProcessVkey = CIRCUIT_INFO["4-2-2-25"]["groth16"].process_vkey;
|
|
@@ -29567,7 +29860,7 @@ function getContractParams(type, circuitType, proofSystem, maxVoter, maxOption)
|
|
|
29567
29860
|
plonkProcessVkey = CIRCUIT_INFO["4-2-2-25"]["plonk"]?.process_vkey;
|
|
29568
29861
|
plonkTallyVkey = CIRCUIT_INFO["4-2-2-25"]["plonk"]?.tally_vkey;
|
|
29569
29862
|
}
|
|
29570
|
-
} else if (
|
|
29863
|
+
} else if (maxVoter <= 15625 && maxOption <= 125) {
|
|
29571
29864
|
parameters = CIRCUIT_INFO["6-3-3-125"].parameter;
|
|
29572
29865
|
if (proofSystem === "groth16" /* GROTH16 */) {
|
|
29573
29866
|
groth16ProcessVkey = CIRCUIT_INFO["6-3-3-125"]["groth16"].process_vkey;
|
|
@@ -29576,7 +29869,7 @@ function getContractParams(type, circuitType, proofSystem, maxVoter, maxOption)
|
|
|
29576
29869
|
plonkProcessVkey = CIRCUIT_INFO["6-3-3-125"]["plonk"]?.process_vkey;
|
|
29577
29870
|
plonkTallyVkey = CIRCUIT_INFO["6-3-3-125"]["plonk"]?.tally_vkey;
|
|
29578
29871
|
}
|
|
29579
|
-
} else if (
|
|
29872
|
+
} else if (maxVoter <= 1953125 && maxOption <= 125) {
|
|
29580
29873
|
parameters = CIRCUIT_INFO["9-4-3-625"].parameter;
|
|
29581
29874
|
if (proofSystem === "groth16" /* GROTH16 */) {
|
|
29582
29875
|
if (circuitType === "0" /* IP1V */) {
|
|
@@ -29630,6 +29923,20 @@ function getContractParams(type, circuitType, proofSystem, maxVoter, maxOption)
|
|
|
29630
29923
|
};
|
|
29631
29924
|
}
|
|
29632
29925
|
}
|
|
29926
|
+
function getAMaciRoundCircuitFee(maxVoter, maxOption) {
|
|
29927
|
+
let requiredFee = {
|
|
29928
|
+
denom: "peaka",
|
|
29929
|
+
amount: "0"
|
|
29930
|
+
};
|
|
29931
|
+
if (maxVoter <= 25 && maxOption <= 5) {
|
|
29932
|
+
requiredFee.amount = "50000000000000000000";
|
|
29933
|
+
} else if (maxVoter <= 625 && maxOption <= 25) {
|
|
29934
|
+
requiredFee.amount = "100000000000000000000";
|
|
29935
|
+
} else {
|
|
29936
|
+
throw new Error("Number of voters or options is too large.");
|
|
29937
|
+
}
|
|
29938
|
+
return requiredFee;
|
|
29939
|
+
}
|
|
29633
29940
|
|
|
29634
29941
|
// src/libs/contract/contract.ts
|
|
29635
29942
|
var Contract = class {
|
|
@@ -29670,26 +29977,32 @@ var Contract = class {
|
|
|
29670
29977
|
wallet: signer,
|
|
29671
29978
|
contractAddress: this.registryAddress
|
|
29672
29979
|
});
|
|
29980
|
+
const requiredFee = getAMaciRoundCircuitFee(maxVoter, maxOption);
|
|
29673
29981
|
preDeactivateRoot = preDeactivateRoot || "0";
|
|
29674
|
-
const res = await client.createRound(
|
|
29675
|
-
|
|
29676
|
-
|
|
29677
|
-
|
|
29678
|
-
|
|
29679
|
-
|
|
29680
|
-
|
|
29681
|
-
|
|
29682
|
-
|
|
29683
|
-
|
|
29684
|
-
|
|
29685
|
-
|
|
29686
|
-
|
|
29982
|
+
const res = await client.createRound(
|
|
29983
|
+
{
|
|
29984
|
+
operator,
|
|
29985
|
+
preDeactivateRoot,
|
|
29986
|
+
voiceCreditAmount,
|
|
29987
|
+
whitelist,
|
|
29988
|
+
roundInfo: {
|
|
29989
|
+
title,
|
|
29990
|
+
description: description || "",
|
|
29991
|
+
link: link || ""
|
|
29992
|
+
},
|
|
29993
|
+
votingTime: {
|
|
29994
|
+
start_time,
|
|
29995
|
+
end_time
|
|
29996
|
+
},
|
|
29997
|
+
maxVoter: maxVoter.toString(),
|
|
29998
|
+
maxOption: maxOption.toString(),
|
|
29999
|
+
certificationSystem: "0",
|
|
30000
|
+
circuitType
|
|
29687
30001
|
},
|
|
29688
|
-
|
|
29689
|
-
|
|
29690
|
-
|
|
29691
|
-
|
|
29692
|
-
});
|
|
30002
|
+
"auto",
|
|
30003
|
+
void 0,
|
|
30004
|
+
[requiredFee]
|
|
30005
|
+
);
|
|
29693
30006
|
let contractAddress = "";
|
|
29694
30007
|
res.events.map((event) => {
|
|
29695
30008
|
if (event.type === "wasm") {
|
|
@@ -29789,8 +30102,8 @@ var Contract = class {
|
|
|
29789
30102
|
"2" /* ORACLE_MACI */,
|
|
29790
30103
|
circuitType,
|
|
29791
30104
|
"groth16" /* GROTH16 */,
|
|
29792
|
-
|
|
29793
|
-
|
|
30105
|
+
0,
|
|
30106
|
+
0
|
|
29794
30107
|
);
|
|
29795
30108
|
const instantiateResponse = await client.instantiate(
|
|
29796
30109
|
address,
|
|
@@ -29905,6 +30218,16 @@ var OracleCertificate = class {
|
|
|
29905
30218
|
const signatureData = await response.json();
|
|
29906
30219
|
return signatureData;
|
|
29907
30220
|
}
|
|
30221
|
+
async feegrantAllowance(granter, grantee) {
|
|
30222
|
+
const response = await this.http.fetchRest(
|
|
30223
|
+
`/cosmos/feegrant/v1beta1/allowance/${granter}/${grantee}`
|
|
30224
|
+
);
|
|
30225
|
+
return {
|
|
30226
|
+
granter,
|
|
30227
|
+
grantee,
|
|
30228
|
+
spend_limit: response.allowance.allowance.allowance.spend_limit
|
|
30229
|
+
};
|
|
30230
|
+
}
|
|
29908
30231
|
};
|
|
29909
30232
|
|
|
29910
30233
|
// src/libs/circom/index.ts
|
|
@@ -30236,6 +30559,24 @@ var MACI = class {
|
|
|
30236
30559
|
}
|
|
30237
30560
|
return response.data.signUpEvents[0].stateIdx;
|
|
30238
30561
|
}
|
|
30562
|
+
async feegrantAllowance({
|
|
30563
|
+
address,
|
|
30564
|
+
contractAddress
|
|
30565
|
+
}) {
|
|
30566
|
+
try {
|
|
30567
|
+
const response = await this.oracleCertificate.feegrantAllowance(
|
|
30568
|
+
contractAddress,
|
|
30569
|
+
address
|
|
30570
|
+
);
|
|
30571
|
+
return response;
|
|
30572
|
+
} catch (error) {
|
|
30573
|
+
return {
|
|
30574
|
+
granter: contractAddress,
|
|
30575
|
+
grantee: address,
|
|
30576
|
+
spend_limit: []
|
|
30577
|
+
};
|
|
30578
|
+
}
|
|
30579
|
+
}
|
|
30239
30580
|
// only for maci and oracle maci, amaci will set the voice credit when deploy the contract
|
|
30240
30581
|
async queryWhitelistBalanceOf({
|
|
30241
30582
|
signer,
|
|
@@ -30327,6 +30668,50 @@ var MACI = class {
|
|
|
30327
30668
|
const circuitType = await this.getRoundCircuitType({ contractAddress });
|
|
30328
30669
|
return circuitType === "1";
|
|
30329
30670
|
}
|
|
30671
|
+
async queryRoundClaimable({
|
|
30672
|
+
contractAddress
|
|
30673
|
+
}) {
|
|
30674
|
+
try {
|
|
30675
|
+
const roundInfo = await this.getRoundInfo({ contractAddress });
|
|
30676
|
+
if (roundInfo.maciType !== "aMACI") {
|
|
30677
|
+
return {
|
|
30678
|
+
claimable: null,
|
|
30679
|
+
balance: null
|
|
30680
|
+
};
|
|
30681
|
+
}
|
|
30682
|
+
const votingEndTime = new Date(Number(roundInfo.votingEnd) / 10 ** 6);
|
|
30683
|
+
const currentTime = /* @__PURE__ */ new Date();
|
|
30684
|
+
const threeDaysInMs = 3 * 24 * 60 * 60 * 1e3;
|
|
30685
|
+
if (currentTime.getTime() - votingEndTime.getTime() <= threeDaysInMs) {
|
|
30686
|
+
return {
|
|
30687
|
+
claimable: null,
|
|
30688
|
+
balance: null
|
|
30689
|
+
};
|
|
30690
|
+
}
|
|
30691
|
+
const roundBalance = await this.indexer.balanceOf(contractAddress);
|
|
30692
|
+
if (isErrorResponse(roundBalance)) {
|
|
30693
|
+
throw new Error(
|
|
30694
|
+
`Failed to query round balance: ${roundBalance.error.type} ${roundBalance.error.message}`
|
|
30695
|
+
);
|
|
30696
|
+
}
|
|
30697
|
+
if (roundBalance.data.balance && roundBalance.data.balance !== "0" && roundBalance.data.balance !== "") {
|
|
30698
|
+
return {
|
|
30699
|
+
claimable: true,
|
|
30700
|
+
balance: roundBalance.data.balance
|
|
30701
|
+
};
|
|
30702
|
+
}
|
|
30703
|
+
return {
|
|
30704
|
+
claimable: false,
|
|
30705
|
+
balance: roundBalance.data.balance
|
|
30706
|
+
};
|
|
30707
|
+
} catch (error) {
|
|
30708
|
+
console.error("Error in queryRoundClaimable:", error);
|
|
30709
|
+
return {
|
|
30710
|
+
claimable: null,
|
|
30711
|
+
balance: null
|
|
30712
|
+
};
|
|
30713
|
+
}
|
|
30714
|
+
}
|
|
30330
30715
|
async queryRoundGasStation({ contractAddress }) {
|
|
30331
30716
|
const roundInfo = await this.getRoundInfo({ contractAddress });
|
|
30332
30717
|
return roundInfo.gasStationEnable;
|