@wormhole-foundation/wormhole-solidity-sdk 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +13 -0
- package/README.md +78 -0
- package/contracts/Executor/Integration.sol +180 -0
- package/contracts/Executor/RelayInstruction.sol +108 -0
- package/contracts/Executor/Request.sol +43 -0
- package/contracts/RawDispatcher.sol +29 -0
- package/contracts/Utils.sol +27 -0
- package/contracts/WormholeRelayer/AdditionalMessages.sol +37 -0
- package/contracts/WormholeRelayer/Keys.sol +198 -0
- package/contracts/WormholeRelayer/Receiver.sol +44 -0
- package/contracts/WormholeRelayer/Sender.sol +264 -0
- package/contracts/WormholeRelayer.sol +7 -0
- package/contracts/constants/CctpDomainMapping.sol +72 -0
- package/contracts/constants/CctpDomains.sol +21 -0
- package/contracts/constants/Chains.sol +66 -0
- package/contracts/constants/Common.sol +17 -0
- package/contracts/constants/ConsistencyLevel.sol +9 -0
- package/contracts/interfaces/ICoreBridge.sol +80 -0
- package/contracts/interfaces/ICustomConsistencyLevel.sol +12 -0
- package/contracts/interfaces/IDeliveryProvider.sol +84 -0
- package/contracts/interfaces/IExecutor.sol +32 -0
- package/contracts/interfaces/ITokenBridge.sol +81 -0
- package/contracts/interfaces/IWormholeRelayer.sol +658 -0
- package/contracts/interfaces/cctp/IMessageTransmitter.sol +76 -0
- package/contracts/interfaces/cctp/ITokenMessenger.sol +72 -0
- package/contracts/interfaces/cctp/ITokenMinter.sol +40 -0
- package/contracts/interfaces/cctp/shared/IOwnable2Step.sol +18 -0
- package/contracts/interfaces/cctp/shared/IPausable.sol +20 -0
- package/contracts/interfaces/token/IERC20.sol +16 -0
- package/contracts/interfaces/token/IERC20Metadata.sol +11 -0
- package/contracts/interfaces/token/IERC20Permit.sol +19 -0
- package/contracts/interfaces/token/IWETH.sol +12 -0
- package/contracts/libraries/BytesParsing.sol +2848 -0
- package/contracts/libraries/CctpMessages.sol +755 -0
- package/contracts/libraries/CoreBridge.sol +365 -0
- package/contracts/libraries/CustomConsistency.sol +60 -0
- package/contracts/libraries/Percentage.sol +99 -0
- package/contracts/libraries/PermitParsing.sol +580 -0
- package/contracts/libraries/QueryResponse.sol +741 -0
- package/contracts/libraries/ReplayProtection.sol +106 -0
- package/contracts/libraries/SafeERC20.sol +67 -0
- package/contracts/libraries/TokenBridgeMessages.sol +742 -0
- package/contracts/libraries/TypedUnits.sol +304 -0
- package/contracts/libraries/UncheckedIndexing.sol +99 -0
- package/contracts/libraries/VaaLib.sol +1385 -0
- package/contracts/proxy/Eip1967Admin.sol +20 -0
- package/contracts/proxy/Eip1967Implementation.sol +15 -0
- package/contracts/proxy/Proxy.sol +43 -0
- package/contracts/proxy/ProxyBase.sol +80 -0
- package/contracts/utils/DecimalNormalization.sol +18 -0
- package/contracts/utils/EagerOps.sol +18 -0
- package/contracts/utils/Keccak.sol +39 -0
- package/contracts/utils/Revert.sol +11 -0
- package/contracts/utils/Transfer.sol +23 -0
- package/contracts/utils/UniversalAddress.sol +17 -0
- package/package.json +23 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.4;
|
|
3
|
+
|
|
4
|
+
//see https://wormhole.com/docs/products/reference/consistency-levels/
|
|
5
|
+
uint8 constant CONSISTENCY_LEVEL_INSTANT = 200;
|
|
6
|
+
uint8 constant CONSISTENCY_LEVEL_SAFE = 201;
|
|
7
|
+
uint8 constant CONSISTENCY_LEVEL_FINALIZED = 1; //alternatively 202 is used
|
|
8
|
+
//see ICustomConsistencyLevel and ConsistencyConfigLib:
|
|
9
|
+
uint8 constant CONSISTENCY_LEVEL_CUSTOM = 203;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
// ╭─────────────────────────────────────────────────────────────╮
|
|
5
|
+
// │ For verification, consider using `CoreBridgeLib` │
|
|
6
|
+
// │ For encoding and decoding, consider using `VaaLib` │
|
|
7
|
+
// │ For replay protection, consider using `ReplayProtectionLib` │
|
|
8
|
+
// ╰─────────────────────────────────────────────────────────────╯
|
|
9
|
+
|
|
10
|
+
//slimmed down interface of the CoreBridge (aka the Wormhole contract)
|
|
11
|
+
|
|
12
|
+
struct GuardianSet {
|
|
13
|
+
address[] keys;
|
|
14
|
+
uint32 expirationTime;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
struct GuardianSignature {
|
|
18
|
+
bytes32 r;
|
|
19
|
+
bytes32 s;
|
|
20
|
+
uint8 v;
|
|
21
|
+
uint8 guardianIndex;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//VM = Verified Message - legacy struct of the CoreBridge
|
|
25
|
+
//contains fields that are not relevant to the integrator:
|
|
26
|
+
// * version - always 1 regardless
|
|
27
|
+
// * signatures/guardianSetIndex - only the CoreBridge itself cares (for verification)
|
|
28
|
+
// * hash - NOT the VAA hash, but the hash of the hash! see warning at the top of VaaLib.sol!
|
|
29
|
+
// _finalized_ VAAs should use the unique (emitterChainId, emitterAddress, sequence) triple
|
|
30
|
+
// for cheaper replay protection, see SequenceReplayProtectionLib
|
|
31
|
+
struct CoreBridgeVM {
|
|
32
|
+
uint8 version;
|
|
33
|
+
uint32 timestamp;
|
|
34
|
+
uint32 nonce;
|
|
35
|
+
uint16 emitterChainId;
|
|
36
|
+
bytes32 emitterAddress;
|
|
37
|
+
uint64 sequence;
|
|
38
|
+
uint8 consistencyLevel;
|
|
39
|
+
bytes payload;
|
|
40
|
+
uint32 guardianSetIndex;
|
|
41
|
+
GuardianSignature[] signatures;
|
|
42
|
+
bytes32 hash; //see comment above
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface ICoreBridge {
|
|
46
|
+
event LogMessagePublished(
|
|
47
|
+
address indexed sender,
|
|
48
|
+
uint64 sequence,
|
|
49
|
+
uint32 nonce,
|
|
50
|
+
bytes payload,
|
|
51
|
+
uint8 consistencyLevel
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
// -- publishing --
|
|
55
|
+
|
|
56
|
+
function messageFee() external view returns (uint256);
|
|
57
|
+
|
|
58
|
+
//Note: This function requires a msg.value equal to the message fee!
|
|
59
|
+
function publishMessage(
|
|
60
|
+
uint32 nonce,
|
|
61
|
+
bytes memory payload,
|
|
62
|
+
uint8 consistencyLevel
|
|
63
|
+
) external payable returns (uint64 sequence);
|
|
64
|
+
|
|
65
|
+
// -- verification --
|
|
66
|
+
|
|
67
|
+
//consider using `VaaLib` and `CoreBridgeLib` instead to save on gas
|
|
68
|
+
// (though at the expense of some code size)
|
|
69
|
+
function parseAndVerifyVM(
|
|
70
|
+
bytes calldata encodedVM
|
|
71
|
+
) external view returns (CoreBridgeVM memory vm, bool valid, string memory reason);
|
|
72
|
+
|
|
73
|
+
// -- getters --
|
|
74
|
+
|
|
75
|
+
function chainId() external view returns (uint16);
|
|
76
|
+
function nextSequence(address emitter) external view returns (uint64);
|
|
77
|
+
|
|
78
|
+
function getGuardianSet(uint32 index) external view returns (GuardianSet memory);
|
|
79
|
+
function getCurrentGuardianSetIndex() external view returns (uint32);
|
|
80
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
//from https://github.com/wormhole-foundation/wormhole/blob/39081fa2936badf178f8b7e5eb63074d3308bf7d/ethereum/contracts/custom_consistency_level/interfaces/ICustomConsistencyLevel.sol
|
|
5
|
+
interface ICustomConsistencyLevel {
|
|
6
|
+
//topic0 0xa37f0112e03d41de27266c1680238ff1548c0441ad1e73c82917c000eefdd5ea
|
|
7
|
+
event ConfigSet(address emitterAddress, bytes32 config);
|
|
8
|
+
|
|
9
|
+
function configure(bytes32 config) external;
|
|
10
|
+
|
|
11
|
+
function getConfiguration(address emitterAddress) external view returns (bytes32);
|
|
12
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
interface IDeliveryProvider {
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @notice This function returns
|
|
8
|
+
*
|
|
9
|
+
* 1) nativePriceQuote: the price of a delivery (by this delivery provider) to chain
|
|
10
|
+
* 'targetChain', giving the user's contract 'receiverValue' target chain wei and performing the
|
|
11
|
+
* relay with the execution parameters (e.g. the gas limit) specified in 'encodedExecutionParameters'
|
|
12
|
+
*
|
|
13
|
+
* 2) encodedExecutionInfo: information relating to how this delivery provider
|
|
14
|
+
* will perform such a delivery (e.g. the gas limit, and the amount it will refund per gas unused)
|
|
15
|
+
*
|
|
16
|
+
* encodedExecutionParameters and encodedExecutionInfo both are encodings of versioned structs -
|
|
17
|
+
* version EVM_V1 of ExecutionParameters specifies the gas limit,
|
|
18
|
+
* and version EVM_V1 of ExecutionInfo specifies the gas limit and the amount that this delivery provider
|
|
19
|
+
* will refund per unit of gas unused
|
|
20
|
+
*/
|
|
21
|
+
function quoteDeliveryPrice(
|
|
22
|
+
uint16 targetChain,
|
|
23
|
+
uint256 receiverValue,
|
|
24
|
+
bytes memory encodedExecutionParams
|
|
25
|
+
) external view returns (uint256 nativePriceQuote, bytes memory encodedExecutionInfo);
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @notice This function returns the amount of extra 'receiverValue' (msg.value on the target chain)
|
|
29
|
+
* that will be sent to your contract, if you specify 'currentChainAmount' in the
|
|
30
|
+
* 'paymentForExtraReceiverValue' field on 'send'
|
|
31
|
+
*/
|
|
32
|
+
function quoteAssetConversion(
|
|
33
|
+
uint16 targetChain,
|
|
34
|
+
uint256 currentChainAmount
|
|
35
|
+
) external view returns (uint256 targetChainAmount);
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @notice This function should return a payable address on this (source) chain where all awards
|
|
39
|
+
* should be sent for the relay provider.
|
|
40
|
+
*/
|
|
41
|
+
function getRewardAddress() external view returns (address payable rewardAddress);
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @notice This function determines whether a relay provider supports deliveries to a given chain
|
|
45
|
+
* or not.
|
|
46
|
+
*
|
|
47
|
+
* @param targetChain - The chain which is being delivered to.
|
|
48
|
+
*/
|
|
49
|
+
function isChainSupported(uint16 targetChain) external view returns (bool supported);
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @notice This function determines whether a relay provider supports the given keyType.
|
|
53
|
+
*
|
|
54
|
+
* Note: 0-127 are reserved for standardized keyTypes and 128-255 are allowed to be custom per DeliveryProvider
|
|
55
|
+
* Practically this means that 0-127 must mean the same thing for all DeliveryProviders,
|
|
56
|
+
* while x within 128-255 may have different meanings between DeliveryProviders
|
|
57
|
+
* (e.g. 130 for provider A means pyth price quotes while 130 for provider B means tweets,
|
|
58
|
+
* but 8 must mean the same for both)
|
|
59
|
+
*
|
|
60
|
+
* @param keyType - The keyType within MessageKey that specifies what the encodedKey within a MessageKey means
|
|
61
|
+
*/
|
|
62
|
+
function isMessageKeyTypeSupported(uint8 keyType) external view returns (bool supported);
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @notice This function returns a bitmap encoding all the keyTypes this provider supports
|
|
66
|
+
*
|
|
67
|
+
* Note: 0-127 are reserved for standardized keyTypes and 128-255 are allowed to be custom per DeliveryProvider
|
|
68
|
+
* Practically this means that 0-127 must mean the same thing for all DeliveryProviders,
|
|
69
|
+
* while x within 128-255 may have different meanings between DeliveryProviders
|
|
70
|
+
* (e.g. 130 for provider A means pyth price quotes while 130 for provider B means tweets,
|
|
71
|
+
* but 8 must mean the same for both)
|
|
72
|
+
*/
|
|
73
|
+
function getSupportedKeys() external view returns (uint256 bitmap);
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @notice If a DeliveryProvider supports a given chain, this function should provide the contract
|
|
77
|
+
* address (in wormhole format) of the relay provider on that chain.
|
|
78
|
+
*
|
|
79
|
+
* @param targetChain - The chain which is being delivered to.
|
|
80
|
+
*/
|
|
81
|
+
function getTargetChainAddress(
|
|
82
|
+
uint16 targetChain
|
|
83
|
+
) external view returns (bytes32 deliveryProviderAddress);
|
|
84
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
//see https://github.com/wormholelabs-xyz/example-messaging-executor/blob/ec5daea3c03f8860a62c23e28db5c6dc8771a9ce/evm/src/interfaces/IExecutor.sol
|
|
5
|
+
|
|
6
|
+
event RequestForExecution(
|
|
7
|
+
address indexed quoterAddress,
|
|
8
|
+
uint256 amtPaid,
|
|
9
|
+
uint16 dstChain,
|
|
10
|
+
bytes32 dstAddr,
|
|
11
|
+
address refundAddr,
|
|
12
|
+
bytes signedQuote,
|
|
13
|
+
bytes requestBytes,
|
|
14
|
+
bytes relayInstructions
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
interface IExecutor {
|
|
18
|
+
function requestExecution(
|
|
19
|
+
uint16 dstChain,
|
|
20
|
+
bytes32 dstAddr,
|
|
21
|
+
address refundAddr,
|
|
22
|
+
bytes calldata signedQuote,
|
|
23
|
+
bytes calldata requestBytes,
|
|
24
|
+
bytes calldata relayInstructions
|
|
25
|
+
) external payable;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//from https://github.com/wormholelabs-xyz/example-messaging-executor/blob/ec5daea3c03f8860a62c23e28db5c6dc8771a9ce/evm/src/interfaces/IVaaV1Receiver.sol
|
|
29
|
+
//required interface for receiving MultiSig (=V1) VAAs from the executor
|
|
30
|
+
interface IVaaV1Receiver {
|
|
31
|
+
function executeVAAv1(bytes memory multiSigVaa) external payable;
|
|
32
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
//slimmed down interface of TokenBridge (only integrator relevant functions)
|
|
5
|
+
|
|
6
|
+
interface ITokenBridge {
|
|
7
|
+
event TransferRedeemed(
|
|
8
|
+
uint16 indexed emitterChainId,
|
|
9
|
+
bytes32 indexed emitterAddress,
|
|
10
|
+
uint64 indexed sequence
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
// -- transfer functions --
|
|
14
|
+
|
|
15
|
+
function wrapAndTransferETH(
|
|
16
|
+
uint16 recipientChain,
|
|
17
|
+
bytes32 recipient,
|
|
18
|
+
uint256 arbiterFee, //no built-in relayer -> unused, always set to 0
|
|
19
|
+
uint32 nonce
|
|
20
|
+
) external payable returns (uint64 sequence);
|
|
21
|
+
|
|
22
|
+
function transferTokens(
|
|
23
|
+
address token,
|
|
24
|
+
uint256 amount,
|
|
25
|
+
uint16 recipientChain,
|
|
26
|
+
bytes32 recipient,
|
|
27
|
+
uint256 arbiterFee, //no built-in relayer -> unused, always set to 0
|
|
28
|
+
uint32 nonce
|
|
29
|
+
) external payable returns (uint64 sequence);
|
|
30
|
+
|
|
31
|
+
function wrapAndTransferETHWithPayload(
|
|
32
|
+
uint16 recipientChain,
|
|
33
|
+
bytes32 recipient,
|
|
34
|
+
uint32 nonce,
|
|
35
|
+
bytes calldata payload
|
|
36
|
+
) external payable returns (uint64 sequence);
|
|
37
|
+
|
|
38
|
+
function transferTokensWithPayload(
|
|
39
|
+
address token,
|
|
40
|
+
uint256 amount,
|
|
41
|
+
uint16 recipientChain,
|
|
42
|
+
bytes32 recipient,
|
|
43
|
+
uint32 nonce,
|
|
44
|
+
bytes calldata payload
|
|
45
|
+
) external payable returns (uint64 sequence);
|
|
46
|
+
|
|
47
|
+
// -- completeTransfer functions --
|
|
48
|
+
|
|
49
|
+
function completeTransfer(bytes calldata encodedVaa) external;
|
|
50
|
+
function completeTransferAndUnwrapETH(bytes calldata encodedVaa) external;
|
|
51
|
+
|
|
52
|
+
//transfers tokens to the recipient (must be msg.sender) and returns the payload of the transfer
|
|
53
|
+
//use libraries/TokenBridgeMessages.sol to decode e.g. emitter chain and fromAddress if required
|
|
54
|
+
function completeTransferWithPayload(bytes calldata encodedVaa) external returns (bytes memory);
|
|
55
|
+
function completeTransferAndUnwrapETHWithPayload(
|
|
56
|
+
bytes calldata encodedVaa
|
|
57
|
+
) external returns (bytes memory);
|
|
58
|
+
|
|
59
|
+
// -- token attestation functions --
|
|
60
|
+
|
|
61
|
+
function attestToken(address token, uint32 nonce) external payable returns (uint64 sequence);
|
|
62
|
+
function createWrapped(bytes calldata encodedVaa) external returns (address token);
|
|
63
|
+
function updateWrapped(bytes calldata encodedVaa) external returns (address token);
|
|
64
|
+
|
|
65
|
+
// -- view functions --
|
|
66
|
+
|
|
67
|
+
//convenience function that wraps the core bridge's chainId()
|
|
68
|
+
function chainId() external view returns (uint16);
|
|
69
|
+
//returns address of the core bridge
|
|
70
|
+
function wormhole() external view returns (address);
|
|
71
|
+
//returns universal address of peer contracts on other chains
|
|
72
|
+
function bridgeContracts(uint16 chainId) external view returns (bytes32);
|
|
73
|
+
//underlying implementation of the beacon
|
|
74
|
+
function tokenImplementation() external view returns (address);
|
|
75
|
+
//returns address of the canonical wrapped native token
|
|
76
|
+
function WETH() external view returns (address);
|
|
77
|
+
|
|
78
|
+
function isTransferCompleted(bytes32 hash) external view returns (bool);
|
|
79
|
+
function isWrappedAsset(address token) external view returns (bool);
|
|
80
|
+
function wrappedAsset(uint16 tokenChainId, bytes32 tokenAddress) external view returns (address);
|
|
81
|
+
}
|