Skip to content

Commit

Permalink
Merge branch 'master' into worldchain
Browse files Browse the repository at this point in the history
  • Loading branch information
0xNe0x1 committed Oct 7, 2024
2 parents 4203f09 + 7f53214 commit d50f9c4
Show file tree
Hide file tree
Showing 22 changed files with 1,060 additions and 1,300 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,18 @@ A Swap configuration is fed into the `route` function:
```
- `tokenIn`: The token put into the swap (out of wallet)
- `amountIn`: The amount of tokenIn put into the swap (out of wallet)
- `amountIn`: The exact amount of tokenIn put into the swap (out of wallet)
- `amountInMax`: The max. amount of tokenIn put into the swap (out of wallet)
- `tokenOut`: The token expected to come out of the swap (into wallet)
- `amountOut`: The amount of tokenOut expected to come out of the swap (into wallet)
- `amountOut`: The exact amount of tokenOut expected to come out of the swap (into wallet)
- `amountOutMin`: The min. amount of tokenOut expected to come out of the swap (into wallet)
The following combinations of provided amounts are possible:
- Pass `amountOutMin`. Swap will return at least `amountOutMin` into the wallet. `amountIn` will be calculated automatically and can vary.
- Pass `amountOut`. Swap will take at max `amountInMax` out of the wallet (calculated based on provided `amountOut`). `amountInMax` will be calculated automatically and can vary.
- Pass `amountOut`. Swap will take at max `amountInMax` out of the wallet (calculated based on provided, exact `amountOut`). `amountInMax` will be calculated automatically and can vary.
- Pass `amountInMax`. Swap will take at max `amountInMax` out of the wallet. `amountOut` will be calculated automatically and can vary.
- Pass `amountIn`. Swap will return at least `amountOutMin` into the the wallet (calculated based on provided `amountIn`). `amountOutMin` will be calculated automatically and can vary.
- Pass `amountIn`. Swap will return at least `amountOutMin` into the the wallet (calculated based on provided, exact `amountIn`). `amountOutMin` will be calculated automatically and can vary.
### Route
Expand Down
2 changes: 1 addition & 1 deletion dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<link rel="icon" type="image/png" href="https://depay.com/favicon.png"/>
<title>Development</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://cdn.ethers.io/lib/ethers-5.7.umd.min.js" type="application/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ethers/5.7.1/ethers.umd.min.js" type="application/javascript"></script>
<script crossorigin src="https://unpkg.com/decimal.js@10"></script>
<script crossorigin src="https://unpkg.com/@depay/solana-web3.js@1"></script>
<script crossorigin src="https://unpkg.com/@depay/web3-blockchains@9"></script>
Expand Down
256 changes: 104 additions & 152 deletions dist/esm/index.evm.js

Large diffs are not rendered by default.

256 changes: 104 additions & 152 deletions dist/esm/index.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions dist/esm/index.solana.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ const route$1 = ({
} catch (e) { return resolve() }
if([amountIn, amountInMax, amountOut, amountOutMin].every((amount)=>{ return amount == undefined })) { return resolve() }

if(slippage || exchange.slippage) {
if(exchange.slippage && slippage !== false) {
try {
({ amountIn, amountInMax, amountOut, amountOutMin, amounts } = await calculateAmountsWithSlippage({
exchange,
Expand Down Expand Up @@ -387,6 +387,7 @@ class Exchange {
amountOut,
amountInMax,
amountOutMin,
slippage,
}) {
if(tokenIn === tokenOut){ return Promise.resolve() }

Expand Down Expand Up @@ -426,7 +427,7 @@ class Exchange {
getAmounts: this.getAmounts,
getPrep: this.getPrep,
getTransaction: this.getTransaction,
slippage: this.slippage,
slippage,
})
}
}
Expand Down
256 changes: 104 additions & 152 deletions dist/umd/index.evm.js

Large diffs are not rendered by default.

256 changes: 104 additions & 152 deletions dist/umd/index.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions dist/umd/index.solana.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@
} catch (e) { return resolve() }
if([amountIn, amountInMax, amountOut, amountOutMin].every((amount)=>{ return amount == undefined })) { return resolve() }

if(slippage || exchange.slippage) {
if(exchange.slippage && slippage !== false) {
try {
({ amountIn, amountInMax, amountOut, amountOutMin, amounts } = await calculateAmountsWithSlippage({
exchange,
Expand Down Expand Up @@ -392,6 +392,7 @@
amountOut,
amountInMax,
amountOutMin,
slippage,
}) {
if(tokenIn === tokenOut){ return Promise.resolve() }

Expand Down Expand Up @@ -431,7 +432,7 @@
getAmounts: this.getAmounts,
getPrep: this.getPrep,
getTransaction: this.getTransaction,
slippage: this.slippage,
slippage,
})
}
}
Expand Down
48 changes: 44 additions & 4 deletions examples/uniswap_v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ wallet.sendTransaction(transaction)
let route = await Web3Exchanges.uniswap_v3.route({
blockchain: 'optimism',
tokenIn: Web3Blockchains.optimism.currency.address,
tokenOut: '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1', // DAI
amountOutMin: 1
tokenOut: '0x94b008aA00579c1307B0EF2c499aD98a8ce58e58', // USDT
amountOutMin: 0.01
})

let wallets = await Web3Wallets.getWallets()
Expand Down Expand Up @@ -63,8 +63,48 @@ wallet.sendTransaction(transaction)
```javascript
let route = await Web3Exchanges.uniswap_v3.route({
blockchain: 'optimism',
tokenIn: '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1', // DAI
tokenOut: '0x4200000000000000000000000000000000000042', // OPTIMSM
tokenIn: '0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85',
tokenOut: '0x94b008aA00579c1307B0EF2c499aD98a8ce58e58',
amountOutMin: 0.01
})

