@@ -48,6 +48,7 @@ export type RandomnessVerificationConfig = {
4848
4949type RequestRandomnessParams = {
5050 callbackGasLimit : bigint
51+ bufferPercent : bigint
5152 timeoutMs : number
5253 confirmations : number
5354 pollingIntervalMs : number
@@ -66,6 +67,7 @@ export class Randomness {
6667 this . contract = RandomnessSender__factory . connect ( this . networkConfig . contractAddress , rpc )
6768 this . defaultRequestParams = {
6869 callbackGasLimit : networkConfig . callbackGasLimitDefault ,
70+ bufferPercent : 50n ,
6971 timeoutMs : defaultRequestTimeoutMs ,
7072 confirmations : 1 ,
7173 pollingIntervalMs : 500 ,
@@ -99,7 +101,7 @@ export class Randomness {
99101 const maxPriorityFeePerGas = feeData . maxPriorityFeePerGas ! ;
100102
101103 // 2. Use EIP-1559 pricing
102- const txGasPrice = ( maxFeePerGas + maxPriorityFeePerGas ) * 10n ;
104+ const txGasPrice = maxFeePerGas + maxPriorityFeePerGas ;
103105
104106 // 3. Estimate request price using the selected txGasPrice
105107 const requestPrice = await this . contract . estimateRequestPriceNative (
@@ -108,7 +110,9 @@ export class Randomness {
108110 ) ;
109111
110112 // 4. Apply buffer (e.g. 100% = 2× total)
111- const bufferPercent = isFilecoin ( Number ( chainId ) ) ? 300n : 50n ;
113+ const bufferPercent = config . bufferPercent !== undefined
114+ ? config . bufferPercent
115+ : ( isFilecoin ( Number ( chainId ) ) ? 300n : 100n ) ;
112116 const valueToSend = requestPrice + ( requestPrice * bufferPercent ) / 100n ;
113117
114118 // 5. Estimate gas
@@ -191,7 +195,7 @@ export class Randomness {
191195 * @param callbackGasLimit The callbackGasLimit to use when fulfilling the request with a decryption key.
192196 * @returns The estimated request price and the transaction gas price used
193197 */
194- async calculateRequestPriceNative ( callbackGasLimit : bigint ) : Promise < [ bigint , bigint ] > {
198+ async calculateRequestPriceNative ( callbackGasLimit : bigint , config : Partial < RequestRandomnessParams > = this . defaultRequestParams ) : Promise < [ bigint , bigint ] > {
195199 if ( this . rpc . provider == null ) {
196200 throw Error ( "RPC requires a provider to request randomness" )
197201 }
@@ -209,7 +213,7 @@ export class Randomness {
209213 const maxPriorityFeePerGas = feeData . maxPriorityFeePerGas ! ;
210214
211215 // 2. Use EIP-1559 pricing
212- const txGasPrice = ( maxFeePerGas + maxPriorityFeePerGas ) * 10n ;
216+ const txGasPrice = maxFeePerGas + maxPriorityFeePerGas ;
213217
214218 // 3. Estimate request price using the selected txGasPrice
215219 const requestPrice = await this . contract . estimateRequestPriceNative (
@@ -218,7 +222,9 @@ export class Randomness {
218222 ) ;
219223
220224 // 4. Apply buffer (e.g. 100% = 2× total)
221- const bufferPercent = isFilecoin ( Number ( chainId ) ) ? 300n : 100n ;
225+ const bufferPercent = config . bufferPercent !== undefined
226+ ? config . bufferPercent
227+ : ( isFilecoin ( Number ( chainId ) ) ? 300n : 100n ) ;
222228 const valueToSend = requestPrice + ( requestPrice * bufferPercent ) / 100n ;
223229
224230 return [ valueToSend , txGasPrice ] ;
0 commit comments