Skip to content

Commit

Permalink
Adds a view method for getting current chi.
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
gbalabasquer authored and MicahZoltu committed Nov 8, 2019
1 parent 6fd7de0 commit 54a2a16
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/pot.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 54a2a16

Please sign in to comment.