-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from 0xPolygon/staging
Staging
- Loading branch information
Showing
22 changed files
with
374 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,6 @@ dist | |
config.json | ||
.nuxt | ||
docs | ||
|
||
examples/package-lock.json | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
const { getLxLyClient, tokens, configuration, from } = require('../../utils_lxly'); | ||
|
||
// counter example smart contract on destination network. | ||
const CounterABI = [ | ||
{ | ||
"inputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "constructor" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "count", | ||
"outputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "", | ||
"type": "uint256" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "amount", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "increment", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "originAddress", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "uint32", | ||
"name": "originNetwork", | ||
"type": "uint32" | ||
}, | ||
{ | ||
"internalType": "bytes", | ||
"name": "metadata", | ||
"type": "bytes" | ||
} | ||
], | ||
"name": "onMessageReceived", | ||
"outputs": [], | ||
"stateMutability": "payable", | ||
"type": "function" | ||
} | ||
] | ||
|
||
const execute = async () => { | ||
const client = await getLxLyClient(); | ||
|
||
// set token as `eth`. | ||
const token = "0x0000000000000000000000000000000000000000"; | ||
// not bridging any token this time | ||
const amount = "0x0"; | ||
// because we are bridging from cardona. | ||
const sourceNetwork = 1; | ||
// sending to zkyoto | ||
const destinationNetwork = 0; | ||
// change it to the counter smart contract deployed on destination network. | ||
const callAddress = "0x43854F7B2a37fA13182BBEA76E50FC8e3D298CF1"; | ||
// if transaction fails, then the funds will be sent back to user's address on destination network. | ||
const fallbackAddress = from; | ||
// if true, then the global exit root will be updated. | ||
const forceUpdateGlobalExitRoot = true; | ||
// get the call Contract ABI instance. | ||
const callContract = client.contract(CounterABI, callAddress, destinationNetwork); | ||
// prepare the call data for the counter smart contract on destination chain. | ||
const callData = await callContract.encodeAbi("increment", "0x4"); | ||
|
||
let result; | ||
// Call bridgeAndCall function. | ||
if (client.client.network === "testnet") { | ||
console.log("testnet"); | ||
result = await client.bridgeExtensions[sourceNetwork].bridgeAndCall( | ||
token, | ||
amount, | ||
destinationNetwork, | ||
callAddress, | ||
fallbackAddress, | ||
callData, | ||
forceUpdateGlobalExitRoot, | ||
permitData="0x0", // permitData is optional | ||
) | ||
} else { | ||
console.log("mainnet"); | ||
result = await client.bridgeExtensions[sourceNetwork].bridgeAndCall( | ||
token, | ||
amount, | ||
destinationNetwork, | ||
callAddress, | ||
fallbackAddress, | ||
callData, | ||
forceUpdateGlobalExitRoot, | ||
) | ||
} | ||
|
||
console.log("result", result); | ||
const txHash = await result.getTransactionHash(); | ||
console.log("txHash", txHash); | ||
const receipt = await result.getReceipt(); | ||
console.log("receipt", receipt); | ||
} | ||
|
||
execute().then(() => { | ||
}).catch(err => { | ||
console.error("err", err); | ||
}).finally(_ => { | ||
process.exit(0); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const { getLxLyClient, tokens, configuration, from, to } = require('../../utils_lxly'); | ||
|
||
const execute = async () => { | ||
const client = await getLxLyClient(); | ||
// example bridge txn hash from the source chain. | ||
const bridgeTransactionHash = "0x6f312627ea607a39f494f49e8b40e9a71c61ad3173a6876f09dd9de7b540c040"; | ||
// Source Network ID, in this example its 1 since its from cardona. | ||
const sourceNetworkId = 1; | ||
// Destination Network ID, in this example its 0 since its to sepolia. | ||
const destinationNetworkId = 0; | ||
// API for building payload for claim | ||
// `bridgeIndex` is needed when there's multiple bridge events in a single txn. It is used to select the claim associated bridge event. | ||
const result = | ||
await client.bridgeUtil.buildPayloadForClaim(bridgeTransactionHash, sourceNetworkId, bridgeIndex=1) | ||
// payload is then passed to `claimMessage` API | ||
.then((payload) => { | ||
return client.bridges[destinationNetworkId].claimMessage( | ||
payload.smtProof, | ||
payload.smtProofRollup, | ||
payload.globalIndex, | ||
payload.mainnetExitRoot, | ||
payload.rollupExitRoot, | ||
payload.originNetwork, | ||
payload.originTokenAddress, | ||
payload.destinationNetwork, | ||
payload.destinationAddress, | ||
payload.amount, | ||
payload.metadata | ||
); | ||
}); | ||
|
||
const txHash = await result.getTransactionHash(); | ||
console.log("txHash", txHash); | ||
const receipt = await result.getReceipt(); | ||
console.log("receipt", receipt); | ||
} | ||
|
||
execute().then(() => { | ||
}).catch(err => { | ||
console.error("err", err); | ||
}).finally(_ => { | ||
process.exit(0); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default [{"type":"constructor","inputs":[{"name":"bridge_","type":"address","internalType":"address"}],"stateMutability":"nonpayable"},{"type":"function","name":"bridge","inputs":[],"outputs":[{"name":"","type":"address","internalType":"contract PolygonZkEVMBridgeV2"}],"stateMutability":"view"},{"type":"function","name":"bridgeAndCall","inputs":[{"name":"token","type":"address","internalType":"address"},{"name":"amount","type":"uint256","internalType":"uint256"},{"name":"destinationNetwork","type":"uint32","internalType":"uint32"},{"name":"callAddress","type":"address","internalType":"address"},{"name":"fallbackAddress","type":"address","internalType":"address"},{"name":"callData","type":"bytes","internalType":"bytes"},{"name":"forceUpdateGlobalExitRoot","type":"bool","internalType":"bool"}],"outputs":[],"stateMutability":"payable"},{"type":"function","name":"onMessageReceived","inputs":[{"name":"originAddress","type":"address","internalType":"address"},{"name":"originNetwork","type":"uint32","internalType":"uint32"},{"name":"data","type":"bytes","internalType":"bytes"}],"outputs":[],"stateMutability":"payable"},{"type":"error","name":"AmountDoesNotMatchMsgValue","inputs":[]},{"type":"error","name":"InvalidDepositIndex","inputs":[]},{"type":"error","name":"OriginMustBeBridgeExtension","inputs":[]},{"type":"error","name":"SenderMustBeBridge","inputs":[]},{"type":"error","name":"UnclaimedAsset","inputs":[]}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
export default [ | ||
{ "type": "constructor", "inputs": [], "stateMutability": "nonpayable" }, | ||
{ "type": "function", "name": "bridge", | ||
"inputs": [], | ||
"outputs": [ | ||
{ "name": "", "type": "address", "internalType": "contract PolygonZkEVMBridgeV2" } | ||
], "stateMutability": "view" | ||
}, | ||
{ "type": "function", "name": "bridgeAndCall", | ||
"inputs": [ | ||
{ "name": "token", "type": "address", "internalType": "address" }, | ||
{ "name": "amount", "type": "uint256", "internalType": "uint256" }, | ||
{ "name": "permitData", "type": "bytes", "internalType": "bytes" }, | ||
{ "name": "destinationNetwork", "type": "uint32", "internalType": "uint32" }, | ||
{ "name": "callAddress", "type": "address", "internalType": "address" }, | ||
{ "name": "fallbackAddress", "type": "address", "internalType": "address" }, | ||
{ "name": "callData", "type": "bytes", "internalType": "bytes" }, | ||
{ "name": "forceUpdateGlobalExitRoot", "type": "bool", "internalType": "bool" } | ||
], "outputs": [], "stateMutability": "payable" | ||
}, | ||
{ "type": "function", "name": "initialize", "inputs": [{ "name": "bridge_", "type": "address", "internalType": "address" }], "outputs": [], "stateMutability": "nonpayable" }, | ||
{ "type": "function", "name": "onMessageReceived", "inputs": [{ "name": "originAddress", "type": "address", "internalType": "address" }, { "name": "originNetwork", "type": "uint32", "internalType": "uint32" }, { "name": "data", "type": "bytes", "internalType": "bytes" }], "outputs": [], "stateMutability": "payable" }, | ||
{ "type": "event", "name": "Initialized", "inputs": [{ "name": "version", "type": "uint8", "indexed": false, "internalType": "uint8" }], "anonymous": false }, | ||
{ "type": "error", "name": "AmountDoesNotMatchMsgValue", "inputs": [] }, | ||
{ "type": "error", "name": "InvalidAddress", "inputs": [] }, | ||
{ "type": "error", "name": "InvalidDepositIndex", "inputs": [] }, | ||
{ "type": "error", "name": "OriginMustBeBridgeExtension", "inputs": [] }, | ||
{ "type": "error", "name": "SenderMustBeBridge", "inputs": [] }, | ||
{ "type": "error", "name": "UnclaimedAsset", "inputs": [] } | ||
] |
Oops, something went wrong.