Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 58 additions & 67 deletions apps/portal/src/app/contracts/deploy/deploy-contract/page.mdx
Original file line number Diff line number Diff line change
@@ -1,68 +1,59 @@
import deployCLI from "./assets/deploy-cli.png";
import linkDevice from "./assets/link-device.png";
import detectedExtensions from "./assets/detected-extensions.png";
import deployContract from "./assets/deploy-contract.png";
import { DocImage, createMetadata } from "@doc";
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@aave/core-v3/contracts/interfaces/IPool.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

contract FlashLoanArbitrage {
address private owner;
IPool public lendingPool;

// Ethereum Mainnet DAI Token Adresi
address public daiTokenAddress = 0x6B175474E89094C44Da98b954EedeAC495271d0F;

event FlashLoanExecuted(uint256 amount);
event ArbitrageExecuted(address tokenA, address tokenB, uint256 amount);
event ProfitWithdrawn(address to, uint256 amount);

modifier onlyOwner() {
require(msg.sender == owner, "Only owner can execute");
_;
}

constructor(address _lendingPool) {
owner = msg.sender;
lendingPool = IPool(_lendingPool);
}

function executeFlashLoan(uint256 amount) external onlyOwner {
address;
assets[0] = daiTokenAddress;
uint256;
amounts[0] = amount;
uint256;
modes[0] = 0; // Teminat gerektirmez
Comment on lines +28 to +34
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The array declarations are incomplete and will cause compilation errors. The arrays need to be properly initialized as memory arrays with fixed sizes. Here's the corrected code:

function executeFlashLoan(uint256 amount) external onlyOwner {
    address[] memory assets = new address[](1);
    assets[0] = daiTokenAddress;
    uint256[] memory amounts = new uint256[](1);
    amounts[0] = amount;
    uint256[] memory modes = new uint256[](1);
    modes[0] = 0; // No collateral needed

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.


lendingPool.flashLoan(
address(this),
assets,
amounts,
modes,
address(this),
"",
0
);

emit FlashLoanExecuted(amount);
}

function swapTokens(address tokenA, address tokenB, uint256 amount) external onlyOwner {
require(IERC20(tokenA).transfer(tokenB, amount), "Swap failed");
emit ArbitrageExecuted(tokenA, tokenB, amount);
}
Comment on lines +49 to +52
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The swapTokens function's current implementation attempts to transfer tokens directly between token addresses, which is not a valid way to perform token swaps. To execute token swaps, this function needs to integrate with a decentralized exchange (DEX) contract like Uniswap or SushiSwap. The DEX's router contract would handle the actual token exchange through its swap functions, typically requiring approval for the token spend and specific function calls to execute the swap.

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.


function withdrawFunds(address token, uint256 amount) external onlyOwner {
require(IERC20(token).transfer(owner, amount), "Withdraw failed");
emit ProfitWithdrawn(owner, amount);
}
}

export const metadata = createMetadata({
title: "Deploy Contract | thirdweb deploy",
description: "deploy a contract using Deploy using thirdweb deploy CLI",
image: {
title: "Deploy Contract",
icon: "contract",
},
});

import { Steps, Step } from "@doc";

# Deploy Contract

To deploy a contract using Deploy:

<Steps>

<Step title="Run CLI">

Navigate to the root of the smart contract repository using the CLI. Then, run the command `npx thirdweb deploy`.

<DocImage src={deployCLI} alt="Screenshot of CLI deployment output text" />

</Step>

<Step title="Authorize device">

To deploy from a desired wallet in the browser, connect and authorize the device.

<DocImage src={linkDevice} alt="Screenshot to link Device" />

</Step>

<Step title="Fill parameter">

Once completed, a user interface will open in the browser that allows filling out the parameters of the contract.

<DocImage
src={detectedExtensions}
alt="Screenshot to detected extensions when deploying contracts"
/>

</Step>

<Step title="Select Options">

Fill in the necessary fields, then find the Network / Chain drop-down menu to select a network for deployment. Choose the `Add to dashboard` option if managing this contract from the dashboard and select Deploy Now. This will require signing a transaction in the connected wallet.

<DocImage
src={deployContract}
alt="Screenshot of contract deployment confirmation"
/>

</Step>

<Step title="Manage contract">

Once deployed, you can manage your contract through the dashboard.

</Step>

</Steps>