Skip to content
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@uxd-protocol/uxd-client",
"version": "9.0.0-rc2",
"version": "9.0.0-rc6",
"description": "JavaScript Client for the UXD Solana Program",
"keywords": [
"solana",
Expand Down
9 changes: 6 additions & 3 deletions src/alloyx_vault/depository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class AlloyxVaultDepository {
public readonly collateralSymbol: string,
public readonly depositoryCollateral: PublicKey,
public readonly depositoryShares: PublicKey,
public readonly alloyxVaultId: string,
public readonly alloyxVaultInfo: PublicKey,
public readonly alloyxVaultCollateral: PublicKey,
public readonly alloyxVaultShares: PublicKey,
Expand Down Expand Up @@ -79,9 +80,10 @@ export class AlloyxVaultDepository {
collateralMint,
uxdProgramId
);

// Then the alloyx pass which depends on the depository
const alloyxVaultPass = this.findAlloyxVaultPassAddress(
alloyxVaultInfo,
alloyxVaultId,
depository,
alloyxProgramId
);
Expand All @@ -107,6 +109,7 @@ export class AlloyxVaultDepository {
collateralSymbol,
depositoryCollateral,
depositoryShares,
alloyxVaultId,
alloyxVaultInfo,
alloyxVaultCollateral,
alloyxVaultShares,
Expand Down Expand Up @@ -185,13 +188,13 @@ export class AlloyxVaultDepository {
}

private static findAlloyxVaultPassAddress(
alloyxVaultId: PublicKey,
alloyxVaultId: string,
depository: PublicKey,
alloyxProgramId: PublicKey
): PublicKey {
return PublicKey.findProgramAddressSync(
[
alloyxVaultId.toBuffer(),
Buffer.from(alloyxVaultId),
Buffer.from(ALLOYX_VAULT_INTERNAL_VAULT_PASS_NAMESPACE),
depository.toBuffer(),
],
Expand Down
140 changes: 140 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,146 @@ export class UXDClient {
);
}

public createEditAlloyxVaultDepositoryInstruction(
controller: Controller,
depository: AlloyxVaultDepository,
authority: PublicKey,
uiFields: {
redeemableAmountUnderManagementCap?: number;
mintingFeeInBps?: number;
redeemingFeeInBps?: number;
mintingDisabled?: boolean;
profitsBeneficiaryCollateral?: PublicKey;
},
options: ConfirmOptions
): TransactionInstruction {
const {
redeemableAmountUnderManagementCap,
mintingFeeInBps,
redeemingFeeInBps,
mintingDisabled,
profitsBeneficiaryCollateral,
} = uiFields;
const fields = {
redeemableAmountUnderManagementCap:
redeemableAmountUnderManagementCap !== undefined
? uiToNative(
redeemableAmountUnderManagementCap,
controller.redeemableMintDecimals
)
: null,
mintingFeeInBps: mintingFeeInBps !== undefined ? mintingFeeInBps : null,
redeemingFeeInBps:
redeemingFeeInBps !== undefined ? redeemingFeeInBps : null,
mintingDisabled: mintingDisabled !== undefined ? mintingDisabled : null,
profitsBeneficiaryCollateral:
profitsBeneficiaryCollateral !== undefined
? profitsBeneficiaryCollateral
: null,
};
return this.instruction.editAlloyxVaultDepository(fields, {
accounts: {
authority,
controller: controller.pda,
depository: depository.pda,
},
options,
});
}

public createRegisterAlloyxVaultDepositoryInstruction(
controller: Controller,
depository: AlloyxVaultDepository,
authority: PublicKey,
mintingFeeInBps: number,
redeemingFeeInBps: number,
redeemableAmountUnderManagementCap: number,
options: ConfirmOptions,
payer?: PublicKey
): TransactionInstruction {
const nativeRedeemableAmountUnderManagementCap = uiToNative(
redeemableAmountUnderManagementCap,
controller.redeemableMintDecimals
);

return this.instruction.registerAlloyxVaultDepository(
mintingFeeInBps,
redeemingFeeInBps,
nativeRedeemableAmountUnderManagementCap,
{
accounts: {
authority,
payer: payer ?? authority,
controller: controller.pda,
depository: depository.pda,
collateralMint: depository.collateralMint,
depositoryCollateral: depository.depositoryCollateral,
depositoryShares: depository.depositoryShares,
alloyxVaultInfo: depository.alloyxVaultInfo,
alloyxVaultCollateral: depository.alloyxVaultCollateral,
alloyxVaultShares: depository.alloyxVaultShares,
alloyxVaultMint: depository.alloyxVaultMint,
systemProgram: SystemProgram.programId,
tokenProgram: TOKEN_PROGRAM_ID,
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
rent: SYSVAR_RENT_PUBKEY,
},
options,
}
);
}

public createRebalanceAlloyxVaultDepositoryInstruction(
controller: Controller,
identityDepository: IdentityDepository,
mercurialVaultDepository: MercurialVaultDepository,
credixLpDepository: CredixLpDepository,
alloyxVaultDepository: AlloyxVaultDepository,
payer: PublicKey,
profitsBeneficiaryCollateral: PublicKey,
options: ConfirmOptions
): TransactionInstruction {
const collateralMintPda = identityDepository.collateralMint;
const payerCollateral = findATAAddrSync(payer, collateralMintPda)[0];

return this.instruction.rebalanceAlloyxVaultDepository(
alloyxVaultDepository.alloyxVaultId,
{
accounts: {
payer: payer,
payerCollateral: payerCollateral,

controller: controller.pda,
collateralMint: collateralMintPda,

identityDepository: identityDepository.pda,
identityDepositoryCollateral: identityDepository.collateralVaultPda,

mercurialVaultDepository: mercurialVaultDepository.pda,

credixLpDepository: credixLpDepository.pda,

alloyxVaultDepository: alloyxVaultDepository.pda,
alloyxVaultDepositoryCollateral:
alloyxVaultDepository.depositoryCollateral,
alloyxVaultDepositoryShares: alloyxVaultDepository.depositoryShares,
alloyxVaultInfo: alloyxVaultDepository.alloyxVaultInfo,
alloyxVaultCollateral: alloyxVaultDepository.alloyxVaultCollateral,
alloyxVaultShares: alloyxVaultDepository.alloyxVaultShares,
alloyxVaultMint: alloyxVaultDepository.alloyxVaultMint,
alloyxVaultPass: alloyxVaultDepository.alloyxVaultPass,

profitsBeneficiaryCollateral: profitsBeneficiaryCollateral,
systemProgram: SystemProgram.programId,
tokenProgram: TOKEN_PROGRAM_ID,
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
alloyxProgram: alloyxVaultDepository.alloyxProgramId,
},
options,
}
);
}

public createFreezeProgramInstruction(
freeze: boolean,
controller: Controller,
Expand Down
6 changes: 2 additions & 4 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ export class ControllerAccount {
isFrozen!: boolean;
redeemableGlobalSupplyCap!: BN; // u128
redeemableCirculatingSupply!: BN; // u128
registeredMercurialVaultDepositories!: PublicKey[];
registeredMercurialVaultDepositoriesCount!: number; // u8
registeredCredixLpDepositories!: PublicKey[];
registeredCredixLpDepositoriesCount!: number; // u8
profitsTotalCollected!: BN; // u128
identityDepositoryWeightBps!: number; // u16
mercurialVaultDepositoryWeightBps!: number; // u16
Expand All @@ -29,6 +25,8 @@ export class ControllerAccount {
slotsPerEpoch!: BN; // u64
epochOutflowAmount!: BN; // u64
lastOutflowSlot!: BN; // u64
alloyxVaultDepository!: PublicKey;
alloyxVaultDepositoryWeightBps!: number; // u16
}

// V1
Expand Down