-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: migrate to vitest and merry in gardenfi/core #31
Changes from all commits
382a232
024fa9a
762b297
e3074f8
1e16aaa
b4b1704
8808b00
50f8873
8b2cbc2
abaedc9
c7635d2
00f6ebb
c0999c0
76ad719
f904d4f
c331fa7
7702292
5da4b3c
7e434b1
1f1ecec
55ce763
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,42 @@ | ||||||||||||||||||||||||||
name: Run Tests | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
on: | ||||||||||||||||||||||||||
push: | ||||||||||||||||||||||||||
branches: | ||||||||||||||||||||||||||
- main | ||||||||||||||||||||||||||
pull_request: | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
jobs: | ||||||||||||||||||||||||||
test: | ||||||||||||||||||||||||||
runs-on: ubuntu-latest | ||||||||||||||||||||||||||
steps: | ||||||||||||||||||||||||||
- uses: actions/checkout@v3 | ||||||||||||||||||||||||||
- uses: actions/setup-node@v4 | ||||||||||||||||||||||||||
with: | ||||||||||||||||||||||||||
node-version: 18 | ||||||||||||||||||||||||||
registry-url: https://registry.npmjs.org/ | ||||||||||||||||||||||||||
- name: Install merry | ||||||||||||||||||||||||||
run: curl https://get.merry.dev | bash | ||||||||||||||||||||||||||
- name: Start merry | ||||||||||||||||||||||||||
run: merry go --headless | ||||||||||||||||||||||||||
- name: install dependencies | ||||||||||||||||||||||||||
run: | | ||||||||||||||||||||||||||
corepack enable | ||||||||||||||||||||||||||
yarn set version 4.3.1 | ||||||||||||||||||||||||||
yarn install | ||||||||||||||||||||||||||
yarn run build | ||||||||||||||||||||||||||
Comment on lines
+22
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optimize dependency installation steps. Combining the installation steps into a single - - name: install dependencies
- run: |
- corepack enable
- yarn set version 4.3.1
- yarn install
- yarn run build
+ - name: Install and build dependencies
+ run: |
+ corepack enable && \
+ yarn set version 4.3.1 && \
+ yarn install && \
+ yarn run build Committable suggestion
Suggested change
|
||||||||||||||||||||||||||
- run: yarn run test | ||||||||||||||||||||||||||
build: | ||||||||||||||||||||||||||
runs-on: ubuntu-latest | ||||||||||||||||||||||||||
steps: | ||||||||||||||||||||||||||
- uses: actions/checkout@v3 | ||||||||||||||||||||||||||
- uses: actions/setup-node@v4 | ||||||||||||||||||||||||||
with: | ||||||||||||||||||||||||||
node-version: 18 | ||||||||||||||||||||||||||
registry-url: https://registry.npmjs.org/ | ||||||||||||||||||||||||||
- name: install dependencies | ||||||||||||||||||||||||||
run: | | ||||||||||||||||||||||||||
corepack enable | ||||||||||||||||||||||||||
yarn set version 4.3.1 | ||||||||||||||||||||||||||
yarn install | ||||||||||||||||||||||||||
- run: yarn run build |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,25 +3,29 @@ id: core | |||||
--- | ||||||
|
||||||
# Core | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Address markdown linting issue: Multiple top-level headings. The file contains multiple top-level headings, which is a markdown linting issue. - # Core
- # GardenJS
+ ## Core
+ ## GardenJS
|
||||||
# GardenJS | ||||||
|
||||||
The `GardenJS` class simplifies the creation of atomic swap orders and interactions with it. | ||||||
|
||||||
## Creating a `GardenJS` Instance | ||||||
|
||||||
```ts | ||||||
constructor(orderbook: IOrderbook, wallets: Partial<Wallets>) | ||||||
``` | ||||||
|
||||||
It accepts an `IOrderbook`, and an object with the keys as the `Chain` and the corresponding wallet for that chain. It can be created as follows: | ||||||
|
||||||
```ts | ||||||
import { | ||||||
BitcoinOTA, | ||||||
EVMWallet, | ||||||
BitcoinNetwork, | ||||||
BitcoinProvider, | ||||||
} from "@catalogfi/wallets"; | ||||||
import { Orderbook, Chains } from "@gardenfi/orderbook"; | ||||||
import { GardenJS } from "@gardenfi/core"; | ||||||
import { BrowserProvider } from "ethers"; | ||||||
import { | ||||||
BitcoinOTA, | ||||||
EVMWallet, | ||||||
BitcoinNetwork, | ||||||
BitcoinProvider, | ||||||
} from '@catalogfi/wallets'; | ||||||
import { Orderbook, Chains } from '@gardenfi/orderbook'; | ||||||
import { GardenJS } from '@gardenfi/core'; | ||||||
import { BrowserProvider } from 'ethers'; | ||||||
|
||||||
const bitcoinProvider = new BitcoinProvider(BitcoinNetwork.Testnet); | ||||||
const provider = new BrowserProvider(window.ethereum); | ||||||
|
@@ -31,19 +35,20 @@ const bitcoinWallet = new BitcoinOTA(bitcoinProvider, signer); | |||||
const ethereumWallet = new EVMWallet(signer); | ||||||
|
||||||
const orderbook = await Orderbook.init({ | ||||||
signer, | ||||||
opts: { | ||||||
domain: window.location.host | ||||||
} | ||||||
signer, | ||||||
opts: { | ||||||
domain: window.location.host, | ||||||
}, | ||||||
}); | ||||||
|
||||||
const garden = new GardenJS(orderbook, { | ||||||
"ethereum_sepolia": ethereumWallet, | ||||||
"bitcoin_testnet": bitcoinWallet | ||||||
ethereum_sepolia: ethereumWallet, | ||||||
bitcoin_testnet: bitcoinWallet, | ||||||
}); | ||||||
``` | ||||||
|
||||||
### Methods | ||||||
|
||||||
```ts | ||||||
subscribeOrders(address: string, callback: (orders: Orders) => void): void | ||||||
|
||||||
|
@@ -67,23 +72,28 @@ calculateReceiveAmt( | |||||
``` | ||||||
|
||||||
## Subscribe Orders | ||||||
|
||||||
```ts | ||||||
subscribeOrders(address: string, callback: (orders: Orders) => void): void | ||||||
``` | ||||||
|
||||||
The `subscribeOrders` method is a wrapper over `IOrderbook`'s `subscribeOrders`. This method allows you to listen to all order updates where you're the maker or the taker. | ||||||
|
||||||
### Parameters | ||||||
|
||||||
- `address`: The address whose orders you want to listen to | ||||||
- `callback`: a callback function that takes in `Orders` as a parameter. | ||||||
|
||||||
## Unsubscribe Orders | ||||||
|
||||||
```ts | ||||||
unsubscribeOrders(): void | ||||||
``` | ||||||
|
||||||
The `unsubscribeOrders` method stops listening to all orders on all accounts. | ||||||
|
||||||
## Swap | ||||||
|
||||||
```ts | ||||||
swap( | ||||||
from: Asset, | ||||||
|
@@ -97,37 +107,42 @@ swap( | |||||
The swap method is used to create atomic swap orders. The initiator addresses and receiver addresses are filled based on the wallets provided. For example, if your `fromAsset` is testnet Bitcoin then the address chosen as the initiator address is the testnet Bitcoin wallet. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add missing comma for clarity. There is a possible missing comma in the sentence. - For example, if your `fromAsset` is testnet Bitcoin then the address chosen as the initiator address is the testnet Bitcoin wallet.
+ For example, if your `fromAsset` is testnet Bitcoin, then the address chosen as the initiator address is the testnet Bitcoin wallet. Committable suggestion
Suggested change
ToolsLanguageTool
|
||||||
|
||||||
The secret is the message signed by an `IBitcoinWallet` and the signed message is `garden.js<nonce><EVM wallet's pub key>` where the nonce is the number of orders created plus one (without the angular brackets). | ||||||
|
||||||
```ts | ||||||
//after creating a GardenJS instance | ||||||
|
||||||
import { Assets } from '@gardenfi/orderbook'; | ||||||
|
||||||
const orderId = await garden.swap( | ||||||
Assets.bitcoin_testnet.BTC, | ||||||
Assets.ethereum_sepolia.WBTC, | ||||||
sendAmount, | ||||||
receiveAmount | ||||||
Assets.bitcoin_testnet.BTC, | ||||||
Assets.ethereum_sepolia.WBTC, | ||||||
sendAmount, | ||||||
receiveAmount | ||||||
); | ||||||
``` | ||||||
|
||||||
### Parameters | ||||||
|
||||||
- `from`: The asset that you want to swap from | ||||||
- `to`: The asset you want to receive | ||||||
- `amt`: The amount that you're sending. Note that this number must be in the lowest denomination of that asset. For example, if you're swapping 1 Bitcoin then the amount must be `100,000,000` SATS | ||||||
- `receiveAmount`: The amount of the to Asset that you want to receive. Like the send amount, this amount, too, should be in its lowest denomination. | ||||||
- `opts.btcInputAddress`: The address in which you want to receive your Bitcoin. | ||||||
|
||||||
### Returns | ||||||
|
||||||
The order id. | ||||||
|
||||||
### Get Swap | ||||||
|
||||||
```ts | ||||||
getSwap(order: Order): ISwapper | ||||||
``` | ||||||
|
||||||
The `getSwap` method provides a `Swapper` instance that allows you to initiate, redeem, or refund your order by using the `.next()` method. The `.next()` method makes the appropriate action based on the status of the order and the role of the person performing the action that is, initiator or redeemer. | ||||||
|
||||||
The `status` of an order is 3 digit number where: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hyphenate "3 digit number" for grammatical correctness. The phrase "3 digit number" should be hyphenated to "3-digit number" for grammatical correctness. - The `status` of an order is 3 digit number where:
+ The `status` of an order is a 3-digit number where: Committable suggestion
Suggested change
ToolsLanguageTool
|
||||||
|
||||||
- the first digit indicates the overall order status, found in `Order.status` | ||||||
- the second digit indicates the order status of the initiator atomic swap, found in `Order.initiatorAtomicSwap.swapStatus` | ||||||
- the third digit indicates the order status of the follower (redeemer) atomic swap, found in `Order.followerAtomicSwap.swapStatus`. | ||||||
|
@@ -144,16 +159,19 @@ The `parseStatus` function in `@gardenfi/orderbook` provides you the `status` of | |||||
When creating orders, the follower is the backend orderbook fillers. | ||||||
|
||||||
### Calculate Receive Amount | ||||||
|
||||||
```ts | ||||||
calculateReceiveAmt(from: Asset, to: Asset, sendAmt: number): Promise<number> | ||||||
``` | ||||||
|
||||||
Calculates the optimal amount of fee taken by the fillers in the orderbook which is *currently 3%*. | ||||||
Calculates the optimal amount of fee taken by the fillers in the orderbook which is _currently 3%_. Note that, this function accepts the `sendAmt` in it's lowest denomination. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add missing comma for clarity. There is a possible missing comma in the sentence. - Calculates the optimal amount of fee taken by the fillers in the orderbook which is _currently 3%_. Note that, this function accepts the `sendAmt` in it's lowest denomination.
+ Calculates the optimal amount of fee taken by the fillers in the orderbook, which is _currently 3%_. Note that, this function accepts the `sendAmt` in its lowest denomination. Committable suggestion
Suggested change
ToolsLanguageTool
|
||||||
|
||||||
### Parameters | ||||||
|
||||||
- `from`: The asset that you want to swap from | ||||||
- `to`: The asset that you want to swap to | ||||||
- `sendAmt`: The amount that you're sending in the lowest denomination of the asset that you're swapping from. | ||||||
|
||||||
### Returns | ||||||
|
||||||
The amount that you will receive in the lowest denomination of the asset that you're swapping. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import globals from 'globals'; | ||
import pluginJs from '@eslint/js'; | ||
import tseslint from 'typescript-eslint'; | ||
Comment on lines
+1
to
+3
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tip Codebase Verification Incompatibility of The
Please address the version incompatibility and verify the compatibility of the plugins. Analysis chainEnsure compatibility of ESLint plugins. Make sure that the plugins Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Verify compatibility of ESLint plugins.
# Test: List installed ESLint plugins and versions. Expect: Compatible versions.
npm list @eslint/js typescript-eslint
Length of output: 110 Script: #!/bin/bash
# Description: Extract versions of ESLint and relevant plugins from package.json
# Extract versions of @eslint/js, typescript-eslint, and eslint
jq '.dependencies["@eslint/js"], .dependencies["typescript-eslint"], .dependencies["eslint"], .devDependencies["@eslint/js"], .devDependencies["typescript-eslint"], .devDependencies["eslint"]' package.json
Length of output: 247 Script: #!/bin/bash
# Description: Search for the usage of @eslint/js in the codebase
# Search for @eslint/js in the codebase
rg '@eslint/js'
Length of output: 294 Script: #!/bin/bash
# Description: Verify compatibility of typescript-eslint with ESLint 9.x
# Check typescript-eslint version compatibility with ESLint 9.x
curl -s https://registry.npmjs.org/@typescript-eslint/eslint-plugin | jq '.versions["7.15.0"].peerDependencies'
Length of output: 180 Script: #!/bin/bash
# Description: Verify compatibility of @eslint/js with ESLint 9.x
# Check @eslint/js version compatibility with ESLint 9.x
curl -s https://registry.npmjs.org/@eslint/js | jq '.versions["9.6.0"].peerDependencies'
Length of output: 95 |
||
|
||
export default [ | ||
{ files: ['**/*.{js,mjs,cjs,ts}'] }, | ||
{ languageOptions: { globals: { ...globals.browser, ...globals.node } } }, | ||
pluginJs.configs.recommended, | ||
...tseslint.configs.recommended, | ||
{ | ||
rules: { | ||
'@typescript-eslint/no-explicit-any': 'off', | ||
}, | ||
}, | ||
{ | ||
ignores: ['**/dist/*', '**/build/*', 'scripts'], | ||
}, | ||
]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,12 +18,18 @@ | |
"docs" | ||
], | ||
"devDependencies": { | ||
"@eslint/js": "^9.6.0", | ||
"@types/chrome": "^0.0.268", | ||
"@types/node": "^20.11.30", | ||
"eslint": "9.x", | ||
"globals": "^15.8.0", | ||
"ts-node": "^10.9.2", | ||
"typescript": "^5.4.2", | ||
"typescript-eslint": "^7.15.0", | ||
"vite": "^5.1.6", | ||
"vite-plugin-dts": "^3.7.3", | ||
"vite-plugin-eslint": "^1.8.1", | ||
"vitest": "^1.6.0" | ||
} | ||
}, | ||
"packageManager": "[email protected]" | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tip
Codebase Verification
Ensure secure installation of external scripts.
Downloading and executing scripts from external sources can introduce security risks. Consider verifying the integrity of the script by adding checksum verification for the downloaded binary.
Analysis chain
Ensure secure installation of external scripts.
Downloading and executing scripts from external sources can introduce security risks. Consider verifying the integrity of the script.
Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 120
Script:
Length of output: 3023