UNPKG

@hyperlane-xyz/core

Version:

Core solidity contracts for Hyperlane

81 lines (63 loc) 2.53 kB
# Yield Routes Yield routes are a mechanism to transfer yield-bearing assets across chains using the ERC4626 standard. `HypERC4626Collateral` is a contract that implements `ERC4626` deposits upon transfer and withdrawal upon transfer back. `HypERC4646` is a contract that implements a rebasing `ERC20`. Balances are virtualized as vault shares times the total assets over the total shares in the `ERC4626` vault (on the collateral chain). ## `HypERC4626Collateral.transferRemote` ```mermaid sequenceDiagram participant User participant ERC20 participant ERC4626 participant WarpRoute participant Mailbox User->>WarpRoute: transferRemote(dest, recipient, amount) WarpRoute->>ERC20: transferFrom(User, WarpRoute, amount) WarpRoute->>ERC20: approve(ERC4626, amount) WarpRoute->>ERC4626: deposit(amount, WarpRoute) ERC4626-->>WarpRoute: shares WarpRoute->>ERC4626: convertToAssets(PRECISION) ERC4626-->>WarpRoute: exchangeRate WarpRoute->>WarpRoute: nonce += 1 WarpRoute->>Mailbox: dispatch(dest, router[dest], {recipient, shares, exchangeRate, nonce}) ``` ## `HypERC4626.handle` ```mermaid sequenceDiagram participant Recipient participant WarpRoute participant Mailbox Mailbox->>WarpRoute: handle(origin, sender, {recipient, shares, exchangeRate, nonce}) alt nonce > latestNonce && origin = collateralChain WarpRoute->>WarpRoute: latestNonce = nonce WarpRoute->>WarpRoute: latestExchangeRate = exchangeRate end WarpRoute->>WarpRoute: mint(shares, recipient) WarpRoute->>WarpRoute: balance[recipient] = shares Recipient->>WarpRoute: balanceOf(recipient) WarpRoute-->>WarpRoute: balance[recipient] * latestExchangeRate WarpRoute-->>Recipient: amount ``` ## `HypERC4626.transferRemote` ```mermaid sequenceDiagram participant User participant WarpRoute participant Mailbox User->>WarpRoute: transferRemote(dest, recipient, amount) WarpRoute-->>WarpRoute: burn(shares, User) WarpRoute->>Mailbox: dispatch(dest, router[dest], {recipient, shares}) ``` ## `HypERC4626Collateral.handle` ```mermaid sequenceDiagram participant Recipient participant ERC20 participant ERC4626 participant WarpRoute participant Mailbox Mailbox->>WarpRoute: handle(orgn, sender, {recipient, shares}) WarpRoute->>ERC4626: redeem(shares, recipient, WarpRoute) ERC4626-->>WarpRoute: amount WarpRoute->>ERC20: transfer(recipient, amount) ERC20-->>Recipient: amount ```