-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deployment scripts for BeefyClient & Gateway (#1190)
- Loading branch information
1 parent
b2bb92e
commit a6f30bb
Showing
12 changed files
with
269 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]> | ||
pragma solidity 0.8.23; | ||
|
||
import {Script} from "forge-std/Script.sol"; | ||
import {BeefyClient} from "../src/BeefyClient.sol"; | ||
|
||
contract DeployBeefyClient is Script { | ||
struct Config { | ||
uint64 startBlock; | ||
BeefyClient.ValidatorSet current; | ||
BeefyClient.ValidatorSet next; | ||
uint256 randaoCommitDelay; | ||
uint256 randaoCommitExpiration; | ||
uint256 minimumSignatures; | ||
} | ||
|
||
function readConfig() internal pure returns (Config memory config) { | ||
// Checkpoint generated at block 20733663 using the `./beefy-checkpoint.js` script in Polkadot-JS. | ||
// Block 20733663 is significant as that was when our bridge was initialized on BridgeHub. | ||
config = Config({ | ||
startBlock: 20733663, | ||
current: BeefyClient.ValidatorSet({id: 496, length: 297, root: 0xdd04a3a0a4a19180bdae78ecc0c089491d22f5b65b685199d877f20b7fc76434}), | ||
next: BeefyClient.ValidatorSet({id: 497, length: 297, root: 0xdd04a3a0a4a19180bdae78ecc0c089491d22f5b65b685199d877f20b7fc76434}), | ||
randaoCommitDelay: 128, | ||
randaoCommitExpiration: 24, | ||
minimumSignatures: 17 | ||
}); | ||
} | ||
|
||
function run() public { | ||
vm.startBroadcast(); | ||
Config memory config = readConfig(); | ||
|
||
new BeefyClient( | ||
config.randaoCommitDelay, | ||
config.randaoCommitExpiration, | ||
config.minimumSignatures, | ||
config.startBlock, | ||
config.current, | ||
config.next | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]> | ||
pragma solidity 0.8.23; | ||
|
||
import {WETH9} from "canonical-weth/WETH9.sol"; | ||
import {Script} from "forge-std/Script.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"; | ||
import {stdJson} from "forge-std/StdJson.sol"; | ||
import {UD60x18, ud60x18} from "prb/math/src/UD60x18.sol"; | ||
|
||
function mDot(uint32 value) pure returns (uint128) { | ||
// 1 mDOT = 0.001 DOT | ||
return value * (10 ** 7); | ||
} | ||
|
||
function dot(uint32 value) pure returns (uint128) { | ||
return value * (10 ** 10); | ||
} | ||
|
||
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: 0x27ca963C279c93801941e1eB8799c23f407d68e7, | ||
beefyClient: address(0), | ||
bridgeHubParaID: ParaID.wrap(1002), | ||
bridgeHubAgentID: 0x03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314, | ||
foreignTokenDecimals: 10, | ||
maxDestinationFee: dot(2), | ||
initializerParams: Gateway.Config({ | ||
mode: OperatingMode.Normal, | ||
deliveryCost: mDot(100), // 0.1 DOT | ||
registerTokenFee: 0.002 ether, | ||
assetHubParaID: ParaID.wrap(1000), | ||
assetHubAgentID: 0x81c5ab2571199e3188135178f3c2c8e2d268be1313d029b30f534fa579b69b79, | ||
assetHubCreateAssetFee: mDot(100), // 0.1 DOT | ||
assetHubReserveTransferFee: mDot(100), // 0.1 DOT | ||
exchangeRate: ud60x18(0.0024e18), | ||
multiplier: ud60x18(1.33e18), | ||
rescueOperator: 0x4B8a782D4F03ffcB7CE1e95C5cfe5BFCb2C8e967 | ||
}) | ||
}); | ||
} | ||
|
||
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Polkadot-JS script to generate a BEEFY checkpoint | ||
|
||
let beefyBlock = 20733663; | ||
let blockHash = await api.rpc.chain.getBlockHash(beefyBlock); | ||
let apiAtBlock = await api.at(blockHash); | ||
|
||
let authorities = await apiAtBlock.query.beefyMmrLeaf.beefyAuthorities(); | ||
let nextAuthorities = | ||
await apiAtBlock.query.beefyMmrLeaf.beefyNextAuthorities(); | ||
|
||
let beefyCheckpoint = { | ||
startBlock: beefyBlock, | ||
current: { | ||
id: authorities.id.toNumber(), | ||
root: authorities.keysetCommitment.toHex(), | ||
length: authorities.len.toNumber(), | ||
}, | ||
next: { | ||
id: nextAuthorities.id.toNumber(), | ||
root: nextAuthorities.keysetCommitment.toHex(), | ||
length: nextAuthorities.len.toNumber(), | ||
}, | ||
}; | ||
|
||
console.log(JSON.stringify(beefyCheckpoint, null, 2)); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]> | ||
pragma solidity 0.8.23; | ||
|
||
library OperatorStorage { | ||
struct Layout { | ||
address operator; | ||
} | ||
|
||
bytes32 internal constant SLOT = keccak256("org.snowbridge.storage.operator"); | ||
|
||
function layout() internal pure returns (Layout storage $) { | ||
bytes32 slot = SLOT; | ||
assembly { | ||
$.slot := slot | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.