Blockchain / Global / Address
Contract
0xF29Ba4Ef6B755a7C65396be2fDF5ADF51536F755
- Balance
- 0 SOMI
- Transactions sent
- 1
- Type
- Contract · 2,554 bytes of code
SomiverseSwapRouter Verified
- Compiler
- solc 0.8.24+commit.e11b9ed9
- Language
- Solidity
- Optimization
- Yes, 200 runs
- EVM version
- paris
- License
- —
- Verified
- 2026-10-12
contracts/SomiverseSwapRouter.sol
Solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/**
* @title SomiverseSwapRouter
* @notice Proxy contract that collects platform fee and forwards the
* remaining amount to the QuickSwap Algebra V4 SwapRouter.
*
* Deployment args:
* _router – QuickSwap Algebra V4 SwapRouter address
* _wsomi – WSOMI (WETH9) contract address
* _treasury – wallet that receives the platform fee
*/
interface IAlgebraSwapRouter {
struct ExactInputSingleParams {
address tokenIn;
address tokenOut;
address deployer;
address recipient;
uint256 deadline;
uint256 amountIn;
uint256 amountOutMinimum;
uint160 limitSqrtPrice;
}
function exactInputSingle(
ExactInputSingleParams calldata params
) external payable returns (uint256 amountOut);
}
interface IERC20 {
function transferFrom(address, address, uint256) external returns (bool);
function transfer(address, uint256) external returns (bool);
function approve(address, uint256) external returns (bool);
}
interface IWETH {
function withdraw(uint256) external;
}
contract SomiverseSwapRouter {
address public immutable router;
address public immutable wsomi;
address public immutable treasury;
uint256 public constant FEE_BPS = 250; // 2.5 %
uint256 public constant BPS_DENOMINATOR = 10_000;
constructor(address _router, address _wsomi, address _treasury) {
router = _router;
wsomi = _wsomi;
treasury = _treasury;
}
/* ───────────────────────── Native SOMI → ERC-20 ───────────────────────── */
/// @notice Swap native SOMI for an ERC-20 token.
function swapNativeToToken(
address tokenOut,
address deployer,
uint256 deadline,
uint256 amountOutMin,
uint160 limitSqrtPrice
) external payable returns (uint256 amountOut) {
uint256 fee = (msg.value * FEE_BPS) / BPS_DENOMINATOR;
uint256 swapAmt = msg.value - fee;
// Fee → treasury
(bool ok, ) = treasury.call{value: fee}("");
require(ok, "fee transfer failed");
// Swap (router wraps native SOMI automatically)
amountOut = IAlgebraSwapRouter(router).exactInputSingle{value: swapAmt}(
IAlgebraSwapRouter.ExactInputSingleParams({
tokenIn: wsomi,
tokenOut: tokenOut,
deployer: deployer,
recipient: msg.sender,
deadline: deadline,
amountIn: swapAmt,
amountOutMinimum: amountOutMin,
limitSqrtPrice: limitSqrtPrice
})
);
}
/* ──────────────── ERC-20 → ERC-20 / ERC-20 → native SOMI ──────────── */
/// @notice Swap an ERC-20 for another ERC-20 (or native SOMI when
/// unwrapToNative is true). Caller must approve this contract for
/// amountIn beforehand.
function swapTokenToToken(
address tokenIn,
address tokenOut,
address deployer,
uint256 deadline,
uint256 amountIn,
uint256 amountOutMin,
uint160 limitSqrtPrice,
bool unwrapToNative
) external returns (uint256 amountOut) {
// Pull full amount from caller
IERC20(tokenIn).transferFrom(msg.sender, address(this), amountIn);
uint256 fee = (amountIn * FEE_BPS) / BPS_DENOMINATOR;
uint256 swapAmt = amountIn - fee;
// Fee → treasury
IERC20(tokenIn).transfer(treasury, fee);
// Approve router for the swap portion only
IERC20(tokenIn).approve(router, swapAmt);
address recipient = unwrapToNative ? address(this) : msg.sender;
amountOut = IAlgebraSwapRouter(router).exactInputSingle(
IAlgebraSwapRouter.ExactInputSingleParams({
tokenIn: tokenIn,
tokenOut: tokenOut,
deployer: deployer,
recipient: recipient,
deadline: deadline,
amountIn: swapAmt,
amountOutMinimum: amountOutMin,
limitSqrtPrice: limitSqrtPrice
})
);
// If output is native SOMI, unwrap WSOMI → native and send to caller
if (unwrapToNative) {
IWETH(wsomi).withdraw(amountOut);
(bool ok, ) = msg.sender.call{value: amountOut}("");
require(ok, "native send failed");
}
}
/// @dev Accept native SOMI (needed for WETH.withdraw callback)
receive() external payable {}
}
ABI · 9 entries
json
[
{
"type": "constructor",
"inputs": [
{
"name": "_router",
"type": "address",
"internalType": "address"
},
{
"name": "_wsomi",
"type": "address",
"internalType": "address"
},
{
"name": "_treasury",
"type": "address",
"internalType": "address"
}
],
"stateMutability": "nonpayable"
},
{
"name": "BPS_DENOMINATOR",
"type": "function",
"inputs": [],
"outputs": [
{
"name": "",
"type": "uint256",
"internalType": "uint256"
}
],
"stateMutability": "view"
},
{
"name": "FEE_BPS",
"type": "function",
"inputs": [],
"outputs": [
{
"name": "",
"type": "uint256",
"internalType": "uint256"
}
],
"stateMutability": "view"
},
{
"name": "router",
"type": "function",
"inputs": [],
"outputs": [
{
"name": "",
"type": "address",
"internalType": "address"
}
],
"stateMutability": "view"
},
{
"name": "swapNativeToToken",
"type": "function",
"inputs": [
{
"name": "tokenOut",
"type": "address",
"internalType": "address"
},
{
"name": "deployer",
"type": "address",
"internalType": "address"
},
{
"name": "deadline",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "amountOutMin",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "limitSqrtPrice",
"type": "uint160",
"internalType": "uint160"
}
],
"outputs": [
{
"name": "amountOut",
"type": "uint256",
"internalType": "uint256"
}
],
"stateMutability": "payable"
},
{
"name": "swapTokenToToken",
"type": "function",
"inputs": [
{
"name": "tokenIn",
"type": "address",
"internalType": "address"
},
{
"name": "tokenOut",
"type": "address",
"internalType": "address"
},
{
"name": "deployer",
"type": "address",
"internalType": "address"
},
{
"name": "deadline",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "amountIn",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "amountOutMin",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "limitSqrtPrice",
"type": "uint160",
"internalType": "uint160"
},
{
"name": "unwrapToNative",
"type": "bool",
"internalType": "bool"
}
],
"outputs": [
{
"name": "amountOut",
"type": "uint256",
"internalType": "uint256"
}
],
"stateMutability": "nonpayable"
},
{
"name": "treasury",
"type": "function",
"inputs": [],
"outputs": [
{
"name": "",
"type": "address",
"internalType": "address"
}
],
"stateMutability": "view"
},
{
"name": "wsomi",
"type": "function",
"inputs": [],
"outputs": [
{
"name": "",
"type": "address",
"internalType": "address"
}
],
"stateMutability": "view"
},
{
"type": "receive",
"stateMutability": "payable"
}
]