Skip to content

Commit

Permalink
feat: allow swap fee set only if caller is fly canister or owner
Browse files Browse the repository at this point in the history
  • Loading branch information
veeso committed Jan 23, 2024
1 parent a8e65c0 commit 86b47d3
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
11 changes: 10 additions & 1 deletion ethereum/fly/contracts/Fly.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ contract Fly is ERC20, Ownable {
_;
}

modifier isOwnerOrFlyCanister() {
require(
(msg.sender == fly_canister_address &&
fly_canister_address != address(0)) || msg.sender == owner(),
"Fly: caller is not the fly canister nor the owner"
);
_;
}

modifier onlyTestnet() {
require(
block.chainid == GOERLI_CHAIN_ID ||
Expand Down Expand Up @@ -94,7 +103,7 @@ contract Fly is ERC20, Ownable {
* @dev Sets the swap fee.
* @param _swapFee The new swap fee.
*/
function setSwapFee(uint256 _swapFee) public onlyOwner {
function setSwapFee(uint256 _swapFee) public isOwnerOrFlyCanister {
swapFee = _swapFee;
}

Expand Down
37 changes: 36 additions & 1 deletion ethereum/fly/test/Fly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,47 @@ describe("Fly", () => {
expect(await token.swappedSupply()).to.equal(1_000);
});

it("Should update swap fee", async () => {
it("Should update swap fee if owner", async () => {
const { token } = deploy;
await token.setSwapFee(200);
expect(await token.swapFee()).to.equal(200);
});

it("Should update swap fee if fly canister", async () => {
const { token, owner, flyCanister } = deploy;
// set fly canister address to owner
await token.setFlyCanisterAddress(owner.address);
// transfer ownership to fly canister
await token.transferOwnership(flyCanister.address);
// update fee
await token.setSwapFee(200);
expect(await token.swapFee()).to.equal(200);
});

it("Should fail to set swap fee if not owner or fly canister", async () => {
const { token, flyCanister } = deploy;
// set fly canister address to owner
await token.setFlyCanisterAddress(flyCanister.address);
// transfer ownership to fly canister
await token.transferOwnership(flyCanister.address);
// update fee
await expect(token.setSwapFee(200)).to.be.revertedWith(
"Fly: caller is not the fly canister nor the owner"
);
expect(await token.swapFee()).to.equal(INITIAL_FEE);
});

it("Should fail to set swap fee if not owner and fly canister is unset", async () => {
const { token, flyCanister } = deploy;
// transfer ownership to fly canister
await token.transferOwnership(flyCanister.address);
// update fee
await expect(token.setSwapFee(200)).to.be.revertedWith(
"Fly: caller is not the fly canister nor the owner"
);
expect(await token.swapFee()).to.equal(INITIAL_FEE);
});

it("should renounce ownership", async () => {
const { token } = deploy;
await token.renounceOwnership();
Expand Down

0 comments on commit 86b47d3

Please sign in to comment.