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
14 changes: 10 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.PHONY: all clean check
.PHONY: all clean check test

DEPS := $(wildcard packages/*/package.json)
PACKAGES := borsh sdk-core sdk-solana sdk-sui sdk-facade
PACKAGES := borsh sdk-core sdk-solana sdk-facade
ALL_TARGETS := $(foreach pkg,$(PACKAGES),packages/$(pkg)/lib)

all: $(ALL_TARGETS)
Expand All @@ -11,16 +11,22 @@ clean:
rm -rf $(ALL_TARGETS)
@echo Build cleaned!

node_modules: $(DEPS)
node_modules/: $(DEPS)
@echo Install dependencies
npm i -ws

check:
@echo make: Entering directory "'packages/$(PKG)'"
npm run check --workspace=@race-foundation/$(PKG)
@echo make: Leaving directory "'packages/$(PKG)'"

test:
@echo make: Entering directory "'packages/$(PKG)'"
npm run test --workspace=@race-foundation/$(PKG)
@echo make: Leaving directory "'packages/$(PKG)'"

define LIB_template
packages/$(1)/lib: node_modules $$(wildcard packages/$(1)/src/*.ts wildcard packages/$(1)/src/**/*.ts packages/$(1)/*.js packages/$(1)/*.json)
packages/$(1)/lib: node_modules/ $$(wildcard packages/$(1)/src/*.ts wildcard packages/$(1)/src/**/*.ts packages/$(1)/*.js packages/$(1)/*.json)
@echo make: Entering directory "'packages/$(1)'"
npm run check --workspace=@race-foundation/$(1)
npm run build --workspace=@race-foundation/$(1)
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"packages/sdk-core",
"packages/sdk-solana",
"packages/sdk-facade",
"packages/borsh",
"packages/sdk-sui"
"packages/borsh"
],
"version": "0.1.0"
}
4 changes: 2 additions & 2 deletions packages/sdk-core/src/account-cache.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GameAccount } from './accounts'
import { IGameAccount } from './accounts'

/**
* We use this structure to cache some useful data from the fetched
Expand All @@ -16,7 +16,7 @@ export interface GameAccountCache {
transactorEndpoint: string | undefined
}

export function makeGameAccountCache(gameAccount: GameAccount): GameAccountCache {
export function makeGameAccountCache(gameAccount: IGameAccount): GameAccountCache {
return {
addr: gameAccount.addr,
bundleAddr: gameAccount.bundleAddr,
Expand Down
98 changes: 38 additions & 60 deletions packages/sdk-core/src/accounts.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
import { CheckpointOnChain } from './checkpoint'
import { IKind, UnionFromValues } from './types'
import { IEntryType } from './entry-type'
import { IPlayerBalance } from './player-balance'

export const ENTRY_LOCKS = ['Open', 'JoinOnly', 'DepositOnly', 'Closed'] as const
export type EntryLock = UnionFromValues<typeof ENTRY_LOCKS>

export const DEPOSIT_STATUS = ['Pending', 'Rejected', 'Refunded', 'Accepted'] as const
export type DepositStatus = UnionFromValues<typeof DEPOSIT_STATUS>

export interface PlayerJoin {
export interface IPlayerJoin {
readonly addr: string
readonly position: number
readonly accessVersion: bigint
readonly verifyKey: string
}

export interface PlayerDeposit {
export interface IPlayerDeposit {
readonly addr: string
readonly amount: bigint
readonly accessVersion: bigint
readonly settleVersion: bigint
readonly status: DepositStatus
}

export interface ServerJoin {
export interface IServerJoin {
readonly addr: string
readonly endpoint: string
readonly accessVersion: bigint
readonly verifyKey: string
}

export interface Bonus {
export interface IBonus {
readonly identifier: string
readonly tokenAddr: string
readonly amount: bigint
Expand All @@ -38,76 +38,73 @@ export interface Bonus {
export const VOTE_TYPES = ['ServerVoteTransactorDropOff', 'ClientVoteTransactorDropOff'] as const
export type VoteType = UnionFromValues<typeof VOTE_TYPES>

export interface Vote {
export interface IVote {
readonly voter: string
readonly votee: string
readonly voteType: VoteType
}

export interface GameRegistration {
export interface IGameRegistration {
readonly title: string
readonly addr: string
readonly regTime: bigint
readonly bundleAddr: string
}

export interface PlayerBalance {
readonly playerId: bigint
readonly balance: bigint
}

export interface GameAccount {
export interface IGameAccount {
readonly addr: string
readonly title: string
readonly bundleAddr: string
readonly tokenAddr: string
readonly ownerAddr: string
readonly settleVersion: bigint
readonly accessVersion: bigint
readonly players: PlayerJoin[]
readonly deposits: PlayerDeposit[]
readonly servers: ServerJoin[]
readonly players: IPlayerJoin[]
readonly deposits: IPlayerDeposit[]
readonly servers: IServerJoin[]
readonly transactorAddr: string | undefined
readonly votes: Vote[]
readonly votes: IVote[]
readonly unlockTime: bigint | undefined
readonly maxPlayers: number
readonly dataLen: number
readonly data: Uint8Array
readonly entryType: EntryType
readonly entryType: IEntryType
readonly recipientAddr: string
readonly checkpointOnChain: CheckpointOnChain | undefined
readonly entryLock: EntryLock
readonly bonuses: Bonus[]
readonly balances: PlayerBalance[]
readonly bonuses: IBonus[]
readonly balances: IPlayerBalance[]
}

export interface ServerAccount {
export interface IServerAccount {
readonly addr: string
readonly endpoint: string
readonly credentials: Uint8Array
}

export interface GameBundle {
export interface IGameBundle {
readonly addr: string
readonly uri: string
readonly name: string
readonly data: Uint8Array
}

export interface PlayerProfile {
export interface IPlayerProfile {
readonly addr: string
readonly nick: string
readonly pfp: string | undefined
readonly credentials: Uint8Array
}

export interface RegistrationAccount {
export interface IRegistrationAccount {
readonly addr: string
readonly isPrivate: boolean
readonly size: number
readonly owner: string | undefined
readonly games: GameRegistration[]
readonly games: IGameRegistration[]
}

export interface Token {
export interface IToken {
readonly addr: string
readonly icon: string
readonly name: string
Expand All @@ -120,7 +117,7 @@ export class TokenBalance {
readonly amount!: bigint
}

export interface Nft {
export interface INft {
readonly addr: string
readonly image: string
readonly name: string
Expand All @@ -129,73 +126,54 @@ export interface Nft {
readonly metadata: any
}

export interface RecipientAccount {
export interface IRecipientAccount {
readonly addr: string
readonly capAddr: string | undefined
readonly slots: RecipientSlot[]
readonly slots: IRecipientSlot[]
}

export const RECIPIENT_SLOT_TYPES = ['Nft', 'Token'] as const

export type RecipientSlotType = UnionFromValues<typeof RECIPIENT_SLOT_TYPES>

export interface RecipientSlot {
export interface IRecipientSlot {
readonly id: number
readonly slotType: RecipientSlotType
readonly tokenAddr: string
readonly shares: RecipientSlotShare[]
readonly shares: IRecipientSlotShare[]
readonly balance: bigint
}

export interface RecipientSlotShare {
readonly owner: RecipientSlotOwner
export interface IRecipientSlotShare {
readonly owner: IRecipientSlotOwner
readonly weights: number
readonly claimAmount: bigint
}

export type RecipientSlotOwnerKind<T extends 'unassigned' | 'assigned'> = IKind<T>
export type RecipientSlotOwnerKind<T extends 'Unassigned' | 'Assigned'> = IKind<T>

export type RecipientSlotOwnerUnassigned = {
readonly identifier: string
} & RecipientSlotOwnerKind<'unassigned'>
} & RecipientSlotOwnerKind<'Unassigned'>

export type RecipientSlotOwnerAssigned = {
readonly addr: string
} & RecipientSlotOwnerKind<'assigned'>

export type RecipientSlotOwner = RecipientSlotOwnerUnassigned | RecipientSlotOwnerAssigned

export type EntryTypeKind<T extends 'cash' | 'ticket' | 'gating' | 'disabled'> = IKind<T>

export type EntryTypeCash = {
readonly minDeposit: bigint
readonly maxDeposit: bigint
} & EntryTypeKind<'cash'>

export type EntryTypeTicket = {
readonly amount: bigint
} & EntryTypeKind<'ticket'>

export type EntryTypeGating = {
readonly collection: string
} & EntryTypeKind<'gating'>

export type EntryTypeDisabled = {} & EntryTypeKind<'disabled'>
} & RecipientSlotOwnerKind<'Assigned'>

export type EntryType = EntryTypeCash | EntryTypeTicket | EntryTypeGating | EntryTypeDisabled
export type IRecipientSlotOwner = RecipientSlotOwnerUnassigned | RecipientSlotOwnerAssigned

/**
* The registration account data with games consolidated.
*/
export interface RegistrationWithGames {
export interface IRegistrationWithGames {
readonly addr: string
readonly isPrivate: boolean
readonly size: number
readonly owner: string | undefined
readonly games: GameAccount[]
readonly games: IGameAccount[]
}

function getEndpointFromGameAccount(gameAccount: GameAccount): string | undefined {
function getEndpointFromGameAccount(gameAccount: IGameAccount): string | undefined {
const { transactorAddr, servers } = gameAccount

if (!transactorAddr) {
Expand Down
Loading
Loading