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
MicahZoltu committed Nov 8, 2019
1 parent 6fd7de0 commit 7ddc3ff
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/pot.sol
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,18 @@ contract Pot is LibNote {
// --- Savings Rate Accumulation ---
function drip() external note returns (uint tmp) {
require(now >= rho, "Pot/invalid-now");
tmp = rmul(rpow(dsr, now - rho, ONE), chi);
tmp = drop();
uint chi_ = sub(tmp, chi);
chi = tmp;
rho = now;
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 7ddc3ff

Please sign in to comment.