-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathCallbackLib.sol
44 lines (40 loc) · 2.02 KB
/
CallbackLib.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.24;
// Interfaces
import {IUniswapV3Factory} from "univ3-core/interfaces/IUniswapV3Factory.sol";
// Libraries
import {Errors} from "@libraries/Errors.sol";
/// @title Library for verifying and decoding Uniswap callbacks.
/// @author Axicon Labs Limited
/// @notice This library provides functions to verify that a callback came from a canonical Uniswap V3 pool with a claimed set of features.
library CallbackLib {
/// @notice Type defining characteristics of a Uniswap V3 pool.
/// @param token0 The address of `token0` for the Uniswap pool
/// @param token1 The address of `token1` for the Uniswap pool
/// @param fee The fee tier of the Uniswap pool (in hundredths of basis points)
struct PoolFeatures {
address token0;
address token1;
uint24 fee;
}
/// @notice Type for data sent by pool in mint/swap callbacks used to validate the pool and send back requisite tokens.
/// @param poolFeatures The features of the pool that sent the callback (used to validate that the pool is canonical)
/// @param payer The address from which the requested tokens should be transferred
struct CallbackData {
PoolFeatures poolFeatures;
address payer;
}
/// @notice Verifies that a callback came from the canonical Uniswap pool with a claimed set of features.
/// @param sender The address initiating the callback and claiming to be a Uniswap pool
/// @param factory The address of the canonical Uniswap V3 factory
/// @param features The features `sender` claims to contain (tokens and fee)
function validateCallback(
address sender,
IUniswapV3Factory factory,
PoolFeatures memory features
) internal view {
// Call getPool on the factory to verify that the sender corresponds to the canonical pool with the claimed features
if (factory.getPool(features.token0, features.token1, features.fee) != sender)
revert Errors.InvalidUniswapCallback();
}
}