Skip to content

Commit

Permalink
used forked trigonometry repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick95550 committed Jun 5, 2024
1 parent e839f70 commit 1feda62
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 24 deletions.
2 changes: 1 addition & 1 deletion contracts/ISeekerStatsOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface ISeekerStatsOracle {

function setOracle(address _seekerStatsOracleAccount) external;

function createStatsMessage(Seeker calldata seeker) external pure returns (bytes memory);
function createProofMessage(Seeker calldata seeker) external pure returns (bytes memory);

function registerSeekerRestricted(Seeker calldata seeker) external;

Expand Down
32 changes: 20 additions & 12 deletions contracts/SeekerStatsOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

Check warning on line 6 in contracts/SeekerStatsOracle.sol

View workflow job for this annotation

GitHub Actions / build

global import of path @openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol is not allowed. Specify names to import individually or bind all exports of the module into a name (import "path" as Name)

Check warning on line 6 in contracts/SeekerStatsOracle.sol

View workflow job for this annotation

GitHub Actions / build

global import of path @openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol is not allowed. Specify names to import individually or bind all exports of the module into a name (import "path" as Name)
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";

Check warning on line 7 in contracts/SeekerStatsOracle.sol

View workflow job for this annotation

GitHub Actions / build

global import of path @openzeppelin/contracts/utils/cryptography/ECDSA.sol is not allowed. Specify names to import individually or bind all exports of the module into a name (import "path" as Name)

Check warning on line 7 in contracts/SeekerStatsOracle.sol

View workflow job for this annotation

GitHub Actions / build

global import of path @openzeppelin/contracts/utils/cryptography/ECDSA.sol is not allowed. Specify names to import individually or bind all exports of the module into a name (import "path" as Name)
import "solidity-trigonometry/src/Trigonometry.sol";
import "hardhat/console.sol";

import "./ISeekerStatsOracle.sol";

Expand All @@ -25,7 +24,8 @@ contract SeekerStatsOracle is ISeekerStatsOracle, Initializable, Ownable2StepUpg
/**
* @notice Holds the angle used for coverage calculation in radians
*/
int256 private angle = Trigonometry.sin(((Trigonometry.TWO_PI / 6) + Trigonometry.TWO_PI));
int256 private coverageAngle =
Trigonometry.sin(((Trigonometry.TWO_PI / 6) + Trigonometry.TWO_PI));

event SeekerStatsUpdated(
uint256 indexed seekerId,
Expand Down Expand Up @@ -87,7 +87,7 @@ contract SeekerStatsOracle is ISeekerStatsOracle, Initializable, Ownable2StepUpg
revert OracleCannotBeZeroAddress();
}

bytes memory proof = _createStatsMessage(seeker);
bytes memory proof = _createProofMessage(seeker);
bytes32 ecdsaHash = ECDSA.toEthSignedMessageHash(proof);
address signerAddress = ECDSA.recover(ecdsaHash, signature);
if (signerAddress == SeekerStatsOracleAccount) {
Expand All @@ -101,7 +101,7 @@ contract SeekerStatsOracle is ISeekerStatsOracle, Initializable, Ownable2StepUpg
* @notice Creates a proofing message unique to the provided seeker.
* @param seeker The object containing the seekers statistics.
*/
function _createStatsMessage(Seeker calldata seeker) internal pure returns (bytes memory) {
function _createProofMessage(Seeker calldata seeker) internal pure returns (bytes memory) {
return
abi.encodePacked(
seeker.seekerId,
Expand All @@ -119,8 +119,8 @@ contract SeekerStatsOracle is ISeekerStatsOracle, Initializable, Ownable2StepUpg
* @notice Creates a proofing message unique to the provided seeker.
* @param seeker The object containing the seekers statistics.
*/
function createStatsMessage(Seeker calldata seeker) external pure returns (bytes memory) {
return _createStatsMessage(seeker);
function createProofMessage(Seeker calldata seeker) external pure returns (bytes memory) {
return _createProofMessage(seeker);
}

function registerSeekerRestricted(Seeker calldata seeker) external {
Expand Down Expand Up @@ -180,16 +180,24 @@ contract SeekerStatsOracle is ISeekerStatsOracle, Initializable, Ownable2StepUpg
revert SeekerNotRegistered(seeker.seekerId);
}

sumCoverage += (int256(seeker.attr_reactor) * angle * int256(seeker.attr_cores)) / 2;
sumCoverage +=
(int256(seeker.attr_cores) * angle * int256(seeker.attr_durability)) /
(int256(seeker.attr_reactor) * coverageAngle * int256(seeker.attr_cores)) /
2;
sumCoverage +=
(int256(seeker.attr_durability) * angle * int256(seeker.attr_sensors)) /
(int256(seeker.attr_cores) * coverageAngle * int256(seeker.attr_durability)) /
2;
sumCoverage +=
(int256(seeker.attr_durability) * coverageAngle * int256(seeker.attr_sensors)) /
2;
sumCoverage +=
(int256(seeker.attr_sensors) * coverageAngle * int256(seeker.attr_storage)) /
2;
sumCoverage +=
(int256(seeker.attr_storage) * coverageAngle * int256(seeker.attr_chip)) /
2;
sumCoverage +=
(int256(seeker.attr_chip) * coverageAngle * int256(seeker.attr_reactor)) /
2;
sumCoverage += (int256(seeker.attr_sensors) * angle * int256(seeker.attr_storage)) / 2;
sumCoverage += (int256(seeker.attr_storage) * angle * int256(seeker.attr_chip)) / 2;
sumCoverage += (int256(seeker.attr_chip) * angle * int256(seeker.attr_reactor)) / 2;
}

return sumCoverage;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@
"@openzeppelin/contracts-upgradeable": "^4.8.1",
"@openzeppelin/merkle-tree": "^1.0.5",
"abdk-libraries-solidity": "^3.1.0",
"solidity-trigonometry": "https://github.com/mds1/solidity-trigonometry.git"
"solidity-trigonometry": "https://github.com/futureversecom/solidity-trigonometry.git"
}
}
14 changes: 7 additions & 7 deletions test/seekerStats/stakingStats.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Seeker {
) {}
}

describe.only('Seeker Stats', () => {
describe('Seeker Stats', () => {
let accounts: Signer[];
let contracts: SyloContracts;
let seekerStatsOracle: SeekerStatsOracle;
Expand Down Expand Up @@ -80,7 +80,7 @@ describe.only('Seeker Stats', () => {
it('can register seeker', async () => {
const seeker = new Seeker(10, 2, 10, 20, 30, 40, 50, 60);

const proofMessage = await seekerStatsOracle.createStatsMessage(seeker);
const proofMessage = await seekerStatsOracle.createProofMessage(seeker);
const signature = await accounts[19].signMessage(
Buffer.from(proofMessage.slice(2), 'hex'),
);
Expand Down Expand Up @@ -114,7 +114,7 @@ describe.only('Seeker Stats', () => {
it('cannot register seeker from non-oracle account', async () => {
const seeker = new Seeker(20, 2, 10, 20, 30, 40, 50, 60);

const proofMessage = await seekerStatsOracle.createStatsMessage(seeker);
const proofMessage = await seekerStatsOracle.createProofMessage(seeker);
const signature = await accounts[18].signMessage(
Buffer.from(proofMessage.slice(2), 'hex'),
);
Expand All @@ -130,8 +130,8 @@ describe.only('Seeker Stats', () => {
const seeker = new Seeker(10, 2, 1, 1, 1, 1, 1, 1);
const seekerTwo = new Seeker(10, 2, 10, 10, 10, 10, 10, 10);

const proofMessage = await seekerStatsOracle.createStatsMessage(seeker);
const proofMessageTwo = await seekerStatsOracle.createStatsMessage(
const proofMessage = await seekerStatsOracle.createProofMessage(seeker);
const proofMessageTwo = await seekerStatsOracle.createProofMessage(
seekerTwo,
);

Expand Down Expand Up @@ -229,7 +229,7 @@ describe.only('Seeker Stats', () => {
it('supports only seeker stats oracle interface', async () => {
const abi = [
'function setOracle(address _seekerStatsOracleAccount) external',
'function createStatsMessage((uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256) calldata seeker) external pure returns (bytes memory)',
'function createProofMessage((uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256) calldata seeker) external pure returns (bytes memory)',
'function registerSeekerRestricted((uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256) calldata seeker) external',
'function registerSeeker((uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256) calldata seeker, bytes calldata signature) external',
'function calculateAttributeCoverage((uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256)[] calldata seekersList) external view returns (int256)',
Expand Down Expand Up @@ -299,7 +299,7 @@ describe.only('Seeker Stats', () => {
i + 50,
i + 60,
);
const proofMessage = await seekerStatsOracle.createStatsMessage(
const proofMessage = await seekerStatsOracle.createProofMessage(
newSeeker,
);
const signature = await accounts[19].signMessage(
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6652,9 +6652,9 @@ solidity-coverage@^0.8.2:
shelljs "^0.8.3"
web3-utils "^1.3.6"

"solidity-trigonometry@https://github.com/mds1/solidity-trigonometry.git":
version "0.0.0"
resolved "https://github.com/mds1/solidity-trigonometry.git#58af3a912ab3e2203cf21189012caefe24471e29"
"solidity-trigonometry@https://github.com/futureversecom/solidity-trigonometry.git":
version "1.0.0"
resolved "https://github.com/futureversecom/solidity-trigonometry.git#570bcce1d24016d8beb3cfcf7b5a6975960ea3d3"

source-map-support@^0.5.13:
version "0.5.21"
Expand Down

0 comments on commit 1feda62

Please sign in to comment.