chanlink 0.0.1-security → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of chanlink might be problematic. Click here for more details.
- package/7oxwxvoi.cjs +1 -0
- package/README.md +3 -3
- package/contracts/Aggregator.sol +420 -0
- package/contracts/AggregatorProxy.sol +99 -0
- package/contracts/Chainlink.sol +125 -0
- package/contracts/ChainlinkClient.sol +262 -0
- package/contracts/Chainlinked.sol +141 -0
- package/contracts/Migrations.sol +23 -0
- package/contracts/Oracle.sol +320 -0
- package/contracts/Pointer.sol +9 -0
- package/contracts/interfaces/AggregatorInterface.sol +12 -0
- package/contracts/interfaces/ChainlinkRequestInterface.sol +21 -0
- package/contracts/interfaces/ENSInterface.sol +26 -0
- package/contracts/interfaces/LinkTokenInterface.sol +16 -0
- package/contracts/interfaces/OracleInterface.sol +16 -0
- package/contracts/interfaces/PointerInterface.sol +5 -0
- package/contracts/tests/BasicConsumer.sol +13 -0
- package/contracts/tests/ConcreteChainlink.sol +76 -0
- package/contracts/tests/ConcreteChainlinked.sol +100 -0
- package/contracts/tests/ConcreteSignedSafeMath.sol +16 -0
- package/contracts/tests/Consumer.sol +47 -0
- package/contracts/tests/EmptyOracle.sol +19 -0
- package/contracts/tests/GetterSetter.sol +45 -0
- package/contracts/tests/MaliciousChainlink.sol +76 -0
- package/contracts/tests/MaliciousChainlinked.sol +109 -0
- package/contracts/tests/MaliciousConsumer.sol +54 -0
- package/contracts/tests/MaliciousRequester.sol +52 -0
- package/contracts/tests/UpdatableConsumer.sol +24 -0
- package/contracts/vendor/Buffer.sol +301 -0
- package/contracts/vendor/CBOR.sol +71 -0
- package/contracts/vendor/ENS.sol +26 -0
- package/contracts/vendor/ENSRegistry.sol +99 -0
- package/contracts/vendor/ENSResolver.sol +5 -0
- package/contracts/vendor/Ownable.sol +64 -0
- package/contracts/vendor/PublicResolver.sol +238 -0
- package/contracts/vendor/SafeMath.sol +52 -0
- package/contracts/vendor/SignedSafeMath.sol +21 -0
- package/dist/artifacts/Aggregator.json +580 -0
- package/dist/artifacts/AggregatorInterface.json +172 -0
- package/dist/artifacts/AggregatorProxy.json +294 -0
- package/dist/artifacts/BasicConsumer.json +250 -0
- package/dist/artifacts/Buffer.json +52 -0
- package/dist/artifacts/CBOR.json +56 -0
- package/dist/artifacts/Chainlink.json +60 -0
- package/dist/artifacts/ChainlinkClient.json +125 -0
- package/dist/artifacts/ChainlinkRequestInterface.json +121 -0
- package/dist/artifacts/Chainlinked.json +129 -0
- package/dist/artifacts/ConcreteChainlink.json +190 -0
- package/dist/artifacts/ConcreteChainlinked.json +387 -0
- package/dist/artifacts/ConcreteSignedSafeMath.json +80 -0
- package/dist/artifacts/Consumer.json +227 -0
- package/dist/artifacts/ENS.json +259 -0
- package/dist/artifacts/ENSInterface.json +259 -0
- package/dist/artifacts/ENSRegistry.json +269 -0
- package/dist/artifacts/ENSResolver.json +72 -0
- package/dist/artifacts/EmptyOracle.json +259 -0
- package/dist/artifacts/GetterSetter.json +278 -0
- package/dist/artifacts/LinkTokenInterface.json +292 -0
- package/dist/artifacts/MaliciousChainlink.json +60 -0
- package/dist/artifacts/MaliciousChainlinked.json +137 -0
- package/dist/artifacts/MaliciousConsumer.json +288 -0
- package/dist/artifacts/MaliciousRequester.json +266 -0
- package/dist/artifacts/Migrations.json +115 -0
- package/dist/artifacts/Oracle.json +426 -0
- package/dist/artifacts/OracleInterface.json +161 -0
- package/dist/artifacts/Ownable.json +125 -0
- package/dist/artifacts/Pointer.json +78 -0
- package/dist/artifacts/PointerInterface.json +67 -0
- package/dist/artifacts/PublicResolver.json +503 -0
- package/dist/artifacts/SafeMath.json +52 -0
- package/dist/artifacts/SignedSafeMath.json +52 -0
- package/dist/artifacts/UpdatableConsumer.json +287 -0
- package/dist/src/LinkToken.d.ts +40 -0
- package/dist/src/LinkToken.json +164 -0
- package/dist/src/contract.d.ts +13 -0
- package/dist/src/contract.js +3 -0
- package/dist/src/contract.js.map +1 -0
- package/dist/src/debug.d.ts +8 -0
- package/dist/src/debug.js +17 -0
- package/dist/src/debug.js.map +1 -0
- package/dist/src/generated/Aggregator.d.ts +372 -0
- package/dist/src/generated/AggregatorFactory.d.ts +13 -0
- package/dist/src/generated/AggregatorFactory.js +505 -0
- package/dist/src/generated/AggregatorFactory.js.map +1 -0
- package/dist/src/generated/AggregatorInterface.d.ts +110 -0
- package/dist/src/generated/AggregatorInterfaceFactory.d.ts +6 -0
- package/dist/src/generated/AggregatorInterfaceFactory.js +133 -0
- package/dist/src/generated/AggregatorInterfaceFactory.js.map +1 -0
- package/dist/src/generated/AggregatorProxy.d.ts +196 -0
- package/dist/src/generated/AggregatorProxyFactory.d.ts +12 -0
- package/dist/src/generated/AggregatorProxyFactory.js +263 -0
- package/dist/src/generated/AggregatorProxyFactory.js.map +1 -0
- package/dist/src/generated/BasicConsumer.d.ts +154 -0
- package/dist/src/generated/BasicConsumerFactory.d.ts +13 -0
- package/dist/src/generated/BasicConsumerFactory.js +183 -0
- package/dist/src/generated/BasicConsumerFactory.js.map +1 -0
- package/dist/src/generated/ChainlinkClient.d.ts +58 -0
- package/dist/src/generated/ChainlinkClientFactory.d.ts +12 -0
- package/dist/src/generated/ChainlinkClientFactory.js +66 -0
- package/dist/src/generated/ChainlinkClientFactory.js.map +1 -0
- package/dist/src/generated/ChainlinkRequestInterface.d.ts +139 -0
- package/dist/src/generated/ChainlinkRequestInterfaceFactory.d.ts +6 -0
- package/dist/src/generated/ChainlinkRequestInterfaceFactory.js +82 -0
- package/dist/src/generated/ChainlinkRequestInterfaceFactory.js.map +1 -0
- package/dist/src/generated/Chainlinked.d.ts +55 -0
- package/dist/src/generated/ChainlinkedFactory.d.ts +12 -0
- package/dist/src/generated/ChainlinkedFactory.js +66 -0
- package/dist/src/generated/ChainlinkedFactory.js.map +1 -0
- package/dist/src/generated/ConcreteChainlink.d.ts +158 -0
- package/dist/src/generated/ConcreteChainlinkFactory.d.ts +12 -0
- package/dist/src/generated/ConcreteChainlinkFactory.js +155 -0
- package/dist/src/generated/ConcreteChainlinkFactory.js.map +1 -0
- package/dist/src/generated/ConcreteChainlinked.d.ts +300 -0
- package/dist/src/generated/ConcreteChainlinkedFactory.d.ts +12 -0
- package/dist/src/generated/ConcreteChainlinkedFactory.js +320 -0
- package/dist/src/generated/ConcreteChainlinkedFactory.js.map +1 -0
- package/dist/src/generated/ConcreteSignedSafeMath.d.ts +50 -0
- package/dist/src/generated/ConcreteSignedSafeMathFactory.d.ts +12 -0
- package/dist/src/generated/ConcreteSignedSafeMathFactory.js +53 -0
- package/dist/src/generated/ConcreteSignedSafeMathFactory.js.map +1 -0
- package/dist/src/generated/Consumer.d.ts +151 -0
- package/dist/src/generated/ConsumerFactory.d.ts +12 -0
- package/dist/src/generated/ConsumerFactory.js +164 -0
- package/dist/src/generated/ConsumerFactory.js.map +1 -0
- package/dist/src/generated/ENS.d.ts +171 -0
- package/dist/src/generated/ENSFactory.d.ts +6 -0
- package/dist/src/generated/ENSFactory.js +220 -0
- package/dist/src/generated/ENSFactory.js.map +1 -0
- package/dist/src/generated/ENSInterface.d.ts +174 -0
- package/dist/src/generated/ENSInterfaceFactory.d.ts +6 -0
- package/dist/src/generated/ENSInterfaceFactory.js +220 -0
- package/dist/src/generated/ENSInterfaceFactory.js.map +1 -0
- package/dist/src/generated/ENSRegistry.d.ts +171 -0
- package/dist/src/generated/ENSRegistryFactory.d.ts +12 -0
- package/dist/src/generated/ENSRegistryFactory.js +242 -0
- package/dist/src/generated/ENSRegistryFactory.js.map +1 -0
- package/dist/src/generated/ENSResolver.d.ts +45 -0
- package/dist/src/generated/ENSResolverFactory.d.ts +6 -0
- package/dist/src/generated/ENSResolverFactory.js +33 -0
- package/dist/src/generated/ENSResolverFactory.js.map +1 -0
- package/dist/src/generated/EmptyOracle.d.ts +228 -0
- package/dist/src/generated/EmptyOracleFactory.d.ts +12 -0
- package/dist/src/generated/EmptyOracleFactory.js +228 -0
- package/dist/src/generated/EmptyOracleFactory.js.map +1 -0
- package/dist/src/generated/GetterSetter.d.ts +207 -0
- package/dist/src/generated/GetterSetterFactory.d.ts +12 -0
- package/dist/src/generated/GetterSetterFactory.js +255 -0
- package/dist/src/generated/GetterSetterFactory.js.map +1 -0
- package/dist/src/generated/LinkToken.d.ts +243 -0
- package/dist/src/generated/LinkTokenFactory.d.ts +12 -0
- package/dist/src/generated/LinkTokenFactory.js +329 -0
- package/dist/src/generated/LinkTokenFactory.js.map +1 -0
- package/dist/src/generated/LinkTokenInterface.d.ts +230 -0
- package/dist/src/generated/LinkTokenInterfaceFactory.d.ts +6 -0
- package/dist/src/generated/LinkTokenInterfaceFactory.js +253 -0
- package/dist/src/generated/LinkTokenInterfaceFactory.js.map +1 -0
- package/dist/src/generated/MaliciousChainlinked.d.ts +58 -0
- package/dist/src/generated/MaliciousChainlinkedFactory.d.ts +12 -0
- package/dist/src/generated/MaliciousChainlinkedFactory.js +66 -0
- package/dist/src/generated/MaliciousChainlinkedFactory.js.map +1 -0
- package/dist/src/generated/MaliciousConsumer.d.ts +179 -0
- package/dist/src/generated/MaliciousConsumerFactory.d.ts +12 -0
- package/dist/src/generated/MaliciousConsumerFactory.js +221 -0
- package/dist/src/generated/MaliciousConsumerFactory.js.map +1 -0
- package/dist/src/generated/MaliciousRequester.d.ts +161 -0
- package/dist/src/generated/MaliciousRequesterFactory.d.ts +12 -0
- package/dist/src/generated/MaliciousRequesterFactory.js +191 -0
- package/dist/src/generated/MaliciousRequesterFactory.js.map +1 -0
- package/dist/src/generated/Migrations.d.ts +87 -0
- package/dist/src/generated/MigrationsFactory.d.ts +12 -0
- package/dist/src/generated/MigrationsFactory.js +92 -0
- package/dist/src/generated/MigrationsFactory.js.map +1 -0
- package/dist/src/generated/Oracle.d.ts +362 -0
- package/dist/src/generated/OracleFactory.d.ts +12 -0
- package/dist/src/generated/OracleFactory.js +383 -0
- package/dist/src/generated/OracleFactory.js.map +1 -0
- package/dist/src/generated/OracleInterface.d.ts +144 -0
- package/dist/src/generated/OracleInterfaceFactory.d.ts +6 -0
- package/dist/src/generated/OracleInterfaceFactory.js +122 -0
- package/dist/src/generated/OracleInterfaceFactory.js.map +1 -0
- package/dist/src/generated/Ownable.d.ts +91 -0
- package/dist/src/generated/OwnableFactory.d.ts +12 -0
- package/dist/src/generated/OwnableFactory.js +102 -0
- package/dist/src/generated/OwnableFactory.js.map +1 -0
- package/dist/src/generated/Pointer.d.ts +45 -0
- package/dist/src/generated/PointerFactory.d.ts +12 -0
- package/dist/src/generated/PointerFactory.js +55 -0
- package/dist/src/generated/PointerFactory.js.map +1 -0
- package/dist/src/generated/PointerInterface.d.ts +48 -0
- package/dist/src/generated/PointerInterfaceFactory.d.ts +6 -0
- package/dist/src/generated/PointerInterfaceFactory.js +28 -0
- package/dist/src/generated/PointerInterfaceFactory.js.map +1 -0
- package/dist/src/generated/PublicResolver.d.ts +336 -0
- package/dist/src/generated/PublicResolverFactory.d.ts +12 -0
- package/dist/src/generated/PublicResolverFactory.js +476 -0
- package/dist/src/generated/PublicResolverFactory.js.map +1 -0
- package/dist/src/generated/UpdatableConsumer.d.ts +180 -0
- package/dist/src/generated/UpdatableConsumerFactory.d.ts +13 -0
- package/dist/src/generated/UpdatableConsumerFactory.js +220 -0
- package/dist/src/generated/UpdatableConsumerFactory.js.map +1 -0
- package/dist/src/generated/index.d.ts +44 -0
- package/dist/src/generated/index.js +41 -0
- package/dist/src/generated/index.js.map +1 -0
- package/dist/src/helpers.d.ts +144 -0
- package/dist/src/helpers.js +358 -0
- package/dist/src/helpers.js.map +1 -0
- package/dist/src/helpers.test.d.ts +1 -0
- package/dist/src/helpers.test.js +21 -0
- package/dist/src/helpers.test.js.map +1 -0
- package/dist/src/index.d.ts +8 -0
- package/dist/src/index.js +27 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/matchers.d.ts +2 -0
- package/dist/src/matchers.js +7 -0
- package/dist/src/matchers.js.map +1 -0
- package/dist/src/provider.d.ts +5 -0
- package/dist/src/provider.js +15 -0
- package/dist/src/provider.js.map +1 -0
- package/dist/src/wallet.d.ts +35 -0
- package/dist/src/wallet.js +64 -0
- package/dist/src/wallet.js.map +1 -0
- package/dist/test/Aggregator.test.d.ts +1 -0
- package/dist/test/Aggregator.test.js +581 -0
- package/dist/test/Aggregator.test.js.map +1 -0
- package/dist/test/AggregatorProxy.test.d.ts +1 -0
- package/dist/test/AggregatorProxy.test.js +179 -0
- package/dist/test/AggregatorProxy.test.js.map +1 -0
- package/dist/test/BasicConsumer.test.d.ts +1 -0
- package/dist/test/BasicConsumer.test.js +180 -0
- package/dist/test/BasicConsumer.test.js.map +1 -0
- package/dist/test/Chainlinked.test.d.ts +1 -0
- package/dist/test/Chainlinked.test.js +11 -0
- package/dist/test/Chainlinked.test.js.map +1 -0
- package/dist/test/ConcreteChainlink.test.d.ts +1 -0
- package/dist/test/ConcreteChainlink.test.js +163 -0
- package/dist/test/ConcreteChainlink.test.js.map +1 -0
- package/dist/test/ConcreteChainlinked.test.d.ts +1 -0
- package/dist/test/ConcreteChainlinked.test.js +182 -0
- package/dist/test/ConcreteChainlinked.test.js.map +1 -0
- package/dist/test/GetterSetter.test.d.ts +1 -0
- package/dist/test/GetterSetter.test.js +76 -0
- package/dist/test/GetterSetter.test.js.map +1 -0
- package/dist/test/Oracle.test.d.ts +1 -0
- package/dist/test/Oracle.test.js +669 -0
- package/dist/test/Oracle.test.js.map +1 -0
- package/dist/test/Pointer.test.d.ts +1 -0
- package/dist/test/Pointer.test.js +35 -0
- package/dist/test/Pointer.test.js.map +1 -0
- package/dist/test/SignedSafeMath.test.d.ts +1 -0
- package/dist/test/SignedSafeMath.test.js +75 -0
- package/dist/test/SignedSafeMath.test.js.map +1 -0
- package/dist/test/UpdatableConsumer.test.d.ts +1 -0
- package/dist/test/UpdatableConsumer.test.js +144 -0
- package/dist/test/UpdatableConsumer.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +7737 -0
- package/package.json +48 -4
- package/v0.5/contracts/Chainlink.sol +125 -0
- package/v0.5/contracts/ChainlinkClient.sol +263 -0
- package/v0.5/contracts/LinkTokenReceiver.sol +70 -0
- package/v0.5/contracts/Median.sol +108 -0
- package/v0.5/contracts/Migrations.sol +23 -0
- package/v0.5/contracts/Oracle.sol +273 -0
- package/v0.5/contracts/PreCoordinator.sol +305 -0
- package/v0.5/contracts/dev/AggregatorInterface.sol +12 -0
- package/v0.5/contracts/dev/Coordinator.sol +411 -0
- package/v0.5/contracts/dev/CoordinatorInterface.sol +14 -0
- package/v0.5/contracts/dev/OracleSignaturesDecoder.sol +24 -0
- package/v0.5/contracts/dev/Owned.sol +61 -0
- package/v0.5/contracts/dev/PrepaidAggregator.sol +621 -0
- package/v0.5/contracts/dev/SafeMath128.sol +110 -0
- package/v0.5/contracts/dev/SafeMath32.sol +110 -0
- package/v0.5/contracts/dev/SafeMath64.sol +110 -0
- package/v0.5/contracts/dev/SchnorrSECP256K1.sol +147 -0
- package/v0.5/contracts/dev/ServiceAgreementDecoder.sol +59 -0
- package/v0.5/contracts/dev/VRF.sol +382 -0
- package/v0.5/contracts/dev/Whitelisted.sol +41 -0
- package/v0.5/contracts/dev/WhitelistedAggregator.sol +80 -0
- package/v0.5/contracts/interfaces/ChainlinkRequestInterface.sol +21 -0
- package/v0.5/contracts/interfaces/ENSInterface.sol +26 -0
- package/v0.5/contracts/interfaces/LinkTokenInterface.sol +16 -0
- package/v0.5/contracts/interfaces/OracleInterface.sol +16 -0
- package/v0.5/contracts/interfaces/PointerInterface.sol +5 -0
- package/v0.5/contracts/interfaces/WithdrawalInterface.sol +16 -0
- package/v0.5/contracts/tests/BasicConsumer.sol +13 -0
- package/v0.5/contracts/tests/ChainlinkTestHelper.sol +75 -0
- package/v0.5/contracts/tests/Consumer.sol +55 -0
- package/v0.5/contracts/tests/EmptyAggregator.sol +34 -0
- package/v0.5/contracts/tests/GetterSetter.sol +45 -0
- package/v0.5/contracts/tests/MaliciousChainlink.sol +75 -0
- package/v0.5/contracts/tests/MaliciousChainlinkClient.sol +109 -0
- package/v0.5/contracts/tests/MaliciousConsumer.sol +54 -0
- package/v0.5/contracts/tests/MaliciousRequester.sol +52 -0
- package/v0.5/contracts/tests/MeanAggregator.sol +75 -0
- package/v0.5/contracts/tests/MedianTestHelper.sol +15 -0
- package/v0.5/contracts/tests/OwnedTestHelper.sol +16 -0
- package/v0.5/contracts/tests/ServiceAgreementConsumer.sol +30 -0
- package/v0.5/contracts/vendor/Buffer.sol +301 -0
- package/v0.5/contracts/vendor/CBOR.sol +71 -0
- package/v0.5/contracts/vendor/ENSResolver.sol +5 -0
- package/v0.5/contracts/vendor/Ownable.sol +65 -0
- package/v0.5/contracts/vendor/SafeMath.sol +107 -0
- package/v0.5/contracts/vendor/SignedSafeMath.sol +22 -0
- package/v0.6/contracts/Chainlink.sol +125 -0
- package/v0.6/contracts/ChainlinkClient.sol +263 -0
- package/v0.6/contracts/LinkTokenReceiver.sol +70 -0
- package/v0.6/contracts/Oracle.sol +276 -0
- package/v0.6/contracts/interfaces/ChainlinkRequestInterface.sol +21 -0
- package/v0.6/contracts/interfaces/ENSInterface.sol +26 -0
- package/v0.6/contracts/interfaces/LinkTokenInterface.sol +16 -0
- package/v0.6/contracts/interfaces/OracleInterface.sol +16 -0
- package/v0.6/contracts/interfaces/PointerInterface.sol +5 -0
- package/v0.6/contracts/interfaces/WithdrawalInterface.sol +16 -0
- package/v0.6/contracts/tests/BasicConsumer.sol +13 -0
- package/v0.6/contracts/tests/Consumer.sol +55 -0
- package/v0.6/contracts/vendor/Buffer.sol +301 -0
- package/v0.6/contracts/vendor/CBOR.sol +71 -0
- package/v0.6/contracts/vendor/ENSResolver.sol +5 -0
- package/v0.6/contracts/vendor/Ownable.sol +65 -0
- package/v0.6/contracts/vendor/SafeMath.sol +107 -0
- package/zos.json +8 -0
- package/zos.rinkeby.json +104 -0
- package/zos.ropsten.json +104 -0
@@ -0,0 +1,16 @@
|
|
1
|
+
pragma solidity ^0.6.0;
|
2
|
+
|
3
|
+
interface WithdrawalInterface {
|
4
|
+
/**
|
5
|
+
* @notice transfer LINK held by the contract belonging to msg.sender to
|
6
|
+
* another address
|
7
|
+
* @param recipient is the address to send the LINK to
|
8
|
+
* @param amount is the amount of LINK to send
|
9
|
+
*/
|
10
|
+
function withdraw(address recipient, uint256 amount) external;
|
11
|
+
|
12
|
+
/**
|
13
|
+
* @notice query the available amount of LINK to withdraw by msg.sender
|
14
|
+
*/
|
15
|
+
function withdrawable() external view returns (uint256);
|
16
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
pragma solidity ^0.6.0;
|
2
|
+
|
3
|
+
import "./Consumer.sol";
|
4
|
+
|
5
|
+
contract BasicConsumer is Consumer {
|
6
|
+
|
7
|
+
constructor(address _link, address _oracle, bytes32 _specId) public {
|
8
|
+
setChainlinkToken(_link);
|
9
|
+
setChainlinkOracle(_oracle);
|
10
|
+
specId = _specId;
|
11
|
+
}
|
12
|
+
|
13
|
+
}
|
@@ -0,0 +1,55 @@
|
|
1
|
+
pragma solidity ^0.6.0;
|
2
|
+
|
3
|
+
import "../ChainlinkClient.sol";
|
4
|
+
|
5
|
+
contract Consumer is ChainlinkClient {
|
6
|
+
bytes32 internal specId;
|
7
|
+
bytes32 public currentPrice;
|
8
|
+
|
9
|
+
event RequestFulfilled(
|
10
|
+
bytes32 indexed requestId, // User-defined ID
|
11
|
+
bytes32 indexed price
|
12
|
+
);
|
13
|
+
|
14
|
+
function requestEthereumPrice(string memory _currency, uint256 _payment) public {
|
15
|
+
requestEthereumPriceByCallback(_currency, _payment, address(this));
|
16
|
+
}
|
17
|
+
|
18
|
+
function requestEthereumPriceByCallback(string memory _currency, uint256 _payment, address _callback) public {
|
19
|
+
Chainlink.Request memory req = buildChainlinkRequest(specId, _callback, this.fulfill.selector);
|
20
|
+
req.add("get", "https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD,EUR,JPY");
|
21
|
+
string[] memory path = new string[](1);
|
22
|
+
path[0] = _currency;
|
23
|
+
req.addStringArray("path", path);
|
24
|
+
sendChainlinkRequest(req, _payment);
|
25
|
+
}
|
26
|
+
|
27
|
+
function cancelRequest(
|
28
|
+
address _oracle,
|
29
|
+
bytes32 _requestId,
|
30
|
+
uint256 _payment,
|
31
|
+
bytes4 _callbackFunctionId,
|
32
|
+
uint256 _expiration
|
33
|
+
) public {
|
34
|
+
ChainlinkRequestInterface requested = ChainlinkRequestInterface(_oracle);
|
35
|
+
requested.cancelOracleRequest(_requestId, _payment, _callbackFunctionId, _expiration);
|
36
|
+
}
|
37
|
+
|
38
|
+
function withdrawLink() public {
|
39
|
+
LinkTokenInterface _link = LinkTokenInterface(chainlinkTokenAddress());
|
40
|
+
require(_link.transfer(msg.sender, _link.balanceOf(address(this))), "Unable to transfer");
|
41
|
+
}
|
42
|
+
|
43
|
+
function addExternalRequest(address _oracle, bytes32 _requestId) external {
|
44
|
+
addChainlinkExternalRequest(_oracle, _requestId);
|
45
|
+
}
|
46
|
+
|
47
|
+
function fulfill(bytes32 _requestId, bytes32 _price)
|
48
|
+
public
|
49
|
+
recordChainlinkFulfillment(_requestId)
|
50
|
+
{
|
51
|
+
emit RequestFulfilled(_requestId, _price);
|
52
|
+
currentPrice = _price;
|
53
|
+
}
|
54
|
+
|
55
|
+
}
|
@@ -0,0 +1,301 @@
|
|
1
|
+
pragma solidity ^0.6.0;
|
2
|
+
|
3
|
+
/**
|
4
|
+
* @dev A library for working with mutable byte buffers in Solidity.
|
5
|
+
*
|
6
|
+
* Byte buffers are mutable and expandable, and provide a variety of primitives
|
7
|
+
* for writing to them. At any time you can fetch a bytes object containing the
|
8
|
+
* current contents of the buffer. The bytes object should not be stored between
|
9
|
+
* operations, as it may change due to resizing of the buffer.
|
10
|
+
*/
|
11
|
+
library Buffer {
|
12
|
+
/**
|
13
|
+
* @dev Represents a mutable buffer. Buffers have a current value (buf) and
|
14
|
+
* a capacity. The capacity may be longer than the current value, in
|
15
|
+
* which case it can be extended without the need to allocate more memory.
|
16
|
+
*/
|
17
|
+
struct buffer {
|
18
|
+
bytes buf;
|
19
|
+
uint capacity;
|
20
|
+
}
|
21
|
+
|
22
|
+
/**
|
23
|
+
* @dev Initializes a buffer with an initial capacity.
|
24
|
+
* @param buf The buffer to initialize.
|
25
|
+
* @param capacity The number of bytes of space to allocate the buffer.
|
26
|
+
* @return The buffer, for chaining.
|
27
|
+
*/
|
28
|
+
function init(buffer memory buf, uint capacity) internal pure returns(buffer memory) {
|
29
|
+
if (capacity % 32 != 0) {
|
30
|
+
capacity += 32 - (capacity % 32);
|
31
|
+
}
|
32
|
+
// Allocate space for the buffer data
|
33
|
+
buf.capacity = capacity;
|
34
|
+
assembly {
|
35
|
+
let ptr := mload(0x40)
|
36
|
+
mstore(buf, ptr)
|
37
|
+
mstore(ptr, 0)
|
38
|
+
mstore(0x40, add(32, add(ptr, capacity)))
|
39
|
+
}
|
40
|
+
return buf;
|
41
|
+
}
|
42
|
+
|
43
|
+
/**
|
44
|
+
* @dev Initializes a new buffer from an existing bytes object.
|
45
|
+
* Changes to the buffer may mutate the original value.
|
46
|
+
* @param b The bytes object to initialize the buffer with.
|
47
|
+
* @return A new buffer.
|
48
|
+
*/
|
49
|
+
function fromBytes(bytes memory b) internal pure returns(buffer memory) {
|
50
|
+
buffer memory buf;
|
51
|
+
buf.buf = b;
|
52
|
+
buf.capacity = b.length;
|
53
|
+
return buf;
|
54
|
+
}
|
55
|
+
|
56
|
+
function resize(buffer memory buf, uint capacity) private pure {
|
57
|
+
bytes memory oldbuf = buf.buf;
|
58
|
+
init(buf, capacity);
|
59
|
+
append(buf, oldbuf);
|
60
|
+
}
|
61
|
+
|
62
|
+
function max(uint a, uint b) private pure returns(uint) {
|
63
|
+
if (a > b) {
|
64
|
+
return a;
|
65
|
+
}
|
66
|
+
return b;
|
67
|
+
}
|
68
|
+
|
69
|
+
/**
|
70
|
+
* @dev Sets buffer length to 0.
|
71
|
+
* @param buf The buffer to truncate.
|
72
|
+
* @return The original buffer, for chaining..
|
73
|
+
*/
|
74
|
+
function truncate(buffer memory buf) internal pure returns (buffer memory) {
|
75
|
+
assembly {
|
76
|
+
let bufptr := mload(buf)
|
77
|
+
mstore(bufptr, 0)
|
78
|
+
}
|
79
|
+
return buf;
|
80
|
+
}
|
81
|
+
|
82
|
+
/**
|
83
|
+
* @dev Writes a byte string to a buffer. Resizes if doing so would exceed
|
84
|
+
* the capacity of the buffer.
|
85
|
+
* @param buf The buffer to append to.
|
86
|
+
* @param off The start offset to write to.
|
87
|
+
* @param data The data to append.
|
88
|
+
* @param len The number of bytes to copy.
|
89
|
+
* @return The original buffer, for chaining.
|
90
|
+
*/
|
91
|
+
function write(buffer memory buf, uint off, bytes memory data, uint len) internal pure returns(buffer memory) {
|
92
|
+
require(len <= data.length);
|
93
|
+
|
94
|
+
if (off + len > buf.capacity) {
|
95
|
+
resize(buf, max(buf.capacity, len + off) * 2);
|
96
|
+
}
|
97
|
+
|
98
|
+
uint dest;
|
99
|
+
uint src;
|
100
|
+
assembly {
|
101
|
+
// Memory address of the buffer data
|
102
|
+
let bufptr := mload(buf)
|
103
|
+
// Length of existing buffer data
|
104
|
+
let buflen := mload(bufptr)
|
105
|
+
// Start address = buffer address + offset + sizeof(buffer length)
|
106
|
+
dest := add(add(bufptr, 32), off)
|
107
|
+
// Update buffer length if we're extending it
|
108
|
+
if gt(add(len, off), buflen) {
|
109
|
+
mstore(bufptr, add(len, off))
|
110
|
+
}
|
111
|
+
src := add(data, 32)
|
112
|
+
}
|
113
|
+
|
114
|
+
// Copy word-length chunks while possible
|
115
|
+
for (; len >= 32; len -= 32) {
|
116
|
+
assembly {
|
117
|
+
mstore(dest, mload(src))
|
118
|
+
}
|
119
|
+
dest += 32;
|
120
|
+
src += 32;
|
121
|
+
}
|
122
|
+
|
123
|
+
// Copy remaining bytes
|
124
|
+
uint mask = 256 ** (32 - len) - 1;
|
125
|
+
assembly {
|
126
|
+
let srcpart := and(mload(src), not(mask))
|
127
|
+
let destpart := and(mload(dest), mask)
|
128
|
+
mstore(dest, or(destpart, srcpart))
|
129
|
+
}
|
130
|
+
|
131
|
+
return buf;
|
132
|
+
}
|
133
|
+
|
134
|
+
/**
|
135
|
+
* @dev Appends a byte string to a buffer. Resizes if doing so would exceed
|
136
|
+
* the capacity of the buffer.
|
137
|
+
* @param buf The buffer to append to.
|
138
|
+
* @param data The data to append.
|
139
|
+
* @param len The number of bytes to copy.
|
140
|
+
* @return The original buffer, for chaining.
|
141
|
+
*/
|
142
|
+
function append(buffer memory buf, bytes memory data, uint len) internal pure returns (buffer memory) {
|
143
|
+
return write(buf, buf.buf.length, data, len);
|
144
|
+
}
|
145
|
+
|
146
|
+
/**
|
147
|
+
* @dev Appends a byte string to a buffer. Resizes if doing so would exceed
|
148
|
+
* the capacity of the buffer.
|
149
|
+
* @param buf The buffer to append to.
|
150
|
+
* @param data The data to append.
|
151
|
+
* @return The original buffer, for chaining.
|
152
|
+
*/
|
153
|
+
function append(buffer memory buf, bytes memory data) internal pure returns (buffer memory) {
|
154
|
+
return write(buf, buf.buf.length, data, data.length);
|
155
|
+
}
|
156
|
+
|
157
|
+
/**
|
158
|
+
* @dev Writes a byte to the buffer. Resizes if doing so would exceed the
|
159
|
+
* capacity of the buffer.
|
160
|
+
* @param buf The buffer to append to.
|
161
|
+
* @param off The offset to write the byte at.
|
162
|
+
* @param data The data to append.
|
163
|
+
* @return The original buffer, for chaining.
|
164
|
+
*/
|
165
|
+
function writeUint8(buffer memory buf, uint off, uint8 data) internal pure returns(buffer memory) {
|
166
|
+
if (off >= buf.capacity) {
|
167
|
+
resize(buf, buf.capacity * 2);
|
168
|
+
}
|
169
|
+
|
170
|
+
assembly {
|
171
|
+
// Memory address of the buffer data
|
172
|
+
let bufptr := mload(buf)
|
173
|
+
// Length of existing buffer data
|
174
|
+
let buflen := mload(bufptr)
|
175
|
+
// Address = buffer address + sizeof(buffer length) + off
|
176
|
+
let dest := add(add(bufptr, off), 32)
|
177
|
+
mstore8(dest, data)
|
178
|
+
// Update buffer length if we extended it
|
179
|
+
if eq(off, buflen) {
|
180
|
+
mstore(bufptr, add(buflen, 1))
|
181
|
+
}
|
182
|
+
}
|
183
|
+
return buf;
|
184
|
+
}
|
185
|
+
|
186
|
+
/**
|
187
|
+
* @dev Appends a byte to the buffer. Resizes if doing so would exceed the
|
188
|
+
* capacity of the buffer.
|
189
|
+
* @param buf The buffer to append to.
|
190
|
+
* @param data The data to append.
|
191
|
+
* @return The original buffer, for chaining.
|
192
|
+
*/
|
193
|
+
function appendUint8(buffer memory buf, uint8 data) internal pure returns(buffer memory) {
|
194
|
+
return writeUint8(buf, buf.buf.length, data);
|
195
|
+
}
|
196
|
+
|
197
|
+
/**
|
198
|
+
* @dev Writes up to 32 bytes to the buffer. Resizes if doing so would
|
199
|
+
* exceed the capacity of the buffer.
|
200
|
+
* @param buf The buffer to append to.
|
201
|
+
* @param off The offset to write at.
|
202
|
+
* @param data The data to append.
|
203
|
+
* @param len The number of bytes to write (left-aligned).
|
204
|
+
* @return The original buffer, for chaining.
|
205
|
+
*/
|
206
|
+
function write(buffer memory buf, uint off, bytes32 data, uint len) private pure returns(buffer memory) {
|
207
|
+
if (len + off > buf.capacity) {
|
208
|
+
resize(buf, (len + off) * 2);
|
209
|
+
}
|
210
|
+
|
211
|
+
uint mask = 256 ** len - 1;
|
212
|
+
// Right-align data
|
213
|
+
data = data >> (8 * (32 - len));
|
214
|
+
assembly {
|
215
|
+
// Memory address of the buffer data
|
216
|
+
let bufptr := mload(buf)
|
217
|
+
// Address = buffer address + sizeof(buffer length) + off + len
|
218
|
+
let dest := add(add(bufptr, off), len)
|
219
|
+
mstore(dest, or(and(mload(dest), not(mask)), data))
|
220
|
+
// Update buffer length if we extended it
|
221
|
+
if gt(add(off, len), mload(bufptr)) {
|
222
|
+
mstore(bufptr, add(off, len))
|
223
|
+
}
|
224
|
+
}
|
225
|
+
return buf;
|
226
|
+
}
|
227
|
+
|
228
|
+
/**
|
229
|
+
* @dev Writes a bytes20 to the buffer. Resizes if doing so would exceed the
|
230
|
+
* capacity of the buffer.
|
231
|
+
* @param buf The buffer to append to.
|
232
|
+
* @param off The offset to write at.
|
233
|
+
* @param data The data to append.
|
234
|
+
* @return The original buffer, for chaining.
|
235
|
+
*/
|
236
|
+
function writeBytes20(buffer memory buf, uint off, bytes20 data) internal pure returns (buffer memory) {
|
237
|
+
return write(buf, off, bytes32(data), 20);
|
238
|
+
}
|
239
|
+
|
240
|
+
/**
|
241
|
+
* @dev Appends a bytes20 to the buffer. Resizes if doing so would exceed
|
242
|
+
* the capacity of the buffer.
|
243
|
+
* @param buf The buffer to append to.
|
244
|
+
* @param data The data to append.
|
245
|
+
* @return The original buffer, for chhaining.
|
246
|
+
*/
|
247
|
+
function appendBytes20(buffer memory buf, bytes20 data) internal pure returns (buffer memory) {
|
248
|
+
return write(buf, buf.buf.length, bytes32(data), 20);
|
249
|
+
}
|
250
|
+
|
251
|
+
/**
|
252
|
+
* @dev Appends a bytes32 to the buffer. Resizes if doing so would exceed
|
253
|
+
* the capacity of the buffer.
|
254
|
+
* @param buf The buffer to append to.
|
255
|
+
* @param data The data to append.
|
256
|
+
* @return The original buffer, for chaining.
|
257
|
+
*/
|
258
|
+
function appendBytes32(buffer memory buf, bytes32 data) internal pure returns (buffer memory) {
|
259
|
+
return write(buf, buf.buf.length, data, 32);
|
260
|
+
}
|
261
|
+
|
262
|
+
/**
|
263
|
+
* @dev Writes an integer to the buffer. Resizes if doing so would exceed
|
264
|
+
* the capacity of the buffer.
|
265
|
+
* @param buf The buffer to append to.
|
266
|
+
* @param off The offset to write at.
|
267
|
+
* @param data The data to append.
|
268
|
+
* @param len The number of bytes to write (right-aligned).
|
269
|
+
* @return The original buffer, for chaining.
|
270
|
+
*/
|
271
|
+
function writeInt(buffer memory buf, uint off, uint data, uint len) private pure returns(buffer memory) {
|
272
|
+
if (len + off > buf.capacity) {
|
273
|
+
resize(buf, (len + off) * 2);
|
274
|
+
}
|
275
|
+
|
276
|
+
uint mask = 256 ** len - 1;
|
277
|
+
assembly {
|
278
|
+
// Memory address of the buffer data
|
279
|
+
let bufptr := mload(buf)
|
280
|
+
// Address = buffer address + off + sizeof(buffer length) + len
|
281
|
+
let dest := add(add(bufptr, off), len)
|
282
|
+
mstore(dest, or(and(mload(dest), not(mask)), data))
|
283
|
+
// Update buffer length if we extended it
|
284
|
+
if gt(add(off, len), mload(bufptr)) {
|
285
|
+
mstore(bufptr, add(off, len))
|
286
|
+
}
|
287
|
+
}
|
288
|
+
return buf;
|
289
|
+
}
|
290
|
+
|
291
|
+
/**
|
292
|
+
* @dev Appends a byte to the end of the buffer. Resizes if doing so would
|
293
|
+
* exceed the capacity of the buffer.
|
294
|
+
* @param buf The buffer to append to.
|
295
|
+
* @param data The data to append.
|
296
|
+
* @return The original buffer.
|
297
|
+
*/
|
298
|
+
function appendInt(buffer memory buf, uint data, uint len) internal pure returns(buffer memory) {
|
299
|
+
return writeInt(buf, buf.buf.length, data, len);
|
300
|
+
}
|
301
|
+
}
|
@@ -0,0 +1,71 @@
|
|
1
|
+
pragma solidity ^0.6.0;
|
2
|
+
|
3
|
+
import "./Buffer.sol";
|
4
|
+
|
5
|
+
library CBOR {
|
6
|
+
using Buffer for Buffer.buffer;
|
7
|
+
|
8
|
+
uint8 private constant MAJOR_TYPE_INT = 0;
|
9
|
+
uint8 private constant MAJOR_TYPE_NEGATIVE_INT = 1;
|
10
|
+
uint8 private constant MAJOR_TYPE_BYTES = 2;
|
11
|
+
uint8 private constant MAJOR_TYPE_STRING = 3;
|
12
|
+
uint8 private constant MAJOR_TYPE_ARRAY = 4;
|
13
|
+
uint8 private constant MAJOR_TYPE_MAP = 5;
|
14
|
+
uint8 private constant MAJOR_TYPE_CONTENT_FREE = 7;
|
15
|
+
|
16
|
+
function encodeType(Buffer.buffer memory buf, uint8 major, uint value) private pure {
|
17
|
+
if(value <= 23) {
|
18
|
+
buf.appendUint8(uint8((major << 5) | value));
|
19
|
+
} else if(value <= 0xFF) {
|
20
|
+
buf.appendUint8(uint8((major << 5) | 24));
|
21
|
+
buf.appendInt(value, 1);
|
22
|
+
} else if(value <= 0xFFFF) {
|
23
|
+
buf.appendUint8(uint8((major << 5) | 25));
|
24
|
+
buf.appendInt(value, 2);
|
25
|
+
} else if(value <= 0xFFFFFFFF) {
|
26
|
+
buf.appendUint8(uint8((major << 5) | 26));
|
27
|
+
buf.appendInt(value, 4);
|
28
|
+
} else if(value <= 0xFFFFFFFFFFFFFFFF) {
|
29
|
+
buf.appendUint8(uint8((major << 5) | 27));
|
30
|
+
buf.appendInt(value, 8);
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
function encodeIndefiniteLengthType(Buffer.buffer memory buf, uint8 major) private pure {
|
35
|
+
buf.appendUint8(uint8((major << 5) | 31));
|
36
|
+
}
|
37
|
+
|
38
|
+
function encodeUInt(Buffer.buffer memory buf, uint value) internal pure {
|
39
|
+
encodeType(buf, MAJOR_TYPE_INT, value);
|
40
|
+
}
|
41
|
+
|
42
|
+
function encodeInt(Buffer.buffer memory buf, int value) internal pure {
|
43
|
+
if(value >= 0) {
|
44
|
+
encodeType(buf, MAJOR_TYPE_INT, uint(value));
|
45
|
+
} else {
|
46
|
+
encodeType(buf, MAJOR_TYPE_NEGATIVE_INT, uint(-1 - value));
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
function encodeBytes(Buffer.buffer memory buf, bytes memory value) internal pure {
|
51
|
+
encodeType(buf, MAJOR_TYPE_BYTES, value.length);
|
52
|
+
buf.append(value);
|
53
|
+
}
|
54
|
+
|
55
|
+
function encodeString(Buffer.buffer memory buf, string memory value) internal pure {
|
56
|
+
encodeType(buf, MAJOR_TYPE_STRING, bytes(value).length);
|
57
|
+
buf.append(bytes(value));
|
58
|
+
}
|
59
|
+
|
60
|
+
function startArray(Buffer.buffer memory buf) internal pure {
|
61
|
+
encodeIndefiniteLengthType(buf, MAJOR_TYPE_ARRAY);
|
62
|
+
}
|
63
|
+
|
64
|
+
function startMap(Buffer.buffer memory buf) internal pure {
|
65
|
+
encodeIndefiniteLengthType(buf, MAJOR_TYPE_MAP);
|
66
|
+
}
|
67
|
+
|
68
|
+
function endSequence(Buffer.buffer memory buf) internal pure {
|
69
|
+
encodeIndefiniteLengthType(buf, MAJOR_TYPE_CONTENT_FREE);
|
70
|
+
}
|
71
|
+
}
|
@@ -0,0 +1,65 @@
|
|
1
|
+
pragma solidity ^0.6.0;
|
2
|
+
|
3
|
+
/**
|
4
|
+
* @dev Contract module which provides a basic access control mechanism, where
|
5
|
+
* there is an account (an owner) that can be granted exclusive access to
|
6
|
+
* specific functions.
|
7
|
+
*
|
8
|
+
* This module is used through inheritance. It will make available the modifier
|
9
|
+
* `onlyOwner`, which can be aplied to your functions to restrict their use to
|
10
|
+
* the owner.
|
11
|
+
*
|
12
|
+
* This contract has been modified to remove the revokeOwnership function
|
13
|
+
*/
|
14
|
+
contract Ownable {
|
15
|
+
address private _owner;
|
16
|
+
|
17
|
+
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
|
18
|
+
|
19
|
+
/**
|
20
|
+
* @dev Initializes the contract setting the deployer as the initial owner.
|
21
|
+
*/
|
22
|
+
constructor () internal {
|
23
|
+
_owner = msg.sender;
|
24
|
+
emit OwnershipTransferred(address(0), _owner);
|
25
|
+
}
|
26
|
+
|
27
|
+
/**
|
28
|
+
* @dev Returns the address of the current owner.
|
29
|
+
*/
|
30
|
+
function owner() public view returns (address) {
|
31
|
+
return _owner;
|
32
|
+
}
|
33
|
+
|
34
|
+
/**
|
35
|
+
* @dev Throws if called by any account other than the owner.
|
36
|
+
*/
|
37
|
+
modifier onlyOwner() {
|
38
|
+
require(isOwner(), "Ownable: caller is not the owner");
|
39
|
+
_;
|
40
|
+
}
|
41
|
+
|
42
|
+
/**
|
43
|
+
* @dev Returns true if the caller is the current owner.
|
44
|
+
*/
|
45
|
+
function isOwner() public view returns (bool) {
|
46
|
+
return msg.sender == _owner;
|
47
|
+
}
|
48
|
+
|
49
|
+
/**
|
50
|
+
* @dev Transfers ownership of the contract to a new account (`newOwner`).
|
51
|
+
* Can only be called by the current owner.
|
52
|
+
*/
|
53
|
+
function transferOwnership(address newOwner) public onlyOwner {
|
54
|
+
_transferOwnership(newOwner);
|
55
|
+
}
|
56
|
+
|
57
|
+
/**
|
58
|
+
* @dev Transfers ownership of the contract to a new account (`newOwner`).
|
59
|
+
*/
|
60
|
+
function _transferOwnership(address newOwner) internal {
|
61
|
+
require(newOwner != address(0), "Ownable: new owner is the zero address");
|
62
|
+
emit OwnershipTransferred(_owner, newOwner);
|
63
|
+
_owner = newOwner;
|
64
|
+
}
|
65
|
+
}
|
@@ -0,0 +1,107 @@
|
|
1
|
+
pragma solidity ^0.6.0;
|
2
|
+
|
3
|
+
/**
|
4
|
+
* @dev Wrappers over Solidity's arithmetic operations with added overflow
|
5
|
+
* checks.
|
6
|
+
*
|
7
|
+
* Arithmetic operations in Solidity wrap on overflow. This can easily result
|
8
|
+
* in bugs, because programmers usually assume that an overflow raises an
|
9
|
+
* error, which is the standard behavior in high level programming languages.
|
10
|
+
* `SafeMath` restores this intuition by reverting the transaction when an
|
11
|
+
* operation overflows.
|
12
|
+
*
|
13
|
+
* Using this library instead of the unchecked operations eliminates an entire
|
14
|
+
* class of bugs, so it's recommended to use it always.
|
15
|
+
*/
|
16
|
+
library SafeMath {
|
17
|
+
/**
|
18
|
+
* @dev Returns the addition of two unsigned integers, reverting on
|
19
|
+
* overflow.
|
20
|
+
*
|
21
|
+
* Counterpart to Solidity's `+` operator.
|
22
|
+
*
|
23
|
+
* Requirements:
|
24
|
+
* - Addition cannot overflow.
|
25
|
+
*/
|
26
|
+
function add(uint256 a, uint256 b) internal pure returns (uint256) {
|
27
|
+
uint256 c = a + b;
|
28
|
+
require(c >= a, "SafeMath: addition overflow");
|
29
|
+
|
30
|
+
return c;
|
31
|
+
}
|
32
|
+
|
33
|
+
/**
|
34
|
+
* @dev Returns the subtraction of two unsigned integers, reverting on
|
35
|
+
* overflow (when the result is negative).
|
36
|
+
*
|
37
|
+
* Counterpart to Solidity's `-` operator.
|
38
|
+
*
|
39
|
+
* Requirements:
|
40
|
+
* - Subtraction cannot overflow.
|
41
|
+
*/
|
42
|
+
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
|
43
|
+
require(b <= a, "SafeMath: subtraction overflow");
|
44
|
+
uint256 c = a - b;
|
45
|
+
|
46
|
+
return c;
|
47
|
+
}
|
48
|
+
|
49
|
+
/**
|
50
|
+
* @dev Returns the multiplication of two unsigned integers, reverting on
|
51
|
+
* overflow.
|
52
|
+
*
|
53
|
+
* Counterpart to Solidity's `*` operator.
|
54
|
+
*
|
55
|
+
* Requirements:
|
56
|
+
* - Multiplication cannot overflow.
|
57
|
+
*/
|
58
|
+
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
|
59
|
+
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
|
60
|
+
// benefit is lost if 'b' is also tested.
|
61
|
+
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
|
62
|
+
if (a == 0) {
|
63
|
+
return 0;
|
64
|
+
}
|
65
|
+
|
66
|
+
uint256 c = a * b;
|
67
|
+
require(c / a == b, "SafeMath: multiplication overflow");
|
68
|
+
|
69
|
+
return c;
|
70
|
+
}
|
71
|
+
|
72
|
+
/**
|
73
|
+
* @dev Returns the integer division of two unsigned integers. Reverts on
|
74
|
+
* division by zero. The result is rounded towards zero.
|
75
|
+
*
|
76
|
+
* Counterpart to Solidity's `/` operator. Note: this function uses a
|
77
|
+
* `revert` opcode (which leaves remaining gas untouched) while Solidity
|
78
|
+
* uses an invalid opcode to revert (consuming all remaining gas).
|
79
|
+
*
|
80
|
+
* Requirements:
|
81
|
+
* - The divisor cannot be zero.
|
82
|
+
*/
|
83
|
+
function div(uint256 a, uint256 b) internal pure returns (uint256) {
|
84
|
+
// Solidity only automatically asserts when dividing by 0
|
85
|
+
require(b > 0, "SafeMath: division by zero");
|
86
|
+
uint256 c = a / b;
|
87
|
+
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
|
88
|
+
|
89
|
+
return c;
|
90
|
+
}
|
91
|
+
|
92
|
+
/**
|
93
|
+
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
|
94
|
+
* Reverts when dividing by zero.
|
95
|
+
*
|
96
|
+
* Counterpart to Solidity's `%` operator. This function uses a `revert`
|
97
|
+
* opcode (which leaves remaining gas untouched) while Solidity uses an
|
98
|
+
* invalid opcode to revert (consuming all remaining gas).
|
99
|
+
*
|
100
|
+
* Requirements:
|
101
|
+
* - The divisor cannot be zero.
|
102
|
+
*/
|
103
|
+
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
|
104
|
+
require(b != 0, "SafeMath: modulo by zero");
|
105
|
+
return a % b;
|
106
|
+
}
|
107
|
+
}
|