From 39aa4bf12036c96556ae4e57fcd2054e02848132 Mon Sep 17 00:00:00 2001 From: 00xSam Date: Wed, 4 Dec 2024 20:19:23 +0800 Subject: [PATCH] fix: typescript --- .gitignore | 1 + ts-client/index.ts | 4 +- ts-client/package.json | 12 +- ts-client/pnpm-lock.yaml | 146 ++++++------------ ts-client/src/amm/curve/constant-product.ts | 5 +- ts-client/src/amm/curve/stable-swap.ts | 1 + ts-client/src/amm/index.ts | 18 ++- .../src/amm/tests/constantProduct.test.ts | 4 +- ts-client/src/amm/utils.ts | 2 +- .../create_pool_and_lock_liquidity.ts | 6 +- .../create_pool_with_authorized_config.ts | 2 +- ts-client/tsconfig.dev.json | 17 ++ ts-client/tsconfig.json | 9 +- 13 files changed, 101 insertions(+), 126 deletions(-) create mode 100644 ts-client/tsconfig.dev.json diff --git a/.gitignore b/.gitignore index 59239ca5..1f452e39 100644 --- a/.gitignore +++ b/.gitignore @@ -12,5 +12,6 @@ ts-client/dist/ ts-client/package-lock.json ts-client/.env +ts-client/.turbo/ commands \ No newline at end of file diff --git a/ts-client/index.ts b/ts-client/index.ts index f83ddae4..1d0edb64 100644 --- a/ts-client/index.ts +++ b/ts-client/index.ts @@ -1,4 +1,4 @@ -import { VaultIdl as Vault, IDL as VaultIdl } from '@mercurial-finance/vault-sdk'; +import { VaultIdl as Vault, IDL as VaultIdl } from '@meteora-ag/vault-sdk'; import AmmImpl from './src/amm'; import DynamicAmmError from './src/amm/error'; import { StableSwap, ConstantProductSwap } from './src/amm/curve'; @@ -64,5 +64,5 @@ export type { SwapQuoteParam, Bootstrapping, } from './src/amm/types'; -export type { VaultState } from '@mercurial-finance/vault-sdk'; +export type { VaultState } from '@meteora-ag/vault-sdk'; export type { Amm, Vault }; diff --git a/ts-client/package.json b/ts-client/package.json index 5b3350a7..1f94deff 100644 --- a/ts-client/package.json +++ b/ts-client/package.json @@ -5,7 +5,8 @@ "main": "dist/cjs/index.js", "module": "dist/esm/index.js", "scripts": { - "postclone": "pnpm rm @meteora-ag/vault-sdk @meteora-ag/config && pnpm install @meteora-ag/vault-sdk @meteora-ag/config", + "postclone": "pnpm rm @meteora-ag/vault-sdk @meteora-ag/config && pnpm i @meteora-ag/vault-sdk && pnpm i -D @meteora-ag/config", + "dev": "rm -rf dist && tsc -p tsconfig.dev.json --watch", "build": "rm -rf dist && tsc -p tsconfig.build.json && tsc -p tsconfig.esm.json", "test": "jest ./src/amm/tests/*.test.ts --runInBand" }, @@ -13,26 +14,24 @@ "dist" ], "dependencies": { - "@meteora-ag/config": "workspace:*", - "@meteora-ag/vault-sdk": "workspace:*", - "@coral-xyz/borsh": "^0.28.0", "@mercurial-finance/token-math": "6.0.0", "@metaplex-foundation/mpl-token-metadata": "~2.13.0", "@meteora-ag/stake-for-fee": "1.0.28", + "@meteora-ag/vault-sdk": "workspace:*", "@solana/buffer-layout": "^4.0.1", "bn-sqrt": "^1.0.0", "dotenv": "^16.0.1", "invariant": "^2.2.4" }, "devDependencies": { - "@tsconfig/recommended": "^1.0.1", + "@meteora-ag/config": "workspace:*", "@types/bn.js": "^5.1.6", "@types/chai": "^4.3.1", "@types/invariant": "^2.2.35", "@types/jest": "^27.5.1", "@types/mocha": "^9.1.1", + "@types/node": "^22.10.1", "chai": "^4.3.6", - "concurrently": "^9.1.0", "jest": "^28.1.0", "mocha": "^10.0.0", "ts-jest": "^28.0.2", @@ -41,6 +40,7 @@ }, "peerDependencies": { "@coral-xyz/anchor": "^0.28.0", + "@coral-xyz/borsh": "^0.28.0", "@solana/buffer-layout": "^4.0.1", "@solana/spl-token": "^0.4.9", "@solana/web3.js": "^1.95.5", diff --git a/ts-client/pnpm-lock.yaml b/ts-client/pnpm-lock.yaml index abb41cfa..531e36ad 100644 --- a/ts-client/pnpm-lock.yaml +++ b/ts-client/pnpm-lock.yaml @@ -20,9 +20,6 @@ importers: '@metaplex-foundation/mpl-token-metadata': specifier: ~2.13.0 version: 2.13.0(bufferutil@4.0.7)(fastestsmallesttextencoderdecoder@1.0.22)(utf-8-validate@5.0.10) - '@meteora-ag/config': - specifier: workspace:* - version: link:../../config '@meteora-ag/stake-for-fee': specifier: 1.0.28 version: 1.0.28(bufferutil@4.0.7)(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.5.4)(utf-8-validate@5.0.10) @@ -54,9 +51,9 @@ importers: specifier: ^2.2.4 version: 2.2.4 devDependencies: - '@tsconfig/recommended': - specifier: ^1.0.1 - version: 1.0.2 + '@meteora-ag/config': + specifier: workspace:* + version: link:../../config '@types/bn.js': specifier: ^5.1.6 version: 5.1.6 @@ -72,21 +69,21 @@ importers: '@types/mocha': specifier: ^9.1.1 version: 9.1.1 + '@types/node': + specifier: ^22.10.1 + version: 22.10.1 chai: specifier: ^4.3.6 version: 4.3.7 - concurrently: - specifier: ^9.1.0 - version: 9.1.0 jest: specifier: ^28.1.0 - version: 28.1.3(@types/node@18.15.11) + version: 28.1.3(@types/node@22.10.1) mocha: specifier: ^10.0.0 version: 10.2.0 ts-jest: specifier: ^28.0.2 - version: 28.0.8(@babel/core@7.21.4)(@jest/types@28.1.3)(babel-jest@28.1.3(@babel/core@7.21.4))(jest@28.1.3(@types/node@18.15.11))(typescript@5.5.4) + version: 28.0.8(@babel/core@7.21.4)(@jest/types@28.1.3)(babel-jest@28.1.3(@babel/core@7.21.4))(jest@28.1.3(@types/node@22.10.1))(typescript@5.5.4) ts-mocha: specifier: ^10.0.0 version: 10.0.0(mocha@10.2.0) @@ -520,9 +517,6 @@ packages: '@swc/helpers@0.5.12': resolution: {integrity: sha512-KMZNXiGibsW9kvZAO1Pam2JPTDBm+KSHMMHWdsyI/1DbIZjT2A6Gy3hblVXUMEDvUAKq+e0vL0X0o54owWji7g==} - '@tsconfig/recommended@1.0.2': - resolution: {integrity: sha512-dbHBtbWBOjq0/otpopAE02NT2Cm05Qe2JsEKeCf/wjSYbI2hz8nCqnpnOJWHATgjDz4fd3dchs3Wy1gQGjfN6w==} - '@types/babel__core@7.20.0': resolution: {integrity: sha512-+n8dL/9GWblDO0iU6eZAwEIJVr5DWigtle+Q6HLOrh/pdbXOhOtqzq8VPPE2zvNJzSKY4vH/z3iT3tn0A3ypiQ==} @@ -574,8 +568,8 @@ packages: '@types/node@12.20.55': resolution: {integrity: sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==} - '@types/node@18.15.11': - resolution: {integrity: sha512-E5Kwq2n4SbMzQOn6wnmBjuK9ouqlURrcZDVfbo9ftDDTFt3nk7ZKK4GMOzoYgnpQJKcxwQw+lGaBvvlMo0qN/Q==} + '@types/node@22.10.1': + resolution: {integrity: sha512-qKgsUwfHZV2WCWLAnVP1JqnpE6Im6h3Y0+fYgMTasNQ7V++CBX5OT1as0g0f+OyubbFqhf6XVNIsmN4IIhEgGQ==} '@types/prettier@2.7.2': resolution: {integrity: sha512-KufADq8uQqo1pYKVIYzfKbJfBAc0sOeXqGbFaSpv8MRmC/zXgowNZmFcbngndGk922QDmOASEXUZCaY48gs4cg==} @@ -855,11 +849,6 @@ packages: concat-map@0.0.1: resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==} - concurrently@9.1.0: - resolution: {integrity: sha512-VxkzwMAn4LP7WyMnJNbHN5mKV9L2IbyDjpzemKr99sXNR3GqRNMMHdm7prV1ws9wg7ETj6WUkNOigZVsptwbgg==} - engines: {node: '>=18'} - hasBin: true - convert-source-map@1.9.0: resolution: {integrity: sha512-ASFBup0Mz1uyiIjANan1jzLQami9z1PoYSZCiiYW2FczPbenXc45FZdBZLzOT+r6+iciuEModtmCti+hjaAk0A==} @@ -1463,9 +1452,6 @@ packages: lodash.memoize@4.1.2: resolution: {integrity: sha512-t7j+NzmgnQzTAYXcsHYLgimltOV1MXHtlOWf6GjL9Kj8GK5FInw5JotxvbOs+IvV1/Dzo04/fCGfLVs7aXb4Ag==} - lodash@4.17.21: - resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==} - log-symbols@4.1.0: resolution: {integrity: sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==} engines: {node: '>=10'} @@ -1718,9 +1704,6 @@ packages: rpc-websockets@9.0.2: resolution: {integrity: sha512-YzggvfItxMY3Lwuax5rC18inhbjJv9Py7JXRHxTIi94JOLrqBsSsUUc5bbl5W6c11tXhdfpDPK0KzBhoGe8jjw==} - rxjs@7.8.1: - resolution: {integrity: sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg==} - safe-buffer@5.2.1: resolution: {integrity: sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==} @@ -1748,10 +1731,6 @@ packages: resolution: {integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==} engines: {node: '>=8'} - shell-quote@1.8.2: - resolution: {integrity: sha512-AzqKpGKjrj7EM6rKVQEPpB288oCfnrEIuyoT9cyF4nmGa7V8Zk6f7RRqYisX8X9m+Q7bd632aZW4ky7EhbQztA==} - engines: {node: '>= 0.4'} - signal-exit@3.0.7: resolution: {integrity: sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==} @@ -1871,10 +1850,6 @@ packages: tr46@0.0.3: resolution: {integrity: sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==} - tree-kill@1.2.2: - resolution: {integrity: sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==} - hasBin: true - ts-jest@28.0.8: resolution: {integrity: sha512-5FaG0lXmRPzApix8oFG8RKjAz4ehtm8yMKOTy5HX3fY6W8kmvOrmcY0hKDElW52FJov+clhUbrKAqofnj4mXTg==} engines: {node: ^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0} @@ -1930,6 +1905,9 @@ packages: engines: {node: '>=14.17'} hasBin: true + undici-types@6.20.0: + resolution: {integrity: sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==} + update-browserslist-db@1.0.10: resolution: {integrity: sha512-OztqDenkfFkbSG+tRxBeAnCVPckDBcvibKd35yDONx6OU8N7sqgwc7rCbkJ/WcYtVRZ4ba68d6byhC21GFh7sQ==} hasBin: true @@ -2037,10 +2015,6 @@ packages: resolution: {integrity: sha512-cwiTb08Xuv5fqF4AovYacTFNxk62th7LKJ6BL9IGUpTJrWoU7/7WdQGTP2SjKf1dUNBGzDd28p/Yfs/GI6JrLw==} engines: {node: '>=12'} - yargs@17.7.2: - resolution: {integrity: sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==} - engines: {node: '>=12'} - yn@2.0.0: resolution: {integrity: sha512-uTv8J/wiWTgUTg+9vLTi//leUl5vDQS6uii/emeTb2ssY7vl6QWf2fFbIIGjnhjvbdKlU0ed7QPgY1htTC86jQ==} engines: {node: '>=4'} @@ -2305,7 +2279,7 @@ snapshots: '@jest/console@28.1.3': dependencies: '@jest/types': 28.1.3 - '@types/node': 18.15.11 + '@types/node': 22.10.1 chalk: 4.1.2 jest-message-util: 28.1.3 jest-util: 28.1.3 @@ -2318,14 +2292,14 @@ snapshots: '@jest/test-result': 28.1.3 '@jest/transform': 28.1.3 '@jest/types': 28.1.3 - '@types/node': 18.15.11 + '@types/node': 22.10.1 ansi-escapes: 4.3.2 chalk: 4.1.2 ci-info: 3.8.0 exit: 0.1.2 graceful-fs: 4.2.11 jest-changed-files: 28.1.3 - jest-config: 28.1.3(@types/node@18.15.11) + jest-config: 28.1.3(@types/node@22.10.1) jest-haste-map: 28.1.3 jest-message-util: 28.1.3 jest-regex-util: 28.0.2 @@ -2350,7 +2324,7 @@ snapshots: dependencies: '@jest/fake-timers': 28.1.3 '@jest/types': 28.1.3 - '@types/node': 18.15.11 + '@types/node': 22.10.1 jest-mock: 28.1.3 '@jest/expect-utils@28.1.3': @@ -2368,7 +2342,7 @@ snapshots: dependencies: '@jest/types': 28.1.3 '@sinonjs/fake-timers': 9.1.2 - '@types/node': 18.15.11 + '@types/node': 22.10.1 jest-message-util: 28.1.3 jest-mock: 28.1.3 jest-util: 28.1.3 @@ -2389,7 +2363,7 @@ snapshots: '@jest/transform': 28.1.3 '@jest/types': 28.1.3 '@jridgewell/trace-mapping': 0.3.18 - '@types/node': 18.15.11 + '@types/node': 22.10.1 chalk: 4.1.2 collect-v8-coverage: 1.0.1 exit: 0.1.2 @@ -2460,7 +2434,7 @@ snapshots: '@jest/schemas': 28.1.3 '@types/istanbul-lib-coverage': 2.0.4 '@types/istanbul-reports': 3.0.1 - '@types/node': 18.15.11 + '@types/node': 22.10.1 '@types/yargs': 17.0.24 chalk: 4.1.2 @@ -2753,8 +2727,6 @@ snapshots: dependencies: tslib: 2.6.3 - '@tsconfig/recommended@1.0.2': {} - '@types/babel__core@7.20.0': dependencies: '@babel/parser': 7.21.4 @@ -2780,17 +2752,17 @@ snapshots: '@types/bn.js@5.1.6': dependencies: - '@types/node': 18.15.11 + '@types/node': 22.10.1 '@types/chai@4.3.4': {} '@types/connect@3.4.35': dependencies: - '@types/node': 18.15.11 + '@types/node': 22.10.1 '@types/graceful-fs@4.1.6': dependencies: - '@types/node': 18.15.11 + '@types/node': 22.10.1 '@types/invariant@2.2.35': {} @@ -2816,7 +2788,9 @@ snapshots: '@types/node@12.20.55': {} - '@types/node@18.15.11': {} + '@types/node@22.10.1': + dependencies: + undici-types: 6.20.0 '@types/prettier@2.7.2': {} @@ -2826,11 +2800,11 @@ snapshots: '@types/ws@7.4.7': dependencies: - '@types/node': 18.15.11 + '@types/node': 22.10.1 '@types/ws@8.5.12': dependencies: - '@types/node': 18.15.11 + '@types/node': 22.10.1 '@types/yargs-parser@21.0.0': {} @@ -3127,16 +3101,6 @@ snapshots: concat-map@0.0.1: {} - concurrently@9.1.0: - dependencies: - chalk: 4.1.2 - lodash: 4.17.21 - rxjs: 7.8.1 - shell-quote: 1.8.2 - supports-color: 8.1.1 - tree-kill: 1.2.2 - yargs: 17.7.2 - convert-source-map@1.9.0: {} cross-fetch@3.1.5: @@ -3519,7 +3483,7 @@ snapshots: '@jest/expect': 28.1.3 '@jest/test-result': 28.1.3 '@jest/types': 28.1.3 - '@types/node': 18.15.11 + '@types/node': 22.10.1 chalk: 4.1.2 co: 4.6.0 dedent: 0.7.0 @@ -3537,7 +3501,7 @@ snapshots: transitivePeerDependencies: - supports-color - jest-cli@28.1.3(@types/node@18.15.11): + jest-cli@28.1.3(@types/node@22.10.1): dependencies: '@jest/core': 28.1.3 '@jest/test-result': 28.1.3 @@ -3546,7 +3510,7 @@ snapshots: exit: 0.1.2 graceful-fs: 4.2.11 import-local: 3.1.0 - jest-config: 28.1.3(@types/node@18.15.11) + jest-config: 28.1.3(@types/node@22.10.1) jest-util: 28.1.3 jest-validate: 28.1.3 prompts: 2.4.2 @@ -3556,7 +3520,7 @@ snapshots: - supports-color - ts-node - jest-config@28.1.3(@types/node@18.15.11): + jest-config@28.1.3(@types/node@22.10.1): dependencies: '@babel/core': 7.21.4 '@jest/test-sequencer': 28.1.3 @@ -3581,7 +3545,7 @@ snapshots: slash: 3.0.0 strip-json-comments: 3.1.1 optionalDependencies: - '@types/node': 18.15.11 + '@types/node': 22.10.1 transitivePeerDependencies: - supports-color @@ -3616,7 +3580,7 @@ snapshots: '@jest/environment': 28.1.3 '@jest/fake-timers': 28.1.3 '@jest/types': 28.1.3 - '@types/node': 18.15.11 + '@types/node': 22.10.1 jest-mock: 28.1.3 jest-util: 28.1.3 @@ -3628,7 +3592,7 @@ snapshots: dependencies: '@jest/types': 28.1.3 '@types/graceful-fs': 4.1.6 - '@types/node': 18.15.11 + '@types/node': 22.10.1 anymatch: 3.1.3 fb-watchman: 2.0.2 graceful-fs: 4.2.11 @@ -3674,7 +3638,7 @@ snapshots: jest-mock@28.1.3: dependencies: '@jest/types': 28.1.3 - '@types/node': 18.15.11 + '@types/node': 22.10.1 jest-pnp-resolver@1.2.3(jest-resolve@28.1.3): optionalDependencies: @@ -3708,7 +3672,7 @@ snapshots: '@jest/test-result': 28.1.3 '@jest/transform': 28.1.3 '@jest/types': 28.1.3 - '@types/node': 18.15.11 + '@types/node': 22.10.1 chalk: 4.1.2 emittery: 0.10.2 graceful-fs: 4.2.11 @@ -3785,7 +3749,7 @@ snapshots: jest-util@28.1.3: dependencies: '@jest/types': 28.1.3 - '@types/node': 18.15.11 + '@types/node': 22.10.1 chalk: 4.1.2 ci-info: 3.8.0 graceful-fs: 4.2.11 @@ -3804,7 +3768,7 @@ snapshots: dependencies: '@jest/test-result': 28.1.3 '@jest/types': 28.1.3 - '@types/node': 18.15.11 + '@types/node': 22.10.1 ansi-escapes: 4.3.2 chalk: 4.1.2 emittery: 0.10.2 @@ -3813,16 +3777,16 @@ snapshots: jest-worker@28.1.3: dependencies: - '@types/node': 18.15.11 + '@types/node': 22.10.1 merge-stream: 2.0.0 supports-color: 8.1.1 - jest@28.1.3(@types/node@18.15.11): + jest@28.1.3(@types/node@22.10.1): dependencies: '@jest/core': 28.1.3 '@jest/types': 28.1.3 import-local: 3.1.0 - jest-cli: 28.1.3(@types/node@18.15.11) + jest-cli: 28.1.3(@types/node@22.10.1) transitivePeerDependencies: - '@types/node' - supports-color @@ -3872,8 +3836,6 @@ snapshots: lodash.memoize@4.1.2: {} - lodash@4.17.21: {} - log-symbols@4.1.0: dependencies: chalk: 4.1.2 @@ -4126,10 +4088,6 @@ snapshots: bufferutil: 4.0.7 utf-8-validate: 5.0.10 - rxjs@7.8.1: - dependencies: - tslib: 2.6.3 - safe-buffer@5.2.1: {} semver@6.3.0: {} @@ -4157,8 +4115,6 @@ snapshots: shebang-regex@3.0.0: {} - shell-quote@1.8.2: {} - signal-exit@3.0.7: {} sisteransi@1.0.5: {} @@ -4264,13 +4220,11 @@ snapshots: tr46@0.0.3: {} - tree-kill@1.2.2: {} - - ts-jest@28.0.8(@babel/core@7.21.4)(@jest/types@28.1.3)(babel-jest@28.1.3(@babel/core@7.21.4))(jest@28.1.3(@types/node@18.15.11))(typescript@5.5.4): + ts-jest@28.0.8(@babel/core@7.21.4)(@jest/types@28.1.3)(babel-jest@28.1.3(@babel/core@7.21.4))(jest@28.1.3(@types/node@22.10.1))(typescript@5.5.4): dependencies: bs-logger: 0.2.6 fast-json-stable-stringify: 2.1.0 - jest: 28.1.3(@types/node@18.15.11) + jest: 28.1.3(@types/node@22.10.1) jest-util: 28.1.3 json5: 2.2.3 lodash.memoize: 4.1.2 @@ -4319,6 +4273,8 @@ snapshots: typescript@5.5.4: {} + undici-types@6.20.0: {} + update-browserslist-db@1.0.10(browserslist@4.21.5): dependencies: browserslist: 4.21.5 @@ -4431,16 +4387,6 @@ snapshots: y18n: 5.0.8 yargs-parser: 21.1.1 - yargs@17.7.2: - dependencies: - cliui: 8.0.1 - escalade: 3.1.1 - get-caller-file: 2.0.5 - require-directory: 2.1.1 - string-width: 4.2.3 - y18n: 5.0.8 - yargs-parser: 21.1.1 - yn@2.0.0: {} yocto-queue@0.1.0: {} diff --git a/ts-client/src/amm/curve/constant-product.ts b/ts-client/src/amm/curve/constant-product.ts index a51fa4bd..747950ef 100644 --- a/ts-client/src/amm/curve/constant-product.ts +++ b/ts-client/src/amm/curve/constant-product.ts @@ -27,7 +27,7 @@ function ceilDiv(lhs: BN, rhs: BN) { } export class ConstantProductSwap implements SwapCurve { - constructor() { } + constructor() {} private computeOutAmountWithoutSlippage(sourceAmount: BN, swapSourceAmount: BN, swapDestinationAmount: BN): BN { return sourceAmount.mul(swapDestinationAmount).div(swapSourceAmount); @@ -42,6 +42,7 @@ export class ConstantProductSwap implements SwapCurve { ): OutResult { let invariant = swapSourceAmount.mul(swapDestinationAmount); let [newSwapDestinationAmount, _newSwapSourceAmount] = ceilDiv(invariant, swapSourceAmount.add(sourceAmount)); + if (!newSwapDestinationAmount) throw new Error('Invalid newSwapDestinationAmount'); let destinationAmountSwapped = swapDestinationAmount.sub(newSwapDestinationAmount); if (destinationAmountSwapped.eq(new BN(0))) { throw new Error('Swap result in zero'); @@ -68,7 +69,7 @@ export class ConstantProductSwap implements SwapCurve { ): BN { let invariant = swapSourceAmount.mul(swapDestinationAmount); let [newSwapSourceAmount, _newSwapDestinationAmount] = ceilDiv(invariant, swapDestinationAmount.sub(destAmount)); - let sourceAmount = newSwapSourceAmount.sub(swapSourceAmount); + let sourceAmount = newSwapSourceAmount?.sub(swapSourceAmount) ?? new BN(0); if (sourceAmount.eq(new BN(0))) { throw new Error('Swap result in zero'); diff --git a/ts-client/src/amm/curve/stable-swap.ts b/ts-client/src/amm/curve/stable-swap.ts index 2e5eeba7..02ffc1c4 100644 --- a/ts-client/src/amm/curve/stable-swap.ts +++ b/ts-client/src/amm/curve/stable-swap.ts @@ -424,6 +424,7 @@ function calculateEstimatedMintAmount( const newBalances = [reserveA + depositAmountA, reserveB + depositAmountB] as const; const adjustedBalances = newBalances.map((newBalance, i) => { const oldBalance = oldBalances[i]; + if (!oldBalance) throw new Error('Old balance not found'); const idealBalance = new Fraction(d1, d0).multiply(oldBalance); const difference = idealBalance.subtract(newBalance); const diffAbs = difference.greaterThan(0) ? difference : difference.multiply(-1); diff --git a/ts-client/src/amm/index.ts b/ts-client/src/amm/index.ts index c5d00946..cbefd44d 100644 --- a/ts-client/src/amm/index.ts +++ b/ts-client/src/amm/index.ts @@ -120,8 +120,8 @@ const getFeeVaultState = async (publicKey: PublicKey, program: StakeForFeeProgra return feeVaultState; }; -type DecoderType = { [x: string]: (accountData: Buffer) => BN }; -const decodeAccountTypeMapper = (type: AccountType): ((accountData: Buffer) => BN) => { +type DecoderType = { [x: string]: ((accountData: Buffer) => BN) | undefined }; +const decodeAccountTypeMapper = (type: AccountType): ((accountData: Buffer) => BN) | undefined => { const decoder: DecoderType = { [AccountType.VAULT_A_RESERVE]: (accountData) => new BN(AccountLayout.decode(accountData).amount.toString()), [AccountType.VAULT_B_RESERVE]: (accountData) => new BN(AccountLayout.decode(accountData).amount.toString()), @@ -162,7 +162,7 @@ const deserializeAccountsBuffer = (accountInfoMap: Map) return Array.from(accountInfoMap).reduce((accValue, [publicKey, { type, account }]) => { const decodedAccountInfo = decodeAccountTypeMapper(type); - accValue.set(publicKey, decodedAccountInfo(account!.data)); + accValue.set(publicKey, decodedAccountInfo?.(account!.data)); return accValue; }, new Map()); @@ -271,6 +271,7 @@ export default class AmmImpl implements AmmImplementation { public async partnerClaimFees(partnerAddress: PublicKey, maxAmountA: BN, maxAmountB: BN) { let preInstructions: Array = []; + // @ts-ignore const [[partnerTokenA, createPartnerTokenAIx], [partnerTokenB, createPartnerTokenBIx]] = await this.createATAPreInstructions(partnerAddress, [this.poolState.tokenAMint, this.poolState.tokenBMint]); @@ -1381,6 +1382,8 @@ export default class AmmImpl implements AmmImplementation { const PdaInfos = poolList.reduce>((accList, _, index) => { const poolState = poolsState[index]; + if (!poolState) throw new Error('Pool not found'); + return [...accList, poolState.aVault, poolState.bVault]; }, []); const vaultsImpl = await VaultImpl.createMultipleWithPda(connection, PdaInfos); @@ -1389,6 +1392,8 @@ export default class AmmImpl implements AmmImplementation { poolsState.map(async (poolState, index) => { const pool = poolList[index]; + if (!pool) throw new Error('Pool not found'); + const vaultA = vaultsImpl.find(({ vaultPda }) => vaultPda.equals(poolState.aVault)); const vaultB = vaultsImpl.find(({ vaultPda }) => vaultPda.equals(poolState.bVault)); @@ -1431,6 +1436,11 @@ export default class AmmImpl implements AmmImplementation { const ammImpls: AmmImpl[] = await Promise.all( accountsToFetch.map(async (accounts) => { const [tokenAVault, tokenBVault, vaultALp, vaultBLp, poolVaultA, poolVaultB, poolLpMint] = accounts; // must follow order + invariant( + !!poolVaultA && !!poolVaultB && !!vaultALp && !!vaultBLp && !!tokenAVault && !!tokenBVault && !!poolLpMint, + 'Account not found', + ); + const poolVaultALp = accountsInfoMap.get(poolVaultA.pubkey.toBase58()) as BN; const poolVaultBLp = accountsInfoMap.get(poolVaultB.pubkey.toBase58()) as BN; const vaultALpSupply = accountsInfoMap.get(vaultALp.pubkey.toBase58()) as BN; @@ -1636,6 +1646,8 @@ export default class AmmImpl implements AmmImplementation { seedBaseKey: opt?.vaultSeedBaseKey, }); + if (!vaultA || !vaultB) throw new Error('Vaults not found'); + const accountsBufferMap = await getAccountsBuffer(connection, [ { pubkey: vaultA.vaultState.tokenVault, type: AccountType.VAULT_A_RESERVE }, { pubkey: vaultB.vaultState.tokenVault, type: AccountType.VAULT_B_RESERVE }, diff --git a/ts-client/src/amm/tests/constantProduct.test.ts b/ts-client/src/amm/tests/constantProduct.test.ts index d06eb6da..8e0ad75b 100644 --- a/ts-client/src/amm/tests/constantProduct.test.ts +++ b/ts-client/src/amm/tests/constantProduct.test.ts @@ -295,7 +295,7 @@ describe('Constant product pool', () => { USDC, btcDepositAmount, usdcDepositAmount, - configs[0].publicKey, + configs[0]!.publicKey, ); for (const transaction of transactions) { @@ -304,7 +304,7 @@ describe('Constant product pool', () => { await connection.confirmTransaction(txHash, 'finalized'); } - const poolKey = derivePoolAddressWithConfig(BTC, USDC, configs[0].publicKey, new PublicKey(PROGRAM_ID)); + const poolKey = derivePoolAddressWithConfig(BTC, USDC, configs[0]!.publicKey, new PublicKey(PROGRAM_ID)); cpPoolConfig = await AmmImpl.create(connection, poolKey); expect(poolKey.toBase58()).toBe(cpPoolConfig.address.toBase58()); diff --git a/ts-client/src/amm/utils.ts b/ts-client/src/amm/utils.ts index ad6a49df..7e70ea83 100644 --- a/ts-client/src/amm/utils.ts +++ b/ts-client/src/amm/utils.ts @@ -122,7 +122,7 @@ export const getOrCreateATAInstruction = async ( owner: PublicKey, connection: Connection, payer?: PublicKey, -): Promise<[PublicKey, TransactionInstruction?]> => { +): Promise<[PublicKey, TransactionInstruction | undefined]> => { let toAccount; try { toAccount = await getAssociatedTokenAccount(tokenMint, owner); diff --git a/ts-client/src/examples/create_pool_and_lock_liquidity.ts b/ts-client/src/examples/create_pool_and_lock_liquidity.ts index 57cf43dd..514c5f37 100644 --- a/ts-client/src/examples/create_pool_and_lock_liquidity.ts +++ b/ts-client/src/examples/create_pool_and_lock_liquidity.ts @@ -43,16 +43,16 @@ function fromAllocationsToAmount(lpAmount: BN, allocations: AllocationByPercenta let amounts: AllocationByAmount[] = []; let sum = new BN(0); for (let i = 0; i < allocations.length - 1; i++) { - const amount = lpAmount.mul(new BN(allocations[i].percentage)).div(new BN(sumPercentage)); + const amount = lpAmount.mul(new BN(allocations[i]?.percentage ?? 0)).div(new BN(sumPercentage)); sum = sum.add(amount); amounts.push({ - address: allocations[i].address, + address: allocations[i]?.address ?? PublicKey.default, amount, }); } // the last wallet get remaining amount amounts.push({ - address: allocations[allocations.length - 1].address, + address: allocations[allocations.length - 1]?.address ?? PublicKey.default, amount: lpAmount.sub(sum), }); return amounts; diff --git a/ts-client/src/examples/create_pool_with_authorized_config.ts b/ts-client/src/examples/create_pool_with_authorized_config.ts index c8e9d5bb..6208a557 100644 --- a/ts-client/src/examples/create_pool_with_authorized_config.ts +++ b/ts-client/src/examples/create_pool_with_authorized_config.ts @@ -61,7 +61,7 @@ async function main() { tokenBMint, tokenADepositAmount, tokenBDepositAmount, - config.publicKey, + config!.publicKey, payerWallet.payer, ); } diff --git a/ts-client/tsconfig.dev.json b/ts-client/tsconfig.dev.json new file mode 100644 index 00000000..accace64 --- /dev/null +++ b/ts-client/tsconfig.dev.json @@ -0,0 +1,17 @@ +{ + "extends": "./tsconfig.json", + "compileOnSave": true, + "compilerOptions": { + "outDir": "./dist/cjs/", + "moduleResolution": "node", + "noEmit": false, + "declaration": true, + "declarationMap": true, + "sourceMap": true, + "esModuleInterop": true, + "resolveJsonModule": true, + "noImplicitAny": false, + "skipLibCheck": true + }, + "exclude": ["./src/vault/tests/**/*", "./dist/**/*"] +} diff --git a/ts-client/tsconfig.json b/ts-client/tsconfig.json index f73a1659..eccaa28f 100644 --- a/ts-client/tsconfig.json +++ b/ts-client/tsconfig.json @@ -1,16 +1,13 @@ { - "extends": "@tsconfig/recommended/tsconfig.json", + "extends": "@meteora-ag/config/typescript/react-library", "compilerOptions": { "outDir": "dist", "types": ["jest", "mocha", "chai"], "typeRoots": ["./node_modules/@types"], "module": "commonjs", - // "target": "es6", - "target": "ES2022", + "target": "es6", "moduleResolution": "node", - "esModuleInterop": true, - "resolveJsonModule": true, "noImplicitAny": false, - "skipLibCheck": true + "preserveSymlinks": true } }