Skip to content

Commit 1ba0599

Browse files
committed
fix: #306 query for min stacking STX amount from /v2/pox endpoint
1 parent 77729a5 commit 1ba0599

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/api/routes/faucets.ts

+13-7
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ export function createFaucetRouter(db: DataStore): RouterWithAsync {
8888
const FAUCET_DEFAULT_WINDOW = 5 * 60 * 1000; // 5 minutes
8989
const FAUCET_DEFAULT_TRIGGER_COUNT = 5;
9090

91-
const FAUCET_STACKING_STX_AMOUNT = stxToMicroStx(3_000_000);
9291
const FAUCET_STACKING_WINDOW = 2 * 24 * 60 * 60 * 1000; // 2 days
9392
const FAUCET_STACKING_TRIGGER_COUNT = 1;
9493

@@ -110,9 +109,19 @@ export function createFaucetRouter(db: DataStore): RouterWithAsync {
110109
// we want to escalate and implement a per IP policy
111110
const now = Date.now();
112111

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];
116125

117126
const requestsInWindow = lastRequests.results
118127
.map(r => now - r.occurred_at)
@@ -130,7 +139,6 @@ export function createFaucetRouter(db: DataStore): RouterWithAsync {
130139
let sendError: Error | undefined = undefined;
131140
let sendSuccess = false;
132141
for (let i = 0; i < MAX_NONCE_INCREMENT_RETRIES; i++) {
133-
const network = getStxFaucetNetwork();
134142
const txOpts: SignedTokenTransferOptions = {
135143
recipient: address,
136144
amount: new BN(stxAmount.toString()),
@@ -144,8 +152,6 @@ export function createFaucetRouter(db: DataStore): RouterWithAsync {
144152
const tx = await makeSTXTokenTransfer(txOpts);
145153
const serializedTx = tx.serialize();
146154
try {
147-
const coreUrl = new URL(network.coreApiUrl);
148-
const rpcClient = new StacksCoreRpcClient({ host: coreUrl.hostname, port: coreUrl.port });
149155
const txSendResult = await rpcClient.sendTransaction(serializedTx);
150156
res.json({
151157
success: true,

0 commit comments

Comments
 (0)