-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathproposeMetavestDeal.s.sol
More file actions
160 lines (141 loc) · 6.52 KB
/
proposeMetavestDeal.s.sol
File metadata and controls
160 lines (141 loc) · 6.52 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.24;
import {YearnBorgCompensation2025_2026} from "./lib/YearnBorgCompensation2025_2026.sol";
import {BaseAllocation} from "../src/BaseAllocation.sol";
import {BorgAuth} from "cybercorps-contracts/src/libs/auth.sol";
import {CyberAgreementRegistry} from "cybercorps-contracts/src/CyberAgreementRegistry.sol";
import {ERC1967Proxy} from "openzeppelin-contracts/proxy/ERC1967/ERC1967Proxy.sol";
import {ISafeProxyFactory, IGnosisSafe} from "../test/lib/safe.sol";
import {CyberAgreementUtils} from "./lib/CyberAgreementUtils.sol";
import {SafeTxHelper} from "./lib/SafeTxHelper.sol";
import {Script} from "forge-std/Script.sol";
import {console2} from "forge-std/console2.sol";
import {metavestController} from "../src/MetaVesTController.sol";
import {MetaVestDealLib, MetaVestDeal} from "../src/lib/MetaVestDealLib.sol";
contract ProposeMetaVestDealScript is SafeTxHelper, Script {
using MetaVestDealLib for MetaVestDeal;
using YearnBorgCompensation2025_2026 for YearnBorgCompensation2025_2026.Config;
/// @dev For running from `forge script`. Provide the deployer private key through env var.
function run() public virtual {
YearnBorgCompensation2025_2026.Config memory defaultConfig = YearnBorgCompensation2025_2026.getDefault(vm);
runSingle(
vm.envUint("DEPLOYER_PRIVATE_KEY"), // proposerPrivateKey
vm.envOr("BORG_DELEGATE_PRIVATE_KEY", uint256(0)), // borgSafeDelegatePrivateKey
defaultConfig.compRecipients[0],
vm.envUint("AGREEMENT_SALT"), // agreementSalt
defaultConfig
);
}
/// @dev For running in tests
function runSingle(
uint256 proposerPrivateKey,
uint256 borgSafeDelegatePrivateKey,
YearnBorgCompensation2025_2026.CompInfo memory recipientInfo,
uint256 agreementSalt,
YearnBorgCompensation2025_2026.Config memory config
) public virtual returns(bytes32) {
return runSingle(
proposerPrivateKey,
borgSafeDelegatePrivateKey,
recipientInfo,
agreementSalt,
// Default guardian allocations
config.parseAllocation(),
config
);
}
/// @dev For running in tests
function runSingle(
uint256 proposerPrivateKey,
uint256 borgSafeDelegatePrivateKey,
YearnBorgCompensation2025_2026.CompInfo memory guardianInfo,
uint256 agreementSalt,
BaseAllocation.Allocation memory allocation,
YearnBorgCompensation2025_2026.Config memory config
) public virtual returns(bytes32) {
console2.log("");
console2.log("=== ProposeMetaVestDealScript ===");
console2.log("Proposer: ", vm.addr(proposerPrivateKey));
console2.log("Guardian SAFE Delegate (if private key available): ", borgSafeDelegatePrivateKey != 0
? vm.addr(borgSafeDelegatePrivateKey)
: address(0));
console2.log("Guardian Safe: ", address(config.borgSafe));
console2.log("Payment token: ", address(config.paymentToken));
console2.log("CyberAgreementRegistry: ", address(config.registry));
console2.log("MetavestControllerFactory: ", address(config.metavestControllerFactory));
console2.log("MetavesTController: ", address(config.controller));
console2.log("");
// Assume Guardian SAFE already delegate signing to the deployer
// Propose a new deal
address[] memory parties = new address[](2);
parties[0] = address(config.borgSafe);
parties[1] = guardianInfo.partyInfo.evmAddress;
string[] memory globalValues = config.formatCompGlobalValues(vm, guardianInfo.partyInfo.evmAddress);
string[][] memory partyValues = YearnBorgCompensation2025_2026.formatPartyValues(
vm,
config.borgSafeInfo,
guardianInfo.partyInfo
);
bytes32 expectedContractId = keccak256(
abi.encode(
guardianInfo.compTemplate.id,
agreementSalt, // salt,
globalValues,
parties
)
);
(string memory agreementUri, ) = config.registry.templates(guardianInfo.compTemplate.id);
if (borgSafeDelegatePrivateKey != 0 || guardianInfo.signature.length > 0) { // has signature
// Has valid signature, proceed to proposal
vm.startBroadcast(proposerPrivateKey);
bytes32 contractId = config.controller.proposeAndSignDeal(
guardianInfo.compTemplate.id,
agreementSalt,
MetaVestDealLib.draft().setVesting(
guardianInfo.partyInfo.evmAddress,
allocation,
config.milestones
),
globalValues,
parties,
partyValues,
(borgSafeDelegatePrivateKey != 0)
? CyberAgreementUtils.signAgreementTypedData(
config.registry,
expectedContractId,
agreementUri,
guardianInfo.compTemplate.globalFields,
guardianInfo.compTemplate.partyFields,
globalValues,
partyValues[0],
borgSafeDelegatePrivateKey
)
: guardianInfo.signature,
bytes32(0), // no secrets
block.timestamp + 365 days * 2 // 2 years after deployment
);
vm.stopBroadcast();
console2.log("Created:");
console2.log(" Agreement ID:");
console2.logBytes32(contractId);
console2.log("");
return contractId;
} else {
// Does not have valid signature, prompt for offline signing
console2.log("Signature required: please sign the following EIP-712 typed data:");
console2.log(" (can be signed with command `cast wallet sign --data '<paste json string here>'`)");
console2.log("==== JSON data start ====");
console2.log(CyberAgreementUtils.formatAgreementTypedDataJson(
config.registry,
expectedContractId,
agreementUri,
guardianInfo.compTemplate.globalFields,
guardianInfo.compTemplate.partyFields,
globalValues,
partyValues[0]
));
console2.log("==== JSON data end ====");
return expectedContractId;
}
}
}