🌈
Flexible Environment
One other important security layer needed in DeFi is to make dApps as independent as possible from an off-chain company. Projects in Ethereum need to manage bugs and updates. Usually, coders will go about this by issuing a proxy contract and using their private key to update the code if needed.
This approach does not guarantee total security for dApp users, because their funds are usually in the hands of the dApp issuers. dApp issuers are not a bank! Remember there are no bailouts or legitimate refunds in crypto. Trusting a dApp with code driven by a single company, even if they're regulated in the real world, is always a bad idea. Some dApps are developing DAOs to mitigate this risk, but at the same time a DAO can reduce problems by voting. Because the code of the DAO is in the hands of issuers, this is better, but still not a concrete solution.
On the contrary, there are new approaches to tackle this problem - like Decentralized Flexible Organizations (DFOs) - that remove the need for issuers to have special keys by using a protocol that is 100% modular and only upgradable or managed by voting.
1
contract MVDProxy {
2
3
//... Some code
4
5
function newProposal(string memory codeName, bool emergency, address sourceLocation, uint256 sourceLocationId, address location, bool submitable, string memory methodSignature, string memory returnAbiParametersArray, bool isInternal, bool needsSender, string memory replaces) public override returns(address proposalAddress) {
6
emergencyBehavior(emergency);
7
8
IMVDFunctionalityModelsManager(_delegates[3]).checkWellKnownFunctionalities(codeName, submitable, methodSignature, returnAbiParametersArray, isInternal, needsSender, replaces);
9
10
IMVDFunctionalitiesManager functionalitiesManager = IMVDFunctionalitiesManager(_delegates[4]);
11
12
IMVDFunctionalityProposal proposal = IMVDFunctionalityProposal(proposalAddress = IMVDFunctionalityProposalManager(_delegates[1]).newProposal(codeName, location, methodSignature, returnAbiParametersArray, replaces));
13
proposal.setCollateralData(emergency, sourceLocation, sourceLocationId, submitable, isInternal, needsSender, msg.sender, functionalitiesManager.hasFunctionality("getVotesHardCap") ? toUint256(read("getVotesHardCap", "")) : 0);
14
15
if(functionalitiesManager.hasFunctionality("onNewProposal")) {
16
submit("onNewProposal", abi.encode(proposalAddress));
17
}
18
19
if(!IMVDFunctionalitiesManager(_delegates[4]).hasFunctionality("startProposal") || !IMVDFunctionalitiesManager(_delegates[4]).hasFunctionality("disableProposal")) {
20
proposal.start();
21
}
22
23
emit Proposal(proposalAddress);
24
}
25
26
//... Other code
27
}
Copied!
This is where it all begins: the creation of a Proposal is carried out by calling the Proxy of the DFO, which in turn consults its delegates, who physically take care of controlling, creating and keeping track of all the data of the Surveys that the Token Holders vote on.
1
contract MVDProxy {
2
3
//... Some code
4
5
function setProposal() public override {
6
7
IMVDFunctionalityProposalManager(_delegates[1]).checkProposal(msg.sender);
8
9
emit ProposalCheck(msg.sender);
10
11
IMVDFunctionalitiesManager functionalitiesManager = IMVDFunctionalitiesManager(_delegates[4]);
12
13
(address addressToCall,,string memory methodSignature,,) = functionalitiesManager.getFunctionalityData("checkSurveyResult");
14
15
(bool surveyResult, bytes memory response) = addressToCall.staticcall(abi.encodeWithSignature(methodSignature, msg.sender));
16
17
surveyResult = toUint256(response) > 0;
18
19
IMVDFunctionalityProposal proposal = IMVDFunctionalityProposal(msg.sender);
20
21
if(!surveyResult) {
22
proposal.set();
23
emit ProposalSet(msg.sender, surveyResult);
24
return;
25
}
26
27
if(collateralCallResult) {
28
try functionalitiesManager.setupFunctionality(msg.sender) returns(bool managerResult) {
29
collateralCallResult = managerResult;
30
} catch {
31
collateralCallResult = false;
32
}
33
}
34
35
if(collateralCallResult) {
36
proposal.set();
37
emit ProposalSet(msg.sender, collateralCallResult);
38
}
39
}
40
41
//... Other code
42
}
Copied!
When a user finalizes a Vote Proposal, it automatically calls the Proxy of the DFO, which in turn asks its delegates to verify the result of the calling Proposal (via the "checkSurveyResult" Microservice) and then call, if successful, the finalization of the Microservice (via its Functionalities Manager).
1
contract MVDFunctionalitiesManager {
2
3
function setupFunctionality(address proposalAddress) public override returns(bool result) {
4
5
require(_proxy == msg.sender, "Only Proxy can call This!");
6
7
IMVDFunctionalityProposal proposal = IMVDFunctionalityProposal(proposalAddress);
8
9
string memory codeName = proposal.getCodeName();
10
bool hasCodeName = !compareStrings(codeName, "");
11
string memory replaces = proposal.getReplaces();
12
bool hasReplaces = !compareStrings(replaces, "");
13
14
if(!hasCodeName && !hasReplaces) {
15
(result,) = IMVDProxy(_proxy).callFromManager(_callingContext = proposal.getLocation(), abi.encodeWithSignature("callOneTime(address)", proposalAddress));
16
_callingContext = address(0);
17
return result;
18
}
19
//continue with other cases...
20
}
21
}
Copied!
On the other hand, the Microservice setup can only be performed exclusively if the FunctionalitiesManager is called by the Proxy, as you can see from the 'require' sentence in the code.
If the conditions are met, the FunctionalitiesManager calls the Proxy again to execute the Microservice code. In summary, we have Token Holders voting for a Proposal, which triggers a constrained automated process that leads to its finalization, thanks to the orchestrated collaboration between all the Contracts that make up a DFO, following two fundamental principles of Software Engineering: 'Divide Et Impera' and 'Single Responsibility'.
This new experimental approach can create a new DeFi standard, by making dApps as resilient as ever and independent from the issuer which is to say the issuer can only rule the code if he holds tokens. Crucially, in the case of issuer failure, the dApp can still continue to function and be updated by token holders. more info at https://dfohub.com
Flexible environments are cool. Nevertheless, they need some limitations to be totally fair for DeFi dApps:

Voting Limitations:

Token holders in a DFO can vote to run code, so they can vote to manage every asset and function. Some things, however, shouldn't be changed by voting. When building a DeFi application on top of a DFO, you need to create an external Functionality to store user funds.
For example, in the code of the Liquidity Staking Contract, all the values ​​that identify the times and parameters for generating the rewards of the various tiers are entered in the construction phase, and it is no longer possible to change them. Rewards are automatically sent to the External Smart Contract, so DFOs can only change the rules for newcomers and not for already staked positions.
Every time a new staking position will be opened, the staking contract will receive from the DFO the voting tokens necessary for the reward, by calling the "stakingTransfer" Microservice, as seen in the method called calculateRewardAndAddStakingPosition. These tokens will be transferable only by the owner of the position, according to the desired times.
1
contract Stake {
2
3
//Other code...
4
5
constructor(uint256 startBlock, address doubleProxy, address[] memory tokens, uint256[] memory timeWindows, uint256[] memory rewardMultipliers, uint256[] memory rewardDividers, uint256[] memory rewardSplitTranches) public {
6
7
_startBlock = startBlock;
8
9
_doubleProxy = doubleProxy;
10
11
for(uint256 i = 0; i < tokens.length; i++) {
12
TOKENS.push(tokens[i]);
13
}
14
15
assert(timeWindows.length == rewardMultipliers.length && rewardMultipliers.length == rewardDividers.length && rewardDividers.length == rewardSplitTranches.length);
16
for(uint256 i = 0; i < timeWindows.length; i++) {
17
TIME_WINDOWS.push(timeWindows[i]);
18
}
19
20
for(uint256 i = 0; i < rewardMultipliers.length; i++) {
21
REWARD_MULTIPLIERS.push(rewardMultipliers[i]);
22
}
23
24
for(uint256 i = 0; i < rewardDividers.length; i++) {
25
REWARD_DIVIDERS.push(rewardDividers[i]);
26
}
27
28
for(uint256 i = 0; i < rewardSplitTranches.length; i++) {
29
REWARD_SPLIT_TRANCHES.push(rewardSplitTranches[i]);
30
}
31
}
32
33
//Other code...
34
35
function calculateRewardAndAddStakingPosition(uint256 tier, uint256 poolPosition, uint256 firstAmount, uint256 secondAmount, uint256 poolAmount, IMVDProxy proxy) private {
36
uint256 partialRewardSingleBlockTime = TIME_WINDOWS[tier] / REWARD_SPLIT_TRANCHES[tier];
37
uint256[] memory partialRewardBlockTimes = new uint256[](REWARD_SPLIT_TRANCHES[tier]);
38
if(partialRewardBlockTimes.length > 0) {
39
partialRewardBlockTimes[0] = block.number + partialRewardSingleBlockTime;
40
for(uint256 i = 1; i < partialRewardBlockTimes.length; i++) {
41
partialRewardBlockTimes[i] = partialRewardBlockTimes[i - 1] + partialRewardSingleBlockTime;
42
}
43
}
44
uint256 reward = firstAmount * REWARD_MULTIPLIERS[tier] / REWARD_DIVIDERS[tier];
45
StakeInfo memory stakeInfo = StakeInfo(msg.sender, poolPosition, firstAmount, secondAmount, poolAmount, reward, block.number + TIME_WINDOWS[tier], partialRewardBlockTimes, reward / REWARD_SPLIT_TRANCHES[tier]);
46
_add(tier, stakeInfo);
47
proxy.submit("stakingTransfer", abi.encode(address(0), 0, reward, address(this)));
48
emit Staked(msg.sender, tier, poolPosition, firstAmount, secondAmount, poolAmount, reward, stakeInfo.endBlock, partialRewardBlockTimes, stakeInfo.splittedReward);
49
}
50
51
//Other code...
52
}
Copied!
1
function stakingTransfer(address sender, uint256, uint256 value, address receiver) public {
2
IMVDProxy proxy = IMVDProxy(msg.sender);
3
require(IStateHolder(proxy.getStateHolderAddress()).getBool(_toStateHolderKey("staking.transfer.authorized", _toString(sender))), "Unauthorized action!");
4
proxy.transfer(receiver, value, proxy.getToken());
5
}
Copied!
In turn, the stakingTransfer Microservice will check that it is being called only and exclusively by an active staking contract. Therefore, if the community of token holders chooses to have new staking rules, they will vote to deactivate the old staking contract and activate the new one with new rules. By doing so, all the staking positions of the old staking contract will always be available and redeemable, but it will not be possible to open new positions. At the same time, the new staking contract with the new rules will work normally.
Last modified 9mo ago
Copy link
Contents