Skip to content

Commit

Permalink
Merge pull request #73 from Premian-Labs/feat/gas-api
Browse files Browse the repository at this point in the history
Add simple GasAPI
  • Loading branch information
froggiedev committed Nov 29, 2023
2 parents a2b00a7 + 81e7a44 commit 59adee8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@premia/v3-sdk",
"version": "1.1.2",
"version": "1.1.3",
"description": "The official SDK for building applications on Premia V3.",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
22 changes: 22 additions & 0 deletions src/api/gasAPI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { JsonRpcProvider } from 'ethers'
import { BaseAPI } from './baseAPI'

/**
* Represents a class for managing gas in transactions.
*
* @class GasAPI
* @extends {BaseAPI}
*/
export class GasAPI extends BaseAPI {
/**
* Returns a promise containing the gas price.
* @returns {Promise<bigint>} Promise containing the gas price.
*/
async getGasPrice(): Promise<bigint> {
const price = await (this.premia.provider as JsonRpcProvider).send(
'eth_gasPrice',
[]
)
return BigInt(price)
}
}
2 changes: 2 additions & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ export * from './analyticsAPI'
export * from './referralAPI'
export * from './optionPSAPI'
export * from './optionRewardAPI'
export * from './miningAPI'
export * from './gasAPI'
10 changes: 9 additions & 1 deletion src/premia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ import {
ReferralAPI,
OptionPSAPI,
OptionRewardAPI,
MiningAPI,
GasAPI,
} from './api'
import { Addresses, SupportedChainId } from './constants'
import { Coingecko, OrderbookV1 } from './services'
import cache from './cache'
import PremiaSubgraph from './services/subgraph'
import { MiningAPI } from './api/miningAPI'

export interface SetProviderParams {
/**
Expand Down Expand Up @@ -434,6 +435,13 @@ export class Premia {
*/
mining: MiningAPI = new MiningAPI(this)

/**
* The API used to interact with gas for Premia V3.
*
* @defaultValue {@link GasAPI}
*/
gas: GasAPI = new GasAPI(this)

/**
* The API used to interact with optionPS for Premia V3.
*
Expand Down

0 comments on commit 59adee8

Please sign in to comment.