Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
- name: Compile circuits
run: yarn circuits circuit:setup:plonk

- name: Run test-ts setup and test SDK and Relayer
- name: Run test-ts setup and test SDK, Relayer and Denylist Bot
env:
CF_TOKEN: ${{ secrets.CF_API_TOKEN }}
CF_IDENTIFIER: ${{ secrets.CF_IDENTIFIER }}
Expand Down
22 changes: 21 additions & 1 deletion .github/workflows/prod_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ on:
- main

jobs:
relayer_deploy:
production_deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down Expand Up @@ -97,6 +97,26 @@ jobs:
command: publish --name prod-relayer --keep-vars
workingDirectory: 'packages/relayer'

- name: Building Denylist Bot
run: yarn denylist build

- name: Set Denylist Variables
env:
NEAR_NETWORK: ${{ env.VITE_NEAR_NETWORK }}
RPC_URL: ${{ env.VITE_NEAR_NODE_URL }}
HYC_CONTRACT: ${{ env.VITE_CONTRACT }}
GRAPHQL_URL: ${{ env.VITE_RELAYER_URL }}
CF_API_TOKEN: ${{ secrets.CF_API_TOKEN }}
CF_IDENTIFIER: ${{ secrets.CF_IDENTIFIER }}
run: yarn denylist populate:envs

- name: Publish Denylist Worker
uses: cloudflare/[email protected]
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
command: publish --name hyc-denybot --keep-vars
workingDirectory: 'packages/denylist-bot'

- name: Compile circuits
run: yarn circuits circuit:setup:plonk

Expand Down
4 changes: 0 additions & 4 deletions .husky/pre-commit

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"contract_libraries": "yarn workspace @near/contract_libraries",
"subgraph": "yarn workspace @near/subgraph",
"sdk": "yarn workspace hideyourcash-sdk",
"denylist": "yarn workspace denylist-bot",
"relayer": "yarn workspace relayer"
},
"engines": {
Expand Down
Binary file added packages/contracts/proxy_contract_release.wasm
Binary file not shown.
35 changes: 33 additions & 2 deletions packages/contracts/tests-ts/src/actions/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
TREE_HEIGHT,
ZERO_VALUE,
PROTOCOL_FEE,
HAPI_ONE_TESTNET,
RISK_PARAMS,
Q,
QF,
Expand All @@ -20,12 +19,44 @@ type Currency =
account_id: string;
};

export const deployHapi = async ({
account,
owner,
}: {
account: Account;
owner: Account;
}): Promise<any> => {
const contractWasm = fs.readFileSync("../proxy_contract_release.wasm");

await account.deployContract(contractWasm);

await account.functionCall({
contractId: account.accountId,
methodName: "new",
args: {
owner_id: owner.accountId,
},
gas: new BN("300000000000000"),
});

await owner.functionCall({
contractId: account.accountId,
methodName: "create_reporter",
args: {
address: owner.accountId,
permission_level: 1,
},
});
};

