@gibs/bridge-sdk 1.6.27 → 1.6.34

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/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # Bridge Sdk
2
+
3
+ tooling to help facilitate briding over omnibridges and apply a price to delivery
4
+
5
+ these are low level tools so they will have to be put together carefully
6
+
7
+ they are also in beta stages of development so things may simply change version to version
8
+
9
+ to make things easier, versions are synced across packages
10
+
11
+ ## install
12
+ ```sh
13
+ npm i --save @gibs/bridge-sdk
14
+ ```
15
+
16
+ ## usage
17
+
18
+ ```ts
19
+ // global import
20
+ import * as bridgeSDK from '@gibs/bridge-sdk'
21
+ // or by file
22
+ import * as abis from '@gibs/bridge-sdk/abis'
23
+ ```
@@ -0,0 +1,356 @@
1
+ /** the abi for the bridge */
2
+ export declare const inputBridge: readonly [{
3
+ readonly name: "minPerTx";
4
+ readonly type: "function";
5
+ readonly stateMutability: "view";
6
+ readonly inputs: readonly [{
7
+ readonly type: "address";
8
+ readonly name: "token";
9
+ }];
10
+ readonly outputs: readonly [{
11
+ readonly type: "uint256";
12
+ }];
13
+ }, {
14
+ readonly name: "foreignTokenAddress";
15
+ readonly type: "function";
16
+ readonly stateMutability: "view";
17
+ readonly inputs: readonly [{
18
+ readonly type: "address";
19
+ readonly name: "token";
20
+ }];
21
+ readonly outputs: readonly [{
22
+ readonly type: "address";
23
+ }];
24
+ }, {
25
+ readonly name: "homeTokenAddress";
26
+ readonly type: "function";
27
+ readonly stateMutability: "view";
28
+ readonly inputs: readonly [{
29
+ readonly type: "address";
30
+ readonly name: "token";
31
+ }];
32
+ readonly outputs: readonly [{
33
+ readonly type: "address";
34
+ }];
35
+ }, {
36
+ readonly name: "bridgedTokenAddress";
37
+ readonly type: "function";
38
+ readonly stateMutability: "view";
39
+ readonly inputs: readonly [{
40
+ readonly type: "address";
41
+ readonly name: "token";
42
+ }];
43
+ readonly outputs: readonly [{
44
+ readonly type: "address";
45
+ }];
46
+ }, {
47
+ readonly name: "nativeTokenAddress";
48
+ readonly type: "function";
49
+ readonly stateMutability: "view";
50
+ readonly inputs: readonly [{
51
+ readonly type: "address";
52
+ readonly name: "token";
53
+ }];
54
+ readonly outputs: readonly [{
55
+ readonly type: "address";
56
+ }];
57
+ }, {
58
+ readonly name: "feeManager";
59
+ readonly type: "function";
60
+ readonly stateMutability: "view";
61
+ readonly inputs: readonly [];
62
+ readonly outputs: readonly [{
63
+ readonly type: "address";
64
+ }];
65
+ }, {
66
+ readonly name: "relayTokensAndCall";
67
+ readonly type: "function";
68
+ readonly stateMutability: "nonpayable";
69
+ readonly inputs: readonly [{
70
+ readonly type: "address";
71
+ readonly name: "token";
72
+ }, {
73
+ readonly type: "address";
74
+ readonly name: "_receiver";
75
+ }, {
76
+ readonly type: "uint256";
77
+ readonly name: "_value";
78
+ }, {
79
+ readonly type: "bytes";
80
+ readonly name: "_data";
81
+ }];
82
+ readonly outputs: readonly [];
83
+ }, {
84
+ readonly name: "relayTokens";
85
+ readonly type: "function";
86
+ readonly stateMutability: "nonpayable";
87
+ readonly inputs: readonly [{
88
+ readonly type: "address";
89
+ readonly name: "token";
90
+ }, {
91
+ readonly type: "address";
92
+ readonly name: "_receiver";
93
+ }, {
94
+ readonly type: "uint256";
95
+ readonly name: "_value";
96
+ }];
97
+ readonly outputs: readonly [];
98
+ }];
99
+ export declare const inputBridgeExtraInput: readonly [{
100
+ readonly name: "relayTokensAndCall";
101
+ readonly type: "function";
102
+ readonly stateMutability: "nonpayable";
103
+ readonly inputs: readonly [{
104
+ readonly type: "address";
105
+ readonly name: "token";
106
+ }, {
107
+ readonly type: "address";
108
+ readonly name: "_receiver";
109
+ }, {
110
+ readonly type: "uint256";
111
+ readonly name: "_value";
112
+ }, {
113
+ readonly type: "bytes";
114
+ readonly name: "_data";
115
+ }, {
116
+ readonly type: "address";
117
+ readonly name: "_senderOrigin";
118
+ }];
119
+ readonly outputs: readonly [];
120
+ }, {
121
+ readonly name: "relayTokens";
122
+ readonly type: "function";
123
+ readonly stateMutability: "nonpayable";
124
+ readonly inputs: readonly [{
125
+ readonly type: "address";
126
+ readonly name: "token";
127
+ }, {
128
+ readonly type: "address";
129
+ readonly name: "_receiver";
130
+ }, {
131
+ readonly type: "uint256";
132
+ readonly name: "_value";
133
+ }, {
134
+ readonly type: "address";
135
+ readonly name: "_senderOrigin";
136
+ }];
137
+ readonly outputs: readonly [];
138
+ }];
139
+ export declare const erc677: readonly [{
140
+ readonly name: "transferAndCall";
141
+ readonly type: "function";
142
+ readonly stateMutability: "nonpayable";
143
+ readonly inputs: readonly [{
144
+ readonly type: "address";
145
+ }, {
146
+ readonly type: "uint256";
147
+ }, {
148
+ readonly type: "bytes";
149
+ }];
150
+ readonly outputs: readonly [];
151
+ }];
152
+ export declare const erc677ExtraInput: readonly [{
153
+ readonly name: "transferAndCall";
154
+ readonly type: "function";
155
+ readonly stateMutability: "nonpayable";
156
+ readonly inputs: readonly [{
157
+ readonly type: "address";
158
+ }, {
159
+ readonly type: "uint256";
160
+ }, {
161
+ readonly type: "bytes";
162
+ }, {
163
+ readonly type: "address";
164
+ readonly name: "sender";
165
+ }];
166
+ readonly outputs: readonly [];
167
+ }];
168
+ export declare const outputRouter: readonly [{
169
+ readonly name: "onTokenBridged";
170
+ readonly type: "function";
171
+ readonly stateMutability: "payable";
172
+ readonly inputs: readonly [{
173
+ readonly type: "address";
174
+ readonly name: "_token";
175
+ }, {
176
+ readonly type: "uint256";
177
+ readonly name: "_value";
178
+ }, {
179
+ readonly type: "bytes";
180
+ readonly name: "_data";
181
+ }];
182
+ readonly outputs: readonly [];
183
+ }, {
184
+ readonly name: "WETH";
185
+ readonly type: "function";
186
+ readonly stateMutability: "view";
187
+ readonly inputs: readonly [];
188
+ readonly outputs: readonly [{
189
+ readonly type: "address";
190
+ }];
191
+ }, {
192
+ readonly name: "bridge";
193
+ readonly type: "function";
194
+ readonly stateMutability: "view";
195
+ readonly inputs: readonly [];
196
+ readonly outputs: readonly [{
197
+ readonly type: "address";
198
+ }];
199
+ }];
200
+ export declare const outputBridge: readonly [{
201
+ readonly name: "bridgeContract";
202
+ readonly type: "function";
203
+ readonly stateMutability: "view";
204
+ readonly inputs: readonly [];
205
+ readonly outputs: readonly [{
206
+ readonly type: "address";
207
+ }];
208
+ }];
209
+ export declare const feeManager: readonly [{
210
+ readonly name: "HOME_TO_FOREIGN_FEE";
211
+ readonly type: "function";
212
+ readonly stateMutability: "view";
213
+ readonly inputs: readonly [];
214
+ readonly outputs: readonly [{
215
+ readonly type: "bytes32";
216
+ }];
217
+ }, {
218
+ readonly name: "FOREIGN_TO_HOME_FEE";
219
+ readonly type: "function";
220
+ readonly stateMutability: "view";
221
+ readonly inputs: readonly [];
222
+ readonly outputs: readonly [{
223
+ readonly type: "bytes32";
224
+ }];
225
+ }, {
226
+ readonly name: "getFee";
227
+ readonly type: "function";
228
+ readonly stateMutability: "view";
229
+ readonly inputs: readonly [{
230
+ readonly type: "bytes32";
231
+ }, {
232
+ readonly type: "address";
233
+ }];
234
+ readonly outputs: readonly [{
235
+ readonly type: "uint256";
236
+ }];
237
+ }];
238
+ export declare const nativeRouter: readonly [{
239
+ readonly name: "wrapAndRelayTokens";
240
+ readonly type: "function";
241
+ readonly stateMutability: "payable";
242
+ readonly inputs: readonly [{
243
+ readonly type: "address";
244
+ readonly name: "receiver";
245
+ }];
246
+ readonly outputs: readonly [];
247
+ }, {
248
+ readonly name: "relayTokensAndCall";
249
+ readonly type: "function";
250
+ readonly stateMutability: "payable";
251
+ readonly inputs: readonly [{
252
+ readonly type: "address";
253
+ readonly name: "receiver";
254
+ }, {
255
+ readonly type: "bytes";
256
+ readonly name: "data";
257
+ }];
258
+ readonly outputs: readonly [];
259
+ }];
260
+ export declare const nativeRouterExtraInput: readonly [{
261
+ readonly name: "wrapAndRelayTokens";
262
+ readonly type: "function";
263
+ readonly stateMutability: "payable";
264
+ readonly inputs: readonly [{
265
+ readonly type: "address";
266
+ readonly name: "receiver";
267
+ }, {
268
+ readonly type: "address";
269
+ readonly name: "sender";
270
+ }];
271
+ readonly outputs: readonly [];
272
+ }, {
273
+ readonly name: "relayTokensAndCall";
274
+ readonly type: "function";
275
+ readonly stateMutability: "payable";
276
+ readonly inputs: readonly [{
277
+ readonly type: "address";
278
+ readonly name: "receiver";
279
+ }, {
280
+ readonly type: "bytes";
281
+ readonly name: "data";
282
+ }, {
283
+ readonly type: "address";
284
+ readonly name: "sender";
285
+ }];
286
+ readonly outputs: readonly [];
287
+ }];
288
+ export declare const univ2Router: readonly [{
289
+ readonly name: "getAmountsOut";
290
+ readonly type: "function";
291
+ readonly stateMutability: "view";
292
+ readonly inputs: readonly [{
293
+ readonly type: "uint256";
294
+ readonly name: "amountIn";
295
+ }, {
296
+ readonly type: "address[]";
297
+ readonly name: "path";
298
+ }];
299
+ readonly outputs: readonly [{
300
+ readonly type: "uint256[]";
301
+ }];
302
+ }];
303
+ export declare const feeDeliveryStruct: readonly [{
304
+ readonly type: "tuple";
305
+ readonly components: readonly [{
306
+ readonly type: "address";
307
+ }, {
308
+ readonly type: "uint256";
309
+ }, {
310
+ readonly type: "uint256";
311
+ }, {
312
+ readonly type: "uint256";
313
+ }];
314
+ }];
315
+ export declare const relayTokensDirect: readonly [{
316
+ readonly name: "safeExecuteSignaturesWithAutoGasLimit";
317
+ readonly type: "function";
318
+ readonly stateMutability: "nonpayable";
319
+ readonly inputs: readonly [{
320
+ readonly type: "bytes";
321
+ readonly name: "data";
322
+ }, {
323
+ readonly type: "bytes";
324
+ readonly name: "signatures";
325
+ }];
326
+ readonly outputs: readonly [];
327
+ }];
328
+ export declare const homeAmb: readonly [{
329
+ readonly name: "submitSignature";
330
+ readonly type: "function";
331
+ readonly stateMutability: "nonpayable";
332
+ readonly inputs: readonly [{
333
+ readonly type: "bytes";
334
+ readonly name: "message";
335
+ }, {
336
+ readonly type: "bytes";
337
+ readonly name: "signature";
338
+ }];
339
+ readonly outputs: readonly [];
340
+ }];
341
+ export declare const pair: readonly [{
342
+ readonly name: "getReserves";
343
+ readonly type: "function";
344
+ readonly stateMutability: "view";
345
+ readonly inputs: readonly [];
346
+ readonly outputs: readonly [{
347
+ readonly type: "uint112";
348
+ readonly name: "reserve0";
349
+ }, {
350
+ readonly type: "uint112";
351
+ readonly name: "reserve1";
352
+ }, {
353
+ readonly type: "uint32";
354
+ readonly name: "blockTimestampLast";
355
+ }];
356
+ }];
@@ -0,0 +1,54 @@
1
+ import { parseAbi, parseAbiParameters } from 'viem';
2
+ /** the abi for the bridge */
3
+ export const inputBridge = parseAbi([
4
+ 'function minPerTx(address token) external view returns(uint256)',
5
+ 'function foreignTokenAddress(address token) external view returns(address)',
6
+ 'function homeTokenAddress(address token) external view returns(address)',
7
+ 'function bridgedTokenAddress(address token) external view returns(address)',
8
+ 'function nativeTokenAddress(address token) external view returns(address)',
9
+ 'function feeManager() external view returns(address)',
10
+ 'function relayTokensAndCall(address token, address _receiver, uint256 _value, bytes memory _data) external',
11
+ 'function relayTokens(address token, address _receiver, uint256 _value) external',
12
+ ]);
13
+ export const inputBridgeExtraInput = parseAbi([
14
+ 'function relayTokensAndCall(address token, address _receiver, uint256 _value, bytes memory _data, address _senderOrigin) external',
15
+ 'function relayTokens(address token, address _receiver, uint256 _value, address _senderOrigin) external',
16
+ ]);
17
+ export const erc677 = parseAbi([
18
+ 'function transferAndCall(address, uint256, bytes calldata) external',
19
+ ]);
20
+ export const erc677ExtraInput = parseAbi([
21
+ 'function transferAndCall(address, uint256, bytes calldata, address sender) external',
22
+ ]);
23
+ export const outputRouter = parseAbi([
24
+ 'function onTokenBridged(address _token, uint256 _value, bytes memory _data) external payable',
25
+ 'function WETH() external view returns(address)',
26
+ 'function bridge() external view returns(address)',
27
+ ]);
28
+ export const outputBridge = parseAbi(['function bridgeContract() external view returns(address)']);
29
+ export const feeManager = parseAbi([
30
+ 'function HOME_TO_FOREIGN_FEE() public view returns(bytes32)',
31
+ 'function FOREIGN_TO_HOME_FEE() public view returns(bytes32)',
32
+ 'function getFee(bytes32, address) public view returns(uint256)',
33
+ ]);
34
+ export const nativeRouter = parseAbi([
35
+ 'function wrapAndRelayTokens(address receiver) external payable',
36
+ 'function relayTokensAndCall(address receiver, bytes calldata data) external payable',
37
+ ]);
38
+ export const nativeRouterExtraInput = parseAbi([
39
+ 'function wrapAndRelayTokens(address receiver, address sender) external payable',
40
+ 'function relayTokensAndCall(address receiver, bytes calldata data, address sender) external payable',
41
+ ]);
42
+ export const univ2Router = parseAbi([
43
+ 'function getAmountsOut(uint256 amountIn, address[] calldata path) external view returns(uint256[] memory)',
44
+ ]);
45
+ export const feeDeliveryStruct = parseAbiParameters('(address, uint256, uint256, uint256)');
46
+ export const relayTokensDirect = parseAbi([
47
+ 'function safeExecuteSignaturesWithAutoGasLimit(bytes calldata data, bytes calldata signatures) external',
48
+ ]);
49
+ export const homeAmb = parseAbi([
50
+ 'function submitSignature(bytes message, bytes signature) external',
51
+ ]);
52
+ export const pair = parseAbi([
53
+ 'function getReserves() view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast)',
54
+ ]);
@@ -0,0 +1,78 @@
1
+ import { type Hex, type PublicClient } from "viem";
2
+ import { Chains, type Pathway } from "./config.js";
3
+ import type { BridgeKey, Token } from "./types.js";
4
+ import _ from "lodash";
5
+ export type TokenBridgeInfo = {
6
+ originationChainId: Chains;
7
+ assetInAddress: Hex;
8
+ assetOutAddress: Hex | null;
9
+ toForeign?: {
10
+ home: Hex;
11
+ foreign: Hex | null;
12
+ };
13
+ toHome?: {
14
+ home: Hex | null;
15
+ foreign: Hex;
16
+ };
17
+ };
18
+ export declare const links: (({ chainId, target, address, client }: {
19
+ chainId: number;
20
+ target: Hex;
21
+ address: Hex;
22
+ client: PublicClient;
23
+ }) => Promise<`0x${string}`[]>) & _.MemoizedFunction;
24
+ export declare const tokenBridgeInfo: ({ bridgeKey, assetIn, isProd, fromChainClient, toChainClient, }: {
25
+ bridgeKey: BridgeKey;
26
+ assetIn: Token | null;
27
+ isProd: boolean;
28
+ fromChainClient: PublicClient;
29
+ toChainClient: PublicClient;
30
+ }) => Promise<null | TokenBridgeInfo>;
31
+ export type FetchResult = bigint[] | Hex;
32
+ export declare const fetchPriceCorrective: ({ bridgeKeyPartner, assetOut, measurementToken, fromChainClient, toChainClient, assetLink, amountIn, isProd, }: {
33
+ bridgeKey: BridgeKey;
34
+ bridgeKeyPartner: BridgeKey;
35
+ measurementToken: Hex;
36
+ assetOut: Token;
37
+ fromChainClient: PublicClient;
38
+ toChainClient: PublicClient;
39
+ assetLink: TokenBridgeInfo;
40
+ amountIn: bigint;
41
+ isProd: boolean;
42
+ }) => {
43
+ getPaymentToken: () => Promise<TokenBridgeInfo | null>;
44
+ getSwapResults: ({ paymentTokenResult, chain, uniV2Router, client, }: {
45
+ paymentTokenResult: TokenBridgeInfo;
46
+ chain: Chains;
47
+ client: PublicClient;
48
+ uniV2Router?: Hex;
49
+ }) => Promise<[FetchResult[], FetchResult[]]>;
50
+ reduceResults: ({ results, oneToken, }: {
51
+ results: [FetchResult[], ...[FetchResult[]]];
52
+ oneToken: bigint;
53
+ }) => bigint;
54
+ };
55
+ export declare const minBridgeAmountIn: ({ assetIn, pathway, fromPublicClient, toPublicClient, }: {
56
+ assetIn: Token;
57
+ pathway: Pathway;
58
+ fromPublicClient: PublicClient;
59
+ toPublicClient: PublicClient;
60
+ }) => Promise<bigint>;
61
+ /** get the symbol of the native asset, unwrap it if it needs to be */
62
+ export declare const nativeSymbol: (asset: {
63
+ address: Hex;
64
+ symbol: string;
65
+ chainId: number;
66
+ } | null, unwrap?: boolean) => string;
67
+ export type InputLoadFeeFor = {
68
+ pathway: Pathway;
69
+ fromChainClient: PublicClient;
70
+ toChainClient: PublicClient;
71
+ };
72
+ export type PathwayExtendableConfig = {
73
+ feeManager: Hex;
74
+ feeH2F: bigint;
75
+ feeF2H: bigint;
76
+ };
77
+ export declare const chainMulticall: (client: PublicClient) => any;
78
+ export declare const loadBridgeFees: ({ pathway, fromChainClient, toChainClient }: InputLoadFeeFor) => Promise<PathwayExtendableConfig>;