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(docs): add dedust cookbook #954

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- New CSpell dictionaries: TVM instructions and adjusted list of Fift words: PR [#881](https://github.com/tact-lang/tact/pull/881)
- Docs: the `description` property to the frontmatter of the each page for better SEO: PR [#916](https://github.com/tact-lang/tact/pull/916)
- Docs: Google Analytics tags per every page: PR [#921](https://github.com/tact-lang/tact/pull/921)
- Docs: Add DeDust cookbook: PR [#954](https://github.com/tact-lang/tact/pull/954)
- Ability to specify a compile-time method ID expression for getters: PR [#922](https://github.com/tact-lang/tact/pull/922) and PR [#932](https://github.com/tact-lang/tact/pull/932)

### Changed
Expand Down
148 changes: 146 additions & 2 deletions docs/src/content/docs/cookbook/dexes/dedust.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,154 @@ sidebar:
order: 1
---

a-bahdanau marked this conversation as resolved.
Show resolved Hide resolved
# DeDust.io
a-bahdanau marked this conversation as resolved.
Show resolved Hide resolved


[DeDust](https://dedust.io) is a decentralized exchange (DEX) and automated market maker (AMM) built natively on [TON Blockchain](https://ton.org) and [DeDust Protocol 2.0](https://docs.dedust.io/reference/tlb-schemes). DeDust is designed with a meticulous attention to user experience (UX), gas efficiency, and extensibility.

:::danger[Not implemented]
## Swaps

You can read more about swaps on [DeDust documentation](https://docs.dedust.io/docs/swaps).

:::caution

This page is a stub until it gets new content in [#146](https://github.com/tact-lang/tact-docs/issues/146).
It's important to ensure that contracts are deployed.
Sending funds to an inactive contract could result in irretrievable loss.

:::

All kinds of swaps shares same structures:

```tact
struct SwapStep {
poolAddress: Address;
reserved: Cell? = null; // NULL always, reserved.
limit: Int as coins = 0;
nextStep: Cell?; // should be `SwapStep`, but recursive types not supported in tact
}

struct SwapParams {
deadline: Int as uint32 = 0;
recipientAddress: Address? = null;
referralAddress: Address? = null;
fulfillPayload: Cell? = null;
rejectPayload: Cell? = null;
}
```

### Swapping native coin

```tact
message(0xea06185d) NativeSwap {
queryId: Int as uint64 = 0;
amount: Int as coins; // TON amount for the swap
poolAddress: Address;
reserved: Cell? = null; // NULL always, reserved.
limit: Int as coins = 0;
nextStep: SwapStep? = null;
swapParams: SwapParams;
}

// address of ton vault to send message
const TON_VAULT_ADDRESS: Address = address("EQDa4VOnTYlLvDJ0gZjNYm5PXfSmmtL6Vs6A_CZEtXCNICq_");

// address of pool to swap. Pool is pair like TON/USDT
const POOL_ADDRESS: Address = address("EQCY5ufIEA-wdv1L5Zw09OMDHywwHsqLKEAUBYtngwNnnal4");

const TON_SWAP_GAS_AMOUNT: Int = ton("0.2");

fun makeTonSwap() {
let swapParams = SwapParams{
deadline: 0,
recipientAddress: null,
referralAddress: null,
fulfillPayload: null,
rejectPayload: null,
};

// ton amount to swap in nanotons
let swapAmount = ...;

send(SendParameters{
to: TON_VAULT_ADDRESS,
value: swapAmount + TON_SWAP_GAS_AMOUNT,
body: NativeSwap{
queryId: 0,
amount: swapAmount,
poolAddress: POOL_ADDRESS,
reserved: null,
limit: 0,
nextStep: null,
swapParams,
}.toCell()
});
}
```


### Swapping jetton

```tact
message(0xf8a7ea5) TokenTransfer {
queryId: Int as uint64;
amount: Int as coins;
destination: Address;
responseDestination: Address;
customPayload: Cell?;
forwardTonAmount: Int as coins;
forwardPayload: Cell?;
}

message(0xe3a0d482) JettonSwapPayload {
poolAddress: Address;
reserved: Cell? = null; // NULL always, reserved.
limit: Int as coins = 0;
nextStep: SwapStep? = null;
swapParams: SwapParams;
}

// address of jetton master you want to swap
const JETTON_MASTER_ADDRESS: Address = address("kQCxBOJjV31OIAa0NN9JbaYUp6OXOahcFCipuYnsujx1MDAY");

// address of jetton vault to send message
const JETTON_VAULT_ADDRESS: Address = address("EQCgne1aW1CmkokSeRjMIREmJWbCKFbJxxkRCvtLDiheTTF9");

// address of pool to swap. Pool is pair like TON/USDT
const POOL_ADDRESS: Address = address("EQCY5ufIEA-wdv1L5Zw09OMDHywwHsqLKEAUBYtngwNnnal4");

const JETTON_SWAP_GAS_AMOUNT: Int = ton("0.3");
const JETTON_SWAP_FWD_AMOUNT: Int = ton("0.25");

fun makeJettonSwap() {
let swapParams = SwapParams{
deadline: 0,
recipientAddress: null,
referralAddress: null,
fulfillPayload: null,
rejectPayload: null,
};

let myJettonWalletAddress = ...; // calculate wallet address of jetton you want to swap
let swapAmount = ...; // jetton amount for swap

send(SendParameters{
to: myJettonWalletAddress,
value: JETTON_SWAP_GAS_AMOUNT,
body: TokenTransfer{
queryId: 0,
amount: swapAmount,
destination: JETTON_VAULT_ADDRESS,
responseDestination: myAddress(),
customPayload: null,
forwardTonAmount: JETTON_SWAP_FWD_AMOUNT,
forwardPayload: JettonSwapPayload{
poolAddress: POOL_ADDRESS,
reserved: null,
limit: 0,
nextStep: null,
swapParams,
}.toCell()
}.toCell()
});
}
```