@alpha-arcade/sdk 0.2.6 → 0.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -46,6 +46,13 @@ type Market = {
46
46
  featured?: boolean;
47
47
  options?: MarketOption[];
48
48
  feeBase?: number;
49
+ /** Liquidty Rewards Info */
50
+ totalRewards?: number;
51
+ rewardsPaidOut?: number;
52
+ rewardsSpreadDistance?: number;
53
+ rewardsMinContracts?: number;
54
+ lastRewardAmount?: number;
55
+ lastRewardTs?: number;
49
56
  /** Data source: 'onchain' or 'api' */
50
57
  source?: 'onchain' | 'api';
51
58
  [key: string]: unknown;
@@ -452,6 +459,13 @@ declare class AlphaClient {
452
459
  * @returns Array of open orders
453
460
  */
454
461
  getOpenOrders(marketAppId: number, walletAddress?: string): Promise<OpenOrder[]>;
462
+ /**
463
+ * Gets all open orders for a wallet across every live market using the Alpha REST API.
464
+ *
465
+ * @param walletAddress - The wallet address
466
+ * @returns Array of open orders for the wallet
467
+ */
468
+ getWalletOrdersFromApi(walletAddress: string): Promise<OpenOrder[]>;
455
469
  /**
456
470
  * Fetches all live, tradeable markets.
457
471
  *
@@ -496,6 +510,12 @@ declare class AlphaClient {
496
510
  * @returns Array of live markets from the API
497
511
  */
498
512
  getLiveMarketsFromApi(): Promise<Market[]>;
513
+ /**
514
+ * Fetches the reward markets from the Alpha REST API (requires API key).
515
+ *
516
+ * @returns Array of reward markets
517
+ */
518
+ getRewardMarkets(): Promise<Market[]>;
499
519
  /**
500
520
  * Fetches a single market by ID from the Alpha REST API (requires API key).
501
521
  *
@@ -505,8 +525,6 @@ declare class AlphaClient {
505
525
  getMarketFromApi(marketId: string): Promise<Market | null>;
506
526
  }
507
527
 
508
- /** The default Alpha Arcade mainnet market creator address */
509
- declare const DEFAULT_MARKET_CREATOR_ADDRESS = "5P5Y6HTWUNG2E3VXBQDZN3ENZD3JPAIR5PKT3LOYJAPAUKOLFD6KANYTRY";
510
528
  /**
511
529
  * Fetches all live, tradeable markets directly from the Algorand blockchain.
512
530
  *
@@ -548,6 +566,9 @@ declare const getLiveMarketsFromApi: (config: AlphaClientConfig) => Promise<Mark
548
566
  */
549
567
  declare const getMarketFromApi: (config: AlphaClientConfig, marketId: string) => Promise<Market | null>;
550
568
 
569
+ declare const DEFAULT_API_BASE_URL = "https://platform.alphaarcade.com/api";
570
+ declare const DEFAULT_MARKET_CREATOR_ADDRESS = "5P5Y6HTWUNG2E3VXBQDZN3ENZD3JPAIR5PKT3LOYJAPAUKOLFD6KANYTRY";
571
+
551
572
  /**
552
573
  * Calculates the required fee amount in microunits.
553
574
  *
@@ -626,4 +647,4 @@ declare const getEscrowGlobalState: (indexerClient: algosdk.Indexer, escrowAppId
626
647
  */
627
648
  declare const checkAssetOptIn: (algodClient: algosdk.Algodv2, address: string, assetId: number) => Promise<boolean>;
628
649
 
629
- 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 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, getLiveMarketsFromApi, getMarketFromApi, getMarketGlobalState, getMarketOnChain, getMarketsOnChain };
650
+ 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 CreateOrderResult, DEFAULT_API_BASE_URL, 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, getLiveMarketsFromApi, getMarketFromApi, getMarketGlobalState, getMarketOnChain, getMarketsOnChain };
package/dist/index.d.ts CHANGED
@@ -46,6 +46,13 @@ type Market = {
46
46
  featured?: boolean;
47
47
  options?: MarketOption[];
48
48
  feeBase?: number;
49
+ /** Liquidty Rewards Info */
50
+ totalRewards?: number;
51
+ rewardsPaidOut?: number;
52
+ rewardsSpreadDistance?: number;
53
+ rewardsMinContracts?: number;
54
+ lastRewardAmount?: number;
55
+ lastRewardTs?: number;
49
56
  /** Data source: 'onchain' or 'api' */
50
57
  source?: 'onchain' | 'api';
51
58
  [key: string]: unknown;
@@ -452,6 +459,13 @@ declare class AlphaClient {
452
459
  * @returns Array of open orders
453
460
  */
454
461
  getOpenOrders(marketAppId: number, walletAddress?: string): Promise<OpenOrder[]>;
462
+ /**
463
+ * Gets all open orders for a wallet across every live market using the Alpha REST API.
464
+ *
465
+ * @param walletAddress - The wallet address
466
+ * @returns Array of open orders for the wallet
467
+ */
468
+ getWalletOrdersFromApi(walletAddress: string): Promise<OpenOrder[]>;
455
469
  /**
456
470
  * Fetches all live, tradeable markets.
457
471
  *
@@ -496,6 +510,12 @@ declare class AlphaClient {
496
510
  * @returns Array of live markets from the API
497
511
  */
498
512
  getLiveMarketsFromApi(): Promise<Market[]>;
513
+ /**
514
+ * Fetches the reward markets from the Alpha REST API (requires API key).
515
+ *
516
+ * @returns Array of reward markets
517
+ */
518
+ getRewardMarkets(): Promise<Market[]>;
499
519
  /**
500
520
  * Fetches a single market by ID from the Alpha REST API (requires API key).
501
521
  *
@@ -505,8 +525,6 @@ declare class AlphaClient {
505
525
  getMarketFromApi(marketId: string): Promise<Market | null>;
506
526
  }
507
527
 
508
- /** The default Alpha Arcade mainnet market creator address */
509
- declare const DEFAULT_MARKET_CREATOR_ADDRESS = "5P5Y6HTWUNG2E3VXBQDZN3ENZD3JPAIR5PKT3LOYJAPAUKOLFD6KANYTRY";
510
528
  /**
511
529
  * Fetches all live, tradeable markets directly from the Algorand blockchain.
512
530
  *
@@ -548,6 +566,9 @@ declare const getLiveMarketsFromApi: (config: AlphaClientConfig) => Promise<Mark
548
566
  */
549
567
  declare const getMarketFromApi: (config: AlphaClientConfig, marketId: string) => Promise<Market | null>;
550
568
 
569
+ declare const DEFAULT_API_BASE_URL = "https://platform.alphaarcade.com/api";
570
+ declare const DEFAULT_MARKET_CREATOR_ADDRESS = "5P5Y6HTWUNG2E3VXBQDZN3ENZD3JPAIR5PKT3LOYJAPAUKOLFD6KANYTRY";
571
+
551
572
  /**
552
573
  * Calculates the required fee amount in microunits.
553
574
  *
@@ -626,4 +647,4 @@ declare const getEscrowGlobalState: (indexerClient: algosdk.Indexer, escrowAppId
626
647
  */
627
648
  declare const checkAssetOptIn: (algodClient: algosdk.Algodv2, address: string, assetId: number) => Promise<boolean>;
628
649
 
629
- 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 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, getLiveMarketsFromApi, getMarketFromApi, getMarketGlobalState, getMarketOnChain, getMarketsOnChain };
650
+ 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 CreateOrderResult, DEFAULT_API_BASE_URL, 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, getLiveMarketsFromApi, getMarketFromApi, getMarketGlobalState, getMarketOnChain, getMarketsOnChain };
package/dist/index.js CHANGED
@@ -1402,6 +1402,12 @@ var calculateMatchingOrders = (orderbook, isBuying, isYes, quantity, price, slip
1402
1402
  }
