@theliem/xmarket-sdk 1.0.12 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{clob_exchange-ATSH42KC.json → clob_exchange-MQF4NI27.json} +2 -46
- package/dist/index.d.mts +8 -87
- package/dist/index.d.ts +8 -87
- package/dist/index.js +31 -118
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +33 -116
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -17
- package/src/idls/clob_exchange.json +2 -46
package/dist/index.mjs
CHANGED
|
@@ -1,63 +1,16 @@
|
|
|
1
1
|
import * as anchor4 from '@coral-xyz/anchor';
|
|
2
|
-
import {
|
|
2
|
+
import { SYSVAR_INSTRUCTIONS_PUBKEY, PublicKey, SystemProgram, SYSVAR_RENT_PUBKEY, TransactionInstruction, Ed25519Program, TransactionMessage, VersionedTransaction, Connection, Transaction } from '@solana/web3.js';
|
|
3
3
|
import { createHash } from 'crypto';
|
|
4
4
|
import { TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID, getAssociatedTokenAddressSync, ASSOCIATED_TOKEN_PROGRAM_ID, createApproveInstruction } from '@solana/spl-token';
|
|
5
5
|
import oracleIdl from './oracle-FZJJIJGI.json';
|
|
6
6
|
import hookIdl from './hook-THBRGUM6.json';
|
|
7
7
|
import questionMarketIdl from './question_market-CB6ZUZ5E.json';
|
|
8
8
|
import conditionalTokensIdl from './conditional_tokens-3O5V46N5.json';
|
|
9
|
-
import clobExchangeIdl from './clob_exchange-
|
|
9
|
+
import clobExchangeIdl from './clob_exchange-MQF4NI27.json';
|
|
10
10
|
import BN4 from 'bn.js';
|
|
11
11
|
import * as nacl from 'tweetnacl';
|
|
12
12
|
|
|
13
13
|
// src/sdk.ts
|
|
14
|
-
var DEVNET_CONFIG = {
|
|
15
|
-
name: "devnet",
|
|
16
|
-
rpcUrl: "https://api.devnet.solana.com",
|
|
17
|
-
programIds: {
|
|
18
|
-
oracle: new PublicKey("FzLnnbKtQCTKviEbrDYMLZYXNDHQdjSSa4Ybj4jAbrUL"),
|
|
19
|
-
conditionalTokens: new PublicKey("A6N1F8MRsdgcojAx8p6FaECvw8mo8w6qJcWsbKQBANK4"),
|
|
20
|
-
questionMarket: new PublicKey("FCvCbWoLpzNYKzQnXYXCo1yz9DTpgUs11QqHVqnqtWhA"),
|
|
21
|
-
hook: new PublicKey("F7y5MfW8d5kqR25QHDhUQ9LrKCiZUZVF6Pdnw15q5zZW"),
|
|
22
|
-
clobExchange: new PublicKey("Cs4GY1yZVxjxhhyUum3AupMuS3bo4yKRXifgLTTAh1sf")
|
|
23
|
-
},
|
|
24
|
-
defaultCollateral: {
|
|
25
|
-
mint: new PublicKey("53osACZSom79AHf6nK4eq8DL6viMZmyVERYPDB6S6Eck"),
|
|
26
|
-
decimals: 9
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
var LOCALNET_CONFIG = {
|
|
30
|
-
name: "localnet",
|
|
31
|
-
rpcUrl: "http://localhost:8899",
|
|
32
|
-
programIds: { ...DEVNET_CONFIG.programIds },
|
|
33
|
-
defaultCollateral: {
|
|
34
|
-
mint: new PublicKey("6Gk4qsruSjunenwzP4L5DQukawfVNvdr9rPX2qG77jmH"),
|
|
35
|
-
decimals: 6
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var MAINNET_CONFIG = {
|
|
39
|
-
name: "mainnet",
|
|
40
|
-
rpcUrl: "https://api.mainnet-beta.solana.com",
|
|
41
|
-
programIds: {
|
|
42
|
-
oracle: new PublicKey("E667trvbHmZEnptjnjXp9x8e1Fpji3viHo1J1DGPKijh"),
|
|
43
|
-
conditionalTokens: new PublicKey("3WFSX7zPLrJSU811h7awgqXTZuKhUR1Fi1VBDayHhk4s"),
|
|
44
|
-
questionMarket: new PublicKey("GiQh2xBmEiM4gYq4U9PMSaUJNq1T9TfEJL5cXvNYhtGm"),
|
|
45
|
-
hook: new PublicKey("11111111111111111111111111111111"),
|
|
46
|
-
// not yet deployed
|
|
47
|
-
clobExchange: new PublicKey("11111111111111111111111111111111")
|
|
48
|
-
// not yet deployed
|
|
49
|
-
},
|
|
50
|
-
defaultCollateral: {
|
|
51
|
-
mint: new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),
|
|
52
|
-
// USDC mainnet
|
|
53
|
-
decimals: 6
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
var NETWORK_CONFIGS = {
|
|
57
|
-
devnet: DEVNET_CONFIG,
|
|
58
|
-
localnet: LOCALNET_CONFIG,
|
|
59
|
-
mainnet: MAINNET_CONFIG
|
|
60
|
-
};
|
|
61
14
|
var SEEDS = {
|
|
62
15
|
config: Buffer.from("config"),
|
|
63
16
|
question: Buffer.from("question"),
|
|
@@ -1291,14 +1244,13 @@ var ClobClient = class {
|
|
|
1291
1244
|
*
|
|
1292
1245
|
* remaining_accounts: [maker×5 × N] (no hook accounts — mint_to doesn't fire hook)
|
|
1293
1246
|
*/
|
|
1294
|
-
async matchMintOrders(yesSigned, makersSigned, collateralMint, whitelistedWallet, lookupTable) {
|
|
1247
|
+
async matchMintOrders(yesSigned, makersSigned, collateralMint, feeRecipient, whitelistedWallet, lookupTable) {
|
|
1295
1248
|
const condition = yesSigned.order.condition;
|
|
1296
1249
|
const [yesMint] = PDA.yesMint(condition, this.programIds);
|
|
1297
1250
|
const [noMint] = PDA.noMint(condition, this.programIds);
|
|
1298
1251
|
const [mintAuthority] = PDA.mintAuthority(condition, this.programIds);
|
|
1299
1252
|
const [collateralVault] = PDA.collateralVault(collateralMint, this.programIds);
|
|
1300
1253
|
const [vaultTokenAccount] = PDA.vaultToken(collateralMint, this.programIds);
|
|
1301
|
-
const [clobAuthority] = PDA.clobConfig(this.programIds);
|
|
1302
1254
|
const buyerYes = yesSigned.order.maker;
|
|
1303
1255
|
const buyerYesCollateral = getAssociatedTokenAddressSync(collateralMint, buyerYes);
|
|
1304
1256
|
const buyerYesTokenAccount = getAssociatedTokenAddressSync(yesMint, buyerYes, false, TOKEN_2022_PROGRAM_ID);
|
|
@@ -1341,12 +1293,19 @@ var ClobClient = class {
|
|
|
1341
1293
|
yesMint,
|
|
1342
1294
|
noMint,
|
|
1343
1295
|
mintAuthority,
|
|
1344
|
-
|
|
1296
|
+
feeRecipient,
|
|
1345
1297
|
conditionalTokensProgram: this.programIds.conditionalTokens,
|
|
1346
1298
|
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
1347
1299
|
token2022Program: TOKEN_2022_PROGRAM_ID,
|
|
1348
1300
|
systemProgram: SystemProgram.programId
|
|
1349
1301
|
}).remainingAccounts(makerAccounts).instruction();
|
|
1302
|
+
const frKey = feeRecipient.toBase58();
|
|
1303
|
+
for (const k of matchIx.keys) {
|
|
1304
|
+
if (k.pubkey.toBase58() === frKey) {
|
|
1305
|
+
k.isWritable = true;
|
|
1306
|
+
break;
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1350
1309
|
const sig = await this._sendMatchTx(
|
|
1351
1310
|
[...ed25519Ixs, matchIx],
|
|
1352
1311
|
lookupTable,
|
|
@@ -1364,13 +1323,12 @@ var ClobClient = class {
|
|
|
1364
1323
|
*
|
|
1365
1324
|
* remaining_accounts: [maker×5 × N] (no hook accounts — burn doesn't fire hook)
|
|
1366
1325
|
*/
|
|
1367
|
-
async matchMergeOrders(yesSigned, makersSigned, collateralMint, whitelistedWallet, lookupTable) {
|
|
1326
|
+
async matchMergeOrders(yesSigned, makersSigned, collateralMint, feeRecipient, whitelistedWallet, lookupTable) {
|
|
1368
1327
|
const condition = yesSigned.order.condition;
|
|
1369
1328
|
const [yesMint] = PDA.yesMint(condition, this.programIds);
|
|
1370
1329
|
const [noMint] = PDA.noMint(condition, this.programIds);
|
|
1371
1330
|
const [collateralVault] = PDA.collateralVault(collateralMint, this.programIds);
|
|
1372
1331
|
const [vaultTokenAccount] = PDA.vaultToken(collateralMint, this.programIds);
|
|
1373
|
-
const [clobAuthority] = PDA.clobConfig(this.programIds);
|
|
1374
1332
|
const sellerYes = yesSigned.order.maker;
|
|
1375
1333
|
const sellerYesTokenAccount = getAssociatedTokenAddressSync(yesMint, sellerYes, false, TOKEN_2022_PROGRAM_ID);
|
|
1376
1334
|
const [sellerYesPosition] = PDA.position(condition, 1, sellerYes, this.programIds);
|
|
@@ -1412,12 +1370,19 @@ var ClobClient = class {
|
|
|
1412
1370
|
vaultTokenAccount,
|
|
1413
1371
|
yesMint,
|
|
1414
1372
|
noMint,
|
|
1415
|
-
|
|
1373
|
+
feeRecipient,
|
|
1416
1374
|
conditionalTokensProgram: this.programIds.conditionalTokens,
|
|
1417
1375
|
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
1418
1376
|
token2022Program: TOKEN_2022_PROGRAM_ID,
|
|
1419
1377
|
systemProgram: SystemProgram.programId
|
|
1420
1378
|
}).remainingAccounts(makerAccounts).instruction();
|
|
1379
|
+
const frKeyM = feeRecipient.toBase58();
|
|
1380
|
+
for (const k of matchIx.keys) {
|
|
1381
|
+
if (k.pubkey.toBase58() === frKeyM) {
|
|
1382
|
+
k.isWritable = true;
|
|
1383
|
+
break;
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1421
1386
|
const sig = await this._sendMatchTx(
|
|
1422
1387
|
[...ed25519Ixs, matchIx],
|
|
1423
1388
|
lookupTable,
|
|
@@ -1440,8 +1405,8 @@ var ClobClient = class {
|
|
|
1440
1405
|
if (makers.length === 0) throw new InvalidParamError("At least 1 maker required");
|
|
1441
1406
|
const t = taker.order;
|
|
1442
1407
|
const m0 = makers[0].order;
|
|
1443
|
-
const SIDE_BUY =
|
|
1444
|
-
const SIDE_SELL =
|
|
1408
|
+
const SIDE_BUY = 0;
|
|
1409
|
+
const SIDE_SELL = 1;
|
|
1445
1410
|
if (t.tokenId === m0.tokenId) {
|
|
1446
1411
|
if (t.side === SIDE_BUY && makers.every((m) => m.order.side === SIDE_SELL)) {
|
|
1447
1412
|
return this.matchComplementary(taker, makers, collateralMint, feeRecipient, whitelistedWallet, lookupTable);
|
|
@@ -1463,9 +1428,9 @@ var ClobClient = class {
|
|
|
1463
1428
|
throw new InvalidParamError("MINT/MERGE: all makers must be the NO side (tokenId=0)");
|
|
1464
1429
|
}
|
|
1465
1430
|
if (allBuy) {
|
|
1466
|
-
return this.matchMintOrders(taker, makers, collateralMint, whitelistedWallet, lookupTable);
|
|
1431
|
+
return this.matchMintOrders(taker, makers, collateralMint, feeRecipient, whitelistedWallet, lookupTable);
|
|
1467
1432
|
}
|
|
1468
|
-
return this.matchMergeOrders(taker, makers, collateralMint, whitelistedWallet, lookupTable);
|
|
1433
|
+
return this.matchMergeOrders(taker, makers, collateralMint, feeRecipient, whitelistedWallet, lookupTable);
|
|
1469
1434
|
}
|
|
1470
1435
|
// ─── Whitelist admin ─────────────────────────────────────────────────────────
|
|
1471
1436
|
/** Add an address to the CLOB whitelist (owner only). */
|
|
@@ -1564,23 +1529,21 @@ var ClobClient = class {
|
|
|
1564
1529
|
return status?.isCancelled === true;
|
|
1565
1530
|
}
|
|
1566
1531
|
};
|
|
1567
|
-
var XMarketSDK = class
|
|
1568
|
-
constructor(config) {
|
|
1569
|
-
this.networkConfig =
|
|
1532
|
+
var XMarketSDK = class {
|
|
1533
|
+
constructor(config, wallet, marketOwner) {
|
|
1534
|
+
this.networkConfig = config;
|
|
1570
1535
|
this.provider = new anchor4.AnchorProvider(
|
|
1571
|
-
new Connection(
|
|
1572
|
-
|
|
1536
|
+
new Connection(config.rpcUrl, "confirmed"),
|
|
1537
|
+
wallet,
|
|
1573
1538
|
{ commitment: "confirmed", preflightCommitment: "confirmed" }
|
|
1574
1539
|
);
|
|
1575
1540
|
anchor4.setProvider(this.provider);
|
|
1576
|
-
this._programIds =
|
|
1577
|
-
this._marketOwner =
|
|
1541
|
+
this._programIds = config.programIds;
|
|
1542
|
+
this._marketOwner = marketOwner ?? wallet.publicKey;
|
|
1578
1543
|
}
|
|
1579
|
-
// ─── Lazy-initialised clients ─────────────────────────────────────────────
|
|
1580
1544
|
_withAddress(idl, address) {
|
|
1581
1545
|
return { ...idl, address: address.toBase58() };
|
|
1582
1546
|
}
|
|
1583
|
-
/** Oracle program client */
|
|
1584
1547
|
get oracle() {
|
|
1585
1548
|
if (!this._oracle) {
|
|
1586
1549
|
const program = new anchor4.Program(this._withAddress(oracleIdl, this._programIds.oracle), this.provider);
|
|
@@ -1588,7 +1551,6 @@ var XMarketSDK = class _XMarketSDK {
|
|
|
1588
1551
|
}
|
|
1589
1552
|
return this._oracle;
|
|
1590
1553
|
}
|
|
1591
|
-
/** Transfer-hook program client */
|
|
1592
1554
|
get hook() {
|
|
1593
1555
|
if (!this._hook) {
|
|
1594
1556
|
const program = new anchor4.Program(this._withAddress(hookIdl, this._programIds.hook), this.provider);
|
|
@@ -1596,7 +1558,6 @@ var XMarketSDK = class _XMarketSDK {
|
|
|
1596
1558
|
}
|
|
1597
1559
|
return this._hook;
|
|
1598
1560
|
}
|
|
1599
|
-
/** QuestionMarket program client */
|
|
1600
1561
|
get market() {
|
|
1601
1562
|
if (!this._market) {
|
|
1602
1563
|
const program = new anchor4.Program(this._withAddress(questionMarketIdl, this._programIds.questionMarket), this.provider);
|
|
@@ -1605,7 +1566,6 @@ var XMarketSDK = class _XMarketSDK {
|
|
|
1605
1566
|
}
|
|
1606
1567
|
return this._market;
|
|
1607
1568
|
}
|
|
1608
|
-
/** Conditional tokens (CTF) program client */
|
|
1609
1569
|
get ctf() {
|
|
1610
1570
|
if (!this._ctf) {
|
|
1611
1571
|
const program = new anchor4.Program(this._withAddress(conditionalTokensIdl, this._programIds.conditionalTokens), this.provider);
|
|
@@ -1613,7 +1573,6 @@ var XMarketSDK = class _XMarketSDK {
|
|
|
1613
1573
|
}
|
|
1614
1574
|
return this._ctf;
|
|
1615
1575
|
}
|
|
1616
|
-
/** CLOB exchange program client */
|
|
1617
1576
|
get clob() {
|
|
1618
1577
|
if (!this._clob) {
|
|
1619
1578
|
const program = new anchor4.Program(this._withAddress(clobExchangeIdl, this._programIds.clobExchange), this.provider);
|
|
@@ -1621,48 +1580,6 @@ var XMarketSDK = class _XMarketSDK {
|
|
|
1621
1580
|
}
|
|
1622
1581
|
return this._clob;
|
|
1623
1582
|
}
|
|
1624
|
-
// ─── Factory helpers ──────────────────────────────────────────────────────
|
|
1625
|
-
/**
|
|
1626
|
-
* Connect to devnet.
|
|
1627
|
-
* ```ts
|
|
1628
|
-
* const sdk = XMarketSDK.devnet(wallet);
|
|
1629
|
-
* ```
|
|
1630
|
-
*/
|
|
1631
|
-
static devnet(wallet, marketOwner) {
|
|
1632
|
-
return new _XMarketSDK({ network: "devnet", wallet, marketOwner });
|
|
1633
|
-
}
|
|
1634
|
-
/**
|
|
1635
|
-
* Connect to localhost test validator.
|
|
1636
|
-
* ```ts
|
|
1637
|
-
* const sdk = XMarketSDK.localnet(wallet);
|
|
1638
|
-
* ```
|
|
1639
|
-
*/
|
|
1640
|
-
static localnet(wallet, marketOwner) {
|
|
1641
|
-
return new _XMarketSDK({ network: "localnet", wallet, marketOwner });
|
|
1642
|
-
}
|
|
1643
|
-
/**
|
|
1644
|
-
* Connect to mainnet-beta.
|
|
1645
|
-
* ```ts
|
|
1646
|
-
* const sdk = XMarketSDK.mainnet(wallet);
|
|
1647
|
-
* ```
|
|
1648
|
-
*/
|
|
1649
|
-
static mainnet(wallet, marketOwner) {
|
|
1650
|
-
return new _XMarketSDK({ network: "mainnet", wallet, marketOwner });
|
|
1651
|
-
}
|
|
1652
|
-
/**
|
|
1653
|
-
* Custom network (e.g. custom RPC, custom program IDs for a fork).
|
|
1654
|
-
* ```ts
|
|
1655
|
-
* const sdk = XMarketSDK.custom({
|
|
1656
|
-
* name: "staging",
|
|
1657
|
-
* rpcUrl: "https://my-rpc.com",
|
|
1658
|
-
* programIds: { ... },
|
|
1659
|
-
* defaultCollateral: { mint: ..., decimals: 6 },
|
|
1660
|
-
* }, wallet);
|
|
1661
|
-
* ```
|
|
1662
|
-
*/
|
|
1663
|
-
static custom(config, wallet, marketOwner) {
|
|
1664
|
-
return new _XMarketSDK({ network: config, wallet, marketOwner });
|
|
1665
|
-
}
|
|
1666
1583
|
};
|
|
1667
1584
|
function buildOrder(params) {
|
|
1668
1585
|
return {
|
|
@@ -1731,7 +1648,7 @@ function detectMatchType(a, b) {
|
|
|
1731
1648
|
return _detectMatchType(_a, _b);
|
|
1732
1649
|
}
|
|
1733
1650
|
function _detectMatchType(a, b) {
|
|
1734
|
-
const SIDE_BUY =
|
|
1651
|
+
const SIDE_BUY = 0;
|
|
1735
1652
|
if (a.tokenId === b.tokenId) {
|
|
1736
1653
|
const aBuy2 = a.side === SIDE_BUY;
|
|
1737
1654
|
const bBuy2 = b.side === SIDE_BUY;
|
|
@@ -1792,6 +1709,6 @@ function buildApproveAllOutcomeTokensTx(condition, signer, payer, delegate, prog
|
|
|
1792
1709
|
return tx;
|
|
1793
1710
|
}
|
|
1794
1711
|
|
|
1795
|
-
export { AccountNotFoundError, ClobClient, CtfClient,
|
|
1712
|
+
export { AccountNotFoundError, ClobClient, CtfClient, HookClient, IX_SYSVAR, InvalidParamError, MAX_APPROVE_AMOUNT, MarketClient, OracleClient, PDA, QuestionStatus, SEEDS, UnauthorizedError, XMarketError, XMarketSDK, buildApproveAllOutcomeTokensTx, buildApproveCollateralTx, buildBatchedEd25519Instruction, buildOrder, deserializeSignedOrder, detectMatchType, generateContentHash, generateQuestionId, getOrderSignBytes, serializeOrderToBytes, serializeSignedOrder, signOrder, signOrderWithKeypair, verifySignedOrder };
|
|
1796
1713
|
//# sourceMappingURL=index.mjs.map
|
|
1797
1714
|
//# sourceMappingURL=index.mjs.map
|