@theliem/xmarket-sdk 3.1.0 → 3.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 +11 -17
- package/dist/index.d.ts +11 -17
- package/dist/index.js +43 -58
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +44 -59
- package/dist/index.mjs.map +1 -1
- package/dist/{oracle-A5VOIMGM.json → oracle-O53KMXDK.json} +119 -155
- package/dist/{presale-ZZJXXQS3.json → presale-Q4NDVQFN.json} +169 -0
- package/dist/{question_market-77YI4LRP.json → question_market-RP3J3N2M.json} +492 -369
- package/package.json +1 -1
- package/src/idls/oracle.json +119 -155
- package/src/idls/presale.json +169 -0
- package/src/idls/question_market.json +492 -369
package/dist/index.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import * as anchor4 from '@coral-xyz/anchor';
|
|
2
|
-
import {
|
|
2
|
+
import { PublicKey, SYSVAR_INSTRUCTIONS_PUBKEY, SystemProgram, SYSVAR_RENT_PUBKEY, TransactionInstruction, Ed25519Program, AddressLookupTableProgram, TransactionMessage, VersionedTransaction, Connection, Transaction } from '@solana/web3.js';
|
|
3
3
|
import { createHash } from 'crypto';
|
|
4
4
|
import { TOKEN_2022_PROGRAM_ID, getAssociatedTokenAddressSync, ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, createApproveInstruction } from '@solana/spl-token';
|
|
5
|
-
import oracleIdl from './oracle-
|
|
5
|
+
import oracleIdl from './oracle-O53KMXDK.json';
|
|
6
6
|
import hookIdl from './hook-THBRGUM6.json';
|
|
7
|
-
import questionMarketIdl from './question_market-
|
|
7
|
+
import questionMarketIdl from './question_market-RP3J3N2M.json';
|
|
8
8
|
import conditionalTokensIdl from './conditional_tokens-3O5V46N5.json';
|
|
9
9
|
import clobExchangeIdl from './clob_exchange-MQF4NI27.json';
|
|
10
10
|
import feeManagementIdl from './fee_management-VGF77YXG.json';
|
|
11
|
-
import presaleIdl from './presale-
|
|
11
|
+
import presaleIdl from './presale-Q4NDVQFN.json';
|
|
12
12
|
import marketOracleIdl from './market_oracle-E6UUARGR.json';
|
|
13
13
|
import BN4 from 'bn.js';
|
|
14
14
|
import * as nacl from 'tweetnacl';
|
|
@@ -253,7 +253,7 @@ var OracleClient = class {
|
|
|
253
253
|
}).rpc();
|
|
254
254
|
return { signature: sig };
|
|
255
255
|
}
|
|
256
|
-
/** Admin or owner adds an address to the oracle whitelist. */
|
|
256
|
+
/** Admin or owner adds an address to the oracle resolver whitelist. */
|
|
257
257
|
async addToWhitelist(address, ownerPubkey) {
|
|
258
258
|
const sig = await this.program.methods.addToWhitelist(address).accounts({
|
|
259
259
|
authority: this.walletPubkey,
|
|
@@ -262,7 +262,7 @@ var OracleClient = class {
|
|
|
262
262
|
}).rpc();
|
|
263
263
|
return { signature: sig };
|
|
264
264
|
}
|
|
265
|
-
/** Admin or owner removes an address from the oracle whitelist. */
|
|
265
|
+
/** Admin or owner removes an address from the oracle resolver whitelist. */
|
|
266
266
|
async removeFromWhitelist(address, ownerPubkey) {
|
|
267
267
|
const sig = await this.program.methods.removeFromWhitelist(address).accounts({
|
|
268
268
|
authority: this.walletPubkey,
|
|
@@ -510,6 +510,7 @@ var InvalidParamError = class extends XMarketError {
|
|
|
510
510
|
};
|
|
511
511
|
|
|
512
512
|
// src/programs/market.ts
|
|
513
|
+
var TOKEN_METADATA_PROGRAM_ID = new PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s");
|
|
513
514
|
var MarketClient = class {
|
|
514
515
|
constructor(program, provider, programIds, ownerPubkey) {
|
|
515
516
|
this.program = program;
|
|
@@ -532,45 +533,6 @@ var MarketClient = class {
|
|
|
532
533
|
systemProgram: SystemProgram.programId
|
|
533
534
|
}).transaction();
|
|
534
535
|
}
|
|
535
|
-
/**
|
|
536
|
-
* Build createQuestion transaction.
|
|
537
|
-
* @param payer - Pays rent for all new accounts (can differ from creator)
|
|
538
|
-
* @param creator - Identity of the question creator (signs but does not pay)
|
|
539
|
-
*/
|
|
540
|
-
async createQuestion(params, oracle, creator = this.walletPubkey, payer = this.walletPubkey) {
|
|
541
|
-
const questionId = params.questionId ?? generateQuestionId(params.content);
|
|
542
|
-
const contentHash = params.contentHash ?? generateContentHash(params.content);
|
|
543
|
-
const [questionPda] = PDA.question(this.configPda, questionId, this.programIds);
|
|
544
|
-
const [conditionPda] = PDA.condition(oracle, questionId, this.programIds);
|
|
545
|
-
const [yesMint] = PDA.yesMint(conditionPda, this.programIds);
|
|
546
|
-
const [noMint] = PDA.noMint(conditionPda, this.programIds);
|
|
547
|
-
const [mintAuthority] = PDA.mintAuthority(conditionPda, this.programIds);
|
|
548
|
-
const [collateralVault] = PDA.collateralVault(params.collateralMint, this.programIds);
|
|
549
|
-
const tx = await this.program.methods.createQuestionWithCondition({
|
|
550
|
-
questionId: Array.from(questionId),
|
|
551
|
-
contentHash: Array.from(contentHash),
|
|
552
|
-
hookProgram: params.hookProgram,
|
|
553
|
-
authorizedClob: params.authorizedClob,
|
|
554
|
-
expirationTime: new anchor4.BN(params.expirationTime)
|
|
555
|
-
}).accounts({
|
|
556
|
-
payer,
|
|
557
|
-
creator,
|
|
558
|
-
config: this.configPda,
|
|
559
|
-
question: questionPda,
|
|
560
|
-
currencyMint: params.collateralMint,
|
|
561
|
-
oracle,
|
|
562
|
-
condition: conditionPda,
|
|
563
|
-
yesMint,
|
|
564
|
-
noMint,
|
|
565
|
-
mintAuthority,
|
|
566
|
-
collateralVault,
|
|
567
|
-
conditionalTokensProgram: this.programIds.conditionalTokens,
|
|
568
|
-
tokenProgram: TOKEN_2022_PROGRAM_ID,
|
|
569
|
-
systemProgram: SystemProgram.programId,
|
|
570
|
-
rent: SYSVAR_RENT_PUBKEY
|
|
571
|
-
}).transaction();
|
|
572
|
-
return { tx, questionPda, conditionPda, questionId };
|
|
573
|
-
}
|
|
574
536
|
/**
|
|
575
537
|
* Build createQuestionAdmin transaction (whitelist/admin path — status = Approved immediately).
|
|
576
538
|
* @param creator - Whitelisted creator (must be in whitelist or be admin/owner)
|
|
@@ -740,6 +702,10 @@ var MarketClient = class {
|
|
|
740
702
|
const presaleVault = getAssociatedTokenAddressSync(currencyMint, presalePda, true);
|
|
741
703
|
const creatorQtAta = getAssociatedTokenAddressSync(qtMint, creator);
|
|
742
704
|
const creatorCurrencyAta = getAssociatedTokenAddressSync(currencyMint, creator);
|
|
705
|
+
const [qtMetadata] = PublicKey.findProgramAddressSync(
|
|
706
|
+
[Buffer.from("metadata"), TOKEN_METADATA_PROGRAM_ID.toBuffer(), qtMint.toBuffer()],
|
|
707
|
+
TOKEN_METADATA_PROGRAM_ID
|
|
708
|
+
);
|
|
743
709
|
const tx = await this.program.methods.createPresale({
|
|
744
710
|
price: params.price,
|
|
745
711
|
startTime: params.startTime,
|
|
@@ -758,6 +724,8 @@ var MarketClient = class {
|
|
|
758
724
|
creatorCurrencyAta,
|
|
759
725
|
creatorQtAta,
|
|
760
726
|
userBuyRecord,
|
|
727
|
+
qtMetadata,
|
|
728
|
+
tokenMetadataProgram: TOKEN_METADATA_PROGRAM_ID,
|
|
761
729
|
presaleProgram: this.programIds.presale,
|
|
762
730
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
763
731
|
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
@@ -968,7 +936,7 @@ var CtfClient = class {
|
|
|
968
936
|
* Split `amount` collateral into equal YES + NO tokens.
|
|
969
937
|
* ATAs created automatically via `init_if_needed`.
|
|
970
938
|
*/
|
|
971
|
-
async splitPosition(condition, collateralMint, amount, user = this.walletPubkey, payer = this.walletPubkey
|
|
939
|
+
async splitPosition(condition, collateralMint, amount, user = this.walletPubkey, payer = this.walletPubkey) {
|
|
972
940
|
const [collateralVault] = PDA.collateralVault(collateralMint, this.programIds);
|
|
973
941
|
const [vaultTokenAccount] = PDA.vaultToken(collateralMint, this.programIds);
|
|
974
942
|
const [yesMint] = PDA.yesMint(condition, this.programIds);
|
|
@@ -979,7 +947,7 @@ var CtfClient = class {
|
|
|
979
947
|
const userYesAta = getAssociatedTokenAddressSync(yesMint, user, false, TOKEN_2022_PROGRAM_ID);
|
|
980
948
|
const userNoAta = getAssociatedTokenAddressSync(noMint, user, false, TOKEN_2022_PROGRAM_ID);
|
|
981
949
|
const userCollateral = getAssociatedTokenAddressSync(collateralMint, user);
|
|
982
|
-
|
|
950
|
+
return this.program.methods.splitPosition(amount).accounts({
|
|
983
951
|
user,
|
|
984
952
|
payer,
|
|
985
953
|
condition,
|
|
@@ -997,14 +965,13 @@ var CtfClient = class {
|
|
|
997
965
|
token2022Program: TOKEN_2022_PROGRAM_ID,
|
|
998
966
|
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
999
967
|
systemProgram: SystemProgram.programId
|
|
1000
|
-
}).
|
|
1001
|
-
return { signature: sig };
|
|
968
|
+
}).transaction();
|
|
1002
969
|
}
|
|
1003
970
|
/**
|
|
1004
971
|
* Merge `amount` YES + NO tokens back into collateral.
|
|
1005
972
|
* Both token balances must be ≥ amount.
|
|
1006
973
|
*/
|
|
1007
|
-
async mergePosition(condition, collateralMint, amount, user = this.walletPubkey, payer = this.walletPubkey
|
|
974
|
+
async mergePosition(condition, collateralMint, amount, user = this.walletPubkey, payer = this.walletPubkey) {
|
|
1008
975
|
const [collateralVault] = PDA.collateralVault(collateralMint, this.programIds);
|
|
1009
976
|
const [vaultTokenAccount] = PDA.vaultToken(collateralMint, this.programIds);
|
|
1010
977
|
const [yesMint] = PDA.yesMint(condition, this.programIds);
|
|
@@ -1014,7 +981,7 @@ var CtfClient = class {
|
|
|
1014
981
|
const userYesAta = getAssociatedTokenAddressSync(yesMint, user, false, TOKEN_2022_PROGRAM_ID);
|
|
1015
982
|
const userNoAta = getAssociatedTokenAddressSync(noMint, user, false, TOKEN_2022_PROGRAM_ID);
|
|
1016
983
|
const userCollateral = getAssociatedTokenAddressSync(collateralMint, user);
|
|
1017
|
-
|
|
984
|
+
return this.program.methods.mergePosition(amount).accounts({
|
|
1018
985
|
user,
|
|
1019
986
|
payer,
|
|
1020
987
|
condition,
|
|
@@ -1030,14 +997,13 @@ var CtfClient = class {
|
|
|
1030
997
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
1031
998
|
token2022Program: TOKEN_2022_PROGRAM_ID,
|
|
1032
999
|
systemProgram: SystemProgram.programId
|
|
1033
|
-
}).
|
|
1034
|
-
return { signature: sig };
|
|
1000
|
+
}).transaction();
|
|
1035
1001
|
}
|
|
1036
1002
|
/**
|
|
1037
1003
|
* After condition resolves: burn outcome tokens proportional to payout
|
|
1038
1004
|
* and receive USDC. Works for winning, losing, or both positions.
|
|
1039
1005
|
*/
|
|
1040
|
-
async redeemPositions(condition, collateralMint, user = this.walletPubkey, payer = this.walletPubkey
|
|
1006
|
+
async redeemPositions(condition, collateralMint, user = this.walletPubkey, payer = this.walletPubkey) {
|
|
1041
1007
|
const [collateralVault] = PDA.collateralVault(collateralMint, this.programIds);
|
|
1042
1008
|
const [vaultTokenAccount] = PDA.vaultToken(collateralMint, this.programIds);
|
|
1043
1009
|
const [yesMint] = PDA.yesMint(condition, this.programIds);
|
|
@@ -1047,7 +1013,7 @@ var CtfClient = class {
|
|
|
1047
1013
|
const userYesAta = getAssociatedTokenAddressSync(yesMint, user, false, TOKEN_2022_PROGRAM_ID);
|
|
1048
1014
|
const userNoAta = getAssociatedTokenAddressSync(noMint, user, false, TOKEN_2022_PROGRAM_ID);
|
|
1049
1015
|
const userCollateral = getAssociatedTokenAddressSync(collateralMint, user);
|
|
1050
|
-
|
|
1016
|
+
return this.program.methods.redeemPositions().accounts({
|
|
1051
1017
|
user,
|
|
1052
1018
|
payer,
|
|
1053
1019
|
condition,
|
|
@@ -1063,8 +1029,7 @@ var CtfClient = class {
|
|
|
1063
1029
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
1064
1030
|
token2022Program: TOKEN_2022_PROGRAM_ID,
|
|
1065
1031
|
systemProgram: SystemProgram.programId
|
|
1066
|
-
}).
|
|
1067
|
-
return { signature: sig };
|
|
1032
|
+
}).transaction();
|
|
1068
1033
|
}
|
|
1069
1034
|
/**
|
|
1070
1035
|
* Oracle directly resolves a condition with payout numerators.
|
|
@@ -1405,8 +1370,8 @@ var ClobClient = class {
|
|
|
1405
1370
|
async _sendLegacyTx(instructions) {
|
|
1406
1371
|
const { connection } = this.provider;
|
|
1407
1372
|
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash();
|
|
1408
|
-
const { Transaction:
|
|
1409
|
-
const tx = new
|
|
1373
|
+
const { Transaction: Transaction5 } = await import('@solana/web3.js');
|
|
1374
|
+
const tx = new Transaction5();
|
|
1410
1375
|
tx.recentBlockhash = blockhash;
|
|
1411
1376
|
tx.feePayer = this.walletPubkey;
|
|
1412
1377
|
tx.add(...instructions);
|
|
@@ -2165,6 +2130,26 @@ var PresaleClient = class {
|
|
|
2165
2130
|
}).signers(signers).rpc();
|
|
2166
2131
|
return { signature: sig };
|
|
2167
2132
|
}
|
|
2133
|
+
/**
|
|
2134
|
+
* Transfer creator_claimable_revenue (80%) to BOTMM wallet.
|
|
2135
|
+
* Call after collectPresaleRevenue (distribute_presale_revenue).
|
|
2136
|
+
*/
|
|
2137
|
+
async distributeBotmmRevenue(presalePda, botmmAddress, currencyMint) {
|
|
2138
|
+
if (!currencyMint) {
|
|
2139
|
+
const presale = await this.fetchPresale(presalePda);
|
|
2140
|
+
if (!presale) throw new Error(`Presale not found: ${presalePda.toBase58()}`);
|
|
2141
|
+
currencyMint = presale.currencyMint;
|
|
2142
|
+
}
|
|
2143
|
+
const presaleVault = getAssociatedTokenAddressSync(currencyMint, presalePda, true);
|
|
2144
|
+
const botmmTokenAccount = getAssociatedTokenAddressSync(currencyMint, botmmAddress);
|
|
2145
|
+
return this.program.methods.distributeBotmmRevenue().accounts({
|
|
2146
|
+
presale: presalePda,
|
|
2147
|
+
presaleVault,
|
|
2148
|
+
currencyMint,
|
|
2149
|
+
botmmTokenAccount,
|
|
2150
|
+
tokenProgram: TOKEN_PROGRAM_ID
|
|
2151
|
+
}).transaction();
|
|
2152
|
+
}
|
|
2168
2153
|
// ─── Queries ─────────────────────────────────────────────────────────────────
|
|
2169
2154
|
async fetchPresale(presalePda) {
|
|
2170
2155
|
try {
|