Skip to content

Commit

Permalink
deploy stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
gunboatsss committed Nov 16, 2024
1 parent 6b51416 commit 8d388a3
Show file tree
Hide file tree
Showing 26 changed files with 2,368 additions and 12 deletions.
50 changes: 50 additions & 0 deletions broadcast/DeployMockSSROracle.sol/11155111/run-1731790385.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"transactions": [
{
"hash": "0x7c953d5c61c2970aac2985e6398318b7d483bba7dc7de974a2d7c92f72b9f944",
"transactionType": "CREATE",
"contractName": "MockSSROracle",
"contractAddress": "0xddf89ed9d3de427d25b3f8c91232f23966a12d82",
"function": null,
"arguments": [
"1000000001996917783620820123",
"1009386687523739115761266631",
"1731317843"
],
"transaction": {
"from": "0x1313c4e7cecef7835d0a8a3491e81178e79e1a6b",
"gas": "0x1dd19",
"value": "0x0",
"input": "0x608060405234801561001057600080fd5b5060405161014e38038061014e83398101604081905261002f91610092565b6000805464ffffffffff909216600160d81b026001600160d81b036001600160781b039094166c01000000000000000000000000026001600160d81b03199093166001600160601b03909516949094179190911791909116919091179055610101565b6000806000606084860312156100a757600080fd5b83516001600160601b03811681146100be57600080fd5b60208501519093506001600160781b03811681146100db57600080fd5b604085015190925064ffffffffff811681146100f657600080fd5b809150509250925092565b603f8061010f6000396000f3fe6080604052600080fdfea264697066735822122023cae1d8427028c8c851806cbfb8f7ed757e447649a78e5437079898ff53b4fd64736f6c634300081200330000000000000000000000000000000000000000033b2e3cbb86fa61ca611c9b00000000000000000000000000000000000000000342f1f1f97cb702e1896fc7000000000000000000000000000000000000000000000000000000006731d053",
"nonce": "0x0",
"chainId": "0xaa36a7"
},
"additionalContracts": [],
"isFixedGasLimit": false
}
],
"receipts": [
{
"status": "0x1",
"cumulativeGasUsed": "0x91969f",
"logs": [],
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"type": "0x2",
"transactionHash": "0x7c953d5c61c2970aac2985e6398318b7d483bba7dc7de974a2d7c92f72b9f944",
"transactionIndex": "0x3b",
"blockHash": "0xcda1ebe546fb3d046f9b9dca56ef39285b18997fa82657f7cb1fe4982c391755",
"blockNumber": "0x6c33be",
"gasUsed": "0x16f1c",
"effectiveGasPrice": "0x3d0347b",
"from": "0x1313c4e7cecef7835d0a8a3491e81178e79e1a6b",
"to": null,
"contractAddress": "0xddf89ed9d3de427d25b3f8c91232f23966a12d82"
}
],
"libraries": [],
"pending": [],
"returns": {},
"timestamp": 1731790385,
"chain": 11155111,
"commit": "6b51416"
}
50 changes: 50 additions & 0 deletions broadcast/DeployMockSSROracle.sol/11155111/run-latest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"transactions": [
{
"hash": "0x7c953d5c61c2970aac2985e6398318b7d483bba7dc7de974a2d7c92f72b9f944",
"transactionType": "CREATE",
"contractName": "MockSSROracle",
"contractAddress": "0xddf89ed9d3de427d25b3f8c91232f23966a12d82",
"function": null,
"arguments": [
"1000000001996917783620820123",
"1009386687523739115761266631",
"1731317843"
],
"transaction": {
"from": "0x1313c4e7cecef7835d0a8a3491e81178e79e1a6b",
"gas": "0x1dd19",
"value": "0x0",
"input": "0x608060405234801561001057600080fd5b5060405161014e38038061014e83398101604081905261002f91610092565b6000805464ffffffffff909216600160d81b026001600160d81b036001600160781b039094166c01000000000000000000000000026001600160d81b03199093166001600160601b03909516949094179190911791909116919091179055610101565b6000806000606084860312156100a757600080fd5b83516001600160601b03811681146100be57600080fd5b60208501519093506001600160781b03811681146100db57600080fd5b604085015190925064ffffffffff811681146100f657600080fd5b809150509250925092565b603f8061010f6000396000f3fe6080604052600080fdfea264697066735822122023cae1d8427028c8c851806cbfb8f7ed757e447649a78e5437079898ff53b4fd64736f6c634300081200330000000000000000000000000000000000000000033b2e3cbb86fa61ca611c9b00000000000000000000000000000000000000000342f1f1f97cb702e1896fc7000000000000000000000000000000000000000000000000000000006731d053",
"nonce": "0x0",
"chainId": "0xaa36a7"
},
"additionalContracts": [],
"isFixedGasLimit": false
}
],
"receipts": [
{
"status": "0x1",
"cumulativeGasUsed": "0x91969f",
"logs": [],
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"type": "0x2",
"transactionHash": "0x7c953d5c61c2970aac2985e6398318b7d483bba7dc7de974a2d7c92f72b9f944",
"transactionIndex": "0x3b",
"blockHash": "0xcda1ebe546fb3d046f9b9dca56ef39285b18997fa82657f7cb1fe4982c391755",
"blockNumber": "0x6c33be",
"gasUsed": "0x16f1c",
"effectiveGasPrice": "0x3d0347b",
"from": "0x1313c4e7cecef7835d0a8a3491e81178e79e1a6b",
"to": null,
"contractAddress": "0xddf89ed9d3de427d25b3f8c91232f23966a12d82"
}
],
"libraries": [],
"pending": [],
"returns": {},
"timestamp": 1731790385,
"chain": 11155111,
"commit": "6b51416"
}
268 changes: 268 additions & 0 deletions broadcast/DeployOnScrollDevnet.sol/2227728/run-1731792802.json

