Skip to content

Instantly share code, notes, and snippets.

@Alirun
Created April 14, 2020 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alirun/84c95a15bda0338dc58ee8898887f4df to your computer and use it in GitHub Desktop.
Save Alirun/84c95a15bda0338dc58ee8898887f4df to your computer and use it in GitHub Desktop.
Gas consumption test https://opium.network
The software and documentation available in this repository (the "Software") is protected by copyright law and accessible pursuant to the license set forth below. Copyright © 2020 Blockeys BV. All rights reserved.
Permission is hereby granted, free of charge, to any person or organization obtaining the Software (the “Licensee”) to privately study, review, and analyze the Software. Licensee shall not use the Software for any other purpose. Licensee shall not modify, transfer, assign, share, or sub-license the Software or any derivative works of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
pragma solidity ^0.5.0;
pragma experimental ABIEncoderV2;
/// @title Opium.Lib.LibDerivative contract should be inherited by contracts that use Derivative structure and calculate derivativeHash
contract LibDerivative {
// Opium derivative structure (ticker) definition
struct Derivative {
// Margin parameter for syntheticId
uint256 margin;
// Maturity of derivative
uint256 endTime;
// Additional parameters for syntheticId
uint256[] params;
// oracleId of derivative
address oracleId;
// Margin token address of derivative
address token;
// syntheticId of derivative
address syntheticId;
}
/// @notice Calculates hash of provided Derivative
/// @param _derivative Derivative Instance of derivative to hash
/// @return derivativeHash bytes32 Derivative hash
function getDerivativeHash(Derivative memory _derivative) public pure returns (bytes32 derivativeHash) {
derivativeHash = keccak256(abi.encodePacked(
_derivative.margin,
_derivative.endTime,
_derivative.params,
_derivative.oracleId,
_derivative.token,
_derivative.syntheticId
));
}
}
contract TestGasConsumption is LibDerivative {
event Created(bytes32 hash, Derivative derivative);
Derivative public derivative;
bytes32 public hash;
function _getD() private returns (Derivative memory derivative, bytes32 hash) {
uint[] memory params = new uint[](3);
params[0] = 7e3;
params[1] = 2e3;
params[2] = 6e3;
derivative = Derivative(
8e10,
2e3,
params,
address(this),
address(this),
address(this)
);
hash = getDerivativeHash(derivative);
}
function saveDerivateive() public {
(Derivative memory _derivative, ) = _getD();
derivative = _derivative;
}
function saveHash() public {
(Derivative memory _derivative, bytes32 _hash) = _getD();
hash = _hash;
emit Created(_hash, _derivative);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment