Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
jankjr committed Nov 26, 2024
1 parent 66499ee commit aae65f8
Show file tree
Hide file tree
Showing 109 changed files with 8,114 additions and 9,224 deletions.
54 changes: 54 additions & 0 deletions contracts/contracts/Balancer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.17;

interface IBalancerVault {
enum SwapKind {
GIVEN_IN,
GIVEN_OUT
}

struct PoolTokenInfo {
uint256 cash;
uint256 managed;
uint256 lastChangeBlock;
address assetManager;
}

struct SingleSwap {
bytes32 poolId;
SwapKind kind;
address assetIn;
address assetOut;
uint256 amount;
bytes userData;
}

struct FundManagement {
address sender;
bool fromInternalBalance;
address payable recipient;
bool toInternalBalance;
}

function getPoolTokenInfo(
bytes32 poolId,
address token
) external view returns (PoolTokenInfo memory);

function swap(
SingleSwap memory singleSwap,
FundManagement memory funds,
uint256 limit,
uint256 deadline
)
external
payable
returns (uint256 amountCalculated);
}

interface IBalancerQueries {
function querySwap(
IBalancerVault.SingleSwap memory singleSwap,
IBalancerVault.FundManagement memory funds
) external returns (uint256);
}
22 changes: 22 additions & 0 deletions contracts/contracts/IRETHRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,25 @@ interface IRETHRouter {
uint256 _steps
) external returns (uint256[2] memory portions, uint256 amountOut);
}

interface IRETH {
function getEthValue(uint256 _rethAmount) external view returns (uint256);
function getRethValue(uint256 _ethAmount) external view returns (uint256);
}

interface RocketDepositPoolInterface {
function getBalance() external view returns (uint256);
function getNodeBalance() external view returns (uint256);
function getUserBalance() external view returns (int256);
function getExcessBalance() external view returns (uint256);
function deposit() external payable;
function getMaximumDepositAmount() external view returns (uint256);
function nodeDeposit(uint256 _totalAmount) external payable;
function nodeCreditWithdrawal(uint256 _amount) external;
function recycleDissolvedDeposit() external payable;
function recycleExcessCollateral() external payable;
function recycleLiquidatedStake() external payable;
function assignDeposits() external;
function maybeAssignDeposits() external returns (bool);
function withdrawExcessBalance(uint256 _amount) external;
}
39 changes: 39 additions & 0 deletions contracts/contracts/weiroll-helpers/BalancerCall.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.17;

import { IBalancerVault } from "../Balancer.sol";

