@evaafi/sdk 0.9.0 → 0.9.2-a
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/api/feeds.d.ts +15 -24
- package/dist/api/feeds.js +22 -49
- package/dist/api/math.d.ts +1 -1
- package/dist/api/math.js +55 -38
- package/dist/api/parser.d.ts +2 -2
- package/dist/api/parser.js +3 -3
- package/dist/api/parsers/PythOracleParser.d.ts +3 -2
- package/dist/api/parsers/PythOracleParser.js +2 -1
- package/dist/api/prices.js +2 -1
- package/dist/constants/assets/assetId.d.ts +3 -1
- package/dist/constants/assets/assetId.js +5 -1
- package/dist/constants/assets/mainnet.d.ts +2 -0
- package/dist/constants/assets/mainnet.js +13 -1
- package/dist/constants/general/index.d.ts +25 -11
- package/dist/constants/general/index.js +15 -1
- package/dist/constants/general/mainnet.d.ts +2 -1
- package/dist/constants/general/mainnet.js +3 -2
- package/dist/constants/pools/mainnet.d.ts +4 -0
- package/dist/constants/pools/mainnet.js +45 -28
- package/dist/constants/pools/testnet.js +14 -6
- package/dist/contracts/AbstractMaster.d.ts +239 -127
- package/dist/contracts/AbstractMaster.js +101 -16
- package/dist/contracts/ClassicMaster.d.ts +12 -12
- package/dist/contracts/PythMaster.d.ts +40 -24
- package/dist/contracts/PythMaster.js +61 -76
- package/dist/contracts/PythOracle.d.ts +15 -0
- package/dist/contracts/PythOracle.js +19 -0
- package/dist/contracts/index.d.ts +1 -0
- package/dist/contracts/index.js +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/{prices → oracles}/Types.d.ts +0 -4
- package/dist/oracles/collectors/AbstractCollector.d.ts +10 -0
- package/dist/oracles/collectors/AbstractCollector.js +6 -0
- package/dist/oracles/collectors/ClassicCollector.d.ts +22 -0
- package/dist/oracles/collectors/ClassicCollector.js +192 -0
- package/dist/oracles/collectors/PythCollector.d.ts +27 -0
- package/dist/oracles/collectors/PythCollector.js +266 -0
- package/dist/oracles/collectors/index.d.ts +3 -0
- package/dist/oracles/collectors/index.js +19 -0
- package/dist/{prices → oracles}/index.d.ts +2 -3
- package/dist/{prices → oracles}/index.js +2 -3
- package/dist/oracles/prices/AbstractPrices.d.ts +33 -0
- package/dist/oracles/prices/AbstractPrices.js +40 -0
- package/dist/oracles/prices/ClassicPrices.d.ts +19 -0
- package/dist/oracles/prices/ClassicPrices.js +48 -0
- package/dist/oracles/prices/PythPrices.d.ts +17 -0
- package/dist/oracles/prices/PythPrices.js +32 -0
- package/dist/oracles/prices/index.d.ts +3 -0
- package/dist/oracles/prices/index.js +19 -0
- package/dist/{prices → oracles}/sources/Backend.js +11 -8
- package/dist/{prices → oracles}/sources/Icp.js +10 -6
- package/dist/{prices → oracles}/utils.d.ts +6 -1
- package/dist/{prices → oracles}/utils.js +10 -1
- package/dist/types/Master.d.ts +4 -5
- package/dist/utils/fivaUtils.d.ts +2 -0
- package/dist/utils/fivaUtils.js +19 -0
- package/dist/utils/userJettonWallet.js +15 -1
- package/dist/utils/utils.d.ts +1 -1
- package/dist/utils/utils.js +4 -2
- package/package.json +1 -1
- package/src/api/feeds.ts +24 -60
- package/src/api/math.ts +118 -90
- package/src/api/parser.ts +5 -5
- package/src/api/parsers/PythOracleParser.ts +6 -2
- package/src/api/prices.ts +2 -1
- package/src/constants/assets/assetId.ts +7 -1
- package/src/constants/assets/mainnet.ts +24 -0
- package/src/constants/general/index.ts +16 -1
- package/src/constants/general/mainnet.ts +2 -1
- package/src/constants/pools/mainnet.ts +42 -38
- package/src/constants/pools/testnet.ts +17 -8
- package/src/contracts/AbstractMaster.ts +272 -144
- package/src/contracts/ClassicMaster.ts +12 -12
- package/src/contracts/PythMaster.ts +130 -123
- package/src/contracts/PythOracle.ts +20 -0
- package/src/contracts/index.ts +2 -0
- package/src/index.ts +1 -1
- package/src/{prices → oracles}/Types.ts +0 -5
- package/src/oracles/collectors/AbstractCollector.ts +22 -0
- package/src/oracles/collectors/ClassicCollector.ts +263 -0
- package/src/oracles/collectors/PythCollector.ts +372 -0
- package/src/oracles/collectors/index.ts +3 -0
- package/src/{prices → oracles}/index.ts +2 -3
- package/src/oracles/prices/AbstractPrices.ts +59 -0
- package/src/oracles/prices/ClassicPrices.ts +52 -0
- package/src/oracles/prices/PythPrices.ts +40 -0
- package/src/oracles/prices/index.ts +3 -0
- package/src/{prices → oracles}/sources/Backend.ts +12 -11
- package/src/{prices → oracles}/sources/Icp.ts +10 -9
- package/src/{prices → oracles}/utils.ts +12 -1
- package/src/types/Master.ts +4 -6
- package/src/utils/fivaUtils.ts +19 -0
- package/src/utils/userJettonWallet.ts +18 -1
- package/src/utils/utils.ts +4 -2
- package/dist/api/pyth.d.ts +0 -16
- package/dist/api/pyth.js +0 -35
- package/dist/constants/assets.d.ts +0 -48
- package/dist/constants/assets.js +0 -176
- package/dist/constants/general.d.ts +0 -67
- package/dist/constants/general.js +0 -75
- package/dist/constants/pools.d.ts +0 -13
- package/dist/constants/pools.js +0 -120
- package/dist/contracts/MasterContract.d.ts +0 -156
- package/dist/contracts/MasterContract.js +0 -260
- package/dist/prices/Oracle.interface.d.ts +0 -9
- package/dist/prices/Oracle.interface.js +0 -2
- package/dist/prices/Prices.d.ts +0 -11
- package/dist/prices/Prices.js +0 -53
- package/dist/prices/PricesCollector.d.ts +0 -22
- package/dist/prices/PricesCollector.js +0 -146
- package/dist/prices/PythCollector.d.ts +0 -22
- package/dist/prices/PythCollector.js +0 -217
- package/src/prices/Oracle.interface.ts +0 -18
- package/src/prices/Prices.ts +0 -45
- package/src/prices/PricesCollector.ts +0 -169
- package/src/prices/PythCollector.ts +0 -294
- /package/dist/{prices → oracles}/Types.js +0 -0
- /package/dist/{prices → oracles}/constants.d.ts +0 -0
- /package/dist/{prices → oracles}/constants.js +0 -0
- /package/dist/{prices → oracles}/sources/Backend.d.ts +0 -0
- /package/dist/{prices → oracles}/sources/Icp.d.ts +0 -0
- /package/dist/{prices → oracles}/sources/PriceSource.d.ts +0 -0
- /package/dist/{prices → oracles}/sources/PriceSource.js +0 -0
- /package/dist/{prices → oracles}/sources/index.d.ts +0 -0
- /package/dist/{prices → oracles}/sources/index.js +0 -0
- /package/src/{prices → oracles}/constants.ts +0 -0
- /package/src/{prices → oracles}/sources/PriceSource.ts +0 -0
- /package/src/{prices → oracles}/sources/index.ts +0 -0
|
@@ -2,26 +2,29 @@
|
|
|
2
2
|
import { HexString } from '@pythnetwork/hermes-client';
|
|
3
3
|
import { Address, Cell, ContractProvider, Dictionary, Sender } from '@ton/core';
|
|
4
4
|
import { PythOracleInfo } from '../api/parsers/PythOracleParser';
|
|
5
|
+
import { PoolAssetConfig } from '../types/Master';
|
|
5
6
|
import { AbstractEvaaMaster, BaseMasterConfig, BaseMasterData, EvaaParameters, LiquidationInnerParameters, LiquidationOperationBuilderParameters, LiquidationParameters, SupplyWithdrawParameters, WithdrawParameters } from './AbstractMaster';
|
|
6
7
|
/**
|
|
7
8
|
* pyth specific parameters
|
|
8
9
|
*/
|
|
9
|
-
export
|
|
10
|
-
priceData: Buffer | Cell;
|
|
11
|
-
targetFeeds: HexString[];
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
export
|
|
15
|
-
pythAddress: Address;
|
|
16
|
-
minPublishTime: number | bigint;
|
|
17
|
-
maxPublishTime: number | bigint;
|
|
18
|
-
}
|
|
19
|
-
export
|
|
20
|
-
publishGap: number | bigint;
|
|
21
|
-
maxStaleness: number | bigint;
|
|
22
|
-
}
|
|
23
|
-
export
|
|
24
|
-
|
|
10
|
+
export interface PythBaseData {
|
|
11
|
+
readonly priceData: Buffer | Cell;
|
|
12
|
+
readonly targetFeeds: HexString[];
|
|
13
|
+
readonly refAssets: PoolAssetConfig[];
|
|
14
|
+
}
|
|
15
|
+
export interface ProxySpecificPythParams {
|
|
16
|
+
readonly pythAddress: Address;
|
|
17
|
+
readonly minPublishTime: number | bigint;
|
|
18
|
+
readonly maxPublishTime: number | bigint;
|
|
19
|
+
}
|
|
20
|
+
export interface OnchainSpecificPythParams {
|
|
21
|
+
readonly publishGap: number | bigint;
|
|
22
|
+
readonly maxStaleness: number | bigint;
|
|
23
|
+
}
|
|
24
|
+
export interface JettonPythParams extends PythBaseData, OnchainSpecificPythParams {
|
|
25
|
+
}
|
|
26
|
+
export interface TonPythParams extends PythBaseData, ProxySpecificPythParams {
|
|
27
|
+
}
|
|
25
28
|
export type PythProxyParams = {
|
|
26
29
|
pyth: PythBaseData & (ProxySpecificPythParams | OnchainSpecificPythParams) & {
|
|
27
30
|
pythAddress: Address;
|
|
@@ -29,16 +32,16 @@ export type PythProxyParams = {
|
|
|
29
32
|
};
|
|
30
33
|
export type PythSupplyWithdrawParameters = SupplyWithdrawParameters & Partial<PythProxyParams>;
|
|
31
34
|
export type PythWithdrawParameters = WithdrawParameters & {
|
|
32
|
-
pyth
|
|
35
|
+
pyth?: TonPythParams;
|
|
33
36
|
};
|
|
34
37
|
export type PythLiquidationOperationParameters = LiquidationOperationBuilderParameters & LiquidationInnerParameters & PythProxyParams;
|
|
35
38
|
export type PythLiquidationParameters = LiquidationParameters & PythLiquidationOperationParameters;
|
|
36
|
-
export
|
|
37
|
-
oraclesInfo: PythOracleInfo;
|
|
38
|
-
}
|
|
39
|
-
export
|
|
40
|
-
masterConfig: PythMasterConfig;
|
|
41
|
-
}
|
|
39
|
+
export interface PythMasterConfig extends BaseMasterConfig {
|
|
40
|
+
readonly oraclesInfo: PythOracleInfo;
|
|
41
|
+
}
|
|
42
|
+
export interface PythMasterData extends BaseMasterData {
|
|
43
|
+
readonly masterConfig: PythMasterConfig;
|
|
44
|
+
}
|
|
42
45
|
export declare class EvaaMasterPyth extends AbstractEvaaMaster<PythMasterData> {
|
|
43
46
|
constructor(parameters: EvaaParameters);
|
|
44
47
|
protected buildPythMasterMessage(args: {
|
|
@@ -50,8 +53,21 @@ export declare class EvaaMasterPyth extends AbstractEvaaMaster<PythMasterData> {
|
|
|
50
53
|
maxStaleness: number | bigint;
|
|
51
54
|
}, operationPayload: Cell): Cell;
|
|
52
55
|
protected buildPythProxyMessage(targetAddress: Address, priceUpdateData: Cell, targetPythFeeds: Cell, minPublishTime: number | bigint, maxPublishTime: number | bigint, operationPayload: Cell): Cell;
|
|
56
|
+
/**
|
|
57
|
+
* Creates a wrapped operation payload for TON assets
|
|
58
|
+
*/
|
|
59
|
+
private createWrappedOperationPayload;
|
|
60
|
+
/**
|
|
61
|
+
* Creates a jetton transfer message with pyth data
|
|
62
|
+
*/
|
|
63
|
+
private createJettonPythMessage;
|
|
64
|
+
/**
|
|
65
|
+
* Creates a TON pyth proxy message
|
|
66
|
+
*/
|
|
67
|
+
private createTonPythMessage;
|
|
68
|
+
protected createSupplyWithdrawMessageNoPrices(parameters: SupplyWithdrawParameters, operationPayload: Cell): Cell;
|
|
53
69
|
createSupplyWithdrawMessage(parameters: PythSupplyWithdrawParameters): Cell;
|
|
54
|
-
buildRefTokensDict(
|
|
70
|
+
buildRefTokensDict(refAssets: PoolAssetConfig[]): Dictionary<bigint, Buffer>;
|
|
55
71
|
buildGeneralDataPayload(parameters: PythSupplyWithdrawParameters): Cell;
|
|
56
72
|
sendWithdraw(provider: ContractProvider, via: Sender, value: bigint, parameters: PythWithdrawParameters): Promise<void>;
|
|
57
73
|
protected buildLiquidationOperationPayload(parameters: PythLiquidationOperationParameters): Cell;
|
|
@@ -36,73 +36,74 @@ class EvaaMasterPyth extends AbstractMaster_1.AbstractEvaaMaster {
|
|
|
36
36
|
.storeRef(operationPayload)
|
|
37
37
|
.endCell();
|
|
38
38
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Creates a wrapped operation payload for TON assets
|
|
41
|
+
*/
|
|
42
|
+
createWrappedOperationPayload(opCode, queryID, operationPayload) {
|
|
43
|
+
return (0, core_1.beginCell)().storeUint(opCode, 32).storeUint(queryID, 64).storeRef(operationPayload).endCell();
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Creates a jetton transfer message with pyth data
|
|
47
|
+
*/
|
|
48
|
+
createJettonPythMessage(parameters, operationPayload, pythParams, opCode) {
|
|
49
|
+
const { priceData, targetFeeds, publishGap, maxStaleness } = pythParams;
|
|
50
|
+
const masterMessage = this.buildPythMasterMessage({
|
|
51
|
+
queryId: parameters.queryID,
|
|
52
|
+
opCode,
|
|
53
|
+
updateDataCell: (0, prices_1.packPythUpdatesData)(priceData),
|
|
54
|
+
targetFeedsCell: (0, prices_1.composeFeedsCell)(targetFeeds),
|
|
55
|
+
publishGap,
|
|
56
|
+
maxStaleness,
|
|
57
|
+
}, operationPayload);
|
|
58
|
+
return this.createJettonTransferMessage(parameters, general_1.FEES.SUPPLY_WITHDRAW, masterMessage);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Creates a TON pyth proxy message
|
|
62
|
+
*/
|
|
63
|
+
createTonPythMessage(parameters, operationPayload, pythParams, opCode) {
|
|
64
|
+
const { priceData, targetFeeds, minPublishTime, maxPublishTime } = pythParams;
|
|
65
|
+
const wrappedOperationPayload = this.createWrappedOperationPayload(opCode, parameters.queryID, operationPayload);
|
|
66
|
+
return this.buildPythProxyMessage(this.address, (0, prices_1.packPythUpdatesData)(priceData), (0, prices_1.composeFeedsCell)(targetFeeds), minPublishTime, maxPublishTime, wrappedOperationPayload);
|
|
67
|
+
}
|
|
68
|
+
createSupplyWithdrawMessageNoPrices(parameters, operationPayload) {
|
|
69
|
+
const messageBody = (0, core_1.beginCell)()
|
|
70
|
+
.storeUint(general_1.OPCODES.SUPPLY_WITHDRAW_MASTER_WITHOUT_PRICES, 32)
|
|
71
|
+
.storeSlice(operationPayload.beginParse())
|
|
72
|
+
.endCell();
|
|
42
73
|
if (!(0, utils_1.isTonAsset)(parameters.supplyAsset)) {
|
|
43
|
-
|
|
44
|
-
const masterMessage = this.buildPythMasterMessage({
|
|
45
|
-
queryId: parameters.queryID,
|
|
46
|
-
opCode: general_1.OPCODES.SUPPLY_WITHDRAW_MASTER_JETTON,
|
|
47
|
-
updateDataCell: (0, prices_1.packPythUpdatesData)(priceData),
|
|
48
|
-
targetFeedsCell: (0, prices_1.composeFeedsCell)(targetFeeds),
|
|
49
|
-
publishGap,
|
|
50
|
-
maxStaleness,
|
|
51
|
-
}, operationPayload);
|
|
52
|
-
return this.createJettonTransferMessage(parameters, general_1.FEES.SUPPLY_WITHDRAW, masterMessage);
|
|
74
|
+
return this.createJettonTransferMessage(parameters, general_1.FEES.SUPPLY_WITHDRAW + general_1.FEES.JETTON_FWD, messageBody);
|
|
53
75
|
}
|
|
54
76
|
else {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
.storeUint(general_1.OPCODES.SUPPLY_WITHDRAW_MASTER, 32)
|
|
77
|
+
return (0, core_1.beginCell)()
|
|
78
|
+
.storeUint(general_1.OPCODES.SUPPLY_WITHDRAW_MASTER_WITHOUT_PRICES, 32)
|
|
58
79
|
.storeUint(parameters.queryID, 64)
|
|
59
|
-
.
|
|
80
|
+
.storeSlice(operationPayload.beginParse())
|
|
60
81
|
.endCell();
|
|
61
|
-
return this.buildPythProxyMessage(this.address, (0, prices_1.packPythUpdatesData)(priceData), (0, prices_1.composeFeedsCell)(targetFeeds), minPublishTime, maxPublishTime, wrappedOperationPayload);
|
|
62
82
|
}
|
|
63
83
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
// .storeAddress(parameters.userAddress)
|
|
80
|
-
// .storeInt(parameters.includeUserCode ? -1 : 0, 2)
|
|
81
|
-
// .storeUint(parameters.amountToTransfer, 64)
|
|
82
|
-
// .storeRef(parameters.payload)
|
|
83
|
-
// .storeSlice(extraTail.beginParse())
|
|
84
|
-
// .endCell(),
|
|
85
|
-
// )
|
|
86
|
-
// .endCell();
|
|
87
|
-
// const { priceData, targetFeeds, minPublishTime, maxPublishTime } = parameters.pyth as TonPythParams;
|
|
88
|
-
// return makePythProxyMessage(
|
|
89
|
-
// this.address,
|
|
90
|
-
// packPythUpdatesData(priceData),
|
|
91
|
-
// composeFeedsCell(targetFeeds),
|
|
92
|
-
// minPublishTime,
|
|
93
|
-
// maxPublishTime,
|
|
94
|
-
// wrappedOperationPayload,
|
|
95
|
-
// );
|
|
96
|
-
// }
|
|
97
|
-
buildRefTokensDict(requestedRefTokens) {
|
|
84
|
+
createSupplyWithdrawMessage(parameters) {
|
|
85
|
+
const operationPayload = this.buildSupplyWithdrawOperationPayload(parameters);
|
|
86
|
+
// Handle case without pyth data
|
|
87
|
+
if (!parameters.pyth) {
|
|
88
|
+
return this.createSupplyWithdrawMessageNoPrices(parameters, operationPayload);
|
|
89
|
+
}
|
|
90
|
+
if (!(0, utils_1.isTonAsset)(parameters.supplyAsset)) {
|
|
91
|
+
return this.createJettonPythMessage(parameters, // as JettonParams & { queryID: number | bigint },
|
|
92
|
+
operationPayload, parameters.pyth, general_1.OPCODES.SUPPLY_WITHDRAW_MASTER_JETTON);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
return this.createTonPythMessage(parameters, operationPayload, parameters.pyth, general_1.OPCODES.SUPPLY_WITHDRAW_MASTER);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
buildRefTokensDict(refAssets) {
|
|
98
99
|
const refsDict = core_1.Dictionary.empty(core_1.Dictionary.Keys.BigUint(256), core_1.Dictionary.Values.Buffer(0));
|
|
99
|
-
for (const
|
|
100
|
-
refsDict.set(
|
|
100
|
+
for (const refAsset of refAssets) {
|
|
101
|
+
refsDict.set(refAsset.assetId, Buffer.alloc(0));
|
|
101
102
|
}
|
|
102
103
|
return refsDict;
|
|
103
104
|
}
|
|
104
105
|
buildGeneralDataPayload(parameters) {
|
|
105
|
-
const refTokensDict = this.buildRefTokensDict(parameters.pyth?.
|
|
106
|
+
const refTokensDict = this.buildRefTokensDict(parameters.pyth?.refAssets ?? []);
|
|
106
107
|
return (0, core_1.beginCell)()
|
|
107
108
|
.storeInt(parameters.includeUserCode ? -1 : 0, 2)
|
|
108
109
|
.storeDict(refTokensDict, core_1.Dictionary.Keys.BigUint(256), core_1.Dictionary.Values.Buffer(0))
|
|
@@ -132,7 +133,7 @@ class EvaaMasterPyth extends AbstractMaster_1.AbstractEvaaMaster {
|
|
|
132
133
|
});
|
|
133
134
|
await via.send({
|
|
134
135
|
value,
|
|
135
|
-
to: parameters.pyth.
|
|
136
|
+
to: parameters.pyth?.pythAddress ?? this.address,
|
|
136
137
|
sendMode: core_1.SendMode.PAY_GAS_SEPARATELY + core_1.SendMode.IGNORE_ERRORS,
|
|
137
138
|
body: message,
|
|
138
139
|
});
|
|
@@ -140,32 +141,16 @@ class EvaaMasterPyth extends AbstractMaster_1.AbstractEvaaMaster {
|
|
|
140
141
|
buildLiquidationOperationPayload(parameters) {
|
|
141
142
|
const operationPayloadBuilder = this.buildLiquidationOperationPayloadBuilder(parameters);
|
|
142
143
|
const innerBuilder = this.buildLiquidationInnerBuilder(parameters);
|
|
143
|
-
const refTokensDict = this.buildRefTokensDict(parameters.pyth.
|
|
144
|
+
const refTokensDict = this.buildRefTokensDict(parameters.pyth.refAssets);
|
|
144
145
|
return operationPayloadBuilder.storeDict(refTokensDict).storeRef(innerBuilder).endCell();
|
|
145
146
|
}
|
|
146
147
|
createLiquidationMessage(parameters) {
|
|
147
|
-
const isTon = (0, utils_1.isTonAsset)(parameters.asset);
|
|
148
148
|
const operationPayload = this.buildLiquidationOperationPayload(parameters);
|
|
149
|
-
if (!
|
|
150
|
-
|
|
151
|
-
const masterMessage = this.buildPythMasterMessage({
|
|
152
|
-
queryId: parameters.queryID,
|
|
153
|
-
opCode: general_1.OPCODES.LIQUIDATE_MASTER,
|
|
154
|
-
updateDataCell: (0, prices_1.packPythUpdatesData)(priceData),
|
|
155
|
-
targetFeedsCell: (0, prices_1.composeFeedsCell)(targetFeeds),
|
|
156
|
-
publishGap,
|
|
157
|
-
maxStaleness,
|
|
158
|
-
}, operationPayload);
|
|
159
|
-
return this.createJettonTransferMessage(parameters, general_1.FEES.LIQUIDATION_JETTON_FWD, masterMessage);
|
|
149
|
+
if (!(0, utils_1.isTonAsset)(parameters.asset)) {
|
|
150
|
+
return this.createJettonPythMessage(parameters, operationPayload, parameters.pyth, general_1.OPCODES.LIQUIDATE_MASTER);
|
|
160
151
|
}
|
|
161
152
|
else {
|
|
162
|
-
|
|
163
|
-
const wrappedOperationPayload = (0, core_1.beginCell)()
|
|
164
|
-
.storeUint(general_1.OPCODES.LIQUIDATE_MASTER, 32)
|
|
165
|
-
.storeUint(parameters.queryID, 64)
|
|
166
|
-
.storeRef(operationPayload)
|
|
167
|
-
.endCell();
|
|
168
|
-
return this.buildPythProxyMessage(this.address, (0, prices_1.packPythUpdatesData)(priceData), (0, prices_1.composeFeedsCell)(targetFeeds), minPublishTime, maxPublishTime, wrappedOperationPayload);
|
|
153
|
+
return this.createTonPythMessage(parameters, operationPayload, parameters.pyth, general_1.OPCODES.LIQUIDATE_MASTER);
|
|
169
154
|
}
|
|
170
155
|
}
|
|
171
156
|
async sendLiquidation(provider, via, value, parameters) {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Address, Cell, Contract, ContractProvider } from '@ton/core';
|
|
3
|
+
export declare class PythOracle implements Contract {
|
|
4
|
+
readonly address: Address;
|
|
5
|
+
readonly init?: {
|
|
6
|
+
code: Cell;
|
|
7
|
+
data: Cell;
|
|
8
|
+
} | undefined;
|
|
9
|
+
constructor(address: Address, init?: {
|
|
10
|
+
code: Cell;
|
|
11
|
+
data: Cell;
|
|
12
|
+
} | undefined);
|
|
13
|
+
static createFromAddress(address: Address): PythOracle;
|
|
14
|
+
getUpdateFee(provider: ContractProvider, vm: Buffer): Promise<bigint>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PythOracle = void 0;
|
|
4
|
+
const pyth_ton_js_1 = require("@pythnetwork/pyth-ton-js");
|
|
5
|
+
class PythOracle {
|
|
6
|
+
constructor(address, init) {
|
|
7
|
+
this.address = address;
|
|
8
|
+
this.init = init;
|
|
9
|
+
}
|
|
10
|
+
static createFromAddress(address) {
|
|
11
|
+
return new this(address);
|
|
12
|
+
}
|
|
13
|
+
async getUpdateFee(provider, vm) {
|
|
14
|
+
const result = await provider.get('get_update_fee', [{ type: 'slice', cell: (0, pyth_ton_js_1.createCellChain)(vm) }]);
|
|
15
|
+
const numUpdates = result.stack.readNumber();
|
|
16
|
+
return (0, pyth_ton_js_1.calculateUpdatePriceFeedsFee)(BigInt(numUpdates)) + BigInt(numUpdates);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.PythOracle = PythOracle;
|
package/dist/contracts/index.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export * from './types/User';
|
|
|
17
17
|
export * from './constants/general';
|
|
18
18
|
export * from './constants/pools';
|
|
19
19
|
export * from './constants/assets';
|
|
20
|
-
export * from './
|
|
20
|
+
export * from './oracles';
|
|
21
21
|
export * from './utils/utils';
|
|
22
22
|
export { getLastSentBoc, getTonConnectSender } from './utils/tonConnectSender';
|
|
23
23
|
export { getUserJettonWallet } from './utils/userJettonWallet';
|
package/dist/index.js
CHANGED
|
@@ -46,7 +46,7 @@ __exportStar(require("./types/User"), exports);
|
|
|
46
46
|
__exportStar(require("./constants/general"), exports);
|
|
47
47
|
__exportStar(require("./constants/pools"), exports);
|
|
48
48
|
__exportStar(require("./constants/assets"), exports);
|
|
49
|
-
__exportStar(require("./
|
|
49
|
+
__exportStar(require("./oracles"), exports);
|
|
50
50
|
__exportStar(require("./utils/utils"), exports);
|
|
51
51
|
// Utils
|
|
52
52
|
var tonConnectSender_1 = require("./utils/tonConnectSender");
|
|
@@ -37,10 +37,6 @@ export type PythFeedUpdateType = {
|
|
|
37
37
|
parsed: PriceUpdate['parsed'];
|
|
38
38
|
binary: Buffer;
|
|
39
39
|
};
|
|
40
|
-
export type PriceData = {
|
|
41
|
-
dict: Dictionary<bigint, bigint>;
|
|
42
|
-
dataCell: Cell;
|
|
43
|
-
};
|
|
44
40
|
export type OraclePricesData = {
|
|
45
41
|
timestamp: number;
|
|
46
42
|
prices: Dictionary<bigint, bigint>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Dictionary } from '@ton/core';
|
|
2
|
+
import { PoolAssetConfig } from '../../types/Master';
|
|
3
|
+
import { FetchConfig } from '../../utils/utils';
|
|
4
|
+
import { ClassicPrices } from '../prices/ClassicPrices';
|
|
5
|
+
import { PythPrices } from '../prices/PythPrices';
|
|
6
|
+
export declare abstract class AbstractCollector {
|
|
7
|
+
abstract getPricesForLiquidate(realPrincipals: Dictionary<bigint, bigint>, fetchConfig?: FetchConfig): Promise<ClassicPrices | PythPrices>;
|
|
8
|
+
abstract getPricesForSupplyWithdraw(realPrincipals: Dictionary<bigint, bigint>, supplyAsset: PoolAssetConfig | undefined, withdrawAsset: PoolAssetConfig | undefined, collateralToDebt: boolean, fetchConfig?: FetchConfig): Promise<ClassicPrices | PythPrices>;
|
|
9
|
+
abstract getPrices(assets: PoolAssetConfig[], fetchConfig?: FetchConfig): Promise<ClassicPrices | PythPrices>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Dictionary } from '@ton/core';
|
|
2
|
+
import { ExtendedEvaaOracle, PoolAssetConfig } from '../../types/Master';
|
|
3
|
+
import { FetchConfig } from '../../utils/utils';
|
|
4
|
+
import { ClassicPrices } from '../prices/ClassicPrices';
|
|
5
|
+
import { PriceSource } from '../sources';
|
|
6
|
+
import { PriceSourcesConfig } from '../Types';
|
|
7
|
+
import { AbstractCollector } from './AbstractCollector';
|
|
8
|
+
export type ClassicCollectorConfig = {
|
|
9
|
+
poolAssetsConfig: PoolAssetConfig[];
|
|
10
|
+
minimalOracles: number;
|
|
11
|
+
evaaOracles: ExtendedEvaaOracle[];
|
|
12
|
+
sourcesConfig?: PriceSourcesConfig;
|
|
13
|
+
additionalPriceSources?: PriceSource[];
|
|
14
|
+
};
|
|
15
|
+
export declare class ClassicCollector extends AbstractCollector {
|
|
16
|
+
#private;
|
|
17
|
+
constructor(config: ClassicCollectorConfig);
|
|
18
|
+
getPricesForLiquidate(realPrincipals: Dictionary<bigint, bigint>, fetchConfig?: FetchConfig): Promise<ClassicPrices>;
|
|
19
|
+
getPricesForWithdraw(realPrincipals: Dictionary<bigint, bigint>, withdrawAsset: PoolAssetConfig, collateralToDebt?: boolean, fetchConfig?: FetchConfig): Promise<ClassicPrices>;
|
|
20
|
+
getPricesForSupplyWithdraw(realPrincipals: Dictionary<bigint, bigint>, supplyAsset: PoolAssetConfig | undefined, withdrawAsset: PoolAssetConfig | undefined, collateralToDebt: boolean, fetchConfig?: FetchConfig): Promise<ClassicPrices>;
|
|
21
|
+
getPrices(assets?: PoolAssetConfig[], fetchConfig?: FetchConfig): Promise<ClassicPrices>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _ClassicCollector_instances, _ClassicCollector_prices, _ClassicCollector_poolAssetsConfig, _ClassicCollector_sourcesConfig, _ClassicCollector_priceSources, _ClassicCollector_minimalOracles, _ClassicCollector_getPricesByAssetList, _ClassicCollector_collectPrices, _ClassicCollector_collectPricesWithValidation, _ClassicCollector_filterPrices, _ClassicCollector_filterEmptyPrincipalsAndAssets, _ClassicCollector_convertToTwapAssets, _ClassicCollector_convertToSpotAssets, _ClassicCollector_getPricesWithMode;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.ClassicCollector = void 0;
|
|
16
|
+
const core_1 = require("@ton/core");
|
|
17
|
+
const math_1 = require("../../api/math");
|
|
18
|
+
const utils_1 = require("../../utils/utils");
|
|
19
|
+
const ClassicPrices_1 = require("../prices/ClassicPrices");
|
|
20
|
+
const Types_1 = require("../Types");
|
|
21
|
+
const utils_2 = require("../utils");
|
|
22
|
+
const AbstractCollector_1 = require("./AbstractCollector");
|
|
23
|
+
class ClassicCollector extends AbstractCollector_1.AbstractCollector {
|
|
24
|
+
constructor(config) {
|
|
25
|
+
super();
|
|
26
|
+
_ClassicCollector_instances.add(this);
|
|
27
|
+
_ClassicCollector_prices.set(this, void 0);
|
|
28
|
+
_ClassicCollector_poolAssetsConfig.set(this, void 0);
|
|
29
|
+
_ClassicCollector_sourcesConfig.set(this, void 0);
|
|
30
|
+
_ClassicCollector_priceSources.set(this, void 0);
|
|
31
|
+
_ClassicCollector_minimalOracles.set(this, void 0);
|
|
32
|
+
__classPrivateFieldSet(this, _ClassicCollector_poolAssetsConfig, config.poolAssetsConfig, "f");
|
|
33
|
+
__classPrivateFieldSet(this, _ClassicCollector_sourcesConfig, config.sourcesConfig ?? Types_1.DefaultPriceSourcesConfig, "f");
|
|
34
|
+
__classPrivateFieldSet(this, _ClassicCollector_priceSources, (0, utils_2.generatePriceSources)(__classPrivateFieldGet(this, _ClassicCollector_sourcesConfig, "f"), config.evaaOracles), "f");
|
|
35
|
+
__classPrivateFieldSet(this, _ClassicCollector_minimalOracles, config.minimalOracles, "f");
|
|
36
|
+
if (config.additionalPriceSources) {
|
|
37
|
+
__classPrivateFieldGet(this, _ClassicCollector_priceSources, "f").push(...config.additionalPriceSources);
|
|
38
|
+
}
|
|
39
|
+
__classPrivateFieldSet(this, _ClassicCollector_prices, [], "f");
|
|
40
|
+
}
|
|
41
|
+
async getPricesForLiquidate(realPrincipals, fetchConfig) {
|
|
42
|
+
const assets = __classPrivateFieldGet(this, _ClassicCollector_instances, "m", _ClassicCollector_filterEmptyPrincipalsAndAssets).call(this, realPrincipals);
|
|
43
|
+
if (assets.includes(undefined)) {
|
|
44
|
+
throw new Error('User from another pool');
|
|
45
|
+
}
|
|
46
|
+
const validAssets = assets.map((x) => x);
|
|
47
|
+
const spotAssets = __classPrivateFieldGet(this, _ClassicCollector_instances, "m", _ClassicCollector_convertToSpotAssets).call(this, validAssets);
|
|
48
|
+
return await __classPrivateFieldGet(this, _ClassicCollector_instances, "m", _ClassicCollector_getPricesWithMode).call(this, spotAssets, ClassicPrices_1.ClassicPricesMode.SPOT, fetchConfig);
|
|
49
|
+
}
|
|
50
|
+
async getPricesForWithdraw(realPrincipals, withdrawAsset, collateralToDebt = false, fetchConfig) {
|
|
51
|
+
let assets = __classPrivateFieldGet(this, _ClassicCollector_instances, "m", _ClassicCollector_filterEmptyPrincipalsAndAssets).call(this, realPrincipals);
|
|
52
|
+
if ((0, math_1.checkNotInDebtAtAll)(realPrincipals) &&
|
|
53
|
+
(realPrincipals.get(withdrawAsset.assetId) ?? 0n) > 0n &&
|
|
54
|
+
!collateralToDebt) {
|
|
55
|
+
return ClassicPrices_1.ClassicPrices.createEmptyTwapPrices();
|
|
56
|
+
}
|
|
57
|
+
if (assets.includes(undefined)) {
|
|
58
|
+
throw new Error('User from another pool');
|
|
59
|
+
}
|
|
60
|
+
if (!assets.includes(withdrawAsset)) {
|
|
61
|
+
assets.push(withdrawAsset);
|
|
62
|
+
}
|
|
63
|
+
if (collateralToDebt && assets.length == 1) {
|
|
64
|
+
throw new Error('Cannot debt only one supplied asset');
|
|
65
|
+
}
|
|
66
|
+
return await this.getPrices(assets.map((x) => x), fetchConfig);
|
|
67
|
+
}
|
|
68
|
+
async getPricesForSupplyWithdraw(realPrincipals, supplyAsset, withdrawAsset, collateralToDebt, fetchConfig) {
|
|
69
|
+
let assets = __classPrivateFieldGet(this, _ClassicCollector_instances, "m", _ClassicCollector_filterEmptyPrincipalsAndAssets).call(this, realPrincipals);
|
|
70
|
+
if ((0, math_1.checkNotInDebtAtAll)(realPrincipals) &&
|
|
71
|
+
withdrawAsset &&
|
|
72
|
+
(realPrincipals.get(withdrawAsset.assetId) ?? 0n) > 0n &&
|
|
73
|
+
!collateralToDebt) {
|
|
74
|
+
return ClassicPrices_1.ClassicPrices.createEmptyTwapPrices();
|
|
75
|
+
}
|
|
76
|
+
if (assets.includes(undefined)) {
|
|
77
|
+
throw new Error('User from another pool');
|
|
78
|
+
}
|
|
79
|
+
if (withdrawAsset && !assets.includes(withdrawAsset)) {
|
|
80
|
+
assets.push(withdrawAsset);
|
|
81
|
+
}
|
|
82
|
+
if (collateralToDebt && assets.length == 1) {
|
|
83
|
+
throw new Error('Cannot debt only one supplied asset');
|
|
84
|
+
}
|
|
85
|
+
const validAssets = assets.map((x) => x);
|
|
86
|
+
const twapAssets = __classPrivateFieldGet(this, _ClassicCollector_instances, "m", _ClassicCollector_convertToTwapAssets).call(this, validAssets);
|
|
87
|
+
return await __classPrivateFieldGet(this, _ClassicCollector_instances, "m", _ClassicCollector_getPricesWithMode).call(this, twapAssets, ClassicPrices_1.ClassicPricesMode.TWAP, fetchConfig);
|
|
88
|
+
}
|
|
89
|
+
async getPrices(assets = __classPrivateFieldGet(this, _ClassicCollector_poolAssetsConfig, "f"), fetchConfig) {
|
|
90
|
+
if (assets.length == 0) {
|
|
91
|
+
return ClassicPrices_1.ClassicPrices.createEmptyPrices();
|
|
92
|
+
}
|
|
93
|
+
await __classPrivateFieldGet(this, _ClassicCollector_instances, "m", _ClassicCollector_collectPricesWithValidation).call(this, fetchConfig);
|
|
94
|
+
if (__classPrivateFieldGet(this, _ClassicCollector_prices, "f").length < __classPrivateFieldGet(this, _ClassicCollector_minimalOracles, "f")) {
|
|
95
|
+
throw new Error(`Error per updating prices, valid ${__classPrivateFieldGet(this, _ClassicCollector_prices, "f").length} of ${__classPrivateFieldGet(this, _ClassicCollector_minimalOracles, "f")}`);
|
|
96
|
+
}
|
|
97
|
+
const prices = __classPrivateFieldGet(this, _ClassicCollector_instances, "m", _ClassicCollector_getPricesByAssetList).call(this, assets);
|
|
98
|
+
return new ClassicPrices_1.ClassicPrices({
|
|
99
|
+
dict: prices.dict,
|
|
100
|
+
dataCell: prices.dataCell,
|
|
101
|
+
minPublishTime: undefined,
|
|
102
|
+
maxPublishTime: undefined,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
exports.ClassicCollector = ClassicCollector;
|
|
107
|
+
_ClassicCollector_prices = new WeakMap(), _ClassicCollector_poolAssetsConfig = new WeakMap(), _ClassicCollector_sourcesConfig = new WeakMap(), _ClassicCollector_priceSources = new WeakMap(), _ClassicCollector_minimalOracles = new WeakMap(), _ClassicCollector_instances = new WeakSet(), _ClassicCollector_getPricesByAssetList = function _ClassicCollector_getPricesByAssetList(assets) {
|
|
108
|
+
let pricesFiltered = __classPrivateFieldGet(this, _ClassicCollector_prices, "f");
|
|
109
|
+
if (pricesFiltered.length < __classPrivateFieldGet(this, _ClassicCollector_minimalOracles, "f")) {
|
|
110
|
+
throw new Error('Not enough price data');
|
|
111
|
+
}
|
|
112
|
+
if (pricesFiltered.length > __classPrivateFieldGet(this, _ClassicCollector_minimalOracles, "f")) {
|
|
113
|
+
const sortedByTimestamp = pricesFiltered.slice().sort((a, b) => b.timestamp - a.timestamp);
|
|
114
|
+
const newerPrices = sortedByTimestamp.slice(0, __classPrivateFieldGet(this, _ClassicCollector_minimalOracles, "f"));
|
|
115
|
+
pricesFiltered = newerPrices.sort((a, b) => a.oracleId - b.oracleId);
|
|
116
|
+
}
|
|
117
|
+
const medianData = assets.map((asset) => ({
|
|
118
|
+
assetId: asset.assetId,
|
|
119
|
+
medianPrice: (0, utils_2.getMedianPrice)(pricesFiltered, asset.assetId),
|
|
120
|
+
}));
|
|
121
|
+
const nonEmptymedianData = medianData.filter((x) => x.medianPrice != null);
|
|
122
|
+
const packedMedianData = (0, utils_2.packAssetsData)(nonEmptymedianData);
|
|
123
|
+
const oraclesData = pricesFiltered.map((x) => ({
|
|
124
|
+
oracle: { id: x.oracleId, pubkey: x.pubkey },
|
|
125
|
+
data: { timestamp: x.timestamp, prices: x.dict },
|
|
126
|
+
signature: x.signature,
|
|
127
|
+
}));
|
|
128
|
+
const packedOracleData = (0, utils_2.packOraclesData)(oraclesData, nonEmptymedianData.map((x) => x.assetId));
|
|
129
|
+
const dict = core_1.Dictionary.empty();
|
|
130
|
+
for (const medianDataAsset of nonEmptymedianData) {
|
|
131
|
+
dict.set(medianDataAsset.assetId, medianDataAsset.medianPrice);
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
dict: dict,
|
|
135
|
+
dataCell: (0, utils_2.packPrices)(packedMedianData, packedOracleData),
|
|
136
|
+
};
|
|
137
|
+
}, _ClassicCollector_collectPrices = async function _ClassicCollector_collectPrices(fetchConfig) {
|
|
138
|
+
for (const priceSource of __classPrivateFieldGet(this, _ClassicCollector_priceSources, "f")) {
|
|
139
|
+
try {
|
|
140
|
+
__classPrivateFieldSet(this, _ClassicCollector_prices, await (0, utils_1.proxyFetchRetries)(() => (0, utils_2.collectAndFilterPrices)(priceSource, __classPrivateFieldGet(this, _ClassicCollector_minimalOracles, "f"), fetchConfig), fetchConfig), "f");
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
// Try next source
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return false;
|
|
149
|
+
}, _ClassicCollector_collectPricesWithValidation = async function _ClassicCollector_collectPricesWithValidation(fetchConfig) {
|
|
150
|
+
if (!__classPrivateFieldGet(this, _ClassicCollector_prices, "f") || __classPrivateFieldGet(this, _ClassicCollector_instances, "m", _ClassicCollector_filterPrices).call(this) < __classPrivateFieldGet(this, _ClassicCollector_minimalOracles, "f")) {
|
|
151
|
+
const success = await __classPrivateFieldGet(this, _ClassicCollector_instances, "m", _ClassicCollector_collectPrices).call(this, fetchConfig);
|
|
152
|
+
if (!success || __classPrivateFieldGet(this, _ClassicCollector_prices, "f").length < __classPrivateFieldGet(this, _ClassicCollector_minimalOracles, "f")) {
|
|
153
|
+
throw new Error(`Failed to collect sufficient prices: ${__classPrivateFieldGet(this, _ClassicCollector_prices, "f")?.length || 0} of ${__classPrivateFieldGet(this, _ClassicCollector_minimalOracles, "f")}`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}, _ClassicCollector_filterPrices = function _ClassicCollector_filterPrices() {
|
|
157
|
+
__classPrivateFieldSet(this, _ClassicCollector_prices, __classPrivateFieldGet(this, _ClassicCollector_prices, "f").filter((0, utils_2.verifyPricesTimestamp)()), "f");
|
|
158
|
+
return __classPrivateFieldGet(this, _ClassicCollector_prices, "f").length;
|
|
159
|
+
}, _ClassicCollector_filterEmptyPrincipalsAndAssets = function _ClassicCollector_filterEmptyPrincipalsAndAssets(principals) {
|
|
160
|
+
return principals
|
|
161
|
+
.keys()
|
|
162
|
+
.filter((x) => principals.get(x) != 0n)
|
|
163
|
+
.map((x) => __classPrivateFieldGet(this, _ClassicCollector_poolAssetsConfig, "f").find((asset) => asset.assetId == x));
|
|
164
|
+
}, _ClassicCollector_convertToTwapAssets = function _ClassicCollector_convertToTwapAssets(assets) {
|
|
165
|
+
return assets.map((asset) => ({
|
|
166
|
+
...asset,
|
|
167
|
+
assetId: asset.assetId - ClassicPrices_1.ClassicPricesOffset[ClassicPrices_1.ClassicPricesMode.TWAP],
|
|
168
|
+
}));
|
|
169
|
+
}, _ClassicCollector_convertToSpotAssets = function _ClassicCollector_convertToSpotAssets(assets) {
|
|
170
|
+
return assets.map((asset) => ({
|
|
171
|
+
...asset,
|
|
172
|
+
assetId: asset.assetId - ClassicPrices_1.ClassicPricesOffset[ClassicPrices_1.ClassicPricesMode.SPOT],
|
|
173
|
+
}));
|
|
174
|
+
}, _ClassicCollector_getPricesWithMode = async function _ClassicCollector_getPricesWithMode(assets, mode, fetchConfig) {
|
|
175
|
+
if (assets.length == 0) {
|
|
176
|
+
return ClassicPrices_1.ClassicPricesMode.TWAP
|
|
177
|
+
? ClassicPrices_1.ClassicPrices.createEmptyTwapPrices()
|
|
178
|
+
: ClassicPrices_1.ClassicPrices.createEmptySpotPrices();
|
|
179
|
+
}
|
|
180
|
+
await __classPrivateFieldGet(this, _ClassicCollector_instances, "m", _ClassicCollector_collectPricesWithValidation).call(this, fetchConfig);
|
|
181
|
+
if (__classPrivateFieldGet(this, _ClassicCollector_prices, "f").length < __classPrivateFieldGet(this, _ClassicCollector_minimalOracles, "f")) {
|
|
182
|
+
throw new Error(`Error per updating prices, valid ${__classPrivateFieldGet(this, _ClassicCollector_prices, "f").length} of ${__classPrivateFieldGet(this, _ClassicCollector_minimalOracles, "f")}`);
|
|
183
|
+
}
|
|
184
|
+
const prices = __classPrivateFieldGet(this, _ClassicCollector_instances, "m", _ClassicCollector_getPricesByAssetList).call(this, assets);
|
|
185
|
+
return new ClassicPrices_1.ClassicPrices({
|
|
186
|
+
mode,
|
|
187
|
+
dict: prices.dict,
|
|
188
|
+
dataCell: prices.dataCell,
|
|
189
|
+
minPublishTime: undefined,
|
|
190
|
+
maxPublishTime: undefined,
|
|
191
|
+
});
|
|
192
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { HexString } from '@pythnetwork/hermes-client';
|
|
2
|
+
import { Dictionary } from '@ton/core';
|
|
3
|
+
import { OracleConfig } from '../../api/parsers/PythOracleParser';
|
|
4
|
+
import { PoolAssetConfig } from '../../types/Master';
|
|
5
|
+
import { FetchConfig } from '../../utils/utils';
|
|
6
|
+
import { PythPrices } from '../prices/PythPrices';
|
|
7
|
+
import { PythPriceSourcesConfig } from '../Types';
|
|
8
|
+
import { AbstractCollector } from './AbstractCollector';
|
|
9
|
+
export type PythCollectorConfig = {
|
|
10
|
+
poolAssetsConfig: PoolAssetConfig[];
|
|
11
|
+
pythOracle: OracleConfig;
|
|
12
|
+
pythConfig: PythPriceSourcesConfig;
|
|
13
|
+
};
|
|
14
|
+
export declare class PythCollector extends AbstractCollector {
|
|
15
|
+
#private;
|
|
16
|
+
constructor(config: PythCollectorConfig);
|
|
17
|
+
getPricesForLiquidate(realPrincipals: Dictionary<bigint, bigint>, fetchConfig?: FetchConfig): Promise<PythPrices>;
|
|
18
|
+
getPricesForSupplyWithdraw(realPrincipals: Dictionary<bigint, bigint>, supplyAsset: PoolAssetConfig, withdrawAsset: PoolAssetConfig, collateralToDebt: boolean, fetchConfig?: FetchConfig): Promise<PythPrices>;
|
|
19
|
+
getPrices(assets?: PoolAssetConfig[], fetchConfig?: FetchConfig): Promise<PythPrices>;
|
|
20
|
+
getPricesForWithdraw(realPrincipals: Dictionary<bigint, bigint>, withdrawAsset: PoolAssetConfig, collateralToDebt?: boolean, fetchConfig?: FetchConfig): Promise<PythPrices>;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a list of required feed IDs for the given assets
|
|
23
|
+
* @param assets - Array of pool asset configurations
|
|
24
|
+
* @returns Array of unique feed IDs required for the assets
|
|
25
|
+
*/
|
|
26
|
+
createRequiredFeedsList(assets: PoolAssetConfig[]): HexString[];
|
|
27
|
+
}
|