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

Add Zeusnetwork TVL adaptor #13732

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions projects/helper/bitcoin-book/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,20 @@ const stacksSBTC = [
'bc1prcs82tvrz70jk8u79uekwdfjhd0qhs2mva6e526arycu7fu25zsqhyztuy',
]

const zeusZBTC = [
// https://docs.zeusnetwork.xyz/intro/welcome-to-zeus-network/how-it-works-bitcoin-and-solana
'bc1pnfxwuhs7tdrdwy4dpqp4s7pslfy725jjnq5mlrzqlenawf3zzmmsenz0pl',
'bc1pe9mqlwch368qk5y8q6s2h68allugyyp5mnr0ps6adfucduz24z8sxzhuey',
]

const magpie = [
'1FoGLbVfpN6e35J45vXSwqsTSajcSxXcYF',
'bc1ppgxcpqq7vm5ckl3unryndeqheut8lanjtpng9jwxjdv6m53w9wuqx4fqy8'
]

module.exports = {
...fetchers,
zeusZBTC,
cygnus,
magpie,
stacksSBTC,
Expand Down
3 changes: 2 additions & 1 deletion projects/helper/utils/solana/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { RAYDIUM_LIQUIDITY_STATE_LAYOUT_CLMM, RAYDIUM_STABLE_STATE_LAYOUT_V1, RAY
const { INVESTIN_FUND_DATA, } = require('./layouts/investin-layout')
const { MARKET_STATE_LAYOUT_V3, OPEN_ORDERS_LAYOUT_V2, MARKET_STATE_LAYOUT_V3_MINIMAL } = require('./layouts/openbook-layout')
const { ReserveLayout, ReserveLayoutLarix, MintLayout, AccountLayout, TokenSwapLayout, ESOLStakePoolLayout, PARLAY_LAYOUT_PARTIAL, HH_PARI_LAYOUT_PARTIAL, ACCESS_LAYOUT,
METEORA_STABLE_SWAP_LAYOUT,
METEORA_STABLE_SWAP_LAYOUT, ZEUS_GUARDIAN_SETTING_LAYOUT,
} = require('./layouts/mixed-layout');
const { SCN_STAKE_POOL, TOKEN_LAYOUT, } = require("./layouts/scnSOL");
const { SANCTUM_INFINITY } = require("./layouts/sanctum-infinity-layout");
Expand Down Expand Up @@ -70,6 +70,7 @@ const customDecoders = {
hhPari: defaultParseLayout(HH_PARI_LAYOUT_PARTIAL),
access: defaultParseLayout(ACCESS_LAYOUT),
meteoraStablePool: defaultParseLayout(METEORA_STABLE_SWAP_LAYOUT),
zeusGuardianSetting: defaultParseLayout(ZEUS_GUARDIAN_SETTING_LAYOUT),
}

function decodeAccount(layout, accountInfo) {
Expand Down
25 changes: 24 additions & 1 deletion projects/helper/utils/solana/layouts/mixed-layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,31 @@ const METEORA_STABLE_SWAP_LAYOUT = BufferLayout.struct([
]),
]);

const ZEUS_GUARDIAN_SETTING_LAYOUT = BufferLayout.struct([
publicKey("spl_token_escrow_authority"),
publicKey("spl_token_vault_authority"),

u32("seed"),
u8("status"),
publicKey("guardian_certificate"),

u64("max_quota"),
u64("available_quota"),
u64("accumulated_amount"),
u64("penalty_rate"),
u8("delegation_removal_lock_days"),
u64("quota_increasing_rate"),

u64("created_at"),
u64("updated_at"),

BufferLayout.seq(u8(), 64, "delegate_options"), // Adjust size based on typical vector length

blob(128, "_padding"), // Ensuring 128-byte padding for safety
]);

module.exports = {
ReserveLayout, ReserveLayoutLarix, MintLayout, AccountLayout, TokenSwapLayout, ESOLStakePoolLayout,
PARLAY_LAYOUT_PARTIAL, HH_PARI_LAYOUT_PARTIAL, ACCESS_LAYOUT, METEORA_STABLE_SWAP_LAYOUT,
PARLAY_LAYOUT_PARTIAL, HH_PARI_LAYOUT_PARTIAL, ACCESS_LAYOUT, METEORA_STABLE_SWAP_LAYOUT, ZEUS_GUARDIAN_SETTING_LAYOUT,
}

60 changes: 60 additions & 0 deletions projects/zeus/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const { getConnection, decodeAccount } = require("../helper/solana");
const { PublicKey } = require("@solana/web3.js");
const { sha256 } = require("js-sha256")
const bs58 = require("bs58")
const { sumTokensExport } = require('../helper/sumTokens');
const bitcoinAddressBook = require('../helper/bitcoin-book/index.js')

const programs = {
delegator: 'ZPLt7XEyRvRxEZcGFGnRKGLBymFjQbwmgTZhMAMfGAU',
two_way_peg: 'ZPLzxjNk1zUAgJmm3Jkmrhvb4UaLwzvY2MotpfovF5K',
liquidity_manager: 'ZPLuj6HoZ2z6y6WfJuHz3Gg48QeMZ6kGbsa74oPxACY'
};

const ZEUS_MINT_ADDRESS = 'ZEUS1aR7aX8DFFJf5QjWj2ftDDdNTroMNGo8YoQm3Gq'
const ZBTC_MINT_ADDRESS = 'zBTCug3er3tLyffELcvDNrKkCymbPWysGcWihESYfLg'
const WBTC_MINT_ADDRESS = '3NZ9JMVBmGAqocybic2c7LQCJScmgsAZ6vQqTDzcqmJh'

async function tvl(api) {
const data = [];
const connection = getConnection();
const programDelegator = new PublicKey(programs.delegator);


function generateDiscriminator(
preImage
) {
return Buffer.from(sha256(preImage), "hex").subarray(0, 8);
}
const filters = [
{
memcmp: {
offset: 0,
bytes: bs58.encode(generateDiscriminator("delegator:guardian-setting")),
},
},
];
const accounts = await connection.getProgramAccounts(programDelegator, {
filters, // Adjust dataSize based on GuardianSetting size
});

data.push(...accounts.map(i => decodeAccount('zeusGuardianSetting', i.account)));
let totalAccumulatedAmount = BigInt(0);

data.forEach(({ accumulated_amount, max_quota, available_quota }) => {
totalAccumulatedAmount += BigInt(accumulated_amount);
});

console.log(`Total Accumulated Amount: ${totalAccumulatedAmount}`);
api.add(ZEUS_MINT_ADDRESS, totalAccumulatedAmount.toString())
}

module.exports = {
timetravel: false,
solana: {
tvl,
},
bitcoin: {
tvl: sumTokensExport({ owners: bitcoinAddressBook.zeusZBTC }),
},
};
Loading