@gearbox-protocol/sdk 3.0.0-vfour.63 → 3.0.0-vfour.65
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/cjs/sdk/index.cjs +252 -228
- package/dist/cjs/sdk/index.d.ts +7 -1
- package/dist/esm/sdk/index.d.mts +7 -1
- package/dist/esm/sdk/index.mjs +253 -229
- package/package.json +2 -2
package/dist/cjs/sdk/index.cjs
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
var viem = require('viem');
|
|
4
4
|
var utils = require('viem/utils');
|
|
5
5
|
var dateFns = require('date-fns');
|
|
6
|
-
var chains$1 = require('viem/chains');
|
|
7
|
-
var actions = require('viem/actions');
|
|
8
6
|
var evmConnector = require('@redstone-finance/evm-connector');
|
|
9
7
|
var redstoneProtocol = require('redstone-protocol');
|
|
8
|
+
var chains$1 = require('viem/chains');
|
|
9
|
+
var actions = require('viem/actions');
|
|
10
10
|
var sdkGov = require('@gearbox-protocol/sdk-gov');
|
|
11
11
|
|
|
12
12
|
// src/sdk/accounts/CreditAccountsService.ts
|
|
@@ -20677,203 +20677,6 @@ var PoolFactory = class extends SDKConstruct {
|
|
|
20677
20677
|
};
|
|
20678
20678
|
}
|
|
20679
20679
|
};
|
|
20680
|
-
var SUPPORTED_CHAINS = [
|
|
20681
|
-
"Mainnet",
|
|
20682
|
-
"Arbitrum",
|
|
20683
|
-
"Optimism",
|
|
20684
|
-
"Base"
|
|
20685
|
-
];
|
|
20686
|
-
var chains = {
|
|
20687
|
-
Mainnet: chains$1.mainnet,
|
|
20688
|
-
Arbitrum: chains$1.arbitrum,
|
|
20689
|
-
Optimism: chains$1.optimism,
|
|
20690
|
-
Base: chains$1.base
|
|
20691
|
-
};
|
|
20692
|
-
function createTransport(opts) {
|
|
20693
|
-
const { timeout = 12e4, retryCount } = opts;
|
|
20694
|
-
if ("transport" in opts) {
|
|
20695
|
-
return opts.transport;
|
|
20696
|
-
}
|
|
20697
|
-
const rpcs = opts.rpcURLs.map((url) => viem.http(url, { timeout, retryCount }));
|
|
20698
|
-
return rpcs.length ? viem.fallback(rpcs) : rpcs[0];
|
|
20699
|
-
}
|
|
20700
|
-
var Provider = class {
|
|
20701
|
-
chainId;
|
|
20702
|
-
chain;
|
|
20703
|
-
networkType;
|
|
20704
|
-
publicClient;
|
|
20705
|
-
addressLabels;
|
|
20706
|
-
transport;
|
|
20707
|
-
constructor(opts) {
|
|
20708
|
-
const { chainId, networkType } = opts;
|
|
20709
|
-
this.chainId = chainId;
|
|
20710
|
-
this.networkType = networkType;
|
|
20711
|
-
this.chain = viem.defineChain({
|
|
20712
|
-
...chains[networkType],
|
|
20713
|
-
id: chainId
|
|
20714
|
-
});
|
|
20715
|
-
this.transport = createTransport(opts);
|
|
20716
|
-
this.publicClient = viem.createPublicClient({
|
|
20717
|
-
chain: this.chain,
|
|
20718
|
-
transport: this.transport
|
|
20719
|
-
});
|
|
20720
|
-
this.addressLabels = new AddressLabeller();
|
|
20721
|
-
}
|
|
20722
|
-
};
|
|
20723
|
-
|
|
20724
|
-
// src/sdk/utils/viem/detectNetwork.ts
|
|
20725
|
-
async function detectNetwork(client) {
|
|
20726
|
-
for (const chain of SUPPORTED_CHAINS) {
|
|
20727
|
-
try {
|
|
20728
|
-
await client.readContract({
|
|
20729
|
-
abi: ierc20MetadataAbi,
|
|
20730
|
-
address: USDC[chain],
|
|
20731
|
-
functionName: "symbol"
|
|
20732
|
-
});
|
|
20733
|
-
return chain;
|
|
20734
|
-
} catch {
|
|
20735
|
-
}
|
|
20736
|
-
}
|
|
20737
|
-
throw new Error("Unsupported network");
|
|
20738
|
-
}
|
|
20739
|
-
async function simulateMulticall(client, parameters) {
|
|
20740
|
-
const {
|
|
20741
|
-
account,
|
|
20742
|
-
allowFailure = true,
|
|
20743
|
-
batchSize: batchSize_,
|
|
20744
|
-
blockNumber,
|
|
20745
|
-
blockTag,
|
|
20746
|
-
gas,
|
|
20747
|
-
multicallAddress: multicallAddress_,
|
|
20748
|
-
stateOverride
|
|
20749
|
-
} = parameters;
|
|
20750
|
-
const contracts = parameters.contracts;
|
|
20751
|
-
const batchSize = batchSize_ ?? (typeof client.batch?.multicall === "object" && client.batch.multicall.batchSize || 1024);
|
|
20752
|
-
let multicallAddress = multicallAddress_;
|
|
20753
|
-
if (!multicallAddress) {
|
|
20754
|
-
if (!client.chain)
|
|
20755
|
-
throw new Error(
|
|
20756
|
-
"client chain not configured. multicallAddress is required."
|
|
20757
|
-
);
|
|
20758
|
-
multicallAddress = viem.getChainContractAddress({
|
|
20759
|
-
blockNumber,
|
|
20760
|
-
chain: client.chain,
|
|
20761
|
-
contract: "multicall3"
|
|
20762
|
-
});
|
|
20763
|
-
}
|
|
20764
|
-
const chunkedCalls = [[]];
|
|
20765
|
-
let currentChunk = 0;
|
|
20766
|
-
let currentChunkSize = 0;
|
|
20767
|
-
for (const contract of contracts) {
|
|
20768
|
-
const { abi: abi20, address, args, functionName } = contract;
|
|
20769
|
-
try {
|
|
20770
|
-
const callData = viem.encodeFunctionData({ abi: abi20, args, functionName });
|
|
20771
|
-
currentChunkSize += (callData.length - 2) / 2;
|
|
20772
|
-
if (
|
|
20773
|
-
// Check if batching is enabled.
|
|
20774
|
-
batchSize > 0 && // Check if the current size of the batch exceeds the size limit.
|
|
20775
|
-
currentChunkSize > batchSize && // Check if the current chunk is not already empty.
|
|
20776
|
-
chunkedCalls[currentChunk].length > 0
|
|
20777
|
-
) {
|
|
20778
|
-
currentChunk++;
|
|
20779
|
-
currentChunkSize = (callData.length - 2) / 2;
|
|
20780
|
-
chunkedCalls[currentChunk] = [];
|
|
20781
|
-
}
|
|
20782
|
-
chunkedCalls[currentChunk] = [
|
|
20783
|
-
...chunkedCalls[currentChunk],
|
|
20784
|
-
{
|
|
20785
|
-
allowFailure: true,
|
|
20786
|
-
callData,
|
|
20787
|
-
target: address
|
|
20788
|
-
}
|
|
20789
|
-
];
|
|
20790
|
-
} catch (err) {
|
|
20791
|
-
const error = viem.getContractError(err, {
|
|
20792
|
-
abi: abi20,
|
|
20793
|
-
address,
|
|
20794
|
-
args,
|
|
20795
|
-
docsPath: "/docs/contract/multicall",
|
|
20796
|
-
functionName
|
|
20797
|
-
});
|
|
20798
|
-
if (!allowFailure) throw error;
|
|
20799
|
-
chunkedCalls[currentChunk] = [
|
|
20800
|
-
...chunkedCalls[currentChunk],
|
|
20801
|
-
{
|
|
20802
|
-
allowFailure: true,
|
|
20803
|
-
callData: "0x",
|
|
20804
|
-
target: address
|
|
20805
|
-
}
|
|
20806
|
-
];
|
|
20807
|
-
}
|
|
20808
|
-
}
|
|
20809
|
-
const aggregate3Results = await Promise.allSettled(
|
|
20810
|
-
chunkedCalls.map(
|
|
20811
|
-
(calls) => utils.getAction(
|
|
20812
|
-
client,
|
|
20813
|
-
actions.simulateContract,
|
|
20814
|
-
"simulateContract"
|
|
20815
|
-
)({
|
|
20816
|
-
account,
|
|
20817
|
-
abi: viem.multicall3Abi,
|
|
20818
|
-
address: multicallAddress,
|
|
20819
|
-
args: [calls],
|
|
20820
|
-
blockNumber,
|
|
20821
|
-
blockTag,
|
|
20822
|
-
// does not infer well that either blockNumber or blockTag must be present
|
|
20823
|
-
functionName: "aggregate3",
|
|
20824
|
-
stateOverride,
|
|
20825
|
-
gas
|
|
20826
|
-
})
|
|
20827
|
-
)
|
|
20828
|
-
);
|
|
20829
|
-
const results = [];
|
|
20830
|
-
for (let i = 0; i < aggregate3Results.length; i++) {
|
|
20831
|
-
const result = aggregate3Results[i];
|
|
20832
|
-
if (result.status === "rejected") {
|
|
20833
|
-
if (!allowFailure) {
|
|
20834
|
-
throw result.reason;
|
|
20835
|
-
}
|
|
20836
|
-
for (const _i of chunkedCalls[i]) {
|
|
20837
|
-
results.push({
|
|
20838
|
-
status: "failure",
|
|
20839
|
-
error: result.reason,
|
|
20840
|
-
result: void 0
|
|
20841
|
-
});
|
|
20842
|
-
}
|
|
20843
|
-
continue;
|
|
20844
|
-
}
|
|
20845
|
-
const aggregate3Result = result.value.result;
|
|
20846
|
-
for (let j = 0; j < aggregate3Result.length; j++) {
|
|
20847
|
-
const { returnData, success } = aggregate3Result[j];
|
|
20848
|
-
const { callData } = chunkedCalls[i][j];
|
|
20849
|
-
const { abi: abi20, address, functionName, args } = contracts[results.length];
|
|
20850
|
-
try {
|
|
20851
|
-
if (callData === "0x") throw new viem.AbiDecodingZeroDataError();
|
|
20852
|
-
if (!success) throw new viem.RawContractError({ data: returnData });
|
|
20853
|
-
const result2 = viem.decodeFunctionResult({
|
|
20854
|
-
abi: abi20,
|
|
20855
|
-
args,
|
|
20856
|
-
data: returnData,
|
|
20857
|
-
functionName
|
|
20858
|
-
});
|
|
20859
|
-
results.push(allowFailure ? { result: result2, status: "success" } : result2);
|
|
20860
|
-
} catch (err) {
|
|
20861
|
-
const error = viem.getContractError(err, {
|
|
20862
|
-
abi: abi20,
|
|
20863
|
-
address,
|
|
20864
|
-
args,
|
|
20865
|
-
docsPath: "/docs/contract/multicall",
|
|
20866
|
-
functionName
|
|
20867
|
-
});
|
|
20868
|
-
if (!allowFailure) throw error;
|
|
20869
|
-
results.push({ error, result: void 0, status: "failure" });
|
|
20870
|
-
}
|
|
20871
|
-
}
|
|
20872
|
-
}
|
|
20873
|
-
if (results.length !== contracts.length)
|
|
20874
|
-
throw new viem.BaseError("multicall results mismatch");
|
|
20875
|
-
return results;
|
|
20876
|
-
}
|
|
20877
20680
|
|
|
20878
20681
|
// src/sdk/market/pricefeeds/PriceFeedRef.ts
|
|
20879
20682
|
var PriceFeedRef = class extends SDKConstruct {
|
|
@@ -21774,33 +21577,7 @@ var PriceOracleContract = class extends BaseContract {
|
|
|
21774
21577
|
* Does not update price feeds, only updates prices
|
|
21775
21578
|
*/
|
|
21776
21579
|
async updatePrices() {
|
|
21777
|
-
|
|
21778
|
-
const resp = await simulateMulticall(this.provider.publicClient, {
|
|
21779
|
-
contracts: [
|
|
21780
|
-
...txs.map(rawTxToMulticallPriceUpdate),
|
|
21781
|
-
{
|
|
21782
|
-
abi: iPriceFeedCompressorAbi,
|
|
21783
|
-
address: this.sdk.addressProvider.getLatestVersion(
|
|
21784
|
-
AP_PRICE_FEED_COMPRESSOR
|
|
21785
|
-
),
|
|
21786
|
-
functionName: "getPriceFeeds",
|
|
21787
|
-
args: [this.address]
|
|
21788
|
-
}
|
|
21789
|
-
],
|
|
21790
|
-
allowFailure: false,
|
|
21791
|
-
gas: 550000000n,
|
|
21792
|
-
batchSize: 0
|
|
21793
|
-
// we cannot have price updates and compressor request in different batches
|
|
21794
|
-
});
|
|
21795
|
-
const [entries, tree] = resp.pop();
|
|
21796
|
-
entries.forEach(({ token, priceFeed, reserve }) => {
|
|
21797
|
-
const price = tree.find((n) => n.baseParams.addr === priceFeed)?.answer?.price;
|
|
21798
|
-
if (reserve && price) {
|
|
21799
|
-
this.reservePrices.upsert(token, price);
|
|
21800
|
-
} else if (price) {
|
|
21801
|
-
this.mainPrices.upsert(token, price);
|
|
21802
|
-
}
|
|
21803
|
-
});
|
|
21580
|
+
await this.sdk.marketRegister.updatePrices([this.address]);
|
|
21804
21581
|
}
|
|
21805
21582
|
#labelPriceFeed(address, usage, token) {
|
|
21806
21583
|
this.sdk.provider.addressLabels.set(address, (label) => {
|
|
@@ -21919,6 +21696,203 @@ var MarketFactory = class extends SDKConstruct {
|
|
|
21919
21696
|
};
|
|
21920
21697
|
}
|
|
21921
21698
|
};
|
|
21699
|
+
var SUPPORTED_CHAINS = [
|
|
21700
|
+
"Mainnet",
|
|
21701
|
+
"Arbitrum",
|
|
21702
|
+
"Optimism",
|
|
21703
|
+
"Base"
|
|
21704
|
+
];
|
|
21705
|
+
var chains = {
|
|
21706
|
+
Mainnet: chains$1.mainnet,
|
|
21707
|
+
Arbitrum: chains$1.arbitrum,
|
|
21708
|
+
Optimism: chains$1.optimism,
|
|
21709
|
+
Base: chains$1.base
|
|
21710
|
+
};
|
|
21711
|
+
function createTransport(opts) {
|
|
21712
|
+
const { timeout = 12e4, retryCount } = opts;
|
|
21713
|
+
if ("transport" in opts) {
|
|
21714
|
+
return opts.transport;
|
|
21715
|
+
}
|
|
21716
|
+
const rpcs = opts.rpcURLs.map((url) => viem.http(url, { timeout, retryCount }));
|
|
21717
|
+
return rpcs.length ? viem.fallback(rpcs) : rpcs[0];
|
|
21718
|
+
}
|
|
21719
|
+
var Provider = class {
|
|
21720
|
+
chainId;
|
|
21721
|
+
chain;
|
|
21722
|
+
networkType;
|
|
21723
|
+
publicClient;
|
|
21724
|
+
addressLabels;
|
|
21725
|
+
transport;
|
|
21726
|
+
constructor(opts) {
|
|
21727
|
+
const { chainId, networkType } = opts;
|
|
21728
|
+
this.chainId = chainId;
|
|
21729
|
+
this.networkType = networkType;
|
|
21730
|
+
this.chain = viem.defineChain({
|
|
21731
|
+
...chains[networkType],
|
|
21732
|
+
id: chainId
|
|
21733
|
+
});
|
|
21734
|
+
this.transport = createTransport(opts);
|
|
21735
|
+
this.publicClient = viem.createPublicClient({
|
|
21736
|
+
chain: this.chain,
|
|
21737
|
+
transport: this.transport
|
|
21738
|
+
});
|
|
21739
|
+
this.addressLabels = new AddressLabeller();
|
|
21740
|
+
}
|
|
21741
|
+
};
|
|
21742
|
+
|
|
21743
|
+
// src/sdk/utils/viem/detectNetwork.ts
|
|
21744
|
+
async function detectNetwork(client) {
|
|
21745
|
+
for (const chain of SUPPORTED_CHAINS) {
|
|
21746
|
+
try {
|
|
21747
|
+
await client.readContract({
|
|
21748
|
+
abi: ierc20MetadataAbi,
|
|
21749
|
+
address: USDC[chain],
|
|
21750
|
+
functionName: "symbol"
|
|
21751
|
+
});
|
|
21752
|
+
return chain;
|
|
21753
|
+
} catch {
|
|
21754
|
+
}
|
|
21755
|
+
}
|
|
21756
|
+
throw new Error("Unsupported network");
|
|
21757
|
+
}
|
|
21758
|
+
async function simulateMulticall(client, parameters) {
|
|
21759
|
+
const {
|
|
21760
|
+
account,
|
|
21761
|
+
allowFailure = true,
|
|
21762
|
+
batchSize: batchSize_,
|
|
21763
|
+
blockNumber,
|
|
21764
|
+
blockTag,
|
|
21765
|
+
gas,
|
|
21766
|
+
multicallAddress: multicallAddress_,
|
|
21767
|
+
stateOverride
|
|
21768
|
+
} = parameters;
|
|
21769
|
+
const contracts = parameters.contracts;
|
|
21770
|
+
const batchSize = batchSize_ ?? (typeof client.batch?.multicall === "object" && client.batch.multicall.batchSize || 1024);
|
|
21771
|
+
let multicallAddress = multicallAddress_;
|
|
21772
|
+
if (!multicallAddress) {
|
|
21773
|
+
if (!client.chain)
|
|
21774
|
+
throw new Error(
|
|
21775
|
+
"client chain not configured. multicallAddress is required."
|
|
21776
|
+
);
|
|
21777
|
+
multicallAddress = viem.getChainContractAddress({
|
|
21778
|
+
blockNumber,
|
|
21779
|
+
chain: client.chain,
|
|
21780
|
+
contract: "multicall3"
|
|
21781
|
+
});
|
|
21782
|
+
}
|
|
21783
|
+
const chunkedCalls = [[]];
|
|
21784
|
+
let currentChunk = 0;
|
|
21785
|
+
let currentChunkSize = 0;
|
|
21786
|
+
for (const contract of contracts) {
|
|
21787
|
+
const { abi: abi20, address, args, functionName } = contract;
|
|
21788
|
+
try {
|
|
21789
|
+
const callData = viem.encodeFunctionData({ abi: abi20, args, functionName });
|
|
21790
|
+
currentChunkSize += (callData.length - 2) / 2;
|
|
21791
|
+
if (
|
|
21792
|
+
// Check if batching is enabled.
|
|
21793
|
+
batchSize > 0 && // Check if the current size of the batch exceeds the size limit.
|
|
21794
|
+
currentChunkSize > batchSize && // Check if the current chunk is not already empty.
|
|
21795
|
+
chunkedCalls[currentChunk].length > 0
|
|
21796
|
+
) {
|
|
21797
|
+
currentChunk++;
|
|
21798
|
+
currentChunkSize = (callData.length - 2) / 2;
|
|
21799
|
+
chunkedCalls[currentChunk] = [];
|
|
21800
|
+
}
|
|
21801
|
+
chunkedCalls[currentChunk] = [
|
|
21802
|
+
...chunkedCalls[currentChunk],
|
|
21803
|
+
{
|
|
21804
|
+
allowFailure: true,
|
|
21805
|
+
callData,
|
|
21806
|
+
target: address
|
|
21807
|
+
}
|
|
21808
|
+
];
|
|
21809
|
+
} catch (err) {
|
|
21810
|
+
const error = viem.getContractError(err, {
|
|
21811
|
+
abi: abi20,
|
|
21812
|
+
address,
|
|
21813
|
+
args,
|
|
21814
|
+
docsPath: "/docs/contract/multicall",
|
|
21815
|
+
functionName
|
|
21816
|
+
});
|
|
21817
|
+
if (!allowFailure) throw error;
|
|
21818
|
+
chunkedCalls[currentChunk] = [
|
|
21819
|
+
...chunkedCalls[currentChunk],
|
|
21820
|
+
{
|
|
21821
|
+
allowFailure: true,
|
|
21822
|
+
callData: "0x",
|
|
21823
|
+
target: address
|
|
21824
|
+
}
|
|
21825
|
+
];
|
|
21826
|
+
}
|
|
21827
|
+
}
|
|
21828
|
+
const aggregate3Results = await Promise.allSettled(
|
|
21829
|
+
chunkedCalls.map(
|
|
21830
|
+
(calls) => utils.getAction(
|
|
21831
|
+
client,
|
|
21832
|
+
actions.simulateContract,
|
|
21833
|
+
"simulateContract"
|
|
21834
|
+
)({
|
|
21835
|
+
account,
|
|
21836
|
+
abi: viem.multicall3Abi,
|
|
21837
|
+
address: multicallAddress,
|
|
21838
|
+
args: [calls],
|
|
21839
|
+
blockNumber,
|
|
21840
|
+
blockTag,
|
|
21841
|
+
// does not infer well that either blockNumber or blockTag must be present
|
|
21842
|
+
functionName: "aggregate3",
|
|
21843
|
+
stateOverride,
|
|
21844
|
+
gas
|
|
21845
|
+
})
|
|
21846
|
+
)
|
|
21847
|
+
);
|
|
21848
|
+
const results = [];
|
|
21849
|
+
for (let i = 0; i < aggregate3Results.length; i++) {
|
|
21850
|
+
const result = aggregate3Results[i];
|
|
21851
|
+
if (result.status === "rejected") {
|
|
21852
|
+
if (!allowFailure) {
|
|
21853
|
+
throw result.reason;
|
|
21854
|
+
}
|
|
21855
|
+
for (const _i of chunkedCalls[i]) {
|
|
21856
|
+
results.push({
|
|
21857
|
+
status: "failure",
|
|
21858
|
+
error: result.reason,
|
|
21859
|
+
result: void 0
|
|
21860
|
+
});
|
|
21861
|
+
}
|
|
21862
|
+
continue;
|
|
21863
|
+
}
|
|
21864
|
+
const aggregate3Result = result.value.result;
|
|
21865
|
+
for (let j = 0; j < aggregate3Result.length; j++) {
|
|
21866
|
+
const { returnData, success } = aggregate3Result[j];
|
|
21867
|
+
const { callData } = chunkedCalls[i][j];
|
|
21868
|
+
const { abi: abi20, address, functionName, args } = contracts[results.length];
|
|
21869
|
+
try {
|
|
21870
|
+
if (callData === "0x") throw new viem.AbiDecodingZeroDataError();
|
|
21871
|
+
if (!success) throw new viem.RawContractError({ data: returnData });
|
|
21872
|
+
const result2 = viem.decodeFunctionResult({
|
|
21873
|
+
abi: abi20,
|
|
21874
|
+
args,
|
|
21875
|
+
data: returnData,
|
|
21876
|
+
functionName
|
|
21877
|
+
});
|
|
21878
|
+
results.push(allowFailure ? { result: result2, status: "success" } : result2);
|
|
21879
|
+
} catch (err) {
|
|
21880
|
+
const error = viem.getContractError(err, {
|
|
21881
|
+
abi: abi20,
|
|
21882
|
+
address,
|
|
21883
|
+
args,
|
|
21884
|
+
docsPath: "/docs/contract/multicall",
|
|
21885
|
+
functionName
|
|
21886
|
+
});
|
|
21887
|
+
if (!allowFailure) throw error;
|
|
21888
|
+
results.push({ error, result: void 0, status: "failure" });
|
|
21889
|
+
}
|
|
21890
|
+
}
|
|
21891
|
+
}
|
|
21892
|
+
if (results.length !== contracts.length)
|
|
21893
|
+
throw new viem.BaseError("multicall results mismatch");
|
|
21894
|
+
return results;
|
|
21895
|
+
}
|
|
21922
21896
|
|
|
21923
21897
|
// src/sdk/market/MarketConfiguratorContract.ts
|
|
21924
21898
|
var abi19 = iMarketConfiguratorV310Abi;
|
|
@@ -22011,6 +21985,48 @@ var MarketRegister = class extends SDKConstruct {
|
|
|
22011
21985
|
}
|
|
22012
21986
|
this.#logger?.info(`loaded ${markets.length} markets`);
|
|
22013
21987
|
}
|
|
21988
|
+
/**
|
|
21989
|
+
* Loads new prices for given oracles from PriceFeedCompressor, defaults to all oracles
|
|
21990
|
+
* Does not update price feeds, only updates prices
|
|
21991
|
+
*/
|
|
21992
|
+
async updatePrices(oracles) {
|
|
21993
|
+
const oraclez = oracles ?? this.markets.map((m) => m.priceOracle.address);
|
|
21994
|
+
if (!oraclez.length) {
|
|
21995
|
+
return;
|
|
21996
|
+
}
|
|
21997
|
+
const { txs } = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs();
|
|
21998
|
+
const resp = await simulateMulticall(this.provider.publicClient, {
|
|
21999
|
+
contracts: [
|
|
22000
|
+
...txs.map(rawTxToMulticallPriceUpdate),
|
|
22001
|
+
...oraclez.map((o) => ({
|
|
22002
|
+
abi: iPriceFeedCompressorAbi,
|
|
22003
|
+
address: this.sdk.addressProvider.getLatestVersion(
|
|
22004
|
+
AP_PRICE_FEED_COMPRESSOR
|
|
22005
|
+
),
|
|
22006
|
+
functionName: "getPriceFeeds",
|
|
22007
|
+
args: [o]
|
|
22008
|
+
}))
|
|
22009
|
+
],
|
|
22010
|
+
allowFailure: false,
|
|
22011
|
+
gas: 550000000n,
|
|
22012
|
+
batchSize: 0
|
|
22013
|
+
// we cannot have price updates and compressor request in different batches
|
|
22014
|
+
});
|
|
22015
|
+
const oraclesStates = resp.slice(txs.length);
|
|
22016
|
+
for (let i = 0; i < oraclez.length; i++) {
|
|
22017
|
+
const oracleAddr = oraclez[i];
|
|
22018
|
+
const oracle = this.findPriceOracle(oracleAddr);
|
|
22019
|
+
const [entries, tree] = oraclesStates[i];
|
|
22020
|
+
for (const { token, priceFeed, reserve } of entries) {
|
|
22021
|
+
const price = tree.find((n) => n.baseParams.addr === priceFeed)?.answer?.price;
|
|
22022
|
+
if (reserve && price) {
|
|
22023
|
+
oracle.reservePrices.upsert(token, price);
|
|
22024
|
+
} else if (price) {
|
|
22025
|
+
oracle.mainPrices.upsert(token, price);
|
|
22026
|
+
}
|
|
22027
|
+
}
|
|
22028
|
+
}
|
|
22029
|
+
}
|
|
22014
22030
|
get state() {
|
|
22015
22031
|
return this.markets.map((market) => market.state);
|
|
22016
22032
|
}
|
|
@@ -22033,6 +22049,14 @@ var MarketRegister = class extends SDKConstruct {
|
|
|
22033
22049
|
}
|
|
22034
22050
|
throw new Error(`cannot find credit manager ${creditManager}`);
|
|
22035
22051
|
}
|
|
22052
|
+
findPriceOracle(address) {
|
|
22053
|
+
for (const market of this.markets) {
|
|
22054
|
+
if (market.priceOracle.address.toLowerCase() === address.toLowerCase()) {
|
|
22055
|
+
return market.priceOracle;
|
|
22056
|
+
}
|
|
22057
|
+
}
|
|
22058
|
+
throw new Error(`cannot find price oracle ${address}`);
|
|
22059
|
+
}
|
|
22036
22060
|
findByCreditManager(creditManager) {
|
|
22037
22061
|
const market = this.markets.find(
|
|
22038
22062
|
(m) => m.creditManagers.some(
|
|
@@ -22434,7 +22458,7 @@ var AddressProviderContractV3_1 = class extends BaseContract {
|
|
|
22434
22458
|
);
|
|
22435
22459
|
return this.getAddress(contract, this.latest[contract]);
|
|
22436
22460
|
}
|
|
22437
|
-
async
|
|
22461
|
+
async syncState(blockNumber) {
|
|
22438
22462
|
const entries = await this.contract.read.getAllSavedContracts({
|
|
22439
22463
|
blockNumber
|
|
22440
22464
|
});
|
|
@@ -22999,7 +23023,7 @@ var GearboxSDK = class _GearboxSDK {
|
|
|
22999
23023
|
this,
|
|
23000
23024
|
addressProviderAddress
|
|
23001
23025
|
);
|
|
23002
|
-
await this.#addressProvider.
|
|
23026
|
+
await this.#addressProvider.syncState(this.currentBlock);
|
|
23003
23027
|
const botListAddress = this.#addressProvider.getAddress(AP_BOT_LIST, 300);
|
|
23004
23028
|
this.#botListContract = new BotListContract(this, botListAddress);
|
|
23005
23029
|
this.#gear = this.#addressProvider.getAddress(AP_GEAR_TOKEN);
|
package/dist/cjs/sdk/index.d.ts
CHANGED
|
@@ -24222,11 +24222,17 @@ declare class MarketRegister extends SDKConstruct {
|
|
|
24222
24222
|
constructor(sdk: GearboxSDK);
|
|
24223
24223
|
loadMarkets(curators: Address[]): Promise<void>;
|
|
24224
24224
|
syncState(): Promise<void>;
|
|
24225
|
+
/**
|
|
24226
|
+
* Loads new prices for given oracles from PriceFeedCompressor, defaults to all oracles
|
|
24227
|
+
* Does not update price feeds, only updates prices
|
|
24228
|
+
*/
|
|
24229
|
+
updatePrices(oracles?: Address[]): Promise<void>;
|
|
24225
24230
|
get state(): MarketData[];
|
|
24226
24231
|
stateHuman(raw?: boolean): MarketStateHuman[];
|
|
24227
24232
|
get pools(): PoolFactory[];
|
|
24228
24233
|
get creditManagers(): CreditFactory[];
|
|
24229
24234
|
findCreditManager(creditManager: Address): CreditFactory;
|
|
24235
|
+
findPriceOracle(address: Address): PriceOracleContract;
|
|
24230
24236
|
findByCreditManager(creditManager: Address): MarketFactory;
|
|
24231
24237
|
get markets(): MarketFactory[];
|
|
24232
24238
|
tvl(): Promise<TVL>;
|
|
@@ -24426,7 +24432,7 @@ declare class AddressProviderContractV3_1 extends BaseContract<abi$3> {
|
|
|
24426
24432
|
protected setInternalAddress(key: string, address: Address, version: number): void;
|
|
24427
24433
|
getAddress(contract: string, version?: number): Address;
|
|
24428
24434
|
getLatestVersion(contract: string): Address;
|
|
24429
|
-
|
|
24435
|
+
syncState(blockNumber?: bigint): Promise<void>;
|
|
24430
24436
|
stateHuman(raw?: boolean): AddressProviderV3StateHuman;
|
|
24431
24437
|
processLog(log: Log<bigint, number, false, undefined, undefined, abi$3, ContractEventName<abi$3>>): void;
|
|
24432
24438
|
}
|
package/dist/esm/sdk/index.d.mts
CHANGED
|
@@ -24222,11 +24222,17 @@ declare class MarketRegister extends SDKConstruct {
|
|
|
24222
24222
|
constructor(sdk: GearboxSDK);
|
|
24223
24223
|
loadMarkets(curators: Address[]): Promise<void>;
|
|
24224
24224
|
syncState(): Promise<void>;
|
|
24225
|
+
/**
|
|
24226
|
+
* Loads new prices for given oracles from PriceFeedCompressor, defaults to all oracles
|
|
24227
|
+
* Does not update price feeds, only updates prices
|
|
24228
|
+
*/
|
|
24229
|
+
updatePrices(oracles?: Address[]): Promise<void>;
|
|
24225
24230
|
get state(): MarketData[];
|
|
24226
24231
|
stateHuman(raw?: boolean): MarketStateHuman[];
|
|
24227
24232
|
get pools(): PoolFactory[];
|
|
24228
24233
|
get creditManagers(): CreditFactory[];
|
|
24229
24234
|
findCreditManager(creditManager: Address): CreditFactory;
|
|
24235
|
+
findPriceOracle(address: Address): PriceOracleContract;
|
|
24230
24236
|
findByCreditManager(creditManager: Address): MarketFactory;
|
|
24231
24237
|
get markets(): MarketFactory[];
|
|
24232
24238
|
tvl(): Promise<TVL>;
|
|
@@ -24426,7 +24432,7 @@ declare class AddressProviderContractV3_1 extends BaseContract<abi$3> {
|
|
|
24426
24432
|
protected setInternalAddress(key: string, address: Address, version: number): void;
|
|
24427
24433
|
getAddress(contract: string, version?: number): Address;
|
|
24428
24434
|
getLatestVersion(contract: string): Address;
|
|
24429
|
-
|
|
24435
|
+
syncState(blockNumber?: bigint): Promise<void>;
|
|
24430
24436
|
stateHuman(raw?: boolean): AddressProviderV3StateHuman;
|
|
24431
24437
|
processLog(log: Log<bigint, number, false, undefined, undefined, abi$3, ContractEventName<abi$3>>): void;
|
|
24432
24438
|
}
|
package/dist/esm/sdk/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { isAddress, bytesToString, toBytes, prepareEncodeFunctionData, encodeAbiParameters, concatHex, getContract, isHex, decodeFunctionData, encodeFunctionData, decodeAbiParameters, http, fallback, defineChain, createPublicClient, getChainContractAddress, getContractError, multicall3Abi, AbiDecodingZeroDataError, RawContractError, decodeFunctionResult, BaseError,
|
|
1
|
+
import { isAddress, bytesToString, toBytes, prepareEncodeFunctionData, encodeAbiParameters, concatHex, getContract, isHex, decodeFunctionData, encodeFunctionData, decodeAbiParameters, erc4626Abi, http, fallback, defineChain, createPublicClient, getChainContractAddress, getContractError, multicall3Abi, AbiDecodingZeroDataError, RawContractError, decodeFunctionResult, BaseError, parseEventLogs, hexToBytes } from 'viem';
|
|
2
2
|
import { formatAbiItem, getAction } from 'viem/utils';
|
|
3
3
|
import { intervalToDuration, formatDuration as formatDuration$1 } from 'date-fns';
|
|
4
|
-
import { mainnet, arbitrum, optimism, base } from 'viem/chains';
|
|
5
|
-
import { simulateContract } from 'viem/actions';
|
|
6
4
|
import { DataServiceWrapper } from '@redstone-finance/evm-connector';
|
|
7
5
|
import { RedstonePayload } from 'redstone-protocol';
|
|
6
|
+
import { mainnet, arbitrum, optimism, base } from 'viem/chains';
|
|
7
|
+
import { simulateContract } from 'viem/actions';
|
|
8
8
|
import { getConnectors, tokenDataByNetwork, contractParams, curveTokens, balancerLpTokens, getTokenSymbol, isCurveLPToken, yearnTokens, convexTokens, isBalancerLPToken, auraTokens } from '@gearbox-protocol/sdk-gov';
|
|
9
9
|
|
|
10
10
|
// src/sdk/accounts/CreditAccountsService.ts
|
|
@@ -20675,203 +20675,6 @@ var PoolFactory = class extends SDKConstruct {
|
|
|
20675
20675
|
};
|
|
20676
20676
|
}
|
|
20677
20677
|
};
|
|
20678
|
-
var SUPPORTED_CHAINS = [
|
|
20679
|
-
"Mainnet",
|
|
20680
|
-
"Arbitrum",
|
|
20681
|
-
"Optimism",
|
|
20682
|
-
"Base"
|
|
20683
|
-
];
|
|
20684
|
-
var chains = {
|
|
20685
|
-
Mainnet: mainnet,
|
|
20686
|
-
Arbitrum: arbitrum,
|
|
20687
|
-
Optimism: optimism,
|
|
20688
|
-
Base: base
|
|
20689
|
-
};
|
|
20690
|
-
function createTransport(opts) {
|
|
20691
|
-
const { timeout = 12e4, retryCount } = opts;
|
|
20692
|
-
if ("transport" in opts) {
|
|
20693
|
-
return opts.transport;
|
|
20694
|
-
}
|
|
20695
|
-
const rpcs = opts.rpcURLs.map((url) => http(url, { timeout, retryCount }));
|
|
20696
|
-
return rpcs.length ? fallback(rpcs) : rpcs[0];
|
|
20697
|
-
}
|
|
20698
|
-
var Provider = class {
|
|
20699
|
-
chainId;
|
|
20700
|
-
chain;
|
|
20701
|
-
networkType;
|
|
20702
|
-
publicClient;
|
|
20703
|
-
addressLabels;
|
|
20704
|
-
transport;
|
|
20705
|
-
constructor(opts) {
|
|
20706
|
-
const { chainId, networkType } = opts;
|
|
20707
|
-
this.chainId = chainId;
|
|
20708
|
-
this.networkType = networkType;
|
|
20709
|
-
this.chain = defineChain({
|
|
20710
|
-
...chains[networkType],
|
|
20711
|
-
id: chainId
|
|
20712
|
-
});
|
|
20713
|
-
this.transport = createTransport(opts);
|
|
20714
|
-
this.publicClient = createPublicClient({
|
|
20715
|
-
chain: this.chain,
|
|
20716
|
-
transport: this.transport
|
|
20717
|
-
});
|
|
20718
|
-
this.addressLabels = new AddressLabeller();
|
|
20719
|
-
}
|
|
20720
|
-
};
|
|
20721
|
-
|
|
20722
|
-
// src/sdk/utils/viem/detectNetwork.ts
|
|
20723
|
-
async function detectNetwork(client) {
|
|
20724
|
-
for (const chain of SUPPORTED_CHAINS) {
|
|
20725
|
-
try {
|
|
20726
|
-
await client.readContract({
|
|
20727
|
-
abi: ierc20MetadataAbi,
|
|
20728
|
-
address: USDC[chain],
|
|
20729
|
-
functionName: "symbol"
|
|
20730
|
-
});
|
|
20731
|
-
return chain;
|
|
20732
|
-
} catch {
|
|
20733
|
-
}
|
|
20734
|
-
}
|
|
20735
|
-
throw new Error("Unsupported network");
|
|
20736
|
-
}
|
|
20737
|
-
async function simulateMulticall(client, parameters) {
|
|
20738
|
-
const {
|
|
20739
|
-
account,
|
|
20740
|
-
allowFailure = true,
|
|
20741
|
-
batchSize: batchSize_,
|
|
20742
|
-
blockNumber,
|
|
20743
|
-
blockTag,
|
|
20744
|
-
gas,
|
|
20745
|
-
multicallAddress: multicallAddress_,
|
|
20746
|
-
stateOverride
|
|
20747
|
-
} = parameters;
|
|
20748
|
-
const contracts = parameters.contracts;
|
|
20749
|
-
const batchSize = batchSize_ ?? (typeof client.batch?.multicall === "object" && client.batch.multicall.batchSize || 1024);
|
|
20750
|
-
let multicallAddress = multicallAddress_;
|
|
20751
|
-
if (!multicallAddress) {
|
|
20752
|
-
if (!client.chain)
|
|
20753
|
-
throw new Error(
|
|
20754
|
-
"client chain not configured. multicallAddress is required."
|
|
20755
|
-
);
|
|
20756
|
-
multicallAddress = getChainContractAddress({
|
|
20757
|
-
blockNumber,
|
|
20758
|
-
chain: client.chain,
|
|
20759
|
-
contract: "multicall3"
|
|
20760
|
-
});
|
|
20761
|
-
}
|
|
20762
|
-
const chunkedCalls = [[]];
|
|
20763
|
-
let currentChunk = 0;
|
|
20764
|
-
let currentChunkSize = 0;
|
|
20765
|
-
for (const contract of contracts) {
|
|
20766
|
-
const { abi: abi20, address, args, functionName } = contract;
|
|
20767
|
-
try {
|
|
20768
|
-
const callData = encodeFunctionData({ abi: abi20, args, functionName });
|
|
20769
|
-
currentChunkSize += (callData.length - 2) / 2;
|
|
20770
|
-
if (
|
|
20771
|
-
// Check if batching is enabled.
|
|
20772
|
-
batchSize > 0 && // Check if the current size of the batch exceeds the size limit.
|
|
20773
|
-
currentChunkSize > batchSize && // Check if the current chunk is not already empty.
|
|
20774
|
-
chunkedCalls[currentChunk].length > 0
|
|
20775
|
-
) {
|
|
20776
|
-
currentChunk++;
|
|
20777
|
-
currentChunkSize = (callData.length - 2) / 2;
|
|
20778
|
-
chunkedCalls[currentChunk] = [];
|
|
20779
|
-
}
|
|
20780
|
-
chunkedCalls[currentChunk] = [
|
|
20781
|
-
...chunkedCalls[currentChunk],
|
|
20782
|
-
{
|
|
20783
|
-
allowFailure: true,
|
|
20784
|
-
callData,
|
|
20785
|
-
target: address
|
|
20786
|
-
}
|
|
20787
|
-
];
|
|
20788
|
-
} catch (err) {
|
|
20789
|
-
const error = getContractError(err, {
|
|
20790
|
-
abi: abi20,
|
|
20791
|
-
address,
|
|
20792
|
-
args,
|
|
20793
|
-
docsPath: "/docs/contract/multicall",
|
|
20794
|
-
functionName
|
|
20795
|
-
});
|
|
20796
|
-
if (!allowFailure) throw error;
|
|
20797
|
-
chunkedCalls[currentChunk] = [
|
|
20798
|
-
...chunkedCalls[currentChunk],
|
|
20799
|
-
{
|
|
20800
|
-
allowFailure: true,
|
|
20801
|
-
callData: "0x",
|
|
20802
|
-
target: address
|
|
20803
|
-
}
|
|
20804
|
-
];
|
|
20805
|
-
}
|
|
20806
|
-
}
|
|
20807
|
-
const aggregate3Results = await Promise.allSettled(
|
|
20808
|
-
chunkedCalls.map(
|
|
20809
|
-
(calls) => getAction(
|
|
20810
|
-
client,
|
|
20811
|
-
simulateContract,
|
|
20812
|
-
"simulateContract"
|
|
20813
|
-
)({
|
|
20814
|
-
account,
|
|
20815
|
-
abi: multicall3Abi,
|
|
20816
|
-
address: multicallAddress,
|
|
20817
|
-
args: [calls],
|
|
20818
|
-
blockNumber,
|
|
20819
|
-
blockTag,
|
|
20820
|
-
// does not infer well that either blockNumber or blockTag must be present
|
|
20821
|
-
functionName: "aggregate3",
|
|
20822
|
-
stateOverride,
|
|
20823
|
-
gas
|
|
20824
|
-
})
|
|
20825
|
-
)
|
|
20826
|
-
);
|
|
20827
|
-
const results = [];
|
|
20828
|
-
for (let i = 0; i < aggregate3Results.length; i++) {
|
|
20829
|
-
const result = aggregate3Results[i];
|
|
20830
|
-
if (result.status === "rejected") {
|
|
20831
|
-
if (!allowFailure) {
|
|
20832
|
-
throw result.reason;
|
|
20833
|
-
}
|
|
20834
|
-
for (const _i of chunkedCalls[i]) {
|
|
20835
|
-
results.push({
|
|
20836
|
-
status: "failure",
|
|
20837
|
-
error: result.reason,
|
|
20838
|
-
result: void 0
|
|
20839
|
-
});
|
|
20840
|
-
}
|
|
20841
|
-
continue;
|
|
20842
|
-
}
|
|
20843
|
-
const aggregate3Result = result.value.result;
|
|
20844
|
-
for (let j = 0; j < aggregate3Result.length; j++) {
|
|
20845
|
-
const { returnData, success } = aggregate3Result[j];
|
|
20846
|
-
const { callData } = chunkedCalls[i][j];
|
|
20847
|
-
const { abi: abi20, address, functionName, args } = contracts[results.length];
|
|
20848
|
-
try {
|
|
20849
|
-
if (callData === "0x") throw new AbiDecodingZeroDataError();
|
|
20850
|
-
if (!success) throw new RawContractError({ data: returnData });
|
|
20851
|
-
const result2 = decodeFunctionResult({
|
|
20852
|
-
abi: abi20,
|
|
20853
|
-
args,
|
|
20854
|
-
data: returnData,
|
|
20855
|
-
functionName
|
|
20856
|
-
});
|
|
20857
|
-
results.push(allowFailure ? { result: result2, status: "success" } : result2);
|
|
20858
|
-
} catch (err) {
|
|
20859
|
-
const error = getContractError(err, {
|
|
20860
|
-
abi: abi20,
|
|
20861
|
-
address,
|
|
20862
|
-
args,
|
|
20863
|
-
docsPath: "/docs/contract/multicall",
|
|
20864
|
-
functionName
|
|
20865
|
-
});
|
|
20866
|
-
if (!allowFailure) throw error;
|
|
20867
|
-
results.push({ error, result: void 0, status: "failure" });
|
|
20868
|
-
}
|
|
20869
|
-
}
|
|
20870
|
-
}
|
|
20871
|
-
if (results.length !== contracts.length)
|
|
20872
|
-
throw new BaseError("multicall results mismatch");
|
|
20873
|
-
return results;
|
|
20874
|
-
}
|
|
20875
20678
|
|
|
20876
20679
|
// src/sdk/market/pricefeeds/PriceFeedRef.ts
|
|
20877
20680
|
var PriceFeedRef = class extends SDKConstruct {
|
|
@@ -21772,33 +21575,7 @@ var PriceOracleContract = class extends BaseContract {
|
|
|
21772
21575
|
* Does not update price feeds, only updates prices
|
|
21773
21576
|
*/
|
|
21774
21577
|
async updatePrices() {
|
|
21775
|
-
|
|
21776
|
-
const resp = await simulateMulticall(this.provider.publicClient, {
|
|
21777
|
-
contracts: [
|
|
21778
|
-
...txs.map(rawTxToMulticallPriceUpdate),
|
|
21779
|
-
{
|
|
21780
|
-
abi: iPriceFeedCompressorAbi,
|
|
21781
|
-
address: this.sdk.addressProvider.getLatestVersion(
|
|
21782
|
-
AP_PRICE_FEED_COMPRESSOR
|
|
21783
|
-
),
|
|
21784
|
-
functionName: "getPriceFeeds",
|
|
21785
|
-
args: [this.address]
|
|
21786
|
-
}
|
|
21787
|
-
],
|
|
21788
|
-
allowFailure: false,
|
|
21789
|
-
gas: 550000000n,
|
|
21790
|
-
batchSize: 0
|
|
21791
|
-
// we cannot have price updates and compressor request in different batches
|
|
21792
|
-
});
|
|
21793
|
-
const [entries, tree] = resp.pop();
|
|
21794
|
-
entries.forEach(({ token, priceFeed, reserve }) => {
|
|
21795
|
-
const price = tree.find((n) => n.baseParams.addr === priceFeed)?.answer?.price;
|
|
21796
|
-
if (reserve && price) {
|
|
21797
|
-
this.reservePrices.upsert(token, price);
|
|
21798
|
-
} else if (price) {
|
|
21799
|
-
this.mainPrices.upsert(token, price);
|
|
21800
|
-
}
|
|
21801
|
-
});
|
|
21578
|
+
await this.sdk.marketRegister.updatePrices([this.address]);
|
|
21802
21579
|
}
|
|
21803
21580
|
#labelPriceFeed(address, usage, token) {
|
|
21804
21581
|
this.sdk.provider.addressLabels.set(address, (label) => {
|
|
@@ -21917,6 +21694,203 @@ var MarketFactory = class extends SDKConstruct {
|
|
|
21917
21694
|
};
|
|
21918
21695
|
}
|
|
21919
21696
|
};
|
|
21697
|
+
var SUPPORTED_CHAINS = [
|
|
21698
|
+
"Mainnet",
|
|
21699
|
+
"Arbitrum",
|
|
21700
|
+
"Optimism",
|
|
21701
|
+
"Base"
|
|
21702
|
+
];
|
|
21703
|
+
var chains = {
|
|
21704
|
+
Mainnet: mainnet,
|
|
21705
|
+
Arbitrum: arbitrum,
|
|
21706
|
+
Optimism: optimism,
|
|
21707
|
+
Base: base
|
|
21708
|
+
};
|
|
21709
|
+
function createTransport(opts) {
|
|
21710
|
+
const { timeout = 12e4, retryCount } = opts;
|
|
21711
|
+
if ("transport" in opts) {
|
|
21712
|
+
return opts.transport;
|
|
21713
|
+
}
|
|
21714
|
+
const rpcs = opts.rpcURLs.map((url) => http(url, { timeout, retryCount }));
|
|
21715
|
+
return rpcs.length ? fallback(rpcs) : rpcs[0];
|
|
21716
|
+
}
|
|
21717
|
+
var Provider = class {
|
|
21718
|
+
chainId;
|
|
21719
|
+
chain;
|
|
21720
|
+
networkType;
|
|
21721
|
+
publicClient;
|
|
21722
|
+
addressLabels;
|
|
21723
|
+
transport;
|
|
21724
|
+
constructor(opts) {
|
|
21725
|
+
const { chainId, networkType } = opts;
|
|
21726
|
+
this.chainId = chainId;
|
|
21727
|
+
this.networkType = networkType;
|
|
21728
|
+
this.chain = defineChain({
|
|
21729
|
+
...chains[networkType],
|
|
21730
|
+
id: chainId
|
|
21731
|
+
});
|
|
21732
|
+
this.transport = createTransport(opts);
|
|
21733
|
+
this.publicClient = createPublicClient({
|
|
21734
|
+
chain: this.chain,
|
|
21735
|
+
transport: this.transport
|
|
21736
|
+
});
|
|
21737
|
+
this.addressLabels = new AddressLabeller();
|
|
21738
|
+
}
|
|
21739
|
+
};
|
|
21740
|
+
|
|
21741
|
+
// src/sdk/utils/viem/detectNetwork.ts
|
|
21742
|
+
async function detectNetwork(client) {
|
|
21743
|
+
for (const chain of SUPPORTED_CHAINS) {
|
|
21744
|
+
try {
|
|
21745
|
+
await client.readContract({
|
|
21746
|
+
abi: ierc20MetadataAbi,
|
|
21747
|
+
address: USDC[chain],
|
|
21748
|
+
functionName: "symbol"
|
|
21749
|
+
});
|
|
21750
|
+
return chain;
|
|
21751
|
+
} catch {
|
|
21752
|
+
}
|
|
21753
|
+
}
|
|
21754
|
+
throw new Error("Unsupported network");
|
|
21755
|
+
}
|
|
21756
|
+
async function simulateMulticall(client, parameters) {
|
|
21757
|
+
const {
|
|
21758
|
+
account,
|
|
21759
|
+
allowFailure = true,
|
|
21760
|
+
batchSize: batchSize_,
|
|
21761
|
+
blockNumber,
|
|
21762
|
+
blockTag,
|
|
21763
|
+
gas,
|
|
21764
|
+
multicallAddress: multicallAddress_,
|
|
21765
|
+
stateOverride
|
|
21766
|
+
} = parameters;
|
|
21767
|
+
const contracts = parameters.contracts;
|
|
21768
|
+
const batchSize = batchSize_ ?? (typeof client.batch?.multicall === "object" && client.batch.multicall.batchSize || 1024);
|
|
21769
|
+
let multicallAddress = multicallAddress_;
|
|
21770
|
+
if (!multicallAddress) {
|
|
21771
|
+
if (!client.chain)
|
|
21772
|
+
throw new Error(
|
|
21773
|
+
"client chain not configured. multicallAddress is required."
|
|
21774
|
+
);
|
|
21775
|
+
multicallAddress = getChainContractAddress({
|
|
21776
|
+
blockNumber,
|
|
21777
|
+
chain: client.chain,
|
|
21778
|
+
contract: "multicall3"
|
|
21779
|
+
});
|
|
21780
|
+
}
|
|
21781
|
+
const chunkedCalls = [[]];
|
|
21782
|
+
let currentChunk = 0;
|
|
21783
|
+
let currentChunkSize = 0;
|
|
21784
|
+
for (const contract of contracts) {
|
|
21785
|
+
const { abi: abi20, address, args, functionName } = contract;
|
|
21786
|
+
try {
|
|
21787
|
+
const callData = encodeFunctionData({ abi: abi20, args, functionName });
|
|
21788
|
+
currentChunkSize += (callData.length - 2) / 2;
|
|
21789
|
+
if (
|
|
21790
|
+
// Check if batching is enabled.
|
|
21791
|
+
batchSize > 0 && // Check if the current size of the batch exceeds the size limit.
|
|
21792
|
+
currentChunkSize > batchSize && // Check if the current chunk is not already empty.
|
|
21793
|
+
chunkedCalls[currentChunk].length > 0
|
|
21794
|
+
) {
|
|
21795
|
+
currentChunk++;
|
|
21796
|
+
currentChunkSize = (callData.length - 2) / 2;
|
|
21797
|
+
chunkedCalls[currentChunk] = [];
|
|
21798
|
+
}
|
|
21799
|
+
chunkedCalls[currentChunk] = [
|
|
21800
|
+
...chunkedCalls[currentChunk],
|
|
21801
|
+
{
|
|
21802
|
+
allowFailure: true,
|
|
21803
|
+
callData,
|
|
21804
|
+
target: address
|
|
21805
|
+
}
|
|
21806
|
+
];
|
|
21807
|
+
} catch (err) {
|
|
21808
|
+
const error = getContractError(err, {
|
|
21809
|
+
abi: abi20,
|
|
21810
|
+
address,
|
|
21811
|
+
args,
|
|
21812
|
+
docsPath: "/docs/contract/multicall",
|
|
21813
|
+
functionName
|
|
21814
|
+
});
|
|
21815
|
+
if (!allowFailure) throw error;
|
|
21816
|
+
chunkedCalls[currentChunk] = [
|
|
21817
|
+
...chunkedCalls[currentChunk],
|
|
21818
|
+
{
|
|
21819
|
+
allowFailure: true,
|
|
21820
|
+
callData: "0x",
|
|
21821
|
+
target: address
|
|
21822
|
+
}
|
|
21823
|
+
];
|
|
21824
|
+
}
|
|
21825
|
+
}
|
|
21826
|
+
const aggregate3Results = await Promise.allSettled(
|
|
21827
|
+
chunkedCalls.map(
|
|
21828
|
+
(calls) => getAction(
|
|
21829
|
+
client,
|
|
21830
|
+
simulateContract,
|
|
21831
|
+
"simulateContract"
|
|
21832
|
+
)({
|
|
21833
|
+
account,
|
|
21834
|
+
abi: multicall3Abi,
|
|
21835
|
+
address: multicallAddress,
|
|
21836
|
+
args: [calls],
|
|
21837
|
+
blockNumber,
|
|
21838
|
+
blockTag,
|
|
21839
|
+
// does not infer well that either blockNumber or blockTag must be present
|
|
21840
|
+
functionName: "aggregate3",
|
|
21841
|
+
stateOverride,
|
|
21842
|
+
gas
|
|
21843
|
+
})
|
|
21844
|
+
)
|
|
21845
|
+
);
|
|
21846
|
+
const results = [];
|
|
21847
|
+
for (let i = 0; i < aggregate3Results.length; i++) {
|
|
21848
|
+
const result = aggregate3Results[i];
|
|
21849
|
+
if (result.status === "rejected") {
|
|
21850
|
+
if (!allowFailure) {
|
|
21851
|
+
throw result.reason;
|
|
21852
|
+
}
|
|
21853
|
+
for (const _i of chunkedCalls[i]) {
|
|
21854
|
+
results.push({
|
|
21855
|
+
status: "failure",
|
|
21856
|
+
error: result.reason,
|
|
21857
|
+
result: void 0
|
|
21858
|
+
});
|
|
21859
|
+
}
|
|
21860
|
+
continue;
|
|
21861
|
+
}
|
|
21862
|
+
const aggregate3Result = result.value.result;
|
|
21863
|
+
for (let j = 0; j < aggregate3Result.length; j++) {
|
|
21864
|
+
const { returnData, success } = aggregate3Result[j];
|
|
21865
|
+
const { callData } = chunkedCalls[i][j];
|
|
21866
|
+
const { abi: abi20, address, functionName, args } = contracts[results.length];
|
|
21867
|
+
try {
|
|
21868
|
+
if (callData === "0x") throw new AbiDecodingZeroDataError();
|
|
21869
|
+
if (!success) throw new RawContractError({ data: returnData });
|
|
21870
|
+
const result2 = decodeFunctionResult({
|
|
21871
|
+
abi: abi20,
|
|
21872
|
+
args,
|
|
21873
|
+
data: returnData,
|
|
21874
|
+
functionName
|
|
21875
|
+
});
|
|
21876
|
+
results.push(allowFailure ? { result: result2, status: "success" } : result2);
|
|
21877
|
+
} catch (err) {
|
|
21878
|
+
const error = getContractError(err, {
|
|
21879
|
+
abi: abi20,
|
|
21880
|
+
address,
|
|
21881
|
+
args,
|
|
21882
|
+
docsPath: "/docs/contract/multicall",
|
|
21883
|
+
functionName
|
|
21884
|
+
});
|
|
21885
|
+
if (!allowFailure) throw error;
|
|
21886
|
+
results.push({ error, result: void 0, status: "failure" });
|
|
21887
|
+
}
|
|
21888
|
+
}
|
|
21889
|
+
}
|
|
21890
|
+
if (results.length !== contracts.length)
|
|
21891
|
+
throw new BaseError("multicall results mismatch");
|
|
21892
|
+
return results;
|
|
21893
|
+
}
|
|
21920
21894
|
|
|
21921
21895
|
// src/sdk/market/MarketConfiguratorContract.ts
|
|
21922
21896
|
var abi19 = iMarketConfiguratorV310Abi;
|
|
@@ -22009,6 +21983,48 @@ var MarketRegister = class extends SDKConstruct {
|
|
|
22009
21983
|
}
|
|
22010
21984
|
this.#logger?.info(`loaded ${markets.length} markets`);
|
|
22011
21985
|
}
|
|
21986
|
+
/**
|
|
21987
|
+
* Loads new prices for given oracles from PriceFeedCompressor, defaults to all oracles
|
|
21988
|
+
* Does not update price feeds, only updates prices
|
|
21989
|
+
*/
|
|
21990
|
+
async updatePrices(oracles) {
|
|
21991
|
+
const oraclez = oracles ?? this.markets.map((m) => m.priceOracle.address);
|
|
21992
|
+
if (!oraclez.length) {
|
|
21993
|
+
return;
|
|
21994
|
+
}
|
|
21995
|
+
const { txs } = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs();
|
|
21996
|
+
const resp = await simulateMulticall(this.provider.publicClient, {
|
|
21997
|
+
contracts: [
|
|
21998
|
+
...txs.map(rawTxToMulticallPriceUpdate),
|
|
21999
|
+
...oraclez.map((o) => ({
|
|
22000
|
+
abi: iPriceFeedCompressorAbi,
|
|
22001
|
+
address: this.sdk.addressProvider.getLatestVersion(
|
|
22002
|
+
AP_PRICE_FEED_COMPRESSOR
|
|
22003
|
+
),
|
|
22004
|
+
functionName: "getPriceFeeds",
|
|
22005
|
+
args: [o]
|
|
22006
|
+
}))
|
|
22007
|
+
],
|
|
22008
|
+
allowFailure: false,
|
|
22009
|
+
gas: 550000000n,
|
|
22010
|
+
batchSize: 0
|
|
22011
|
+
// we cannot have price updates and compressor request in different batches
|
|
22012
|
+
});
|
|
22013
|
+
const oraclesStates = resp.slice(txs.length);
|
|
22014
|
+
for (let i = 0; i < oraclez.length; i++) {
|
|
22015
|
+
const oracleAddr = oraclez[i];
|
|
22016
|
+
const oracle = this.findPriceOracle(oracleAddr);
|
|
22017
|
+
const [entries, tree] = oraclesStates[i];
|
|
22018
|
+
for (const { token, priceFeed, reserve } of entries) {
|
|
22019
|
+
const price = tree.find((n) => n.baseParams.addr === priceFeed)?.answer?.price;
|
|
22020
|
+
if (reserve && price) {
|
|
22021
|
+
oracle.reservePrices.upsert(token, price);
|
|
22022
|
+
} else if (price) {
|
|
22023
|
+
oracle.mainPrices.upsert(token, price);
|
|
22024
|
+
}
|
|
22025
|
+
}
|
|
22026
|
+
}
|
|
22027
|
+
}
|
|
22012
22028
|
get state() {
|
|
22013
22029
|
return this.markets.map((market) => market.state);
|
|
22014
22030
|
}
|
|
@@ -22031,6 +22047,14 @@ var MarketRegister = class extends SDKConstruct {
|
|
|
22031
22047
|
}
|
|
22032
22048
|
throw new Error(`cannot find credit manager ${creditManager}`);
|
|
22033
22049
|
}
|
|
22050
|
+
findPriceOracle(address) {
|
|
22051
|
+
for (const market of this.markets) {
|
|
22052
|
+
if (market.priceOracle.address.toLowerCase() === address.toLowerCase()) {
|
|
22053
|
+
return market.priceOracle;
|
|
22054
|
+
}
|
|
22055
|
+
}
|
|
22056
|
+
throw new Error(`cannot find price oracle ${address}`);
|
|
22057
|
+
}
|
|
22034
22058
|
findByCreditManager(creditManager) {
|
|
22035
22059
|
const market = this.markets.find(
|
|
22036
22060
|
(m) => m.creditManagers.some(
|
|
@@ -22432,7 +22456,7 @@ var AddressProviderContractV3_1 = class extends BaseContract {
|
|
|
22432
22456
|
);
|
|
22433
22457
|
return this.getAddress(contract, this.latest[contract]);
|
|
22434
22458
|
}
|
|
22435
|
-
async
|
|
22459
|
+
async syncState(blockNumber) {
|
|
22436
22460
|
const entries = await this.contract.read.getAllSavedContracts({
|
|
22437
22461
|
blockNumber
|
|
22438
22462
|
});
|
|
@@ -22997,7 +23021,7 @@ var GearboxSDK = class _GearboxSDK {
|
|
|
22997
23021
|
this,
|
|
22998
23022
|
addressProviderAddress
|
|
22999
23023
|
);
|
|
23000
|
-
await this.#addressProvider.
|
|
23024
|
+
await this.#addressProvider.syncState(this.currentBlock);
|
|
23001
23025
|
const botListAddress = this.#addressProvider.getAddress(AP_BOT_LIST, 300);
|
|
23002
23026
|
this.#botListContract = new BotListContract(this, botListAddress);
|
|
23003
23027
|
this.#gear = this.#addressProvider.getAddress(AP_GEAR_TOKEN);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gearbox-protocol/sdk",
|
|
3
|
-
"version": "3.0.0-vfour.
|
|
3
|
+
"version": "3.0.0-vfour.65",
|
|
4
4
|
"description": "Gearbox SDK",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "./dist/cjs/sdk/index.cjs",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"abitype": "^1.0.6",
|
|
52
52
|
"date-fns": "^4.1.0",
|
|
53
53
|
"redstone-protocol": "^1.0.5",
|
|
54
|
-
"viem": "
|
|
54
|
+
"viem": ">=2.21.0 <3.0.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@commitlint/cli": "^19.5.0",
|