Skip to content

Commit d997ae0

Browse files
committed
🥞 Publish minimum-deposit-controller package (#486)
1 parent 5d97b19 commit d997ae0

File tree

78 files changed

+5839
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+5839
-1
lines changed

.compiler.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"version": "0.8.16",
3+
"settings": {
4+
"optimizer": {
5+
"enabled": true,
6+
"runs": 200
7+
}
8+
}
9+
}

.eslintrc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
root: true,
3+
// This tells ESLint to load the config from the package `eslint-config-archblock`
4+
extends: ['archblock/contracts'],
5+
}

.mocharc.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"require": ["ts-node/register/transpile-only", "tsconfig-paths/register"],
3+
"extension": ["ts"],
4+
"target": "esnext",
5+
"timeout": 40000,
6+
"watch-files": ["test"],
7+
"exit": true
8+
}

.solhint.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"extends": "solhint:recommended",
3+
"rules": {
4+
"avoid-suicide": "error",
5+
"compiler-version": [
6+
"error",
7+
">=0.8.16"
8+
],
9+
"state-visibility": "off",
10+
"func-name-mixedcase": "off",
11+
"var-name-mixedcase": "off",
12+
"no-empty-blocks": "off",
13+
"no-inline-assembly": "off",
14+
"not-rely-on-time": "off",
15+
"max-states-count": "off",
16+
"reason-string": "off",
17+
"const-name-snakecase": "off",
18+
"avoid-tx-origin": "off",
19+
"func-visibility": [
20+
"warn",
21+
{
22+
"ignoreConstructors": true,
23+
"reentrancy": true
24+
}
25+
]
26+
}
27+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
## 🥞 Minimum deposit controller
1+
# 🦐 Minimum deposit controller