let wallets = await Web3Wallets.getWallets()
let wallet = wallets[0]
let account = await wallet.account()

let prep = await route.getPrep({ account })

let transaction = await route.getTransaction({ account })
wallet.sendTransaction(transaction)
```

# NATIVE TO TOKEN (OPTIMISM, 1 pool)

```javascript
let route = await Web3Exchanges.uniswap_v3.route({
blockchain: 'optimism',
tokenIn: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",
tokenOut: '0x94b008aA00579c1307B0EF2c499aD98a8ce58e58',
amountInMax: 0.1
})

let wallets = await Web3Wallets.getWallets()
let wallet = wallets[0]
let account = await wallet.account()

let prep = await route.getPrep({ account })

let transaction = await route.getTransaction({ account })
wallet.sendTransaction(transaction)
```

# TOKEN TO TOKEN (OPTIMISM, 2 pools)

```javascript
let route = await Web3Exchanges.uniswap_v3.route({
blockchain: 'optimism',
tokenIn: '0x76FB31fb4af56892A25e32cFC43De717950c9278',
tokenOut: '0xdC6fF44d5d932Cbd77B52E5612Ba0529DC6226F1',
amountOutMin: 0.01
})

Expand Down
175 changes: 175 additions & 0 deletions examples/uniswap_v3/base.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
# 1 Pool

## ETH TO TOKEN

### amountOutMin

```javascript
let route = await Web3Exchanges.uniswap_v3.route({
blockchain: 'base',
tokenIn: Web3Blockchains.base.currency.address,
tokenOut: '0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA', // USDCb
amountOutMin: 1
})

let wallets = await Web3Wallets.getWallets()
let wallet = wallets[0]
let account = await wallet.account()

let prep = await route.getPrep({ account })

let transaction = await route.getTransaction({ account })
wallet.sendTransaction(transaction)
```

### amountOut

```javascript
let route = await Web3Exchanges.uniswap_v3.route({
blockchain: 'base',
tokenIn: Web3Blockchains.base.currency.address,
tokenOut: '0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA', // USDCb
amountOut: 1
})

let wallets = await Web3Wallets.getWallets()
let wallet = wallets[0]
let account = await wallet.account()

let prep = await route.getPrep({ account })

let transaction = await route.getTransaction({ account })
wallet.sendTransaction(transaction)
```

## TOKEN to ETH

### amountOutMin

```javascript
let route = await Web3Exchanges.uniswap_v3.route({
blockchain: 'base',
tokenIn: '0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA', // USDCb,
tokenOut: Web3Blockchains.base.currency.address,
amountOutMin: 0.000377697
})

let wallets = await Web3Wallets.getWallets()
let wallet = wallets[0]
let account = await wallet.account()

let prep = await route.getPrep({ account })

let transaction = await route.getTransaction({ account })
wallet.sendTransaction(transaction)
```

### amountOut

```javascript
let route = await Web3Exchanges.uniswap_v3.route({
blockchain: 'base',
tokenIn: '0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA', // USDCb,
tokenOut: Web3Blockchains.base.currency.address,
amountOut: 0.000377697
})

let wallets = await Web3Wallets.getWallets()
let wallet = wallets[0]
let account = await wallet.account()

let prep = await route.getPrep({ account })

let transaction = await route.getTransaction({ account })
wallet.sendTransaction(transaction)
```

## TOKEN to TOKEN

### amountOutMin

