@playthecut/agent 0.0.0-stage → 0.2.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/dist/client.js ADDED
@@ -0,0 +1,202 @@
1
+ import { signRequest } from "@slicekit/erc8128";
2
+ import { getAddress, isHex } from "viem";
3
+ import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
4
+ import { actionSchema, registerSchema, } from "./contract.js";
5
+ export class CutAgentError extends Error {
6
+ constructor(message, status, body) {
7
+ super(message);
8
+ this.name = "CutAgentError";
9
+ this.status = status;
10
+ this.body = body;
11
+ }
12
+ }
13
+ export function generateDelegateKey() {
14
+ const privateKey = generatePrivateKey();
15
+ return { privateKey, address: privateKeyToAccount(privateKey).address };
16
+ }
17
+ export function createCutAgent(options) {
18
+ const requestedChain = options.chainId ?? 8453;
19
+ if (requestedChain !== 8453 && requestedChain !== 84532) {
20
+ throw new CutAgentError("ChainId must be 8453 (Base) or 84532 (Base Sepolia)", 400, null);
21
+ }
22
+ const chainId = requestedChain;
23
+ const account = privateKeyToAccount(options.privateKey);
24
+ let smartWallet;
25
+ try {
26
+ smartWallet = options.smartWallet ? getAddress(options.smartWallet) : account.address;
27
+ }
28
+ catch {
29
+ throw new CutAgentError("Invalid smart wallet", 400, null);
30
+ }
31
+ const origin = (options.origin ?? "https://playthecut.com").replace(/\/$/, "");
32
+ const fetchImpl = options.fetch ?? ((request) => fetch(request));
33
+ const signer = {
34
+ chainId,
35
+ address: account.address,
36
+ signMessage: (message) => account.signMessage({ message: { raw: message } }),
37
+ };
38
+ function parse(schema, body) {
39
+ const parsed = schema.safeParse(body);
40
+ if (!parsed.success) {
41
+ const message = parsed.error.issues.map((issue) => issue.message).join("; ");
42
+ throw new CutAgentError(message || "Invalid request body", 400, parsed.error.issues);
43
+ }
44
+ return parsed.data;
45
+ }
46
+ async function send(signed) {
47
+ const headers = new Headers(signed.headers);
48
+ headers.set("x-cut-chain-id", String(chainId));
49
+ const response = await fetchImpl(new Request(signed, { headers }));
50
+ const text = await response.text();
51
+ let body = null;
52
+ if (text) {
53
+ try {
54
+ body = JSON.parse(text);
55
+ }
56
+ catch {
57
+ body = text;
58
+ }
59
+ }
60
+ if (!response.ok) {
61
+ const message = body && typeof body === "object" && "error" in body && typeof body.error === "string"
62
+ ? body.error
63
+ : response.statusText || "Request failed";
64
+ throw new CutAgentError(message, response.status, body);
65
+ }
66
+ return body;
67
+ }
68
+ async function get(path, query) {
69
+ const url = new URL(path, origin);
70
+ for (const [key, value] of Object.entries(query))
71
+ url.searchParams.set(key, value);
72
+ return send(await signRequest(url.toString(), signer));
73
+ }
74
+ async function post(path, body) {
75
+ return send(await signRequest(`${origin}${path}`, {
76
+ method: "POST",
77
+ headers: { "content-type": "application/json" },
78
+ body: JSON.stringify(body),
79
+ }, signer));
80
+ }
81
+ function prepared(value) {
82
+ if (!value || typeof value !== "object" || !("preparedUserOp" in value))
83
+ return null;
84
+ const row = value;
85
+ if (row.preparedUserOp !== true || !row.userOpHash || !isHex(row.userOpHash) || !row.userOp) {
86
+ return null;
87
+ }
88
+ return row;
89
+ }
90
+ async function postAction(body) {
91
+ const first = await post("/api/bot/actions", body);
92
+ const ready = prepared(first);
93
+ if (!ready)
94
+ return first;
95
+ const userOpSignature = await account.signMessage({ message: { raw: ready.userOpHash } });
96
+ const second = await post("/api/bot/actions", {
97
+ ...body,
98
+ userOp: ready.userOp,
99
+ userOpSignature,
100
+ });
101
+ if (prepared(second)) {
102
+ throw new CutAgentError("Server returned another prepared user operation", 502, second);
103
+ }
104
+ return second;
105
+ }
106
+ function lineupResult(value) {
107
+ if (!value || typeof value !== "object") {
108
+ throw new CutAgentError("Unexpected response", 502, value);
109
+ }
110
+ const lineupId = value.lineupId;
111
+ if (value.ok !== true || typeof lineupId !== "string" || !lineupId) {
112
+ throw new CutAgentError("Unexpected response", 502, value);
113
+ }
114
+ return { ok: true, lineupId };
115
+ }
116
+ return {
117
+ address: account.address,
118
+ smartWallet,
119
+ async contests(eventId) {
120
+ const query = {
121
+ chainId: String(chainId),
122
+ smartWallet,
123
+ };
124
+ if (eventId)
125
+ query.eventId = eventId;
126
+ const body = await get("/api/bot/contests", query);
127
+ if (!body || typeof body !== "object" || !Array.isArray(body.contests)) {
128
+ throw new CutAgentError("Unexpected response", 502, body);
129
+ }
130
+ return { contests: body.contests };
131
+ },
132
+ async lineupUpsert(input) {
133
+ const body = parse(actionSchema, {
134
+ chainId,
135
+ action: "lineupUpsert",
136
+ smartWallet,
137
+ contestId: input.contestId,
138
+ lineupId: input.lineupId ?? "",
139
+ candidates: input.candidates,
140
+ ...(input.prediction !== undefined ? { prediction: input.prediction } : {}),
141
+ });
142
+ return lineupResult(await postAction(body));
143
+ },
144
+ async join(input) {
145
+ const body = parse(actionSchema, {
146
+ chainId,
147
+ action: "join",
148
+ smartWallet,
149
+ contestId: input.contestId,
150
+ lineupId: input.lineupId,
151
+ });
152
+ return lineupResult(await postAction(body));
153
+ },
154
+ async leave(input) {
155
+ const body = parse(actionSchema, {
156
+ chainId,
157
+ action: "leave",
158
+ smartWallet,
159
+ contestId: input.contestId,
160
+ lineupId: input.lineupId,
161
+ });
162
+ return lineupResult(await postAction(body));
163
+ },
164
+ async register(input) {
165
+ const body = parse(registerSchema, input);
166
+ const value = await post("/api/auth/register", body);
167
+ if (!value ||
168
+ typeof value !== "object" ||
169
+ typeof value.userId !== "string") {
170
+ throw new CutAgentError("Unexpected response", 502, value);
171
+ }
172
+ return value;
173
+ },
174
+ async createContest(input) {
175
+ const body = parse(actionSchema, {
176
+ chainId,
177
+ action: "createContest",
178
+ smartWallet,
179
+ name: input.name,
180
+ eventId: input.eventId,
181
+ endDate: input.endDate,
182
+ settings: input.settings,
183
+ ...(input.description !== undefined ? { description: input.description } : {}),
184
+ ...(input.userGroupId !== undefined ? { userGroupId: input.userGroupId } : {}),
185
+ ...(input.notifyLeagueMembers !== undefined
186
+ ? { notifyLeagueMembers: input.notifyLeagueMembers }
187
+ : {}),
188
+ });
189
+ const value = await postAction(body);
190
+ if (!value || typeof value !== "object") {
191
+ throw new CutAgentError("Unexpected response", 502, value);
192
+ }
193
+ const created = value;
194
+ if (created.ok !== true ||
195
+ typeof created.contestId !== "string" ||
196
+ typeof created.address !== "string") {
197
+ throw new CutAgentError("Unexpected response", 502, value);
198
+ }
199
+ return { ok: true, contestId: created.contestId, address: created.address };
200
+ },
201
+ };
202
+ }
@@ -0,0 +1,251 @@
1
+ import { z } from "zod";
2
+ export declare const contestSettingsSchema: z.ZodOptional<z.ZodObject<{
3
+ contestType: z.ZodOptional<z.ZodString>;
4
+ chainId: z.ZodOptional<z.ZodNumber>;
5
+ paymentTokenAddress: z.ZodOptional<z.ZodString>;
6
+ paymentTokenSymbol: z.ZodOptional<z.ZodString>;
7
+ operator: z.ZodOptional<z.ZodString>;
8
+ expiryTimestamp: z.ZodOptional<z.ZodNumber>;
9
+ primaryDeposit: z.ZodOptional<z.ZodNumber>;
10
+ referralNetworkBps: z.ZodOptional<z.ZodNumber>;
11
+ oracleFeeBps: z.ZodOptional<z.ZodNumber>;
12
+ referralGroupId: z.ZodOptional<z.ZodString>;
13
+ primaryDepositSecondarySubsidyBps: z.ZodOptional<z.ZodNumber>;
14
+ primaryEntryInvestmentShareBps: z.ZodOptional<z.ZodNumber>;
15
+ positionBonusShareBps: z.ZodOptional<z.ZodNumber>;
16
+ targetPrimaryShareBps: z.ZodOptional<z.ZodNumber>;
17
+ maxCrossSubsidyBps: z.ZodOptional<z.ZodNumber>;
18
+ maxPlayers: z.ZodOptional<z.ZodNumber>;
19
+ scoringType: z.ZodOptional<z.ZodEnum<{
20
+ STABLEFORD: "STABLEFORD";
21
+ STROKE_PLAY: "STROKE_PLAY";
22
+ }>>;
23
+ }, z.core.$strip>>;
24
+ export declare const userOpSchema: z.ZodObject<{
25
+ sender: z.ZodString & z.ZodType<`0x${string}`, string, z.core.$ZodTypeInternals<`0x${string}`, string>>;
26
+ nonce: z.ZodString;
27
+ callData: z.ZodString;
28
+ callGasLimit: z.ZodString;
29
+ verificationGasLimit: z.ZodString;
30
+ preVerificationGas: z.ZodString;
31
+ maxFeePerGas: z.ZodString;
32
+ maxPriorityFeePerGas: z.ZodString;
33
+ paymaster: z.ZodOptional<z.ZodString>;
34
+ paymasterData: z.ZodOptional<z.ZodString>;
35
+ paymasterVerificationGasLimit: z.ZodOptional<z.ZodString>;
36
+ paymasterPostOpGasLimit: z.ZodOptional<z.ZodString>;
37
+ factory: z.ZodOptional<z.ZodString>;
38
+ factoryData: z.ZodOptional<z.ZodString>;
39
+ }, z.core.$strip>;
40
+ export declare const playActionSchema: z.ZodObject<{
41
+ chainId: z.ZodNumber;
42
+ action: z.ZodEnum<{
43
+ lineupUpsert: "lineupUpsert";
44
+ join: "join";
45
+ leave: "leave";
46
+ }>;
47
+ smartWallet: z.ZodString;
48
+ contestId: z.ZodString;
49
+ lineupId: z.ZodDefault<z.ZodString>;
50
+ candidates: z.ZodOptional<z.ZodArray<z.ZodString>>;
51
+ prediction: z.ZodOptional<z.ZodUnknown>;
52
+ userOpSignature: z.ZodOptional<z.ZodString>;
53
+ userOp: z.ZodOptional<z.ZodObject<{
54
+ sender: z.ZodString & z.ZodType<`0x${string}`, string, z.core.$ZodTypeInternals<`0x${string}`, string>>;
55
+ nonce: z.ZodString;
56
+ callData: z.ZodString;
57
+ callGasLimit: z.ZodString;
58
+ verificationGasLimit: z.ZodString;
59
+ preVerificationGas: z.ZodString;
60
+ maxFeePerGas: z.ZodString;
61
+ maxPriorityFeePerGas: z.ZodString;
62
+ paymaster: z.ZodOptional<z.ZodString>;
63
+ paymasterData: z.ZodOptional<z.ZodString>;
64
+ paymasterVerificationGasLimit: z.ZodOptional<z.ZodString>;
65
+ paymasterPostOpGasLimit: z.ZodOptional<z.ZodString>;
66
+ factory: z.ZodOptional<z.ZodString>;
67
+ factoryData: z.ZodOptional<z.ZodString>;
68
+ }, z.core.$strip>>;
69
+ }, z.core.$strip>;
70
+ export declare const createContestActionSchema: z.ZodObject<{
71
+ chainId: z.ZodNumber;
72
+ action: z.ZodLiteral<"createContest">;
73
+ smartWallet: z.ZodString;
74
+ name: z.ZodString;
75
+ description: z.ZodOptional<z.ZodString>;
76
+ eventId: z.ZodString;
77
+ userGroupId: z.ZodOptional<z.ZodString>;
78
+ endDate: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
79
+ settings: z.ZodOptional<z.ZodObject<{
80
+ contestType: z.ZodOptional<z.ZodString>;
81
+ chainId: z.ZodOptional<z.ZodNumber>;
82
+ paymentTokenAddress: z.ZodOptional<z.ZodString>;
83
+ paymentTokenSymbol: z.ZodOptional<z.ZodString>;
84
+ operator: z.ZodOptional<z.ZodString>;
85
+ expiryTimestamp: z.ZodOptional<z.ZodNumber>;
86
+ primaryDeposit: z.ZodOptional<z.ZodNumber>;
87
+ referralNetworkBps: z.ZodOptional<z.ZodNumber>;
88
+ oracleFeeBps: z.ZodOptional<z.ZodNumber>;
89
+ referralGroupId: z.ZodOptional<z.ZodString>;
90
+ primaryDepositSecondarySubsidyBps: z.ZodOptional<z.ZodNumber>;
91
+ primaryEntryInvestmentShareBps: z.ZodOptional<z.ZodNumber>;
92
+ positionBonusShareBps: z.ZodOptional<z.ZodNumber>;
93
+ targetPrimaryShareBps: z.ZodOptional<z.ZodNumber>;
94
+ maxCrossSubsidyBps: z.ZodOptional<z.ZodNumber>;
95
+ maxPlayers: z.ZodOptional<z.ZodNumber>;
96
+ scoringType: z.ZodOptional<z.ZodEnum<{
97
+ STABLEFORD: "STABLEFORD";
98
+ STROKE_PLAY: "STROKE_PLAY";
99
+ }>>;
100
+ }, z.core.$strip>>;
101
+ notifyLeagueMembers: z.ZodOptional<z.ZodBoolean>;
102
+ userOpSignature: z.ZodOptional<z.ZodString>;
103
+ userOp: z.ZodOptional<z.ZodObject<{
104
+ sender: z.ZodString & z.ZodType<`0x${string}`, string, z.core.$ZodTypeInternals<`0x${string}`, string>>;
105
+ nonce: z.ZodString;
106
+ callData: z.ZodString;
107
+ callGasLimit: z.ZodString;
108
+ verificationGasLimit: z.ZodString;
109
+ preVerificationGas: z.ZodString;
110
+ maxFeePerGas: z.ZodString;
111
+ maxPriorityFeePerGas: z.ZodString;
112
+ paymaster: z.ZodOptional<z.ZodString>;
113
+ paymasterData: z.ZodOptional<z.ZodString>;
114
+ paymasterVerificationGasLimit: z.ZodOptional<z.ZodString>;
115
+ paymasterPostOpGasLimit: z.ZodOptional<z.ZodString>;
116
+ factory: z.ZodOptional<z.ZodString>;
117
+ factoryData: z.ZodOptional<z.ZodString>;
118
+ }, z.core.$strip>>;
119
+ }, z.core.$strip>;
120
+ export declare const actionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
121
+ chainId: z.ZodNumber;
122
+ action: z.ZodEnum<{
123
+ lineupUpsert: "lineupUpsert";
124
+ join: "join";
125
+ leave: "leave";
126
+ }>;
127
+ smartWallet: z.ZodString;
128
+ contestId: z.ZodString;
129
+ lineupId: z.ZodDefault<z.ZodString>;
130
+ candidates: z.ZodOptional<z.ZodArray<z.ZodString>>;
131
+ prediction: z.ZodOptional<z.ZodUnknown>;
132
+ userOpSignature: z.ZodOptional<z.ZodString>;
133
+ userOp: z.ZodOptional<z.ZodObject<{
134
+ sender: z.ZodString & z.ZodType<`0x${string}`, string, z.core.$ZodTypeInternals<`0x${string}`, string>>;
135
+ nonce: z.ZodString;
136
+ callData: z.ZodString;
137
+ callGasLimit: z.ZodString;
138
+ verificationGasLimit: z.ZodString;
139
+ preVerificationGas: z.ZodString;
140
+ maxFeePerGas: z.ZodString;
141
+ maxPriorityFeePerGas: z.ZodString;
142
+ paymaster: z.ZodOptional<z.ZodString>;
143
+ paymasterData: z.ZodOptional<z.ZodString>;
144
+ paymasterVerificationGasLimit: z.ZodOptional<z.ZodString>;
145
+ paymasterPostOpGasLimit: z.ZodOptional<z.ZodString>;
146
+ factory: z.ZodOptional<z.ZodString>;
147
+ factoryData: z.ZodOptional<z.ZodString>;
148
+ }, z.core.$strip>>;
149
+ }, z.core.$strip>, z.ZodObject<{
150
+ chainId: z.ZodNumber;
151
+ action: z.ZodLiteral<"createContest">;
152
+ smartWallet: z.ZodString;
153
+ name: z.ZodString;
154
+ description: z.ZodOptional<z.ZodString>;
155
+ eventId: z.ZodString;
156
+ userGroupId: z.ZodOptional<z.ZodString>;
157
+ endDate: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
158
+ settings: z.ZodOptional<z.ZodObject<{
159
+ contestType: z.ZodOptional<z.ZodString>;
160
+ chainId: z.ZodOptional<z.ZodNumber>;
161
+ paymentTokenAddress: z.ZodOptional<z.ZodString>;
162
+ paymentTokenSymbol: z.ZodOptional<z.ZodString>;
163
+ operator: z.ZodOptional<z.ZodString>;
164
+ expiryTimestamp: z.ZodOptional<z.ZodNumber>;
165
+ primaryDeposit: z.ZodOptional<z.ZodNumber>;
166
+ referralNetworkBps: z.ZodOptional<z.ZodNumber>;
167
+ oracleFeeBps: z.ZodOptional<z.ZodNumber>;
168
+ referralGroupId: z.ZodOptional<z.ZodString>;
169
+ primaryDepositSecondarySubsidyBps: z.ZodOptional<z.ZodNumber>;
170
+ primaryEntryInvestmentShareBps: z.ZodOptional<z.ZodNumber>;
171
+ positionBonusShareBps: z.ZodOptional<z.ZodNumber>;
172
+ targetPrimaryShareBps: z.ZodOptional<z.ZodNumber>;
173
+ maxCrossSubsidyBps: z.ZodOptional<z.ZodNumber>;
174
+ maxPlayers: z.ZodOptional<z.ZodNumber>;
175
+ scoringType: z.ZodOptional<z.ZodEnum<{
176
+ STABLEFORD: "STABLEFORD";
177
+ STROKE_PLAY: "STROKE_PLAY";
178
+ }>>;
179
+ }, z.core.$strip>>;
180
+ notifyLeagueMembers: z.ZodOptional<z.ZodBoolean>;
181
+ userOpSignature: z.ZodOptional<z.ZodString>;
182
+ userOp: z.ZodOptional<z.ZodObject<{
183
+ sender: z.ZodString & z.ZodType<`0x${string}`, string, z.core.$ZodTypeInternals<`0x${string}`, string>>;
184
+ nonce: z.ZodString;
185
+ callData: z.ZodString;
186
+ callGasLimit: z.ZodString;
187
+ verificationGasLimit: z.ZodString;
188
+ preVerificationGas: z.ZodString;
189
+ maxFeePerGas: z.ZodString;
190
+ maxPriorityFeePerGas: z.ZodString;
191
+ paymaster: z.ZodOptional<z.ZodString>;
192
+ paymasterData: z.ZodOptional<z.ZodString>;
193
+ paymasterVerificationGasLimit: z.ZodOptional<z.ZodString>;
194
+ paymasterPostOpGasLimit: z.ZodOptional<z.ZodString>;
195
+ factory: z.ZodOptional<z.ZodString>;
196
+ factoryData: z.ZodOptional<z.ZodString>;
197
+ }, z.core.$strip>>;
198
+ }, z.core.$strip>], "action">;
199
+ export declare const registerSchema: z.ZodObject<{
200
+ email: z.ZodString;
201
+ name: z.ZodOptional<z.ZodString>;
202
+ referralCode: z.ZodOptional<z.ZodString>;
203
+ }, z.core.$strip>;
204
+ export type UserOpBody = z.infer<typeof userOpSchema>;
205
+ export type PlayActionBody = z.infer<typeof playActionSchema>;
206
+ export type CreateContestActionBody = z.infer<typeof createContestActionSchema>;
207
+ export type ActionBody = z.infer<typeof actionSchema>;
208
+ export type RegisterBody = z.infer<typeof registerSchema>;
209
+ export type BotCandidate = {
210
+ eventParticipantId: string;
211
+ participantId: string;
212
+ displayName: string;
213
+ sortKeys: Record<string, number | string>;
214
+ metadata: unknown;
215
+ };
216
+ export type BotContest = {
217
+ contestId: string;
218
+ name: string;
219
+ eventId: string;
220
+ sportId: string;
221
+ chainId: number;
222
+ status: string;
223
+ address: string | null;
224
+ userGroupId: string | null;
225
+ userGroupName: string | null;
226
+ primaryDeposit: number | null;
227
+ endTime: string;
228
+ candidates: BotCandidate[];
229
+ };
230
+ export type RegisteredAgent = {
231
+ userId: string;
232
+ email: string;
233
+ userType: string;
234
+ name: string;
235
+ referralCode: string;
236
+ smartWallet: string;
237
+ created: boolean;
238
+ };
239
+ export type LineupResult = {
240
+ ok: true;
241
+ lineupId: string;
242
+ };
243
+ export type ContestCreated = {
244
+ ok: true;
245
+ contestId: string;
246
+ address: string;
247
+ };
248
+ export type ContestList = {
249
+ contests: BotContest[];
250
+ };
251
+ //# sourceMappingURL=contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAUxB,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;kBAoBrB,CAAC;AAEd,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;iBAevB,CAAC;AAEH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAU3B,CAAC;AAEH,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAapC,CAAC;AAEH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BAGvB,CAAC;AAEH,eAAO,MAAM,cAAc;;;;iBAIzB,CAAC;AAEH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AACtD,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAC9D,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAChF,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AACtD,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAE1D,MAAM,MAAM,YAAY,GAAG;IACzB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;IAC1C,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,YAAY,EAAE,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAC1D,MAAM,MAAM,cAAc,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAC9E,MAAM,MAAM,WAAW,GAAG;IAAE,QAAQ,EAAE,UAAU,EAAE,CAAA;CAAE,CAAC"}
@@ -0,0 +1,79 @@
1
+ import { isAddress } from "viem";
2
+ import { z } from "zod";
3
+ const NAME_MAX_LENGTH = 80;
4
+ const DESCRIPTION_MAX_LENGTH = 2000;
5
+ const hexSchema = z.string().regex(/^0x[0-9a-fA-F]*$/);
6
+ const uintSchema = z.string().regex(/^\d+$/);
7
+ const ethAddress = z.string().regex(/^0x[a-fA-F0-9]{40}$/, "Invalid address");
8
+ const bps = z.number().int().min(0).max(10000);
9
+ export const contestSettingsSchema = z
10
+ .object({
11
+ contestType: z.string().max(32).optional(),
12
+ chainId: z.number().optional(),
13
+ paymentTokenAddress: ethAddress.optional(),
14
+ paymentTokenSymbol: z.string().max(16).optional(),
15
+ operator: ethAddress.optional(),
16
+ expiryTimestamp: z.number().optional(),
17
+ primaryDeposit: z.number().min(0).optional(),
18
+ referralNetworkBps: bps.optional(),
19
+ oracleFeeBps: bps.optional(),
20
+ referralGroupId: z.string().optional(),
21
+ primaryDepositSecondarySubsidyBps: bps.optional(),
22
+ primaryEntryInvestmentShareBps: bps.optional(),
23
+ positionBonusShareBps: bps.optional(),
24
+ targetPrimaryShareBps: bps.optional(),
25
+ maxCrossSubsidyBps: bps.optional(),
26
+ maxPlayers: z.number().int().positive().optional(),
27
+ scoringType: z.enum(["STABLEFORD", "STROKE_PLAY"]).optional(),
28
+ })
29
+ .optional();
30
+ export const userOpSchema = z.object({
31
+ sender: z.string().refine((value) => isAddress(value), "Invalid user operation sender"),
32
+ nonce: uintSchema,
33
+ callData: hexSchema,
34
+ callGasLimit: uintSchema,
35
+ verificationGasLimit: uintSchema,
36
+ preVerificationGas: uintSchema,
37
+ maxFeePerGas: uintSchema,
38
+ maxPriorityFeePerGas: uintSchema,
39
+ paymaster: z.string().optional(),
40
+ paymasterData: hexSchema.optional(),
41
+ paymasterVerificationGasLimit: uintSchema.optional(),
42
+ paymasterPostOpGasLimit: uintSchema.optional(),
43
+ factory: z.string().optional(),
44
+ factoryData: hexSchema.optional(),
45
+ });
46
+ export const playActionSchema = z.object({
47
+ chainId: z.number().int(),
48
+ action: z.enum(["lineupUpsert", "join", "leave"]),
49
+ smartWallet: z.string(),
50
+ contestId: z.string().min(1),
51
+ lineupId: z.string().default(""),
52
+ candidates: z.array(z.string().min(1)).optional(),
53
+ prediction: z.unknown().optional(),
54
+ userOpSignature: hexSchema.optional(),
55
+ userOp: userOpSchema.optional(),
56
+ });
57
+ export const createContestActionSchema = z.object({
58
+ chainId: z.number().int(),
59
+ action: z.literal("createContest"),
60
+ smartWallet: z.string(),
61
+ name: z.string().trim().min(1).max(NAME_MAX_LENGTH),
62
+ description: z.string().max(DESCRIPTION_MAX_LENGTH).optional(),
63
+ eventId: z.string().cuid(),
64
+ userGroupId: z.string().cuid().optional(),
65
+ endDate: z.union([z.string().datetime(), z.number()]),
66
+ settings: contestSettingsSchema,
67
+ notifyLeagueMembers: z.boolean().optional(),
68
+ userOpSignature: hexSchema.optional(),
69
+ userOp: userOpSchema.optional(),
70
+ });
71
+ export const actionSchema = z.discriminatedUnion("action", [
72
+ playActionSchema,
73
+ createContestActionSchema,
74
+ ]);
75
+ export const registerSchema = z.object({
76
+ email: z.string().trim().email("A valid email is required"),
77
+ name: z.string().trim().min(1).max(NAME_MAX_LENGTH).optional(),
78
+ referralCode: z.string().trim().min(1).max(32).optional(),
79
+ });
@@ -0,0 +1,4 @@
1
+ export { createCutAgent, generateDelegateKey, CutAgentError } from "./client.js";
2
+ export type { CreateContestInput, CutAgent, CutAgentOptions, CutChainId, LineupRef, LineupUpsertInput, } from "./client.js";
3
+ export type { BotCandidate, BotContest, ContestCreated, ContestList, LineupResult, RegisteredAgent, } from "./contract.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjF,YAAY,EACV,kBAAkB,EAClB,QAAQ,EACR,eAAe,EACf,UAAU,EACV,SAAS,EACT,iBAAiB,GAClB,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,YAAY,EACZ,UAAU,EACV,cAAc,EACd,WAAW,EACX,YAAY,EACZ,eAAe,GAChB,MAAM,eAAe,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export { createCutAgent, generateDelegateKey, CutAgentError } from "./client.js";