@@ -10,6 +10,7 @@ import {
1010 CpAmm ,
1111 deriveConfigAddress ,
1212 FEE_DENOMINATOR ,
13+ getDynamicFeeParams ,
1314 getSqrtPriceFromPrice ,
1415} from "../src" ;
1516import privateConfig from "./config/privateConfig.json" ;
@@ -60,44 +61,10 @@ import Decimal from "decimal.js";
6061
6162 let dynamicFee = null ;
6263 if ( privateConfig . dynamicFee ) {
63- const priceRatio = privateConfig . maxPriceChangeBps / BASIS_POINT_MAX + 1 ;
64- // Q64
65- const sqrtPriceRatioQ64 = new BN (
66- Decimal . sqrt ( priceRatio . toString ( ) )
67- . mul ( Decimal . pow ( 2 , 64 ) )
68- . floor ( )
69- . toFixed ( )
64+ dynamicFee = getDynamicFeeParams (
65+ privateConfig . baseFeeBps ,
66+ privateConfig . maxPriceChangeBps
7067 ) ;
71- const ONE = new BN ( 1 ) . shln ( 64 ) ;
72- const deltaBinId = sqrtPriceRatioQ64
73- . sub ( ONE )
74- . div ( new BN ( 1844674407370955 ) )
75- . muln ( 2 ) ;
76-
77- const maxVolatilityAccumulator = new BN ( deltaBinId . muln ( BASIS_POINT_MAX ) ) ;
78-
79- const squareVfaBin = maxVolatilityAccumulator . mul ( new BN ( 1 ) ) . pow ( new BN ( 2 ) ) ;
80-
81- const baseFeeNumerator = new BN (
82- privateConfig . baseFeeBps * FEE_DENOMINATOR
83- ) . divn ( BASIS_POINT_MAX ) ;
84-
85- const maxDynamicFeeNumerator = baseFeeNumerator . muln ( 20 ) . divn ( 100 ) ; // default max dynamic fee = 20% of base fee.
86- const vFee = maxDynamicFeeNumerator
87- . mul ( new BN ( 100_000_000_000 ) )
88- . sub ( new BN ( 99_999_999_999 ) ) ;
89-
90- const variableFeeControl = vFee . div ( squareVfaBin ) ;
91-
92- dynamicFee = {
93- binStep : 1 ,
94- binStepU128 : new BN ( "1844674407370955" ) ,
95- filterPeriod : 10 ,
96- decayPeriod : 120 ,
97- reductionFactor : 5000 ,
98- maxVolatilityAccumulator : maxVolatilityAccumulator . toNumber ( ) ,
99- variableFeeControl : variableFeeControl . toNumber ( ) ,
100- } ;
10168 }
10269 const createConfigParams = {
10370 index : new BN ( privateConfig . configIndex ) ,
@@ -135,6 +102,7 @@ import Decimal from "decimal.js";
135102 await connection . getLatestBlockhash ( )
136103 ) . blockhash ;
137104 transaction . sign ( wallet ) ;
105+ console . log ( await connection . simulateTransaction ( transaction ) ) ;
138106
139107 // const signature = await sendAndConfirmRawTransaction(
140108 // connection,
0 commit comments