hedge-web3 0.2.19 → 0.2.22

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,19 +5,9 @@ export declare type Pyth = {
5
5
  {
6
6
  "name": "initialize";
7
7
  "accounts": [
8
- {
9
- "name": "payer";
10
- "isMut": true;
11
- "isSigner": true;
12
- },
13
8
  {
14
9
  "name": "price";
15
10
  "isMut": true;
16
- "isSigner": true;
17
- },
18
- {
19
- "name": "systemProgram";
20
- "isMut": false;
21
11
  "isSigner": false;
22
12
  }
23
13
  ];
@@ -53,27 +43,57 @@ export declare type Pyth = {
53
43
  ];
54
44
  }
55
45
  ];
56
- "accounts": [
46
+ "types": [
57
47
  {
58
- "name": "priceWrapper";
48
+ "name": "PriceStatus";
59
49
  "type": {
60
- "kind": "struct";
61
- "fields": [
50
+ "kind": "enum";
51
+ "variants": [
52
+ {
53
+ "name": "Unknown";
54
+ },
55
+ {
56
+ "name": "Trading";
57
+ },
62
58
  {
63
- "name": "price";
64
- "type": {
65
- "defined": "Price";
66
- };
59
+ "name": "Halted";
60
+ },
61
+ {
62
+ "name": "Auction";
67
63
  }
68
64
  ];
69
65
  };
70
- }
71
- ];
72
- "errors": [
66
+ },
67
+ {
68
+ "name": "CorpAction";
69
+ "type": {
70
+ "kind": "enum";
71
+ "variants": [
72
+ {
73
+ "name": "NoCorpAct";
74
+ }
75
+ ];
76
+ };
77
+ },
73
78
  {
74
- "code": 6000;
75
- "name": "InvalidTradingStatus";
76
- "msg": "invalid trading status";
79
+ "name": "PriceType";
80
+ "type": {
81
+ "kind": "enum";
82
+ "variants": [
83
+ {
84
+ "name": "Unknown";
85
+ },
86
+ {
87
+ "name": "Price";
88
+ },
89
+ {
90
+ "name": "TWAP";
91
+ },
92
+ {
93
+ "name": "Volatility";
94
+ }
95
+ ];
96
+ };
77
97
  }
78
98
  ];
79
99
  };
@@ -0,0 +1,47 @@
1
+ export declare type Switchboard = {
2
+ "version": "0.1.0";
3
+ "name": "switchboard";
4
+ "instructions": [
5
+ {
6
+ "name": "initialize";
7
+ "accounts": [
8
+ {
9
+ "name": "aggregator";
10
+ "isMut": true;
11
+ "isSigner": false;
12
+ }
13
+ ];
14
+ "args": [
15
+ {
16
+ "name": "price";
17
+ "type": "u64";
18
+ },
19
+ {
20
+ "name": "scale";
21
+ "type": "u16";
22
+ }
23
+ ];
24
+ },
25
+ {
26
+ "name": "setPrice";
27
+ "accounts": [
28
+ {
29
+ "name": "aggregator";
30
+ "isMut": true;
31
+ "isSigner": false;
32
+ }
33
+ ];
34
+ "args": [
35
+ {
36
+ "name": "price";
37
+ "type": "u64";
38
+ },
39
+ {
40
+ "name": "scale";
41
+ "type": "u16";
42
+ }
43
+ ];
44
+ }
45
+ ];
46
+ };
47
+ export declare const IDL: Switchboard;
@@ -2012,6 +2012,47 @@ export declare type Vault = {
2012
2012
  "type": "i64";
2013
2013
  }
2014
2014
  ];
2015
+ },
2016
+ {
2017
+ "name": "transferVault";
2018
+ "accounts": [
2019
+ {
2020
+ "name": "vault";
2021
+ "isMut": true;
2022
+ "isSigner": false;
2023
+ },
2024
+ {
2025
+ "name": "vaultSystemState";
2026
+ "isMut": true;
2027
+ "isSigner": false;
2028
+ },
2029
+ {
2030
+ "name": "vaultType";
2031
+ "isMut": true;
2032
+ "isSigner": false;
2033
+ },
2034
+ {
2035
+ "name": "history";
2036
+ "isMut": true;
2037
+ "isSigner": true;
2038
+ },
2039
+ {
2040
+ "name": "vaultOwner";
2041
+ "isMut": true;
2042
+ "isSigner": true;
2043
+ },
2044
+ {
2045
+ "name": "systemProgram";
2046
+ "isMut": false;
2047
+ "isSigner": false;
2048
+ }
2049
+ ];
2050
+ "args": [
2051
+ {
2052
+ "name": "newOwner";
2053
+ "type": "publicKey";
2054
+ }
2055
+ ];
2015
2056
  }
2016
2057
  ];
2017
2058
  "accounts": [
@@ -2798,6 +2839,12 @@ export declare type Vault = {
2798
2839
  "option": "u64";
2799
2840
  };
2800
2841
  },
2842
+ {
2843
+ "name": "interestRatePerSecond";
2844
+ "type": {
2845
+ "option": "u128";
2846
+ };
2847
+ },
2801
2848
  {
2802
2849
  "name": "emergencyModeThreshold";
2803
2850
  "type": {
@@ -3076,6 +3123,26 @@ export declare type Vault = {
3076
3123
  "index": false;
3077
3124
  }
3078
3125
  ];
3126
+ },
3127
+ {
3128
+ "name": "VaultTransferEvent";
3129
+ "fields": [
3130
+ {
3131
+ "name": "vault";
3132
+ "type": "publicKey";
3133
+ "index": false;
3134
+ },
3135
+ {
3136
+ "name": "oldOwner";
3137
+ "type": "publicKey";
3138
+ "index": false;
3139
+ },
3140
+ {
3141
+ "name": "newOwner";
3142
+ "type": "publicKey";
3143
+ "index": false;
3144
+ }
3145
+ ];
3079
3146
  }
3080
3147
  ];
3081
3148
  "errors": [
@@ -20,6 +20,7 @@ export * from './instructions/initHedgeFoundation';
20
20
  export * from './instructions/initHedgeFoundationTokens';
21
21
  export * from './instructions/setHalted';
22
22
  export * from './instructions/updateVaultType';
23
+ export * from './instructions/transferVault';
23
24
  export * from './HedgeDecimal';
24
25
  export * from './Constants';
25
26
  export * from './state/VaultAccount';
@@ -0,0 +1,5 @@
1
+ import { Program, Provider } from '@project-serum/anchor';
2
+ import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
3
+ import { Vault } from '../idl/vault';
4
+ export declare function transferVault(program: Program<Vault>, provider: Provider, payer: Signer, vaultPublicKey: PublicKey, vaultSystemStatePublicKey: PublicKey, vaultTypeAccount: PublicKey, newOwner: PublicKey): Promise<PublicKey>;
5
+ export declare function transferVaultInstruction(vaultPublickey: PublicKey, vaultSystemStatePublicKey: PublicKey, vaultTypeAccount: PublicKey, historyPublicKey: PublicKey, vaultOwner: PublicKey, program: Program<Vault>, newOwner: PublicKey): Promise<TransactionInstruction>;
@@ -6,6 +6,7 @@ export interface VaultTypeConfig {
6
6
  maxDebtExtended?: BN;
7
7
  minDebtPerVault?: BN;
8
8
  loanInitFee?: BN;
9
+ interestRatePerSecond?: BN;
9
10
  emergencyModeThreshold?: BN;
10
11
  oracleChainlink?: PublicKey;
11
12
  oraclePyth?: PublicKey;
@@ -11,7 +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. */
14
+ /** The salt used to derive the PDA for the vault. */
15
15
  pdaSalt: string;
16
16
  /** The deposited collateral of the vault (in SOL Lamports). */
17
17
  deposited: BN;
package/lib/idl/pyth.js CHANGED
@@ -8,19 +8,9 @@ exports.IDL = {
8
8
  {
9
9
  "name": "initialize",
10
10
  "accounts": [
11
- {
12
- "name": "payer",
13
- "isMut": true,
14
- "isSigner": true
15
- },
16
11
  {
17
12
  "name": "price",
18
13
  "isMut": true,
19
- "isSigner": true
20
- },
21
- {
22
- "name": "systemProgram",
23
- "isMut": false,
24
14
  "isSigner": false
25
15
  }
26
16
  ],
@@ -56,27 +46,57 @@ exports.IDL = {
56
46
  ]
57
47
  }
58
48
  ],
59
- "accounts": [
49
+ "types": [
60
50
  {
61
- "name": "priceWrapper",
51
+ "name": "PriceStatus",
62
52
  "type": {
63
- "kind": "struct",
64
- "fields": [
53
+ "kind": "enum",
54
+ "variants": [
55
+ {
56
+ "name": "Unknown"
57
+ },
58
+ {
59
+ "name": "Trading"
60
+ },
65
61
  {
66
- "name": "price",
67
- "type": {
68
- "defined": "Price"
69
- }
62
+ "name": "Halted"
63
+ },
64
+ {
65
+ "name": "Auction"
70
66
  }
71
67
  ]
72
68
  }
73
- }
74
- ],
75
- "errors": [
69
+ },
70
+ {
71
+ "name": "CorpAction",
72
+ "type": {
73
+ "kind": "enum",
74
+ "variants": [
75
+ {
76
+ "name": "NoCorpAct"
77
+ }
78
+ ]
79
+ }
80
+ },
76
81
  {
77
- "code": 6000,
78
- "name": "InvalidTradingStatus",
79
- "msg": "invalid trading status"
82
+ "name": "PriceType",
83
+ "type": {
84
+ "kind": "enum",
85
+ "variants": [
86
+ {
87
+ "name": "Unknown"
88
+ },
89
+ {
90
+ "name": "Price"
91
+ },
92
+ {
93
+ "name": "TWAP"
94
+ },
95
+ {
96
+ "name": "Volatility"
97
+ }
98
+ ]
99
+ }
80
100
  }
81
101
  ]
82
102
  };
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IDL = void 0;
4
+ exports.IDL = {
5
+ "version": "0.1.0",
6
+ "name": "switchboard",
7
+ "instructions": [
8
+ {
9
+ "name": "initialize",
10
+ "accounts": [
11
+ {
12
+ "name": "aggregator",
13
+ "isMut": true,
14
+ "isSigner": false
15
+ }
16
+ ],
17
+ "args": [
18
+ {
19
+ "name": "price",
20
+ "type": "u64"
21
+ },
22
+ {
23
+ "name": "scale",
24
+ "type": "u16"
25
+ }
26
+ ]
27
+ },
28
+ {
29
+ "name": "setPrice",
30
+ "accounts": [
31
+ {
32
+ "name": "aggregator",
33
+ "isMut": true,
34
+ "isSigner": false
35
+ }
36
+ ],
37
+ "args": [
38
+ {
39
+ "name": "price",
40
+ "type": "u64"
41
+ },
42
+ {
43
+ "name": "scale",
44
+ "type": "u16"
45
+ }
46
+ ]
47
+ }
48
+ ]
49
+ };
package/lib/idl/vault.js CHANGED
@@ -2015,6 +2015,47 @@ exports.IDL = {
2015
2015
  "type": "i64"
2016
2016
  }
2017
2017
  ]
2018
+ },
2019
+ {
2020
+ "name": "transferVault",
2021
+ "accounts": [
2022
+ {
2023
+ "name": "vault",
2024
+ "isMut": true,
2025
+ "isSigner": false
2026
+ },
2027
+ {
2028
+ "name": "vaultSystemState",
2029
+ "isMut": true,
2030
+ "isSigner": false
2031
+ },
2032
+ {
2033
+ "name": "vaultType",
2034
+ "isMut": true,
2035
+ "isSigner": false
2036
+ },
2037
+ {
2038
+ "name": "history",
2039
+ "isMut": true,
2040
+ "isSigner": true
2041
+ },
2042
+ {
2043
+ "name": "vaultOwner",
2044
+ "isMut": true,
2045
+ "isSigner": true
2046
+ },
2047
+ {
2048
+ "name": "systemProgram",
2049
+ "isMut": false,
2050
+ "isSigner": false
2051
+ }
2052
+ ],
2053
+ "args": [
2054
+ {
2055
+ "name": "newOwner",
2056
+ "type": "publicKey"
2057
+ }
2058
+ ]
2018
2059
  }
2019
2060
  ],
2020
2061
  "accounts": [
@@ -2801,6 +2842,12 @@ exports.IDL = {
2801
2842
  "option": "u64"
2802
2843
  }
2803
2844
  },
2845
+ {
2846
+ "name": "interestRatePerSecond",
2847
+ "type": {
2848
+ "option": "u128"
2849
+ }
2850
+ },
2804
2851
  {
2805
2852
  "name": "emergencyModeThreshold",
2806
2853
  "type": {
@@ -3079,6 +3126,26 @@ exports.IDL = {
3079
3126
  "index": false
3080
3127
  }
3081
3128
  ]
3129
+ },
3130
+ {
3131
+ "name": "VaultTransferEvent",
3132
+ "fields": [
3133
+ {
3134
+ "name": "vault",
3135
+ "type": "publicKey",
3136
+ "index": false
3137
+ },
3138
+ {
3139
+ "name": "oldOwner",
3140
+ "type": "publicKey",
3141
+ "index": false
3142
+ },
3143
+ {
3144
+ "name": "newOwner",
3145
+ "type": "publicKey",
3146
+ "index": false
3147
+ }
3148
+ ]
3082
3149
  }
3083
3150
  ],
3084
3151
  "errors": [
package/lib/index.js CHANGED
@@ -32,6 +32,7 @@ __exportStar(require("./instructions/initHedgeFoundation"), exports);
32
32
  __exportStar(require("./instructions/initHedgeFoundationTokens"), exports);
33
33
  __exportStar(require("./instructions/setHalted"), exports);
34
34
  __exportStar(require("./instructions/updateVaultType"), exports);
35
+ __exportStar(require("./instructions/transferVault"), exports);
35
36
  __exportStar(require("./HedgeDecimal"), exports);
36
37
  __exportStar(require("./Constants"), exports);
37
38
  __exportStar(require("./state/VaultAccount"), exports);
@@ -0,0 +1,41 @@
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 sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
18
+ function transferVault(program, provider, payer, vaultPublicKey, vaultSystemStatePublicKey, vaultTypeAccount, newOwner) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ const history = web3_js_1.Keypair.generate();
21
+ const transaction = new web3_js_1.Transaction().add(yield transferVaultInstruction(vaultPublicKey, vaultSystemStatePublicKey, vaultTypeAccount, history.publicKey, payer.publicKey, program, newOwner));
22
+ yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer, history]);
23
+ return vaultPublicKey;
24
+ });
25
+ }
26
+ exports.transferVault = transferVault;
27
+ function transferVaultInstruction(vaultPublickey, vaultSystemStatePublicKey, vaultTypeAccount, historyPublicKey, vaultOwner, program, newOwner) {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ return yield program.methods
30
+ .transferVault(newOwner)
31
+ .accounts({
32
+ vault: vaultPublickey,
33
+ vaultSystemState: vaultSystemStatePublicKey,
34
+ vaultType: vaultTypeAccount,
35
+ history: historyPublicKey,
36
+ vaultOwner: vaultOwner,
37
+ })
38
+ .instruction();
39
+ });
40
+ }
41
+ exports.transferVaultInstruction = transferVaultInstruction;
@@ -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
- 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,
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,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.19",
3
+ "version": "0.2.22",
4
4
  "description": "Hedge Javascript Web3 API",
5
5
  "main": "lib/index.js",
6
6
  "types": "declarations/index.d.ts",
package/src/idl/pyth.ts CHANGED
@@ -5,19 +5,9 @@ export type Pyth = {
5
5
  {
6
6
  "name": "initialize",
7
7
  "accounts": [
8
- {
9
- "name": "payer",
10
- "isMut": true,
11
- "isSigner": true
12
- },
13
8
  {
14
9
  "name": "price",
15
10
  "isMut": true,
16
- "isSigner": true
17
- },
18
- {
19
- "name": "systemProgram",
20
- "isMut": false,
21
11
  "isSigner": false
22
12
  }
23
13
  ],
@@ -53,27 +43,57 @@ export type Pyth = {
53
43
  ]
54
44
  }
55
45
  ],
56
- "accounts": [
46
+ "types": [
57
47
  {
58
- "name": "priceWrapper",
48
+ "name": "PriceStatus",
59
49
  "type": {
60
- "kind": "struct",
61
- "fields": [
50
+ "kind": "enum",
51
+ "variants": [
52
+ {
53
+ "name": "Unknown"
54
+ },
55
+ {
56
+ "name": "Trading"
57
+ },
62
58
  {
63
- "name": "price",
64
- "type": {
65
- "defined": "Price"
66
- }
59
+ "name": "Halted"
60
+ },
61
+ {
62
+ "name": "Auction"
67
63
  }
68
64
  ]
69
65
  }
70
- }
71
- ],
72
- "errors": [
66
+ },
67
+ {
68
+ "name": "CorpAction",
69
+ "type": {
70
+ "kind": "enum",
71
+ "variants": [
72
+ {
73
+ "name": "NoCorpAct"
74
+ }
75
+ ]
76
+ }
77
+ },
73
78
  {
74
- "code": 6000,
75
- "name": "InvalidTradingStatus",
76
- "msg": "invalid trading status"
79
+ "name": "PriceType",
80
+ "type": {
81
+ "kind": "enum",
82
+ "variants": [
83
+ {
84
+ "name": "Unknown"
85
+ },
86
+ {
87
+ "name": "Price"
88
+ },
89
+ {
90
+ "name": "TWAP"
91
+ },
92
+ {
93
+ "name": "Volatility"
94
+ }
95
+ ]
96
+ }
77
97
  }
78
98
  ]
79
99
  };
@@ -85,19 +105,9 @@ export const IDL: Pyth = {
85
105
  {
86
106
  "name": "initialize",
87
107
  "accounts": [
88
- {
89
- "name": "payer",
90
- "isMut": true,
91
- "isSigner": true
92
- },
93
108
  {
94
109
  "name": "price",
95
110
  "isMut": true,
96
- "isSigner": true
97
- },
98
- {
99
- "name": "systemProgram",
100
- "isMut": false,
101
111
  "isSigner": false
102
112
  }
103
113
  ],
@@ -133,27 +143,57 @@ export const IDL: Pyth = {
133
143
  ]
134
144
  }
135
145
  ],
136
- "accounts": [
146
+ "types": [
137
147
  {
138
- "name": "priceWrapper",
148
+ "name": "PriceStatus",
139
149
  "type": {
140
- "kind": "struct",
141
- "fields": [
150
+ "kind": "enum",
151
+ "variants": [
152
+ {
153
+ "name": "Unknown"
154
+ },
155
+ {
156
+ "name": "Trading"
157
+ },
142
158
  {
143
- "name": "price",
144
- "type": {
145
- "defined": "Price"
146
- }
159
+ "name": "Halted"
160
+ },
161
+ {
162
+ "name": "Auction"
147
163
  }
148
164
  ]
149
165
  }
150
- }
151
- ],
152
- "errors": [
166
+ },
167
+ {
168
+ "name": "CorpAction",
169
+ "type": {
170
+ "kind": "enum",
171
+ "variants": [
172
+ {
173
+ "name": "NoCorpAct"
174
+ }
175
+ ]
176
+ }
177
+ },
153
178
  {
154
- "code": 6000,
155
- "name": "InvalidTradingStatus",
156
- "msg": "invalid trading status"
179
+ "name": "PriceType",
180
+ "type": {
181
+ "kind": "enum",
182
+ "variants": [
183
+ {
184
+ "name": "Unknown"
185
+ },
186
+ {
187
+ "name": "Price"
188
+ },
189
+ {
190
+ "name": "TWAP"
191
+ },
192
+ {
193
+ "name": "Volatility"
194
+ }
195
+ ]
196
+ }
157
197
  }
158
198
  ]
159
199
  };
@@ -0,0 +1,93 @@
1
+ export type Switchboard = {
2
+ "version": "0.1.0",
3
+ "name": "switchboard",
4
+ "instructions": [
5
+ {
6
+ "name": "initialize",
7
+ "accounts": [
8
+ {
9
+ "name": "aggregator",
10
+ "isMut": true,
11
+ "isSigner": false
12
+ }
13
+ ],
14
+ "args": [
15
+ {
16
+ "name": "price",
17
+ "type": "u64"
18
+ },
19
+ {
20
+ "name": "scale",
21
+ "type": "u16"
22
+ }
23
+ ]
24
+ },
25
+ {
26
+ "name": "setPrice",
27
+ "accounts": [
28
+ {
29
+ "name": "aggregator",
30
+ "isMut": true,
31
+ "isSigner": false
32
+ }
33
+ ],
34
+ "args": [
35
+ {
36
+ "name": "price",
37
+ "type": "u64"
38
+ },
39
+ {
40
+ "name": "scale",
41
+ "type": "u16"
42
+ }
43
+ ]
44
+ }
45
+ ]
46
+ };
47
+
48
+ export const IDL: Switchboard = {
49
+ "version": "0.1.0",
50
+ "name": "switchboard",
51
+ "instructions": [
52
+ {
53
+ "name": "initialize",
54
+ "accounts": [
55
+ {
56
+ "name": "aggregator",
57
+ "isMut": true,
58
+ "isSigner": false
59
+ }
60
+ ],
61
+ "args": [
62
+ {
63
+ "name": "price",
64
+ "type": "u64"
65
+ },
66
+ {
67
+ "name": "scale",
68
+ "type": "u16"
69
+ }
70
+ ]
71
+ },
72
+ {
73
+ "name": "setPrice",
74
+ "accounts": [
75
+ {
76
+ "name": "aggregator",
77
+ "isMut": true,
78
+ "isSigner": false
79
+ }
80
+ ],
81
+ "args": [
82
+ {
83
+ "name": "price",
84
+ "type": "u64"
85
+ },
86
+ {
87
+ "name": "scale",
88
+ "type": "u16"
89
+ }
90
+ ]
91
+ }
92
+ ]
93
+ };
package/src/idl/vault.ts CHANGED
@@ -2012,6 +2012,47 @@ export type Vault = {
2012
2012
  "type": "i64"
2013
2013
  }
2014
2014
  ]
2015
+ },
2016
+ {
2017
+ "name": "transferVault",
2018
+ "accounts": [
2019
+ {
2020
+ "name": "vault",
2021
+ "isMut": true,
2022
+ "isSigner": false
2023
+ },
2024
+ {
2025
+ "name": "vaultSystemState",
2026
+ "isMut": true,
2027
+ "isSigner": false
2028
+ },
2029
+ {
2030
+ "name": "vaultType",
2031
+ "isMut": true,
2032
+ "isSigner": false
2033
+ },
2034
+ {
2035
+ "name": "history",
2036
+ "isMut": true,
2037
+ "isSigner": true
2038
+ },
2039
+ {
2040
+ "name": "vaultOwner",
2041
+ "isMut": true,
2042
+ "isSigner": true
2043
+ },
2044
+ {
2045
+ "name": "systemProgram",
2046
+ "isMut": false,
2047
+ "isSigner": false
2048
+ }
2049
+ ],
2050
+ "args": [
2051
+ {
2052
+ "name": "newOwner",
2053
+ "type": "publicKey"
2054
+ }
2055
+ ]
2015
2056
  }
2016
2057
  ],
2017
2058
  "accounts": [
@@ -2798,6 +2839,12 @@ export type Vault = {
2798
2839
  "option": "u64"
2799
2840
  }
2800
2841
  },
2842
+ {
2843
+ "name": "interestRatePerSecond",
2844
+ "type": {
2845
+ "option": "u128"
2846
+ }
2847
+ },
2801
2848
  {
2802
2849
  "name": "emergencyModeThreshold",
2803
2850
  "type": {
@@ -3076,6 +3123,26 @@ export type Vault = {
3076
3123
  "index": false
3077
3124
  }
3078
3125
  ]
3126
+ },
3127
+ {
3128
+ "name": "VaultTransferEvent",
3129
+ "fields": [
3130
+ {
3131
+ "name": "vault",
3132
+ "type": "publicKey",
3133
+ "index": false
3134
+ },
3135
+ {
3136
+ "name": "oldOwner",
3137
+ "type": "publicKey",
3138
+ "index": false
3139
+ },
3140
+ {
3141
+ "name": "newOwner",
3142
+ "type": "publicKey",
3143
+ "index": false
3144
+ }
3145
+ ]
3079
3146
  }
3080
3147
  ],
3081
3148
  "errors": [
@@ -5271,6 +5338,47 @@ export const IDL: Vault = {
5271
5338
  "type": "i64"
5272
5339
  }
5273
5340
  ]
5341
+ },
5342
+ {
5343
+ "name": "transferVault",
5344
+ "accounts": [
5345
+ {
5346
+ "name": "vault",
5347
+ "isMut": true,
5348
+ "isSigner": false
5349
+ },
5350
+ {
5351
+ "name": "vaultSystemState",
5352
+ "isMut": true,
5353
+ "isSigner": false
5354
+ },
5355
+ {
5356
+ "name": "vaultType",
5357
+ "isMut": true,
5358
+ "isSigner": false
5359
+ },
5360
+ {
5361
+ "name": "history",
5362
+ "isMut": true,
5363
+ "isSigner": true
5364
+ },
5365
+ {
5366
+ "name": "vaultOwner",
5367
+ "isMut": true,
5368
+ "isSigner": true
5369
+ },
5370
+ {
5371
+ "name": "systemProgram",
5372
+ "isMut": false,
5373
+ "isSigner": false
5374
+ }
5375
+ ],
5376
+ "args": [
5377
+ {
5378
+ "name": "newOwner",
5379
+ "type": "publicKey"
5380
+ }
5381
+ ]
5274
5382
  }
5275
5383
  ],
5276
5384
  "accounts": [
@@ -6057,6 +6165,12 @@ export const IDL: Vault = {
6057
6165
  "option": "u64"
6058
6166
  }
6059
6167
  },
6168
+ {
6169
+ "name": "interestRatePerSecond",
6170
+ "type": {
6171
+ "option": "u128"
6172
+ }
6173
+ },
6060
6174
  {
6061
6175
  "name": "emergencyModeThreshold",
6062
6176
  "type": {
@@ -6335,6 +6449,26 @@ export const IDL: Vault = {
6335
6449
  "index": false
6336
6450
  }
6337
6451
  ]
6452
+ },
6453
+ {
6454
+ "name": "VaultTransferEvent",
6455
+ "fields": [
6456
+ {
6457
+ "name": "vault",
6458
+ "type": "publicKey",
6459
+ "index": false
6460
+ },
6461
+ {
6462
+ "name": "oldOwner",
6463
+ "type": "publicKey",
6464
+ "index": false
6465
+ },
6466
+ {
6467
+ "name": "newOwner",
6468
+ "type": "publicKey",
6469
+ "index": false
6470
+ }
6471
+ ]
6338
6472
  }
6339
6473
  ],
6340
6474
  "errors": [
package/src/index.ts CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  export * from './instructions/createStakingPool'
3
2
  export * from './instructions/depositStakingPool'
4
3
  export * from './instructions/withdrawStakingPool'
@@ -21,10 +20,9 @@ export * from './instructions/initHedgeFoundation'
21
20
  export * from './instructions/initHedgeFoundationTokens'
22
21
  export * from './instructions/setHalted'
23
22
  export * from './instructions/updateVaultType'
24
-
23
+ export * from './instructions/transferVault'
25
24
  export * from './HedgeDecimal'
26
25
  export * from './Constants'
27
-
28
26
  export * from './state/VaultAccount'
29
27
  export * from './state/VaultHistoryEvent'
30
28
  export * from './state/StakingPool'
@@ -32,6 +30,5 @@ export * from './state/StakingPoolPosition'
32
30
  export * from './state/LiquidationPoolEra'
33
31
  export * from './state/LiquidationPoolState'
34
32
  export * from './state/LiquidationPosition'
35
-
36
33
  export * from './utils/getLinkedListAccounts'
37
34
  export * from './idl/vault'
@@ -0,0 +1,62 @@
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
+
13
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
14
+ import { Vault } from '../idl/vault'
15
+
16
+ export async function transferVault(
17
+ program: Program<Vault>,
18
+ provider: Provider,
19
+ payer: Signer,
20
+ vaultPublicKey: PublicKey,
21
+ vaultSystemStatePublicKey: PublicKey,
22
+ vaultTypeAccount: PublicKey,
23
+ newOwner: PublicKey
24
+ ): Promise<PublicKey> {
25
+ const history = Keypair.generate()
26
+
27
+ const transaction = new Transaction().add(
28
+ await transferVaultInstruction(
29
+ vaultPublicKey,
30
+ vaultSystemStatePublicKey,
31
+ vaultTypeAccount,
32
+ history.publicKey,
33
+ payer.publicKey,
34
+ program,
35
+ newOwner
36
+ )
37
+ )
38
+
39
+ await sendAndConfirmWithDebug(provider.connection, transaction, [payer, history])
40
+ return vaultPublicKey
41
+ }
42
+
43
+ export async function transferVaultInstruction(
44
+ vaultPublickey: PublicKey,
45
+ vaultSystemStatePublicKey: PublicKey,
46
+ vaultTypeAccount: PublicKey,
47
+ historyPublicKey: PublicKey,
48
+ vaultOwner: PublicKey,
49
+ program: Program<Vault>,
50
+ newOwner: PublicKey
51
+ ): Promise<TransactionInstruction> {
52
+ return await program.methods
53
+ .transferVault(newOwner)
54
+ .accounts({
55
+ vault: vaultPublickey,
56
+ vaultSystemState: vaultSystemStatePublicKey,
57
+ vaultType: vaultTypeAccount,
58
+ history: historyPublicKey,
59
+ vaultOwner: vaultOwner,
60
+ })
61
+ .instruction()
62
+ }
@@ -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 salt used to derive the PDA for the vault. */
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