hedge-web3 0.2.20 → 0.2.21
Sign up to get free protection for your applications and to get access to all the features.
- package/declarations/idl/vault.d.ts +6 -20
- package/declarations/instructions/updateVaultType.d.ts +1 -0
- package/declarations/state/VaultAccount.d.ts +2 -1
- package/lib/idl/vault.js +6 -20
- package/lib/instructions/updateVaultType.js +10 -9
- package/lib/state/VaultAccount.js +1 -3
- package/package.json +1 -1
- package/src/idl/vault.ts +12 -40
- package/src/instructions/updateVaultType.ts +3 -0
- package/src/state/VaultAccount.ts +10 -9
- package/src/instructions/transferVault.ts +0 -99
@@ -2798,6 +2798,12 @@ export declare type Vault = {
|
|
2798
2798
|
"option": "u64";
|
2799
2799
|
};
|
2800
2800
|
},
|
2801
|
+
{
|
2802
|
+
"name": "interestRatePerSecond";
|
2803
|
+
"type": {
|
2804
|
+
"option": "u128";
|
2805
|
+
};
|
2806
|
+
},
|
2801
2807
|
{
|
2802
2808
|
"name": "emergencyModeThreshold";
|
2803
2809
|
"type": {
|
@@ -3076,26 +3082,6 @@ export declare type Vault = {
|
|
3076
3082
|
"index": false;
|
3077
3083
|
}
|
3078
3084
|
];
|
3079
|
-
},
|
3080
|
-
{
|
3081
|
-
"name": "VaultTransferEvent";
|
3082
|
-
"fields": [
|
3083
|
-
{
|
3084
|
-
"name": "vault";
|
3085
|
-
"type": "publicKey";
|
3086
|
-
"index": false;
|
3087
|
-
},
|
3088
|
-
{
|
3089
|
-
"name": "oldOwner";
|
3090
|
-
"type": "publicKey";
|
3091
|
-
"index": false;
|
3092
|
-
},
|
3093
|
-
{
|
3094
|
-
"name": "newOwner";
|
3095
|
-
"type": "publicKey";
|
3096
|
-
"index": false;
|
3097
|
-
}
|
3098
|
-
];
|
3099
3085
|
}
|
3100
3086
|
];
|
3101
3087
|
"errors": [
|
@@ -11,7 +11,8 @@ export declare class VaultAccount {
|
|
11
11
|
publicKey: PublicKey;
|
12
12
|
/** The public key of the vault owner. */
|
13
13
|
vaultOwner: PublicKey;
|
14
|
-
/** The public key of the vault owner. */
|
14
|
+
/** The public key of the vault owner. */
|
15
|
+
pdaSalt: string;
|
15
16
|
/** The deposited collateral of the vault (in SOL Lamports). */
|
16
17
|
deposited: BN;
|
17
18
|
/** The outstanding debt of the vault (in USH Lamports). Denormalized to time 0. */
|
package/lib/idl/vault.js
CHANGED
@@ -2801,6 +2801,12 @@ exports.IDL = {
|
|
2801
2801
|
"option": "u64"
|
2802
2802
|
}
|
2803
2803
|
},
|
2804
|
+
{
|
2805
|
+
"name": "interestRatePerSecond",
|
2806
|
+
"type": {
|
2807
|
+
"option": "u128"
|
2808
|
+
}
|
2809
|
+
},
|
2804
2810
|
{
|
2805
2811
|
"name": "emergencyModeThreshold",
|
2806
2812
|
"type": {
|
@@ -3079,26 +3085,6 @@ exports.IDL = {
|
|
3079
3085
|
"index": false
|
3080
3086
|
}
|
3081
3087
|
]
|
3082
|
-
},
|
3083
|
-
{
|
3084
|
-
"name": "VaultTransferEvent",
|
3085
|
-
"fields": [
|
3086
|
-
{
|
3087
|
-
"name": "vault",
|
3088
|
-
"type": "publicKey",
|
3089
|
-
"index": false
|
3090
|
-
},
|
3091
|
-
{
|
3092
|
-
"name": "oldOwner",
|
3093
|
-
"type": "publicKey",
|
3094
|
-
"index": false
|
3095
|
-
},
|
3096
|
-
{
|
3097
|
-
"name": "newOwner",
|
3098
|
-
"type": "publicKey",
|
3099
|
-
"index": false
|
3100
|
-
}
|
3101
|
-
]
|
3102
3088
|
}
|
3103
3089
|
],
|
3104
3090
|
"errors": [
|
@@ -26,20 +26,21 @@ function updateVaultType(program, provider, payer, vaultTypeAccount, oracleInfoA
|
|
26
26
|
}
|
27
27
|
exports.updateVaultType = updateVaultType;
|
28
28
|
function updateVaultTypeStatusInstruction(program, vaultSystemStatePublicKey, payerPublicKey, vaultTypeAccount, oracleInfoAccount, vaultTypeConfig) {
|
29
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
29
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
30
30
|
return __awaiter(this, void 0, void 0, function* () {
|
31
31
|
const config = {
|
32
32
|
maxDebtExtended: (_a = vaultTypeConfig.maxDebtExtended) !== null && _a !== void 0 ? _a : null,
|
33
33
|
minDebtPerVault: (_b = vaultTypeConfig.minDebtPerVault) !== null && _b !== void 0 ? _b : null,
|
34
34
|
loanInitFee: (_c = vaultTypeConfig.loanInitFee) !== null && _c !== void 0 ? _c : null,
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
35
|
+
interestRatePerSecond: (_d = vaultTypeConfig.interestRatePerSecond) !== null && _d !== void 0 ? _d : null,
|
36
|
+
emergencyModeThreshold: (_e = vaultTypeConfig.emergencyModeThreshold) !== null && _e !== void 0 ? _e : null,
|
37
|
+
oracleChainlink: (_f = vaultTypeConfig.oracleChainlink) !== null && _f !== void 0 ? _f : null,
|
38
|
+
oraclePyth: (_g = vaultTypeConfig.oraclePyth) !== null && _g !== void 0 ? _g : null,
|
39
|
+
oracleSwitchboard: (_h = vaultTypeConfig.oracleSwitchboard) !== null && _h !== void 0 ? _h : null,
|
40
|
+
deprecated: (_j = vaultTypeConfig.deprecated) !== null && _j !== void 0 ? _j : null,
|
41
|
+
priorityPyth: (_k = vaultTypeConfig.priorityPyth) !== null && _k !== void 0 ? _k : null,
|
42
|
+
priorityChainlink: (_l = vaultTypeConfig.priorityChainlink) !== null && _l !== void 0 ? _l : null,
|
43
|
+
prioritySwitchboard: (_m = vaultTypeConfig.prioritySwitchboard) !== null && _m !== void 0 ? _m : null,
|
43
44
|
};
|
44
45
|
return yield program.methods
|
45
46
|
.updateVaultType(config)
|
@@ -163,9 +163,7 @@ class VaultAccount {
|
|
163
163
|
.mul(new decimal_js_1.default(this.denormalizedDebt.toString()))
|
164
164
|
.floor()
|
165
165
|
.toString());
|
166
|
-
const extraCollateralDeposited = new decimal_js_1.default(this.denormalizedDebt.toString())
|
167
|
-
.mul(vaultTypeAccountData.collateralRedistributionAccumulator.sub(this.collateralAccumulatorSnapshotBytes).toNumber())
|
168
|
-
.floor();
|
166
|
+
const extraCollateralDeposited = new decimal_js_1.default(this.denormalizedDebt.toString()).mul(vaultTypeAccountData.collateralRedistributionAccumulator.sub(this.collateralAccumulatorSnapshotBytes).toNumber()).floor();
|
169
167
|
this.deposited = this.deposited.add(new bn_js_1.default(extraCollateralDeposited.toString()));
|
170
168
|
this.collateralAccumulatorSnapshotBytes = vaultTypeAccountData.collateralRedistributionAccumulator;
|
171
169
|
this.debtProductSnapshotBytes = vaultTypeAccountData.debtRedistributionProduct;
|
package/package.json
CHANGED
package/src/idl/vault.ts
CHANGED
@@ -2798,6 +2798,12 @@ export type Vault = {
|
|
2798
2798
|
"option": "u64"
|
2799
2799
|
}
|
2800
2800
|
},
|
2801
|
+
{
|
2802
|
+
"name": "interestRatePerSecond",
|
2803
|
+
"type": {
|
2804
|
+
"option": "u128"
|
2805
|
+
}
|
2806
|
+
},
|
2801
2807
|
{
|
2802
2808
|
"name": "emergencyModeThreshold",
|
2803
2809
|
"type": {
|
@@ -3076,26 +3082,6 @@ export type Vault = {
|
|
3076
3082
|
"index": false
|
3077
3083
|
}
|
3078
3084
|
]
|
3079
|
-
},
|
3080
|
-
{
|
3081
|
-
"name": "VaultTransferEvent",
|
3082
|
-
"fields": [
|
3083
|
-
{
|
3084
|
-
"name": "vault",
|
3085
|
-
"type": "publicKey",
|
3086
|
-
"index": false
|
3087
|
-
},
|
3088
|
-
{
|
3089
|
-
"name": "oldOwner",
|
3090
|
-
"type": "publicKey",
|
3091
|
-
"index": false
|
3092
|
-
},
|
3093
|
-
{
|
3094
|
-
"name": "newOwner",
|
3095
|
-
"type": "publicKey",
|
3096
|
-
"index": false
|
3097
|
-
}
|
3098
|
-
]
|
3099
3085
|
}
|
3100
3086
|
],
|
3101
3087
|
"errors": [
|
@@ -6077,6 +6063,12 @@ export const IDL: Vault = {
|
|
6077
6063
|
"option": "u64"
|
6078
6064
|
}
|
6079
6065
|
},
|
6066
|
+
{
|
6067
|
+
"name": "interestRatePerSecond",
|
6068
|
+
"type": {
|
6069
|
+
"option": "u128"
|
6070
|
+
}
|
6071
|
+
},
|
6080
6072
|
{
|
6081
6073
|
"name": "emergencyModeThreshold",
|
6082
6074
|
"type": {
|
@@ -6355,26 +6347,6 @@ export const IDL: Vault = {
|
|
6355
6347
|
"index": false
|
6356
6348
|
}
|
6357
6349
|
]
|
6358
|
-
},
|
6359
|
-
{
|
6360
|
-
"name": "VaultTransferEvent",
|
6361
|
-
"fields": [
|
6362
|
-
{
|
6363
|
-
"name": "vault",
|
6364
|
-
"type": "publicKey",
|
6365
|
-
"index": false
|
6366
|
-
},
|
6367
|
-
{
|
6368
|
-
"name": "oldOwner",
|
6369
|
-
"type": "publicKey",
|
6370
|
-
"index": false
|
6371
|
-
},
|
6372
|
-
{
|
6373
|
-
"name": "newOwner",
|
6374
|
-
"type": "publicKey",
|
6375
|
-
"index": false
|
6376
|
-
}
|
6377
|
-
]
|
6378
6350
|
}
|
6379
6351
|
],
|
6380
6352
|
"errors": [
|
@@ -28,6 +28,8 @@ export interface VaultTypeConfig {
|
|
28
28
|
maxDebtExtended?: BN
|
29
29
|
minDebtPerVault?: BN
|
30
30
|
loanInitFee?: BN
|
31
|
+
interestRatePerSecond?: BN
|
32
|
+
|
31
33
|
emergencyModeThreshold?: BN
|
32
34
|
|
33
35
|
oracleChainlink?: PublicKey
|
@@ -77,6 +79,7 @@ export async function updateVaultTypeStatusInstruction(
|
|
77
79
|
maxDebtExtended: vaultTypeConfig.maxDebtExtended ?? null,
|
78
80
|
minDebtPerVault: vaultTypeConfig.minDebtPerVault ?? null,
|
79
81
|
loanInitFee: vaultTypeConfig.loanInitFee ?? null,
|
82
|
+
interestRatePerSecond: vaultTypeConfig.interestRatePerSecond ?? null,
|
80
83
|
emergencyModeThreshold: vaultTypeConfig.emergencyModeThreshold ?? null,
|
81
84
|
oracleChainlink: vaultTypeConfig.oracleChainlink ?? null,
|
82
85
|
oraclePyth: vaultTypeConfig.oraclePyth ?? null,
|
@@ -16,7 +16,7 @@ export class VaultAccount {
|
|
16
16
|
/** The public key of the vault owner. */
|
17
17
|
vaultOwner: PublicKey
|
18
18
|
|
19
|
-
/** The public key of the vault owner. */
|
19
|
+
/** The public key of the vault owner. */
|
20
20
|
pdaSalt: string
|
21
21
|
|
22
22
|
/** The deposited collateral of the vault (in SOL Lamports). */
|
@@ -50,7 +50,7 @@ export class VaultAccount {
|
|
50
50
|
this.publicKey = publicKey
|
51
51
|
this.vaultOwner = vault.vaultOwner
|
52
52
|
this.pdaSalt = vault.pdaSalt
|
53
|
-
|
53
|
+
|
54
54
|
this.deposited = vault.deposited
|
55
55
|
this.denormalizedDebt = vault.denormalizedDebt
|
56
56
|
|
@@ -177,15 +177,16 @@ export class VaultAccount {
|
|
177
177
|
public updateDebtAndCollateral(vaultTypeAccountData: VaultType) {
|
178
178
|
this.denormalizedDebt = new BN(
|
179
179
|
vaultTypeAccountData.debtRedistributionProduct
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
180
|
+
.div(this.debtProductSnapshotBytes)
|
181
|
+
.mul(new Decimal(this.denormalizedDebt.toString()))
|
182
|
+
.floor()
|
183
|
+
.toString()
|
184
184
|
)
|
185
185
|
|
186
|
-
const extraCollateralDeposited =
|
187
|
-
|
188
|
-
|
186
|
+
const extraCollateralDeposited =
|
187
|
+
new Decimal(this.denormalizedDebt.toString()).mul(
|
188
|
+
vaultTypeAccountData.collateralRedistributionAccumulator.sub(this.collateralAccumulatorSnapshotBytes).toNumber()
|
189
|
+
).floor()
|
189
190
|
this.deposited = this.deposited.add(new BN(extraCollateralDeposited.toString()))
|
190
191
|
|
191
192
|
this.collateralAccumulatorSnapshotBytes = vaultTypeAccountData.collateralRedistributionAccumulator
|
@@ -1,99 +0,0 @@
|
|
1
|
-
import { BN, Program, Provider } from '@project-serum/anchor'
|
2
|
-
import {
|
3
|
-
Keypair,
|
4
|
-
PublicKey,
|
5
|
-
sendAndConfirmTransaction,
|
6
|
-
Signer,
|
7
|
-
SystemProgram,
|
8
|
-
SYSVAR_RENT_PUBKEY,
|
9
|
-
Transaction,
|
10
|
-
TransactionInstruction,
|
11
|
-
} from '@solana/web3.js'
|
12
|
-
import {
|
13
|
-
findAssociatedTokenAddress,
|
14
|
-
findVaultAddress,
|
15
|
-
getVaultTypeAccountPublicKey,
|
16
|
-
getUshMintPublicKey,
|
17
|
-
getVaultSystemStatePublicKey,
|
18
|
-
getPoolPublicKeyForMint,
|
19
|
-
getHedgeMintPublicKey,
|
20
|
-
} from '../Constants'
|
21
|
-
|
22
|
-
import { v4 as uuidv4 } from 'uuid'
|
23
|
-
import { parseAnchorErrors } from '../utils/Errors'
|
24
|
-
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
25
|
-
import { Vault } from '../idl/vault'
|
26
|
-
|
27
|
-
export interface VaultTypeConfig {
|
28
|
-
maxDebtExtended?: BN
|
29
|
-
minDebtPerVault?: BN
|
30
|
-
loanInitFee?: BN
|
31
|
-
emergencyModeThreshold?: BN
|
32
|
-
|
33
|
-
oracleChainlink?: PublicKey
|
34
|
-
oraclePyth?: PublicKey
|
35
|
-
oracleSwitchboard?: PublicKey
|
36
|
-
|
37
|
-
priorityPyth?: number
|
38
|
-
priorityChainlink?: number
|
39
|
-
prioritySwitchboard?: number
|
40
|
-
|
41
|
-
deprecated?: boolean
|
42
|
-
}
|
43
|
-
|
44
|
-
export async function transferVault(
|
45
|
-
program: Program<Vault>,
|
46
|
-
provider: Provider,
|
47
|
-
payer: Signer,
|
48
|
-
vaultTypeAccount: PublicKey,
|
49
|
-
oracleInfoAccount: PublicKey,
|
50
|
-
config: VaultTypeConfig
|
51
|
-
): Promise<PublicKey> {
|
52
|
-
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
53
|
-
const transaction = new Transaction().add(
|
54
|
-
await transferVaultInstruction(
|
55
|
-
program,
|
56
|
-
vaultSystemStatePublicKey,
|
57
|
-
payer.publicKey,
|
58
|
-
vaultTypeAccount,
|
59
|
-
oracleInfoAccount,
|
60
|
-
config
|
61
|
-
)
|
62
|
-
)
|
63
|
-
|
64
|
-
await sendAndConfirmWithDebug(provider.connection, transaction, [payer])
|
65
|
-
return vaultSystemStatePublicKey
|
66
|
-
}
|
67
|
-
|
68
|
-
export async function transferVaultInstruction(
|
69
|
-
program: Program<Vault>,
|
70
|
-
vaultSystemStatePublicKey: PublicKey,
|
71
|
-
payerPublicKey: PublicKey,
|
72
|
-
vaultTypeAccount: PublicKey,
|
73
|
-
oracleInfoAccount: PublicKey,
|
74
|
-
vaultTypeConfig: VaultTypeConfig
|
75
|
-
): Promise<TransactionInstruction> {
|
76
|
-
const config = {
|
77
|
-
maxDebtExtended: vaultTypeConfig.maxDebtExtended ?? null,
|
78
|
-
minDebtPerVault: vaultTypeConfig.minDebtPerVault ?? null,
|
79
|
-
loanInitFee: vaultTypeConfig.loanInitFee ?? null,
|
80
|
-
emergencyModeThreshold: vaultTypeConfig.emergencyModeThreshold ?? null,
|
81
|
-
oracleChainlink: vaultTypeConfig.oracleChainlink ?? null,
|
82
|
-
oraclePyth: vaultTypeConfig.oraclePyth ?? null,
|
83
|
-
oracleSwitchboard: vaultTypeConfig.oracleSwitchboard ?? null,
|
84
|
-
deprecated: vaultTypeConfig.deprecated ?? null,
|
85
|
-
priorityPyth: vaultTypeConfig.priorityPyth ?? null,
|
86
|
-
priorityChainlink: vaultTypeConfig.priorityChainlink ?? null,
|
87
|
-
prioritySwitchboard: vaultTypeConfig.prioritySwitchboard ?? null,
|
88
|
-
}
|
89
|
-
|
90
|
-
return await program.methods
|
91
|
-
.updateVaultType(config)
|
92
|
-
.accounts({
|
93
|
-
payer: payerPublicKey,
|
94
|
-
vaultSystemState: vaultSystemStatePublicKey,
|
95
|
-
vaultType: vaultTypeAccount,
|
96
|
-
oracleInfoAccount: oracleInfoAccount,
|
97
|
-
})
|
98
|
-
.instruction()
|
99
|
-
}
|