You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: price_feeds/evm/oracle_swap/README.md
+47-25Lines changed: 47 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
# Pyth Oracle AMM
2
2
3
-
This directory contains an example oracle AMM application using Pyth price feeds.
4
-
The oracle AMM manages a pool of two tokens and allows a user to trade with the pool at the current Pyth price.
3
+
This directory contains an example of an AMM application using Pyth Price Feeds.
4
+
This AMM application manages a pool of two tokens and allows a user to trade with the pool at the current Pyth price.
5
5
6
6
This application has two components. The first component is a smart contract (in the `contract` directory) that manages the pool and implements the trading functionality.
7
7
The second is a frontend application (in the `app` directory) that communicates with the smart contract.
@@ -38,27 +38,56 @@ tests located in the [`contract/test`](./contract/test) directory.
38
38
39
39
### Deploying
40
40
41
-
To deploy the contract, you first need to configure the target network and the tokens in the AMM pool.
42
-
Edit the configuration parameters in the [deploy script](./contract/scripts/deploy.sh) and then run it using `./scripts/deploy.sh`.
43
-
The code comments in that file should help you populate the parameters correctly.
41
+
To deploy the contract, you first need to set up your environment with the following values:
44
42
45
-
If you don't have ERC-20 tokens to test with, you can use the [token deploy script](./contract/scripts/deploy_token.sh) to create some for testing.
46
-
Edit the configuration parameters in there before running to set the network and token name.
47
-
This will deploy a new mock token and print out a contract address.
48
-
Once you have this address, you can mint the token anytime using the following command:
Here, `RPC_URL` is the URL of the EVM chain you want to use, `PRIVATE_KEY` is the private key of the account you want to deploy from, and `WALLET_ADDRESS` is the address of the account associated with the private key. Make sure the account has enough funds to pay for the gas.
59
+
60
+
Check [Pyth Contract Address](https://docs.pyth.network/price-feeds/contract-addresses/evm) to get the `PYTH_ADDRESS` for your respective network.
61
+
62
+
`TOKEN_NAME_1` and `TOKEN_SYMBOL_1` are the name and symbol of the base token in the pool, and `TOKEN_NAME_2` and `TOKEN_SYMBOL_2` are the name and symbol of the quote token in the pool. **NOTE:** The above values are made up, and you can use any name and symbol you want.
63
+
64
+
65
+
66
+
67
+
We will use the `BASE_PRICE_ID` and `QUOTE_PRICE_ID` to get the price of the tokens from the Pyth oracle. These price feeds should be in the form of `BASE/USD` and `QUOTE/USD`. Above we are using `ETH/USD` and `SOL/USD` price feeds.
68
+
69
+
We can assume our ERC20 tokens to be any coin that has a price feed on Pyth.
70
+
71
+
For example, if we need a pair for `ETH/SOL`, we can use the following price ids:
72
+
73
+
Check [Pyth Price Feed Ids](https://pyth.network/developers/price-feed-ids) for the complete list of supported feeds.
74
+
75
+
76
+
If you wish to deploy on the Ethereum Sepolia testnet for `ETH/SOL` pair, you can use the following values:
77
+
78
+
79
+
After setting up the environment, you can deploy the contract by running the following command:
This script will deploy 2 ERC20 tokens, the OracleSwap contract, and initialize the pool with the Pyth price feed.
86
+
It also transfers some of the tokens to the pool for testing purposes.
87
+
88
+
After deploying the contract, you will see the address of the deployed contract in the output.
89
+
You can use this address to interact with the contract.
90
+
62
91
### Create ABI
63
92
64
93
If you change the contract, you will need to create a new ABI.
@@ -73,7 +102,7 @@ forge inspect OracleSwap abi > ../app/src/abi/OracleSwapAbi.json
73
102
74
103
By default, the frontend is configured to use the already deployed version of the oracle AMM
75
104
at address [`0x15F9ccA28688F5E6Cbc8B00A8f33e8cE73eD7B02`](https://mumbai.polygonscan.com/address/0x15F9ccA28688F5E6Cbc8B00A8f33e8cE73eD7B02) on Polygon Mumbai.
76
-
This means you can start playing with the application without going through the steps above (Remember to switch your wallet to Mumbai and to claim funds from a faucet to pay for the gas).
105
+
This means you can start playing with the application without going through the steps above (Remember to switch your wallet to Mumbai and claim funds from a faucet to pay for the gas).
77
106
78
107
### Build
79
108
@@ -90,11 +119,4 @@ After building, you can start the frontend by navigating to the `app/` directory
0 commit comments