@morpho-dev/router 0.1.17 → 0.1.18

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.
@@ -487,8 +487,12 @@ var chains = {
487
487
  [
488
488
  "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
489
489
  // USDC
490
- "0x6B175474E89094C44Da98b954EedeAC495271d0F"
490
+ "0x6B175474E89094C44Da98b954EedeAC495271d0F",
491
491
  // DAI
492
+ "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
493
+ // WETH
494
+ "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599"
495
+ // WBTC
492
496
  ].map((address) => address.toLowerCase())
493
497
  ),
494
498
  morpho: "0x0000000000000000000000000000000000000000",
@@ -511,8 +515,12 @@ var chains = {
511
515
  [
512
516
  "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
513
517
  // USDC
514
- "0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb"
518
+ "0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb",
515
519
  // DAI
520
+ "0x4200000000000000000000000000000000000006",
521
+ // WETH
522
+ "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599"
523
+ // WBTC
516
524
  ].map((address) => address.toLowerCase())
517
525
  ),
518
526
  morpho: "0x0000000000000000000000000000000000000000",
@@ -535,8 +543,12 @@ var chains = {
535
543
  [
536
544
  "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
537
545
  // USDC
538
- "0x6B175474E89094C44Da98b954EedeAC495271d0F"
546
+ "0x6B175474E89094C44Da98b954EedeAC495271d0F",
539
547
  // DAI
548
+ "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
549
+ // WETH
550
+ "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599"
551
+ // WBTC
540
552
  ].map((address) => address.toLowerCase())
541
553
  ),
542
554
  morpho: "0x11a002d45db720ed47a80d2f3489cba5b833eaf5",
@@ -560,8 +572,12 @@ var chains = {
560
572
  [
561
573
  "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
562
574
  // USDC
563
- "0x6B175474E89094C44Da98b954EedeAC495271d0F"
575
+ "0x6B175474E89094C44Da98b954EedeAC495271d0F",
564
576
  // DAI
577
+ "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
578
+ // WETH
579
+ "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599"
580
+ // WBTC
565
581
  ].map((address) => address.toLowerCase())
566
582
  ),
567
583
  morpho: "0x23DFBc4B8B80C14CC5e25011B8491f268395BAd6",
