@gala-chain/launchpad-sdk 4.0.6 → 4.0.7-beta.10

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.
Files changed (55) hide show
  1. package/README.md +174 -4
  2. package/dist/index.cjs.js +1 -1
  3. package/dist/index.d.ts +3 -1
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.esm.js +1 -1
  6. package/dist/index.js +1 -1
  7. package/dist/src/LaunchpadSDK.d.ts +214 -1
  8. package/dist/src/LaunchpadSDK.d.ts.map +1 -1
  9. package/dist/src/bridge/BridgeService.d.ts +364 -0
  10. package/dist/src/bridge/BridgeService.d.ts.map +1 -0
  11. package/dist/src/bridge/GalaConnectClient.d.ts +164 -0
  12. package/dist/src/bridge/GalaConnectClient.d.ts.map +1 -0
  13. package/dist/src/bridge/constants/index.d.ts +7 -0
  14. package/dist/src/bridge/constants/index.d.ts.map +1 -0
  15. package/dist/src/bridge/constants/tokens.d.ts +181 -0
  16. package/dist/src/bridge/constants/tokens.d.ts.map +1 -0
  17. package/dist/src/bridge/index.d.ts +22 -0
  18. package/dist/src/bridge/index.d.ts.map +1 -0
  19. package/dist/src/bridge/strategies/BridgeStrategy.d.ts +160 -0
  20. package/dist/src/bridge/strategies/BridgeStrategy.d.ts.map +1 -0
  21. package/dist/src/bridge/strategies/EthereumBridgeStrategy.d.ts +198 -0
  22. package/dist/src/bridge/strategies/EthereumBridgeStrategy.d.ts.map +1 -0
  23. package/dist/src/bridge/strategies/SolanaBridgeStrategy.d.ts +207 -0
  24. package/dist/src/bridge/strategies/SolanaBridgeStrategy.d.ts.map +1 -0
  25. package/dist/src/bridge/strategies/index.d.ts +9 -0
  26. package/dist/src/bridge/strategies/index.d.ts.map +1 -0
  27. package/dist/src/bridge/types/bridge.dto.d.ts +618 -0
  28. package/dist/src/bridge/types/bridge.dto.d.ts.map +1 -0
  29. package/dist/src/bridge/types/eip712.d.ts +57 -0
  30. package/dist/src/bridge/types/eip712.d.ts.map +1 -0
  31. package/dist/src/bridge/types/index.d.ts +8 -0
  32. package/dist/src/bridge/types/index.d.ts.map +1 -0
  33. package/dist/src/bridge/utils/RateLimiter.d.ts +34 -0
  34. package/dist/src/bridge/utils/RateLimiter.d.ts.map +1 -0
  35. package/dist/src/bridge/utils/index.d.ts +9 -0
  36. package/dist/src/bridge/utils/index.d.ts.map +1 -0
  37. package/dist/src/bridge/utils/retry.d.ts +96 -0
  38. package/dist/src/bridge/utils/retry.d.ts.map +1 -0
  39. package/dist/src/bridge/utils/tokenMath.d.ts +39 -0
  40. package/dist/src/bridge/utils/tokenMath.d.ts.map +1 -0
  41. package/dist/src/constants/version.generated.d.ts +1 -1
  42. package/dist/src/constants/version.generated.d.ts.map +1 -1
  43. package/dist/src/index.d.ts +3 -1
  44. package/dist/src/index.d.ts.map +1 -1
  45. package/dist/src/services/DexBackendClient.d.ts +51 -1
  46. package/dist/src/services/DexBackendClient.d.ts.map +1 -1
  47. package/dist/src/services/GSwapService.d.ts +62 -8
  48. package/dist/src/services/GSwapService.d.ts.map +1 -1
  49. package/dist/src/types/galachain-api.types.d.ts +28 -0
  50. package/dist/src/types/galachain-api.types.d.ts.map +1 -1
  51. package/dist/src/types/gswap.dto.d.ts +43 -4
  52. package/dist/src/types/gswap.dto.d.ts.map +1 -1
  53. package/dist/src/utils/validation-helpers.d.ts +9 -1
  54. package/dist/src/utils/validation-helpers.d.ts.map +1 -1
  55. package/package.json +19 -2
