Skip to content

Commit

Permalink
Merge pull request #16 from killroy192/fix/trade
Browse files Browse the repository at this point in the history
fix trading for scripts
  • Loading branch information
McReader authored Dec 6, 2023
2 parents e66fb1d + 65d092c commit 21f7cf3
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 41 deletions.
29 changes: 0 additions & 29 deletions demo/.github/workflows/contracts.yml

This file was deleted.

1 change: 0 additions & 1 deletion demo/.gitignore

This file was deleted.

File renamed without changes.
Binary file removed demo/img/arch-overview-trade.png
Binary file not shown.
Binary file removed demo/img/arch-overview.png
Binary file not shown.
Binary file removed demo/img/architecture-overview.png
Binary file not shown.
4 changes: 2 additions & 2 deletions deployment-lock.json

Large diffs are not rendered by default.

13 changes: 6 additions & 7 deletions scripts/e2e/example/trade.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const hre = require("hardhat");
const { getDeploymentLockData } = require("../../common");
const hre = require("hardhat");

const { ethers, network } = hre;
const coder = new ethers.AbiCoder();
Expand Down Expand Up @@ -55,18 +54,18 @@ async function main() {
"FakedOracleProxy",
lock.FakedOracleProxy.addr,
);
const usdc = await ethers.getContractAt("FUSDC", lock.FUSDC.addr);

const initBalance = await usdc.balanceOf(signerAddr);
console.log("USD balance before trade: ", await usdc.balanceOf(signerAddr));

await consumer.trade(tradeArgs, nonce, {
value: hre.ethers.parseEther("0.01"),
value: hre.ethers.parseEther("0.005"),
});

const usdc = await ethers.getContractAt("FUSDC", lock.FUSDC.addr);

const balance = initBalance - await usdc.balanceOf(signerAddr);
// wait ~block for automation to perform a swap
await new Promise((res) => setTimeout(res, 4500));

console.log("Successfully traded fWETH tokens for fUSDC", balance);
console.log("USD balance after trade: ", await usdc.balanceOf(signerAddr));

console.log("run fallback check logic..");

Expand Down
6 changes: 4 additions & 2 deletions src/Oracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ contract Oracle is IOracle, DataStreamConsumer, ReentrancyGuard {

bool success = IOracleConsumerContract(callbackContract).consume(
ForwardData({
price: int256(0),
price: int256(report.price),
feedType: FeedType.DataStream,
forwardArguments: callbackArgs
})
Expand Down Expand Up @@ -186,7 +186,9 @@ contract Oracle is IOracle, DataStreamConsumer, ReentrancyGuard {

bool success = IOracleConsumerContract(callbackContract).consume(
ForwardData({
price: price,
// price convertion to 18 decimals is hardcoded for ETH\USD
// TODO: implement flexible conversion
price: price * 10 ** 10,
feedType: FeedType.PriceFeed,
forwardArguments: callbackArgs
})
Expand Down

0 comments on commit 21f7cf3

Please sign in to comment.