Skip to content

Commit

Permalink
Merge pull request #237 from mrgnlabs/e/fixing-for-fuse
Browse files Browse the repository at this point in the history
Allow off-curve addresses for fuse
  • Loading branch information
losman0s authored Sep 15, 2023
2 parents 113fe82 + e02a466 commit bfc5d77
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
20 changes: 10 additions & 10 deletions apps/marginfi-v2-ui/src/components/CampaignWizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const CampaignWizardInputBox: FC<CampaignWizardInputBox> = ({
);
};

interface CampaignWizardProps {}
interface CampaignWizardProps { }

const CampaignWizard: FC<CampaignWizardProps> = () => {
const [guaranteedApy, setGuaranteedApy] = useState(0);
Expand Down Expand Up @@ -133,7 +133,7 @@ const CampaignWizard: FC<CampaignWizardProps> = () => {

const campaignKeypair = Keypair.generate();
console.log("creating campaign", campaignKeypair.publicKey.toBase58());
const userTokenAtaPk = getAssociatedTokenAddressSync(campaignBank.mint, lipClient.wallet.publicKey);
const userTokenAtaPk = getAssociatedTokenAddressSync(campaignBank.mint, lipClient.wallet.publicKey, true); // We allow off curve addresses here to support Fuse.

const tx = new Transaction();

Expand Down Expand Up @@ -271,7 +271,7 @@ const CampaignWizard: FC<CampaignWizardProps> = () => {
<CampaignWizardInputBox
value={guaranteedApy * 100}
setValue={(value) => setGuaranteedApy(value / 100)}
loadingSafetyCheck={() => {}}
loadingSafetyCheck={() => { }}
maxDecimals={2}
disabled={!walletContext.connected}
/>
Expand All @@ -282,7 +282,7 @@ const CampaignWizard: FC<CampaignWizardProps> = () => {
<CampaignWizardInputBox
value={lockupPeriodInDays}
setValue={setLockupPeriodInDays}
loadingSafetyCheck={() => {}}
loadingSafetyCheck={() => { }}
maxDecimals={4}
disabled={!walletContext.connected}
/>
Expand All @@ -293,7 +293,7 @@ const CampaignWizard: FC<CampaignWizardProps> = () => {
<CampaignWizardInputBox
value={depositCapacity}
setValue={setDepositCapacity}
loadingSafetyCheck={() => {}}
loadingSafetyCheck={() => { }}
maxDecimals={3}
disabled={!walletContext.connected}
/>
Expand Down Expand Up @@ -343,12 +343,12 @@ const CampaignWizard: FC<CampaignWizardProps> = () => {
>
{campaignBank
? percentFormatterDyn.format(
computeGuaranteedApy(
contractInputs.lockupPeriod.toNumber(),
contractInputs.maxDeposits.toNumber(),
contractInputs.maxRewards.toNumber()
)
computeGuaranteedApy(
contractInputs.lockupPeriod.toNumber(),
contractInputs.maxDeposits.toNumber(),
contractInputs.maxRewards.toNumber()
)
)
: 0}
</span>
</div>
Expand Down
2 changes: 1 addition & 1 deletion apps/omni/src/api/ai/tools/walletBalances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class WalletBalancesTool extends Tool {
};
}

const ataAddresses = mintList.map((mint) => getAssociatedTokenAddressSync(mint.address, wallet!));
const ataAddresses = mintList.map((mint) => getAssociatedTokenAddressSync(mint.address, wallet!, true)); // We allow off curve addresses here to support Fuse.

// Fetch relevant accounts
const accountsAiList = await this.connection.getMultipleAccountsInfo([wallet, ...ataAddresses]);
Expand Down
2 changes: 1 addition & 1 deletion packages/lip-client/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class LipAccount {
async makeClosePositionIx(deposit: Deposit): Promise<InstructionsWrapper> {
let ixs = [];

const userAta = getAssociatedTokenAddressSync(deposit.campaign.bank.mint, this.client.wallet.publicKey);
const userAta = getAssociatedTokenAddressSync(deposit.campaign.bank.mint, this.client.wallet.publicKey, true); // We allow off curve addresses here to support Fuse.
const createAtaIdempotentIx = createAssociatedTokenAccountIdempotentInstruction(
this.client.wallet.publicKey,
userAta,
Expand Down
2 changes: 1 addition & 1 deletion packages/lip-client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class LipClient {
async makeDepositIx(campaign: PublicKey, amount: Amount, bank: Bank): Promise<InstructionsWrapper> {
const depositKeypair = Keypair.generate();
const tempTokenAccountKeypair = Keypair.generate();
const userTokenAtaPk = getAssociatedTokenAddressSync(bank.mint, this.mfiClient.provider.wallet.publicKey);
const userTokenAtaPk = getAssociatedTokenAddressSync(bank.mint, this.mfiClient.provider.wallet.publicKey, true); // We allow off curve addresses here to support Fuse.
const amountNative = uiToNative(amount, bank.mintDecimals);

const ixs = [];
Expand Down
12 changes: 6 additions & 6 deletions packages/marginfi-client-v2/src/models/account/pure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ class MarginfiAccount {
const bank = banks.get(bankAddress.toBase58());
if (!bank) throw Error(`Bank ${bankAddress.toBase58()} not found`);

const userTokenAtaPk = getAssociatedTokenAddressSync(bank.mint, this.authority);
const userTokenAtaPk = getAssociatedTokenAddressSync(bank.mint, this.authority, true); // We allow off curve addresses here to support Fuse.
const remainingAccounts = this.getHealthCheckAccounts(banks, [bank]);
const ix = await instructions.makeDepositIx(
program,
Expand Down Expand Up @@ -432,7 +432,7 @@ class MarginfiAccount {

// Add emissions-related instructions if necessary
if (repayAll && !bank.emissionsMint.equals(PublicKey.default)) {
const userAta = getAssociatedTokenAddressSync(bank.emissionsMint, this.authority);
const userAta = getAssociatedTokenAddressSync(bank.emissionsMint, this.authority, true); // We allow off curve addresses here to support Fuse.
const createAtaIdempotentIx = createAssociatedTokenAccountIdempotentInstruction(
this.authority,
userAta,
Expand All @@ -445,7 +445,7 @@ class MarginfiAccount {
}

// Add repay-related instructions
const userAta = getAssociatedTokenAddressSync(bank.mint, this.authority);
const userAta = getAssociatedTokenAddressSync(bank.mint, this.authority, true); // We allow off curve addresses here to support Fuse.
const remainingAccounts = repayAll
? this.getHealthCheckAccounts(banks, [], [bank])
: this.getHealthCheckAccounts(banks, [bank], []);
Expand Down Expand Up @@ -490,7 +490,7 @@ class MarginfiAccount {

// Add emissions-related instructions if necessary
if (withdrawAll && !bank.emissionsMint.equals(PublicKey.default)) {
const userAta = getAssociatedTokenAddressSync(bank.emissionsMint, this.authority);
const userAta = getAssociatedTokenAddressSync(bank.emissionsMint, this.authority, true); // We allow off curve addresses here to support Fuse.
const createAtaIdempotentIx = createAssociatedTokenAccountIdempotentInstruction(
this.authority,
userAta,
Expand Down Expand Up @@ -548,7 +548,7 @@ class MarginfiAccount {

let ixs = [];

const userAta = getAssociatedTokenAddressSync(bank.mint, this.authority);
const userAta = getAssociatedTokenAddressSync(bank.mint, this.authority, true); // We allow off curve addresses here to support Fuse.

// Add additional CU request if necessary
const activeBalances = this.balances.filter((b) => b.active);
Expand Down Expand Up @@ -599,7 +599,7 @@ class MarginfiAccount {

let ixs = [];

const userAta = getAssociatedTokenAddressSync(bank.emissionsMint, this.authority);
const userAta = getAssociatedTokenAddressSync(bank.emissionsMint, this.authority, true); // We allow off curve addresses here to support Fuse.
const createAtaIdempotentIx = createAssociatedTokenAccountIdempotentInstruction(
this.authority,
userAta,
Expand Down
2 changes: 1 addition & 1 deletion packages/marginfi-client-v2/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ export function makeWrapSolIxs(walletAddress: PublicKey, amount: BigNumber): Tra
}

export function makeUnwrapSolIx(walletAddress: PublicKey): TransactionInstruction {
const address = getAssociatedTokenAddressSync(NATIVE_MINT, walletAddress);
const address = getAssociatedTokenAddressSync(NATIVE_MINT, walletAddress, true); // We allow off curve addresses here to support Fuse.
return createCloseAccountInstruction(address, walletAddress, walletAddress);
}
2 changes: 1 addition & 1 deletion packages/marginfi-v2-ui-state/src/lib/mrgnlend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ async function fetchTokenAccounts(
};
}

const ataAddresses = mintList.map((mint) => getAssociatedTokenAddressSync(mint.address, walletAddress!));
const ataAddresses = mintList.map((mint) => getAssociatedTokenAddressSync(mint.address, walletAddress!, true)); // We allow off curve addresses here to support Fuse.

// Fetch relevant accounts
const accountsAiList = await connection.getMultipleAccountsInfo([walletAddress, ...ataAddresses]);
Expand Down

3 comments on commit bfc5d77

@vercel
Copy link

@vercel vercel bot commented on bfc5d77 Sep 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

marginfi-landing-page – ./apps/marginfi-landing-page

marginfi-landing-page.vercel.app
marginfi-landing-page-git-production-mrgn.vercel.app
marginfi-landing-page-mrgn.vercel.app
www.marginfi.com
marginfi.com

@vercel
Copy link

@vercel vercel bot commented on bfc5d77 Sep 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

omni – ./apps/omni

omni-one.vercel.app
omni-mrgn.vercel.app
omni-git-production-mrgn.vercel.app
omni.marginfi.com

@vercel
Copy link

@vercel vercel bot commented on bfc5d77 Sep 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.