Skip to content

Commit 533c391

Browse files
committed
script to commit matic xc transfers
1 parent c88e44a commit 533c391

File tree

5 files changed

+470
-30
lines changed

5 files changed

+470
-30
lines changed

hardhat.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ module.exports = {
9494
url: 'https://eth-goerli.alchemyapi.io/v2/' + process.env.ALCHEMY_SECRET
9595
},
9696
dev2MumbaiSatChain: {
97-
url: 'https://matic-testnet-archive-rpc.bwarelabs.com'
97+
url: 'https://polygon-mumbai.infura.io/v3/' + process.env.INFURA_SECRET
9898
},
9999

100100
prodEthereumBaseChain: {

helpers/contracts.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ const getCompiledContractFactory = (ethers, contract) => {
5050
};
5151

5252
const deployContract = async (ethers, contractName, signer, args, txParams) => {
53-
console.log("Deploying", contractName)
53+
console.log('Deploying', contractName);
5454
const Factory = await getCompiledContractFactory(ethers, contractName);
5555
const contract = await Factory.connect(signer).deploy(...args, txParams);
5656
await contract.deployTransaction.wait(2);
57-
console.log("Deployed")
57+
console.log('Deployed');
5858
return contract;
5959
};
6060

@@ -71,7 +71,7 @@ const deployProxyContract = async (
7171
initializerDef,
7272
txParams,
7373
) => {
74-
console.log("Deploying proxy", contractName)
74+
console.log('Deploying proxy', contractName);
7575
const ProxyAdminFactory = await getCompiledContractFactory(
7676
ethers,
7777
'ProxyAdmin',
@@ -84,7 +84,7 @@ const deployProxyContract = async (
8484
txParams,
8585
);
8686
await contract.deployTransaction.wait(2);
87-
console.log("Deployed")
87+
console.log('Deployed');
8888

8989
const defaultProxyAdmin = ProxyAdminFactory.connect(signer).attach(
9090
await getAdminAddress(signer.provider, contract.address),

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"lint"
1919
],
2020
"dependencies": {
21+
"@maticnetwork/maticjs": "^2.0.43",
2122
"@openzeppelin/contracts": "^3.4.0",
2223
"@openzeppelin/contracts-upgradeable": "^3.3.0",
2324
"@openzeppelin/upgrades": "^2.8.0",

tasks/ops/xc_transfer.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,47 @@ txTask('matic:xc_transfer', 'Executes cross chain transfer through matic')
163163

164164
console.log(txR.transactionHash);
165165
});
166+
167+
txTask(
168+
'matic:xc_transfer:commit',
169+
'Commits the cross chain transfer from matic to base chain',
170+
)
171+
.addParam('txHash', 'The transaction hash of the xc transfer on matic')
172+
.addParam('baseChainNetwork', 'The network name base chain')
173+
.addParam('satChainNetwork', 'The network name matic satellite chain')
174+
.setAction(async (args, hre) => {
175+
const baseChainProvider = getEthersProvider(args.baseChainNetwork);
176+
const satChainProvider = getEthersProvider(args.satChainNetwork);
177+
178+
const txParams = { gasPrice: args.gasPrice, gasLimit: args.gasLimit };
179+
if (txParams.gasPrice == 0) {
180+
txParams.gasPrice = await baseChainProvider.getGasPrice();
181+
}
182+
const sender = await loadSignerSync(args, baseChainProvider);
183+
const senderAddress = await sender.getAddress();
184+
console.log('Sender:', senderAddress);
185+
186+
const baseChainTransferGateway = await getDeployedContractInstance(
187+
args.baseChainNetwork,
188+
'matic/transferGateway',
189+
baseChainProvider,
190+
);
191+
192+
const maticPOSClient = new require('@maticnetwork/maticjs').MaticPOSClient({
193+
network: baseChainProvider.includes('prod') ? 'mainnet' : 'testnet',
194+
version: baseChainProvider.includes('prod') ? 'v1' : 'mumbai',
195+
maticProvider: satChainProvider.connection.url,
196+
parentProvider: baseChainProvider.connection.url,
197+
});
198+
199+
const proof = await maticPOSClient.posRootChainManager.customPayload(
200+
args.txHash,
201+
await baseChainTransferGateway.SEND_MESSAGE_EVENT_SIG(),
202+
);
203+
204+
const tx = await baseChainTransferGateway
205+
.connect(sender)
206+
.receiveMessage(proof);
207+
const txR = await tx.wait();
208+
console.log(txR.transactionHash);
209+
});

0 commit comments

Comments
 (0)