Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Credix] Minting/Redeeming/CollectProfit IXs #34

Merged
merged 43 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
96cb30a
up
crypto-vincent Nov 28, 2022
99c6114
up
crypto-vincent Nov 28, 2022
d5aa01c
npm-published
crypto-vincent Nov 28, 2022
ce17f2a
change-idl
crypto-vincent Nov 30, 2022
eb7e72d
removed-unused-param
crypto-vincent Nov 30, 2022
858fbb7
nit-naming
crypto-vincent Dec 4, 2022
13a51c8
nit-naming
crypto-vincent Dec 5, 2022
4b19d6f
nits
crypto-vincent Dec 8, 2022
b64274e
simplification-of-api
crypto-vincent Dec 9, 2022
5498812
formatting
crypto-vincent Dec 9, 2022
02ffade
fix-idl-reader
crypto-vincent Dec 9, 2022
5be363a
nit
crypto-vincent Dec 12, 2022
8f7c4b3
read-shares-mint-onchain-instead
crypto-vincent Dec 12, 2022
8cd46ab
market-name-included
crypto-vincent Dec 14, 2022
a9fff2e
up
crypto-vincent Dec 16, 2022
81a7e37
up
crypto-vincent Dec 19, 2022
11e6311
update-idl
crypto-vincent Dec 19, 2022
91ee0bd
update-idl
crypto-vincent Dec 21, 2022
4f78575
applying-pr-nits
crypto-vincent Dec 27, 2022
dcc7459
precision-correct-native-to-ui
crypto-vincent Dec 27, 2022
5235497
Merge branch 'vbrunet/2022_11_28-integration-credix' of github.com:UX…
crypto-vincent Dec 27, 2022
d0b02f8
make-depository-credix-more-async-efficient
crypto-vincent Dec 27, 2022
43aada2
tested-and-hardedned-native-ui-conversions
crypto-vincent Dec 27, 2022
40d5928
format
crypto-vincent Dec 27, 2022
204d5fa
up
crypto-vincent Dec 27, 2022
2572b12
adding-tests
crypto-vincent Dec 27, 2022
cce5b9c
nit-test
crypto-vincent Dec 27, 2022
93aa8fd
nit
crypto-vincent Dec 27, 2022
a9ed2ac
up
crypto-vincent Dec 27, 2022
c76ac30
p
crypto-vincent Dec 27, 2022
fc5c81e
package-update
crypto-vincent Dec 27, 2022
564aed5
support-for-exponential-notation-for-extreme-numbers
crypto-vincent Dec 27, 2022
5d0793e
new-utils-implementation
crypto-vincent Dec 27, 2022
4ef7fab
package
crypto-vincent Dec 28, 2022
2efe9cf
nit
crypto-vincent Dec 28, 2022
186925d
format
crypto-vincent Dec 28, 2022
c12411c
extra-unit-tests
crypto-vincent Dec 28, 2022
3d5229b
simplify-utils
crypto-vincent Jan 1, 2023
55284c5
comment-nit
crypto-vincent Jan 1, 2023
36d9a8a
fix-import
crypto-vincent Jan 1, 2023
0f93787
update-package-version
crypto-vincent Jan 2, 2023
5a965ae
package-version
crypto-vincent Jan 2, 2023
7026432
cleanup-test
crypto-vincent Jan 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@uxd-protocol/uxd-client",
"version": "5.1.4",
"version": "6.0.0-credix-integration-rc5",
"description": "JavaScript Client for the UXD Solana Program",
"keywords": [
"solana",
Expand Down Expand Up @@ -61,4 +61,4 @@
"prettier": "^2.6.2",
"typescript": "^4.6.4"
}
}
}
236 changes: 234 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { InstructionNamespace } from '@project-serum/anchor';
import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
import {
ASSOCIATED_TOKEN_PROGRAM_ID,
TOKEN_PROGRAM_ID,
} from '@solana/spl-token';
import {
SystemProgram,
SYSVAR_RENT_PUBKEY,
Expand All @@ -9,11 +12,12 @@ import {
} from '@solana/web3.js';
import { Controller } from './controller';
import { MercurialVaultDepository } from './mercurial/depository';
import { findMultipleATAAddSync, uiToNative } from './utils';
import { findATAAddrSync, findMultipleATAAddSync, uiToNative } from './utils';
import NamespaceFactory from './namespace';
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';

export class UXDClient {
public instruction: InstructionNamespace<UXD_IDL_TYPE>;
Expand Down Expand Up @@ -393,4 +397,232 @@ export class UXDClient {
options: options,
});
}

