@xitadel-fi/sdk 0.1.1
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/README.md +90 -0
- package/dist/sdk/src/constants.d.ts +11 -0
- package/dist/sdk/src/constants.js +15 -0
- package/dist/sdk/src/index.d.ts +3 -0
- package/dist/sdk/src/index.js +12 -0
- package/dist/sdk/src/meteora.d.ts +1229 -0
- package/dist/sdk/src/meteora.js +1231 -0
- package/dist/sdk/src/program.d.ts +433 -0
- package/dist/sdk/src/program.js +825 -0
- package/dist/sdk/src/utils.d.ts +17 -0
- package/dist/sdk/src/utils.js +75 -0
- package/dist/target/idl/xitadel.json +4978 -0
- package/dist/target/types/xitadel.d.ts +4984 -0
- package/dist/target/types/xitadel.js +2 -0
- package/package.json +52 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PublicKey } from '@solana/web3.js';
|
|
2
|
+
import { BN } from '@coral-xyz/anchor';
|
|
3
|
+
export declare const getSqrtPriceFromPrice: (price: string, tokenADecimal: number, tokenBDecimal: number) => BN;
|
|
4
|
+
export declare const getFirstKey: (key1: PublicKey, key2: PublicKey) => PublicKey;
|
|
5
|
+
export declare const getSecondKey: (key1: PublicKey, key2: PublicKey) => PublicKey;
|
|
6
|
+
export declare const derivePoolKey: (config: PublicKey, mintA: PublicKey, mintB: PublicKey, programId: PublicKey) => PublicKey;
|
|
7
|
+
export declare const getVaultPda: (tokenMint: PublicKey, programId: PublicKey, poolKey: PublicKey) => PublicKey;
|
|
8
|
+
export declare function deriveProtocolFeeKey(mintKey: PublicKey, poolKey: PublicKey, cpAmmProgramId: PublicKey): PublicKey;
|
|
9
|
+
export declare function deriveMintMetadata(lpMint: PublicKey): [PublicKey, number];
|
|
10
|
+
export declare const getLiquidityDelta: (params: {
|
|
11
|
+
maxAmountTokenA: BN;
|
|
12
|
+
maxAmountTokenB: BN;
|
|
13
|
+
sqrtMaxPrice: BN;
|
|
14
|
+
sqrtMinPrice: BN;
|
|
15
|
+
sqrtPrice: BN;
|
|
16
|
+
}) => BN;
|
|
17
|
+
export declare function calculateTotalStableAmountRequiredForMaturity(lttSupply: any, lpSupplyAmount: any, stableInterestAmount: any, interestTokenDecimals: number): any;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getLiquidityDelta = exports.getVaultPda = exports.derivePoolKey = exports.getSecondKey = exports.getFirstKey = exports.getSqrtPriceFromPrice = void 0;
|
|
7
|
+
exports.deriveProtocolFeeKey = deriveProtocolFeeKey;
|
|
8
|
+
exports.deriveMintMetadata = deriveMintMetadata;
|
|
9
|
+
exports.calculateTotalStableAmountRequiredForMaturity = calculateTotalStableAmountRequiredForMaturity;
|
|
10
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
11
|
+
const constants_1 = require("./constants");
|
|
12
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
13
|
+
const cp_amm_sdk_1 = require("@meteora-ag/cp-amm-sdk");
|
|
14
|
+
const bn_js_1 = require("bn.js");
|
|
15
|
+
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
16
|
+
// sqrt(price / 10^(tokenADecimal - tokenBDecimal)) * 2^64
|
|
17
|
+
const getSqrtPriceFromPrice = (price, tokenADecimal, tokenBDecimal) => {
|
|
18
|
+
const decimalPrice = new decimal_js_1.default(price);
|
|
19
|
+
const adjustedByDecimals = decimalPrice.div(new decimal_js_1.default(10 ** (tokenADecimal - tokenBDecimal)));
|
|
20
|
+
const sqrtValue = decimal_js_1.default.sqrt(adjustedByDecimals);
|
|
21
|
+
const sqrtValueQ64 = sqrtValue.mul(decimal_js_1.default.pow(2, 64));
|
|
22
|
+
return new anchor_1.BN(sqrtValueQ64.floor().toFixed());
|
|
23
|
+
};
|
|
24
|
+
exports.getSqrtPriceFromPrice = getSqrtPriceFromPrice;
|
|
25
|
+
const getFirstKey = (key1, key2) => {
|
|
26
|
+
if (key1.toBuffer().compare(key2.toBuffer()) > 0) {
|
|
27
|
+
return key1;
|
|
28
|
+
}
|
|
29
|
+
return key2;
|
|
30
|
+
};
|
|
31
|
+
exports.getFirstKey = getFirstKey;
|
|
32
|
+
const getSecondKey = (key1, key2) => {
|
|
33
|
+
if (key1.toBuffer().compare(key2.toBuffer()) > 0) {
|
|
34
|
+
return key2;
|
|
35
|
+
}
|
|
36
|
+
return key1;
|
|
37
|
+
};
|
|
38
|
+
exports.getSecondKey = getSecondKey;
|
|
39
|
+
const derivePoolKey = (config, mintA, mintB, programId) => {
|
|
40
|
+
const firstKey = (0, exports.getFirstKey)(mintA, mintB);
|
|
41
|
+
const secondKey = (0, exports.getSecondKey)(mintA, mintB);
|
|
42
|
+
const [poolKey] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('pool'), config.toBuffer(), firstKey.toBuffer(), secondKey.toBuffer()], programId);
|
|
43
|
+
return poolKey;
|
|
44
|
+
};
|
|
45
|
+
exports.derivePoolKey = derivePoolKey;
|
|
46
|
+
const getVaultPda = (tokenMint, programId, poolKey) => {
|
|
47
|
+
const [tokenVault] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('token_vault'), tokenMint.toBuffer(), poolKey.toBuffer()], programId);
|
|
48
|
+
return tokenVault;
|
|
49
|
+
};
|
|
50
|
+
exports.getVaultPda = getVaultPda;
|
|
51
|
+
function deriveProtocolFeeKey(mintKey, poolKey, cpAmmProgramId) {
|
|
52
|
+
const [feeKey, _] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('fee'), mintKey.toBuffer(), poolKey.toBuffer()], cpAmmProgramId);
|
|
53
|
+
return feeKey;
|
|
54
|
+
}
|
|
55
|
+
function deriveMintMetadata(lpMint) {
|
|
56
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('metadata'), constants_1.METADATA_PROGRAM_ID.toBuffer(), lpMint.toBuffer()], constants_1.METADATA_PROGRAM_ID);
|
|
57
|
+
}
|
|
58
|
+
const getLiquidityDelta = (params) => {
|
|
59
|
+
const { maxAmountTokenA, maxAmountTokenB, sqrtMaxPrice, sqrtMinPrice, sqrtPrice } = params;
|
|
60
|
+
const liquidityDeltaFromAmountA = (0, cp_amm_sdk_1.getLiquidityDeltaFromAmountA)(maxAmountTokenA, sqrtPrice, sqrtMaxPrice);
|
|
61
|
+
const liquidityDeltaFromAmountB = (0, cp_amm_sdk_1.getLiquidityDeltaFromAmountB)(maxAmountTokenB, sqrtMinPrice, sqrtPrice);
|
|
62
|
+
return (0, bn_js_1.min)(liquidityDeltaFromAmountA, liquidityDeltaFromAmountB);
|
|
63
|
+
};
|
|
64
|
+
exports.getLiquidityDelta = getLiquidityDelta;
|
|
65
|
+
function calculateTotalStableAmountRequiredForMaturity(lttSupply, lpSupplyAmount, stableInterestAmount, interestTokenDecimals) {
|
|
66
|
+
const LTT_TOKEN_DECIMALS = 3;
|
|
67
|
+
const normalizedLttSupply = lttSupply
|
|
68
|
+
.mul(new anchor_1.BN(10 ** interestTokenDecimals))
|
|
69
|
+
.div(new anchor_1.BN(10 ** LTT_TOKEN_DECIMALS));
|
|
70
|
+
const normalizedLpSupply = lpSupplyAmount
|
|
71
|
+
.mul(new anchor_1.BN(10 ** interestTokenDecimals))
|
|
72
|
+
.div(new anchor_1.BN(10 ** LTT_TOKEN_DECIMALS));
|
|
73
|
+
const initializeLpValue = normalizedLpSupply.mul(new anchor_1.BN(2));
|
|
74
|
+
return stableInterestAmount.add(normalizedLttSupply).sub(initializeLpValue);
|
|
75
|
+
}
|