Created
June 30, 2023 13:23
-
-
Save antomor/56c5d85123b9de37ad21c8787f4b63c5 to your computer and use it in GitHub Desktop.
test-sdk
This file contains hidden or 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
{ | |
"name": "franklin-contracts", | |
"version": "0.1.0", | |
"license": "MIT", | |
"devDependencies": { | |
"@nomiclabs/hardhat-ethers": "^2.0.0", | |
"@nomiclabs/hardhat-etherscan": "^2.1.0", | |
"@nomiclabs/hardhat-solpp": "^2.0.0", | |
"@nomiclabs/hardhat-waffle": "^2.0.0", | |
"@typechain/ethers-v5": "^3.0.0", | |
"@types/argparse": "^1.0.36", | |
"@types/chai": "^4.2.14", | |
"@types/mocha": "^8.0.3", | |
"argparse": "^1.0.10", | |
"axios": "^0.21.2", | |
"chai": "^4.2.0", | |
"chalk": "^4.1.0", | |
"commander": "^6.0.0", | |
"ethereum-waffle": "^3.0.0", | |
"ethereumjs-abi": "^0.6.8", | |
"ethers": "^5.4.4", | |
"ethjs": "^0.4.0", | |
"fs": "^0.0.1-security", | |
"handlebars": "^4.7.7", | |
"hardhat": "^2.8.0", | |
"hardhat-contract-sizer": "^2.0.2", | |
"hardhat-typechain": "^0.3.3", | |
"jsonwebtoken": "^8.5.1", | |
"mocha": "^8.2.0", | |
"@rsksmart/rif-aggregation-sdk-js": "0.0.2", | |
"openzeppelin-solidity": "^2.3.0", | |
"path": "^0.12.7", | |
"prettier": "^1.18.2", | |
"prettier-plugin-solidity": "^1.0.0-alpha.27", | |
"querystring": "^0.2.0", | |
"solc": "0.7.4", | |
"ts-generator": "^0.1.1", | |
"ts-node": "^9.0.0", | |
"typechain": "^4.0.0", | |
"typescript": "^4.0.5", | |
"zksync": "file:../sdk/zksync.js" | |
}, | |
"scripts": { | |
"build": "hardhat compile", | |
"test": "cd ../sdk/zksync.js && yarn && yarn build && cd ../../contracts && rm -rf node_modules && yarn && CONTRACT_TESTS=1 zk f yarn run hardhat test test/*.spec.ts", | |
"test:fork": "cd ../sdk/zksync.js && yarn && yarn build && cd ../../contracts && rm -rf node_modules && yarn && CONTRACT_TESTS=1 TEST_CONTRACTS_FORK=1 zk f yarn run hardhat test test/*.fork.ts", | |
"deploy-no-build": "ts-node scripts/deploy.ts", | |
"upgrade-testnet-no-build": "ts-node scripts/upgrade-testnet.ts", | |
"deploy-eip1271": "ts-node scripts/deploy-eip1271.ts", | |
"deploy-erc20": "ts-node scripts/deploy-erc20.ts", | |
"deploy-withdrawal-helpers-contracts": "ts-node scripts/deploy-withdrawal-helpers.ts", | |
"governance-add-erc20": "ts-node scripts/governance-add-erc20.ts", | |
"server-add-erc20": "ts-node scripts/server-add-erc20.ts", | |
"token-info": "ts-node scripts/token-info.ts", | |
"deploy-testkit": "ts-node scripts/deploy-testkit.ts", | |
"publish-sources": "hardhat run --network env scripts/publish.ts", | |
"deploy-testnet-erc20": "ts-node scripts/deploy-testnet-token.ts", | |
"submit-hash-regenesis": "ts-node scripts/submit-hash-regenesis.ts", | |
"submit-regenesis-upgrade": "ts-node scripts/submit-regenesis-upgrade.ts", | |
"read-variable": "ts-node scripts/read-variable.ts", | |
"verify-deployed-contract": "ts-node scripts/verify-deployed-contract.ts", | |
"test-withdraw": "cd ../sdk/zksync.js && yarn && yarn build && cd ../../contracts && rm -rf node_modules && yarn && ts-node scripts/test-withdraw.ts", | |
"test-withdraw:direct": "ts-node scripts/test-withdraw.ts" | |
}, | |
"dependencies": { | |
"@openzeppelin/contracts": "3.4.2" | |
} | |
} |
This file contains hidden or 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
import { ethers } from "ethers"; | |
import { web3Provider } from "./utils"; | |
import * as zksync from 'zksync'; | |
async function printBalance(syncWallet: zksync.Wallet) { | |
const l1Balance = await syncWallet.getEthereumBalance("ETH"); | |
const l2Balance = await syncWallet.getBalance("ETH"); | |
console.log('L1 balance', l1Balance.toString()); | |
console.log('L2 balance', l2Balance.toString()); | |
} | |
/** | |
* It requires the Rollup system to be running locally | |
*/ | |
async function main() { | |
const privateKey = '<PRIVATE_KEY_HERE>'; | |
// const receiverAddress = '0x39B12C05E8503356E3a7DF0B7B33efA4c054C409'; // corresponding to private key | |
const receiverAddress = '0x3bffdae0d62b8a745337a85738dc18c0a23f78db'; // not the one associated with the private key | |
const amountToWithdraw = '5' | |
const ethersProvider = web3Provider(); | |
const ethWallet = new ethers.Wallet(privateKey).connect(ethersProvider); | |
const syncProvider = await zksync.Provider.newHttpProvider('http://127.0.0.1:3030', 500, 'localhost'); | |
// Derive zksync.Signer from ethereum wallet. | |
const syncWallet = await zksync.Wallet.fromEthSigner(ethWallet, syncProvider); | |
console.log('### Before'); | |
await printBalance(syncWallet); | |
// withdraw | |
/* const withdraw = await syncWallet.withdrawFromSyncToEthereum({ | |
ethAddress: receiverAddress, | |
token: 'ETH', | |
amount: ethers.utils.parseEther(amountToWithdraw) | |
}); | |
await withdraw.awaitVerifyReceipt(); */ | |
// withdraw pending balance | |
/* const withdrawPendingTx = await syncWallet.withdrawPendingBalance( | |
receiverAddress, | |
"ETH", | |
// ethers.utils.parseEther(amountToWithdraw) | |
); | |
// Wait till the transaction is complete | |
const txReceipt = await withdrawPendingTx.wait(); | |
console.log({txReceipt}); */ | |
// get pending balance | |
/* const zksyncContract = syncWallet.getZkSyncMainContract(); | |
const tokenAddress = syncWallet.provider.tokenSet.resolveTokenAddress("ETH"); | |
const pendingBalance = await zksyncContract.getPendingBalance(receiverAddress, tokenAddress); | |
console.log('### Pending balance', pendingBalance.toString()); */ | |
// deposit | |
const depositPriorityOperation = await syncWallet.depositToSyncFromEthereum({ | |
depositTo: receiverAddress, | |
token: "ETH", | |
amount: ethers.utils.parseEther("1.0"), | |
}); | |
// Wait till priority operation is committed. | |
const priorityOpReceipt = await depositPriorityOperation.awaitReceipt(); | |
console.log({priorityOpReceipt}) | |
console.log('### After'); | |
await printBalance(syncWallet); | |
} | |
main() | |
.then(() => process.exit(0)) | |
.catch((err) => { | |
console.error('Error:', err.message || err); | |
process.exit(1); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment