@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.js CHANGED
@@ -1886,40 +1886,43 @@ var getPositions = async (config, walletAddress) => {
1886
1886
  const amount = Number(asset.amount);
1887
1887
  try {
1888
1888
  const assetInfo = await indexerClient.lookupAssetByID(assetId).do();
1889
- const creator = assetInfo.asset?.params?.creator;
1890
- if (!creator) continue;
1891
- const createdApps = await indexerClient.lookupAccountCreatedApplications(creator).limit(1).do();
1892
- if (!createdApps.applications?.length) continue;
1893
- const appId = createdApps.applications[0].id;
1894
- try {
1895
- const appInfo = await indexerClient.lookupApplications(appId).do();
1896
- const rawState = appInfo.application?.params?.["global-state"];
1897
- if (!rawState) continue;
1898
- let yesAssetIdOnChain = 0;
1899
- let noAssetIdOnChain = 0;
1900
- for (const item of rawState) {
1901
- const key = Buffer.from(item.key, "base64").toString();
1902
- if (key === "yes_asset_id") yesAssetIdOnChain = Number(item.value.uint);
1903
- if (key === "no_asset_id") noAssetIdOnChain = Number(item.value.uint);
1904
- }
1905
- if (yesAssetIdOnChain === 0 && noAssetIdOnChain === 0) continue;
1906
- const existing = positions.get(appId) ?? {
1907
- marketAppId: appId,
1908
- yesAssetId: yesAssetIdOnChain,
1909
- noAssetId: noAssetIdOnChain,
1910
- yesBalance: 0,
1911
- noBalance: 0
1912
- };
1913
- if (assetId === yesAssetIdOnChain) {
1889
+ const assetName = assetInfo.asset?.params?.name ?? "";
1890
+ const unitName = assetInfo.asset?.params?.["unit-name"] ?? "";
1891
+ if (!unitName.startsWith("ALPHA-")) continue;
1892
+ const match = assetName.match(/^Alpha Market (\d+) (Yes|No)$/);
1893
+ if (!match) continue;
1894
+ const marketAppId = Number(match[1]);
1895
+ const side = match[2];
1896
+ const existing = positions.get(marketAppId);
1897
+ if (existing) {
1898
+ if (side === "Yes") {
1914
1899
  existing.yesBalance = amount;
1915
- } else if (assetId === noAssetIdOnChain) {
1916
- existing.noBalance = amount;
1917
1900
  } else {
1901
+ existing.noBalance = amount;
1902
+ }
1903
+ } else {
1904
+ try {
1905
+ const appInfo = await indexerClient.lookupApplications(marketAppId).do();
1906
+ const rawState = appInfo.application?.params?.["global-state"];
1907
+ if (!rawState) continue;
1908
+ let yesAssetIdOnChain = 0;
1909
+ let noAssetIdOnChain = 0;
1910
+ for (const item of rawState) {
1911
+ const key = Buffer.from(item.key, "base64").toString();
1912
+ if (key === "yes_asset_id") yesAssetIdOnChain = Number(item.value.uint);
1913
+ if (key === "no_asset_id") noAssetIdOnChain = Number(item.value.uint);
1914
+ }
1915
+ if (yesAssetIdOnChain === 0 && noAssetIdOnChain === 0) continue;
1916
+ positions.set(marketAppId, {
1917
+ marketAppId,
1918
+ yesAssetId: yesAssetIdOnChain,
1919
+ noAssetId: noAssetIdOnChain,
1920
+ yesBalance: side === "Yes" ? amount : 0,
1921
+ noBalance: side === "No" ? amount : 0
1922
+ });
1923
+ } catch {
1918
1924
  continue;
1919
1925
  }
1920
- positions.set(appId, existing);
1921
- } catch {
1922
- continue;
1923
1926
  }
1924
1927
  } catch {
1925
1928
  continue;