aftermath-ts-sdk 1.2.64 → 1.2.66
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/dist/general/dynamicGas/dynamicGas.d.ts +34 -0
- package/dist/general/dynamicGas/dynamicGas.d.ts.map +1 -1
- package/dist/general/dynamicGas/dynamicGas.js +34 -0
- package/dist/general/dynamicGas/dynamicGasTypes.d.ts +25 -0
- package/dist/general/dynamicGas/dynamicGasTypes.d.ts.map +1 -1
- package/dist/general/prices/prices.d.ts +73 -0
- package/dist/general/prices/prices.d.ts.map +1 -1
- package/dist/general/prices/prices.js +73 -0
- package/dist/general/providers/aftermath.d.ts +106 -25
- package/dist/general/providers/aftermath.d.ts.map +1 -1
- package/dist/general/providers/aftermath.js +108 -27
- package/dist/general/providers/aftermathApi.d.ts +127 -8
- package/dist/general/providers/aftermathApi.d.ts.map +1 -1
- package/dist/general/providers/aftermathApi.js +132 -12
- package/dist/general/types/castingTypes.d.ts +0 -7
- package/dist/general/types/castingTypes.d.ts.map +1 -1
- package/dist/general/types/castingTypes.js +6 -0
- package/dist/general/types/generalTypes.d.ts +228 -7
- package/dist/general/types/generalTypes.d.ts.map +1 -1
- package/dist/general/types/suiTypes.d.ts +0 -16
- package/dist/general/types/suiTypes.d.ts.map +1 -1
- package/dist/general/types/suiTypes.js +3 -25
- package/dist/general/utils/casting.d.ts +159 -3
- package/dist/general/utils/casting.d.ts.map +1 -1
- package/dist/general/utils/casting.js +162 -16
- package/dist/general/utils/fixedUtils.d.ts +89 -2
- package/dist/general/utils/fixedUtils.d.ts.map +1 -1
- package/dist/general/utils/fixedUtils.js +81 -4
- package/dist/general/utils/helpers.d.ts +320 -9
- package/dist/general/utils/helpers.d.ts.map +1 -1
- package/dist/general/utils/helpers.js +350 -89
- package/dist/general/utils/iFixedUtils.d.ts +64 -0
- package/dist/general/utils/iFixedUtils.d.ts.map +1 -1
- package/dist/general/utils/iFixedUtils.js +64 -0
- package/dist/general/wallet/wallet.d.ts +75 -0
- package/dist/general/wallet/wallet.d.ts.map +1 -1
- package/dist/general/wallet/wallet.js +75 -5
- package/dist/packages/auth/auth.d.ts +113 -0
- package/dist/packages/auth/auth.d.ts.map +1 -1
- package/dist/packages/auth/auth.js +129 -15
- package/dist/packages/auth/authTypes.d.ts +66 -0
- package/dist/packages/auth/authTypes.d.ts.map +1 -1
- package/dist/packages/coin/coin.d.ts +250 -0
- package/dist/packages/coin/coin.d.ts.map +1 -1
- package/dist/packages/coin/coin.js +238 -14
- package/dist/packages/coin/coinTypes.d.ts +93 -0
- package/dist/packages/coin/coinTypes.d.ts.map +1 -1
- package/dist/packages/dca/dca.d.ts +124 -35
- package/dist/packages/dca/dca.d.ts.map +1 -1
- package/dist/packages/dca/dca.js +127 -37
- package/dist/packages/dca/dcaTypes.d.ts +213 -28
- package/dist/packages/dca/dcaTypes.d.ts.map +1 -1
- package/dist/packages/farms/farms.d.ts +184 -1
- package/dist/packages/farms/farms.d.ts.map +1 -1
- package/dist/packages/farms/farms.js +185 -11
- package/dist/packages/farms/farmsStakedPosition.d.ts +140 -6
- package/dist/packages/farms/farmsStakedPosition.d.ts.map +1 -1
- package/dist/packages/farms/farmsStakedPosition.js +189 -144
- package/dist/packages/farms/farmsStakingPool.d.ts +161 -1
- package/dist/packages/farms/farmsStakingPool.d.ts.map +1 -1
- package/dist/packages/farms/farmsStakingPool.js +178 -70
- package/dist/packages/farms/farmsTypes.d.ts +283 -2
- package/dist/packages/farms/farmsTypes.d.ts.map +1 -1
- package/dist/packages/farms/farmsTypes.js +18 -0
- package/dist/packages/limitOrders/limitOrders.d.ts +108 -21
- package/dist/packages/limitOrders/limitOrders.d.ts.map +1 -1
- package/dist/packages/limitOrders/limitOrders.js +110 -22
- package/dist/packages/limitOrders/limitOrdersTypes.d.ts +142 -0
- package/dist/packages/limitOrders/limitOrdersTypes.d.ts.map +1 -1
- package/dist/packages/multisig/multisig.d.ts +33 -4
- package/dist/packages/multisig/multisig.d.ts.map +1 -1
- package/dist/packages/multisig/multisig.js +33 -4
- package/dist/packages/multisig/multisigTypes.d.ts +17 -0
- package/dist/packages/multisig/multisigTypes.d.ts.map +1 -1
- package/dist/packages/perpetuals/api/perpetualsApi.d.ts.map +1 -1
- package/dist/packages/pools/pool.d.ts +327 -85
- package/dist/packages/pools/pool.d.ts.map +1 -1
- package/dist/packages/pools/pool.js +333 -91
- package/dist/packages/pools/pools.d.ts +299 -37
- package/dist/packages/pools/pools.d.ts.map +1 -1
- package/dist/packages/pools/pools.js +306 -52
- package/dist/packages/pools/poolsTypes.d.ts +267 -2
- package/dist/packages/pools/poolsTypes.d.ts.map +1 -1
- package/dist/packages/referralVault/referralVault.d.ts +37 -0
- package/dist/packages/referralVault/referralVault.d.ts.map +1 -1
- package/dist/packages/referralVault/referralVault.js +37 -0
- package/dist/packages/router/router.d.ts +213 -17
- package/dist/packages/router/router.d.ts.map +1 -1
- package/dist/packages/router/router.js +214 -18
- package/dist/packages/router/routerTypes.d.ts +198 -14
- package/dist/packages/router/routerTypes.d.ts.map +1 -1
- package/dist/packages/staking/staking.d.ts +301 -43
- package/dist/packages/staking/staking.d.ts.map +1 -1
- package/dist/packages/staking/staking.js +308 -51
- package/dist/packages/staking/stakingTypes.d.ts +426 -6
- package/dist/packages/staking/stakingTypes.d.ts.map +1 -1
- package/dist/packages/staking/stakingTypes.js +19 -0
- package/dist/packages/sui/sui.d.ts +39 -0
- package/dist/packages/sui/sui.d.ts.map +1 -1
- package/dist/packages/sui/sui.js +39 -0
- package/dist/packages/userData/userData.d.ts +66 -12
- package/dist/packages/userData/userData.d.ts.map +1 -1
- package/dist/packages/userData/userData.js +66 -12
- package/dist/packages/userData/userDataTypes.d.ts +19 -0
- package/dist/packages/userData/userDataTypes.d.ts.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +0 -1
- package/package.json +1 -1
- package/dist/general/historicalData/historicalData.d.ts +0 -15
- package/dist/general/historicalData/historicalData.d.ts.map +0 -1
- package/dist/general/historicalData/historicalData.js +0 -45
- package/dist/general/historicalData/historicalDataTypes.d.ts +0 -10
- package/dist/general/historicalData/historicalDataTypes.d.ts.map +0 -1
- package/dist/general/historicalData/historicalDataTypes.js +0 -2
|
@@ -1,27 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// =========================================================================
|
|
3
|
+
// Network
|
|
4
|
+
// =========================================================================
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
// export interface StakedSui {
|
|
4
|
-
// objectId: ObjectId;
|
|
5
|
-
// validatorAddress: SuiAddress;
|
|
6
|
-
// poolStartingEpoch: number;
|
|
7
|
-
// delegationRequestEpoch: number;
|
|
8
|
-
// principal: Balance;
|
|
9
|
-
// }
|
|
10
|
-
// export interface Delegation {
|
|
11
|
-
// objectId: ObjectId;
|
|
12
|
-
// stakedSuiId: ObjectId;
|
|
13
|
-
// poolTokens: Balance;
|
|
14
|
-
// principalSuiAmount: Balance;
|
|
15
|
-
// }
|
|
16
|
-
// export interface StakedSuiWithDelegation {
|
|
17
|
-
// stakedSui: StakedSui;
|
|
18
|
-
// delegation?: Delegation;
|
|
19
|
-
// }
|
|
20
|
-
// export interface AuthorityPublicKeyBytes {
|
|
21
|
-
// pubKey: string;
|
|
22
|
-
// bytes: bigint;
|
|
23
|
-
// }
|
|
24
|
-
// export interface CommitteeInfo {
|
|
25
|
-
// committeeInfo: AuthorityPublicKeyBytes[];
|
|
26
|
-
// epoch: EpochTimeStamp;
|
|
27
|
-
// }
|
|
@@ -15,43 +15,199 @@ import { SuiObjectResponse } from "@mysten/sui/client";
|
|
|
15
15
|
import { NftsApiCasting } from "../nfts/nftsApiCasting";
|
|
16
16
|
import { OracleApiCasting } from "../../packages/oracle/api/oracleApiCasting";
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
18
|
+
* A central utility class for casting and conversion routines across
|
|
19
|
+
* different Aftermath modules. Provides both direct numeric transformations
|
|
20
|
+
* (e.g., fixed-point arithmetic) and advanced BCS-based object deserialization.
|
|
20
21
|
*/
|
|
21
22
|
export declare class Casting {
|
|
23
|
+
/**
|
|
24
|
+
* Casting utilities for pools-related data (AMM pools, liquidity, etc.).
|
|
25
|
+
*/
|
|
22
26
|
static pools: typeof PoolsApiCasting;
|
|
27
|
+
/**
|
|
28
|
+
* Casting utilities for SuiFrens-related data or objects.
|
|
29
|
+
*/
|
|
23
30
|
static suiFrens: typeof SuiFrensApiCasting;
|
|
31
|
+
/**
|
|
32
|
+
* Casting utilities for faucet-related data, typically for devnet or testnet tokens.
|
|
33
|
+
*/
|
|
24
34
|
static faucet: typeof FaucetApiCasting;
|
|
35
|
+
/**
|
|
36
|
+
* Casting utilities for staking-related data (positions, pools, etc.).
|
|
37
|
+
*/
|
|
25
38
|
static staking: typeof StakingApiCasting;
|
|
39
|
+
/**
|
|
40
|
+
* Casting utilities for leveraged staking data structures.
|
|
41
|
+
*/
|
|
26
42
|
static leveragedStaking: typeof LeveragedStakingApiCasting;
|
|
43
|
+
/**
|
|
44
|
+
* Casting utilities for NFT AMM objects and events.
|
|
45
|
+
*/
|
|
27
46
|
static nftAmm: typeof NftAmmApiCasting;
|
|
47
|
+
/**
|
|
48
|
+
* Casting utilities for router-based data, such as trade routes and DEX interactions.
|
|
49
|
+
*/
|
|
28
50
|
static router: typeof RouterApiCasting;
|
|
51
|
+
/**
|
|
52
|
+
* Casting utilities for perpetuals/futures data.
|
|
53
|
+
*/
|
|
29
54
|
static perpetuals: typeof PerpetualsApiCasting;
|
|
55
|
+
/**
|
|
56
|
+
* Casting utilities for oracle-based data or price feed objects.
|
|
57
|
+
*/
|
|
30
58
|
static oracle: typeof OracleApiCasting;
|
|
59
|
+
/**
|
|
60
|
+
* Casting utilities for farming data (yield farms, locked positions, etc.).
|
|
61
|
+
*/
|
|
31
62
|
static farms: typeof FarmsApiCasting;
|
|
63
|
+
/**
|
|
64
|
+
* Casting utilities for NFT structures and data retrieval logic.
|
|
65
|
+
*/
|
|
32
66
|
static nfts: typeof NftsApiCasting;
|
|
67
|
+
/**
|
|
68
|
+
* Reference to the standard fixed-point arithmetic utilities (18 decimals).
|
|
69
|
+
*/
|
|
33
70
|
static Fixed: typeof FixedUtils;
|
|
71
|
+
/**
|
|
72
|
+
* Reference to the intermediate fixed type (signed 18 decimals).
|
|
73
|
+
*/
|
|
34
74
|
static IFixed: typeof IFixedUtils;
|
|
75
|
+
/**
|
|
76
|
+
* The maximum unsigned 64-bit integer value as a bigint (0xFFFFFFFFFFFFFFFF).
|
|
77
|
+
*/
|
|
35
78
|
static u64MaxBigInt: bigint;
|
|
79
|
+
/**
|
|
80
|
+
* Converts a floating-point number to a fixed bigint with 18 decimals.
|
|
81
|
+
* For example, `1.23` => `1230000000000000000n` if we consider 18 decimals.
|
|
82
|
+
*
|
|
83
|
+
* @param a - The number to convert.
|
|
84
|
+
* @returns A bigint representing the number in 18-decimal fixed format.
|
|
85
|
+
*/
|
|
36
86
|
static numberToFixedBigInt: (a: number) => bigint;
|
|
87
|
+
/**
|
|
88
|
+
* Converts an 18-decimal fixed bigint to a floating-point number.
|
|
89
|
+
* For example, `1230000000000000000n` => `1.23`.
|
|
90
|
+
*
|
|
91
|
+
* @param a - The fixed bigint to convert.
|
|
92
|
+
* @returns A floating-point representation of the 18-decimal fixed value.
|
|
93
|
+
*/
|
|
37
94
|
static bigIntToFixedNumber: (a: bigint) => number;
|
|
95
|
+
/**
|
|
96
|
+
* Scales a bigint by a floating-point scalar. For instance, a scalar of 0.5
|
|
97
|
+
* and a bigint of 100 => 50n.
|
|
98
|
+
*
|
|
99
|
+
* @param scalar - The floating-point multiplier (e.g., 0.5).
|
|
100
|
+
* @param int - The bigint to be scaled.
|
|
101
|
+
* @returns A bigint result after scaling.
|
|
102
|
+
*/
|
|
38
103
|
static scaleNumberByBigInt: (scalar: number, int: bigint) => bigint;
|
|
104
|
+
/**
|
|
105
|
+
* Converts a decimal percentage into basis points (bps), returned as a bigint.
|
|
106
|
+
* For example, 0.05 => 500 bps.
|
|
107
|
+
*
|
|
108
|
+
* @param percentage - The decimal percentage to convert (e.g., 0.05 for 5%).
|
|
109
|
+
* @returns A bigint representing basis points.
|
|
110
|
+
*/
|
|
39
111
|
static percentageToBps(percentage: Percentage): bigint;
|
|
112
|
+
/**
|
|
113
|
+
* Converts a bigint basis points value back to a decimal percentage.
|
|
114
|
+
* For example, 500n => 0.05 (5%).
|
|
115
|
+
*
|
|
116
|
+
* @param bps - The bigint basis points to convert (e.g., 500n).
|
|
117
|
+
* @returns The decimal percentage (0.05).
|
|
118
|
+
*/
|
|
40
119
|
static bpsToPercentage(bps: bigint): Percentage;
|
|
120
|
+
/**
|
|
121
|
+
* Converts an array of bytes into a string by interpreting each byte as a character code.
|
|
122
|
+
*
|
|
123
|
+
* @param bytes - An array of bytes to convert.
|
|
124
|
+
* @returns The resulting ASCII string.
|
|
125
|
+
*/
|
|
41
126
|
static stringFromBytes: (bytes: Byte[]) => string;
|
|
127
|
+
/**
|
|
128
|
+
* Interprets an array of bytes as a little-endian hex string, converting
|
|
129
|
+
* that string into a bigint. For example, `[0x01, 0x02]` => `0x0201` => `513n`.
|
|
130
|
+
*
|
|
131
|
+
* @param bytes - An array of bytes.
|
|
132
|
+
* @returns The resulting bigint from the hex.
|
|
133
|
+
*/
|
|
42
134
|
static bigIntFromBytes: (bytes: Byte[]) => bigint;
|
|
135
|
+
/**
|
|
136
|
+
* Converts BCS-encoded address bytes into a SuiAddress (0x...) string,
|
|
137
|
+
* preserving any needed leading zeroes.
|
|
138
|
+
*
|
|
139
|
+
* @param bytes - The address bytes in BCS-encoded form.
|
|
140
|
+
* @returns A normalized Sui address string (e.g., "0x000123...").
|
|
141
|
+
*/
|
|
43
142
|
static addressFromBcsBytes: (bytes: Byte[]) => SuiAddress;
|
|
143
|
+
/**
|
|
144
|
+
* Converts an array of bytes directly to a Sui address string in "0x..." format,
|
|
145
|
+
* adding any leading zeros if needed.
|
|
146
|
+
*
|
|
147
|
+
* @param bytes - The raw bytes for the address.
|
|
148
|
+
* @returns A normalized Sui address.
|
|
149
|
+
*/
|
|
44
150
|
static addressFromBytes: (bytes: Byte[]) => SuiAddress;
|
|
151
|
+
/**
|
|
152
|
+
* Converts an array of hex string bytes into a Sui address. Each element of
|
|
153
|
+
* the array is a string representing a byte (e.g., `["255", "0", ...]`).
|
|
154
|
+
*
|
|
155
|
+
* @param bytes - An array of stringified bytes to convert.
|
|
156
|
+
* @returns A normalized Sui address.
|
|
157
|
+
*/
|
|
45
158
|
static addressFromStringBytes: (bytes: string[]) => SuiAddress;
|
|
159
|
+
/**
|
|
160
|
+
* Converts an array of decimal-encoded string bytes (e.g., `["255", "0"]`)
|
|
161
|
+
* into a numeric `Byte[]` array.
|
|
162
|
+
*
|
|
163
|
+
* @param bytes - The string array representing decimal values.
|
|
164
|
+
* @returns A numeric array of bytes.
|
|
165
|
+
*/
|
|
46
166
|
static bytesFromStringBytes: (bytes: string[]) => Byte[];
|
|
167
|
+
/**
|
|
168
|
+
* Unwraps a deserialized "Option" type from the BCS, returning its contents
|
|
169
|
+
* if present, or `undefined` if not.
|
|
170
|
+
*
|
|
171
|
+
* @param deserializedData - The BCS-deserialized structure that might contain `{ Some: value }` or `{ None: true }`.
|
|
172
|
+
* @returns The unwrapped data if present, or `undefined`.
|
|
173
|
+
*/
|
|
47
174
|
static unwrapDeserializedOption: (deserializedData: any) => any | undefined;
|
|
175
|
+
/**
|
|
176
|
+
* Encodes a JavaScript string into a UTF-8 `Uint8Array`, suitable for
|
|
177
|
+
* on-chain usage or hashing.
|
|
178
|
+
*
|
|
179
|
+
* @param str - The string to encode.
|
|
180
|
+
* @returns An array of numeric bytes representing the UTF-8 encoded string.
|
|
181
|
+
*/
|
|
48
182
|
static u8VectorFromString: (str: string) => number[];
|
|
183
|
+
/**
|
|
184
|
+
* Normalizes a user-provided slippage tolerance from an integer percentage
|
|
185
|
+
* into a decimal fraction. E.g., `1 => 0.01`.
|
|
186
|
+
*
|
|
187
|
+
* @param slippageTolerance - The slippage in integer percent form (e.g., 1 for 1%).
|
|
188
|
+
* @returns A decimal fraction (e.g., 0.01).
|
|
189
|
+
*/
|
|
49
190
|
static normalizeSlippageTolerance: (slippageTolerance: number) => number;
|
|
191
|
+
/**
|
|
192
|
+
* Deserializes a `SuiObjectResponse`'s BCS bytes into an object of type `T` using
|
|
193
|
+
* a specified `bcsType`. Typically used for on-chain object decoding.
|
|
194
|
+
*
|
|
195
|
+
* @param inputs - The inputs including `suiObjectResponse`, `bcsType`, and a `fromDeserialized` transform function.
|
|
196
|
+
* @returns The transformed object of type `T` after BCS deserialization.
|
|
197
|
+
* @throws If no BCS bytes are found in the object.
|
|
198
|
+
*/
|
|
50
199
|
static castObjectBcs: <T, U>(inputs: {
|
|
51
200
|
suiObjectResponse: SuiObjectResponse;
|
|
52
201
|
bcsType: BcsType<U, U>;
|
|
53
|
-
fromDeserialized: (deserialized:
|
|
202
|
+
fromDeserialized: (deserialized: U) => T;
|
|
54
203
|
}) => T;
|
|
204
|
+
/**
|
|
205
|
+
* Extracts base64 BCS bytes from a `SuiObjectResponse` if present. Throws an error otherwise.
|
|
206
|
+
*
|
|
207
|
+
* @param suiObjectResponse - The Sui object response containing `bcsBytes`.
|
|
208
|
+
* @returns A base64 string representing the object's BCS data.
|
|
209
|
+
* @throws If the object response does not contain `bcsBytes`.
|
|
210
|
+
*/
|
|
55
211
|
static bcsBytesFromSuiObjectResponse(suiObjectResponse: SuiObjectResponse): string;
|
|
56
212
|
}
|
|
57
213
|
//# sourceMappingURL=casting.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"casting.d.ts","sourceRoot":"","sources":["../../../src/general/utils/casting.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAO,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,gDAAgD,CAAC;AACpF,OAAO,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAC;AAC9E,OAAO,EA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eAAe,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM;IAO7D;;;;;;OAMG;WACW,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU;IAYtD;;;;;OAKG;IACH,OAAc,eAAe,UAAW,IAAI,EAAE,YACC;IAE/C;;;;;;OAMG;IACH,OAAc,eAAe,UAAW,IAAI,EAAE,YAO3C;IAEH;;;;;;OAMG;IACH,OAAc,mBAAmB,UAAW,IAAI,EAAE,KAAG,UAAU,CAG5D;IAEH;;;;;;OAMG;IACH,OAAc,gBAAgB,UAAW,IAAI,EAAE,KAAG,UAAU,CASzD;IAEH;;;;;;OAMG;IACH,OAAc,sBAAsB,UAAW,MAAM,EAAE,KAAG,UAAU,CACX;IAEzD;;;;;;OAMG;IACH,OAAc,oBAAoB,UAAW,MAAM,EAAE,KAAG,IAAI,EAAE,CAC3B;IAEnC;;;;;;OAMG;IACH,OAAc,wBAAwB,qBACnB,GAAG,KACnB,GAAG,GAAG,SAAS,CAEhB;IAEF;;;;;;OAMG;IACH,OAAc,kBAAkB,QAAS,MAAM,cAS7C;IAEF;;;;;;OAMG;IACH,OAAc,0BAA0B,sBAAuB,MAAM,YAEnE;IAEF;;;;;;;OAOG;IACH,OAAc,aAAa;2BACP,iBAAiB;;;YAWnC;IAEF;;;;;;OAMG;WACW,6BAA6B,CAC1C,iBAAiB,EAAE,iBAAiB,GAClC,MAAM;CAOT"}
|
|
@@ -18,20 +18,34 @@ const __1 = require("../..");
|
|
|
18
18
|
const nftsApiCasting_1 = require("../nfts/nftsApiCasting");
|
|
19
19
|
const oracleApiCasting_1 = require("../../packages/oracle/api/oracleApiCasting");
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
21
|
+
* A central utility class for casting and conversion routines across
|
|
22
|
+
* different Aftermath modules. Provides both direct numeric transformations
|
|
23
|
+
* (e.g., fixed-point arithmetic) and advanced BCS-based object deserialization.
|
|
23
24
|
*/
|
|
24
25
|
class Casting {
|
|
25
26
|
// =========================================================================
|
|
26
|
-
//
|
|
27
|
+
// Percentage <-> Bps
|
|
27
28
|
// =========================================================================
|
|
29
|
+
/**
|
|
30
|
+
* Converts a decimal percentage into basis points (bps), returned as a bigint.
|
|
31
|
+
* For example, 0.05 => 500 bps.
|
|
32
|
+
*
|
|
33
|
+
* @param percentage - The decimal percentage to convert (e.g., 0.05 for 5%).
|
|
34
|
+
* @returns A bigint representing basis points.
|
|
35
|
+
*/
|
|
28
36
|
static percentageToBps(percentage) {
|
|
29
37
|
// Convert decimal percentage to basis points
|
|
30
38
|
const bps = percentage * 10000;
|
|
31
39
|
// Convert basis points to bigint
|
|
32
|
-
|
|
33
|
-
return bpsBigint;
|
|
40
|
+
return BigInt(Math.round(bps));
|
|
34
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Converts a bigint basis points value back to a decimal percentage.
|
|
44
|
+
* For example, 500n => 0.05 (5%).
|
|
45
|
+
*
|
|
46
|
+
* @param bps - The bigint basis points to convert (e.g., 500n).
|
|
47
|
+
* @returns The decimal percentage (0.05).
|
|
48
|
+
*/
|
|
35
49
|
static bpsToPercentage(bps) {
|
|
36
50
|
// Convert bigint basis points to number
|
|
37
51
|
const bpsNumber = Number(bps);
|
|
@@ -39,6 +53,13 @@ class Casting {
|
|
|
39
53
|
const percentage = bpsNumber / 10000;
|
|
40
54
|
return percentage;
|
|
41
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Extracts base64 BCS bytes from a `SuiObjectResponse` if present. Throws an error otherwise.
|
|
58
|
+
*
|
|
59
|
+
* @param suiObjectResponse - The Sui object response containing `bcsBytes`.
|
|
60
|
+
* @returns A base64 string representing the object's BCS data.
|
|
61
|
+
* @throws If the object response does not contain `bcsBytes`.
|
|
62
|
+
*/
|
|
42
63
|
static bcsBytesFromSuiObjectResponse(suiObjectResponse) {
|
|
43
64
|
var _b, _c;
|
|
44
65
|
const rawData = (_b = suiObjectResponse.data) === null || _b === void 0 ? void 0 : _b.bcs;
|
|
@@ -52,46 +73,133 @@ _a = Casting;
|
|
|
52
73
|
// =========================================================================
|
|
53
74
|
// Api Casting
|
|
54
75
|
// =========================================================================
|
|
76
|
+
/**
|
|
77
|
+
* Casting utilities for pools-related data (AMM pools, liquidity, etc.).
|
|
78
|
+
*/
|
|
55
79
|
Casting.pools = poolsApiCasting_1.PoolsApiCasting;
|
|
80
|
+
/**
|
|
81
|
+
* Casting utilities for SuiFrens-related data or objects.
|
|
82
|
+
*/
|
|
56
83
|
Casting.suiFrens = suiFrensApiCasting_1.SuiFrensApiCasting;
|
|
84
|
+
/**
|
|
85
|
+
* Casting utilities for faucet-related data, typically for devnet or testnet tokens.
|
|
86
|
+
*/
|
|
57
87
|
Casting.faucet = faucetApiCasting_1.FaucetApiCasting;
|
|
88
|
+
/**
|
|
89
|
+
* Casting utilities for staking-related data (positions, pools, etc.).
|
|
90
|
+
*/
|
|
58
91
|
Casting.staking = stakingApiCasting_1.StakingApiCasting;
|
|
92
|
+
/**
|
|
93
|
+
* Casting utilities for leveraged staking data structures.
|
|
94
|
+
*/
|
|
59
95
|
Casting.leveragedStaking = leveragedStakingApiCasting_1.LeveragedStakingApiCasting;
|
|
96
|
+
/**
|
|
97
|
+
* Casting utilities for NFT AMM objects and events.
|
|
98
|
+
*/
|
|
60
99
|
Casting.nftAmm = nftAmmApiCasting_1.NftAmmApiCasting;
|
|
100
|
+
/**
|
|
101
|
+
* Casting utilities for router-based data, such as trade routes and DEX interactions.
|
|
102
|
+
*/
|
|
61
103
|
Casting.router = routerApiCasting_1.RouterApiCasting;
|
|
104
|
+
/**
|
|
105
|
+
* Casting utilities for perpetuals/futures data.
|
|
106
|
+
*/
|
|
62
107
|
Casting.perpetuals = perpetualsApiCasting_1.PerpetualsApiCasting;
|
|
108
|
+
/**
|
|
109
|
+
* Casting utilities for oracle-based data or price feed objects.
|
|
110
|
+
*/
|
|
63
111
|
Casting.oracle = oracleApiCasting_1.OracleApiCasting;
|
|
112
|
+
/**
|
|
113
|
+
* Casting utilities for farming data (yield farms, locked positions, etc.).
|
|
114
|
+
*/
|
|
64
115
|
Casting.farms = farmsApiCasting_1.FarmsApiCasting;
|
|
116
|
+
/**
|
|
117
|
+
* Casting utilities for NFT structures and data retrieval logic.
|
|
118
|
+
*/
|
|
65
119
|
Casting.nfts = nftsApiCasting_1.NftsApiCasting;
|
|
66
120
|
// =========================================================================
|
|
67
121
|
// Constants
|
|
68
122
|
// =========================================================================
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
123
|
+
/**
|
|
124
|
+
* Reference to the standard fixed-point arithmetic utilities (18 decimals).
|
|
125
|
+
*/
|
|
72
126
|
Casting.Fixed = fixedUtils_1.FixedUtils;
|
|
127
|
+
/**
|
|
128
|
+
* Reference to the intermediate fixed type (signed 18 decimals).
|
|
129
|
+
*/
|
|
73
130
|
Casting.IFixed = iFixedUtils_1.IFixedUtils;
|
|
131
|
+
/**
|
|
132
|
+
* The maximum unsigned 64-bit integer value as a bigint (0xFFFFFFFFFFFFFFFF).
|
|
133
|
+
*/
|
|
74
134
|
Casting.u64MaxBigInt = BigInt("0xFFFFFFFFFFFFFFFF");
|
|
75
135
|
// =========================================================================
|
|
76
136
|
// Functions
|
|
77
137
|
// =========================================================================
|
|
78
138
|
// =========================================================================
|
|
79
|
-
// Fixed
|
|
139
|
+
// Fixed / IFixed
|
|
80
140
|
// =========================================================================
|
|
81
|
-
|
|
141
|
+
/**
|
|
142
|
+
* Converts a floating-point number to a fixed bigint with 18 decimals.
|
|
143
|
+
* For example, `1.23` => `1230000000000000000n` if we consider 18 decimals.
|
|
144
|
+
*
|
|
145
|
+
* @param a - The number to convert.
|
|
146
|
+
* @returns A bigint representing the number in 18-decimal fixed format.
|
|
147
|
+
*/
|
|
82
148
|
Casting.numberToFixedBigInt = (a) => BigInt(Math.floor(a * _a.Fixed.fixedOneN));
|
|
149
|
+
/**
|
|
150
|
+
* Converts an 18-decimal fixed bigint to a floating-point number.
|
|
151
|
+
* For example, `1230000000000000000n` => `1.23`.
|
|
152
|
+
*
|
|
153
|
+
* @param a - The fixed bigint to convert.
|
|
154
|
+
* @returns A floating-point representation of the 18-decimal fixed value.
|
|
155
|
+
*/
|
|
83
156
|
Casting.bigIntToFixedNumber = (a) => Number(a) / _a.Fixed.fixedOneN;
|
|
157
|
+
/**
|
|
158
|
+
* Scales a bigint by a floating-point scalar. For instance, a scalar of 0.5
|
|
159
|
+
* and a bigint of 100 => 50n.
|
|
160
|
+
*
|
|
161
|
+
* @param scalar - The floating-point multiplier (e.g., 0.5).
|
|
162
|
+
* @param int - The bigint to be scaled.
|
|
163
|
+
* @returns A bigint result after scaling.
|
|
164
|
+
*/
|
|
84
165
|
Casting.scaleNumberByBigInt = (scalar, int) => BigInt(Math.floor(scalar * Number(int)));
|
|
85
166
|
// =========================================================================
|
|
86
167
|
// Bytes / BCS
|
|
87
168
|
// =========================================================================
|
|
169
|
+
/**
|
|
170
|
+
* Converts an array of bytes into a string by interpreting each byte as a character code.
|
|
171
|
+
*
|
|
172
|
+
* @param bytes - An array of bytes to convert.
|
|
173
|
+
* @returns The resulting ASCII string.
|
|
174
|
+
*/
|
|
88
175
|
Casting.stringFromBytes = (bytes) => String.fromCharCode.apply(null, bytes);
|
|
176
|
+
/**
|
|
177
|
+
* Interprets an array of bytes as a little-endian hex string, converting
|
|
178
|
+
* that string into a bigint. For example, `[0x01, 0x02]` => `0x0201` => `513n`.
|
|
179
|
+
*
|
|
180
|
+
* @param bytes - An array of bytes.
|
|
181
|
+
* @returns The resulting bigint from the hex.
|
|
182
|
+
*/
|
|
89
183
|
Casting.bigIntFromBytes = (bytes) => BigInt("0x" +
|
|
90
184
|
bytes
|
|
91
185
|
.reverse()
|
|
92
186
|
.map((byte) => byte.toString(16).padStart(2, "0"))
|
|
93
187
|
.join(""));
|
|
188
|
+
/**
|
|
189
|
+
* Converts BCS-encoded address bytes into a SuiAddress (0x...) string,
|
|
190
|
+
* preserving any needed leading zeroes.
|
|
191
|
+
*
|
|
192
|
+
* @param bytes - The address bytes in BCS-encoded form.
|
|
193
|
+
* @returns A normalized Sui address string (e.g., "0x000123...").
|
|
194
|
+
*/
|
|
94
195
|
Casting.addressFromBcsBytes = (bytes) => __1.Helpers.addLeadingZeroesToType(bcs_1.bcs.Address.parse(new Uint8Array(bytes)));
|
|
196
|
+
/**
|
|
197
|
+
* Converts an array of bytes directly to a Sui address string in "0x..." format,
|
|
198
|
+
* adding any leading zeros if needed.
|
|
199
|
+
*
|
|
200
|
+
* @param bytes - The raw bytes for the address.
|
|
201
|
+
* @returns A normalized Sui address.
|
|
202
|
+
*/
|
|
95
203
|
Casting.addressFromBytes = (bytes) => __1.Helpers.addLeadingZeroesToType("0x" +
|
|
96
204
|
bytes
|
|
97
205
|
.map((byte) => {
|
|
@@ -99,28 +207,66 @@ Casting.addressFromBytes = (bytes) => __1.Helpers.addLeadingZeroesToType("0x" +
|
|
|
99
207
|
return hex.length === 1 ? "0" + hex : hex;
|
|
100
208
|
})
|
|
101
209
|
.join(""));
|
|
210
|
+
/**
|
|
211
|
+
* Converts an array of hex string bytes into a Sui address. Each element of
|
|
212
|
+
* the array is a string representing a byte (e.g., `["255", "0", ...]`).
|
|
213
|
+
*
|
|
214
|
+
* @param bytes - An array of stringified bytes to convert.
|
|
215
|
+
* @returns A normalized Sui address.
|
|
216
|
+
*/
|
|
102
217
|
Casting.addressFromStringBytes = (bytes) => _a.addressFromBytes(_a.bytesFromStringBytes(bytes));
|
|
218
|
+
/**
|
|
219
|
+
* Converts an array of decimal-encoded string bytes (e.g., `["255", "0"]`)
|
|
220
|
+
* into a numeric `Byte[]` array.
|
|
221
|
+
*
|
|
222
|
+
* @param bytes - The string array representing decimal values.
|
|
223
|
+
* @returns A numeric array of bytes.
|
|
224
|
+
*/
|
|
103
225
|
Casting.bytesFromStringBytes = (bytes) => bytes.map((byte) => Number(byte));
|
|
226
|
+
/**
|
|
227
|
+
* Unwraps a deserialized "Option" type from the BCS, returning its contents
|
|
228
|
+
* if present, or `undefined` if not.
|
|
229
|
+
*
|
|
230
|
+
* @param deserializedData - The BCS-deserialized structure that might contain `{ Some: value }` or `{ None: true }`.
|
|
231
|
+
* @returns The unwrapped data if present, or `undefined`.
|
|
232
|
+
*/
|
|
104
233
|
Casting.unwrapDeserializedOption = (deserializedData) => {
|
|
105
|
-
// return "vec" in deserializedData
|
|
106
|
-
// ? deserializedData.vec.length > 0
|
|
107
|
-
// ? deserializedData.vec[0]
|
|
108
|
-
// : undefined
|
|
109
|
-
// : undefined;
|
|
110
234
|
return "Some" in deserializedData ? deserializedData.Some : undefined;
|
|
111
235
|
};
|
|
236
|
+
/**
|
|
237
|
+
* Encodes a JavaScript string into a UTF-8 `Uint8Array`, suitable for
|
|
238
|
+
* on-chain usage or hashing.
|
|
239
|
+
*
|
|
240
|
+
* @param str - The string to encode.
|
|
241
|
+
* @returns An array of numeric bytes representing the UTF-8 encoded string.
|
|
242
|
+
*/
|
|
112
243
|
Casting.u8VectorFromString = (str) => {
|
|
113
244
|
const textEncode = new TextEncoder();
|
|
114
245
|
const encodedStr = textEncode.encode(str);
|
|
115
|
-
|
|
246
|
+
const uint8s = [];
|
|
116
247
|
for (const uint8 of encodedStr.values()) {
|
|
117
248
|
uint8s.push(uint8);
|
|
118
249
|
}
|
|
119
250
|
return uint8s;
|
|
120
251
|
};
|
|
252
|
+
/**
|
|
253
|
+
* Normalizes a user-provided slippage tolerance from an integer percentage
|
|
254
|
+
* into a decimal fraction. E.g., `1 => 0.01`.
|
|
255
|
+
*
|
|
256
|
+
* @param slippageTolerance - The slippage in integer percent form (e.g., 1 for 1%).
|
|
257
|
+
* @returns A decimal fraction (e.g., 0.01).
|
|
258
|
+
*/
|
|
121
259
|
Casting.normalizeSlippageTolerance = (slippageTolerance) => {
|
|
122
260
|
return slippageTolerance / 100;
|
|
123
261
|
};
|
|
262
|
+
/**
|
|
263
|
+
* Deserializes a `SuiObjectResponse`'s BCS bytes into an object of type `T` using
|
|
264
|
+
* a specified `bcsType`. Typically used for on-chain object decoding.
|
|
265
|
+
*
|
|
266
|
+
* @param inputs - The inputs including `suiObjectResponse`, `bcsType`, and a `fromDeserialized` transform function.
|
|
267
|
+
* @returns The transformed object of type `T` after BCS deserialization.
|
|
268
|
+
* @throws If no BCS bytes are found in the object.
|
|
269
|
+
*/
|
|
124
270
|
Casting.castObjectBcs = (inputs) => {
|
|
125
271
|
const { suiObjectResponse, bcsType, fromDeserialized } = inputs;
|
|
126
272
|
const deserialized = bcsType.fromBase64(_a.bcsBytesFromSuiObjectResponse(suiObjectResponse));
|
|
@@ -1,22 +1,109 @@
|
|
|
1
1
|
import { Balance, DecimalsScalar, NormalizedBalance } from "../../types";
|
|
2
|
+
/**
|
|
3
|
+
* The `FixedUtils` class provides utilities for fixed-point arithmetic
|
|
4
|
+
* with a standard 18-decimal precision, along with some convenience
|
|
5
|
+
* methods for normalizing/un-normalizing amounts based on token decimals.
|
|
6
|
+
*/
|
|
2
7
|
export declare class FixedUtils {
|
|
8
|
+
/**
|
|
9
|
+
* Represents 1.0 in 18-decimal fixed math as a float: 1_000_000_000_000_000_000.
|
|
10
|
+
*/
|
|
3
11
|
static readonly fixedOneN: number;
|
|
12
|
+
/**
|
|
13
|
+
* Represents 1.0 in 18-decimal fixed math as a bigint: 1000000000000000000n.
|
|
14
|
+
*/
|
|
4
15
|
static readonly fixedOneB: bigint;
|
|
16
|
+
/**
|
|
17
|
+
* Represents 1.0 in 9-decimal fixed math as a float: 1_000_000_000.
|
|
18
|
+
*/
|
|
5
19
|
static readonly fixedOneN9 = 1000000000;
|
|
20
|
+
/**
|
|
21
|
+
* Represents 1.0 in 9-decimal fixed math as a bigint: 1000000000n.
|
|
22
|
+
*/
|
|
6
23
|
static readonly fixedOneB9: bigint;
|
|
24
|
+
/**
|
|
25
|
+
* Directly convert an on-chain `u64` (stored as a bigint) into a float, effectively no scaling.
|
|
26
|
+
*
|
|
27
|
+
* @param n - The on-chain number as a bigint.
|
|
28
|
+
* @returns The converted number as a float.
|
|
29
|
+
*/
|
|
7
30
|
static readonly convertFromInt: (n: OnChainNumber) => LocalNumber;
|
|
31
|
+
/**
|
|
32
|
+
* Convert a floating number back to an on-chain integer (bigint),
|
|
33
|
+
* truncating decimals.
|
|
34
|
+
*
|
|
35
|
+
* @param n - The local float.
|
|
36
|
+
* @returns The truncated bigint.
|
|
37
|
+
*/
|
|
8
38
|
static readonly convertToInt: (n: LocalNumber) => OnChainNumber;
|
|
39
|
+
/**
|
|
40
|
+
* Converts a fixed-18 on-chain number to a floating local number by dividing by `fixedOneN`.
|
|
41
|
+
*
|
|
42
|
+
* @param n - The on-chain 18-decimal fixed number (as a bigint).
|
|
43
|
+
* @returns A float representing the unscaled value.
|
|
44
|
+
*/
|
|
9
45
|
static readonly directCast: (n: OnChainNumber) => LocalNumber;
|
|
46
|
+
/**
|
|
47
|
+
* Converts a floating local number to an on-chain 18-decimal fixed bigint by multiplying by `fixedOneN`.
|
|
48
|
+
*
|
|
49
|
+
* @param n - The local float to be scaled.
|
|
50
|
+
* @returns The scaled 18-decimal fixed as a bigint.
|
|
51
|
+
*/
|
|
10
52
|
static readonly directUncast: (n: LocalNumber) => OnChainNumber;
|
|
53
|
+
/**
|
|
54
|
+
* Returns the complement of the number in `[0,1]`, i.e., `1 - n`.
|
|
55
|
+
* If `n` is negative, it's treated as zero; if `n` > 1, also treated as zero for the complement.
|
|
56
|
+
*
|
|
57
|
+
* @param n - The local float in [0,1].
|
|
58
|
+
* @returns The complement of `n` in [0,1].
|
|
59
|
+
*/
|
|
11
60
|
static readonly complement: (n: LocalNumber) => number;
|
|
61
|
+
/**
|
|
62
|
+
* Multiplies a raw integer `amount` by a `decimalsScalar` to produce
|
|
63
|
+
* a "normalized" form. E.g., if decimals = 9, we store it as 10^9 scale.
|
|
64
|
+
*
|
|
65
|
+
* @param decimalsScalar - The scale factor for the coin (e.g., 1e9).
|
|
66
|
+
* @param amount - The raw integer (balance) to be scaled.
|
|
67
|
+
* @returns The scaled (normalized) amount as a `number`.
|
|
68
|
+
*/
|
|
12
69
|
static readonly normalizeAmount: (decimalsScalar: DecimalsScalar, amount: Balance) => NormalizedBalance;
|
|
70
|
+
/**
|
|
71
|
+
* Divides a normalized amount by the `decimalsScalar` to get back the
|
|
72
|
+
* raw on-chain integer. This is typically used after floating computations.
|
|
73
|
+
*
|
|
74
|
+
* @param decimalsScalar - The scale factor for the coin (e.g., 1e9).
|
|
75
|
+
* @param normalizedAmount - The scaled amount to reduce.
|
|
76
|
+
* @returns The raw integer balance.
|
|
77
|
+
*/
|
|
13
78
|
static readonly unnormalizeAmount: (decimalsScalar: DecimalsScalar, normalizedAmount: NormalizedBalance) => Balance;
|
|
79
|
+
/**
|
|
80
|
+
* Directly cast a `Balance` to an 18-decimal float, factoring in token decimals.
|
|
81
|
+
*
|
|
82
|
+
* @param decimalsScalar - The token's decimal scale factor.
|
|
83
|
+
* @param amount - The raw integer `Balance`.
|
|
84
|
+
* @returns A float representing the 18-decimal scale cast.
|
|
85
|
+
*/
|
|
14
86
|
static readonly castAndNormalize: (decimalsScalar: DecimalsScalar, amount: Balance) => LocalNumber;
|
|
87
|
+
/**
|
|
88
|
+
* Reverse the cast of a normalized float back to a raw `Balance`,
|
|
89
|
+
* factoring in the token decimals.
|
|
90
|
+
*
|
|
91
|
+
* @param decimalsScalar - The token's decimal scale factor.
|
|
92
|
+
* @param normalizedAmount - A local float in 18-decimal domain.
|
|
93
|
+
* @returns A raw integer `Balance`.
|
|
94
|
+
*/
|
|
15
95
|
static readonly uncastAndUnnormalize: (decimalsScalar: DecimalsScalar, normalizedAmount: LocalNumber) => Balance;
|
|
16
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* A numeric type used on chain, typically fixed 18 decimals or direct u64.
|
|
99
|
+
*/
|
|
17
100
|
export type OnChainNumber = bigint;
|
|
101
|
+
/**
|
|
102
|
+
* A local floating value for user calculations or UI representation.
|
|
103
|
+
*/
|
|
18
104
|
export type LocalNumber = number;
|
|
19
|
-
|
|
20
|
-
|
|
105
|
+
/**
|
|
106
|
+
* A scalar is any fixed 18-point number. They are stored on chain as a u128 and are always directly cast.
|
|
107
|
+
*/
|
|
21
108
|
export type OnChainScalar = OnChainNumber;
|
|
22
109
|
//# sourceMappingURL=fixedUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fixedUtils.d.ts","sourceRoot":"","sources":["../../../src/general/utils/fixedUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEzE,qBAAa,UAAU;
|
|
1
|
+
{"version":3,"file":"fixedUtils.d.ts","sourceRoot":"","sources":["../../../src/general/utils/fixedUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEzE;;;;GAIG;AACH,qBAAa,UAAU;IACtB;;OAEG;IACH,gBAAuB,SAAS,EAAE,MAAM,CAA6B;IAErE;;OAEG;IACH,gBAAuB,SAAS,EAAE,MAAM,CAAiC;IAEzE;;OAEG;IACH,gBAAuB,UAAU,cAAiB;IAElD;;OAEG;IACH,gBAAuB,UAAU,SAAyB;IAI1D;;;;;OAKG;IACH,gBAAuB,cAAc,MAAO,aAAa,KAAG,WAAW,CAC5D;IAEX;;;;;;OAMG;IACH,gBAAuB,YAAY,MAAO,WAAW,KAAG,aAAa,CAC9C;IAEvB;;;;;OAKG;IACH,gBAAuB,UAAU,MAAO,aAAa,KAAG,WAAW,CACjC;IAElC;;;;;OAKG;IACH,gBAAuB,YAAY,MAAO,WAAW,KAAG,aAAa,CACvB;IAE9C;;;;;;OAMG;IACH,gBAAuB,UAAU,MAAO,WAAW,YAClB;IAEjC;;;;;;;OAOG;IACH,gBAAuB,eAAe,mBACrB,cAAc,UACtB,OAAO,KACb,iBAAiB,CAA4B;IAEhD;;;;;;;OAOG;IACH,gBAAuB,iBAAiB,mBACvB,cAAc,oBACZ,iBAAiB,KACjC,OAAO,CAA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