Skip to content

Commit

Permalink
Add rate limits
Browse files Browse the repository at this point in the history
  • Loading branch information
wcgcyx committed Nov 21, 2023
1 parent f1c8948 commit d1fefc1
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 0 deletions.
32 changes: 32 additions & 0 deletions scripts/bootstrap/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,38 @@ RATE_LIMIT_ETH_CAPACITY=
RATE_LIMIT_ETH_REFILL_RATE=
## The large threshold of the rate limit policy of ETH token, unit is in 10^18.
RATE_LIMIT_ETH_LARGE_THRESHOLD=
## The address of USDC token to set rate limit policy.
RATE_LIMIT_USDC_ADDR=
## The capacity of the rate limit policy of USDC token, unit is in 10^18.
RATE_LIMIT_USDC_CAPACITY=
## The refill rate of the rate limit policy of USDC token, unit is in 10^18.
RATE_LIMIT_USDC_REFILL_RATE=
## The large threshold of the rate limit policy of USDC token, unit is in 10^18.
RATE_LIMIT_USDC_LARGE_THRESHOLD=
## The address of GU token to set rate limit policy.
RATE_LIMIT_GU_ADDR=
## The capacity of the rate limit policy of GU token, unit is in 10^18.
RATE_LIMIT_GU_CAPACITY=
## The refill rate of the rate limit policy of GU token, unit is in 10^18.
RATE_LIMIT_GU_REFILL_RATE=
## The large threshold of the rate limit policy of GU token, unit is in 10^18.
RATE_LIMIT_GU_LARGE_THRESHOLD=
## The address of CheckMate token to set rate limit policy.
RATE_LIMIT_CHECKMATE_ADDR=
## The capacity of the rate limit policy of CheckMate token, unit is in 10^18.
RATE_LIMIT_CHECKMATE_CAPACITY=
## The refill rate of the rate limit policy of CheckMate token, unit is in 10^18.
RATE_LIMIT_CHECKMATE_REFILL_RATE=
## The large threshold of the rate limit policy of CheckMate token, unit is in 10^18.
RATE_LIMIT_CHECKMATE_LARGE_THRESHOLD=
## The address of GOG token to set rate limit policy.
RATE_LIMIT_GOG_ADDR=
## The capacity of the rate limit policy of GOG token, unit is in 10^18.
RATE_LIMIT_GOG_CAPACITY=
## The refill rate of the rate limit policy of GOG token, unit is in 10^18.
RATE_LIMIT_GOG_REFILL_RATE=
## The large threshold of the rate limit policy of GOG token, unit is in 10^18.
RATE_LIMIT_GOG_LARGE_THRESHOLD=

