@affluent-org/sdk 0.0.4 → 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 +2 -32
- 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 +9 -134
- package/dist/services/strategy-vault/index.js +5 -1
- 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 +28 -40
- package/dist/utils/risk_calculator/risk_calculator.d.ts +3 -3
- package/package.json +1 -1
|
@@ -4,7 +4,7 @@ import { AddressInput, AddressLike } from "../../contracts/common/type";
|
|
|
4
4
|
import { JettonWallet } from "../../contracts/jetton/jetton-wallet";
|
|
5
5
|
import { RFQAuction } from "../../contracts/rfq/rfq_auction";
|
|
6
6
|
import { StrategyVault } from "../../contracts/vault/strategy-vault";
|
|
7
|
-
import {
|
|
7
|
+
import { VaultNativeAmountDecomposedContext, VaultNativeValueDecomposedContext, VaultStateContext } from "../../common/transform";
|
|
8
8
|
export declare function getVault(ctx: AffluentContext, strategyVaultAddress: AddressInput): OpenedContract<StrategyVault>;
|
|
9
9
|
export declare function getVaultData(ctx: AffluentContext, strategyVaultAddress: AddressLike): Promise<{
|
|
10
10
|
globalDepositValueCap: bigint;
|
|
@@ -137,149 +137,20 @@ export declare function splitPureAndVaultAsset(ctx: AffluentContext, addresses:
|
|
|
137
137
|
vaultAssetAddresses: string[];
|
|
138
138
|
pureAssetAddresses: string[];
|
|
139
139
|
}>;
|
|
140
|
-
export declare function getPoolDataForStrategyVault(ctx: AffluentContext, strategyVaultAddress: AddressInput): Promise<
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
depositQueueManager: import("../../contracts/vault/strategy-vault").QueueManager;
|
|
153
|
-
withdrawQueueManager: import("../../contracts/vault/strategy-vault").QueueManager;
|
|
154
|
-
interactiveVaultDict: Record<string, import("../../contracts/vault/strategy-vault").InteractiveVaultConfigItem>;
|
|
155
|
-
xchainConnectorAddress: Address | null;
|
|
156
|
-
xchainConfig: Record<string, {
|
|
157
|
-
connected: boolean;
|
|
158
|
-
xchainAccountAddress: bigint;
|
|
159
|
-
oftConfig: Map<string, {
|
|
160
|
-
destinationAddress: Address;
|
|
161
|
-
forwardGas: bigint;
|
|
162
|
-
forwardPayload?: import("@ton/core").Cell | null;
|
|
163
|
-
lzTransferFeeRate?: bigint;
|
|
164
|
-
}> | null;
|
|
165
|
-
strategyConfig: Map<bigint, {
|
|
166
|
-
isExecutable: boolean;
|
|
167
|
-
}> | null;
|
|
168
|
-
afterStrategyConfig: Map<bigint, {
|
|
169
|
-
isExecutable: boolean;
|
|
170
|
-
}> | null;
|
|
171
|
-
lzGasFee: bigint;
|
|
172
|
-
}>;
|
|
173
|
-
xchainUpdateHash: bigint;
|
|
174
|
-
owner: Address;
|
|
175
|
-
manager: Address;
|
|
176
|
-
assets: Record<string, import("../../contracts/vault/strategy-vault").AssetV2>;
|
|
177
|
-
factorialPools: Record<string, import("../../contracts/vault/strategy-vault").FactorialPool>;
|
|
178
|
-
aggregatorIndex: bigint;
|
|
179
|
-
content: import("@ton/core").Cell;
|
|
180
|
-
totalSupply: bigint;
|
|
181
|
-
oracleConfig: import("@ton/core").Cell | import("../../contracts/oracle/redstone-onchain-oracle/type").RedstoneOnchainOracleConfig | import("../../contracts/oracle/redstone-oracle/type").RedstonOracleConfig;
|
|
182
|
-
rfqConfig: {
|
|
183
|
-
priceDeviationTolerance: number;
|
|
184
|
-
rfqEventEmitterAddress: string | null;
|
|
185
|
-
} | null;
|
|
186
|
-
gasConfig: Record<string, bigint> | null;
|
|
187
|
-
isPrivateVault: boolean;
|
|
188
|
-
depositCloseTimestamp: number;
|
|
189
|
-
withdrawOpenTimestamp: number;
|
|
190
|
-
whitelistedMinters: import("@ton/core").Dictionary<Address, Boolean>;
|
|
191
|
-
lastCollectTime: number;
|
|
192
|
-
managementFeeRatePerYear: number;
|
|
193
|
-
protocolFeeRatePerYear: number;
|
|
194
|
-
collectedManagementFee: bigint;
|
|
195
|
-
collectedProtocolFee: bigint;
|
|
196
|
-
rfqCode: import("@ton/core").Cell;
|
|
197
|
-
walletCode: import("@ton/core").Cell;
|
|
198
|
-
dataAggregatorCode: import("@ton/core").Cell;
|
|
199
|
-
protocolFeeManagerAddress: Address;
|
|
200
|
-
rfqIndex: bigint;
|
|
201
|
-
isExecutingStrategy: boolean;
|
|
202
|
-
maxLeverageRatio: number;
|
|
203
|
-
assetWalletDict: Record<string, string>;
|
|
204
|
-
walletAssetDict: Record<string, string>;
|
|
205
|
-
managementFeeRecipientAddress: Address | null;
|
|
206
|
-
guardianAddress: Address | null;
|
|
207
|
-
timelock: bigint;
|
|
208
|
-
pendingOwnerActionIndex: bigint;
|
|
209
|
-
pendingOwnerActionCount: bigint;
|
|
210
|
-
pendingOwnerAction: any;
|
|
211
|
-
getFactorialPoolAsset: (poolAddress: Address, assetAddress: Address) => import("../../contracts/vault/strategy-vault").FactorialPoolShare;
|
|
212
|
-
getAsset: (assetAddress: Address) => import("../../contracts/vault/strategy-vault").AssetV2;
|
|
213
|
-
version: string;
|
|
214
|
-
address: Address;
|
|
215
|
-
balance: bigint;
|
|
216
|
-
code: import("@ton/core").Cell;
|
|
217
|
-
} | {
|
|
218
|
-
globalDepositValueCap: bigint;
|
|
219
|
-
withdrawFeeRate: number;
|
|
220
|
-
queueWithdrawFeeRate: number;
|
|
221
|
-
depositQueueManager: import("../../contracts/vault/strategy-vault").QueueManager;
|
|
222
|
-
withdrawQueueManager: import("../../contracts/vault/strategy-vault").QueueManager;
|
|
223
|
-
interactiveVaultDict: Record<string, import("../../contracts/vault/strategy-vault").InteractiveVaultConfigItem>;
|
|
224
|
-
xchainConnectorAddress: null;
|
|
225
|
-
xchainConfig: null;
|
|
226
|
-
xchainUpdateHash: bigint;
|
|
227
|
-
owner: Address;
|
|
228
|
-
manager: Address;
|
|
229
|
-
assets: Record<string, import("../../contracts/vault/strategy-vault").AssetV2>;
|
|
230
|
-
factorialPools: Record<string, import("../../contracts/vault/strategy-vault").FactorialPool>;
|
|
231
|
-
aggregatorIndex: bigint;
|
|
232
|
-
content: import("@ton/core").Cell;
|
|
233
|
-
totalSupply: bigint;
|
|
234
|
-
oracleConfig: import("@ton/core").Cell | import("../../contracts/oracle/redstone-onchain-oracle/type").RedstoneOnchainOracleConfig | import("../../contracts/oracle/redstone-oracle/type").RedstonOracleConfig;
|
|
235
|
-
rfqConfig: {
|
|
236
|
-
priceDeviationTolerance: number;
|
|
237
|
-
rfqEventEmitterAddress: string | null;
|
|
238
|
-
} | null;
|
|
239
|
-
gasConfig: Record<string, bigint> | null;
|
|
240
|
-
isPrivateVault: boolean;
|
|
241
|
-
depositCloseTimestamp: number;
|
|
242
|
-
withdrawOpenTimestamp: number;
|
|
243
|
-
whitelistedMinters: import("@ton/core").Dictionary<Address, Boolean>;
|
|
244
|
-
lastCollectTime: number;
|
|
245
|
-
managementFeeRatePerYear: number;
|
|
246
|
-
protocolFeeRatePerYear: number;
|
|
247
|
-
collectedManagementFee: bigint;
|
|
248
|
-
collectedProtocolFee: bigint;
|
|
249
|
-
rfqCode: import("@ton/core").Cell;
|
|
250
|
-
walletCode: import("@ton/core").Cell;
|
|
251
|
-
dataAggregatorCode: import("@ton/core").Cell;
|
|
252
|
-
protocolFeeManagerAddress: Address;
|
|
253
|
-
rfqIndex: bigint;
|
|
254
|
-
isExecutingStrategy: boolean;
|
|
255
|
-
maxLeverageRatio: number;
|
|
256
|
-
assetWalletDict: Record<string, string>;
|
|
257
|
-
walletAssetDict: Record<string, string>;
|
|
258
|
-
managementFeeRecipientAddress: Address | null;
|
|
259
|
-
guardianAddress: Address | null;
|
|
260
|
-
timelock: bigint;
|
|
261
|
-
pendingOwnerActionIndex: bigint;
|
|
262
|
-
pendingOwnerActionCount: bigint;
|
|
263
|
-
pendingOwnerAction: any;
|
|
264
|
-
getFactorialPoolAsset: (poolAddress: Address, assetAddress: Address) => import("../../contracts/vault/strategy-vault").FactorialPoolShare;
|
|
265
|
-
getAsset: (assetAddress: Address) => import("../../contracts/vault/strategy-vault").AssetV2;
|
|
266
|
-
version: string;
|
|
267
|
-
address: Address;
|
|
268
|
-
balance: bigint;
|
|
269
|
-
code: import("@ton/core").Cell;
|
|
270
|
-
};
|
|
271
|
-
totalSupply: bigint;
|
|
272
|
-
reserves: {
|
|
273
|
-
[k: string]: bigint;
|
|
140
|
+
export declare function getPoolDataForStrategyVault(ctx: AffluentContext, strategyVaultAddress: AddressInput): Promise<{
|
|
141
|
+
[k: string]: import("../..").PoolState;
|
|
142
|
+
}>;
|
|
143
|
+
export declare function getValuationContext(ctx: AffluentContext, vaultAddress: Address): Promise<{
|
|
144
|
+
vaultStateContext: VaultStateContext;
|
|
145
|
+
amountContext: import("../../common/transform").VaultAmountContext;
|
|
146
|
+
valueContext: import("../../common/transform").VaultValueContext;
|
|
147
|
+
nativeValueDecomposedContext: VaultNativeValueDecomposedContext;
|
|
148
|
+
nativeAmountDecomposedContext: VaultNativeAmountDecomposedContext;
|
|
149
|
+
priceInfo: import("../composite-oracle").CompositeOracleResult & {
|
|
150
|
+
targetVaultAddress: string;
|
|
151
|
+
price: bigint;
|
|
274
152
|
};
|
|
275
|
-
poolPositions: Record<string, Record<string, {
|
|
276
|
-
supplyShare: bigint;
|
|
277
|
-
supplyAmount: bigint;
|
|
278
|
-
borrowShare: bigint;
|
|
279
|
-
borrowAmount: bigint;
|
|
280
|
-
}>>;
|
|
281
|
-
price: bigint;
|
|
282
|
-
priceInfo: import("../composite-oracle").Prices;
|
|
283
153
|
}>;
|
|
284
154
|
export declare function getPrice(ctx: AffluentContext, strategyVaultAddress: AddressInput): Promise<bigint>;
|
|
285
155
|
export declare function getUnderlyingPrices(ctx: AffluentContext, strategyVaultAddress: AddressInput): Promise<any>;
|
|
156
|
+
export declare function getNativeAmountDecomposedContext(ctx: AffluentContext, strategyVaultAddress: AddressInput): Promise<VaultNativeAmountDecomposedContext>;
|
|
@@ -8,10 +8,10 @@ exports.getRFQAuction = getRFQAuction;
|
|
|
8
8
|
exports.isVaultAsset = isVaultAsset;
|
|
9
9
|
exports.splitPureAndVaultAsset = splitPureAndVaultAsset;
|
|
10
10
|
exports.getPoolDataForStrategyVault = getPoolDataForStrategyVault;
|
|
11
|
-
exports.getPoolPositionsForStrategyVault = getPoolPositionsForStrategyVault;
|
|
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
|
}
|
|
@@ -75,57 +76,44 @@ async function getPoolDataForStrategyVault(ctx, strategyVaultAddress) {
|
|
|
75
76
|
const poolDataEntries = await Promise.all(poolDataEntriesPromises);
|
|
76
77
|
return Object.fromEntries(poolDataEntries);
|
|
77
78
|
}
|
|
78
|
-
async function
|
|
79
|
-
const strategyVault = getVault(ctx, strategyVaultAddress);
|
|
80
|
-
const vaultData = await strategyVault.getVaultData();
|
|
81
|
-
const poolInfo = {};
|
|
82
|
-
const poolDatas = await getPoolDataForStrategyVault(ctx, strategyVaultAddress);
|
|
83
|
-
for (const [poolAddress, poolPosition] of Object.entries(vaultData.factorialPools)) {
|
|
84
|
-
const poolData = poolDatas[poolAddress];
|
|
85
|
-
const position = {};
|
|
86
|
-
for (const [assetAddress, assetPosition] of Object.entries(poolPosition)) {
|
|
87
|
-
const amountPosition = (0, pool_1.positionShareToAmount)(assetPosition, poolData.assets[assetAddress]);
|
|
88
|
-
position[assetAddress] = {
|
|
89
|
-
supplyShare: assetPosition.supply,
|
|
90
|
-
supplyAmount: amountPosition.supply,
|
|
91
|
-
borrowShare: assetPosition.borrow,
|
|
92
|
-
borrowAmount: amountPosition.borrow,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
poolInfo[poolAddress] = position;
|
|
96
|
-
}
|
|
97
|
-
return poolInfo;
|
|
98
|
-
}
|
|
99
|
-
async function getValuationContext(ctx, strategyVaultAddress) {
|
|
79
|
+
async function getValuationContext(ctx, vaultAddress) {
|
|
100
80
|
const compositeOracle = new composite_oracle_1.CompositeOracleV1(ctx);
|
|
101
|
-
const
|
|
102
|
-
const
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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);
|
|
107
92
|
return {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
price: vaultPrice,
|
|
93
|
+
vaultStateContext,
|
|
94
|
+
amountContext,
|
|
95
|
+
valueContext,
|
|
96
|
+
nativeValueDecomposedContext,
|
|
97
|
+
nativeAmountDecomposedContext,
|
|
114
98
|
priceInfo,
|
|
115
99
|
};
|
|
116
100
|
}
|
|
117
101
|
async function getPrice(ctx, strategyVaultAddress) {
|
|
118
|
-
const valuationCtx = await getValuationContext(ctx, strategyVaultAddress);
|
|
119
|
-
return valuationCtx.price;
|
|
102
|
+
const valuationCtx = await getValuationContext(ctx, (0, utils_1.toAddress)(strategyVaultAddress));
|
|
103
|
+
return valuationCtx.priceInfo.price;
|
|
120
104
|
}
|
|
121
105
|
async function getUnderlyingPrices(ctx, strategyVaultAddress) {
|
|
122
|
-
const valuationCtx = await getValuationContext(ctx, strategyVaultAddress);
|
|
123
|
-
const underlyingPriceEntries = Object.keys(valuationCtx.
|
|
106
|
+
const valuationCtx = await getValuationContext(ctx, (0, utils_1.toAddress)(strategyVaultAddress));
|
|
107
|
+
const underlyingPriceEntries = Object.keys(valuationCtx.vaultStateContext.assets)
|
|
124
108
|
.map(assetAddress => {
|
|
125
|
-
const priceData = valuationCtx.priceInfo[assetAddress];
|
|
109
|
+
const priceData = valuationCtx.priceInfo.allPrices[assetAddress];
|
|
126
110
|
if (!priceData)
|
|
127
111
|
throw new Error(`Price data not found for asset ${assetAddress}`);
|
|
128
112
|
return [assetAddress, priceData.price];
|
|
129
113
|
});
|
|
130
114
|
return Object.fromEntries(underlyingPriceEntries);
|
|
131
115
|
}
|
|
116
|
+
async function getNativeAmountDecomposedContext(ctx, strategyVaultAddress) {
|
|
117
|
+
const valuationCtx = await getValuationContext(ctx, (0, utils_1.toAddress)(strategyVaultAddress));
|
|
118
|
+
return valuationCtx.nativeAmountDecomposedContext;
|
|
119
|
+
}
|
|
@@ -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
|