Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 0.4.0 #44

Merged
merged 9 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
run: |
git clone https://github.com/matter-labs/local-setup.git
pushd local-setup
./start.sh
./start-zk-chains.sh
popd
- name: Test with Gradle
run: gradle clean test
29 changes: 25 additions & 4 deletions src/main/java/io/zksync/methods/request/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ public class Transaction {
private String to;
private BigInteger gas;
private BigInteger gasPrice;
private BigInteger maxFeePerGas;
private BigInteger maxPriorityFeePerGas;
private BigInteger value;
private String data;

private Long transactionType;
private Long type;
private AccessListObject accessList;
private Eip712Meta eip712Meta;

Expand All @@ -47,7 +49,20 @@ public Transaction(String from, String to, BigInteger gas, BigInteger gasPrice,
this.data = data;
this.eip712Meta = eip712Meta;

this.transactionType = (long) Transaction712.EIP_712_TX_TYPE;
this.type = (long) Transaction712.EIP_712_TX_TYPE;
}

public Transaction(String from, String to, BigInteger gas, BigInteger maxFeePerGas, BigInteger maxPriorityFeePerGas, BigInteger value, String data, Eip712Meta eip712Meta) {
this.from = from;
this.to = to;
this.gas = gas;
this.maxFeePerGas = maxFeePerGas;
this.maxPriorityFeePerGas = maxPriorityFeePerGas;
this.value = value;
this.data = data;
this.eip712Meta = eip712Meta;

this.type = (long) Transaction712.EIP_712_TX_TYPE;
}

public static Transaction createEtherTransaction(
Expand Down Expand Up @@ -351,6 +366,12 @@ public String getGas() {
public String getGasPrice() {
return convert(gasPrice);
}
public BigInteger getMaxFeePerGas() {
return maxFeePerGas;
}
public BigInteger getMaxPriorityFeePerGas() {
return maxPriorityFeePerGas;
}

public String getValue() {
return convert(value);
Expand All @@ -375,8 +396,8 @@ public String getData() {
return data;
}

public String getTransactionType() {
return convert(BigInteger.valueOf(transactionType));
public String getType() {
return convert(BigInteger.valueOf(type));
}

public AccessListObject getAccessList() {
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/io/zksync/methods/response/ZksFeeParams.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.zksync.methods.response;

import io.zksync.protocol.core.FeeParams;
import org.web3j.protocol.core.Response;

public class ZksFeeParams extends Response<FeeParams> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.zksync.methods.response;

import io.zksync.protocol.core.ProtocolVersion;
import org.web3j.protocol.core.Response;

public class ZksProtocolVersion extends Response<ProtocolVersion> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.zksync.methods.response;

import io.zksync.protocol.core.TransactionWithDetailedOutput;
import org.web3j.protocol.core.Response;

public class ZksTransactionWithDetailedOutput extends Response<TransactionWithDetailedOutput> {
}
83 changes: 78 additions & 5 deletions src/main/java/io/zksync/protocol/JsonRpc2_0ZkSync.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
import io.zksync.methods.request.Transaction;
import io.zksync.methods.response.*;
import io.zksync.protocol.core.BridgeAddresses;
import io.zksync.protocol.core.ProtocolVersion;
import io.zksync.transaction.type.TransactionOptions;
import io.zksync.transaction.type.TransferTransaction;
import io.zksync.transaction.type.WithdrawTransaction;
import io.zksync.utils.TransactionStatus;
import io.zksync.utils.WalletUtils;
import io.zksync.utils.ZkSyncAddresses;
import io.zksync.wrappers.ERC20;
import io.zksync.wrappers.IEthToken;
import io.zksync.wrappers.IL2Bridge;
import io.zksync.wrappers.*;
import org.jetbrains.annotations.Nullable;
import org.web3j.abi.FunctionEncoder;
import org.web3j.abi.TypeReference;
Expand Down Expand Up @@ -188,6 +187,10 @@ public Request<?, EthEstimateGas> estimateGasL1(Transaction transaction) {
}

public String l2TokenAddress(String tokenAddress){
return l2TokenAddress(tokenAddress, null);
}

public String l2TokenAddress(String tokenAddress, @Nullable String bridgeAddress){
if (tokenAddress.equalsIgnoreCase(ZkSyncAddresses.LEGACY_ETH_ADDRESS)){
tokenAddress = ZkSyncAddresses.ETH_ADDRESS_IN_CONTRACTS;
}
Expand All @@ -198,12 +201,82 @@ public String l2TokenAddress(String tokenAddress){
}

BridgeAddresses bridgeAddresses = zksGetBridgeContracts().sendAsync().join().getResult();
bridgeAddress = bridgeAddress != null ? bridgeAddress : bridgeAddresses.getL2SharedDefaultBridge();
BigInteger gas = ethGasPrice().sendAsync().join().getGasPrice();
IL2Bridge shared = IL2Bridge.load(bridgeAddresses.getL2SharedDefaultBridge(), this, WalletUtils.createRandomCredentials(), gas, gas);
IL2SharedBridge shared = IL2SharedBridge.load(bridgeAddress, this, WalletUtils.createRandomCredentials(), gas, gas);

return shared.l2TokenAddress(tokenAddress).sendAsync().join();
}

/**
* Return the protocol version
*
* Calls the {@link <a href="https://docs.zksync.io/build/api.html#zks_getprotocolversion">...</a> zks_getProtocolVersion} JSON-RPC method.
*
* @param id Specific version ID.
*/
public Request<?, ZksProtocolVersion> getProtocolVersion(int id){
return new Request<>(
"zks_getProtocolVersion",
Collections.singletonList(id),
web3jService,
ZksProtocolVersion.class);
}

/**
* Returns true if passed bridge address is legacy and false if its shared bridge.
**
* @param address The bridge address.
*/
public RemoteCall<Boolean> isL2BridgeLegacy(String address) {
BigInteger gas = ethGasPrice().sendAsync().join().getGasPrice();
IL2SharedBridge shared = IL2SharedBridge.load(address, this, WalletUtils.createRandomCredentials(), gas, gas);
return new RemoteCall<>(() -> {
try {
shared.l1SharedBridge().send();
return true;
} catch (Exception e) {
return false;
}
});
}

/**
* Returns the current fee parameters.
*
* Calls the {@link <a href="https://docs.zksync.io/build/api.html#zks_getFeeParams">zks_getFeeParams</a>} JSON-RPC method.
*/
public Request<?, ZksFeeParams> getFeeParams() {
return new Request<>(
"zks_getFeeParams",
Collections.emptyList(),
web3jService,
ZksFeeParams.class);
}

/**
* Executes a transaction and returns its hash, storage logs, and events that would have been generated if the
* transaction had already been included in the block. The API has a similar behaviour to `eth_sendRawTransaction`
* but with some extra data returned from it.
*
* With this API Consumer apps can apply "optimistic" events in their applications instantly without having to
* wait for ZKsync block confirmation time.
*
* It’s expected that the optimistic logs of two uncommitted transactions that modify the same state will not
* have causal relationships between each other.
*
* Calls the {@link <a href="https://docs.zksync.io/build/api.html#zks_sendRawTransactionWithDetailedOutput">zks_sendRawTransactionWithDetailedOutput</a>} JSON-RPC method.
*
* @param signedTx The signed transaction that needs to be broadcasted.
*/
public Request<?, ZksTransactionWithDetailedOutput> sendRawTransactionWithDetailedOutput(String signedTx) {
return new Request<>(
"zks_sendRawTransactionWithDetailedOutput",
Collections.singletonList(signedTx),
web3jService,
ZksTransactionWithDetailedOutput.class);
}

public Request<?, EthEstimateGas> estimateL1ToL2Execute(String contractAddress, byte[] calldata, String caller, @Nullable BigInteger l2GasLimit, @Nullable BigInteger l2Value, @Nullable byte[][] factoryDeps, @Nullable BigInteger operatorTip, @Nullable BigInteger gasPerPubDataByte, @Nullable String refoundRecepient) {
if (gasPerPubDataByte == null){
gasPerPubDataByte = BigInteger.valueOf(800);
Expand Down Expand Up @@ -340,7 +413,7 @@ public Request<?, ZksL1BatchNumber> getL1BatchNumber() {
@Override
public Request<?, ZksStorageProof> getProof(String address, String[] keys, BigInteger l1BatchNumber) {
return new Request<>(
"zks_L1BatchNumber", Arrays.asList(address, keys, l1BatchNumber), web3jService, ZksStorageProof.class);
"zks_getProof", Arrays.asList(address, keys, l1BatchNumber), web3jService, ZksStorageProof.class);
}

@Override
Expand Down
52 changes: 52 additions & 0 deletions src/main/java/io/zksync/protocol/ZkSync.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.web3j.protocol.Web3j;
import org.web3j.protocol.Web3jService;
import org.web3j.protocol.core.DefaultBlockParameter;
import org.web3j.protocol.core.RemoteCall;
import org.web3j.protocol.core.RemoteFunctionCall;
import org.web3j.protocol.core.Request;
import org.web3j.protocol.core.methods.request.EthFilter;
Expand Down Expand Up @@ -197,6 +198,57 @@ Request<?, ZksBlock> zksGetBlockByNumber(
*/
String l2TokenAddress(String tokenAddress);

/**
* Returns the L2 token address equivalent for a L1 token address as they are not necessarily equal.
* The ETH address is set to the zero address.
*
* Only works for tokens bridged on default zkSync Era bridges.
*
* @param tokenAddress The address of the token on L1.
* @param customBridge The address of the token on L1.
*/
String l2TokenAddress(String tokenAddress, @Nullable String customBridge);

/**
* Returns the current fee parameters.
*
* Calls the {@link <a href="https://docs.zksync.io/build/api.html#zks_getFeeParams">zks_getFeeParams</a>} JSON-RPC method.
*/
Request<?, ZksFeeParams> getFeeParams();

/**
* Return the protocol version
*
* Calls the {@link <a href="https://docs.zksync.io/build/api.html#zks_getprotocolversion">...</a> zks_getProtocolVersion} JSON-RPC method.
*
* @param id Specific version ID.
*/
Request<?, ZksProtocolVersion> getProtocolVersion(int id);

/**
* Executes a transaction and returns its hash, storage logs, and events that would have been generated if the
* transaction had already been included in the block. The API has a similar behaviour to `eth_sendRawTransaction`
* but with some extra data returned from it.
*
* With this API Consumer apps can apply "optimistic" events in their applications instantly without having to
* wait for ZKsync block confirmation time.
*
* It’s expected that the optimistic logs of two uncommitted transactions that modify the same state will not
* have causal relationships between each other.
*
* Calls the {@link <a href="https://docs.zksync.io/build/api.html#zks_sendRawTransactionWithDetailedOutput">zks_sendRawTransactionWithDetailedOutput</a>} JSON-RPC method.
*
* @param signedTx The signed transaction that needs to be broadcasted.
*/
Request<?, ZksTransactionWithDetailedOutput> sendRawTransactionWithDetailedOutput(String signedTx);

/**
* Returns true if passed bridge address is legacy and false if its shared bridge.
**
* @param address The bridge address.
*/
RemoteCall<Boolean> isL2BridgeLegacy(String address);

Request<?, EthEstimateGas> estimateL1ToL2Execute(String contractAddress, byte[] calldata, String caller, @Nullable BigInteger l2GasLimit, @Nullable BigInteger l2Value, @Nullable byte[][] factoryDeps, @Nullable BigInteger operatorTip, @Nullable BigInteger gasPerPubDataByte, @Nullable String refoundRecepient);

Transaction getWithdrawTransaction(WithdrawTransaction tx, ContractGasProvider gasProvider, TransactionManager transactionManager) throws Exception;
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/io/zksync/protocol/account/ECDSASmartAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.zksync.protocol.account;

import io.zksync.protocol.ZkSync;
import io.zksync.utils.smart.account.PopulateTransactionECDSA;
import io.zksync.utils.smart.account.SignPayloadWithECDSA;

import java.util.Arrays;

public class ECDSASmartAccount extends SmartAccount{
public ECDSASmartAccount(ZkSync provider, String address, String secret) {
super(provider, Arrays.asList(secret), address, new SignPayloadWithECDSA(), new PopulateTransactionECDSA());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.zksync.protocol.account;

import io.zksync.protocol.ZkSync;
import io.zksync.utils.smart.account.PopulateTransactionECDSA;
import io.zksync.utils.smart.account.SignPayloadWithMultipleECDSA;

import java.util.List;

public class MultisigECDSASmartAccount extends SmartAccount{
public MultisigECDSASmartAccount(ZkSync provider, String address, List<String> secrets) {
super(provider, secrets, address, new SignPayloadWithMultipleECDSA(), new PopulateTransactionECDSA());
}
}
Loading