diff --git a/src/abi/FM_BC_Restricted_Bancor_Redeeming_VirtualSupply_v1.json b/src/abi/FM_BC_Restricted_Bancor_Redeeming_VirtualSupply_v1.json deleted file mode 100644 index 9ee6e2317..000000000 --- a/src/abi/FM_BC_Restricted_Bancor_Redeeming_VirtualSupply_v1.json +++ /dev/null @@ -1,15 +0,0 @@ -[ - { - "type": "function", - "name": "getStaticPriceForBuying", - "inputs": [], - "outputs": [ - { - "name": "", - "type": "uint256", - "internalType": "uint256" - } - ], - "stateMutability": "view" - } -] \ No newline at end of file diff --git a/src/adapters/inverter/contractAdapter.ts b/src/adapters/inverter/contractAdapter.ts new file mode 100644 index 000000000..20ecce4c2 --- /dev/null +++ b/src/adapters/inverter/contractAdapter.ts @@ -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 { + 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; + } + } +}