-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
185 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
MAX_OVER_TIME_DURATION=2d | ||
NODE_ENV=development | ||
PROM_QUERY_URL=http://localhost:9090 | ||
|
||
RADIX_URL=... | ||
DEVTOOLS_API_KEY=... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
{ | ||
"exec": "ts-node --files --project tsconfig.json src/index.ts" | ||
"exec": "ts-node --files --project tsconfig.json src/index.ts", | ||
"ext": "js, ts", | ||
"watch": ["src/"] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { RESTDataSource } from "@apollo/datasource-rest"; | ||
// KeyValueCache is the type of Apollo server's default cache | ||
import type { KeyValueCache } from "@apollo/utils.keyvaluecache"; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
require("dotenv").config(); | ||
|
||
if (!process.env.DEVTOOLS_API_KEY) { | ||
throw new Error("DEVTOOLS_API_KEY is not set"); | ||
} | ||
|
||
// https://suiexplorer.com/validator/0x1e1985024aafe50a8e4eafc5a89eb7ecd58ba08c39f37688bee00bd55c8b2059 | ||
const validatorAddress = | ||
"0x1e1985024aafe50a8e4eafc5a89eb7ecd58ba08c39f37688bee00bd55c8b2059"; | ||
|
||
// https://docs.sui.io/ | ||
export class SuiAPI extends RESTDataSource { | ||
override baseURL = `https://rpc-mainnet-sui.forbole.com`; | ||
|
||
constructor(options: { cache: KeyValueCache }) { | ||
super(options); // this sends our server's `cache` through | ||
} | ||
|
||
private getRequestContent(body: unknown) { | ||
return { | ||
headers: { | ||
"apikey": `${process.env.DEVTOOLS_API_KEY}`, | ||
"content-type": "application/json", | ||
}, | ||
body: JSON.stringify(body), | ||
}; | ||
} | ||
|
||
async getSuiBondedToken() { | ||
const [response, coinData] = await Promise.all([ | ||
this.post( | ||
`/`, | ||
this.getRequestContent({ | ||
id: 1, | ||
jsonrpc: "2.0", | ||
// This is the same method used by the official explorer | ||
method: "suix_getLatestSuiSystemState", | ||
params: [], | ||
}), | ||
), | ||
this.post( | ||
`/`, | ||
this.getRequestContent({ | ||
id: 1, | ||
jsonrpc: "2.0", | ||
method: "suix_getCoinMetadata", | ||
params: ["0x2::sui::SUI"], | ||
}), | ||
), | ||
]); | ||
|
||
const validator = response.result.activeValidators.find( | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
(v: any) => v.suiAddress === validatorAddress, | ||
); | ||
|
||
const decimals = coinData?.result?.decimals; | ||
const stakingPoolSuiBalance = validator?.stakingPoolSuiBalance; | ||
|
||
if (!decimals || !stakingPoolSuiBalance) { | ||
return { | ||
status: "error", | ||
}; | ||
} | ||
|
||
// https://github.com/MystenLabs/sui/blob/cdcfa76c4304caff2496e7b9ba535086704585d5/apps/explorer/src/components/validator/ValidatorStats.tsx#L31 | ||
const bondedToken = validator?.stakingPoolSuiBalance / 10 ** decimals; | ||
|
||
return { | ||
status: "success", | ||
data: { | ||
bondedToken, | ||
}, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters