hedge-web3 0.1.2 → 0.1.8
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/README.md +44 -0
- package/lib/index.js +385 -73
- package/lib/index.js.map +1 -1
- package/lib/types/src/Constants.d.ts +3 -3
- package/lib/types/src/Constants.d.ts.map +1 -1
- package/lib/types/src/StakingPools.d.ts +4 -0
- package/lib/types/src/StakingPools.d.ts.map +1 -0
- package/lib/types/src/Vaults.d.ts +9 -0
- package/lib/types/src/Vaults.d.ts.map +1 -0
- package/lib/types/src/index.d.ts +12 -2
- package/lib/types/src/index.d.ts.map +1 -1
- package/lib/types/src/instructions/createStakingPool.d.ts +5 -0
- package/lib/types/src/instructions/createStakingPool.d.ts.map +1 -0
- package/lib/types/src/instructions/createVault.d.ts +4 -3
- package/lib/types/src/instructions/createVault.d.ts.map +1 -1
- package/lib/types/src/instructions/depositStakingPool.d.ts +5 -0
- package/lib/types/src/instructions/depositStakingPool.d.ts.map +1 -0
- package/lib/types/src/instructions/depositVault.d.ts +4 -3
- package/lib/types/src/instructions/depositVault.d.ts.map +1 -1
- package/lib/types/src/instructions/liquidateVault.d.ts +5 -0
- package/lib/types/src/instructions/liquidateVault.d.ts.map +1 -0
- package/lib/types/src/instructions/loanVault.d.ts +4 -3
- package/lib/types/src/instructions/loanVault.d.ts.map +1 -1
- package/lib/types/src/instructions/redeemVault.d.ts +4 -3
- package/lib/types/src/instructions/redeemVault.d.ts.map +1 -1
- package/lib/types/src/instructions/repayVault.d.ts +4 -3
- package/lib/types/src/instructions/repayVault.d.ts.map +1 -1
- package/lib/types/src/instructions/withdrawStakingPool.d.ts +5 -0
- package/lib/types/src/instructions/withdrawStakingPool.d.ts.map +1 -0
- package/lib/types/src/instructions/withdrawVault.d.ts +4 -3
- package/lib/types/src/instructions/withdrawVault.d.ts.map +1 -1
- package/lib/types/src/state/LiquidationPoolEra.d.ts.map +1 -1
- package/lib/types/src/state/LiquidationPosition.d.ts +1 -0
- package/lib/types/src/state/LiquidationPosition.d.ts.map +1 -1
- package/lib/types/src/state/StakingPool.d.ts +1 -2
- package/lib/types/src/state/StakingPool.d.ts.map +1 -1
- package/lib/types/src/state/StakingPoolPosition.d.ts +1 -0
- package/lib/types/src/state/StakingPoolPosition.d.ts.map +1 -1
- package/lib/types/src/state/VaultAccount.d.ts.map +1 -1
- package/lib/types/src/utils/Errors.d.ts +2 -0
- package/lib/types/src/utils/Errors.d.ts.map +1 -0
- package/lib/types/tsconfig.base.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/Constants.ts +3 -3
- package/src/StakingPools.ts +3 -0
- package/src/Vaults.ts +8 -0
- package/src/index.ts +14 -5
- package/src/instructions/createStakingPool.ts +64 -0
- package/src/instructions/createVault.ts +10 -11
- package/src/instructions/depositStakingPool.ts +60 -0
- package/src/instructions/depositVault.ts +10 -11
- package/src/instructions/liquidateVault.ts +66 -0
- package/src/instructions/loanVault.ts +10 -11
- package/src/instructions/redeemVault.ts +10 -11
- package/src/instructions/repayVault.ts +10 -11
- package/src/instructions/withdrawStakingPool.ts +69 -0
- package/src/instructions/withdrawVault.ts +10 -11
- package/src/state/LiquidationPoolEra.ts +5 -5
- package/src/state/LiquidationPosition.ts +26 -18
- package/src/state/StakingPool.ts +4 -5
- package/src/state/StakingPoolPosition.ts +4 -5
- package/src/state/VaultAccount.ts +0 -1
- package/src/state/VaultHistoryEvent.ts +1 -1
- package/src/types/buffer-layout/index.d.ts +88 -0
- package/src/utils/Errors.ts +11 -0
- package/typedoc.json +1 -2
@@ -1,22 +1,20 @@
|
|
1
|
-
import { BN, Program } from '@project-serum/anchor'
|
1
|
+
import { BN, Program, Provider } from '@project-serum/anchor'
|
2
2
|
import { Token, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
|
-
import {
|
4
|
-
import { CHAINLINK_SOL_USD_PUBLICKEY, findAssociatedTokenAddress, getHedgeMintPublicKey, getPoolPublicKeyForMint, getUsdhMintPublicKey, getVaultSystemStatePublicKey
|
5
|
-
|
6
|
-
import { vaultIdl } from '../idl/idl'
|
3
|
+
import { Keypair, LAMPORTS_PER_SOL, PublicKey, sendAndConfirmTransaction, Signer, SystemProgram, Transaction, TransactionInstruction } from '@solana/web3.js'
|
4
|
+
import { CHAINLINK_SOL_USD_PUBLICKEY, findAssociatedTokenAddress, getHedgeMintPublicKey, getPoolPublicKeyForMint, getUsdhMintPublicKey, getVaultSystemStatePublicKey } from '../Constants'
|
7
5
|
|
8
6
|
export async function redeemVault (
|
9
|
-
|
7
|
+
program: Program,
|
8
|
+
provider: Provider,
|
10
9
|
payer: Signer,
|
11
10
|
vaultPublicKey: PublicKey,
|
12
11
|
repayAmount: number,
|
13
12
|
chainlinkOverridePrice?: number,
|
14
|
-
transactionOverrideTime?: number
|
15
|
-
confirmOptions?: ConfirmOptions
|
13
|
+
transactionOverrideTime?: number
|
16
14
|
): Promise<PublicKey> {
|
17
15
|
const [usdhMintPublickey] = await getUsdhMintPublicKey()
|
18
16
|
const USDH = new Token(
|
19
|
-
connection,
|
17
|
+
provider.connection,
|
20
18
|
usdhMintPublickey,
|
21
19
|
TOKEN_PROGRAM_ID,
|
22
20
|
payer
|
@@ -28,6 +26,7 @@ export async function redeemVault (
|
|
28
26
|
const history = Keypair.generate()
|
29
27
|
const transaction = new Transaction().add(
|
30
28
|
await redeemVaultInstruction(
|
29
|
+
program,
|
31
30
|
payer.publicKey,
|
32
31
|
payerUsdhAccount.address,
|
33
32
|
vaultPublicKey,
|
@@ -37,11 +36,12 @@ export async function redeemVault (
|
|
37
36
|
transactionOverrideTime
|
38
37
|
)
|
39
38
|
)
|
40
|
-
await sendAndConfirmTransaction(connection, transaction, [payer, history],
|
39
|
+
await sendAndConfirmTransaction(provider.connection, transaction, [payer, history], provider.opts)
|
41
40
|
return vaultPublicKey
|
42
41
|
}
|
43
42
|
|
44
43
|
export async function redeemVaultInstruction (
|
44
|
+
program: Program,
|
45
45
|
payerPublicKey: PublicKey,
|
46
46
|
ownerUsdhAccount: PublicKey,
|
47
47
|
vaultPublickey: PublicKey,
|
@@ -50,7 +50,6 @@ export async function redeemVaultInstruction (
|
|
50
50
|
chainlinkOverridePrice?: number,
|
51
51
|
transactionOverrideTime?: number
|
52
52
|
): Promise<TransactionInstruction> {
|
53
|
-
const program = new Program(vaultIdl, HEDGE_PROGRAM_ID)
|
54
53
|
const [vaultSystemStatePublicKey] = await getVaultSystemStatePublicKey()
|
55
54
|
const [usdhMintPublickey] = await getUsdhMintPublicKey()
|
56
55
|
const [hedgeMintPublickey] = await getHedgeMintPublicKey()
|
@@ -1,20 +1,18 @@
|
|
1
|
-
import { BN, Program } from '@project-serum/anchor'
|
1
|
+
import { BN, Program, Provider } from '@project-serum/anchor'
|
2
2
|
import { Token, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
|
-
import {
|
4
|
-
import { findAssociatedTokenAddress, getHedgeMintPublicKey, getPoolPublicKeyForMint, getUsdhMintPublicKey, getVaultSystemStatePublicKey
|
5
|
-
|
6
|
-
import { vaultIdl } from '../idl/idl'
|
3
|
+
import { Keypair, PublicKey, sendAndConfirmTransaction, Signer, SystemProgram, Transaction, TransactionInstruction } from '@solana/web3.js'
|
4
|
+
import { findAssociatedTokenAddress, getHedgeMintPublicKey, getPoolPublicKeyForMint, getUsdhMintPublicKey, getVaultSystemStatePublicKey } from '../Constants'
|
7
5
|
|
8
6
|
export async function repayVault (
|
9
|
-
|
7
|
+
program: Program,
|
8
|
+
provider: Provider,
|
10
9
|
payer: Signer,
|
11
10
|
vaultPublicKey: PublicKey,
|
12
|
-
repayAmount: number
|
13
|
-
confirmOptions?: ConfirmOptions
|
11
|
+
repayAmount: number
|
14
12
|
): Promise<PublicKey> {
|
15
13
|
const [usdhMintPublickey] = await getUsdhMintPublicKey()
|
16
14
|
const USDH = new Token(
|
17
|
-
connection,
|
15
|
+
provider.connection,
|
18
16
|
usdhMintPublickey,
|
19
17
|
TOKEN_PROGRAM_ID,
|
20
18
|
payer
|
@@ -26,6 +24,7 @@ export async function repayVault (
|
|
26
24
|
const history = Keypair.generate()
|
27
25
|
const transaction = new Transaction().add(
|
28
26
|
await repayVaultInstruction(
|
27
|
+
program,
|
29
28
|
payer.publicKey,
|
30
29
|
payerUsdhAccount.address,
|
31
30
|
vaultPublicKey,
|
@@ -33,18 +32,18 @@ export async function repayVault (
|
|
33
32
|
repayAmount
|
34
33
|
)
|
35
34
|
)
|
36
|
-
await sendAndConfirmTransaction(connection, transaction, [payer, history],
|
35
|
+
await sendAndConfirmTransaction(provider.connection, transaction, [payer, history], provider.opts)
|
37
36
|
return vaultPublicKey
|
38
37
|
}
|
39
38
|
|
40
39
|
export async function repayVaultInstruction (
|
40
|
+
program: Program,
|
41
41
|
payerPublicKey: PublicKey,
|
42
42
|
ownerUsdhAccount: PublicKey,
|
43
43
|
vaultPublickey: PublicKey,
|
44
44
|
historyPublicKey: PublicKey,
|
45
45
|
repayAmount: number
|
46
46
|
): Promise<TransactionInstruction> {
|
47
|
-
const program = new Program(vaultIdl, HEDGE_PROGRAM_ID)
|
48
47
|
const [vaultSystemStatePublicKey] = await getVaultSystemStatePublicKey()
|
49
48
|
const [usdhMintPublickey] = await getUsdhMintPublicKey()
|
50
49
|
const [hedgeMintPublickey] = await getHedgeMintPublicKey()
|
@@ -0,0 +1,69 @@
|
|
1
|
+
import { BN, Program, Provider } from '@project-serum/anchor'
|
2
|
+
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
|
+
import { Keypair, PublicKey, sendAndConfirmTransaction, Signer, SystemProgram, SYSVAR_RENT_PUBKEY, Transaction, TransactionInstruction } from '@solana/web3.js'
|
4
|
+
import { parseAnchorErrors } from '../utils/Errors'
|
5
|
+
import { findAssociatedTokenAddress, getHedgeMintPublicKey, getPoolPublicKeyForMint, getUsdhMintPublicKey, getVaultSystemStatePublicKey } from '../Constants'
|
6
|
+
|
7
|
+
export async function withdrawStakingPool (
|
8
|
+
program: Program,
|
9
|
+
provider: Provider,
|
10
|
+
payer: Signer,
|
11
|
+
poolPositionPublicKey: PublicKey,
|
12
|
+
stakedTokenMintPublicKey: PublicKey,
|
13
|
+
overrideStartTime?: number
|
14
|
+
): Promise<PublicKey> {
|
15
|
+
const poolPosition = Keypair.generate()
|
16
|
+
const transaction = new Transaction().add(
|
17
|
+
await withdrawStakingPoolInstruction(
|
18
|
+
program,
|
19
|
+
payer.publicKey,
|
20
|
+
poolPositionPublicKey,
|
21
|
+
stakedTokenMintPublicKey,
|
22
|
+
overrideStartTime
|
23
|
+
)
|
24
|
+
)
|
25
|
+
await sendAndConfirmTransaction(provider.connection, transaction, [payer], provider.opts).catch(parseAnchorErrors)
|
26
|
+
return poolPosition.publicKey
|
27
|
+
}
|
28
|
+
|
29
|
+
export async function withdrawStakingPoolInstruction (
|
30
|
+
program: Program,
|
31
|
+
payerPublicKey: PublicKey,
|
32
|
+
poolPositionPublicKey: PublicKey,
|
33
|
+
stakedTokenMintPublicKey: PublicKey,
|
34
|
+
overrideStartTime?: number
|
35
|
+
): Promise<TransactionInstruction> {
|
36
|
+
const [vaultSystemStatePublicKey] = await getVaultSystemStatePublicKey()
|
37
|
+
const [usdhMintPublickey] = await getUsdhMintPublicKey()
|
38
|
+
const [hedgeMintPublickey] = await getHedgeMintPublicKey()
|
39
|
+
const [poolPublickey] = await getPoolPublicKeyForMint(stakedTokenMintPublicKey)
|
40
|
+
const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(poolPublickey, stakedTokenMintPublicKey)
|
41
|
+
const poolAssociatedUsdhTokenAccount = await findAssociatedTokenAddress(poolPublickey, usdhMintPublickey)
|
42
|
+
const payerAssociatedStakedTokenAccount = await findAssociatedTokenAddress(payerPublicKey, stakedTokenMintPublicKey)
|
43
|
+
const payerAssociatedHedgeAccount = await findAssociatedTokenAddress(payerPublicKey, hedgeMintPublickey)
|
44
|
+
const payerAssociatedUsdhAccount = await findAssociatedTokenAddress(payerPublicKey, usdhMintPublickey)
|
45
|
+
|
46
|
+
return program.instruction.withdrawStakingPool(
|
47
|
+
new BN(overrideStartTime ?? Date.now() / 1000), // override current time
|
48
|
+
{
|
49
|
+
accounts: {
|
50
|
+
payer: payerPublicKey,
|
51
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
52
|
+
pool: poolPublickey,
|
53
|
+
poolPosition: poolPositionPublicKey,
|
54
|
+
poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
|
55
|
+
poolAssociatedUsdhTokenAccount: poolAssociatedUsdhTokenAccount,
|
56
|
+
payerAssociatedStakedTokenAccount: payerAssociatedStakedTokenAccount,
|
57
|
+
payerAssociatedHedgeAccount: payerAssociatedHedgeAccount,
|
58
|
+
payerAssociatedUsdhAccount: payerAssociatedUsdhAccount,
|
59
|
+
hedgeMint: hedgeMintPublickey,
|
60
|
+
stakedTokenMint: stakedTokenMintPublicKey,
|
61
|
+
usdhMint: usdhMintPublickey,
|
62
|
+
rent: SYSVAR_RENT_PUBKEY,
|
63
|
+
splTokenProgramInfo: TOKEN_PROGRAM_ID,
|
64
|
+
splAssociatedTokenProgramInfo: ASSOCIATED_TOKEN_PROGRAM_ID,
|
65
|
+
systemProgram: SystemProgram.programId
|
66
|
+
},
|
67
|
+
signers: []
|
68
|
+
})
|
69
|
+
}
|
@@ -1,21 +1,19 @@
|
|
1
|
-
import { BN, Program } from '@project-serum/anchor'
|
1
|
+
import { BN, Program, Provider } from '@project-serum/anchor'
|
2
2
|
import { Token, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
|
-
import {
|
4
|
-
import { CHAINLINK_SOL_USD_PUBLICKEY, getUsdhMintPublicKey, getVaultSystemStatePublicKey
|
5
|
-
|
6
|
-
import { vaultIdl } from '../idl/idl'
|
3
|
+
import { Keypair, LAMPORTS_PER_SOL, PublicKey, sendAndConfirmTransaction, Signer, SystemProgram, Transaction, TransactionInstruction } from '@solana/web3.js'
|
4
|
+
import { CHAINLINK_SOL_USD_PUBLICKEY, getUsdhMintPublicKey, getVaultSystemStatePublicKey } from '../Constants'
|
7
5
|
|
8
6
|
export async function withdrawVault (
|
9
|
-
|
7
|
+
program: Program,
|
8
|
+
provider: Provider,
|
10
9
|
payer: Signer,
|
11
10
|
vaultPublicKey: PublicKey,
|
12
11
|
withdrawAmount: number,
|
13
|
-
chainlinkOverridePrice?: number
|
14
|
-
confirmOptions?: ConfirmOptions
|
12
|
+
chainlinkOverridePrice?: number
|
15
13
|
): Promise<PublicKey> {
|
16
14
|
const [usdhMintPublickey] = await getUsdhMintPublicKey()
|
17
15
|
const USDH = new Token(
|
18
|
-
connection,
|
16
|
+
provider.connection,
|
19
17
|
usdhMintPublickey,
|
20
18
|
TOKEN_PROGRAM_ID,
|
21
19
|
payer
|
@@ -28,6 +26,7 @@ export async function withdrawVault (
|
|
28
26
|
const [vaultSystemStatePublicKey] = await getVaultSystemStatePublicKey()
|
29
27
|
const transaction = new Transaction().add(
|
30
28
|
withdrawVaultInstruction(
|
29
|
+
program,
|
31
30
|
vaultSystemStatePublicKey,
|
32
31
|
payer.publicKey,
|
33
32
|
vaultPublicKey,
|
@@ -36,11 +35,12 @@ export async function withdrawVault (
|
|
36
35
|
chainlinkOverridePrice
|
37
36
|
)
|
38
37
|
)
|
39
|
-
await sendAndConfirmTransaction(connection, transaction, [payer, history],
|
38
|
+
await sendAndConfirmTransaction(provider.connection, transaction, [payer, history], provider.opts)
|
40
39
|
return vaultPublicKey
|
41
40
|
}
|
42
41
|
|
43
42
|
export function withdrawVaultInstruction (
|
43
|
+
program: Program,
|
44
44
|
vaultSystemStatePublicKey: PublicKey,
|
45
45
|
payerPublicKey: PublicKey,
|
46
46
|
vaultPublickey: PublicKey,
|
@@ -48,7 +48,6 @@ export function withdrawVaultInstruction (
|
|
48
48
|
withdrawAmount: number,
|
49
49
|
chainlinkOverridePrice?: number
|
50
50
|
): TransactionInstruction {
|
51
|
-
const program = new Program(vaultIdl, HEDGE_PROGRAM_ID)
|
52
51
|
return program.instruction.withdrawVault(
|
53
52
|
new BN(withdrawAmount),
|
54
53
|
new BN(chainlinkOverridePrice ?? 200 * LAMPORTS_PER_SOL),
|
@@ -1,6 +1,6 @@
|
|
1
1
|
|
2
2
|
import Decimal from 'decimal.js'
|
3
|
-
import { DecimalFromU128 } from '
|
3
|
+
import { DecimalFromU128 } from '../HedgeDecimal'
|
4
4
|
|
5
5
|
/**
|
6
6
|
* Represents an on-chian pool era. In the event an era is depleted of deposits, a new era is
|
@@ -9,13 +9,13 @@ import { DecimalFromU128 } from '..'
|
|
9
9
|
export class LiquidationPoolEra {
|
10
10
|
public totalDeposits: number
|
11
11
|
|
12
|
-
product: Decimal
|
12
|
+
public product: Decimal
|
13
13
|
|
14
|
-
sum: Decimal
|
14
|
+
public sum: Decimal
|
15
15
|
|
16
|
-
hedgeRewardsAccumulator: Decimal
|
16
|
+
public hedgeRewardsAccumulator: Decimal
|
17
17
|
|
18
|
-
hedgeRewardsTimestamp: number
|
18
|
+
public hedgeRewardsTimestamp: number
|
19
19
|
|
20
20
|
constructor (public liquidyPoolEra: any) {
|
21
21
|
this.totalDeposits = liquidyPoolEra.totalDeposits.toNumber()
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import { PublicKey } from '@solana/web3.js'
|
1
|
+
import { LAMPORTS_PER_SOL, PublicKey } from '@solana/web3.js'
|
2
2
|
import Decimal from 'decimal.js'
|
3
|
-
import { DecimalFromU128 } from '
|
3
|
+
import { DecimalFromU128 } from '../HedgeDecimal'
|
4
4
|
import { LiquidationPoolEra } from './LiquidationPoolEra'
|
5
5
|
import { LiquidationPoolState } from './LiquidationPoolState'
|
6
6
|
|
@@ -48,22 +48,30 @@ export class LiquidationPosition {
|
|
48
48
|
return this.era.sum.minus(this.sumSnapshot).div(this.productSnapshot).mul(new Decimal(this.deposit)).floor()
|
49
49
|
}
|
50
50
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
51
|
+
public getHedgeAvailable (): Decimal {
|
52
|
+
const LiquidationPoolTotalSupply = 2000000.0 * LAMPORTS_PER_SOL
|
53
|
+
const hedgeRewardsSinceLastUpdate = hedgeRewardsDecay(
|
54
|
+
LiquidationPoolTotalSupply,
|
55
|
+
this.liquidationPoolState.hedgeInitRewardsTimestamp * 1000,
|
56
|
+
this.era.hedgeRewardsTimestamp * 1000,
|
57
|
+
Date.now(),
|
58
|
+
365 * 1000)
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
|
60
|
+
if (this.era.totalDeposits === 0) {
|
61
|
+
return new Decimal(0)
|
62
|
+
}
|
63
63
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
64
|
+
const rewardsPerToken = this.era.product.mul(new Decimal(hedgeRewardsSinceLastUpdate / this.era.totalDeposits))
|
65
|
+
const newAccumulator = rewardsPerToken.add(new Decimal(this.era.hedgeRewardsAccumulator))
|
66
|
+
const hedgeAvailable = (newAccumulator.minus(this.hedgeRewardsSnapshot)).mul(new Decimal(this.deposit)).div(new Decimal(this.productSnapshot))
|
67
|
+
return hedgeAvailable
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
function hedgeRewardsDecay (supply: number, birthTime: number, timeIn: number, timeOut: number, halfLifeInDays: number): number {
|
72
|
+
const timeInOffsetStart = timeIn - birthTime
|
73
|
+
const timeOutOffsetStart = timeOut - birthTime
|
74
|
+
const halfLife = -1 * Math.log(2) / (halfLifeInDays * 60 * 60 * 24)
|
75
|
+
const awardedTokens = supply * (Math.pow(Math.E, halfLife * timeInOffsetStart) - Math.pow(Math.E, halfLife * timeOutOffsetStart))
|
76
|
+
return awardedTokens
|
69
77
|
}
|
package/src/state/StakingPool.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
import { PublicKey } from '@solana/web3.js'
|
3
3
|
import Decimal from 'decimal.js'
|
4
|
-
import { DecimalFromU128 } from '
|
4
|
+
import { DecimalFromU128 } from '../HedgeDecimal'
|
5
5
|
|
6
6
|
export class StakingPool {
|
7
7
|
public publicKey: PublicKey
|
@@ -14,10 +14,9 @@ export class StakingPool {
|
|
14
14
|
hedgeRewardAccumulator: Decimal
|
15
15
|
usdhFeeAccumulator: Decimal
|
16
16
|
solFeeAccumulator: Decimal
|
17
|
-
currentRewardsPerDay: Decimal
|
18
17
|
|
19
|
-
constructor (public poolInfo: any,
|
20
|
-
this.publicKey =
|
18
|
+
constructor (public poolInfo: any, publicKey: PublicKey) {
|
19
|
+
this.publicKey = publicKey
|
21
20
|
this.deposits = poolInfo.deposits.toNumber()
|
22
21
|
// this.totalFeesNow = poolInfo.totalFeesNow.toNumber()
|
23
22
|
// this.totalFeesPrevious = poolInfo.totalFeesPrevious.toNumber()
|
@@ -29,7 +28,7 @@ export class StakingPool {
|
|
29
28
|
this.hedgeRewardAccumulator = DecimalFromU128(poolInfo.hedgeRewardAccumulator)
|
30
29
|
this.usdhFeeAccumulator = DecimalFromU128(poolInfo.usdhFeeAccumulator)
|
31
30
|
this.solFeeAccumulator = DecimalFromU128(poolInfo.solFeeAccumulator)
|
32
|
-
this.currentRewardsPerDay = DecimalFromU128(poolInfo.currentRewardsPerDay)
|
31
|
+
// this.currentRewardsPerDay = DecimalFromU128(poolInfo.currentRewardsPerDay)
|
33
32
|
}
|
34
33
|
|
35
34
|
// updateFeeAccumulator () {
|
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
import { PublicKey } from '@solana/web3.js'
|
3
3
|
import Decimal from 'decimal.js'
|
4
|
-
import { DecimalFromU128 } from '
|
4
|
+
import { DecimalFromU128 } from '../HedgeDecimal'
|
5
5
|
import { StakingPool } from './StakingPool'
|
6
6
|
|
7
7
|
export class StakingPoolPosition {
|
@@ -33,8 +33,7 @@ export class StakingPoolPosition {
|
|
33
33
|
this.open = poolPositionInfo.state.open !== undefined
|
34
34
|
}
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
// }
|
36
|
+
public getCurrentUsdhFeeReward (): Decimal {
|
37
|
+
return this.pool.usdhFeeAccumulator.minus(this.startUsdhFeeAccumulator).times(new Decimal(this.deposited))
|
38
|
+
}
|
40
39
|
}
|
@@ -34,7 +34,6 @@ export class VaultAccount {
|
|
34
34
|
this.deposited = vault.deposited.toNumber()
|
35
35
|
this.minCollateralRatio = DecimalFromU128(vault.minCollateralRatio)
|
36
36
|
this.liquidationPrice = vault.liquidationPrice.toNumber()
|
37
|
-
this.minCollateralRatio = vault.minCollateralRatio.toNumber()
|
38
37
|
this.vaultStatus = Object.keys(vault.vaultStatus)[0]
|
39
38
|
}
|
40
39
|
|
@@ -0,0 +1,88 @@
|
|
1
|
+
|
2
|
+
declare module 'buffer-layout' {
|
3
|
+
// TODO: remove `any`.
|
4
|
+
export class Layout<T = any> {
|
5
|
+
span: number
|
6
|
+
property?: string
|
7
|
+
|
8
|
+
constructor (span: number, property?: string);
|
9
|
+
|
10
|
+
decode (b: Buffer | string, offset?: number): T;
|
11
|
+
encode (src: T, b: Buffer, offset?: number): number;
|
12
|
+
getSpan (b: Buffer, offset?: number): number;
|
13
|
+
replicate (name: string): this;
|
14
|
+
}
|
15
|
+
// TODO: remove any.
|
16
|
+
export class Structure<T = any> extends Layout<T> {
|
17
|
+
span: any
|
18
|
+
}
|
19
|
+
export function greedy (
|
20
|
+
elementSpan?: number,
|
21
|
+
property?: string,
|
22
|
+
): Layout<number>
|
23
|
+
export function offset<T> (
|
24
|
+
layout: Layout<T>,
|
25
|
+
offset?: number,
|
26
|
+
property?: string,
|
27
|
+
): Layout<T>
|
28
|
+
export function u8 (property?: string): Layout<number>
|
29
|
+
export function u16 (property?: string): Layout<number>
|
30
|
+
export function u24 (property?: string): Layout<number>
|
31
|
+
export function u32 (property?: string): Layout<number>
|
32
|
+
export function u40 (property?: string): Layout<number>
|
33
|
+
export function u48 (property?: string): Layout<number>
|
34
|
+
export function nu64 (property?: string): Layout<number>
|
35
|
+
export function u16be (property?: string): Layout<number>
|
36
|
+
export function u24be (property?: string): Layout<number>
|
37
|
+
export function u32be (property?: string): Layout<number>
|
38
|
+
export function u40be (property?: string): Layout<number>
|
39
|
+
export function u48be (property?: string): Layout<number>
|
40
|
+
export function nu64be (property?: string): Layout<number>
|
41
|
+
export function s8 (property?: string): Layout<number>
|
42
|
+
export function s16 (property?: string): Layout<number>
|
43
|
+
export function s24 (property?: string): Layout<number>
|
44
|
+
export function s32 (property?: string): Layout<number>
|
45
|
+
export function s40 (property?: string): Layout<number>
|
46
|
+
export function s48 (property?: string): Layout<number>
|
47
|
+
export function ns64 (property?: string): Layout<number>
|
48
|
+
export function s16be (property?: string): Layout<number>
|
49
|
+
export function s24be (property?: string): Layout<number>
|
50
|
+
export function s32be (property?: string): Layout<number>
|
51
|
+
export function s40be (property?: string): Layout<number>
|
52
|
+
export function s48be (property?: string): Layout<number>
|
53
|
+
export function ns64be (property?: string): Layout<number>
|
54
|
+
export function f32 (property?: string): Layout<number>
|
55
|
+
export function f32be (property?: string): Layout<number>
|
56
|
+
export function f64 (property?: string): Layout<number>
|
57
|
+
export function f64be (property?: string): Layout<number>
|
58
|
+
export function struct<T> (
|
59
|
+
fields: Array<Layout<any>>,
|
60
|
+
property?: string,
|
61
|
+
decodePrefixes?: boolean,
|
62
|
+
): Layout<T>
|
63
|
+
export function bits (
|
64
|
+
word: Layout<number>,
|
65
|
+
msb?: boolean,
|
66
|
+
property?: string,
|
67
|
+
): any
|
68
|
+
export function seq<T> (
|
69
|
+
elementLayout: Layout<T>,
|
70
|
+
count: number | Layout<number>,
|
71
|
+
property?: string,
|
72
|
+
): Layout<T[]>
|
73
|
+
export function union (
|
74
|
+
discr: Layout<any>,
|
75
|
+
defaultLayout?: any,
|
76
|
+
property?: string,
|
77
|
+
): any
|
78
|
+
export function unionLayoutDiscriminator (
|
79
|
+
layout: Layout<any>,
|
80
|
+
property?: string,
|
81
|
+
): any
|
82
|
+
export function blob (
|
83
|
+
length: number | Layout<number>,
|
84
|
+
property?: string,
|
85
|
+
): Layout<Buffer>
|
86
|
+
export function cstr (property?: string): Layout<string>
|
87
|
+
export function utf8 (maxSpan: number, property?: string): Layout<string>
|
88
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { parseIdlErrors, ProgramError } from '@project-serum/anchor'
|
2
|
+
import { vaultIdl } from '../idl/idl'
|
3
|
+
|
4
|
+
export function parseAnchorErrors (error: any): void {
|
5
|
+
const idlErrors = parseIdlErrors(vaultIdl)
|
6
|
+
const parsedError = ProgramError.parse(error, idlErrors)
|
7
|
+
if (parsedError !== null) {
|
8
|
+
throw parsedError
|
9
|
+
}
|
10
|
+
throw error
|
11
|
+
}
|