Skip to content

Commit

Permalink
feat: endpoint for adding l1 assets
Browse files Browse the repository at this point in the history
  • Loading branch information
just-mitch committed Dec 11, 2024
1 parent 8141c3b commit 08f091d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
2 changes: 1 addition & 1 deletion spartan/terraform/deploy-release/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ resource "helm_release" "aztec-gke-cluster" {
upgrade_install = true

# base values file
values = [file("../../aztec-network/values/${var.VALUES_FILE}"), "${var.VALUES_INLINE}"]
values = [file("../../aztec-network/values/${var.VALUES_FILE}")]

set {
name = "images.aztec.image"
Expand Down
6 changes: 0 additions & 6 deletions spartan/terraform/deploy-release/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ variable "VALUES_FILE" {
type = string
}

variable "VALUES_INLINE" {
description = "Inline values to set in a cluster"
type = string
default = ""
}

variable "AZTEC_DOCKER_IMAGE" {
description = "Docker image to use for the aztec network"
type = string
Expand Down
2 changes: 2 additions & 0 deletions yarn-project/aztec-faucet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,15 @@
"@aztec/l1-artifacts": "workspace:^",
"@koa/cors": "^5.0.0",
"koa": "^2.14.2",
"koa-bodyparser": "^4.4.1",
"koa-router": "^12.0.0",
"viem": "^2.7.15",
"zod": "^3.23.8"
},
"devDependencies": {
"@jest/globals": "^29.5.0",
"@types/jest": "^29.5.0",
"@types/koa-bodyparser": "^4.3.12",
"@types/node": "^18.7.23",
"jest": "^29.5.0",
"ts-node": "^10.9.1",
Expand Down
27 changes: 26 additions & 1 deletion yarn-project/aztec-faucet/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { type ApiSchemaFor, schemas } from '@aztec/foundation/schemas';
import cors from '@koa/cors';
import { createServer } from 'http';
import Koa from 'koa';
import bodyParser from 'koa-bodyparser';
import Router from 'koa-router';
import { z } from 'zod';

Expand All @@ -17,14 +18,37 @@ export function createFaucetHttpServer(faucet: Faucet, apiPrefix = '', logger =
const { asset } = ctx.query;

if (typeof asset !== 'string') {
throw new Error(`Bad asset: ${asset}`);
throw new Error(`Bad asset: [${asset}]`);
}

await faucet.send(EthAddress.fromString(address), asset);

ctx.status = 200;
});

const L1AssetRequestSchema = z.object({
address: z.string().transform(str => EthAddress.fromString(str)),
amount: z.string().transform(str => BigInt(str)),
});

router.post('/l1-asset', async ctx => {
if (!ctx.request.body) {
throw new Error('Invalid request body');
}

const result = L1AssetRequestSchema.safeParse(ctx.request.body);

if (!result.success) {
throw new Error(`Invalid request: ${result.error.message}`);
}

const { address, amount } = result.data;

await faucet.addL1Asset({ address, amount });

ctx.status = 200;
});

const app = new Koa();

app.on('error', error => {
Expand All @@ -42,6 +66,7 @@ export function createFaucetHttpServer(faucet: Faucet, apiPrefix = '', logger =
});

app.use(cors());
app.use(bodyParser());
app.use(router.routes());
app.use(router.allowedMethods());

Expand Down
6 changes: 4 additions & 2 deletions yarn-project/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,11 @@ __metadata:
"@jest/globals": ^29.5.0
"@koa/cors": ^5.0.0
"@types/jest": ^29.5.0
"@types/koa-bodyparser": ^4.3.12
"@types/node": ^18.7.23
jest: ^29.5.0
koa: ^2.14.2
koa-bodyparser: ^4.4.1
koa-router: ^12.0.0
ts-node: ^10.9.1
typescript: ^5.0.4
Expand Down Expand Up @@ -5196,7 +5198,7 @@ __metadata:
languageName: node
linkType: hard

"@types/koa-bodyparser@npm:^4.3.10":
"@types/koa-bodyparser@npm:^4.3.10, @types/koa-bodyparser@npm:^4.3.12":
version: 4.3.12
resolution: "@types/koa-bodyparser@npm:4.3.12"
dependencies:
Expand Down Expand Up @@ -13680,7 +13682,7 @@ __metadata:
languageName: node
linkType: hard

"koa-bodyparser@npm:^4.4.0":
"koa-bodyparser@npm:^4.4.0, koa-bodyparser@npm:^4.4.1":
version: 4.4.1
resolution: "koa-bodyparser@npm:4.4.1"
dependencies:
Expand Down

0 comments on commit 08f091d

Please sign in to comment.