Skip to content

🦄 🦄 🦄 Uniswap V3 peripheral smart contracts Java wrappers

License

Notifications You must be signed in to change notification settings

jclagache/v3-periphery

Repository files navigation

Uniswap V3 Periphery Java contract wrapper

This repository contains Web3j generated smart contract wrapper code to interact with the periphery smart contracts for the Uniswap V3 Protocol. For the periphery smart contracts sources, see the uniswap-v3-periphery repository.

Maven

Add the JitPack repository to the repositories element of your project pom.xml file.

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

Add the package dependencies to the dependencies element of your project pom.xml file.

<dependencies>
 <dependency>
    <groupId>me.jclagache</groupId>
    <artifactId>v3-periphery</artifactId>
    <version>v1.4.3-SNAPSHOT</version>
  </dependency>
</dependencies>

Gradle

Add the JitPack repository to your build.gradle file (Gradle Groovy) or build.gradle.kts file (Kotlin DSL) file.

Groovy:

repositories {
    maven {
        url = uri("https://jitpack.io")
    }
}

Kotlin:

repositories {
    maven {
        url = uri("https://jitpack.io")
    }
}

Add the package dependencies to your build.gradle file (Gradle Groovy) or build.gradle.kts file (Kotlin DSL) file.

Groovy:

dependencies {
    implementation 'me.jclagache:v3-periphery:v1.4.3-SNAPSHOT'
}

Kotlin:

dependencies {
    implementation("me.jclagache:v3-periphery:v1.4.3-SNAPSHOT")
}

Usage

Refer to the Uniswap V3 Smart Contracts and Web3j documentation.

Web3j web3j = Web3j.build(new HttpService("<your_node_url>"));
EthBlock.Block block = web3j.ethGetBlockByNumber(DefaultBlockParameterName.LATEST, false).send().getBlock();
// Mainnet
// Max Priority Fee : 2 Gwei
// Max Fee Per Gas = (2 * Base Fee) + Max Priority Fee
ContractEIP1559GasProvider gasProvider = new StaticEIP1559GasProvider(ChainId.MAIN_NET.getId(), block.getBaseFeePerGas().multiply(BigInteger.TWO).add(Convert.toWei("2", Convert.Unit.GWEI).toBigInteger()), Convert.toWei("2", Convert.Unit.GWEI).toBigInteger(), block.getGasLimit());
ISwapRouter router = ISwapRouter.load("0xE592427A0AEce92De3Edee1F18E0157C05861564", web3j, Credentials.create("your_private_key"), gasProvider);
// 1 WETH -> DAI
// fee 0.3%
// transaction expires in 300 seconds (5 minutes)
// slippage not taken into account
ISwapRouter.ExactInputSingleParams params = new ISwapRouter.ExactInputSingleParams("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", "0x6b175474e89094c44da98b954eedeac495271d0f", BigInteger.valueOf(3000), "my_address", block.getTimestamp().add(BigInteger.valueOf(300)), Convert.toWei("1", Convert.Unit.ETHER).toBigInteger(), BigInteger.ZERO, BigInteger.ZERO);
// value (1 ETH) will be automatically wrapped by the router
router.exactInputSingle(params, Convert.toWei("1", Convert.Unit.ETHER).toBigInteger()).send();

About

🦄 🦄 🦄 Uniswap V3 peripheral smart contracts Java wrappers

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published