-
Notifications
You must be signed in to change notification settings - Fork 377
Add UST1 unstablecoin (Terra Classic) #903
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
Open
PlasticDigits
wants to merge
1
commit into
DefiLlama:master
Choose a base branch
from
PlasticDigits:feat/ust1-unstablecoin
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+57
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| const axios = require("axios"); | ||
| const retry = require("async-retry"); | ||
| import { sumSingleBalance } from "../helper/generalUtil"; | ||
| import { Balances, PeggedIssuanceAdapter } from "../peggedAsset.type"; | ||
|
|
||
| /** | ||
| * UST1 unstablecoin on Terra Classic. | ||
| * Circulating = CW20 token_info.total_supply / 1e6 (human). peggedUSD. | ||
| * Mechanism: crypto-backed (ust1-window vs vFDUSD). Do not hardcode $1. | ||
| */ | ||
|
|
||
| const UST1 = "terra1f0eqgy9w7e5e7up97vjudqwx38tesf8ylx75x2lv3nwm0clry0pqmgfy72"; | ||
| const UST1_DECIMALS = 6; | ||
| const TERRA_LCD = "https://terra-classic-lcd.publicnode.com"; | ||
|
|
||
| async function terraMinted() { | ||
| const query = Buffer.from(JSON.stringify({ token_info: {} })).toString("base64"); | ||
| const url = `${TERRA_LCD}/cosmwasm/wasm/v1/contract/${UST1}/smart/${query}`; | ||
| const res = await retry(async (_bail: any) => await axios.get(url)); | ||
| const raw = res?.data?.data?.total_supply; | ||
| const n = Number(raw); | ||
| if (raw == null || raw === "" || !Number.isFinite(n) || n < 0) { | ||
| throw new Error("UST1 token_info.total_supply missing or invalid"); | ||
| } | ||
| const balances = {} as Balances; | ||
| sumSingleBalance(balances, "peggedUSD", n / 10 ** UST1_DECIMALS, "issued", false); | ||
| return balances; | ||
| } | ||
|
|
||
| const adapter: PeggedIssuanceAdapter = { | ||
| terra: { | ||
| minted: terraMinted, | ||
| unreleased: async () => ({}), | ||
| }, | ||
| }; | ||
|
|
||
| export default adapter; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: DefiLlama/peggedassets-server
Length of output: 915
🏁 Script executed:
Repository: DefiLlama/peggedassets-server
Length of output: 50385
🏁 Script executed:
Repository: DefiLlama/peggedassets-server
Length of output: 5117
🌐 Web query:
Axios 1.7.7 request config timeout default 0 documentation async-retry 1.3.1 retries only when promise rejects💡 Result:
In Axios 1.7.7, the request configuration property
timeoutspecifies the number of milliseconds before a request times out, with a default value of 0, which signifies no timeout [1][2][3]. Regardingasync-retry1.3.1, the library is designed to retry when the provided function throws an error or returns a promise that rejects [4][5]. If the function resolves successfully,async-retryconsiders the operation complete and does not retry [4][5]. Therefore, retries only occur when the promise rejects or an error is thrown [4][5]. Note that if you need to abort retries manually within the function, you can invoke thebailfunction provided as the first argument to the retrier [4][5].Citations:
Bound the Terra LCD request.
axios.get(url)uses Axios 1.7.7 with the defaulttimeout: 0. A stalled request remains pending, soasync-retrycannot start another attempt andterraMintedmay not publish a supply update.Set a per-attempt timeout.
🤖 Prompt for AI Agents