feat: Initial setup and price() function implementation
This commit is contained in:
282
evm/src/angle/AngleAdapter.sol
Normal file
282
evm/src/angle/AngleAdapter.sol
Normal file
@@ -0,0 +1,282 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
pragma experimental ABIEncoderV2;
|
||||
pragma solidity ^0.8.13;
|
||||
|
||||
import {IERC20, ISwapAdapter} from "src/interfaces/ISwapAdapter.sol";
|
||||
|
||||
/// @title AngleAdapter
|
||||
contract AngleAdapter is ISwapAdapter {
|
||||
|
||||
ITransmuter transmuter;
|
||||
|
||||
constructor(ITransmuter _transmuter) {
|
||||
transmuter = _transmuter;
|
||||
}
|
||||
|
||||
function price(
|
||||
bytes32,
|
||||
IERC20 _sellToken,
|
||||
IERC20 _buyToken,
|
||||
uint256[] memory _specifiedAmounts
|
||||
) external view override returns (Fraction[] memory _prices) {
|
||||
_prices = new Fraction[](_specifiedAmounts.length);
|
||||
address sellTokenAddress = address(_sellToken);
|
||||
address buyTokenAddress = address(_buyToken);
|
||||
|
||||
for (uint256 i = 0; i < _specifiedAmounts.length; i++) {
|
||||
_prices[i] = getPriceAt(_specifiedAmounts[i], sellTokenAddress, buyTokenAddress);
|
||||
}
|
||||
}
|
||||
|
||||
function swap(
|
||||
bytes32 poolId,
|
||||
IERC20 sellToken,
|
||||
IERC20 buyToken,
|
||||
OrderSide side,
|
||||
uint256 specifiedAmount
|
||||
) external returns (Trade memory trade) {
|
||||
revert NotImplemented("TemplateSwapAdapter.swap");
|
||||
}
|
||||
|
||||
function getLimits(bytes32, IERC20 sellToken, IERC20 buyToken)
|
||||
external
|
||||
returns (uint256[] memory limits)
|
||||
{
|
||||
revert NotImplemented("TemplateSwapAdapter.getLimits");
|
||||
}
|
||||
|
||||
function getCapabilities(bytes32 poolId, IERC20 sellToken, IERC20 buyToken)
|
||||
external
|
||||
returns (Capability[] memory capabilities)
|
||||
{
|
||||
revert NotImplemented("TemplateSwapAdapter.getCapabilities");
|
||||
}
|
||||
|
||||
function getTokens(bytes32 poolId)
|
||||
external
|
||||
returns (IERC20[] memory tokens)
|
||||
{
|
||||
revert NotImplemented("TemplateSwapAdapter.getTokens");
|
||||
}
|
||||
|
||||
function getPoolIds(uint256 offset, uint256 limit)
|
||||
external
|
||||
returns (bytes32[] memory ids)
|
||||
{
|
||||
revert NotImplemented("TemplateSwapAdapter.getPoolIds");
|
||||
}
|
||||
|
||||
/// @notice Calculates pool prices for specified amounts
|
||||
/// @param amountIn The amount of the token being sold
|
||||
/// @param tokenIn The token being sold
|
||||
/// @param tokenOut The token being bought
|
||||
/// @return The price as a fraction corresponding to the provided amount.
|
||||
function getPriceAt(uint256 amountIn, address tokenIn, address tokenOut)
|
||||
internal
|
||||
view
|
||||
returns (Fraction memory)
|
||||
{
|
||||
uint256 amountOut = transmuter.quoteIn(amountIn, tokenIn, tokenOut);
|
||||
return Fraction(
|
||||
amountOut,
|
||||
amountIn
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
abstract contract ITransmuter {
|
||||
struct Tuple6871229 {
|
||||
address facetAddress;
|
||||
uint8 action;
|
||||
bytes4[] functionSelectors;
|
||||
}
|
||||
|
||||
struct Tuple1236461 {
|
||||
address facetAddress;
|
||||
bytes4[] functionSelectors;
|
||||
}
|
||||
|
||||
struct Tuple3550792 {
|
||||
uint8 isManaged;
|
||||
uint8 isMintLive;
|
||||
uint8 isBurnLive;
|
||||
uint8 decimals;
|
||||
uint8 onlyWhitelisted;
|
||||
uint216 normalizedStables;
|
||||
uint64[] xFeeMint;
|
||||
int64[] yFeeMint;
|
||||
uint64[] xFeeBurn;
|
||||
int64[] yFeeBurn;
|
||||
bytes oracleConfig;
|
||||
bytes whitelistData;
|
||||
Tuple5479340 managerData;
|
||||
}
|
||||
|
||||
struct Tuple5479340 {
|
||||
address[] subCollaterals;
|
||||
bytes config;
|
||||
}
|
||||
|
||||
function diamondCut(Tuple6871229[] memory _diamondCut, address _init, bytes memory _calldata) external {}
|
||||
|
||||
function implementation() external view returns (address) {}
|
||||
|
||||
function setDummyImplementation(address _implementation) external {}
|
||||
|
||||
function facetAddress(bytes4 _functionSelector) external view returns (address facetAddress_) {}
|
||||
|
||||
function facetAddresses() external view returns (address[] memory facetAddresses_) {}
|
||||
|
||||
function facetFunctionSelectors(address _facet) external view returns (bytes4[] memory _facetFunctionSelectors) {}
|
||||
|
||||
function facets() external view returns (Tuple1236461[] memory facets_) {}
|
||||
|
||||
function accessControlManager() external view returns (address) {}
|
||||
|
||||
function agToken() external view returns (address) {}
|
||||
|
||||
function getCollateralBurnFees(
|
||||
address collateral
|
||||
) external view returns (uint64[] memory xFeeBurn, int64[] memory yFeeBurn) {}
|
||||
|
||||
function getCollateralDecimals(address collateral) external view returns (uint8) {}
|
||||
|
||||
function getCollateralInfo(address collateral) external view returns (Tuple3550792 memory) {}
|
||||
|
||||
function getCollateralList() external view returns (address[] memory) {}
|
||||
|
||||
function getCollateralMintFees(
|
||||
address collateral
|
||||
) external view returns (uint64[] memory xFeeMint, int64[] memory yFeeMint) {}
|
||||
|
||||
function getCollateralRatio() external view returns (uint64 collatRatio, uint256 stablecoinsIssued) {}
|
||||
|
||||
function getCollateralWhitelistData(address collateral) external view returns (bytes memory) {}
|
||||
|
||||
function getIssuedByCollateral(
|
||||
address collateral
|
||||
) external view returns (uint256 stablecoinsFromCollateral, uint256 stablecoinsIssued) {}
|
||||
|
||||
function getManagerData(address collateral) external view returns (bool, address[] memory, bytes memory) {}
|
||||
|
||||
function getOracle(
|
||||
address collateral
|
||||
) external view returns (uint8 oracleType, uint8 targetType, bytes memory oracleData, bytes memory targetData) {}
|
||||
|
||||
function getOracleValues(
|
||||
address collateral
|
||||
) external view returns (uint256 mint, uint256 burn, uint256 ratio, uint256 minRatio, uint256 redemption) {}
|
||||
|
||||
function getRedemptionFees()
|
||||
external
|
||||
view
|
||||
returns (uint64[] memory xRedemptionCurve, int64[] memory yRedemptionCurve)
|
||||
{}
|
||||
|
||||
function getTotalIssued() external view returns (uint256) {}
|
||||
|
||||
function isPaused(address collateral, uint8 action) external view returns (bool) {}
|
||||
|
||||
function isTrusted(address sender) external view returns (bool) {}
|
||||
|
||||
function isTrustedSeller(address sender) external view returns (bool) {}
|
||||
|
||||
function isValidSelector(bytes4 selector) external view returns (bool) {}
|
||||
|
||||
function isWhitelistedCollateral(address collateral) external view returns (bool) {}
|
||||
|
||||
function isWhitelistedForCollateral(address collateral, address sender) external returns (bool) {}
|
||||
|
||||
function isWhitelistedForType(uint8 whitelistType, address sender) external view returns (bool) {}
|
||||
|
||||
function sellRewards(uint256 minAmountOut, bytes memory payload) external returns (uint256 amountOut) {}
|
||||
|
||||
function addCollateral(address collateral) external {}
|
||||
|
||||
function adjustStablecoins(address collateral, uint128 amount, bool increase) external {}
|
||||
|
||||
function changeAllowance(address token, address spender, uint256 amount) external {}
|
||||
|
||||
function recoverERC20(address collateral, address token, address to, uint256 amount) external {}
|
||||
|
||||
function revokeCollateral(address collateral) external {}
|
||||
|
||||
function setAccessControlManager(address _newAccessControlManager) external {}
|
||||
|
||||
function setCollateralManager(address collateral, Tuple5479340 memory managerData) external {}
|
||||
|
||||
function setOracle(address collateral, bytes memory oracleConfig) external {}
|
||||
|
||||
function setWhitelistStatus(address collateral, uint8 whitelistStatus, bytes memory whitelistData) external {}
|
||||
|
||||
function toggleTrusted(address sender, uint8 t) external {}
|
||||
|
||||
function setFees(address collateral, uint64[] memory xFee, int64[] memory yFee, bool mint) external {}
|
||||
|
||||
function setRedemptionCurveParams(uint64[] memory xFee, int64[] memory yFee) external {}
|
||||
|
||||
function togglePause(address collateral, uint8 pausedType) external {}
|
||||
|
||||
function toggleWhitelist(uint8 whitelistType, address who) external {}
|
||||
|
||||
function quoteIn(uint256 amountIn, address tokenIn, address tokenOut) external view returns (uint256 amountOut) {}
|
||||
|
||||
function quoteOut(uint256 amountOut, address tokenIn, address tokenOut) external view returns (uint256 amountIn) {}
|
||||
|
||||
function swapExactInput(
|
||||
uint256 amountIn,
|
||||
uint256 amountOutMin,
|
||||
address tokenIn,
|
||||
address tokenOut,
|
||||
address to,
|
||||
uint256 deadline
|
||||
) external returns (uint256 amountOut) {}
|
||||
|
||||
function swapExactInputWithPermit(
|
||||
uint256 amountIn,
|
||||
uint256 amountOutMin,
|
||||
address tokenIn,
|
||||
address to,
|
||||
uint256 deadline,
|
||||
bytes memory permitData
|
||||
) external returns (uint256 amountOut) {}
|
||||
|
||||
function swapExactOutput(
|
||||
uint256 amountOut,
|
||||
uint256 amountInMax,
|
||||
address tokenIn,
|
||||
address tokenOut,
|
||||
address to,
|
||||
uint256 deadline
|
||||
) external returns (uint256 amountIn) {}
|
||||
|
||||
function swapExactOutputWithPermit(
|
||||
uint256 amountOut,
|
||||
uint256 amountInMax,
|
||||
address tokenIn,
|
||||
address to,
|
||||
uint256 deadline,
|
||||
bytes memory permitData
|
||||
) external returns (uint256 amountIn) {}
|
||||
|
||||
function quoteRedemptionCurve(
|
||||
uint256 amount
|
||||
) external view returns (address[] memory tokens, uint256[] memory amounts) {}
|
||||
|
||||
function redeem(
|
||||
uint256 amount,
|
||||
address receiver,
|
||||
uint256 deadline,
|
||||
uint256[] memory minAmountOuts
|
||||
) external returns (address[] memory tokens, uint256[] memory amounts) {}
|
||||
|
||||
function redeemWithForfeit(
|
||||
uint256 amount,
|
||||
address receiver,
|
||||
uint256 deadline,
|
||||
uint256[] memory minAmountOuts,
|
||||
address[] memory forfeitTokens
|
||||
) external returns (address[] memory tokens, uint256[] memory amounts) {}
|
||||
|
||||
function updateNormalizer(uint256 amount, bool increase) external returns (uint256) {}
|
||||
}
|
||||
36
evm/src/angle/manifest.yaml
Normal file
36
evm/src/angle/manifest.yaml
Normal file
@@ -0,0 +1,36 @@
|
||||
# information about the author helps us reach out in case of issues.
|
||||
author:
|
||||
name: YourCompany
|
||||
email: developer@yourcompany.xyz
|
||||
|
||||
# Protocol Constants
|
||||
constants:
|
||||
protocol_gas: 30000
|
||||
# minimum capabilities we can expect, individual pools may extend these
|
||||
capabilities:
|
||||
- SellSide
|
||||
- BuySide
|
||||
- PriceFunction
|
||||
|
||||
# The file containing the adapter contract
|
||||
contract: TemplateSwapAdapter.sol
|
||||
|
||||
# Deployment instances used to generate chain specific bytecode.
|
||||
instances:
|
||||
- chain:
|
||||
name: mainnet
|
||||
id: 0
|
||||
arguments:
|
||||
- "0x00253582b2a3FE112feEC532221d9708c64cEFAb"
|
||||
|
||||
# Specify some automatic test cases in case getPoolIds and
|
||||
# getTokens are not implemented.
|
||||
tests:
|
||||
instances:
|
||||
- pool_id: "0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc"
|
||||
sell_token: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
|
||||
buy_token: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
|
||||
block: 17000000
|
||||
chain:
|
||||
id: 0
|
||||
name: mainnet
|
||||
Reference in New Issue
Block a user