This repository has been archived by the owner on Jun 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
12,230 additions
and
1,704 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,32 @@ | ||
# Examples | ||
[quoter](./quoter/main.go) - get the swapped amount from chain. | ||
[swap](./pool/main.go) - swap two tokens on chain. | ||
[liquidity](liquidity/main.go) - shows how to mint/add/remove/burn a liquidity position. | ||
|
||
[Quoter](./quoter/README.md) | ||
[Pool](./pool/README.md) | ||
## Usage | ||
If you want to see the code running in real environment, set you private key to environment variable. The variable `MY_PRIVATE_KEY` will be get by each `main` function. | ||
```bash | ||
MY_PRIVATE_KEY="" | ||
``` | ||
|
||
Replace `helper.TryTx` to `helper.SendTx` in each example case. | ||
```go | ||
//try go send a transaction, it try to estimate gas price. | ||
tx, err := helper.TryTX(client, common.HexToAddress(helper.ContractV3SwapRouterV1), | ||
swapValue, params.Calldata, wallet) | ||
|
||
//send a transaction to chain, it will cost your money. | ||
tx, err := helper.SendTX(client, common.HexToAddress(helper.ContractV3SwapRouterV1), | ||
swapValue, params.Calldata, wallet) | ||
``` | ||
If you just want to check the paramerters are passed correctly, we recommend you use `TryTx`. | ||
|
||
We use Polygon to test our code(it so cheap), you can set for your own. | ||
``` | ||
client, err := ethclient.Dial(helper.PolygonRPC) | ||
``` | ||
|
||
## Run | ||
``` | ||
go run examples/quoter/*.go | ||
``` |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,236 @@ | ||
[ | ||
{ | ||
"inputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "constructor" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": true, | ||
"internalType": "uint24", | ||
"name": "fee", | ||
"type": "uint24" | ||
}, | ||
{ | ||
"indexed": true, | ||
"internalType": "int24", | ||
"name": "tickSpacing", | ||
"type": "int24" | ||
} | ||
], | ||
"name": "FeeAmountEnabled", | ||
"type": "event" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "oldOwner", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "newOwner", | ||
"type": "address" | ||
} | ||
], | ||
"name": "OwnerChanged", | ||
"type": "event" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "token0", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "token1", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": true, | ||
"internalType": "uint24", | ||
"name": "fee", | ||
"type": "uint24" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "int24", | ||
"name": "tickSpacing", | ||
"type": "int24" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "address", | ||
"name": "pool", | ||
"type": "address" | ||
} | ||
], | ||
"name": "PoolCreated", | ||
"type": "event" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "tokenA", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "address", | ||
"name": "tokenB", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "uint24", | ||
"name": "fee", | ||
"type": "uint24" | ||
} | ||
], | ||
"name": "createPool", | ||
"outputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "pool", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "uint24", | ||
"name": "fee", | ||
"type": "uint24" | ||
}, | ||
{ | ||
"internalType": "int24", | ||
"name": "tickSpacing", | ||
"type": "int24" | ||
} | ||
], | ||
"name": "enableFeeAmount", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "uint24", | ||
"name": "", | ||
"type": "uint24" | ||
} | ||
], | ||
"name": "feeAmountTickSpacing", | ||
"outputs": [ | ||
{ | ||
"internalType": "int24", | ||
"name": "", | ||
"type": "int24" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "address", | ||
"name": "", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "uint24", | ||
"name": "", | ||
"type": "uint24" | ||
} | ||
], | ||
"name": "getPool", | ||
"outputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "owner", | ||
"outputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "parameters", | ||
"outputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "factory", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "address", | ||
"name": "token0", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "address", | ||
"name": "token1", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "uint24", | ||
"name": "fee", | ||
"type": "uint24" | ||
}, | ||
{ | ||
"internalType": "int24", | ||
"name": "tickSpacing", | ||
"type": "int24" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "_owner", | ||
"type": "address" | ||
} | ||
], | ||
"name": "setOwner", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
} | ||
] |
Oops, something went wrong.