Skip to content

Commit

Permalink
escrow tiping script and test
Browse files Browse the repository at this point in the history
  • Loading branch information
MSghais committed Jun 18, 2024
1 parent 93a6e61 commit be6db3e
Show file tree
Hide file tree
Showing 28 changed files with 6,284 additions and 0 deletions.
2 changes: 2 additions & 0 deletions prototype/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
27 changes: 27 additions & 0 deletions prototype/.env.exemple
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Starknet Dev account. Using Sepolia by default, change RPC Starknet provider on the utils to use Devnet.
DEV_PK="0xPrivateKeyPaymaster"
DEV_PUBLIC_KEY="0xPublicKeyPaymaster"
RPC_ENDPOINT="http://localhost:5050" # Sepolia starknet by default, change the provider on the starknet test utils to use the RPC Endpoint
NODE_ENV="development"


# Account SocialPay declared class hash in Sepolia
ACCOUNT_CLASS_HASH=0x06a2684722b20b66e140dbd6cf8b7fb3d7736a46af3efebb467dc5279608d6fe

# Bob account to use wehn SNIP-6 finish
AA_PUBKEY=0x3...de
AA_PRIVATE_KEY=0x1..99
NODE_ENV=development
IS_DEPLOY_CONTRACT=true


# To run Nostr relayer, not needed
POSTGRES_DB=mydatabase
POSTGRES_USER=myuser
POSTGRES_PASSWORD=mypassword
POSTGRES_HOST=db
POSTGRES_PORT=5432
DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}
NOSTR_RELAYER_WEBSOCKET=ws://localhost:3000

ESCROW_CLASS_HASH=0x3f70abaaeef59cc900b597d45a2c97c08abb5260c03327cce9e45d4c7a8ad0 # Sepolia
25 changes: 25 additions & 0 deletions prototype/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
/dist

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
.env

npm-debug.log*
yarn-debug.log*
yarn-error.log*
5 changes: 5 additions & 0 deletions prototype/.mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require": "ts-node/register",
"spec": "test/**/*.ts"
}

121 changes: 121 additions & 0 deletions prototype/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# Social pay repository with Relayer and tests

The Social pay provide Nostr user to send token easily via Starknet.

### Alice sends tokens to Bob

```mermaid
sequenceDiagram
actor Alice
actor Bob
participant SocialPay relay
participant Starknet Node
participant Alice Account
participant STRK Token
Alice->>SocialPay relay: @joyboy send 10 STRK to @bob
activate SocialPay relay
SocialPay relay->>Starknet Node: SocialPay transaction
Starknet Node->>Alice Account: SocialPay handler
Alice Account->>STRK Token: transfer
Starknet Node->>SocialPay relay: SocialPay transaction complete
SocialPay relay->>Bob: @bob you just recived 10 STRK from @alice
SocialPay relay->>Alice: @alice transfer of 10 STRK to @bob is complete
deactivate SocialPay relay
```

## Overview of the Flow end to end with the Test
The end to end script is localted in the [End to End test](./test/tip_end_to_end.test.ts) script.

- [x] Create Bob & Alice account on Nostr
- [x] Create Account/Contract for Alice & Bob on Starknet
- [x] Send Nostr event kind 1 with Bob
- [] Check request, format, type Cairo to send.
- [] Verify signature
- [] Send SocialPay request to the Bob contract to send and transfer ERC20

## Tasks

The script only work in Sepolia at this stage. Working to fix the devnet script to test it on local.

Done:
- [x] Create SocialAccount (Contract or A.A when SNIP-6 is fully implemented)
- [x] Utils for Nostr & Starknet to format, check, deploy and do call on Starknet
- [] Tiping: Start Mocha script

WIP:
- [] Format & Deserialize SocialPay Request to send to the contract
- [] Fix type of SocialPay request attributes
- [] Verify signature and call handle transfer balance
- [] Tiping: Mocha Flow end to end working with Starknet call

TODO:
- [] Script working on Devnet (Contract not Found issue mainly, even with using running devnet with -- --seed 0)

## How install and use it:

The script is working only on Sepolia.
Please setup your .env correctly as the example.
If you want to do it on Localnet, change the Provider in this file to use your RPC_ENDPOINT:

[Starknet utils](./utils//starknet.ts)

### Locally

Create and Setup your .env file, use .env.example as example

Install the packages
```bash
npm i
```

Run the test by Default in Sepolia
```bash
npm test
```


TLDR: When you have already push and deploy your contract for the first time, you can skip this process on the test.
You can comment on the script the function "createSocialAccount" or "createSocialContract" the deploy process and only use the contract already deployed


#### Devnet script need to be fix.
Run the Social relay in WIP
```bash
npm run relay:dev # with nodemon
npm run relay
```

Run a Starknet dev:
[Localdevnet](https://github.com/0xSpaceShard/starknet-devnet-rs?tab=readme-ov-file)


```bash
cargo run
```

### Docker

Work in progress

## Test the integration

Tests are script in Typescript. We use Chalk and Mocha.

The script run in default with Sepolia.
If you want to do it on Localnet, run your devnet and change the Provider in this file to use your RPC_ENDPOINT:
[Starknet utils](./utils//starknet.ts)


Run the integration test end to end
```bash
npm run test
```

Not needed to test the script, only if you want to send it on a Relayer.

Run the Social relay in WIP
```bash
npm run relay:dev # with nodemon
npm run relay
```
61 changes: 61 additions & 0 deletions prototype/constants/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
export const ACCOUNT_TEST_PROFILE = {
alice: {
name: "alice.xyz",
pubkey: "",
strkKey: "",
// nostrPk: "5b2b830f2778075ab3befb5a48c9d8138aef017fab2b26b5c31a2742a901afcc",
nostrPublicKey: "5b2b830f2778075ab3befb5a48c9d8138aef017fab2b26b5c31a2742a901afcc",
nostrPrivateKey: "59a772c0e643e4e2be5b8bac31b2ab5c5582b03a84444c81d6e2eec34a5e6c35",
// contract:"0x261d2434b2583293b7dd2048cb9c0984e262ed0a3eb70a19ed4eac6defef8b1",
contract:
"0x65d17b5c8fca3da3c45a4b7a97007331d51860e6843094fa98040b3962b741b",
},
bob: {
name: "joyboy.xyz",
pubkey: "",
strkKey: "",
/** FIRST TEST */
/*** Dummy data */
nostrPrivateKey: "70aca2a9ab722bd56a9a1aadae7f39bc747c7d6735a04d677e0bc5dbefa71d47",
nostrPublicKey: "d6f1cf53f9f52d876505164103b1e25811ec4226a17c7449576ea48b00578171",

contract:
"0x1b5f5bee60ce25d6979c5b88cfbb74ad1dae197dba11719b2e06a5efa7e666d",
},
escrow: {
contract: "0x53327953bddcb4ae216b14ea0b84261c6c1ad0af112a29be2dab11cf2e76c48",
SEPOLIA: "0x53327953bddcb4ae216b14ea0b84261c6c1ad0af112a29be2dab11cf2e76c48"
}
};
export const ERROR_MESSAGES = {
EVENT_NOTE_INVALID: {
label: "EVENT_NOTE_INVALID",
message: "The note event provided is invalid",
},
ADDRESS_INVALID: {
label: "ADDRESS_INVALID",
message: "The address of the receiver or sender are invalid",
},
PAY_REQUEST_NOT_FOUND: {
label: "PAY_REQUEST_NOT_FOUND",
message: "The pay request content on the event note is not correct",
},
};

export const TOKENS_ADDRESS = {
SEPOLIA: {
ETH: "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
// TEST: "0x00148a15f9fbf4c015b927bf88608fbafb6d149abdd5ef5b3e3b296e6ac999a4",

STRK: "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
USDC: "0x02f37c3e00e75ee4135b32bb60c37e0599af264076376a618f138d2f9929ac74",
TEST: "0x00148a15f9fbf4c015b927bf88608fbafb6d149abdd5ef5b3e3b296e6ac999a4",
BIG_TOKEN: "0x00148a15f9fbf4c015b927bf88608fbafb6d149abdd5ef5b3e3b296e6ac999a4",

},
DEVNET: {
ETH: "0x49D36570D4E46F48E99674BD3FCC84644DDD6B96F7C741B1562B82F9E004DC7",
TEST: "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
STRK: "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
},
};
33 changes: 33 additions & 0 deletions prototype/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: '3.3'

services:
devnet:
build:
context: .
dockerfile: ./localdevnet/Dockerfile
ports:
- "5050:5050"
environment:
- MY_ENV_VAR=some_value
db:
image: postgres:16
environment:
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
ports:
- "5432:5432"
volumes:
- db-data:/var/lib/postgresql/data
relayer:
build:
context: .
dockerfile: ./nostr/Dockerfile
ports:
- "3000:3000"
environment:
- DATABASE_URL=${DATABASE_URL}


volumes:
db-data:
14 changes: 14 additions & 0 deletions prototype/docker/localdevnet/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Use the official Rust image
FROM rust:latest

# Set the working directory
WORKDIR /usr/src/devnet

# Clone the GitHub repository
RUN git clone https://github.com/0xSpaceShard/starknet-devnet-rs.git .

# Build the Rust application
RUN cargo build --release

# Command to run the Rust application
CMD ["./target/release/starknet-devnet-rs"]
20 changes: 20 additions & 0 deletions prototype/docker/nostr/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use the official Node.js image
FROM node:18

# Set the working directory
WORKDIR /usr/src/relay

# Clone the GitHub repository
RUN git clone https://github.com/CodyTseng/nostr-relay-nestjs.git .

# Install the dependencies
RUN npm install

# Build the NestJS application
RUN npm run build

# Expose the application port
EXPOSE 3000

# Command to run the NestJS application
CMD ["npm", "run", "start"]
Loading

0 comments on commit be6db3e

Please sign in to comment.