@snowbridge/base-types 1.0.5 → 1.0.6

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/src/index.ts CHANGED
@@ -1,8 +1,19 @@
1
+ export type BridgeInfo = {
2
+ environment: Environment;
3
+ routes: readonly TransferRoute[];
4
+ registry: AssetRegistry;
5
+ chains: ChainMap;
6
+ };
7
+
1
8
  export type AccountType = "AccountId20" | "AccountId32";
2
9
 
3
- export interface XC20TokenMap {
4
- [xc20: string]: string;
5
- }
10
+ export type XcmVersion = "v4" | "v5";
11
+
12
+ export type EthereumKind = "ethereum" | "ethereum_l2";
13
+ export type ParachainKind = "polkadot" | "kusama";
14
+ export type ChainKind = EthereumKind | ParachainKind;
15
+
16
+ export type XC20TokenMap = Record<string, string>;
6
17
 
7
18
  export type ERC20Metadata = {
8
19
  token: string;
@@ -12,15 +23,18 @@ export type ERC20Metadata = {
12
23
  foreignId?: string;
13
24
  // The gas cost of a local transfer, which involves unlocking for ENA and minting for PNA.
14
25
  deliveryGas?: bigint;
26
+ // For ERC-20 tokens on L2 chains that have a corresponding mapped L1 token address.
27
+ swapTokenAddress?: string;
28
+ // fee tier for uniswap call in basis points (e.g., 500 = 0.05%)
29
+ swapFee?: number;
15
30
  };
16
31
 
17
- export interface ERC20MetadataMap {
18
- [token: string]: ERC20Metadata;
19
- }
32
+ export type ERC20MetadataMap = Record<string, ERC20Metadata>;
20
33
 
21
- export type EthereumChain = {
22
- chainId: number;
23
- id: string;
34
+ export type EthereumChain = ChainId & {
35
+ kind: EthereumKind;
36
+ key: `${EthereumKind}_${number}`;
37
+ name?: string;
24
38
  evmParachainId?: number;
25
39
  assets: ERC20MetadataMap;
26
40
  precompile?: `0x${string}`;
@@ -64,12 +78,11 @@ export type Asset = {
64
78
  foreignId?: string;
65
79
  };
66
80
 
67
- export interface AssetMap {
68
- [token: string]: Asset;
69
- }
81
+ export type AssetMap = Record<string, Asset>;
70
82
 
71
- export type Parachain = {
72
- parachainId: number;
83
+ export type Parachain = ChainId & {
84
+ kind: ParachainKind;
85
+ key: `${ParachainKind}_${number}`;
73
86
  info: ChainProperties;
74
87
  features: {
75
88
  hasPalletXcm: boolean;
@@ -77,6 +90,12 @@ export type Parachain = {
77
90
  hasTxPaymentApi: boolean;
78
91
  hasDryRunRpc: boolean;
79
92
  hasDotBalance: boolean;
93
+ hasEthBalance: boolean;
94
+ hasXcmPaymentApi: boolean;
95
+ supportsAliasOrigin: boolean;
96
+ xcmVersion: XcmVersion;
97
+ /** @deprecated Remove once V2 is fully rolled out to all parachains */
98
+ supportsV2: boolean;
80
99
  };
81
100
  assets: AssetMap;
82
101
  estimatedExecutionFeeDOT: bigint;
@@ -84,9 +103,12 @@ export type Parachain = {
84
103
  xcDOT?: string;
85
104
  };
86
105
 
87
- export interface ParachainMap {
88
- [paraId: string]: Parachain;
89
- }
106
+ export type EthereumChainMap = Record<ChainKey<EthereumKind>, EthereumChain>;
107
+ export type ParachainMap = Record<ChainKey<ParachainKind>, Parachain>;
108
+ export type ChainRef = ChainId & {
109
+ key: ChainKey<ChainKind>;
110
+ };
111
+ export type ChainMap = Record<string, ChainRef>;
90
112
 
91
113
  export type KusamaConfig = {
92
114
  assetHubParaId: number;
@@ -94,6 +116,110 @@ export type KusamaConfig = {
94
116
  parachains: ParachainMap;
95
117
  };
96
118
 
119
+ export type Environment = {
120
+ name: string;
121
+ // Ethereum
122
+ ethChainId: number;
123
+ gatewayContract: string;
124
+ beefyContract: string;
125
+ beaconApiUrl: string;
126
+ ethereumChains: Record<string, string>;
127
+ // Substrate
128
+ assetHubParaId: number;
129
+ bridgeHubParaId: number;
130
+ /** @deprecated Remove once V2 is fully rolled out to all parachains */
131
+ v2_parachains?: readonly number[];
132
+ relaychainUrl: string;
133
+ parachains: {
134
+ [paraId: string]: string;
135
+ };
136
+ // Indexer
137
+ indexerGraphQlUrl: string;
138
+ kusama?: {
139
+ assetHubParaId: number;
140
+ bridgeHubParaId: number;
141
+ parachains: Record<string, string>;
142
+ };
143
+ // Assets
144
+ assetOverrides?: AssetOverrideMap;
145
+ precompiles?: PrecompileMap;
146
+ metadataOverrides?: ERC20MetadataOverrideMap;
147
+ // L2 Forwarding
148
+ l2Bridge?: {
149
+ acrossAPIUrl: string;
150
+ l1AdapterAddress: string;
151
+ l1HandlerAddress: string;
152
+ l1FeeTokenAddress: string;
153
+ l1SwapRouterAddress: string;
154
+ l1SwapQuoterAddress: string;
155
+ l2Chains: Record<number, L2ForwardMetadata>;
156
+ };
157
+ };
158
+
159
+ export type ChainId = {
160
+ kind: ChainKind;
161
+ /** Ethereum chain id or polkadot parachain id.
162
+ */
163
+ id: number;
164
+ };
165
+
166
+ export type TransferRoute = {
167
+ from: ChainId;
168
+ to: ChainId;
169
+ assets: readonly string[];
170
+ };
171
+
172
+ export type TransferKind =
173
+ | "polkadot->polkadot"
174
+ | "kusama->polkadot"
175
+ | "polkadot->kusama"
176
+ | "polkadot->ethereum"
177
+ | "ethereum->polkadot"
178
+ | "ethereum->ethereum"
179
+ | "polkadot->ethereum_l2"
180
+ | "ethereum_l2->polkadot";
181
+
182
+ export type ChainKey<T extends string> = `${T}_${number}`;
183
+
184
+ export type Source = ChainId & {
185
+ key: ChainKey<ChainKind>;
186
+ destinations: Record<
187
+ ChainKey<ChainKind>,
188
+ ChainId & {
189
+ key: ChainKey<ChainKind>;
190
+ assets: string[];
191
+ }
192
+ >;
193
+ };
194
+
195
+ export type TransferLocation = ParachainLocation | EthereumLocation;
196
+
197
+ export type ParachainLocation = ChainId & {
198
+ kind: ParachainKind;
199
+ key: ChainKey<ParachainKind>;
200
+ parachain: Parachain;
201
+ };
202
+
203
+ export type EthereumLocation = ChainId & {
204
+ kind: EthereumKind;
205
+ key: ChainKey<EthereumKind>;
206
+ ethChain: EthereumChain;
207
+ parachain?: Parachain;
208
+ };
209
+
210
+ export type AssetOverrideMap = Record<string, Asset[]>;
211
+
212
+ export type ERC20MetadataOverrideMap = Record<
213
+ string,
214
+ {
215
+ name?: string;
216
+ symbol?: string;
217
+ decimals?: number;
218
+ }
219
+ >;
220
+
221
+ export type PrecompileMap = Record<string, `0x${string}`>;
222
+
97
223
  export type AssetRegistry = {
98
224
  timestamp: string;
99
225
  environment: string;
@@ -103,9 +229,78 @@ export type AssetRegistry = {
103
229
  bridgeHubParaId: number;
104
230
  relaychain: ChainProperties;
105
231
  bridgeHub: ChainProperties;
106
- ethereumChains: {
107
- [chainId: string]: EthereumChain;
108
- };
232
+ ethereumChains: EthereumChainMap;
109
233
  parachains: ParachainMap;
110
- kusama: KusamaConfig | undefined;
234
+ kusama?: KusamaConfig;
235
+ };
236
+
237
+ export type {
238
+ EthereumProvider,
239
+ EthereumProviderTypes,
240
+ FeeData,
241
+ GatewayV1OutboundMessageAccepted,
242
+ GatewayV2OutboundMessageAccepted,
243
+ L1AdapterDepositParams,
244
+ L1LegacySwapRouterExactOutputSingleParams,
245
+ L1SwapRouterExactOutputSingleParams,
246
+ MultiAddressStruct,
247
+ } from "./provider";
248
+
249
+ export type ContractCall = {
250
+ target: string;
251
+ calldata: string;
252
+ value: bigint;
253
+ gas: bigint;
111
254
  };
255
+
256
+ export type SubstrateAccount = {
257
+ nonce: bigint;
258
+ consumers: bigint;
259
+ providers: bigint;
260
+ sufficients: bigint;
261
+ data: {
262
+ free: bigint;
263
+ reserved: bigint;
264
+ frozen: bigint;
265
+ transferable: bigint;
266
+ total: bigint;
267
+ };
268
+ };
269
+
270
+ export type PNAMap = Record<
271
+ string,
272
+ {
273
+ token: string;
274
+ foreignId: string;
275
+ ethereumlocation: any;
276
+ }
277
+ >;
278
+
279
+ export type AssetSwapRoute = {
280
+ inputToken: string;
281
+ outputToken: string;
282
+ swapFee: number; // fee tier for uniswap call in basis points (e.g., 500 = 0.05%)
283
+ };
284
+
285
+ export type L2ForwardMetadata = {
286
+ adapterAddress: string;
287
+ feeTokenAddress: string;
288
+ swapRoutes: readonly AssetSwapRoute[];
289
+ };
290
+
291
+ export type FeeEstimateErrorDetails = {
292
+ type: string;
293
+ code: string;
294
+ status: number;
295
+ message: string;
296
+ id: string;
297
+ };
298
+ export class FeeEstimateError extends Error {
299
+ readonly details: FeeEstimateErrorDetails;
300
+ constructor(details: FeeEstimateErrorDetails) {
301
+ super(details.message);
302
+ this.details = details;
303
+ }
304
+ }
305
+
306
+ export * from "./contracts";
@@ -0,0 +1,228 @@
1
+ import type {
2
+ DepositParamsStruct,
3
+ IGatewayV1,
4
+ IGatewayV2,
5
+ SendParamsStruct,
6
+ SwapParamsStruct,
7
+ } from "./contracts";
8
+
9
+ export type MultiAddressStruct = {
10
+ kind: number;
11
+ data: string;
12
+ };
13
+
14
+ export type GatewayV1OutboundMessageAccepted = {
15
+ channelId: string;
16
+ nonce: bigint;
17
+ messageId: string;
18
+ blockNumber: number;
19
+ blockHash: string;
20
+ txHash: string;
21
+ txIndex: number;
22
+ };
23
+
24
+ export type GatewayV2OutboundMessageAccepted = {
25
+ nonce: bigint;
26
+ payload: {
27
+ origin: string;
28
+ assets: [number, string][];
29
+ xcm: [number, string];
30
+ claimer: string;
31
+ value: bigint;
32
+ executionFee: bigint;
33
+ relayerFee: bigint;
34
+ };
35
+ blockNumber: number;
36
+ blockHash: string;
37
+ txHash: string;
38
+ txIndex: number;
39
+ };
40
+
41
+ export type FeeData = {
42
+ gasPrice: bigint | null;
43
+ maxFeePerGas: bigint | null;
44
+ maxPriorityFeePerGas: bigint | null;
45
+ };
46
+
47
+ export type EncodedMultiAddress = MultiAddressStruct;
48
+
49
+ export type L1AdapterDepositParams = {
50
+ inputToken: string;
51
+ outputToken: string;
52
+ inputAmount: bigint;
53
+ outputAmount: bigint;
54
+ destinationChainId: number;
55
+ fillDeadlineBuffer: bigint;
56
+ };
57
+
58
+ export type L1SwapRouterExactOutputSingleParams = {
59
+ tokenIn: string;
60
+ tokenOut: string;
61
+ fee: bigint;
62
+ recipient: string;
63
+ deadline: bigint;
64
+ amountOut: bigint;
65
+ amountInMaximum: bigint;
66
+ sqrtPriceLimitX96: bigint;
67
+ };
68
+
69
+ export type L1LegacySwapRouterExactOutputSingleParams = {
70
+ tokenIn: string;
71
+ tokenOut: string;
72
+ fee: bigint;
73
+ recipient: string;
74
+ amountOut: bigint;
75
+ amountInMaximum: bigint;
76
+ sqrtPriceLimitX96: bigint;
77
+ };
78
+
79
+ export interface EthereumProviderTypes {
80
+ Connection: unknown;
81
+ Contract: unknown;
82
+ Abi: unknown;
83
+ TransactionReceipt: unknown;
84
+ ContractTransaction: unknown;
85
+ }
86
+
87
+ export interface EthereumProvider<T extends EthereumProviderTypes> {
88
+ readonly providerTypes: T;
89
+ createProvider(url: string): T["Connection"];
90
+ destroyProvider(provider: T["Connection"]): void;
91
+ destroyContract(contract: T["Contract"]): Promise<void>;
92
+ connectContract(
93
+ address: string,
94
+ abi: T["Abi"],
95
+ provider: T["Connection"],
96
+ ): T["Contract"];
97
+ erc20Balance(
98
+ provider: T["Connection"],
99
+ tokenAddress: string,
100
+ owner: string,
101
+ spender: string,
102
+ ): Promise<{ balance: bigint; gatewayAllowance: bigint }>;
103
+ encodeFunctionData(
104
+ abi: T["Abi"],
105
+ method: string,
106
+ args: readonly unknown[],
107
+ ): string;
108
+ decodeFunctionResult<U = unknown>(
109
+ abi: T["Abi"],
110
+ method: string,
111
+ data: string,
112
+ ): U;
113
+ encodeNativeAsset(tokenAddress: string, amount: bigint): string;
114
+ l1AdapterDepositNativeEther(
115
+ params: L1AdapterDepositParams,
116
+ recipient: string,
117
+ topic: string,
118
+ ): string;
119
+ l1AdapterDepositToken(
120
+ params: L1AdapterDepositParams,
121
+ recipient: string,
122
+ topic: string,
123
+ ): string;
124
+ l1SwapRouterExactOutputSingle(
125
+ params: L1SwapRouterExactOutputSingleParams,
126
+ ): string;
127
+ l1LegacySwapRouterExactOutputSingle(
128
+ params: L1LegacySwapRouterExactOutputSingleParams,
129
+ ): string;
130
+ beneficiaryMultiAddress(beneficiary: string): MultiAddressStruct;
131
+ estimateGas(
132
+ provider: T["Connection"],
133
+ tx: T["ContractTransaction"],
134
+ ): Promise<bigint>;
135
+ getTransactionCount(
136
+ provider: T["Connection"],
137
+ address: string,
138
+ blockTag?: "latest" | "pending",
139
+ ): Promise<number>;
140
+ gatewayV1SendToken(
141
+ provider: T["Connection"],
142
+ gatewayAddress: string,
143
+ sender: string,
144
+ token: string,
145
+ destinationChain: number,
146
+ destinationAddress: MultiAddressStruct,
147
+ destinationFee: bigint,
148
+ amount: bigint,
149
+ value: bigint,
150
+ ): Promise<T["ContractTransaction"]>;
151
+ gatewayV2RegisterToken(
152
+ provider: T["Connection"],
153
+ gatewayAddress: string,
154
+ sender: string,
155
+ token: string,
156
+ network: number,
157
+ executionFee: bigint,
158
+ relayerFee: bigint,
159
+ value: bigint,
160
+ ): Promise<T["ContractTransaction"]>;
161
+ gatewayV2CreateAgent(
162
+ provider: T["Connection"],
163
+ gatewayAddress: string,
164
+ id: string,
165
+ ): Promise<T["ContractTransaction"]>;
166
+ gatewayV2SendMessage(
167
+ provider: T["Connection"],
168
+ gatewayAddress: string,
169
+ sender: string,
170
+ xcm: Uint8Array,
171
+ assets: string[],
172
+ claimer: Uint8Array,
173
+ executionFee: bigint,
174
+ relayerFee: bigint,
175
+ value: bigint,
176
+ ): Promise<T["ContractTransaction"]>;
177
+ l2AdapterSendEtherAndCall(
178
+ provider: T["Connection"],
179
+ adapterAddress: string,
180
+ sender: string,
181
+ params: DepositParamsStruct,
182
+ sendParams: SendParamsStruct,
183
+ recipient: string,
184
+ topic: string,
185
+ value?: bigint,
186
+ ): Promise<T["ContractTransaction"]>;
187
+ l2AdapterSendTokenAndCall(
188
+ provider: T["Connection"],
189
+ adapterAddress: string,
190
+ sender: string,
191
+ params: DepositParamsStruct,
192
+ swapParams: SwapParamsStruct,
193
+ sendParams: SendParamsStruct,
194
+ recipient: string,
195
+ topic: string,
196
+ ): Promise<T["ContractTransaction"]>;
197
+ evmParachainTransferAssetsUsingTypeAndThenAddress(
198
+ provider: T["Connection"],
199
+ precompileAddress: string,
200
+ sourceAccount: string,
201
+ destination: [number, string[]],
202
+ assets: [string, bigint][],
203
+ assetsTransferType: number,
204
+ remoteFeesIdIndex: number,
205
+ feesTransferType: number,
206
+ customXcmHex: string,
207
+ ): Promise<T["ContractTransaction"]>;
208
+ getBalance(provider: T["Connection"], address: string): Promise<bigint>;
209
+ getFeeData(provider: T["Connection"]): Promise<FeeData>;
210
+ parseUnits(value: string, decimals: number): bigint;
211
+ gatewayOperatingMode(
212
+ gateway: T["Contract"] & (IGatewayV1 | IGatewayV2),
213
+ ): Promise<bigint>;
214
+ gatewayChannelOperatingModeOf(
215
+ gateway: T["Contract"] & IGatewayV1,
216
+ channelId: string,
217
+ ): Promise<bigint>;
218
+ isContractAddress(
219
+ provider: T["Connection"],
220
+ address: string,
221
+ ): Promise<boolean>;
222
+ scanGatewayV1OutboundMessageAccepted(
223
+ receipt: T["TransactionReceipt"],
224
+ ): GatewayV1OutboundMessageAccepted | null;
225
+ scanGatewayV2OutboundMessageAccepted(
226
+ receipt: T["TransactionReceipt"],
227
+ ): GatewayV2OutboundMessageAccepted | null;
228
+ }