Skip to content

Commit

Permalink
script: add bash script for bulk override tiers and bulk reset renewa…
Browse files Browse the repository at this point in the history
…l fees
  • Loading branch information
TuDo1403 committed Mar 12, 2024
1 parent 399a1ef commit 8fe81bb
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 8 deletions.
8 changes: 5 additions & 3 deletions config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ loadConfig() {
ERC721_BATCH_TRANSFER=0x2368dfed532842db89b470fde9fd584d48d4f644

if [ "$MODE" == "broadcast" ]; then
PK=$TESTNET_PK
PK=$MAINNET_PK
fi
else
RPC=$TESTNET_URL
Expand All @@ -37,18 +37,20 @@ loadConfig() {
ERC721_BATCH_TRANSFER=0x2e889348bd37f192063bfec8ff39bd3635949e20

if [ "$MODE" == "broadcast" ]; then
PK=$MAINNET_PK
PK=$TESTNET_PK
fi
fi

if [ "$MODE" == "broadcast" ]; then
CURRENT_NONCE=$(cast nonce --rpc-url $RPC $FROM)
CURRENT_GAS_PRICE=$(cast gas-price --rpc-url $RPC)

if [[ "$PK" == op://* ]]; then
PK=$(op read "$PK")
fi
fi

CURRENT_NONCE=$(cast nonce --rpc-url $RPC $FROM)
echo "Current nonce: $CURRENT_NONCE"
}

# Function to load address from deployment file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { StdStyle } from "forge-std/StdStyle.sol";
import { IMulticall3 } from "forge-std/interfaces/IMulticall3.sol";
import { LibString } from "solady/utils/LibString.sol";
import { DefaultNetwork } from "foundry-deployment-kit/utils/DefaultNetwork.sol";
Expand All @@ -10,6 +11,7 @@ import { INSDomainPrice, RNSDomainPrice } from "@rns-contracts/RNSDomainPrice.so
import "./20240215_Migration.s.sol";

contract Migration__01_UpgradeRNSDomainPriceAndOverrideTierForCommunityNames_RNSDomainPrice is Migration__20240215 {
using StdStyle for *;
using LibString for *;

RNSDomainPrice internal _domainPrice;
Expand All @@ -29,14 +31,13 @@ contract Migration__01_UpgradeRNSDomainPriceAndOverrideTierForCommunityNames_RNS
uint256 totalBatches = (totalElements + batchSize - 1) / batchSize;

address overrider = _domainPrice.getRoleMember(_domainPrice.OVERRIDER_ROLE(), 0);
console.log("Overrider".yellow(), overrider);

for (uint256 i; i < totalBatches; i++) {
console.log("Processing batch", i, "of", totalBatches);
uint256 start = i * batchSize;
uint256 end = (i + 1) * batchSize;
if (end > totalElements) {
end = totalElements;
}
if (end > totalElements) end = totalElements;

bytes32[] memory batchHashes = new bytes32[](end - start);
INSDomainPrice.Tier[] memory batchTiers = new INSDomainPrice.Tier[](end - start);
Expand All @@ -46,7 +47,7 @@ contract Migration__01_UpgradeRNSDomainPriceAndOverrideTierForCommunityNames_RNS
batchTiers[j - start] = _tiers[j];
}

vm.broadcast(overrider);
vm.prank(overrider);
_domainPrice.bulkOverrideTiers(batchHashes, batchTiers);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ contract Migration__20240215 is Migration {
returns (string[] memory labels, INSDomainPrice.Tier[] memory tiers)
{
string memory raw = vm.readFile(path);
JSONParserLib.Item memory communityNames = raw.parse();
JSONParserLib.Item memory communityNames = raw.parse().at('"communityNames"');
uint256 length = communityNames.size();
console.log("length", length);

Expand Down
1 change: 1 addition & 0 deletions script/Migration.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ abstract contract Migration is BaseMigration {

// RNSDomainPrice
param.rnsDomainPrice.admin = temporaryAdmin;
param.rnsDomainPrice.overrider = duke;
param.rnsDomainPrice.domainPriceOperators = _toSingletonArray(operator);
param.rnsDomainPrice.renewalFees = new INSDomainPrice.RenewalFee[](4);
param.rnsDomainPrice.renewalFees[0] = INSDomainPrice.RenewalFee(5, uint256(5e18) / 365 days);
Expand Down
79 changes: 79 additions & 0 deletions script/operations/20240313-override-tier.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
source config.sh

# Declare an array to store results

# Read the JSON file
jsonData=$(cat "script/data/517 Community names (Tier 1) - _3 characters.json")

# Parse JSON data
labels=$(
node -e '
const labels = JSON.parse(process.argv[1]).communityNames.map(name => name.domain);
labels.forEach(v => console.log(v))
' "$jsonData"
)

tiers=$(
node -e '
const tiers = JSON.parse(process.argv[1]).communityNames.map(name => name.tier);
tiers.forEach(v => console.log(v))
' "$jsonData"
)

batchSize=100
length=${#labels[@]}
labels=($labels)
tiers=($tiers)
length=${#labels[@]}
echo "Num override tier: $length \n"

# Calculate the number of batches
numBatches=$(((length + batchSize - 1) / batchSize))
echo "Number of Batches: $numBatches \n"

# Loop through each batch
for ((batch = 0; batch < numBatches; batch++)); do
(
# Increment nextNonce
nextNonce=$((CURRENT_NONCE + batch))

# Calculate the start and end index for the current batch
start=$((batch * batchSize))
end=$((start + batchSize - 1))
if ((end >= length)); then
end=$((length - 1))
fi

echo "Next Nonce: $nextNonce"
echo "Batch: $batch"
echo "Start: $start, End: $end \n"

# Declare arrays to store results
labelhashResults=()
tiersBatch=()

# Loop through each label and call cast namehash
for ((i = start; i <= end; i++)); do
label=${labels[i]}
tier=${tiers[i]}
result=$(cast keccak $(cast from-utf8 $label))
labelhashResults+=($result)
tiersBatch+=($tier)
done

# Join array elements with ","
lbHash=$(
IFS=,
echo "${labelhashResults[*]}"
)

tiersBatch=$(
IFS=,
echo "${tiersBatch[*]}"
)

execute $nextNonce $(loadAddress RNSDomainPriceProxy) $(cast calldata "bulkOverrideTiers(bytes32[],uint8[])" "[$lbHash]" "[$tiersBatch]")
) &
done

wait
79 changes: 79 additions & 0 deletions script/operations/20240313-reset-fee.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
source config.sh

# Declare an array to store results

# Read the JSON file
jsonData=$(cat "script/data/517 Community names (Tier 1) - _3 characters.json")

# Parse JSON data
labels=$(
node -e '
const labels = JSON.parse(process.argv[1]).communityNames.map(name => name.domain);
labels.forEach(v => console.log(v))
' "$jsonData"
)

tiers=$(
node -e '
const tiers = JSON.parse(process.argv[1]).communityNames.map(name => name.tier);
tiers.forEach(v => console.log("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))
' "$jsonData"
)

batchSize=100
length=${#labels[@]}
labels=($labels)
tiers=($tiers)
length=${#labels[@]}
echo "Num reset tier: $length \n"

# Calculate the number of batches
numBatches=$(((length + batchSize - 1) / batchSize))
echo "Number of Batches: $numBatches \n"

# Loop through each batch
for ((batch = 0; batch < numBatches; batch++)); do
(
# Increment nextNonce
nextNonce=$((CURRENT_NONCE + batch))

# Calculate the start and end index for the current batch
start=$((batch * batchSize))
end=$((start + batchSize - 1))
if ((end >= length)); then
end=$((length - 1))
fi

echo "Next Nonce: $nextNonce"
echo "Batch: $batch"
echo "Start: $start, End: $end \n"

# Declare arrays to store results
labelhashResults=()
tiersBatch=()

# Loop through each label and call cast namehash
for ((i = start; i <= end; i++)); do
label=${labels[i]}
tier=${tiers[i]}
result=$(cast keccak $(cast from-utf8 $label))
labelhashResults+=($result)
tiersBatch+=($tier)
done

# Join array elements with ","
lbHash=$(
IFS=,
echo "${labelhashResults[*]}"
)

tiersBatch=$(
IFS=,
echo "${tiersBatch[*]}"
)

execute $nextNonce $(loadAddress RNSDomainPriceProxy) $(cast calldata "bulkOverrideRenewalFees(bytes32[],uint256[])" "[$lbHash]" "[$tiersBatch]")
) &
done

wait

0 comments on commit 8fe81bb

Please sign in to comment.