🆘
On-Chain Decentralized Exit Strategy
Yet another new security layer for building responsible DeFi dApps is that of predetermined exit strategies for users in a bugged contract. Using Flexible Organizations, this procedure can also be activated by voting.
The circulation of a Stablecoin, for example, should always be based on one or more sources of underlying collateral, which in any case has a value even if taken individually. So it is important to always make it possible to remove it if there is a need, even if only a temporary one.
1
contract AStableCoin {
2
function mint(
3
uint256 pairIndex,
4
uint256 amount0,
5
uint256 amount1,
6
uint256 amount0Min,
7
uint256 amount1Min
8
) public override _forAllowedPair(pairIndex) returns (uint256 minted) {
9
require(
10
IStateHolder(
11
IMVDProxy(IDoubleProxy(_doubleProxy).proxy())
12
.getStateHolderAddress()
13
)
14
.getBool(
15
_toStateHolderKey(
16
"authorizedStableCoin",
17
_toString(address(this))
18
)
19
),
20
"Unauthorized action!"
21
);
22
(address token0, address token1, ) = _getPairData(pairIndex);
23
_transferTokensAndCheckAllowance(token0, amount0);
24
_transferTokensAndCheckAllowance(token1, amount1);
25
(uint256 firstAmount, uint256 secondAmount, ) = _createPoolToken(
26
token0,
27
token1,
28
amount0,
29
amount1,
30
amount0Min,
31
amount1Min
32
);
33
minted =
34
fromTokenToStable(token0, firstAmount) +
35
fromTokenToStable(token1, secondAmount);
36
require(minted <= availableToMint(), "Minting amount is greater than availability");
37
_mint(msg.sender, minted);
38
}
39
40
function burn(
41
uint256 pairIndex,
42
uint256 pairAmount,
43
uint256 amount0,
44
uint256 amount1
45
)
46
public
47
override
48
_forAllowedPair(pairIndex)
49
returns (uint256 removed0, uint256 removed1)
50
{
51
(address token0, address token1, address pairAddress) = _getPairData(pairIndex);
52
_checkAllowance(pairAddress, pairAmount);
53
(removed0, removed1) = IUniswapV2Router(UNISWAP_V2_ROUTER)
54
.removeLiquidity(
55
token0,
56
token1,
57
pairAmount,
58
amount0,
59
amount1,
60
msg.sender,
61
block.timestamp + 1000
62
);
63
_burn(
64
msg.sender,
65
fromTokenToStable(token0, removed0) +
66
fromTokenToStable(token1, removed1)
67
);
68
}
69
}
Copied!
The code above shows that it is possible to create value in the Stablecoin if and only if it is fully active and working, and as long as its underlying collateral can be withdrawn by the owner in any circumstance.
Last modified 9mo ago
Copy link