serum-dev-tools/ts/examples/marketMaking.ts

79 lines
1.9 KiB
TypeScript
Raw Normal View History

2022-04-26 02:41:30 -07:00
import { Connection, LAMPORTS_PER_SOL, PublicKey } from "@solana/web3.js";
import { Dex, FileKeypair } from "../src";
2022-04-08 23:32:20 -07:00
2022-05-10 01:23:21 -07:00
process.on("beforeExit", () => console.log("Parent process exiting..."));
2022-04-08 23:32:20 -07:00
const main = async () => {
2022-06-01 06:38:09 -07:00
console.log("Process: ", process.pid);
2022-04-08 23:32:20 -07:00
const connection = new Connection("http://localhost:8899", "confirmed");
const owner = FileKeypair.loadOrGenerate("./scripts/keys/owner.json");
2022-05-17 08:45:50 -07:00
console.log("Owner: ", owner.keypair.publicKey.toString());
2022-04-08 23:32:20 -07:00
const airdropSig = await connection.requestAirdrop(
2022-04-26 02:41:30 -07:00
owner.keypair.publicKey,
2022-05-10 01:23:21 -07:00
10 * LAMPORTS_PER_SOL,
2022-04-08 23:32:20 -07:00
);
await connection.confirmTransaction(airdropSig);
const dexAddress = new PublicKey(
"7zo7HCQAZPRb4pYiQQ6fLjC8ssN3E8LkavVs8JUA5NMn",
);
const dex = new Dex(dexAddress, connection);
2022-04-26 02:41:30 -07:00
const baseCoin = await dex.createCoin(
"SAYA",
2022-05-10 01:23:21 -07:00
9,
2022-04-26 02:41:30 -07:00
owner.keypair,
owner.keypair,
owner.keypair,
);
const quoteCoin = await dex.createCoin(
"SRM",
2022-05-10 01:23:21 -07:00
9,
2022-04-26 02:41:30 -07:00
owner.keypair,
owner.keypair,
owner.keypair,
);
2022-04-08 23:32:20 -07:00
2022-04-26 02:41:30 -07:00
const market = await dex.initDexMarket(owner.keypair, baseCoin, quoteCoin, {
2022-05-10 01:23:21 -07:00
lotSize: 1e-3,
tickSize: 1e-2,
2022-04-08 23:32:20 -07:00
});
2022-05-10 01:23:21 -07:00
console.log(
`Created ${market.marketSymbol} market @ ${market.address.toString()}`,
);
2022-04-23 05:01:59 -07:00
2022-05-10 01:23:21 -07:00
await baseCoin.fundAccount(1000000, owner.keypair, connection);
await quoteCoin.fundAccount(2000000, owner.keypair, connection);
2022-04-23 05:01:59 -07:00
2022-04-26 02:41:30 -07:00
console.log(`Funded owner with ${baseCoin.symbol} and ${quoteCoin.symbol}`);
2022-04-08 23:32:20 -07:00
2022-05-24 04:31:12 -07:00
dex.runMarketMaker(market, owner, {
2022-06-21 12:17:43 -07:00
durationInSecs: 30,
2022-05-10 01:23:21 -07:00
orderCount: 3,
initialBidSize: 1000,
baseGeckoSymbol: "solana",
quoteGeckoSymbol: "usd",
2022-06-23 06:58:12 -07:00
verbose: false,
2022-05-10 01:23:21 -07:00
});
2022-06-21 12:17:43 -07:00
dex.runCrank(market, owner, {
durationInSecs: 20,
verbose: true,
});
2022-05-10 01:23:21 -07:00
};
const runMain = async () => {
try {
await main();
process.exit(0);
} catch (err) {
console.error(err);
process.exit(1);
}
2022-04-08 23:32:20 -07:00
};
2022-05-10 01:23:21 -07:00
runMain();