From c674876fbdbe85299e7eff75ba0a89187610d00e Mon Sep 17 00:00:00 2001 From: dtfiedler Date: Fri, 12 Jul 2024 11:20:00 -0600 Subject: [PATCH] fix(types): remove deprecated types --- src/common.ts | 39 ----- src/common/ant.ts | 12 +- src/common/io.ts | 51 +++--- src/contract-state.ts | 305 ---------------------------------- src/io.ts | 372 ++++++++++++++++++++++++------------------ src/types.ts | 1 - src/utils/ao.ts | 18 +- 7 files changed, 258 insertions(+), 540 deletions(-) delete mode 100644 src/contract-state.ts diff --git a/src/common.ts b/src/common.ts index afab1946..cab11022 100644 --- a/src/common.ts +++ b/src/common.ts @@ -25,14 +25,6 @@ import { } from '@permaweb/aoconnect'; import { Signer } from 'arbundles'; -import { - AllowedProtocols, - GatewayConnectionSettings, - GatewayMetadata, - GatewayStakingSettings, -} from './contract-state.js'; -import { mIOToken } from './token.js'; - export type BlockHeight = number; export type SortKey = string; export type Timestamp = number; @@ -64,43 +56,12 @@ export type WriteParameters = WithSigner< export type AoMessageResult = { id: string }; -// Helper type to overwrite properties of A with B -type Overwrite = { - [K in keyof T]: K extends keyof U ? U[K] : T[K]; -}; - -export type JoinNetworkParams = Overwrite< - GatewayConnectionSettings & GatewayStakingSettings & GatewayMetadata, - { - minDelegatedStake: number | mIOToken; // TODO: this is for backwards compatibility - } ->; - -// Original type definition refined with proper field-specific types -export type UpdateGatewaySettingsParamsBase = { - allowDelegatedStaking?: boolean; - delegateRewardShareRatio?: number; - fqdn?: string; - label?: string; - minDelegatedStake?: number | mIOToken; // TODO: this is for backwards compatibility - eventually we'll drop number - note?: string; - port?: number; - properties?: string; - protocol?: AllowedProtocols; - autoStake?: boolean; - observerAddress?: WalletAddress; -}; - // Utility type to require at least one of the fields export type AtLeastOne< T, U = { [K in keyof T]-?: Record }, > = Partial & U[keyof U]; -// Define the type used for function parameters -export type UpdateGatewaySettingsParams = - AtLeastOne; - export interface HTTPClient { get({ endpoint, diff --git a/src/common/ant.ts b/src/common/ant.ts index d654fe57..d87d3b3a 100644 --- a/src/common/ant.ts +++ b/src/common/ant.ts @@ -15,8 +15,8 @@ * along with this program. If not, see . */ import { - ANTRecord, AoANTRead, + AoANTRecord, AoANTState, AoANTWrite, AoMessageResult, @@ -107,29 +107,29 @@ export class AoANTReadable implements AoANTRead { * ant.getRecord({ undername: "john" }); * ``` */ - async getRecord({ undername }: { undername: string }): Promise { + async getRecord({ undername }: { undername: string }): Promise { const tags = [ { name: 'Sub-Domain', value: undername }, { name: 'Action', value: 'Record' }, ]; - const record = await this.process.read({ + const record = await this.process.read({ tags, }); return record; } /** - * @returns {Promise>} All the undernames managed by the ANT. + * @returns {Promise>} All the undernames managed by the ANT. * @example * Get the current records * ```ts * ant.getRecords(); * ```` */ - async getRecords(): Promise> { + async getRecords(): Promise> { const tags = [{ name: 'Action', value: 'Records' }]; - const records = await this.process.read>({ + const records = await this.process.read>({ tags, }); return records; diff --git a/src/common/io.ts b/src/common/io.ts index 500d48e7..9cad01f9 100644 --- a/src/common/io.ts +++ b/src/common/io.ts @@ -17,12 +17,6 @@ import Arweave from 'arweave'; import { IO_TESTNET_PROCESS_ID } from '../constants.js'; -import { - ArNSReservedNameData, - EpochDistributionData, - EpochObservations, - WeightedObserver, -} from '../contract-state.js'; import { AoArNSNameData, AoEpochData, @@ -37,17 +31,21 @@ import { import { AoSigner, mIOToken } from '../token.js'; import { AoArNSNameDataWithName, + AoArNSReservedNameData, AoBalanceWithAddress, + AoEpochDistributionData, + AoEpochObservationData, AoGatewayWithAddress, + AoJoinNetworkParams, AoMessageResult, + AoUpdateGatewaySettingsParams, + AoWeightedObserver, ContractSigner, - JoinNetworkParams, OptionalSigner, PaginationParams, PaginationResult, ProcessConfiguration, TransactionId, - UpdateGatewaySettingsParams, WalletAddress, WithSigner, WriteOptions, @@ -243,9 +241,9 @@ export class IOReadable implements AoIORead { } async getArNSReservedNames(): Promise< - Record | Record + Record | Record > { - return this.process.read>({ + return this.process.read>({ tags: [{ name: 'Action', value: 'Reserved-Names' }], }); } @@ -254,8 +252,8 @@ export class IOReadable implements AoIORead { name, }: { name: string; - }): Promise { - return this.process.read({ + }): Promise { + return this.process.read({ tags: [ { name: 'Action', value: 'Reserved-Name' }, { name: 'Name', value: name }, @@ -354,7 +352,7 @@ export class IOReadable implements AoIORead { async getPrescribedObservers( epoch?: EpochInput, - ): Promise { + ): Promise { const allTags = [ { name: 'Action', value: 'Epoch-Prescribed-Observers' }, { @@ -385,7 +383,7 @@ export class IOReadable implements AoIORead { }): tag is { name: string; value: string } => tag.value !== undefined, ); - return this.process.read({ + return this.process.read({ tags: prunedTags, }); } @@ -426,7 +424,7 @@ export class IOReadable implements AoIORead { }); } - async getObservations(epoch?: EpochInput): Promise { + async getObservations(epoch?: EpochInput): Promise { const allTags = [ { name: 'Action', value: 'Epoch-Observations' }, { @@ -457,12 +455,12 @@ export class IOReadable implements AoIORead { }): tag is { name: string; value: string } => tag.value !== undefined, ); - return this.process.read({ + return this.process.read({ tags: prunedTags, }); } - async getDistributions(epoch?: EpochInput): Promise { + async getDistributions(epoch?: EpochInput): Promise { const allTags = [ { name: 'Action', value: 'Epoch-Distributions' }, { @@ -493,7 +491,7 @@ export class IOReadable implements AoIORead { }): tag is { name: string; value: string } => tag.value !== undefined, ); - return this.process.read({ + return this.process.read({ tags: prunedTags, }); } @@ -653,10 +651,7 @@ export class IOWriteable extends IOReadable implements AoIOWrite { protocol, autoStake, observerAddress, - }: Omit & { - observerAddress: string; - operatorStake: number | mIOToken; - }, + }: AoJoinNetworkParams, options?: WriteOptions, ): Promise { const { tags = [] } = options || {}; @@ -669,11 +664,11 @@ export class IOWriteable extends IOReadable implements AoIOWrite { }, { name: 'Allow-Delegated-Staking', - value: allowDelegatedStaking.toString(), + value: allowDelegatedStaking?.toString(), }, { name: 'Delegate-Reward-Share-Ratio', - value: delegateRewardShareRatio.toString(), + value: delegateRewardShareRatio?.toString(), }, { name: 'FQDN', @@ -685,7 +680,7 @@ export class IOWriteable extends IOReadable implements AoIOWrite { }, { name: 'Min-Delegated-Stake', - value: minDelegatedStake.valueOf().toString(), + value: minDelegatedStake?.valueOf().toString(), }, { name: 'Note', @@ -693,7 +688,7 @@ export class IOWriteable extends IOReadable implements AoIOWrite { }, { name: 'Port', - value: port.toString(), + value: port?.toString(), }, { name: 'Properties', @@ -705,7 +700,7 @@ export class IOWriteable extends IOReadable implements AoIOWrite { }, { name: 'Auto-Stake', - value: autoStake.toString(), + value: autoStake?.toString(), }, { name: 'Observer-Address', @@ -747,7 +742,7 @@ export class IOWriteable extends IOReadable implements AoIOWrite { protocol, autoStake, observerAddress, - }: UpdateGatewaySettingsParams, + }: AoUpdateGatewaySettingsParams, options?: WriteOptions, ): Promise { const { tags = [] } = options || {}; diff --git a/src/contract-state.ts b/src/contract-state.ts deleted file mode 100644 index eceac889..00000000 --- a/src/contract-state.ts +++ /dev/null @@ -1,305 +0,0 @@ -/** - * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -import { WalletAddress } from './common.js'; - -export type Balances = Record; -export type Fees = Record; -export type Observations = Record; - -export const ioContractReadInteractions = [ - 'gateway', - 'gateways', - 'prescribedObservers', - 'record', - 'auction', - 'balance', - 'epoch', - 'priceForInteraction', -] as const; - -export const ioContractWriteInteractions = [ - 'delegateStake', - 'decreaseDelegateStake', - 'joinNetwork', - 'increaseOperatorStake', - 'decreaseOperatorStake', - 'updateGatewaySettings', - 'saveObservations', - 'extendRecord', - 'buyRecord', - 'increaseUndernameCount', - 'transfer', -] as const; - -export const ioContractInteractions = [ - ...ioContractReadInteractions, - ...ioContractWriteInteractions, -] as const; - -export type IOContractReadInteractions = - (typeof ioContractReadInteractions)[number]; -export type IOContractWriteInteractions = - (typeof ioContractWriteInteractions)[number]; -export type IOContractInteractions = (typeof ioContractInteractions)[number]; - -export type IOContractInteractionsWithIOFees = Extract< - IOContractInteractions, - 'buyRecord' | 'extendRecord' | 'increaseUndernameCount' ->; - -export const AR_IO_CONTRACT_FUNCTIONS: Record = - { - GATEWAY: 'gateway', - GATEWAYS: 'gateways', - PRESCRIBED_OBSERVERS: 'prescribedObservers', - DELEGATE_STAKE: 'delegateStake', - DECREASE_DELEGATE_STAKE: 'decreaseDelegateStake', - JOIN_NETWORK: 'joinNetwork', - INCREASE_OPERATOR_STAKE: 'increaseOperatorStake', - DECREASE_OPERATOR_STAKE: 'decreaseOperatorStake', - UPDATE_GATEWAY_SETTINGS: 'updateGatewaySettings', - SAVE_OBSERVATIONS: 'saveObservations', - EXTEND_RECORD: 'extendRecord', - INCREASE_UNDERNAME_COUNT: 'increaseUndernameCount', - RECORD: 'record', - AUCTION: 'auction', - TRANSFER: 'transfer', - BALANCE: 'balance', - PRICE_FOR_INTERACTION: 'priceForInteraction', - EPOCH: 'epoch', - BUY_RECORD: 'buyRecord', - }; - -// Gateways - -export type Gateway = { - delegates: Record; - end: number; - observerWallet: WalletAddress; - operatorStake: number; - settings: GatewaySettings; - start: number; - stats: GatewayStats; - status: string; - totalDelegatedStake: number; - vaults: Record; - weights: ObserverWeights; -}; - -export type GatewayDelegate = { - delegatedStake: number; - start: number; - vaults: Record; -}; - -export type GatewayStakingSettings = { - allowDelegatedStaking: boolean; - delegateRewardShareRatio: number; - minDelegatedStake: number; - autoStake: boolean; -}; - -export type GatewayMetadata = { - label: string; - note: string; - properties: string; -}; - -export type GatewayConnectionSettings = { - fqdn: string; - port: number; - protocol: AllowedProtocols; -}; - -export type GatewaySettings = GatewayConnectionSettings & - GatewayStakingSettings & - GatewayMetadata; - -export type AllowedProtocols = 'https'; - -export type GatewayStats = { - prescribedEpochCount: number; - observedEpochCount: number; - totalEpochCount: number; - passedEpochCount: number; - failedEpochCount: number; - failedConsecutiveEpochs: number; - passedConsecutiveEpochs: number; -}; - -// Observations - -export type WeightedObserver = { - gatewayAddress: WalletAddress; - observerAddress: WalletAddress; - stake: number; - start: number; -} & ObserverWeights; - -export type ObserverWeights = { - stakeWeight: number; - tenureWeight: number; - gatewayRewardRatioWeight: number; - observerRewardRatioWeight: number; - compositeWeight: number; - normalizedCompositeWeight: number; -}; - -// Records -export type RegistrationType = 'lease' | 'permabuy'; -export type ArNSBaseNameData = { - contractTxId: string; // The ANT Contract used to manage this name - startTimestamp: number; // At what unix time (seconds since epoch) the lease starts - type: RegistrationType; - undernames: number; - purchasePrice: number; -}; - -export type ArNSPermabuyData = ArNSBaseNameData & { - type: 'permabuy'; -}; - -export type ArNSLeaseData = ArNSBaseNameData & { - type: 'lease'; - endTimestamp: number; // At what unix time (seconds since epoch) the lease ends -}; - -// TODO: break this up into union types to account for names that are permanently reserved -export type ArNSReservedNameData = { - target?: string; - endTimestamp?: number; -}; - -export type ArNSNameData = ArNSPermabuyData | ArNSLeaseData; - -// Vaults - -export type VaultData = { - balance: number; - start: number; - end: number; -}; - -// Balances - -export enum DENOMINATIONS { - IO = 'IO', - MIO = 'mIO', -} - -export type ReservedNameData = { - target?: string; // The target wallet address this name is reserved for - endTimestamp?: number; // At what unix time (seconds since epoch) this reserved name becomes available -}; - -export type ArNSBaseAuctionData = { - startPrice: number; - floorPrice: number; - startHeight: number; - endHeight: number; - type: RegistrationType; - initiator: string; - contractTxId: string; -}; - -export type ArNSLeaseAuctionData = ArNSBaseAuctionData & { - type: 'lease'; - years: 1; -}; - -export type ArNSPermabuyAuctionData = ArNSBaseAuctionData & { - type: 'permabuy'; -}; - -export type ArNSAuctionData = ArNSLeaseAuctionData | ArNSPermabuyAuctionData; - -export type DemandFactoringData = { - periodZeroBlockHeight: number; // TODO: The block height at which the contract was initialized - currentPeriod: number; - trailingPeriodPurchases: number[]; // Acts as a ring buffer of trailing period purchase counts - trailingPeriodRevenues: number[]; // Acts as a ring buffer of trailing period revenues - purchasesThisPeriod: number; - revenueThisPeriod: number; - demandFactor: number; - consecutivePeriodsWithMinDemandFactor: number; -}; - -export type EpochObservations = { - failureSummaries: Record; // an observers summary of all failed gateways in the epoch - reports: Record; // a reference point for the report submitted by this observer -}; - -export type EpochDistributionData = { - epochZeroStartHeight: number; - epochStartHeight: number; // the current epoch start height - epochEndHeight: number; // the current epoch end height - epochPeriod: number; - epochDistributionHeight: number; - epochBlockLength: number; -}; - -export type Vaults = Record; - -export type RegistryVaults = Record; - -export type PrescribedObservers = Record; - -export interface ArIOState { - balances: Balances; - name: string; // The friendly name of the token, shown in block explorers and marketplaces - records: Record; // The list of all ArNS names and their associated data - gateways: Record; // each gateway uses its public arweave wallet address to identify it in the gateway registry - fees: Fees; // starting list of all fees for purchasing ArNS names - reserved: Record; // list of all reserved names that are not allowed to be purchased at this time - auctions: Record; - lastTickedHeight: number; // periodicity management - demandFactoring: DemandFactoringData; - observations: Observations; - distributions: EpochDistributionData; - vaults: RegistryVaults; - prescribedObservers: PrescribedObservers; -} - -// ANT - -export type ANTRecord = { - transactionId: string; - ttlSeconds: number; -}; - -export type ANTRecords = Record & { '@': ANTRecord }; - -export type ANTState = { - owner: WalletAddress; - controllers: WalletAddress[]; - name: string; - ticker: string; - records: ANTRecords; - balances: Balances; -}; - -export const ANT_CONTRACT_FUNCTIONS = { - TRANSFER: 'transfer', - SET_CONTROLLER: 'setController', - REMOVE_CONTROLLER: 'removeController', - SET_NAME: 'setName', - SET_TICKER: 'setTicker', - SET_RECORD: 'setRecord', - REMOVE_RECORD: 'removeRecord', - BALANCE: 'balance', - EVOLVE: 'evolve', -}; diff --git a/src/io.ts b/src/io.ts index dbb197c5..41539e02 100644 --- a/src/io.ts +++ b/src/io.ts @@ -15,52 +15,21 @@ * along with this program. If not, see . */ import { AOProcess } from './common/index.js'; -import { - ANTRecord, - ArNSReservedNameData, - EpochDistributionData, - EpochObservations, - GatewayDelegate, - GatewaySettings, - RegistrationType, - VaultData, - WeightedObserver, -} from './contract-state.js'; -import { AoSigner, mIOToken } from './token.js'; +import { mIOToken } from './token.js'; import { AoMessageResult, + AoSigner, + AtLeastOne, BlockHeight, - JoinNetworkParams, ProcessId, Timestamp, TransactionId, - UpdateGatewaySettingsParams, WalletAddress, WriteOptions, } from './types.js'; import { validateArweaveId } from './utils/arweave.js'; -export function isProcessConfiguration( - config: object, -): config is { process: AOProcess } { - return 'process' in config; -} - -export function isProcessIdConfiguration( - config: object, -): config is { processId: string } { - return ( - 'processId' in config && - typeof config.processId === 'string' && - validateArweaveId(config.processId) === true - ); -} - -export function isLeasedArNSRecord( - record: AoArNSNameData, -): record is AoArNSLeaseData { - return record.type === 'lease' && record.endTimestamp !== undefined; -} +// Pagination export type PaginationParams = { cursor?: string; @@ -78,6 +47,7 @@ export type PaginationResult = { hasMore: boolean; }; +// Configuration export type ProcessConfiguration = | { process?: AOProcess; @@ -95,6 +65,188 @@ export type EpochInput = } | undefined; +// AO/IO Contract +export type AoBalances = Record; +export type AoFees = Record; +export type AoObservations = Record; +export type AoEpochIndex = number; + +export interface AoIOState { + GatewayRegistry: Record; + Epochs: Record; + NameRegistry: { + records: Record; + reserved: Record; + }; + Balances: Record; + Vaults: Record; + Ticker: string; + Name: string; + Logo: string; +} + +export type AoEpochObservationData = { + failureSummaries: Record; + reports: Record; +}; + +export type AoVaultData = { + balance: number; + locked: number; + endTimestamp: Timestamp; +}; + +export type AoEpochDistributionData = { + rewards: Record; + distributedTimestamp: Timestamp; + totalDistributedRewards: number; + totalEligibleRewards: number; +}; + +export type AoArNSReservedNameData = { + target?: string; + endTimestamp?: number; +}; +export type AoArNSNameData = AoArNSPermabuyData | AoArNSLeaseData; +export type AoArNSNameDataWithName = AoArNSNameData & { name: string }; +export type AoArNSBaseNameData = { + processId: ProcessId; + startTimestamp: number; + type: 'lease' | 'permabuy'; + undernameLimit: number; + purchasePrice: number; +}; + +export type AoArNSPermabuyData = AoArNSBaseNameData & { + type: 'permabuy'; +}; + +export type AoArNSLeaseData = AoArNSBaseNameData & { + type: 'lease'; + endTimestamp: Timestamp; +}; + +export type AoEpochSettings = { + epochZeroStartTimestamp: Timestamp; + durationMs: number; + prescribedNameCount: number; + rewardPercentage: number; + maxObservers: number; + distributionDelayMs: number; +}; + +export type AoEpochData = { + epochIndex: AoEpochIndex; + startHeight: BlockHeight; + observations: AoObservations; + prescribedObservers: AoWeightedObserver[]; + startTimestamp: Timestamp; + endTimestamp: Timestamp; + distributionTimestamp: Timestamp; + distributions: AoEpochDistributionData; +}; + +export type AoGateway = { + settings: AoGatewaySettings; + stats: AoGatewayStats; + delegates: Record; + totalDelegatedStake: number; + vaults: Record; + startTimestamp: Timestamp; + endTimestamp: Timestamp; + observerAddress: WalletAddress; + operatorStake: number; + status: 'joined' | 'leaving'; + // TODO: add weights +}; + +export type AoGatewayStats = { + passedConsecutiveEpochs: number; + failedConsecutiveEpochs: number; + totalEpochParticipationCount: number; + passedEpochCount: number; + failedEpochCount: number; + observedEpochCount: number; + prescribedEpochCount: number; +}; + +export type AoWeightedObserver = { + gatewayAddress: WalletAddress; + observerAddress: WalletAddress; + stake: number; + startTimestamp: number; +} & AoGatewayWeights; + +export type AoGatewayWeights = { + stakeWeight: number; + tenureWeight: number; + gatewayRewardRatioWeight: number; + observerRewardRatioWeight: number; + compositeWeight: number; + normalizedCompositeWeight: number; +}; + +export type AoGatewayWithAddress = AoGateway & { + gatewayAddress: WalletAddress; +}; + +export type AoGatewayDelegate = { + delegatedStake: number; + startTimestamp: Timestamp; + vaults: Record; +}; + +export type AoGatewaySettings = { + allowDelegatedStaking: boolean; + delegateRewardShareRatio: number; + minDelegatedStake: number; + autoStake: boolean; + label: string; + note: string; + properties: string; + fqdn: string; + port: number; + protocol: 'https'; +}; + +export type AoBalanceWithAddress = { + address: WalletAddress; + balance: number; +}; + +// ANT Contract + +export type AoANTState = { + Name: string; + Ticker: string; + Denomination: number; + Owner: WalletAddress; + Controllers: WalletAddress[]; + Records: Record; + Balances: Record; + Logo: string; + TotalSupply: number; + Initialized: boolean; +}; + +export type AoANTRecord = { + transactionId: string; + ttlSeconds: number; +}; + +// Input types + +// TODO: confirm what is required or if all can be optional and defaults will be provided +export type AoJoinNetworkParams = Pick< + AoGateway, + 'operatorStake' | 'observerAddress' +> & + Partial; + +export type AoUpdateGatewaySettingsParams = AtLeastOne; + +// Interfaces + export interface AOContract { read({ tags, @@ -151,13 +303,13 @@ export interface AoIORead { name, }: { name: string; - }): Promise; + }): Promise; getEpoch(epoch?: EpochInput): Promise; getCurrentEpoch(): Promise; - getPrescribedObservers(epoch?: EpochInput): Promise; + getPrescribedObservers(epoch?: EpochInput): Promise; getPrescribedNames(epoch?: EpochInput): Promise; - getObservations(epoch?: EpochInput): Promise; - getDistributions(epoch?: EpochInput): Promise; + getObservations(epoch?: EpochInput): Promise; + getDistributions(epoch?: EpochInput): Promise; getTokenCost({ intent, purchaseType, @@ -199,10 +351,7 @@ export interface AoIOWrite extends AoIORead { protocol, autoStake, observerAddress, - }: Omit & { - observerAddress: string; - operatorStake: number | mIOToken; - }, + }: AoJoinNetworkParams, options?: WriteOptions, ): Promise; leaveNetwork(options?: WriteOptions): Promise; @@ -219,7 +368,7 @@ export interface AoIOWrite extends AoIORead { protocol, autoStake, observerAddress, - }: UpdateGatewaySettingsParams, + }: AoUpdateGatewaySettingsParams, options?: WriteOptions, ): Promise; increaseOperatorStake( @@ -289,8 +438,8 @@ export interface AoANTRead { Owner: string; ['Source-Code-TX-ID']?: string; }>; - getRecord({ undername }): Promise; - getRecords(): Promise>; + getRecord({ undername }): Promise; + getRecords(): Promise>; getOwner(): Promise; getControllers(): Promise; getTicker(): Promise; @@ -335,118 +484,25 @@ export interface AoANTRegistryWrite extends AoANTRegistryRead { register(params: { processId: string }): Promise; } -// AO Contract types -export interface AoIOState { - GatewayRegistry: Record; - Epochs: Record; - NameRegistry: { - records: Record; - reserved: Record; - }; - Balances: Record; - Vaults: Record; - Ticker: string; - Name: string; - Logo: string; +// Typeguard functions +export function isProcessConfiguration( + config: object, +): config is { process: AOProcess } { + return 'process' in config; } -export type AoEpochIndex = number; -export type AoArNSReservedNameData = ArNSReservedNameData; -export type AoArNSNameData = AoArNSPermabuyData | AoArNSLeaseData; -export type AoArNSNameDataWithName = AoArNSNameData & { name: string }; -export type AoArNSBaseNameData = { - processId: ProcessId; - startTimestamp: number; - type: RegistrationType; - undernameLimit: number; - purchasePrice: number; -}; - -export type AoArNSPermabuyData = AoArNSBaseNameData & { - type: 'permabuy'; -}; - -export type AoArNSLeaseData = AoArNSBaseNameData & { - type: 'lease'; - endTimestamp: number; // At what unix time (seconds since epoch) the lease ends -}; - -export type AoEpochSettings = { - epochZeroStartTimestamp: Timestamp; - durationMs: number; - prescribedNameCount: number; - rewardPercentage: number; - maxObservers: number; - distributionDelayMs: number; -}; - -export type AoEpochData = { - epochIndex: AoEpochIndex; - startHeight: BlockHeight; - observations: EpochObservations; - prescribedObservers: WeightedObserver[]; - startTimestamp: Timestamp; - endTimestamp: Timestamp; - distributionTimestamp: Timestamp; - distributions: { - rewards: Record; - distributedTimestamp: Timestamp; - totalDistributedRewards: number; - totalEligibleRewards: number; - }; -}; - -export type AoGatewayStats = { - passedConsecutiveEpochs: number; - failedConsecutiveEpochs: number; - totalEpochCount: number; - passedEpochCount: number; - failedEpochCount: number; - observedEpochCount: number; - prescribedEpochCount: number; -}; - -export type AoGatewayWeights = { - compositeWeight: number; - gatewayRewardRatioWeight: number; - tenureWeight: number; - observerRewardRatioWeight: number; - normalizedCompositeWeight: number; - stakeWeight: number; -}; - -export type AoGateway = { - settings: GatewaySettings; - stats: AoGatewayStats; - delegates: Record; - totalDelegatedStake: number; - vaults: Record; - startTimestamp: Timestamp; - endTimestamp: Timestamp; - observerAddress: WalletAddress; - operatorStake: number; - status: 'joined' | 'leaving'; - weights: AoGatewayWeights; -}; - -export type AoBalanceWithAddress = { - address: WalletAddress; - balance: number; -}; - -export type AoGatewayWithAddress = AoGateway & { - gatewayAddress: WalletAddress; -}; +export function isProcessIdConfiguration( + config: object, +): config is { processId: string } { + return ( + 'processId' in config && + typeof config.processId === 'string' && + validateArweaveId(config.processId) === true + ); +} -export type AoANTState = { - Name: string; - Ticker: string; - Denomination: number; - Owner: WalletAddress; - Controllers: WalletAddress[]; - Records: Record; - Balances: Record; - Logo: string; - TotalSupply: number; - Initialized: boolean; -}; +export function isLeasedArNSRecord( + record: AoArNSNameData, +): record is AoArNSLeaseData { + return record.type === 'lease'; +} diff --git a/src/types.ts b/src/types.ts index 05383621..34f378e2 100644 --- a/src/types.ts +++ b/src/types.ts @@ -14,7 +14,6 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -export * from './contract-state.js'; export * from './common.js'; export * from './token.js'; export * from './io.js'; diff --git a/src/utils/ao.ts b/src/utils/ao.ts index 0c2d094b..9a810bf6 100644 --- a/src/utils/ao.ts +++ b/src/utils/ao.ts @@ -25,8 +25,13 @@ import { AOS_MODULE_ID, DEFAULT_SCHEDULER_ID, } from '../constants.js'; -import { ANTState } from '../contract-state.js'; -import { AoClient, AoSigner, ContractSigner } from '../types.js'; +import { + AoANTRecord, + AoClient, + AoSigner, + ContractSigner, + WalletAddress, +} from '../types.js'; export async function spawnANT({ signer, @@ -43,7 +48,14 @@ export async function spawnANT({ luaCodeTxId?: string; ao?: AoClient; scheduler?: string; - state?: ANTState; + state?: { + owner: WalletAddress; + controllers: WalletAddress[]; + name: string; + ticker: string; + records: Record; + balances: Record; + }; stateContractTxId?: string; antRegistryId?: string; }): Promise {