Large diffs are not rendered by default.

268 changes: 268 additions & 0 deletions broadcast/DeployOnScrollDevnet.sol/2227728/run-1731792841.json

Large diffs are not rendered by default.

268 changes: 268 additions & 0 deletions broadcast/DeployOnScrollDevnet.sol/2227728/run-1731792986.json

Large diffs are not rendered by default.

268 changes: 268 additions & 0 deletions broadcast/DeployOnScrollDevnet.sol/2227728/run-latest.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ src = "src"
out = "out"
libs = ["lib"]
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options

[rpc_endpoints]
sepolia = "${SEPOLIA_RPC}"
scroll_devnet = "${SCROLL_DEVNET_}"
14 changes: 14 additions & 0 deletions script/DeployMockSSROracle.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.18;

import {Script} from "forge-std/Script.sol";
import {MockSSROracle} from "src/mock-ssr-oracle.sol";

contract DeployMockSSROracle is Script {
function run() external {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(deployerPrivateKey);
MockSSROracle o = new MockSSROracle(1000000001996917783620820123 ,1009386687523739115761266631, 1731317843);
vm.stopBroadcast();
}
}
22 changes: 22 additions & 0 deletions script/DeployOnScrollDevnet.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.18;

import {Script} from "forge-std/Script.sol";
import {PriceOracle} from "src/PriceOracle.sol";
import {LendNowFactory} from "src/LendNowFactory.sol";
import {MockPyth} from "test/MockPyth.sol";
import {ERC20PoolFactory} from "ajna-core/src/ERC20PoolFactory.sol";
import {ERC20} from "lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
import {Scroll_L1SLOAD_USDS_RateHook} from "src/hooks/Scroll_L1SLOAD_USDS_RateHook.sol";

contract DeployOnScrollDevnet is Script {
function run() external {
vm.startBroadcast(vm.envUint("PRIVATE_KEY"));
MockPyth pyth = new MockPyth(15 * 60, 1);
ERC20 mockbwAJNA = new ERC20("Mock bwAJNA", "MbwAJNA");
ERC20PoolFactory ajnaFactory = new ERC20PoolFactory(address(mockbwAJNA));
PriceOracle p = new PriceOracle(address(pyth));
LendNowFactory factory = new LendNowFactory(address(ajnaFactory), address(p));
Scroll_L1SLOAD_USDS_RateHook i = new Scroll_L1SLOAD_USDS_RateHook(0xDDF89eD9D3dE427d25b3f8C91232F23966a12d82);
}
}
5 changes: 5 additions & 0 deletions src/InterestHook.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pragma solidity ^0.8.0;

interface IInterestHook {
function getRate() external returns (uint256);
}
8 changes: 5 additions & 3 deletions src/LendNowFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@ import {LendNowVault} from "./LendNowVault.sol";

