Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add safe tx for updating stale times #138

Closed
wants to merge 2 commits into from

Conversation

lacoop6tu
Copy link
Contributor

Add script and test for updating stale times to current assets

bool[] memory invertPyth = new bool[](4);

ICommonConfigFacet.PythConfig memory pythConfig = ICommonConfigFacet.PythConfig({
pythIds: tickers,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be best if we just create configuration once in the script and test with that

eg. state and private function for config in script:

    bytes32[] internal tickers = [bytes32("ETH"), "BTC", "USDC", "ARB"];

    function getPythConfig() private view returns (ICommonConfigFacet.PythConfig memory pythConfig) {
        pythConfig.pythIds = new bytes32[](tickers.length);
        pythConfig.invertPyth = new bool[](tickers.length);
        pythConfig.staleTimes = new uint256[](tickers.length);
        for (uint256 i; i < tickers.length; i++) {
            Oracle memory config = kresko.getOracleOfTicker(tickers[i], Enums.OracleType.Pyth);
            pythConfig.pythIds[i] = config.pythId;
            pythConfig.invertPyth[i] = config.invertPyth;
            pythConfig.staleTimes[i] = 30;
        }
    }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in getPythConfig we also fix the issue of pythIds as we simply copy everything that exists on chain and just replace the staleTime.

pythId !== ticker:

ticker is eg bytes32("ETH") but the pythId for this ticker is 0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace which can be found here https://pyth.network/developers/price-feed-ids or in pyth_stable_ids.json in the repo

_;
}

function test_payload0003() public setUp broadcasted(safe) {
Copy link
Contributor

@fxp3 fxp3 Mar 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think here it would be best if we just test the actual script being run and not rewrite it so something like:

    function setUp() public {
        currentForkId = vm.createSelectFork("arbitrum", 194029135);
    }

    bytes32 pyth_eth = 0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace;

    function test_payload0002() public {
        payload0002();

        fetchPythAndUpdate();
        vm.warp(pythEP.getPriceUnsafe(pyth_eth).timestamp);
        for (uint256 i; i < tickers.length; i++) {
            uint256 price = kresko.getPythPrice(tickers[i]);
            assertTrue(price > 0, "price is 0");
        }
        vm.warp(pythEP.getPriceUnsafe(pyth_eth).timestamp + 31);
        for (uint256 i; i < tickers.length; i++) {
            vm.expectRevert(0x19abf40e); // pyth StalePrice selector
            kresko.getPythPrice(tickers[i]);
        }
    }

and in the script side we would have:

function payload0002() public {
        if (currentForkId == 0) {
            vm.createSelectFork("arbitrum");
        }
        broadcastWith(safe);
        kresko.setPythFeeds(tickers, getPythConfig());
    }

@fxp3 fxp3 closed this Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants