@cypher-zk/sdk 0.7.4 → 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 +193 -114
- 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,16 +2452,9 @@ var lpPositionFilters = {
|
|
|
2440
2452
|
};
|
|
2441
2453
|
|
|
2442
2454
|
// src/accounts/market.ts
|
|
2443
|
-
var MIN_DECODE_BYTES = 8 + 580;
|
|
2444
2455
|
function decodeMarketAccount(client, data) {
|
|
2445
2456
|
const coder = client.program.coder.accounts;
|
|
2446
|
-
|
|
2447
|
-
if (buf.length < MIN_DECODE_BYTES) {
|
|
2448
|
-
const padded = Buffer.alloc(MIN_DECODE_BYTES);
|
|
2449
|
-
buf.copy(padded);
|
|
2450
|
-
buf = padded;
|
|
2451
|
-
}
|
|
2452
|
-
return coder.decode("market", buf);
|
|
2457
|
+
return coder.decode("market", Buffer.from(data));
|
|
2453
2458
|
}
|
|
2454
2459
|
async function gpaFetchMarkets(client, extraFilters = []) {
|
|
2455
2460
|
const rawAccounts = await client.connection.getProgramAccounts(client.programId, {
|
|
@@ -2466,12 +2471,8 @@ async function gpaFetchMarkets(client, extraFilters = []) {
|
|
|
2466
2471
|
return results;
|
|
2467
2472
|
}
|
|
2468
2473
|
function decode2(raw) {
|
|
2469
|
-
const questionLen = raw.questionLen;
|
|
2470
|
-
const question = Buffer.from(raw.question.slice(0, questionLen)).toString("utf8");
|
|
2471
2474
|
return {
|
|
2472
2475
|
marketId: BigInt(raw.marketId.toString()),
|
|
2473
|
-
question,
|
|
2474
|
-
questionLen,
|
|
2475
2476
|
marketType: raw.marketType,
|
|
2476
2477
|
numOutcomes: raw.numOutcomes,
|
|
2477
2478
|
category: raw.category,
|
|
@@ -2541,6 +2542,7 @@ function decode3(raw) {
|
|
|
2541
2542
|
entryOdds: BigInt(raw.entryOdds.toString()),
|
|
2542
2543
|
netAmount: BigInt(raw.netAmount.toString()),
|
|
2543
2544
|
claimed: raw.claimed,
|
|
2545
|
+
computationQueued: raw.computationQueued,
|
|
2544
2546
|
bump: raw.bump
|
|
2545
2547
|
};
|
|
2546
2548
|
}
|
|
@@ -2583,6 +2585,40 @@ async function fetchLpPositionsByProvider(client, provider) {
|
|
|
2583
2585
|
const raw = await facade2(client).all([lpPositionFilters.byProvider(provider)]);
|
|
2584
2586
|
return raw.map(({ publicKey, account }) => ({ publicKey, account: decode4(account) }));
|
|
2585
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
|
+
}
|
|
2586
2622
|
|
|
2587
2623
|
// src/instructions/admin.ts
|
|
2588
2624
|
async function initializeIx(client, params) {
|
|
@@ -2602,6 +2638,7 @@ async function initializeIx(client, params) {
|
|
|
2602
2638
|
globalState: gsPda,
|
|
2603
2639
|
protocolTreasury: params.protocolTreasury,
|
|
2604
2640
|
acceptedMint: params.acceptedMint,
|
|
2641
|
+
tokenProgram: client.tokenProgram,
|
|
2605
2642
|
systemProgram: SystemProgram.programId
|
|
2606
2643
|
}).instruction();
|
|
2607
2644
|
}
|
|
@@ -2611,7 +2648,8 @@ async function updateAcceptedMintIx(client, params) {
|
|
|
2611
2648
|
admin: params.admin,
|
|
2612
2649
|
globalState: gsPda,
|
|
2613
2650
|
newMint: params.newMint,
|
|
2614
|
-
newTreasury: params.newTreasury
|
|
2651
|
+
newTreasury: params.newTreasury,
|
|
2652
|
+
tokenProgram: client.tokenProgram
|
|
2615
2653
|
}).instruction();
|
|
2616
2654
|
}
|
|
2617
2655
|
async function adminClaimRemainingIx(client, params) {
|
|
@@ -2714,6 +2752,7 @@ async function createMarketIx(client, params) {
|
|
|
2714
2752
|
validateMarketDraft(params);
|
|
2715
2753
|
const [gsPda] = globalStatePda(client.programId);
|
|
2716
2754
|
const [marketPdaKey] = marketPda(toBN(params.expectedMarketId), client.programId);
|
|
2755
|
+
const [questionPda] = marketQuestionPda(marketPdaKey, client.programId);
|
|
2717
2756
|
const [vaultPda] = marketVaultPda(marketPdaKey, client.programId);
|
|
2718
2757
|
const [lpPda] = lpPositionPda(marketPdaKey, params.creator, client.programId);
|
|
2719
2758
|
const creatorAta = userAta(params.creator, params.acceptedMint, client.tokenProgram);
|
|
@@ -2727,6 +2766,7 @@ async function createMarketIx(client, params) {
|
|
|
2727
2766
|
creator: params.creator,
|
|
2728
2767
|
globalState: gsPda,
|
|
2729
2768
|
market: marketPdaKey,
|
|
2769
|
+
marketQuestion: questionPda,
|
|
2730
2770
|
lpPosition: lpPda,
|
|
2731
2771
|
marketVault: vaultPda,
|
|
2732
2772
|
creatorTokenAccount: creatorAta,
|
|
@@ -2744,6 +2784,7 @@ async function createMarketMultiIx(client, params) {
|
|
|
2744
2784
|
}
|
|
2745
2785
|
const [gsPda] = globalStatePda(client.programId);
|
|
2746
2786
|
const [marketPdaKey] = marketPda(toBN(params.expectedMarketId), client.programId);
|
|
2787
|
+
const [questionPda] = marketQuestionPda(marketPdaKey, client.programId);
|
|
2747
2788
|
const [vaultPda] = marketVaultPda(marketPdaKey, client.programId);
|
|
2748
2789
|
const [lpPda] = lpPositionPda(marketPdaKey, params.creator, client.programId);
|
|
2749
2790
|
const creatorAta = userAta(params.creator, params.acceptedMint, client.tokenProgram);
|
|
@@ -2758,6 +2799,7 @@ async function createMarketMultiIx(client, params) {
|
|
|
2758
2799
|
creator: params.creator,
|
|
2759
2800
|
globalState: gsPda,
|
|
2760
2801
|
market: marketPdaKey,
|
|
2802
|
+
marketQuestion: questionPda,
|
|
2761
2803
|
lpPosition: lpPda,
|
|
2762
2804
|
marketVault: vaultPda,
|
|
2763
2805
|
creatorTokenAccount: creatorAta,
|
|
@@ -2767,6 +2809,7 @@ async function createMarketMultiIx(client, params) {
|
|
|
2767
2809
|
}).instruction();
|
|
2768
2810
|
}
|
|
2769
2811
|
async function cancelMarketIx(client, params) {
|
|
2812
|
+
const [gsPda] = globalStatePda(client.programId);
|
|
2770
2813
|
const [marketPdaKey] = marketPda(toBN(params.marketId), client.programId);
|
|
2771
2814
|
const [vaultPda] = marketVaultPda(marketPdaKey, client.programId);
|
|
2772
2815
|
const [lpPda] = lpPositionPda(marketPdaKey, params.creator, client.programId);
|
|
@@ -2774,6 +2817,7 @@ async function cancelMarketIx(client, params) {
|
|
|
2774
2817
|
return method(client, "cancelMarket")().accountsPartial({
|
|
2775
2818
|
creator: params.creator,
|
|
2776
2819
|
market: marketPdaKey,
|
|
2820
|
+
globalState: gsPda,
|
|
2777
2821
|
marketVault: vaultPda,
|
|
2778
2822
|
lpPosition: lpPda,
|
|
2779
2823
|
creatorTokenAccount: creatorAta,
|
|
@@ -2781,6 +2825,7 @@ async function cancelMarketIx(client, params) {
|
|
|
2781
2825
|
}).instruction();
|
|
2782
2826
|
}
|
|
2783
2827
|
async function withdrawCreatorFundsIx(client, params) {
|
|
2828
|
+
const [gsPda] = globalStatePda(client.programId);
|
|
2784
2829
|
const [marketPdaKey] = marketPda(toBN(params.marketId), client.programId);
|
|
2785
2830
|
const [vaultPda] = marketVaultPda(marketPdaKey, client.programId);
|
|
2786
2831
|
const [lpPda] = lpPositionPda(marketPdaKey, params.creator, client.programId);
|
|
@@ -2789,6 +2834,7 @@ async function withdrawCreatorFundsIx(client, params) {
|
|
|
2789
2834
|
creator: params.creator,
|
|
2790
2835
|
market: marketPdaKey,
|
|
2791
2836
|
lpPosition: lpPda,
|
|
2837
|
+
globalState: gsPda,
|
|
2792
2838
|
marketVault: vaultPda,
|
|
2793
2839
|
creatorTokenAccount: creatorAta,
|
|
2794
2840
|
tokenProgram: client.tokenProgram
|
|
@@ -2847,39 +2893,54 @@ async function fetchMxeLookupTable(client) {
|
|
|
2847
2893
|
}
|
|
2848
2894
|
|
|
2849
2895
|
// src/instructions/bet.ts
|
|
2850
|
-
function assertU8(name, v) {
|
|
2851
|
-
if (!Number.isInteger(v) || v < 0 || v > 255) {
|
|
2852
|
-
throw new Error(`placePrivateBet*Ix: ${name} must be a u8`);
|
|
2853
|
-
}
|
|
2854
|
-
}
|
|
2855
2896
|
function assertCiphertext(name, v) {
|
|
2856
2897
|
if (v.length !== 32) {
|
|
2857
2898
|
throw new Error(`placePrivateBet*Ix: ${name} must be exactly 32 bytes`);
|
|
2858
2899
|
}
|
|
2859
2900
|
}
|
|
2860
|
-
async function buildPlaceBetIx(client,
|
|
2901
|
+
async function buildPlaceBetIx(client, methodName, params) {
|
|
2861
2902
|
assertCiphertext("encryptedAmount", params.encryptedAmount);
|
|
2862
2903
|
assertCiphertext("encryptedSide", params.encryptedSide);
|
|
2863
2904
|
assertCiphertext("userX25519Pubkey", params.userX25519Pubkey);
|
|
2864
|
-
assertU8("(amount sanity)", 0);
|
|
2865
2905
|
const [gsPda] = globalStatePda(client.programId);
|
|
2866
2906
|
const [marketPdaKey] = marketPda(toBN(params.marketId), client.programId);
|
|
2867
2907
|
const [vaultPda] = marketVaultPda(marketPdaKey, client.programId);
|
|
2868
2908
|
const [positionPdaKey] = positionPda(marketPdaKey, params.user, client.programId);
|
|
2869
2909
|
const userTokenAccount = userAta(params.user, params.acceptedMint, client.tokenProgram);
|
|
2870
|
-
const arcium = buildArciumQueueAccounts(client, {
|
|
2871
|
-
circuit,
|
|
2872
|
-
computationOffset: toBN(params.computationOffset),
|
|
2873
|
-
addressLookupTable: params.addressLookupTable
|
|
2874
|
-
});
|
|
2875
2910
|
return method(client, methodName)(
|
|
2876
|
-
toBN(params.computationOffset),
|
|
2877
2911
|
toBN(params.betAmountUsdc),
|
|
2878
2912
|
Array.from(params.encryptedAmount),
|
|
2879
2913
|
Array.from(params.encryptedSide),
|
|
2880
2914
|
Array.from(params.userX25519Pubkey),
|
|
2881
2915
|
toBN(params.nonce)
|
|
2882
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({
|
|
2883
2944
|
payer: params.payer,
|
|
2884
2945
|
signPdaAccount: arcium.signPdaAccount,
|
|
2885
2946
|
mxeAccount: arcium.mxeAccount,
|
|
@@ -2893,30 +2954,25 @@ async function buildPlaceBetIx(client, circuit, methodName, params) {
|
|
|
2893
2954
|
systemProgram: SystemProgram.programId,
|
|
2894
2955
|
arciumProgram: arcium.arciumProgram,
|
|
2895
2956
|
user: params.user,
|
|
2896
|
-
globalState: gsPda,
|
|
2897
2957
|
market: marketPdaKey,
|
|
2898
|
-
|
|
2899
|
-
userTokenAccount,
|
|
2900
|
-
protocolTreasury: params.protocolTreasury,
|
|
2901
|
-
position: positionPdaKey,
|
|
2902
|
-
tokenProgram: client.tokenProgram
|
|
2958
|
+
position: positionPdaKey
|
|
2903
2959
|
}).instruction();
|
|
2904
2960
|
}
|
|
2905
|
-
function
|
|
2906
|
-
return
|
|
2907
|
-
client,
|
|
2908
|
-
CIRCUITS.placePrivateBetYesno,
|
|
2909
|
-
"placePrivateBetYesno",
|
|
2910
|
-
params
|
|
2911
|
-
);
|
|
2961
|
+
function submitBetYesnoIx(client, params) {
|
|
2962
|
+
return buildSubmitBetIx(client, CIRCUITS.placePrivateBetYesno, "submitBetYesno", params);
|
|
2912
2963
|
}
|
|
2913
|
-
function
|
|
2914
|
-
return
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
);
|
|
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();
|
|
2920
2976
|
}
|
|
2921
2977
|
|
|
2922
2978
|
// src/instructions/resolve.ts
|
|
@@ -2966,6 +3022,7 @@ function resolveMarketMultiIx(client, params) {
|
|
|
2966
3022
|
|
|
2967
3023
|
// src/instructions/claim.ts
|
|
2968
3024
|
async function buildClaimIx(client, circuit, methodName, params) {
|
|
3025
|
+
const [gsPda] = globalStatePda(client.programId);
|
|
2969
3026
|
const [marketPdaKey] = marketPda(toBN(params.marketId), client.programId);
|
|
2970
3027
|
const [vaultPda] = marketVaultPda(marketPdaKey, client.programId);
|
|
2971
3028
|
const [positionPdaKey] = positionPda(marketPdaKey, params.user, client.programId);
|
|
@@ -2991,6 +3048,7 @@ async function buildClaimIx(client, circuit, methodName, params) {
|
|
|
2991
3048
|
user: params.user,
|
|
2992
3049
|
market: marketPdaKey,
|
|
2993
3050
|
position: positionPdaKey,
|
|
3051
|
+
globalState: gsPda,
|
|
2994
3052
|
marketVault: vaultPda,
|
|
2995
3053
|
userTokenAccount,
|
|
2996
3054
|
tokenProgram: client.tokenProgram
|
|
@@ -3084,7 +3142,11 @@ function emitProgress(cb, stage, extra) {
|
|
|
3084
3142
|
}
|
|
3085
3143
|
}
|
|
3086
3144
|
async function sendIx(client, ix, opts = {}) {
|
|
3087
|
-
|
|
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);
|
|
3088
3150
|
try {
|
|
3089
3151
|
return await client.provider.sendAndConfirm(
|
|
3090
3152
|
tx,
|
|
@@ -3329,26 +3391,36 @@ async function placeBetAction(client, inputs) {
|
|
|
3329
3391
|
const encrypted = encryptBetInput({ amount: netAmount, side: inputs.side }, cipher);
|
|
3330
3392
|
const computationOffset = inputs.computationOffset ?? randomComputationOffset();
|
|
3331
3393
|
const isMulti = market.marketType === MarketType.MultiOutcome;
|
|
3332
|
-
const
|
|
3333
|
-
const
|
|
3394
|
+
const placeBetBuilder = isMulti ? placePrivateBetMultiIx : placePrivateBetYesnoIx;
|
|
3395
|
+
const submitBetBuilder = isMulti ? submitBetMultiIx : submitBetYesnoIx;
|
|
3396
|
+
const placeBetParams = {
|
|
3334
3397
|
payer: inputs.payer,
|
|
3335
3398
|
user: inputs.user,
|
|
3336
3399
|
marketId: inputs.marketId,
|
|
3337
3400
|
acceptedMint: gs.acceptedMint,
|
|
3338
3401
|
protocolTreasury: gs.protocolTreasury,
|
|
3339
|
-
computationOffset,
|
|
3340
3402
|
betAmountUsdc: grossAmount,
|
|
3341
3403
|
encryptedAmount: encrypted.encryptedAmount,
|
|
3342
3404
|
encryptedSide: encrypted.encryptedSide,
|
|
3343
3405
|
userX25519Pubkey: userKeypair.publicKey,
|
|
3344
|
-
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,
|
|
3345
3413
|
addressLookupTable: lut
|
|
3346
|
-
}
|
|
3414
|
+
};
|
|
3415
|
+
const [placeIx, submitIx] = await Promise.all([
|
|
3416
|
+
placeBetBuilder(client, placeBetParams),
|
|
3417
|
+
submitBetBuilder(client, submitBetParams)
|
|
3418
|
+
]);
|
|
3347
3419
|
emitProgress(inputs.onProgress, "submitting", {
|
|
3348
3420
|
message: "Submitting transaction",
|
|
3349
3421
|
computationOffset
|
|
3350
3422
|
});
|
|
3351
|
-
const signature = await
|
|
3423
|
+
const signature = await sendTx(client, [placeIx, submitIx]);
|
|
3352
3424
|
emitProgress(inputs.onProgress, "awaiting-callback", {
|
|
3353
3425
|
message: "Waiting for Arcium MPC nodes to finalize",
|
|
3354
3426
|
signature,
|
|
@@ -3804,6 +3876,7 @@ var CypherClient = class {
|
|
|
3804
3876
|
*/
|
|
3805
3877
|
globalState;
|
|
3806
3878
|
markets;
|
|
3879
|
+
marketQuestions;
|
|
3807
3880
|
positions;
|
|
3808
3881
|
lpPositions;
|
|
3809
3882
|
/**
|
|
@@ -3872,6 +3945,9 @@ var CypherClient = class {
|
|
|
3872
3945
|
byCreator: (creator) => fetchMarketsByCreator(this, creator),
|
|
3873
3946
|
byState: (state) => fetchMarketsByState(this, state)
|
|
3874
3947
|
};
|
|
3948
|
+
this.marketQuestions = {
|
|
3949
|
+
fetch: (market) => fetchMarketQuestion(this, market)
|
|
3950
|
+
};
|
|
3875
3951
|
this.positions = {
|
|
3876
3952
|
fetch: (market, user) => fetchPosition(this, market, user),
|
|
3877
3953
|
byUser: (user) => fetchUserPositions(this, user),
|
|
@@ -3919,7 +3995,8 @@ var CypherClient = class {
|
|
|
3919
3995
|
this.admin = {
|
|
3920
3996
|
initializeIx: (p) => initializeIx(this, p),
|
|
3921
3997
|
updateAcceptedMintIx: (p) => updateAcceptedMintIx(this, p),
|
|
3922
|
-
adminClaimRemainingIx: (p) => adminClaimRemainingIx(this, p)
|
|
3998
|
+
adminClaimRemainingIx: (p) => adminClaimRemainingIx(this, p),
|
|
3999
|
+
initSignPdaIx: (p) => initSignPdaIx(this, p)
|
|
3923
4000
|
};
|
|
3924
4001
|
this.compDefs = {
|
|
3925
4002
|
initIx: (name, p) => initCompDefIx(this, name, p),
|
|
@@ -3933,7 +4010,9 @@ var CypherClient = class {
|
|
|
3933
4010
|
};
|
|
3934
4011
|
this.bets = {
|
|
3935
4012
|
placeYesnoIx: (p) => placePrivateBetYesnoIx(this, p),
|
|
3936
|
-
placeMultiIx: (p) => placePrivateBetMultiIx(this, p)
|
|
4013
|
+
placeMultiIx: (p) => placePrivateBetMultiIx(this, p),
|
|
4014
|
+
submitYesnoIx: (p) => submitBetYesnoIx(this, p),
|
|
4015
|
+
submitMultiIx: (p) => submitBetMultiIx(this, p)
|
|
3937
4016
|
};
|
|
3938
4017
|
this.resolveIx = {
|
|
3939
4018
|
yesnoIx: (p) => resolveMarketYesnoIx(this, p),
|
|
@@ -3978,6 +4057,6 @@ safe-buffer/index.js:
|
|
|
3978
4057
|
(*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> *)
|
|
3979
4058
|
*/
|
|
3980
4059
|
|
|
3981
|
-
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 };
|
|
3982
4061
|
//# sourceMappingURL=index.js.map
|
|
3983
4062
|
//# sourceMappingURL=index.js.map
|