-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bca6f0f
commit 583ca3f
Showing
8 changed files
with
103 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
.DS_Store | ||
|
||
# Compiler files | ||
cache/ | ||
out/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file was deleted.
Oops, something went wrong.