-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathPolyWeb3Client.ts
More file actions
42 lines (35 loc) · 1.25 KB
/
PolyWeb3Client.ts
File metadata and controls
42 lines (35 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { $config } from '@dequanto/utils/$config';
import { Web3Client } from './Web3Client';
import { TPlatform } from '@dequanto/models/TPlatform';
import { ClientEndpoints } from './utils/ClientEndpoints';
import { IWeb3EndpointOptions } from './interfaces/IWeb3EndpointOptions';
import { $bigint } from '@dequanto/utils/$bigint';
export class PolyWeb3Client extends Web3Client {
platform: TPlatform = 'polygon';
chainId: number = this.options.chainId ?? 137;
chainToken = 'MATIC';
defaultGasLimit = 2_000_000;
constructor (opts?: IWeb3EndpointOptions) {
super({
...(opts ?? {}),
endpoints: ClientEndpoints.filterEndpoints($config.get('web3.polygon.endpoints'), opts)
});
}
async getGasPrice() {
let { price, base, priority } = await super.getGasPrice();
price = $bigint.min(
price,
$bigint.toWei(60, $bigint.GWEI_DECIMALS)
);
// Use minimum gas price as 15 gwei (network sometimes returns too low fees)
let gasPrice = $bigint.max(
price,
$bigint.toWei(28, $bigint.GWEI_DECIMALS)
);
return {
price: gasPrice,
base: gasPrice,
priority: gasPrice
};
}
}