Skip to content
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
39 changes: 39 additions & 0 deletions tools/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ version-bump = [
]

[dependencies]
regex = "1"
semver = { version = "1.0", optional = true }
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", optional = true }
Expand Down
42 changes: 40 additions & 2 deletions tools/src/bin/apigen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
//!
//! - [ ] Automate publication to package repositories: PyPI, crates.io, and NPM

use std::path::PathBuf;
use std::fs;
use std::path::{Path, PathBuf};
use std::process::{Command, exit};
use std::{env, fmt, io};

use regex::{Captures, Regex};
use tools::Lang;

// Import version bump functionality from library (only when feature is enabled)
Expand Down Expand Up @@ -133,7 +135,43 @@ fn generate(lang: Lang) -> Result<()> {
.args(["--generator-name", lang.generator()])
.args(["--output", lang.output()]),
"openapi-generator-cli",
)
)?;

if matches!(lang, Lang::TypeScript) {
postprocess_typescript_esm_imports(Path::new(lang.output()))?;
}

Ok(())
}

fn postprocess_typescript_esm_imports(dir: &Path) -> Result<()> {
let import_re = Regex::new(r#"(?m)(from\s+['"])(\./[^'".]+)(['"])"#)
.expect("valid import regex");
let export_re = Regex::new(r#"(?m)(export\s+\*\s+from\s+['"])(\./[^'".]+)(['"])"#)
.expect("valid export regex");

for entry in fs::read_dir(dir)? {
let entry = entry?;
let path = entry.path();

if path.extension().and_then(|ext| ext.to_str()) != Some("ts") {
continue;
}

let original = fs::read_to_string(&path)?;
let with_imports = import_re.replace_all(&original, |caps: &Captures<'_>| {
format!("{}{}.js{}", &caps[1], &caps[2], &caps[3])
});
let updated = export_re.replace_all(&with_imports, |caps: &Captures<'_>| {
format!("{}{}.js{}", &caps[1], &caps[2], &caps[3])
});

if updated != original {
fs::write(path, updated.as_bytes())?;
}
}

Ok(())
}

/// Returns the nearest ancestor of the current working directory containing a "resources" folder.
Expand Down
8 changes: 4 additions & 4 deletions ts/sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ import {
BluefinRequestSigner,
makeSigner,
} from "@bluefin-exchange/pro-sdk";
import { SuiClient, Ed25519Keypair } from "@firefly-exchange/library-sui";
import { hexToBytes } from "@noble/hashes/utils";
import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
import { hexToBytes } from "@noble/hashes/utils.js";

// Create wallet from private key
const wallet = Ed25519Keypair.fromSecretKey(
Expand All @@ -50,7 +51,7 @@ const signer = new BluefinRequestSigner(makeSigner(wallet, false));
const client = new BluefinProSdk(
signer,
"mainnet", // or "testnet" for staging, "devnet" for development
new SuiClient({ url: "https://fullnode.mainnet.sui.io:443" })
new SuiJsonRpcClient({ url: "https://fullnode.mainnet.sui.io:443", network: "mainnet" })
);

// Initialize the SDK (authenticates and loads exchange configuration)
Expand Down Expand Up @@ -252,4 +253,3 @@ The SDK supports three environments:
Each environment has different API endpoints configured automatically.

See [example.ts](./example.ts) for the complete example code.

12 changes: 7 additions & 5 deletions ts/sdk/docs/batch-claim-rewards-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import {
makeSigner,
BatchClaimParams
} from "@bluefin-exchange/pro-sdk";
import { SuiClient, Ed25519Keypair } from "@firefly-exchange/library-sui";
import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";

// Create wallet from private key or mnemonic
const wallet = Ed25519Keypair.fromSecretKey(hexToBytes("YOUR_PRIVATE_KEY"));
Expand All @@ -33,7 +34,7 @@ const signer = new BluefinRequestSigner(makeSigner(wallet, false));
const sdk = new BluefinProSdk(
signer,
"mainnet", // or "testnet" for staging
new SuiClient({ url: "https://fullnode.mainnet.sui.io:443" })
new SuiJsonRpcClient({ url: "https://fullnode.mainnet.sui.io:443", network: "mainnet" })
);

await sdk.initialize();
Expand Down Expand Up @@ -129,8 +130,9 @@ import {
makeSigner,
BatchClaimParams
} from "@bluefin-exchange/pro-sdk";
import { SuiClient, Ed25519Keypair } from "@firefly-exchange/library-sui";
import { hexToBytes } from "@noble/hashes/utils";
import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
import { hexToBytes } from "@noble/hashes/utils.js";

async function claimRewards() {
// 1. Setup
Expand All @@ -139,7 +141,7 @@ async function claimRewards() {
const sdk = new BluefinProSdk(
signer,
"mainnet",
new SuiClient({ url: "https://fullnode.mainnet.sui.io:443" })
new SuiJsonRpcClient({ url: "https://fullnode.mainnet.sui.io:443", network: "mainnet" })
);
await sdk.initialize();

Expand Down
11 changes: 6 additions & 5 deletions ts/sdk/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ import {
makeSigner,
GetAccountValueHistoryParamsInterval,
BatchClaimParams,
} from "./index";
} from "./index.js";

import { hexToBytes } from "@noble/hashes/utils";
import { SuiClient, Ed25519Keypair } from "@firefly-exchange/library-sui";
import { hexToBytes } from "@noble/hashes/utils.js";
import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";

// Configure logging
const logger = {
Expand Down Expand Up @@ -113,7 +114,7 @@ async function main() {
const client = new BluefinProSdk(
bfSigner,
"testnet",
new SuiClient({ url: "https://fullnode.testnet.sui.io:443" })
new SuiJsonRpcClient({ url: "https://fullnode.testnet.sui.io:443", network: "testnet" })
);
await client.initialize();

Expand All @@ -122,7 +123,7 @@ async function main() {
// const clientWithTimeOffset = new BluefinProSdk(
// bfSigner,
// "testnet",
// new SuiClient({ url: "https://fullnode.testnet.sui.io:443" }),
// new SuiJsonRpcClient({ url: "https://fullnode.testnet.sui.io:443", network: "testnet" }),
// { currentTimeMs: customTime }
// );
// await clientWithTimeOffset.initialize();
Expand Down
2 changes: 1 addition & 1 deletion ts/sdk/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./src/index";
export * from "./src/index.js";
1 change: 1 addition & 0 deletions ts/sdk/openapitools.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading