From 4ee2459e63e0a3cbb7e4e6801e6b9305c62313f7 Mon Sep 17 00:00:00 2001 From: Vincent Brunet Date: Thu, 2 Nov 2023 17:52:32 +0900 Subject: [PATCH 01/12] saving-progress --- src/alloyx_vault/alloyxIdl.ts | 1319 ++++++++++++++++++++++ src/alloyx_vault/depository.ts | 303 +++++ src/idl.ts | 1880 +++++++++++++++++++++++++------- src/interfaces.ts | 24 + 4 files changed, 3111 insertions(+), 415 deletions(-) create mode 100644 src/alloyx_vault/alloyxIdl.ts create mode 100644 src/alloyx_vault/depository.ts diff --git a/src/alloyx_vault/alloyxIdl.ts b/src/alloyx_vault/alloyxIdl.ts new file mode 100644 index 0000000..3347eaa --- /dev/null +++ b/src/alloyx_vault/alloyxIdl.ts @@ -0,0 +1,1319 @@ +export type AlloyxSolana = { + version: '0.1.0'; + name: 'alloyx_solana'; + instructions: [ + { + name: 'initialize'; + accounts: [ + { + name: 'signer'; + isMut: true; + isSigner: true; + }, + { + name: 'usdcVaultAccount'; + isMut: true; + isSigner: false; + }, + { + name: 'usdcMint'; + isMut: false; + isSigner: false; + }, + { + name: 'alloyxVaultAccount'; + isMut: true; + isSigner: false; + }, + { + name: 'alloyxMint'; + isMut: false; + isSigner: false; + }, + { + name: 'vaultInfoAccount'; + isMut: true; + isSigner: false; + }, + { + name: 'tokenProgram'; + isMut: false; + isSigner: false; + }, + { + name: 'systemProgram'; + isMut: false; + isSigner: false; + } + ]; + args: [ + { + name: 'vaultId'; + type: 'string'; + } + ]; + }, + { + name: 'whitelist'; + accounts: [ + { + name: 'signer'; + isMut: true; + isSigner: true; + }, + { + name: 'investorPass'; + isMut: true; + isSigner: false; + }, + { + name: 'vaultInfoAccount'; + isMut: false; + isSigner: false; + }, + { + name: 'systemProgram'; + isMut: false; + isSigner: false; + } + ]; + args: [ + { + name: 'vaultId'; + type: 'string'; + }, + { + name: 'investor'; + type: 'publicKey'; + } + ]; + }, + { + name: 'unwhitelist'; + accounts: [ + { + name: 'signer'; + isMut: true; + isSigner: true; + }, + { + name: 'investorPass'; + isMut: true; + isSigner: false; + }, + { + name: 'vaultInfoAccount'; + isMut: false; + isSigner: false; + }, + { + name: 'systemProgram'; + isMut: false; + isSigner: false; + } + ]; + args: [ + { + name: 'vaultId'; + type: 'string'; + }, + { + name: 'investor'; + type: 'publicKey'; + } + ]; + }, + { + name: 'deposit'; + accounts: [ + { + name: 'signer'; + isMut: true; + isSigner: true; + }, + { + name: 'investorPass'; + isMut: false; + isSigner: false; + }, + { + name: 'vaultInfoAccount'; + isMut: false; + isSigner: false; + }, + { + name: 'usdcVaultAccount'; + isMut: true; + isSigner: false; + }, + { + name: 'usdcMint'; + isMut: false; + isSigner: false; + }, + { + name: 'alloyxVaultAccount'; + isMut: false; + isSigner: false; + }, + { + name: 'alloyxMint'; + isMut: true; + isSigner: false; + }, + { + name: 'userUsdcAccount'; + isMut: true; + isSigner: false; + }, + { + name: 'userAlloyxAccount'; + isMut: true; + isSigner: false; + }, + { + name: 'tokenProgram'; + isMut: false; + isSigner: false; + }, + { + name: 'associatedTokenProgram'; + isMut: false; + isSigner: false; + }, + { + name: 'systemProgram'; + isMut: false; + isSigner: false; + } + ]; + args: [ + { + name: 'vaultId'; + type: 'string'; + }, + { + name: 'usdcAmount'; + type: 'u64'; + } + ]; + }, + { + name: 'withdraw'; + accounts: [ + { + name: 'signer'; + isMut: true; + isSigner: true; + }, + { + name: 'investorPass'; + isMut: false; + isSigner: false; + }, + { + name: 'vaultInfoAccount'; + isMut: false; + isSigner: false; + }, + { + name: 'usdcVaultAccount'; + isMut: true; + isSigner: false; + }, + { + name: 'usdcMint'; + isMut: false; + isSigner: false; + }, + { + name: 'alloyxVaultAccount'; + isMut: true; + isSigner: false; + }, + { + name: 'alloyxMint'; + isMut: true; + isSigner: false; + }, + { + name: 'userUsdcAccount'; + isMut: true; + isSigner: false; + }, + { + name: 'userAlloyxAccount'; + isMut: true; + isSigner: false; + }, + { + name: 'tokenProgram'; + isMut: false; + isSigner: false; + }, + { + name: 'associatedTokenProgram'; + isMut: false; + isSigner: false; + }, + { + name: 'systemProgram'; + isMut: false; + isSigner: false; + } + ]; + args: [ + { + name: 'vaultId'; + type: 'string'; + }, + { + name: 'alloyxAmount'; + type: 'u64'; + } + ]; + }, + { + name: 'transferUsdcOut'; + accounts: [ + { + name: 'signer'; + isMut: true; + isSigner: true; + }, + { + name: 'vaultInfoAccount'; + isMut: true; + isSigner: false; + }, + { + name: 'usdcVaultAccount'; + isMut: true; + isSigner: false; + }, + { + name: 'usdcMint'; + isMut: false; + isSigner: false; + }, + { + name: 'userUsdcAccount'; + isMut: true; + isSigner: false; + }, + { + name: 'tokenProgram'; + isMut: false; + isSigner: false; + }, + { + name: 'associatedTokenProgram'; + isMut: false; + isSigner: false; + }, + { + name: 'systemProgram'; + isMut: false; + isSigner: false; + } + ]; + args: [ + { + name: 'vaultId'; + type: 'string'; + }, + { + name: 'amount'; + type: 'u64'; + } + ]; + }, + { + name: 'transferUsdcIn'; + accounts: [ + { + name: 'signer'; + isMut: true; + isSigner: true; + }, + { + name: 'vaultInfoAccount'; + isMut: true; + isSigner: false; + }, + { + name: 'usdcVaultAccount'; + isMut: true; + isSigner: false; + }, + { + name: 'usdcMint'; + isMut: false; + isSigner: false; + }, + { + name: 'userUsdcAccount'; + isMut: true; + isSigner: false; + }, + { + name: 'tokenProgram'; + isMut: false; + isSigner: false; + }, + { + name: 'associatedTokenProgram'; + isMut: false; + isSigner: false; + }, + { + name: 'systemProgram'; + isMut: false; + isSigner: false; + } + ]; + args: [ + { + name: 'vaultId'; + type: 'string'; + }, + { + name: 'amount'; + type: 'u64'; + } + ]; + }, + { + name: 'setVaultInfo'; + accounts: [ + { + name: 'signer'; + isMut: true; + isSigner: true; + }, + { + name: 'vaultInfoAccount'; + isMut: true; + isSigner: false; + }, + { + name: 'usdcMint'; + isMut: false; + isSigner: false; + }, + { + name: 'systemProgram'; + isMut: false; + isSigner: false; + } + ]; + args: [ + { + name: 'vaultId'; + type: 'string'; + }, + { + name: 'walletDeskAmount'; + type: 'u64'; + } + ]; + }, + { + name: 'transferAuthority'; + accounts: [ + { + name: 'signer'; + isMut: true; + isSigner: true; + }, + { + name: 'vaultInfoAccount'; + isMut: true; + isSigner: false; + }, + { + name: 'systemProgram'; + isMut: false; + isSigner: false; + } + ]; + args: [ + { + name: 'vaultId'; + type: 'string'; + }, + { + name: 'newAuthority'; + type: 'publicKey'; + } + ]; + } + ]; + accounts: [ + { + name: 'vaultInfo'; + type: { + kind: 'struct'; + fields: [ + { + name: 'walletDeskUsdcValue'; + type: 'u64'; + }, + { + name: 'authority'; + type: 'publicKey'; + }, + { + name: 'usdcMint'; + type: 'publicKey'; + }, + { + name: 'alloyxMint'; + type: 'publicKey'; + } + ]; + }; + }, + { + name: 'passInfo'; + type: { + kind: 'struct'; + fields: [ + { + name: 'investor'; + type: 'publicKey'; + } + ]; + }; + } + ]; + events: [ + { + name: 'DepositEvent'; + fields: [ + { + name: 'investor'; + type: 'publicKey'; + index: false; + }, + { + name: 'usdcAmount'; + type: 'u64'; + index: false; + }, + { + name: 'duraAmount'; + type: 'u64'; + index: false; + } + ]; + }, + { + name: 'InitializeEvent'; + fields: [ + { + name: 'authority'; + type: 'publicKey'; + index: false; + }, + { + name: 'usdcMint'; + type: 'publicKey'; + index: false; + }, + { + name: 'alloyxMint'; + type: 'publicKey'; + index: false; + } + ]; + }, + { + name: 'SetVaultInfoEvent'; + fields: [ + { + name: 'authority'; + type: 'publicKey'; + index: false; + }, + { + name: 'walletDeskAmount'; + type: 'u64'; + index: false; + } + ]; + }, + { + name: 'TransferAuthorityEvent'; + fields: [ + { + name: 'oldAuthority'; + type: 'publicKey'; + index: false; + }, + { + name: 'newAuthority'; + type: 'publicKey'; + index: false; + } + ]; + }, + { + name: 'TransferUsdcInEvent'; + fields: [ + { + name: 'authority'; + type: 'publicKey'; + index: false; + }, + { + name: 'usdcAmount'; + type: 'u64'; + index: false; + } + ]; + }, + { + name: 'TransferUsdcOutEvent'; + fields: [ + { + name: 'authority'; + type: 'publicKey'; + index: false; + }, + { + name: 'usdcAmount'; + type: 'u64'; + index: false; + } + ]; + }, + { + name: 'UnwhitelistEvent'; + fields: [ + { + name: 'authority'; + type: 'publicKey'; + index: false; + }, + { + name: 'investor'; + type: 'publicKey'; + index: false; + } + ]; + }, + { + name: 'WhitelistEvent'; + fields: [ + { + name: 'authority'; + type: 'publicKey'; + index: false; + }, + { + name: 'investor'; + type: 'publicKey'; + index: false; + } + ]; + }, + { + name: 'WithdrawEvent'; + fields: [ + { + name: 'investor'; + type: 'publicKey'; + index: false; + }, + { + name: 'usdcAmount'; + type: 'u64'; + index: false; + }, + { + name: 'duraAmount'; + type: 'u64'; + index: false; + } + ]; + } + ]; + errors: [ + { + code: 6000; + name: 'NotAdmin'; + msg: 'Not The Admin'; + }, + { + code: 6001; + name: 'NotUsdcMintDetected'; + msg: 'Not The USDC Token Type'; + }, + { + code: 6002; + name: 'NotAlloyxMintDetected'; + msg: 'Not The Alloyx Token Type'; + } + ]; +}; + +export const IDL: AlloyxSolana = { + version: '0.1.0', + name: 'alloyx_solana', + instructions: [ + { + name: 'initialize', + accounts: [ + { + name: 'signer', + isMut: true, + isSigner: true, + }, + { + name: 'usdcVaultAccount', + isMut: true, + isSigner: false, + }, + { + name: 'usdcMint', + isMut: false, + isSigner: false, + }, + { + name: 'alloyxVaultAccount', + isMut: true, + isSigner: false, + }, + { + name: 'alloyxMint', + isMut: false, + isSigner: false, + }, + { + name: 'vaultInfoAccount', + isMut: true, + isSigner: false, + }, + { + name: 'tokenProgram', + isMut: false, + isSigner: false, + }, + { + name: 'systemProgram', + isMut: false, + isSigner: false, + }, + ], + args: [ + { + name: 'vaultId', + type: 'string', + }, + ], + }, + { + name: 'whitelist', + accounts: [ + { + name: 'signer', + isMut: true, + isSigner: true, + }, + { + name: 'investorPass', + isMut: true, + isSigner: false, + }, + { + name: 'vaultInfoAccount', + isMut: false, + isSigner: false, + }, + { + name: 'systemProgram', + isMut: false, + isSigner: false, + }, + ], + args: [ + { + name: 'vaultId', + type: 'string', + }, + { + name: 'investor', + type: 'publicKey', + }, + ], + }, + { + name: 'unwhitelist', + accounts: [ + { + name: 'signer', + isMut: true, + isSigner: true, + }, + { + name: 'investorPass', + isMut: true, + isSigner: false, + }, + { + name: 'vaultInfoAccount', + isMut: false, + isSigner: false, + }, + { + name: 'systemProgram', + isMut: false, + isSigner: false, + }, + ], + args: [ + { + name: 'vaultId', + type: 'string', + }, + { + name: 'investor', + type: 'publicKey', + }, + ], + }, + { + name: 'deposit', + accounts: [ + { + name: 'signer', + isMut: true, + isSigner: true, + }, + { + name: 'investorPass', + isMut: false, + isSigner: false, + }, + { + name: 'vaultInfoAccount', + isMut: false, + isSigner: false, + }, + { + name: 'usdcVaultAccount', + isMut: true, + isSigner: false, + }, + { + name: 'usdcMint', + isMut: false, + isSigner: false, + }, + { + name: 'alloyxVaultAccount', + isMut: false, + isSigner: false, + }, + { + name: 'alloyxMint', + isMut: true, + isSigner: false, + }, + { + name: 'userUsdcAccount', + isMut: true, + isSigner: false, + }, + { + name: 'userAlloyxAccount', + isMut: true, + isSigner: false, + }, + { + name: 'tokenProgram', + isMut: false, + isSigner: false, + }, + { + name: 'associatedTokenProgram', + isMut: false, + isSigner: false, + }, + { + name: 'systemProgram', + isMut: false, + isSigner: false, + }, + ], + args: [ + { + name: 'vaultId', + type: 'string', + }, + { + name: 'usdcAmount', + type: 'u64', + }, + ], + }, + { + name: 'withdraw', + accounts: [ + { + name: 'signer', + isMut: true, + isSigner: true, + }, + { + name: 'investorPass', + isMut: false, + isSigner: false, + }, + { + name: 'vaultInfoAccount', + isMut: false, + isSigner: false, + }, + { + name: 'usdcVaultAccount', + isMut: true, + isSigner: false, + }, + { + name: 'usdcMint', + isMut: false, + isSigner: false, + }, + { + name: 'alloyxVaultAccount', + isMut: true, + isSigner: false, + }, + { + name: 'alloyxMint', + isMut: true, + isSigner: false, + }, + { + name: 'userUsdcAccount', + isMut: true, + isSigner: false, + }, + { + name: 'userAlloyxAccount', + isMut: true, + isSigner: false, + }, + { + name: 'tokenProgram', + isMut: false, + isSigner: false, + }, + { + name: 'associatedTokenProgram', + isMut: false, + isSigner: false, + }, + { + name: 'systemProgram', + isMut: false, + isSigner: false, + }, + ], + args: [ + { + name: 'vaultId', + type: 'string', + }, + { + name: 'alloyxAmount', + type: 'u64', + }, + ], + }, + { + name: 'transferUsdcOut', + accounts: [ + { + name: 'signer', + isMut: true, + isSigner: true, + }, + { + name: 'vaultInfoAccount', + isMut: true, + isSigner: false, + }, + { + name: 'usdcVaultAccount', + isMut: true, + isSigner: false, + }, + { + name: 'usdcMint', + isMut: false, + isSigner: false, + }, + { + name: 'userUsdcAccount', + isMut: true, + isSigner: false, + }, + { + name: 'tokenProgram', + isMut: false, + isSigner: false, + }, + { + name: 'associatedTokenProgram', + isMut: false, + isSigner: false, + }, + { + name: 'systemProgram', + isMut: false, + isSigner: false, + }, + ], + args: [ + { + name: 'vaultId', + type: 'string', + }, + { + name: 'amount', + type: 'u64', + }, + ], + }, + { + name: 'transferUsdcIn', + accounts: [ + { + name: 'signer', + isMut: true, + isSigner: true, + }, + { + name: 'vaultInfoAccount', + isMut: true, + isSigner: false, + }, + { + name: 'usdcVaultAccount', + isMut: true, + isSigner: false, + }, + { + name: 'usdcMint', + isMut: false, + isSigner: false, + }, + { + name: 'userUsdcAccount', + isMut: true, + isSigner: false, + }, + { + name: 'tokenProgram', + isMut: false, + isSigner: false, + }, + { + name: 'associatedTokenProgram', + isMut: false, + isSigner: false, + }, + { + name: 'systemProgram', + isMut: false, + isSigner: false, + }, + ], + args: [ + { + name: 'vaultId', + type: 'string', + }, + { + name: 'amount', + type: 'u64', + }, + ], + }, + { + name: 'setVaultInfo', + accounts: [ + { + name: 'signer', + isMut: true, + isSigner: true, + }, + { + name: 'vaultInfoAccount', + isMut: true, + isSigner: false, + }, + { + name: 'usdcMint', + isMut: false, + isSigner: false, + }, + { + name: 'systemProgram', + isMut: false, + isSigner: false, + }, + ], + args: [ + { + name: 'vaultId', + type: 'string', + }, + { + name: 'walletDeskAmount', + type: 'u64', + }, + ], + }, + { + name: 'transferAuthority', + accounts: [ + { + name: 'signer', + isMut: true, + isSigner: true, + }, + { + name: 'vaultInfoAccount', + isMut: true, + isSigner: false, + }, + { + name: 'systemProgram', + isMut: false, + isSigner: false, + }, + ], + args: [ + { + name: 'vaultId', + type: 'string', + }, + { + name: 'newAuthority', + type: 'publicKey', + }, + ], + }, + ], + accounts: [ + { + name: 'vaultInfo', + type: { + kind: 'struct', + fields: [ + { + name: 'walletDeskUsdcValue', + type: 'u64', + }, + { + name: 'authority', + type: 'publicKey', + }, + { + name: 'usdcMint', + type: 'publicKey', + }, + { + name: 'alloyxMint', + type: 'publicKey', + }, + ], + }, + }, + { + name: 'passInfo', + type: { + kind: 'struct', + fields: [ + { + name: 'investor', + type: 'publicKey', + }, + ], + }, + }, + ], + events: [ + { + name: 'DepositEvent', + fields: [ + { + name: 'investor', + type: 'publicKey', + index: false, + }, + { + name: 'usdcAmount', + type: 'u64', + index: false, + }, + { + name: 'duraAmount', + type: 'u64', + index: false, + }, + ], + }, + { + name: 'InitializeEvent', + fields: [ + { + name: 'authority', + type: 'publicKey', + index: false, + }, + { + name: 'usdcMint', + type: 'publicKey', + index: false, + }, + { + name: 'alloyxMint', + type: 'publicKey', + index: false, + }, + ], + }, + { + name: 'SetVaultInfoEvent', + fields: [ + { + name: 'authority', + type: 'publicKey', + index: false, + }, + { + name: 'walletDeskAmount', + type: 'u64', + index: false, + }, + ], + }, + { + name: 'TransferAuthorityEvent', + fields: [ + { + name: 'oldAuthority', + type: 'publicKey', + index: false, + }, + { + name: 'newAuthority', + type: 'publicKey', + index: false, + }, + ], + }, + { + name: 'TransferUsdcInEvent', + fields: [ + { + name: 'authority', + type: 'publicKey', + index: false, + }, + { + name: 'usdcAmount', + type: 'u64', + index: false, + }, + ], + }, + { + name: 'TransferUsdcOutEvent', + fields: [ + { + name: 'authority', + type: 'publicKey', + index: false, + }, + { + name: 'usdcAmount', + type: 'u64', + index: false, + }, + ], + }, + { + name: 'UnwhitelistEvent', + fields: [ + { + name: 'authority', + type: 'publicKey', + index: false, + }, + { + name: 'investor', + type: 'publicKey', + index: false, + }, + ], + }, + { + name: 'WhitelistEvent', + fields: [ + { + name: 'authority', + type: 'publicKey', + index: false, + }, + { + name: 'investor', + type: 'publicKey', + index: false, + }, + ], + }, + { + name: 'WithdrawEvent', + fields: [ + { + name: 'investor', + type: 'publicKey', + index: false, + }, + { + name: 'usdcAmount', + type: 'u64', + index: false, + }, + { + name: 'duraAmount', + type: 'u64', + index: false, + }, + ], + }, + ], + errors: [ + { + code: 6000, + name: 'NotAdmin', + msg: 'Not The Admin', + }, + { + code: 6001, + name: 'NotUsdcMintDetected', + msg: 'Not The USDC Token Type', + }, + { + code: 6002, + name: 'NotAlloyxMintDetected', + msg: 'Not The Alloyx Token Type', + }, + ], +}; diff --git a/src/alloyx_vault/depository.ts b/src/alloyx_vault/depository.ts new file mode 100644 index 0000000..92add15 --- /dev/null +++ b/src/alloyx_vault/depository.ts @@ -0,0 +1,303 @@ +import { + BorshAccountsCoder, + Wallet, + AnchorProvider, + Program, + BN, +} from '@project-serum/anchor'; +import { ConfirmOptions, Connection, PublicKey } from '@solana/web3.js'; +import { IDL } from '../idl'; +import { AlloyxVaultDepositoryAccount } from '../interfaces'; +import { getMint } from '@solana/spl-token'; +import { findATAAddrSync } from '../utils'; +import { IDL as alloyxIDL, AlloyxSolana as AlloyxIDL } from './alloyxIdl'; + +const ALLOYX_VAULT_DEPOSITORY_NAMESPACE = 'ALLOYX_VAULT_DEPOSITORY'; + +const ALLOYX_VAULT_INTERNAL_VAULT_INFO_NAMESPACE = 'vault_info'; +const ALLOYX_VAULT_INTERNAL_VAULT_COLLATERAL_NAMESPACE = 'usdc_token'; +const ALLOYX_VAULT_INTERNAL_VAULT_SHARES_NAMESPACE = 'alloyx_token'; +const ALLOYX_VAULT_INTERNAL_VAULT_PASS_NAMESPACE = 'pass'; + +export class AlloyxVaultDepository { + public constructor( + public readonly pda: PublicKey, + public readonly collateralMint: PublicKey, + public readonly collateralDecimals: number, + public readonly collateralSymbol: string, + public readonly depositoryCollateral: PublicKey, + public readonly depositoryShares: PublicKey, + public readonly alloyxVaultInfo: PublicKey, + public readonly alloyxVaultCollateral: PublicKey, + public readonly alloyxVaultShares: PublicKey, + public readonly alloyxVaultMint: PublicKey, + public readonly alloyxVaultPass: PublicKey, + public readonly alloyxProgramId: PublicKey + ) {} + + public static async initialize({ + connection, + uxdProgramId, + collateralMint, + collateralSymbol, + alloyxVaultId, + alloyxProgramId, + }: { + connection: Connection; + uxdProgramId: PublicKey; + collateralMint: PublicKey; + collateralSymbol: string; + alloyxVaultId: string; + alloyxProgramId: PublicKey; + }): Promise { + // Collateral decimals can be resolved asynchronously + const collateralDecimalsPromise = this.getCollateralDecimals( + connection, + collateralMint + ); + + // First we need to resolve the basic alloyx vault address + const alloyxVaultInfo = this.findAlloyxVaultInfoAddress( + alloyxProgramId, + alloyxVaultId + ); + + // Then derive alloyx internal accounts that depends on the above + const alloyxVaultCollateral = this.findAlloyxVaultCollateralAddress( + alloyxVaultInfo, + alloyxProgramId + ); + const alloyxVaultShares = this.findAlloyxVaultSharesAddress( + alloyxVaultCollateral, + collateralMint + ); + + // Then we can find the depository address + const depository = this.findDepositoryAddress( + alloyxVaultInfo, + collateralMint, + uxdProgramId + ); + // Then the alloyx pass which depends on the depository + const alloyxVaultPass = this.findAlloyxVaultPassAddress( + alloyxVaultInfo, + depository, + alloyxProgramId + ); + + // Then we can read the content of all alloyx accounts on chain + const alloyxProgram = this.getAlloyxProgram(connection, alloyxProgramId); + const alloyxVaultInfoAccountPromise = this.getAlloyxVaultInfoAccount( + alloyxProgram, + alloyxVaultInfo + ); + + // Wait until we have all the accounts deserialized data before progressing further + const alloyxVaultInfoAccount = await alloyxVaultInfoAccountPromise; + const alloyxProgramStateAccount = await alloyxProgramStateAccountPromise; + + // Then we can read all the informations needed from the onchain accounts + const alloyxVaultMint = alloyxVaultInfoAccount.lpTokenMint; + const alloyxTreasuryPoolCollateral = + alloyxVaultInfoAccount.treasuryPoolTokenAccount; + + // Then generate the depository token accounts + const depositoryCollateral = this.findDepositoryCollateralAddress( + depository, + collateralMint + ); + const depositoryShares = this.findDepositorySharesAddress( + depository, + alloyxVaultMint + ); + + // Resolve final informations when all scheduled work is done + const collateralDecimals = await collateralDecimalsPromise; + + // Done + return new AlloyxVaultDepository( + depository, + collateralMint, + collateralDecimals, + collateralSymbol, + depositoryCollateral, + depositoryShares, + alloyxVaultInfo, + alloyxVaultCollateral, + alloyxVaultShares, + alloyxVaultMint, + alloyxVaultPass, + alloyxProgramId + ); + } + + private static findDepositoryAddress( + alloyxVaultInfo: PublicKey, + collateralMint: PublicKey, + uxdProgramId: PublicKey + ): PublicKey { + return PublicKey.findProgramAddressSync( + [ + Buffer.from(ALLOYX_VAULT_DEPOSITORY_NAMESPACE), + alloyxVaultInfo.toBuffer(), + collateralMint.toBuffer(), + ], + uxdProgramId + )[0]; + } + + private static findDepositoryCollateralAddress( + depository: PublicKey, + collateralMint: PublicKey + ): PublicKey { + return findATAAddrSync(depository, collateralMint)[0]; + } + + private static findDepositorySharesAddress( + depository: PublicKey, + alloyxVaultMint: PublicKey + ): PublicKey { + return findATAAddrSync(depository, alloyxVaultMint)[0]; + } + + private static findAlloyxVaultInfoAddress( + alloyxVaultId: string, + alloyxProgramId: PublicKey + ): PublicKey { + return PublicKey.findProgramAddressSync( + [ + Buffer.from(alloyxVaultId), + Buffer.from(ALLOYX_VAULT_INTERNAL_VAULT_INFO_NAMESPACE), + ], + alloyxProgramId + )[0]; + } + + private static findAlloyxVaultCollateralAddress( + alloyxVaultId: string, + alloyxProgramId: PublicKey + ): PublicKey { + return PublicKey.findProgramAddressSync( + [ + Buffer.from(alloyxVaultId), + Buffer.from(ALLOYX_VAULT_INTERNAL_VAULT_COLLATERAL_NAMESPACE), + ], + alloyxProgramId + )[0]; + } + + private static findAlloyxVaultSharesAddress( + alloyxVaultId: string, + alloyxProgramId: PublicKey + ): PublicKey { + return PublicKey.findProgramAddressSync( + [ + Buffer.from(alloyxVaultId), + Buffer.from(ALLOYX_VAULT_INTERNAL_VAULT_SHARES_NAMESPACE), + ], + alloyxProgramId + )[0]; + } + + private static findAlloyxVaultPassAddress( + alloyxVaultId: PublicKey, + depository: PublicKey, + alloyxProgramId: PublicKey + ): PublicKey { + return PublicKey.findProgramAddressSync( + [ + alloyxVaultId.toBuffer(), + Buffer.from(ALLOYX_VAULT_INTERNAL_VAULT_PASS_NAMESPACE), + depository.toBuffer(), + ], + alloyxProgramId + )[0]; + } + + public static getAlloyxProgram( + connection: Connection, + alloyxProgramId: PublicKey + ): Program { + const provider = new AnchorProvider( + connection, + {} as Wallet, + AnchorProvider.defaultOptions() + ); + return new Program(alloyxIDL, alloyxProgramId, provider); + } + + public static async getAlloyxVaultInfoAccount( + alloyxProgram: Program, + alloyxVaultInfo: PublicKey + ) { + const alloyxVaultInfoAccount = + await alloyxProgram.account.vaultInfo.fetchNullable(alloyxVaultInfo); + if (!alloyxVaultInfoAccount) { + throw new Error( + 'Could not read alloyxVaultInfo account: ' + alloyxVaultInfo.toString() + ); + } + return alloyxVaultInfoAccount; + } + + public static async getAlloyxVaultPassAccount( + alloyxProgram: Program, + alloyxVaultPass: PublicKey + ) { + const alloyxVaultPassAccount = + await alloyxProgram.account.passInfo.fetchNullable(alloyxVaultPass); + if (!alloyxVaultPassAccount) { + throw new Error( + 'Could not read alloyxVaultPass account: ' + alloyxVaultPass.toString() + ); + } + return alloyxVaultPassAccount; + } + + public static async getCollateralDecimals( + connection: Connection, + collateralMint: PublicKey + ): Promise { + const collateralMintData = await getMint(connection, collateralMint); + if (!collateralMintData) { + throw new Error( + 'Could not read collateralMint account: ' + collateralMint.toString() + ); + } + return collateralMintData.decimals; + } + + public info() { + console.groupCollapsed('[Alloyx Vault Depository debug info]'); + console.table({ + pda: this.pda.toBase58(), + collateralMint: this.collateralMint.toBase58(), + collateralDecimals: this.collateralDecimals, + collateralSymbol: this.collateralSymbol, + depositoryCollateral: this.depositoryCollateral.toBase58(), + depositoryShares: this.depositoryShares.toBase58(), + alloyxVaultInfo: this.alloyxVaultInfo.toBase58(), + alloyxVaultCollateral: this.alloyxVaultCollateral.toBase58(), + alloyxVaultShares: this.alloyxVaultShares.toBase58(), + alloyxVaultMint: this.alloyxVaultMint.toBase58(), + alloyxVaultPass: this.alloyxVaultPass.toBase58(), + alloyxProgramId: this.alloyxProgramId.toBase58(), + }); + console.groupEnd(); + } + + public async getOnchainAccount( + connection: Connection, + options: ConfirmOptions + ): Promise { + const coder = new BorshAccountsCoder(IDL); + const result = await connection.getAccountInfo( + this.pda, + options.commitment + ); + if (!result) { + throw new Error('alloyxVaultDepository not found'); + } + return coder.decode('alloyxVaultDepository', result.data); + } +} diff --git a/src/idl.ts b/src/idl.ts index a62e088..abb168a 100644 --- a/src/idl.ts +++ b/src/idl.ts @@ -215,6 +215,41 @@ export type Uxd = { } ]; }, + { + name: 'editAlloyxVaultDepository'; + accounts: [ + { + name: 'authority'; + isMut: false; + isSigner: true; + docs: [ + '#1 Authored call accessible only to the signer matching Controller.authority' + ]; + }, + { + name: 'controller'; + isMut: true; + isSigner: false; + docs: [ + '#2 The top level UXDProgram on chain account managing the redeemable mint' + ]; + }, + { + name: 'depository'; + isMut: true; + isSigner: false; + docs: ['#3']; + } + ]; + args: [ + { + name: 'fields'; + type: { + defined: 'EditAlloyxVaultDepositoryFields'; + }; + } + ]; + }, { name: 'mint'; accounts: [ @@ -356,6 +391,12 @@ export type Uxd = { isSigner: false; docs: ['#22']; }, + { + name: 'alloyxVaultDepository'; + isMut: true; + isSigner: false; + docs: ['#6']; + }, { name: 'systemProgram'; isMut: false; @@ -505,6 +546,12 @@ export type Uxd = { isSigner: false; docs: ['#15']; }, + { + name: 'alloyxVaultDepository'; + isMut: true; + isSigner: false; + docs: ['#15']; + }, { name: 'systemProgram'; isMut: false; @@ -1761,31 +1808,31 @@ export type Uxd = { docs: ['#2']; }, { - name: 'identityDepository'; - isMut: true; + name: 'collateralMint'; + isMut: false; isSigner: false; docs: ['#3']; }, { - name: 'mercurialVaultDepository'; + name: 'identityDepository'; isMut: true; isSigner: false; docs: ['#4']; }, { - name: 'depository'; + name: 'mercurialVaultDepository'; isMut: true; isSigner: false; docs: ['#5']; }, { - name: 'collateralMint'; - isMut: false; + name: 'credixLpDepository'; + isMut: true; isSigner: false; docs: ['#6']; }, { - name: 'depositoryShares'; + name: 'credixLpDepositoryShares'; isMut: true; isSigner: false; docs: ['#7']; @@ -1826,17 +1873,23 @@ export type Uxd = { isSigner: false; docs: ['#13']; }, + { + name: 'alloyxVaultDepository'; + isMut: true; + isSigner: false; + docs: ['#14']; + }, { name: 'systemProgram'; isMut: false; isSigner: false; - docs: ['#14']; + docs: ['#15']; }, { name: 'credixProgram'; isMut: false; isSigner: false; - docs: ['#15']; + docs: ['#16']; } ]; args: []; @@ -1859,43 +1912,43 @@ export type Uxd = { docs: ['#2']; }, { - name: 'identityDepository'; - isMut: true; + name: 'collateralMint'; + isMut: false; isSigner: false; docs: ['#3']; }, { - name: 'identityDepositoryCollateral'; + name: 'identityDepository'; isMut: true; isSigner: false; docs: ['#4']; }, { - name: 'mercurialVaultDepository'; + name: 'identityDepositoryCollateral'; isMut: true; isSigner: false; docs: ['#5']; }, { - name: 'depository'; + name: 'mercurialVaultDepository'; isMut: true; isSigner: false; docs: ['#6']; }, { - name: 'collateralMint'; - isMut: false; + name: 'credixLpDepository'; + isMut: true; isSigner: false; docs: ['#7']; }, { - name: 'depositoryCollateral'; + name: 'credixLpDepositoryCollateral'; isMut: true; isSigner: false; docs: ['#8']; }, { - name: 'depositoryShares'; + name: 'credixLpDepositoryShares'; isMut: true; isSigner: false; docs: ['#9']; @@ -1961,165 +2014,493 @@ export type Uxd = { docs: ['#19']; }, { - name: 'profitsBeneficiaryCollateral'; + name: 'alloyxVaultDepository'; isMut: true; isSigner: false; docs: ['#20']; }, + { + name: 'profitsBeneficiaryCollateral'; + isMut: true; + isSigner: false; + docs: ['#21']; + }, { name: 'systemProgram'; isMut: false; isSigner: false; - docs: ['#21']; + docs: ['#22']; }, { name: 'tokenProgram'; isMut: false; isSigner: false; - docs: ['#22']; + docs: ['#23']; }, { name: 'associatedTokenProgram'; isMut: false; isSigner: false; - docs: ['#23']; + docs: ['#24']; }, { name: 'credixProgram'; isMut: false; isSigner: false; - docs: ['#24']; + docs: ['#25']; }, { name: 'rent'; isMut: false; isSigner: false; - docs: ['#25']; + docs: ['#26']; } ]; args: []; }, { - name: 'freezeProgram'; - docs: [ - 'Freeze or resume all ixs associated with the controller (except this one).', - '', - 'Parameters:', - '- freeze: bool param to flip the `is_frozen` property in the controller', - '', - 'Note:', - 'This is a wildcard to stop the program temporarily when a vulnerability has been detected to allow the team to do servicing work.', - '' - ]; + name: 'registerAlloyxVaultDepository'; accounts: [ { name: 'authority'; isMut: false; isSigner: true; - docs: [ - '#1 Authored call accessible only to the signer matching Controller.authority' - ]; + docs: ['#1']; + }, + { + name: 'payer'; + isMut: true; + isSigner: true; + docs: ['#2']; }, { name: 'controller'; isMut: true; isSigner: false; - docs: [ - '#2 The top level UXDProgram on chain account managing the redeemable mint' - ]; + docs: ['#3']; + }, + { + name: 'depository'; + isMut: true; + isSigner: false; + docs: ['#4']; + }, + { + name: 'collateralMint'; + isMut: false; + isSigner: false; + docs: ['#5']; + }, + { + name: 'depositoryCollateral'; + isMut: true; + isSigner: false; + docs: ['#6']; + }, + { + name: 'depositoryShares'; + isMut: true; + isSigner: false; + docs: ['#7']; + }, + { + name: 'alloyxVaultInfo'; + isMut: false; + isSigner: false; + docs: ['#8']; + }, + { + name: 'alloyxVaultCollateral'; + isMut: false; + isSigner: false; + docs: ['#9']; + }, + { + name: 'alloyxVaultShares'; + isMut: false; + isSigner: false; + docs: ['#10']; + }, + { + name: 'alloyxVaultMint'; + isMut: false; + isSigner: false; + docs: ['#11']; + }, + { + name: 'systemProgram'; + isMut: false; + isSigner: false; + docs: ['#12']; + }, + { + name: 'tokenProgram'; + isMut: false; + isSigner: false; + docs: ['#13']; + }, + { + name: 'associatedTokenProgram'; + isMut: false; + isSigner: false; + docs: ['#14']; + }, + { + name: 'rent'; + isMut: false; + isSigner: false; + docs: ['#15']; } ]; args: [ { - name: 'freeze'; - type: 'bool'; + name: 'mintingFeeInBps'; + type: 'u8'; + }, + { + name: 'redeemingFeeInBps'; + type: 'u8'; + }, + { + name: 'redeemableAmountUnderManagementCap'; + type: 'u64'; } ]; - } - ]; - accounts: [ + }, { - name: 'controller'; - type: { - kind: 'struct'; - fields: [ - { - name: 'bump'; - type: 'u8'; - }, - { - name: 'redeemableMintBump'; - type: 'u8'; - }, - { - name: 'version'; - type: 'u8'; - }, - { - name: 'authority'; - type: 'publicKey'; - }, - { - name: 'redeemableMint'; - type: 'publicKey'; - }, - { - name: 'redeemableMintDecimals'; - type: 'u8'; - }, - { - name: 'unused'; - type: { - array: ['u8', 255]; - }; - }, - { - name: 'isFrozen'; - type: 'bool'; - }, - { - name: 'unused2'; - type: 'u8'; - }, - { - name: 'redeemableGlobalSupplyCap'; - type: 'u128'; - }, + name: 'rebalanceAlloyxVaultDepository'; + accounts: [ + { + name: 'payer'; + isMut: true; + isSigner: true; + docs: ['#1']; + }, + { + name: 'payerCollateral'; + isMut: true; + isSigner: false; + docs: [ + '#2 - This account will be responsible for paying the precision loss' + ]; + }, + { + name: 'controller'; + isMut: true; + isSigner: false; + docs: ['#3']; + }, + { + name: 'collateralMint'; + isMut: false; + isSigner: false; + docs: ['#4']; + }, + { + name: 'identityDepository'; + isMut: true; + isSigner: false; + docs: ['#5']; + }, + { + name: 'identityDepositoryCollateral'; + isMut: true; + isSigner: false; + docs: ['#6']; + }, + { + name: 'mercurialVaultDepository'; + isMut: true; + isSigner: false; + docs: ['#7']; + }, + { + name: 'credixLpDepository'; + isMut: true; + isSigner: false; + docs: ['#8']; + }, + { + name: 'alloyxVaultDepository'; + isMut: true; + isSigner: false; + docs: ['#9']; + }, + { + name: 'alloyxVaultDepositoryCollateral'; + isMut: true; + isSigner: false; + docs: ['#10']; + }, + { + name: 'alloyxVaultDepositoryShares'; + isMut: true; + isSigner: false; + docs: ['#11']; + }, + { + name: 'alloyxVaultInfo'; + isMut: false; + isSigner: false; + docs: ['#12']; + }, + { + name: 'alloyxVaultCollateral'; + isMut: true; + isSigner: false; + docs: ['#13']; + }, + { + name: 'alloyxVaultShares'; + isMut: true; + isSigner: false; + docs: ['#14']; + }, + { + name: 'alloyxVaultMint'; + isMut: true; + isSigner: false; + docs: ['#15']; + }, + { + name: 'alloyxVaultPass'; + isMut: false; + isSigner: false; + docs: ['#16']; + }, + { + name: 'profitsBeneficiaryCollateral'; + isMut: true; + isSigner: false; + docs: ['#17']; + }, + { + name: 'systemProgram'; + isMut: false; + isSigner: false; + docs: ['#18']; + }, + { + name: 'tokenProgram'; + isMut: false; + isSigner: false; + docs: ['#19']; + }, + { + name: 'associatedTokenProgram'; + isMut: false; + isSigner: false; + docs: ['#20']; + }, + { + name: 'alloyxProgram'; + isMut: false; + isSigner: false; + docs: ['#21']; + } + ]; + args: [ + { + name: 'vaultId'; + type: 'string'; + } + ]; + }, + { + name: 'freezeProgram'; + docs: [ + 'Freeze or resume all ixs associated with the controller (except this one).', + '', + 'Parameters:', + '- freeze: bool param to flip the `is_frozen` property in the controller', + '', + 'Note:', + 'This is a wildcard to stop the program temporarily when a vulnerability has been detected to allow the team to do servicing work.', + '' + ]; + accounts: [ + { + name: 'authority'; + isMut: false; + isSigner: true; + docs: [ + '#1 Authored call accessible only to the signer matching Controller.authority' + ]; + }, + { + name: 'controller'; + isMut: true; + isSigner: false; + docs: [ + '#2 The top level UXDProgram on chain account managing the redeemable mint' + ]; + } + ]; + args: [ + { + name: 'freeze'; + type: 'bool'; + } + ]; + } + ]; + accounts: [ + { + name: 'alloyxVaultDepository'; + type: { + kind: 'struct'; + fields: [ { - name: 'unused3'; - type: { - array: ['u8', 8]; - }; + name: 'bump'; + type: 'u8'; }, { - name: 'redeemableCirculatingSupply'; - type: 'u128'; + name: 'version'; + type: 'u8'; }, { - name: 'unused4'; + name: 'controller'; + type: 'publicKey'; + }, + { + name: 'collateralMint'; + type: 'publicKey'; + }, + { + name: 'depositoryCollateral'; + type: 'publicKey'; + }, + { + name: 'depositoryShares'; + type: 'publicKey'; + }, + { + name: 'alloyxVaultInfo'; + type: 'publicKey'; + }, + { + name: 'alloyxVaultCollateral'; + type: 'publicKey'; + }, + { + name: 'alloyxVaultShares'; + type: 'publicKey'; + }, + { + name: 'alloyxVaultMint'; + type: 'publicKey'; + }, + { + name: 'redeemableAmountUnderManagementCap'; + type: 'u64'; + }, + { + name: 'mintingFeeInBps'; + type: 'u8'; + }, + { + name: 'redeemingFeeInBps'; + type: 'u8'; + }, + { + name: 'mintingDisabled'; + type: 'bool'; + }, + { + name: 'collateralAmountDeposited'; + type: 'u64'; + }, + { + name: 'redeemableAmountUnderManagement'; + type: 'u64'; + }, + { + name: 'mintingFeeTotalAccrued'; + type: 'u64'; + }, + { + name: 'redeemingFeeTotalAccrued'; + type: 'u64'; + }, + { + name: 'profitsTotalCollected'; + type: 'u64'; + }, + { + name: 'profitsBeneficiaryCollateral'; + type: 'publicKey'; + }, + { + name: 'reserved'; type: { - array: ['u8', 8]; + array: ['u8', 803]; }; + } + ]; + }; + }, + { + name: 'controller'; + type: { + kind: 'struct'; + fields: [ + { + name: 'bump'; + type: 'u8'; + }, + { + name: 'redeemableMintBump'; + type: 'u8'; }, { - name: 'registeredMercurialVaultDepositories'; + name: 'version'; + type: 'u8'; + }, + { + name: 'authority'; + type: 'publicKey'; + }, + { + name: 'redeemableMint'; + type: 'publicKey'; + }, + { + name: 'redeemableMintDecimals'; + type: 'u8'; + }, + { + name: 'unused'; type: { - array: ['publicKey', 4]; + array: ['u8', 255]; }; }, { - name: 'registeredMercurialVaultDepositoriesCount'; + name: 'isFrozen'; + type: 'bool'; + }, + { + name: 'unused2'; type: 'u8'; }, { - name: 'registeredCredixLpDepositories'; + name: 'redeemableGlobalSupplyCap'; + type: 'u128'; + }, + { + name: 'unused3'; type: { - array: ['publicKey', 4]; + array: ['u8', 8]; }; }, { - name: 'registeredCredixLpDepositoriesCount'; - type: 'u8'; + name: 'redeemableCirculatingSupply'; + type: 'u128'; + }, + { + name: 'unused4'; + type: { + array: ['u8', 266]; + }; }, { name: 'profitsTotalCollected'; @@ -2169,10 +2550,18 @@ export type Uxd = { name: 'lastOutflowSlot'; type: 'u64'; }, + { + name: 'alloyxVaultDepository'; + type: 'publicKey'; + }, + { + name: 'alloyxVaultDepositoryWeightBps'; + type: 'u16'; + }, { name: 'reserved'; type: { - array: ['u8', 94]; + array: ['u8', 60]; }; } ]; @@ -2480,6 +2869,44 @@ export type Uxd = { ]; }; }, + { + name: 'EditAlloyxVaultDepositoryFields'; + type: { + kind: 'struct'; + fields: [ + { + name: 'redeemableAmountUnderManagementCap'; + type: { + option: 'u64'; + }; + }, + { + name: 'mintingFeeInBps'; + type: { + option: 'u8'; + }; + }, + { + name: 'redeemingFeeInBps'; + type: { + option: 'u8'; + }; + }, + { + name: 'mintingDisabled'; + type: { + option: 'bool'; + }; + }, + { + name: 'profitsBeneficiaryCollateral'; + type: { + option: 'publicKey'; + }; + } + ]; + }; + }, { name: 'EditDepositoriesRoutingWeightBps'; type: { @@ -2496,6 +2923,10 @@ export type Uxd = { { name: 'credixLpDepositoryWeightBps'; type: 'u16'; + }, + { + name: 'alloyxVaultDepositoryWeightBps'; + type: 'u16'; } ]; }; @@ -2516,6 +2947,10 @@ export type Uxd = { { name: 'credixLpDepository'; type: 'publicKey'; + }, + { + name: 'alloyxVaultDepository'; + type: 'publicKey'; } ]; }; @@ -2755,6 +3190,11 @@ export type Uxd = { name: 'credixLpDepositoryWeightBps'; type: 'u16'; index: false; + }, + { + name: 'alloyxVaultDepositoryWeightBps'; + type: 'u16'; + index: false; } ]; }, @@ -2785,6 +3225,11 @@ export type Uxd = { name: 'credixLpDepository'; type: 'publicKey'; index: false; + }, + { + name: 'alloyxVaultDepository'; + type: 'publicKey'; + index: false; } ]; }, @@ -3308,6 +3753,41 @@ export type Uxd = { } ]; }, + { + name: 'RegisterAlloyxVaultDepositoryEvent'; + fields: [ + { + name: 'controllerVersion'; + type: 'u8'; + index: true; + }, + { + name: 'depositoryVersion'; + type: 'u8'; + index: true; + }, + { + name: 'controller'; + type: 'publicKey'; + index: true; + }, + { + name: 'depository'; + type: 'publicKey'; + index: true; + }, + { + name: 'collateralMint'; + type: 'publicKey'; + index: false; + }, + { + name: 'alloyxVaultInfo'; + type: 'publicKey'; + index: false; + } + ]; + }, { name: 'FreezeProgramEvent'; fields: [ @@ -3498,7 +3978,7 @@ export type Uxd = { { code: 6033; name: 'InvalidDepository'; - msg: 'The Depository provided is not registered with the Controller.'; + msg: 'The Depository provided is not matching the one stored in the Controller.'; }, { code: 6034; @@ -3624,6 +4104,51 @@ export type Uxd = { code: 6058; name: 'InvalidOutflowLimitPerEpochBps'; msg: 'The outflow_limit_per_epoch_bps is invalid: over 100%.'; + }, + { + code: 6059; + name: 'CollateralMintMismatch'; + msg: "The collateral_mint is not matching with the integration's collateral mint."; + }, + { + code: 6060; + name: 'CollateralMintConflict'; + msg: "The collateral_mint should not be equal to the integration's custom mint."; + }, + { + code: 6061; + name: 'CustomMintMismatch'; + msg: "The passed custom mint is not matching with the integration's mint."; + }, + { + code: 6062; + name: 'CustomMintConflict'; + msg: 'The passed custom mint should not be equal to the collateral mint.'; + }, + { + code: 6063; + name: 'InvalidAlloyxVaultInfo'; + msg: "The alloyx_vault_info account isn't the depository's one."; + }, + { + code: 6064; + name: 'InvalidAlloyxVaultCollateral'; + msg: "The alloyx_vault_collateral account isn't the depository's one."; + }, + { + code: 6065; + name: 'InvalidAlloyxVaultShares'; + msg: "The alloyx_vault_shares account isn't the depository's one."; + }, + { + code: 6066; + name: 'InvalidAlloyxVaultMint'; + msg: "The alloyx_vault_mint account isn't the depository's one."; + }, + { + code: 6067; + name: 'InvalidAlloyxVaultPass'; + msg: "The alloyx_vault_pass account isn't for the correct investor."; } ]; }; @@ -3805,13 +4330,48 @@ export const IDL: Uxd = { { name: 'fields', type: { - defined: 'EditIdentityDepositoryFields', + defined: 'EditIdentityDepositoryFields', + }, + }, + ], + }, + { + name: 'editCredixLpDepository', + accounts: [ + { + name: 'authority', + isMut: false, + isSigner: true, + docs: [ + '#1 Authored call accessible only to the signer matching Controller.authority', + ], + }, + { + name: 'controller', + isMut: true, + isSigner: false, + docs: [ + '#2 The top level UXDProgram on chain account managing the redeemable mint', + ], + }, + { + name: 'depository', + isMut: true, + isSigner: false, + docs: ['#3'], + }, + ], + args: [ + { + name: 'fields', + type: { + defined: 'EditCredixLpDepositoryFields', }, }, ], }, { - name: 'editCredixLpDepository', + name: 'editAlloyxVaultDepository', accounts: [ { name: 'authority', @@ -3840,7 +4400,7 @@ export const IDL: Uxd = { { name: 'fields', type: { - defined: 'EditCredixLpDepositoryFields', + defined: 'EditAlloyxVaultDepositoryFields', }, }, ], @@ -3986,6 +4546,12 @@ export const IDL: Uxd = { isSigner: false, docs: ['#22'], }, + { + name: 'alloyxVaultDepository', + isMut: true, + isSigner: false, + docs: ['#6'], + }, { name: 'systemProgram', isMut: false, @@ -4135,6 +4701,12 @@ export const IDL: Uxd = { isSigner: false, docs: ['#15'], }, + { + name: 'alloyxVaultDepository', + isMut: true, + isSigner: false, + docs: ['#15'], + }, { name: 'systemProgram', isMut: false, @@ -4757,85 +5329,339 @@ export const IDL: Uxd = { docs: ['#2'], }, { - name: 'payer', + name: 'payer', + isMut: true, + isSigner: true, + docs: ['#3'], + }, + { + name: 'controller', + isMut: true, + isSigner: false, + docs: [ + '#4 The top level UXDProgram on chain account managing the redeemable mint', + ], + }, + { + name: 'depository', + isMut: true, + isSigner: false, + docs: [ + '#5 UXDProgram on chain account bound to a Controller instance that represent the blank minting/redeeming', + ], + }, + { + name: 'collateralVault', + isMut: true, + isSigner: false, + docs: ['#6', 'Token account holding the collateral from minting'], + }, + { + name: 'redeemableMint', + isMut: true, + isSigner: false, + docs: [ + '#7 The redeemable mint managed by the `controller` instance', + 'Tokens will be burnt during this instruction', + ], + }, + { + name: 'userCollateral', + isMut: true, + isSigner: false, + docs: [ + "#8 The `user`'s ATA for the `depository`'s `collateral_mint`", + 'Will be credited during this instruction', + ], + }, + { + name: 'userRedeemable', + isMut: true, + isSigner: false, + docs: [ + "#9 The `user`'s ATA for the `controller`'s `redeemable_mint`", + 'Will be debited during this instruction', + ], + }, + { + name: 'systemProgram', + isMut: false, + isSigner: false, + docs: ['#10'], + }, + { + name: 'tokenProgram', + isMut: false, + isSigner: false, + docs: ['#11'], + }, + ], + args: [ + { + name: 'redeemableAmount', + type: 'u64', + }, + ], + }, + { + name: 'registerCredixLpDepository', + accounts: [ + { + name: 'authority', + isMut: false, + isSigner: true, + docs: ['#1'], + }, + { + name: 'payer', + isMut: true, + isSigner: true, + docs: ['#2'], + }, + { + name: 'controller', + isMut: true, + isSigner: false, + docs: ['#3'], + }, + { + name: 'depository', + isMut: true, + isSigner: false, + docs: ['#4'], + }, + { + name: 'collateralMint', + isMut: false, + isSigner: false, + docs: ['#5'], + }, + { + name: 'depositoryCollateral', + isMut: true, + isSigner: false, + docs: ['#6'], + }, + { + name: 'depositoryShares', + isMut: true, + isSigner: false, + docs: ['#7'], + }, + { + name: 'credixProgramState', + isMut: false, + isSigner: false, + docs: ['#8'], + }, + { + name: 'credixGlobalMarketState', + isMut: false, + isSigner: false, + docs: ['#9'], + }, + { + name: 'credixSigningAuthority', + isMut: false, + isSigner: false, + docs: ['#10'], + }, + { + name: 'credixLiquidityCollateral', + isMut: false, + isSigner: false, + docs: ['#11'], + }, + { + name: 'credixSharesMint', + isMut: false, + isSigner: false, + docs: ['#12'], + }, + { + name: 'systemProgram', + isMut: false, + isSigner: false, + docs: ['#13'], + }, + { + name: 'tokenProgram', + isMut: false, + isSigner: false, + docs: ['#14'], + }, + { + name: 'associatedTokenProgram', + isMut: false, + isSigner: false, + docs: ['#15'], + }, + { + name: 'rent', + isMut: false, + isSigner: false, + docs: ['#16'], + }, + ], + args: [ + { + name: 'mintingFeeInBps', + type: 'u8', + }, + { + name: 'redeemingFeeInBps', + type: 'u8', + }, + { + name: 'redeemableAmountUnderManagementCap', + type: 'u128', + }, + ], + }, + { + name: 'mintWithCredixLpDepository', + accounts: [ + { + name: 'authority', + isMut: false, + isSigner: true, + docs: [ + '#1 This IX should only be accessible by the router or the DAO', + ], + }, + { + name: 'user', + isMut: false, + isSigner: true, + docs: ['#2'], + }, + { + name: 'payer', + isMut: true, + isSigner: true, + docs: ['#3'], + }, + { + name: 'controller', + isMut: true, + isSigner: false, + docs: ['#4'], + }, + { + name: 'depository', + isMut: true, + isSigner: false, + docs: ['#5'], + }, + { + name: 'redeemableMint', + isMut: true, + isSigner: false, + docs: ['#6'], + }, + { + name: 'collateralMint', + isMut: false, + isSigner: false, + docs: ['#7'], + }, + { + name: 'userRedeemable', + isMut: true, + isSigner: false, + docs: ['#8'], + }, + { + name: 'userCollateral', isMut: true, - isSigner: true, - docs: ['#3'], + isSigner: false, + docs: ['#9'], }, { - name: 'controller', + name: 'depositoryCollateral', isMut: true, isSigner: false, - docs: [ - '#4 The top level UXDProgram on chain account managing the redeemable mint', - ], + docs: ['#10'], }, { - name: 'depository', + name: 'depositoryShares', isMut: true, isSigner: false, - docs: [ - '#5 UXDProgram on chain account bound to a Controller instance that represent the blank minting/redeeming', - ], + docs: ['#11'], }, { - name: 'collateralVault', - isMut: true, + name: 'credixGlobalMarketState', + isMut: false, isSigner: false, - docs: ['#6', 'Token account holding the collateral from minting'], + docs: ['#12'], }, { - name: 'redeemableMint', - isMut: true, + name: 'credixSigningAuthority', + isMut: false, isSigner: false, - docs: [ - '#7 The redeemable mint managed by the `controller` instance', - 'Tokens will be burnt during this instruction', - ], + docs: ['#13'], }, { - name: 'userCollateral', + name: 'credixLiquidityCollateral', isMut: true, isSigner: false, - docs: [ - "#8 The `user`'s ATA for the `depository`'s `collateral_mint`", - 'Will be credited during this instruction', - ], + docs: ['#14'], }, { - name: 'userRedeemable', + name: 'credixSharesMint', isMut: true, isSigner: false, - docs: [ - "#9 The `user`'s ATA for the `controller`'s `redeemable_mint`", - 'Will be debited during this instruction', - ], + docs: ['#15'], + }, + { + name: 'credixPass', + isMut: false, + isSigner: false, + docs: ['#16'], }, { name: 'systemProgram', isMut: false, isSigner: false, - docs: ['#10'], + docs: ['#17'], }, { name: 'tokenProgram', isMut: false, isSigner: false, - docs: ['#11'], + docs: ['#18'], + }, + { + name: 'associatedTokenProgram', + isMut: false, + isSigner: false, + docs: ['#19'], + }, + { + name: 'credixProgram', + isMut: false, + isSigner: false, + docs: ['#20'], + }, + { + name: 'rent', + isMut: false, + isSigner: false, + docs: ['#21'], }, ], args: [ { - name: 'redeemableAmount', + name: 'collateralAmount', type: 'u64', }, ], }, { - name: 'registerCredixLpDepository', + name: 'redeemFromCredixLpDepository', accounts: [ { - name: 'authority', + name: 'user', isMut: false, isSigner: true, docs: ['#1'], @@ -4858,192 +5684,230 @@ export const IDL: Uxd = { isSigner: false, docs: ['#4'], }, + { + name: 'redeemableMint', + isMut: true, + isSigner: false, + docs: ['#5'], + }, { name: 'collateralMint', isMut: false, isSigner: false, - docs: ['#5'], + docs: ['#6'], + }, + { + name: 'userRedeemable', + isMut: true, + isSigner: false, + docs: ['#7'], + }, + { + name: 'userCollateral', + isMut: true, + isSigner: false, + docs: ['#8'], }, { name: 'depositoryCollateral', isMut: true, isSigner: false, - docs: ['#6'], + docs: ['#9'], }, { name: 'depositoryShares', isMut: true, isSigner: false, - docs: ['#7'], + docs: ['#10'], }, { name: 'credixProgramState', isMut: false, isSigner: false, - docs: ['#8'], + docs: ['#11'], }, { name: 'credixGlobalMarketState', - isMut: false, + isMut: true, isSigner: false, - docs: ['#9'], + docs: ['#12'], }, { name: 'credixSigningAuthority', isMut: false, isSigner: false, - docs: ['#10'], + docs: ['#13'], }, { name: 'credixLiquidityCollateral', - isMut: false, + isMut: true, isSigner: false, - docs: ['#11'], + docs: ['#14'], }, { name: 'credixSharesMint', + isMut: true, + isSigner: false, + docs: ['#15'], + }, + { + name: 'credixPass', isMut: false, isSigner: false, - docs: ['#12'], + docs: ['#16'], + }, + { + name: 'credixTreasuryPoolCollateral', + isMut: true, + isSigner: false, + docs: ['#17'], + }, + { + name: 'credixTreasury', + isMut: false, + isSigner: false, + docs: ['#18'], + }, + { + name: 'credixTreasuryCollateral', + isMut: true, + isSigner: false, + docs: ['#19'], }, { name: 'systemProgram', isMut: false, isSigner: false, - docs: ['#13'], + docs: ['#20'], }, { name: 'tokenProgram', isMut: false, isSigner: false, - docs: ['#14'], + docs: ['#21'], }, { name: 'associatedTokenProgram', isMut: false, isSigner: false, - docs: ['#15'], + docs: ['#22'], + }, + { + name: 'credixProgram', + isMut: false, + isSigner: false, + docs: ['#23'], }, { name: 'rent', isMut: false, isSigner: false, - docs: ['#16'], + docs: ['#24'], }, ], args: [ { - name: 'mintingFeeInBps', - type: 'u8', - }, - { - name: 'redeemingFeeInBps', - type: 'u8', - }, - { - name: 'redeemableAmountUnderManagementCap', - type: 'u128', + name: 'redeemableAmount', + type: 'u64', }, ], }, { - name: 'mintWithCredixLpDepository', + name: 'collectProfitsOfCredixLpDepository', accounts: [ { - name: 'authority', - isMut: false, + name: 'payer', + isMut: true, isSigner: true, - docs: [ - '#1 This IX should only be accessible by the router or the DAO', - ], + docs: ['#1'], }, { - name: 'user', - isMut: false, - isSigner: true, + name: 'controller', + isMut: true, + isSigner: false, docs: ['#2'], }, { - name: 'payer', + name: 'depository', isMut: true, - isSigner: true, + isSigner: false, docs: ['#3'], }, { - name: 'controller', - isMut: true, + name: 'collateralMint', + isMut: false, isSigner: false, docs: ['#4'], }, { - name: 'depository', + name: 'depositoryCollateral', isMut: true, isSigner: false, docs: ['#5'], }, { - name: 'redeemableMint', + name: 'depositoryShares', isMut: true, isSigner: false, docs: ['#6'], }, { - name: 'collateralMint', + name: 'credixProgramState', isMut: false, isSigner: false, docs: ['#7'], }, { - name: 'userRedeemable', + name: 'credixGlobalMarketState', isMut: true, isSigner: false, docs: ['#8'], }, { - name: 'userCollateral', - isMut: true, + name: 'credixSigningAuthority', + isMut: false, isSigner: false, docs: ['#9'], }, { - name: 'depositoryCollateral', + name: 'credixLiquidityCollateral', isMut: true, isSigner: false, docs: ['#10'], }, { - name: 'depositoryShares', + name: 'credixSharesMint', isMut: true, isSigner: false, docs: ['#11'], }, { - name: 'credixGlobalMarketState', - isMut: false, + name: 'credixPass', + isMut: true, isSigner: false, docs: ['#12'], }, { - name: 'credixSigningAuthority', - isMut: false, + name: 'credixTreasuryPoolCollateral', + isMut: true, isSigner: false, docs: ['#13'], }, { - name: 'credixLiquidityCollateral', - isMut: true, + name: 'credixTreasury', + isMut: false, isSigner: false, docs: ['#14'], }, { - name: 'credixSharesMint', + name: 'credixTreasuryCollateral', isMut: true, isSigner: false, docs: ['#15'], }, { - name: 'credixPass', - isMut: false, + name: 'profitsBeneficiaryCollateral', + isMut: true, isSigner: false, docs: ['#16'], }, @@ -5078,176 +5942,123 @@ export const IDL: Uxd = { docs: ['#21'], }, ], - args: [ - { - name: 'collateralAmount', - type: 'u64', - }, - ], + args: [], }, { - name: 'redeemFromCredixLpDepository', - accounts: [ - { - name: 'user', - isMut: false, - isSigner: true, - docs: ['#1'], - }, - { - name: 'payer', - isMut: true, - isSigner: true, - docs: ['#2'], - }, - { - name: 'controller', - isMut: true, - isSigner: false, - docs: ['#3'], - }, + name: 'rebalanceCreateWithdrawRequestFromCredixLpDepository', + accounts: [ { - name: 'depository', + name: 'payer', isMut: true, - isSigner: false, - docs: ['#4'], + isSigner: true, + docs: [ + '#1', + 'Permissionless IX that can be called by anyone at any time', + ], }, { - name: 'redeemableMint', + name: 'controller', isMut: true, isSigner: false, - docs: ['#5'], + docs: ['#2'], }, { name: 'collateralMint', isMut: false, isSigner: false, - docs: ['#6'], + docs: ['#3'], }, { - name: 'userRedeemable', + name: 'identityDepository', isMut: true, isSigner: false, - docs: ['#7'], + docs: ['#4'], }, { - name: 'userCollateral', + name: 'mercurialVaultDepository', isMut: true, isSigner: false, - docs: ['#8'], + docs: ['#5'], }, { - name: 'depositoryCollateral', + name: 'credixLpDepository', isMut: true, isSigner: false, - docs: ['#9'], + docs: ['#6'], }, { - name: 'depositoryShares', + name: 'credixLpDepositoryShares', isMut: true, isSigner: false, - docs: ['#10'], - }, - { - name: 'credixProgramState', - isMut: false, - isSigner: false, - docs: ['#11'], + docs: ['#7'], }, { name: 'credixGlobalMarketState', - isMut: true, + isMut: false, isSigner: false, - docs: ['#12'], + docs: ['#8'], }, { name: 'credixSigningAuthority', isMut: false, isSigner: false, - docs: ['#13'], + docs: ['#9'], }, { name: 'credixLiquidityCollateral', isMut: true, isSigner: false, - docs: ['#14'], + docs: ['#10'], }, { name: 'credixSharesMint', isMut: true, isSigner: false, - docs: ['#15'], + docs: ['#11'], }, { name: 'credixPass', isMut: false, isSigner: false, - docs: ['#16'], + docs: ['#12'], }, { - name: 'credixTreasuryPoolCollateral', + name: 'credixWithdrawEpoch', isMut: true, isSigner: false, - docs: ['#17'], - }, - { - name: 'credixTreasury', - isMut: false, - isSigner: false, - docs: ['#18'], + docs: ['#13'], }, { - name: 'credixTreasuryCollateral', + name: 'alloyxVaultDepository', isMut: true, isSigner: false, - docs: ['#19'], + docs: ['#14'], }, { name: 'systemProgram', isMut: false, isSigner: false, - docs: ['#20'], - }, - { - name: 'tokenProgram', - isMut: false, - isSigner: false, - docs: ['#21'], - }, - { - name: 'associatedTokenProgram', - isMut: false, - isSigner: false, - docs: ['#22'], + docs: ['#15'], }, { name: 'credixProgram', isMut: false, isSigner: false, - docs: ['#23'], - }, - { - name: 'rent', - isMut: false, - isSigner: false, - docs: ['#24'], - }, - ], - args: [ - { - name: 'redeemableAmount', - type: 'u64', + docs: ['#16'], }, ], + args: [], }, { - name: 'collectProfitsOfCredixLpDepository', + name: 'rebalanceRedeemWithdrawRequestFromCredixLpDepository', accounts: [ { name: 'payer', isMut: true, isSigner: true, - docs: ['#1'], + docs: [ + '#1 // Permissionless IX that can be called by anyone at any time', + ], }, { name: 'controller', @@ -5256,161 +6067,188 @@ export const IDL: Uxd = { docs: ['#2'], }, { - name: 'depository', - isMut: true, + name: 'collateralMint', + isMut: false, isSigner: false, docs: ['#3'], }, { - name: 'collateralMint', - isMut: false, + name: 'identityDepository', + isMut: true, isSigner: false, docs: ['#4'], }, { - name: 'depositoryCollateral', + name: 'identityDepositoryCollateral', isMut: true, isSigner: false, docs: ['#5'], }, { - name: 'depositoryShares', + name: 'mercurialVaultDepository', isMut: true, isSigner: false, docs: ['#6'], }, + { + name: 'credixLpDepository', + isMut: true, + isSigner: false, + docs: ['#7'], + }, + { + name: 'credixLpDepositoryCollateral', + isMut: true, + isSigner: false, + docs: ['#8'], + }, + { + name: 'credixLpDepositoryShares', + isMut: true, + isSigner: false, + docs: ['#9'], + }, { name: 'credixProgramState', isMut: false, isSigner: false, - docs: ['#7'], + docs: ['#10'], }, { name: 'credixGlobalMarketState', isMut: true, isSigner: false, - docs: ['#8'], + docs: ['#11'], }, { name: 'credixSigningAuthority', isMut: false, isSigner: false, - docs: ['#9'], + docs: ['#12'], }, { name: 'credixLiquidityCollateral', isMut: true, isSigner: false, - docs: ['#10'], + docs: ['#13'], }, { name: 'credixSharesMint', isMut: true, isSigner: false, - docs: ['#11'], + docs: ['#14'], }, { name: 'credixPass', isMut: true, isSigner: false, - docs: ['#12'], + docs: ['#15'], }, { name: 'credixTreasuryPoolCollateral', isMut: true, isSigner: false, - docs: ['#13'], + docs: ['#16'], }, { name: 'credixTreasury', isMut: false, isSigner: false, - docs: ['#14'], + docs: ['#17'], }, { name: 'credixTreasuryCollateral', isMut: true, isSigner: false, - docs: ['#15'], + docs: ['#18'], + }, + { + name: 'credixWithdrawEpoch', + isMut: true, + isSigner: false, + docs: ['#19'], + }, + { + name: 'alloyxVaultDepository', + isMut: true, + isSigner: false, + docs: ['#20'], }, { name: 'profitsBeneficiaryCollateral', isMut: true, isSigner: false, - docs: ['#16'], + docs: ['#21'], }, { name: 'systemProgram', isMut: false, isSigner: false, - docs: ['#17'], + docs: ['#22'], }, { name: 'tokenProgram', isMut: false, isSigner: false, - docs: ['#18'], + docs: ['#23'], }, { name: 'associatedTokenProgram', isMut: false, isSigner: false, - docs: ['#19'], + docs: ['#24'], }, { name: 'credixProgram', isMut: false, isSigner: false, - docs: ['#20'], + docs: ['#25'], }, { name: 'rent', isMut: false, isSigner: false, - docs: ['#21'], + docs: ['#26'], }, ], args: [], }, { - name: 'rebalanceCreateWithdrawRequestFromCredixLpDepository', + name: 'registerAlloyxVaultDepository', accounts: [ { - name: 'payer', - isMut: true, + name: 'authority', + isMut: false, isSigner: true, - docs: [ - '#1', - 'Permissionless IX that can be called by anyone at any time', - ], + docs: ['#1'], }, { - name: 'controller', + name: 'payer', isMut: true, - isSigner: false, + isSigner: true, docs: ['#2'], }, { - name: 'identityDepository', + name: 'controller', isMut: true, isSigner: false, docs: ['#3'], }, { - name: 'mercurialVaultDepository', + name: 'depository', isMut: true, isSigner: false, docs: ['#4'], }, { - name: 'depository', - isMut: true, + name: 'collateralMint', + isMut: false, isSigner: false, docs: ['#5'], }, { - name: 'collateralMint', - isMut: false, + name: 'depositoryCollateral', + isMut: true, isSigner: false, docs: ['#6'], }, @@ -5421,213 +6259,207 @@ export const IDL: Uxd = { docs: ['#7'], }, { - name: 'credixGlobalMarketState', + name: 'alloyxVaultInfo', isMut: false, isSigner: false, docs: ['#8'], }, { - name: 'credixSigningAuthority', + name: 'alloyxVaultCollateral', isMut: false, isSigner: false, docs: ['#9'], }, { - name: 'credixLiquidityCollateral', - isMut: true, + name: 'alloyxVaultShares', + isMut: false, isSigner: false, docs: ['#10'], }, { - name: 'credixSharesMint', - isMut: true, + name: 'alloyxVaultMint', + isMut: false, isSigner: false, docs: ['#11'], }, { - name: 'credixPass', + name: 'systemProgram', isMut: false, isSigner: false, docs: ['#12'], }, { - name: 'credixWithdrawEpoch', - isMut: true, + name: 'tokenProgram', + isMut: false, isSigner: false, docs: ['#13'], }, { - name: 'systemProgram', + name: 'associatedTokenProgram', isMut: false, isSigner: false, docs: ['#14'], }, { - name: 'credixProgram', + name: 'rent', isMut: false, isSigner: false, docs: ['#15'], }, ], - args: [], + args: [ + { + name: 'mintingFeeInBps', + type: 'u8', + }, + { + name: 'redeemingFeeInBps', + type: 'u8', + }, + { + name: 'redeemableAmountUnderManagementCap', + type: 'u64', + }, + ], }, { - name: 'rebalanceRedeemWithdrawRequestFromCredixLpDepository', + name: 'rebalanceAlloyxVaultDepository', accounts: [ { name: 'payer', isMut: true, isSigner: true, - docs: [ - '#1 // Permissionless IX that can be called by anyone at any time', - ], + docs: ['#1'], }, { - name: 'controller', + name: 'payerCollateral', isMut: true, isSigner: false, - docs: ['#2'], + docs: [ + '#2 - This account will be responsible for paying the precision loss', + ], }, { - name: 'identityDepository', + name: 'controller', isMut: true, isSigner: false, docs: ['#3'], }, { - name: 'identityDepositoryCollateral', - isMut: true, + name: 'collateralMint', + isMut: false, isSigner: false, docs: ['#4'], }, { - name: 'mercurialVaultDepository', + name: 'identityDepository', isMut: true, isSigner: false, docs: ['#5'], }, { - name: 'depository', + name: 'identityDepositoryCollateral', isMut: true, isSigner: false, docs: ['#6'], }, { - name: 'collateralMint', - isMut: false, + name: 'mercurialVaultDepository', + isMut: true, isSigner: false, docs: ['#7'], }, { - name: 'depositoryCollateral', + name: 'credixLpDepository', isMut: true, isSigner: false, docs: ['#8'], }, { - name: 'depositoryShares', + name: 'alloyxVaultDepository', isMut: true, isSigner: false, docs: ['#9'], }, { - name: 'credixProgramState', - isMut: false, + name: 'alloyxVaultDepositoryCollateral', + isMut: true, isSigner: false, docs: ['#10'], }, { - name: 'credixGlobalMarketState', + name: 'alloyxVaultDepositoryShares', isMut: true, isSigner: false, docs: ['#11'], }, { - name: 'credixSigningAuthority', + name: 'alloyxVaultInfo', isMut: false, isSigner: false, docs: ['#12'], }, { - name: 'credixLiquidityCollateral', + name: 'alloyxVaultCollateral', isMut: true, isSigner: false, docs: ['#13'], }, { - name: 'credixSharesMint', + name: 'alloyxVaultShares', isMut: true, isSigner: false, docs: ['#14'], }, { - name: 'credixPass', + name: 'alloyxVaultMint', isMut: true, isSigner: false, docs: ['#15'], }, { - name: 'credixTreasuryPoolCollateral', - isMut: true, - isSigner: false, - docs: ['#16'], - }, - { - name: 'credixTreasury', + name: 'alloyxVaultPass', isMut: false, isSigner: false, - docs: ['#17'], - }, - { - name: 'credixTreasuryCollateral', - isMut: true, - isSigner: false, - docs: ['#18'], - }, - { - name: 'credixWithdrawEpoch', - isMut: true, - isSigner: false, - docs: ['#19'], + docs: ['#16'], }, { name: 'profitsBeneficiaryCollateral', isMut: true, isSigner: false, - docs: ['#20'], + docs: ['#17'], }, { name: 'systemProgram', isMut: false, isSigner: false, - docs: ['#21'], + docs: ['#18'], }, { name: 'tokenProgram', isMut: false, isSigner: false, - docs: ['#22'], + docs: ['#19'], }, { name: 'associatedTokenProgram', isMut: false, isSigner: false, - docs: ['#23'], + docs: ['#20'], }, { - name: 'credixProgram', + name: 'alloyxProgram', isMut: false, isSigner: false, - docs: ['#24'], + docs: ['#21'], }, + ], + args: [ { - name: 'rent', - isMut: false, - isSigner: false, - docs: ['#25'], + name: 'vaultId', + type: 'string', }, ], - args: [], }, { name: 'freezeProgram', @@ -5668,6 +6500,100 @@ export const IDL: Uxd = { }, ], accounts: [ + { + name: 'alloyxVaultDepository', + type: { + kind: 'struct', + fields: [ + { + name: 'bump', + type: 'u8', + }, + { + name: 'version', + type: 'u8', + }, + { + name: 'controller', + type: 'publicKey', + }, + { + name: 'collateralMint', + type: 'publicKey', + }, + { + name: 'depositoryCollateral', + type: 'publicKey', + }, + { + name: 'depositoryShares', + type: 'publicKey', + }, + { + name: 'alloyxVaultInfo', + type: 'publicKey', + }, + { + name: 'alloyxVaultCollateral', + type: 'publicKey', + }, + { + name: 'alloyxVaultShares', + type: 'publicKey', + }, + { + name: 'alloyxVaultMint', + type: 'publicKey', + }, + { + name: 'redeemableAmountUnderManagementCap', + type: 'u64', + }, + { + name: 'mintingFeeInBps', + type: 'u8', + }, + { + name: 'redeemingFeeInBps', + type: 'u8', + }, + { + name: 'mintingDisabled', + type: 'bool', + }, + { + name: 'collateralAmountDeposited', + type: 'u64', + }, + { + name: 'redeemableAmountUnderManagement', + type: 'u64', + }, + { + name: 'mintingFeeTotalAccrued', + type: 'u64', + }, + { + name: 'redeemingFeeTotalAccrued', + type: 'u64', + }, + { + name: 'profitsTotalCollected', + type: 'u64', + }, + { + name: 'profitsBeneficiaryCollateral', + type: 'publicKey', + }, + { + name: 'reserved', + type: { + array: ['u8', 803], + }, + }, + ], + }, + }, { name: 'controller', type: { @@ -5728,29 +6654,9 @@ export const IDL: Uxd = { { name: 'unused4', type: { - array: ['u8', 8], - }, - }, - { - name: 'registeredMercurialVaultDepositories', - type: { - array: ['publicKey', 4], - }, - }, - { - name: 'registeredMercurialVaultDepositoriesCount', - type: 'u8', - }, - { - name: 'registeredCredixLpDepositories', - type: { - array: ['publicKey', 4], + array: ['u8', 266], }, }, - { - name: 'registeredCredixLpDepositoriesCount', - type: 'u8', - }, { name: 'profitsTotalCollected', type: 'u128', @@ -5799,10 +6705,18 @@ export const IDL: Uxd = { name: 'lastOutflowSlot', type: 'u64', }, + { + name: 'alloyxVaultDepository', + type: 'publicKey', + }, + { + name: 'alloyxVaultDepositoryWeightBps', + type: 'u16', + }, { name: 'reserved', type: { - array: ['u8', 94], + array: ['u8', 60], }, }, ], @@ -6110,6 +7024,44 @@ export const IDL: Uxd = { ], }, }, + { + name: 'EditAlloyxVaultDepositoryFields', + type: { + kind: 'struct', + fields: [ + { + name: 'redeemableAmountUnderManagementCap', + type: { + option: 'u64', + }, + }, + { + name: 'mintingFeeInBps', + type: { + option: 'u8', + }, + }, + { + name: 'redeemingFeeInBps', + type: { + option: 'u8', + }, + }, + { + name: 'mintingDisabled', + type: { + option: 'bool', + }, + }, + { + name: 'profitsBeneficiaryCollateral', + type: { + option: 'publicKey', + }, + }, + ], + }, + }, { name: 'EditDepositoriesRoutingWeightBps', type: { @@ -6127,6 +7079,10 @@ export const IDL: Uxd = { name: 'credixLpDepositoryWeightBps', type: 'u16', }, + { + name: 'alloyxVaultDepositoryWeightBps', + type: 'u16', + }, ], }, }, @@ -6147,6 +7103,10 @@ export const IDL: Uxd = { name: 'credixLpDepository', type: 'publicKey', }, + { + name: 'alloyxVaultDepository', + type: 'publicKey', + }, ], }, }, @@ -6386,6 +7346,11 @@ export const IDL: Uxd = { type: 'u16', index: false, }, + { + name: 'alloyxVaultDepositoryWeightBps', + type: 'u16', + index: false, + }, ], }, { @@ -6416,6 +7381,11 @@ export const IDL: Uxd = { type: 'publicKey', index: false, }, + { + name: 'alloyxVaultDepository', + type: 'publicKey', + index: false, + }, ], }, { @@ -6938,6 +7908,41 @@ export const IDL: Uxd = { }, ], }, + { + name: 'RegisterAlloyxVaultDepositoryEvent', + fields: [ + { + name: 'controllerVersion', + type: 'u8', + index: true, + }, + { + name: 'depositoryVersion', + type: 'u8', + index: true, + }, + { + name: 'controller', + type: 'publicKey', + index: true, + }, + { + name: 'depository', + type: 'publicKey', + index: true, + }, + { + name: 'collateralMint', + type: 'publicKey', + index: false, + }, + { + name: 'alloyxVaultInfo', + type: 'publicKey', + index: false, + }, + ], + }, { name: 'FreezeProgramEvent', fields: [ @@ -7128,7 +8133,7 @@ export const IDL: Uxd = { { code: 6033, name: 'InvalidDepository', - msg: 'The Depository provided is not registered with the Controller.', + msg: 'The Depository provided is not matching the one stored in the Controller.', }, { code: 6034, @@ -7255,5 +8260,50 @@ export const IDL: Uxd = { name: 'InvalidOutflowLimitPerEpochBps', msg: 'The outflow_limit_per_epoch_bps is invalid: over 100%.', }, + { + code: 6059, + name: 'CollateralMintMismatch', + msg: "The collateral_mint is not matching with the integration's collateral mint.", + }, + { + code: 6060, + name: 'CollateralMintConflict', + msg: "The collateral_mint should not be equal to the integration's custom mint.", + }, + { + code: 6061, + name: 'CustomMintMismatch', + msg: "The passed custom mint is not matching with the integration's mint.", + }, + { + code: 6062, + name: 'CustomMintConflict', + msg: 'The passed custom mint should not be equal to the collateral mint.', + }, + { + code: 6063, + name: 'InvalidAlloyxVaultInfo', + msg: "The alloyx_vault_info account isn't the depository's one.", + }, + { + code: 6064, + name: 'InvalidAlloyxVaultCollateral', + msg: "The alloyx_vault_collateral account isn't the depository's one.", + }, + { + code: 6065, + name: 'InvalidAlloyxVaultShares', + msg: "The alloyx_vault_shares account isn't the depository's one.", + }, + { + code: 6066, + name: 'InvalidAlloyxVaultMint', + msg: "The alloyx_vault_mint account isn't the depository's one.", + }, + { + code: 6067, + name: 'InvalidAlloyxVaultPass', + msg: "The alloyx_vault_pass account isn't for the correct investor.", + }, ], }; diff --git a/src/interfaces.ts b/src/interfaces.ts index d77439a..23e3dc2 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -94,3 +94,27 @@ export class CredixLpDepositoryAccount { profitsTotalCollected!: BN; // u128 profitsBeneficiaryCollateral!: PublicKey; } + +// V1 +export class AlloyxVaultDepositoryAccount { + bump!: number; // u8 + version!: number; // u8 + controller!: PublicKey; + collateralMint!: PublicKey; + depositoryCollateral!: PublicKey; + depositoryShares!: PublicKey; + alloyxVaultInfo!: PublicKey; + alloyxVaultCollateral!: PublicKey; + alloyxVaultShares!: PublicKey; + alloyxVaultMint!: PublicKey; + redeemableAmountUnderManagementCap!: BN; // u64 + mintingFeeInBps!: number; // u8 + redeemingFeeInBps!: number; // u8 + mintingDisabled!: boolean; + collateralAmountDeposited!: BN; // u64 + redeemableAmountUnderManagement!: BN; // u64 + mintingFeeTotalAccrued!: BN; // u64 + redeemingFeeTotalAccrued!: BN; // u64 + profitsTotalCollected!: BN; // u64 + profitsBeneficiaryCollateral!: PublicKey; +} From 4fe351841957630c9e55ba27649f3bb2b90bc274 Mon Sep 17 00:00:00 2001 From: Vincent Brunet Date: Thu, 2 Nov 2023 18:09:13 +0900 Subject: [PATCH 02/12] fix-compilation --- src/alloyx_vault/depository.ts | 29 ++++------------- src/client.ts | 58 ++++++++++++++++++---------------- 2 files changed, 37 insertions(+), 50 deletions(-) diff --git a/src/alloyx_vault/depository.ts b/src/alloyx_vault/depository.ts index 92add15..cbce065 100644 --- a/src/alloyx_vault/depository.ts +++ b/src/alloyx_vault/depository.ts @@ -3,7 +3,6 @@ import { Wallet, AnchorProvider, Program, - BN, } from '@project-serum/anchor'; import { ConfirmOptions, Connection, PublicKey } from '@solana/web3.js'; import { IDL } from '../idl'; @@ -41,6 +40,7 @@ export class AlloyxVaultDepository { collateralMint, collateralSymbol, alloyxVaultId, + alloyxVaultMint, alloyxProgramId, }: { connection: Connection; @@ -48,6 +48,7 @@ export class AlloyxVaultDepository { collateralMint: PublicKey; collateralSymbol: string; alloyxVaultId: string; + alloyxVaultMint: PublicKey; alloyxProgramId: PublicKey; }): Promise { // Collateral decimals can be resolved asynchronously @@ -58,18 +59,18 @@ export class AlloyxVaultDepository { // First we need to resolve the basic alloyx vault address const alloyxVaultInfo = this.findAlloyxVaultInfoAddress( - alloyxProgramId, - alloyxVaultId + alloyxVaultId, + alloyxProgramId ); // Then derive alloyx internal accounts that depends on the above const alloyxVaultCollateral = this.findAlloyxVaultCollateralAddress( - alloyxVaultInfo, + alloyxVaultId, alloyxProgramId ); const alloyxVaultShares = this.findAlloyxVaultSharesAddress( - alloyxVaultCollateral, - collateralMint + alloyxVaultId, + alloyxProgramId ); // Then we can find the depository address @@ -85,22 +86,6 @@ export class AlloyxVaultDepository { alloyxProgramId ); - // Then we can read the content of all alloyx accounts on chain - const alloyxProgram = this.getAlloyxProgram(connection, alloyxProgramId); - const alloyxVaultInfoAccountPromise = this.getAlloyxVaultInfoAccount( - alloyxProgram, - alloyxVaultInfo - ); - - // Wait until we have all the accounts deserialized data before progressing further - const alloyxVaultInfoAccount = await alloyxVaultInfoAccountPromise; - const alloyxProgramStateAccount = await alloyxProgramStateAccountPromise; - - // Then we can read all the informations needed from the onchain accounts - const alloyxVaultMint = alloyxVaultInfoAccount.lpTokenMint; - const alloyxTreasuryPoolCollateral = - alloyxVaultInfoAccount.treasuryPoolTokenAccount; - // Then generate the depository token accounts const depositoryCollateral = this.findDepositoryCollateralAddress( depository, diff --git a/src/client.ts b/src/client.ts index 8e44a8e..06656a5 100644 --- a/src/client.ts +++ b/src/client.ts @@ -18,6 +18,7 @@ import { IDL as UXD_IDL } from './idl'; import type { Uxd as UXD_IDL_TYPE } from './idl'; import { IdentityDepository } from './identity/depository'; import { CredixLpDepository } from './credix_lp/depository'; +import { AlloyxVaultDepository } from './alloyx_vault/depository'; export class UXDClient { public instruction: InstructionNamespace; @@ -61,11 +62,13 @@ export class UXDClient { identityDepositoryWeightBps: number; mercurialVaultDepositoryWeightBps: number; credixLpDepositoryWeightBps: number; + alloyxVaultDepositoryWeightBps: number; }; routerDepositories?: { identityDepository: PublicKey; mercurialVaultDepository: PublicKey; credixLpDepository: PublicKey; + alloyxVaultDepository: PublicKey; }; outflowLimitPerEpochAmount?: number; outflowLimitPerEpochBps?: number; @@ -423,27 +426,6 @@ export class UXDClient { }); } - /** - * @deprecated - * for backward compatibility only - * please use createEditControllerInstruction instead - */ - public createSetRedeemableGlobalSupplyCapInstruction( - controller: Controller, - authority: PublicKey, - redeemableGlobalSupplyCap: number, - options: ConfirmOptions - ): TransactionInstruction { - return this.createEditControllerInstruction( - controller, - authority, - { - redeemableGlobalSupplyCap, - }, - options - ); - } - public createEditIdentityDepositoryInstruction( controller: Controller, depository: IdentityDepository, @@ -707,6 +689,7 @@ export class UXDClient { identityDepository: IdentityDepository, mercurialVaultDepository: MercurialVaultDepository, credixLpDepository: CredixLpDepository, + alloyxVaultDepository: AlloyxVaultDepository, payer: PublicKey, options: ConfirmOptions ): TransactionInstruction { @@ -717,11 +700,14 @@ export class UXDClient { accounts: { payer: payer, controller: controller.pda, + collateralMint: collateralMintPda, + identityDepository: identityDepository.pda, + mercurialVaultDepository: mercurialVaultDepository.pda, - depository: credixLpDepository.pda, - collateralMint: collateralMintPda, - depositoryShares: credixLpDepository.depositoryShares, + + credixLpDepository: credixLpDepository.pda, + credixLpDepositoryShares: credixLpDepository.depositoryShares, credixGlobalMarketState: credixLpDepository.credixGlobalMarketState, credixSigningAuthority: credixLpDepository.credixSigningAuthority, credixLiquidityCollateral: @@ -729,6 +715,9 @@ export class UXDClient { credixSharesMint: credixLpDepository.credixSharesMint, credixPass: credixLpDepository.credixPass, credixWithdrawEpoch: credixLpDepository.credixWithdrawEpoch, + + alloyxVaultDepository: alloyxVaultDepository.pda, + systemProgram: SystemProgram.programId, credixProgram: credixLpDepository.credixProgramId, }, @@ -742,6 +731,7 @@ export class UXDClient { identityDepository: IdentityDepository, mercurialVaultDepository: MercurialVaultDepository, credixLpDepository: CredixLpDepository, + alloyxVaultDepository: AlloyxVaultDepository, payer: PublicKey, profitsBeneficiaryCollateral: PublicKey, options: ConfirmOptions @@ -753,13 +743,16 @@ export class UXDClient { accounts: { payer: payer, controller: controller.pda, + collateralMint: collateralMintPda, + identityDepository: identityDepository.pda, identityDepositoryCollateral: identityDepository.collateralVaultPda, + mercurialVaultDepository: mercurialVaultDepository.pda, - depository: credixLpDepository.pda, - collateralMint: collateralMintPda, - depositoryCollateral: credixLpDepository.depositoryCollateral, - depositoryShares: credixLpDepository.depositoryShares, + + credixLpDepository: credixLpDepository.pda, + credixLpDepositoryCollateral: credixLpDepository.depositoryCollateral, + credixLpDepositoryShares: credixLpDepository.depositoryShares, credixProgramState: credixLpDepository.credixProgramState, credixGlobalMarketState: credixLpDepository.credixGlobalMarketState, credixSigningAuthority: credixLpDepository.credixSigningAuthority, @@ -772,6 +765,9 @@ export class UXDClient { credixTreasury: credixLpDepository.credixTreasury, credixTreasuryCollateral: credixLpDepository.credixTreasuryCollateral, credixWithdrawEpoch: credixLpDepository.credixWithdrawEpoch, + + alloyxVaultDepository: alloyxVaultDepository.pda, + profitsBeneficiaryCollateral: profitsBeneficiaryCollateral, systemProgram: SystemProgram.programId, tokenProgram: TOKEN_PROGRAM_ID, @@ -804,6 +800,7 @@ export class UXDClient { identityDepository: IdentityDepository, mercurialVaultDepository: MercurialVaultDepository, credixLpDepository: CredixLpDepository, + alloyxVaultDepository: AlloyxVaultDepository, user: PublicKey, collateralAmount: number, options: ConfirmOptions, @@ -858,6 +855,8 @@ export class UXDClient { credixLpDepository.credixLiquidityCollateral, credixLpDepositorySharesMint: credixLpDepository.credixSharesMint, + alloyxVaultDepository: alloyxVaultDepository.pda, + systemProgram: SystemProgram.programId, tokenProgram: TOKEN_PROGRAM_ID, associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID, @@ -875,6 +874,7 @@ export class UXDClient { identityDepository: IdentityDepository, mercurialVaultDepository: MercurialVaultDepository, credixLpDepository: CredixLpDepository, + alloyxVaultDepository: AlloyxVaultDepository, user: PublicKey, redeemableAmount: number, options: ConfirmOptions, @@ -918,6 +918,8 @@ export class UXDClient { credixLpDepository: credixLpDepository.pda, + alloyxVaultDepository: alloyxVaultDepository.pda, + systemProgram: SystemProgram.programId, tokenProgram: TOKEN_PROGRAM_ID, associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID, From 7559bec05eada0fbb6fca374675f50b4b6102755 Mon Sep 17 00:00:00 2001 From: Vincent Brunet Date: Thu, 2 Nov 2023 18:10:57 +0900 Subject: [PATCH 03/12] published-idl-with-basic-depository --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index a4a9967..4e15bea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@uxd-protocol/uxd-client", - "version": "8.1.4-rc7", + "version": "8.3.0-rc1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@uxd-protocol/uxd-client", - "version": "8.1.4-rc7", + "version": "8.3.0-rc1", "license": "MIT", "dependencies": { "@project-serum/anchor": "0.26.0", diff --git a/package.json b/package.json index a1a11fb..4f1d24d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@uxd-protocol/uxd-client", - "version": "8.2.0-rc2", + "version": "8.3.0-rc1", "description": "JavaScript Client for the UXD Solana Program", "keywords": [ "solana", From a5a85c84c01d8d61bf476377e3bfe60e4edf0010 Mon Sep 17 00:00:00 2001 From: Vincent Brunet Date: Fri, 3 Nov 2023 17:07:23 +0900 Subject: [PATCH 04/12] 9.0-is-breaking-change --- package-lock.json | 4 ++-- package.json | 2 +- src/idl.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4e15bea..51bd3cc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@uxd-protocol/uxd-client", - "version": "8.3.0-rc1", + "version": "9.0.0-rc1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@uxd-protocol/uxd-client", - "version": "8.3.0-rc1", + "version": "9.0.0-rc1", "license": "MIT", "dependencies": { "@project-serum/anchor": "0.26.0", diff --git a/package.json b/package.json index 4f1d24d..8c599e3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@uxd-protocol/uxd-client", - "version": "8.3.0-rc1", + "version": "9.0.0-rc1", "description": "JavaScript Client for the UXD Solana Program", "keywords": [ "solana", diff --git a/src/idl.ts b/src/idl.ts index abb168a..c408e2c 100644 --- a/src/idl.ts +++ b/src/idl.ts @@ -1,5 +1,5 @@ export type Uxd = { - version: '8.2.0'; + version: '9.0.0'; name: 'uxd'; instructions: [ { @@ -4154,7 +4154,7 @@ export type Uxd = { }; export const IDL: Uxd = { - version: '8.2.0', + version: '9.0.0', name: 'uxd', instructions: [ { From 8ccd3e629f77ad102194428efcdaf50c2b030466 Mon Sep 17 00:00:00 2001 From: Vincent Brunet Date: Fri, 3 Nov 2023 17:15:03 +0900 Subject: [PATCH 05/12] export-alloyx-depository --- package-lock.json | 4 ++-- package.json | 2 +- src/index.ts | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 51bd3cc..84db99e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@uxd-protocol/uxd-client", - "version": "9.0.0-rc1", + "version": "9.0.0-rc2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@uxd-protocol/uxd-client", - "version": "9.0.0-rc1", + "version": "9.0.0-rc2", "license": "MIT", "dependencies": { "@project-serum/anchor": "0.26.0", diff --git a/package.json b/package.json index 8c599e3..f147b2d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@uxd-protocol/uxd-client", - "version": "9.0.0-rc1", + "version": "9.0.0-rc2", "description": "JavaScript Client for the UXD Solana Program", "keywords": [ "solana", diff --git a/src/index.ts b/src/index.ts index ea694a9..254e5eb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,6 +10,7 @@ export { export { MercurialVaultDepository } from './mercurial/depository'; export { IdentityDepository } from './identity/depository'; export { CredixLpDepository } from './credix_lp/depository'; +export { AlloyxVaultDepository } from './alloyx_vault/depository'; export { ETH_DECIMALS, BTC_DECIMALS, From e22a596feeca6a20397e793048e26366eab0a599 Mon Sep 17 00:00:00 2001 From: Vincent Brunet Date: Fri, 3 Nov 2023 17:36:34 +0900 Subject: [PATCH 06/12] export-account-alloyx --- src/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.ts b/src/index.ts index 254e5eb..3d3d92c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,6 +6,7 @@ export { MercurialVaultDepositoryAccount, IdentityDepositoryAccount, CredixLpDepositoryAccount, + AlloyxVaultDepositoryAccount, } from './interfaces'; export { MercurialVaultDepository } from './mercurial/depository'; export { IdentityDepository } from './identity/depository'; From 6ae348222015239f3d49974106559f3caf54eee5 Mon Sep 17 00:00:00 2001 From: Vincent Brunet Date: Mon, 27 Nov 2023 21:53:33 +0900 Subject: [PATCH 07/12] update-controller-flag --- src/interfaces.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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 From b323e5ab0dde3135153bc8987976c0add890c08d Mon Sep 17 00:00:00 2001 From: Vincent Brunet Date: Mon, 27 Nov 2023 21:55:26 +0900 Subject: [PATCH 08/12] package-version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 84db99e..997b8d1 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-rc4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@uxd-protocol/uxd-client", - "version": "9.0.0-rc2", + "version": "9.0.0-rc4", "license": "MIT", "dependencies": { "@project-serum/anchor": "0.26.0", diff --git a/package.json b/package.json index f147b2d..f05fc5c 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-rc4", "description": "JavaScript Client for the UXD Solana Program", "keywords": [ "solana", From 9349591a1ec0db32ebe78c5531394b317c51c439 Mon Sep 17 00:00:00 2001 From: Vincent Brunet Date: Thu, 21 Dec 2023 17:02:24 +0100 Subject: [PATCH 09/12] fix-error-in-pda --- package-lock.json | 4 ++-- package.json | 2 +- src/alloyx_vault/depository.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 997b8d1..99484ce 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@uxd-protocol/uxd-client", - "version": "9.0.0-rc4", + "version": "9.0.0-rc5", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@uxd-protocol/uxd-client", - "version": "9.0.0-rc4", + "version": "9.0.0-rc5", "license": "MIT", "dependencies": { "@project-serum/anchor": "0.26.0", diff --git a/package.json b/package.json index f05fc5c..1e6f0b2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@uxd-protocol/uxd-client", - "version": "9.0.0-rc4", + "version": "9.0.0-rc5", "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..2756799 100644 --- a/src/alloyx_vault/depository.ts +++ b/src/alloyx_vault/depository.ts @@ -185,13 +185,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(), ], From 75eb5de9805f56962f003454bdb0702e22fdfb28 Mon Sep 17 00:00:00 2001 From: Vincent Brunet Date: Thu, 21 Dec 2023 17:04:06 +0100 Subject: [PATCH 10/12] typo-fix --- src/alloyx_vault/depository.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/alloyx_vault/depository.ts b/src/alloyx_vault/depository.ts index 2756799..38f00b6 100644 --- a/src/alloyx_vault/depository.ts +++ b/src/alloyx_vault/depository.ts @@ -79,9 +79,10 @@ export class AlloyxVaultDepository { collateralMint, uxdProgramId ); + // Then the alloyx pass which depends on the depository const alloyxVaultPass = this.findAlloyxVaultPassAddress( - alloyxVaultInfo, + alloyxVaultId, depository, alloyxProgramId ); From d00d1afc101fc8e1091d26ba5247c1bf4a22c905 Mon Sep 17 00:00:00 2001 From: Vincent Brunet Date: Fri, 22 Dec 2023 11:00:00 +0100 Subject: [PATCH 11/12] add-new-idxs --- src/alloyx_vault/depository.ts | 2 + src/client.ts | 140 +++++++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+) diff --git a/src/alloyx_vault/depository.ts b/src/alloyx_vault/depository.ts index 38f00b6..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, @@ -108,6 +109,7 @@ export class AlloyxVaultDepository { collateralSymbol, depositoryCollateral, depositoryShares, + alloyxVaultId, alloyxVaultInfo, alloyxVaultCollateral, alloyxVaultShares, 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, From ddd38cb7ae7c7d6b25a8a62a4990f52afdef8dc1 Mon Sep 17 00:00:00 2001 From: Vincent Brunet Date: Fri, 22 Dec 2023 11:00:53 +0100 Subject: [PATCH 12/12] rc6 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 99484ce..cb20d07 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@uxd-protocol/uxd-client", - "version": "9.0.0-rc5", + "version": "9.0.0-rc6", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@uxd-protocol/uxd-client", - "version": "9.0.0-rc5", + "version": "9.0.0-rc6", "license": "MIT", "dependencies": { "@project-serum/anchor": "0.26.0", diff --git a/package.json b/package.json index 1e6f0b2..7576364 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@uxd-protocol/uxd-client", - "version": "9.0.0-rc5", + "version": "9.0.0-rc6", "description": "JavaScript Client for the UXD Solana Program", "keywords": [ "solana",