Skip to content

Commit b7d626b

Browse files
committed
Smol clarifications and fixes
1 parent 71243c1 commit b7d626b

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

packages/contract-deposit/scripts/exec.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ const main = async () => {
8282
console.log(`Sending deposit transaction...`);
8383

8484
let depositTx;
85+
let nativeTokenDecimals = 18; // We default to 18 decimals for ETH and most of ERC-20 tokens
8586
if (isCustomGasTokenChain) {
8687
// Approve the gas token to be sent to the contract
8788
console.log('Giving allowance to the contract to transfer the chain native token');
@@ -90,17 +91,20 @@ const main = async () => {
9091
ERC20__factory.abi,
9192
parentChainWallet,
9293
);
94+
nativeTokenDecimals = await nativeToken.decimals();
9395
const approvalTransaction = await nativeToken.approve(
9496
depositContract.address,
95-
ethers.utils.parseEther('1'),
97+
ethers.utils.parseUnits('1', nativeTokenDecimals),
9698
);
9799
const approvalTransactionReceipt = await approvalTransaction.wait();
98100
console.log(`Approval transaction receipt is: ${approvalTransactionReceipt.transactionHash}`);
99101

100-
depositTx = await depositContract.depositToChildChain(ethers.utils.parseEther('0.01'));
102+
depositTx = await depositContract.depositToChildChain(
103+
ethers.utils.parseUnits('0.01', nativeTokenDecimals),
104+
);
101105
} else {
102106
depositTx = await depositContract.depositToChildChain({
103-
value: ethers.utils.parseEther('0.01'),
107+
value: ethers.utils.parseEther('0.01'), // Here we know we are using ETH, so we can use parseEther
104108
});
105109
}
106110
const depositReceipt = await depositTx.wait();
@@ -176,7 +180,7 @@ const main = async () => {
176180
{
177181
from: contractAliasAddress,
178182
to: transferTo,
179-
l2CallValue: ethers.utils.parseEther('0.01'), // because we deposited 0.01 ether, so we also transfer 0.01 ether out here.
183+
l2CallValue: ethers.utils.parseUnits('0.01', nativeTokenDecimals), // because we deposited 0.01 ether, so we also transfer 0.01 ether out here.
180184
excessFeeRefundAddress: depositContract.address,
181185
callValueRefundAddress: depositContract.address,
182186
data: [],
@@ -204,7 +208,9 @@ const main = async () => {
204208
* we need to subtract it here so the transaction in the parent chain doesn't pay l2callvalue
205209
* and instead uses the alias balance on the child chain directly.
206210
*/
207-
const depositAmount = parentToChildMessageGasParams.deposit.sub(ethers.utils.parseEther('0.01'));
211+
const depositAmount = parentToChildMessageGasParams.deposit.sub(
212+
ethers.utils.parseUnits('0.01', nativeTokenDecimals),
213+
);
208214

209215
console.log(
210216
`Transfer funds txn needs ${ethers.utils.formatEther(
@@ -222,7 +228,7 @@ const main = async () => {
222228

223229
setTransferTx = await depositContract.moveFundsFromChildChainAliasToAnotherAddress(
224230
transferTo,
225-
ethers.utils.parseEther('0.01'), // because we deposited 0.01 ether, so we also transfer 0.01 ether out here.
231+
ethers.utils.parseUnits('0.01', nativeTokenDecimals), // because we deposited 0.01 ether, so we also transfer 0.01 ether out here.
226232
parentToChildMessageGasParams.maxSubmissionCost,
227233
parentToChildMessageGasParams.gasLimit,
228234
gasPriceBid,

packages/greeter/contracts/ethereum/GreeterParent.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ contract GreeterParent is Greeter {
3535
bytes memory data = abi.encodeWithSelector(Greeter.setGreeting.selector, _greeting);
3636

3737
// Find out if this chain uses a custom gas token
38+
// NOTE: in a real dApp, you don't need to perform this check since you'll
39+
// know what kind of chain you'll be deploying this contract to. We added this
40+
// check here to simplify showcasing how the Greeter contract works in any chain.
3841
address bridge = address(IInbox(inbox).bridge());
3942
address nativeToken;
4043
try IERC20Bridge(bridge).nativeToken() returns (address nativeTokenAddress) {

0 commit comments

Comments
 (0)