Skip to content

Commit

Permalink
Merge pull request #53 from invariant-labs/add-example-test
Browse files Browse the repository at this point in the history
Add example test
  • Loading branch information
none00y authored Jun 28, 2024
2 parents 0d99cfd + 4130150 commit b60f00c
Show file tree
Hide file tree
Showing 21 changed files with 780 additions and 385 deletions.
43 changes: 29 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,68 +17,83 @@ Invariant protocol is an AMM built on [Vara Network](https://vara.network), leve
- Configure Rust toolchain
- Install Gear node


#### Rust & Cargo

```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```

#### Install required packages

```bash
sudo apt install -y build-essential clang cmake curl
```

#### Configure Rust toolchain

```bash
rustup install nightly-2024-01-25
```
```bash
rustup target add wasm32-unknown-unknown --toolchain nightly-2024-01-25
rustup install 1.78
rustup target add wasm32-unknown-unknown --toolchain 1.78
```

#### Instal Gear node
```
curl https://get.gear.rs/gear-v1.3.0-x86_64-unknown-linux-gnu.tar.xz | tar Jx
#### Install wasm-opt

```bash
cargo install wasm-opt --locked
```

## Build protocol

in release mode

```bash
chmod +x build.sh
chmod +x ./build.sh
./build.sh
```

for tests

```bash
chmod +x build.sh
chmod +x ./build.sh
./build.sh dev
```

## Run tests

```bash
chmod +x tests.sh
chmod +x ./tests.sh
./tests.sh
```

## Running local node
run it in the desired location as dev

run it in the desired location as dev

```bash
path/to/node/gear --dev
```

or run it through CI in sdk folder

```bash
cargo xtask node
npm run node:local
```

## SDK

To build SDK go to the dedicated folder [SDK](https://github.com/invariant-labs/protocol-vara/tree/master/sdk)

- Build sdk

```bash
chmod +x build.sh
chmod +x ./build.sh
./build.sh
```

- Run sdk tests

```bash
chmod +x ./tests.sh
./tests.sh
```
```
16 changes: 15 additions & 1 deletion sdk/.npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
node_modules
src/wasm/*
src/**/*
tests/**/*
target/test-utils.*
!src/wasm/pkg
# build scripts
build.sh
fix-generate.js
tests.sh
package-wasm.sh
# config files
.eslintrc
.nvmrc
mocharc.json
tsconfig.json
# idls
contracts/**/*.idl
Binary file modified sdk/contracts/gear_erc20/gear_erc20.opt.wasm
Binary file not shown.
1 change: 0 additions & 1 deletion sdk/contracts/invariant/invariant.meta.txt

This file was deleted.

5 changes: 3 additions & 2 deletions sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"license": "ISC",
"repository": {
"type": "git",
"url": "https://github.com/invariant-labs/protocol-vara",
"url": "git+https://github.com/invariant-labs/protocol-vara.git",
"directory": "sdk"
},
"scripts": {
Expand All @@ -29,14 +29,15 @@
"node:local:stop": "pkill -9 gear",
"start": "npm run build && node --experimental-wasm-modules --trace-uncaught target/index.js",
"wasm:build": "cd ./src/wasm && wasm-pack build --features tsify/js && rm ./pkg/.gitignore",
"test:local": "npm run test:fungible-token && npm run test:deposits && npm run test:invariant && npm run test:protocol-fee && npm run test:position && npm run test:math && npm run test:events",
"test:local": "npm run test:fungible-token && npm run test:deposits && npm run test:invariant && npm run test:example && npm run test:protocol-fee && npm run test:position && npm run test:math && npm run test:events",
"test:fungible-token": "npx mocha --config mocharc.json ./tests/fungible-token.test.ts",
"test:invariant": "npx mocha --config mocharc.json ./tests/invariant.test.ts",
"test:protocol-fee": "npx mocha --config mocharc.json ./tests/protocol-fee.test.ts",
"test:deposits": "npx mocha --config mocharc.json ./tests/deposits.test.ts",
"test:position": "npx mocha --config mocharc.json ./tests/position.test.ts",
"test:events": "npx mocha --config mocharc.json ./tests/events.test.ts",
"test:math": "npx mocha --config mocharc.json ./tests/math.test.ts",
"test:example": "npx mocha --config mocharc.json ./tests/example.test.ts",
"contract:build": "cd ../ && ./build.sh dev-sdk",
"invariant:copy": "cp ../src/wasm/invariant.idl ./contracts/invariant/invariant.idl && cp ../target/wasm32-unknown-unknown/release/invariant_wasm.opt.wasm ./contracts/invariant/invariant.opt.wasm",
"erc-20:copy": "cp ../gear-erc20/wasm/erc20.idl ./contracts/gear_erc20/gear_erc20.idl && cp ../target/wasm32-unknown-unknown/release/gear_erc20_wasm.opt.wasm ./contracts/gear_erc20/gear_erc20.opt.wasm",
Expand Down
9 changes: 5 additions & 4 deletions sdk/src/consts.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
export const LOCAL = 'ws://127.0.0.1:9944'
export const TESTNET = 'wss://testnet.vara.network'
export const MAINNET = 'wss://rpc.vara.network'

export const enum Network {
Local = 'ws://127.0.0.1:9944',
Testnet = 'wss://testnet.vara.network',
Mainnet = 'wss://rpc.vara.network',
}
export const FUNGIBLE_TOKEN_GAS_LIMIT = 750_000_000_000n
export const INVARIANT_GAS_LIMIT = 750_000_000_000n
export const DEFAULT_ADDRESS = '5F3sa2TJAWMqDhXG6jhV4N8ko9SxwGy8TpaNS1repo5EYjQX'
Expand Down
Loading

0 comments on commit b60f00c

Please sign in to comment.