@n1xyz/nord-ts 0.0.19 → 0.0.20
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/api/client.d.ts +14 -0
- package/dist/api/client.js +45 -0
- package/dist/bridge/client.d.ts +151 -0
- package/dist/bridge/client.js +434 -0
- package/dist/bridge/const.d.ts +23 -0
- package/dist/bridge/const.js +47 -0
- package/dist/bridge/index.d.ts +4 -0
- package/dist/bridge/index.js +23 -0
- package/dist/bridge/types.d.ts +120 -0
- package/dist/bridge/types.js +18 -0
- package/dist/bridge/utils.d.ts +64 -0
- package/dist/bridge/utils.js +131 -0
- package/dist/const.d.ts +8 -0
- package/dist/const.js +30 -0
- package/dist/gen/common.d.ts +68 -0
- package/dist/gen/common.js +215 -0
- package/dist/gen/nord.d.ts +882 -0
- package/dist/gen/nord.js +6520 -0
- package/dist/gen/openapi.d.ts +2244 -0
- package/dist/gen/openapi.js +6 -0
- package/dist/idl/bridge.d.ts +569 -0
- package/dist/idl/bridge.js +8 -0
- package/dist/idl/bridge.json +1506 -0
- package/dist/idl/index.d.ts +607 -0
- package/dist/idl/index.js +8 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +21 -0
- package/dist/nord/api/actions.d.ts +135 -0
- package/dist/nord/api/actions.js +313 -0
- package/dist/nord/api/core.d.ts +16 -0
- package/dist/nord/api/core.js +93 -0
- package/dist/nord/api/market.d.ts +36 -0
- package/dist/nord/api/market.js +96 -0
- package/dist/nord/api/metrics.d.ts +67 -0
- package/dist/nord/api/metrics.js +229 -0
- package/dist/nord/api/queries.d.ts +46 -0
- package/dist/nord/api/queries.js +109 -0
- package/dist/nord/client/Nord.d.ts +282 -0
- package/dist/nord/client/Nord.js +531 -0
- package/dist/nord/client/NordUser.d.ts +340 -0
- package/dist/nord/client/NordUser.js +652 -0
- package/dist/nord/index.d.ts +7 -0
- package/dist/nord/index.js +31 -0
- package/dist/nord/models/Subscriber.d.ts +37 -0
- package/dist/nord/models/Subscriber.js +25 -0
- package/dist/nord/utils/NordError.d.ts +35 -0
- package/dist/nord/utils/NordError.js +49 -0
- package/dist/types.d.ts +260 -0
- package/dist/types.js +103 -0
- package/dist/utils.d.ts +98 -0
- package/dist/utils.js +237 -0
- package/dist/websocket/NordWebSocketClient.d.ts +68 -0
- package/dist/websocket/NordWebSocketClient.js +343 -0
- package/dist/websocket/events.d.ts +19 -0
- package/dist/websocket/events.js +2 -0
- package/dist/websocket/index.d.ts +2 -0
- package/dist/websocket/index.js +5 -0
- package/package.json +7 -1
- package/src/gen/.gitkeep +0 -0
- package/src/gen/nord.ts +7593 -0
- package/src/gen/openapi.ts +2245 -0
- package/.claude/settings.local.json +0 -11
- package/.local/qa.ts +0 -77
- package/.local/test-atomic.ts +0 -112
- package/.prettierignore +0 -2
- package/check.sh +0 -4
- package/default.nix +0 -47
- package/eslint.config.mjs +0 -66
- package/tests/utils.spec.ts +0 -121
- package/tsconfig.eslint.json +0 -12
- package/tsconfig.json +0 -24
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
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; } });
|
|
@@ -0,0 +1,120 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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 = {}));
|
|
@@ -0,0 +1,64 @@
|
|
|
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;
|
|
@@ -0,0 +1,131 @@
|
|
|
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/const.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { TokenInfo } from "./types";
|
|
2
|
+
export declare const DEBUG_KEYS: string[];
|
|
3
|
+
export declare const DEV_URL = "http://localhost";
|
|
4
|
+
export declare const WEBSERVER_DEV_URL: string;
|
|
5
|
+
export declare const DEV_TOKEN_INFOS: TokenInfo[];
|
|
6
|
+
export declare const DEFAULT_FUNDING_AMOUNTS: {
|
|
7
|
+
[key: string]: [string, number];
|
|
8
|
+
};
|
package/dist/const.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_FUNDING_AMOUNTS = exports.DEV_TOKEN_INFOS = exports.WEBSERVER_DEV_URL = exports.DEV_URL = exports.DEBUG_KEYS = void 0;
|
|
4
|
+
const WEBSERVER_PORT = "80";
|
|
5
|
+
exports.DEBUG_KEYS = [
|
|
6
|
+
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
|
|
7
|
+
"0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d",
|
|
8
|
+
"0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a",
|
|
9
|
+
"0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6",
|
|
10
|
+
"0x47e179ec197488593b187f80a00eb0da91f1b9d0b13f8733639f19c30a34926a",
|
|
11
|
+
"0x8b3a350cf5c34c9194ca85829a2df0ec3153be0318b5e2d3348e872092edffba",
|
|
12
|
+
"0x92db14e403b83dfe3df233f83dfa3a0d7096f21ca9b0d6d6b8d88b2b4ec1564e",
|
|
13
|
+
"0x4bbbf85ce3377467afe5d46f804f221813b2bb87f24d81f60f1fcdbf7cbf4356",
|
|
14
|
+
"0xdbda1821b80551c9d65939329250298aa3472ba22feea921c0cf5d620ea67b97",
|
|
15
|
+
"0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6",
|
|
16
|
+
];
|
|
17
|
+
exports.DEV_URL = "http://localhost";
|
|
18
|
+
exports.WEBSERVER_DEV_URL = exports.DEV_URL + ":" + WEBSERVER_PORT;
|
|
19
|
+
exports.DEV_TOKEN_INFOS = [
|
|
20
|
+
{
|
|
21
|
+
address: "0x9a9f2ccfde556a7e9ff0848998aa4a0cfd8863ae",
|
|
22
|
+
precision: 6,
|
|
23
|
+
tokenId: 0,
|
|
24
|
+
name: "usdc",
|
|
25
|
+
},
|
|
26
|
+
];
|
|
27
|
+
exports.DEFAULT_FUNDING_AMOUNTS = {
|
|
28
|
+
SOL: ["0.2", 0],
|
|
29
|
+
"0x9a9f2ccfde556a7e9ff0848998aa4a0cfd8863ae": ["10000", 6],
|
|
30
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
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 {};
|