@gearbox-protocol/sdk 8.24.8 → 8.25.1-next.1

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 (23) hide show
  1. package/dist/cjs/plugins/zappers/extraZappers.js +84 -0
  2. package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +8 -19
  3. package/dist/cjs/sdk/market/credit/CreditFacadeV300Contract.js +0 -11
  4. package/dist/cjs/sdk/market/credit/CreditFacadeV310Contract.js +0 -18
  5. package/dist/cjs/sdk/market/oracle/PriceOracleBaseContract.js +0 -43
  6. package/dist/cjs/sdk/market/oracle/PriceOracleV300Contract.js +51 -0
  7. package/dist/cjs/sdk/market/oracle/PriceOracleV310Contract.js +41 -0
  8. package/dist/esm/plugins/zappers/extraZappers.js +84 -0
  9. package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +8 -19
  10. package/dist/esm/sdk/market/credit/CreditFacadeV300Contract.js +0 -11
  11. package/dist/esm/sdk/market/credit/CreditFacadeV310Contract.js +0 -18
  12. package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +1 -44
  13. package/dist/esm/sdk/market/oracle/PriceOracleV300Contract.js +58 -1
  14. package/dist/esm/sdk/market/oracle/PriceOracleV310Contract.js +48 -1
  15. package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +1 -7
  16. package/dist/types/sdk/accounts/types.d.ts +1 -7
  17. package/dist/types/sdk/market/credit/CreditFacadeV300Contract.d.ts +0 -2
  18. package/dist/types/sdk/market/credit/CreditFacadeV310Contract.d.ts +0 -2
  19. package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +3 -9
  20. package/dist/types/sdk/market/oracle/PriceOracleV300Contract.d.ts +10 -1
  21. package/dist/types/sdk/market/oracle/PriceOracleV310Contract.d.ts +10 -1
  22. package/dist/types/sdk/market/oracle/types.d.ts +3 -13
  23. package/package.json +1 -1
@@ -64,6 +64,90 @@ const extraZappers = {
64
64
  decimals: 18
65
65
  },
66
66
  pool: "0xf00B548f1b69cB5EE559d891E03A196FB5101d4A"
67
+ },
68
+ {
69
+ baseParams: {
70
+ addr: "0x17897d188bb49fea7bfac56e29b07036e16b3537",
71
+ version: 310n,
72
+ contractType: "0x5a41505045523a3a5354414b45445f4552433436323600000000000000000000",
73
+ serializedParams: "0x0000000000000000000000009ef444a6d7f4a5adcd68fd5329aa5240c90e14d2000000000000000000000000da00000035fef4082f78def6a8903bee419fbf8e"
74
+ },
75
+ tokenIn: {
76
+ addr: "0x9ef444a6d7F4A5adcd68FD5329aA5240C90E14d2",
77
+ symbol: "farmdUSDCV3",
78
+ name: "Farming of Trade USDC v3",
79
+ decimals: 6
80
+ },
81
+ tokenOut: {
82
+ addr: "0xC155444481854c60e7a29f4150373f479988F32D",
83
+ symbol: "USDC",
84
+ name: "USDC",
85
+ decimals: 6
86
+ },
87
+ pool: "0xC155444481854c60e7a29f4150373f479988F32D"
88
+ },
89
+ {
90
+ baseParams: {
91
+ addr: "0x70383bac778f0285ddb5f35afbd631e5a4675c58",
92
+ version: 310n,
93
+ contractType: "0x5a41505045523a3a5354414b45445f4552433436323600000000000000000000",
94
+ serializedParams: "0x0000000000000000000000009ef444a6d7f4a5adcd68fd5329aa5240c90e14d2000000000000000000000000da00000035fef4082f78def6a8903bee419fbf8e"
95
+ },
96
+ tokenIn: {
97
+ addr: "0x9ef444a6d7F4A5adcd68FD5329aA5240C90E14d2",
98
+ symbol: "farmdUSDCV3",
99
+ name: "Farming of Trade USDC v3",
100
+ decimals: 6
101
+ },
102
+ tokenOut: {
103
+ addr: "0xF0795C47fA58d00f5F77F4D5c01F31eE891E21B4",
104
+ symbol: "rUSDC",
105
+ name: "Resolv USDC",
106
+ decimals: 6
107
+ },
108
+ pool: "0xF0795C47fA58d00f5F77F4D5c01F31eE891E21B4"
109
+ },
110
+ {
111
+ baseParams: {
112
+ addr: "0x2bC0231a1FC6a9b2E0C44AC1089F47a122a7a8c1",
113
+ version: 310n,
114
+ contractType: "0x5a41505045523a3a455243343632360000000000000000000000000000000000",
115
+ serializedParams: "0x000000000000000000000000da0002859b2d05f66a753d8241fcde8623f26f4f"
116
+ },
117
+ tokenIn: {
118
+ addr: "0xda0002859B2d05F66a753d8241fCDE8623f26F4f",
119
+ symbol: "dWETHV3",
120
+ name: "Trade WETH v3",
121
+ decimals: 18
122
+ },
123
+ tokenOut: {
124
+ addr: "0xf00B548f1b69cB5EE559d891E03A196FB5101d4A",
125
+ symbol: "dWETHV3-cp0x",
126
+ name: "Gearbox WETH v3",
127
+ decimals: 18
128
+ },
129
+ pool: "0xf00B548f1b69cB5EE559d891E03A196FB5101d4A"
130
+ },
131
+ {
132
+ baseParams: {
133
+ addr: "0x62af1fc6e54e66aba5322a3491b5ce1808a6fe89",
134
+ version: 310n,
135
+ contractType: "0x5a41505045523a3a455243343632360000000000000000000000000000000000",
136
+ serializedParams: "0x000000000000000000000000da00000035fef4082f78def6a8903bee419fbf8e"
137
+ },
138
+ tokenIn: {
139
+ addr: "0xda00000035fef4082F78dEF6A8903bee419FbF8E",
140
+ symbol: "dUSDCV3",
141
+ name: "Trade USDC v3",
142
+ decimals: 6
143
+ },
144
+ tokenOut: {
145
+ addr: "0xF0795C47fA58d00f5F77F4D5c01F31eE891E21B4",
146
+ symbol: "rUSDC",
147
+ name: "Resolv USDC",
148
+ decimals: 6
149
+ },
150
+ pool: "0xF0795C47fA58d00f5F77F4D5c01F31eE891E21B4"
67
151
  }
68
152
  ]
69
153
  };
@@ -836,11 +836,14 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
836
836
  );
837
837
  }
838
838
  /**
839
- * Returns account price updates in a non-encoded format
839
+ * Returns price updates in format that is accepted by various credit facade methods (multicall, close/liquidate, etc...).
840
+ * - If there are desiredQuotas and creditAccount update quotaBalance > 0 || (balance > 10n && isEnabled). Is used when account has both: balances and quota buys.
841
+ * - If there is creditAccount update balance > 10n && isEnabled. Is used in credit account actions when quota is not being bought.
842
+ * - If there is desiredQuotas update quotaBalance > 0. Is used on credit account opening, when quota is bought for the first time.
840
843
  * @param acc
841
844
  * @returns
842
845
  */
843
- async getOnDemandPriceUpdates(creditManager, creditAccount, desiredQuotas) {
846
+ async getPriceUpdatesForFacade(creditManager, creditAccount, desiredQuotas) {
844
847
  const market = this.sdk.marketRegister.findByCreditManager(creditManager);
845
848
  const cm = this.sdk.marketRegister.findCreditManager(creditManager);
846
849
  const update = await this.getUpdateForAccount(
@@ -852,24 +855,10 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
852
855
  { account: creditAccount?.creditAccount, manager: cm.name },
853
856
  `getting on demand price updates from ${update.txs.length} txs`
854
857
  );
855
- return market.priceOracle.onDemandPriceUpdates(update);
856
- }
857
- /**
858
- * Returns price updates in format that is accepted by various credit facade methods (multicall, close/liquidate, etc...).
859
- * - If there are desiredQuotas and creditAccount update quotaBalance > 0 || (balance > 10n && isEnabled). Is used when account has both: balances and quota buys.
860
- * - If there is creditAccount update balance > 10n && isEnabled. Is used in credit account actions when quota is not being bought.
861
- * - If there is desiredQuotas update quotaBalance > 0. Is used on credit account opening, when quota is bought for the first time.
862
- * @param acc
863
- * @returns
864
- */
865
- async getPriceUpdatesForFacade(creditManager, creditAccount, desiredQuotas) {
866
- const cm = this.sdk.marketRegister.findCreditManager(creditManager);
867
- const updates = await this.getOnDemandPriceUpdates(
868
- creditManager,
869
- creditAccount,
870
- desiredQuotas
858
+ return market.priceOracle.onDemandPriceUpdates(
859
+ cm.creditFacade.address,
860
+ update
871
861
  );
872
- return cm.creditFacade.encodeOnDemandPriceUpdates(updates);
873
862
  }
874
863
  prepareDisableQuotas(ca) {
875
864
  const calls = [];
@@ -21,7 +21,6 @@ __export(CreditFacadeV300Contract_exports, {
21
21
  CreditFacadeV300Contract: () => CreditFacadeV300Contract
22
22
  });
23
23
  module.exports = __toCommonJS(CreditFacadeV300Contract_exports);
24
- var import_viem = require("viem");
25
24
  var import_iPausable = require("../../../abi/iPausable.js");
26
25
  var import_v300 = require("../../../abi/v300.js");
27
26
  var import_base = require("../../base/index.js");
@@ -82,16 +81,6 @@ class CreditFacadeV300Contract extends import_base.BaseContract {
82
81
  break;
83
82
  }
84
83
  }
85
- encodeOnDemandPriceUpdates(updates) {
86
- return updates.map((u) => ({
87
- target: this.address,
88
- callData: (0, import_viem.encodeFunctionData)({
89
- abi: import_v300.iCreditFacadeV300MulticallAbi,
90
- functionName: "onDemandPriceUpdate",
91
- args: [u.token, u.reserve, u.data]
92
- })
93
- }));
94
- }
95
84
  liquidateCreditAccount(ca, to, calls) {
96
85
  return this.createRawTx({
97
86
  functionName: "liquidateCreditAccount",
@@ -21,7 +21,6 @@ __export(CreditFacadeV310Contract_exports, {
21
21
  CreditFacadeV310Contract: () => CreditFacadeV310Contract
22
22
  });
23
23
  module.exports = __toCommonJS(CreditFacadeV310Contract_exports);
24
- var import_viem = require("viem");
25
24
  var import_iPausable = require("../../../abi/iPausable.js");
26
25
  var import_v310 = require("../../../abi/v310.js");
27
26
  var import_base = require("../../base/index.js");
@@ -82,23 +81,6 @@ class CreditFacadeV310Contract extends import_base.BaseContract {
82
81
  break;
83
82
  }
84
83
  }
85
- encodeOnDemandPriceUpdates(updates) {
86
- return [
87
- {
88
- target: this.address,
89
- callData: (0, import_viem.encodeFunctionData)({
90
- abi: import_v310.iCreditFacadeMulticallV310Abi,
91
- functionName: "onDemandPriceUpdates",
92
- args: [
93
- updates.map((u) => ({
94
- priceFeed: u.priceFeed,
95
- data: u.data
96
- }))
97
- ]
98
- })
99
- }
100
- ];
101
- }
102
84
  liquidateCreditAccount(ca, to, calls) {
103
85
  return this.createRawTx({
104
86
  functionName: "liquidateCreditAccount",
@@ -34,7 +34,6 @@ module.exports = __toCommonJS(PriceOracleBaseContract_exports);
34
34
  var import_date_fns = require("date-fns");
35
35
  var import_viem = require("viem");
36
36
  var import_compressors = require("../../../abi/compressors.js");
37
- var import_iUpdatablePriceFeed = require("../../../abi/iUpdatablePriceFeed.js");
38
37
  var import_base = require("../../base/index.js");
39
38
  var import_constants = require("../../constants/index.js");
40
39
  var import_utils = require("../../utils/index.js");
@@ -103,48 +102,6 @@ class PriceOracleBaseContract extends import_base.BaseContract {
103
102
  }
104
103
  return this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(updatables);
105
104
  }
106
- /**
107
- * Converts previously obtained price updates into CreditFacade multicall entries
108
- * @param creditFacade
109
- * @param updates
110
- * @returns
111
- */
112
- onDemandPriceUpdates(updates) {
113
- const result = [];
114
- if (!updates) {
115
- this.logger?.debug("empty updates list");
116
- return result;
117
- }
118
- const { txs } = updates;
119
- for (const tx of txs) {
120
- const { to: priceFeed, callData, description } = tx.raw;
121
- const [token, reserve] = this.findTokenForPriceFeed(priceFeed);
122
- if (!token) {
123
- const mains = this.mainPriceFeeds.values().map((v) => v.address);
124
- const reserves = this.reservePriceFeeds.values().map((v) => v.address);
125
- this.logger?.debug(
126
- { mainPriceFeeds: mains, reservePriceFeeds: reserves },
127
- `skipping onDemandPriceUpdate ${description}): token not found for price feed ${priceFeed} in oracle ${this.address}`
128
- );
129
- continue;
130
- }
131
- const { args } = (0, import_viem.decodeFunctionData)({
132
- abi: import_iUpdatablePriceFeed.iUpdatablePriceFeedAbi,
133
- data: callData
134
- });
135
- const data = args[0];
136
- result.push({
137
- priceFeed,
138
- token,
139
- reserve,
140
- data
141
- });
142
- }
143
- this.logger?.debug(
144
- `got ${result.length} onDemandPriceUpdates from ${txs.length} txs`
145
- );
146
- return result;
147
- }
148
105
  /**
149
106
  * Gets main price for given token
150
107
  * Throws if token price feed is not found or answer is not successful
@@ -21,7 +21,9 @@ __export(PriceOracleV300Contract_exports, {
21
21
  PriceOracleV300Contract: () => PriceOracleV300Contract
22
22
  });
23
23
  module.exports = __toCommonJS(PriceOracleV300Contract_exports);
24
+ var import_viem = require("viem");
24
25
  var import_iPausable = require("../../../abi/iPausable.js");
26
+ var import_iUpdatablePriceFeed = require("../../../abi/iUpdatablePriceFeed.js");
25
27
  var import_v300 = require("../../../abi/v300.js");
26
28
  var import_sdk_gov_legacy = require("../../sdk-gov-legacy/index.js");
27
29
  var import_PriceOracleBaseContract = require("./PriceOracleBaseContract.js");
@@ -50,6 +52,55 @@ class PriceOracleV300Contract extends import_PriceOracleBaseContract.PriceOracle
50
52
  break;
51
53
  }
52
54
  }
55
+ /**
56
+ * Converts previously obtained price updates into CreditFacade multicall entries
57
+ * @param creditFacade
58
+ * @param updates
59
+ * @returns
60
+ */
61
+ onDemandPriceUpdates(creditFacade, updates) {
62
+ const result = [];
63
+ if (!updates) {
64
+ this.logger?.debug("empty updates list");
65
+ return result;
66
+ }
67
+ const { txs } = updates;
68
+ for (const tx of txs) {
69
+ const { to: priceFeed, callData, description } = tx.raw;
70
+ const [token, reserve] = this.findTokenForPriceFeed(priceFeed);
71
+ if (!token) {
72
+ const mains = this.mainPriceFeeds.values().map((v) => v.address);
73
+ const reserves = this.reservePriceFeeds.values().map((v) => v.address);
74
+ this.logger?.debug(
75
+ { mainPriceFeeds: mains, reservePriceFeeds: reserves },
76
+ `skipping onDemandPriceUpdate ${description}): token not found for price feed ${priceFeed} in oracle ${this.address}`
77
+ );
78
+ continue;
79
+ }
80
+ const { args } = (0, import_viem.decodeFunctionData)({
81
+ abi: import_iUpdatablePriceFeed.iUpdatablePriceFeedAbi,
82
+ data: callData
83
+ });
84
+ const data = args[0];
85
+ if (!data) {
86
+ throw new Error(
87
+ `failed to decode update price args for ${description}`
88
+ );
89
+ }
90
+ result.push({
91
+ target: creditFacade,
92
+ callData: (0, import_viem.encodeFunctionData)({
93
+ abi: import_v300.iCreditFacadeV300MulticallAbi,
94
+ functionName: "onDemandPriceUpdate",
95
+ args: [token, reserve, data]
96
+ })
97
+ });
98
+ }
99
+ this.logger?.debug(
100
+ `got ${result.length} onDemandPriceUpdates from ${txs.length} txs`
101
+ );
102
+ return result;
103
+ }
53
104
  findTokenForPriceFeed(priceFeed) {
54
105
  const [token, reserve] = super.findTokenForPriceFeed(priceFeed);
55
106
  if (token) {
@@ -21,6 +21,8 @@ __export(PriceOracleV310Contract_exports, {
21
21
  PriceOracleV310Contract: () => PriceOracleV310Contract
22
22
  });
23
23
  module.exports = __toCommonJS(PriceOracleV310Contract_exports);
24
+ var import_viem = require("viem");
25
+ var import_iUpdatablePriceFeed = require("../../../abi/iUpdatablePriceFeed.js");
24
26
  var import_v310 = require("../../../abi/v310.js");
25
27
  var import_PriceOracleBaseContract = require("./PriceOracleBaseContract.js");
26
28
  const abi = import_v310.iPriceOracleV310Abi;
@@ -36,6 +38,45 @@ class PriceOracleV310Contract extends import_PriceOracleBaseContract.PriceOracle
36
38
  data
37
39
  );
38
40
  }
41
+ /**
42
+ * Converts previously obtained price updates into CreditFacade multicall entry
43
+ * @param creditFacade
44
+ * @param updates
45
+ * @returns
46
+ */
47
+ onDemandPriceUpdates(creditFacade, updates) {
48
+ if (!updates) {
49
+ this.logger?.debug("empty updates list");
50
+ return [];
51
+ }
52
+ return [
53
+ {
54
+ target: creditFacade,
55
+ callData: (0, import_viem.encodeFunctionData)({
56
+ abi: import_v310.iCreditFacadeMulticallV310Abi,
57
+ functionName: "onDemandPriceUpdates",
58
+ args: [
59
+ updates.txs.map((u) => {
60
+ const { args } = (0, import_viem.decodeFunctionData)({
61
+ abi: import_iUpdatablePriceFeed.iUpdatablePriceFeedAbi,
62
+ data: u.raw.callData
63
+ });
64
+ const data = args[0];
65
+ if (!data) {
66
+ throw new Error(
67
+ `failed to decode update price args for ${u.raw.description}`
68
+ );
69
+ }
70
+ return {
71
+ priceFeed: u.raw.to,
72
+ data
73
+ };
74
+ })
75
+ ]
76
+ })
77
+ }
78
+ ];
79
+ }
39
80
  processLog(log) {
40
81
  switch (log.eventName) {
41
82
  case "SetPriceFeed":
@@ -41,6 +41,90 @@ const extraZappers = {
41
41
  decimals: 18
42
42
  },
43
43
  pool: "0xf00B548f1b69cB5EE559d891E03A196FB5101d4A"
44
+ },
45
+ {
46
+ baseParams: {
47
+ addr: "0x17897d188bb49fea7bfac56e29b07036e16b3537",
48
+ version: 310n,
49
+ contractType: "0x5a41505045523a3a5354414b45445f4552433436323600000000000000000000",
50
+ serializedParams: "0x0000000000000000000000009ef444a6d7f4a5adcd68fd5329aa5240c90e14d2000000000000000000000000da00000035fef4082f78def6a8903bee419fbf8e"
51
+ },
52
+ tokenIn: {
53
+ addr: "0x9ef444a6d7F4A5adcd68FD5329aA5240C90E14d2",
54
+ symbol: "farmdUSDCV3",
55
+ name: "Farming of Trade USDC v3",
56
+ decimals: 6
57
+ },
58
+ tokenOut: {
59
+ addr: "0xC155444481854c60e7a29f4150373f479988F32D",
60
+ symbol: "USDC",
61
+ name: "USDC",
62
+ decimals: 6
63
+ },
64
+ pool: "0xC155444481854c60e7a29f4150373f479988F32D"
65
+ },
66
+ {
67
+ baseParams: {
68
+ addr: "0x70383bac778f0285ddb5f35afbd631e5a4675c58",
69
+ version: 310n,
70
+ contractType: "0x5a41505045523a3a5354414b45445f4552433436323600000000000000000000",
71
+ serializedParams: "0x0000000000000000000000009ef444a6d7f4a5adcd68fd5329aa5240c90e14d2000000000000000000000000da00000035fef4082f78def6a8903bee419fbf8e"
72
+ },
73
+ tokenIn: {
74
+ addr: "0x9ef444a6d7F4A5adcd68FD5329aA5240C90E14d2",
75
+ symbol: "farmdUSDCV3",
76
+ name: "Farming of Trade USDC v3",
77
+ decimals: 6
78
+ },
79
+ tokenOut: {
80
+ addr: "0xF0795C47fA58d00f5F77F4D5c01F31eE891E21B4",
81
+ symbol: "rUSDC",
82
+ name: "Resolv USDC",
83
+ decimals: 6
84
+ },
85
+ pool: "0xF0795C47fA58d00f5F77F4D5c01F31eE891E21B4"
86
+ },
87
+ {
88
+ baseParams: {
89
+ addr: "0x2bC0231a1FC6a9b2E0C44AC1089F47a122a7a8c1",
90
+ version: 310n,
91
+ contractType: "0x5a41505045523a3a455243343632360000000000000000000000000000000000",
92
+ serializedParams: "0x000000000000000000000000da0002859b2d05f66a753d8241fcde8623f26f4f"
93
+ },
94
+ tokenIn: {
95
+ addr: "0xda0002859B2d05F66a753d8241fCDE8623f26F4f",
96
+ symbol: "dWETHV3",
97
+ name: "Trade WETH v3",
98
+ decimals: 18
99
+ },
100
+ tokenOut: {
101
+ addr: "0xf00B548f1b69cB5EE559d891E03A196FB5101d4A",
102
+ symbol: "dWETHV3-cp0x",
103
+ name: "Gearbox WETH v3",
104
+ decimals: 18
105
+ },
106
+ pool: "0xf00B548f1b69cB5EE559d891E03A196FB5101d4A"
107
+ },
108
+ {
109
+ baseParams: {
110
+ addr: "0x62af1fc6e54e66aba5322a3491b5ce1808a6fe89",
111
+ version: 310n,
112
+ contractType: "0x5a41505045523a3a455243343632360000000000000000000000000000000000",
113
+ serializedParams: "0x000000000000000000000000da00000035fef4082f78def6a8903bee419fbf8e"
114
+ },
115
+ tokenIn: {
116
+ addr: "0xda00000035fef4082F78dEF6A8903bee419FbF8E",
117
+ symbol: "dUSDCV3",
118
+ name: "Trade USDC v3",
119
+ decimals: 6
120
+ },
121
+ tokenOut: {
122
+ addr: "0xF0795C47fA58d00f5F77F4D5c01F31eE891E21B4",
123
+ symbol: "rUSDC",
124
+ name: "Resolv USDC",
125
+ decimals: 6
126
+ },
127
+ pool: "0xF0795C47fA58d00f5F77F4D5c01F31eE891E21B4"
44
128
  }
45
129
  ]
46
130
  };
@@ -827,11 +827,14 @@ class AbstractCreditAccountService extends SDKConstruct {
827
827
  );
828
828
  }
829
829
  /**
830
- * Returns account price updates in a non-encoded format
830
+ * Returns price updates in format that is accepted by various credit facade methods (multicall, close/liquidate, etc...).
831
+ * - If there are desiredQuotas and creditAccount update quotaBalance > 0 || (balance > 10n && isEnabled). Is used when account has both: balances and quota buys.
832
+ * - If there is creditAccount update balance > 10n && isEnabled. Is used in credit account actions when quota is not being bought.
833
+ * - If there is desiredQuotas update quotaBalance > 0. Is used on credit account opening, when quota is bought for the first time.
831
834
  * @param acc
832
835
  * @returns
833
836
  */
834
- async getOnDemandPriceUpdates(creditManager, creditAccount, desiredQuotas) {
837
+ async getPriceUpdatesForFacade(creditManager, creditAccount, desiredQuotas) {
835
838
  const market = this.sdk.marketRegister.findByCreditManager(creditManager);
836
839
  const cm = this.sdk.marketRegister.findCreditManager(creditManager);
837
840
  const update = await this.getUpdateForAccount(
@@ -843,24 +846,10 @@ class AbstractCreditAccountService extends SDKConstruct {
843
846
  { account: creditAccount?.creditAccount, manager: cm.name },
844
847
  `getting on demand price updates from ${update.txs.length} txs`
845
848
  );
846
- return market.priceOracle.onDemandPriceUpdates(update);
847
- }
848
- /**
849
- * Returns price updates in format that is accepted by various credit facade methods (multicall, close/liquidate, etc...).
850
- * - If there are desiredQuotas and creditAccount update quotaBalance > 0 || (balance > 10n && isEnabled). Is used when account has both: balances and quota buys.
851
- * - If there is creditAccount update balance > 10n && isEnabled. Is used in credit account actions when quota is not being bought.
852
- * - If there is desiredQuotas update quotaBalance > 0. Is used on credit account opening, when quota is bought for the first time.
853
- * @param acc
854
- * @returns
855
- */
856
- async getPriceUpdatesForFacade(creditManager, creditAccount, desiredQuotas) {
857
- const cm = this.sdk.marketRegister.findCreditManager(creditManager);
858
- const updates = await this.getOnDemandPriceUpdates(
859
- creditManager,
860
- creditAccount,
861
- desiredQuotas
849
+ return market.priceOracle.onDemandPriceUpdates(
850
+ cm.creditFacade.address,
851
+ update
862
852
  );
863
- return cm.creditFacade.encodeOnDemandPriceUpdates(updates);
864
853
  }
865
854
  prepareDisableQuotas(ca) {
866
855
  const calls = [];
@@ -1,4 +1,3 @@
1
- import { encodeFunctionData } from "viem";
2
1
  import { iPausableAbi } from "../../../abi/iPausable.js";
3
2
  import {
4
3
  iCreditFacadeV300Abi,
@@ -62,16 +61,6 @@ class CreditFacadeV300Contract extends BaseContract {
62
61
  break;
63
62
  }
64
63
  }
65
- encodeOnDemandPriceUpdates(updates) {
66
- return updates.map((u) => ({
67
- target: this.address,
68
- callData: encodeFunctionData({
69
- abi: iCreditFacadeV300MulticallAbi,
70
- functionName: "onDemandPriceUpdate",
71
- args: [u.token, u.reserve, u.data]
72
- })
73
- }));
74
- }
75
64
  liquidateCreditAccount(ca, to, calls) {
76
65
  return this.createRawTx({
77
66
  functionName: "liquidateCreditAccount",
@@ -1,4 +1,3 @@
1
- import { encodeFunctionData } from "viem";
2
1
  import { iPausableAbi } from "../../../abi/iPausable.js";
3
2
  import {
4
3
  iCreditFacadeMulticallV310Abi,
@@ -62,23 +61,6 @@ class CreditFacadeV310Contract extends BaseContract {
62
61
  break;
63
62
  }
64
63
  }
65
- encodeOnDemandPriceUpdates(updates) {
66
- return [
67
- {
68
- target: this.address,
69
- callData: encodeFunctionData({
70
- abi: iCreditFacadeMulticallV310Abi,
71
- functionName: "onDemandPriceUpdates",
72
- args: [
73
- updates.map((u) => ({
74
- priceFeed: u.priceFeed,
75
- data: u.data
76
- }))
77
- ]
78
- })
79
- }
80
- ];
81
- }
82
64
  liquidateCreditAccount(ca, to, calls) {
83
65
  return this.createRawTx({
84
66
  functionName: "liquidateCreditAccount",
@@ -1,7 +1,6 @@
1
1
  import { format, formatDistanceToNow } from "date-fns";
2
- import { decodeFunctionData, stringToHex } from "viem";
2
+ import { stringToHex } from "viem";
3
3
  import { iPriceFeedCompressorAbi } from "../../../abi/compressors.js";
4
- import { iUpdatablePriceFeedAbi } from "../../../abi/iUpdatablePriceFeed.js";
5
4
  import { BaseContract } from "../../base/index.js";
6
5
  import {
7
6
  AP_PRICE_FEED_COMPRESSOR,
@@ -74,48 +73,6 @@ class PriceOracleBaseContract extends BaseContract {
74
73
  }
75
74
  return this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(updatables);
76
75
  }
77
- /**
78
- * Converts previously obtained price updates into CreditFacade multicall entries
79
- * @param creditFacade
80
- * @param updates
81
- * @returns
82
- */
83
- onDemandPriceUpdates(updates) {
84
- const result = [];
85
- if (!updates) {
86
- this.logger?.debug("empty updates list");
87
- return result;
88
- }
89
- const { txs } = updates;
90
- for (const tx of txs) {
91
- const { to: priceFeed, callData, description } = tx.raw;
92
- const [token, reserve] = this.findTokenForPriceFeed(priceFeed);
93
- if (!token) {
94
- const mains = this.mainPriceFeeds.values().map((v) => v.address);
95
- const reserves = this.reservePriceFeeds.values().map((v) => v.address);
96
- this.logger?.debug(
97
- { mainPriceFeeds: mains, reservePriceFeeds: reserves },
98
- `skipping onDemandPriceUpdate ${description}): token not found for price feed ${priceFeed} in oracle ${this.address}`
99
- );
100
- continue;
101
- }
102
- const { args } = decodeFunctionData({
103
- abi: iUpdatablePriceFeedAbi,
104
- data: callData
105
- });
106
- const data = args[0];
107
- result.push({
108
- priceFeed,
109
- token,
110
- reserve,
111
- data
112
- });
113
- }
114
- this.logger?.debug(
115
- `got ${result.length} onDemandPriceUpdates from ${txs.length} txs`
116
- );
117
- return result;
118
- }
119
76
  /**
120
77
  * Gets main price for given token
121
78
  * Throws if token price feed is not found or answer is not successful
@@ -1,5 +1,13 @@
1
+ import {
2
+ decodeFunctionData,
3
+ encodeFunctionData
4
+ } from "viem";
1
5
  import { iPausableAbi } from "../../../abi/iPausable.js";
2
- import { iPriceOracleV300Abi } from "../../../abi/v300.js";
6
+ import { iUpdatablePriceFeedAbi } from "../../../abi/iUpdatablePriceFeed.js";
7
+ import {
8
+ iCreditFacadeV300MulticallAbi,
9
+ iPriceOracleV300Abi
10
+ } from "../../../abi/v300.js";
3
11
  import { tickerInfoTokensByNetwork } from "../../sdk-gov-legacy/index.js";
4
12
  import { PriceOracleBaseContract } from "./PriceOracleBaseContract.js";
5
13
  const abi = [...iPriceOracleV300Abi, ...iPausableAbi];
@@ -27,6 +35,55 @@ class PriceOracleV300Contract extends PriceOracleBaseContract {
27
35
  break;
28
36
  }
29
37
  }
38
+ /**
39
+ * Converts previously obtained price updates into CreditFacade multicall entries
40
+ * @param creditFacade
41
+ * @param updates
42
+ * @returns
43
+ */
44
+ onDemandPriceUpdates(creditFacade, updates) {
45
+ const result = [];
46
+ if (!updates) {
47
+ this.logger?.debug("empty updates list");
48
+ return result;
49
+ }
50
+ const { txs } = updates;
51
+ for (const tx of txs) {
52
+ const { to: priceFeed, callData, description } = tx.raw;
53
+ const [token, reserve] = this.findTokenForPriceFeed(priceFeed);
54
+ if (!token) {
55
+ const mains = this.mainPriceFeeds.values().map((v) => v.address);
56
+ const reserves = this.reservePriceFeeds.values().map((v) => v.address);
57
+ this.logger?.debug(
58
+ { mainPriceFeeds: mains, reservePriceFeeds: reserves },
59
+ `skipping onDemandPriceUpdate ${description}): token not found for price feed ${priceFeed} in oracle ${this.address}`
60
+ );
61
+ continue;
62
+ }
63
+ const { args } = decodeFunctionData({
64
+ abi: iUpdatablePriceFeedAbi,
65
+ data: callData
66
+ });
67
+ const data = args[0];
68
+ if (!data) {
69
+ throw new Error(
70
+ `failed to decode update price args for ${description}`
71
+ );
72
+ }
73
+ result.push({
74
+ target: creditFacade,
75
+ callData: encodeFunctionData({
76
+ abi: iCreditFacadeV300MulticallAbi,
77
+ functionName: "onDemandPriceUpdate",
78
+ args: [token, reserve, data]
79
+ })
80
+ });
81
+ }
82
+ this.logger?.debug(
83
+ `got ${result.length} onDemandPriceUpdates from ${txs.length} txs`
84
+ );
85
+ return result;
86
+ }
30
87
  findTokenForPriceFeed(priceFeed) {
31
88
  const [token, reserve] = super.findTokenForPriceFeed(priceFeed);
32
89
  if (token) {
@@ -1,4 +1,12 @@
1
- import { iPriceOracleV310Abi } from "../../../abi/v310.js";
1
+ import {
2
+ decodeFunctionData,
3
+ encodeFunctionData
4
+ } from "viem";
5
+ import { iUpdatablePriceFeedAbi } from "../../../abi/iUpdatablePriceFeed.js";
6
+ import {
7
+ iCreditFacadeMulticallV310Abi,
8
+ iPriceOracleV310Abi
9
+ } from "../../../abi/v310.js";
2
10
  import { PriceOracleBaseContract } from "./PriceOracleBaseContract.js";
3
11
  const abi = iPriceOracleV310Abi;
4
12
  class PriceOracleV310Contract extends PriceOracleBaseContract {
@@ -13,6 +21,45 @@ class PriceOracleV310Contract extends PriceOracleBaseContract {
13
21
  data
14
22
  );
15
23
  }
24
+ /**
25
+ * Converts previously obtained price updates into CreditFacade multicall entry
26
+ * @param creditFacade
27
+ * @param updates
28
+ * @returns
29
+ */
30
+ onDemandPriceUpdates(creditFacade, updates) {
31
+ if (!updates) {
32
+ this.logger?.debug("empty updates list");
33
+ return [];
34
+ }
35
+ return [
36
+ {
37
+ target: creditFacade,
38
+ callData: encodeFunctionData({
39
+ abi: iCreditFacadeMulticallV310Abi,
40
+ functionName: "onDemandPriceUpdates",
41
+ args: [
42
+ updates.txs.map((u) => {
43
+ const { args } = decodeFunctionData({
44
+ abi: iUpdatablePriceFeedAbi,
45
+ data: u.raw.callData
46
+ });
47
+ const data = args[0];
48
+ if (!data) {
49
+ throw new Error(
50
+ `failed to decode update price args for ${u.raw.description}`
51
+ );
52
+ }
53
+ return {
54
+ priceFeed: u.raw.to,
55
+ data
56
+ };
57
+ })
58
+ ]
59
+ })
60
+ }
61
+ ];
62
+ }
16
63
  processLog(log) {
17
64
  switch (log.eventName) {
18
65
  case "SetPriceFeed":
@@ -2,7 +2,7 @@ import type { Address } from "viem";
2
2
  import type { CreditAccountData } from "../base/index.js";
3
3
  import { SDKConstruct } from "../base/index.js";
4
4
  import type { GearboxSDK } from "../GearboxSDK.js";
5
- import type { OnDemandPriceUpdate, UpdatePriceFeedsResult } from "../market/index.js";
5
+ import type { UpdatePriceFeedsResult } from "../market/index.js";
6
6
  import { type Asset, type RouterCASlice } from "../router/index.js";
7
7
  import type { MultiCall } from "../types/index.js";
8
8
  import type { ClaimDelayedProps, FullyLiquidateProps, GetConnectedBotsResult, StartDelayedWithdrawalProps } from "./types";
@@ -179,12 +179,6 @@ export declare abstract class AbstractCreditAccountService extends SDKConstruct
179
179
  */
180
180
  getUpdateForAccounts(accounts: Array<RouterCASlice>): Promise<UpdatePriceFeedsResult>;
181
181
  protected getUpdateForAccount(creditManager: Address, creditAccount: RouterCASlice | undefined, desiredQuotas: Array<Asset> | undefined): Promise<UpdatePriceFeedsResult>;
182
- /**
183
- * Returns account price updates in a non-encoded format
184
- * @param acc
185
- * @returns
186
- */
187
- getOnDemandPriceUpdates(creditManager: Address, creditAccount: RouterCASlice | undefined, desiredQuotas: Array<Asset> | undefined): Promise<Array<OnDemandPriceUpdate>>;
188
182
  /**
189
183
  * Returns price updates in format that is accepted by various credit facade methods (multicall, close/liquidate, etc...).
190
184
  * - If there are desiredQuotas and creditAccount update quotaBalance > 0 || (balance > 10n && isEnabled). Is used when account has both: balances and quota buys.
@@ -3,7 +3,7 @@ import type { iCreditAccountCompressorAbi } from "../../abi/compressors.js";
3
3
  import type { BotType } from "../../plugins/bots/types.js";
4
4
  import type { ConnectedBotData, CreditAccountData } from "../base/index.js";
5
5
  import type { SDKConstruct } from "../base/SDKConstruct.js";
6
- import type { CreditSuite, OnDemandPriceUpdate, UpdatePriceFeedsResult } from "../market/index.js";
6
+ import type { CreditSuite, UpdatePriceFeedsResult } from "../market/index.js";
7
7
  import type { Asset, RouterCASlice, RouterCloseResult } from "../router/index.js";
8
8
  import type { MultiCall, RawTx } from "../types/index.js";
9
9
  export type GetCreditAccountsArgs = ContractFunctionArgs<typeof iCreditAccountCompressorAbi, "pure" | "view", "getCreditAccounts">;
@@ -492,12 +492,6 @@ export interface ICreditAccountsService extends SDKConstruct {
492
492
  * @returns
493
493
  */
494
494
  getUpdateForAccounts(accounts: Array<RouterCASlice>): Promise<UpdatePriceFeedsResult>;
495
- /**
496
- * Returns account price updates in a non-encoded format
497
- * @param acc
498
- * @returns
499
- */
500
- getOnDemandPriceUpdates(creditManager: Address, creditAccount: RouterCASlice | undefined, desiredQuotas: Array<Asset> | undefined): Promise<Array<OnDemandPriceUpdate>>;
501
495
  /**
502
496
  * Withdraws a single collateral from credit account to wallet to and updates quotas;
503
497
  * technically can withdraw several tokens at once
@@ -3,7 +3,6 @@ import type { CreditFacadeState, CreditSuiteState } from "../../base/index.js";
3
3
  import { BaseContract } from "../../base/index.js";
4
4
  import type { GearboxSDK } from "../../GearboxSDK.js";
5
5
  import type { CreditFacadeStateHuman, MultiCall, RawTx } from "../../types/index.js";
6
- import type { OnDemandPriceUpdate } from "../oracle/index.js";
7
6
  declare const abi: readonly [{
8
7
  readonly type: "function";
9
8
  readonly name: "botList";
@@ -781,7 +780,6 @@ export declare class CreditFacadeV300Contract extends BaseContract<abi> {
781
780
  constructor(sdk: GearboxSDK, { creditFacade, creditManager }: CreditSuiteState);
782
781
  stateHuman(raw?: boolean): CreditFacadeStateHuman;
783
782
  processLog(log: Log<bigint, number, false, undefined, undefined, abi, ContractEventName<abi>>): void;
784
- encodeOnDemandPriceUpdates(updates: OnDemandPriceUpdate[]): MultiCall[];
785
783
  liquidateCreditAccount(ca: Address, to: Address, calls: MultiCall[]): RawTx;
786
784
  closeCreditAccount(ca: Address, calls: MultiCall[]): RawTx;
787
785
  multicall(ca: Address, calls: MultiCall[]): RawTx;
@@ -3,7 +3,6 @@ import type { CreditFacadeState, CreditSuiteState } from "../../base/index.js";
3
3
  import { BaseContract } from "../../base/index.js";
4
4
  import type { GearboxSDK } from "../../GearboxSDK.js";
5
5
  import type { CreditFacadeStateHuman, MultiCall, RawTx } from "../../types/index.js";
6
- import type { OnDemandPriceUpdate } from "../oracle/index.js";
7
6
  declare const abi: readonly [{
8
7
  readonly type: "function";
9
8
  readonly inputs: readonly [];
@@ -854,7 +853,6 @@ export declare class CreditFacadeV310Contract extends BaseContract<abi> {
854
853
  constructor(sdk: GearboxSDK, { creditFacade, creditManager }: CreditSuiteState);
855
854
  stateHuman(raw?: boolean): CreditFacadeStateHuman;
856
855
  processLog(log: Log<bigint, number, false, undefined, undefined, abi, ContractEventName<abi>>): void;
857
- encodeOnDemandPriceUpdates(updates: OnDemandPriceUpdate[]): MultiCall[];
858
856
  liquidateCreditAccount(ca: Address, to: Address, calls: MultiCall[]): RawTx;
859
857
  closeCreditAccount(ca: Address, calls: MultiCall[]): RawTx;
860
858
  multicall(ca: Address, calls: MultiCall[]): RawTx;
@@ -3,12 +3,12 @@ import type { BaseContractOptions } from "../../base/BaseContract.js";
3
3
  import type { PriceOracleData } from "../../base/index.js";
4
4
  import { BaseContract } from "../../base/index.js";
5
5
  import type { GearboxSDK } from "../../GearboxSDK.js";
6
- import type { PriceOracleStateHuman } from "../../types/index.js";
6
+ import type { MultiCall, PriceOracleStateHuman } from "../../types/index.js";
7
7
  import { AddressMap } from "../../utils/index.js";
8
8
  import type { IPriceFeedContract, UpdatePriceFeedsResult } from "../pricefeeds/index.js";
9
9
  import { PriceFeedRef } from "../pricefeeds/index.js";
10
10
  import PriceFeedAnswerMap from "./PriceFeedAnswerMap.js";
11
- import type { DelegatedOracleMulticall, IPriceOracleContract, OnDemandPriceUpdate, PriceFeedsForTokensOptions } from "./types.js";
11
+ import type { DelegatedOracleMulticall, IPriceOracleContract, PriceFeedsForTokensOptions } from "./types.js";
12
12
  export declare abstract class PriceOracleBaseContract<abi extends Abi | readonly unknown[]> extends BaseContract<abi> implements IPriceOracleContract {
13
13
  #private;
14
14
  /**
@@ -40,13 +40,7 @@ export declare abstract class PriceOracleBaseContract<abi extends Abi | readonly
40
40
  * @returns
41
41
  */
42
42
  updatePriceFeeds(): Promise<UpdatePriceFeedsResult>;
43
- /**
44
- * Converts previously obtained price updates into CreditFacade multicall entries
45
- * @param creditFacade
46
- * @param updates
47
- * @returns
48
- */
49
- onDemandPriceUpdates(updates?: UpdatePriceFeedsResult): OnDemandPriceUpdate[];
43
+ abstract onDemandPriceUpdates(creditFacade: Address, updates?: UpdatePriceFeedsResult): MultiCall[];
50
44
  /**
51
45
  * Gets main price for given token
52
46
  * Throws if token price feed is not found or answer is not successful
@@ -1,6 +1,8 @@
1
- import type { Address, ContractEventName, Log } from "viem";
1
+ import { type Address, type ContractEventName, type Log } from "viem";
2
2
  import type { PriceOracleData } from "../../base/index.js";
3
3
  import type { GearboxSDK } from "../../GearboxSDK.js";
4
+ import type { MultiCall } from "../../types/index.js";
5
+ import type { UpdatePriceFeedsResult } from "../pricefeeds/index.js";
4
6
  import { PriceOracleBaseContract } from "./PriceOracleBaseContract.js";
5
7
  declare const abi: ({
6
8
  readonly type: "function";
@@ -355,6 +357,13 @@ type abi = typeof abi;
355
357
  export declare class PriceOracleV300Contract extends PriceOracleBaseContract<abi> {
356
358
  constructor(sdk: GearboxSDK, data: PriceOracleData);
357
359
  processLog(log: Log<bigint, number, false, undefined, undefined, abi, ContractEventName<abi>>): void;
360
+ /**
361
+ * Converts previously obtained price updates into CreditFacade multicall entries
362
+ * @param creditFacade
363
+ * @param updates
364
+ * @returns
365
+ */
366
+ onDemandPriceUpdates(creditFacade: Address, updates?: UpdatePriceFeedsResult): MultiCall[];
358
367
  findTokenForPriceFeed(priceFeed: Address): [token: Address | undefined, reserve: boolean];
359
368
  }
360
369
  export {};
@@ -1,6 +1,8 @@
1
- import type { ContractEventName, Log } from "viem";
1
+ import { type Address, type ContractEventName, type Log } from "viem";
2
2
  import type { PriceOracleData } from "../../base/index.js";
3
3
  import type { GearboxSDK } from "../../GearboxSDK.js";
4
+ import type { MultiCall } from "../../types/index.js";
5
+ import type { UpdatePriceFeedsResult } from "../pricefeeds/index.js";
4
6
  import { PriceOracleBaseContract } from "./PriceOracleBaseContract.js";
5
7
  declare const abi: readonly [{
6
8
  readonly type: "function";
@@ -340,6 +342,13 @@ declare const abi: readonly [{
340
342
  type abi = typeof abi;
341
343
  export declare class PriceOracleV310Contract extends PriceOracleBaseContract<abi> {
342
344
  constructor(sdk: GearboxSDK, data: PriceOracleData);
345
+ /**
346
+ * Converts previously obtained price updates into CreditFacade multicall entry
347
+ * @param creditFacade
348
+ * @param updates
349
+ * @returns
350
+ */
351
+ onDemandPriceUpdates(creditFacade: Address, updates?: UpdatePriceFeedsResult): MultiCall[];
343
352
  processLog(log: Log<bigint, number, false, undefined, undefined, abi, ContractEventName<abi>>): void;
344
353
  }
345
354
  export {};
@@ -1,7 +1,7 @@
1
- import type { Address, ContractFunctionParameters, ContractFunctionReturnType, Hex } from "viem";
1
+ import type { Address, ContractFunctionParameters, ContractFunctionReturnType } from "viem";
2
2
  import type { iPriceFeedCompressorAbi } from "../../../abi/compressors.js";
3
3
  import type { IBaseContract } from "../../base/index.js";
4
- import type { PriceOracleStateHuman } from "../../types/index.js";
4
+ import type { MultiCall, PriceOracleStateHuman } from "../../types/index.js";
5
5
  import type { AddressMap } from "../../utils/index.js";
6
6
  import type { IPriceFeedContract, PriceFeedRef, UpdatePriceFeedsResult } from "../pricefeeds/index.js";
7
7
  import type PriceFeedAnswerMap from "./PriceFeedAnswerMap.js";
@@ -9,16 +9,6 @@ export interface PriceFeedsForTokensOptions {
9
9
  main?: boolean;
10
10
  reserve?: boolean;
11
11
  }
12
- /**
13
- * Data to be passed to credit facade's multicall
14
- * Compatible with both v300 and v310 facades
15
- */
16
- export interface OnDemandPriceUpdate {
17
- priceFeed: Address;
18
- token: Address;
19
- reserve: boolean;
20
- data: Hex;
21
- }
22
12
  export interface IPriceOracleContract extends IBaseContract {
23
13
  mainPriceFeeds: AddressMap<PriceFeedRef>;
24
14
  mainPrices: PriceFeedAnswerMap;
@@ -82,7 +72,7 @@ export interface IPriceOracleContract extends IBaseContract {
82
72
  * @param updates
83
73
  * @returns
84
74
  */
85
- onDemandPriceUpdates: (updates?: UpdatePriceFeedsResult) => OnDemandPriceUpdate[];
75
+ onDemandPriceUpdates: (creditFacade: Address, updates?: UpdatePriceFeedsResult) => MultiCall[];
86
76
  /**
87
77
  * Tries to convert amount of from one token to another, using latest known prices
88
78
  * @param from
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "8.24.8",
3
+ "version": "8.25.1-next.1",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",