Skip to content

Commit

Permalink
Cleanup for demo
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjimmutable committed Oct 30, 2023
1 parent 4eb7dda commit ad21f38
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
15 changes: 5 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,28 +148,23 @@ CHILD_GAS_SERVICE_ADDRESS="0xC573c722e21eD7fadD38A8f189818433e01Ae466"
./deploy.sh
```

4. Copy the config file with the correct addresses
```shell
cp axelar-local-dev/chain-config/local.template.json axelar-local-dev/chain-config/local.json
```

5. Run the script that will send a `MAP_TOKEN` message
4. Run the script that will send a `MAP_TOKEN` message
```shell
yarn run execute evm/call-contract local Ethereum Polygon map
```

6. (OPTIONAL) Check the token mapping has been populated using `cast`
5. (OPTIONAL) Check the token mapping has been populated using `cast`
```shell
source .env
cast call --rpc-url $CHILD_RPC_URL "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0" "rootTokenToChildToken(address)(address)" "0x38Aa1Cb12E5263eC0c6e9febC25B01116D346CD4"
```

7. Run the script that will send a `DEPOSIT` message
6. Run the script that will send a `DEPOSIT` message
```shell
yarn run execute evm/call-contract local Ethereum Polygon map
yarn run execute evm/call-contract local Ethereum Polygon deposit
```

8. (OPTIONAL) Check the tokens have been deposited using `cast`
7. (OPTIONAL) Check the tokens have been deposited using `cast`
```shell
source .env
cast call --rpc-url $CHILD_RPC_URL "0x3b39f73D7De57Ed2Fe85C0F30374D839dc625b93" "balanceOf(address)(uint256)" "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
Expand Down
19 changes: 14 additions & 5 deletions axelar-local-dev/examples/evm/call-contract/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ async function map(source, destination, calculateBridgeFee) {

async function logValue() {
let childTokenAddress = await destination.contract2.rootTokenToChildToken(TOKEN);
let rootChainChildTokenAddress = await source.contract.rootTokenToChildToken(TOKEN);
console.log("LAYER 1:")
console.log(`The L1 => L2 token mapping for token ${TOKEN.slice(0,8)}... is ${rootChainChildTokenAddress.slice(0,8)}...`)
console.log()
console.log("LAYER 2:")
console.log(`The L1 => L2 token mapping for token ${TOKEN.slice(0,8)}... is ${childTokenAddress.slice(0,8)}...`)
console.log()

if (childTokenAddress === ZERO_ADDRESS){
console.log("This is empty, indicating that the L1 token hasn't been deployed yet on L2. :( :(")
} else {
Expand All @@ -50,7 +57,9 @@ async function map(source, destination, calculateBridgeFee) {

console.log(`Calling mapToken with a service fee of ${fee} ETH`);
console.log()
await source.contract.mapToken(TOKEN, {value: fee})
const tx = await source.contract.mapToken(TOKEN, {value: fee})
await tx.wait()
await logValue();

const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

Expand All @@ -71,7 +80,7 @@ async function deposit(source, destination, calculateBridgeFee) {

const depositAmount = ethers.utils.parseEther("0.1")
const userAddress = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
const balanceOfAbi = `
const basicTokenAbi = `
[
{
"inputs": [
Expand Down Expand Up @@ -126,15 +135,15 @@ async function deposit(source, destination, calculateBridgeFee) {
}

// User ethers to call the balanceOf function on the TOKEN contract
let l2TokenContract = new ethers.Contract(l2TokenAddress, balanceOfAbi, destination.contract.signer)
let l1TokenContract = new ethers.Contract(TOKEN, balanceOfAbi, source.contract.signer)
let l2TokenContract = new ethers.Contract(l2TokenAddress, basicTokenAbi, destination.contract.signer)
let l1TokenContract = new ethers.Contract(TOKEN, basicTokenAbi, source.contract.signer)

const initialBal = await l2TokenContract.balanceOf(userAddress)

async function logValue() {
let l2Balance = await l2TokenContract.balanceOf(userAddress)
let l1Balance = await l1TokenContract.balanceOf(userAddress)
console.log(`The user currently has ${ethers.utils.formatEther(l2Balance).toString()} L2 token(s), and ${ethers.utils.formatEther(l1Balance).toString()} L1 token(s)`)
console.log(`The user currently has ${ethers.utils.formatEther(l1Balance).toString()} L1 token(s), and ${ethers.utils.formatEther(l2Balance).toString()} L2 token(s)`)
console.log()
}

Expand Down

0 comments on commit ad21f38

Please sign in to comment.