Skip to content

Commit

Permalink
Merge pull request #18 from terra-money/feat/amp/roar
Browse files Browse the repository at this point in the history
feat: implement amp roar
  • Loading branch information
emidev98 authored Feb 29, 2024
2 parents 73a7eab + 6139726 commit 3ec4dc0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
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;
}

0 comments on commit 3ec4dc0

Please sign in to comment.