Skip to content

Commit

Permalink
Merge pull request #28 from IndexCoop/ek/fix-auction-params
Browse files Browse the repository at this point in the history
[Fix] Change Config values to use BigNumber; Re-align component ordering in arrays
  • Loading branch information
edkim authored Jan 12, 2024
2 parents 095a816 + 7e83c70 commit 7064dfd
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 47 deletions.
4 changes: 2 additions & 2 deletions scripts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export function displayTargetUnits(targetUnits: BigNumber[]) {
console.log("Target Units:");
console.log("Lido: " + utils.formatEther(targetUnits[0]));
console.log("RocketPool: " + utils.formatEther(targetUnits[1]));
console.log("StakeWise: " + utils.formatEther(targetUnits[2]));
console.log("Frax: " + utils.formatEther(targetUnits[3]));
console.log("Frax: " + utils.formatEther(targetUnits[2]));
console.log("Stakewise: " + utils.formatEther(targetUnits[3]));
console.log("Swell: " + utils.formatEther(targetUnits[4]));
console.log("Stader: " + utils.formatEther(targetUnits[5]));
}
Expand Down
5 changes: 3 additions & 2 deletions src/addresses.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { PoolIds, SetTokens } from "./types";

// IMPORTANT: These must be in the same order as dsetH.getComponents(), with new components added to the end
export const stakingTokens: Record<PoolIds, string> = {
Lido: "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0", // wstETH
Rocketpool: "0xae78736Cd615f374D3085123A210448E74Fc6393", // rETH
StakeWise: "0xf1C9acDc66974dFB6dEcB12aA385b9cD01190E38", // osETH
Frax: "0xac3E018457B222d93114458476f3E3416Abbe38F", // sfrxETH
StakeWise: "0xf1C9acDc66974dFB6dEcB12aA385b9cD01190E38", // osETH
Swell: "0xf951E335afb289353dc249e82926178EaC7DEd78", // swETH
Stader: "0xA35b1B31Ce002FBF2058D22F30f95D405200A15b", // ETHx
};

export const stakingTokenRateProviders: Record<PoolIds, string> = {
Lido: "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0", // wstETH
Rocketpool: "0xae78736Cd615f374D3085123A210448E74Fc6393", // rETH
StakeWise: "0x8023518b2192FB5384DAdc596765B3dD1cdFe471", // osETH
Frax: "0xac3E018457B222d93114458476f3E3416Abbe38F", // sfrxETH
StakeWise: "0x8023518b2192FB5384DAdc596765B3dD1cdFe471", // osETH
Swell: "0xf951E335afb289353dc249e82926178EaC7DEd78", // swETH
Stader: "0xcf5EA1b38380f6aF39068375516Daf40Ed70D299", // ETHx
};
Expand Down
26 changes: 14 additions & 12 deletions src/auctionConfig.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
import { BigNumber, ethers } from "ethers";

export type AuctionConfig = {
priceAdapterName: string;
priceAdapterAddress: string;
quoteAsset: string;
bucketSize: number;
slopeForSellComponents: number;
slopeForBuyComponents: number;
slopeForSellComponents: BigNumber;
slopeForBuyComponents: BigNumber;
shouldLockSetToken: boolean;
rebalanceDuration: number;
initialPricePctSellComponents: number;
initialPricePctBuyComponents: number;
maxPriceAsPercentOfMarketPrice: number;
minPriceAsPercentOfMarketPrice: number;
initialPriceAdjustSellComponents: BigNumber;
initialPriceAdjustBuyComponents: BigNumber;
maxPriceAboveMarketPrice: BigNumber;
minPriceBelowMarketPrice: BigNumber;
};

