Skip to content

Commit

Permalink
Merge pull request #242 from CarmineOptions/feature/proposal-add-options
Browse files Browse the repository at this point in the history
Feature/proposal add options
  • Loading branch information
DaveVodrazka authored Oct 8, 2024
2 parents 6651241 + 908c4c2 commit e38ea1f
Show file tree
Hide file tree
Showing 13 changed files with 688 additions and 4 deletions.
11 changes: 11 additions & 0 deletions src/api/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { API_URL, NETWORK } from "../constants/amm";
import { ApiResponse, TokenPriceData } from "../types/api";

export type ApiConfig = {
network?: "testnet" | "mainnet";
Expand All @@ -25,3 +26,13 @@ export const apiUrl = (path: string, config?: ApiConfig): string => {

return url.toString();
};

export const fetchTokenPrices = async () => {
const url = apiUrl("token-prices");
const res = await fetch(url);
const body = (await res.json()) as ApiResponse<TokenPriceData>;
if (body.status === "success") {
return body.data;
}
throw Error("Failed getting token prices");
};
4 changes: 2 additions & 2 deletions src/classes/Option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ export class Option extends Pool {
typeof strike === "string" ? strike : "0x" + strike.toString(16);
this.strike = math64toDecimal(strike, mathBase);
this.side = bnToOptionSide(side);
this.optionId = this.generateId();
this.optionId = this.generateOptionId();
}

/**
* Generates id that uniquily describes option
*/
generateId(): string {
generateOptionId(): string {
return JSON.stringify({
base: this.baseToken.id,
quote: this.quoteToken.id,
Expand Down
70 changes: 69 additions & 1 deletion src/classes/Pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { shortInteger } from "../utils/computations";
import { bnToOptionType } from "../utils/conversions";
import { toHex } from "../utils/utils";
import { Pair, PairKey } from "./Pair";
import { Token } from "./Token";
import { Token, TokenKey } from "./Token";

export class Pool extends Pair {
public type: OptionType;
Expand Down Expand Up @@ -203,6 +203,74 @@ export class Pool extends Pair {
get name(): string {
return `${this.baseToken.symbol}/${this.quoteToken.symbol} ${this.typeAsText} Pool (${this.symbol})`;
}

get strikeStep(): [number, number] {
if (
this.baseToken.id === TokenKey.ETH &&
this.quoteToken.id === TokenKey.USDC
) {
// ETH/USDC
return [100, 200];
}
if (
this.baseToken.id === TokenKey.STRK &&
this.quoteToken.id === TokenKey.USDC
) {
// STRK/USDC
return [0.05, 0.05];
}
if (
this.baseToken.id === TokenKey.ETH &&
this.quoteToken.id === TokenKey.STRK
) {
// ETH/STRK
return [100, 300];
}
if (
this.baseToken.id === TokenKey.BTC &&
this.quoteToken.id === TokenKey.USDC
) {
// BTC/USDC
return [1000, 3000];
}

// unreachable
throw Error("Failed getting strike step");
}

get baseVolatility(): number {
if (
this.baseToken.id === TokenKey.ETH &&
this.quoteToken.id === TokenKey.USDC
) {
// ETH/USDC
return 55;
}
if (
this.baseToken.id === TokenKey.STRK &&
this.quoteToken.id === TokenKey.USDC
) {
// STRK/USDC
return 90;
}
if (
this.baseToken.id === TokenKey.ETH &&
this.quoteToken.id === TokenKey.STRK
) {
// ETH/STRK
return 100;
}
if (
this.baseToken.id === TokenKey.BTC &&
this.quoteToken.id === TokenKey.USDC
) {
// BTC/USDC
return 55;
}

// unreachable
throw Error("Failed getting base volatility");
}
}

export class PoolInfo extends Pool {
Expand Down
Loading

0 comments on commit e38ea1f

Please sign in to comment.