@alpha-arcade/sdk 0.2.2 → 0.2.3

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
@@ -147,6 +147,8 @@ type CounterpartyMatch = {
147
147
  quantity: number;
148
148
  /** Owner address of the counterparty order */
149
149
  owner: string;
150
+ /** Effective fill price in microunits (accounts for complementary matching, e.g. 1_000_000 - noPrice for YES buys) */
151
+ price?: number;
150
152
  };
151
153
  /** Result of creating an order */
152
154
  type CreateOrderResult = {
@@ -161,6 +163,8 @@ type CreateOrderResult = {
161
163
  type CreateMarketOrderResult = CreateOrderResult & {
162
164
  /** Total quantity that was matched */
163
165
  matchedQuantity: number;
166
+ /** Weighted average fill price in microunits (accounts for complementary matching) */
167
+ matchedPrice: number;
164
168
  };
165
169
  /** Result of cancelling an order */
166
170
  type CancelOrderResult = {
@@ -168,6 +172,8 @@ type CancelOrderResult = {
168
172
  success: boolean;
169
173
  /** Transaction IDs */
170
174
  txIds: string[];
175
+ /** Confirmed round number */
176
+ confirmedRound: number;
171
177
  };
172
178
  /** Result of proposing a match */
173
179
  type ProposeMatchResult = {
@@ -175,6 +181,8 @@ type ProposeMatchResult = {
175
181
  success: boolean;
176
182
  /** Transaction IDs */
177
183
  txIds: string[];
184
+ /** Confirmed round number */
185
+ confirmedRound: number;
178
186
  };
179
187
  /** A single entry in the orderbook (one price level, one order) */
180
188
  type OrderbookEntry = {
@@ -250,11 +258,15 @@ type ClaimResult = {
250
258
  success: boolean;
251
259
  txIds: string[];
252
260
  confirmedRound: number;
261
+ /** Amount of tokens claimed in microunits */
262
+ amountClaimed: number;
253
263
  };
254
264
  /** A wallet's token position in a market */
255
265
  type WalletPosition = {
256
266
  /** Market app ID */
257
267
  marketAppId: number;
268
+ /** Market title (fetched from on-chain global state) */
269
+ title: string;
258
270
  /** YES token ASA ID */
259
271
  yesAssetId: number;
260
272
  /** NO token ASA ID */
package/dist/index.d.ts CHANGED
@@ -147,6 +147,8 @@ type CounterpartyMatch = {
147
147
  quantity: number;
148
148
  /** Owner address of the counterparty order */
149
149
  owner: string;
150
+ /** Effective fill price in microunits (accounts for complementary matching, e.g. 1_000_000 - noPrice for YES buys) */
151
+ price?: number;
150
152
  };
151
153
  /** Result of creating an order */
152
154
  type CreateOrderResult = {
@@ -161,6 +163,8 @@ type CreateOrderResult = {
161
163
  type CreateMarketOrderResult = CreateOrderResult & {
162
164
  /** Total quantity that was matched */
163
165
  matchedQuantity: number;
166
+ /** Weighted average fill price in microunits (accounts for complementary matching) */
167
+ matchedPrice: number;
164
168
  };
165
169
  /** Result of cancelling an order */
166
170
  type CancelOrderResult = {
@@ -168,6 +172,8 @@ type CancelOrderResult = {
168
172
  success: boolean;
169
173
  /** Transaction IDs */
170
174
  txIds: string[];
175
+ /** Confirmed round number */
176
+ confirmedRound: number;
171
177
  };
172
178
  /** Result of proposing a match */
173
179
  type ProposeMatchResult = {
@@ -175,6 +181,8 @@ type ProposeMatchResult = {
175
181
  success: boolean;
176
182
  /** Transaction IDs */
177
183
  txIds: string[];
184
+ /** Confirmed round number */
185
+ confirmedRound: number;
178
186
  };
179
187
  /** A single entry in the orderbook (one price level, one order) */
180
188
  type OrderbookEntry = {
@@ -250,11 +258,15 @@ type ClaimResult = {
250
258
  success: boolean;
251
259
  txIds: string[];
252
260
  confirmedRound: number;
261
+ /** Amount of tokens claimed in microunits */
262
+ amountClaimed: number;
253
263
  };
254
264
  /** A wallet's token position in a market */
255
265
  type WalletPosition = {
256
266
  /** Market app ID */
257
267
  marketAppId: number;
268
+ /** Market title (fetched from on-chain global state) */
269
+ title: string;
258
270
  /** YES token ASA ID */
259
271
  yesAssetId: number;
260
272
  /** NO token ASA ID */
package/dist/index.js CHANGED
@@ -1394,7 +1394,8 @@ var calculateMatchingOrders = (orderbook, isBuying, isYes, quantity, price, slip
1394
1394
  matches.push({
1395
1395
  escrowAppId: counterParty.escrowAppId,
1396
1396
  quantity: amountToTake,
1397
- owner: counterParty.owner
1397
+ owner: counterParty.owner,
1398
+ price: counterParty.price
1398
1399
  });
1399
1400
  volumeLeft -= amountToTake;
1400
1401
  }
@@ -1534,11 +1535,14 @@ var createMarketOrder = async (config, params) => {
1534
1535
  );
1535
1536
  }
1536
1537
  const totalMatchedQuantity = matchingOrders.reduce((sum, o) => sum + o.quantity, 0);
1538
+ const matchedPrice = totalMatchedQuantity > 0 ? Math.round(
1539
+ matchingOrders.reduce((sum, o) => sum + (o.price ?? params.price) * o.quantity, 0) / totalMatchedQuantity
1540
+ ) : params.price;
1537
1541
  const result = await createOrder(config, {
1538
1542
  ...params,
1539
1543
  matchingOrders
1540
1544
  });
1541
- return { ...result, matchedQuantity: totalMatchedQuantity };
1545
+ return { ...result, matchedQuantity: totalMatchedQuantity, matchedPrice };
1542
1546
  };
1543
1547
  var createOrder = async (config, params) => {
1544
1548
  const { algodClient, indexerClient, signer, activeAddress, matcherAppId, usdcAssetId } = config;
@@ -1670,7 +1674,8 @@ var cancelOrder = async (config, params) => {
1670
1674
  const result = await atc.execute(algodClient, 4);
1671
1675
  return {
1672
1676
  success: true,
1673
- txIds: result.txIDs
1677
+ txIds: result.txIDs,
1678
+ confirmedRound: result.confirmedRound
1674
1679
  };
1675
1680
  };
1676
1681
  var proposeMatch = async (config, params) => {
@@ -1716,7 +1721,8 @@ var proposeMatch = async (config, params) => {
1716
1721
  const result = await atc.execute(algodClient, 4);
1717
1722
  return {
1718
1723
  success: true,
1719
- txIds: result.txIDs
1724
+ txIds: result.txIDs,
1725
+ confirmedRound: result.confirmedRound
1720
1726
  };
1721
1727
  };
1722
1728
  var splitShares = async (config, params) => {
@@ -1870,7 +1876,8 @@ var claim = async (config, params) => {
1870
1876
  return {
1871
1877
  success: true,
1872
1878
  txIds: result.txIDs,
1873
- confirmedRound: result.confirmedRound
1879
+ confirmedRound: result.confirmedRound,
1880
+ amountClaimed: tokenBalance
1874
1881
  };
1875
1882
  };
1876
1883
  var getPositions = async (config, walletAddress) => {
@@ -1907,14 +1914,17 @@ var getPositions = async (config, walletAddress) => {
1907
1914
  if (!rawState) continue;
1908
1915
  let yesAssetIdOnChain = 0;
1909
1916
  let noAssetIdOnChain = 0;
1917
+ let marketTitle = "";
1910
1918
  for (const item of rawState) {
1911
1919
  const key = Buffer.from(item.key, "base64").toString();
1912
1920
  if (key === "yes_asset_id") yesAssetIdOnChain = Number(item.value.uint);
1913
1921
  if (key === "no_asset_id") noAssetIdOnChain = Number(item.value.uint);
1922
+ if (key === "title") marketTitle = Buffer.from(item.value.bytes, "base64").toString();
1914
1923
  }
1915
1924
  if (yesAssetIdOnChain === 0 && noAssetIdOnChain === 0) continue;
1916
1925
  positions.set(marketAppId, {
1917
1926
  marketAppId,
1927
+ title: marketTitle,
1918
1928
  yesAssetId: yesAssetIdOnChain,
1919
1929
  noAssetId: noAssetIdOnChain,
1920
1930
  yesBalance: side === "Yes" ? amount : 0,