@@ -1270,39 +1286,92 @@ function fromSnakeCase3(input) {
1270
1286
  function toSnakeCase2(offer) {
1271
1287
  return toSnakeCase(offer);
1272
1288
  }
1273
- function random2() {
1274
- const loanToken = privateKeyToAccount(generatePrivateKey()).address;
1275
- const maturity = from5("end_of_month");
1276
- const expiry = from5("end_of_week") - 1;
1277
- const lltv = from3(0.965);
1289
+ function random2(config) {
1290
+ const chain = config?.chains ? config.chains[Math.floor(Math.random() * config.chains.length)] : chains.ethereum;
1291
+ const loanToken = config?.loanTokens ? config.loanTokens[Math.floor(Math.random() * config.loanTokens.length)] : privateKeyToAccount(generatePrivateKey()).address;
1292
+ const collateralCandidates = config?.collateralTokens ? config.collateralTokens.filter((a) => a !== loanToken) : [privateKeyToAccount(generatePrivateKey()).address];
1293
+ const collateralAsset = collateralCandidates[Math.floor(Math.random() * collateralCandidates.length)];
1294
+ const maturityOption = weightedChoice([
1295
+ ["end_of_month", 1],
1296
+ ["end_of_next_month", 1]
1297
+ ]);
1298
+ const maturity = config?.maturity ?? from5(maturityOption);
1299
+ const lltv = from3(
1300
+ weightedChoice([
1301
+ [0.385, 1],
1302
+ [0.5, 1],
1303
+ [0.625, 2],
1304
+ [0.77, 8],
1305
+ [0.86, 10],
1306
+ [0.915, 8],
1307
+ [0.945, 6],
1308
+ [0.965, 4],
1309
+ [0.98, 2]
1310
+ ])
1311
+ );
1312
+ const buy = config?.buy !== void 0 ? config.buy : Math.random() > 0.5;
1313
+ const ONE = 1000000000000000000n;
1314
+ const qMin = buy ? 16 : 4;
1315
+ const qMax = buy ? 32 : 16;
1316
+ const len = qMax - qMin + 1;
1317
+ const ratePairs = Array.from(
1318
+ { length: len },
1319
+ (_, idx) => {
1320
+ const q = qMin + idx;
1321
+ const scaledRate = BigInt(q) * (ONE / 4n);
1322
+ const weight = buy ? 1 + idx : 1 + (len - 1 - idx);
1323
+ return [scaledRate, weight];
1324
+ }
1325
+ );
1326
+ const rate = config?.rate ?? weightedChoice(ratePairs);
1327
+ const loanTokenDecimals = config?.assetsDecimals?.[loanToken] ?? 18;
1328
+ const unit = BigInt(10) ** BigInt(loanTokenDecimals);
1329
+ const amountBase = BigInt(100 + Math.floor(Math.random() * (1e6 - 100 + 1)));
1330
+ const assetsScaled = config?.assets ?? amountBase * unit;
1331
+ const consumed = config?.consumed !== void 0 ? config.consumed : Math.random() < 0.8 ? 0n : assetsScaled * BigInt(1 + Math.floor(Math.random() * 900)) / 1000n;
1332
+ const callbackBySide = (() => {
1333
+ if (buy) return { address: zeroAddress, data: "0x", gasLimit: 0n };
1334
+ const sellCallbackAddress = WhitelistedCallbackAddresses["sell_erc20_callback" /* SellERC20Callback */][0].toLowerCase();
1335
+ const amount = assetsScaled * 1000000000000000000000n;
1336
+ const data = encodeSellERC20Callback({
1337
+ collaterals: [collateralAsset],
1338
+ amounts: [amount]
1339
+ });
1340
+ return { address: sellCallbackAddress, data, gasLimit: 500000n };
1341
+ })();
1278
1342
  const offer = from7({
1279
- offering: privateKeyToAccount(generatePrivateKey()).address,
1280
- assets: BigInt(Math.floor(Math.random() * 1e6)),
1281
- rate: BigInt(Math.floor(Math.random() * 1e6)),
1343
+ offering: config?.offering ?? privateKeyToAccount(generatePrivateKey()).address,
1344
+ assets: assetsScaled,
1345
+ rate,
1282
1346
  maturity,
1283
- expiry,
1284
- start: expiry - 10,
1347
+ expiry: config?.expiry ?? maturity - 1,
1348
+ start: config?.start ?? maturity - 10,
1285
1349
  nonce: BigInt(Math.floor(Math.random() * 1e6)),
1286
- buy: Math.random() > 0.5,
1287
- chainId: 1n,
1350
+ buy,
1351
+ chainId: chain.id,
1288
1352
  loanToken,
1289
- collaterals: [
1353
+ collaterals: config?.collaterals ?? [
1290
1354
  from4({
1291
- asset: zeroAddress,
1355
+ asset: collateralAsset,
1292
1356
  oracle: zeroAddress,
1293
1357
  lltv
1294
1358
  })
1295
1359
  ],
1296
- callback: {
1297
- address: zeroAddress,
1298
- data: "0x",
1299
- gasLimit: 0n
1300
- },
1301
- consumed: 0n,
1360
+ callback: config?.callback ?? callbackBySide,
1361
+ consumed,
1302
1362
  blockNumber: Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)
1303
1363
  });
1304
1364
  return offer;
1305
1365
  }
1366
+ var weightedChoice = (pairs) => {
1367
+ const total = pairs.reduce((sum, [, weight]) => sum + weight, 0);
1368
+ let roll = Math.random() * total;
1369
+ for (const [value, weight] of pairs) {
1370
+ roll -= weight;
1371
+ if (roll < 0) return value;
1372
+ }
1373
+ return pairs[0][0];
1374
+ };
1306
1375
  var domain = (chainId) => ({
1307
1376
  chainId,
1308
1377
  verifyingContract: zeroAddress