Skip to content

Commit a8008a6

Browse files
committed
Log all major state variables that change
1 parent dd08535 commit a8008a6

16 files changed

Lines changed: 168 additions & 59 deletions

packages/pool/contracts/ClaimUtils.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ abstract contract ClaimUtils is StakeUtils, IClaimUtils {
4444
assert(api3Token.transfer(recipient, amount));
4545
emit PaidOutClaim(
4646
recipient,
47-
amount
47+
amount,
48+
totalStake
4849
);
4950
}
5051
}

packages/pool/contracts/DelegationUtils.sol

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ abstract contract DelegationUtils is RewardUtils, IDelegationUtils {
5353
}
5454

5555
// Assign the new delegation
56+
uint256 delegatedToUpdate = delegatedToUser(delegate) + userShares;
5657
updateCheckpointArray(
5758
users[delegate].delegatedTo,
58-
delegatedToUser(delegate) + userShares
59+
delegatedToUpdate
5960
);
6061

6162
// Record the new delegate for the user
@@ -66,7 +67,8 @@ abstract contract DelegationUtils is RewardUtils, IDelegationUtils {
6667
emit Delegated(
6768
msg.sender,
6869
delegate,
69-
userShares
70+
userShares,
71+
delegatedToUpdate
7072
);
7173
}
7274

@@ -89,9 +91,10 @@ abstract contract DelegationUtils is RewardUtils, IDelegationUtils {
8991
user.lastDelegationUpdateTimestamp = block.timestamp;
9092

9193
uint256 userShares = userShares(msg.sender);
94+
uint256 delegatedToUpdate = delegatedToUser(previousDelegate) - userShares;
9295
updateCheckpointArray(
9396
users[previousDelegate].delegatedTo,
94-
delegatedToUser(previousDelegate) - userShares
97+
delegatedToUpdate
9598
);
9699
updateAddressCheckpointArray(
97100
user.delegates,
@@ -100,7 +103,8 @@ abstract contract DelegationUtils is RewardUtils, IDelegationUtils {
100103
emit Undelegated(
101104
msg.sender,
102105
previousDelegate,
103-
userShares
106+
userShares,
107+
delegatedToUpdate
104108
);
105109
}
106110

@@ -122,17 +126,19 @@ abstract contract DelegationUtils is RewardUtils, IDelegationUtils {
122126
return;
123127
}
124128
uint256 currentDelegatedTo = delegatedToUser(delegate);
125-
uint256 newDelegatedTo = delta
129+
uint256 delegatedToUpdate = delta
126130
? currentDelegatedTo + shares
127131
: currentDelegatedTo - shares;
128132
updateCheckpointArray(
129133
users[delegate].delegatedTo,
130-
newDelegatedTo
134+
delegatedToUpdate
131135
);
132136
emit UpdatedDelegation(
133137
msg.sender,
134138
delegate,
135-
newDelegatedTo
139+
delta,
140+
shares,
141+
delegatedToUpdate
136142
);
137143
}
138144
}

packages/pool/contracts/StakeUtils.sol

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,24 @@ abstract contract StakeUtils is TransferUtils, IStakeUtils {
2121
user.unstaked -= amount;
2222
uint256 totalSharesNow = totalShares();
2323
uint256 sharesToMint = amount * totalSharesNow / totalStake;
24-
uint256 userSharesNow = userShares(msg.sender);
24+
uint256 userSharesUpdate = userShares(msg.sender) + sharesToMint;
2525
updateCheckpointArray(
2626
user.shares,
27-
userSharesNow + sharesToMint
27+
userSharesUpdate
2828
);
29+
uint256 totalSharesUpdate = totalSharesNow + sharesToMint;
2930
updateCheckpointArray(
3031
poolShares,
31-
totalSharesNow + sharesToMint
32+
totalSharesUpdate
3233
);
3334
totalStake += amount;
3435
updateDelegatedVotingPower(sharesToMint, true);
3536
emit Staked(
3637
msg.sender,
3738
amount,
38-
sharesToMint
39+
sharesToMint,
40+
userSharesUpdate,
41+
totalSharesUpdate
3942
);
4043
}
4144

