From cfcb3059ee05c31f194c976238ef23bd6e66105b Mon Sep 17 00:00:00 2001 From: Dr-Electron Date: Sat, 10 Feb 2024 17:12:06 +0100 Subject: [PATCH 1/4] Add swap example --- docs/docs/how-to/swap/create-swap.md | 42 ++++++++++++++++++++++ docs/sidebars.js | 5 +++ packages/sdk/examples/swap/https/create.ts | 3 +- 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 docs/docs/how-to/swap/create-swap.md diff --git a/docs/docs/how-to/swap/create-swap.md b/docs/docs/how-to/swap/create-swap.md new file mode 100644 index 0000000000..383e28b665 --- /dev/null +++ b/docs/docs/how-to/swap/create-swap.md @@ -0,0 +1,42 @@ +--- +title: Create Swap +tags: + - how-to + - swap + - nft + - token +--- + +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; +import DeepLink from '../../_admonitions/_deep_link.md' + + + + To create a swap order, you must call [`create`](../../reference-api/classes/SwapOtrDataset.md#create) on `dataset(Dataset.SWAP)`. + [`create`](../../reference-api/classes/SwapOtrDataset.md#create) takes an object of type [`SwapCreateTangleRequest`](../../reference-api/interfaces/SwapCreateTangleRequest.md) as parameter. + + ```tsx file=../../../../packages/sdk/examples/swap/otr/create.ts#L21-L27 + ``` + + + + + To create a swap order, you must call [`create`](../../reference-api/classes/SwapDataset.md#create) on `dataset(Dataset.SWAP)`. + [`create`](../../reference-api/classes/SwapDataset.md#create) takes an object of type [`SwapCreateRequest`](../../reference-api/interfaces/SwapCreateRequest.md) as parameter. + + ```tsx file=../../../../packages/sdk/examples/swap/https/create.ts#L14-L29 + ``` + + afterwards you need to fund a specific address: + + ```tsx file=../../../../packages/sdk/examples/swap/https/create.ts#L31 + ``` + + and set the order as funded: + + ```tsx file=../../../../packages/sdk/examples/swap/https/create.ts#L35-L46 + ``` + + + diff --git a/docs/sidebars.js b/docs/sidebars.js index 84c931343e..0ded669753 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -62,6 +62,11 @@ const sidebars = { 'how-to/nft/transfer', ], }, + { + 'Swap': [ + 'how-to/swap/create-swap', + ] + }, { 'Stamp API': [ 'how-to/stamp/create-stamp', diff --git a/packages/sdk/examples/swap/https/create.ts b/packages/sdk/examples/swap/https/create.ts index 6e16894294..7b10b243fb 100644 --- a/packages/sdk/examples/swap/https/create.ts +++ b/packages/sdk/examples/swap/https/create.ts @@ -28,7 +28,8 @@ async function main() { }, }); - console.log('Send bids to swap order address', response.payload.targetAddress); + const targetAddress = response.payload.targetAddress; + console.log('Send bids to swap order address', targetAddress); console.log('Once bids are sent mark the swap as funded.'); await https(origin) From b0abdafacfdb0e2de453f778e6ff517f6f31c8fb Mon Sep 17 00:00:00 2001 From: Dr-Electron Date: Sat, 10 Feb 2024 20:48:21 +0100 Subject: [PATCH 2/4] Add additional info --- docs/docs/how-to/swap/create-swap.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/docs/how-to/swap/create-swap.md b/docs/docs/how-to/swap/create-swap.md index 383e28b665..1e472bbf26 100644 --- a/docs/docs/how-to/swap/create-swap.md +++ b/docs/docs/how-to/swap/create-swap.md @@ -14,7 +14,7 @@ import DeepLink from '../../_admonitions/_deep_link.md' To create a swap order, you must call [`create`](../../reference-api/classes/SwapOtrDataset.md#create) on `dataset(Dataset.SWAP)`. - [`create`](../../reference-api/classes/SwapOtrDataset.md#create) takes an object of type [`SwapCreateTangleRequest`](../../reference-api/interfaces/SwapCreateTangleRequest.md) as parameter. + [`create`](../../reference-api/classes/SwapOtrDataset.md#create) takes an object of type [`SwapCreateTangleRequest`](../../reference-api/interfaces/SwapCreateTangleRequest.md) as parameter, in which you can specify the recipient, native tokens, NFTs and base token you are interested in. ```tsx file=../../../../packages/sdk/examples/swap/otr/create.ts#L21-L27 ``` @@ -23,7 +23,7 @@ import DeepLink from '../../_admonitions/_deep_link.md' To create a swap order, you must call [`create`](../../reference-api/classes/SwapDataset.md#create) on `dataset(Dataset.SWAP)`. - [`create`](../../reference-api/classes/SwapDataset.md#create) takes an object of type [`SwapCreateRequest`](../../reference-api/interfaces/SwapCreateRequest.md) as parameter. + [`create`](../../reference-api/classes/SwapDataset.md#create) takes an object of type [`SwapCreateRequest`](../../reference-api/interfaces/SwapCreateRequest.md) as parameter, in which you can specify the recipient, native tokens, NFTs and base token you are interested in. ```tsx file=../../../../packages/sdk/examples/swap/https/create.ts#L14-L29 ``` @@ -40,3 +40,9 @@ import DeepLink from '../../_admonitions/_deep_link.md' + +:::info setFunded + +With `setFunded` you can specify if you want to fund the swap right on creation or TODO + +::: From 8137bd245eb630c1b7daea5ae43b88f61b7bd0dd Mon Sep 17 00:00:00 2001 From: Dr-Electron Date: Sun, 11 Feb 2024 00:25:55 +0100 Subject: [PATCH 3/4] Update admonition --- docs/docs/how-to/swap/create-swap.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/how-to/swap/create-swap.md b/docs/docs/how-to/swap/create-swap.md index 1e472bbf26..200280a297 100644 --- a/docs/docs/how-to/swap/create-swap.md +++ b/docs/docs/how-to/swap/create-swap.md @@ -43,6 +43,6 @@ import DeepLink from '../../_admonitions/_deep_link.md' :::info setFunded -With `setFunded` you can specify if you want to fund the swap right on creation or TODO +With `setFunded` you can specify if you want to fund the swap right on creation or create an "open" swap where you send your bid/funds later ::: From cb8a3bbc99d09708e0733fe6050de1eeffd46aab Mon Sep 17 00:00:00 2001 From: Dr-Electron Date: Sat, 17 Feb 2024 11:10:34 +0100 Subject: [PATCH 4/4] Update admonition --- docs/docs/how-to/swap/create-swap.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/how-to/swap/create-swap.md b/docs/docs/how-to/swap/create-swap.md index 200280a297..3df07ad7f0 100644 --- a/docs/docs/how-to/swap/create-swap.md +++ b/docs/docs/how-to/swap/create-swap.md @@ -43,6 +43,6 @@ import DeepLink from '../../_admonitions/_deep_link.md' :::info setFunded -With `setFunded` you can specify if you want to fund the swap right on creation or create an "open" swap where you send your bid/funds later +With `setFunded`, you can specify if you, as the bidder, are giving your final bid or keeping it open. :::