Skip to content

Commit

Permalink
feat: shared config endpoint (#212)
Browse files Browse the repository at this point in the history
* feat: shared config endpoint

* chore: resource endpoint + domains renamed + domain metadata defined for testnet and mainnet

* chore: resources metadata and some cleanup for the domain ones

* chore: 404 if you dont find resource or metadata

* chore: explorer urls

* chore: removing phala from testnet metadata

* chore: adding render name to remove unnecessary functions on explorer ui

* chore: update schema and resource metadata info

* chore: update workflow file

* chore: update workflow file for e2e test

* chore: small update on schema remove error on runtime

* chore: update schema to have correct serialization

* chore: change url for icon property name

* chore: adding bitcoin and layer edge logos urls
  • Loading branch information
wainola authored Sep 9, 2024
1 parent f0876a0 commit 5ef7c52
Show file tree
Hide file tree
Showing 7 changed files with 598 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
run: yarn run license-check
- run: yarn run build
- name: Run docker
run: docker-compose up -d
run: docker compose up -d
- name: Wait
run: sleep 50s
- name: Run tests
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e_testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Install dependencies
run: yarn install --frozen-lockfile --non-interactive
- name: Run docker
run: docker-compose up -d
run: docker compose up -d
- name: Wait
run: sleep 50s
- name: Run tests
Expand Down
20 changes: 17 additions & 3 deletions src/controllers/DomainController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,33 @@ SPDX-License-Identifier: LGPL-3.0-only
*/
import { FastifyReply, FastifyRequest } from "fastify"
import { Environment } from "@buildwithsygma/sygma-sdk-core"
import { ResourcesMetadataConfig } from "../utils/resourcesMetadata"
import { logger } from "../utils/logger"
import { DomainMetadataConfig } from "../utils/domainMetadata"

const env = process.env.ENVIRONMENT || ""
const environment = (env.toLowerCase() as Environment) || Environment.MAINNET
export const DomainsController = {
domains: function (request: FastifyRequest<{}>, reply: FastifyReply): void {
domainsMetadata: function (request: FastifyRequest<{}>, reply: FastifyReply): void {
const metadata = DomainMetadataConfig[environment]
if (metadata) {
void reply.status(200).send(metadata)
void reply.status(200).send(JSON.stringify(metadata))
} else {
logger.error(`Unable to find metadata for environment ${environment}`)
void reply.status(500)
void reply.status(404)
}
},
resources: function (request: FastifyRequest<{ Params: { domainID: string } }>, reply: FastifyReply): void {
const {
params: { domainID },
} = request
const resources = ResourcesMetadataConfig[environment]!

if (!resources) {
logger.error(`Unable to find resources metadata for ${environment}`)
void reply.status(404)
} else {
void reply.status(200).send(resources[parseInt(domainID)])
}
},
}
55 changes: 50 additions & 5 deletions src/controllers/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,20 +414,65 @@ export const domainsMetadataSchema = {
type: "object",
properties: {
url: { type: "string" },
name: { type: "string" },
caipId: { type: "string" },
nativeTokenSymbol: { type: "string" },
nativeTokenDecimals: { type: "integer" },
nativeTokenFullName: { type: "string" },
type: { type: "string" },
blockExplorerUrl: { type: "string" },
renderName: { type: "string" },
},
},
example: {
domainId1: {
url: "https://scan.buildwithsygma.com",
name: "Sepolia",
caipId: "eip155:11155111",
nativeTokenSymbol: "eth",
nativeTokenDecimals: 18,
nativeTokenFullName: "eth",
type: "evm",
blockExplorerUrl: "https://sepolia.etherscan.io",
renderName: "Sepolia",
},
domainId2: {
url: "https://scan.buildwithsygma.com",
},
domainId3: {
url: "https://scan.buildwithsygma.com",
},
},
},
},
},
},
}

export const resourcesByDomainSchema = {
summary: "Get resources from a specific domain",
response: {
200: {
description: "Resources",
content: {
"application/json": {
schema: {
type: "array",
items: {
type: "object",
properties: {
caipId: { type: "string" },
symbol: { type: "string" },
decimals: { type: "integer" },
resourceId: { type: "string" },
},
},
},
example: {
domainId1: [
{
caipId: "eip155:11155111/erc721:0x285207Cbed7AF3Bc80E05421D17AE1181d63aBd0",
symbol: "ERC721TST",
decimals: 0,
resourceId: "0x",
},
],
},
},
},
},
Expand Down
10 changes: 9 additions & 1 deletion src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { FastifyInstance } from "fastify"
import { TransfersController } from "./controllers/TransfersController"
import {
domainsMetadataSchema,
resourcesByDomainSchema,
routesByDomainSchema,
transferByIdSchema,
transferByTxHashAndDomainSchema,
Expand Down Expand Up @@ -81,7 +82,7 @@ export async function routes(fastify: FastifyInstance): Promise<void> {
method: "GET",
url: "/domains/metadata",
schema: domainsMetadataSchema,
handler: DomainsController.domains,
handler: DomainsController.domainsMetadata,
})

fastify.route({
Expand All @@ -90,4 +91,11 @@ export async function routes(fastify: FastifyInstance): Promise<void> {
schema: routesByDomainSchema,
handler: RoutesController.routes,
})

fastify.route({
method: "GET",
url: "/domains/:domainID/resources",
schema: resourcesByDomainSchema,
handler: DomainsController.resources,
})
}
Loading

0 comments on commit 5ef7c52

Please sign in to comment.