@across-protocol/contracts 5.0.11 → 5.0.12-alpha.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/contracts/external/interfaces/CCTPInterfaces.sol +18 -0
- package/contracts/interfaces/SponsoredCCTPInterface.sol +11 -0
- package/contracts/libraries/SponsoredCCTPQuoteLib.sol +22 -0
- package/contracts/periphery/mintburn/ArbitraryEVMFlowExecutor.sol +38 -15
- package/contracts/periphery/mintburn/sponsored-cctp/SponsoredCCTPDstPeriphery.sol +41 -12
- package/contracts/test/MockCCTP.sol +10 -0
- package/dist/broadcast/deployed-addresses.json +172 -102
- package/dist/evm/artifacts/Arbitrum_Adapter.sol/Arbitrum_Adapter.json +1 -1
- package/dist/evm/artifacts/Arbitrum_CustomGasToken_Adapter.sol/Arbitrum_CustomGasToken_Adapter.json +1 -1
- package/dist/evm/artifacts/Arbitrum_RescueAdapter.sol/Arbitrum_RescueAdapter.json +1 -1
- package/dist/evm/artifacts/Arbitrum_SendTokensAdapter.sol/Arbitrum_SendTokensAdapter.json +1 -1
- package/dist/evm/artifacts/Arbitrum_SpokePool.sol/Arbitrum_SpokePool.json +1 -1
- package/dist/evm/artifacts/Arbitrum_WithdrawalHelper.sol/Arbitrum_WithdrawalHelper.json +1 -1
- package/dist/evm/artifacts/Base_Adapter.sol/Base_Adapter.json +1 -1
- package/dist/evm/artifacts/Blast_Adapter.sol/Blast_Adapter.json +1 -1
- package/dist/evm/artifacts/Blast_SpokePool.sol/Blast_SpokePool.json +1 -1
- package/dist/evm/artifacts/Boba_SpokePool.sol/Boba_SpokePool.json +1 -1
- package/dist/evm/artifacts/CCTPInterfaces.sol/ITokenMessengerV2.json +1 -1
- package/dist/evm/artifacts/CCTPInterfaces.sol/ITokenMinter.json +1 -1
- package/dist/evm/artifacts/Cher_SpokePool.sol/Cher_SpokePool.json +1 -1
- package/dist/evm/artifacts/CircleCCTPAdapter.sol/CircleDomainIds.json +1 -1
- package/dist/evm/artifacts/CounterfactualDepositCCTP.sol/CounterfactualDepositCCTP.json +1 -1
- package/dist/evm/artifacts/DoctorWho_Adapter.sol/DoctorWho_Adapter.json +1 -1
- package/dist/evm/artifacts/DstOFTHandler.sol/DstOFTHandler.json +1 -1
- package/dist/evm/artifacts/Ink_SpokePool.sol/Ink_SpokePool.json +1 -1
- package/dist/evm/artifacts/Lens_SpokePool.sol/Lens_SpokePool.json +1 -1
- package/dist/evm/artifacts/Linea_Adapter.sol/Linea_Adapter.json +1 -1
- package/dist/evm/artifacts/Linea_SpokePool.sol/Linea_SpokePool.json +1 -1
- package/dist/evm/artifacts/Lisk_Adapter.sol/Lisk_Adapter.json +1 -1
- package/dist/evm/artifacts/Lisk_SpokePool.sol/Lisk_SpokePool.json +1 -1
- package/dist/evm/artifacts/MockBedrockStandardBridge.sol/MockBedrockCrossDomainMessenger.json +1 -1
- package/dist/evm/artifacts/MockBedrockStandardBridge.sol/MockBedrockL1StandardBridge.json +1 -1
- package/dist/evm/artifacts/MockBedrockStandardBridge.sol/MockBedrockL2StandardBridge.json +1 -1
- package/dist/evm/artifacts/MockCCTP.sol/MockCCTPMessageTransmitter.json +1 -1
- package/dist/evm/artifacts/MockCCTP.sol/MockCCTPMessenger.json +1 -1
- package/dist/evm/artifacts/MockCCTP.sol/MockCCTPMessengerV2.json +1 -1
- package/dist/evm/artifacts/MockCCTP.sol/MockCCTPMinter.json +1 -1
- package/dist/evm/artifacts/MockOptimism_SpokePool.sol/MockOptimism_SpokePool.json +1 -1
- package/dist/evm/artifacts/Mode_Adapter.sol/Mode_Adapter.json +1 -1
- package/dist/evm/artifacts/OP_Adapter.sol/OP_Adapter.json +1 -1
- package/dist/evm/artifacts/OP_SpokePool.sol/OP_SpokePool.json +1 -1
- package/dist/evm/artifacts/Optimism_Adapter.sol/Optimism_Adapter.json +1 -1
- package/dist/evm/artifacts/Optimism_SpokePool.sol/Optimism_SpokePool.json +1 -1
- package/dist/evm/artifacts/Ovm_SpokePool.sol/Ovm_SpokePool.json +1 -1
- package/dist/evm/artifacts/Ovm_WithdrawalHelper.sol/Ovm_WithdrawalHelper.json +1 -1
- package/dist/evm/artifacts/Polygon_Adapter.sol/Polygon_Adapter.json +1 -1
- package/dist/evm/artifacts/Polygon_SpokePool.sol/Polygon_SpokePool.json +1 -1
- package/dist/evm/artifacts/Solana_Adapter.sol/Solana_Adapter.json +1 -1
- package/dist/evm/artifacts/SponsoredCCTPDstPeriphery.sol/SponsoredCCTPDstPeriphery.json +1 -1
- package/dist/evm/artifacts/SponsoredCCTPInterface.sol/SponsoredCCTPInterface.json +1 -1
- package/dist/evm/artifacts/SponsoredCCTPSrcPeriphery.sol/SponsoredCCTPSrcPeriphery.json +1 -1
- package/dist/evm/artifacts/SponsoredOFTSrcPeriphery.sol/SponsoredOFTSrcPeriphery.json +1 -1
- package/dist/evm/artifacts/Tron_SpokePool.sol/Tron_SpokePool.json +1 -1
- package/dist/evm/artifacts/Universal_Adapter.sol/Universal_Adapter.json +1 -1
- package/dist/evm/artifacts/Universal_SpokePool.sol/Universal_SpokePool.json +1 -1
- package/dist/evm/artifacts/WorldChain_SpokePool.sol/WorldChain_SpokePool.json +1 -1
- package/dist/evm/artifacts/ZkStack_Adapter.sol/ZkStack_Adapter.json +1 -1
- package/dist/evm/artifacts/ZkStack_CustomGasToken_Adapter.sol/ZkStack_CustomGasToken_Adapter.json +1 -1
- package/dist/evm/artifacts/ZkSync_SpokePool.sol/ZkSync_SpokePool.json +1 -1
- package/dist/evm/artifacts/Zora_Adapter.sol/Zora_Adapter.json +1 -1
- package/dist/evm/artifacts/eraVM_EIP7702.sol/SimpleContract.json +1 -1
- package/dist/evm/artifacts/eraVM_EIP7702.sol/SpokePoolEIP7702Test.json +1 -1
- package/dist/evm/artifacts/eraVM_EIP7702.sol/TestableMockSpokePool.json +1 -1
- package/package.json +1 -1
|
@@ -58,6 +58,14 @@ interface ITokenMessenger {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
interface ITokenMessengerV2 {
|
|
61
|
+
/**
|
|
62
|
+
* @notice Minter responsible for minting and burning tokens on the local domain.
|
|
63
|
+
* Used on destination to prove that a received message would mint via the expected
|
|
64
|
+
* TokenMinter, and to resolve the local token that corresponds to a remote burnToken.
|
|
65
|
+
* https://github.com/circlefin/evm-cctp-contracts/blob/63ab1f0ac06ce0793c0bbfbb8d09816bc211386d/src/v2/TokenMessengerV2.sol
|
|
66
|
+
*/
|
|
67
|
+
function localMinter() external view returns (ITokenMinter minter);
|
|
68
|
+
|
|
61
69
|
// Source: https://github.com/circlefin/evm-cctp-contracts/blob/63ab1f0ac06ce0793c0bbfbb8d09816bc211386d/src/v2/TokenMessengerV2.sol#L138C1-L166C15
|
|
62
70
|
/**
|
|
63
71
|
* @notice Deposits and burns tokens from sender to be minted on destination domain.
|
|
@@ -139,6 +147,16 @@ interface ITokenMinter {
|
|
|
139
147
|
* @return burnLimit maximum burn amount per message for token
|
|
140
148
|
*/
|
|
141
149
|
function burnLimitsPerMessage(address token) external view returns (uint256);
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* @notice Returns the local token that is associated with the given remote burnToken on `remoteDomain`.
|
|
153
|
+
* Returns address(0) when no link has been configured.
|
|
154
|
+
* https://github.com/circlefin/evm-cctp-contracts/blob/63ab1f0ac06ce0793c0bbfbb8d09816bc211386d/src/TokenMinter.sol#L155
|
|
155
|
+
* @param remoteDomain CCTP source domain
|
|
156
|
+
* @param remoteToken burnToken (as bytes32) on the remote domain
|
|
157
|
+
* @return localToken the locally-minted token, or address(0) if the pair is not linked
|
|
158
|
+
*/
|
|
159
|
+
function getLocalToken(uint32 remoteDomain, bytes32 remoteToken) external view returns (address localToken);
|
|
142
160
|
}
|
|
143
161
|
|
|
144
162
|
/**
|
|
@@ -24,6 +24,17 @@ interface SponsoredCCTPInterface is SponsoredExecutionModeInterface {
|
|
|
24
24
|
// Error thrown when the CCTP message transmitter receive message fails.
|
|
25
25
|
error CCTPMessageTransmitterFailed();
|
|
26
26
|
|
|
27
|
+
// Error thrown when the amount actually minted into this contract by the CCTP call does not match
|
|
28
|
+
// the `amount - feeExecuted` encoded in the message.
|
|
29
|
+
error InvalidMintedAmount();
|
|
30
|
+
|
|
31
|
+
// Error thrown when the CCTP message's top-level `recipient` is not the configured TokenMessenger.
|
|
32
|
+
error InvalidRecipient();
|
|
33
|
+
|
|
34
|
+
// Error thrown when the TokenMinter does not link the message's remote burnToken to this periphery's
|
|
35
|
+
// `baseToken` on the local domain.
|
|
36
|
+
error InvalidMintedToken();
|
|
37
|
+
|
|
27
38
|
// Error thrown when direct flow destination handler is not a contract.
|
|
28
39
|
error InvalidDirectHandler();
|
|
29
40
|
|
|
@@ -89,6 +89,28 @@ library SponsoredCCTPQuoteLib {
|
|
|
89
89
|
);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
+
/**
|
|
93
|
+
* @notice Reads the top-level CCTP message `recipient` (i.e. the contract MessageTransmitter delivers to,
|
|
94
|
+
* typically the TokenMessenger that performs the mint). Assumes `message` has passed length validation.
|
|
95
|
+
*/
|
|
96
|
+
function extractRecipient(bytes memory message) internal pure returns (bytes32) {
|
|
97
|
+
return message.toBytes32(RECIPIENT_INDEX);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* @notice Reads the CCTP source domain from the message header. Assumes `message` has passed length validation.
|
|
102
|
+
*/
|
|
103
|
+
function extractSourceDomain(bytes memory message) internal pure returns (uint32) {
|
|
104
|
+
return message.toUint32(SOURCE_DOMAIN_INDEX);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @notice Reads the burnToken (as bytes32) from the burn message body. Assumes `message` has passed length validation.
|
|
109
|
+
*/
|
|
110
|
+
function extractBurnToken(bytes memory message) internal pure returns (bytes32) {
|
|
111
|
+
return message.toBytes32(MESSAGE_BODY_INDEX + BURN_TOKEN_INDEX);
|
|
112
|
+
}
|
|
113
|
+
|
|
92
114
|
/**
|
|
93
115
|
* @notice Validates the message that is received from CCTP. If this checks fails, then the quote on source chain was invalid
|
|
94
116
|
* and we are unable to retrieve user's address to send the funds to. In that case the funds will stay in this contract.
|
|
@@ -60,9 +60,17 @@ abstract contract ArbitraryEVMFlowExecutor {
|
|
|
60
60
|
// Decode the compressed action data
|
|
61
61
|
CompressedCall[] memory compressedCalls = abi.decode(params.actionData, (CompressedCall[]));
|
|
62
62
|
|
|
63
|
-
//
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
// Sweep any pre-existing dust on MulticallHandler so it cannot pollute our balance snapshots
|
|
64
|
+
_drainMulticallHandlerDust(params.initialToken);
|
|
65
|
+
if (params.commonParams.finalToken != params.initialToken) {
|
|
66
|
+
_drainMulticallHandlerDust(params.commonParams.finalToken);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
bool differentTokens = params.initialToken != params.commonParams.finalToken;
|
|
70
|
+
|
|
71
|
+
// Read "starting balance initial token"(sBI) and "starting balance final token"(sBF)
|
|
72
|
+
uint256 sBI = IERC20(params.initialToken).balanceOf(address(this));
|
|
73
|
+
uint256 sBF = differentTokens ? IERC20(params.commonParams.finalToken).balanceOf(address(this)) : sBI;
|
|
66
74
|
|
|
67
75
|
// Transfer tokens to MulticallHandler
|
|
68
76
|
IERC20(params.initialToken).safeTransfer(multicallHandler, params.commonParams.amountInEVM);
|
|
@@ -82,19 +90,21 @@ abstract contract ArbitraryEVMFlowExecutor {
|
|
|
82
90
|
instructions
|
|
83
91
|
);
|
|
84
92
|
|
|
85
|
-
|
|
86
|
-
//
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
uint256
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
// Default to initial-token accounting; overwrite below if finalToken was actually produced.
|
|
94
|
+
// Ending balance initial token
|
|
95
|
+
uint256 eBI = IERC20(params.initialToken).balanceOf(address(this));
|
|
96
|
+
uint256 finalAmount = params.commonParams.amountInEVM + eBI - sBI;
|
|
97
|
+
if (differentTokens) {
|
|
98
|
+
// Ending balance final token
|
|
99
|
+
uint256 eBF = IERC20(params.commonParams.finalToken).balanceOf(address(this));
|
|
100
|
+
|
|
101
|
+
// Any positive finalToken delta is treated as successful execution when initialToken != finalToken. If any
|
|
102
|
+
// (or all) of the initialToken amount is unspent during the execution, it lands back into this contract and
|
|
103
|
+
// can be withdrawn by the admin
|
|
104
|
+
if (eBF > sBF) {
|
|
105
|
+
finalAmount = eBF - sBF;
|
|
95
106
|
} else {
|
|
96
|
-
|
|
97
|
-
finalAmount = 0;
|
|
107
|
+
params.commonParams.finalToken = params.initialToken;
|
|
98
108
|
}
|
|
99
109
|
}
|
|
100
110
|
|
|
@@ -155,6 +165,19 @@ abstract contract ArbitraryEVMFlowExecutor {
|
|
|
155
165
|
return abi.encode(instructions);
|
|
156
166
|
}
|
|
157
167
|
|
|
168
|
+
/// @notice Drains any pre-existing balance of token from MulticallHandler
|
|
169
|
+
function _drainMulticallHandlerDust(address token) internal {
|
|
170
|
+
if (IERC20(token).balanceOf(multicallHandler) == 0) return;
|
|
171
|
+
|
|
172
|
+
// Empty instructions with `fallbackRecipient` set. Causes MulticallHandler to call `_drainRemainingTokens`, which
|
|
173
|
+
// does a safeTransfer of `token` to `fallbackRecipient`, this contract, essentially removing dust
|
|
174
|
+
bytes memory instructions = abi.encode(
|
|
175
|
+
MulticallHandler.Instructions({ calls: new MulticallHandler.Call[](0), fallbackRecipient: address(this) })
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
MulticallHandler(payable(multicallHandler)).handleV3AcrossMessage(token, 0, address(this), instructions);
|
|
179
|
+
}
|
|
180
|
+
|
|
158
181
|
/// @notice Calculates proportional fees to sponsor in finalToken, given the fees to sponsor in initial token and initial amount
|
|
159
182
|
function _calcExtraFeesFinal(
|
|
160
183
|
uint256 amount,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
pragma solidity ^0.8.0;
|
|
3
3
|
|
|
4
4
|
import { BaseModuleHandler } from "../BaseModuleHandler.sol";
|
|
5
|
-
import { IMessageTransmitterV2 } from "../../../external/interfaces/CCTPInterfaces.sol";
|
|
5
|
+
import { IMessageTransmitterV2, ITokenMessengerV2 } from "../../../external/interfaces/CCTPInterfaces.sol";
|
|
6
6
|
import { SponsoredCCTPQuoteLib } from "../../../libraries/SponsoredCCTPQuoteLib.sol";
|
|
7
7
|
import { SponsoredCCTPInterface } from "../../../interfaces/SponsoredCCTPInterface.sol";
|
|
8
8
|
import { Bytes32ToAddress } from "../../../libraries/AddressConverters.sol";
|
|
@@ -27,6 +27,10 @@ contract SponsoredCCTPDstPeriphery is BaseModuleHandler, SponsoredCCTPInterface,
|
|
|
27
27
|
/// @notice The CCTP message transmitter contract.
|
|
28
28
|
IMessageTransmitterV2 public immutable cctpMessageTransmitter;
|
|
29
29
|
|
|
30
|
+
/// @notice The CCTP token messenger contract that is the expected top-level recipient of MessageTransmitter
|
|
31
|
+
/// deliveries and owns the TokenMinter used to resolve burnToken -> local token for non-direct-deposit flows.
|
|
32
|
+
ITokenMessengerV2 public immutable cctpTokenMessenger;
|
|
33
|
+
|
|
30
34
|
/// @notice Base token associated with this handler. The one we receive from the CCTP bridge
|
|
31
35
|
address public immutable baseToken;
|
|
32
36
|
|
|
@@ -52,6 +56,8 @@ contract SponsoredCCTPDstPeriphery is BaseModuleHandler, SponsoredCCTPInterface,
|
|
|
52
56
|
/**
|
|
53
57
|
* @notice Constructor for the SponsoredCCTPDstPeriphery contract.
|
|
54
58
|
* @param _cctpMessageTransmitter The address of the CCTP message transmitter contract.
|
|
59
|
+
* @param _cctpTokenMessenger The address of the CCTP token messenger contract. Used to pin that a received
|
|
60
|
+
* message actually routed through the real mint flow and that the remote burnToken links to `baseToken`.
|
|
55
61
|
* @param _signer The address of the signer that was used to sign the quotes.
|
|
56
62
|
* @param _donationBox The address of the donation box contract. This is used to store funds that are used for sponsored flows.
|
|
57
63
|
* @param _baseToken The address of the base token which would be the USDC on HyperEVM.
|
|
@@ -59,6 +65,7 @@ contract SponsoredCCTPDstPeriphery is BaseModuleHandler, SponsoredCCTPInterface,
|
|
|
59
65
|
*/
|
|
60
66
|
constructor(
|
|
61
67
|
address _cctpMessageTransmitter,
|
|
68
|
+
address _cctpTokenMessenger,
|
|
62
69
|
address _signer,
|
|
63
70
|
address _donationBox,
|
|
64
71
|
address _baseToken,
|
|
@@ -67,6 +74,7 @@ contract SponsoredCCTPDstPeriphery is BaseModuleHandler, SponsoredCCTPInterface,
|
|
|
67
74
|
baseToken = _baseToken;
|
|
68
75
|
|
|
69
76
|
cctpMessageTransmitter = IMessageTransmitterV2(_cctpMessageTransmitter);
|
|
77
|
+
cctpTokenMessenger = ITokenMessengerV2(_cctpTokenMessenger);
|
|
70
78
|
|
|
71
79
|
MainStorage storage $ = _getMainStorage();
|
|
72
80
|
$.signer = _signer;
|
|
@@ -127,10 +135,15 @@ contract SponsoredCCTPDstPeriphery is BaseModuleHandler, SponsoredCCTPInterface,
|
|
|
127
135
|
bytes memory message,
|
|
128
136
|
bytes memory attestation
|
|
129
137
|
) external nonReentrant onlyRole(PERMISSIONED_BOT_ROLE) {
|
|
138
|
+
uint256 baseBalBefore = IERC20Metadata(baseToken).balanceOf(address(this));
|
|
130
139
|
bool success = cctpMessageTransmitter.receiveMessage(message, attestation);
|
|
131
140
|
if (!success) {
|
|
132
141
|
return;
|
|
133
142
|
}
|
|
143
|
+
// Forward only what the CCTP call actually credited to this contract, so a message that mints nothing
|
|
144
|
+
// (wrong recipient, unlinked burnToken, etc.) cannot drain this contract's prior `baseToken` balance.
|
|
145
|
+
uint256 baseBalAfter = IERC20Metadata(baseToken).balanceOf(address(this));
|
|
146
|
+
uint256 mintedAmount = baseBalAfter - baseBalBefore;
|
|
134
147
|
|
|
135
148
|
// Use try-catch to handle potential abi.decode reverts gracefully
|
|
136
149
|
try this.validateMessage(message) returns (bool isValid) {
|
|
@@ -141,19 +154,14 @@ contract SponsoredCCTPDstPeriphery is BaseModuleHandler, SponsoredCCTPInterface,
|
|
|
141
154
|
// Malformed message that causes abi.decode to revert then early return
|
|
142
155
|
return;
|
|
143
156
|
}
|
|
144
|
-
(SponsoredCCTPInterface.SponsoredCCTPQuote memory quote,
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
_getMainStorage().usedNonces[quote.nonce] = true;
|
|
157
|
+
(SponsoredCCTPInterface.SponsoredCCTPQuote memory quote, ) = SponsoredCCTPQuoteLib.getSponsoredCCTPQuoteData(
|
|
158
|
+
message
|
|
159
|
+
);
|
|
148
160
|
|
|
149
|
-
|
|
161
|
+
address finalRecipient = quote.finalRecipient.toAddress();
|
|
162
|
+
IERC20Metadata(baseToken).safeTransfer(finalRecipient, mintedAmount);
|
|
150
163
|
|
|
151
|
-
emit EmergencyReceiveMessage(
|
|
152
|
-
quote.nonce,
|
|
153
|
-
quote.finalRecipient.toAddress(),
|
|
154
|
-
baseToken,
|
|
155
|
-
quote.amount - feeExecuted
|
|
156
|
-
);
|
|
164
|
+
emit EmergencyReceiveMessage(quote.nonce, finalRecipient, baseToken, mintedAmount);
|
|
157
165
|
}
|
|
158
166
|
|
|
159
167
|
/**
|
|
@@ -168,6 +176,20 @@ contract SponsoredCCTPDstPeriphery is BaseModuleHandler, SponsoredCCTPInterface,
|
|
|
168
176
|
bytes memory attestation,
|
|
169
177
|
bytes memory signature
|
|
170
178
|
) external nonReentrant authorizeFundedFlow {
|
|
179
|
+
// Check that the CCTP message was actually routed through our TokenMessenger (which owns the mint flow),
|
|
180
|
+
// and that its TokenMinter links the remote burnToken to our `baseToken` on this domain.
|
|
181
|
+
if (SponsoredCCTPQuoteLib.extractRecipient(message).toAddressUnchecked() != address(cctpTokenMessenger)) {
|
|
182
|
+
revert InvalidRecipient();
|
|
183
|
+
}
|
|
184
|
+
address localToken = cctpTokenMessenger.localMinter().getLocalToken(
|
|
185
|
+
SponsoredCCTPQuoteLib.extractSourceDomain(message),
|
|
186
|
+
SponsoredCCTPQuoteLib.extractBurnToken(message)
|
|
187
|
+
);
|
|
188
|
+
if (localToken != baseToken) {
|
|
189
|
+
revert InvalidMintedToken();
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
uint256 baseBalBefore = IERC20Metadata(baseToken).balanceOf(address(this));
|
|
171
193
|
bool success = cctpMessageTransmitter.receiveMessage(message, attestation);
|
|
172
194
|
if (!success) {
|
|
173
195
|
revert CCTPMessageTransmitterFailed();
|
|
@@ -188,6 +210,13 @@ contract SponsoredCCTPDstPeriphery is BaseModuleHandler, SponsoredCCTPInterface,
|
|
|
188
210
|
(SponsoredCCTPInterface.SponsoredCCTPQuote memory quote, uint256 feeExecuted) = SponsoredCCTPQuoteLib
|
|
189
211
|
.getSponsoredCCTPQuoteData(message);
|
|
190
212
|
|
|
213
|
+
// Confirm the CCTP call actually minted `baseToken` to this contract.
|
|
214
|
+
uint256 baseBalAfter = IERC20Metadata(baseToken).balanceOf(address(this));
|
|
215
|
+
uint256 amountAfterFees = quote.amount - feeExecuted;
|
|
216
|
+
if (baseBalAfter - baseBalBefore != amountAfterFees) {
|
|
217
|
+
revert InvalidMintedAmount();
|
|
218
|
+
}
|
|
219
|
+
|
|
191
220
|
// Validate the quote and the signature. Revert on invalid to prevent griefing attacks
|
|
192
221
|
// where an attacker provides correct message/attestation but invalid signature.
|
|
193
222
|
_validateQuoteOrRevert(quote, signature);
|
|
@@ -6,14 +6,24 @@ import { IMessageTransmitter } from "../external/interfaces/CCTPInterfaces.sol";
|
|
|
6
6
|
|
|
7
7
|
contract MockCCTPMinter is ITokenMinter {
|
|
8
8
|
uint256 private _burnLimit = type(uint256).max;
|
|
9
|
+
// remoteDomain => remoteToken => localToken
|
|
10
|
+
mapping(uint32 => mapping(bytes32 => address)) private _localTokens;
|
|
9
11
|
|
|
10
12
|
function setBurnLimit(uint256 limit) external {
|
|
11
13
|
_burnLimit = limit;
|
|
12
14
|
}
|
|
13
15
|
|
|
16
|
+
function setLocalToken(uint32 remoteDomain, bytes32 remoteToken, address localToken) external {
|
|
17
|
+
_localTokens[remoteDomain][remoteToken] = localToken;
|
|
18
|
+
}
|
|
19
|
+
|
|
14
20
|
function burnLimitsPerMessage(address) external view returns (uint256) {
|
|
15
21
|
return _burnLimit;
|
|
16
22
|
}
|
|
23
|
+
|
|
24
|
+
function getLocalToken(uint32 remoteDomain, bytes32 remoteToken) external view returns (address) {
|
|
25
|
+
return _localTokens[remoteDomain][remoteToken];
|
|
26
|
+
}
|
|
17
27
|
}
|
|
18
28
|
|
|
19
29
|
contract MockCCTPMessenger is ITokenMessenger {
|