@evaafi/sdk 0.9.0 → 0.9.2
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 +16 -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.d.ts +1 -0
- 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 +1 -0
- package/dist/constants/general/mainnet.js +2 -1
- 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 +41 -24
- package/dist/contracts/PythMaster.js +61 -76
- package/dist/contracts/PythOracle.d.ts +16 -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 +1 -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 +252 -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 +18 -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}/utils.d.ts +7 -1
- package/dist/{prices → oracles}/utils.js +10 -1
- package/dist/rewards/RewardMaster.d.ts +1 -0
- package/dist/rewards/RewardUser.d.ts +1 -0
- package/dist/types/Master.d.ts +5 -5
- package/dist/types/MasterRewards.d.ts +1 -0
- package/dist/types/UserRewards.d.ts +1 -0
- package/dist/utils/fivaUtils.d.ts +2 -0
- package/dist/utils/fivaUtils.js +19 -0
- package/dist/utils/sha256BigInt.d.ts +1 -0
- package/dist/utils/userJettonWallet.js +15 -1
- package/package.json +2 -3
- 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 +1 -0
- 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 +358 -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}/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/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/Backend.js +0 -0
- /package/dist/{prices → oracles}/sources/Icp.d.ts +0 -0
- /package/dist/{prices → oracles}/sources/Icp.js +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/Backend.ts +0 -0
- /package/src/{prices → oracles}/sources/Icp.ts +0 -0
- /package/src/{prices → oracles}/sources/PriceSource.ts +0 -0
- /package/src/{prices → oracles}/sources/index.ts +0 -0
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { Address, Cell, Contract, ContractProvider, OpenedContract, Sender } from '@ton/core';
|
|
2
|
-
import { Maybe } from '@ton/core/dist/utils/maybe';
|
|
3
|
-
import { EvaaUser } from './UserContract';
|
|
4
|
-
import { MasterData, PoolAssetConfig, PoolConfig } from '../types/Master';
|
|
5
|
-
import { PricesCollector, PriceSourcesConfig } from '..';
|
|
6
|
-
/**
|
|
7
|
-
* Parameters for the Evaa contract
|
|
8
|
-
* @property testnet - true for testnet, false for mainnet
|
|
9
|
-
* @property debug - true to enable debug mode (optional)
|
|
10
|
-
*/
|
|
11
|
-
export type EvaaParameters = {
|
|
12
|
-
poolConfig: PoolConfig;
|
|
13
|
-
debug?: boolean;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Base parameters for supply
|
|
17
|
-
* @property queryID - unique query ID
|
|
18
|
-
* @property includeUserCode - true to include user code for update (needed when user contract code version is outdated)
|
|
19
|
-
* @property amount - amount to supply
|
|
20
|
-
* @property userAddress - user address
|
|
21
|
-
* @property asset
|
|
22
|
-
*/
|
|
23
|
-
export type SupplyParameters = {
|
|
24
|
-
asset: PoolAssetConfig;
|
|
25
|
-
queryID: bigint;
|
|
26
|
-
includeUserCode: boolean;
|
|
27
|
-
amount: bigint;
|
|
28
|
-
userAddress: Address;
|
|
29
|
-
responseAddress?: Address;
|
|
30
|
-
forwardAmount?: bigint;
|
|
31
|
-
amountToTransfer: bigint;
|
|
32
|
-
payload: Cell;
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* Parameters for the withdraw message
|
|
36
|
-
* @property queryID - unique query ID
|
|
37
|
-
* * @property assetID - asset ID
|
|
38
|
-
* @property assetID - asset ID
|
|
39
|
-
* @property amount - amount to withdraw
|
|
40
|
-
* @property userAddress - user address
|
|
41
|
-
* @property includeUserCode - true to include user code for update (needed when user contract code version is outdated)
|
|
42
|
-
* @property priceData - price data cell. Can be obtained from the getPrices function
|
|
43
|
-
*/
|
|
44
|
-
export type WithdrawParameters = {
|
|
45
|
-
queryID: bigint;
|
|
46
|
-
amount: bigint;
|
|
47
|
-
userAddress: Address;
|
|
48
|
-
includeUserCode: boolean;
|
|
49
|
-
asset: PoolAssetConfig;
|
|
50
|
-
priceData: Cell;
|
|
51
|
-
amountToTransfer: bigint;
|
|
52
|
-
payload: Cell;
|
|
53
|
-
};
|
|
54
|
-
/**
|
|
55
|
-
* Base data for liquidation. Can be obtained from the user contract liquidationParameters getter
|
|
56
|
-
* @property borrowerAddress - borrower address (user address that is being liquidated)
|
|
57
|
-
* @property loanAsset - loan asset ID
|
|
58
|
-
* @property collateralAsset - collateral asset ID
|
|
59
|
-
* @property minCollateralAmount - minimal amount to receive from the liquidation
|
|
60
|
-
* @property liquidationAmount - amount to liquidate
|
|
61
|
-
* @property tonLiquidation - true if the loan asset is TON
|
|
62
|
-
*/
|
|
63
|
-
export type LiquidationBaseData = {
|
|
64
|
-
borrowerAddress: Address;
|
|
65
|
-
loanAsset: bigint;
|
|
66
|
-
collateralAsset: bigint;
|
|
67
|
-
minCollateralAmount: bigint;
|
|
68
|
-
liquidationAmount: bigint;
|
|
69
|
-
tonLiquidation: boolean;
|
|
70
|
-
forwardAmount?: bigint;
|
|
71
|
-
};
|
|
72
|
-
/**
|
|
73
|
-
* Base parameters for liquidation
|
|
74
|
-
* @property queryID - unique query ID
|
|
75
|
-
* @property liquidatorAddress - liquidator address, where and collateral will be sent
|
|
76
|
-
* @property includeUserCode - true to include user code for update (needed when user contract code version is outdated)
|
|
77
|
-
* @property priceData - price data cell. Can be obtained from the getPrices function
|
|
78
|
-
*/
|
|
79
|
-
export type LiquidationParameters = LiquidationBaseData & {
|
|
80
|
-
asset: PoolAssetConfig;
|
|
81
|
-
queryID: bigint;
|
|
82
|
-
liquidatorAddress: Address;
|
|
83
|
-
responseAddress: Address;
|
|
84
|
-
includeUserCode: boolean;
|
|
85
|
-
priceData: Cell;
|
|
86
|
-
payload: Cell;
|
|
87
|
-
payloadForwardAmount: bigint;
|
|
88
|
-
};
|
|
89
|
-
/**
|
|
90
|
-
* Evaa master contract wrapper
|
|
91
|
-
*/
|
|
92
|
-
export declare class Evaa implements Contract {
|
|
93
|
-
readonly address: Address;
|
|
94
|
-
private _poolConfig;
|
|
95
|
-
private readonly debug?;
|
|
96
|
-
private _data?;
|
|
97
|
-
private lastSync;
|
|
98
|
-
/**
|
|
99
|
-
* Create Evaa contract wrapper
|
|
100
|
-
* @param parameters Evaa contract parameters
|
|
101
|
-
*/
|
|
102
|
-
constructor(parameters?: EvaaParameters);
|
|
103
|
-
/**
|
|
104
|
-
* Returns pool config
|
|
105
|
-
*/
|
|
106
|
-
get poolConfig(): PoolConfig;
|
|
107
|
-
/**
|
|
108
|
-
* Create supply message
|
|
109
|
-
* @returns supply message as a cell
|
|
110
|
-
*/
|
|
111
|
-
createSupplyMessage(parameters: SupplyParameters): Cell;
|
|
112
|
-
/**
|
|
113
|
-
* Create withdraw message
|
|
114
|
-
* @returns withdraw message as a cell
|
|
115
|
-
*/
|
|
116
|
-
createWithdrawMessage(parameters: WithdrawParameters): Cell;
|
|
117
|
-
/**
|
|
118
|
-
* Create liquidation message
|
|
119
|
-
* @returns liquidation message as a cell
|
|
120
|
-
*/
|
|
121
|
-
createLiquidationMessage(parameters: LiquidationParameters): Cell;
|
|
122
|
-
/**
|
|
123
|
-
* Calculate user contract address
|
|
124
|
-
* @param userAddress
|
|
125
|
-
* @returns user contract address
|
|
126
|
-
*/
|
|
127
|
-
calculateUserSCAddr(userAddress: Address, lendingCode: Cell): Address;
|
|
128
|
-
/**
|
|
129
|
-
* Open user contract wrapper
|
|
130
|
-
* @param userAddress
|
|
131
|
-
* @returns user contract
|
|
132
|
-
*/
|
|
133
|
-
openUserContract(userAddress: Address): EvaaUser;
|
|
134
|
-
getOpenedUserContract(provider: ContractProvider, userAddress: Address): OpenedContract<EvaaUser>;
|
|
135
|
-
/**
|
|
136
|
-
* Get master contract data
|
|
137
|
-
*/
|
|
138
|
-
get data(): Maybe<MasterData>;
|
|
139
|
-
sendSupply(provider: ContractProvider, via: Sender, value: bigint, parameters: SupplyParameters): Promise<void>;
|
|
140
|
-
sendWithdraw(provider: ContractProvider, via: Sender, value: bigint, parameters: WithdrawParameters): Promise<void>;
|
|
141
|
-
sendLiquidation(provider: ContractProvider, via: Sender, value: bigint, parameters: LiquidationParameters): Promise<void>;
|
|
142
|
-
/**
|
|
143
|
-
* Open user contract wrapper
|
|
144
|
-
* @param forwardPayload - payload that will be forwarded to the address which requested the data
|
|
145
|
-
*/
|
|
146
|
-
sendOnchainGetter(provider: ContractProvider, via: Sender, value: bigint, queryID: bigint, forwardPayload: Cell): Promise<void>;
|
|
147
|
-
/**
|
|
148
|
-
* Sync master contract data
|
|
149
|
-
*/
|
|
150
|
-
getSync(provider: ContractProvider): Promise<void>;
|
|
151
|
-
/**
|
|
152
|
-
* @deprecated Use PriceCollector (createPriceCollector) istead of getPrices
|
|
153
|
-
*/
|
|
154
|
-
getPrices(provider: ContractProvider, endpoints?: string[]): Promise<import("..").PriceData>;
|
|
155
|
-
createPriceCollector(priceSourcesConfig?: PriceSourcesConfig): PricesCollector;
|
|
156
|
-
}
|
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Evaa = void 0;
|
|
4
|
-
const core_1 = require("@ton/core");
|
|
5
|
-
const general_1 = require("../constants/general");
|
|
6
|
-
const UserContract_1 = require("./UserContract");
|
|
7
|
-
const parser_1 = require("../api/parser");
|
|
8
|
-
const JettonWallet_1 = require("./JettonWallet");
|
|
9
|
-
const userJettonWallet_1 = require("../utils/userJettonWallet");
|
|
10
|
-
const __1 = require("..");
|
|
11
|
-
/**
|
|
12
|
-
* Evaa master contract wrapper
|
|
13
|
-
*/
|
|
14
|
-
class Evaa {
|
|
15
|
-
/**
|
|
16
|
-
* Create Evaa contract wrapper
|
|
17
|
-
* @param parameters Evaa contract parameters
|
|
18
|
-
*/
|
|
19
|
-
constructor(parameters) {
|
|
20
|
-
this.lastSync = 0;
|
|
21
|
-
this._poolConfig = parameters?.poolConfig ?? __1.MAINNET_POOL_CONFIG;
|
|
22
|
-
this.address = this._poolConfig.masterAddress;
|
|
23
|
-
this.debug = parameters?.debug;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Returns pool config
|
|
27
|
-
*/
|
|
28
|
-
get poolConfig() {
|
|
29
|
-
return this._poolConfig;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Create supply message
|
|
33
|
-
* @returns supply message as a cell
|
|
34
|
-
*/
|
|
35
|
-
createSupplyMessage(parameters) {
|
|
36
|
-
if (!(0, __1.isTonAsset)(parameters.asset)) {
|
|
37
|
-
return (0, core_1.beginCell)()
|
|
38
|
-
.storeUint(general_1.OPCODES.JETTON_TRANSFER, 32)
|
|
39
|
-
.storeUint(parameters.queryID, 64)
|
|
40
|
-
.storeCoins(parameters.amount)
|
|
41
|
-
.storeAddress(this.address)
|
|
42
|
-
.storeAddress(parameters.responseAddress ?? parameters.userAddress)
|
|
43
|
-
.storeBit(0)
|
|
44
|
-
.storeCoins(parameters.forwardAmount ?? general_1.FEES.SUPPLY_JETTON_FWD)
|
|
45
|
-
.storeBit(1)
|
|
46
|
-
.storeRef((0, core_1.beginCell)()
|
|
47
|
-
.storeUint(general_1.OPCODES.SUPPLY, 32)
|
|
48
|
-
.storeInt(parameters.includeUserCode ? -1 : 0, 2)
|
|
49
|
-
.storeAddress(parameters.userAddress)
|
|
50
|
-
.storeUint(parameters.amountToTransfer, 64)
|
|
51
|
-
.storeRef(parameters.payload)
|
|
52
|
-
.endCell())
|
|
53
|
-
.endCell();
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
return (0, core_1.beginCell)()
|
|
57
|
-
.storeUint(general_1.OPCODES.SUPPLY, 32)
|
|
58
|
-
.storeUint(parameters.queryID, 64)
|
|
59
|
-
.storeInt(parameters.includeUserCode ? -1 : 0, 2)
|
|
60
|
-
.storeUint(parameters.amount, 64)
|
|
61
|
-
.storeAddress(parameters.userAddress)
|
|
62
|
-
.storeUint(parameters.amountToTransfer, 64)
|
|
63
|
-
.storeRef(parameters.payload)
|
|
64
|
-
.endCell();
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Create withdraw message
|
|
69
|
-
* @returns withdraw message as a cell
|
|
70
|
-
*/
|
|
71
|
-
createWithdrawMessage(parameters) {
|
|
72
|
-
return (0, core_1.beginCell)()
|
|
73
|
-
.storeUint(general_1.OPCODES.WITHDRAW, 32)
|
|
74
|
-
.storeUint(parameters.queryID, 64)
|
|
75
|
-
.storeUint(parameters.asset.assetId, 256)
|
|
76
|
-
.storeUint(parameters.amount, 64)
|
|
77
|
-
.storeAddress(parameters.userAddress)
|
|
78
|
-
.storeInt(parameters.includeUserCode ? -1 : 0, 2)
|
|
79
|
-
.storeUint(parameters.amountToTransfer, 64)
|
|
80
|
-
.storeRef(parameters.payload)
|
|
81
|
-
.storeRef(parameters.priceData)
|
|
82
|
-
.endCell();
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Create liquidation message
|
|
86
|
-
* @returns liquidation message as a cell
|
|
87
|
-
*/
|
|
88
|
-
createLiquidationMessage(parameters) {
|
|
89
|
-
if (!(0, __1.isTonAsset)(parameters.asset)) {
|
|
90
|
-
return (0, core_1.beginCell)()
|
|
91
|
-
.storeUint(general_1.OPCODES.JETTON_TRANSFER, 32)
|
|
92
|
-
.storeUint(parameters.queryID, 64)
|
|
93
|
-
.storeCoins(parameters.liquidationAmount)
|
|
94
|
-
.storeAddress(this.address)
|
|
95
|
-
.storeAddress(parameters.responseAddress ?? parameters.liquidatorAddress)
|
|
96
|
-
.storeBit(0)
|
|
97
|
-
.storeCoins(parameters.forwardAmount ?? general_1.FEES.LIQUIDATION_JETTON_FWD)
|
|
98
|
-
.storeBit(1)
|
|
99
|
-
.storeRef((0, core_1.beginCell)()
|
|
100
|
-
.storeUint(general_1.OPCODES.LIQUIDATE, 32)
|
|
101
|
-
.storeAddress(parameters.borrowerAddress)
|
|
102
|
-
.storeAddress(parameters.liquidatorAddress)
|
|
103
|
-
.storeUint(parameters.collateralAsset, 256)
|
|
104
|
-
.storeUint(parameters.minCollateralAmount, 64)
|
|
105
|
-
.storeInt(parameters.includeUserCode ? -1 : 0, 2)
|
|
106
|
-
// do not need liquidationAmount in case of jetton liquidation because
|
|
107
|
-
// the exact amount of transferred jettons for liquidation is known
|
|
108
|
-
.storeUint(0, 64)
|
|
109
|
-
.storeRef((0, core_1.beginCell)()
|
|
110
|
-
.storeUint(parameters.payloadForwardAmount ?? 0, 64)
|
|
111
|
-
.storeRef(parameters.payload)
|
|
112
|
-
.endCell())
|
|
113
|
-
.storeRef(parameters.priceData)
|
|
114
|
-
.endCell())
|
|
115
|
-
.endCell();
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
return (0, core_1.beginCell)()
|
|
119
|
-
.storeUint(general_1.OPCODES.LIQUIDATE, 32)
|
|
120
|
-
.storeUint(parameters.queryID, 64)
|
|
121
|
-
.storeAddress(parameters.borrowerAddress)
|
|
122
|
-
.storeAddress(parameters.liquidatorAddress)
|
|
123
|
-
.storeUint(parameters.collateralAsset, 256)
|
|
124
|
-
.storeUint(parameters.minCollateralAmount, 64)
|
|
125
|
-
.storeInt(parameters.includeUserCode ? -1 : 0, 2)
|
|
126
|
-
.storeUint(parameters.liquidationAmount, 64)
|
|
127
|
-
.storeRef((0, core_1.beginCell)()
|
|
128
|
-
.storeUint(parameters.payloadForwardAmount ?? 0, 64)
|
|
129
|
-
.storeRef(parameters.payload)
|
|
130
|
-
.endCell())
|
|
131
|
-
.storeRef(parameters.priceData)
|
|
132
|
-
.endCell();
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Calculate user contract address
|
|
137
|
-
* @param userAddress
|
|
138
|
-
* @returns user contract address
|
|
139
|
-
*/
|
|
140
|
-
calculateUserSCAddr(userAddress, lendingCode) {
|
|
141
|
-
const lendingData = (0, core_1.beginCell)()
|
|
142
|
-
.storeAddress(this.address)
|
|
143
|
-
.storeAddress(userAddress)
|
|
144
|
-
.storeUint(0, 8)
|
|
145
|
-
.storeBit(0)
|
|
146
|
-
.endCell();
|
|
147
|
-
const stateInit = (0, core_1.beginCell)()
|
|
148
|
-
.store((0, core_1.storeStateInit)({
|
|
149
|
-
code: lendingCode,
|
|
150
|
-
data: lendingData,
|
|
151
|
-
}))
|
|
152
|
-
.endCell();
|
|
153
|
-
return new core_1.Address(0, stateInit.hash());
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Open user contract wrapper
|
|
157
|
-
* @param userAddress
|
|
158
|
-
* @returns user contract
|
|
159
|
-
*/
|
|
160
|
-
openUserContract(userAddress) {
|
|
161
|
-
return UserContract_1.EvaaUser.createFromAddress(this.calculateUserSCAddr(userAddress, this._poolConfig.lendingCode), this._poolConfig);
|
|
162
|
-
}
|
|
163
|
-
getOpenedUserContract(provider, userAddress) {
|
|
164
|
-
return provider.open(this.openUserContract(userAddress));
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Get master contract data
|
|
168
|
-
*/
|
|
169
|
-
get data() {
|
|
170
|
-
return this._data;
|
|
171
|
-
}
|
|
172
|
-
async sendSupply(provider, via, value, parameters) {
|
|
173
|
-
const message = this.createSupplyMessage(parameters);
|
|
174
|
-
if (!(0, __1.isTonAsset)(parameters.asset)) {
|
|
175
|
-
if (!via.address) {
|
|
176
|
-
throw Error('Via address is required for jetton supply');
|
|
177
|
-
}
|
|
178
|
-
const jettonWallet = provider.open(JettonWallet_1.JettonWallet.createFromAddress((0, userJettonWallet_1.getUserJettonWallet)(via.address, parameters.asset)));
|
|
179
|
-
await jettonWallet.sendTransfer(via, value, message);
|
|
180
|
-
}
|
|
181
|
-
else {
|
|
182
|
-
await provider.internal(via, {
|
|
183
|
-
value,
|
|
184
|
-
sendMode: core_1.SendMode.PAY_GAS_SEPARATELY + core_1.SendMode.IGNORE_ERRORS,
|
|
185
|
-
body: message,
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
async sendWithdraw(provider, via, value, parameters) {
|
|
190
|
-
const message = this.createWithdrawMessage(parameters);
|
|
191
|
-
await provider.internal(via, {
|
|
192
|
-
value,
|
|
193
|
-
sendMode: core_1.SendMode.PAY_GAS_SEPARATELY + core_1.SendMode.IGNORE_ERRORS,
|
|
194
|
-
body: message,
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
async sendLiquidation(provider, via, value, parameters) {
|
|
198
|
-
const message = this.createLiquidationMessage(parameters);
|
|
199
|
-
if (!(0, __1.isTonAssetId)(parameters.loanAsset)) {
|
|
200
|
-
if (!via.address) {
|
|
201
|
-
throw Error('Via address is required for jetton liquidation');
|
|
202
|
-
}
|
|
203
|
-
const jettonWallet = provider.open(JettonWallet_1.JettonWallet.createFromAddress((0, userJettonWallet_1.getUserJettonWallet)(via.address, parameters.asset)));
|
|
204
|
-
await jettonWallet.sendTransfer(via, value, message);
|
|
205
|
-
}
|
|
206
|
-
else {
|
|
207
|
-
await provider.internal(via, {
|
|
208
|
-
value,
|
|
209
|
-
sendMode: core_1.SendMode.PAY_GAS_SEPARATELY + core_1.SendMode.IGNORE_ERRORS,
|
|
210
|
-
body: message,
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Open user contract wrapper
|
|
216
|
-
* @param forwardPayload - payload that will be forwarded to the address which requested the data
|
|
217
|
-
*/
|
|
218
|
-
async sendOnchainGetter(provider, via, value, queryID, forwardPayload) {
|
|
219
|
-
await provider.internal(via, {
|
|
220
|
-
value,
|
|
221
|
-
sendMode: core_1.SendMode.PAY_GAS_SEPARATELY + core_1.SendMode.IGNORE_ERRORS,
|
|
222
|
-
body: (0, core_1.beginCell)()
|
|
223
|
-
.storeUint(general_1.OPCODES.ONCHAIN_GETTER, 32)
|
|
224
|
-
.storeUint(queryID, 64)
|
|
225
|
-
.storeRef(forwardPayload)
|
|
226
|
-
.endCell(),
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Sync master contract data
|
|
231
|
-
*/
|
|
232
|
-
async getSync(provider) {
|
|
233
|
-
const state = (await provider.getState()).state;
|
|
234
|
-
if (state.type === 'active') {
|
|
235
|
-
this._data = (0, parser_1.parseMasterData)(state.data.toString('base64'), this._poolConfig.poolAssetsConfig, this._poolConfig.masterConstants);
|
|
236
|
-
if (this._data.upgradeConfig.masterCodeVersion !== this._poolConfig.masterVersion) {
|
|
237
|
-
throw Error(`Outdated SDK pool version. It supports only master code version ${this._poolConfig.masterVersion}, but the current master code version is ${this._data.upgradeConfig.masterCodeVersion}`);
|
|
238
|
-
}
|
|
239
|
-
this.lastSync = Math.floor(Date.now() / 1000);
|
|
240
|
-
}
|
|
241
|
-
else {
|
|
242
|
-
throw Error('Master contract is not active');
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* @deprecated Use PriceCollector (createPriceCollector) istead of getPrices
|
|
247
|
-
*/
|
|
248
|
-
async getPrices(provider, endpoints) {
|
|
249
|
-
if ((endpoints?.length ?? 0) > 0) {
|
|
250
|
-
return await (0, __1.getPrices)(endpoints, this._poolConfig);
|
|
251
|
-
}
|
|
252
|
-
else {
|
|
253
|
-
return await (0, __1.getPrices)(undefined, this._poolConfig);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
createPriceCollector(priceSourcesConfig = __1.DefaultPriceSourcesConfig) {
|
|
257
|
-
return new __1.PricesCollector(this._poolConfig, priceSourcesConfig);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
exports.Evaa = Evaa;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Dictionary } from '@ton/core';
|
|
2
|
-
import { Prices } from '.';
|
|
3
|
-
import { PoolAssetConfig, PoolAssetsConfig } from '../types/Master';
|
|
4
|
-
import { FetchConfig } from '../utils/utils';
|
|
5
|
-
export interface Oracle {
|
|
6
|
-
getPricesForLiquidate(realPrincipals: Dictionary<bigint, bigint>, fetchConfig?: FetchConfig): Promise<Prices>;
|
|
7
|
-
getPricesForSupplyWithdraw(realPrincipals: Dictionary<bigint, bigint>, supplyAsset: PoolAssetConfig | undefined, withdrawAsset: PoolAssetConfig | undefined, collateralToDebt: boolean, fetchConfig?: FetchConfig): Promise<Prices>;
|
|
8
|
-
getPrices(assets: PoolAssetsConfig, fetchConfig?: FetchConfig): Promise<Prices>;
|
|
9
|
-
}
|
package/dist/prices/Prices.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Cell, Dictionary } from '@ton/core';
|
|
2
|
-
import { PoolAssetConfig } from '../types/Master';
|
|
3
|
-
export declare class Prices {
|
|
4
|
-
#private;
|
|
5
|
-
constructor(dict: Dictionary<bigint, bigint>, dataCell: Cell, minPublishTime?: bigint, maxPublishTime?: bigint);
|
|
6
|
-
get dict(): Dictionary<bigint, bigint>;
|
|
7
|
-
get dataCell(): Cell;
|
|
8
|
-
get minPublishTime(): bigint | undefined;
|
|
9
|
-
get maxPublishTime(): bigint | undefined;
|
|
10
|
-
getAssetPrice<T extends bigint | PoolAssetConfig>(asset: T): bigint | undefined;
|
|
11
|
-
}
|
package/dist/prices/Prices.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
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 _Prices_instances, _Prices_dict, _Prices_dataCell, _Prices_minPublishTime, _Prices_maxPublishTime, _Prices_extractAssetId;
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.Prices = void 0;
|
|
16
|
-
const core_1 = require("@ton/core");
|
|
17
|
-
class Prices {
|
|
18
|
-
constructor(dict, dataCell, minPublishTime, maxPublishTime) {
|
|
19
|
-
_Prices_instances.add(this);
|
|
20
|
-
_Prices_dict.set(this, void 0);
|
|
21
|
-
_Prices_dataCell.set(this, void 0);
|
|
22
|
-
_Prices_minPublishTime.set(this, void 0);
|
|
23
|
-
_Prices_maxPublishTime.set(this, void 0);
|
|
24
|
-
__classPrivateFieldSet(this, _Prices_dict, dict, "f");
|
|
25
|
-
__classPrivateFieldSet(this, _Prices_dataCell, dataCell, "f");
|
|
26
|
-
__classPrivateFieldSet(this, _Prices_minPublishTime, minPublishTime, "f");
|
|
27
|
-
__classPrivateFieldSet(this, _Prices_maxPublishTime, maxPublishTime, "f");
|
|
28
|
-
}
|
|
29
|
-
get dict() {
|
|
30
|
-
const dict = core_1.Dictionary.empty();
|
|
31
|
-
for (const [key, value] of __classPrivateFieldGet(this, _Prices_dict, "f")) {
|
|
32
|
-
dict.set(key, value);
|
|
33
|
-
}
|
|
34
|
-
return dict;
|
|
35
|
-
}
|
|
36
|
-
get dataCell() {
|
|
37
|
-
return new core_1.Cell(__classPrivateFieldGet(this, _Prices_dataCell, "f"));
|
|
38
|
-
}
|
|
39
|
-
get minPublishTime() {
|
|
40
|
-
return __classPrivateFieldGet(this, _Prices_minPublishTime, "f");
|
|
41
|
-
}
|
|
42
|
-
get maxPublishTime() {
|
|
43
|
-
return __classPrivateFieldGet(this, _Prices_maxPublishTime, "f");
|
|
44
|
-
}
|
|
45
|
-
getAssetPrice(asset) {
|
|
46
|
-
const assetId = __classPrivateFieldGet(this, _Prices_instances, "m", _Prices_extractAssetId).call(this, asset);
|
|
47
|
-
return __classPrivateFieldGet(this, _Prices_dict, "f").get(assetId);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
exports.Prices = Prices;
|
|
51
|
-
_Prices_dict = new WeakMap(), _Prices_dataCell = new WeakMap(), _Prices_minPublishTime = new WeakMap(), _Prices_maxPublishTime = new WeakMap(), _Prices_instances = new WeakSet(), _Prices_extractAssetId = function _Prices_extractAssetId(asset) {
|
|
52
|
-
return typeof asset === 'bigint' ? asset : asset.assetId;
|
|
53
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Dictionary } from "@ton/core";
|
|
2
|
-
import { ExtendedEvaaOracle, PoolAssetConfig, PoolAssetsConfig } from "../types/Master";
|
|
3
|
-
import { FetchConfig } from '../utils/utils';
|
|
4
|
-
import { Oracle } from "./Oracle.interface";
|
|
5
|
-
import { Prices } from "./Prices";
|
|
6
|
-
import { PriceSource } from "./sources";
|
|
7
|
-
import { PriceSourcesConfig } from "./Types";
|
|
8
|
-
export type PricesCollectorConfig = {
|
|
9
|
-
poolAssetsConfig: PoolAssetsConfig;
|
|
10
|
-
minimalOracles: number;
|
|
11
|
-
evaaOracles: ExtendedEvaaOracle[];
|
|
12
|
-
sourcesConfig?: PriceSourcesConfig;
|
|
13
|
-
additionalPriceSources?: PriceSource[];
|
|
14
|
-
};
|
|
15
|
-
export declare class PricesCollector implements Oracle {
|
|
16
|
-
#private;
|
|
17
|
-
constructor(config: PricesCollectorConfig);
|
|
18
|
-
getPricesForLiquidate(realPrincipals: Dictionary<bigint, bigint>, fetchConfig?: FetchConfig): Promise<Prices>;
|
|
19
|
-
getPricesForWithdraw(realPrincipals: Dictionary<bigint, bigint>, withdrawAsset: PoolAssetConfig, collateralToDebt?: boolean, fetchConfig?: FetchConfig): Promise<Prices>;
|
|
20
|
-
getPricesForSupplyWithdraw(realPrincipals: Dictionary<bigint, bigint>, supplyAsset: PoolAssetConfig | undefined, withdrawAsset: PoolAssetConfig | undefined, collateralToDebt: boolean, fetchConfig?: FetchConfig): Promise<Prices>;
|
|
21
|
-
getPrices(assets?: PoolAssetsConfig, fetchConfig?: FetchConfig): Promise<Prices>;
|
|
22
|
-
}
|
|
@@ -1,146 +0,0 @@
|
|
|
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 _PricesCollector_instances, _PricesCollector_prices, _PricesCollector_poolAssetsConfig, _PricesCollector_sourcesConfig, _PricesCollector_priceSources, _PricesCollector_minimalOracles, _PricesCollector_getPricesByAssetList, _PricesCollector_collectPrices, _PricesCollector_collectPricesWithValidation, _PricesCollector_filterPrices, _PricesCollector_filterEmptyPrincipalsAndAssets;
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.PricesCollector = 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 Prices_1 = require("./Prices");
|
|
20
|
-
const Types_1 = require("./Types");
|
|
21
|
-
const utils_2 = require("./utils");
|
|
22
|
-
class PricesCollector {
|
|
23
|
-
constructor(config) {
|
|
24
|
-
_PricesCollector_instances.add(this);
|
|
25
|
-
_PricesCollector_prices.set(this, void 0);
|
|
26
|
-
_PricesCollector_poolAssetsConfig.set(this, void 0);
|
|
27
|
-
_PricesCollector_sourcesConfig.set(this, void 0);
|
|
28
|
-
_PricesCollector_priceSources.set(this, void 0);
|
|
29
|
-
_PricesCollector_minimalOracles.set(this, void 0);
|
|
30
|
-
__classPrivateFieldSet(this, _PricesCollector_poolAssetsConfig, config.poolAssetsConfig, "f");
|
|
31
|
-
__classPrivateFieldSet(this, _PricesCollector_sourcesConfig, config.sourcesConfig ?? Types_1.DefaultPriceSourcesConfig, "f");
|
|
32
|
-
__classPrivateFieldSet(this, _PricesCollector_priceSources, (0, utils_2.generatePriceSources)(__classPrivateFieldGet(this, _PricesCollector_sourcesConfig, "f"), config.evaaOracles), "f");
|
|
33
|
-
__classPrivateFieldSet(this, _PricesCollector_minimalOracles, config.minimalOracles, "f");
|
|
34
|
-
if (config.additionalPriceSources) {
|
|
35
|
-
__classPrivateFieldGet(this, _PricesCollector_priceSources, "f").push(...config.additionalPriceSources);
|
|
36
|
-
}
|
|
37
|
-
__classPrivateFieldSet(this, _PricesCollector_prices, [], "f");
|
|
38
|
-
}
|
|
39
|
-
async getPricesForLiquidate(realPrincipals, fetchConfig) {
|
|
40
|
-
const assets = __classPrivateFieldGet(this, _PricesCollector_instances, "m", _PricesCollector_filterEmptyPrincipalsAndAssets).call(this, realPrincipals);
|
|
41
|
-
if (assets.includes(undefined)) {
|
|
42
|
-
throw new Error("User from another pool");
|
|
43
|
-
}
|
|
44
|
-
return await this.getPrices(assets.map(x => x), fetchConfig);
|
|
45
|
-
}
|
|
46
|
-
async getPricesForWithdraw(realPrincipals, withdrawAsset, collateralToDebt = false, fetchConfig) {
|
|
47
|
-
let assets = __classPrivateFieldGet(this, _PricesCollector_instances, "m", _PricesCollector_filterEmptyPrincipalsAndAssets).call(this, realPrincipals);
|
|
48
|
-
if ((0, math_1.checkNotInDebtAtAll)(realPrincipals) && (realPrincipals.get(withdrawAsset.assetId) ?? 0n) > 0n && !collateralToDebt) {
|
|
49
|
-
return new Prices_1.Prices(core_1.Dictionary.empty(), core_1.Cell.EMPTY);
|
|
50
|
-
}
|
|
51
|
-
if (assets.includes(undefined)) {
|
|
52
|
-
throw new Error("User from another pool");
|
|
53
|
-
}
|
|
54
|
-
if (!assets.includes(withdrawAsset)) {
|
|
55
|
-
assets.push(withdrawAsset);
|
|
56
|
-
}
|
|
57
|
-
if (collateralToDebt && assets.length == 1) {
|
|
58
|
-
throw new Error("Cannot debt only one supplied asset");
|
|
59
|
-
}
|
|
60
|
-
return await this.getPrices(assets.map(x => x), fetchConfig);
|
|
61
|
-
}
|
|
62
|
-
async getPricesForSupplyWithdraw(realPrincipals, supplyAsset, withdrawAsset, collateralToDebt, fetchConfig) {
|
|
63
|
-
// Используем ту же логику, что и getPricesForWithdraw, но supplyAsset не используется
|
|
64
|
-
let assets = __classPrivateFieldGet(this, _PricesCollector_instances, "m", _PricesCollector_filterEmptyPrincipalsAndAssets).call(this, realPrincipals);
|
|
65
|
-
if ((0, math_1.checkNotInDebtAtAll)(realPrincipals) && withdrawAsset && (realPrincipals.get(withdrawAsset.assetId) ?? 0n) > 0n && !collateralToDebt) {
|
|
66
|
-
return new Prices_1.Prices(core_1.Dictionary.empty(), core_1.Cell.EMPTY);
|
|
67
|
-
}
|
|
68
|
-
if (assets.includes(undefined)) {
|
|
69
|
-
throw new Error("User from another pool");
|
|
70
|
-
}
|
|
71
|
-
if (withdrawAsset && !assets.includes(withdrawAsset)) {
|
|
72
|
-
assets.push(withdrawAsset);
|
|
73
|
-
}
|
|
74
|
-
if (collateralToDebt && assets.length == 1) {
|
|
75
|
-
throw new Error("Cannot debt only one supplied asset");
|
|
76
|
-
}
|
|
77
|
-
return await this.getPrices(assets.map(x => x), fetchConfig);
|
|
78
|
-
}
|
|
79
|
-
async getPrices(assets = __classPrivateFieldGet(this, _PricesCollector_poolAssetsConfig, "f"), fetchConfig) {
|
|
80
|
-
if (assets.length == 0) {
|
|
81
|
-
return new Prices_1.Prices(core_1.Dictionary.empty(), core_1.Cell.EMPTY);
|
|
82
|
-
}
|
|
83
|
-
await __classPrivateFieldGet(this, _PricesCollector_instances, "m", _PricesCollector_collectPricesWithValidation).call(this, fetchConfig);
|
|
84
|
-
if (__classPrivateFieldGet(this, _PricesCollector_prices, "f").length < __classPrivateFieldGet(this, _PricesCollector_minimalOracles, "f")) {
|
|
85
|
-
throw new Error(`Error per updating prices, valid ${__classPrivateFieldGet(this, _PricesCollector_prices, "f").length} of ${__classPrivateFieldGet(this, _PricesCollector_minimalOracles, "f")}`);
|
|
86
|
-
}
|
|
87
|
-
const prices = __classPrivateFieldGet(this, _PricesCollector_instances, "m", _PricesCollector_getPricesByAssetList).call(this, assets);
|
|
88
|
-
return new Prices_1.Prices(prices.dict, prices.dataCell);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
exports.PricesCollector = PricesCollector;
|
|
92
|
-
_PricesCollector_prices = new WeakMap(), _PricesCollector_poolAssetsConfig = new WeakMap(), _PricesCollector_sourcesConfig = new WeakMap(), _PricesCollector_priceSources = new WeakMap(), _PricesCollector_minimalOracles = new WeakMap(), _PricesCollector_instances = new WeakSet(), _PricesCollector_getPricesByAssetList = function _PricesCollector_getPricesByAssetList(assets) {
|
|
93
|
-
let pricesFiltered = __classPrivateFieldGet(this, _PricesCollector_prices, "f");
|
|
94
|
-
if (pricesFiltered.length < __classPrivateFieldGet(this, _PricesCollector_minimalOracles, "f")) {
|
|
95
|
-
throw new Error("Not enough price data");
|
|
96
|
-
}
|
|
97
|
-
if (pricesFiltered.length > __classPrivateFieldGet(this, _PricesCollector_minimalOracles, "f")) {
|
|
98
|
-
const sortedByTimestamp = pricesFiltered.slice().sort((a, b) => b.timestamp - a.timestamp);
|
|
99
|
-
const newerPrices = sortedByTimestamp.slice(0, __classPrivateFieldGet(this, _PricesCollector_minimalOracles, "f"));
|
|
100
|
-
pricesFiltered = newerPrices.sort((a, b) => a.oracleId - b.oracleId);
|
|
101
|
-
}
|
|
102
|
-
const medianData = assets.map((asset) => ({
|
|
103
|
-
assetId: asset.assetId,
|
|
104
|
-
medianPrice: (0, utils_2.getMedianPrice)(pricesFiltered, asset.assetId),
|
|
105
|
-
}));
|
|
106
|
-
const nonEmptymedianData = medianData.filter(x => x.medianPrice != null);
|
|
107
|
-
const packedMedianData = (0, utils_2.packAssetsData)(nonEmptymedianData);
|
|
108
|
-
const oraclesData = pricesFiltered.map((x) => ({
|
|
109
|
-
oracle: { id: x.oracleId, pubkey: x.pubkey },
|
|
110
|
-
data: { timestamp: x.timestamp, prices: x.dict },
|
|
111
|
-
signature: x.signature,
|
|
112
|
-
}));
|
|
113
|
-
const packedOracleData = (0, utils_2.packOraclesData)(oraclesData, nonEmptymedianData.map(x => x.assetId));
|
|
114
|
-
const dict = core_1.Dictionary.empty();
|
|
115
|
-
for (const medianDataAsset of nonEmptymedianData) {
|
|
116
|
-
dict.set(medianDataAsset.assetId, medianDataAsset.medianPrice);
|
|
117
|
-
}
|
|
118
|
-
return {
|
|
119
|
-
dict: dict,
|
|
120
|
-
dataCell: (0, utils_2.packPrices)(packedMedianData, packedOracleData)
|
|
121
|
-
};
|
|
122
|
-
}, _PricesCollector_collectPrices = async function _PricesCollector_collectPrices(fetchConfig) {
|
|
123
|
-
for (const priceSource of __classPrivateFieldGet(this, _PricesCollector_priceSources, "f")) {
|
|
124
|
-
try {
|
|
125
|
-
__classPrivateFieldSet(this, _PricesCollector_prices, await (0, utils_1.proxyFetchRetries)((0, utils_2.collectAndFilterPrices)(priceSource, __classPrivateFieldGet(this, _PricesCollector_minimalOracles, "f"), fetchConfig), fetchConfig), "f");
|
|
126
|
-
return true;
|
|
127
|
-
}
|
|
128
|
-
catch (error) {
|
|
129
|
-
// Try next source
|
|
130
|
-
continue;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
return false;
|
|
134
|
-
}, _PricesCollector_collectPricesWithValidation = async function _PricesCollector_collectPricesWithValidation(fetchConfig) {
|
|
135
|
-
if (!__classPrivateFieldGet(this, _PricesCollector_prices, "f") || __classPrivateFieldGet(this, _PricesCollector_instances, "m", _PricesCollector_filterPrices).call(this) < __classPrivateFieldGet(this, _PricesCollector_minimalOracles, "f")) {
|
|
136
|
-
const success = await __classPrivateFieldGet(this, _PricesCollector_instances, "m", _PricesCollector_collectPrices).call(this, fetchConfig);
|
|
137
|
-
if (!success || __classPrivateFieldGet(this, _PricesCollector_prices, "f").length < __classPrivateFieldGet(this, _PricesCollector_minimalOracles, "f")) {
|
|
138
|
-
throw new Error(`Failed to collect sufficient prices: ${__classPrivateFieldGet(this, _PricesCollector_prices, "f")?.length || 0} of ${__classPrivateFieldGet(this, _PricesCollector_minimalOracles, "f")}`);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}, _PricesCollector_filterPrices = function _PricesCollector_filterPrices() {
|
|
142
|
-
__classPrivateFieldSet(this, _PricesCollector_prices, __classPrivateFieldGet(this, _PricesCollector_prices, "f").filter((0, utils_2.verifyPricesTimestamp)()), "f");
|
|
143
|
-
return __classPrivateFieldGet(this, _PricesCollector_prices, "f").length;
|
|
144
|
-
}, _PricesCollector_filterEmptyPrincipalsAndAssets = function _PricesCollector_filterEmptyPrincipalsAndAssets(principals) {
|
|
145
|
-
return principals.keys().filter(x => principals.get(x) != 0n).map(x => __classPrivateFieldGet(this, _PricesCollector_poolAssetsConfig, "f").find(asset => asset.assetId == x));
|
|
146
|
-
};
|