Skip to content

Commit

Permalink
Update marketAgg setup
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruv035 committed Jul 22, 2024
1 parent 621e1c6 commit d7c7130
Show file tree
Hide file tree
Showing 18 changed files with 531 additions and 995 deletions.
1,122 changes: 217 additions & 905 deletions scripts/abi/erc20.ts

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion scripts/abi/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { ABI as vaultABI} from "./vault"
export { ABI as erc20ABI} from "./erc20"
export { ABI as optionRoundABI} from "./optionRound"
export { ABI as optionRoundABI} from "./optionRound"
export {ABI as marketAggregatorABI} from "./marketAggregator"
44 changes: 20 additions & 24 deletions scripts/integrationTests/smokeTest1/auctionOpen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const smokeTest = async ({
//Approve A for depositing
await eth.approval({
owner: liquidityProviderAccounts[0],
amount: 1000000,
amount: BigInt(100)*BigInt(depositAmount),
spender: vault.vaultContract.address,
});

Expand Down Expand Up @@ -71,11 +71,11 @@ export const smokeTest = async ({
const withdrawAllData: Array<WithdrawArgs> = [
{
account: liquidityProviderAccounts[0],
amount: depositAmount / 2,
amount: BigInt(depositAmount) / BigInt(2),
},
{
account: liquidityProviderAccounts[1],
amount: depositAmount / 2,
amount: BigInt(depositAmount) / BigInt(2),
},
];
await vault.withdrawAll(withdrawAllData);
Expand All @@ -91,7 +91,7 @@ export const smokeTest = async ({
try {
await vault.withdraw({
account: liquidityProviderAccounts[1],
amount: depositAmount / 2 + 1,
amount: BigInt(depositAmount) / BigInt(2) + BigInt(1),
});
throw Error("Should have reverted");
} catch (err: unknown) {
Expand All @@ -102,10 +102,6 @@ export const smokeTest = async ({
const lpUnlockedBalancesAfterWithdraw2 = await vault.getLPUnlockedBalanceAll(
liquidityProviderAccounts
);
console.log(
"lpUnlockedBalancesAfterWithdraw2:",
lpUnlockedBalancesAfterWithdraw2
);
//Asserts
//1) Check liquidity for A & B has decreased by depositAmount/2
//2) Check balance for A & B has increased by depositAmount/2
Expand All @@ -130,21 +126,21 @@ function checkpoint1({
lpUnlockedBalancesAfter: Array<number | bigint>;
ethBalancesBefore: Array<number | bigint>;
ethBalancesAfter: Array<number | bigint>;
depositAmount: number;
depositAmount: number|bigint;
}) {
assert(
Number(lpUnlockedBalancesAfter[0]) ===
Number(lpUnlockedBalancesBefore[0]) + depositAmount,
BigInt(lpUnlockedBalancesAfter[0]) ===
BigInt(lpUnlockedBalancesBefore[0]) + BigInt(depositAmount),
"liquidity A mismatch"
);
assert(
Number(lpUnlockedBalancesAfter[1]) ===
Number(lpUnlockedBalancesBefore[1]) + depositAmount,
BigInt(lpUnlockedBalancesAfter[1]) ===
BigInt(lpUnlockedBalancesBefore[1]) + BigInt(depositAmount),
"liquidity B mismatch"
);
assert(
Number(ethBalancesBefore[0]) ===
Number(ethBalancesAfter[0]) + 2 * depositAmount,
BigInt(ethBalancesBefore[0]) ===
BigInt(ethBalancesAfter[0]) + BigInt(2) * BigInt(depositAmount),
"Eth balance for a mismatch"
);
}
Expand All @@ -159,26 +155,26 @@ function checkpoint2({
lpUnlockedBalancesBefore: Array<number | bigint>;
ethBalancesAfter: Array<number | bigint>;
ethBalancesBefore: Array<number | bigint>;
depositAmount: number;
depositAmount: number|bigint;
}) {
assert(
Number(lpUnlockedBalancesBefore[0]) ==
Number(lpUnlockedBalancesAfter[0]) + depositAmount / 2,
BigInt(lpUnlockedBalancesBefore[0]) ==
BigInt(lpUnlockedBalancesAfter[0]) + BigInt(depositAmount) / BigInt(2),
"Mismatch A liquidity"
);
assert(
Number(lpUnlockedBalancesBefore[1]) ==
Number(lpUnlockedBalancesAfter[1]) + depositAmount / 2,
BigInt(lpUnlockedBalancesBefore[1]) ==
BigInt(lpUnlockedBalancesAfter[1]) + BigInt(depositAmount) / BigInt(2),
"Mismatch B liquidity"
);
assert(
Number(ethBalancesBefore[0]) ==
Number(ethBalancesAfter[0]) - depositAmount / 2,
BigInt(ethBalancesBefore[0]) ==
BigInt(ethBalancesAfter[0]) - BigInt(depositAmount) / BigInt(2),
"Mismatch A balance"
);
assert(
Number(ethBalancesBefore[1]) ==
Number(ethBalancesAfter[1]) - depositAmount / 2,
BigInt(ethBalancesBefore[1]) ==
BigInt(ethBalancesAfter[1]) - BigInt(depositAmount) / BigInt(2),
"Mismatch B balance"
);
}
34 changes: 18 additions & 16 deletions scripts/integrationTests/smokeTest1/auctionStart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ export const smokeTest = async ({
const devAccount = getAccount("dev", provider);
try {
await vaultFacade.startAuction(devAccount);
throw Error("Should have reverted")
throw Error("Should have reverted");
} catch (err) {
const error = err as LibraryError
assert(error.message!=="Should have reverted",error.message)
const error = err as LibraryError;
assert(error.message !== "Should have reverted", error.message);
//Failure expected when contracts are changed to revert
}

Expand All @@ -45,7 +45,7 @@ export const smokeTest = async ({
`Expected:Open\nReceived:${stateAfter.activeVariant()}`
);

await vaultFacade.startAuctionBystander(provider);
await vaultFacade.startAuctionBystander(provider, constants);

const unlockedBalances = await vaultFacade.getLPUnlockedBalanceAll(
liquidityProviderAccounts
Expand All @@ -62,7 +62,7 @@ export const smokeTest = async ({
lockedBalances,
totalLockedAmount,
totalUnlockedAmount,
constants,
depositAmount: constants.depositAmount,
});

//Approve OptionBidders
Expand Down Expand Up @@ -128,13 +128,13 @@ async function checkpoint1({
unlockedBalances,
totalLockedAmount,
totalUnlockedAmount,
constants,
depositAmount,
}: {
lockedBalances: Array<bigint | number>;
unlockedBalances: Array<bigint | number>;
totalLockedAmount: bigint | number | Uint256 | undefined;
totalUnlockedAmount: bigint | number | Uint256 | undefined;
constants: Constants;
totalLockedAmount: bigint | number;
totalUnlockedAmount: bigint | number;
depositAmount: number | bigint;
}) {
assert(
Number(unlockedBalances[0]) === 0,
Expand All @@ -145,24 +145,26 @@ async function checkpoint1({
`UnlockedBalanceB 0 expected, found ${unlockedBalances[1]}`
);
assert(
Number(lockedBalances[0]) === constants.depositAmount / 2,
`LockedBalanceA ${constants.depositAmount / 2} expected, found ${
BigInt(lockedBalances[0]) === BigInt(depositAmount) / BigInt(2),
`LockedBalanceA ${BigInt(depositAmount) / BigInt(2)} expected, found ${
lockedBalances[0]
}`
);
assert(
Number(lockedBalances[1]) === constants.depositAmount / 2,
`LockedBalanceB ${constants.depositAmount / 2} expected, found ${
BigInt(lockedBalances[1]) === BigInt(depositAmount) / BigInt(2),
`LockedBalanceB ${BigInt(depositAmount) / BigInt(2)} expected, found ${
lockedBalances[1]
}`
);
assert(
Number(totalUnlockedAmount) === 0,
BigInt(totalUnlockedAmount) === BigInt(0),
`Total unlocked 0 expected, found ${totalUnlockedAmount}`
);
assert(
Number(totalLockedAmount) === constants.depositAmount,
`Total Locked amount ${constants.depositAmount} expected, found ${totalLockedAmount}`
BigInt(totalLockedAmount) === BigInt(depositAmount),
`Total Locked amount ${BigInt(
depositAmount
)} expected, found ${totalLockedAmount}`
);
}

Expand Down
3 changes: 2 additions & 1 deletion scripts/integrationTests/smokeTest1/exerciseOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export const smokeTest = async ({
}: TestRunner) => {
const optionRoundFacade = await getOptionRoundFacade(
provider,
vaultFacade.vaultContract
vaultFacade.vaultContract,
true
);

const optionBidderAccounts = getOptionBidderAccounts(provider, 3);
Expand Down
2 changes: 2 additions & 0 deletions scripts/integrationTests/smokeTest1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ export { smokeTest as auctionOpenTests } from "./auctionOpen";
export { smokeTest as auctionStartTests } from "./auctionStart";
export { smokeTest as auctionEndTetsts } from "./auctionEnd";
export { smokeTest as refundTokenizeBids } from "./refundBid";
export { smokeTest as optionSettle } from "./optionSettle";
export { smokeTest as exerciseOptions } from "./exerciseOptions";
12 changes: 7 additions & 5 deletions scripts/integrationTests/smokeTest1/optionSettle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
getOptionBidderAccounts,
} from "../../utils/helpers/accounts";
import { TestRunner } from "../../utils/facades/TestRunner";
import { LibraryError } from "starknet";
import { eth, LibraryError } from "starknet";

export const smokeTest = async ({
provider,
Expand All @@ -24,7 +24,7 @@ export const smokeTest = async ({
const devAccount = getAccount("dev", provider);

try {
await vaultFacade.settleAuction(devAccount);
await vaultFacade.settleOptionRound(devAccount);
throw Error("Should have reverted");
} catch (err) {
const error = err as LibraryError;
Expand All @@ -45,7 +45,7 @@ export const smokeTest = async ({
);


vaultFacade.withdraw({
await vaultFacade.withdraw({
account: liquidityProviderAccounts[0],
amount: BigInt(totalPremiums) / BigInt(4),
});
Expand All @@ -67,7 +67,8 @@ export const smokeTest = async ({
totalPremiums,
});

await vaultFacade.settleAuctionBystander(provider);
await vaultFacade.settleOptionRoundBystander(provider);


const stateAfter: any =
await optionRoundFacade.optionRoundContract.get_state();
Expand All @@ -78,7 +79,7 @@ export const smokeTest = async ({
const totalPayout = await optionRoundFacade.getTotalPayout();
const totalLocked = await vaultFacade.getTotalLocked();
assert(
stateAfter.activeVariant() === "Running",
stateAfter.activeVariant() === "Settled",
`Expected:Running\nReceived:${stateAfter.activeVariant()}`
);

Expand All @@ -105,6 +106,7 @@ async function checkpoint1({
totalUnlocked: number | bigint;
totalPremiums: number | bigint;
}) {
console.log("ethBalanceAfter:",ethBalanceAfter,"\nethBalanceBefore:",ethBalanceBefore,"\ntotalPremiums",totalPremiums,"lpUnlockedBalanceAfter:",lpUnlockedBalanceAfter);
assert(
BigInt(ethBalanceAfter) - BigInt(ethBalanceBefore) ===
BigInt(totalPremiums) / BigInt(4),
Expand Down
4 changes: 4 additions & 0 deletions scripts/integrationTests/smokeTesting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import {
auctionEndTetsts,
auctionOpenTests,
auctionStartTests,
exerciseOptions,
optionSettle,
refundTokenizeBids,
} from "./smokeTest1";
import { TestRunner } from "../utils/facades/TestRunner";
Expand All @@ -10,6 +12,8 @@ async function smokeTesting(testRunner: TestRunner) {
await auctionStartTests(testRunner);
await auctionEndTetsts(testRunner);
await refundTokenizeBids(testRunner);
await optionSettle(testRunner);
await exerciseOptions(testRunner);
}

export { smokeTesting };
4 changes: 4 additions & 0 deletions scripts/katana.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ 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
17 changes: 12 additions & 5 deletions scripts/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,29 @@ import { getAccount, getProvider } from "./utils/helpers/common";
import { smokeTesting } from "./integrationTests/smokeTesting";
import { declareContracts } from "./utils/deployment/declareContracts";
import { deployContracts } from "./utils/deployment/deployContracts";
import { erc20ABI } from "./abi";
import { Contract } from "starknet";
import { TestRunner } from "./utils/facades/TestRunner";
import { Constants } from "./utils/facades/types";

async function main(environment: string, port?: string) {
const provider = getProvider(environment, port);
const devAccount = getAccount(environment, provider);
let hashes = await declareContracts(devAccount);

const constants:Constants={
depositAmount:BigInt(10000000000000),
reservePrice:BigInt(4000000000),
strikePrice:BigInt(8000000000),
settlementPrice:BigInt(16000000000),
capLevel:5000,
}
let { ethAddress, vaultAddress } = await deployContracts(
environment,
devAccount,
hashes
hashes,
constants,
);

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


await testRunner.ethFacade.supplyERC20(
devAccount,
Expand Down
3 changes: 3 additions & 0 deletions scripts/utils/deployment/deployContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ async function deployContracts(
vaultHash: string;
optionRoundHash: string;
marketAggregatorHash: string;
},
constants:{

}
) {
let ethAddress = await deployEthContract(
Expand Down
Loading

0 comments on commit d7c7130

Please sign in to comment.