Skip to content

Commit

Permalink
fix oracle
Browse files Browse the repository at this point in the history
  • Loading branch information
scobru committed Jun 16, 2024
1 parent a1d4c58 commit 45d7343
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 33 deletions.
99 changes: 97 additions & 2 deletions .openzeppelin/polygon.json
Original file line number Diff line number Diff line change
Expand Up @@ -6559,7 +6559,7 @@
"label": "registry",
"offset": 0,
"slot": "0",
"type": "t_contract(IBaluniV1Registry)2529",
"type": "t_contract(IBaluniV1Registry)3983",
"contract": "BaluniV1Oracle",
"src": "contracts\\oracles\\BaluniV1Oracle.sol:52"
}
Expand Down Expand Up @@ -6607,7 +6607,7 @@
"label": "uint64",
"numberOfBytes": "8"
},
"t_contract(IBaluniV1Registry)2529": {
"t_contract(IBaluniV1Registry)3983": {
"label": "contract IBaluniV1Registry",
"numberOfBytes": "20"
}
Expand Down Expand Up @@ -7718,6 +7718,101 @@
]
}
}
},
"c8dd494fd91c589b7e8ff1e30bc21e0643105cb9a72af7544b04015ab19c8ae9": {
"address": "0x37382ACd2eD69F113524295A04D2302a7572205a",
"txHash": "0x98288e9383d949ef49b24a801299dc11e48ad651329649da8547af8c4f719ab2",
"layout": {
"solcVersion": "0.8.25",
"storage": [
{
"label": "registry",
"offset": 0,
"slot": "0",
"type": "t_contract(IBaluniV1Registry)2529",
"contract": "BaluniV1Oracle",
"src": "contracts\\oracles\\BaluniV1Oracle.sol:52"
}
],
"types": {
"t_address": {
"label": "address",
"numberOfBytes": "20"
},
"t_bool": {
"label": "bool",
"numberOfBytes": "1"
},
"t_struct(InitializableStorage)65_storage": {
"label": "struct Initializable.InitializableStorage",
"members": [
{
"label": "_initialized",
"type": "t_uint64",
"offset": 0,
"slot": "0"
},
{
"label": "_initializing",
"type": "t_bool",
"offset": 8,
"slot": "0"
}
],
"numberOfBytes": "32"
},
"t_struct(OwnableStorage)14_storage": {
"label": "struct OwnableUpgradeable.OwnableStorage",
"members": [
{
"label": "_owner",
"type": "t_address",
"offset": 0,
"slot": "0"
}
],
"numberOfBytes": "32"
},
"t_uint64": {
"label": "uint64",
"numberOfBytes": "8"
},
"t_contract(IBaluniV1Registry)2529": {
"label": "contract IBaluniV1Registry",
"numberOfBytes": "20"
}
},
"namespaces": {
"erc7201:openzeppelin.storage.Ownable": [
{
"contract": "OwnableUpgradeable",
"label": "_owner",
"type": "t_address",
"src": "@openzeppelin\\contracts-upgradeable\\access\\OwnableUpgradeable.sol:24",
"offset": 0,
"slot": "0"
}
],
"erc7201:openzeppelin.storage.Initializable": [
{
"contract": "Initializable",
"label": "_initialized",
"type": "t_uint64",
"src": "@openzeppelin\\contracts-upgradeable\\proxy\\utils\\Initializable.sol:69",
"offset": 0,
"slot": "0"
},
{
"contract": "Initializable",
"label": "_initializing",
"type": "t_bool",
"src": "@openzeppelin\\contracts-upgradeable\\proxy\\utils\\Initializable.sol:73",
"offset": 8,
"slot": "0"
}
]
}
}
}
}
}
1 change: 1 addition & 0 deletions artifacts/build-info/5da0dd1a3dbba4d339ececb6d6bfda23.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "..\\..\\..\\build-info\\69835c00a496a85c92d338d861531839.json"
"buildInfo": "..\\..\\..\\build-info\\5da0dd1a3dbba4d339ececb6d6bfda23.json"
}

Large diffs are not rendered by default.

