Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions coins/src/adapters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import * as balancer from "./markets/balancer";
import * as others from "./other/index";
import * as others2 from "./other/others2";
import * as graphCoins from "./markets/graphCoins";
import * as optimex from "./moneyMarkets/optimex";

export default {
...compound.adapters,
...aave.adapters,
...optimex.adapters,
...euler.adapters,
...uniswap.adapters,
...curve.adapters,
Expand Down
1 change: 1 addition & 0 deletions coins/src/adapters/moneyMarkets/optimex/abi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const AGGREGATOR_ABI = "function latestRoundData() external view returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound)";
34 changes: 34 additions & 0 deletions coins/src/adapters/moneyMarkets/optimex/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { addToDBWritesList } from "../../utils/database";
import { Write } from "../../utils/dbInterfaces";
import { getBtcToUsdPrice } from "./utils";

const oBTCConfig = {
address: "0x1Ee774B40eECef1ed4BB702C83A97dc949c900e5",
decimals: 8,
symbol: "oBTC",
}


export async function obtc(timestamp: number) {
const writes: Write[] = [];

const price = await getBtcToUsdPrice(timestamp);

addToDBWritesList(
writes,
"ethereum",
oBTCConfig.address,
price,
oBTCConfig.decimals,
oBTCConfig.symbol,
timestamp,
"optimex",
0.98,
);

return writes;
}

export const adapters = {
obtc,
}
14 changes: 14 additions & 0 deletions coins/src/adapters/moneyMarkets/optimex/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { getApi } from "../../utils/sdk";
import { AGGREGATOR_ABI } from "./abi";

// BTC/USD Chainlink Oracle on Ethereum
const BTC_TO_USD_ORACLE_ETH = "0xF4030086522a5bEEa4988F8cA5B36dbC97BeE88c";
// Rounding decimals for the above chainlink oracle
const ROUNDING_DECIMALS = 1e8;

export async function getBtcToUsdPrice(timestamp: number): Promise<number> {
const api = await getApi("ethereum", timestamp);
const response = await api.call({ abi: AGGREGATOR_ABI, target: BTC_TO_USD_ORACLE_ETH });
// Scale down using decimals
return response.answer / ROUNDING_DECIMALS;
}