Skip to content

Commit

Permalink
feat(auctions): add auctions apis
Browse files Browse the repository at this point in the history
  • Loading branch information
Atticus committed Mar 15, 2024
1 parent 1b6772e commit faf08c5
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 4 deletions.
68 changes: 68 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,74 @@ const previousEpochObservers = arIO.getPrescribedObservers({
// ]
```

### `getAuction({ domain, evaluationOptions })`

Return the auction info for the supplied domain, be it in auction, registered, or available to auction.

```typescript

const auction = await arIO.getAuction({ domain });

// output

// {
// "name": "ardrive",
// "initiator": "",
// "contractTxId": "",
// "startPrice": 89950,
// "floorPrice": 1799,
// "startHeight": 1384196,
// "endHeight": 1394276,
// "type": "lease",
// "years": 1,
// "isActive": false,
// "isAvailableForAuction": false,
// "isRequiredToBeAuctioned": false,
// "currentPrice": 1799,
// "prices": {
// "1384196": 89950,
// "1384226": 88930,
// "1384256": 87922,
// ...
// "1394216": 1921,
// "1394246": 1899,
// "1394276": 1877
// }
// }
```

### `getAuctions({ evauluationOptions })`

Retrieves all active auctions.

```typescript

const auctions = await arIO.getAuctions({ evaluationOptions });

// output

// {
// "cyprien": {
// "contractTxId": "Fmhdc4f1rWK6Zn1W__7GNvWvo4d1FSze7rLK5AOnO5E",
// "endHeight": 1386879,
// "floorPrice": 4758777913,
// "initiator": "UPJHTNsaKcC6baqLFHMAMI7daWPIG3NDDfFQ2s2h8T0",
// "startHeight": 1376799,
// "startPrice": 237938895627,
// "type": "permabuy"
// },
// "saktinaga": {
// "contractTxId": "nl8heYyDxKowujaDqbsPkjALzULYG8T0z3J91CdWDIM",
// "endHeight": 1386834,
// "floorPrice": 2379388956,
// "initiator": "TE0zVR32RF5qFAO8K50-pEivZpM_s35HK-dex-5d-IU",
// "startHeight": 1376754,
// "startPrice": 118969447813,
// "type": "permabuy"
// }
// }


## Developers

### Requirements
Expand Down
4 changes: 4 additions & 0 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
*/
import {
ArIOState,
ArNSAuctionData,
ArNSNameData,
EpochDistributionData,
Gateway,
Observations,
RegistrationType,
WeightedObserver,
} from './contract-state.js';

Expand Down Expand Up @@ -100,6 +102,8 @@ export interface ArIOContract {
getDistributions({
evaluationOptions,
}: EvaluationParameters): Promise<EpochDistributionData>;
getAuctions({ evaluationOptions }: EvaluationParameters): Promise<Record<string, ArNSAuctionData>>;

Check failure on line 105 in src/common.ts

View workflow job for this annotation

GitHub Actions / build (18.x, lint)

Replace `·evaluationOptions` with `⏎····evaluationOptions,⏎·`

Check failure on line 105 in src/common.ts

View workflow job for this annotation

GitHub Actions / build (20.x, lint)

Replace `·evaluationOptions` with `⏎····evaluationOptions,⏎·`
getAuction({ domain, type, evaluationOptions }: EvaluationParameters<{ domain: string; type?: RegistrationType }>): Promise<ArNSAuctionData>

Check failure on line 106 in src/common.ts

View workflow job for this annotation

GitHub Actions / build (18.x, lint)

Replace `·domain,·type,·evaluationOptions·}:·EvaluationParameters<{·domain:·string;·type?:·RegistrationType·}>):·Promise<ArNSAuctionData>` with `⏎····domain,⏎····type,⏎····evaluationOptions,⏎··}:·EvaluationParameters<{⏎····domain:·string;⏎····type?:·RegistrationType;⏎··}>):·Promise<ArNSAuctionData>;`

Check failure on line 106 in src/common.ts

View workflow job for this annotation

GitHub Actions / build (20.x, lint)

Replace `·domain,·type,·evaluationOptions·}:·EvaluationParameters<{·domain:·string;·type?:·RegistrationType·}>):·Promise<ArNSAuctionData>` with `⏎····domain,⏎····type,⏎····evaluationOptions,⏎··}:·EvaluationParameters<{⏎····domain:·string;⏎····type?:·RegistrationType;⏎··}>):·Promise<ArNSAuctionData>;`
}

/* eslint-disable @typescript-eslint/no-explicit-any */
Expand Down
29 changes: 25 additions & 4 deletions src/common/ar-io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ import { ARNS_TESTNET_REGISTRY_TX } from '../constants.js';
import {
ArIOContract,
ArIOState,
ArNSAuctionData,
ArNSNameData,
EpochDistributionData,
EvaluationOptions,
EvaluationParameters,
Gateway,
Observations,
RegistrationType,
SmartWeaveContract,
WeightedObserver,
} from '../types.js';
Expand All @@ -31,11 +34,11 @@ import { RemoteContract } from './contracts/remote-contract.js';
// TODO: append this with other configuration options (e.g. local vs. remote evaluation)
export type ContractConfiguration =
| {
contract?: SmartWeaveContract<unknown>;
}
contract?: SmartWeaveContract<unknown>;

Check failure on line 37 in src/common/ar-io.ts

View workflow job for this annotation

GitHub Actions / build (18.x, lint)

Insert `··`

Check failure on line 37 in src/common/ar-io.ts

View workflow job for this annotation

GitHub Actions / build (20.x, lint)

Insert `··`
}

Check failure on line 38 in src/common/ar-io.ts

View workflow job for this annotation

GitHub Actions / build (18.x, lint)

Insert `··`

Check failure on line 38 in src/common/ar-io.ts

View workflow job for this annotation

GitHub Actions / build (20.x, lint)

Insert `··`
| {
contractTxId: string;
};
contractTxId: string;

Check failure on line 40 in src/common/ar-io.ts

View workflow job for this annotation

GitHub Actions / build (18.x, lint)

Insert `··`

Check failure on line 40 in src/common/ar-io.ts

View workflow job for this annotation

GitHub Actions / build (20.x, lint)

Insert `··`
};

