|
| 1 | +// SPDX-License-Identifier: LGPL-3.0-only |
| 2 | +pragma solidity ^0.8.17; |
| 3 | + |
| 4 | +import {Script, console2} from "forge-std/Script.sol"; |
| 5 | +import {LiFiDiamond} from "lifi/LiFiDiamond.sol"; |
| 6 | +import {PolymerCCTPFacet, PolymerCCTPData} from "lifi/Facets/PolymerCCTPFacet.sol"; |
| 7 | +import {ILiFi} from "lifi/Interfaces/ILiFi.sol"; |
| 8 | +import {LibSwap} from "lifi/Libraries/LibSwap.sol"; |
| 9 | +import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; |
| 10 | + |
| 11 | +contract CallPolymerCCTPFacet is Script { |
| 12 | + function run() external payable { |
| 13 | + uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); |
| 14 | + address diamondAddress = vm.envAddress("DIAMOND_ADDRESS"); |
| 15 | + uint32 destinationDomain = uint32(vm.envUint("DESTINATION_DOMAIN")); |
| 16 | + address receiver = vm.addr(deployerPrivateKey); |
| 17 | + uint256 amount = uint256(1000); |
| 18 | + uint256 polymerTokenFee = uint256(10); |
| 19 | + uint32 maxCCTPFee = uint32(vm.envOr("MAX_CCTP_FEE", uint256(100))); |
| 20 | + uint32 minFinalityThreshold = uint32(vm.envOr("MIN_FINALITY_THRESHOLD", uint256(0))); |
| 21 | + |
| 22 | + console2.log("Diamond Proxy address:", diamondAddress); |
| 23 | + // Cast diamond to PolymerCCTPFacet to call its functions |
| 24 | + PolymerCCTPFacet polymerFacet = PolymerCCTPFacet(diamondAddress); |
| 25 | + address usdcAddress = vm.envAddress("USDC"); |
| 26 | + |
| 27 | + // Get USDC address from the PolymerCCTPFacet |
| 28 | + console2.log("USDC address:", usdcAddress); |
| 29 | + |
| 30 | + vm.startBroadcast(deployerPrivateKey); |
| 31 | + |
| 32 | + // Approve USDC spending |
| 33 | + IERC20(usdcAddress).approve(diamondAddress, amount + polymerTokenFee); |
| 34 | + |
| 35 | + // Prepare bridge data |
| 36 | + ILiFi.BridgeData memory bridgeData = ILiFi.BridgeData({ |
| 37 | + transactionId: bytes32(uint256(1)), // Simple transaction ID |
| 38 | + bridge: "PolymerCCTP", |
| 39 | + integrator: "LiFi", |
| 40 | + referrer: address(0), |
| 41 | + sendingAssetId: usdcAddress, |
| 42 | + receiver: receiver, |
| 43 | + minAmount: amount, |
| 44 | + destinationChainId: uint256(destinationDomain), // Using domain as chain ID to avoid SLOAD to read from a mapping - this seems like it can just directly be passed via calldata. |
| 45 | + hasSourceSwaps: false, |
| 46 | + hasDestinationCall: false |
| 47 | + }); |
| 48 | + |
| 49 | + // Prepare Polymer-specific data |
| 50 | + PolymerCCTPData memory polymerData = PolymerCCTPData({ |
| 51 | + polymerTokenFee: polymerTokenFee, |
| 52 | + maxCCTPFee: maxCCTPFee, |
| 53 | + minFinalityThreshold: minFinalityThreshold, |
| 54 | + nonEvmAddress: bytes32(0) |
| 55 | + }); |
| 56 | + |
| 57 | + console2.log("Calling startBridgeTokensViaPolymerCCTP..."); |
| 58 | + console2.log("Amount:", amount); |
| 59 | + console2.log("Destination Domain:", destinationDomain); |
| 60 | + console2.log("Receiver:", receiver); |
| 61 | + |
| 62 | + // Call the bridge function |
| 63 | + polymerFacet.startBridgeTokensViaPolymerCCTP(bridgeData, polymerData); |
| 64 | + |
| 65 | + console2.log("Bridge transaction initiated successfully"); |
| 66 | + |
| 67 | + vm.stopBroadcast(); |
| 68 | + } |
| 69 | +} |
0 commit comments