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

docs: add content for Gas Tank API Documentation (XDEFI-6907) #34

Merged
merged 18 commits into from
Jun 12, 2024
Merged
8 changes: 6 additions & 2 deletions .vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -764,13 +764,17 @@ function sidebarHome() {
text: "🔹 Authentication",
link: "/gas-tank/gas-tank-api#authentication",
},
{
text: "🔹 Messages",
link: "/gas-tank/gas-tank-api#messages",
},
{
text: "🔹 Chains / Tokens / Status",
link: "/gas-tank/gas-tank-api#chains",
link: "/gas-tank/gas-tank-api#chains-token-status",
},
{
text: "🔹 Balances & Gas top-up: Deposit, Withdraw, Send Gas",
link: "/gas-tank/gas-tank-api#balance-transactions",
link: "/gas-tank/gas-tank-api#balance-transactions-deposit-withdraw-send-gas",
},
{
text: "🔹 Other services",
Expand Down
16 changes: 8 additions & 8 deletions gas-tank/balance-services.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ await fetch(`${GAS_TANK_ENDPOINT}/balances/totals`, {

This endpoint allows users to deposit balance to the Gas Tank platform.

To deposit the balance, you need to sign the message with the private key of the address you want to deposit the balance for. `v`, `r`, `s` are the signature fields of the message signed by the address owner.
To deposit the balance, you need to sign the message with the private key of the address you want to deposit the balance for. `v`, `r`, `s` are the signature fields of the message signed by the address owner and `message` is generated in [Construct Deposit Message](#construct-deposit-message).

You can sign a string of data using [ethers.js](https://docs.ethers.org/v5), below is an example of [how to sign a message using ethers.js](https://docs.ethers.org/v5/getting-started/#getting-started--signing) and deposit the balance.

Expand All @@ -133,7 +133,7 @@ import { ethers } from "ethers";
const web3 = new Web3(window.ethereum);
const GAS_TANK_ENDPOINT = "https://gas-tank.xdefi.services";
const address = "0x1234567890123456789012345678901234567890"; // Address to deposit balance // [!code highlight]
const message = web3.utils.sha3("Deposit balance to Gas Tank"); // Message to sign // [!code highlight]
const message = message; // Message is generated in Construct Deposit Message
const privateKey = "0x1234"; // Private key of the address // [!code highlight]
const wallet = new ethers.Wallet(privateKey);
const signature = await wallet.signMessage(message);
HoangVD2 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -172,7 +172,7 @@ await fetch(`${GAS_TANK_ENDPOINT}/balances/increase`, {

This endpoint allows users to withdraw their balance from the Gas Tank platform.

To withdraw the balance, you need to sign the message with the private key of the address you want to withdraw the balance from. The `signature` field is the signature of the message signed by the address owner.
To withdraw the balance, you need to sign the message with the private key of the address you want to withdraw the balance from. The `signature` field is the signature of the message signed by the address owner and `message` is generated in [Aonstruct Withdraw Message](#construct-withdraw-message).

Same as the [Deposit balance](#deposit-balance), you can sign a string of data using [ethers.js](https://docs.ethers.org/v5/getting-started/), below is an example of [how to sign a message using ethers.js](https://docs.ethers.org/v5/getting-started/#getting-started--signing) and withdraw the balance.

Expand All @@ -184,7 +184,7 @@ import { ethers } from "ethers";
const web3 = new Web3(window.ethereum);
const GAS_TANK_ENDPOINT = "https://gas-tank.xdefi.services";
const address = "0x1234567890123456789012345678901234567890"; // Address to withdraw balance // [!code highlight]
HoangVD2 marked this conversation as resolved.
Show resolved Hide resolved
const message = web3.utils.sha3("Withdraw balance from Gas Tank"); // Message to sign // [!code highlight]
const message = message; // Message is generated in Construct Withdraw Message
const privateKey = "0x1234"; // Private key of the address // [!code highlight]
const wallet = new ethers.Wallet(privateKey);
const signature = await wallet.signMessage(message);
Expand Down Expand Up @@ -217,7 +217,7 @@ await fetch(`${GAS_TANK_ENDPOINT}/balances/withdraw`, {

### Internal transfer

This endpoint allows users to create an internal transfer task on the Gas Tank platform.
This endpoint allows users to create an internal transfer task on the Gas Tank platform. The internal transfer task is used to transfer balance from one address to another address on the Gas Tank platform. The `signature` field is the signature of the message signed by the address owner and `message` is generated in [Construct Internal Transfer Message](#construct-internal-transfer-message).

::: code-group

Expand All @@ -227,7 +227,7 @@ import { ethers } from "ethers";
const web3 = new Web3(window.ethereum);
const GAS_TANK_ENDPOINT = "https://gas-tank.xdefi.services";
const address = "0x1234567890123456789012345678901234567890"; // Address to transfer balance // [!code highlight]
const message = web3.utils.sha3("Transfer balance from Gas Tank"); // Message to sign // [!code highlight]
const message = message; // Message is generated in Construct Internal Transfer Message
const privateKey = "0x1234"; // Private key of the address // [!code highlight]
const wallet = new ethers.Wallet(privateKey);
const signature = await wallet.signMessage(message);
Expand Down Expand Up @@ -262,7 +262,7 @@ await fetch(`${GAS_TANK_ENDPOINT}/balances/transfer`, {

This endpoint allows users to consume their balance on the Gas Tank platform.

To consume the balance, you need to sign the message with the private key of the address you want to consume the balance from. The `signature` field is the signature of the message signed by the address owner.
To consume the balance, you need to sign the message with the private key of the address you want to consume the balance from. The `signature` field is the signature of the message signed by the address owner and `message` is generated in [Construct Consume Message](#construct-consume-message).

Same as the [Deposit balance](#deposit-balance)/[Withdraw balance](#withdraw-balance), you can sign a string of data using [ethers.js](https://docs.ethers.org/v5/getting-started/), below is an example of [how to sign a message using ethers.js](https://docs.ethers.org/v5/getting-started/#getting-started--signing) and consume the balance.

Expand All @@ -274,7 +274,7 @@ import { ethers } from "ethers";
const web3 = new Web3(window.ethereum);
const GAS_TANK_ENDPOINT = "https://gas-tank.xdefi.services";
const address = "0x1234567890123456789012345678901234567890"; // Address to consume balance // [!code highlight]
const message = web3.utils.sha3("Consume balance from Gas Tank"); // Message to sign // [!code highlight]
const message = message; // Message is generated in Construct Consume Message
const privateKey = "0x1234"; // Private key of the address // [!code highlight]
const wallet = new ethers.Wallet(privateKey);
const signature = await wallet.signMessage(message);
Expand Down
2 changes: 1 addition & 1 deletion gas-tank/chains-services.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Chains / Status
## Chains / Token / Status

### Get all Tokens

Expand Down
2 changes: 2 additions & 0 deletions gas-tank/gas-tank-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Below are the available services provided by the Gas Tank API. You need to have

<!--@include: ./authentication-services.md-->

<!--@include: ./messages-service.md-->

<!--@include: ./chains-services.md-->

<!--@include: ./balance-services.md-->
Expand Down
142 changes: 142 additions & 0 deletions gas-tank/messages-service.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
## Messages

### Construct Deposit Message

This endpoint will generate `messages` parameter for [Deposit balances](#deposit-balance).

::: code-group

```javascript [Request]
const GAS_TANK_ENDPOINT = "https://gas-tank.xdefi.services";

await fetch(`${GAS_TANK_ENDPOINT}/msg/increase`, {
davidp94 marked this conversation as resolved.
Show resolved Hide resolved
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
owner: "string", // [!code highlight]
tokenAddress: "string", // [!code highlight]
amount: "string", // [!code highlight]
chain: "string", // [!code highlight]
}),
}).then((response) => {
console.log(response);
// Handle & do something with the response
});
```

```json [Response]
{
"type": "string",
"message": "string"
}
```

:::

### Construct Withdraw Message

This endpoint will generate `messages` parameter for [Withdraw balances](#withdraw-balance).

::: code-group

```javascript [Request]
const GAS_TANK_ENDPOINT = "https://gas-tank.xdefi.services";

await fetch(`${GAS_TANK_ENDPOINT}/msg/withdraw`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
address: "string", // [!code highlight]
HoangVD2 marked this conversation as resolved.
Show resolved Hide resolved
tokenAddress: "string", // [!code highlight]
amount: "string", // [!code highlight]
chain: "string", // [!code highlight]
recipient: "string", // [!code highlight]
}),
}).then((response) => {
console.log(response);
// Handle & do something with the response
});
```

```json [Response]
{
"type": "string",
"message": "string"
}
```

:::

### Construct Internal Transfer Message

This endpoint will generate `messages` parameter for [Internal Transfer balances](#internal-transfer).

::: code-group

```javascript [Request]
const GAS_TANK_ENDPOINT = "https://gas-tank.xdefi.services";

await fetch(`${GAS_TANK_ENDPOINT}/msg/internal-transfer`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
HoangVD2 marked this conversation as resolved.
Show resolved Hide resolved
address: "string", // [!code highlight]
tokenAddress: "string", // [!code highlight]
amount: "string", // [!code highlight]
chain: "string", // [!code highlight]
recipient: "string", // [!code highlight]
}),
}).then((response) => {
console.log(response);
// Handle & do something with the response
});
```

```json [Response]
{
"type": "string",
"message": "string"
}
```

:::

### Construct Consume Message

This endpoint will generate `messages` parameter for [Consume balances](#consume-balance).

::: code-group

```javascript [Request]
const GAS_TANK_ENDPOINT = "https://gas-tank.xdefi.services";

await fetch(`${GAS_TANK_ENDPOINT}/msg/consume`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
address: "string", // [!code highlight]
minDestinationAmount: "string", // [!code highlight]
destinationChain: "string", // [!code highlight]
}),
}).then((response) => {
console.log(response);
// Handle & do something with the response
});
```

```json [Response]
{
"type": "string",
"message": "string"
}
```

:::
Loading