@olympex-io/olympex-sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,107 @@
1
+ # Getting Started
2
+
3
+ This SDK is a thin GraphQL client over the Olympex backend. It signs requests **server-side**
4
+ using `apiKey`, `apiSecret`, and `passphrase`.
5
+
6
+ > **Server-side only** — do not use this SDK directly in browser bundles. See
7
+ > `docs/authentication.md`.
8
+
9
+ ## Backend URL
10
+
11
+ The SDK resolves the GraphQL endpoint from `OLYMPEX_BACKEND_URL` at call time. When unset,
12
+ empty, or whitespace-only, it defaults to production (`https://back.olympex.io/graphql`).
13
+
14
+ You may set either the backend origin or the full GraphQL path:
15
+
16
+ | Deployment | Example `OLYMPEX_BACKEND_URL` |
17
+ | ---------- | ------------------------------------------------------------------------------ |
18
+ | Production | _(unset — uses default)_ |
19
+ | Staging | `https://staging-back.olympex.io` or `https://staging-back.olympex.io/graphql` |
20
+ | Local dev | `http://localhost:4000` or `http://localhost:4000/graphql` |
21
+
22
+ GraphQL requests use the resolved endpoint. REST onboarding POSTs to `{origin}/api/v1/accounts`
23
+ (the SDK strips `/graphql` from the resolved endpoint when needed).
24
+
25
+ ## Minimal Node example
26
+
27
+ ```ts
28
+ import { initialize } from '@olympex-io/olympex-sdk';
29
+
30
+ const client = initialize({
31
+ apiKey: process.env.OLYMPEX_API_KEY!,
32
+ apiSecret: process.env.OLYMPEX_API_SECRET!,
33
+ passphrase: process.env.OLYMPEX_PASSPHRASE!,
34
+ });
35
+
36
+ console.log(client.getVersion());
37
+ console.log(await client.supportChain(1));
38
+ ```
39
+
40
+ For staging or local backends, set `OLYMPEX_BACKEND_URL` in your environment before calling
41
+ `initialize` or `createAccount`.
42
+
43
+ ## Account onboarding
44
+
45
+ `createAccount` is REST-based and does not require `initialize`:
46
+
47
+ ```ts
48
+ import { createAccount } from '@olympex-io/olympex-sdk';
49
+
50
+ const credentials = await createAccount({
51
+ name: 'My App',
52
+ password: process.env.OLYMPEX_ACCOUNT_PASSWORD!,
53
+ });
54
+
55
+ // credentials.apiKey → OLYMPEX_API_KEY
56
+ // credentials.secretKey → OLYMPEX_API_SECRET
57
+ // password above → OLYMPEX_PASSPHRASE
58
+ ```
59
+
60
+ See `docs/authentication.md` for the full credential lifecycle.
61
+
62
+ ## Quote
63
+
64
+ Fees are configured per request with `feeRecipient` and optional `feeBps`. These declare **integrator margin**; channel resolution and `platformFeeIntegrator` are backend-owned from signed auth. See [`fees.md`](./fees.md).
65
+
66
+ ```ts
67
+ const quote = await client.quote({
68
+ mode: 'cross-chain',
69
+ params: {
70
+ fromChainId: 56,
71
+ toChainId: 137,
72
+ fromTokenAddress: '0x...',
73
+ toTokenAddress: '0x...',
74
+ amount: '1',
75
+ slippage: '0.5',
76
+ },
77
+ fees: {
78
+ feeBps: 15,
79
+ feeRecipient: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
80
+ },
81
+ });
82
+ ```
83
+
84
+ ## Swap
85
+
86
+ ```ts
87
+ const swap = await client.swap({
88
+ mode: 'single-chain',
89
+ params: {
90
+ chainId: 1,
91
+ inTokenAddress: '0x...',
92
+ outTokenAddress: '0x...',
93
+ amount: '1',
94
+ slippage: '1',
95
+ gasPrice: '30',
96
+ account: '0x...',
97
+ aggregatorId: 'olympex',
98
+ },
99
+ fees: {
100
+ feeRecipient: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
101
+ },
102
+ });
103
+ ```
104
+
105
+ Optional fee fields (`feeBps`, `feeRecipient`) can also be set once via
106
+ `initialize({ defaultFees })`. Per-call `fees` override client defaults.
107
+ See [docs/fees.md](./fees.md).
@@ -0,0 +1,85 @@
1
+ # SDK logging
2
+
3
+ The Olympex SDK is **silent by default**. No log output is produced unless you pass an `OlympexLogger` to `initialize({ logger })`.
4
+
5
+ ## OlympexLogger contract
6
+
7
+ ```typescript
8
+ interface OlympexLogger {
9
+ log(level: LogLevel, message: string, metadata?: Record<string, unknown>): void;
10
+ }
11
+
12
+ type LogLevel = 'debug' | 'info' | 'warn' | 'error';
13
+ ```
14
+
15
+ - Compatible with pino, winston, or any adapter that exposes the same `log(level, message, metadata?)` signature.
16
+ - Your implementation **must not throw** — a throwing logger can break SDK methods mid-flight.
17
+ - All SDK-emitted `metadata` is passed through `redact()` before reaching your logger (api keys, tokens, secrets stripped).
18
+
19
+ ## createConsoleLogger
20
+
21
+ Zero-dependency console adapter for quick local debugging:
22
+
23
+ ```typescript
24
+ import { createConsoleLogger, initialize } from '@olympex-io/olympex-sdk';
25
+
26
+ const client = initialize({
27
+ apiKey: process.env.OLYMPEX_API_KEY!,
28
+ logger: createConsoleLogger({ minLevel: 'info' }), // default minLevel is 'info'
29
+ });
30
+ ```
31
+
32
+ | Option | Default | Description |
33
+ | ---------- | -------- | ----------------------------------------------------------------------- |
34
+ | `minLevel` | `'info'` | Suppresses levels below this rank (`debug` < `info` < `warn` < `error`) |
35
+
36
+ Use `minLevel: 'debug'` to see outgoing GraphQL request metadata in the console.
37
+
38
+ ## Stable log message strings
39
+
40
+ Callers may grep or match on these strings. Treat them as part of the public log surface:
41
+
42
+ | Level | Message |
43
+ | ------- | ------------------------------------------------- |
44
+ | `debug` | `Sending Olympex GraphQL request` |
45
+ | `warn` | `Olympex GraphQL response contains errors` |
46
+ | `error` | `Olympex GraphQL request failed with HTTP status` |
47
+ | `error` | `Olympex GraphQL response was not valid JSON` |
48
+ | `error` | `Olympex GraphQL network failure` |
49
+ | `info` | `Olympex quote requested` |
50
+ | `info` | `Olympex swap requested` |
51
+
52
+ Quote/swap `info` logs include only `mode` and chain id(s) — never amounts, routes, token addresses, or fee values.
53
+
54
+ ## pino adapter (5 lines)
55
+
56
+ No peer dependency is bundled; wire pino yourself:
57
+
58
+ ```typescript
59
+ import pino from 'pino';
60
+ import type { OlympexLogger } from '@olympex-io/olympex-sdk';
61
+
62
+ const pinoLogger = pino({ level: 'info' });
63
+ const logger: OlympexLogger = {
64
+ log(level, message, metadata) {
65
+ pinoLogger[level](metadata ?? {}, message);
66
+ },
67
+ };
68
+ ```
69
+
70
+ ## winston adapter (5 lines)
71
+
72
+ ```typescript
73
+ import winston from 'winston';
74
+ import type { OlympexLogger } from '@olympex-io/olympex-sdk';
75
+
76
+ const winstonLogger = winston.createLogger({
77
+ level: 'info',
78
+ transports: [new winston.transports.Console()],
79
+ });
80
+ const logger: OlympexLogger = {
81
+ log(level, message, metadata) {
82
+ winstonLogger.log(level, message, metadata);
83
+ },
84
+ };
85
+ ```
@@ -0,0 +1,25 @@
1
+ # Public methods
2
+
3
+ Method-level contracts for the partner SDK. Each page describes inputs, outputs, and error boundaries. The SDK is a thin GraphQL/REST client — it does not compute routes, fees, or calldata locally.
4
+
5
+ | Method | Doc | Requires `initialize` |
6
+ | --------------- | --------------------------------------------- | --------------------- |
7
+ | `initialize` | [`getting-started.md`](../getting-started.md) | — |
8
+ | `createAccount` | [`create-account.md`](./create-account.md) | No |
9
+ | `quote` | [`quote.md`](./quote.md) | Yes |
10
+ | `swap` | [`swap.md`](./swap.md) | Yes |
11
+ | `supportChain` | [`getting-started.md`](../getting-started.md) | Yes |
12
+ | `txStatus` | SDK JSDoc / backend schema | Yes |
13
+ | `getVersion` | README | No |
14
+
15
+ ## GitBook export note
16
+
17
+ Partner documentation lives in this repository under `docs/`. For GitBook or similar portals, sync these markdown files (plus `README.md`) rather than maintaining a separate copy. Suggested structure:
18
+
19
+ - Getting started → `docs/getting-started.md`
20
+ - Authentication → `docs/authentication.md`
21
+ - Fees → `docs/fees.md`
22
+ - Errors → `docs/errors.md`
23
+ - Methods → `docs/methods/*`
24
+
25
+ Until a GitBook space is provisioned, treat this folder as the source of truth.
@@ -0,0 +1,62 @@
1
+ # `createAccount`
2
+
3
+ Server-side REST bootstrap for partner credentials. Does **not** require `initialize`.
4
+
5
+ ## Signature
6
+
7
+ ```ts
8
+ createAccount(input: CreateAccountInput, options?: CreateAccountOptions): Promise<CreateAccountResponse>
9
+ ```
10
+
11
+ ## REST contract
12
+
13
+ ```
14
+ POST {origin}/api/v1/accounts
15
+ Content-Type: application/json
16
+
17
+ { "name": "<app name>", "password": "<strong passphrase>" }
18
+ ```
19
+
20
+ The SDK resolves `{origin}` from `OLYMPEX_BACKEND_URL` (see [`getting-started.md`](../getting-started.md#backend-url)).
21
+
22
+ ## Response
23
+
24
+ | Field | Maps to |
25
+ | ------------------ | --------------------------------------------------- |
26
+ | `apiKey` | `initialize({ apiKey })` / `OLYMPEX_API_KEY` |
27
+ | `secretKey` | `initialize({ apiSecret })` / `OLYMPEX_API_SECRET` |
28
+ | `password` (input) | `initialize({ passphrase })` / `OLYMPEX_PASSPHRASE` |
29
+
30
+ `secretKey` is returned **once** at creation. Store it immediately in a secret manager.
31
+
32
+ ## Example
33
+
34
+ ```ts
35
+ import { createAccount, initialize } from '@olympex-io/olympex-sdk';
36
+
37
+ const { apiKey, secretKey } = await createAccount({
38
+ name: 'My Integration',
39
+ password: process.env.OLYMPEX_ACCOUNT_PASSWORD!,
40
+ });
41
+
42
+ const client = initialize({
43
+ apiKey,
44
+ apiSecret: secretKey,
45
+ passphrase: process.env.OLYMPEX_ACCOUNT_PASSWORD!,
46
+ });
47
+ ```
48
+
49
+ Run bootstrap only from trusted server automation — never from browser code. See [`authentication.md`](../authentication.md).
50
+
51
+ ## Errors
52
+
53
+ | Failure | Error class |
54
+ | ----------------------------------- | --------------------- |
55
+ | Invalid input (empty name/password) | `OlympexConfigError` |
56
+ | HTTP/network failure | `OlympexNetworkError` |
57
+ | Unexpected response shape | `OlympexNetworkError` |
58
+
59
+ ## Non-goals
60
+
61
+ - Credential rotation API (contact Olympex ops)
62
+ - Browser-accessible onboarding
@@ -0,0 +1,84 @@
1
+ # `quote`
2
+
3
+ Returns a backend-computed quote for a single-chain or cross-chain swap. The SDK validates and forwards parameters; it does not calculate routes, amounts, or fees.
4
+
5
+ ## Signature
6
+
7
+ ```ts
8
+ quote(input: QuoteRequest): Promise<QuoteResult>
9
+ ```
10
+
11
+ Available on the object returned by `initialize`.
12
+
13
+ ## Modes
14
+
15
+ | Mode | GraphQL operation | Key params |
16
+ | -------------- | -------------------- | ----------------------------------------------------------------- |
17
+ | `single-chain` | `getQuote` | `chainId`, token addresses, `amount`, `slippage`, `gasPrice` |
18
+ | `cross-chain` | `getCrossChainQuote` | `fromChainId`, `toChainId`, token addresses, `amount`, `slippage` |
19
+
20
+ ## Optional fees
21
+
22
+ Pass `fees: { feeBps?, feeRecipient? }` to declare integrator margin for this call. Per-call `fees` override `initialize({ defaultFees })`. See [`fees.md`](../fees.md).
23
+
24
+ ## Example — single-chain
25
+
26
+ ```ts
27
+ import { initialize } from '@olympex-io/olympex-sdk';
28
+
29
+ const client = initialize({
30
+ apiKey: process.env.OLYMPEX_API_KEY!,
31
+ apiSecret: process.env.OLYMPEX_API_SECRET!,
32
+ passphrase: process.env.OLYMPEX_PASSPHRASE!,
33
+ });
34
+
35
+ const result = await client.quote({
36
+ mode: 'single-chain',
37
+ params: {
38
+ chainId: 1,
39
+ inTokenAddress: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
40
+ outTokenAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
41
+ amount: '1',
42
+ slippage: '1',
43
+ gasPrice: '30',
44
+ },
45
+ fees: {
46
+ feeBps: 15,
47
+ feeRecipient: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
48
+ },
49
+ });
50
+
51
+ console.log(result.mode, result.quote);
52
+ ```
53
+
54
+ ## Example — cross-chain
55
+
56
+ ```ts
57
+ const result = await client.quote({
58
+ mode: 'cross-chain',
59
+ params: {
60
+ fromChainId: 56,
61
+ toChainId: 137,
62
+ fromTokenAddress: '0x...',
63
+ toTokenAddress: '0x...',
64
+ amount: '1',
65
+ slippage: '0.5',
66
+ },
67
+ });
68
+ ```
69
+
70
+ ## Errors
71
+
72
+ | Failure | Error class |
73
+ | ---------------------------------- | -------------------------------------- |
74
+ | Invalid `feeBps`, address, or mode | `OlympexConfigError` (no network call) |
75
+ | Backend `success: false` | `OlympexDomainError` |
76
+ | GraphQL execution errors | `OlympexGraphQLError` |
77
+ | Network, timeout, 401/403 | `OlympexNetworkError` |
78
+
79
+ See [`errors.md`](../errors.md).
80
+
81
+ ## Non-goals
82
+
83
+ - Local route or price calculation
84
+ - Channel detection or protocol fee selection
@@ -0,0 +1,69 @@
1
+ # `swap`
2
+
3
+ Builds swap calldata and metadata from a backend quote path. The SDK validates and forwards parameters; execution happens on-chain via returned calldata.
4
+
5
+ ## Signature
6
+
7
+ ```ts
8
+ swap(input: SwapRequest): Promise<SwapResult>
9
+ ```
10
+
11
+ Available on the object returned by `initialize`.
12
+
13
+ ## Modes
14
+
15
+ | Mode | GraphQL operation | Key params |
16
+ | -------------- | ------------------- | ---------------------------------------------------------------------------------- |
17
+ | `single-chain` | `getQuoteSwap` | `chainId`, tokens, `amount`, `slippage`, `gasPrice`, `account`, `aggregatorId` |
18
+ | `cross-chain` | `getCrossChainSwap` | `fromChainId`, `toChainId`, tokens, `amount`, `slippage`, `account`, bridge fields |
19
+
20
+ ## Optional fees
21
+
22
+ Same integrator margin fields as `quote`. See [`fees.md`](../fees.md).
23
+
24
+ ## Example — single-chain
25
+
26
+ ```ts
27
+ import { initialize } from '@olympex-io/olympex-sdk';
28
+
29
+ const client = initialize({
30
+ apiKey: process.env.OLYMPEX_API_KEY!,
31
+ apiSecret: process.env.OLYMPEX_API_SECRET!,
32
+ passphrase: process.env.OLYMPEX_PASSPHRASE!,
33
+ });
34
+
35
+ const result = await client.swap({
36
+ mode: 'single-chain',
37
+ params: {
38
+ chainId: 1,
39
+ inTokenAddress: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
40
+ outTokenAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
41
+ amount: '1',
42
+ slippage: '1',
43
+ gasPrice: '30',
44
+ account: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
45
+ aggregatorId: 'olympex',
46
+ },
47
+ fees: {
48
+ feeRecipient: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
49
+ },
50
+ });
51
+
52
+ console.log(result.mode, result.swap);
53
+ ```
54
+
55
+ ## Errors
56
+
57
+ | Failure | Error class |
58
+ | -------------------------------- | --------------------- |
59
+ | Invalid fees, addresses, or mode | `OlympexConfigError` |
60
+ | Backend `success: false` | `OlympexDomainError` |
61
+ | GraphQL errors | `OlympexGraphQLError` |
62
+ | Network / auth failures | `OlympexNetworkError` |
63
+
64
+ See [`errors.md`](../errors.md).
65
+
66
+ ## Non-goals
67
+
68
+ - Local calldata generation or fee math
69
+ - Wallet signing (integrator signs and submits returned transactions)
package/package.json ADDED
@@ -0,0 +1,88 @@
1
+ {
2
+ "name": "@olympex-io/olympex-sdk",
3
+ "repository": {
4
+ "type": "git",
5
+ "url": "git+https://github.com/olympexio/olympex-sdk.git"
6
+ },
7
+ "version": "0.1.0",
8
+ "description": "Official TypeScript SDK for Olympex partner integrations.",
9
+ "license": "Apache-2.0",
10
+ "packageManager": "yarn@4.15.0",
11
+ "type": "commonjs",
12
+ "main": "./dist/index.js",
13
+ "module": "./dist/index.mjs",
14
+ "types": "./dist/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "node": {
19
+ "import": "./dist/index.mjs",
20
+ "require": "./dist/index.js"
21
+ },
22
+ "import": "./dist/index.mjs",
23
+ "require": "./dist/index.js",
24
+ "default": "./dist/index.mjs"
25
+ },
26
+ "./package.json": "./package.json"
27
+ },
28
+ "files": [
29
+ "dist",
30
+ "docs",
31
+ "README.md",
32
+ "LICENSE",
33
+ "package.json"
34
+ ],
35
+ "sideEffects": false,
36
+ "engines": {
37
+ "node": ">=22.15.0"
38
+ },
39
+ "publishConfig": {
40
+ "access": "public",
41
+ "provenance": true,
42
+ "registry": "https://registry.npmjs.org"
43
+ },
44
+ "scripts": {
45
+ "build": "tsup",
46
+ "dev": "tsup --watch",
47
+ "typecheck": "tsc --noEmit -p tsconfig.typecheck.json",
48
+ "lint": "eslint .",
49
+ "format": "prettier --write .",
50
+ "format:check": "prettier --check .",
51
+ "test": "vitest run --exclude tests/packaging",
52
+ "test:packaging": "vitest run tests/packaging",
53
+ "test:coverage": "vitest run --coverage --exclude tests/packaging",
54
+ "lint:jsdoc": "node --experimental-strip-types scripts/validate-export-jsdoc.ts",
55
+ "changeset": "changeset",
56
+ "version-packages": "changeset version",
57
+ "prepack": "yarn build",
58
+ "debugging": "tsx ./scripts/sdk-instance.ts",
59
+ "prepare": "husky"
60
+ },
61
+ "keywords": [
62
+ "olympex",
63
+ "sdk",
64
+ "graphql",
65
+ "web3",
66
+ "typescript"
67
+ ],
68
+ "devDependencies": {
69
+ "@changesets/cli": "2.31.0",
70
+ "@eslint/js": "10.0.1",
71
+ "@types/node": "22.7.5",
72
+ "@vitest/coverage-v8": "4.1.9",
73
+ "dotenv": "17.4.2",
74
+ "eslint": "10.4.1",
75
+ "eslint-plugin-jsdoc": "63.0.4",
76
+ "husky": "9.1.7",
77
+ "lint-staged": "17.0.7",
78
+ "prettier": "3.8.3",
79
+ "tsup": "8.5.1",
80
+ "tsx": "4.22.4",
81
+ "typescript": "6.0.3",
82
+ "typescript-eslint": "8.60.0",
83
+ "vitest": "4.1.9"
84
+ },
85
+ "dependencies": {
86
+ "ethers": "6.16.0"
87
+ }
88
+ }