Skip to content

Commit

Permalink
Sponsorship Policy API functions and Integrate with paymaster data ge…
Browse files Browse the repository at this point in the history
…neration endpoint (#111)

* feat: PRO-2395 Design doc for sponsorship policy management

* feat: PRO-2395 sponsorship policy db migration

* feat: PRO-2395 sequelize integration to backend and property name updates for APIKey entity references in backend and frontend components

* feat: PRO-2395 update apiKey sequelize based response reference in admin-frontend

* feat: PRO-2395 sequelize models and centralised model association files for sponsorship_policy tables and api_keys association

* feat: PRO-2395 refactor sequelize models and their initialisation in the sequelizePlugin

* fix: PRO-2395 admin-frontend to parse the error message from response while saving apiKey

* feat: PRO-2395 sequelize models updated with new association relationships

* feat: PRO-2395 sequelize init and test

* feat: PRO-2395 migration scripts refactored and updated

* feat: PRO-2395 sequelize repository updates and conflict resolution

* fix: PRO-2395 admin-frontend global-config components fix

* chore: PRO-2395 logging updates

* feat: PRO-2395 restricted sequelize references from repository, server and index files only

* fix: PRO-2395 Fix SponsorshipPolicy migrations and sequelize models naming issues

* chore: PRO-2395 delete obselete file at root directory

* feat: PRO-2395 denormalize SponsorshipPolicy table data

* feat: PRO-2395 refactor types and optimise imports

* fix: PRO-2395 adjust the property name to typescript model fieldnames

* feat: PRO-2395 SponsorshipPolicy repository functions and package version upgrade for all 3 projects in arka

* fix: PRO-2395 fix imports in backend

* feat: PRO-2395 SponsorshipPolicy validations, db model updates and docker updates

* doc: PRO-2395 docker documentation for backend updated in readme file

* feat: PRO-2455 validate userOp in sponsorMode with sponsorshipPolicy constraints

* feat: PRO-2455 refactor sponsorship-policy to include EP version and new route functions

* feat: PRO-2455 sponsorship-policy validation logic updated

* fix: PRO-2455 fix sequelize model update pattern

* fix: PRO-2455 SponsorshipPolicy query functions from chainId, EntryPointVersion and apiKey

* feat: PRO-2455 api-endpoint refactoring for sponsorship policy extraction via policyId or apiKey

* feat: PRO-2455 HMAC env added and function imports fixed

* feat: PRO-2455 configure the SSL options for sequelize

* feat: PRO-2455 sequelize migration standalone script and added script command in package.json

* fix: PRO-2455 docker-compose fixes

* fix: PRO-2455 sponsorship-policy api endpoints fixed

* feat: PRO-2455 externalise values from docker-compose to env variable file

* doc: PRO-2455 backend and arka docker startup instructions

* feat: rearrange docker-compose files

* feat: PRO-2455 add new api route functions for sponsorship-policy

* feat: PRO-2455 split functions in routes

* feat: PRO-2455 split functions in routes

* feat: PRO-2455 refactor local docker setup instructions and local postgres database docker file setup to project root directory
  • Loading branch information
kanthgithub authored Jun 26, 2024
1 parent 58a37f8 commit 2d265c8
Show file tree
Hide file tree
Showing 65 changed files with 4,102 additions and 1,532 deletions.
21 changes: 21 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
LOG_LEVEL=
API_HOST=
API_PORT=
UNSAFE_MODE=true
SUPPORTED_NETWORKS=
CRON_PRIVATE_KEY=
DEFAULT_INDEXER_ENDPOINT=
FEE_MARKUP=0
MULTI_TOKEN_MARKUP=
ADMIN_WALLET_ADDRESS=
ETHERSCAN_GAS_ORACLES=""
DEFAULT_API_KEY=""
WEBHOOK_URL=
HMAC_SECRET=
DATABASE_URL=
DATABASE_USER=
DATABASE_PASSWORD=
DATABASE_NAME=
DATABASE_SCHEMA_NAME=arka
DATABASE_SSL_ENABLED=false
DATABASE_SSL_REJECT_UNAUTHORIZED=false
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules

# build
/build/

# misc
.DS_Store
.env.production

# debug
npm-debug.log*

.nyc_output
coverage

.env
config.json
database.sqlite

package-lock.json
pnpm-lock.yaml

# Ponder
/indexer/.ponder
/indexer/generated
yarn.lock
107 changes: 106 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,114 @@ To run your own instance of this, please [follow these steps.](https://github.co

You can see a [list of available endpoints here](https://github.com/etherspot/arka/tree/master/backend#available-endpoints--).


### Local - Setup

#### environment for backend

1. Start Docker postgres database

```sh
cd local-setup
```

```sh
docker-compose up -d
```

- Verify if the postgres docker instance is up and running

```sh
docker ps -a
```

```sh
docker logs --follow local-setup-db-1
```

- It must show up logs similar to this

```
PostgreSQL init process complete; ready for start up.
2024-06-24 19:31:56.739 UTC [1] LOG: starting PostgreSQL 16.1 (Debian 16.1-1.pgdg120+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
2024-06-24 19:31:56.740 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2024-06-24 19:31:56.740 UTC [1] LOG: listening on IPv6 address "::", port 5432
2024-06-24 19:31:56.741 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2024-06-24 19:31:56.744 UTC [66] LOG: database system was shut down at 2024-06-24 19:31:56 UTC
2024-06-24 19:31:56.748 UTC [1] LOG: database system is ready to accept connections
```

2. create .env

```sh
cp .env.example .env
```

3. populate these environment variables

```sh
LOG_LEVEL=
API_HOST=
API_PORT=
UNSAFE_MODE=true
SUPPORTED_NETWORKS=
CRON_PRIVATE_KEY=
DEFAULT_INDEXER_ENDPOINT=
FEE_MARKUP=0
MULTI_TOKEN_MARKUP=
ADMIN_WALLET_ADDRESS=
ETHERSCAN_GAS_ORACLES=""
DEFAULT_API_KEY=""
WEBHOOK_URL=
HMAC_SECRET=
DATABASE_URL=
DATABASE_USER=
DATABASE_PASSWORD=
DATABASE_NAME=
DATABASE_SCHEMA_NAME=arka
DATABASE_SSL_ENABLED=false
DATABASE_SSL_REJECT_UNAUTHORIZED=false
```

4. start docker instance for backend, admin_frontend, frontend

```sh
docker-compose up --build -d
```

5. Here we need to create a network and tag backend & postgres on same network

```sh
docker network create arka-network
```

6. add postgres instance to docker network

```sh
docker network connect arka-network local-setup-db-1
```

7. add arka backend docker instance to docker-network

```sh
docker network connect arka-network arka-backend-1
```

8. restart backend docker instance

```sh
docker-compose up -d
```

9. verify backend logs

```sh
docker logs arka-backend-1
```

## 🖥 Arka Admin Frontend

This contains ability to change configuration that are available in sql.
This contains ability to change system configuration, apiKeys and apiKey-config that are available in database.

## 🖥 Arka Frontend

Expand Down
4 changes: 2 additions & 2 deletions admin_frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*

.env
yarn.lock
.env
2 changes: 1 addition & 1 deletion admin_frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "admin_frontend",
"version": "1.2.6",
"version": "1.2.7",
"private": true,
"dependencies": {
"@emotion/react": "11.11.3",
Expand Down
44 changes: 22 additions & 22 deletions admin_frontend/src/components/ApiKeys.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ const ApiKeysPage = () => {
);
const dataJson = await data.json();
dataJson.filter((element) => {
if (element.SUPPORTED_NETWORKS) {
const buffer = Buffer.from(element.SUPPORTED_NETWORKS, "base64");
if (element.supportedNetworks) {
const buffer = Buffer.from(element.supportedNetworks, "base64");
const parsedSupportedNetowrks = JSON.parse(buffer.toString());
element.SUPPORTED_NETWORKS = parsedSupportedNetowrks;
element.supportedNetworks = parsedSupportedNetowrks;
}
if (element.ERC20_PAYMASTERS) {
const buffer = Buffer.from(element.ERC20_PAYMASTERS, "base64");
if (element.erc20Paymasters) {
const buffer = Buffer.from(element.erc20Paymasters, "base64");
const parsedErc20Paymasters = JSON.parse(buffer.toString());
element.ERC20_PAYMASTERS = parsedErc20Paymasters;
element.erc20Paymasters = parsedErc20Paymasters;
}
return element;
});
Expand Down Expand Up @@ -135,12 +135,12 @@ const ApiKeysPage = () => {
JSON.stringify(customErc20Paymaster)
).toString("base64");
const requestData = {
API_KEY: apiKey,
PRIVATE_KEY: privateKey,
SUPPORTED_NETWORKS:
apiKey: apiKey,
privateKey: privateKey,
supportedNetworks:
Buffer.from(JSON.stringify(supportedNetworks)).toString("base64") ??
"",
ERC20_PAYMASTERS: base64Erc20 ?? "",
erc20Paymasters: base64Erc20 ?? "",
};
const data = await fetch(
`${process.env.REACT_APP_SERVER_URL}${ENDPOINTS["saveKey"]}`,
Expand All @@ -149,15 +149,15 @@ const ApiKeysPage = () => {
body: JSON.stringify(requestData),
}
);
const dataJson = data.json();
const dataJson = await data.json();
if (!dataJson.error) {
toast.success("Saved Successfully");
setApiKey("");
setPrivateKey("");
fetchData();
} else {
setLoading(false);
toast.error(`${dataJson.message} Please try again or contant Arka support team`);
toast.error(`${dataJson.error} Please try again or contant Arka support team`);
}
} catch (err) {
if (err?.message?.includes("Failed to fetch")) {
Expand All @@ -174,7 +174,7 @@ const ApiKeysPage = () => {
`${process.env.REACT_APP_SERVER_URL}${ENDPOINTS["deleteKey"]}`,
{
method: "POST",
body: JSON.stringify({ API_KEY: key }),
body: JSON.stringify({ apiKey: key }),
}
);
const dataJson = data.json();
Expand Down Expand Up @@ -280,12 +280,12 @@ const ApiKeysPage = () => {
</TableCell>
</TableRow>
{keys.map((row, index) => (
<TableRow key={row.API_KEY}>
<TableCell>{row.WALLET_ADDRESS}</TableCell>
<TableCell>{row.API_KEY}</TableCell>
<TableRow key={row.apiKey}>
<TableCell>{row.walletAddress}</TableCell>
<TableCell>{row.apiKey}</TableCell>
<TableCell>
<div className="flex flex-row">
<div>{showPassword ? row.PRIVATE_KEY : "*****"} </div>
<div>{showPassword ? row.privateKey : "*****"} </div>
<div>
<InputAdornment position="end">
<IconButton
Expand All @@ -302,16 +302,16 @@ const ApiKeysPage = () => {
</TableCell>
<TableCell>
<Button
disabled={row.SUPPORTED_NETWORKS === ""}
onClick={() => handleViewOpen(row.SUPPORTED_NETWORKS)}
disabled={row.supportedNetworks === ""}
onClick={() => handleViewOpen(row.supportedNetworks)}
>
View
</Button>
</TableCell>
<TableCell>
<Button
disabled={row.ERC20_PAYMASTERS === ""}
onClick={() => handleViewERC20Open(row.ERC20_PAYMASTERS)}
disabled={row.erc20Paymasters === ""}
onClick={() => handleViewERC20Open(row.erc20Paymasters)}
>
View
</Button>
Expand All @@ -324,7 +324,7 @@ const ApiKeysPage = () => {
startIcon={<RemoveCircleIcon />}
variant="contained"
onClick={() => {
handleDelete(row.API_KEY);
handleDelete(row.apiKey);
}}
>
Delete Row
Expand Down
Loading

0 comments on commit 2d265c8

Please sign in to comment.