-
Notifications
You must be signed in to change notification settings - Fork 166
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
const estimatedGas = BigNumber.from(60_000).mul(maxFeePerGas) | ||
|
||
if (isL2NetworkWithCustomFeeToken()) { | ||
const approvalTx = await ERC20__factory.connect( |
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.
This code should be inside approveGasToken
and getApproveGasTokenRequest
of AdminErc20Bridger
src/lib/assetBridger/erc20Bridger.ts
Outdated
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)) { |
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.
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)
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)) { |
src/lib/assetBridger/erc20Bridger.ts
Outdated
return num.add(num.mul(increase).div(100)) | ||
} | ||
|
||
public getApproveTokenRequestForCustomTokenRegistration( |
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.
Why do we need this method as well as getApproveGasTokenRequestForCustomTokenRegistration
?
src/lib/assetBridger/erc20Bridger.ts
Outdated
return num.add(num.mul(increase).div(100)) | ||
} | ||
|
||
public getApproveGasTokenRequestForCustomTokenRegistration( |
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.
public getApproveGasTokenRequestForCustomTokenRegistration( | |
public getApproveGasTokenForCustomTokenRegistrationRequest( |
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, | ||
}) | ||
} |
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.
for test simplicity we can just use max
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, | |
}) | |
} |
…bs/arbitrum-sdk into register-token-approval
registerCustomToken
for custom gas token chains
Closes FS-315