Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 33 additions & 18 deletions blockchain/MNDContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -788,14 +788,19 @@ export const MNDContractAbi = [
type: 'address',
},
{
internalType: 'uint256[]',
name: 'epochs',
type: 'uint256[]',
internalType: 'uint256',
name: 'fromEpoch',
type: 'uint256',
},
{
internalType: 'uint8[]',
name: 'availabilies',
type: 'uint8[]',
internalType: 'uint256',
name: 'toEpoch',
type: 'uint256',
},
{
internalType: 'bytes',
name: 'packedAvailabilities',
type: 'bytes',
},
],
internalType: 'struct ComputeRewardsParams[]',
Expand Down Expand Up @@ -851,14 +856,19 @@ export const MNDContractAbi = [
type: 'address',
},
{
internalType: 'uint256[]',
name: 'epochs',
type: 'uint256[]',
internalType: 'uint256',
name: 'fromEpoch',
type: 'uint256',
},
{
internalType: 'uint256',
name: 'toEpoch',
type: 'uint256',
},
{
internalType: 'uint8[]',
name: 'availabilies',
type: 'uint8[]',
internalType: 'bytes',
name: 'packedAvailabilities',
type: 'bytes',
},
],
internalType: 'struct ComputeRewardsParams[]',
Expand Down Expand Up @@ -1738,14 +1748,19 @@ export const MNDContractAbi = [
type: 'address',
},
{
internalType: 'uint256[]',
name: 'epochs',
type: 'uint256[]',
internalType: 'uint256',
name: 'fromEpoch',
type: 'uint256',
},
{
internalType: 'uint256',
name: 'toEpoch',
type: 'uint256',
},
{
internalType: 'uint8[]',
name: 'availabilies',
type: 'uint8[]',
internalType: 'bytes',
name: 'packedAvailabilities',
type: 'bytes',
},
],
internalType: 'struct ComputeRewardsParams',
Expand Down
18 changes: 15 additions & 3 deletions lib/api/blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -607,13 +607,24 @@ const getMndOrGndLicenseRewardsBreakdown = async (
epochs_vals = epochs_vals.slice(start);
}

if (epochsToClaim !== epochs.length || epochsToClaim !== epochs_vals.length) {
const epochsAreContiguous = epochs.every((epoch, index) => epoch === firstEpochToClaim + index);

if (
epochsToClaim !== epochs.length ||
epochsToClaim !== epochs_vals.length ||
!epochsAreContiguous ||
epochs[0] !== firstEpochToClaim ||
epochs[epochs.length - 1] !== currentEpoch - 1
) {
return {
claimableAmount: undefined,
};
}

const publicClient = await getPublicClient();
const packedAvailabilities = `0x${epochs_vals
.map((availability) => availability.toString(16).padStart(2, '0'))
.join('')}` as `0x${string}`;

let result: ReadContractReturnType<typeof MNDContractAbi, 'calculateRewards'> | undefined;

Expand All @@ -627,8 +638,9 @@ const getMndOrGndLicenseRewardsBreakdown = async (
{
licenseId,
nodeAddress: license.nodeAddress,
epochs: epochs.map((epoch) => BigInt(epoch)),
availabilies: epochs_vals,
fromEpoch: BigInt(firstEpochToClaim),
toEpoch: BigInt(currentEpoch - 1),
packedAvailabilities,
},
],
],
Expand Down
5 changes: 3 additions & 2 deletions typedefs/blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ type CachedLicense = {
type ComputeParam = {
licenseId: bigint;
nodeAddress: `0x${string}`;
epochs: bigint[];
availabilies: number[];
fromEpoch: bigint;
toEpoch: bigint;
packedAvailabilities: `0x${string}`;
};

type OraclesAvailabilityResult = {
Expand Down
Loading