@@ -91,16 +94,18 @@ abstract contract StakeUtils is TransferUtils, IStakeUtils {
9194
user.unstakeScheduledFor = unstakeScheduledFor;
9295
user.unstakeAmount = amount;
9396
user.unstakeShares = sharesToUnstake;
97+
uint256 userSharesUpdate = userSharesNow - sharesToUnstake;
9498
updateCheckpointArray(
9599
user.shares,
96-
userSharesNow - sharesToUnstake
100+
userSharesUpdate
97101
);
98102
updateDelegatedVotingPower(sharesToUnstake, false);
99103
emit ScheduledUnstake(
100104
msg.sender,
101105
amount,
102106
sharesToUnstake,
103-
unstakeScheduledFor
107+
unstakeScheduledFor,
108+
userSharesUpdate
104109
);
105110
}
106111

@@ -136,16 +141,21 @@ abstract contract StakeUtils is TransferUtils, IStakeUtils {
136141
}
137142
user.unstaked += unstakeAmount;
138143

144+
uint256 totalSharesUpdate = totalShares - user.unstakeShares;
139145
updateCheckpointArray(
140146
poolShares,
141-
totalShares - user.unstakeShares
147+
totalSharesUpdate
142148
);
143149
totalStake -= unstakeAmount;
144150

145151
user.unstakeAmount = 0;
146152
user.unstakeShares = 0;
147153
user.unstakeScheduledFor = 0;
148-
emit Unstaked(userAddress, unstakeAmount);
154+
emit Unstaked(
155+
userAddress,
156+
unstakeAmount,
157+
totalSharesUpdate
158+
);
149159
return unstakeAmount;
150160
}
151161

packages/pool/contracts/TimelockUtils.sol

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,15 @@ abstract contract TimelockUtils is ClaimUtils, ITimelockUtils {
4646
msg.sender == timelockManager,
4747
"Pool: Caller not TimelockManager"
4848
);
49-
users[userAddress].unstaked += amount;
49+
uint256 unstakedUpdate = users[userAddress].unstaked + amount;
50+
users[userAddress].unstaked = unstakedUpdate;
5051
// Should never return false because the API3 token uses the
5152
// OpenZeppelin implementation
5253
assert(api3Token.transferFrom(source, address(this), amount));
5354
emit DepositedByTimelockManager(
5455
userAddress,
55-
amount
56+
amount,
57+
unstakedUpdate
5658
);
5759
}
5860

@@ -103,8 +105,10 @@ abstract contract TimelockUtils is ClaimUtils, ITimelockUtils {
103105
amount != 0,
104106
"Pool: Timelock amount zero"
105107
);
106-
users[userAddress].unstaked += amount;
107-
users[userAddress].vesting += amount;
108+
uint256 unstakedUpdate = users[userAddress].unstaked + amount;
109+
users[userAddress].unstaked = unstakedUpdate;
110+
uint256 vestingUpdate = users[userAddress].vesting + amount;
111+
users[userAddress].vesting = vestingUpdate;
108112
userToTimelock[userAddress] = Timelock({
109113
totalAmount: amount,
110114
remainingAmount: amount,
@@ -118,7 +122,9 @@ abstract contract TimelockUtils is ClaimUtils, ITimelockUtils {
118122
userAddress,
119123
amount,
120124
releaseStart,
121-
releaseEnd
125+
releaseEnd,
126+
unstakedUpdate,
127+
vestingUpdate
122128
);
123129
}
124130

@@ -152,11 +158,13 @@ abstract contract TimelockUtils is ClaimUtils, ITimelockUtils {
152158
uint256 previouslyUnlocked = timelock.totalAmount - timelock.remainingAmount;
153159
uint256 newlyUnlocked = totalUnlocked - previouslyUnlocked;
154160
User storage user = users[userAddress];
155-
user.vesting -= newlyUnlocked;
161+
uint256 vestingUpdate = user.vesting - newlyUnlocked;
162+
user.vesting = vestingUpdate;
156163
timelock.remainingAmount -= newlyUnlocked;
157164
emit VestedTimelock(
158165
userAddress,
159-
newlyUnlocked
166+
newlyUnlocked,
167+
vestingUpdate
160168
);
161169
}
162170
}

