@lifi/sdk-provider-stellar 4.2.2 → 4.2.4
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 +43 -0
- package/dist/esm/core/tasks/helpers/buildApproveTransaction.d.ts +5 -0
- package/dist/esm/core/tasks/helpers/buildApproveTransaction.d.ts.map +1 -1
- package/dist/esm/core/tasks/helpers/buildApproveTransaction.js +14 -4
- package/dist/esm/core/tasks/helpers/buildApproveTransaction.js.map +1 -1
- package/dist/esm/core/tasks/helpers/deriveTransactionHash.js +2 -1
- package/dist/esm/core/tasks/helpers/deriveTransactionHash.js.map +1 -1
- package/dist/esm/core/tasks/helpers/resolveInclusionFee.d.ts +26 -0
- package/dist/esm/core/tasks/helpers/resolveInclusionFee.d.ts.map +1 -0
- package/dist/esm/core/tasks/helpers/resolveInclusionFee.js +70 -0
- package/dist/esm/core/tasks/helpers/resolveInclusionFee.js.map +1 -0
- package/dist/esm/core/tasks/helpers/submitStellarTransaction.js +2 -2
- package/dist/esm/core/tasks/helpers/submitStellarTransaction.js.map +1 -1
- package/dist/esm/core/tasks/helpers/waitForStellarTransaction.js +1 -1
- package/dist/esm/core/tasks/helpers/waitForStellarTransaction.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/package.json +3 -3
- package/src/core/tasks/helpers/buildApproveTransaction.ts +10 -4
- package/src/core/tasks/helpers/deriveTransactionHash.ts +4 -2
- package/src/core/tasks/helpers/resolveInclusionFee.ts +84 -0
- package/src/core/tasks/helpers/submitStellarTransaction.ts +2 -2
- package/src/core/tasks/helpers/waitForStellarTransaction.ts +1 -1
- package/src/version.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,48 @@
|
|
|
1
1
|
# @lifi/sdk-provider-stellar
|
|
2
2
|
|
|
3
|
+
## 4.2.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#462](https://github.com/lifinance/sdk/pull/462) [`83a179b`](https://github.com/lifinance/sdk/commit/83a179b2d25d84a38e8ff9972f46508dd0a970c3) Thanks [@thesems](https://github.com/thesems)! - Bid the live Soroban inclusion fee for the approval transaction instead of the network minimum, so it doesn't expire unincluded on a congested ledger.
|
|
8
|
+
|
|
9
|
+
## 4.2.3
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#457](https://github.com/lifinance/sdk/pull/457) [`71b03eb`](https://github.com/lifinance/sdk/commit/71b03eb93d8d9af42759e05a359260f5ffd1e87f) Thanks [@chybisov](https://github.com/chybisov)! - Bump `@stellar/stellar-sdk` from 16.2.0 to 17.0.1.
|
|
14
|
+
|
|
15
|
+
v17 rebuilds the XDR namespace as a class based API and switches every byte
|
|
16
|
+
returning API from `Buffer` to `Uint8Array`. The public API of this package is
|
|
17
|
+
unchanged.
|
|
18
|
+
|
|
19
|
+
`deriveTransactionHash` called `.toString('hex')` on the result of
|
|
20
|
+
`transaction.hash()`. That is a `Uint8Array` now, whose `toString` ignores the
|
|
21
|
+
argument and returns comma separated decimals, so the digest is built from the
|
|
22
|
+
bytes instead. The helper still returns the same 64 character lowercase hex
|
|
23
|
+
string, which `StellarSignAndExecuteTask.unit.spec.ts` asserts against an
|
|
24
|
+
independently computed digest.
|
|
25
|
+
|
|
26
|
+
`submitStellarTransaction` and `waitForStellarTransaction` read the failure
|
|
27
|
+
reason through `result().switch().name`. The generated XDR classes expose
|
|
28
|
+
`result` as a readonly field with a `type` discriminant, so both read
|
|
29
|
+
`result.type`. The variant names are unchanged, and a new test pins the failure
|
|
30
|
+
variant into the error message.
|
|
31
|
+
|
|
32
|
+
`toXDR` and `TransactionBuilder.fromXDR` are both deprecated in v17 in favour of
|
|
33
|
+
`toXdr` and `fromXdr`, and both remain as aliases. All seven call sites moved to
|
|
34
|
+
the new names.
|
|
35
|
+
|
|
36
|
+
Two behaviour notes that need no code change here. v17 raises its Node floor to
|
|
37
|
+
22.12.0, and CI runs Node 26. v17 also sends `useUpgradedAuth: true` on every
|
|
38
|
+
simulation rather than omitting the key, which turns on CAP-71 address
|
|
39
|
+
credentials. The two read paths simulate methods that need no authorization, and
|
|
40
|
+
the approve path authorizes with the transaction source account, so a live
|
|
41
|
+
mainnet simulation records `sorobanCredentialsSourceAccount` and the flag has no
|
|
42
|
+
effect. Mainnet is on protocol 27, which activates CAP-71 in any case.
|
|
43
|
+
- Updated dependencies [[`954bc4b`](https://github.com/lifinance/sdk/commit/954bc4bda013b470102041810daf95cb4f9181a1)]:
|
|
44
|
+
- @lifi/sdk@4.6.1
|
|
45
|
+
|
|
3
46
|
## 4.2.2
|
|
4
47
|
|
|
5
48
|
### Patch Changes
|
|
@@ -8,6 +8,11 @@ import { SDKClient } from "@lifi/sdk";
|
|
|
8
8
|
* entries and resource fee into the envelope in one step — the client-side
|
|
9
9
|
* equivalent of what the backend's invocation builder does for route
|
|
10
10
|
* transactions.
|
|
11
|
+
*
|
|
12
|
+
* The inclusion fee is bid off the live distribution rather than left at
|
|
13
|
+
* `BASE_FEE`: this transaction is submitted, and a minimum bid on a busy
|
|
14
|
+
* Soroban ledger expires unincluded instead of failing. See
|
|
15
|
+
* {@link resolveSorobanInclusionFee}.
|
|
11
16
|
*/
|
|
12
17
|
declare const buildApproveTransaction: (client: SDKClient, token: string, from: string, spender: string, amount: bigint, networkPassphrase: string) => Promise<string>;
|
|
13
18
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildApproveTransaction.d.ts","names":[],"sources":["../../../../../src/core/tasks/helpers/buildApproveTransaction.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"buildApproveTransaction.d.ts","names":[],"sources":["../../../../../src/core/tasks/helpers/buildApproveTransaction.ts"],"mappings":";;;;;;;;;;;;;;;;cAgCa,0BACX,QAAQ,WACR,eACA,cACA,iBACA,gBACA,8BACC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { callStellarRpcsWithRetry } from "../../../client/getStellarRpc.js";
|
|
2
|
-
import {
|
|
2
|
+
import { resolveSorobanInclusionFee } from "./resolveInclusionFee.js";
|
|
3
|
+
import { Address, Contract, TransactionBuilder, nativeToScVal } from "@stellar/stellar-sdk";
|
|
3
4
|
//#region src/core/tasks/helpers/buildApproveTransaction.ts
|
|
4
5
|
/**
|
|
5
6
|
* How long the granted allowance stays live, in ledgers. Ledgers close roughly
|
|
@@ -16,14 +17,23 @@ const APPROVAL_TTL_LEDGERS = 17280;
|
|
|
16
17
|
* entries and resource fee into the envelope in one step — the client-side
|
|
17
18
|
* equivalent of what the backend's invocation builder does for route
|
|
18
19
|
* transactions.
|
|
20
|
+
*
|
|
21
|
+
* The inclusion fee is bid off the live distribution rather than left at
|
|
22
|
+
* `BASE_FEE`: this transaction is submitted, and a minimum bid on a busy
|
|
23
|
+
* Soroban ledger expires unincluded instead of failing. See
|
|
24
|
+
* {@link resolveSorobanInclusionFee}.
|
|
19
25
|
*/
|
|
20
26
|
const buildApproveTransaction = async (client, token, from, spender, amount, networkPassphrase) => callStellarRpcsWithRetry(client, async (server) => {
|
|
21
|
-
const [account, latestLedger] = await Promise.all([
|
|
27
|
+
const [account, latestLedger, inclusionFee] = await Promise.all([
|
|
28
|
+
server.getAccount(from),
|
|
29
|
+
server.getLatestLedger(),
|
|
30
|
+
resolveSorobanInclusionFee(server)
|
|
31
|
+
]);
|
|
22
32
|
const transaction = new TransactionBuilder(account, {
|
|
23
|
-
fee:
|
|
33
|
+
fee: inclusionFee,
|
|
24
34
|
networkPassphrase
|
|
25
35
|
}).addOperation(new Contract(token).call("approve", Address.fromString(from).toScVal(), Address.fromString(spender).toScVal(), nativeToScVal(amount, { type: "i128" }), nativeToScVal(latestLedger.sequence + APPROVAL_TTL_LEDGERS, { type: "u32" }))).setTimeout(300).build();
|
|
26
|
-
return (await server.prepareTransaction(transaction)).
|
|
36
|
+
return (await server.prepareTransaction(transaction)).toXdr();
|
|
27
37
|
});
|
|
28
38
|
//#endregion
|
|
29
39
|
export { buildApproveTransaction };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildApproveTransaction.js","names":[],"sources":["../../../../../src/core/tasks/helpers/buildApproveTransaction.ts"],"sourcesContent":["import type { SDKClient } from '@lifi/sdk'\nimport {\n Address,\n
|
|
1
|
+
{"version":3,"file":"buildApproveTransaction.js","names":[],"sources":["../../../../../src/core/tasks/helpers/buildApproveTransaction.ts"],"sourcesContent":["import type { SDKClient } from '@lifi/sdk'\nimport {\n Address,\n Contract,\n nativeToScVal,\n TransactionBuilder,\n} from '@stellar/stellar-sdk'\nimport { callStellarRpcsWithRetry } from '../../../client/getStellarRpc.js'\nimport { resolveSorobanInclusionFee } from './resolveInclusionFee.js'\n\n/**\n * How long the granted allowance stays live, in ledgers. Ledgers close roughly\n * every 5s, so this is ~24h — far longer than the seconds between approving and\n * executing, but enough that a user who steps away mid-route doesn't have to\n * approve twice.\n */\nconst APPROVAL_TTL_LEDGERS = 17_280\n\n/**\n * Builds and simulation-assembles a SAC `approve(from, spender, amount,\n * expiration_ledger)` transaction, returning the unsigned envelope XDR.\n *\n * Uses `prepareTransaction`, which simulates and folds the footprint, auth\n * entries and resource fee into the envelope in one step — the client-side\n * equivalent of what the backend's invocation builder does for route\n * transactions.\n *\n * The inclusion fee is bid off the live distribution rather than left at\n * `BASE_FEE`: this transaction is submitted, and a minimum bid on a busy\n * Soroban ledger expires unincluded instead of failing. See\n * {@link resolveSorobanInclusionFee}.\n */\nexport const buildApproveTransaction = async (\n client: SDKClient,\n token: string,\n from: string,\n spender: string,\n amount: bigint,\n networkPassphrase: string\n): Promise<string> =>\n callStellarRpcsWithRetry(client, async (server) => {\n const [account, latestLedger, inclusionFee] = await Promise.all([\n server.getAccount(from),\n server.getLatestLedger(),\n resolveSorobanInclusionFee(server),\n ])\n\n const transaction = new TransactionBuilder(account, {\n fee: inclusionFee,\n networkPassphrase,\n })\n .addOperation(\n new Contract(token).call(\n 'approve',\n Address.fromString(from).toScVal(),\n Address.fromString(spender).toScVal(),\n nativeToScVal(amount, { type: 'i128' }),\n nativeToScVal(latestLedger.sequence + APPROVAL_TTL_LEDGERS, {\n type: 'u32',\n })\n )\n )\n .setTimeout(300)\n .build()\n\n const prepared = await server.prepareTransaction(transaction)\n return prepared.toXdr()\n })\n"],"mappings":";;;;;;;;;;AAgBA,MAAM,uBAAuB;;;;;;;;;;;;;;;AAgB7B,MAAa,0BAA0B,OACrC,QACA,OACA,MACA,SACA,QACA,sBAEA,yBAAyB,QAAQ,OAAO,WAAW;CACjD,MAAM,CAAC,SAAS,cAAc,gBAAgB,MAAM,QAAQ,IAAI;EAC9D,OAAO,WAAW,IAAI;EACtB,OAAO,gBAAgB;EACvB,2BAA2B,MAAM;CACnC,CAAC;CAED,MAAM,cAAc,IAAI,mBAAmB,SAAS;EAClD,KAAK;EACL;CACF,CAAC,CAAC,CACC,aACC,IAAI,SAAS,KAAK,CAAC,CAAC,KAClB,WACA,QAAQ,WAAW,IAAI,CAAC,CAAC,QAAQ,GACjC,QAAQ,WAAW,OAAO,CAAC,CAAC,QAAQ,GACpC,cAAc,QAAQ,EAAE,MAAM,OAAO,CAAC,GACtC,cAAc,aAAa,WAAW,sBAAsB,EAC1D,MAAM,MACR,CAAC,CACH,CACF,CAAC,CACA,WAAW,GAAG,CAAC,CACf,MAAM;CAGT,QAAO,MADgB,OAAO,mBAAmB,WAAW,EAAA,CAC5C,MAAM;AACxB,CAAC"}
|
|
@@ -8,7 +8,8 @@ import { TransactionBuilder } from "@stellar/stellar-sdk";
|
|
|
8
8
|
* hash first and resume by polling instead of re-signing.
|
|
9
9
|
*/
|
|
10
10
|
const deriveTransactionHash = (signedTxXdr, networkPassphrase) => {
|
|
11
|
-
|
|
11
|
+
const transaction = TransactionBuilder.fromXdr(signedTxXdr, networkPassphrase);
|
|
12
|
+
return Array.from(transaction.hash(), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
12
13
|
};
|
|
13
14
|
//#endregion
|
|
14
15
|
export { deriveTransactionHash };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deriveTransactionHash.js","names":[],"sources":["../../../../../src/core/tasks/helpers/deriveTransactionHash.ts"],"sourcesContent":["import { type Transaction, TransactionBuilder } from '@stellar/stellar-sdk'\n\n/**\n * Derives the canonical transaction hash from a signed base64 envelope.\n *\n * The hash is a function of the envelope and the network passphrase, so it is\n * knowable before submission — which is what lets a signing task persist the\n * hash first and resume by polling instead of re-signing.\n */\nexport const deriveTransactionHash = (\n signedTxXdr: string,\n networkPassphrase: string\n): string => {\n const transaction = TransactionBuilder.
|
|
1
|
+
{"version":3,"file":"deriveTransactionHash.js","names":[],"sources":["../../../../../src/core/tasks/helpers/deriveTransactionHash.ts"],"sourcesContent":["import { type Transaction, TransactionBuilder } from '@stellar/stellar-sdk'\n\n/**\n * Derives the canonical transaction hash from a signed base64 envelope.\n *\n * The hash is a function of the envelope and the network passphrase, so it is\n * knowable before submission — which is what lets a signing task persist the\n * hash first and resume by polling instead of re-signing.\n */\nexport const deriveTransactionHash = (\n signedTxXdr: string,\n networkPassphrase: string\n): string => {\n const transaction = TransactionBuilder.fromXdr(\n signedTxXdr,\n networkPassphrase\n ) as Transaction\n return Array.from(transaction.hash(), (byte) =>\n byte.toString(16).padStart(2, '0')\n ).join('')\n}\n"],"mappings":";;;;;;;;;AASA,MAAa,yBACX,aACA,sBACW;CACX,MAAM,cAAc,mBAAmB,QACrC,aACA,iBACF;CACA,OAAO,MAAM,KAAK,YAAY,KAAK,IAAI,SACrC,KAAK,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,GAAG,CACnC,CAAC,CAAC,KAAK,EAAE;AACX"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Server } from "@stellar/stellar-sdk/rpc";
|
|
2
|
+
//#region src/core/tasks/helpers/resolveInclusionFee.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Resolves the per-operation inclusion fee to bid for a Soroban transaction.
|
|
5
|
+
*
|
|
6
|
+
* `BASE_FEE` is the network *minimum*, not a market price: Soroban validators
|
|
7
|
+
* rank transactions by the inclusion component alone, and when the Soroban
|
|
8
|
+
* ledger is at capacity every included transaction pays well above the minimum.
|
|
9
|
+
* A minimum bid is then accepted into the mempool, never wins a slot, and dies
|
|
10
|
+
* silently when its timebound expires — `sendTransaction` reports `PENDING` and
|
|
11
|
+
* `getTransaction` reports `NOT_FOUND` forever, with nothing on chain to
|
|
12
|
+
* explain it. Reading the live distribution is what avoids that.
|
|
13
|
+
*
|
|
14
|
+
* Note the resource fee cannot substitute for this. `prepareTransaction` folds
|
|
15
|
+
* a large resource fee into the total, but that buys nothing in the inclusion
|
|
16
|
+
* queue.
|
|
17
|
+
*
|
|
18
|
+
* Fee stats are read best-effort: the surrounding RPC failover has already
|
|
19
|
+
* proven this server answers, so a `getFeeStats` hiccup falls back to a bid
|
|
20
|
+
* rather than failing the approval. Both degraded paths warn, because a silent
|
|
21
|
+
* fallback re-creates the undiagnosable failure this helper exists to remove.
|
|
22
|
+
*/
|
|
23
|
+
declare const resolveSorobanInclusionFee: (server: Server) => Promise<string>;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { resolveSorobanInclusionFee };
|
|
26
|
+
//# sourceMappingURL=resolveInclusionFee.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveInclusionFee.d.ts","names":[],"sources":["../../../../../src/core/tasks/helpers/resolveInclusionFee.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;cA2Da,6BACX,QAAQ,WACP"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { BASE_FEE } from "@stellar/stellar-sdk";
|
|
2
|
+
//#region src/core/tasks/helpers/resolveInclusionFee.ts
|
|
3
|
+
/** stroops/op — the network minimum, and the floor under any bid. */
|
|
4
|
+
const MIN_BASE_FEE = Number(BASE_FEE);
|
|
5
|
+
/** stroops/op — the bid placed when fee stats cannot be read or decoded. */
|
|
6
|
+
const FALLBACK_FEE = 1e4;
|
|
7
|
+
/**
|
|
8
|
+
* stroops/op cap (0.1 XLM). A broken RPC percentile must never reach a real
|
|
9
|
+
* bid, so the ceiling is enforced even on a value the network reported.
|
|
10
|
+
*/
|
|
11
|
+
const MAX_FEE_STROOPS = 1e6;
|
|
12
|
+
/**
|
|
13
|
+
* Percentile read for the inclusion bid.
|
|
14
|
+
*
|
|
15
|
+
* `p70` matches the backend's `standard` fee tier — `getFeeTiers` in
|
|
16
|
+
* lifi-backend `apps/backend-api/src/stellar/gas/stellar.gas.ts` maps
|
|
17
|
+
* slow/standard/fast to p20/p70/p95, and the three constants above mirror that
|
|
18
|
+
* module. Bidding the same percentile keeps the approval and the route it
|
|
19
|
+
* unblocks on equal terms: a cheaper approval is not a cheaper route — it is a
|
|
20
|
+
* route that never starts.
|
|
21
|
+
*
|
|
22
|
+
* Known limitation. `getFeeStats` reports the inclusion fees transactions were
|
|
23
|
+
* *charged*, not the fees they bid. Under surge pricing every transaction in an
|
|
24
|
+
* included set pays the lowest bid in that set, so the reported values cluster
|
|
25
|
+
* at recent clearing prices rather than spanning a range of bids — a 2026-09
|
|
26
|
+
* mainnet sample over ~7k transactions returned `p10` through `p99` all equal.
|
|
27
|
+
* A mid percentile of clearing prices is therefore a marginal bid. Raising it
|
|
28
|
+
* is worth doing, but only alongside the backend so the two stay aligned.
|
|
29
|
+
*/
|
|
30
|
+
const INCLUSION_FEE_PERCENTILE = "p70";
|
|
31
|
+
/** Bounds a bid to an integer in range — the builder rejects non-integers. */
|
|
32
|
+
const clampBid = (value) => Math.floor(Math.min(MAX_FEE_STROOPS, Math.max(MIN_BASE_FEE, value)));
|
|
33
|
+
/**
|
|
34
|
+
* Resolves the per-operation inclusion fee to bid for a Soroban transaction.
|
|
35
|
+
*
|
|
36
|
+
* `BASE_FEE` is the network *minimum*, not a market price: Soroban validators
|
|
37
|
+
* rank transactions by the inclusion component alone, and when the Soroban
|
|
38
|
+
* ledger is at capacity every included transaction pays well above the minimum.
|
|
39
|
+
* A minimum bid is then accepted into the mempool, never wins a slot, and dies
|
|
40
|
+
* silently when its timebound expires — `sendTransaction` reports `PENDING` and
|
|
41
|
+
* `getTransaction` reports `NOT_FOUND` forever, with nothing on chain to
|
|
42
|
+
* explain it. Reading the live distribution is what avoids that.
|
|
43
|
+
*
|
|
44
|
+
* Note the resource fee cannot substitute for this. `prepareTransaction` folds
|
|
45
|
+
* a large resource fee into the total, but that buys nothing in the inclusion
|
|
46
|
+
* queue.
|
|
47
|
+
*
|
|
48
|
+
* Fee stats are read best-effort: the surrounding RPC failover has already
|
|
49
|
+
* proven this server answers, so a `getFeeStats` hiccup falls back to a bid
|
|
50
|
+
* rather than failing the approval. Both degraded paths warn, because a silent
|
|
51
|
+
* fallback re-creates the undiagnosable failure this helper exists to remove.
|
|
52
|
+
*/
|
|
53
|
+
const resolveSorobanInclusionFee = async (server) => {
|
|
54
|
+
try {
|
|
55
|
+
const reported = (await server.getFeeStats())?.sorobanInclusionFee?.[INCLUSION_FEE_PERCENTILE];
|
|
56
|
+
const percentile = Number(reported);
|
|
57
|
+
if (!Number.isFinite(percentile) || percentile <= 0) {
|
|
58
|
+
console.warn("[resolveSorobanInclusionFee] Unusable fee percentile, using fallback bid:", FALLBACK_FEE, reported);
|
|
59
|
+
return String(FALLBACK_FEE);
|
|
60
|
+
}
|
|
61
|
+
return String(clampBid(percentile));
|
|
62
|
+
} catch (error) {
|
|
63
|
+
console.warn("[resolveSorobanInclusionFee] Fee stats unreadable, using fallback bid:", FALLBACK_FEE, error);
|
|
64
|
+
return String(FALLBACK_FEE);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
//#endregion
|
|
68
|
+
export { resolveSorobanInclusionFee };
|
|
69
|
+
|
|
70
|
+
//# sourceMappingURL=resolveInclusionFee.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveInclusionFee.js","names":[],"sources":["../../../../../src/core/tasks/helpers/resolveInclusionFee.ts"],"sourcesContent":["import { BASE_FEE } from '@stellar/stellar-sdk'\nimport type { Server } from '@stellar/stellar-sdk/rpc'\n\n/** stroops/op — the network minimum, and the floor under any bid. */\nconst MIN_BASE_FEE = Number(BASE_FEE)\n\n/** stroops/op — the bid placed when fee stats cannot be read or decoded. */\nconst FALLBACK_FEE = 10_000\n\n/**\n * stroops/op cap (0.1 XLM). A broken RPC percentile must never reach a real\n * bid, so the ceiling is enforced even on a value the network reported.\n */\nconst MAX_FEE_STROOPS = 1_000_000\n\n/**\n * Percentile read for the inclusion bid.\n *\n * `p70` matches the backend's `standard` fee tier — `getFeeTiers` in\n * lifi-backend `apps/backend-api/src/stellar/gas/stellar.gas.ts` maps\n * slow/standard/fast to p20/p70/p95, and the three constants above mirror that\n * module. Bidding the same percentile keeps the approval and the route it\n * unblocks on equal terms: a cheaper approval is not a cheaper route — it is a\n * route that never starts.\n *\n * Known limitation. `getFeeStats` reports the inclusion fees transactions were\n * *charged*, not the fees they bid. Under surge pricing every transaction in an\n * included set pays the lowest bid in that set, so the reported values cluster\n * at recent clearing prices rather than spanning a range of bids — a 2026-09\n * mainnet sample over ~7k transactions returned `p10` through `p99` all equal.\n * A mid percentile of clearing prices is therefore a marginal bid. Raising it\n * is worth doing, but only alongside the backend so the two stay aligned.\n */\nconst INCLUSION_FEE_PERCENTILE = 'p70' as const\n\n/** Bounds a bid to an integer in range — the builder rejects non-integers. */\nconst clampBid = (value: number): number =>\n Math.floor(Math.min(MAX_FEE_STROOPS, Math.max(MIN_BASE_FEE, value)))\n\n/**\n * Resolves the per-operation inclusion fee to bid for a Soroban transaction.\n *\n * `BASE_FEE` is the network *minimum*, not a market price: Soroban validators\n * rank transactions by the inclusion component alone, and when the Soroban\n * ledger is at capacity every included transaction pays well above the minimum.\n * A minimum bid is then accepted into the mempool, never wins a slot, and dies\n * silently when its timebound expires — `sendTransaction` reports `PENDING` and\n * `getTransaction` reports `NOT_FOUND` forever, with nothing on chain to\n * explain it. Reading the live distribution is what avoids that.\n *\n * Note the resource fee cannot substitute for this. `prepareTransaction` folds\n * a large resource fee into the total, but that buys nothing in the inclusion\n * queue.\n *\n * Fee stats are read best-effort: the surrounding RPC failover has already\n * proven this server answers, so a `getFeeStats` hiccup falls back to a bid\n * rather than failing the approval. Both degraded paths warn, because a silent\n * fallback re-creates the undiagnosable failure this helper exists to remove.\n */\nexport const resolveSorobanInclusionFee = async (\n server: Server\n): Promise<string> => {\n try {\n const feeStats = await server.getFeeStats()\n const reported = feeStats?.sorobanInclusionFee?.[INCLUSION_FEE_PERCENTILE]\n const percentile = Number(reported)\n if (!Number.isFinite(percentile) || percentile <= 0) {\n console.warn(\n '[resolveSorobanInclusionFee] Unusable fee percentile, using fallback bid:',\n FALLBACK_FEE,\n reported\n )\n return String(FALLBACK_FEE)\n }\n return String(clampBid(percentile))\n } catch (error) {\n console.warn(\n '[resolveSorobanInclusionFee] Fee stats unreadable, using fallback bid:',\n FALLBACK_FEE,\n error\n )\n return String(FALLBACK_FEE)\n }\n}\n"],"mappings":";;;AAIA,MAAM,eAAe,OAAO,QAAQ;;AAGpC,MAAM,eAAe;;;;;AAMrB,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;AAoBxB,MAAM,2BAA2B;;AAGjC,MAAM,YAAY,UAChB,KAAK,MAAM,KAAK,IAAI,iBAAiB,KAAK,IAAI,cAAc,KAAK,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;AAsBrE,MAAa,6BAA6B,OACxC,WACoB;CACpB,IAAI;EAEF,MAAM,YAAW,MADM,OAAO,YAAY,EAAA,EACf,sBAAsB;EACjD,MAAM,aAAa,OAAO,QAAQ;EAClC,IAAI,CAAC,OAAO,SAAS,UAAU,KAAK,cAAc,GAAG;GACnD,QAAQ,KACN,6EACA,cACA,QACF;GACA,OAAO,OAAO,YAAY;EAC5B;EACA,OAAO,OAAO,SAAS,UAAU,CAAC;CACpC,SAAS,OAAO;EACd,QAAQ,KACN,0EACA,cACA,KACF;EACA,OAAO,OAAO,YAAY;CAC5B;AACF"}
|
|
@@ -27,14 +27,14 @@ const TRY_AGAIN_DELAY_MS = 2e3;
|
|
|
27
27
|
* core is telling us the envelope was not queued, not that it is invalid.
|
|
28
28
|
*/
|
|
29
29
|
const submitStellarTransaction = async (client, signedTxXdr, networkPassphrase) => {
|
|
30
|
-
const transaction = TransactionBuilder.
|
|
30
|
+
const transaction = TransactionBuilder.fromXdr(signedTxXdr, networkPassphrase);
|
|
31
31
|
for (let attempt = 0; attempt < TRY_AGAIN_ATTEMPTS; attempt++) {
|
|
32
32
|
const response = await callStellarRpcsWithRetry(client, (server) => server.sendTransaction(transaction));
|
|
33
33
|
switch (response.status) {
|
|
34
34
|
case "PENDING":
|
|
35
35
|
case "DUPLICATE": return response.hash;
|
|
36
36
|
case "TRY_AGAIN_LATER": break;
|
|
37
|
-
default: throw new TransactionError(LiFiErrorCode.TransactionFailed, `Stellar transaction submission failed: ${response.errorResult?.result
|
|
37
|
+
default: throw new TransactionError(LiFiErrorCode.TransactionFailed, `Stellar transaction submission failed: ${response.errorResult?.result.type ?? response.status}`);
|
|
38
38
|
}
|
|
39
39
|
if (attempt < 2) await new Promise((resolve) => setTimeout(resolve, TRY_AGAIN_DELAY_MS));
|
|
40
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"submitStellarTransaction.js","names":[],"sources":["../../../../../src/core/tasks/helpers/submitStellarTransaction.ts"],"sourcesContent":["import { LiFiErrorCode, type SDKClient, TransactionError } from '@lifi/sdk'\nimport { type Transaction, TransactionBuilder } from '@stellar/stellar-sdk'\nimport type { Api } from '@stellar/stellar-sdk/rpc'\nimport { callStellarRpcsWithRetry } from '../../../client/getStellarRpc.js'\n\n/**\n * `TRY_AGAIN_LATER` says the envelope is valid but was not queued, so the fix\n * is to send the same envelope again. Submission is idempotent by hash, which\n * makes the retry free of side effects.\n */\nconst TRY_AGAIN_ATTEMPTS = 3\nconst TRY_AGAIN_DELAY_MS = 2_000\n\n/**\n * Submits a signed base64 envelope over Stellar RPC and returns the hash.\n *\n * Only the transport call goes through {@link callStellarRpcsWithRetry}, so a\n * dead RPC fails over to the next one. Classifying the response happens outside\n * that wrapper on purpose: the helper collapses everything its callback throws\n * into an `AggregateError`, which would hide a classified `TransactionError`\n * from `parseStellarErrors` and surface every rejection as an unknown error.\n *\n * `DUPLICATE` counts as success — it means this exact envelope already reached\n * the network, the expected outcome when failover retries a submission the first\n * RPC had in fact accepted. Soroban submission is idempotent by hash, so the\n * right move is to stop resubmitting and start polling.\n *\n * `TRY_AGAIN_LATER` is retried a bounded number of times rather than thrown:\n * core is telling us the envelope was not queued, not that it is invalid.\n */\nexport const submitStellarTransaction = async (\n client: SDKClient,\n signedTxXdr: string,\n networkPassphrase: string\n): Promise<string> => {\n const transaction = TransactionBuilder.
|
|
1
|
+
{"version":3,"file":"submitStellarTransaction.js","names":[],"sources":["../../../../../src/core/tasks/helpers/submitStellarTransaction.ts"],"sourcesContent":["import { LiFiErrorCode, type SDKClient, TransactionError } from '@lifi/sdk'\nimport { type Transaction, TransactionBuilder } from '@stellar/stellar-sdk'\nimport type { Api } from '@stellar/stellar-sdk/rpc'\nimport { callStellarRpcsWithRetry } from '../../../client/getStellarRpc.js'\n\n/**\n * `TRY_AGAIN_LATER` says the envelope is valid but was not queued, so the fix\n * is to send the same envelope again. Submission is idempotent by hash, which\n * makes the retry free of side effects.\n */\nconst TRY_AGAIN_ATTEMPTS = 3\nconst TRY_AGAIN_DELAY_MS = 2_000\n\n/**\n * Submits a signed base64 envelope over Stellar RPC and returns the hash.\n *\n * Only the transport call goes through {@link callStellarRpcsWithRetry}, so a\n * dead RPC fails over to the next one. Classifying the response happens outside\n * that wrapper on purpose: the helper collapses everything its callback throws\n * into an `AggregateError`, which would hide a classified `TransactionError`\n * from `parseStellarErrors` and surface every rejection as an unknown error.\n *\n * `DUPLICATE` counts as success — it means this exact envelope already reached\n * the network, the expected outcome when failover retries a submission the first\n * RPC had in fact accepted. Soroban submission is idempotent by hash, so the\n * right move is to stop resubmitting and start polling.\n *\n * `TRY_AGAIN_LATER` is retried a bounded number of times rather than thrown:\n * core is telling us the envelope was not queued, not that it is invalid.\n */\nexport const submitStellarTransaction = async (\n client: SDKClient,\n signedTxXdr: string,\n networkPassphrase: string\n): Promise<string> => {\n const transaction = TransactionBuilder.fromXdr(\n signedTxXdr,\n networkPassphrase\n ) as Transaction\n\n for (let attempt = 0; attempt < TRY_AGAIN_ATTEMPTS; attempt++) {\n const response: Api.SendTransactionResponse =\n await callStellarRpcsWithRetry(client, (server) =>\n server.sendTransaction(transaction)\n )\n\n switch (response.status) {\n case 'PENDING':\n case 'DUPLICATE':\n return response.hash\n case 'TRY_AGAIN_LATER':\n break\n default:\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n `Stellar transaction submission failed: ${\n response.errorResult?.result.type ?? response.status\n }`\n )\n }\n\n if (attempt < TRY_AGAIN_ATTEMPTS - 1) {\n await new Promise((resolve) => setTimeout(resolve, TRY_AGAIN_DELAY_MS))\n }\n }\n\n throw new TransactionError(\n LiFiErrorCode.RateLimitExceeded,\n 'Stellar RPC asked to try again later.'\n )\n}\n"],"mappings":";;;;;;;;;AAUA,MAAM,qBAAqB;AAC3B,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;AAmB3B,MAAa,2BAA2B,OACtC,QACA,aACA,sBACoB;CACpB,MAAM,cAAc,mBAAmB,QACrC,aACA,iBACF;CAEA,KAAK,IAAI,UAAU,GAAG,UAAU,oBAAoB,WAAW;EAC7D,MAAM,WACJ,MAAM,yBAAyB,SAAS,WACtC,OAAO,gBAAgB,WAAW,CACpC;EAEF,QAAQ,SAAS,QAAjB;GACE,KAAK;GACL,KAAK,aACH,OAAO,SAAS;GAClB,KAAK,mBACH;GACF,SACE,MAAM,IAAI,iBACR,cAAc,mBACd,0CACE,SAAS,aAAa,OAAO,QAAQ,SAAS,QAElD;EACJ;EAEA,IAAI,UAAU,GACZ,MAAM,IAAI,SAAS,YAAY,WAAW,SAAS,kBAAkB,CAAC;CAE1E;CAEA,MAAM,IAAI,iBACR,cAAc,mBACd,uCACF;AACF"}
|
|
@@ -32,7 +32,7 @@ const waitForStellarTransaction = async (client, transactionHash, pollingInterva
|
|
|
32
32
|
try {
|
|
33
33
|
const response = await callStellarRpcsWithRetry(client, (server) => server.getTransaction(transactionHash));
|
|
34
34
|
if (response.status === Api.GetTransactionStatus.SUCCESS) return response;
|
|
35
|
-
if (response.status === Api.GetTransactionStatus.FAILED) throw new TransactionError(LiFiErrorCode.TransactionFailed, `Stellar transaction ${transactionHash} failed: ${response.resultXdr?.result
|
|
35
|
+
if (response.status === Api.GetTransactionStatus.FAILED) throw new TransactionError(LiFiErrorCode.TransactionFailed, `Stellar transaction ${transactionHash} failed: ${response.resultXdr?.result.type ?? "unknown reason"}`);
|
|
36
36
|
} catch (error) {
|
|
37
37
|
if (error instanceof TransactionError) throw error;
|
|
38
38
|
lastTransportError = error instanceof Error ? error : new Error(String(error));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"waitForStellarTransaction.js","names":[],"sources":["../../../../../src/core/tasks/helpers/waitForStellarTransaction.ts"],"sourcesContent":["import { LiFiErrorCode, type SDKClient, TransactionError } from '@lifi/sdk'\nimport { Api } from '@stellar/stellar-sdk/rpc'\nimport { callStellarRpcsWithRetry } from '../../../client/getStellarRpc.js'\n\nconst CONFIRM_POLL_INTERVAL_MS = 3_000\n\n/**\n * Outlives the backend's `[0, now + 300 s]` timebounds, so a transaction that\n * has not been applied by the deadline is genuinely dead rather than still in\n * flight. Expressed as a deadline, not an attempt count, so a caller-supplied\n * polling interval cannot shorten the budget.\n */\nconst CONFIRM_TIMEOUT_MS = 330_000\n\n/**\n * Polls `getTransaction` until the transaction is included in a ledger.\n *\n * `NOT_FOUND` is not an error — Soroban RPC only knows a transaction once it has\n * been applied — so polling continues until the deadline passes and the result\n * is reported as a timeout rather than a failure.\n *\n * A transport failure costs one interval rather than the whole wait: every RPC\n * can reject one read during a rate-limit burst while the transaction is\n * perfectly healthy. The last such error rides along as the timeout's cause.\n *\n * The terminal classification is deliberately done outside\n * {@link callStellarRpcsWithRetry}; only the read goes through the failover\n * wrapper, which would otherwise wrap a classified error in an `AggregateError`.\n */\nexport const waitForStellarTransaction = async (\n client: SDKClient,\n transactionHash: string,\n pollingIntervalMs: number = CONFIRM_POLL_INTERVAL_MS\n): Promise<Api.GetSuccessfulTransactionResponse> => {\n const deadline = Date.now() + CONFIRM_TIMEOUT_MS\n let lastTransportError: Error | undefined\n\n while (Date.now() < deadline) {\n try {\n const response = await callStellarRpcsWithRetry(client, (server) =>\n server.getTransaction(transactionHash)\n )\n\n if (response.status === Api.GetTransactionStatus.SUCCESS) {\n return response\n }\n\n if (response.status === Api.GetTransactionStatus.FAILED) {\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n `Stellar transaction ${transactionHash} failed: ${\n response.resultXdr?.result
|
|
1
|
+
{"version":3,"file":"waitForStellarTransaction.js","names":[],"sources":["../../../../../src/core/tasks/helpers/waitForStellarTransaction.ts"],"sourcesContent":["import { LiFiErrorCode, type SDKClient, TransactionError } from '@lifi/sdk'\nimport { Api } from '@stellar/stellar-sdk/rpc'\nimport { callStellarRpcsWithRetry } from '../../../client/getStellarRpc.js'\n\nconst CONFIRM_POLL_INTERVAL_MS = 3_000\n\n/**\n * Outlives the backend's `[0, now + 300 s]` timebounds, so a transaction that\n * has not been applied by the deadline is genuinely dead rather than still in\n * flight. Expressed as a deadline, not an attempt count, so a caller-supplied\n * polling interval cannot shorten the budget.\n */\nconst CONFIRM_TIMEOUT_MS = 330_000\n\n/**\n * Polls `getTransaction` until the transaction is included in a ledger.\n *\n * `NOT_FOUND` is not an error — Soroban RPC only knows a transaction once it has\n * been applied — so polling continues until the deadline passes and the result\n * is reported as a timeout rather than a failure.\n *\n * A transport failure costs one interval rather than the whole wait: every RPC\n * can reject one read during a rate-limit burst while the transaction is\n * perfectly healthy. The last such error rides along as the timeout's cause.\n *\n * The terminal classification is deliberately done outside\n * {@link callStellarRpcsWithRetry}; only the read goes through the failover\n * wrapper, which would otherwise wrap a classified error in an `AggregateError`.\n */\nexport const waitForStellarTransaction = async (\n client: SDKClient,\n transactionHash: string,\n pollingIntervalMs: number = CONFIRM_POLL_INTERVAL_MS\n): Promise<Api.GetSuccessfulTransactionResponse> => {\n const deadline = Date.now() + CONFIRM_TIMEOUT_MS\n let lastTransportError: Error | undefined\n\n while (Date.now() < deadline) {\n try {\n const response = await callStellarRpcsWithRetry(client, (server) =>\n server.getTransaction(transactionHash)\n )\n\n if (response.status === Api.GetTransactionStatus.SUCCESS) {\n return response\n }\n\n if (response.status === Api.GetTransactionStatus.FAILED) {\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n `Stellar transaction ${transactionHash} failed: ${\n response.resultXdr?.result.type ?? 'unknown reason'\n }`\n )\n }\n } catch (error) {\n // The ledger's verdict is terminal; only transport failures are retried.\n if (error instanceof TransactionError) {\n throw error\n }\n lastTransportError =\n error instanceof Error ? error : new Error(String(error))\n }\n\n await new Promise((resolve) => setTimeout(resolve, pollingIntervalMs))\n }\n\n throw new TransactionError(\n LiFiErrorCode.Timeout,\n `Stellar transaction ${transactionHash} was not confirmed in time.`,\n lastTransportError\n )\n}\n"],"mappings":";;;;AAIA,MAAM,2BAA2B;;;;;;;AAQjC,MAAM,qBAAqB;;;;;;;;;;;;;;;;AAiB3B,MAAa,4BAA4B,OACvC,QACA,iBACA,oBAA4B,6BACsB;CAClD,MAAM,WAAW,KAAK,IAAI,IAAI;CAC9B,IAAI;CAEJ,OAAO,KAAK,IAAI,IAAI,UAAU;EAC5B,IAAI;GACF,MAAM,WAAW,MAAM,yBAAyB,SAAS,WACvD,OAAO,eAAe,eAAe,CACvC;GAEA,IAAI,SAAS,WAAW,IAAI,qBAAqB,SAC/C,OAAO;GAGT,IAAI,SAAS,WAAW,IAAI,qBAAqB,QAC/C,MAAM,IAAI,iBACR,cAAc,mBACd,uBAAuB,gBAAgB,WACrC,SAAS,WAAW,OAAO,QAAQ,kBAEvC;EAEJ,SAAS,OAAO;GAEd,IAAI,iBAAiB,kBACnB,MAAM;GAER,qBACE,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC;EAC5D;EAEA,MAAM,IAAI,SAAS,YAAY,WAAW,SAAS,iBAAiB,CAAC;CACvE;CAEA,MAAM,IAAI,iBACR,cAAc,SACd,uBAAuB,gBAAgB,8BACvC,kBACF;AACF"}
|
package/dist/esm/version.d.ts
CHANGED
package/dist/esm/version.js
CHANGED
package/dist/esm/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-stellar'\nexport const version = '4.2.
|
|
1
|
+
{"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-stellar'\nexport const version = '4.2.4'\n"],"mappings":";AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/sdk-provider-stellar",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.4",
|
|
4
4
|
"description": "LI.FI Stellar SDK Provider for Any-to-Any Cross-Chain-Swap",
|
|
5
5
|
"homepage": "https://github.com/lifinance/sdk",
|
|
6
6
|
"bugs": {
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"./package.json": "./package.json"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@lifi/sdk": "4.6.
|
|
32
|
-
"@stellar/stellar-sdk": "^
|
|
31
|
+
"@lifi/sdk": "4.6.1",
|
|
32
|
+
"@stellar/stellar-sdk": "^17.0.1"
|
|
33
33
|
},
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"access": "public"
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { SDKClient } from '@lifi/sdk'
|
|
2
2
|
import {
|
|
3
3
|
Address,
|
|
4
|
-
BASE_FEE,
|
|
5
4
|
Contract,
|
|
6
5
|
nativeToScVal,
|
|
7
6
|
TransactionBuilder,
|
|
8
7
|
} from '@stellar/stellar-sdk'
|
|
9
8
|
import { callStellarRpcsWithRetry } from '../../../client/getStellarRpc.js'
|
|
9
|
+
import { resolveSorobanInclusionFee } from './resolveInclusionFee.js'
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* How long the granted allowance stays live, in ledgers. Ledgers close roughly
|
|
@@ -24,6 +24,11 @@ const APPROVAL_TTL_LEDGERS = 17_280
|
|
|
24
24
|
* entries and resource fee into the envelope in one step — the client-side
|
|
25
25
|
* equivalent of what the backend's invocation builder does for route
|
|
26
26
|
* transactions.
|
|
27
|
+
*
|
|
28
|
+
* The inclusion fee is bid off the live distribution rather than left at
|
|
29
|
+
* `BASE_FEE`: this transaction is submitted, and a minimum bid on a busy
|
|
30
|
+
* Soroban ledger expires unincluded instead of failing. See
|
|
31
|
+
* {@link resolveSorobanInclusionFee}.
|
|
27
32
|
*/
|
|
28
33
|
export const buildApproveTransaction = async (
|
|
29
34
|
client: SDKClient,
|
|
@@ -34,13 +39,14 @@ export const buildApproveTransaction = async (
|
|
|
34
39
|
networkPassphrase: string
|
|
35
40
|
): Promise<string> =>
|
|
36
41
|
callStellarRpcsWithRetry(client, async (server) => {
|
|
37
|
-
const [account, latestLedger] = await Promise.all([
|
|
42
|
+
const [account, latestLedger, inclusionFee] = await Promise.all([
|
|
38
43
|
server.getAccount(from),
|
|
39
44
|
server.getLatestLedger(),
|
|
45
|
+
resolveSorobanInclusionFee(server),
|
|
40
46
|
])
|
|
41
47
|
|
|
42
48
|
const transaction = new TransactionBuilder(account, {
|
|
43
|
-
fee:
|
|
49
|
+
fee: inclusionFee,
|
|
44
50
|
networkPassphrase,
|
|
45
51
|
})
|
|
46
52
|
.addOperation(
|
|
@@ -58,5 +64,5 @@ export const buildApproveTransaction = async (
|
|
|
58
64
|
.build()
|
|
59
65
|
|
|
60
66
|
const prepared = await server.prepareTransaction(transaction)
|
|
61
|
-
return prepared.
|
|
67
|
+
return prepared.toXdr()
|
|
62
68
|
})
|
|
@@ -11,9 +11,11 @@ export const deriveTransactionHash = (
|
|
|
11
11
|
signedTxXdr: string,
|
|
12
12
|
networkPassphrase: string
|
|
13
13
|
): string => {
|
|
14
|
-
const transaction = TransactionBuilder.
|
|
14
|
+
const transaction = TransactionBuilder.fromXdr(
|
|
15
15
|
signedTxXdr,
|
|
16
16
|
networkPassphrase
|
|
17
17
|
) as Transaction
|
|
18
|
-
return transaction.hash()
|
|
18
|
+
return Array.from(transaction.hash(), (byte) =>
|
|
19
|
+
byte.toString(16).padStart(2, '0')
|
|
20
|
+
).join('')
|
|
19
21
|
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { BASE_FEE } from '@stellar/stellar-sdk'
|
|
2
|
+
import type { Server } from '@stellar/stellar-sdk/rpc'
|
|
3
|
+
|
|
4
|
+
/** stroops/op — the network minimum, and the floor under any bid. */
|
|
5
|
+
const MIN_BASE_FEE = Number(BASE_FEE)
|
|
6
|
+
|
|
7
|
+
/** stroops/op — the bid placed when fee stats cannot be read or decoded. */
|
|
8
|
+
const FALLBACK_FEE = 10_000
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* stroops/op cap (0.1 XLM). A broken RPC percentile must never reach a real
|
|
12
|
+
* bid, so the ceiling is enforced even on a value the network reported.
|
|
13
|
+
*/
|
|
14
|
+
const MAX_FEE_STROOPS = 1_000_000
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Percentile read for the inclusion bid.
|
|
18
|
+
*
|
|
19
|
+
* `p70` matches the backend's `standard` fee tier — `getFeeTiers` in
|
|
20
|
+
* lifi-backend `apps/backend-api/src/stellar/gas/stellar.gas.ts` maps
|
|
21
|
+
* slow/standard/fast to p20/p70/p95, and the three constants above mirror that
|
|
22
|
+
* module. Bidding the same percentile keeps the approval and the route it
|
|
23
|
+
* unblocks on equal terms: a cheaper approval is not a cheaper route — it is a
|
|
24
|
+
* route that never starts.
|
|
25
|
+
*
|
|
26
|
+
* Known limitation. `getFeeStats` reports the inclusion fees transactions were
|
|
27
|
+
* *charged*, not the fees they bid. Under surge pricing every transaction in an
|
|
28
|
+
* included set pays the lowest bid in that set, so the reported values cluster
|
|
29
|
+
* at recent clearing prices rather than spanning a range of bids — a 2026-09
|
|
30
|
+
* mainnet sample over ~7k transactions returned `p10` through `p99` all equal.
|
|
31
|
+
* A mid percentile of clearing prices is therefore a marginal bid. Raising it
|
|
32
|
+
* is worth doing, but only alongside the backend so the two stay aligned.
|
|
33
|
+
*/
|
|
34
|
+
const INCLUSION_FEE_PERCENTILE = 'p70' as const
|
|
35
|
+
|
|
36
|
+
/** Bounds a bid to an integer in range — the builder rejects non-integers. */
|
|
37
|
+
const clampBid = (value: number): number =>
|
|
38
|
+
Math.floor(Math.min(MAX_FEE_STROOPS, Math.max(MIN_BASE_FEE, value)))
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Resolves the per-operation inclusion fee to bid for a Soroban transaction.
|
|
42
|
+
*
|
|
43
|
+
* `BASE_FEE` is the network *minimum*, not a market price: Soroban validators
|
|
44
|
+
* rank transactions by the inclusion component alone, and when the Soroban
|
|
45
|
+
* ledger is at capacity every included transaction pays well above the minimum.
|
|
46
|
+
* A minimum bid is then accepted into the mempool, never wins a slot, and dies
|
|
47
|
+
* silently when its timebound expires — `sendTransaction` reports `PENDING` and
|
|
48
|
+
* `getTransaction` reports `NOT_FOUND` forever, with nothing on chain to
|
|
49
|
+
* explain it. Reading the live distribution is what avoids that.
|
|
50
|
+
*
|
|
51
|
+
* Note the resource fee cannot substitute for this. `prepareTransaction` folds
|
|
52
|
+
* a large resource fee into the total, but that buys nothing in the inclusion
|
|
53
|
+
* queue.
|
|
54
|
+
*
|
|
55
|
+
* Fee stats are read best-effort: the surrounding RPC failover has already
|
|
56
|
+
* proven this server answers, so a `getFeeStats` hiccup falls back to a bid
|
|
57
|
+
* rather than failing the approval. Both degraded paths warn, because a silent
|
|
58
|
+
* fallback re-creates the undiagnosable failure this helper exists to remove.
|
|
59
|
+
*/
|
|
60
|
+
export const resolveSorobanInclusionFee = async (
|
|
61
|
+
server: Server
|
|
62
|
+
): Promise<string> => {
|
|
63
|
+
try {
|
|
64
|
+
const feeStats = await server.getFeeStats()
|
|
65
|
+
const reported = feeStats?.sorobanInclusionFee?.[INCLUSION_FEE_PERCENTILE]
|
|
66
|
+
const percentile = Number(reported)
|
|
67
|
+
if (!Number.isFinite(percentile) || percentile <= 0) {
|
|
68
|
+
console.warn(
|
|
69
|
+
'[resolveSorobanInclusionFee] Unusable fee percentile, using fallback bid:',
|
|
70
|
+
FALLBACK_FEE,
|
|
71
|
+
reported
|
|
72
|
+
)
|
|
73
|
+
return String(FALLBACK_FEE)
|
|
74
|
+
}
|
|
75
|
+
return String(clampBid(percentile))
|
|
76
|
+
} catch (error) {
|
|
77
|
+
console.warn(
|
|
78
|
+
'[resolveSorobanInclusionFee] Fee stats unreadable, using fallback bid:',
|
|
79
|
+
FALLBACK_FEE,
|
|
80
|
+
error
|
|
81
|
+
)
|
|
82
|
+
return String(FALLBACK_FEE)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -33,7 +33,7 @@ export const submitStellarTransaction = async (
|
|
|
33
33
|
signedTxXdr: string,
|
|
34
34
|
networkPassphrase: string
|
|
35
35
|
): Promise<string> => {
|
|
36
|
-
const transaction = TransactionBuilder.
|
|
36
|
+
const transaction = TransactionBuilder.fromXdr(
|
|
37
37
|
signedTxXdr,
|
|
38
38
|
networkPassphrase
|
|
39
39
|
) as Transaction
|
|
@@ -54,7 +54,7 @@ export const submitStellarTransaction = async (
|
|
|
54
54
|
throw new TransactionError(
|
|
55
55
|
LiFiErrorCode.TransactionFailed,
|
|
56
56
|
`Stellar transaction submission failed: ${
|
|
57
|
-
response.errorResult?.result
|
|
57
|
+
response.errorResult?.result.type ?? response.status
|
|
58
58
|
}`
|
|
59
59
|
)
|
|
60
60
|
}
|
|
@@ -49,7 +49,7 @@ export const waitForStellarTransaction = async (
|
|
|
49
49
|
throw new TransactionError(
|
|
50
50
|
LiFiErrorCode.TransactionFailed,
|
|
51
51
|
`Stellar transaction ${transactionHash} failed: ${
|
|
52
|
-
response.resultXdr?.result
|
|
52
|
+
response.resultXdr?.result.type ?? 'unknown reason'
|
|
53
53
|
}`
|
|
54
54
|
)
|
|
55
55
|
}
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/sdk-provider-stellar'
|
|
2
|
-
export const version = '4.2.
|
|
2
|
+
export const version = '4.2.4'
|