@alpha-arcade/sdk 0.2.11 → 0.3.0
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/README.md +2 -2
- package/dist/index.cjs +78 -54
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +78 -51
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -49,7 +49,7 @@ const client = new AlphaClient({
|
|
|
49
49
|
algodClient,
|
|
50
50
|
indexerClient,
|
|
51
51
|
signer,
|
|
52
|
-
activeAddress: account.addr,
|
|
52
|
+
activeAddress: account.addr.toString(),
|
|
53
53
|
matcherAppId: 3078581851,
|
|
54
54
|
usdcAssetId: 31566704,
|
|
55
55
|
});
|
|
@@ -380,7 +380,7 @@ const setup = () => {
|
|
|
380
380
|
algodClient,
|
|
381
381
|
indexerClient,
|
|
382
382
|
signer: algosdk.makeBasicAccountTransactionSigner(account),
|
|
383
|
-
activeAddress: account.addr,
|
|
383
|
+
activeAddress: account.addr.toString(),
|
|
384
384
|
matcherAppId: 3078581851,
|
|
385
385
|
usdcAssetId: 31566704,
|
|
386
386
|
});
|
package/dist/index.cjs
CHANGED
|
@@ -4,8 +4,6 @@ var algosdk2 = require('algosdk');
|
|
|
4
4
|
var algokit4 = require('@algorandfoundation/algokit-utils');
|
|
5
5
|
var decimal_js = require('decimal.js');
|
|
6
6
|
|
|
7
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
-
|
|
9
7
|
function _interopNamespace(e) {
|
|
10
8
|
if (e && e.__esModule) return e;
|
|
11
9
|
var n = Object.create(null);
|
|
@@ -24,7 +22,7 @@ function _interopNamespace(e) {
|
|
|
24
22
|
return Object.freeze(n);
|
|
25
23
|
}
|
|
26
24
|
|
|
27
|
-
var
|
|
25
|
+
var algosdk2__namespace = /*#__PURE__*/_interopNamespace(algosdk2);
|
|
28
26
|
var algokit4__namespace = /*#__PURE__*/_interopNamespace(algokit4);
|
|
29
27
|
|
|
30
28
|
// src/modules/trading.ts
|
|
@@ -1998,47 +1996,58 @@ var calculateFeeFromTotal = (totalAmount, price, feeBase) => {
|
|
|
1998
1996
|
var decodeGlobalState = (rawState) => {
|
|
1999
1997
|
const state = {};
|
|
2000
1998
|
for (const item of rawState) {
|
|
2001
|
-
const
|
|
2002
|
-
|
|
1999
|
+
const rawKey = item.key;
|
|
2000
|
+
const key = typeof rawKey === "string" ? Buffer.from(rawKey, "base64").toString() : rawKey instanceof Uint8Array ? Buffer.from(rawKey).toString() : String(rawKey);
|
|
2001
|
+
const val = item.value;
|
|
2002
|
+
const type = val.type;
|
|
2003
|
+
if (type === 1) {
|
|
2003
2004
|
if (key === "owner" || key === "oracle_address" || key === "fee_address" || key === "market_friend_addr" || key === "escrow_cancel_address") {
|
|
2004
2005
|
try {
|
|
2005
|
-
const
|
|
2006
|
+
const rawBytes = val.bytes;
|
|
2007
|
+
const addressBytes = typeof rawBytes === "string" ? Buffer.from(rawBytes, "base64") : rawBytes instanceof Uint8Array ? rawBytes : Buffer.from(String(rawBytes), "base64");
|
|
2006
2008
|
if (addressBytes.length === 32) {
|
|
2007
|
-
state[key] =
|
|
2009
|
+
state[key] = algosdk2__namespace.encodeAddress(new Uint8Array(addressBytes));
|
|
2008
2010
|
} else {
|
|
2009
|
-
state[key] =
|
|
2011
|
+
state[key] = val.bytes;
|
|
2010
2012
|
}
|
|
2011
2013
|
} catch {
|
|
2012
|
-
state[key] =
|
|
2014
|
+
state[key] = val.bytes;
|
|
2013
2015
|
}
|
|
2014
2016
|
} else {
|
|
2015
2017
|
try {
|
|
2016
|
-
|
|
2018
|
+
const rawBytes = val.bytes;
|
|
2019
|
+
if (typeof rawBytes === "string") {
|
|
2020
|
+
state[key] = Buffer.from(rawBytes, "base64").toString();
|
|
2021
|
+
} else if (rawBytes instanceof Uint8Array) {
|
|
2022
|
+
state[key] = Buffer.from(rawBytes).toString();
|
|
2023
|
+
} else {
|
|
2024
|
+
state[key] = rawBytes;
|
|
2025
|
+
}
|
|
2017
2026
|
} catch {
|
|
2018
|
-
state[key] =
|
|
2027
|
+
state[key] = val.bytes;
|
|
2019
2028
|
}
|
|
2020
2029
|
}
|
|
2021
2030
|
} else {
|
|
2022
|
-
state[key] = Number(
|
|
2031
|
+
state[key] = Number(val.uint);
|
|
2023
2032
|
}
|
|
2024
2033
|
}
|
|
2025
2034
|
return state;
|
|
2026
2035
|
};
|
|
2027
2036
|
var getMarketGlobalState = async (algodClient, marketAppId) => {
|
|
2028
2037
|
const appInfo = await algodClient.getApplicationByID(marketAppId).do();
|
|
2029
|
-
const rawState = appInfo.params?.
|
|
2038
|
+
const rawState = appInfo.params?.globalState ?? appInfo.params?.["global-state"] ?? [];
|
|
2030
2039
|
return decodeGlobalState(rawState);
|
|
2031
2040
|
};
|
|
2032
2041
|
var getEscrowGlobalState = async (indexerClient, escrowAppId) => {
|
|
2033
2042
|
const appInfo = await indexerClient.lookupApplications(escrowAppId).do();
|
|
2034
|
-
const rawState = appInfo.application?.params?.["global-state"] ?? [];
|
|
2043
|
+
const rawState = appInfo.application?.params?.globalState ?? appInfo.application?.params?.["global-state"] ?? [];
|
|
2035
2044
|
return decodeGlobalState(rawState);
|
|
2036
2045
|
};
|
|
2037
2046
|
var checkAssetOptIn = async (algodClient, address, assetId) => {
|
|
2038
2047
|
try {
|
|
2039
2048
|
const accountInfo = await algodClient.accountInformation(address).do();
|
|
2040
|
-
const assets = accountInfo.assets ||
|
|
2041
|
-
return assets.some((a) => (a["asset-id"]
|
|
2049
|
+
const assets = accountInfo.assets || [];
|
|
2050
|
+
return assets.some((a) => Number(a.assetId ?? a["asset-id"]) === assetId);
|
|
2042
2051
|
} catch {
|
|
2043
2052
|
return false;
|
|
2044
2053
|
}
|
|
@@ -2132,8 +2141,9 @@ var getAllCreatedApplications = async (indexerClient, address, limit = 100) => {
|
|
|
2132
2141
|
if (response.applications?.length) {
|
|
2133
2142
|
applications = [...applications, ...response.applications];
|
|
2134
2143
|
}
|
|
2135
|
-
|
|
2136
|
-
|
|
2144
|
+
const token = response.nextToken ?? response["next-token"];
|
|
2145
|
+
if (token) {
|
|
2146
|
+
nextToken = token;
|
|
2137
2147
|
} else {
|
|
2138
2148
|
hasMore = false;
|
|
2139
2149
|
}
|
|
@@ -2147,7 +2157,7 @@ var fetchApplicationsGlobalState = async (indexerClient, applications) => {
|
|
|
2147
2157
|
try {
|
|
2148
2158
|
const appInfo = await indexerClient.lookupApplications(appId).do();
|
|
2149
2159
|
const globalState = {};
|
|
2150
|
-
const rawGlobalState = appInfo.application?.params?.["global-state"];
|
|
2160
|
+
const rawGlobalState = appInfo.application?.params?.globalState ?? appInfo.application?.params?.["global-state"];
|
|
2151
2161
|
if (rawGlobalState) {
|
|
2152
2162
|
const decoded = decodeGlobalState(rawGlobalState);
|
|
2153
2163
|
Object.assign(globalState, decoded);
|
|
@@ -2166,7 +2176,7 @@ var transformOrders = (orders) => orders.filter((o) => o.appId > 0).map((o) => (
|
|
|
2166
2176
|
owner: o.globalState.owner ?? ""
|
|
2167
2177
|
}));
|
|
2168
2178
|
var getOrderbook = async (config, marketAppId) => {
|
|
2169
|
-
const appAddress =
|
|
2179
|
+
const appAddress = algosdk2__namespace.getApplicationAddress(marketAppId).toString();
|
|
2170
2180
|
const applications = await getAllCreatedApplications(config.indexerClient, appAddress);
|
|
2171
2181
|
const appsWithState = await fetchApplicationsGlobalState(config.indexerClient, applications);
|
|
2172
2182
|
const isOpenLimitOrder = (o) => (o.globalState.quantity ?? 0) > (o.globalState.quantity_filled ?? 0) && o.globalState.slippage === 0;
|
|
@@ -2195,7 +2205,7 @@ var getOrderbook = async (config, marketAppId) => {
|
|
|
2195
2205
|
};
|
|
2196
2206
|
var getOpenOrders = async (config, marketAppId, walletAddress) => {
|
|
2197
2207
|
const owner = walletAddress ?? config.activeAddress;
|
|
2198
|
-
const appAddress =
|
|
2208
|
+
const appAddress = algosdk2__namespace.getApplicationAddress(marketAppId).toString();
|
|
2199
2209
|
const applications = await getAllCreatedApplications(config.indexerClient, appAddress);
|
|
2200
2210
|
const appsWithState = await fetchApplicationsGlobalState(config.indexerClient, applications);
|
|
2201
2211
|
return appsWithState.filter(
|
|
@@ -2260,8 +2270,10 @@ var getWalletOrdersFromApi = async (config, walletAddress) => {
|
|
|
2260
2270
|
var extractEscrowAppId = async (algodClient, indexerClient, targetTxId) => {
|
|
2261
2271
|
try {
|
|
2262
2272
|
const pendingInfo = await algodClient.pendingTransactionInformation(targetTxId).do();
|
|
2263
|
-
|
|
2264
|
-
|
|
2273
|
+
const innerTxns = pendingInfo.innerTxns ?? pendingInfo["inner-txns"];
|
|
2274
|
+
const createdAppId = innerTxns?.[0]?.applicationIndex ?? innerTxns?.[0]?.["created-application-index"];
|
|
2275
|
+
if (createdAppId) {
|
|
2276
|
+
return Number(createdAppId);
|
|
2265
2277
|
}
|
|
2266
2278
|
} catch {
|
|
2267
2279
|
}
|
|
@@ -2270,8 +2282,11 @@ var extractEscrowAppId = async (algodClient, indexerClient, targetTxId) => {
|
|
|
2270
2282
|
try {
|
|
2271
2283
|
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
2272
2284
|
const txnLookup = await indexerClient.lookupTransactionByID(targetTxId).do();
|
|
2273
|
-
|
|
2274
|
-
|
|
2285
|
+
const txn = txnLookup.transaction;
|
|
2286
|
+
const innerTxns = txn?.innerTxns ?? txn?.["inner-txns"];
|
|
2287
|
+
const createdAppId = innerTxns?.[0]?.createdApplicationIndex ?? innerTxns?.[0]?.["created-application-index"];
|
|
2288
|
+
if (createdAppId) {
|
|
2289
|
+
return Number(createdAppId);
|
|
2275
2290
|
}
|
|
2276
2291
|
} catch {
|
|
2277
2292
|
}
|
|
@@ -2339,7 +2354,7 @@ var createOrder = async (config, params) => {
|
|
|
2339
2354
|
if (isBuying) {
|
|
2340
2355
|
fee = calculateFee(quantity, price + slippage, feeBase);
|
|
2341
2356
|
}
|
|
2342
|
-
const marketAddress = algosdk2.getApplicationAddress(marketAppId);
|
|
2357
|
+
const marketAddress = algosdk2.getApplicationAddress(marketAppId).toString();
|
|
2343
2358
|
const atc = new algosdk2.AtomicTransactionComposer();
|
|
2344
2359
|
let createEscrowTxnIndex = 0;
|
|
2345
2360
|
if (!isBuying) {
|
|
@@ -2388,7 +2403,7 @@ var createOrder = async (config, params) => {
|
|
|
2388
2403
|
const payCounterPartyTxn = await algokit4__namespace.transferAlgos(
|
|
2389
2404
|
{
|
|
2390
2405
|
from: signerAccount,
|
|
2391
|
-
to: algosdk2.getApplicationAddress(matchingOrder.escrowAppId),
|
|
2406
|
+
to: algosdk2.getApplicationAddress(matchingOrder.escrowAppId).toString(),
|
|
2392
2407
|
amount: algokit4__namespace.microAlgos(1e3 * (isBuying ? 1 : 2)),
|
|
2393
2408
|
skipSending: true
|
|
2394
2409
|
},
|
|
@@ -2420,7 +2435,7 @@ var createOrder = async (config, params) => {
|
|
|
2420
2435
|
return {
|
|
2421
2436
|
escrowAppId,
|
|
2422
2437
|
txIds: result.txIDs,
|
|
2423
|
-
confirmedRound: result.confirmedRound
|
|
2438
|
+
confirmedRound: Number(result.confirmedRound)
|
|
2424
2439
|
};
|
|
2425
2440
|
};
|
|
2426
2441
|
var cancelOrder = async (config, params) => {
|
|
@@ -2449,7 +2464,7 @@ var cancelOrder = async (config, params) => {
|
|
|
2449
2464
|
return {
|
|
2450
2465
|
success: true,
|
|
2451
2466
|
txIds: result.txIDs,
|
|
2452
|
-
confirmedRound: result.confirmedRound
|
|
2467
|
+
confirmedRound: Number(result.confirmedRound)
|
|
2453
2468
|
};
|
|
2454
2469
|
};
|
|
2455
2470
|
var proposeMatch = async (config, params) => {
|
|
@@ -2468,7 +2483,7 @@ var proposeMatch = async (config, params) => {
|
|
|
2468
2483
|
const payMakerTxn = await algokit4__namespace.transferAlgos(
|
|
2469
2484
|
{
|
|
2470
2485
|
from: signerAccount,
|
|
2471
|
-
to: algosdk2.getApplicationAddress(makerEscrowAppId),
|
|
2486
|
+
to: algosdk2.getApplicationAddress(makerEscrowAppId).toString(),
|
|
2472
2487
|
amount: algokit4__namespace.microAlgos(2e3),
|
|
2473
2488
|
skipSending: true
|
|
2474
2489
|
},
|
|
@@ -2496,7 +2511,7 @@ var proposeMatch = async (config, params) => {
|
|
|
2496
2511
|
return {
|
|
2497
2512
|
success: true,
|
|
2498
2513
|
txIds: result.txIDs,
|
|
2499
|
-
confirmedRound: result.confirmedRound
|
|
2514
|
+
confirmedRound: Number(result.confirmedRound)
|
|
2500
2515
|
};
|
|
2501
2516
|
};
|
|
2502
2517
|
var amendOrder = async (config, params) => {
|
|
@@ -2504,7 +2519,7 @@ var amendOrder = async (config, params) => {
|
|
|
2504
2519
|
const { marketAppId, escrowAppId, price, quantity, slippage = 0 } = params;
|
|
2505
2520
|
const escrowAppInfo = await algodClient.getApplicationByID(escrowAppId).do();
|
|
2506
2521
|
const escrowState = decodeGlobalState(
|
|
2507
|
-
escrowAppInfo.params?.
|
|
2522
|
+
escrowAppInfo.params?.globalState ?? escrowAppInfo.params?.["global-state"] ?? []
|
|
2508
2523
|
);
|
|
2509
2524
|
if ((escrowState.quantity_filled ?? 0) > 0) {
|
|
2510
2525
|
throw new Error("Cannot amend an order that has been partially or fully filled.");
|
|
@@ -2558,7 +2573,7 @@ var amendOrder = async (config, params) => {
|
|
|
2558
2573
|
return {
|
|
2559
2574
|
success: true,
|
|
2560
2575
|
txIds: result.txIDs,
|
|
2561
|
-
confirmedRound: result.confirmedRound
|
|
2576
|
+
confirmedRound: Number(result.confirmedRound)
|
|
2562
2577
|
};
|
|
2563
2578
|
};
|
|
2564
2579
|
var splitShares = async (config, params) => {
|
|
@@ -2572,7 +2587,7 @@ var splitShares = async (config, params) => {
|
|
|
2572
2587
|
{ resolveBy: "id", id: marketAppId, sender: signerAccount },
|
|
2573
2588
|
algodClient
|
|
2574
2589
|
);
|
|
2575
|
-
const marketAddress = algosdk2.getApplicationAddress(marketAppId);
|
|
2590
|
+
const marketAddress = algosdk2.getApplicationAddress(marketAppId).toString();
|
|
2576
2591
|
const atc = new algosdk2.AtomicTransactionComposer();
|
|
2577
2592
|
let optInCosts = 0;
|
|
2578
2593
|
const hasYesOptIn = await checkAssetOptIn(algodClient, activeAddress, yesAssetId);
|
|
@@ -2612,7 +2627,7 @@ var splitShares = async (config, params) => {
|
|
|
2612
2627
|
return {
|
|
2613
2628
|
success: true,
|
|
2614
2629
|
txIds: result.txIDs,
|
|
2615
|
-
confirmedRound: result.confirmedRound
|
|
2630
|
+
confirmedRound: Number(result.confirmedRound)
|
|
2616
2631
|
};
|
|
2617
2632
|
};
|
|
2618
2633
|
var mergeShares = async (config, params) => {
|
|
@@ -2626,7 +2641,7 @@ var mergeShares = async (config, params) => {
|
|
|
2626
2641
|
{ resolveBy: "id", id: marketAppId, sender: signerAccount },
|
|
2627
2642
|
algodClient
|
|
2628
2643
|
);
|
|
2629
|
-
const marketAddress = algosdk2.getApplicationAddress(marketAppId);
|
|
2644
|
+
const marketAddress = algosdk2.getApplicationAddress(marketAppId).toString();
|
|
2630
2645
|
const atc = new algosdk2.AtomicTransactionComposer();
|
|
2631
2646
|
let optInCosts = 0;
|
|
2632
2647
|
const hasUsdcOptIn = await checkAssetOptIn(algodClient, activeAddress, usdcAssetId);
|
|
@@ -2662,7 +2677,7 @@ var mergeShares = async (config, params) => {
|
|
|
2662
2677
|
return {
|
|
2663
2678
|
success: true,
|
|
2664
2679
|
txIds: result.txIDs,
|
|
2665
|
-
confirmedRound: result.confirmedRound
|
|
2680
|
+
confirmedRound: Number(result.confirmedRound)
|
|
2666
2681
|
};
|
|
2667
2682
|
};
|
|
2668
2683
|
var claim = async (config, params) => {
|
|
@@ -2673,12 +2688,12 @@ var claim = async (config, params) => {
|
|
|
2673
2688
|
{ resolveBy: "id", id: marketAppId, sender: signerAccount },
|
|
2674
2689
|
algodClient
|
|
2675
2690
|
);
|
|
2676
|
-
const marketAddress = algosdk2.getApplicationAddress(marketAppId);
|
|
2691
|
+
const marketAddress = algosdk2.getApplicationAddress(marketAppId).toString();
|
|
2677
2692
|
let tokenBalance = params.amount;
|
|
2678
2693
|
if (!tokenBalance) {
|
|
2679
2694
|
const accountInfo = await algodClient.accountInformation(activeAddress).do();
|
|
2680
|
-
const assets = accountInfo.assets ||
|
|
2681
|
-
const asset = assets.find((a) => (a["asset-id"]
|
|
2695
|
+
const assets = accountInfo.assets || [];
|
|
2696
|
+
const asset = assets.find((a) => Number(a.assetId ?? a["asset-id"]) === assetId);
|
|
2682
2697
|
tokenBalance = asset ? Number(asset.amount) : 0;
|
|
2683
2698
|
}
|
|
2684
2699
|
if (tokenBalance <= 0) {
|
|
@@ -2699,9 +2714,9 @@ var claim = async (config, params) => {
|
|
|
2699
2714
|
);
|
|
2700
2715
|
atc.addTransaction({ txn: claimTxn.transaction, signer });
|
|
2701
2716
|
const sp = await algodClient.getTransactionParams().do();
|
|
2702
|
-
const closeOutTxn =
|
|
2703
|
-
|
|
2704
|
-
|
|
2717
|
+
const closeOutTxn = algosdk2__namespace.makeAssetTransferTxnWithSuggestedParamsFromObject({
|
|
2718
|
+
sender: activeAddress,
|
|
2719
|
+
receiver: marketAddress,
|
|
2705
2720
|
amount: 0,
|
|
2706
2721
|
assetIndex: assetId,
|
|
2707
2722
|
closeRemainderTo: marketAddress,
|
|
@@ -2712,7 +2727,7 @@ var claim = async (config, params) => {
|
|
|
2712
2727
|
return {
|
|
2713
2728
|
success: true,
|
|
2714
2729
|
txIds: result.txIDs,
|
|
2715
|
-
confirmedRound: result.confirmedRound,
|
|
2730
|
+
confirmedRound: Number(result.confirmedRound),
|
|
2716
2731
|
amountClaimed: tokenBalance
|
|
2717
2732
|
};
|
|
2718
2733
|
};
|
|
@@ -2720,17 +2735,17 @@ var getPositions = async (config, walletAddress) => {
|
|
|
2720
2735
|
const { algodClient, indexerClient } = config;
|
|
2721
2736
|
const address = walletAddress ?? config.activeAddress;
|
|
2722
2737
|
const accountInfo = await algodClient.accountInformation(address).do();
|
|
2723
|
-
const assets = accountInfo.assets ||
|
|
2738
|
+
const assets = accountInfo.assets || [];
|
|
2724
2739
|
const nonZeroAssets = assets.filter((a) => Number(a.amount) > 0);
|
|
2725
2740
|
if (nonZeroAssets.length === 0) return [];
|
|
2726
2741
|
const positions = /* @__PURE__ */ new Map();
|
|
2727
2742
|
for (const asset of nonZeroAssets) {
|
|
2728
|
-
const assetId = asset["asset-id"]
|
|
2743
|
+
const assetId = Number(asset.assetId ?? asset["asset-id"]);
|
|
2729
2744
|
const amount = Number(asset.amount);
|
|
2730
2745
|
try {
|
|
2731
2746
|
const assetInfo = await indexerClient.lookupAssetByID(assetId).do();
|
|
2732
2747
|
const assetName = assetInfo.asset?.params?.name ?? "";
|
|
2733
|
-
const unitName = assetInfo.asset?.params?.["unit-name"] ?? "";
|
|
2748
|
+
const unitName = assetInfo.asset?.params?.unitName ?? assetInfo.asset?.params?.["unit-name"] ?? "";
|
|
2734
2749
|
if (!unitName.startsWith("ALPHA-")) continue;
|
|
2735
2750
|
const match = assetName.match(/^Alpha Market (\d+) (Yes|No)$/);
|
|
2736
2751
|
if (!match) continue;
|
|
@@ -2746,16 +2761,24 @@ var getPositions = async (config, walletAddress) => {
|
|
|
2746
2761
|
} else {
|
|
2747
2762
|
try {
|
|
2748
2763
|
const appInfo = await indexerClient.lookupApplications(marketAppId).do();
|
|
2749
|
-
const rawState = appInfo.application?.params?.["global-state"];
|
|
2764
|
+
const rawState = appInfo.application?.params?.globalState ?? appInfo.application?.params?.["global-state"];
|
|
2750
2765
|
if (!rawState) continue;
|
|
2751
2766
|
let yesAssetIdOnChain = 0;
|
|
2752
2767
|
let noAssetIdOnChain = 0;
|
|
2753
2768
|
let marketTitle = "";
|
|
2754
2769
|
for (const item of rawState) {
|
|
2755
|
-
const
|
|
2770
|
+
const rawKey = item.key;
|
|
2771
|
+
const key = typeof rawKey === "string" ? Buffer.from(rawKey, "base64").toString() : rawKey instanceof Uint8Array ? Buffer.from(rawKey).toString() : String(rawKey);
|
|
2756
2772
|
if (key === "yes_asset_id") yesAssetIdOnChain = Number(item.value.uint);
|
|
2757
2773
|
if (key === "no_asset_id") noAssetIdOnChain = Number(item.value.uint);
|
|
2758
|
-
if (key === "title")
|
|
2774
|
+
if (key === "title") {
|
|
2775
|
+
const rawBytes = item.value.bytes;
|
|
2776
|
+
if (typeof rawBytes === "string") {
|
|
2777
|
+
marketTitle = Buffer.from(rawBytes, "base64").toString();
|
|
2778
|
+
} else if (rawBytes instanceof Uint8Array) {
|
|
2779
|
+
marketTitle = Buffer.from(rawBytes).toString();
|
|
2780
|
+
}
|
|
2781
|
+
}
|
|
2759
2782
|
}
|
|
2760
2783
|
if (yesAssetIdOnChain === 0 && noAssetIdOnChain === 0) continue;
|
|
2761
2784
|
positions.set(marketAppId, {
|
|
@@ -2836,8 +2859,9 @@ var getMarketsOnChain = async (config, options) => {
|
|
|
2836
2859
|
if (response.applications?.length) {
|
|
2837
2860
|
allApps.push(...response.applications);
|
|
2838
2861
|
}
|
|
2839
|
-
|
|
2840
|
-
|
|
2862
|
+
const token = response.nextToken ?? response["next-token"];
|
|
2863
|
+
if (token) {
|
|
2864
|
+
nextToken = token;
|
|
2841
2865
|
} else {
|
|
2842
2866
|
hasMore = false;
|
|
2843
2867
|
}
|
|
@@ -2845,7 +2869,7 @@ var getMarketsOnChain = async (config, options) => {
|
|
|
2845
2869
|
const flatMarkets = [];
|
|
2846
2870
|
for (const app of allApps) {
|
|
2847
2871
|
if (app.deleted) continue;
|
|
2848
|
-
const rawState = app.params?.["global-state"];
|
|
2872
|
+
const rawState = app.params?.globalState ?? app.params?.["global-state"];
|
|
2849
2873
|
if (!rawState) continue;
|
|
2850
2874
|
const state = decodeGlobalState(rawState);
|
|
2851
2875
|
if (activeOnly && !state.is_activated) continue;
|
|
@@ -2871,7 +2895,7 @@ var getMarketOnChain = async (config, marketAppId) => {
|
|
|
2871
2895
|
try {
|
|
2872
2896
|
const appId = typeof marketAppId === "string" ? Number(marketAppId) : marketAppId;
|
|
2873
2897
|
const appInfo = await config.algodClient.getApplicationByID(appId).do();
|
|
2874
|
-
const rawState = appInfo.params?.
|
|
2898
|
+
const rawState = appInfo.params?.globalState ?? appInfo.params?.["global-state"] ?? [];
|
|
2875
2899
|
const state = decodeGlobalState(rawState);
|
|
2876
2900
|
return {
|
|
2877
2901
|
id: String(appId),
|