Skip to content

Commit a5ec670

Browse files
committed
test twap expected value
1 parent 1888d4f commit a5ec670

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

tests/integration/twap.test.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default async function test() {
5151
);
5252

5353
// Advance slots to get past the delay period
54-
await advanceBySlots(this.context, twapStartDelaySlots + 1n);
54+
await advanceBySlots(this.context, twapStartDelaySlots);
5555

5656
// Crank the TWAP - should update now
5757
await this.ammClient
@@ -78,7 +78,7 @@ export default async function test() {
7878
await this.ammClient.swap(amm, { sell: {} }, 0.2, 100);
7979

8080
// Advance slots and crank again
81-
await advanceBySlots(this.context, 151n);
81+
await advanceBySlots(this.context, 150n);
8282
await this.ammClient
8383
.crankThatTwapIx(amm)
8484
.preInstructions([
@@ -95,10 +95,19 @@ export default async function test() {
9595
"TWAP should update after swap and crank"
9696
);
9797

98-
// Verify TWAP value changed
98+
// Verify TWAP value changed after swaps
9999
const finalTwap = AmmMath.getTwap(ammAfterSwap);
100100
assert.isTrue(
101101
!finalTwap.eq(initialTwap),
102102
"TWAP value should change after swaps and crank"
103103
);
104+
105+
// Verify that the TWAP is calculated correctly
106+
const expectedTwap = ammAfterSwap.oracle.aggregator.div(
107+
ammAfterSwap.oracle.lastUpdatedSlot.sub(ammAfterSwap.createdAtSlot)
108+
);
109+
assert.isTrue(
110+
finalTwap.eq(expectedTwap),
111+
"Calculated TWAP should match the expected value"
112+
);
104113
}

0 commit comments

Comments
 (0)