```javascript
let route = await Web3Exchanges.uniswap_v3.route({
blockchain: 'base',
tokenIn: '0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA', // USDCb,
tokenOut: '0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb', // DAI
amountOutMin: 1
})

let wallets = await Web3Wallets.getWallets()
let wallet = wallets[0]
let account = await wallet.account()

let prep = await route.getPrep({ account })

let transaction = await route.getTransaction({ account })
wallet.sendTransaction(transaction)
```

### amountOut

```javascript
let route = await Web3Exchanges.uniswap_v3.route({
blockchain: 'base',
tokenIn: '0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA', // USDCb,
tokenOut: '0x6223901eA64608c75Da8497d5eff15D19A1D8fd5', // DAI
amountOut: 1
})

let wallets = await Web3Wallets.getWallets()
let wallet = wallets[0]
let account = await wallet.account()

let prep = await route.getPrep({ account })

let transaction = await route.getTransaction({ account })
wallet.sendTransaction(transaction)
```

# 2 Pools

## TOKEN to TOKEN

### amountOutMin

```javascript
let route = await Web3Exchanges.uniswap_v3.route({
blockchain: 'base',
tokenIn: '0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA', // USDCb,
tokenOut: '0x6223901eA64608c75Da8497d5eff15D19A1D8fd5', // CORGI
amountOutMin: 1
})

let wallets = await Web3Wallets.getWallets()
let wallet = wallets[0]
let account = await wallet.account()

let prep = await route.getPrep({ account })

let transaction = await route.getTransaction({ account })
wallet.sendTransaction(transaction)
```

## ETH TO TOKEN

### amountOutMin

```javascript
let route = await Web3Exchanges.uniswap_v3.route({
blockchain: 'base',
tokenIn: Web3Blockchains.base.currency.address,
tokenOut: '0x0c03ce270b4826ec62e7dd007f0b716068639f7b',
amountOutMin: 1
})

let wallets = await Web3Wallets.getWallets()
let wallet = wallets[0]
let account = await wallet.account()

let prep = await route.getPrep({ account })

let transaction = await route.getTransaction({ account })
wallet.sendTransaction(transaction)
```

## TOKEN to ETH
2 changes: 1 addition & 1 deletion package.evm.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@depay/web3-exchanges-evm",
"moduleName": "Web3Exchanges",
"version": "13.8.6",
"version": "13.10.0",
"description": "JavaScript library simplifying decentralized web3 exchange routing for multiple blockchains and exchanges.",
"main": "dist/umd/index.evm.js",
"module": "dist/esm/index.evm.js",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@depay/web3-exchanges",
"moduleName": "Web3Exchanges",
"version": "13.8.6",
"version": "13.10.0",
"description": "JavaScript library simplifying decentralized web3 exchange routing for multiple blockchains and exchanges.",
"main": "dist/umd/index.js",
"module": "dist/esm/index.js",
Expand Down
2 changes: 1 addition & 1 deletion package.solana.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@depay/web3-exchanges-solana",
"moduleName": "Web3Exchanges",
"version": "13.8.6",
"version": "13.10.0",
"description": "JavaScript library simplifying decentralized web3 exchange routing for multiple blockchains and exchanges.",
"main": "dist/umd/index.solana.js",
"module": "dist/esm/index.solana.js",
Expand Down
5 changes: 3 additions & 2 deletions src/classes/Exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const route = ({
} catch { return resolve() }
if([amountIn, amountInMax, amountOut, amountOutMin].every((amount)=>{ return amount == undefined })) { return resolve() }

if(slippage || exchange.slippage) {
if(exchange.slippage && slippage !== false) {
try {
({ amountIn, amountInMax, amountOut, amountOutMin, amounts } = await calculateAmountsWithSlippage({
exchange,
Expand Down Expand Up @@ -126,6 +126,7 @@ class Exchange {
amountOut,
amountInMax,
amountOutMin,
slippage,
}) {
if(tokenIn === tokenOut){ return Promise.resolve() }

Expand Down Expand Up @@ -165,7 +166,7 @@ class Exchange {
getAmounts: this.getAmounts,
getPrep: this.getPrep,
getTransaction: this.getTransaction,
slippage: this.slippage,
slippage,
})
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/exchanges.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ exchanges.fantom = [
exchanges.fantom.forEach((exchange)=>{ exchanges.fantom[exchange.name] = exchange })
exchanges.avalanche = [
uniswap_v3('avalanche'),
trader_joe_v2_1('avalanche'),
wavax('avalanche'),
]
Expand Down Expand Up @@ -214,6 +215,7 @@ exchanges.fantom = [
exchanges.fantom.forEach((exchange)=>{ exchanges.fantom[exchange.name] = exchange })

exchanges.avalanche = [
uniswap_v3('avalanche'),
trader_joe_v2_1('avalanche'),
wavax('avalanche'),
]
Expand Down
Loading

0 comments on commit d50f9c4

Please sign in to comment.