@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.cjs
CHANGED
|
@@ -1419,7 +1419,8 @@ var calculateMatchingOrders = (orderbook, isBuying, isYes, quantity, price, slip
|
|
|
1419
1419
|
matches.push({
|
|
1420
1420
|
escrowAppId: counterParty.escrowAppId,
|
|
1421
1421
|
quantity: amountToTake,
|
|
1422
|
-
owner: counterParty.owner
|
|
1422
|
+
owner: counterParty.owner,
|
|
1423
|
+
price: counterParty.price
|
|
1423
1424
|
});
|
|
1424
1425
|
volumeLeft -= amountToTake;
|
|
1425
1426
|
}
|
|
@@ -1559,11 +1560,14 @@ var createMarketOrder = async (config, params) => {
|
|
|
1559
1560
|
);
|
|
1560
1561
|
}
|
|
1561
1562
|
const totalMatchedQuantity = matchingOrders.reduce((sum, o) => sum + o.quantity, 0);
|
|
1563
|
+
const matchedPrice = totalMatchedQuantity > 0 ? Math.round(
|
|
1564
|
+
matchingOrders.reduce((sum, o) => sum + (o.price ?? params.price) * o.quantity, 0) / totalMatchedQuantity
|
|
1565
|
+
) : params.price;
|
|
1562
1566
|
const result = await createOrder(config, {
|
|
1563
1567
|
...params,
|
|
1564
1568
|
matchingOrders
|
|
1565
1569
|
});
|
|
1566
|
-
return { ...result, matchedQuantity: totalMatchedQuantity };
|
|
1570
|
+
return { ...result, matchedQuantity: totalMatchedQuantity, matchedPrice };
|
|
1567
1571
|
};
|
|
1568
1572
|
var createOrder = async (config, params) => {
|
|
1569
1573
|
const { algodClient, indexerClient, signer, activeAddress, matcherAppId, usdcAssetId } = config;
|
|
@@ -1695,7 +1699,8 @@ var cancelOrder = async (config, params) => {
|
|
|
1695
1699
|
const result = await atc.execute(algodClient, 4);
|
|
1696
1700
|
return {
|
|
1697
1701
|
success: true,
|
|
1698
|
-
txIds: result.txIDs
|
|
1702
|
+
txIds: result.txIDs,
|
|
1703
|
+
confirmedRound: result.confirmedRound
|
|
1699
1704
|
};
|
|
1700
1705
|
};
|
|
1701
1706
|
var proposeMatch = async (config, params) => {
|
|
@@ -1741,7 +1746,8 @@ var proposeMatch = async (config, params) => {
|
|
|
1741
1746
|
const result = await atc.execute(algodClient, 4);
|
|
1742
1747
|
return {
|
|
1743
1748
|
success: true,
|
|
1744
|
-
txIds: result.txIDs
|
|
1749
|
+
txIds: result.txIDs,
|
|
1750
|
+
confirmedRound: result.confirmedRound
|
|
1745
1751
|
};
|
|
1746
1752
|
};
|
|
1747
1753
|
var splitShares = async (config, params) => {
|
|
@@ -1895,7 +1901,8 @@ var claim = async (config, params) => {
|
|
|
1895
1901
|
return {
|
|
1896
1902
|
success: true,
|
|
1897
1903
|
txIds: result.txIDs,
|
|
1898
|
-
confirmedRound: result.confirmedRound
|
|
1904
|
+
confirmedRound: result.confirmedRound,
|
|
1905
|
+
amountClaimed: tokenBalance
|
|
1899
1906
|
};
|
|
1900
1907
|
};
|
|
1901
1908
|
var getPositions = async (config, walletAddress) => {
|
|
@@ -1932,14 +1939,17 @@ var getPositions = async (config, walletAddress) => {
|
|
|
1932
1939
|
if (!rawState) continue;
|
|
1933
1940
|
let yesAssetIdOnChain = 0;
|
|
1934
1941
|
let noAssetIdOnChain = 0;
|
|
1942
|
+
let marketTitle = "";
|
|
1935
1943
|
for (const item of rawState) {
|
|
1936
1944
|
const key = Buffer.from(item.key, "base64").toString();
|
|
1937
1945
|
if (key === "yes_asset_id") yesAssetIdOnChain = Number(item.value.uint);
|
|
1938
1946
|
if (key === "no_asset_id") noAssetIdOnChain = Number(item.value.uint);
|
|
1947
|
+
if (key === "title") marketTitle = Buffer.from(item.value.bytes, "base64").toString();
|
|
1939
1948
|
}
|
|
1940
1949
|
if (yesAssetIdOnChain === 0 && noAssetIdOnChain === 0) continue;
|
|
1941
1950
|
positions.set(marketAppId, {
|
|
1942
1951
|
marketAppId,
|
|
1952
|
+
title: marketTitle,
|
|
1943
1953
|
yesAssetId: yesAssetIdOnChain,
|
|
1944
1954
|
noAssetId: noAssetIdOnChain,
|
|
1945
1955
|
yesBalance: side === "Yes" ? amount : 0,
|
|
@@ -1959,6 +1969,7 @@ var getPositions = async (config, walletAddress) => {
|
|
|
1959
1969
|
// src/modules/markets.ts
|
|
1960
1970
|
var DEFAULT_API_BASE_URL = "https://partners.alphaarcade.com/api";
|
|
1961
1971
|
var DEFAULT_MARKET_CREATOR_ADDRESS = "5P5Y6HTWUNG2E3VXBQDZN3ENZD3JPAIR5PKT3LOYJAPAUKOLFD6KANYTRY";
|
|
1972
|
+
var toSeconds = (ts) => ts > 1e10 ? Math.floor(ts / 1e3) : ts;
|
|
1962
1973
|
var groupMultiChoiceMarkets = (flatMarkets) => {
|
|
1963
1974
|
const parentMap = /* @__PURE__ */ new Map();
|
|
1964
1975
|
const result = [];
|
|
@@ -2088,11 +2099,16 @@ var getMarketsFromApi = async (config) => {
|
|
|
2088
2099
|
throw new Error(`Alpha API error: ${response.status} ${response.statusText}`);
|
|
2089
2100
|
}
|
|
2090
2101
|
const data = await response.json();
|
|
2102
|
+
const normalizeApiMarket = (m) => ({
|
|
2103
|
+
...m,
|
|
2104
|
+
endTs: m.endTs ? toSeconds(m.endTs) : 0,
|
|
2105
|
+
source: "api"
|
|
2106
|
+
});
|
|
2091
2107
|
if (Array.isArray(data)) {
|
|
2092
|
-
allMarkets.push(...data.map(
|
|
2108
|
+
allMarkets.push(...data.map(normalizeApiMarket));
|
|
2093
2109
|
hasMore = false;
|
|
2094
2110
|
} else if (data.markets) {
|
|
2095
|
-
allMarkets.push(...data.markets.map(
|
|
2111
|
+
allMarkets.push(...data.markets.map(normalizeApiMarket));
|
|
2096
2112
|
lastEvaluatedKey = data.lastEvaluatedKey;
|
|
2097
2113
|
hasMore = !!lastEvaluatedKey;
|
|
2098
2114
|
} else {
|
|
@@ -2114,7 +2130,10 @@ var getMarketFromApi = async (config, marketId) => {
|
|
|
2114
2130
|
}
|
|
2115
2131
|
const data = await response.json();
|
|
2116
2132
|
const market = data.market ?? data ?? null;
|
|
2117
|
-
if (market)
|
|
2133
|
+
if (market) {
|
|
2134
|
+
market.source = "api";
|
|
2135
|
+
if (market.endTs) market.endTs = toSeconds(market.endTs);
|
|
2136
|
+
}
|
|
2118
2137
|
return market;
|
|
2119
2138
|
};
|
|
2120
2139
|
var getMarkets = async (config) => {
|