Skip to content

Commit

Permalink
Merge pull request #698 from rysk-finance/RYSK-364/update-manager-fun…
Browse files Browse the repository at this point in the history
…ctions-access-control

RYSK-364/update-manager-functions-access-control: update functions an…
  • Loading branch information
kjr217 authored Oct 30, 2023
2 parents 0b03df8 + f9dfacd commit 3f144e5
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 52 deletions.
79 changes: 39 additions & 40 deletions packages/contracts/contracts/Manager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import "./LiquidityPool.sol";
import "./OptionExchange.sol";
import "./OptionCatalogue.sol";
import "./BeyondPricer.sol";
import {IRangeOrderReactor, Position, IUniswapV3PoolState} from "./interfaces/IRangeOrderReactor.sol";
import { IRangeOrderReactor, Position, IUniswapV3PoolState } from "./interfaces/IRangeOrderReactor.sol";

import "./libraries/AccessControl.sol";
import "./libraries/CustomErrors.sol";
Expand Down Expand Up @@ -272,12 +272,12 @@ contract Manager is AccessControl {
/////////////////////

function setLowDeltaSellOptionFlatIV(uint256 _lowDeltaSellOptionFlatIV) external {
_isProxyManager();
_isKeeper();
beyondPricer.setLowDeltaSellOptionFlatIV(_lowDeltaSellOptionFlatIV);
}

function setLowDeltaThreshold(uint256 _lowDeltaThreshold) external {
_isProxyManager();
_isKeeper();
beyondPricer.setLowDeltaThreshold(_lowDeltaThreshold);
}

Expand All @@ -287,22 +287,22 @@ contract Manager is AccessControl {
}

function setBidAskIVSpread(uint256 _bidAskIVSpread) external {
_isProxyManager();
_isKeeper();
beyondPricer.setBidAskIVSpread(_bidAskIVSpread);
}

function setSlippageGradient(uint256 _slippageGradient) external {
_isProxyManager();
_isKeeper();
beyondPricer.setSlippageGradient(_slippageGradient);
}

function setCollateralLendingRate(uint256 _collateralLendingRate) external {
_isProxyManager();
_isKeeper();
beyondPricer.setCollateralLendingRate(_collateralLendingRate);
}

function setDeltaBorrowRates(BeyondPricer.DeltaBorrowRates calldata _deltaBorrowRates) external {
_isProxyManager();
_isKeeper();
beyondPricer.setDeltaBorrowRates(_deltaBorrowRates);
}

Expand All @@ -326,7 +326,7 @@ contract Manager is AccessControl {
int80[] memory _callSlippageGradientMultipliers,
int80[] memory _putSlippageGradientMultipliers
) public {
_isProxyManager();
_isKeeper();
beyondPricer.setSlippageGradientMultipliers(
_tenorIndex,
_callSlippageGradientMultipliers,
Expand All @@ -339,7 +339,7 @@ contract Manager is AccessControl {
int80[] memory _callSpreadCollateralMultipliers,
int80[] memory _putSpreadCollateralMultipliers
) public {
_isProxyManager();
_isKeeper();
beyondPricer.setSpreadCollateralMultipliers(
_tenorIndex,
_callSpreadCollateralMultipliers,
Expand All @@ -352,7 +352,7 @@ contract Manager is AccessControl {
int80[] memory _callSpreadDeltaMultipliers,
int80[] memory _putSpreadDeltaMultipliers
) public {
_isProxyManager();
_isKeeper();
beyondPricer.setSpreadDeltaMultipliers(
_tenorIndex,
_callSpreadDeltaMultipliers,
Expand Down Expand Up @@ -382,7 +382,7 @@ contract Manager is AccessControl {
* @notice Exits an active range order
* @param reactorIndex the index of the range order reactor
*/
function exitActiveRangeOrder(uint256 reactorIndex) external {
function exitActiveRangeOrder(uint256 reactorIndex) external {
_isKeeper();
address rangeOrderReactorAddress = liquidityPool.hedgingReactors(reactorIndex);
IRangeOrderReactor rangeOrderReactor = IRangeOrderReactor(rangeOrderReactorAddress);
Expand All @@ -396,54 +396,53 @@ contract Manager is AccessControl {
IUniswapV3PoolState uniswapPool = rangeOrderReactor.pool();
(, int24 tick) = uniswapPool.slot0();
Position memory currentOrder = rangeOrderReactor.currentPosition();
deltaLimit[rebalanceCaller.caller] += reclaimableDelta(rebalanceCaller.deltaUsed, tick, currentOrder);
deltaLimit[rebalanceCaller.caller] += reclaimableDelta(
rebalanceCaller.deltaUsed,
tick,
currentOrder
);
delete rebalanceCallers[reactorIndex];
}
}
}

/**
* @notice Calculates amount of delta that can be reclaimed depending on how much of the range order was filled
* @param deltaAmount the amount of delta used to execute the range order
* @param tick the current tick of the pool
* @param currentOrder the current position of the range order reactor
*/
function reclaimableDelta(uint256 deltaAmount, int24 tick, Position memory currentOrder)
public
pure
returns (uint256)
{
uint256 filled = percentageFilled(tick, currentOrder);
// Calculate reclaimable amount
uint256 reclaimable = deltaAmount * (1e18 - filled) / 1e18;
return reclaimable;
}
function reclaimableDelta(
uint256 deltaAmount,
int24 tick,
Position memory currentOrder
) public pure returns (uint256) {
uint256 filled = percentageFilled(tick, currentOrder);
// Calculate reclaimable amount
uint256 reclaimable = (deltaAmount * (1e18 - filled)) / 1e18;
return reclaimable;
}

/**
* @notice Calculates the percentage of the range order that has been filled
* @param tick the current tick of the pool
* @param position the current position of the range order reactor
*/
function percentageFilled(int24 tick, Position memory position)
public
pure
returns (uint256)
{
*/
function percentageFilled(int24 tick, Position memory position) public pure returns (uint256) {
int256 totalRange = int256(position.activeUpperTick - position.activeLowerTick);

if(totalRange == 0) return 0;
if (totalRange == 0) return 0;

int256 distance;
if(position.activeRangeAboveTick) {
int256 distance;
if (position.activeRangeAboveTick) {
distance = int256(position.activeUpperTick - tick);
} else {
} else {
distance = int256(tick - position.activeLowerTick);
}

// Clamp the distance to be within the range [0, totalRange]
if (distance < 0) distance = 0;
if (distance > totalRange) distance = totalRange;
}

return uint256(distance * 1e18 / totalRange);
}
// Clamp the distance to be within the range [0, totalRange]
if (distance < 0) distance = 0;
if (distance > totalRange) distance = totalRange;

return uint256((distance * 1e18) / totalRange);
}
}
52 changes: 40 additions & 12 deletions packages/contracts/deploy/arbitrum/ArbitrumManagerDeploy.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Signer } from "ethers"
import hre, { ethers } from "hardhat"


// Arbitrum mainnet specific contract addresses. Change for other networks
const authorityAddress = "0x0c83E447dc7f4045b8717d5321056D4e9E86dCD2"
const liquidityPoolAddress = "0xC10B976C671Ce9bFf0723611F01422ACbAe100A5"
const optionHandlerAddress = "0xA802795269588bf33739816f76B53fD6cd099b27"
const authorityAddress = "0x74948DAf8Beb3d14ddca66d205bE3bc58Df39aC9"
const liquidityPoolAddress = "0x217749d9017cB87712654422a1F5856AAA147b80"
const optionHandlerAddress = "0xc63717c4436043781a63C8c64B02Ff774350e8F8"
const catalogueAddress = "0x44227Dc2a1d71FC07DC254Dfd42B1C44aFF12168"
const exchangeAddress = "0xC117bf3103bd09552F9a721F0B8Bce9843aaE1fa"
const beyondPricerAddress = "0xeA5Fb118862876f249Ff0b3e7fb25fEb38158def"

async function main() {
const [deployer] = await ethers.getSigners()
Expand All @@ -14,21 +15,49 @@ async function main() {

console.log("Account balance:", (await deployer.getBalance()).toString())
// deploy system
let deployParams = await deployManager(deployer, authorityAddress, liquidityPoolAddress, optionHandlerAddress)
let deployParams = await deployManager(
authorityAddress,
liquidityPoolAddress,
optionHandlerAddress,
catalogueAddress,
exchangeAddress,
beyondPricerAddress
)
console.log("system deployed")
const manager = deployParams.manager
console.log("manager address: ", deployParams.manager.address)
}

// --------- DEPLOY RYSK SYSTEM ----------------

export async function deployManager(deployer: Signer, authorityAddress: String, liquidityPoolAddress: String, optionHandlerAddress: String) {
export async function deployManager(
authorityAddress: String,
liquidityPoolAddress: String,
optionHandlerAddress: String,
catalogueAddress: String,
exchangeAddress: String,
beyondPricerAddress: String
) {
const managerFactory = await ethers.getContractFactory("Manager")
const manager = await managerFactory.deploy(authorityAddress, liquidityPoolAddress, optionHandlerAddress)
const manager = await managerFactory.deploy(
authorityAddress: String,
liquidityPoolAddress,
optionHandlerAddress,
catalogueAddress,
exchangeAddress,
beyondPricerAddress
)
console.log("manager deployed")
try {
await hre.run("verify:verify", {
address: manager.address,
constructorArguments: [authorityAddress, liquidityPoolAddress, optionHandlerAddress]
constructorArguments: [
authorityAddress,
liquidityPoolAddress,
optionHandlerAddress,
catalogueAddress,
exchangeAddress,
beyondPricerAddress
]
})
console.log("manager verified")
} catch (err: any) {
Expand All @@ -38,7 +67,7 @@ export async function deployManager(deployer: Signer, authorityAddress: String,
}
}
return {
manager
manager
}
}

Expand All @@ -48,4 +77,3 @@ main()
console.error(error)
process.exit(1)
})

0 comments on commit 3f144e5

Please sign in to comment.