@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.
- package/CHANGELOG.md +3043 -0
- package/README.md +1940 -0
- package/dist/codex/codec.d.ts +77 -0
- package/dist/codex/codec.js +123 -0
- package/dist/codex/errors.d.ts +14 -0
- package/dist/codex/errors.js +20 -0
- package/dist/codex/index.d.ts +27 -0
- package/dist/codex/index.js +25 -0
- package/dist/codex/seedTypeMigration.d.ts +35 -0
- package/dist/codex/seedTypeMigration.js +45 -0
- package/dist/codex/types.d.ts +100 -0
- package/dist/codex/types.js +19 -0
- package/dist/constants/index.d.ts +2 -0
- package/dist/constants/index.js +3 -0
- package/dist/constants/ouronet.d.ts +33 -0
- package/dist/constants/ouronet.js +59 -0
- package/dist/constants/tokenIds.d.ts +13 -0
- package/dist/constants/tokenIds.js +21 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +1 -0
- package/dist/interactions/activateFunctions.d.ts +67 -0
- package/dist/interactions/activateFunctions.js +154 -0
- package/dist/interactions/addLiquidityFunctions.d.ts +140 -0
- package/dist/interactions/addLiquidityFunctions.js +485 -0
- package/dist/interactions/coilFunctions.d.ts +73 -0
- package/dist/interactions/coilFunctions.js +213 -0
- package/dist/interactions/crossChainFunctions.d.ts +211 -0
- package/dist/interactions/crossChainFunctions.js +463 -0
- package/dist/interactions/dexAcquisitionPoolFunctions.d.ts +18 -0
- package/dist/interactions/dexAcquisitionPoolFunctions.js +18 -0
- package/dist/interactions/dexCollectablesFunctions.d.ts +28 -0
- package/dist/interactions/dexCollectablesFunctions.js +227 -0
- package/dist/interactions/dexFunctions.d.ts +23 -0
- package/dist/interactions/dexFunctions.js +23 -0
- package/dist/interactions/dexOrtoFungibleFunctions.d.ts +33 -0
- package/dist/interactions/dexOrtoFungibleFunctions.js +171 -0
- package/dist/interactions/dexParseFunctions.d.ts +150 -0
- package/dist/interactions/dexParseFunctions.js +316 -0
- package/dist/interactions/dexSwapPairAdminFunctions.d.ts +75 -0
- package/dist/interactions/dexSwapPairAdminFunctions.js +255 -0
- package/dist/interactions/dexSwapPairCalcFunctions.d.ts +55 -0
- package/dist/interactions/dexSwapPairCalcFunctions.js +218 -0
- package/dist/interactions/dexSwapPairDashboardFunctions.d.ts +47 -0
- package/dist/interactions/dexSwapPairDashboardFunctions.js +179 -0
- package/dist/interactions/dexSwapPairExecuteFunctions.d.ts +40 -0
- package/dist/interactions/dexSwapPairExecuteFunctions.js +301 -0
- package/dist/interactions/dexSwapPairSmartSwapFunctions.d.ts +25 -0
- package/dist/interactions/dexSwapPairSmartSwapFunctions.js +166 -0
- package/dist/interactions/dexTrueFungibleFunctions.d.ts +52 -0
- package/dist/interactions/dexTrueFungibleFunctions.js +220 -0
- package/dist/interactions/dexTypes.d.ts +465 -0
- package/dist/interactions/dexTypes.js +6 -0
- package/dist/interactions/errors.d.ts +12 -0
- package/dist/interactions/errors.js +13 -0
- package/dist/interactions/guardFunctions.d.ts +33 -0
- package/dist/interactions/guardFunctions.js +110 -0
- package/dist/interactions/index.d.ts +1 -0
- package/dist/interactions/index.js +20 -0
- package/dist/interactions/infoOneFunctions.d.ts +133 -0
- package/dist/interactions/infoOneFunctions.js +566 -0
- package/dist/interactions/kadenaFunctions.d.ts +11 -0
- package/dist/interactions/kadenaFunctions.js +40 -0
- package/dist/interactions/kpayFunctions.d.ts +45 -0
- package/dist/interactions/kpayFunctions.js +191 -0
- package/dist/interactions/ouroAccountFunctions.d.ts +64 -0
- package/dist/interactions/ouroAccountFunctions.js +229 -0
- package/dist/interactions/ouroBalanceFunctions.d.ts +39 -0
- package/dist/interactions/ouroBalanceFunctions.js +100 -0
- package/dist/interactions/ouroCoilFunctions.d.ts +33 -0
- package/dist/interactions/ouroCoilFunctions.js +190 -0
- package/dist/interactions/ouroFunctions.d.ts +23 -0
- package/dist/interactions/ouroFunctions.js +23 -0
- package/dist/interactions/ouroMovieBoosterFunctions.d.ts +18 -0
- package/dist/interactions/ouroMovieBoosterFunctions.js +203 -0
- package/dist/interactions/ouroPriceFunctions.d.ts +38 -0
- package/dist/interactions/ouroPriceFunctions.js +96 -0
- package/dist/interactions/ouroPrimordialsFunctions.d.ts +10 -0
- package/dist/interactions/ouroPrimordialsFunctions.js +480 -0
- package/dist/interactions/ouroRotateFunctions.d.ts +22 -0
- package/dist/interactions/ouroRotateFunctions.js +114 -0
- package/dist/interactions/ouroSubCompressFunctions.d.ts +23 -0
- package/dist/interactions/ouroSubCompressFunctions.js +191 -0
- package/dist/interactions/ouroTransferFunctions.d.ts +14 -0
- package/dist/interactions/ouroTransferFunctions.js +87 -0
- package/dist/interactions/ouroTypes.d.ts +113 -0
- package/dist/interactions/ouroTypes.js +6 -0
- package/dist/interactions/ouroUrStoaFunctions.d.ts +16 -0
- package/dist/interactions/ouroUrStoaFunctions.js +121 -0
- package/dist/interactions/ouroWrapFunctions.d.ts +22 -0
- package/dist/interactions/ouroWrapFunctions.js +234 -0
- package/dist/interactions/pensionFunctions.d.ts +12 -0
- package/dist/interactions/pensionFunctions.js +127 -0
- package/dist/interactions/urStoaFunctions.d.ts +104 -0
- package/dist/interactions/urStoaFunctions.js +475 -0
- package/dist/interactions/wrapFunctions.d.ts +46 -0
- package/dist/interactions/wrapFunctions.js +221 -0
- package/dist/pact/cfmBuilders.d.ts +807 -0
- package/dist/pact/cfmBuilders.js +812 -0
- package/dist/pact/index.d.ts +1 -0
- package/dist/pact/index.js +10 -0
- package/package.json +64 -0
|
@@ -0,0 +1,190 @@
|
|
|
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 { calculateAutoGasLimit } from "@stoachain/stoa-core/gas";
|
|
8
|
+
import { KADENA_CHAIN_ID, KADENA_NAMESPACE, STOA_AUTONOMIC_OURONETGASSTATION, KADENA_NETWORK, } from "../constants/index.js";
|
|
9
|
+
import { safeCreationTime, formatDecimalForPact } from "@stoachain/stoa-core/pact";
|
|
10
|
+
import { Pact } from "@stoachain/kadena-stoic-legacy/client";
|
|
11
|
+
import { getFailoverClient } from "@stoachain/stoa-core/network";
|
|
12
|
+
import { universalSignTransaction, fromKeypair } from "@stoachain/stoa-core/signing";
|
|
13
|
+
import { pactRead } from "@stoachain/stoa-core/reads";
|
|
14
|
+
import { getLogger } from "@stoachain/stoa-core/observability";
|
|
15
|
+
// Get AURYN generation preview for coiling OURO
|
|
16
|
+
export async function getCoilPreview(ouroAmount) {
|
|
17
|
+
try {
|
|
18
|
+
const decimalAmount = formatDecimalForPact(ouroAmount);
|
|
19
|
+
const response = await pactRead(`(${KADENA_NAMESPACE}.INFO-ONE.ATS|INFO_Coil "preview" "preview" "Auryndex-O136CBn22ncY" "OURO-8Nh-JO8JO4F5" ${decimalAmount})`, { tier: "T2" });
|
|
20
|
+
if (!response || !response.result || response.result.status === "failure") {
|
|
21
|
+
// v3.3.0 (closes part of F-LOGGER-SEAM-001): routed through getLogger().warn
|
|
22
|
+
// — failure context is operationally useful, kept at warn-level so
|
|
23
|
+
// structured-logger consumers (HUB pino, OuronetUI Sentry) capture it.
|
|
24
|
+
getLogger().warn("Coil preview failed:", response?.result);
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const data = response.result.data;
|
|
28
|
+
// v3.3.0: removed `console.log("Coil preview response data:", data)`
|
|
29
|
+
// — pure debug-only data dump on the success path, no operational
|
|
30
|
+
// value beyond developer trace. Matches the F-LOGGER-SEAM-001
|
|
31
|
+
// validator's "should be removed" classification for debug-leak sites.
|
|
32
|
+
// Extract AURYN amount from text arrays
|
|
33
|
+
let aurynAmount = 0;
|
|
34
|
+
// Check pre-text array for AURYN amount
|
|
35
|
+
if (data && data['pre-text']) {
|
|
36
|
+
for (const text of data['pre-text']) {
|
|
37
|
+
const aurynMatch = text.match(/generates\s+([\d.]+)\s+AURYN/);
|
|
38
|
+
if (aurynMatch) {
|
|
39
|
+
aurynAmount = parseFloat(aurynMatch[1]);
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// Fallback: check post-text array
|
|
45
|
+
if (!aurynAmount && data && data['post-text']) {
|
|
46
|
+
for (const text of data['post-text']) {
|
|
47
|
+
const aurynMatch = text.match(/generating\s+([\d.]+)\s+AURYN/);
|
|
48
|
+
if (aurynMatch) {
|
|
49
|
+
aurynAmount = parseFloat(aurynMatch[1]);
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Return rich data structure
|
|
55
|
+
return {
|
|
56
|
+
auryn: aurynAmount,
|
|
57
|
+
fee: 0,
|
|
58
|
+
kadenaInfo: {
|
|
59
|
+
text: data?.kadena?.[`kadena-text`] || "Kadena fee information not available",
|
|
60
|
+
discount: data?.kadena?.[`kadena-discount`] || 1,
|
|
61
|
+
full: data?.kadena?.[`kadena-full`] || 0,
|
|
62
|
+
need: data?.kadena?.[`kadena-need`] || 0,
|
|
63
|
+
},
|
|
64
|
+
ignisInfo: {
|
|
65
|
+
text: data?.ignis?.[`ignis-text`] || "IGNIS fee information not available",
|
|
66
|
+
discount: data?.ignis?.[`ignis-discount`] || 1,
|
|
67
|
+
full: data?.ignis?.[`ignis-full`] || 0,
|
|
68
|
+
need: data?.ignis?.[`ignis-need`] || 0,
|
|
69
|
+
},
|
|
70
|
+
preText: data?.[`pre-text`] || [],
|
|
71
|
+
postText: data?.[`post-text`] || [],
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
getLogger().error("Error getting coil preview:", error);
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// Curl OURO to Elite AURYN
|
|
80
|
+
// (namespace.TS01-C2.ATS|C_Curl patron:string curler:string "Auryndex-O136CBn22ncY" "EliteAuryndex-O136CBn22ncY" "OURO-8Nh-JO8JO4F5" amount:decimal)
|
|
81
|
+
export async function curlOuroToEliteAuryn(ouroAccount, kadenaAccount, guard, targetAccount, // The account that will receive the Elite AURYN (same as patron per client explanation)
|
|
82
|
+
ouroAmount) {
|
|
83
|
+
const keysetName = `ks`;
|
|
84
|
+
// Ensure amount is formatted as decimal
|
|
85
|
+
const decimalAmount = formatDecimalForPact(ouroAmount);
|
|
86
|
+
let gasLimit = 2000000; // Default gas limit
|
|
87
|
+
const buildTransaction = (gasLimitOverride) => {
|
|
88
|
+
return Pact.builder
|
|
89
|
+
.execution(`(${KADENA_NAMESPACE}.TS01-C2.ATS|C_Curl "${ouroAccount.address}" "${targetAccount}" "Auryndex-O136CBn22ncY" "EliteAuryndex-O136CBn22ncY" "OURO-8Nh-JO8JO4F5" ${decimalAmount})`)
|
|
90
|
+
.addData(keysetName, {
|
|
91
|
+
keys: [guard.publicKey],
|
|
92
|
+
pred: "keys-all",
|
|
93
|
+
})
|
|
94
|
+
.setMeta({
|
|
95
|
+
senderAccount: STOA_AUTONOMIC_OURONETGASSTATION,
|
|
96
|
+
creationTime: safeCreationTime(),
|
|
97
|
+
chainId: KADENA_CHAIN_ID,
|
|
98
|
+
gasLimit: gasLimitOverride || gasLimit,
|
|
99
|
+
})
|
|
100
|
+
.setNetworkId(KADENA_NETWORK)
|
|
101
|
+
.addSigner(kadenaAccount.publicKey, (withCapability) => [
|
|
102
|
+
withCapability(`${KADENA_NAMESPACE}.DALOS.GAS_PAYER`, "", { int: 0 }, { decimal: "0.0" }),
|
|
103
|
+
])
|
|
104
|
+
.addSigner(guard.publicKey)
|
|
105
|
+
.createTransaction();
|
|
106
|
+
};
|
|
107
|
+
const { dirtyRead, submit } = getFailoverClient(KADENA_CHAIN_ID);
|
|
108
|
+
// First do a simulation to check gas
|
|
109
|
+
let transaction = buildTransaction();
|
|
110
|
+
const simulation = await dirtyRead(transaction);
|
|
111
|
+
// Check if simulation failed
|
|
112
|
+
if (simulation.result.status === "failure") {
|
|
113
|
+
const errorMessage = simulation.result.error?.message || "Transaction simulation failed";
|
|
114
|
+
throw new Error(`Simulation failed: ${errorMessage}`);
|
|
115
|
+
}
|
|
116
|
+
// Check if we need to adjust gas limit
|
|
117
|
+
const requiredGas = simulation.gas;
|
|
118
|
+
if (requiredGas && requiredGas > gasLimit) {
|
|
119
|
+
// Rebuild transaction with adjusted gas limit (20% buffer)
|
|
120
|
+
gasLimit = calculateAutoGasLimit(requiredGas);
|
|
121
|
+
transaction = buildTransaction(gasLimit);
|
|
122
|
+
}
|
|
123
|
+
// Sign the transaction with both keypairs
|
|
124
|
+
const signedTransaction = await universalSignTransaction(transaction, [
|
|
125
|
+
fromKeypair(kadenaAccount),
|
|
126
|
+
fromKeypair(guard),
|
|
127
|
+
]);
|
|
128
|
+
// Submit the signed transaction
|
|
129
|
+
const result = await submit(signedTransaction);
|
|
130
|
+
return result;
|
|
131
|
+
}
|
|
132
|
+
// Export new coiling functions for AURYN and WSTOA
|
|
133
|
+
export { getAurynCoilPreview, coilAurynToElite, getWkdaCoilPreview, coilWkdaToLkda, COIL_CONFIGS } from "./coilFunctions.js";
|
|
134
|
+
// Export pension functions for WSTOA and SSTOA
|
|
135
|
+
export { brumateWkdaToPkda, constrictLkdaToPkda } from "./pensionFunctions.js";
|
|
136
|
+
// Export INFO-ONE preview functions
|
|
137
|
+
export { getTransferPreview, getCoilPreviewInfo, getCurlPreviewInfo, getBrumatePreviewInfo, getConstrictPreviewInfo, parseTransferPreview } from "./infoOneFunctions.js";
|
|
138
|
+
// Coil OURO to AURYN
|
|
139
|
+
// (namespace.TS01-C2.ATS|C_Coil patron:string coiler:string "Auryndex-O136CBn22ncY" "OURO-8Nh-JO8JO4F5" amount:decimal)
|
|
140
|
+
export async function coilOuroToAuryn(ouroAccount, kadenaAccount, guard, targetAccount, // The account that will receive the AURYN
|
|
141
|
+
ouroAmount) {
|
|
142
|
+
const keysetName = `ks`;
|
|
143
|
+
// Ensure amount is formatted as decimal
|
|
144
|
+
const decimalAmount = formatDecimalForPact(ouroAmount);
|
|
145
|
+
let gasLimit = 2000000; // Default gas limit
|
|
146
|
+
const buildTransaction = (gasLimitOverride) => {
|
|
147
|
+
return Pact.builder
|
|
148
|
+
.execution(`(${KADENA_NAMESPACE}.TS01-C2.ATS|C_Coil "${ouroAccount.address}" "${targetAccount}" "Auryndex-O136CBn22ncY" "OURO-8Nh-JO8JO4F5" ${decimalAmount})`)
|
|
149
|
+
.addData(keysetName, {
|
|
150
|
+
keys: [guard.publicKey],
|
|
151
|
+
pred: "keys-all",
|
|
152
|
+
})
|
|
153
|
+
.setMeta({
|
|
154
|
+
senderAccount: STOA_AUTONOMIC_OURONETGASSTATION,
|
|
155
|
+
creationTime: safeCreationTime(),
|
|
156
|
+
chainId: KADENA_CHAIN_ID,
|
|
157
|
+
gasLimit: gasLimitOverride || gasLimit,
|
|
158
|
+
})
|
|
159
|
+
.setNetworkId(KADENA_NETWORK)
|
|
160
|
+
.addSigner(kadenaAccount.publicKey, (withCapability) => [
|
|
161
|
+
withCapability(`${KADENA_NAMESPACE}.DALOS.GAS_PAYER`, "", { int: 0 }, { decimal: "0.0" }),
|
|
162
|
+
])
|
|
163
|
+
.addSigner(guard.publicKey)
|
|
164
|
+
.createTransaction();
|
|
165
|
+
};
|
|
166
|
+
const { dirtyRead, submit } = getFailoverClient(KADENA_CHAIN_ID);
|
|
167
|
+
// First do a simulation to check gas
|
|
168
|
+
let transaction = buildTransaction();
|
|
169
|
+
const simulation = await dirtyRead(transaction);
|
|
170
|
+
// Check if simulation failed
|
|
171
|
+
if (simulation.result.status === "failure") {
|
|
172
|
+
const errorMessage = simulation.result.error?.message || "Transaction simulation failed";
|
|
173
|
+
throw new Error(`Simulation failed: ${errorMessage}`);
|
|
174
|
+
}
|
|
175
|
+
// Check if we need to adjust gas limit
|
|
176
|
+
const requiredGas = simulation.gas;
|
|
177
|
+
if (requiredGas && requiredGas > gasLimit) {
|
|
178
|
+
// Rebuild transaction with adjusted gas limit (20% buffer)
|
|
179
|
+
gasLimit = calculateAutoGasLimit(requiredGas);
|
|
180
|
+
transaction = buildTransaction(gasLimit);
|
|
181
|
+
}
|
|
182
|
+
// Sign the transaction with both keypairs
|
|
183
|
+
const signedTransaction = await universalSignTransaction(transaction, [
|
|
184
|
+
fromKeypair(kadenaAccount),
|
|
185
|
+
fromKeypair(guard),
|
|
186
|
+
]);
|
|
187
|
+
// Submit the signed transaction
|
|
188
|
+
const result = await submit(signedTransaction);
|
|
189
|
+
return result;
|
|
190
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ouroFunctions.ts
|
|
3
|
+
*
|
|
4
|
+
* Thin re-export shim for backward compat (Phase 2 of v4.2.0).
|
|
5
|
+
*
|
|
6
|
+
* Real logic moved to entity-oriented files: ouroAccountFunctions,
|
|
7
|
+
* ouroPrimordialsFunctions, ouroSubCompressFunctions, ouroWrapFunctions,
|
|
8
|
+
* ouroTransferFunctions, ouroMovieBoosterFunctions, ouroCoilFunctions,
|
|
9
|
+
* ouroBalanceFunctions, ouroRotateFunctions, ouroPriceFunctions,
|
|
10
|
+
* ouroUrStoaFunctions, ouroTypes.
|
|
11
|
+
*/
|
|
12
|
+
export * from "./ouroTypes.js";
|
|
13
|
+
export * from "./ouroAccountFunctions.js";
|
|
14
|
+
export * from "./ouroPrimordialsFunctions.js";
|
|
15
|
+
export * from "./ouroSubCompressFunctions.js";
|
|
16
|
+
export * from "./ouroWrapFunctions.js";
|
|
17
|
+
export * from "./ouroTransferFunctions.js";
|
|
18
|
+
export * from "./ouroMovieBoosterFunctions.js";
|
|
19
|
+
export * from "./ouroCoilFunctions.js";
|
|
20
|
+
export * from "./ouroBalanceFunctions.js";
|
|
21
|
+
export * from "./ouroRotateFunctions.js";
|
|
22
|
+
export * from "./ouroPriceFunctions.js";
|
|
23
|
+
export * from "./ouroUrStoaFunctions.js";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ouroFunctions.ts
|
|
3
|
+
*
|
|
4
|
+
* Thin re-export shim for backward compat (Phase 2 of v4.2.0).
|
|
5
|
+
*
|
|
6
|
+
* Real logic moved to entity-oriented files: ouroAccountFunctions,
|
|
7
|
+
* ouroPrimordialsFunctions, ouroSubCompressFunctions, ouroWrapFunctions,
|
|
8
|
+
* ouroTransferFunctions, ouroMovieBoosterFunctions, ouroCoilFunctions,
|
|
9
|
+
* ouroBalanceFunctions, ouroRotateFunctions, ouroPriceFunctions,
|
|
10
|
+
* ouroUrStoaFunctions, ouroTypes.
|
|
11
|
+
*/
|
|
12
|
+
export * from "./ouroTypes.js";
|
|
13
|
+
export * from "./ouroAccountFunctions.js";
|
|
14
|
+
export * from "./ouroPrimordialsFunctions.js";
|
|
15
|
+
export * from "./ouroSubCompressFunctions.js";
|
|
16
|
+
export * from "./ouroWrapFunctions.js";
|
|
17
|
+
export * from "./ouroTransferFunctions.js";
|
|
18
|
+
export * from "./ouroMovieBoosterFunctions.js";
|
|
19
|
+
export * from "./ouroCoilFunctions.js";
|
|
20
|
+
export * from "./ouroBalanceFunctions.js";
|
|
21
|
+
export * from "./ouroRotateFunctions.js";
|
|
22
|
+
export * from "./ouroPriceFunctions.js";
|
|
23
|
+
export * from "./ouroUrStoaFunctions.js";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ouroMovieBoosterFunctions.ts
|
|
3
|
+
* Sparks balance / movie-booster purchase / firestarter execution + max-buy probe.
|
|
4
|
+
*/
|
|
5
|
+
import type { IKadenaKeypair } from "@stoachain/stoa-core/signing";
|
|
6
|
+
import type { IOuroAccountKeypair } from "./ouroTypes.js";
|
|
7
|
+
export declare function getTotalMBCost(sparks: number): Promise<string | null>;
|
|
8
|
+
export declare function movieBoosterBuy(patronAccount: IOuroAccountKeypair, // The patron account (owner)
|
|
9
|
+
buyerAccount: string, // Buyer Ouro address (usually same as patron)
|
|
10
|
+
mbAmount: number, // Amount of SPARK tokens to buy (integer)
|
|
11
|
+
isNative: boolean, // true for KDA, false for WSTOA
|
|
12
|
+
kadenaAccount: IKadenaKeypair, // The kadena account (payer)
|
|
13
|
+
guardAccount: IKadenaKeypair): Promise<import("@stoachain/kadena-stoic-legacy/client").ITransactionDescriptor>;
|
|
14
|
+
export declare function getMaxBuyMovieBooster(account: string, native: boolean): Promise<number | null>;
|
|
15
|
+
export declare function getSparksBalance(account: string): Promise<any | null>;
|
|
16
|
+
export declare function firestarter(ouroAccount: IOuroAccountKeypair, // Ouro account that will receive the IGNIS
|
|
17
|
+
kadenaAccount: IKadenaKeypair, // The kadena account that will transfer KDA
|
|
18
|
+
guardAccount: IKadenaKeypair): Promise<import("@stoachain/kadena-stoic-legacy/client").ITransactionDescriptor>;
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ouroMovieBoosterFunctions.ts
|
|
3
|
+
* Sparks balance / movie-booster purchase / firestarter execution + max-buy probe.
|
|
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 } 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 { pactRead } from "@stoachain/stoa-core/reads";
|
|
12
|
+
import { getLogger } from "@stoachain/stoa-core/observability";
|
|
13
|
+
// (ouronet-ns.MB.URC_TotalMBCost sparks)
|
|
14
|
+
export async function getTotalMBCost(sparks) {
|
|
15
|
+
try {
|
|
16
|
+
const integerSparks = Math.floor(sparks);
|
|
17
|
+
const response = await pactRead(`(${KADENA_NAMESPACE}.MB.URC_TotalMBCost ${integerSparks})`, { tier: "T5" });
|
|
18
|
+
if (!response || !response.result || response.result.status === "failure") {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
return response.result.data;
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
getLogger().error("Error getting total MB cost:", error);
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
// (ouronet-ns.MB.C_MovieBoosterBuyer patron:string buyer:string mb-amount:integer iz-native:bool)
|
|
29
|
+
export async function movieBoosterBuy(patronAccount, // The patron account (owner)
|
|
30
|
+
buyerAccount, // Buyer Ouro address (usually same as patron)
|
|
31
|
+
mbAmount, // Amount of SPARK tokens to buy (integer)
|
|
32
|
+
isNative, // true for KDA, false for WSTOA
|
|
33
|
+
kadenaAccount, // The kadena account (payer)
|
|
34
|
+
guardAccount // The guard account from the Ouro account
|
|
35
|
+
) {
|
|
36
|
+
const keysetName = `ks`;
|
|
37
|
+
// Ensure amount is integer
|
|
38
|
+
const integerAmount = Math.floor(mbAmount);
|
|
39
|
+
const kadenaCost = await getTotalMBCost(integerAmount);
|
|
40
|
+
let gasLimit = 2000000; // Default gas limit for movie booster buy
|
|
41
|
+
const buildTransaction = (gasLimitOverride) => {
|
|
42
|
+
const txBuilder = Pact.builder
|
|
43
|
+
.execution(`(${KADENA_NAMESPACE}.MB.C_MovieBoosterBuyer "${patronAccount.address}" "${buyerAccount}" ${integerAmount} ${isNative})`)
|
|
44
|
+
.addData(keysetName, {
|
|
45
|
+
keys: [guardAccount.publicKey],
|
|
46
|
+
pred: "keys-all",
|
|
47
|
+
})
|
|
48
|
+
.setMeta({
|
|
49
|
+
senderAccount: STOA_AUTONOMIC_OURONETGASSTATION,
|
|
50
|
+
creationTime: safeCreationTime(),
|
|
51
|
+
chainId: KADENA_CHAIN_ID,
|
|
52
|
+
gasLimit: gasLimitOverride || gasLimit,
|
|
53
|
+
})
|
|
54
|
+
.setNetworkId(KADENA_NETWORK)
|
|
55
|
+
.addSigner(kadenaAccount.publicKey, (withCapability) => {
|
|
56
|
+
const capabilities = [
|
|
57
|
+
withCapability(`${KADENA_NAMESPACE}.DALOS.GAS_PAYER`, "", { int: 0 }, { decimal: "0.0" }),
|
|
58
|
+
];
|
|
59
|
+
// If paying with native KDA, add coin.TRANSFER capability
|
|
60
|
+
if (isNative) {
|
|
61
|
+
// We'll need to calculate the KDA amount based on SPARK price
|
|
62
|
+
// For now, we'll use a placeholder that will be replaced after simulation
|
|
63
|
+
capabilities.push(withCapability("coin.TRANSFER", `k:${kadenaAccount.publicKey}`, STOA_AUTONOMIC_OURONETGASSTATION, { decimal: `${kadenaCost}` } // This will be updated after simulation
|
|
64
|
+
));
|
|
65
|
+
}
|
|
66
|
+
return capabilities;
|
|
67
|
+
})
|
|
68
|
+
.addSigner(guardAccount.publicKey);
|
|
69
|
+
return txBuilder.createTransaction();
|
|
70
|
+
};
|
|
71
|
+
const { dirtyRead, submit } = getFailoverClient(KADENA_CHAIN_ID);
|
|
72
|
+
// First do a simulation to check gas and get the actual KDA amount if native
|
|
73
|
+
let transaction = buildTransaction();
|
|
74
|
+
const simulation = await dirtyRead(transaction);
|
|
75
|
+
// Check if simulation failed
|
|
76
|
+
if (simulation.result.status === "failure") {
|
|
77
|
+
const errorMessage = simulation.result.error?.message || "Transaction simulation failed";
|
|
78
|
+
throw new Error(`Simulation failed: ${errorMessage}`);
|
|
79
|
+
}
|
|
80
|
+
if (isNative && simulation.result.data) {
|
|
81
|
+
if (kadenaCost && parseFloat(kadenaCost) <= 0) {
|
|
82
|
+
throw new Error("Invalid KDA amount required for purchase");
|
|
83
|
+
}
|
|
84
|
+
// Rebuild transaction with correct KDA amount
|
|
85
|
+
transaction = Pact.builder
|
|
86
|
+
.execution(`(${KADENA_NAMESPACE}.MB.C_MovieBoosterBuyer "${patronAccount.address}" "${buyerAccount}" ${integerAmount} ${isNative})`)
|
|
87
|
+
.addData(keysetName, {
|
|
88
|
+
keys: [guardAccount.publicKey],
|
|
89
|
+
pred: "keys-all",
|
|
90
|
+
})
|
|
91
|
+
.setMeta({
|
|
92
|
+
senderAccount: STOA_AUTONOMIC_OURONETGASSTATION,
|
|
93
|
+
creationTime: safeCreationTime(),
|
|
94
|
+
chainId: KADENA_CHAIN_ID,
|
|
95
|
+
gasLimit: gasLimit,
|
|
96
|
+
})
|
|
97
|
+
.setNetworkId(KADENA_NETWORK)
|
|
98
|
+
.addSigner(kadenaAccount.publicKey, (withCapability) => [
|
|
99
|
+
withCapability(`${KADENA_NAMESPACE}.DALOS.GAS_PAYER`, "", { int: 0 }, { decimal: "0.0" }),
|
|
100
|
+
withCapability("coin.TRANSFER", `k:${kadenaAccount.publicKey}`, STOA_AUTONOMIC_OURONETGASSTATION, { decimal: `${kadenaCost}` }),
|
|
101
|
+
])
|
|
102
|
+
.addSigner(guardAccount.publicKey)
|
|
103
|
+
.createTransaction();
|
|
104
|
+
}
|
|
105
|
+
// Check if we need to adjust gas limit
|
|
106
|
+
const requiredGas = simulation.gas;
|
|
107
|
+
if (requiredGas && requiredGas > gasLimit) {
|
|
108
|
+
// Rebuild transaction with adjusted gas limit (20% buffer)
|
|
109
|
+
gasLimit = calculateAutoGasLimit(requiredGas);
|
|
110
|
+
transaction = buildTransaction(gasLimit);
|
|
111
|
+
}
|
|
112
|
+
// Sign the transaction with both keypairs
|
|
113
|
+
const signedTransaction = await universalSignTransaction(transaction, [
|
|
114
|
+
fromKeypair(kadenaAccount),
|
|
115
|
+
fromKeypair(guardAccount),
|
|
116
|
+
]);
|
|
117
|
+
// Submit the signed transaction
|
|
118
|
+
const result = await submit(signedTransaction);
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
121
|
+
export async function getMaxBuyMovieBooster(account, native) {
|
|
122
|
+
try {
|
|
123
|
+
const response = await pactRead(`(${KADENA_NAMESPACE}.MB.URC_GetMaxBuy "${account}" ${native})`, { tier: "T5" });
|
|
124
|
+
if (!response || !response.result || response.result.status === "failure") {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
const data = response.result.data;
|
|
128
|
+
const value = Number(data?.int);
|
|
129
|
+
return Number.isFinite(value) ? value : null;
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
getLogger().error("Error getting max buy for movie booster:", error);
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
export async function getSparksBalance(account) {
|
|
137
|
+
try {
|
|
138
|
+
const response = await pactRead(`(${KADENA_NAMESPACE}.MB.UR_Sparks "${account}")`, { tier: "T5" });
|
|
139
|
+
if (!response || !response.result || response.result.status === "failure") {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
return response.result.data;
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
getLogger().error("Error getting sparks balance:", error);
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
// (ouronet-ns.TS01-C2.SWP|C_Firestarter ouro-account:string)
|
|
150
|
+
export async function firestarter(ouroAccount, // Ouro account that will receive the IGNIS
|
|
151
|
+
kadenaAccount, // The kadena account that will transfer KDA
|
|
152
|
+
guardAccount // The guard account from the Ouro account
|
|
153
|
+
) {
|
|
154
|
+
const keysetName = `ks`;
|
|
155
|
+
// Fixed amount of 10 KDA
|
|
156
|
+
const kdaAmount = "10.0";
|
|
157
|
+
let gasLimit = 2000000; // Default gas limit for firestarter operation
|
|
158
|
+
const buildTransaction = (gasLimitOverride) => {
|
|
159
|
+
return Pact.builder
|
|
160
|
+
.execution(`(${KADENA_NAMESPACE}.TS01-C3.SWP|C_Firestarter "${ouroAccount.address}")`)
|
|
161
|
+
.addData(keysetName, {
|
|
162
|
+
keys: [guardAccount.publicKey],
|
|
163
|
+
pred: "keys-all",
|
|
164
|
+
})
|
|
165
|
+
.setMeta({
|
|
166
|
+
senderAccount: STOA_AUTONOMIC_OURONETGASSTATION,
|
|
167
|
+
creationTime: safeCreationTime(),
|
|
168
|
+
chainId: KADENA_CHAIN_ID,
|
|
169
|
+
gasLimit: gasLimitOverride || gasLimit,
|
|
170
|
+
})
|
|
171
|
+
.setNetworkId(KADENA_NETWORK)
|
|
172
|
+
.addSigner(kadenaAccount.publicKey, (withCapability) => [
|
|
173
|
+
withCapability(`${KADENA_NAMESPACE}.DALOS.GAS_PAYER`, "", { int: 0 }, { decimal: "0.0" }),
|
|
174
|
+
withCapability("coin.TRANSFER", `k:${kadenaAccount.publicKey}`, STOA_AUTONOMIC_OURONETGASSTATION, { decimal: kdaAmount }),
|
|
175
|
+
])
|
|
176
|
+
.addSigner(guardAccount.publicKey)
|
|
177
|
+
.createTransaction();
|
|
178
|
+
};
|
|
179
|
+
const { dirtyRead, submit } = getFailoverClient(KADENA_CHAIN_ID);
|
|
180
|
+
// First do a simulation to check gas
|
|
181
|
+
let transaction = buildTransaction();
|
|
182
|
+
const simulation = await dirtyRead(transaction);
|
|
183
|
+
// Check if simulation failed
|
|
184
|
+
if (simulation.result.status === "failure") {
|
|
185
|
+
const errorMessage = simulation.result.error?.message || "Transaction simulation failed";
|
|
186
|
+
throw new Error(`Simulation failed: ${errorMessage}`);
|
|
187
|
+
}
|
|
188
|
+
// Check if we need to adjust gas limit
|
|
189
|
+
const requiredGas = simulation.gas;
|
|
190
|
+
if (requiredGas && requiredGas > gasLimit) {
|
|
191
|
+
// Rebuild transaction with adjusted gas limit (20% buffer)
|
|
192
|
+
gasLimit = calculateAutoGasLimit(requiredGas);
|
|
193
|
+
transaction = buildTransaction(gasLimit);
|
|
194
|
+
}
|
|
195
|
+
// Sign the transaction with both keypairs
|
|
196
|
+
const signedTransaction = await universalSignTransaction(transaction, [
|
|
197
|
+
fromKeypair(kadenaAccount),
|
|
198
|
+
fromKeypair(guardAccount),
|
|
199
|
+
]);
|
|
200
|
+
// Submit the signed transaction
|
|
201
|
+
const result = await submit(signedTransaction);
|
|
202
|
+
return result;
|
|
203
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ouroPriceFunctions.ts
|
|
3
|
+
* Price oracle (STOA/USD), coin-account existence probe, DPTF issue/min-move reads.
|
|
4
|
+
* All four functions follow the v3.0.0 nullable contract — return null on RPC failure or non-finite value.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Read the live STOA/USD price from the on-chain KDA-PID oracle.
|
|
8
|
+
*
|
|
9
|
+
* Returns `null` when the oracle is unreachable, the chain call returns a
|
|
10
|
+
* non-success status, or the decoded value is not a finite number. Callers
|
|
11
|
+
* are expected to handle the nullable contract explicitly — no fabricated
|
|
12
|
+
* fallback price is ever returned.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getStoaPriceUSD(options?: {
|
|
15
|
+
skipTempWatcher?: boolean;
|
|
16
|
+
}): Promise<number | null>;
|
|
17
|
+
/**
|
|
18
|
+
* Check if a coin account exists.
|
|
19
|
+
* (try false (coin.get-balance <address>))
|
|
20
|
+
* Returns: true = exists, false = doesn't exist, null = error
|
|
21
|
+
*/
|
|
22
|
+
export declare function checkCoinAccountExists(address: string): Promise<boolean | null>;
|
|
23
|
+
/**
|
|
24
|
+
* Get INFO for UnwrapStoa function.
|
|
25
|
+
* (ouronet-ns.INFO-ONE.LIQUID|INFO_UnwrapStoa <patron> <unwrapper> <amount:decimal>)
|
|
26
|
+
*/
|
|
27
|
+
export declare function getDPTFIssueInfo(patron: string, resident: string, tokens: string[]): Promise<any | null>;
|
|
28
|
+
/**
|
|
29
|
+
* Fetch the minimum transfer amount for a DPTF token.
|
|
30
|
+
* (ouronet-ns.DPTF.UR_MinMove <token-id>) → decimal
|
|
31
|
+
*
|
|
32
|
+
* Returns null when the chain read returns a non-success status, when the
|
|
33
|
+
* outer call throws, or when the decoded value is not a finite number.
|
|
34
|
+
* Callers must handle the nullable contract explicitly — no fabricated
|
|
35
|
+
* sentinel (previously `0`) is ever returned, since `0` is also a valid
|
|
36
|
+
* legitimate min-move and would mask read failures.
|
|
37
|
+
*/
|
|
38
|
+
export declare function getDPTFMinMove(tokenId: string): Promise<number | null>;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ouroPriceFunctions.ts
|
|
3
|
+
* Price oracle (STOA/USD), coin-account existence probe, DPTF issue/min-move reads.
|
|
4
|
+
* All four functions follow the v3.0.0 nullable contract — return null on RPC failure or non-finite value.
|
|
5
|
+
*/
|
|
6
|
+
import { KADENA_NAMESPACE } 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
|
+
/**
|
|
11
|
+
* Read the live STOA/USD price from the on-chain KDA-PID oracle.
|
|
12
|
+
*
|
|
13
|
+
* Returns `null` when the oracle is unreachable, the chain call returns a
|
|
14
|
+
* non-success status, or the decoded value is not a finite number. Callers
|
|
15
|
+
* are expected to handle the nullable contract explicitly — no fabricated
|
|
16
|
+
* fallback price is ever returned.
|
|
17
|
+
*/
|
|
18
|
+
export async function getStoaPriceUSD(options) {
|
|
19
|
+
try {
|
|
20
|
+
const pactCode = `(${KADENA_NAMESPACE}.U|CT.UR|KDA-PID)`;
|
|
21
|
+
const response = await pactRead(pactCode, { tier: "T6", skipTempWatcher: options?.skipTempWatcher });
|
|
22
|
+
if (response?.result?.status === "success") {
|
|
23
|
+
const value = Number(mayComeWithDeimal(response.result.data));
|
|
24
|
+
return Number.isFinite(value) ? value : null;
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
getLogger().error("Error in getStoaPriceUSD:", error);
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Check if a coin account exists.
|
|
35
|
+
* (try false (coin.get-balance <address>))
|
|
36
|
+
* Returns: true = exists, false = doesn't exist, null = error
|
|
37
|
+
*/
|
|
38
|
+
export async function checkCoinAccountExists(address) {
|
|
39
|
+
try {
|
|
40
|
+
const pactCode = `(try false (coin.get-balance "${address}"))`;
|
|
41
|
+
const response = await pactRead(pactCode, { tier: "T3" });
|
|
42
|
+
const data = response?.result?.data;
|
|
43
|
+
if (data === false || data === "false")
|
|
44
|
+
return false;
|
|
45
|
+
if (typeof data === "number" || (data && typeof data === "object" && "decimal" in data))
|
|
46
|
+
return true;
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
getLogger().error("Error checking coin account:", error);
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Get INFO for UnwrapStoa function.
|
|
56
|
+
* (ouronet-ns.INFO-ONE.LIQUID|INFO_UnwrapStoa <patron> <unwrapper> <amount:decimal>)
|
|
57
|
+
*/
|
|
58
|
+
export async function getDPTFIssueInfo(patron, resident, tokens) {
|
|
59
|
+
try {
|
|
60
|
+
const tokenList = tokens.map(t => `"${t}"`).join(" ");
|
|
61
|
+
const pactCode = `(${KADENA_NAMESPACE}.INFO-ONE.DPTF|INFO_Issue "${patron}" "${resident}" [${tokenList}])`;
|
|
62
|
+
const response = await pactRead(pactCode, { tier: "T2" });
|
|
63
|
+
if (response?.result?.status === "success")
|
|
64
|
+
return response.result.data;
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
getLogger().error("Error in getDPTFIssueInfo:", error);
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Fetch the minimum transfer amount for a DPTF token.
|
|
74
|
+
* (ouronet-ns.DPTF.UR_MinMove <token-id>) → decimal
|
|
75
|
+
*
|
|
76
|
+
* Returns null when the chain read returns a non-success status, when the
|
|
77
|
+
* outer call throws, or when the decoded value is not a finite number.
|
|
78
|
+
* Callers must handle the nullable contract explicitly — no fabricated
|
|
79
|
+
* sentinel (previously `0`) is ever returned, since `0` is also a valid
|
|
80
|
+
* legitimate min-move and would mask read failures.
|
|
81
|
+
*/
|
|
82
|
+
export async function getDPTFMinMove(tokenId) {
|
|
83
|
+
try {
|
|
84
|
+
const pactCode = `(${KADENA_NAMESPACE}.DPTF.UR_MinMove "${tokenId}")`;
|
|
85
|
+
const response = await pactRead(pactCode, { tier: "T7" });
|
|
86
|
+
if (response?.result?.status === "success") {
|
|
87
|
+
const value = parseFloat(String(mayComeWithDeimal(response.result.data)));
|
|
88
|
+
return Number.isFinite(value) ? value : null;
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
getLogger().error("Error in getDPTFMinMove:", error);
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ouroPrimordialsFunctions.ts
|
|
3
|
+
* Chain call to ouronet-ns.DPL-UR.URC_0002_Primordials plus the placeholder factory.
|
|
4
|
+
* The internal `parseResponse` and `fmt` helpers retain the v4.x token-decoration
|
|
5
|
+
* logic verbatim for backward compat (v5.0.0 will physically extract it).
|
|
6
|
+
*/
|
|
7
|
+
export declare function getPrimordials(currentAccount?: string, codexAccounts?: string[], options?: {
|
|
8
|
+
skipTempWatcher?: boolean;
|
|
9
|
+
}): Promise<any>;
|
|
10
|
+
export declare function buildPlaceholderPrimordials(): any;
|