@xoxno/sdk-js 1.0.227 → 1.0.228
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/cjs/sdk/stellar/__tests__/amount.test.d.ts +1 -0
- package/dist/cjs/sdk/stellar/lending.d.ts +9 -0
- package/dist/esm/sdk/stellar/lending.js +22 -1
- package/dist/index.cjs +1 -1
- package/dist/sdk/stellar/__tests__/amount.test.d.ts +1 -0
- package/dist/sdk/stellar/index.cjs +1 -1
- package/dist/sdk/stellar/index.esm.js +1 -1
- package/dist/sdk/stellar/lending.d.ts +9 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -19,6 +19,15 @@
|
|
|
19
19
|
import { xdr } from '@stellar/stellar-sdk';
|
|
20
20
|
import { type StellarNetwork } from './contracts.js';
|
|
21
21
|
import { type StellarSeizeModeInput, type StellarStrategySwapHopInput, type StellarStrategySwapInput, type StellarStrategySwapPathInput } from './scval-encode.js';
|
|
22
|
+
/**
|
|
23
|
+
* Convert a positive decimal token amount into a builder-ready base-unit string.
|
|
24
|
+
* Uses Stellar's exact string parser; never rounds excess precision or uses floats.
|
|
25
|
+
* @param amount - Plain decimal text, for example '1.25'; no sign or exponent.
|
|
26
|
+
* @param decimals - Token decimal places, from 0 to 18; null metadata is rejected.
|
|
27
|
+
* @throws If the input is invalid, non-positive, over-precise, or exceeds i128.
|
|
28
|
+
* @example parseStellarTokenAmount('1.25', 7) // '12500000'
|
|
29
|
+
*/
|
|
30
|
+
export declare function parseStellarTokenAmount(amount: string, decimals: number | null): string;
|
|
22
31
|
/**
|
|
23
32
|
* Stellar `G...` public key of the caller (tx source account).
|
|
24
33
|
*/
|
|
@@ -15,9 +15,30 @@
|
|
|
15
15
|
* current sequence via `rpc.Server.getAccount(caller)` and runs
|
|
16
16
|
* `rpc.Server.prepareTransaction` (simulation + Soroban footprint/auth/resource
|
|
17
17
|
* fee) before handing the XDR to the wallet to sign.
|
|
18
|
-
*/ import { Account, BASE_FEE, Contract, scValToNative, TransactionBuilder, xdr } from "@stellar/stellar-sdk";
|
|
18
|
+
*/ import { Account, BASE_FEE, Contract, Soroban, scValToNative, TransactionBuilder, xdr } from "@stellar/stellar-sdk";
|
|
19
19
|
import { STELLAR_NETWORK_PASSPHRASE } from "./contracts.js";
|
|
20
20
|
import { addr, asStellarBytes, asStellarStrategySwapBytes, bool, hubAsset, i128, option, seizeMode, tupleAddrAmountVec, tupleHubAssetAmount, tupleHubAssetAmountVec, u32, u64, vec } from "./scval-encode.js";
|
|
21
|
+
/**
|
|
22
|
+
* Convert a positive decimal token amount into a builder-ready base-unit string.
|
|
23
|
+
* Uses Stellar's exact string parser; never rounds excess precision or uses floats.
|
|
24
|
+
* @param amount - Plain decimal text, for example '1.25'; no sign or exponent.
|
|
25
|
+
* @param decimals - Token decimal places, from 0 to 18; null metadata is rejected.
|
|
26
|
+
* @throws If the input is invalid, non-positive, over-precise, or exceeds i128.
|
|
27
|
+
* @example parseStellarTokenAmount('1.25', 7) // '12500000'
|
|
28
|
+
*/ export function parseStellarTokenAmount(amount, decimals) {
|
|
29
|
+
if (typeof decimals !== 'number' || !Number.isInteger(decimals) || decimals < 0 || decimals > 18) {
|
|
30
|
+
throw new Error('Token decimals must be an integer from 0 to 18');
|
|
31
|
+
}
|
|
32
|
+
if (typeof amount !== 'string' || !/^\d+(?:\.\d+)?$/.test(amount)) {
|
|
33
|
+
throw new Error('Token amount must be plain decimal text');
|
|
34
|
+
}
|
|
35
|
+
const raw = Soroban.parseTokenAmount(amount, decimals);
|
|
36
|
+
const value = BigInt(raw);
|
|
37
|
+
if (value <= 0n || value > (1n << 127n) - 1n) {
|
|
38
|
+
throw new Error('Token amount must be within the positive i128 range');
|
|
39
|
+
}
|
|
40
|
+
return raw;
|
|
41
|
+
}
|
|
21
42
|
// -----------------------------------------------------------------------------
|
|
22
43
|
// Transaction assembly
|
|
23
44
|
// -----------------------------------------------------------------------------
|