@kamino-finance/klend-sdk 5.13.20 → 5.13.21-beta.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/dist/classes/configItems.d.ts +166 -0
- package/dist/classes/configItems.d.ts.map +1 -0
- package/dist/classes/configItems.js +202 -0
- package/dist/classes/configItems.js.map +1 -0
- package/dist/classes/farm_utils.d.ts.map +1 -1
- package/dist/classes/farm_utils.js +3 -10
- package/dist/classes/farm_utils.js.map +1 -1
- package/dist/classes/manager.d.ts +5 -8
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +39 -294
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/obligation.d.ts.map +1 -1
- package/dist/classes/obligation.js +14 -0
- package/dist/classes/obligation.js.map +1 -1
- package/dist/classes/reserve.d.ts +5 -14
- package/dist/classes/reserve.d.ts.map +1 -1
- package/dist/classes/reserve.js +91 -463
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/utils.d.ts +1 -0
- package/dist/classes/utils.d.ts.map +1 -1
- package/dist/classes/utils.js +12 -0
- package/dist/classes/utils.js.map +1 -1
- package/dist/classes/vault.d.ts +1 -1
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +5 -6
- package/dist/classes/vault.js.map +1 -1
- package/dist/client_kamino_manager.d.ts.map +1 -1
- package/dist/client_kamino_manager.js +27 -26
- package/dist/client_kamino_manager.js.map +1 -1
- package/dist/idl.json +186 -9
- package/dist/idl_codegen/accounts/GlobalConfig.d.ts +40 -0
- package/dist/idl_codegen/accounts/GlobalConfig.d.ts.map +1 -0
- package/dist/idl_codegen/accounts/GlobalConfig.js +116 -0
- package/dist/idl_codegen/accounts/GlobalConfig.js.map +1 -0
- package/dist/idl_codegen/accounts/LendingMarket.d.ts +24 -3
- package/dist/idl_codegen/accounts/LendingMarket.d.ts.map +1 -1
- package/dist/idl_codegen/accounts/LendingMarket.js +25 -7
- package/dist/idl_codegen/accounts/LendingMarket.js.map +1 -1
- package/dist/idl_codegen/accounts/index.d.ts +2 -0
- package/dist/idl_codegen/accounts/index.d.ts.map +1 -1
- package/dist/idl_codegen/accounts/index.js +3 -1
- package/dist/idl_codegen/accounts/index.js.map +1 -1
- package/dist/idl_codegen/errors/custom.d.ts +25 -1
- package/dist/idl_codegen/errors/custom.d.ts.map +1 -1
- package/dist/idl_codegen/errors/custom.js +43 -1
- package/dist/idl_codegen/errors/custom.js.map +1 -1
- package/dist/idl_codegen/instructions/idlMissingTypes.d.ts +2 -1
- package/dist/idl_codegen/instructions/idlMissingTypes.d.ts.map +1 -1
- package/dist/idl_codegen/instructions/idlMissingTypes.js +2 -1
- package/dist/idl_codegen/instructions/idlMissingTypes.js.map +1 -1
- package/dist/idl_codegen/instructions/index.d.ts +6 -0
- package/dist/idl_codegen/instructions/index.d.ts.map +1 -1
- package/dist/idl_codegen/instructions/index.js +7 -1
- package/dist/idl_codegen/instructions/index.js.map +1 -1
- package/dist/idl_codegen/instructions/initGlobalConfig.d.ts +10 -0
- package/dist/idl_codegen/instructions/initGlobalConfig.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/initGlobalConfig.js +19 -0
- package/dist/idl_codegen/instructions/initGlobalConfig.js.map +1 -0
- package/dist/idl_codegen/instructions/updateGlobalConfig.d.ts +13 -0
- package/dist/idl_codegen/instructions/updateGlobalConfig.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/updateGlobalConfig.js +61 -0
- package/dist/idl_codegen/instructions/updateGlobalConfig.js.map +1 -0
- package/dist/idl_codegen/instructions/updateGlobalConfigAdmin.d.ts +7 -0
- package/dist/idl_codegen/instructions/updateGlobalConfigAdmin.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/updateGlobalConfigAdmin.js +16 -0
- package/dist/idl_codegen/instructions/updateGlobalConfigAdmin.js.map +1 -0
- package/dist/idl_codegen/instructions/updateReserveConfig.d.ts +4 -3
- package/dist/idl_codegen/instructions/updateReserveConfig.d.ts.map +1 -1
- package/dist/idl_codegen/instructions/updateReserveConfig.js +5 -3
- package/dist/idl_codegen/instructions/updateReserveConfig.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawProtocolFee.d.ts +2 -2
- package/dist/idl_codegen/instructions/withdrawProtocolFee.d.ts.map +1 -1
- package/dist/idl_codegen/instructions/withdrawProtocolFee.js +2 -6
- package/dist/idl_codegen/instructions/withdrawProtocolFee.js.map +1 -1
- package/dist/idl_codegen/types/UpdateGlobalConfigMode.d.ts +32 -0
- package/dist/idl_codegen/types/UpdateGlobalConfigMode.d.ts.map +1 -0
- package/dist/idl_codegen/types/UpdateGlobalConfigMode.js +108 -0
- package/dist/idl_codegen/types/UpdateGlobalConfigMode.js.map +1 -0
- package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts +33 -7
- package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts.map +1 -1
- package/dist/idl_codegen/types/UpdateLendingMarketMode.js +60 -12
- package/dist/idl_codegen/types/UpdateLendingMarketMode.js.map +1 -1
- package/dist/idl_codegen/types/index.d.ts +6 -2
- package/dist/idl_codegen/types/index.d.ts.map +1 -1
- package/dist/idl_codegen/types/index.js +3 -1
- package/dist/idl_codegen/types/index.js.map +1 -1
- package/dist/utils/accountListing.d.ts +1 -1
- package/dist/utils/accountListing.d.ts.map +1 -1
- package/dist/utils/accountListing.js +2 -2
- package/dist/utils/accountListing.js.map +1 -1
- package/dist/utils/lookupTable.d.ts.map +1 -1
- package/dist/utils/lookupTable.js +1 -6
- package/dist/utils/lookupTable.js.map +1 -1
- package/dist/utils/managerTypes.d.ts.map +1 -1
- package/dist/utils/managerTypes.js +10 -4
- package/dist/utils/managerTypes.js.map +1 -1
- package/dist/utils/seeds.d.ts +16 -0
- package/dist/utils/seeds.d.ts.map +1 -1
- package/dist/utils/seeds.js +23 -1
- package/dist/utils/seeds.js.map +1 -1
- package/package.json +1 -1
- package/src/classes/configItems.ts +295 -0
- package/src/classes/farm_utils.ts +3 -11
- package/src/classes/manager.ts +51 -394
- package/src/classes/obligation.ts +16 -0
- package/src/classes/reserve.ts +119 -783
- package/src/classes/utils.ts +12 -0
- package/src/classes/vault.ts +7 -10
- package/src/client_kamino_manager.ts +42 -34
- package/src/idl.json +186 -9
- package/src/idl_codegen/accounts/GlobalConfig.ts +125 -0
- package/src/idl_codegen/accounts/LendingMarket.ts +41 -9
- package/src/idl_codegen/accounts/index.ts +2 -0
- package/src/idl_codegen/errors/custom.ts +45 -0
- package/src/idl_codegen/instructions/idlMissingTypes.ts +4 -2
- package/src/idl_codegen/instructions/index.ts +9 -0
- package/src/idl_codegen/instructions/initGlobalConfig.ts +30 -0
- package/src/idl_codegen/instructions/updateGlobalConfig.ts +47 -0
- package/src/idl_codegen/instructions/updateGlobalConfigAdmin.ts +24 -0
- package/src/idl_codegen/instructions/updateReserveConfig.ts +7 -5
- package/src/idl_codegen/instructions/withdrawProtocolFee.ts +4 -8
- package/src/idl_codegen/types/UpdateGlobalConfigMode.ts +90 -0
- package/src/idl_codegen/types/UpdateLendingMarketMode.ts +73 -13
- package/src/idl_codegen/types/index.ts +16 -2
- package/src/utils/accountListing.ts +2 -3
- package/src/utils/lookupTable.ts +1 -7
- package/src/utils/managerTypes.ts +10 -4
- package/src/utils/seeds.ts +25 -0
package/src/classes/utils.ts
CHANGED
|
@@ -287,6 +287,18 @@ export function orThrow(message: string): never {
|
|
|
287
287
|
throw new Error(message);
|
|
288
288
|
}
|
|
289
289
|
|
|
290
|
+
export function blobEquals(left: Uint8Array, right: Uint8Array): boolean {
|
|
291
|
+
if (left.length !== right.length) {
|
|
292
|
+
return false;
|
|
293
|
+
}
|
|
294
|
+
for (let i = 0; i < left.length; ++i) {
|
|
295
|
+
if (left[i] !== right[i]) {
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return true;
|
|
300
|
+
}
|
|
301
|
+
|
|
290
302
|
/**
|
|
291
303
|
* Returns an integer {@link Decimal} nearest to the given one.
|
|
292
304
|
*
|
package/src/classes/vault.ts
CHANGED
|
@@ -966,9 +966,7 @@ export class KaminoVaultClient {
|
|
|
966
966
|
};
|
|
967
967
|
|
|
968
968
|
const depositArgs: DepositArgs = {
|
|
969
|
-
maxAmount: new BN(
|
|
970
|
-
numberToLamportsDecimal(tokenAmount, vaultState.tokenMintDecimals.toNumber()).floor().toString()
|
|
971
|
-
),
|
|
969
|
+
maxAmount: new BN(numberToLamportsDecimal(tokenAmount, vaultState.tokenMintDecimals.toNumber()).toString()),
|
|
972
970
|
};
|
|
973
971
|
|
|
974
972
|
const depositIx = deposit(depositArgs, depoistAccounts, this._kaminoVaultProgramId);
|
|
@@ -1086,7 +1084,7 @@ export class KaminoVaultClient {
|
|
|
1086
1084
|
);
|
|
1087
1085
|
|
|
1088
1086
|
if (vaultAllocation) {
|
|
1089
|
-
const withdrawFromVaultIxs = await this.
|
|
1087
|
+
const withdrawFromVaultIxs = await this.wihdrdrawWithReserveIxs(
|
|
1090
1088
|
user,
|
|
1091
1089
|
kaminoVault,
|
|
1092
1090
|
shareAmount,
|
|
@@ -1131,7 +1129,7 @@ export class KaminoVaultClient {
|
|
|
1131
1129
|
return [createAtaIx, withdrawFromAvailableIxn];
|
|
1132
1130
|
}
|
|
1133
1131
|
|
|
1134
|
-
private async
|
|
1132
|
+
private async wihdrdrawWithReserveIxs(
|
|
1135
1133
|
user: PublicKey,
|
|
1136
1134
|
vault: KaminoVault,
|
|
1137
1135
|
shareAmount: Decimal,
|
|
@@ -1141,6 +1139,7 @@ export class KaminoVaultClient {
|
|
|
1141
1139
|
const vaultState = await vault.getState(this.getConnection());
|
|
1142
1140
|
|
|
1143
1141
|
const vaultReservesState = vaultReservesMap ? vaultReservesMap : await this.loadVaultReserves(vaultState);
|
|
1142
|
+
|
|
1144
1143
|
const userSharesAta = getAssociatedTokenAddress(vaultState.sharesMint, user);
|
|
1145
1144
|
const [{ ata: userTokenAta, createAtaIx }] = createAtasIdempotent(user, [
|
|
1146
1145
|
{
|
|
@@ -1163,12 +1162,9 @@ export class KaminoVaultClient {
|
|
|
1163
1162
|
let isFirstWithdraw = true;
|
|
1164
1163
|
|
|
1165
1164
|
if (tokenLeftToWithdraw.lte(0)) {
|
|
1166
|
-
// Availabe enough to withdraw all - using
|
|
1167
|
-
const firstReserve = vaultState.vaultAllocationStrategy.find(
|
|
1168
|
-
(reserve) => !reserve.reserve.equals(PublicKey.default)
|
|
1169
|
-
);
|
|
1165
|
+
// Availabe enough to withdraw all - using first reserve as it does not matter
|
|
1170
1166
|
reserveWithSharesAmountToWithdraw.push({
|
|
1171
|
-
reserve:
|
|
1167
|
+
reserve: vaultState.vaultAllocationStrategy[0].reserve,
|
|
1172
1168
|
shares: shareLamportsToWithdraw,
|
|
1173
1169
|
});
|
|
1174
1170
|
} else {
|
|
@@ -1201,6 +1197,7 @@ export class KaminoVaultClient {
|
|
|
1201
1197
|
|
|
1202
1198
|
const withdrawIxs: TransactionInstruction[] = [];
|
|
1203
1199
|
withdrawIxs.push(createAtaIx);
|
|
1200
|
+
|
|
1204
1201
|
for (let reserveIndex = 0; reserveIndex < reserveWithSharesAmountToWithdraw.length; reserveIndex++) {
|
|
1205
1202
|
const reserveWithTokens = reserveWithSharesAmountToWithdraw[reserveIndex];
|
|
1206
1203
|
const reserveState = vaultReservesState.get(reserveWithTokens.reserve);
|
|
@@ -8,15 +8,20 @@ import {
|
|
|
8
8
|
Signer,
|
|
9
9
|
Transaction,
|
|
10
10
|
TransactionInstruction,
|
|
11
|
+
TransactionMessage,
|
|
11
12
|
TransactionSignature,
|
|
12
13
|
VersionedTransaction,
|
|
13
14
|
} from '@solana/web3.js';
|
|
14
15
|
import {
|
|
15
16
|
AssetReserveConfigCli,
|
|
16
17
|
Chain,
|
|
18
|
+
createLookupTableIx,
|
|
17
19
|
DEFAULT_RECENT_SLOT_DURATION_MS,
|
|
18
20
|
encodeTokenName,
|
|
21
|
+
extendLookupTableIxs,
|
|
22
|
+
getLookupTableAccounts,
|
|
19
23
|
getMedianSlotDurationInMsFromLastEpochs,
|
|
24
|
+
globalConfigPda,
|
|
20
25
|
initLookupTableIx,
|
|
21
26
|
KaminoManager,
|
|
22
27
|
KaminoMarket,
|
|
@@ -27,6 +32,7 @@ import {
|
|
|
27
32
|
MAINNET_BETA_CHAIN_ID,
|
|
28
33
|
parseZeroPaddedUtf8,
|
|
29
34
|
printHoldings,
|
|
35
|
+
PROGRAM_ID,
|
|
30
36
|
Reserve,
|
|
31
37
|
ReserveAllocationConfig,
|
|
32
38
|
ReserveWithAddress,
|
|
@@ -153,7 +159,10 @@ async function main() {
|
|
|
153
159
|
|
|
154
160
|
const _createReserveSig = await processTxn(env.client, env.payer, txnIxs[0], mode, 2500, [reserve]);
|
|
155
161
|
|
|
156
|
-
const
|
|
162
|
+
const [lut, createLutIxs] = await createUpdateReserveConfigLutIxs(env, marketAddress, reserve.publicKey);
|
|
163
|
+
await processTxn(env.client, env.payer, createLutIxs, mode, 2500, []);
|
|
164
|
+
|
|
165
|
+
const _updateSig = await processTxn(env.client, env.payer, txnIxs[1], mode, 2500, [], 400_000, 1000, [lut]);
|
|
157
166
|
|
|
158
167
|
mode === 'execute' &&
|
|
159
168
|
console.log(
|
|
@@ -609,21 +618,13 @@ async function main() {
|
|
|
609
618
|
const acceptVaultOwnershipSig = await processTxn(
|
|
610
619
|
env.client,
|
|
611
620
|
env.payer,
|
|
612
|
-
[instructions.acceptVaultOwnershipIx],
|
|
621
|
+
[instructions.acceptVaultOwnershipIx, ...instructions.updateLUTIxs],
|
|
613
622
|
mode,
|
|
614
623
|
2500,
|
|
615
624
|
[]
|
|
616
625
|
);
|
|
617
626
|
|
|
618
627
|
mode === 'execute' && console.log('Vault ownership accepted:', acceptVaultOwnershipSig);
|
|
619
|
-
|
|
620
|
-
// send the LUT mgmt ixs one by one
|
|
621
|
-
const lutIxs = [...instructions.updateLUTIxs];
|
|
622
|
-
for (let i = 0; i < lutIxs.length; i++) {
|
|
623
|
-
const lutIxsGroup = lutIxs.slice(i, i + 1);
|
|
624
|
-
const lutIxsSig = await processTxn(env.client, env.payer, lutIxsGroup, mode, 2500, []);
|
|
625
|
-
mode === 'execute' && console.log('LUT updated:', lutIxsSig);
|
|
626
|
-
}
|
|
627
628
|
});
|
|
628
629
|
|
|
629
630
|
commands
|
|
@@ -1076,11 +1077,7 @@ async function main() {
|
|
|
1076
1077
|
const walletAddress = new PublicKey(wallet);
|
|
1077
1078
|
const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kVaultProgramId);
|
|
1078
1079
|
const userShares = await kaminoManager.getUserSharesBalanceSingleVault(walletAddress, kaminoVault);
|
|
1079
|
-
console.log(
|
|
1080
|
-
`User shares for vault ${vaultAddress.toBase58()}: unstaked shares: ${
|
|
1081
|
-
userShares.unstakedShares
|
|
1082
|
-
} staked shares: ${userShares.stakedShares} total shares: ${userShares.totalShares}`
|
|
1083
|
-
);
|
|
1080
|
+
console.log(`User shares for vault ${vaultAddress.toBase58()}: ${userShares}`);
|
|
1084
1081
|
});
|
|
1085
1082
|
|
|
1086
1083
|
commands
|
|
@@ -1604,45 +1601,46 @@ async function processTxn(
|
|
|
1604
1601
|
priorityFeeMultiplier: number = 2500,
|
|
1605
1602
|
extraSigners: Signer[],
|
|
1606
1603
|
computeUnits: number = 200_000,
|
|
1607
|
-
priorityFeeLamports: number = 1000
|
|
1604
|
+
priorityFeeLamports: number = 1000,
|
|
1605
|
+
luts: PublicKey[] = []
|
|
1608
1606
|
): Promise<TransactionSignature> {
|
|
1609
1607
|
if (mode !== 'inspect' && mode !== 'simulate' && mode !== 'execute' && mode !== 'multisig') {
|
|
1610
1608
|
throw new Error('Invalid mode: ' + mode + '. Must be one of: inspect/simulate/execute/multisig');
|
|
1611
1609
|
}
|
|
1612
1610
|
if (mode === 'multisig') {
|
|
1613
1611
|
const { blockhash } = await web3Client.connection.getLatestBlockhash();
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
txn.feePayer = admin.publicKey;
|
|
1612
|
+
const txn = new Transaction();
|
|
1613
|
+
txn.add(...ixs);
|
|
1614
|
+
txn.recentBlockhash = blockhash;
|
|
1615
|
+
txn.feePayer = admin.publicKey;
|
|
1619
1616
|
|
|
1620
|
-
|
|
1621
|
-
}
|
|
1617
|
+
console.log(binary_to_base58(txn.serializeMessage()));
|
|
1622
1618
|
|
|
1623
1619
|
return '';
|
|
1624
1620
|
} else {
|
|
1625
1621
|
const microLamport = priorityFeeLamports * 10 ** 6; // 1000 lamports
|
|
1626
1622
|
const microLamportsPrioritizationFee = microLamport / computeUnits;
|
|
1627
|
-
|
|
1628
|
-
const tx = new Transaction();
|
|
1629
1623
|
const { blockhash } = await web3Client.connection.getLatestBlockhash();
|
|
1624
|
+
|
|
1630
1625
|
if (priorityFeeMultiplier) {
|
|
1631
1626
|
const priorityFeeIxn = createAddExtraComputeUnitFeeTransaction(
|
|
1632
1627
|
computeUnits,
|
|
1633
1628
|
microLamportsPrioritizationFee * priorityFeeMultiplier
|
|
1634
1629
|
);
|
|
1635
|
-
|
|
1630
|
+
ixs.push(...priorityFeeIxn);
|
|
1636
1631
|
}
|
|
1637
|
-
|
|
1638
|
-
tx
|
|
1639
|
-
|
|
1632
|
+
|
|
1633
|
+
const tx = new TransactionMessage({
|
|
1634
|
+
payerKey: admin.publicKey,
|
|
1635
|
+
recentBlockhash: blockhash,
|
|
1636
|
+
instructions: ixs,
|
|
1637
|
+
}).compileToV0Message(await getLookupTableAccounts(web3Client.connection, luts));
|
|
1640
1638
|
|
|
1641
1639
|
if (mode === 'execute') {
|
|
1642
1640
|
return await signSendAndConfirmRawTransactionWithRetry({
|
|
1643
1641
|
mainConnection: web3Client.sendConnection,
|
|
1644
1642
|
extraConnections: [],
|
|
1645
|
-
tx: new VersionedTransaction(tx
|
|
1643
|
+
tx: new VersionedTransaction(tx),
|
|
1646
1644
|
signers: [admin, ...extraSigners],
|
|
1647
1645
|
commitment: 'confirmed',
|
|
1648
1646
|
sendTransactionOptions: {
|
|
@@ -1651,9 +1649,7 @@ async function processTxn(
|
|
|
1651
1649
|
},
|
|
1652
1650
|
});
|
|
1653
1651
|
} else if (mode === 'simulate') {
|
|
1654
|
-
const simulation = await web3Client.sendConnection.simulateTransaction(
|
|
1655
|
-
new VersionedTransaction(tx.compileMessage())
|
|
1656
|
-
);
|
|
1652
|
+
const simulation = await web3Client.sendConnection.simulateTransaction(new VersionedTransaction(tx));
|
|
1657
1653
|
if (simulation.value.logs && simulation.value.logs.length > 0) {
|
|
1658
1654
|
console.log('Simulation: \n' + simulation.value.logs);
|
|
1659
1655
|
} else {
|
|
@@ -1663,7 +1659,7 @@ async function processTxn(
|
|
|
1663
1659
|
console.log(
|
|
1664
1660
|
'Tx in B64',
|
|
1665
1661
|
`https://explorer.solana.com/tx/inspector?message=${encodeURIComponent(
|
|
1666
|
-
tx.
|
|
1662
|
+
Buffer.from(tx.serialize()).toString('base64')
|
|
1667
1663
|
)}`
|
|
1668
1664
|
);
|
|
1669
1665
|
}
|
|
@@ -1861,3 +1857,15 @@ function parseReserveConfigToFile(reserveConfig: ReserveConfig) {
|
|
|
1861
1857
|
reserved2: Array(9).fill(0),
|
|
1862
1858
|
};
|
|
1863
1859
|
}
|
|
1860
|
+
|
|
1861
|
+
async function createUpdateReserveConfigLutIxs(
|
|
1862
|
+
env: Env,
|
|
1863
|
+
lendingMarketAddress: PublicKey,
|
|
1864
|
+
reserveAddress: PublicKey
|
|
1865
|
+
): Promise<[PublicKey, TransactionInstruction[]]> {
|
|
1866
|
+
const [globalConfigAddress] = globalConfigPda(PROGRAM_ID);
|
|
1867
|
+
const contents = [globalConfigAddress, lendingMarketAddress, reserveAddress];
|
|
1868
|
+
const [createIx, lut] = await createLookupTableIx(env.connection, env.payer.publicKey);
|
|
1869
|
+
const extendIxs = extendLookupTableIxs(env.payer.publicKey, lut, contents);
|
|
1870
|
+
return [lut, [createIx, ...extendIxs]];
|
|
1871
|
+
}
|
package/src/idl.json
CHANGED
|
@@ -230,10 +230,15 @@
|
|
|
230
230
|
"name": "updateReserveConfig",
|
|
231
231
|
"accounts": [
|
|
232
232
|
{
|
|
233
|
-
"name": "
|
|
233
|
+
"name": "signer",
|
|
234
234
|
"isMut": false,
|
|
235
235
|
"isSigner": true
|
|
236
236
|
},
|
|
237
|
+
{
|
|
238
|
+
"name": "globalConfig",
|
|
239
|
+
"isMut": false,
|
|
240
|
+
"isSigner": false
|
|
241
|
+
},
|
|
237
242
|
{
|
|
238
243
|
"name": "lendingMarket",
|
|
239
244
|
"isMut": false,
|
|
@@ -248,7 +253,9 @@
|
|
|
248
253
|
"args": [
|
|
249
254
|
{
|
|
250
255
|
"name": "mode",
|
|
251
|
-
"type":
|
|
256
|
+
"type": {
|
|
257
|
+
"defined": "UpdateConfigMode"
|
|
258
|
+
}
|
|
252
259
|
},
|
|
253
260
|
{
|
|
254
261
|
"name": "value",
|
|
@@ -305,9 +312,9 @@
|
|
|
305
312
|
"name": "withdrawProtocolFee",
|
|
306
313
|
"accounts": [
|
|
307
314
|
{
|
|
308
|
-
"name": "
|
|
315
|
+
"name": "globalConfig",
|
|
309
316
|
"isMut": false,
|
|
310
|
-
"isSigner":
|
|
317
|
+
"isSigner": false
|
|
311
318
|
},
|
|
312
319
|
{
|
|
313
320
|
"name": "lendingMarket",
|
|
@@ -335,7 +342,7 @@
|
|
|
335
342
|
"isSigner": false
|
|
336
343
|
},
|
|
337
344
|
{
|
|
338
|
-
"name": "
|
|
345
|
+
"name": "feeCollectorAta",
|
|
339
346
|
"isMut": true,
|
|
340
347
|
"isSigner": false
|
|
341
348
|
},
|
|
@@ -2932,14 +2939,93 @@
|
|
|
2932
2939
|
}
|
|
2933
2940
|
]
|
|
2934
2941
|
},
|
|
2942
|
+
{
|
|
2943
|
+
"name": "initGlobalConfig",
|
|
2944
|
+
"accounts": [
|
|
2945
|
+
{
|
|
2946
|
+
"name": "payer",
|
|
2947
|
+
"isMut": true,
|
|
2948
|
+
"isSigner": true
|
|
2949
|
+
},
|
|
2950
|
+
{
|
|
2951
|
+
"name": "globalConfig",
|
|
2952
|
+
"isMut": true,
|
|
2953
|
+
"isSigner": false
|
|
2954
|
+
},
|
|
2955
|
+
{
|
|
2956
|
+
"name": "programData",
|
|
2957
|
+
"isMut": false,
|
|
2958
|
+
"isSigner": false
|
|
2959
|
+
},
|
|
2960
|
+
{
|
|
2961
|
+
"name": "systemProgram",
|
|
2962
|
+
"isMut": false,
|
|
2963
|
+
"isSigner": false
|
|
2964
|
+
},
|
|
2965
|
+
{
|
|
2966
|
+
"name": "rent",
|
|
2967
|
+
"isMut": false,
|
|
2968
|
+
"isSigner": false
|
|
2969
|
+
}
|
|
2970
|
+
],
|
|
2971
|
+
"args": []
|
|
2972
|
+
},
|
|
2973
|
+
{
|
|
2974
|
+
"name": "updateGlobalConfig",
|
|
2975
|
+
"accounts": [
|
|
2976
|
+
{
|
|
2977
|
+
"name": "globalAdmin",
|
|
2978
|
+
"isMut": false,
|
|
2979
|
+
"isSigner": true
|
|
2980
|
+
},
|
|
2981
|
+
{
|
|
2982
|
+
"name": "globalConfig",
|
|
2983
|
+
"isMut": true,
|
|
2984
|
+
"isSigner": false
|
|
2985
|
+
}
|
|
2986
|
+
],
|
|
2987
|
+
"args": [
|
|
2988
|
+
{
|
|
2989
|
+
"name": "mode",
|
|
2990
|
+
"type": {
|
|
2991
|
+
"defined": "UpdateGlobalConfigMode"
|
|
2992
|
+
}
|
|
2993
|
+
},
|
|
2994
|
+
{
|
|
2995
|
+
"name": "value",
|
|
2996
|
+
"type": "bytes"
|
|
2997
|
+
}
|
|
2998
|
+
]
|
|
2999
|
+
},
|
|
3000
|
+
{
|
|
3001
|
+
"name": "updateGlobalConfigAdmin",
|
|
3002
|
+
"accounts": [
|
|
3003
|
+
{
|
|
3004
|
+
"name": "pendingAdmin",
|
|
3005
|
+
"isMut": false,
|
|
3006
|
+
"isSigner": true
|
|
3007
|
+
},
|
|
3008
|
+
{
|
|
3009
|
+
"name": "globalConfig",
|
|
3010
|
+
"isMut": true,
|
|
3011
|
+
"isSigner": false
|
|
3012
|
+
}
|
|
3013
|
+
],
|
|
3014
|
+
"args": []
|
|
3015
|
+
},
|
|
2935
3016
|
{
|
|
2936
3017
|
"name": "idlMissingTypes",
|
|
2937
3018
|
"accounts": [
|
|
2938
3019
|
{
|
|
2939
|
-
"name": "
|
|
3020
|
+
"name": "signer",
|
|
2940
3021
|
"isMut": false,
|
|
2941
3022
|
"isSigner": true
|
|
2942
3023
|
},
|
|
3024
|
+
{
|
|
3025
|
+
"name": "globalConfig",
|
|
3026
|
+
"isMut": false,
|
|
3027
|
+
"isSigner": false
|
|
3028
|
+
},
|
|
2943
3029
|
{
|
|
2944
3030
|
"name": "lendingMarket",
|
|
2945
3031
|
"isMut": false,
|
|
@@ -3134,6 +3220,47 @@
|
|
|
3134
3220
|
]
|
|
3135
3221
|
}
|
|
3136
3222
|
},
|
|
3223
|
+
{
|
|
3224
|
+
"name": "GlobalConfig",
|
|
3225
|
+
"type": {
|
|
3226
|
+
"kind": "struct",
|
|
3227
|
+
"fields": [
|
|
3228
|
+
{
|
|
3229
|
+
"name": "globalAdmin",
|
|
3230
|
+
"docs": [
|
|
3231
|
+
"Global admin of the program"
|
|
3232
|
+
],
|
|
3233
|
+
"type": "publicKey"
|
|
3234
|
+
},
|
|
3235
|
+
{
|
|
3236
|
+
"name": "pendingAdmin",
|
|
3237
|
+
"docs": [
|
|
3238
|
+
"Pending admin must sign a specific transaction to become the global admin"
|
|
3239
|
+
],
|
|
3240
|
+
"type": "publicKey"
|
|
3241
|
+
},
|
|
3242
|
+
{
|
|
3243
|
+
"name": "feeCollector",
|
|
3244
|
+
"docs": [
|
|
3245
|
+
"Fee collector is the only allowed owner of token accounts receiving protocol fees"
|
|
3246
|
+
],
|
|
3247
|
+
"type": "publicKey"
|
|
3248
|
+
},
|
|
3249
|
+
{
|
|
3250
|
+
"name": "padding",
|
|
3251
|
+
"docs": [
|
|
3252
|
+
"Padding to make the struct size 1024 bytes"
|
|
3253
|
+
],
|
|
3254
|
+
"type": {
|
|
3255
|
+
"array": [
|
|
3256
|
+
"u8",
|
|
3257
|
+
928
|
|
3258
|
+
]
|
|
3259
|
+
}
|
|
3260
|
+
}
|
|
3261
|
+
]
|
|
3262
|
+
}
|
|
3263
|
+
},
|
|
3137
3264
|
{
|
|
3138
3265
|
"name": "LendingMarket",
|
|
3139
3266
|
"type": {
|
|
@@ -3353,18 +3480,33 @@
|
|
|
3353
3480
|
"type": "u64"
|
|
3354
3481
|
},
|
|
3355
3482
|
{
|
|
3356
|
-
"name": "
|
|
3483
|
+
"name": "obligationOrderExecutionEnabled",
|
|
3357
3484
|
"docs": [
|
|
3358
3485
|
"Whether the obligation orders should be evaluated during liquidations."
|
|
3359
3486
|
],
|
|
3360
3487
|
"type": "u8"
|
|
3361
3488
|
},
|
|
3489
|
+
{
|
|
3490
|
+
"name": "immutable",
|
|
3491
|
+
"docs": [
|
|
3492
|
+
"Whether the lending market is set as immutable."
|
|
3493
|
+
],
|
|
3494
|
+
"type": "u8"
|
|
3495
|
+
},
|
|
3496
|
+
{
|
|
3497
|
+
"name": "obligationOrderCreationEnabled",
|
|
3498
|
+
"docs": [
|
|
3499
|
+
"Whether new obligation orders can be created.",
|
|
3500
|
+
"Note: updating or cancelling existing orders is *not* affected by this flag."
|
|
3501
|
+
],
|
|
3502
|
+
"type": "u8"
|
|
3503
|
+
},
|
|
3362
3504
|
{
|
|
3363
3505
|
"name": "padding2",
|
|
3364
3506
|
"type": {
|
|
3365
3507
|
"array": [
|
|
3366
3508
|
"u8",
|
|
3367
|
-
|
|
3509
|
+
5
|
|
3368
3510
|
]
|
|
3369
3511
|
}
|
|
3370
3512
|
},
|
|
@@ -4186,7 +4328,27 @@
|
|
|
4186
4328
|
"name": "UpdateInitialDepositAmount"
|
|
4187
4329
|
},
|
|
4188
4330
|
{
|
|
4189
|
-
"name": "
|
|
4331
|
+
"name": "UpdateObligationOrderExecutionEnabled"
|
|
4332
|
+
},
|
|
4333
|
+
{
|
|
4334
|
+
"name": "UpdateImmutableFlag"
|
|
4335
|
+
},
|
|
4336
|
+
{
|
|
4337
|
+
"name": "UpdateObligationOrderCreationEnabled"
|
|
4338
|
+
}
|
|
4339
|
+
]
|
|
4340
|
+
}
|
|
4341
|
+
},
|
|
4342
|
+
{
|
|
4343
|
+
"name": "UpdateGlobalConfigMode",
|
|
4344
|
+
"type": {
|
|
4345
|
+
"kind": "enum",
|
|
4346
|
+
"variants": [
|
|
4347
|
+
{
|
|
4348
|
+
"name": "PendingAdmin"
|
|
4349
|
+
},
|
|
4350
|
+
{
|
|
4351
|
+
"name": "FeeCollector"
|
|
4190
4352
|
}
|
|
4191
4353
|
]
|
|
4192
4354
|
}
|
|
@@ -6032,6 +6194,21 @@
|
|
|
6032
6194
|
"code": 6126,
|
|
6033
6195
|
"name": "OperationNotPermittedWithCurrentObligationOrders",
|
|
6034
6196
|
"msg": "Single debt, single collateral obligation orders have to be cancelled before changing the deposit/borrow count"
|
|
6197
|
+
},
|
|
6198
|
+
{
|
|
6199
|
+
"code": 6127,
|
|
6200
|
+
"name": "OperationNotPermittedMarketImmutable",
|
|
6201
|
+
"msg": "Cannot update lending market because it is set as immutable"
|
|
6202
|
+
},
|
|
6203
|
+
{
|
|
6204
|
+
"code": 6128,
|
|
6205
|
+
"name": "OrderCreationDisabled",
|
|
6206
|
+
"msg": "Creation of new orders is disabled"
|
|
6207
|
+
},
|
|
6208
|
+
{
|
|
6209
|
+
"code": 6129,
|
|
6210
|
+
"name": "NoUpgradeAuthority",
|
|
6211
|
+
"msg": "Cannot initialize global config because there is no upgrade authority to the program"
|
|
6035
6212
|
}
|
|
6036
6213
|
]
|
|
6037
6214
|
}
|
|
@@ -0,0 +1,125 @@
|
|
|
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
|
+
}
|