Skip to content

Commit

Permalink
feat: removed swap fee
Browse files Browse the repository at this point in the history
  • Loading branch information
veeso committed Jan 24, 2024
1 parent 60ba7ff commit e45e038
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 247 deletions.
1 change: 0 additions & 1 deletion ethereum/fly/.env.github
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ PROD_PRIVATE_KEY="00000000000000000000000000000000000000000000000000000000000000
DEV_PRIVATE_KEY="0000000000000000000000000000000000000000000000000000000000000000"
LOCAL_PRIVATE_KEY="ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
OWNER_ADDRESS="0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
SWAP_FEE=10
ETHERSCAN_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
4 changes: 0 additions & 4 deletions ethereum/fly/app/src/js/components/Form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import MintTestnetTokens from './MintTestnetTokens/MintTestnetTokens';
import SetFlyCanisterAddressForm from './SetFlyCanisterAddress/SetFlyCanisterAddressForm';
import Web3Client from '../../web3/Web3Client';
import { ChainId } from '../MetamaskConnect';
import SwapFeeForm from './SwapFee/SwapFeeForm';

const Form = () => {
const { status, account, ethereum, chainId } = useMetaMask();
Expand Down Expand Up @@ -46,9 +45,6 @@ const Form = () => {
<Card>
<TransferForm />
</Card>
<Card>
<SwapFeeForm />
</Card>
<Card>
<ChangeOwnerForm />
</Card>
Expand Down
91 changes: 0 additions & 91 deletions ethereum/fly/app/src/js/components/Form/SwapFee/SwapFeeForm.tsx

This file was deleted.

10 changes: 0 additions & 10 deletions ethereum/fly/app/src/js/web3/Web3Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,6 @@ export default class Web3Client {
return contract.methods.swappedSupply().call();
}

async swapFee(): Promise<BigInt> {
const contract = this.getContract();
return contract.methods.swapFee().call();
}

async setSwapFee(fee: number) {
const contract = this.getContract();
return contract.methods.setSwapFee(fee).send({ from: this.address });
}

private getContract() {
return new this.web3.eth.Contract(ABI, CONTRACT_ADDRESS[this.chainId]);
}
Expand Down
33 changes: 1 addition & 32 deletions ethereum/fly/app/src/js/web3/contracts/Fly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ export const ABI = [
name: '_initialOwner',
type: 'address',
},
{
internalType: 'uint256',
name: '_swapFee',
type: 'uint256',
},
],
stateMutability: 'nonpayable',
type: 'constructor',
Expand Down Expand Up @@ -376,19 +371,6 @@ export const ABI = [
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [
{
internalType: 'uint256',
name: '_swapFee',
type: 'uint256',
},
],
name: 'setSwapFee',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [
{
Expand All @@ -404,20 +386,7 @@ export const ABI = [
],
name: 'swap',
outputs: [],
stateMutability: 'payable',
type: 'function',
},
{
inputs: [],
name: 'swapFee',
outputs: [
{
internalType: 'uint256',
name: '',
type: 'uint256',
},
],
stateMutability: 'view',
stateMutability: 'nonpayable',
type: 'function',
},
{
Expand Down
22 changes: 2 additions & 20 deletions ethereum/fly/contracts/Fly.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
contract Fly is ERC20, Ownable {
address private fly_canister_address;
uint8 private _decimals;
uint256 public swapFee;

uint256 private constant GOERLI_CHAIN_ID = 5;
uint256 private constant HARDHAT_CHAIN_ID = 31337;
Expand All @@ -22,11 +21,9 @@ contract Fly is ERC20, Ownable {
);

constructor(
address _initialOwner,
uint256 _swapFee
address _initialOwner
) ERC20("Fly", "FLY") Ownable(_initialOwner) {
_decimals = 12;
swapFee = _swapFee;
fly_canister_address = address(0);
}

Expand Down Expand Up @@ -99,20 +96,12 @@ contract Fly is ERC20, Ownable {
fly_canister_address = _fly_canister_address;
}

/**
* @dev Sets the swap fee.
* @param _swapFee The new swap fee.
*/
function setSwapFee(uint256 _swapFee) public isOwnerOrFlyCanister {
swapFee = _swapFee;
}

/**
* @dev Swaps the Fly tokens from Ethereum blockchain to IC from the caller to the recipient principal for the provided amount.
* @param _recipient The principal to receive the tokens.
* @param _amount The amount of tokens to swap.
*/
function swap(bytes32 _recipient, uint256 _amount) public payable {
function swap(bytes32 _recipient, uint256 _amount) public {
// check if the fly canister address is set
require(
fly_canister_address != address(0),
Expand All @@ -123,17 +112,10 @@ contract Fly is ERC20, Ownable {
balanceOf(msg.sender) >= _amount,
"Fly: caller does not have enough tokens to swap"
);
// check if the caller has enough ether to pay the fee
require(
msg.value >= swapFee,
"Fly: caller does not have enough ether to pay the fee"
);
// burn the tokens from the caller
_burn(msg.sender, _amount);
// emit swap event
emit FlySwapped(msg.sender, _recipient, _amount);
// pay fee
payable(fly_canister_address).transfer(msg.value);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions ethereum/fly/scripts/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ethers } from "hardhat";
require("dotenv").config();

const { OWNER_ADDRESS, SWAP_FEE } = process.env;
const { OWNER_ADDRESS } = process.env;

async function main() {
// deploy contract
const Contract = await ethers.getContractFactory("Fly");
const contract = await Contract.deploy(OWNER_ADDRESS!, SWAP_FEE!);
const contract = await Contract.deploy(OWNER_ADDRESS!);
await contract.waitForDeployment();
const address = await contract.getAddress();
console.log(`Contract deployed to ${address}`);
Expand Down
Loading

0 comments on commit e45e038

Please sign in to comment.