hedge-web3 0.2.17 → 0.2.20

Sign up to get free protection for your applications and to get access to all the features.
@@ -76,6 +76,10 @@ export declare type Vault = {
76
76
  "name": "maxDebtExtended";
77
77
  "type": "u64";
78
78
  },
79
+ {
80
+ "name": "emergencyModeThreshold";
81
+ "type": "u64";
82
+ },
79
83
  {
80
84
  "name": "canBeRedeemed";
81
85
  "type": "bool";
@@ -1802,8 +1806,56 @@ export declare type Vault = {
1802
1806
  "type": "u64";
1803
1807
  },
1804
1808
  {
1805
- "name": "collateralDecimals";
1806
- "type": "u8";
1809
+ "name": "overrideCurrentTime";
1810
+ "type": "i64";
1811
+ }
1812
+ ];
1813
+ },
1814
+ {
1815
+ "name": "psmEditAccount";
1816
+ "accounts": [
1817
+ {
1818
+ "name": "payer";
1819
+ "isMut": true;
1820
+ "isSigner": true;
1821
+ },
1822
+ {
1823
+ "name": "vaultSystemState";
1824
+ "isMut": true;
1825
+ "isSigner": false;
1826
+ },
1827
+ {
1828
+ "name": "psmAccount";
1829
+ "isMut": true;
1830
+ "isSigner": false;
1831
+ },
1832
+ {
1833
+ "name": "collateralMint";
1834
+ "isMut": false;
1835
+ "isSigner": false;
1836
+ },
1837
+ {
1838
+ "name": "systemProgram";
1839
+ "isMut": false;
1840
+ "isSigner": false;
1841
+ }
1842
+ ];
1843
+ "args": [
1844
+ {
1845
+ "name": "mintFee";
1846
+ "type": "u64";
1847
+ },
1848
+ {
1849
+ "name": "redeemFee";
1850
+ "type": "u64";
1851
+ },
1852
+ {
1853
+ "name": "debtLimit";
1854
+ "type": "u64";
1855
+ },
1856
+ {
1857
+ "name": "minSwap";
1858
+ "type": "u64";
1807
1859
  },
1808
1860
  {
1809
1861
  "name": "overrideCurrentTime";
@@ -2746,6 +2798,12 @@ export declare type Vault = {
2746
2798
  "option": "u64";
2747
2799
  };
2748
2800
  },
2801
+ {
2802
+ "name": "emergencyModeThreshold";
2803
+ "type": {
2804
+ "option": "u64";
2805
+ };
2806
+ },
2749
2807
  {
2750
2808
  "name": "oracleChainlink";
2751
2809
  "type": {
@@ -3018,6 +3076,26 @@ export declare type Vault = {
3018
3076
  "index": false;
3019
3077
  }
3020
3078
  ];
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
+ ];
3021
3099
  }
3022
3100
  ];
3023
3101
  "errors": [
@@ -3163,31 +3241,36 @@ export declare type Vault = {
3163
3241
  },
3164
3242
  {
3165
3243
  "code": 6028;
3166
- "name": "PsmError";
3167
- "msg": "PSM error.";
3244
+ "name": "PsmMaxDebtReached";
3245
+ "msg": "PSM - Max Debt reached";
3168
3246
  },
3169
3247
  {
3170
3248
  "code": 6029;
3249
+ "name": "PsmMinSwapAmount";
3250
+ "msg": "PSM - Need more to swap";
3251
+ },
3252
+ {
3253
+ "code": 6030;
3171
3254
  "name": "UpdateVaultTypeBadMaxDebtExtended";
3172
3255
  "msg": "New Max debt extended value is less than the current debt!";
3173
3256
  },
3174
3257
  {
3175
- "code": 6030;
3258
+ "code": 6031;
3176
3259
  "name": "UpdateVaultTypeNoEnabledOracles";
3177
3260
  "msg": "No Enabled Oracles!";
3178
3261
  },
3179
3262
  {
3180
- "code": 6031;
3263
+ "code": 6032;
3181
3264
  "name": "UpdateVaultTypeDuplicateOraclePriorities";
3182
3265
  "msg": "Duplicate Oracle Priorities";
3183
3266
  },
3184
3267
  {
3185
- "code": 6032;
3268
+ "code": 6033;
3186
3269
  "name": "UpdateVaultTypeInvalidOraclePriority";
3187
3270
  "msg": "Invalid Oracle Priority";
3188
3271
  },
3189
3272
  {
3190
- "code": 6033;
3273
+ "code": 6034;
3191
3274
  "name": "OracleUpdateFailed";
3192
3275
  "msg": "OracleUpdateFailed";
3193
3276
  }
@@ -0,0 +1,19 @@
1
+ /// <reference types="bn.js" />
2
+ import { BN, Program, Provider } from '@project-serum/anchor';
3
+ import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
4
+ import { Vault } from '../idl/vault';
5
+ export interface VaultTypeConfig {
6
+ maxDebtExtended?: BN;
7
+ minDebtPerVault?: BN;
8
+ loanInitFee?: BN;
9
+ emergencyModeThreshold?: BN;
10
+ oracleChainlink?: PublicKey;
11
+ oraclePyth?: PublicKey;
12
+ oracleSwitchboard?: PublicKey;
13
+ priorityPyth?: number;
14
+ priorityChainlink?: number;
15
+ prioritySwitchboard?: number;
16
+ deprecated?: boolean;
17
+ }
18
+ export declare function transferVault(program: Program<Vault>, provider: Provider, payer: Signer, vaultTypeAccount: PublicKey, oracleInfoAccount: PublicKey, config: VaultTypeConfig): Promise<PublicKey>;
19
+ export declare function transferVaultInstruction(program: Program<Vault>, vaultSystemStatePublicKey: PublicKey, payerPublicKey: PublicKey, vaultTypeAccount: PublicKey, oracleInfoAccount: PublicKey, vaultTypeConfig: VaultTypeConfig): Promise<TransactionInstruction>;
@@ -6,6 +6,7 @@ export interface VaultTypeConfig {
6
6
  maxDebtExtended?: BN;
7
7
  minDebtPerVault?: BN;
8
8
  loanInitFee?: BN;
9
+ emergencyModeThreshold?: BN;
9
10
  oracleChainlink?: PublicKey;
10
11
  oraclePyth?: PublicKey;
11
12
  oracleSwitchboard?: PublicKey;
@@ -11,8 +11,7 @@ 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. */
15
- pdaSalt: string;
14
+ /** The public key of the vault owner. */ pdaSalt: string;
16
15
  /** The deposited collateral of the vault (in SOL Lamports). */
17
16
  deposited: BN;
18
17
  /** The outstanding debt of the vault (in USH Lamports). Denormalized to time 0. */
package/lib/idl/vault.js CHANGED
@@ -79,6 +79,10 @@ exports.IDL = {
79
79
  "name": "maxDebtExtended",
80
80
  "type": "u64"
81
81
  },
82
+ {
83
+ "name": "emergencyModeThreshold",
84
+ "type": "u64"
85
+ },
82
86
  {
83
87
  "name": "canBeRedeemed",
84
88
  "type": "bool"
@@ -1805,8 +1809,56 @@ exports.IDL = {
1805
1809
  "type": "u64"
1806
1810
  },
1807
1811
  {
1808
- "name": "collateralDecimals",
1809
- "type": "u8"
1812
+ "name": "overrideCurrentTime",
1813
+ "type": "i64"
1814
+ }
1815
+ ]
1816
+ },
1817
+ {
1818
+ "name": "psmEditAccount",
1819
+ "accounts": [
1820
+ {
1821
+ "name": "payer",
1822
+ "isMut": true,
1823
+ "isSigner": true
1824
+ },
1825
+ {
1826
+ "name": "vaultSystemState",
1827
+ "isMut": true,
1828
+ "isSigner": false
1829
+ },
1830
+ {
1831
+ "name": "psmAccount",
1832
+ "isMut": true,
1833
+ "isSigner": false
1834
+ },
1835
+ {
1836
+ "name": "collateralMint",
1837
+ "isMut": false,
1838
+ "isSigner": false
1839
+ },
1840
+ {
1841
+ "name": "systemProgram",
1842
+ "isMut": false,
1843
+ "isSigner": false
1844
+ }
1845
+ ],
1846
+ "args": [
1847
+ {
1848
+ "name": "mintFee",
1849
+ "type": "u64"
1850
+ },
1851
+ {
1852
+ "name": "redeemFee",
1853
+ "type": "u64"
1854
+ },
1855
+ {
1856
+ "name": "debtLimit",
1857
+ "type": "u64"
1858
+ },
1859
+ {
1860
+ "name": "minSwap",
1861
+ "type": "u64"
1810
1862
  },
1811
1863
  {
1812
1864
  "name": "overrideCurrentTime",
@@ -2749,6 +2801,12 @@ exports.IDL = {
2749
2801
  "option": "u64"
2750
2802
  }
2751
2803
  },
2804
+ {
2805
+ "name": "emergencyModeThreshold",
2806
+ "type": {
2807
+ "option": "u64"
2808
+ }
2809
+ },
2752
2810
  {
2753
2811
  "name": "oracleChainlink",
2754
2812
  "type": {
@@ -3021,6 +3079,26 @@ exports.IDL = {
3021
3079
  "index": false
3022
3080
  }
3023
3081
  ]
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
+ ]
3024
3102
  }
3025
3103
  ],
3026
3104
  "errors": [
@@ -3166,31 +3244,36 @@ exports.IDL = {
3166
3244
  },
3167
3245
  {
3168
3246
  "code": 6028,
3169
- "name": "PsmError",
3170
- "msg": "PSM error."
3247
+ "name": "PsmMaxDebtReached",
3248
+ "msg": "PSM - Max Debt reached"
3171
3249
  },
3172
3250
  {
3173
3251
  "code": 6029,
3252
+ "name": "PsmMinSwapAmount",
3253
+ "msg": "PSM - Need more to swap"
3254
+ },
3255
+ {
3256
+ "code": 6030,
3174
3257
  "name": "UpdateVaultTypeBadMaxDebtExtended",
3175
3258
  "msg": "New Max debt extended value is less than the current debt!"
3176
3259
  },
3177
3260
  {
3178
- "code": 6030,
3261
+ "code": 6031,
3179
3262
  "name": "UpdateVaultTypeNoEnabledOracles",
3180
3263
  "msg": "No Enabled Oracles!"
3181
3264
  },
3182
3265
  {
3183
- "code": 6031,
3266
+ "code": 6032,
3184
3267
  "name": "UpdateVaultTypeDuplicateOraclePriorities",
3185
3268
  "msg": "Duplicate Oracle Priorities"
3186
3269
  },
3187
3270
  {
3188
- "code": 6032,
3271
+ "code": 6033,
3189
3272
  "name": "UpdateVaultTypeInvalidOraclePriority",
3190
3273
  "msg": "Invalid Oracle Priority"
3191
3274
  },
3192
3275
  {
3193
- "code": 6033,
3276
+ "code": 6034,
3194
3277
  "name": "OracleUpdateFailed",
3195
3278
  "msg": "OracleUpdateFailed"
3196
3279
  }
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.transferVaultInstruction = exports.transferVault = void 0;
16
+ const web3_js_1 = require("@solana/web3.js");
17
+ const Constants_1 = require("../Constants");
18
+ const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
19
+ function transferVault(program, provider, payer, vaultTypeAccount, oracleInfoAccount, config) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
22
+ const transaction = new web3_js_1.Transaction().add(yield transferVaultInstruction(program, vaultSystemStatePublicKey, payer.publicKey, vaultTypeAccount, oracleInfoAccount, config));
23
+ yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer]);
24
+ return vaultSystemStatePublicKey;
25
+ });
26
+ }
27
+ exports.transferVault = transferVault;
28
+ function transferVaultInstruction(program, vaultSystemStatePublicKey, payerPublicKey, vaultTypeAccount, oracleInfoAccount, vaultTypeConfig) {
29
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ const config = {
32
+ maxDebtExtended: (_a = vaultTypeConfig.maxDebtExtended) !== null && _a !== void 0 ? _a : null,
33
+ minDebtPerVault: (_b = vaultTypeConfig.minDebtPerVault) !== null && _b !== void 0 ? _b : null,
34
+ loanInitFee: (_c = vaultTypeConfig.loanInitFee) !== null && _c !== void 0 ? _c : null,
35
+ emergencyModeThreshold: (_d = vaultTypeConfig.emergencyModeThreshold) !== null && _d !== void 0 ? _d : null,
36
+ oracleChainlink: (_e = vaultTypeConfig.oracleChainlink) !== null && _e !== void 0 ? _e : null,
37
+ oraclePyth: (_f = vaultTypeConfig.oraclePyth) !== null && _f !== void 0 ? _f : null,
38
+ oracleSwitchboard: (_g = vaultTypeConfig.oracleSwitchboard) !== null && _g !== void 0 ? _g : null,
39
+ deprecated: (_h = vaultTypeConfig.deprecated) !== null && _h !== void 0 ? _h : null,
40
+ priorityPyth: (_j = vaultTypeConfig.priorityPyth) !== null && _j !== void 0 ? _j : null,
41
+ priorityChainlink: (_k = vaultTypeConfig.priorityChainlink) !== null && _k !== void 0 ? _k : null,
42
+ prioritySwitchboard: (_l = vaultTypeConfig.prioritySwitchboard) !== null && _l !== void 0 ? _l : null,
43
+ };
44
+ return yield program.methods
45
+ .updateVaultType(config)
46
+ .accounts({
47
+ payer: payerPublicKey,
48
+ vaultSystemState: vaultSystemStatePublicKey,
49
+ vaultType: vaultTypeAccount,
50
+ oracleInfoAccount: oracleInfoAccount,
51
+ })
52
+ .instruction();
53
+ });
54
+ }
55
+ exports.transferVaultInstruction = transferVaultInstruction;
@@ -26,19 +26,20 @@ 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;
29
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
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
- oracleChainlink: (_d = vaultTypeConfig.oracleChainlink) !== null && _d !== void 0 ? _d : null,
36
- oraclePyth: (_e = vaultTypeConfig.oraclePyth) !== null && _e !== void 0 ? _e : null,
37
- oracleSwitchboard: (_f = vaultTypeConfig.oracleSwitchboard) !== null && _f !== void 0 ? _f : null,
38
- deprecated: (_g = vaultTypeConfig.deprecated) !== null && _g !== void 0 ? _g : null,
39
- priorityPyth: (_h = vaultTypeConfig.priorityPyth) !== null && _h !== void 0 ? _h : null,
40
- priorityChainlink: (_j = vaultTypeConfig.priorityChainlink) !== null && _j !== void 0 ? _j : null,
41
- prioritySwitchboard: (_k = vaultTypeConfig.prioritySwitchboard) !== null && _k !== void 0 ? _k : null,
35
+ emergencyModeThreshold: (_d = vaultTypeConfig.emergencyModeThreshold) !== null && _d !== void 0 ? _d : null,
36
+ oracleChainlink: (_e = vaultTypeConfig.oracleChainlink) !== null && _e !== void 0 ? _e : null,
37
+ oraclePyth: (_f = vaultTypeConfig.oraclePyth) !== null && _f !== void 0 ? _f : null,
38
+ oracleSwitchboard: (_g = vaultTypeConfig.oracleSwitchboard) !== null && _g !== void 0 ? _g : null,
39
+ deprecated: (_h = vaultTypeConfig.deprecated) !== null && _h !== void 0 ? _h : null,
40
+ priorityPyth: (_j = vaultTypeConfig.priorityPyth) !== null && _j !== void 0 ? _j : null,
41
+ priorityChainlink: (_k = vaultTypeConfig.priorityChainlink) !== null && _k !== void 0 ? _k : null,
42
+ prioritySwitchboard: (_l = vaultTypeConfig.prioritySwitchboard) !== null && _l !== void 0 ? _l : null,
42
43
  };
43
44
  return yield program.methods
44
45
  .updateVaultType(config)
@@ -163,7 +163,9 @@ 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()).mul(vaultTypeAccountData.collateralRedistributionAccumulator.sub(this.collateralAccumulatorSnapshotBytes).toNumber()).floor();
166
+ const extraCollateralDeposited = new decimal_js_1.default(this.denormalizedDebt.toString())
167
+ .mul(vaultTypeAccountData.collateralRedistributionAccumulator.sub(this.collateralAccumulatorSnapshotBytes).toNumber())
168
+ .floor();
167
169
  this.deposited = this.deposited.add(new bn_js_1.default(extraCollateralDeposited.toString()));
168
170
  this.collateralAccumulatorSnapshotBytes = vaultTypeAccountData.collateralRedistributionAccumulator;
169
171
  this.debtProductSnapshotBytes = vaultTypeAccountData.debtRedistributionProduct;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hedge-web3",
3
- "version": "0.2.17",
3
+ "version": "0.2.20",
4
4
  "description": "Hedge Javascript Web3 API",
5
5
  "main": "lib/index.js",
6
6
  "types": "declarations/index.d.ts",
package/src/idl/vault.ts CHANGED
@@ -76,6 +76,10 @@ export type Vault = {
76
76
  "name": "maxDebtExtended",
77
77
  "type": "u64"
78
78
  },
79
+ {
80
+ "name": "emergencyModeThreshold",
81
+ "type": "u64"
82
+ },
79
83
  {
80
84
  "name": "canBeRedeemed",
81
85
  "type": "bool"
@@ -1802,8 +1806,56 @@ export type Vault = {
1802
1806
  "type": "u64"
1803
1807
  },
1804
1808
  {
1805
- "name": "collateralDecimals",
1806
- "type": "u8"
1809
+ "name": "overrideCurrentTime",
1810
+ "type": "i64"
1811
+ }
1812
+ ]
1813
+ },
1814
+ {
1815
+ "name": "psmEditAccount",
1816
+ "accounts": [
1817
+ {
1818
+ "name": "payer",
1819
+ "isMut": true,
1820
+ "isSigner": true
1821
+ },
1822
+ {
1823
+ "name": "vaultSystemState",
1824
+ "isMut": true,
1825
+ "isSigner": false
1826
+ },
1827
+ {
1828
+ "name": "psmAccount",
1829
+ "isMut": true,
1830
+ "isSigner": false
1831
+ },
1832
+ {
1833
+ "name": "collateralMint",
1834
+ "isMut": false,
1835
+ "isSigner": false
1836
+ },
1837
+ {
1838
+ "name": "systemProgram",
1839
+ "isMut": false,
1840
+ "isSigner": false
1841
+ }
1842
+ ],
1843
+ "args": [
1844
+ {
1845
+ "name": "mintFee",
1846
+ "type": "u64"
1847
+ },
1848
+ {
1849
+ "name": "redeemFee",
1850
+ "type": "u64"
1851
+ },
1852
+ {
1853
+ "name": "debtLimit",
1854
+ "type": "u64"
1855
+ },
1856
+ {
1857
+ "name": "minSwap",
1858
+ "type": "u64"
1807
1859
  },
1808
1860
  {
1809
1861
  "name": "overrideCurrentTime",
@@ -2746,6 +2798,12 @@ export type Vault = {
2746
2798
  "option": "u64"
2747
2799
  }
2748
2800
  },
2801
+ {
2802
+ "name": "emergencyModeThreshold",
2803
+ "type": {
2804
+ "option": "u64"
2805
+ }
2806
+ },
2749
2807
  {
2750
2808
  "name": "oracleChainlink",
2751
2809
  "type": {
@@ -3018,6 +3076,26 @@ export type Vault = {
3018
3076
  "index": false
3019
3077
  }
3020
3078
  ]
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
+ ]
3021
3099
  }
3022
3100
  ],
3023
3101
  "errors": [
@@ -3163,31 +3241,36 @@ export type Vault = {
3163
3241
  },
3164
3242
  {
3165
3243
  "code": 6028,
3166
- "name": "PsmError",
3167
- "msg": "PSM error."
3244
+ "name": "PsmMaxDebtReached",
3245
+ "msg": "PSM - Max Debt reached"
3168
3246
  },
3169
3247
  {
3170
3248
  "code": 6029,
3249
+ "name": "PsmMinSwapAmount",
3250
+ "msg": "PSM - Need more to swap"
3251
+ },
3252
+ {
3253
+ "code": 6030,
3171
3254
  "name": "UpdateVaultTypeBadMaxDebtExtended",
3172
3255
  "msg": "New Max debt extended value is less than the current debt!"
3173
3256
  },
3174
3257
  {
3175
- "code": 6030,
3258
+ "code": 6031,
3176
3259
  "name": "UpdateVaultTypeNoEnabledOracles",
3177
3260
  "msg": "No Enabled Oracles!"
3178
3261
  },
3179
3262
  {
3180
- "code": 6031,
3263
+ "code": 6032,
3181
3264
  "name": "UpdateVaultTypeDuplicateOraclePriorities",
3182
3265
  "msg": "Duplicate Oracle Priorities"
3183
3266
  },
3184
3267
  {
3185
- "code": 6032,
3268
+ "code": 6033,
3186
3269
  "name": "UpdateVaultTypeInvalidOraclePriority",
3187
3270
  "msg": "Invalid Oracle Priority"
3188
3271
  },
3189
3272
  {
3190
- "code": 6033,
3273
+ "code": 6034,
3191
3274
  "name": "OracleUpdateFailed",
3192
3275
  "msg": "OracleUpdateFailed"
3193
3276
  }
@@ -3272,6 +3355,10 @@ export const IDL: Vault = {
3272
3355
  "name": "maxDebtExtended",
3273
3356
  "type": "u64"
3274
3357
  },
3358
+ {
3359
+ "name": "emergencyModeThreshold",
3360
+ "type": "u64"
3361
+ },
3275
3362
  {
3276
3363
  "name": "canBeRedeemed",
3277
3364
  "type": "bool"
@@ -4998,8 +5085,56 @@ export const IDL: Vault = {
4998
5085
  "type": "u64"
4999
5086
  },
5000
5087
  {
5001
- "name": "collateralDecimals",
5002
- "type": "u8"
5088
+ "name": "overrideCurrentTime",
5089
+ "type": "i64"
5090
+ }
5091
+ ]
5092
+ },
5093
+ {
5094
+ "name": "psmEditAccount",
5095
+ "accounts": [
5096
+ {
5097
+ "name": "payer",
5098
+ "isMut": true,
5099
+ "isSigner": true
5100
+ },
5101
+ {
5102
+ "name": "vaultSystemState",
5103
+ "isMut": true,
5104
+ "isSigner": false
5105
+ },
5106
+ {
5107
+ "name": "psmAccount",
5108
+ "isMut": true,
5109
+ "isSigner": false
5110
+ },
5111
+ {
5112
+ "name": "collateralMint",
5113
+ "isMut": false,
5114
+ "isSigner": false
5115
+ },
5116
+ {
5117
+ "name": "systemProgram",
5118
+ "isMut": false,
5119
+ "isSigner": false
5120
+ }
5121
+ ],
5122
+ "args": [
5123
+ {
5124
+ "name": "mintFee",
5125
+ "type": "u64"
5126
+ },
5127
+ {
5128
+ "name": "redeemFee",
5129
+ "type": "u64"
5130
+ },
5131
+ {
5132
+ "name": "debtLimit",
5133
+ "type": "u64"
5134
+ },
5135
+ {
5136
+ "name": "minSwap",
5137
+ "type": "u64"
5003
5138
  },
5004
5139
  {
5005
5140
  "name": "overrideCurrentTime",
@@ -5942,6 +6077,12 @@ export const IDL: Vault = {
5942
6077
  "option": "u64"
5943
6078
  }
5944
6079
  },
6080
+ {
6081
+ "name": "emergencyModeThreshold",
6082
+ "type": {
6083
+ "option": "u64"
6084
+ }
6085
+ },
5945
6086
  {
5946
6087
  "name": "oracleChainlink",
5947
6088
  "type": {
@@ -6214,6 +6355,26 @@ export const IDL: Vault = {
6214
6355
  "index": false
6215
6356
  }
6216
6357
  ]
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
+ ]
6217
6378
  }
6218
6379
  ],
6219
6380
  "errors": [
@@ -6359,31 +6520,36 @@ export const IDL: Vault = {
6359
6520
  },
6360
6521
  {
6361
6522
  "code": 6028,
6362
- "name": "PsmError",
6363
- "msg": "PSM error."
6523
+ "name": "PsmMaxDebtReached",
6524
+ "msg": "PSM - Max Debt reached"
6364
6525
  },
6365
6526
  {
6366
6527
  "code": 6029,
6528
+ "name": "PsmMinSwapAmount",
6529
+ "msg": "PSM - Need more to swap"
6530
+ },
6531
+ {
6532
+ "code": 6030,
6367
6533
  "name": "UpdateVaultTypeBadMaxDebtExtended",
6368
6534
  "msg": "New Max debt extended value is less than the current debt!"
6369
6535
  },
6370
6536
  {
6371
- "code": 6030,
6537
+ "code": 6031,
6372
6538
  "name": "UpdateVaultTypeNoEnabledOracles",
6373
6539
  "msg": "No Enabled Oracles!"
6374
6540
  },
6375
6541
  {
6376
- "code": 6031,
6542
+ "code": 6032,
6377
6543
  "name": "UpdateVaultTypeDuplicateOraclePriorities",
6378
6544
  "msg": "Duplicate Oracle Priorities"
6379
6545
  },
6380
6546
  {
6381
- "code": 6032,
6547
+ "code": 6033,
6382
6548
  "name": "UpdateVaultTypeInvalidOraclePriority",
6383
6549
  "msg": "Invalid Oracle Priority"
6384
6550
  },
6385
6551
  {
6386
- "code": 6033,
6552
+ "code": 6034,
6387
6553
  "name": "OracleUpdateFailed",
6388
6554
  "msg": "OracleUpdateFailed"
6389
6555
  }
@@ -0,0 +1,124 @@
1
+ import { BN, Program, Provider } from '@project-serum/anchor'
2
+ import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
+ import {
4
+ Keypair,
5
+ PublicKey,
6
+ sendAndConfirmTransaction,
7
+ Signer,
8
+ SystemProgram,
9
+ Transaction,
10
+ TransactionInstruction,
11
+ } from '@solana/web3.js'
12
+ import { getLinkedListAccounts } from '../utils/getLinkedListAccounts'
13
+ import {
14
+ findAssociatedTokenAddress,
15
+ getHedgeMintPublicKey,
16
+ getPoolPublicKeyForMint,
17
+ getUshMintPublicKey,
18
+ getVaultSystemStatePublicKey,
19
+ HEDGE_PROGRAM_PUBLICKEY,
20
+ } from '../Constants'
21
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
22
+ import { Vault } from '../idl/vault'
23
+ import { parseAnchorErrors } from '../utils/Errors'
24
+ import { VaultAccount } from '../state/VaultAccount'
25
+
26
+ export enum psmStatus {
27
+ PsmEnabled,
28
+ PsmDisabled,
29
+ MintOnly,
30
+ RedeemOnly
31
+ }
32
+
33
+ export async function psmEditAccount(
34
+ program: Program<Vault>,
35
+ provider: Provider,
36
+ payer: Signer,
37
+ collateralMint: PublicKey,
38
+ mintFee: number,
39
+ redeemFee: number,
40
+ debtLimit: number,
41
+ minSwap: number,
42
+ overrideTime?: number
43
+ ): Promise<PublicKey> {
44
+ const ushMintPublickey = await getUshMintPublicKey()
45
+
46
+ const payerUshAccount = await getOrCreateAssociatedTokenAccount(
47
+ provider.connection,
48
+ payer,
49
+ ushMintPublickey,
50
+ payer.publicKey
51
+ )
52
+
53
+ const payerCollateralAccount = await getOrCreateAssociatedTokenAccount(
54
+ provider.connection,
55
+ payer,
56
+ collateralMint,
57
+ payer.publicKey
58
+ )
59
+
60
+
61
+ const enc = new TextEncoder()
62
+ const [psmAccount] = await PublicKey.findProgramAddress(
63
+ [enc.encode(collateralMint.toString().slice(0, 12)), enc.encode('PSM')],
64
+ HEDGE_PROGRAM_PUBLICKEY
65
+ )
66
+
67
+ const psmAccountAta = await getOrCreateAssociatedTokenAccount(
68
+ provider.connection,
69
+ payer,
70
+ collateralMint,
71
+ psmAccount,
72
+ true
73
+ )
74
+
75
+ const transaction = new Transaction().add(
76
+ await psmEditAccountInstruction(
77
+ program,
78
+ payer.publicKey,
79
+ psmAccount,
80
+ collateralMint,
81
+ new BN(mintFee),
82
+ new BN(redeemFee),
83
+ new BN(debtLimit),
84
+ new BN(minSwap),
85
+ overrideTime
86
+ )
87
+ )
88
+ await sendAndConfirmWithDebug(provider.connection, transaction, [payer])
89
+ return payer.publicKey
90
+ }
91
+
92
+ export async function psmEditAccountInstruction(
93
+ program: Program<Vault>,
94
+ payerPublicKey: PublicKey,
95
+ psmAccount: PublicKey,
96
+ collateralMint: PublicKey,
97
+ mintFee: BN,
98
+ redeemFee: BN,
99
+ debtLimit: BN,
100
+ minSwap: BN,
101
+ overrideTime?: number
102
+ ): Promise<TransactionInstruction> {
103
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
104
+ const hedgeMintPublickey = await getHedgeMintPublicKey()
105
+ const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(hedgeMintPublickey)
106
+
107
+
108
+ return await program.methods
109
+ .psmEditAccount(
110
+ mintFee,
111
+ redeemFee,
112
+ debtLimit,
113
+ minSwap,
114
+ new BN(overrideTime ?? Math.floor(Date.now() / 1000)) // override override time
115
+ )
116
+ .accounts({
117
+ payer: payerPublicKey,
118
+ vaultSystemState: vaultSystemStatePublicKey,
119
+ psmAccount: psmAccount,
120
+ collateralMint: collateralMint,
121
+ systemProgram: SystemProgram.programId,
122
+ })
123
+ .instruction()
124
+ }
@@ -0,0 +1,99 @@
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
+ }
@@ -28,6 +28,7 @@ export interface VaultTypeConfig {
28
28
  maxDebtExtended?: BN
29
29
  minDebtPerVault?: BN
30
30
  loanInitFee?: BN
31
+ emergencyModeThreshold?: BN
31
32
 
32
33
  oracleChainlink?: PublicKey
33
34
  oraclePyth?: PublicKey
@@ -76,6 +77,7 @@ export async function updateVaultTypeStatusInstruction(
76
77
  maxDebtExtended: vaultTypeConfig.maxDebtExtended ?? null,
77
78
  minDebtPerVault: vaultTypeConfig.minDebtPerVault ?? null,
78
79
  loanInitFee: vaultTypeConfig.loanInitFee ?? null,
80
+ emergencyModeThreshold: vaultTypeConfig.emergencyModeThreshold ?? null,
79
81
  oracleChainlink: vaultTypeConfig.oracleChainlink ?? null,
80
82
  oraclePyth: vaultTypeConfig.oraclePyth ?? null,
81
83
  oracleSwitchboard: vaultTypeConfig.oracleSwitchboard ?? 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. */ // dont think this is correct? thoughts?
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,16 +177,15 @@ export class VaultAccount {
177
177
  public updateDebtAndCollateral(vaultTypeAccountData: VaultType) {
178
178
  this.denormalizedDebt = new BN(
179
179
  vaultTypeAccountData.debtRedistributionProduct
180
- .div(this.debtProductSnapshotBytes)
181
- .mul(new Decimal(this.denormalizedDebt.toString()))
182
- .floor()
183
- .toString()
180
+ .div(this.debtProductSnapshotBytes)
181
+ .mul(new Decimal(this.denormalizedDebt.toString()))
182
+ .floor()
183
+ .toString()
184
184
  )
185
185
 
186
- const extraCollateralDeposited =
187
- new Decimal(this.denormalizedDebt.toString()).mul(
188
- vaultTypeAccountData.collateralRedistributionAccumulator.sub(this.collateralAccumulatorSnapshotBytes).toNumber()
189
- ).floor()
186
+ const extraCollateralDeposited = new Decimal(this.denormalizedDebt.toString())
187
+ .mul(vaultTypeAccountData.collateralRedistributionAccumulator.sub(this.collateralAccumulatorSnapshotBytes).toNumber())
188
+ .floor()
190
189
  this.deposited = this.deposited.add(new BN(extraCollateralDeposited.toString()))
191
190
 
192
191
  this.collateralAccumulatorSnapshotBytes = vaultTypeAccountData.collateralRedistributionAccumulator