> ## Documentation Index
> Fetch the complete documentation index at: https://mgb-ru.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# SOAR

> Достижения и рейтинг на блокчейне Solana 

**SOAR** — это программа, которая предоставляет удобное решение для управления таблицами лидеров, достижениями, профилями игроков и автоматическим распределением наград в блокчейне Solana. В настоящее время поддерживается вызов через клиент на TypeScript; интеграция в **Solana.Unity-SDK** будет доступна скоро.

## Содержание

* [SOAR SDK](#soar-sdk)
  * [Начало Работы](#quick-start)
  * [Классы](#classes)
    * [SoarProgram](#soarprogram)
    * [GameClient](#gameclient)
    * [InstructionBuilder](#instructionbuilder)
  * [Тесты](#tests)

## Быстрый старт

### Создать новую игру

```typescript theme={null}
import { SoarProgram, GameType, Genre } from "@magicblock-labs/soar-sdk";

// Create a Soar client using the '@solana/web3.js' active Connection and a defaultPayer
const client = SoarProgram.getFromConnection(connection, defaultPayer);

let game = Keypair.generate();
let title = "Game1";
let description = "Description";
let genre = Genre.Action;
let gameType = GameType.Web;
let nftMeta = Keypair.generate().publicKey;
let _auths = auths.map((keypair) => keypair.publicKey);

// Retrieve the bundled transaction.
let { newGame, transaction } = await client.initializeNewGame(
  game.publicKey,
  title,
  description,
  genre,
  gameType,
  nftMeta,
  _auths
);
// Send and confirm the transaction with the game keypair as signer.
await web3.sendAndConfirmTransaction(connection, transaction);
```

### Создать таблицу лидеров

```typescript theme={null}
const transactionIx = await client.addNewGameLeaderBoard(
  newGame,
  authWallet.publicKey,
  "my leaderboard", // description
  leaderboardNft, // nft associated with the leaderboard
  100,
  true // isAscending
);

await web3.sendAndConfirmTransaction(connection, transactionIx.transaction, [
  authWallet,
]);
```

### Отправить результат

```typescript theme={null}
const score = 10;
const playerAddress = new web3.PublicKey("..."); // The player publicKey
const authWallet = web3.Keypair.fromSecretKey(bs58.decode("")); // AUTH_WALLET_PRIVATE_KEY
const leaderboardPda = new web3.PublicKey(""); // LEADERBOARD_PDA

const transactionIx = await client.submitScoreToLeaderBoard(
  playerAddress,
  authWallet.publicKey,
  leaderboardPda,
  new BN(score)
);

await web3.sendAndConfirmTransaction(connection, transactionIx.transaction, [
  authWallet,
]);
```

### **Классы**

**SoarProgram**

Класс **SoarProgram** предоставляет клиенту доступ ко всем инструкциям программы **SOAR** на блокчейне.

Он также содержит утилитарные функции для вычисления **PDA** (Program Derived Addresses):

```typescript theme={null}
const user = Keypair.generate().publicKey;
const playerAddress = client.utils.derivePlayerAddress(user)[0];
```

Получение данных аккаунта:

```typescript theme={null}
const account = await client.fetchLeaderBoardAccount(address);
```

И получение данных нескольких аккаунтов:

```typescript theme={null}
const accounts = await client.fetchAllLeaderboardAccounts([]);
```

### **GameClient**

Класс **GameClient** предоставляет более специализированный набор функций, предназначенных для работы с одной учетной записью игры.

```typescript theme={null}
import { GameClient } from "@magicblock-labs/soar-sdk";
```

Получение экземпляра, представляющего существующую on-chain учетную запись игры:

```typescript theme={null}
const soar = SoarProgram.getFromConnection(connection, defaultPayer);
const gameClient = new GameClient(soar, address);
```

Регистрация новой игры:

```typescript theme={null}
const soar = SoarProgram.getFromConnection(connection, defaultPayer);
const game = new GameClient.register(soar, ...);
```

```typescript theme={null}
// Create a new leaderboard:
await game.addLeaderboard(....);

// Access the game's state.
await game.init();

// Refresh the game's state.
await game.refresh();

// Get the most recently-created achievement for a game
const achievement = game.recentAchievementAddress();
```

## InstructionBuilder

```typescript theme={null}
import { InstructionBuilder } from "@magicblock-labs/soar-sdk";
```

**InstructionBuilder** предоставляет набор методов для удобного формирования и упаковки транзакций.

```typescript theme={null}
const transaction = await this.builder
  .andInitializePlayer({ username, nftMeta }, user)
  .andRegisterPlayerEntry(/*...*/)
  .andSubmitScoreToLeaderboard(/*...*/)
  .and(/*some other transaction*/)
  .then((builder) => builder.build());
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.