public createEditCredixLpDepositoryInstruction(
controller: Controller,
depository: CredixLpDepository,
authority: PublicKey,
uiFields: {
redeemableAmountUnderManagementCap?: number;
mintingFeeInBps?: number;
redeemingFeeInBps?: number;
mintingDisabled?: boolean;
},
options: ConfirmOptions
): TransactionInstruction {
const {
redeemableAmountUnderManagementCap,
mintingFeeInBps,
redeemingFeeInBps,
mintingDisabled,
} = 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,
};
return this.instruction.editCredixLpDepository(fields, {
accounts: {
authority,
controller: controller.pda,
depository: depository.pda,
},
options: options,
crypto-vincent marked this conversation as resolved.
Show resolved Hide resolved
});
}

public createRegisterCredixLpDepositoryInstruction(
controller: Controller,
depository: CredixLpDepository,
authority: PublicKey,
mintingFeeInBps: number,
redeemingFeeInBps: number,
redeemableAmountUnderManagementCap: number,
options: ConfirmOptions,
payer?: PublicKey
): TransactionInstruction {
const redeemableAmountUnderManagementCapBN = uiToNative(
crypto-vincent marked this conversation as resolved.
Show resolved Hide resolved
redeemableAmountUnderManagementCap,
controller.redeemableMintDecimals
);

return this.instruction.registerCredixLpDepository(
mintingFeeInBps,
redeemingFeeInBps,
redeemableAmountUnderManagementCapBN,
{
accounts: {
authority,
payer: payer ?? authority,
controller: controller.pda,
depository: depository.pda,
collateralMint: depository.collateralMint,
depositoryCollateral: depository.depositoryCollateral,
depositoryShares: depository.depositoryShares,
credixProgramState: depository.credixProgramState,
credixGlobalMarketState: depository.credixGlobalMarketState,
credixSigningAuthority: depository.credixSigningAuthority,
credixLiquidityCollateral: depository.credixLiquidityCollateral,
credixSharesMint: depository.credixSharesMint,
systemProgram: SystemProgram.programId,
tokenProgram: TOKEN_PROGRAM_ID,
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
rent: SYSVAR_RENT_PUBKEY,
},
options,
}
);
}

public createMintWithCredixLpDepositoryInstruction(
controller: Controller,
depository: CredixLpDepository,
user: PublicKey,
collateralAmount: number,
options: ConfirmOptions,
payer?: PublicKey
): TransactionInstruction {
const nativeCollateralAmount = uiToNative(
collateralAmount,
depository.collateralDecimals
);

const collateralMint = depository.collateralMint;
const redeemableMint = controller.redeemableMintPda;

const [[userCollateral], [userRedeemable]] = findMultipleATAAddSync(user, [
collateralMint,
redeemableMint,
]);

return this.instruction.mintWithCredixLpDepository(nativeCollateralAmount, {
accounts: {
user: user,
payer: payer ?? user,
controller: controller.pda,
depository: depository.pda,
depositoryCollateral: depository.depositoryCollateral,
depositoryShares: depository.depositoryShares,
redeemableMint: redeemableMint,
userRedeemable: userRedeemable,
collateralMint: collateralMint,
userCollateral: userCollateral,
crypto-vincent marked this conversation as resolved.
Show resolved Hide resolved
credixGlobalMarketState: depository.credixGlobalMarketState,
credixSigningAuthority: depository.credixSigningAuthority,
credixLiquidityCollateral: depository.credixLiquidityCollateral,
credixSharesMint: depository.credixSharesMint,
credixPass: depository.credixPass,
systemProgram: SystemProgram.programId,
tokenProgram: TOKEN_PROGRAM_ID,
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
credixProgram: depository.credixProgramId,
rent: SYSVAR_RENT_PUBKEY,
},
options,
});
crypto-vincent marked this conversation as resolved.
Show resolved Hide resolved
}

