@exponent-labs/generic-sy-sdk 0.9.19 → 0.9.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.d.ts +16 -2
- package/build/index.js +160 -207
- package/build/index.js.map +1 -1
- package/build/interfaces/exponentTranching.d.ts +12 -0
- package/build/interfaces/exponentTranching.js +75 -0
- package/build/interfaces/exponentTranching.js.map +1 -0
- package/build/interfaces/glowVault.d.ts +7 -0
- package/build/interfaces/glowVault.js +46 -0
- package/build/interfaces/glowVault.js.map +1 -0
- package/package.json +10 -10
- package/src/index.ts +179 -159
- package/src/interfaces/exponentTranching.ts +125 -0
- package/src/interfaces/glowVault.ts +55 -0
- package/tsconfig.json +3 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { web3 } from "@coral-xyz/anchor"
|
|
2
|
+
|
|
3
|
+
const GLOW_VAULT_PROGRAM_ID = new web3.PublicKey("gwv1ybUe2JVEpjdWARK1PjZUVY5xdNUCRhu24tgYtxa")
|
|
4
|
+
const GLOW_VAULT_DISCRIMINATOR = Buffer.from([211, 8, 232, 43, 2, 152, 117, 119])
|
|
5
|
+
const GLOW_VAULT_ACCOUNT_SIZE = 8 + 552
|
|
6
|
+
const SHARE_MINT_OFFSET = 8 + 160
|
|
7
|
+
const DEPOSIT_TOKENS_OFFSET = 8 + 320
|
|
8
|
+
const DEPOSIT_SHARES_OFFSET = 8 + 336
|
|
9
|
+
const UNCOLLECTED_MANAGEMENT_FEES_OFFSET = 8 + 344
|
|
10
|
+
const MINIMUM_SHARES_DUST_THRESHOLD_OFFSET = 8 + 408
|
|
11
|
+
const REALISED_PERFORMANCE_FEES_OFFSET = 8 + 488
|
|
12
|
+
const NUMBER_DENOMINATOR = 1_000_000_000_000n
|
|
13
|
+
|
|
14
|
+
/** Reads a Glow vault's net underlying-token value per share. */
|
|
15
|
+
export async function fetchGlowVaultRate(params: {
|
|
16
|
+
connection: web3.Connection
|
|
17
|
+
vaultAddress: web3.PublicKey
|
|
18
|
+
expectedShareMint: web3.PublicKey
|
|
19
|
+
}): Promise<number> {
|
|
20
|
+
const accountInfo = await params.connection.getAccountInfo(params.vaultAddress)
|
|
21
|
+
if (!accountInfo) {
|
|
22
|
+
throw new Error(`Glow vault not found: ${params.vaultAddress.toBase58()}`)
|
|
23
|
+
}
|
|
24
|
+
if (!accountInfo.owner.equals(GLOW_VAULT_PROGRAM_ID)) {
|
|
25
|
+
throw new Error(`Invalid Glow vault owner: ${accountInfo.owner.toBase58()}`)
|
|
26
|
+
}
|
|
27
|
+
if (accountInfo.data.length < GLOW_VAULT_ACCOUNT_SIZE) {
|
|
28
|
+
throw new Error(`Glow vault account is too short: ${accountInfo.data.length}`)
|
|
29
|
+
}
|
|
30
|
+
if (!accountInfo.data.subarray(0, 8).equals(GLOW_VAULT_DISCRIMINATOR)) {
|
|
31
|
+
throw new Error("Invalid Glow vault discriminator")
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const shareMint = new web3.PublicKey(accountInfo.data.subarray(SHARE_MINT_OFFSET, SHARE_MINT_OFFSET + 32))
|
|
35
|
+
if (!shareMint.equals(params.expectedShareMint)) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
`Glow vault share mint ${shareMint.toBase58()} does not match ${params.expectedShareMint.toBase58()}`,
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const depositShares = accountInfo.data.readBigUInt64LE(DEPOSIT_SHARES_OFFSET)
|
|
42
|
+
const minimumSharesDustThreshold = accountInfo.data.readBigUInt64LE(MINIMUM_SHARES_DUST_THRESHOLD_OFFSET)
|
|
43
|
+
if (depositShares <= minimumSharesDustThreshold) return 1
|
|
44
|
+
|
|
45
|
+
const depositTokens = accountInfo.data.readBigUInt64LE(DEPOSIT_TOKENS_OFFSET)
|
|
46
|
+
const uncollectedManagementFees = accountInfo.data.readBigUInt64LE(UNCOLLECTED_MANAGEMENT_FEES_OFFSET)
|
|
47
|
+
const realisedPerformanceFees = accountInfo.data.readBigUInt64LE(REALISED_PERFORMANCE_FEES_OFFSET)
|
|
48
|
+
const netAfterManagementFees =
|
|
49
|
+
depositTokens > uncollectedManagementFees ? depositTokens - uncollectedManagementFees : 0n
|
|
50
|
+
const netTokens =
|
|
51
|
+
netAfterManagementFees > realisedPerformanceFees ? netAfterManagementFees - realisedPerformanceFees : 0n
|
|
52
|
+
const rateRaw = (netTokens * NUMBER_DENOMINATOR) / depositShares
|
|
53
|
+
|
|
54
|
+
return Number(rateRaw) / Number(NUMBER_DENOMINATOR)
|
|
55
|
+
}
|