46 changes: 23 additions & 23 deletions contracts/oracles/BaluniV1Oracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -149,28 +149,28 @@ contract BaluniV1Oracle is Initializable, OwnableUpgradeable, UUPSUpgradeable, I
address toToken,
uint256 amount
) external view returns (uint256 valuation) {
// if (fromToken == toToken) return amount * 10 ** (18 - IERC20Metadata(toToken).decimals());
// address _1InchSpotAgg = registry.get1inchSpotAgg();
// uint8 fromDecimal = IERC20Metadata(fromToken).decimals();
// uint8 toDecimal = IERC20Metadata(toToken).decimals();
// uint256 rate = I1inchSpotAgg(_1InchSpotAgg).getRate(IERC20(fromToken), IERC20(toToken), false);
// rate = (rate * (10 ** fromDecimal)) / (10 ** toDecimal);
// uint256 scalingFactor;
// uint256 tokenAmount;
// uint256 finalScalingFactor = 10 ** (18 - toDecimal);
// if (fromDecimal == toDecimal) {
// valuation = (amount * rate) / 1e18;
// } else if (fromDecimal > toDecimal) {
// scalingFactor = 10 ** (fromDecimal - toDecimal);
// tokenAmount = amount / scalingFactor;
// valuation = (tokenAmount * rate) / 1e18;
// } else {
// scalingFactor = 10 ** (toDecimal - fromDecimal);
// tokenAmount = amount * scalingFactor;
// valuation = (tokenAmount * rate) / 1e18;
// }
// valuation = valuation * finalScalingFactor;
// return valuation;
if (fromToken == toToken) return amount * 10 ** (18 - IERC20Metadata(toToken).decimals());
address _1InchSpotAgg = registry.get1inchSpotAgg();
uint8 fromDecimal = IERC20Metadata(fromToken).decimals();
uint8 toDecimal = IERC20Metadata(toToken).decimals();
uint256 rate = I1inchSpotAgg(_1InchSpotAgg).getRate(IERC20(fromToken), IERC20(toToken), false);
rate = (rate * (10 ** fromDecimal)) / (10 ** toDecimal);
uint256 scalingFactor;
uint256 tokenAmount;
uint256 finalScalingFactor = 10 ** (18 - toDecimal);
if (fromDecimal == toDecimal) {
valuation = (amount * rate) / 1e18;
} else if (fromDecimal > toDecimal) {
scalingFactor = 10 ** (fromDecimal - toDecimal);
tokenAmount = amount / scalingFactor;
valuation = (tokenAmount * rate) / 1e18;
} else {
scalingFactor = 10 ** (toDecimal - fromDecimal);
tokenAmount = amount * scalingFactor;
valuation = (tokenAmount * rate) / 1e18;
}
valuation = valuation * finalScalingFactor;
return valuation;
}

/**
Expand All @@ -187,7 +187,7 @@ contract BaluniV1Oracle is Initializable, OwnableUpgradeable, UUPSUpgradeable, I
) external view returns (uint256 valuation) {
IStaticOracle staticOracle = IStaticOracle(registry.getStaticOracle());
require(address(staticOracle) != address(0), 'StaticOracle not set');
(valuation, ) = staticOracle.quoteAllAvailablePoolsWithTimePeriod(uint128(amount), fromToken, toToken, 3600);
(valuation, ) = staticOracle.quoteAllAvailablePoolsWithTimePeriod(uint128(amount), fromToken, toToken, 60);
return valuation;
}

Expand Down
10 changes: 5 additions & 5 deletions deploy/01_upgrades.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,17 @@ const upgradeProtocol: DeployFunction = async function (hre: HardhatRuntimeEnvir
await baluniAgentFactory?.waitForDeployment()
console.log('BaluniV1AgentFactory upgraded to:', baluniAgentFactory.target) */

/* const BaluniV1Oracle = await ethers.getContractFactory('BaluniV1Oracle')
const BaluniV1Oracle = await ethers.getContractFactory('BaluniV1Oracle')
await upgrades.prepareUpgrade('0xD8dDca643684e67c17087B7cF6CeE08C91F12511', BaluniV1Oracle)
const baluniOracle = await upgrades.upgradeProxy('0xD8dDca643684e67c17087B7cF6CeE08C91F12511', BaluniV1Oracle, {
kind: 'uups',
call: {
fn: 'reinitialize',
args: ['0xe81562a7e2af6F147Ff05EAbAb9B36e88830b655', 7],
args: ['0xe81562a7e2af6F147Ff05EAbAb9B36e88830b655', 8],
},
})
await baluniOracle?.waitForDeployment()
console.log('BaluniV1Oracle upgraded to:', baluniOracle.target) */
console.log('BaluniV1Oracle upgraded to:', baluniOracle.target)

/* const BaluniV1Router = await ethers.getContractFactory('BaluniV1Router')
await upgrades.prepareUpgrade('0xEd1B284de8D6B398B5744F5178E8BE198A4DaF5e', BaluniV1Router)
Expand All @@ -130,13 +130,13 @@ const upgradeProtocol: DeployFunction = async function (hre: HardhatRuntimeEnvir
await baluniRouter?.waitForDeployment()
console.log('BaluniV1Router upgraded to:', baluniRouter.target) */

const BaluniV1Pool = await ethers.getContractFactory('BaluniV1Pool')
/* const BaluniV1Pool = await ethers.getContractFactory('BaluniV1Pool')
await upgrades.prepareUpgrade('0xabEEAbbEaf1D160031e4BB2AC2918C8EeE73E9aa', BaluniV1Pool)
const baluniPool = await upgrades.upgradeProxy('0xabEEAbbEaf1D160031e4BB2AC2918C8EeE73E9aa', BaluniV1Pool, {
kind: 'uups',
})
await baluniPool?.waitForDeployment()
console.log('BaluniV1Pool upgraded to:', baluniPool.target)
console.log('BaluniV1Pool upgraded to:', baluniPool.target) */

// const BaluniV1PoolFactory = await ethers.getContractFactory("BaluniV1PoolFactory");
// await upgrades.prepareUpgrade(factoryAddress, BaluniV1PoolFactory);
Expand Down

0 comments on commit 45d7343

Please sign in to comment.