packages/pool/contracts/TransferUtils.sol

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ abstract contract TransferUtils is DelegationUtils, ITransferUtils {
1717
override
1818
{
1919
mintReward();
20-
users[msg.sender].unstaked += amount;
20+
uint256 unstakedUpdate = users[msg.sender].unstaked + amount;
21+
users[msg.sender].unstaked = unstakedUpdate;
2122
// Should never return false because the API3 token uses the
2223
// OpenZeppelin implementation
2324
assert(api3Token.transferFrom(msg.sender, address(this), amount));
2425
emit Deposited(
2526
msg.sender,
26-
amount
27+
amount,
28+
unstakedUpdate
2729
);
2830
}
2931

@@ -148,13 +150,15 @@ abstract contract TransferUtils is DelegationUtils, ITransferUtils {
148150
"Pool: Not enough unstaked funds"
149151
);
150152
// Carry on with the withdrawal
151-
user.unstaked -= amount;
153+
uint256 unstakedUpdate = user.unstaked - amount;
154+
user.unstaked = unstakedUpdate;
152155
// Should never return false because the API3 token uses the
153156
// OpenZeppelin implementation
154157
assert(api3Token.transfer(msg.sender, amount));
155158
emit Withdrawn(
156159
msg.sender,
157-
amount
160+
amount,
161+
unstakedUpdate
158162
);
159163
}
160164
}

packages/pool/contracts/interfaces/IClaimUtils.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import "./IStakeUtils.sol";
66
interface IClaimUtils is IStakeUtils {
77
event PaidOutClaim(
88
address indexed recipient,
9-
uint256 amount
9+
uint256 amount,
10+
uint256 totalStake
1011
);
1112

1213
function payOutClaim(

packages/pool/contracts/interfaces/IDelegationUtils.sol

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,23 @@ interface IDelegationUtils is IRewardUtils {
77
event Delegated(
88
address indexed user,
99
address indexed delegate,
10-
uint256 shares
10+
uint256 shares,
11+
uint256 totalDelegatedTo
1112
);
1213

1314
event Undelegated(
1415
address indexed user,
1516
address indexed delegate,
16-
uint256 shares
17+
uint256 shares,
18+
uint256 totalDelegatedTo
1719
);
1820

1921
event UpdatedDelegation(
2022
address indexed user,
2123
address indexed delegate,
22-
uint256 shares
24+
bool delta,
25+
uint256 shares,
26+
uint256 totalDelegatedTo
2327
);
2428

2529
function delegateVotingPower(address delegate)

packages/pool/contracts/interfaces/IStakeUtils.sol

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,23 @@ interface IStakeUtils is ITransferUtils{
77
event Staked(
88
address indexed user,
99
uint256 amount,
10-
uint256 shares
10+
uint256 mintedShares,
11+
uint256 userShares,
12+
uint256 totalShares
1113
);
1214

1315
event ScheduledUnstake(
1416
address indexed user,
1517
uint256 amount,
1618
uint256 shares,
17-
uint256 scheduledFor
19+
uint256 scheduledFor,
20+
uint256 userShares
1821
);
1922

2023
event Unstaked(
2124
address indexed user,
22-
uint256 amount
25+
uint256 amount,
26+
uint256 totalShares
2327
);
2428

2529
function stake(uint256 amount)

packages/pool/contracts/interfaces/ITimelockUtils.sol

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,23 @@ import "./IClaimUtils.sol";
66
interface ITimelockUtils is IClaimUtils {
77
event DepositedByTimelockManager(
88
address indexed user,
9-
uint256 amount
9+
uint256 amount,
10+
uint256 userUnstaked
1011
);
1112

1213
event DepositedVesting(
1314
address indexed user,
1415
uint256 amount,
1516
uint256 start,
16-
uint256 end
17+
uint256 end,
18+
uint256 userUnstaked,
19+
uint256 userVesting
1720
);
1821

1922
event VestedTimelock(
2023
address indexed user,
21-
uint256 amount
24+
uint256 amount,
25+
uint256 userVesting
2226
);
2327

2428
function deposit(

packages/pool/contracts/interfaces/ITransferUtils.sol

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import "./IDelegationUtils.sol";
66
interface ITransferUtils is IDelegationUtils{
77
event Deposited(
88
address indexed user,
9-
uint256 amount
9+
uint256 amount,
10+
uint256 userUnstaked
1011
);
1112

1213
event Withdrawn(
1314
address indexed user,
14-
uint256 amount
15+
uint256 amount,
16+
uint256 userUnstaked
1517
);
1618

1719
event CalculatingUserLocked(

0 commit comments

Comments
 (0)