Skip to content

Commit

Permalink
Merge pull request #171 from osmosis-labs/sunny/fix-osmosis-stables
Browse files Browse the repository at this point in the history
fix Osmosis stables calculations
  • Loading branch information
Define101 authored Nov 9, 2023
2 parents 95f7978 + 811df89 commit ab984b1
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/adapters/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion src/adapters/peggedAssets/dai/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ const chainContracts: ChainContracts = {
mixin: {
ethAssetIds: ["8549b4ad-917c-3461-a646-481adc5d7f7f"],
},
osmosis: {
bridgedFromETH: ["ibc/0CD3A0285E1341859B5E86B6AB7682F023D03E97607CCC1DC95706411D866DF7"], // axelar
}
};

/*
Expand Down Expand Up @@ -574,7 +577,8 @@ const adapter: PeggedIssuanceAdapter = {
osmosis: {
minted: async () => ({}),
unreleased: async () => ({}),
ethereum: osmosisSupply("dai", "Axelar", "Ethereum"),
ethereum: osmosisSupply(chainContracts.osmosis.bridgedFromETH, 18, "Axelar"),

},
starknet: {
minted: async () => ({}),
Expand Down
30 changes: 27 additions & 3 deletions src/adapters/peggedAssets/helper/getSupply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export async function terraSupply(addresses: string[], decimals: number) {
};
}

export async function osmosisSupply(token: string, bridgeName: string, bridgedFrom: string) {
export async function osmosisLiquidity(token: string, bridgeName: string, bridgedFrom: string) {
return async function (
_timestamp: number,
_ethBlock: number,
Expand All @@ -199,8 +199,8 @@ export async function osmosisSupply(token: string, bridgeName: string, bridgedFr
async (_bail: any) =>
await axios.get(`https://api-osmosis.imperator.co/tokens/v2/${token}`)
);
const totalSupply = res.data[0].liquidity;
sumSingleBalance(balances, "peggedUSD", totalSupply, bridgeName, false, bridgedFrom);
const totalLiquidity = res.data[0].liquidity;
sumSingleBalance(balances, "peggedUSD", totalLiquidity, bridgeName, false, bridgedFrom);
return balances;
};
}
Expand Down Expand Up @@ -230,6 +230,30 @@ export async function cosmosSupply(chain: string, tokens: string[], decimals: nu
};
}

export async function osmosisSupply(tokens: string[], decimals: number, bridgedFromChain: string) {
return async function (
_timestamp: number,
_ethBlock: number,
_chainBlocks: ChainBlocks
) {
let balances = {} as Balances;
for (let token of tokens) {
const res = await retry(
async (_bail: any) =>
await axios.get(`https://lcd.osmosis.zone/osmosis/superfluid/v1beta1/supply?denom=${token}`)
);
sumSingleBalance(
balances,
"peggedUSD",
parseInt(res.data.amount.amount) / 10 ** decimals,
token,
false,
bridgedFromChain
);
}
return balances;
};
}

export async function kujiraSupply(tokens: string[], decimals: number, bridgedFromChain: string) {
return cosmosSupply("kujira", tokens, decimals, bridgedFromChain);
Expand Down
5 changes: 4 additions & 1 deletion src/adapters/peggedAssets/terrausd/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ const chainContracts: ChainContracts = {
dfk: {
bridgedFromTerra: ["0x360d6dd540e3448371876662fbe7f1acaf08c5ab"], // synapse
},
osmosis: {
bridgedFromTerra: ["ibc/BE1BB42D4BE3C30D50B68D7C41DB4DFCE9678E8EF8C539F6E6A9345048894FCC"],
},
};

/*
Expand Down Expand Up @@ -201,7 +204,7 @@ const adapter: PeggedIssuanceAdapter = {
osmosis: {
minted: async () => ({}),
unreleased: async () => ({}),
terra: osmosisSupply("ustc", "Axelar", "Terra"),
terra: osmosisSupply(chainContracts.osmosis.bridgedFromTerra, 6, "Terra"),
},
moonbeam: {
minted: async () => ({}),
Expand Down
12 changes: 11 additions & 1 deletion src/adapters/peggedAssets/tether/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ const chainContracts: ChainContracts = {
"0x4f3C8E20942461e2c3Bdd8311AC57B0c222f2b82"
],
},
osmosis: {
bridgedFromETH: ["ibc/8242AD24008032E457D2E12D46588FD39FB54FB29680C6C7663D296B383C37C4"], // axelar
bridgedFromKava: ["ibc/4ABBEF4C8926DDDB320AE5188CFD63267ABBCEFC0583E4AE05D6E5AA2401DDAB"],
}
};

/*
Expand Down Expand Up @@ -1314,7 +1318,13 @@ const adapter: PeggedIssuanceAdapter = {
minted: async () => ({}),
unreleased: async () => ({}),
ethereum: bridgedSupply("thundercore", 6, chainContracts.thundercore.bridgeFromETH),
}
},
osmosis: {
minted: async () => ({}),
unreleased: async () => ({}),
ethereum: osmosisSupply(chainContracts.osmosis.bridgedFromETH, 6, "Axelar"),
kava: osmosisSupply(chainContracts.osmosis.bridgedFromKava, 6, "Kava"),
},
};

export default adapter;
10 changes: 8 additions & 2 deletions src/adapters/peggedAssets/usd-coin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import {
supplyInEthereumBridge,
solanaMintedOrBridged,
terraSupply,
osmosisSupply,
cosmosSupply,
kujiraSupply,
osmosisSupply,
} from "../helper/getSupply";
import {
getTotalSupply as ontologyGetTotalSupply,
Expand Down Expand Up @@ -347,6 +348,10 @@ const chainContracts: ChainContracts = {
kujira: {
bridgedFromETH: ["ibc/295548A78785A1007F232DE286149A6FF512F180AF5657780FC89C009E2C348F"],
bridgedFromNoble: ["ibc/FE98AAD68F02F03565E9FA39A5E627946699B2B07115889ED812D8BA639576A9"],
},
osmosis: {
bridgedFromETH: ["ibc/D189335C6E4A68B513C10AB227BF1C1D38C746766278BA3EEB4FB14124F1D858"], // axelar
bridgedFromNoble: ["ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4"],
}
};

Expand Down Expand Up @@ -1031,7 +1036,8 @@ const adapter: PeggedIssuanceAdapter = {
osmosis: {
minted: async () => ({}),
unreleased: async () => ({}),
ethereum: osmosisSupply("usdc", "Axelar", "Ethereum"),
ethereum: osmosisSupply(chainContracts.osmosis.bridgedFromETH, 6, "Axelar"),
noble: osmosisSupply(chainContracts.osmosis.bridgedFromNoble, 6, "Noble"),
},
fantom: {
minted: async () => ({}),
Expand Down

0 comments on commit ab984b1

Please sign in to comment.