@@ -88,7 +88,6 @@ export function createFaucetRouter(db: DataStore): RouterWithAsync {
88
88
const FAUCET_DEFAULT_WINDOW = 5 * 60 * 1000 ; // 5 minutes
89
89
const FAUCET_DEFAULT_TRIGGER_COUNT = 5 ;
90
90
91
- const FAUCET_STACKING_STX_AMOUNT = stxToMicroStx ( 3_000_000 ) ;
92
91
const FAUCET_STACKING_WINDOW = 2 * 24 * 60 * 60 * 1000 ; // 2 days
93
92
const FAUCET_STACKING_TRIGGER_COUNT = 1 ;
94
93
@@ -110,9 +109,19 @@ export function createFaucetRouter(db: DataStore): RouterWithAsync {
110
109
// we want to escalate and implement a per IP policy
111
110
const now = Date . now ( ) ;
112
111
113
- const [ window , triggerCount , stxAmount ] = isStackingReq
114
- ? [ FAUCET_STACKING_WINDOW , FAUCET_STACKING_TRIGGER_COUNT , FAUCET_STACKING_STX_AMOUNT ]
115
- : [ FAUCET_DEFAULT_WINDOW , FAUCET_DEFAULT_TRIGGER_COUNT , FAUCET_DEFAULT_STX_AMOUNT ] ;
112
+ const network = getStxFaucetNetwork ( ) ;
113
+ const coreUrl = new URL ( network . coreApiUrl ) ;
114
+ const rpcClient = new StacksCoreRpcClient ( { host : coreUrl . hostname , port : coreUrl . port } ) ;
115
+
116
+ let stxAmount = FAUCET_DEFAULT_STX_AMOUNT ;
117
+ if ( isStackingReq ) {
118
+ const poxInfo = await rpcClient . getPox ( ) ;
119
+ stxAmount = BigInt ( poxInfo . min_amount_ustx ) ;
120
+ }
121
+
122
+ const [ window , triggerCount ] = isStackingReq
123
+ ? [ FAUCET_STACKING_WINDOW , FAUCET_STACKING_TRIGGER_COUNT ]
124
+ : [ FAUCET_DEFAULT_WINDOW , FAUCET_DEFAULT_TRIGGER_COUNT ] ;
116
125
117
126
const requestsInWindow = lastRequests . results
118
127
. map ( r => now - r . occurred_at )
@@ -130,7 +139,6 @@ export function createFaucetRouter(db: DataStore): RouterWithAsync {
130
139
let sendError : Error | undefined = undefined ;
131
140
let sendSuccess = false ;
132
141
for ( let i = 0 ; i < MAX_NONCE_INCREMENT_RETRIES ; i ++ ) {
133
- const network = getStxFaucetNetwork ( ) ;
134
142
const txOpts : SignedTokenTransferOptions = {
135
143
recipient : address ,
136
144
amount : new BN ( stxAmount . toString ( ) ) ,
@@ -144,8 +152,6 @@ export function createFaucetRouter(db: DataStore): RouterWithAsync {
144
152
const tx = await makeSTXTokenTransfer ( txOpts ) ;
145
153
const serializedTx = tx . serialize ( ) ;
146
154
try {
147
- const coreUrl = new URL ( network . coreApiUrl ) ;
148
- const rpcClient = new StacksCoreRpcClient ( { host : coreUrl . hostname , port : coreUrl . port } ) ;
149
155
const txSendResult = await rpcClient . sendTransaction ( serializedTx ) ;
150
156
res . json ( {
151
157
success : true ,
0 commit comments