@@ -0,0 +1,181 @@
1
+ /**
2
+ * Bridge Token Constants
3
+ *
4
+ * Static token configurations and chain IDs for bridging.
5
+ */
6
+ import type { EthereumTokenConfig, SolanaTokenConfig, TokenMetadata, BridgeTokenDescriptor } from '../types/bridge.dto.js';
7
+ /**
8
+ * Chain IDs used by the bridge system
9
+ */
10
+ export declare const CHAIN_IDS: {
11
+ readonly GALA_CHAIN: 1;
12
+ readonly ETHEREUM: 2;
13
+ readonly SOLANA: 1002;
14
+ };
15
+ /**
16
+ * Rate limit for GalaConnect API (requests per second)
17
+ */
18
+ export declare const DEFAULT_RATE_LIMIT_RPS = 12;
19
+ /**
20
+ * Default polling interval for bridge status (15 seconds)
21
+ */
22
+ export declare const DEFAULT_POLL_INTERVAL_MS = 15000;
23
+ /**
24
+ * Default polling timeout (45 minutes)
25
+ */
26
+ export declare const DEFAULT_POLL_TIMEOUT_MS: number;
27
+ /**
28
+ * Delay before registering inbound bridge transactions (30 seconds)
29
+ */
30
+ export declare const REGISTRATION_DELAY_MS = 30000;
31
+ /**
32
+ * Solana compute budget settings
33
+ */
34
+ export declare const SOLANA_COMPUTE: {
35
+ readonly UNIT_LIMIT: 200000;
36
+ readonly UNIT_PRICE_MICROLAMPORTS: 375000;
37
+ };
38
+ /**
39
+ * Default Ethereum RPC URL (public endpoint)
40
+ *
41
+ * **WARNING: Public RPC Endpoint Limitations**
42
+ *
43
+ * This is a free public endpoint with the following limitations:
44
+ * - **Rate Limits**: Typically 10-25 requests/second (varies by provider load)
45
+ * - **Reliability**: No SLA, may experience downtime during high network activity
46
+ * - **Privacy**: Requests may be logged by the provider
47
+ * - **Features**: May not support all RPC methods (e.g., trace_* calls)
48
+ * - **Monitoring**: No error tracking, request analytics, or debugging tools available
49
+ *
50
+ * **For Production Use**, provide your own RPC URL from:
51
+ * - Infura: https://infura.io (free tier: 100k requests/day)
52
+ * - Alchemy: https://alchemy.com (free tier: 300M compute units/month)
53
+ * - QuickNode: https://quicknode.com
54
+ * - Your own Ethereum node
55
+ *
56
+ * @example
57
+ * ```typescript
58
+ * const bridgeService = new BridgeService({
59
+ * ethereumRpcUrl: 'https://mainnet.infura.io/v3/YOUR_API_KEY',
60
+ * // ... other config
61
+ * });
62
+ * ```
63
+ */
64
+ export declare const DEFAULT_ETHEREUM_RPC_URL = "https://ethereum.publicnode.com";
65
+ /**
66
+ * Default Solana RPC URL (public endpoint)
67
+ *
68
+ * **WARNING: Public RPC Endpoint Limitations**
69
+ *
70
+ * This is the official Solana public RPC with the following limitations:
71
+ * - **Rate Limits**: Aggressive rate limiting (may return 429 errors under load)
72
+ * - **Reliability**: Best-effort availability, no SLA
73
+ * - **Performance**: Higher latency than dedicated endpoints
74
+ * - **Features**: Some methods may be disabled or limited
75
+ * - **Monitoring**: No error tracking, request analytics, or debugging tools available
76
+ *
77
+ * **For Production Use**, provide your own RPC URL from:
78
+ * - Helius: https://helius.dev (free tier: 500k credits/month)
79
+ * - QuickNode: https://quicknode.com
80
+ * - Triton: https://triton.one
81
+ * - Your own Solana validator
82
+ *
83
+ * @example
84
+ * ```typescript
85
+ * const bridgeService = new BridgeService({
86
+ * solanaRpcUrl: 'https://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY',
87
+ * // ... other config
88
+ * });
89
+ * ```
90
+ */
91
+ export declare const DEFAULT_SOLANA_RPC_URL = "https://api.mainnet-beta.solana.com";
92
+ /**
93
+ * Default Ethereum bridge contract address (mainnet)
94
+ */
95
+ export declare const DEFAULT_ETHEREUM_BRIDGE_CONTRACT = "0x9f452b7cC24e6e6FA690fe77CF5dD2ba3DbF1ED9";
96
+ /**
97
+ * Ethereum bridge contract address for Sepolia testnet
98
+ */
99
+ export declare const ETHEREUM_BRIDGE_CONTRACT_SEPOLIA = "0x6a1734E09f3099a3675645D214ce547080ea67e0";
100
+ /**
101
+ * Default Solana bridge program ID (mainnet)
102
+ */
103
+ export declare const DEFAULT_SOLANA_BRIDGE_PROGRAM = "AaE4dTnL75XqgUJpdxBKg6vS9sTJgBPJwBQRVhD29WwS";
104
+ /**
105
+ * GalaConnect production base URL (DEX API platform)
106
+ */
107
+ export declare const GALACONNECT_PRODUCTION_URL = "https://dex-api-platform-dex-prod-gala.gala.com";
108
+ /**
109
+ * Ethereum tokens for bridging - Production (Mainnet)
110
+ */
111
+ export declare const ETHEREUM_TOKENS_PROD: EthereumTokenConfig[];
112
+ /**
113
+ * Ethereum tokens for bridging - Stage (Sepolia testnet)
114
+ *
115
+ * Note: GWTRX is not available on Sepolia
116
+ */
117
+ export declare const ETHEREUM_TOKENS_STAGE: EthereumTokenConfig[];
118
+ /** Bridge environment type for token selection */
119
+ export type BridgeEnvironment = 'PROD' | 'STAGE';
120
+ /**
121
+ * Get Ethereum tokens by environment
122
+ *
123
+ * @param environment - Target environment (PROD or STAGE)
124
+ * @returns Token configurations for the specified environment
125
+ */
126
+ export declare function getEthereumTokensByEnvironment(environment: BridgeEnvironment): EthereumTokenConfig[];
127
+ /**
128
+ * Get Ethereum bridge contract address by environment
129
+ *
130
+ * @param environment - Target environment (PROD or STAGE)
131
+ * @returns Bridge contract address for the specified environment
132
+ */
133
+ export declare function getEthereumBridgeContractByEnvironment(environment: BridgeEnvironment): string;
134
+ /**
135
+ * Default supported Ethereum tokens for bridging (Production/Mainnet)
136
+ *
137
+ * @deprecated Use `getEthereumTokensByEnvironment()` for environment-aware token selection
138
+ */
139
+ export declare const DEFAULT_ETHEREUM_TOKENS: EthereumTokenConfig[];
140
+ /**
141
+ * Default supported Solana tokens for bridging
142
+ */
143
+ export declare const DEFAULT_SOLANA_TOKENS: SolanaTokenConfig[];
144
+ /**
145
+ * Static token metadata for common bridge tokens
146
+ *
147
+ * This avoids API calls for well-known tokens.
148
+ */
149
+ export declare const STATIC_TOKEN_METADATA: Record<string, TokenMetadata>;
150
+ /**
151
+ * Ethereum ERC-20 ABI for bridge operations
152
+ */
153
+ export declare const ERC20_ABI: readonly ["function decimals() view returns (uint8)", "function balanceOf(address owner) view returns (uint256)", "function approve(address spender, uint256 value) returns (bool)", "function allowance(address owner, address spender) view returns (uint256)", "function transfer(address to, uint256 value) returns (bool)", "function name() view returns (string)", "function nonces(address owner) view returns (uint256)", "function permit(address owner,address spender,uint256 value,uint256 deadline,uint8 v,bytes32 r,bytes32 s)"];
154
+ /**
155
+ * Ethereum bridge contract ABI
156
+ */
157
+ export declare const BRIDGE_CONTRACT_ABI: readonly ["function bridgeOut(address token,uint256 amount,uint256 tokenId,uint16 destinationChainId,bytes recipient) external", "function bridgeOutWithPermit(address token,uint256 amount,uint16 destinationChainId,bytes recipient,uint256 deadline,uint8 v,bytes32 r,bytes32 s) external"];
158
+ /**
159
+ * Solana bridge instruction discriminators
160
+ */
161
+ export declare const SOLANA_DISCRIMINATORS: {
162
+ readonly BRIDGE_OUT: Buffer<ArrayBuffer>;
163
+ readonly BRIDGE_OUT_NATIVE: Buffer<ArrayBuffer>;
164
+ };
165
+ /**
166
+ * Get token metadata by symbol
167
+ */
168
+ export declare function getStaticTokenMetadata(symbol: string): TokenMetadata | undefined;
169
+ /**
170
+ * Get Ethereum token config by symbol
171
+ */
172
+ export declare function getEthereumTokenConfig(symbol: string): EthereumTokenConfig | undefined;
173
+ /**
174
+ * Get Solana token config by symbol
175
+ */
176
+ export declare function getSolanaTokenConfig(symbol: string): SolanaTokenConfig | undefined;
177
+ /**
178
+ * Format a BridgeTokenDescriptor as a pipe-separated string
179
+ */
180
+ export declare function formatTokenDescriptor(descriptor: BridgeTokenDescriptor): string;
181
+ //# sourceMappingURL=tokens.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../../../../src/bridge/constants/tokens.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,mBAAmB,EACnB,iBAAiB,EACjB,aAAa,EACb,qBAAqB,EACtB,MAAM,wBAAwB,CAAC;AAEhC;;GAEG;AACH,eAAO,MAAM,SAAS;;;;CAIZ,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,sBAAsB,KAAK,CAAC;AAEzC;;GAEG;AACH,eAAO,MAAM,wBAAwB,QAAS,CAAC;AAE/C;;GAEG;AACH,eAAO,MAAM,uBAAuB,QAAkB,CAAC;AAEvD;;GAEG;AACH,eAAO,MAAM,qBAAqB,QAAS,CAAC;AAE5C;;GAEG;AACH,eAAO,MAAM,cAAc;;;CAGjB,CAAC;AAEX;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,wBAAwB,oCAAoC,CAAC;AAE1E;;;;;;;;;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F;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,iBAAiB,GAAG,SAAS,CAKlF;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,qBAAqB,GAAG,MAAM,CAE/E"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Bridge Module
3
+ *
4
+ * Cross-chain bridging capabilities for GalaChain.
5
+ * Supports bridging between:
6
+ * - GalaChain ↔ Ethereum (6 tokens)
7
+ * - GalaChain ↔ Solana (2 tokens)
8
+ *
9
+ * @module bridge
10
+ */
11
+ export { BridgeService, type BridgeServiceConfig, type BridgeEnvironment } from './BridgeService.js';
12
+ export { GalaConnectClient, GalaConnectHttpError } from './GalaConnectClient.js';
13
+ export { type BridgeStrategy, BaseBridgeStrategy, type WaitOptions, } from './strategies/BridgeStrategy.js';
14
+ export { EthereumBridgeStrategy, type EthereumBridgeConfig, } from './strategies/EthereumBridgeStrategy.js';
15
+ export { SolanaBridgeStrategy, type SolanaBridgeConfig, } from './strategies/SolanaBridgeStrategy.js';
16
+ export type { ExternalNetwork, BridgeTokenDescriptor, BridgeTokenInstance, EthereumTokenConfig, SolanaTokenConfig, BridgeConfigurationToken, TokenMetadata, ExternalTokenInfo, GalaExchangeRate, BaseTokenCrossRate, QuoteTokenCrossRate, GalaExchangeCrossRate, DestinationChainTxFee, BridgeFeeEstimate, BridgeRequestDto, BridgeStatus, BridgeTransaction, BridgeLegResult, TokenRoundTripResult, BridgeToken, BridgeConfig, EstimateBridgeFeeParams, BridgeOutParams, BridgeInParams, WaitForBridgeOptions, GalaConnectConfig, BridgeFeeResponse, RequestBridgeOutResponse, BridgeTokenOutResponse, BridgeStatusResponse, BridgeTransactionRegistrationResponse, TokenBalanceEntry, FetchBalancesResponse, ExternalChainBalance, EthereumWalletBalanceResult, SolanaWalletBalanceResult, } from './types/index.js';
17
+ export { BridgeStatusCode } from './types/index.js';
18
+ export { GALA_BRIDGE_TYPED_DATA_DOMAIN, LEGACY_TYPED_DATA_TYPES, CROSS_RATE_TYPED_DATA_TYPES, getGalaBridgeTypedDataTypes, } from './types/eip712.js';
19
+ export { CHAIN_IDS, DEFAULT_ETHEREUM_TOKENS, DEFAULT_SOLANA_TOKENS, STATIC_TOKEN_METADATA, ERC20_ABI, BRIDGE_CONTRACT_ABI, SOLANA_DISCRIMINATORS, GALACONNECT_PRODUCTION_URL, DEFAULT_RATE_LIMIT_RPS, DEFAULT_POLL_INTERVAL_MS, DEFAULT_POLL_TIMEOUT_MS, DEFAULT_ETHEREUM_RPC_URL, DEFAULT_SOLANA_RPC_URL, DEFAULT_ETHEREUM_BRIDGE_CONTRACT, ETHEREUM_BRIDGE_CONTRACT_SEPOLIA, DEFAULT_SOLANA_BRIDGE_PROGRAM, SOLANA_COMPUTE, ETHEREUM_TOKENS_PROD, ETHEREUM_TOKENS_STAGE, getEthereumTokensByEnvironment, getEthereumBridgeContractByEnvironment, getStaticTokenMetadata, getEthereumTokenConfig, getSolanaTokenConfig, formatTokenDescriptor, } from './constants/index.js';
20
+ export { RateLimiter } from './utils/RateLimiter.js';
21
+ export { toBaseUnits, fromBaseUnits, formatTokenAmount, compareAmounts, } from './utils/tokenMath.js';
22
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/bridge/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,aAAa,EAAE,KAAK,mBAAmB,EAAE,KAAK,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAGrG,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAGjF,OAAO,EACL,KAAK,cAAc,EACnB,kBAAkB,EAClB,KAAK,WAAW,GACjB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,sBAAsB,EACtB,KAAK,oBAAoB,GAC1B,MAAM,wCAAwC,CAAC;AAChD,OAAO,EACL,oB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,EACjB,cAAc,GACf,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,160 @@
1
+ /**
2
+ * Bridge Strategy Interface
3
+ *
4
+ * Defines the contract for chain-specific bridge implementations.
5
+ * Each external chain (Ethereum, Solana) implements this interface
6
+ * to handle its unique signing, transaction, and status tracking logic.
7
+ */
8
+ import { type BridgeFeeEstimate, type BridgeInParams, type BridgeOutParams, type BridgeStatus, type BridgeTransaction, type ExternalNetwork } from '../types/index.js';
9
+ /**
10
+ * Strategy interface for chain-specific bridge operations.
11
+ *
12
+ * The Bridge SDK uses the Strategy pattern to abstract chain-specific logic:
13
+ * - EthereumBridgeStrategy: Handles ERC-20 approvals, ethers.js signing
14
+ * - SolanaBridgeStrategy: Handles SPL token accounts, @solana/web3.js signing
15
+ *
16
+ * Each strategy encapsulates:
17
+ * - Fee estimation for the target chain
18
+ * - Outbound transfers (GalaChain → External)
19
+ * - Inbound transfers (External → GalaChain)
20
+ * - Status polling and transaction tracking
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * class EthereumBridgeStrategy implements BridgeStrategy {
25
+ * readonly network: ExternalNetwork = 'Ethereum';
26
+ *
27
+ * async estimateFee(tokenSymbol: string, amount: string): Promise<BridgeFeeEstimate> {
28
+ * // Ethereum-specific fee calculation
29
+ * }
30
+ * }
31
+ * ```
32
+ */
33
+ export interface BridgeStrategy {
34
+ /**
35
+ * The external network this strategy handles.
36
+ */
37
+ readonly network: ExternalNetwork;
38
+ /**
39
+ * Estimate bridge fees for a transfer.
40
+ *
41
+ * Calculates the total cost including:
42
+ * - Bridge protocol fee (paid to GalaChain)
43
+ * - Network gas fee (estimated)
44
+ * - Any chain-specific fees
45
+ *
46
+ * @param tokenSymbol - Token symbol (e.g., 'GALA', 'GUSDC')
47
+ * @param amount - Amount in decimal format (e.g., '100.5')
48
+ * @returns Fee estimate with breakdown
49
+ */
50
+ estimateFee(tokenSymbol: string, amount: string): Promise<BridgeFeeEstimate>;
51
+ /**
52
+ * Bridge tokens OUT from GalaChain to external chain.
53
+ *
54
+ * Flow:
55
+ * 1. Lock tokens on GalaChain (via GalaConnect)
56
+ * 2. Wait for bridge confirmation
57
+ * 3. Receive wrapped tokens on external chain
58
+ *
59
+ * @param params - Bridge out parameters
60
+ * @returns Transaction details with tracking info
61
+ */
62
+ bridgeOut(params: BridgeOutParams): Promise<BridgeTransaction>;
63
+ /**
64
+ * Bridge tokens IN from external chain to GalaChain.
65
+ *
66
+ * Flow:
67
+ * 1. Approve bridge contract (if needed)
68
+ * 2. Deposit tokens to bridge contract
69
+ * 3. Wait for GalaChain confirmation
70
+ * 4. Receive native tokens on GalaChain
71
+ *
72
+ * @param params - Bridge in parameters
73
+ * @returns Transaction details with tracking info
74
+ */
75
+ bridgeIn(params: BridgeInParams): Promise<BridgeTransaction>;
76
+ /**
77
+ * Get the current status of a bridge transaction.
78
+ *
79
+ * Polls both the source and destination chains to determine
80
+ * the transaction's progress through the bridge.
81
+ *
82
+ * @param transactionHash - The bridge transaction hash
83
+ * @returns Current status with details
84
+ */
85
+ getStatus(transactionHash: string): Promise<BridgeStatus>;
86
+ /**
87
+ * Wait for a bridge transaction to complete.
88
+ *
89
+ * Polls the transaction status until it reaches a terminal state
90
+ * (completed or failed) or the timeout is reached.
91
+ *
92
+ * @param transactionHash - The bridge transaction hash
93
+ * @param options - Polling options
94
+ * @returns Final status when complete
95
+ * @throws Error if timeout reached or transaction fails
96
+ */
97
+ waitForCompletion(transactionHash: string, options?: WaitOptions): Promise<BridgeStatus>;
98
+ /**
99
+ * Get the list of supported tokens for this chain.
100
+ *
101
+ * @returns Array of token symbols supported by this bridge
102
+ */
103
+ getSupportedTokens(): string[];
104
+ /**
105
+ * Check if a specific token is supported for bridging.
106
+ *
107
+ * @param tokenSymbol - Token symbol to check
108
+ * @returns True if token can be bridged
109
+ */
110
+ isTokenSupported(tokenSymbol: string): boolean;
111
+ /**
112
+ * Validate a recipient address for the external chain.
113
+ *
114
+ * @param address - Address to validate
115
+ * @returns True if address is valid for this chain
116
+ */
117
+ isValidAddress(address: string): boolean;
118
+ }
119
+ /**
120
+ * Options for waiting on bridge completion.
121
+ */
122
+ export interface WaitOptions {
123
+ /**
124
+ * Polling interval in milliseconds.
125
+ * @default 15000 (15 seconds)
126
+ */
127
+ pollInterval?: number;
128
+ /**
129
+ * Maximum time to wait in milliseconds.
130
+ * @default 2700000 (45 minutes)
131
+ */
132
+ timeout?: number;
133
+ /**
134
+ * Callback for status updates during polling.
135
+ */
136
+ onStatusUpdate?: (status: BridgeStatus) => void;
137
+ }
138
+ /**
139
+ * Base class providing common functionality for bridge strategies.
140
+ *
141
+ * Concrete strategies extend this class and implement chain-specific logic.
142
+ */
143
+ export declare abstract class BaseBridgeStrategy implements BridgeStrategy {
144
+ abstract readonly network: ExternalNetwork;
145
+ abstract estimateFee(tokenSymbol: string, amount: string): Promise<BridgeFeeEstimate>;
146
+ abstract bridgeOut(params: BridgeOutParams): Promise<BridgeTransaction>;
147
+ abstract bridgeIn(params: BridgeInParams): Promise<BridgeTransaction>;
148
+ abstract getStatus(transactionHash: string): Promise<BridgeStatus>;
149
+ abstract getSupportedTokens(): string[];
150
+ abstract isTokenSupported(tokenSymbol: string): boolean;
151
+ abstract isValidAddress(address: string): boolean;
152
+ /**
153
+ * Default implementation of waitForCompletion with polling.
154
+ *
155
+ * Strategies can override this if they have chain-specific
156
+ * event subscription capabilities.
157
+ */
158
+ waitForCompletion(transactionHash: string, options?: WaitOptions): Promise<BridgeStatus>;
159
+ }
160
+ //# sourceMappingURL=BridgeStrategy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BridgeStrategy.d.ts","sourceRoot":"","sources":["../../../../src/bridge/strategies/BridgeStrategy.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAEL,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACrB,MAAM,mBAAmB,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W,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,iBAAiB,CAAC;IAC7B,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,iBAAiB,CAAC;IACvE,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,iBAAiB,CAAC;IACrE,QAAQ,CAAC,SAAS,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAClE,QAAQ,CAAC,kBAAkB,IAAI,MAAM,EAAE;IACvC,QAAQ,CAAC,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO;IACvD,QAAQ,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAEjD;;;;;OAKG;IACG,iBAAiB,CACrB,eAAe,EAAE,MAAM,EACvB,OAAO,GAAE,WAAgB,GACxB,OAAO,CAAC,YAAY,CAAC;CAiCzB"}
@@ -0,0 +1,198 @@
1
+ /**
2
+ * Ethereum Bridge Strategy
3
+ *
4
+ * Implements bridging between GalaChain and Ethereum networks.
5
+ * Handles ERC-20 approvals, EIP-712 signing, and bridge contract interactions.
6
+ */
7
+ import { BaseBridgeStrategy } from './BridgeStrategy.js';
8
+ import { GalaConnectClient } from '../GalaConnectClient.js';
9
+ import type { BridgeFeeEstimate, BridgeInParams, BridgeOutParams, BridgeStatus, BridgeTransaction, EthereumTokenConfig, ExternalNetwork } from '../types/index.js';
10
+ /**
11
+ * Configuration for Ethereum bridge strategy.
12
+ */
13
+ export interface EthereumBridgeConfig {
14
+ /** GalaConnect API client */
15
+ galaConnectClient: GalaConnectClient;
16
+ /** GalaChain wallet address (eth|0x...) */
17
+ galaChainWalletAddress: string;
18
+ /** Ethereum private key for signing */
19
+ ethereumPrivateKey: string;
20
+ /** Ethereum RPC URL */
21
+ ethereumRpcUrl?: string;
22
+ /** Ethereum bridge contract address */
23
+ ethereumBridgeContract?: string;
24
+ /** Ethereum wallet address (derived from private key if not provided) */
25
+ ethereumWalletAddress?: string;
26
+ /** Token configurations */
27
+ tokenConfigs?: EthereumTokenConfig[];
28
+ }
29
+ /**
30
+ * Bridge strategy for GalaChain ↔ Ethereum transfers.
31
+ *
32
+ * Supports 6 tokens: GALA, GWETH, GUSDC, GUSDT, GWTRX, GWBTC
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * const strategy = new EthereumBridgeStrategy({
37
+ * galaConnectClient,
38
+ * galaChainWalletAddress: 'eth|0x1234...',
39
+ * ethereumPrivateKey: '0xabcd...',
40
+ * });
41
+ *
42
+ * // Bridge out (GalaChain → Ethereum)
43
+ * const tx = await strategy.bridgeOut({
44
+ * tokenSymbol: 'GALA',
45
+ * amount: '100',
46
+ * destinationChain: 'Ethereum',
47
+ * recipientAddress: '0x5678...',
48
+ * });
49
+ * ```
50
+ */
51
+ export declare class EthereumBridgeStrategy extends BaseBridgeStrategy {
52
+ readonly network: ExternalNetwork;
53
+ private readonly galaConnectClient;
54
+ private readonly galaChainWalletAddress;
55
+ private readonly ethereumProvider;
56
+ private readonly ethereumWallet;
57
+ private readonly ethereumBridgeContract;
58
+ private readonly ethereumWalletAddress;
59
+ private readonly tokenConfigs;
60
+ private readonly tokenMetadataCache;
61
+ /**
62
+ * Creates a new Ethereum bridge strategy.
63
+ *
64
+ * @param config - Strategy configuration
65
+ * @throws Error if ethereumPrivateKey is invalid format
66
+ */
67
+ constructor(config: EthereumBridgeConfig);
68
+ /**
69
+ * Estimate bridge fees for a transfer to Ethereum.
70
+ *
71
+ * @param tokenSymbol - Token symbol (e.g., 'GALA', 'GWETH')
72
+ * @param amount - Amount in decimal format
73
+ * @returns Fee estimate with breakdown
74
+ */
75
+ estimateFee(tokenSymbol: string, _amount: string): Promise<BridgeFeeEstimate>;
76
+ /**
77
+ * Bridge tokens from GalaChain to Ethereum.
78
+ *
79
+ * @param params - Bridge out parameters
80
+ * @returns Transaction details
81
+ */
82
+ bridgeOut(params: BridgeOutParams): Promise<BridgeTransaction>;
83
+ /**
84
+ * Bridge tokens from Ethereum to GalaChain.
85
+ *
86
+ * @param params - Bridge in parameters
87
+ * @returns Transaction details
88
+ */
89
+ bridgeIn(params: BridgeInParams): Promise<BridgeTransaction>;
90
+ /**
91
+ * Get the current status of a bridge transaction.
92
+ *
93
+ * @param transactionHash - Transaction hash to check
94
+ * @returns Current status
95
+ */
96
+ getStatus(transactionHash: string): Promise<BridgeStatus>;
97
+ /**
98
+ * Get list of supported tokens for Ethereum bridging.
99
+ *
100
+ * @returns Array of token symbols
101
+ */
102
+ getSupportedTokens(): string[];
103
+ /**
104
+ * Check if a token is supported for Ethereum bridging.
105
+ *
106
+ * @param tokenSymbol - Token symbol to check
107
+ * @returns True if supported
108
+ */
109
+ isTokenSupported(tokenSymbol: string): boolean;
110
+ /**
111
+ * Validate an Ethereum address.
112
+ *
113
+ * @param address - Address to validate
114
+ * @returns True if valid Ethereum address
115
+ */
116
+ isValidAddress(address: string): boolean;
117
+ /**
118
+ * Get the configured Ethereum wallet address.
119
+ *
120
+ * @returns Ethereum wallet address (0x format)
121
+ *
122
+ * @example
123
+ * ```typescript
124
+ * const address = strategy.getWalletAddress();
125
+ * console.log(`Wallet: ${address}`);
126
+ * ```
127
+ */
128
+ getWalletAddress(): string;
129
+ /**
130
+ * Get ERC-20 token balance for an Ethereum address.
131
+ *
132
+ * @param tokenSymbol - Token symbol (e.g., 'GALA', 'GWETH', 'GUSDC')
133
+ * @param address - Optional Ethereum address (defaults to configured wallet)
134
+ * @returns Token balance as decimal string (e.g., "123.45678901")
135
+ * @throws Error if token not supported or address invalid
136
+ *
137
+ * @example
138
+ * ```typescript
139
+ * const balance = await strategy.getEthereumTokenBalance('GALA');
140
+ * console.log(`Balance: ${balance} GALA`);
141
+ *
142
+ * // Check another address
143
+ * const otherBalance = await strategy.getEthereumTokenBalance('GUSDC', '0x1234...');
144
+ * ```
145
+ */
146
+ getEthereumTokenBalance(tokenSymbol: string, address?: string): Promise<string>;
147
+ /**
148
+ * Get native ETH balance for an Ethereum address.
149
+ *
150
+ * @param address - Optional Ethereum address (defaults to configured wallet)
151
+ * @returns ETH balance as decimal string (18 decimals)
152
+ * @throws Error if address invalid
153
+ *
154
+ * @example
155
+ * ```typescript
156
+ * const ethBalance = await strategy.getEthereumNativeBalance();
157
+ * console.log(`ETH Balance: ${ethBalance} ETH`);
158
+ * ```
159
+ */
160
+ getEthereumNativeBalance(address?: string): Promise<string>;
161
+ /**
162
+ * Get token metadata from cache or API.
163
+ */
164
+ private getTokenMetadata;
165
+ /**
166
+ * Build EIP-712 signed bridge out payload.
167
+ */
168
+ private buildBridgeOutPayload;
169
+ /**
170
+ * Execute bridge deposit on Ethereum.
171
+ */
172
+ private executeBridgeDeposit;
173
+ /**
174
+ * Bridge using ERC-20 Permit for gas-less approval.
175
+ */
176
+ private bridgeWithPermit;
177
+ /**
178
+ * Bridge using traditional ERC-20 approval.
179
+ */
180
+ private bridgeWithApproval;
181
+ /**
182
+ * Normalize fee response for deterministic signing.
183
+ */
184
+ private normalizeDestinationChainTxFee;
185
+ /**
186
+ * Remove undefined values for deterministic JSON.
187
+ */
188
+ private sanitizeObject;
189
+ /**
190
+ * Extract bridge request ID from response.
191
+ */
192
+ private extractBridgeRequestId;
193
+ /**
194
+ * Delay helper.
195
+ */
196
+ private delay;
197
+ }
198
+ //# sourceMappingURL=EthereumBridgeStrategy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EthereumBridgeStrategy.d.ts","sourceRoot":"","sources":["../../../../src/bridge/strategies/EthereumBridgeStrategy.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAcH,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,KAAK,EACV,iBAAiB,EACjB,cAAc,EACd,eAAe,EAEf,YAAY,EAEZ,iBAAiB,EAEjB,mBAAmB,EACnB,eAAe,EAEhB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