Skip to content

Commit

Permalink
add intent aggregator
Browse files Browse the repository at this point in the history
  • Loading branch information
d4mr committed Dec 6, 2024
1 parent 38be0e2 commit 56dda77
Show file tree
Hide file tree
Showing 23 changed files with 5,820 additions and 172 deletions.
33 changes: 33 additions & 0 deletions packages/intent-aggregator/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# prod
dist/

# dev
.yarn/
!.yarn/releases
.vscode/*
!.vscode/launch.json
!.vscode/*.code-snippets
.idea/workspace.xml
.idea/usage.statistics.xml
.idea/shelf

# deps
node_modules/
.wrangler

# env
.env
.env.production
.dev.vars

# logs
logs/
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

# misc
.DS_Store
8 changes: 8 additions & 0 deletions packages/intent-aggregator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
```
npm install
npm run dev
```

```
npm run deploy
```
50 changes: 50 additions & 0 deletions packages/intent-aggregator/drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { defineConfig, type Config } from "drizzle-kit";
import fs from "fs";
import path from "path";

const getLocalD1 = () => {
try {
const basePath = path.resolve(".wrangler");
const dbFile = fs
.readdirSync(basePath, { encoding: "utf-8", recursive: true })
.find((f) => f.endsWith(".sqlite"));

if (!dbFile) {
throw new Error(`.sqlite file not found in ${basePath}`);
}

const url = path.resolve(basePath, dbFile);
return url;
} catch (err) {
console.log(`Error ${err}`);
}
};

const isProd = () => process.env.NODE_ENV === "production";

const getCredentials = () => {
const prod = {
driver: "d1-http",
dbCredentials: {
databaseId: process.env.CLOUDFLARE_D1_ID,
accountId: process.env.CLOUDFLARE_ACCOUNT_ID,
token: process.env.CLOUDFLARE_API_TOKEN,
},
};

const dev = {
dbCredentials: {
url: getLocalD1(),
},
};

return isProd() ? prod : dev;
};

export default defineConfig({
dialect: "sqlite",
schema: "./db/schema/index.ts",
out: "./db/migrations",
tablesFilter: ["/^(?!.*_cf_KV).*$/"],
...getCredentials(),
}) satisfies Config;
32 changes: 32 additions & 0 deletions packages/intent-aggregator/migrations/0000_small_paibok.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
CREATE TABLE `intents` (
`id` text PRIMARY KEY NOT NULL,
`payment_token` text NOT NULL,
`payment_token_amount` text NOT NULL,
`rail_type` text NOT NULL,
`recipient_address` text NOT NULL,
`rail_amount` text NOT NULL,
`creator_address` text NOT NULL,
`chain_id` integer NOT NULL,
`created_at` text DEFAULT CURRENT_TIMESTAMP NOT NULL,
`state` text DEFAULT 'CREATED' NOT NULL,
`winning_solution_id` text,
`resolution_tx_hash` text
);
--> statement-breakpoint
CREATE INDEX `creator_idx` ON `intents` (`creator_address`);--> statement-breakpoint
CREATE INDEX `state_idx` ON `intents` (`state`);--> statement-breakpoint
CREATE INDEX `rail_idx` ON `intents` (`rail_type`);--> statement-breakpoint
CREATE TABLE `solutions` (
`id` text PRIMARY KEY NOT NULL,
`intent_id` text NOT NULL,
`solver_address` text NOT NULL,
`amount_wei` text NOT NULL,
`signature` text NOT NULL,
`created_at` text DEFAULT CURRENT_TIMESTAMP NOT NULL,
`commitment_tx_hash` text,
`payment_metadata` text,
FOREIGN KEY (`intent_id`) REFERENCES `intents`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE INDEX `intent_solutions_idx` ON `solutions` (`intent_id`);--> statement-breakpoint
CREATE INDEX `solver_idx` ON `solutions` (`solver_address`);
232 changes: 232 additions & 0 deletions packages/intent-aggregator/migrations/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
{
"version": "6",
"dialect": "sqlite",
"id": "39865177-9e6c-482b-935b-9e4fd1bdc31f",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"intents": {
"name": "intents",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"payment_token": {
"name": "payment_token",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"payment_token_amount": {
"name": "payment_token_amount",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"rail_type": {
"name": "rail_type",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"recipient_address": {
"name": "recipient_address",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"rail_amount": {
"name": "rail_amount",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"creator_address": {
"name": "creator_address",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"chain_id": {
"name": "chain_id",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "CURRENT_TIMESTAMP"
},
"state": {
"name": "state",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'CREATED'"
},
"winning_solution_id": {
"name": "winning_solution_id",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"resolution_tx_hash": {
"name": "resolution_tx_hash",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {
"creator_idx": {
"name": "creator_idx",
"columns": [
"creator_address"
],
"isUnique": false
},
"state_idx": {
"name": "state_idx",
"columns": [
"state"
],
"isUnique": false
},
"rail_idx": {
"name": "rail_idx",
"columns": [
"rail_type"
],
"isUnique": false
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"solutions": {
"name": "solutions",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"intent_id": {
"name": "intent_id",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"solver_address": {
"name": "solver_address",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"amount_wei": {
"name": "amount_wei",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"signature": {
"name": "signature",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "CURRENT_TIMESTAMP"
},
"commitment_tx_hash": {
"name": "commitment_tx_hash",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"payment_metadata": {
"name": "payment_metadata",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {
"intent_solutions_idx": {
"name": "intent_solutions_idx",
"columns": [
"intent_id"
],
"isUnique": false
},
"solver_idx": {
"name": "solver_idx",
"columns": [
"solver_address"
],
"isUnique": false
}
},
"foreignKeys": {
"solutions_intent_id_intents_id_fk": {
"name": "solutions_intent_id_intents_id_fk",
"tableFrom": "solutions",
"tableTo": "intents",
"columnsFrom": [
"intent_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
}
},
"views": {},
"enums": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
},
"internal": {
"indexes": {}
}
}
13 changes: 13 additions & 0 deletions packages/intent-aggregator/migrations/meta/_journal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "7",
"dialect": "sqlite",
"entries": [
{
"idx": 0,
"version": "6",
"when": 1733522405248,
"tag": "0000_small_paibok",
"breakpoints": true
}
]
}
Loading

0 comments on commit 56dda77

Please sign in to comment.