Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixFan1992 committed Mar 22, 2024
1 parent 682c89e commit 25c0c00
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 62 deletions.
111 changes: 55 additions & 56 deletions contracts/src/v0.8/automation/dev/v2_3/AutomationRegistry2_3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -299,59 +299,7 @@ contract AutomationRegistry2_3 is AutomationRegistryBase2_3, OCR2Abstract, Chain
// set billing config for tokens
_setBillingConfig(billingTokens, billingConfigs);

// move all pooled payments out of the pool to each transmitter's balance
for (uint256 i = 0; i < s_transmittersList.length; i++) {
_updateTransmitterBalanceFromPool(
s_transmittersList[i],
s_hotVars.totalPremium,
uint96(s_transmittersList.length)
);
}

// remove any old signer/transmitter addresses
address signerAddress;
address transmitterAddress;
//PayoutMode mode = s_payoutMode;
for (uint256 i = 0; i < s_transmittersList.length; i++) {
signerAddress = s_signersList[i];
transmitterAddress = s_transmittersList[i];
delete s_signers[signerAddress];
// Do not delete the whole transmitter struct as it has balance information stored
s_transmitters[transmitterAddress].active = false;
if (s_payoutMode == PayoutMode.OFF_CHAIN) {
s_deactivatedTransmitters.add(transmitterAddress);
}
}
delete s_signersList;
delete s_transmittersList;

// add new signer/transmitter addresses
{
Transmitter memory transmitter;
address temp;
//PayoutMode mode = s_payoutMode;
for (uint256 i = 0; i < signers.length; i++) {
if (s_signers[signers[i]].active) revert RepeatedSigner();
if (signers[i] == ZERO_ADDRESS) revert InvalidSigner();
s_signers[signers[i]] = Signer({active: true, index: uint8(i)});

temp = transmitters[i];
if (temp == ZERO_ADDRESS) revert InvalidTransmitter();
transmitter = s_transmitters[temp];
if (transmitter.active) revert RepeatedTransmitter();
transmitter.active = true;
transmitter.index = uint8(i);
// new transmitters start afresh from current totalPremium
// some spare change of premium from previous pool will be forfeited
transmitter.lastCollected = s_hotVars.totalPremium;
s_transmitters[temp] = transmitter;
if (s_payoutMode == PayoutMode.OFF_CHAIN) {
s_deactivatedTransmitters.remove(temp);
}
}
}
s_signersList = signers;
s_transmittersList = transmitters;
_updateTransmitters(signers, transmitters);

s_hotVars = HotVars({
f: f,
Expand Down Expand Up @@ -400,9 +348,7 @@ contract AutomationRegistry2_3 is AutomationRegistryBase2_3, OCR2Abstract, Chain
offchainConfig
);

for (uint256 idx = 0; idx < s_registrars.length(); idx++) {
s_registrars.remove(s_registrars.at(idx));
}
delete s_registrars;

for (uint256 idx = 0; idx < onchainConfig.registrars.length; idx++) {
s_registrars.add(onchainConfig.registrars[idx]);
Expand All @@ -421,6 +367,59 @@ contract AutomationRegistry2_3 is AutomationRegistryBase2_3, OCR2Abstract, Chain
);
}

function _updateTransmitters(address[] memory signers, address[] memory transmitters) internal {
// move all pooled payments out of the pool to each transmitter's balance
for (uint256 i = 0; i < s_transmittersList.length; i++) {
_updateTransmitterBalanceFromPool(
s_transmittersList[i],
s_hotVars.totalPremium,
uint96(s_transmittersList.length)
);
}

// remove any old signer/transmitter addresses
address signerAddress;
address transmitterAddress;
PayoutMode mode = s_payoutMode;
for (uint256 i = 0; i < s_transmittersList.length; i++) {
signerAddress = s_signersList[i];
transmitterAddress = s_transmittersList[i];
delete s_signers[signerAddress];
// Do not delete the whole transmitter struct as it has balance information stored
s_transmitters[transmitterAddress].active = false;
if (mode == PayoutMode.OFF_CHAIN) {
s_deactivatedTransmitters.add(transmitterAddress);
}
}
delete s_signersList;
delete s_transmittersList;

// add new signer/transmitter addresses
Transmitter memory transmitter;
for (uint256 i = 0; i < signers.length; i++) {
if (s_signers[signers[i]].active) revert RepeatedSigner();
if (signers[i] == ZERO_ADDRESS) revert InvalidSigner();
s_signers[signers[i]] = Signer({active: true, index: uint8(i)});

transmitterAddress = transmitters[i];
if (transmitterAddress == ZERO_ADDRESS) revert InvalidTransmitter();
transmitter = s_transmitters[transmitterAddress];
if (transmitter.active) revert RepeatedTransmitter();
transmitter.active = true;
transmitter.index = uint8(i);
// new transmitters start afresh from current totalPremium
// some spare change of premium from previous pool will be forfeited
transmitter.lastCollected = s_hotVars.totalPremium;
s_transmitters[transmitterAddress] = transmitter;
if (mode == PayoutMode.OFF_CHAIN) {
s_deactivatedTransmitters.remove(transmitterAddress);
}
}

s_signersList = signers;
s_transmittersList = transmitters;
}

// ================================================================
// | GETTERS |
// ================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,8 @@ contract AutomationRegistryLogicC2_3 is AutomationRegistryBase2_3 {
address deactivatedAddr = s_deactivatedTransmitters.at(i);
Transmitter memory transmitter = s_transmitters[deactivatedAddr];
payees[i + activeTransmittersLength] = s_transmitterPayees[deactivatedAddr];
if (transmitter.balance != 0) {
payments[i + activeTransmittersLength] = transmitter.balance;
s_transmitters[deactivatedAddr].balance = 0;
}
payments[i + activeTransmittersLength] = transmitter.balance;
s_transmitters[deactivatedAddr].balance = 0;
}
delete s_deactivatedTransmitters;

Expand Down
Loading

0 comments on commit 25c0c00

Please sign in to comment.