# Set prior to 2_deployment_validation.js
CHILD_GATEWAY_ADDRESS=
Expand Down
52 changes: 52 additions & 0 deletions scripts/bootstrap/8_root_initialisation.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ async function run() {
let rateLimitETHCap = helper.requireEnv("RATE_LIMIT_ETH_CAPACITY");
let rateLimitETHRefill = helper.requireEnv("RATE_LIMIT_ETH_REFILL_RATE");
let rateLimitETHLargeThreshold = helper.requireEnv("RATE_LIMIT_ETH_LARGE_THRESHOLD");
let rateLimitUSDCAddr = helper.requireEnv("RATE_LIMIT_USDC_ADDR");
let rateLimitUSDCCap = helper.requireEnv("RATE_LIMIT_USDC_CAPACITY");
let rateLimitUSDCRefill = helper.requireEnv("RATE_LIMIT_USDC_REFILL_RATE");
let rateLimitUSDCLargeThreshold = helper.requireEnv("RATE_LIMIT_USDC_LARGE_THRESHOLD");
let rateLimitGUAddr = helper.requireEnv("RATE_LIMIT_GU_ADDR");
let rateLimitGUCap = helper.requireEnv("RATE_LIMIT_GU_CAPACITY");
let rateLimitGURefill = helper.requireEnv("RATE_LIMIT_GU_REFILL_RATE");
let rateLimitGULargeThreshold = helper.requireEnv("RATE_LIMIT_GU_LARGE_THRESHOLD");
let rateLimitCheckMateAddr = helper.requireEnv("RATE_LIMIT_CHECKMATE_ADDR");
let rateLimitCheckMateCap = helper.requireEnv("RATE_LIMIT_CHECKMATE_CAPACITY");
let rateLimitCheckMateRefill = helper.requireEnv("RATE_LIMIT_CHECKMATE_REFILL_RATE");
let rateLimitCheckMateLargeThreshold = helper.requireEnv("RATE_LIMIT_CHECKMATE_LARGE_THRESHOLD");
let rateLimitGOGAddr = helper.requireEnv("RATE_LIMIT_GOG_ADDR");
let rateLimitGOGCap = helper.requireEnv("RATE_LIMIT_GOG_CAPACITY");
let rateLimitGOGRefill = helper.requireEnv("RATE_LIMIT_GOG_REFILL_RATE");
let rateLimitGOGLargeThreshold = helper.requireEnv("RATE_LIMIT_GOG_LARGE_THRESHOLD");

// Read from contract file.
let data = fs.readFileSync(".child.bridge.contracts.json", 'utf-8');
Expand Down Expand Up @@ -112,6 +128,42 @@ async function run() {
);
await helper.waitForReceipt(resp.hash, rootProvider);

// USDC
resp = await rootBridge.connect(rateAdminWallet).setRateControlThreshold(
rateLimitUSDCAddr,
ethers.utils.parseEther(rateLimitUSDCCap),
ethers.utils.parseEther(rateLimitUSDCRefill),
ethers.utils.parseEther(rateLimitUSDCLargeThreshold)
);
await helper.waitForReceipt(resp.hash, rootProvider);

// GU
resp = await rootBridge.connect(rateAdminWallet).setRateControlThreshold(
rateLimitGUAddr,
ethers.utils.parseEther(rateLimitGUCap),
ethers.utils.parseEther(rateLimitGURefill),
ethers.utils.parseEther(rateLimitGULargeThreshold)
);
await helper.waitForReceipt(resp.hash, rootProvider);

// Checkmate
resp = await rootBridge.connect(rateAdminWallet).setRateControlThreshold(
rateLimitCheckMateAddr,
ethers.utils.parseEther(rateLimitCheckMateCap),
ethers.utils.parseEther(rateLimitCheckMateRefill),
ethers.utils.parseEther(rateLimitCheckMateLargeThreshold)
);
await helper.waitForReceipt(resp.hash, rootProvider);

// GOG
resp = await rootBridge.connect(rateAdminWallet).setRateControlThreshold(
rateLimitGOGAddr,
ethers.utils.parseEther(rateLimitGOGCap),
ethers.utils.parseEther(rateLimitGOGRefill),
ethers.utils.parseEther(rateLimitGOGLargeThreshold)
);
await helper.waitForReceipt(resp.hash, rootProvider);

// Initialise root adaptor
let rootAdaptorObj = JSON.parse(fs.readFileSync('../../out/RootAxelarBridgeAdaptor.sol/RootAxelarBridgeAdaptor.json', 'utf8'));
console.log("Initialise root adaptor...");
Expand Down
32 changes: 32 additions & 0 deletions scripts/bootstrap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,38 @@ RATE_LIMIT_ETH_CAPACITY=
RATE_LIMIT_ETH_REFILL_RATE=
## The large threshold of the rate limit policy of ETH token, unit is in 10^18.
RATE_LIMIT_ETH_LARGE_THRESHOLD=
## The address of USDC token to set rate limit policy.
RATE_LIMIT_USDC_ADDR=
## The capacity of the rate limit policy of USDC token, unit is in 10^18.
RATE_LIMIT_USDC_CAPACITY=
## The refill rate of the rate limit policy of USDC token, unit is in 10^18.
RATE_LIMIT_USDC_REFILL_RATE=
## The large threshold of the rate limit policy of USDC token, unit is in 10^18.
RATE_LIMIT_USDC_LARGE_THRESHOLD=
## The address of GU token to set rate limit policy.
RATE_LIMIT_GU_ADDR=
## The capacity of the rate limit policy of GU token, unit is in 10^18.
RATE_LIMIT_GU_CAPACITY=
## The refill rate of the rate limit policy of GU token, unit is in 10^18.
RATE_LIMIT_GU_REFILL_RATE=
## The large threshold of the rate limit policy of GU token, unit is in 10^18.
RATE_LIMIT_GU_LARGE_THRESHOLD=
## The address of CheckMate token to set rate limit policy.
RATE_LIMIT_CHECKMATE_ADDR=
## The capacity of the rate limit policy of CheckMate token, unit is in 10^18.
RATE_LIMIT_CHECKMATE_CAPACITY=
## The refill rate of the rate limit policy of CheckMate token, unit is in 10^18.
RATE_LIMIT_CHECKMATE_REFILL_RATE=
## The large threshold of the rate limit policy of CheckMate token, unit is in 10^18.
RATE_LIMIT_CHECKMATE_LARGE_THRESHOLD=
## The address of GOG token to set rate limit policy.
RATE_LIMIT_GOG_ADDR=
## The capacity of the rate limit policy of GOG token, unit is in 10^18.
RATE_LIMIT_GOG_CAPACITY=
## The refill rate of the rate limit policy of GOG token, unit is in 10^18.
RATE_LIMIT_GOG_REFILL_RATE=
## The large threshold of the rate limit policy of GOG token, unit is in 10^18.
RATE_LIMIT_GOG_LARGE_THRESHOLD=
```
3. Fund deployer
```
Expand Down
32 changes: 32 additions & 0 deletions scripts/localdev/.env.local
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,38 @@ RATE_LIMIT_ETH_CAPACITY=10.08
RATE_LIMIT_ETH_REFILL_RATE=0.0028
## The large threshold of the rate limit policy of ETH token, unit is in 10^18.
RATE_LIMIT_ETH_LARGE_THRESHOLD=5.04
## The address of USDC token to set rate limit policy.
RATE_LIMIT_USDC_ADDR=0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
## The capacity of the rate limit policy of USDC token, unit is in 10^18.
RATE_LIMIT_USDC_CAPACITY=20016
## The refill rate of the rate limit policy of USDC token, unit is in 10^18.
RATE_LIMIT_USDC_REFILL_RATE=5.56
## The large threshold of the rate limit policy of USDC token, unit is in 10^18.
RATE_LIMIT_USDC_LARGE_THRESHOLD=10008
## The address of GU token to set rate limit policy.
RATE_LIMIT_GU_ADDR=0xccC8cb5229B0ac8069C51fd58367Fd1e622aFD97
## The capacity of the rate limit policy of GU token, unit is in 10^18.
RATE_LIMIT_GU_CAPACITY=68976
## The refill rate of the rate limit policy of GU token, unit is in 10^18.
RATE_LIMIT_GU_REFILL_RATE=19.16
## The large threshold of the rate limit policy of GU token, unit is in 10^18.
RATE_LIMIT_GU_LARGE_THRESHOLD=34488
## The address of CheckMate token to set rate limit policy.
RATE_LIMIT_CHECKMATE_ADDR=0xE910c2a090516Fb7a7Be07f96a464785f2D5Dc18
## The capacity of the rate limit policy of CheckMate token, unit is in 10^18.
RATE_LIMIT_CHECKMATE_CAPACITY=12276000
## The refill rate of the rate limit policy of CheckMate token, unit is in 10^18.
RATE_LIMIT_CHECKMATE_REFILL_RATE=3410
## The large threshold of the rate limit policy of CheckMate token, unit is in 10^18.
RATE_LIMIT_CHECKMATE_LARGE_THRESHOLD=6138000
## The address of GOG token to set rate limit policy.
RATE_LIMIT_GOG_ADDR=0x9AB7bb7FdC60f4357ECFef43986818A2A3569c62
## The capacity of the rate limit policy of GOG token, unit is in 10^18.
RATE_LIMIT_GOG_CAPACITY=255816
## The refill rate of the rate limit policy of GOG token, unit is in 10^18.
RATE_LIMIT_GOG_REFILL_RATE=71.06
## The large threshold of the rate limit policy of GOG token, unit is in 10^18.
RATE_LIMIT_GOG_LARGE_THRESHOLD=127908

# Set prior to 2_deployment_validation.js
CHILD_GATEWAY_ADDRESS=0xcf27F781841484d5CF7e155b44954D7224caF1dD
Expand Down

0 comments on commit d1fefc1

Please sign in to comment.