@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.
- package/dist/adapters.d.ts +4889 -0
- package/dist/adapters.d.ts.map +1 -0
- package/dist/adapters.js +18 -0
- package/dist/address.d.ts +12 -0
- package/dist/address.d.ts.map +1 -0
- package/dist/address.js +19 -0
- package/dist/errors.d.ts +77 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +114 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/rebalancing.d.ts +41 -0
- package/dist/rebalancing.d.ts.map +1 -0
- package/dist/rebalancing.js +117 -0
- package/dist/router.d.ts +68 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/router.js +137 -0
- package/dist/types.d.ts +42 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/package.json +46 -0
package/dist/router.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.functionSelectorToAdapterCallMap = exports.EcoRepaymentsRelayerContext = exports.SameChainRepaymentsRelayerContext = exports.AcrossRepaymentsRelayerContext = exports.NoRelayerContext = void 0;
|
|
4
|
+
exports.decodeRouterCall = decodeRouterCall;
|
|
5
|
+
const shared_configs_1 = require("@rhinestone/shared-configs");
|
|
6
|
+
const viem_1 = require("viem");
|
|
7
|
+
const adapters_1 = require("./adapters");
|
|
8
|
+
const errors_1 = require("./errors");
|
|
9
|
+
const supportedRouteCalls = [
|
|
10
|
+
'routeClaim',
|
|
11
|
+
'routeFill',
|
|
12
|
+
'optimized_routeFill921336808',
|
|
13
|
+
];
|
|
14
|
+
/**
|
|
15
|
+
* Decodes router calldata and validates it's a supported route function.
|
|
16
|
+
*
|
|
17
|
+
* @param data - The ABI-encoded router calldata
|
|
18
|
+
* @returns Decoded function data with optimization flag
|
|
19
|
+
* @throws Error if the function is not a supported route call
|
|
20
|
+
*/
|
|
21
|
+
function decodeRouterCall(data) {
|
|
22
|
+
const routerCall = (0, viem_1.decodeFunctionData)({
|
|
23
|
+
abi: shared_configs_1.routerAbi,
|
|
24
|
+
data,
|
|
25
|
+
});
|
|
26
|
+
if (!supportedRouteCalls.includes(routerCall.functionName)) {
|
|
27
|
+
throw new errors_1.UnsupportedRouteCallError({
|
|
28
|
+
functionName: routerCall.functionName,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
const isOptimizedRouteCall = routerCall.functionName.startsWith('optimized');
|
|
32
|
+
return {
|
|
33
|
+
...routerCall,
|
|
34
|
+
isOptimizedRouteCall,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* No-op rewrite for adapters that don't need repayment context modification.
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
const NoRelayerContext = (original, _repayment) => {
|
|
42
|
+
return original;
|
|
43
|
+
};
|
|
44
|
+
exports.NoRelayerContext = NoRelayerContext;
|
|
45
|
+
const acrossRelayerContext = [
|
|
46
|
+
{
|
|
47
|
+
type: 'tuple[]',
|
|
48
|
+
components: [
|
|
49
|
+
{ name: 'repaymentChain', type: 'uint256' },
|
|
50
|
+
{ name: 'repaymentAddress', type: 'address' },
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
];
|
|
54
|
+
/**
|
|
55
|
+
* Rewrites Across adapter relayer context.
|
|
56
|
+
* Across contexts contain an array of (repaymentChain, repaymentAddress) tuples,
|
|
57
|
+
* one per deposit/origin chain.
|
|
58
|
+
*
|
|
59
|
+
* When `repayment.chain` is provided, all tuples are updated to that chain.
|
|
60
|
+
* When omitted, each tuple preserves its original repaymentChain.
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
const AcrossRepaymentsRelayerContext = (original, repayment) => {
|
|
64
|
+
const decoded = (0, viem_1.decodeAbiParameters)(acrossRelayerContext, original);
|
|
65
|
+
const contexts = decoded[0];
|
|
66
|
+
for (const context of contexts) {
|
|
67
|
+
context.repaymentAddress = repayment.address;
|
|
68
|
+
if (repayment.chain) {
|
|
69
|
+
context.repaymentChain = BigInt(repayment.chain);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return (0, viem_1.encodeAbiParameters)(acrossRelayerContext, [contexts]);
|
|
73
|
+
};
|
|
74
|
+
exports.AcrossRepaymentsRelayerContext = AcrossRepaymentsRelayerContext;
|
|
75
|
+
const sameChainRelayerContext = ['address'];
|
|
76
|
+
/**
|
|
77
|
+
* Rewrites SameChain adapter relayer context.
|
|
78
|
+
* Simply encodes the new repayment address.
|
|
79
|
+
* @internal
|
|
80
|
+
*/
|
|
81
|
+
const SameChainRepaymentsRelayerContext = (_original, repayment) => {
|
|
82
|
+
return (0, viem_1.encodePacked)(sameChainRelayerContext, [repayment.address]);
|
|
83
|
+
};
|
|
84
|
+
exports.SameChainRepaymentsRelayerContext = SameChainRepaymentsRelayerContext;
|
|
85
|
+
const ecoRelayerContext = ['address'];
|
|
86
|
+
/**
|
|
87
|
+
* Rewrites Eco adapter relayer context.
|
|
88
|
+
* Simply encodes the new repayment address (claimant).
|
|
89
|
+
* @internal
|
|
90
|
+
*/
|
|
91
|
+
const EcoRepaymentsRelayerContext = (_original, repayment) => {
|
|
92
|
+
return (0, viem_1.encodePacked)(ecoRelayerContext, [repayment.address]);
|
|
93
|
+
};
|
|
94
|
+
exports.EcoRepaymentsRelayerContext = EcoRepaymentsRelayerContext;
|
|
95
|
+
const lookup = (defaultCtx, overrides) => {
|
|
96
|
+
return (f) => {
|
|
97
|
+
const override = overrides?.[f.name];
|
|
98
|
+
if (override) {
|
|
99
|
+
return override;
|
|
100
|
+
}
|
|
101
|
+
return defaultCtx;
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
const adapterRelayerContextMap = {
|
|
105
|
+
singleCallAbi: lookup(exports.NoRelayerContext),
|
|
106
|
+
multiCallAbi: lookup(exports.NoRelayerContext, {
|
|
107
|
+
multicall_handleJITClaim: exports.SameChainRepaymentsRelayerContext,
|
|
108
|
+
multicall_handleFill: exports.SameChainRepaymentsRelayerContext,
|
|
109
|
+
}),
|
|
110
|
+
directRouteAbi: lookup(exports.NoRelayerContext),
|
|
111
|
+
sameChainAbi: lookup(exports.SameChainRepaymentsRelayerContext),
|
|
112
|
+
ecoAbi: lookup(exports.EcoRepaymentsRelayerContext),
|
|
113
|
+
acrossAbi: lookup(exports.AcrossRepaymentsRelayerContext),
|
|
114
|
+
intentExecutorAbi: lookup(exports.NoRelayerContext),
|
|
115
|
+
relayAbi: lookup(exports.NoRelayerContext),
|
|
116
|
+
};
|
|
117
|
+
function buildSelectorToAdapterCallMap() {
|
|
118
|
+
const map = {};
|
|
119
|
+
for (const key of Object.keys(adapters_1.adapters)) {
|
|
120
|
+
const lookupFn = adapterRelayerContextMap[key];
|
|
121
|
+
const abi = adapters_1.adapters[key];
|
|
122
|
+
for (const item of abi.filter((v) => v.type === 'function')) {
|
|
123
|
+
const functionSelector = (0, viem_1.toFunctionSelector)(item);
|
|
124
|
+
map[functionSelector] = {
|
|
125
|
+
functionName: item.name,
|
|
126
|
+
adapterName: key,
|
|
127
|
+
rewriteRelayerContext: lookupFn(item),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return map;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Pre-built map from 4-byte function selector to adapter call metadata.
|
|
135
|
+
* Used to look up the appropriate rewrite function for each adapter call.
|
|
136
|
+
*/
|
|
137
|
+
exports.functionSelectorToAdapterCallMap = buildSelectorToAdapterCallMap();
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Address } from 'viem';
|
|
2
|
+
declare const __brand: unique symbol;
|
|
3
|
+
/**
|
|
4
|
+
* Internal branded Ethereum address type.
|
|
5
|
+
* Lowercase-normalized and intersects with viem's Address type.
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export type EthAddress = Address & {
|
|
9
|
+
[__brand]: 'EthAddress';
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Where the relayer wants to be repaid.
|
|
13
|
+
*
|
|
14
|
+
* - `address` — the repayment recipient address.
|
|
15
|
+
* - `chain` — override the repayment chain. When omitted, each repayment
|
|
16
|
+
* entry preserves its original chain (e.g., Across tuples keep their
|
|
17
|
+
* per-deposit origin chains). Pass explicitly to redirect all repayments
|
|
18
|
+
* to a single chain.
|
|
19
|
+
*/
|
|
20
|
+
export type RepaymentDestination = {
|
|
21
|
+
address: Address;
|
|
22
|
+
chain?: number;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Contract addresses required to identify router vs intent-executor calls.
|
|
26
|
+
* When omitted from `replaceRepaymentDestinations`, defaults to production
|
|
27
|
+
* addresses from `@rhinestone/shared-configs`.
|
|
28
|
+
*/
|
|
29
|
+
export type RebalancingConfig = {
|
|
30
|
+
routerAddress: Address;
|
|
31
|
+
intentExecutorAddress: Address;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Internal version of RepaymentDestination with normalized addresses.
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
export type InternalRepaymentDestination = {
|
|
38
|
+
address: EthAddress;
|
|
39
|
+
chain?: number;
|
|
40
|
+
};
|
|
41
|
+
export {};
|
|
42
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAEnC,OAAO,CAAC,MAAM,OAAO,EAAE,OAAO,MAAM,CAAA;AAEpC;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG;IAAE,CAAC,OAAO,CAAC,EAAE,YAAY,CAAA;CAAE,CAAA;AAE9D;;;;;;;;GAQG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,aAAa,EAAE,OAAO,CAAA;IACtB,qBAAqB,EAAE,OAAO,CAAA;CAC/B,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,4BAA4B,GAAG;IACzC,OAAO,EAAE,UAAU,CAAA;IACnB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA"}
|
package/dist/types.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rhinestone/relayer-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "SDK for rewriting repayment destinations in router-encoded intent calldata",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Rhinestone",
|
|
7
|
+
"url": "https://rhinestone.dev"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"ethereum",
|
|
11
|
+
"rhinestone",
|
|
12
|
+
"relayer",
|
|
13
|
+
"intent",
|
|
14
|
+
"rebalancing"
|
|
15
|
+
],
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"main": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"import": "./dist/index.js",
|
|
23
|
+
"require": "./dist/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"homepage": "https://docs.rhinestone.dev/",
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/rhinestonewtf/relayer-sdk/issues"
|
|
32
|
+
},
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/rhinestonewtf/relayer-sdk.git"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@rhinestone/shared-configs": "1.4.74"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"viem": "^2.38.0"
|
|
45
|
+
}
|
|
46
|
+
}
|