@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.
Files changed (29) hide show
  1. package/dist/common/transform.d.ts +93 -0
  2. package/dist/common/transform.js +351 -0
  3. package/dist/common/types.d.ts +144 -0
  4. package/dist/common/types.js +11 -0
  5. package/dist/contracts/oracle/redstone-onchain-oracle/type.d.ts +1 -1
  6. package/dist/services/composite-oracle/codec.d.ts +76 -0
  7. package/dist/services/composite-oracle/codec.js +281 -0
  8. package/dist/services/composite-oracle/computation.d.ts +9 -15
  9. package/dist/services/composite-oracle/computation.js +44 -36
  10. package/dist/services/composite-oracle/index.d.ts +2 -2
  11. package/dist/services/composite-oracle/index.js +2 -2
  12. package/dist/services/composite-oracle/query.d.ts +6 -6
  13. package/dist/services/composite-oracle/query.js +7 -46
  14. package/dist/services/pool/computation.d.ts +3 -9
  15. package/dist/services/pool/computation.js +16 -30
  16. package/dist/services/pool/oracle.d.ts +2 -2
  17. package/dist/services/pool/query.d.ts +1 -1
  18. package/dist/services/rfq-auction/oracle.d.ts +2 -2
  19. package/dist/services/rfq-batch/oracle.d.ts +2 -2
  20. package/dist/services/share-vault/index.d.ts +2 -32
  21. package/dist/services/share-vault/query.d.ts +5 -32
  22. package/dist/services/share-vault/query.js +25 -12
  23. package/dist/services/strategy-vault/index.d.ts +9 -134
  24. package/dist/services/strategy-vault/index.js +5 -1
  25. package/dist/services/strategy-vault/oracle.d.ts +3 -3
  26. package/dist/services/strategy-vault/query.d.ts +14 -143
  27. package/dist/services/strategy-vault/query.js +28 -40
  28. package/dist/utils/risk_calculator/risk_calculator.d.ts +3 -3
  29. package/package.json +1 -1