Check failure on line 41 in src/common/ar-io.ts

View workflow job for this annotation

GitHub Actions / build (18.x, lint)

Insert `··`

Check failure on line 41 in src/common/ar-io.ts

View workflow job for this annotation

GitHub Actions / build (20.x, lint)

Insert `··`

function isContractConfiguration<T>(
config: ContractConfiguration,
Expand Down Expand Up @@ -215,4 +218,22 @@ export class ArIO implements ArIOContract {
});
return distributions;
}

async getAuction({ domain, type, evaluationOptions }: EvaluationParameters<{ domain: string; type?: RegistrationType }>): Promise<ArNSAuctionData> {

Check failure on line 222 in src/common/ar-io.ts

View workflow job for this annotation

GitHub Actions / build (18.x, lint)

Replace `·domain,·type,·evaluationOptions·}:·EvaluationParameters<{·domain:·string;·type?:·RegistrationType` with `⏎····domain,⏎····type,⏎····evaluationOptions,⏎··}:·EvaluationParameters<{⏎····domain:·string;⏎····type?:·RegistrationType;⏎·`

Check failure on line 222 in src/common/ar-io.ts

View workflow job for this annotation

GitHub Actions / build (20.x, lint)

Replace `·domain,·type,·evaluationOptions·}:·EvaluationParameters<{·domain:·string;·type?:·RegistrationType` with `⏎····domain,⏎····type,⏎····evaluationOptions,⏎··}:·EvaluationParameters<{⏎····domain:·string;⏎····type?:·RegistrationType;⏎·`
return this.contract.readInteraction({
functionName: 'auction',
inputs: {
name: domain,
type,
},
evaluationOptions,
});
}
async getAuctions({ evaluationOptions }: { evaluationOptions?: EvaluationOptions | Record<string, never> | undefined; }): Promise<Record<string, ArNSAuctionData>> {

Check failure on line 232 in src/common/ar-io.ts

View workflow job for this annotation

GitHub Actions / build (18.x, lint)

Replace `·evaluationOptions·}:·{·evaluationOptions?:·EvaluationOptions·|·Record<string,·never>·|·undefined;` with `⏎····evaluationOptions,⏎··}:·{⏎····evaluationOptions?:·EvaluationOptions·|·Record<string,·never>·|·undefined;⏎·`

Check failure on line 232 in src/common/ar-io.ts

View workflow job for this annotation

GitHub Actions / build (20.x, lint)

Replace `·evaluationOptions·}:·{·evaluationOptions?:·EvaluationOptions·|·Record<string,·never>·|·undefined;` with `⏎····evaluationOptions,⏎··}:·{⏎····evaluationOptions?:·EvaluationOptions·|·Record<string,·never>·|·undefined;⏎·`
const { auctions } = await this.contract.getContractState({
evaluationOptions,
});

return auctions

Check failure on line 237 in src/common/ar-io.ts

View workflow job for this annotation

GitHub Actions / build (18.x, lint)

Insert `;`

Check failure on line 237 in src/common/ar-io.ts

View workflow job for this annotation

GitHub Actions / build (20.x, lint)

Insert `;`
}
}
28 changes: 28 additions & 0 deletions tests/ar-io.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,32 @@ describe('ArIO Client', () => {
});
expect(distributions).toBeDefined();
});

it.each([
[{ sortKey: evaluateToSortKey.toString() }],
[{ blockHeight: evaluateToBlockHeight }],
])(
`should return auction for provided evaluation options: ${JSON.stringify('%s')}`,
async (evalTo) => {
const auction = await arIO.getAuction({
domain: "ardrive",
evaluationOptions: { evalTo },
});
expect(auction).toBeDefined();
},
);

it.each([
[{ sortKey: evaluateToSortKey.toString() }],
[{ blockHeight: evaluateToBlockHeight }],
])(
`should return auction for provided evaluation options: ${JSON.stringify('%s')}`,
async (evalTo) => {
const auctions = await arIO.getAuctions({
evaluationOptions: { evalTo },
});
expect(auctions).toBeDefined();
},
);

});

0 comments on commit faf08c5

Please sign in to comment.