generated from bgd-labs/bgd-forge-template
-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathAaveV3Ethereum_TokenLogicKarpatkeyServiceProviderPartnership_20231207.t.sol
More file actions
166 lines (135 loc) · 5.75 KB
/
AaveV3Ethereum_TokenLogicKarpatkeyServiceProviderPartnership_20231207.t.sol
File metadata and controls
166 lines (135 loc) · 5.75 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
161
162
163
164
165
166
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
import {IERC20} from 'solidity-utils/contracts/oz-common/interfaces/IERC20.sol';
import {ProtocolV3TestBase} from 'aave-helpers/ProtocolV3TestBase.sol';
import {AaveV3Ethereum, AaveV3EthereumAssets} from 'aave-address-book/AaveV3Ethereum.sol';
import {AaveV3Ethereum_TokenLogicKarpatkeyServiceProviderPartnership_20231207} from './AaveV3Ethereum_TokenLogicKarpatkeyServiceProviderPartnership_20231207.sol';
/**
* @dev Test for AaveV3Ethereum_TokenLogicKarpatkeyServiceProviderPartnership_20231207
* command: make test-contract filter=AaveV3Ethereum_TokenLogicKarpatkeyServiceProviderPartnership_20231207
*/
contract AaveV3Ethereum_TokenLogicKarpatkeyServiceProviderPartnership_20231207_Test is
ProtocolV3TestBase
{
AaveV3Ethereum_TokenLogicKarpatkeyServiceProviderPartnership_20231207 internal proposal;
function setUp() public {
vm.createSelectFork(vm.rpcUrl('mainnet'), 18736059);
proposal = new AaveV3Ethereum_TokenLogicKarpatkeyServiceProviderPartnership_20231207();
}
/**
* @dev executes the generic test suite including e2e and config snapshots
*/
function test_execute() public {
(, , , , , , uint256 streamToCancelRemaining, ) = AaveV3Ethereum.COLLECTOR.getStream(
proposal.STREAM_TO_CANCEL()
);
assertGt(streamToCancelRemaining, 0);
vm.startPrank(proposal.STREAM_TWO_RECEIVER());
AaveV3Ethereum.COLLECTOR.withdrawFromStream(
proposal.STREAM_TO_CANCEL(),
7773680555555554162512 // what's available currently to withdraw
);
vm.stopPrank();
uint256 nextCollectorStreamID = AaveV3Ethereum.COLLECTOR.getNextStreamId();
uint256 nextCollectorStreamIDTwo = nextCollectorStreamID + 1;
uint256 receiverOneBalanceBefore = IERC20(AaveV3EthereumAssets.GHO_UNDERLYING).balanceOf(
proposal.STREAM_ONE_RECEIVER()
);
uint256 receiverTwoBalanceBefore = IERC20(AaveV3EthereumAssets.GHO_UNDERLYING).balanceOf(
proposal.STREAM_TWO_RECEIVER()
);
uint256 collectorBalanceBefore = IERC20(AaveV3EthereumAssets.GHO_UNDERLYING).balanceOf(
address(AaveV3Ethereum.COLLECTOR)
);
executePayload(vm, address(proposal));
uint256 streamId = proposal.STREAM_TO_CANCEL();
vm.expectRevert('stream does not exist');
AaveV3Ethereum.COLLECTOR.getStream(streamId);
{
(
address senderGHO,
address recipientGHO,
uint256 depositGHO,
address tokenAddressGHO,
uint256 startTimeGHO,
uint256 stopTimeGHO,
uint256 remainingBalanceGHO,
) = AaveV3Ethereum.COLLECTOR.getStream(nextCollectorStreamID);
assertEq(senderGHO, address(AaveV3Ethereum.COLLECTOR));
assertEq(recipientGHO, proposal.STREAM_ONE_RECEIVER());
assertEq(depositGHO, proposal.ACTUAL_AMOUNT_ONE());
assertEq(tokenAddressGHO, AaveV3EthereumAssets.GHO_UNDERLYING);
assertEq(stopTimeGHO - startTimeGHO, proposal.STREAM_DURATION());
assertEq(remainingBalanceGHO, proposal.ACTUAL_AMOUNT_ONE());
}
{
(
address senderGHO,
address recipientGHO,
uint256 depositGHO,
address tokenAddressGHO,
uint256 startTimeGHO,
uint256 stopTimeGHO,
uint256 remainingBalanceGHO,
) = AaveV3Ethereum.COLLECTOR.getStream(nextCollectorStreamIDTwo);
assertEq(senderGHO, address(AaveV3Ethereum.COLLECTOR));
assertEq(recipientGHO, proposal.STREAM_TWO_RECEIVER());
assertEq(depositGHO, proposal.ACTUAL_AMOUNT_TWO());
assertEq(tokenAddressGHO, AaveV3EthereumAssets.GHO_UNDERLYING);
assertEq(stopTimeGHO - startTimeGHO, proposal.STREAM_DURATION());
assertEq(remainingBalanceGHO, proposal.ACTUAL_AMOUNT_TWO());
}
// Can withdraw during stream
vm.warp(block.timestamp + 30 days);
vm.startPrank(proposal.STREAM_ONE_RECEIVER());
AaveV3Ethereum.COLLECTOR.withdrawFromStream(
nextCollectorStreamID,
proposal.ACTUAL_AMOUNT_ONE() / 30 days
);
vm.stopPrank();
assertGt(
IERC20(AaveV3EthereumAssets.GHO_UNDERLYING).balanceOf(proposal.STREAM_ONE_RECEIVER()),
receiverOneBalanceBefore
);
vm.startPrank(proposal.STREAM_TWO_RECEIVER());
AaveV3Ethereum.COLLECTOR.withdrawFromStream(
nextCollectorStreamIDTwo,
proposal.ACTUAL_AMOUNT_TWO() / 30 days
);
vm.stopPrank();
assertGt(
IERC20(AaveV3EthereumAssets.GHO_UNDERLYING).balanceOf(proposal.STREAM_TWO_RECEIVER()),
receiverTwoBalanceBefore
);
assertLt(
IERC20(AaveV3EthereumAssets.GHO_UNDERLYING).balanceOf(address(AaveV3Ethereum.COLLECTOR)),
collectorBalanceBefore
);
// Can withdraw post stream all remaining funds
vm.warp(block.timestamp + proposal.STREAM_DURATION());
(, , , , , , uint256 remainingOne, ) = AaveV3Ethereum.COLLECTOR.getStream(
nextCollectorStreamID
);
(, , , , , , uint256 remainingTwo, ) = AaveV3Ethereum.COLLECTOR.getStream(
nextCollectorStreamIDTwo
);
vm.startPrank(proposal.STREAM_ONE_RECEIVER());
AaveV3Ethereum.COLLECTOR.withdrawFromStream(nextCollectorStreamID, remainingOne);
vm.stopPrank();
vm.startPrank(proposal.STREAM_TWO_RECEIVER());
AaveV3Ethereum.COLLECTOR.withdrawFromStream(nextCollectorStreamIDTwo, remainingTwo);
vm.stopPrank();
assertEq(
IERC20(AaveV3EthereumAssets.GHO_UNDERLYING).balanceOf(proposal.STREAM_ONE_RECEIVER()),
receiverOneBalanceBefore + proposal.ACTUAL_AMOUNT_ONE()
);
assertEq(
IERC20(AaveV3EthereumAssets.GHO_UNDERLYING).balanceOf(proposal.STREAM_TWO_RECEIVER()),
receiverTwoBalanceBefore + proposal.ACTUAL_AMOUNT_TWO()
);
assertEq(
IERC20(AaveV3EthereumAssets.GHO_UNDERLYING).balanceOf(address(AaveV3Ethereum.COLLECTOR)),
collectorBalanceBefore - proposal.ACTUAL_AMOUNT_ONE() - proposal.ACTUAL_AMOUNT_TWO()
);
}
}