Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement amp roar #18

Merged
merged 1 commit into from
Feb 29, 2024
Merged
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
13 changes: 9 additions & 4 deletions const/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ export const SUPPORTED_CHAINS: { [key: string]: Chain } = {
},
icon: "https://raw.githubusercontent.com/terra-money/station-assets/main/img/chains/Terra.svg",
allianceCoins: {
"ibc/0E90026619DD296AD4EF9546396F292B465BAB6B5BE00ABD6162AA1CE8E68098": {
name: "rSWTH",
priceKey: "rSWTH",
icon: "https://raw.githubusercontent.com/terra-money/station-assets/main/img/coins/rSWTH.svg",
"factory/terra1vklefn7n6cchn0u962w3gaszr4vf52wjvd4y95t2sydwpmpdtszsqvk9wy/ampROAR": {
name: "ampRoar",
priceKey: "AMPROAR",
icon: "https://raw.githubusercontent.com/terra-money/station-assets/main/img/coins/ampROAR.png",
},
"ibc/B3F639855EE7478750CC8F82072307ED6E131A8EFF20345E1D136B50C4E5EC36": {
name: "ampWhale",
Expand All @@ -108,6 +108,11 @@ export const SUPPORTED_CHAINS: { [key: string]: Chain } = {
priceKey: "BWHALE",
icon: "https://raw.githubusercontent.com/terra-money/station-assets/main/img/coins/bWHALE.png",
},
"ibc/0E90026619DD296AD4EF9546396F292B465BAB6B5BE00ABD6162AA1CE8E68098": {
name: "rSWTH",
priceKey: "rSWTH",
icon: "https://raw.githubusercontent.com/terra-money/station-assets/main/img/coins/rSWTH.svg",
},
},
}),
};
Expand Down
39 changes: 37 additions & 2 deletions models/Prices.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { LCD } from "./LCDConfig"

export interface TerraPriceServerResponse {
created_at: string,
prices: Array<{
Expand All @@ -15,15 +17,29 @@ export interface Prices {
}
}

// Used to calculate the price of ampROAR
interface ErisLSDResponse {
exchange_rate: string;

// total_ustake: string;
// total_utoken: string;
// unlocked_coins: any[];
// unbonding: string;
// available: string;
// tvl_utoken: string;
}

// Query all prices from the different servers
// available and merge them into a single object
export const QueryAndMergePrices = async (): Promise<Prices> => {
const pricesRes = await Promise.all([
fetch("https://price.api.tfm.com/tokens/?limit=1500"),
fetch("https://pisco-price-server.terra.dev/latest")
fetch("https://pisco-price-server.terra.dev/latest"),
// ampRoar Smart Contract
LCD.wasm.contractQuery("terra1vklefn7n6cchn0u962w3gaszr4vf52wjvd4y95t2sydwpmpdtszsqvk9wy", { "state": {} }),
]);
const [tfmPrices, terraOraclePrices]: [Prices, TerraPriceServerResponse] = await Promise.all([pricesRes[0].json(), pricesRes[1].json()]);
const prices = terraOraclePrices.prices.reduce((acc, price) => {
let prices = terraOraclePrices.prices.reduce((acc, price) => {
acc[price.denom] = {
chain: "",
change24h: 0,
Expand All @@ -33,5 +49,24 @@ export const QueryAndMergePrices = async (): Promise<Prices> => {
return acc
}, {} as Prices)

// Quick fix for the AMPROAR price because
// there is no way to recover the price from
// any of the different Price Providers in
// the oracle feeder.
prices = parseRoarPrice(prices, pricesRes[2] as ErisLSDResponse);
console.log(prices)
return { ...tfmPrices, ...prices }
}

const parseRoarPrice = (prices: Prices, roarRes: ErisLSDResponse): Prices => {
let roarPrice = prices["ROAR"]?.usd ?? 0;

prices["AMPROAR"] = {
chain: "",
change24h: 0,
contract_addr: "",
usd: parseFloat(roarRes.exchange_rate) * roarPrice,
}

return prices;
}
Loading