contract BalancerCall {
struct StaticData {
uint256 limit;
address tokenIn;
address tokenOut;
bytes32 poolId;
address payable recipient;
uint256 deadline;
IBalancerVault.SwapKind kind;
}
function swap(
uint256 amountIn,
bytes memory data
) external returns (uint256) {
StaticData memory staticData = abi.decode(data, (StaticData));
IBalancerVault.SingleSwap memory singleSwap = IBalancerVault.SingleSwap({
poolId: staticData.poolId,
kind: staticData.kind,
assetIn: staticData.tokenIn,
assetOut: staticData.tokenOut,
amount: amountIn,
userData: ""
});
IBalancerVault.FundManagement memory funds = IBalancerVault.FundManagement({
sender: address(this),
fromInternalBalance: false,
recipient: staticData.recipient,
toInternalBalance: false
});
return IBalancerVault(
0xBA12222222228d8Ba445958a75a0704d566BF2C8
).swap(singleSwap, funds, staticData.limit, staticData.deadline);
}
}
34 changes: 32 additions & 2 deletions contracts/contracts/weiroll-helpers/CurveRouterCall.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,17 @@ interface ICurveRouter {
) external returns (uint256);
}
contract CurveRouterCall {
function exchange(uint256 amountIn, uint256 expected, address router, bytes memory encodedRouterCall) external returns (uint256) {
(address[9] memory route, uint256[3][4] memory swapParams, address[4] memory pools ) = abi.decode(
function exchange(
uint256 amountIn,
uint256 expected,
address router,
bytes memory encodedRouterCall
) external returns (uint256) {
(
address[9] memory route,
uint256[3][4] memory swapParams,
address[4] memory pools
) = abi.decode(
encodedRouterCall,
(address[9], uint256[3][4], address[4])
);
Expand All @@ -64,4 +73,25 @@ contract CurveRouterCall {
pools
);
}

function exchangeNew(
uint256 amountIn,
bytes memory encodedRouterCall
) external returns (uint256) {
(
address[11] memory route,
uint256[5][5] memory swapParams,
uint256 expected,
address router
) = abi.decode(
encodedRouterCall,
(address[11], uint256[5][5], uint256, address)
);
return ICurveRouter(router).exchange(
route,
swapParams,
amountIn,
expected
);
}
}
102 changes: 102 additions & 0 deletions contracts/contracts/weiroll-helpers/UniV3RouterCall.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,107 @@
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.17;
interface IUniV3Factory {
function getPool(address tokenA, address tokenB, uint24 fee) external view returns (address pool);
function feeAmountTickSpacing(uint24 fee) external view returns (int24);
}

interface IUniV3Pool {
function token0() external view returns (address);
function token1() external view returns (address);
function fee() external view returns (uint24);
function tickSpacing() external view returns (int24);
}
interface IUniV3QuoterV2 {


/// @notice Returns the amount out received for a given exact input swap without executing the swap
/// @param path The path of the swap, i.e. each token pair and the pool fee
/// @param amountIn The amount of the first token to swap
/// @return amountOut The amount of the last token that would be received
/// @return sqrtPriceX96AfterList List of the sqrt price after the swap for each pool in the path
/// @return initializedTicksCrossedList List of the initialized ticks that the swap crossed for each pool in the path
/// @return gasEstimate The estimate of the gas that the swap consumes
function quoteExactInput(bytes memory path, uint256 amountIn)
external
returns (
uint256 amountOut,
uint160[] memory sqrtPriceX96AfterList,
uint32[] memory initializedTicksCrossedList,
uint256 gasEstimate
);

struct QuoteExactInputSingleParams {
address tokenIn;
address tokenOut;
uint256 amountIn;
uint24 fee;
uint160 sqrtPriceLimitX96;
}

/// @notice Returns the amount out received for a given exact input but for a swap of a single pool
/// @param params The params for the quote, encoded as `QuoteExactInputSingleParams`
/// tokenIn The token being swapped in
/// tokenOut The token being swapped out
/// fee The fee of the token pool to consider for the pair
/// amountIn The desired input amount
/// sqrtPriceLimitX96 The price limit of the pool that cannot be exceeded by the swap
/// @return amountOut The amount of `tokenOut` that would be received
/// @return sqrtPriceX96After The sqrt price of the pool after the swap
/// @return initializedTicksCrossed The number of initialized ticks that the swap crossed
/// @return gasEstimate The estimate of the gas that the swap consumes
function quoteExactInputSingle(QuoteExactInputSingleParams memory params)
external
returns (
uint256 amountOut,
uint160 sqrtPriceX96After,
uint32 initializedTicksCrossed,
uint256 gasEstimate
);

/// @notice Returns the amount in required for a given exact output swap without executing the swap
/// @param path The path of the swap, i.e. each token pair and the pool fee. Path must be provided in reverse order
/// @param amountOut The amount of the last token to receive
/// @return amountIn The amount of first token required to be paid
/// @return sqrtPriceX96AfterList List of the sqrt price after the swap for each pool in the path
/// @return initializedTicksCrossedList List of the initialized ticks that the swap crossed for each pool in the path
/// @return gasEstimate The estimate of the gas that the swap consumes
function quoteExactOutput(bytes memory path, uint256 amountOut)
external
returns (
uint256 amountIn,
uint160[] memory sqrtPriceX96AfterList,
uint32[] memory initializedTicksCrossedList,
uint256 gasEstimate
);

struct QuoteExactOutputSingleParams {
address tokenIn;
address tokenOut;
uint256 amount;
uint24 fee;
uint160 sqrtPriceLimitX96;
}

/// @notice Returns the amount in required to receive the given exact output amount but for a swap of a single pool
/// @param params The params for the quote, encoded as `QuoteExactOutputSingleParams`
/// tokenIn The token being swapped in
/// tokenOut The token being swapped out
/// fee The fee of the token pool to consider for the pair
/// amountOut The desired output amount
/// sqrtPriceLimitX96 The price limit of the pool that cannot be exceeded by the swap
/// @return amountIn The amount required as the input for the swap in order to receive `amountOut`
/// @return sqrtPriceX96After The sqrt price of the pool after the swap
/// @return initializedTicksCrossed The number of initialized ticks that the swap crossed
/// @return gasEstimate The estimate of the gas that the swap consumes
function quoteExactOutputSingle(QuoteExactOutputSingleParams memory params)
external
returns (
uint256 amountIn,
uint160 sqrtPriceX96After,
uint32 initializedTicksCrossed,
uint256 gasEstimate
);
}

interface ISwapRouter {
struct ExactInputSingleParams {
Expand Down
16 changes: 8 additions & 8 deletions contracts/deploy/02_toolkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ import { DeployFunction } from 'hardhat-deploy/types'

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployer } = await hre.getNamedAccounts()
const balanceOf = await hre.deployments.deploy('BalanceOf', {
from: deployer,
})
console.log('BalanceOf deployed to:', balanceOf.address)
// const balanceOf = await hre.deployments.deploy('BalanceOf', {
// from: deployer,
// })
// console.log('BalanceOf deployed to:', balanceOf.address)

const curveRouterCall = await hre.deployments.deploy('CurveRouterCall', {
from: deployer,
})
console.log('curveRouterCall deployed to:', curveRouterCall.address)

const ethhBalance = await hre.deployments.deploy('EthBalance', {
from: deployer,
})
console.log('ethhBalance deployed to:', ethhBalance.address)
// const ethhBalance = await hre.deployments.deploy('EthBalance', {
// from: deployer,
// })
// console.log('ethhBalance deployed to:', ethhBalance.address)



Expand Down
53 changes: 29 additions & 24 deletions contracts/deploy/03_routers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ import { DeployFunction } from 'hardhat-deploy/types'

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployer } = await hre.getNamedAccounts()
// const uniV3RouterCall = await hre.deployments.deploy('UniV3RouterCall', {
// from: deployer,
// })
// console.log('uniV3RouterCall deployed to:', uniV3RouterCall.address)
const uniV3RouterCall = await hre.deployments.deploy('UniV3RouterCall', {
from: deployer,
})
console.log('uniV3RouterCall deployed to:', uniV3RouterCall.address)

// const CurveStableSwapNGHelper = await hre.deployments.deploy(
// 'CurveStableSwapNGHelper',
// {
// from: deployer,
// }
// )
// console.log(
// 'CurveStableSwapNGHelper deployed to:',
// CurveStableSwapNGHelper.address
// )
const CurveStableSwapNGHelper = await hre.deployments.deploy(
'CurveStableSwapNGHelper',
{
from: deployer,
}
)
console.log(
'CurveStableSwapNGHelper deployed to:',
CurveStableSwapNGHelper.address
)

if ((await hre.ethers.provider.getNetwork()).chainId === 8453) {
const SlipstreamRouterCall = await hre.deployments.deploy(
Expand All @@ -32,16 +32,21 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
)
}

// const CurveCryptoFactoryHelper = await hre.deployments.deploy(
// 'CurveCryptoFactoryHelper',
// {
// from: deployer,
// }
// )
// console.log(
// 'CurveCryptoFactoryHelper deployed to:',
// CurveCryptoFactoryHelper.address
// )
const CurveCryptoFactoryHelper = await hre.deployments.deploy(
'CurveCryptoFactoryHelper',
{
from: deployer,
}
)
console.log(
'CurveCryptoFactoryHelper deployed to:',
CurveCryptoFactoryHelper.address
)

const BalancerCall = await hre.deployments.deploy('BalancerCall', {
from: deployer,
})
console.log('BalancerCall deployed to:', BalancerCall.address)
}
func.tags = ['routers']
export default func
Loading

0 comments on commit aae65f8

Please sign in to comment.