@huma-finance/permissionless-sdk 1.0.5-beta.20250910221648.867356c → 1.0.5
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.
- package/package.json +2 -3
- package/examples/addRedemptionRequest.ts +0 -43
- package/examples/deposit.ts +0 -35
- package/examples/tokenPrice.ts +0 -31
package/package.json
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@huma-finance/permissionless-sdk",
|
|
3
|
-
"version": "1.0.5
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "Huma Finance Permissionless SDK for Solana",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist/**/*",
|
|
9
|
-
"README.md"
|
|
10
|
-
"examples/**/*"
|
|
9
|
+
"README.md"
|
|
11
10
|
],
|
|
12
11
|
"publishConfig": {
|
|
13
12
|
"access": "public"
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { Connection } from "@solana/web3.js";
|
|
2
|
-
import { getModeTokenATA, PermissionlessClient, SolanaChainEnum } from "../src";
|
|
3
|
-
import { DepositMode } from "../src/types/metadata";
|
|
4
|
-
import { PublicKey } from "@solana/web3.js";
|
|
5
|
-
import { BN } from "@coral-xyz/anchor";
|
|
6
|
-
import dotenv from "dotenv";
|
|
7
|
-
import { Keypair } from "@solana/web3.js";
|
|
8
|
-
|
|
9
|
-
dotenv.config();
|
|
10
|
-
|
|
11
|
-
async function main() {
|
|
12
|
-
const connection = new Connection(process.env.RPC_URL!);
|
|
13
|
-
const client = new PermissionlessClient(connection, SolanaChainEnum.MAINNET);
|
|
14
|
-
|
|
15
|
-
const key = Keypair.fromSecretKey(
|
|
16
|
-
new Uint8Array(JSON.parse(process.env.PRIVATE_KEY!))
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
const tokenATA = await client.getModeTokenATA(
|
|
20
|
-
key.publicKey,
|
|
21
|
-
DepositMode.CLASSIC
|
|
22
|
-
);
|
|
23
|
-
const balance = await connection.getTokenAccountBalance(tokenATA);
|
|
24
|
-
console.log("Submitting redemption for shares: ", balance.value.amount);
|
|
25
|
-
|
|
26
|
-
// Note: 1 USDC is the minimum deposit amount
|
|
27
|
-
const tx = await client.buildWithdrawTx(
|
|
28
|
-
key.publicKey,
|
|
29
|
-
new BN(balance.value.amount),
|
|
30
|
-
DepositMode.CLASSIC
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
console.log(tx);
|
|
34
|
-
|
|
35
|
-
tx.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
|
|
36
|
-
await tx.sign(key);
|
|
37
|
-
|
|
38
|
-
const txHash = await connection.sendRawTransaction(tx.serialize());
|
|
39
|
-
|
|
40
|
-
console.log(txHash);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
main();
|
package/examples/deposit.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { Connection } from "@solana/web3.js";
|
|
2
|
-
import { PermissionlessClient, SolanaChainEnum } from "../src";
|
|
3
|
-
import { DepositMode } from "../src/types/metadata";
|
|
4
|
-
import { PublicKey } from "@solana/web3.js";
|
|
5
|
-
import { BN } from "@coral-xyz/anchor";
|
|
6
|
-
import dotenv from "dotenv";
|
|
7
|
-
import { Keypair } from "@solana/web3.js";
|
|
8
|
-
|
|
9
|
-
dotenv.config();
|
|
10
|
-
|
|
11
|
-
async function main() {
|
|
12
|
-
const connection = new Connection(process.env.RPC_URL!);
|
|
13
|
-
const client = new PermissionlessClient(connection, SolanaChainEnum.MAINNET);
|
|
14
|
-
|
|
15
|
-
const key = Keypair.fromSecretKey(
|
|
16
|
-
new Uint8Array(JSON.parse(process.env.PRIVATE_KEY!))
|
|
17
|
-
);
|
|
18
|
-
// Note: 1 USDC is the minimum deposit amount
|
|
19
|
-
const tx = await client.buildDepositTx(
|
|
20
|
-
key.publicKey,
|
|
21
|
-
new BN(1000000),
|
|
22
|
-
DepositMode.CLASSIC
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
console.log(tx);
|
|
26
|
-
|
|
27
|
-
tx.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
|
|
28
|
-
await tx.sign(key);
|
|
29
|
-
|
|
30
|
-
const txHash = await connection.sendRawTransaction(tx.serialize());
|
|
31
|
-
|
|
32
|
-
console.log(txHash);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
main();
|
package/examples/tokenPrice.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Connection } from "@solana/web3.js";
|
|
2
|
-
import { PermissionlessClient, SolanaChainEnum } from "../src";
|
|
3
|
-
import { DepositMode } from "../src/types/metadata";
|
|
4
|
-
import dotenv from "dotenv";
|
|
5
|
-
import { BN } from "@coral-xyz/anchor";
|
|
6
|
-
|
|
7
|
-
dotenv.config();
|
|
8
|
-
|
|
9
|
-
function formatPrice(price: BN, decimals: BN): string {
|
|
10
|
-
// Show full decimal value (e.g. 1.234567)
|
|
11
|
-
const integerPart = price.div(decimals).toString();
|
|
12
|
-
const fractionalPart = price
|
|
13
|
-
.mod(decimals)
|
|
14
|
-
.toString()
|
|
15
|
-
.padStart(decimals.toString().length - 1, "0");
|
|
16
|
-
// Remove trailing zeros from fractional part, but keep at least one zero if all are zero
|
|
17
|
-
const trimmedFractional = fractionalPart.replace(/0+$/, "") || "0";
|
|
18
|
-
return `${integerPart}.${trimmedFractional}`;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async function main() {
|
|
22
|
-
const connection = new Connection(process.env.RPC_URL!);
|
|
23
|
-
const client = new PermissionlessClient(connection, SolanaChainEnum.MAINNET);
|
|
24
|
-
|
|
25
|
-
const price = await client.getModeTokenPrice(DepositMode.CLASSIC);
|
|
26
|
-
|
|
27
|
-
const decimalsFactor = new BN(10).pow(new BN(6));
|
|
28
|
-
console.log(formatPrice(price, decimalsFactor));
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
main();
|