diff --git a/release-to-devnet.sh b/release-to-devnet.sh index 8a343a1fd..2f40658a0 100755 --- a/release-to-devnet.sh +++ b/release-to-devnet.sh @@ -13,7 +13,7 @@ anchor build --skip-lint ./idl-fixup.sh # 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 # publish program @@ -29,13 +29,4 @@ fi # build npm package -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 +(cd ./ts/client && tsc) diff --git a/ts/client/src/client.ts b/ts/client/src/client.ts index c2adc1ec2..705be5441 100644 --- a/ts/client/src/client.ts +++ b/ts/client/src/client.ts @@ -227,13 +227,13 @@ export class MangoClient { { memcmp: { bytes: group.publicKey.toBase58(), - offset: 24, + offset: 40, }, }, { memcmp: { bytes: ownerPk.toBase58(), - offset: 56, + offset: 72, }, }, ]) diff --git a/ts/client/src/constants.ts b/ts/client/src/constants.ts index 606b67541..cf2e46473 100644 --- a/ts/client/src/constants.ts +++ b/ts/client/src/constants.ts @@ -2,34 +2,6 @@ import { PublicKey } from '@solana/web3.js'; 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( 'DESVgJVGajEgKGXhb6XmqDHGz3VjdgP7rEVESBgxmroY', ); diff --git a/ts/client/src/example1-admin.ts b/ts/client/src/example1-admin.ts index f357adaf1..186b10045 100644 --- a/ts/client/src/example1-admin.ts +++ b/ts/client/src/example1-admin.ts @@ -2,12 +2,18 @@ import { Provider, Wallet } from '@project-serum/anchor'; import { Connection, Keypair, PublicKey } from '@solana/web3.js'; import fs from 'fs'; import { MangoClient } from './client'; -import { - DEVNET_MINTS, - DEVNET_ORACLES, - DEVNET_SERUM3_MARKETS, - DEVNET_SERUM3_PROGRAM_ID, -} from './constants'; +import { DEVNET_SERUM3_PROGRAM_ID } from './constants'; + +const DEVNET_SERUM3_MARKETS = new Map([ + ['BTC/USDC', 'DW83EpHFywBxCHmyARxwj3nzxJd7MUdSeznmrdzZKNZB'], +]); +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 @@ -59,6 +65,7 @@ async function main() { 1.4, 0.02, ); + await group.reload(client); } catch (error) {} // stub oracle + register token 1 @@ -86,11 +93,11 @@ async function main() { 1.4, 0.02, ); + await group.reload(client); } catch (error) {} // log tokens/banks - const banks = await client.getBanksForGroup(group); - for (const bank of banks) { + for (const bank of await group.banksMap.values()) { console.log( `Bank ${bank.tokenIndex} ${bank.publicKey}, mint ${bank.mint}, oracle ${bank.oracle}`, ); @@ -106,18 +113,16 @@ async function main() { group, DEVNET_SERUM3_PROGRAM_ID, serumMarketExternalPk, - banks[0], - banks[1], + group.banksMap.get('BTC')!, + group.banksMap.get('USDC')!, 0, 'BTC/USDC', ); } catch (error) {} const markets = await client.serum3GetMarket( group, - banks.find((bank) => bank.mint.toBase58() === DEVNET_MINTS.get('BTC')) - ?.tokenIndex, - banks.find((bank) => bank.mint.toBase58() === DEVNET_MINTS.get('USDC')) - ?.tokenIndex, + group.banksMap.get('BTC')?.tokenIndex, + group.banksMap.get('USDC')?.tokenIndex, ); console.log(`Serum3 market ${markets[0].publicKey}`); diff --git a/ts/client/src/example1-user.ts b/ts/client/src/example1-user.ts index 242becf9a..bff56ea22 100644 --- a/ts/client/src/example1-user.ts +++ b/ts/client/src/example1-user.ts @@ -1,5 +1,5 @@ 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 { Serum3OrderType, @@ -7,7 +7,7 @@ import { Serum3Side, } from './accounts/serum3'; 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 @@ -30,13 +30,14 @@ async function main() { console.log(`User ${userWallet.publicKey.toBase58()}`); // 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()}`); - for (const bank of group.banksMap.values()) { - console.log(bank.publicKey.toBase58()); - } - // create + fetch account const mangoAccount = await client.getOrCreateMangoAccount( group, diff --git a/ts/client/src/index.ts b/ts/client/src/index.ts index 4cdecd6a6..762b29351 100644 --- a/ts/client/src/index.ts +++ b/ts/client/src/index.ts @@ -1,10 +1,10 @@ -export { Group } from './client/accounts/group'; -export * from './client/accounts/I80F48'; +export { Group } from './accounts/group'; +export * from './accounts/I80F48'; export { MangoAccount, TokenAccount, TokenAccountDto, -} from './client/accounts/mangoAccount'; -export { StubOracle } from './client/accounts/oracle'; -export { Serum3Market } from './client/accounts/serum3'; -export * from './client/client'; +} from './accounts/mangoAccount'; +export { StubOracle } from './accounts/oracle'; +export { Serum3Market } from './accounts/serum3'; +export * from './client'; diff --git a/ts/client/src/mango_v4.ts b/ts/client/src/mango_v4.ts index dbc9d0ea8..65012a207 100644 --- a/ts/client/src/mango_v4.ts +++ b/ts/client/src/mango_v4.ts @@ -1569,7 +1569,7 @@ export type MangoV4 = { "type": { "array": [ "u8", - 16 + 32 ] } }, @@ -4085,7 +4085,7 @@ export const IDL: MangoV4 = { "type": { "array": [ "u8", - 16 + 32 ] } }, diff --git a/ts/client/tsconfig.json b/ts/client/tsconfig.json index 3dee67b50..4c7b94637 100644 --- a/ts/client/tsconfig.json +++ b/ts/client/tsconfig.json @@ -1,6 +1,5 @@ { "extends": "@tsconfig/recommended/tsconfig.json", - "compilerOptions": { "allowJs": true, "checkJs": true, @@ -8,7 +7,9 @@ "declarationDir": "dist", "declarationMap": true, "esModuleInterop": true, - "lib": ["es2019"], + "lib": [ + "es2019" + ], "noImplicitAny": false, "outDir": "dist", "resolveJsonModule": true, @@ -16,6 +17,12 @@ "strictNullChecks": true, "target": "es6" }, - "include": ["./ts/**/*"], - "exclude": ["./ts/**/*.test.js", "node_modules", "**/node_modules"] -} + "include": [ + "./src/**/*" + ], + "exclude": [ + "./src/**/*.test.js", + "node_modules", + "**/node_modules" + ] +} \ No newline at end of file diff --git a/update-local-idl.sh b/update-local-idl.sh index a1759ba19..c3cefcc03 100755 --- a/update-local-idl.sh +++ b/update-local-idl.sh @@ -4,5 +4,4 @@ set -e pipefail anchor build --skip-lint ./idl-fixup.sh -cp -v ./target/types/mango_v4.ts ./ts/mango_v4.ts -tsc \ No newline at end of file +cp -v ./target/types/mango_v4.ts ./ts/client/src/mango_v4.ts