@xoxno/sdk-js 1.0.227 → 1.0.229
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/cjs/sdk/stellar/scval-encode.d.ts +1 -1
- package/dist/esm/sdk/stellar/lending.js +22 -1
- package/dist/esm/sdk/stellar/route-verify.js +6 -3
- package/dist/esm/sdk/stellar/scval-encode.js +4 -2
- 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/dist/sdk/stellar/scval-encode.d.ts +1 -1
- package/dist/sdk/stellar/swap-index.cjs +1 -1
- package/dist/sdk/stellar/swap-index.esm.js +1 -1
- package/package.json +2 -2
|
@@ -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
|
*/
|
|
@@ -10,7 +10,7 @@ import { xdr } from '@stellar/stellar-sdk';
|
|
|
10
10
|
* On-chain swap venues, validated at runtime for a caller-supplied venue.
|
|
11
11
|
* Mirrors the Soroban-only aggregator router's opcode table.
|
|
12
12
|
*/
|
|
13
|
-
export declare const STELLAR_SWAP_VENUES: readonly ["Soroswap", "Aquarius", "Phoenix", "Sushi", "CometDex"];
|
|
13
|
+
export declare const STELLAR_SWAP_VENUES: readonly ["Soroswap", "Aquarius", "Phoenix", "Sushi", "CometDex", "Curve"];
|
|
14
14
|
export type StellarSwapVenue = (typeof STELLAR_SWAP_VENUES)[number];
|
|
15
15
|
/**
|
|
16
16
|
* Instruction opcode per venue. Part of the on-chain ABI — see
|
|
@@ -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
|
// -----------------------------------------------------------------------------
|
|
@@ -24,7 +24,7 @@ function _define_property(obj, key, value) {
|
|
|
24
24
|
*/ import { Address, Asset, scValToBigInt, StrKey, xdr } from "@stellar/stellar-sdk";
|
|
25
25
|
import { STELLAR_NETWORK_PASSPHRASE } from "./contracts.js";
|
|
26
26
|
import { xdrBytes, xdrField, xdrType } from "./xdr-compat.js";
|
|
27
|
-
import { asStellarStrategySwapBytes, MAX_AMOUNTS, MAX_ASSETS, MAX_OPS, MAX_WEIGHTS, MODE_ALL, MODE_FIXED_BASE, MODE_PPM_BASE, MODE_PREV, OP_BURN, OP_MINT, PPM_DENOMINATOR, STELLAR_PROGRAM_VERSION, STELLAR_SWAP_VENUES } from "./scval-encode.js";
|
|
27
|
+
import { asStellarStrategySwapBytes, MAX_AMOUNTS, MAX_ASSETS, MAX_OPS, MAX_WEIGHTS, MODE_ALL, MODE_FIXED_BASE, MODE_PPM_BASE, MODE_PREV, OP_BURN, OP_MINT, PPM_DENOMINATOR, STELLAR_PROGRAM_VERSION, STELLAR_SWAP_VENUES, STELLAR_SWAP_VENUE_OPCODE } from "./scval-encode.js";
|
|
28
28
|
const HEADER_LEN = 10;
|
|
29
29
|
const OP_LEN = 5;
|
|
30
30
|
const WEIGHT_LEN = 3;
|
|
@@ -164,7 +164,10 @@ const readPayloadFields = (buf)=>{
|
|
|
164
164
|
const idxA = byte(at + 2);
|
|
165
165
|
const idxB = byte(at + 3);
|
|
166
166
|
const idxC = byte(at + 4);
|
|
167
|
-
|
|
167
|
+
const venue = STELLAR_SWAP_VENUES.find((value)=>STELLAR_SWAP_VENUE_OPCODE[value] === opcode);
|
|
168
|
+
if (!venue && opcode !== OP_BURN && opcode !== OP_MINT) {
|
|
169
|
+
fail('UNKNOWN_OPCODE', `instruction ${i} has opcode ${opcode}`);
|
|
170
|
+
}
|
|
168
171
|
let mode;
|
|
169
172
|
if (modeByte === MODE_ALL) {
|
|
170
173
|
mode = {
|
|
@@ -208,7 +211,7 @@ const readPayloadFields = (buf)=>{
|
|
|
208
211
|
if (idxB === idxC) fail('INVALID_STRUCTURE', `instruction ${i} swaps a token for itself`);
|
|
209
212
|
decoded.push({
|
|
210
213
|
kind: 'swap',
|
|
211
|
-
venue:
|
|
214
|
+
venue: venue,
|
|
212
215
|
mode,
|
|
213
216
|
pool,
|
|
214
217
|
tokenIn: asset(idxB),
|
|
@@ -27,7 +27,8 @@ import { Buffer } from "buffer";
|
|
|
27
27
|
'Aquarius',
|
|
28
28
|
'Phoenix',
|
|
29
29
|
'Sushi',
|
|
30
|
-
'CometDex'
|
|
30
|
+
'CometDex',
|
|
31
|
+
'Curve'
|
|
31
32
|
];
|
|
32
33
|
/**
|
|
33
34
|
* Instruction opcode per venue. Part of the on-chain ABI — see
|
|
@@ -37,7 +38,8 @@ import { Buffer } from "buffer";
|
|
|
37
38
|
Aquarius: 1,
|
|
38
39
|
Phoenix: 2,
|
|
39
40
|
Sushi: 3,
|
|
40
|
-
CometDex: 4
|
|
41
|
+
CometDex: 4,
|
|
42
|
+
Curve: 7
|
|
41
43
|
};
|
|
42
44
|
/** Wire version of the packed program. Must match the contract's `VERSION`. */ export const STELLAR_PROGRAM_VERSION = 1;
|
|
43
45
|
/** Split weights are parts per million. */ export const PPM_DENOMINATOR = 1000000;
|