/* Imports */
#include "./utils/WadMath.huff"

/* Methods */
#define macro COMPUTE_GOO_BALANCE() = takes (0) returns (0) {
    // Input Stack:             // [timeElapsedWad,lastBalanceWad,emissionMultiple]  

     dup1                       // [timeElapsedWad,timeElapsedWad,lastBalanceWad,emissionMultiple]   
     dup1                       // [timeElapsedWad,timeElapsedWad,timeElapsedWad,lastBalanceWad,emissionMultiple]   
     WAD_MUL()                  // [timeElapsedWad * timeElapsedWad,timeElapsedWad,lastBalanceWad,emissionMultiple]   
     
     dup4                       // [emissionMultiple, timeElapsedWad * timeElapsedWad,timeElapsedWad,lastBalanceWad,emissionMultiple]
     mul                        // [emissionMultiple * timeElapsedWadSquared,timeElapsedWad,lastBalanceWad,emissionMultiple]  
     0x02 shr                   // [emissionMultiple * timeElapsedWadSquared >> 2,timeElapsedWad, lastBalanceWad,emissionMultiple]    
     dup3                       // [lastBalanceWad, emissionMultiple * timeElapsedWadSquared >> 2,timeElapsedWad,lastBalanceWad,emissionMultiple]
     add                        // [lastBalanceWad + (emissionMultiple * timeElapsedWadSquared >> 2),timeElapsedWad,lastBalanceWad,emissionMultiple]        
     0x00 mstore                // [timeElapsedWad,lastBalanceWad,emissionMultiple]  
     
     dup2                       // [lastBalanceWad, timeElapsedWad,lastBalanceWad,emissionMultiple]  
     dup4                       // [emissionMultiple, lastBalanceWad, timeElapsedWad,lastBalanceWad,emissionMultiple]            
     mul                        // [emissionMultiple * lastBalanceWad, timeElapsedWad,lastBalanceWad,emissionMultiple]     
     [WAD]                      // [1e18, emissionMultiple * lastBalanceWad, timeElapsedWad,lastBalanceWad,emissionMultiple]     
     mul                        // [1e18 * emissionMultiple * lastBalanceWad, timeElapsedWad,lastBalanceWad,emissionMultiple]       
     SQRT()                     // [ sqrt(1e18 * emissionMultiple * lastBalanceWad), timeElapsedWad,lastBalanceWad,emissionMultiple]         
     
     WAD_MUL()                  // [ sqrt(1e18 * emissionMultiple * lastBalanceWad) * timeElapsedWad,lastBalanceWad,emissionMultiple]           
     0x00 mload                 // [ lastBalanceWad + (emissionMultiple * timeElapsedWadSquared >> 2), sqrt(1e18 * emissionMultiple * lastBalanceWad) * timeElapsedWad,lastBalanceWad,emissionMultiple]             
     add                        // [ lastBalanceWad + (emissionMultiple * timeElapsedWadSquared >> 2) + sqrt(1e18 * emissionMultiple * lastBalanceWad) * timeElapsedWad,lastBalanceWad,emissionMultiple]               
   
     //Return Stack:            // [ lastBalanceWad + (emissionMultiple * timeElapsedWadSquared >> 2) + sqrt(1e18 * emissionMultiple * lastBalanceWad) * timeElapsedWad]               
}

