|
@@ -1,159 +1,159 @@
|
|
|
-package com.ichaoj.ams.script.zksync.era;
|
|
|
-
|
|
|
-import cn.hutool.core.collection.ListUtil;
|
|
|
-import com.ichaoj.ams.script.IScript;
|
|
|
-import com.ichaoj.ams.script.annotation.Script;
|
|
|
-import com.ichaoj.ams.script.annotation.ScriptParam;
|
|
|
-import com.ichaoj.ams.script.model.AirdropParam;
|
|
|
-import com.ichaoj.ams.script.model.AirdropWallet;
|
|
|
-import com.ichaoj.ams.script.util.Web3Util;
|
|
|
-import lombok.SneakyThrows;
|
|
|
-import org.web3j.abi.FunctionEncoder;
|
|
|
-import org.web3j.abi.TypeReference;
|
|
|
-import org.web3j.abi.datatypes.*;
|
|
|
-import org.web3j.abi.datatypes.generated.Uint8;
|
|
|
-import org.web3j.protocol.Web3j;
|
|
|
-import org.web3j.protocol.core.DefaultBlockParameterName;
|
|
|
-import org.web3j.protocol.core.methods.request.Transaction;
|
|
|
-import org.web3j.protocol.core.methods.response.EthGasPrice;
|
|
|
-import org.web3j.protocol.core.methods.response.EthGetTransactionCount;
|
|
|
-import org.web3j.protocol.http.HttpService;
|
|
|
-import org.web3j.utils.Convert;
|
|
|
-import org.web3j.utils.Numeric;
|
|
|
-
|
|
|
-import java.math.BigInteger;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
-/**
|
|
|
- * zkSyncEra script
|
|
|
- * //todo 假设原生代币已经转入了子钱包
|
|
|
- *
|
|
|
- * @author wren
|
|
|
- */
|
|
|
-@Script(name = "zkSyncEra",
|
|
|
- params = {
|
|
|
-
|
|
|
- @ScriptParam(name = "swapAmount", note = "swap金额")
|
|
|
- }
|
|
|
-)
|
|
|
-public class ZkSyncEraScript extends IScript {
|
|
|
- private final String POOL_FACTORY = "0xf2DAd89f2788a8CD54625C60b55cD3d2D0ACa7Cb";
|
|
|
- private final String W_ETH = "0x5aea5775959fbc2557cc8789bc1bf90a239d9a91";
|
|
|
- private final String USDC = "0x3355df6D4c9C3035724Fd0e3914dE96A5a83aaf4";
|
|
|
-
|
|
|
- private final String ROUTER = "0x2da10A1e27bF85cEdD8FFb1AbBe97e53391C0295";
|
|
|
-
|
|
|
- private final String ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
|
-
|
|
|
-// 0x2cc4081e
|
|
|
-// 0000000000000000000000000000000000000000000000000000000000000060
|
|
|
-// 00000000000000000000000000000000000000000000000000000000001b6171
|
|
|
-// 00000000000000000000000000000000000000000000000000000000647084d2
|
|
|
-// 0000000000000000000000000000000000000000000000000000000000000001
|
|
|
-// 0000000000000000000000000000000000000000000000000000000000000020
|
|
|
-// 0000000000000000000000000000000000000000000000000000000000000060
|
|
|
-// 0000000000000000000000000000000000000000000000000000000000000000
|
|
|
-// 00000000000000000000000000000000000000000000000000038d7ea4c68000
|
|
|
-// 0000000000000000000000000000000000000000000000000000000000000001
|
|
|
-// 0000000000000000000000000000000000000000000000000000000000000020
|
|
|
-// 00000000000000000000000080115c708e12edd42e504c1cd52aea96c547c05c
|
|
|
-// 0000000000000000000000000000000000000000000000000000000000000080
|
|
|
-// 0000000000000000000000000000000000000000000000000000000000000000
|
|
|
-// 0000000000000000000000000000000000000000000000000000000000000100
|
|
|
-// 0000000000000000000000000000000000000000000000000000000000000060
|
|
|
-// 0000000000000000000000005aea5775959fbc2557cc8789bc1bf90a239d9a91
|
|
|
-// 000000000000000000000000368715f09c1ab5e0b55bf5ba19cd887189a28dbe address
|
|
|
-// 0000000000000000000000000000000000000000000000000000000000000002
|
|
|
-// 0000000000000000000000000000000000000000000000000000000000000000
|
|
|
-
|
|
|
-// 0x0054ed6a
|
|
|
-// 0000000000000000000000000000000000000000000000000000000000000060
|
|
|
-// 0000000000000000000000000000000000000000000000000000000000000000
|
|
|
-// 00000000000000000000000000000000000000000000000000000000647570f3
|
|
|
-// 0000000000000000000000000000000000000000000000000000000000000001
|
|
|
-// 0000000000000000000000000000000000000000000000000000000000000001
|
|
|
-// 00000000000000000000000080115c708e12edd42e504c1cd52aea96c547c05c
|
|
|
-// 0000000000000000000000000000000000000000000000000000000000000060
|
|
|
-// 0000000000000000000000005aea5775959fbc2557cc8789bc1bf90a239d9a91
|
|
|
-// 000000000000000000000000368715f09c1ab5e0b55bf5ba19cd887189a28dbe
|
|
|
-// 0000000000000000000000000000000000000000000000000000000000000001
|
|
|
-// 0000000000000000000000000000000000000000000000000000000000000000
|
|
|
-// 0000000000000000000000000000000000000000000000000000000000000000
|
|
|
-// 0000000000000000000000000000000000000000000000000000000000000000
|
|
|
-// 00000000000000000000000000000000000000000000000000005af3107a4000
|
|
|
-
|
|
|
- @SneakyThrows
|
|
|
- @Override
|
|
|
- public String run(Map<String, AirdropParam> params, AirdropWallet airdropWallet) {
|
|
|
-
|
|
|
-
|
|
|
- Web3j web3j = Web3j.build(new HttpService("https://mainnet.era.zksync.io"));
|
|
|
- Address poolAddress = new Address("0x80115c708E12eDd42E504c1cD52Aea96C547c05c");
|
|
|
-
|
|
|
-// 0x0000000000000000000000005aea5775959fbc2557cc8789bc1bf90a239d9a91000000000000000000000000368715f09c1ab5e0b55bf5ba19cd887189a28dbe0000000000000000000000000000000000000000000000000000000000000001
|
|
|
-// 0x0000000000000000000000005aea5775959fbc2557cc8789bc1bf90a239d9a91000000000000000000000000368715f09c1ab5e0b55bf5ba19cd887189a28dbe0000000000000000000000000000000000000000000000000000000000000001
|
|
|
- String data = "0x" + FunctionEncoder.encodeConstructor(ListUtil.of(
|
|
|
- new Address(W_ETH),
|
|
|
- new Address(airdropWallet.getAddress()),
|
|
|
- new Uint8(1)));
|
|
|
- // build SwapSteps --step1
|
|
|
- DynamicArray<StaticStruct> steps = new DynamicArray<>(StaticStruct.class, ListUtil.of(new StaticStruct(
|
|
|
- poolAddress,
|
|
|
- new DynamicBytes(Numeric.hexStringToByteArray(data)),
|
|
|
- new Address(ZERO_ADDRESS),
|
|
|
- new DynamicBytes(Numeric.hexStringToByteArray("0x")))));
|
|
|
- BigInteger swapAmount = Convert.toWei(params.get("swapAmount").getValue(), Convert.Unit.ETHER).toBigInteger();
|
|
|
- // build SwapPaths --step2
|
|
|
- DynamicArray<StaticStruct> paths = new DynamicArray<>(StaticStruct.class, ListUtil.of(new StaticStruct(
|
|
|
- steps,
|
|
|
- new Address(ZERO_ADDRESS),
|
|
|
- new Uint(swapAmount))));
|
|
|
-
|
|
|
- Function swap = new Function("swap",
|
|
|
- ListUtil.of(
|
|
|
- paths,
|
|
|
- new Uint(BigInteger.ZERO),
|
|
|
- new Uint(BigInteger.valueOf(System.currentTimeMillis() / 1000 + 1800))),
|
|
|
- ListUtil.of(new TypeReference<TokenAmount>() {
|
|
|
- }));
|
|
|
- String swapEncoder = FunctionEncoder.encode(swap);
|
|
|
-
|
|
|
- BigInteger nonce;
|
|
|
- EthGetTransactionCount transactionCount = web3j.ethGetTransactionCount(airdropWallet.getAddress(), DefaultBlockParameterName.PENDING).send();
|
|
|
- if (transactionCount == null) {
|
|
|
- throw new RuntimeException("Failed to get nonce");
|
|
|
- }
|
|
|
- nonce = transactionCount.getTransactionCount();
|
|
|
- BigInteger gasPrice;
|
|
|
- EthGasPrice ethGasPrice = web3j.ethGasPrice().sendAsync().get();
|
|
|
- if (ethGasPrice == null) {
|
|
|
- throw new RuntimeException("Failed to get GasPrice");
|
|
|
- }
|
|
|
- gasPrice = ethGasPrice.getGasPrice();
|
|
|
- Transaction callTransaction = Transaction.createFunctionCallTransaction(
|
|
|
- airdropWallet.getAddress(),
|
|
|
- nonce,
|
|
|
- gasPrice,
|
|
|
- BigInteger.valueOf(0),
|
|
|
- ROUTER,
|
|
|
- swapAmount,
|
|
|
- swapEncoder);
|
|
|
-
|
|
|
-
|
|
|
- BigInteger gasLimit = Web3Util.getTransactionGasLimit(web3j, callTransaction);
|
|
|
-
|
|
|
-// RawTransaction rawTransaction = RawTransaction.createTransaction(nonce, gasPrice, gasLimit, ROUTER, swapEncoder);
|
|
|
-// //签名
|
|
|
-// Credentials credentials = Web3Util.getCredentials(airdropWallet);
|
|
|
-// byte[] signMessage = TransactionEncoder.signMessage(rawTransaction, credentials);
|
|
|
-// String hexValue = Numeric.toHexString(signMessage);
|
|
|
-// //发送交易
|
|
|
-// EthSendTransaction ethSendTransaction = web3j.ethSendRawTransaction(hexValue).sendAsync().get();
|
|
|
-// Response.Error error = ethSendTransaction.getError();
|
|
|
-// if (error != null) {
|
|
|
-// throw new RuntimeException(error.getMessage());
|
|
|
+//package com.ichaoj.ams.script.zksync.era;
|
|
|
+//
|
|
|
+//import cn.hutool.core.collection.ListUtil;
|
|
|
+//import com.ichaoj.ams.script.IScript;
|
|
|
+//import com.ichaoj.ams.script.annotation.Script;
|
|
|
+//import com.ichaoj.ams.script.annotation.ScriptParam;
|
|
|
+//import com.ichaoj.ams.script.model.AirdropParam;
|
|
|
+//import com.ichaoj.ams.script.model.AirdropWallet;
|
|
|
+//import com.ichaoj.ams.script.util.Web3Util;
|
|
|
+//import lombok.SneakyThrows;
|
|
|
+//import org.web3j.abi.FunctionEncoder;
|
|
|
+//import org.web3j.abi.TypeReference;
|
|
|
+//import org.web3j.abi.datatypes.*;
|
|
|
+//import org.web3j.abi.datatypes.generated.Uint8;
|
|
|
+//import org.web3j.protocol.Web3j;
|
|
|
+//import org.web3j.protocol.core.DefaultBlockParameterName;
|
|
|
+//import org.web3j.protocol.core.methods.request.Transaction;
|
|
|
+//import org.web3j.protocol.core.methods.response.EthGasPrice;
|
|
|
+//import org.web3j.protocol.core.methods.response.EthGetTransactionCount;
|
|
|
+//import org.web3j.protocol.http.HttpService;
|
|
|
+//import org.web3j.utils.Convert;
|
|
|
+//import org.web3j.utils.Numeric;
|
|
|
+//
|
|
|
+//import java.math.BigInteger;
|
|
|
+//import java.util.Map;
|
|
|
+//
|
|
|
+///**
|
|
|
+// * zkSyncEra script
|
|
|
+// * //todo 假设原生代币已经转入了子钱包
|
|
|
+// *
|
|
|
+// * @author wren
|
|
|
+// */
|
|
|
+//@Script(name = "zkSyncEra",
|
|
|
+// params = {
|
|
|
+//
|
|
|
+// @ScriptParam(name = "swapAmount", note = "swap金额")
|
|
|
// }
|
|
|
- return gasLimit.toString();
|
|
|
-
|
|
|
- }
|
|
|
-}
|
|
|
+//)
|
|
|
+//public class ZkSyncEraScript extends IScript {
|
|
|
+// private final String POOL_FACTORY = "0xf2DAd89f2788a8CD54625C60b55cD3d2D0ACa7Cb";
|
|
|
+// private final String W_ETH = "0x5aea5775959fbc2557cc8789bc1bf90a239d9a91";
|
|
|
+// private final String USDC = "0x3355df6D4c9C3035724Fd0e3914dE96A5a83aaf4";
|
|
|
+//
|
|
|
+// private final String ROUTER = "0x2da10A1e27bF85cEdD8FFb1AbBe97e53391C0295";
|
|
|
+//
|
|
|
+// private final String ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
|
+//
|
|
|
+//// 0x2cc4081e
|
|
|
+//// 0000000000000000000000000000000000000000000000000000000000000060
|
|
|
+//// 00000000000000000000000000000000000000000000000000000000001b6171
|
|
|
+//// 00000000000000000000000000000000000000000000000000000000647084d2
|
|
|
+//// 0000000000000000000000000000000000000000000000000000000000000001
|
|
|
+//// 0000000000000000000000000000000000000000000000000000000000000020
|
|
|
+//// 0000000000000000000000000000000000000000000000000000000000000060
|
|
|
+//// 0000000000000000000000000000000000000000000000000000000000000000
|
|
|
+//// 00000000000000000000000000000000000000000000000000038d7ea4c68000
|
|
|
+//// 0000000000000000000000000000000000000000000000000000000000000001
|
|
|
+//// 0000000000000000000000000000000000000000000000000000000000000020
|
|
|
+//// 00000000000000000000000080115c708e12edd42e504c1cd52aea96c547c05c
|
|
|
+//// 0000000000000000000000000000000000000000000000000000000000000080
|
|
|
+//// 0000000000000000000000000000000000000000000000000000000000000000
|
|
|
+//// 0000000000000000000000000000000000000000000000000000000000000100
|
|
|
+//// 0000000000000000000000000000000000000000000000000000000000000060
|
|
|
+//// 0000000000000000000000005aea5775959fbc2557cc8789bc1bf90a239d9a91
|
|
|
+//// 000000000000000000000000368715f09c1ab5e0b55bf5ba19cd887189a28dbe address
|
|
|
+//// 0000000000000000000000000000000000000000000000000000000000000002
|
|
|
+//// 0000000000000000000000000000000000000000000000000000000000000000
|
|
|
+//
|
|
|
+//// 0x0054ed6a
|
|
|
+//// 0000000000000000000000000000000000000000000000000000000000000060
|
|
|
+//// 0000000000000000000000000000000000000000000000000000000000000000
|
|
|
+//// 00000000000000000000000000000000000000000000000000000000647570f3
|
|
|
+//// 0000000000000000000000000000000000000000000000000000000000000001
|
|
|
+//// 0000000000000000000000000000000000000000000000000000000000000001
|
|
|
+//// 00000000000000000000000080115c708e12edd42e504c1cd52aea96c547c05c
|
|
|
+//// 0000000000000000000000000000000000000000000000000000000000000060
|
|
|
+//// 0000000000000000000000005aea5775959fbc2557cc8789bc1bf90a239d9a91
|
|
|
+//// 000000000000000000000000368715f09c1ab5e0b55bf5ba19cd887189a28dbe
|
|
|
+//// 0000000000000000000000000000000000000000000000000000000000000001
|
|
|
+//// 0000000000000000000000000000000000000000000000000000000000000000
|
|
|
+//// 0000000000000000000000000000000000000000000000000000000000000000
|
|
|
+//// 0000000000000000000000000000000000000000000000000000000000000000
|
|
|
+//// 00000000000000000000000000000000000000000000000000005af3107a4000
|
|
|
+//
|
|
|
+// @SneakyThrows
|
|
|
+// @Override
|
|
|
+// public String run(Map<String, AirdropParam> params, AirdropWallet airdropWallet) {
|
|
|
+//
|
|
|
+//
|
|
|
+// Web3j web3j = Web3j.build(new HttpService("https://mainnet.era.zksync.io"));
|
|
|
+// Address poolAddress = new Address("0x80115c708E12eDd42E504c1cD52Aea96C547c05c");
|
|
|
+//
|
|
|
+//// 0x0000000000000000000000005aea5775959fbc2557cc8789bc1bf90a239d9a91000000000000000000000000368715f09c1ab5e0b55bf5ba19cd887189a28dbe0000000000000000000000000000000000000000000000000000000000000001
|
|
|
+//// 0x0000000000000000000000005aea5775959fbc2557cc8789bc1bf90a239d9a91000000000000000000000000368715f09c1ab5e0b55bf5ba19cd887189a28dbe0000000000000000000000000000000000000000000000000000000000000001
|
|
|
+// String data = "0x" + FunctionEncoder.encodeConstructor(ListUtil.of(
|
|
|
+// new Address(W_ETH),
|
|
|
+// new Address(airdropWallet.getAddress()),
|
|
|
+// new Uint8(1)));
|
|
|
+// // build SwapSteps --step1
|
|
|
+// org.web3j.abi.datatypes.DynamicArray<StaticStruct> steps = new org.web3j.abi.datatypes.DynamicArray<>(StaticStruct.class, ListUtil.of(new StaticStruct(
|
|
|
+// poolAddress,
|
|
|
+// new DynamicBytes(Numeric.hexStringToByteArray(data)),
|
|
|
+// new Address(ZERO_ADDRESS),
|
|
|
+// new DynamicBytes(Numeric.hexStringToByteArray("0x")))));
|
|
|
+// BigInteger swapAmount = Convert.toWei(params.get("swapAmount").getValue(), Convert.Unit.ETHER).toBigInteger();
|
|
|
+// // build SwapPaths --step2
|
|
|
+// org.web3j.abi.datatypes.DynamicArray<StaticStruct> paths = new org.web3j.abi.datatypes.DynamicArray<>(StaticStruct.class, ListUtil.of(new StaticStruct(
|
|
|
+// steps,
|
|
|
+// new Address(ZERO_ADDRESS),
|
|
|
+// new Uint(swapAmount))));
|
|
|
+//
|
|
|
+// Function swap = new Function("swap",
|
|
|
+// ListUtil.of(
|
|
|
+// paths,
|
|
|
+// new Uint(BigInteger.ZERO),
|
|
|
+// new Uint(BigInteger.valueOf(System.currentTimeMillis() / 1000 + 1800))),
|
|
|
+// ListUtil.of(new TypeReference<TokenAmount>() {
|
|
|
+// }));
|
|
|
+// String swapEncoder = FunctionEncoder.encode(swap);
|
|
|
+//
|
|
|
+// BigInteger nonce;
|
|
|
+// EthGetTransactionCount transactionCount = web3j.ethGetTransactionCount(airdropWallet.getAddress(), DefaultBlockParameterName.PENDING).send();
|
|
|
+// if (transactionCount == null) {
|
|
|
+// throw new RuntimeException("Failed to get nonce");
|
|
|
+// }
|
|
|
+// nonce = transactionCount.getTransactionCount();
|
|
|
+// BigInteger gasPrice;
|
|
|
+// EthGasPrice ethGasPrice = web3j.ethGasPrice().sendAsync().get();
|
|
|
+// if (ethGasPrice == null) {
|
|
|
+// throw new RuntimeException("Failed to get GasPrice");
|
|
|
+// }
|
|
|
+// gasPrice = ethGasPrice.getGasPrice();
|
|
|
+// Transaction callTransaction = Transaction.createFunctionCallTransaction(
|
|
|
+// airdropWallet.getAddress(),
|
|
|
+// nonce,
|
|
|
+// gasPrice,
|
|
|
+// BigInteger.valueOf(0),
|
|
|
+// ROUTER,
|
|
|
+// swapAmount,
|
|
|
+// swapEncoder);
|
|
|
+//
|
|
|
+//
|
|
|
+// BigInteger gasLimit = Web3Util.getTransactionGasLimit(web3j, callTransaction);
|
|
|
+//
|
|
|
+//// RawTransaction rawTransaction = RawTransaction.createTransaction(nonce, gasPrice, gasLimit, ROUTER, swapEncoder);
|
|
|
+//// //签名
|
|
|
+//// Credentials credentials = Web3Util.getCredentials(airdropWallet);
|
|
|
+//// byte[] signMessage = TransactionEncoder.signMessage(rawTransaction, credentials);
|
|
|
+//// String hexValue = Numeric.toHexString(signMessage);
|
|
|
+//// //发送交易
|
|
|
+//// EthSendTransaction ethSendTransaction = web3j.ethSendRawTransaction(hexValue).sendAsync().get();
|
|
|
+//// Response.Error error = ethSendTransaction.getError();
|
|
|
+//// if (error != null) {
|
|
|
+//// throw new RuntimeException(error.getMessage());
|
|
|
+//// }
|
|
|
+// return gasLimit.toString();
|
|
|
+//
|
|
|
+// }
|
|
|
+//}
|