瀏覽代碼

misc stuff

Jayant Krishnamurthy 2 年之前
父節點
當前提交
debc1220cc

+ 3 - 3
target_chains/ethereum/examples/oracle_swap/app/src/App.tsx

@@ -20,19 +20,19 @@ const CONFIG = {
   // Note that feeds have different ids on testnet / mainnet.
   baseToken: {
     name: "BRL",
-    erc20Address: "0xB3a2EDFEFC35afE110F983E32Eb67E671501de1f",
+    erc20Address: "0x8e2a09b54fF35Cc4fe3e7dba68bF4173cC559C69",
     pythPriceFeedId:
       "08f781a893bc9340140c5f89c8a96f438bcfae4d1474cc0f688e3a52892c7318",
     decimals: 18,
   },
   quoteToken: {
     name: "USD",
-    erc20Address: "0x8C65F3b18fB29D756d26c1965d84DBC273487624",
+    erc20Address: "0x98cDc14fe999435F3d4C2E65eC8863e0d70493Df",
     pythPriceFeedId:
       "1fc18861232290221461220bd4e2acd1dcdfbc89c84092c93c18bdc7756c1588",
     decimals: 18,
   },
-  swapContractAddress: "0x15F9ccA28688F5E6Cbc8B00A8f33e8cE73eD7B02",
+  swapContractAddress: "0xec86479a72469Fe5E4efc2B5b1c960Ed460e9081",
   pythContractAddress: "0xff1a0f4744e8582DF1aE09D5611b887B6a12925C",
   priceServiceUrl: "https://xc-testnet.pyth.network",
   mintQty: 100,

+ 28 - 3
target_chains/ethereum/examples/oracle_swap/app/src/OrderEntry.tsx

@@ -233,7 +233,32 @@ async function sendSwapTxNew(
   );
 
   const tip = 7;
-  await swapContract.methods
-    .swapNoUpdate(isBuy, qtyWei)
-    .send({ value: tip, from: sender });
+
+  console.log("trying to swap");
+
+  try {
+    const res = await swapContract.methods
+      .swapNoUpdate(isBuy, qtyWei)
+      .call({ value: tip, from: sender });
+  } catch (error) {
+    console.log(error);
+  }
+
+  const pythPriceService = new EvmPriceServiceConnection(priceServiceUrl);
+  const priceFeedUpdateData = await pythPriceService.getPriceFeedsUpdateData([
+    baseTokenPriceFeedId,
+    quoteTokenPriceFeedId,
+  ]);
+
+  const pythContract = new web3.eth.Contract(
+    IPythAbi as any,
+    pythContractAddress
+  );
+
+  const updateFee = await pythContract.methods
+    .getUpdateFee(priceFeedUpdateData.length)
+    .call();
+
+  pythContract;
+  alert(res);
 }

+ 18 - 0
target_chains/ethereum/examples/oracle_swap/app/src/abi/OracleSwapAbi.json

@@ -164,6 +164,24 @@
     "stateMutability": "payable",
     "type": "function"
   },
+  {
+    "inputs": [
+      {
+        "internalType": "bool",
+        "name": "isBuy",
+        "type": "bool"
+      },
+      {
+        "internalType": "uint256",
+        "name": "size",
+        "type": "uint256"
+      }
+    ],
+    "name": "swapNoUpdate",
+    "outputs": [],
+    "stateMutability": "payable",
+    "type": "function"
+  },
   {
     "inputs": [],
     "name": "withdrawAll",

+ 3 - 3
target_chains/ethereum/examples/oracle_swap/contract/scripts/deploy.sh

@@ -2,7 +2,7 @@
 
 # URL of the ethereum RPC node to use. Choose this based on your target network
 # (e.g., this deploys to goerli optimism testnet)
-RPC_URL=https://endpoints.omniatech.io/v1/matic/mumbai/public
+RPC_URL=https://goerli.optimism.io
 
 # The address of the Pyth contract on your network. See the list of contract addresses here https://docs.pyth.network/pythnet-price-feeds/evm
 PYTH_CONTRACT_ADDRESS="0xff1a0f4744e8582DF1aE09D5611b887B6a12925C"
@@ -11,8 +11,8 @@ PYTH_CONTRACT_ADDRESS="0xff1a0f4744e8582DF1aE09D5611b887B6a12925C"
 BASE_FEED_ID="0x08f781a893bc9340140c5f89c8a96f438bcfae4d1474cc0f688e3a52892c7318"
 QUOTE_FEED_ID="0x1fc18861232290221461220bd4e2acd1dcdfbc89c84092c93c18bdc7756c1588"
 # The address of the base and quote ERC20 tokens.
-BASE_ERC20_ADDR="0xB3a2EDFEFC35afE110F983E32Eb67E671501de1f"
-QUOTE_ERC20_ADDR="0x8C65F3b18fB29D756d26c1965d84DBC273487624"
+BASE_ERC20_ADDR="0x8e2a09b54fF35Cc4fe3e7dba68bF4173cC559C69"
+QUOTE_ERC20_ADDR="0x98cDc14fe999435F3d4C2E65eC8863e0d70493Df"
 
 # Note the -l here uses a ledger wallet to deploy your contract. You may need to change this
 # option if you are using a different wallet.

+ 27 - 11
target_chains/ethereum/proxy/src/index.ts

@@ -4,33 +4,49 @@ import bodyParser from "body-parser";
 
 const UNDERLYING_URL = "https://goerli.optimism.io";
 
+const IGNORE_METHODS = [
+  "eth_blockNumber",
+  "eth_getBalance",
+  "eth_getBlockByNumber",
+  "eth_feeHistory",
+  "eth_call",
+];
 const app = express();
 const port = 8080;
 
+function logRequest(req: any) {}
+
 // Use body-parser to parse JSON request bodies
 app.use(bodyParser.json());
 
 // Handle POST requests to /
 app.post("/", async (req, res) => {
   try {
-    // Get the URL to proxy to from the request body
-    console.log(
-      `[-->] ${req.method} url: ${req.url} path: ${
-        req.path
-      } params: ${JSON.stringify(req.params)}`
-    );
-    console.log(`      ${JSON.stringify(req.body)}`);
-
     if (req.method == "POST") {
       const ethMethod = req.body.method;
+      const logsEnabled = !IGNORE_METHODS.includes(ethMethod);
+
+      if (logsEnabled) {
+        // Get the URL to proxy to from the request body
+        console.log(
+          `[-->] ${req.method} url: ${req.url} path: ${
+            req.path
+          } params: ${JSON.stringify(req.params)}`
+        );
+        console.log(`      ${JSON.stringify(req.body)}`);
+      }
+
       if (ethMethod === "FOOOOOO") {
       } else {
         // default fallback is to proxy the data to the underlying rpc node.
         const destUrl = `${UNDERLYING_URL}${req.path}`;
         const response = await axios.post(destUrl, req.body);
-        console.log(
-          `[<--] ${response.status} ${JSON.stringify(response.data)}`
-        );
+
+        if (logsEnabled) {
+          console.log(
+            `[<--] ${response.status} ${JSON.stringify(response.data)}`
+          );
+        }
         res.status(response.status).send(response.data);
       }
     } else {