Skip to content

Commit 3f97af0

Browse files
rooch: add alby API and sqlite support.
1 parent c1a31c9 commit 3f97af0

File tree

10 files changed

+132
-32
lines changed

10 files changed

+132
-32
lines changed

.env.sample

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,19 @@ POSTGRES_PASSWORD=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\
1818
# Prisma postgres config
1919
DATABASE_URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres_db:5432/${POSTGRES_DB}"
2020

21+
# Sqlite config
22+
SQLITE_PATH=sqlite.db
23+
24+
# Prisma sqlite config
25+
DATABASE_URL_DEV="file:${SQLITE_PATH}"
26+
2127
# Optionals
2228
SENTRY_DSN=""
2329
ECDSA_PRIVATE_KEY="" # for verity analysis.
2430

2531
# Integrations
2632
X_BEARER_TOKEN=""
2733

28-
OPEN_AI_TOKEN=""
34+
OPEN_AI_TOKEN=""
35+
36+
ALBY_ACCESS_TOKEN=""

.gitignore

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,11 @@ temp*
126126

127127
# else
128128
.script
129+
deno.lock
129130

130131
# Prisma
131-
prisma/.db
132-
prisma/.db*
133-
orchestrator/prisma/.db
134-
orchestrator/prisma/.db*
132+
orchestrator/prisma-dev/*.db
133+
orchestrator/prisma-dev/*.db*
135134
.infisical.json
136135
.aptos
137136
migration_lock.toml

docs/ROOCH.md

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,22 @@ Before running the script, ensure you have the following prerequisites installed
1313

1414
### Step-by-Step Instructions
1515

16-
#### Step 1: Create a Roach Account
16+
#### Step 1: Create a Rooch Account
1717

18-
First, you need to create a Roach account. This account will be used throughout the setup process.
18+
First, you need to have `rooch` binary in hand. The `rooch` binary can be downloaded from the [Rooch GitHub repo](https://github.com/rooch-network/rooch). Use the `rooch` binary to create a Rooch account. This account will be used throughout the setup process.
19+
20+
```bash
21+
rooch init
22+
```
23+
24+
or
1925

2026
```bash
2127
rooch account create
2228
```
2329

30+
if there already exists an account.
31+
2432
#### Step 2: Clear and Start Local Network
2533

2634
Clear any existing state and start the local network.
@@ -32,12 +40,11 @@ rooch server start
3240

3341
#### Step 3: Deploy Contracts
3442

35-
Navigate to the `rooch` directory, build the contracts for development, publish them with named addresses and update `.env` `ROOCH_ORACLE_ADDRESS` with deployed Address
43+
Navigate to this repo's [rooch](../rooch) directory, build the contracts for development, and publish them with named addresses and update `.env` `ROOCH_ORACLE_ADDRESS` with deployed Address
3644

3745
```bash
3846
cd rooch
39-
rooch move build --dev
40-
rooch move publish --named-addresses verity=default --sender default
47+
rooch move publish --named-addresses verity=default,verity_test_foreign_module=default --sender default
4148
cd ..
4249
```
4350

@@ -72,7 +79,7 @@ pnpm prisma:deploy
7279
**In Development (for SQLite):**
7380

7481
```bash
75-
pnpm clean:db
82+
pnpm clean:db:dev
7683
pnpm prisma:generate:dev
7784
pnpm prisma:deploy:dev
7885
```
@@ -82,19 +89,18 @@ pnpm prisma:deploy:dev
8289
Copy the example environment file to create your own `.env` file:
8390

8491
```bash
85-
cp .env.example .env
92+
cp .env.sample .env
8693
```
8794

8895
Export the Rooch Private Key:
8996

9097
```bash
9198
rooch account export --address <Rooch Address>
92-
9399
```
94100

95101

96-
To connect to the local Rooch node, set `ROOCH_CHAIN_ID` to `"localnet"`.
97-
Otherwise, connect to testNet by setting `ROOCH_CHAIN_ID` to `"testnet"`, or to TestNet by setting `ROOCH_CHAIN_ID` to `"testnet"`.
102+
To connect to the local Rooch node, set `ROOCH_CHAIN_ID` to `"localnet"`.
103+
Otherwise, connect to DevNet by setting `ROOCH_CHAIN_ID` to `"devnet"`, or to TestNet by setting `ROOCH_CHAIN_ID` to `"testnet"`.
98104
Ensure that `ROOCH_ORACLE_ADDRESS` is set to the address of the deployed module, e.g., `"0x85859e45551846d9ab8651bb0b6f6e1740c9d758cfda05cfc39d49e2a604d783"`.
99105

100106
#### Step 7: Register supported URL
@@ -103,19 +109,19 @@ Additional steps for managing supported orchestrator URL
103109
- To add URL
104110

105111
```bash
106-
rooch move run --function 0xf1290fb0e7e1de7e92e616209fb628970232e85c4c1a264858ff35092e1be231::registry::add_supported_url --sender-account 0x694cbe655b126e9e6a997e86aaab39e538abf30a8c78669ce23a98740b47b65d --args 'string:https://api.openai.com/v1/chat/completions' --args 'u256:50000' --args 'u64:40' --args 'u256:4000' --args 'u256:5000'
112+
rooch move run --function <contract_address>::registry::add_supported_url --sender-account <orchestrator_address> --args 'string:https://api.openai.com/v1/chat/completions' --args 'u256:50000' --args 'u64:40' --args 'u256:4000' --args 'u256:5000'
107113
```
108114

109115
- to remove URLs
110116

111117
```bash
112-
rooch move run --function 0xf1290fb0e7e1de7e92e616209fb628970232e85c4c1a264858ff35092e1be231::registry::remove_supported_url --sender-account <orchestrator_address> --args 'string:https://api.twitter.com/2/users/'
118+
rooch move run --function <contract_address>::registry::remove_supported_url --sender-account <orchestrator_address> --args 'string:https://api.openai.com/v1/chat/completions'
113119
```
114120

115-
- To view supported URLS
121+
- To view supported URLs
116122

117123
```bash
118-
rooch move view --function 0xf1290fb0e7e1de7e92e616209fb628970232e85c4c1a264858ff35092e1be231::registry::get_supported_urls --args 'address:0x694cbe655b126e9e6a997e86aaab39e538abf30a8c78669ce23a98740b47b65d'
124+
rooch move view --function <contract_address>::registry::get_supported_urls --args 'address:<orchestrator_address>'
119125
```
120126

121127

@@ -144,7 +150,7 @@ Here's an example of requesting the Twitter Followers Count on a Local Rooch Nod
144150
```bash
145151
rooch move run --function 0xf1290fb0e7e1de7e92e616209fb628970232e85c4c1a264858ff35092e1be231::example_caller::request_data --sender-account default --args 'string:https://api.x.com/2/users/by/username/elonmusk?user.fields=public_metrics' --args 'string:GET' --args 'string:{}' --args 'string:{}' --args 'string:.data.public_metrics.followers_count' --args 'address:0x694cbe655b126e9e6a997e86aaab39e538abf30a8c78669ce23a98740b47b65d' --args 'u256:50000'
146152
```
147-
or
153+
or
148154
```bash
149155
rooch move run --function 0xf1290fb0e7e1de7e92e616209fb628970232e85c4c1a264858ff35092e1be231::example_caller::request_data --sender-account default --args 'string:https://api.openai.com/v1/chat/completions' --args 'string:POST' --args 'string:{}' --args 'string:{"model": "gpt-4o-mini", "messages": [{"role": "user", "content": "Say this is a test!"}],"temperature": 0.7}' --args 'string:.choices[].message.content' --args 'address:0x694cbe655b126e9e6a997e86aaab39e538abf30a8c78669ce23a98740b47b65d' --args 'u256:50000000'
150156
```
@@ -155,28 +161,28 @@ rooch state -a /object/0x7a01ddf194f8a1c19212d56f747294352bf2e5cf23e6e10e64937aa
155161
```
156162

157163

158-
Additionally,
164+
Additionally,
159165
For notification calls you can allocated an portion form escrow for notification per fulfilment Request(Recommended 1Rgas for the first fulfilment).
160166
```bash
161167
rooch move run --function 0xf1290fb0e7e1de7e92e616209fb628970232e85c4c1a264858ff35092e1be231::oracles::update_notification_gas_allocation --sender-account default --args 'address:0x27e46e033da11c4d1f986081877e80cefb2b29dec1c559c97c3ccf12e910aba7' --args 'string:example_caller::receive_data' --args 'u256:10000000'
162168
```
163169

164170
#### Step 10: Manage Escrow balance
165171

166-
- To view balance
172+
- To view balance
167173

168174
```bash
169-
rooch move view --function 0xf1290fb0e7e1de7e92e616209fb628970232e85c4c1a264858ff35092e1be231::oracles::get_user_balance --args 'address:<your_address>'
175+
rooch move view --function 0xf1290fb0e7e1de7e92e616209fb628970232e85c4c1a264858ff35092e1be231::oracles::get_user_balance --args 'address:<your_address>'
170176
```
171177

172178
- To withdraw Balance
173179
```bash
174-
rooch move run --function 0xf1290fb0e7e1de7e92e616209fb628970232e85c4c1a264858ff35092e1be231::oracles::withdraw_from_escrow --args 'u256:<amount>'
180+
rooch move run --function 0xf1290fb0e7e1de7e92e616209fb628970232e85c4c1a264858ff35092e1be231::oracles::withdraw_from_escrow --args 'u256:<amount>'
175181
```
176182

177-
- To Deposit
183+
- To Deposit
178184
```bash
179-
rooch move run --function 0xf1290fb0e7e1de7e92e616209fb628970232e85c4c1a264858ff35092e1be231::oracles::deposit_to_escrow --args 'u256:<amount>'
185+
rooch move run --function 0xf1290fb0e7e1de7e92e616209fb628970232e85c4c1a264858ff35092e1be231::oracles::deposit_to_escrow --args 'u256:<amount>'
180186
```
181187

182188
To confirm the `Request` Object State, use the Object ID generated from the initial transaction to query the state of the response object.
@@ -190,7 +196,7 @@ An example of requesting the Twitter Followers Count on a Rooch Testnet:
190196
rooch move run --function 0xf1290fb0e7e1de7e92e616209fb628970232e85c4c1a264858ff35092e1be231::example_caller::request_data --sender-account default --args 'string:https://api.x.com/2/users/by/username/elonmusk?user.fields=public_metrics' --args 'string:GET' --args 'string:{}' --args 'string:{}' --args 'string:.data.public_metrics.followers_count' --args 'address:0x694cbe655b126e9e6a997e86aaab39e538abf30a8c78669ce23a98740b47b65d'
191197
```
192198

193-
To check the state of the response object on testnet, devnet, or mainnet,
199+
To check the state of the response object on testnet, devnet, or mainnet,
194200

195201
1. Switch to the relevant network using `rooch env switch --alias <NETWORK_ALIAS>`
196202
2. Use the following command:

orchestrator/prisma-dev/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { PrismaClient } from "@prisma/client";
2+
3+
const prismaClient = new PrismaClient();
4+
export default prismaClient;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// This is your Prisma schema file,
2+
// learn more about it in the docs: https://pris.ly/d/prisma-schema
3+
4+
generator client {
5+
provider = "prisma-client-js"
6+
}
7+
8+
datasource db {
9+
provider = "sqlite"
10+
url = env("DATABASE_URL_DEV")
11+
}
12+
13+
model Events{
14+
id String @id @default(cuid())
15+
eventHandleId String
16+
eventSeq BigInt
17+
eventType String
18+
eventData String
19+
eventIndex String
20+
decoded_event_data String //JSON String
21+
chain String @default("ROOCH-testnet")
22+
23+
status Int
24+
retries Int
25+
response String?
26+
indexedAt DateTime @default(now())
27+
updateAt DateTime @updatedAt
28+
29+
@@index([eventHandleId, eventSeq,chain])
30+
}
31+
32+
model Keeper{
33+
id String @id @default(cuid())
34+
chain String @default("ROOCH-testnet")
35+
module String
36+
privateKey String
37+
38+
createdAt DateTime @default(now())
39+
updateAt DateTime @updatedAt
40+
41+
@@unique([chain, module])
42+
43+
}

orchestrator/src/env.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const baseConfig = {
2525
// Integrations
2626
xBearerToken: process.env.X_BEARER_TOKEN ?? "",
2727
openAIToken: process.env.OPEN_AI_TOKEN ?? "",
28+
albyAccessToken: process.env.ALBY_ACCESS_TOKEN ?? "",
2829
};
2930

3031
interface IEnvVars {
@@ -43,6 +44,7 @@ interface IEnvVars {
4344
batchSize: number;
4445
xBearerToken: string;
4546
openAIToken: string;
47+
albyAccessToken: string;
4648
}
4749

4850
const envVarsSchema = Joi.object({
@@ -93,6 +95,7 @@ const envVarsSchema = Joi.object({
9395
// Integrations
9496
xBearerToken: Joi.string().allow("").required(),
9597
openAIToken: Joi.string().allow("").required(),
98+
albyAccessToken: Joi.string().allow("").required(),
9699

97100
// Common
98101
sentryDSN: Joi.string().allow("", null),
@@ -117,6 +120,7 @@ export default {
117120
integrations: {
118121
xBearerToken: envVars.xBearerToken,
119122
openAIToken: envVars.openAIToken,
123+
albyAccessToken: envVars.albyAccessToken,
120124
},
121125
rooch: {
122126
chainId: envVars.roochChainId,

orchestrator/src/indexer/base.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { log } from "@/logger";
22
import { type ProcessedRequestAdded, RequestStatus } from "@/types";
33

4+
import { instance as albyInstance } from "@/integrations/alby";
45
import { instance as openAIInstance } from "@/integrations/openAI";
56
import { instance as xTwitterInstance } from "@/integrations/xtwitter";
67

@@ -50,6 +51,9 @@ export abstract class Indexer {
5051
if (openAIInstance.isApprovedPath(url)) {
5152
return openAIInstance;
5253
}
54+
if (albyInstance.isApprovedPath(url)) {
55+
return albyInstance;
56+
}
5357
return null;
5458
}
5559

orchestrator/src/indexer/rooch.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import env from "@/env";
2+
import { instance as albyInstance } from "@/integrations/alby";
23
import { instance as xTwitterInstance } from "@/integrations/xtwitter";
34
import { log } from "@/logger";
45
import type { IEvent, IRequestAdded, JsonRpcResponse, ProcessedRequestAdded, RoochNetwork } from "@/types";
@@ -115,6 +116,7 @@ export default class RoochIndexer extends Indexer {
115116
for (let i = 0; i < skippedRequests.length; i++) {
116117
try {
117118
await new Promise((resolve) => setTimeout(resolve, xTwitterInstance.getRequestRate));
119+
await new Promise((resolve) => setTimeout(resolve, albyInstance.getRequestRate));
118120
const event = skippedRequests[i];
119121
const data = await this.processRequestAddedEvent(event);
120122
if (data) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import env from "@/env";
2+
import { BasicBearerAPIHandler } from "./base";
3+
4+
export default class AlbyIntegration extends BasicBearerAPIHandler {
5+
validatePayload(path: string): boolean {
6+
return true;
7+
}
8+
}
9+
10+
export const instance = new AlbyIntegration(
11+
env.integrations.albyAccessToken,
12+
["api.getalby.com"],
13+
["/nwc/nip47/info", "/nwc/nip47", "/nwc/publish", "/nwc/subscriptions", "/nwc/nip47/notifications", "/nwc/subscriptions/"],
14+
60 * 1000,
15+
);

package.json

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@
77
"node": ">=18"
88
},
99
"type": "module",
10-
"keywords": ["web3", "crypto", "blockchain", "move", "verity", "smart-contracts"],
10+
"keywords": [
11+
"web3",
12+
"crypto",
13+
"blockchain",
14+
"move",
15+
"verity",
16+
"smart-contracts"
17+
],
1118
"author": "Ryan Soury <[email protected]>",
1219
"license": "LGPL-2.1",
1320
"bugs": {
@@ -21,14 +28,18 @@
2128
"lint": "biome check orchestrator/src/",
2229
"lint:fix": "biome check orchestrator/src/ --fix",
2330
"clean": "del dist",
24-
"clean:db": "del ./orchestrator/prisma/.db*",
31+
"clean:db": "del ./orchestrator/prisma/*.db*",
32+
"clean:db:dev": "del ./orchestrator/prisma-dev/*.db*",
2533
"prepare": "husky",
2634
"format": "biome format orchestrator/src/ --fix",
2735
"sentry:sourcemaps": "sentry-cli sourcemaps inject --org usherlabs --project verity-move-oracles ./dist && sentry-cli sourcemaps upload --org usherlabs --project verity-move-oracles ./dist",
2836
"test": "jest --runInBand ",
2937
"prisma:generate": "prisma generate --schema=./orchestrator/prisma/schema.prisma",
38+
"prisma:generate:dev": "prisma generate --schema=./orchestrator/prisma-dev/schema.prisma",
3039
"prisma:deploy": "prisma migrate deploy --schema=./orchestrator/prisma/schema.prisma",
31-
"prisma:studio": "prisma studio --schema=./orchestrator/prisma/schema.prisma"
40+
"prisma:deploy:dev": "prisma migrate deploy --schema=./orchestrator/prisma-dev/schema.prisma",
41+
"prisma:studio": "prisma studio --schema=./orchestrator/prisma/schema.prisma",
42+
"prisma:studio:dev": "prisma studio --schema=./orchestrator/prisma-dev/schema.prisma"
3243
},
3344
"devDependencies": {
3445
"@biomejs/biome": "^1.8.3",
@@ -65,13 +76,17 @@
6576
"tslog": "^4.9.3"
6677
},
6778
"lint-staged": {
68-
"*.{js,ts,cjs,mjs,d.cts,d.mts,json,jsonc}": ["biome check --apply --no-errors-on-unmatched"]
79+
"*.{js,ts,cjs,mjs,d.cts,d.mts,json,jsonc}": [
80+
"biome check --apply --no-errors-on-unmatched"
81+
]
6982
},
7083
"prisma": {
7184
"schema": "orchestrator/prisma/schema.prisma"
7285
},
7386
"tsup": {
74-
"entry": ["./orchestrator/src"],
87+
"entry": [
88+
"./orchestrator/src"
89+
],
7590
"splitting": false,
7691
"sourcemap": true,
7792
"clean": true

0 commit comments

Comments
 (0)