diff --git a/package-lock.json b/package-lock.json index 84db99e..cb20d07 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@uxd-protocol/uxd-client", - "version": "9.0.0-rc2", + "version": "9.0.0-rc6", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@uxd-protocol/uxd-client", - "version": "9.0.0-rc2", + "version": "9.0.0-rc6", "license": "MIT", "dependencies": { "@project-serum/anchor": "0.26.0", diff --git a/package.json b/package.json index f147b2d..7576364 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/alloyx_vault/depository.ts b/src/alloyx_vault/depository.ts index cbce065..4e1ead8 100644 --- a/src/alloyx_vault/depository.ts +++ b/src/alloyx_vault/depository.ts @@ -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, @@ -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 ); @@ -107,6 +109,7 @@ export class AlloyxVaultDepository { collateralSymbol, depositoryCollateral, depositoryShares, + alloyxVaultId, alloyxVaultInfo, alloyxVaultCollateral, alloyxVaultShares, @@ -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(), ], diff --git a/src/client.ts b/src/client.ts index 06656a5..6e776cd 100644 --- a/src/client.ts +++ b/src/client.ts @@ -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, diff --git a/src/interfaces.ts b/src/interfaces.ts index 23e3dc2..fc66e52 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -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 @@ -29,6 +25,8 @@ export class ControllerAccount { slotsPerEpoch!: BN; // u64 epochOutflowAmount!: BN; // u64 lastOutflowSlot!: BN; // u64 + alloyxVaultDepository!: PublicKey; + alloyxVaultDepositoryWeightBps!: number; // u16 } // V1