@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,191 @@
1
+ import { calculateAutoGasLimit } from "@stoachain/stoa-core/gas";
2
+ import { KADENA_CHAIN_ID, KADENA_NAMESPACE, STOA_AUTONOMIC_OURONETGASSTATION, KADENA_NETWORK, } from "../constants/index.js";
3
+ import { Pact } from "@stoachain/kadena-stoic-legacy/client";
4
+ import { getFailoverClient } from "@stoachain/stoa-core/network";
5
+ import { pactRead } from "@stoachain/stoa-core/reads";
6
+ import { universalSignTransaction, fromKeypair } from "@stoachain/stoa-core/signing";
7
+ import { safeCreationTime } from "@stoachain/stoa-core/pact";
8
+ import { getLogger } from "@stoachain/stoa-core/observability";
9
+ /**
10
+ * Get KPay data for a specific Ouro account
11
+ * @param account - Ouro account address
12
+ * @returns KPay data object or null on failure
13
+ */
14
+ export async function getKpayData(account) {
15
+ try {
16
+ const response = await pactRead(`(${KADENA_NAMESPACE}.DEMIPAD-KPAY.UR_Kpay "${account}")`, { tier: "T5" });
17
+ if (!response || !response.result || response.result.status === "failure") {
18
+ return null;
19
+ }
20
+ return response.result.data;
21
+ }
22
+ catch (error) {
23
+ getLogger().error("Error getting KPay data:", error);
24
+ return null;
25
+ }
26
+ }
27
+ /**
28
+ * Get cost for specific amount of KPAY tokens with future price projection
29
+ * @param amount - Amount of KPAY tokens (integer)
30
+ * @param futureSeconds - Seconds in the future to calculate price (default 900 = 15 minutes)
31
+ * @returns Object with pid (price in dollars) and wkda (WSTOA amount) or null
32
+ */
33
+ export async function getKpayAmountCosts(amount, futureSeconds = 900.0) {
34
+ try {
35
+ const integerAmount = Math.floor(amount);
36
+ const response = await pactRead(`(${KADENA_NAMESPACE}.DEMIPAD-KPAY.URC_KpayAmountCosts ${integerAmount} ${futureSeconds})`, { tier: "T6" });
37
+ if (!response || !response.result || response.result.status === "failure") {
38
+ return null;
39
+ }
40
+ return response.result.data;
41
+ }
42
+ catch (error) {
43
+ getLogger().error("Error getting KPay amount costs:", error);
44
+ return null;
45
+ }
46
+ }
47
+ /**
48
+ * Get required capabilities for KPAY acquisition
49
+ * @param buyer - Buyer Ouro account address
50
+ * @param amount - Amount of KPAY tokens (integer)
51
+ * @param isNative - true for KDA native, false for WSTOA
52
+ * @returns Array of capability strings or null
53
+ */
54
+ export async function getKpayAcquireCapabilities(buyer, amount, isNative) {
55
+ try {
56
+ const integerAmount = Math.floor(amount);
57
+ const response = await pactRead(`(${KADENA_NAMESPACE}.DEMIPAD-KPAY.URC_Acquire "${buyer}" ${integerAmount} ${isNative})`, { tier: "T5" });
58
+ if (!response || !response.result || response.result.status === "failure") {
59
+ return null;
60
+ }
61
+ return response.result.data;
62
+ }
63
+ catch (error) {
64
+ getLogger().error("Error getting KPay acquire capabilities:", error);
65
+ return null;
66
+ }
67
+ }
68
+ /**
69
+ * Parse capability string from blockchain format to withCapability format
70
+ * @param capString - Capability string like "<(coin.TRANSFER \"k:...\" \"c:...\" 46.298)>"
71
+ * @returns Parsed capability object or null
72
+ */
73
+ function parseCapabilityString(capString) {
74
+ try {
75
+ // Remove < > wrapper and extra whitespace
76
+ const cleaned = capString.replace(/^<\s*|\s*>$/g, '').trim();
77
+ // Pattern for: (coin.TRANSFER "from" "to" amount)
78
+ // More flexible regex that allows dots, pipes, and other chars in module names
79
+ const regex = /\(([^\s]+)\s+"([^"]+)"\s+"([^"]+)"\s+([\d.]+)\)/;
80
+ const match = cleaned.match(regex);
81
+ if (!match) {
82
+ return null;
83
+ }
84
+ const [, name, from, to, amount] = match;
85
+ // For coin.TRANSFER, format args as [from, to, { decimal: amount }]
86
+ if (name === "coin.TRANSFER") {
87
+ return {
88
+ name,
89
+ args: [from, to, { decimal: amount }]
90
+ };
91
+ }
92
+ // Generic fallback for other capabilities
93
+ return {
94
+ name,
95
+ args: [from, to, { decimal: amount }]
96
+ };
97
+ }
98
+ catch (error) {
99
+ getLogger().error("Error parsing capability string:", error);
100
+ return null;
101
+ }
102
+ }
103
+ /**
104
+ * Buy KPAY tokens with KDA or WSTOA
105
+ * @param patronAccount - Patron Ouro account
106
+ * @param buyerAccount - Buyer Ouro address (usually same as patron)
107
+ * @param kpayAmount - Amount of KPAY tokens to buy (integer)
108
+ * @param isNative - true for KDA native, false for WSTOA
109
+ * @param kadenaAccount - Kadena account for gas and payments
110
+ * @param guardAccount - Guard account from Ouro account
111
+ * @returns Transaction result
112
+ */
113
+ export async function kpayBuy(patronAccount, buyerAccount, kpayAmount, isNative, kadenaAccount, guardAccount, guardKeyset) {
114
+ const keysetName = `ks`;
115
+ // 1. Convert to integer
116
+ const integerAmount = Math.floor(kpayAmount);
117
+ // 2. Get required capabilities from blockchain
118
+ const capabilitiesStrings = await getKpayAcquireCapabilities(buyerAccount, integerAmount, isNative);
119
+ if (!capabilitiesStrings || capabilitiesStrings.length === 0) {
120
+ throw new Error("Failed to retrieve capabilities for KPAY purchase");
121
+ }
122
+ // 3. Parse capabilities
123
+ const parsedCapabilities = [];
124
+ for (const capString of capabilitiesStrings) {
125
+ const parsed = parseCapabilityString(capString);
126
+ if (parsed) {
127
+ parsedCapabilities.push(parsed);
128
+ }
129
+ }
130
+ if (parsedCapabilities.length === 0) {
131
+ throw new Error("Failed to parse any capabilities for KPAY purchase");
132
+ }
133
+ let gasLimit = 2000000; // Default gas limit for KPAY buy
134
+ // 4. Build transaction
135
+ const buildTransaction = (gasLimitOverride) => {
136
+ return Pact.builder
137
+ .execution(`(${KADENA_NAMESPACE}.TS02-DPAD.KPAY|C_BuyKpay "${patronAccount.address}" "${buyerAccount}" ${integerAmount} ${isNative})`)
138
+ .addData(keysetName, {
139
+ keys: guardKeyset.keys,
140
+ pred: guardKeyset.pred,
141
+ })
142
+ .setMeta({
143
+ senderAccount: STOA_AUTONOMIC_OURONETGASSTATION,
144
+ creationTime: safeCreationTime(), // Gas station
145
+ chainId: KADENA_CHAIN_ID,
146
+ gasLimit: gasLimitOverride || gasLimit,
147
+ })
148
+ .setNetworkId(KADENA_NETWORK)
149
+ .addSigner(kadenaAccount.publicKey, (withCapability) => {
150
+ const capabilities = [];
151
+ // Always add GAS_PAYER first
152
+ capabilities.push(withCapability(`${KADENA_NAMESPACE}.DALOS.GAS_PAYER`, "", { int: 0 }, { decimal: "0.0" }));
153
+ // Add all parsed capabilities from URC_Acquire
154
+ for (const cap of parsedCapabilities) {
155
+ try {
156
+ const addedCap = withCapability(cap.name, ...cap.args);
157
+ capabilities.push(addedCap);
158
+ }
159
+ catch (error) {
160
+ getLogger().error(`Failed to add capability: ${cap.name}`, error);
161
+ }
162
+ }
163
+ return capabilities;
164
+ })
165
+ .addSigner(guardAccount.publicKey)
166
+ .createTransaction();
167
+ };
168
+ const { dirtyRead, submit } = getFailoverClient(KADENA_CHAIN_ID);
169
+ // 5. Build and simulate UNSIGNED to check gas
170
+ let transaction = buildTransaction();
171
+ const simulation = await dirtyRead(transaction);
172
+ // Check if simulation failed
173
+ if (simulation.result.status === "failure") {
174
+ const errorMessage = simulation.result.error?.message || "Transaction simulation failed";
175
+ throw new Error(`KPAY purchase simulation failed: ${errorMessage}`);
176
+ }
177
+ // 6. Adjust gas limit if needed
178
+ const requiredGas = simulation.gas;
179
+ if (requiredGas && requiredGas > gasLimit) {
180
+ gasLimit = calculateAutoGasLimit(requiredGas); // 20% buffer
181
+ transaction = buildTransaction(gasLimit);
182
+ }
183
+ // 7. Sign the transaction with both keypairs
184
+ const signedTransaction = await universalSignTransaction(transaction, [
185
+ fromKeypair(kadenaAccount),
186
+ fromKeypair(guardAccount),
187
+ ]);
188
+ // 8. Submit the signed transaction
189
+ const result = await submit(signedTransaction);
190
+ return result;
191
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * ouroAccountFunctions.ts
3
+ * Selector / overview / guard / ledger reads against the ouronet-ns DALOS / DPL-UR / DSP / TFT modules.
4
+ */
5
+ import type { IKeyset } from "@stoachain/stoa-core/guard";
6
+ import type { AccountSelectorData, StoaAccountSelectorData, AccountOverviewData, StoicTagSelectorData } from "./ouroTypes.js";
7
+ export declare function getAccountSelectorData(accounts: string[], options?: {
8
+ skipTempWatcher?: boolean;
9
+ }): Promise<AccountSelectorData[]>;
10
+ /**
11
+ * Inverse StoicTag read — batch resolve a list of tag names to their on-chain
12
+ * status (existence / active / released) and bound Ouronet account, via
13
+ * `URC_0027b_StoicTagSelectorMapper`. Used by Address Book StoicTag entries,
14
+ * which watch a tag independently of any codex account. Returns one row per
15
+ * input tag, in order. Empty input → empty array.
16
+ */
17
+ export declare function getStoicTagSelectorData(tagNames: string[]): Promise<StoicTagSelectorData[]>;
18
+ /**
19
+ * Inverse StoicTag read — single tag name, via
20
+ * `URC_0027c_StoicTagSelectorSingle`. Returns `null` only on a read failure;
21
+ * a never-registered tag still resolves to a row with
22
+ * `iz-never-registered: true`.
23
+ */
24
+ export declare function getStoicTagInfo(tagName: string): Promise<StoicTagSelectorData | null>;
25
+ export interface RegisterStoicTagFullInfo {
26
+ /** The raw INFO_RegisterStoicTag ClientInfo (ignis + kadena/STOA split, text). */
27
+ info: any;
28
+ /** Split receiver k:/c: addresses — `kadena-targets` resolved via UR_AccountKadena. */
29
+ receivers: string[];
30
+ }
31
+ /**
32
+ * Full INFO for registering a StoicTag — fetches INFO_RegisterStoicTag AND
33
+ * resolves the STOA-split target Ouronet accounts (`kadena.kadena-targets`) to
34
+ * their actual k:/c: payment addresses in one read (mirrors
35
+ * getDeployStandardAccountInfo). The amounts live in `info.kadena.kadena-split`.
36
+ * Used to build the `coin.TRANSFER` capabilities the patron's payment key signs.
37
+ */
38
+ export declare function getRegisterStoicTagInfo(patron: string, tagName: string, account: string): Promise<RegisterStoicTagFullInfo | null>;
39
+ export declare function getStoaAccountSelectorData(accounts: string[]): Promise<StoaAccountSelectorData[]>;
40
+ export declare function getAccountOverview(account: string): Promise<AccountOverviewData | null>;
41
+ export declare function isAdministrativePause(): Promise<boolean>;
42
+ export declare function kadenaLedger(address: string): Promise<any>;
43
+ export declare const getKadenaAccountOwner: (address: string) => Promise<string | null>;
44
+ export declare const readKeyset: (namespace: string, keysetName: string) => Promise<any>;
45
+ /**
46
+ * Resolve a guard value — if it's a keyset ref, fetch the actual keyset.
47
+ * Handles both direct keyset objects and {keysetref: {ns, ksn}} references.
48
+ *
49
+ * Normalises the chain-native lowercase `keysetref` field to camelCase
50
+ * `keysetRef` at this boundary via `normalizeKeysetRef`, so internal code
51
+ * that follows downstream of `resolveGuard` only ever sees the camelCase
52
+ * form. The lowercase field is preserved for backwards-compat with
53
+ * existing reads.
54
+ */
55
+ export declare function resolveGuard(guardData: any): Promise<any>;
56
+ export declare const getKadenaAccountGuard: (address: string) => Promise<IKeyset | null>;
57
+ export declare function getOuronetKdaDetails(address: string): Promise<any>;
58
+ export declare function primordialPrices(): Promise<any>;
59
+ export declare function eliteAccount(address: string): Promise<any>;
60
+ export declare function filterKeysForInfo(address: string, table?: number, mode?: boolean): Promise<any>;
61
+ export declare function usagePrice(tokenType?: string): Promise<any>;
62
+ export declare function getHeaderData(address?: string, options?: {
63
+ skipTempWatcher?: boolean;
64
+ }): Promise<any>;
@@ -0,0 +1,229 @@
1
+ /**
2
+ * ouroAccountFunctions.ts
3
+ * Selector / overview / guard / ledger reads against the ouronet-ns DALOS / DPL-UR / DSP / TFT modules.
4
+ */
5
+ import { KADENA_NAMESPACE } from "../constants/index.js";
6
+ import { normalizeKeysetRef } from "@stoachain/stoa-core/guard";
7
+ import { pactRead } from "@stoachain/stoa-core/reads";
8
+ import { getLogger } from "@stoachain/stoa-core/observability";
9
+ export async function getAccountSelectorData(accounts, options) {
10
+ const accountsList = accounts.map(a => `"${a}"`).join(" ");
11
+ const pactCode = `(${KADENA_NAMESPACE}.DPL-UR.URC_0027_AccountSelectorMapper [${accountsList}])`;
12
+ const response = await pactRead(pactCode, { tier: "T5", skipTempWatcher: options?.skipTempWatcher });
13
+ if (!response?.result || response.result.status === "failure") {
14
+ getLogger().error("AccountSelectorMapper failed:", response);
15
+ return [];
16
+ }
17
+ return response.result?.data ?? [];
18
+ }
19
+ /**
20
+ * Inverse StoicTag read — batch resolve a list of tag names to their on-chain
21
+ * status (existence / active / released) and bound Ouronet account, via
22
+ * `URC_0027b_StoicTagSelectorMapper`. Used by Address Book StoicTag entries,
23
+ * which watch a tag independently of any codex account. Returns one row per
24
+ * input tag, in order. Empty input → empty array.
25
+ */
26
+ export async function getStoicTagSelectorData(tagNames) {
27
+ if (tagNames.length === 0)
28
+ return [];
29
+ const tagList = tagNames.map(t => `"${t}"`).join(" ");
30
+ const pactCode = `(${KADENA_NAMESPACE}.DPL-UR.URC_0027b_StoicTagSelectorMapper [${tagList}])`;
31
+ const response = await pactRead(pactCode, { tier: "T5" });
32
+ if (!response?.result || response.result.status === "failure") {
33
+ getLogger().error("StoicTagSelectorMapper failed:", response);
34
+ return [];
35
+ }
36
+ return response.result?.data ?? [];
37
+ }
38
+ /**
39
+ * Inverse StoicTag read — single tag name, via
40
+ * `URC_0027c_StoicTagSelectorSingle`. Returns `null` only on a read failure;
41
+ * a never-registered tag still resolves to a row with
42
+ * `iz-never-registered: true`.
43
+ */
44
+ export async function getStoicTagInfo(tagName) {
45
+ if (!tagName)
46
+ return null;
47
+ const pactCode = `(${KADENA_NAMESPACE}.DPL-UR.URC_0027c_StoicTagSelectorSingle "${tagName}")`;
48
+ const response = await pactRead(pactCode, { tier: "T5" });
49
+ if (!response?.result || response.result.status === "failure") {
50
+ getLogger().error("StoicTagSelectorSingle failed:", response);
51
+ return null;
52
+ }
53
+ return response.result?.data ?? null;
54
+ }
55
+ /**
56
+ * Full INFO for registering a StoicTag — fetches INFO_RegisterStoicTag AND
57
+ * resolves the STOA-split target Ouronet accounts (`kadena.kadena-targets`) to
58
+ * their actual k:/c: payment addresses in one read (mirrors
59
+ * getDeployStandardAccountInfo). The amounts live in `info.kadena.kadena-split`.
60
+ * Used to build the `coin.TRANSFER` capabilities the patron's payment key signs.
61
+ */
62
+ export async function getRegisterStoicTagInfo(patron, tagName, account) {
63
+ if (!patron || !tagName || !account)
64
+ return null;
65
+ try {
66
+ const pactCode = `(let*` +
67
+ ` ((info (${KADENA_NAMESPACE}.CODEX.CODEX|INFO_RegisterStoicTag "${patron}" "${tagName}" "${account}"))` +
68
+ ` (receivers (map (${KADENA_NAMESPACE}.DALOS.UR_AccountKadena) (at "kadena-targets" (at "kadena" info)))))` +
69
+ ` { "info": info, "receivers": receivers })`;
70
+ const response = await pactRead(pactCode, { tier: "T5" });
71
+ if (response?.result && response.result.status !== "failure") {
72
+ const data = response.result.data;
73
+ return { info: data?.info ?? null, receivers: data?.receivers ?? [] };
74
+ }
75
+ getLogger().error("getRegisterStoicTagInfo failed:", response);
76
+ return null;
77
+ }
78
+ catch (error) {
79
+ getLogger().error("getRegisterStoicTagInfo error:", error);
80
+ return null;
81
+ }
82
+ }
83
+ export async function getStoaAccountSelectorData(accounts) {
84
+ if (accounts.length === 0)
85
+ return [];
86
+ const accountsList = accounts.map(a => `"${a}"`).join(" ");
87
+ const pactCode = `(${KADENA_NAMESPACE}.DPL-UR.URC_0028_StoaAccountSelectorMapper [${accountsList}])`;
88
+ const response = await pactRead(pactCode, { tier: "T5" });
89
+ if (!response?.result || response.result.status === "failure") {
90
+ getLogger().error("StoaAccountSelectorMapper failed:", response);
91
+ return [];
92
+ }
93
+ return response.result?.data ?? [];
94
+ }
95
+ export async function getAccountOverview(account) {
96
+ if (!account)
97
+ return null;
98
+ const pactCode = `(${KADENA_NAMESPACE}.DPL-UR.URC_0029_AccountOverview "${account}")`;
99
+ const response = await pactRead(pactCode, { tier: "T7" });
100
+ if (!response?.result || response.result.status === "failure") {
101
+ getLogger().error("AccountOverview failed:", response);
102
+ return null;
103
+ }
104
+ return response.result?.data ?? null;
105
+ }
106
+ export async function isAdministrativePause() {
107
+ const response = await pactRead(`(${KADENA_NAMESPACE}.DALOS.UR_GAP)`, { tier: "T7" });
108
+ if (!response || !response.result) {
109
+ throw new Error("Failed to retrieve data from the transaction.");
110
+ }
111
+ return response.result.data;
112
+ }
113
+ export async function kadenaLedger(address) {
114
+ const response = await pactRead(`(${KADENA_NAMESPACE}.DALOS.UR_KadenaLedger "${address}")`, { tier: "T5" });
115
+ if (!response || !response.result) {
116
+ throw new Error("Failed to retrieve data from the transaction.");
117
+ }
118
+ return response.result;
119
+ }
120
+ export const getKadenaAccountOwner = async (address) => {
121
+ const response = await pactRead(`(${KADENA_NAMESPACE}.DALOS.UR_AccountKadena "${address}")`, { tier: "T5" });
122
+ if (!response || !response.result) {
123
+ throw new Error("Failed to retrieve data from the transaction.");
124
+ }
125
+ return response.result?.data || null;
126
+ };
127
+ export const readKeyset = async (namespace, keysetName) => {
128
+ const response = await pactRead(`(describe-keyset "${namespace}.${keysetName}")`, { tier: "T7" });
129
+ if (!response || !response.result) {
130
+ throw new Error("Failed to retrieve data from the transaction.");
131
+ }
132
+ return response.result?.data || null;
133
+ };
134
+ /**
135
+ * Resolve a guard value — if it's a keyset ref, fetch the actual keyset.
136
+ * Handles both direct keyset objects and {keysetref: {ns, ksn}} references.
137
+ *
138
+ * Normalises the chain-native lowercase `keysetref` field to camelCase
139
+ * `keysetRef` at this boundary via `normalizeKeysetRef`, so internal code
140
+ * that follows downstream of `resolveGuard` only ever sees the camelCase
141
+ * form. The lowercase field is preserved for backwards-compat with
142
+ * existing reads.
143
+ */
144
+ export async function resolveGuard(guardData) {
145
+ if (!guardData || guardData === false)
146
+ return null;
147
+ guardData = normalizeKeysetRef(guardData);
148
+ if (guardData.keysetref) {
149
+ const ks = await readKeyset(guardData.keysetref.ns, guardData.keysetref.ksn);
150
+ // Return a copy rather than mutating `ks` in place: the keyset object
151
+ // comes from `readKeyset`, which (under OuronetUI's cache-aware reader)
152
+ // hands back a shared, frozen reference. Writing `.keysetRef` onto it
153
+ // throws "Cannot assign to read only property 'keysetRef'".
154
+ return ks ? { ...ks, keysetRef: `${guardData.keysetref.ns}.${guardData.keysetref.ksn}` } : ks;
155
+ }
156
+ return guardData;
157
+ }
158
+ export const getKadenaAccountGuard = async (address) => {
159
+ const response = await pactRead(`(${KADENA_NAMESPACE}.DALOS.UR_AccountGuard "${address}")`, { tier: "T7" });
160
+ if (!response || !response.result) {
161
+ throw new Error("Failed to retrieve data from the transaction.");
162
+ }
163
+ const { data } = response.result;
164
+ if (data?.hasOwnProperty("keysetref")) {
165
+ const ks2 = await readKeyset(data.keysetref.ns, data.keysetref.ksn);
166
+ // Copy, don't mutate — see resolveGuard above for the frozen-reference rationale.
167
+ return ks2 ? { ...ks2, keysetRef: `${data.keysetref.ns}.${data.keysetref.ksn}` } : ks2;
168
+ }
169
+ return data || null;
170
+ };
171
+ export async function getOuronetKdaDetails(address) {
172
+ // v3.3.6 (F-PERF-004): parallelize the two independent reads.
173
+ // `getKadenaAccountOwner` reads `DALOS.UR_AccountKadena` and
174
+ // `getKadenaAccountGuard` reads `DALOS.UR_AccountGuard` — neither
175
+ // depends on the other's result, so `Promise.all` halves the
176
+ // happy-path latency (was ~2 sequential RPC roundtrips, now ~1
177
+ // parallel roundtrip).
178
+ const [owner, guard] = await Promise.all([
179
+ getKadenaAccountOwner(address),
180
+ getKadenaAccountGuard(address),
181
+ ]);
182
+ return {
183
+ isActive: owner !== null,
184
+ owner: owner,
185
+ guard: guard,
186
+ };
187
+ }
188
+ // (namespace.DSP.URC_PrimordialPrices)
189
+ export async function primordialPrices() {
190
+ const response = await pactRead(`(${KADENA_NAMESPACE}.DSP.URC_PrimordialPrices)`, { tier: "T6" });
191
+ if (!response || !response.result) {
192
+ throw new Error("Failed to retrieve data from the transaction.");
193
+ }
194
+ return response.result?.data || null;
195
+ }
196
+ // DALOS.UR_Elite account
197
+ export async function eliteAccount(address) {
198
+ const response = await pactRead(`(${KADENA_NAMESPACE}.DALOS.UR_Elite "${address}")`, { tier: "T6" });
199
+ if (!response || !response.result) {
200
+ throw new Error("Failed to retrieve data from the transaction.");
201
+ }
202
+ return response.result?.data || null;
203
+ }
204
+ export async function filterKeysForInfo(address, table = 1, mode = true) {
205
+ const pactCode = `(${KADENA_NAMESPACE}.TFT.DPTF-DPMF-ATS|UR_FilterKeysForInfo "${address}" ${table} ${mode})`;
206
+ const response = await pactRead(pactCode, { tier: "T3" });
207
+ if (!response || !response.result) {
208
+ throw new Error("Failed to retrieve data from the transaction.");
209
+ }
210
+ return response.result?.data || null;
211
+ }
212
+ // returns the price of the activation
213
+ export async function usagePrice(tokenType = "standard") {
214
+ const response = await pactRead(`(${KADENA_NAMESPACE}.DALOS.UR_UsagePrice "${tokenType}")`, { tier: "T7" });
215
+ if (!response || !response.result) {
216
+ throw new Error("Failed to retrieve data from the transaction.");
217
+ }
218
+ return response.result?.data || null;
219
+ }
220
+ // (namespace.DPL-UR.URC_0001_Header account) 5000 gas
221
+ // Legacy: getHeaderData removed — replaced by URC_0027_AccountSelectorMapper for header.
222
+ // HeaderV3 is still used by Dashboard (IndexCardsGrid, OuroAccountCard, FirestarterSection).
223
+ export async function getHeaderData(address = "", options) {
224
+ const response = await pactRead(`(${KADENA_NAMESPACE}.DPL-UR.URC_0001_HeaderV3 "${address}")`, { tier: "T6", skipTempWatcher: options?.skipTempWatcher });
225
+ if (!response || !response.result) {
226
+ throw new Error("Failed to retrieve data from the transaction.");
227
+ }
228
+ return response.result?.data || null;
229
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * ouroBalanceFunctions.ts
3
+ * IGNIS / DPTF / OURO-dispo / virtual-OURO balance reads.
4
+ * All four functions use catch-return-null per the v3.0.0 fabricated-fallbacks-removal contract.
5
+ */
6
+ export declare const IGNIS_TOKEN_ID = "GAS-8Nh-JO8JO4F5";
7
+ /**
8
+ * Get IGNIS (GAS) balance for an Ouronet account.
9
+ * Uses DPTF.UR_AccountSupply with the IGNIS token ID.
10
+ *
11
+ * Returns the balance as a decimal string on success, or `null` when the
12
+ * RPC call fails or the chain returns a non-success status. Consumers must
13
+ * distinguish "no balance" (legitimate `"0"` from chain) from "RPC failure"
14
+ * (`null`) — see v3.0.0 fabricated-fallbacks-removal.
15
+ */
16
+ export declare function getIgnisBalance(account: string): Promise<string | null>;
17
+ /**
18
+ * Fetch DPTF token balance for any account via DPTF.UR_AccountSupply
19
+ * (ouronet-ns.DPTF.UR_AccountSupply <token-id> <account>)
20
+ *
21
+ * Returns the balance as a decimal string on success, or `null` when the
22
+ * RPC call fails or the chain returns a non-success status (v3.0.0).
23
+ */
24
+ export declare function getAccountTokenSupply(tokenId: string, account: string): Promise<string | null>;
25
+ /**
26
+ * Fetch OURO dispo capacity for an account via DALOS.UR_DISPOSupply
27
+ *
28
+ * Returns the capacity as a decimal string on success, or `null` when the
29
+ * RPC call fails or the chain returns a non-success status (v3.0.0).
30
+ */
31
+ export declare function getOuroDispoCapacity(account: string): Promise<string | null>;
32
+ /**
33
+ * Fetch Virtual OURO balance for an account
34
+ * (ouronet-ns.TFT.URC_VirtualOuro <account>)
35
+ *
36
+ * Returns the virtual balance as a decimal string on success, or `null` when
37
+ * the RPC call fails or the chain returns a non-success status (v3.0.0).
38
+ */
39
+ export declare function getVirtualOuro(account: string): Promise<string | null>;
@@ -0,0 +1,100 @@
1
+ /**
2
+ * ouroBalanceFunctions.ts
3
+ * IGNIS / DPTF / OURO-dispo / virtual-OURO balance reads.
4
+ * All four functions use catch-return-null per the v3.0.0 fabricated-fallbacks-removal contract.
5
+ */
6
+ import { KADENA_NAMESPACE, TOKEN_ID_IGNIS } from "../constants/index.js";
7
+ import { mayComeWithDeimal } from "@stoachain/stoa-core/pact";
8
+ import { pactRead } from "@stoachain/stoa-core/reads";
9
+ import { getLogger } from "@stoachain/stoa-core/observability";
10
+ export const IGNIS_TOKEN_ID = TOKEN_ID_IGNIS;
11
+ /**
12
+ * Get IGNIS (GAS) balance for an Ouronet account.
13
+ * Uses DPTF.UR_AccountSupply with the IGNIS token ID.
14
+ *
15
+ * Returns the balance as a decimal string on success, or `null` when the
16
+ * RPC call fails or the chain returns a non-success status. Consumers must
17
+ * distinguish "no balance" (legitimate `"0"` from chain) from "RPC failure"
18
+ * (`null`) — see v3.0.0 fabricated-fallbacks-removal.
19
+ */
20
+ // All catch blocks below route via getLogger().error(...) from ../observability (F-CORE-019, v2.3.0)
21
+ export async function getIgnisBalance(account) {
22
+ try {
23
+ const pactCode = `(${KADENA_NAMESPACE}.DPTF.UR_AccountSupply "${IGNIS_TOKEN_ID}" "${account}")`;
24
+ // T1, not T5 — this is a BALANCE read (the canonical tier mapping puts
25
+ // balance reads at T1: high churn, very short TTL). At T5 the patron IGNIS
26
+ // balance stayed stale right after a transfer, falsely blocking spends with
27
+ // "Insufficient IGNIS" until a hard refresh.
28
+ const response = await pactRead(pactCode, { tier: "T1" });
29
+ if (response?.result?.status === "success") {
30
+ return String(mayComeWithDeimal(response.result.data));
31
+ }
32
+ return null;
33
+ }
34
+ catch (error) {
35
+ getLogger().error("Error in getIgnisBalance:", error);
36
+ return null;
37
+ }
38
+ }
39
+ /**
40
+ * Fetch DPTF token balance for any account via DPTF.UR_AccountSupply
41
+ * (ouronet-ns.DPTF.UR_AccountSupply <token-id> <account>)
42
+ *
43
+ * Returns the balance as a decimal string on success, or `null` when the
44
+ * RPC call fails or the chain returns a non-success status (v3.0.0).
45
+ */
46
+ export async function getAccountTokenSupply(tokenId, account) {
47
+ try {
48
+ const pactCode = `(${KADENA_NAMESPACE}.DPTF.UR_AccountSupply "${tokenId}" "${account}")`;
49
+ const response = await pactRead(pactCode, { tier: "T5" });
50
+ if (response?.result?.status === "success") {
51
+ return String(mayComeWithDeimal(response.result.data));
52
+ }
53
+ return null;
54
+ }
55
+ catch (error) {
56
+ getLogger().error("Error in getAccountTokenSupply:", error);
57
+ return null;
58
+ }
59
+ }
60
+ /**
61
+ * Fetch OURO dispo capacity for an account via DALOS.UR_DISPOSupply
62
+ *
63
+ * Returns the capacity as a decimal string on success, or `null` when the
64
+ * RPC call fails or the chain returns a non-success status (v3.0.0).
65
+ */
66
+ export async function getOuroDispoCapacity(account) {
67
+ try {
68
+ const pactCode = `(${KADENA_NAMESPACE}.DALOS.UR_DISPOSupply "${account}")`;
69
+ const response = await pactRead(pactCode, { tier: "T5" });
70
+ if (response?.result?.status === "success") {
71
+ return String(mayComeWithDeimal(response.result.data));
72
+ }
73
+ return null;
74
+ }
75
+ catch (error) {
76
+ getLogger().error("Error in getOuroDispoCapacity:", error);
77
+ return null;
78
+ }
79
+ }
80
+ /**
81
+ * Fetch Virtual OURO balance for an account
82
+ * (ouronet-ns.TFT.URC_VirtualOuro <account>)
83
+ *
84
+ * Returns the virtual balance as a decimal string on success, or `null` when
85
+ * the RPC call fails or the chain returns a non-success status (v3.0.0).
86
+ */
87
+ export async function getVirtualOuro(account) {
88
+ try {
89
+ const pactCode = `(${KADENA_NAMESPACE}.TFT.URC_VirtualOuro "${account}")`;
90
+ const response = await pactRead(pactCode, { tier: "T5" });
91
+ if (response?.result?.status === "success") {
92
+ return String(mayComeWithDeimal(response.result.data));
93
+ }
94
+ return null;
95
+ }
96
+ catch (error) {
97
+ getLogger().error("Error in getVirtualOuro:", error);
98
+ return null;
99
+ }
100
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * ouroCoilFunctions.ts
3
+ * OURO-specific coil/curl execution + verbatim tail-block re-exports of the broader
4
+ * coil/pension/info-one preview surface (locked here because the original tail-block
5
+ * comment "Export new coiling functions for AURYN and WSTOA" places them in the coil domain).
6
+ */
7
+ import type { IKadenaKeypair } from "@stoachain/stoa-core/signing";
8
+ import type { IOuroAccountKeypair } from "./ouroTypes.js";
9
+ export declare function getCoilPreview(ouroAmount: string): Promise<{
10
+ auryn: number;
11
+ fee: number;
12
+ kadenaInfo: {
13
+ text: string;
14
+ discount: number;
15
+ full: number;
16
+ need: number;
17
+ };
18
+ ignisInfo: {
19
+ text: string;
20
+ discount: number;
21
+ full: number;
22
+ need: number;
23
+ };
24
+ preText: string[];
25
+ postText: string[];
26
+ } | null>;
27
+ export declare function curlOuroToEliteAuryn(ouroAccount: IOuroAccountKeypair, kadenaAccount: IKadenaKeypair, guard: IKadenaKeypair, targetAccount: string, // The account that will receive the Elite AURYN (same as patron per client explanation)
28
+ ouroAmount: string): Promise<import("@stoachain/kadena-stoic-legacy/client").ITransactionDescriptor>;
29
+ export { getAurynCoilPreview, coilAurynToElite, getWkdaCoilPreview, coilWkdaToLkda, COIL_CONFIGS } from "./coilFunctions.js";
30
+ export { brumateWkdaToPkda, constrictLkdaToPkda } from "./pensionFunctions.js";
31
+ export { getTransferPreview, getCoilPreviewInfo, getCurlPreviewInfo, getBrumatePreviewInfo, getConstrictPreviewInfo, parseTransferPreview, type TransferPreviewData } from "./infoOneFunctions.js";
32
+ export declare function coilOuroToAuryn(ouroAccount: IOuroAccountKeypair, kadenaAccount: IKadenaKeypair, guard: IKadenaKeypair, targetAccount: string, // The account that will receive the AURYN
33
+ ouroAmount: string): Promise<import("@stoachain/kadena-stoic-legacy/client").ITransactionDescriptor>;