@affluent-org/sdk 0.0.3 → 0.0.5
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/common/transform.d.ts +93 -0
- package/dist/common/transform.js +351 -0
- package/dist/common/types.d.ts +144 -0
- package/dist/common/types.js +11 -0
- package/dist/contracts/oracle/redstone-onchain-oracle/type.d.ts +1 -1
- package/dist/services/composite-oracle/codec.d.ts +76 -0
- package/dist/services/composite-oracle/codec.js +281 -0
- package/dist/services/composite-oracle/computation.d.ts +9 -15
- package/dist/services/composite-oracle/computation.js +44 -36
- package/dist/services/composite-oracle/index.d.ts +2 -2
- package/dist/services/composite-oracle/index.js +2 -2
- package/dist/services/composite-oracle/query.d.ts +6 -6
- package/dist/services/composite-oracle/query.js +7 -46
- package/dist/services/pool/computation.d.ts +3 -9
- package/dist/services/pool/computation.js +16 -30
- package/dist/services/pool/oracle.d.ts +2 -2
- package/dist/services/pool/query.d.ts +1 -1
- package/dist/services/rfq-auction/oracle.d.ts +2 -2
- package/dist/services/rfq-batch/oracle.d.ts +2 -2
- package/dist/services/share-vault/index.d.ts +7 -0
- package/dist/services/share-vault/index.js +6 -0
- package/dist/services/share-vault/query.d.ts +5 -32
- package/dist/services/share-vault/query.js +25 -12
- package/dist/services/strategy-vault/index.d.ts +14 -0
- package/dist/services/strategy-vault/index.js +13 -0
- package/dist/services/strategy-vault/oracle.d.ts +3 -3
- package/dist/services/strategy-vault/query.d.ts +14 -143
- package/dist/services/strategy-vault/query.js +42 -49
- package/dist/types/address.d.ts +7 -0
- package/dist/types/address.js +2 -0
- package/dist/utils/risk_calculator/risk_calculator.d.ts +3 -3
- package/package.json +1 -1
|
@@ -7,11 +7,11 @@ exports.getRFQAuctionAddress = getRFQAuctionAddress;
|
|
|
7
7
|
exports.getRFQAuction = getRFQAuction;
|
|
8
8
|
exports.isVaultAsset = isVaultAsset;
|
|
9
9
|
exports.splitPureAndVaultAsset = splitPureAndVaultAsset;
|
|
10
|
-
exports.
|
|
11
|
-
exports.getPoolPositionsForStrategyVault = getPoolPositionsForStrategyVault;
|
|
10
|
+
exports.getPoolDataForStrategyVault = getPoolDataForStrategyVault;
|
|
12
11
|
exports.getValuationContext = getValuationContext;
|
|
13
12
|
exports.getPrice = getPrice;
|
|
14
13
|
exports.getUnderlyingPrices = getUnderlyingPrices;
|
|
14
|
+
exports.getNativeAmountDecomposedContext = getNativeAmountDecomposedContext;
|
|
15
15
|
const core_1 = require("@ton/core");
|
|
16
16
|
const utils_1 = require("../../contracts/common/utils");
|
|
17
17
|
const jetton_wallet_1 = require("../../contracts/jetton/jetton-wallet");
|
|
@@ -19,6 +19,7 @@ const rfq_auction_1 = require("../../contracts/rfq/rfq_auction");
|
|
|
19
19
|
const strategy_vault_1 = require("../../contracts/vault/strategy-vault");
|
|
20
20
|
const composite_oracle_1 = require("../composite-oracle");
|
|
21
21
|
const pool_1 = require("../../contracts/core/pool");
|
|
22
|
+
const transform_1 = require("../../common/transform");
|
|
22
23
|
function getVault(ctx, strategyVaultAddress) {
|
|
23
24
|
return ctx.getByContract(strategy_vault_1.StrategyVault, (0, utils_1.toAddress)(strategyVaultAddress));
|
|
24
25
|
}
|
|
@@ -65,62 +66,54 @@ async function splitPureAndVaultAsset(ctx, addresses) {
|
|
|
65
66
|
pureAssetAddresses,
|
|
66
67
|
};
|
|
67
68
|
}
|
|
68
|
-
async function
|
|
69
|
+
async function getPoolDataForStrategyVault(ctx, strategyVaultAddress) {
|
|
69
70
|
const vaultData = await getVault(ctx, strategyVaultAddress).getVaultData();
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
return [poolAddress,
|
|
74
|
-
})
|
|
71
|
+
const poolAddresses = Object.keys(vaultData.factorialPools);
|
|
72
|
+
const poolDataEntriesPromises = poolAddresses.map(async (poolAddress) => {
|
|
73
|
+
const pool = ctx.getByContract(pool_1.Pool, core_1.Address.parse(poolAddress));
|
|
74
|
+
return [poolAddress, await pool.getPoolData()];
|
|
75
|
+
});
|
|
76
|
+
const poolDataEntries = await Promise.all(poolDataEntriesPromises);
|
|
77
|
+
return Object.fromEntries(poolDataEntries);
|
|
75
78
|
}
|
|
76
|
-
async function
|
|
77
|
-
const strategyVault = getVault(ctx, strategyVaultAddress);
|
|
78
|
-
const vaultData = await strategyVault.getVaultData();
|
|
79
|
-
const poolInfo = {};
|
|
80
|
-
const poolDatas = await getPoolInfoForStrategyVault(ctx, strategyVaultAddress);
|
|
81
|
-
for (const [poolAddress, poolPosition] of Object.entries(vaultData.factorialPools)) {
|
|
82
|
-
const poolData = poolDatas[poolAddress];
|
|
83
|
-
const position = {};
|
|
84
|
-
for (const [assetAddress, assetPosition] of Object.entries(poolPosition)) {
|
|
85
|
-
const amountPosition = (0, pool_1.positionShareToAmount)(assetPosition, poolData.assets[assetAddress]);
|
|
86
|
-
position[assetAddress] = {
|
|
87
|
-
supplyShare: assetPosition.supply,
|
|
88
|
-
supplyAmount: amountPosition.supply,
|
|
89
|
-
borrowShare: assetPosition.borrow,
|
|
90
|
-
borrowAmount: amountPosition.borrow,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
poolInfo[poolAddress] = position;
|
|
94
|
-
}
|
|
95
|
-
return poolInfo;
|
|
96
|
-
}
|
|
97
|
-
async function getValuationContext(ctx, strategyVaultAddress) {
|
|
79
|
+
async function getValuationContext(ctx, vaultAddress) {
|
|
98
80
|
const compositeOracle = new composite_oracle_1.CompositeOracleV1(ctx);
|
|
99
|
-
const
|
|
100
|
-
const
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
81
|
+
const vault = ctx.getByContract(strategy_vault_1.StrategyVault, (0, utils_1.toAddress)(vaultAddress));
|
|
82
|
+
const vaultData = await vault.getVaultData();
|
|
83
|
+
const priceInfo = await compositeOracle.getVaultPriceWithDetails(vaultAddress, vaultData);
|
|
84
|
+
const poolPositions = await getPoolDataForStrategyVault(ctx, vaultAddress);
|
|
85
|
+
const poolContexts = {};
|
|
86
|
+
Object.entries(poolPositions).forEach(([poolAddress, poolState]) => poolContexts[poolAddress] = transform_1.PoolContext.fromPoolState(poolState));
|
|
87
|
+
const vaultStateContext = transform_1.VaultStateContext.fromStrategyVaultState(vaultData);
|
|
88
|
+
const amountContext = vaultStateContext.toAmountContext(poolContexts);
|
|
89
|
+
const valueContext = amountContext.toValueContext(priceInfo.allPrices);
|
|
90
|
+
const nativeValueDecomposedContext = transform_1.VaultNativeValueDecomposedContext.fromValueContext(valueContext, priceInfo.allPrices);
|
|
91
|
+
const nativeAmountDecomposedContext = transform_1.VaultNativeAmountDecomposedContext.fromDecomposedValueContext(nativeValueDecomposedContext, priceInfo.allPrices);
|
|
105
92
|
return {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
price: vaultPrice,
|
|
93
|
+
vaultStateContext,
|
|
94
|
+
amountContext,
|
|
95
|
+
valueContext,
|
|
96
|
+
nativeValueDecomposedContext,
|
|
97
|
+
nativeAmountDecomposedContext,
|
|
112
98
|
priceInfo,
|
|
113
99
|
};
|
|
114
100
|
}
|
|
115
101
|
async function getPrice(ctx, strategyVaultAddress) {
|
|
116
|
-
const valuationCtx = await getValuationContext(ctx, strategyVaultAddress);
|
|
117
|
-
return valuationCtx.price;
|
|
102
|
+
const valuationCtx = await getValuationContext(ctx, (0, utils_1.toAddress)(strategyVaultAddress));
|
|
103
|
+
return valuationCtx.priceInfo.price;
|
|
118
104
|
}
|
|
119
105
|
async function getUnderlyingPrices(ctx, strategyVaultAddress) {
|
|
120
|
-
const valuationCtx = await getValuationContext(ctx, strategyVaultAddress);
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
106
|
+
const valuationCtx = await getValuationContext(ctx, (0, utils_1.toAddress)(strategyVaultAddress));
|
|
107
|
+
const underlyingPriceEntries = Object.keys(valuationCtx.vaultStateContext.assets)
|
|
108
|
+
.map(assetAddress => {
|
|
109
|
+
const priceData = valuationCtx.priceInfo.allPrices[assetAddress];
|
|
110
|
+
if (!priceData)
|
|
111
|
+
throw new Error(`Price data not found for asset ${assetAddress}`);
|
|
112
|
+
return [assetAddress, priceData.price];
|
|
113
|
+
});
|
|
125
114
|
return Object.fromEntries(underlyingPriceEntries);
|
|
126
115
|
}
|
|
116
|
+
async function getNativeAmountDecomposedContext(ctx, strategyVaultAddress) {
|
|
117
|
+
const valuationCtx = await getValuationContext(ctx, (0, utils_1.toAddress)(strategyVaultAddress));
|
|
118
|
+
return valuationCtx.nativeAmountDecomposedContext;
|
|
119
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type Brand<T, B> = T & {
|
|
2
|
+
readonly __brand: B;
|
|
3
|
+
};
|
|
4
|
+
export type AssetAddress = Brand<string, 'AssetAddress'>;
|
|
5
|
+
export type PoolAddress = Brand<string, 'PoolAddress'>;
|
|
6
|
+
export type PoolAccountAddress = Brand<string, 'PoolAccountAddress'>;
|
|
7
|
+
export type VaultAddress = Brand<string, 'VaultAddress'>;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { AccountAssetState, AccountAssetStateWithDelta } from "../../contracts/core/account/type";
|
|
2
|
-
import { AssetPrice,
|
|
2
|
+
import { AssetPrice, AssetPrices, OnchainDataInfo } from "../../contracts/oracle/redstone-onchain-oracle/type";
|
|
3
3
|
import { PoolState } from "../../contracts/core/pool/type";
|
|
4
4
|
export declare class RiskCalculator {
|
|
5
5
|
accountStatus: Record<string, AccountAssetState>;
|
|
6
|
-
prices:
|
|
6
|
+
prices: AssetPrices;
|
|
7
7
|
onchainData: OnchainDataInfo;
|
|
8
8
|
poolData: PoolState;
|
|
9
9
|
PRICE_DECIMALS: number;
|
|
10
10
|
DELTA_DECIMALS: number;
|
|
11
11
|
RATIO_DECIMALS: number;
|
|
12
12
|
LEVERAGE_DECIMALS: number;
|
|
13
|
-
constructor(accountStatus: Record<string, AccountAssetState>, prices:
|
|
13
|
+
constructor(accountStatus: Record<string, AccountAssetState>, prices: AssetPrices, onchainData: OnchainDataInfo, poolData: PoolState);
|
|
14
14
|
calculateDeltaForTargetRiskRatio(_targetRiskRatio: bigint, // ex : 6000n
|
|
15
15
|
targetAsset: string, dualAsset?: string): SolutionForTargetRatio[];
|
|
16
16
|
calculateDeltaForTargetLeverage(_targetLeverage: bigint, // ex : 6000n
|