Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
microwavedcola1 2022-04-13 08:48:35 +02:00
parent b56fd46721
commit c63d860bc1
9 changed files with 52 additions and 77 deletions

View File

@ -13,7 +13,7 @@ anchor build --skip-lint
./idl-fixup.sh ./idl-fixup.sh
# update types in ts client package # update types in ts client package
cp -v ./target/types/mango_v4.ts ./ts/mango_v4.ts cp -v ./target/types/mango_v4.ts ./ts/client/src/mango_v4.ts
if [[ -z "${NO_DEPLOY}" ]]; then if [[ -z "${NO_DEPLOY}" ]]; then
# publish program # publish program
@ -29,13 +29,4 @@ fi
# build npm package # build npm package
tsc (cd ./ts/client && tsc)
# yarn clean && yarn build && cp package.json ./dist/
# publish the npm package
# yarn publish dist
# echo
# echo Remember to commit and push the version update as well as the changes
# echo to ts/mango_v4.tx.
# echo

View File

@ -227,13 +227,13 @@ export class MangoClient {
{ {
memcmp: { memcmp: {
bytes: group.publicKey.toBase58(), bytes: group.publicKey.toBase58(),
offset: 24, offset: 40,
}, },
}, },
{ {
memcmp: { memcmp: {
bytes: ownerPk.toBase58(), bytes: ownerPk.toBase58(),
offset: 56, offset: 72,
}, },
}, },
]) ])

View File

@ -2,34 +2,6 @@ import { PublicKey } from '@solana/web3.js';
export const DEVNET_GROUP = 'NDLmPdjzm7Tm3gnsZw8EoBbBTR7wfAcyDY8LCqFSGtX'; export const DEVNET_GROUP = 'NDLmPdjzm7Tm3gnsZw8EoBbBTR7wfAcyDY8LCqFSGtX';
export const DEVNET_MINTS = new Map([
['USDC', '8FRFC6MoGGkMFQwngccyu69VnYbzykGeez7ignHVAFSN'],
['BTC', '3UNBZ6o52WTWwjac2kPUb4FyodhU1vFkRJheu1Sh2TvU'],
]);
export const DEVNET_MINTS_REVERSE = Array.from(DEVNET_MINTS.entries()).reduce(
function (map, obj) {
map[obj[1]] = obj[0];
return map;
},
{},
);
export const DEVNET_ORACLES = new Map([
['BTC', 'HovQMDrbAgAYPCmHVSrezcSmkMtXSSUsLDFANExrZh2J'],
]);
export const DEVNET_SERUM3_MARKETS = new Map([
['BTC/USDC', 'DW83EpHFywBxCHmyARxwj3nzxJd7MUdSeznmrdzZKNZB'],
]);
export const DEVNET_SERUM3_MARKETS_REVERSE = Array.from(
DEVNET_SERUM3_MARKETS.entries(),
).reduce(function (map, obj) {
map[obj[1]] = obj[0];
return map;
}, {});
export const DEVNET_SERUM3_PROGRAM_ID = new PublicKey( export const DEVNET_SERUM3_PROGRAM_ID = new PublicKey(
'DESVgJVGajEgKGXhb6XmqDHGz3VjdgP7rEVESBgxmroY', 'DESVgJVGajEgKGXhb6XmqDHGz3VjdgP7rEVESBgxmroY',
); );

View File

@ -2,12 +2,18 @@ import { Provider, Wallet } from '@project-serum/anchor';
import { Connection, Keypair, PublicKey } from '@solana/web3.js'; import { Connection, Keypair, PublicKey } from '@solana/web3.js';
import fs from 'fs'; import fs from 'fs';
import { MangoClient } from './client'; import { MangoClient } from './client';
import { import { DEVNET_SERUM3_PROGRAM_ID } from './constants';
DEVNET_MINTS,
DEVNET_ORACLES, const DEVNET_SERUM3_MARKETS = new Map([
DEVNET_SERUM3_MARKETS, ['BTC/USDC', 'DW83EpHFywBxCHmyARxwj3nzxJd7MUdSeznmrdzZKNZB'],
DEVNET_SERUM3_PROGRAM_ID, ]);
} from './constants'; const DEVNET_MINTS = new Map([
['USDC', '8FRFC6MoGGkMFQwngccyu69VnYbzykGeez7ignHVAFSN'],
['BTC', '3UNBZ6o52WTWwjac2kPUb4FyodhU1vFkRJheu1Sh2TvU'],
]);
const DEVNET_ORACLES = new Map([
['BTC', 'HovQMDrbAgAYPCmHVSrezcSmkMtXSSUsLDFANExrZh2J'],
]);
// //
// An example for admins based on high level api i.e. the client // An example for admins based on high level api i.e. the client
@ -59,6 +65,7 @@ async function main() {
1.4, 1.4,
0.02, 0.02,
); );
await group.reload(client);
} catch (error) {} } catch (error) {}
// stub oracle + register token 1 // stub oracle + register token 1
@ -86,11 +93,11 @@ async function main() {
1.4, 1.4,
0.02, 0.02,
); );
await group.reload(client);
} catch (error) {} } catch (error) {}
// log tokens/banks // log tokens/banks
const banks = await client.getBanksForGroup(group); for (const bank of await group.banksMap.values()) {
for (const bank of banks) {
console.log( console.log(
`Bank ${bank.tokenIndex} ${bank.publicKey}, mint ${bank.mint}, oracle ${bank.oracle}`, `Bank ${bank.tokenIndex} ${bank.publicKey}, mint ${bank.mint}, oracle ${bank.oracle}`,
); );
@ -106,18 +113,16 @@ async function main() {
group, group,
DEVNET_SERUM3_PROGRAM_ID, DEVNET_SERUM3_PROGRAM_ID,
serumMarketExternalPk, serumMarketExternalPk,
banks[0], group.banksMap.get('BTC')!,
banks[1], group.banksMap.get('USDC')!,
0, 0,
'BTC/USDC', 'BTC/USDC',
); );
} catch (error) {} } catch (error) {}
const markets = await client.serum3GetMarket( const markets = await client.serum3GetMarket(
group, group,
banks.find((bank) => bank.mint.toBase58() === DEVNET_MINTS.get('BTC')) group.banksMap.get('BTC')?.tokenIndex,
?.tokenIndex, group.banksMap.get('USDC')?.tokenIndex,
banks.find((bank) => bank.mint.toBase58() === DEVNET_MINTS.get('USDC'))
?.tokenIndex,
); );
console.log(`Serum3 market ${markets[0].publicKey}`); console.log(`Serum3 market ${markets[0].publicKey}`);

