@peeramid-labs/sdk 3.10.3 → 3.11.0
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/cli/cli/commands/blockchain/mine.js +1 -0
- package/cli/cli/commands/blockchain/mine.js.map +1 -1
- package/cli/cli/commands/distributions/add.js +7 -6
- package/cli/cli/commands/distributions/add.js.map +1 -1
- package/cli/cli/commands/distributions/list.js +7 -0
- package/cli/cli/commands/distributions/list.js.map +1 -1
- package/cli/cli/commands/distributions/remove.js +5 -0
- package/cli/cli/commands/distributions/remove.js.map +1 -1
- package/cli/cli/commands/distributions/state.js +5 -0
- package/cli/cli/commands/distributions/state.js.map +1 -1
- package/cli/cli/commands/fellowship/create.js +7 -1
- package/cli/cli/commands/fellowship/create.js.map +1 -1
- package/cli/cli/commands/fellowship/eip712.js +5 -0
- package/cli/cli/commands/fellowship/eip712.js.map +1 -1
- package/cli/cli/commands/fellowship/game/cancel.js +6 -0
- package/cli/cli/commands/fellowship/game/cancel.js.map +1 -1
- package/cli/cli/commands/fellowship/game/create.js +8 -1
- package/cli/cli/commands/fellowship/game/create.js.map +1 -1
- package/cli/cli/commands/fellowship/game/end-turn.js +12 -5
- package/cli/cli/commands/fellowship/game/end-turn.js.map +1 -1
- package/cli/cli/commands/fellowship/game/join.js +9 -1
- package/cli/cli/commands/fellowship/game/join.js.map +1 -1
- package/cli/cli/commands/fellowship/game/list.js +6 -0
- package/cli/cli/commands/fellowship/game/list.js.map +1 -1
- package/cli/cli/commands/fellowship/game/propose.js +10 -1
- package/cli/cli/commands/fellowship/game/propose.js.map +1 -1
- package/cli/cli/commands/fellowship/game/start.js +10 -1
- package/cli/cli/commands/fellowship/game/start.js.map +1 -1
- package/cli/cli/commands/fellowship/game/vote.js +10 -1
- package/cli/cli/commands/fellowship/game/vote.js.map +1 -1
- package/cli/cli/commands/fellowship/list.js +5 -0
- package/cli/cli/commands/fellowship/list.js.map +1 -1
- package/cli/cli/commands/fellowship/params.js +5 -0
- package/cli/cli/commands/fellowship/params.js.map +1 -1
- package/cli/cli/commands/instances/list.js +5 -0
- package/cli/cli/commands/instances/list.js.map +1 -1
- package/cli/cli/commands/rankify/games.js +5 -0
- package/cli/cli/commands/rankify/games.js.map +1 -1
- package/cli/cli/utils.js +3 -3
- package/cli/cli/utils.js.map +1 -1
- package/cli/eds/Distributor.js +18 -29
- package/cli/eds/Distributor.js.map +1 -1
- package/cli/rankify/GameMaster.js +42 -39
- package/cli/rankify/GameMaster.js.map +1 -1
- package/cli/rankify/InstanceBase.js +101 -130
- package/cli/rankify/InstanceBase.js.map +1 -1
- package/cli/rankify/MAODistributor.js +45 -54
- package/cli/rankify/MAODistributor.js.map +1 -1
- package/cli/rankify/Player.js +4 -6
- package/cli/rankify/Player.js.map +1 -1
- package/cli/utils/EnvioGraphQLClient.js +728 -0
- package/cli/utils/EnvioGraphQLClient.js.map +1 -0
- package/cli/utils/index.js.map +1 -1
- package/cli/utils/logger.js +12 -0
- package/cli/utils/logger.js.map +1 -0
- package/docs/classes/EnvioGraphQLClient.md +309 -0
- package/docs/classes/GameMaster.md +8 -0
- package/docs/classes/InstanceBase.md +16 -8
- package/docs/classes/InstancePlayer.md +22 -10
- package/docs/classes/MAODistributorClient.md +36 -27
- package/docs/docs/classes/EnvioGraphQLClient.md +309 -0
- package/docs/docs/classes/GameMaster.md +8 -0
- package/docs/docs/classes/InstanceBase.md +16 -8
- package/docs/docs/classes/InstancePlayer.md +22 -10
- package/docs/docs/classes/MAODistributorClient.md +36 -27
- package/docs/docs/index.md +5 -2
- package/docs/docs/interfaces/EnvioGraphQLClientConfig.md +41 -0
- package/docs/docs/interfaces/MAOInstanceArgs.md +29 -0
- package/docs/index.md +5 -2
- package/docs/interfaces/EnvioGraphQLClientConfig.md +41 -0
- package/docs/interfaces/MAOInstanceArgs.md +29 -0
- package/lib.commonjs/eds/Distributor.d.ts +5 -3
- package/lib.commonjs/eds/Distributor.d.ts.map +1 -1
- package/lib.commonjs/eds/Distributor.js +19 -29
- package/lib.commonjs/eds/Distributor.js.map +1 -1
- package/lib.commonjs/index.d.ts +1 -0
- package/lib.commonjs/index.d.ts.map +1 -1
- package/lib.commonjs/index.js +4 -1
- package/lib.commonjs/index.js.map +1 -1
- package/lib.commonjs/rankify/GameMaster.d.ts +6 -2
- package/lib.commonjs/rankify/GameMaster.d.ts.map +1 -1
- package/lib.commonjs/rankify/GameMaster.js +43 -39
- package/lib.commonjs/rankify/GameMaster.js.map +1 -1
- package/lib.commonjs/rankify/InstanceBase.d.ts +46 -9442
- package/lib.commonjs/rankify/InstanceBase.d.ts.map +1 -1
- package/lib.commonjs/rankify/InstanceBase.js +102 -130
- package/lib.commonjs/rankify/InstanceBase.js.map +1 -1
- package/lib.commonjs/rankify/MAODistributor.d.ts +24 -16
- package/lib.commonjs/rankify/MAODistributor.d.ts.map +1 -1
- package/lib.commonjs/rankify/MAODistributor.js +45 -54
- package/lib.commonjs/rankify/MAODistributor.js.map +1 -1
- package/lib.commonjs/rankify/Player.d.ts +4 -2
- package/lib.commonjs/rankify/Player.d.ts.map +1 -1
- package/lib.commonjs/rankify/Player.js +4 -6
- package/lib.commonjs/rankify/Player.js.map +1 -1
- package/lib.commonjs/utils/EnvioGraphQLClient.d.ts +273 -0
- package/lib.commonjs/utils/EnvioGraphQLClient.d.ts.map +1 -0
- package/lib.commonjs/utils/EnvioGraphQLClient.js +730 -0
- package/lib.commonjs/utils/EnvioGraphQLClient.js.map +1 -0
- package/lib.commonjs/utils/index.d.ts +1 -1
- package/lib.commonjs/utils/index.d.ts.map +1 -1
- package/lib.commonjs/utils/index.js.map +1 -1
- package/lib.commonjs/utils/logger.d.ts +12 -0
- package/lib.commonjs/utils/logger.d.ts.map +1 -0
- package/lib.commonjs/utils/logger.js +12 -0
- package/lib.commonjs/utils/logger.js.map +1 -0
- package/lib.commonjs/utils/mockUtils.d.ts +39 -0
- package/lib.commonjs/utils/mockUtils.d.ts.map +1 -0
- package/lib.commonjs/utils/mockUtils.js +103 -0
- package/lib.commonjs/utils/mockUtils.js.map +1 -0
- package/lib.esm/eds/Distributor.d.ts +5 -3
- package/lib.esm/eds/Distributor.d.ts.map +1 -1
- package/lib.esm/eds/Distributor.js +20 -30
- package/lib.esm/eds/Distributor.js.map +1 -1
- package/lib.esm/index.d.ts +1 -0
- package/lib.esm/index.d.ts.map +1 -1
- package/lib.esm/index.js +2 -0
- package/lib.esm/index.js.map +1 -1
- package/lib.esm/rankify/GameMaster.d.ts +6 -2
- package/lib.esm/rankify/GameMaster.d.ts.map +1 -1
- package/lib.esm/rankify/GameMaster.js +43 -39
- package/lib.esm/rankify/GameMaster.js.map +1 -1
- package/lib.esm/rankify/InstanceBase.d.ts +46 -9442
- package/lib.esm/rankify/InstanceBase.d.ts.map +1 -1
- package/lib.esm/rankify/InstanceBase.js +102 -130
- package/lib.esm/rankify/InstanceBase.js.map +1 -1
- package/lib.esm/rankify/MAODistributor.d.ts +24 -16
- package/lib.esm/rankify/MAODistributor.d.ts.map +1 -1
- package/lib.esm/rankify/MAODistributor.js +37 -46
- package/lib.esm/rankify/MAODistributor.js.map +1 -1
- package/lib.esm/rankify/Player.d.ts +4 -2
- package/lib.esm/rankify/Player.d.ts.map +1 -1
- package/lib.esm/rankify/Player.js +5 -7
- package/lib.esm/rankify/Player.js.map +1 -1
- package/lib.esm/utils/EnvioGraphQLClient.d.ts +273 -0
- package/lib.esm/utils/EnvioGraphQLClient.d.ts.map +1 -0
- package/lib.esm/utils/EnvioGraphQLClient.js +726 -0
- package/lib.esm/utils/EnvioGraphQLClient.js.map +1 -0
- package/lib.esm/utils/index.d.ts +1 -1
- package/lib.esm/utils/index.d.ts.map +1 -1
- package/lib.esm/utils/index.js.map +1 -1
- package/lib.esm/utils/logger.d.ts +12 -0
- package/lib.esm/utils/logger.d.ts.map +1 -0
- package/lib.esm/utils/logger.js +12 -0
- package/lib.esm/utils/logger.js.map +1 -0
- package/lib.esm/utils/mockUtils.d.ts +39 -0
- package/lib.esm/utils/mockUtils.d.ts.map +1 -0
- package/lib.esm/utils/mockUtils.js +96 -0
- package/lib.esm/utils/mockUtils.js.map +1 -0
- package/package.json +3 -1
- package/cli/cli/helpers.js +0 -64
- package/cli/cli/helpers.js.map +0 -1
|
@@ -0,0 +1,728 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EnvioGraphQLClient = void 0;
|
|
4
|
+
const graphql_request_1 = require("graphql-request");
|
|
5
|
+
const logger_1 = require("./logger");
|
|
6
|
+
/**
|
|
7
|
+
* Default Envio GraphQL client configuration
|
|
8
|
+
*/
|
|
9
|
+
const DEFAULT_CONFIG = {
|
|
10
|
+
endpoint: process.env.INDEXER_URL || "http://localhost:8080/v1/graphql",
|
|
11
|
+
fallbackToRPC: true,
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Client for interacting with Envio GraphQL API to retrieve indexed blockchain events
|
|
15
|
+
*/
|
|
16
|
+
class EnvioGraphQLClient {
|
|
17
|
+
/**
|
|
18
|
+
* Create a new Envio GraphQL client
|
|
19
|
+
* @param config - Optional configuration for the client
|
|
20
|
+
*/
|
|
21
|
+
constructor(config = {}) {
|
|
22
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
23
|
+
// Log the endpoint we're using
|
|
24
|
+
console.debug(`Initializing EnvioGraphQLClient with endpoint: ${this.config.endpoint}`);
|
|
25
|
+
if (this.config.endpoint === DEFAULT_CONFIG.endpoint) {
|
|
26
|
+
console.debug(`Using default endpoint ${DEFAULT_CONFIG.endpoint}. Set INDEXER_URL environment variable to override.`);
|
|
27
|
+
}
|
|
28
|
+
const headers = {
|
|
29
|
+
"Content-Type": "application/json",
|
|
30
|
+
};
|
|
31
|
+
if (this.config.apiKey) {
|
|
32
|
+
headers["Authorization"] = `Bearer ${this.config.apiKey}`;
|
|
33
|
+
}
|
|
34
|
+
this.client = new graphql_request_1.GraphQLClient(this.config.endpoint, {
|
|
35
|
+
headers,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get GameCreated events for a specific creator or game ID
|
|
40
|
+
*/
|
|
41
|
+
async getGameCreatedEvents({ creator, gameId, gm, contractAddress, limit = 10, offset = 0, }) {
|
|
42
|
+
try {
|
|
43
|
+
// Use direct string interpolation for the query - no variables for numeric fields
|
|
44
|
+
const gameIdStr = gameId !== undefined ? gameId.toString() : undefined;
|
|
45
|
+
// Build where conditions
|
|
46
|
+
const whereParts = [];
|
|
47
|
+
if (creator) {
|
|
48
|
+
whereParts.push(`creator: { _eq: "${creator}" }`);
|
|
49
|
+
}
|
|
50
|
+
if (gameIdStr !== undefined) {
|
|
51
|
+
whereParts.push(`gameId: { _eq: ${gameIdStr} }`);
|
|
52
|
+
}
|
|
53
|
+
if (gm) {
|
|
54
|
+
whereParts.push(`gm: { _eq: "${gm}" }`);
|
|
55
|
+
}
|
|
56
|
+
if (contractAddress) {
|
|
57
|
+
whereParts.push(`srcAddress: { _eq: "${contractAddress}" }`);
|
|
58
|
+
}
|
|
59
|
+
const whereClause = whereParts.length > 0 ? whereParts.join(", ") : "";
|
|
60
|
+
// Simpler query with direct string literals instead of variables
|
|
61
|
+
const query = (0, graphql_request_1.gql) `
|
|
62
|
+
query {
|
|
63
|
+
RankifyInstance_gameCreated(
|
|
64
|
+
where: {
|
|
65
|
+
${whereClause}
|
|
66
|
+
}
|
|
67
|
+
limit: ${limit}
|
|
68
|
+
offset: ${offset}
|
|
69
|
+
order_by: { blockTimestamp: desc }
|
|
70
|
+
) {
|
|
71
|
+
id
|
|
72
|
+
gameId
|
|
73
|
+
gm
|
|
74
|
+
creator
|
|
75
|
+
rank
|
|
76
|
+
blockNumber
|
|
77
|
+
blockTimestamp
|
|
78
|
+
srcAddress
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
`;
|
|
82
|
+
const result = await this.client.request(query);
|
|
83
|
+
return result.RankifyInstance_gameCreated.map((event) => ({
|
|
84
|
+
...event,
|
|
85
|
+
gameId: BigInt(event.gameId),
|
|
86
|
+
rank: BigInt(event.rank),
|
|
87
|
+
blockNumber: BigInt(event.blockNumber),
|
|
88
|
+
contractAddress: event.srcAddress,
|
|
89
|
+
gm: event.gm,
|
|
90
|
+
creator: event.creator,
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
console.error("Error fetching game created events:", error);
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Get player joined events for a specific game and participant
|
|
100
|
+
*/
|
|
101
|
+
async getPlayerJoinedEvents({ gameId, participant, contractAddress, }) {
|
|
102
|
+
try {
|
|
103
|
+
// Use direct string interpolation for the query - no variables for numeric fields
|
|
104
|
+
const gameIdStr = gameId.toString();
|
|
105
|
+
// Build where conditions
|
|
106
|
+
const whereParts = [];
|
|
107
|
+
whereParts.push(`gameId: { _eq: ${gameIdStr} }`);
|
|
108
|
+
if (participant) {
|
|
109
|
+
whereParts.push(`participant: { _eq: "${participant}" }`);
|
|
110
|
+
}
|
|
111
|
+
if (contractAddress) {
|
|
112
|
+
whereParts.push(`srcAddress: { _eq: "${contractAddress}" }`);
|
|
113
|
+
}
|
|
114
|
+
const whereClause = whereParts.join(", ");
|
|
115
|
+
// Simpler query with direct string literals instead of variables
|
|
116
|
+
const query = (0, graphql_request_1.gql) `
|
|
117
|
+
query {
|
|
118
|
+
RankifyInstance_PlayerJoined(
|
|
119
|
+
where: {
|
|
120
|
+
${whereClause}
|
|
121
|
+
}
|
|
122
|
+
order_by: { blockTimestamp: asc }
|
|
123
|
+
) {
|
|
124
|
+
id
|
|
125
|
+
gameId
|
|
126
|
+
participant
|
|
127
|
+
gmCommitment
|
|
128
|
+
voterPubKey
|
|
129
|
+
blockNumber
|
|
130
|
+
blockTimestamp
|
|
131
|
+
srcAddress
|
|
132
|
+
transactionIndex
|
|
133
|
+
logIndex
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
`;
|
|
137
|
+
const result = await this.client.request(query);
|
|
138
|
+
return result.RankifyInstance_PlayerJoined.map((event) => ({
|
|
139
|
+
...event,
|
|
140
|
+
gameId: BigInt(event.gameId),
|
|
141
|
+
blockNumber: BigInt(event.blockNumber),
|
|
142
|
+
contractAddress: event.srcAddress,
|
|
143
|
+
participant: event.participant,
|
|
144
|
+
transactionIndex: event.transactionIndex,
|
|
145
|
+
logIndex: event.logIndex,
|
|
146
|
+
}));
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
console.error("Error fetching player joined events:", error);
|
|
150
|
+
throw error;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Get proposal submitted events for a specific game and turn
|
|
155
|
+
*/
|
|
156
|
+
async getProposalSubmittedEvents({ gameId, turn, proposer, contractAddress, }) {
|
|
157
|
+
try {
|
|
158
|
+
// Use direct string interpolation for the query - no variables for numeric fields
|
|
159
|
+
const gameIdStr = gameId.toString();
|
|
160
|
+
const turnStr = turn !== undefined ? turn.toString() : undefined;
|
|
161
|
+
// Build where conditions
|
|
162
|
+
const whereParts = [];
|
|
163
|
+
whereParts.push(`gameId: { _eq: ${gameIdStr} }`);
|
|
164
|
+
if (turnStr !== undefined) {
|
|
165
|
+
whereParts.push(`turn: { _eq: ${turnStr} }`);
|
|
166
|
+
}
|
|
167
|
+
if (proposer) {
|
|
168
|
+
whereParts.push(`proposer: { _eq: "${proposer}" }`);
|
|
169
|
+
}
|
|
170
|
+
if (contractAddress) {
|
|
171
|
+
whereParts.push(`srcAddress: { _eq: "${contractAddress}" }`);
|
|
172
|
+
}
|
|
173
|
+
const whereClause = whereParts.join(", ");
|
|
174
|
+
// Simpler query with direct string literals instead of variables
|
|
175
|
+
const query = (0, graphql_request_1.gql) `
|
|
176
|
+
query {
|
|
177
|
+
RankifyInstance_ProposalSubmitted(
|
|
178
|
+
where: {
|
|
179
|
+
${whereClause}
|
|
180
|
+
}
|
|
181
|
+
order_by: { blockTimestamp: asc }
|
|
182
|
+
) {
|
|
183
|
+
id
|
|
184
|
+
gameId
|
|
185
|
+
turn
|
|
186
|
+
proposer
|
|
187
|
+
commitment
|
|
188
|
+
encryptedProposal
|
|
189
|
+
gmSignature
|
|
190
|
+
proposerSignature
|
|
191
|
+
blockNumber
|
|
192
|
+
blockTimestamp
|
|
193
|
+
srcAddress
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
`;
|
|
197
|
+
const result = await this.client.request(query);
|
|
198
|
+
return result.RankifyInstance_ProposalSubmitted.map((event) => ({
|
|
199
|
+
...event,
|
|
200
|
+
gameId: BigInt(event.gameId),
|
|
201
|
+
turn: BigInt(event.turn),
|
|
202
|
+
commitment: BigInt(event.commitment),
|
|
203
|
+
blockNumber: BigInt(event.blockNumber),
|
|
204
|
+
contractAddress: event.srcAddress,
|
|
205
|
+
proposer: event.proposer,
|
|
206
|
+
}));
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
console.error("Error fetching proposal submitted events:", error);
|
|
210
|
+
throw error;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Get vote submitted events for a specific game and turn
|
|
215
|
+
*/
|
|
216
|
+
async getVoteSubmittedEvents({ gameId, turn, player, contractAddress, }) {
|
|
217
|
+
try {
|
|
218
|
+
// Use direct string interpolation for the query - no variables for numeric fields
|
|
219
|
+
const gameIdStr = gameId.toString();
|
|
220
|
+
const turnStr = turn !== undefined ? turn.toString() : undefined;
|
|
221
|
+
// Build where conditions
|
|
222
|
+
const whereParts = [];
|
|
223
|
+
whereParts.push(`gameId: { _eq: ${gameIdStr} }`);
|
|
224
|
+
if (turnStr !== undefined) {
|
|
225
|
+
whereParts.push(`turn: { _eq: ${turnStr} }`);
|
|
226
|
+
}
|
|
227
|
+
if (player) {
|
|
228
|
+
whereParts.push(`player: { _eq: "${player}" }`);
|
|
229
|
+
}
|
|
230
|
+
if (contractAddress) {
|
|
231
|
+
whereParts.push(`srcAddress: { _eq: "${contractAddress}" }`);
|
|
232
|
+
}
|
|
233
|
+
const whereClause = whereParts.join(", ");
|
|
234
|
+
// Simpler query with direct string literals instead of variables
|
|
235
|
+
const query = (0, graphql_request_1.gql) `
|
|
236
|
+
query {
|
|
237
|
+
RankifyInstance_VoteSubmitted(
|
|
238
|
+
where: {
|
|
239
|
+
${whereClause}
|
|
240
|
+
}
|
|
241
|
+
order_by: { blockTimestamp: asc }
|
|
242
|
+
) {
|
|
243
|
+
id
|
|
244
|
+
gameId
|
|
245
|
+
turn
|
|
246
|
+
player
|
|
247
|
+
sealedBallotId
|
|
248
|
+
gmSignature
|
|
249
|
+
voterSignature
|
|
250
|
+
ballotHash
|
|
251
|
+
blockNumber
|
|
252
|
+
blockTimestamp
|
|
253
|
+
srcAddress
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
`;
|
|
257
|
+
const result = await this.client.request(query);
|
|
258
|
+
return result.RankifyInstance_VoteSubmitted.map((event) => ({
|
|
259
|
+
...event,
|
|
260
|
+
gameId: BigInt(event.gameId),
|
|
261
|
+
turn: BigInt(event.turn),
|
|
262
|
+
blockNumber: BigInt(event.blockNumber),
|
|
263
|
+
contractAddress: event.srcAddress,
|
|
264
|
+
player: event.player,
|
|
265
|
+
}));
|
|
266
|
+
}
|
|
267
|
+
catch (error) {
|
|
268
|
+
console.error("Error fetching vote submitted events:", error);
|
|
269
|
+
throw error;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Get registration open events for a specific game
|
|
274
|
+
*/
|
|
275
|
+
async getRegistrationOpenEvents({ gameId, contractAddress }) {
|
|
276
|
+
try {
|
|
277
|
+
// Use direct string interpolation for the query - no variables for numeric fields
|
|
278
|
+
const gameIdStr = gameId.toString();
|
|
279
|
+
// Build where conditions
|
|
280
|
+
const whereParts = [];
|
|
281
|
+
whereParts.push(`gameId: { _eq: ${gameIdStr} }`);
|
|
282
|
+
if (contractAddress) {
|
|
283
|
+
whereParts.push(`srcAddress: { _eq: "${contractAddress}" }`);
|
|
284
|
+
}
|
|
285
|
+
const whereClause = whereParts.join(", ");
|
|
286
|
+
// Simpler query with direct string literals instead of variables
|
|
287
|
+
const query = (0, graphql_request_1.gql) `
|
|
288
|
+
query {
|
|
289
|
+
RankifyInstance_RegistrationOpen(
|
|
290
|
+
where: {
|
|
291
|
+
${whereClause}
|
|
292
|
+
},
|
|
293
|
+
limit: 1
|
|
294
|
+
) {
|
|
295
|
+
id
|
|
296
|
+
gameId
|
|
297
|
+
blockNumber
|
|
298
|
+
blockTimestamp
|
|
299
|
+
srcAddress
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
`;
|
|
303
|
+
const result = await this.client.request(query);
|
|
304
|
+
return result.RankifyInstance_RegistrationOpen.map((event) => ({
|
|
305
|
+
...event,
|
|
306
|
+
gameId: BigInt(event.gameId),
|
|
307
|
+
blockNumber: BigInt(event.blockNumber),
|
|
308
|
+
contractAddress: event.srcAddress,
|
|
309
|
+
}));
|
|
310
|
+
}
|
|
311
|
+
catch (error) {
|
|
312
|
+
console.error("Error fetching registration open events:", error);
|
|
313
|
+
throw error;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Get turn ended events for a specific game and turn
|
|
318
|
+
*/
|
|
319
|
+
async getTurnEndedEvents({ gameId, turn, contractAddress, }) {
|
|
320
|
+
try {
|
|
321
|
+
// Use direct string interpolation for the query - no variables for numeric fields
|
|
322
|
+
const gameIdStr = gameId.toString();
|
|
323
|
+
const turnStr = turn !== undefined ? turn.toString() : undefined;
|
|
324
|
+
// Build where conditions
|
|
325
|
+
const whereParts = [];
|
|
326
|
+
whereParts.push(`gameId: { _eq: ${gameIdStr} }`);
|
|
327
|
+
if (turnStr !== undefined) {
|
|
328
|
+
whereParts.push(`turn: { _eq: ${turnStr} }`);
|
|
329
|
+
}
|
|
330
|
+
if (contractAddress) {
|
|
331
|
+
whereParts.push(`srcAddress: { _eq: "${contractAddress}" }`);
|
|
332
|
+
}
|
|
333
|
+
const whereClause = whereParts.join(", ");
|
|
334
|
+
// Simpler query with direct string literals instead of variables
|
|
335
|
+
const query = (0, graphql_request_1.gql) `
|
|
336
|
+
query {
|
|
337
|
+
RankifyInstance_TurnEnded(
|
|
338
|
+
where: {
|
|
339
|
+
${whereClause}
|
|
340
|
+
}
|
|
341
|
+
order_by: { turn: desc }
|
|
342
|
+
limit: 1
|
|
343
|
+
) {
|
|
344
|
+
id
|
|
345
|
+
gameId
|
|
346
|
+
turn
|
|
347
|
+
players
|
|
348
|
+
scores
|
|
349
|
+
newProposals
|
|
350
|
+
proposerIndices
|
|
351
|
+
votes
|
|
352
|
+
blockNumber
|
|
353
|
+
blockTimestamp
|
|
354
|
+
srcAddress
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
`;
|
|
358
|
+
const result = await this.client.request(query);
|
|
359
|
+
return result.RankifyInstance_TurnEnded.map((event) => ({
|
|
360
|
+
...event,
|
|
361
|
+
gameId: BigInt(event.gameId),
|
|
362
|
+
turn: BigInt(event.turn),
|
|
363
|
+
scores: event.scores.map((score) => BigInt(score)),
|
|
364
|
+
proposerIndices: event.proposerIndices.map((index) => BigInt(index)),
|
|
365
|
+
votes: event.votes.map((row) => row.map((vote) => BigInt(vote))),
|
|
366
|
+
blockNumber: BigInt(event.blockNumber),
|
|
367
|
+
contractAddress: event.srcAddress,
|
|
368
|
+
players: event.players.map((player) => player),
|
|
369
|
+
}));
|
|
370
|
+
}
|
|
371
|
+
catch (error) {
|
|
372
|
+
console.error("Error fetching turn ended events:", error);
|
|
373
|
+
throw error;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Get proposal score events for a specific game and turn
|
|
378
|
+
*/
|
|
379
|
+
async getProposalScoreEvents({ gameId, turn, contractAddress, }) {
|
|
380
|
+
try {
|
|
381
|
+
// Use direct string interpolation for the query - no variables for numeric fields
|
|
382
|
+
const gameIdStr = gameId.toString();
|
|
383
|
+
const turnStr = turn !== undefined ? turn.toString() : undefined;
|
|
384
|
+
// Build where conditions
|
|
385
|
+
const whereParts = [];
|
|
386
|
+
whereParts.push(`gameId: { _eq: ${gameIdStr} }`);
|
|
387
|
+
if (turnStr !== undefined) {
|
|
388
|
+
whereParts.push(`turn: { _eq: ${turnStr} }`);
|
|
389
|
+
}
|
|
390
|
+
if (contractAddress) {
|
|
391
|
+
whereParts.push(`srcAddress: { _eq: "${contractAddress}" }`);
|
|
392
|
+
}
|
|
393
|
+
const whereClause = whereParts.join(", ");
|
|
394
|
+
// Simpler query with direct string literals instead of variables
|
|
395
|
+
const query = (0, graphql_request_1.gql) `
|
|
396
|
+
query {
|
|
397
|
+
RankifyInstance_ProposalScore(
|
|
398
|
+
where: {
|
|
399
|
+
${whereClause}
|
|
400
|
+
}
|
|
401
|
+
order_by: { blockTimestamp: desc }
|
|
402
|
+
) {
|
|
403
|
+
id
|
|
404
|
+
gameId
|
|
405
|
+
turn
|
|
406
|
+
proposalHash
|
|
407
|
+
proposal
|
|
408
|
+
score
|
|
409
|
+
blockNumber
|
|
410
|
+
blockTimestamp
|
|
411
|
+
srcAddress
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
`;
|
|
415
|
+
const result = await this.client.request(query);
|
|
416
|
+
return result.RankifyInstance_ProposalScore.map((event) => ({
|
|
417
|
+
...event,
|
|
418
|
+
gameId: BigInt(event.gameId),
|
|
419
|
+
turn: BigInt(event.turn),
|
|
420
|
+
score: BigInt(event.score),
|
|
421
|
+
blockNumber: BigInt(event.blockNumber),
|
|
422
|
+
contractAddress: event.srcAddress,
|
|
423
|
+
}));
|
|
424
|
+
}
|
|
425
|
+
catch (error) {
|
|
426
|
+
console.error("Error fetching proposal score events:", error);
|
|
427
|
+
throw error;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Get game over events for a specific game
|
|
432
|
+
*/
|
|
433
|
+
async getGameOverEvents({ gameId, contractAddress }) {
|
|
434
|
+
try {
|
|
435
|
+
// Use direct string interpolation for the query - no variables for numeric fields
|
|
436
|
+
const gameIdStr = gameId.toString();
|
|
437
|
+
// Build where conditions
|
|
438
|
+
const whereParts = [];
|
|
439
|
+
whereParts.push(`gameId: { _eq: ${gameIdStr} }`);
|
|
440
|
+
if (contractAddress) {
|
|
441
|
+
whereParts.push(`srcAddress: { _eq: "${contractAddress}" }`);
|
|
442
|
+
}
|
|
443
|
+
const whereClause = whereParts.join(", ");
|
|
444
|
+
// Simpler query with direct string literals instead of variables
|
|
445
|
+
const query = (0, graphql_request_1.gql) `
|
|
446
|
+
query {
|
|
447
|
+
RankifyInstance_GameOver(
|
|
448
|
+
where: {
|
|
449
|
+
${whereClause}
|
|
450
|
+
},
|
|
451
|
+
limit: 1
|
|
452
|
+
) {
|
|
453
|
+
id
|
|
454
|
+
gameId
|
|
455
|
+
players
|
|
456
|
+
scores
|
|
457
|
+
blockNumber
|
|
458
|
+
blockTimestamp
|
|
459
|
+
srcAddress
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
`;
|
|
463
|
+
const result = await this.client.request(query);
|
|
464
|
+
return result.RankifyInstance_GameOver.map((event) => ({
|
|
465
|
+
...event,
|
|
466
|
+
gameId: BigInt(event.gameId),
|
|
467
|
+
scores: event.scores.map((score) => BigInt(score)),
|
|
468
|
+
blockNumber: BigInt(event.blockNumber),
|
|
469
|
+
contractAddress: event.srcAddress,
|
|
470
|
+
players: event.players.map((player) => player),
|
|
471
|
+
}));
|
|
472
|
+
}
|
|
473
|
+
catch (error) {
|
|
474
|
+
console.error("Error fetching game over events:", error);
|
|
475
|
+
throw error;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Get game started events for a specific game
|
|
480
|
+
*/
|
|
481
|
+
async getGameStartedEvents({ gameId, contractAddress }) {
|
|
482
|
+
try {
|
|
483
|
+
// Use direct string interpolation for the query - no variables for numeric fields
|
|
484
|
+
const gameIdStr = gameId.toString();
|
|
485
|
+
// Build where conditions
|
|
486
|
+
const whereParts = [];
|
|
487
|
+
whereParts.push(`gameId: { _eq: ${gameIdStr} }`);
|
|
488
|
+
if (contractAddress) {
|
|
489
|
+
whereParts.push(`srcAddress: { _eq: "${contractAddress}" }`);
|
|
490
|
+
}
|
|
491
|
+
const whereClause = whereParts.join(", ");
|
|
492
|
+
// Simpler query with direct string literals instead of variables
|
|
493
|
+
const query = (0, graphql_request_1.gql) `
|
|
494
|
+
query {
|
|
495
|
+
RankifyInstance_GameStarted(
|
|
496
|
+
where: {
|
|
497
|
+
${whereClause}
|
|
498
|
+
},
|
|
499
|
+
limit: 1,
|
|
500
|
+
order_by: { blockTimestamp: desc }
|
|
501
|
+
) {
|
|
502
|
+
id
|
|
503
|
+
gameId
|
|
504
|
+
blockNumber
|
|
505
|
+
blockTimestamp
|
|
506
|
+
srcAddress
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
`;
|
|
510
|
+
const result = await this.client.request(query);
|
|
511
|
+
return result.RankifyInstance_GameStarted.map((event) => ({
|
|
512
|
+
...event,
|
|
513
|
+
gameId: BigInt(event.gameId),
|
|
514
|
+
blockNumber: BigInt(event.blockNumber),
|
|
515
|
+
contractAddress: event.srcAddress,
|
|
516
|
+
}));
|
|
517
|
+
}
|
|
518
|
+
catch (error) {
|
|
519
|
+
console.error("Error fetching game started events:", error);
|
|
520
|
+
throw error;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* Query MAO instances from the Envio GraphQL API
|
|
525
|
+
* @param params Query parameters for filtering instances
|
|
526
|
+
* @returns Array of MAO instance data
|
|
527
|
+
*/
|
|
528
|
+
async queryInstances(params) {
|
|
529
|
+
try {
|
|
530
|
+
// Convert parameters to strings
|
|
531
|
+
const instanceIdStr = params.instanceId ? params.instanceId.toString() : undefined;
|
|
532
|
+
const distributionIdStr = params.distributionId || undefined;
|
|
533
|
+
// Build where conditions using the proper Envio GraphQL syntax
|
|
534
|
+
const conditions = [];
|
|
535
|
+
// Add simple equality conditions using _eq operator
|
|
536
|
+
if (instanceIdStr) {
|
|
537
|
+
conditions.push(`newInstanceId: { _eq: "${instanceIdStr}" }`);
|
|
538
|
+
}
|
|
539
|
+
if (distributionIdStr) {
|
|
540
|
+
conditions.push(`distributionId: { _eq: "${distributionIdStr}" }`);
|
|
541
|
+
}
|
|
542
|
+
// For a simple query, let's just use these two main identifiers
|
|
543
|
+
// and filter the results client-side for other criteria
|
|
544
|
+
console.log("Querying DAODistributor_Instantiated with params:", {
|
|
545
|
+
instanceId: instanceIdStr,
|
|
546
|
+
distributionId: distributionIdStr,
|
|
547
|
+
});
|
|
548
|
+
const query = (0, graphql_request_1.gql) `
|
|
549
|
+
query {
|
|
550
|
+
DAODistributor_Instantiated(
|
|
551
|
+
where: {
|
|
552
|
+
${conditions.length > 0 ? conditions.join(", ") : ""}
|
|
553
|
+
}
|
|
554
|
+
order_by: { blockTimestamp: desc }
|
|
555
|
+
limit: ${instanceIdStr ? 1 : 100}
|
|
556
|
+
) {
|
|
557
|
+
id
|
|
558
|
+
distributionId
|
|
559
|
+
newInstanceId
|
|
560
|
+
instances
|
|
561
|
+
args
|
|
562
|
+
blockNumber
|
|
563
|
+
blockTimestamp
|
|
564
|
+
version
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
`;
|
|
568
|
+
// Log the query for debugging (as a string)
|
|
569
|
+
(0, logger_1.logger)("GraphQL query:", 3);
|
|
570
|
+
(0, logger_1.logger)(query, 3);
|
|
571
|
+
const result = await this.client.request(query);
|
|
572
|
+
if (!result.DAODistributor_Instantiated || result.DAODistributor_Instantiated.length === 0) {
|
|
573
|
+
(0, logger_1.logger)("No instances found with the given parameters", 3);
|
|
574
|
+
return [];
|
|
575
|
+
}
|
|
576
|
+
(0, logger_1.logger)(`Found ${result.DAODistributor_Instantiated.length} instance(s)`, 3);
|
|
577
|
+
// Filter results client-side based on additional criteria
|
|
578
|
+
let results = result.DAODistributor_Instantiated;
|
|
579
|
+
// Return the filtered results
|
|
580
|
+
return results.map((event) => ({
|
|
581
|
+
distributionId: event.distributionId,
|
|
582
|
+
newInstanceId: event.newInstanceId,
|
|
583
|
+
version: event.version,
|
|
584
|
+
instances: event.instances,
|
|
585
|
+
args: event.args,
|
|
586
|
+
blockNumber: event.blockNumber,
|
|
587
|
+
blockTimestamp: event.blockTimestamp,
|
|
588
|
+
}));
|
|
589
|
+
}
|
|
590
|
+
catch (error) {
|
|
591
|
+
console.error("Error querying instances:", error);
|
|
592
|
+
// Log more details about the error to help diagnose issues
|
|
593
|
+
if (error instanceof Error) {
|
|
594
|
+
console.error("Error message:", error.message);
|
|
595
|
+
console.error("Error stack:", error.stack);
|
|
596
|
+
}
|
|
597
|
+
if (typeof error === 'object' &&
|
|
598
|
+
error !== null &&
|
|
599
|
+
'response' in error &&
|
|
600
|
+
typeof error.response === 'object' &&
|
|
601
|
+
error.response !== null &&
|
|
602
|
+
'status' in error.response &&
|
|
603
|
+
error.response.status === 404) {
|
|
604
|
+
console.error("Server returned 404 - Check if the Envio indexer is running and accessible at", this.config.endpoint);
|
|
605
|
+
}
|
|
606
|
+
else if (typeof error === 'object' &&
|
|
607
|
+
error !== null &&
|
|
608
|
+
'response' in error &&
|
|
609
|
+
typeof error.response === 'object' &&
|
|
610
|
+
error.response !== null &&
|
|
611
|
+
'errors' in error.response) {
|
|
612
|
+
console.error("GraphQL errors:", error.response.errors);
|
|
613
|
+
}
|
|
614
|
+
throw error;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Get multiple game states with pagination
|
|
619
|
+
*/
|
|
620
|
+
async getGameStates({ skip = 0, first = 10, orderDirection = "desc", contractAddress, }) {
|
|
621
|
+
const variables = {
|
|
622
|
+
limit: first,
|
|
623
|
+
offset: skip,
|
|
624
|
+
contractAddress: contractAddress,
|
|
625
|
+
};
|
|
626
|
+
const query = (0, graphql_request_1.gql) `
|
|
627
|
+
query GetGames($limit: Int, $offset: Int, $contractAddress: String) {
|
|
628
|
+
RankifyInstance_gameCreated(
|
|
629
|
+
where: {
|
|
630
|
+
srcAddress: { _eq: $contractAddress }
|
|
631
|
+
}
|
|
632
|
+
limit: $limit
|
|
633
|
+
offset: $offset
|
|
634
|
+
order_by: { blockTimestamp: ${orderDirection} }
|
|
635
|
+
) {
|
|
636
|
+
gameId
|
|
637
|
+
gm
|
|
638
|
+
creator
|
|
639
|
+
rank
|
|
640
|
+
blockNumber
|
|
641
|
+
blockTimestamp
|
|
642
|
+
srcAddress
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
`;
|
|
646
|
+
try {
|
|
647
|
+
const result = await this.client.request(query, variables);
|
|
648
|
+
// Fetch additional state info for each game
|
|
649
|
+
const gameStates = await Promise.all(result.RankifyInstance_gameCreated.map(async (game) => {
|
|
650
|
+
const gameId = BigInt(game.gameId);
|
|
651
|
+
const [turnEndedEvents, gameOverEvents] = await Promise.all([
|
|
652
|
+
this.getTurnEndedEvents({ gameId, contractAddress }),
|
|
653
|
+
this.getGameOverEvents({ gameId, contractAddress }),
|
|
654
|
+
]);
|
|
655
|
+
// Determine current state
|
|
656
|
+
const turn = turnEndedEvents.length > 0 ? turnEndedEvents[0].turn + 1n : 0n;
|
|
657
|
+
const hasStarted = turn > 0n;
|
|
658
|
+
const isLastTurn = gameOverEvents.length > 0;
|
|
659
|
+
const hasEnded = gameOverEvents.length > 0;
|
|
660
|
+
return {
|
|
661
|
+
gameId,
|
|
662
|
+
gm: game.gm,
|
|
663
|
+
creator: game.creator,
|
|
664
|
+
rank: BigInt(game.rank),
|
|
665
|
+
turn,
|
|
666
|
+
hasStarted,
|
|
667
|
+
isLastTurn,
|
|
668
|
+
hasEnded,
|
|
669
|
+
createdAt: game.blockTimestamp,
|
|
670
|
+
contractAddress,
|
|
671
|
+
};
|
|
672
|
+
}));
|
|
673
|
+
return gameStates;
|
|
674
|
+
}
|
|
675
|
+
catch (error) {
|
|
676
|
+
console.error("Error fetching game states:", error);
|
|
677
|
+
throw error;
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
/**
|
|
681
|
+
* Get MAO instances for a specific distribution
|
|
682
|
+
*/
|
|
683
|
+
async getMAOInstances({ distributionId, contractAddress, }) {
|
|
684
|
+
try {
|
|
685
|
+
// Build where conditions
|
|
686
|
+
const whereParts = [];
|
|
687
|
+
whereParts.push(`distributionId: { _eq: "${distributionId}" }`);
|
|
688
|
+
if (contractAddress) {
|
|
689
|
+
whereParts.push(`srcAddress: { _eq: "${contractAddress}" }`);
|
|
690
|
+
}
|
|
691
|
+
const whereClause = whereParts.join(", ");
|
|
692
|
+
// Simpler query with direct string literals instead of variables
|
|
693
|
+
const query = (0, graphql_request_1.gql) `
|
|
694
|
+
query {
|
|
695
|
+
DAODistributor_Instantiated(
|
|
696
|
+
where: {
|
|
697
|
+
${whereClause}
|
|
698
|
+
}
|
|
699
|
+
order_by: { blockTimestamp: desc }
|
|
700
|
+
) {
|
|
701
|
+
id
|
|
702
|
+
distributionId
|
|
703
|
+
newInstanceId
|
|
704
|
+
instances
|
|
705
|
+
args
|
|
706
|
+
blockNumber
|
|
707
|
+
blockTimestamp
|
|
708
|
+
version
|
|
709
|
+
srcAddress
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
`;
|
|
713
|
+
const result = await this.client.request(query);
|
|
714
|
+
return result.DAODistributor_Instantiated.map((event) => ({
|
|
715
|
+
...event,
|
|
716
|
+
blockNumber: BigInt(event.blockNumber),
|
|
717
|
+
contractAddress: event.srcAddress,
|
|
718
|
+
}));
|
|
719
|
+
}
|
|
720
|
+
catch (error) {
|
|
721
|
+
console.error("Error fetching MAO instances:", error);
|
|
722
|
+
throw error;
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
exports.EnvioGraphQLClient = EnvioGraphQLClient;
|
|
727
|
+
exports.default = EnvioGraphQLClient;
|
|
728
|
+
//# sourceMappingURL=EnvioGraphQLClient.js.map
|