Skip to content

Commit

Permalink
foundry project init
Browse files Browse the repository at this point in the history
  • Loading branch information
rbajollari committed Nov 25, 2024
1 parent bca6f0f commit 583ca3f
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 57 deletions.
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ETH_RPC_URL=
HOLESKY_RPC_URL=
ETHERSCAN_API_KEY=

PT_ADDRESS=
BASE_DISCOUNT_PER_YEAR=
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.DS_Store

# Compiler files
cache/
out/
Expand Down
27 changes: 27 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
[profile.default]
solc = "0.8.19"
via_ir = true
src = "src"
out = "out"
libs = ["lib"]
fs_permissions = [{ access = "read-write", path = "./"}]
gas_reports = ["*"]
build_info = true
extra_output = ["storageLayout"]

[rpc_endpoints]
mainnet = "${ETH_RPC_URL}"
holesky = "${HOLESKY_RPC_URL}"

[fmt]
bracket_spacing = false
int_types = "long"
line_length = 120
multiline_func_header = "params_first"
number_underscore = "thousands"
quote_style = "double"
tab_width = 4

[fuzz]
runs = 4096
max_test_rejects = 262144

[etherscan]
mainnet = { key = "${ETHERSCAN_API_KEY}" }
holesky = { key = "${ETHERSCAN_API_KEY}" }

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
19 changes: 0 additions & 19 deletions script/Counter.s.sol

This file was deleted.

21 changes: 21 additions & 0 deletions script/OjoPointsOracle.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.19;

import {Script} from "forge-std/Script.sol";
import {OjoPointsOracle} from "src/OjoPointsOracle.sol";
import {console} from "forge-std/console.sol";

contract DeployOjoPointsOracle is Script {
function run() external {
address _pt = vm.envAddress("PT_ADDRESS");
uint256 _baseDiscountPerYear = vm.envUint("BASE_DISCOUNT_PER_YEAR");

vm.startBroadcast();

OjoPointsOracle ojoPointsOracle = new OjoPointsOracle(_pt, _baseDiscountPerYear);

vm.stopBroadcast();

console.log("OjoPointsOracle Address:", address(ojoPointsOracle));
}
}
14 changes: 0 additions & 14 deletions src/Counter.sol

This file was deleted.

47 changes: 47 additions & 0 deletions src/OjoPointsOracle.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-License-Identifier: SEE LICENSE IN LICENSE
pragma solidity ^0.8.19;

contract OjoPointsOracle {
uint256 private constant SECONDS_PER_YEAR = 365 days;
uint256 private constant ONE = 1e18;

address public immutable PT;
uint256 public immutable maturity;
uint256 public immutable baseDiscountPerYear; // 100% = 1e18

constructor(address _pt, uint256 _baseDiscountPerYear) {
require(_baseDiscountPerYear <= 1e18, "invalid discount");
require(_pt != address(0), "zero address");

PT = _pt;
maturity = PTExpiry(PT).expiry();
baseDiscountPerYear = _baseDiscountPerYear;
}

function latestRoundData()
external
view
returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound)
{
uint256 timeLeft = (maturity > block.timestamp) ? maturity - block.timestamp : 0;
uint256 discount = getDiscount(timeLeft);

require(discount <= ONE, "discount overflow");

return (0, int256(ONE - discount), 0, 0, 0);
}

function decimals() external pure returns (uint8) {
return 18;
}

function getDiscount(
uint256 timeLeft
) public view returns (uint256) {
return (timeLeft * baseDiscountPerYear) / SECONDS_PER_YEAR;
}
}

interface PTExpiry {
function expiry() external view returns (uint256);
}
24 changes: 0 additions & 24 deletions test/Counter.t.sol

This file was deleted.

0 comments on commit 583ca3f

Please sign in to comment.