-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Fee to OriginalTokenBridge #6
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -307,6 +307,51 @@ describe("OriginalTokenBridge", () => { | |
}) | ||
}) | ||
|
||
describe("sets withdrawal fee", () => { | ||
const withdrawalFeeBps = 100 | ||
it("reverts when called by non owner", async () => { | ||
await expect(originalTokenBridge.connect(user).setWithdrawalFeeBps(withdrawalFeeBps)).to.be.revertedWith("Ownable: caller is not the owner") | ||
}) | ||
|
||
it("sets withdrawal fee", async () => { | ||
MayankMittal1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
await originalTokenBridge.setWithdrawalFeeBps(withdrawalFeeBps) | ||
expect(await originalTokenBridge.withdrawalFeeBps()).to.be.eq(withdrawalFeeBps) | ||
}) | ||
}) | ||
|
||
describe("bridges and withdraw fee", () => { | ||
const withdrawalFeeBps = 100 | ||
let fee | ||
let totalAmount | ||
beforeEach(async () => { | ||
await originalTokenBridge.setWithdrawalFeeBps(withdrawalFeeBps) | ||
fee = (await originalTokenBridge.estimateBridgeFee(false, adapterParams)).nativeFee | ||
totalAmount = amount + fee | ||
await originalToken.connect(user).approve(originalTokenBridge.target, amount) | ||
}) | ||
|
||
it("bridges ERC20 token and withdraws fees", async () => { | ||
await originalTokenBridge.registerToken(originalToken.target, sharedDecimals) | ||
await originalTokenBridge.connect(user).bridge(originalToken.target, amount, user.address, callParams, adapterParams, { value: fee }) | ||
const LDtoSD = await originalTokenBridge.LDtoSDConversionRate(originalToken.target) | ||
|
||
const withdrawalFee = (amount * BigInt(withdrawalFeeBps)) / BigInt(10000) / LDtoSD | ||
|
||
await originalTokenBridge.connect(owner).withdrawFee(originalToken.target, owner.address, withdrawalFee) | ||
expect(await originalToken.balanceOf(owner.address)).to.be.eq(withdrawalFee) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you check the following: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @leonprou I have updated the test which checks the total value locked for a token which is essentially the actual amount of token sent in the LZ message to be minted on the dest chain |
||
}) | ||
|
||
it("bridges WETH and withdraws fees", async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's actually bridging native, no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, this is what we will be using for FUSE token |
||
await originalTokenBridge.registerToken(weth.target, wethSharedDecimals) | ||
await originalTokenBridge.connect(user).bridgeNative(amount, user.address, callParams, adapterParams, { value: totalAmount }) | ||
|
||
const withdrawalFee = (amount * BigInt(withdrawalFeeBps)) / BigInt(10000) | ||
|
||
await originalTokenBridge.connect(owner).withdrawFee(weth.target, owner.address, withdrawalFee) | ||
expect(await weth.balanceOf(owner.address)).to.be.eq(withdrawalFee) | ||
}) | ||
}) | ||
|
||
describe("Upgrades Contract", () => { | ||
beforeEach(async () => { | ||
originalTokenBridgeV2Factory = await ethers.getContractFactory("OriginalTokenBridgeHarnessUpgradableV2") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check this flow with max and min values for uint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@leonprou why is that needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The user sends a really big amount of tokens, when it gets multiplied by
withdrawalFeeBps
an integer overflow might happen.