Skip to content
Draft
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
7 changes: 6 additions & 1 deletion .github/actions/docker-buildx/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ inputs:
cache-strategy:
default: 'registry'
description: 'Cache strategy: gha or registry'
npm-token:
default: ''
description: 'NPM token for private registry access during build'
runs:
using: "composite"
steps:
Expand Down Expand Up @@ -77,4 +80,6 @@ runs:
cache-to: ${{ inputs.cache-enabled == 'true' && (inputs.cache-strategy == 'gha' && 'type=gha,mode=max' || format('type=registry,ref={0}/{1}:cache,mode=max', inputs.repository, inputs.app-name)) || '' }}
build-args: ${{ inputs.build-args }}
ssh: ${{ inputs.ssh-enabled == 'true' && 'default' || '' }}
secrets: ${{ inputs.extra-secrets }}
secrets: |
${{ inputs.extra-secrets }}
${{ inputs.npm-token != '' && format('npmrc=//registry.npmjs.org/:_authToken={0}', inputs.npm-token) || '' }}
12 changes: 12 additions & 0 deletions .github/actions/install/action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
name: 'Install cached modules'
description: 'Run pnpm install with cached modules'

inputs:
npm-token:
description: 'NPM token for private registry'
required: false
default: ''

runs:
using: 'composite'
steps:
Expand Down Expand Up @@ -28,6 +34,12 @@ runs:
restore-keys: |
pnpm-store-

- name: Configure npm auth
shell: bash
if: ${{ inputs.npm-token != '' }}
run: |
echo "//registry.npmjs.org/:_authToken=${{ inputs.npm-token }}" > ~/.npmrc

- name: Install dependencies
shell: bash
run: pnpm install --frozen-lockfile
7 changes: 7 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,26 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/install
with:
npm-token: ${{ secrets.NPM_TOKEN }}
- run: pnpm run build

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/install
with:
npm-token: ${{ secrets.NPM_TOKEN }}
- run: pnpm run lint

release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/install
with:
npm-token: ${{ secrets.NPM_TOKEN }}
- run: pnpm run build
- run: pnpm install --frozen-lockfile --ignore-scripts --prod
- uses: ./.github/actions/docker-buildx
Expand All @@ -36,4 +42,5 @@ jobs:
dockerhub-username: ${{ secrets.DOCKERHUB_USERNAME }}
dockerhub-password: ${{ secrets.DOCKERHUB_TOKEN }}
dockerfile: 'docker/Dockerfile'
npm-token: ${{ secrets.NPM_TOKEN }}

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
/node_modules
.env*
!.env.example
.npmrc
*.iml
dist/

src/main/basedbot/lib/sage/ships.json
package-lock.json
contrib/star-atlas-tech/
1 change: 1 addition & 0 deletions contrib/solana-dev-skill
Submodule solana-dev-skill added at dcc633
1 change: 0 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ ADD https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.s

COPY --from=builder /app/node_modules /app/node_modules
COPY --from=builder /app/dist/airdrop/index.js /app/airdrop.js
COPY --from=builder /app/dist/fleetbot/index.js /app/fleetbot.js
COPY --from=builder /app/dist/basedbot/index.js /app/basedbot.js
COPY --from=builder /app/dist/migrate/index.js /app/migrate.js
COPY src/db/db-data-source.ts /app/db/db-data-source.ts
Expand Down
5 changes: 0 additions & 5 deletions docker/bin/fleetbot.sh

This file was deleted.

217 changes: 217 additions & 0 deletions docs/C4_MIGRATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
# Fleetbot C4 Migration Plan

**Strategy:** Big-bang rewrite (no compat layer)

**Scope:** Core automation only (mining, transport, docking)

**Testing:** C4 devnet available

## Progress Tracker

- [x] **M1.1:** Update dependencies - add Kit/dev-sage, remove web3.js/anchor
- [x] **M1.2:** Rewrite RPC/Connection layer with solana-kite
- [x] **M1.3:** Rewrite transaction building/sending with Kit (incl priority fees)
- [x] **M1.4:** Migrate wallet/signer to KeyPairSigner
- [ ] **M2.1:** Migrate account types and discriminator-based decoding
- [ ] **M2.2:** Refactor Player context with Character account
- [ ] **M2.3:** Update Game/StarSystem/CelestialBody state structures
- [ ] **M2.4:** Update Fleet state machine (__kind discriminators)
- [x] **M3.1:** Rewrite dock/undock actions
- [x] **M3.2:** Rewrite warp/subwarp movement actions
- [x] **M3.3:** Rewrite mining start/stop actions
- [x] **M3.4:** Rewrite cargo load/unload actions
- [ ] **M4.1:** Update FSM strategies for C4 state patterns
- [ ] **M4.2:** Update mining configs for C4 resource IDs
- [ ] **M5:** Devnet integration testing

