@alpha-arcade/sdk 0.2.2 → 0.2.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/index.cjs +27 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +27 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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,
|
|
@@ -1934,6 +1944,7 @@ var getPositions = async (config, walletAddress) => {
|
|
|
1934
1944
|
// src/modules/markets.ts
|
|
1935
1945
|
var DEFAULT_API_BASE_URL = "https://partners.alphaarcade.com/api";
|
|
1936
1946
|
var DEFAULT_MARKET_CREATOR_ADDRESS = "5P5Y6HTWUNG2E3VXBQDZN3ENZD3JPAIR5PKT3LOYJAPAUKOLFD6KANYTRY";
|
|
1947
|
+
var toSeconds = (ts) => ts > 1e10 ? Math.floor(ts / 1e3) : ts;
|
|
1937
1948
|
var groupMultiChoiceMarkets = (flatMarkets) => {
|
|
1938
1949
|
const parentMap = /* @__PURE__ */ new Map();
|
|
1939
1950
|
const result = [];
|
|
@@ -2063,11 +2074,16 @@ var getMarketsFromApi = async (config) => {
|
|
|
2063
2074
|
throw new Error(`Alpha API error: ${response.status} ${response.statusText}`);
|
|
2064
2075
|
}
|
|
2065
2076
|
const data = await response.json();
|
|
2077
|
+
const normalizeApiMarket = (m) => ({
|
|
2078
|
+
...m,
|
|
2079
|
+
endTs: m.endTs ? toSeconds(m.endTs) : 0,
|
|
2080
|
+
source: "api"
|
|
2081
|
+
});
|
|
2066
2082
|
if (Array.isArray(data)) {
|
|
2067
|
-
allMarkets.push(...data.map(
|
|
2083
|
+
allMarkets.push(...data.map(normalizeApiMarket));
|
|
2068
2084
|
hasMore = false;
|
|
2069
2085
|
} else if (data.markets) {
|
|
2070
|
-
allMarkets.push(...data.markets.map(
|
|
2086
|
+
allMarkets.push(...data.markets.map(normalizeApiMarket));
|
|
2071
2087
|
lastEvaluatedKey = data.lastEvaluatedKey;
|
|
2072
2088
|
hasMore = !!lastEvaluatedKey;
|
|
2073
2089
|
} else {
|
|
@@ -2089,7 +2105,10 @@ var getMarketFromApi = async (config, marketId) => {
|
|
|
2089
2105
|
}
|
|
2090
2106
|
const data = await response.json();
|
|
2091
2107
|
const market = data.market ?? data ?? null;
|
|
2092
|
-
if (market)
|
|
2108
|
+
if (market) {
|
|
2109
|
+
market.source = "api";
|
|
2110
|
+
if (market.endTs) market.endTs = toSeconds(market.endTs);
|
|
2111
|
+
}
|
|
2093
2112
|
return market;
|
|
2094
2113
|
};
|
|
2095
2114
|
var getMarkets = async (config) => {
|