Skip to content

Commit

Permalink
Merge pull request #3022 from OlympusDAO/rbs1.4
Browse files Browse the repository at this point in the history
RBS 1.4 Contract updates
  • Loading branch information
brightiron committed Nov 16, 2023
2 parents f694d38 + 49e7f4f commit b7d6fca
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 101 deletions.
95 changes: 48 additions & 47 deletions src/abi/Range.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
{ "internalType": "contract ERC20", "name": "ohm_", "type": "address" },
{ "internalType": "contract ERC20", "name": "reserve_", "type": "address" },
{ "internalType": "uint256", "name": "thresholdFactor_", "type": "uint256" },
{ "internalType": "uint256", "name": "cushionSpread_", "type": "uint256" },
{ "internalType": "uint256", "name": "wallSpread_", "type": "uint256" }
{ "internalType": "uint256[2]", "name": "lowSpreads_", "type": "uint256[2]" },
{ "internalType": "uint256[2]", "name": "highSpreads_", "type": "uint256[2]" }
],
"stateMutability": "nonpayable",
"type": "constructor"
Expand Down Expand Up @@ -56,6 +56,7 @@
{
"anonymous": false,
"inputs": [
{ "indexed": false, "internalType": "bool", "name": "high_", "type": "bool" },
{ "indexed": false, "internalType": "uint256", "name": "cushionSpread_", "type": "uint256" },
{ "indexed": false, "internalType": "uint256", "name": "wallSpread_", "type": "uint256" }
],
Expand Down Expand Up @@ -171,8 +172,8 @@
},
{
"inputs": [
{ "internalType": "bool", "name": "wall_", "type": "bool" },
{ "internalType": "bool", "name": "high_", "type": "bool" }
{ "internalType": "bool", "name": "high_", "type": "bool" },
{ "internalType": "bool", "name": "wall_", "type": "bool" }
],
"name": "price",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
Expand All @@ -191,66 +192,62 @@
{ "internalType": "uint48", "name": "lastActive", "type": "uint48" },
{ "internalType": "uint256", "name": "capacity", "type": "uint256" },
{ "internalType": "uint256", "name": "threshold", "type": "uint256" },
{ "internalType": "uint256", "name": "market", "type": "uint256" }
],
"internalType": "struct RANGEv1.Side",
"name": "low",
"type": "tuple"
},
{
"components": [
{ "internalType": "bool", "name": "active", "type": "bool" },
{ "internalType": "uint48", "name": "lastActive", "type": "uint48" },
{ "internalType": "uint256", "name": "capacity", "type": "uint256" },
{ "internalType": "uint256", "name": "threshold", "type": "uint256" },
{ "internalType": "uint256", "name": "market", "type": "uint256" }
],
"internalType": "struct RANGEv1.Side",
"name": "high",
"type": "tuple"
},
{
"components": [
{ "internalType": "uint256", "name": "market", "type": "uint256" },
{
"components": [{ "internalType": "uint256", "name": "price", "type": "uint256" }],
"internalType": "struct RANGEv1.Line",
"name": "high",
"components": [
{ "internalType": "uint256", "name": "price", "type": "uint256" },
{ "internalType": "uint256", "name": "spread", "type": "uint256" }
],
"internalType": "struct RANGEv2.Line",
"name": "cushion",
"type": "tuple"
},
{
"components": [{ "internalType": "uint256", "name": "price", "type": "uint256" }],
"internalType": "struct RANGEv1.Line",
"name": "low",
"components": [
{ "internalType": "uint256", "name": "price", "type": "uint256" },
{ "internalType": "uint256", "name": "spread", "type": "uint256" }
],
"internalType": "struct RANGEv2.Line",
"name": "wall",
"type": "tuple"
},
{ "internalType": "uint256", "name": "spread", "type": "uint256" }
}
],
"internalType": "struct RANGEv1.Band",
"name": "cushion",
"internalType": "struct RANGEv2.Side",
"name": "low",
"type": "tuple"
},
{
"components": [
{ "internalType": "bool", "name": "active", "type": "bool" },
{ "internalType": "uint48", "name": "lastActive", "type": "uint48" },
{ "internalType": "uint256", "name": "capacity", "type": "uint256" },
{ "internalType": "uint256", "name": "threshold", "type": "uint256" },
{ "internalType": "uint256", "name": "market", "type": "uint256" },
{
"components": [{ "internalType": "uint256", "name": "price", "type": "uint256" }],
"internalType": "struct RANGEv1.Line",
"name": "high",
"components": [
{ "internalType": "uint256", "name": "price", "type": "uint256" },
{ "internalType": "uint256", "name": "spread", "type": "uint256" }
],
"internalType": "struct RANGEv2.Line",
"name": "cushion",
"type": "tuple"
},
{
"components": [{ "internalType": "uint256", "name": "price", "type": "uint256" }],
"internalType": "struct RANGEv1.Line",
"name": "low",
"components": [
{ "internalType": "uint256", "name": "price", "type": "uint256" },
{ "internalType": "uint256", "name": "spread", "type": "uint256" }
],
"internalType": "struct RANGEv2.Line",
"name": "wall",
"type": "tuple"
},
{ "internalType": "uint256", "name": "spread", "type": "uint256" }
}
],
"internalType": "struct RANGEv1.Band",
"name": "wall",
"internalType": "struct RANGEv2.Side",
"name": "high",
"type": "tuple"
}
],
"internalType": "struct RANGEv1.Range",
"internalType": "struct RANGEv2.Range",
"name": "",
"type": "tuple"
}
Expand All @@ -277,6 +274,7 @@
},
{
"inputs": [
{ "internalType": "bool", "name": "high_", "type": "bool" },
{ "internalType": "uint256", "name": "cushionSpread_", "type": "uint256" },
{ "internalType": "uint256", "name": "wallSpread_", "type": "uint256" }
],
Expand All @@ -293,7 +291,10 @@
"type": "function"
},
{
"inputs": [{ "internalType": "bool", "name": "wall_", "type": "bool" }],
"inputs": [
{ "internalType": "bool", "name": "high_", "type": "bool" },
{ "internalType": "bool", "name": "wall_", "type": "bool" }
],
"name": "spread",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
Expand Down Expand Up @@ -328,7 +329,7 @@
"type": "function"
},
{
"inputs": [{ "internalType": "uint256", "name": "movingAverage_", "type": "uint256" }],
"inputs": [{ "internalType": "uint256", "name": "target_", "type": "uint256" }],
"name": "updatePrices",
"outputs": [],
"stateMutability": "nonpayable",
Expand Down
8 changes: 4 additions & 4 deletions src/constants/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,13 @@ export const BALANCER_VAULT_ADDRESSSES = {
};

export const RANGE_OPERATOR_ADDRESSES = {
[NetworkId.MAINNET]: "0x0374c001204eF5e7E4F5362A5A2430CB6c219326",
[NetworkId.TESTNET_GOERLI]: "0x255467F1ca090Cd0Ed20014DC957E942d846843b",
[NetworkId.MAINNET]: "0x0AE561226896dA978EaDA0Bec4a7d3CfAE04f506",
[NetworkId.TESTNET_GOERLI]: "0x6620592f9bdffAbadcea644a35946E7b93EaaF56",
};

export const RANGE_ADDRESSES = {
[NetworkId.MAINNET]: "0xb212D9584cfc56EFf1117F412Fe0bBdc53673954",
[NetworkId.TESTNET_GOERLI]: "0x446f06f8Df7d5f627B073c6349b948B95c1f9185",
[NetworkId.MAINNET]: "0x399cD3685912bb56aAeD0949119dB6cE5Df60FB5",
[NetworkId.TESTNET_GOERLI]: "0xFF88b47af188d91aC05ff5E843B5F6863472EdD0",
};

export const RANGE_PRICE_ADDRESSES = {
Expand Down
23 changes: 12 additions & 11 deletions src/views/Range/RangeChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from "recharts";
import { NameType } from "recharts/types/component/DefaultTooltipContent";
import { formatCurrency, parseBigNumber, trim } from "src/helpers";
import { RANGEv2 as OlympusRange } from "src/typechain/Range";
import { OperatorMovingAverage, OperatorTargetPrice, PriceHistory } from "src/views/Range/hooks";

const PREFIX = "RangeChart";
Expand All @@ -39,7 +40,7 @@ const StyledResponsiveContainer = styled(ResponsiveContainer)(({ theme }) => ({
* Component for Displaying RangeChart
*/
const RangeChart = (props: {
rangeData: any;
rangeData: OlympusRange.RangeStructOutput;
currentPrice: number;
bidPrice: number;
askPrice: number;
Expand All @@ -53,10 +54,10 @@ const RangeChart = (props: {
const { data: targetPrice } = OperatorTargetPrice();
const { data: movingAverage } = OperatorMovingAverage();

const formattedWallHigh = trim(parseBigNumber(rangeData.wall.high.price, 18), 2);
const formattedWallLow = trim(parseBigNumber(rangeData.wall.low.price, 18), 2);
const formattedCushionHigh = trim(parseBigNumber(rangeData.cushion.high.price, 18), 2);
const formattedCushionLow = trim(parseBigNumber(rangeData.cushion.low.price, 18), 2);
const formattedWallHigh = trim(parseBigNumber(rangeData.high.wall.price, 18), 2);
const formattedWallLow = trim(parseBigNumber(rangeData.low.wall.price, 18), 2);
const formattedCushionHigh = trim(parseBigNumber(rangeData.high.cushion.price, 18), 2);
const formattedCushionLow = trim(parseBigNumber(rangeData.low.cushion.price, 18), 2);
const chartData = priceData.map((item: any) => {
return {
...item,
Expand Down Expand Up @@ -128,19 +129,19 @@ const RangeChart = (props: {
<>
<DataRow
title="Upper Wall"
balance={formatCurrency(parseBigNumber(rangeData.wall.high.price, 18), 2, reserveSymbol)}
balance={formatCurrency(parseBigNumber(rangeData.high.wall.price, 18), 2, reserveSymbol)}
/>
<DataRow
title="Upper Cushion"
balance={formatCurrency(parseBigNumber(rangeData.cushion.high.price, 18), 2, reserveSymbol)}
balance={formatCurrency(parseBigNumber(rangeData.high.cushion.price, 18), 2, reserveSymbol)}
/>
<DataRow
title="Lower Cushion"
balance={formatCurrency(parseBigNumber(rangeData.cushion.low.price, 18), 2, reserveSymbol)}
balance={formatCurrency(parseBigNumber(rangeData.low.cushion.price, 18), 2, reserveSymbol)}
/>
<DataRow
title="Lower Wall"
balance={formatCurrency(parseBigNumber(rangeData.wall.low.price, 18), 2, reserveSymbol)}
balance={formatCurrency(parseBigNumber(rangeData.low.wall.price, 18), 2, reserveSymbol)}
/>
<DataRow
title="Upper Capacity"
Expand Down Expand Up @@ -188,9 +189,9 @@ const RangeChart = (props: {
type="number"
domain={[
(dataMin: number) =>
Math.min(dataMin, askPrice, bidPrice, parseBigNumber(rangeData.wall.low.price, 18)) * 0.95,
Math.min(dataMin, askPrice, bidPrice, parseBigNumber(rangeData.low.wall.price, 18)) * 0.95,
(dataMax: number) =>
Math.max(dataMax, askPrice, bidPrice, parseBigNumber(rangeData.wall.low.price, 18)) * 1.05,
Math.max(dataMax, askPrice, bidPrice, parseBigNumber(rangeData.low.wall.price, 18)) * 1.05,
]}
padding={{ top: 20, bottom: 20 }}
tick={false}
Expand Down
32 changes: 17 additions & 15 deletions src/views/Range/__mocks__/mockRangeCalls.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
import { BigNumber } from "ethers";
import { RANGEv1 as OlympusRange } from "src/typechain/Range";
import { RANGEv2 as OlympusRange } from "src/typechain/Range";

export const RangeData: OlympusRange.RangeStruct = {
cushion: {
high: {
price: BigNumber.from("22161077252064087762"),
},
low: {
price: BigNumber.from("18131790478961526351"),
},
spread: BigNumber.from("1000"),
},
high: {
active: true,
lastActive: 1656528651,
capacity: BigNumber.from("605396958336933"), //9 decimals for OHM
market: BigNumber.from("115792089237316195423570985008687907853269984665640564039457584007913129639935"),
threshold: BigNumber.from("6054147227010"),
wall: {
price: BigNumber.from("24175720638615368468"),
spread: BigNumber.from(2000),
},
cushion: {
price: BigNumber.from("22161077252064087762"),
spread: BigNumber.from(1000),
},
},
low: {
active: true,
lastActive: 1656015227,
capacity: BigNumber.from("10000000000000000000000000"), //18 decimals for Reserve
market: BigNumber.from("115792089237316195423570985008687907853269984665640564039457584007913129639935"),
threshold: BigNumber.from("100000000000000000000000"),
},
wall: {
low: { price: BigNumber.from("13117147092410245645") },
high: { price: BigNumber.from("24175720638615368468") },
spread: BigNumber.from(2000),
wall: {
price: BigNumber.from("13117147092410245645"),
spread: BigNumber.from(2000),
},
cushion: {
price: BigNumber.from("18131790478961526351"),
spread: BigNumber.from(1000),
},
},
};

Expand Down
3 changes: 2 additions & 1 deletion src/views/Range/__tests__/Range.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { connectWallet, invalidAddress } from "src/testHelpers";
import { fireEvent, render, screen } from "src/testUtils";
import * as IERC20Factory from "src/typechain/factories/IERC20__factory";
import * as RangeFactory from "src/typechain/factories/Range__factory";
import { RANGEv2 as OlympusRange } from "src/typechain/Range";
import { RangeData } from "src/views/Range/__mocks__/mockRangeCalls";
import { Range } from "src/views/Range/index";
import { beforeEach, describe, expect, it, vi } from "vitest";
Expand All @@ -18,7 +19,7 @@ global.ResizeObserver = require("resize-observer-polyfill");
vi.mock("src/hooks/useContractAllowance");
vi.mock("src/views/Range/RangeChart", () => ({
default: (props: {
rangeData: any;
rangeData: OlympusRange.RangeStructOutput;
currentPrice: number;
bidPrice: number;
askPrice: number;
Expand Down
Loading

0 comments on commit b7d6fca

Please sign in to comment.