Skip to content

Commit

Permalink
fetch token's decimals directly + update the test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
livingrockrises committed Feb 12, 2024
1 parent 50da798 commit 902146b
Show file tree
Hide file tree
Showing 11 changed files with 6 additions and 30 deletions.
4 changes: 2 additions & 2 deletions contracts/token/oracles/OracleAggregator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity ^0.8.23;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "./IOracleAggregator.sol";
import "./FeedInterface.sol";

Expand All @@ -14,7 +15,6 @@ abstract contract OracleAggregator is Ownable, IOracleAggregator {

function setTokenOracle(
address token,
uint8 tokenDecimals,
address tokenOracle,
address nativeOracle,
bool isDerivedFeed,
Expand All @@ -28,7 +28,7 @@ abstract contract OracleAggregator is Ownable, IOracleAggregator {
if (decimals1 != decimals2) revert MismatchInBaseAndQuoteDecimals();
tokensInfo[token].tokenOracle = tokenOracle;
tokensInfo[token].nativeOracle = nativeOracle;
tokensInfo[token].tokenDecimals = tokenDecimals;
tokensInfo[token].tokenDecimals = ERC20(token).decimals();
tokensInfo[token].isDerivedFeed = isDerivedFeed;
tokensInfo[token].priceUpdateThreshold = priceUpdateThreshold;
}
Expand Down
16 changes: 1 addition & 15 deletions scripts/token-paymaster-v2/deploy-token-paymaster-mumbai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
BiconomyTokenPaymaster__factory,
Deployer,
Deployer__factory,
ERC20__factory,
} from "../../typechain-types";
import { mumbaiConfigInfoProd } from "../configs";
import { TokenConfig } from "../utils/Types";
Expand Down Expand Up @@ -127,7 +126,6 @@ async function getPredeployedDeployerContractInstance(): Promise<Deployer> {
async function setTokenOracle(
tokenPaymasterInstance: BiconomyTokenPaymaster,
tokenAddress: string,
tokenDecimals: number,
tokenOracle: string,
nativeOracle: string,
isDerivedFeed: boolean,
Expand All @@ -136,7 +134,6 @@ async function setTokenOracle(
// Connect as the owner of the token paymaster
const tx = await tokenPaymasterInstance.setTokenOracle(
tokenAddress,
tokenDecimals,
tokenOracle,
nativeOracle,
isDerivedFeed,
Expand Down Expand Up @@ -173,11 +170,6 @@ async function getTokenPaymasterContractInstance(
}
}

async function getERC20TokenInstance(tokenAddress: string) {
const [signer] = await ethers.getSigners();
return ERC20__factory.connect(tokenAddress, signer);
}

async function main() {
const accounts = await ethers.getSigners();
const earlyOwner = await accounts[0].getAddress();
Expand Down Expand Up @@ -224,19 +216,13 @@ async function main() {
priceUpdateThreshold = 172800; // 2 days default
}

let tokenDecimals = 18;

if (address) {
const tokenInstance = await getERC20TokenInstance(address);
tokenDecimals = await tokenInstance.decimals();
} else {
if (!address) {
throw new Error("token address can not be undefined");
}
if (tokenPaymasterInstance) {
await setTokenOracle(
tokenPaymasterInstance,
address,
tokenDecimals,
nativeOracleAddress,
tokenOracleAddress,
derivedFeed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ describe("Biconomy Token Paymaster (with Bundler)", function () {

await sampleTokenPaymaster.setTokenOracle(
token.address,
await token.decimals(),
tokenOracle.address,
nativeOracle.address,
true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ describe("Biconomy Token Paymaster (with Bundler)", function () {

await sampleTokenPaymaster.setTokenOracle(
token.address,
await token.decimals(),
tokenOracle.address,
nativeOracle.address,
true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ describe("Biconomy Token Paymaster (With Bundler)", function () {

await sampleTokenPaymaster.setTokenOracle(
token.address,
await token.decimals(),
tokenOracle.address,
nativeOracle.address,
true,
Expand Down
2 changes: 1 addition & 1 deletion test/foundry/token-paymaster/TokenPaymaster.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ contract TokenPaymasterTest is SATestBase {
vm.startPrank(alice.addr);
// could also make a .call using selector and handle success
// append 2 days price threshold
_btpm.setTokenOracle(address(usdc), usdc.decimals(), address(tokenOracle), address(nativeOracle), true, 172800);
_btpm.setTokenOracle(address(usdc), address(tokenOracle), address(nativeOracle), true, 172800);
vm.stopPrank();

uint256 priceToLog = _btpm.getTokenValueOfOneNativeToken((address(usdc)));
Expand Down
6 changes: 2 additions & 4 deletions test/foundry/token-paymaster/TokenPaymasterMumbai.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,12 @@ contract TokenPaymasterMumbaiTest is SATestBase {
vm.startPrank(alice.addr);
// could also make a .call using selector and handle success
_btpm.setTokenOracle(
address(usdc), ERC20(address(usdc)).decimals(), address(tokenOracle), address(nativeOracle), true, 172800
address(usdc), address(tokenOracle), address(nativeOracle), true, 172800
);
vm.stopPrank();

uint256 priceToLog = _btpm.getTokenValueOfOneNativeToken((address(usdc)));
// console2.log(priceToLog);

address accountAddress = address(sa);
console2.log(priceToLog);

vm.startPrank(charlie.addr);
entryPoint.depositTo{value: 2 ether}(address(_btpm));
Expand Down
1 change: 0 additions & 1 deletion test/token-paymaster/biconomy-token-paymaster-specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ describe("Biconomy Token Paymaster", function () {

await sampleTokenPaymaster.setTokenOracle(
token.address,
await token.decimals(),
tokenOracle.address,
nativeOracle.address,
true,
Expand Down
1 change: 0 additions & 1 deletion test/token-paymaster/btpm-coverage-specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ describe("Biconomy Token Paymaster", function () {

await sampleTokenPaymaster.setTokenOracle(
token.address,
await token.decimals(),
tokenOracle.address,
nativeOracle.address,
true,
Expand Down
1 change: 0 additions & 1 deletion test/token-paymaster/btpm-undeployed-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ describe("Biconomy Token Paymaster", function () {

await sampleTokenPaymaster.setTokenOracle(
token.address,
await token.decimals(),
tokenOracle.address,
nativeOracle.address,
true,
Expand Down
2 changes: 0 additions & 2 deletions test/token-paymaster/oracle-aggregator-specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ describe("Biconomy Token Paymaster", function () {

await sampleTokenPaymaster.setTokenOracle(
token.address,
await token.decimals(),
tokenOracle.address,
nativeOracle.address,
true,
Expand Down Expand Up @@ -338,7 +337,6 @@ describe("Biconomy Token Paymaster", function () {

await sampleTokenPaymaster.setTokenOracle(
token.address,
await token.decimals(),
staleFeed.address,
nativeOracle.address,
true,
Expand Down

0 comments on commit 902146b

Please sign in to comment.