-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathFractionalizeProposal.sol
80 lines (73 loc) · 2.73 KB
/
FractionalizeProposal.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
// SPDX-License-Identifier: Beta Software
pragma solidity ^0.8;
import "../tokens/IERC721.sol";
import "../party/PartyGovernance.sol";
import "./IProposalExecutionEngine.sol";
import "./vendor/FractionalV1.sol";
// Implements fractionalizing an NFT to ERC20s on Fractional V1. Inherited by the `ProposalExecutionEngine`.
// This contract will be delegatecall'ed into by `Party` proxy instances.
contract FractionalizeProposal {
struct FractionalizeProposalData {
// The ERC721 token contract to fractionalize.
IERC721 token;
// The ERC721 token ID to fractionalize.
uint256 tokenId;
// The starting list price for the fractional vault.
uint256 listPrice;
}
event FractionalV1VaultCreated(
IERC721 indexed token,
uint256 indexed tokenId,
uint256 vaultId,
IERC20 vault,
uint256 listPrice
);
/// @notice Deployment of https://github.com/fractional-company/contracts/blob/master/src/ERC721TokenVault.sol.
IFractionalV1VaultFactory public immutable VAULT_FACTORY;
// Set the `VAULT_FACTORY`.
constructor(IFractionalV1VaultFactory vaultFactory) {
VAULT_FACTORY = vaultFactory;
}
// Fractionalize an NFT held by this party on Fractional V1.
function _executeFractionalize(
IProposalExecutionEngine.ExecuteProposalParams memory params
)
internal
returns (bytes memory nextProgressData)
{
// Decode the proposal data.
FractionalizeProposalData memory data =
abi.decode(params.proposalData, (FractionalizeProposalData));
// The supply of fractional vault ERC20 tokens will be equal to the total
// voting power of the party.
uint256 supply =
PartyGovernance(address(this)).getGovernanceValues().totalVotingPower;
// Create a vault around the NFT.
data.token.approve(address(VAULT_FACTORY), data.tokenId);
uint256 vaultId = VAULT_FACTORY.mint(
IERC721(address(this)).name(),
IERC721(address(this)).symbol(),
data.token,
data.tokenId,
supply,
data.listPrice,
0
);
// Get the vault we just created.
IFractionalV1Vault vault = VAULT_FACTORY.vaults(vaultId);
// Check that we now hold the correct amount of fractional tokens.
// Should always succeed.
assert(vault.balanceOf(address(this)) == supply);
// Remove ourselves as curator.
vault.updateCurator(address(0));
emit FractionalV1VaultCreated(
data.token,
data.tokenId,
vaultId,
vault,
data.listPrice
);
// Nothing left to do.
return "";
}
}