Skip to content

Commit

Permalink
Merge pull request #205 from ar-io/PE-6684-get-registration-fees
Browse files Browse the repository at this point in the history
feat(PE-6684): add api for querying get registration fees
  • Loading branch information
dtfiedler authored Sep 25, 2024
2 parents 8cd1e0f + 877b03f commit 1987e41
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/common/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
AoGateway,
AoIORead,
AoIOWrite,
AoRegistrationFees,
EpochInput,
isProcessConfiguration,
isProcessIdConfiguration,
Expand Down Expand Up @@ -572,6 +573,12 @@ export class IOReadable implements AoIORead {
tags: prunedTags,
});
}

async getRegistrationFees(): Promise<AoRegistrationFees> {
return this.process.read<AoRegistrationFees>({
tags: [{ name: 'Action', value: 'Get-Registration-Fees' }],
});
}
}

export class IOWriteable extends IOReadable implements AoIOWrite {
Expand Down
15 changes: 14 additions & 1 deletion src/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,19 @@ export type EpochInput =

// AO/IO Contract
export type AoBalances = Record<WalletAddress, number>;
export type AoFees = Record<string, number>;
const nameLengthArray = [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
] as const;
const leaseLengthArray = [1, 2, 3, 4, 5] as const;
export type AoRegistrationFees = Record<
(typeof nameLengthArray)[number],
{
lease: Record<(typeof leaseLengthArray)[number], number>;
permabuy: number;
}
>;
export type AoObservations = Record<number, AoEpochObservationData>;
export type AoEpochIndex = number;

Expand Down Expand Up @@ -337,6 +349,7 @@ export interface AoIORead {
name?: string;
quantity?: number;
}): Promise<number>;
getRegistrationFees(): Promise<AoRegistrationFees>;
}

export interface AoIOWrite extends AoIORead {
Expand Down
14 changes: 14 additions & 0 deletions tests/e2e/cjs/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,20 @@ describe('IO', async () => {
assert.ok(tokenCost);
});

it('should be able to get registration fees', async () => {
const registrationFees = await io.getRegistrationFees();
assert(registrationFees);
assert.equal(Object.keys(registrationFees).length, 51);
for (const nameLength of Object.keys(registrationFees)) {
// assert lease is length of 5
assert(registrationFees[nameLength]['lease']['1'] > 0);
assert(registrationFees[nameLength]['lease']['2'] > 0);
assert(registrationFees[nameLength]['lease']['3'] > 0);
assert(registrationFees[nameLength]['lease']['4'] > 0);
assert(registrationFees[nameLength]['lease']['5'] > 0);
assert(registrationFees[nameLength]['permabuy'] > 0);
}
});
it('should be able to create IOWriteable with valid signers', async () => {
for (const signer of signers) {
const io = IO.init({ signer });
Expand Down
15 changes: 15 additions & 0 deletions tests/e2e/esm/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,21 @@ describe('IO', async () => {
assert.ok(tokenCost);
});

it('should be able to get registration fees', async () => {
const registrationFees = await io.getRegistrationFees();
assert(registrationFees);
assert.equal(Object.keys(registrationFees).length, 51);
for (const nameLength of Object.keys(registrationFees)) {
// assert lease is length of 5
assert(registrationFees[nameLength]['lease']['1'] > 0);
assert(registrationFees[nameLength]['lease']['2'] > 0);
assert(registrationFees[nameLength]['lease']['3'] > 0);
assert(registrationFees[nameLength]['lease']['4'] > 0);
assert(registrationFees[nameLength]['lease']['5'] > 0);
assert(registrationFees[nameLength]['permabuy'] > 0);
}
});

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 1987e41

Please sign in to comment.