@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,221 @@
1
+ /**
2
+ * wrapFunctions.ts
3
+ * On-chain interactions for C_WrapStoa (ouronet-ns.TS01-C2.LQD)
4
+ */
5
+ import { Pact } from "@stoachain/kadena-stoic-legacy/client";
6
+ import { getFailoverClient } from "@stoachain/stoa-core/network";
7
+ import { calculateAutoGasLimit } from "@stoachain/stoa-core/gas";
8
+ import { KADENA_CHAIN_ID, KADENA_NAMESPACE, KADENA_NETWORK, STOA_AUTONOMIC_OURONETGASSTATION, STOA_AUTONOMIC_LIQUIDPOT, } from "../constants/index.js";
9
+ import { formatDecimalForPact, safeCreationTime } from "@stoachain/stoa-core/pact";
10
+ import { pactRead } from "@stoachain/stoa-core/reads";
11
+ import { universalSignTransaction, fromKeypair } from "@stoachain/stoa-core/signing";
12
+ import { createSimulationError, logDetailedError } from "@stoachain/stoa-core/errors";
13
+ import { getLogger } from "@stoachain/stoa-core/observability";
14
+ // ─── INFO ─────────────────────────────────────────────────────────────────────
15
+ /**
16
+ * (ouronet-ns.INFO-ONE.LIQUID|INFO_WrapStoa <patron:string> <wrapper:string> <amount:decimal>)
17
+ * Returns cost info: ignis, kadena, pre-text, post-text, etc.
18
+ */
19
+ export async function getWrapStoaInfo(patron, wrapper, amount) {
20
+ try {
21
+ const decimalAmount = formatDecimalForPact(amount);
22
+ const pactCode = `(${KADENA_NAMESPACE}.INFO-ONE.LIQUID|INFO_WrapStoa "${patron}" "${wrapper}" ${decimalAmount})`;
23
+ const response = await pactRead(pactCode, { tier: "T2" });
24
+ if (response?.result?.status === "success") {
25
+ return response.result.data;
26
+ }
27
+ return null;
28
+ }
29
+ catch (error) {
30
+ getLogger().error("Error getting WrapStoa info:", error);
31
+ return null;
32
+ }
33
+ }
34
+ // ─── Resolve wrapper's payment key address ────────────────────────────────────
35
+ /**
36
+ * (ouronet-ns.DALOS.UR_AccountKadena <wrapper>) → k: address (payment key)
37
+ */
38
+ export async function getWrapperPaymentKey(wrapper) {
39
+ try {
40
+ const pactCode = `(${KADENA_NAMESPACE}.DALOS.UR_AccountKadena "${wrapper}")`;
41
+ const response = await pactRead(pactCode, { tier: "T5" });
42
+ if (response?.result?.status === "success") {
43
+ return String(response.result.data);
44
+ }
45
+ return null;
46
+ }
47
+ catch (error) {
48
+ getLogger().error("Error resolving wrapper payment key:", error);
49
+ return null;
50
+ }
51
+ }
52
+ // ─── Get STOA balance of payment key ─────────────────────────────────────────
53
+ /**
54
+ * (coin.get-balance <paymentKeyAddress>) → decimal balance
55
+ */
56
+ export async function getPaymentKeyBalance(paymentKeyAddress) {
57
+ try {
58
+ const pactCode = `(try 0.0 (coin.get-balance "${paymentKeyAddress}"))`;
59
+ const response = await pactRead(pactCode, { tier: "T1" });
60
+ if (response?.result?.status === "success") {
61
+ const data = response.result.data;
62
+ if (typeof data === "number")
63
+ return data;
64
+ if (data?.decimal !== undefined)
65
+ return parseFloat(data.decimal);
66
+ return parseFloat(String(data));
67
+ }
68
+ return null;
69
+ }
70
+ catch (error) {
71
+ getLogger().error("Error fetching payment key balance:", error);
72
+ return null;
73
+ }
74
+ }
75
+ export async function executeWrapStoa(params) {
76
+ const { patronAddress, wrapperAddress, amount, numAmount, paymentKeyAddress, gasStationKey, paymentSignerKey, patronGuardKeys, wrapperGuardKeys, } = params;
77
+ const buildTransaction = (gasLimitOverride) => {
78
+ let builder = Pact.builder
79
+ .execution(`(${KADENA_NAMESPACE}.TS01-C2.LQD|C_WrapStoa "${patronAddress}" "${wrapperAddress}" ${amount})`)
80
+ .setMeta({
81
+ senderAccount: STOA_AUTONOMIC_OURONETGASSTATION,
82
+ creationTime: safeCreationTime(),
83
+ chainId: KADENA_CHAIN_ID,
84
+ gasLimit: gasLimitOverride ?? 2000000,
85
+ })
86
+ .setNetworkId(KADENA_NETWORK)
87
+ // GAS_PAYER — CodexPrime Key #0
88
+ .addSigner(gasStationKey.publicKey, (w) => [
89
+ w(`${KADENA_NAMESPACE}.DALOS.GAS_PAYER`, "", { int: 0 }, { decimal: "0.0" }),
90
+ ]);
91
+ // coin.TRANSFER — payment key signer
92
+ // If same key as gas station, add TRANSFER cap to existing signer,
93
+ // otherwise add new signer with TRANSFER cap
94
+ if (paymentSignerKey.publicKey === gasStationKey.publicKey) {
95
+ // Edge case: payment key IS CodexPrime Key #0 — rebuild with both caps on same key
96
+ builder = Pact.builder
97
+ .execution(`(${KADENA_NAMESPACE}.TS01-C2.LQD|C_WrapStoa "${patronAddress}" "${wrapperAddress}" ${amount})`)
98
+ .setMeta({
99
+ senderAccount: STOA_AUTONOMIC_OURONETGASSTATION,
100
+ creationTime: safeCreationTime(),
101
+ chainId: KADENA_CHAIN_ID,
102
+ gasLimit: gasLimitOverride ?? 2000000,
103
+ })
104
+ .setNetworkId(KADENA_NETWORK)
105
+ .addSigner(gasStationKey.publicKey, (w) => [
106
+ w(`${KADENA_NAMESPACE}.DALOS.GAS_PAYER`, "", { int: 0 }, { decimal: "0.0" }),
107
+ w("coin.TRANSFER", paymentKeyAddress, STOA_AUTONOMIC_LIQUIDPOT, { decimal: String(numAmount) }),
108
+ ]);
109
+ }
110
+ else {
111
+ builder = builder.addSigner(paymentSignerKey.publicKey, (w) => [
112
+ w("coin.TRANSFER", paymentKeyAddress, STOA_AUTONOMIC_LIQUIDPOT, { decimal: String(numAmount) }),
113
+ ]);
114
+ }
115
+ // Pure guard signers (patron + wrapper) — no capabilities
116
+ const addedPubs = new Set([gasStationKey.publicKey, paymentSignerKey.publicKey]);
117
+ for (const k of [...patronGuardKeys, ...wrapperGuardKeys]) {
118
+ if (!addedPubs.has(k.publicKey)) {
119
+ builder = builder.addSigner(k.publicKey);
120
+ addedPubs.add(k.publicKey);
121
+ }
122
+ }
123
+ return builder.createTransaction();
124
+ };
125
+ const { dirtyRead, submit } = getFailoverClient(KADENA_CHAIN_ID);
126
+ // 1. Simulate with 2M (network max)
127
+ const simTx = buildTransaction();
128
+ const simulation = await dirtyRead(simTx);
129
+ if (simulation.result.status === "failure") {
130
+ const error = createSimulationError("Wrap STOA", simulation.result, `Patron: ${patronAddress} | Wrapper: ${wrapperAddress} | Amount: ${amount} | PaymentKey: ${paymentKeyAddress}`);
131
+ logDetailedError(error);
132
+ throw error;
133
+ }
134
+ // 2. Adaptive gas
135
+ const gasLimit = simulation.gas ? calculateAutoGasLimit(simulation.gas) : 2000000;
136
+ const finalTx = buildTransaction(gasLimit);
137
+ // 3. Collect all unique signers
138
+ const allSigners = [gasStationKey];
139
+ const seenPubs = new Set([gasStationKey.publicKey]);
140
+ for (const k of [paymentSignerKey, ...patronGuardKeys, ...wrapperGuardKeys]) {
141
+ if (!seenPubs.has(k.publicKey)) {
142
+ allSigners.push(k);
143
+ seenPubs.add(k.publicKey);
144
+ }
145
+ }
146
+ // 4. Sign & submit
147
+ const signed = await universalSignTransaction(finalTx, allSigners.map((s) => fromKeypair(s)));
148
+ return await submit(signed);
149
+ }
150
+ // ─── INFO UrStoa ──────────────────────────────────────────────────────────────
151
+ /**
152
+ * (ouronet-ns.INFO-ONE.LIQUID|INFO_WrapUrStoa <patron:string> <wrapper:string> <amount:decimal>)
153
+ * Returns cost info: ignis, kadena, pre-text, post-text, etc.
154
+ */
155
+ export async function getWrapUrStoaInfo(patron, wrapper, amount) {
156
+ try {
157
+ const decimalAmount = formatDecimalForPact(amount);
158
+ const pactCode = `(${KADENA_NAMESPACE}.INFO-ONE.LIQUID|INFO_WrapUrStoa "${patron}" "${wrapper}" ${decimalAmount})`;
159
+ const response = await pactRead(pactCode, { tier: "T2" });
160
+ if (response?.result?.status === "success") {
161
+ return response.result.data;
162
+ }
163
+ return null;
164
+ }
165
+ catch (error) {
166
+ getLogger().error("Error getting WrapUrStoa info:", error);
167
+ return null;
168
+ }
169
+ }
170
+ export async function executeWrapUrStoa(params) {
171
+ const { patronAddress, wrapperAddress, amount, numAmount, paymentKeyAddress, gasStationKey, patronGuardKeys, wrapperGuardKeys, } = params;
172
+ const buildTransaction = (gasLimitOverride) => {
173
+ let builder = Pact.builder
174
+ .execution(`(${KADENA_NAMESPACE}.TS01-C2.LQD|C_WrapUrStoa "${patronAddress}" "${wrapperAddress}" ${amount})`)
175
+ .setMeta({
176
+ senderAccount: STOA_AUTONOMIC_OURONETGASSTATION,
177
+ creationTime: safeCreationTime(),
178
+ chainId: KADENA_CHAIN_ID,
179
+ gasLimit: gasLimitOverride ?? 2000000,
180
+ })
181
+ .setNetworkId(KADENA_NETWORK)
182
+ // Payment key signs: GAS_PAYER + coin.UR|TRANSFER
183
+ .addSigner(gasStationKey.publicKey, (w) => [
184
+ w(`${KADENA_NAMESPACE}.DALOS.GAS_PAYER`, "", { int: 0 }, { decimal: "0.0" }),
185
+ w("coin.UR|TRANSFER", paymentKeyAddress, STOA_AUTONOMIC_LIQUIDPOT, { decimal: String(numAmount) }),
186
+ ]);
187
+ // Pure guard signers (patron + wrapper) — no capabilities
188
+ const addedPubs = new Set([gasStationKey.publicKey]);
189
+ for (const k of [...patronGuardKeys, ...wrapperGuardKeys]) {
190
+ if (!addedPubs.has(k.publicKey)) {
191
+ builder = builder.addSigner(k.publicKey);
192
+ addedPubs.add(k.publicKey);
193
+ }
194
+ }
195
+ return builder.createTransaction();
196
+ };
197
+ const { dirtyRead, submit } = getFailoverClient(KADENA_CHAIN_ID);
198
+ // 1. Simulate with 2M (network max)
199
+ const simTx = buildTransaction();
200
+ const simulation = await dirtyRead(simTx);
201
+ if (simulation.result.status === "failure") {
202
+ const error = createSimulationError("Wrap UrStoa", simulation.result, `Patron: ${patronAddress} | Wrapper: ${wrapperAddress} | Amount: ${amount}`);
203
+ logDetailedError(error);
204
+ throw error;
205
+ }
206
+ // 2. Adaptive gas
207
+ const gasLimit = simulation.gas ? calculateAutoGasLimit(simulation.gas) : 2000000;
208
+ const finalTx = buildTransaction(gasLimit);
209
+ // 3. Collect all unique signers
210
+ const allSigners = [gasStationKey];
211
+ const seenPubs = new Set([gasStationKey.publicKey]);
212
+ for (const k of [...patronGuardKeys, ...wrapperGuardKeys]) {
213
+ if (!seenPubs.has(k.publicKey)) {
214
+ allSigners.push(k);
215
+ seenPubs.add(k.publicKey);
216
+ }
217
+ }
218
+ // 4. Sign & submit
219
+ const signed = await universalSignTransaction(finalTx, allSigners.map((s) => fromKeypair(s)));
220
+ return await submit(signed);
221
+ }