@ouronet/ouronet-core 4.3.6

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.
Files changed (101) hide show
  1. package/CHANGELOG.md +3043 -0
  2. package/README.md +1940 -0
  3. package/dist/codex/codec.d.ts +77 -0
  4. package/dist/codex/codec.js +123 -0
  5. package/dist/codex/errors.d.ts +14 -0
  6. package/dist/codex/errors.js +20 -0
  7. package/dist/codex/index.d.ts +27 -0
  8. package/dist/codex/index.js +25 -0
  9. package/dist/codex/seedTypeMigration.d.ts +35 -0
  10. package/dist/codex/seedTypeMigration.js +45 -0
  11. package/dist/codex/types.d.ts +100 -0
  12. package/dist/codex/types.js +19 -0
  13. package/dist/constants/index.d.ts +2 -0
  14. package/dist/constants/index.js +3 -0
  15. package/dist/constants/ouronet.d.ts +33 -0
  16. package/dist/constants/ouronet.js +59 -0
  17. package/dist/constants/tokenIds.d.ts +13 -0
  18. package/dist/constants/tokenIds.js +21 -0
  19. package/dist/index.d.ts +18 -0
  20. package/dist/index.js +1 -0
  21. package/dist/interactions/activateFunctions.d.ts +67 -0
  22. package/dist/interactions/activateFunctions.js +154 -0
  23. package/dist/interactions/addLiquidityFunctions.d.ts +140 -0
  24. package/dist/interactions/addLiquidityFunctions.js +485 -0
  25. package/dist/interactions/coilFunctions.d.ts +73 -0
  26. package/dist/interactions/coilFunctions.js +213 -0
  27. package/dist/interactions/crossChainFunctions.d.ts +211 -0
  28. package/dist/interactions/crossChainFunctions.js +463 -0
  29. package/dist/interactions/dexAcquisitionPoolFunctions.d.ts +18 -0
  30. package/dist/interactions/dexAcquisitionPoolFunctions.js +18 -0
  31. package/dist/interactions/dexCollectablesFunctions.d.ts +28 -0
  32. package/dist/interactions/dexCollectablesFunctions.js +227 -0
  33. package/dist/interactions/dexFunctions.d.ts +23 -0
  34. package/dist/interactions/dexFunctions.js +23 -0
  35. package/dist/interactions/dexOrtoFungibleFunctions.d.ts +33 -0
  36. package/dist/interactions/dexOrtoFungibleFunctions.js +171 -0
  37. package/dist/interactions/dexParseFunctions.d.ts +150 -0
  38. package/dist/interactions/dexParseFunctions.js +316 -0
  39. package/dist/interactions/dexSwapPairAdminFunctions.d.ts +75 -0
  40. package/dist/interactions/dexSwapPairAdminFunctions.js +255 -0
  41. package/dist/interactions/dexSwapPairCalcFunctions.d.ts +55 -0
  42. package/dist/interactions/dexSwapPairCalcFunctions.js +218 -0
  43. package/dist/interactions/dexSwapPairDashboardFunctions.d.ts +47 -0
  44. package/dist/interactions/dexSwapPairDashboardFunctions.js +179 -0
  45. package/dist/interactions/dexSwapPairExecuteFunctions.d.ts +40 -0
  46. package/dist/interactions/dexSwapPairExecuteFunctions.js +301 -0
  47. package/dist/interactions/dexSwapPairSmartSwapFunctions.d.ts +25 -0
  48. package/dist/interactions/dexSwapPairSmartSwapFunctions.js +166 -0
  49. package/dist/interactions/dexTrueFungibleFunctions.d.ts +52 -0
  50. package/dist/interactions/dexTrueFungibleFunctions.js +220 -0
  51. package/dist/interactions/dexTypes.d.ts +465 -0
  52. package/dist/interactions/dexTypes.js +6 -0
  53. package/dist/interactions/errors.d.ts +12 -0
  54. package/dist/interactions/errors.js +13 -0
  55. package/dist/interactions/guardFunctions.d.ts +33 -0
  56. package/dist/interactions/guardFunctions.js +110 -0
  57. package/dist/interactions/index.d.ts +1 -0
  58. package/dist/interactions/index.js +20 -0
  59. package/dist/interactions/infoOneFunctions.d.ts +133 -0
  60. package/dist/interactions/infoOneFunctions.js +566 -0
  61. package/dist/interactions/kadenaFunctions.d.ts +11 -0
  62. package/dist/interactions/kadenaFunctions.js +40 -0
  63. package/dist/interactions/kpayFunctions.d.ts +45 -0
  64. package/dist/interactions/kpayFunctions.js +191 -0
  65. package/dist/interactions/ouroAccountFunctions.d.ts +64 -0
  66. package/dist/interactions/ouroAccountFunctions.js +229 -0
  67. package/dist/interactions/ouroBalanceFunctions.d.ts +39 -0
  68. package/dist/interactions/ouroBalanceFunctions.js +100 -0
  69. package/dist/interactions/ouroCoilFunctions.d.ts +33 -0
  70. package/dist/interactions/ouroCoilFunctions.js +190 -0
  71. package/dist/interactions/ouroFunctions.d.ts +23 -0
  72. package/dist/interactions/ouroFunctions.js +23 -0
  73. package/dist/interactions/ouroMovieBoosterFunctions.d.ts +18 -0
  74. package/dist/interactions/ouroMovieBoosterFunctions.js +203 -0
  75. package/dist/interactions/ouroPriceFunctions.d.ts +38 -0
  76. package/dist/interactions/ouroPriceFunctions.js +96 -0
  77. package/dist/interactions/ouroPrimordialsFunctions.d.ts +10 -0
  78. package/dist/interactions/ouroPrimordialsFunctions.js +480 -0
  79. package/dist/interactions/ouroRotateFunctions.d.ts +22 -0
  80. package/dist/interactions/ouroRotateFunctions.js +114 -0
  81. package/dist/interactions/ouroSubCompressFunctions.d.ts +23 -0
  82. package/dist/interactions/ouroSubCompressFunctions.js +191 -0
  83. package/dist/interactions/ouroTransferFunctions.d.ts +14 -0
  84. package/dist/interactions/ouroTransferFunctions.js +87 -0
  85. package/dist/interactions/ouroTypes.d.ts +113 -0
  86. package/dist/interactions/ouroTypes.js +6 -0
  87. package/dist/interactions/ouroUrStoaFunctions.d.ts +16 -0
  88. package/dist/interactions/ouroUrStoaFunctions.js +121 -0
  89. package/dist/interactions/ouroWrapFunctions.d.ts +22 -0
  90. package/dist/interactions/ouroWrapFunctions.js +234 -0
  91. package/dist/interactions/pensionFunctions.d.ts +12 -0
  92. package/dist/interactions/pensionFunctions.js +127 -0
  93. package/dist/interactions/urStoaFunctions.d.ts +104 -0
  94. package/dist/interactions/urStoaFunctions.js +475 -0
  95. package/dist/interactions/wrapFunctions.d.ts +46 -0
  96. package/dist/interactions/wrapFunctions.js +221 -0
  97. package/dist/pact/cfmBuilders.d.ts +807 -0
  98. package/dist/pact/cfmBuilders.js +812 -0
  99. package/dist/pact/index.d.ts +1 -0
  100. package/dist/pact/index.js +10 -0
  101. package/package.json +64 -0
