Skip to content

Commit

Permalink
Initialize for westend
Browse files Browse the repository at this point in the history
  • Loading branch information
yrong committed Sep 13, 2024
1 parent 77b4c04 commit 6cee4af
Show file tree
Hide file tree
Showing 27 changed files with 862 additions and 46 deletions.
82 changes: 82 additions & 0 deletions contracts/scripts/westend/UpgradeShell.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]>
pragma solidity 0.8.25;

import {WETH9} from "canonical-weth/WETH9.sol";
import {Script} from "forge-std/Script.sol";
import {stdJson} from "forge-std/StdJson.sol";
import {UD60x18, ud60x18} from "prb/math/src/UD60x18.sol";

import {BeefyClient} from "../../src/BeefyClient.sol";
import {IGateway} from "../../src/interfaces/IGateway.sol";
import {IShell} from "../../src/interfaces/IShell.sol";
import {GatewayProxy} from "../../src/GatewayProxy.sol";
import {Gateway} from "../../src/Gateway.sol";
import {MockGatewayV2} from "../../test/mocks/MockGatewayV2.sol";
import {Agent} from "../../src/Agent.sol";
import {AgentExecutor} from "../../src/AgentExecutor.sol";
import {ChannelID, ParaID, OperatingMode} from "../../src/Types.sol";
import {SafeNativeTransfer} from "../../src/utils/SafeTransfer.sol";

contract UpgradeShell is Script {
using SafeNativeTransfer for address payable;
using stdJson for string;

struct Config {
address gatewayProxy;
address beefyClient;
ParaID bridgeHubParaID;
bytes32 bridgeHubAgentID;
uint8 foreignTokenDecimals;
uint128 maxDestinationFee;
Gateway.Config initializerParams;
}

function readConfig() internal pure returns (Config memory config) {
config = Config({
gatewayProxy: 0x9Ed8b47Bc3417e3BD0507ADC06E56e2Fa360A4E9,
beefyClient: 0x6DFaD3D73A28c48E4F4c616ECda80885b415283a,
bridgeHubParaID: ParaID.wrap(1002),
bridgeHubAgentID: 0x03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314,
foreignTokenDecimals: 12,
maxDestinationFee: 2000000000000,
initializerParams: Gateway.Config({
mode: OperatingMode.Normal,
deliveryCost: 200000000000, // 0.2 Wnd
registerTokenFee: 0.002 ether,
assetHubParaID: ParaID.wrap(1000),
assetHubAgentID: 0x81c5ab2571199e3188135178f3c2c8e2d268be1313d029b30f534fa579b69b79,
assetHubCreateAssetFee: 200000000000, // 0.2 Wnd
assetHubReserveTransferFee: 200000000000, // 0.2 Wnd
exchangeRate: ud60x18(2400000000000000),
multiplier: ud60x18(1330000000000000000),
rescueOperator: 0x302F0B71B8aD3CF6dD90aDb668E49b2168d652fd
})
});
}

function run() public {
vm.startBroadcast();

Config memory config = readConfig();

// AgentExecutor
AgentExecutor executor = new AgentExecutor();

// Gateway implementation
Gateway gatewayLogic = new Gateway(
config.beefyClient,
address(executor),
config.bridgeHubParaID,
config.bridgeHubAgentID,
config.foreignTokenDecimals,
config.maxDestinationFee
);

IShell shell = IShell(config.gatewayProxy);

shell.upgrade(address(gatewayLogic), address(gatewayLogic).codehash, abi.encode(config.initializerParams));

vm.stopBroadcast();
}
}
36 changes: 36 additions & 0 deletions control/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions control/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ members = [
"runtimes/polkadot",
"runtimes/bridge-hub-polkadot",
"runtimes/asset-hub-polkadot",
"runtimes/westend",
"runtimes/bridge-hub-westend",
"runtimes/asset-hub-westend",
"preimage",
]

Expand Down
21 changes: 17 additions & 4 deletions control/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ Tools for generating governance proposals
## Example: Generate bridge activation preimage

```shell
cargo run --bin snowbridge-preimage -- \
--bridge-hub-api ws://localhost:8001 \
--asset-hub-api ws://localhost:8000 \
cargo run --features polkadot --bin snowbridge-preimage -- \
initialize \
--exchange-rate-numerator 1 \
--exchange-rate-denominator 400 \
Expand All @@ -16,11 +14,26 @@ cargo run --bin snowbridge-preimage -- \
--fee-per-gas 80 \
--local-reward 0.01 \
--remote-reward 0.0001 \
--checkpoint initial-checkpoint.json \
--checkpoint initial-checkpoint-mainnet.json \
--gateway-address 0x1F98431c8aD98523631AE4a59f267346ea31F984 \
--gateway-operating-mode normal
```

```shell
cargo run --features westend --bin snowbridge-preimage -- \
initialize \
--exchange-rate-numerator 1 \
--exchange-rate-denominator 400 \
--multiplier-numerator 4 \
--multiplier-denominator 3 \
--fee-per-gas 80 \
--local-reward 0.01 \
--remote-reward 0.0001 \
--checkpoint initial-checkpoint-sepolia.json \
--gateway-address 0x9ed8b47bc3417e3bd0507adc06e56e2fa360a4e9 \
--gateway-operating-mode normal
```

The preimage can be tested using the generated `chopsticks-execute-upgrade.js` script

NOTE: Since the 1.2.0 upgrade has not executed yet on mainnet Polkadot, I tested the tool using a local zombienet or chopsticks environment. Pass the `--bridge-hub-api` the `--asset-hub-api` params to override the default API endpoints.
Expand Down
Loading

0 comments on commit 6cee4af

Please sign in to comment.