@openzeppelin/relayer-plugin-channels 0.3.1 → 0.5.0

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.
@@ -2,9 +2,13 @@
2
2
  /**
3
3
  * management.ts
4
4
  *
5
- * Payload-based management API for channel relayerIds.
5
+ * Payload-based management API for channel relayerIds and fee limits.
6
6
  * - listChannelAccounts: returns relayerIds from KV
7
7
  * - setChannelAccounts: replaces relayerIds array in KV (checks lock conflicts)
8
+ * - getFeeUsage: returns fee consumption for an API key
9
+ * - getFeeLimit: returns custom limit for an API key (if set)
10
+ * - setFeeLimit: sets custom limit for an API key
11
+ * - deleteFeeLimit: removes custom limit for an API key
8
12
  */
9
13
  Object.defineProperty(exports, "__esModule", { value: true });
10
14
  exports.isManagementRequest = isManagementRequest;
@@ -12,16 +16,7 @@ exports.handleManagement = handleManagement;
12
16
  const relayer_sdk_1 = require("@openzeppelin/relayer-sdk");
13
17
  const config_1 = require("./config");
14
18
  const constants_1 = require("./constants");
15
- function timingSafeEqual(a, b) {
16
- // Basic constant-time comparison without crypto dep
17
- if (a.length !== b.length)
18
- return false;
19
- let result = 0;
20
- for (let i = 0; i < a.length; i++) {
21
- result |= a.charCodeAt(i) ^ b.charCodeAt(i);
22
- }
23
- return result === 0;
24
- }
19
+ const fee_tracking_1 = require("./fee-tracking");
25
20
  function isManagementRequest(params) {
26
21
  return Boolean(params &&
27
22
  typeof params === "object" &&
@@ -30,8 +25,8 @@ function isManagementRequest(params) {
30
25
  }
31
26
  async function handleManagement(context) {
32
27
  const { kv, params } = context;
33
- const adminSecretEnv = (0, config_1.getAdminSecret)();
34
- if (!adminSecretEnv) {
28
+ const config = (0, config_1.loadConfig)();
29
+ if (!config.adminSecret) {
35
30
  throw (0, relayer_sdk_1.pluginError)("Management API disabled", {
36
31
  code: "MANAGEMENT_DISABLED",
37
32
  status: constants_1.HTTP_STATUS.FORBIDDEN,
@@ -39,20 +34,26 @@ async function handleManagement(context) {
39
34
  }
40
35
  const m = params?.management || {};
41
36
  const provided = (m.adminSecret ?? "").toString();
42
- if (!provided || !timingSafeEqual(provided, adminSecretEnv)) {
37
+ if (!provided || provided !== config.adminSecret) {
43
38
  throw (0, relayer_sdk_1.pluginError)("Unauthorized", {
44
39
  code: "UNAUTHORIZED",
45
40
  status: constants_1.HTTP_STATUS.UNAUTHORIZED,
46
41
  });
47
42
  }
48
43
  const action = String(m.action || "");
49
- // Load config (requires env like STELLAR_NETWORK) after auth
50
- const cfg = (0, config_1.loadConfig)();
51
44
  switch (action) {
52
45
  case "listChannelAccounts":
53
- return await listChannelAccounts(kv, cfg.network);
46
+ return await listChannelAccounts(kv, config.network);
54
47
  case "setChannelAccounts":
55
- return await setChannelAccounts(kv, cfg.network, m);
48
+ return await setChannelAccounts(kv, config.network, m);
49
+ case "getFeeUsage":
50
+ return await getFeeUsage(kv, config.network, config.feeLimit, config.feeResetPeriodMs, m);
51
+ case "getFeeLimit":
52
+ return await getFeeLimit(kv, config.network, config.feeLimit, m);
53
+ case "setFeeLimit":
54
+ return await setFeeLimit(kv, config.network, m);
55
+ case "deleteFeeLimit":
56
+ return await deleteFeeLimit(kv, config.network, m);
56
57
  default:
57
58
  throw (0, relayer_sdk_1.pluginError)("Invalid management action", {
58
59
  code: "INVALID_ACTION",
@@ -76,6 +77,100 @@ async function listChannelAccounts(kv, network) {
76
77
  });
77
78
  }
78
79
  }
80
+ async function getFeeUsage(kv, network, defaultLimit, resetPeriodMs, payload) {
81
+ const apiKey = payload?.apiKey;
82
+ if (!apiKey || typeof apiKey !== "string") {
83
+ throw (0, relayer_sdk_1.pluginError)("Invalid payload: apiKey is required", {
84
+ code: "INVALID_PAYLOAD",
85
+ status: constants_1.HTTP_STATUS.BAD_REQUEST,
86
+ });
87
+ }
88
+ try {
89
+ const tracker = new fee_tracking_1.FeeTracker({
90
+ kv,
91
+ network,
92
+ apiKey,
93
+ defaultLimit,
94
+ resetPeriodMs,
95
+ });
96
+ return await tracker.getUsageInfo();
97
+ }
98
+ catch (e) {
99
+ throw (0, relayer_sdk_1.pluginError)("KV error while reading fee usage", {
100
+ code: "KV_ERROR",
101
+ status: constants_1.HTTP_STATUS.INTERNAL_SERVER_ERROR,
102
+ });
103
+ }
104
+ }
105
+ async function getFeeLimit(kv, network, defaultLimit, payload) {
106
+ const apiKey = payload?.apiKey;
107
+ if (!apiKey || typeof apiKey !== "string") {
108
+ throw (0, relayer_sdk_1.pluginError)("Invalid payload: apiKey is required", {
109
+ code: "INVALID_PAYLOAD",
110
+ status: constants_1.HTTP_STATUS.BAD_REQUEST,
111
+ });
112
+ }
113
+ try {
114
+ const tracker = new fee_tracking_1.FeeTracker({ kv, network, apiKey, defaultLimit });
115
+ const customLimit = await tracker.getCustomLimit();
116
+ return {
117
+ limit: customLimit ?? defaultLimit,
118
+ };
119
+ }
120
+ catch (e) {
121
+ throw (0, relayer_sdk_1.pluginError)("KV error while reading fee limit", {
122
+ code: "KV_ERROR",
123
+ status: constants_1.HTTP_STATUS.INTERNAL_SERVER_ERROR,
124
+ });
125
+ }
126
+ }
127
+ async function setFeeLimit(kv, network, payload) {
128
+ const apiKey = payload?.apiKey;
129
+ const limit = payload?.limit;
130
+ if (!apiKey || typeof apiKey !== "string") {
131
+ throw (0, relayer_sdk_1.pluginError)("Invalid payload: apiKey is required", {
132
+ code: "INVALID_PAYLOAD",
133
+ status: constants_1.HTTP_STATUS.BAD_REQUEST,
134
+ });
135
+ }
136
+ if (typeof limit !== "number" || !Number.isFinite(limit) || limit < 0) {
137
+ throw (0, relayer_sdk_1.pluginError)("Invalid payload: limit must be a non-negative number", {
138
+ code: "INVALID_PAYLOAD",
139
+ status: constants_1.HTTP_STATUS.BAD_REQUEST,
140
+ });
141
+ }
142
+ try {
143
+ const tracker = new fee_tracking_1.FeeTracker({ kv, network, apiKey });
144
+ await tracker.setCustomLimit(Math.floor(limit));
145
+ return { ok: true, limit: Math.floor(limit) };
146
+ }
147
+ catch (e) {
148
+ throw (0, relayer_sdk_1.pluginError)("KV error while setting fee limit", {
149
+ code: "KV_ERROR",
150
+ status: constants_1.HTTP_STATUS.INTERNAL_SERVER_ERROR,
151
+ });
152
+ }
153
+ }
154
+ async function deleteFeeLimit(kv, network, payload) {
155
+ const apiKey = payload?.apiKey;
156
+ if (!apiKey || typeof apiKey !== "string") {
157
+ throw (0, relayer_sdk_1.pluginError)("Invalid payload: apiKey is required", {
158
+ code: "INVALID_PAYLOAD",
159
+ status: constants_1.HTTP_STATUS.BAD_REQUEST,
160
+ });
161
+ }
162
+ try {
163
+ const tracker = new fee_tracking_1.FeeTracker({ kv, network, apiKey });
164
+ await tracker.deleteCustomLimit();
165
+ return { ok: true };
166
+ }
167
+ catch (e) {
168
+ throw (0, relayer_sdk_1.pluginError)("KV error while deleting fee limit", {
169
+ code: "KV_ERROR",
170
+ status: constants_1.HTTP_STATUS.INTERNAL_SERVER_ERROR,
171
+ });
172
+ }
173
+ }
79
174
  async function setChannelAccounts(kv, network, payload) {
80
175
  const incoming = payload?.relayerIds;
81
176
  if (!Array.isArray(incoming)) {
@@ -17,7 +17,7 @@ export declare class ChannelPool {
17
17
  private readonly channelLockTtlSec;
18
18
  private readonly mutexTtlSec;
19
19
  private readonly kv;
20
- constructor(network: "testnet" | "mainnet", kv: PluginKVStore);
20
+ constructor(network: "testnet" | "mainnet", kv: PluginKVStore, lockTtlSeconds: number);
21
21
  /** Acquire a relayerId with a token lock */
22
22
  acquire(): Promise<PoolLock>;
23
23
  private withGlobalMutex;
@@ -1 +1 @@
1
- {"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../../src/plugin/pool.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,aAAa,EAAe,MAAM,2BAA2B,CAAC;AAKvE,MAAM,MAAM,QAAQ,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAI5D,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAwB;IAChD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IACvC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAS;IAC3C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAgB;gBAEvB,OAAO,EAAE,SAAS,GAAG,SAAS,EAAE,EAAE,EAAE,aAAa;IAQ7D,4CAA4C;IACtC,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC;YAuBpB,eAAe;YASf,iBAAiB;IAwB/B,oCAAoC;IAC9B,OAAO,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAY5C,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,OAAO;YAID,mBAAmB;CAWlC"}
1
+ {"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../../src/plugin/pool.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,aAAa,EAAe,MAAM,2BAA2B,CAAC;AAIvE,MAAM,MAAM,QAAQ,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAI5D,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAwB;IAChD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IACvC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAS;IAC3C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAgB;gBAGjC,OAAO,EAAE,SAAS,GAAG,SAAS,EAC9B,EAAE,EAAE,aAAa,EACjB,cAAc,EAAE,MAAM;IASxB,4CAA4C;IACtC,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC;YAuBpB,eAAe;YAQf,iBAAiB;IAwB/B,oCAAoC;IAC9B,OAAO,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAY5C,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,OAAO;YAID,mBAAmB;CAWlC"}
@@ -14,14 +14,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.ChannelPool = void 0;
15
15
  const relayer_sdk_1 = require("@openzeppelin/relayer-sdk");
16
16
  const crypto_1 = __importDefault(require("crypto"));
17
- const config_1 = require("./config");
18
17
  const constants_1 = require("./constants");
19
18
  class ChannelPool {
20
- constructor(network, kv) {
19
+ constructor(network, kv, lockTtlSeconds) {
21
20
  this.network = network;
22
21
  this.kv = kv;
23
22
  this.globalLockKey = `${this.network}:channel-pool-lock`;
24
- this.channelLockTtlSec = (0, config_1.getLockTtlSeconds)();
23
+ this.channelLockTtlSec = lockTtlSeconds;
25
24
  this.mutexTtlSec = constants_1.POOL.MUTEX_TTL_SECONDS;
26
25
  }
27
26
  /** Acquire a relayerId with a token lock */
@@ -45,11 +44,10 @@ class ChannelPool {
45
44
  }
46
45
  // Run a function under the short-lived global mutex; returns null if busy
47
46
  async withGlobalMutex(fn) {
48
- const r = (await this.kv.withLock(this.globalLockKey, fn, {
47
+ return this.kv.withLock(this.globalLockKey, fn, {
49
48
  ttlSec: this.mutexTtlSec,
50
49
  onBusy: "skip",
51
- }));
52
- return r;
50
+ });
53
51
  }
54
52
  // Inside the mutex: pick an available relayer and set its channel lock
55
53
  async tryLockAnyRelayer() {
@@ -5,10 +5,11 @@
5
5
  * and the fund account as the operation source. Returns an unsigned inner
6
6
  * transaction with sorobanData and correct fee set to the resource fee.
7
7
  */
8
- import { SorobanRpc, Transaction, xdr } from "@stellar/stellar-sdk";
8
+ import { Transaction, xdr } from "@stellar/stellar-sdk";
9
+ import { Relayer } from "@openzeppelin/relayer-sdk";
9
10
  export interface ChannelAccount {
10
11
  address: string;
11
12
  sequence: string;
12
13
  }
13
- export declare function simulateAndBuildWithChannel(func: xdr.HostFunction, auth: xdr.SorobanAuthorizationEntry[] | undefined, channel: ChannelAccount, _fundAddress: string, rpc: SorobanRpc.Server, networkPassphrase: string): Promise<Transaction>;
14
+ export declare function simulateAndBuildWithChannel(func: xdr.HostFunction, auth: xdr.SorobanAuthorizationEntry[] | undefined, channel: ChannelAccount, _fundAddress: string, relayer: Relayer, networkPassphrase: string): Promise<Transaction>;
14
15
  //# sourceMappingURL=simulation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"simulation.d.ts","sourceRoot":"","sources":["../../src/plugin/simulation.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAGL,UAAU,EACV,WAAW,EAEX,GAAG,EACJ,MAAM,sBAAsB,CAAC;AAI9B,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,wBAAsB,2BAA2B,CAC/C,IAAI,EAAE,GAAG,CAAC,YAAY,EACtB,IAAI,EAAE,GAAG,CAAC,yBAAyB,EAAE,GAAG,SAAS,EACjD,OAAO,EAAE,cAAc,EACvB,YAAY,EAAE,MAAM,EACpB,GAAG,EAAE,UAAU,CAAC,MAAM,EACtB,iBAAiB,EAAE,MAAM,GACxB,OAAO,CAAC,WAAW,CAAC,CA8CtB"}
1
+ {"version":3,"file":"simulation.d.ts","sourceRoot":"","sources":["../../src/plugin/simulation.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAIL,WAAW,EAEX,GAAG,EACJ,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAGL,OAAO,EACR,MAAM,2BAA2B,CAAC;AAGnC,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,wBAAsB,2BAA2B,CAC/C,IAAI,EAAE,GAAG,CAAC,YAAY,EACtB,IAAI,EAAE,GAAG,CAAC,yBAAyB,EAAE,GAAG,SAAS,EACjD,OAAO,EAAE,cAAc,EACvB,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,OAAO,EAChB,iBAAiB,EAAE,MAAM,GACxB,OAAO,CAAC,WAAW,CAAC,CA8FtB"}
@@ -11,7 +11,7 @@ exports.simulateAndBuildWithChannel = simulateAndBuildWithChannel;
11
11
  const stellar_sdk_1 = require("@stellar/stellar-sdk");
12
12
  const relayer_sdk_1 = require("@openzeppelin/relayer-sdk");
13
13
  const constants_1 = require("./constants");
14
- async function simulateAndBuildWithChannel(func, auth, channel, _fundAddress, rpc, networkPassphrase) {
14
+ async function simulateAndBuildWithChannel(func, auth, channel, _fundAddress, relayer, networkPassphrase) {
15
15
  const now = Math.floor(Date.now() / 1000);
16
16
  console.debug(`[channels] Building tx: channel=${channel.address}, seq=${channel.sequence}, auth_count=${auth?.length ?? 0}`);
17
17
  // Build inner transaction (source = channel, op source = fund)
@@ -29,9 +29,49 @@ async function simulateAndBuildWithChannel(func, auth, channel, _fundAddress, rp
29
29
  // No explicit source: default to transaction source (channel account)
30
30
  }))
31
31
  .build();
32
- // Prepare transaction (attaches sorobanData/resources, preserves provided auth)
32
+ let rpcResponse;
33
33
  try {
34
- const prepared = await rpc.prepareTransaction(transaction);
34
+ rpcResponse = await relayer.rpc({
35
+ jsonrpc: "2.0",
36
+ id: Math.floor(Math.random() * 1e8).toString(),
37
+ method: "simulateTransaction",
38
+ params: {
39
+ transaction: transaction.toXDR(),
40
+ },
41
+ });
42
+ }
43
+ catch (err) {
44
+ throw (0, relayer_sdk_1.pluginError)("Simulation network request failed", {
45
+ code: "SIMULATION_NETWORK_ERROR",
46
+ status: constants_1.HTTP_STATUS.BAD_GATEWAY,
47
+ details: {
48
+ message: err instanceof Error ? err.message : String(err),
49
+ },
50
+ });
51
+ }
52
+ if (rpcResponse.error) {
53
+ const { code, message, description, data } = rpcResponse.error;
54
+ throw (0, relayer_sdk_1.pluginError)("Simulation RPC execution failed", {
55
+ code: "SIMULATION_RPC_FAILURE",
56
+ status: constants_1.HTTP_STATUS.BAD_REQUEST,
57
+ details: {
58
+ rpcCode: code,
59
+ message,
60
+ description: description || data,
61
+ },
62
+ });
63
+ }
64
+ try {
65
+ // Format simulation result for SDK's assembleTransaction
66
+ const simResult = {
67
+ id: String(rpcResponse.id ?? "1"),
68
+ ...rpcResponse.result,
69
+ };
70
+ console.debug(`[channels] Simulation result:`, JSON.stringify(simResult, null, 2));
71
+ // Use SDK's assembleTransaction to apply simulation results
72
+ const prepared = stellar_sdk_1.rpc
73
+ .assembleTransaction(transaction, simResult)
74
+ .build();
35
75
  const resourceFee = prepared
36
76
  .toEnvelope()
37
77
  .v1()
@@ -42,11 +82,13 @@ async function simulateAndBuildWithChannel(func, auth, channel, _fundAddress, rp
42
82
  console.debug(`[channels] Simulation complete: resourceFee=${resourceFee}`);
43
83
  return prepared;
44
84
  }
45
- catch (e) {
46
- throw (0, relayer_sdk_1.pluginError)("Simulation failed", {
85
+ catch (err) {
86
+ throw (0, relayer_sdk_1.pluginError)("Simulation result processing failed", {
47
87
  code: "SIMULATION_FAILED",
48
- status: constants_1.HTTP_STATUS.BAD_REQUEST,
49
- details: { error: e instanceof Error ? e.message : String(e) },
88
+ status: constants_1.HTTP_STATUS.INTERNAL_SERVER_ERROR,
89
+ details: {
90
+ message: err instanceof Error ? err.message : String(err),
91
+ },
50
92
  });
51
93
  }
52
94
  }
@@ -6,6 +6,7 @@
6
6
  import { Transaction } from "@stellar/stellar-sdk";
7
7
  import { Relayer, PluginAPI } from "@openzeppelin/relayer-sdk";
8
8
  import { ChannelAccountsResponse } from "./types";
9
+ import { FeeTracker } from "./fee-tracking";
9
10
  /**
10
11
  * Sign transaction with both channel and fund relayers
11
12
  * - First sign with channel account
@@ -16,5 +17,5 @@ export declare function signWithChannelAndFund(transaction: Transaction, channel
16
17
  /**
17
18
  * Submit transaction with fee bump and wait for confirmation
18
19
  */
19
- export declare function submitWithFeeBumpAndWait(fundRelayer: Relayer, signedXdr: string, network: "testnet" | "mainnet", maxFee: number, api: PluginAPI): Promise<ChannelAccountsResponse>;
20
+ export declare function submitWithFeeBumpAndWait(fundRelayer: Relayer, signedXdr: string, network: "testnet" | "mainnet", maxFee: number, api: PluginAPI, tracker?: FeeTracker): Promise<ChannelAccountsResponse>;
20
21
  //# sourceMappingURL=submit.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"submit.d.ts","sourceRoot":"","sources":["../../src/plugin/submit.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAEL,OAAO,EAGP,SAAS,EACV,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAElD;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAC1C,WAAW,EAAE,WAAW,EACxB,cAAc,EAAE,OAAO,EACvB,YAAY,EAAE,OAAO,EACrB,cAAc,EAAE,MAAM,EACtB,YAAY,EAAE,MAAM,EACpB,iBAAiB,EAAE,MAAM,GACxB,OAAO,CAAC,WAAW,CAAC,CA2BtB;AAED;;GAEG;AACH,wBAAsB,wBAAwB,CAC5C,WAAW,EAAE,OAAO,EACpB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,SAAS,GAAG,SAAS,EAC9B,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,SAAS,GACb,OAAO,CAAC,uBAAuB,CAAC,CAwDlC"}
1
+ {"version":3,"file":"submit.d.ts","sourceRoot":"","sources":["../../src/plugin/submit.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAEL,OAAO,EAGP,SAAS,EACV,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAC1C,WAAW,EAAE,WAAW,EACxB,cAAc,EAAE,OAAO,EACvB,YAAY,EAAE,OAAO,EACrB,cAAc,EAAE,MAAM,EACtB,YAAY,EAAE,MAAM,EACpB,iBAAiB,EAAE,MAAM,GACxB,OAAO,CAAC,WAAW,CAAC,CA2BtB;AAED;;GAEG;AACH,wBAAsB,wBAAwB,CAC5C,WAAW,EAAE,OAAO,EACpB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,SAAS,GAAG,SAAS,EAC9B,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,SAAS,EACd,OAAO,CAAC,EAAE,UAAU,GACnB,OAAO,CAAC,uBAAuB,CAAC,CAiElC"}
@@ -39,7 +39,7 @@ async function signWithChannelAndFund(transaction, channelRelayer, _fundRelayer,
39
39
  /**
40
40
  * Submit transaction with fee bump and wait for confirmation
41
41
  */
42
- async function submitWithFeeBumpAndWait(fundRelayer, signedXdr, network, maxFee, api) {
42
+ async function submitWithFeeBumpAndWait(fundRelayer, signedXdr, network, maxFee, api, tracker) {
43
43
  // Submit with fee bump
44
44
  console.debug(`[channels] Sending fee bump tx: network=${network}, maxFee=${maxFee}, xdr_len=${signedXdr.length}`);
45
45
  const payload = {
@@ -58,6 +58,10 @@ async function submitWithFeeBumpAndWait(fundRelayer, signedXdr, network, maxFee,
58
58
  }));
59
59
  // Check if transaction actually succeeded
60
60
  if (final.status === "failed") {
61
+ // Record fee on on-chain failure (transaction was still submitted and consumed fees)
62
+ if (tracker) {
63
+ await tracker.recordUsage(maxFee);
64
+ }
61
65
  throw (0, relayer_sdk_1.pluginError)(final.status_reason || "Transaction failed", {
62
66
  code: "ONCHAIN_FAILED",
63
67
  status: constants_1.HTTP_STATUS.BAD_REQUEST,
@@ -69,6 +73,10 @@ async function submitWithFeeBumpAndWait(fundRelayer, signedXdr, network, maxFee,
69
73
  },
70
74
  });
71
75
  }
76
+ // Record fee on success
77
+ if (tracker) {
78
+ await tracker.recordUsage(maxFee);
79
+ }
72
80
  return {
73
81
  transactionId: final.id,
74
82
  status: final.status,
@@ -80,7 +88,7 @@ async function submitWithFeeBumpAndWait(fundRelayer, signedXdr, network, maxFee,
80
88
  if (error.code === "ONCHAIN_FAILED") {
81
89
  throw error;
82
90
  }
83
- // Otherwise, it's a timeout
91
+ // Otherwise, it's a timeout - don't track fees (status unknown)
84
92
  throw (0, relayer_sdk_1.pluginError)("Transaction wait timeout. It may still submit.", {
85
93
  code: "WAIT_TIMEOUT",
86
94
  status: constants_1.HTTP_STATUS.GATEWAY_TIMEOUT,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openzeppelin/relayer-plugin-channels",
3
- "version": "0.3.1",
3
+ "version": "0.5.0",
4
4
  "description": "OpenZeppelin Relayer Plugin for Stellar Channel Accounts",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -19,23 +19,23 @@
19
19
  "author": "OpenZeppelin <contact@openzeppelin.com>",
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
- "@openzeppelin/relayer-sdk": "^1.7.0",
23
- "@stellar/stellar-sdk": "^11.2.0",
24
22
  "@actions/exec": "^1.1.1",
25
- "axios": "^1.6.0"
23
+ "@openzeppelin/relayer-sdk": "^1.8.0",
24
+ "@stellar/stellar-sdk": "^14.4.0",
25
+ "axios": "^1.13.2"
26
26
  },
27
27
  "devDependencies": {
28
- "@changesets/cli": "^2.27.7",
29
- "@types/node": "^22.13.14",
30
- "@typescript-eslint/eslint-plugin": "^8.38.0",
31
- "@typescript-eslint/parser": "^8.38.0",
32
- "eslint": "^9.22.0",
33
- "eslint-config-prettier": "^9.0.0",
34
- "eslint-plugin-prettier": "^5.0.0",
35
- "prettier": "^3.0.0",
28
+ "@changesets/cli": "^2.29.8",
29
+ "@types/node": "^22.19.1",
30
+ "@typescript-eslint/eslint-plugin": "^8.48.1",
31
+ "@typescript-eslint/parser": "^8.48.1",
32
+ "eslint": "^9.39.1",
33
+ "eslint-config-prettier": "^9.1.2",
34
+ "eslint-plugin-prettier": "^5.5.4",
35
+ "prettier": "^3.7.4",
36
36
  "typescript": "5.8.3",
37
37
  "typescript-eslint": "8.27.0",
38
- "vitest": "^4.0.4"
38
+ "vitest": "^4.0.15"
39
39
  },
40
40
  "engines": {
41
41
  "node": ">=22.18.0",