@cypher-zk/sdk 0.7.2 → 0.7.4
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-SMTHYAIl.d.ts → client-BECBXFEY.d.ts} +14 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +87 -54
- package/dist/index.js.map +1 -1
- package/dist/react/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -6517,7 +6517,7 @@ interface SendIxOptions {
|
|
|
6517
6517
|
* `ParsedCypherError` (when the program rejected the call) instead of
|
|
6518
6518
|
* Anchor's nested error objects.
|
|
6519
6519
|
*/
|
|
6520
|
-
declare function sendIx(client: CypherClient, ix: TransactionInstruction
|
|
6520
|
+
declare function sendIx(client: CypherClient, ix: TransactionInstruction, opts?: SendIxOptions): Promise<string>;
|
|
6521
6521
|
/**
|
|
6522
6522
|
* Send an instruction that queues an Arcium computation, then block until
|
|
6523
6523
|
* the MPC nodes finalize the callback. Returns both the queue tx
|
|
@@ -6884,6 +6884,12 @@ interface CypherClientOptions {
|
|
|
6884
6884
|
commitment?: Commitment;
|
|
6885
6885
|
/** Override the program ID (for redeploys with a different keypair). */
|
|
6886
6886
|
programId?: PublicKey;
|
|
6887
|
+
/**
|
|
6888
|
+
* The SPL token program that owns the accepted mint. Defaults to auto-detection
|
|
6889
|
+
* (resolved on first `globalState.fetch()` by querying the mint's account owner).
|
|
6890
|
+
* Pass `TOKEN_2022_PROGRAM_ID` explicitly to skip the detection RPC call.
|
|
6891
|
+
*/
|
|
6892
|
+
tokenProgram?: PublicKey;
|
|
6887
6893
|
/** Extra confirmation options forwarded to `AnchorProvider`. */
|
|
6888
6894
|
confirmOptions?: ConfirmOptions;
|
|
6889
6895
|
}
|
|
@@ -6903,6 +6909,13 @@ declare class CypherClient {
|
|
|
6903
6909
|
readonly programId: PublicKey;
|
|
6904
6910
|
readonly cluster: ClusterConfig;
|
|
6905
6911
|
private _globalStateCache;
|
|
6912
|
+
private _tokenProgram;
|
|
6913
|
+
/**
|
|
6914
|
+
* The SPL token program that owns the accepted mint (TOKEN_PROGRAM_ID or
|
|
6915
|
+
* TOKEN_2022_PROGRAM_ID). Defaults to TOKEN_PROGRAM_ID until auto-detected
|
|
6916
|
+
* on the first `globalState.fetch()` call.
|
|
6917
|
+
*/
|
|
6918
|
+
get tokenProgram(): PublicKey;
|
|
6906
6919
|
/**
|
|
6907
6920
|
* High-level account accessors. Each namespace is a thin facade over
|
|
6908
6921
|
* the per-account fetch helpers in `./accounts/`.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { k as Cypher, C as CypherClient, l as CircuitName } from './client-
|
|
2
|
-
export { m as ACCOUNT_DISCRIMINATOR_SIZE, n as ALL_CIRCUITS, o as ALL_EVENT_NAMES, p as ActionProgressEvent, q as ActionStage, r as AdminClaimRemainingParams, A as AdminOverrideResolutionInputs, s as AdminOverrideResolutionParams, t as AwaitComputationOptions, B as BPS_DENOMINATOR, u as BetPlacedEvent, v as CIRCUITS, w as CLUSTERS, a as CancelMarketParams, c as ClaimInputs, x as ClaimParams, b as ClaimResult, y as ClusterConfig, z as ClusterName, D as ComputationResult, H as CreateMarketMultiParams, e as CreateMarketParams, d as CreateMarketResult, I as CreatorWithdrawnEvent, J as CypherClientOptions, j as CypherEvent, K as CypherEventName, L as DEFAULT_CLAIM_PERIOD_SECS, N as DEFAULT_REFUND_PERIOD_SECS, O as DEFAULT_RESOLUTION_WINDOW_SECS, E as EncryptedPositionAccount, Q as EventCallback, T as EventSubscription, F as FinalizeResolutionInputs, U as FinalizeResolutionParams, f as FlagResolutionInputs, V as FlagResolutionParams, G as GlobalStateAccount, W as INIT_COMP_DEF_INSTRUCTIONS, X as InitCompDefMethodName, Y as InitCompDefParams, Z as InitializeParams, _ as KNOWN_MINTS, $ as LpPositionAccount, a0 as MAX_CHALLENGE_PERIOD_SECS, a1 as MAX_LP_FEE_BPS, a2 as MAX_OUTCOMES_MULTI, a3 as MAX_PROTOCOL_FEE_BPS, a4 as MAX_QUESTION_BYTES, a5 as MIN_BET_USDC, a6 as MIN_CHALLENGE_PERIOD_SECS, a7 as MIN_CREATOR_BOND, a8 as MIN_OUTCOMES_MULTI, M as MarketAccount, a9 as MarketCancelledEvent, aa as MarketCategory, ab as MarketCategoryValue, ac as MarketCreatedEvent, ad as MarketFinalizedEvent, ae as MarketResolvedEvent, af as MarketState, ag as MarketStateValue, ah as MarketType, ai as MarketTypeValue, aj as ODDS_SCALE, ak as PROGRAM_ID, al as PayoutClaimedEvent, g as PlaceBetInputs, P as PlaceBetResult, am as PlacePrivateBetParams, an as PollEventsOptions, ao as PolledEvent, ap as ProgressCallback, aq as RefundClaimedEvent, R as ResolutionActionResult, ar as ResolutionFlaggedEvent, as as ResolutionOverriddenEvent, i as ResolveMarketInputs, at as ResolveMarketParams, h as ResolveMarketResult, au as SendIxOptions, S as SubscribeOptions, av as UpdateAcceptedMintParams, aw as UserCryptoKeypair, ax as Wallet, ay as WithdrawCreatorFundsParams, az as adminClaimRemainingIx, aA as adminOverrideResolutionAction, aB as adminOverrideResolutionIx, aC as awaitComputation, aD as buildAllInitCompDefIx, aE as cancelMarketAction, aF as cancelMarketIx, aG as claimPayoutAction, aH as claimPayoutMultiIx, aI as claimPayoutYesnoIx, aJ as claimRefundAction, aK as claimRefundMultiIx, aL as claimRefundYesnoIx, aM as compDefOffsetBytes, aN as compDefOffsetU32, aO as createCipher, aP as createMarketAction, aQ as createMarketIx, aR as createMarketMultiAction, aS as createMarketMultiIx, aT as createUserKeypair, aU as deriveSharedSecret, aV as fetchAllMarkets, aW as fetchGlobalState, aX as fetchLpPosition, aY as fetchLpPositionsByProvider, aZ as fetchMarket, a_ as fetchMarketsByCreator, a$ as fetchMarketsByState, b0 as fetchMxePublicKey, b1 as fetchPosition, b2 as fetchPositionsForMarket, b3 as fetchUserPositions, b4 as finalizeResolutionAction, b5 as finalizeResolutionIx, b6 as flagResolutionAction, b7 as flagResolutionIx, b8 as freshNonce, b9 as initCompDefIx, ba as initializeIx, bb as keypairToWallet, bc as leBytesToBigInt, bd as onBetPlaced, be as onCreatorWithdrawn, bf as onMarketCancelled, bg as onMarketCreated, bh as onMarketFinalized, bi as onMarketResolved, bj as onPayoutClaimed, bk as onRefundClaimed, bl as onResolutionFlagged, bm as onResolutionOverridden, bn as parseLogs, bo as parseLogsFor, bp as placeBetAction, bq as placePrivateBetMultiIx, br as placePrivateBetYesnoIx, bs as pollEvents, bt as randomComputationOffset, bu as readonlyWallet, bv as resolveMarketAction, bw as resolveMarketMultiIx, bx as resolveMarketYesnoIx, by as sendIx, bz as sendIxAndAwaitArcium, bA as subscribeAll, bB as subscribeEvent, bC as updateAcceptedMintIx, bD as withdrawCreatorFundsAction, bE as withdrawCreatorFundsIx } from './client-
|
|
1
|
+
import { k as Cypher, C as CypherClient, l as CircuitName } from './client-BECBXFEY.js';
|
|
2
|
+
export { m as ACCOUNT_DISCRIMINATOR_SIZE, n as ALL_CIRCUITS, o as ALL_EVENT_NAMES, p as ActionProgressEvent, q as ActionStage, r as AdminClaimRemainingParams, A as AdminOverrideResolutionInputs, s as AdminOverrideResolutionParams, t as AwaitComputationOptions, B as BPS_DENOMINATOR, u as BetPlacedEvent, v as CIRCUITS, w as CLUSTERS, a as CancelMarketParams, c as ClaimInputs, x as ClaimParams, b as ClaimResult, y as ClusterConfig, z as ClusterName, D as ComputationResult, H as CreateMarketMultiParams, e as CreateMarketParams, d as CreateMarketResult, I as CreatorWithdrawnEvent, J as CypherClientOptions, j as CypherEvent, K as CypherEventName, L as DEFAULT_CLAIM_PERIOD_SECS, N as DEFAULT_REFUND_PERIOD_SECS, O as DEFAULT_RESOLUTION_WINDOW_SECS, E as EncryptedPositionAccount, Q as EventCallback, T as EventSubscription, F as FinalizeResolutionInputs, U as FinalizeResolutionParams, f as FlagResolutionInputs, V as FlagResolutionParams, G as GlobalStateAccount, W as INIT_COMP_DEF_INSTRUCTIONS, X as InitCompDefMethodName, Y as InitCompDefParams, Z as InitializeParams, _ as KNOWN_MINTS, $ as LpPositionAccount, a0 as MAX_CHALLENGE_PERIOD_SECS, a1 as MAX_LP_FEE_BPS, a2 as MAX_OUTCOMES_MULTI, a3 as MAX_PROTOCOL_FEE_BPS, a4 as MAX_QUESTION_BYTES, a5 as MIN_BET_USDC, a6 as MIN_CHALLENGE_PERIOD_SECS, a7 as MIN_CREATOR_BOND, a8 as MIN_OUTCOMES_MULTI, M as MarketAccount, a9 as MarketCancelledEvent, aa as MarketCategory, ab as MarketCategoryValue, ac as MarketCreatedEvent, ad as MarketFinalizedEvent, ae as MarketResolvedEvent, af as MarketState, ag as MarketStateValue, ah as MarketType, ai as MarketTypeValue, aj as ODDS_SCALE, ak as PROGRAM_ID, al as PayoutClaimedEvent, g as PlaceBetInputs, P as PlaceBetResult, am as PlacePrivateBetParams, an as PollEventsOptions, ao as PolledEvent, ap as ProgressCallback, aq as RefundClaimedEvent, R as ResolutionActionResult, ar as ResolutionFlaggedEvent, as as ResolutionOverriddenEvent, i as ResolveMarketInputs, at as ResolveMarketParams, h as ResolveMarketResult, au as SendIxOptions, S as SubscribeOptions, av as UpdateAcceptedMintParams, aw as UserCryptoKeypair, ax as Wallet, ay as WithdrawCreatorFundsParams, az as adminClaimRemainingIx, aA as adminOverrideResolutionAction, aB as adminOverrideResolutionIx, aC as awaitComputation, aD as buildAllInitCompDefIx, aE as cancelMarketAction, aF as cancelMarketIx, aG as claimPayoutAction, aH as claimPayoutMultiIx, aI as claimPayoutYesnoIx, aJ as claimRefundAction, aK as claimRefundMultiIx, aL as claimRefundYesnoIx, aM as compDefOffsetBytes, aN as compDefOffsetU32, aO as createCipher, aP as createMarketAction, aQ as createMarketIx, aR as createMarketMultiAction, aS as createMarketMultiIx, aT as createUserKeypair, aU as deriveSharedSecret, aV as fetchAllMarkets, aW as fetchGlobalState, aX as fetchLpPosition, aY as fetchLpPositionsByProvider, aZ as fetchMarket, a_ as fetchMarketsByCreator, a$ as fetchMarketsByState, b0 as fetchMxePublicKey, b1 as fetchPosition, b2 as fetchPositionsForMarket, b3 as fetchUserPositions, b4 as finalizeResolutionAction, b5 as finalizeResolutionIx, b6 as flagResolutionAction, b7 as flagResolutionIx, b8 as freshNonce, b9 as initCompDefIx, ba as initializeIx, bb as keypairToWallet, bc as leBytesToBigInt, bd as onBetPlaced, be as onCreatorWithdrawn, bf as onMarketCancelled, bg as onMarketCreated, bh as onMarketFinalized, bi as onMarketResolved, bj as onPayoutClaimed, bk as onRefundClaimed, bl as onResolutionFlagged, bm as onResolutionOverridden, bn as parseLogs, bo as parseLogsFor, bp as placeBetAction, bq as placePrivateBetMultiIx, br as placePrivateBetYesnoIx, bs as pollEvents, bt as randomComputationOffset, bu as readonlyWallet, bv as resolveMarketAction, bw as resolveMarketMultiIx, bx as resolveMarketYesnoIx, by as sendIx, bz as sendIxAndAwaitArcium, bA as subscribeAll, bB as subscribeEvent, bC as updateAcceptedMintIx, bD as withdrawCreatorFundsAction, bE as withdrawCreatorFundsIx } from './client-BECBXFEY.js';
|
|
3
3
|
import { GetProgramAccountsFilter, PublicKey } from '@solana/web3.js';
|
|
4
4
|
import { BN } from '@anchor-lang/core';
|
|
5
5
|
import { RescueCipher } from '@arcium-hq/client';
|
|
@@ -118,8 +118,8 @@ declare const GLOBAL_STATE_OFFSETS: {
|
|
|
118
118
|
declare const ADDRESS_LOOKUP_TABLE_PROGRAM_ID: PublicKey;
|
|
119
119
|
/** Convert `bigint | number | BN` → `BN`. Idempotent. */
|
|
120
120
|
declare function toBN(v: bigint | number | BN): BN;
|
|
121
|
-
/** The default ATA derivation for `(owner, mint)`. */
|
|
122
|
-
declare function userAta(owner: PublicKey, mint: PublicKey): PublicKey;
|
|
121
|
+
/** The default ATA derivation for `(owner, mint)`. Pass `tokenProgram` for Token-2022 mints. */
|
|
122
|
+
declare function userAta(owner: PublicKey, mint: PublicKey, tokenProgram?: PublicKey): PublicKey;
|
|
123
123
|
|
|
124
124
|
/**
|
|
125
125
|
* A user's plaintext bet input as the circuits expect it.
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { __commonJS, __toESM } from './chunk-5WRI5ZAA.js';
|
|
|
2
2
|
import idlJson from './cypher-G57ZWFM3.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
|
-
import {
|
|
5
|
+
import { TOKEN_PROGRAM_ID, getAssociatedTokenAddressSync } from '@solana/spl-token';
|
|
6
6
|
export { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, getAssociatedTokenAddressSync } from '@solana/spl-token';
|
|
7
7
|
import { getCompDefAccOffset, getMXEAccAddress, getCompDefAccAddress, getArciumProgramId, getLookupTableAddress, getClockAccAddress, getFeePoolAccAddress, getExecutingPoolAccAddress, getMempoolAccAddress, getClusterAccAddress, getComputationAccAddress, awaitComputationFinalization, x25519, RescueCipher, getMXEPublicKey } from '@arcium-hq/client';
|
|
8
8
|
|
|
@@ -2285,6 +2285,23 @@ function materialize(code) {
|
|
|
2285
2285
|
msg: CYPHER_ERROR_MESSAGES[name]
|
|
2286
2286
|
};
|
|
2287
2287
|
}
|
|
2288
|
+
var ADDRESS_LOOKUP_TABLE_PROGRAM_ID = AddressLookupTableProgram.programId;
|
|
2289
|
+
function method(client, methodName) {
|
|
2290
|
+
const m = client.program.methods[methodName];
|
|
2291
|
+
if (!m) {
|
|
2292
|
+
throw new Error(
|
|
2293
|
+
`instructions: unknown program method '${methodName}' \u2014 IDL out of sync?`
|
|
2294
|
+
);
|
|
2295
|
+
}
|
|
2296
|
+
return m;
|
|
2297
|
+
}
|
|
2298
|
+
function toBN(v) {
|
|
2299
|
+
if (v instanceof BN) return v;
|
|
2300
|
+
return new BN(typeof v === "bigint" ? v.toString() : v);
|
|
2301
|
+
}
|
|
2302
|
+
function userAta(owner, mint, tokenProgram = TOKEN_PROGRAM_ID) {
|
|
2303
|
+
return getAssociatedTokenAddressSync(mint, owner, true, tokenProgram);
|
|
2304
|
+
}
|
|
2288
2305
|
|
|
2289
2306
|
// src/accounts/globalState.ts
|
|
2290
2307
|
function decode(raw) {
|
|
@@ -2423,6 +2440,31 @@ var lpPositionFilters = {
|
|
|
2423
2440
|
};
|
|
2424
2441
|
|
|
2425
2442
|
// src/accounts/market.ts
|
|
2443
|
+
var MIN_DECODE_BYTES = 8 + 580;
|
|
2444
|
+
function decodeMarketAccount(client, data) {
|
|
2445
|
+
const coder = client.program.coder.accounts;
|
|
2446
|
+
let buf = Buffer.from(data);
|
|
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);
|
|
2453
|
+
}
|
|
2454
|
+
async function gpaFetchMarkets(client, extraFilters = []) {
|
|
2455
|
+
const rawAccounts = await client.connection.getProgramAccounts(client.programId, {
|
|
2456
|
+
filters: [marketFilters.discriminator(), ...extraFilters]
|
|
2457
|
+
});
|
|
2458
|
+
const results = [];
|
|
2459
|
+
for (const { pubkey, account } of rawAccounts) {
|
|
2460
|
+
try {
|
|
2461
|
+
const raw = decodeMarketAccount(client, account.data);
|
|
2462
|
+
results.push({ publicKey: pubkey, account: decode2(raw) });
|
|
2463
|
+
} catch {
|
|
2464
|
+
}
|
|
2465
|
+
}
|
|
2466
|
+
return results;
|
|
2467
|
+
}
|
|
2426
2468
|
function decode2(raw) {
|
|
2427
2469
|
const questionLen = raw.questionLen;
|
|
2428
2470
|
const question = Buffer.from(raw.question.slice(0, questionLen)).toString("utf8");
|
|
@@ -2469,25 +2511,24 @@ function decode2(raw) {
|
|
|
2469
2511
|
vaultBump: raw.vaultBump
|
|
2470
2512
|
};
|
|
2471
2513
|
}
|
|
2472
|
-
function marketAccountFacade(client) {
|
|
2473
|
-
return client.program.account.market;
|
|
2474
|
-
}
|
|
2475
2514
|
async function fetchMarket(client, idOrPda) {
|
|
2476
2515
|
const pda = idOrPda instanceof PublicKey ? idOrPda : marketPda(idOrPda, client.programId)[0];
|
|
2477
|
-
const
|
|
2478
|
-
|
|
2516
|
+
const accountInfo = await client.connection.getAccountInfo(pda);
|
|
2517
|
+
if (!accountInfo) return null;
|
|
2518
|
+
try {
|
|
2519
|
+
return decode2(decodeMarketAccount(client, accountInfo.data));
|
|
2520
|
+
} catch {
|
|
2521
|
+
return null;
|
|
2522
|
+
}
|
|
2479
2523
|
}
|
|
2480
2524
|
async function fetchAllMarkets(client) {
|
|
2481
|
-
|
|
2482
|
-
return raw.map(({ publicKey, account }) => ({ publicKey, account: decode2(account) }));
|
|
2525
|
+
return gpaFetchMarkets(client);
|
|
2483
2526
|
}
|
|
2484
2527
|
async function fetchMarketsByCreator(client, creator) {
|
|
2485
|
-
|
|
2486
|
-
return raw.map(({ publicKey, account }) => ({ publicKey, account: decode2(account) }));
|
|
2528
|
+
return gpaFetchMarkets(client, [marketFilters.byCreator(creator)]);
|
|
2487
2529
|
}
|
|
2488
2530
|
async function fetchMarketsByState(client, state) {
|
|
2489
|
-
|
|
2490
|
-
return raw.map(({ publicKey, account }) => ({ publicKey, account: decode2(account) }));
|
|
2531
|
+
return gpaFetchMarkets(client, [marketFilters.byState(state)]);
|
|
2491
2532
|
}
|
|
2492
2533
|
function decode3(raw) {
|
|
2493
2534
|
return {
|
|
@@ -2542,23 +2583,6 @@ async function fetchLpPositionsByProvider(client, provider) {
|
|
|
2542
2583
|
const raw = await facade2(client).all([lpPositionFilters.byProvider(provider)]);
|
|
2543
2584
|
return raw.map(({ publicKey, account }) => ({ publicKey, account: decode4(account) }));
|
|
2544
2585
|
}
|
|
2545
|
-
var ADDRESS_LOOKUP_TABLE_PROGRAM_ID = AddressLookupTableProgram.programId;
|
|
2546
|
-
function method(client, methodName) {
|
|
2547
|
-
const m = client.program.methods[methodName];
|
|
2548
|
-
if (!m) {
|
|
2549
|
-
throw new Error(
|
|
2550
|
-
`instructions: unknown program method '${methodName}' \u2014 IDL out of sync?`
|
|
2551
|
-
);
|
|
2552
|
-
}
|
|
2553
|
-
return m;
|
|
2554
|
-
}
|
|
2555
|
-
function toBN(v) {
|
|
2556
|
-
if (v instanceof BN) return v;
|
|
2557
|
-
return new BN(typeof v === "bigint" ? v.toString() : v);
|
|
2558
|
-
}
|
|
2559
|
-
function userAta(owner, mint) {
|
|
2560
|
-
return getAssociatedTokenAddressSync(mint, owner, true);
|
|
2561
|
-
}
|
|
2562
2586
|
|
|
2563
2587
|
// src/instructions/admin.ts
|
|
2564
2588
|
async function initializeIx(client, params) {
|
|
@@ -2600,7 +2624,7 @@ async function adminClaimRemainingIx(client, params) {
|
|
|
2600
2624
|
market: marketPdaKey,
|
|
2601
2625
|
marketVault: vaultPda,
|
|
2602
2626
|
protocolTreasury: params.protocolTreasury,
|
|
2603
|
-
tokenProgram:
|
|
2627
|
+
tokenProgram: client.tokenProgram
|
|
2604
2628
|
}).instruction();
|
|
2605
2629
|
}
|
|
2606
2630
|
var CIRCUITS = {
|
|
@@ -2692,7 +2716,7 @@ async function createMarketIx(client, params) {
|
|
|
2692
2716
|
const [marketPdaKey] = marketPda(toBN(params.expectedMarketId), client.programId);
|
|
2693
2717
|
const [vaultPda] = marketVaultPda(marketPdaKey, client.programId);
|
|
2694
2718
|
const [lpPda] = lpPositionPda(marketPdaKey, params.creator, client.programId);
|
|
2695
|
-
const creatorAta = userAta(params.creator, params.acceptedMint);
|
|
2719
|
+
const creatorAta = userAta(params.creator, params.acceptedMint, client.tokenProgram);
|
|
2696
2720
|
return method(client, "createMarket")(
|
|
2697
2721
|
params.question,
|
|
2698
2722
|
toBN(params.closeTime),
|
|
@@ -2707,7 +2731,7 @@ async function createMarketIx(client, params) {
|
|
|
2707
2731
|
marketVault: vaultPda,
|
|
2708
2732
|
creatorTokenAccount: creatorAta,
|
|
2709
2733
|
acceptedMint: params.acceptedMint,
|
|
2710
|
-
tokenProgram:
|
|
2734
|
+
tokenProgram: client.tokenProgram,
|
|
2711
2735
|
systemProgram: SystemProgram.programId
|
|
2712
2736
|
}).instruction();
|
|
2713
2737
|
}
|
|
@@ -2722,7 +2746,7 @@ async function createMarketMultiIx(client, params) {
|
|
|
2722
2746
|
const [marketPdaKey] = marketPda(toBN(params.expectedMarketId), client.programId);
|
|
2723
2747
|
const [vaultPda] = marketVaultPda(marketPdaKey, client.programId);
|
|
2724
2748
|
const [lpPda] = lpPositionPda(marketPdaKey, params.creator, client.programId);
|
|
2725
|
-
const creatorAta = userAta(params.creator, params.acceptedMint);
|
|
2749
|
+
const creatorAta = userAta(params.creator, params.acceptedMint, client.tokenProgram);
|
|
2726
2750
|
return method(client, "createMarketMulti")(
|
|
2727
2751
|
params.question,
|
|
2728
2752
|
toBN(params.closeTime),
|
|
@@ -2738,7 +2762,7 @@ async function createMarketMultiIx(client, params) {
|
|
|
2738
2762
|
marketVault: vaultPda,
|
|
2739
2763
|
creatorTokenAccount: creatorAta,
|
|
2740
2764
|
acceptedMint: params.acceptedMint,
|
|
2741
|
-
tokenProgram:
|
|
2765
|
+
tokenProgram: client.tokenProgram,
|
|
2742
2766
|
systemProgram: SystemProgram.programId
|
|
2743
2767
|
}).instruction();
|
|
2744
2768
|
}
|
|
@@ -2746,28 +2770,28 @@ async function cancelMarketIx(client, params) {
|
|
|
2746
2770
|
const [marketPdaKey] = marketPda(toBN(params.marketId), client.programId);
|
|
2747
2771
|
const [vaultPda] = marketVaultPda(marketPdaKey, client.programId);
|
|
2748
2772
|
const [lpPda] = lpPositionPda(marketPdaKey, params.creator, client.programId);
|
|
2749
|
-
const creatorAta = userAta(params.creator, params.acceptedMint);
|
|
2773
|
+
const creatorAta = userAta(params.creator, params.acceptedMint, client.tokenProgram);
|
|
2750
2774
|
return method(client, "cancelMarket")().accountsPartial({
|
|
2751
2775
|
creator: params.creator,
|
|
2752
2776
|
market: marketPdaKey,
|
|
2753
2777
|
marketVault: vaultPda,
|
|
2754
2778
|
lpPosition: lpPda,
|
|
2755
2779
|
creatorTokenAccount: creatorAta,
|
|
2756
|
-
tokenProgram:
|
|
2780
|
+
tokenProgram: client.tokenProgram
|
|
2757
2781
|
}).instruction();
|
|
2758
2782
|
}
|
|
2759
2783
|
async function withdrawCreatorFundsIx(client, params) {
|
|
2760
2784
|
const [marketPdaKey] = marketPda(toBN(params.marketId), client.programId);
|
|
2761
2785
|
const [vaultPda] = marketVaultPda(marketPdaKey, client.programId);
|
|
2762
2786
|
const [lpPda] = lpPositionPda(marketPdaKey, params.creator, client.programId);
|
|
2763
|
-
const creatorAta = userAta(params.creator, params.acceptedMint);
|
|
2787
|
+
const creatorAta = userAta(params.creator, params.acceptedMint, client.tokenProgram);
|
|
2764
2788
|
return method(client, "withdrawCreatorFunds")().accountsPartial({
|
|
2765
2789
|
creator: params.creator,
|
|
2766
2790
|
market: marketPdaKey,
|
|
2767
2791
|
lpPosition: lpPda,
|
|
2768
2792
|
marketVault: vaultPda,
|
|
2769
2793
|
creatorTokenAccount: creatorAta,
|
|
2770
|
-
tokenProgram:
|
|
2794
|
+
tokenProgram: client.tokenProgram
|
|
2771
2795
|
}).instruction();
|
|
2772
2796
|
}
|
|
2773
2797
|
function buildArciumQueueAccounts(client, params) {
|
|
@@ -2842,7 +2866,7 @@ async function buildPlaceBetIx(client, circuit, methodName, params) {
|
|
|
2842
2866
|
const [marketPdaKey] = marketPda(toBN(params.marketId), client.programId);
|
|
2843
2867
|
const [vaultPda] = marketVaultPda(marketPdaKey, client.programId);
|
|
2844
2868
|
const [positionPdaKey] = positionPda(marketPdaKey, params.user, client.programId);
|
|
2845
|
-
const userTokenAccount = userAta(params.user, params.acceptedMint);
|
|
2869
|
+
const userTokenAccount = userAta(params.user, params.acceptedMint, client.tokenProgram);
|
|
2846
2870
|
const arcium = buildArciumQueueAccounts(client, {
|
|
2847
2871
|
circuit,
|
|
2848
2872
|
computationOffset: toBN(params.computationOffset),
|
|
@@ -2875,7 +2899,7 @@ async function buildPlaceBetIx(client, circuit, methodName, params) {
|
|
|
2875
2899
|
userTokenAccount,
|
|
2876
2900
|
protocolTreasury: params.protocolTreasury,
|
|
2877
2901
|
position: positionPdaKey,
|
|
2878
|
-
tokenProgram:
|
|
2902
|
+
tokenProgram: client.tokenProgram
|
|
2879
2903
|
}).instruction();
|
|
2880
2904
|
}
|
|
2881
2905
|
function placePrivateBetYesnoIx(client, params) {
|
|
@@ -2945,7 +2969,7 @@ async function buildClaimIx(client, circuit, methodName, params) {
|
|
|
2945
2969
|
const [marketPdaKey] = marketPda(toBN(params.marketId), client.programId);
|
|
2946
2970
|
const [vaultPda] = marketVaultPda(marketPdaKey, client.programId);
|
|
2947
2971
|
const [positionPdaKey] = positionPda(marketPdaKey, params.user, client.programId);
|
|
2948
|
-
const userTokenAccount = userAta(params.user, params.acceptedMint);
|
|
2972
|
+
const userTokenAccount = userAta(params.user, params.acceptedMint, client.tokenProgram);
|
|
2949
2973
|
const arcium = buildArciumQueueAccounts(client, {
|
|
2950
2974
|
circuit,
|
|
2951
2975
|
computationOffset: toBN(params.computationOffset),
|
|
@@ -2969,7 +2993,7 @@ async function buildClaimIx(client, circuit, methodName, params) {
|
|
|
2969
2993
|
position: positionPdaKey,
|
|
2970
2994
|
marketVault: vaultPda,
|
|
2971
2995
|
userTokenAccount,
|
|
2972
|
-
tokenProgram:
|
|
2996
|
+
tokenProgram: client.tokenProgram
|
|
2973
2997
|
}).instruction();
|
|
2974
2998
|
}
|
|
2975
2999
|
function claimPayoutYesnoIx(client, params) {
|
|
@@ -3060,9 +3084,7 @@ function emitProgress(cb, stage, extra) {
|
|
|
3060
3084
|
}
|
|
3061
3085
|
}
|
|
3062
3086
|
async function sendIx(client, ix, opts = {}) {
|
|
3063
|
-
const tx = new Transaction();
|
|
3064
|
-
const ixs = Array.isArray(ix) ? ix : [ix];
|
|
3065
|
-
for (const i of ixs) tx.add(i);
|
|
3087
|
+
const tx = new Transaction().add(ix);
|
|
3066
3088
|
try {
|
|
3067
3089
|
return await client.provider.sendAndConfirm(
|
|
3068
3090
|
tx,
|
|
@@ -3095,6 +3117,8 @@ function rethrowCypher(err) {
|
|
|
3095
3117
|
}
|
|
3096
3118
|
throw err;
|
|
3097
3119
|
}
|
|
3120
|
+
|
|
3121
|
+
// src/actions/createMarket.ts
|
|
3098
3122
|
async function createMarketCommon(client, inputs) {
|
|
3099
3123
|
emitProgress(inputs.onProgress, "validating", {
|
|
3100
3124
|
message: "Validating market draft"
|
|
@@ -3110,14 +3134,7 @@ async function createMarketCommon(client, inputs) {
|
|
|
3110
3134
|
const expectedMarketId = gs.marketCounter;
|
|
3111
3135
|
const challengePeriod = inputs.challengePeriod ?? MIN_CHALLENGE_PERIOD_SECS;
|
|
3112
3136
|
const bondAmount = inputs.bondAmount ?? MIN_CREATOR_BOND;
|
|
3113
|
-
const
|
|
3114
|
-
const ataIx = createAssociatedTokenAccountIdempotentInstruction(
|
|
3115
|
-
inputs.creator,
|
|
3116
|
-
creatorAta,
|
|
3117
|
-
inputs.creator,
|
|
3118
|
-
acceptedMint
|
|
3119
|
-
);
|
|
3120
|
-
const marketIx = inputs.kind === "yesno" ? await createMarketIx(client, {
|
|
3137
|
+
const ix = inputs.kind === "yesno" ? await createMarketIx(client, {
|
|
3121
3138
|
...inputs,
|
|
3122
3139
|
acceptedMint,
|
|
3123
3140
|
expectedMarketId,
|
|
@@ -3133,7 +3150,7 @@ async function createMarketCommon(client, inputs) {
|
|
|
3133
3150
|
emitProgress(inputs.onProgress, "submitting", {
|
|
3134
3151
|
message: "Submitting create-market transaction"
|
|
3135
3152
|
});
|
|
3136
|
-
const signature = await sendIx(client,
|
|
3153
|
+
const signature = await sendIx(client, ix);
|
|
3137
3154
|
emitProgress(inputs.onProgress, "refetching");
|
|
3138
3155
|
const [marketPdaKey] = marketPda(expectedMarketId, client.programId);
|
|
3139
3156
|
const market = await client.markets.fetchByPda(marketPdaKey);
|
|
@@ -3772,6 +3789,15 @@ var CypherClient = class {
|
|
|
3772
3789
|
programId;
|
|
3773
3790
|
cluster;
|
|
3774
3791
|
_globalStateCache = null;
|
|
3792
|
+
_tokenProgram = null;
|
|
3793
|
+
/**
|
|
3794
|
+
* The SPL token program that owns the accepted mint (TOKEN_PROGRAM_ID or
|
|
3795
|
+
* TOKEN_2022_PROGRAM_ID). Defaults to TOKEN_PROGRAM_ID until auto-detected
|
|
3796
|
+
* on the first `globalState.fetch()` call.
|
|
3797
|
+
*/
|
|
3798
|
+
get tokenProgram() {
|
|
3799
|
+
return this._tokenProgram ?? TOKEN_PROGRAM_ID;
|
|
3800
|
+
}
|
|
3775
3801
|
/**
|
|
3776
3802
|
* High-level account accessors. Each namespace is a thin facade over
|
|
3777
3803
|
* the per-account fetch helpers in `./accounts/`.
|
|
@@ -3813,6 +3839,7 @@ var CypherClient = class {
|
|
|
3813
3839
|
this.wallet = opts.wallet;
|
|
3814
3840
|
this.programId = opts.programId ?? PROGRAM_ID;
|
|
3815
3841
|
this.cluster = resolveCluster(opts.cluster, opts.connection.rpcEndpoint);
|
|
3842
|
+
if (opts.tokenProgram) this._tokenProgram = opts.tokenProgram;
|
|
3816
3843
|
const confirmOptions = opts.confirmOptions ?? {
|
|
3817
3844
|
commitment: opts.commitment ?? "confirmed",
|
|
3818
3845
|
preflightCommitment: opts.commitment ?? "confirmed",
|
|
@@ -3825,6 +3852,12 @@ var CypherClient = class {
|
|
|
3825
3852
|
fetch: async (o = {}) => {
|
|
3826
3853
|
if (o.refresh || !this._globalStateCache) {
|
|
3827
3854
|
this._globalStateCache = await fetchGlobalState(this);
|
|
3855
|
+
if (!this._tokenProgram) {
|
|
3856
|
+
const mintInfo = await this.connection.getAccountInfo(
|
|
3857
|
+
this._globalStateCache.acceptedMint
|
|
3858
|
+
);
|
|
3859
|
+
if (mintInfo) this._tokenProgram = mintInfo.owner;
|
|
3860
|
+
}
|
|
3828
3861
|
}
|
|
3829
3862
|
return this._globalStateCache;
|
|
3830
3863
|
},
|