diff --git a/scripts/integrationTests/smokeTest1/auctionEnd.ts b/scripts/integrationTests/smokeTest1/auctionEnd.ts index df3bc676..96afc790 100644 --- a/scripts/integrationTests/smokeTest1/auctionEnd.ts +++ b/scripts/integrationTests/smokeTest1/auctionEnd.ts @@ -3,16 +3,16 @@ import { getAccount } from "../../utils/helpers/common"; import { getOptionRoundFacade } from "../../utils/helpers/setup"; import assert from "assert"; import { Constants } from "../../utils/facades/types"; -import { - getLiquidityProviderAccounts, - getOptionBidderAccounts, -} from "../../utils/helpers/accounts"; import { TestRunner } from "../../utils/facades/TestRunner"; export const smokeTest = async ({ provider, vaultFacade, constants, + getLPLockedBalanceAll, + getLPUnlockedBalanceAll, + endAuctionBystander, + getLiquidityProviderAccounts, }: TestRunner) => { const optionRoundFacade = await getOptionRoundFacade( provider, @@ -35,15 +35,14 @@ export const smokeTest = async ({ `Expected:Auctioning\nReceived:${state.activeVariant()}` ); - const liquidityProviderAccounts = getLiquidityProviderAccounts(provider, 2); - const optionBidderAccounts = getOptionBidderAccounts(provider, 3); + const liquidityProviderAccounts = getLiquidityProviderAccounts(2); - await vaultFacade.endAuctionBystander(provider); + await endAuctionBystander(); - const lpUnlockedBalances = await vaultFacade.getLPUnlockedBalanceAll( + const lpUnlockedBalances = await getLPUnlockedBalanceAll( liquidityProviderAccounts ); - const lpLockedBalances = await vaultFacade.getLPLockedBalanceAll( + const lpLockedBalances = await getLPLockedBalanceAll( liquidityProviderAccounts ); const totalPremiums = await optionRoundFacade.getTotalPremiums(); diff --git a/scripts/integrationTests/smokeTest1/auctionOpen.ts b/scripts/integrationTests/smokeTest1/auctionOpen.ts index 76f2df8b..d1842a9c 100644 --- a/scripts/integrationTests/smokeTest1/auctionOpen.ts +++ b/scripts/integrationTests/smokeTest1/auctionOpen.ts @@ -1,6 +1,5 @@ import assert from "assert"; import { DepositArgs, WithdrawArgs } from "../../utils/facades/types"; -import { getLiquidityProviderAccounts } from "../../utils/helpers/accounts"; import { TestRunner } from "../../utils/facades/TestRunner"; import { LibraryError } from "starknet"; @@ -11,8 +10,13 @@ export const smokeTest = async ({ vaultFacade: vault, ethFacade: eth, constants: { depositAmount }, + getLPUnlockedBalanceAll, + depositAll, + withdrawAll, + getBalancesAll, + getLiquidityProviderAccounts }: TestRunner) => { - const liquidityProviderAccounts = getLiquidityProviderAccounts(provider, 2); + const liquidityProviderAccounts = getLiquidityProviderAccounts(2); //Approve A for depositing await eth.approval({ @@ -21,9 +25,9 @@ export const smokeTest = async ({ spender: vault.vaultContract.address, }); - const ethBalancesBefore = await eth.getBalancesAll(liquidityProviderAccounts); + const ethBalancesBefore = await getBalancesAll(liquidityProviderAccounts); - const lpUnlockedBalancesBefore = await vault.getLPUnlockedBalanceAll( + const lpUnlockedBalancesBefore = await getLPUnlockedBalanceAll( liquidityProviderAccounts ); //Deposits @@ -43,13 +47,13 @@ export const smokeTest = async ({ }, ]; - await vault.depositAll(depositAllArgs); + await depositAll(depositAllArgs); //Debug - const lpUnlockedBalancesAfter = await vault.getLPUnlockedBalanceAll( + const lpUnlockedBalancesAfter = await getLPUnlockedBalanceAll( liquidityProviderAccounts ); - const ethBalancesAfter = await eth.getBalancesAll(liquidityProviderAccounts); + const ethBalancesAfter = await getBalancesAll(liquidityProviderAccounts); //Asserts //1) Check liquidity for A has increased by depositAmount @@ -78,13 +82,13 @@ export const smokeTest = async ({ amount: BigInt(depositAmount) / BigInt(2), }, ]; - await vault.withdrawAll(withdrawAllData); + await withdrawAll(withdrawAllData); - const lpUnlockedBalancesAfterWithdraw = await vault.getLPUnlockedBalanceAll( + const lpUnlockedBalancesAfterWithdraw = await getLPUnlockedBalanceAll( liquidityProviderAccounts ); - const ethBalancesAfterWithdraw = await eth.getBalancesAll( + const ethBalancesAfterWithdraw = await getBalancesAll( liquidityProviderAccounts ); @@ -99,7 +103,7 @@ export const smokeTest = async ({ assert(error.message !== "Should have reverted"); } - const lpUnlockedBalancesAfterWithdraw2 = await vault.getLPUnlockedBalanceAll( + const lpUnlockedBalancesAfterWithdraw2 = await getLPUnlockedBalanceAll( liquidityProviderAccounts ); //Asserts diff --git a/scripts/integrationTests/smokeTest1/auctionStart.ts b/scripts/integrationTests/smokeTest1/auctionStart.ts index 79d53405..b249932d 100644 --- a/scripts/integrationTests/smokeTest1/auctionStart.ts +++ b/scripts/integrationTests/smokeTest1/auctionStart.ts @@ -4,21 +4,22 @@ import { getOptionRoundFacade } from "../../utils/helpers/setup"; import assert from "assert"; import { ApprovalArgs, - Constants, PlaceBidArgs, } from "../../utils/facades/types"; import { mineNextBlock } from "../../utils/katana"; -import { - getLiquidityProviderAccounts, - getOptionBidderAccounts, -} from "../../utils/helpers/accounts"; import { TestRunner } from "../../utils/facades/TestRunner"; export const smokeTest = async ({ provider, vaultFacade, - ethFacade, constants, + getLPUnlockedBalanceAll, + getLPLockedBalanceAll, + getBalancesAll, + approveAll, + startAuctionBystander, + getLiquidityProviderAccounts, + getOptionBidderAccounts }: TestRunner) => { const optionRoundFacade = await getOptionRoundFacade( provider, @@ -37,20 +38,20 @@ export const smokeTest = async ({ const stateAfter: any = await optionRoundFacade.optionRoundContract.get_state(); - const liquidityProviderAccounts = getLiquidityProviderAccounts(provider, 2); - const optionBidderAccounts = getOptionBidderAccounts(provider, 2); + const liquidityProviderAccounts = getLiquidityProviderAccounts(2); + const optionBidderAccounts = getOptionBidderAccounts(2); assert( stateAfter.activeVariant() === "Open", `Expected:Open\nReceived:${stateAfter.activeVariant()}` ); - await vaultFacade.startAuctionBystander(provider, constants); + await startAuctionBystander(constants); - const unlockedBalances = await vaultFacade.getLPUnlockedBalanceAll( + const unlockedBalances = await getLPUnlockedBalanceAll( liquidityProviderAccounts ); - const lockedBalances = await vaultFacade.getLPLockedBalanceAll( + const lockedBalances = await getLPLockedBalanceAll( liquidityProviderAccounts ); const totalLockedAmount = await vaultFacade.getTotalLocked(); @@ -79,7 +80,7 @@ export const smokeTest = async ({ spender: optionRoundFacade.optionRoundContract.address, }, ]; - await ethFacade.approveAll(approveAllData); + await approveAll(approveAllData); await mineNextBlock(provider.channel.nodeUrl); //Place bids according to story script @@ -87,7 +88,7 @@ export const smokeTest = async ({ const totalOptionAvailable = await optionRoundFacade.getTotalOptionsAvailable(); - const ethBalancesBefore = await ethFacade.getBalancesAll( + const ethBalancesBefore = await getBalancesAll( optionBidderAccounts ); @@ -110,7 +111,7 @@ export const smokeTest = async ({ ]; await optionRoundFacade.placeBidsAll(placeBidsData); - const ethBalancesAfter = await ethFacade.getBalancesAll(optionBidderAccounts); + const ethBalancesAfter = await getBalancesAll(optionBidderAccounts); const bidArrays = await optionRoundFacade.getBidsForAll(optionBidderAccounts); diff --git a/scripts/integrationTests/smokeTest1/exerciseOptions.ts b/scripts/integrationTests/smokeTest1/exerciseOptions.ts index 91a95ae9..0a383a05 100644 --- a/scripts/integrationTests/smokeTest1/exerciseOptions.ts +++ b/scripts/integrationTests/smokeTest1/exerciseOptions.ts @@ -1,7 +1,6 @@ import { getOptionRoundFacade } from "../../utils/helpers/setup"; import assert from "assert"; -import { getOptionBidderAccounts } from "../../utils/helpers/accounts"; import { TestRunner } from "../../utils/facades/TestRunner"; import { ExerciseOptionArgs } from "../../utils/facades/types"; @@ -9,8 +8,8 @@ import { ExerciseOptionArgs } from "../../utils/facades/types"; export const smokeTest = async ({ provider, vaultFacade, - constants: { depositAmount }, - ethFacade, + getBalancesAll, + getOptionBidderAccounts }: TestRunner) => { const optionRoundFacade = await getOptionRoundFacade( provider, @@ -18,9 +17,9 @@ export const smokeTest = async ({ true ); - const optionBidderAccounts = getOptionBidderAccounts(provider, 3); + const optionBidderAccounts = getOptionBidderAccounts(3); - const ethBalancesBefore = await ethFacade.getBalancesAll( + const ethBalancesBefore = await getBalancesAll( optionBidderAccounts ); @@ -30,7 +29,7 @@ export const smokeTest = async ({ await optionRoundFacade.exerciseOptionsAll(exerciseOptionsAllArgs); - const ethBalancesAfter = await ethFacade.getBalancesAll(optionBidderAccounts); + const ethBalancesAfter = await getBalancesAll(optionBidderAccounts); const totalPayout = await optionRoundFacade.getTotalPayout(); checkpoint1({ @@ -40,7 +39,7 @@ export const smokeTest = async ({ }); await optionRoundFacade.exerciseOptionsAll(exerciseOptionsAllArgs); - const ethBalancesAfterTwice = await ethFacade.getBalancesAll( + const ethBalancesAfterTwice = await getBalancesAll( optionBidderAccounts ); diff --git a/scripts/integrationTests/smokeTest1/optionSettle.ts b/scripts/integrationTests/smokeTest1/optionSettle.ts index cdcfae52..4283566b 100644 --- a/scripts/integrationTests/smokeTest1/optionSettle.ts +++ b/scripts/integrationTests/smokeTest1/optionSettle.ts @@ -1,10 +1,6 @@ import { getAccount } from "../../utils/helpers/common"; import { getOptionRoundFacade } from "../../utils/helpers/setup"; import assert from "assert"; -import { - getLiquidityProviderAccounts, - getOptionBidderAccounts, -} from "../../utils/helpers/accounts"; import { TestRunner } from "../../utils/facades/TestRunner"; import { eth, LibraryError } from "starknet"; @@ -13,14 +9,18 @@ export const smokeTest = async ({ vaultFacade, constants: { depositAmount }, ethFacade, + getLPUnlockedBalanceAll, + settleOptionRoundBystander, + getLiquidityProviderAccounts, + getOptionBidderAccounts }: TestRunner) => { const optionRoundFacade = await getOptionRoundFacade( provider, vaultFacade.vaultContract ); - const liquidityProviderAccounts = getLiquidityProviderAccounts(provider, 2); - const optionBidderAccounts = getOptionBidderAccounts(provider, 3); + const liquidityProviderAccounts = getLiquidityProviderAccounts(2); + const devAccount = getAccount("dev", provider); try { @@ -67,13 +67,13 @@ export const smokeTest = async ({ totalPremiums, }); - await vaultFacade.settleOptionRoundBystander(provider); + await settleOptionRoundBystander(); const stateAfter: any = await optionRoundFacade.optionRoundContract.get_state(); - const lpUnlockedBalances = await vaultFacade.getLPUnlockedBalanceAll( + const lpUnlockedBalances = await getLPUnlockedBalanceAll( liquidityProviderAccounts ); const totalPayout = await optionRoundFacade.getTotalPayout(); diff --git a/scripts/integrationTests/smokeTest1/refundBid.ts b/scripts/integrationTests/smokeTest1/refundBid.ts index 1a724e85..fe87a126 100644 --- a/scripts/integrationTests/smokeTest1/refundBid.ts +++ b/scripts/integrationTests/smokeTest1/refundBid.ts @@ -3,16 +3,14 @@ import { getOptionRoundFacade, } from "../../utils/helpers/setup"; import assert from "assert"; -import { - getOptionBidderAccounts, -} from "../../utils/helpers/accounts"; import { TestRunner } from "../../utils/facades/TestRunner"; import { ERC20Facade } from "../../utils/facades/erc20Facade"; export const smokeTest = async ({ provider, vaultFacade: vault, - ethFacade: eth, + getBalancesAll, + getOptionBidderAccounts }: TestRunner) => { const optionRoundFacade = await getOptionRoundFacade( provider, @@ -28,9 +26,9 @@ export const smokeTest = async ({ const totalOptionAvailable = await optionRoundFacade.getTotalOptionsAvailable(); const reservePrice = await optionRoundFacade.getReservePrice(); - const optionBidderAccounts = getOptionBidderAccounts(provider, 3); + const optionBidderAccounts = getOptionBidderAccounts(3); - const balancesBefore = await eth.getBalancesAll(optionBidderAccounts); + const balancesBefore = await getBalancesAll(optionBidderAccounts); try { await optionRoundFacade.refundUnusedBids({ @@ -44,7 +42,7 @@ export const smokeTest = async ({ } catch (err) { console.log("Error while refunding the unused bids", err); } - const balancesAfter = await eth.getBalancesAll(optionBidderAccounts); + const balancesAfter = await getBalancesAll(optionBidderAccounts); checkpoint1({ balancesBefore, diff --git a/scripts/simulationTests/index.ts b/scripts/simulationTests/index.ts index f5dc1713..24dd50ae 100644 --- a/scripts/simulationTests/index.ts +++ b/scripts/simulationTests/index.ts @@ -40,7 +40,7 @@ async function simulationTesting(testRunner: TestRunner) { const simulationSheets = plugMarketData(simulationMarketData,inputSheets); const simulationParams = generateSimulationParams( - testRunner.provider, + testRunner, simulationSheets ); diff --git a/scripts/utils/facades/Backup.ts b/scripts/utils/facades/Backup.ts deleted file mode 100644 index 2003ce19..00000000 --- a/scripts/utils/facades/Backup.ts +++ /dev/null @@ -1,166 +0,0 @@ -import { Account, TypedContractV2 } from "starknet"; -import { - ApprovalArgs, - DepositArgs, - ExerciseOptionArgs, - MarketData, - PlaceBidArgs, - RefundableBidsArgs, - RefundUnusedBidsArgs, -} from "./types"; -import { TestRunner } from "./TestRunner"; -import { getOptionRoundContract, getOptionRoundFacade } from "../helpers/setup"; -import { optionRoundABI } from "../../abi"; -import { OptionRoundFacade } from "./optionRoundFacade"; -import { - getLiquidityProviderAccounts, - getOptionBidderAccounts, -} from "../helpers/accounts"; - -export type SimulationSheet = { - liquidityProviders: Array; - optionBidders: Array; - depositAmounts: Array; - bidAmounts: Array; - bidPrices: Array; - marketData: MarketData; - exerciseOptions: Array; -}; - -export type SimulationParameters = { - depositAllArgs: Array; - bidAllArgs: Array; - refundAllArgs: Array; - lpAccounts?: Array; - bidderAccounts?: Array; - - exerciseOptionsAllArgs: Array; - marketData: MarketData; -}; - -export class RoundSimulator { - public testRunner: TestRunner; - public optionRoundFacade: OptionRoundFacade; - public lpAccounts: Array; - public bidderAccounts: Array; - - constructor( - testRunner: TestRunner, - optionRoundContract: TypedContractV2 - ) { - this.testRunner = testRunner; - this.optionRoundFacade = new OptionRoundFacade(optionRoundContract); - this.lpAccounts = getLiquidityProviderAccounts(testRunner.provider, 5); - this.bidderAccounts = getOptionBidderAccounts(testRunner.provider, 5); - } - - async simulateRound(params: SimulationParameters) { - - //Add market agg setter here or somewhere in openState - const openStateData = await this.simulateOpenState(params.depositAllArgs); - const AuctioningStateData = await this.simulateAuctioningState( - params.bidAllArgs, - params.marketData - ); - const RunningStateData = this.simulateRunningState(params.refundAllArgs); - const settledStateData = await this.simulateSettledState( - params.exerciseOptionsAllArgs - ); - } - - async captureLockedUnlockedBalances() { - const lpLockedBalances = - await this.testRunner.vaultFacade.getLPLockedBalanceAll(this.lpAccounts); - const lpUnlockedBalances = - await this.testRunner.vaultFacade.getLPUnlockedBalanceAll( - this.lpAccounts - ); - return { lpLockedBalances, lpUnlockedBalances }; - } - - async captureEthBalancesLiquidityProviders() { - const ethBalances = await this.testRunner.ethFacade.getBalancesAll( - this.lpAccounts - ); - return ethBalances; - } - - async captureEthBalancesOptionBidders() { - const ethBalances = await this.testRunner.ethFacade.getBalancesAll( - this.bidderAccounts - ); - return ethBalances; - } - async simulateOpenState(depositAllArgs: Array) { - await this.testRunner.vaultFacade.depositAll(depositAllArgs); - const lockedUnlockedBalances = await this.captureLockedUnlockedBalances(); - const ethBalancesBidders = await this.captureEthBalancesOptionBidders(); - return { - lockedUnlockedBalances, - ethBalancesBidders, - }; - //Add market data setter abstraction after Jithin's merge - } - async simulateAuctioningState( - bidAllArgs: Array, - marketData: MarketData - ) { - await this.testRunner.vaultFacade.startAuctionBystander( - this.testRunner.provider, - marketData - ); - - const lockedUnlockedBalances = await this.captureLockedUnlockedBalances(); - const approvalArgs = bidAllArgs.map((arg) => { - const data: ApprovalArgs = { - owner: arg.from, - spender: this.optionRoundFacade.optionRoundContract.address, - amount: BigInt(arg.amount) * BigInt(arg.price), - }; - return data; - }); - await this.testRunner.ethFacade.approveAll(approvalArgs); - - await this.optionRoundFacade.placeBidsAll(bidAllArgs); - const ethBalancesBidders = await this.captureEthBalancesOptionBidders(); - return { - lockedUnlockedBalances, - ethBalancesBidders, - }; - } - async simulateRunningState(refundAllArgs: Array) { - await this.testRunner.vaultFacade.endAuctionBystander( - this.testRunner.provider - ); - - const lpLockedUnlockedBalances = await this.captureLockedUnlockedBalances(); - await this.optionRoundFacade.refundUnusedBidsAll(refundAllArgs); - const ethBalancesBidders = await this.captureEthBalancesOptionBidders(); - return { - lpLockedUnlockedBalances, - ethBalancesBidders, - }; - } - async simulateSettledState(exerciseOptionsArgs: Array) { - console.log("1"); - await this.testRunner.vaultFacade.settleOptionRoundBystander( - this.testRunner.provider - ); - console.log("2"); - - const lpLockedUnlockedBalances = await this.captureLockedUnlockedBalances(); console.log("3"); - await this.optionRoundFacade.exerciseOptionsAll(exerciseOptionsArgs); - const ethBalancesBidders = await this.captureEthBalancesOptionBidders(); - - //Update optionRoundFacade - const optionRoundContract = await getOptionRoundContract( - this.testRunner.provider, - this.testRunner.vaultFacade.vaultContract - ); - this.optionRoundFacade = new OptionRoundFacade(optionRoundContract); - return { - lpLockedUnlockedBalances, - ethBalancesBidders, - }; - } -} diff --git a/scripts/utils/facades/RoundSimulator.ts b/scripts/utils/facades/RoundSimulator.ts index 0a85d615..41b265ea 100644 --- a/scripts/utils/facades/RoundSimulator.ts +++ b/scripts/utils/facades/RoundSimulator.ts @@ -11,10 +11,6 @@ import { TestRunner } from "./TestRunner"; import { getOptionRoundContract, getOptionRoundFacade } from "../helpers/setup"; import { optionRoundABI } from "../../abi"; import { OptionRoundFacade } from "./optionRoundFacade"; -import { - getLiquidityProviderAccounts, - getOptionBidderAccounts, -} from "../helpers/accounts"; export type SimulationSheet = { liquidityProviders: Array; @@ -56,8 +52,8 @@ export class RoundSimulator { ) { this.testRunner = testRunner; this.optionRoundFacade = new OptionRoundFacade(optionRoundContract); - this.lpAccounts = getLiquidityProviderAccounts(testRunner.provider, 5); - this.bidderAccounts = getOptionBidderAccounts(testRunner.provider, 5); + this.lpAccounts = testRunner.getLiquidityProviderAccounts(5); + this.bidderAccounts = testRunner.getOptionBidderAccounts(5); } async simulateRound(params: SimulationParameters) { @@ -107,9 +103,9 @@ export class RoundSimulator { async captureLockedUnlockedBalances() { const lpLockedBalancesBigInt = - await this.testRunner.vaultFacade.getLPLockedBalanceAll(this.lpAccounts); + await this.testRunner.getLPLockedBalanceAll(this.lpAccounts); const lpUnlockedBalancesBigint = - await this.testRunner.vaultFacade.getLPUnlockedBalanceAll( + await this.testRunner.getLPUnlockedBalanceAll( this.lpAccounts ); const lpLockedBalances = lpLockedBalancesBigInt.map((balance) => { @@ -122,7 +118,7 @@ export class RoundSimulator { } async captureEthBalancesLiquidityProviders() { - const ethBalancesBigInt = await this.testRunner.ethFacade.getBalancesAll( + const ethBalancesBigInt = await this.testRunner.getBalancesAll( this.lpAccounts ); const ethBalances = ethBalancesBigInt.map((balance) => { @@ -132,7 +128,7 @@ export class RoundSimulator { } async captureEthBalancesOptionBidders() { - const ethBalancesBigInt = await this.testRunner.ethFacade.getBalancesAll( + const ethBalancesBigInt = await this.testRunner.getBalancesAll( this.bidderAccounts ); const ethBalances = ethBalancesBigInt.map((balance) => { @@ -141,7 +137,7 @@ export class RoundSimulator { return ethBalances; } async simulateOpenState(depositAllArgs: Array) { - await this.testRunner.vaultFacade.depositAll(depositAllArgs); + await this.testRunner.depositAll(depositAllArgs); const lockedUnlockedBalances = await this.captureLockedUnlockedBalances(); const ethBalancesBidders = await this.captureEthBalancesOptionBidders(); return { @@ -154,10 +150,7 @@ export class RoundSimulator { bidAllArgs: Array, marketData: MarketData ) { - await this.testRunner.vaultFacade.startAuctionBystander( - this.testRunner.provider, - marketData - ); + await this.testRunner.startAuctionBystander(marketData); const lockedUnlockedBalances = await this.captureLockedUnlockedBalances(); const approvalArgs = bidAllArgs.map((arg) => { @@ -168,7 +161,7 @@ export class RoundSimulator { }; return data; }); - await this.testRunner.ethFacade.approveAll(approvalArgs); + await this.testRunner.approveAll(approvalArgs); await this.optionRoundFacade.placeBidsAll(bidAllArgs); const ethBalancesBidders = await this.captureEthBalancesOptionBidders(); @@ -178,9 +171,7 @@ export class RoundSimulator { }; } async simulateRunningState(refundAllArgs: Array) { - const data = await this.testRunner.vaultFacade.endAuctionBystander( - this.testRunner.provider - ); + const data = await this.testRunner.endAuctionBystander(); const lockedUnlockedBalances = await this.captureLockedUnlockedBalances(); await this.optionRoundFacade.refundUnusedBidsAll(refundAllArgs); @@ -192,9 +183,7 @@ export class RoundSimulator { } async simulateSettledState(exerciseOptionsArgs: Array) { const data = await this.optionRoundFacade.optionRoundContract.get_state(); - await this.testRunner.vaultFacade.settleOptionRoundBystander( - this.testRunner.provider - ); + await this.testRunner.settleOptionRoundBystander(); const lockedUnlockedBalances = await this.captureLockedUnlockedBalances(); console.log("3"); diff --git a/scripts/utils/facades/TestRunner.ts b/scripts/utils/facades/TestRunner.ts index 019d3a34..5bf8a15a 100644 --- a/scripts/utils/facades/TestRunner.ts +++ b/scripts/utils/facades/TestRunner.ts @@ -1,7 +1,12 @@ import { Account, Provider } from "starknet"; import { ERC20Facade } from "./erc20Facade"; import { VaultFacade } from "./vaultFacade"; -import { Constants } from "./types"; +import { ApprovalArgs, Constants, DepositArgs, MarketData, WithdrawArgs } from "./types"; +import { getOptionRoundContract } from "../helpers/setup"; +import { getNow, timeskipNextBlock } from "../katana"; +import { getAccount, getCustomAccount, stringToHex } from "../helpers/common"; +import { MarketAggregatorFacade } from "./marketAggregatorFacade"; +import { liquidityProviders, optionBidders } from "../constants"; export type ResultSheet = { accounts: Array; @@ -33,7 +38,7 @@ export class TestRunner { this.provider = provider; } - async testResults(accounts:Array,params: Array, method: Methods) { + testResults = async (accounts:Array,params: Array, method: Methods) => { const before:Map> = new Map; @@ -45,13 +50,13 @@ export class TestRunner { switch (param){ case StoragePoints.lpLocked: { - const res = await this.vaultFacade.getLPLockedBalanceAll(accounts); + const res = await this.getLPLockedBalanceAll(accounts); resultSheet.before.set(StoragePoints.lpLocked,res); break; } case StoragePoints.lpUnlocked: { - const res = await this.vaultFacade.getLPUnlockedBalanceAll(accounts); + const res = await this.getLPUnlockedBalanceAll(accounts); resultSheet.before.set(StoragePoints.lpUnlocked,res); break; } @@ -70,6 +75,176 @@ export class TestRunner { } } } + + getLPUnlockedBalanceAll = async (accounts: Array) => { + const balances = await Promise.all( + accounts.map(async (account: Account) => { + const res = await this.vaultFacade.getLPUnlockedBalance(account.address); + return res; + }) + ); + return balances; + } + + getLPLockedBalanceAll = async (accounts: Array) => { + const balances = await Promise.all( + accounts.map(async (account: Account) => { + const res = await this.vaultFacade.getLPLockedBalance(account.address); + return res; + }) + ); + return balances; + } + + depositAll = async (depositData: Array) => { + for (const depositArgs of depositData) { + await this.vaultFacade.deposit(depositArgs); + } + } + + withdrawAll = async (withdrawData: Array) => { + for (const withdrawArgs of withdrawData) { + await this.vaultFacade.withdraw(withdrawArgs); + } + } + + getBalancesAll = async (accounts: Array) => { + const balances = await Promise.all( + accounts.map(async (account: Account) => { + const balance = await this.ethFacade.getBalance(account.address); + return balance; + }) + ); + return balances; + } + + approveAll = async (approveData: Array) => { + for (const approvalArgs of approveData) { + await this.ethFacade.approval(approvalArgs); + } + } + + accelerateToAuctioning = async () => { + const optionRoundContract = await getOptionRoundContract( + this.provider, + this.vaultFacade.vaultContract + ); + const currentTime = await getNow(this.provider); + const auctionStartDate = await optionRoundContract.get_auction_start_date(); + + console.log("currentTime:",currentTime,"\nauctionStartDate:",auctionStartDate);; + await timeskipNextBlock( + Number(auctionStartDate) - Number(currentTime), + this.provider.channel.nodeUrl + ); + } + + accelerateToRunning = async () => { + const optionRoundContract = await getOptionRoundContract( + this.provider, + this.vaultFacade.vaultContract + ); + + const currentTime = await getNow(this.provider); + const auctionEndDate = await optionRoundContract.get_auction_end_date(); + + await timeskipNextBlock( + Number(auctionEndDate) - Number(currentTime)+1, + this.provider.channel.nodeUrl + ); + } + + accelerateToSettled = async () => { + const optionRoundContract = await getOptionRoundContract( + this.provider, + this.vaultFacade.vaultContract + ); + + const currentTime = await getNow(this.provider); + const optionSettleDate = + await optionRoundContract.get_option_settlement_date(); + + await timeskipNextBlock( + Number(optionSettleDate) - Number(currentTime), + this.provider.channel.nodeUrl + ); + } + + //@note Only works for katana dev instance with a --dev flag + startAuctionBystander = async (marketData: MarketData) => { + console.log("MARKETDATA:",marketData); + const devAccount = getAccount("dev", this.provider); + //Set market aggregator reserve_price + const marketAggregatorString = + await this.vaultFacade.vaultContract.get_market_aggregator(); + const marketAggregatorAddress = "0x" + stringToHex(marketAggregatorString); + const marketAggFacade = new MarketAggregatorFacade( + marketAggregatorAddress, + this.provider + ); + const optionRound = await getOptionRoundContract( + this.provider, + this.vaultFacade.vaultContract + ); + const startDate = await optionRound.get_auction_start_date(); + const settleDate = await optionRound.get_option_settlement_date(); + + await marketAggFacade.setMarketParameters( + devAccount, + startDate, + settleDate, + marketData + ) + + await this.vaultFacade.vaultContract.update_round_params(); + + await this.accelerateToAuctioning(); + + this.vaultFacade.vaultContract.connect(devAccount); + await this.vaultFacade.vaultContract.start_auction(); + } + + endAuctionBystander = async () => { + const devAccount = getAccount("dev", this.provider); + await this.accelerateToRunning(); + await this.vaultFacade.endAuction(devAccount); + } + + settleOptionRoundBystander = async () => { + await this.accelerateToSettled(); + const devAccount = getAccount("dev", this.provider); + await this.vaultFacade.settleOptionRound(devAccount); + } + + getLiquidityProviderAccounts = ( + length: number + ) => { + const liquidityProviderAccounts: Array = []; + for (let i = 0; i < length; i++) { + liquidityProviderAccounts.push( + getCustomAccount( + this.provider, + liquidityProviders[i].account, + liquidityProviders[i].privateKey + ) + ); + } + return liquidityProviderAccounts; + }; + + getOptionBidderAccounts = (length: number) => { + const optionBidderAccounts: Array = []; + for (let i = 0; i < length; i++) { + optionBidderAccounts.push( + getCustomAccount( + this.provider, + optionBidders[i].account, + optionBidders[i].privateKey + ) + ); + } + return optionBidderAccounts; + }; } enum StoragePoints { diff --git a/scripts/utils/facades/erc20Facade.ts b/scripts/utils/facades/erc20Facade.ts index 5a7e4103..6759008e 100644 --- a/scripts/utils/facades/erc20Facade.ts +++ b/scripts/utils/facades/erc20Facade.ts @@ -20,15 +20,6 @@ export class ERC20Facade { ); } - async getBalancesAll(accounts: Array) { - const balances = await Promise.all( - accounts.map(async (account: Account) => { - const balance = await this.getBalance(account.address); - return balance; - }) - ); - return balances; - } async getBalance(account: string) { const balance = await this.erc20Contract.balance_of(account); @@ -72,12 +63,6 @@ export class ERC20Facade { } } - async approveAll(approveData: Array) { - for (const approvalArgs of approveData) { - await this.approval(approvalArgs); - } - } - async supplyERC20( devAccount: Account, provider: Provider, diff --git a/scripts/utils/facades/marketAggregatorFacade.ts b/scripts/utils/facades/marketAggregatorFacade.ts index 243efdaa..d6086000 100644 --- a/scripts/utils/facades/marketAggregatorFacade.ts +++ b/scripts/utils/facades/marketAggregatorFacade.ts @@ -1,5 +1,6 @@ import { Account, Contract, Provider, TypedContractV2 } from "starknet"; import { marketAggregatorABI } from "../../abi"; +import { MarketData } from "./types"; export class MarketAggregatorFacade { marketAggregatorContract: TypedContractV2; @@ -64,4 +65,38 @@ export class MarketAggregatorFacade { reservePrice ); } + + async setMarketParameters( + devAccount: Account, + startDate: number | bigint, + settleDate: number | bigint, + marketData: MarketData + ) { + await this.setReservePrice( + devAccount, + startDate, + settleDate, + marketData.reservePrice + + ); + await this.setCapLevel( + devAccount, + startDate, + settleDate, + marketData.capLevel + ); + + await this.setStrikePrice( + devAccount, + startDate, + settleDate, + marketData.strikePrice + ); + await this.setTWAP( + devAccount, + startDate, + settleDate, + marketData.settlementPrice + ); + } } diff --git a/scripts/utils/facades/optionRoundFacade.ts b/scripts/utils/facades/optionRoundFacade.ts index 64e61206..d6fc9ff6 100644 --- a/scripts/utils/facades/optionRoundFacade.ts +++ b/scripts/utils/facades/optionRoundFacade.ts @@ -11,6 +11,7 @@ import { UpdateBidArgs, } from "./types"; import { optionRoundABI } from "../../abi"; +import { convertToBigInt } from "../helpers/common"; export class OptionRoundFacade { optionRoundContract: TypedContractV2; @@ -22,38 +23,23 @@ export class OptionRoundFacade { async getRoundId() { const res = await this.optionRoundContract.get_round_id(); - if (typeof res !== "bigint" && typeof res !== "number") { - const data = new CairoUint256(res); - return data.toBigInt(); - } else return res; + return convertToBigInt(res); } async getTotalPayout() { const res = await this.optionRoundContract.total_payout(); - if (typeof res !== "bigint" && typeof res !== "number") { - const data = new CairoUint256(res); - return data.toBigInt(); - } else return res; + return convertToBigInt(res); } async getTotalPremiums() { const res = await this.optionRoundContract.total_premiums(); - if (typeof res !== "bigint" && typeof res !== "number") { - const data = new CairoUint256(res); - return data.toBigInt(); - } else return res; + return convertToBigInt(res); } async getTotalOptionsAvailable() { const res = await this.optionRoundContract.get_total_options_available(); - if (typeof res !== "bigint" && typeof res !== "number") { - const data = new CairoUint256(res); - return data.toBigInt(); - } else return res; + return convertToBigInt(res); } async getReservePrice() { const res = await this.optionRoundContract.get_reserve_price(); - if (typeof res !== "bigint" && typeof res !== "number") { - const data = new CairoUint256(res); - return data.toBigInt(); - } else return res; + return convertToBigInt(res); } async getBidsFor(address: string) { const res = await this.optionRoundContract.get_bids_for(address); @@ -129,10 +115,7 @@ export class OptionRoundFacade { const res = await this.optionRoundContract.get_refundable_bids_for( optionBuyer ); - if (typeof res !== "bigint" && typeof res !== "number") { - const data = new CairoUint256(res); - return data.toBigInt(); - } else return res; + return convertToBigInt(res); } catch (err) { console.log(err); } @@ -157,10 +140,7 @@ export class OptionRoundFacade { const res = await this.optionRoundContract.get_total_options_balance_for( optionBuyer ); - if (typeof res !== "bigint" && typeof res !== "number") { - const data = new CairoUint256(res); - return data.toBigInt(); - } else return res; + return convertToBigInt(res); } catch (err) { console.log(err); } @@ -171,10 +151,7 @@ export class OptionRoundFacade { const res = await this.optionRoundContract.get_payout_balance_for( optionBuyer ); - if (typeof res !== "bigint" && typeof res !== "number") { - const data = new CairoUint256(res); - return data.toBigInt(); - } else return res; + return convertToBigInt(res); } catch (err) { console.log(err); } @@ -185,10 +162,7 @@ export class OptionRoundFacade { const res = await this.optionRoundContract.get_tokenizable_options_for( optionBuyer ); - if (typeof res !== "bigint" && typeof res !== "number") { - const data = new CairoUint256(res); - return data.toBigInt(); - } else return res; + return convertToBigInt(res); } catch (err) { console.log(err); } diff --git a/scripts/utils/facades/vaultFacade.ts b/scripts/utils/facades/vaultFacade.ts index 0950efa6..382f88a9 100644 --- a/scripts/utils/facades/vaultFacade.ts +++ b/scripts/utils/facades/vaultFacade.ts @@ -1,18 +1,12 @@ import { Account, - CairoUint256, Contract, Provider, TypedContractV2, } from "starknet"; import { optionRoundABI, vaultABI } from "../../abi"; import { DepositArgs, MarketData, WithdrawArgs } from "./types"; -import { - accelerateToAuctioning, - accelerateToRunning, - accelerateToSettled, -} from "../helpers/accelerators"; -import { getAccount, stringToHex } from "../helpers/common"; +import { convertToBigInt, getAccount, stringToHex } from "../helpers/common"; import { MarketAggregatorFacade } from "./marketAggregatorFacade"; import { getOptionRoundContract } from "../helpers/setup"; @@ -38,58 +32,24 @@ export class VaultFacade { async getTotalLocked() { const res = await this.vaultContract.get_total_locked_balance(); - if (typeof res !== "bigint" && typeof res !== "number") { - const data = new CairoUint256(res); - return data.toBigInt(); - } - return res; + return convertToBigInt(res); } async getTotalUnLocked() { const res = await this.vaultContract.get_total_unlocked_balance(); - if (typeof res !== "bigint" && typeof res !== "number") { - const data = new CairoUint256(res); - return data.toBigInt(); - } - return res; + return convertToBigInt(res); } async getLPLockedBalance(address: string) { const res = await this.vaultContract.get_lp_locked_balance(address); - if (typeof res !== "bigint" && typeof res !== "number") { - const data = new CairoUint256(res); - return data.toBigInt(); - } - return res; - } - async getLPLockedBalanceAll(accounts: Array) { - const balances = await Promise.all( - accounts.map(async (account: Account) => { - const res = await this.getLPLockedBalance(account.address); - return res; - }) - ); - return balances; + return convertToBigInt(res); } async getLPUnlockedBalance(address: string) { const res = await this.vaultContract.get_lp_unlocked_balance(address); - if (typeof res !== "bigint" && typeof res !== "number") { - const data = new CairoUint256(res); - return data.toBigInt(); - } - return res; + return convertToBigInt(res); } - async getLPUnlockedBalanceAll(accounts: Array) { - const balances = await Promise.all( - accounts.map(async (account: Account) => { - const res = await this.getLPUnlockedBalance(account.address); - return res; - }) - ); - return balances; - } async withdraw({ account, amount }: WithdrawArgs) { this.vaultContract.connect(account); await this.vaultContract.withdraw_liquidity(amount); @@ -108,95 +68,19 @@ export class VaultFacade { } } - async depositAll(depositData: Array) { - for (const depositArgs of depositData) { - await this.deposit(depositArgs); - } - } - - async withdrawAll(withdrawData: Array) { - for (const withdrawArgs of withdrawData) { - await this.withdraw(withdrawArgs); - } - } - //State Transitions async startAuction(account: Account) { this.vaultContract.connect(account); await this.vaultContract.start_auction(); } - //@note Only works for katana dev instance with a --dev flag - async startAuctionBystander(provider: Provider, marketData: MarketData) { - console.log("MARKETDATA:",marketData); - const devAccount = getAccount("dev", provider); - //Set market aggregator reserve_price - const marketAggregatorString = - await this.vaultContract.get_market_aggregator(); - const marketAggregatorAddress = "0x" + stringToHex(marketAggregatorString); - const marketAggFacade = new MarketAggregatorFacade( - marketAggregatorAddress, - provider - ); - const optionRound = await getOptionRoundContract( - provider, - this.vaultContract - ); - const startDate = await optionRound.get_auction_start_date(); - const settleDate = await optionRound.get_option_settlement_date(); - await marketAggFacade.setReservePrice( - devAccount, - startDate, - settleDate, - marketData.reservePrice - - ); - await marketAggFacade.setCapLevel( - devAccount, - startDate, - settleDate, - marketData.capLevel - ); - - await marketAggFacade.setStrikePrice( - devAccount, - startDate, - settleDate, - marketData.strikePrice - ); - await marketAggFacade.setTWAP( - devAccount, - startDate, - settleDate, - marketData.settlementPrice - ); - await this.vaultContract.update_round_params(); - - await accelerateToAuctioning(provider, this.vaultContract); - - this.vaultContract.connect(devAccount); - await this.vaultContract.start_auction(); - } - async endAuction(account: Account) { this.vaultContract.connect(account); const res = await this.vaultContract.end_auction(); } - async endAuctionBystander(provider: Provider) { - const devAccount = getAccount("dev", provider); - await accelerateToRunning(provider, this.vaultContract); - await this.endAuction(devAccount); - } - async settleOptionRound(account: Account) { this.vaultContract.connect(account); await this.vaultContract.settle_option_round(); } - - async settleOptionRoundBystander(provider: Provider) { - await accelerateToSettled(provider, this.vaultContract); - const devAccount = getAccount("dev", provider); - await this.settleOptionRound(devAccount); - } } diff --git a/scripts/utils/helpers/accelerators.ts b/scripts/utils/helpers/accelerators.ts deleted file mode 100644 index f8e0b9cd..00000000 --- a/scripts/utils/helpers/accelerators.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { Provider, TypedContractV2 } from "starknet"; -import { getAccount } from "./common"; -import { vaultABI } from "../../abi"; -import { getNow, timeskipNextBlock } from "../katana"; -import { getOptionRoundContract } from "./setup"; - -async function accelerateToAuctioning( - provider: Provider, - vaultContract: TypedContractV2 -) { - const optionRoundContract = await getOptionRoundContract( - provider, - vaultContract - ); - const currentTime = await getNow(provider); - const auctionStartDate = await optionRoundContract.get_auction_start_date(); - - console.log("currentTime:",currentTime,"\nauctionStartDate:",auctionStartDate);; - await timeskipNextBlock( - Number(auctionStartDate) - Number(currentTime), - provider.channel.nodeUrl - ); - -} - -async function accelerateToRunning( - provider: Provider, - vaultContract: TypedContractV2 -) { - const optionRoundContract = await getOptionRoundContract( - provider, - vaultContract - ); - - const currentTime = await getNow(provider); - const auctionEndDate = await optionRoundContract.get_auction_end_date(); - - await timeskipNextBlock( - Number(auctionEndDate) - Number(currentTime)+1, - provider.channel.nodeUrl - ); -} - -async function accelerateToSettled( - provider: Provider, - vaultContract: TypedContractV2 -) { - const optionRoundContract = await getOptionRoundContract( - provider, - vaultContract - ); - - const currentTime = await getNow(provider); - const optionSettleDate = - await optionRoundContract.get_option_settlement_date(); - - await timeskipNextBlock( - Number(optionSettleDate) - Number(currentTime), - provider.channel.nodeUrl - ); - -} -export { accelerateToAuctioning, accelerateToRunning, accelerateToSettled }; diff --git a/scripts/utils/helpers/accounts.ts b/scripts/utils/helpers/accounts.ts deleted file mode 100644 index cc2a4539..00000000 --- a/scripts/utils/helpers/accounts.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { Account, Provider } from "starknet"; -import { liquidityProviders, optionBidders } from "../constants"; -import { getCustomAccount } from "./common"; - -export const getLiquidityProviderAccounts = ( - provider: Provider, - length: number -) => { - const liquidityProviderAccounts: Array = []; - for (let i = 0; i < length; i++) { - liquidityProviderAccounts.push( - getCustomAccount( - provider, - liquidityProviders[i].account, - liquidityProviders[i].privateKey - ) - ); - } - return liquidityProviderAccounts; -}; - -export const getOptionBidderAccounts = (provider: Provider, length: number) => { - const optionBidderAccounts: Array = []; - for (let i = 0; i < length; i++) { - optionBidderAccounts.push( - getCustomAccount( - provider, - optionBidders[i].account, - optionBidders[i].privateKey - ) - ); - } - return optionBidderAccounts; -}; diff --git a/scripts/utils/helpers/common.ts b/scripts/utils/helpers/common.ts index 823986f4..da7e045f 100644 --- a/scripts/utils/helpers/common.ts +++ b/scripts/utils/helpers/common.ts @@ -1,4 +1,4 @@ -import { Account, Contract, Provider, RpcProvider } from "starknet"; +import { Account, CairoUint256, Contract, Provider, RpcProvider, Uint256 } from "starknet"; import { nodeUrlMapping, accountDetailsMapping } from "../constants"; function getProvider(environment: string, port?: string) { @@ -80,6 +80,14 @@ function stringToHex(decimalString: string): string { return num.toString(16); } +function convertToBigInt(quantity: number | bigint | Uint256) { + if (typeof quantity !== "bigint" && typeof quantity !== "number") { + const res = new CairoUint256(quantity); + quantity = res.toBigInt(); + } + return quantity; +} + -export { getProvider, getAccount, getContract, getCustomAccount, stringToHex }; +export { getProvider, getAccount, getContract, getCustomAccount, stringToHex, convertToBigInt }; diff --git a/scripts/utils/helpers/setup.ts b/scripts/utils/helpers/setup.ts index 42b9d371..53c39e2d 100644 --- a/scripts/utils/helpers/setup.ts +++ b/scripts/utils/helpers/setup.ts @@ -3,8 +3,8 @@ import { stringToHex } from "./common"; import { erc20ABI, optionRoundABI, vaultABI } from "../../abi"; import { OptionRoundFacade } from "../facades/optionRoundFacade"; import { SimulationParameters, SimulationSheet } from "../facades/RoundSimulator"; -import { getLiquidityProviderAccounts, getOptionBidderAccounts } from "./accounts"; import { DepositArgs, ExerciseOptionArgs, PlaceBidArgs, RefundUnusedBidsArgs } from "../facades/types"; +import { TestRunner } from "../facades/TestRunner"; export const getOptionRoundFacade = async ( provider: Provider, @@ -61,11 +61,11 @@ export const getOptionRoundContract = async ( }; export const generateSimulationParams = ( - provider: Provider, + { getLiquidityProviderAccounts, getOptionBidderAccounts }: TestRunner, simulationSheets: Array ) => { - const liquidityProviderAccounts = getLiquidityProviderAccounts(provider, 5); - const optionBidderAccounts = getOptionBidderAccounts(provider, 5); + const liquidityProviderAccounts = getLiquidityProviderAccounts(5); + const optionBidderAccounts = getOptionBidderAccounts(5); const simulationParams = simulationSheets.map((simulationSheet) => { const depositAllArgs = simulationSheet.liquidityProviders.map( (provider, index) => {