@gearbox-protocol/sdk 3.0.0-vfour.171 → 3.0.0-vfour.173
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 +271 -275
- package/dist/cjs/sdk/index.d.ts +16 -16
- package/dist/esm/sdk/index.d.mts +16 -16
- package/dist/esm/sdk/index.mjs +271 -275
- package/package.json +1 -1
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 evmConnector = require('@redstone-finance/evm-connector');
|
|
7
|
-
var redstoneProtocol = require('redstone-protocol');
|
|
8
6
|
var chains$1 = require('viem/chains');
|
|
9
7
|
var actions = require('viem/actions');
|
|
8
|
+
var evmConnector = require('@redstone-finance/evm-connector');
|
|
9
|
+
var redstoneProtocol = require('redstone-protocol');
|
|
10
10
|
var decimal_jsLight = require('decimal.js-light');
|
|
11
11
|
var axios = require('axios');
|
|
12
12
|
|
|
@@ -55378,7 +55378,7 @@ var iMarketConfiguratorV310Abi = [
|
|
|
55378
55378
|
},
|
|
55379
55379
|
{
|
|
55380
55380
|
type: "function",
|
|
55381
|
-
name: "
|
|
55381
|
+
name: "CreditSuite",
|
|
55382
55382
|
inputs: [],
|
|
55383
55383
|
outputs: [
|
|
55384
55384
|
{
|
|
@@ -58017,8 +58017,8 @@ var CreditManagerV310Contract = class extends BaseContract {
|
|
|
58017
58017
|
}
|
|
58018
58018
|
};
|
|
58019
58019
|
|
|
58020
|
-
// src/sdk/market/
|
|
58021
|
-
var
|
|
58020
|
+
// src/sdk/market/CreditSuite.ts
|
|
58021
|
+
var CreditSuite = class extends SDKConstruct {
|
|
58022
58022
|
name;
|
|
58023
58023
|
pool;
|
|
58024
58024
|
underlying;
|
|
@@ -58213,6 +58213,256 @@ var LinearModelContract = class extends BaseContract {
|
|
|
58213
58213
|
};
|
|
58214
58214
|
}
|
|
58215
58215
|
};
|
|
58216
|
+
var SUPPORTED_CHAINS = [
|
|
58217
|
+
"Mainnet",
|
|
58218
|
+
"Arbitrum",
|
|
58219
|
+
"Optimism",
|
|
58220
|
+
"Base"
|
|
58221
|
+
];
|
|
58222
|
+
var chains = {
|
|
58223
|
+
Mainnet: chains$1.mainnet,
|
|
58224
|
+
Arbitrum: chains$1.arbitrum,
|
|
58225
|
+
Optimism: chains$1.optimism,
|
|
58226
|
+
Base: chains$1.base
|
|
58227
|
+
};
|
|
58228
|
+
var CHAINS_BY_ID = {
|
|
58229
|
+
[chains$1.mainnet.id]: "Mainnet",
|
|
58230
|
+
[chains$1.arbitrum.id]: "Arbitrum",
|
|
58231
|
+
[chains$1.optimism.id]: "Optimism"
|
|
58232
|
+
// [base.id]: "Base",
|
|
58233
|
+
};
|
|
58234
|
+
var getNetworkType = (chainId) => {
|
|
58235
|
+
const chainType = CHAINS_BY_ID[chainId];
|
|
58236
|
+
if (chainType) {
|
|
58237
|
+
return chainType;
|
|
58238
|
+
}
|
|
58239
|
+
throw new Error("Unsupported network");
|
|
58240
|
+
};
|
|
58241
|
+
var isSupportedNetwork = (chainId) => chainId !== undefined && !!CHAINS_BY_ID[chainId];
|
|
58242
|
+
async function detectChain(transportOrRPC) {
|
|
58243
|
+
const transport = typeof transportOrRPC === "string" ? viem.http(transportOrRPC) : transportOrRPC;
|
|
58244
|
+
const tempClient = viem.createPublicClient({ transport });
|
|
58245
|
+
const [networkType, chainId] = await Promise.all([
|
|
58246
|
+
detectNetwork(tempClient),
|
|
58247
|
+
tempClient.getChainId()
|
|
58248
|
+
]);
|
|
58249
|
+
return viem.defineChain({
|
|
58250
|
+
...chains[networkType],
|
|
58251
|
+
id: chainId
|
|
58252
|
+
});
|
|
58253
|
+
}
|
|
58254
|
+
function createTransport(opts) {
|
|
58255
|
+
const { timeout = 12e4, retryCount } = opts;
|
|
58256
|
+
if ("transport" in opts) {
|
|
58257
|
+
return opts.transport;
|
|
58258
|
+
}
|
|
58259
|
+
const rpcs = opts.rpcURLs.map((url) => viem.http(url, { timeout, retryCount }));
|
|
58260
|
+
return rpcs.length ? viem.fallback(rpcs) : rpcs[0];
|
|
58261
|
+
}
|
|
58262
|
+
var Provider = class {
|
|
58263
|
+
chainId;
|
|
58264
|
+
chain;
|
|
58265
|
+
networkType;
|
|
58266
|
+
addressLabels;
|
|
58267
|
+
#transport;
|
|
58268
|
+
#publicClient;
|
|
58269
|
+
constructor(opts) {
|
|
58270
|
+
const { chainId, networkType } = opts;
|
|
58271
|
+
this.chainId = chainId;
|
|
58272
|
+
this.networkType = networkType;
|
|
58273
|
+
this.chain = viem.defineChain({
|
|
58274
|
+
...chains[networkType],
|
|
58275
|
+
id: chainId
|
|
58276
|
+
});
|
|
58277
|
+
this.#transport = createTransport(opts);
|
|
58278
|
+
this.#publicClient = viem.createPublicClient({
|
|
58279
|
+
chain: this.chain,
|
|
58280
|
+
transport: this.#transport
|
|
58281
|
+
});
|
|
58282
|
+
this.addressLabels = new AddressLabeller();
|
|
58283
|
+
}
|
|
58284
|
+
get transport() {
|
|
58285
|
+
return this.#transport;
|
|
58286
|
+
}
|
|
58287
|
+
set transport(transport) {
|
|
58288
|
+
this.#transport = transport;
|
|
58289
|
+
this.#publicClient = viem.createPublicClient({
|
|
58290
|
+
chain: this.chain,
|
|
58291
|
+
transport: this.#transport
|
|
58292
|
+
});
|
|
58293
|
+
}
|
|
58294
|
+
get publicClient() {
|
|
58295
|
+
return this.#publicClient;
|
|
58296
|
+
}
|
|
58297
|
+
};
|
|
58298
|
+
|
|
58299
|
+
// src/sdk/utils/viem/detectNetwork.ts
|
|
58300
|
+
async function detectNetwork(client) {
|
|
58301
|
+
for (const chain of SUPPORTED_CHAINS) {
|
|
58302
|
+
try {
|
|
58303
|
+
await client.readContract({
|
|
58304
|
+
abi: ierc20MetadataAbi,
|
|
58305
|
+
address: USDC[chain],
|
|
58306
|
+
functionName: "symbol"
|
|
58307
|
+
});
|
|
58308
|
+
return chain;
|
|
58309
|
+
} catch {
|
|
58310
|
+
}
|
|
58311
|
+
}
|
|
58312
|
+
throw new Error("Unsupported network");
|
|
58313
|
+
}
|
|
58314
|
+
async function sendRawTx(client, params) {
|
|
58315
|
+
const { account, tx } = params;
|
|
58316
|
+
return utils.getAction(
|
|
58317
|
+
client,
|
|
58318
|
+
actions.sendTransaction,
|
|
58319
|
+
"sendTransaction"
|
|
58320
|
+
)({
|
|
58321
|
+
// @ts-expect-error
|
|
58322
|
+
account,
|
|
58323
|
+
data: tx.callData,
|
|
58324
|
+
to: tx.to,
|
|
58325
|
+
value: BigInt(tx.value)
|
|
58326
|
+
});
|
|
58327
|
+
}
|
|
58328
|
+
async function simulateMulticall(client, parameters) {
|
|
58329
|
+
const {
|
|
58330
|
+
account,
|
|
58331
|
+
allowFailure = true,
|
|
58332
|
+
batchSize: batchSize_,
|
|
58333
|
+
blockNumber,
|
|
58334
|
+
blockTag,
|
|
58335
|
+
gas,
|
|
58336
|
+
multicallAddress: multicallAddress_,
|
|
58337
|
+
stateOverride
|
|
58338
|
+
} = parameters;
|
|
58339
|
+
const contracts = parameters.contracts;
|
|
58340
|
+
const batchSize = batchSize_ ?? (typeof client.batch?.multicall === "object" && client.batch.multicall.batchSize || 1024);
|
|
58341
|
+
let multicallAddress = multicallAddress_;
|
|
58342
|
+
if (!multicallAddress) {
|
|
58343
|
+
if (!client.chain)
|
|
58344
|
+
throw new Error(
|
|
58345
|
+
"client chain not configured. multicallAddress is required."
|
|
58346
|
+
);
|
|
58347
|
+
multicallAddress = viem.getChainContractAddress({
|
|
58348
|
+
blockNumber,
|
|
58349
|
+
chain: client.chain,
|
|
58350
|
+
contract: "multicall3"
|
|
58351
|
+
});
|
|
58352
|
+
}
|
|
58353
|
+
const chunkedCalls = [[]];
|
|
58354
|
+
let currentChunk = 0;
|
|
58355
|
+
let currentChunkSize = 0;
|
|
58356
|
+
for (const contract of contracts) {
|
|
58357
|
+
const { abi: abi32, address, args, functionName } = contract;
|
|
58358
|
+
try {
|
|
58359
|
+
const callData = viem.encodeFunctionData({ abi: abi32, args, functionName });
|
|
58360
|
+
currentChunkSize += (callData.length - 2) / 2;
|
|
58361
|
+
if (
|
|
58362
|
+
// Check if batching is enabled.
|
|
58363
|
+
batchSize > 0 && // Check if the current size of the batch exceeds the size limit.
|
|
58364
|
+
currentChunkSize > batchSize && // Check if the current chunk is not already empty.
|
|
58365
|
+
chunkedCalls[currentChunk].length > 0
|
|
58366
|
+
) {
|
|
58367
|
+
currentChunk++;
|
|
58368
|
+
currentChunkSize = (callData.length - 2) / 2;
|
|
58369
|
+
chunkedCalls[currentChunk] = [];
|
|
58370
|
+
}
|
|
58371
|
+
chunkedCalls[currentChunk] = [
|
|
58372
|
+
...chunkedCalls[currentChunk],
|
|
58373
|
+
{
|
|
58374
|
+
allowFailure: true,
|
|
58375
|
+
callData,
|
|
58376
|
+
target: address
|
|
58377
|
+
}
|
|
58378
|
+
];
|
|
58379
|
+
} catch (err) {
|
|
58380
|
+
const error = viem.getContractError(err, {
|
|
58381
|
+
abi: abi32,
|
|
58382
|
+
address,
|
|
58383
|
+
args,
|
|
58384
|
+
docsPath: "/docs/contract/multicall",
|
|
58385
|
+
functionName
|
|
58386
|
+
});
|
|
58387
|
+
if (!allowFailure) throw error;
|
|
58388
|
+
chunkedCalls[currentChunk] = [
|
|
58389
|
+
...chunkedCalls[currentChunk],
|
|
58390
|
+
{
|
|
58391
|
+
allowFailure: true,
|
|
58392
|
+
callData: "0x",
|
|
58393
|
+
target: address
|
|
58394
|
+
}
|
|
58395
|
+
];
|
|
58396
|
+
}
|
|
58397
|
+
}
|
|
58398
|
+
const aggregate3Results = await Promise.allSettled(
|
|
58399
|
+
chunkedCalls.map(
|
|
58400
|
+
(calls) => utils.getAction(
|
|
58401
|
+
client,
|
|
58402
|
+
actions.simulateContract,
|
|
58403
|
+
"simulateContract"
|
|
58404
|
+
)({
|
|
58405
|
+
account,
|
|
58406
|
+
abi: viem.multicall3Abi,
|
|
58407
|
+
address: multicallAddress,
|
|
58408
|
+
args: [calls],
|
|
58409
|
+
blockNumber,
|
|
58410
|
+
blockTag,
|
|
58411
|
+
// does not infer well that either blockNumber or blockTag must be present
|
|
58412
|
+
functionName: "aggregate3",
|
|
58413
|
+
stateOverride,
|
|
58414
|
+
gas
|
|
58415
|
+
})
|
|
58416
|
+
)
|
|
58417
|
+
);
|
|
58418
|
+
const results = [];
|
|
58419
|
+
for (let i = 0; i < aggregate3Results.length; i++) {
|
|
58420
|
+
const result = aggregate3Results[i];
|
|
58421
|
+
if (result.status === "rejected") {
|
|
58422
|
+
if (!allowFailure) {
|
|
58423
|
+
throw result.reason;
|
|
58424
|
+
}
|
|
58425
|
+
for (const _i of chunkedCalls[i]) {
|
|
58426
|
+
results.push({
|
|
58427
|
+
status: "failure",
|
|
58428
|
+
error: result.reason,
|
|
58429
|
+
result: undefined
|
|
58430
|
+
});
|
|
58431
|
+
}
|
|
58432
|
+
continue;
|
|
58433
|
+
}
|
|
58434
|
+
const aggregate3Result = result.value.result;
|
|
58435
|
+
for (let j = 0; j < aggregate3Result.length; j++) {
|
|
58436
|
+
const { returnData, success } = aggregate3Result[j];
|
|
58437
|
+
const { callData } = chunkedCalls[i][j];
|
|
58438
|
+
const { abi: abi32, address, functionName, args } = contracts[results.length];
|
|
58439
|
+
try {
|
|
58440
|
+
if (callData === "0x") throw new viem.AbiDecodingZeroDataError();
|
|
58441
|
+
if (!success) throw new viem.RawContractError({ data: returnData });
|
|
58442
|
+
const result2 = viem.decodeFunctionResult({
|
|
58443
|
+
abi: abi32,
|
|
58444
|
+
args,
|
|
58445
|
+
data: returnData,
|
|
58446
|
+
functionName
|
|
58447
|
+
});
|
|
58448
|
+
results.push(allowFailure ? { result: result2, status: "success" } : result2);
|
|
58449
|
+
} catch (err) {
|
|
58450
|
+
const error = viem.getContractError(err, {
|
|
58451
|
+
abi: abi32,
|
|
58452
|
+
address,
|
|
58453
|
+
args,
|
|
58454
|
+
docsPath: "/docs/contract/multicall",
|
|
58455
|
+
functionName
|
|
58456
|
+
});
|
|
58457
|
+
if (!allowFailure) throw error;
|
|
58458
|
+
results.push({ error, result: undefined, status: "failure" });
|
|
58459
|
+
}
|
|
58460
|
+
}
|
|
58461
|
+
}
|
|
58462
|
+
if (results.length !== contracts.length)
|
|
58463
|
+
throw new viem.BaseError("multicall results mismatch");
|
|
58464
|
+
return results;
|
|
58465
|
+
}
|
|
58216
58466
|
|
|
58217
58467
|
// src/sdk/market/MarketConfiguratorContract.ts
|
|
58218
58468
|
var abi27 = iMarketConfiguratorV310Abi;
|
|
@@ -58371,7 +58621,7 @@ var PoolQuotaKeeperContract = class extends BaseContract {
|
|
|
58371
58621
|
quotas: this.quotas.entries().reduce(
|
|
58372
58622
|
(acc, [address, params]) => ({
|
|
58373
58623
|
...acc,
|
|
58374
|
-
[address]: {
|
|
58624
|
+
[this.labelAddress(address)]: {
|
|
58375
58625
|
rate: percentFmt(params.rate, raw),
|
|
58376
58626
|
quotaIncreaseFee: percentFmt(params.quotaIncreaseFee, raw),
|
|
58377
58627
|
totalQuoted: formatBNvalue(
|
|
@@ -65372,11 +65622,13 @@ var PriceOracleBaseContract = class extends BaseContract {
|
|
|
65372
65622
|
);
|
|
65373
65623
|
}
|
|
65374
65624
|
#labelPriceFeed(address, usage, token) {
|
|
65375
|
-
this.sdk.provider.addressLabels.set(address, (
|
|
65625
|
+
this.sdk.provider.addressLabels.set(address, (oldLabel) => {
|
|
65376
65626
|
const symbol = this.sdk.tokensMeta.symbol(token);
|
|
65377
65627
|
let pricefeedTag = `${symbol}.${usage}`;
|
|
65378
|
-
if (
|
|
65379
|
-
|
|
65628
|
+
if (oldLabel) {
|
|
65629
|
+
const oldLabelParts = new Set(oldLabel.split(", "));
|
|
65630
|
+
oldLabelParts.add(pricefeedTag);
|
|
65631
|
+
pricefeedTag = Array.from(oldLabelParts).join(", ");
|
|
65380
65632
|
}
|
|
65381
65633
|
return pricefeedTag;
|
|
65382
65634
|
});
|
|
@@ -65405,16 +65657,10 @@ var PriceOracleBaseContract = class extends BaseContract {
|
|
|
65405
65657
|
return {
|
|
65406
65658
|
...super.stateHuman(raw),
|
|
65407
65659
|
mainPriceFeeds: Object.fromEntries(
|
|
65408
|
-
this.mainPriceFeeds.entries().map(([token, v]) => [
|
|
65409
|
-
this.labelAddress(token),
|
|
65410
|
-
v.stateHuman(raw)
|
|
65411
|
-
])
|
|
65660
|
+
this.mainPriceFeeds.entries().map(([token, v]) => [this.labelAddress(token), v.stateHuman(raw)])
|
|
65412
65661
|
),
|
|
65413
65662
|
reservePriceFeeds: Object.fromEntries(
|
|
65414
|
-
this.reservePriceFeeds.entries().map(([token, v]) => [
|
|
65415
|
-
this.labelAddress(token),
|
|
65416
|
-
v.stateHuman(raw)
|
|
65417
|
-
])
|
|
65663
|
+
this.reservePriceFeeds.entries().map(([token, v]) => [this.labelAddress(token), v.stateHuman(raw)])
|
|
65418
65664
|
)
|
|
65419
65665
|
};
|
|
65420
65666
|
}
|
|
@@ -65497,8 +65743,8 @@ var PriceOracleV310Contract = class extends PriceOracleBaseContract {
|
|
|
65497
65743
|
}
|
|
65498
65744
|
};
|
|
65499
65745
|
|
|
65500
|
-
// src/sdk/market/
|
|
65501
|
-
var
|
|
65746
|
+
// src/sdk/market/MarketSuite.ts
|
|
65747
|
+
var MarketSuite = class extends SDKConstruct {
|
|
65502
65748
|
acl;
|
|
65503
65749
|
configurator;
|
|
65504
65750
|
poolFactory;
|
|
@@ -65534,7 +65780,7 @@ var MarketFactory = class extends SDKConstruct {
|
|
|
65534
65780
|
this.poolFactory = new PoolFactory(sdk, marketData);
|
|
65535
65781
|
this.zappers = marketData.zappers;
|
|
65536
65782
|
for (let i = 0; i < marketData.creditManagers.length; i++) {
|
|
65537
|
-
this.creditManagers.push(new
|
|
65783
|
+
this.creditManagers.push(new CreditSuite(sdk, marketData, i));
|
|
65538
65784
|
}
|
|
65539
65785
|
if (marketData.priceOracleData.baseParams.version < 310) {
|
|
65540
65786
|
this.priceOracle = new PriceOracleV300Contract(
|
|
@@ -65575,262 +65821,12 @@ var MarketFactory = class extends SDKConstruct {
|
|
|
65575
65821
|
};
|
|
65576
65822
|
}
|
|
65577
65823
|
};
|
|
65578
|
-
var SUPPORTED_CHAINS = [
|
|
65579
|
-
"Mainnet",
|
|
65580
|
-
"Arbitrum",
|
|
65581
|
-
"Optimism",
|
|
65582
|
-
"Base"
|
|
65583
|
-
];
|
|
65584
|
-
var chains = {
|
|
65585
|
-
Mainnet: chains$1.mainnet,
|
|
65586
|
-
Arbitrum: chains$1.arbitrum,
|
|
65587
|
-
Optimism: chains$1.optimism,
|
|
65588
|
-
Base: chains$1.base
|
|
65589
|
-
};
|
|
65590
|
-
var CHAINS_BY_ID = {
|
|
65591
|
-
[chains$1.mainnet.id]: "Mainnet",
|
|
65592
|
-
[chains$1.arbitrum.id]: "Arbitrum",
|
|
65593
|
-
[chains$1.optimism.id]: "Optimism"
|
|
65594
|
-
// [base.id]: "Base",
|
|
65595
|
-
};
|
|
65596
|
-
var getNetworkType = (chainId) => {
|
|
65597
|
-
const chainType = CHAINS_BY_ID[chainId];
|
|
65598
|
-
if (chainType) {
|
|
65599
|
-
return chainType;
|
|
65600
|
-
}
|
|
65601
|
-
throw new Error("Unsupported network");
|
|
65602
|
-
};
|
|
65603
|
-
var isSupportedNetwork = (chainId) => chainId !== undefined && !!CHAINS_BY_ID[chainId];
|
|
65604
|
-
async function detectChain(transportOrRPC) {
|
|
65605
|
-
const transport = typeof transportOrRPC === "string" ? viem.http(transportOrRPC) : transportOrRPC;
|
|
65606
|
-
const tempClient = viem.createPublicClient({ transport });
|
|
65607
|
-
const [networkType, chainId] = await Promise.all([
|
|
65608
|
-
detectNetwork(tempClient),
|
|
65609
|
-
tempClient.getChainId()
|
|
65610
|
-
]);
|
|
65611
|
-
return viem.defineChain({
|
|
65612
|
-
...chains[networkType],
|
|
65613
|
-
id: chainId
|
|
65614
|
-
});
|
|
65615
|
-
}
|
|
65616
|
-
function createTransport(opts) {
|
|
65617
|
-
const { timeout = 12e4, retryCount } = opts;
|
|
65618
|
-
if ("transport" in opts) {
|
|
65619
|
-
return opts.transport;
|
|
65620
|
-
}
|
|
65621
|
-
const rpcs = opts.rpcURLs.map((url) => viem.http(url, { timeout, retryCount }));
|
|
65622
|
-
return rpcs.length ? viem.fallback(rpcs) : rpcs[0];
|
|
65623
|
-
}
|
|
65624
|
-
var Provider = class {
|
|
65625
|
-
chainId;
|
|
65626
|
-
chain;
|
|
65627
|
-
networkType;
|
|
65628
|
-
addressLabels;
|
|
65629
|
-
#transport;
|
|
65630
|
-
#publicClient;
|
|
65631
|
-
constructor(opts) {
|
|
65632
|
-
const { chainId, networkType } = opts;
|
|
65633
|
-
this.chainId = chainId;
|
|
65634
|
-
this.networkType = networkType;
|
|
65635
|
-
this.chain = viem.defineChain({
|
|
65636
|
-
...chains[networkType],
|
|
65637
|
-
id: chainId
|
|
65638
|
-
});
|
|
65639
|
-
this.#transport = createTransport(opts);
|
|
65640
|
-
this.#publicClient = viem.createPublicClient({
|
|
65641
|
-
chain: this.chain,
|
|
65642
|
-
transport: this.#transport
|
|
65643
|
-
});
|
|
65644
|
-
this.addressLabels = new AddressLabeller();
|
|
65645
|
-
}
|
|
65646
|
-
get transport() {
|
|
65647
|
-
return this.#transport;
|
|
65648
|
-
}
|
|
65649
|
-
set transport(transport) {
|
|
65650
|
-
this.#transport = transport;
|
|
65651
|
-
this.#publicClient = viem.createPublicClient({
|
|
65652
|
-
chain: this.chain,
|
|
65653
|
-
transport: this.#transport
|
|
65654
|
-
});
|
|
65655
|
-
}
|
|
65656
|
-
get publicClient() {
|
|
65657
|
-
return this.#publicClient;
|
|
65658
|
-
}
|
|
65659
|
-
};
|
|
65660
|
-
|
|
65661
|
-
// src/sdk/utils/viem/detectNetwork.ts
|
|
65662
|
-
async function detectNetwork(client) {
|
|
65663
|
-
for (const chain of SUPPORTED_CHAINS) {
|
|
65664
|
-
try {
|
|
65665
|
-
await client.readContract({
|
|
65666
|
-
abi: ierc20MetadataAbi,
|
|
65667
|
-
address: USDC[chain],
|
|
65668
|
-
functionName: "symbol"
|
|
65669
|
-
});
|
|
65670
|
-
return chain;
|
|
65671
|
-
} catch {
|
|
65672
|
-
}
|
|
65673
|
-
}
|
|
65674
|
-
throw new Error("Unsupported network");
|
|
65675
|
-
}
|
|
65676
|
-
async function sendRawTx(client, params) {
|
|
65677
|
-
const { account, tx } = params;
|
|
65678
|
-
return utils.getAction(
|
|
65679
|
-
client,
|
|
65680
|
-
actions.sendTransaction,
|
|
65681
|
-
"sendTransaction"
|
|
65682
|
-
)({
|
|
65683
|
-
// @ts-expect-error
|
|
65684
|
-
account,
|
|
65685
|
-
data: tx.callData,
|
|
65686
|
-
to: tx.to,
|
|
65687
|
-
value: BigInt(tx.value)
|
|
65688
|
-
});
|
|
65689
|
-
}
|
|
65690
|
-
async function simulateMulticall(client, parameters) {
|
|
65691
|
-
const {
|
|
65692
|
-
account,
|
|
65693
|
-
allowFailure = true,
|
|
65694
|
-
batchSize: batchSize_,
|
|
65695
|
-
blockNumber,
|
|
65696
|
-
blockTag,
|
|
65697
|
-
gas,
|
|
65698
|
-
multicallAddress: multicallAddress_,
|
|
65699
|
-
stateOverride
|
|
65700
|
-
} = parameters;
|
|
65701
|
-
const contracts = parameters.contracts;
|
|
65702
|
-
const batchSize = batchSize_ ?? (typeof client.batch?.multicall === "object" && client.batch.multicall.batchSize || 1024);
|
|
65703
|
-
let multicallAddress = multicallAddress_;
|
|
65704
|
-
if (!multicallAddress) {
|
|
65705
|
-
if (!client.chain)
|
|
65706
|
-
throw new Error(
|
|
65707
|
-
"client chain not configured. multicallAddress is required."
|
|
65708
|
-
);
|
|
65709
|
-
multicallAddress = viem.getChainContractAddress({
|
|
65710
|
-
blockNumber,
|
|
65711
|
-
chain: client.chain,
|
|
65712
|
-
contract: "multicall3"
|
|
65713
|
-
});
|
|
65714
|
-
}
|
|
65715
|
-
const chunkedCalls = [[]];
|
|
65716
|
-
let currentChunk = 0;
|
|
65717
|
-
let currentChunkSize = 0;
|
|
65718
|
-
for (const contract of contracts) {
|
|
65719
|
-
const { abi: abi32, address, args, functionName } = contract;
|
|
65720
|
-
try {
|
|
65721
|
-
const callData = viem.encodeFunctionData({ abi: abi32, args, functionName });
|
|
65722
|
-
currentChunkSize += (callData.length - 2) / 2;
|
|
65723
|
-
if (
|
|
65724
|
-
// Check if batching is enabled.
|
|
65725
|
-
batchSize > 0 && // Check if the current size of the batch exceeds the size limit.
|
|
65726
|
-
currentChunkSize > batchSize && // Check if the current chunk is not already empty.
|
|
65727
|
-
chunkedCalls[currentChunk].length > 0
|
|
65728
|
-
) {
|
|
65729
|
-
currentChunk++;
|
|
65730
|
-
currentChunkSize = (callData.length - 2) / 2;
|
|
65731
|
-
chunkedCalls[currentChunk] = [];
|
|
65732
|
-
}
|
|
65733
|
-
chunkedCalls[currentChunk] = [
|
|
65734
|
-
...chunkedCalls[currentChunk],
|
|
65735
|
-
{
|
|
65736
|
-
allowFailure: true,
|
|
65737
|
-
callData,
|
|
65738
|
-
target: address
|
|
65739
|
-
}
|
|
65740
|
-
];
|
|
65741
|
-
} catch (err) {
|
|
65742
|
-
const error = viem.getContractError(err, {
|
|
65743
|
-
abi: abi32,
|
|
65744
|
-
address,
|
|
65745
|
-
args,
|
|
65746
|
-
docsPath: "/docs/contract/multicall",
|
|
65747
|
-
functionName
|
|
65748
|
-
});
|
|
65749
|
-
if (!allowFailure) throw error;
|
|
65750
|
-
chunkedCalls[currentChunk] = [
|
|
65751
|
-
...chunkedCalls[currentChunk],
|
|
65752
|
-
{
|
|
65753
|
-
allowFailure: true,
|
|
65754
|
-
callData: "0x",
|
|
65755
|
-
target: address
|
|
65756
|
-
}
|
|
65757
|
-
];
|
|
65758
|
-
}
|
|
65759
|
-
}
|
|
65760
|
-
const aggregate3Results = await Promise.allSettled(
|
|
65761
|
-
chunkedCalls.map(
|
|
65762
|
-
(calls) => utils.getAction(
|
|
65763
|
-
client,
|
|
65764
|
-
actions.simulateContract,
|
|
65765
|
-
"simulateContract"
|
|
65766
|
-
)({
|
|
65767
|
-
account,
|
|
65768
|
-
abi: viem.multicall3Abi,
|
|
65769
|
-
address: multicallAddress,
|
|
65770
|
-
args: [calls],
|
|
65771
|
-
blockNumber,
|
|
65772
|
-
blockTag,
|
|
65773
|
-
// does not infer well that either blockNumber or blockTag must be present
|
|
65774
|
-
functionName: "aggregate3",
|
|
65775
|
-
stateOverride,
|
|
65776
|
-
gas
|
|
65777
|
-
})
|
|
65778
|
-
)
|
|
65779
|
-
);
|
|
65780
|
-
const results = [];
|
|
65781
|
-
for (let i = 0; i < aggregate3Results.length; i++) {
|
|
65782
|
-
const result = aggregate3Results[i];
|
|
65783
|
-
if (result.status === "rejected") {
|
|
65784
|
-
if (!allowFailure) {
|
|
65785
|
-
throw result.reason;
|
|
65786
|
-
}
|
|
65787
|
-
for (const _i of chunkedCalls[i]) {
|
|
65788
|
-
results.push({
|
|
65789
|
-
status: "failure",
|
|
65790
|
-
error: result.reason,
|
|
65791
|
-
result: undefined
|
|
65792
|
-
});
|
|
65793
|
-
}
|
|
65794
|
-
continue;
|
|
65795
|
-
}
|
|
65796
|
-
const aggregate3Result = result.value.result;
|
|
65797
|
-
for (let j = 0; j < aggregate3Result.length; j++) {
|
|
65798
|
-
const { returnData, success } = aggregate3Result[j];
|
|
65799
|
-
const { callData } = chunkedCalls[i][j];
|
|
65800
|
-
const { abi: abi32, address, functionName, args } = contracts[results.length];
|
|
65801
|
-
try {
|
|
65802
|
-
if (callData === "0x") throw new viem.AbiDecodingZeroDataError();
|
|
65803
|
-
if (!success) throw new viem.RawContractError({ data: returnData });
|
|
65804
|
-
const result2 = viem.decodeFunctionResult({
|
|
65805
|
-
abi: abi32,
|
|
65806
|
-
args,
|
|
65807
|
-
data: returnData,
|
|
65808
|
-
functionName
|
|
65809
|
-
});
|
|
65810
|
-
results.push(allowFailure ? { result: result2, status: "success" } : result2);
|
|
65811
|
-
} catch (err) {
|
|
65812
|
-
const error = viem.getContractError(err, {
|
|
65813
|
-
abi: abi32,
|
|
65814
|
-
address,
|
|
65815
|
-
args,
|
|
65816
|
-
docsPath: "/docs/contract/multicall",
|
|
65817
|
-
functionName
|
|
65818
|
-
});
|
|
65819
|
-
if (!allowFailure) throw error;
|
|
65820
|
-
results.push({ error, result: undefined, status: "failure" });
|
|
65821
|
-
}
|
|
65822
|
-
}
|
|
65823
|
-
}
|
|
65824
|
-
if (results.length !== contracts.length)
|
|
65825
|
-
throw new viem.BaseError("multicall results mismatch");
|
|
65826
|
-
return results;
|
|
65827
|
-
}
|
|
65828
65824
|
|
|
65829
65825
|
// src/sdk/market/MarketRegister.ts
|
|
65830
65826
|
var MarketRegister = class extends SDKConstruct {
|
|
65831
65827
|
#logger;
|
|
65832
65828
|
/**
|
|
65833
|
-
* Mapping pool.address ->
|
|
65829
|
+
* Mapping pool.address -> MarketSuite
|
|
65834
65830
|
*/
|
|
65835
65831
|
#markets = new AddressMap();
|
|
65836
65832
|
constructor(sdk, markets) {
|
|
@@ -65839,7 +65835,7 @@ var MarketRegister = class extends SDKConstruct {
|
|
|
65839
65835
|
for (const data of markets ?? []) {
|
|
65840
65836
|
this.#markets.upsert(
|
|
65841
65837
|
data.pool.baseParams.addr,
|
|
65842
|
-
new
|
|
65838
|
+
new MarketSuite(this.sdk, data)
|
|
65843
65839
|
);
|
|
65844
65840
|
}
|
|
65845
65841
|
}
|
|
@@ -65899,7 +65895,7 @@ var MarketRegister = class extends SDKConstruct {
|
|
|
65899
65895
|
for (const data of markets) {
|
|
65900
65896
|
this.#markets.upsert(
|
|
65901
65897
|
data.pool.baseParams.addr,
|
|
65902
|
-
new
|
|
65898
|
+
new MarketSuite(this.sdk, data)
|
|
65903
65899
|
);
|
|
65904
65900
|
}
|
|
65905
65901
|
this.#logger?.info(`loaded ${markets.length} markets`);
|
|
@@ -73760,12 +73756,12 @@ exports.CreditConfiguratorV300Contract = CreditConfiguratorV300Contract;
|
|
|
73760
73756
|
exports.CreditConfiguratorV310Contract = CreditConfiguratorV310Contract;
|
|
73761
73757
|
exports.CreditFacadeV300Contract = CreditFacadeV300Contract;
|
|
73762
73758
|
exports.CreditFacadeV310Contract = CreditFacadeV310Contract;
|
|
73763
|
-
exports.CreditFactory = CreditFactory;
|
|
73764
73759
|
exports.CreditManagerData_Legacy = CreditManagerData_Legacy;
|
|
73765
73760
|
exports.CreditManagerV300Contract = CreditManagerV300Contract;
|
|
73766
73761
|
exports.CreditManagerV310Contract = CreditManagerV310Contract;
|
|
73767
73762
|
exports.CreditSession = CreditSession;
|
|
73768
73763
|
exports.CreditSessionFiltered = CreditSessionFiltered;
|
|
73764
|
+
exports.CreditSuite = CreditSuite;
|
|
73769
73765
|
exports.Curve2AssetsAdapterContract = Curve2AssetsAdapterContract;
|
|
73770
73766
|
exports.Curve3AssetsAdapterContract = Curve3AssetsAdapterContract;
|
|
73771
73767
|
exports.Curve3CrvUnderlyingTokenIndex = Curve3CrvUnderlyingTokenIndex;
|
|
@@ -73806,8 +73802,8 @@ exports.MAX_UINT256 = MAX_UINT256;
|
|
|
73806
73802
|
exports.MELLOW_COLLECTOR = MELLOW_COLLECTOR;
|
|
73807
73803
|
exports.MIN_INT96 = MIN_INT96;
|
|
73808
73804
|
exports.MULTICALL_ADDRESS = MULTICALL_ADDRESS;
|
|
73809
|
-
exports.MarketFactory = MarketFactory;
|
|
73810
73805
|
exports.MarketRegister = MarketRegister;
|
|
73806
|
+
exports.MarketSuite = MarketSuite;
|
|
73811
73807
|
exports.MellowLRTPriceFeedContract = MellowLRTPriceFeedContract;
|
|
73812
73808
|
exports.MellowVaultAdapterContract = MellowVaultAdapterContract;
|
|
73813
73809
|
exports.NOT_DEPLOYED = NOT_DEPLOYED;
|