@warganetwork/sdk 0.0.0-stage → 1.4.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.
package/src/helpers.js ADDED
@@ -0,0 +1,124 @@
1
+ import { CONTRACTS, ABIS } from "./index.js";
2
+
3
+ /**
4
+ * High-level helper wrapper for MerchantEscrow.vy v2 (timeout, dispute, release, expiry refund).
5
+ * Accepts any ethers v6 Contract instance (or custom contract adapter) — zero hard dependencies!
6
+ */
7
+ export class WargaEscrow {
8
+ constructor(contract) {
9
+ if (!contract) {
10
+ throw new Error("Pass an initialized MerchantEscrow contract instance (e.g. new ethers.Contract(CONTRACTS.MerchantEscrow, ABIS.MerchantEscrow, signer)).");
11
+ }
12
+ this.contract = contract;
13
+ }
14
+
15
+ static create(ethersContractCtor, signerOrProvider, address = CONTRACTS.MerchantEscrow) {
16
+ return new WargaEscrow(new ethersContractCtor(address, ABIS.MerchantEscrow, signerOrProvider));
17
+ }
18
+
19
+ async lockOrder(orderId, merchant, amountWei) {
20
+ return this.contract.lock_order(orderId, merchant, amountWei);
21
+ }
22
+
23
+ async lockOrderWithTimeout(orderId, merchant, amountWei, timeoutSeconds) {
24
+ return this.contract.lock_order_with_timeout(orderId, merchant, amountWei, timeoutSeconds);
25
+ }
26
+
27
+ async openDispute(orderId, reason) {
28
+ return this.contract.open_dispute(orderId, reason);
29
+ }
30
+
31
+ async releaseEscrow(orderId) {
32
+ return this.contract.release_escrow(orderId);
33
+ }
34
+
35
+ async refundEscrow(orderId, reason) {
36
+ return this.contract.refund_escrow(orderId, reason);
37
+ }
38
+
39
+ async claimExpiredOrder(orderId) {
40
+ return this.contract.claim_expired_order(orderId);
41
+ }
42
+
43
+ async resolveDispute(orderId, releaseToMerchant, resolutionNote) {
44
+ return this.contract.resolve_dispute(orderId, releaseToMerchant, resolutionNote);
45
+ }
46
+
47
+ async getOrder(orderId) {
48
+ return this.contract.orders(orderId);
49
+ }
50
+ }
51
+
52
+ /**
53
+ * High-level helper wrapper for WargaSwapV3Pool.vy v2 (constant-product x*y=k AMM + slippage math).
54
+ */
55
+ export class WargaPool {
56
+ constructor(contract) {
57
+ if (!contract) {
58
+ throw new Error("Pass an initialized WargaSwapV3Pool contract instance.");
59
+ }
60
+ this.contract = contract;
61
+ }
62
+
63
+ static create(ethersContractCtor, signerOrProvider, address = CONTRACTS.WargaSwapV3Pool) {
64
+ return new WargaPool(new ethersContractCtor(address, ABIS.WargaSwapV3Pool, signerOrProvider));
65
+ }
66
+
67
+ static computeMinOut(quotedOutWei, slippageBps = 50) {
68
+ const q = BigInt(quotedOutWei);
69
+ if (slippageBps < 0 || slippageBps >= 10000) {
70
+ throw new Error(`Invalid slippageBps: ${slippageBps}`);
71
+ }
72
+ return (q * BigInt(10000 - slippageBps)) / 10000n;
73
+ }
74
+
75
+ async getReserves() {
76
+ return this.contract.get_reserves();
77
+ }
78
+
79
+ async quoteSwap(tokenIn, amountInWei, slippageBps = 50) {
80
+ const amountOut = await this.contract.get_amount_out(tokenIn, amountInWei);
81
+ return {
82
+ amountOut: BigInt(amountOut),
83
+ minAmountOut: WargaPool.computeMinOut(amountOut, slippageBps),
84
+ };
85
+ }
86
+
87
+ async swap(tokenIn, amountInWei, minAmountOutWei, recipient) {
88
+ return this.contract.swap(tokenIn, amountInWei, minAmountOutWei, recipient);
89
+ }
90
+ }
91
+
92
+ /**
93
+ * High-level helper wrapper for MerchantKYCBadgeNFT.vy v2 (ERC-5192 Soulbound e-KYC NFT).
94
+ */
95
+ export class WargaKycBadge {
96
+ constructor(contract) {
97
+ if (!contract) {
98
+ throw new Error("Pass an initialized MerchantKYCBadgeNFT contract instance.");
99
+ }
100
+ this.contract = contract;
101
+ }
102
+
103
+ static create(ethersContractCtor, signerOrProvider, address = CONTRACTS.MerchantKYCBadgeNFT) {
104
+ return new WargaKycBadge(new ethersContractCtor(address, ABIS.MerchantKYCBadgeNFT, signerOrProvider));
105
+ }
106
+
107
+ async verifyBadge(tokenId) {
108
+ const [isErc5192, isLocked, owner, uri] = await Promise.all([
109
+ this.contract.supportsInterface("0xb45a3c0e"),
110
+ this.contract.locked(tokenId),
111
+ this.contract.ownerOf(tokenId),
112
+ this.contract.tokenURI(tokenId),
113
+ ]);
114
+ return { isErc5192, isLocked, owner, uri };
115
+ }
116
+
117
+ async mintBadge(recipient, storeId, storeName, kycHash, metadataUri) {
118
+ return this.contract.mintBadge(recipient, storeId, storeName, kycHash, metadataUri);
119
+ }
120
+
121
+ async revokeBadge(tokenId) {
122
+ return this.contract.revokeBadge(tokenId);
123
+ }
124
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,150 @@
1
+ export interface WargaChainConfig {
2
+ readonly id: number;
3
+ readonly chainIdHex: string;
4
+ readonly name: string;
5
+ readonly network: string;
6
+ readonly nativeCurrency: {
7
+ readonly name: string;
8
+ readonly symbol: string;
9
+ readonly decimals: number;
10
+ };
11
+ readonly rpcUrls: {
12
+ readonly default: { readonly http: readonly string[] };
13
+ readonly public: { readonly http: readonly string[] };
14
+ };
15
+ readonly blockExplorers: {
16
+ readonly default: { readonly name: string; readonly url: string };
17
+ };
18
+ readonly iconUrls?: readonly string[];
19
+ readonly testnet?: boolean;
20
+ }
21
+
22
+ export type AbiEntry = Readonly<Record<string, unknown>>;
23
+
24
+ export declare const WARGA_MAINNET: WargaChainConfig;
25
+ export declare const WARGA_TESTNET: WargaChainConfig;
26
+
27
+ export declare const CONTRACTS: Readonly<{
28
+ WargaCoin: string;
29
+ WrgVault: string;
30
+ MerchantEscrow: string;
31
+ ValidatorRegistry: string;
32
+ MerchantKYCBadgeNFT: string;
33
+ IDRToken: string;
34
+ USDTToken: string;
35
+ JPYToken: string;
36
+ WargaSwapV3Pool: string;
37
+ }>;
38
+
39
+ export declare const WargaCoinAbi: readonly AbiEntry[];
40
+ export declare const WrgVaultAbi: readonly AbiEntry[];
41
+ export declare const MerchantEscrowAbi: readonly AbiEntry[];
42
+ export declare const ValidatorRegistryAbi: readonly AbiEntry[];
43
+ export declare const MerchantKYCBadgeNFTAbi: readonly AbiEntry[];
44
+ export declare const IDRTokenAbi: readonly AbiEntry[];
45
+ export declare const USDTTokenAbi: readonly AbiEntry[];
46
+ export declare const JPYTokenAbi: readonly AbiEntry[];
47
+ export declare const WargaSwapV3PoolAbi: readonly AbiEntry[];
48
+ export declare const QuantumGuardVaultAbi: readonly AbiEntry[];
49
+
50
+ export declare const ABIS: Readonly<
51
+ Record<keyof typeof CONTRACTS | "QuantumGuardVault", readonly AbiEntry[]>
52
+ >;
53
+
54
+ export declare class WargaRpcError extends Error {
55
+ code: number | string | null;
56
+ method: string | null;
57
+ status: number | null;
58
+ constructor(message: string, opts?: { code?: number | string | null; method?: string | null; status?: number | null });
59
+ }
60
+
61
+ export interface WargaClientOptions {
62
+ rpcUrl?: string;
63
+ fallbackRpcUrls?: string[];
64
+ apiBaseUrl?: string;
65
+ testnet?: boolean;
66
+ timeoutMs?: number;
67
+ retries?: number;
68
+ retryDelayMs?: number;
69
+ fetch?: typeof globalThis.fetch;
70
+ }
71
+
72
+ export interface BalanceResult {
73
+ address: string;
74
+ wei: bigint;
75
+ wrg: string;
76
+ }
77
+
78
+ export declare function formatWrg(wei: bigint | string | number, maxDecimals?: number): string;
79
+ export declare function parseWrg(amount: string | number): bigint;
80
+ export declare function isValidAddress(address: string): boolean;
81
+ export declare function computeQuantumAnchor(secretPreimage: string | Uint8Array): Promise<string>;
82
+ export declare function scanTransactionLocal(tx: { to?: string; data?: string; input?: string; origin?: string; domain?: string }): {
83
+ isSafe: boolean;
84
+ riskLevel: "LOW" | "MEDIUM" | "HIGH" | "CRITICAL";
85
+ drainerDetected: boolean;
86
+ reasons: string[];
87
+ source: "local-offline";
88
+ };
89
+
90
+ export declare class WargaClient {
91
+ rpcUrl: string;
92
+ fallbackRpcUrls: string[];
93
+ apiBaseUrl: string;
94
+ timeoutMs: number;
95
+ retries: number;
96
+ retryDelayMs: number;
97
+ constructor(options?: WargaClientOptions);
98
+ rpc<T = unknown>(method: string, params?: unknown[]): Promise<T>;
99
+ batchRpc(calls: ReadonlyArray<{ method: string; params?: unknown[] }>): Promise<unknown[]>;
100
+ getChainId(): Promise<number>;
101
+ getBlockNumber(): Promise<number>;
102
+ getGasPrice(): Promise<bigint>;
103
+ getBalance(address: string, blockTag?: string): Promise<BalanceResult>;
104
+ getTransactionCount(address: string, blockTag?: string): Promise<number>;
105
+ estimateGas(txObject: Record<string, unknown>): Promise<bigint>;
106
+ sendRawTransaction(signedTxHex: string): Promise<string>;
107
+ getTransactionReceipt(txHash: string): Promise<Record<string, unknown> | null>;
108
+ waitForTransaction(txHash: string, opts?: { timeoutMs?: number; pollMs?: number }): Promise<Record<string, unknown>>;
109
+ getLogs(filter?: Record<string, unknown>): Promise<unknown[]>;
110
+ pollLogs(filter: Record<string, unknown>, onLogs: (logs: unknown[]) => void, opts?: { intervalMs?: number }): () => void;
111
+ lookupWallet(query: string): Promise<Record<string, unknown>>;
112
+ getPqcStatus(): Promise<Record<string, unknown>>;
113
+ getPqcPubKey(): Promise<Record<string, unknown>>;
114
+ getPqcAttestation(): Promise<Record<string, unknown>>;
115
+ verifyMLDSA65(message: string, signatureHex: string, publicKeyHex?: string | null): Promise<Record<string, unknown>>;
116
+ scanTransaction(txPayload: Record<string, unknown>, opts?: { localOnly?: boolean }): Promise<Record<string, unknown>>;
117
+ }
118
+
119
+ export declare class WargaEscrow {
120
+ contract: any;
121
+ constructor(contract: any);
122
+ static create(ethersContractCtor: any, signerOrProvider: any, address?: string): WargaEscrow;
123
+ lockOrder(orderId: string, merchant: string, amountWei: bigint): Promise<any>;
124
+ lockOrderWithTimeout(orderId: string, merchant: string, amountWei: bigint, timeoutSeconds: number): Promise<any>;
125
+ openDispute(orderId: string, reason: string): Promise<any>;
126
+ releaseEscrow(orderId: string): Promise<any>;
127
+ refundEscrow(orderId: string, reason: string): Promise<any>;
128
+ claimExpiredOrder(orderId: string): Promise<any>;
129
+ resolveDispute(orderId: string, releaseToMerchant: boolean, resolutionNote: string): Promise<any>;
130
+ getOrder(orderId: string): Promise<any>;
131
+ }
132
+
133
+ export declare class WargaPool {
134
+ contract: any;
135
+ constructor(contract: any);
136
+ static create(ethersContractCtor: any, signerOrProvider: any, address?: string): WargaPool;
137
+ static computeMinOut(quotedOutWei: bigint | string | number, slippageBps?: number): bigint;
138
+ getReserves(): Promise<[bigint, bigint]>;
139
+ quoteSwap(tokenIn: string, amountInWei: bigint, slippageBps?: number): Promise<{ amountOut: bigint; minAmountOut: bigint }>;
140
+ swap(tokenIn: string, amountInWei: bigint, minAmountOutWei: bigint, recipient: string): Promise<any>;
141
+ }
142
+
143
+ export declare class WargaKycBadge {
144
+ contract: any;
145
+ constructor(contract: any);
146
+ static create(ethersContractCtor: any, signerOrProvider: any, address?: string): WargaKycBadge;
147
+ verifyBadge(tokenId: bigint | number): Promise<{ isErc5192: boolean; isLocked: boolean; owner: string; uri: string }>;
148
+ mintBadge(recipient: string, storeId: string, storeName: string, kycHash: string, metadataUri: string): Promise<any>;
149
+ revokeBadge(tokenId: bigint | number): Promise<any>;
150
+ }