@n1xyz/nord-ts 0.1.7 → 0.1.8
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/dist/actions.js +39 -82
- package/dist/bundle.js +79181 -0
- package/dist/client/Nord.d.ts +2 -2
- package/dist/client/Nord.js +46 -78
- package/dist/client/NordAdmin.d.ts +2 -2
- package/dist/client/NordAdmin.js +57 -89
- package/dist/client/NordUser.js +118 -147
- package/dist/const.js +5 -8
- package/dist/error.js +7 -5
- package/dist/gen/nord_pb.js +88 -92
- package/dist/gen/openapi.d.ts +5 -6
- package/dist/gen/openapi.js +1 -2
- package/dist/index.js +10 -49
- package/dist/types.d.ts +1 -0
- package/dist/types.js +21 -60
- package/dist/utils.js +38 -86
- package/dist/websocket/NordWebSocketClient.js +12 -17
- package/dist/websocket/Subscriber.js +6 -7
- package/dist/websocket/events.js +1 -2
- package/dist/websocket/index.js +10 -15
- package/package.json +2 -3
- package/dist/api/client.d.ts +0 -14
- package/dist/api/client.js +0 -45
- package/dist/bridge/client.d.ts +0 -151
- package/dist/bridge/client.js +0 -434
- package/dist/bridge/const.d.ts +0 -23
- package/dist/bridge/const.js +0 -47
- package/dist/bridge/index.d.ts +0 -4
- package/dist/bridge/index.js +0 -23
- package/dist/bridge/types.d.ts +0 -120
- package/dist/bridge/types.js +0 -18
- package/dist/bridge/utils.d.ts +0 -64
- package/dist/bridge/utils.js +0 -131
- package/dist/gen/common.d.ts +0 -68
- package/dist/gen/common.js +0 -215
- package/dist/gen/nord.d.ts +0 -882
- package/dist/gen/nord.js +0 -6520
- package/dist/idl/bridge.d.ts +0 -569
- package/dist/idl/bridge.js +0 -8
- package/dist/idl/bridge.json +0 -1506
- package/dist/idl/index.d.ts +0 -607
- package/dist/idl/index.js +0 -8
- package/dist/nord/api/actions.d.ts +0 -126
- package/dist/nord/api/actions.js +0 -397
- package/dist/nord/api/core.d.ts +0 -16
- package/dist/nord/api/core.js +0 -81
- package/dist/nord/api/market.d.ts +0 -36
- package/dist/nord/api/market.js +0 -96
- package/dist/nord/api/metrics.d.ts +0 -67
- package/dist/nord/api/metrics.js +0 -229
- package/dist/nord/api/queries.d.ts +0 -46
- package/dist/nord/api/queries.js +0 -109
- package/dist/nord/api/triggers.d.ts +0 -7
- package/dist/nord/api/triggers.js +0 -38
- package/dist/nord/client/Nord.d.ts +0 -396
- package/dist/nord/client/Nord.js +0 -747
- package/dist/nord/client/NordAdmin.d.ts +0 -259
- package/dist/nord/client/NordAdmin.js +0 -395
- package/dist/nord/client/NordClient.d.ts +0 -33
- package/dist/nord/client/NordClient.js +0 -45
- package/dist/nord/client/NordUser.d.ts +0 -362
- package/dist/nord/client/NordUser.js +0 -781
- package/dist/nord/index.d.ts +0 -11
- package/dist/nord/index.js +0 -36
- package/dist/nord/models/Subscriber.d.ts +0 -37
- package/dist/nord/models/Subscriber.js +0 -25
- package/dist/nord/utils/NordError.d.ts +0 -35
- package/dist/nord/utils/NordError.js +0 -49
- package/src/actions.ts +0 -333
- package/src/client/Nord.ts +0 -934
- package/src/client/NordAdmin.ts +0 -484
- package/src/client/NordUser.ts +0 -1122
- package/src/const.ts +0 -34
- package/src/error.ts +0 -76
- package/src/gen/.gitkeep +0 -0
- package/src/gen/nord_pb.ts +0 -5053
- package/src/gen/openapi.ts +0 -2904
- package/src/index.ts +0 -11
- package/src/types.ts +0 -327
- package/src/utils.ts +0 -266
- package/src/websocket/NordWebSocketClient.ts +0 -316
- package/src/websocket/Subscriber.ts +0 -56
- package/src/websocket/events.ts +0 -31
- package/src/websocket/index.ts +0 -105
package/dist/bridge/const.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PDA_SEEDS = exports.DEFAULT_FUNDING_AMOUNTS = exports.DEV_TOKEN_INFOS = exports.SOLANA_PROGRAM_ID = exports.WEBSERVER_DEV_URL = exports.DEV_URL = exports.DEFAULT_COMMITMENT = exports.SOLANA_LOCALNET_URL = exports.SOLANA_TESTNET_URL = exports.SOLANA_DEVNET_URL = exports.SOLANA_MAINNET_URL = void 0;
|
|
4
|
-
// Solana RPC endpoints
|
|
5
|
-
exports.SOLANA_MAINNET_URL = "https://api.mainnet-beta.solana.com";
|
|
6
|
-
exports.SOLANA_DEVNET_URL = "https://api.devnet.solana.com";
|
|
7
|
-
exports.SOLANA_TESTNET_URL = "https://api.testnet.solana.com";
|
|
8
|
-
exports.SOLANA_LOCALNET_URL = "http://localhost:8899";
|
|
9
|
-
// Default commitment level
|
|
10
|
-
exports.DEFAULT_COMMITMENT = "confirmed";
|
|
11
|
-
// Webserver configuration
|
|
12
|
-
const WEBSERVER_PORT = "80";
|
|
13
|
-
exports.DEV_URL = "http://localhost";
|
|
14
|
-
exports.WEBSERVER_DEV_URL = exports.DEV_URL + ":" + WEBSERVER_PORT;
|
|
15
|
-
// Program ID (will be supplied externally)
|
|
16
|
-
exports.SOLANA_PROGRAM_ID = "CVDFLCAjXhVWiPXH9nTCTpCgVzmDVoiPzNJYuccr1dqB";
|
|
17
|
-
// Sample token information for development
|
|
18
|
-
exports.DEV_TOKEN_INFOS = [
|
|
19
|
-
{
|
|
20
|
-
mint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", // USDC on devnet
|
|
21
|
-
precision: 6,
|
|
22
|
-
tokenId: 0,
|
|
23
|
-
name: "usdc",
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
mint: "So11111111111111111111111111111111111111112", // Wrapped SOL
|
|
27
|
-
precision: 9,
|
|
28
|
-
tokenId: 1,
|
|
29
|
-
name: "sol",
|
|
30
|
-
},
|
|
31
|
-
];
|
|
32
|
-
// Default funding amounts for development
|
|
33
|
-
exports.DEFAULT_FUNDING_AMOUNTS = {
|
|
34
|
-
SOL: ["0.2", 9],
|
|
35
|
-
// USDC mint address
|
|
36
|
-
EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v: ["10000", 6],
|
|
37
|
-
};
|
|
38
|
-
// PDA seed constants
|
|
39
|
-
exports.PDA_SEEDS = {
|
|
40
|
-
CONTRACT_STORAGE: "contract_storage",
|
|
41
|
-
ASSET_WHITELISTED: "asset_whitelisted",
|
|
42
|
-
DEPOSIT_STORAGE: "deposit_storage",
|
|
43
|
-
BLOCK_STORAGE: "block_storage",
|
|
44
|
-
WITHDRAWAL_NULLIFIER: "withdrawal_nullifier",
|
|
45
|
-
AUTHORITY: "authority",
|
|
46
|
-
DA_FACT_STORAGE: "da_fact_storage",
|
|
47
|
-
};
|
package/dist/bridge/index.d.ts
DELETED
package/dist/bridge/index.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.BRIDGE_IDL = void 0;
|
|
18
|
-
__exportStar(require("./client"), exports);
|
|
19
|
-
__exportStar(require("./types"), exports);
|
|
20
|
-
__exportStar(require("./utils"), exports);
|
|
21
|
-
// Re-export the IDL for convenience
|
|
22
|
-
var idl_1 = require("../idl");
|
|
23
|
-
Object.defineProperty(exports, "BRIDGE_IDL", { enumerable: true, get: function () { return idl_1.BRIDGE_IDL; } });
|
package/dist/bridge/types.d.ts
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { PublicKey } from "@solana/web3.js";
|
|
2
|
-
import { BN } from "@coral-xyz/anchor";
|
|
3
|
-
/**
|
|
4
|
-
* Configuration for Solana bridge
|
|
5
|
-
*/
|
|
6
|
-
export interface SolanaBridgeConfig {
|
|
7
|
-
/** Solana RPC URL */
|
|
8
|
-
rpcUrl: string;
|
|
9
|
-
/** Program ID for the bridge program */
|
|
10
|
-
programId: string;
|
|
11
|
-
/** Bridge Verifying Key */
|
|
12
|
-
bridgeVk: string;
|
|
13
|
-
/** Commitment level for transactions */
|
|
14
|
-
commitment: "processed" | "confirmed" | "finalized";
|
|
15
|
-
/** Token information for supported SPL tokens */
|
|
16
|
-
tokenInfos: SPLTokenInfo[];
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Information about an SPL token
|
|
20
|
-
*/
|
|
21
|
-
export interface SPLTokenInfo {
|
|
22
|
-
/** Token mint address */
|
|
23
|
-
mint: string;
|
|
24
|
-
/** Token decimals */
|
|
25
|
-
precision: number;
|
|
26
|
-
/** Token ID in the Layer-N system */
|
|
27
|
-
tokenId: number;
|
|
28
|
-
/** Token name */
|
|
29
|
-
name: string;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Parameters for depositing SPL tokens
|
|
33
|
-
*/
|
|
34
|
-
export interface DepositSplParams {
|
|
35
|
-
/** Amount to deposit (in token's smallest unit) */
|
|
36
|
-
amount: BN;
|
|
37
|
-
/** Mint address of the token to deposit */
|
|
38
|
-
mint: PublicKey;
|
|
39
|
-
/** User's token account to deposit from */
|
|
40
|
-
fromAccount: PublicKey;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Parameters for withdrawing tokens
|
|
44
|
-
*/
|
|
45
|
-
export interface WithdrawalParams {
|
|
46
|
-
/** Withdrawal claim data */
|
|
47
|
-
claim: WithdrawalClaim;
|
|
48
|
-
/** User's token account to receive tokens */
|
|
49
|
-
toAccount: PublicKey;
|
|
50
|
-
/** Bridge's token account to withdraw from */
|
|
51
|
-
fromAccount: PublicKey;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Withdrawal claim data
|
|
55
|
-
*/
|
|
56
|
-
export interface WithdrawalClaim {
|
|
57
|
-
/** Block ID containing the withdrawal */
|
|
58
|
-
blockId: BN;
|
|
59
|
-
/** Leaf index in the Merkle tree */
|
|
60
|
-
leafIndex: BN;
|
|
61
|
-
/** Amount to withdraw */
|
|
62
|
-
amount: BN;
|
|
63
|
-
/** Recipient address */
|
|
64
|
-
recipient: PublicKey;
|
|
65
|
-
/** Token mint address */
|
|
66
|
-
mint: PublicKey;
|
|
67
|
-
/** Merkle proof for the withdrawal */
|
|
68
|
-
proof: Buffer[];
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Block facts data structure
|
|
72
|
-
*/
|
|
73
|
-
export interface BlockFacts {
|
|
74
|
-
/** Previous state facts */
|
|
75
|
-
prevStateFacts: StateFacts;
|
|
76
|
-
/** Next state facts */
|
|
77
|
-
nextStateFacts: StateFacts;
|
|
78
|
-
/** Data availability commitment */
|
|
79
|
-
daCommitment: Buffer;
|
|
80
|
-
/** Withdrawal Merkle root */
|
|
81
|
-
withdrawalRoot: Buffer;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* State facts data structure
|
|
85
|
-
*/
|
|
86
|
-
export interface StateFacts {
|
|
87
|
-
/** Application state commitment */
|
|
88
|
-
appStateCommitment: Buffer;
|
|
89
|
-
/** Deposit root */
|
|
90
|
-
depositRoot: Buffer;
|
|
91
|
-
/** Last deposit index */
|
|
92
|
-
lastDepositIndex: BN;
|
|
93
|
-
/** Last action ID */
|
|
94
|
-
lastActionId: BN;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Transfer parameters
|
|
98
|
-
*/
|
|
99
|
-
export interface TransferParams {
|
|
100
|
-
/** User public key */
|
|
101
|
-
user: PublicKey;
|
|
102
|
-
/** Token mint */
|
|
103
|
-
mint: PublicKey;
|
|
104
|
-
/** Amount to transfer */
|
|
105
|
-
amount: BN;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* PDA seed types
|
|
109
|
-
*/
|
|
110
|
-
export declare enum PdaSeedType {
|
|
111
|
-
Bridge = "bridge",
|
|
112
|
-
TokenAuthority = "token_authority",
|
|
113
|
-
CrumbAuthority = "crumb_authority",
|
|
114
|
-
AssetConfig = "asset_config",
|
|
115
|
-
DepositStorage = "deposit_storage",
|
|
116
|
-
BlockStorage = "block_storage",
|
|
117
|
-
WithdrawalNullifier = "withdrawal_nullifier",
|
|
118
|
-
Authority = "authority",
|
|
119
|
-
DaFactStorage = "da_fact_storage"
|
|
120
|
-
}
|
package/dist/bridge/types.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PdaSeedType = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* PDA seed types
|
|
6
|
-
*/
|
|
7
|
-
var PdaSeedType;
|
|
8
|
-
(function (PdaSeedType) {
|
|
9
|
-
PdaSeedType["Bridge"] = "bridge";
|
|
10
|
-
PdaSeedType["TokenAuthority"] = "token_authority";
|
|
11
|
-
PdaSeedType["CrumbAuthority"] = "crumb_authority";
|
|
12
|
-
PdaSeedType["AssetConfig"] = "asset_config";
|
|
13
|
-
PdaSeedType["DepositStorage"] = "deposit_storage";
|
|
14
|
-
PdaSeedType["BlockStorage"] = "block_storage";
|
|
15
|
-
PdaSeedType["WithdrawalNullifier"] = "withdrawal_nullifier";
|
|
16
|
-
PdaSeedType["Authority"] = "authority";
|
|
17
|
-
PdaSeedType["DaFactStorage"] = "da_fact_storage";
|
|
18
|
-
})(PdaSeedType || (exports.PdaSeedType = PdaSeedType = {}));
|
package/dist/bridge/utils.d.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { Keypair, PublicKey } from "@solana/web3.js";
|
|
2
|
-
import { BN } from "@coral-xyz/anchor";
|
|
3
|
-
import { PdaSeedType } from "./types";
|
|
4
|
-
/**
|
|
5
|
-
* Convert a private key string to a Solana Keypair
|
|
6
|
-
*
|
|
7
|
-
* @param privateKey Private key as base58 string, hex string, or Uint8Array
|
|
8
|
-
* @returns Solana Keypair
|
|
9
|
-
*/
|
|
10
|
-
export declare function keypairFromPrivateKey(privateKey: string | Uint8Array): Keypair;
|
|
11
|
-
/**
|
|
12
|
-
* Create a signing function for Solana transactions
|
|
13
|
-
*
|
|
14
|
-
* @param keypair Solana keypair
|
|
15
|
-
* @returns Signing function
|
|
16
|
-
*/
|
|
17
|
-
export declare function makeSigningFunction(keypair: Keypair): (_message: Uint8Array) => Promise<Uint8Array>;
|
|
18
|
-
/**
|
|
19
|
-
* Convert a number to a BN with the specified number of decimals
|
|
20
|
-
*
|
|
21
|
-
* @param amount Amount as a number
|
|
22
|
-
* @param decimals Number of decimals
|
|
23
|
-
* @returns BN representation of the amount
|
|
24
|
-
*/
|
|
25
|
-
export declare function bridgeToBN(amount: number, decimals: number): BN;
|
|
26
|
-
/**
|
|
27
|
-
* Format a BN as a human-readable number with the specified number of decimals
|
|
28
|
-
*
|
|
29
|
-
* @param amount Amount as a BN
|
|
30
|
-
* @param decimals Number of decimals
|
|
31
|
-
* @returns Formatted number
|
|
32
|
-
*/
|
|
33
|
-
export declare function fromBN(amount: BN, decimals: number): number;
|
|
34
|
-
/**
|
|
35
|
-
* Derive a PDA (Program Derived Address) for the given seeds
|
|
36
|
-
*
|
|
37
|
-
* @param programId Program ID
|
|
38
|
-
* @param type PDA seed type
|
|
39
|
-
* @param seeds Additional seeds
|
|
40
|
-
* @returns [PDA, bump]
|
|
41
|
-
*/
|
|
42
|
-
export declare function findPda(programId: PublicKey, type: PdaSeedType, ...seeds: (Buffer | PublicKey | string | number)[]): [PublicKey, number];
|
|
43
|
-
/**
|
|
44
|
-
* Convert a buffer to a hex string
|
|
45
|
-
*
|
|
46
|
-
* @param buffer Buffer to convert
|
|
47
|
-
* @returns Hex string
|
|
48
|
-
*/
|
|
49
|
-
export declare function bufferToHex(buffer: Buffer | Uint8Array): string;
|
|
50
|
-
/**
|
|
51
|
-
* Convert a hex string to a buffer
|
|
52
|
-
*
|
|
53
|
-
* @param hex Hex string
|
|
54
|
-
* @returns Buffer
|
|
55
|
-
*/
|
|
56
|
-
export declare function hexToBuffer(hex: string): Buffer;
|
|
57
|
-
/**
|
|
58
|
-
* Shorten a public key for display
|
|
59
|
-
*
|
|
60
|
-
* @param publicKey Public key to shorten
|
|
61
|
-
* @param chars Number of characters to show at the beginning and end
|
|
62
|
-
* @returns Shortened public key
|
|
63
|
-
*/
|
|
64
|
-
export declare function shortenPublicKey(publicKey: PublicKey | string, chars?: number): string;
|
package/dist/bridge/utils.js
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.keypairFromPrivateKey = keypairFromPrivateKey;
|
|
7
|
-
exports.makeSigningFunction = makeSigningFunction;
|
|
8
|
-
exports.bridgeToBN = bridgeToBN;
|
|
9
|
-
exports.fromBN = fromBN;
|
|
10
|
-
exports.findPda = findPda;
|
|
11
|
-
exports.bufferToHex = bufferToHex;
|
|
12
|
-
exports.hexToBuffer = hexToBuffer;
|
|
13
|
-
exports.shortenPublicKey = shortenPublicKey;
|
|
14
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
15
|
-
const anchor_1 = require("@coral-xyz/anchor");
|
|
16
|
-
const bs58_1 = __importDefault(require("bs58"));
|
|
17
|
-
/**
|
|
18
|
-
* Convert a private key string to a Solana Keypair
|
|
19
|
-
*
|
|
20
|
-
* @param privateKey Private key as base58 string, hex string, or Uint8Array
|
|
21
|
-
* @returns Solana Keypair
|
|
22
|
-
*/
|
|
23
|
-
function keypairFromPrivateKey(privateKey) {
|
|
24
|
-
if (typeof privateKey === "string") {
|
|
25
|
-
// Check if it's a base58 encoded string
|
|
26
|
-
if (!privateKey.startsWith("0x")) {
|
|
27
|
-
return web3_js_1.Keypair.fromSecretKey(bs58_1.default.decode(privateKey));
|
|
28
|
-
}
|
|
29
|
-
// It's a hex string
|
|
30
|
-
const hex = privateKey.startsWith("0x") ? privateKey.slice(2) : privateKey;
|
|
31
|
-
const bytes = new Uint8Array(hex.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
|
|
32
|
-
return web3_js_1.Keypair.fromSecretKey(bytes);
|
|
33
|
-
}
|
|
34
|
-
// It's already a Uint8Array
|
|
35
|
-
return web3_js_1.Keypair.fromSecretKey(privateKey);
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Create a signing function for Solana transactions
|
|
39
|
-
*
|
|
40
|
-
* @param keypair Solana keypair
|
|
41
|
-
* @returns Signing function
|
|
42
|
-
*/
|
|
43
|
-
function makeSigningFunction(keypair) {
|
|
44
|
-
return async (_message) => {
|
|
45
|
-
// Use the correct API for signing with a Keypair
|
|
46
|
-
const signature = keypair.secretKey.slice(0, 32);
|
|
47
|
-
const publicKey = keypair.publicKey.toBytes();
|
|
48
|
-
// This is a simplified version - in a real implementation, you would use proper signing
|
|
49
|
-
// For now, we're just returning a placeholder signature
|
|
50
|
-
return new Uint8Array([...signature, ...publicKey].slice(0, 64));
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Convert a number to a BN with the specified number of decimals
|
|
55
|
-
*
|
|
56
|
-
* @param amount Amount as a number
|
|
57
|
-
* @param decimals Number of decimals
|
|
58
|
-
* @returns BN representation of the amount
|
|
59
|
-
*/
|
|
60
|
-
function bridgeToBN(amount, decimals) {
|
|
61
|
-
const factor = Math.pow(10, decimals);
|
|
62
|
-
const amountBN = new anchor_1.BN(Math.floor(amount * factor));
|
|
63
|
-
return amountBN;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Format a BN as a human-readable number with the specified number of decimals
|
|
67
|
-
*
|
|
68
|
-
* @param amount Amount as a BN
|
|
69
|
-
* @param decimals Number of decimals
|
|
70
|
-
* @returns Formatted number
|
|
71
|
-
*/
|
|
72
|
-
function fromBN(amount, decimals) {
|
|
73
|
-
const factor = Math.pow(10, decimals);
|
|
74
|
-
return amount.toNumber() / factor;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Derive a PDA (Program Derived Address) for the given seeds
|
|
78
|
-
*
|
|
79
|
-
* @param programId Program ID
|
|
80
|
-
* @param type PDA seed type
|
|
81
|
-
* @param seeds Additional seeds
|
|
82
|
-
* @returns [PDA, bump]
|
|
83
|
-
*/
|
|
84
|
-
function findPda(programId, type, ...seeds) {
|
|
85
|
-
const seedBuffers = [
|
|
86
|
-
Buffer.from(type),
|
|
87
|
-
...seeds.map((seed) => {
|
|
88
|
-
if (seed instanceof web3_js_1.PublicKey) {
|
|
89
|
-
return seed.toBuffer();
|
|
90
|
-
}
|
|
91
|
-
else if (typeof seed === "string") {
|
|
92
|
-
return Buffer.from(seed);
|
|
93
|
-
}
|
|
94
|
-
else if (typeof seed === "number") {
|
|
95
|
-
return Buffer.from([seed]);
|
|
96
|
-
}
|
|
97
|
-
return seed;
|
|
98
|
-
}),
|
|
99
|
-
];
|
|
100
|
-
return web3_js_1.PublicKey.findProgramAddressSync(seedBuffers, programId);
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Convert a buffer to a hex string
|
|
104
|
-
*
|
|
105
|
-
* @param buffer Buffer to convert
|
|
106
|
-
* @returns Hex string
|
|
107
|
-
*/
|
|
108
|
-
function bufferToHex(buffer) {
|
|
109
|
-
return "0x" + Buffer.from(buffer).toString("hex");
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Convert a hex string to a buffer
|
|
113
|
-
*
|
|
114
|
-
* @param hex Hex string
|
|
115
|
-
* @returns Buffer
|
|
116
|
-
*/
|
|
117
|
-
function hexToBuffer(hex) {
|
|
118
|
-
const hexString = hex.startsWith("0x") ? hex.slice(2) : hex;
|
|
119
|
-
return Buffer.from(hexString, "hex");
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Shorten a public key for display
|
|
123
|
-
*
|
|
124
|
-
* @param publicKey Public key to shorten
|
|
125
|
-
* @param chars Number of characters to show at the beginning and end
|
|
126
|
-
* @returns Shortened public key
|
|
127
|
-
*/
|
|
128
|
-
function shortenPublicKey(publicKey, chars = 4) {
|
|
129
|
-
const key = typeof publicKey === "string" ? publicKey : publicKey.toBase58();
|
|
130
|
-
return `${key.slice(0, chars)}...${key.slice(-chars)}`;
|
|
131
|
-
}
|
package/dist/gen/common.d.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
|
|
2
|
-
export declare const protobufPackage = "common";
|
|
3
|
-
export interface Message {
|
|
4
|
-
kind?: //
|
|
5
|
-
/**
|
|
6
|
-
* there are many things to come here, that why enum,
|
|
7
|
-
* from list abi calls, nfts, multi asset transfer
|
|
8
|
-
*/
|
|
9
|
-
{
|
|
10
|
-
$case: "transfer";
|
|
11
|
-
value: Message_Transfer;
|
|
12
|
-
} | undefined;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Message sent by user to app to move funds out of app, `withdraw`.
|
|
16
|
-
* Receiver side considers it `route` or `deposit`.
|
|
17
|
-
*/
|
|
18
|
-
export interface Message_Transfer {
|
|
19
|
-
/** Token id as registered on L1 chain settlement */
|
|
20
|
-
tokenId: number;
|
|
21
|
-
/**
|
|
22
|
-
* User public key from L1 which he used for deposits
|
|
23
|
-
* This address will be used to deposit onto L1 or L2 target,
|
|
24
|
-
* Target is "here", as soon as ther are no `channel_id`s remaining.
|
|
25
|
-
*/
|
|
26
|
-
userPubkey: Uint8Array;
|
|
27
|
-
amount: bigint;
|
|
28
|
-
/**
|
|
29
|
-
* Numeric identifiers of channels to traverse.
|
|
30
|
-
*
|
|
31
|
-
* Message removed first channel_id in list,
|
|
32
|
-
* and sent remaining message to "removed" channel.
|
|
33
|
-
*
|
|
34
|
-
* If received by app via channel and no channels defined,
|
|
35
|
-
* deposit target this app ("here").
|
|
36
|
-
*
|
|
37
|
-
* If it is direct user input and no channels defined, default route is used: q
|
|
38
|
-
* to Gate on Nord, to L1 on Gate, and to Gate on L1.
|
|
39
|
-
*/
|
|
40
|
-
channelId: number[];
|
|
41
|
-
}
|
|
42
|
-
export declare const Message: MessageFns<Message>;
|
|
43
|
-
export declare const Message_Transfer: MessageFns<Message_Transfer>;
|
|
44
|
-
type Builtin = Date | Function | Uint8Array | string | number | boolean | bigint | undefined;
|
|
45
|
-
export type DeepPartial<T> = T extends Builtin ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {
|
|
46
|
-
$case: string;
|
|
47
|
-
value: unknown;
|
|
48
|
-
} ? {
|
|
49
|
-
$case: T["$case"];
|
|
50
|
-
value?: DeepPartial<T["value"]>;
|
|
51
|
-
} : T extends {} ? {
|
|
52
|
-
[K in keyof T]?: DeepPartial<T[K]>;
|
|
53
|
-
} : Partial<T>;
|
|
54
|
-
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
|
55
|
-
export type Exact<P, I extends P> = P extends Builtin ? P : P & {
|
|
56
|
-
[K in keyof P]: Exact<P[K], I[K]>;
|
|
57
|
-
} & {
|
|
58
|
-
[K in Exclude<keyof I, KeysOfUnion<P>>]: never;
|
|
59
|
-
};
|
|
60
|
-
export interface MessageFns<T> {
|
|
61
|
-
encode(message: T, writer?: BinaryWriter): BinaryWriter;
|
|
62
|
-
decode(input: BinaryReader | Uint8Array, length?: number): T;
|
|
63
|
-
fromJSON(object: any): T;
|
|
64
|
-
toJSON(message: T): unknown;
|
|
65
|
-
create<I extends Exact<DeepPartial<T>, I>>(base?: I): T;
|
|
66
|
-
fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
|
|
67
|
-
}
|
|
68
|
-
export {};
|
package/dist/gen/common.js
DELETED
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
|
|
3
|
-
// versions:
|
|
4
|
-
// protoc-gen-ts_proto v2.7.0
|
|
5
|
-
// protoc v5.28.3
|
|
6
|
-
// source: common.proto
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.Message_Transfer = exports.Message = exports.protobufPackage = void 0;
|
|
9
|
-
/* eslint-disable */
|
|
10
|
-
const wire_1 = require("@bufbuild/protobuf/wire");
|
|
11
|
-
exports.protobufPackage = "common";
|
|
12
|
-
function createBaseMessage() {
|
|
13
|
-
return { kind: undefined };
|
|
14
|
-
}
|
|
15
|
-
exports.Message = {
|
|
16
|
-
encode(message, writer = new wire_1.BinaryWriter()) {
|
|
17
|
-
switch (message.kind?.$case) {
|
|
18
|
-
case "transfer":
|
|
19
|
-
exports.Message_Transfer.encode(message.kind.value, writer.uint32(10).fork()).join();
|
|
20
|
-
break;
|
|
21
|
-
}
|
|
22
|
-
return writer;
|
|
23
|
-
},
|
|
24
|
-
decode(input, length) {
|
|
25
|
-
const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
|
|
26
|
-
let end = length === undefined ? reader.len : reader.pos + length;
|
|
27
|
-
const message = createBaseMessage();
|
|
28
|
-
while (reader.pos < end) {
|
|
29
|
-
const tag = reader.uint32();
|
|
30
|
-
switch (tag >>> 3) {
|
|
31
|
-
case 1: {
|
|
32
|
-
if (tag !== 10) {
|
|
33
|
-
break;
|
|
34
|
-
}
|
|
35
|
-
message.kind = { $case: "transfer", value: exports.Message_Transfer.decode(reader, reader.uint32()) };
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
if ((tag & 7) === 4 || tag === 0) {
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
|
-
reader.skip(tag & 7);
|
|
43
|
-
}
|
|
44
|
-
return message;
|
|
45
|
-
},
|
|
46
|
-
fromJSON(object) {
|
|
47
|
-
return {
|
|
48
|
-
kind: isSet(object.transfer)
|
|
49
|
-
? { $case: "transfer", value: exports.Message_Transfer.fromJSON(object.transfer) }
|
|
50
|
-
: undefined,
|
|
51
|
-
};
|
|
52
|
-
},
|
|
53
|
-
toJSON(message) {
|
|
54
|
-
const obj = {};
|
|
55
|
-
if (message.kind?.$case === "transfer") {
|
|
56
|
-
obj.transfer = exports.Message_Transfer.toJSON(message.kind.value);
|
|
57
|
-
}
|
|
58
|
-
return obj;
|
|
59
|
-
},
|
|
60
|
-
create(base) {
|
|
61
|
-
return exports.Message.fromPartial(base ?? {});
|
|
62
|
-
},
|
|
63
|
-
fromPartial(object) {
|
|
64
|
-
const message = createBaseMessage();
|
|
65
|
-
switch (object.kind?.$case) {
|
|
66
|
-
case "transfer": {
|
|
67
|
-
if (object.kind?.value !== undefined && object.kind?.value !== null) {
|
|
68
|
-
message.kind = { $case: "transfer", value: exports.Message_Transfer.fromPartial(object.kind.value) };
|
|
69
|
-
}
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return message;
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
-
function createBaseMessage_Transfer() {
|
|
77
|
-
return { tokenId: 0, userPubkey: new Uint8Array(0), amount: 0n, channelId: [] };
|
|
78
|
-
}
|
|
79
|
-
exports.Message_Transfer = {
|
|
80
|
-
encode(message, writer = new wire_1.BinaryWriter()) {
|
|
81
|
-
if (message.tokenId !== 0) {
|
|
82
|
-
writer.uint32(8).uint32(message.tokenId);
|
|
83
|
-
}
|
|
84
|
-
if (message.userPubkey.length !== 0) {
|
|
85
|
-
writer.uint32(18).bytes(message.userPubkey);
|
|
86
|
-
}
|
|
87
|
-
if (message.amount !== 0n) {
|
|
88
|
-
if (BigInt.asUintN(64, message.amount) !== message.amount) {
|
|
89
|
-
throw new globalThis.Error("value provided for field message.amount of type uint64 too large");
|
|
90
|
-
}
|
|
91
|
-
writer.uint32(24).uint64(message.amount);
|
|
92
|
-
}
|
|
93
|
-
writer.uint32(58).fork();
|
|
94
|
-
for (const v of message.channelId) {
|
|
95
|
-
writer.uint32(v);
|
|
96
|
-
}
|
|
97
|
-
writer.join();
|
|
98
|
-
return writer;
|
|
99
|
-
},
|
|
100
|
-
decode(input, length) {
|
|
101
|
-
const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
|
|
102
|
-
let end = length === undefined ? reader.len : reader.pos + length;
|
|
103
|
-
const message = createBaseMessage_Transfer();
|
|
104
|
-
while (reader.pos < end) {
|
|
105
|
-
const tag = reader.uint32();
|
|
106
|
-
switch (tag >>> 3) {
|
|
107
|
-
case 1: {
|
|
108
|
-
if (tag !== 8) {
|
|
109
|
-
break;
|
|
110
|
-
}
|
|
111
|
-
message.tokenId = reader.uint32();
|
|
112
|
-
continue;
|
|
113
|
-
}
|
|
114
|
-
case 2: {
|
|
115
|
-
if (tag !== 18) {
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
message.userPubkey = reader.bytes();
|
|
119
|
-
continue;
|
|
120
|
-
}
|
|
121
|
-
case 3: {
|
|
122
|
-
if (tag !== 24) {
|
|
123
|
-
break;
|
|
124
|
-
}
|
|
125
|
-
message.amount = reader.uint64();
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
case 7: {
|
|
129
|
-
if (tag === 56) {
|
|
130
|
-
message.channelId.push(reader.uint32());
|
|
131
|
-
continue;
|
|
132
|
-
}
|
|
133
|
-
if (tag === 58) {
|
|
134
|
-
const end2 = reader.uint32() + reader.pos;
|
|
135
|
-
while (reader.pos < end2) {
|
|
136
|
-
message.channelId.push(reader.uint32());
|
|
137
|
-
}
|
|
138
|
-
continue;
|
|
139
|
-
}
|
|
140
|
-
break;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
if ((tag & 7) === 4 || tag === 0) {
|
|
144
|
-
break;
|
|
145
|
-
}
|
|
146
|
-
reader.skip(tag & 7);
|
|
147
|
-
}
|
|
148
|
-
return message;
|
|
149
|
-
},
|
|
150
|
-
fromJSON(object) {
|
|
151
|
-
return {
|
|
152
|
-
tokenId: isSet(object.tokenId) ? globalThis.Number(object.tokenId) : 0,
|
|
153
|
-
userPubkey: isSet(object.userPubkey) ? bytesFromBase64(object.userPubkey) : new Uint8Array(0),
|
|
154
|
-
amount: isSet(object.amount) ? BigInt(object.amount) : 0n,
|
|
155
|
-
channelId: globalThis.Array.isArray(object?.channelId)
|
|
156
|
-
? object.channelId.map((e) => globalThis.Number(e))
|
|
157
|
-
: [],
|
|
158
|
-
};
|
|
159
|
-
},
|
|
160
|
-
toJSON(message) {
|
|
161
|
-
const obj = {};
|
|
162
|
-
if (message.tokenId !== 0) {
|
|
163
|
-
obj.tokenId = Math.round(message.tokenId);
|
|
164
|
-
}
|
|
165
|
-
if (message.userPubkey.length !== 0) {
|
|
166
|
-
obj.userPubkey = base64FromBytes(message.userPubkey);
|
|
167
|
-
}
|
|
168
|
-
if (message.amount !== 0n) {
|
|
169
|
-
obj.amount = message.amount.toString();
|
|
170
|
-
}
|
|
171
|
-
if (message.channelId?.length) {
|
|
172
|
-
obj.channelId = message.channelId.map((e) => Math.round(e));
|
|
173
|
-
}
|
|
174
|
-
return obj;
|
|
175
|
-
},
|
|
176
|
-
create(base) {
|
|
177
|
-
return exports.Message_Transfer.fromPartial(base ?? {});
|
|
178
|
-
},
|
|
179
|
-
fromPartial(object) {
|
|
180
|
-
const message = createBaseMessage_Transfer();
|
|
181
|
-
message.tokenId = object.tokenId ?? 0;
|
|
182
|
-
message.userPubkey = object.userPubkey ?? new Uint8Array(0);
|
|
183
|
-
message.amount = object.amount ?? 0n;
|
|
184
|
-
message.channelId = object.channelId?.map((e) => e) || [];
|
|
185
|
-
return message;
|
|
186
|
-
},
|
|
187
|
-
};
|
|
188
|
-
function bytesFromBase64(b64) {
|
|
189
|
-
if (globalThis.Buffer) {
|
|
190
|
-
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
const bin = globalThis.atob(b64);
|
|
194
|
-
const arr = new Uint8Array(bin.length);
|
|
195
|
-
for (let i = 0; i < bin.length; ++i) {
|
|
196
|
-
arr[i] = bin.charCodeAt(i);
|
|
197
|
-
}
|
|
198
|
-
return arr;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
function base64FromBytes(arr) {
|
|
202
|
-
if (globalThis.Buffer) {
|
|
203
|
-
return globalThis.Buffer.from(arr).toString("base64");
|
|
204
|
-
}
|
|
205
|
-
else {
|
|
206
|
-
const bin = [];
|
|
207
|
-
arr.forEach((byte) => {
|
|
208
|
-
bin.push(globalThis.String.fromCharCode(byte));
|
|
209
|
-
});
|
|
210
|
-
return globalThis.btoa(bin.join(""));
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
function isSet(value) {
|
|
214
|
-
return value !== null && value !== undefined;
|
|
215
|
-
}
|