View File

@ -1,5 +1,5 @@
import { Provider, Wallet } from '@project-serum/anchor'; import { Provider, Wallet } from '@project-serum/anchor';
import { Connection, Keypair, PublicKey } from '@solana/web3.js'; import { Connection, Keypair } from '@solana/web3.js';
import fs from 'fs'; import fs from 'fs';
import { import {
Serum3OrderType, Serum3OrderType,
@ -7,7 +7,7 @@ import {
Serum3Side, Serum3Side,
} from './accounts/serum3'; } from './accounts/serum3';
import { MangoClient } from './client'; import { MangoClient } from './client';
import { DEVNET_GROUP, DEVNET_SERUM3_PROGRAM_ID } from './constants'; import { DEVNET_SERUM3_PROGRAM_ID } from './constants';
// //
// An example for users based on high level api i.e. the client // An example for users based on high level api i.e. the client
@ -30,13 +30,14 @@ async function main() {
console.log(`User ${userWallet.publicKey.toBase58()}`); console.log(`User ${userWallet.publicKey.toBase58()}`);
// fetch group // fetch group
const group = await client.getGroup(new PublicKey(DEVNET_GROUP)); const admin = Keypair.fromSecretKey(
Buffer.from(
JSON.parse(fs.readFileSync(process.env.ADMIN_KEYPAIR!, 'utf-8')),
),
);
const group = await client.getGroupForAdmin(admin.publicKey);
console.log(`Group ${group.publicKey.toBase58()}`); console.log(`Group ${group.publicKey.toBase58()}`);
for (const bank of group.banksMap.values()) {
console.log(bank.publicKey.toBase58());
}
// create + fetch account // create + fetch account
const mangoAccount = await client.getOrCreateMangoAccount( const mangoAccount = await client.getOrCreateMangoAccount(
group, group,

View File

@ -1,10 +1,10 @@
export { Group } from './client/accounts/group'; export { Group } from './accounts/group';
export * from './client/accounts/I80F48'; export * from './accounts/I80F48';
export { export {
MangoAccount, MangoAccount,
TokenAccount, TokenAccount,
TokenAccountDto, TokenAccountDto,
} from './client/accounts/mangoAccount'; } from './accounts/mangoAccount';
export { StubOracle } from './client/accounts/oracle'; export { StubOracle } from './accounts/oracle';
export { Serum3Market } from './client/accounts/serum3'; export { Serum3Market } from './accounts/serum3';
export * from './client/client'; export * from './client';

View File

@ -1569,7 +1569,7 @@ export type MangoV4 = {
"type": { "type": {
"array": [ "array": [
"u8", "u8",
16 32
] ]
} }
}, },
@ -4085,7 +4085,7 @@ export const IDL: MangoV4 = {
"type": { "type": {
"array": [ "array": [
"u8", "u8",
16 32
] ]
} }
}, },

View File

@ -1,6 +1,5 @@
{ {
"extends": "@tsconfig/recommended/tsconfig.json", "extends": "@tsconfig/recommended/tsconfig.json",
"compilerOptions": { "compilerOptions": {
"allowJs": true, "allowJs": true,
"checkJs": true, "checkJs": true,
@ -8,7 +7,9 @@
"declarationDir": "dist", "declarationDir": "dist",
"declarationMap": true, "declarationMap": true,
"esModuleInterop": true, "esModuleInterop": true,
"lib": ["es2019"], "lib": [
"es2019"
],
"noImplicitAny": false, "noImplicitAny": false,
"outDir": "dist", "outDir": "dist",
"resolveJsonModule": true, "resolveJsonModule": true,
@ -16,6 +17,12 @@
"strictNullChecks": true, "strictNullChecks": true,
"target": "es6" "target": "es6"
}, },
"include": ["./ts/**/*"], "include": [
"exclude": ["./ts/**/*.test.js", "node_modules", "**/node_modules"] "./src/**/*"
} ],
"exclude": [
"./src/**/*.test.js",
"node_modules",
"**/node_modules"
]
}

View File

@ -4,5 +4,4 @@ set -e pipefail
anchor build --skip-lint anchor build --skip-lint
./idl-fixup.sh ./idl-fixup.sh
cp -v ./target/types/mango_v4.ts ./ts/mango_v4.ts cp -v ./target/types/mango_v4.ts ./ts/client/src/mango_v4.ts
tsc