-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
99e9384
commit 1e2b827
Showing
11 changed files
with
593 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/basedbot/fleet-strategies/atlasnet-fc-strategy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { mine } from '../fsm/configs/mine' | ||
import { createMiningStrategy } from '../fsm/mine' | ||
import { Strategy } from '../fsm/strategy' | ||
import { Player } from '../lib/sage/state/user-account' | ||
import { WorldMap } from '../lib/sage/state/world-map' | ||
import { galaxySectorsData } from '../lib/util/galaxy-sectors-data' | ||
|
||
export const atlasnetFcStrategy = | ||
(count: number) => | ||
(map: WorldMap, player: Player): Map<string, Strategy> => { | ||
const ans: Map<string, Strategy> = new Map<string, Strategy>() | ||
const sectors = galaxySectorsData() | ||
.filter((sector) => sector.closestFaction === player.faction) | ||
.sort((a, b) => a.name.localeCompare(b.name)) | ||
|
||
for (let i = 0; i < count; i++) { | ||
ans.set( | ||
`basedbot-mud-${i}`, | ||
createMiningStrategy( | ||
mine( | ||
map, | ||
player.homeCoordinates, | ||
sectors[i % sectors.length].coordinates, | ||
), | ||
player, | ||
), | ||
) | ||
} | ||
|
||
return ans | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { mineableByCoordinates, WorldMap } from '../../lib/sage/state/world-map' | ||
import { Coordinates } from '../../lib/util/coordinates' | ||
|
||
import { mineConfig, MineConfig } from './mine-config' | ||
|
||
export const mine = ( | ||
map: WorldMap, | ||
homeBase: Coordinates, | ||
targetBase: Coordinates, | ||
): MineConfig => | ||
mineConfig({ | ||
homeBase, | ||
targetBase, | ||
resource: mineableByCoordinates(map, targetBase).values().next().value, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { PublicKey } from '@solana/web3.js' | ||
import { InstructionReturn, ixReturnsToIxs } from '@staratlas/data-source' | ||
import { Starbase } from '@staratlas/sage' | ||
|
||
import { sendAndConfirmInstructions } from '../../../../../service/sol/send-and-confirm-tx' | ||
import { programs } from '../../programs' | ||
import { createFleetIx } from '../ix/create-fleet' | ||
import { getCargoStatsDefinition } from '../state/cargo-stats-definition' | ||
import { getStarbasePlayer } from '../state/starbase-player' | ||
import { Player } from '../state/user-account' | ||
|
||
export const createFleet = async ( | ||
player: Player, | ||
starbase: Starbase, | ||
_mint: PublicKey, | ||
name: string, | ||
amount: number, | ||
// eslint-disable-next-line max-params | ||
): Promise<void> => { | ||
const instructions: InstructionReturn[] = [] | ||
|
||
const starbasePlayer = await getStarbasePlayer(player, starbase, programs) | ||
// TODO: Ask Sammy about this | ||
const [shipEscrow] = starbasePlayer.wrappedShipEscrows | ||
|
||
const [cargoStatsDefinition] = await getCargoStatsDefinition() | ||
|
||
instructions.push( | ||
createFleetIx( | ||
player, | ||
starbase, | ||
starbasePlayer, | ||
programs, | ||
shipEscrow.ship, | ||
0, | ||
cargoStatsDefinition.key, | ||
amount, | ||
name, | ||
).instructions, | ||
) | ||
|
||
await sendAndConfirmInstructions( | ||
await ixReturnsToIxs(instructions, player.signer), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { PublicKey } from '@solana/web3.js' | ||
import { Starbase } from '@staratlas/sage' | ||
import BN from 'bn.js' | ||
|
||
import { Player } from '../state/user-account' | ||
|
||
export const depositShip = async ( | ||
_player: Player, | ||
_starbase: Starbase, | ||
_mint: PublicKey, | ||
_amount: BN, | ||
// eslint-disable-next-line max-params,require-await | ||
): Promise<void> => { | ||
throw new Error('Not implemented') | ||
// const instructions: InstructionReturn[] = [] | ||
// | ||
// const starbasePlayer = await getStarbasePlayer(player, starbase, programs) | ||
// | ||
// const sourceTokenAccount = getAssociatedTokenAddressSync( | ||
// mint, | ||
// player.signer.publicKey(), | ||
// ) | ||
// | ||
// | ||
// const destinationTokenAccount = getAssociatedTokenAddressSync( | ||
// mint, | ||
// cargoPodTo.key, | ||
// true, | ||
// ) | ||
// | ||
// instructions.push( | ||
// createAssociatedTokenAccountIdempotent(mint, cargoPodTo.key, true) | ||
// .instructions, | ||
// ) | ||
// | ||
// const allTokenAccounts = await getParsedTokenAccountsByOwner( | ||
// connection, | ||
// player.signer.publicKey(), | ||
// TOKEN_PROGRAM_ID, | ||
// ) | ||
// | ||
// const [cargoTokenAccount] = allTokenAccounts.filter((it) => | ||
// it.address.equals(sourceTokenAccount), | ||
// ) | ||
// | ||
// if (!cargoTokenAccount) { | ||
// throw new Error('Cargo token account not found') | ||
// } | ||
// const amountAtOrigin = new BN(cargoTokenAccount.amount.toString()) | ||
// | ||
// if (!cargoTokenAccount) { | ||
// throw new Error('Cargo not found at origin') | ||
// } | ||
// if (amountAtOrigin.lt(new BN(amount))) { | ||
// throw new Error('Not enough cargo available at origin') | ||
// } | ||
// | ||
// instructions.push( | ||
// addShipIx( | ||
// player, | ||
// starbase, | ||
// starbasePlayer, | ||
// programs, | ||
// sourceTokenAccount, | ||
// ship, | ||
// destinationTokenAccount, | ||
// amount, | ||
// ), | ||
// ) | ||
// | ||
// await sendAndConfirmInstructions( | ||
// await ixReturnsToIxs(instructions, player.signer), | ||
// ) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { PublicKey } from '@solana/web3.js' | ||
import { InstructionReturn } from '@staratlas/data-source' | ||
import { SagePlayerProfile, Starbase, StarbasePlayer } from '@staratlas/sage' | ||
import BN from 'bn.js' | ||
|
||
import { StarAtlasPrograms } from '../../programs' | ||
import { Player } from '../state/user-account' | ||
|
||
export const addShipIx = ( | ||
player: Player, | ||
starbase: Starbase, | ||
starbasePlayer: StarbasePlayer, | ||
programs: StarAtlasPrograms, | ||
originTokenAccount: PublicKey, | ||
ship: PublicKey, | ||
shipEscrowTokenAccount: PublicKey, | ||
shipAmount: BN, | ||
// eslint-disable-next-line max-params | ||
): InstructionReturn => | ||
SagePlayerProfile.addShipEscrow( | ||
programs.sage, | ||
player.profile.key, | ||
player.profileFaction.key, | ||
player.profile.key, | ||
player.signer, | ||
originTokenAccount, | ||
ship, | ||
shipEscrowTokenAccount, | ||
starbasePlayer.key, | ||
starbase.key, | ||
player.game.key, | ||
player.game.data.gameState, | ||
{ | ||
shipAmount, | ||
index: 0, | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { PublicKey } from '@solana/web3.js' | ||
import { InstructionReturn, stringToByteArray } from '@staratlas/data-source' | ||
import { Fleet, Starbase, StarbasePlayer } from '@staratlas/sage' | ||
|
||
import { StarAtlasPrograms } from '../../programs' | ||
import { Player } from '../state/user-account' | ||
|
||
type CreateFleetReturn = { | ||
fleetKey: [PublicKey, number] | ||
cargoHoldKey: [PublicKey, number] | ||
fuelTankKey: [PublicKey, number] | ||
ammoBankKey: [PublicKey, number] | ||
instructions: InstructionReturn | ||
} | ||
|
||
export const createFleetIx = ( | ||
player: Player, | ||
starbase: Starbase, | ||
starbasePlayer: StarbasePlayer, | ||
programs: StarAtlasPrograms, | ||
ship: PublicKey, | ||
shipEscrowIndex: number, | ||
cargoStatsDefinition: PublicKey, | ||
shipAmount: number, | ||
name: string, | ||
// eslint-disable-next-line max-params | ||
): CreateFleetReturn => | ||
Fleet.createFleet( | ||
programs.sage, | ||
programs.cargo, | ||
player.signer, | ||
player.profile.key, | ||
player.profileFaction.key, | ||
ship, | ||
starbasePlayer.key, | ||
starbase.key, | ||
player.game.key, | ||
player.game.data.gameState, | ||
cargoStatsDefinition, | ||
{ | ||
shipAmount, | ||
fleetLabel: stringToByteArray(name, 32), | ||
shipEscrowIndex, | ||
keyIndex: 0, | ||
}, | ||
) |
19 changes: 19 additions & 0 deletions
19
src/main/basedbot/lib/sage/state/cargo-stats-definition.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { CargoStatsDefinition } from '@staratlas/cargo' | ||
import { readAllFromRPC } from '@staratlas/data-source' | ||
|
||
import { connection } from '../../../../../service/sol' | ||
import { programs } from '../../programs' | ||
|
||
export const getCargoStatsDefinition = async (): Promise< | ||
Array<CargoStatsDefinition> | ||
> => { | ||
const cargoTypesAccountData = await readAllFromRPC( | ||
connection, | ||
programs.cargo, | ||
CargoStatsDefinition, | ||
) | ||
|
||
return cargoTypesAccountData | ||
.filter((f) => f.type === 'ok' && 'data' in f) | ||
.map((f) => (f as any).data) | ||
} |
Oops, something went wrong.