Skip to content
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

feat: approve gas token for custom token registration #477

Merged
merged 35 commits into from
Jun 12, 2024

Conversation

brtkx
Copy link
Contributor

@brtkx brtkx commented Jun 5, 2024

Closes FS-315

Copy link

vercel bot commented Jun 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
arbitrum-sdk ✅ Ready (Inspect) Visit Preview Jun 12, 2024 5:11pm

@cla-bot cla-bot bot added the cla-signed label Jun 5, 2024
@brtkx brtkx requested review from TucksonDev and spsjvc June 5, 2024 10:49
@brtkx brtkx marked this pull request as ready for review June 6, 2024 15:29
const estimatedGas = BigNumber.from(60_000).mul(maxFeePerGas)

if (isL2NetworkWithCustomFeeToken()) {
const approvalTx = await ERC20__factory.connect(
Copy link
Member

Choose a reason for hiding this comment

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

This code should be inside approveGasToken and getApproveGasTokenRequest of AdminErc20Bridger

Comment on lines 898 to 906
const gEstimator = new L1ToL2MessageGasEstimator(l2Provider)

// increase by 500%
const maxFeePerGas = (await gEstimator.estimateMaxFeePerGas()).mul(6)

// hardcode gas limit to 60k
const estimatedGas = BigNumber.from(60_000).mul(maxFeePerGas)

if (allowance.lt(estimatedGas)) {
Copy link
Member

Choose a reason for hiding this comment

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

you don't neeed to use L1ToL2MessageGasEstimator + let's use percentIncrease (we can copy it over from L1ToL2MessageGasEstimator https://github.com/OffchainLabs/arbitrum-sdk/blob/main/src/lib/message/L1ToL2MessageGasEstimator.ts#L76)

Suggested change
const gEstimator = new L1ToL2MessageGasEstimator(l2Provider)
// increase by 500%
const maxFeePerGas = (await gEstimator.estimateMaxFeePerGas()).mul(6)
// hardcode gas limit to 60k
const estimatedGas = BigNumber.from(60_000).mul(maxFeePerGas)
if (allowance.lt(estimatedGas)) {
const maxFeePerGasOnL2 = (await l2Provider.getFeeData()).maxFeePerGas
const maxFeePerGasOnL2WithBuffer = percentIncrease(maxFeePerGasOnL2, 500)
// hardcode gas limit to 60k
const estimatedGasFee = BigNumber.from(60_000).mul(maxFeePerGasOnL2WithBuffer)
if (allowance.lt(estimatedGasFee)) {

return num.add(num.mul(increase).div(100))
}

public getApproveTokenRequestForCustomTokenRegistration(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this method as well as getApproveGasTokenRequestForCustomTokenRegistration?

return num.add(num.mul(increase).div(100))
}

public getApproveGasTokenRequestForCustomTokenRegistration(
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public getApproveGasTokenRequestForCustomTokenRegistration(
public getApproveGasTokenForCustomTokenRegistrationRequest(

Comment on lines 229 to 242
const maxFeePerGasOnL2 = (await l2Signer.provider!.getFeeData()).maxFeePerGas
const maxFeePerGasOnL2WithBuffer = maxFeePerGasOnL2?.mul(7)
// hardcode gas limit to 60k
const estimatedGasFee = BigNumber.from(60_000).mul(
maxFeePerGasOnL2WithBuffer!
)

if (isL2NetworkWithCustomFeeToken()) {
await adminErc20Bridger.approveGasTokenForCustomTokenRegistration({
l1Signer,
amount: estimatedGasFee,
erc20L1Address: l1CustomToken.address,
})
}
Copy link
Member

Choose a reason for hiding this comment

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

for test simplicity we can just use max

Suggested change
const maxFeePerGasOnL2 = (await l2Signer.provider!.getFeeData()).maxFeePerGas
const maxFeePerGasOnL2WithBuffer = maxFeePerGasOnL2?.mul(7)
// hardcode gas limit to 60k
const estimatedGasFee = BigNumber.from(60_000).mul(
maxFeePerGasOnL2WithBuffer!
)
if (isL2NetworkWithCustomFeeToken()) {
await adminErc20Bridger.approveGasTokenForCustomTokenRegistration({
l1Signer,
amount: estimatedGasFee,
erc20L1Address: l1CustomToken.address,
})
}
if (isL2NetworkWithCustomFeeToken()) {
await adminErc20Bridger.approveGasTokenForCustomTokenRegistration({
l1Signer,
erc20L1Address: l1CustomToken.address,
})
}

@spsjvc spsjvc changed the title feat: add allowance error in registerCustomToken for custom gas token chains feat: approve gas token for custom token registration Jun 12, 2024
@spsjvc spsjvc self-requested a review June 12, 2024 17:12
@spsjvc spsjvc merged commit 47ba17b into main Jun 12, 2024
24 checks passed
@spsjvc spsjvc deleted the register-token-approval branch June 12, 2024 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants