Skip to content

Commit 67ea4ea

Browse files
authored
Oracle amm update (#6)
* oracle-amm-update * update * update * update * update * Removed unwanted files marked in .gitignore * prettier * resolved comments
1 parent f8d269e commit 67ea4ea

File tree

13 files changed

+40858
-172
lines changed

13 files changed

+40858
-172
lines changed

price_feeds/evm/oracle_swap/README.md

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Pyth Oracle AMM
22

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.
55

66
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.
77
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.
3838

3939
### Deploying
4040

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:
4442

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:
43+
``` bash
44+
export RPC_URL=<YOUR_RPC_URL>
45+
export PRIVATE_KEY=<YOUR_PRIVATE_KEY>
46+
export PYTH_ADDRESS=<PYTH_ADDRESS>
4947

50-
```
51-
cast send --rpc-url <RPC_URL> -l <ERC20_CONTRACT_ADDRESS> "mint(address,uint256)" <YOUR_WALLET_ADDRESS> <QUANTITY_IN_WEI>
52-
```
48+
export TOKEN_NAME_1=MockWETH
49+
export TOKEN_SYMBOL_1=mWETH
50+
export TOKEN_NAME_2=MockSOL
51+
export TOKEN_SYMBOL_2=mSOL
5352

54-
When the contract is deployed, the token pools are initially empty.
55-
You will need to send some funds to the pool for testing purposes.
56-
You can use the following command to transfer ERC-20 tokens from your wallet to the contract:
5753

54+
BASE_PRICE_ID=0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace # ETH/USD
55+
QUOTE_PRICE_ID=0xef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d # SOL/USD
5856
```
59-
cast send --rpc-url <RPC_URL> -l <ERC20_CONTRACT_ADDRESS> "transfer(address,uint256)" <DESTINATION_ADDRESS> <QUANTITY_IN_WEI>
57+
58+
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:
80+
81+
``` bash
82+
forge script scripts/OracleDeployment.s.sol --rpc-url $RPC_URL --broadcast
6083
```
6184

85+
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+
6291
### Create ABI
6392

6493
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
73102

74103
By default, the frontend is configured to use the already deployed version of the oracle AMM
75104
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).
77106

78107
### Build
79108

@@ -90,11 +119,4 @@ After building, you can start the frontend by navigating to the `app/` directory
90119

91120
`npm run start`
92121

93-
Then navigate your browser to `localhost:3000`.
94-
95-
### Other configurations:
96-
97-
optimism goerli addresses
98-
brl 0x8e2a09b54fF35Cc4fe3e7dba68bF4173cC559C69
99-
usd 0x98cDc14fe999435F3d4C2E65eC8863e0d70493Df
100-
swap contract 0xf3161b2B32761B46C084a7e1d8993C19703C09e7
122+
Then navigate your browser to `localhost:3000`.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
module.exports = {
2+
webpack: {
3+
configure: (config) => {
4+
// ...
5+
const fileLoaderRule = getFileLoaderRule(config.module.rules);
6+
if (!fileLoaderRule) {
7+
throw new Error("File loader not found");
8+
}
9+
fileLoaderRule.exclude.push(/\.cjs$/);
10+
// ...
11+
return config;
12+
},
13+
ignoreWarnings: [
14+
function ignoreSourcemapsloaderWarnings(warning) {
15+
return (
16+
warning.module &&
17+
warning.module.resource.includes('node_modules') &&
18+
warning.details &&
19+
warning.details.includes('source-map-loader')
20+
)
21+
},
22+
],
23+
},
24+
eslint: null,
25+
};
26+
27+
function getFileLoaderRule(rules) {
28+
for (const rule of rules) {
29+
if ("oneOf" in rule) {
30+
const found = getFileLoaderRule(rule.oneOf);
31+
if (found) {
32+
return found;
33+
}
34+
} else if (rule.test === undefined && rule.type === "asset/resource") {
35+
return rule;
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)