From 4c9f99832f1aea5149ca44e8caddeee8f08694ca Mon Sep 17 00:00:00 2001 From: tylersssss Date: Wed, 22 Feb 2023 02:36:59 -0500 Subject: [PATCH] Update package.json build steps and move js scripts out of src folder (#470) * extracts scripts from source; update tsc build configs and packages * publish latest * remove type module --- anchor-tests/test.ts | 44 +++---- migrations/deploy.ts | 4 +- package.json | 36 ++---- .../debug-scripts/debug-banks.ts | 12 +- .../debug-scripts/debug-perp.ts | 6 +- .../debug-scripts/debug-user.ts | 18 +-- ts/client/{src => }/scripts/decode-event.ts | 4 +- .../{src => }/scripts/devnet-admin-close.ts | 6 +- ts/client/{src => }/scripts/devnet-admin.ts | 16 +-- ts/client/{src => }/scripts/devnet-user-2.ts | 6 +- .../scripts/devnet-user-close-account.ts | 8 +- ts/client/{src => }/scripts/devnet-user.ts | 14 +-- .../{src => }/scripts/mb-add-spot-market.ts | 6 +- ts/client/{src => }/scripts/mb-admin-close.ts | 6 +- ts/client/{src => }/scripts/mb-admin.ts | 20 +-- .../{src => }/scripts/mb-close-account.ts | 8 +- .../scripts/mb-force-close-account.ts | 8 +- .../scripts/mb-liqtest-create-group.ts | 7 +- .../scripts/mb-liqtest-make-candidates.ts | 18 +-- .../mb-liqtest-settle-and-close-all.ts | 6 +- ts/client/{src => }/scripts/mb-user.ts | 6 +- ts/client/{src => }/scripts/mm/log-perp-ob.ts | 6 +- .../{src => }/scripts/mm/market-maker.ts | 18 +-- .../{src => }/scripts/mm/params/default.json | 0 .../scripts/mm/sequence-enforcer-util.ts | 2 +- ts/client/{src => }/scripts/mm/taker.ts | 20 +-- ts/client/src/accounts/bank.ts | 6 +- ts/client/src/accounts/group.ts | 13 +- ts/client/src/accounts/healthCache.spec.ts | 5 +- ts/client/src/accounts/healthCache.ts | 4 +- ts/client/src/accounts/mangoAccount.ts | 4 +- ts/client/src/accounts/perp.ts | 13 +- ts/client/src/accounts/serum3.ts | 4 +- ts/client/src/client.ts | 47 ++++--- ts/client/src/clientIxParamBuilder.ts | 2 +- ts/client/src/constants/index.ts | 2 +- ts/client/src/index.ts | 4 +- ts/client/src/types.ts | 3 +- ts/client/src/utils.ts | 10 +- ts/client/src/utils/rpc.ts | 4 +- ts/client/src/utils/spl.ts | 35 ++++++ tsconfig.build.json | 7 -- tsconfig.cjs.json | 5 +- tsconfig.esm.json | 9 +- tsconfig.json | 24 +--- tsconfig.types.json | 9 ++ yarn.lock | 116 ++++++------------ 47 files changed, 297 insertions(+), 334 deletions(-) rename ts/client/{src => scripts}/debug-scripts/debug-banks.ts (94%) rename ts/client/{src => scripts}/debug-scripts/debug-perp.ts (96%) rename ts/client/{src => scripts}/debug-scripts/debug-user.ts (94%) rename ts/client/{src => }/scripts/decode-event.ts (82%) rename ts/client/{src => }/scripts/devnet-admin-close.ts (94%) rename ts/client/{src => }/scripts/devnet-admin.ts (96%) rename ts/client/{src => }/scripts/devnet-user-2.ts (96%) rename ts/client/{src => }/scripts/devnet-user-close-account.ts (95%) rename ts/client/{src => }/scripts/devnet-user.ts (98%) rename ts/client/{src => }/scripts/mb-add-spot-market.ts (91%) rename ts/client/{src => }/scripts/mb-admin-close.ts (94%) rename ts/client/{src => }/scripts/mb-admin.ts (98%) rename ts/client/{src => }/scripts/mb-close-account.ts (95%) rename ts/client/{src => }/scripts/mb-force-close-account.ts (88%) rename ts/client/{src => }/scripts/mb-liqtest-create-group.ts (98%) rename ts/client/{src => }/scripts/mb-liqtest-make-candidates.ts (97%) rename ts/client/{src => }/scripts/mb-liqtest-settle-and-close-all.ts (94%) rename ts/client/{src => }/scripts/mb-user.ts (96%) rename ts/client/{src => }/scripts/mm/log-perp-ob.ts (91%) rename ts/client/{src => }/scripts/mm/market-maker.ts (97%) rename ts/client/{src => }/scripts/mm/params/default.json (100%) rename ts/client/{src => }/scripts/mm/sequence-enforcer-util.ts (97%) rename ts/client/{src => }/scripts/mm/taker.ts (91%) create mode 100644 ts/client/src/utils/spl.ts delete mode 100644 tsconfig.build.json create mode 100644 tsconfig.types.json diff --git a/anchor-tests/test.ts b/anchor-tests/test.ts index fa7bf09db..f72b2f865 100644 --- a/anchor-tests/test.ts +++ b/anchor-tests/test.ts @@ -1,6 +1,6 @@ -import * as anchor from '@project-serum/anchor'; -import { AnchorProvider, BN, Program } from '@project-serum/anchor'; -import NodeWallet from '@project-serum/anchor/dist/cjs/nodewallet'; +import * as anchor from '@coral-xyz/anchor'; +import { AnchorProvider, BN, Program } from '@coral-xyz/anchor'; +import NodeWallet from '@coral-xyz/anchor/dist/cjs/nodewallet'; import * as spl from '@solana/spl-token'; import { Connection, @@ -743,37 +743,25 @@ describe('mango-v4', () => { const positionA = accountA.getPerpPosition(btcPerp.perpMarketIndex)!; const positionB = accountB.getPerpPosition(btcPerp.perpMarketIndex)!; - assert.equal( - positionA.getBasePositionUi(btcPerp), - 1, - 'Position is long' + assert.equal(positionA.getBasePositionUi(btcPerp), 1, 'Position is long'); + assert.equal(positionB.getBasePositionUi(btcPerp), -1, 'Position is short'); + + assert.isTrue( + positionA.getEntryPrice(btcPerp).eq(new BN(99.0)), + 'long entry price matches', ); - assert.equal( - positionB.getBasePositionUi(btcPerp), - -1, - 'Position is short' + assert.isTrue( + positionB.getEntryPrice(btcPerp).eq(new BN(99.0)), + 'short entry price matches', ); assert.isTrue( - positionA.getEntryPrice(btcPerp) - .eq(new BN(99.0)), - 'long entry price matches' + positionA.getBreakEvenPrice(btcPerp).eq(new BN(99.0)), + 'long break even price matches', ); assert.isTrue( - positionB.getEntryPrice(btcPerp) - .eq(new BN(99.0)), - 'short entry price matches' - ); - - assert.isTrue( - positionA.getBreakEvenPrice(btcPerp) - .eq(new BN(99.0)), - 'long break even price matches' - ); - assert.isTrue( - positionB.getBreakEvenPrice(btcPerp) - .eq(new BN(99.0)), - 'short break even price matches' + positionB.getBreakEvenPrice(btcPerp).eq(new BN(99.0)), + 'short break even price matches', ); }); }); diff --git a/migrations/deploy.ts b/migrations/deploy.ts index 325cf3d0e..b8551f56a 100644 --- a/migrations/deploy.ts +++ b/migrations/deploy.ts @@ -2,11 +2,11 @@ // single deploy script that's invoked from the CLI, injecting a provider // configured from the workspace's Anchor.toml. -const anchor = require("@project-serum/anchor"); +const anchor = require('@coral-xyz/anchor'); module.exports = async function (provider) { // Configure client to use the provider. anchor.setProvider(provider); // Add your deploy script here. -} +}; diff --git a/package.json b/package.json index 41788c7ff..57714d6cc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@blockworks-foundation/mango-v4", - "version": "0.4.3", + "version": "0.5.21", "description": "Typescript Client for mango-v4 program.", "repository": "https://github.com/blockworks-foundation/mango-v4", "author": { @@ -8,31 +8,27 @@ "email": "hello@blockworks.foundation", "url": "https://blockworks.foundation" }, - "main": "dist/cjs/src/index.js", - "module": "dist/esm/src/index.js", - "types": "dist/types/src/index.d.ts", "sideEffects": false, + "main": "./dist/cjs/src/index.js", + "module": "./dist/esm/src/index.js", + "types": "./dist/types/src/index.d.ts", "files": [ "dist" ], "scripts": { - "build": "npm run build:esm; npm run build:cjs", - "build:cjs": "tsc -p tsconfig.cjs.json", - "build:esm": "tsc -p tsconfig.esm.json", + "build": "tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json && tsc -p tsconfig.types.json", "test": "ts-mocha ts/client/**/*.spec.ts --timeout 300000", - "clean": "rm -rf dist", "example1-user": "ts-node ts/client/src/scripts/example1-user.ts", "example1-admin": "ts-node ts/client/src/scripts/example1-admin.ts", "format": "prettier --check ./ts", - "lint": "eslint ./ts --ext ts --ext tsx --ext js --quiet", + "lint": "eslint ./ts/client/src --ext ts --ext tsx --ext js --quiet", "typecheck": "tsc --noEmit --pretty", - "prepare": "npm run build", - "prebuild": "npm run clean", - "prepublishOnly": "npm run validate && npm run build", - "validate": "npm run typecheck && npm run lint && npm run format" + "prepublishOnly": "yarn validate && yarn build", + "validate": "yarn lint && yarn format" }, "devDependencies": { "@tsconfig/recommended": "^1.0.1", + "@types/bn.js": "^5.1.1", "@types/bs58": "^4.0.1", "@types/chai": "^4.3.0", "@types/mocha": "^9.1.0", @@ -47,21 +43,18 @@ "ts-mocha": "^10.0.0", "ts-node": "^9.1.1", "typedoc": "^0.22.5", - "typescript": "^4.4.4" - }, - "publishConfig": { - "access": "public" + "typescript": "^4.8.4" }, "prettier": { "singleQuote": true, "trailingComma": "all" }, "dependencies": { - "@project-serum/anchor": "^0.25.0", - "@project-serum/serum": "^0.13.65", + "@coral-xyz/anchor": "^0.26.0", + "@project-serum/serum": "0.13.65", "@pythnetwork/client": "~2.14.0", "@solana/spl-token": "0.3.7", - "@solana/web3.js": "^1.63.1", + "@solana/web3.js": "^1.73.2", "@switchboard-xyz/sbv2-lite": "^0.1.6", "big.js": "^6.1.1", "binance-api-node": "^0.12.0", @@ -70,8 +63,5 @@ "dotenv": "^16.0.3", "node-kraken-api": "^2.2.2" }, - "resolutions": { - "@project-serum/anchor/@solana/web3.js": "1.63.1" - }, "license": "MIT" } diff --git a/ts/client/src/debug-scripts/debug-banks.ts b/ts/client/scripts/debug-scripts/debug-banks.ts similarity index 94% rename from ts/client/src/debug-scripts/debug-banks.ts rename to ts/client/scripts/debug-scripts/debug-banks.ts index 75c0ce615..540d437a4 100644 --- a/ts/client/src/debug-scripts/debug-banks.ts +++ b/ts/client/scripts/debug-scripts/debug-banks.ts @@ -1,12 +1,12 @@ -import { AnchorProvider, Wallet } from '@project-serum/anchor'; -import { coder } from '@project-serum/anchor/dist/cjs/spl/token'; +import { AnchorProvider, Wallet } from '@coral-xyz/anchor'; +import { coder } from '@coral-xyz/anchor/dist/cjs/spl/token'; import { Cluster, Connection, Keypair } from '@solana/web3.js'; import * as dotenv from 'dotenv'; import fs from 'fs'; -import { MangoClient } from '../client'; -import { MANGO_V4_ID } from '../constants'; -import { I80F48, ZERO_I80F48 } from '../numbers/I80F48'; -import { toUiDecimals } from '../utils'; +import { MangoClient } from '../../src/client'; +import { MANGO_V4_ID } from '../../src/constants'; +import { I80F48, ZERO_I80F48 } from '../../src/numbers/I80F48'; +import { toUiDecimals } from '../../src/utils'; dotenv.config(); const CLUSTER_URL = diff --git a/ts/client/src/debug-scripts/debug-perp.ts b/ts/client/scripts/debug-scripts/debug-perp.ts similarity index 96% rename from ts/client/src/debug-scripts/debug-perp.ts rename to ts/client/scripts/debug-scripts/debug-perp.ts index a5e4f6fa1..4dd57a9c5 100644 --- a/ts/client/src/debug-scripts/debug-perp.ts +++ b/ts/client/scripts/debug-scripts/debug-perp.ts @@ -1,8 +1,8 @@ -import { AnchorProvider, Wallet } from '@project-serum/anchor'; +import { AnchorProvider, Wallet } from '@coral-xyz/anchor'; import { Cluster, Connection, Keypair, PublicKey } from '@solana/web3.js'; import * as dotenv from 'dotenv'; -import { MangoClient } from '../client'; -import { MANGO_V4_ID } from '../constants'; +import { MangoClient } from '../../src/client'; +import { MANGO_V4_ID } from '../../src/constants'; dotenv.config(); const CLUSTER_URL = diff --git a/ts/client/src/debug-scripts/debug-user.ts b/ts/client/scripts/debug-scripts/debug-user.ts similarity index 94% rename from ts/client/src/debug-scripts/debug-user.ts rename to ts/client/scripts/debug-scripts/debug-user.ts index 8182bec1c..cdc21d1ed 100644 --- a/ts/client/src/debug-scripts/debug-user.ts +++ b/ts/client/scripts/debug-scripts/debug-user.ts @@ -1,14 +1,14 @@ -import { AnchorProvider, Wallet } from '@project-serum/anchor'; +import { AnchorProvider, Wallet } from '@coral-xyz/anchor'; import { Cluster, Connection, Keypair, PublicKey } from '@solana/web3.js'; import fs from 'fs'; -import { Group } from '../accounts/group'; -import { HealthCache } from '../accounts/healthCache'; -import { HealthType, MangoAccount } from '../accounts/mangoAccount'; -import { PerpMarket } from '../accounts/perp'; -import { Serum3Market } from '../accounts/serum3'; -import { MangoClient } from '../client'; -import { MANGO_V4_ID } from '../constants'; -import { toUiDecimalsForQuote } from '../utils'; +import { Group } from '../../src/accounts/group'; +import { HealthCache } from '../../src/accounts/healthCache'; +import { HealthType, MangoAccount } from '../../src/accounts/mangoAccount'; +import { PerpMarket } from '../../src/accounts/perp'; +import { Serum3Market } from '../../src/accounts/serum3'; +import { MangoClient } from '../../src/client'; +import { MANGO_V4_ID } from '../../src/constants'; +import { toUiDecimalsForQuote } from '../../src/utils'; const CLUSTER_URL = process.env.CLUSTER_URL_OVERRIDE || process.env.MB_CLUSTER_URL; diff --git a/ts/client/src/scripts/decode-event.ts b/ts/client/scripts/decode-event.ts similarity index 82% rename from ts/client/src/scripts/decode-event.ts rename to ts/client/scripts/decode-event.ts index bcd9b64d4..fd0bcfa25 100644 --- a/ts/client/src/scripts/decode-event.ts +++ b/ts/client/scripts/decode-event.ts @@ -1,5 +1,5 @@ -import { BN, BorshCoder } from '@project-serum/anchor'; -import { IDL } from '../mango_v4'; +import { BN, BorshCoder } from '@coral-xyz/anchor'; +import { IDL } from '../src/mango_v4'; async function main() { const coder = new BorshCoder(IDL); diff --git a/ts/client/src/scripts/devnet-admin-close.ts b/ts/client/scripts/devnet-admin-close.ts similarity index 94% rename from ts/client/src/scripts/devnet-admin-close.ts rename to ts/client/scripts/devnet-admin-close.ts index cfe157d67..7204f1ca6 100644 --- a/ts/client/src/scripts/devnet-admin-close.ts +++ b/ts/client/scripts/devnet-admin-close.ts @@ -1,8 +1,8 @@ -import { AnchorProvider, Wallet } from '@project-serum/anchor'; +import { AnchorProvider, Wallet } from '@coral-xyz/anchor'; import { Connection, Keypair, PublicKey } from '@solana/web3.js'; import fs from 'fs'; -import { MangoClient } from '../client'; -import { MANGO_V4_ID } from '../constants'; +import { MangoClient } from '../src/client'; +import { MANGO_V4_ID } from '../src/constants'; // // example script to close accounts - banks, markets, group etc. which require admin to be the signer diff --git a/ts/client/src/scripts/devnet-admin.ts b/ts/client/scripts/devnet-admin.ts similarity index 96% rename from ts/client/src/scripts/devnet-admin.ts rename to ts/client/scripts/devnet-admin.ts index e3fd4cbb8..71b7f8bd1 100644 --- a/ts/client/src/scripts/devnet-admin.ts +++ b/ts/client/scripts/devnet-admin.ts @@ -1,4 +1,4 @@ -import { AnchorProvider, Wallet } from '@project-serum/anchor'; +import { AnchorProvider, Wallet } from '@coral-xyz/anchor'; import { AddressLookupTableProgram, Connection, @@ -6,10 +6,10 @@ import { PublicKey, } from '@solana/web3.js'; import fs from 'fs'; -import { PerpMarketIndex } from '../accounts/perp'; -import { MangoClient } from '../client'; -import { MANGO_V4_ID } from '../constants'; -import { buildVersionedTx } from '../utils'; +import { PerpMarketIndex } from '../src/accounts/perp'; +import { MangoClient } from '../src/client'; +import { MANGO_V4_ID } from '../src/constants'; +import { buildVersionedTx } from '../src/utils'; // // An example for admins based on high level api i.e. the client @@ -131,6 +131,7 @@ async function main() { `...registered token bank ${bank.publicKey}, https://explorer.solana.com/tx/${sig}?cluster=devnet`, ); await group.reloadAll(client); + // eslint-disable-next-line } catch (error) {} // register token 1 @@ -320,11 +321,6 @@ async function main() { } } - try { - } catch (error) { - console.log(error); - } - process.exit(); } diff --git a/ts/client/src/scripts/devnet-user-2.ts b/ts/client/scripts/devnet-user-2.ts similarity index 96% rename from ts/client/src/scripts/devnet-user-2.ts rename to ts/client/scripts/devnet-user-2.ts index 1a7f5f318..3a469cb78 100644 --- a/ts/client/src/scripts/devnet-user-2.ts +++ b/ts/client/scripts/devnet-user-2.ts @@ -1,8 +1,8 @@ -import { AnchorProvider, Wallet } from '@project-serum/anchor'; +import { AnchorProvider, Wallet } from '@coral-xyz/anchor'; import { Connection, Keypair, PublicKey } from '@solana/web3.js'; import fs from 'fs'; -import { MangoClient } from '../client'; -import { MANGO_V4_ID } from '../constants'; +import { MangoClient } from '../src/client'; +import { MANGO_V4_ID } from '../src/constants'; // // An example for users based on high level api i.e. the client diff --git a/ts/client/src/scripts/devnet-user-close-account.ts b/ts/client/scripts/devnet-user-close-account.ts similarity index 95% rename from ts/client/src/scripts/devnet-user-close-account.ts rename to ts/client/scripts/devnet-user-close-account.ts index cb6ad9f24..1f3c43422 100644 --- a/ts/client/src/scripts/devnet-user-close-account.ts +++ b/ts/client/scripts/devnet-user-close-account.ts @@ -1,9 +1,9 @@ -import { AnchorProvider, BN, Wallet } from '@project-serum/anchor'; +import { AnchorProvider, BN, Wallet } from '@coral-xyz/anchor'; import { Connection, Keypair } from '@solana/web3.js'; import fs from 'fs'; -import { Serum3Side } from '../accounts/serum3'; -import { MangoClient } from '../client'; -import { MANGO_V4_ID } from '../constants'; +import { Serum3Side } from '../src/accounts/serum3'; +import { MangoClient } from '../src/client'; +import { MANGO_V4_ID } from '../src/constants'; // // script which shows how to close a mango account cleanly i.e. close all active positions, withdraw all tokens, etc. diff --git a/ts/client/src/scripts/devnet-user.ts b/ts/client/scripts/devnet-user.ts similarity index 98% rename from ts/client/src/scripts/devnet-user.ts rename to ts/client/scripts/devnet-user.ts index 3b044eed1..87189f628 100644 --- a/ts/client/src/scripts/devnet-user.ts +++ b/ts/client/scripts/devnet-user.ts @@ -1,13 +1,13 @@ -import { AnchorProvider, BN, Wallet } from '@project-serum/anchor'; +import { AnchorProvider, BN, Wallet } from '@coral-xyz/anchor'; import { Connection, Keypair, PublicKey } from '@solana/web3.js'; import { expect } from 'chai'; import fs from 'fs'; -import { Group } from '../accounts/group'; -import { HealthType } from '../accounts/mangoAccount'; -import { PerpOrderSide, PerpOrderType } from '../accounts/perp'; -import { MangoClient } from '../client'; -import { MANGO_V4_ID } from '../constants'; -import { toUiDecimalsForQuote } from '../utils'; +import { Group } from '../src/accounts/group'; +import { HealthType } from '../src/accounts/mangoAccount'; +import { PerpOrderSide, PerpOrderType } from '../src/accounts/perp'; +import { MangoClient } from '../src/client'; +import { MANGO_V4_ID } from '../src/constants'; +import { toUiDecimalsForQuote } from '../src/utils'; // // An example for users based on high level api i.e. the client diff --git a/ts/client/src/scripts/mb-add-spot-market.ts b/ts/client/scripts/mb-add-spot-market.ts similarity index 91% rename from ts/client/src/scripts/mb-add-spot-market.ts rename to ts/client/scripts/mb-add-spot-market.ts index 822c1f813..e1dc122c2 100644 --- a/ts/client/src/scripts/mb-add-spot-market.ts +++ b/ts/client/scripts/mb-add-spot-market.ts @@ -1,9 +1,9 @@ -import { AnchorProvider, Wallet } from '@project-serum/anchor'; +import { AnchorProvider, Wallet } from '@coral-xyz/anchor'; import { Connection, Keypair, PublicKey } from '@solana/web3.js'; import * as dotenv from 'dotenv'; import fs from 'fs'; -import { MangoClient } from '../client'; -import { MANGO_V4_ID } from '../constants'; +import { MangoClient } from '../src/client'; +import { MANGO_V4_ID } from '../src/constants'; dotenv.config(); // diff --git a/ts/client/src/scripts/mb-admin-close.ts b/ts/client/scripts/mb-admin-close.ts similarity index 94% rename from ts/client/src/scripts/mb-admin-close.ts rename to ts/client/scripts/mb-admin-close.ts index dbb9e5bbe..d2449f52f 100644 --- a/ts/client/src/scripts/mb-admin-close.ts +++ b/ts/client/scripts/mb-admin-close.ts @@ -1,8 +1,8 @@ -import { AnchorProvider, Wallet } from '@project-serum/anchor'; +import { AnchorProvider, Wallet } from '@coral-xyz/anchor'; import { Connection, Keypair } from '@solana/web3.js'; import fs from 'fs'; -import { MangoClient } from '../client'; -import { MANGO_V4_ID } from '../constants'; +import { MangoClient } from '../src/client'; +import { MANGO_V4_ID } from '../src/constants'; // // example script to close accounts - banks, markets, group etc. which require admin to be the signer diff --git a/ts/client/src/scripts/mb-admin.ts b/ts/client/scripts/mb-admin.ts similarity index 98% rename from ts/client/src/scripts/mb-admin.ts rename to ts/client/scripts/mb-admin.ts index 60a4bc0da..4c13b2163 100644 --- a/ts/client/src/scripts/mb-admin.ts +++ b/ts/client/scripts/mb-admin.ts @@ -1,9 +1,9 @@ -import { AnchorProvider, Wallet } from '@project-serum/anchor'; +import { AnchorProvider, Wallet } from '@coral-xyz/anchor'; import { ASSOCIATED_TOKEN_PROGRAM_ID, NATIVE_MINT, TOKEN_PROGRAM_ID, -} from '@solana/spl-token'; +} from '../src/utils/spl'; import { AddressLookupTableProgram, ComputeBudgetProgram, @@ -15,21 +15,21 @@ import { SystemProgram, } from '@solana/web3.js'; import fs from 'fs'; -import { TokenIndex } from '../accounts/bank'; -import { Group } from '../accounts/group'; +import { TokenIndex } from '../src/accounts/bank'; +import { Group } from '../src/accounts/group'; import { Serum3OrderType, Serum3SelfTradeBehavior, Serum3Side, -} from '../accounts/serum3'; -import { Builder } from '../builder'; -import { MangoClient } from '../client'; +} from '../src/accounts/serum3'; +import { Builder } from '../src/builder'; +import { MangoClient } from '../src/client'; import { NullPerpEditParams, NullTokenEditParams, -} from '../clientIxParamBuilder'; -import { MANGO_V4_ID, OPENBOOK_PROGRAM_ID } from '../constants'; -import { buildVersionedTx, toNative } from '../utils'; +} from '../src/clientIxParamBuilder'; +import { MANGO_V4_ID, OPENBOOK_PROGRAM_ID } from '../src/constants'; +import { buildVersionedTx, toNative } from '../src/utils'; const GROUP_NUM = Number(process.env.GROUP_NUM || 0); diff --git a/ts/client/src/scripts/mb-close-account.ts b/ts/client/scripts/mb-close-account.ts similarity index 95% rename from ts/client/src/scripts/mb-close-account.ts rename to ts/client/scripts/mb-close-account.ts index 9ae717f6d..13d6ad8ca 100644 --- a/ts/client/src/scripts/mb-close-account.ts +++ b/ts/client/scripts/mb-close-account.ts @@ -1,9 +1,9 @@ -import { AnchorProvider, BN, Wallet } from '@project-serum/anchor'; +import { AnchorProvider, BN, Wallet } from '@coral-xyz/anchor'; import { Connection, Keypair } from '@solana/web3.js'; import fs from 'fs'; -import { Serum3Side } from '../accounts/serum3'; -import { MangoClient } from '../client'; -import { MANGO_V4_ID } from '../constants'; +import { Serum3Side } from '../src/accounts/serum3'; +import { MangoClient } from '../src/client'; +import { MANGO_V4_ID } from '../src/constants'; // // (untested?) script which closes a mango account cleanly, first closes all positions, withdraws all tokens and then closes it diff --git a/ts/client/src/scripts/mb-force-close-account.ts b/ts/client/scripts/mb-force-close-account.ts similarity index 88% rename from ts/client/src/scripts/mb-force-close-account.ts rename to ts/client/scripts/mb-force-close-account.ts index 5e38413b2..44eea6b76 100644 --- a/ts/client/src/scripts/mb-force-close-account.ts +++ b/ts/client/scripts/mb-force-close-account.ts @@ -1,9 +1,9 @@ -import { AnchorProvider, Wallet } from '@project-serum/anchor'; +import { AnchorProvider, Wallet } from '@coral-xyz/anchor'; import { Connection, Keypair, PublicKey } from '@solana/web3.js'; import fs from 'fs'; -import { Group } from '../accounts/group'; -import { MangoClient } from '../client'; -import { MANGO_V4_ID } from '../constants'; +import { Group } from '../src/accounts/group'; +import { MangoClient } from '../src/client'; +import { MANGO_V4_ID } from '../src/constants'; const GROUP_NUM = Number(process.env.GROUP_NUM || 0); const MANGO_ACCOUNT_PK = process.env.MANGO_ACCOUNT_PK; diff --git a/ts/client/src/scripts/mb-liqtest-create-group.ts b/ts/client/scripts/mb-liqtest-create-group.ts similarity index 98% rename from ts/client/src/scripts/mb-liqtest-create-group.ts rename to ts/client/scripts/mb-liqtest-create-group.ts index 7df441977..813d7cdad 100644 --- a/ts/client/src/scripts/mb-liqtest-create-group.ts +++ b/ts/client/scripts/mb-liqtest-create-group.ts @@ -1,4 +1,4 @@ -import { AnchorProvider, Wallet } from '@project-serum/anchor'; +import { AnchorProvider, Wallet } from '@coral-xyz/anchor'; import { AddressLookupTableProgram, Connection, @@ -6,9 +6,8 @@ import { PublicKey, } from '@solana/web3.js'; import fs from 'fs'; -import { MangoClient } from '../client'; -import { MANGO_V4_ID } from '../constants'; -import { sendTransaction } from '../utils/rpc'; +import { MangoClient } from '../src/client'; +import { MANGO_V4_ID } from '../src/constants'; // // Script which depoys a new mango group, and registers 3 tokens diff --git a/ts/client/src/scripts/mb-liqtest-make-candidates.ts b/ts/client/scripts/mb-liqtest-make-candidates.ts similarity index 97% rename from ts/client/src/scripts/mb-liqtest-make-candidates.ts rename to ts/client/scripts/mb-liqtest-make-candidates.ts index 6402322e7..3dac48399 100644 --- a/ts/client/src/scripts/mb-liqtest-make-candidates.ts +++ b/ts/client/scripts/mb-liqtest-make-candidates.ts @@ -1,21 +1,21 @@ -import { AnchorProvider, BN, Wallet } from '@project-serum/anchor'; +import { AnchorProvider, BN, Wallet } from '@coral-xyz/anchor'; import { Connection, Keypair, PublicKey } from '@solana/web3.js'; import fs from 'fs'; -import { Bank } from '../accounts/bank'; -import { MangoAccount } from '../accounts/mangoAccount'; -import { PerpMarket, PerpOrderSide, PerpOrderType } from '../accounts/perp'; +import { Bank } from '../src/accounts/bank'; +import { MangoAccount } from '../src/accounts/mangoAccount'; +import { PerpMarket, PerpOrderSide, PerpOrderType } from '../src/accounts/perp'; import { Serum3OrderType, Serum3SelfTradeBehavior, Serum3Side, -} from '../accounts/serum3'; -import { Builder } from '../builder'; -import { MangoClient } from '../client'; +} from '../src/accounts/serum3'; +import { Builder } from '../src/builder'; +import { MangoClient } from '../src/client'; import { NullPerpEditParams, NullTokenEditParams, -} from '../clientIxParamBuilder'; -import { MANGO_V4_ID } from '../constants'; +} from '../src/clientIxParamBuilder'; +import { MANGO_V4_ID } from '../src/constants'; // // This script creates liquidation candidates diff --git a/ts/client/src/scripts/mb-liqtest-settle-and-close-all.ts b/ts/client/scripts/mb-liqtest-settle-and-close-all.ts similarity index 94% rename from ts/client/src/scripts/mb-liqtest-settle-and-close-all.ts rename to ts/client/scripts/mb-liqtest-settle-and-close-all.ts index e05054799..b61046826 100644 --- a/ts/client/src/scripts/mb-liqtest-settle-and-close-all.ts +++ b/ts/client/scripts/mb-liqtest-settle-and-close-all.ts @@ -1,8 +1,8 @@ -import { AnchorProvider, Wallet } from '@project-serum/anchor'; +import { AnchorProvider, Wallet } from '@coral-xyz/anchor'; import { Connection, Keypair } from '@solana/web3.js'; import fs from 'fs'; -import { MangoClient } from '../client'; -import { MANGO_V4_ID } from '../constants'; +import { MangoClient } from '../src/client'; +import { MANGO_V4_ID } from '../src/constants'; // // This script tries to withdraw all positive balances for all accounts diff --git a/ts/client/src/scripts/mb-user.ts b/ts/client/scripts/mb-user.ts similarity index 96% rename from ts/client/src/scripts/mb-user.ts rename to ts/client/scripts/mb-user.ts index 19a443a9b..c2d7cd0db 100644 --- a/ts/client/src/scripts/mb-user.ts +++ b/ts/client/scripts/mb-user.ts @@ -1,8 +1,8 @@ -import { AnchorProvider, Wallet } from '@project-serum/anchor'; +import { AnchorProvider, Wallet } from '@coral-xyz/anchor'; import { Connection, Keypair } from '@solana/web3.js'; import fs from 'fs'; -import { HealthType } from '../accounts/mangoAccount'; -import { MangoClient, MANGO_V4_ID, toUiDecimalsForQuote } from '../index'; +import { HealthType } from '../src/accounts/mangoAccount'; +import { MangoClient, MANGO_V4_ID, toUiDecimalsForQuote } from '../src/index'; async function main() { const options = AnchorProvider.defaultOptions(); diff --git a/ts/client/src/scripts/mm/log-perp-ob.ts b/ts/client/scripts/mm/log-perp-ob.ts similarity index 91% rename from ts/client/src/scripts/mm/log-perp-ob.ts rename to ts/client/scripts/mm/log-perp-ob.ts index 8a5da5556..b27a811e8 100644 --- a/ts/client/src/scripts/mm/log-perp-ob.ts +++ b/ts/client/scripts/mm/log-perp-ob.ts @@ -1,7 +1,7 @@ -import { AnchorProvider, Wallet } from '@project-serum/anchor'; +import { AnchorProvider, Wallet } from '@coral-xyz/anchor'; import { Cluster, Connection, Keypair, PublicKey } from '@solana/web3.js'; -import { MangoClient } from '../../client'; -import { MANGO_V4_ID } from '../../constants'; +import { MangoClient } from '../../src/client'; +import { MANGO_V4_ID } from '../../src/constants'; // For easy switching between mainnet and devnet, default is mainnet const CLUSTER: Cluster = diff --git a/ts/client/src/scripts/mm/market-maker.ts b/ts/client/scripts/mm/market-maker.ts similarity index 97% rename from ts/client/src/scripts/mm/market-maker.ts rename to ts/client/scripts/mm/market-maker.ts index 7ceee0cb1..e7175e541 100644 --- a/ts/client/src/scripts/mm/market-maker.ts +++ b/ts/client/scripts/mm/market-maker.ts @@ -1,4 +1,4 @@ -import { AnchorProvider, BN, Wallet } from '@project-serum/anchor'; +import { AnchorProvider, BN, Wallet } from '@coral-xyz/anchor'; import { Cluster, Connection, @@ -10,19 +10,19 @@ import Binance from 'binance-api-node'; import fs from 'fs'; import { Kraken } from 'node-kraken-api'; import path from 'path'; -import { Group } from '../../accounts/group'; -import { HealthType, MangoAccount } from '../../accounts/mangoAccount'; +import { Group } from '../../src/accounts/group'; +import { HealthType, MangoAccount } from '../../src/accounts/mangoAccount'; import { BookSide, PerpMarket, PerpMarketIndex, PerpOrderSide, PerpOrderType, -} from '../../accounts/perp'; -import { MangoClient } from '../../client'; -import { MANGO_V4_ID } from '../../constants'; -import { toUiDecimalsForQuote } from '../../utils'; -import { sendTransaction } from '../../utils/rpc'; +} from '../../src/accounts/perp'; +import { MangoClient } from '../../src/client'; +import { MANGO_V4_ID } from '../../src/constants'; +import { toUiDecimalsForQuote } from '../../src/utils'; +import { sendTransaction } from '../../src/utils/rpc'; import * as defaultParams from './params/default.json'; import { makeCheckAndSetSequenceNumberIx, @@ -159,6 +159,8 @@ async function initSequenceEnforcerAccounts( CLUSTER, ), ); + + // eslint-disable-next-line while (true) { try { const sig = await sendTransaction( diff --git a/ts/client/src/scripts/mm/params/default.json b/ts/client/scripts/mm/params/default.json similarity index 100% rename from ts/client/src/scripts/mm/params/default.json rename to ts/client/scripts/mm/params/default.json diff --git a/ts/client/src/scripts/mm/sequence-enforcer-util.ts b/ts/client/scripts/mm/sequence-enforcer-util.ts similarity index 97% rename from ts/client/src/scripts/mm/sequence-enforcer-util.ts rename to ts/client/scripts/mm/sequence-enforcer-util.ts index 721aeb8eb..ecb4204f2 100644 --- a/ts/client/src/scripts/mm/sequence-enforcer-util.ts +++ b/ts/client/scripts/mm/sequence-enforcer-util.ts @@ -1,4 +1,4 @@ -import { BN } from '@project-serum/anchor'; +import { BN } from '@coral-xyz/anchor'; import { PublicKey, SystemProgram, diff --git a/ts/client/src/scripts/mm/taker.ts b/ts/client/scripts/mm/taker.ts similarity index 91% rename from ts/client/src/scripts/mm/taker.ts rename to ts/client/scripts/mm/taker.ts index ce19c7539..e3d4159bb 100644 --- a/ts/client/src/scripts/mm/taker.ts +++ b/ts/client/scripts/mm/taker.ts @@ -1,13 +1,17 @@ -import { AnchorProvider, Wallet } from '@project-serum/anchor'; +import { AnchorProvider, Wallet } from '@coral-xyz/anchor'; import { Cluster, Connection, Keypair, PublicKey } from '@solana/web3.js'; import fs from 'fs'; -import { Group } from '../../accounts/group'; -import { MangoAccount } from '../../accounts/mangoAccount'; -import { PerpMarket, PerpOrderSide, PerpOrderType } from '../../accounts/perp'; -import { MangoClient } from '../../client'; -import { MANGO_V4_ID } from '../../constants'; -import { ZERO_I80F48 } from '../../numbers/I80F48'; -import { toNativeI80F48, toUiDecimalsForQuote } from '../../utils'; +import { Group } from '../../src/accounts/group'; +import { MangoAccount } from '../../src/accounts/mangoAccount'; +import { + PerpMarket, + PerpOrderSide, + PerpOrderType, +} from '../../src/accounts/perp'; +import { MangoClient } from '../../src/client'; +import { MANGO_V4_ID } from '../../src/constants'; +import { ZERO_I80F48 } from '../../src/numbers/I80F48'; +import { toNativeI80F48, toUiDecimalsForQuote } from '../../src/utils'; // For easy switching between mainnet and devnet, default is mainnet const CLUSTER: Cluster = diff --git a/ts/client/src/accounts/bank.ts b/ts/client/src/accounts/bank.ts index 9fa22caf3..b064d941f 100644 --- a/ts/client/src/accounts/bank.ts +++ b/ts/client/src/accounts/bank.ts @@ -1,11 +1,9 @@ -import { BN } from '@project-serum/anchor'; -import { utf8 } from '@project-serum/anchor/dist/cjs/utils/bytes'; +import { BN } from '@coral-xyz/anchor'; +import { utf8 } from '@coral-xyz/anchor/dist/cjs/utils/bytes'; import { PublicKey } from '@solana/web3.js'; import { I80F48, I80F48Dto, ZERO_I80F48 } from '../numbers/I80F48'; import { As, toUiDecimals } from '../utils'; -export const QUOTE_DECIMALS = 6; - export type TokenIndex = number & As<'token-index'>; export type OracleConfigDto = { diff --git a/ts/client/src/accounts/group.ts b/ts/client/src/accounts/group.ts index 87113e10a..ae9cf6126 100644 --- a/ts/client/src/accounts/group.ts +++ b/ts/client/src/accounts/group.ts @@ -1,5 +1,4 @@ -import { BorshAccountsCoder } from '@project-serum/anchor'; -import { coder } from '@project-serum/anchor/dist/cjs/spl/token'; +import { BorshAccountsCoder } from '@coral-xyz/anchor'; import { Market, Orderbook } from '@project-serum/serum'; import { parsePriceData } from '@pythnetwork/client'; import { @@ -8,7 +7,8 @@ import { PublicKey, } from '@solana/web3.js'; import BN from 'bn.js'; -import { cloneDeep, merge } from 'lodash'; +import cloneDeep from 'lodash/cloneDeep'; +import merge from 'lodash/merge'; import { MangoClient } from '../client'; import { OPENBOOK_PROGRAM_ID } from '../constants'; import { Id } from '../ids'; @@ -408,16 +408,13 @@ export class Group { await client.program.provider.connection.getMultipleAccountsInfo( vaultPks, ); - + const coder = new BorshAccountsCoder(client.program.idl); this.vaultAmountsMap = new Map( vaultAccounts.map((vaultAi, i) => { if (!vaultAi) { throw new Error(`Undefined vaultAi for ${vaultPks[i]}`!); } - const vaultAmount = coder().accounts.decode( - 'token', - vaultAi.data, - ).amount; + const vaultAmount = coder.decode('token', vaultAi.data).amount; return [vaultPks[i].toBase58(), vaultAmount]; }), ); diff --git a/ts/client/src/accounts/healthCache.spec.ts b/ts/client/src/accounts/healthCache.spec.ts index bf1059217..7fb979d50 100644 --- a/ts/client/src/accounts/healthCache.spec.ts +++ b/ts/client/src/accounts/healthCache.spec.ts @@ -1,7 +1,8 @@ -import { BN } from '@project-serum/anchor'; +import { BN } from '@coral-xyz/anchor'; import { OpenOrders } from '@project-serum/serum'; import { expect } from 'chai'; -import { cloneDeep, range } from 'lodash'; +import cloneDeep from 'lodash/cloneDeep'; +import range from 'lodash/range'; import { I80F48, ONE_I80F48, ZERO_I80F48 } from '../numbers/I80F48'; import { BankForHealth, StablePriceModel, TokenIndex } from './bank'; diff --git a/ts/client/src/accounts/healthCache.ts b/ts/client/src/accounts/healthCache.ts index 70e663351..62fd9ce65 100644 --- a/ts/client/src/accounts/healthCache.ts +++ b/ts/client/src/accounts/healthCache.ts @@ -1,7 +1,7 @@ -import { BN } from '@project-serum/anchor'; +import { BN } from '@coral-xyz/anchor'; import { OpenOrders } from '@project-serum/serum'; import { PublicKey } from '@solana/web3.js'; -import { cloneDeep } from 'lodash'; +import cloneDeep from 'lodash/cloneDeep'; import { HUNDRED_I80F48, I80F48, diff --git a/ts/client/src/accounts/mangoAccount.ts b/ts/client/src/accounts/mangoAccount.ts index e6f03de02..bfc40ed1e 100644 --- a/ts/client/src/accounts/mangoAccount.ts +++ b/ts/client/src/accounts/mangoAccount.ts @@ -1,5 +1,5 @@ -import { AnchorProvider, BN } from '@project-serum/anchor'; -import { utf8 } from '@project-serum/anchor/dist/cjs/utils/bytes'; +import { AnchorProvider, BN } from '@coral-xyz/anchor'; +import { utf8 } from '@coral-xyz/anchor/dist/cjs/utils/bytes'; import { OpenOrders, Order, Orderbook } from '@project-serum/serum/lib/market'; import { AccountInfo, PublicKey, TransactionSignature } from '@solana/web3.js'; import { MangoClient } from '../client'; diff --git a/ts/client/src/accounts/perp.ts b/ts/client/src/accounts/perp.ts index f64e08ff3..4f02bb71b 100644 --- a/ts/client/src/accounts/perp.ts +++ b/ts/client/src/accounts/perp.ts @@ -1,16 +1,21 @@ -import { BN } from '@project-serum/anchor'; -import { utf8 } from '@project-serum/anchor/dist/cjs/utils/bytes'; +import { BN } from '@coral-xyz/anchor'; +import { utf8 } from '@coral-xyz/anchor/dist/cjs/utils/bytes'; import { PublicKey } from '@solana/web3.js'; import Big from 'big.js'; import { MangoClient } from '../client'; import { RUST_U64_MAX } from '../constants'; import { I80F48, I80F48Dto, ZERO_I80F48 } from '../numbers/I80F48'; import { Modify } from '../types'; -import { As, U64_MAX_BN, toNative, toUiDecimals } from '../utils'; +import { + As, + U64_MAX_BN, + toNative, + toUiDecimals, + QUOTE_DECIMALS, +} from '../utils'; import { OracleConfig, OracleConfigDto, - QUOTE_DECIMALS, StablePriceModel, TokenIndex, } from './bank'; diff --git a/ts/client/src/accounts/serum3.ts b/ts/client/src/accounts/serum3.ts index 4fe5f8cf6..e77522033 100644 --- a/ts/client/src/accounts/serum3.ts +++ b/ts/client/src/accounts/serum3.ts @@ -1,5 +1,5 @@ -import { utf8 } from '@project-serum/anchor/dist/cjs/utils/bytes'; -import { Market, Orderbook } from '@project-serum/serum/lib/market'; +import { utf8 } from '@coral-xyz/anchor/dist/cjs/utils/bytes'; +import { Market, Orderbook } from '@project-serum/serum'; import { Cluster, PublicKey } from '@solana/web3.js'; import BN from 'bn.js'; import { MangoClient } from '../client'; diff --git a/ts/client/src/client.ts b/ts/client/src/client.ts index da224f29c..30291dd40 100644 --- a/ts/client/src/client.ts +++ b/ts/client/src/client.ts @@ -1,10 +1,5 @@ -import { AnchorProvider, BN, Program, Provider } from '@project-serum/anchor'; -import { - WRAPPED_SOL_MINT, - closeAccount, - initializeAccount, -} from '@project-serum/serum/lib/token-instructions'; -import { TOKEN_PROGRAM_ID } from '@solana/spl-token'; +import { AnchorProvider, BN, Program, Provider } from '@coral-xyz/anchor'; +import { TOKEN_PROGRAM_ID, NATIVE_MINT } from './utils/spl'; import { AccountMeta, AddressLookupTableAccount, @@ -65,6 +60,10 @@ import { toNative, } from './utils'; import { sendTransaction } from './utils/rpc'; +import { + createCloseAccountInstruction, + createInitializeAccount3Instruction, +} from '@solana/spl-token'; export enum AccountRetriever { Scanning, @@ -1020,7 +1019,7 @@ export class MangoClient { let preInstructions: TransactionInstruction[] = []; let postInstructions: TransactionInstruction[] = []; const additionalSigners: Signer[] = []; - if (mintPk.equals(WRAPPED_SOL_MINT)) { + if (mintPk.equals(NATIVE_MINT)) { wrappedSolAccount = new Keypair(); const lamports = nativeAmount.add(new BN(1e7)); @@ -1032,18 +1031,18 @@ export class MangoClient { space: 165, programId: TOKEN_PROGRAM_ID, }), - initializeAccount({ - account: wrappedSolAccount.publicKey, - mint: WRAPPED_SOL_MINT, - owner: mangoAccount.owner, - }), + createInitializeAccount3Instruction( + wrappedSolAccount.publicKey, + NATIVE_MINT, + mangoAccount.owner, + ), ]; postInstructions = [ - closeAccount({ - source: wrappedSolAccount.publicKey, - destination: mangoAccount.owner, - owner: mangoAccount.owner, - }), + createCloseAccountInstruction( + wrappedSolAccount.publicKey, + mangoAccount.owner, + mangoAccount.owner, + ), ]; additionalSigners.push(wrappedSolAccount); } @@ -1128,13 +1127,13 @@ export class MangoClient { ]; const postInstructions: TransactionInstruction[] = []; - if (mintPk.equals(WRAPPED_SOL_MINT)) { + if (mintPk.equals(NATIVE_MINT)) { postInstructions.push( - closeAccount({ - source: tokenAccountPk, - destination: mangoAccount.owner, - owner: mangoAccount.owner, - }), + createCloseAccountInstruction( + tokenAccountPk, + mangoAccount.owner, + mangoAccount.owner, + ), ); } diff --git a/ts/client/src/clientIxParamBuilder.ts b/ts/client/src/clientIxParamBuilder.ts index 179d3f739..e3506db76 100644 --- a/ts/client/src/clientIxParamBuilder.ts +++ b/ts/client/src/clientIxParamBuilder.ts @@ -1,4 +1,4 @@ -import { BN } from '@project-serum/anchor'; +import { BN } from '@coral-xyz/anchor'; import { PublicKey } from '@solana/web3.js'; import { InterestRateParams, OracleConfigParams } from './types'; diff --git a/ts/client/src/constants/index.ts b/ts/client/src/constants/index.ts index f09f7ef04..e0a96c385 100644 --- a/ts/client/src/constants/index.ts +++ b/ts/client/src/constants/index.ts @@ -1,4 +1,4 @@ -import { BN } from '@project-serum/anchor'; +import { BN } from '@coral-xyz/anchor'; import { PublicKey } from '@solana/web3.js'; export const RUST_U64_MAX = (): BN => { diff --git a/ts/client/src/index.ts b/ts/client/src/index.ts index 0f8e0b86e..e3576f6f1 100644 --- a/ts/client/src/index.ts +++ b/ts/client/src/index.ts @@ -13,15 +13,13 @@ export { Serum3Side, } from './accounts/serum3'; export { - IxGateParams, NullPerpEditParams, NullTokenEditParams, - PerpEditParams, - TokenEditParams, TrueIxGateParams, buildIxGate, } from './clientIxParamBuilder'; export * from './constants'; export * from './numbers/I80F48'; export * from './utils'; +export * from './types'; export { Group, StubOracle, MangoClient, MANGO_V4_ID }; diff --git a/ts/client/src/types.ts b/ts/client/src/types.ts index 88c1f47d3..f31b6d503 100644 --- a/ts/client/src/types.ts +++ b/ts/client/src/types.ts @@ -1,5 +1,4 @@ -import { BN } from '@project-serum/anchor'; -import { PublicKey } from '@solana/web3.js'; +import { BN } from '@coral-xyz/anchor'; export type Modify = Omit & R; diff --git a/ts/client/src/utils.ts b/ts/client/src/utils.ts index 6faa971fa..2e535c052 100644 --- a/ts/client/src/utils.ts +++ b/ts/client/src/utils.ts @@ -1,8 +1,5 @@ -import { AnchorProvider } from '@project-serum/anchor'; -import { - ASSOCIATED_TOKEN_PROGRAM_ID, - TOKEN_PROGRAM_ID, -} from '@solana/spl-token'; +import { AnchorProvider } from '@coral-xyz/anchor'; +import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from './utils/spl'; import { AddressLookupTableAccount, MessageV0, @@ -13,7 +10,6 @@ import { VersionedTransaction, } from '@solana/web3.js'; import BN from 'bn.js'; -import { QUOTE_DECIMALS } from './accounts/bank'; import { I80F48 } from './numbers/I80F48'; /// @@ -50,6 +46,8 @@ export function toUiDecimals( return nativeAmount / Math.pow(10, decimals); } +export const QUOTE_DECIMALS = 6; + export function toUiDecimalsForQuote( nativeAmount: BN | I80F48 | number, ): number { diff --git a/ts/client/src/utils/rpc.ts b/ts/client/src/utils/rpc.ts index 845548b59..4613e1b6a 100644 --- a/ts/client/src/utils/rpc.ts +++ b/ts/client/src/utils/rpc.ts @@ -1,5 +1,5 @@ -import { AnchorProvider } from '@project-serum/anchor'; -import NodeWallet from '@project-serum/anchor/dist/cjs/nodewallet'; +import { AnchorProvider } from '@coral-xyz/anchor'; +import NodeWallet from '@coral-xyz/anchor/dist/cjs/nodewallet'; import { AddressLookupTableAccount, ComputeBudgetProgram, diff --git a/ts/client/src/utils/spl.ts b/ts/client/src/utils/spl.ts new file mode 100644 index 000000000..e9095fbcc --- /dev/null +++ b/ts/client/src/utils/spl.ts @@ -0,0 +1,35 @@ +import { PublicKey } from '@solana/web3.js'; + +/** Address of the SPL Token program */ +export const TOKEN_PROGRAM_ID = new PublicKey( + 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', +); + +/** Address of the SPL Token 2022 program */ +export const TOKEN_2022_PROGRAM_ID = new PublicKey( + 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb', +); + +/** Address of the SPL Associated Token Account program */ +export const ASSOCIATED_TOKEN_PROGRAM_ID = new PublicKey( + 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL', +); + +/** Address of the special mint for wrapped native SOL in spl-token */ +export const NATIVE_MINT = new PublicKey( + 'So11111111111111111111111111111111111111112', +); + +/** Address of the special mint for wrapped native SOL in spl-token-2022 */ +export const NATIVE_MINT_2022 = new PublicKey( + '9pan9bMn5HatX4EJdBwg9VgCa7Uz5HL8N1m5D3NdXejP', +); + +/** Check that the token program provided is not `Tokenkeg...`, useful when using extensions */ +export function programSupportsExtensions(programId: PublicKey): boolean { + if (programId === TOKEN_PROGRAM_ID) { + return false; + } else { + return true; + } +} diff --git a/tsconfig.build.json b/tsconfig.build.json deleted file mode 100644 index 3213cda91..000000000 --- a/tsconfig.build.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "./tsconfig", - "compilerOptions": { - "skipLibCheck": true, - "skipDefaultLibCheck": true - } -} diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json index 6c73afe5f..b43dfbcaf 100644 --- a/tsconfig.cjs.json +++ b/tsconfig.cjs.json @@ -1,9 +1,10 @@ { - "extends": "./tsconfig.build", + "extends": "./tsconfig", "compilerOptions": { "module": "commonjs", "outDir": "dist/cjs", "declaration": true, - "declarationDir": "dist/types" + "declarationMap": false, + "sourceMap": false } } diff --git a/tsconfig.esm.json b/tsconfig.esm.json index a7da90121..e34d1724a 100644 --- a/tsconfig.esm.json +++ b/tsconfig.esm.json @@ -1,9 +1,10 @@ { - "extends": "./tsconfig.build", + "extends": "./tsconfig", "compilerOptions": { - "declaration": true, - "declarationDir": "dist/types", + "declaration": false, + "declarationMap": false, + "sourceMap": false, "module": "esnext", - "outDir": "dist/esm" + "outDir": "./dist/esm" } } diff --git a/tsconfig.json b/tsconfig.json index e5d8f227a..3c6de7205 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,27 +1,13 @@ { "compilerOptions": { - "esModuleInterop": true, + "target": "esnext", + "module": "esnext", "moduleResolution": "node", - "lib": [ - "es2019", - "dom" - ], - "outDir": "./dist", + "esModuleInterop": true, "resolveJsonModule": true, "noImplicitAny": false, - "sourceMap": true, "skipLibCheck": true, - "target": "es2019", "strictNullChecks": true }, - "include": [ - "ts/client/src", - "ts/client/src/scripts", - "ts/client/src/debug-scripts", - "ts/client/src/deployment-scripts" - ], - "exclude": [ - "./ts/**/*.test.js", - "node_modules", - ] -} \ No newline at end of file + "include": ["ts/client/src"] +} diff --git a/tsconfig.types.json b/tsconfig.types.json new file mode 100644 index 000000000..982e90f2d --- /dev/null +++ b/tsconfig.types.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig", + "compilerOptions": { + "outDir": "./dist/types", + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true + } +} diff --git a/yarn.lock b/yarn.lock index afc066bd2..03cbd6c69 100644 --- a/yarn.lock +++ b/yarn.lock @@ -192,27 +192,6 @@ snake-case "^3.0.4" toml "^3.0.0" -"@project-serum/anchor@^0.25.0": - version "0.25.0" - resolved "https://registry.npmjs.org/@project-serum/anchor/-/anchor-0.25.0.tgz" - integrity sha512-E6A5Y/ijqpfMJ5psJvbw0kVTzLZFUcOFgs6eSM2M2iWE1lVRF18T6hWZVNl6zqZsoz98jgnNHtVGJMs+ds9A7A== - dependencies: - "@project-serum/borsh" "^0.2.5" - "@solana/web3.js" "^1.36.0" - base64-js "^1.5.1" - bn.js "^5.1.2" - bs58 "^4.0.1" - buffer-layout "^1.2.2" - camelcase "^5.3.1" - cross-fetch "^3.1.5" - crypto-hash "^1.3.0" - eventemitter3 "^4.0.7" - js-sha256 "^0.9.0" - pako "^2.0.3" - snake-case "^3.0.4" - superstruct "^0.15.4" - toml "^3.0.0" - "@project-serum/borsh@^0.2.2", "@project-serum/borsh@^0.2.5": version "0.2.5" resolved "https://registry.npmjs.org/@project-serum/borsh/-/borsh-0.2.5.tgz" @@ -221,9 +200,9 @@ bn.js "^5.1.2" buffer-layout "^1.2.0" -"@project-serum/serum@^0.13.65": +"@project-serum/serum@0.13.65": version "0.13.65" - resolved "https://registry.npmjs.org/@project-serum/serum/-/serum-0.13.65.tgz" + resolved "https://registry.yarnpkg.com/@project-serum/serum/-/serum-0.13.65.tgz#6d3cf07912f13985765237f053cca716fe84b0b0" integrity sha512-BHRqsTqPSfFB5p+MgI2pjvMBAQtO8ibTK2fYY96boIFkCI3TTwXDt2gUmspeChKO2pqHr5aKevmexzAcXxrSRA== dependencies: "@project-serum/anchor" "^0.11.1" @@ -242,7 +221,7 @@ "@solana/buffer-layout-utils@^0.2.0": version "0.2.0" - resolved "https://registry.npmjs.org/@solana/buffer-layout-utils/-/buffer-layout-utils-0.2.0.tgz" + resolved "https://registry.yarnpkg.com/@solana/buffer-layout-utils/-/buffer-layout-utils-0.2.0.tgz#b45a6cab3293a2eb7597cceb474f229889d875ca" integrity sha512-szG4sxgJGktbuZYDg2FfNmkMi0DYQoVjN2h7ta1W1hPrwzarcFLBq9UpX1UjNXsNpT9dn+chgprtWGioUAr4/g== dependencies: "@solana/buffer-layout" "^4.0.0" @@ -278,27 +257,6 @@ buffer-layout "^1.2.0" dotenv "10.0.0" -"@solana/web3.js@1.63.1", "@solana/web3.js@^1.36.0": - version "1.63.1" - resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-1.63.1.tgz#88a19a17f5f4aada73ad70a94044c1067cab2b4d" - integrity sha512-wgEdGVK5FTS2zENxbcGSvKpGZ0jDS6BUdGu8Gn6ns0CzgJkK83u4ip3THSnBPEQ5i/jrqukg998BwV1H67+qiQ== - dependencies: - "@babel/runtime" "^7.12.5" - "@noble/ed25519" "^1.7.0" - "@noble/hashes" "^1.1.2" - "@noble/secp256k1" "^1.6.3" - "@solana/buffer-layout" "^4.0.0" - bigint-buffer "^1.1.5" - bn.js "^5.0.0" - borsh "^0.7.0" - bs58 "^4.0.1" - buffer "6.0.1" - fast-stable-stringify "^1.0.0" - jayson "^3.4.4" - node-fetch "2" - rpc-websockets "^7.5.0" - superstruct "^0.14.2" - "@solana/web3.js@^1.17.0", "@solana/web3.js@^1.21.0": version "1.51.0" resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-1.51.0.tgz#51b28b5332f1f03ea25bea6c229869e33aebc507" @@ -322,29 +280,7 @@ superstruct "^0.14.2" tweetnacl "^1.0.3" -"@solana/web3.js@^1.32.0": - version "1.47.3" - resolved "https://registry.npmjs.org/@solana/web3.js/-/web3.js-1.47.3.tgz" - integrity sha512-TQJulaN/+b0xXq5EhQAYFwVyOORxSyVJn1EiXupClZm8DY7f9EeUG6vl0FzSAgwEAwXKsgK3sVs/3px2e7H7dQ== - dependencies: - "@babel/runtime" "^7.12.5" - "@ethersproject/sha2" "^5.5.0" - "@solana/buffer-layout" "^4.0.0" - bigint-buffer "^1.1.5" - bn.js "^5.0.0" - borsh "^0.7.0" - bs58 "^4.0.1" - buffer "6.0.1" - fast-stable-stringify "^1.0.0" - jayson "^3.4.4" - js-sha3 "^0.8.0" - node-fetch "2" - rpc-websockets "^7.5.0" - secp256k1 "^4.0.2" - superstruct "^0.14.2" - tweetnacl "^1.0.0" - -"@solana/web3.js@^1.63.1", "@solana/web3.js@^1.68.0": +"@solana/web3.js@^1.32.0", "@solana/web3.js@^1.68.0", "@solana/web3.js@^1.73.2": version "1.73.2" resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-1.73.2.tgz#4b30cd402b35733dae3a7d0b638be26a7742b395" integrity sha512-9WACF8W4Nstj7xiDw3Oom22QmrhBh0VyZyZ7JvvG3gOxLWLlX3hvm5nPVJOGcCE/9fFavBbCUb5A6CIuvMGdoA== @@ -366,6 +302,27 @@ rpc-websockets "^7.5.0" superstruct "^0.14.2" +"@solana/web3.js@^1.36.0": + version "1.63.1" + resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-1.63.1.tgz#88a19a17f5f4aada73ad70a94044c1067cab2b4d" + integrity sha512-wgEdGVK5FTS2zENxbcGSvKpGZ0jDS6BUdGu8Gn6ns0CzgJkK83u4ip3THSnBPEQ5i/jrqukg998BwV1H67+qiQ== + dependencies: + "@babel/runtime" "^7.12.5" + "@noble/ed25519" "^1.7.0" + "@noble/hashes" "^1.1.2" + "@noble/secp256k1" "^1.6.3" + "@solana/buffer-layout" "^4.0.0" + bigint-buffer "^1.1.5" + bn.js "^5.0.0" + borsh "^0.7.0" + bs58 "^4.0.1" + buffer "6.0.1" + fast-stable-stringify "^1.0.0" + jayson "^3.4.4" + node-fetch "2" + rpc-websockets "^7.5.0" + superstruct "^0.14.2" + "@switchboard-xyz/sbv2-lite@^0.1.6": version "0.1.6" resolved "https://registry.yarnpkg.com/@switchboard-xyz/sbv2-lite/-/sbv2-lite-0.1.6.tgz#dc3fbb5b3b028dbd3c688b991bcc48a670131ddb" @@ -379,6 +336,13 @@ resolved "https://registry.npmjs.org/@tsconfig/recommended/-/recommended-1.0.1.tgz" integrity sha512-2xN+iGTbPBEzGSnVp/Hd64vKJCJWxsi9gfs88x4PPMyEjHJoA3o5BY9r5OLPHIZU2pAQxkSAsJFqn6itClP8mQ== +"@types/bn.js@^5.1.1": + version "5.1.1" + resolved "https://registry.yarnpkg.com/@types/bn.js/-/bn.js-5.1.1.tgz#b51e1b55920a4ca26e9285ff79936bbdec910682" + integrity sha512-qNrYbZqMx0uJAfKnKclPh+dTwK33KfLHYqtyODwd5HnXOjnkhc4qgn3BrK6RWyGZm5+sIFE7Q7Vz6QQtJB7w7g== + dependencies: + "@types/node" "*" + "@types/bs58@^4.0.1": version "4.0.1" resolved "https://registry.npmjs.org/@types/bs58/-/bs58-4.0.1.tgz" @@ -683,9 +647,9 @@ bignumber.js@^9.0.0: integrity sha512-4LwHK4nfDOraBCtst+wOWIHbu1vhvAPJK8g8nROd4iuc3PSEjWif/qwbkh8jwCJz6yDBvtU4KPynETgrfh7y3A== bignumber.js@^9.0.1: - version "9.0.2" - resolved "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.2.tgz" - integrity sha512-GAcQvbpsM0pUb0zw1EI0KhQEZ+lRwR5fYaAp3vPOYuP7aDvGy6cVN6XHLauvF8SOga2y0dcLcjt3iQDTSEliyw== + version "9.1.1" + resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-9.1.1.tgz#c4df7dc496bd849d4c9464344c1aa74228b4dac6" + integrity sha512-pHm4LsMJ6lzgNGVfZHjMoO8sdoRhOzOH4MLmY65Jg70bpxCKu5iOHNJyfF6OyvYw7t8Fpf35RuzUyqnQsj8Vig== binance-api-node@^0.12.0: version "0.12.0" @@ -2303,7 +2267,7 @@ tsutils@^3.21.0: dependencies: tslib "^1.8.1" -tweetnacl@^1.0.0, tweetnacl@^1.0.3: +tweetnacl@^1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-1.0.3.tgz#ac0af71680458d8a6378d0d0d050ab1407d35596" integrity sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw== @@ -2336,10 +2300,10 @@ typedoc@^0.22.5: minimatch "^3.0.4" shiki "^0.10.0" -typescript@^4.4.4: - version "4.6.3" - resolved "https://registry.npmjs.org/typescript/-/typescript-4.6.3.tgz" - integrity sha512-yNIatDa5iaofVozS/uQJEl3JRWLKKGJKh6Yaiv0GLGSuhpFJe7P3SbHZ8/yjAHRQwKRoA6YZqlfjXWmVzoVSMw== +typescript@^4.8.4: + version "4.9.5" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.5.tgz#095979f9bcc0d09da324d58d03ce8f8374cbe65a" + integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g== uri-js@^4.2.2: version "4.4.1"