-
Notifications
You must be signed in to change notification settings - Fork 10
/
DeFiExample.sol
84 lines (64 loc) · 2.13 KB
/
DeFiExample.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// SPDX-License-Identifier: MIT
pragma solidity 0.6.12;
interface SecurityOracle {
function getSecurityScore(address contractAddress)
external
view
returns (uint8);
function getSecurityScore(
address contractAddress,
string calldata functionSignature
) external view returns (uint8);
function getSecurityScoreBytes4(
address contractAddress,
bytes4 functionSignature
) external view returns (uint8);
function getSecurityScores(
address[] calldata addresses,
bytes4[] calldata functionSignatures
) external view returns (uint8[] memory);
}
contract DeFiExample {
event Score(uint8 score);
event SuccessBytes4(address addr, bytes4 sig);
event SuccessString(address addr, string sig);
address private _securityOracleAddress;
constructor(address securityOracleAddress) public {
_securityOracleAddress = securityOracleAddress;
}
function callGetSecurityScore(address addr, string memory sig) public {
uint8 score = SecurityOracle(_securityOracleAddress).getSecurityScore(
addr,
sig
);
emit Score(score);
require(score > 100, "revert due to high security risk");
emit SuccessString(addr, sig);
}
function callGetSecurityScoreBytes4(address addr, bytes4 sig) public {
uint8 score = SecurityOracle(_securityOracleAddress).getSecurityScoreBytes4(
addr,
sig
);
emit Score(score);
require(score > 100, "revert due to high security risk");
emit SuccessBytes4(addr, sig);
}
function callGetSecurityScores() public view {
address[] memory addresses = new address[](2);
bytes4[] memory functionSignatures = new bytes4[](2);
addresses[0] = msg.sender;
functionSignatures[0] = bytes4(
keccak256(abi.encodePacked("getPrice(string)"))
);
addresses[1] = msg.sender;
functionSignatures[1] = bytes4(
keccak256(abi.encodePacked("getPrice2(string)"))
);
uint8[] memory scores = SecurityOracle(_securityOracleAddress)
.getSecurityScores(addresses, functionSignatures);
for (uint256 i = 0; i < scores.length; i++) {
require(scores[i] > 100, "failed security check");
}
}
}