Skip to content

Commit

Permalink
Merge pull request #27 from decentldotland/prep
Browse files Browse the repository at this point in the history
feat: Redstone price oracle molecule
  • Loading branch information
charmful0x authored Jan 22, 2023
2 parents eb6457f + ece8efc commit aa350db
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "molecule",
"version": "0.2.0",
"version": "0.2.1",
"type": "module",
"description": "reusable EXM components and helper functions for a faster development",
"main": "./src/api.js",
Expand Down
14 changes: 14 additions & 0 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { isTezSigner } from "./molecules/tez/atoms/verifySigner.js";
import { isAptosSigner } from "./molecules/aptos/atoms/verifySigner.js";
import { readNearOracleState } from "./molecules/near/atoms/read-contract.js";
import { getEverTxObject } from "./molecules/everpay/atoms/tx.js";
import { getTokenPrice } from "./molecules/redstone/atoms/oracle.js";
import base64url from "base64url";

const app = express();
Expand Down Expand Up @@ -262,7 +263,20 @@ app.get("/everpay/tx/:txid", async (req, res) => {
}
});

app.get("/redstone/price/:ticker", async (req, res) => {
try {
res.setHeader("Content-Type", "application/json");

assert.equal(checkSubdomain(req, "redstone"), true);
const { ticker } = req.params;
const response = await getTokenPrice(ticker);
res.send(response);
return;
} catch (error) {
res.send({ molecule_error: "redstone_error" });
return;
}
});

app.get("/n-view-state/:network/:address", async (req, res) => {
try {
Expand Down
14 changes: 14 additions & 0 deletions src/molecules/redstone/atoms/oracle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { MOLECULE_API_ENDPOINT } from "../../../utils/constants.js"
import axios from "axios";

export async function getTokenPrice(ticker) {
try {
const result = await axios.get(
`${MOLECULE_API_ENDPOINT}/redstone/${ticker}`
);

return result?.data;;
} catch (error) {
return { molecule_error: "redstone_error" }
}
}
1 change: 1 addition & 0 deletions src/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const MOLECULES = [
"massa",
"ever",
"fuel",
"redstone",
"substrate",
"rand",
];
Expand Down

0 comments on commit aa350db

Please sign in to comment.