export const deployRegistry = async ({
account,
owner,
hapi,
}: {
account: Account;
owner: Account;
hapi: Account;
}): Promise<any> => {
const contractWasm = fs.readFileSync("../out/registry.wasm");

Expand All @@ -36,7 +67,7 @@ export const deployRegistry = async ({
methodName: "new",
args: {
owner: owner.accountId,
authorizer: HAPI_ONE_TESTNET,
authorizer: hapi.accountId,
// vec of tupples (category, max_risk_threshold)
risk_params: RISK_PARAMS,
// merkle tree params
Expand Down
2 changes: 0 additions & 2 deletions packages/contracts/tests-ts/src/constants/merkle-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ export const FT_DECIMALS = "000000";

export const NEAR_DECIMALS = "000000000000000000000000";

export const HAPI_ONE_TESTNET = "proxy.hapi-npo.testnet";

export const Q =
"21888242871839275222246405745257275088548364400416034343698204186575808495617";

Expand Down
17 changes: 16 additions & 1 deletion packages/contracts/tests-ts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { deployToken, sendDeposit } from "./actions/token";
import { createAccount } from "./actions/account";
import { getConnection } from "./actions/connection";
import { FT_DECIMALS } from "./constants";
import { deployInstance, deployRegistry, addEntry } from "./actions/registry";
import { deployInstance, deployRegistry, addEntry, deployHapi } from "./actions/registry";
import { addBalances, addStorage, registerUser } from "./actions/contracts";
import { buildCommitments } from "./prepare_commitments";
import { readInputs } from "./utils/file";
Expand Down Expand Up @@ -80,16 +80,29 @@ export async function setup(): Promise<void> {
accountId: `${random_prefix}sdk.testnet`,
});

const hapiOneAccount = await createAccount({
creator,
config,
near,
accountId: `${random_prefix}hapione.testnet`,
});

console.log("Deploying tokens and instances");

await deployToken({
owner,
account: tokenContractAccount,
});

await deployHapi({
owner,
account: hapiOneAccount,
});

await deployRegistry({
owner,
account: registryAccount,
hapi: hapiOneAccount,
});

await deployInstance({
Expand Down Expand Up @@ -207,11 +220,13 @@ export async function setup(): Promise<void> {
account: proofInputs.sdk,
tokenInstance: tokenInstanceAccount10.accountId,
hyc_contract: registryAccount.accountId,
hapi_contract: hapiOneAccount.accountId,
cache: output,
});

fs.writeFileSync("../../sdk/test/test_setup.json", testSetup);
fs.writeFileSync("../../relayer/test/test_setup.json", testSetup);
fs.writeFileSync("../../denylist-bot/test_setup.json", testSetup);

if (isCI) {
console.log("The code is running on a CI server");
Expand Down
6 changes: 6 additions & 0 deletions packages/denylist-bot/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
GRAPHQL_URL="https://api.thegraph.com/subgraphs/name/hack-a-chain/hyc_mainnet"
RPC_URL="https://rpc.testnet.near.org/"
PRIVATE_KEY=""
ACCOUNT_ID=""
HYC_CONTRACT=""
NEAR_NETWORK="testnet"
5 changes: 5 additions & 0 deletions packages/denylist-bot/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
dist
.mf
.env
testnet_setup.json
24 changes: 24 additions & 0 deletions packages/denylist-bot/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import path from "path";
import { build } from "esbuild";
import { fileURLToPath } from "url";
import { NodeModulesPolyfillPlugin } from "@esbuild-plugins/node-modules-polyfill";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

try {
await build({
bundle: true,
format: "esm",
external: ["__STATIC_CONTENT_MANIFEST"],
conditions: ["worker"],
entryPoints: [path.join(__dirname, "src", "index.ts")],
outdir: path.join(__dirname, "dist"),
outExtension: { ".js": ".mjs" },
plugins: [NodeModulesPolyfillPlugin()],
});
} catch (e) {
console.warn(e);

process.exitCode = 1;
}
14 changes: 14 additions & 0 deletions packages/denylist-bot/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default {
preset: "ts-jest/presets/default-esm",
globals: {
"ts-jest": {
tsconfig: "test/tsconfig.json",
useESM: true,
},
},
forceExit: true,
transform: {},
verbose: true,
detectOpenHandles: true,
clearMocks: true,
};
42 changes: 42 additions & 0 deletions packages/denylist-bot/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "denylist-bot",
"version": "1.0.0",
"description": "Production level CF Worker Bot",
"type": "module",
"module": "./dist/index.mjs",
"scripts": {
"build": "node build.js",
"dev": "miniflare --live-reload --debug --modules dist/index.mjs --env .env",
"dev:remote": "wrangler dev",
"test:only": "yarn build && node --experimental-vm-modules --no-warnings node_modules/.bin/jest --forceExit --detectOpenHandles",
"test": "(cd ../contracts && yarn tests:ts) && (cd ../sdk && yarn test:only) && yarn test:only --forceExit --detectOpenHandles",
"types:check": "tsc && tsc -p test/tsconfig.json",
"deploy": "yarn build && wrangler publish --keep-vars",
"populate:envs": "cd scripts && tsc && node build/populateEnvs.js"
},
"keywords": [],
"author": "",
"license": "MIT",
"devDependencies": {
"@cloudflare/workers-types": "^4.20230321.0",
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
"@jest/globals": "^29.5.0",
"@types/big.js": "^6.1.6",
"@types/jest": "^27.5.1",
"esbuild": "^0.14.41",
"jest": "^28.1.0",
"jest-environment-miniflare": "^2.5.0",
"miniflare": "^2.5.0",
"prettier": "^2.6.2",
"ts-jest": "^28.0.3",
"typescript": "^4.7.2",
"wrangler": "^2.0.7"
},
"dependencies": {
"@tsndr/cloudflare-worker-jwt": "^2.2.1",
"@tsndr/cloudflare-worker-router": "^2.3.2",
"big.js": "^6.2.1",
"buffer": "^6.0.3",
"near-api-js": "^1.1.0"
}
}
1 change: 1 addition & 0 deletions packages/denylist-bot/scripts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
5 changes: 5 additions & 0 deletions packages/denylist-bot/scripts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "relayer-scripts",
"version": "1.0.0",
"description": "Production level relayer with cloudflare workers"
}
62 changes: 62 additions & 0 deletions packages/denylist-bot/scripts/src/populateEnvs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { deploySecrets } from "./secrets";

const {
NEAR_NETWORK,
RPC_URL,
PRIVATE_KEY,
ACCOUNT_ID,
HYC_CONTRACT,
CF_API_TOKEN,
CF_IDENTIFIER,
GRAPHQL_URL,
} = process.env;

if (
!NEAR_NETWORK ||
!RPC_URL ||
!PRIVATE_KEY ||
!ACCOUNT_ID ||
!GRAPHQL_URL ||
!HYC_CONTRACT ||
!CF_API_TOKEN ||
!CF_IDENTIFIER
) {
throw new Error("There are missing Envs that need to be set");
}

console.log(`Deploy secrets for script: denylist bot`);

deploySecrets(CF_API_TOKEN, CF_IDENTIFIER, [
{
name: "NEAR_NETWORK",
text: NEAR_NETWORK,
type: 'secret_text',
},
{
name: "RPC_URL",
text: RPC_URL,
type: 'secret_text',
},
{
name: "PRIVATE_KEY",
text: PRIVATE_KEY,
type: 'secret_text',
},
{
name: "ACCOUNT_ID",
text: ACCOUNT_ID,
type: 'secret_text',
},
{
name: "GRAPHQL_URL",
text: GRAPHQL_URL,
type: 'secret_text',
},
{
name: "HYC_CONTRACT",
text: HYC_CONTRACT,
type: 'secret_text',
},
]).then(res => {
console.log('Deploy secrets res: ', res);
});
Loading