@cypher-zk/sdk 0.7.3 → 0.7.5
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/{client-BECBXFEY.d.ts → client-C6xXOySs.d.ts} +840 -452
- package/dist/cypher-3HKPZR2F.json +6053 -0
- package/dist/index.d.ts +66 -58
- package/dist/index.js +220 -117
- package/dist/index.js.map +1 -1
- package/dist/react/index.d.ts +6 -2
- package/dist/react/index.js.map +1 -1
- package/package.json +1 -1
- package/src/idl/cypher.json +780 -438
- package/src/idl/cypher.ts +780 -438
- package/src/idl/cypher.ts.bak +5717 -0
- /package/{dist/cypher-G57ZWFM3.json → src/idl/cypher.json.bak} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __commonJS, __toESM } from './chunk-5WRI5ZAA.js';
|
|
2
|
-
import idlJson from './cypher-
|
|
2
|
+
import idlJson from './cypher-3HKPZR2F.json';
|
|
3
3
|
import { PublicKey, AddressLookupTableProgram, SystemProgram, Transaction } from '@solana/web3.js';
|
|
4
4
|
import { BN, AnchorProvider, Program, BorshCoder, EventParser } from '@anchor-lang/core';
|
|
5
5
|
import { TOKEN_PROGRAM_ID, getAssociatedTokenAddressSync } from '@solana/spl-token';
|
|
@@ -1953,7 +1953,7 @@ var require_src = __commonJS({
|
|
|
1953
1953
|
}
|
|
1954
1954
|
return vch;
|
|
1955
1955
|
}
|
|
1956
|
-
function
|
|
1956
|
+
function decode6(string) {
|
|
1957
1957
|
var buffer = decodeUnsafe(string);
|
|
1958
1958
|
if (buffer) {
|
|
1959
1959
|
return buffer;
|
|
@@ -1963,7 +1963,7 @@ var require_src = __commonJS({
|
|
|
1963
1963
|
return {
|
|
1964
1964
|
encode,
|
|
1965
1965
|
decodeUnsafe,
|
|
1966
|
-
decode:
|
|
1966
|
+
decode: decode6
|
|
1967
1967
|
};
|
|
1968
1968
|
}
|
|
1969
1969
|
module.exports = base;
|
|
@@ -2075,6 +2075,12 @@ function lpPositionPda(market, creator, programId = PROGRAM_ID) {
|
|
|
2075
2075
|
programId
|
|
2076
2076
|
);
|
|
2077
2077
|
}
|
|
2078
|
+
function marketQuestionPda(market, programId = PROGRAM_ID) {
|
|
2079
|
+
return PublicKey.findProgramAddressSync(
|
|
2080
|
+
[Buffer.from("market_question"), market.toBuffer()],
|
|
2081
|
+
programId
|
|
2082
|
+
);
|
|
2083
|
+
}
|
|
2078
2084
|
function arciumSignerPda(programId = PROGRAM_ID) {
|
|
2079
2085
|
return PublicKey.findProgramAddressSync(
|
|
2080
2086
|
[Buffer.from("ArciumSignerAccount")],
|
|
@@ -2215,21 +2221,23 @@ var CypherErrorCode = {
|
|
|
2215
2221
|
ResolutionDeadlineNotReached: 6025,
|
|
2216
2222
|
ClaimPeriodExpired: 6026,
|
|
2217
2223
|
RefundPeriodExpired: 6027,
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2224
|
+
ComputationAlreadyQueued: 6028,
|
|
2225
|
+
AbortedComputation: 6029,
|
|
2226
|
+
ComputationVerificationFailed: 6030,
|
|
2227
|
+
CannotWithdrawFromUnresolved: 6031,
|
|
2228
|
+
AdminAlreadyClaimed: 6032,
|
|
2229
|
+
WrongMarketType: 6033,
|
|
2230
|
+
WrongMint: 6034,
|
|
2231
|
+
NotAcceptedMint: 6035,
|
|
2232
|
+
InvalidCategory: 6036,
|
|
2233
|
+
InvalidChallengePeriod: 6037,
|
|
2234
|
+
BondTooSmall: 6038,
|
|
2235
|
+
NotPendingResolution: 6039,
|
|
2236
|
+
ChallengePeriodNotElapsed: 6040,
|
|
2237
|
+
ChallengePeriodElapsed: 6041,
|
|
2238
|
+
MarketDisputed: 6042,
|
|
2239
|
+
MarketNotDisputed: 6043,
|
|
2240
|
+
UnauthorizedUser: 6044
|
|
2233
2241
|
};
|
|
2234
2242
|
var CYPHER_ERROR_MESSAGES = Object.freeze(
|
|
2235
2243
|
Object.fromEntries(
|
|
@@ -2328,45 +2336,43 @@ var import_bs58 = __toESM(require_bs58(), 1);
|
|
|
2328
2336
|
// src/accounts/layout.ts
|
|
2329
2337
|
var MARKET_OFFSETS = {
|
|
2330
2338
|
marketId: 0,
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
bump: 578,
|
|
2369
|
-
vaultBump: 579
|
|
2339
|
+
marketType: 8,
|
|
2340
|
+
numOutcomes: 9,
|
|
2341
|
+
category: 10,
|
|
2342
|
+
creator: 11,
|
|
2343
|
+
resolver: 43,
|
|
2344
|
+
creatorBond: 75,
|
|
2345
|
+
bondWithdrawn: 83,
|
|
2346
|
+
totalBetsCount: 84,
|
|
2347
|
+
encryptedPool0: 92,
|
|
2348
|
+
encryptedPool1: 124,
|
|
2349
|
+
encryptedPool2: 156,
|
|
2350
|
+
encryptedPool3: 188,
|
|
2351
|
+
mxeNonce: 220,
|
|
2352
|
+
revealedPool0: 236,
|
|
2353
|
+
revealedPool1: 244,
|
|
2354
|
+
revealedPool2: 252,
|
|
2355
|
+
revealedPool3: 260,
|
|
2356
|
+
state: 268,
|
|
2357
|
+
outcome: 269,
|
|
2358
|
+
pendingOutcome: 270,
|
|
2359
|
+
closeTime: 271,
|
|
2360
|
+
resolutionTime: 279,
|
|
2361
|
+
payoutRatio: 287,
|
|
2362
|
+
accumulatedLpFees: 295,
|
|
2363
|
+
accumulatedProtocolFees: 303,
|
|
2364
|
+
minBet: 311,
|
|
2365
|
+
totalPayoutsClaimed: 319,
|
|
2366
|
+
totalRefundsClaimed: 327,
|
|
2367
|
+
adminClaimedRemaining: 335,
|
|
2368
|
+
resolutionDeadline: 336,
|
|
2369
|
+
claimDeadline: 344,
|
|
2370
|
+
refundDeadline: 352,
|
|
2371
|
+
challengePeriod: 360,
|
|
2372
|
+
challengeDeadline: 368,
|
|
2373
|
+
disputed: 376,
|
|
2374
|
+
bump: 377,
|
|
2375
|
+
vaultBump: 378
|
|
2370
2376
|
};
|
|
2371
2377
|
var ENCRYPTED_POSITION_OFFSETS = {
|
|
2372
2378
|
user: 0,
|
|
@@ -2378,7 +2384,13 @@ var ENCRYPTED_POSITION_OFFSETS = {
|
|
|
2378
2384
|
entryOdds: 176,
|
|
2379
2385
|
netAmount: 184,
|
|
2380
2386
|
claimed: 192,
|
|
2381
|
-
|
|
2387
|
+
computationQueued: 193,
|
|
2388
|
+
bump: 194
|
|
2389
|
+
};
|
|
2390
|
+
var MARKET_QUESTION_OFFSETS = {
|
|
2391
|
+
question: 0,
|
|
2392
|
+
questionLen: 200,
|
|
2393
|
+
bump: 201
|
|
2382
2394
|
};
|
|
2383
2395
|
var LP_POSITION_OFFSETS = {
|
|
2384
2396
|
lpProvider: 0,
|
|
@@ -2440,13 +2452,27 @@ var lpPositionFilters = {
|
|
|
2440
2452
|
};
|
|
2441
2453
|
|
|
2442
2454
|
// src/accounts/market.ts
|
|
2455
|
+
function decodeMarketAccount(client, data) {
|
|
2456
|
+
const coder = client.program.coder.accounts;
|
|
2457
|
+
return coder.decode("market", Buffer.from(data));
|
|
2458
|
+
}
|
|
2459
|
+
async function gpaFetchMarkets(client, extraFilters = []) {
|
|
2460
|
+
const rawAccounts = await client.connection.getProgramAccounts(client.programId, {
|
|
2461
|
+
filters: [marketFilters.discriminator(), ...extraFilters]
|
|
2462
|
+
});
|
|
2463
|
+
const results = [];
|
|
2464
|
+
for (const { pubkey, account } of rawAccounts) {
|
|
2465
|
+
try {
|
|
2466
|
+
const raw = decodeMarketAccount(client, account.data);
|
|
2467
|
+
results.push({ publicKey: pubkey, account: decode2(raw) });
|
|
2468
|
+
} catch {
|
|
2469
|
+
}
|
|
2470
|
+
}
|
|
2471
|
+
return results;
|
|
2472
|
+
}
|
|
2443
2473
|
function decode2(raw) {
|
|
2444
|
-
const questionLen = raw.questionLen;
|
|
2445
|
-
const question = Buffer.from(raw.question.slice(0, questionLen)).toString("utf8");
|
|
2446
2474
|
return {
|
|
2447
2475
|
marketId: BigInt(raw.marketId.toString()),
|
|
2448
|
-
question,
|
|
2449
|
-
questionLen,
|
|
2450
2476
|
marketType: raw.marketType,
|
|
2451
2477
|
numOutcomes: raw.numOutcomes,
|
|
2452
2478
|
category: raw.category,
|
|
@@ -2486,25 +2512,24 @@ function decode2(raw) {
|
|
|
2486
2512
|
vaultBump: raw.vaultBump
|
|
2487
2513
|
};
|
|
2488
2514
|
}
|
|
2489
|
-
function marketAccountFacade(client) {
|
|
2490
|
-
return client.program.account.market;
|
|
2491
|
-
}
|
|
2492
2515
|
async function fetchMarket(client, idOrPda) {
|
|
2493
2516
|
const pda = idOrPda instanceof PublicKey ? idOrPda : marketPda(idOrPda, client.programId)[0];
|
|
2494
|
-
const
|
|
2495
|
-
|
|
2517
|
+
const accountInfo = await client.connection.getAccountInfo(pda);
|
|
2518
|
+
if (!accountInfo) return null;
|
|
2519
|
+
try {
|
|
2520
|
+
return decode2(decodeMarketAccount(client, accountInfo.data));
|
|
2521
|
+
} catch {
|
|
2522
|
+
return null;
|
|
2523
|
+
}
|
|
2496
2524
|
}
|
|
2497
2525
|
async function fetchAllMarkets(client) {
|
|
2498
|
-
|
|
2499
|
-
return raw.map(({ publicKey, account }) => ({ publicKey, account: decode2(account) }));
|
|
2526
|
+
return gpaFetchMarkets(client);
|
|
2500
2527
|
}
|
|
2501
2528
|
async function fetchMarketsByCreator(client, creator) {
|
|
2502
|
-
|
|
2503
|
-
return raw.map(({ publicKey, account }) => ({ publicKey, account: decode2(account) }));
|
|
2529
|
+
return gpaFetchMarkets(client, [marketFilters.byCreator(creator)]);
|
|
2504
2530
|
}
|
|
2505
2531
|
async function fetchMarketsByState(client, state) {
|
|
2506
|
-
|
|
2507
|
-
return raw.map(({ publicKey, account }) => ({ publicKey, account: decode2(account) }));
|
|
2532
|
+
return gpaFetchMarkets(client, [marketFilters.byState(state)]);
|
|
2508
2533
|
}
|
|
2509
2534
|
function decode3(raw) {
|
|
2510
2535
|
return {
|
|
@@ -2517,6 +2542,7 @@ function decode3(raw) {
|
|
|
2517
2542
|
entryOdds: BigInt(raw.entryOdds.toString()),
|
|
2518
2543
|
netAmount: BigInt(raw.netAmount.toString()),
|
|
2519
2544
|
claimed: raw.claimed,
|
|
2545
|
+
computationQueued: raw.computationQueued,
|
|
2520
2546
|
bump: raw.bump
|
|
2521
2547
|
};
|
|
2522
2548
|
}
|
|
@@ -2559,6 +2585,40 @@ async function fetchLpPositionsByProvider(client, provider) {
|
|
|
2559
2585
|
const raw = await facade2(client).all([lpPositionFilters.byProvider(provider)]);
|
|
2560
2586
|
return raw.map(({ publicKey, account }) => ({ publicKey, account: decode4(account) }));
|
|
2561
2587
|
}
|
|
2588
|
+
function decode5(raw) {
|
|
2589
|
+
const question = Buffer.from(raw.question.slice(0, raw.questionLen)).toString("utf8");
|
|
2590
|
+
return { question, questionLen: raw.questionLen, bump: raw.bump };
|
|
2591
|
+
}
|
|
2592
|
+
async function fetchMarketQuestion(client, market) {
|
|
2593
|
+
const [pda] = marketQuestionPda(market, client.programId);
|
|
2594
|
+
const info = await client.connection.getAccountInfo(pda);
|
|
2595
|
+
if (!info) return null;
|
|
2596
|
+
try {
|
|
2597
|
+
const coder = client.program.coder.accounts;
|
|
2598
|
+
const raw = coder.decode("marketQuestion", Buffer.from(info.data));
|
|
2599
|
+
return decode5(raw);
|
|
2600
|
+
} catch {
|
|
2601
|
+
return null;
|
|
2602
|
+
}
|
|
2603
|
+
}
|
|
2604
|
+
async function fetchMarketQuestions(client, markets) {
|
|
2605
|
+
if (!markets.length) return /* @__PURE__ */ new Map();
|
|
2606
|
+
const pdas = markets.map(({ publicKey }) => marketQuestionPda(publicKey, client.programId)[0]);
|
|
2607
|
+
const infos = await client.connection.getMultipleAccountsInfo(pdas);
|
|
2608
|
+
const coder = client.program.coder.accounts;
|
|
2609
|
+
const map = /* @__PURE__ */ new Map();
|
|
2610
|
+
markets.forEach(({ publicKey }, i) => {
|
|
2611
|
+
try {
|
|
2612
|
+
const info = infos[i];
|
|
2613
|
+
if (info) {
|
|
2614
|
+
const raw = coder.decode("marketQuestion", Buffer.from(info.data));
|
|
2615
|
+
map.set(publicKey.toBase58(), decode5(raw).question);
|
|
2616
|
+
}
|
|
2617
|
+
} catch {
|
|
2618
|
+
}
|
|
2619
|
+
});
|
|
2620
|
+
return map;
|
|
2621
|
+
}
|
|
2562
2622
|
|
|
2563
2623
|
// src/instructions/admin.ts
|
|
2564
2624
|
async function initializeIx(client, params) {
|
|
@@ -2578,6 +2638,7 @@ async function initializeIx(client, params) {
|
|
|
2578
2638
|
globalState: gsPda,
|
|
2579
2639
|
protocolTreasury: params.protocolTreasury,
|
|
2580
2640
|
acceptedMint: params.acceptedMint,
|
|
2641
|
+
tokenProgram: client.tokenProgram,
|
|
2581
2642
|
systemProgram: SystemProgram.programId
|
|
2582
2643
|
}).instruction();
|
|
2583
2644
|
}
|
|
@@ -2587,7 +2648,8 @@ async function updateAcceptedMintIx(client, params) {
|
|
|
2587
2648
|
admin: params.admin,
|
|
2588
2649
|
globalState: gsPda,
|
|
2589
2650
|
newMint: params.newMint,
|
|
2590
|
-
newTreasury: params.newTreasury
|
|
2651
|
+
newTreasury: params.newTreasury,
|
|
2652
|
+
tokenProgram: client.tokenProgram
|
|
2591
2653
|
}).instruction();
|
|
2592
2654
|
}
|
|
2593
2655
|
async function adminClaimRemainingIx(client, params) {
|
|
@@ -2690,6 +2752,7 @@ async function createMarketIx(client, params) {
|
|
|
2690
2752
|
validateMarketDraft(params);
|
|
2691
2753
|
const [gsPda] = globalStatePda(client.programId);
|
|
2692
2754
|
const [marketPdaKey] = marketPda(toBN(params.expectedMarketId), client.programId);
|
|
2755
|
+
const [questionPda] = marketQuestionPda(marketPdaKey, client.programId);
|
|
2693
2756
|
const [vaultPda] = marketVaultPda(marketPdaKey, client.programId);
|
|
2694
2757
|
const [lpPda] = lpPositionPda(marketPdaKey, params.creator, client.programId);
|
|
2695
2758
|
const creatorAta = userAta(params.creator, params.acceptedMint, client.tokenProgram);
|
|
@@ -2703,6 +2766,7 @@ async function createMarketIx(client, params) {
|
|
|
2703
2766
|
creator: params.creator,
|
|
2704
2767
|
globalState: gsPda,
|
|
2705
2768
|
market: marketPdaKey,
|
|
2769
|
+
marketQuestion: questionPda,
|
|
2706
2770
|
lpPosition: lpPda,
|
|
2707
2771
|
marketVault: vaultPda,
|
|
2708
2772
|
creatorTokenAccount: creatorAta,
|
|
@@ -2720,6 +2784,7 @@ async function createMarketMultiIx(client, params) {
|
|
|
2720
2784
|
}
|
|
2721
2785
|
const [gsPda] = globalStatePda(client.programId);
|
|
2722
2786
|
const [marketPdaKey] = marketPda(toBN(params.expectedMarketId), client.programId);
|
|
2787
|
+
const [questionPda] = marketQuestionPda(marketPdaKey, client.programId);
|
|
2723
2788
|
const [vaultPda] = marketVaultPda(marketPdaKey, client.programId);
|
|
2724
2789
|
const [lpPda] = lpPositionPda(marketPdaKey, params.creator, client.programId);
|
|
2725
2790
|
const creatorAta = userAta(params.creator, params.acceptedMint, client.tokenProgram);
|
|
@@ -2734,6 +2799,7 @@ async function createMarketMultiIx(client, params) {
|
|
|
2734
2799
|
creator: params.creator,
|
|
2735
2800
|
globalState: gsPda,
|
|
2736
2801
|
market: marketPdaKey,
|
|
2802
|
+
marketQuestion: questionPda,
|
|
2737
2803
|
lpPosition: lpPda,
|
|
2738
2804
|
marketVault: vaultPda,
|
|
2739
2805
|
creatorTokenAccount: creatorAta,
|
|
@@ -2743,6 +2809,7 @@ async function createMarketMultiIx(client, params) {
|
|
|
2743
2809
|
}).instruction();
|
|
2744
2810
|
}
|
|
2745
2811
|
async function cancelMarketIx(client, params) {
|
|
2812
|
+
const [gsPda] = globalStatePda(client.programId);
|
|
2746
2813
|
const [marketPdaKey] = marketPda(toBN(params.marketId), client.programId);
|
|
2747
2814
|
const [vaultPda] = marketVaultPda(marketPdaKey, client.programId);
|
|
2748
2815
|
const [lpPda] = lpPositionPda(marketPdaKey, params.creator, client.programId);
|
|
@@ -2750,6 +2817,7 @@ async function cancelMarketIx(client, params) {
|
|
|
2750
2817
|
return method(client, "cancelMarket")().accountsPartial({
|
|
2751
2818
|
creator: params.creator,
|
|
2752
2819
|
market: marketPdaKey,
|
|
2820
|
+
globalState: gsPda,
|
|
2753
2821
|
marketVault: vaultPda,
|
|
2754
2822
|
lpPosition: lpPda,
|
|
2755
2823
|
creatorTokenAccount: creatorAta,
|
|
@@ -2757,6 +2825,7 @@ async function cancelMarketIx(client, params) {
|
|
|
2757
2825
|
}).instruction();
|
|
2758
2826
|
}
|
|
2759
2827
|
async function withdrawCreatorFundsIx(client, params) {
|
|
2828
|
+
const [gsPda] = globalStatePda(client.programId);
|
|
2760
2829
|
const [marketPdaKey] = marketPda(toBN(params.marketId), client.programId);
|
|
2761
2830
|
const [vaultPda] = marketVaultPda(marketPdaKey, client.programId);
|
|
2762
2831
|
const [lpPda] = lpPositionPda(marketPdaKey, params.creator, client.programId);
|
|
@@ -2765,6 +2834,7 @@ async function withdrawCreatorFundsIx(client, params) {
|
|
|
2765
2834
|
creator: params.creator,
|
|
2766
2835
|
market: marketPdaKey,
|
|
2767
2836
|
lpPosition: lpPda,
|
|
2837
|
+
globalState: gsPda,
|
|
2768
2838
|
marketVault: vaultPda,
|
|
2769
2839
|
creatorTokenAccount: creatorAta,
|
|
2770
2840
|
tokenProgram: client.tokenProgram
|
|
@@ -2823,39 +2893,54 @@ async function fetchMxeLookupTable(client) {
|
|
|
2823
2893
|
}
|
|
2824
2894
|
|
|
2825
2895
|
// src/instructions/bet.ts
|
|
2826
|
-
function assertU8(name, v) {
|
|
2827
|
-
if (!Number.isInteger(v) || v < 0 || v > 255) {
|
|
2828
|
-
throw new Error(`placePrivateBet*Ix: ${name} must be a u8`);
|
|
2829
|
-
}
|
|
2830
|
-
}
|
|
2831
2896
|
function assertCiphertext(name, v) {
|
|
2832
2897
|
if (v.length !== 32) {
|
|
2833
2898
|
throw new Error(`placePrivateBet*Ix: ${name} must be exactly 32 bytes`);
|
|
2834
2899
|
}
|
|
2835
2900
|
}
|
|
2836
|
-
async function buildPlaceBetIx(client,
|
|
2901
|
+
async function buildPlaceBetIx(client, methodName, params) {
|
|
2837
2902
|
assertCiphertext("encryptedAmount", params.encryptedAmount);
|
|
2838
2903
|
assertCiphertext("encryptedSide", params.encryptedSide);
|
|
2839
2904
|
assertCiphertext("userX25519Pubkey", params.userX25519Pubkey);
|
|
2840
|
-
assertU8("(amount sanity)", 0);
|
|
2841
2905
|
const [gsPda] = globalStatePda(client.programId);
|
|
2842
2906
|
const [marketPdaKey] = marketPda(toBN(params.marketId), client.programId);
|
|
2843
2907
|
const [vaultPda] = marketVaultPda(marketPdaKey, client.programId);
|
|
2844
2908
|
const [positionPdaKey] = positionPda(marketPdaKey, params.user, client.programId);
|
|
2845
2909
|
const userTokenAccount = userAta(params.user, params.acceptedMint, client.tokenProgram);
|
|
2846
|
-
const arcium = buildArciumQueueAccounts(client, {
|
|
2847
|
-
circuit,
|
|
2848
|
-
computationOffset: toBN(params.computationOffset),
|
|
2849
|
-
addressLookupTable: params.addressLookupTable
|
|
2850
|
-
});
|
|
2851
2910
|
return method(client, methodName)(
|
|
2852
|
-
toBN(params.computationOffset),
|
|
2853
2911
|
toBN(params.betAmountUsdc),
|
|
2854
2912
|
Array.from(params.encryptedAmount),
|
|
2855
2913
|
Array.from(params.encryptedSide),
|
|
2856
2914
|
Array.from(params.userX25519Pubkey),
|
|
2857
2915
|
toBN(params.nonce)
|
|
2858
2916
|
).accountsPartial({
|
|
2917
|
+
payer: params.payer,
|
|
2918
|
+
user: params.user,
|
|
2919
|
+
globalState: gsPda,
|
|
2920
|
+
market: marketPdaKey,
|
|
2921
|
+
marketVault: vaultPda,
|
|
2922
|
+
userTokenAccount,
|
|
2923
|
+
protocolTreasury: params.protocolTreasury,
|
|
2924
|
+
position: positionPdaKey,
|
|
2925
|
+
tokenProgram: client.tokenProgram,
|
|
2926
|
+
systemProgram: SystemProgram.programId
|
|
2927
|
+
}).instruction();
|
|
2928
|
+
}
|
|
2929
|
+
function placePrivateBetYesnoIx(client, params) {
|
|
2930
|
+
return buildPlaceBetIx(client, "placePrivateBetYesno", params);
|
|
2931
|
+
}
|
|
2932
|
+
function placePrivateBetMultiIx(client, params) {
|
|
2933
|
+
return buildPlaceBetIx(client, "placePrivateBetMulti", params);
|
|
2934
|
+
}
|
|
2935
|
+
async function buildSubmitBetIx(client, circuit, methodName, params) {
|
|
2936
|
+
const [marketPdaKey] = marketPda(toBN(params.marketId), client.programId);
|
|
2937
|
+
const [positionPdaKey] = positionPda(marketPdaKey, params.user, client.programId);
|
|
2938
|
+
const arcium = buildArciumQueueAccounts(client, {
|
|
2939
|
+
circuit,
|
|
2940
|
+
computationOffset: toBN(params.computationOffset),
|
|
2941
|
+
addressLookupTable: params.addressLookupTable
|
|
2942
|
+
});
|
|
2943
|
+
return method(client, methodName)(toBN(params.computationOffset)).accountsPartial({
|
|
2859
2944
|
payer: params.payer,
|
|
2860
2945
|
signPdaAccount: arcium.signPdaAccount,
|
|
2861
2946
|
mxeAccount: arcium.mxeAccount,
|
|
@@ -2869,30 +2954,25 @@ async function buildPlaceBetIx(client, circuit, methodName, params) {
|
|
|
2869
2954
|
systemProgram: SystemProgram.programId,
|
|
2870
2955
|
arciumProgram: arcium.arciumProgram,
|
|
2871
2956
|
user: params.user,
|
|
2872
|
-
globalState: gsPda,
|
|
2873
2957
|
market: marketPdaKey,
|
|
2874
|
-
|
|
2875
|
-
userTokenAccount,
|
|
2876
|
-
protocolTreasury: params.protocolTreasury,
|
|
2877
|
-
position: positionPdaKey,
|
|
2878
|
-
tokenProgram: client.tokenProgram
|
|
2958
|
+
position: positionPdaKey
|
|
2879
2959
|
}).instruction();
|
|
2880
2960
|
}
|
|
2881
|
-
function
|
|
2882
|
-
return
|
|
2883
|
-
client,
|
|
2884
|
-
CIRCUITS.placePrivateBetYesno,
|
|
2885
|
-
"placePrivateBetYesno",
|
|
2886
|
-
params
|
|
2887
|
-
);
|
|
2961
|
+
function submitBetYesnoIx(client, params) {
|
|
2962
|
+
return buildSubmitBetIx(client, CIRCUITS.placePrivateBetYesno, "submitBetYesno", params);
|
|
2888
2963
|
}
|
|
2889
|
-
function
|
|
2890
|
-
return
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
);
|
|
2964
|
+
function submitBetMultiIx(client, params) {
|
|
2965
|
+
return buildSubmitBetIx(client, CIRCUITS.placePrivateBetMulti, "submitBetMulti", params);
|
|
2966
|
+
}
|
|
2967
|
+
|
|
2968
|
+
// src/instructions/signPda.ts
|
|
2969
|
+
async function initSignPdaIx(client, params) {
|
|
2970
|
+
const [signPda] = arciumSignerPda(client.programId);
|
|
2971
|
+
return method(client, "initSignPda")().accountsPartial({
|
|
2972
|
+
payer: params.payer,
|
|
2973
|
+
signPdaAccount: signPda,
|
|
2974
|
+
systemProgram: SystemProgram.programId
|
|
2975
|
+
}).instruction();
|
|
2896
2976
|
}
|
|
2897
2977
|
|
|
2898
2978
|
// src/instructions/resolve.ts
|
|
@@ -2942,6 +3022,7 @@ function resolveMarketMultiIx(client, params) {
|
|
|
2942
3022
|
|
|
2943
3023
|
// src/instructions/claim.ts
|
|
2944
3024
|
async function buildClaimIx(client, circuit, methodName, params) {
|
|
3025
|
+
const [gsPda] = globalStatePda(client.programId);
|
|
2945
3026
|
const [marketPdaKey] = marketPda(toBN(params.marketId), client.programId);
|
|
2946
3027
|
const [vaultPda] = marketVaultPda(marketPdaKey, client.programId);
|
|
2947
3028
|
const [positionPdaKey] = positionPda(marketPdaKey, params.user, client.programId);
|
|
@@ -2967,6 +3048,7 @@ async function buildClaimIx(client, circuit, methodName, params) {
|
|
|
2967
3048
|
user: params.user,
|
|
2968
3049
|
market: marketPdaKey,
|
|
2969
3050
|
position: positionPdaKey,
|
|
3051
|
+
globalState: gsPda,
|
|
2970
3052
|
marketVault: vaultPda,
|
|
2971
3053
|
userTokenAccount,
|
|
2972
3054
|
tokenProgram: client.tokenProgram
|
|
@@ -3060,7 +3142,11 @@ function emitProgress(cb, stage, extra) {
|
|
|
3060
3142
|
}
|
|
3061
3143
|
}
|
|
3062
3144
|
async function sendIx(client, ix, opts = {}) {
|
|
3063
|
-
|
|
3145
|
+
return sendTx(client, [ix], opts);
|
|
3146
|
+
}
|
|
3147
|
+
async function sendTx(client, ixs, opts = {}) {
|
|
3148
|
+
const tx = new Transaction();
|
|
3149
|
+
for (const ix of ixs) tx.add(ix);
|
|
3064
3150
|
try {
|
|
3065
3151
|
return await client.provider.sendAndConfirm(
|
|
3066
3152
|
tx,
|
|
@@ -3305,26 +3391,36 @@ async function placeBetAction(client, inputs) {
|
|
|
3305
3391
|
const encrypted = encryptBetInput({ amount: netAmount, side: inputs.side }, cipher);
|
|
3306
3392
|
const computationOffset = inputs.computationOffset ?? randomComputationOffset();
|
|
3307
3393
|
const isMulti = market.marketType === MarketType.MultiOutcome;
|
|
3308
|
-
const
|
|
3309
|
-
const
|
|
3394
|
+
const placeBetBuilder = isMulti ? placePrivateBetMultiIx : placePrivateBetYesnoIx;
|
|
3395
|
+
const submitBetBuilder = isMulti ? submitBetMultiIx : submitBetYesnoIx;
|
|
3396
|
+
const placeBetParams = {
|
|
3310
3397
|
payer: inputs.payer,
|
|
3311
3398
|
user: inputs.user,
|
|
3312
3399
|
marketId: inputs.marketId,
|
|
3313
3400
|
acceptedMint: gs.acceptedMint,
|
|
3314
3401
|
protocolTreasury: gs.protocolTreasury,
|
|
3315
|
-
computationOffset,
|
|
3316
3402
|
betAmountUsdc: grossAmount,
|
|
3317
3403
|
encryptedAmount: encrypted.encryptedAmount,
|
|
3318
3404
|
encryptedSide: encrypted.encryptedSide,
|
|
3319
3405
|
userX25519Pubkey: userKeypair.publicKey,
|
|
3320
|
-
nonce: encrypted.nonce
|
|
3406
|
+
nonce: encrypted.nonce
|
|
3407
|
+
};
|
|
3408
|
+
const submitBetParams = {
|
|
3409
|
+
payer: inputs.payer,
|
|
3410
|
+
user: inputs.user,
|
|
3411
|
+
marketId: inputs.marketId,
|
|
3412
|
+
computationOffset,
|
|
3321
3413
|
addressLookupTable: lut
|
|
3322
|
-
}
|
|
3414
|
+
};
|
|
3415
|
+
const [placeIx, submitIx] = await Promise.all([
|
|
3416
|
+
placeBetBuilder(client, placeBetParams),
|
|
3417
|
+
submitBetBuilder(client, submitBetParams)
|
|
3418
|
+
]);
|
|
3323
3419
|
emitProgress(inputs.onProgress, "submitting", {
|
|
3324
3420
|
message: "Submitting transaction",
|
|
3325
3421
|
computationOffset
|
|
3326
3422
|
});
|
|
3327
|
-
const signature = await
|
|
3423
|
+
const signature = await sendTx(client, [placeIx, submitIx]);
|
|
3328
3424
|
emitProgress(inputs.onProgress, "awaiting-callback", {
|
|
3329
3425
|
message: "Waiting for Arcium MPC nodes to finalize",
|
|
3330
3426
|
signature,
|
|
@@ -3780,6 +3876,7 @@ var CypherClient = class {
|
|
|
3780
3876
|
*/
|
|
3781
3877
|
globalState;
|
|
3782
3878
|
markets;
|
|
3879
|
+
marketQuestions;
|
|
3783
3880
|
positions;
|
|
3784
3881
|
lpPositions;
|
|
3785
3882
|
/**
|
|
@@ -3848,6 +3945,9 @@ var CypherClient = class {
|
|
|
3848
3945
|
byCreator: (creator) => fetchMarketsByCreator(this, creator),
|
|
3849
3946
|
byState: (state) => fetchMarketsByState(this, state)
|
|
3850
3947
|
};
|
|
3948
|
+
this.marketQuestions = {
|
|
3949
|
+
fetch: (market) => fetchMarketQuestion(this, market)
|
|
3950
|
+
};
|
|
3851
3951
|
this.positions = {
|
|
3852
3952
|
fetch: (market, user) => fetchPosition(this, market, user),
|
|
3853
3953
|
byUser: (user) => fetchUserPositions(this, user),
|
|
@@ -3895,7 +3995,8 @@ var CypherClient = class {
|
|
|
3895
3995
|
this.admin = {
|
|
3896
3996
|
initializeIx: (p) => initializeIx(this, p),
|
|
3897
3997
|
updateAcceptedMintIx: (p) => updateAcceptedMintIx(this, p),
|
|
3898
|
-
adminClaimRemainingIx: (p) => adminClaimRemainingIx(this, p)
|
|
3998
|
+
adminClaimRemainingIx: (p) => adminClaimRemainingIx(this, p),
|
|
3999
|
+
initSignPdaIx: (p) => initSignPdaIx(this, p)
|
|
3899
4000
|
};
|
|
3900
4001
|
this.compDefs = {
|
|
3901
4002
|
initIx: (name, p) => initCompDefIx(this, name, p),
|
|
@@ -3909,7 +4010,9 @@ var CypherClient = class {
|
|
|
3909
4010
|
};
|
|
3910
4011
|
this.bets = {
|
|
3911
4012
|
placeYesnoIx: (p) => placePrivateBetYesnoIx(this, p),
|
|
3912
|
-
placeMultiIx: (p) => placePrivateBetMultiIx(this, p)
|
|
4013
|
+
placeMultiIx: (p) => placePrivateBetMultiIx(this, p),
|
|
4014
|
+
submitYesnoIx: (p) => submitBetYesnoIx(this, p),
|
|
4015
|
+
submitMultiIx: (p) => submitBetMultiIx(this, p)
|
|
3913
4016
|
};
|
|
3914
4017
|
this.resolveIx = {
|
|
3915
4018
|
yesnoIx: (p) => resolveMarketYesnoIx(this, p),
|
|
@@ -3954,6 +4057,6 @@ safe-buffer/index.js:
|
|
|
3954
4057
|
(*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> *)
|
|
3955
4058
|
*/
|
|
3956
4059
|
|
|
3957
|
-
export { ACCOUNT_DISCRIMINATOR_SIZE, ADDRESS_LOOKUP_TABLE_PROGRAM_ID, ALL_CIRCUITS, ALL_EVENT_NAMES, BPS_DENOMINATOR, CIRCUITS, CLUSTERS, CYPHER_ERROR_MESSAGES, CypherClient, CypherErrorCode, DEFAULT_CLAIM_PERIOD_SECS, DEFAULT_REFUND_PERIOD_SECS, DEFAULT_RESOLUTION_WINDOW_SECS, ENCRYPTED_POSITION_OFFSETS, GLOBAL_STATE_OFFSETS, IDL, IDL_PROGRAM_ID, INIT_COMP_DEF_INSTRUCTIONS, KNOWN_MINTS, LP_POSITION_OFFSETS, MARKET_OFFSETS, MAX_CHALLENGE_PERIOD_SECS, MAX_LP_FEE_BPS, MAX_OUTCOMES_MULTI, MAX_PROTOCOL_FEE_BPS, MAX_QUESTION_BYTES, MIN_BET_USDC, MIN_CHALLENGE_PERIOD_SECS, MIN_CREATOR_BOND, MIN_OUTCOMES_MULTI, MarketCategory, MarketState, MarketType, ODDS_SCALE, PROGRAM_ID, adminClaimRemainingIx, adminOverrideResolutionAction, adminOverrideResolutionIx, arciumSignerPda, awaitComputation, bigIntToLeBytes, buildAllInitCompDefIx, buildArciumQueueAccounts, cancelMarketAction, cancelMarketIx, claimPayoutAction, claimPayoutMultiIx, claimPayoutYesnoIx, claimRefundAction, claimRefundMultiIx, claimRefundYesnoIx, compDefOffsetBytes, compDefOffsetU32, computeFees, createCipher, createMarketAction, createMarketIx, createMarketMultiAction, createMarketMultiIx, createUserKeypair, cypherErrorName, decryptBetInput, deriveSharedSecret, discriminatorFilter, encryptBetInput, encryptRefundInput, fetchAllMarkets, fetchGlobalState, fetchLpPosition, fetchLpPositionsByProvider, fetchMarket, fetchMarketsByCreator, fetchMarketsByState, fetchMxeLookupTable, fetchMxePublicKey, fetchPosition, fetchPositionsForMarket, fetchUserPositions, finalizeResolutionAction, finalizeResolutionIx, flagResolutionAction, flagResolutionIx, freshNonce, globalStatePda, initCompDefIx, initializeIx, isBetAmountValid, isValidCloseTime, keypairToWallet, leBytesToBigInt, lpPositionFilters, lpPositionPda, marketFilters, marketPda, marketPhase, marketVaultPda, onBetPlaced, onCreatorWithdrawn, onMarketCancelled, onMarketCreated, onMarketFinalized, onMarketResolved, onPayoutClaimed, onRefundClaimed, onResolutionFlagged, onResolutionOverridden, parseCypherError, parseLogs, parseLogsFor, placeBetAction, placePrivateBetMultiIx, placePrivateBetYesnoIx, pollEvents, positionFilters, positionPda, projectDeadlines, randomComputationOffset, readonlyWallet, resolveMarketAction, resolveMarketMultiIx, resolveMarketYesnoIx, sendIx, sendIxAndAwaitArcium, subscribeAll, subscribeEvent, toBN, updateAcceptedMintIx, userAta, withdrawCreatorFundsAction, withdrawCreatorFundsIx };
|
|
4060
|
+
export { ACCOUNT_DISCRIMINATOR_SIZE, ADDRESS_LOOKUP_TABLE_PROGRAM_ID, ALL_CIRCUITS, ALL_EVENT_NAMES, BPS_DENOMINATOR, CIRCUITS, CLUSTERS, CYPHER_ERROR_MESSAGES, CypherClient, CypherErrorCode, DEFAULT_CLAIM_PERIOD_SECS, DEFAULT_REFUND_PERIOD_SECS, DEFAULT_RESOLUTION_WINDOW_SECS, ENCRYPTED_POSITION_OFFSETS, GLOBAL_STATE_OFFSETS, IDL, IDL_PROGRAM_ID, INIT_COMP_DEF_INSTRUCTIONS, KNOWN_MINTS, LP_POSITION_OFFSETS, MARKET_OFFSETS, MARKET_QUESTION_OFFSETS, MAX_CHALLENGE_PERIOD_SECS, MAX_LP_FEE_BPS, MAX_OUTCOMES_MULTI, MAX_PROTOCOL_FEE_BPS, MAX_QUESTION_BYTES, MIN_BET_USDC, MIN_CHALLENGE_PERIOD_SECS, MIN_CREATOR_BOND, MIN_OUTCOMES_MULTI, MarketCategory, MarketState, MarketType, ODDS_SCALE, PROGRAM_ID, adminClaimRemainingIx, adminOverrideResolutionAction, adminOverrideResolutionIx, arciumSignerPda, awaitComputation, bigIntToLeBytes, buildAllInitCompDefIx, buildArciumQueueAccounts, cancelMarketAction, cancelMarketIx, claimPayoutAction, claimPayoutMultiIx, claimPayoutYesnoIx, claimRefundAction, claimRefundMultiIx, claimRefundYesnoIx, compDefOffsetBytes, compDefOffsetU32, computeFees, createCipher, createMarketAction, createMarketIx, createMarketMultiAction, createMarketMultiIx, createUserKeypair, cypherErrorName, decryptBetInput, deriveSharedSecret, discriminatorFilter, encryptBetInput, encryptRefundInput, fetchAllMarkets, fetchGlobalState, fetchLpPosition, fetchLpPositionsByProvider, fetchMarket, fetchMarketQuestion, fetchMarketQuestions, fetchMarketsByCreator, fetchMarketsByState, fetchMxeLookupTable, fetchMxePublicKey, fetchPosition, fetchPositionsForMarket, fetchUserPositions, finalizeResolutionAction, finalizeResolutionIx, flagResolutionAction, flagResolutionIx, freshNonce, globalStatePda, initCompDefIx, initSignPdaIx, initializeIx, isBetAmountValid, isValidCloseTime, keypairToWallet, leBytesToBigInt, lpPositionFilters, lpPositionPda, marketFilters, marketPda, marketPhase, marketQuestionPda, marketVaultPda, onBetPlaced, onCreatorWithdrawn, onMarketCancelled, onMarketCreated, onMarketFinalized, onMarketResolved, onPayoutClaimed, onRefundClaimed, onResolutionFlagged, onResolutionOverridden, parseCypherError, parseLogs, parseLogsFor, placeBetAction, placePrivateBetMultiIx, placePrivateBetYesnoIx, pollEvents, positionFilters, positionPda, projectDeadlines, randomComputationOffset, readonlyWallet, resolveMarketAction, resolveMarketMultiIx, resolveMarketYesnoIx, sendIx, sendIxAndAwaitArcium, sendTx, submitBetMultiIx, submitBetYesnoIx, subscribeAll, subscribeEvent, toBN, updateAcceptedMintIx, userAta, withdrawCreatorFundsAction, withdrawCreatorFundsIx };
|
|
3958
4061
|
//# sourceMappingURL=index.js.map
|
|
3959
4062
|
//# sourceMappingURL=index.js.map
|