Skip to content

Commit

Permalink
Add contractAdapter.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
ae2079 committed Sep 5, 2024
1 parent 9ccaed1 commit 636f84b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
15 changes: 0 additions & 15 deletions src/abi/FM_BC_Restricted_Bancor_Redeeming_VirtualSupply_v1.json

This file was deleted.

37 changes: 37 additions & 0 deletions src/adapters/inverter/contractAdapter.ts
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;
}
}
}

0 comments on commit 636f84b

Please sign in to comment.