mirror of
https://github.com/alexgo-io/peggedassets-server.git
synced 2026-01-12 22:43:29 +08:00
refactor threshold usd adapter (#354)
* refactor threshold usd adapter * code refactor --------- Co-authored-by: g1nt0ki <99907941+g1nt0ki@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
b335fe0851
commit
1502a69005
@@ -1,16 +1,44 @@
|
||||
import {
|
||||
PeggedIssuanceAdapter,
|
||||
Balances,
|
||||
} from "../peggedAsset.type";
|
||||
import { sumSingleBalance } from "../helper/generalUtil";
|
||||
import { ChainApi } from "@defillama/sdk";
|
||||
|
||||
const chainContracts = {
|
||||
ethereum: {
|
||||
issued: ["0xcfc5bd99915aaa815401c5a41a927ab7a38d29cf"],
|
||||
unreleased: [
|
||||
"0x097f1ee62E63aCFC3Bf64c1a61d96B3771dd06cB", // Protocol Controlled Value
|
||||
"0x1a4739509F50E683927472b03e251e36d07DD872", // Protocol Controlled ETH Value
|
||||
"0xF6374AEfb1e69a21ee516ea4B803b2eA96d06f29", // Stability Pool
|
||||
"0xA18Ab4Fa9a44A72c58e64bfB33D425Ec48475a9f", // Stability Pool ETH
|
||||
],
|
||||
},
|
||||
ethereum: {
|
||||
issued: ["0xcfc5bd99915aaa815401c5a41a927ab7a38d29cf"],
|
||||
pcvContracts: [
|
||||
"0x097f1ee62E63aCFC3Bf64c1a61d96B3771dd06cB", // Protocol Controlled Value tBTC Collateral
|
||||
"0x1a4739509F50E683927472b03e251e36d07DD872", // Protocol Controlled Value ETH Collateral
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
async function ethereumMinted() {
|
||||
return async function (api: ChainApi) {
|
||||
let balances = {} as Balances;
|
||||
const totalSupply = await api.call({ abi: "erc20:totalSupply", target: chainContracts.ethereum.issued[0], })
|
||||
sumSingleBalance(balances, "peggedUSD", totalSupply / 1e18, "issued", false);
|
||||
return balances;
|
||||
};
|
||||
|
||||
import { addChainExports } from "../helper/getSupply";
|
||||
const adapter = addChainExports(chainContracts);
|
||||
export default adapter;
|
||||
|
||||
}
|
||||
|
||||
async function ethereumUnreleased() {
|
||||
return async function (api: ChainApi) {
|
||||
let balances = {} as Balances;
|
||||
const debts = await api.multiCall({ abi: 'uint256:debtToPay', calls: chainContracts.ethereum.pcvContracts})
|
||||
for (const debt of debts)
|
||||
sumSingleBalance(balances, "peggedUSD", debt / 1e18)
|
||||
return balances;
|
||||
};
|
||||
}
|
||||
|
||||
const adapter: PeggedIssuanceAdapter = {
|
||||
ethereum: {
|
||||
minted: ethereumMinted(),
|
||||
unreleased: ethereumUnreleased(),
|
||||
},
|
||||
};
|
||||
|
||||
export default adapter;
|
||||
|
||||
Reference in New Issue
Block a user