Initial Commit
This commit is contained in:
1189
contracts/base_paca.sol
Normal file
1189
contracts/base_paca.sol
Normal file
File diff suppressed because it is too large
Load Diff
1235
contracts/bsc_paca.sol
Normal file
1235
contracts/bsc_paca.sol
Normal file
File diff suppressed because it is too large
Load Diff
25
contracts/s_pricefeed.sol
Normal file
25
contracts/s_pricefeed.sol
Normal file
@@ -0,0 +1,25 @@
|
||||
pragma solidity ^0.8.20;
|
||||
|
||||
interface AggregatorV3Interface {
|
||||
function latestRoundData() external view returns (
|
||||
uint80 roundId,
|
||||
int256 answer,
|
||||
uint256 startedAt,
|
||||
uint256 updatedAt,
|
||||
uint80 answeredInRound
|
||||
);
|
||||
}
|
||||
|
||||
contract SPriceOracle {
|
||||
AggregatorV3Interface public priceFeed;
|
||||
|
||||
constructor() {
|
||||
priceFeed = AggregatorV3Interface(0x726D2E87d73567ecA1b75C063Bd09c1493655918);
|
||||
}
|
||||
/// @notice Returns the USD price of S in 1e18 based on API3
|
||||
function getLatestPrice(address token) external view returns (uint256) {
|
||||
(, int256 price,,,) = priceFeed.latestRoundData();
|
||||
require(price > 0, "Invalid price from Chainlink");
|
||||
return uint256(price);
|
||||
}
|
||||
}
|
||||
58
contracts/swapx_pricefeed.sol
Normal file
58
contracts/swapx_pricefeed.sol
Normal file
@@ -0,0 +1,58 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.20;
|
||||
|
||||
import "@uniswap/v3-core/contracts/libraries/FullMath.sol";
|
||||
|
||||
/// @notice Minimal interface for a Uniswap V3 pool (to access slot0)
|
||||
interface IUniswapV3Pool {
|
||||
function safelyGetStateOfAMM()
|
||||
external
|
||||
view
|
||||
returns (
|
||||
uint160 sqrtPrice, // The current sqrt(price) as a Q64.96 value
|
||||
int24 tick,
|
||||
uint16 lastFee,
|
||||
uint8 pluginConfig,
|
||||
uint128 activeLiquidity,
|
||||
uint24 nextTick,
|
||||
uint24 previousTick
|
||||
);
|
||||
}
|
||||
|
||||
/// @title USDC Quote for SWAPx
|
||||
/// @notice Returns the USDC price (scaled to 18 decimals) of 1 token,
|
||||
/// assuming a pool where token0 is USDC and token1 is the token of interest.
|
||||
/// The pool is hardcoded as well as the token addresses.
|
||||
contract UsdcQuoteV3 {
|
||||
// Hardcoded addresses
|
||||
address public constant POOL_ADDRESS = 0x467865E7Ce29E7ED8f362D51Fd7141117B234b44;
|
||||
// token0 is USDC
|
||||
address public constant USDC = 0x29219dd400f2Bf60E5a23d13Be72B486D4038894;
|
||||
// token1 is the token to be priced (assumed to have 18 decimals)
|
||||
address public constant TOKEN = 0xA04BC7140c26fc9BB1F36B1A604C7A5a88fb0E70;
|
||||
|
||||
// Constant representing 2^192 used for fixed‑point math
|
||||
uint256 public constant Q192 = 2**192;
|
||||
|
||||
function getSqrtPrice() public view returns (uint256 price) {
|
||||
IUniswapV3Pool pool = IUniswapV3Pool(POOL_ADDRESS);
|
||||
(uint160 sqrtPrice,,,,,,) = pool.safelyGetStateOfAMM();
|
||||
|
||||
price = sqrtPrice;
|
||||
}
|
||||
/**
|
||||
* @notice Returns the USDC price (scaled to 18 decimals) for exactly 1 TOKEN.
|
||||
*
|
||||
* @return amount18 The USDC amount (scaled to 18 decimals) per 1 TOKEN.
|
||||
*/
|
||||
function getLatestPrice(address token) external view returns (uint256 amount18) {
|
||||
uint256 sqrtPrice = getSqrtPrice();
|
||||
|
||||
uint256 numerator1 = uint256(sqrtPrice) * uint256(sqrtPrice);
|
||||
uint256 directPrice = FullMath.mulDiv(numerator1, 10**6, 1 << 192);
|
||||
require(directPrice > 0, "Direct price is zero");
|
||||
amount18 = 1e36 / directPrice;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user