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

78 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";
2022-04-08 23:32:20 -07:00
import BN from "bn.js";
2022-04-26 02:41:30 -07:00
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 () => {
const connection = new Connection("http://localhost:8899", "confirmed");
2022-04-26 02:41:30 -07:00
const owner = FileKeypair.generate("./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
feeRate: 10,
quoteDustThreshold: new BN(100),
});
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-10 01:23:21 -07:00
const marketMaker = dex.runMarketMaker(market, owner, {
unref: true,
durationInSecs: 30,
orderCount: 3,
initialBidSize: 1000,
baseGeckoSymbol: "solana",
quoteGeckoSymbol: "usd",
});
console.log(`Market Maker running at process: ${marketMaker.pid}`);
};
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();