Skip to content

Commit

Permalink
Merge pull request #509 from k0beLeenders/configureBankIx
Browse files Browse the repository at this point in the history
feat(mfi-v2-ui): added configure bank ix
  • Loading branch information
losman0s authored Jan 19, 2024
2 parents 46d07dd + 4ad04ca commit 092401e
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
24 changes: 24 additions & 0 deletions packages/marginfi-client-v2/src/instructions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AccountMeta, PublicKey, SystemProgram } from "@solana/web3.js";
import BN from "bn.js";
import { MarginfiProgram } from "./types";
import { BankConfigOpt } from "./models/bank";

async function makeInitMarginfiAccountIx(
mfProgram: MarginfiProgram,
Expand Down Expand Up @@ -227,6 +228,28 @@ function makeUnsetAccountFlagIx(
})
.instruction();
}

function makePoolConfigureBankIx(
mfiProgram: MarginfiProgram,
accounts: {
marginfiGroup: PublicKey;
admin: PublicKey;
bank: PublicKey;
},
args: {
bankConfigOpt: BankConfigOpt;
}
) {
return mfiProgram.methods
.lendingPoolConfigureBank(args.bankConfigOpt)
.accounts({
marginfiGroup: accounts.marginfiGroup,
admin: accounts.admin,
bank: accounts.bank,
})
.instruction();
}

const instructions = {
makeDepositIx,
makeRepayIx,
Expand All @@ -237,6 +260,7 @@ const instructions = {
makelendingAccountWithdrawEmissionIx,
makeSetAccountFlagIx,
makeUnsetAccountFlagIx,
makePoolConfigureBankIx,
};

export default instructions;
25 changes: 24 additions & 1 deletion packages/marginfi-client-v2/src/models/bank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,29 @@ enum OracleSetup {
SwitchboardV2 = 2,
}

// BankConfigOpt Args
interface BankConfigOpt {
assetWeightInit: WrappedI80F48 | null;
assetWeightMaint: WrappedI80F48 | null;

liabilityWeightInit: WrappedI80F48 | null;
liabilityWeightMaint: WrappedI80F48 | null;

depositLimit: BN | null;
borrowLimit: BN | null;
riskTier: { collateral: {} } | { isolated: {} } | null;
totalAssetValueInitLimit: BN | null;

interestRateConfig: InterestRateConfigRaw | null;
operationalState: { paused: {} } | { operational: {} } | { reduceOnly: {} } | null;

oracle: {
setup: { none: {} } | { pythEma: {} } | { switchboardV2: {} } ;
keys: PublicKey[] ;
} | null
}


function parseRiskTier(riskTierRaw: RiskTierRaw): RiskTier {
switch (Object.keys(riskTierRaw)[0].toLowerCase()) {
case "collateral":
Expand Down Expand Up @@ -713,7 +736,7 @@ function parseOracleSetup(oracleSetupRaw: OracleSetupRaw): OracleSetup {
}
}

export type { InterestRateConfig };
export type { InterestRateConfig, BankConfigOpt };
export { Bank, BankConfig, RiskTier, OperationalState, OracleSetup, parseRiskTier, parseOracleSetup };

// ----------------------------------------------------------------------------
Expand Down
23 changes: 23 additions & 0 deletions packages/marginfi-client-v2/src/models/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { AccountType, MarginfiProgram } from "../types";
import { InstructionsWrapper } from "@mrgnlabs/mrgn-common";
import instructions from "../instructions";
import { FLASHLOAN_ENABLED_FLAG } from "../constants";
import { BankConfigOpt } from "./bank";

// ----------------------------------------------------------------------------
// On-chain types
Expand Down Expand Up @@ -101,6 +102,28 @@ class MarginfiGroup {
keys: [],
};
}

public async makePoolConfigureBankIxb(
program: MarginfiProgram,
bank: PublicKey,
args: BankConfigOpt
): Promise<InstructionsWrapper> {
const ix = await instructions.makePoolConfigureBankIx(
program,
{
marginfiGroup: this.address,

admin: this.admin,
bank: bank,
},
{ bankConfigOpt: args }
);

return {
instructions: [ix],
keys: [],
};
}
}

export { MarginfiGroup };

0 comments on commit 092401e

Please sign in to comment.