## Current vs Target Stack

| Layer | Current | Target |
|-------|---------|--------|
| Solana SDK | `@solana/web3.js` v1.x | `@solana/kit` + `solana-kite` |
| Program SDK | `@coral-xyz/anchor` v0.29 | Direct instruction fns (no Anchor) |
| Star Atlas | `@staratlas/sage` + `data-source` | `@staratlas/dev-sage` v0.38+ |
| Types | `PublicKey`, `Keypair`, `Connection` | `Address`, `KeyPairSigner`, `Connection` (kite) |
| Instructions | `Fleet.warpToCoordinate(...)` | `getWarpToCoordinateInstruction({...})` |

---

## Milestone 1: Solana Foundation Layer

Complete rewrite of core Solana infrastructure.

### 1.1 Dependencies

Remove legacy, add Kit stack:

```diff
- "@solana/web3.js": "^1.98.2"
- "@coral-xyz/anchor": "^0.29.0"
- "@staratlas/sage": "^1.8.10"
- "@staratlas/cargo": "^1.1.0"
- "@staratlas/data-source": "^0.9.0"
- "@staratlas/player-profile": "^0.11.0"
- "@staratlas/profile-faction": "^0.6.0"
+ "@solana/kit": "^2.x"
+ "solana-kite": "^x.x"
+ "@staratlas/dev-sage": "^0.38.0"
+ "@staratlas/dev-player-profile": "^0.38.0"
+ "@staratlas/dev-profile-faction": "^0.38.0"
```

### 1.2 RPC/Connection Layer

Rewrite `src/service/sol/const/connection.ts`:

```typescript
// Target pattern from fc-app
import { connect } from 'solana-kite'
export const connection = connect(config.sol.rpcEndpoint, config.sol.wsEndpoint)
```

### 1.3 Transaction Sending

Rewrite `src/service/sol/send-and-confirm-tx.ts` using Kit:

- `pipe()`, `createTransactionMessage()`, `setTransactionMessageFeePayerSigner()`
- `signTransactionMessageWithSigners()`, `sendAndConfirmTransactionFactory()`
- Migrate priority fee logic to Kit (remove Anchor dependency)

### 1.4 Wallet/Signer

Rewrite `src/service/wallet/init-keypair.ts`:

- `Keypair` to `KeyPairSigner` via `createKeyPairSignerFromBytes()`

---

## Milestone 2: Account State Layer

Rewrite account types and state management for C4.

### 2.1 Account Decoding

Delete `src/main/basedbot/lib/programs.ts` (no Anchor).

Create discriminator-based account fetching (pattern from fc-app):

```typescript
import { FLEET_DISCRIMINATOR, getFleetDecoder } from '@staratlas/dev-sage'
```

### 2.2 Player Context

Rewrite `src/main/basedbot/lib/sage/state/user-account.ts`:

- `PlayerProfile` -> `Profile` (dev-player-profile)
- Add `Character` account (new in C4, required for all actions)
- `AsyncSigner` -> `KeyPairSigner`

### 2.3 Game/World State

Rewrite `src/main/basedbot/lib/sage/state/game.ts`:

- `Game` struct layout differs
- `StarSystem` replaces sector concepts
- `CelestialBody` for asteroid references
- `RegionTracker` required for movement/mining

### 2.4 Fleet State Machine

Rewrite `src/main/basedbot/lib/fleet-state/`:

```typescript
// Current: fleet.state.MoveWarp
// Target: fleet.state.__kind === 'MoveWarp'
switch (fleet.state.__kind) {
case 'Idle': ...
case 'Docked': ...
case 'MoveWarp': ...
case 'MoveSubwarp': ...
case 'MineAsteroid': ...
}
```

---

## Milestone 3: Action Layer

Rewrite fleet actions. Delete `src/main/basedbot/lib/sage/ix/` - inline direct dev-sage calls.

### 3.1 Docking

Rewrite `src/main/basedbot/lib/sage/act/dock.ts`:

```typescript
import { getIdleToDockedInstruction, getDockedToIdleInstruction } from '@staratlas/dev-sage'
```

### 3.2 Movement

Rewrite `src/main/basedbot/lib/sage/act/move.ts`:

