@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,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dexSwapPairCalcFunctions.ts
|
|
3
|
+
* Swap pair calculation reads (URC_0006-0011 swap math, decimals, total fee).
|
|
4
|
+
*/
|
|
5
|
+
import type { SwapCalculationResult, InverseSwapResult, CappedInverseResult, UserAccountSupplies } from "./dexTypes.js";
|
|
6
|
+
/**
|
|
7
|
+
* Calculate direct swap output amounts
|
|
8
|
+
*
|
|
9
|
+
* Returns null on RPC failure (catch-and-return-null contract, v4.2.0).
|
|
10
|
+
*/
|
|
11
|
+
export declare function calculateDirectSwap(account: string, swpair: string, inputIds: string[], inputAmounts: string[] | number[], outputId: string): Promise<SwapCalculationResult | null>;
|
|
12
|
+
/**
|
|
13
|
+
* Calculate reverse swap input amounts (user specifies desired output)
|
|
14
|
+
*
|
|
15
|
+
* Returns null on RPC failure (catch-and-return-null contract, v4.2.0).
|
|
16
|
+
*/
|
|
17
|
+
export declare function calculateInverseSwap(account: string, swpair: string, outputId: string, outputAmount: number, inputId: string): Promise<InverseSwapResult | null>;
|
|
18
|
+
/**
|
|
19
|
+
* URC_0006b — Direct swap calculation, returns numeric output amount directly
|
|
20
|
+
*
|
|
21
|
+
* Returns null on RPC failure (catch-and-return-null contract, v4.2.0).
|
|
22
|
+
*/
|
|
23
|
+
export declare function calculateDirectSwapB(account: string, swpair: string, inputIds: string[], inputAmounts: string[] | number[], outputId: string): Promise<{
|
|
24
|
+
decimal: string;
|
|
25
|
+
} | number | null>;
|
|
26
|
+
/**
|
|
27
|
+
* URC_0007b — Inverse swap calculation, returns numeric input amount directly
|
|
28
|
+
*
|
|
29
|
+
* Returns null on RPC failure (catch-and-return-null contract, v4.2.0).
|
|
30
|
+
*/
|
|
31
|
+
export declare function calculateInverseSwapB(account: string, swpair: string, outputId: string, outputAmount: number, inputId: string): Promise<{
|
|
32
|
+
decimal: string;
|
|
33
|
+
} | number | null>;
|
|
34
|
+
/**
|
|
35
|
+
* Get maximum output amount for reverse swap (75% of token supply in pool)
|
|
36
|
+
*
|
|
37
|
+
* Returns null on RPC failure (catch-and-return-null contract, v4.2.0).
|
|
38
|
+
*/
|
|
39
|
+
export declare function getCappedInverseAmount(swpair: string, outputId: string): Promise<CappedInverseResult | null>;
|
|
40
|
+
/**
|
|
41
|
+
* Get user's token balances for all tokens in a specific swap pair
|
|
42
|
+
*
|
|
43
|
+
* Returns null on RPC failure (catch-and-return-null contract, v4.2.0).
|
|
44
|
+
*/
|
|
45
|
+
export declare function getUserAccountSupplies(account: string, swpair: string): Promise<UserAccountSupplies | null>;
|
|
46
|
+
/**
|
|
47
|
+
* Fetch decimal precision for a DPTF token via DPTF.UR_Decimals
|
|
48
|
+
* Returns the number of decimal places (e.g. 12 for high-precision tokens)
|
|
49
|
+
*/
|
|
50
|
+
export declare function getTokenDecimals(tokenId: string): Promise<number | null>;
|
|
51
|
+
/**
|
|
52
|
+
* Fetch total fee for a swap pair pool via SWP.URC_PoolTotalFee
|
|
53
|
+
* Returns fee as a decimal fraction (e.g. 0.003 = 0.3%)
|
|
54
|
+
*/
|
|
55
|
+
export declare function getPoolTotalFee(swpair: string): Promise<number | null>;
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dexSwapPairCalcFunctions.ts
|
|
3
|
+
* Swap pair calculation reads (URC_0006-0011 swap math, decimals, total fee).
|
|
4
|
+
*/
|
|
5
|
+
import { KADENA_NAMESPACE } from "../constants/index.js";
|
|
6
|
+
import { pactRead } from "@stoachain/stoa-core/reads";
|
|
7
|
+
import { getLogger } from "@stoachain/stoa-core/observability";
|
|
8
|
+
/**
|
|
9
|
+
* Calculate direct swap output amounts
|
|
10
|
+
*
|
|
11
|
+
* Returns null on RPC failure (catch-and-return-null contract, v4.2.0).
|
|
12
|
+
*/
|
|
13
|
+
export async function calculateDirectSwap(account, swpair, inputIds, inputAmounts, outputId) {
|
|
14
|
+
try {
|
|
15
|
+
// Format arrays for Pact with proper decimal formatting - keep as strings to preserve precision
|
|
16
|
+
const pactInputIds = `[${inputIds.map(id => `"${id}"`).join(' ')}]`;
|
|
17
|
+
const pactInputAmounts = `[${inputAmounts.map(amount => {
|
|
18
|
+
const amountStr = typeof amount === 'string' ? amount : amount.toString();
|
|
19
|
+
return amountStr.includes('.') ? amountStr : `${amountStr}.0`;
|
|
20
|
+
}).join(' ')}]`;
|
|
21
|
+
const pactCode = `(${KADENA_NAMESPACE}.DPL-UR.URC_0006_Swap "${account}" "${swpair}" ${pactInputIds} ${pactInputAmounts} "${outputId}")`;
|
|
22
|
+
const response = await pactRead(pactCode, { tier: "T2" });
|
|
23
|
+
if (!response || !response.result) {
|
|
24
|
+
throw new Error("Failed to retrieve direct swap calculation from the transaction.");
|
|
25
|
+
}
|
|
26
|
+
if (response.result.status === "failure") {
|
|
27
|
+
throw new Error(`Direct swap calculation failed: ${response.result.error?.message || "Unknown error"}`);
|
|
28
|
+
}
|
|
29
|
+
const data = response.result.data;
|
|
30
|
+
return data;
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
getLogger().error("Error in calculateDirectSwap:", error);
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Calculate reverse swap input amounts (user specifies desired output)
|
|
39
|
+
*
|
|
40
|
+
* Returns null on RPC failure (catch-and-return-null contract, v4.2.0).
|
|
41
|
+
*/
|
|
42
|
+
export async function calculateInverseSwap(account, swpair, outputId, outputAmount, inputId) {
|
|
43
|
+
try {
|
|
44
|
+
// Format outputAmount as decimal for Pact (e.g., 1 → "1.0")
|
|
45
|
+
const outputAmountDecimal = outputAmount.toString().includes('.') ? outputAmount.toString() : `${outputAmount}.0`;
|
|
46
|
+
const pactCode = `(${KADENA_NAMESPACE}.DPL-UR.URC_0007_InverseSwap "${account}" "${swpair}" "${outputId}" ${outputAmountDecimal} "${inputId}")`;
|
|
47
|
+
const response = await pactRead(pactCode, { tier: "T2" });
|
|
48
|
+
if (!response || !response.result) {
|
|
49
|
+
throw new Error("Failed to retrieve inverse swap calculation from the transaction.");
|
|
50
|
+
}
|
|
51
|
+
if (response.result.status === "failure") {
|
|
52
|
+
throw new Error(`Inverse swap calculation failed: ${response.result.error?.message || "Unknown error"}`);
|
|
53
|
+
}
|
|
54
|
+
const data = response.result.data;
|
|
55
|
+
return data;
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
getLogger().error("Error in calculateInverseSwap:", error);
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* URC_0006b — Direct swap calculation, returns numeric output amount directly
|
|
64
|
+
*
|
|
65
|
+
* Returns null on RPC failure (catch-and-return-null contract, v4.2.0).
|
|
66
|
+
*/
|
|
67
|
+
export async function calculateDirectSwapB(account, swpair, inputIds, inputAmounts, outputId) {
|
|
68
|
+
try {
|
|
69
|
+
const pactInputIds = `[${inputIds.map(id => `"${id}"`).join(' ')}]`;
|
|
70
|
+
const pactInputAmounts = `[${inputAmounts.map(a => {
|
|
71
|
+
const s = typeof a === 'string' ? a : a.toString();
|
|
72
|
+
return s.includes('.') ? s : `${s}.0`;
|
|
73
|
+
}).join(' ')}]`;
|
|
74
|
+
const pactCode = `(${KADENA_NAMESPACE}.DPL-UR.URC_0006b_DirectSwap "${account}" "${swpair}" ${pactInputIds} ${pactInputAmounts} "${outputId}")`;
|
|
75
|
+
const response = await pactRead(pactCode, { tier: "T2" });
|
|
76
|
+
if (!response?.result)
|
|
77
|
+
throw new Error("No response");
|
|
78
|
+
if (response.result.status === "failure")
|
|
79
|
+
throw new Error(response.result.error?.message ?? "Failed");
|
|
80
|
+
return response.result.data;
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
getLogger().error("Error in calculateDirectSwapB:", error);
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* URC_0007b — Inverse swap calculation, returns numeric input amount directly
|
|
89
|
+
*
|
|
90
|
+
* Returns null on RPC failure (catch-and-return-null contract, v4.2.0).
|
|
91
|
+
*/
|
|
92
|
+
export async function calculateInverseSwapB(account, swpair, outputId, outputAmount, inputId) {
|
|
93
|
+
try {
|
|
94
|
+
const outDecimal = outputAmount.toString().includes('.') ? outputAmount.toString() : `${outputAmount}.0`;
|
|
95
|
+
const pactCode = `(${KADENA_NAMESPACE}.DPL-UR.URC_0007b_InverseSwap "${account}" "${swpair}" "${outputId}" ${outDecimal} "${inputId}")`;
|
|
96
|
+
const response = await pactRead(pactCode, { tier: "T2" });
|
|
97
|
+
if (!response?.result)
|
|
98
|
+
throw new Error("No response");
|
|
99
|
+
if (response.result.status === "failure")
|
|
100
|
+
throw new Error(response.result.error?.message ?? "Failed");
|
|
101
|
+
return response.result.data;
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
getLogger().error("Error in calculateInverseSwapB:", error);
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Get maximum output amount for reverse swap (75% of token supply in pool)
|
|
110
|
+
*
|
|
111
|
+
* Returns null on RPC failure (catch-and-return-null contract, v4.2.0).
|
|
112
|
+
*/
|
|
113
|
+
export async function getCappedInverseAmount(swpair, outputId) {
|
|
114
|
+
try {
|
|
115
|
+
const pactCode = `(${KADENA_NAMESPACE}.DPL-UR.URC_0008_CappedInverse "${swpair}" "${outputId}")`;
|
|
116
|
+
const response = await pactRead(pactCode, { tier: "T5" });
|
|
117
|
+
if (!response || !response.result) {
|
|
118
|
+
throw new Error("Failed to retrieve capped inverse amount from the transaction.");
|
|
119
|
+
}
|
|
120
|
+
if (response.result.status === "failure") {
|
|
121
|
+
throw new Error(`Capped inverse query failed: ${response.result.error?.message || "Unknown error"}`);
|
|
122
|
+
}
|
|
123
|
+
const data = response.result.data;
|
|
124
|
+
return data;
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
getLogger().error("Error in getCappedInverseAmount:", error);
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Get user's token balances for all tokens in a specific swap pair
|
|
133
|
+
*
|
|
134
|
+
* Returns null on RPC failure (catch-and-return-null contract, v4.2.0).
|
|
135
|
+
*/
|
|
136
|
+
export async function getUserAccountSupplies(account, swpair) {
|
|
137
|
+
try {
|
|
138
|
+
const pactCode = `(${KADENA_NAMESPACE}.DPL-UR.URC_0011_AccountSuppliesForSwpair "${account}" "${swpair}")`;
|
|
139
|
+
const response = await pactRead(pactCode, { tier: "T5" });
|
|
140
|
+
if (!response || !response.result) {
|
|
141
|
+
throw new Error("Failed to retrieve user account supplies from the transaction.");
|
|
142
|
+
}
|
|
143
|
+
if (response.result.status === "failure") {
|
|
144
|
+
throw new Error(`User account supplies query failed: ${response.result.error?.message || "Unknown error"}`);
|
|
145
|
+
}
|
|
146
|
+
const data = response.result.data;
|
|
147
|
+
return data;
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
getLogger().error("Error in getUserAccountSupplies:", error);
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Fetch decimal precision for a DPTF token via DPTF.UR_Decimals
|
|
156
|
+
* Returns the number of decimal places (e.g. 12 for high-precision tokens)
|
|
157
|
+
*/
|
|
158
|
+
export async function getTokenDecimals(tokenId) {
|
|
159
|
+
try {
|
|
160
|
+
const response = await pactRead(`(${KADENA_NAMESPACE}.DPTF.UR_Decimals "${tokenId}")`, { tier: "T7" });
|
|
161
|
+
if (!response || !response.result || response.result.status === "failure") {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
const data = response.result.data;
|
|
165
|
+
if (typeof data === "number") {
|
|
166
|
+
return Number.isFinite(data) ? data : null;
|
|
167
|
+
}
|
|
168
|
+
if (data && typeof data === "object") {
|
|
169
|
+
if ("int" in data) {
|
|
170
|
+
const n = parseInt(data.int, 10);
|
|
171
|
+
return Number.isFinite(n) ? n : null;
|
|
172
|
+
}
|
|
173
|
+
if ("decimal" in data) {
|
|
174
|
+
const n = parseInt(data.decimal, 10);
|
|
175
|
+
return Number.isFinite(n) ? n : null;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
getLogger().error("Error in getTokenDecimals:", error);
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Local helper to resolve Pact decimal/int/number values to JS number
|
|
187
|
+
*/
|
|
188
|
+
function resolvePactDecimalLocal(val) {
|
|
189
|
+
if (val === null || val === undefined)
|
|
190
|
+
return 0;
|
|
191
|
+
if (typeof val === "number")
|
|
192
|
+
return val;
|
|
193
|
+
if (typeof val === "object") {
|
|
194
|
+
if ("decimal" in val)
|
|
195
|
+
return parseFloat(val.decimal);
|
|
196
|
+
if ("int" in val)
|
|
197
|
+
return parseInt(val.int, 10);
|
|
198
|
+
}
|
|
199
|
+
return parseFloat(String(val));
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Fetch total fee for a swap pair pool via SWP.URC_PoolTotalFee
|
|
203
|
+
* Returns fee as a decimal fraction (e.g. 0.003 = 0.3%)
|
|
204
|
+
*/
|
|
205
|
+
export async function getPoolTotalFee(swpair) {
|
|
206
|
+
try {
|
|
207
|
+
const response = await pactRead(`(${KADENA_NAMESPACE}.SWP.URC_PoolTotalFee "${swpair}")`, { tier: "T5" });
|
|
208
|
+
if (response?.result?.status === "success") {
|
|
209
|
+
const value = resolvePactDecimalLocal(response.result.data);
|
|
210
|
+
return Number.isFinite(value) ? value : null;
|
|
211
|
+
}
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
getLogger().error("Error in getPoolTotalFee:", error);
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dexSwapPairDashboardFunctions.ts
|
|
3
|
+
* Swap pair dashboard reads and pool previews (URC_0003-0005, URC_0010 dashboard surface).
|
|
4
|
+
*/
|
|
5
|
+
import type { SwapPoolData, PoolPreviewData, SwpairInternalDashboard } from "./dexTypes.js";
|
|
6
|
+
/**
|
|
7
|
+
* Fetch all swap pair IDs from the SWP contract
|
|
8
|
+
*
|
|
9
|
+
* Returns null on RPC failure (catch-and-return-null contract, v4.2.0).
|
|
10
|
+
*/
|
|
11
|
+
export declare function getPoolIds(): Promise<string[] | null>;
|
|
12
|
+
/**
|
|
13
|
+
* Fetch the primordial pool ID
|
|
14
|
+
*/
|
|
15
|
+
export declare function getPrimordialPool(): Promise<string | null>;
|
|
16
|
+
/**
|
|
17
|
+
* Fetch general information for all swap pairs
|
|
18
|
+
*
|
|
19
|
+
* Returns null on RPC failure (catch-and-return-null contract, v4.2.0).
|
|
20
|
+
*/
|
|
21
|
+
export declare function getSWPairGeneralInfo(): Promise<any>;
|
|
22
|
+
/**
|
|
23
|
+
* Fetch detailed dashboard information for a specific swap pair
|
|
24
|
+
*
|
|
25
|
+
* Returns null on RPC failure (catch-and-return-null contract, v4.2.0).
|
|
26
|
+
*/
|
|
27
|
+
export declare function getSWPairDashboardInfo(swpair: string): Promise<SwapPoolData | null>;
|
|
28
|
+
/**
|
|
29
|
+
* Fetch enhanced pool preview/dashboard data for a specific pool
|
|
30
|
+
* Returns richer data structure with formatted values and weights
|
|
31
|
+
*
|
|
32
|
+
* Returns null on RPC failure (catch-and-return-null contract, v4.2.0).
|
|
33
|
+
*/
|
|
34
|
+
export declare function getPoolPreviewData(poolId: string): Promise<PoolPreviewData | null>;
|
|
35
|
+
/**
|
|
36
|
+
* Fetch detailed dashboard information for multiple swap pairs
|
|
37
|
+
*
|
|
38
|
+
* Returns null on RPC failure (catch-and-return-null contract, v4.2.0).
|
|
39
|
+
*/
|
|
40
|
+
export declare function getSWPairMultiDashboardInfo(swpairs: string[]): Promise<SwapPoolData[] | null>;
|
|
41
|
+
/**
|
|
42
|
+
* Fetch comprehensive internal dashboard data for a specific swap pair
|
|
43
|
+
* Contains all pool stats including detailed analytics
|
|
44
|
+
*
|
|
45
|
+
* Returns null on RPC failure (catch-and-return-null contract, v4.2.0).
|
|
46
|
+
*/
|
|
47
|
+
export declare function getSwpairInternalDashboard(swpair: string): Promise<SwpairInternalDashboard | null>;
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dexSwapPairDashboardFunctions.ts
|
|
3
|
+
* Swap pair dashboard reads and pool previews (URC_0003-0005, URC_0010 dashboard surface).
|
|
4
|
+
*/
|
|
5
|
+
import { KADENA_NAMESPACE } from "../constants/index.js";
|
|
6
|
+
import { pactRead } from "@stoachain/stoa-core/reads";
|
|
7
|
+
import { getLogger } from "@stoachain/stoa-core/observability";
|
|
8
|
+
/**
|
|
9
|
+
* Fetch all swap pair IDs from the SWP contract
|
|
10
|
+
*
|
|
11
|
+
* Returns null on RPC failure (catch-and-return-null contract, v4.2.0).
|
|
12
|
+
*/
|
|
13
|
+
export async function getPoolIds() {
|
|
14
|
+
try {
|
|
15
|
+
const response = await pactRead(`(${KADENA_NAMESPACE}.SWP.URC_Swpairs)`, { tier: "T7" });
|
|
16
|
+
if (!response || !response.result) {
|
|
17
|
+
throw new Error("Failed to retrieve pool IDs from the transaction.");
|
|
18
|
+
}
|
|
19
|
+
if (response.result.status === "failure") {
|
|
20
|
+
throw new Error(`Pool IDs query failed: ${response.result.error?.message || "Unknown error"}`);
|
|
21
|
+
}
|
|
22
|
+
const data = response.result.data;
|
|
23
|
+
return Array.isArray(data) ? data : null;
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
getLogger().error("Error in getPoolIds:", error);
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Fetch the primordial pool ID
|
|
32
|
+
*/
|
|
33
|
+
export async function getPrimordialPool() {
|
|
34
|
+
try {
|
|
35
|
+
const response = await pactRead(`(${KADENA_NAMESPACE}.SWP.UR_PrimordialPool)`, { tier: "T7" });
|
|
36
|
+
if (response?.result?.status === "success") {
|
|
37
|
+
return String(response.result.data);
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
getLogger().error("Error in getPrimordialPool:", error);
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Fetch general information for all swap pairs
|
|
48
|
+
*
|
|
49
|
+
* Returns null on RPC failure (catch-and-return-null contract, v4.2.0).
|
|
50
|
+
*/
|
|
51
|
+
export async function getSWPairGeneralInfo() {
|
|
52
|
+
try {
|
|
53
|
+
const response = await pactRead(`(${KADENA_NAMESPACE}.DPL-UR.URC_0003_SWPairGeneralInfo)`, { tier: "T5" });
|
|
54
|
+
if (!response || !response.result) {
|
|
55
|
+
throw new Error("Failed to retrieve general swap pair info from the transaction.");
|
|
56
|
+
}
|
|
57
|
+
if (response.result.status === "failure") {
|
|
58
|
+
throw new Error(`General info query failed: ${response.result.error?.message || "Unknown error"}`);
|
|
59
|
+
}
|
|
60
|
+
return response.result.data;
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
getLogger().error("Error in getSWPairGeneralInfo:", error);
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Fetch detailed dashboard information for a specific swap pair
|
|
69
|
+
*
|
|
70
|
+
* Returns null on RPC failure (catch-and-return-null contract, v4.2.0).
|
|
71
|
+
*/
|
|
72
|
+
export async function getSWPairDashboardInfo(swpair) {
|
|
73
|
+
try {
|
|
74
|
+
const pactCode = `(${KADENA_NAMESPACE}.DPL-UR.URC_0004_SWPairDashboardInfo "${swpair}")`;
|
|
75
|
+
const response = await pactRead(pactCode, { tier: "T2" });
|
|
76
|
+
if (!response || !response.result) {
|
|
77
|
+
throw new Error("Failed to retrieve swap pair dashboard info from the transaction.");
|
|
78
|
+
}
|
|
79
|
+
if (response.result.status === "failure") {
|
|
80
|
+
throw new Error(`Dashboard info query failed: ${response.result.error?.message || "Unknown error"}`);
|
|
81
|
+
}
|
|
82
|
+
const data = response.result.data;
|
|
83
|
+
// Single pool API returns an object directly, not an array
|
|
84
|
+
if (data && typeof data === 'object' && !Array.isArray(data)) {
|
|
85
|
+
return data;
|
|
86
|
+
}
|
|
87
|
+
else if (Array.isArray(data) && data.length > 0) {
|
|
88
|
+
return data[0];
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
getLogger().error("Error in getSWPairDashboardInfo:", error);
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Fetch enhanced pool preview/dashboard data for a specific pool
|
|
101
|
+
* Returns richer data structure with formatted values and weights
|
|
102
|
+
*
|
|
103
|
+
* Returns null on RPC failure (catch-and-return-null contract, v4.2.0).
|
|
104
|
+
*/
|
|
105
|
+
export async function getPoolPreviewData(poolId) {
|
|
106
|
+
try {
|
|
107
|
+
const pactCode = `(${KADENA_NAMESPACE}.DPL-UR.URC_0004_SWPairDashboardInfo "${poolId}")`;
|
|
108
|
+
const response = await pactRead(pactCode, { tier: "T5" });
|
|
109
|
+
if (!response || !response.result) {
|
|
110
|
+
throw new Error("Failed to retrieve pool preview data from the transaction.");
|
|
111
|
+
}
|
|
112
|
+
if (response.result.status === "failure") {
|
|
113
|
+
throw new Error(`Pool preview query failed: ${response.result.error?.message || "Unknown error"}`);
|
|
114
|
+
}
|
|
115
|
+
const data = response.result.data;
|
|
116
|
+
// Enhanced pool API returns an object directly with additional formatted fields
|
|
117
|
+
if (data && typeof data === 'object' && !Array.isArray(data)) {
|
|
118
|
+
return data;
|
|
119
|
+
}
|
|
120
|
+
else if (Array.isArray(data) && data.length > 0) {
|
|
121
|
+
return data[0];
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
getLogger().error("Error in getPoolPreviewData:", error);
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Fetch detailed dashboard information for multiple swap pairs
|
|
134
|
+
*
|
|
135
|
+
* Returns null on RPC failure (catch-and-return-null contract, v4.2.0).
|
|
136
|
+
*/
|
|
137
|
+
export async function getSWPairMultiDashboardInfo(swpairs) {
|
|
138
|
+
try {
|
|
139
|
+
// Format array for Pact: ["id1" "id2" "id3"]
|
|
140
|
+
const pactArray = `[${swpairs.map(swpair => `"${swpair}"`).join(' ')}]`;
|
|
141
|
+
const response = await pactRead(`(${KADENA_NAMESPACE}.DPL-UR.URC_0005_SWPairMultiDashboardInfo ${pactArray})`, { tier: "T5" });
|
|
142
|
+
if (!response || !response.result) {
|
|
143
|
+
throw new Error("Failed to retrieve multi swap pair dashboard info from the transaction.");
|
|
144
|
+
}
|
|
145
|
+
if (response.result.status === "failure") {
|
|
146
|
+
throw new Error(`Multi dashboard info query failed: ${response.result.error?.message || "Unknown error"}`);
|
|
147
|
+
}
|
|
148
|
+
const data = response.result.data;
|
|
149
|
+
return Array.isArray(data) ? data : null;
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
getLogger().error("Error in getSWPairMultiDashboardInfo:", error);
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Fetch comprehensive internal dashboard data for a specific swap pair
|
|
158
|
+
* Contains all pool stats including detailed analytics
|
|
159
|
+
*
|
|
160
|
+
* Returns null on RPC failure (catch-and-return-null contract, v4.2.0).
|
|
161
|
+
*/
|
|
162
|
+
export async function getSwpairInternalDashboard(swpair) {
|
|
163
|
+
try {
|
|
164
|
+
const pactCode = `(${KADENA_NAMESPACE}.DPL-UR.URC_0010_SwpairInternalDashboard "${swpair}")`;
|
|
165
|
+
const response = await pactRead(pactCode, { tier: "T5" });
|
|
166
|
+
if (!response || !response.result) {
|
|
167
|
+
throw new Error("Failed to retrieve internal dashboard data from the transaction.");
|
|
168
|
+
}
|
|
169
|
+
if (response.result.status === "failure") {
|
|
170
|
+
throw new Error(`Internal dashboard query failed: ${response.result.error?.message || "Unknown error"}`);
|
|
171
|
+
}
|
|
172
|
+
const data = response.result.data;
|
|
173
|
+
return data;
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
getLogger().error("Error in getSwpairInternalDashboard:", error);
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dexSwapPairExecuteFunctions.ts
|
|
3
|
+
* Swap pair execution (single/multi pool, with/without slippage protection — TS01-C3 module).
|
|
4
|
+
*/
|
|
5
|
+
import type { SwapExecutionParams, SlippageBounds } from "./dexTypes.js";
|
|
6
|
+
/**
|
|
7
|
+
* Fetch slippage bounds object for a swap via dirtyRead.
|
|
8
|
+
* Must be called before executing a swap with slippage protection.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getSlippageBounds(swpair: string, inputIds: string[], inputAmounts: (string | number)[], outputId: string, slippage: number): Promise<SlippageBounds>;
|
|
11
|
+
/**
|
|
12
|
+
* Execute single swap with slippage protection
|
|
13
|
+
*/
|
|
14
|
+
export declare function executeSingleSwapWithSlippage(params: SwapExecutionParams & {
|
|
15
|
+
inputId: string;
|
|
16
|
+
inputAmount: string | number;
|
|
17
|
+
slippage: number;
|
|
18
|
+
}): Promise<any>;
|
|
19
|
+
/**
|
|
20
|
+
* Execute single swap without slippage protection
|
|
21
|
+
*/
|
|
22
|
+
export declare function executeSingleSwapNoSlippage(params: SwapExecutionParams & {
|
|
23
|
+
inputId: string;
|
|
24
|
+
inputAmount: string | number;
|
|
25
|
+
}): Promise<any>;
|
|
26
|
+
/**
|
|
27
|
+
* Execute multi-token swap with slippage protection
|
|
28
|
+
*/
|
|
29
|
+
export declare function executeMultiSwapWithSlippage(params: SwapExecutionParams & {
|
|
30
|
+
inputIds: string[];
|
|
31
|
+
inputAmounts: (string | number)[];
|
|
32
|
+
slippage: number;
|
|
33
|
+
}): Promise<any>;
|
|
34
|
+
/**
|
|
35
|
+
* Execute multi-token swap without slippage protection
|
|
36
|
+
*/
|
|
37
|
+
export declare function executeMultiSwapNoSlippage(params: SwapExecutionParams & {
|
|
38
|
+
inputIds: string[];
|
|
39
|
+
inputAmounts: (string | number)[];
|
|
40
|
+
}): Promise<any>;
|