Skip to content

Commit

Permalink
fix: use less json for mock prices
Browse files Browse the repository at this point in the history
  • Loading branch information
fxp3 committed Jul 13, 2024
1 parent b6b6371 commit 7153193
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/hardhat-and-foundry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- run: bun install --yarn

- name: Run Foundry Tests
run: forge test
run: forge test --no-rpc-rate-limit --memory-limit 234217728
env:
ALCHEMY_API_KEY: ${{ secrets.ALCHEMY_API_KEY }}
RPC_ARBITRUM_ALCHEMY: https://arb-mainnet.g.alchemy.com/v2/${{ secrets.ALCHEMY_API_KEY }}
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/scripts/deploy/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ contract Deploy is DeployBase {

function setupUsers(JSON.Config memory json, bool disableLog) private reclearCallers {
payable(address(kresko)).transfer(0.00001 ether);
updatePythLocal(json.getMockPrices());
updatePythLocal(json.assets.tickers);
setupBalances(json.users, json.assets);
setupSCDP(json.users, json.assets);
setupMinter(json.users, json.assets);
Expand Down
5 changes: 3 additions & 2 deletions src/contracts/scripts/deploy/DeployBase.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {SCDPConfigFacet} from "scdp/facets/SCDPConfigFacet.sol";
import {PythView} from "kresko-lib/vendor/Pyth.sol";
import "scripts/deploy/JSON.s.sol" as JSON;
import {FacetData, getFacets, create1} from "kresko-lib/utils/ffi/ffi-facets.s.sol";
import {LibJSON} from "scripts/deploy/libs/LibJSON.s.sol";

abstract contract DeployBase is Based {
using LibDeploy for bytes;
Expand Down Expand Up @@ -135,8 +136,8 @@ abstract contract DeployBase is Based {
return (kresko = IKresko(address(new DiamondBomb().create(_deployer, facets, selectors, initializers, calldatas))));
}

function updatePythLocal(PythView memory _prices) internal {
getMockPayload(_prices);
function updatePythLocal(JSON.TickerConfig[] memory tickers) internal {
getMockPayload(LibJSON.getMockPrices(tickers));
updatePyth(pyth.update, 0);
}
}
4 changes: 1 addition & 3 deletions src/contracts/scripts/deploy/JSON.s.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.23;
import {Asset, CommonInitArgs} from "common/Types.sol";
import {CommonInitArgs} from "common/Types.sol";
import {SCDPInitArgs} from "scdp/STypes.sol";
import {MinterInitArgs} from "minter/MTypes.sol";
import {IWETH9} from "kresko-lib/token/IWETH9.sol";
import {Enums} from "common/Constants.sol";
import {LibJSON} from "scripts/deploy/libs/LibJSON.s.sol";
import {Help, Utils, mAddr, mvm} from "kresko-lib/utils/s/LibVm.s.sol";
import {CONST} from "scripts/deploy/CONST.s.sol";
import {PLog} from "kresko-lib/utils/s/PLog.s.sol";
import {Deployed} from "scripts/deploy/libs/Deployed.s.sol";

struct Files {
Expand Down Expand Up @@ -310,7 +309,6 @@ function get(Users memory users, uint256 i) returns (address) {
uint256 constant ALL_USERS = 9999;

using {get} for Users global;
using {LibJSON.getMockPrices} for Config global;

using {LibJSON.metadata} for KrAssetConfig global;
using {LibJSON.toAsset} for AssetJSON global;
4 changes: 2 additions & 2 deletions src/contracts/scripts/deploy/libs/LibDeploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ library LibDeploy {
using Help for *;
using Utils for *;
using Deployed for *;
using LibJSON for string;
using LibJSON for *;
using LibDeploy for bytes;
using LibDeploy for bytes32;

Expand All @@ -40,7 +40,7 @@ library LibDeploy {

function createMockPythEP(JSON.Config memory json) internal saveOutput("MockPythEP") returns (address) {
bytes[] memory args = new bytes[](1);
args[0] = abi.encode(json.getMockPrices());
args[0] = abi.encode(json.assets.tickers.getMockPrices());
bytes memory implementation = type(MockPyth).creationCode.ctor(abi.encode(args));
return implementation.d3("", CONST.PYTH_MOCK_SALT).implementation;
}
Expand Down
17 changes: 9 additions & 8 deletions src/contracts/scripts/deploy/libs/LibJSON.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ library LibJSON {
revert("Balance not found");
}

function getMockPrices(JSON.Config memory cfg) internal view returns (PythView memory result) {
function getMockPrices(JSON.TickerConfig[] memory cfg) internal view returns (PythView memory result) {
(bytes32[] memory ids, int64[] memory prices) = _getPrices(cfg);
require(ids.length == prices.length, "PythScript: mock price length mismatch");
result.ids = new bytes32[](ids.length);
Expand All @@ -242,11 +242,11 @@ library LibJSON {
}
}

function _getPrices(JSON.Config memory cfg) private pure returns (bytes32[] memory ids, int64[] memory prices) {
function _getPrices(JSON.TickerConfig[] memory cfg) private pure returns (bytes32[] memory ids, int64[] memory prices) {
uint256 count;

for (uint256 i; i < cfg.assets.tickers.length; i++) {
if (cfg.assets.tickers[i].pythId != bytes32(0)) {
for (uint256 i; i < cfg.length; i++) {
if (cfg[i].pythId != bytes32(0)) {
count++;
}
}
Expand All @@ -255,10 +255,11 @@ library LibJSON {
prices = new int64[](count);

count = 0;
for (uint256 i; i < cfg.assets.tickers.length; i++) {
if (cfg.assets.tickers[i].pythId != bytes32(0)) {
ids[count] = cfg.assets.tickers[i].pythId;
prices[count] = int64(uint64(cfg.assets.tickers[i].mockPrice));
for (uint256 i; i < cfg.length; i++) {
JSON.TickerConfig memory ticker = cfg[i];
if (ticker.pythId != bytes32(0)) {
ids[count] = ticker.pythId;
prices[count] = int64(uint64(ticker.mockPrice));
count++;
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/contracts/test/Complex.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {Deploy} from "scripts/deploy/Deploy.s.sol";
import {KreskoAsset} from "kresko-asset/KreskoAsset.sol";
import {MockERC20, MockOracle} from "mocks/Mocks.sol";
import {Deployed} from "scripts/deploy/libs/Deployed.s.sol";
import "scripts/deploy/JSON.s.sol" as JSON;
import {JSON, LibJSON} from "scripts/deploy/libs/LibJSON.s.sol";
import {MintArgs, SCDPLiquidationArgs, SCDPWithdrawArgs, SwapArgs} from "common/Args.sol";

contract ComplexTest is Deploy {
Expand Down Expand Up @@ -656,12 +656,12 @@ contract ComplexTest is Deploy {

function _setETHPrice(uint256 _newPrice) internal {
ethFeed.setPrice(_newPrice * 1e8);
JSON.Config memory cfg = JSON.getConfig("test", "test-audit");
for (uint256 i = 0; i < cfg.assets.tickers.length; i++) {
if (cfg.assets.tickers[i].ticker.equals("ETH")) {
cfg.assets.tickers[i].mockPrice = _newPrice * 1e8;
JSON.TickerConfig[] memory tickers = JSON.getAssetConfig("test", "test-audit").tickers;
for (uint256 i = 0; i < tickers.length; i++) {
if (tickers[i].ticker.equals("ETH")) {
tickers[i].mockPrice = _newPrice * 1e8;
}
}
updatePythLocal(cfg.getMockPrices());
updatePythLocal(tickers);
}
}
10 changes: 5 additions & 5 deletions src/contracts/test/Multicall.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -687,12 +687,12 @@ contract MulticallTest is Deploy {

function _setETHPrice(uint256 _newPrice) internal {
ethFeed.setPrice(_newPrice * 1e8);
JSON.Config memory cfg = JSON.getConfig("test", "test-base");
for (uint256 i = 0; i < cfg.assets.tickers.length; i++) {
if (cfg.assets.tickers[i].ticker.equals("ETH")) {
cfg.assets.tickers[i].mockPrice = _newPrice * 1e8;
JSON.TickerConfig[] memory tickers = JSON.getAssetConfig("test", "test-base").tickers;
for (uint256 i = 0; i < tickers.length; i++) {
if (tickers[i].ticker.equals("ETH")) {
tickers[i].mockPrice = _newPrice * 1e8;
}
}
updatePythLocal(cfg.getMockPrices());
updatePythLocal(tickers);
}
}
21 changes: 13 additions & 8 deletions src/contracts/test/SCDP.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ contract SCDPTest is Tested, Deploy {
IKreskoAsset krETH;
IKreskoAsset krJPY;
IKreskoAsset krTSLA;
MockOracle ethFeed;
Asset krETHConfig;
Asset kissConfig;
uint256 fee_KISS_krETH;
Expand All @@ -39,10 +40,15 @@ contract SCDPTest is Tested, Deploy {

address krETHAddr;
address kissAddr;

JSON.TickerConfig[] tickerCfg;
function setUp() public mnemonic("MNEMONIC_DEVNET") users(getAddr(11), getAddr(22), getAddr(33)) {
JSON.Config memory json = Deploy.deployTest("MNEMONIC_DEVNET", "test-clean", 0);

for (uint256 i; i < json.assets.tickers.length; i++) {
tickerCfg.push(json.assets.tickers[i]);
}
ethFeed = MockOracle(kresko.getOracleOfTicker(bytes32("ETH"), Enums.OracleType.Chainlink).feed);

// for price updates
vm.deal(address(kresko), 1 ether);

Expand Down Expand Up @@ -71,7 +77,7 @@ contract SCDPTest is Tested, Deploy {
usdc.mint(user0, 1000e6);
prank(getAddr(0));
council = kresko.getRoleMember(keccak256("kresko.roles.minter.safety.council"), 0);
assertNotEq(council, address(0));
council.notEq(address(0));

kiss.transfer(user0, 2000e18);
}
Expand Down Expand Up @@ -688,14 +694,13 @@ contract SCDPTest is Tested, Deploy {
}

function _setETHPrice(uint256 price) internal repranked(admin) {
MockOracle(kresko.getOracleOfTicker(bytes32("ETH"), Enums.OracleType.Chainlink).feed).setPrice(price);
JSON.Config memory cfg = JSON.getConfig("test", "test-clean");
for (uint256 i = 0; i < cfg.assets.tickers.length; i++) {
if (cfg.assets.tickers[i].ticker.equals("ETH")) {
cfg.assets.tickers[i].mockPrice = price;
ethFeed.setPrice(price);
for (uint256 i = 0; i < tickerCfg.length; i++) {
if (tickerCfg[i].ticker.equals("ETH")) {
tickerCfg[i].mockPrice = price;
}
}
updatePythLocal(cfg.getMockPrices());
updatePythLocal(tickerCfg);
}

function _toggleActionPaused(address asset, Enums.Action action, bool paused) internal repranked(council) {
Expand Down

0 comments on commit 7153193

Please sign in to comment.