4

On the parachain auction page. IIUC, there isn't any on-chain storage to store these values. How can I get that?

enter image description here

2 Answers 2

5

So for clarity we wrote out a lot of parachain auctions, leases, crowdloan logic in substrate-api-sidecar to which you can checkout if you want more information about what you can query and grab.

Okay so to the question above, here is some code to get the leasePeriods.

const apiAt = api.at(<some_block_hash>);

const auctionInfoOpt = apiAt.query.auctions.auctionInfo<Option<Vec<BlockNumber>>>();

let leasePeriodIndex: BlockNumber | null;
if (auctionInfoOpt.isSome) {
    [leasePeriodIndex, _] = auctionInfoOpt.unwrap();
}

const leasePeriodsPerSlot = apiAt.consts.auctions.leasePeriodsPerSlot.toNumber()

const leasePeriods = leasePeriodIndex !== null
    ? Array(leasePeriodsPerSlot)
            .fill(0)
            .map((_, i) => i + (leasePeriodIndex as BN).toNumber())
    : null;

console.log(leasePeriods)

This will yield a result like:

[
        "31",
        "32",
        "33",
        "34",
        "35",
        "36",
        "37"
]
2
  • Sorry, I updated the screenshot. I mean a parachain could also bid for 31 ~ 35, 32 ~ 33, 30, etc. Your algorithm just count the leases.
    – AurevoirXavier
    Jun 11, 2023 at 17:33
  • @AurevoirXavier Ahh okay makes sense thanks for updating the picture, AFAIK if you want to get the leases for a specific parachain you can use apiAt.query.slots.leases(<para_id>) which will return the type: Vec<Option<ITuple<[AccountId, BalanceOf]>>>. You can take then take the size of that vector, and increment from the current leasePeriodIndex. On ways to calculate the index you can find that here.
    – Tarik Gul
    Jun 12, 2023 at 13:48
0

I'm not sure if this is correct.

It reads from the auctions.winning: Option<[Option<(AccountId32,u32,u128)>;36]>.

And the result is:

[
      null
      null
      null
      null
      null
      null
      null
      null
      null
      null
      null
      null
      null
      null
      [
        xxx
        xxx
        xxx
      ]
      null
      null
      null
      null
      null
      null
      null
      null
      null
      null
      null
      null
      null
      null
      null
      null
      null
      null
      null
      null
      null
]

According to the slot range:

// pub enum SlotRange {
//  ZeroZero,       0
//  ZeroOne,        1
//  ZeroTwo,        2
//  ZeroThree,      3
//  ZeroFour,       4
//  ZeroFive,       5
//  ZeroSix,        6
//  ZeroSeven,      7
//  OneOne,         8
//  OneTwo,         9
//  OneThree,       10
//  OneFour,        11
//  OneFive,        12
//  OneSix,         13
//  OneSeven,       14
//  TwoTwo,         15
//  TwoThree,       16
//  TwoFour,        17
//  TwoFive,        18
//  TwoSix,         19
//  TwoSeven,       20
//  ThreeThree,     21
//  ThreeFour,      22
//  ThreeFive,      23
//  ThreeSix,       24
//  ThreeSeven,     25
//  FourFour,       26
//  FourFive,       27
//  FourSix,        28
//  FourSeven,      29
//  FiveFive,       30
//  FiveSix,        31
//  FiveSeven,      32
//  SixSix,         33
//  SixSeven,       34
//  SevenSeven,     35
// }

It's OneSeven. And this auction's start index is 30.

So, 30 + 1 ~ 30 + 7.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.