@@ -0,0 +1,93 @@
1
+ import { Address, Cell } from "@ton/core";
2
+ import { PoolState } from "../contracts/core/pool/type";
3
+ import { ShareVaultState } from "../contracts/vault/share-vault";
4
+ import { StrategyVaultState } from "../contracts/vault/strategy-vault";
5
+ import { Prices, IPosition, ISharePosition, IValuePosition, IAmountPosition, IPoolAsset, IPoolContext, IVaultStateContext, IVaultAmountContext, IVaultValueContext, IPoolAmountPositions, IPoolValuePositions, IPoolSharePositions, IPoolContexts, IAmountPositionWithAddress } from "./types";
6
+ export declare class Position implements IPosition {
7
+ supply: bigint;
8
+ borrow: bigint;
9
+ constructor(supply?: bigint, borrow?: bigint);
10
+ apply(supply: bigint, borrow: bigint): this;
11
+ applyPosition(position: typeof this): this;
12
+ clone(): this;
13
+ }
14
+ export declare class SharePosition extends Position implements ISharePosition {
15
+ readonly _brand: 'SharePosition';
16
+ toAmountPosition(poolAsset: IPoolAsset): AmountPosition;
17
+ }
18
+ export declare class ValuePosition extends Position implements IValuePosition {
19
+ readonly _brand: 'ValuePosition';
20
+ toAmountPosition(price: bigint): AmountPosition;
21
+ static from(data: IPosition): ValuePosition;
22
+ net(): bigint;
23
+ }
24
+ export declare class AmountPosition extends Position implements IAmountPosition {
25
+ readonly _brand: 'AmountPosition';
26
+ toValuePosition(price: bigint): ValuePosition;
27
+ net(): bigint;
28
+ }
29
+ export declare class AmountPositionWithAddress extends AmountPosition implements IAmountPositionWithAddress {
30
+ address: Address;
31
+ constructor(address: Address, supply: bigint, borrow: bigint);
32
+ static from(data: {
33
+ address: Address;
34
+ supply: bigint;
35
+ borrow: bigint;
36
+ }): AmountPositionWithAddress;
37
+ }
38
+ export declare class PoolAsset implements IPoolAsset {
39
+ amount: AmountPosition;
40
+ share: SharePosition;
41
+ constructor(amount: AmountPosition, share: SharePosition);
42
+ }
43
+ export declare class PoolContext implements IPoolContext {
44
+ readonly address: string;
45
+ readonly assets: Record<string, IPoolAsset>;
46
+ constructor(address: string, assets?: Record<string, IPoolAsset>);
47
+ static fromPoolState(poolState: PoolState): PoolContext;
48
+ getAmountFrom(address: string, share: SharePosition): AmountPosition;
49
+ }
50
+ export declare class VaultStateContext implements IVaultStateContext {
51
+ readonly address: string;
52
+ readonly totalSupply: bigint;
53
+ readonly assets: Record<string, IAmountPosition>;
54
+ readonly pools: IPoolSharePositions;
55
+ constructor(address: string, totalSupply: bigint, assets: Record<string, IAmountPosition>, pools: IPoolSharePositions);
56
+ static fromShareVaultStateCell(address: Address, cell: Cell): VaultStateContext;
57
+ static fromShareVaultState(vaultState: Omit<ShareVaultState, 'code' | 'balance'>): VaultStateContext;
58
+ static fromStrategyVaultStateCell(address: Address, cell: Cell): VaultStateContext;
59
+ static fromStrategyVaultState(vaultState: Omit<StrategyVaultState, 'code' | 'balance'>): VaultStateContext;
60
+ toAmountContext(poolContexts: IPoolContexts): VaultAmountContext;
61
+ }
62
+ export declare class VaultAmountContext implements IVaultAmountContext {
63
+ readonly address: string;
64
+ readonly totalSupply: bigint;
65
+ readonly assets: Record<string, IAmountPosition>;
66
+ readonly pools: IPoolAmountPositions;
67
+ constructor(address: string, totalSupply: bigint, assets: Record<string, IAmountPosition>, pools: IPoolAmountPositions);
68
+ static fromVaultStateContext(VaultStateContext: VaultStateContext, poolContexts: IPoolContexts): VaultAmountContext;
69
+ toValueContext(prices: Prices): VaultValueContext;
70
+ net(): Record<string, IAmountPosition>;
71
+ }
72
+ export declare class VaultValueContext implements IVaultValueContext {
73
+ readonly address: string;
74
+ readonly assets: Record<string, IValuePosition>;
75
+ readonly pools: IPoolValuePositions;
76
+ constructor(address: string, assets: Record<string, IValuePosition>, pools: IPoolValuePositions);
77
+ static fromAmountContext(amountContext: VaultAmountContext, prices: Prices): VaultValueContext;
78
+ get totalValue(): bigint;
79
+ net(): Record<string, IValuePosition>;
80
+ }
81
+ export declare class VaultNativeValueDecomposedContext extends VaultValueContext {
82
+ static fromValueContext(valueContext: VaultValueContext, prices: Prices): VaultNativeValueDecomposedContext;
83
+ static decomposeContext(valueContext: Record<string, IValuePosition>, prices: Prices, nativeAssets: Record<string, IValuePosition>): Record<string, IValuePosition>;
84
+ net(): Record<string, IValuePosition>;
85
+ }
86
+ export declare class VaultNativeAmountDecomposedContext {
87
+ readonly address: string;
88
+ readonly totalSupply: bigint;
89
+ readonly assets: Record<string, IAmountPosition>;
90
+ constructor(address: string, totalSupply: bigint, assets: Record<string, IAmountPosition>);
91
+ net(): Record<string, IAmountPosition>;
92
+ static fromDecomposedValueContext(decomposedValueContext: VaultValueContext, prices: Prices): VaultNativeAmountDecomposedContext;
93
+ }
@@ -0,0 +1,351 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VaultNativeAmountDecomposedContext = exports.VaultNativeValueDecomposedContext = exports.VaultValueContext = exports.VaultAmountContext = exports.VaultStateContext = exports.PoolContext = exports.PoolAsset = exports.AmountPositionWithAddress = exports.AmountPosition = exports.ValuePosition = exports.SharePosition = exports.Position = void 0;
4
+ const pool_1 = require("../contracts/core/pool");
5
+ const share_vault_1 = require("../contracts/vault/share-vault");
6
+ const strategy_vault_1 = require("../contracts/vault/strategy-vault");
7
+ const types_1 = require("./types");
8
+ class Position {
9
+ supply;
10
+ borrow;
11
+ constructor(supply = 0n, borrow = 0n) {
12
+ this.supply = supply;
13
+ this.borrow = borrow;
14
+ }
15
+ apply(supply, borrow) {
16
+ this.supply += supply;
17
+ this.borrow += borrow;
18
+ return this;
19
+ }
20
+ applyPosition(position) {
21
+ this.supply += position.supply;
22
+ this.borrow += position.borrow;
23
+ return this;
24
+ }
25
+ clone() {
26
+ return new this.constructor(this.supply, this.borrow);
27
+ }
28
+ }
29
+ exports.Position = Position;
30
+ class SharePosition extends Position {
31
+ toAmountPosition(poolAsset) {
32
+ return new AmountPosition((0, pool_1.shareToAmount)(this.supply, poolAsset.amount.supply, poolAsset.share.supply), (0, pool_1.shareToAmount)(this.borrow, poolAsset.amount.borrow, poolAsset.share.borrow));
33
+ }
34
+ }
35
+ exports.SharePosition = SharePosition;
36
+ class ValuePosition extends Position {
37
+ toAmountPosition(price) {
38
+ return new AmountPosition(this.supply / price, this.borrow / price);
39
+ }
40
+ static from(data) {
41
+ return new this(data.supply, data.borrow);
42
+ }
43
+ net() {
44
+ return this.supply - this.borrow;
45
+ }
46
+ }
47
+ exports.ValuePosition = ValuePosition;
48
+ class AmountPosition extends Position {
49
+ toValuePosition(price) {
50
+ return new ValuePosition(this.supply * price, this.borrow * price);
51
+ }
52
+ net() {
53
+ return this.supply - this.borrow;
54
+ }
55
+ }
56
+ exports.AmountPosition = AmountPosition;
57
+ class AmountPositionWithAddress extends AmountPosition {
58
+ address;
59
+ constructor(address, supply, borrow) {
60
+ super(supply, borrow);
61
+ this.address = address;
62
+ }
63
+ static from(data) {
64
+ return new this(data.address, data.supply, data.borrow);
65
+ }
66
+ }
67
+ exports.AmountPositionWithAddress = AmountPositionWithAddress;
68
+ class PoolAsset {
69
+ amount;
70
+ share;
71
+ constructor(amount, share) {
72
+ this.amount = amount;
73
+ this.share = share;
74
+ }
75
+ }
76
+ exports.PoolAsset = PoolAsset;
77
+ class PoolContext {
78
+ address;
79
+ assets;
80
+ constructor(address, assets = {}) {
81
+ this.address = address;
82
+ this.assets = assets;
83
+ }
84
+ static fromPoolState(poolState) {
85
+ const assets = {};
86
+ Object.entries(poolState.assets)
87
+ .forEach(([asset, assetState]) => {
88
+ assets[asset] = {
89
+ amount: new AmountPosition(assetState.totalSupplyAmount, assetState.totalBorrowAmount),
90
+ share: new SharePosition(assetState.totalSupplyShare, assetState.totalBorrowShare),
91
+ };
92
+ });
93
+ return new this(poolState.address.toString(), assets);
94
+ }
95
+ getAmountFrom(address, share) {
96
+ const asset = this.assets[address];
97
+ if (!asset)
98
+ throw new Error(`Asset not found: ${address}`);
99
+ return new AmountPosition((0, pool_1.shareToAmount)(share.supply, asset.amount.supply, asset.share.supply), (0, pool_1.shareToAmount)(share.borrow, asset.amount.borrow, asset.share.borrow));
100
+ }
101
+ }
102
+ exports.PoolContext = PoolContext;
103
+ class VaultStateContext {
104
+ address;
105
+ totalSupply;
106
+ assets;
107
+ pools;
108
+ constructor(address, totalSupply, assets, pools) {
109
+ this.address = address;
110
+ this.totalSupply = totalSupply;
111
+ this.assets = assets;
112
+ this.pools = pools;
113
+ }
114
+ static fromShareVaultStateCell(address, cell) {
115
+ const vaultData = share_vault_1.ShareVault.parseVaultData(cell);
116
+ return this.fromShareVaultState({ address, ...vaultData });
117
+ }
118
+ static fromShareVaultState(vaultState) {
119
+ const asset = vaultState.asset.toString();
120
+ const assets = {
121
+ [asset]: new AmountPosition(vaultState.cash, 0n),
122
+ };
123
+ const pools = {};
124
+ Object.entries(vaultState.whitelistedPools)
125
+ .forEach(([pool, poolState]) => {
126
+ pools[pool] = {
127
+ [asset]: new SharePosition(poolState.supply, 0n),
128
+ };
129
+ });
130
+ return new this(vaultState.address.toString(), vaultState.totalSupply, assets, pools);
131
+ }
132
+ static fromStrategyVaultStateCell(address, cell) {
133
+ const vaultData = strategy_vault_1.StrategyVault.parseVaultData(cell);
134
+ return this.fromStrategyVaultState({ address, ...vaultData });
135
+ }
136
+ static fromStrategyVaultState(vaultState) {
137
+ const assets = {};
138
+ Object.entries(vaultState.assets)
139
+ .forEach(([asset, assetState]) => {
140
+ assets[asset] = new AmountPosition(assetState.cash, 0n);
141
+ });
142
+ const pools = {};
143
+ Object.entries(vaultState.factorialPools)
144
+ .forEach(([pool, poolState]) => {
145
+ const poolEntry = {};
146
+ Object.entries(poolState)
147
+ .forEach(([asset, assetState]) => {
148
+ poolEntry[asset] = new SharePosition(assetState.supply, assetState.borrow);
149
+ });
150
+ pools[pool] = poolEntry;
151
+ });
152
+ return new this(vaultState.address.toString(), vaultState.totalSupply, assets, pools);
153
+ }
154
+ toAmountContext(poolContexts) {
155
+ return VaultAmountContext.fromVaultStateContext(this, poolContexts);
156
+ }
157
+ }
158
+ exports.VaultStateContext = VaultStateContext;
159
+ class VaultAmountContext {
160
+ address;
161
+ totalSupply;
162
+ assets;
163
+ pools;
164
+ constructor(address, totalSupply, assets, pools) {
165
+ this.address = address;
166
+ this.totalSupply = totalSupply;
167
+ this.assets = assets;
168
+ this.pools = pools;
169
+ }
170
+ static fromVaultStateContext(VaultStateContext, poolContexts) {
171
+ const assets = {};
172
+ Object.entries(VaultStateContext.assets)
173
+ .forEach(([asset, amount]) => assets[asset] = amount.clone());
174
+ const pools = {};
175
+ Object.entries(VaultStateContext.pools)
176
+ .forEach(([pool, poolPosition]) => {
177
+ const poolEntry = {};
178
+ Object.entries(poolPosition)
179
+ .forEach(([asset, sharePosition]) => poolEntry[asset] = poolContexts[pool].getAmountFrom(asset, sharePosition));
180
+ pools[pool] = poolEntry;
181
+ });
182
+ return new this(VaultStateContext.address, VaultStateContext.totalSupply, assets, pools);
183
+ }
184
+ toValueContext(prices) {
185
+ return VaultValueContext.fromAmountContext(this, prices);
186
+ }
187
+ net() {
188
+ const net = {};
189
+ Object.entries(this.assets)
190
+ .forEach(([asset, position]) => {
191
+ net[asset] = position.clone();
192
+ });
193
+ Object.entries(this.pools)
194
+ .forEach(([pool, poolPosition]) => {
195
+ Object.entries(poolPosition)
196
+ .forEach(([asset, amountPosition]) => {
197
+ net[asset] = (net[asset] ?? new AmountPosition()).applyPosition(amountPosition);
198
+ });
199
+ });
200
+ return net;
201
+ }
202
+ }
203
+ exports.VaultAmountContext = VaultAmountContext;
204
+ class VaultValueContext {
205
+ address;
206
+ assets;
207
+ pools;
208
+ constructor(address, assets, pools) {
209
+ this.address = address;
210
+ this.assets = assets;
211
+ this.pools = pools;
212
+ }
213
+ static fromAmountContext(amountContext, prices) {
214
+ const assets = {};
215
+ Object.entries(amountContext.assets)
216
+ .forEach(([asset, position]) => assets[asset] = position.toValuePosition(prices[asset].price));
217
+ const pools = {};
218
+ Object.entries(amountContext.pools)
219
+ .forEach(([pool, poolState]) => {
220
+ const poolEntry = {};
221
+ Object.entries(poolState)
222
+ .forEach(([asset, assetState]) => poolEntry[asset] = assetState.toValuePosition(prices[asset].price));
223
+ pools[pool] = poolEntry;
224
+ });
225
+ return new this(amountContext.address, assets, pools);
226
+ }
227
+ get totalValue() {
228
+ let totalValue = 0n;
229
+ Object.entries(this.assets)
230
+ .forEach(([asset, position]) => totalValue += position.net());
231
+ Object.entries(this.pools)
232
+ .forEach(([_pool, poolPosition]) => Object.entries(poolPosition)
233
+ .forEach(([_, position]) => totalValue += position.net()));
234
+ return totalValue;
235
+ }
236
+ net() {
237
+ const net = {};
238
+ Object.entries(this.assets)
239
+ .forEach(([asset, position]) => {
240
+ net[asset] = position.clone();
241
+ });
242
+ Object.entries(this.pools)
243
+ .forEach(([_, poolPosition]) => {
244
+ Object.entries(poolPosition)
245
+ .forEach(([asset, position]) => {
246
+ net[asset] = (net[asset] ?? new ValuePosition()).applyPosition(position);
247
+ });
248
+ });
249
+ return net;
250
+ }
251
+ }
252
+ exports.VaultValueContext = VaultValueContext;
253
+ class VaultNativeValueDecomposedContext extends VaultValueContext {
254
+ static fromValueContext(valueContext, prices) {
255
+ const assetsNativePositions = {};
256
+ VaultNativeValueDecomposedContext.decomposeContext(valueContext.assets, prices, assetsNativePositions);
257
+ const poolsNativePositions = {};
258
+ Object.entries(valueContext.pools)
259
+ .forEach(([pool, poolPosition]) => {
260
+ const nativePoolPosition = {};
261
+ VaultNativeValueDecomposedContext.decomposeContext(poolPosition, prices, nativePoolPosition);
262
+ poolsNativePositions[pool] = nativePoolPosition;
263
+ });
264
+ return new this(valueContext.address, assetsNativePositions, poolsNativePositions);
265
+ }
266
+ static decomposeContext(valueContext, prices, nativeAssets) {
267
+ Object.entries(valueContext)
268
+ .forEach(([asset, position]) => {
269
+ const price = prices[asset];
270
+ if (price.type === types_1.CompositeAssetType.NATIVE) {
271
+ nativeAssets[asset] = (nativeAssets[asset] ?? new ValuePosition()).applyPosition(position);
272
+ }
273
+ else if (price.type === types_1.CompositeAssetType.SYNTHETIC1) {
274
+ if (prices[price.additionalData.underlying].type !== types_1.CompositeAssetType.NATIVE)
275
+ throw new Error(`Invalid underlying asset type: ${price.additionalData.underlying}`);
276
+ nativeAssets[price.additionalData.underlying] = (nativeAssets[price.additionalData.underlying] ?? new ValuePosition())
277
+ .apply(position.supply, position.borrow);
278
+ }
279
+ else if (price.type === types_1.CompositeAssetType.SYNTHETIC2) {
280
+ if (prices[price.additionalData0.underlying].type !== types_1.CompositeAssetType.NATIVE)
281
+ throw new Error(`Invalid underlying asset type: ${price.additionalData0.underlying}`);
282
+ if (prices[price.additionalData1.underlying].type !== types_1.CompositeAssetType.NATIVE)
283
+ throw new Error(`Invalid underlying asset type: ${price.additionalData1.underlying}`);
284
+ const price0 = prices[price.additionalData0.underlying].price;
285
+ const price1 = prices[price.additionalData1.underlying].price;
286
+ const totalValue = price.additionalData0.reserve * price0 + price.additionalData1.reserve * price1;
287
+ nativeAssets[price.additionalData0.underlying] = (nativeAssets[price.additionalData0.underlying] ?? new ValuePosition())
288
+ .apply(position.supply * price.additionalData0.reserve * price0 / totalValue, position.borrow * price.additionalData0.reserve * price0 / totalValue);
289
+ nativeAssets[price.additionalData1.underlying] = (nativeAssets[price.additionalData1.underlying] ?? new ValuePosition())
290
+ .apply(position.supply * price.additionalData1.reserve * price1 / totalValue, position.borrow * price.additionalData1.reserve * price1 / totalValue);
291
+ }
292
+ else if (price.type === types_1.CompositeAssetType.VAULT) {
293
+ // dependencyVaultValue
294
+ const depVaultValue = price.price * price.additionalData.totalSupply;
295
+ const decomposedPosition = {};
296
+ Object.entries(price.additionalData.decomposed)
297
+ .forEach(([depAsset, depPosition]) => {
298
+ const decomposedAssetPrice = prices[depAsset].price;
299
+ const depVaultPosition = new AmountPosition(depPosition.supply, depPosition.borrow)
300
+ .toValuePosition(decomposedAssetPrice);
301
+ decomposedPosition[depAsset] = new ValuePosition((position.supply * depVaultPosition.supply + position.borrow * depVaultPosition.borrow) / depVaultValue, (position.supply * depVaultPosition.borrow + position.borrow * depVaultPosition.supply) / depVaultValue);
302
+ });
303
+ VaultNativeValueDecomposedContext.decomposeContext(decomposedPosition, prices, nativeAssets);
304
+ }
305
+ else {
306
+ throw new Error(`Invalid asset type: ${price}`);
307
+ }
308
+ });
309
+ return nativeAssets;
310
+ }
311
+ net() {
312
+ const net = {};
313
+ Object.entries(this.assets)
314
+ .forEach(([asset, position]) => {
315
+ net[asset] ??= new ValuePosition();
316
+ net[asset].applyPosition(position);
317
+ });
318
+ Object.entries(this.pools)
319
+ .forEach(([_pool, poolPosition]) => Object.entries(poolPosition)
320
+ .forEach(([asset, position]) => {
321
+ net[asset] ??= new ValuePosition();
322
+ net[asset].applyPosition(position);
323
+ }));
324
+ return net;
325
+ }
326
+ }
327
+ exports.VaultNativeValueDecomposedContext = VaultNativeValueDecomposedContext;
328
+ class VaultNativeAmountDecomposedContext {
329
+ address;
330
+ totalSupply;
331
+ assets;
332
+ constructor(address, totalSupply, assets) {
333
+ this.address = address;
334
+ this.totalSupply = totalSupply;
335
+ this.assets = assets;
336
+ }
337
+ net() {
338
+ throw new Error("Method not implemented.");
339
+ }
340
+ static fromDecomposedValueContext(decomposedValueContext, prices) {
341
+ const totalSupply = decomposedValueContext.totalValue / prices[decomposedValueContext.address].price;
342
+ const net = decomposedValueContext.net();
343
+ const assets = {};
344
+ Object.entries(net)
345
+ .forEach(([asset, position]) => {
346
+ assets[asset] = position.toAmountPosition(prices[asset].price);
347
+ });
348
+ return new this(decomposedValueContext.address, totalSupply, assets);
349
+ }
350
+ }
351
+ exports.VaultNativeAmountDecomposedContext = VaultNativeAmountDecomposedContext;
@@ -0,0 +1,144 @@
1
+ import { Address } from "@ton/core";
2
+ export declare const DECIMALS_OF_PRICE = 100000000n;
3
+ export declare enum CompositeAssetType {
4
+ NATIVE = 0,
5
+ SYNTHETIC1 = 1,
6
+ SYNTHETIC2 = 2,
7
+ VAULT = 10
8
+ }
9
+ export type NativePriceEntry = {
10
+ type: CompositeAssetType.NATIVE;
11
+ price: bigint;
12
+ timestamp?: number;
13
+ };
14
+ export type SyntheticAssetAdditionalData = {
15
+ underlying: string;
16
+ reserve: bigint;
17
+ totalSupply: bigint;
18
+ };
19
+ export type Synthetic1PriceEntry = {
20
+ type: CompositeAssetType.SYNTHETIC1;
21
+ price: bigint;
22
+ timestamp?: number;
23
+ additionalData: SyntheticAssetAdditionalData;
24
+ };
25
+ export type Synthetic2PriceEntry = {
26
+ type: CompositeAssetType.SYNTHETIC2;
27
+ price: bigint;
28
+ timestamp?: number;
29
+ additionalData0: SyntheticAssetAdditionalData;
30
+ additionalData1: SyntheticAssetAdditionalData;
31
+ };
32
+ export type VaultPriceEntry = {
33
+ type: CompositeAssetType.VAULT;
34
+ price: bigint;
35
+ timestamp?: number;
36
+ additionalData: VaultComposition;
37
+ };
38
+ export type PriceEntry = NativePriceEntry | Synthetic1PriceEntry | Synthetic2PriceEntry | VaultPriceEntry;
39
+ export type Prices = Record<string, PriceEntry>;
40
+ export type PoolShareInfo = {
41
+ totalSupplyAmount: bigint;
42
+ totalSupplyShare: bigint;
43
+ totalBorrowAmount: bigint;
44
+ totalBorrowShare: bigint;
45
+ };
46
+ export type PoolInfos = Record<string, Record<string, PoolShareInfo>>;
47
+ export type SingleAssetData = {
48
+ assetType: CompositeAssetType.SYNTHETIC1;
49
+ underlyingAddress: Address | string;
50
+ underlyingReserve: bigint;
51
+ totalSupply: bigint;
52
+ };
53
+ export type MultiAssetData = {
54
+ assetType: CompositeAssetType.SYNTHETIC2;
55
+ underlying0Address: Address | string;
56
+ underlying1Address: Address | string;
57
+ underlying0Reserve: bigint;
58
+ underlying1Reserve: bigint;
59
+ totalSupply: bigint;
60
+ };
61
+ export type SyntheticComposition = SingleAssetData | MultiAssetData;
62
+ export type SyntheticCompositions = Record<string, SyntheticComposition>;
63
+ /** @deprecated Use SyntheticComposition instead */
64
+ export type OnchainData = SyntheticComposition;
65
+ /** @deprecated Use SyntheticCompositions instead */
66
+ export type OnchainDataMap = SyntheticCompositions;
67
+ export type VaultComposition = {
68
+ decomposed: Record<string, {
69
+ supply: bigint;
70
+ borrow: bigint;
71
+ }>;
72
+ totalSupply: bigint;
73
+ };
74
+ export type VaultCompositions = Record<string, VaultComposition>;
75
+ export type VaultPrices = Record<string, VaultPriceEntry>;
76
+ export type CompositeOracleResult = {
77
+ assetPrices: Prices;
78
+ vaultPrices: VaultPrices;
79
+ allPrices: Prices;
80
+ };
81
+ export type CompositeOracleInput = {
82
+ rawPrices: Prices;
83
+ syntheticCompositions: SyntheticCompositions;
84
+ vaultPositions: Record<string, IVaultStateContext>;
85
+ poolInfos: Record<string, IPoolContext>;
86
+ };
87
+ export interface IPosition {
88
+ supply: bigint;
89
+ borrow: bigint;
90
+ apply(supply: bigint, borrow: bigint): this;
91
+ applyPosition(position: this): this;
92
+ clone(): this;
93
+ }
94
+ export interface ISharePosition extends IPosition {
95
+ readonly _brand: 'SharePosition';
96
+ toAmountPosition(poolAsset: IPoolAsset): IAmountPosition;
97
+ }
98
+ export interface IValuePosition extends IPosition {
99
+ readonly _brand: 'ValuePosition';
100
+ toAmountPosition(price: bigint): IAmountPosition;
101
+ net(): bigint;
102
+ }
103
+ export interface IAmountPosition extends IPosition {
104
+ readonly _brand: 'AmountPosition';
105
+ toValuePosition(price: bigint): IValuePosition;
106
+ net(): bigint;
107
+ }
108
+ export interface IAmountPositionWithAddress extends IAmountPosition {
109
+ address: Address;
110
+ }
111
+ export interface IPoolAsset {
112
+ amount: IAmountPosition;
113
+ share: ISharePosition;
114
+ }
115
+ export type IPoolAmountPositions = Record<string, Record<string, IAmountPosition>>;
116
+ export type IPoolValuePositions = Record<string, Record<string, IValuePosition>>;
117
+ export type IPoolSharePositions = Record<string, Record<string, ISharePosition>>;
118
+ export interface IPoolContext {
119
+ readonly address: string;
120
+ readonly assets: Record<string, IPoolAsset>;
121
+ getAmountFrom(address: string, share: ISharePosition): IAmountPosition;
122
+ }
123
+ export type IPoolContexts = Record<string, IPoolContext>;
124
+ export interface IVaultStateContext {
125
+ readonly address: string;
126
+ readonly totalSupply: bigint;
127
+ readonly assets: Record<string, IAmountPosition>;
128
+ readonly pools: IPoolSharePositions;
129
+ toAmountContext(poolContexts: IPoolContexts): IVaultAmountContext;
130
+ }
131
+ export interface IVaultAmountContext {
132
+ readonly address: string;
133
+ readonly totalSupply: bigint;
134
+ readonly assets: Record<string, IAmountPosition>;
135
+ readonly pools: IPoolAmountPositions;
136
+ net(): Record<string, IAmountPosition>;
137
+ }
138
+ export interface IVaultValueContext {
139
+ readonly address: string;
140
+ readonly assets: Record<string, IValuePosition>;
141
+ readonly pools: IPoolValuePositions;
142
+ readonly totalValue: bigint;
143
+ net(): Record<string, IValuePosition>;
144
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CompositeAssetType = exports.DECIMALS_OF_PRICE = void 0;
4
+ exports.DECIMALS_OF_PRICE = 100000000n;
5
+ var CompositeAssetType;
6
+ (function (CompositeAssetType) {
7
+ CompositeAssetType[CompositeAssetType["NATIVE"] = 0] = "NATIVE";
8
+ CompositeAssetType[CompositeAssetType["SYNTHETIC1"] = 1] = "SYNTHETIC1";
9
+ CompositeAssetType[CompositeAssetType["SYNTHETIC2"] = 2] = "SYNTHETIC2";
10
+ CompositeAssetType[CompositeAssetType["VAULT"] = 10] = "VAULT";
11
+ })(CompositeAssetType || (exports.CompositeAssetType = CompositeAssetType = {}));
@@ -49,7 +49,7 @@ export type OnchainDataInfoInternal = OnchainDataInfoBase & {
49
49
  };
50
50
  export type OnchainData = OnchainDataInfoNative | OnchainDataInfoSingleAsset | OnchainDataInfoMultiAsset;
51
51
  export type OnchainDataInfo = Record<string, OnchainData>;
52
- export type AssetPriceInfo = Record<string, AssetPrice>;
52
+ export type AssetPrices = Record<string, AssetPrice>;
53
53
  export type AssetPrice = {
54
54
  type: AssetType;
55
55
  price: bigint;
@@ -0,0 +1,76 @@
1
+ import { PoolState } from "../../contracts/core/pool/type";
2
+ import { ShareVaultState } from "../../contracts/vault/share-vault";
3
+ import { StrategyVaultState } from "../../contracts/vault/strategy-vault";
4
+ import { Prices } from "./types";
5
+ export declare class Position {
6
+ supply: bigint;
7
+ borrow: bigint;
8
+ constructor(supply: bigint, borrow: bigint);
9
+ apply(supply: bigint, borrow: bigint): this;
10
+ applyPosition(position: typeof this): this;
11
+ clone(): typeof this;
12
+ }
13
+ export declare class SharePosition extends Position {
14
+ toAmountPosition(PoolContext: PoolAsset): AmountPosition;
15
+ }
16
+ export declare class ValuePosition extends Position {
17
+ net(): bigint;
18
+ }
19
+ export declare class AmountPosition extends ValuePosition {
20
+ toValuePosition(price: bigint): ValuePosition;
21
+ net(): bigint;
22
+ }
23
+ export declare class PoolAsset {
24
+ amount: AmountPosition;
25
+ share: SharePosition;
26
+ constructor(amount: AmountPosition, share: SharePosition);
27
+ }
28
+ export type PoolAssets = Record<string, PoolAsset>;
29
+ export declare class PoolContext {
30
+ readonly address: string;
31
+ readonly assets: PoolAssets;
32
+ constructor(address: string, assets?: PoolAssets);
33
+ static fromPoolState(poolState: PoolState): PoolContext;
34
+ }
35
+ export type PoolContexts = Record<string, PoolContext>;
36
+ export type AmountPositions = Record<string, AmountPosition>;
37
+ export type SharePositions = Record<string, SharePosition>;
38
+ export type ValuePositions = Record<string, ValuePosition>;
39
+ export type PoolAmountPositions = Record<string, AmountPositions>;
40
+ export type PoolValuePositions = Record<string, ValuePositions>;
41
+ export type PoolSharePositions = Record<string, SharePositions>;
42
+ export declare class VaultStateContext {
43
+ readonly address: string;
44
+ readonly totalSupply: bigint;
45
+ readonly assets: AmountPositions;
46
+ readonly pools: PoolSharePositions;
47
+ constructor(address: string, totalSupply: bigint, assets: AmountPositions, // amount
48
+ pools: PoolSharePositions);
49
+ static fromShareVaultState(vaultState: ShareVaultState): VaultStateContext;
50
+ static fromStrategyVaultState(vaultState: StrategyVaultState): VaultStateContext;
51
+ toAmountContext(poolContexts: PoolContexts): VaultAmountContext;
52
+ }
53
+ export declare class VaultAmountContext {
54
+ readonly address: string;
55
+ readonly totalSupply: bigint;
56
+ readonly assets: AmountPositions;
57
+ readonly pools: PoolAmountPositions;
58
+ constructor(address: string, totalSupply: bigint, assets: AmountPositions, pools: PoolAmountPositions);
59
+ static fromVaultStateContext(VaultStateContext: VaultStateContext, poolContexts: PoolContexts): VaultAmountContext;
60
+ toValueContext(prices: Prices): VaultValueContext;
61
+ net(): AmountPositions;
62
+ }
63
+ export declare class VaultValueContext {
64
+ readonly address: string;
65
+ readonly assets: ValuePositions;
66
+ readonly pools: PoolValuePositions;
67
+ constructor(address: string, assets: ValuePositions, pools: PoolValuePositions);
68
+ static fromAmountContext(amountContext: VaultAmountContext, prices: Prices): VaultValueContext;
69
+ get totalValue(): bigint;
70
+ net(): ValuePositions;
71
+ nativeDecompose(prices: Prices): VaultNativeDecomposedValueContext;
72
+ }
73
+ export declare class VaultNativeDecomposedValueContext extends VaultValueContext {
74
+ static fromValueContext(valueContext: VaultValueContext, prices: Prices): VaultNativeDecomposedValueContext;
75
+ static decomposeContext(valueContext: ValuePositions, prices: Prices, nativeAssets: ValuePositions): ValuePositions;
76
+ }