@xitadel-fi/sdk 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/sdk/src/program.d.ts +53 -0
- package/dist/sdk/src/program.js +135 -0
- package/dist/sdk/src/utils.d.ts +2 -1
- package/dist/sdk/src/utils.js +10 -0
- package/dist/target/idl/xitadel.json +624 -12
- package/dist/target/types/xitadel.d.ts +624 -12
- package/package.json +1 -1
|
@@ -155,6 +155,7 @@ export declare class XitadelProgram {
|
|
|
155
155
|
chainlinkDataStreamDecimals: number;
|
|
156
156
|
chainlinkDataStreamVersion: number;
|
|
157
157
|
positionNftMintB: PublicKey;
|
|
158
|
+
stakedCollateralAmount: BN;
|
|
158
159
|
}>;
|
|
159
160
|
/**
|
|
160
161
|
* Helper method to get LP authority PDA
|
|
@@ -356,6 +357,7 @@ export declare class XitadelProgram {
|
|
|
356
357
|
chainlinkDataStreamDecimals: number;
|
|
357
358
|
chainlinkDataStreamVersion: number;
|
|
358
359
|
positionNftMintB: PublicKey;
|
|
360
|
+
stakedCollateralAmount: BN;
|
|
359
361
|
}>;
|
|
360
362
|
/**
|
|
361
363
|
* Redeem LTT tokens
|
|
@@ -442,4 +444,55 @@ export declare class XitadelProgram {
|
|
|
442
444
|
* @returns Transaction instruction for claiming fees
|
|
443
445
|
*/
|
|
444
446
|
claimFees(signer: PublicKey, lttId: PublicKey, positionNftMint: PublicKey, ammConfig: PublicKey, cpAmmProgramId: PublicKey, receiver: PublicKey): Promise<TransactionInstruction>;
|
|
447
|
+
/**
|
|
448
|
+
* Deposit stake to flash trade from collateral vault
|
|
449
|
+
* @param lttId The LTT ID
|
|
450
|
+
* @param authority The authority (manager or issuer) public key
|
|
451
|
+
* @param amount The amount to stake
|
|
452
|
+
* @param lpTokenMint The LP token mint
|
|
453
|
+
* @param flashTradeProgramId The flash trade program ID
|
|
454
|
+
* @param perpetuals The perpetuals account from flash_trade
|
|
455
|
+
* @param pool The pool account from flash_trade
|
|
456
|
+
* @param transferAuthority The transfer authority account from flash_trade
|
|
457
|
+
* @param flpStakeAccount The FLP stake account from flash_trade
|
|
458
|
+
* @param poolStakedLpVault The pool staked LP vault from flash_trade
|
|
459
|
+
* @param eventAuthority The event authority from flash_trade
|
|
460
|
+
* @returns Transaction instruction for depositing stake to flash trade
|
|
461
|
+
*/
|
|
462
|
+
depositStakeFlashTrade(lttId: PublicKey, authority: PublicKey, amount: BN, lpTokenMint: PublicKey, flashTradeProgramId: PublicKey, perpetuals: PublicKey, pool: PublicKey, transferAuthority: PublicKey, flpStakeAccount: PublicKey, poolStakedLpVault: PublicKey, eventAuthority: PublicKey): Promise<TransactionInstruction>;
|
|
463
|
+
/**
|
|
464
|
+
* Claim flash trade fees to funding vault
|
|
465
|
+
* @param lttId The LTT ID
|
|
466
|
+
* @param authority The authority (manager or issuer) public key
|
|
467
|
+
* @param fundingTokenMint The funding token mint
|
|
468
|
+
* @param flashTradeProgramId The flash trade program ID
|
|
469
|
+
* @param transferAuthority The transfer authority (ltt_configuration PDA)
|
|
470
|
+
* @param perpetuals The perpetuals account from flash_trade
|
|
471
|
+
* @param pool The pool account from flash_trade
|
|
472
|
+
* @param feeCustody The fee custody account from flash_trade
|
|
473
|
+
* @param flpStakeAccount The FLP stake account from flash_trade
|
|
474
|
+
* @param feeCustodyTokenAccount The fee custody token account from flash_trade
|
|
475
|
+
* @param eventAuthority The event authority from flash_trade
|
|
476
|
+
* @param programPda The program PDA from flash_trade
|
|
477
|
+
* @param ixSysvar The instruction sysvar
|
|
478
|
+
* @returns Transaction instruction for claiming flash trade fees
|
|
479
|
+
*/
|
|
480
|
+
claimFlashTradeFees(lttId: PublicKey, authority: PublicKey, fundingTokenMint: PublicKey, flashTradeProgramId: PublicKey, transferAuthority: PublicKey, perpetuals: PublicKey, pool: PublicKey, feeCustody: PublicKey, flpStakeAccount: PublicKey, feeCustodyTokenAccount: PublicKey, eventAuthority: PublicKey, ixSysvar: PublicKey): Promise<TransactionInstruction>;
|
|
481
|
+
/**
|
|
482
|
+
* Withdraw stake from flash trade (unstake instant + withdraw stake)
|
|
483
|
+
* @param lttId The LTT ID
|
|
484
|
+
* @param authority The authority (manager or issuer) public key
|
|
485
|
+
* @param unstakeAmount The amount to unstake
|
|
486
|
+
* @param lpTokenMint The LP token mint
|
|
487
|
+
* @param flashTradeProgramId The flash trade program ID
|
|
488
|
+
* @param transferAuthority The transfer authority account from flash_trade
|
|
489
|
+
* @param perpetuals The perpetuals account from flash_trade
|
|
490
|
+
* @param pool The pool account from flash_trade
|
|
491
|
+
* @param flpStakeAccount The FLP stake account from flash_trade
|
|
492
|
+
* @param poolStakedLpVault The pool staked LP vault from flash_trade
|
|
493
|
+
* @param rewardCustody The reward custody account from flash_trade
|
|
494
|
+
* @param eventAuthority The event authority from flash_trade
|
|
495
|
+
* @returns Transaction instruction for withdrawing stake from flash trade
|
|
496
|
+
*/
|
|
497
|
+
withdrawStakeFlashTrade(lttId: PublicKey, authority: PublicKey, unstakeAmount: BN, lpTokenMint: PublicKey, flashTradeProgramId: PublicKey, transferAuthority: PublicKey, perpetuals: PublicKey, pool: PublicKey, flpStakeAccount: PublicKey, poolStakedLpVault: PublicKey, rewardCustody: PublicKey, eventAuthority: PublicKey): Promise<TransactionInstruction>;
|
|
445
498
|
}
|
package/dist/sdk/src/program.js
CHANGED
|
@@ -884,5 +884,140 @@ class XitadelProgram {
|
|
|
884
884
|
})
|
|
885
885
|
.instruction();
|
|
886
886
|
}
|
|
887
|
+
/**
|
|
888
|
+
* Deposit stake to flash trade from collateral vault
|
|
889
|
+
* @param lttId The LTT ID
|
|
890
|
+
* @param authority The authority (manager or issuer) public key
|
|
891
|
+
* @param amount The amount to stake
|
|
892
|
+
* @param lpTokenMint The LP token mint
|
|
893
|
+
* @param flashTradeProgramId The flash trade program ID
|
|
894
|
+
* @param perpetuals The perpetuals account from flash_trade
|
|
895
|
+
* @param pool The pool account from flash_trade
|
|
896
|
+
* @param transferAuthority The transfer authority account from flash_trade
|
|
897
|
+
* @param flpStakeAccount The FLP stake account from flash_trade
|
|
898
|
+
* @param poolStakedLpVault The pool staked LP vault from flash_trade
|
|
899
|
+
* @param eventAuthority The event authority from flash_trade
|
|
900
|
+
* @returns Transaction instruction for depositing stake to flash trade
|
|
901
|
+
*/
|
|
902
|
+
async depositStakeFlashTrade(lttId, authority, amount, lpTokenMint, flashTradeProgramId, perpetuals, pool, transferAuthority, flpStakeAccount, poolStakedLpVault, eventAuthority) {
|
|
903
|
+
const configPda = this.getConfigPda();
|
|
904
|
+
const lttConfigPda = this.getLTTConfigPda(lttId);
|
|
905
|
+
const collateralVaultAta = (0, spl_token_1.getAssociatedTokenAddressSync)(lpTokenMint, lttConfigPda, true, spl_token_1.TOKEN_PROGRAM_ID, spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID);
|
|
906
|
+
return this.program.methods
|
|
907
|
+
.depositStakeFlashTrade(amount)
|
|
908
|
+
.accountsPartial({
|
|
909
|
+
lttConfiguration: lttConfigPda,
|
|
910
|
+
config: configPda,
|
|
911
|
+
authority: authority,
|
|
912
|
+
collateralVaultAta: collateralVaultAta,
|
|
913
|
+
lpTokenMint: lpTokenMint,
|
|
914
|
+
flashTradeProgram: flashTradeProgramId,
|
|
915
|
+
perpetuals: perpetuals,
|
|
916
|
+
pool: pool,
|
|
917
|
+
transferAuthority: transferAuthority,
|
|
918
|
+
flpStakeAccount: flpStakeAccount,
|
|
919
|
+
poolStakedLpVault: poolStakedLpVault,
|
|
920
|
+
eventAuthority: eventAuthority,
|
|
921
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
922
|
+
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
923
|
+
systemProgram: web3_js_2.SystemProgram.programId,
|
|
924
|
+
})
|
|
925
|
+
.instruction();
|
|
926
|
+
}
|
|
927
|
+
/**
|
|
928
|
+
* Claim flash trade fees to funding vault
|
|
929
|
+
* @param lttId The LTT ID
|
|
930
|
+
* @param authority The authority (manager or issuer) public key
|
|
931
|
+
* @param fundingTokenMint The funding token mint
|
|
932
|
+
* @param flashTradeProgramId The flash trade program ID
|
|
933
|
+
* @param transferAuthority The transfer authority (ltt_configuration PDA)
|
|
934
|
+
* @param perpetuals The perpetuals account from flash_trade
|
|
935
|
+
* @param pool The pool account from flash_trade
|
|
936
|
+
* @param feeCustody The fee custody account from flash_trade
|
|
937
|
+
* @param flpStakeAccount The FLP stake account from flash_trade
|
|
938
|
+
* @param feeCustodyTokenAccount The fee custody token account from flash_trade
|
|
939
|
+
* @param eventAuthority The event authority from flash_trade
|
|
940
|
+
* @param programPda The program PDA from flash_trade
|
|
941
|
+
* @param ixSysvar The instruction sysvar
|
|
942
|
+
* @returns Transaction instruction for claiming flash trade fees
|
|
943
|
+
*/
|
|
944
|
+
async claimFlashTradeFees(lttId, authority, fundingTokenMint, flashTradeProgramId, transferAuthority, perpetuals, pool, feeCustody, flpStakeAccount, feeCustodyTokenAccount, eventAuthority, ixSysvar) {
|
|
945
|
+
const configPda = this.getConfigPda();
|
|
946
|
+
const lttConfigPda = this.getLTTConfigPda(lttId);
|
|
947
|
+
const fundingVaultAta = (0, spl_token_1.getAssociatedTokenAddressSync)(fundingTokenMint, lttConfigPda, true, spl_token_1.TOKEN_PROGRAM_ID, spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID);
|
|
948
|
+
return this.program.methods
|
|
949
|
+
.claimFlashTradeFees()
|
|
950
|
+
.accountsPartial({
|
|
951
|
+
lttConfiguration: lttConfigPda,
|
|
952
|
+
config: configPda,
|
|
953
|
+
authority: authority,
|
|
954
|
+
fundingVaultAta: fundingVaultAta,
|
|
955
|
+
fundingTokenMint: fundingTokenMint,
|
|
956
|
+
flashTradeProgram: flashTradeProgramId,
|
|
957
|
+
transferAuthority: transferAuthority,
|
|
958
|
+
perpetuals: perpetuals,
|
|
959
|
+
pool: pool,
|
|
960
|
+
feeCustody: feeCustody,
|
|
961
|
+
flpStakeAccount: flpStakeAccount,
|
|
962
|
+
feeCustodyTokenAccount: feeCustodyTokenAccount,
|
|
963
|
+
eventAuthority: eventAuthority,
|
|
964
|
+
ixSysvar: ixSysvar,
|
|
965
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
966
|
+
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
967
|
+
systemProgram: web3_js_2.SystemProgram.programId,
|
|
968
|
+
})
|
|
969
|
+
.instruction();
|
|
970
|
+
}
|
|
971
|
+
/**
|
|
972
|
+
* Withdraw stake from flash trade (unstake instant + withdraw stake)
|
|
973
|
+
* @param lttId The LTT ID
|
|
974
|
+
* @param authority The authority (manager or issuer) public key
|
|
975
|
+
* @param unstakeAmount The amount to unstake
|
|
976
|
+
* @param lpTokenMint The LP token mint
|
|
977
|
+
* @param flashTradeProgramId The flash trade program ID
|
|
978
|
+
* @param transferAuthority The transfer authority account from flash_trade
|
|
979
|
+
* @param perpetuals The perpetuals account from flash_trade
|
|
980
|
+
* @param pool The pool account from flash_trade
|
|
981
|
+
* @param flpStakeAccount The FLP stake account from flash_trade
|
|
982
|
+
* @param poolStakedLpVault The pool staked LP vault from flash_trade
|
|
983
|
+
* @param rewardCustody The reward custody account from flash_trade
|
|
984
|
+
* @param eventAuthority The event authority from flash_trade
|
|
985
|
+
* @returns Transaction instruction for withdrawing stake from flash trade
|
|
986
|
+
*/
|
|
987
|
+
async withdrawStakeFlashTrade(lttId, authority, unstakeAmount, lpTokenMint, flashTradeProgramId, transferAuthority, perpetuals, pool, flpStakeAccount, poolStakedLpVault, rewardCustody, eventAuthority) {
|
|
988
|
+
const configPda = this.getConfigPda();
|
|
989
|
+
const lttConfigPda = this.getLTTConfigPda(lttId);
|
|
990
|
+
const collateralVaultAta = (0, spl_token_1.getAssociatedTokenAddressSync)(lpTokenMint, lttConfigPda, true, spl_token_1.TOKEN_PROGRAM_ID, spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID);
|
|
991
|
+
const tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), lttConfigPda.toBuffer()], flashTradeProgramId)[0];
|
|
992
|
+
let tokenStakeAccounts = [];
|
|
993
|
+
if (tokenStakeAccount && await (0, utils_1.checkIfAccountExists)(tokenStakeAccount, this.program.provider.connection)) {
|
|
994
|
+
tokenStakeAccounts.push({
|
|
995
|
+
pubkey: tokenStakeAccount,
|
|
996
|
+
isSigner: false,
|
|
997
|
+
isWritable: false,
|
|
998
|
+
});
|
|
999
|
+
}
|
|
1000
|
+
return this.program.methods
|
|
1001
|
+
.withdrawStakeFlashTrade(unstakeAmount)
|
|
1002
|
+
.accountsPartial({
|
|
1003
|
+
lttConfiguration: lttConfigPda,
|
|
1004
|
+
config: configPda,
|
|
1005
|
+
authority: authority,
|
|
1006
|
+
collateralVaultAta: collateralVaultAta,
|
|
1007
|
+
lpTokenMint: lpTokenMint,
|
|
1008
|
+
flashTradeProgram: flashTradeProgramId,
|
|
1009
|
+
transferAuthority: transferAuthority,
|
|
1010
|
+
perpetuals: perpetuals,
|
|
1011
|
+
pool: pool,
|
|
1012
|
+
flpStakeAccount: flpStakeAccount,
|
|
1013
|
+
poolStakedLpVault: poolStakedLpVault,
|
|
1014
|
+
rewardCustody: rewardCustody,
|
|
1015
|
+
eventAuthority: eventAuthority,
|
|
1016
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
1017
|
+
systemProgram: web3_js_2.SystemProgram.programId,
|
|
1018
|
+
})
|
|
1019
|
+
.remainingAccounts([...tokenStakeAccounts])
|
|
1020
|
+
.instruction();
|
|
1021
|
+
}
|
|
887
1022
|
}
|
|
888
1023
|
exports.XitadelProgram = XitadelProgram;
|
package/dist/sdk/src/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PublicKey } from '@solana/web3.js';
|
|
1
|
+
import { PublicKey, Connection } from '@solana/web3.js';
|
|
2
2
|
import { BN } from '@coral-xyz/anchor';
|
|
3
3
|
export declare const getSqrtPriceFromPrice: (price: string, tokenADecimal: number, tokenBDecimal: number) => BN;
|
|
4
4
|
export declare const getFirstKey: (key1: PublicKey, key2: PublicKey) => PublicKey;
|
|
@@ -15,3 +15,4 @@ export declare const getLiquidityDelta: (params: {
|
|
|
15
15
|
sqrtPrice: BN;
|
|
16
16
|
}) => BN;
|
|
17
17
|
export declare function calculateTotalStableAmountRequiredForMaturity(lttSupply: any, lpSupplyAmount: any, stableInterestAmount: any, interestTokenDecimals: number): any;
|
|
18
|
+
export declare function checkIfAccountExists(account: PublicKey, connection: Connection): Promise<boolean>;
|
package/dist/sdk/src/utils.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.getLiquidityDelta = exports.getVaultPda = exports.derivePoolKey = export
|
|
|
7
7
|
exports.deriveProtocolFeeKey = deriveProtocolFeeKey;
|
|
8
8
|
exports.deriveMintMetadata = deriveMintMetadata;
|
|
9
9
|
exports.calculateTotalStableAmountRequiredForMaturity = calculateTotalStableAmountRequiredForMaturity;
|
|
10
|
+
exports.checkIfAccountExists = checkIfAccountExists;
|
|
10
11
|
const web3_js_1 = require("@solana/web3.js");
|
|
11
12
|
const constants_1 = require("./constants");
|
|
12
13
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
@@ -73,3 +74,12 @@ function calculateTotalStableAmountRequiredForMaturity(lttSupply, lpSupplyAmount
|
|
|
73
74
|
const initializeLpValue = normalizedLpSupply.mul(new anchor_1.BN(2));
|
|
74
75
|
return stableInterestAmount.add(normalizedLttSupply).sub(initializeLpValue);
|
|
75
76
|
}
|
|
77
|
+
async function checkIfAccountExists(account, connection) {
|
|
78
|
+
let bal = await connection.getBalance(account);
|
|
79
|
+
if (bal > 0) {
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|