Skip to content

Commit 54a2a16

Browse files
gbalabasquerMicahZoltu
authored andcommitted
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).
1 parent 6fd7de0 commit 54a2a16

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/pot.sol

+5
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ contract Pot is LibNote {
146146
vat.suck(address(vow), address(this), mul(Pie, chi_));
147147
}
148148

149+
function drop() external view returns (uint) {
150+
if (now == rho) return chi;
151+
return rmul(rpow(dsr, now - rho, ONE), chi);
152+
}
153+
149154
// --- Savings Dai Management ---
150155
function join(uint wad) external note {
151156
require(now == rho, "Pot/rho-not-updated");

0 commit comments

Comments
 (0)