Skip to content

Commit

Permalink
feat: opact tickets
Browse files Browse the repository at this point in the history
  • Loading branch information
1Mateus committed Jan 10, 2024
1 parent bd01a28 commit 1fc4ae3
Show file tree
Hide file tree
Showing 230 changed files with 12,271 additions and 71,664 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/CI.yml
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 All @@ -70,11 +70,11 @@ jobs:
echo "private_key=${{ env.TESTNET_RELAYER_PRIVATE_KEY }}" >> "$GITHUB_OUTPUT"
echo "hyc_contract=${{ env.TESTNET_HYC_CONTRACT }}" >> "$GITHUB_OUTPUT"
- name: Rust Tests
run: yarn contracts test:rust
# - name: Rust Tests
# run: yarn contracts test:rust

- name: Lib Tests
run: yarn contracts test:lib
# - name: Lib Tests
# run: yarn contracts test:lib

- name: Front build
run: yarn front build
Expand Down
75 changes: 48 additions & 27 deletions .github/workflows/prod_deploy.yml
Expand Up @@ -33,8 +33,10 @@ on:
branches:
- main

# on: pull_request

jobs:
relayer_deploy:
production_deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down Expand Up @@ -70,32 +72,51 @@ jobs:
- name: Installing Dependencies
run: yarn

- name: Signin on TheGraph
run: yarn subgraph auth

- name: Deploy The graph
run: yarn subgraph deploy:production

- name: Building Relayer
run: yarn relayer build

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


- name: Publish Relayer
uses: cloudflare/wrangler-action@2.0.0
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
command: publish --name prod-relayer --keep-vars
workingDirectory: 'packages/relayer'
# - name: Signin on TheGraph
# run: yarn subgraph auth

# - name: Deploy The graph
# run: yarn subgraph deploy:production

# - name: Building Relayer
# run: yarn relayer build

# - name: Set Relayer Variables
# env:
# NEAR_NETWORK: ${{ env.VITE_NEAR_NETWORK }}
# RPC_URL: ${{ env.VITE_NEAR_NODE_URL }}
# RELAYER_URL: ${{ env.VITE_RELAYER_URL }}
# HYC_CONTRACT: ${{ env.VITE_CONTRACT }}
# CF_API_TOKEN: ${{ secrets.CF_API_TOKEN }}
# CF_IDENTIFIER: ${{ secrets.CF_IDENTIFIER }}
# run: yarn relayer populate:envs

# - name: Publish Relayer
# uses: cloudflare/wrangler-action@2.0.0
# with:
# apiToken: ${{ secrets.CF_API_TOKEN }}
# 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/wrangler-action@2.0.0
# 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.

16 changes: 8 additions & 8 deletions README.MD
@@ -1,14 +1,14 @@
# Hideyour.cash
# Opact Tickets

Hideyour.cash is a compliant anonymous transactions tool, that utilizes ZK (Zero-knowledge proof) technology.
Opact Tickets is a compliant anonymous transactions tool, that utilizes ZK (Zero-knowledge proof) technology.

The main feature is allowing the mixing of transactions using NEAR or any NEP-141 token only for well inteded users. The system integrates with data providors to block wallets suspicious of money laundering and smart contract hacking.

This works by leveaging [hapi.one protocol] as a data partner which is responsible for allowlisting and denylisting accounts.

## How mixing works

TBD
TBD

## Compliance scheme

Expand All @@ -31,12 +31,12 @@ This means that, even if a malicious user is fast enough to deposit the tokens t

### Installation

Hideyour.cash requires [Node.js], [yarn], [rust], [circom] and the rust wasm toolchain. It is recommended that you follow [near sdk tutorial] to install rust and wasm.
Opact Tickets requires [Node.js], [yarn], [rust], [circom] and the rust wasm toolchain. It is recommended that you follow [near sdk tutorial] to install rust and wasm.

After installing all the tools, you can run the command:

```sh
yarn
yarn
```
And install all the dependencies

Expand Down Expand Up @@ -103,6 +103,6 @@ production: `.github/workflows/vercel_deploy.yml`
[yarn]: <https://yarnpkg.com/>
[circom]: <https://docs.circom.io/getting-started/installation/>
[hapi.one protocol]: <https://hapi.one/>



1 change: 1 addition & 0 deletions package.json
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
6 changes: 3 additions & 3 deletions packages/contracts/README.md
@@ -1,4 +1,4 @@
# Hideyour.cash Smart Contracts
# Opact Tickets Smart Contracts

This suite of smart contracts implements a zk transaction mixer on NEAR protocol that is nativelly integrated into [hapi.one's anti money laundering software](https://hapi.one/).

Expand Down Expand Up @@ -34,7 +34,7 @@ This has implications for this contract when using a NEP-141 token.
Whenever a user tries to withdraw to an account that is not registered in the contract for the token, the transaction is going to be reverted so that the user does not lose their funds.
Relayers and front end apps should check registration and pay for storage in case the accounts are not registered.

However, if owner or relayer are not registered in the NEP-141 contract, the fees that are transferred to them on each withdraw are going to fail and the funds will be locked in the HYC contract forever. So make sure that owner and relayers are registered in the contract.
However, if owner or relayer are not registered in the NEP-141 contract, the fees that are transferred to them on each withdraw are going to fail and the funds will be locked in the HYC contract forever. So make sure that owner and relayers are registered in the contract.

## Contract ownership
The contract implements an ownership model, where a priviledged `owner` account has access to methods that regular users do not.
Expand All @@ -53,4 +53,4 @@ The system is designed around a single REGISTRY smart contract and multiple INST

The registry is responsible for the setup of all AML parameters and for keeeping track of all different currencies and amounts supported by the protocol.

Instace smart contracts are where funds are actually mixed. Each instance only accepts one token type and deposits and withdraws can only be made in a fixed amount. That ensures external observers cannot differentiate between withdraws, guaranteeing more anonymity to users.
Instace smart contracts are where funds are actually mixed. Each instance only accepts one token type and deposits and withdraws can only be made in a fixed amount. That ensures external observers cannot differentiate between withdraws, guaranteeing more anonymity to users.
4 changes: 2 additions & 2 deletions packages/contracts/instance/README.md
@@ -1,4 +1,4 @@
# Hideyour.cash Instance Smart Contract
# Opact Tickets Instance Smart Contract

Instance Smart contract is responsible for receiving deposits and issuing withdrawals. Each instance can only receive deposits of a single token type at a fixed amount.

Expand Down Expand Up @@ -130,4 +130,4 @@ Panics if proof and public params submitted are invalid, returns `true` otherwis
1. `toggle_kill_switch`

Can only be called by owner upon depositing 1 yoctoNEAR.
Toggles value of kill_switch. Default is false. When true, disallows all deposits.
Toggles value of kill_switch. Default is false. When true, disallows all deposits.
Binary file added packages/contracts/proxy_contract_release.wasm
Binary file not shown.
12 changes: 6 additions & 6 deletions packages/contracts/registry/README.md
@@ -1,12 +1,12 @@
# Hideyour.cash Registry Smart Contract
# Opact Tickets Registry Smart Contract

The smart contract implements a NEAR protocol compatible Registry to allow multiple different amounts and currencies to be used with hideyour.cash.
The smart contract implements a NEAR protocol compatible Registry to allow multiple different amounts and currencies to be used with Opact Tickets.

The goal is for end users to be able to:
1. Discover all token and amount options available in HYC;
2. Discover the correct addresses for every available currency and amount option within HYC;
3. Allow the seamless replacement of deprecated contracts for their updated versions without compromising users ability to withdraw deposited funds;
4. Allow relayers to check whether specific contracts should be trusted;
4. Allow relayers to check whether specific contracts should be trusted;

The ideal logic would be for this to be the single point of contact for every interaction with HYC. However, given NEAR protocol's asynchronous nature, it is not possible to implement a router or proxy as we would for a different blockchain, such as Ethereum.

Expand Down Expand Up @@ -63,7 +63,7 @@ Panics if currency or amount is not registered.
params:
- account_id: AccountId -> Address of the HYC contract that you're removing from the allowlist

This method removes one entry from the allowlist.
This method removes one entry from the allowlist.

### Allowlist methods

Expand Down Expand Up @@ -91,7 +91,7 @@ Returns a Vec with all supported currencies in HYC.
params:
- currency: Currency -> Currency for which you want to query all available contracts

Returns a HashMap mapping each available deposit amount in the currency to the corresponding HYC contract address
Returns a HashMap mapping each available deposit amount in the currency to the corresponding HYC contract address

3. `view_is_contract_allowed` -> `bool`
params:
Expand All @@ -112,4 +112,4 @@ returns last know allowlist merkle tree root in the cotnract. Necessary to build
params:
- account_id: AccountId -> account you want to checks

true if account is in allowlist, false otherwise
true if account is in allowlist, false otherwise
2 changes: 1 addition & 1 deletion packages/contracts/tests-rs/src/methods/token.rs
Expand Up @@ -75,7 +75,7 @@ pub async fn ft_balance_of(
}

pub async fn initialize_ft_contract(
worker: &Worker<impl DevNetwork>,
worker: &Worker<Sandbox>,
contract: &Contract,
owner: &Account,
) -> workspaces::result::CallExecutionDetails {
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/tests-ts/src/actions/contracts.ts
Expand Up @@ -15,7 +15,7 @@ export const registerUser = async ({
account_id: account.accountId,
},
gas: new BN("300000000000000"),
attachedDeposit: new BN("480000000000000000000"),
attachedDeposit: new BN("400000000000000000000"),
});
};

Expand Down
35 changes: 33 additions & 2 deletions packages/contracts/tests-ts/src/actions/registry.ts
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
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
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
@@ -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"

0 comments on commit 1fc4ae3

Please sign in to comment.