Building advanced mechanics
Usually, after a swap, DEX returns coins to the sender, and DeDust follows this practice by default.
With TON's message-based approach, you should chain transactions for advanced mechanics.
For this in DeDust Protocol, here are two options.
Configurable address of recipient
Typically, the sender gets coins after a swap. However, sometimes the recipient might be another user or a different smart-contract. To do this, set the swapParams.recipientAddress
using the DeDust SDK. If building a message manually, use the recipient_addr
in SwapParams.
Example:
const forwardPayload = VaultJetton.createSwapPayload({
/* ... */
swapParams: {
recipientAddress: RECIPIENT_ADDRESS,
},
});
Conditionally attached custom payload
Each swap can either be fulfilled or rejected, for reasons like excessive slippage or expiration.
Fulfilled swaps
If a swap is successfully executed, DeDust transfers funds to recipient_addr
or, if not specified, to sender.
DeDust Protocol also lets you add a custom payload for fulfilled swaps.
The attached payload will serve as forward_payload
in transfer_notification
for jetton transfers or as payload in payout for TON in fulfilled swaps.
When using the DeDust SDK, set the swapParams.fulfillPayload
as follows:
const forwardPayload = VaultJetton.createSwapPayload({
/* ... */
swapParams: {
recipientAddress: RECIPIENT_ADDRESS,
fulfillPayload: CUSTOM_PAYLOAD,
},
});
If you build a message manually, store it as fulfill_payload
in SwapParams.
Rejected swaps
If a swap is rejected for some reason (excessive slippage or expiration), DeDust transfers funds back to sender.
However, you may also attach custom payload for this case.
Just set the swapParams.rejectPayload
as follows:
const forwardPayload = VaultJetton.createSwapPayload({
/* ... */
swapParams: {
recipientAddress: RECIPIENT_ADDRESS,
rejectPayload: CUSTOM_PAYLOAD,
},
});
Or store it as reject_payload
in SwapParams, if you build a message manually.
Updated about 1 year ago