Skip to content

Commit

Permalink
Merge pull request #231 from ar-io/gateway-types
Browse files Browse the repository at this point in the history
fix(types): add `totalEligibleGateways` to `AoEpochDistributionData` …
  • Loading branch information
dtfiedler authored Oct 15, 2024
2 parents 2a42ba4 + 78cf932 commit 7eaa504
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 9 deletions.
38 changes: 30 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ const demandFactor = await io.getDemandFactor();

#### `getObservations({ epochIndex })`

Returns the epoch-indexed observation list.
Returns the epoch-indexed observation list. If no epoch index is provided, the current epoch is used.

```typescript
const io = IO.init();
Expand Down Expand Up @@ -625,23 +625,34 @@ const observations = await io.getObservations();

#### `getDistributions({ epochIndex })`

Returns the current rewards distribution information.
Returns the current rewards distribution information. If no epoch index is provided, the current epoch is used.

```typescript
const io = IO.init();
const distributions = await io.getDistributions();
const distributions = await io.getDistributions({ epochIndex: 0 });
```

<details>
<summary>Output</summary>

```json
{
"totalEligibleGateways": 1,
"totalEligibleRewards": 100000000,
"totalEligibleObserverReward": 100000000,
"totalEligibleGatewayReward": 100000000,
"totalDistributedRewards": 100000000,
"distributedTimestamp": 1720720621424,
"rewards": {
"IPdwa3Mb_9pDD8c2IaJx6aad51Ss-_TfStVwBuhtXMs": 100000000
"eligible": {
"IPdwa3Mb_9pDD8c2IaJx6aad51Ss-_TfStVwBuhtXMs": {
"operatorReward": 100000000,
"delegateRewards": {}
}
},
"distributed": {
"IPdwa3Mb_9pDD8c2IaJx6aad51Ss-_TfStVwBuhtXMs": 100000000
}
}
}
```
Expand All @@ -650,7 +661,7 @@ const distributions = await io.getDistributions();

#### `getEpoch({ epochIndex })`

Returns the epoch data for the specified block height.
Returns the epoch data for the specified block height. If no epoch index is provided, the current epoch is used.

```typescript
const io = IO.init();
Expand Down Expand Up @@ -693,11 +704,22 @@ const epoch = await io.getEpoch({ epochIndex: 0 });
}
],
"distributions": {
"distributedTimestamp": 1752256702026,
"totalEligibleGateways": 1,
"totalEligibleRewards": 100000000,
"totoalDistributedRewards": 100000000,
"totalEligibleObserverReward": 100000000,
"totalEligibleGatewayReward": 100000000,
"totalDistributedRewards": 100000000,
"distributedTimestamp": 1720720621424,
"rewards": {
"IPdwa3Mb_9pDD8c2IaJx6aad51Ss-_TfStVwBuhtXMs": 100000000
"eligible": {
"IPdwa3Mb_9pDD8c2IaJx6aad51Ss-_TfStVwBuhtXMs": {
"operatorReward": 100000000,
"delegateRewards": {}
}
},
"distributed": {
"IPdwa3Mb_9pDD8c2IaJx6aad51Ss-_TfStVwBuhtXMs": 100000000
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export type AoEpochDistributionRewards = {

export type AoEpochDistributionData = {
rewards: AoEpochDistributionRewards;
totalEligibleGateways: number;
totalEligibleRewards: number;
totalEligibleObserverReward: number;
totalEligibleGatewayReward: number;
Expand Down
7 changes: 6 additions & 1 deletion tests/e2e/cjs/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,16 @@ describe('IO', async () => {
assert.ok(arns);
});

it('should be able to get the current epoch', async () => {
it('should be able to get the current epoch using getCurrentEpoch', async () => {
const epoch = await io.getCurrentEpoch();
assert.ok(epoch);
});

it('should be able to get the current epoch using getEpoch', async () => {
const epoch = await io.getEpoch({ epochIndex: 0 });
assert.ok(epoch);
});

it('should be able to get epoch-settings', async () => {
const epochSettings = await io.getEpochSettings();
assert.ok(epochSettings);
Expand Down
25 changes: 25 additions & 0 deletions tests/e2e/esm/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,31 @@ describe('IO', async () => {
}
});

it('should be able to get current epoch distributions', async () => {
const distributions = await io.getDistributions();
assert.ok(distributions);
});

it('should be able to get epoch distributions at a specific epoch', async () => {
const distributions = await io.getDistributions({ epochIndex: 0 });
assert.ok(distributions);
});

it('should be able to get current epoch observations', async () => {
const observations = await io.getObservations();
assert.ok(observations);
});

it('should be able to get epoch observations at a specific epoch', async () => {
const observations = await io.getObservations({ epochIndex: 0 });
assert.ok(observations);
});

it('should be able to get current demand factor', async () => {
const demandFactor = await io.getDemandFactor();
assert.ok(demandFactor);
});

it('should be able to create IOWriteable with valid signers', async () => {
for (const signer of signers) {
const io = IO.init({ signer });
Expand Down

0 comments on commit 7eaa504

Please sign in to comment.