1403
1403
  return matches;
1404
1404
  };
1405
+
1406
+ // src/constants.ts
1407
+ var DEFAULT_API_BASE_URL = "https://platform.alphaarcade.com/api";
1408
+ var DEFAULT_MARKET_CREATOR_ADDRESS = "5P5Y6HTWUNG2E3VXBQDZN3ENZD3JPAIR5PKT3LOYJAPAUKOLFD6KANYTRY";
1409
+
1410
+ // src/modules/orderbook.ts
1405
1411
  var getAllCreatedApplications = async (indexerClient, address, limit = 100) => {
1406
1412
  let applications = [];
1407
1413
  let nextToken;
@@ -1495,6 +1501,49 @@ var getOpenOrders = async (config, marketAppId, walletAddress) => {
1495
1501
  owner: o.globalState.owner ?? ""
1496
1502
  }));
1497
1503
  };
1504
+ var normalizeApiOrder = (raw) => ({
1505
+ escrowAppId: Number(raw.escrowAppId ?? raw.orderId),
1506
+ marketAppId: Number(raw.marketAppId),
1507
+ position: raw.orderPosition ?? 0,
1508
+ side: raw.orderSide === "BUY" ? 1 : 0,
1509
+ price: raw.orderPrice ?? 0,
1510
+ quantity: raw.orderQuantity ?? 0,
1511
+ quantityFilled: raw.orderQuantityFilled ?? 0,
1512
+ slippage: raw.slippage ?? 0,
1513
+ owner: raw.senderWallet ?? ""
1514
+ });
1515
+ var getWalletOrdersFromApi = async (config, walletAddress) => {
1516
+ if (!config.apiKey) {
1517
+ throw new Error("apiKey is required for API-based market fetching. Retrieve an API key from the Alpha Arcade platform via the Account page and pass it to the client.");
1518
+ }
1519
+ const baseUrl = config.apiBaseUrl ?? DEFAULT_API_BASE_URL;
1520
+ const allOrders = [];
1521
+ let cursor;
1522
+ let hasMore = true;
1523
+ while (hasMore) {
1524
+ const params = new URLSearchParams({ wallet: walletAddress, limit: "300" });
1525
+ if (cursor) {
1526
+ params.set("cursor", cursor);
1527
+ }
1528
+ const url = `${baseUrl}/get-wallet-orders?${params.toString()}`;
1529
+ const response = await fetch(url, { headers: { "x-api-key": config.apiKey } });
1530
+ if (!response.ok) {
1531
+ throw new Error(`Alpha API error: ${response.status} ${response.statusText}`);
1532
+ }
1533
+ const data = await response.json();
1534
+ if (Array.isArray(data)) {
1535
+ allOrders.push(...data.map(normalizeApiOrder));
1536
+ hasMore = false;
1537
+ } else if (data.orders) {
1538
+ allOrders.push(...data.orders.map(normalizeApiOrder));
1539
+ cursor = data.nextCursor ?? void 0;
1540
+ hasMore = data.hasMore === true && !!cursor;
1541
+ } else {
1542
+ hasMore = false;
1543
+ }
1544
+ }
1545
+ return allOrders;
1546
+ };
1498
1547
 
