From 54a2a164e2a8ed1cd3b2bcb8bdd90acc6dd618d0 Mon Sep 17 00:00:00 2001 From: Gonzalo Balabasquer Date: Thu, 7 Nov 2019 18:19:15 -0300 Subject: [PATCH] Adds a `view` method for getting current `chi`. This change makes it so a contract with a `view` function can know what `chi` would be in this block. This is useful for contracts that have view functions that need to return values denominated in DAI when looking at DSR balances. An example use case for this is a token contract (DAI-GoUp) that wraps DAI held in DSR. The `balanceOf` function of such a contract (which is `view`) needs to be able to calculate the current balance of an account denominated in DAI. In order to do this, it must calculate what `chi` _would_ be if `drip` was called this block, but without actually calling `drip` (because that is not a view function). --- src/pot.sol | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/pot.sol b/src/pot.sol index dfdff599..76271296 100644 --- a/src/pot.sol +++ b/src/pot.sol @@ -146,6 +146,11 @@ contract Pot is LibNote { vat.suck(address(vow), address(this), mul(Pie, chi_)); } + function drop() external view returns (uint) { + if (now == rho) return chi; + return rmul(rpow(dsr, now - rho, ONE), chi); + } + // --- Savings Dai Management --- function join(uint wad) external note { require(now == rho, "Pot/rho-not-updated");