contract LendNowFactory {
IERC20PoolFactory immutable factory;
address priceOracle;
bytes32 constant ERC20_NON_SUBSET_HASH = keccak256("ERC20_NON_SUBSET_HASH");

address[] public pools;

constructor(address factory_) {
constructor(address factory_, address priceOracle_) {
factory = IERC20PoolFactory(factory_);
priceOracle = priceOracle_;
}

function createNewVault(address _collateral, address _quote, uint256 _bps) external returns (address vault) {
function createNewVault(address _collateral, address _quote, uint256 _bps, bytes32 _collateralOracleId, bytes32 _quotePriceId, address hook_) external returns (address vault) {
string memory token_sym = IERC20Metadata(_quote).symbol();
address pool = factory.deployedPools(ERC20_NON_SUBSET_HASH, _collateral, _quote);
require(pool != address(0));
vault = address(new LendNowVault(pool, _bps, _quote, token_sym));
vault = address(new LendNowVault(pool, _bps, _quote, _collateralOracleId, _quotePriceId, priceOracle, hook_, token_sym));
pools.push(vault);
}
}
52 changes: 47 additions & 5 deletions src/LendNowVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
pragma solidity 0.8.18;

import {_indexOf, _priceAt, _lpToQuoteToken} from "ajna-core/src/libraries/helpers/PoolHelper.sol";
import {IInterestHook} from "./InterestHook.sol";
import {IERC20Pool} from "ajna-core/src/interfaces/pool/erc20/IERC20Pool.sol";
import {PriceOracle} from "./PriceOracle.sol";

import {IInterestHook} from "./InterestHook.sol";
import "openzeppelin-contracts/contracts/token/ERC20/extensions/ERC4626.sol";

contract LendNowVault is ERC4626 {
Expand All @@ -14,27 +15,59 @@ contract LendNowVault is ERC4626 {
bytes32 immutable public collateralOracleId;
bytes32 immutable public quoteOracleId;
PriceOracle immutable priceOracle;
IInterestHook immutable hook;


uint256 lastPrice;
uint256 lastUpdate;

constructor(address ajnaPool_, uint256 bps_, address asset_, bytes32 collateralOracleId_, bytes32 quoteOracleId_, address priceOracle_, string memory symbol_) ERC4626(IERC20(asset_)) ERC20(string.concat("Lend Now! ", symbol_), string.concat("LN!", symbol_)) {
constructor(address ajnaPool_, uint256 bps_, address asset_, bytes32 collateralOracleId_, bytes32 quoteOracleId_, address priceOracle_, address interestHook_, string memory symbol_) ERC4626(IERC20(asset_)) ERC20(string.concat("Lend Now! ", symbol_), string.concat("LN!", symbol_)) {
ajnaPool = IERC20Pool(ajnaPool_);
require(bps_ < 10000, "bps too high");
collateralOracleId = collateralOracleId_;
quoteOracleId = quoteOracleId_;
bps = bps_;
priceOracle = PriceOracle(priceOracle_);
hook = IInterestHook(interestHook_);
}

function getPriceIndex() public view returns (uint256) {
return _indexOf(lastPrice * bps / 10000);
}

// this function intended for simulation
function offchain_poke() public returns (bool shouldUpdate) {
if (address(hook) != address(0)) {
uint256 target = hook.getRate();
(uint256 interestRate, uint256 lastUpdate_) = ajnaPool.interestRateInfo();
if(lastUpdate_ < block.timestamp + 12 hours) {
shouldUpdate = false;
}
else {
ajnaPool.updateInterest();
(uint256 newInterestRate,) = ajnaPool.interestRateInfo();
if((newInterestRate > interestRate && interestRate < target) || (newInterestRate < interestRate && interestRate > target)) {
shouldUpdate = true;
}
shouldUpdate = false;
}
}
}

function updatePrice() public {
uint256 collateralPrice = priceOracle.read(collateralOracleId);
uint256 quotePrice = priceOracle.read(quotePrice);
lastPrice = collateralPrice * 1e18 / quotePrice;
uint256 quotePrice = priceOracle.read(quoteOracleId);
uint256 newPrice = collateralPrice * 1e18 / quotePrice;
if(lastPrice == 0) {
lastPrice = newPrice;
return;
}
uint256 lastIndex = _indexOf(lastPrice * bps / 10000);
uint256 newIndex = _indexOf(newPrice * bps / 10000);
if(_indexOf(lastPrice) != _indexOf(newPrice) && totalAssets() > 0) {
ajnaPool.moveQuoteToken(totalAssets(), lastIndex, newIndex, type(uint256).max);
}
lastUpdate = block.timestamp;
}

function totalAssets() public view override returns (uint256 quoteAmount) {
Expand All @@ -55,6 +88,9 @@ contract LendNowVault is ERC4626 {
function _deposit(address caller, address receiver, uint256 assets, uint256 shares) internal override {
super._deposit(caller, receiver, assets, shares);
_asset.approve(address(ajnaPool), assets);
if (_underlyingDecimals < 18) {
assets = assets * 10 ** (18 - _underlyingDecimals);
}
ajnaPool.addQuoteToken(assets, getPriceIndex(), type(uint256).max);
}

Expand All @@ -65,7 +101,13 @@ contract LendNowVault is ERC4626 {
uint256 assets,
uint256 shares
) internal override {
ajnaPool.removeQuoteToken(assets, getPriceIndex());
if (_underlyingDecimals < 18) {
assets = assets * 10 ** (18 - _underlyingDecimals);
}
(uint256 removedAmount, ) = ajnaPool.removeQuoteToken(assets, getPriceIndex());
if (_underlyingDecimals < 18) {
assets = assets / 10 ** (18 - _underlyingDecimals);
}
super._withdraw(caller, receiver, owner, assets, shares);
}
}
Loading

0 comments on commit 8d388a3

Please sign in to comment.