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
Show file tree
Hide file tree
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
28 changes: 27 additions & 1 deletion .vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,33 @@ function sidebarHome() {
{
text: "⛽ Gas Tank API",
link: "/gas-tank/gas-tank-api",
items: [],
collapsed: true,
items: [
{
text: "🔹 Introduction",
link: "/gas-tank/gas-tank-api",
},
{
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-token-status",
},
{
text: "🔹 Balances & Gas top-up: Deposit, Withdraw, Send Gas",
link: "/gas-tank/gas-tank-api#balance-transactions-deposit-withdraw-send-gas",
},
{
text: "🔹 Other services",
link: "/gas-tank/gas-tank-api#other-services",
},
],
},
{
text: "🛠️ Partners APIs",
Expand Down
6 changes: 3 additions & 3 deletions assets-services/assets-and-prices-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ getAssetsTokens();

Get Assets Crypto Currencies provides information about cryptocurrencies on various blockchains, including Ethereum, Binance Smart Chain, and Solana. The API returns data such as the cryptocurrency's name, symbol, icon, type, external data, scaling factor, chain, market cap, and price.

[Query GraphQL directly here](https://gql-router.dev.xdefi.services/graphql?explorerURLState=N4IgJg9gxgrgtgUwHYBcQC4QEcYIE4CeABAMKEAOKEJMeeyUAlggM4AUAJOQIYDmC6UhCRIEUFI2EBBPLxYBCADREOAM0YAbFPkFkClarXpIoBAGKbteZR26qrABTyMoAogBFu2gCqNENuytBTx8-BABKImAAHSQiIm4WFgQUFijY%2BPioCioaOgZmdh5%2BQS4%2BBGV1LR0VKqtlQPwnFzdbeybnVwb2vFLGvEiYuMz44oQQ7nThkayIGFQMmfiNP0YURaWIVVVk9enMgF8NzLGppdHygEkkVQgz8-iAC0SAOQQADxQHcuOl5DA8iwIHhfodQfEEGB%2BGkhg94kgIGAEPc4URGGBwTMkNxEJiRiwCHAAEYQDR4zIuYTk%2BIofQIalED5WbEaCYMuDcPAAaxSJG45AZLCg3BWSF4Zm44mBDKgz0YSAZ5E6yNhqMyOLmC32DyO2pmup1oINYOGuoOIEUIAAbpzGNwiRpWBgQKroiAxm7BKr4m71HgWOsMEQAKyKY5u-qeohIGAaMmmsPDX2WfBR71EN2y7jylhRmNxxMjN3o3NB-MaQuZN0E4mk0uCcuLA6ViM9ZquPOxiuLVtWTtx2Lmy3kCAB1QrXiPFAAeXI%2BC8kiQAGVsoxKM6QAcgA)
[Query GraphQL directly here](https://gql-router.xdefi.services/graphql?explorerURLState=N4IgJg9gxgrgtgUwHYBcQC4QEcYIE4CeABAMKEAOKEJMeeyUAlggM4AUAJOQIYDmC6UhCRIEUFI2EBBPLxYBCADREOAM0YAbFPkFkClarXpIoBAGKbteZR26qrABTyMoAogBFu2gCqNENuytBTx8-BABKImAAHSQiIm4WFgQUFijY%2BPioCioaOgZmdh5%2BQS4%2BBGV1LR0VKqtlQPwnFzdbeybnVwb2vFLGvEiYuMz44oQQ7nThkayIGFQMmfiNP0YURaWIVVVk9enMgF8NzLGppdHygEkkVQgz8-iAC0SAOQQADxQHcuOl5DA8iwIHhfodQfEEGB%2BGkhg94kgIGAEPc4URGGBwTMkNxEJiRiwCHAAEYQDR4zIuYTk%2BIofQIalED5WbEaCYMuDcPAAaxSJG45AZLCg3BWSF4Zm44mBDKgz0YSAZ5E6yNhqMyOLmC32DyO2pmup1oINYOGuoOIEUIAAbpzGNwiRpWBgQKroiAxm7BKr4m71HgWOsMEQAKyKY5u-qeohIGAaMmmsPDX2WfBR71EN2y7jylhRmNxxMjN3o3NB-MaQuZN0E4mk0uCcuLA6ViM9ZquPOxiuLVtWTtx2Lmy3kCAB1QrXiPFAAeXI%2BC8kiQAGVsoxKM6QAcgA)

::: code-group

Expand Down Expand Up @@ -229,7 +229,7 @@ getCryptoCurrencies();

Get Assets Fiat Currencies provides information about fiat currencies on various blockchains, including Ethereum, Binance Smart Chain, and Solana. The API returns data such as the fiat currency's name, symbol, scaling factor, character, and price.

[Query GraphQL directly here](https://gql-router.dev.xdefi.services/graphql?explorerURLState=N4IgJg9gxgrgtgUwHYBcQC4QEcYIE4CeABAGICWAhigMIx57JRkIDOAFACQAOFA5guiLUISJAigoyIgIJ5eLAIQAaIhwBmZADYp8g8lVr1GBctvwqOFNTryCAIlQQAVMogtWbABTxkoAog46LogAlETAADpIREQULCwIKCzhUTExGgZ0DEhMrGw8-ILcfAgqGma2quU2Kh66qnV4tdb43r7%2Bli14bX5hkdFpMQUIgRQpA4MxUBAwqKmTMZquZCjzCxBqagmrE2kAvmtpw%2BMLQyUAkkhqECenMchghiwQeIcLABZxAHIIAB4onhKb32wPuYH4yX6dxiSAgYAQt2hRDIYFBkyQFEQaMGLAIcAARhBNNi0iwoBQlkheCQKBIXiSpp88LSbAyiFwfH5EUjYnAZnNdncDoLJsKhcCxSCBsK9iAlCAAG4UHwUfGaVgYEBQogREDDXWCbUxXUaPAsVYYIgAViUh11jQNRCQME0xOltoGJq0rMtRp1IBRLEdztd8z2HuNIAdlpDmgj-saPQQwZdbtl8q4EHNaiWvHeKAA8lx8FQpEgAMpQHxcNCYEB7IA)
[Query GraphQL directly here](https://gql-router.xdefi.services/graphql?explorerURLState=N4IgJg9gxgrgtgUwHYBcQC4QEcYIE4CeABAGICWAhigMIx57JRkIDOAFACQAOFA5guiLUISJAigoyIgIJ5eLAIQAaIhwBmZADYp8g8lVr1GBctvwqOFNTryCAIlQQAVMogtWbABTxkoAog46LogAlETAADpIREQULCwIKCzhUTExGgZ0DEhMrGw8-ILcfAgqGma2quU2Kh66qnV4tdb43r7%2Bli14bX5hkdFpMQUIgRQpA4MxUBAwqKmTMZquZCjzCxBqagmrE2kAvmtpw%2BMLQyUAkkhqECenMchghiwQeIcLABZxAHIIAB4onhKb32wPuYH4yX6dxiSAgYAQt2hRDIYFBkyQFEQaMGLAIcAARhBNNi0iwoBQlkheCQKBIXiSpp88LSbAyiFwfH5EUjYnAZnNdncDoLJsKhcCxSCBsK9iAlCAAG4UHwUfGaVgYEBQogREDDXWCbUxXUaPAsVYYIgAViUh11jQNRCQME0xOltoGJq0rMtRp1IBRLEdztd8z2HuNIAdlpDmgj-saPQQwZdbtl8q4EHNaiWvHeKAA8lx8FQpEgAMpQHxcNCYEB7IA)

::: code-group

Expand Down Expand Up @@ -321,7 +321,7 @@ getFiatCurrencies();

Get LP Tokens is fully the same structure as Get Assets Tokens but it’s like "Low Priority" tokens. The API returns data such as the LP token's symbol, scaling factor, address, chain, fees, defi protocols and external data.

[Query GraphQL directly here](https://gql-router.dev.xdefi.services/graphql?explorerURLState=N4IgJg9gxgrgtgUwHYBcQC4QEcYIE4CeABADIAKAKhANbIDOAFACQAOAhgOYLpEDCESJAigoAlgICCeDnQCEAGiJMAZqIA2KfDyq0kAMXWa8ipm2VGeAETaaKoxCbNGyeUVG5Frt%2BwgCURYAAdJCIiNjo6BBQ6AODQ0LUWHXoGdi4eVk4ERVUNLSVco0UnfNNzfGLyvBc3DzLnV3d-IJD40LSELzZY1rbQqAgYVDi%2BhPtRFBHRiGVlSMne%2BIBfKfiOntH2rIBJJGUIDc3Q5DBeGDw6CDxV0YALcIA5BAAPFDIsm%2BXP47AuGJajqEkBAwAhDoCiANUHg2CJ-t9NqIwAjRnQCHAAEYQNQovp0KBsNSiJAcPSwlBXXFtNhgMB4BARKnxKD3YlM0LKBBggEQvoAN0JuHZRBWiwhoNULggFIGanBvP6rKQwtCbgEKqISDYiGFooVet5LyMWrUXSZSPNUKZWp1Ys2cDYeFoKF4bBYTJYjW5wu1g2GdtGBohaMx2KZKAILAQuKDfVjoVjBtFSxA8hAAtcbAxagZGBAPMCIA6hZ4PNChdUF0mGCIAFZ5KtCyVrjWkDA1DjWksG60K4Z8CX5YWQ1i1HRB22Oz22oWkePW%2B21NP4oWWWxifOeJOl42QDS6QzN5rFyNuyMm1UJ4vlxeGrUrx3gim0ywIHQUMoiRxbigAPJRmExAEABlKBXBYNBMBAJYgA)
[Query GraphQL directly here](https://gql-router.xdefi.services/graphql?explorerURLState=N4IgJg9gxgrgtgUwHYBcQC4QEcYIE4CeABADIAKAKhANbIDOAFACQAOAhgOYLpEDCESJAigoAlgICCeDnQCEAGiJMAZqIA2KfDyq0kAMXWa8ipm2VGeAETaaKoxCbNGyeUVG5Frt%2BwgCURYAAdJCIiNjo6BBQ6AODQ0LUWHXoGdi4eVk4ERVUNLSVco0UnfNNzfGLyvBc3DzLnV3d-IJD40LSELzZY1rbQqAgYVDi%2BhPtRFBHRiGVlSMne%2BIBfKfiOntH2rIBJJGUIDc3Q5DBeGDw6CDxV0YALcIA5BAAPFDIsm%2BXP47AuGJajqEkBAwAhDoCiANUHg2CJ-t9NqIwAjRnQCHAAEYQNQovp0KBsNSiJAcPSwlBXXFtNhgMB4BARKnxKD3YlM0LKBBggEQvoAN0JuHZRBWiwhoNULggFIGanBvP6rKQwtCbgEKqISDYiGFooVet5LyMWrUXSZSPNUKZWp1Ys2cDYeFoKF4bBYTJYjW5wu1g2GdtGBohaMx2KZKAILAQuKDfVjoVjBtFSxA8hAAtcbAxagZGBAPMCIA6hZ4PNChdUF0mGCIAFZ5KtCyVrjWkDA1DjWksG60K4Z8CX5YWQ1i1HRB22Oz22oWkePW%2B21NP4oWWWxifOeJOl42QDS6QzN5rFyNuyMm1UJ4vlxeGrUrx3gim0ywIHQUMoiRxbigAPJRmExAEABlKBXBYNBMBAJYgA)

::: code-group

Expand Down
2 changes: 1 addition & 1 deletion components/staking/CreateCosmosDelegateTx.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PlayIcon from "../PlayIcon";
import { cosmosSupportedAssets as assetSupported } from "../common";

const CreateCosmosDelegateTx = () => {
const GRAPHQL_ENDPOINT = "https://gql-router.dev.xdefi.services/graphql";
const GRAPHQL_ENDPOINT = "https://gql-router.xdefi.services/graphql";
const validators = ["Meria", "StakeLab", "Custom"];

const [loading, setLoading] = useState(false);
Expand Down
2 changes: 1 addition & 1 deletion components/staking/CreateErc20ApproveTx.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PlayIcon from "../PlayIcon";
import { otherSupportedAssets as assetSupported } from "../common";

const CreateErc20ApproveTx = () => {
const GRAPHQL_ENDPOINT = "https://gql-router.dev.xdefi.services/graphql";
const GRAPHQL_ENDPOINT = "https://gql-router.xdefi.services/graphql";
const [loading, setLoading] = useState(false);
const [response, setResponse] = useState({});
const [assetSelected, setAssetSelected] = useState(undefined);
Expand Down
2 changes: 1 addition & 1 deletion components/staking/CreateLidoStakeTx.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PlayIcon from "../PlayIcon";
import { otherSupportedAssets as assetSupported } from "../common";

const CreateLidoStakeTx = () => {
const GRAPHQL_ENDPOINT = "https://gql-router.dev.xdefi.services/graphql";
const GRAPHQL_ENDPOINT = "https://gql-router.xdefi.services/graphql";
const [loading, setLoading] = useState(false);
const [response, setResponse] = useState({});
const [assetSelected, setAssetSelected] = useState(undefined);
Expand Down
2 changes: 1 addition & 1 deletion components/staking/CreateStrideLiquidStakingTx.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PlayIcon from "../PlayIcon";
import { cosmosSupportedAssets as assetSupported } from "../common";

const CreateStrideLiquidStakingTx = () => {
const GRAPHQL_ENDPOINT = "https://gql-router.dev.xdefi.services/graphql";
const GRAPHQL_ENDPOINT = "https://gql-router.xdefi.services/graphql";
const [loading, setLoading] = useState(false);
const [response, setResponse] = useState({});
const [assetSelected, setAssetSelected] = useState(undefined);
Expand Down
2 changes: 1 addition & 1 deletion components/staking/GetCosmosDelegations.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PlayIcon from "../PlayIcon";
import { cosmosSupportedAssets as assetSupported } from "../common";

const GetCosmosDelegations = () => {
const GRAPHQL_ENDPOINT = "https://gql-router.dev.xdefi.services/graphql";
const GRAPHQL_ENDPOINT = "https://gql-router.xdefi.services/graphql";
const [loading, setLoading] = useState(false);
const [response, setResponse] = useState({});
const [assetSelected, setAssetSelected] = useState(undefined);
Expand Down
2 changes: 1 addition & 1 deletion components/staking/GetLidoStakedBalance.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PlayIcon from "../PlayIcon";
import { otherSupportedAssets as assetSupported } from "../common";

const GetLidoStakedBalance = () => {
const GRAPHQL_ENDPOINT = "https://gql-router.dev.xdefi.services/graphql";
const GRAPHQL_ENDPOINT = "https://gql-router.xdefi.services/graphql";
const [loading, setLoading] = useState(false);
const [response, setResponse] = useState({});
const [assetSelected, setAssetSelected] = useState(undefined);
Expand Down
2 changes: 1 addition & 1 deletion components/staking/GetStrideStakedAssetBalance.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PlayIcon from "../PlayIcon";
import { cosmosSupportedAssets as assetSupported } from "../common";

const GetStrideStakedAssetBalance = () => {
const GRAPHQL_ENDPOINT = "https://gql-router.dev.xdefi.services/graphql";
const GRAPHQL_ENDPOINT = "https://gql-router.xdefi.services/graphql";
const [loading, setLoading] = useState(false);
const [response, setResponse] = useState({});
const [assetSelected, setAssetSelected] = useState(undefined);
Expand Down
133 changes: 133 additions & 0 deletions gas-tank/authentication-services.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
## Authentication

### Multiple Addresses Login

This endpoint facilitates the generation of JWT tokens for multiple wallet addresses in a single request. The request payload should consist of an array of objects, each containing an address and its corresponding signature. Upon successful validation of the signatures, the server will generate JWT tokens for the provided addresses.

To get signatures, you can use `personal_sign` method from web3.js or ethers.js. Below is an example of how to get a signature using web3.js:

::: code-group
HoangVD2 marked this conversation as resolved.
Show resolved Hide resolved

```javascript [Request]
const web3 = new Web3(window.ethereum);
const GAS_TANK_ENDPOINT = "https://gas-tank.xdefi.services";

const address1 = "0x1234567890123456789012345678901234567890";
const address2 = "0x0987654321098765432109876543210987654321";

const messageToSign = await (
await fetch(`${GAS_TANK_ENDPOINT}/v2/auth/message`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify([address1, address2]),
})
).json();

const message = messageToSign.message;


const signature1 = await web3.eth.personal.sign(message, address1);
const signature2 = await web3.eth.personal.sign(message, address2);

await fetch(`${GAS_TANK_ENDPOINT}/v2/auth/login`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify([
{
address: address1, // Address of the user // [!code highlight]
signature: signature1, // Signature // [!code highlight]
},
{
address: address2, // [!code highlight]
signature: signature2, // [!code highlight]
},
...
]),
})
.then((response) => {
console.log(response);
// Handle & do something with the response
})
```

```json [Response]
{
"access": "jwt.access.token",
"refresh": "jwt.refresh.token"
}
```

:::

You can also add new wallets to an existing JWT token. Request will be secured by JWT header. Clients need to submit an array of objects containing the address and signature for each new wallet. The server will validate the signatures and, if successful, update the existing JWT token to include the new wallets and generate new JWT.

::: code-group

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

await fetch(`${GAS_TANK_ENDPOINT}/v2/auth/update`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${jwtToken}`, // JWT token // [!code highlight]
},
body: JSON.stringify([
{
address: newAddress, // [!code highlight]
signature: newSignature, // [!code highlight]
},
...
]),
})
.then((response) => {
console.log(response);
// Handle & do something with the response
})
```

```json [Response]
{
"access": "jwt.access.token",
"refresh": "jwt.refresh.token"
}
```

:::

### Refresh JWT Token

Clients can use this endpoint to obtain a new JWT token without re-authenticating, providing a refresh token.

::: code-group

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

await fetch(`${GAS_TANK_ENDPOINT}/v2/auth/refresh`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${jwtToken}`, // JWT token // [!code highlight]
},
body: JSON.stringify({
refresh: refreshToken, // Refresh token // [!code highlight]
}),
}).then((response) => {
console.log(response);
// Handle & do something with the response
});
```

```json [Response]
{
"access": "jwt.access.token",
"refresh": "jwt.refresh.token"
}
```

:::
Loading
Loading