Skip to content

Commit b8ecf4c

Browse files
committed
new features yey
1 parent b3034fb commit b8ecf4c

32 files changed

+1534
-294
lines changed

bun.lockb

18 KB
Binary file not shown.

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"@googleapis/sheets": "^9.6.0"
4+
}
5+
}

tooling/sparta/src/.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ ETHEREUM_VALUE=20ether
1313

1414
MINIMUM_STAKE=100000000000000000000
1515
APPROVAL_AMOUNT=10000000000000000000000
16+
17+
# Google Sheets Configuration
18+
GOOGLE_API_KEY=your_google_api_key_here
19+
SPREADSHEET_ID=your_spreadsheet_id_here

tooling/sparta/src/.gitignore

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
2+
3+
# Logs
4+
5+
logs
6+
_.log
7+
npm-debug.log_
8+
yarn-debug.log*
9+
yarn-error.log*
10+
lerna-debug.log*
11+
.pnpm-debug.log*
12+
13+
# Caches
14+
15+
.cache
16+
17+
# Diagnostic reports (https://nodejs.org/api/report.html)
18+
19+
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
20+
21+
# Runtime data
22+
23+
pids
24+
_.pid
25+
_.seed
26+
*.pid.lock
27+
28+
# Directory for instrumented libs generated by jscoverage/JSCover
29+
30+
lib-cov
31+
32+
# Coverage directory used by tools like istanbul
33+
34+
coverage
35+
*.lcov
36+
37+
# nyc test coverage
38+
39+
.nyc_output
40+
41+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
42+
43+
.grunt
44+
45+
# Bower dependency directory (https://bower.io/)
46+
47+
bower_components
48+
49+
# node-waf configuration
50+
51+
.lock-wscript
52+
53+
# Compiled binary addons (https://nodejs.org/api/addons.html)
54+
55+
build/Release
56+
57+
# Dependency directories
58+
59+
node_modules/
60+
jspm_packages/
61+
62+
# Snowpack dependency directory (https://snowpack.dev/)
63+
64+
web_modules/
65+
66+
# TypeScript cache
67+
68+
*.tsbuildinfo
69+
70+
# Optional npm cache directory
71+
72+
.npm
73+
74+
# Optional eslint cache
75+
76+
.eslintcache
77+
78+
# Optional stylelint cache
79+
80+
.stylelintcache
81+
82+
# Microbundle cache
83+
84+
.rpt2_cache/
85+
.rts2_cache_cjs/
86+
.rts2_cache_es/
87+
.rts2_cache_umd/
88+
89+
# Optional REPL history
90+
91+
.node_repl_history
92+
93+
# Output of 'npm pack'
94+
95+
*.tgz
96+
97+
# Yarn Integrity file
98+
99+
.yarn-integrity
100+
101+
# dotenv environment variable files
102+
103+
.env
104+
.env.development.local
105+
.env.test.local
106+
.env.production.local
107+
.env.local
108+
109+
# parcel-bundler cache (https://parceljs.org/)
110+
111+
.parcel-cache
112+
113+
# Next.js build output
114+
115+
.next
116+
out
117+
118+
# Nuxt.js build / generate output
119+
120+
.nuxt
121+
dist
122+
123+
# Gatsby files
124+
125+
# Comment in the public line in if your project uses Gatsby and not Next.js
126+
127+
# https://nextjs.org/blog/next-9-1#public-directory-support
128+
129+
# public
130+
131+
# vuepress build output
132+
133+
.vuepress/dist
134+
135+
# vuepress v2.x temp and cache directory
136+
137+
.temp
138+
139+
# Docusaurus cache and generated files
140+
141+
.docusaurus
142+
143+
# Serverless directories
144+
145+
.serverless/
146+
147+
# FuseBox cache
148+
149+
.fusebox/
150+
151+
# DynamoDB Local files
152+
153+
.dynamodb/
154+
155+
# TernJS port file
156+
157+
.tern-port
158+
159+
# Stores VSCode versions used for testing VSCode extensions
160+
161+
.vscode-test
162+
163+
# yarn v2
164+
165+
.yarn/cache
166+
.yarn/unplugged
167+
.yarn/build-state.yml
168+
.yarn/install-state.gz
169+
.pnp.*
170+
171+
# IntelliJ based IDEs
172+
.idea
173+
174+
# Finder (MacOS) folder config
175+
.DS_Store

