Skip to content

Commit

Permalink
fix auction priceConfig calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
edkim committed Jan 11, 2024
1 parent 095a816 commit d87356f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
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

0 comments on commit d87356f

Please sign in to comment.