-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathVRGDA.sol
More file actions
60 lines (50 loc) · 3.07 KB
/
VRGDA.sol
File metadata and controls
60 lines (50 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
import {wadExp, wadLn, wadMul, unsafeWadMul, toWadUnsafe} from "./utils/SignedWadMath.sol";
/// @title Variable Rate Gradual Dutch Auction
/// @author transmissions11 <t11s@paradigm.xyz>
/// @author FrankieIsLost <frankie@paradigm.xyz>
/// @notice Sell tokens roughly according to an issuance schedule.
abstract contract VRGDA {
/*//////////////////////////////////////////////////////////////
VRGDA PARAMETERS
//////////////////////////////////////////////////////////////*/
/// @notice Target price for a token, to be scaled according to sales pace.
/// @dev Represented as an 18 decimal fixed point number.
int256 public immutable targetPrice;
/// @dev Precomputed constant that allows us to rewrite a pow() as an exp().
/// @dev Represented as an 18 decimal fixed point number.
int256 internal immutable decayConstant;
/// @notice Sets target price and per time unit price decay for the VRGDA.
/// @param _targetPrice The target price for a token if sold on pace, scaled by 1e18.
/// @param _priceDecayPercent The percent price decays per unit of time with no sales, scaled by 1e18.
constructor(int256 _targetPrice, int256 _priceDecayPercent) {
targetPrice = _targetPrice;
decayConstant = wadLn(1e18 - _priceDecayPercent);
// The decay constant must be negative for VRGDAs to work.
require(decayConstant < 0, "NON_NEGATIVE_DECAY_CONSTANT");
}
/*//////////////////////////////////////////////////////////////
PRICING LOGIC
//////////////////////////////////////////////////////////////*/
/// @notice Calculate the price of a token according to the VRGDA formula.
/// @param timeSinceStart Time passed since the VRGDA began, scaled by 1e18.
/// @param sold The total number of tokens that have been sold so far.
/// @return The price of a token according to VRGDA, scaled by 1e18.
function getVRGDAPrice(int256 timeSinceStart, uint256 sold) public view returns (uint256) {
unchecked {
// prettier-ignore
return uint256(wadMul(targetPrice, wadExp(unsafeWadMul(decayConstant,
// Theoretically calling toWadUnsafe with sold can silently overflow but under
// any reasonable circumstance it will never be large enough. We use sold + 1 as
// the VRGDA formula's n param represents the nth token and sold is the n-1th token.
timeSinceStart - getTargetSaleTime(toWadUnsafe(sold + 1))
))));
}
}
/// @dev Given a number of tokens sold, return the target time that number of tokens should be sold by.
/// @param sold A number of tokens sold, scaled by 1e18, to get the corresponding target sale time for.
/// @return The target time the tokens should be sold by, scaled by 1e18, where the time is
/// relative, such that 0 means the tokens should be sold immediately when the VRGDA begins.
function getTargetSaleTime(int256 sold) public view virtual returns (int256);
}