@kamino-finance/klend-sdk 5.14.0-beta.0 → 5.14.0

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.
Files changed (150) hide show
  1. package/dist/classes/farm_utils.d.ts.map +1 -1
  2. package/dist/classes/farm_utils.js +10 -3
  3. package/dist/classes/farm_utils.js.map +1 -1
  4. package/dist/classes/manager.d.ts +21 -6
  5. package/dist/classes/manager.d.ts.map +1 -1
  6. package/dist/classes/manager.js +311 -40
  7. package/dist/classes/manager.js.map +1 -1
  8. package/dist/classes/obligation.d.ts +1 -3
  9. package/dist/classes/obligation.d.ts.map +1 -1
  10. package/dist/classes/obligation.js +2 -18
  11. package/dist/classes/obligation.js.map +1 -1
  12. package/dist/classes/obligationOrder.d.ts +2 -1
  13. package/dist/classes/obligationOrder.d.ts.map +1 -1
  14. package/dist/classes/obligationOrder.js +16 -3
  15. package/dist/classes/obligationOrder.js.map +1 -1
  16. package/dist/classes/reserve.d.ts +14 -5
  17. package/dist/classes/reserve.d.ts.map +1 -1
  18. package/dist/classes/reserve.js +463 -91
  19. package/dist/classes/reserve.js.map +1 -1
  20. package/dist/classes/shared.d.ts +1 -0
  21. package/dist/classes/shared.d.ts.map +1 -1
  22. package/dist/classes/shared.js.map +1 -1
  23. package/dist/classes/utils.d.ts +0 -1
  24. package/dist/classes/utils.d.ts.map +1 -1
  25. package/dist/classes/utils.js +0 -12
  26. package/dist/classes/utils.js.map +1 -1
  27. package/dist/classes/vault.d.ts +11 -1
  28. package/dist/classes/vault.d.ts.map +1 -1
  29. package/dist/classes/vault.js +54 -6
  30. package/dist/classes/vault.js.map +1 -1
  31. package/dist/client_kamino_manager.d.ts.map +1 -1
  32. package/dist/client_kamino_manager.js +26 -27
  33. package/dist/client_kamino_manager.js.map +1 -1
  34. package/dist/idl.json +9 -186
  35. package/dist/idl_codegen/accounts/LendingMarket.d.ts +3 -24
  36. package/dist/idl_codegen/accounts/LendingMarket.d.ts.map +1 -1
  37. package/dist/idl_codegen/accounts/LendingMarket.js +7 -25
  38. package/dist/idl_codegen/accounts/LendingMarket.js.map +1 -1
  39. package/dist/idl_codegen/accounts/index.d.ts +0 -2
  40. package/dist/idl_codegen/accounts/index.d.ts.map +1 -1
  41. package/dist/idl_codegen/accounts/index.js +1 -3
  42. package/dist/idl_codegen/accounts/index.js.map +1 -1
  43. package/dist/idl_codegen/errors/custom.d.ts +1 -25
  44. package/dist/idl_codegen/errors/custom.d.ts.map +1 -1
  45. package/dist/idl_codegen/errors/custom.js +1 -43
  46. package/dist/idl_codegen/errors/custom.js.map +1 -1
  47. package/dist/idl_codegen/instructions/idlMissingTypes.d.ts +1 -2
  48. package/dist/idl_codegen/instructions/idlMissingTypes.d.ts.map +1 -1
  49. package/dist/idl_codegen/instructions/idlMissingTypes.js +1 -2
  50. package/dist/idl_codegen/instructions/idlMissingTypes.js.map +1 -1
  51. package/dist/idl_codegen/instructions/index.d.ts +0 -6
  52. package/dist/idl_codegen/instructions/index.d.ts.map +1 -1
  53. package/dist/idl_codegen/instructions/index.js +1 -7
  54. package/dist/idl_codegen/instructions/index.js.map +1 -1
  55. package/dist/idl_codegen/instructions/updateReserveConfig.d.ts +3 -4
  56. package/dist/idl_codegen/instructions/updateReserveConfig.d.ts.map +1 -1
  57. package/dist/idl_codegen/instructions/updateReserveConfig.js +3 -5
  58. package/dist/idl_codegen/instructions/updateReserveConfig.js.map +1 -1
  59. package/dist/idl_codegen/instructions/withdrawProtocolFee.d.ts +2 -2
  60. package/dist/idl_codegen/instructions/withdrawProtocolFee.d.ts.map +1 -1
  61. package/dist/idl_codegen/instructions/withdrawProtocolFee.js +6 -2
  62. package/dist/idl_codegen/instructions/withdrawProtocolFee.js.map +1 -1
  63. package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts +7 -33
  64. package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts.map +1 -1
  65. package/dist/idl_codegen/types/UpdateLendingMarketMode.js +12 -60
  66. package/dist/idl_codegen/types/UpdateLendingMarketMode.js.map +1 -1
  67. package/dist/idl_codegen/types/index.d.ts +2 -6
  68. package/dist/idl_codegen/types/index.d.ts.map +1 -1
  69. package/dist/idl_codegen/types/index.js +1 -3
  70. package/dist/idl_codegen/types/index.js.map +1 -1
  71. package/dist/lending_operations/repay_with_collateral_calcs.d.ts.map +1 -1
  72. package/dist/lending_operations/repay_with_collateral_calcs.js +2 -2
  73. package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -1
  74. package/dist/utils/accountListing.d.ts +1 -1
  75. package/dist/utils/accountListing.d.ts.map +1 -1
  76. package/dist/utils/accountListing.js +2 -2
  77. package/dist/utils/accountListing.js.map +1 -1
  78. package/dist/utils/api.d.ts +5 -1
  79. package/dist/utils/api.d.ts.map +1 -1
  80. package/dist/utils/api.js +15 -6
  81. package/dist/utils/api.js.map +1 -1
  82. package/dist/utils/constants.d.ts +1 -1
  83. package/dist/utils/constants.js +1 -1
  84. package/dist/utils/lookupTable.d.ts.map +1 -1
  85. package/dist/utils/lookupTable.js +6 -1
  86. package/dist/utils/lookupTable.js.map +1 -1
  87. package/dist/utils/managerTypes.d.ts.map +1 -1
  88. package/dist/utils/managerTypes.js +4 -10
  89. package/dist/utils/managerTypes.js.map +1 -1
  90. package/dist/utils/seeds.d.ts +0 -16
  91. package/dist/utils/seeds.d.ts.map +1 -1
  92. package/dist/utils/seeds.js +1 -23
  93. package/dist/utils/seeds.js.map +1 -1
  94. package/package.json +1 -1
  95. package/src/classes/farm_utils.ts +11 -3
  96. package/src/classes/manager.ts +417 -52
  97. package/src/classes/obligation.ts +9 -20
  98. package/src/classes/obligationOrder.ts +22 -3
  99. package/src/classes/reserve.ts +783 -119
  100. package/src/classes/shared.ts +1 -0
  101. package/src/classes/utils.ts +0 -12
  102. package/src/classes/vault.ts +75 -7
  103. package/src/client_kamino_manager.ts +34 -42
  104. package/src/idl.json +9 -186
  105. package/src/idl_codegen/accounts/LendingMarket.ts +9 -41
  106. package/src/idl_codegen/accounts/index.ts +0 -2
  107. package/src/idl_codegen/errors/custom.ts +0 -45
  108. package/src/idl_codegen/instructions/idlMissingTypes.ts +2 -4
  109. package/src/idl_codegen/instructions/index.ts +0 -9
  110. package/src/idl_codegen/instructions/updateReserveConfig.ts +5 -7
  111. package/src/idl_codegen/instructions/withdrawProtocolFee.ts +8 -4
  112. package/src/idl_codegen/types/UpdateLendingMarketMode.ts +13 -73
  113. package/src/idl_codegen/types/index.ts +2 -16
  114. package/src/lending_operations/repay_with_collateral_calcs.ts +2 -5
  115. package/src/utils/accountListing.ts +3 -2
  116. package/src/utils/api.ts +20 -6
  117. package/src/utils/constants.ts +1 -1
  118. package/src/utils/lookupTable.ts +7 -1
  119. package/src/utils/managerTypes.ts +4 -10
  120. package/src/utils/seeds.ts +0 -25
  121. package/dist/classes/configItems.d.ts +0 -137
  122. package/dist/classes/configItems.d.ts.map +0 -1
  123. package/dist/classes/configItems.js +0 -143
  124. package/dist/classes/configItems.js.map +0 -1
  125. package/dist/idl_codegen/accounts/GlobalConfig.d.ts +0 -40
  126. package/dist/idl_codegen/accounts/GlobalConfig.d.ts.map +0 -1
  127. package/dist/idl_codegen/accounts/GlobalConfig.js +0 -116
  128. package/dist/idl_codegen/accounts/GlobalConfig.js.map +0 -1
  129. package/dist/idl_codegen/instructions/initGlobalConfig.d.ts +0 -10
  130. package/dist/idl_codegen/instructions/initGlobalConfig.d.ts.map +0 -1
  131. package/dist/idl_codegen/instructions/initGlobalConfig.js +0 -19
  132. package/dist/idl_codegen/instructions/initGlobalConfig.js.map +0 -1
  133. package/dist/idl_codegen/instructions/updateGlobalConfig.d.ts +0 -13
  134. package/dist/idl_codegen/instructions/updateGlobalConfig.d.ts.map +0 -1
  135. package/dist/idl_codegen/instructions/updateGlobalConfig.js +0 -61
  136. package/dist/idl_codegen/instructions/updateGlobalConfig.js.map +0 -1
  137. package/dist/idl_codegen/instructions/updateGlobalConfigAdmin.d.ts +0 -7
  138. package/dist/idl_codegen/instructions/updateGlobalConfigAdmin.d.ts.map +0 -1
  139. package/dist/idl_codegen/instructions/updateGlobalConfigAdmin.js +0 -16
  140. package/dist/idl_codegen/instructions/updateGlobalConfigAdmin.js.map +0 -1
  141. package/dist/idl_codegen/types/UpdateGlobalConfigMode.d.ts +0 -32
  142. package/dist/idl_codegen/types/UpdateGlobalConfigMode.d.ts.map +0 -1
  143. package/dist/idl_codegen/types/UpdateGlobalConfigMode.js +0 -108
  144. package/dist/idl_codegen/types/UpdateGlobalConfigMode.js.map +0 -1
  145. package/src/classes/configItems.ts +0 -229
  146. package/src/idl_codegen/accounts/GlobalConfig.ts +0 -125
  147. package/src/idl_codegen/instructions/initGlobalConfig.ts +0 -30
  148. package/src/idl_codegen/instructions/updateGlobalConfig.ts +0 -47
  149. package/src/idl_codegen/instructions/updateGlobalConfigAdmin.ts +0 -24
  150. package/src/idl_codegen/types/UpdateGlobalConfigMode.ts +0 -90
@@ -1,32 +0,0 @@
1
- import * as types from "../types";
2
- import * as borsh from "@coral-xyz/borsh";
3
- export interface PendingAdminJSON {
4
- kind: "PendingAdmin";
5
- }
6
- export declare class PendingAdmin {
7
- static readonly discriminator = 0;
8
- static readonly kind = "PendingAdmin";
9
- readonly discriminator = 0;
10
- readonly kind = "PendingAdmin";
11
- toJSON(): PendingAdminJSON;
12
- toEncodable(): {
13
- PendingAdmin: {};
14
- };
15
- }
16
- export interface FeeCollectorJSON {
17
- kind: "FeeCollector";
18
- }
19
- export declare class FeeCollector {
20
- static readonly discriminator = 1;
21
- static readonly kind = "FeeCollector";
22
- readonly discriminator = 1;
23
- readonly kind = "FeeCollector";
24
- toJSON(): FeeCollectorJSON;
25
- toEncodable(): {
26
- FeeCollector: {};
27
- };
28
- }
29
- export declare function fromDecoded(obj: any): types.UpdateGlobalConfigModeKind;
30
- export declare function fromJSON(obj: types.UpdateGlobalConfigModeJSON): types.UpdateGlobalConfigModeKind;
31
- export declare function layout(property?: string): borsh.EnumLayout<unknown>;
32
- //# sourceMappingURL=UpdateGlobalConfigMode.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"UpdateGlobalConfigMode.d.ts","sourceRoot":"","sources":["../../../src/idl_codegen/types/UpdateGlobalConfigMode.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,UAAU,CAAA;AACjC,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAA;AAEzC,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,cAAc,CAAA;CACrB;AAED,qBAAa,YAAY;IACvB,MAAM,CAAC,QAAQ,CAAC,aAAa,KAAI;IACjC,MAAM,CAAC,QAAQ,CAAC,IAAI,kBAAiB;IACrC,QAAQ,CAAC,aAAa,KAAI;IAC1B,QAAQ,CAAC,IAAI,kBAAiB;IAE9B,MAAM,IAAI,gBAAgB;IAM1B,WAAW;;;CAKZ;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,cAAc,CAAA;CACrB;AAED,qBAAa,YAAY;IACvB,MAAM,CAAC,QAAQ,CAAC,aAAa,KAAI;IACjC,MAAM,CAAC,QAAQ,CAAC,IAAI,kBAAiB;IACrC,QAAQ,CAAC,aAAa,KAAI;IAC1B,QAAQ,CAAC,IAAI,kBAAiB;IAE9B,MAAM,IAAI,gBAAgB;IAM1B,WAAW;;;CAKZ;AAGD,wBAAgB,WAAW,CAAC,GAAG,EAAE,GAAG,GAAG,KAAK,CAAC,0BAA0B,CAatE;AAED,wBAAgB,QAAQ,CACtB,GAAG,EAAE,KAAK,CAAC,0BAA0B,GACpC,KAAK,CAAC,0BAA0B,CASlC;AAED,wBAAgB,MAAM,CAAC,QAAQ,CAAC,EAAE,MAAM,6BASvC"}
@@ -1,108 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.FeeCollector = exports.PendingAdmin = void 0;
37
- exports.fromDecoded = fromDecoded;
38
- exports.fromJSON = fromJSON;
39
- exports.layout = layout;
40
- const borsh = __importStar(require("@coral-xyz/borsh"));
41
- class PendingAdmin {
42
- static discriminator = 0;
43
- static kind = "PendingAdmin";
44
- discriminator = 0;
45
- kind = "PendingAdmin";
46
- toJSON() {
47
- return {
48
- kind: "PendingAdmin",
49
- };
50
- }
51
- toEncodable() {
52
- return {
53
- PendingAdmin: {},
54
- };
55
- }
56
- }
57
- exports.PendingAdmin = PendingAdmin;
58
- class FeeCollector {
59
- static discriminator = 1;
60
- static kind = "FeeCollector";
61
- discriminator = 1;
62
- kind = "FeeCollector";
63
- toJSON() {
64
- return {
65
- kind: "FeeCollector",
66
- };
67
- }
68
- toEncodable() {
69
- return {
70
- FeeCollector: {},
71
- };
72
- }
73
- }
74
- exports.FeeCollector = FeeCollector;
75
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
76
- function fromDecoded(obj) {
77
- if (typeof obj !== "object") {
78
- throw new Error("Invalid enum object");
79
- }
80
- if ("PendingAdmin" in obj) {
81
- return new PendingAdmin();
82
- }
83
- if ("FeeCollector" in obj) {
84
- return new FeeCollector();
85
- }
86
- throw new Error("Invalid enum object");
87
- }
88
- function fromJSON(obj) {
89
- switch (obj.kind) {
90
- case "PendingAdmin": {
91
- return new PendingAdmin();
92
- }
93
- case "FeeCollector": {
94
- return new FeeCollector();
95
- }
96
- }
97
- }
98
- function layout(property) {
99
- const ret = borsh.rustEnum([
100
- borsh.struct([], "PendingAdmin"),
101
- borsh.struct([], "FeeCollector"),
102
- ]);
103
- if (property !== undefined) {
104
- return ret.replicate(property);
105
- }
106
- return ret;
107
- }
108
- //# sourceMappingURL=UpdateGlobalConfigMode.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"UpdateGlobalConfigMode.js","sourceRoot":"","sources":["../../../src/idl_codegen/types/UpdateGlobalConfigMode.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDA,kCAaC;AAED,4BAWC;AAED,wBASC;AAtFD,wDAAyC;AAMzC,MAAa,YAAY;IACvB,MAAM,CAAU,aAAa,GAAG,CAAC,CAAA;IACjC,MAAM,CAAU,IAAI,GAAG,cAAc,CAAA;IAC5B,aAAa,GAAG,CAAC,CAAA;IACjB,IAAI,GAAG,cAAc,CAAA;IAE9B,MAAM;QACJ,OAAO;YACL,IAAI,EAAE,cAAc;SACrB,CAAA;IACH,CAAC;IAED,WAAW;QACT,OAAO;YACL,YAAY,EAAE,EAAE;SACjB,CAAA;IACH,CAAC;;AAhBH,oCAiBC;AAMD,MAAa,YAAY;IACvB,MAAM,CAAU,aAAa,GAAG,CAAC,CAAA;IACjC,MAAM,CAAU,IAAI,GAAG,cAAc,CAAA;IAC5B,aAAa,GAAG,CAAC,CAAA;IACjB,IAAI,GAAG,cAAc,CAAA;IAE9B,MAAM;QACJ,OAAO;YACL,IAAI,EAAE,cAAc;SACrB,CAAA;IACH,CAAC;IAED,WAAW;QACT,OAAO;YACL,YAAY,EAAE,EAAE;SACjB,CAAA;IACH,CAAC;;AAhBH,oCAiBC;AAED,8DAA8D;AAC9D,SAAgB,WAAW,CAAC,GAAQ;IAClC,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAA;IACxC,CAAC;IAED,IAAI,cAAc,IAAI,GAAG,EAAE,CAAC;QAC1B,OAAO,IAAI,YAAY,EAAE,CAAA;IAC3B,CAAC;IACD,IAAI,cAAc,IAAI,GAAG,EAAE,CAAC;QAC1B,OAAO,IAAI,YAAY,EAAE,CAAA;IAC3B,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAA;AACxC,CAAC;AAED,SAAgB,QAAQ,CACtB,GAAqC;IAErC,QAAQ,GAAG,CAAC,IAAI,EAAE,CAAC;QACjB,KAAK,cAAc,CAAC,CAAC,CAAC;YACpB,OAAO,IAAI,YAAY,EAAE,CAAA;QAC3B,CAAC;QACD,KAAK,cAAc,CAAC,CAAC,CAAC;YACpB,OAAO,IAAI,YAAY,EAAE,CAAA;QAC3B,CAAC;IACH,CAAC;AACH,CAAC;AAED,SAAgB,MAAM,CAAC,QAAiB;IACtC,MAAM,GAAG,GAAG,KAAK,CAAC,QAAQ,CAAC;QACzB,KAAK,CAAC,MAAM,CAAC,EAAE,EAAE,cAAc,CAAC;QAChC,KAAK,CAAC,MAAM,CAAC,EAAE,EAAE,cAAc,CAAC;KACjC,CAAC,CAAA;IACF,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,OAAO,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAA;IAChC,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC"}
@@ -1,229 +0,0 @@
1
- import { struct, Layout } from '@coral-xyz/borsh';
2
- import { blobEquals, orThrow } from './utils';
3
- import { Buffer } from 'buffer';
4
-
5
- /**
6
- * An object literal specifying *all* "update mode" enum values (of type {@code M}) and their corresponding config items
7
- * (belonging to a top-level config struct {@code C}).
8
- *
9
- * An instance of this type is needed to construct a {@link ConfigUpdater}, as shown below.
10
- *
11
- * @example
12
- * ```
13
- * // Define the updater using a "map" - the line below would NOT compile if you forgot about any `StarWarsUpdateMode`:
14
- * const STAR_WARS_UPDATER = new ConfigUpdater(StarWarsUpdateMode.fromDecoded, StarWars, (config) => ({
15
- * [StarWarsUpdateMode.ANewHope.kind]: config.aNewHope,
16
- * [StarWarsUpdateMode.TheEmpireStrikesBack.kind]: config.theEmpireStrikesBack,
17
- * [StarWarsUpdateMode.ReturnOfTheJedi.kind]: config.returnOfTheJedi,
18
- * }));
19
- * ```
20
- */
21
- export type ConfigItemMap<M extends BorshEnum, C> = BorshEnumMap<M, ConfigItem<C, any> | null>;
22
-
23
- /**
24
- * A set of everything required to create an update ix for a single config item of type {@code A} belonging to a
25
- * config object of type {@code C}.
26
- */
27
- export type ConfigItem<C, A> = {
28
- readonly __layout: Layout<A>;
29
- readonly __getter: Getter<C, A>;
30
- };
31
-
32
- /**
33
- * A {@link ConfigItem} representing a borsh structure.
34
- *
35
- * Such structure may be used:
36
- * - either directly (i.e. a borsh-serialized "fat" config item, e.g. `ReserveConfig.borrowRateCurve`),
37
- * - or just to its fields (e.g. `ReserveConfig.tokenInfo.pythConfiguration.price`).
38
- */
39
- export type StructConfigItem<C, A extends Record<string, any>> = ConfigItem<C, A> & {
40
- [K in keyof A]: A[K] extends object ? StructConfigItem<C, A[K]> : ConfigItem<C, A>;
41
- };
42
-
43
- /**
44
- * A syntactic sugar allowing for auto-completion of values within {@link ConfigItemMap}.
45
- */
46
- export type AnyConfigItem<C, A> = A extends Record<string, any> ? StructConfigItem<C, A> : ConfigItem<C, A>;
47
-
48
- /**
49
- * A composite {@link ConfigItem}, allowing to encode multiple fields together.
50
- *
51
- * @example
52
- * ```
53
- * ...
54
- * [CartoonsUpdateMode.UpdateTomAndJerry.discriminator]: new CompositeConfigItem(
55
- * CARTOONS.value().characters.cats.tom,
56
- * CARTOONS.value().characters.rodents.jerry
57
- * ),
58
- * ...
59
- * ```
60
- */
61
- export class CompositeConfigItem<C> implements ConfigItem<C, Record<string, any>> {
62
- readonly __layout: Layout<Record<string, any>>;
63
- readonly __getter: Getter<C, Record<string, any>>;
64
-
65
- constructor(...components: AnyConfigItem<C, any>[]) {
66
- this.__layout = struct<any>(components.map((component, index) => component.__layout.replicate(index.toString())));
67
- this.__getter = (config) =>
68
- Object.fromEntries(components.map((component, index) => [index.toString(), component.__getter(config)]));
69
- }
70
- }
71
-
72
- /**
73
- * A constructor reference of a borsh structure.
74
- */
75
- export interface BorshStructClass<C> {
76
- new (...args: any[]): C;
77
- layout: any;
78
- }
79
-
80
- /**
81
- * A missing common type for borsh enums, which borsh should really have provided itself.
82
- */
83
- export interface BorshEnum {
84
- kind: string;
85
- }
86
-
87
- /**
88
- * A part of a {@link ConfigUpdater} responsible for a single config item.
89
- */
90
- export class ConfigItemUpdater<C, A> {
91
- constructor(private readonly item: ConfigItem<C, A>) {}
92
-
93
- /**
94
- * Returns a serialized value of the specific config item extracted from the given top-level {@code newConfig}, or
95
- * `undefined` if the value has not changed from the given {@code currentConfig}.
96
- */
97
- encodeUpdatedItemFrom(currentConfig: C | undefined, newConfig: C): Uint8Array | undefined {
98
- const getter = this.item.__getter;
99
- const newItemValue = this.encodeItem(getter(newConfig));
100
- if (currentConfig === undefined) {
101
- return newItemValue;
102
- }
103
- if (blobEquals(newItemValue, this.encodeItem(getter(currentConfig)))) {
104
- return undefined;
105
- }
106
- return newItemValue;
107
- }
108
-
109
- /**
110
- * Borsh-serializes the given value.
111
- *
112
- * Only exposed for some legacy callers which still construct the update ixs manually (in tests).
113
- */
114
- encodeItem(item: A): Uint8Array {
115
- return encodeUsingLayout(this.item.__layout, item);
116
- }
117
- }
118
-
119
- /**
120
- * A resolver of config item changes.
121
- */
122
- export class ConfigUpdater<M extends BorshEnum, C> {
123
- private readonly itemUpdaters: Map<M['kind'], [M, ConfigItemUpdater<C, any>]>;
124
-
125
- /**
126
- * A resolving constructor.
127
- *
128
- * The inputs:
129
- * - `fromDecoded`: a reference to the codegen'ed enum-decoding function, e.g. `UpdateConfigMode.fromDecoded`. Needed
130
- * to turn the `<enumClass>.kind` strings into enums (i.e. instances of `M`).
131
- * - `configClass`: a reference to the codegen'ed top-level config class, e.g. `ReserveConfig`. Need to create a
132
- * completion helper for the `itemMapBuilder`.
133
- * - `itemMapBuilder`: a function building a {@link ConfigItemMap} using the completion helper provided as its
134
- * argument, e.g. `(config) => ({[UpdateLendingMarketMode.UpdateImmutableFlag.kind]: config.immutable, ...})`.
135
- *
136
- * See the usage example at {@link ConfigItemMap}.
137
- */
138
- constructor(
139
- fromDecoded: (mode: any) => M,
140
- configClass: BorshStructClass<C>,
141
- itemMapBuilder: (config: AnyConfigItem<C, C>) => ConfigItemMap<M, C>
142
- ) {
143
- this.itemUpdaters = new Map(
144
- Object.entries(itemMapBuilder(wrap(configClass)))
145
- .filter(([_kind, item]) => item !== null)
146
- .map(([kind, item]) => [kind, [fromDecoded({ [kind]: {} }), new ConfigItemUpdater(item as ConfigItem<C, any>)]])
147
- );
148
- }
149
-
150
- /**
151
- * Returns all changes between the given current and new configs - in particular, this will be *all* supported fields'
152
- * changes if the previous config does not exist.
153
- */
154
- encodeAllUpdates(currentConfig: C | undefined, newConfig: C): EncodedConfigUpdate<M>[] {
155
- const updates: EncodedConfigUpdate<M>[] = [];
156
- for (const [mode, itemUpdater] of this.itemUpdaters.values()) {
157
- const value = itemUpdater.encodeUpdatedItemFrom(currentConfig, newConfig);
158
- if (value === undefined) {
159
- continue;
160
- }
161
- updates.push({ mode, value });
162
- }
163
- return updates;
164
- }
165
-
166
- /**
167
- * Gets an isolated updater of the given config item.
168
- */
169
- forMode(mode: M): ConfigItemUpdater<C, any> {
170
- const [_mode, itemUpdater] =
171
- this.itemUpdaters.get(mode.kind) ?? orThrow(`config item for ${mode.kind} was explicitly set to null`);
172
- return itemUpdater;
173
- }
174
- }
175
-
176
- /**
177
- * The update mode discriminator and the serialized value needed to construct an update ix.
178
- */
179
- export type EncodedConfigUpdate<M extends BorshEnum> = {
180
- mode: M;
181
- value: Uint8Array;
182
- };
183
-
184
- /**
185
- * Borsh-serializes the given value according to the given layout.
186
- *
187
- * Only exposed for some legacy callers which still construct the update ixs manually (in tests).
188
- */
189
- export function encodeUsingLayout<T>(layout: Layout<T>, value: T): Uint8Array {
190
- const buffer = Buffer.alloc(layout.span);
191
- const length = layout.encode(value, buffer, 0);
192
- if (length !== layout.span) {
193
- throw new Error(`layout span declared incorrect length ${layout.span}; got ${length}`);
194
- }
195
- return Uint8Array.from(buffer);
196
- }
197
-
198
- // Only internals below:
199
-
200
- function wrap<C>(configClass: BorshStructClass<C>): AnyConfigItem<C, C> {
201
- return withPotentialChildren({
202
- __layout: typeof configClass.layout === 'function' ? configClass.layout() : configClass.layout,
203
- __getter: (config: C) => config,
204
- } as any);
205
- }
206
-
207
- function wrapChild<C, A extends Record<string, any>>(
208
- layout: Layout<A>,
209
- parent: StructConfigItem<C, A>
210
- ): AnyConfigItem<C, any> {
211
- return withPotentialChildren({
212
- __layout: layout,
213
- __getter: (config: C) => parent.__getter(config)[layout.property!],
214
- });
215
- }
216
-
217
- function withPotentialChildren<C, A>(item: AnyConfigItem<C, A>): AnyConfigItem<C, A> {
218
- for (const fieldLayout of (item.__layout as any).fields ?? []) {
219
- const structItem = item as StructConfigItem<C, any>;
220
- structItem[fieldLayout.property] = wrapChild(fieldLayout, structItem);
221
- }
222
- return item;
223
- }
224
-
225
- type BorshEnumMap<M extends BorshEnum, T> = {
226
- [Key in M['kind']]: T;
227
- };
228
-
229
- type Getter<C, A> = (config: C) => A;
@@ -1,125 +0,0 @@
1
- import { PublicKey, Connection } from "@solana/web3.js"
2
- import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars
3
- import * as borsh from "@coral-xyz/borsh" // eslint-disable-line @typescript-eslint/no-unused-vars
4
- import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars
5
- import { PROGRAM_ID } from "../programId"
6
-
7
- export interface GlobalConfigFields {
8
- /** Global admin of the program */
9
- globalAdmin: PublicKey
10
- /** Pending admin must sign a specific transaction to become the global admin */
11
- pendingAdmin: PublicKey
12
- /** Fee collector is the only allowed owner of token accounts receiving protocol fees */
13
- feeCollector: PublicKey
14
- /** Padding to make the struct size 1024 bytes */
15
- padding: Array<number>
16
- }
17
-
18
- export interface GlobalConfigJSON {
19
- /** Global admin of the program */
20
- globalAdmin: string
21
- /** Pending admin must sign a specific transaction to become the global admin */
22
- pendingAdmin: string
23
- /** Fee collector is the only allowed owner of token accounts receiving protocol fees */
24
- feeCollector: string
25
- /** Padding to make the struct size 1024 bytes */
26
- padding: Array<number>
27
- }
28
-
29
- export class GlobalConfig {
30
- /** Global admin of the program */
31
- readonly globalAdmin: PublicKey
32
- /** Pending admin must sign a specific transaction to become the global admin */
33
- readonly pendingAdmin: PublicKey
34
- /** Fee collector is the only allowed owner of token accounts receiving protocol fees */
35
- readonly feeCollector: PublicKey
36
- /** Padding to make the struct size 1024 bytes */
37
- readonly padding: Array<number>
38
-
39
- static readonly discriminator = Buffer.from([
40
- 149, 8, 156, 202, 160, 252, 176, 217,
41
- ])
42
-
43
- static readonly layout = borsh.struct([
44
- borsh.publicKey("globalAdmin"),
45
- borsh.publicKey("pendingAdmin"),
46
- borsh.publicKey("feeCollector"),
47
- borsh.array(borsh.u8(), 928, "padding"),
48
- ])
49
-
50
- constructor(fields: GlobalConfigFields) {
51
- this.globalAdmin = fields.globalAdmin
52
- this.pendingAdmin = fields.pendingAdmin
53
- this.feeCollector = fields.feeCollector
54
- this.padding = fields.padding
55
- }
56
-
57
- static async fetch(
58
- c: Connection,
59
- address: PublicKey,
60
- programId: PublicKey = PROGRAM_ID
61
- ): Promise<GlobalConfig | null> {
62
- const info = await c.getAccountInfo(address)
63
-
64
- if (info === null) {
65
- return null
66
- }
67
- if (!info.owner.equals(programId)) {
68
- throw new Error("account doesn't belong to this program")
69
- }
70
-
71
- return this.decode(info.data)
72
- }
73
-
74
- static async fetchMultiple(
75
- c: Connection,
76
- addresses: PublicKey[],
77
- programId: PublicKey = PROGRAM_ID
78
- ): Promise<Array<GlobalConfig | null>> {
79
- const infos = await c.getMultipleAccountsInfo(addresses)
80
-
81
- return infos.map((info) => {
82
- if (info === null) {
83
- return null
84
- }
85
- if (!info.owner.equals(programId)) {
86
- throw new Error("account doesn't belong to this program")
87
- }
88
-
89
- return this.decode(info.data)
90
- })
91
- }
92
-
93
- static decode(data: Buffer): GlobalConfig {
94
- if (!data.slice(0, 8).equals(GlobalConfig.discriminator)) {
95
- throw new Error("invalid account discriminator")
96
- }
97
-
98
- const dec = GlobalConfig.layout.decode(data.slice(8))
99
-
100
- return new GlobalConfig({
101
- globalAdmin: dec.globalAdmin,
102
- pendingAdmin: dec.pendingAdmin,
103
- feeCollector: dec.feeCollector,
104
- padding: dec.padding,
105
- })
106
- }
107
-
108
- toJSON(): GlobalConfigJSON {
109
- return {
110
- globalAdmin: this.globalAdmin.toString(),
111
- pendingAdmin: this.pendingAdmin.toString(),
112
- feeCollector: this.feeCollector.toString(),
113
- padding: this.padding,
114
- }
115
- }
116
-
117
- static fromJSON(obj: GlobalConfigJSON): GlobalConfig {
118
- return new GlobalConfig({
119
- globalAdmin: new PublicKey(obj.globalAdmin),
120
- pendingAdmin: new PublicKey(obj.pendingAdmin),
121
- feeCollector: new PublicKey(obj.feeCollector),
122
- padding: obj.padding,
123
- })
124
- }
125
- }
@@ -1,30 +0,0 @@
1
- import { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars
2
- import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars
3
- import * as borsh from "@coral-xyz/borsh" // eslint-disable-line @typescript-eslint/no-unused-vars
4
- import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars
5
- import { PROGRAM_ID } from "../programId"
6
-
7
- export interface InitGlobalConfigAccounts {
8
- payer: PublicKey
9
- globalConfig: PublicKey
10
- programData: PublicKey
11
- systemProgram: PublicKey
12
- rent: PublicKey
13
- }
14
-
15
- export function initGlobalConfig(
16
- accounts: InitGlobalConfigAccounts,
17
- programId: PublicKey = PROGRAM_ID
18
- ) {
19
- const keys: Array<AccountMeta> = [
20
- { pubkey: accounts.payer, isSigner: true, isWritable: true },
21
- { pubkey: accounts.globalConfig, isSigner: false, isWritable: true },
22
- { pubkey: accounts.programData, isSigner: false, isWritable: false },
23
- { pubkey: accounts.systemProgram, isSigner: false, isWritable: false },
24
- { pubkey: accounts.rent, isSigner: false, isWritable: false },
25
- ]
26
- const identifier = Buffer.from([140, 136, 214, 48, 87, 0, 120, 255])
27
- const data = identifier
28
- const ix = new TransactionInstruction({ keys, programId, data })
29
- return ix
30
- }
@@ -1,47 +0,0 @@
1
- import { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars
2
- import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars
3
- import * as borsh from "@coral-xyz/borsh" // eslint-disable-line @typescript-eslint/no-unused-vars
4
- import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars
5
- import { PROGRAM_ID } from "../programId"
6
-
7
- export interface UpdateGlobalConfigArgs {
8
- mode: types.UpdateGlobalConfigModeKind
9
- value: Uint8Array
10
- }
11
-
12
- export interface UpdateGlobalConfigAccounts {
13
- globalAdmin: PublicKey
14
- globalConfig: PublicKey
15
- }
16
-
17
- export const layout = borsh.struct([
18
- types.UpdateGlobalConfigMode.layout("mode"),
19
- borsh.vecU8("value"),
20
- ])
21
-
22
- export function updateGlobalConfig(
23
- args: UpdateGlobalConfigArgs,
24
- accounts: UpdateGlobalConfigAccounts,
25
- programId: PublicKey = PROGRAM_ID
26
- ) {
27
- const keys: Array<AccountMeta> = [
28
- { pubkey: accounts.globalAdmin, isSigner: true, isWritable: false },
29
- { pubkey: accounts.globalConfig, isSigner: false, isWritable: true },
30
- ]
31
- const identifier = Buffer.from([164, 84, 130, 189, 111, 58, 250, 200])
32
- const buffer = Buffer.alloc(1000)
33
- const len = layout.encode(
34
- {
35
- mode: args.mode.toEncodable(),
36
- value: Buffer.from(
37
- args.value.buffer,
38
- args.value.byteOffset,
39
- args.value.length
40
- ),
41
- },
42
- buffer
43
- )
44
- const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len)
45
- const ix = new TransactionInstruction({ keys, programId, data })
46
- return ix
47
- }
@@ -1,24 +0,0 @@
1
- import { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars
2
- import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars
3
- import * as borsh from "@coral-xyz/borsh" // eslint-disable-line @typescript-eslint/no-unused-vars
4
- import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars
5
- import { PROGRAM_ID } from "../programId"
6
-
7
- export interface UpdateGlobalConfigAdminAccounts {
8
- pendingAdmin: PublicKey
9
- globalConfig: PublicKey
10
- }
11
-
12
- export function updateGlobalConfigAdmin(
13
- accounts: UpdateGlobalConfigAdminAccounts,
14
- programId: PublicKey = PROGRAM_ID
15
- ) {
16
- const keys: Array<AccountMeta> = [
17
- { pubkey: accounts.pendingAdmin, isSigner: true, isWritable: false },
18
- { pubkey: accounts.globalConfig, isSigner: false, isWritable: true },
19
- ]
20
- const identifier = Buffer.from([184, 87, 23, 193, 156, 238, 175, 119])
21
- const data = identifier
22
- const ix = new TransactionInstruction({ keys, programId, data })
23
- return ix
24
- }