-
Notifications
You must be signed in to change notification settings - Fork 11
/
createPermissionedMarket.ts
93 lines (83 loc) · 2.04 KB
/
createPermissionedMarket.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
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,
type OracleConfigParams,
} 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)
);
// WSOL
const baseMint = new PublicKey("So11111111111111111111111111111111111111112");
// USDC
const quoteMint = new PublicKey(
"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
);
// Sol/USD
const oracleAId = new PublicKey(
"H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG"
);
// USDC/USD
const oracleBId = new PublicKey(
"Gnt27xtC473ZT2Mw5u8wZ68Z3gULkSTb5DuxJy7eJotD"
);
const name = "SOL-USDC";
// expiricy in 10 days
const expiry = Math.floor(Date.now() / 1000) + 10 * 86400;
const oracleConfigParams: OracleConfigParams = {
confFilter: 0.1,
maxStalenessSlots: 100,
};
const [ixs, signers] = await client.createMarketIx(
authority.publicKey,
name,
quoteMint,
baseMint,
new BN(1),
new BN(1000000),
new BN(0),
new BN(0),
new BN(expiry),
oracleAId,
oracleBId,
null,
null,
wallet.publicKey,
oracleConfigParams
);
const tx = await client.sendAndConfirmTransaction(ixs, {
additionalSigners: [signers],
});
console.log("created market", tx);
console.log(
"finished with balance: ",
await connection.getBalance(authority.publicKey)
);
}
main();