public createRedeemFromCredixLpDepositoryInstruction(
controller: Controller,
depository: CredixLpDepository,
user: PublicKey,
redeemableAmount: number,
options: ConfirmOptions,
payer?: PublicKey
): TransactionInstruction {
const nativeRedeemableAmount = uiToNative(
redeemableAmount,
controller.redeemableMintDecimals
);

const collateralMint = depository.collateralMint;
const redeemableMint = controller.redeemableMintPda;

const [[userCollateral], [userRedeemable]] = findMultipleATAAddSync(user, [
collateralMint,
redeemableMint,
]);

return this.instruction.redeemFromCredixLpDepository(
nativeRedeemableAmount,
{
accounts: {
user: user,
payer: payer ?? user,
controller: controller.pda,
depository: depository.pda,
depositoryCollateral: depository.depositoryCollateral,
depositoryShares: depository.depositoryShares,
redeemableMint: redeemableMint,
userRedeemable: userRedeemable,
collateralMint: collateralMint,
userCollateral: userCollateral,
credixProgramState: depository.credixProgramState,
credixGlobalMarketState: depository.credixGlobalMarketState,
credixSigningAuthority: depository.credixSigningAuthority,
credixLiquidityCollateral: depository.credixLiquidityCollateral,
credixSharesMint: depository.credixSharesMint,
credixPass: depository.credixPass,
credixTreasuryCollateral: depository.credixTreasuryCollateral,
credixMultisigKey: depository.credixMultisigKey,
credixMultisigCollateral: depository.credixMultisigCollateral,
systemProgram: SystemProgram.programId,
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
tokenProgram: TOKEN_PROGRAM_ID,
credixProgram: depository.credixProgramId,
rent: SYSVAR_RENT_PUBKEY,
},
options,
}
);
}

public createCollectProfitOfCredixLpDepositoryInstruction(
controller: Controller,
depository: CredixLpDepository,
authority: PublicKey,
options: ConfirmOptions,
payer?: PublicKey
): TransactionInstruction {
const collateralMint = depository.collateralMint;
const [authorityCollateral] = findATAAddrSync(
authority,
depository.collateralMint
);
return this.instruction.collectProfitOfCredixLpDepository({
accounts: {
authority: authority,
payer: payer ?? authority,
controller: controller.pda,
depository: depository.pda,
depositoryCollateral: depository.depositoryCollateral,
depositoryShares: depository.depositoryShares,
collateralMint: collateralMint,
credixProgramState: depository.credixProgramState,
credixGlobalMarketState: depository.credixGlobalMarketState,
credixSigningAuthority: depository.credixSigningAuthority,
credixLiquidityCollateral: depository.credixLiquidityCollateral,
credixSharesMint: depository.credixSharesMint,
credixPass: depository.credixPass,
credixTreasuryCollateral: depository.credixTreasuryCollateral,
credixMultisigKey: depository.credixMultisigKey,
credixMultisigCollateral: depository.credixMultisigCollateral,
authorityCollateral: authorityCollateral,
systemProgram: SystemProgram.programId,
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
tokenProgram: TOKEN_PROGRAM_ID,
credixProgram: depository.credixProgramId,
rent: SYSVAR_RENT_PUBKEY,
},
options,
});
}
}
Loading