diff --git a/app/src/components/trade-dialog.tsx b/app/src/components/trade-dialog.tsx index 7da80c0..f3ddecc 100644 --- a/app/src/components/trade-dialog.tsx +++ b/app/src/components/trade-dialog.tsx @@ -9,7 +9,6 @@ import { useAccount, useBalance, useContractWrite, - usePrepareSendTransaction, useSendTransaction, } from "wagmi"; @@ -29,6 +28,7 @@ import { usdcConfig, avaxConfig, } from "@/config/contracts"; +import { Check } from "lucide-react"; const formSchema = z.object({ from: z.coerce.number().gt(0), @@ -37,6 +37,7 @@ const formSchema = z.object({ const TradeDialog = ({ pair }: { pair: Pair }) => { const [isLoading, setIsLoading] = useState(false); + const [txHash, setTxHash] = useState
(); const { address } = useAccount(); const { prices } = useDatafeed(); const [tokenA, setTokenA] = useState
( @@ -179,7 +180,7 @@ const TradeDialog = ({ pair }: { pair: Pair }) => { }); } - await trade({ + const result = await trade({ args: [tokenA!, tokenB!, parseEther(`${fromAmount}`), feedId], }); toast({ @@ -188,9 +189,31 @@ const TradeDialog = ({ pair }: { pair: Pair }) => { variant: "success", }); setIsLoading(false); + setTxHash(result.hash); } - return ( + return txHash ? ( +
+ +

Swap completed!

+ + + View on Explorer + + external-link + +
+ ) : ( <>
diff --git a/app/src/config/contracts.ts b/app/src/config/contracts.ts index e2dc6ac..da634af 100644 --- a/app/src/config/contracts.ts +++ b/app/src/config/contracts.ts @@ -478,7 +478,7 @@ export const avaxConfig = { } as const; export const proxyConfig = { - address: "0xb017Bd229423af4a836baEBBB01110918e1E091A", + address: "0xcB2c15CEe8309A2442a1b0B35c475e1531C4CFE4", abi: [ { inputs: [ diff --git a/contracts/scripts/deploy.ts b/contracts/scripts/deploy.ts index 668c203..8ca2ad5 100644 --- a/contracts/scripts/deploy.ts +++ b/contracts/scripts/deploy.ts @@ -3,11 +3,12 @@ import { ethers, upgrades } from "hardhat"; async function main() { const [signer] = await ethers.getSigners(); const router = "0xab7664500b19a7a2362Ab26081e6DfB971B6F1B0"; - const verifier = "0xea9B98Be000FBEA7f6e88D08ebe70EbaAD10224c"; + const verifier = '0xcB1241Fdf26501fA7A2d47d841dcF72C3CAa9dCe'; const linkToken = "0xe39Ab88f8A4777030A534146A9Ca3B52bd5D43A3"; const feedsId = [ - "0x00023496426b520583ae20a66d80484e0fc18544866a5b0bfee15ec771963274", + '0x00029584363bcf642315133c335b3646513c20f049602fc7d933be0d3f6360d3', + '0x0002c407f448ffe50a15fd5f1ffe4791830c5f8fa39cd971a3d6ae337aef51a0', ]; const Consumer = await ethers.getContractFactory("DataFeedsConsumer"); diff --git a/contracts/scripts/initialize.ts b/contracts/scripts/initialize.ts new file mode 100644 index 0000000..9361c42 --- /dev/null +++ b/contracts/scripts/initialize.ts @@ -0,0 +1,27 @@ +import { ethers } from 'hardhat'; +import { abi } from '../artifacts/contracts/DataStreamsConsumer.sol/DataStreamsConsumer.json'; + +async function main() { + const [signer] = await ethers.getSigners(); + const proxyAddress = '0xcB2c15CEe8309A2442a1b0B35c475e1531C4CFE4'; + const router = '0xab7664500b19a7a2362Ab26081e6DfB971B6F1B0'; + const verifier = '0xcB1241Fdf26501fA7A2d47d841dcF72C3CAa9dCe'; + const linkToken = '0xe39Ab88f8A4777030A534146A9Ca3B52bd5D43A3'; + + const feedsId = [ + '0x00029584363bcf642315133c335b3646513c20f049602fc7d933be0d3f6360d3', + '0x0002c407f448ffe50a15fd5f1ffe4791830c5f8fa39cd971a3d6ae337aef51a0', + ]; + + const consumer = new ethers.Contract(proxyAddress, abi, signer); + + await consumer.initializer(router, verifier, linkToken, feedsId); + console.log('Successfully initialized'); +} + +// We recommend this pattern to be able to use async/await everywhere +// and properly handle errors. +main().catch((error) => { + console.error(error); + process.exitCode = 1; +}); diff --git a/contracts/scripts/trade.ts b/contracts/scripts/trade.ts index 0f44913..bf0a018 100644 --- a/contracts/scripts/trade.ts +++ b/contracts/scripts/trade.ts @@ -3,17 +3,33 @@ import { abi } from "../artifacts/contracts/DataStreamsConsumer.sol/DataStreamsC async function main() { const [signer] = await ethers.getSigners(); - const proxyAddress = "0xb017Bd229423af4a836baEBBB01110918e1E091A"; + const proxyAddress = "0xcB2c15CEe8309A2442a1b0B35c475e1531C4CFE4"; const wethAddress = "0xe39ab88f8a4777030a534146a9ca3b52bd5d43a3"; + const avaxAddress = "0x586A52Ca64f75b49a72e4CaEf5B91374257e1538"; const usdc = "0x8fb1e3fc51f3b789ded7557e680551d93ea9d892"; - const amountIn = ethers.parseEther("0.001"); - const weth = await ethers.getContractAt("IERC20", wethAddress); + const feedsId = [ + '0x00029584363bcf642315133c335b3646513c20f049602fc7d933be0d3f6360d3', + '0x0002c407f448ffe50a15fd5f1ffe4791830c5f8fa39cd971a3d6ae337aef51a0', + ]; const consumer = new ethers.Contract(proxyAddress, abi, signer); + const amountIn = ethers.parseEther('0.001'); + + // Trade WETH <> USDC + const weth = await ethers.getContractAt("IERC20", wethAddress); + await weth.approve(await consumer.getAddress(), amountIn); - await consumer.trade(wethAddress, usdc, amountIn); - console.log("Successfully traded tokens"); + await consumer.trade(wethAddress, usdc, amountIn, feedsId[0]); + console.log("Successfully traded WETH tokens for USDC"); + + // Trade AVAX <> USDC + const avax = await ethers.getContractAt("IERC20", avaxAddress); + + await avax.approve(await consumer.getAddress(), amountIn); + await consumer.trade(avaxAddress, usdc, amountIn, feedsId[1]); + console.log('Successfully traded AVAX tokens for USDC'); + } // We recommend this pattern to be able to use async/await everywhere diff --git a/contracts/scripts/upgrade.ts b/contracts/scripts/upgrade.ts index 827d72b..2490fa5 100644 --- a/contracts/scripts/upgrade.ts +++ b/contracts/scripts/upgrade.ts @@ -4,12 +4,12 @@ async function main() { const [signer] = await ethers.getSigners(); /* const contract = new ethers.Contract( - "0xb017Bd229423af4a836baEBBB01110918e1E091A", + "0xcB2c15CEe8309A2442a1b0B35c475e1531C4CFE4", abi, signer ); */ - const proxyAddress = "0xb017bd229423af4a836baebbb01110918e1e091a"; + const proxyAddress = "0xcB2c15CEe8309A2442a1b0B35c475e1531C4CFE4"; const Consumer = await ethers.getContractFactory("DataStreamsConsumer"); await upgrades.upgradeProxy(proxyAddress, Consumer);