@@ -0,0 +1,566 @@
1
+ import { KADENA_NAMESPACE, } from "../constants/index.js";
2
+ import { formatDecimalForPact } from "@stoachain/stoa-core/pact";
3
+ import { pactRead } from "@stoachain/stoa-core/reads";
4
+ import { getLogger } from "@stoachain/stoa-core/observability";
5
+ export function parseTransferPreview(previewData) {
6
+ if (!previewData?.result)
7
+ return null;
8
+ const data = previewData.result;
9
+ return {
10
+ ignisNeed: String(data.ignis?.["ignis-need"] || "0"),
11
+ ignisText: data.ignis?.["ignis-text"] || "",
12
+ preText: data["pre-text"] || [],
13
+ postText: data["post-text"] || [],
14
+ kadenaFree: data.kadena?.["kadena-need"] === 0,
15
+ };
16
+ }
17
+ /**
18
+ * Get transfer preview information
19
+ * (INFO-ONE.DPTF|INFO_Transfer patron id sender receiver transfer-amount)
20
+ */
21
+ export async function getTransferPreview(patronAddress, tokenId, senderAddress, receiverAddress, amount) {
22
+ try {
23
+ const decimalAmount = formatDecimalForPact(amount);
24
+ const response = await pactRead(`(${KADENA_NAMESPACE}.INFO-ONE.DPTF|INFO_Transfer "${patronAddress}" "${tokenId}" "${senderAddress}" "${receiverAddress}" ${decimalAmount})`, { tier: "T2" });
25
+ if (!response || !response.result || response.result.status === "failure") {
26
+ return null;
27
+ }
28
+ return { result: response.result.data };
29
+ }
30
+ catch (error) {
31
+ getLogger().error("Error getting transfer preview:", error);
32
+ return null;
33
+ }
34
+ }
35
+ /**
36
+ * Get coil preview information from INFO-ONE
37
+ * (INFO-ONE.ATS|INFO_Coil patron coiler ats reward-token coil-amount)
38
+ */
39
+ export async function getCoilPreviewInfo(patronAddress, coilerAddress, atsId, rewardTokenId, amount) {
40
+ try {
41
+ const decimalAmount = formatDecimalForPact(amount);
42
+ const response = await pactRead(`(${KADENA_NAMESPACE}.INFO-ONE.ATS|INFO_Coil "${patronAddress}" "${coilerAddress}" "${atsId}" "${rewardTokenId}" ${decimalAmount})`, { tier: "T2" });
43
+ if (!response || !response.result || response.result.status === "failure") {
44
+ return null;
45
+ }
46
+ return { result: response.result.data };
47
+ }
48
+ catch (error) {
49
+ getLogger().error("Error getting coil preview:", error);
50
+ return null;
51
+ }
52
+ }
53
+ /**
54
+ * Get curl preview information from INFO-ONE
55
+ * (INFO-ONE.ATS|INFO_Curl patron curler ats1 ats2 reward-token curl-amount)
56
+ */
57
+ export async function getCurlPreviewInfo(patronAddress, curlerAddress, ats1Id, ats2Id, rewardTokenId, amount) {
58
+ try {
59
+ const decimalAmount = formatDecimalForPact(amount);
60
+ const response = await pactRead(`(${KADENA_NAMESPACE}.INFO-ONE.ATS|INFO_Curl "${patronAddress}" "${curlerAddress}" "${ats1Id}" "${ats2Id}" "${rewardTokenId}" ${decimalAmount})`, { tier: "T2" });
61
+ if (!response || !response.result || response.result.status === "failure") {
62
+ return null;
63
+ }
64
+ return { result: response.result.data };
65
+ }
66
+ catch (error) {
67
+ getLogger().error("Error getting curl preview:", error);
68
+ return null;
69
+ }
70
+ }
71
+ /**
72
+ * Get brumate preview information from INFO-ONE
73
+ * (INFO-ONE.ATS|INFO_Brumate patron brumator ats1 ats2 reward-token brumate-amount dayz)
74
+ */
75
+ export async function getBrumatePreviewInfo(patronAddress, brumatorAddress, ats1Id, ats2Id, rewardTokenId, amount, lockDays) {
76
+ try {
77
+ const decimalAmount = formatDecimalForPact(amount);
78
+ const response = await pactRead(`(${KADENA_NAMESPACE}.INFO-ONE.ATS|INFO_Brumate "${patronAddress}" "${brumatorAddress}" "${ats1Id}" "${ats2Id}" "${rewardTokenId}" ${decimalAmount} ${lockDays})`, { tier: "T2" });
79
+ if (!response || !response.result || response.result.status === "failure") {
80
+ return null;
81
+ }
82
+ return { result: response.result.data };
83
+ }
84
+ catch (error) {
85
+ getLogger().error("Error getting brumate preview:", error);
86
+ return null;
87
+ }
88
+ }
89
+ /**
90
+ * Get constrict preview information from INFO-ONE
91
+ * (INFO-ONE.ATS|INFO_Constrict patron constricter ats reward-token constrict-amount dayz)
92
+ */
93
+ export async function getConstrictPreviewInfo(patronAddress, constracterAddress, atsId, rewardTokenId, amount, lockDays) {
94
+ try {
95
+ const decimalAmount = formatDecimalForPact(amount);
96
+ const response = await pactRead(`(${KADENA_NAMESPACE}.INFO-ONE.ATS|INFO_Constrict "${patronAddress}" "${constracterAddress}" "${atsId}" "${rewardTokenId}" ${decimalAmount} ${lockDays})`, { tier: "T2" });
97
+ if (!response || !response.result || response.result.status === "failure") {
98
+ return null;
99
+ }
100
+ return { result: response.result.data };
101
+ }
102
+ catch (error) {
103
+ getLogger().error("Error getting constrict preview:", error);
104
+ return null;
105
+ }
106
+ }
107
+ /**
108
+ * Get Sublimate info from INFO-ONE
109
+ * (ouronet-ns.INFO-ONE.ORBR|INFO_Sublimate <client:string> <target:string> <ouro-amount:decimal>)
110
+ */
111
+ export async function getSublimateInfo(client, target, amount) {
112
+ try {
113
+ const decimalAmount = amount % 1 === 0 ? `${amount}.0` : String(amount);
114
+ const pactCode = `(${KADENA_NAMESPACE}.INFO-ONE.ORBR|INFO_Sublimate "${client}" "${target}" ${decimalAmount})`;
115
+ const response = await pactRead(pactCode, { tier: "T2" });
116
+ if (response?.result?.status === "success") {
117
+ return response.result.data;
118
+ }
119
+ return null;
120
+ }
121
+ catch (error) {
122
+ getLogger().error("Error getting sublimate info:", error);
123
+ return null;
124
+ }
125
+ }
126
+ /**
127
+ * Get Firestarter info from INFO-ONE
128
+ * (ouronet-ns.INFO-ONE.SWP|INFO_Firestarter <firestarter:string>)
129
+ */
130
+ export async function getFirestarterInfo(firestarter) {
131
+ try {
132
+ const pactCode = `(${KADENA_NAMESPACE}.INFO-ONE.SWP|INFO_Firestarter "${firestarter}")`;
133
+ const response = await pactRead(pactCode, { tier: "T2" });
134
+ if (response?.result?.status === "success") {
135
+ return response.result.data;
136
+ }
137
+ return null;
138
+ }
139
+ catch (error) {
140
+ getLogger().error("Error getting firestarter info:", error);
141
+ return null;
142
+ }
143
+ }
144
+ /**
145
+ * Get ChangeOwnership info from INFO-ONE
146
+ * (ouronet-ns.INFO-ONE.SWP|INFO_ChangeOwnership <patron> <swpair> <new-owner>)
147
+ */
148
+ export async function getChangeOwnershipInfo(patron, swpair, newOwner) {
149
+ try {
150
+ const pactCode = `(${KADENA_NAMESPACE}.INFO-ONE.SWP|INFO_ChangeOwnership "${patron}" "${swpair}" "${newOwner}")`;
151
+ const response = await pactRead(pactCode, { tier: "T2" });
152
+ if (response?.result?.status === "success") {
153
+ return response.result.data;
154
+ }
155
+ return null;
156
+ }
157
+ catch (error) {
158
+ getLogger().error("Error getting change-ownership info:", error);
159
+ return null;
160
+ }
161
+ }
162
+ /**
163
+ * Get ModifyWeights info from INFO-ONE
164
+ * (ouronet-ns.INFO-ONE.SWP|INFO_ModifyWeights <patron> <swpair> <new-weights:[decimal]>)
165
+ */
166
+ export async function getModifyWeightsInfo(patron, swpair, newWeights) {
167
+ try {
168
+ const weightList = `[${newWeights.map(w => {
169
+ const s = String(w);
170
+ return s.includes(".") ? s : `${s}.0`;
171
+ }).join(" ")}]`;
172
+ const pactCode = `(${KADENA_NAMESPACE}.INFO-ONE.SWP|INFO_ModifyWeights "${patron}" "${swpair}" ${weightList})`;
173
+ const response = await pactRead(pactCode, { tier: "T2" });
174
+ if (response?.result?.status === "success") {
175
+ return response.result.data;
176
+ }
177
+ return null;
178
+ }
179
+ catch (error) {
180
+ getLogger().error("Error getting modify-weights info:", error);
181
+ return null;
182
+ }
183
+ }
184
+ /**
185
+ * Get ToggleSwapCapability info from INFO-ONE
186
+ * (ouronet-ns.INFO-ONE.SWP|INFO_ToggleSwapCapability <patron> <swpair> <toggle:bool>)
187
+ */
188
+ export async function getToggleSwapCapabilityInfo(patron, swpair, toggle) {
189
+ try {
190
+ const pactCode = `(${KADENA_NAMESPACE}.INFO-ONE.SWP|INFO_ToggleSwapCapability "${patron}" "${swpair}" ${toggle})`;
191
+ const response = await pactRead(pactCode, { tier: "T2" });
192
+ if (response?.result?.status === "success") {
193
+ return response.result.data;
194
+ }
195
+ return null;
196
+ }
197
+ catch (error) {
198
+ getLogger().error("Error getting toggle-swap-capability info:", error);
199
+ return null;
200
+ }
201
+ }
202
+ /**
203
+ * Get ToggleAddLiquidity info from INFO-ONE
204
+ * (ouronet-ns.INFO-ONE.SWP|INFO_ToggleAddLiquidity <patron> <swpair> <toggle:bool>)
205
+ */
206
+ export async function getToggleAddLiquidityInfo(patron, swpair, toggle) {
207
+ try {
208
+ const pactCode = `(${KADENA_NAMESPACE}.INFO-ONE.SWP|INFO_ToggleAddLiquidity "${patron}" "${swpair}" ${toggle})`;
209
+ const response = await pactRead(pactCode, { tier: "T2" });
210
+ if (response?.result?.status === "success") {
211
+ return response.result.data;
212
+ }
213
+ return null;
214
+ }
215
+ catch (error) {
216
+ getLogger().error("Error getting toggle-add-liquidity info:", error);
217
+ return null;
218
+ }
219
+ }
220
+ /**
221
+ * Get ModifyCanChangeOwner info from INFO-ONE
222
+ * (ouronet-ns.INFO-ONE.SWP|INFO_ModifyCanChangeOwner <patron> <swpair> <new-boolean:bool>)
223
+ */
224
+ export async function getModifyCanChangeOwnerInfo(patron, swpair, newBoolean) {
225
+ try {
226
+ const pactCode = `(${KADENA_NAMESPACE}.INFO-ONE.SWP|INFO_ModifyCanChangeOwner "${patron}" "${swpair}" ${newBoolean})`;
227
+ const response = await pactRead(pactCode, { tier: "T2" });
228
+ if (response?.result?.status === "success") {
229
+ return response.result.data;
230
+ }
231
+ return null;
232
+ }
233
+ catch (error) {
234
+ getLogger().error("Error getting modify-can-change-owner info:", error);
235
+ return null;
236
+ }
237
+ }
238
+ /**
239
+ * Get DPTF Transfer info from INFO-ONE
240
+ * (ouronet-ns.INFO-ONE.DPTF|INFO_Transfer <patron> <token-id> <sender> <receiver> <amount>)
241
+ */
242
+ export async function getTransferInfo(patron, tokenId, sender, receiver, amount) {
243
+ try {
244
+ const decimalAmount = amount % 1 === 0 ? `${amount}.0` : String(amount);
245
+ const pactCode = `(${KADENA_NAMESPACE}.INFO-ONE.DPTF|INFO_Transfer "${patron}" "${tokenId}" "${sender}" "${receiver}" ${decimalAmount})`;
246
+ const response = await pactRead(pactCode, { tier: "T2" });
247
+ if (response?.result?.status === "success") {
248
+ return response.result.data;
249
+ }
250
+ return null;
251
+ }
252
+ catch (error) {
253
+ getLogger().error("Error getting transfer info:", error);
254
+ return null;
255
+ }
256
+ }
257
+ // ── Recovery Primordial read ─────────────────────────────────────────────────
258
+ // (ouronet-ns.DPL-UR.URC_0012_RecoveryPrimordial <ats:string> <resident:string>)
259
+ export async function getRecoveryPrimordial(atsId, residentAddress) {
260
+ try {
261
+ const response = await pactRead(`(${KADENA_NAMESPACE}.DPL-UR.URC_0012_RecoveryPrimordial "${atsId}" "${residentAddress}")`, { tier: "T2" });
262
+ if (!response || !response.result || response.result.status === "failure") {
263
+ return null;
264
+ }
265
+ return response.result.data ?? null;
266
+ }
267
+ catch (error) {
268
+ getLogger().error("Error getting recovery primordial:", error);
269
+ return null;
270
+ }
271
+ }
272
+ // ── Cold Recovery Info ────────────────────────────────────────────────────────
273
+ // (ouronet-ns.INFO-ONE.ATS|INFO_ColdRecovery <patron:string> <recoverer:string> <ats:string> <ra:decimal>)
274
+ export async function getColdRecoveryInfo(patronAddress, recovererAddress, atsId, ra) {
275
+ try {
276
+ const decimalRa = ra.includes(".") ? ra : ra + ".0";
277
+ const pactCode = `(${KADENA_NAMESPACE}.INFO-ONE.ATS|INFO_ColdRecovery "${patronAddress}" "${recovererAddress}" "${atsId}" ${decimalRa})`;
278
+ const response = await pactRead(pactCode, { tier: "T2" });
279
+ if (!response || !response.result || response.result.status === "failure")
280
+ return null;
281
+ return response.result.data ?? null;
282
+ }
283
+ catch (error) {
284
+ getLogger().error("Error getting cold recovery info:", error);
285
+ return null;
286
+ }
287
+ }
288
+ // ── Direct Recovery Info ───────────────────────────────────────────────────────
289
+ // (ouronet-ns.INFO-ONE.ATS|INFO_DirectRecovery <patron:string> <recoverer:string> <ats:string> <ra:decimal>)
290
+ export async function getDirectRecoveryInfo(patronAddress, recovererAddress, atsId, ra) {
291
+ try {
292
+ const decimalRa = ra.includes(".") ? ra : ra + ".0";
293
+ const pactCode = `(${KADENA_NAMESPACE}.INFO-ONE.ATS|INFO_DirectRecovery "${patronAddress}" "${recovererAddress}" "${atsId}" ${decimalRa})`;
294
+ const response = await pactRead(pactCode, { tier: "T2" });
295
+ if (!response || !response.result || response.result.status === "failure")
296
+ return null;
297
+ return response.result.data ?? null;
298
+ }
299
+ catch (error) {
300
+ getLogger().error("Error getting direct recovery info:", error);
301
+ return null;
302
+ }
303
+ }
304
+ // ── Elite Max Recovery Amount ──────────────────────────────────────────────────
305
+ // (ouronet-ns.DPL-UR.URC_MaxRecoveryAmount <ats:string> <recoverer:string>)
306
+ // Returns the max RBT amount a resident can uncoil while preserving their Elite tier.
307
+ export async function getMaxRecoveryAmount(atsId, residentAddress) {
308
+ try {
309
+ const pactCode = `(${KADENA_NAMESPACE}.DPL-UR.URC_MaxRecoveryAmount "${atsId}" "${residentAddress}")`;
310
+ const response = await pactRead(pactCode, { tier: "T2" });
311
+ if (!response || !response.result || response.result.status === "failure")
312
+ return null;
313
+ const raw = response.result.data;
314
+ if (raw === undefined || raw === null)
315
+ return null;
316
+ // Result may be decimal object {decimal:"..."} or plain number
317
+ if (typeof raw === "object" && raw.decimal !== undefined)
318
+ return String(raw.decimal);
319
+ return String(raw);
320
+ }
321
+ catch (error) {
322
+ getLogger().error("Error getting max recovery amount:", error);
323
+ return null;
324
+ }
325
+ }
326
+ // ── Cull Info ─────────────────────────────────────────────────────────────────
327
+ // (ouronet-ns.INFO-ONE.ATS|INFO_Cull <patron:string> <culler:string> <ats:string>)
328
+ export async function getCullInfo(patronAddress, cullerAddress, atsId) {
329
+ const r = await pactRead(`(${KADENA_NAMESPACE}.INFO-ONE.ATS|INFO_Cull "${patronAddress}" "${cullerAddress}" "${atsId}")`, { tier: "T2" });
330
+ if (!r?.result || r.result.status === "failure")
331
+ return null;
332
+ return r.result.data ?? null;
333
+ }
334
+ /** Normalize Pact primitive wrappers → plain JS values.
335
+ * Handles: {int: N} → number, {decimal: "..."} → number
336
+ * Time objects are handled separately by normalizePactTime. */
337
+ function normalizePactValue(v) {
338
+ if (v === null || v === undefined)
339
+ return v;
340
+ if (typeof v === "object" && !Array.isArray(v)) {
341
+ const o = v;
342
+ if ("int" in o)
343
+ return Number(o["int"]);
344
+ if ("decimal" in o)
345
+ return parseFloat(String(o["decimal"]));
346
+ }
347
+ return v;
348
+ }
349
+ /**
350
+ * Normalize a Pact time value to an ISO 8601 string that new Date() can parse.
351
+ * Pact returns time as: {time: "YYYY-MM-DDThh:mm:ss.000000Z"} or similar.
352
+ * We extract the inner string and ensure it's a valid ISO string.
353
+ */
354
+ function normalizePactTime(v) {
355
+ let raw = "";
356
+ if (typeof v === "string") {
357
+ raw = v;
358
+ }
359
+ else if (typeof v === "object" && v !== null && !Array.isArray(v)) {
360
+ const o = v;
361
+ // Pact wraps time as {timep: "..."} (Pact's actual key)
362
+ // Also handle {time: "..."} as fallback
363
+ if ("timep" in o)
364
+ raw = String(o["timep"]);
365
+ else if ("time" in o)
366
+ raw = String(o["time"]);
367
+ }
368
+ if (!raw)
369
+ return "";
370
+ // Ensure it ends with Z if no timezone info
371
+ if (!raw.endsWith("Z") && !raw.includes("+"))
372
+ raw = raw + "Z";
373
+ return raw;
374
+ }
375
+ function normalizeNonce(raw) {
376
+ return {
377
+ nonce: Number(normalizePactValue(raw["nonce"]) ?? 0),
378
+ "nonce-supply": Number(normalizePactValue(raw["nonce-supply"]) ?? 0),
379
+ "mint-time": normalizePactTime(raw["mint-time"]),
380
+ "release-time": normalizePactTime(raw["release-time"]),
381
+ "hibernating-fee-promile": Number(normalizePactValue(raw["hibernating-fee-promile"]) ?? 0),
382
+ remainder: Number(normalizePactValue(raw["remainder"]) ?? 0),
383
+ "hibernating-fee": Number(normalizePactValue(raw["hibernating-fee"]) ?? 0),
384
+ };
385
+ }
386
+ export async function getHibernatedNoncesDisplay(residentAccount, dpof, sortBy) {
387
+ try {
388
+ const inner = `(${KADENA_NAMESPACE}.INFO-ONE.VST|INFO-HibernatedNoncesDisplay "${residentAccount}" "${dpof}")`;
389
+ const pactCode = sortBy === "fee-promile"
390
+ ? `(sort ["hibernating-fee-promile"] ${inner})`
391
+ : inner;
392
+ const response = await pactRead(pactCode, { tier: "T2" });
393
+ if (!response || !response.result || response.result.status === "failure")
394
+ return null;
395
+ const data = response.result.data;
396
+ if (!Array.isArray(data))
397
+ return null;
398
+ // Normalize all Pact primitive wrappers ({int:N}, {decimal:"..."}, {time:"..."})
399
+ return data.map(normalizeNonce);
400
+ }
401
+ catch (error) {
402
+ getLogger().error("Error getting hibernated nonces:", error);
403
+ return null;
404
+ }
405
+ }
406
+ // ── Awake Info ────────────────────────────────────────────────────────────────
407
+ // (ouronet-ns.INFO-ONE.VST|INFO_Awake <patron> <awaker> <dpof> <nonce>)
408
+ export async function getAwakeInfo(patron, awaker, dpof, nonce) {
409
+ try {
410
+ const pactCode = `(${KADENA_NAMESPACE}.INFO-ONE.VST|INFO_Awake "${patron}" "${awaker}" "${dpof}" ${nonce})`;
411
+ const response = await pactRead(pactCode, { tier: "T2" });
412
+ if (!response || !response.result || response.result.status === "failure")
413
+ return null;
414
+ return response.result.data ?? null;
415
+ }
416
+ catch (error) {
417
+ getLogger().error("Error getting awake info:", error);
418
+ return null;
419
+ }
420
+ }
421
+ // ── Slumber Info ──────────────────────────────────────────────────────────────
422
+ // (ouronet-ns.INFO-ONE.VST|INFO_Slumber <patron> <merger> <dpof> <nonces:[integer]>)
423
+ export async function getSlumberInfo(patron, merger, dpof, nonces) {
424
+ try {
425
+ const nonceList = `[${nonces.join(" ")}]`;
426
+ const pactCode = `(${KADENA_NAMESPACE}.INFO-ONE.VST|INFO_Slumber "${patron}" "${merger}" "${dpof}" ${nonceList})`;
427
+ const response = await pactRead(pactCode, { tier: "T2" });
428
+ if (!response || !response.result || response.result.status === "failure")
429
+ return null;
430
+ return response.result.data ?? null;
431
+ }
432
+ catch (error) {
433
+ getLogger().error("Error getting slumber info:", error);
434
+ return null;
435
+ }
436
+ }
437
+ /**
438
+ * Get ClearDispo preview info from INFO-ONE
439
+ * (ouronet-ns.INFO-ONE.DPTF|INFO_ClearDispo <patron:string> <account:string>)
440
+ */
441
+ export async function getClearDispoInfo(patronAddress, accountAddress) {
442
+ try {
443
+ const response = await pactRead(`(${KADENA_NAMESPACE}.INFO-ONE.DPTF|INFO_ClearDispo "${patronAddress}" "${accountAddress}")`, { tier: "T2" });
444
+ if (response.result.status === "failure")
445
+ return null;
446
+ return response.result.data ?? null;
447
+ }
448
+ catch (error) {
449
+ getLogger().error("Error in getClearDispoInfo:", error);
450
+ return null;
451
+ }
452
+ }
453
+ // ── Add Liquidity INFO function ───────────────────────────────────────────────
454
+ /**
455
+ * INFO_AddLiquidity — dirty read for add liquidity preview.
456
+ * (ouronet-ns.INFO-ONE.SWP|INFO_AddLiquidity patron account swpair input-amounts kda-pid)
457
+ */
458
+ export async function getInfoAddLiquidity(patron, account, swpair, inputAmounts, kdaPid) {
459
+ try {
460
+ const pactInputAmounts = `[${inputAmounts.map(a => {
461
+ const s = String(a || "0");
462
+ return s.includes(".") ? s : s + ".0";
463
+ }).join(" ")}]`;
464
+ const decKdaPid = kdaPid.includes(".") ? kdaPid : kdaPid + ".0";
465
+ const pactCode = `(${KADENA_NAMESPACE}.INFO-ONE.SWP|INFO_AddLiquidity "${patron}" "${account}" "${swpair}" ${pactInputAmounts} ${decKdaPid})`;
466
+ const response = await pactRead(pactCode, { tier: "T2" });
467
+ if (!response?.result || response.result.status === "failure")
468
+ return null;
469
+ return response.result.data;
470
+ }
471
+ catch (error) {
472
+ getLogger().error("getInfoAddLiquidity error:", error);
473
+ return null;
474
+ }
475
+ }
476
+ /**
477
+ * INFO_Fuel — dirty read for fuel preview.
478
+ * (ouronet-ns.INFO-ONE.SWP|INFO_Fuel patron account swpair input-amounts)
479
+ */
480
+ export async function getInfoFuel(patron, account, swpair, inputAmounts) {
481
+ try {
482
+ const pactInputAmounts = `[${inputAmounts.map(a => {
483
+ const s = String(a || "0");
484
+ return s.includes(".") ? s : s + ".0";
485
+ }).join(" ")}]`;
486
+ const pactCode = `(${KADENA_NAMESPACE}.INFO-ONE.SWP|INFO_Fuel "${patron}" "${account}" "${swpair}" ${pactInputAmounts})`;
487
+ const response = await pactRead(pactCode, { tier: "T2" });
488
+ if (!response?.result || response.result.status === "failure")
489
+ return null;
490
+ return response.result.data;
491
+ }
492
+ catch (error) {
493
+ getLogger().error("getInfoFuel error:", error);
494
+ return null;
495
+ }
496
+ }
497
+ // ── Swap INFO functions ───────────────────────────────────────────────────────
498
+ /**
499
+ * INFO_SinglePoolSwap — dirty read for single-input swap preview.
500
+ * (ouronet-ns.INFO-ONE.SWP|INFO_SinglePoolSwap patron account swpair input-id input-amount output-id)
501
+ */
502
+ export async function getInfoSinglePoolSwap(patron, account, swpair, inputId, inputAmount, outputId) {
503
+ try {
504
+ const decAmount = formatDecimalForPact(inputAmount);
505
+ const pactCode = `(${KADENA_NAMESPACE}.INFO-ONE.SWP|INFO_SinglePoolSwap "${patron}" "${account}" "${swpair}" "${inputId}" ${decAmount} "${outputId}")`;
506
+ const response = await pactRead(pactCode, { tier: "T2" });
507
+ if (!response?.result || response.result.status === "failure")
508
+ return null;
509
+ return response.result.data;
510
+ }
511
+ catch (error) {
512
+ getLogger().error("getInfoSinglePoolSwap error:", error);
513
+ return null;
514
+ }
515
+ }
516
+ /**
517
+ * INFO_MultiPoolSwap — dirty read for multi-input swap preview.
518
+ * (ouronet-ns.INFO-ONE.SWP|INFO_MultiPoolSwap patron account swpair input-ids input-amounts output-id)
519
+ */
520
+ export async function getInfoMultiPoolSwap(patron, account, swpair, inputIds, inputAmounts, outputId) {
521
+ try {
522
+ const pactInputIds = `[${inputIds.map(id => `"${id}"`).join(" ")}]`;
523
+ const pactInputAmounts = `[${inputAmounts.map(a => {
524
+ const s = String(a);
525
+ return s.includes(".") ? s : s + ".0";
526
+ }).join(" ")}]`;
527
+ const pactCode = `(${KADENA_NAMESPACE}.INFO-ONE.SWP|INFO_MultiPoolSwap "${patron}" "${account}" "${swpair}" ${pactInputIds} ${pactInputAmounts} "${outputId}")`;
528
+ const response = await pactRead(pactCode, { tier: "T2" });
529
+ if (!response?.result || response.result.status === "failure")
530
+ return null;
531
+ return response.result.data;
532
+ }
533
+ catch (error) {
534
+ getLogger().error("getInfoMultiPoolSwap error:", error);
535
+ return null;
536
+ }
537
+ }
538
+ /**
539
+ * INFO_RemoveLiquidity — dirty read for remove liquidity (unfold) preview.
540
+ * (ouronet-ns.INFO-ONE.SWP|INFO_RemoveLiquidity patron account swpair lp-amount)
541
+ */
542
+ export async function getInfoRemoveLiquidity(patron, account, swpair, lpAmount) {
543
+ try {
544
+ const decLpAmount = lpAmount.includes(".") ? lpAmount : lpAmount + ".0";
545
+ const pactCode = `(${KADENA_NAMESPACE}.INFO-ONE.SWP|INFO_RemoveLiquidity "${patron}" "${account}" "${swpair}" ${decLpAmount})`;
546
+ // v3.3.0 (closes part of consolidated F-LOGGER-SEAM-001): the two
547
+ // `console.log` debug-leak calls that used to live here were leftover
548
+ // dev instrumentation (per-keystroke pretty-printed `JSON.stringify`
549
+ // dumps that bypassed the seam AND added serialisation cost on every
550
+ // preview read). The legitimate diagnostic — the FAILED warn call
551
+ // below — already routes through the seam. Removing the debug-only
552
+ // calls is the audit-recommended outcome (per the F-LOGGER-SEAM-001
553
+ // validator's "should be removed or routed" classification — these
554
+ // had no operational value beyond developer-side trace).
555
+ const response = await pactRead(pactCode, { tier: "T2" });
556
+ if (!response?.result || response.result.status === "failure") {
557
+ getLogger().warn("[INFO_RemoveLiquidity] FAILED:", response?.result?.error?.message);
558
+ return null;
559
+ }
560
+ return response.result.data;
561
+ }
562
+ catch (error) {
563
+ getLogger().error("getInfoRemoveLiquidity error:", error);
564
+ return null;
565
+ }
566
+ }
@@ -0,0 +1,11 @@
1
+ export interface BalanceItem {
2
+ account: string;
3
+ balance: string;
4
+ }
5
+ export declare function getBalance(account: string): Promise<BalanceItem>;
6
+ export declare function accountDescription(address: string): Promise<{
7
+ isNewAccount: boolean;
8
+ balance: any;
9
+ account: any;
10
+ guard: any;
11
+ }>;
@@ -0,0 +1,40 @@
1
+ import { pactRead } from "@stoachain/stoa-core/reads";
2
+ import { KadenaShapeError } from "./errors.js";
3
+ export async function getBalance(account) {
4
+ const pactCode = `(coin.get-balance "${account}")`;
5
+ const response = await pactRead(pactCode, { tier: "T1" });
6
+ const raw = response.result.data;
7
+ let balance;
8
+ if (raw !== null && raw !== undefined && typeof raw === "object" && "decimal" in raw) {
9
+ // Kadena may return { decimal: "..." } — unwrap to plain string
10
+ balance = String(raw.decimal);
11
+ }
12
+ else if (typeof raw === "string") {
13
+ balance = raw;
14
+ }
15
+ else {
16
+ throw new KadenaShapeError("Unexpected balance envelope", { cause: response.result });
17
+ }
18
+ return { account, balance };
19
+ }
20
+ export async function accountDescription(address) {
21
+ const pactCode = `(coin.details "${address}")`;
22
+ const { result } = await pactRead(pactCode, { tier: "T5" });
23
+ if (result?.status === "failure") {
24
+ return {
25
+ isNewAccount: true,
26
+ balance: undefined,
27
+ account: result?.data?.account || address,
28
+ guard: result?.data?.guard || null,
29
+ };
30
+ }
31
+ if (result?.data?.balance === undefined || result?.data?.balance === null) {
32
+ throw new KadenaShapeError("Account description envelope missing balance field", { cause: result });
33
+ }
34
+ return {
35
+ isNewAccount: false,
36
+ balance: result.data.balance,
37
+ account: result?.data?.account || address,
38
+ guard: result?.data?.guard || null,
39
+ };
40
+ }
@@ -0,0 +1,45 @@
1
+ import type { IKadenaKeypair } from "@stoachain/stoa-core/signing";
2
+ export type { IKadenaKeypair } from "@stoachain/stoa-core/signing";
3
+ export interface IOuroAccountKeypair {
4
+ address: string;
5
+ publicKey: string;
6
+ privateKey?: string;
7
+ }
8
+ /**
9
+ * Get KPay data for a specific Ouro account
10
+ * @param account - Ouro account address
11
+ * @returns KPay data object or null on failure
12
+ */
13
+ export declare function getKpayData(account: string): Promise<any>;
14
+ /**
15
+ * Get cost for specific amount of KPAY tokens with future price projection
16
+ * @param amount - Amount of KPAY tokens (integer)
17
+ * @param futureSeconds - Seconds in the future to calculate price (default 900 = 15 minutes)
18
+ * @returns Object with pid (price in dollars) and wkda (WSTOA amount) or null
19
+ */
20
+ export declare function getKpayAmountCosts(amount: number, futureSeconds?: number): Promise<{
21
+ pid: string;
22
+ wkda: string;
23
+ } | null>;
24
+ /**
25
+ * Get required capabilities for KPAY acquisition
26
+ * @param buyer - Buyer Ouro account address
27
+ * @param amount - Amount of KPAY tokens (integer)
28
+ * @param isNative - true for KDA native, false for WSTOA
29
+ * @returns Array of capability strings or null
30
+ */
31
+ export declare function getKpayAcquireCapabilities(buyer: string, amount: number, isNative: boolean): Promise<string[] | null>;
32
+ /**
33
+ * Buy KPAY tokens with KDA or WSTOA
34
+ * @param patronAccount - Patron Ouro account
35
+ * @param buyerAccount - Buyer Ouro address (usually same as patron)
36
+ * @param kpayAmount - Amount of KPAY tokens to buy (integer)
37
+ * @param isNative - true for KDA native, false for WSTOA
38
+ * @param kadenaAccount - Kadena account for gas and payments
39
+ * @param guardAccount - Guard account from Ouro account
40
+ * @returns Transaction result
41
+ */
42
+ export declare function kpayBuy(patronAccount: IOuroAccountKeypair, buyerAccount: string, kpayAmount: number, isNative: boolean, kadenaAccount: IKadenaKeypair, guardAccount: IKadenaKeypair, guardKeyset: {
43
+ keys: string[];
44
+ pred: "keys-all" | "keys-any" | "keys-2";
45
+ }): Promise<any>;