@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
+ /**
2
+ * ouroSubCompressFunctions.ts
3
+ * Sublimate (OURO -> IGNIS) and compress (IGNIS -> OURO) execution + preview/info reads.
4
+ */
5
+ import { calculateAutoGasLimit } from "@stoachain/stoa-core/gas";
6
+ import { KADENA_CHAIN_ID, KADENA_NAMESPACE, STOA_AUTONOMIC_OURONETGASSTATION, KADENA_NETWORK, } from "../constants/index.js";
7
+ import { safeCreationTime, formatDecimalForPact } from "@stoachain/stoa-core/pact";
8
+ import { Pact } from "@stoachain/kadena-stoic-legacy/client";
9
+ import { getFailoverClient } from "@stoachain/stoa-core/network";
10
+ import { universalSignTransaction, fromKeypair } from "@stoachain/stoa-core/signing";
11
+ import { createSigningError, createSimulationError, logDetailedError } from "@stoachain/stoa-core/errors";
12
+ import { pactRead } from "@stoachain/stoa-core/reads";
13
+ import { getLogger } from "@stoachain/stoa-core/observability";
14
+ // Ouro to Ignis
15
+ // (namespace.T201-C2.ORBR|C_Sublimate client target ouro-amount)
16
+ export async function sublimateOuroToIgnis(ouroAccount, kadenaAccount, guard, targetAccount, ouroAmount) {
17
+ const keysetName = `ks`;
18
+ // Ensure amount is formatted as decimal
19
+ const decimalAmount = formatDecimalForPact(ouroAmount);
20
+ let gasLimit = 2000000; // Default gas limit
21
+ const buildTransaction = (gasLimitOverride) => {
22
+ return Pact.builder
23
+ .execution(`(${KADENA_NAMESPACE}.TS01-C2.ORBR|C_Sublimate "${ouroAccount.address}" "${targetAccount}" ${decimalAmount})`)
24
+ .addData(keysetName, {
25
+ keys: [guard.publicKey],
26
+ pred: "keys-all",
27
+ })
28
+ .setMeta({
29
+ senderAccount: STOA_AUTONOMIC_OURONETGASSTATION,
30
+ creationTime: safeCreationTime(),
31
+ chainId: KADENA_CHAIN_ID,
32
+ gasLimit: gasLimitOverride || gasLimit,
33
+ })
34
+ .setNetworkId(KADENA_NETWORK)
35
+ .addSigner(kadenaAccount.publicKey, (withCapability) => [
36
+ withCapability(`${KADENA_NAMESPACE}.DALOS.GAS_PAYER`, "", { int: 0 }, { decimal: "0.0" }),
37
+ ])
38
+ .addSigner(guard.publicKey)
39
+ .createTransaction();
40
+ };
41
+ const { dirtyRead, submit } = getFailoverClient(KADENA_CHAIN_ID);
42
+ // First do a simulation to check gas
43
+ let transaction = buildTransaction();
44
+ const simulation = await dirtyRead(transaction);
45
+ // Check if simulation failed
46
+ if (simulation.result.status === "failure") {
47
+ const error = createSimulationError("OURO to IGNIS sublimation", simulation.result, `Amount: ${decimalAmount} OURO → Target: ${targetAccount}`);
48
+ logDetailedError(error);
49
+ throw error;
50
+ }
51
+ // Check if we need to adjust gas limit
52
+ const requiredGas = simulation.gas;
53
+ if (requiredGas && requiredGas > gasLimit) {
54
+ // Rebuild transaction with adjusted gas limit (20% buffer)
55
+ gasLimit = calculateAutoGasLimit(requiredGas);
56
+ transaction = buildTransaction(gasLimit);
57
+ }
58
+ // Sign the transaction with both keypairs
59
+ try {
60
+ const signedTransaction = await universalSignTransaction(transaction, [
61
+ fromKeypair(kadenaAccount),
62
+ fromKeypair(guard),
63
+ ]);
64
+ // Submit the signed transaction
65
+ const result = await submit(signedTransaction);
66
+ return result;
67
+ }
68
+ catch (originalError) {
69
+ const error = createSigningError("OURO to IGNIS sublimation", originalError, `Signers: ${kadenaAccount.publicKey.slice(0, 8)}... (payer), ${guard.publicKey.slice(0, 8)}... (guard)`);
70
+ logDetailedError(error);
71
+ throw error;
72
+ }
73
+ }
74
+ // Ignis to Ouro is mainly the same as sublimateOuroToIgnis but has no target
75
+ // ORBR|C_Compress:decimal (client:string ignis-amount:decimal)
76
+ export async function compressIgnisToOuro(ouroAccount, kadenaAccount, guard, ignisAmount) {
77
+ const keysetName = `ks`;
78
+ // Ensure amount is formatted as decimal
79
+ const decimalAmount = formatDecimalForPact(ignisAmount);
80
+ let gasLimit = 2000000; // Default gas limit
81
+ const buildTransaction = (gasLimitOverride) => {
82
+ return Pact.builder
83
+ .execution(`(${KADENA_NAMESPACE}.TS01-C2.ORBR|C_Compress "${ouroAccount.address}" ${decimalAmount})`)
84
+ .addData(keysetName, {
85
+ keys: [guard.publicKey],
86
+ pred: "keys-all",
87
+ })
88
+ .setMeta({
89
+ senderAccount: STOA_AUTONOMIC_OURONETGASSTATION,
90
+ creationTime: safeCreationTime(),
91
+ chainId: KADENA_CHAIN_ID,
92
+ gasLimit: gasLimitOverride || gasLimit,
93
+ })
94
+ .setNetworkId(KADENA_NETWORK)
95
+ .addSigner(kadenaAccount.publicKey, (withCapability) => [
96
+ withCapability(`${KADENA_NAMESPACE}.DALOS.GAS_PAYER`, "", { int: 0 }, { decimal: "0.0" }),
97
+ ])
98
+ .addSigner(guard.publicKey)
99
+ .createTransaction();
100
+ };
101
+ const { dirtyRead, submit } = getFailoverClient(KADENA_CHAIN_ID);
102
+ // First do a simulation to check gas
103
+ let transaction = buildTransaction();
104
+ const simulation = await dirtyRead(transaction);
105
+ // Check if simulation failed
106
+ if (simulation.result.status === "failure") {
107
+ const errorMessage = simulation.result.error?.message || "Transaction simulation failed";
108
+ throw new Error(`Simulation failed: ${errorMessage}`);
109
+ }
110
+ // Check if we need to adjust gas limit
111
+ const requiredGas = simulation.gas;
112
+ if (requiredGas && requiredGas > gasLimit) {
113
+ // Rebuild transaction with adjusted gas limit (20% buffer)
114
+ gasLimit = calculateAutoGasLimit(requiredGas);
115
+ transaction = buildTransaction(gasLimit);
116
+ }
117
+ // Sign the transaction with both keypairs
118
+ const signedTransaction = await universalSignTransaction(transaction, [
119
+ fromKeypair(kadenaAccount),
120
+ fromKeypair(guard),
121
+ ]);
122
+ // Submit the signed transaction
123
+ const result = await submit(signedTransaction);
124
+ return result;
125
+ }
126
+ // Get IGNIS generation preview for sublimation
127
+ // (namespace.OUROBOROS.URC_Sublimate ouro-amount)
128
+ export async function getSublimatPreview(ouroAmount) {
129
+ try {
130
+ const decimalAmount = formatDecimalForPact(ouroAmount);
131
+ const response = await pactRead(`(${KADENA_NAMESPACE}.OUROBOROS.URC_Sublimate (at 0 (${KADENA_NAMESPACE}.U|ATS.UC_PromilleSplit 10.0 ${decimalAmount} 24)))`, { tier: "T2" });
132
+ if (!response || !response.result || response.result.status === "failure") {
133
+ return null;
134
+ }
135
+ const data = response.result.data;
136
+ return {
137
+ ignis: data,
138
+ fee: 0,
139
+ };
140
+ }
141
+ catch (error) {
142
+ getLogger().error("Error getting sublimate preview:", error);
143
+ return null;
144
+ }
145
+ }
146
+ // getCompressPreview
147
+ // (at 0 (ouronet-ns.OUROBOROS.URC_Compress ignis-amount))
148
+ export async function getCompressPreview(ignisAmount) {
149
+ try {
150
+ const decimalAmount = formatDecimalForPact(ignisAmount);
151
+ const response = await pactRead(`(at 0 (${KADENA_NAMESPACE}.OUROBOROS.URC_Compress ${decimalAmount}))`, { tier: "T2" });
152
+ if (!response || !response.result || response.result.status === "failure") {
153
+ return null;
154
+ }
155
+ const data = response.result.data;
156
+ if (!data?.decimal) {
157
+ return null;
158
+ }
159
+ return {
160
+ ouro: parseFloat(data.decimal),
161
+ fee: 0,
162
+ };
163
+ }
164
+ catch (error) {
165
+ getLogger().error("Error getting compress preview:", error);
166
+ return null;
167
+ }
168
+ }
169
+ /**
170
+ * @deprecated Use `getSublimateInfo` from `@ouronet/ouronet-core/interactions/infoOneFunctions` instead.
171
+ * This compat shim accepts the legacy (patron, resident, amount-as-string) signature and forwards to the canonical
172
+ * (client, target, amount-as-number) form. Will be removed in v4.2.0.
173
+ */
174
+ export async function getSublimateInfo(a, b, c) {
175
+ const { getSublimateInfo: canonical } = await import("./infoOneFunctions");
176
+ return canonical(a, b, typeof c === "string" ? Number(c) : c);
177
+ }
178
+ export async function getCompressInfo(client, amount) {
179
+ try {
180
+ const decimalAmount = formatDecimalForPact(amount);
181
+ const pactCode = `(${KADENA_NAMESPACE}.INFO-ONE.ORBR|INFO_Compress "${client}" ${decimalAmount})`;
182
+ const response = await pactRead(pactCode, { tier: "T2" });
183
+ if (response?.result?.status === "success")
184
+ return response.result.data;
185
+ return null;
186
+ }
187
+ catch (error) {
188
+ getLogger().error("Error in getCompressInfo:", error);
189
+ return null;
190
+ }
191
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * ouroTransferFunctions.ts
3
+ * Single-token DPTF transfer execution via TS01-C1.DPTF|C_Transfer.
4
+ */
5
+ import type { IKadenaKeypair } from "@stoachain/stoa-core/signing";
6
+ import type { IOuroAccountKeypair } from "./ouroTypes.js";
7
+ export declare function transferToken(patronAccount: IOuroAccountKeypair, // The patron account (owner)
8
+ tokenId: string, // Token ID
9
+ senderAccount: string, // Sender Ouro address (usually same as patron)
10
+ receiverAccount: string, // Receiver Ouro address
11
+ transferAmount: string, // Amount to transfer
12
+ method: boolean, // false for standard accounts, true for smart accounts
13
+ kadenaAccount: IKadenaKeypair, // The kadena account (payer)
14
+ guardAccount: IKadenaKeypair): Promise<import("@stoachain/kadena-stoic-legacy/client").ITransactionDescriptor>;
@@ -0,0 +1,87 @@
1
+ /**
2
+ * ouroTransferFunctions.ts
3
+ * Single-token DPTF transfer execution via TS01-C1.DPTF|C_Transfer.
4
+ */
5
+ import { calculateAutoGasLimit } from "@stoachain/stoa-core/gas";
6
+ import { KADENA_CHAIN_ID, KADENA_NAMESPACE, STOA_AUTONOMIC_OURONETGASSTATION, KADENA_NETWORK, } from "../constants/index.js";
7
+ import { safeCreationTime, formatDecimalForPact } from "@stoachain/stoa-core/pact";
8
+ import { Pact } from "@stoachain/kadena-stoic-legacy/client";
9
+ import { getFailoverClient } from "@stoachain/stoa-core/network";
10
+ import { universalSignTransaction, fromKeypair } from "@stoachain/stoa-core/signing";
11
+ // Single Token Transfer
12
+ // (namespace.TS01-C1.DPTF|C_Transfer patron id sender receiver transfer-amount method)
13
+ export async function transferToken(patronAccount, // The patron account (owner)
14
+ tokenId, // Token ID
15
+ senderAccount, // Sender Ouro address (usually same as patron)
16
+ receiverAccount, // Receiver Ouro address
17
+ transferAmount, // Amount to transfer
18
+ method, // false for standard accounts, true for smart accounts
19
+ kadenaAccount, // The kadena account (payer)
20
+ guardAccount // The guard account from the Ouro account
21
+ ) {
22
+ // Ensure amount is formatted as decimal
23
+ const decimalAmount = formatDecimalForPact(transferAmount);
24
+ let gasLimit = 2000000; // Default gas limit for transfer operation
25
+ const buildTransaction = (gasLimitOverride) => {
26
+ return Pact.builder
27
+ .execution(`(${KADENA_NAMESPACE}.TS01-C1.DPTF|C_Transfer "${patronAccount.address}" "${tokenId}" "${senderAccount}" "${receiverAccount}" ${decimalAmount} ${method})`)
28
+ .setMeta({
29
+ senderAccount: STOA_AUTONOMIC_OURONETGASSTATION,
30
+ creationTime: safeCreationTime(),
31
+ chainId: KADENA_CHAIN_ID,
32
+ gasLimit: gasLimitOverride || gasLimit,
33
+ })
34
+ .setNetworkId(KADENA_NETWORK)
35
+ .addSigner(kadenaAccount.publicKey, (withCapability) => [
36
+ withCapability(`${KADENA_NAMESPACE}.DALOS.GAS_PAYER`, "", { int: 0 }, { decimal: "0.0" }),
37
+ ])
38
+ .addSigner(guardAccount.publicKey)
39
+ .createTransaction();
40
+ };
41
+ const { dirtyRead, submit } = getFailoverClient(KADENA_CHAIN_ID);
42
+ // First do a simulation to check gas
43
+ let transaction = buildTransaction();
44
+ let simulation = await dirtyRead(transaction);
45
+ // Check if simulation failed due to gas limit exceeded
46
+ if (simulation.result.status === "failure") {
47
+ const errorMessage = simulation.result.error?.message || "";
48
+ // Check if it's a gas limit exceeded error
49
+ if (errorMessage.includes("Gas limit") && errorMessage.includes("exceeded")) {
50
+ // Extract the required gas from error message or use a higher limit
51
+ const gasMatch = errorMessage.match(/exceeded:\s*(\d+)/);
52
+ if (gasMatch) {
53
+ const requiredGas = parseInt(gasMatch[1]);
54
+ gasLimit = calculateAutoGasLimit(requiredGas); // 20% buffer
55
+ // Rebuild and retry simulation with higher gas limit
56
+ transaction = buildTransaction(gasLimit);
57
+ simulation = await dirtyRead(transaction);
58
+ }
59
+ else {
60
+ // If we can't extract exact gas, increase by 50%
61
+ gasLimit = Math.ceil(gasLimit * 1.5);
62
+ transaction = buildTransaction(gasLimit);
63
+ simulation = await dirtyRead(transaction);
64
+ }
65
+ }
66
+ // If still failing after retry, throw error
67
+ if (simulation.result.status === "failure") {
68
+ const finalErrorMessage = simulation.result.error?.message || "Transaction simulation failed";
69
+ throw new Error(`Simulation failed: ${finalErrorMessage}`);
70
+ }
71
+ }
72
+ // Check if we need to adjust gas limit further (normal case)
73
+ const requiredGas = simulation.gas;
74
+ if (requiredGas && requiredGas > gasLimit) {
75
+ // Rebuild transaction with adjusted gas limit (20% buffer)
76
+ gasLimit = calculateAutoGasLimit(requiredGas);
77
+ transaction = buildTransaction(gasLimit);
78
+ }
79
+ // Sign the transaction with both keypairs
80
+ const signedTransaction = await universalSignTransaction(transaction, [
81
+ fromKeypair(kadenaAccount),
82
+ fromKeypair(guardAccount),
83
+ ]);
84
+ // Submit the signed transaction
85
+ const result = await submit(signedTransaction);
86
+ return result;
87
+ }
@@ -0,0 +1,113 @@
1
+ /**
2
+ * ouroTypes.ts
3
+ * Cross-cutting interface and type-alias definitions for the ouro entity files.
4
+ * Sole non-local re-export: IKadenaKeypair from @stoachain/stoa-core/signing.
5
+ */
6
+ export type { IKadenaKeypair } from "@stoachain/stoa-core/signing";
7
+ import type { IKadenaKeypair } from "@stoachain/stoa-core/signing";
8
+ export interface AccountSelectorData {
9
+ readonly "iz-activated": boolean;
10
+ readonly "ouronet-account": string;
11
+ readonly "ouronet-account-guard": any;
12
+ readonly "iz-smart": boolean | number;
13
+ readonly "ouro-balance": number;
14
+ readonly "ignis-balance": number;
15
+ readonly "payment-key-existance": boolean;
16
+ readonly "payment-key": string;
17
+ readonly "payment-key-balance": number;
18
+ readonly "payment-key-guard": any;
19
+ readonly "ignis-discount": any;
20
+ readonly "stoa-discount": any;
21
+ /**
22
+ * On-chain public key for the account — the long base-49 string in the
23
+ * DALOS `{prefixLenBase49}.{xyBase49}` format. Populated for both
24
+ * Standard (Ѻ.) and Smart (Σ.) accounts. **This is the on-chain source
25
+ * of truth** and is expected to match the codex-stored `publicKey` for
26
+ * any account created through the standard flow. A mismatch would
27
+ * indicate either (a) an admin-level key rotation performed on chain
28
+ * (designed as a last-resort correction tool), or (b) a corrupted
29
+ * codex entry. Added in ouronet-core v1.4.0 alongside the
30
+ * `URC_0027_AccountSelectorMapper` Pact-side extension.
31
+ */
32
+ readonly "public-key": string;
33
+ /**
34
+ * Sovereign — only populated for Smart accounts (iz-smart = true). The
35
+ * Ѻ. Standard Ouronet Account that has sovereignty over this Smart
36
+ * account; proving ownership of the sovereign proves ownership of the
37
+ * Smart account's `sovereign` authorization path. Pact returns `false`
38
+ * for Standard accounts and unactivated accounts. Added in v1.4.0.
39
+ */
40
+ readonly "sovereign": string | false;
41
+ /**
42
+ * Governor — only populated for Smart accounts. A Pact guard used for
43
+ * complex custom authorization logic (capability guards, module guards,
44
+ * user guards, or additional keyset arrangements). For Smart accounts
45
+ * where no custom governor has been set, this equals the account's own
46
+ * `ouronet-account-guard`. Pact returns `false` for Standard accounts
47
+ * and unactivated accounts. Added in v1.4.0.
48
+ */
49
+ readonly "governor": any | false;
50
+ /**
51
+ * Stoic Tag — the human-readable alias attached to this Ouronet account.
52
+ * `stoic-tag-has` true when the account has an active tag.
53
+ * `stoic-tag` the tag name, or the literal sentinel
54
+ * "No StoicTag yet" when none. Consumers MUST
55
+ * gate on `stoic-tag-has`, never the string.
56
+ * `stoic-tag-registered-at` block time at registration; `false` if none.
57
+ */
58
+ readonly "stoic-tag-has": boolean;
59
+ readonly "stoic-tag": string;
60
+ readonly "stoic-tag-registered-at": unknown;
61
+ }
62
+ /**
63
+ * Inverse StoicTag read — one row per queried tag name, from
64
+ * `URC_0027c_StoicTagSelectorSingle` (and the batch `URC_0027b_…Mapper`).
65
+ * Powers Address Book StoicTag entries, which watch a tag independently of
66
+ * any codex account.
67
+ */
68
+ export interface StoicTagSelectorData {
69
+ readonly "stoic-tag": string;
70
+ readonly "iz-row-exists": boolean;
71
+ readonly "iz-active": boolean;
72
+ readonly "iz-released": boolean;
73
+ readonly "iz-never-registered": boolean;
74
+ readonly "ouronet-account": string;
75
+ readonly "registered-at": unknown;
76
+ }
77
+ export interface StoaAccountSelectorData {
78
+ readonly "iz-activated": boolean;
79
+ readonly "account": string;
80
+ readonly "balance": number;
81
+ readonly "guard": any;
82
+ }
83
+ export interface AccountOverviewData {
84
+ readonly "global-administrative-pause": boolean;
85
+ readonly "iz-selected-activated": boolean;
86
+ readonly "stoa-costs": number;
87
+ }
88
+ export interface IOuroAccountKeypair {
89
+ readonly address: string;
90
+ readonly publicKey: string;
91
+ readonly privateKey?: string;
92
+ }
93
+ export interface UnwrapStoaParams {
94
+ readonly patronAddress: string;
95
+ readonly unwrapperAddress: string;
96
+ readonly amount: string;
97
+ readonly numAmount: number;
98
+ readonly targetAddress: string;
99
+ readonly targetExists: boolean;
100
+ readonly gasStationKey: IKadenaKeypair;
101
+ readonly patronGuardKeys: IKadenaKeypair[];
102
+ readonly accountGuardKeys: IKadenaKeypair[];
103
+ }
104
+ export interface UnwrapUrStoaParams {
105
+ readonly patronAddress: string;
106
+ readonly unwrapperAddress: string;
107
+ readonly amount: string;
108
+ readonly targetAddress: string;
109
+ readonly targetExists: boolean;
110
+ readonly gasStationKey: IKadenaKeypair;
111
+ readonly patronGuardKeys: IKadenaKeypair[];
112
+ readonly accountGuardKeys: IKadenaKeypair[];
113
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * ouroTypes.ts
3
+ * Cross-cutting interface and type-alias definitions for the ouro entity files.
4
+ * Sole non-local re-export: IKadenaKeypair from @stoachain/stoa-core/signing.
5
+ */
6
+ export {};
@@ -0,0 +1,16 @@
1
+ /**
2
+ * ouroUrStoaFunctions.ts
3
+ * UrStoa account-existence probe, unwrap-info read, and unwrap execution (parallel to UnwrapStoa).
4
+ */
5
+ import type { UnwrapUrStoaParams } from "./ouroTypes.js";
6
+ /**
7
+ * Check if an account exists in the UrStoa table.
8
+ * (if (= (typeof (try false (coin.UR_UR|Balance "<address>"))) "bool") false true)
9
+ */
10
+ export declare function checkUrStoaAccountExists(address: string): Promise<boolean | null>;
11
+ /**
12
+ * Get INFO for UnwrapUrStoa function.
13
+ * (ouronet-ns.INFO-ONE.LIQUID|INFO_UnwrapUrStoa <patron> <wrapper> <amount:decimal>)
14
+ */
15
+ export declare function getUnwrapUrStoaInfo(patron: string, wrapper: string, amount: string): Promise<any | null>;
16
+ export declare function executeUnwrapUrStoa(params: UnwrapUrStoaParams): Promise<any>;
@@ -0,0 +1,121 @@
1
+ /**
2
+ * ouroUrStoaFunctions.ts
3
+ * UrStoa account-existence probe, unwrap-info read, and unwrap execution (parallel to UnwrapStoa).
4
+ */
5
+ import { calculateAutoGasLimit } from "@stoachain/stoa-core/gas";
6
+ import { KADENA_CHAIN_ID, KADENA_NAMESPACE, STOA_AUTONOMIC_OURONETGASSTATION, KADENA_NETWORK, } from "../constants/index.js";
7
+ import { safeCreationTime, formatDecimalForPact } from "@stoachain/stoa-core/pact";
8
+ import { Pact } from "@stoachain/kadena-stoic-legacy/client";
9
+ import { getFailoverClient } from "@stoachain/stoa-core/network";
10
+ import { universalSignTransaction, fromKeypair } from "@stoachain/stoa-core/signing";
11
+ import { createSimulationError, logDetailedError } from "@stoachain/stoa-core/errors";
12
+ import { pactRead } from "@stoachain/stoa-core/reads";
13
+ import { getLogger } from "@stoachain/stoa-core/observability";
14
+ // ─── Unwrap UrStoa ────────────────────────────────────────────────────────────
15
+ /**
16
+ * Check if an account exists in the UrStoa table.
17
+ * (if (= (typeof (try false (coin.UR_UR|Balance "<address>"))) "bool") false true)
18
+ */
19
+ export async function checkUrStoaAccountExists(address) {
20
+ try {
21
+ const pactCode = `(if (= (typeof (try false (coin.UR_UR|Balance "${address}"))) "bool") false true)`;
22
+ const response = await pactRead(pactCode, { tier: "T3" });
23
+ const data = response?.result?.data;
24
+ if (data === true)
25
+ return true;
26
+ if (data === false)
27
+ return false;
28
+ return null;
29
+ }
30
+ catch (error) {
31
+ getLogger().error("Error checking UrStoa account:", error);
32
+ return null;
33
+ }
34
+ }
35
+ /**
36
+ * Get INFO for UnwrapUrStoa function.
37
+ * (ouronet-ns.INFO-ONE.LIQUID|INFO_UnwrapUrStoa <patron> <wrapper> <amount:decimal>)
38
+ */
39
+ export async function getUnwrapUrStoaInfo(patron, wrapper, amount) {
40
+ try {
41
+ const decimalAmount = formatDecimalForPact(amount);
42
+ const pactCode = `(${KADENA_NAMESPACE}.INFO-ONE.LIQUID|INFO_UnwrapUrStoa "${patron}" "${wrapper}" ${decimalAmount})`;
43
+ const response = await pactRead(pactCode, { tier: "T2" });
44
+ if (response?.result?.status === "success") {
45
+ return response.result.data;
46
+ }
47
+ return null;
48
+ }
49
+ catch (error) {
50
+ getLogger().error("Error getting UnwrapUrStoa info:", error);
51
+ return null;
52
+ }
53
+ }
54
+ // ─── executeUnwrapUrStoa ──────────────────────────────────────────────────────
55
+ // Handles both cases:
56
+ // target exists → simple unwrap via C_UnwrapUrStoa
57
+ // target new k: → create UrStoa account + unwrap
58
+ export async function executeUnwrapUrStoa(params) {
59
+ const { patronAddress, unwrapperAddress, amount, targetAddress, targetExists, gasStationKey, patronGuardKeys, accountGuardKeys, } = params;
60
+ const allSigners = [gasStationKey];
61
+ const addedPubs = new Set([gasStationKey.publicKey]);
62
+ for (const k of [...patronGuardKeys, ...accountGuardKeys]) {
63
+ if (!addedPubs.has(k.publicKey)) {
64
+ allSigners.push(k);
65
+ addedPubs.add(k.publicKey);
66
+ }
67
+ }
68
+ let gasLimit = 2000000;
69
+ const buildTransaction = (gasLimitOverride) => {
70
+ const effectiveGasLimit = gasLimitOverride ?? gasLimit;
71
+ let builder = targetExists
72
+ ? Pact.builder.execution(`(${KADENA_NAMESPACE}.TS01-C2.LQD|C_UnwrapUrStoa "${patronAddress}" "${unwrapperAddress}" ${amount})`)
73
+ : Pact.builder
74
+ .execution(`(namespace "${KADENA_NAMESPACE}")\n` +
75
+ `(IGNIS.C_Collect "${patronAddress}" (IGNIS.UDC_CustomCodeCumulator))\n` +
76
+ `(let\n` +
77
+ ` (\n` +
78
+ ` (wp:string "${unwrapperAddress}")\n` +
79
+ ` (target:string (DALOS.UR_AccountKadena wp))\n` +
80
+ ` )\n` +
81
+ ` [\n` +
82
+ ` (coin.C_UR|CreateAccount target (read-keyset "ks"))\n` +
83
+ ` (TS01-C2.LQD|C_UnwrapUrStoa "${patronAddress}" "${unwrapperAddress}" ${amount})\n` +
84
+ ` ]\n` +
85
+ `)`)
86
+ .addData("ks", {
87
+ keys: [targetAddress.slice(2)],
88
+ pred: "keys-all",
89
+ });
90
+ builder = builder
91
+ .setMeta({ senderAccount: STOA_AUTONOMIC_OURONETGASSTATION, chainId: KADENA_CHAIN_ID, creationTime: safeCreationTime(),
92
+ gasLimit: effectiveGasLimit })
93
+ .setNetworkId(KADENA_NETWORK)
94
+ .addSigner(gasStationKey.publicKey, (w) => [
95
+ w(`${KADENA_NAMESPACE}.DALOS.GAS_PAYER`, "", { int: 0 }, { decimal: "0.0" }),
96
+ ]);
97
+ const addedSignerPubs = new Set([gasStationKey.publicKey]);
98
+ for (const k of [...patronGuardKeys, ...accountGuardKeys]) {
99
+ if (!addedSignerPubs.has(k.publicKey)) {
100
+ builder = builder.addSigner(k.publicKey);
101
+ addedSignerPubs.add(k.publicKey);
102
+ }
103
+ }
104
+ return builder.createTransaction();
105
+ };
106
+ const { dirtyRead, submit } = getFailoverClient(KADENA_CHAIN_ID);
107
+ let transaction = buildTransaction();
108
+ const simulation = await dirtyRead(transaction);
109
+ if (simulation.result.status === "failure") {
110
+ const error = createSimulationError("Unwrap UrStoa", simulation.result, `Patron: ${patronAddress} | Unwrapper: ${unwrapperAddress} | Target: ${targetAddress} | Amount: ${amount}`);
111
+ logDetailedError(error);
112
+ throw error;
113
+ }
114
+ const requiredGas = simulation.gas;
115
+ if (requiredGas) {
116
+ gasLimit = calculateAutoGasLimit(requiredGas);
117
+ transaction = buildTransaction(gasLimit);
118
+ }
119
+ const signed = await universalSignTransaction(transaction, allSigners.map((s) => fromKeypair(s)));
120
+ return await submit(signed);
121
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * ouroWrapFunctions.ts
3
+ * KDA wrap/unwrap and unwrap-stoa execution + supporting reads.
4
+ */
5
+ import type { IKadenaKeypair } from "@stoachain/stoa-core/signing";
6
+ import type { IOuroAccountKeypair, UnwrapStoaParams } from "./ouroTypes.js";
7
+ export declare function wrapKadena(patronAccount: IOuroAccountKeypair, wrapperAccount: string, // Ouro address that will receive the wrapped KDA
8
+ kadenaAccount: IKadenaKeypair, // The kadena account that will transfer KDA
9
+ guardAccount: IKadenaKeypair, // The guard account from the Ouro account
10
+ amount: string): Promise<import("@stoachain/kadena-stoic-legacy/client").ITransactionDescriptor>;
11
+ export declare function unwrapKadena(patronAccount: IOuroAccountKeypair, // Ouro account that owns the WSTOA
12
+ unwrapperAccount: string, // Ouro address that will receive the unwrapped KDA
13
+ kadenaAccount: IKadenaKeypair, // The kadena account (payer)
14
+ guardAccount: IKadenaKeypair, // The guard account from the Ouro account
15
+ amount: string): Promise<import("@stoachain/kadena-stoic-legacy/client").ITransactionDescriptor>;
16
+ /**
17
+ * Resolve the target Kadena address for an Ouronet unwrapper account.
18
+ * (ouronet-ns.DALOS.UR_AccountKadena <unwrapper>)
19
+ */
20
+ export declare function getUnwrapStoaTarget(unwrapper: string): Promise<string | null>;
21
+ export declare function getUnwrapStoaInfo(patron: string, unwrapper: string, amount: string): Promise<any | null>;
22
+ export declare function executeUnwrapStoa(params: UnwrapStoaParams): Promise<any>;