```typescript
import { getWarpToCoordinateInstruction, getStartSubwarpInstruction } from '@staratlas/dev-sage'
// Note: coordinates now [bigint, bigint]
```

### 3.3 Mining

Rewrite `src/main/basedbot/lib/sage/act/mine.ts`:

```typescript
import { getStartMiningAsteroidInstruction, getStopMiningAsteroidInstruction } from '@staratlas/dev-sage'
// Uses CelestialBody instead of mineItem
```

### 3.4 Cargo

Rewrite `src/main/basedbot/lib/sage/act/load-cargo.ts`:

```typescript
import { getTransferCargoToFleetInstruction } from '@staratlas/dev-sage'
// Uses cargoId-based transfers (fuelTank, ammoBank, cargoHold)
```

Reference: `contrib/star-atlas-tech/packages/fc-app/src/actions/FleetActions.ts`

---

## Milestone 4: FSM Strategy Layer

### 4.1 State Transitions

Update `src/main/basedbot/fsm/mine.ts`:

- `fleetInfo.fleetState.type` -> `fleet.state.__kind`
- Adapt timing checks for C4 mechanics

### 4.2 Config Updates

Update `src/main/basedbot/fsm/configs/mine/`:

- New resource/cargoId mappings
- StarSystem coordinates

---

## Milestone 5: Devnet Testing

- Test full mining loop: undock -> move -> mine -> move -> dock -> unload
- Validate error handling

---

## Files to Delete

- `src/service/sol/anchor.ts` (no Anchor)
- `src/main/basedbot/lib/programs.ts` (no Anchor program wrappers)
- `src/main/basedbot/lib/sage/ix/*.ts` (inline into act layer)

---

## Reference Resources

- **C4 Implementation:** `contrib/star-atlas-tech/packages/fc-app/src/actions/`
- **Solana Kit Best Practices:** `contrib/solana-dev-skill/skill/`
- **Account Registry Pattern:** `contrib/star-atlas-tech/packages/fc-app/src/config/accountRegistry.ts`
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import globals from 'globals'

export default [
{
ignores: ['node_modules/', 'dist/'],
ignores: ['node_modules/', 'dist/', 'contrib/'],
},
{
files: ['src/**/*.ts', 'test/**/*.ts'],
Expand Down
24 changes: 8 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"type": "module",
"scripts": {
"type-check": "tsc --noEmit",
"start:fleetbot": "tsx src/main/fleetbot/index.ts",
"start:basedbot": "tsx src/main/basedbot/index.ts",
"start:airdrop": "tsx src/main/airdrop/index.ts",
"build": "pnpm run type-check && tsup",
Expand All @@ -30,27 +29,21 @@
},
"homepage": "https://github.com/mindrunner/fleetbot#readme",
"dependencies": {
"@coral-xyz/anchor": "^0.29.0",
"@faker-js/faker": "^9.7.0",
"@sentry/integrations": "^7.114.0",
"@sentry/node": "^9.17.0",
"@sentry/tracing": "^7.120.3",
"@solana/spl-token": "^0.4.13",
"@solana/web3.js": "^1.98.2",
"@staratlas/atlas-prime": "^0.13.1",
"@staratlas/cargo": "^1.1.0",
"@staratlas/claim-stake": "^0.12.0",
"@staratlas/crafting": "^1.1.0",
"@staratlas/data-source": "^0.9.0",
"@staratlas/factory": "^0.7.1",
"@staratlas/player-profile": "^0.11.0",
"@staratlas/points": "^1.1.0",
"@staratlas/profile-faction": "^0.6.0",
"@staratlas/sage": "^1.8.10",
"@solana/kit": "^5.4.0",
"@solana-program/compute-budget": "^0.9.0",
"@solana-program/system": "^0.9.0",
"@solana-program/token": "^0.9.0",
"@staratlas/dev-player-profile": "^0.38.0",
"@staratlas/dev-profile-faction": "^0.38.0",
"@staratlas/dev-sage": "^0.38.0",
"big.js": "^7.0.1",
"bip39": "^3.1.0",
"bn.js": "^5.2.2",
"bs58": "^6.0.0",
"solana-kite": "^2.1.0",
"chance": "^1.1.12",
"cron": "^4.3.0",
"dayjs": "^1.11.13",
Expand All @@ -70,7 +63,6 @@
},
"devDependencies": {
"@types/big.js": "^6.2.2",
"@types/bn.js": "^5.1.6",
"@types/chance": "^1.1.6",
"@types/module-alias": "^2.0.4",
"@types/node": "^22.15.29",
Expand Down
Loading
Loading