Skip to content

Commit c7954d6

Browse files
committed
add polymer cctp facet + related deploy scripts
1 parent f81f1db commit c7954d6

File tree

9 files changed

+1559
-0
lines changed

9 files changed

+1559
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/bin/bash
2+
3+
# Exit on error
4+
set -e
5+
6+
# Color codes for output
7+
GREEN='\033[0;32m'
8+
BLUE='\033[0;34m'
9+
RED='\033[0;31m'
10+
NC='\033[0m' # No Color
11+
12+
# Function to display usage
13+
usage() {
14+
echo "Usage: $0 <RPC_URL> <PRIVATE_KEY> <DESTINATION_DOMAIN> <ADDRESSES_FILE>"
15+
echo ""
16+
echo "Required arguments:"
17+
echo " RPC_URL RPC endpoint URL"
18+
echo " PRIVATE_KEY Private key for deployment"
19+
echo " DESTINATION_DOMAIN Destination domain for CCTP bridge"
20+
echo " ADDRESSES_FILE Path to addresses json"
21+
echo ""
22+
echo "Example:"
23+
echo " $0 https://arb-sepolia.g.alchemy.com/v2/KEY 0xYOURKEY 3 ./testnet-addresses.json"
24+
exit 1
25+
}
26+
27+
# Check if we have the required number of arguments
28+
if [ $# -lt 4 ]; then
29+
echo -e "${RED}Error: Missing required arguments${NC}\n"
30+
usage
31+
fi
32+
33+
# Parse positional arguments
34+
RPC_URL="$1"
35+
PRIVATE_KEY="$2"
36+
DESTINATION_DOMAIN="$3"
37+
ADDRESSES_FILE="$4"
38+
39+
# Get chain ID from RPC
40+
echo -e "${BLUE}Fetching chain ID from RPC...${NC}"
41+
if ! CHAIN_ID=$(cast chain-id -r "$RPC_URL" 2>&1); then
42+
echo -e "${RED}Error: cast chain-id failed for $RPC_URL${NC}"
43+
echo "$CHAIN_ID"
44+
exit 1
45+
fi
46+
if [ -z "$CHAIN_ID" ]; then
47+
echo -e "${RED}Error: Could not fetch chain ID from RPC${NC}"
48+
exit 1
49+
fi
50+
echo -e "${GREEN}Chain ID: $CHAIN_ID${NC}"
51+
52+
# Read DIAMOND_ADDRESS and USDC from addresses.json
53+
DIAMOND_ADDRESS=$(jq -r --arg chainId "$CHAIN_ID" '.[$chainId].diamondProxy // empty' "$ADDRESSES_FILE")
54+
if [ -z "$DIAMOND_ADDRESS" ]; then
55+
echo -e "${RED}Error: DIAMOND_ADDRESS not found in $ADDRESSES_FILE for chain $CHAIN_ID${NC}"
56+
echo "Please deploy the diamond first using DeployPolymerContracts.sh"
57+
exit 1
58+
fi
59+
echo -e "${BLUE}Using DIAMOND_ADDRESS from $ADDRESSES_FILE: $DIAMOND_ADDRESS${NC}"
60+
61+
if [ -z "$USDC" ]; then
62+
USDC=$(jq -r --arg chainId "$CHAIN_ID" '.[$chainId].usdc // empty' "$ADDRESSES_FILE")
63+
if [ -z "$USDC" ]; then
64+
echo -e "${RED}Error: USDC not found in $ADDRESSES_FILE for chain $CHAIN_ID and not set in environment${NC}"
65+
echo "Please either:"
66+
echo " 1. Set USDC environment variable, or"
67+
echo " 2. Add it to $ADDRESSES_FILE under \"$CHAIN_ID\": { \"usdc\": \"0x...\" }"
68+
exit 1
69+
fi
70+
echo -e "${BLUE}Using USDC from $ADDRESSES_FILE: $USDC${NC}"
71+
fi
72+
73+
# Export all variables for forge scripts
74+
export RPC_URL
75+
export CHAIN_ID
76+
export PRIVATE_KEY
77+
export DESTINATION_DOMAIN
78+
export DIAMOND_ADDRESS
79+
export USDC
80+
81+
echo -e "${BLUE}Calling PolymerCCTPFacet on chain $CHAIN_ID...${NC}"
82+
83+
# Run the call script
84+
forge script ./script/demoScripts/PolymerCCTP.s.sol \
85+
--rpc-url "$RPC_URL" \
86+
--broadcast \
87+
--verify
88+
89+
echo -e "${GREEN}PolymerCCTP call complete!${NC}"
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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

Comments
 (0)