-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathBondingCurveFacet.sol
133 lines (122 loc) · 4.26 KB
/
BondingCurveFacet.sol
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
import {LibBondingCurve} from "../libraries/LibBondingCurve.sol";
import {Modifiers} from "../libraries/LibAppStorage.sol";
import {IBondingCurve} from "../../dollar/interfaces/IBondingCurve.sol";
/**
* @notice Bonding curve contract based on Bancor formula
* @notice Inspired from Bancor protocol https://github.com/bancorprotocol/contracts
* @notice Used on UbiquiStick NFT minting
*/
contract BondingCurveFacet is Modifiers, IBondingCurve {
/**
* @notice Sets bonding curve params
* @param _connectorWeight Connector weight
* @param _baseY Base Y
*/
function setParams(
uint32 _connectorWeight,
uint256 _baseY
) external onlyAdmin {
LibBondingCurve.setParams(_connectorWeight, _baseY);
}
/**
* @notice Returns `connectorWeight` value
* @return Connector weight value
*/
function connectorWeight() external view returns (uint32) {
return LibBondingCurve.connectorWeight();
}
/**
* @notice Returns `baseY` value
* @return Base Y value
*/
function baseY() external view returns (uint256) {
return LibBondingCurve.baseY();
}
/**
* @notice Returns total balance of deposited collateral
* @return Amount of deposited collateral
*/
function poolBalance() external view returns (uint256) {
return LibBondingCurve.poolBalance();
}
/**
* @notice Deposits collateral tokens in exchange for UbiquiStick NFT
* @param _collateralDeposited Amount of collateral
* @param _recipient Address to receive the NFT
*/
function deposit(
uint256 _collateralDeposited,
address _recipient
) external {
LibBondingCurve.deposit(_collateralDeposited, _recipient);
}
/**
* @notice Returns number of NFTs a `_recipient` holds
* @param _recipient User address
* @return Amount of NFTs for `_recipient`
*/
function getShare(address _recipient) external view returns (uint256) {
return LibBondingCurve.getShare(_recipient);
}
/**
* @notice Withdraws collateral tokens to treasury
* @param _amount Amount of collateral tokens to withdraw
*/
function withdraw(uint256 _amount) external onlyAdmin whenNotPaused {
LibBondingCurve.withdraw(_amount);
}
/**
* @notice Given a token supply, reserve balance, weight and a deposit amount (in the reserve token),
* calculates the target amount for a given conversion (in the main token)
*
* @notice `_supply * ((1 + _tokensDeposited / _connectorBalance) ^ (_connectorWeight / 1000000) - 1)`
*
* @param _tokensDeposited Amount of collateral tokens to deposit
* @param _connectorWeight Connector weight, represented in ppm, 1 - 1,000,000
* @param _supply Current token supply
* @param _connectorBalance Total connector balance
* @return Amount of tokens minted
*/
function purchaseTargetAmount(
uint256 _tokensDeposited,
uint32 _connectorWeight,
uint256 _supply,
uint256 _connectorBalance
) external pure returns (uint256) {
return
LibBondingCurve.purchaseTargetAmount(
_tokensDeposited,
_connectorWeight,
_supply,
_connectorBalance
);
}
/**
* @notice Given a deposit (in the collateral token) token supply of 0, calculates the return
* for a given conversion (in the token)
*
* @notice `_supply * ((1 + _tokensDeposited / _connectorBalance) ^ (_connectorWeight / 1000000) - 1)`
*
* @param _tokensDeposited Amount of collateral tokens to deposit
* @param _connectorWeight Connector weight, represented in ppm, 1 - 1,000,000
* @param _baseX Constant x
* @param _baseY Expected price
* @return Amount of tokens minted
*/
function purchaseTargetAmountFromZero(
uint256 _tokensDeposited,
uint256 _connectorWeight,
uint256 _baseX,
uint256 _baseY
) external pure returns (uint256) {
return
LibBondingCurve.purchaseTargetAmountFromZero(
_tokensDeposited,
_connectorWeight,
_baseX,
_baseY
);
}
}