Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
Added freesGasTokensFromCollector.
Browse files Browse the repository at this point in the history
To handle the case where GST2 is being traded and the balanceOf checks become confusing
  • Loading branch information
dekz committed Mar 25, 2020
1 parent c9b9aab commit a069919
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ contract CurveBridge is
bytes calldata bridgeData
)
external
burnsGasTokens
freesGasTokensFromCollector
returns (bytes4 success)
{
// Decode the bridge data to get the Curve metadata.
Expand Down
24 changes: 19 additions & 5 deletions contracts/asset-proxy/contracts/src/bridges/MixinGasToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,32 @@ import "../interfaces/IGasToken.sol";

contract MixinGasToken is
DeploymentConstants
{
{

/// @dev Burns gas tokens based on the amount of gas consumed in the function
modifier burnsGasTokens {
/// @dev Frees gas tokens based on the amount of gas consumed in the function
modifier freesGasTokens {
uint256 gasBefore = gasleft();
_;
IGasToken gst = IGasToken(_getGstAddress());
if (address(gst) != address(0) && msg.sender == _getERC20BridgeProxyAddress()) {
if (address(gst) != address(0)) {
// (gasUsed + FREE_BASE) / (2 * REIMBURSE - FREE_TOKEN)
// 14154 2400 6870
// 14154 24000 6870
uint256 value = (gasBefore - gasleft() + 14154) / 41130;
gst.freeUpTo(value);
}
}

/// @dev Frees gas tokens using the balance of `from`. Amount freed is based
/// on the gas consumed in the function
modifier freesGasTokensFromCollector() {
uint256 gasBefore = gasleft();
_;
IGasToken gst = IGasToken(_getGstAddress());
if (address(gst) != address(0)) {
// (gasUsed + FREE_BASE) / (2 * REIMBURSE - FREE_TOKEN)
// 14154 24000 6870
uint256 value = (gasBefore - gasleft() + 14154) / 41130;
gst.freeFromUpTo(_getGstCollectorAddress(), value);
}
}
}
14 changes: 14 additions & 0 deletions contracts/utils/contracts/src/DeploymentConstants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ contract DeploymentConstants {
address constant private DYDX_ADDRESS = 0x1E0447b19BB6EcFdAe1e4AE1694b0C3659614e4e;
/// @dev Mainnet address of the GST2 contract
address constant private GST_ADDRESS = 0x0000000000b3F879cb30FE243b4Dfee438691c04;
/// @dev Mainnet address of the GST Collector
address constant private GST_COLLECTOR_ADDRESS = address(0);
// /// @dev Kovan address of the GST2 contract
// address constant private GST_ADDRESS = address(0);
// /// @dev Kovan address of the GST Collector
// address constant private GST_COLLECTOR_ADDRESS = address(0);

/// @dev Overridable way to get the `KyberNetworkProxy` address.
/// @return kyberAddress The `IKyberNetworkProxy` address.
Expand Down Expand Up @@ -158,4 +162,14 @@ contract DeploymentConstants {
{
return GST_ADDRESS;
}

/// @dev An overridable way to retrieve the GST Collector address.
/// @return collector The GST collector address.
function _getGstCollectorAddress()
internal
view
returns (address collector)
{
return GST_COLLECTOR_ADDRESS;
}
}

0 comments on commit a069919

Please sign in to comment.