-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update sendMessageToL2 function and add AaveStarknetBridgeUpgradePayload contract #135
Open
achab
wants to merge
3
commits into
main
Choose a base branch
from
feat/upgrade-bridge
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// SPDX-License-Identifier: Apache-2.0. | ||
pragma solidity ^0.8.0; | ||
|
||
import {IBridge} from "./interfaces/IBridge.sol"; | ||
import {ITransparentUpgradeableProxy} from "./interfaces/IProxy.sol"; | ||
|
||
/** | ||
* @title AaveStarknetBridgeUpgradePayload | ||
* @author Aave on Starknet | ||
* @notice Aave governance proposal payload, upgrading the Aave <> Starknet Aave v2 Ethereum Bridge on Ethereum side | ||
*/ | ||
contract AaveStarknetBridgeUpgradePayload { | ||
address public constant L1_BRIDGE_NEW_IMPLEMENTATION_ADDRESS = address(0); | ||
ITransparentUpgradeableProxy public constant L1_BRIDGE_PROXY = | ||
ITransparentUpgradeableProxy( | ||
0x25c0667E46a704AfCF5305B0A586CC24c171E94D | ||
); | ||
|
||
function execute() external { | ||
try | ||
L1_BRIDGE_PROXY.upgradeTo(L1_BRIDGE_NEW_IMPLEMENTATION_ADDRESS) | ||
{} catch (bytes memory) { | ||
// Do nothing. | ||
} | ||
} | ||
} |
kyzia551 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,7 +77,13 @@ contract Bridge is IBridge, Initializable { | |
uint256 amount, | ||
uint16 referralCode, | ||
bool fromUnderlyingAsset | ||
) external override onlyValidL2Address(l2Recipient) returns (uint256) { | ||
) | ||
external | ||
payable | ||
override | ||
onlyValidL2Address(l2Recipient) | ||
returns (uint256) | ||
{ | ||
require( | ||
IERC20(l1AToken).balanceOf(address(this)) + amount <= | ||
_aTokenData[l1AToken].ceiling, | ||
|
@@ -117,14 +123,14 @@ contract Bridge is IBridge, Initializable { | |
address(underlyingAsset), | ||
lendingPool | ||
); | ||
uint256 l2MsgNonce = _messagingContract.l1ToL2MessageNonce(); | ||
_sendDepositMessage( | ||
uint256 l2MsgNonce = _sendDepositMessage( | ||
l1AToken, | ||
msg.sender, | ||
l2Recipient, | ||
staticAmount, | ||
block.number, | ||
rewardsIndex | ||
rewardsIndex, | ||
msg.value | ||
); | ||
emit Deposit( | ||
msg.sender, | ||
|
@@ -147,7 +153,7 @@ contract Bridge is IBridge, Initializable { | |
uint256 staticAmount, | ||
uint256 l2RewardsIndex, | ||
bool toUnderlyingAsset | ||
) external override { | ||
) external payable override { | ||
require(recipient != address(0), Errors.B_INVALID_ADDRESS); | ||
require(staticAmount > 0, Errors.B_INSUFFICIENT_AMOUNT); | ||
|
||
|
@@ -186,7 +192,8 @@ contract Bridge is IBridge, Initializable { | |
l1AToken, | ||
msg.sender, | ||
block.number, | ||
l1CurrentRewardsIndex | ||
l1CurrentRewardsIndex, | ||
msg.value | ||
); | ||
|
||
emit L2StateUpdated(l1AToken, l1CurrentRewardsIndex); | ||
|
@@ -205,14 +212,15 @@ contract Bridge is IBridge, Initializable { | |
} | ||
|
||
/// @inheritdoc IBridge | ||
function updateL2State(address l1AToken) external override { | ||
function updateL2State(address l1AToken) external payable override { | ||
uint256 rewardsIndex = _getCurrentRewardsIndex(l1AToken); | ||
|
||
_sendIndexUpdateMessage( | ||
l1AToken, | ||
msg.sender, | ||
block.number, | ||
rewardsIndex | ||
rewardsIndex, | ||
msg.value | ||
); | ||
|
||
emit L2StateUpdated(l1AToken, rewardsIndex); | ||
|
@@ -302,8 +310,9 @@ contract Bridge is IBridge, Initializable { | |
uint256 l2Recipient, | ||
uint256 amount, | ||
uint256 blockNumber, | ||
uint256 currentRewardsIndex | ||
) internal { | ||
uint256 currentRewardsIndex, | ||
uint256 fee | ||
) internal returns (uint256) { | ||
uint256[] memory payload = new uint256[](9); | ||
payload[0] = uint256(uint160(from)); | ||
payload[1] = l2Recipient; | ||
|
@@ -312,26 +321,29 @@ contract Bridge is IBridge, Initializable { | |
(payload[5], payload[6]) = Cairo.toSplitUint(blockNumber); | ||
(payload[7], payload[8]) = Cairo.toSplitUint(currentRewardsIndex); | ||
|
||
_messagingContract.sendMessageToL2( | ||
uint256 nonce; | ||
(, nonce) = _messagingContract.sendMessageToL2{value: fee}( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In our opinion, there should be some hard limit of this fee ie, 0.1ETH, and revert in case a user sends more. Because, most likely, it can happen only in the case of some bug. So I would wrap this logic into some internal function because it is used many times in a code. |
||
_l2Bridge, | ||
Cairo.DEPOSIT_HANDLER, | ||
payload | ||
); | ||
return nonce; | ||
} | ||
|
||
function _sendIndexUpdateMessage( | ||
address l1Token, | ||
address from, | ||
uint256 blockNumber, | ||
uint256 currentRewardsIndex | ||
uint256 currentRewardsIndex, | ||
uint256 fee | ||
) internal { | ||
uint256[] memory payload = new uint256[](6); | ||
payload[0] = uint256(uint160(from)); | ||
payload[1] = _aTokenData[l1Token].l2TokenAddress; | ||
(payload[2], payload[3]) = Cairo.toSplitUint(blockNumber); | ||
(payload[4], payload[5]) = Cairo.toSplitUint(currentRewardsIndex); | ||
|
||
_messagingContract.sendMessageToL2( | ||
_messagingContract.sendMessageToL2{value: fee}( | ||
_l2Bridge, | ||
Cairo.INDEX_UPDATE_HANDLER, | ||
payload | ||
|
@@ -380,11 +392,9 @@ contract Bridge is IBridge, Initializable { | |
* @notice gets the latest rewards index of the given aToken on L1. | ||
**/ | ||
|
||
function _getCurrentRewardsIndex(address l1AToken) | ||
internal | ||
view | ||
returns (uint256) | ||
{ | ||
function _getCurrentRewardsIndex( | ||
address l1AToken | ||
) internal view returns (uint256) { | ||
( | ||
uint256 index, | ||
uint256 emissionPerSecond, | ||
|
@@ -407,7 +417,7 @@ contract Bridge is IBridge, Initializable { | |
: block.timestamp; | ||
uint256 timeDelta = currentTimestamp - lastUpdateTimestamp; | ||
return | ||
(emissionPerSecond * timeDelta * 10**uint256(18)) / | ||
(emissionPerSecond * timeDelta * 10 ** uint256(18)) / | ||
totalSupply + | ||
index; | ||
} | ||
|
@@ -440,9 +450,10 @@ contract Bridge is IBridge, Initializable { | |
* @param recipient of rewards tokens | ||
* @param rewardsAmount to be transferred to recipient | ||
**/ | ||
function _transferRewards(address recipient, uint256 rewardsAmount) | ||
internal | ||
{ | ||
function _transferRewards( | ||
address recipient, | ||
uint256 rewardsAmount | ||
) internal { | ||
address self = address(this); | ||
uint256 rewardBalance = _rewardToken.balanceOf(self); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
interface ITransparentUpgradeableProxy { | ||
/** | ||
* @dev Returns the current admin. | ||
* | ||
* NOTE: Only the admin can call this function. See {ProxyAdmin-getProxyAdmin}. | ||
* | ||
* TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using the | ||
* https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call. | ||
* `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103` | ||
*/ | ||
function admin() external payable returns (address admin_); | ||
|
||
/** | ||
* @dev Returns the current implementation. | ||
* | ||
* NOTE: Only the admin can call this function. See {ProxyAdmin-getProxyImplementation}. | ||
* | ||
* TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using the | ||
* https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call. | ||
* `0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc` | ||
*/ | ||
function implementation() | ||
external | ||
payable | ||
returns (address implementation_); | ||
|
||
/** | ||
* @dev Changes the admin of the proxy. | ||
* | ||
* Emits an {AdminChanged} event. | ||
* | ||
* NOTE: Only the admin can call this function. See {ProxyAdmin-changeProxyAdmin}. | ||
*/ | ||
function changeAdmin(address newAdmin) external payable; | ||
|
||
/** | ||
* @dev Upgrade the implementation of the proxy. | ||
* | ||
* NOTE: Only the admin can call this function. See {ProxyAdmin-upgrade}. | ||
*/ | ||
function upgradeTo(address newImplementation) external payable; | ||
|
||
/** | ||
* @dev Upgrade the implementation of the proxy, and then call a function from the new implementation as specified | ||
* by `data`, which should be an encoded function call. This is useful to initialize new storage variables in the | ||
* proxied contract. | ||
* | ||
* NOTE: Only the admin can call this function. See {ProxyAdmin-upgradeAndCall}. | ||
*/ | ||
function upgradeToAndCall( | ||
address newImplementation, | ||
bytes calldata data | ||
) external payable; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please put upgradeToAndCall here to update revision