-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
69ec4b2
commit df355ae
Showing
21 changed files
with
309 additions
and
210 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
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 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
File renamed without changes.
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,37 @@ | ||
// SPDX-License-Identifier: Apache 2 | ||
|
||
pragma solidity ^0.8.4; | ||
|
||
import {BytesParsing} from "wormhole-sdk/libraries/BytesParsing.sol"; | ||
import {tokenOrNativeTransfer} from "wormhole-sdk/utils/Transfer.sol"; | ||
import {senderAtLeastAdmin} from "wormhole-sdk/components/dispatcher/AccessControl.sol"; | ||
import {SWEEP_TOKENS_ID} from "wormhole-sdk/components/dispatcher/Ids.sol"; | ||
|
||
abstract contract SweepTokens { | ||
using BytesParsing for bytes; | ||
|
||
function dispatchExecSweepTokens( | ||
bytes calldata data, | ||
uint offset, | ||
uint8 command | ||
) internal returns (bool, uint) { | ||
return command == SWEEP_TOKENS_ID | ||
? (true, _sweepTokens(data, offset)) | ||
: (false, offset); | ||
} | ||
|
||
function _sweepTokens( | ||
bytes calldata commands, | ||
uint offset | ||
) internal returns (uint) { | ||
senderAtLeastAdmin(); | ||
|
||
address token; | ||
uint256 amount; | ||
(token, offset) = commands.asAddressCdUnchecked(offset); | ||
(amount, offset) = commands.asUint256CdUnchecked(offset); | ||
|
||
tokenOrNativeTransfer(token, msg.sender, amount); | ||
return offset; | ||
} | ||
} |
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,57 @@ | ||
// SPDX-License-Identifier: Apache 2 | ||
|
||
pragma solidity ^0.8.4; | ||
|
||
import {BytesParsing} from "wormhole-sdk/libraries/BytesParsing.sol"; | ||
import {ProxyBase} from "wormhole-sdk/proxy/ProxyBase.sol"; | ||
import {Role, senderRole, failAuthIf} from "wormhole-sdk/components/dispatcher/AccessControl.sol"; | ||
import {UPGRADE_CONTRACT_ID, IMPLEMENTATION_ID} from "wormhole-sdk/components/dispatcher/Ids.sol"; | ||
|
||
error InvalidGovernanceCommand(uint8 command); | ||
error InvalidGovernanceQuery(uint8 query); | ||
|
||
abstract contract Upgrade is ProxyBase { | ||
using BytesParsing for bytes; | ||
|
||
function dispatchExecUpgrade( | ||
bytes calldata data, | ||
uint offset, | ||
uint8 command | ||
) internal returns (bool, uint) { | ||
return (command == UPGRADE_CONTRACT_ID) | ||
? (true, _upgradeContract(data, offset)) | ||
: (false, offset); | ||
} | ||
|
||
function dispatchQueryUpgrade( | ||
bytes calldata, | ||
uint offset, | ||
uint8 query | ||
) view internal returns (bool, bytes memory, uint) { | ||
return query == IMPLEMENTATION_ID | ||
? (true, abi.encodePacked(_getImplementation()), offset) | ||
: (false, new bytes(0), offset); | ||
} | ||
|
||
function upgrade(address implementation, bytes calldata data) external { | ||
failAuthIf(senderRole() != Role.Owner); | ||
|
||
_upgradeTo(implementation, data); | ||
} | ||
|
||
function _upgradeContract( | ||
bytes calldata commands, | ||
uint offset | ||
) internal returns (uint) { | ||
failAuthIf(senderRole() != Role.Owner); | ||
|
||
address newImplementation; | ||
(newImplementation, offset) = commands.asAddressCdUnchecked(offset); | ||
//contract upgrades must be the last command in the batch | ||
commands.checkLengthCd(offset); | ||
|
||
_upgradeTo(newImplementation, new bytes(0)); | ||
|
||
return offset; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,11 +1,17 @@ | ||
// SPDX-License-Identifier: Apache 2 | ||
pragma solidity ^0.8.4; | ||
|
||
uint256 constant FREE_MEMORY_PTR = 0x40; | ||
// ┌──────────────────────────────────────────────────────────────────────────────┐ | ||
// │ NOTE: We can't define e.g. WORD_SIZE_MINUS_ONE via WORD_SIZE - 1 because │ | ||
// │ of solc restrictions on what constants can be used in inline assembly. │ | ||
// └──────────────────────────────────────────────────────────────────────────────┘ | ||
|
||
uint256 constant WORD_SIZE = 32; | ||
//we can't define _WORD_SIZE_MINUS_ONE via _WORD_SIZE - 1 because of solc restrictions | ||
// what constants can be used in inline assembly | ||
uint256 constant WORD_SIZE_MINUS_ONE = 31; //=0x1f=0b00011111 | ||
|
||
//see section "prefer `< MAX + 1` over `<= MAX` for const comparison" in docs/Optimization.md | ||
uint256 constant WORD_SIZE_PLUS_ONE = 33; | ||
|
||
uint256 constant SCRATCH_SPACE_PTR = 0x00; | ||
uint256 constant SCRATCH_SPACE_SIZE = 64; | ||
|
||
uint256 constant FREE_MEMORY_PTR = 0x40; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.