@alpha-arcade/sdk 0.1.1 → 0.2.0
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/README.md +28 -21
- package/dist/index.cjs +192 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +100 -15
- package/dist/index.d.ts +100 -15
- package/dist/index.js +188 -15
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -10,19 +10,20 @@ type AlphaClientConfig = {
|
|
|
10
10
|
signer: TransactionSigner;
|
|
11
11
|
/** The active Algorand address that will sign transactions */
|
|
12
12
|
activeAddress: string;
|
|
13
|
-
/** Matcher contract app ID (mainnet:
|
|
13
|
+
/** Matcher contract app ID (mainnet: 3078581851) */
|
|
14
14
|
matcherAppId: number;
|
|
15
15
|
/** USDC ASA ID on Algorand (mainnet: 31566704) */
|
|
16
16
|
usdcAssetId: number;
|
|
17
|
-
/** Platform fee collection address */
|
|
18
|
-
feeAddress: string;
|
|
19
17
|
/** Base URL for the Alpha REST API (default: https://partners.alphaarcade.com/api) */
|
|
20
18
|
apiBaseUrl?: string;
|
|
21
|
-
/** API key for the Alpha partners API
|
|
22
|
-
apiKey
|
|
19
|
+
/** API key for the Alpha partners API. Optional -- if not provided, markets are loaded on-chain. */
|
|
20
|
+
apiKey?: string;
|
|
21
|
+
/** Market creator address for on-chain market discovery. Defaults to the Alpha Arcade mainnet creator. */
|
|
22
|
+
marketCreatorAddress?: string;
|
|
23
23
|
};
|
|
24
|
-
/** A prediction market
|
|
24
|
+
/** A prediction market (from the Alpha API or on-chain discovery) */
|
|
25
25
|
type Market = {
|
|
26
|
+
/** Market ID (app ID as string for on-chain, UUID for API) */
|
|
26
27
|
id: string;
|
|
27
28
|
title: string;
|
|
28
29
|
slug?: string;
|
|
@@ -30,9 +31,13 @@ type Market = {
|
|
|
30
31
|
marketAppId: number;
|
|
31
32
|
yesAssetId: number;
|
|
32
33
|
noAssetId: number;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
/** YES probability (API only -- not available from on-chain lookup) */
|
|
35
|
+
yesProb?: number;
|
|
36
|
+
/** NO probability (API only -- not available from on-chain lookup) */
|
|
37
|
+
noProb?: number;
|
|
38
|
+
/** Trading volume (API only -- not available from on-chain lookup) */
|
|
39
|
+
volume?: number;
|
|
40
|
+
/** End/resolution timestamp in seconds */
|
|
36
41
|
endTs: number;
|
|
37
42
|
resolution?: number;
|
|
38
43
|
isResolved?: boolean;
|
|
@@ -41,6 +46,8 @@ type Market = {
|
|
|
41
46
|
featured?: boolean;
|
|
42
47
|
options?: MarketOption[];
|
|
43
48
|
feeBase?: number;
|
|
49
|
+
/** Data source: 'onchain' or 'api' */
|
|
50
|
+
source?: 'onchain' | 'api';
|
|
44
51
|
[key: string]: unknown;
|
|
45
52
|
};
|
|
46
53
|
/** An option within a multi-choice market */
|
|
@@ -316,9 +323,8 @@ type EscrowGlobalState = {
|
|
|
316
323
|
* indexerClient,
|
|
317
324
|
* signer,
|
|
318
325
|
* activeAddress: account.addr,
|
|
319
|
-
* matcherAppId:
|
|
326
|
+
* matcherAppId: 3078581851,
|
|
320
327
|
* usdcAssetId: 31566704,
|
|
321
|
-
* feeAddress: 'FEE_ADDRESS_HERE',
|
|
322
328
|
* });
|
|
323
329
|
*
|
|
324
330
|
* // Fetch markets
|
|
@@ -438,9 +444,10 @@ declare class AlphaClient {
|
|
|
438
444
|
*/
|
|
439
445
|
getOpenOrders(marketAppId: number, walletAddress?: string): Promise<OpenOrder[]>;
|
|
440
446
|
/**
|
|
441
|
-
* Fetches all live, tradeable markets
|
|
447
|
+
* Fetches all live, tradeable markets.
|
|
442
448
|
*
|
|
443
|
-
*
|
|
449
|
+
* If an API key is configured, uses the Alpha REST API (richer data: images, categories, volume).
|
|
450
|
+
* Otherwise, discovers markets on-chain from the market creator address (no API key needed).
|
|
444
451
|
*
|
|
445
452
|
* @returns Array of live markets
|
|
446
453
|
*/
|
|
@@ -448,12 +455,90 @@ declare class AlphaClient {
|
|
|
448
455
|
/**
|
|
449
456
|
* Fetches a single market by its ID.
|
|
450
457
|
*
|
|
451
|
-
*
|
|
458
|
+
* If an API key is configured, uses the Alpha REST API.
|
|
459
|
+
* Otherwise, reads the market's on-chain global state (pass the market app ID as a string).
|
|
460
|
+
*
|
|
461
|
+
* @param marketId - The market ID (UUID for API, app ID string for on-chain)
|
|
452
462
|
* @returns The market data, or null if not found
|
|
453
463
|
*/
|
|
454
464
|
getMarket(marketId: string): Promise<Market | null>;
|
|
465
|
+
/**
|
|
466
|
+
* Fetches all live markets directly from the blockchain (no API key needed).
|
|
467
|
+
*
|
|
468
|
+
* Discovers markets by looking up all apps created by the market creator address.
|
|
469
|
+
* Returns core data: title, asset IDs, resolution time, fees.
|
|
470
|
+
* Does NOT include images, categories, volume, or probabilities.
|
|
471
|
+
*
|
|
472
|
+
* @returns Array of live markets from on-chain data
|
|
473
|
+
*/
|
|
474
|
+
getMarketsOnChain(): Promise<Market[]>;
|
|
475
|
+
/**
|
|
476
|
+
* Fetches a single market by app ID directly from the blockchain (no API key needed).
|
|
477
|
+
*
|
|
478
|
+
* @param marketAppId - The market app ID
|
|
479
|
+
* @returns The market data, or null if not found
|
|
480
|
+
*/
|
|
481
|
+
getMarketOnChain(marketAppId: number): Promise<Market | null>;
|
|
482
|
+
/**
|
|
483
|
+
* Fetches all live markets from the Alpha REST API (requires API key).
|
|
484
|
+
*
|
|
485
|
+
* Returns richer data than on-chain: images, categories, volume, probabilities.
|
|
486
|
+
*
|
|
487
|
+
* @returns Array of live markets from the API
|
|
488
|
+
*/
|
|
489
|
+
getMarketsFromApi(): Promise<Market[]>;
|
|
490
|
+
/**
|
|
491
|
+
* Fetches a single market by ID from the Alpha REST API (requires API key).
|
|
492
|
+
*
|
|
493
|
+
* @param marketId - The market UUID
|
|
494
|
+
* @returns The market data, or null if not found
|
|
495
|
+
*/
|
|
496
|
+
getMarketFromApi(marketId: string): Promise<Market | null>;
|
|
455
497
|
}
|
|
456
498
|
|
|
499
|
+
/** The default Alpha Arcade mainnet market creator address */
|
|
500
|
+
declare const DEFAULT_MARKET_CREATOR_ADDRESS = "5P5Y6HTWUNG2E3VXBQDZN3ENZD3JPAIR5PKT3LOYJAPAUKOLFD6KANYTRY";
|
|
501
|
+
/**
|
|
502
|
+
* Fetches all live, tradeable markets directly from the Algorand blockchain.
|
|
503
|
+
*
|
|
504
|
+
* Discovers markets by looking up all applications created by the market creator
|
|
505
|
+
* address, then reading their global state. No API key required.
|
|
506
|
+
*
|
|
507
|
+
* @param config - Alpha client config
|
|
508
|
+
* @param options - Optional filters
|
|
509
|
+
* @returns Array of live markets
|
|
510
|
+
*/
|
|
511
|
+
declare const getMarketsOnChain: (config: AlphaClientConfig, options?: {
|
|
512
|
+
activeOnly?: boolean;
|
|
513
|
+
}) => Promise<Market[]>;
|
|
514
|
+
/**
|
|
515
|
+
* Fetches a single market by its app ID directly from the Algorand blockchain.
|
|
516
|
+
*
|
|
517
|
+
* @param config - Alpha client config
|
|
518
|
+
* @param marketAppId - The market app ID (number or string)
|
|
519
|
+
* @returns The market data, or null if not found
|
|
520
|
+
*/
|
|
521
|
+
declare const getMarketOnChain: (config: AlphaClientConfig, marketAppId: number | string) => Promise<Market | null>;
|
|
522
|
+
/**
|
|
523
|
+
* Fetches all live, tradeable markets from the Alpha REST API.
|
|
524
|
+
*
|
|
525
|
+
* Paginates automatically through all results. Requires an API key.
|
|
526
|
+
* Returns richer data than on-chain lookup (images, categories, volume, probabilities).
|
|
527
|
+
*
|
|
528
|
+
* @param config - Alpha client config
|
|
529
|
+
* @returns Array of live markets
|
|
530
|
+
*/
|
|
531
|
+
declare const getMarketsFromApi: (config: AlphaClientConfig) => Promise<Market[]>;
|
|
532
|
+
/**
|
|
533
|
+
* Fetches a single market by its ID from the Alpha REST API.
|
|
534
|
+
* Requires an API key.
|
|
535
|
+
*
|
|
536
|
+
* @param config - Alpha client config
|
|
537
|
+
* @param marketId - The market ID
|
|
538
|
+
* @returns The market data, or null if not found
|
|
539
|
+
*/
|
|
540
|
+
declare const getMarketFromApi: (config: AlphaClientConfig, marketId: string) => Promise<Market | null>;
|
|
541
|
+
|
|
457
542
|
/**
|
|
458
543
|
* Calculates the required fee amount in microunits.
|
|
459
544
|
*
|
|
@@ -532,4 +617,4 @@ declare const getEscrowGlobalState: (indexerClient: algosdk.Indexer, escrowAppId
|
|
|
532
617
|
*/
|
|
533
618
|
declare const checkAssetOptIn: (algodClient: algosdk.Algodv2, address: string, assetId: number) => Promise<boolean>;
|
|
534
619
|
|
|
535
|
-
export { type AggregatedOrderbook, type AggregatedOrderbookEntry, type AggregatedOrderbookSide, AlphaClient, type AlphaClientConfig, type CancelOrderParams, type CancelOrderResult, type ClaimParams, type ClaimResult, type CounterpartyMatch, type CreateLimitOrderParams, type CreateMarketOrderParams, type CreateMarketOrderResult, type CreateOrderResult, type EscrowGlobalState, type Market, type MarketGlobalState, type MarketOption, type MergeSharesParams, type OpenOrder, type OrderSide, type Orderbook, type OrderbookEntry, type OrderbookSide, type Position, type ProposeMatchParams, type ProposeMatchResult, type SplitMergeResult, type SplitSharesParams, type WalletPosition, calculateFee, calculateFeeFromTotal, calculateMatchingOrders, checkAssetOptIn, decodeGlobalState, getEscrowGlobalState, getMarketGlobalState };
|
|
620
|
+
export { type AggregatedOrderbook, type AggregatedOrderbookEntry, type AggregatedOrderbookSide, AlphaClient, type AlphaClientConfig, type CancelOrderParams, type CancelOrderResult, type ClaimParams, type ClaimResult, type CounterpartyMatch, type CreateLimitOrderParams, type CreateMarketOrderParams, type CreateMarketOrderResult, type CreateOrderResult, DEFAULT_MARKET_CREATOR_ADDRESS, type EscrowGlobalState, type Market, type MarketGlobalState, type MarketOption, type MergeSharesParams, type OpenOrder, type OrderSide, type Orderbook, type OrderbookEntry, type OrderbookSide, type Position, type ProposeMatchParams, type ProposeMatchResult, type SplitMergeResult, type SplitSharesParams, type WalletPosition, calculateFee, calculateFeeFromTotal, calculateMatchingOrders, checkAssetOptIn, decodeGlobalState, getEscrowGlobalState, getMarketFromApi, getMarketGlobalState, getMarketOnChain, getMarketsFromApi, getMarketsOnChain };
|
package/dist/index.d.ts
CHANGED
|
@@ -10,19 +10,20 @@ type AlphaClientConfig = {
|
|
|
10
10
|
signer: TransactionSigner;
|
|
11
11
|
/** The active Algorand address that will sign transactions */
|
|
12
12
|
activeAddress: string;
|
|
13
|
-
/** Matcher contract app ID (mainnet:
|
|
13
|
+
/** Matcher contract app ID (mainnet: 3078581851) */
|
|
14
14
|
matcherAppId: number;
|
|
15
15
|
/** USDC ASA ID on Algorand (mainnet: 31566704) */
|
|
16
16
|
usdcAssetId: number;
|
|
17
|
-
/** Platform fee collection address */
|
|
18
|
-
feeAddress: string;
|
|
19
17
|
/** Base URL for the Alpha REST API (default: https://partners.alphaarcade.com/api) */
|
|
20
18
|
apiBaseUrl?: string;
|
|
21
|
-
/** API key for the Alpha partners API
|
|
22
|
-
apiKey
|
|
19
|
+
/** API key for the Alpha partners API. Optional -- if not provided, markets are loaded on-chain. */
|
|
20
|
+
apiKey?: string;
|
|
21
|
+
/** Market creator address for on-chain market discovery. Defaults to the Alpha Arcade mainnet creator. */
|
|
22
|
+
marketCreatorAddress?: string;
|
|
23
23
|
};
|
|
24
|
-
/** A prediction market
|
|
24
|
+
/** A prediction market (from the Alpha API or on-chain discovery) */
|
|
25
25
|
type Market = {
|
|
26
|
+
/** Market ID (app ID as string for on-chain, UUID for API) */
|
|
26
27
|
id: string;
|
|
27
28
|
title: string;
|
|
28
29
|
slug?: string;
|
|
@@ -30,9 +31,13 @@ type Market = {
|
|
|
30
31
|
marketAppId: number;
|
|
31
32
|
yesAssetId: number;
|
|
32
33
|
noAssetId: number;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
/** YES probability (API only -- not available from on-chain lookup) */
|
|
35
|
+
yesProb?: number;
|
|
36
|
+
/** NO probability (API only -- not available from on-chain lookup) */
|
|
37
|
+
noProb?: number;
|
|
38
|
+
/** Trading volume (API only -- not available from on-chain lookup) */
|
|
39
|
+
volume?: number;
|
|
40
|
+
/** End/resolution timestamp in seconds */
|
|
36
41
|
endTs: number;
|
|
37
42
|
resolution?: number;
|
|
38
43
|
isResolved?: boolean;
|
|
@@ -41,6 +46,8 @@ type Market = {
|
|
|
41
46
|
featured?: boolean;
|
|
42
47
|
options?: MarketOption[];
|
|
43
48
|
feeBase?: number;
|
|
49
|
+
/** Data source: 'onchain' or 'api' */
|
|
50
|
+
source?: 'onchain' | 'api';
|
|
44
51
|
[key: string]: unknown;
|
|
45
52
|
};
|
|
46
53
|
/** An option within a multi-choice market */
|
|
@@ -316,9 +323,8 @@ type EscrowGlobalState = {
|
|
|
316
323
|
* indexerClient,
|
|
317
324
|
* signer,
|
|
318
325
|
* activeAddress: account.addr,
|
|
319
|
-
* matcherAppId:
|
|
326
|
+
* matcherAppId: 3078581851,
|
|
320
327
|
* usdcAssetId: 31566704,
|
|
321
|
-
* feeAddress: 'FEE_ADDRESS_HERE',
|
|
322
328
|
* });
|
|
323
329
|
*
|
|
324
330
|
* // Fetch markets
|
|
@@ -438,9 +444,10 @@ declare class AlphaClient {
|
|
|
438
444
|
*/
|
|
439
445
|
getOpenOrders(marketAppId: number, walletAddress?: string): Promise<OpenOrder[]>;
|
|
440
446
|
/**
|
|
441
|
-
* Fetches all live, tradeable markets
|
|
447
|
+
* Fetches all live, tradeable markets.
|
|
442
448
|
*
|
|
443
|
-
*
|
|
449
|
+
* If an API key is configured, uses the Alpha REST API (richer data: images, categories, volume).
|
|
450
|
+
* Otherwise, discovers markets on-chain from the market creator address (no API key needed).
|
|
444
451
|
*
|
|
445
452
|
* @returns Array of live markets
|
|
446
453
|
*/
|
|
@@ -448,12 +455,90 @@ declare class AlphaClient {
|
|
|
448
455
|
/**
|
|
449
456
|
* Fetches a single market by its ID.
|
|
450
457
|
*
|
|
451
|
-
*
|
|
458
|
+
* If an API key is configured, uses the Alpha REST API.
|
|
459
|
+
* Otherwise, reads the market's on-chain global state (pass the market app ID as a string).
|
|
460
|
+
*
|
|
461
|
+
* @param marketId - The market ID (UUID for API, app ID string for on-chain)
|
|
452
462
|
* @returns The market data, or null if not found
|
|
453
463
|
*/
|
|
454
464
|
getMarket(marketId: string): Promise<Market | null>;
|
|
465
|
+
/**
|
|
466
|
+
* Fetches all live markets directly from the blockchain (no API key needed).
|
|
467
|
+
*
|
|
468
|
+
* Discovers markets by looking up all apps created by the market creator address.
|
|
469
|
+
* Returns core data: title, asset IDs, resolution time, fees.
|
|
470
|
+
* Does NOT include images, categories, volume, or probabilities.
|
|
471
|
+
*
|
|
472
|
+
* @returns Array of live markets from on-chain data
|
|
473
|
+
*/
|
|
474
|
+
getMarketsOnChain(): Promise<Market[]>;
|
|
475
|
+
/**
|
|
476
|
+
* Fetches a single market by app ID directly from the blockchain (no API key needed).
|
|
477
|
+
*
|
|
478
|
+
* @param marketAppId - The market app ID
|
|
479
|
+
* @returns The market data, or null if not found
|
|
480
|
+
*/
|
|
481
|
+
getMarketOnChain(marketAppId: number): Promise<Market | null>;
|
|
482
|
+
/**
|
|
483
|
+
* Fetches all live markets from the Alpha REST API (requires API key).
|
|
484
|
+
*
|
|
485
|
+
* Returns richer data than on-chain: images, categories, volume, probabilities.
|
|
486
|
+
*
|
|
487
|
+
* @returns Array of live markets from the API
|
|
488
|
+
*/
|
|
489
|
+
getMarketsFromApi(): Promise<Market[]>;
|
|
490
|
+
/**
|
|
491
|
+
* Fetches a single market by ID from the Alpha REST API (requires API key).
|
|
492
|
+
*
|
|
493
|
+
* @param marketId - The market UUID
|
|
494
|
+
* @returns The market data, or null if not found
|
|
495
|
+
*/
|
|
496
|
+
getMarketFromApi(marketId: string): Promise<Market | null>;
|
|
455
497
|
}
|
|
456
498
|
|
|
499
|
+
/** The default Alpha Arcade mainnet market creator address */
|
|
500
|
+
declare const DEFAULT_MARKET_CREATOR_ADDRESS = "5P5Y6HTWUNG2E3VXBQDZN3ENZD3JPAIR5PKT3LOYJAPAUKOLFD6KANYTRY";
|
|
501
|
+
/**
|
|
502
|
+
* Fetches all live, tradeable markets directly from the Algorand blockchain.
|
|
503
|
+
*
|
|
504
|
+
* Discovers markets by looking up all applications created by the market creator
|
|
505
|
+
* address, then reading their global state. No API key required.
|
|
506
|
+
*
|
|
507
|
+
* @param config - Alpha client config
|
|
508
|
+
* @param options - Optional filters
|
|
509
|
+
* @returns Array of live markets
|
|
510
|
+
*/
|
|
511
|
+
declare const getMarketsOnChain: (config: AlphaClientConfig, options?: {
|
|
512
|
+
activeOnly?: boolean;
|
|
513
|
+
}) => Promise<Market[]>;
|
|
514
|
+
/**
|
|
515
|
+
* Fetches a single market by its app ID directly from the Algorand blockchain.
|
|
516
|
+
*
|
|
517
|
+
* @param config - Alpha client config
|
|
518
|
+
* @param marketAppId - The market app ID (number or string)
|
|
519
|
+
* @returns The market data, or null if not found
|
|
520
|
+
*/
|
|
521
|
+
declare const getMarketOnChain: (config: AlphaClientConfig, marketAppId: number | string) => Promise<Market | null>;
|
|
522
|
+
/**
|
|
523
|
+
* Fetches all live, tradeable markets from the Alpha REST API.
|
|
524
|
+
*
|
|
525
|
+
* Paginates automatically through all results. Requires an API key.
|
|
526
|
+
* Returns richer data than on-chain lookup (images, categories, volume, probabilities).
|
|
527
|
+
*
|
|
528
|
+
* @param config - Alpha client config
|
|
529
|
+
* @returns Array of live markets
|
|
530
|
+
*/
|
|
531
|
+
declare const getMarketsFromApi: (config: AlphaClientConfig) => Promise<Market[]>;
|
|
532
|
+
/**
|
|
533
|
+
* Fetches a single market by its ID from the Alpha REST API.
|
|
534
|
+
* Requires an API key.
|
|
535
|
+
*
|
|
536
|
+
* @param config - Alpha client config
|
|
537
|
+
* @param marketId - The market ID
|
|
538
|
+
* @returns The market data, or null if not found
|
|
539
|
+
*/
|
|
540
|
+
declare const getMarketFromApi: (config: AlphaClientConfig, marketId: string) => Promise<Market | null>;
|
|
541
|
+
|
|
457
542
|
/**
|
|
458
543
|
* Calculates the required fee amount in microunits.
|
|
459
544
|
*
|
|
@@ -532,4 +617,4 @@ declare const getEscrowGlobalState: (indexerClient: algosdk.Indexer, escrowAppId
|
|
|
532
617
|
*/
|
|
533
618
|
declare const checkAssetOptIn: (algodClient: algosdk.Algodv2, address: string, assetId: number) => Promise<boolean>;
|
|
534
619
|
|
|
535
|
-
export { type AggregatedOrderbook, type AggregatedOrderbookEntry, type AggregatedOrderbookSide, AlphaClient, type AlphaClientConfig, type CancelOrderParams, type CancelOrderResult, type ClaimParams, type ClaimResult, type CounterpartyMatch, type CreateLimitOrderParams, type CreateMarketOrderParams, type CreateMarketOrderResult, type CreateOrderResult, type EscrowGlobalState, type Market, type MarketGlobalState, type MarketOption, type MergeSharesParams, type OpenOrder, type OrderSide, type Orderbook, type OrderbookEntry, type OrderbookSide, type Position, type ProposeMatchParams, type ProposeMatchResult, type SplitMergeResult, type SplitSharesParams, type WalletPosition, calculateFee, calculateFeeFromTotal, calculateMatchingOrders, checkAssetOptIn, decodeGlobalState, getEscrowGlobalState, getMarketGlobalState };
|
|
620
|
+
export { type AggregatedOrderbook, type AggregatedOrderbookEntry, type AggregatedOrderbookSide, AlphaClient, type AlphaClientConfig, type CancelOrderParams, type CancelOrderResult, type ClaimParams, type ClaimResult, type CounterpartyMatch, type CreateLimitOrderParams, type CreateMarketOrderParams, type CreateMarketOrderResult, type CreateOrderResult, DEFAULT_MARKET_CREATOR_ADDRESS, type EscrowGlobalState, type Market, type MarketGlobalState, type MarketOption, type MergeSharesParams, type OpenOrder, type OrderSide, type Orderbook, type OrderbookEntry, type OrderbookSide, type Position, type ProposeMatchParams, type ProposeMatchResult, type SplitMergeResult, type SplitSharesParams, type WalletPosition, calculateFee, calculateFeeFromTotal, calculateMatchingOrders, checkAssetOptIn, decodeGlobalState, getEscrowGlobalState, getMarketFromApi, getMarketGlobalState, getMarketOnChain, getMarketsFromApi, getMarketsOnChain };
|
package/dist/index.js
CHANGED
|
@@ -1541,13 +1541,13 @@ var createMarketOrder = async (config, params) => {
|
|
|
1541
1541
|
return { ...result, matchedQuantity: totalMatchedQuantity };
|
|
1542
1542
|
};
|
|
1543
1543
|
var createOrder = async (config, params) => {
|
|
1544
|
-
const { algodClient, indexerClient, signer, activeAddress, matcherAppId, usdcAssetId
|
|
1544
|
+
const { algodClient, indexerClient, signer, activeAddress, matcherAppId, usdcAssetId } = config;
|
|
1545
1545
|
const { marketAppId, position, price, quantity, isBuying, slippage, matchingOrders } = params;
|
|
1546
1546
|
const globalState = await getMarketGlobalState(algodClient, marketAppId);
|
|
1547
1547
|
const yesAssetId = globalState.yes_asset_id;
|
|
1548
1548
|
const noAssetId = globalState.no_asset_id;
|
|
1549
1549
|
const feeBase = params.feeBase ?? globalState.fee_base_percent;
|
|
1550
|
-
const marketFeeAddress = globalState.fee_address
|
|
1550
|
+
const marketFeeAddress = globalState.fee_address;
|
|
1551
1551
|
const signerAccount = { signer, addr: activeAddress };
|
|
1552
1552
|
const marketClient = new MarketAppClient(
|
|
1553
1553
|
{ resolveBy: "id", id: marketAppId, sender: signerAccount },
|
|
@@ -1674,12 +1674,12 @@ var cancelOrder = async (config, params) => {
|
|
|
1674
1674
|
};
|
|
1675
1675
|
};
|
|
1676
1676
|
var proposeMatch = async (config, params) => {
|
|
1677
|
-
const { algodClient, signer, activeAddress, matcherAppId, usdcAssetId
|
|
1677
|
+
const { algodClient, signer, activeAddress, matcherAppId, usdcAssetId } = config;
|
|
1678
1678
|
const { marketAppId, makerEscrowAppId, makerAddress, quantityMatched } = params;
|
|
1679
1679
|
const globalState = await getMarketGlobalState(algodClient, marketAppId);
|
|
1680
1680
|
const yesAssetId = globalState.yes_asset_id;
|
|
1681
1681
|
const noAssetId = globalState.no_asset_id;
|
|
1682
|
-
const marketFeeAddress = globalState.fee_address
|
|
1682
|
+
const marketFeeAddress = globalState.fee_address;
|
|
1683
1683
|
const signerAccount = { signer, addr: activeAddress };
|
|
1684
1684
|
const matcherClient = new MatcherAppClient(
|
|
1685
1685
|
{ resolveBy: "id", id: matcherAppId, sender: signerAccount },
|
|
@@ -1930,7 +1930,121 @@ var getPositions = async (config, walletAddress) => {
|
|
|
1930
1930
|
|
|
1931
1931
|
// src/modules/markets.ts
|
|
1932
1932
|
var DEFAULT_API_BASE_URL = "https://partners.alphaarcade.com/api";
|
|
1933
|
-
var
|
|
1933
|
+
var DEFAULT_MARKET_CREATOR_ADDRESS = "5P5Y6HTWUNG2E3VXBQDZN3ENZD3JPAIR5PKT3LOYJAPAUKOLFD6KANYTRY";
|
|
1934
|
+
var groupMultiChoiceMarkets = (flatMarkets) => {
|
|
1935
|
+
const parentMap = /* @__PURE__ */ new Map();
|
|
1936
|
+
const result = [];
|
|
1937
|
+
for (const m of flatMarkets) {
|
|
1938
|
+
const separatorIdx = m.title.lastIndexOf(" : ");
|
|
1939
|
+
if (separatorIdx === -1) {
|
|
1940
|
+
result.push(m);
|
|
1941
|
+
continue;
|
|
1942
|
+
}
|
|
1943
|
+
const parentTitle = m.title.substring(0, separatorIdx).trim();
|
|
1944
|
+
const optionTitle = m.title.substring(separatorIdx + 3).trim();
|
|
1945
|
+
let parent = parentMap.get(parentTitle);
|
|
1946
|
+
if (!parent) {
|
|
1947
|
+
parent = {
|
|
1948
|
+
id: `group:${parentTitle}`,
|
|
1949
|
+
title: parentTitle,
|
|
1950
|
+
marketAppId: m.marketAppId,
|
|
1951
|
+
// Use first option's app ID as the parent's
|
|
1952
|
+
yesAssetId: 0,
|
|
1953
|
+
noAssetId: 0,
|
|
1954
|
+
endTs: m.endTs,
|
|
1955
|
+
isResolved: m.isResolved,
|
|
1956
|
+
isLive: m.isLive,
|
|
1957
|
+
feeBase: m.feeBase,
|
|
1958
|
+
source: "onchain",
|
|
1959
|
+
options: []
|
|
1960
|
+
};
|
|
1961
|
+
parentMap.set(parentTitle, parent);
|
|
1962
|
+
result.push(parent);
|
|
1963
|
+
}
|
|
1964
|
+
parent.options.push({
|
|
1965
|
+
id: m.id,
|
|
1966
|
+
title: optionTitle,
|
|
1967
|
+
marketAppId: m.marketAppId,
|
|
1968
|
+
yesAssetId: m.yesAssetId,
|
|
1969
|
+
noAssetId: m.noAssetId,
|
|
1970
|
+
yesProb: 0,
|
|
1971
|
+
noProb: 0
|
|
1972
|
+
});
|
|
1973
|
+
}
|
|
1974
|
+
return result;
|
|
1975
|
+
};
|
|
1976
|
+
var getMarketsOnChain = async (config, options) => {
|
|
1977
|
+
const creatorAddress = config.marketCreatorAddress ?? DEFAULT_MARKET_CREATOR_ADDRESS;
|
|
1978
|
+
const activeOnly = options?.activeOnly ?? true;
|
|
1979
|
+
const allApps = [];
|
|
1980
|
+
let nextToken;
|
|
1981
|
+
let hasMore = true;
|
|
1982
|
+
while (hasMore) {
|
|
1983
|
+
let query = config.indexerClient.lookupAccountCreatedApplications(creatorAddress).limit(100);
|
|
1984
|
+
if (nextToken) {
|
|
1985
|
+
query = query.nextToken(nextToken);
|
|
1986
|
+
}
|
|
1987
|
+
const response = await query.do();
|
|
1988
|
+
if (response.applications?.length) {
|
|
1989
|
+
allApps.push(...response.applications);
|
|
1990
|
+
}
|
|
1991
|
+
if (response["next-token"]) {
|
|
1992
|
+
nextToken = response["next-token"];
|
|
1993
|
+
} else {
|
|
1994
|
+
hasMore = false;
|
|
1995
|
+
}
|
|
1996
|
+
}
|
|
1997
|
+
const flatMarkets = [];
|
|
1998
|
+
for (const app of allApps) {
|
|
1999
|
+
if (app.deleted) continue;
|
|
2000
|
+
const rawState = app.params?.["global-state"];
|
|
2001
|
+
if (!rawState) continue;
|
|
2002
|
+
const state = decodeGlobalState(rawState);
|
|
2003
|
+
if (activeOnly && !state.is_activated) continue;
|
|
2004
|
+
if (activeOnly && state.is_resolved) continue;
|
|
2005
|
+
if (activeOnly && state.resolution_time && state.resolution_time < Math.floor(Date.now() / 1e3)) continue;
|
|
2006
|
+
const appId = Number(app.id);
|
|
2007
|
+
flatMarkets.push({
|
|
2008
|
+
id: String(appId),
|
|
2009
|
+
title: state.title || "",
|
|
2010
|
+
marketAppId: appId,
|
|
2011
|
+
yesAssetId: state.yes_asset_id || 0,
|
|
2012
|
+
noAssetId: state.no_asset_id || 0,
|
|
2013
|
+
endTs: state.resolution_time || 0,
|
|
2014
|
+
isResolved: !!state.is_resolved,
|
|
2015
|
+
isLive: !!state.is_activated && !state.is_resolved,
|
|
2016
|
+
feeBase: state.fee_base_percent,
|
|
2017
|
+
source: "onchain"
|
|
2018
|
+
});
|
|
2019
|
+
}
|
|
2020
|
+
return groupMultiChoiceMarkets(flatMarkets);
|
|
2021
|
+
};
|
|
2022
|
+
var getMarketOnChain = async (config, marketAppId) => {
|
|
2023
|
+
try {
|
|
2024
|
+
const appId = typeof marketAppId === "string" ? Number(marketAppId) : marketAppId;
|
|
2025
|
+
const appInfo = await config.algodClient.getApplicationByID(appId).do();
|
|
2026
|
+
const rawState = appInfo.params?.["global-state"] ?? appInfo["params"]?.["global-state"] ?? [];
|
|
2027
|
+
const state = decodeGlobalState(rawState);
|
|
2028
|
+
return {
|
|
2029
|
+
id: String(appId),
|
|
2030
|
+
title: state.title || "",
|
|
2031
|
+
marketAppId: appId,
|
|
2032
|
+
yesAssetId: state.yes_asset_id || 0,
|
|
2033
|
+
noAssetId: state.no_asset_id || 0,
|
|
2034
|
+
endTs: state.resolution_time || 0,
|
|
2035
|
+
isResolved: !!state.is_resolved,
|
|
2036
|
+
isLive: !!state.is_activated && !state.is_resolved,
|
|
2037
|
+
feeBase: state.fee_base_percent,
|
|
2038
|
+
source: "onchain"
|
|
2039
|
+
};
|
|
2040
|
+
} catch {
|
|
2041
|
+
return null;
|
|
2042
|
+
}
|
|
2043
|
+
};
|
|
2044
|
+
var getMarketsFromApi = async (config) => {
|
|
2045
|
+
if (!config.apiKey) {
|
|
2046
|
+
throw new Error("apiKey is required for API-based market fetching. Use getMarketsOnChain() instead, or pass an apiKey.");
|
|
2047
|
+
}
|
|
1934
2048
|
const baseUrl = config.apiBaseUrl ?? DEFAULT_API_BASE_URL;
|
|
1935
2049
|
const allMarkets = [];
|
|
1936
2050
|
let lastEvaluatedKey;
|
|
@@ -1947,10 +2061,10 @@ var getMarkets = async (config) => {
|
|
|
1947
2061
|
}
|
|
1948
2062
|
const data = await response.json();
|
|
1949
2063
|
if (Array.isArray(data)) {
|
|
1950
|
-
allMarkets.push(...data);
|
|
2064
|
+
allMarkets.push(...data.map((m) => ({ ...m, source: "api" })));
|
|
1951
2065
|
hasMore = false;
|
|
1952
2066
|
} else if (data.markets) {
|
|
1953
|
-
allMarkets.push(...data.markets);
|
|
2067
|
+
allMarkets.push(...data.markets.map((m) => ({ ...m, source: "api" })));
|
|
1954
2068
|
lastEvaluatedKey = data.lastEvaluatedKey;
|
|
1955
2069
|
hasMore = !!lastEvaluatedKey;
|
|
1956
2070
|
} else {
|
|
@@ -1959,7 +2073,10 @@ var getMarkets = async (config) => {
|
|
|
1959
2073
|
}
|
|
1960
2074
|
return allMarkets;
|
|
1961
2075
|
};
|
|
1962
|
-
var
|
|
2076
|
+
var getMarketFromApi = async (config, marketId) => {
|
|
2077
|
+
if (!config.apiKey) {
|
|
2078
|
+
throw new Error("apiKey is required for API-based market fetching. Use getMarketOnChain() instead, or pass an apiKey.");
|
|
2079
|
+
}
|
|
1963
2080
|
const baseUrl = config.apiBaseUrl ?? DEFAULT_API_BASE_URL;
|
|
1964
2081
|
const url = `${baseUrl}/get-market?marketId=${encodeURIComponent(marketId)}`;
|
|
1965
2082
|
const response = await fetch(url, { headers: { "x-api-key": config.apiKey } });
|
|
@@ -1968,7 +2085,21 @@ var getMarket = async (config, marketId) => {
|
|
|
1968
2085
|
throw new Error(`Alpha API error: ${response.status} ${response.statusText}`);
|
|
1969
2086
|
}
|
|
1970
2087
|
const data = await response.json();
|
|
1971
|
-
|
|
2088
|
+
const market = data.market ?? data ?? null;
|
|
2089
|
+
if (market) market.source = "api";
|
|
2090
|
+
return market;
|
|
2091
|
+
};
|
|
2092
|
+
var getMarkets = async (config) => {
|
|
2093
|
+
if (config.apiKey) {
|
|
2094
|
+
return getMarketsFromApi(config);
|
|
2095
|
+
}
|
|
2096
|
+
return getMarketsOnChain(config);
|
|
2097
|
+
};
|
|
2098
|
+
var getMarket = async (config, marketId) => {
|
|
2099
|
+
if (config.apiKey) {
|
|
2100
|
+
return getMarketFromApi(config, marketId);
|
|
2101
|
+
}
|
|
2102
|
+
return getMarketOnChain(config, marketId);
|
|
1972
2103
|
};
|
|
1973
2104
|
|
|
1974
2105
|
// src/client.ts
|
|
@@ -1981,8 +2112,6 @@ var AlphaClient = class {
|
|
|
1981
2112
|
if (!config.activeAddress) throw new Error("activeAddress is required");
|
|
1982
2113
|
if (!config.matcherAppId) throw new Error("matcherAppId is required");
|
|
1983
2114
|
if (!config.usdcAssetId) throw new Error("usdcAssetId is required");
|
|
1984
|
-
if (!config.feeAddress) throw new Error("feeAddress is required");
|
|
1985
|
-
if (!config.apiKey) throw new Error("apiKey is required");
|
|
1986
2115
|
this.config = {
|
|
1987
2116
|
...config,
|
|
1988
2117
|
apiBaseUrl: config.apiBaseUrl ?? "https://partners.alphaarcade.com/api"
|
|
@@ -2121,9 +2250,10 @@ var AlphaClient = class {
|
|
|
2121
2250
|
// Markets
|
|
2122
2251
|
// ============================================
|
|
2123
2252
|
/**
|
|
2124
|
-
* Fetches all live, tradeable markets
|
|
2253
|
+
* Fetches all live, tradeable markets.
|
|
2125
2254
|
*
|
|
2126
|
-
*
|
|
2255
|
+
* If an API key is configured, uses the Alpha REST API (richer data: images, categories, volume).
|
|
2256
|
+
* Otherwise, discovers markets on-chain from the market creator address (no API key needed).
|
|
2127
2257
|
*
|
|
2128
2258
|
* @returns Array of live markets
|
|
2129
2259
|
*/
|
|
@@ -2133,14 +2263,57 @@ var AlphaClient = class {
|
|
|
2133
2263
|
/**
|
|
2134
2264
|
* Fetches a single market by its ID.
|
|
2135
2265
|
*
|
|
2136
|
-
*
|
|
2266
|
+
* If an API key is configured, uses the Alpha REST API.
|
|
2267
|
+
* Otherwise, reads the market's on-chain global state (pass the market app ID as a string).
|
|
2268
|
+
*
|
|
2269
|
+
* @param marketId - The market ID (UUID for API, app ID string for on-chain)
|
|
2137
2270
|
* @returns The market data, or null if not found
|
|
2138
2271
|
*/
|
|
2139
2272
|
async getMarket(marketId) {
|
|
2140
2273
|
return getMarket(this.config, marketId);
|
|
2141
2274
|
}
|
|
2275
|
+
/**
|
|
2276
|
+
* Fetches all live markets directly from the blockchain (no API key needed).
|
|
2277
|
+
*
|
|
2278
|
+
* Discovers markets by looking up all apps created by the market creator address.
|
|
2279
|
+
* Returns core data: title, asset IDs, resolution time, fees.
|
|
2280
|
+
* Does NOT include images, categories, volume, or probabilities.
|
|
2281
|
+
*
|
|
2282
|
+
* @returns Array of live markets from on-chain data
|
|
2283
|
+
*/
|
|
2284
|
+
async getMarketsOnChain() {
|
|
2285
|
+
return getMarketsOnChain(this.config);
|
|
2286
|
+
}
|
|
2287
|
+
/**
|
|
2288
|
+
* Fetches a single market by app ID directly from the blockchain (no API key needed).
|
|
2289
|
+
*
|
|
2290
|
+
* @param marketAppId - The market app ID
|
|
2291
|
+
* @returns The market data, or null if not found
|
|
2292
|
+
*/
|
|
2293
|
+
async getMarketOnChain(marketAppId) {
|
|
2294
|
+
return getMarketOnChain(this.config, marketAppId);
|
|
2295
|
+
}
|
|
2296
|
+
/**
|
|
2297
|
+
* Fetches all live markets from the Alpha REST API (requires API key).
|
|
2298
|
+
*
|
|
2299
|
+
* Returns richer data than on-chain: images, categories, volume, probabilities.
|
|
2300
|
+
*
|
|
2301
|
+
* @returns Array of live markets from the API
|
|
2302
|
+
*/
|
|
2303
|
+
async getMarketsFromApi() {
|
|
2304
|
+
return getMarketsFromApi(this.config);
|
|
2305
|
+
}
|
|
2306
|
+
/**
|
|
2307
|
+
* Fetches a single market by ID from the Alpha REST API (requires API key).
|
|
2308
|
+
*
|
|
2309
|
+
* @param marketId - The market UUID
|
|
2310
|
+
* @returns The market data, or null if not found
|
|
2311
|
+
*/
|
|
2312
|
+
async getMarketFromApi(marketId) {
|
|
2313
|
+
return getMarketFromApi(this.config, marketId);
|
|
2314
|
+
}
|
|
2142
2315
|
};
|
|
2143
2316
|
|
|
2144
|
-
export { AlphaClient, calculateFee, calculateFeeFromTotal, calculateMatchingOrders, checkAssetOptIn, decodeGlobalState, getEscrowGlobalState, getMarketGlobalState };
|
|
2317
|
+
export { AlphaClient, DEFAULT_MARKET_CREATOR_ADDRESS, calculateFee, calculateFeeFromTotal, calculateMatchingOrders, checkAssetOptIn, decodeGlobalState, getEscrowGlobalState, getMarketFromApi, getMarketGlobalState, getMarketOnChain, getMarketsFromApi, getMarketsOnChain };
|
|
2145
2318
|
//# sourceMappingURL=index.js.map
|
|
2146
2319
|
//# sourceMappingURL=index.js.map
|