⚛️Cross-chain Logic
Explains how the Cross-Chain Lending Gateway (CLG) uses Stargate to securely execute lending operations across different blockchains.
What is CLG?
The Cross-Chain Lending Gateway (CLG) is a smart contract designed to bridge lending operations between chains using Stargate. It acts as a router and dispatcher, allowing users to interact with Compound-style markets on remote chains.
How CLG Works
When a user wants to perform a cross-chain action (e.g. supply on Ethereum and borrow on Hyperliquid), CLG packages the request and sends it through Stargate.
Stargate handles the bridging of tokens and execution messages, which are then processed on the destination chain by the corresponding CLG instance.
CLG Functions
1. Cross-chain Supply and Borrow
This function allows a user to supply collateral on a remote chain and simultaneously borrow an asset from that chain.
function supplyThenBorrowCrosschain(
uint16 dstChainId,
address dstCTokenCollateral,
address dstCTokenBorrow,
uint256 mintAmount,
uint256 borrowAmount,
address borrower,
address receiver,
uint256 lzFee
) external payable2. Cross-chain Repay
This function enables repayment of a loan on another chain. The caller sends the repayment amount and metadata, and the remote CLG performs the actual repayment.
3. Cross-chain Redeem
This function lets users redeem their collateral from another chain and withdraw the underlying asset locally.
Stargate Integration
Stargate is responsible for two things:
Token bridging: The underlying ERC20 tokens are securely transferred between chains using Stargate’s liquidity network.
Message execution: A payload is encoded and sent with
lzSend, received by the destination chain’slzReceive, and interpreted for execution.
Stargate Send Example
Stargate Receive Logic
The payload includes encoded parameters and the operation type (enum), which the receiving CLG parses and routes to the appropriate internal function.
User Flow
Here is a complete user flow for a cross-chain supplyThenBorrowCrosschain operation:
User calls
supplyThenBorrowCrosschain(...)on source chain CLG.CLG pulls tokens from the user and transfers them to the Stargate Router.
Stargate bridges the tokens and an encoded payload to the destination chain.
Destination CLG receives the payload in
lzReceive, decodes it.CLG supplies collateral to the destination
cTokenmarket on behalf of the user.CLG borrows the requested amount from the borrow market.
The borrowed tokens are transferred to the user’s receiver address on the destination chain.
Events are emitted to reflect the full transaction lifecycle.
Cross-chain Repay (from Origin Chain)
User calls
repayBorrowCrosschain(...)on source chain CLG.CLG pulls the repayment tokens from the user and transfers them to Stargate.
Stargate bridges tokens and an encoded
REPAYpayload to the destination chain.Destination CLG receives the payload, decodes it, and performs a repayment on the borrow market for the borrower.
Repayment event is emitted.
Cross-chain Repay (from Destination Chain)
User directly calls the native Compound
repayBorrow(...)on the local cToken.Repayment is processed within the destination chain; CLG is not involved.
Only applies when the repayment occurs on the same chain where the borrow was initiated.
Last updated