Skip to content

Commit

Permalink
Feat/simulator (#150)
Browse files Browse the repository at this point in the history
* Settle

* Settle Option Round story test

* Exercise options

* Update marketAgg setup

* Simulation Run

* Refund all balances

* cleanup

* run multiple rounds

* Export Simulation Results JSON

* Loop rounds

* Add timestamp to file

* checkIgnore

* Read marketData json function

* Mock timestamps
  • Loading branch information
dhruv035 authored Jul 24, 2024
1 parent 2ac6e96 commit 9bd2639
Show file tree
Hide file tree
Showing 18 changed files with 1,116 additions and 66 deletions.
14 changes: 9 additions & 5 deletions scripts/integrationTests/smokeTest1/exerciseOptions.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

import { getOptionRoundFacade } from "../../utils/helpers/setup";
import assert from "assert";
import {
getOptionBidderAccounts,
} from "../../utils/helpers/accounts";
import { getOptionBidderAccounts } from "../../utils/helpers/accounts";
import { TestRunner } from "../../utils/facades/TestRunner";
import { ExerciseOptionArgs } from "../../utils/facades/types";


export const smokeTest = async ({
provider,
Expand All @@ -24,7 +24,11 @@ export const smokeTest = async ({
optionBidderAccounts
);

await optionRoundFacade.exerciseOptionsAll(optionBidderAccounts);
const exerciseOptionsAllArgs = optionBidderAccounts.map((bidder) => {
return { from: bidder } as ExerciseOptionArgs;
});
await optionRoundFacade.exerciseOptionsAll(exerciseOptionsAllArgs);


const ethBalancesAfter = await ethFacade.getBalancesAll(optionBidderAccounts);
const totalPayout = await optionRoundFacade.getTotalPayout();
Expand All @@ -35,7 +39,7 @@ export const smokeTest = async ({
totalPayout,
});

await optionRoundFacade.exerciseOptionsAll(optionBidderAccounts);
await optionRoundFacade.exerciseOptionsAll(exerciseOptionsAllArgs);
const ethBalancesAfterTwice = await ethFacade.getBalancesAll(
optionBidderAccounts
);
Expand Down
5 changes: 0 additions & 5 deletions scripts/katana.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ PORT=$(python3 -c 'import socket; s=socket.socket(); s.bind(("", 0)); print(s.ge

echo "Starting katana on port $PORT"
katana --chain-id SN_SEPOLIA --host 127.0.0.1 --port 5050 --accounts "25" --seed "1" -b 2000 --dev &

npx abi-wan-kanabi --input target/dev/pitch_lake_starknet_Eth.contract_class.json --output scripts/abi/erc20.ts
npx abi-wan-kanabi --input target/dev/pitch_lake_starknet_Vault.contract_class.json --output scripts/abi/vault.ts
npx abi-wan-kanabi --input target/dev/pitch_lake_starknet_OptionRound.contract_class.json --output scripts/abi/optionRound.ts
npx abi-wan-kanabi --input target/dev/pitch_lake_starknet_MarketAggregator.contract_class.json --output scripts/abi/MarketAggregator.ts
# while ! nc -z localhost $PORT; do
# sleep 0.1 # wait for 1/10 of the second before check again
# done
Expand Down
1 change: 0 additions & 1 deletion scripts/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ async function main(environment: string, port?: string) {
environment,
devAccount,
hashes,
constants,
);

const testRunner = new TestRunner(provider, vaultAddress, ethAddress,constants);
Expand Down
46 changes: 46 additions & 0 deletions scripts/simulation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { getAccount, getProvider } from "./utils/helpers/common";
import { declareContracts } from "./utils/deployment/declareContracts";
import { deployContracts } from "./utils/deployment/deployContracts";
import { TestRunner } from "./utils/facades/TestRunner";
import { Constants, MarketData } from "./utils/facades/types";
import { simulationTesting } from "./simulationTests";
import { SimulationParameters } from "./utils/facades/RoundSimulator";
async function main(environment: string, port?: string) {
const provider = getProvider(environment, port);
const devAccount = getAccount(environment, provider);
let hashes = await declareContracts(devAccount);
let { ethAddress, vaultAddress } = await deployContracts(
environment,
devAccount,
hashes
);

//@Note remove this when testRunner refactor by Jithin is finished

const constants: Constants = {
depositAmount: BigInt(10000000000000),
reservePrice: BigInt(4000000000),
strikePrice: BigInt(8000000000),
settlementPrice: BigInt(16000000000),
capLevel: 5000,
};

const testRunner = new TestRunner(
provider,
vaultAddress,
ethAddress,
constants
);


await testRunner.ethFacade.supplyERC20(
devAccount,
provider,
ethAddress,
vaultAddress
);
await simulationTesting(testRunner);
}

main(process.argv[2], process.argv[3]);

170 changes: 170 additions & 0 deletions scripts/simulationData/marketData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
[
{
"starting_timestamp": 1671082204,
"ending_timestamp": 1673760608,
"reserve_price": 1133806091.8973722,
"strike_price": 17635296321.331875,
"settlement_price": 21386087366.87111,
"cap_level": 3000
},
{
"starting_timestamp": 1673760608,
"ending_timestamp": 1676439005,
"reserve_price": 2289497207.1168942,
"strike_price": 21386087366.87111,
"settlement_price": 29034664790.817963,
"cap_level": 3000
},
{
"starting_timestamp": 1676439005,
"ending_timestamp": 1678858200,
"reserve_price": 1279595660.5008752,
"strike_price": 29034664790.817963,
"settlement_price": 38493145481.02064,
"cap_level": 3000
},
{
"starting_timestamp": 1678858200,
"ending_timestamp": 1681536603,
"reserve_price": 875665408.7313896,
"strike_price": 38493145481.02064,
"settlement_price": 25439135433.663445,
"cap_level": 3000
},
{
"starting_timestamp": 1681536603,
"ending_timestamp": 1684128611,
"reserve_price": 2633366765.449701,
"strike_price": 25439135433.663445,
"settlement_price": 74555216167.31648,
"cap_level": 3000
},
{
"starting_timestamp": 1684128611,
"ending_timestamp": 1686807007,
"reserve_price": 1356220491.835023,
"strike_price": 74555216167.31648,
"settlement_price": 20136894952.505894,
"cap_level": 3000
},
{
"starting_timestamp": 1686807007,
"ending_timestamp": 1689399000,
"reserve_price": 1952777064.7434845,
"strike_price": 20136894952.505894,
"settlement_price": 22828235819.938293,
"cap_level": 3000
},
{
"starting_timestamp": 1689399000,
"ending_timestamp": 1692077411,
"reserve_price": 2146702361.445386,
"strike_price": 22828235819.938293,
"settlement_price": 19320316991.848763,
"cap_level": 3000
},
{
"starting_timestamp": 1692077411,
"ending_timestamp": 1694755801,
"reserve_price": 1644783441.6741364,
"strike_price": 19320316991.848763,
"settlement_price": 15696616976.733692,
"cap_level": 3000
},
{
"starting_timestamp": 1694755801,
"ending_timestamp": 1697347808,
"reserve_price": 1467840115.5542483,
"strike_price": 15696616976.733692,
"settlement_price": 7419675169.569965,
"cap_level": 3000
},
{
"starting_timestamp": 1697347808,
"ending_timestamp": 1700026208,
"reserve_price": 554611569.0124147,
"strike_price": 7419675169.569965,
"settlement_price": 37644135519.247475,
"cap_level": 3000
},
{
"starting_timestamp": 1700026208,
"ending_timestamp": 1702618206,
"reserve_price": 3834880492.891962,
"strike_price": 37644135519.247475,
"settlement_price": 39788123292.43376,
"cap_level": 3000
},
{
"starting_timestamp": 1702618206,
"ending_timestamp": 1705296605,
"reserve_price": 5010998700.134231,
"strike_price": 39788123292.43376,
"settlement_price": 26352409279.067184,
"cap_level": 3000
},
{
"starting_timestamp": 1705296605,
"ending_timestamp": 1707975009,
"reserve_price": 2102480779.8673804,
"strike_price": 26352409279.067184,
"settlement_price": 40189317122.14552,
"cap_level": 3000
},
{
"starting_timestamp": 1707975009,
"ending_timestamp": 1710480615,
"reserve_price": 1358716570.77586,
"strike_price": 40189317122.14552,
"settlement_price": 58500408944.033165,
"cap_level": 3000
},
{
"starting_timestamp": 1710480615,
"ending_timestamp": 1713159006,
"reserve_price": 7431323768.285521,
"strike_price": 58500408944.033165,
"settlement_price": 24358911017.007843,
"cap_level": 3000
},
{
"starting_timestamp": 1713159006,
"ending_timestamp": 1715751017,
"reserve_price": 1105329970.4182699,
"strike_price": 24358911017.007843,
"settlement_price": 5681275902.434905,
"cap_level": 3000
},
{
"starting_timestamp": 1715751017,
"ending_timestamp": 1718429397,
"reserve_price": 517729381.0134145,
"strike_price": 5681275902.434905,
"settlement_price": 10706888590.398533,
"cap_level": 3000
},
{
"starting_timestamp": 1718429397,
"ending_timestamp": 1721021409,
"reserve_price": 1008885496.8860922,
"strike_price": 10706888590.398533,
"settlement_price": 3907948839.4517756,
"cap_level": 3000
},
{
"starting_timestamp": 1721021409,
"ending_timestamp": 1721160731,
"reserve_price": 347501891.0070594,
"strike_price": 3907948839.4517756,
"settlement_price": 5191304671.922286,
"cap_level": 3000
},
{
"starting_timestamp": 1721160731,
"ending_timestamp": 1721160731,
"reserve_price": 361402055.1651912,
"strike_price": 5191304671.922286,
"settlement_price": 5191304671.922286,
"cap_level": 3000
}
]
Loading

0 comments on commit 9bd2639

Please sign in to comment.