Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: optimize doc #5

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
46 changes: 23 additions & 23 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,35 @@ In this documentation you will find an explanation of how the SDK works and code

First of all, the environment variables must be set (see .env.example):

- WALLET_MNEMONIC
- RPC_API_KEY
- WALLET_MNEMONIC
- RPC_API_KEY

Then you can run the following commands:

- Supply
- Supply

```shell
npm run supply
```

- Supply - TonConnect
- Supply - TonConnect

```shell
npm run supply:tonconnect
```

- Withdraw
- Withdraw

```shell
npm run withdraw
```

- Liquidation
- Liquidation

```shell
npm run liquidation
```


## Getting Started

First of all, you need to get a wrapper class for the Master Contract and open it using TonClient:
Expand Down Expand Up @@ -63,27 +66,26 @@ At this point, `evaa` has all the necessary information for further work. Mostly

With the master contract wrapper, we can get the user contract using two methods:

- getOpenedUserContract: A contract that will be opened by the same client and use the same provider as the master contract.
- openUserContract: Getting a user contract class without opening it, which will allow it to be opened later by another client.
- getOpenedUserContract: A contract that will be opened by the same client and use the same provider as the master contract.
- openUserContract: Getting a user contract class without opening it, which will allow it to be opened later by another client.

If there is no need for a separate provider, it is recommended to use `getOpenedUserContract` for convenience. After that, we need to [get the current prices](./extended.md#pricedata). There are 2 possible scenarios:


- Very rare case when prices are not available: `getSyncLite` - a method that can get only the token balances on the user contract without calculating other values. This allows you to interact with the contract at a minimum level even if prices are not available.
- Main case: `getSync` - a method that takes **AssetsData**, **AssetsConfig** and **PriceData**. Using these values, it calculates all the necessary limits and useful values for the user.
- Very rare case when prices are not available: `getSyncLite` - a method that can get only the token balances on the user contract without calculating other values. This allows you to interact with the contract at a minimum level even if prices are not available.
- Main case: `getSync` - a method that takes **AssetsData**, **AssetsConfig** and **PriceData**. Using these values, it calculates all the necessary limits and useful values for the user.

## Available Operations

MasterContract wrapper provides 3 possible operations: **supply**, **withdraw** and **liquidation**. You can either get ready-to-send messages or send them immediately.

It is possible to use `TonConnect` or available wallet contract wrappers from `@ton/ton` for sending messages.
It is possible to use `TonConnect` or available wallet contract wrappers from `@ton/ton` for sending messages.

Short summary of examples:

- Supply: Manual sending using `@ton/ton` wrapper to calculate external message hash and find transaction later.
- Supply - TonConnect: Sending using TonConnect and getting transaction.
- Withdraw: Simple sending with minimal code.
- Liquidation: Simple sending with minimal code.
- Supply: Manual sending using `@ton/ton` wrapper to calculate external message hash and find transaction later.
- Supply - TonConnect: Sending using TonConnect and getting transaction.
- Withdraw: Simple sending with minimal code.
- Liquidation: Simple sending with minimal code.

### Supply

Expand Down Expand Up @@ -150,9 +152,7 @@ await evaa.sendSupply(getTonConnectSender(connector), toNano(1) + FEES.SUPPLY, {

const lastSentBoc = getLastSentBoc();
console.log(lastSentBoc);
console.log(
`https://testnet.tonviewer.com/transaction/${Cell.fromBase64(lastSentBoc!.boc).hash().toString('hex')}`,
);
console.log(`https://testnet.tonviewer.com/transaction/${Cell.fromBase64(lastSentBoc!.boc).hash().toString('hex')}`);
```

**Important:** To get the external message hash, you want to use the `getLastSentBoc` function. At the moment, this is the only way to get the last sent message. Value of `lastSentBoc` containd only the last sent message.
Expand Down Expand Up @@ -185,7 +185,7 @@ const user = evaa.getOpenedUserContract(wallet.address);
await user.getSync(evaa.data!.assetsData, evaa.data!.assetsConfig, priceData!.dict);
```

Now we can calculate all the necessary data and check if the user is liquidable using the `isLiqidable` field. If yes, we can get the necessary information (`liquidationBaseData`). Using these values, we can liquidate the user:
Now we can calculate all the necessary data and check if the user is liquidable using the `isLiquidable` field. If yes, we can get the necessary information (`liquidationBaseData`). Using these values, we can liquidate the user:

```typescript
if (user.isLiquidable) {
Expand All @@ -203,8 +203,8 @@ if (user.isLiquidable) {
});
} else {
const sender: Sender = {
address: wallet.address,
send: wallet.sender(keyPair.secretKey).send
address: wallet.address,
send: wallet.sender(keyPair.secretKey).send,
};
await evaa.sendLiquidation(sender, FEES.LIQUIDATION_JETTON, {
queryID: 0n,
Expand Down