-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathcreateMarket.ts
168 lines (149 loc) · 4.09 KB
/
createMarket.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import {
Keypair,
PublicKey,
ComputeBudgetProgram,
SystemProgram,
Transaction,
Connection,
} from "@solana/web3.js";
import {
AnchorProvider,
BN,
Program,
Wallet,
getProvider,
} from "@coral-xyz/anchor";
import { createAccount } from "./solana_utils";
import { MintUtils } from "./mint_utils";
import { OpenBookV2Client } from "@openbook-dex/openbook-v2";
import { RPC, authority, connection, programId } from "./utils";
function delay(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
async function main() {
const wallet = new Wallet(authority);
const provider = new AnchorProvider(new Connection(RPC), wallet, {
commitment: "confirmed",
});
const client = new OpenBookV2Client(provider, programId);
console.log(
"starting with balance: ",
await provider.connection.getBalance(authority.publicKey)
);
// const nbMints = 2;
// let mintUtils = new MintUtils(provider.connection, authority);
// let mints = await mintUtils.createMints(nbMints);
// console.log("Mints created");
// console.log("Mint 0", mints[0].toString());
// console.log("Mint 1", mints[1].toString());
// await delay(300);
// const baseMint = mints[1];
// const quoteMint = mints[0];
// In devent
// const baseMint = new PublicKey("DEPipWZkmZcr1sL6pVwj8amRjr9kw91UkFR7tvqdvMy2");
// const quoteMint = new PublicKey("BfvE9DViu6SkSMBz4TYVftd5DNp7bafemMujXBdVwFYN");
// Mainnet acounts for SOL-USDC
// WSOL
const baseMint = new PublicKey("METADDFL6wWMWEoKTFJwcThTbUmtarRJZjRpzUvkxhr");
// USDC
const quoteMint = new PublicKey(
"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
);
// // Sol/USD
// const oracleAId = new PublicKey(
// "H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG"
// );
// // USDC/USD
// const oracleBId = new PublicKey(
// "Gnt27xtC473ZT2Mw5u8wZ68Z3gULkSTb5DuxJy7eJotD"
// );
const oracleAId = null;
const oracleBId = null;
// let [oracleAId, _tmp1] = PublicKey.findProgramAddressSync(
// [
// Buffer.from("StubOracle"),
// adminKp.publicKey.toBytes(),
// baseMint.toBytes(),
// ],
// programId
// );
// let [oracleBId, _tmp3] = PublicKey.findProgramAddressSync(
// [
// Buffer.from("StubOracle"),
// adminKp.publicKey.toBytes(),
// quoteMint.toBytes(),
// ],
// programId
// );
// let price = getRandomInt(1000);
// if ((await anchorProvider.connection.getAccountInfo(oracleAId)) == null) {
// await program.methods
// .stubOracleCreate({ val: new BN(1) })
// .accounts({
// payer: adminKp.publicKey,
// oracle: oracleAId,
// mint: baseMint,
// systemProgram: SystemProgram.programId,
// })
// .signers([adminKp])
// .rpc();
// }
// if ((await anchorProvider.connection.getAccountInfo(oracleBId)) == null) {
// await program.methods
// .stubOracleCreate({ val: new BN(1) })
// .accounts({
// payer: adminKp.publicKey,
// oracle: oracleBId,
// mint: quoteMint,
// systemProgram: SystemProgram.programId,
// })
// .signers([adminKp])
// .rpc();
// }
// await program.methods
// .stubOracleSet({
// val: new BN(price),
// })
// .accounts({
// owner: adminKp.publicKey,
// oracle: oracleAId,
// })
// .signers([adminKp])
// .rpc();
// await program.methods
// .stubOracleSet({
// val: new BN(price),
// })
// .accounts({
// owner: adminKp.publicKey,
// oracle: oracleBId,
// })
// .signers([adminKp])
// .rpc();
const name = "SOL-USDC";
const [ixs, signers] = await client.createMarketIx(
authority.publicKey,
name,
quoteMint,
baseMint,
new BN(1),
new BN(1000000),
new BN(1000),
new BN(1000),
new BN(0),
oracleAId,
oracleBId,
null,
null,
null
);
const tx = await client.sendAndConfirmTransaction(ixs, {
additionalSigners: signers,
});
console.log("created market", tx);
console.log(
"finished with balance: ",
await connection.getBalance(authority.publicKey)
);
}
main();