export const DEFAULT_AUCTION_CONFIG: AuctionConfig = {
priceAdapterName: "BoundedStepwiseLinearPriceAdapter",
priceAdapterAddress: "0x237F7BBe0b358415bE84AB6d279D4338C0d026bB",
quoteAsset: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH
bucketSize: 600, // 10 minutes
slopeForSellComponents: 0.00025, // decrease by 0.00025 WETH each bucket
slopeForBuyComponents: 0.000015, // increase by 0.00001 WETH each bucket
slopeForSellComponents: ethers.utils.parseEther("0.00025"), // decrease by 0.00025 WETH each bucket
slopeForBuyComponents: ethers.utils.parseEther("0.0001"), // increase by 0.00001 WETH each bucket
shouldLockSetToken: false,
rebalanceDuration: 86400, // 1 days
initialPricePctSellComponents: 1.01, // 2% above market price
initialPricePctBuyComponents: 0.99, // 2% below market price
maxPriceAsPercentOfMarketPrice: 1.01,
minPriceAsPercentOfMarketPrice: 0.99,
initialPriceAdjustSellComponents: ethers.utils.parseEther("0.01"), // 1% above market price
initialPriceAdjustBuyComponents: ethers.utils.parseEther("0.01"), // 1% below market price
maxPriceAboveMarketPrice: ethers.utils.parseEther("0.01"),
minPriceBelowMarketPrice: ethers.utils.parseEther("0.01"),
};
18 changes: 7 additions & 11 deletions src/auctionRebalanceProposer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BigNumber, Contract, Signer } from "ethers";
import { RatedApiService } from "./ratedApiService";
import { AuctionConfig } from "./auctionConfig";
import { toWei } from "./utils";
import { parseEther, toWei } from "./utils";
import {
SET_TOKEN_ABI,
SWETH_ABI,
Expand Down Expand Up @@ -362,17 +362,13 @@ export class AuctionRebalanceProposer {
isDecreasing: boolean,
): Promise<AuctionExecutionParams> {
const initialPrice = isDecreasing
? priceInWei.mul(toWei(config.initialPricePctSellComponents))
: priceInWei.mul(toWei(config.initialPricePctBuyComponents));
? priceInWei.add(config.initialPriceAdjustSellComponents)
: priceInWei.sub(config.initialPriceAdjustSellComponents);
const slope = isDecreasing
? priceInWei.mul(toWei(config.slopeForSellComponents))
: priceInWei.mul(toWei(config.slopeForBuyComponents));
const maxPrice = priceInWei.mul(
toWei(config.maxPriceAsPercentOfMarketPrice),
);
const minPrice = priceInWei.mul(
toWei(config.minPriceAsPercentOfMarketPrice),
);
? config.slopeForSellComponents
: config.slopeForBuyComponents;
const maxPrice = priceInWei.add(config.maxPriceAboveMarketPrice);
const minPrice = priceInWei.sub(config.minPriceBelowMarketPrice);

const priceAdapterData = await priceAdapter.getEncodedData(
initialPrice,
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { BigNumber } from "ethers";
export enum PoolIds {
Lido = "Lido",
Rocketpool = "Rocketpool",
StakeWise = "StakeWise",
Frax = "Frax",
StakeWise = "StakeWise",
Swell = "Swell",
Stader = "Stader",
}
Expand Down
37 changes: 18 additions & 19 deletions test/proposeRebalance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ describe("Calculate dsETH auction rebalance params", function () {
const rocketPoolEthExchangeRate = utils.parseEther(
"1.094761417991677774",
);
const stakeWiseEthExchangeRate = utils.parseEther(
"1.004232276619834910",
);
const fraxEthExchangeRate = utils.parseEther(
"1.070920905211974170",
);
const stakeWiseEthExchangeRate = utils.parseEther(
"1.004232276619834910",
);
const swellEthExchangeRate = utils.parseEther(
"1.047375758619640637",
);
Expand All @@ -68,8 +68,8 @@ describe("Calculate dsETH auction rebalance params", function () {
const expectedLstEthExchangeRates = [
lidoEthExchangeRate,
rocketPoolEthExchangeRate,
stakeWiseEthExchangeRate,
fraxEthExchangeRate,
stakeWiseEthExchangeRate,
swellEthExchangeRate,
staderEthExchangeRate,
];
Expand Down Expand Up @@ -206,10 +206,10 @@ describe("Calculate dsETH auction rebalance params", function () {
const rocketPoolTargetUnits = utils.parseEther(
"0.137182714490521918",
);
const fraxTargetUnits = utils.parseEther("0.140236634011607713");
const stakeWiseTargetUnits = utils.parseEther(
"0.149549408574172648",
);
const fraxTargetUnits = utils.parseEther("0.140236634011607713");
const swellTargetUnits = utils.parseEther("0.143389172227472443");
const staderTargetUnits = utils.parseEther("0.223325247302630300");

Expand All @@ -219,8 +219,8 @@ describe("Calculate dsETH auction rebalance params", function () {
const expectedTargetUnits = [
lidoTargetUnits,
rocketPoolTargetUnits,
stakeWiseTargetUnits,
fraxTargetUnits,
stakeWiseTargetUnits,
swellTargetUnits,
staderTargetUnits,
];
Expand All @@ -247,49 +247,48 @@ describe("Calculate dsETH auction rebalance params", function () {

const expectedOldComponentsAuctionParams = [
{
targetUnit: utils.parseEther("0.183524947187164250"),
targetUnit: BigNumber.from("183524947187164250"),
priceAdapterName: "BoundedStepwiseLinearPriceAdapter",
priceAdapterConfigData:
"0x0000000000000000000000000000000000dffbc1bd871e47d23ab9f3ff4800000000000000000000000000000000000000000e31690b80b45bbe3d82e9710000000000000000000000000000000000000000000000000000000000000000025800000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000dffbc1bd871e47d23ab9f3ff4800000000000000000000000000000000000000db8c50e9eee5eb26c7810b0bf80000",
"0x000000000000000000000000000000000000000000000000101e622c74c4e3a80000000000000000000000000000000000000000000000000000e35fa931a00000000000000000000000000000000000000000000000000000000000000002580000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000101e622c74c4e3a80000000000000000000000000000000000000000000000000fd754479542e3a8",
},
{
targetUnit: utils.parseEther("0.137182714490521918"),
targetUnit: BigNumber.from("137182714490521918"),
priceAdapterName: "BoundedStepwiseLinearPriceAdapter",
priceAdapterConfigData:
"0x0000000000000000000000000000000000d4f3aa0c691d6e60873e24f04600000000000000000000000000000000000000000d7e753b155c9b049889c47ec000000000000000000000000000000000000000000000000000000000000000025800000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000d4f3aa0c691d6e60873e24f04600000000000000000000000000000000000000d0bc2569f2707def17931788aa0000",
"0x0000000000000000000000000000000000000000000000000f54e6a808f3674e0000000000000000000000000000000000000000000000000000e35fa931a000000000000000000000000000000000000000000000000000000000000000025800000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000f54e6a808f3674e0000000000000000000000000000000000000000000000000f0dd8c32971674e",
},
{
targetUnit: utils.parseEther("0.149549408574172648"),
targetUnit: BigNumber.from("140236634011607713"),
priceAdapterName: "BoundedStepwiseLinearPriceAdapter",
priceAdapterConfigData:
"0x0000000000000000000000000000000000c3579942011da1106dcee0845600000000000000000000000000000000000000000c60cc5f6e131cf6653f4b90c000000000000000000000000000000000000000000000000000000000000000025800000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000c3579942011da1106dcee0845600000000000000000000000000000000000000bf7959642eb7a8036e2b18e71a0000",
"0x0000000000000000000000000000000000000000000000000f0033d61974121a0000000000000000000000000000000000000000000000000000e35fa931a000000000000000000000000000000000000000000000000000000000000000025800000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000f0033d61974121a0000000000000000000000000000000000000000000000000eb925f139f2121a",
},
{
targetUnit: utils.parseEther("0.140236634011607713"),
targetUnit: BigNumber.from("149549408574172648"),
priceAdapterName: "BoundedStepwiseLinearPriceAdapter",
priceAdapterConfigData:
"0x0000000000000000000000000000000000d0507b6078c646dafc8c5df3c200000000000000000000000000000000000000000d333b04979f1129c1ef8c4a4000000000000000000000000000000000000000000000000000000000000000025800000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000d0507b6078c646dafc8c5df3c200000000000000000000000000000000000000cc3078ef0964917deff1821c8e0000",
"0x0000000000000000000000000000000000000000000000000e1346e1c7a9361e0000000000000000000000000000000000000000000000000000e35fa931a000000000000000000000000000000000000000000000000000000000000000025800000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000e1346e1c7a9361e0000000000000000000000000000000000000000000000000dcc38fce827361e",
},
];

const expectedNewComponentsAuctionParams = [
{
targetUnit: utils.parseEther("0.143389172227472443"),
targetUnit: BigNumber.from("143389172227472443"),
priceAdapterName: "BoundedStepwiseLinearPriceAdapter",
priceAdapterConfigData:
"0x0000000000000000000000000000000000c7b33737f44df5ee5f5cf42ad7000000000000000000000000000000000000000000c64bcdd2e60cfe614efdc83000000000000000000000000000000000000000000000000000000000000000025800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000cbbc0207f411799b44d85df2d100000000000000000000000000000000000000c7b33737f44df5ee5f5cf42ad70000",
"0x0000000000000000000000000000000000000000000000000e657fc19720033d00000000000000000000000000000000000000000000000000005af3107a4000000000000000000000000000000000000000000000000000000000000000025800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000eac8da676a2033d0000000000000000000000000000000000000000000000000e657fc19720033d",
},
{
targetUnit: utils.parseEther("0.223325247302630300"),
targetUnit: BigNumber.from("223325247302630300"),
priceAdapterName: "BoundedStepwiseLinearPriceAdapter",
priceAdapterConfigData:
"0x0000000000000000000000000000000000c21c00f4eebf00ab3b2e5b73e4000000000000000000000000000000000000000000c0bea76586bace15b3d8634000000000000000000000000000000000000000000000000000000000000000025800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c607e1f21f8762f1ec370d237c00000000000000000000000000000000000000c21c00f4eebf00ab3b2e5b73e40000",
"0x0000000000000000000000000000000000000000000000000dfd53e06d994acc00000000000000000000000000000000000000000000000000005af3107a4000000000000000000000000000000000000000000000000000000000000000025800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e4461c54d1b4acc0000000000000000000000000000000000000000000000000dfd53e06d994acc",
},
];

it("Should return the correct values", async function () {
const targetUnits = await dsEthProposer.getTargetUnits();

const proposeRebalanceParams =
await dsEthProposer.getProposeRebalanceParams(targetUnits);

Expand Down

0 comments on commit 7064dfd

Please sign in to comment.