@gibs/bridge-sdk 1.12.0 → 1.13.1
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/LICENSE +15 -0
- package/README.md +234 -432
- package/dist/abis.d.ts +1 -0
- package/dist/bridge-limits.d.ts +103 -0
- package/dist/bridge-limits.js +84 -0
- package/dist/chain-info.d.ts +169 -0
- package/dist/chain-info.js +410 -0
- package/dist/chain-names.d.ts +160 -0
- package/dist/chain-names.js +200 -0
- package/dist/chains.d.ts +65 -0
- package/dist/chains.js +284 -0
- package/dist/config.d.ts +216 -0
- package/dist/config.js +493 -0
- package/dist/consolidated-quote.d.ts +554 -0
- package/dist/consolidated-quote.js +773 -0
- package/dist/destination-calldata.d.ts +118 -0
- package/dist/destination-calldata.js +152 -0
- package/dist/ecosystems.d.ts +217 -0
- package/dist/ecosystems.js +288 -0
- package/dist/fee-type.d.ts +10 -0
- package/dist/fee-type.js +9 -0
- package/dist/hyperliquid-execution.d.ts +152 -0
- package/dist/hyperliquid-execution.js +168 -0
- package/dist/image-links.d.ts +117 -0
- package/dist/image-links.js +142 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +20 -0
- package/dist/lifi-execution-guard.d.ts +199 -0
- package/dist/lifi-execution-guard.js +400 -0
- package/dist/near-intents-conformance.d.ts +85 -0
- package/dist/near-intents-conformance.js +329 -0
- package/dist/near-intents-route.d.ts +47 -0
- package/dist/near-intents-route.js +265 -0
- package/dist/near-intents.d.ts +524 -0
- package/dist/near-intents.js +1055 -0
- package/dist/origin-deposit.d.ts +326 -0
- package/dist/origin-deposit.js +68 -0
- package/dist/pre-quote.d.ts +198 -0
- package/dist/pre-quote.js +175 -0
- package/dist/prices.d.ts +107 -0
- package/dist/prices.js +162 -0
- package/dist/providers.d.ts +221 -0
- package/dist/providers.js +157 -0
- package/dist/quote-fees.d.ts +102 -0
- package/dist/quote-fees.js +195 -0
- package/dist/referral.d.ts +77 -0
- package/dist/referral.js +72 -0
- package/dist/relay-currencies.d.ts +47 -0
- package/dist/relay-currencies.js +89 -0
- package/dist/relay-quote.d.ts +301 -0
- package/dist/relay-quote.js +983 -0
- package/dist/route-steps.d.ts +138 -0
- package/dist/route-steps.js +305 -0
- package/dist/routing/amounts.d.ts +80 -0
- package/dist/routing/amounts.js +120 -0
- package/dist/routing/candidate-route.d.ts +43 -0
- package/dist/routing/candidate-route.js +45 -0
- package/dist/routing/candidate.d.ts +237 -0
- package/dist/routing/candidate.js +96 -0
- package/dist/routing/carriers/ask-answer.d.ts +60 -0
- package/dist/routing/carriers/ask-answer.js +1 -0
- package/dist/routing/carriers/omnibridge.d.ts +137 -0
- package/dist/routing/carriers/omnibridge.js +419 -0
- package/dist/routing/carriers/pulsex.d.ts +149 -0
- package/dist/routing/carriers/pulsex.js +453 -0
- package/dist/routing/carriers/wrap.d.ts +25 -0
- package/dist/routing/carriers/wrap.js +115 -0
- package/dist/routing/composed-route-quality.d.ts +103 -0
- package/dist/routing/composed-route-quality.js +108 -0
- package/dist/routing/entry-chain-anchor.d.ts +88 -0
- package/dist/routing/entry-chain-anchor.js +55 -0
- package/dist/routing/format.d.ts +31 -0
- package/dist/routing/format.js +58 -0
- package/dist/routing/index.d.ts +34 -0
- package/dist/routing/index.js +42 -0
- package/dist/routing/producers.d.ts +770 -0
- package/dist/routing/producers.js +1564 -0
- package/dist/routing/providers.d.ts +26 -0
- package/dist/routing/providers.js +38 -0
- package/dist/routing/route-data.d.ts +355 -0
- package/dist/routing/route-data.js +1 -0
- package/dist/routing/search/compose.d.ts +168 -0
- package/dist/routing/search/compose.js +98 -0
- package/dist/routing/search/graph.d.ts +653 -0
- package/dist/routing/search/graph.js +445 -0
- package/dist/routing/search/plan-route-data.d.ts +244 -0
- package/dist/routing/search/plan-route-data.js +767 -0
- package/dist/routing/search/score.d.ts +353 -0
- package/dist/routing/search/score.js +427 -0
- package/dist/routing/usd-value.d.ts +17 -0
- package/dist/routing/usd-value.js +25 -0
- package/dist/settings.d.ts +692 -0
- package/dist/settings.js +909 -0
- package/dist/ton-execution.d.ts +117 -0
- package/dist/ton-execution.js +247 -0
- package/dist/tron-execution.d.ts +146 -0
- package/dist/tron-execution.js +239 -0
- package/dist/types.d.ts +51 -0
- package/dist/types.js +1 -0
- package/llms.txt +169 -0
- package/package.json +204 -23
- package/src/chain-info.test.ts +0 -968
- package/src/chain-info.ts +0 -498
- package/src/chains.test.ts +0 -123
- package/src/chains.ts +0 -88
- package/src/config.test.ts +0 -679
- package/src/config.ts +0 -500
- package/src/fee-type.test.ts +0 -45
- package/src/fee-type.ts +0 -14
- package/src/image-links.test.ts +0 -160
- package/src/image-links.ts +0 -65
- package/src/index.ts +0 -8
- package/src/settings.test.ts +0 -2754
- package/src/settings.ts +0 -875
- package/src/types.ts +0 -48
- package/tsconfig.json +0 -17
- package/vitest.config.ts +0 -13
- /package/{src/abis.ts → dist/abis.js} +0 -0
package/src/config.ts
DELETED
|
@@ -1,500 +0,0 @@
|
|
|
1
|
-
import _ from 'lodash';
|
|
2
|
-
import { getAddress, type Hex, keccak256, stringToHex, zeroAddress } from 'viem';
|
|
3
|
-
import type { BridgeKey, Token, TokenOut } from './types.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Add here your chain id as hex, be sure to add your chain in the chainsMetadata object too
|
|
7
|
-
*/
|
|
8
|
-
export enum Chains {
|
|
9
|
-
PLS = '0x171',
|
|
10
|
-
ETH = '0x1',
|
|
11
|
-
BNB = '0x38',
|
|
12
|
-
// testnets
|
|
13
|
-
SEP = '0xaa36a7',
|
|
14
|
-
V4PLS = '0x3af',
|
|
15
|
-
// TBNB = '0x61',
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/** The key of a chain - human readable for query params */
|
|
19
|
-
export type ChainKey = keyof typeof Chains;
|
|
20
|
-
|
|
21
|
-
/** A map of chain ids to chain keys */
|
|
22
|
-
export const chainIdToKey = new Map<Chains, ChainKey>(
|
|
23
|
-
Object.entries(Chains).map(([key, chain]) => [chain, key] as [Chains, ChainKey]),
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Converts a chain id to a chain key
|
|
28
|
-
* @param chainId - the chain id
|
|
29
|
-
* @returns the chain key
|
|
30
|
-
*/
|
|
31
|
-
export const toChain = (chainId: number | string) => `0x${Number(chainId).toString(16)}` as Chains;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Converts a chain id to a chain key
|
|
35
|
-
* @param chainId - the chain id
|
|
36
|
-
* @returns the chain key
|
|
37
|
-
*/
|
|
38
|
-
export const toChainKey = (chainId: number | string) => chainIdToKey.get(toChain(chainId));
|
|
39
|
-
|
|
40
|
-
// /** The provider of an omnibridge */
|
|
41
|
-
// export enum Provider {
|
|
42
|
-
// PULSECHAIN = 'pulsechain',
|
|
43
|
-
// TOKENSEX = 'tokensex',
|
|
44
|
-
// }
|
|
45
|
-
|
|
46
|
-
export const Providers = {
|
|
47
|
-
PULSECHAIN: 'pulsechain',
|
|
48
|
-
TOKENSEX: 'tokensex',
|
|
49
|
-
} as const;
|
|
50
|
-
|
|
51
|
-
export type Provider = (typeof Providers)[keyof typeof Providers];
|
|
52
|
-
|
|
53
|
-
/** A map of chains to native asset out addresses */
|
|
54
|
-
export const nativeAssetOut = {
|
|
55
|
-
[Chains.ETH]: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
|
|
56
|
-
[Chains.BNB]: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c',
|
|
57
|
-
[Chains.PLS]: '0xA1077a294dDE1B09bB078844df40758a5D0f9a27',
|
|
58
|
-
[Chains.SEP]: '0x7b79995e5f793A07Bc00c21412e50Ecae098E7f9',
|
|
59
|
-
[Chains.V4PLS]: '0x70499adEBB11Efd915E3b69E700c331778628707',
|
|
60
|
-
} as Record<Chains, Hex>;
|
|
61
|
-
|
|
62
|
-
/** A map of chains to deprecated native asset out addresses */
|
|
63
|
-
export const deprecatedNativeAssetOut = {
|
|
64
|
-
[Chains.PLS]: new Set(['0x97Ac4a2439A47c07ad535bb1188c989dae755341']),
|
|
65
|
-
} as Partial<Record<Chains, Set<Hex>>>;
|
|
66
|
-
|
|
67
|
-
/** A map of chains to uni v2 router addresses */
|
|
68
|
-
export const uniV2Routers = {
|
|
69
|
-
[Chains.PLS]: [
|
|
70
|
-
'0x98bf93ebf5c380C0e6Ae8e192A7e2AE08edAcc02',
|
|
71
|
-
'0x165C3410fC91EF562C50559f7d2289fEbed552d9',
|
|
72
|
-
],
|
|
73
|
-
[Chains.ETH]: ['0x7a250d5630b4cf539739df2c5dacb4c659f2488d'],
|
|
74
|
-
[Chains.BNB]: ['0x05fF2B0DB69458A0750badebc4f9e13aDd608C7F'],
|
|
75
|
-
[Chains.SEP]: ['0xeE567Fe1712Faf6149d80dA1E6934E354124CfE3'],
|
|
76
|
-
[Chains.V4PLS]: [
|
|
77
|
-
'0xDaE9dd3d1A52CfCe9d5F2fAC7fDe164D500E50f7',
|
|
78
|
-
'0x636f6407B90661b73b1C0F7e24F4C79f624d0738',
|
|
79
|
-
],
|
|
80
|
-
} as Record<Chains, Hex[]>;
|
|
81
|
-
|
|
82
|
-
/** A map of chains to native token symbols */
|
|
83
|
-
export const nativeTokenSymbol = {
|
|
84
|
-
[Chains.PLS]: 'PLS',
|
|
85
|
-
[Chains.V4PLS]: 'V4PLS',
|
|
86
|
-
[Chains.ETH]: 'ETH',
|
|
87
|
-
[Chains.SEP]: 'sepETH',
|
|
88
|
-
[Chains.BNB]: 'BNB',
|
|
89
|
-
} as Record<Chains, string>;
|
|
90
|
-
|
|
91
|
-
/** A map of chains to native token names */
|
|
92
|
-
export const nativeTokenName = {
|
|
93
|
-
[Chains.PLS]: 'Pulse',
|
|
94
|
-
[Chains.V4PLS]: 'V4 Pulse',
|
|
95
|
-
[Chains.ETH]: 'Ether',
|
|
96
|
-
[Chains.SEP]: 'Sepolia Ether',
|
|
97
|
-
[Chains.BNB]: 'BNB',
|
|
98
|
-
} as Record<Chains, string>;
|
|
99
|
-
|
|
100
|
-
/** The pathway of a bridge */
|
|
101
|
-
export type Pathway = {
|
|
102
|
-
from: Hex;
|
|
103
|
-
to: Hex;
|
|
104
|
-
destinationRouter: Hex | null;
|
|
105
|
-
nativeRouter: Hex;
|
|
106
|
-
validator: Hex;
|
|
107
|
-
// defaultAssetIn: Token
|
|
108
|
-
usesExtraParam: boolean;
|
|
109
|
-
feeManager: 'from' | 'to';
|
|
110
|
-
toHome: boolean;
|
|
111
|
-
requiresDelivery: boolean;
|
|
112
|
-
bridgedNativeAssetOut: Hex;
|
|
113
|
-
settingOverrides?: Record<Hex, Partial<Pathway>>;
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
/** A map of providers to pathways */
|
|
117
|
-
export type DeepPathwayConfig = Record<
|
|
118
|
-
Provider,
|
|
119
|
-
Partial<Record<Chains, Partial<Record<Chains, Pathway>>>>
|
|
120
|
-
>;
|
|
121
|
-
|
|
122
|
-
/** The settings for the pulsechain pls eth pathway */
|
|
123
|
-
const pulsechainPLSETHSettings = {
|
|
124
|
-
from: '0x0e18d0d556b652794EF12Bf68B2dC857EF5f3996',
|
|
125
|
-
to: '0xe20E337DB2a00b1C37139c873B92a0AAd3F468bF',
|
|
126
|
-
destinationRouter: '0x1F0144Ce3BDaf11944Fe0beF6444599a0500695B',
|
|
127
|
-
nativeRouter: '0xE66877Cfe4CEc10ffBbBB3092B7001321AB5809D',
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
export const pathways = {
|
|
131
|
-
[Providers.PULSECHAIN]: {
|
|
132
|
-
[Chains.PLS]: {
|
|
133
|
-
[Chains.ETH]: {
|
|
134
|
-
from: '0x4fD0aaa7506f3d9cB8274bdB946Ec42A1b8751Ef',
|
|
135
|
-
to: '0x1715a3E4A142d8b698131108995174F37aEBA10D',
|
|
136
|
-
destinationRouter: '0x2Ed02372C3efF1F239B22a901ceA8Cf6fbf82d8d',
|
|
137
|
-
nativeRouter: '0x612Da68aA7BcA625dD2F27f252cddB573674991A',
|
|
138
|
-
validator: '0x5ECfE77502317F3677f23C3b8Ab17929ACE3D74E',
|
|
139
|
-
usesExtraParam: false,
|
|
140
|
-
feeManager: 'from',
|
|
141
|
-
toHome: false,
|
|
142
|
-
requiresDelivery: true,
|
|
143
|
-
// weth from ethereum on pulsechain
|
|
144
|
-
bridgedNativeAssetOut: '0x02DcdD04e3F455D838cd1249292C58f3B79e3C3C',
|
|
145
|
-
settingOverrides: {
|
|
146
|
-
[zeroAddress]: pulsechainPLSETHSettings,
|
|
147
|
-
[getAddress(nativeAssetOut[Chains.PLS])]: pulsechainPLSETHSettings,
|
|
148
|
-
},
|
|
149
|
-
},
|
|
150
|
-
},
|
|
151
|
-
[Chains.ETH]: {
|
|
152
|
-
[Chains.PLS]: {
|
|
153
|
-
from: '0x1715a3E4A142d8b698131108995174F37aEBA10D',
|
|
154
|
-
to: '0x4fD0aaa7506f3d9cB8274bdB946Ec42A1b8751Ef',
|
|
155
|
-
nativeRouter: '0x2Ed02372C3efF1F239B22a901ceA8Cf6fbf82d8d',
|
|
156
|
-
destinationRouter: '0x612Da68aA7BcA625dD2F27f252cddB573674991A',
|
|
157
|
-
validator: '0x5ECfE77502317F3677f23C3b8Ab17929ACE3D74E',
|
|
158
|
-
feeManager: 'to',
|
|
159
|
-
usesExtraParam: false,
|
|
160
|
-
toHome: true,
|
|
161
|
-
requiresDelivery: false,
|
|
162
|
-
// wpls from pulsechain on ethereum
|
|
163
|
-
bridgedNativeAssetOut: '0xA882606494D86804B5514E07e6Bd2D6a6eE6d68A',
|
|
164
|
-
settingOverrides: {
|
|
165
|
-
[getAddress('0xa882606494d86804b5514e07e6bd2d6a6ee6d68a')]: {
|
|
166
|
-
from: '0xe20E337DB2a00b1C37139c873B92a0AAd3F468bF',
|
|
167
|
-
to: '0x0e18d0d556b652794EF12Bf68B2dC857EF5f3996',
|
|
168
|
-
destinationRouter: '0xE66877Cfe4CEc10ffBbBB3092B7001321AB5809D',
|
|
169
|
-
nativeRouter: '0x1F0144Ce3BDaf11944Fe0beF6444599a0500695B',
|
|
170
|
-
},
|
|
171
|
-
},
|
|
172
|
-
},
|
|
173
|
-
},
|
|
174
|
-
},
|
|
175
|
-
[Providers.TOKENSEX]: {
|
|
176
|
-
[Chains.PLS]: {
|
|
177
|
-
[Chains.BNB]: {
|
|
178
|
-
from: '0xf1DFc63e10fF01b8c3d307529b47AefaD2154C0e',
|
|
179
|
-
to: '0xb4005881e81a6ecd2c1f75d58e8e41f28d59c6b1',
|
|
180
|
-
destinationRouter: '0x9c50EfD36dF2DBD310fBC981d6D8478cF3484B85',
|
|
181
|
-
nativeRouter: '0xB80B80EBB375BD83a9d6c0761b197d16a8670f81',
|
|
182
|
-
validator: '0xc3c3d5d3ba946a2eb3906878ebe187418b0b524e',
|
|
183
|
-
feeManager: 'from',
|
|
184
|
-
usesExtraParam: true,
|
|
185
|
-
toHome: false,
|
|
186
|
-
requiresDelivery: true,
|
|
187
|
-
// wbnb from bsc on pulsechain (tokensex)
|
|
188
|
-
bridgedNativeAssetOut: '0x518076CCE3729eF1a3877EA3647a26e278e764FE',
|
|
189
|
-
},
|
|
190
|
-
},
|
|
191
|
-
[Chains.BNB]: {
|
|
192
|
-
[Chains.PLS]: {
|
|
193
|
-
from: '0xb4005881e81a6ecd2c1f75d58e8e41f28d59c6b1',
|
|
194
|
-
to: '0xf1DFc63e10fF01b8c3d307529b47AefaD2154C0e',
|
|
195
|
-
nativeRouter: '0x9c50EfD36dF2DBD310fBC981d6D8478cF3484B85',
|
|
196
|
-
destinationRouter: '0xB80B80EBB375BD83a9d6c0761b197d16a8670f81',
|
|
197
|
-
validator: '0xc3c3d5d3ba946a2eb3906878ebe187418b0b524e',
|
|
198
|
-
feeManager: 'to',
|
|
199
|
-
usesExtraParam: true,
|
|
200
|
-
toHome: true,
|
|
201
|
-
requiresDelivery: false,
|
|
202
|
-
// wpls from pulsechain on bsc (tokensex)
|
|
203
|
-
bridgedNativeAssetOut: '0xF6088134D28eeBEF7128BA41FaDb2FCA0666c64C',
|
|
204
|
-
},
|
|
205
|
-
},
|
|
206
|
-
},
|
|
207
|
-
} as DeepPathwayConfig;
|
|
208
|
-
|
|
209
|
-
export const testnetPathways = {
|
|
210
|
-
[Providers.TOKENSEX]: {
|
|
211
|
-
// plsv4 to bnb home omnibridge: 0xfd0c07C376D27EA0E9fA64Ac5D2481439e36CF9C
|
|
212
|
-
// [Chains.BNB]: {
|
|
213
|
-
// [Chains.V4PLS]: {
|
|
214
|
-
// from: '0xDDf1b0CD7fb7AAA310c703C17995c6671F9DC806',
|
|
215
|
-
// to: '0xfd0c07C376D27EA0E9fA64Ac5D2481439e36CF9C',
|
|
216
|
-
// usesExtraParam: false,
|
|
217
|
-
// requiresDelivery: false,
|
|
218
|
-
// toHome: true,
|
|
219
|
-
// feeManager: 'to',
|
|
220
|
-
// defaultAssetIn: {
|
|
221
|
-
// chainId: 56,
|
|
222
|
-
// address: nativeAssetOut[Chains.TBNB],
|
|
223
|
-
// },
|
|
224
|
-
// },
|
|
225
|
-
// },
|
|
226
|
-
// [Chains.V4PLS]: {
|
|
227
|
-
// [Chains.BNB]: {
|
|
228
|
-
// from: '0xfd0c07C376D27EA0E9fA64Ac5D2481439e36CF9C',
|
|
229
|
-
// to: '0xDDf1b0CD7fb7AAA310c703C17995c6671F9DC806',
|
|
230
|
-
// },
|
|
231
|
-
// },
|
|
232
|
-
},
|
|
233
|
-
[Providers.PULSECHAIN]: {
|
|
234
|
-
[Chains.V4PLS]: {
|
|
235
|
-
[Chains.SEP]: {
|
|
236
|
-
from: '0x6B08a50865aDeCe6e3869D9AfbB316d0a0436B6c',
|
|
237
|
-
to: '0x546e37DAA15cdb82fd1a717E5dEEa4AF08D4349A',
|
|
238
|
-
nativeRouter: '0xCA1BDc038909038C4B3cbab0EA0ec3cC2839F106',
|
|
239
|
-
destinationRouter: '0xCb4057d7DA4CE521B93b71186DfE11f9FBC3e3b1',
|
|
240
|
-
validator: '0xDcd4D88552c86114b2ca029F7F8d4e1a7951d051',
|
|
241
|
-
usesExtraParam: false,
|
|
242
|
-
requiresDelivery: true,
|
|
243
|
-
toHome: false,
|
|
244
|
-
feeManager: 'from',
|
|
245
|
-
bridgedNativeAssetOut: '0x3677bd78ccf4d299328ecfba61790cf8dbfcf686',
|
|
246
|
-
},
|
|
247
|
-
},
|
|
248
|
-
[Chains.SEP]: {
|
|
249
|
-
[Chains.V4PLS]: {
|
|
250
|
-
from: '0x546e37DAA15cdb82fd1a717E5dEEa4AF08D4349A',
|
|
251
|
-
to: '0x6B08a50865aDeCe6e3869D9AfbB316d0a0436B6c',
|
|
252
|
-
nativeRouter: '0xCb4057d7DA4CE521B93b71186DfE11f9FBC3e3b1',
|
|
253
|
-
destinationRouter: '0xCA1BDc038909038C4B3cbab0EA0ec3cC2839F106',
|
|
254
|
-
validator: '0xDcd4D88552c86114b2ca029F7F8d4e1a7951d051',
|
|
255
|
-
usesExtraParam: false,
|
|
256
|
-
requiresDelivery: false,
|
|
257
|
-
toHome: true,
|
|
258
|
-
feeManager: 'to',
|
|
259
|
-
bridgedNativeAssetOut: '0x35807560aD0597E23F452cdc82D4Fb0e7E3c6590',
|
|
260
|
-
},
|
|
261
|
-
},
|
|
262
|
-
},
|
|
263
|
-
} as DeepPathwayConfig;
|
|
264
|
-
|
|
265
|
-
/** The mainnet bridge keys */
|
|
266
|
-
const mainnetBridgeKeys = [
|
|
267
|
-
[Providers.PULSECHAIN, Chains.PLS, Chains.ETH],
|
|
268
|
-
[Providers.PULSECHAIN, Chains.ETH, Chains.PLS],
|
|
269
|
-
[Providers.TOKENSEX, Chains.PLS, Chains.BNB],
|
|
270
|
-
[Providers.TOKENSEX, Chains.BNB, Chains.PLS],
|
|
271
|
-
] as BridgeKey[];
|
|
272
|
-
|
|
273
|
-
/** The testnet bridge keys */
|
|
274
|
-
const testnetBridgeKeys = [
|
|
275
|
-
[Providers.PULSECHAIN, Chains.SEP, Chains.V4PLS],
|
|
276
|
-
[Providers.PULSECHAIN, Chains.V4PLS, Chains.SEP],
|
|
277
|
-
] as BridgeKey[];
|
|
278
|
-
|
|
279
|
-
/** Returns the valid bridge keys for the given is prod */
|
|
280
|
-
export const validBridgeKeys = (isProd: boolean) => [
|
|
281
|
-
...mainnetBridgeKeys,
|
|
282
|
-
...(isProd ? [] : testnetBridgeKeys),
|
|
283
|
-
];
|
|
284
|
-
|
|
285
|
-
/**
|
|
286
|
-
* Infers the bridge key from the current key, provider, from chain, and to chain
|
|
287
|
-
* @param currentKey - the current bridge key
|
|
288
|
-
* @param provider - the provider
|
|
289
|
-
* @param fromChain - the from chain
|
|
290
|
-
* @param toChain - the to chain
|
|
291
|
-
* @returns the inferred bridge key
|
|
292
|
-
*/
|
|
293
|
-
export const inferBridgeKey = ({
|
|
294
|
-
currentKey,
|
|
295
|
-
provider,
|
|
296
|
-
fromChain,
|
|
297
|
-
toChain,
|
|
298
|
-
}: {
|
|
299
|
-
currentKey: BridgeKey;
|
|
300
|
-
provider: Provider;
|
|
301
|
-
fromChain?: Chains;
|
|
302
|
-
toChain?: Chains;
|
|
303
|
-
}) => {
|
|
304
|
-
const [, fromChainKey, toChainKey] = currentKey;
|
|
305
|
-
const from = fromChain ?? fromChainKey;
|
|
306
|
-
const to = toChain ?? toChainKey;
|
|
307
|
-
const currentFromChainIsValid = !!_.get(pathways, [provider, from]);
|
|
308
|
-
const nextFromChain = currentFromChainIsValid
|
|
309
|
-
? from
|
|
310
|
-
: (Object.keys(pathways[provider])[0] as Chains);
|
|
311
|
-
const currentToChainIsValid = !!_.get(pathways, [provider, nextFromChain, to]);
|
|
312
|
-
const nextToChain = currentToChainIsValid
|
|
313
|
-
? to
|
|
314
|
-
: (Object.keys(pathways[provider]![nextFromChain]!)[0] as Chains);
|
|
315
|
-
return [provider, nextFromChain, nextToChain] as BridgeKey;
|
|
316
|
-
};
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
* Returns the pathway for the given bridge key, is prod, and asset in address
|
|
320
|
-
* @param bridgeKey - the bridge key
|
|
321
|
-
* @param isProd - whether to use the production pathway
|
|
322
|
-
* @param assetInAddress - the asset in address
|
|
323
|
-
* @returns the pathway
|
|
324
|
-
*/
|
|
325
|
-
export const pathway = (
|
|
326
|
-
bridgeKey: BridgeKey | null,
|
|
327
|
-
isProd: boolean,
|
|
328
|
-
assetInAddress?: string | Hex | null | undefined,
|
|
329
|
-
) => {
|
|
330
|
-
if (!bridgeKey) return;
|
|
331
|
-
let pathway =
|
|
332
|
-
_.get(pathways, bridgeKey) || (!isProd ? _.get(testnetPathways, bridgeKey) : undefined);
|
|
333
|
-
if (assetInAddress) {
|
|
334
|
-
const addr = getAddress(assetInAddress);
|
|
335
|
-
if (pathway?.settingOverrides?.[addr]) {
|
|
336
|
-
pathway = {
|
|
337
|
-
...pathway,
|
|
338
|
-
...pathway.settingOverrides[addr],
|
|
339
|
-
};
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
return pathway;
|
|
343
|
-
};
|
|
344
|
-
|
|
345
|
-
/**
|
|
346
|
-
* Returns the default asset in for the given bridge key and is prod
|
|
347
|
-
* @param bridgeKey - the bridge key
|
|
348
|
-
* @param isProd - whether to use the production pathway
|
|
349
|
-
* @returns the default asset in
|
|
350
|
-
*/
|
|
351
|
-
export const defaultAssetIn = ($bridgeKey: BridgeKey | null, isProd: boolean) => {
|
|
352
|
-
if (!$bridgeKey) return null;
|
|
353
|
-
const conf = pathway($bridgeKey, isProd);
|
|
354
|
-
const defaultAssetIn = _.get(conf, ['bridgedNativeAssetOut']) as Hex | undefined;
|
|
355
|
-
return defaultAssetIn;
|
|
356
|
-
};
|
|
357
|
-
|
|
358
|
-
/**
|
|
359
|
-
* Returns whether the given asset is the native asset for the given bridge key
|
|
360
|
-
* @param asset - the asset
|
|
361
|
-
* @param bridgeKey - the bridge key
|
|
362
|
-
* @returns whether the given asset is the native asset for the given bridge key
|
|
363
|
-
*/
|
|
364
|
-
export const isNative = (asset: Token | TokenOut | null, bridgeKey: BridgeKey | null) => {
|
|
365
|
-
if (!bridgeKey || !asset) {
|
|
366
|
-
return false;
|
|
367
|
-
}
|
|
368
|
-
const path = pathway(bridgeKey, false);
|
|
369
|
-
return (
|
|
370
|
-
getAddress(asset.address!) === getAddress(path!.bridgedNativeAssetOut!) ||
|
|
371
|
-
((asset.address === zeroAddress ||
|
|
372
|
-
nativeAssetOut[toChain(asset.chainId)]?.toLowerCase() === asset.address?.toLowerCase()) &&
|
|
373
|
-
!asset.name.includes(' from Pulsechain'))
|
|
374
|
-
);
|
|
375
|
-
};
|
|
376
|
-
|
|
377
|
-
/**
|
|
378
|
-
* Returns whether the given asset is unwrappable for the given bridge key
|
|
379
|
-
* @param bridgeKey - the bridge key
|
|
380
|
-
* @param assetIn - the asset in
|
|
381
|
-
* @returns whether the given asset is unwrappable for the given bridge key
|
|
382
|
-
*/
|
|
383
|
-
export const isUnwrappable = (
|
|
384
|
-
bridgeKey: BridgeKey | null,
|
|
385
|
-
assetIn: Pick<Token, 'address'> | null,
|
|
386
|
-
) => {
|
|
387
|
-
if (!bridgeKey || !assetIn) {
|
|
388
|
-
return false;
|
|
389
|
-
}
|
|
390
|
-
const addr = getAddress(assetIn.address);
|
|
391
|
-
const path = pathway(bridgeKey, false);
|
|
392
|
-
if (!path) return false;
|
|
393
|
-
return path.bridgedNativeAssetOut === getAddress(addr);
|
|
394
|
-
};
|
|
395
|
-
|
|
396
|
-
/**
|
|
397
|
-
* Returns whether the given asset can be unwrapped for the given bridge key
|
|
398
|
-
* @param bridgeKey - the bridge key
|
|
399
|
-
* @param assetIn - the asset in
|
|
400
|
-
* @returns boolean
|
|
401
|
-
*/
|
|
402
|
-
export const canChangeUnwrap = (bridgeKey: BridgeKey, assetIn: Token | null) => {
|
|
403
|
-
return !!assetIn && isUnwrappable(bridgeKey, assetIn);
|
|
404
|
-
};
|
|
405
|
-
|
|
406
|
-
export const chains = {
|
|
407
|
-
ethereum: 1,
|
|
408
|
-
bsc: 56,
|
|
409
|
-
pulsechain: 369,
|
|
410
|
-
pulsechainV4: 943,
|
|
411
|
-
sepolia: 11155111,
|
|
412
|
-
} as const;
|
|
413
|
-
|
|
414
|
-
export const chainIds = Object.values(chains);
|
|
415
|
-
|
|
416
|
-
/** Start blocks aligned with when bridge validators began operating — canonical reference for all ponder indexers in this monorepo. */
|
|
417
|
-
export const startBlocks: Record<keyof typeof chains, number> = {
|
|
418
|
-
ethereum: 17_264_119,
|
|
419
|
-
bsc: 28_987_313,
|
|
420
|
-
pulsechain: 17_268_300,
|
|
421
|
-
pulsechainV4: 16_564_233,
|
|
422
|
-
sepolia: 3_331_901,
|
|
423
|
-
};
|
|
424
|
-
|
|
425
|
-
export type ChainId = (typeof chainIds)[number];
|
|
426
|
-
|
|
427
|
-
export type Side = 'home' | 'foreign';
|
|
428
|
-
|
|
429
|
-
export type MinimalKey = `${ChainId}-${Hex}`;
|
|
430
|
-
|
|
431
|
-
// export const Providers = {
|
|
432
|
-
// PULSECHAIN: 'pulsechain',
|
|
433
|
-
// TOKENSEX: 'tokensex',
|
|
434
|
-
// } as const
|
|
435
|
-
|
|
436
|
-
export type PathwayInfo = {
|
|
437
|
-
pair: string;
|
|
438
|
-
key: string;
|
|
439
|
-
home: Hex;
|
|
440
|
-
foreign: Hex;
|
|
441
|
-
};
|
|
442
|
-
|
|
443
|
-
export type ProviderHomeChainEntry = Partial<Record<ChainId, PathwayInfo[]>>;
|
|
444
|
-
|
|
445
|
-
export type ProviderEntries = Partial<Record<ChainId, ProviderHomeChainEntry>>;
|
|
446
|
-
|
|
447
|
-
export type BridgeConfig = Record<Provider, ProviderEntries>;
|
|
448
|
-
|
|
449
|
-
// provider -> home -> foreign
|
|
450
|
-
export const bridgeConfigs = {
|
|
451
|
-
[Providers.PULSECHAIN]: {
|
|
452
|
-
[chains.pulsechain]: {
|
|
453
|
-
[chains.ethereum]: [
|
|
454
|
-
{
|
|
455
|
-
pair: 'mainnet',
|
|
456
|
-
key: 'erc20',
|
|
457
|
-
home: '0x4fD0aaa7506f3d9cB8274bdB946Ec42A1b8751Ef',
|
|
458
|
-
foreign: '0x1715a3e4a142d8b698131108995174f37aeba10d',
|
|
459
|
-
},
|
|
460
|
-
{
|
|
461
|
-
pair: 'mainnet',
|
|
462
|
-
key: 'native',
|
|
463
|
-
home: '0x0e18d0d556b652794EF12Bf68B2dC857EF5f3996',
|
|
464
|
-
foreign: '0xe20E337DB2a00b1C37139c873B92a0AAd3F468bF',
|
|
465
|
-
},
|
|
466
|
-
],
|
|
467
|
-
},
|
|
468
|
-
[chains.pulsechainV4]: {
|
|
469
|
-
[chains.sepolia]: [
|
|
470
|
-
{
|
|
471
|
-
pair: 'v4',
|
|
472
|
-
key: 'erc20',
|
|
473
|
-
home: '0x6B08a50865aDeCe6e3869D9AfbB316d0a0436B6c',
|
|
474
|
-
foreign: '0x546e37DAA15cdb82fd1a717E5dEEa4AF08D4349A',
|
|
475
|
-
},
|
|
476
|
-
{
|
|
477
|
-
pair: 'v4',
|
|
478
|
-
key: 'native',
|
|
479
|
-
home: '0x81c10846F40fA2B173FC47958D0a892529983F50',
|
|
480
|
-
foreign: '0x5e238ef968467cf443ef5ecb683b76c5a04a0421',
|
|
481
|
-
},
|
|
482
|
-
],
|
|
483
|
-
},
|
|
484
|
-
},
|
|
485
|
-
[Providers.TOKENSEX]: {
|
|
486
|
-
[chains.pulsechain]: {
|
|
487
|
-
[chains.bsc]: [
|
|
488
|
-
{
|
|
489
|
-
pair: 'bsctokensex',
|
|
490
|
-
key: 'erc20',
|
|
491
|
-
home: '0xf1DFc63e10fF01b8c3d307529b47AefaD2154C0e',
|
|
492
|
-
foreign: '0xb4005881e81a6ecd2c1f75d58e8e41f28d59c6b1',
|
|
493
|
-
},
|
|
494
|
-
],
|
|
495
|
-
},
|
|
496
|
-
},
|
|
497
|
-
} as BridgeConfig;
|
|
498
|
-
|
|
499
|
-
export const HOME_TO_FOREIGN_FEE = keccak256(stringToHex('homeToForeignFee'));
|
|
500
|
-
export const FOREIGN_TO_HOME_FEE = keccak256(stringToHex('foreignToHomeFee'));
|
package/src/fee-type.test.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { FeeType, feeTypeValToKeyMap } from './fee-type';
|
|
3
|
-
|
|
4
|
-
describe('fee-type', () => {
|
|
5
|
-
describe('FeeType enum', () => {
|
|
6
|
-
it('should have PERCENT fee type', () => {
|
|
7
|
-
expect(FeeType.PERCENT).toBe('%');
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it('should have GAS_TIP fee type', () => {
|
|
11
|
-
expect(FeeType.GAS_TIP).toBe('gas+%');
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it('should have FIXED fee type', () => {
|
|
15
|
-
expect(FeeType.FIXED).toBe('fixed');
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('should have exactly 3 fee types', () => {
|
|
19
|
-
const keys = Object.keys(FeeType);
|
|
20
|
-
expect(keys).toHaveLength(3);
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
describe('feeTypeValToKeyMap', () => {
|
|
25
|
-
it('should map PERCENT value to key', () => {
|
|
26
|
-
expect(feeTypeValToKeyMap.get(FeeType.PERCENT)).toBe('PERCENT');
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('should map GAS_TIP value to key', () => {
|
|
30
|
-
expect(feeTypeValToKeyMap.get(FeeType.GAS_TIP)).toBe('GAS_TIP');
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('should map FIXED value to key', () => {
|
|
34
|
-
expect(feeTypeValToKeyMap.get(FeeType.FIXED)).toBe('FIXED');
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('should map all fee type values to keys', () => {
|
|
38
|
-
expect(feeTypeValToKeyMap.size).toBe(3);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('should return undefined for invalid fee type', () => {
|
|
42
|
-
expect(feeTypeValToKeyMap.get('invalid' as FeeType)).toBeUndefined();
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
});
|
package/src/fee-type.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/** The type of fee to use for the bridge */
|
|
2
|
-
export enum FeeType {
|
|
3
|
-
PERCENT = '%',
|
|
4
|
-
GAS_TIP = 'gas+%',
|
|
5
|
-
FIXED = 'fixed',
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/** The keys of the fee type */
|
|
9
|
-
export type FeeTypeKeys = keyof typeof FeeType;
|
|
10
|
-
|
|
11
|
-
/** A map of fee type values to keys */
|
|
12
|
-
export const feeTypeValToKeyMap = new Map<FeeType, FeeTypeKeys>(
|
|
13
|
-
(Object.keys(FeeType) as FeeTypeKeys[]).map((key) => [FeeType[key], key]),
|
|
14
|
-
);
|