@theliem/xmarket-sdk 4.1.1 → 4.1.2
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/index.d.mts +30 -5
- package/dist/index.d.ts +30 -5
- package/dist/index.js +102 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +96 -27
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -185,6 +185,7 @@ var PDA = class {
|
|
|
185
185
|
);
|
|
186
186
|
}
|
|
187
187
|
// ─── Presale ─────────────────────────────────────────────────────────────────
|
|
188
|
+
/** seeds: ["presale", questionMarketConfig, presale_index u64 LE] under presale program */
|
|
188
189
|
static presale(questionMarketConfig, presaleIndex, programIds) {
|
|
189
190
|
if (!programIds.presale) throw new Error("presale program ID not configured");
|
|
190
191
|
const idxBuf = Buffer.alloc(8);
|
|
@@ -607,28 +608,52 @@ var MarketClient = class {
|
|
|
607
608
|
return this.program.methods.bumpPresaleCount(new anchor6.BN(count)).accounts({ authority, config: this.configPda }).transaction();
|
|
608
609
|
}
|
|
609
610
|
// ─── Queries ─────────────────────────────────────────────────────────────────
|
|
611
|
+
configNotFoundMessage() {
|
|
612
|
+
return `Question market config not found at ${this.configPda.toBase58()}. Check NetworkConfig.programIds.questionMarket (v2 FkpHo3...) and marketOwner (config owner pubkey \u2014 not the user wallet). Devnet: use DEVNET_CONFIG or marketOwner DEVNET_MARKET_OWNER.`;
|
|
613
|
+
}
|
|
610
614
|
async fetchConfig() {
|
|
615
|
+
const info = await this.provider.connection.getAccountInfo(this.configPda);
|
|
616
|
+
if (!info) return null;
|
|
611
617
|
try {
|
|
612
618
|
const acc = await this.program.account.questionMarketConfig.fetch(this.configPda);
|
|
613
|
-
return
|
|
614
|
-
owner: acc.owner,
|
|
615
|
-
admin: acc.admin,
|
|
616
|
-
oracle: acc.oracle,
|
|
617
|
-
oracleProgram: acc.oracleProgram,
|
|
618
|
-
conditionalTokensProgram: acc.conditionalTokensProgram,
|
|
619
|
-
questionCount: acc.questionCount.toNumber(),
|
|
620
|
-
approvedCount: acc.approvedCount.toNumber(),
|
|
621
|
-
rejectedCount: acc.rejectedCount.toNumber(),
|
|
622
|
-
presaleCount: acc.presaleCount.toNumber(),
|
|
623
|
-
whitelist: acc.whitelist.slice(0, acc.whitelistLen),
|
|
624
|
-
whitelistLen: acc.whitelistLen,
|
|
625
|
-
isPaused: acc.isPaused,
|
|
626
|
-
bump: acc.bump
|
|
627
|
-
};
|
|
619
|
+
return this.mapQuestionMarketConfig(acc);
|
|
628
620
|
} catch {
|
|
629
621
|
return null;
|
|
630
622
|
}
|
|
631
623
|
}
|
|
624
|
+
/** Like fetchConfig but throws with a hint when the config account is missing or invalid. */
|
|
625
|
+
async fetchConfigOrThrow() {
|
|
626
|
+
const info = await this.provider.connection.getAccountInfo(this.configPda);
|
|
627
|
+
if (!info) {
|
|
628
|
+
throw new Error(this.configNotFoundMessage());
|
|
629
|
+
}
|
|
630
|
+
try {
|
|
631
|
+
const acc = await this.program.account.questionMarketConfig.fetch(this.configPda);
|
|
632
|
+
return this.mapQuestionMarketConfig(acc);
|
|
633
|
+
} catch (e) {
|
|
634
|
+
throw new Error(
|
|
635
|
+
`${this.configNotFoundMessage()} Deserialize failed: ${e instanceof Error ? e.message : e}`
|
|
636
|
+
);
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
mapQuestionMarketConfig(acc) {
|
|
640
|
+
const accAny = acc;
|
|
641
|
+
return {
|
|
642
|
+
owner: accAny.owner,
|
|
643
|
+
admin: accAny.admin,
|
|
644
|
+
oracle: accAny.oracle,
|
|
645
|
+
oracleProgram: accAny.oracleProgram,
|
|
646
|
+
conditionalTokensProgram: accAny.conditionalTokensProgram,
|
|
647
|
+
questionCount: Number(accAny.questionCount.toString()),
|
|
648
|
+
approvedCount: Number(accAny.approvedCount.toString()),
|
|
649
|
+
rejectedCount: Number(accAny.rejectedCount.toString()),
|
|
650
|
+
presaleCount: Number(accAny.presaleCount.toString()),
|
|
651
|
+
whitelist: accAny.whitelist.slice(0, accAny.whitelistLen),
|
|
652
|
+
whitelistLen: accAny.whitelistLen,
|
|
653
|
+
isPaused: accAny.isPaused,
|
|
654
|
+
bump: accAny.bump
|
|
655
|
+
};
|
|
656
|
+
}
|
|
632
657
|
/** Check if address is in question_market whitelist (can call createQuestion) */
|
|
633
658
|
async isWhitelisted(address) {
|
|
634
659
|
const cfg = await this.fetchConfig();
|
|
@@ -681,9 +706,10 @@ var MarketClient = class {
|
|
|
681
706
|
* Any user creates a presale + initial buy (question-market::create_presale).
|
|
682
707
|
* Reads agents_rev / company_rev from fee_config.
|
|
683
708
|
*
|
|
684
|
-
*
|
|
685
|
-
*
|
|
686
|
-
*
|
|
709
|
+
* Presale PDA seeds (presale program): ["presale", config, presale_index]
|
|
710
|
+
* where presale_index must equal config.presale_count at execution time.
|
|
711
|
+
*
|
|
712
|
+
* @param presaleIndex config.presale_count — fetch config first via fetchConfig()
|
|
687
713
|
*/
|
|
688
714
|
async createPresale(params, feeConfig, currencyMint, presaleIndex, creator = this.walletPubkey, payer = creator) {
|
|
689
715
|
if (!this.programIds.presale) throw new Error("presale program ID not configured");
|
|
@@ -7184,13 +7210,6 @@ var question_market_default = {
|
|
|
7184
7210
|
],
|
|
7185
7211
|
type: "pubkey"
|
|
7186
7212
|
},
|
|
7187
|
-
{
|
|
7188
|
-
name: "oracle_program",
|
|
7189
|
-
docs: [
|
|
7190
|
-
"Oracle program ID \u2014 pinned for CPI validation in resolve_question"
|
|
7191
|
-
],
|
|
7192
|
-
type: "pubkey"
|
|
7193
|
-
},
|
|
7194
7213
|
{
|
|
7195
7214
|
name: "question_count",
|
|
7196
7215
|
docs: [
|
|
@@ -7252,6 +7271,14 @@ var question_market_default = {
|
|
|
7252
7271
|
],
|
|
7253
7272
|
type: "u64"
|
|
7254
7273
|
},
|
|
7274
|
+
{
|
|
7275
|
+
name: "oracle_program",
|
|
7276
|
+
docs: [
|
|
7277
|
+
"Oracle program ID \u2014 pinned for CPI validation in resolve_question",
|
|
7278
|
+
"Placed at end of meaningful fields to avoid layout shift on old accounts."
|
|
7279
|
+
],
|
|
7280
|
+
type: "pubkey"
|
|
7281
|
+
},
|
|
7255
7282
|
{
|
|
7256
7283
|
name: "_reserved",
|
|
7257
7284
|
docs: [
|
|
@@ -18042,7 +18069,11 @@ var XMarketSDK = class {
|
|
|
18042
18069
|
);
|
|
18043
18070
|
anchor6.setProvider(this.provider);
|
|
18044
18071
|
this._programIds = config.programIds;
|
|
18045
|
-
this._marketOwner = marketOwner ?? wallet.publicKey;
|
|
18072
|
+
this._marketOwner = marketOwner ?? config.marketOwner ?? wallet.publicKey;
|
|
18073
|
+
}
|
|
18074
|
+
/** Question market config PDA derived from marketOwner + questionMarket program. */
|
|
18075
|
+
get questionMarketConfigPda() {
|
|
18076
|
+
return this.market.configPda;
|
|
18046
18077
|
}
|
|
18047
18078
|
_withAddress(idl, address) {
|
|
18048
18079
|
return { ...idl, address: address.toBase58() };
|
|
@@ -18132,6 +18163,44 @@ var XMarketSDK = class {
|
|
|
18132
18163
|
return this._dispute;
|
|
18133
18164
|
}
|
|
18134
18165
|
};
|
|
18166
|
+
var V2_PROGRAM_IDS = {
|
|
18167
|
+
oracle: new PublicKey("8uNiLDZnarxyFyoCi1bE1qkBMsLs2Tpyohtdzdvjkg8j"),
|
|
18168
|
+
conditionalTokens: new PublicKey("xpn3htSptTZECudoRA8WJmAEtiijxDseTqtawYysVNT"),
|
|
18169
|
+
questionMarket: new PublicKey("FkpHo3zb5h2nNS5n6tWAvDwXPTXR2qqVLjDmEkMayott"),
|
|
18170
|
+
clobExchange: new PublicKey("AFT8SM1Vv8g8AQTf81LoE5oLteUTyhWzWTLj7SKZjkY1"),
|
|
18171
|
+
feeManagement: new PublicKey("8S6hxqbDc8kgHf4uUzq2t15PeY36QSCYEpBVvM4Fhrkm"),
|
|
18172
|
+
presale: new PublicKey("CKd94vPibAMAr8R5eLv21r8PYXkgLRithipBe8GV7J6C"),
|
|
18173
|
+
marketOracle: new PublicKey("Agt6beCbghi4jV9A8v9geRP5dnt2wDkJBVgy9oM33zit"),
|
|
18174
|
+
adminContract: new PublicKey("2HsyCdr59W5ndeboaE9JAmhEQ46m5Gm2ZWBfYEs1tC1i"),
|
|
18175
|
+
referral: new PublicKey("9kyNMtUEFR6hDeZHUTbRKH3t1EJisfSvWQKKUev7ujoC"),
|
|
18176
|
+
dispute: new PublicKey("8gqHPY1WtGFGmYNbrGrPVoct1kqPL6cCaUtJ17EHSsFp")
|
|
18177
|
+
};
|
|
18178
|
+
var DEVNET_MARKET_OWNER = new PublicKey(
|
|
18179
|
+
"7eGpbyRpcM7WpNKQtd6XkteNQWHbWXP7icZjKzNK2aTk"
|
|
18180
|
+
);
|
|
18181
|
+
var DEVNET_QUESTION_MARKET_CONFIG = new PublicKey(
|
|
18182
|
+
"7n8y2oQYmxTp9fn2Wf2dFE1pC7ZESXYJ4yXSbYSEuRn5"
|
|
18183
|
+
);
|
|
18184
|
+
var DEVNET_USDC_MINT = new PublicKey(
|
|
18185
|
+
"4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU"
|
|
18186
|
+
);
|
|
18187
|
+
var MAINNET_USDC_MINT = new PublicKey(
|
|
18188
|
+
"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
|
|
18189
|
+
);
|
|
18190
|
+
var DEVNET_CONFIG = {
|
|
18191
|
+
name: "devnet",
|
|
18192
|
+
rpcUrl: "https://api.devnet.solana.com",
|
|
18193
|
+
programIds: V2_PROGRAM_IDS,
|
|
18194
|
+
defaultCollateral: { mint: DEVNET_USDC_MINT, decimals: 6 },
|
|
18195
|
+
marketOwner: DEVNET_MARKET_OWNER,
|
|
18196
|
+
feeConfigOwner: DEVNET_MARKET_OWNER
|
|
18197
|
+
};
|
|
18198
|
+
var MAINNET_CONFIG = {
|
|
18199
|
+
name: "mainnet",
|
|
18200
|
+
rpcUrl: "https://api.mainnet-beta.solana.com",
|
|
18201
|
+
programIds: V2_PROGRAM_IDS,
|
|
18202
|
+
defaultCollateral: { mint: MAINNET_USDC_MINT, decimals: 6 }
|
|
18203
|
+
};
|
|
18135
18204
|
var MAX_APPROVE_AMOUNT = new BN4("18446744073709551615");
|
|
18136
18205
|
function buildCreateUserAtasTx(condition, user, payer, programIds) {
|
|
18137
18206
|
const [yesMint] = PDA.yesMint(condition, programIds);
|
|
@@ -18201,6 +18270,6 @@ function buildApproveAllOutcomeTokensTx(condition, signer, payer, delegate, prog
|
|
|
18201
18270
|
return tx;
|
|
18202
18271
|
}
|
|
18203
18272
|
|
|
18204
|
-
export { AccountNotFoundError, AdminClient, ClobClient, CtfClient, DisputeClient, FEE_DENOMINATOR, FeeManagementClient, IX_SYSVAR, InvalidParamError, MAX_APPROVE_AMOUNT, MarketClient, MarketOracleClient, OracleClient, PDA, PresaleClient, QuestionStatus, ReferralClient, SEEDS, UnauthorizedError, XMarketError, XMarketSDK, buildApproveAllOutcomeTokensTx, buildApproveCollateralTx, buildBatchedCollectFeeEd25519Instruction, buildBatchedEd25519Instruction, buildBatchedRedeemFeeEd25519Instruction, buildCreateUserAtasTx, buildOrder, buildOrderFromPrice, deserializeSignedOrder, detectMatchType, generateContentHash, generateQuestionId, getOrderSignBytes, orderAmountsFromPrice, serializeCollectFeeOrderToBytes, serializeOrderToBytes, serializeRedeemFeeOrderToBytes, serializeSignedOrder, signOrder, signOrderWithKeypair, verifySignedOrder };
|
|
18273
|
+
export { AccountNotFoundError, AdminClient, ClobClient, CtfClient, DEVNET_CONFIG, DEVNET_MARKET_OWNER, DEVNET_QUESTION_MARKET_CONFIG, DEVNET_USDC_MINT, DisputeClient, FEE_DENOMINATOR, FeeManagementClient, IX_SYSVAR, InvalidParamError, MAINNET_CONFIG, MAINNET_USDC_MINT, MAX_APPROVE_AMOUNT, MarketClient, MarketOracleClient, OracleClient, PDA, PresaleClient, QuestionStatus, ReferralClient, SEEDS, UnauthorizedError, V2_PROGRAM_IDS, XMarketError, XMarketSDK, buildApproveAllOutcomeTokensTx, buildApproveCollateralTx, buildBatchedCollectFeeEd25519Instruction, buildBatchedEd25519Instruction, buildBatchedRedeemFeeEd25519Instruction, buildCreateUserAtasTx, buildOrder, buildOrderFromPrice, deserializeSignedOrder, detectMatchType, generateContentHash, generateQuestionId, getOrderSignBytes, orderAmountsFromPrice, serializeCollectFeeOrderToBytes, serializeOrderToBytes, serializeRedeemFeeOrderToBytes, serializeSignedOrder, signOrder, signOrderWithKeypair, verifySignedOrder };
|
|
18205
18274
|
//# sourceMappingURL=index.mjs.map
|
|
18206
18275
|
//# sourceMappingURL=index.mjs.map
|