@lifi/sdk-provider-stellar 4.2.3 → 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 +6 -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 +13 -3
- package/dist/esm/core/tasks/helpers/buildApproveTransaction.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/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/package.json +1 -1
- package/src/core/tasks/helpers/buildApproveTransaction.ts +9 -3
- package/src/core/tasks/helpers/resolveInclusionFee.ts +84 -0
- package/src/version.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
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
|
+
|
|
3
9
|
## 4.2.3
|
|
4
10
|
|
|
5
11
|
### 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,11 +17,20 @@ 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
36
|
return (await server.prepareTransaction(transaction)).toXdr();
|
|
@@ -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"}
|
|
@@ -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"}
|
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,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(
|
|
@@ -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
|
+
}
|
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'
|