Merge remote-tracking branch 'origin/main' into dev
This commit is contained in:
commit
662e2acc16
|
@ -1,24 +1,28 @@
|
|||
{
|
||||
"name": "@blockworks-foundation/mango-client",
|
||||
"version": "0.1.0",
|
||||
"name": "@blockworks-foundation/mango-v4",
|
||||
"version": "0.0.1",
|
||||
"description": "Typescript Client for mango-v4 program.",
|
||||
"main": "lib/src/index.js",
|
||||
"types": "lib/src/index.d.ts",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"repository": "https://github.com/blockworks-foundation/mango-v4",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"clean": "rm -rf dist",
|
||||
"example1-user": "ts-node src/scripts/example1-user.ts",
|
||||
"example1-admin": "ts-node src/scripts/example1-admin.ts",
|
||||
"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 .",
|
||||
"lint": "eslint . --ext ts --ext tsx --ext js --quiet",
|
||||
"type-check": "tsc --pretty --noEmit"
|
||||
"type-check": "tsc --pretty --noEmit",
|
||||
"prepare": "yarn build"
|
||||
},
|
||||
"author": {
|
||||
"name": "Blockworks Foundation",
|
||||
"email": "hello@blockworks.foundation",
|
||||
"url": "https://blockworks.foundation"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@tsconfig/recommended": "^1.0.1",
|
||||
"@types/chai": "^4.3.0",
|
||||
|
@ -36,6 +40,9 @@
|
|||
"typedoc": "^0.22.5",
|
||||
"typescript": "^4.4.4"
|
||||
},
|
||||
"resolutions": {
|
||||
"@types/bn.js": "^4.11.6"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
|
@ -9,6 +9,7 @@ export class Bank {
|
|||
public name: string;
|
||||
public depositIndex: I80F48;
|
||||
public borrowIndex: I80F48;
|
||||
public indexedTotalDeposits: I80F48;
|
||||
|
||||
static from(
|
||||
publicKey: PublicKey,
|
||||
|
@ -101,6 +102,7 @@ export class Bank {
|
|||
this.name = utf8.decode(new Uint8Array(name)).split('\x00')[0];
|
||||
this.depositIndex = I80F48.from(depositIndex);
|
||||
this.borrowIndex = I80F48.from(borrowIndex);
|
||||
this.indexedTotalDeposits = I80F48.from(indexedTotalDeposits);
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
|
|
|
@ -3,7 +3,7 @@ import { utf8 } from '@project-serum/anchor/dist/cjs/utils/bytes';
|
|||
import { PublicKey } from '@solana/web3.js';
|
||||
import { MangoClient } from '../client';
|
||||
import { Bank } from './bank';
|
||||
import { I80F48, I80F48Dto } from './I80F48';
|
||||
import { I80F48, I80F48Dto, ZERO_I80F48 } from './I80F48';
|
||||
export class MangoAccount {
|
||||
public tokens: TokenAccount[];
|
||||
public serum3: Serum3Account[];
|
||||
|
@ -79,12 +79,12 @@ export class MangoAccount {
|
|||
|
||||
getNativeDeposit(bank: Bank): I80F48 {
|
||||
const ta = this.findToken(bank.tokenIndex);
|
||||
return bank.depositIndex.mul(ta?.indexedValue!);
|
||||
return ta ? bank.depositIndex.mul(ta?.indexedValue) : ZERO_I80F48;
|
||||
}
|
||||
|
||||
getNativeBorrow(bank: Bank): I80F48 {
|
||||
const ta = this.findToken(bank.tokenIndex);
|
||||
return bank.borrowIndex.mul(ta?.indexedValue!);
|
||||
return ta ? bank.borrowIndex.mul(ta?.indexedValue) : ZERO_I80F48;
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
|
@ -133,6 +133,10 @@ export class TokenAccount {
|
|||
public tokenIndex: number,
|
||||
public inUseCount: number,
|
||||
) {}
|
||||
|
||||
isActive(): boolean {
|
||||
return this.tokenIndex !== 65535;
|
||||
}
|
||||
}
|
||||
|
||||
export class TokenAccountDto {
|
||||
|
|
|
@ -49,10 +49,8 @@ export class MangoClient {
|
|||
}
|
||||
|
||||
public async getGroup(groupPk: PublicKey): Promise<Group> {
|
||||
const group = Group.from(
|
||||
groupPk,
|
||||
await this.program.account.group.fetch(groupPk),
|
||||
);
|
||||
const groupAccount = await this.program.account.group.fetch(groupPk);
|
||||
const group = Group.from(groupPk, groupAccount);
|
||||
await group.reload(this);
|
||||
return group;
|
||||
}
|
||||
|
@ -807,10 +805,7 @@ export class MangoClient {
|
|||
|
||||
/// static
|
||||
|
||||
static async connect(
|
||||
provider: Provider,
|
||||
devnet?: boolean,
|
||||
): Promise<MangoClient> {
|
||||
static connect(provider?: Provider, devnet?: boolean): MangoClient {
|
||||
// TODO: use IDL on chain or in repository? decide...
|
||||
// Alternatively we could fetch IDL from chain.
|
||||
// const idl = await Program.fetchIdl(MANGO_V4_ID, provider);
|
||||
|
|
|
@ -8,3 +8,4 @@ export {
|
|||
export { StubOracle } from './accounts/oracle';
|
||||
export { Serum3Market } from './accounts/serum3';
|
||||
export * from './client';
|
||||
export * from './constants';
|
||||
|
|
|
@ -514,13 +514,26 @@ export type MangoV4 = {
|
|||
"name": "owner",
|
||||
"isMut": false,
|
||||
"isSigner": true
|
||||
},
|
||||
{
|
||||
"name": "tokenProgram",
|
||||
"isMut": false,
|
||||
"isSigner": false
|
||||
}
|
||||
],
|
||||
"args": [
|
||||
{
|
||||
"name": "banksLen",
|
||||
"name": "numHealthAccounts",
|
||||
"type": "u64"
|
||||
},
|
||||
{
|
||||
"name": "withdraws",
|
||||
"type": {
|
||||
"vec": {
|
||||
"defined": "(u8,u64)"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "cpiData",
|
||||
"type": "bytes"
|
||||
|
@ -1703,12 +1716,16 @@ export type MangoV4 = {
|
|||
"name": "tokenIndex",
|
||||
"type": "u16"
|
||||
},
|
||||
{
|
||||
"name": "bump",
|
||||
"type": "u8"
|
||||
},
|
||||
{
|
||||
"name": "reserved",
|
||||
"type": {
|
||||
"array": [
|
||||
"u8",
|
||||
6
|
||||
5
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -3354,13 +3371,26 @@ export const IDL: MangoV4 = {
|
|||
"name": "owner",
|
||||
"isMut": false,
|
||||
"isSigner": true
|
||||
},
|
||||
{
|
||||
"name": "tokenProgram",
|
||||
"isMut": false,
|
||||
"isSigner": false
|
||||
}
|
||||
],
|
||||
"args": [
|
||||
{
|
||||
"name": "banksLen",
|
||||
"name": "numHealthAccounts",
|
||||
"type": "u64"
|
||||
},
|
||||
{
|
||||
"name": "withdraws",
|
||||
"type": {
|
||||
"vec": {
|
||||
"defined": "(u8,u64)"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "cpiData",
|
||||
"type": "bytes"
|
||||
|
@ -4543,12 +4573,16 @@ export const IDL: MangoV4 = {
|
|||
"name": "tokenIndex",
|
||||
"type": "u16"
|
||||
},
|
||||
{
|
||||
"name": "bump",
|
||||
"type": "u8"
|
||||
},
|
||||
{
|
||||
"name": "reserved",
|
||||
"type": {
|
||||
"array": [
|
||||
"u8",
|
||||
6
|
||||
5
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"extends": "@tsconfig/recommended/tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist",
|
||||
"target": "es6",
|
||||
"lib": ["es2019"],
|
||||
"allowJs": true,
|
||||
"checkJs": true,
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"noImplicitAny": false,
|
||||
"resolveJsonModule": true,
|
||||
"sourceMap": true,
|
||||
"esModuleInterop": true
|
||||
},
|
||||
"include": ["./ts/**/*"],
|
||||
"exclude": ["./ts/**/*.test.js", "node_modules", "**/node_modules"]
|
||||
}
|
|
@ -255,6 +255,13 @@
|
|||
resolved "https://registry.yarnpkg.com/@tsconfig/recommended/-/recommended-1.0.1.tgz#7619bad397e06ead1c5182926c944e0ca6177f52"
|
||||
integrity sha512-2xN+iGTbPBEzGSnVp/Hd64vKJCJWxsi9gfs88x4PPMyEjHJoA3o5BY9r5OLPHIZU2pAQxkSAsJFqn6itClP8mQ==
|
||||
|
||||
"@types/bn.js@^4.11.6":
|
||||
version "4.11.6"
|
||||
resolved "https://registry.yarnpkg.com/@types/bn.js/-/bn.js-4.11.6.tgz#c306c70d9358aaea33cd4eda092a742b9505967c"
|
||||
integrity sha512-pqr857jrp2kPuO9uRjZ3PwnJTjoQy+fcdxvBTvHm6dkmEL9q+hDD/2j/0ELOBPtPnS8LjCX0gI9nbl8lVkadpg==
|
||||
dependencies:
|
||||
"@types/node" "*"
|
||||
|
||||
"@types/bs58@^4.0.1":
|
||||
version "4.0.1"
|
||||
resolved "https://registry.yarnpkg.com/@types/bs58/-/bs58-4.0.1.tgz#3d51222aab067786d3bc3740a84a7f5a0effaa37"
|
Loading…
Reference in New Issue