diff --git a/deployments/_deployments_log_file.json b/deployments/_deployments_log_file.json index f78d139f6..44c2b4cae 100644 --- a/deployments/_deployments_log_file.json +++ b/deployments/_deployments_log_file.json @@ -37434,6 +37434,17 @@ "SALT": "", "VERIFIED": "true" } + ], + "1.0.2": [ + { + "ADDRESS": "0xdaD5da5FB53EAe15f490Fb31F4573e56277b59CA", + "OPTIMIZER_RUNS": "1000000", + "TIMESTAMP": "2025-09-12 14:50:00", + "CONSTRUCTOR_ARGS": "0x000000000000000000000000a5f565650890fba1824ee0f21ebbbf660a179934000000000000000000000000f70da97812cb96acdf810712aa562db8dfa3dbef", + "SALT": "22345116", + "VERIFIED": "false", + "ZK_SOLC_VERSION": "" + } ] }, "production": { diff --git a/deployments/arbitrum.diamond.staging.json b/deployments/arbitrum.diamond.staging.json index c600fde1a..2f645eaeb 100644 --- a/deployments/arbitrum.diamond.staging.json +++ b/deployments/arbitrum.diamond.staging.json @@ -180,6 +180,18 @@ "0x004E291b9244C811B0BE00cA2C179d54FAA5073D": { "Name": "RelayDepositoryFacet", "Version": "1.0.0" + }, + "0xdaD5da5FB53EAe15f490Fb31F4573e56277b59CA": { + "Name": "RelayFacet", + "Version": "1.0.2" + }, + "0xaA1E88f4D0cb0a798f1FeBAfc8fAb4778629D4e7": { + "Name": "", + "Version": "" + }, + "0x33EcEb68994E0499a61FAda3b49Ab243e63555F1": { + "Name": "", + "Version": "" } }, "Periphery": { diff --git a/deployments/arbitrum.staging.json b/deployments/arbitrum.staging.json index d49ac733d..4ea15ec8b 100644 --- a/deployments/arbitrum.staging.json +++ b/deployments/arbitrum.staging.json @@ -50,7 +50,7 @@ "AcrossFacetV3": "0xF336cc028Fc5328472f96e377d32Fd32F8eE1750", "ReceiverAcrossV3": "0xe4F3DEF14D61e47c696374453CD64d438FD277F8", "AcrossFacetPackedV3": "0x21767081Ff52CE5563A29f27149D01C7127775A2", - "RelayFacet": "0x681a3409c35F12224c436D50Ce14F25f954B6Ea2", + "RelayFacet": "0xdaD5da5FB53EAe15f490Fb31F4573e56277b59CA", "GlacisFacet": "0x36e1375B0755162d720276dFF6893DF02bd49225", "PioneerFacet": "0x371E61d9DC497C506837DFA47B8dccEF1da30459", "GasZipFacet": "0x7C27b0FD92dbC5a1cA268255A649320E8C649e70", diff --git a/script/demoScripts/demoRelay.ts b/script/demoScripts/demoRelay.ts index a69a16627..0e0ab55ee 100644 --- a/script/demoScripts/demoRelay.ts +++ b/script/demoScripts/demoRelay.ts @@ -35,283 +35,382 @@ const main = async () => { // Bridge ETH - let params = { - user: deployments.LiFiDiamond, - originChainId: 42161, - destinationChainId: 137, - originCurrency: '0x0000000000000000000000000000000000000000', - destinationCurrency: '0x0000000000000000000000000000000000000000', - recipient: address, - tradeType: 'EXACT_INPUT', - amount: '1000000000000000', - referrer: 'relay.link/swap', - useExternalLiquidity: false, - } - - let resp = await fetch('https://api.relay.link/quote', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify(params), - }) - let quote = await resp.json() - let requestId = quote.steps[0].requestId - - let sigResp = await fetch( - `https://api.relay.link/requests/${requestId}/signature/v2`, - { headers: { 'Content-Type': 'application/json' } } - ) - let sigData = await sigResp.json() - - let bridgeData: ILiFi.BridgeDataStruct = { - transactionId: utils.randomBytes(32), - bridge: 'Relay', - integrator: 'ACME Devs', - referrer: '0x0000000000000000000000000000000000000000', - sendingAssetId: '0x0000000000000000000000000000000000000000', - receiver: address, - minAmount: ethers.utils.parseEther('0.001'), - destinationChainId: 137, - hasSourceSwaps: false, - hasDestinationCall: false, - } - - let relayData: RelayFacet.RelayDataStruct = { - requestId, - nonEVMReceiver: ethers.constants.HashZero, - receivingAssetId: ethers.constants.HashZero, - signature: sigData.signature, - } - - console.info('Dev Wallet Address: ', address) - console.info('Bridging ETH...') - tx = await relay - .connect(signer) - .startBridgeTokensViaRelay(bridgeData, relayData, { - value: ethers.utils.parseEther('0.001'), - }) - await tx.wait() - console.info('Bridged ETH') - - // Bridge USDC - - params = { - user: deployments.LiFiDiamond, - originChainId: 42161, - destinationChainId: 10, - originCurrency: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', - destinationCurrency: '0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85', - recipient: address, - tradeType: 'EXACT_INPUT', - amount: '5000000', - referrer: 'relay.link/swap', - useExternalLiquidity: false, - } - - resp = await fetch('https://api.relay.link/quote', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify(params), - }) - quote = await resp.json() - requestId = quote.steps[0].requestId - - sigResp = await fetch( - `https://api.relay.link/requests/${requestId}/signature/v2`, - { headers: { 'Content-Type': 'application/json' } } - ) - sigData = await sigResp.json() + // let params = { + // user: deployments.LiFiDiamond, + // originChainId: 42161, + // destinationChainId: 137, + // originCurrency: '0x0000000000000000000000000000000000000000', + // destinationCurrency: '0x0000000000000000000000000000000000000000', + // recipient: address, + // tradeType: 'EXACT_INPUT', + // amount: '1000000000000000', + // referrer: 'relay.link/swap', + // useExternalLiquidity: false, + // } + + // let resp = await fetch('https://api.relay.link/quote', { + // method: 'POST', + // headers: { + // 'Content-Type': 'application/json', + // }, + // body: JSON.stringify(params), + // }) + // let quote = await resp.json() + // let requestId = quote.steps[0].requestId + + // let sigResp = await fetch( + // `https://api.relay.link/requests/${requestId}/signature/v2`, + // { headers: { 'Content-Type': 'application/json' } } + // ) + // let sigData = await sigResp.json() + + // let bridgeData: ILiFi.BridgeDataStruct = { + // transactionId: utils.randomBytes(32), + // bridge: 'Relay', + // integrator: 'ACME Devs', + // referrer: '0x0000000000000000000000000000000000000000', + // sendingAssetId: '0x0000000000000000000000000000000000000000', + // receiver: address, + // minAmount: ethers.utils.parseEther('0.001'), + // destinationChainId: 137, + // hasSourceSwaps: false, + // hasDestinationCall: false, + // } + + // let relayData: RelayFacet.RelayDataStruct = { + // requestId, + // nonEVMReceiver: ethers.constants.HashZero, + // receivingAssetId: ethers.constants.HashZero, + // signature: sigData.signature, + // } + + // console.info('Dev Wallet Address: ', address) + // console.info('Bridging ETH...') + // tx = await relay + // .connect(signer) + // .startBridgeTokensViaRelay(bridgeData, relayData, { + // value: ethers.utils.parseEther('0.001'), + // }) + // await tx.wait() + // console.info('Bridged ETH') + + // // Bridge USDC + + // params = { + // user: deployments.LiFiDiamond, + // originChainId: 42161, + // destinationChainId: 10, + // originCurrency: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', + // destinationCurrency: '0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85', + // recipient: address, + // tradeType: 'EXACT_INPUT', + // amount: '5000000', + // referrer: 'relay.link/swap', + // useExternalLiquidity: false, + // } + + // resp = await fetch('https://api.relay.link/quote', { + // method: 'POST', + // headers: { + // 'Content-Type': 'application/json', + // }, + // body: JSON.stringify(params), + // }) + // quote = await resp.json() + // requestId = quote.steps[0].requestId + + // sigResp = await fetch( + // `https://api.relay.link/requests/${requestId}/signature/v2`, + // { headers: { 'Content-Type': 'application/json' } } + // ) + // sigData = await sigResp.json() const token = ERC20__factory.connect( '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', provider ) - bridgeData = { - transactionId: utils.randomBytes(32), - bridge: 'Relay', - integrator: 'ACME Devs', - referrer: '0x0000000000000000000000000000000000000000', - sendingAssetId: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', - receiver: address, - minAmount: '5000000', - destinationChainId: 10, - hasSourceSwaps: false, - hasDestinationCall: false, - } - - relayData = { - requestId, - nonEVMReceiver: ethers.constants.HashZero, - receivingAssetId: ethers.utils.hexZeroPad( - '0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85', - 32 - ), - signature: sigData.signature, - } - - console.info('Dev Wallet Address: ', address) - console.info('Approving USDC...') - tx = await token.connect(signer).approve(LIFI_ADDRESS, '5000000') - await tx.wait() - console.info('Approved USDC') - console.info('Bridging USDC...') - tx = await relay - .connect(signer) - .startBridgeTokensViaRelay(bridgeData, relayData) - await tx.wait() - console.info('Bridged USDC') - - // Swap USDC and Bridge ETH - - params = { - user: deployments.LiFiDiamond, - originChainId: 42161, - destinationChainId: 137, - originCurrency: '0x0000000000000000000000000000000000000000', - destinationCurrency: '0x0000000000000000000000000000000000000000', - recipient: address, - tradeType: 'EXACT_INPUT', - amount: '1000000000000000', - referrer: 'relay.link/swap', - useExternalLiquidity: false, - } - - resp = await fetch('https://api.relay.link/quote', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify(params), - }) - quote = await resp.json() - requestId = quote.steps[0].requestId - - sigResp = await fetch( - `https://api.relay.link/requests/${requestId}/signature/v2`, - { headers: { 'Content-Type': 'application/json' } } - ) - sigData = await sigResp.json() - console.log(sigData) - - bridgeData = { - transactionId: utils.randomBytes(32), - bridge: 'Relay', - integrator: 'ACME Devs', - referrer: '0x0000000000000000000000000000000000000000', - sendingAssetId: '0x0000000000000000000000000000000000000000', - receiver: address, - minAmount: ethers.utils.parseEther('0.001'), - destinationChainId: 137, - hasSourceSwaps: true, - hasDestinationCall: false, - } - - const swapData = [] - - const uniswapAddress = ADDRESS_UNISWAP_ARB - swapData[0] = await getUniswapSwapDataERC20ToETH( - uniswapAddress, - 42161, - ADDRESS_USDC_ARB, - ADDRESS_WETH_ARB, - ethers.utils.parseUnits('4', 6), - LIFI_ADDRESS, - true - ) - - relayData = { - requestId, - nonEVMReceiver: ethers.constants.HashZero, - receivingAssetId: ethers.constants.HashZero, - signature: sigData.signature, - } - - console.info('Dev Wallet Address: ', address) - console.info('Approving USDC...') - tx = await token.connect(signer).approve(LIFI_ADDRESS, '4000000') - await tx.wait() - console.info('Approved USDC') - console.info('Bridging USDC -> ETH...') - tx = await relay - .connect(signer) - .swapAndStartBridgeTokensViaRelay(bridgeData, swapData, relayData) - await tx.wait() - console.info('Bridged ETH') - - // Bridge USDC to Solana - - const solanaReceiver = 'EoW7FWTdPdZKpd3WAhH98c2HMGHsdh5yhzzEtk1u68Bb' - const solanaUSDC = 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v' - - params = { + // bridgeData = { + // transactionId: utils.randomBytes(32), + // bridge: 'Relay', + // integrator: 'ACME Devs', + // referrer: '0x0000000000000000000000000000000000000000', + // sendingAssetId: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', + // receiver: address, + // minAmount: '5000000', + // destinationChainId: 10, + // hasSourceSwaps: false, + // hasDestinationCall: false, + // } + + // relayData = { + // requestId, + // nonEVMReceiver: ethers.constants.HashZero, + // receivingAssetId: ethers.utils.hexZeroPad( + // '0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85', + // 32 + // ), + // signature: sigData.signature, + // } + + // console.info('Dev Wallet Address: ', address) + // console.info('Approving USDC...') + // tx = await token.connect(signer).approve(LIFI_ADDRESS, '5000000') + // await tx.wait() + // console.info('Approved USDC') + // console.info('Bridging USDC...') + // tx = await relay + // .connect(signer) + // .startBridgeTokensViaRelay(bridgeData, relayData) + // await tx.wait() + // console.info('Bridged USDC') + + // // Swap USDC and Bridge ETH + + // params = { + // user: deployments.LiFiDiamond, + // originChainId: 42161, + // destinationChainId: 137, + // originCurrency: '0x0000000000000000000000000000000000000000', + // destinationCurrency: '0x0000000000000000000000000000000000000000', + // recipient: address, + // tradeType: 'EXACT_INPUT', + // amount: '1000000000000000', + // referrer: 'relay.link/swap', + // useExternalLiquidity: false, + // } + + // resp = await fetch('https://api.relay.link/quote', { + // method: 'POST', + // headers: { + // 'Content-Type': 'application/json', + // }, + // body: JSON.stringify(params), + // }) + // quote = await resp.json() + // requestId = quote.steps[0].requestId + + // sigResp = await fetch( + // `https://api.relay.link/requests/${requestId}/signature/v2`, + // { headers: { 'Content-Type': 'application/json' } } + // ) + // sigData = await sigResp.json() + // console.log(sigData) + + // bridgeData = { + // transactionId: utils.randomBytes(32), + // bridge: 'Relay', + // integrator: 'ACME Devs', + // referrer: '0x0000000000000000000000000000000000000000', + // sendingAssetId: '0x0000000000000000000000000000000000000000', + // receiver: address, + // minAmount: ethers.utils.parseEther('0.001'), + // destinationChainId: 137, + // hasSourceSwaps: true, + // hasDestinationCall: false, + // } + + // const swapData = [] + + // const uniswapAddress = ADDRESS_UNISWAP_ARB + // swapData[0] = await getUniswapSwapDataERC20ToETH( + // uniswapAddress, + // 42161, + // ADDRESS_USDC_ARB, + // ADDRESS_WETH_ARB, + // ethers.utils.parseUnits('4', 6), + // LIFI_ADDRESS, + // true + // ) + + // relayData = { + // requestId, + // nonEVMReceiver: ethers.constants.HashZero, + // receivingAssetId: ethers.constants.HashZero, + // signature: sigData.signature, + // } + + // console.info('Dev Wallet Address: ', address) + // console.info('Approving USDC...') + // tx = await token.connect(signer).approve(LIFI_ADDRESS, '4000000') + // await tx.wait() + // console.info('Approved USDC') + // console.info('Bridging USDC -> ETH...') + // tx = await relay + // .connect(signer) + // .swapAndStartBridgeTokensViaRelay(bridgeData, swapData, relayData) + // await tx.wait() + // console.info('Bridged ETH') + + // // Bridge USDC to Solana + + // const solanaReceiver = 'EoW7FWTdPdZKpd3WAhH98c2HMGHsdh5yhzzEtk1u68Bb' + // const solanaUSDC = 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v' + + // params = { + // user: deployments.LiFiDiamond, + // originChainId: 42161, + // destinationChainId: 792703809, + // originCurrency: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', + // destinationCurrency: solanaUSDC, + // recipient: solanaReceiver, + // tradeType: 'EXACT_INPUT', + // amount: '5000000', + // referrer: 'relay.link/swap', + // useExternalLiquidity: false, + // } + + // resp = await fetch('https://api.relay.link/quote', { + // method: 'POST', + // headers: { + // 'Content-Type': 'application/json', + // }, + // body: JSON.stringify(params), + // }) + // quote = await resp.json() + // console.log(quote) + // requestId = quote.steps[0].requestId + + // console.log(requestId) + // sigResp = await fetch( + // `https://api.relay.link/requests/${requestId}/signature/v2`, + // { headers: { 'Content-Type': 'application/json' } } + // ) + // sigData = await sigResp.json() + // console.log(sigData) + + // bridgeData = { + // transactionId: utils.randomBytes(32), + // bridge: 'Relay', + // integrator: 'ACME Devs', + // referrer: '0x0000000000000000000000000000000000000000', + // sendingAssetId: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', + // receiver: '0x11f111f111f111F111f111f111F111f111f111F1', + // minAmount: '5000000', + // destinationChainId: 1151111081099710, + // hasSourceSwaps: false, + // hasDestinationCall: false, + // } + + // relayData = { + // requestId, + // nonEVMReceiver: `0x${new PublicKey(solanaReceiver) + // .toBuffer() + // .toString('hex')}`, + // receivingAssetId: `0x${new PublicKey(solanaUSDC) + // .toBuffer() + // .toString('hex')}`, + // signature: sigData.signature, + // } + + // console.info('Dev Wallet Address: ', address) + // console.info('Approving USDC...') + // tx = await token.connect(signer).approve(LIFI_ADDRESS, '5000000') + // await tx.wait() + // console.info('Approved USDC') + // console.info('Bridging USDC...') + // tx = await relay + // .connect(signer) + // .startBridgeTokensViaRelay(bridgeData, relayData) + // await tx.wait() + // console.info('Bridged USDC') + + /// === BRIDGE TO SUI === + /// Success tx: https://arbiscan.io/tx/0x82e067d09e240805c1a2745e4119077af0c0281b04ca27808fa6cf95307e097b + /// Relay explorer: https://relay.link/transaction/0x3b2a172ac09209eb32d6c2042757eaf61eeb9be5c63b33891a23822cd31c362e + + const suiUSDC = + '0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC' + const suiRandomReceiver = + '0x102fec3799bcae8f987a023f52c468156ebca136bdaa32bc148669027a5cbc98' + const usdcAmount = '500000' + const params = { user: deployments.LiFiDiamond, originChainId: 42161, - destinationChainId: 792703809, - originCurrency: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', - destinationCurrency: solanaUSDC, - recipient: solanaReceiver, + destinationChainId: 103665049, // SUI + originCurrency: ADDRESS_USDC_ARB, + destinationCurrency: suiUSDC, + recipient: suiRandomReceiver, tradeType: 'EXACT_INPUT', - amount: '5000000', + amount: usdcAmount, referrer: 'relay.link/swap', useExternalLiquidity: false, } + console.log(params) - resp = await fetch('https://api.relay.link/quote', { + const resp = await fetch('https://api.relay.link/quote', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(params), }) - quote = await resp.json() + const quote = await resp.json() console.log(quote) - requestId = quote.steps[0].requestId + const requestId = quote.steps[0].requestId + console.log('requestId') + console.log('requestId') + console.log('requestId') + console.log('requestId') + console.log('requestId') console.log(requestId) - sigResp = await fetch( + console.log(requestId) + console.log(requestId) + console.log(requestId) + console.log(requestId) + const sigResp = await fetch( `https://api.relay.link/requests/${requestId}/signature/v2`, { headers: { 'Content-Type': 'application/json' } } ) - sigData = await sigResp.json() + console.log('sigResp') + console.log(sigResp) + const sigData = await sigResp.json() + console.log('sigData') console.log(sigData) - bridgeData = { + const bridgeData = { transactionId: utils.randomBytes(32), bridge: 'Relay', integrator: 'ACME Devs', referrer: '0x0000000000000000000000000000000000000000', sendingAssetId: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', - receiver: '0x11f111f111f111F111f111f111F111f111f111F1', - minAmount: '5000000', - destinationChainId: 1151111081099710, + receiver: '0x11f111f111f111F111f111f111F111f111f111F1', // Non-EVM address + minAmount: usdcAmount, + destinationChainId: '9270000000000000', // SUI hasSourceSwaps: false, hasDestinationCall: false, } - relayData = { + console.log('bridgeData') + console.log(bridgeData) + + const relayData = { requestId, - nonEVMReceiver: `0x${new PublicKey(solanaReceiver) - .toBuffer() - .toString('hex')}`, - receivingAssetId: `0x${new PublicKey(solanaUSDC) - .toBuffer() - .toString('hex')}`, + nonEVMReceiver: suiRandomReceiver, + receivingAssetId: suiUSDC.substring(0, 66), // take first 66 characters (32 bytes) - there is no documentation on this, Relay team said to do this "We take the first 32 bytes of the currency when we generate the signature" signature: sigData.signature, } + const balance = await token.balanceOf(address) + console.log('USDC Balance:', ethers.utils.formatUnits(balance, 6), 'USDC') + + if (balance.lt(ethers.BigNumber.from(usdcAmount))) { + console.log('Insufficient USDC balance!') + return + } + console.info('Dev Wallet Address: ', address) console.info('Approving USDC...') - tx = await token.connect(signer).approve(LIFI_ADDRESS, '5000000') + tx = await token.connect(signer).approve(LIFI_ADDRESS, usdcAmount) await tx.wait() console.info('Approved USDC') console.info('Bridging USDC...') tx = await relay .connect(signer) .startBridgeTokensViaRelay(bridgeData, relayData) + console.log('tx') + console.log(tx.hash) await tx.wait() console.info('Bridged USDC') } diff --git a/src/Facets/RelayFacet.sol b/src/Facets/RelayFacet.sol index 275f26a21..9463e6df6 100644 --- a/src/Facets/RelayFacet.sol +++ b/src/Facets/RelayFacet.sol @@ -15,7 +15,7 @@ import { InvalidConfig } from "../Errors/GenericErrors.sol"; /// @title RelayFacet /// @author LI.FI (https://li.fi) /// @notice Provides functionality for bridging through Relay Protocol -/// @custom:version 1.0.1 +/// @custom:version 1.0.2 contract RelayFacet is ILiFi, ReentrancyGuard, @@ -219,21 +219,26 @@ contract RelayFacet is } /// @notice get Relay specific chain id for non-EVM chains - /// IDs found here https://li.quest/v1/chains?chainTypes=UTXO,SVM + /// IDs found here https://api.relay.link/chains /// @param chainId LIFI specific chain id function _getMappedChainId( uint256 chainId ) internal pure returns (uint256) { // Bitcoin - if (chainId == 20000000000001) { + if (chainId == LIFI_CHAIN_ID_BTC) { return 8253038; } // Solana - if (chainId == 1151111081099710) { + if (chainId == LIFI_CHAIN_ID_SOLANA) { return 792703809; } + // Sui + if (chainId == LIFI_CHAIN_ID_SUI) { + return 103665049; + } + return chainId; } } diff --git a/test/solidity/Facets/RelayFacet.t.sol b/test/solidity/Facets/RelayFacet.t.sol index 119340f71..3225c30ba 100644 --- a/test/solidity/Facets/RelayFacet.t.sol +++ b/test/solidity/Facets/RelayFacet.t.sol @@ -734,6 +734,12 @@ contract RelayFacetTest is TestBaseFacet { return; } + // Sui + if (chainId == 9270000000000000) { + assertEq(mapped, 103665049); + return; + } + assertEq(mapped, chainId); }