@gibs/bridge-sdk 1.7.1 → 1.7.3
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 +476 -12
- package/dist/src/abis.d.ts +14 -1
- package/dist/src/abis.js +14 -1
- package/dist/src/chain-info.d.ts +52 -0
- package/dist/src/chain-info.js +51 -15
- package/dist/src/config.d.ts +61 -2
- package/dist/src/config.js +63 -92
- package/dist/src/fee-type.d.ts +3 -0
- package/dist/src/fee-type.js +2 -0
- package/dist/src/image-links.d.ts +29 -0
- package/dist/src/image-links.js +28 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/settings.d.ts +341 -0
- package/dist/src/settings.js +614 -0
- package/dist/src/types.d.ts +9 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -2
- package/src/abis.ts +14 -2
- package/src/chain-info.ts +53 -15
- package/src/config.ts +66 -92
- package/src/fee-type.ts +3 -1
- package/src/image-links.ts +29 -0
- package/src/index.ts +1 -0
- package/src/settings.ts +853 -0
- package/src/types.ts +9 -0
package/dist/src/chain-info.d.ts
CHANGED
|
@@ -15,12 +15,29 @@ export type TokenBridgeInfo = {
|
|
|
15
15
|
foreign: Hex;
|
|
16
16
|
};
|
|
17
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* Returns the bridged token address and native token address
|
|
20
|
+
* @param chainId - the chain id being targeted
|
|
21
|
+
* @param target - the target
|
|
22
|
+
* @param address - the address
|
|
23
|
+
* @param client - the client
|
|
24
|
+
* @returns the bridged token address and native token address
|
|
25
|
+
*/
|
|
18
26
|
export declare const links: (({ chainId, target, address, client }: {
|
|
19
27
|
chainId: number;
|
|
20
28
|
target: Hex;
|
|
21
29
|
address: Hex;
|
|
22
30
|
client: PublicClient;
|
|
23
31
|
}) => Promise<`0x${string}`[]>) & _.MemoizedFunction;
|
|
32
|
+
/**
|
|
33
|
+
* Returns the token bridge info for the given bridge key, asset in, is prod, from chain client, and to chain client
|
|
34
|
+
* @param bridgeKey - the bridge key
|
|
35
|
+
* @param assetIn - the asset in
|
|
36
|
+
* @param isProd - whether to use the production pathway
|
|
37
|
+
* @param fromChainClient - the from chain client
|
|
38
|
+
* @param toChainClient - the to chain client
|
|
39
|
+
* @returns the token bridge info
|
|
40
|
+
*/
|
|
24
41
|
export declare const tokenBridgeInfo: ({ bridgeKey, assetIn, isProd, fromChainClient, toChainClient, }: {
|
|
25
42
|
bridgeKey: BridgeKey;
|
|
26
43
|
assetIn: Token | null;
|
|
@@ -28,7 +45,20 @@ export declare const tokenBridgeInfo: ({ bridgeKey, assetIn, isProd, fromChainCl
|
|
|
28
45
|
fromChainClient: PublicClient;
|
|
29
46
|
toChainClient: PublicClient;
|
|
30
47
|
}) => Promise<null | TokenBridgeInfo>;
|
|
48
|
+
/** The result of reading the amount out from a router */
|
|
31
49
|
export type FetchResult = bigint[] | Hex;
|
|
50
|
+
/**
|
|
51
|
+
* Fetch the price corrective for the given bridge key, asset out, measurement token, from chain client, to chain client, asset link, amount in, and is prod
|
|
52
|
+
* @param bridgeKeyPartner - the bridge key partner
|
|
53
|
+
* @param assetOut - the asset out
|
|
54
|
+
* @param measurementToken - the measurement token
|
|
55
|
+
* @param fromChainClient - the from chain client
|
|
56
|
+
* @param toChainClient - the to chain client
|
|
57
|
+
* @param assetLink - the asset link
|
|
58
|
+
* @param amountIn - the amount in
|
|
59
|
+
* @param isProd - whether to use the production pathway
|
|
60
|
+
* @returns the price corrective
|
|
61
|
+
*/
|
|
32
62
|
export declare const fetchPriceCorrective: ({ bridgeKeyPartner, assetOut, measurementToken, fromChainClient, toChainClient, assetLink, amountIn, isProd, }: {
|
|
33
63
|
bridgeKey: BridgeKey;
|
|
34
64
|
bridgeKeyPartner: BridgeKey;
|
|
@@ -52,6 +82,14 @@ export declare const fetchPriceCorrective: ({ bridgeKeyPartner, assetOut, measur
|
|
|
52
82
|
oneToken: bigint;
|
|
53
83
|
}) => bigint;
|
|
54
84
|
};
|
|
85
|
+
/**
|
|
86
|
+
* Fetch the minimum bridge amount in for the given asset in, pathway, from public client, and to public client
|
|
87
|
+
* @param assetIn - the asset in
|
|
88
|
+
* @param pathway - the pathway
|
|
89
|
+
* @param fromPublicClient - the from public client
|
|
90
|
+
* @param toPublicClient - the to public client
|
|
91
|
+
* @returns the minimum bridge amount in
|
|
92
|
+
*/
|
|
55
93
|
export declare const minBridgeAmountIn: ({ assetIn, pathway, fromPublicClient, toPublicClient, }: {
|
|
56
94
|
assetIn: Token;
|
|
57
95
|
pathway: Pathway;
|
|
@@ -64,15 +102,29 @@ export declare const nativeSymbol: (asset: {
|
|
|
64
102
|
symbol: string;
|
|
65
103
|
chainId: number;
|
|
66
104
|
} | null, unwrap?: boolean) => string;
|
|
105
|
+
/** The input for loading the bridge fees */
|
|
67
106
|
export type InputLoadFeeFor = {
|
|
68
107
|
pathway: Pathway;
|
|
69
108
|
fromChainClient: PublicClient;
|
|
70
109
|
toChainClient: PublicClient;
|
|
71
110
|
};
|
|
111
|
+
/** The fee configuration for a given pathway */
|
|
72
112
|
export type PathwayExtendableConfig = {
|
|
73
113
|
feeManager: Hex;
|
|
74
114
|
feeH2F: bigint;
|
|
75
115
|
feeF2H: bigint;
|
|
76
116
|
};
|
|
117
|
+
/**
|
|
118
|
+
* Returns the chain multicall for the given client
|
|
119
|
+
* @param client - the client
|
|
120
|
+
* @returns the chain multicall
|
|
121
|
+
*/
|
|
77
122
|
export declare const chainMulticall: (client: PublicClient) => any;
|
|
123
|
+
/**
|
|
124
|
+
* Load the bridge fees for the given pathway, from chain client, and to chain client
|
|
125
|
+
* @param pathway - the pathway
|
|
126
|
+
* @param fromChainClient - the from chain client
|
|
127
|
+
* @param toChainClient - the to chain client
|
|
128
|
+
* @returns the bridge fees
|
|
129
|
+
*/
|
|
78
130
|
export declare const loadBridgeFees: ({ pathway, fromChainClient, toChainClient }: InputLoadFeeFor) => Promise<PathwayExtendableConfig>;
|
package/dist/src/chain-info.js
CHANGED
|
@@ -4,6 +4,14 @@ import _ from "lodash";
|
|
|
4
4
|
import { chainsMetadata } from "./chains.js";
|
|
5
5
|
import * as abis from "./abis.js";
|
|
6
6
|
import { multicallRead } from "@gibs/common/multicall";
|
|
7
|
+
/**
|
|
8
|
+
* Returns the bridged token address and native token address
|
|
9
|
+
* @param chainId - the chain id being targeted
|
|
10
|
+
* @param target - the target
|
|
11
|
+
* @param address - the address
|
|
12
|
+
* @param client - the client
|
|
13
|
+
* @returns the bridged token address and native token address
|
|
14
|
+
*/
|
|
7
15
|
export const links = _.memoize(async ({ chainId, target, address, client }) => {
|
|
8
16
|
return multicallRead({
|
|
9
17
|
client,
|
|
@@ -16,6 +24,15 @@ export const links = _.memoize(async ({ chainId, target, address, client }) => {
|
|
|
16
24
|
],
|
|
17
25
|
});
|
|
18
26
|
}, ({ chainId, target, address }) => `${chainId}-${target}-${address}`.toLowerCase());
|
|
27
|
+
/**
|
|
28
|
+
* Returns the token bridge info for the given bridge key, asset in, is prod, from chain client, and to chain client
|
|
29
|
+
* @param bridgeKey - the bridge key
|
|
30
|
+
* @param assetIn - the asset in
|
|
31
|
+
* @param isProd - whether to use the production pathway
|
|
32
|
+
* @param fromChainClient - the from chain client
|
|
33
|
+
* @param toChainClient - the to chain client
|
|
34
|
+
* @returns the token bridge info
|
|
35
|
+
*/
|
|
19
36
|
export const tokenBridgeInfo = async ({ bridgeKey, assetIn, isProd, fromChainClient, toChainClient, }) => {
|
|
20
37
|
const bridgePathway = pathway(bridgeKey, isProd, assetIn?.address);
|
|
21
38
|
if (!assetIn || !bridgePathway) {
|
|
@@ -39,11 +56,7 @@ export const tokenBridgeInfo = async ({ bridgeKey, assetIn, isProd, fromChainCli
|
|
|
39
56
|
}),
|
|
40
57
|
]);
|
|
41
58
|
const [toBridged, toNative] = toMappings;
|
|
42
|
-
// const notGas = !Object.values(nativeAssetOut).find(
|
|
43
|
-
// (v) => v.toLowerCase() === assetInAddress.toLowerCase(),
|
|
44
|
-
// )
|
|
45
59
|
if (toBridged !== zeroAddress) {
|
|
46
|
-
// if (notGas) console.log('toBridged')
|
|
47
60
|
return {
|
|
48
61
|
originationChainId: fromChain,
|
|
49
62
|
assetInAddress: assetInAddress,
|
|
@@ -55,8 +68,6 @@ export const tokenBridgeInfo = async ({ bridgeKey, assetIn, isProd, fromChainCli
|
|
|
55
68
|
};
|
|
56
69
|
}
|
|
57
70
|
if (toNative !== zeroAddress) {
|
|
58
|
-
// if (notGas) console.log('toNative')
|
|
59
|
-
console.log('toNative', toNative);
|
|
60
71
|
return {
|
|
61
72
|
originationChainId: toChain,
|
|
62
73
|
assetInAddress: assetInAddress,
|
|
@@ -69,8 +80,6 @@ export const tokenBridgeInfo = async ({ bridgeKey, assetIn, isProd, fromChainCli
|
|
|
69
80
|
}
|
|
70
81
|
const [fromBridged, fromNative] = fromMappings;
|
|
71
82
|
if (fromNative !== zeroAddress) {
|
|
72
|
-
// if (notGas) console.log('fromNative')
|
|
73
|
-
console.log('fromNative', fromNative);
|
|
74
83
|
return {
|
|
75
84
|
originationChainId: toChain,
|
|
76
85
|
assetInAddress: assetInAddress,
|
|
@@ -82,7 +91,6 @@ export const tokenBridgeInfo = async ({ bridgeKey, assetIn, isProd, fromChainCli
|
|
|
82
91
|
};
|
|
83
92
|
}
|
|
84
93
|
if (fromBridged !== zeroAddress) {
|
|
85
|
-
// if (notGas) console.log('fromBridged')
|
|
86
94
|
return {
|
|
87
95
|
originationChainId: fromChain,
|
|
88
96
|
assetInAddress: assetInAddress,
|
|
@@ -114,7 +122,7 @@ export const tokenBridgeInfo = async ({ bridgeKey, assetIn, isProd, fromChainCli
|
|
|
114
122
|
};
|
|
115
123
|
};
|
|
116
124
|
/**
|
|
117
|
-
*
|
|
125
|
+
* Check the prices that each router offers for the given paths
|
|
118
126
|
* @param assetInAddress the address of the asset going into the bridge
|
|
119
127
|
* @param oneTokenInt the number of tokens to push into the bridge (before fees)
|
|
120
128
|
* @param chain the chain of the asset going into the bridge
|
|
@@ -137,11 +145,19 @@ const readAmountOut = ({ amountIn, chain, paths, client, uniV2Router, }) => {
|
|
|
137
145
|
}))),
|
|
138
146
|
});
|
|
139
147
|
};
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
148
|
+
/**
|
|
149
|
+
* Fetch the price corrective for the given bridge key, asset out, measurement token, from chain client, to chain client, asset link, amount in, and is prod
|
|
150
|
+
* @param bridgeKeyPartner - the bridge key partner
|
|
151
|
+
* @param assetOut - the asset out
|
|
152
|
+
* @param measurementToken - the measurement token
|
|
153
|
+
* @param fromChainClient - the from chain client
|
|
154
|
+
* @param toChainClient - the to chain client
|
|
155
|
+
* @param assetLink - the asset link
|
|
156
|
+
* @param amountIn - the amount in
|
|
157
|
+
* @param isProd - whether to use the production pathway
|
|
158
|
+
* @returns the price corrective
|
|
159
|
+
*/
|
|
160
|
+
export const fetchPriceCorrective = ({ bridgeKeyPartner, assetOut, measurementToken, fromChainClient, toChainClient, assetLink, amountIn, isProd, }) => {
|
|
145
161
|
return {
|
|
146
162
|
getPaymentToken: async () => {
|
|
147
163
|
// fetch the token bridge info for the token that is about to be spent by the delivery service
|
|
@@ -215,6 +231,14 @@ bridgeKeyPartner, assetOut, measurementToken, fromChainClient, toChainClient, as
|
|
|
215
231
|
}
|
|
216
232
|
};
|
|
217
233
|
};
|
|
234
|
+
/**
|
|
235
|
+
* Fetch the minimum bridge amount in for the given asset in, pathway, from public client, and to public client
|
|
236
|
+
* @param assetIn - the asset in
|
|
237
|
+
* @param pathway - the pathway
|
|
238
|
+
* @param fromPublicClient - the from public client
|
|
239
|
+
* @param toPublicClient - the to public client
|
|
240
|
+
* @returns the minimum bridge amount in
|
|
241
|
+
*/
|
|
218
242
|
export const minBridgeAmountIn = async ({ assetIn, pathway, fromPublicClient, toPublicClient, }) => {
|
|
219
243
|
const publicClient = pathway?.feeManager === 'from' ? fromPublicClient : toPublicClient;
|
|
220
244
|
return publicClient.readContract({
|
|
@@ -228,6 +252,11 @@ export const minBridgeAmountIn = async ({ assetIn, pathway, fromPublicClient, to
|
|
|
228
252
|
export const nativeSymbol = (asset, unwrap = false) => {
|
|
229
253
|
return asset ? (unwrap && asset.address === nativeAssetOut[toChain(asset.chainId)] ? asset.symbol.slice(1) : asset.symbol) : '';
|
|
230
254
|
};
|
|
255
|
+
/**
|
|
256
|
+
* Returns the chain multicall for the given client
|
|
257
|
+
* @param client - the client
|
|
258
|
+
* @returns the chain multicall
|
|
259
|
+
*/
|
|
231
260
|
export const chainMulticall = (client) => {
|
|
232
261
|
const chainId = client.chain.id;
|
|
233
262
|
const metadata = chainsMetadata[toChain(chainId)];
|
|
@@ -237,6 +266,13 @@ export const chainMulticall = (client) => {
|
|
|
237
266
|
address: metadata.contracts.multicall3.address,
|
|
238
267
|
});
|
|
239
268
|
};
|
|
269
|
+
/**
|
|
270
|
+
* Load the bridge fees for the given pathway, from chain client, and to chain client
|
|
271
|
+
* @param pathway - the pathway
|
|
272
|
+
* @param fromChainClient - the from chain client
|
|
273
|
+
* @param toChainClient - the to chain client
|
|
274
|
+
* @returns the bridge fees
|
|
275
|
+
*/
|
|
240
276
|
export const loadBridgeFees = async ({ pathway, fromChainClient, toChainClient }) => {
|
|
241
277
|
const multicall = pathway.feeManager === 'from'
|
|
242
278
|
? chainMulticall(fromChainClient)
|
package/dist/src/config.d.ts
CHANGED
|
@@ -10,26 +10,44 @@ export declare enum Chains {
|
|
|
10
10
|
SEP = "0xaa36a7",
|
|
11
11
|
V4PLS = "0x3af"
|
|
12
12
|
}
|
|
13
|
+
/** The key of a chain - human readable for query params */
|
|
13
14
|
export type ChainKey = keyof typeof Chains;
|
|
15
|
+
/** A map of chain ids to chain keys */
|
|
14
16
|
export declare const chainIdToKey: Map<Chains, "ETH" | "PLS" | "BNB" | "SEP" | "V4PLS">;
|
|
17
|
+
/**
|
|
18
|
+
* Converts a chain id to a chain key
|
|
19
|
+
* @param chainId - the chain id
|
|
20
|
+
* @returns the chain key
|
|
21
|
+
*/
|
|
15
22
|
export declare const toChain: (chainId: number | string) => Chains;
|
|
23
|
+
/**
|
|
24
|
+
* Converts a chain id to a chain key
|
|
25
|
+
* @param chainId - the chain id
|
|
26
|
+
* @returns the chain key
|
|
27
|
+
*/
|
|
16
28
|
export declare const toChainKey: (chainId: number | string) => "ETH" | "PLS" | "BNB" | "SEP" | "V4PLS" | undefined;
|
|
29
|
+
/** The provider of an omnibridge */
|
|
17
30
|
export declare enum Provider {
|
|
18
31
|
PULSECHAIN = "pulsechain",
|
|
19
32
|
TOKENSEX = "tokensex"
|
|
20
33
|
}
|
|
34
|
+
/** A map of chains to native asset out addresses */
|
|
21
35
|
export declare const nativeAssetOut: Record<Chains, Hex>;
|
|
36
|
+
/** A map of chains to deprecated native asset out addresses */
|
|
22
37
|
export declare const deprecatedNativeAssetOut: Partial<Record<Chains, Set<Hex>>>;
|
|
38
|
+
/** A map of chains to uni v2 router addresses */
|
|
23
39
|
export declare const uniV2Routers: Record<Chains, Hex[]>;
|
|
40
|
+
/** A map of chains to native token symbols */
|
|
24
41
|
export declare const nativeTokenSymbol: Record<Chains, string>;
|
|
42
|
+
/** A map of chains to native token names */
|
|
25
43
|
export declare const nativeTokenName: Record<Chains, string>;
|
|
44
|
+
/** The pathway of a bridge */
|
|
26
45
|
export type Pathway = {
|
|
27
46
|
from: Hex;
|
|
28
47
|
to: Hex;
|
|
29
48
|
destinationRouter: Hex | null;
|
|
30
49
|
nativeRouter: Hex;
|
|
31
50
|
validator: Hex;
|
|
32
|
-
defaultAssetIn: Token;
|
|
33
51
|
usesExtraParam: boolean;
|
|
34
52
|
feeManager: 'from' | 'to';
|
|
35
53
|
toHome: boolean;
|
|
@@ -37,18 +55,59 @@ export type Pathway = {
|
|
|
37
55
|
bridgedNativeAssetOut: Hex;
|
|
38
56
|
settingOverrides?: Record<Hex, Partial<Pathway>>;
|
|
39
57
|
};
|
|
58
|
+
/** A map of providers to pathways */
|
|
40
59
|
export type DeepPathwayConfig = Record<Provider, Partial<Record<Chains, Partial<Record<Chains, Pathway>>>>>;
|
|
41
60
|
export declare const pathways: DeepPathwayConfig;
|
|
42
61
|
export declare const testnetPathways: DeepPathwayConfig;
|
|
62
|
+
/** Returns the valid bridge keys for the given is prod */
|
|
43
63
|
export declare const validBridgeKeys: (isProd: boolean) => BridgeKey[];
|
|
64
|
+
/**
|
|
65
|
+
* Infers the bridge key from the current key, provider, from chain, and to chain
|
|
66
|
+
* @param currentKey - the current bridge key
|
|
67
|
+
* @param provider - the provider
|
|
68
|
+
* @param fromChain - the from chain
|
|
69
|
+
* @param toChain - the to chain
|
|
70
|
+
* @returns the inferred bridge key
|
|
71
|
+
*/
|
|
44
72
|
export declare const inferBridgeKey: ({ currentKey, provider, fromChain, toChain, }: {
|
|
45
73
|
currentKey: BridgeKey;
|
|
46
74
|
provider: Provider;
|
|
47
75
|
fromChain?: Chains;
|
|
48
76
|
toChain?: Chains;
|
|
49
77
|
}) => BridgeKey;
|
|
78
|
+
/**
|
|
79
|
+
* Returns the pathway for the given bridge key, is prod, and asset in address
|
|
80
|
+
* @param bridgeKey - the bridge key
|
|
81
|
+
* @param isProd - whether to use the production pathway
|
|
82
|
+
* @param assetInAddress - the asset in address
|
|
83
|
+
* @returns the pathway
|
|
84
|
+
*/
|
|
50
85
|
export declare const pathway: (bridgeKey: BridgeKey | null, isProd: boolean, assetInAddress?: string | Hex | null | undefined) => Pathway | undefined;
|
|
51
|
-
|
|
86
|
+
/**
|
|
87
|
+
* Returns the default asset in for the given bridge key and is prod
|
|
88
|
+
* @param bridgeKey - the bridge key
|
|
89
|
+
* @param isProd - whether to use the production pathway
|
|
90
|
+
* @returns the default asset in
|
|
91
|
+
*/
|
|
92
|
+
export declare const defaultAssetIn: ($bridgeKey: BridgeKey | null, isProd: boolean) => `0x${string}` | null | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* Returns whether the given asset is the native asset for the given bridge key
|
|
95
|
+
* @param asset - the asset
|
|
96
|
+
* @param bridgeKey - the bridge key
|
|
97
|
+
* @returns whether the given asset is the native asset for the given bridge key
|
|
98
|
+
*/
|
|
52
99
|
export declare const isNative: (asset: Token | TokenOut | null, bridgeKey: BridgeKey | null) => boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Returns whether the given asset is unwrappable for the given bridge key
|
|
102
|
+
* @param bridgeKey - the bridge key
|
|
103
|
+
* @param assetIn - the asset in
|
|
104
|
+
* @returns whether the given asset is unwrappable for the given bridge key
|
|
105
|
+
*/
|
|
53
106
|
export declare const isUnwrappable: (bridgeKey: BridgeKey | null, assetIn: Pick<Token, "address"> | null) => boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Returns whether the given asset can be unwrapped for the given bridge key
|
|
109
|
+
* @param bridgeKey - the bridge key
|
|
110
|
+
* @param assetIn - the asset in
|
|
111
|
+
* @returns boolean
|
|
112
|
+
*/
|
|
54
113
|
export declare const canChangeUnwrap: (bridgeKey: BridgeKey, assetIn: Token | null) => boolean;
|
package/dist/src/config.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { getAddress, zeroAddress } from "viem";
|
|
2
2
|
import _ from 'lodash';
|
|
3
|
-
import * as imageLinks from '@gibs/bridge-sdk/image-links';
|
|
4
3
|
/**
|
|
5
4
|
* Add here your chain id as hex, be sure to add your chain in the chainsMetadata object too
|
|
6
5
|
*/
|
|
@@ -14,14 +13,27 @@ export var Chains;
|
|
|
14
13
|
Chains["V4PLS"] = "0x3af";
|
|
15
14
|
// TBNB = '0x61',
|
|
16
15
|
})(Chains || (Chains = {}));
|
|
16
|
+
/** A map of chain ids to chain keys */
|
|
17
17
|
export const chainIdToKey = new Map(Object.entries(Chains).map(([key, chain]) => [chain, key]));
|
|
18
|
+
/**
|
|
19
|
+
* Converts a chain id to a chain key
|
|
20
|
+
* @param chainId - the chain id
|
|
21
|
+
* @returns the chain key
|
|
22
|
+
*/
|
|
18
23
|
export const toChain = (chainId) => `0x${Number(chainId).toString(16)}`;
|
|
24
|
+
/**
|
|
25
|
+
* Converts a chain id to a chain key
|
|
26
|
+
* @param chainId - the chain id
|
|
27
|
+
* @returns the chain key
|
|
28
|
+
*/
|
|
19
29
|
export const toChainKey = (chainId) => chainIdToKey.get(toChain(chainId));
|
|
30
|
+
/** The provider of an omnibridge */
|
|
20
31
|
export var Provider;
|
|
21
32
|
(function (Provider) {
|
|
22
33
|
Provider["PULSECHAIN"] = "pulsechain";
|
|
23
34
|
Provider["TOKENSEX"] = "tokensex";
|
|
24
35
|
})(Provider || (Provider = {}));
|
|
36
|
+
/** A map of chains to native asset out addresses */
|
|
25
37
|
export const nativeAssetOut = {
|
|
26
38
|
[Chains.ETH]: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
|
|
27
39
|
[Chains.BNB]: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c',
|
|
@@ -29,9 +41,11 @@ export const nativeAssetOut = {
|
|
|
29
41
|
[Chains.SEP]: '0x7b79995e5f793A07Bc00c21412e50Ecae098E7f9',
|
|
30
42
|
[Chains.V4PLS]: '0x70499adEBB11Efd915E3b69E700c331778628707',
|
|
31
43
|
};
|
|
44
|
+
/** A map of chains to deprecated native asset out addresses */
|
|
32
45
|
export const deprecatedNativeAssetOut = {
|
|
33
46
|
[Chains.PLS]: new Set(['0x97Ac4a2439A47c07ad535bb1188c989dae755341']),
|
|
34
47
|
};
|
|
48
|
+
/** A map of chains to uni v2 router addresses */
|
|
35
49
|
export const uniV2Routers = {
|
|
36
50
|
[Chains.PLS]: [
|
|
37
51
|
'0x98bf93ebf5c380C0e6Ae8e192A7e2AE08edAcc02',
|
|
@@ -45,6 +59,7 @@ export const uniV2Routers = {
|
|
|
45
59
|
'0x636f6407B90661b73b1C0F7e24F4C79f624d0738',
|
|
46
60
|
],
|
|
47
61
|
};
|
|
62
|
+
/** A map of chains to native token symbols */
|
|
48
63
|
export const nativeTokenSymbol = {
|
|
49
64
|
[Chains.PLS]: 'PLS',
|
|
50
65
|
[Chains.V4PLS]: 'V4PLS',
|
|
@@ -52,6 +67,7 @@ export const nativeTokenSymbol = {
|
|
|
52
67
|
[Chains.SEP]: 'sepETH',
|
|
53
68
|
[Chains.BNB]: 'BNB',
|
|
54
69
|
};
|
|
70
|
+
/** A map of chains to native token names */
|
|
55
71
|
export const nativeTokenName = {
|
|
56
72
|
[Chains.PLS]: 'Pulse',
|
|
57
73
|
[Chains.V4PLS]: 'V4 Pulse',
|
|
@@ -59,6 +75,7 @@ export const nativeTokenName = {
|
|
|
59
75
|
[Chains.SEP]: 'Sepolia Ether',
|
|
60
76
|
[Chains.BNB]: 'BNB',
|
|
61
77
|
};
|
|
78
|
+
/** The settings for the pulsechain pls eth pathway */
|
|
62
79
|
const pulsechainPLSETHSettings = {
|
|
63
80
|
from: '0x0e18d0d556b652794EF12Bf68B2dC857EF5f3996',
|
|
64
81
|
to: '0xe20E337DB2a00b1C37139c873B92a0AAd3F468bF',
|
|
@@ -84,21 +101,6 @@ export const pathways = {
|
|
|
84
101
|
[zeroAddress]: pulsechainPLSETHSettings,
|
|
85
102
|
[getAddress(nativeAssetOut[Chains.PLS])]: pulsechainPLSETHSettings,
|
|
86
103
|
},
|
|
87
|
-
defaultAssetIn: {
|
|
88
|
-
symbol: 'WETH',
|
|
89
|
-
name: 'Wrapped Ether from Ethereum',
|
|
90
|
-
address: '0x02DcdD04e3F455D838cd1249292C58f3B79e3C3C',
|
|
91
|
-
decimals: 18,
|
|
92
|
-
chainId: 369,
|
|
93
|
-
logoURI: imageLinks.network(369),
|
|
94
|
-
extensions: {
|
|
95
|
-
bridgeInfo: {
|
|
96
|
-
'1': {
|
|
97
|
-
tokenAddress: nativeAssetOut[Chains.ETH],
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
},
|
|
102
104
|
},
|
|
103
105
|
},
|
|
104
106
|
[Chains.ETH]: {
|
|
@@ -122,21 +124,6 @@ export const pathways = {
|
|
|
122
124
|
nativeRouter: '0x1F0144Ce3BDaf11944Fe0beF6444599a0500695B',
|
|
123
125
|
},
|
|
124
126
|
},
|
|
125
|
-
defaultAssetIn: {
|
|
126
|
-
chainId: 1,
|
|
127
|
-
address: nativeAssetOut[Chains.ETH],
|
|
128
|
-
name: 'Wrapped Ether',
|
|
129
|
-
symbol: 'WETH',
|
|
130
|
-
decimals: 18,
|
|
131
|
-
logoURI: imageLinks.network(1),
|
|
132
|
-
extensions: {
|
|
133
|
-
bridgeInfo: {
|
|
134
|
-
'369': {
|
|
135
|
-
tokenAddress: '0x02DcdD04e3F455D838cd1249292C58f3B79e3C3C',
|
|
136
|
-
},
|
|
137
|
-
},
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
127
|
},
|
|
141
128
|
},
|
|
142
129
|
},
|
|
@@ -154,21 +141,6 @@ export const pathways = {
|
|
|
154
141
|
requiresDelivery: true,
|
|
155
142
|
// wbnb from bsc on pulsechain (tokensex)
|
|
156
143
|
bridgedNativeAssetOut: '0x518076CCE3729eF1a3877EA3647a26e278e764FE',
|
|
157
|
-
defaultAssetIn: {
|
|
158
|
-
symbol: 'WBNB',
|
|
159
|
-
name: 'Wrapped BNB',
|
|
160
|
-
address: '0x518076CCE3729eF1a3877EA3647a26e278e764FE',
|
|
161
|
-
decimals: 18,
|
|
162
|
-
chainId: 369,
|
|
163
|
-
logoURI: imageLinks.network(369),
|
|
164
|
-
extensions: {
|
|
165
|
-
bridgeInfo: {
|
|
166
|
-
'56': {
|
|
167
|
-
tokenAddress: nativeAssetOut[Chains.BNB],
|
|
168
|
-
},
|
|
169
|
-
},
|
|
170
|
-
},
|
|
171
|
-
},
|
|
172
144
|
},
|
|
173
145
|
},
|
|
174
146
|
[Chains.BNB]: {
|
|
@@ -184,21 +156,6 @@ export const pathways = {
|
|
|
184
156
|
requiresDelivery: false,
|
|
185
157
|
// wpls from pulsechain on bsc (tokensex)
|
|
186
158
|
bridgedNativeAssetOut: '0xF6088134D28eeBEF7128BA41FaDb2FCA0666c64C',
|
|
187
|
-
defaultAssetIn: {
|
|
188
|
-
chainId: 56,
|
|
189
|
-
address: nativeAssetOut[Chains.BNB],
|
|
190
|
-
name: 'Wrapped BNB from BSC',
|
|
191
|
-
symbol: 'WBNB',
|
|
192
|
-
decimals: 18,
|
|
193
|
-
logoURI: imageLinks.network(56),
|
|
194
|
-
extensions: {
|
|
195
|
-
bridgeInfo: {
|
|
196
|
-
'369': {
|
|
197
|
-
tokenAddress: '0x518076CCE3729eF1a3877EA3647a26e278e764FE',
|
|
198
|
-
},
|
|
199
|
-
},
|
|
200
|
-
},
|
|
201
|
-
},
|
|
202
159
|
},
|
|
203
160
|
},
|
|
204
161
|
},
|
|
@@ -240,21 +197,6 @@ export const testnetPathways = {
|
|
|
240
197
|
toHome: false,
|
|
241
198
|
feeManager: 'from',
|
|
242
199
|
bridgedNativeAssetOut: '0x3677bd78ccf4d299328ecfba61790cf8dbfcf686',
|
|
243
|
-
defaultAssetIn: {
|
|
244
|
-
chainId: 943,
|
|
245
|
-
address: '0x3677bd78CCf4d299328ECFBa61790cf8dBfcF686',
|
|
246
|
-
name: 'Wrapped Ether from Sepolia',
|
|
247
|
-
symbol: 'WsepETH',
|
|
248
|
-
decimals: 18,
|
|
249
|
-
logoURI: imageLinks.network(943),
|
|
250
|
-
extensions: {
|
|
251
|
-
bridgeInfo: {
|
|
252
|
-
'11155111': {
|
|
253
|
-
tokenAddress: nativeAssetOut[Chains.SEP],
|
|
254
|
-
},
|
|
255
|
-
},
|
|
256
|
-
},
|
|
257
|
-
},
|
|
258
200
|
},
|
|
259
201
|
},
|
|
260
202
|
[Chains.SEP]: {
|
|
@@ -269,39 +211,35 @@ export const testnetPathways = {
|
|
|
269
211
|
toHome: true,
|
|
270
212
|
feeManager: 'to',
|
|
271
213
|
bridgedNativeAssetOut: '0x35807560aD0597E23F452cdc82D4Fb0e7E3c6590',
|
|
272
|
-
defaultAssetIn: {
|
|
273
|
-
chainId: 11_155_111,
|
|
274
|
-
address: nativeAssetOut[Chains.SEP],
|
|
275
|
-
name: 'Wrapped Ether',
|
|
276
|
-
symbol: 'sepWETH',
|
|
277
|
-
decimals: 18,
|
|
278
|
-
logoURI: imageLinks.network(11_155_111),
|
|
279
|
-
extensions: {
|
|
280
|
-
bridgeInfo: {
|
|
281
|
-
'943': {
|
|
282
|
-
tokenAddress: '0x3677bd78CCf4d299328ECFBa61790cf8dBfcF686',
|
|
283
|
-
},
|
|
284
|
-
},
|
|
285
|
-
},
|
|
286
|
-
},
|
|
287
214
|
},
|
|
288
215
|
},
|
|
289
216
|
},
|
|
290
217
|
};
|
|
218
|
+
/** The mainnet bridge keys */
|
|
291
219
|
const mainnetBridgeKeys = [
|
|
292
220
|
[Provider.PULSECHAIN, Chains.PLS, Chains.ETH],
|
|
293
221
|
[Provider.PULSECHAIN, Chains.ETH, Chains.PLS],
|
|
294
222
|
[Provider.TOKENSEX, Chains.PLS, Chains.BNB],
|
|
295
223
|
[Provider.TOKENSEX, Chains.BNB, Chains.PLS],
|
|
296
224
|
];
|
|
225
|
+
/** The testnet bridge keys */
|
|
297
226
|
const testnetBridgeKeys = [
|
|
298
227
|
[Provider.PULSECHAIN, Chains.SEP, Chains.V4PLS],
|
|
299
228
|
[Provider.PULSECHAIN, Chains.V4PLS, Chains.SEP],
|
|
300
229
|
];
|
|
230
|
+
/** Returns the valid bridge keys for the given is prod */
|
|
301
231
|
export const validBridgeKeys = (isProd) => [
|
|
302
232
|
...mainnetBridgeKeys,
|
|
303
233
|
...(isProd ? [] : testnetBridgeKeys),
|
|
304
234
|
];
|
|
235
|
+
/**
|
|
236
|
+
* Infers the bridge key from the current key, provider, from chain, and to chain
|
|
237
|
+
* @param currentKey - the current bridge key
|
|
238
|
+
* @param provider - the provider
|
|
239
|
+
* @param fromChain - the from chain
|
|
240
|
+
* @param toChain - the to chain
|
|
241
|
+
* @returns the inferred bridge key
|
|
242
|
+
*/
|
|
305
243
|
export const inferBridgeKey = ({ currentKey, provider, fromChain, toChain, }) => {
|
|
306
244
|
const [, fromChainKey, toChainKey] = currentKey;
|
|
307
245
|
const from = fromChain ?? fromChainKey;
|
|
@@ -316,6 +254,13 @@ export const inferBridgeKey = ({ currentKey, provider, fromChain, toChain, }) =>
|
|
|
316
254
|
: Object.keys(pathways[provider][nextFromChain])[0];
|
|
317
255
|
return [provider, nextFromChain, nextToChain];
|
|
318
256
|
};
|
|
257
|
+
/**
|
|
258
|
+
* Returns the pathway for the given bridge key, is prod, and asset in address
|
|
259
|
+
* @param bridgeKey - the bridge key
|
|
260
|
+
* @param isProd - whether to use the production pathway
|
|
261
|
+
* @param assetInAddress - the asset in address
|
|
262
|
+
* @returns the pathway
|
|
263
|
+
*/
|
|
319
264
|
export const pathway = (bridgeKey, isProd, assetInAddress) => {
|
|
320
265
|
if (!bridgeKey)
|
|
321
266
|
return;
|
|
@@ -331,11 +276,25 @@ export const pathway = (bridgeKey, isProd, assetInAddress) => {
|
|
|
331
276
|
}
|
|
332
277
|
return pathway;
|
|
333
278
|
};
|
|
279
|
+
/**
|
|
280
|
+
* Returns the default asset in for the given bridge key and is prod
|
|
281
|
+
* @param bridgeKey - the bridge key
|
|
282
|
+
* @param isProd - whether to use the production pathway
|
|
283
|
+
* @returns the default asset in
|
|
284
|
+
*/
|
|
334
285
|
export const defaultAssetIn = ($bridgeKey, isProd) => {
|
|
286
|
+
if (!$bridgeKey)
|
|
287
|
+
return null;
|
|
335
288
|
const conf = pathway($bridgeKey, isProd);
|
|
336
|
-
const defaultAssetIn = _.get(conf, ['
|
|
289
|
+
const defaultAssetIn = _.get(conf, ['bridgedNativeAssetOut']);
|
|
337
290
|
return defaultAssetIn;
|
|
338
291
|
};
|
|
292
|
+
/**
|
|
293
|
+
* Returns whether the given asset is the native asset for the given bridge key
|
|
294
|
+
* @param asset - the asset
|
|
295
|
+
* @param bridgeKey - the bridge key
|
|
296
|
+
* @returns whether the given asset is the native asset for the given bridge key
|
|
297
|
+
*/
|
|
339
298
|
export const isNative = (asset, bridgeKey) => {
|
|
340
299
|
if (!bridgeKey || !asset) {
|
|
341
300
|
return false;
|
|
@@ -346,6 +305,12 @@ export const isNative = (asset, bridgeKey) => {
|
|
|
346
305
|
nativeAssetOut[toChain(asset.chainId)]?.toLowerCase() === asset.address?.toLowerCase()) &&
|
|
347
306
|
!asset.name.includes(' from Pulsechain'));
|
|
348
307
|
};
|
|
308
|
+
/**
|
|
309
|
+
* Returns whether the given asset is unwrappable for the given bridge key
|
|
310
|
+
* @param bridgeKey - the bridge key
|
|
311
|
+
* @param assetIn - the asset in
|
|
312
|
+
* @returns whether the given asset is unwrappable for the given bridge key
|
|
313
|
+
*/
|
|
349
314
|
export const isUnwrappable = (bridgeKey, assetIn) => {
|
|
350
315
|
if (!bridgeKey || !assetIn) {
|
|
351
316
|
return false;
|
|
@@ -356,6 +321,12 @@ export const isUnwrappable = (bridgeKey, assetIn) => {
|
|
|
356
321
|
return false;
|
|
357
322
|
return path.bridgedNativeAssetOut === getAddress(addr);
|
|
358
323
|
};
|
|
324
|
+
/**
|
|
325
|
+
* Returns whether the given asset can be unwrapped for the given bridge key
|
|
326
|
+
* @param bridgeKey - the bridge key
|
|
327
|
+
* @param assetIn - the asset in
|
|
328
|
+
* @returns boolean
|
|
329
|
+
*/
|
|
359
330
|
export const canChangeUnwrap = (bridgeKey, assetIn) => {
|
|
360
331
|
return !!assetIn && isUnwrappable(bridgeKey, assetIn);
|
|
361
332
|
};
|
package/dist/src/fee-type.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
/** The type of fee to use for the bridge */
|
|
1
2
|
export declare enum FeeType {
|
|
2
3
|
PERCENT = "%",
|
|
3
4
|
GAS_TIP = "gas+%",
|
|
4
5
|
FIXED = "fixed"
|
|
5
6
|
}
|
|
7
|
+
/** The keys of the fee type */
|
|
6
8
|
export type FeeTypeKeys = keyof typeof FeeType;
|
|
9
|
+
/** A map of fee type values to keys */
|
|
7
10
|
export declare const feeTypeValToKeyMap: Map<FeeType, "PERCENT" | "GAS_TIP" | "FIXED">;
|
package/dist/src/fee-type.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
/** The type of fee to use for the bridge */
|
|
1
2
|
export var FeeType;
|
|
2
3
|
(function (FeeType) {
|
|
3
4
|
FeeType["PERCENT"] = "%";
|
|
4
5
|
FeeType["GAS_TIP"] = "gas+%";
|
|
5
6
|
FeeType["FIXED"] = "fixed";
|
|
6
7
|
})(FeeType || (FeeType = {}));
|
|
8
|
+
/** A map of fee type values to keys */
|
|
7
9
|
export const feeTypeValToKeyMap = new Map(Object.keys(FeeType).map((key) => [FeeType[key], key]));
|