@rhinestone/relayer-sdk 0.1.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapters.d.ts","sourceRoot":"","sources":["../adapters.ts"],"names":[],"mappings":"AAWA;;;GAGG;AACH,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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Property(exports, "__esModule", { value: true });
3
+ exports.adapters = void 0;
4
+ const shared_configs_1 = require("@rhinestone/shared-configs");
5
+ /**
6
+ * Collection of adapter ABIs used by the router.
7
+ * Each adapter handles a specific settlement layer or execution pattern.
8
+ */
9
+ exports.adapters = {
10
+ singleCallAbi: shared_configs_1.singleCallAbi,
11
+ multiCallAbi: shared_configs_1.multiCallAbi,
12
+ directRouteAbi: shared_configs_1.directRouteAbi,
13
+ ecoAbi: shared_configs_1.ecoAdapterAbi,
14
+ sameChainAbi: shared_configs_1.sameChainAdapterAbi,
15
+ acrossAbi: shared_configs_1.acrossAdapterAbi,
16
+ intentExecutorAbi: shared_configs_1.intentExecutorAdapterAbi,
17
+ relayAbi: shared_configs_1.relayAdapterAbi,
18
+ };
@@ -0,0 +1,12 @@
1
+ import { type Address } from 'viem';
2
+ import type { EthAddress } from './types';
3
+ /**
4
+ * Validates and normalizes an address string to an EthAddress.
5
+ * Lowercases the address for consistent comparison.
6
+ *
7
+ * @param value - The address string to parse
8
+ * @returns The normalized EthAddress
9
+ * @throws Error if the address is invalid
10
+ */
11
+ export declare function parseAddress(value: Address | string): EthAddress;
12
+ //# sourceMappingURL=address.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAa,MAAM,MAAM,CAAA;AAE9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEzC;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,UAAU,CAKhE"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseAddress = parseAddress;
4
+ const viem_1 = require("viem");
5
+ const errors_1 = require("./errors");
6
+ /**
7
+ * Validates and normalizes an address string to an EthAddress.
8
+ * Lowercases the address for consistent comparison.
9
+ *
10
+ * @param value - The address string to parse
11
+ * @returns The normalized EthAddress
12
+ * @throws Error if the address is invalid
13
+ */
14
+ function parseAddress(value) {
15
+ if (!(0, viem_1.isAddress)(value, { strict: false })) {
16
+ throw new errors_1.InvalidAddressError({ value });
17
+ }
18
+ return value.toLowerCase();
19
+ }
@@ -0,0 +1,77 @@
1
+ import type { Hex } from 'viem';
2
+ /**
3
+ * Base error class for all relayer SDK errors.
4
+ * Provides structured error information with context for debugging.
5
+ */
6
+ export declare class RelayerError extends Error {
7
+ private readonly _message;
8
+ private readonly _context;
9
+ private readonly _errorType;
10
+ constructor(params: {
11
+ message: string;
12
+ context?: Record<string, unknown>;
13
+ errorType?: string;
14
+ });
15
+ get message(): string;
16
+ get context(): Record<string, unknown>;
17
+ get errorType(): string;
18
+ }
19
+ /**
20
+ * Error thrown when an unknown adapter function selector is encountered.
21
+ */
22
+ export declare class UnsupportedAdapterError extends RelayerError {
23
+ constructor(params: {
24
+ selector: Hex;
25
+ index: number;
26
+ functionName: string;
27
+ });
28
+ }
29
+ /**
30
+ * Error thrown when the number of relayer contexts doesn't match
31
+ * the number of adapter calls that require them.
32
+ */
33
+ export declare class ContextMismatchError extends RelayerError {
34
+ constructor(params: {
35
+ expected: number;
36
+ actual: number;
37
+ adapterCalls: Array<{
38
+ name: string;
39
+ expectsContext: boolean;
40
+ }>;
41
+ });
42
+ }
43
+ /**
44
+ * Error thrown when an unsupported router function is called.
45
+ */
46
+ export declare class UnsupportedRouteCallError extends RelayerError {
47
+ constructor(params: {
48
+ functionName: string;
49
+ });
50
+ }
51
+ /**
52
+ * Error thrown when the target address is not a recognized
53
+ * router or intent executor address.
54
+ */
55
+ export declare class UnsupportedDestinationError extends RelayerError {
56
+ constructor(params: {
57
+ address: string;
58
+ });
59
+ }
60
+ /**
61
+ * Error thrown when an invalid Ethereum address is provided.
62
+ */
63
+ export declare class InvalidAddressError extends RelayerError {
64
+ constructor(params: {
65
+ value: string;
66
+ });
67
+ }
68
+ /**
69
+ * Type guard to check if an error is a RelayerError.
70
+ */
71
+ export declare function isRelayerError(err: unknown): err is RelayerError;
72
+ /**
73
+ * Type guard to check if an error is a validation error
74
+ * (InvalidAddressError or ContextMismatchError).
75
+ */
76
+ export declare function isValidationError(err: unknown): boolean;
77
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,MAAM,CAAA;AAE/B;;;GAGG;AACH,qBAAa,YAAa,SAAQ,KAAK;IACrC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAQ;IACjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAyB;IAClD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAQ;gBAEvB,MAAM,EAAE;QAClB,OAAO,EAAE,MAAM,CAAA;QACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QACjC,SAAS,CAAC,EAAE,MAAM,CAAA;KACnB;IAQD,IAAa,OAAO,IAAI,MAAM,CAE7B;IAED,IAAI,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAErC;IAED,IAAI,SAAS,IAAI,MAAM,CAEtB;CACF;AAED;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,YAAY;gBAC3C,MAAM,EAAE;QAClB,QAAQ,EAAE,GAAG,CAAA;QACb,KAAK,EAAE,MAAM,CAAA;QACb,YAAY,EAAE,MAAM,CAAA;KACrB;CAOF;AAED;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,YAAY;gBACxC,MAAM,EAAE;QAClB,QAAQ,EAAE,MAAM,CAAA;QAChB,MAAM,EAAE,MAAM,CAAA;QACd,YAAY,EAAE,KAAK,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,cAAc,EAAE,OAAO,CAAA;SAAE,CAAC,CAAA;KAC/D;CAWF;AAED;;GAEG;AACH,qBAAa,yBAA0B,SAAQ,YAAY;gBAC7C,MAAM,EAAE;QAAE,YAAY,EAAE,MAAM,CAAA;KAAE;CAO7C;AAED;;;GAGG;AACH,qBAAa,2BAA4B,SAAQ,YAAY;gBAC/C,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE;CAOxC;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,YAAY;gBACvC,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE;CAOtC;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,YAAY,CAEhE;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAIvD"}
package/dist/errors.js ADDED
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InvalidAddressError = exports.UnsupportedDestinationError = exports.UnsupportedRouteCallError = exports.ContextMismatchError = exports.UnsupportedAdapterError = exports.RelayerError = void 0;
4
+ exports.isRelayerError = isRelayerError;
5
+ exports.isValidationError = isValidationError;
6
+ /**
7
+ * Base error class for all relayer SDK errors.
8
+ * Provides structured error information with context for debugging.
9
+ */
10
+ class RelayerError extends Error {
11
+ _message;
12
+ _context;
13
+ _errorType;
14
+ constructor(params) {
15
+ super(params.message);
16
+ this._message = params.message;
17
+ this._context = params.context ?? {};
18
+ this._errorType = params.errorType ?? 'RelayerError';
19
+ this.name = this._errorType;
20
+ }
21
+ get message() {
22
+ return this._message;
23
+ }
24
+ get context() {
25
+ return this._context;
26
+ }
27
+ get errorType() {
28
+ return this._errorType;
29
+ }
30
+ }
31
+ exports.RelayerError = RelayerError;
32
+ /**
33
+ * Error thrown when an unknown adapter function selector is encountered.
34
+ */
35
+ class UnsupportedAdapterError extends RelayerError {
36
+ constructor(params) {
37
+ super({
38
+ message: `Unknown adapter call at index ${params.index}, selector: ${params.selector} for ${params.functionName}`,
39
+ context: params,
40
+ errorType: 'UnsupportedAdapterError',
41
+ });
42
+ }
43
+ }
44
+ exports.UnsupportedAdapterError = UnsupportedAdapterError;
45
+ /**
46
+ * Error thrown when the number of relayer contexts doesn't match
47
+ * the number of adapter calls that require them.
48
+ */
49
+ class ContextMismatchError extends RelayerError {
50
+ constructor(params) {
51
+ const message = params.expected > params.actual
52
+ ? `Mismatch: Expected ${params.expected} relayer contexts but only ${params.actual} were provided`
53
+ : `Mismatch: More contexts were provided (${params.actual}) than were consumed (${params.expected}) by the adapter calls`;
54
+ super({
55
+ message,
56
+ context: params,
57
+ errorType: 'ContextMismatchError',
58
+ });
59
+ }
60
+ }
61
+ exports.ContextMismatchError = ContextMismatchError;
62
+ /**
63
+ * Error thrown when an unsupported router function is called.
64
+ */
65
+ class UnsupportedRouteCallError extends RelayerError {
66
+ constructor(params) {
67
+ super({
68
+ message: `Unsupported route function call: ${params.functionName}`,
69
+ context: params,
70
+ errorType: 'UnsupportedRouteCallError',
71
+ });
72
+ }
73
+ }
74
+ exports.UnsupportedRouteCallError = UnsupportedRouteCallError;
75
+ /**
76
+ * Error thrown when the target address is not a recognized
77
+ * router or intent executor address.
78
+ */
79
+ class UnsupportedDestinationError extends RelayerError {
80
+ constructor(params) {
81
+ super({
82
+ message: `Unsupported destination address: ${params.address}`,
83
+ context: params,
84
+ errorType: 'UnsupportedDestinationError',
85
+ });
86
+ }
87
+ }
88
+ exports.UnsupportedDestinationError = UnsupportedDestinationError;
89
+ /**
90
+ * Error thrown when an invalid Ethereum address is provided.
91
+ */
92
+ class InvalidAddressError extends RelayerError {
93
+ constructor(params) {
94
+ super({
95
+ message: `Invalid Ethereum address: ${params.value}`,
96
+ context: params,
97
+ errorType: 'InvalidAddressError',
98
+ });
99
+ }
100
+ }
101
+ exports.InvalidAddressError = InvalidAddressError;
102
+ /**
103
+ * Type guard to check if an error is a RelayerError.
104
+ */
105
+ function isRelayerError(err) {
106
+ return err instanceof RelayerError;
107
+ }
108
+ /**
109
+ * Type guard to check if an error is a validation error
110
+ * (InvalidAddressError or ContextMismatchError).
111
+ */
112
+ function isValidationError(err) {
113
+ return (err instanceof InvalidAddressError || err instanceof ContextMismatchError);
114
+ }
@@ -0,0 +1,7 @@
1
+ export { adapters } from './adapters';
2
+ export { ContextMismatchError, InvalidAddressError, isRelayerError, isValidationError, RelayerError, UnsupportedAdapterError, UnsupportedDestinationError, UnsupportedRouteCallError, } from './errors';
3
+ export { replaceRepaymentDestinations } from './rebalancing';
4
+ export type { AdapterCall, DecodeRouterCallReturnType, RelayerContextRewrite, } from './router';
5
+ export { AcrossRepaymentsRelayerContext, decodeRouterCall, EcoRepaymentsRelayerContext, functionSelectorToAdapterCallMap, NoRelayerContext, SameChainRepaymentsRelayerContext, } from './router';
6
+ export type { RebalancingConfig, RepaymentDestination } from './types';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAErC,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,uBAAuB,EACvB,2BAA2B,EAC3B,yBAAyB,GAC1B,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAA;AAC5D,YAAY,EACV,WAAW,EACX,0BAA0B,EAC1B,qBAAqB,GACtB,MAAM,UAAU,CAAA;AAEjB,OAAO,EACL,8BAA8B,EAC9B,gBAAgB,EAChB,2BAA2B,EAC3B,gCAAgC,EAChC,gBAAgB,EAChB,iCAAiC,GAClC,MAAM,UAAU,CAAA;AAEjB,YAAY,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SameChainRepaymentsRelayerContext = exports.NoRelayerContext = exports.functionSelectorToAdapterCallMap = exports.EcoRepaymentsRelayerContext = exports.decodeRouterCall = exports.AcrossRepaymentsRelayerContext = exports.replaceRepaymentDestinations = exports.UnsupportedRouteCallError = exports.UnsupportedDestinationError = exports.UnsupportedAdapterError = exports.RelayerError = exports.isValidationError = exports.isRelayerError = exports.InvalidAddressError = exports.ContextMismatchError = exports.adapters = void 0;
4
+ // Adapters
5
+ // biome-ignore lint/performance/noBarrelFile: Package entry point requires re-exports
6
+ var adapters_1 = require("./adapters");
7
+ Object.defineProperty(exports, "adapters", { enumerable: true, get: function () { return adapters_1.adapters; } });
8
+ // Errors
9
+ var errors_1 = require("./errors");
10
+ Object.defineProperty(exports, "ContextMismatchError", { enumerable: true, get: function () { return errors_1.ContextMismatchError; } });
11
+ Object.defineProperty(exports, "InvalidAddressError", { enumerable: true, get: function () { return errors_1.InvalidAddressError; } });
12
+ Object.defineProperty(exports, "isRelayerError", { enumerable: true, get: function () { return errors_1.isRelayerError; } });
13
+ Object.defineProperty(exports, "isValidationError", { enumerable: true, get: function () { return errors_1.isValidationError; } });
14
+ Object.defineProperty(exports, "RelayerError", { enumerable: true, get: function () { return errors_1.RelayerError; } });
15
+ Object.defineProperty(exports, "UnsupportedAdapterError", { enumerable: true, get: function () { return errors_1.UnsupportedAdapterError; } });
16
+ Object.defineProperty(exports, "UnsupportedDestinationError", { enumerable: true, get: function () { return errors_1.UnsupportedDestinationError; } });
17
+ Object.defineProperty(exports, "UnsupportedRouteCallError", { enumerable: true, get: function () { return errors_1.UnsupportedRouteCallError; } });
18
+ var rebalancing_1 = require("./rebalancing");
19
+ Object.defineProperty(exports, "replaceRepaymentDestinations", { enumerable: true, get: function () { return rebalancing_1.replaceRepaymentDestinations; } });
20
+ // Lower-level building blocks
21
+ var router_1 = require("./router");
22
+ Object.defineProperty(exports, "AcrossRepaymentsRelayerContext", { enumerable: true, get: function () { return router_1.AcrossRepaymentsRelayerContext; } });
23
+ Object.defineProperty(exports, "decodeRouterCall", { enumerable: true, get: function () { return router_1.decodeRouterCall; } });
24
+ Object.defineProperty(exports, "EcoRepaymentsRelayerContext", { enumerable: true, get: function () { return router_1.EcoRepaymentsRelayerContext; } });
25
+ Object.defineProperty(exports, "functionSelectorToAdapterCallMap", { enumerable: true, get: function () { return router_1.functionSelectorToAdapterCallMap; } });
26
+ Object.defineProperty(exports, "NoRelayerContext", { enumerable: true, get: function () { return router_1.NoRelayerContext; } });
27
+ Object.defineProperty(exports, "SameChainRepaymentsRelayerContext", { enumerable: true, get: function () { return router_1.SameChainRepaymentsRelayerContext; } });
@@ -0,0 +1,41 @@
1
+ import { type Address, type Hex } from 'viem';
2
+ import type { RebalancingConfig, RepaymentDestination } from './types';
3
+ /**
4
+ * Rewrites repayment destinations inside router-encoded intent calldata.
5
+ *
6
+ * Decodes the router call, walks each adapter call in the route, and replaces
7
+ * the relayer context (repayment address / chain) for every adapter that
8
+ * carries one (Across, SameChain, Eco).
9
+ *
10
+ * @param to - Target contract address of the call
11
+ * @param data - ABI-encoded calldata (routeFill / routeClaim / optimized variant)
12
+ * @param destination - The repayment destination to write into each relayer context.
13
+ * Omit `chain` to preserve per-deposit origin chains (recommended for Across).
14
+ * @param config - Optional override for router / intent-executor addresses.
15
+ * Defaults to production addresses from `@rhinestone/shared-configs`.
16
+ * @returns The calldata with rewritten repayment destinations
17
+ * @throws Error if the target address is not recognized or adapter call is unknown
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * // Simple usage with defaults
22
+ * const rewritten = replaceRepaymentDestinations(
23
+ * routerAddress,
24
+ * originalCalldata,
25
+ * { address: '0x...' },
26
+ * )
27
+ *
28
+ * // With custom config (e.g., dev deployment)
29
+ * const rewritten = replaceRepaymentDestinations(
30
+ * routerAddress,
31
+ * originalCalldata,
32
+ * { address: '0x...' },
33
+ * {
34
+ * routerAddress: '0x...',
35
+ * intentExecutorAddress: '0x...',
36
+ * },
37
+ * )
38
+ * ```
39
+ */
40
+ export declare function replaceRepaymentDestinations(to: Address, data: Hex, destination: RepaymentDestination, config?: RebalancingConfig): Hex;
41
+ //# sourceMappingURL=rebalancing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rebalancing.d.ts","sourceRoot":"","sources":["../rebalancing.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,OAAO,EAGZ,KAAK,GAAG,EAET,MAAM,MAAM,CAAA;AAYb,OAAO,KAAK,EAEV,iBAAiB,EACjB,oBAAoB,EACrB,MAAM,SAAS,CAAA;AAOhB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,4BAA4B,CAC1C,EAAE,EAAE,OAAO,EACX,IAAI,EAAE,GAAG,EACT,WAAW,EAAE,oBAAoB,EACjC,MAAM,CAAC,EAAE,iBAAiB,GACzB,GAAG,CA0FL"}
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.replaceRepaymentDestinations = replaceRepaymentDestinations;
4
+ const shared_configs_1 = require("@rhinestone/shared-configs");
5
+ const viem_1 = require("viem");
6
+ const address_1 = require("./address");
7
+ const errors_1 = require("./errors");
8
+ const router_1 = require("./router");
9
+ const DEFAULT_ROUTER_ADDRESS = (0, address_1.parseAddress)(shared_configs_1.contractAddresses['*'].router);
10
+ const DEFAULT_INTENT_EXECUTOR_ADDRESS = (0, address_1.parseAddress)(shared_configs_1.contractAddresses['*'].intentExecutor);
11
+ /**
12
+ * Rewrites repayment destinations inside router-encoded intent calldata.
13
+ *
14
+ * Decodes the router call, walks each adapter call in the route, and replaces
15
+ * the relayer context (repayment address / chain) for every adapter that
16
+ * carries one (Across, SameChain, Eco).
17
+ *
18
+ * @param to - Target contract address of the call
19
+ * @param data - ABI-encoded calldata (routeFill / routeClaim / optimized variant)
20
+ * @param destination - The repayment destination to write into each relayer context.
21
+ * Omit `chain` to preserve per-deposit origin chains (recommended for Across).
22
+ * @param config - Optional override for router / intent-executor addresses.
23
+ * Defaults to production addresses from `@rhinestone/shared-configs`.
24
+ * @returns The calldata with rewritten repayment destinations
25
+ * @throws Error if the target address is not recognized or adapter call is unknown
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * // Simple usage with defaults
30
+ * const rewritten = replaceRepaymentDestinations(
31
+ * routerAddress,
32
+ * originalCalldata,
33
+ * { address: '0x...' },
34
+ * )
35
+ *
36
+ * // With custom config (e.g., dev deployment)
37
+ * const rewritten = replaceRepaymentDestinations(
38
+ * routerAddress,
39
+ * originalCalldata,
40
+ * { address: '0x...' },
41
+ * {
42
+ * routerAddress: '0x...',
43
+ * intentExecutorAddress: '0x...',
44
+ * },
45
+ * )
46
+ * ```
47
+ */
48
+ function replaceRepaymentDestinations(to, data, destination, config) {
49
+ // Normalize addresses internally
50
+ const normalizedTo = (0, address_1.parseAddress)(to);
51
+ const routerAddress = config?.routerAddress
52
+ ? (0, address_1.parseAddress)(config.routerAddress)
53
+ : DEFAULT_ROUTER_ADDRESS;
54
+ const intentExecutorAddress = config?.intentExecutorAddress
55
+ ? (0, address_1.parseAddress)(config.intentExecutorAddress)
56
+ : DEFAULT_INTENT_EXECUTOR_ADDRESS;
57
+ const normalizedDestination = {
58
+ address: (0, address_1.parseAddress)(destination.address),
59
+ chain: destination.chain,
60
+ };
61
+ if (normalizedTo === intentExecutorAddress) {
62
+ // Intent executor calls don't need repayment context modification
63
+ return data;
64
+ }
65
+ if (normalizedTo === routerAddress) {
66
+ const { functionName: routerFunctionName, args: routerCallArgs, isOptimizedRouteCall, } = (0, router_1.decodeRouterCall)(data);
67
+ let contextIndex = 0;
68
+ const relayerContextData = routerCallArgs[0];
69
+ const adaptersCallData = !isOptimizedRouteCall
70
+ ? routerCallArgs[1]
71
+ : (0, viem_1.decodeAbiParameters)([{ type: 'bytes[]', name: 'adapterContexts' }], routerCallArgs[1])[0];
72
+ // Track adapter calls for better error diagnostics
73
+ const adapterCalls = [];
74
+ for (let i = 0; i < adaptersCallData.length; i++) {
75
+ const adapterCallBytes = adaptersCallData[i];
76
+ const selector = (0, viem_1.sliceHex)(adapterCallBytes, 0, 4);
77
+ const adapterCall = router_1.functionSelectorToAdapterCallMap[selector];
78
+ if (!adapterCall) {
79
+ throw new errors_1.UnsupportedAdapterError({
80
+ selector,
81
+ index: i,
82
+ functionName: routerFunctionName,
83
+ });
84
+ }
85
+ adapterCalls.push({
86
+ name: `${adapterCall.adapterName}:${adapterCall.functionName}`,
87
+ expectsContext: adapterCall.rewriteRelayerContext !== router_1.NoRelayerContext,
88
+ });
89
+ const rewriteF = adapterCall.rewriteRelayerContext;
90
+ if (rewriteF !== router_1.NoRelayerContext) {
91
+ if (contextIndex >= relayerContextData.length) {
92
+ throw new errors_1.ContextMismatchError({
93
+ expected: contextIndex + 1,
94
+ actual: relayerContextData.length,
95
+ adapterCalls,
96
+ });
97
+ }
98
+ const currentContext = relayerContextData[contextIndex];
99
+ relayerContextData[contextIndex] = rewriteF(currentContext, normalizedDestination);
100
+ contextIndex++;
101
+ }
102
+ }
103
+ if (contextIndex !== relayerContextData.length) {
104
+ throw new errors_1.ContextMismatchError({
105
+ expected: contextIndex,
106
+ actual: relayerContextData.length,
107
+ adapterCalls,
108
+ });
109
+ }
110
+ return (0, viem_1.encodeFunctionData)({
111
+ functionName: routerFunctionName,
112
+ args: routerCallArgs,
113
+ abi: shared_configs_1.routerAbi,
114
+ });
115
+ }
116
+ throw new errors_1.UnsupportedDestinationError({ address: to });
117
+ }
@@ -0,0 +1,68 @@
1
+ import { routerAbi } from '@rhinestone/shared-configs';
2
+ import type { DecodeFunctionDataReturnType, Hex } from 'viem';
3
+ import type { InternalRepaymentDestination } from './types';
4
+ /**
5
+ * Return type for decodeRouterCall, extends viem's decoded function data
6
+ * with metadata about whether this is an optimized route call.
7
+ */
8
+ export type DecodeRouterCallReturnType = DecodeFunctionDataReturnType<typeof routerAbi> & {
9
+ isOptimizedRouteCall: boolean;
10
+ };
11
+ /**
12
+ * Decodes router calldata and validates it's a supported route function.
13
+ *
14
+ * @param data - The ABI-encoded router calldata
15
+ * @returns Decoded function data with optimization flag
16
+ * @throws Error if the function is not a supported route call
17
+ */
18
+ export declare function decodeRouterCall(data: Hex): DecodeRouterCallReturnType;
19
+ /**
20
+ * Function signature for adapter-specific relayer context rewrite functions.
21
+ * Takes the original encoded context and a repayment destination,
22
+ * returns the rewritten encoded context.
23
+ * @internal
24
+ */
25
+ export type RelayerContextRewrite = (original: Hex, repayment: InternalRepaymentDestination) => Hex;
26
+ /**
27
+ * Metadata for a single adapter function, resolved from its 4-byte selector.
28
+ */
29
+ export type AdapterCall = {
30
+ functionName: string;
31
+ adapterName: string;
32
+ rewriteRelayerContext: RelayerContextRewrite;
33
+ };
34
+ /**
35
+ * No-op rewrite for adapters that don't need repayment context modification.
36
+ * @internal
37
+ */
38
+ export declare const NoRelayerContext: RelayerContextRewrite;
39
+ /**
40
+ * Rewrites Across adapter relayer context.
41
+ * Across contexts contain an array of (repaymentChain, repaymentAddress) tuples,
42
+ * one per deposit/origin chain.
43
+ *
44
+ * When `repayment.chain` is provided, all tuples are updated to that chain.
45
+ * When omitted, each tuple preserves its original repaymentChain.
46
+ * @internal
47
+ */
48
+ export declare const AcrossRepaymentsRelayerContext: RelayerContextRewrite;
49
+ /**
50
+ * Rewrites SameChain adapter relayer context.
51
+ * Simply encodes the new repayment address.
52
+ * @internal
53
+ */
54
+ export declare const SameChainRepaymentsRelayerContext: RelayerContextRewrite;
55
+ /**
56
+ * Rewrites Eco adapter relayer context.
57
+ * Simply encodes the new repayment address (claimant).
58
+ * @internal
59
+ */
60
+ export declare const EcoRepaymentsRelayerContext: RelayerContextRewrite;
61
+ /**
62
+ * Pre-built map from 4-byte function selector to adapter call metadata.
63
+ * Used to look up the appropriate rewrite function for each adapter call.
64
+ */
65
+ export declare const functionSelectorToAdapterCallMap: Readonly<{
66
+ [key: Hex]: AdapterCall;
67
+ }>;
68
+ //# sourceMappingURL=router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AACtD,OAAO,KAAK,EAAe,4BAA4B,EAAE,GAAG,EAAE,MAAM,MAAM,CAAA;AAU1E,OAAO,KAAK,EAAc,4BAA4B,EAAE,MAAM,SAAS,CAAA;AAQvE;;;GAGG;AACH,MAAM,MAAM,0BAA0B,GAAG,4BAA4B,CACnE,OAAO,SAAS,CACjB,GAAG;IACF,oBAAoB,EAAE,OAAO,CAAA;CAC9B,CAAA;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,GAAG,GAAG,0BAA0B,CAetE;AAED;;;;;GAKG;AACH,MAAM,MAAM,qBAAqB,GAAG,CAClC,QAAQ,EAAE,GAAG,EACb,SAAS,EAAE,4BAA4B,KACpC,GAAG,CAAA;AAER;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,YAAY,EAAE,MAAM,CAAA;IACpB,WAAW,EAAE,MAAM,CAAA;IACnB,qBAAqB,EAAE,qBAAqB,CAAA;CAC7C,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,qBAK9B,CAAA;AAYD;;;;;;;;GAQG;AACH,eAAO,MAAM,8BAA8B,EAAE,qBAkB5C,CAAA;AAID;;;;GAIG;AACH,eAAO,MAAM,iCAAiC,EAAE,qBAK/C,CAAA;AAID;;;;GAIG;AACH,eAAO,MAAM,2BAA2B,EAAE,qBAKzC,CAAA;AAqDD;;;GAGG;AACH,eAAO,MAAM,gCAAgC,EAAE,QAAQ,CAAC;IACtD,CAAC,GAAG,EAAE,GAAG,GAAG,WAAW,CAAA;CACxB,CAAmC,CAAA"}