Update mango-client, add testnet configs
This commit is contained in:
parent
e4c140fe90
commit
472c098a5b
|
@ -0,0 +1,2 @@
|
|||
mm-1: PARAMS=testnet.json yarn mm
|
||||
mm-2: PARAMS=testnet2.json yarn mm
|
22
package.json
22
package.json
|
@ -11,7 +11,6 @@
|
|||
"format": "prettier --check ."
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tsconfig/recommended": "^1.0.1",
|
||||
"@types/big.js": "^6.1.1",
|
||||
"@types/bn.js": "^5.1.0",
|
||||
"@types/chai": "^4.2.14",
|
||||
|
@ -27,9 +26,8 @@
|
|||
"eslint-config-prettier": "^7.2.0",
|
||||
"mocha": "^8.4.0",
|
||||
"prettier": "^2.0.5",
|
||||
"ts-node": "^9.1.1",
|
||||
"typedoc": "^0.22.5",
|
||||
"typescript": "^4.1.3"
|
||||
"typescript": "^4.6.3"
|
||||
},
|
||||
"files": [
|
||||
"lib"
|
||||
|
@ -39,25 +37,21 @@
|
|||
"trailingComma": "all"
|
||||
},
|
||||
"dependencies": {
|
||||
"@blockworks-foundation/mango-client": "git+https://github.com/blockworks-foundation/mango-client-v3.git",
|
||||
"@project-serum/anchor": "^0.16.2",
|
||||
"@project-serum/serum": "0.13.55",
|
||||
"@blockworks-foundation/mango-client": "^3.6.2",
|
||||
"@project-serum/anchor": "^0.21.0",
|
||||
"@project-serum/sol-wallet-adapter": "^0.2.0",
|
||||
"@solana/spl-token": "^0.1.6",
|
||||
"@solana/web3.js": "1.31.0",
|
||||
"@solana/web3.js": "^1.43.5",
|
||||
"@tsconfig/recommended": "^1.0.1",
|
||||
"axios": "^0.21.1",
|
||||
"big.js": "^6.1.1",
|
||||
"bigint-buffer": "^1.1.5",
|
||||
"bn.js": "^5.2.0",
|
||||
"bn.js": "^5.1.0",
|
||||
"buffer-layout": "^1.2.1",
|
||||
"crypto-js": "^4.1.1",
|
||||
"dotenv": "^10.0.0",
|
||||
"dotenv-expand": "^5.1.0",
|
||||
"tardis-dev": "^13.1.3"
|
||||
},
|
||||
"resolutions": {
|
||||
"bn.js": "5.1.3",
|
||||
"@types/bn.js": "5.1.0",
|
||||
"@solana/web3.js": "^1.31.0"
|
||||
"tardis-dev": "^13.1.3",
|
||||
"ts-node": "^10.7.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,102 @@
|
|||
{
|
||||
"group": "testnet.0",
|
||||
"mangoAccountName": "MM",
|
||||
"mangoAccountPubkey": "optional pubkey string if your mango account doesn't have name",
|
||||
"interval": 1000,
|
||||
"batch": 2,
|
||||
"assets": {
|
||||
"MNGO": {
|
||||
"perp": {
|
||||
"sizePerc": 0.01,
|
||||
"leanCoeff": 0.0010,
|
||||
"bias": 0.0,
|
||||
"requoteThresh": 0.0002,
|
||||
"takeSpammers": true,
|
||||
"spammerCharge": 2,
|
||||
"ftxSize": 10000
|
||||
}
|
||||
},
|
||||
|
||||
"BTC": {
|
||||
"perp": {
|
||||
"sizePerc": 0.05,
|
||||
"leanCoeff": 0.00025,
|
||||
"bias": 0.0,
|
||||
"requoteThresh": 0.0002,
|
||||
"takeSpammers": true,
|
||||
"spammerCharge": 2
|
||||
}
|
||||
},
|
||||
"ETH": {
|
||||
"perp": {
|
||||
"sizePerc": 0.05,
|
||||
"leanCoeff": 0.000375,
|
||||
"bias": 0.0,
|
||||
"requoteThresh": 0.0002,
|
||||
"takeSpammers": true,
|
||||
"spammerCharge": 2
|
||||
}
|
||||
},
|
||||
|
||||
"SOL": {
|
||||
"perp": {
|
||||
"sizePerc": 0.05,
|
||||
"leanCoeff": 0.0005,
|
||||
"bias": 0.0,
|
||||
"requoteThresh": 0.0002,
|
||||
"takeSpammers": true,
|
||||
"spammerCharge": 2
|
||||
}
|
||||
},
|
||||
"SRM": {
|
||||
"perp": {
|
||||
"sizePerc": 0.02,
|
||||
"leanCoeff": 0.0010,
|
||||
"bias": 0.0,
|
||||
"requoteThresh": 0.0002,
|
||||
"takeSpammers": true,
|
||||
"spammerCharge": 2
|
||||
}
|
||||
},
|
||||
"RAY": {
|
||||
"perp": {
|
||||
"sizePerc": 0.015,
|
||||
"leanCoeff": 0.00075,
|
||||
"bias": 0.0,
|
||||
"requoteThresh": 0.0002,
|
||||
"takeSpammers": true,
|
||||
"spammerCharge": 2
|
||||
}
|
||||
},
|
||||
"FTT": {
|
||||
"perp": {
|
||||
"sizePerc": 0.02,
|
||||
"leanCoeff": 0.0005,
|
||||
"bias": 0.0,
|
||||
"requoteThresh": 0.0002,
|
||||
"takeSpammers": true,
|
||||
"spammerCharge": 2
|
||||
}
|
||||
},
|
||||
"AVAX": {
|
||||
"perp": {
|
||||
"sizePerc": 0.02,
|
||||
"leanCoeff": 0.0005,
|
||||
"bias": 0.0,
|
||||
"requoteThresh": 0.0002,
|
||||
"takeSpammers": true,
|
||||
"spammerCharge": 2
|
||||
}
|
||||
},
|
||||
"GMT": {
|
||||
"perp": {
|
||||
"sizePerc": 0.02,
|
||||
"leanCoeff": 0.0005,
|
||||
"bias": 0.0,
|
||||
"requoteThresh": 0.0002,
|
||||
"takeSpammers": true,
|
||||
"spammerCharge": 2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
{
|
||||
"group": "testnet.0",
|
||||
"mangoAccountName": "MM2",
|
||||
"mangoAccountPubkey": "optional pubkey string if your mango account doesn't have name",
|
||||
"interval": 500,
|
||||
"batch": 2,
|
||||
"assets": {
|
||||
"MNGO": {
|
||||
"perp": {
|
||||
"sizePerc": 0.01,
|
||||
"leanCoeff": 0.0010,
|
||||
"bias": 0.0,
|
||||
"requoteThresh": 0.0002,
|
||||
"takeSpammers": true,
|
||||
"spammerCharge": 2,
|
||||
"ftxSize": 10000,
|
||||
"charge": 0.0020
|
||||
}
|
||||
},
|
||||
|
||||
"BTC": {
|
||||
"perp": {
|
||||
"sizePerc": 0.05,
|
||||
"leanCoeff": 0.00025,
|
||||
"bias": 0.0,
|
||||
"requoteThresh": 0.0002,
|
||||
"takeSpammers": true,
|
||||
"spammerCharge": 2,
|
||||
"charge": 0.0020
|
||||
}
|
||||
},
|
||||
"ETH": {
|
||||
"perp": {
|
||||
"sizePerc": 0.05,
|
||||
"leanCoeff": 0.000375,
|
||||
"bias": 0.0,
|
||||
"requoteThresh": 0.0002,
|
||||
"takeSpammers": true,
|
||||
"spammerCharge": 2,
|
||||
"charge": 0.0020
|
||||
}
|
||||
},
|
||||
|
||||
"SOL": {
|
||||
"perp": {
|
||||
"sizePerc": 0.05,
|
||||
"leanCoeff": 0.0005,
|
||||
"bias": 0.0,
|
||||
"requoteThresh": 0.0002,
|
||||
"takeSpammers": true,
|
||||
"spammerCharge": 2,
|
||||
"charge": 0.0020
|
||||
}
|
||||
},
|
||||
"SRM": {
|
||||
"perp": {
|
||||
"sizePerc": 0.02,
|
||||
"leanCoeff": 0.0010,
|
||||
"bias": 0.0,
|
||||
"requoteThresh": 0.0002,
|
||||
"takeSpammers": true,
|
||||
"spammerCharge": 2,
|
||||
"charge": 0.0020
|
||||
}
|
||||
},
|
||||
"RAY": {
|
||||
"perp": {
|
||||
"sizePerc": 0.015,
|
||||
"leanCoeff": 0.00075,
|
||||
"bias": 0.0,
|
||||
"requoteThresh": 0.0002,
|
||||
"takeSpammers": true,
|
||||
"spammerCharge": 2,
|
||||
"charge": 0.0020
|
||||
}
|
||||
},
|
||||
"FTT": {
|
||||
"perp": {
|
||||
"sizePerc": 0.02,
|
||||
"leanCoeff": 0.0005,
|
||||
"bias": 0.0,
|
||||
"requoteThresh": 0.0002,
|
||||
"takeSpammers": true,
|
||||
"spammerCharge": 2,
|
||||
"charge": 0.0020
|
||||
}
|
||||
},
|
||||
"AVAX": {
|
||||
"perp": {
|
||||
"sizePerc": 0.02,
|
||||
"leanCoeff": 0.0005,
|
||||
"bias": 0.0,
|
||||
"requoteThresh": 0.0002,
|
||||
"takeSpammers": true,
|
||||
"spammerCharge": 2,
|
||||
"charge": 0.0020
|
||||
}
|
||||
},
|
||||
"GMT": {
|
||||
"perp": {
|
||||
"sizePerc": 0.02,
|
||||
"leanCoeff": 0.0005,
|
||||
"bias": 0.0,
|
||||
"requoteThresh": 0.0002,
|
||||
"takeSpammers": true,
|
||||
"spammerCharge": 2,
|
||||
"charge": 0.0020
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
24
src/mm.ts
24
src/mm.ts
|
@ -2,6 +2,7 @@ import {
|
|||
Account,
|
||||
Commitment,
|
||||
Connection,
|
||||
Keypair,
|
||||
PublicKey,
|
||||
Transaction,
|
||||
TransactionInstruction,
|
||||
|
@ -35,6 +36,7 @@ import {
|
|||
PerpMarketConfig,
|
||||
sleep,
|
||||
zeroKey,
|
||||
Payer,
|
||||
} from '@blockworks-foundation/mango-client';
|
||||
import { OpenOrders } from '@project-serum/serum';
|
||||
import path from 'path';
|
||||
|
@ -43,7 +45,7 @@ import {
|
|||
loadMangoAccountWithPubkey,
|
||||
makeCheckAndSetSequenceNumberInstruction,
|
||||
makeInitSequenceInstruction,
|
||||
seqEnforcerProgramId,
|
||||
seqEnforcerProgramIds,
|
||||
listenersArray,
|
||||
} from './utils';
|
||||
import { findProgramAddressSync } from '@project-serum/anchor/dist/cjs/utils/pubkey';
|
||||
|
@ -56,13 +58,15 @@ const params = JSON.parse(
|
|||
),
|
||||
);
|
||||
|
||||
const payer = new Account(
|
||||
const payer = Keypair.fromSecretKey(
|
||||
Uint8Array.from(
|
||||
JSON.parse(
|
||||
fs.readFileSync(
|
||||
process.env.KEYPAIR || os.homedir() + '/.config/solana/id.json',
|
||||
process.env.KEYPAIR || fs.readFileSync(
|
||||
process.env.KEYPAIR_FILE || os.homedir() + '/.config/solana/id.json',
|
||||
'utf-8',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
const config = new Config(IDS);
|
||||
|
@ -205,6 +209,7 @@ async function initSeqEnfAccounts(
|
|||
payer.publicKey,
|
||||
mc.sequenceAccountBump,
|
||||
mc.marketName,
|
||||
cluster,
|
||||
),
|
||||
);
|
||||
const seqAccTx = new Transaction();
|
||||
|
@ -275,7 +280,7 @@ async function fullMarketMaker() {
|
|||
|
||||
const [sequenceAccount, sequenceAccountBump] = findProgramAddressSync(
|
||||
[new Buffer(perpMarketConfig.name, 'utf-8'), payer.publicKey.toBytes()],
|
||||
seqEnforcerProgramId,
|
||||
seqEnforcerProgramIds[cluster],
|
||||
);
|
||||
|
||||
const perpMarket = perpMarkets.find((pm) =>
|
||||
|
@ -374,7 +379,7 @@ async function fullMarketMaker() {
|
|||
j++;
|
||||
if (j === params.batch) {
|
||||
// sendDupTxs(client, tx, [], 10);
|
||||
client.sendTransaction(tx, payer, [], null);
|
||||
client.sendTransaction(tx, payer, []);
|
||||
tx = new Transaction();
|
||||
j = 0;
|
||||
}
|
||||
|
@ -537,7 +542,7 @@ function listenState(
|
|||
async function sendDupTxs(
|
||||
client: MangoClient,
|
||||
transaction: Transaction,
|
||||
signers: Account[],
|
||||
signers: Keypair[],
|
||||
n: number,
|
||||
) {
|
||||
await client.signTransaction({
|
||||
|
@ -653,6 +658,7 @@ function makeMarketUpdateInstructions(
|
|||
marketContext.sequenceAccount,
|
||||
payer.publicKey,
|
||||
Math.round(getUnixTs() * 1000),
|
||||
cluster,
|
||||
),
|
||||
];
|
||||
|
||||
|
@ -815,7 +821,7 @@ function makeMarketUpdateInstructions(
|
|||
|
||||
async function onExit(
|
||||
client: MangoClient,
|
||||
payer: Account,
|
||||
payer: Payer,
|
||||
group: MangoGroup,
|
||||
mangoAccount: MangoAccount,
|
||||
marketContexts: MarketContext[],
|
||||
|
@ -833,7 +839,7 @@ async function onExit(
|
|||
mangoProgramId,
|
||||
group.publicKey,
|
||||
mangoAccount.publicKey,
|
||||
payer.publicKey,
|
||||
payer.publicKey!,
|
||||
mc.market.publicKey,
|
||||
mc.market.bids,
|
||||
mc.market.asks,
|
||||
|
|
27
src/utils.ts
27
src/utils.ts
|
@ -8,6 +8,7 @@ import {
|
|||
MangoAccount,
|
||||
MangoClient,
|
||||
MangoGroup,
|
||||
Payer,
|
||||
} from '@blockworks-foundation/mango-client';
|
||||
import { createHash } from 'crypto';
|
||||
import { BN } from 'bn.js';
|
||||
|
@ -15,17 +16,17 @@ import { BN } from 'bn.js';
|
|||
export async function loadMangoAccountWithName(
|
||||
client: MangoClient,
|
||||
mangoGroup: MangoGroup,
|
||||
payer: Account,
|
||||
payer: Payer,
|
||||
mangoAccountName: string,
|
||||
): Promise<MangoAccount> {
|
||||
const ownerAccounts = await client.getMangoAccountsForOwner(
|
||||
mangoGroup,
|
||||
payer.publicKey,
|
||||
payer.publicKey!,
|
||||
true,
|
||||
);
|
||||
const delegateAccounts = await client.getMangoAccountsForDelegate(
|
||||
mangoGroup,
|
||||
payer.publicKey,
|
||||
payer.publicKey!,
|
||||
true,
|
||||
);
|
||||
ownerAccounts.push(...delegateAccounts);
|
||||
|
@ -41,7 +42,7 @@ export async function loadMangoAccountWithName(
|
|||
export async function loadMangoAccountWithPubkey(
|
||||
client: MangoClient,
|
||||
mangoGroup: MangoGroup,
|
||||
payer: Account,
|
||||
payer: Payer,
|
||||
mangoAccountPk: PublicKey,
|
||||
): Promise<MangoAccount> {
|
||||
const mangoAccount = await client.getMangoAccount(
|
||||
|
@ -49,22 +50,25 @@ export async function loadMangoAccountWithPubkey(
|
|||
mangoGroup.dexProgramId,
|
||||
);
|
||||
|
||||
if (!mangoAccount.owner.equals(payer.publicKey)) {
|
||||
if (!mangoAccount.owner.equals(payer.publicKey!)) {
|
||||
throw new Error(
|
||||
`Invalid MangoAccount owner: ${mangoAccount.owner.toString()}; expected: ${payer.publicKey.toString()}`,
|
||||
`Invalid MangoAccount owner: ${mangoAccount.owner.toString()}; expected: ${payer.publicKey!.toString()}`,
|
||||
);
|
||||
}
|
||||
return mangoAccount;
|
||||
}
|
||||
export const seqEnforcerProgramId = new PublicKey(
|
||||
'GDDMwNyyx8uB6zrqwBFHjLLG3TBYk2F8Az4yrQC5RzMp',
|
||||
);
|
||||
export const seqEnforcerProgramIds = {
|
||||
devnet: undefined,
|
||||
testnet: new PublicKey('FThcgpaJM8WiEbK5rw3i31Ptb8Hm4rQ27TrhfzeR1uUy'),
|
||||
mainnet: new PublicKey('GDDMwNyyx8uB6zrqwBFHjLLG3TBYk2F8Az4yrQC5RzMp'),
|
||||
};
|
||||
|
||||
export function makeInitSequenceInstruction(
|
||||
sequenceAccount: PublicKey,
|
||||
ownerPk: PublicKey,
|
||||
bump: number,
|
||||
sym: string,
|
||||
cluster: string,
|
||||
): TransactionInstruction {
|
||||
const keys = [
|
||||
{ isSigner: false, isWritable: true, pubkey: sequenceAccount },
|
||||
|
@ -86,7 +90,7 @@ export function makeInitSequenceInstruction(
|
|||
return new TransactionInstruction({
|
||||
keys,
|
||||
data,
|
||||
programId: seqEnforcerProgramId,
|
||||
programId: seqEnforcerProgramIds[cluster],
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -94,6 +98,7 @@ export function makeCheckAndSetSequenceNumberInstruction(
|
|||
sequenceAccount: PublicKey,
|
||||
ownerPk: PublicKey,
|
||||
seqNum: number,
|
||||
cluster,
|
||||
): TransactionInstruction {
|
||||
const keys = [
|
||||
{ isSigner: false, isWritable: true, pubkey: sequenceAccount },
|
||||
|
@ -109,7 +114,7 @@ export function makeCheckAndSetSequenceNumberInstruction(
|
|||
return new TransactionInstruction({
|
||||
keys,
|
||||
data,
|
||||
programId: seqEnforcerProgramId,
|
||||
programId: seqEnforcerProgramIds[cluster],
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue