@kamino-finance/klend-sdk 7.2.6 → 7.3.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.
- package/README.md +1 -0
- package/dist/@codegen/klend/accounts/LendingMarket.d.ts +33 -0
- package/dist/@codegen/klend/accounts/LendingMarket.d.ts.map +1 -1
- package/dist/@codegen/klend/accounts/LendingMarket.js +24 -2
- package/dist/@codegen/klend/accounts/LendingMarket.js.map +1 -1
- package/dist/@codegen/klend/errors/custom.d.ts +26 -2
- package/dist/@codegen/klend/errors/custom.d.ts.map +1 -1
- package/dist/@codegen/klend/errors/custom.js +45 -3
- package/dist/@codegen/klend/errors/custom.js.map +1 -1
- package/dist/@codegen/klend/instructions/index.d.ts +2 -0
- package/dist/@codegen/klend/instructions/index.d.ts.map +1 -1
- package/dist/@codegen/klend/instructions/index.js +3 -1
- package/dist/@codegen/klend/instructions/index.js.map +1 -1
- package/dist/@codegen/klend/instructions/initReserve.d.ts +1 -1
- package/dist/@codegen/klend/instructions/initReserve.d.ts.map +1 -1
- package/dist/@codegen/klend/instructions/initReserve.js +1 -5
- package/dist/@codegen/klend/instructions/initReserve.js.map +1 -1
- package/dist/@codegen/klend/instructions/liquidateObligationAndRedeemReserveCollateralV2.js +1 -1
- package/dist/@codegen/klend/instructions/seedDepositOnInitReserve.d.ts +13 -0
- package/dist/@codegen/klend/instructions/seedDepositOnInitReserve.d.ts.map +1 -0
- package/dist/@codegen/klend/instructions/seedDepositOnInitReserve.js +24 -0
- package/dist/@codegen/klend/instructions/seedDepositOnInitReserve.js.map +1 -0
- package/dist/@codegen/klend/instructions/withdrawObligationCollateral.js +1 -1
- package/dist/@codegen/klend/instructions/withdrawObligationCollateralV2.js +1 -1
- package/dist/@codegen/klend/types/ReserveConfig.d.ts +58 -24
- package/dist/@codegen/klend/types/ReserveConfig.d.ts.map +1 -1
- package/dist/@codegen/klend/types/ReserveConfig.js +40 -18
- package/dist/@codegen/klend/types/ReserveConfig.js.map +1 -1
- package/dist/@codegen/klend/types/ReserveFees.d.ts +8 -8
- package/dist/@codegen/klend/types/ReserveFees.d.ts.map +1 -1
- package/dist/@codegen/klend/types/ReserveFees.js +8 -8
- package/dist/@codegen/klend/types/ReserveFees.js.map +1 -1
- package/dist/@codegen/klend/types/UpdateConfigMode.d.ts +46 -7
- package/dist/@codegen/klend/types/UpdateConfigMode.d.ts.map +1 -1
- package/dist/@codegen/klend/types/UpdateConfigMode.js +85 -12
- package/dist/@codegen/klend/types/UpdateConfigMode.js.map +1 -1
- package/dist/@codegen/klend/types/UpdateLendingMarketMode.d.ts +26 -0
- package/dist/@codegen/klend/types/UpdateLendingMarketMode.d.ts.map +1 -1
- package/dist/@codegen/klend/types/UpdateLendingMarketMode.js +49 -1
- package/dist/@codegen/klend/types/UpdateLendingMarketMode.js.map +1 -1
- package/dist/@codegen/klend/types/index.d.ts +4 -4
- package/dist/@codegen/klend/types/index.d.ts.map +1 -1
- package/dist/@codegen/klend/types/index.js.map +1 -1
- package/dist/@codegen/kvault/accounts/GlobalConfig.d.ts +32 -0
- package/dist/@codegen/kvault/accounts/GlobalConfig.d.ts.map +1 -0
- package/dist/@codegen/kvault/accounts/GlobalConfig.js +125 -0
- package/dist/@codegen/kvault/accounts/GlobalConfig.js.map +1 -0
- package/dist/@codegen/kvault/accounts/Reserve.js +1 -1
- package/dist/@codegen/kvault/accounts/ReserveWhitelistEntry.d.ts +52 -0
- package/dist/@codegen/kvault/accounts/ReserveWhitelistEntry.d.ts.map +1 -0
- package/dist/@codegen/kvault/accounts/ReserveWhitelistEntry.js +127 -0
- package/dist/@codegen/kvault/accounts/ReserveWhitelistEntry.js.map +1 -0
- package/dist/@codegen/kvault/accounts/VaultState.d.ts +18 -0
- package/dist/@codegen/kvault/accounts/VaultState.d.ts.map +1 -1
- package/dist/@codegen/kvault/accounts/VaultState.js +39 -1
- package/dist/@codegen/kvault/accounts/VaultState.js.map +1 -1
- package/dist/@codegen/kvault/accounts/index.d.ts +4 -0
- package/dist/@codegen/kvault/accounts/index.d.ts.map +1 -1
- package/dist/@codegen/kvault/accounts/index.js +5 -1
- package/dist/@codegen/kvault/accounts/index.js.map +1 -1
- package/dist/@codegen/kvault/errors/custom.d.ts +61 -5
- package/dist/@codegen/kvault/errors/custom.d.ts.map +1 -1
- package/dist/@codegen/kvault/errors/custom.js +108 -9
- package/dist/@codegen/kvault/errors/custom.js.map +1 -1
- package/dist/@codegen/kvault/instructions/addUpdateWhitelistedReserve.d.ts +16 -0
- package/dist/@codegen/kvault/instructions/addUpdateWhitelistedReserve.d.ts.map +1 -0
- package/dist/@codegen/kvault/instructions/addUpdateWhitelistedReserve.js +66 -0
- package/dist/@codegen/kvault/instructions/addUpdateWhitelistedReserve.js.map +1 -0
- package/dist/@codegen/kvault/instructions/buy.d.ts +24 -0
- package/dist/@codegen/kvault/instructions/buy.d.ts.map +1 -0
- package/dist/@codegen/kvault/instructions/buy.js +67 -0
- package/dist/@codegen/kvault/instructions/buy.js.map +1 -0
- package/dist/@codegen/kvault/instructions/index.d.ts +12 -0
- package/dist/@codegen/kvault/instructions/index.d.ts.map +1 -1
- package/dist/@codegen/kvault/instructions/index.js +13 -1
- package/dist/@codegen/kvault/instructions/index.js.map +1 -1
- package/dist/@codegen/kvault/instructions/initGlobalConfig.d.ts +11 -0
- package/dist/@codegen/kvault/instructions/initGlobalConfig.d.ts.map +1 -0
- package/dist/@codegen/kvault/instructions/initGlobalConfig.js +20 -0
- package/dist/@codegen/kvault/instructions/initGlobalConfig.js.map +1 -0
- package/dist/@codegen/kvault/instructions/invest.d.ts +2 -1
- package/dist/@codegen/kvault/instructions/invest.d.ts.map +1 -1
- package/dist/@codegen/kvault/instructions/invest.js +5 -0
- package/dist/@codegen/kvault/instructions/invest.js.map +1 -1
- package/dist/@codegen/kvault/instructions/sell.d.ts +40 -0
- package/dist/@codegen/kvault/instructions/sell.d.ts.map +1 -0
- package/dist/@codegen/kvault/instructions/sell.js +98 -0
- package/dist/@codegen/kvault/instructions/sell.js.map +1 -0
- package/dist/@codegen/kvault/instructions/updateGlobalConfig.d.ts +13 -0
- package/dist/@codegen/kvault/instructions/updateGlobalConfig.d.ts.map +1 -0
- package/dist/@codegen/kvault/instructions/updateGlobalConfig.js +63 -0
- package/dist/@codegen/kvault/instructions/updateGlobalConfig.js.map +1 -0
- package/dist/@codegen/kvault/instructions/updateGlobalConfigAdmin.d.ts +8 -0
- package/dist/@codegen/kvault/instructions/updateGlobalConfigAdmin.d.ts.map +1 -0
- package/dist/@codegen/kvault/instructions/updateGlobalConfigAdmin.js +21 -0
- package/dist/@codegen/kvault/instructions/updateGlobalConfigAdmin.js.map +1 -0
- package/dist/@codegen/kvault/instructions/updateReserveAllocation.d.ts +2 -1
- package/dist/@codegen/kvault/instructions/updateReserveAllocation.d.ts.map +1 -1
- package/dist/@codegen/kvault/instructions/updateReserveAllocation.js +5 -0
- package/dist/@codegen/kvault/instructions/updateReserveAllocation.js.map +1 -1
- package/dist/@codegen/kvault/instructions/updateVaultConfig.d.ts +2 -1
- package/dist/@codegen/kvault/instructions/updateVaultConfig.d.ts.map +1 -1
- package/dist/@codegen/kvault/instructions/updateVaultConfig.js +2 -5
- package/dist/@codegen/kvault/instructions/updateVaultConfig.js.map +1 -1
- package/dist/@codegen/kvault/instructions/withdraw.d.ts +1 -0
- package/dist/@codegen/kvault/instructions/withdraw.d.ts.map +1 -1
- package/dist/@codegen/kvault/instructions/withdraw.js +1 -0
- package/dist/@codegen/kvault/instructions/withdraw.js.map +1 -1
- package/dist/@codegen/kvault/instructions/withdrawFromAvailable.d.ts +1 -0
- package/dist/@codegen/kvault/instructions/withdrawFromAvailable.d.ts.map +1 -1
- package/dist/@codegen/kvault/instructions/withdrawFromAvailable.js +1 -0
- package/dist/@codegen/kvault/instructions/withdrawFromAvailable.js.map +1 -1
- package/dist/@codegen/kvault/types/ReserveConfig.d.ts +27 -34
- package/dist/@codegen/kvault/types/ReserveConfig.d.ts.map +1 -1
- package/dist/@codegen/kvault/types/ReserveConfig.js +20 -17
- package/dist/@codegen/kvault/types/ReserveConfig.js.map +1 -1
- package/dist/@codegen/kvault/types/ReserveFees.d.ts +8 -8
- package/dist/@codegen/kvault/types/ReserveFees.d.ts.map +1 -1
- package/dist/@codegen/kvault/types/ReserveFees.js +8 -8
- package/dist/@codegen/kvault/types/ReserveFees.js.map +1 -1
- package/dist/@codegen/kvault/types/UpdateGlobalConfigMode.d.ts +68 -0
- package/dist/@codegen/kvault/types/UpdateGlobalConfigMode.d.ts.map +1 -0
- package/dist/@codegen/kvault/types/UpdateGlobalConfigMode.js +162 -0
- package/dist/@codegen/kvault/types/UpdateGlobalConfigMode.js.map +1 -0
- package/dist/@codegen/kvault/types/UpdateReserveWhitelistMode.d.ts +46 -0
- package/dist/@codegen/kvault/types/UpdateReserveWhitelistMode.d.ts.map +1 -0
- package/dist/@codegen/kvault/types/UpdateReserveWhitelistMode.js +124 -0
- package/dist/@codegen/kvault/types/UpdateReserveWhitelistMode.js.map +1 -0
- package/dist/@codegen/kvault/types/VaultConfigField.d.ts +65 -0
- package/dist/@codegen/kvault/types/VaultConfigField.d.ts.map +1 -1
- package/dist/@codegen/kvault/types/VaultConfigField.js +121 -1
- package/dist/@codegen/kvault/types/VaultConfigField.js.map +1 -1
- package/dist/@codegen/kvault/types/index.d.ts +10 -2
- package/dist/@codegen/kvault/types/index.d.ts.map +1 -1
- package/dist/@codegen/kvault/types/index.js +5 -1
- package/dist/@codegen/kvault/types/index.js.map +1 -1
- package/dist/classes/manager.d.ts +17 -1
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +22 -0
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/reserve.d.ts.map +1 -1
- package/dist/classes/reserve.js +7 -4
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/vault.d.ts +29 -5
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +119 -48
- package/dist/classes/vault.js.map +1 -1
- package/dist/idl/klend.json +129 -59
- package/dist/lib.d.ts +1 -0
- package/dist/lib.d.ts.map +1 -1
- package/dist/lib.js +4 -2
- package/dist/lib.js.map +1 -1
- package/dist/manager/client_kamino_manager.js +206 -15
- package/dist/manager/client_kamino_manager.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/managerTypes.d.ts +1 -1
- package/dist/utils/managerTypes.d.ts.map +1 -1
- package/dist/utils/managerTypes.js +5 -3
- package/dist/utils/managerTypes.js.map +1 -1
- package/dist/utils/parse.d.ts +10 -0
- package/dist/utils/parse.d.ts.map +1 -0
- package/dist/utils/parse.js +24 -0
- package/dist/utils/parse.js.map +1 -0
- package/dist/utils/seeds.d.ts +5 -5
- package/dist/utils/seeds.d.ts.map +1 -1
- package/dist/utils/seeds.js +13 -13
- package/dist/utils/seeds.js.map +1 -1
- package/dist/utils/vault.d.ts.map +1 -1
- package/dist/utils/vault.js +6 -0
- package/dist/utils/vault.js.map +1 -1
- package/package.json +1 -1
- package/src/@codegen/klend/accounts/LendingMarket.ts +46 -2
- package/src/@codegen/klend/errors/custom.ts +47 -2
- package/src/@codegen/klend/instructions/index.ts +2 -0
- package/src/@codegen/klend/instructions/initReserve.ts +2 -6
- package/src/@codegen/klend/instructions/liquidateObligationAndRedeemReserveCollateralV2.ts +1 -1
- package/src/@codegen/klend/instructions/seedDepositOnInitReserve.ts +50 -0
- package/src/@codegen/klend/instructions/withdrawObligationCollateral.ts +1 -1
- package/src/@codegen/klend/instructions/withdrawObligationCollateralV2.ts +1 -1
- package/src/@codegen/klend/types/ReserveConfig.ts +72 -30
- package/src/@codegen/klend/types/ReserveFees.ts +12 -12
- package/src/@codegen/klend/types/UpdateConfigMode.ts +103 -13
- package/src/@codegen/klend/types/UpdateLendingMarketMode.ts +60 -0
- package/src/@codegen/klend/types/index.ts +12 -2
- package/src/@codegen/kvault/accounts/GlobalConfig.ts +136 -0
- package/src/@codegen/kvault/accounts/Reserve.ts +1 -1
- package/src/@codegen/kvault/accounts/ReserveWhitelistEntry.ts +157 -0
- package/src/@codegen/kvault/accounts/VaultState.ts +57 -1
- package/src/@codegen/kvault/accounts/index.ts +7 -0
- package/src/@codegen/kvault/errors/custom.ts +109 -8
- package/src/@codegen/kvault/instructions/addUpdateWhitelistedReserve.ts +64 -0
- package/src/@codegen/kvault/instructions/buy.ts +74 -0
- package/src/@codegen/kvault/instructions/index.ts +18 -0
- package/src/@codegen/kvault/instructions/initGlobalConfig.ts +44 -0
- package/src/@codegen/kvault/instructions/invest.ts +4 -0
- package/src/@codegen/kvault/instructions/sell.ts +122 -0
- package/src/@codegen/kvault/instructions/updateGlobalConfig.ts +58 -0
- package/src/@codegen/kvault/instructions/updateGlobalConfigAdmin.ts +42 -0
- package/src/@codegen/kvault/instructions/updateReserveAllocation.ts +4 -0
- package/src/@codegen/kvault/instructions/updateVaultConfig.ts +4 -6
- package/src/@codegen/kvault/instructions/withdraw.ts +2 -0
- package/src/@codegen/kvault/instructions/withdrawFromAvailable.ts +2 -0
- package/src/@codegen/kvault/types/ReserveConfig.ts +34 -37
- package/src/@codegen/kvault/types/ReserveFees.ts +12 -12
- package/src/@codegen/kvault/types/UpdateGlobalConfigMode.ts +160 -0
- package/src/@codegen/kvault/types/UpdateReserveWhitelistMode.ts +117 -0
- package/src/@codegen/kvault/types/VaultConfigField.ts +150 -0
- package/src/@codegen/kvault/types/index.ts +31 -0
- package/src/classes/manager.ts +29 -1
- package/src/classes/reserve.ts +7 -5
- package/src/classes/vault.ts +166 -48
- package/src/idl/klend.json +130 -60
- package/src/idl/kvault.json +582 -23
- package/src/lib.ts +2 -1
- package/src/manager/client_kamino_manager.ts +313 -18
- package/src/utils/index.ts +2 -1
- package/src/utils/managerTypes.ts +6 -4
- package/src/utils/parse.ts +18 -0
- package/src/utils/seeds.ts +13 -17
- package/src/utils/vault.ts +6 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
import {
|
|
3
|
+
address,
|
|
4
|
+
Address,
|
|
5
|
+
fetchEncodedAccount,
|
|
6
|
+
fetchEncodedAccounts,
|
|
7
|
+
GetAccountInfoApi,
|
|
8
|
+
GetMultipleAccountsApi,
|
|
9
|
+
Rpc,
|
|
10
|
+
} from "@solana/kit"
|
|
11
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
12
|
+
import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
13
|
+
import * as borsh from "@coral-xyz/borsh" // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
14
|
+
import { borshAddress } from "../utils" // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
15
|
+
import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
16
|
+
import { PROGRAM_ID } from "../programId"
|
|
17
|
+
|
|
18
|
+
export interface GlobalConfigFields {
|
|
19
|
+
globalAdmin: Address
|
|
20
|
+
pendingAdmin: Address
|
|
21
|
+
withdrawalPenaltyLamports: BN
|
|
22
|
+
withdrawalPenaltyBps: BN
|
|
23
|
+
padding: Array<number>
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface GlobalConfigJSON {
|
|
27
|
+
globalAdmin: string
|
|
28
|
+
pendingAdmin: string
|
|
29
|
+
withdrawalPenaltyLamports: string
|
|
30
|
+
withdrawalPenaltyBps: string
|
|
31
|
+
padding: Array<number>
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export class GlobalConfig {
|
|
35
|
+
readonly globalAdmin: Address
|
|
36
|
+
readonly pendingAdmin: Address
|
|
37
|
+
readonly withdrawalPenaltyLamports: BN
|
|
38
|
+
readonly withdrawalPenaltyBps: BN
|
|
39
|
+
readonly padding: Array<number>
|
|
40
|
+
|
|
41
|
+
static readonly discriminator = Buffer.from([
|
|
42
|
+
149, 8, 156, 202, 160, 252, 176, 217,
|
|
43
|
+
])
|
|
44
|
+
|
|
45
|
+
static readonly layout = borsh.struct<GlobalConfig>([
|
|
46
|
+
borshAddress("globalAdmin"),
|
|
47
|
+
borshAddress("pendingAdmin"),
|
|
48
|
+
borsh.u64("withdrawalPenaltyLamports"),
|
|
49
|
+
borsh.u64("withdrawalPenaltyBps"),
|
|
50
|
+
borsh.array(borsh.u8(), 944, "padding"),
|
|
51
|
+
])
|
|
52
|
+
|
|
53
|
+
constructor(fields: GlobalConfigFields) {
|
|
54
|
+
this.globalAdmin = fields.globalAdmin
|
|
55
|
+
this.pendingAdmin = fields.pendingAdmin
|
|
56
|
+
this.withdrawalPenaltyLamports = fields.withdrawalPenaltyLamports
|
|
57
|
+
this.withdrawalPenaltyBps = fields.withdrawalPenaltyBps
|
|
58
|
+
this.padding = fields.padding
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static async fetch(
|
|
62
|
+
rpc: Rpc<GetAccountInfoApi>,
|
|
63
|
+
address: Address,
|
|
64
|
+
programId: Address = PROGRAM_ID
|
|
65
|
+
): Promise<GlobalConfig | null> {
|
|
66
|
+
const info = await fetchEncodedAccount(rpc, address)
|
|
67
|
+
|
|
68
|
+
if (!info.exists) {
|
|
69
|
+
return null
|
|
70
|
+
}
|
|
71
|
+
if (info.programAddress !== programId) {
|
|
72
|
+
throw new Error(
|
|
73
|
+
`KVaultGlobalConfigFields account ${address} belongs to wrong program ${info.programAddress}, expected ${programId}`
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return this.decode(Buffer.from(info.data))
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
static async fetchMultiple(
|
|
81
|
+
rpc: Rpc<GetMultipleAccountsApi>,
|
|
82
|
+
addresses: Address[],
|
|
83
|
+
programId: Address = PROGRAM_ID
|
|
84
|
+
): Promise<Array<GlobalConfig | null>> {
|
|
85
|
+
const infos = await fetchEncodedAccounts(rpc, addresses)
|
|
86
|
+
|
|
87
|
+
return infos.map((info) => {
|
|
88
|
+
if (!info.exists) {
|
|
89
|
+
return null
|
|
90
|
+
}
|
|
91
|
+
if (info.programAddress !== programId) {
|
|
92
|
+
throw new Error(
|
|
93
|
+
`GlobalConfigFields account ${info.address} belongs to wrong program ${info.programAddress}, expected ${programId}`
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return this.decode(Buffer.from(info.data))
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
static decode(data: Buffer): GlobalConfig {
|
|
102
|
+
if (!data.slice(0, 8).equals(GlobalConfig.discriminator)) {
|
|
103
|
+
throw new Error("invalid account discriminator")
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const dec = GlobalConfig.layout.decode(data.slice(8))
|
|
107
|
+
|
|
108
|
+
return new GlobalConfig({
|
|
109
|
+
globalAdmin: dec.globalAdmin,
|
|
110
|
+
pendingAdmin: dec.pendingAdmin,
|
|
111
|
+
withdrawalPenaltyLamports: dec.withdrawalPenaltyLamports,
|
|
112
|
+
withdrawalPenaltyBps: dec.withdrawalPenaltyBps,
|
|
113
|
+
padding: dec.padding,
|
|
114
|
+
})
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
toJSON(): GlobalConfigJSON {
|
|
118
|
+
return {
|
|
119
|
+
globalAdmin: this.globalAdmin,
|
|
120
|
+
pendingAdmin: this.pendingAdmin,
|
|
121
|
+
withdrawalPenaltyLamports: this.withdrawalPenaltyLamports.toString(),
|
|
122
|
+
withdrawalPenaltyBps: this.withdrawalPenaltyBps.toString(),
|
|
123
|
+
padding: this.padding,
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
static fromJSON(obj: GlobalConfigJSON): GlobalConfig {
|
|
128
|
+
return new GlobalConfig({
|
|
129
|
+
globalAdmin: address(obj.globalAdmin),
|
|
130
|
+
pendingAdmin: address(obj.pendingAdmin),
|
|
131
|
+
withdrawalPenaltyLamports: new BN(obj.withdrawalPenaltyLamports),
|
|
132
|
+
withdrawalPenaltyBps: new BN(obj.withdrawalPenaltyBps),
|
|
133
|
+
padding: obj.padding,
|
|
134
|
+
})
|
|
135
|
+
}
|
|
136
|
+
}
|
|
@@ -110,7 +110,7 @@ export class Reserve {
|
|
|
110
110
|
types.ReserveCollateral.layout("collateral"),
|
|
111
111
|
borsh.array(borsh.u64(), 150, "reserveCollateralPadding"),
|
|
112
112
|
types.ReserveConfig.layout("config"),
|
|
113
|
-
borsh.array(borsh.u64(),
|
|
113
|
+
borsh.array(borsh.u64(), 116, "configPadding"),
|
|
114
114
|
borsh.u64("borrowedAmountOutsideElevationGroup"),
|
|
115
115
|
borsh.array(
|
|
116
116
|
borsh.u64(),
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
import {
|
|
3
|
+
address,
|
|
4
|
+
Address,
|
|
5
|
+
fetchEncodedAccount,
|
|
6
|
+
fetchEncodedAccounts,
|
|
7
|
+
GetAccountInfoApi,
|
|
8
|
+
GetMultipleAccountsApi,
|
|
9
|
+
Rpc,
|
|
10
|
+
} from "@solana/kit"
|
|
11
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
12
|
+
import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
13
|
+
import * as borsh from "@coral-xyz/borsh" // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
14
|
+
import { borshAddress } from "../utils" // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
15
|
+
import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
16
|
+
import { PROGRAM_ID } from "../programId"
|
|
17
|
+
|
|
18
|
+
export interface ReserveWhitelistEntryFields {
|
|
19
|
+
/**
|
|
20
|
+
* The token mint is stored to solve the problem of finding all the whitelisted reserves for a particular token mint:
|
|
21
|
+
* when storing the token mint inside the PDA, finding all the whitelisted reserves becomes a `getProgramAccounts` with
|
|
22
|
+
* a filter on discriminator + the mint field
|
|
23
|
+
* The reserve pubkey, as seed of the reserve whitelist PDA account, it stored so you can link back the PDA to its seeds
|
|
24
|
+
* (for instance, in the operation above we easily find the reserve corresponding to the PDA)
|
|
25
|
+
*/
|
|
26
|
+
tokenMint: Address
|
|
27
|
+
reserve: Address
|
|
28
|
+
whitelistAddAllocation: number
|
|
29
|
+
whitelistInvest: number
|
|
30
|
+
padding: Array<number>
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface ReserveWhitelistEntryJSON {
|
|
34
|
+
/**
|
|
35
|
+
* The token mint is stored to solve the problem of finding all the whitelisted reserves for a particular token mint:
|
|
36
|
+
* when storing the token mint inside the PDA, finding all the whitelisted reserves becomes a `getProgramAccounts` with
|
|
37
|
+
* a filter on discriminator + the mint field
|
|
38
|
+
* The reserve pubkey, as seed of the reserve whitelist PDA account, it stored so you can link back the PDA to its seeds
|
|
39
|
+
* (for instance, in the operation above we easily find the reserve corresponding to the PDA)
|
|
40
|
+
*/
|
|
41
|
+
tokenMint: string
|
|
42
|
+
reserve: string
|
|
43
|
+
whitelistAddAllocation: number
|
|
44
|
+
whitelistInvest: number
|
|
45
|
+
padding: Array<number>
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export class ReserveWhitelistEntry {
|
|
49
|
+
/**
|
|
50
|
+
* The token mint is stored to solve the problem of finding all the whitelisted reserves for a particular token mint:
|
|
51
|
+
* when storing the token mint inside the PDA, finding all the whitelisted reserves becomes a `getProgramAccounts` with
|
|
52
|
+
* a filter on discriminator + the mint field
|
|
53
|
+
* The reserve pubkey, as seed of the reserve whitelist PDA account, it stored so you can link back the PDA to its seeds
|
|
54
|
+
* (for instance, in the operation above we easily find the reserve corresponding to the PDA)
|
|
55
|
+
*/
|
|
56
|
+
readonly tokenMint: Address
|
|
57
|
+
readonly reserve: Address
|
|
58
|
+
readonly whitelistAddAllocation: number
|
|
59
|
+
readonly whitelistInvest: number
|
|
60
|
+
readonly padding: Array<number>
|
|
61
|
+
|
|
62
|
+
static readonly discriminator = Buffer.from([
|
|
63
|
+
135, 130, 156, 210, 58, 58, 91, 170,
|
|
64
|
+
])
|
|
65
|
+
|
|
66
|
+
static readonly layout = borsh.struct<ReserveWhitelistEntry>([
|
|
67
|
+
borshAddress("tokenMint"),
|
|
68
|
+
borshAddress("reserve"),
|
|
69
|
+
borsh.u8("whitelistAddAllocation"),
|
|
70
|
+
borsh.u8("whitelistInvest"),
|
|
71
|
+
borsh.array(borsh.u8(), 62, "padding"),
|
|
72
|
+
])
|
|
73
|
+
|
|
74
|
+
constructor(fields: ReserveWhitelistEntryFields) {
|
|
75
|
+
this.tokenMint = fields.tokenMint
|
|
76
|
+
this.reserve = fields.reserve
|
|
77
|
+
this.whitelistAddAllocation = fields.whitelistAddAllocation
|
|
78
|
+
this.whitelistInvest = fields.whitelistInvest
|
|
79
|
+
this.padding = fields.padding
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
static async fetch(
|
|
83
|
+
rpc: Rpc<GetAccountInfoApi>,
|
|
84
|
+
address: Address,
|
|
85
|
+
programId: Address = PROGRAM_ID
|
|
86
|
+
): Promise<ReserveWhitelistEntry | null> {
|
|
87
|
+
const info = await fetchEncodedAccount(rpc, address)
|
|
88
|
+
|
|
89
|
+
if (!info.exists) {
|
|
90
|
+
return null
|
|
91
|
+
}
|
|
92
|
+
if (info.programAddress !== programId) {
|
|
93
|
+
throw new Error(
|
|
94
|
+
`ReserveWhitelistEntryFields account ${address} belongs to wrong program ${info.programAddress}, expected ${programId}`
|
|
95
|
+
)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return this.decode(Buffer.from(info.data))
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
static async fetchMultiple(
|
|
102
|
+
rpc: Rpc<GetMultipleAccountsApi>,
|
|
103
|
+
addresses: Address[],
|
|
104
|
+
programId: Address = PROGRAM_ID
|
|
105
|
+
): Promise<Array<ReserveWhitelistEntry | null>> {
|
|
106
|
+
const infos = await fetchEncodedAccounts(rpc, addresses)
|
|
107
|
+
|
|
108
|
+
return infos.map((info) => {
|
|
109
|
+
if (!info.exists) {
|
|
110
|
+
return null
|
|
111
|
+
}
|
|
112
|
+
if (info.programAddress !== programId) {
|
|
113
|
+
throw new Error(
|
|
114
|
+
`ReserveWhitelistEntryFields account ${info.address} belongs to wrong program ${info.programAddress}, expected ${programId}`
|
|
115
|
+
)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return this.decode(Buffer.from(info.data))
|
|
119
|
+
})
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
static decode(data: Buffer): ReserveWhitelistEntry {
|
|
123
|
+
if (!data.slice(0, 8).equals(ReserveWhitelistEntry.discriminator)) {
|
|
124
|
+
throw new Error("invalid account discriminator")
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const dec = ReserveWhitelistEntry.layout.decode(data.slice(8))
|
|
128
|
+
|
|
129
|
+
return new ReserveWhitelistEntry({
|
|
130
|
+
tokenMint: dec.tokenMint,
|
|
131
|
+
reserve: dec.reserve,
|
|
132
|
+
whitelistAddAllocation: dec.whitelistAddAllocation,
|
|
133
|
+
whitelistInvest: dec.whitelistInvest,
|
|
134
|
+
padding: dec.padding,
|
|
135
|
+
})
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
toJSON(): ReserveWhitelistEntryJSON {
|
|
139
|
+
return {
|
|
140
|
+
tokenMint: this.tokenMint,
|
|
141
|
+
reserve: this.reserve,
|
|
142
|
+
whitelistAddAllocation: this.whitelistAddAllocation,
|
|
143
|
+
whitelistInvest: this.whitelistInvest,
|
|
144
|
+
padding: this.padding,
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
static fromJSON(obj: ReserveWhitelistEntryJSON): ReserveWhitelistEntry {
|
|
149
|
+
return new ReserveWhitelistEntry({
|
|
150
|
+
tokenMint: address(obj.tokenMint),
|
|
151
|
+
reserve: address(obj.reserve),
|
|
152
|
+
whitelistAddAllocation: obj.whitelistAddAllocation,
|
|
153
|
+
whitelistInvest: obj.whitelistInvest,
|
|
154
|
+
padding: obj.padding,
|
|
155
|
+
})
|
|
156
|
+
}
|
|
157
|
+
}
|
|
@@ -51,6 +51,12 @@ export interface VaultStateFields {
|
|
|
51
51
|
creationTimestamp: BN
|
|
52
52
|
unallocatedTokensCap: BN
|
|
53
53
|
allocationAdmin: Address
|
|
54
|
+
withdrawalPenaltyLamports: BN
|
|
55
|
+
withdrawalPenaltyBps: BN
|
|
56
|
+
firstLossCapitalFarm: Address
|
|
57
|
+
allowAllocationsInWhitelistedReservesOnly: number
|
|
58
|
+
allowInvestInWhitelistedReservesOnly: number
|
|
59
|
+
padding4: Array<number>
|
|
54
60
|
padding3: Array<BN>
|
|
55
61
|
}
|
|
56
62
|
|
|
@@ -90,6 +96,12 @@ export interface VaultStateJSON {
|
|
|
90
96
|
creationTimestamp: string
|
|
91
97
|
unallocatedTokensCap: string
|
|
92
98
|
allocationAdmin: string
|
|
99
|
+
withdrawalPenaltyLamports: string
|
|
100
|
+
withdrawalPenaltyBps: string
|
|
101
|
+
firstLossCapitalFarm: string
|
|
102
|
+
allowAllocationsInWhitelistedReservesOnly: number
|
|
103
|
+
allowInvestInWhitelistedReservesOnly: number
|
|
104
|
+
padding4: Array<number>
|
|
93
105
|
padding3: Array<string>
|
|
94
106
|
}
|
|
95
107
|
|
|
@@ -129,6 +141,12 @@ export class VaultState {
|
|
|
129
141
|
readonly creationTimestamp: BN
|
|
130
142
|
readonly unallocatedTokensCap: BN
|
|
131
143
|
readonly allocationAdmin: Address
|
|
144
|
+
readonly withdrawalPenaltyLamports: BN
|
|
145
|
+
readonly withdrawalPenaltyBps: BN
|
|
146
|
+
readonly firstLossCapitalFarm: Address
|
|
147
|
+
readonly allowAllocationsInWhitelistedReservesOnly: number
|
|
148
|
+
readonly allowInvestInWhitelistedReservesOnly: number
|
|
149
|
+
readonly padding4: Array<number>
|
|
132
150
|
readonly padding3: Array<BN>
|
|
133
151
|
|
|
134
152
|
static readonly discriminator = Buffer.from([
|
|
@@ -171,7 +189,13 @@ export class VaultState {
|
|
|
171
189
|
borsh.u64("creationTimestamp"),
|
|
172
190
|
borsh.u64("unallocatedTokensCap"),
|
|
173
191
|
borshAddress("allocationAdmin"),
|
|
174
|
-
borsh.
|
|
192
|
+
borsh.u64("withdrawalPenaltyLamports"),
|
|
193
|
+
borsh.u64("withdrawalPenaltyBps"),
|
|
194
|
+
borshAddress("firstLossCapitalFarm"),
|
|
195
|
+
borsh.u8("allowAllocationsInWhitelistedReservesOnly"),
|
|
196
|
+
borsh.u8("allowInvestInWhitelistedReservesOnly"),
|
|
197
|
+
borsh.array(borsh.u8(), 14, "padding4"),
|
|
198
|
+
borsh.array(borsh.u128(), 238, "padding3"),
|
|
175
199
|
])
|
|
176
200
|
|
|
177
201
|
constructor(fields: VaultStateFields) {
|
|
@@ -212,6 +236,14 @@ export class VaultState {
|
|
|
212
236
|
this.creationTimestamp = fields.creationTimestamp
|
|
213
237
|
this.unallocatedTokensCap = fields.unallocatedTokensCap
|
|
214
238
|
this.allocationAdmin = fields.allocationAdmin
|
|
239
|
+
this.withdrawalPenaltyLamports = fields.withdrawalPenaltyLamports
|
|
240
|
+
this.withdrawalPenaltyBps = fields.withdrawalPenaltyBps
|
|
241
|
+
this.firstLossCapitalFarm = fields.firstLossCapitalFarm
|
|
242
|
+
this.allowAllocationsInWhitelistedReservesOnly =
|
|
243
|
+
fields.allowAllocationsInWhitelistedReservesOnly
|
|
244
|
+
this.allowInvestInWhitelistedReservesOnly =
|
|
245
|
+
fields.allowInvestInWhitelistedReservesOnly
|
|
246
|
+
this.padding4 = fields.padding4
|
|
215
247
|
this.padding3 = fields.padding3
|
|
216
248
|
}
|
|
217
249
|
|
|
@@ -302,6 +334,14 @@ export class VaultState {
|
|
|
302
334
|
creationTimestamp: dec.creationTimestamp,
|
|
303
335
|
unallocatedTokensCap: dec.unallocatedTokensCap,
|
|
304
336
|
allocationAdmin: dec.allocationAdmin,
|
|
337
|
+
withdrawalPenaltyLamports: dec.withdrawalPenaltyLamports,
|
|
338
|
+
withdrawalPenaltyBps: dec.withdrawalPenaltyBps,
|
|
339
|
+
firstLossCapitalFarm: dec.firstLossCapitalFarm,
|
|
340
|
+
allowAllocationsInWhitelistedReservesOnly:
|
|
341
|
+
dec.allowAllocationsInWhitelistedReservesOnly,
|
|
342
|
+
allowInvestInWhitelistedReservesOnly:
|
|
343
|
+
dec.allowInvestInWhitelistedReservesOnly,
|
|
344
|
+
padding4: dec.padding4,
|
|
305
345
|
padding3: dec.padding3,
|
|
306
346
|
})
|
|
307
347
|
}
|
|
@@ -345,6 +385,14 @@ export class VaultState {
|
|
|
345
385
|
creationTimestamp: this.creationTimestamp.toString(),
|
|
346
386
|
unallocatedTokensCap: this.unallocatedTokensCap.toString(),
|
|
347
387
|
allocationAdmin: this.allocationAdmin,
|
|
388
|
+
withdrawalPenaltyLamports: this.withdrawalPenaltyLamports.toString(),
|
|
389
|
+
withdrawalPenaltyBps: this.withdrawalPenaltyBps.toString(),
|
|
390
|
+
firstLossCapitalFarm: this.firstLossCapitalFarm,
|
|
391
|
+
allowAllocationsInWhitelistedReservesOnly:
|
|
392
|
+
this.allowAllocationsInWhitelistedReservesOnly,
|
|
393
|
+
allowInvestInWhitelistedReservesOnly:
|
|
394
|
+
this.allowInvestInWhitelistedReservesOnly,
|
|
395
|
+
padding4: this.padding4,
|
|
348
396
|
padding3: this.padding3.map((item) => item.toString()),
|
|
349
397
|
}
|
|
350
398
|
}
|
|
@@ -388,6 +436,14 @@ export class VaultState {
|
|
|
388
436
|
creationTimestamp: new BN(obj.creationTimestamp),
|
|
389
437
|
unallocatedTokensCap: new BN(obj.unallocatedTokensCap),
|
|
390
438
|
allocationAdmin: address(obj.allocationAdmin),
|
|
439
|
+
withdrawalPenaltyLamports: new BN(obj.withdrawalPenaltyLamports),
|
|
440
|
+
withdrawalPenaltyBps: new BN(obj.withdrawalPenaltyBps),
|
|
441
|
+
firstLossCapitalFarm: address(obj.firstLossCapitalFarm),
|
|
442
|
+
allowAllocationsInWhitelistedReservesOnly:
|
|
443
|
+
obj.allowAllocationsInWhitelistedReservesOnly,
|
|
444
|
+
allowInvestInWhitelistedReservesOnly:
|
|
445
|
+
obj.allowInvestInWhitelistedReservesOnly,
|
|
446
|
+
padding4: obj.padding4,
|
|
391
447
|
padding3: obj.padding3.map((item) => new BN(item)),
|
|
392
448
|
})
|
|
393
449
|
}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
export { Reserve } from "./Reserve"
|
|
2
2
|
export type { ReserveFields, ReserveJSON } from "./Reserve"
|
|
3
|
+
export { GlobalConfig } from "./GlobalConfig"
|
|
4
|
+
export type { GlobalConfigFields, GlobalConfigJSON } from "./GlobalConfig"
|
|
5
|
+
export { ReserveWhitelistEntry } from "./ReserveWhitelistEntry"
|
|
6
|
+
export type {
|
|
7
|
+
ReserveWhitelistEntryFields,
|
|
8
|
+
ReserveWhitelistEntryJSON,
|
|
9
|
+
} from "./ReserveWhitelistEntry"
|
|
3
10
|
export { VaultState } from "./VaultState"
|
|
4
11
|
export type { VaultStateFields, VaultStateJSON } from "./VaultState"
|
|
@@ -48,15 +48,22 @@ export type CustomError =
|
|
|
48
48
|
| WrongAdminOrAllocationAdmin
|
|
49
49
|
| ReserveHasNonZeroAllocationOrCTokens
|
|
50
50
|
| DepositAmountGreaterThanRequestedAmount
|
|
51
|
+
| WithdrawAmountLessThanWithdrawalPenalty
|
|
52
|
+
| CannotWithdrawZeroLamports
|
|
53
|
+
| NoUpgradeAuthority
|
|
54
|
+
| WithdrawalFeeBPSGreaterThanMaxAllowed
|
|
55
|
+
| WithdrawalFeeLamportsGreaterThanMaxAllowed
|
|
56
|
+
| ReserveNotWhitelisted
|
|
57
|
+
| InvalidBoolLikeValue
|
|
51
58
|
|
|
52
59
|
export class DepositAmountsZero extends Error {
|
|
53
60
|
static readonly code = 7000
|
|
54
61
|
readonly code = 7000
|
|
55
62
|
readonly name = "DepositAmountsZero"
|
|
56
|
-
readonly msg = "
|
|
63
|
+
readonly msg = "Cannot deposit zero tokens"
|
|
57
64
|
|
|
58
65
|
constructor(readonly logs?: string[]) {
|
|
59
|
-
super("7000:
|
|
66
|
+
super("7000: Cannot deposit zero tokens")
|
|
60
67
|
}
|
|
61
68
|
}
|
|
62
69
|
|
|
@@ -64,10 +71,10 @@ export class SharesIssuedAmountDoesNotMatch extends Error {
|
|
|
64
71
|
static readonly code = 7001
|
|
65
72
|
readonly code = 7001
|
|
66
73
|
readonly name = "SharesIssuedAmountDoesNotMatch"
|
|
67
|
-
readonly msg = "
|
|
74
|
+
readonly msg = "Post check failed on share issued"
|
|
68
75
|
|
|
69
76
|
constructor(readonly logs?: string[]) {
|
|
70
|
-
super("7001:
|
|
77
|
+
super("7001: Post check failed on share issued")
|
|
71
78
|
}
|
|
72
79
|
}
|
|
73
80
|
|
|
@@ -75,10 +82,10 @@ export class MathOverflow extends Error {
|
|
|
75
82
|
static readonly code = 7002
|
|
76
83
|
readonly code = 7002
|
|
77
84
|
readonly name = "MathOverflow"
|
|
78
|
-
readonly msg = "
|
|
85
|
+
readonly msg = "Math operation overflowed"
|
|
79
86
|
|
|
80
87
|
constructor(readonly logs?: string[]) {
|
|
81
|
-
super("7002:
|
|
88
|
+
super("7002: Math operation overflowed")
|
|
82
89
|
}
|
|
83
90
|
}
|
|
84
91
|
|
|
@@ -86,10 +93,10 @@ export class IntegerOverflow extends Error {
|
|
|
86
93
|
static readonly code = 7003
|
|
87
94
|
readonly code = 7003
|
|
88
95
|
readonly name = "IntegerOverflow"
|
|
89
|
-
readonly msg = "
|
|
96
|
+
readonly msg = "Integer conversion overflowed"
|
|
90
97
|
|
|
91
98
|
constructor(readonly logs?: string[]) {
|
|
92
|
-
super("7003:
|
|
99
|
+
super("7003: Integer conversion overflowed")
|
|
93
100
|
}
|
|
94
101
|
}
|
|
95
102
|
|
|
@@ -591,6 +598,86 @@ export class DepositAmountGreaterThanRequestedAmount extends Error {
|
|
|
591
598
|
}
|
|
592
599
|
}
|
|
593
600
|
|
|
601
|
+
export class WithdrawAmountLessThanWithdrawalPenalty extends Error {
|
|
602
|
+
static readonly code = 7049
|
|
603
|
+
readonly code = 7049
|
|
604
|
+
readonly name = "WithdrawAmountLessThanWithdrawalPenalty"
|
|
605
|
+
readonly msg = "Withdraw amount is less than withdrawal penalty"
|
|
606
|
+
|
|
607
|
+
constructor(readonly logs?: string[]) {
|
|
608
|
+
super("7049: Withdraw amount is less than withdrawal penalty")
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
export class CannotWithdrawZeroLamports extends Error {
|
|
613
|
+
static readonly code = 7050
|
|
614
|
+
readonly code = 7050
|
|
615
|
+
readonly name = "CannotWithdrawZeroLamports"
|
|
616
|
+
readonly msg = "Cannot withdraw 0 lamports"
|
|
617
|
+
|
|
618
|
+
constructor(readonly logs?: string[]) {
|
|
619
|
+
super("7050: Cannot withdraw 0 lamports")
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
export class NoUpgradeAuthority extends Error {
|
|
624
|
+
static readonly code = 7051
|
|
625
|
+
readonly code = 7051
|
|
626
|
+
readonly name = "NoUpgradeAuthority"
|
|
627
|
+
readonly msg =
|
|
628
|
+
"Cannot initialize global config because there is no upgrade authority to the program"
|
|
629
|
+
|
|
630
|
+
constructor(readonly logs?: string[]) {
|
|
631
|
+
super(
|
|
632
|
+
"7051: Cannot initialize global config because there is no upgrade authority to the program"
|
|
633
|
+
)
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
export class WithdrawalFeeBPSGreaterThanMaxAllowed extends Error {
|
|
638
|
+
static readonly code = 7052
|
|
639
|
+
readonly code = 7052
|
|
640
|
+
readonly name = "WithdrawalFeeBPSGreaterThanMaxAllowed"
|
|
641
|
+
readonly msg = "Withdrawal fee BPS is greater than maximum allowed"
|
|
642
|
+
|
|
643
|
+
constructor(readonly logs?: string[]) {
|
|
644
|
+
super("7052: Withdrawal fee BPS is greater than maximum allowed")
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
export class WithdrawalFeeLamportsGreaterThanMaxAllowed extends Error {
|
|
649
|
+
static readonly code = 7053
|
|
650
|
+
readonly code = 7053
|
|
651
|
+
readonly name = "WithdrawalFeeLamportsGreaterThanMaxAllowed"
|
|
652
|
+
readonly msg = "Withdrawal fee lamports is greater than maximum allowed"
|
|
653
|
+
|
|
654
|
+
constructor(readonly logs?: string[]) {
|
|
655
|
+
super("7053: Withdrawal fee lamports is greater than maximum allowed")
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
export class ReserveNotWhitelisted extends Error {
|
|
660
|
+
static readonly code = 7054
|
|
661
|
+
readonly code = 7054
|
|
662
|
+
readonly name = "ReserveNotWhitelisted"
|
|
663
|
+
readonly msg = "Reserve is not whitelisted"
|
|
664
|
+
|
|
665
|
+
constructor(readonly logs?: string[]) {
|
|
666
|
+
super("7054: Reserve is not whitelisted")
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
export class InvalidBoolLikeValue extends Error {
|
|
671
|
+
static readonly code = 7055
|
|
672
|
+
readonly code = 7055
|
|
673
|
+
readonly name = "InvalidBoolLikeValue"
|
|
674
|
+
readonly msg = "Invalid bool-like value passed in (should be 0 or 1)"
|
|
675
|
+
|
|
676
|
+
constructor(readonly logs?: string[]) {
|
|
677
|
+
super("7055: Invalid bool-like value passed in (should be 0 or 1)")
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
|
|
594
681
|
export function fromCode(code: number, logs?: string[]): CustomError | null {
|
|
595
682
|
switch (code) {
|
|
596
683
|
case 7000:
|
|
@@ -691,6 +778,20 @@ export function fromCode(code: number, logs?: string[]): CustomError | null {
|
|
|
691
778
|
return new ReserveHasNonZeroAllocationOrCTokens(logs)
|
|
692
779
|
case 7048:
|
|
693
780
|
return new DepositAmountGreaterThanRequestedAmount(logs)
|
|
781
|
+
case 7049:
|
|
782
|
+
return new WithdrawAmountLessThanWithdrawalPenalty(logs)
|
|
783
|
+
case 7050:
|
|
784
|
+
return new CannotWithdrawZeroLamports(logs)
|
|
785
|
+
case 7051:
|
|
786
|
+
return new NoUpgradeAuthority(logs)
|
|
787
|
+
case 7052:
|
|
788
|
+
return new WithdrawalFeeBPSGreaterThanMaxAllowed(logs)
|
|
789
|
+
case 7053:
|
|
790
|
+
return new WithdrawalFeeLamportsGreaterThanMaxAllowed(logs)
|
|
791
|
+
case 7054:
|
|
792
|
+
return new ReserveNotWhitelisted(logs)
|
|
793
|
+
case 7055:
|
|
794
|
+
return new InvalidBoolLikeValue(logs)
|
|
694
795
|
}
|
|
695
796
|
|
|
696
797
|
return null
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
import {
|
|
3
|
+
Address,
|
|
4
|
+
isSome,
|
|
5
|
+
AccountMeta,
|
|
6
|
+
AccountSignerMeta,
|
|
7
|
+
Instruction,
|
|
8
|
+
Option,
|
|
9
|
+
TransactionSigner,
|
|
10
|
+
} from "@solana/kit"
|
|
11
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
12
|
+
import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
13
|
+
import * as borsh from "@coral-xyz/borsh" // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
14
|
+
import { borshAddress } from "../utils" // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
15
|
+
import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
16
|
+
import { PROGRAM_ID } from "../programId"
|
|
17
|
+
|
|
18
|
+
export const DISCRIMINATOR = Buffer.from([219, 139, 95, 204, 7, 183, 118, 45])
|
|
19
|
+
|
|
20
|
+
export interface AddUpdateWhitelistedReserveArgs {
|
|
21
|
+
update: types.UpdateReserveWhitelistModeKind
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface AddUpdateWhitelistedReserveAccounts {
|
|
25
|
+
globalAdmin: TransactionSigner
|
|
26
|
+
globalConfig: Address
|
|
27
|
+
reserve: Address
|
|
28
|
+
reserveWhitelistEntry: Address
|
|
29
|
+
systemProgram: Address
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const layout = borsh.struct([
|
|
33
|
+
types.UpdateReserveWhitelistMode.layout("update"),
|
|
34
|
+
])
|
|
35
|
+
|
|
36
|
+
export function addUpdateWhitelistedReserve(
|
|
37
|
+
args: AddUpdateWhitelistedReserveArgs,
|
|
38
|
+
accounts: AddUpdateWhitelistedReserveAccounts,
|
|
39
|
+
remainingAccounts: Array<AccountMeta | AccountSignerMeta> = [],
|
|
40
|
+
programAddress: Address = PROGRAM_ID
|
|
41
|
+
) {
|
|
42
|
+
const keys: Array<AccountMeta | AccountSignerMeta> = [
|
|
43
|
+
{
|
|
44
|
+
address: accounts.globalAdmin.address,
|
|
45
|
+
role: 3,
|
|
46
|
+
signer: accounts.globalAdmin,
|
|
47
|
+
},
|
|
48
|
+
{ address: accounts.globalConfig, role: 0 },
|
|
49
|
+
{ address: accounts.reserve, role: 0 },
|
|
50
|
+
{ address: accounts.reserveWhitelistEntry, role: 1 },
|
|
51
|
+
{ address: accounts.systemProgram, role: 0 },
|
|
52
|
+
...remainingAccounts,
|
|
53
|
+
]
|
|
54
|
+
const buffer = Buffer.alloc(1000)
|
|
55
|
+
const len = layout.encode(
|
|
56
|
+
{
|
|
57
|
+
update: args.update.toEncodable(),
|
|
58
|
+
},
|
|
59
|
+
buffer
|
|
60
|
+
)
|
|
61
|
+
const data = Buffer.concat([DISCRIMINATOR, buffer]).slice(0, 8 + len)
|
|
62
|
+
const ix: Instruction = { accounts: keys, programAddress, data }
|
|
63
|
+
return ix
|
|
64
|
+
}
|