@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,316 @@
1
+ /**
2
+ * dexParseFunctions.ts
3
+ * Pact response parsers and formatters for dex entities (cross-cutting helpers).
4
+ */
5
+ // Utility functions to parse swap calculation results
6
+ export function parseSwapAmount(amountString) {
7
+ // Extract number from strings like "WSTOA-8Nh-JO8JO4F5 Output: 28.633136871920000000000000"
8
+ const match = amountString.match(/:\s*([0-9.]+)/);
9
+ return match ? parseFloat(match[1]) : 0;
10
+ }
11
+ /**
12
+ * Parse swap amount as string to preserve full decimal precision
13
+ * @param amountString - String like "WSTOA-8Nh-JO8JO4F5 Output: 28.633136871920000000000000"
14
+ * @returns The numeric value as a string with full precision
15
+ */
16
+ export function parseSwapAmountPrecise(amountString) {
17
+ const match = amountString.match(/:\s*([0-9.]+)/);
18
+ return match ? match[1] : "0";
19
+ }
20
+ export function parseSwapLiquidityProviders(providers) {
21
+ // Sum all liquidity provider fees from array like:
22
+ // ["SSTOA-8Nh-JO8JO4F5 from Input to Liquidity Providers: 0.0000829749299355716637", "OURO-8Nh-JO8JO4F5 from Input to Liquidity Providers: 0.26312828657714566275"]
23
+ return providers.reduce((total, providerString) => {
24
+ const amount = parseSwapAmount(providerString);
25
+ return total + amount;
26
+ }, 0);
27
+ }
28
+ export function parseSwapLiquidityProvidersDetailed(providers) {
29
+ // Parse individual liquidity provider fees from array like:
30
+ return providers.map((providerString) => {
31
+ const amount = parseSwapAmount(providerString);
32
+ // Extract token name from the beginning of the string (e.g., "SSTOA" from "SSTOA-8Nh-JO8JO4F5")
33
+ const tokenMatch = providerString.match(/^([A-Z]+)/);
34
+ const token = tokenMatch ? tokenMatch[1] : 'Unknown';
35
+ return {
36
+ token,
37
+ amount
38
+ };
39
+ });
40
+ }
41
+ /**
42
+ * Parse liquidity provider fees with full precision
43
+ * @param providers - Array of provider strings from API
44
+ * @returns Array of {token, amount} with amount as string for full precision
45
+ */
46
+ export function parseSwapLiquidityProvidersDetailedPrecise(providers) {
47
+ return providers.map((providerString) => {
48
+ const amount = parseSwapAmountPrecise(providerString);
49
+ const tokenMatch = providerString.match(/^([A-Z]+)/);
50
+ const token = tokenMatch ? tokenMatch[1] : 'Unknown';
51
+ return {
52
+ token,
53
+ amount
54
+ };
55
+ });
56
+ }
57
+ /**
58
+ * Parse decimal string to number for display
59
+ */
60
+ export function parseDecimalValue(decimalValue) {
61
+ return parseFloat(decimalValue.decimal);
62
+ }
63
+ /**
64
+ * Parse decimal value as string to preserve full precision
65
+ * @param decimalValue - DecimalValue object with decimal string
66
+ * @returns The decimal value as a string with full precision
67
+ */
68
+ export function parseDecimalValuePrecise(decimalValue) {
69
+ return decimalValue.decimal;
70
+ }
71
+ /**
72
+ * Format pool type for display
73
+ */
74
+ export function formatPoolType(poolType, poolTypeWord) {
75
+ return `${poolType} (${poolTypeWord})`;
76
+ }
77
+ /**
78
+ * Get total pool value in USD from a pool
79
+ */
80
+ export function getPoolValueUSD(pool) {
81
+ return pool["tvl-in-$"];
82
+ }
83
+ /**
84
+ * Get pool tokens summary
85
+ */
86
+ export function getPoolTokensSummary(pool) {
87
+ return {
88
+ tokens: pool["pool-tokens"],
89
+ supplies: pool["pool-token-supplies"].map(parseDecimalValue),
90
+ totalTokens: pool["pool-tokens"].length,
91
+ };
92
+ }
93
+ /**
94
+ * Calculate total fees for pool
95
+ */
96
+ export function getPoolFeeStructure(pool) {
97
+ return {
98
+ liquidFee: pool["liquid-fee"],
99
+ lpFee: pool["lp-fee"],
100
+ specialFee: pool["special-fee"],
101
+ totalFee: pool["total-fee"],
102
+ };
103
+ }
104
+ /**
105
+ * Get special fee targets with proportions
106
+ */
107
+ export function getSpecialFeeTargets(pool) {
108
+ return {
109
+ targets: pool["special-fee-targets"],
110
+ shortTargets: pool["special-fee-targets-short"],
111
+ proportions: pool["special-fee-targets-proportions"],
112
+ };
113
+ }
114
+ /**
115
+ * Get formatted pool values from enhanced preview data
116
+ */
117
+ export function getFormattedPoolValues(pool) {
118
+ return {
119
+ formattedPoolValue: pool["ft-pool-value-in-dwk"],
120
+ formattedLpSupply: pool["ft-lp-supply"],
121
+ formattedLpValue: pool["ft-lp-value-in-dwk"],
122
+ formattedTokenSupplies: pool["ft-pool-token-supplies"],
123
+ };
124
+ }
125
+ /**
126
+ * Get pool weights and calculate percentages
127
+ */
128
+ export function getPoolWeights(pool) {
129
+ const weights = pool["weigths"]; // Note: API has typo "weigths"
130
+ const percentages = weights.map(w => `${(w * 100).toFixed(1)}%`);
131
+ const isBalanced = weights.every(w => Math.abs(w - weights[0]) < 0.01);
132
+ return {
133
+ weights,
134
+ weightPercentages: percentages,
135
+ isBalanced,
136
+ };
137
+ }
138
+ /**
139
+ * Calculate pool composition data for charts/visualizations
140
+ */
141
+ export function getPoolComposition(pool) {
142
+ const tokens = pool["pool-tokens"];
143
+ const supplies = pool["pool-token-supplies"].map(parseDecimalValue);
144
+ const weights = pool["weigths"];
145
+ const formattedSupplies = pool["ft-pool-token-supplies"];
146
+ const compositions = tokens.map((token, index) => ({
147
+ token: token.split('-')[0], // Clean token name
148
+ supply: supplies[index],
149
+ weight: weights[index],
150
+ percentage: `${(weights[index] * 100).toFixed(1)}%`,
151
+ formattedSupply: formattedSupplies[index],
152
+ }));
153
+ return {
154
+ tokens,
155
+ supplies,
156
+ weights,
157
+ compositions,
158
+ };
159
+ }
160
+ /**
161
+ * Local helper to resolve Pact decimal/int values to a numeric string.
162
+ */
163
+ function parseLPDec(v) {
164
+ if (v == null)
165
+ return "0";
166
+ if (typeof v === "number")
167
+ return String(v);
168
+ if (typeof v === "string")
169
+ return v;
170
+ if (typeof v === "object" && v !== null && "decimal" in v)
171
+ return v.decimal;
172
+ if (typeof v === "object" && v !== null && "int" in v)
173
+ return String(v.int);
174
+ return String(v);
175
+ }
176
+ /**
177
+ * Local helper to resolve Pact int/number values to JS number.
178
+ */
179
+ function parseIntVal(v) {
180
+ if (v === null || v === undefined)
181
+ return 0;
182
+ if (typeof v === "number")
183
+ return v;
184
+ if (typeof v === "object" && "int" in v)
185
+ return v.int;
186
+ return parseInt(String(v), 10) || 0;
187
+ }
188
+ export function formatLPEntry(entry) {
189
+ const walletSupply = parseLPDec(entry["wallet-supply"]);
190
+ const totalSupply = parseLPDec(entry["dptf-supply"]);
191
+ const walletStoa = parseLPDec(entry["wallet-worth-in-stoa"]);
192
+ const walletUsd = typeof entry["wallet-worth-in-dollarz"] === "string"
193
+ ? entry["wallet-worth-in-dollarz"]
194
+ : parseLPDec(entry["wallet-worth-in-dollarz"]);
195
+ const tokenStoa = parseLPDec(entry["token-worth-in-stoa"]);
196
+ const tokenUsd = typeof entry["token-worth-in-dollarz"] === "string"
197
+ ? entry["token-worth-in-dollarz"]
198
+ : parseLPDec(entry["token-worth-in-dollarz"]);
199
+ return { name: entry.t1, tokenId: entry.t2, walletSupply, totalSupply, walletStoa, walletUsd, tokenStoa, tokenUsd };
200
+ }
201
+ /**
202
+ * Format a TrueFungibleEntry response into display-ready values.
203
+ */
204
+ export function formatTFEntry(entry) {
205
+ const walletSupply = parseLPDec(entry["wallet-supply"]);
206
+ const totalSupply = parseLPDec(entry["dptf-supply"]);
207
+ const walletStoa = parseLPDec(entry["wallet-worth-in-stoa"]);
208
+ const walletUsd = typeof entry["wallet-worth-in-dollarz"] === "string"
209
+ ? entry["wallet-worth-in-dollarz"]
210
+ : parseLPDec(entry["wallet-worth-in-dollarz"]);
211
+ const tokenStoa = parseLPDec(entry["token-worth-in-stoa"]);
212
+ const tokenUsd = typeof entry["token-worth-in-dollarz"] === "string"
213
+ ? entry["token-worth-in-dollarz"]
214
+ : parseLPDec(entry["token-worth-in-dollarz"]);
215
+ return { name: entry.t1, tokenId: entry.t2, walletSupply, totalSupply, walletStoa, walletUsd, tokenStoa, tokenUsd };
216
+ }
217
+ /**
218
+ * Format an OrtoFungibleEntryData into display-ready values.
219
+ * Same as formatTFEntry but includes wallet-nonces.
220
+ */
221
+ export function formatOFEntry(entry) {
222
+ const walletSupply = parseLPDec(entry["wallet-supply"]);
223
+ const totalSupply = parseLPDec(entry["dpof-supply"]);
224
+ const walletStoa = parseLPDec(entry["wallet-worth-in-stoa"]);
225
+ const walletUsd = typeof entry["wallet-worth-in-dollarz"] === "string"
226
+ ? entry["wallet-worth-in-dollarz"]
227
+ : parseLPDec(entry["wallet-worth-in-dollarz"]);
228
+ const tokenStoa = parseLPDec(entry["token-worth-in-stoa"]);
229
+ const tokenUsd = typeof entry["token-worth-in-dollarz"] === "string"
230
+ ? entry["token-worth-in-dollarz"]
231
+ : parseLPDec(entry["token-worth-in-dollarz"]);
232
+ // wallet-nonces can be [0, 1, 2] or [{int: 0}, {int: 1}, {int: 2}] from chain
233
+ const rawNonces = entry["wallet-nonces"] ?? [];
234
+ const walletNonces = rawNonces.map((n) => parseIntVal(n));
235
+ const walletNoncesNo = parseIntVal(entry["wallet-nonces-no"]);
236
+ return { name: entry.t1, tokenId: entry.t2, walletSupply, totalSupply, walletStoa, walletUsd, tokenStoa, tokenUsd, walletNonces, walletNoncesNo };
237
+ }
238
+ /**
239
+ * Classify a token ID into its category based on prefix.
240
+ * Returns: "lp" | "frozen-lp" | "frozen" | "reserved" | "native"
241
+ */
242
+ export function classifyTokenId(tokenId) {
243
+ // Frozen LP: F|S|, F|W|, F|P|
244
+ if (/^F\|[SWP]\|/.test(tokenId))
245
+ return "frozen-lp";
246
+ // LP: S|, W|, P|
247
+ if (/^[SWP]\|/.test(tokenId))
248
+ return "lp";
249
+ // Frozen: F|
250
+ if (tokenId.startsWith("F|"))
251
+ return "frozen";
252
+ // Reserved: R|
253
+ if (tokenId.startsWith("R|"))
254
+ return "reserved";
255
+ return "native";
256
+ }
257
+ /**
258
+ * Classify an Orto Fungible token ID into one of 5 categories.
259
+ *
260
+ * Sleeping LP: Z|S|, Z|W|, Z|P|
261
+ * Vesting: V|
262
+ * Sleeping: Z| (but NOT Z|S|, Z|W|, Z|P|)
263
+ * Hibernating: H|
264
+ * Native: everything else
265
+ */
266
+ export function classifyOrtoFungibleId(tokenId) {
267
+ // Sleeping LP: Z|S|, Z|W|, Z|P| — must be checked BEFORE sleeping
268
+ if (/^Z\|[SWP]\|/.test(tokenId))
269
+ return "sleeping-lp";
270
+ // Vesting: V|
271
+ if (tokenId.startsWith("V|"))
272
+ return "vesting";
273
+ // Sleeping: Z|
274
+ if (tokenId.startsWith("Z|"))
275
+ return "sleeping";
276
+ // Hibernating: H|
277
+ if (tokenId.startsWith("H|"))
278
+ return "hibernating";
279
+ return "native";
280
+ }
281
+ export function parseNonceData(raw) {
282
+ const parseURIType = (t) => ({
283
+ image: !!t?.image, audio: !!t?.audio, video: !!t?.video,
284
+ document: !!t?.document, archive: !!t?.archive, model: !!t?.model, exotic: !!t?.exotic,
285
+ });
286
+ const parseURIData = (d) => ({
287
+ image: d?.image ?? "", audio: d?.audio ?? "", video: d?.video ?? "",
288
+ document: d?.document ?? "", archive: d?.archive ?? "", model: d?.model ?? "", exotic: d?.exotic ?? "",
289
+ });
290
+ const parseDecNonce = (v) => {
291
+ if (typeof v === "number")
292
+ return v;
293
+ if (typeof v === "object" && v !== null) {
294
+ if ("decimal" in v)
295
+ return parseFloat(v.decimal) || 0;
296
+ if ("int" in v)
297
+ return parseFloat(v.int) || 0;
298
+ }
299
+ return parseFloat(String(v)) || 0;
300
+ };
301
+ return {
302
+ royalty: parseDecNonce(raw?.royalty),
303
+ ignis: parseDecNonce(raw?.ignis),
304
+ name: raw?.name ?? "",
305
+ description: raw?.description ?? "",
306
+ "meta-data": {
307
+ score: parseDecNonce(raw?.["meta-data"]?.score),
308
+ composition: Array.isArray(raw?.["meta-data"]?.composition) ? raw["meta-data"].composition : [],
309
+ "meta-data": raw?.["meta-data"]?.["meta-data"] ?? {},
310
+ },
311
+ "asset-type": parseURIType(raw?.["asset-type"]),
312
+ "uri-primary": parseURIData(raw?.["uri-primary"]),
313
+ "uri-secondary": parseURIData(raw?.["uri-secondary"]),
314
+ "uri-tertiary": parseURIData(raw?.["uri-tertiary"]),
315
+ };
316
+ }
@@ -0,0 +1,75 @@
1
+ /**
2
+ * dexSwapPairAdminFunctions.ts
3
+ * Swap pair admin reads — module/principals/limits/management/branding (URC_0014-0015, BRD/DALOS reads).
4
+ */
5
+ export declare function describeModule(moduleName: string): Promise<string | null>;
6
+ /** Fetch SWP principal tokens list */
7
+ export declare function getSWPPrincipals(): Promise<string[]>;
8
+ /**
9
+ * Fetch the current owner account of a SWP pair (Ouronet account string).
10
+ *
11
+ * (ouronet-ns.SWP.UR_OwnerKonto <swpair>)
12
+ *
13
+ * Lightweight unprotected read — returns just the owner-konto string. Used
14
+ * by the OuronetUI ChangeOwnership flow to decide which ghost address to
15
+ * pre-fill in the new-owner field (must differ from the current owner so
16
+ * the ghost-as-default execution path stays valid).
17
+ */
18
+ export declare function getSwpairOwnerKonto(swpair: string): Promise<string | null>;
19
+ /**
20
+ * Fetch the current `can-swap` (UI label "Swapping") flag for a SWP pair.
21
+ *
22
+ * (ouronet-ns.SWP.UR_CanSwap <swpair>)
23
+ *
24
+ * Used by the OuronetUI ToggleSwapCapability flow to compute the
25
+ * autonomous `toggle` argument (chain rejects same-value writes; only
26
+ * allowed value is the inverse of current).
27
+ */
28
+ export declare function getSwpairCanSwap(swpair: string): Promise<boolean | null>;
29
+ /**
30
+ * Fetch the current `can-add` (UI label "Provisioning") flag for a SWP pair.
31
+ *
32
+ * (ouronet-ns.SWP.UR_CanAdd <swpair>)
33
+ *
34
+ * Used by the OuronetUI ToggleAddLiquidity flow to compute the autonomous
35
+ * `toggle` argument (same chain-rejects-same-value-writes constraint as
36
+ * the other Toggle flows).
37
+ */
38
+ export declare function getSwpairCanAdd(swpair: string): Promise<boolean | null>;
39
+ /**
40
+ * Fetch the current `can-change-owner` flag for a SWP pair (boolean).
41
+ *
42
+ * (ouronet-ns.SWP.UR_CanChangeOwner <swpair>)
43
+ *
44
+ * Lightweight unprotected read. Used by the OuronetUI ModifyCanChangeOwner
45
+ * flow to compute the only-allowed `new-boolean` argument (the chain
46
+ * rejects same-value writes, so `new-boolean` is always the inverse of the
47
+ * current value — autonomous, never user-typed).
48
+ */
49
+ export declare function getSwpairCanChangeOwner(swpair: string): Promise<boolean | null>;
50
+ /** Fetch SWP spawn limit (WSTOA minimum to create a pool) */
51
+ export declare function getSWPSpawnLimit(): Promise<string | null>;
52
+ /** Fetch SWP inactive limit (WSTOA below which swap auto-deactivates) */
53
+ export declare function getSWPInactiveLimit(): Promise<string | null>;
54
+ /**
55
+ * Fetch management pool settings for a specific swap pair
56
+ * URC_0014_SwpairManagementPoolSettings
57
+ */
58
+ export declare function getSwpairManagementPoolSettings(swpair: string): Promise<any>;
59
+ /**
60
+ * URC_0015_SwpairManagementFeeSettings
61
+ * Returns fee configuration for a SWP pair: lock state, fee breakdown,
62
+ * special fee targets (up to 7), and max available target slots.
63
+ */
64
+ export declare function getSwpairManagementFeeSettings(swpair: string): Promise<any>;
65
+ /**
66
+ * DALOS.UR_UsagePrice — Get the price for a usage type (e.g. "blue" for blue flag branding)
67
+ * Returns the price in STOA
68
+ */
69
+ export declare function getUsagePrice(usageType: string): Promise<number | null>;
70
+ /**
71
+ * BRD.UR_Branding — Fetch branding properties for an entity
72
+ * @param entityId - SWP pair ID or LP token ID
73
+ * @param pending - true for pending branding, false for live branding
74
+ */
75
+ export declare function getBranding(entityId: string, pending: boolean): Promise<any>;
@@ -0,0 +1,255 @@
1
+ /**
2
+ * dexSwapPairAdminFunctions.ts
3
+ * Swap pair admin reads — module/principals/limits/management/branding (URC_0014-0015, BRD/DALOS reads).
4
+ */
5
+ import { KADENA_NAMESPACE } from "../constants/index.js";
6
+ import { pactRead } from "@stoachain/stoa-core/reads";
7
+ import { getLogger } from "@stoachain/stoa-core/observability";
8
+ export async function describeModule(moduleName) {
9
+ try {
10
+ const fqn = moduleName.includes(".") ? moduleName : `${KADENA_NAMESPACE}.${moduleName}`;
11
+ const response = await pactRead(`(describe-module "${fqn}")`, { tier: "T7" });
12
+ if (response.result.status === "success") {
13
+ const data = response.result.data;
14
+ return data?.code || JSON.stringify(data);
15
+ }
16
+ return null;
17
+ }
18
+ catch (error) {
19
+ getLogger().error("Error in describeModule:", error);
20
+ return null;
21
+ }
22
+ }
23
+ /** Fetch SWP principal tokens list */
24
+ export async function getSWPPrincipals() {
25
+ try {
26
+ const res = await pactRead(`(${KADENA_NAMESPACE}.SWP.UR_Principals)`, { tier: "T7" });
27
+ if (res.result.status === "failure")
28
+ return [];
29
+ return (Array.isArray(res.result.data) ? res.result.data : []);
30
+ }
31
+ catch (error) {
32
+ getLogger().error("Error in getSWPPrincipals:", error);
33
+ return [];
34
+ }
35
+ }
36
+ /**
37
+ * Fetch the current owner account of a SWP pair (Ouronet account string).
38
+ *
39
+ * (ouronet-ns.SWP.UR_OwnerKonto <swpair>)
40
+ *
41
+ * Lightweight unprotected read — returns just the owner-konto string. Used
42
+ * by the OuronetUI ChangeOwnership flow to decide which ghost address to
43
+ * pre-fill in the new-owner field (must differ from the current owner so
44
+ * the ghost-as-default execution path stays valid).
45
+ */
46
+ export async function getSwpairOwnerKonto(swpair) {
47
+ try {
48
+ const res = await pactRead(`(${KADENA_NAMESPACE}.SWP.UR_OwnerKonto "${swpair}")`, { tier: "T5" });
49
+ if (res.result.status === "failure")
50
+ return null;
51
+ const d = res.result.data;
52
+ return d == null ? null : String(d);
53
+ }
54
+ catch (error) {
55
+ getLogger().error("Error in getSwpairOwnerKonto:", error);
56
+ return null;
57
+ }
58
+ }
59
+ /**
60
+ * Fetch the current `can-swap` (UI label "Swapping") flag for a SWP pair.
61
+ *
62
+ * (ouronet-ns.SWP.UR_CanSwap <swpair>)
63
+ *
64
+ * Used by the OuronetUI ToggleSwapCapability flow to compute the
65
+ * autonomous `toggle` argument (chain rejects same-value writes; only
66
+ * allowed value is the inverse of current).
67
+ */
68
+ export async function getSwpairCanSwap(swpair) {
69
+ try {
70
+ const res = await pactRead(`(${KADENA_NAMESPACE}.SWP.UR_CanSwap "${swpair}")`, { tier: "T5" });
71
+ if (res.result.status === "failure")
72
+ return null;
73
+ const d = res.result.data;
74
+ if (typeof d === "boolean")
75
+ return d;
76
+ if (d === "true")
77
+ return true;
78
+ if (d === "false")
79
+ return false;
80
+ return null;
81
+ }
82
+ catch (error) {
83
+ getLogger().error("Error in getSwpairCanSwap:", error);
84
+ return null;
85
+ }
86
+ }
87
+ /**
88
+ * Fetch the current `can-add` (UI label "Provisioning") flag for a SWP pair.
89
+ *
90
+ * (ouronet-ns.SWP.UR_CanAdd <swpair>)
91
+ *
92
+ * Used by the OuronetUI ToggleAddLiquidity flow to compute the autonomous
93
+ * `toggle` argument (same chain-rejects-same-value-writes constraint as
94
+ * the other Toggle flows).
95
+ */
96
+ export async function getSwpairCanAdd(swpair) {
97
+ try {
98
+ const res = await pactRead(`(${KADENA_NAMESPACE}.SWP.UR_CanAdd "${swpair}")`, { tier: "T5" });
99
+ if (res.result.status === "failure")
100
+ return null;
101
+ const d = res.result.data;
102
+ if (typeof d === "boolean")
103
+ return d;
104
+ if (d === "true")
105
+ return true;
106
+ if (d === "false")
107
+ return false;
108
+ return null;
109
+ }
110
+ catch (error) {
111
+ getLogger().error("Error in getSwpairCanAdd:", error);
112
+ return null;
113
+ }
114
+ }
115
+ /**
116
+ * Fetch the current `can-change-owner` flag for a SWP pair (boolean).
117
+ *
118
+ * (ouronet-ns.SWP.UR_CanChangeOwner <swpair>)
119
+ *
120
+ * Lightweight unprotected read. Used by the OuronetUI ModifyCanChangeOwner
121
+ * flow to compute the only-allowed `new-boolean` argument (the chain
122
+ * rejects same-value writes, so `new-boolean` is always the inverse of the
123
+ * current value — autonomous, never user-typed).
124
+ */
125
+ export async function getSwpairCanChangeOwner(swpair) {
126
+ try {
127
+ const res = await pactRead(`(${KADENA_NAMESPACE}.SWP.UR_CanChangeOwner "${swpair}")`, { tier: "T5" });
128
+ if (res.result.status === "failure")
129
+ return null;
130
+ const d = res.result.data;
131
+ if (typeof d === "boolean")
132
+ return d;
133
+ if (d === "true")
134
+ return true;
135
+ if (d === "false")
136
+ return false;
137
+ return null;
138
+ }
139
+ catch (error) {
140
+ getLogger().error("Error in getSwpairCanChangeOwner:", error);
141
+ return null;
142
+ }
143
+ }
144
+ /** Fetch SWP spawn limit (WSTOA minimum to create a pool) */
145
+ export async function getSWPSpawnLimit() {
146
+ try {
147
+ const res = await pactRead(`(${KADENA_NAMESPACE}.SWP.UR_SpawnLimit)`, { tier: "T7" });
148
+ if (res.result.status === "failure")
149
+ return null;
150
+ const d = res.result.data;
151
+ return d && typeof d === "object" && d.decimal ? d.decimal : (d != null ? String(d) : null);
152
+ }
153
+ catch (error) {
154
+ getLogger().error("Error in getSWPSpawnLimit:", error);
155
+ return null;
156
+ }
157
+ }
158
+ /** Fetch SWP inactive limit (WSTOA below which swap auto-deactivates) */
159
+ export async function getSWPInactiveLimit() {
160
+ try {
161
+ const res = await pactRead(`(${KADENA_NAMESPACE}.SWP.UR_InactiveLimit)`, { tier: "T7" });
162
+ if (res.result.status === "failure")
163
+ return null;
164
+ const d = res.result.data;
165
+ return d && typeof d === "object" && d.decimal ? d.decimal : (d != null ? String(d) : null);
166
+ }
167
+ catch (error) {
168
+ getLogger().error("Error in getSWPInactiveLimit:", error);
169
+ return null;
170
+ }
171
+ }
172
+ /**
173
+ * Fetch management pool settings for a specific swap pair
174
+ * URC_0014_SwpairManagementPoolSettings
175
+ */
176
+ export async function getSwpairManagementPoolSettings(swpair) {
177
+ try {
178
+ const pactCode = `(${KADENA_NAMESPACE}.DPL-UR.URC_0014_SwpairManagementPoolSettings "${swpair}")`;
179
+ const response = await pactRead(pactCode, { tier: "T5" });
180
+ if (!response || !response.result) {
181
+ throw new Error("Failed to retrieve pool settings from the transaction.");
182
+ }
183
+ if (response.result.status === "failure") {
184
+ throw new Error(`Pool settings query failed: ${response.result.error?.message || "Unknown error"}`);
185
+ }
186
+ return response.result.data;
187
+ }
188
+ catch (err) {
189
+ getLogger().error("URC_0014 failed:", err);
190
+ return null;
191
+ }
192
+ }
193
+ /**
194
+ * URC_0015_SwpairManagementFeeSettings
195
+ * Returns fee configuration for a SWP pair: lock state, fee breakdown,
196
+ * special fee targets (up to 7), and max available target slots.
197
+ */
198
+ export async function getSwpairManagementFeeSettings(swpair) {
199
+ try {
200
+ const pactCode = `(${KADENA_NAMESPACE}.DPL-UR.URC_0015_SwpairManagementFeeSettings "${swpair}")`;
201
+ const response = await pactRead(pactCode, { tier: "T5" });
202
+ if (!response || !response.result) {
203
+ throw new Error("Failed to retrieve fee settings from the transaction.");
204
+ }
205
+ if (response.result.status === "failure") {
206
+ throw new Error(`Fee settings query failed: ${response.result.error?.message || "Unknown error"}`);
207
+ }
208
+ return response.result.data;
209
+ }
210
+ catch (err) {
211
+ getLogger().error("URC_0015 failed:", err);
212
+ return null;
213
+ }
214
+ }
215
+ /**
216
+ * DALOS.UR_UsagePrice — Get the price for a usage type (e.g. "blue" for blue flag branding)
217
+ * Returns the price in STOA
218
+ */
219
+ export async function getUsagePrice(usageType) {
220
+ try {
221
+ const pactCode = `(${KADENA_NAMESPACE}.DALOS.UR_UsagePrice "${usageType}")`;
222
+ const response = await pactRead(pactCode, { tier: "T5" });
223
+ if (response?.result?.status === "success") {
224
+ const d = response.result.data;
225
+ return typeof d === "number" ? d : (typeof d === "object" && d?.decimal ? parseFloat(d.decimal) : null);
226
+ }
227
+ return null;
228
+ }
229
+ catch (err) {
230
+ getLogger().error(`UR_UsagePrice(${usageType}) failed:`, err);
231
+ return null;
232
+ }
233
+ }
234
+ /**
235
+ * BRD.UR_Branding — Fetch branding properties for an entity
236
+ * @param entityId - SWP pair ID or LP token ID
237
+ * @param pending - true for pending branding, false for live branding
238
+ */
239
+ export async function getBranding(entityId, pending) {
240
+ try {
241
+ const pactCode = `(${KADENA_NAMESPACE}.BRD.UR_Branding "${entityId}" ${pending})`;
242
+ const response = await pactRead(pactCode, { tier: "T5" });
243
+ if (!response || !response.result) {
244
+ throw new Error("Failed to retrieve branding from the transaction.");
245
+ }
246
+ if (response.result.status === "failure") {
247
+ throw new Error(`Branding query failed: ${response.result.error?.message || "Unknown error"}`);
248
+ }
249
+ return response.result.data;
250
+ }
251
+ catch (err) {
252
+ getLogger().error(`BRD.UR_Branding(${entityId}, ${pending}) failed:`, err);
253
+ return null;
254
+ }
255
+ }