Skip to content

Commit 91e00dc

Browse files
author
henrye
committed
update tests to also ensure TWAP is correct
1 parent 31e867f commit 91e00dc

1 file changed

Lines changed: 29 additions & 22 deletions

File tree

tests/autocratV0.ts

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ describe("autocrat_v0", async function () {
8787
autocrat,
8888
payer,
8989
context,
90-
banksClient,
90+
banksClient: BanksClient,
9191
dao,
9292
daoTreasury,
9393
META,
9494
USDC,
9595
vaultProgram,
96-
openbook,
96+
openbook: OpenBookV2Client,
9797
openbookTwap,
9898
migrator,
9999
treasuryMetaAccount,
@@ -533,33 +533,33 @@ describe("autocrat_v0", async function () {
533533

534534
let passBuyArgs: PlaceOrderArgs = {
535535
side: Side.Bid,
536-
priceLots: new BN(10000), // 1 USDC for 1 META
536+
priceLots: new BN(135_000), // $13.5 USDC for 0.1 META -> $135 per meta
537537
maxBaseLots: new BN(10),
538-
maxQuoteLotsIncludingFees: new BN(10000),
538+
maxQuoteLotsIncludingFees: new BN(1_350_000), // $135 dollars in quote lots
539539
clientOrderId: new BN(1),
540540
orderType: OrderType.Limit,
541541
expiryTimestamp: new BN(0),
542542
selfTradeBehavior: SelfTradeBehavior.DecrementTake,
543543
limit: 255,
544544
};
545-
let failBuyArgs: PlaceOrderArgs = {
546-
side: Side.Bid,
547-
priceLots: new BN(7000), // 0.7 USDC for 1 META
545+
let passSellArgs: PlaceOrderArgs = {
546+
side: Side.Ask,
547+
priceLots: new BN(145_000), // $14.5 USDC for 0.1 META -> $145 per meta
548548
maxBaseLots: new BN(10),
549-
maxQuoteLotsIncludingFees: new BN(10000),
550-
clientOrderId: new BN(1),
549+
maxQuoteLotsIncludingFees: new BN(1_450_000), // $145 dollars in quote lots
550+
clientOrderId: new BN(2),
551551
orderType: OrderType.Limit,
552552
expiryTimestamp: new BN(0),
553553
selfTradeBehavior: SelfTradeBehavior.DecrementTake,
554554
limit: 255,
555555
};
556556

557-
let passSellArgs: PlaceOrderArgs = {
558-
side: Side.Ask,
559-
priceLots: new BN(11_000), // 1.1 USDC for 1 META
557+
let failBuyArgs: PlaceOrderArgs = {
558+
side: Side.Bid,
559+
priceLots: new BN(7_000), // 0.7 USDC per 0.1 META -> $7 per meta
560560
maxBaseLots: new BN(10),
561-
maxQuoteLotsIncludingFees: new BN(12000),
562-
clientOrderId: new BN(2),
561+
maxQuoteLotsIncludingFees: new BN(10000),
562+
clientOrderId: new BN(1),
563563
orderType: OrderType.Limit,
564564
expiryTimestamp: new BN(0),
565565
selfTradeBehavior: SelfTradeBehavior.DecrementTake,
@@ -676,11 +676,11 @@ describe("autocrat_v0", async function () {
676676
)
677677
);
678678

679-
let takeBuyArgs: PlaceOrderArgs = {
679+
let takeBuyPassArgs: PlaceOrderArgs = {
680680
side: Side.Bid,
681-
priceLots: new BN(13000), // 13 USDC for 1 META
682-
maxBaseLots: new BN(1),
683-
maxQuoteLotsIncludingFees: new BN(20000),
681+
priceLots: new BN(145_000), // $14.5 USDC for 0.1 META
682+
maxBaseLots: new BN(1), // Buy 1 meta
683+
maxQuoteLotsIncludingFees: new BN(1_450_000),
684684
clientOrderId: new BN(1),
685685
orderType: OrderType.Market,
686686
expiryTimestamp: new BN(0),
@@ -689,7 +689,7 @@ describe("autocrat_v0", async function () {
689689
};
690690

691691
await openbookTwap.methods
692-
.placeTakeOrder(takeBuyArgs)
692+
.placeTakeOrder(takeBuyPassArgs)
693693
.accountsStrict({
694694
market: openbookPassMarket,
695695
asks: storedPassMarket.asks,
@@ -858,15 +858,22 @@ describe("autocrat_v0", async function () {
858858
banksClient
859859
);
860860

861-
// alice should have gained 1 META & lost 0.11 USDC
861+
// alice should have gained 1 META & lost $145 USDC
862862
assert.equal(
863863
(await getAccount(banksClient, aliceUnderlyingBaseTokenAccount)).amount,
864-
100_000_000n
864+
1_000_000_000n
865865
);
866866
assert.equal(
867867
(await getAccount(banksClient, aliceUnderlyingQuoteTokenAccount))
868868
.amount,
869-
10_000n * 1_000_000n - 1_100_000n
869+
10_000n * 1_000_000n - 145_000_000n
870+
);
871+
// And the TWAP on pass market should be $140 per meta / $14 per 0.1 meta
872+
assert.equal(
873+
(
874+
await openbookTwap.account.twapMarket.fetch(openbookTwapPassMarket)
875+
).twapOracle.lastObservation.toNumber(),
876+
140_000 //
870877
);
871878
});
872879

0 commit comments

Comments
 (0)