abi-exporter.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
const fs = require('fs')
2+
const path = require('path')
3+
const { extendConfig } = require('hardhat/config')
4+
5+
const { HardhatPluginError } = require('hardhat/plugins')
6+
7+
const {
8+
TASK_COMPILE,
9+
} = require('hardhat/builtin-tasks/task-names')
10+
11+
extendConfig(function (config, userConfig) {
12+
config.abiExporter = Object.assign(
13+
{
14+
path: './abi',
15+
clear: false,
16+
flat: false,
17+
only: [],
18+
except: [],
19+
spacing: 2,
20+
},
21+
userConfig.abiExporter,
22+
)
23+
})
24+
25+
task(TASK_COMPILE, async function (args, hre, runSuper) {
26+
const config = hre.config.abiExporter
27+
28+
await runSuper()
29+
30+
const outputDirectory = path.resolve(hre.config.paths.root, config.path)
31+
32+
if (!outputDirectory.startsWith(hre.config.paths.root)) {
33+
throw new HardhatPluginError('resolved path must be inside of project directory')
34+
}
35+
36+
if (outputDirectory === hre.config.paths.root) {
37+
throw new HardhatPluginError('resolved path must not be root directory')
38+
}
39+
40+
if (config.clear) {
41+
if (fs.existsSync(outputDirectory)) {
42+
fs.rmdirSync(outputDirectory, { recursive: true })
43+
}
44+
}
45+
46+
if (!fs.existsSync(outputDirectory)) {
47+
fs.mkdirSync(outputDirectory, { recursive: true })
48+
}
49+
50+
for (const fullName of await hre.artifacts.getAllFullyQualifiedNames()) {
51+
if (config.only.length && !config.only.some(m => fullName.match(m))) continue
52+
if (config.except.length && config.except.some(m => fullName.match(m))) continue
53+
54+
const { abi, sourceName, contractName, bytecode, deployedBytecode } = await hre.artifacts.readArtifact(fullName)
55+
56+
if (!abi.length) continue
57+
58+
const destination = path.resolve(
59+
outputDirectory,
60+
config.flat ? '' : sourceName,
61+
contractName,
62+
) + '.json'
63+
64+
if (!fs.existsSync(path.dirname(destination))) {
65+
fs.mkdirSync(path.dirname(destination), { recursive: true })
66+
}
67+
68+
fs.writeFileSync(destination, `${JSON.stringify({ abi, bytecode, deployedBytecode }, null, config.spacing)}\n`, { flag: 'w' })
69+
}
70+
})
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.16;
4+
5+
import {ILenderVerifier} from "../carbon/interfaces/ILenderVerifier.sol";
6+
import {Status} from "../carbon/interfaces/IStructuredPortfolio.sol";
7+
import {DepositAllowed} from "../carbon/interfaces/IDepositController.sol";
8+
9+
/**
10+
* @title Contract for managing deposit related settings
11+
* @dev Used by TrancheVault contract
12+
*/
13+
interface IDepositController {
14+
/**
15+
* @notice Event emitted when new ceiling is set
16+
* @param newCeiling New ceiling value
17+
*/
18+
event CeilingChanged(uint256 newCeiling);
19+
20+
/**
21+
* @notice Event emitted when deposits are disabled or enabled for a specific StructuredPortfolio status
22+
* @param newDepositAllowed Value indicating whether deposits should be enabled or disabled
23+
* @param portfolioStatus StructuredPortfolio status for which changes are applied
24+
*/
25+
event DepositAllowedChanged(bool newDepositAllowed, Status portfolioStatus);
26+
27+
/**
28+
* @notice Event emitted when deposit fee rate is switched
29+
* @param newFeeRate New deposit fee rate value (in BPS)
30+
*/
31+
event DepositFeeRateChanged(uint256 newFeeRate);
32+
33+
/**
34+
* @notice Event emitted when minimum deposit is changed
35+
* @param newMinimumDeposit New minimum deposit value (in assets)
36+
*/
37+
event MinimumDepositChanged(uint256 newMinimumDeposit);
38+
39+
/**
40+
* @notice Event emitted when lender verifier is switched
41+
* @param newLenderVerifier New lender verifier contract address
42+
*/
43+
event LenderVerifierChanged(ILenderVerifier indexed newLenderVerifier);
44+
45+
/// @return DepositController manager role used for access control
46+
function MANAGER_ROLE() external view returns (bytes32);
47+
48+
/// @return Address of contract used for checking whether given address is allowed to put funds into an instrument according to implemented strategy
49+
function lenderVerifier() external view returns (ILenderVerifier);
50+
51+
/// @return Max asset capacity defined for TrancheVaults interacting with DepositController
52+
function ceiling() external view returns (uint256);
53+
54+
/// @return Rate (in BPS) of the fee applied to the deposit amount
55+
function depositFeeRate() external view returns (uint256);
56+
57+
/// @return Value indicating whether deposits are allowed when related StructuredPortfolio is in given status
58+
/// @param status StructuredPortfolio status
59+
function depositAllowed(Status status) external view returns (bool);
60+
61+
/**
62+
* @notice Setup contract with given params
63+
* @dev Used by Initializable contract (can be called only once)
64+
* @param manager Address to which MANAGER_ROLE should be granted
65+
* @param _lenderVerifier Address of LenderVerifier contract
66+
* @param _depositFeeRate Deposit fee rate (in BPS)
67+
* @param _minimumDeposit Minimum deposit value (in assets)
68+
* @param _ceiling Ceiling value
69+
*/
70+
function initialize(
71+
address manager,
72+
address _lenderVerifier,
73+
uint256 _depositFeeRate,
74+
uint256 _minimumDeposit,
75+
uint256 _ceiling
76+
) external;
77+
78+
/**
79+
* @return assets Max assets amount that can be deposited with TrancheVault shares minted to given receiver
80+
* @param receiver Shares receiver address
81+
*/
82+
function maxDeposit(address receiver) external view returns (uint256 assets);
83+
84+
/**
85+
* @return shares Max TrancheVault shares amount given address can receive
86+
* @param receiver Shares receiver address
87+
*/
88+
function maxMint(address receiver) external view returns (uint256 shares);
89+
90+
/**
91+
* @notice Simulates deposit assets conversion including fees
92+
* @return shares Shares amount that can be obtained from the given assets amount
93+
* @param assets Tested assets amount
94+
*/
95+
function previewDeposit(uint256 assets) external view returns (uint256 shares);
96+
97+
/**
98+
* @notice Simulates mint shares conversion including fees
99+
* @return assets Assets amount that needs to be deposited to obtain given shares amount
100+
* @param shares Tested shares amount
101+
*/
102+
function previewMint(uint256 shares) external view returns (uint256 assets);
103+
104+
/**
105+
* @notice Simulates deposit result
106+
* @return shares Shares amount that can be obtained from the deposit with given params
107+
* @return depositFee Fee for a deposit with given params
108+
* @param sender Supposed deposit transaction sender address
109+
* @param assets Supposed assets amount
110+
* @param receiver Supposed shares receiver address
111+
*/
112+
function onDeposit(
113+
address sender,
114+
uint256 assets,
115+
address receiver
116+
) external returns (uint256 shares, uint256 depositFee);
117+
118+
/**
119+
* @notice Simulates mint result
120+
* @return assets Assets amount that needs to be provided to execute mint with given params
121+
* @return mintFee Fee for a mint with given params
122+
* @param sender Supposed mint transaction sender address
123+
* @param shares Supposed shares amount
124+
* @param receiver Supposed shares receiver address
125+
*/
126+
function onMint(
127+
address sender,
128+
uint256 shares,
129+
address receiver
130+
) external returns (uint256 assets, uint256 mintFee);
131+
132+
/**
133+
* @notice Ceiling setter
134+
* @param newCeiling New ceiling value
135+
*/
136+
function setCeiling(uint256 newCeiling) external;
137+
138+
/**
139+
* @notice Deposit allowed setter
140+
* @param newDepositAllowed Value indicating whether deposits should be allowed when related StructuredPortfolio is in given status
141+
* @param portfolioStatus StructuredPortfolio status for which changes are applied
142+
*/
143+
function setDepositAllowed(bool newDepositAllowed, Status portfolioStatus) external;
144+
145+
/**
146+
* @notice Deposit fee rate setter
147+
* @param newFeeRate New deposit fee rate (in BPS)
148+
*/
149+
function setDepositFeeRate(uint256 newFeeRate) external;
150+
151+
/**
152+
* @notice Lender verifier setter
153+
* @param newLenderVerifier New LenderVerifier contract address
154+
*/
155+
function setLenderVerifier(ILenderVerifier newLenderVerifier) external;
156+
157+
/**
158+
* @notice Allows to change ceiling, deposit fee rate, minimum deposit, lender verifier and enable or disable deposits at once
159+
* @param newCeiling New ceiling value
160+
* @param newFeeRate New deposit fee rate (in BPS)
161+
* @param newMinimumDeposit New minimum deposit value (in assets)
162+
* @param newLenderVerifier New LenderVerifier contract address
163+
* @param newDepositAllowed New deposit allowed settings
164+
*/
165+
function configure(
166+
uint256 newCeiling,
167+
uint256 newFeeRate,
168+
uint256 newMinimumDeposit,
169+
ILenderVerifier newLenderVerifier,
170+
DepositAllowed memory newDepositAllowed
171+
) external;
172+
}

0 commit comments

Comments
 (0)