Проверенный контрактТочноеMIT
CurveAdderProxy
Адрес0xc207c97e11d561d5951561de52c15bbbd2515879
- Баланс
0 ETH
- Транзакций
2
- Компилятор
solc 0.8.28
- Тот же код
Только этот контракт
Подробности
- Компилятор
- solc 0.8.28+commit.7893614a
- Язык
- solidity
- Оптимизация
- Да, 200 прогонов
- Через IR
- да
- Лицензия
- MIT
- Совпадение
- Точноекод создания: да, код в сети: да
- Проверен на Sourcify
- Создан в блоке
- 26 379 315
- Транзакция создания
- 0x4ad767e126…60e48f59a6
- Реализация прокси
- 0x59a14e61…51fe948aисходник не проверен
<stdin>
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
// CurveAdderV1 + CurveAdderProxy — YOUR OWN upgradeable bonding-curve liquidity
// adder. It is the same one-sided band mechanic as curve_add_liq.py, but the
// logic lives behind an EIP-1967 proxy so you can fix/extend it without moving
// liquidity (positions live in the Uniswap v4 PoolManager, not in this storage).
//
// Why the proxy matters here: the pools it seeds are the *tracked* Uniswap v4
// pools, which is what CMC / GeckoTerminal index. A self-made pool contract
// would never appear there (their DEX catalog is fixed), so the adder keeps
// custody/upgradeability in your hands while liquidity lands in an indexed pool.
//
// Upgrade path: admin calls upgradeTo(newImpl). New implementation MUST keep the
// storage layout: slot0 admin, slot1 seeded mapping, then new vars only.
interface IERC20 {
function transfer(address to, uint256 amount) external returns (bool);
function transferFrom(address from, address to, uint256 amount) external returns (bool);
function balanceOf(address owner) external view returns (uint256);
}
interface IPoolManager {
struct PoolKey {
address currency0;
address currency1;
uint24 fee;
int24 tickSpacing;
address hooks;
}
struct ModifyLiquidityParams {
int24 tickLower;
int24 tickUpper;
int256 liquidityDelta;
bytes32 salt;
}
function initialize(PoolKey calldata key, uint160 sqrtPriceX96) external returns (int24);
function unlock(bytes calldata data) external returns (bytes memory);
function modifyLiquidity(
PoolKey calldata key,
ModifyLiquidityParams calldata params,
bytes calldata hookData
) external returns (int256 callerDelta, int256 feesAccrued);
function sync(address currency) external;
function settle() external returns (uint256);
function take(address currency, address to, uint256 amount) external;
}
/// implementation — constructor-free storage, initialized through the proxy
contract CurveAdderV1 {
address public constant PM = 0x000000000004444c5dc75cB358380D2e3dE08A90;
bytes32 internal constant IMPL_SLOT =
0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
address public admin; // slot 0
mapping(bytes32 => mapping(address => uint256)) public seeded; // slot 1
event Seeded(
bytes32 indexed poolId,
address indexed token,
address indexed depositor,
int24 tickLower,
int24 tickUpper,
uint128 liquidity,
uint256 tokenSpent
);
event Withdrawn(bytes32 indexed poolId, address indexed depositor, uint128 liquidity);
event Upgraded(address indexed implementation);
error AlreadyInitialized();
error OnlyAdmin();
error HooksNotSupported();
error NotOneSided();
error WrongCurrency();
error NothingPulled();
error UnknownDeposit();
function initialize(address admin_) external {
if (admin != address(0)) revert AlreadyInitialized();
admin = admin_;
}
modifier onlyAdmin() {
if (msg.sender != admin) revert OnlyAdmin();
_;
}
function upgradeTo(address newImpl) external onlyAdmin {
require(newImpl.code.length > 0, "impl");
assembly {
sstore(IMPL_SLOT, newImpl)
}
emit Upgraded(newImpl);
}
function version() external pure returns (string memory) {
return "1.0.0";
}
function poolId(IPoolManager.PoolKey memory key) public pure returns (bytes32) {
return keccak256(abi.encode(key.currency0, key.currency1, key.fee, key.tickSpacing, key.hooks));
}
/// @notice seed a one-sided band; `token` is the currency that funds it
function seed(
IPoolManager.PoolKey calldata key,
address token,
int24 tickLower,
int24 tickUpper,
uint128 liquidity,
uint160 initSqrtP
) external returns (uint256 tokenSpent) {
if (key.hooks != address(0)) revert HooksNotSupported();
require(token == key.currency0 || token == key.currency1, "token not in key");
require(tickLower < tickUpper, "band");
require(liquidity > 0, "liquidity");
if (initSqrtP != 0) {
IPoolManager(PM).initialize(key, initSqrtP);
}
bytes memory ret = IPoolManager(PM).unlock(
abi.encode(msg.sender, key, token, tickLower, tickUpper, liquidity, false)
);
tokenSpent = abi.decode(ret, (uint256));
if (tokenSpent == 0) revert NothingPulled();
bytes32 pid = poolId(key);
seeded[pid][msg.sender] += liquidity;
emit Seeded(pid, token, msg.sender, tickLower, tickUpper, liquidity, tokenSpent);
}
function withdraw(
IPoolManager.PoolKey calldata key,
int24 tickLower,
int24 tickUpper,
uint128 liquidity
) external {
bytes32 pid = poolId(key);
if (seeded[pid][msg.sender] < liquidity) revert UnknownDeposit();
seeded[pid][msg.sender] -= liquidity;
IPoolManager(PM).unlock(
abi.encode(msg.sender, key, key.currency0, tickLower, tickUpper, liquidity, true)
);
emit Withdrawn(pid, msg.sender, liquidity);
}
function unlockCallback(bytes calldata data) external returns (bytes memory) {
require(msg.sender == PM, "only PM");
(
address depositor,
IPoolManager.PoolKey memory key,
address token,
int24 tickLower,
int24 tickUpper,
uint128 liquidity,
bool removing
) = abi.decode(data, (address, IPoolManager.PoolKey, address, int24, int24, uint128, bool));
(int256 callerDelta, ) = IPoolManager(PM).modifyLiquidity(
key,
IPoolManager.ModifyLiquidityParams({
tickLower: tickLower,
tickUpper: tickUpper,
liquidityDelta: removing ? -int256(uint256(liquidity)) : int256(uint256(liquidity)),
salt: bytes32(0)
}),
""
);
int128 d0 = int128(uint128(uint256(callerDelta >> 128)));
int128 d1 = int128(uint128(uint256(callerDelta)));
if (removing) {
if (d0 > 0) IPoolManager(PM).take(key.currency0, depositor, uint256(uint128(d0)));
if (d1 > 0) IPoolManager(PM).take(key.currency1, depositor, uint256(uint128(d1)));
return abi.encode(uint256(0));
}
if (d0 < 0 && d1 < 0) revert NotOneSided();
uint256 spent;
if (d0 < 0) {
if (key.currency0 != token) revert WrongCurrency();
spent = uint256(uint128(-d0));
_pay(key.currency0, depositor, uint128(-d0));
}
if (d1 < 0) {
if (key.currency1 != token) revert WrongCurrency();
spent = uint256(uint128(-d1));
_pay(key.currency1, depositor, uint128(-d1));
}
if (d0 > 0) IPoolManager(PM).take(key.currency0, depositor, uint256(uint128(d0)));
if (d1 > 0) IPoolManager(PM).take(key.currency1, depositor, uint256(uint128(d1)));
return abi.encode(spent);
}
function _pay(address currency, address from, uint128 amount) private {
IPoolManager pm = IPoolManager(PM);
pm.sync(currency);
require(IERC20(currency).transferFrom(from, address(pm), uint256(amount)), "pay fail");
pm.settle();
}
receive() external payable {}
}
/// EIP-1967 proxy: implementation address lives in the standard slot
contract CurveAdderProxy {
bytes32 internal constant IMPL_SLOT =
0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
constructor(address impl, bytes memory data) {
require(impl.code.length > 0, "impl");
assembly {
sstore(IMPL_SLOT, impl)
}
if (data.length > 0) {
(bool ok, bytes memory ret) = impl.delegatecall(data);
if (!ok) {
assembly {
revert(add(ret, 32), mload(ret))
}
}
}
}
function implementation() external view returns (address impl) {
assembly {
impl := sload(IMPL_SLOT)
}
}
fallback() external payable {
_delegate();
}
receive() external payable {
_delegate();
}
function _delegate() private {
assembly {
let ptr := mload(0x40)
calldatacopy(ptr, 0, calldatasize())
let impl := sload(IMPL_SLOT)
let ok := delegatecall(gas(), impl, ptr, calldatasize(), 0, 0)
returndatacopy(ptr, 0, returndatasize())
if iszero(ok) {
revert(ptr, returndatasize())
}
return(ptr, returndatasize())
}
}
}
Настройки компилятораПоказать
{
"viaIR": true,
"optimizer": {
"runs": 200,
"enabled": true
}
}Исходный код и метаданные: Sourcify.
Исходный код принадлежит авторам контракта.