@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,234 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ouroWrapFunctions.ts
|
|
3
|
+
* KDA wrap/unwrap and unwrap-stoa execution + supporting reads.
|
|
4
|
+
*/
|
|
5
|
+
import { calculateAutoGasLimit } from "@stoachain/stoa-core/gas";
|
|
6
|
+
import { KADENA_CHAIN_ID, KADENA_NAMESPACE, STOA_AUTONOMIC_OURONETGASSTATION, STOA_AUTONOMIC_LIQUIDPOT, 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
|
+
// Wrap Kadena
|
|
15
|
+
// (defun LQD|C_WrapStoa (patron:string wrapper:string amount:decimal))
|
|
16
|
+
// patron is current ouro account public key | wrapper by default is the same but can also be a different ouro account public key amount should be decimal
|
|
17
|
+
// as keys we need to use the ouro account kadena_ledger that has the capability coin.TRANSFER and the value of the amount. STOA_AUTONOMIC_OURONETGASSTATION
|
|
18
|
+
export async function wrapKadena(patronAccount, wrapperAccount, // Ouro address that will receive the wrapped KDA
|
|
19
|
+
kadenaAccount, // The kadena account that will transfer KDA
|
|
20
|
+
guardAccount, // The guard account from the Ouro account
|
|
21
|
+
amount) {
|
|
22
|
+
const keysetName = `ks`;
|
|
23
|
+
// Ensure amount is formatted as decimal
|
|
24
|
+
const decimalAmount = formatDecimalForPact(amount);
|
|
25
|
+
let gasLimit = 2000000; // Default gas limit for wrap operation
|
|
26
|
+
const buildTransaction = (gasLimitOverride) => {
|
|
27
|
+
return Pact.builder
|
|
28
|
+
.execution(`(${KADENA_NAMESPACE}.TS01-C2.LQD|C_WrapStoa "${patronAccount.address}" "${wrapperAccount}" ${decimalAmount})`)
|
|
29
|
+
.addData(keysetName, {
|
|
30
|
+
keys: [guardAccount.publicKey],
|
|
31
|
+
pred: "keys-all",
|
|
32
|
+
})
|
|
33
|
+
.setMeta({
|
|
34
|
+
senderAccount: STOA_AUTONOMIC_OURONETGASSTATION,
|
|
35
|
+
creationTime: safeCreationTime(),
|
|
36
|
+
chainId: KADENA_CHAIN_ID,
|
|
37
|
+
gasLimit: gasLimitOverride || gasLimit,
|
|
38
|
+
})
|
|
39
|
+
.setNetworkId(KADENA_NETWORK)
|
|
40
|
+
.addSigner(kadenaAccount.publicKey, (withCapability) => [
|
|
41
|
+
withCapability(`${KADENA_NAMESPACE}.DALOS.GAS_PAYER`, "", { int: 0 }, { decimal: "0.0" }),
|
|
42
|
+
withCapability("coin.TRANSFER", `k:${kadenaAccount.publicKey}`, STOA_AUTONOMIC_LIQUIDPOT, { decimal: decimalAmount }),
|
|
43
|
+
])
|
|
44
|
+
.addSigner(guardAccount.publicKey)
|
|
45
|
+
.createTransaction();
|
|
46
|
+
};
|
|
47
|
+
const { dirtyRead, submit } = getFailoverClient(KADENA_CHAIN_ID);
|
|
48
|
+
// First do a simulation to check gas
|
|
49
|
+
let transaction = buildTransaction();
|
|
50
|
+
const simulation = await dirtyRead(transaction);
|
|
51
|
+
// Check if simulation failed
|
|
52
|
+
if (simulation.result.status === "failure") {
|
|
53
|
+
const errorMessage = simulation.result.error?.message || "Transaction simulation failed";
|
|
54
|
+
throw new Error(`Simulation failed: ${errorMessage}`);
|
|
55
|
+
}
|
|
56
|
+
// Check if we need to adjust gas limit
|
|
57
|
+
const requiredGas = simulation.gas;
|
|
58
|
+
if (requiredGas && requiredGas > gasLimit) {
|
|
59
|
+
// Rebuild transaction with adjusted gas limit (20% buffer)
|
|
60
|
+
gasLimit = calculateAutoGasLimit(requiredGas);
|
|
61
|
+
transaction = buildTransaction(gasLimit);
|
|
62
|
+
}
|
|
63
|
+
// Sign the transaction with both keypairs
|
|
64
|
+
const signedTransaction = await universalSignTransaction(transaction, [
|
|
65
|
+
fromKeypair(kadenaAccount),
|
|
66
|
+
fromKeypair(guardAccount),
|
|
67
|
+
]);
|
|
68
|
+
// Submit the signed transaction
|
|
69
|
+
const result = await submit(signedTransaction);
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
// unwrap Kadena
|
|
73
|
+
// (ouronet-ns.TS01-C2.LQD|C_UnwrapStoa patron unwrapper amount)
|
|
74
|
+
export async function unwrapKadena(patronAccount, // Ouro account that owns the WSTOA
|
|
75
|
+
unwrapperAccount, // Ouro address that will receive the unwrapped KDA
|
|
76
|
+
kadenaAccount, // The kadena account (payer)
|
|
77
|
+
guardAccount, // The guard account from the Ouro account
|
|
78
|
+
amount) {
|
|
79
|
+
// Ensure amount is formatted as decimal
|
|
80
|
+
const decimalAmount = formatDecimalForPact(amount);
|
|
81
|
+
let gasLimit = 2000000; // Default gas limit for unwrap operation
|
|
82
|
+
const buildTransaction = (gasLimitOverride) => {
|
|
83
|
+
return Pact.builder
|
|
84
|
+
.execution(`(${KADENA_NAMESPACE}.TS01-C2.LQD|C_UnwrapStoa "${patronAccount.address}" "${unwrapperAccount}" ${decimalAmount})`)
|
|
85
|
+
.setMeta({
|
|
86
|
+
senderAccount: STOA_AUTONOMIC_OURONETGASSTATION,
|
|
87
|
+
creationTime: safeCreationTime(),
|
|
88
|
+
chainId: KADENA_CHAIN_ID,
|
|
89
|
+
gasLimit: gasLimitOverride || gasLimit,
|
|
90
|
+
})
|
|
91
|
+
.setNetworkId(KADENA_NETWORK)
|
|
92
|
+
.addSigner(kadenaAccount.publicKey, (withCapability) => [
|
|
93
|
+
withCapability(`${KADENA_NAMESPACE}.DALOS.GAS_PAYER`, "", { int: 0 }, { decimal: "0.0" }),
|
|
94
|
+
withCapability("coin.TRANSFER", STOA_AUTONOMIC_LIQUIDPOT, `k:${kadenaAccount.publicKey}`, { decimal: decimalAmount }),
|
|
95
|
+
])
|
|
96
|
+
.addSigner(guardAccount.publicKey)
|
|
97
|
+
.createTransaction();
|
|
98
|
+
};
|
|
99
|
+
const { dirtyRead, submit } = getFailoverClient(KADENA_CHAIN_ID);
|
|
100
|
+
// First do a simulation to check gas
|
|
101
|
+
let transaction = buildTransaction();
|
|
102
|
+
const simulation = await dirtyRead(transaction);
|
|
103
|
+
// Check if simulation failed
|
|
104
|
+
if (simulation.result.status === "failure") {
|
|
105
|
+
const errorMessage = simulation.result.error?.message || "Transaction simulation failed";
|
|
106
|
+
throw new Error(`Simulation failed: ${errorMessage}`);
|
|
107
|
+
}
|
|
108
|
+
// Check if we need to adjust gas limit
|
|
109
|
+
const requiredGas = simulation.gas;
|
|
110
|
+
if (requiredGas && requiredGas > gasLimit) {
|
|
111
|
+
// Rebuild transaction with adjusted gas limit (20% buffer)
|
|
112
|
+
gasLimit = calculateAutoGasLimit(requiredGas);
|
|
113
|
+
transaction = buildTransaction(gasLimit);
|
|
114
|
+
}
|
|
115
|
+
// Sign the transaction with both keypairs
|
|
116
|
+
const signedTransaction = await universalSignTransaction(transaction, [
|
|
117
|
+
fromKeypair(kadenaAccount),
|
|
118
|
+
fromKeypair(guardAccount),
|
|
119
|
+
]);
|
|
120
|
+
// Submit the signed transaction
|
|
121
|
+
const result = await submit(signedTransaction);
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Resolve the target Kadena address for an Ouronet unwrapper account.
|
|
126
|
+
* (ouronet-ns.DALOS.UR_AccountKadena <unwrapper>)
|
|
127
|
+
*/
|
|
128
|
+
export async function getUnwrapStoaTarget(unwrapper) {
|
|
129
|
+
try {
|
|
130
|
+
const pactCode = `(${KADENA_NAMESPACE}.DALOS.UR_AccountKadena "${unwrapper}")`;
|
|
131
|
+
const response = await pactRead(pactCode, { tier: "T5" });
|
|
132
|
+
if (response?.result?.status === "success") {
|
|
133
|
+
return String(response.result.data);
|
|
134
|
+
}
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
getLogger().error("Error resolving UnwrapStoa target:", error);
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
export async function getUnwrapStoaInfo(patron, unwrapper, amount) {
|
|
143
|
+
try {
|
|
144
|
+
const decimalAmount = formatDecimalForPact(amount);
|
|
145
|
+
const pactCode = `(${KADENA_NAMESPACE}.INFO-ONE.LIQUID|INFO_UnwrapStoa "${patron}" "${unwrapper}" ${decimalAmount})`;
|
|
146
|
+
const response = await pactRead(pactCode, { tier: "T2" });
|
|
147
|
+
if (response?.result?.status === "success") {
|
|
148
|
+
return response.result.data;
|
|
149
|
+
}
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
getLogger().error("Error getting UnwrapStoa info:", error);
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
// ─── executeUnwrapStoa ────────────────────────────────────────────────────────
|
|
158
|
+
// Handles both execution cases for UnwrapStoa:
|
|
159
|
+
// Case 2 — target exists → simple unwrap
|
|
160
|
+
// Case 1 — target is new k: account → create account + unwrap
|
|
161
|
+
// Adaptive gas: simulate first, then rebuild with calculateAutoGasLimit.
|
|
162
|
+
export async function executeUnwrapStoa(params) {
|
|
163
|
+
const { patronAddress, unwrapperAddress, amount, numAmount, targetAddress, targetExists, gasStationKey, patronGuardKeys, accountGuardKeys, } = params;
|
|
164
|
+
// All unique signers (gas station first, then guard keys de-duped)
|
|
165
|
+
const allSigners = [gasStationKey];
|
|
166
|
+
const addedPubs = new Set([gasStationKey.publicKey]);
|
|
167
|
+
for (const k of [...patronGuardKeys, ...accountGuardKeys]) {
|
|
168
|
+
if (!addedPubs.has(k.publicKey)) {
|
|
169
|
+
allSigners.push(k);
|
|
170
|
+
addedPubs.add(k.publicKey);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
let gasLimit = 2000000;
|
|
174
|
+
const buildTransaction = (gasLimitOverride) => {
|
|
175
|
+
const effectiveGasLimit = gasLimitOverride ?? gasLimit;
|
|
176
|
+
let builder = targetExists
|
|
177
|
+
// Case 2 — target exists: simple unwrap
|
|
178
|
+
? Pact.builder.execution(`(${KADENA_NAMESPACE}.TS01-C2.LQD|C_UnwrapStoa "${patronAddress}" "${unwrapperAddress}" ${amount})`)
|
|
179
|
+
// Case 1 — new k: account: create + unwrap
|
|
180
|
+
: Pact.builder
|
|
181
|
+
.execution(`(namespace "${KADENA_NAMESPACE}")\n` +
|
|
182
|
+
`(IGNIS.C_Collect "${patronAddress}" (IGNIS.UDC_CustomCodeCumulator))\n` +
|
|
183
|
+
`(let\n` +
|
|
184
|
+
` (\n` +
|
|
185
|
+
` (wp:string "${unwrapperAddress}")\n` +
|
|
186
|
+
` (target:string (DALOS.UR_AccountKadena wp))\n` +
|
|
187
|
+
` )\n` +
|
|
188
|
+
` [\n` +
|
|
189
|
+
` (coin.C_CreateAccount target (read-keyset "ks"))\n` +
|
|
190
|
+
` (TS01-C2.LQD|C_UnwrapStoa "${patronAddress}" "${unwrapperAddress}" ${amount})\n` +
|
|
191
|
+
` ]\n` +
|
|
192
|
+
`)`)
|
|
193
|
+
.addData("ks", {
|
|
194
|
+
keys: [targetAddress.slice(2)], // k:<pubkey> → strip "k:"
|
|
195
|
+
pred: "keys-all",
|
|
196
|
+
});
|
|
197
|
+
builder = builder
|
|
198
|
+
.setMeta({ senderAccount: STOA_AUTONOMIC_OURONETGASSTATION, chainId: KADENA_CHAIN_ID, creationTime: safeCreationTime(),
|
|
199
|
+
gasLimit: effectiveGasLimit })
|
|
200
|
+
.setNetworkId(KADENA_NETWORK)
|
|
201
|
+
// Gas Station: GAS_PAYER + coin.TRANSFER
|
|
202
|
+
.addSigner(gasStationKey.publicKey, (w) => [
|
|
203
|
+
w(`${KADENA_NAMESPACE}.DALOS.GAS_PAYER`, "", { int: 0 }, { decimal: "0.0" }),
|
|
204
|
+
w("coin.TRANSFER", STOA_AUTONOMIC_LIQUIDPOT, targetAddress, { decimal: String(numAmount) }),
|
|
205
|
+
]);
|
|
206
|
+
// Patron + account guard keys: pure signers
|
|
207
|
+
const addedSignerPubs = new Set([gasStationKey.publicKey]);
|
|
208
|
+
for (const k of [...patronGuardKeys, ...accountGuardKeys]) {
|
|
209
|
+
if (!addedSignerPubs.has(k.publicKey)) {
|
|
210
|
+
builder = builder.addSigner(k.publicKey);
|
|
211
|
+
addedSignerPubs.add(k.publicKey);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return builder.createTransaction();
|
|
215
|
+
};
|
|
216
|
+
const { dirtyRead, submit } = getFailoverClient(KADENA_CHAIN_ID);
|
|
217
|
+
// 1. Simulate with 2M (network max)
|
|
218
|
+
let transaction = buildTransaction();
|
|
219
|
+
const simulation = await dirtyRead(transaction);
|
|
220
|
+
if (simulation.result.status === "failure") {
|
|
221
|
+
const error = createSimulationError("Unwrap STOA", simulation.result, `Patron: ${patronAddress} | Unwrapper: ${unwrapperAddress} | Target: ${targetAddress} | Amount: ${amount}`);
|
|
222
|
+
logDetailedError(error);
|
|
223
|
+
throw error;
|
|
224
|
+
}
|
|
225
|
+
// 2. Adaptive gas: rebuild with calibrated limit
|
|
226
|
+
const requiredGas = simulation.gas;
|
|
227
|
+
if (requiredGas) {
|
|
228
|
+
gasLimit = calculateAutoGasLimit(requiredGas);
|
|
229
|
+
transaction = buildTransaction(gasLimit);
|
|
230
|
+
}
|
|
231
|
+
// 3. Sign & submit
|
|
232
|
+
const signed = await universalSignTransaction(transaction, allSigners.map((s) => fromKeypair(s)));
|
|
233
|
+
return await submit(signed);
|
|
234
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type IKadenaKeypair } from "@stoachain/stoa-core/signing";
|
|
2
|
+
import type { IOuroAccountKeypair } from "./ouroTypes.js";
|
|
3
|
+
export declare function brumateWkdaToPkda(ouroAccount: IOuroAccountKeypair, kadenaAccount: IKadenaKeypair, guard: IKadenaKeypair, wkdaAmount: string, lockDays: number): Promise<import("@stoachain/kadena-stoic-legacy/client").ITransactionDescriptor>;
|
|
4
|
+
export declare function constrictLkdaToPkda(ouroAccount: IOuroAccountKeypair, kadenaAccount: IKadenaKeypair, guard: IKadenaKeypair, lkdaAmount: string, lockDays: number): Promise<import("@stoachain/kadena-stoic-legacy/client").ITransactionDescriptor>;
|
|
5
|
+
/**
|
|
6
|
+
* Get Hibernate/Pension entry fee for a specific lock period
|
|
7
|
+
* Formula: 12% - 0.0008% per day locked (0% at 15000 days)
|
|
8
|
+
* @param korIndexId - KORIndex pool ID (e.g., "GoldenStoaPillar-O136CBn22ncY")
|
|
9
|
+
* @param lockDays - Number of days to lock
|
|
10
|
+
* @returns Fee as decimal (e.g., 0.12 for 12%)
|
|
11
|
+
*/
|
|
12
|
+
export declare function getHibernateFee(korIndexId: string, lockDays: number): Promise<number>;
|
|
@@ -0,0 +1,127 @@
|
|
|
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 { formatDecimalForPact, safeCreationTime } from "@stoachain/stoa-core/pact";
|
|
4
|
+
import { Pact } from "@stoachain/kadena-stoic-legacy/client";
|
|
5
|
+
import { getFailoverClient } from "@stoachain/stoa-core/network";
|
|
6
|
+
import { pactRead } from "@stoachain/stoa-core/reads";
|
|
7
|
+
import { universalSignTransaction, fromKeypair } from "@stoachain/stoa-core/signing";
|
|
8
|
+
// Brumate WSTOA to H|GSTOA (Hibernated Pension Kadena)
|
|
9
|
+
// (namespace.TS01-C2.ATS|C_Brumate patron:string brumate-account:string "SilverStoaPillar-O136CBn22ncY" "GoldenStoaPillar-O136CBn22ncY" "WSTOA-8Nh-JO8JO4F5" amount:decimal lock-days:integer)
|
|
10
|
+
export async function brumateWkdaToPkda(ouroAccount, kadenaAccount, guard, wkdaAmount, lockDays) {
|
|
11
|
+
const keysetName = `ks`;
|
|
12
|
+
const decimalAmount = formatDecimalForPact(wkdaAmount);
|
|
13
|
+
let gasLimit = 2000000;
|
|
14
|
+
const buildTransaction = (gasLimitOverride) => {
|
|
15
|
+
return Pact.builder
|
|
16
|
+
.execution(`(${KADENA_NAMESPACE}.TS01-C2.ATS|C_Brumate "${ouroAccount.address}" "${ouroAccount.address}" "SilverStoaPillar-O136CBn22ncY" "GoldenStoaPillar-O136CBn22ncY" "WSTOA-8Nh-JO8JO4F5" ${decimalAmount} ${lockDays})`)
|
|
17
|
+
.addData(keysetName, {
|
|
18
|
+
keys: [guard.publicKey],
|
|
19
|
+
pred: "keys-all",
|
|
20
|
+
})
|
|
21
|
+
.setMeta({
|
|
22
|
+
senderAccount: STOA_AUTONOMIC_OURONETGASSTATION,
|
|
23
|
+
creationTime: safeCreationTime(),
|
|
24
|
+
chainId: KADENA_CHAIN_ID,
|
|
25
|
+
gasLimit: gasLimitOverride || gasLimit,
|
|
26
|
+
})
|
|
27
|
+
.setNetworkId(KADENA_NETWORK)
|
|
28
|
+
.addSigner(kadenaAccount.publicKey, (withCapability) => [
|
|
29
|
+
withCapability(`${KADENA_NAMESPACE}.DALOS.GAS_PAYER`, "", { int: 0 }, { decimal: "0.0" }),
|
|
30
|
+
])
|
|
31
|
+
.addSigner(guard.publicKey)
|
|
32
|
+
.createTransaction();
|
|
33
|
+
};
|
|
34
|
+
const { dirtyRead, submit } = getFailoverClient(KADENA_CHAIN_ID);
|
|
35
|
+
let transaction = buildTransaction();
|
|
36
|
+
const simulation = await dirtyRead(transaction);
|
|
37
|
+
if (simulation.result.status === "failure") {
|
|
38
|
+
const errorMessage = simulation.result.error?.message || "Transaction simulation failed";
|
|
39
|
+
throw new Error(`Simulation failed: ${errorMessage}`);
|
|
40
|
+
}
|
|
41
|
+
const requiredGas = simulation.gas;
|
|
42
|
+
if (requiredGas && requiredGas > gasLimit) {
|
|
43
|
+
gasLimit = calculateAutoGasLimit(requiredGas);
|
|
44
|
+
transaction = buildTransaction(gasLimit);
|
|
45
|
+
}
|
|
46
|
+
const signedTransaction = await universalSignTransaction(transaction, [
|
|
47
|
+
fromKeypair(kadenaAccount),
|
|
48
|
+
fromKeypair(guard),
|
|
49
|
+
]);
|
|
50
|
+
const result = await submit(signedTransaction);
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
// Constrict SSTOA to H|GSTOA (Hibernated Pension Kadena)
|
|
54
|
+
// (namespace.TS01-C2.ATS|C_Constrict patron:string constrictor:string "GoldenStoaPillar-O136CBn22ncY" "SSTOA-8Nh-JO8JO4F5" amount:decimal lock-days:integer)
|
|
55
|
+
export async function constrictLkdaToPkda(ouroAccount, kadenaAccount, guard, lkdaAmount, lockDays) {
|
|
56
|
+
const keysetName = `ks`;
|
|
57
|
+
const decimalAmount = formatDecimalForPact(lkdaAmount);
|
|
58
|
+
let gasLimit = 2000000;
|
|
59
|
+
const buildTransaction = (gasLimitOverride) => {
|
|
60
|
+
return Pact.builder
|
|
61
|
+
.execution(`(${KADENA_NAMESPACE}.TS01-C2.ATS|C_Constrict "${ouroAccount.address}" "${ouroAccount.address}" "GoldenStoaPillar-O136CBn22ncY" "SSTOA-8Nh-JO8JO4F5" ${decimalAmount} ${lockDays})`)
|
|
62
|
+
.addData(keysetName, {
|
|
63
|
+
keys: [guard.publicKey],
|
|
64
|
+
pred: "keys-all",
|
|
65
|
+
})
|
|
66
|
+
.setMeta({
|
|
67
|
+
senderAccount: STOA_AUTONOMIC_OURONETGASSTATION,
|
|
68
|
+
creationTime: safeCreationTime(),
|
|
69
|
+
chainId: KADENA_CHAIN_ID,
|
|
70
|
+
gasLimit: gasLimitOverride || gasLimit,
|
|
71
|
+
})
|
|
72
|
+
.setNetworkId(KADENA_NETWORK)
|
|
73
|
+
.addSigner(kadenaAccount.publicKey, (withCapability) => [
|
|
74
|
+
withCapability(`${KADENA_NAMESPACE}.DALOS.GAS_PAYER`, "", { int: 0 }, { decimal: "0.0" }),
|
|
75
|
+
])
|
|
76
|
+
.addSigner(guard.publicKey)
|
|
77
|
+
.createTransaction();
|
|
78
|
+
};
|
|
79
|
+
const { dirtyRead, submit } = getFailoverClient(KADENA_CHAIN_ID);
|
|
80
|
+
let transaction = buildTransaction();
|
|
81
|
+
const simulation = await dirtyRead(transaction);
|
|
82
|
+
if (simulation.result.status === "failure") {
|
|
83
|
+
const errorMessage = simulation.result.error?.message || "Transaction simulation failed";
|
|
84
|
+
throw new Error(`Simulation failed: ${errorMessage}`);
|
|
85
|
+
}
|
|
86
|
+
const requiredGas = simulation.gas;
|
|
87
|
+
if (requiredGas && requiredGas > gasLimit) {
|
|
88
|
+
gasLimit = calculateAutoGasLimit(requiredGas);
|
|
89
|
+
transaction = buildTransaction(gasLimit);
|
|
90
|
+
}
|
|
91
|
+
const signedTransaction = await universalSignTransaction(transaction, [
|
|
92
|
+
fromKeypair(kadenaAccount),
|
|
93
|
+
fromKeypair(guard),
|
|
94
|
+
]);
|
|
95
|
+
const result = await submit(signedTransaction);
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Get Hibernate/Pension entry fee for a specific lock period
|
|
100
|
+
* Formula: 12% - 0.0008% per day locked (0% at 15000 days)
|
|
101
|
+
* @param korIndexId - KORIndex pool ID (e.g., "GoldenStoaPillar-O136CBn22ncY")
|
|
102
|
+
* @param lockDays - Number of days to lock
|
|
103
|
+
* @returns Fee as decimal (e.g., 0.12 for 12%)
|
|
104
|
+
*/
|
|
105
|
+
export async function getHibernateFee(korIndexId, lockDays) {
|
|
106
|
+
try {
|
|
107
|
+
const response = await pactRead(`(${KADENA_NAMESPACE}.DPL-UR.URC_0012_HibernateFee "${korIndexId}" ${lockDays})`, { tier: "T2" });
|
|
108
|
+
if (!response || !response.result) {
|
|
109
|
+
throw new Error("Failed to retrieve hibernate fee");
|
|
110
|
+
}
|
|
111
|
+
if (response.result.status === "failure") {
|
|
112
|
+
throw new Error(`Hibernate fee query failed: ${response.result.error?.message || "Unknown error"}`);
|
|
113
|
+
}
|
|
114
|
+
const data = response.result.data;
|
|
115
|
+
// API returns decimal value, convert to number
|
|
116
|
+
if (typeof data === 'object' && data !== null && 'decimal' in data) {
|
|
117
|
+
return parseFloat(String(data.decimal));
|
|
118
|
+
}
|
|
119
|
+
return typeof data === 'number' ? data : parseFloat(String(data));
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
// Silent fallback - function may not be deployed yet on blockchain
|
|
123
|
+
// Using local calculation: 12% - 0.0008% per day (0% at 15000 days)
|
|
124
|
+
const fee = 0.12 - (0.000008 * lockDays);
|
|
125
|
+
return Math.max(0, fee); // Never negative
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* urStoaFunctions.ts — Native UrStoa on-chain interactions
|
|
3
|
+
*
|
|
4
|
+
* Balance: (try 0.0 (coin.UR_UR|Balance "<account>"))
|
|
5
|
+
* Guard: (try false (coin.UR_UR|Guard "<account>"))
|
|
6
|
+
* Transfer: coin.C_UR|Transfer / Transmit / TransferAnew / TransmitAnew
|
|
7
|
+
*/
|
|
8
|
+
import { type IKadenaKeypair } from "@stoachain/stoa-core/signing";
|
|
9
|
+
export interface UrStoaGuardResult {
|
|
10
|
+
exists: boolean;
|
|
11
|
+
guard?: any;
|
|
12
|
+
isKeyset: boolean;
|
|
13
|
+
keys: string[];
|
|
14
|
+
pred: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function getUrStoaBalance(account: string): Promise<number | null>;
|
|
17
|
+
export declare function getUrStoaGuard(account: string): Promise<UrStoaGuardResult | null>;
|
|
18
|
+
/** Keypair with optional Chainweaver/Ecko signing fields */
|
|
19
|
+
export interface UrStoaKeypair {
|
|
20
|
+
publicKey: string;
|
|
21
|
+
privateKey?: string;
|
|
22
|
+
secretKey?: string;
|
|
23
|
+
seedType?: string;
|
|
24
|
+
encryptedSecretKey?: any;
|
|
25
|
+
password?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface ExecuteNativeUrStoaParams {
|
|
28
|
+
senderAddress: string;
|
|
29
|
+
receiverAddress: string;
|
|
30
|
+
amount: string;
|
|
31
|
+
paymentKeyAddress: string;
|
|
32
|
+
paymentKeypair: UrStoaKeypair;
|
|
33
|
+
senderGuardKeys: UrStoaKeypair[];
|
|
34
|
+
isTransferFamily: boolean;
|
|
35
|
+
receiverExists: boolean;
|
|
36
|
+
receiverKeyset?: {
|
|
37
|
+
keys: string[];
|
|
38
|
+
pred: string;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export declare function executeNativeUrStoaTransfer(params: ExecuteNativeUrStoaParams): Promise<any>;
|
|
42
|
+
/**
|
|
43
|
+
* (coin.C_URV|Stake <account:string> <urstoa-amount:decimal>)
|
|
44
|
+
* Caps: GAS_PAYER + coin.URV|STAKE(account, amount) — both on payment key
|
|
45
|
+
*/
|
|
46
|
+
export interface StakeUrStoaParams {
|
|
47
|
+
paymentKeyAddress: string;
|
|
48
|
+
amount: string;
|
|
49
|
+
/**
|
|
50
|
+
* @deprecated since v3.2.1 — the `amount` string is now the single source
|
|
51
|
+
* of truth. `numAmount` is retained on the interface for non-breaking
|
|
52
|
+
* compatibility with v3.x callers but is no longer read by the executor.
|
|
53
|
+
* Will be removed in v4.0.0.
|
|
54
|
+
*/
|
|
55
|
+
numAmount?: number;
|
|
56
|
+
gasStationKey: IKadenaKeypair;
|
|
57
|
+
}
|
|
58
|
+
export declare function executeStakeUrStoa(params: StakeUrStoaParams): Promise<any>;
|
|
59
|
+
/**
|
|
60
|
+
* (coin.C_URV|Unstake <account:string> <urstoa-amount:decimal>)
|
|
61
|
+
* Caps: GAS_PAYER + coin.URV|UNSTAKE(account, amount) — both on payment key
|
|
62
|
+
*/
|
|
63
|
+
export interface UnstakeUrStoaParams {
|
|
64
|
+
paymentKeyAddress: string;
|
|
65
|
+
amount: string;
|
|
66
|
+
/**
|
|
67
|
+
* @deprecated since v3.2.1 — same rationale as `StakeUrStoaParams.numAmount`.
|
|
68
|
+
* Retained for non-breaking compatibility; will be removed in v4.0.0.
|
|
69
|
+
*/
|
|
70
|
+
numAmount?: number;
|
|
71
|
+
gasStationKey: IKadenaKeypair;
|
|
72
|
+
}
|
|
73
|
+
export declare function executeUnstakeUrStoa(params: UnstakeUrStoaParams): Promise<any>;
|
|
74
|
+
/**
|
|
75
|
+
* Polls for urStoa account existence in the coin table using:
|
|
76
|
+
* (if (= (typeof (try false (coin.UR_Balance account))) "bool") false true)
|
|
77
|
+
*
|
|
78
|
+
* Returns: true = exists, null = doesn't exist OR RPC error (both collapse
|
|
79
|
+
* to a non-existence/uncertainty signal — callers should treat null as
|
|
80
|
+
* "do not proceed assuming the account exists").
|
|
81
|
+
*
|
|
82
|
+
* @see {@link checkCoinAccountExists} in `ouroFunctions.ts` — both functions
|
|
83
|
+
* share the nullable-boolean return shape (`Promise<boolean | null>`) but
|
|
84
|
+
* differ in account scope: this one probes urStoa account existence via
|
|
85
|
+
* `coin.UR_Balance`; the sibling probes a generic coin account via
|
|
86
|
+
* `coin.get-balance`. Renaming to disambiguate the two identifiers is
|
|
87
|
+
* deferred to a separate breaking change to keep the consumer migration
|
|
88
|
+
* surface tight.
|
|
89
|
+
*/
|
|
90
|
+
export declare function checkCoinAccountExists(account: string): Promise<boolean | null>;
|
|
91
|
+
/**
|
|
92
|
+
* (coin.C_URV|Collect <account:string>)
|
|
93
|
+
* Caps: GAS_PAYER + coin.URV|COLLECT(account)
|
|
94
|
+
*
|
|
95
|
+
* If accountExists=false, wraps in 2-line tx:
|
|
96
|
+
* (coin.C_CreateAccount <account> (read-keyset "ks"))
|
|
97
|
+
* (coin.C_URV|Collect <account>)
|
|
98
|
+
*/
|
|
99
|
+
export interface CollectUrStoaParams {
|
|
100
|
+
paymentKeyAddress: string;
|
|
101
|
+
gasStationKey: IKadenaKeypair;
|
|
102
|
+
accountExists?: boolean;
|
|
103
|
+
}
|
|
104
|
+
export declare function executeCollectUrStoa(params: CollectUrStoaParams): Promise<any>;
|