Skip to content

Commit f0541e8

Browse files
committed
test: right asset custodians
1 parent 57fbd34 commit f0541e8

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

test/shared/CustodianShared.t.sol

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// SPDX-License-Identifier: BUSL-1.1
2+
pragma solidity 0.8.26;
3+
4+
import { BaseTest } from "test/BaseTest.t.sol";
5+
import { ICustodianFactory } from "contracts/core/interfaces/custody/ICustodianFactory.sol";
6+
import { ICustodianRegistrable } from "contracts/core/interfaces/custody/ICustodianRegistrable.sol";
7+
import { IAgreementManager } from "contracts/core/interfaces/financial/IAgreementManager.sol";
8+
import { ITollgate } from "contracts/core/interfaces/economics/ITollgate.sol";
9+
import { ILedgerVault } from "contracts/core/interfaces/financial/ILedgerVault.sol";
10+
import { IERC20 } from "@openzeppelin/contracts/interfaces/IERC20.sol";
11+
import { T } from "contracts/core/primitives/Types.sol";
12+
13+
contract CustodianShared is BaseTest {
14+
function setUp() public virtual initialize {
15+
deployCustodianReferendum();
16+
deployCustodianFactory();
17+
}
18+
19+
function deployCustodian(string memory endpoint) public returns (address) {
20+
vm.prank(admin);
21+
ICustodianFactory custodianFactory = ICustodianFactory(custodianFactory);
22+
return custodianFactory.create(endpoint);
23+
}
24+
25+
function _setFeesAsGovernor(uint256 fees) internal {
26+
vm.startPrank(governor);
27+
ITollgate(tollgate).setFees(T.Scheme.FLAT, custodianReferendum, fees, token);
28+
vm.stopPrank();
29+
}
30+
31+
function _registerCustodianWithApproval(address d9r, uint256 approval) internal {
32+
// manager = contract deployer
33+
// only manager can pay enrollment..
34+
vm.startPrank(admin);
35+
// approve approval to ledger to deposit funds
36+
address[] memory parties = new address[](1);
37+
parties[0] = d9r;
38+
39+
uint256 proof = _createAgreement(approval, parties);
40+
// operate over msg.sender ledger registered funds
41+
ICustodianRegistrable(custodianReferendum).register(proof, d9r);
42+
vm.stopPrank();
43+
}
44+
45+
function _createAgreement(uint256 amount, address[] memory parties) internal returns (uint256) {
46+
IERC20(token).approve(ledger, amount);
47+
ILedgerVault(ledger).deposit(admin, amount, token);
48+
49+
uint256 proof = IAgreementManager(agreementManager).createAgreement(
50+
amount,
51+
token,
52+
address(custodianReferendum),
53+
parties,
54+
""
55+
);
56+
57+
return proof;
58+
}
59+
60+
function _registerAndApproveCustodian(address d9r) internal {
61+
// intially the balance = 0
62+
_setFeesAsGovernor(1 * 1e18);
63+
// register the custodian with fees = 100 MMC
64+
_registerCustodianWithApproval(d9r, 1 * 1e18);
65+
vm.prank(governor); // as governor.
66+
// distribuitor approved only by governor..
67+
ICustodianRegistrable(custodianReferendum).approve(d9r);
68+
}
69+
}

0 commit comments

Comments
 (0)