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
This commit is contained in:
tylersssss 2023-02-22 02:36:59 -05:00 committed by GitHub
parent f41f2ab337
commit 4c9f99832f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
47 changed files with 297 additions and 334 deletions

View File

@ -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',
);
});
});

View File

@ -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.
}
};

View File

@ -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"
}

View File

@ -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 =

View File

@ -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 =

View File

@ -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;

View File

@ -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);

View File

@ -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

View File

@ -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();
}

View File

@ -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

View File

@ -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.

View File

@ -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

View File

@ -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();
//

View File

@ -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

View File

@ -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);

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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();

View File

@ -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 =

View File

@ -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(

View File

@ -1,4 +1,4 @@
import { BN } from '@project-serum/anchor';
import { BN } from '@coral-xyz/anchor';
import {
PublicKey,
SystemProgram,

View File

@ -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 =

View File

@ -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 = {

View File

@ -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];
}),
);

View File

@ -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';

View File

@ -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,

View File

@ -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';

View File

@ -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';

View File

@ -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';

View File

@ -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,
),
);
}

View File

@ -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';

View File

@ -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 => {

View File

@ -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 };

View File

@ -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<T, R> = Omit<T, keyof R> & R;

View File

@ -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 {

View File

@ -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,

View File

@ -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;
}
}

View File

@ -1,7 +0,0 @@
{
"extends": "./tsconfig",
"compilerOptions": {
"skipLibCheck": true,
"skipDefaultLibCheck": true
}
}

View File

@ -1,9 +1,10 @@
{
"extends": "./tsconfig.build",
"extends": "./tsconfig",
"compilerOptions": {
"module": "commonjs",
"outDir": "dist/cjs",
"declaration": true,
"declarationDir": "dist/types"
"declarationMap": false,
"sourceMap": false
}
}

View File

@ -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"
}
}

View File

@ -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",
]
}
"include": ["ts/client/src"]
}

9
tsconfig.types.json Normal file
View File

@ -0,0 +1,9 @@
{
"extends": "./tsconfig",
"compilerOptions": {
"outDir": "./dist/types",
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true
}
}

116
yarn.lock
View File

@ -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"