@alpha-arcade/sdk 0.2.0 → 0.2.1
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 +33 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +33 -30
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1911,40 +1911,43 @@ var getPositions = async (config, walletAddress) => {
|
|
|
1911
1911
|
const amount = Number(asset.amount);
|
|
1912
1912
|
try {
|
|
1913
1913
|
const assetInfo = await indexerClient.lookupAssetByID(assetId).do();
|
|
1914
|
-
const
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
let noAssetIdOnChain = 0;
|
|
1925
|
-
for (const item of rawState) {
|
|
1926
|
-
const key = Buffer.from(item.key, "base64").toString();
|
|
1927
|
-
if (key === "yes_asset_id") yesAssetIdOnChain = Number(item.value.uint);
|
|
1928
|
-
if (key === "no_asset_id") noAssetIdOnChain = Number(item.value.uint);
|
|
1929
|
-
}
|
|
1930
|
-
if (yesAssetIdOnChain === 0 && noAssetIdOnChain === 0) continue;
|
|
1931
|
-
const existing = positions.get(appId) ?? {
|
|
1932
|
-
marketAppId: appId,
|
|
1933
|
-
yesAssetId: yesAssetIdOnChain,
|
|
1934
|
-
noAssetId: noAssetIdOnChain,
|
|
1935
|
-
yesBalance: 0,
|
|
1936
|
-
noBalance: 0
|
|
1937
|
-
};
|
|
1938
|
-
if (assetId === yesAssetIdOnChain) {
|
|
1914
|
+
const assetName = assetInfo.asset?.params?.name ?? "";
|
|
1915
|
+
const unitName = assetInfo.asset?.params?.["unit-name"] ?? "";
|
|
1916
|
+
if (!unitName.startsWith("ALPHA-")) continue;
|
|
1917
|
+
const match = assetName.match(/^Alpha Market (\d+) (Yes|No)$/);
|
|
1918
|
+
if (!match) continue;
|
|
1919
|
+
const marketAppId = Number(match[1]);
|
|
1920
|
+
const side = match[2];
|
|
1921
|
+
const existing = positions.get(marketAppId);
|
|
1922
|
+
if (existing) {
|
|
1923
|
+
if (side === "Yes") {
|
|
1939
1924
|
existing.yesBalance = amount;
|
|
1940
|
-
} else if (assetId === noAssetIdOnChain) {
|
|
1941
|
-
existing.noBalance = amount;
|
|
1942
1925
|
} else {
|
|
1926
|
+
existing.noBalance = amount;
|
|
1927
|
+
}
|
|
1928
|
+
} else {
|
|
1929
|
+
try {
|
|
1930
|
+
const appInfo = await indexerClient.lookupApplications(marketAppId).do();
|
|
1931
|
+
const rawState = appInfo.application?.params?.["global-state"];
|
|
1932
|
+
if (!rawState) continue;
|
|
1933
|
+
let yesAssetIdOnChain = 0;
|
|
1934
|
+
let noAssetIdOnChain = 0;
|
|
1935
|
+
for (const item of rawState) {
|
|
1936
|
+
const key = Buffer.from(item.key, "base64").toString();
|
|
1937
|
+
if (key === "yes_asset_id") yesAssetIdOnChain = Number(item.value.uint);
|
|
1938
|
+
if (key === "no_asset_id") noAssetIdOnChain = Number(item.value.uint);
|
|
1939
|
+
}
|
|
1940
|
+
if (yesAssetIdOnChain === 0 && noAssetIdOnChain === 0) continue;
|
|
1941
|
+
positions.set(marketAppId, {
|
|
1942
|
+
marketAppId,
|
|
1943
|
+
yesAssetId: yesAssetIdOnChain,
|
|
1944
|
+
noAssetId: noAssetIdOnChain,
|
|
1945
|
+
yesBalance: side === "Yes" ? amount : 0,
|
|
1946
|
+
noBalance: side === "No" ? amount : 0
|
|
1947
|
+
});
|
|
1948
|
+
} catch {
|
|
1943
1949
|
continue;
|
|
1944
1950
|
}
|
|
1945
|
-
positions.set(appId, existing);
|
|
1946
|
-
} catch {
|
|
1947
|
-
continue;
|
|
1948
1951
|
}
|
|
1949
1952
|
} catch {
|
|
1950
1953
|
continue;
|