forked from Giveth/impact-graph
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
37 additions
and
15 deletions.
There are no files selected for viewing
15 changes: 0 additions & 15 deletions
15
src/abi/FM_BC_Restricted_Bancor_Redeeming_VirtualSupply_v1.json
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { ethers, Contract, providers } from 'ethers'; | ||
import { logger } from '../../utils/logger'; | ||
|
||
const abi = [ | ||
{ | ||
type: 'function', | ||
name: 'getStaticPriceForBuying', | ||
inputs: [], | ||
outputs: [ | ||
{ | ||
name: '', | ||
type: 'uint256', | ||
internalType: 'uint256', | ||
}, | ||
], | ||
stateMutability: 'view', | ||
}, | ||
]; | ||
|
||
export class ContractAdapter { | ||
private contract: Contract; | ||
|
||
constructor(provider: providers.Provider, contractAddress: string) { | ||
this.contract = new ethers.Contract(contractAddress, abi, provider); | ||
} | ||
|
||
public async getTokenPrice(): Promise<string> { | ||
try { | ||
const price: ethers.BigNumber = | ||
await this.contract.getStaticPriceForBuying(); | ||
return ethers.utils.formatUnits(price, 18); // Assuming the price is returned in 18 decimals | ||
} catch (error) { | ||
logger.error('Error fetching token price:', error); | ||
throw error; | ||
} | ||
} | ||
} |