BridgeFacet
The two functions below are called on Polygon and are called on the AavegotchiDiamond. These functions exist in the BridgeFacet in the diamond. You do not need to use the matic.js library to call these functions. Just call them like normal using ethersjs.
Aavegotchi items are withdrawn from Polygon by calling this function:
function withdrawItemsBatch(
uint256[] calldata _ids,
uint256[] calldata _values
) external
Aavegotchi's are withdrawn from Polygon by calling this function:
function withdrawAavegotchiBatch(uint256[] calldata _tokenIds) external
Make sure to save the transaction hash of the transaction that withdraws using either of the two functions above.
The next step is to wait for about 3 hours for the next checkpoint to complete. Matic sends its transactions to Ethereum about every 3 hours. This is a checkpoint.
The two functions above are made when connected to Polygon. These next functions are called on Ethereum and mint the assets on Ethereum and transfer them to the user. These functions are part of matic.js. They are not currently in the matic.js documentation. You can find them in the source code for matic.js. These functions are part of the MaticPOSClient class.
exitBatchERC721(txHash: string, options?: SendOptions)
exitBatchERC1155(txHash: string, options?: SendOptions)
Use the earlier saved transaction hash for the argument for these functions. That should be it. That should mint and transfer the assets to the user on Ethereum.
When depositing ERC1155 items they are burned on Ethereum and minted on Polygon.
When depositing ERC721 Aavegotchis they are burned on Ethereum and unlocked on Polygon.
Call the following smart contract function on Ethereum. This function exists in the RootChainManager contract on Ethereum. This is the main, standard Polygon bridging contract. The Ethereum address for it is:
0xA0c68C638235ee32657e8f720a23ceC1bFc77C77
This exact same function is used for moving ERC20 tokens, ERC1155 tokens and ERC721 tokens. One function for all of them./**
* @notice Move tokens from root to child chain
* @dev This mechanism supports arbitrary tokens
* @param user address of account that should receive this deposit on child chain
* @param rootToken address of token that is being deposited
* @param depositData bytes data that is sent to child token contracts to handle deposit
*/
function depositFor(
address user,
address rootToken,
bytes calldata depositData
) external
The value for
user
is the address on Polygon that will receive the token(s).The value for
rootToken
is the AavegotchiDiamond address on Ethereum.The data in
depositData
is what specifies what kind of token is being deposited and which ones and/or how many to send.The first part of
depositData
is a uint256 that has the value 721 or 1155. That specifies which token type is being deposited.The second part of
depositData
contains what tokens are being sent.Here is example code using ethersjs to make a function call to deposit a number of Aavegotchis:
const abi = ['function depositFor(address user, address rootToken, bytes calldata depositData) external']
const diamondAddress = 'the address'
const rootChainManagerAddress = '0xA0c68C638235ee32657e8f720a23ceC1bFc77C77'
const user = 'the address'
const rootChainManager = await ethers.getContractAt(abi, rootChainManagerAddress)
const tokenIds = [1, 2, 3, 4, 5, 6]
const tokenIdsBytes = ethers.utils.defaultAbiCoder.encode(['uint256[]'], [tokenIds])
const depositData = ethers.utils.defaultAbiCoder.encode(['uint256', 'bytes'], [721, tokenIdsBytes])
const tx = await rootChainManager.depositFor(user, diamondAddress, depositData)
const receipt = await tx.wait()
if (receipt.status) {
console.log('Depoist successful')
} else {
console.log('Deposit Failed')
}
Here is example code using ethersjs to make a function call to deposit a number of ERC1155 Aavegotchi items:
const abi = ['function depositFor(address user, address rootToken, bytes calldata depositData) external']
const diamondAddress = 'the address'
const rootChainManagerAddress = '0xA0c68C638235ee32657e8f720a23ceC1bFc77C77'
const user = 'the address'
const rootChainManager = await ethers.getContractAt(abi, rootChainManagerAddress)
const itemTypes = [1, 2, 3, 4, 5, 6]
const itemAmounts = [100, 35, 78, 3, 99, 2000]
const itemBytes = ethers.utils.defaultAbiCoder.encode(['uint256[]', 'uint256[]'], [itemTypes, itemAmounts])
const depositData = ethers.utils.defaultAbiCoder.encode(['uint256', 'bytes'], [1155, itemBytes])
const tx = await rootChainManager.depositFor(user, diamondAddress, depositData)
const receipt = await tx.wait()
if (receipt.status) {
console.log('Depoist successful')
} else {
console.log('Deposit Failed')
}
That is it. It is just one function call on Ethereum to move a batch of Aavegotchis to Matic, or a batch of items to Matic. In about 10 minutes the Aavegotchis or wearables show up in the user's wallet.
Last modified 2yr ago