1499
1548
  // src/modules/trading.ts
1500
1549
  var extractEscrowAppId = async (algodClient, indexerClient, targetTxId) => {
@@ -1956,8 +2005,6 @@ var getPositions = async (config, walletAddress) => {
1956
2005
  };
1957
2006
 
1958
2007
  // src/modules/markets.ts
1959
- var DEFAULT_API_BASE_URL = "https://partners.alphaarcade.com/api";
1960
- var DEFAULT_MARKET_CREATOR_ADDRESS = "5P5Y6HTWUNG2E3VXBQDZN3ENZD3JPAIR5PKT3LOYJAPAUKOLFD6KANYTRY";
1961
2008
  var toSeconds = (ts) => ts > 1e10 ? Math.floor(ts / 1e3) : ts;
1962
2009
  var groupMultiChoiceMarkets = (flatMarkets) => {
1963
2010
  const parentMap = /* @__PURE__ */ new Map();
@@ -2071,7 +2118,7 @@ var getMarketOnChain = async (config, marketAppId) => {
2071
2118
  };
2072
2119
  var getLiveMarketsFromApi = async (config) => {
2073
2120
  if (!config.apiKey) {
2074
- throw new Error("apiKey is required for API-based market fetching. Use getMarketsOnChain() instead, or pass an apiKey.");
2121
+ throw new Error("apiKey is required for API-based market fetching. Use getMarketsOnChain() instead, or retrieve an API key from the Alpha Arcade platform via the Account page and pass it to the client.");
2075
2122
  }
2076
2123
  const baseUrl = config.apiBaseUrl ?? DEFAULT_API_BASE_URL;
2077
2124
  const allMarkets = [];
@@ -2108,7 +2155,7 @@ var getLiveMarketsFromApi = async (config) => {
2108
2155
  };
2109
2156
  var getMarketFromApi = async (config, marketId) => {
2110
2157
  if (!config.apiKey) {
2111
- throw new Error("apiKey is required for API-based market fetching. Use getMarketOnChain() instead, or pass an apiKey.");
2158
+ throw new Error("apiKey is required for API-based market fetching. Use getMarketOnChain() instead, or retrieve an API key from the Alpha Arcade platform via the Account page and pass it to the client.");
2112
2159
  }
2113
2160
  const baseUrl = config.apiBaseUrl ?? DEFAULT_API_BASE_URL;
2114
2161
  const url = `${baseUrl}/get-market?marketId=${encodeURIComponent(marketId)}`;
@@ -2125,6 +2172,13 @@ var getMarketFromApi = async (config, marketId) => {
2125
2172
  }
2126
2173
  return market;
2127
2174
  };
2175
+ var getRewardMarkets = async (config) => {
2176
+ if (!config.apiKey) {
2177
+ throw new Error("apiKey is required for API-based market fetching. Retrieve an API key from the Alpha Arcade platform via the Account page and pass it to the client.");
2178
+ }
2179
+ const markets = await getLiveMarketsFromApi(config);
2180
+ return markets.filter((m) => m.totalRewards && m.totalRewards > 0);
2181
+ };
2128
2182
  var getLiveMarkets = async (config) => {
2129
2183
  if (config.apiKey) {
2130
2184
  return getLiveMarketsFromApi(config);
@@ -2150,7 +2204,7 @@ var AlphaClient = class {
2150
2204
  if (!config.usdcAssetId) throw new Error("usdcAssetId is required");
2151
2205
  this.config = {
2152
2206
  ...config,
2153
- apiBaseUrl: config.apiBaseUrl ?? "https://partners.alphaarcade.com/api"
2207
+ apiBaseUrl: config.apiBaseUrl ?? DEFAULT_API_BASE_URL
2154
2208
  };
2155
2209
  }
2156
2210
  // ============================================
@@ -2282,6 +2336,15 @@ var AlphaClient = class {
2282
2336
  async getOpenOrders(marketAppId, walletAddress) {
2283
2337
  return getOpenOrders(this.config, marketAppId, walletAddress);
2284
2338
  }
2339
+ /**
2340
+ * Gets all open orders for a wallet across every live market using the Alpha REST API.
2341
+ *
2342
+ * @param walletAddress - The wallet address
2343
+ * @returns Array of open orders for the wallet
2344
+ */
2345
+ async getWalletOrdersFromApi(walletAddress) {
2346
+ return getWalletOrdersFromApi(this.config, walletAddress);
2347
+ }
2285
2348
  // ============================================
2286
2349
  // Markets
2287
2350
  // ============================================
@@ -2339,6 +2402,14 @@ var AlphaClient = class {
2339
2402
  async getLiveMarketsFromApi() {
2340
2403
  return getLiveMarketsFromApi(this.config);
2341
2404
  }
2405
+ /**
2406
+ * Fetches the reward markets from the Alpha REST API (requires API key).
2407
+ *
2408
+ * @returns Array of reward markets
2409
+ */
2410
+ async getRewardMarkets() {
2411
+ return getRewardMarkets(this.config);
2412
+ }
2342
2413
  /**
2343
2414
  * Fetches a single market by ID from the Alpha REST API (requires API key).
2344
2415
  *
@@ -2350,6 +2421,6 @@ var AlphaClient = class {
2350
2421
  }
2351
2422
  };
2352
2423
 
2353
- export { AlphaClient, DEFAULT_MARKET_CREATOR_ADDRESS, calculateFee, calculateFeeFromTotal, calculateMatchingOrders, checkAssetOptIn, decodeGlobalState, getEscrowGlobalState, getLiveMarketsFromApi, getMarketFromApi, getMarketGlobalState, getMarketOnChain, getMarketsOnChain };
2424
+ export { AlphaClient, DEFAULT_API_BASE_URL, DEFAULT_MARKET_CREATOR_ADDRESS, calculateFee, calculateFeeFromTotal, calculateMatchingOrders, checkAssetOptIn, decodeGlobalState, getEscrowGlobalState, getLiveMarketsFromApi, getMarketFromApi, getMarketGlobalState, getMarketOnChain, getMarketsOnChain };
2354
2425
  //# sourceMappingURL=index.js.map
2355
2426
  //# sourceMappingURL=index.js.map