tooling/sparta/src/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# sparta-bot
2+
3+
To install dependencies:
4+
5+
```bash
6+
bun install
7+
```
8+
9+
To run:
10+
11+
```bash
12+
bun run index.ts
13+
```
14+
15+
This project was created using `bun init` in bun v1.1.43. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.

tooling/sparta/src/admins/index.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

tooling/sparta/src/clients/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Clients
2+
3+
This directory contains client adapters for external services and APIs.
4+
5+
- `discord.ts` - Discord client for bot interactions
6+
- `google.ts` - Google Sheets client for spreadsheet operations
7+
- `ethereum.ts` - Ethereum blockchain client for interacting with smart contracts
8+
- `aztec.ts` - Aztec client for interacting with Aztec protocol

tooling/sparta/src/clients/aztec.ts

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/**
2+
* @fileoverview Aztec client and utilities
3+
* @description Provides Aztec node interaction methods via JSON-RPC
4+
* @module sparta/utils/aztec
5+
*/
6+
7+
export class Aztec {
8+
private readonly rpcUrl: string;
9+
10+
constructor(rpcUrl: string) {
11+
this.rpcUrl = rpcUrl;
12+
}
13+
14+
static new = async () => {
15+
try {
16+
console.log("Initializing Aztec client");
17+
const rpcUrl = process.env.AZTEC_NODE_URL;
18+
19+
if (!rpcUrl) {
20+
throw new Error("AZTEC_NODE_URL is not set");
21+
}
22+
23+
return new Aztec(rpcUrl);
24+
} catch (error) {
25+
console.error("Error initializing Aztec client:", error);
26+
throw error;
27+
}
28+
};
29+
30+
private async sendJsonRpcRequest(
31+
method: string,
32+
params: any[] = []
33+
): Promise<any> {
34+
const response = await fetch(this.rpcUrl, {
35+
method: "POST",
36+
headers: {
37+
"Content-Type": "application/json",
38+
},
39+
body: JSON.stringify({
40+
jsonrpc: "2.0",
41+
method,
42+
params,
43+
id: 67,
44+
}),
45+
});
46+
47+
if (!response.ok) {
48+
throw new Error(`HTTP error! status: ${response.status}`);
49+
}
50+
51+
const data = await response.json();
52+
if (data.error) {
53+
throw new Error(`RPC error: ${JSON.stringify(data.error)}`);
54+
}
55+
56+
return data.result;
57+
}
58+
59+
getL2Tips = async (): Promise<string> => {
60+
const result = await this.sendJsonRpcRequest("node_getL2Tips");
61+
return result.proven.number as string;
62+
};
63+
64+
getArchiveSiblingPath = async (blockNumber: string): Promise<any> => {
65+
return await this.sendJsonRpcRequest("node_getArchiveSiblingPath", [
66+
blockNumber,
67+
blockNumber,
68+
]);
69+
};
70+
71+
proveSynced = async (blockNumber: string, proof: string): Promise<any> => {
72+
if (process.env.BYPASS_SYNC_CHECK === "true") {
73+
return true;
74+
}
75+
const tip = await this.getL2Tips();
76+
if (Number(tip) > Number(blockNumber) + 20) {
77+
throw new Error("Proof is too old");
78+
}
79+
80+
const rpcProof = await this.getArchiveSiblingPath(blockNumber);
81+
return rpcProof === proof;
82+
};
83+
}
84+
85+
export const aztec = await Aztec.new();

0 commit comments

Comments
 (0)