Skip to content

Commit

Permalink
Merge pull request #52 from ThalaLabs/thalasdk-monorepo
Browse files Browse the repository at this point in the history
create thala-sdk monorepo
  • Loading branch information
SamuelQZQ authored Apr 26, 2024
2 parents c912d92 + 97adea2 commit 294cebc
Show file tree
Hide file tree
Showing 53 changed files with 13,860 additions and 179 deletions.
2 changes: 1 addition & 1 deletion .changeset/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ We have a quick list of common questions to get you started engaging with this p

# How to upgrade the version

- Run `bun run changeset` and provide a description of your change.
- Run `npx changeset` and provide a description of your change.
- Commit the `.md` file generated by `changeset` along with your code changes, then create the PR.
- After your PR merged, Github Workflow will create a PR called "Version Packages" to update the version in `package.json` and the `CHANGELOG.md`.
- Once the "Version Packages" PR is merged, Github Workflow will publish a new version to NPM.
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://unpkg.com/@changesets/config@2.3.1/schema.json",
"$schema": "https://unpkg.com/@changesets/config@3.0.0/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
Expand Down
5 changes: 5 additions & 0 deletions .changeset/four-papayas-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@thalalabs/thalaswap-math": major
---

Update Readme & move some files
21 changes: 15 additions & 6 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,18 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: oven-sh/setup-bun@v1
- run: bun install
- run: bun run typecheck
- run: bun run build
- run: bun test
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
with:
version: 8

- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'

- run: pnpm i
- run: pnpm run all
env:
CI: true
19 changes: 13 additions & 6 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,23 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: oven-sh/setup-bun@v1
- uses: actions/setup-node@v3
- run: bun install
- run: bun run build
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
with:
version: 8

- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'

- run: pnpm i
- name: Create Release Pull Request or Publish
id: changesets
uses: changesets/action@v1
with:
publish: npm run release
publish: pnpm run release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
134 changes: 132 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,133 @@
node_modules
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist
.env

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

.DS_Store
.turbo
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

bun lint-staged
npx lint-staged
4 changes: 4 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# thala-sdk

- [@thalalabs/thalaswap-math](./packages/thalaswap-math/)
- [@thalalabs/router-sdk](./packages/thalaswap-router/)
Binary file removed bun.lockb
Binary file not shown.
69 changes: 23 additions & 46 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,56 +1,33 @@
{
"name": "@thalalabs/router-sdk",
"version": "2.1.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"sideEffects": false,
"name": "thala-sdk",
"version": "0.0.0",
"private": true,
"workspaces": [
"packages/*"
],
"main": "index.js",
"scripts": {
"typecheck": "bun run tsc --noEmit",
"build": "bun run tsup ./src/index.ts --dts",
"prepare": "husky",
"typecheck": "turbo typecheck",
"build": "turbo typecheck build",
"test": "turbo typecheck test",
"format": "prettier . --write",
"release": "bun run build && changeset publish",
"prepare": "husky install"
},
"files": [
"dist"
],
"repository": {
"type": "git",
"url": "git+https://github.com/ThalaLabs/thala-router.git"
},
"publishConfig": {
"access": "public"
},
"devDependencies": {
"@changesets/cli": "^2.26.2",
"@typescript-eslint/eslint-plugin": "^6.10.0",
"@typescript-eslint/parser": "^6.10.0",
"bun-plugin-dts": "^0.2.1",
"bun-types": "^1.0.7",
"eslint": "^8.53.0",
"husky": "^9.0.10",
"lint-staged": "^15.0.2",
"prettier": "3.2.5",
"tsup": "^8.0.2",
"typescript": "^5.2.2",
"@aptos-labs/ts-sdk": "^1.11.0",
"@thalalabs/surf": "^1.3.1",
"@types/lodash": "^4.17.0"
},
"license": "MIT",
"dependencies": {
"bignumber.js": "^9.1.2",
"lodash": "^4.17.21"
},
"peerDependencies": {
"@aptos-labs/ts-sdk": "^1.11.0",
"@thalalabs/surf": "^1.3.1"
"all": "turbo build typecheck test",
"release": "pnpm run all && changeset publish"
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
"eslint --fix",
"pnpm -r run eslint --fix",
"prettier --write"
],
"*.json": "prettier --write"
}
},
"devDependencies": {
"@changesets/cli": "^2.27.1",
"husky": "^9.0.11",
"lint-staged": "^15.2.2",
"prettier": "^3.2.5",
"turbo": "^1.13.3"
},
"license": "MIT"
}
7 changes: 7 additions & 0 deletions packages/thalaswap-math/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# thalaswap-math

## 1.0.0

### Major Changes

- 9a602ba: Create initial version
21 changes: 21 additions & 0 deletions packages/thalaswap-math/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Thala Labs

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
52 changes: 52 additions & 0 deletions packages/thalaswap-math/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# thalaswap-math

SDK to calculate swap amounts and pool price.

# install

```
$ npm i @thalalabs/thalaswap-math
```

# example

```typescript
import {
calcInGivenOutStable,
calcInGivenOutWeighted,
calcOutGivenInStable,
calcOutGivenInWeighted,
} from "@thalalabs/thalaswap-math";

// Calculate amount out given amount in:
// A stable pool with three tokens having balances of [100, 200, 300],
// The pool's amplification coefficient is 1.
// And the swap fee is 0.01.
// We use the second token as input and the third token as output.
// And the input token amount is 10.
console.log(calcOutGivenInStable(10, 1, 2, [100, 200, 300], 1, 0.01));

// Calculate amount in given amount out:
// A stable pool with three tokens having balances of [100, 200, 300],
// The pool's amplification coefficient is 1.
// And the swap fee is 0.01.
// We use the second token as input and the third token as output.
// And the output token amount is 10.
console.log(calcInGivenOutStable(10, 1, 2, [100, 200, 300], 1, 0.01));

// Calculate amount out given amount in:
// A weighted pool has a token whose balance is 100 and weight is 20,
// and the pool also has another token whose balance is 200 and weight is 30.
// The swap fee is 0.01.
// Use the first token as input and the second token as output.
// And the input token amount is 10.
console.log(calcOutGivenInWeighted(100, 20, 200, 30, 10, 0.01));

// Calculate amount out given amount out:
// A weighted pool has a token whose balance is 100 and weight is 20,
// and the pool also has another token whose balance is 200 and weight is 30.
// The swap fee is 0.01.
// Use the first token as input and the second token as output.
// And the output token amount is 10.
console.log(calcInGivenOutWeighted(100, 20, 200, 30, 10, 0.01));
```
Loading

0 comments on commit 294cebc

Please sign in to comment.