warthog-ts 0.1.21
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/LICENSE +21 -0
- package/README.md +300 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/src/tests/account.test.d.ts +2 -0
- package/dist/src/tests/account.test.d.ts.map +1 -0
- package/dist/src/tests/account.test.js +32 -0
- package/dist/src/tests/account.test.js.map +1 -0
- package/dist/src/tests/funds.test.d.ts +2 -0
- package/dist/src/tests/funds.test.d.ts.map +1 -0
- package/dist/src/tests/funds.test.js +161 -0
- package/dist/src/tests/funds.test.js.map +1 -0
- package/dist/src/tests/hdwallet.test.d.ts +2 -0
- package/dist/src/tests/hdwallet.test.d.ts.map +1 -0
- package/dist/src/tests/hdwallet.test.js +26 -0
- package/dist/src/tests/hdwallet.test.js.map +1 -0
- package/dist/src/tests/price.test.d.ts +2 -0
- package/dist/src/tests/price.test.d.ts.map +1 -0
- package/dist/src/tests/price.test.js +40 -0
- package/dist/src/tests/price.test.js.map +1 -0
- package/dist/src/types/Account.d.ts +44 -0
- package/dist/src/types/Account.d.ts.map +1 -0
- package/dist/src/types/Account.js +74 -0
- package/dist/src/types/Account.js.map +1 -0
- package/dist/src/types/Address.d.ts +24 -0
- package/dist/src/types/Address.d.ts.map +1 -0
- package/dist/src/types/Address.js +56 -0
- package/dist/src/types/Address.js.map +1 -0
- package/dist/src/types/Api.d.ts +90 -0
- package/dist/src/types/Api.d.ts.map +1 -0
- package/dist/src/types/Api.js +99 -0
- package/dist/src/types/Api.js.map +1 -0
- package/dist/src/types/Funds.d.ts +175 -0
- package/dist/src/types/Funds.d.ts.map +1 -0
- package/dist/src/types/Funds.js +329 -0
- package/dist/src/types/Funds.js.map +1 -0
- package/dist/src/types/HDWallet.d.ts +29 -0
- package/dist/src/types/HDWallet.d.ts.map +1 -0
- package/dist/src/types/HDWallet.js +40 -0
- package/dist/src/types/HDWallet.js.map +1 -0
- package/dist/src/types/NonceId.d.ts +26 -0
- package/dist/src/types/NonceId.d.ts.map +1 -0
- package/dist/src/types/NonceId.js +37 -0
- package/dist/src/types/NonceId.js.map +1 -0
- package/dist/src/types/Price.d.ts +93 -0
- package/dist/src/types/Price.d.ts.map +1 -0
- package/dist/src/types/Price.js +170 -0
- package/dist/src/types/Price.js.map +1 -0
- package/dist/src/types/TransactionContext.d.ts +135 -0
- package/dist/src/types/TransactionContext.d.ts.map +1 -0
- package/dist/src/types/TransactionContext.js +314 -0
- package/dist/src/types/TransactionContext.js.map +1 -0
- package/dist/src/util/frexp.d.ts +2 -0
- package/dist/src/util/frexp.d.ts.map +1 -0
- package/dist/src/util/frexp.js +68 -0
- package/dist/src/util/frexp.js.map +1 -0
- package/package.json +40 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { test, expect } from "bun:test";
|
|
2
|
+
import { Price } from "../types/Price";
|
|
3
|
+
test("Price fromDoubleInternal rejects invalid input", () => {
|
|
4
|
+
// Zero, negative, infinity, and NaN are invalid
|
|
5
|
+
expect(Price.fromDoubleInternal(0.0)).toBeNull();
|
|
6
|
+
expect(Price.fromDoubleInternal(0)).toBeNull();
|
|
7
|
+
expect(Price.fromDoubleInternal(-1.0)).toBeNull();
|
|
8
|
+
expect(Price.fromDoubleInternal(-0.5)).toBeNull();
|
|
9
|
+
expect(Price.fromDoubleInternal(Infinity)).toBeNull();
|
|
10
|
+
expect(Price.fromDoubleInternal(-Infinity)).toBeNull();
|
|
11
|
+
expect(Price.fromDoubleInternal(NaN)).toBeNull();
|
|
12
|
+
});
|
|
13
|
+
test("Price roundtrip fromDoubleInternal -> toDoubleRaw", () => {
|
|
14
|
+
const testRoundtrip = (input) => {
|
|
15
|
+
const price = Price.fromDoubleInternal(input);
|
|
16
|
+
expect(price).not.toBeNull();
|
|
17
|
+
const output = price.toDoubleRaw();
|
|
18
|
+
console.log(`Input: ${input}, Output: ${output}, Diff: ${(Math.abs(1 - output / input) * 100).toFixed(4)}%`);
|
|
19
|
+
expect(Math.abs(1 - output / input) * 100).toBeLessThan(0.01);
|
|
20
|
+
};
|
|
21
|
+
testRoundtrip(0.0000001354);
|
|
22
|
+
testRoundtrip(0.000001345);
|
|
23
|
+
testRoundtrip(0.000016574);
|
|
24
|
+
testRoundtrip(0.00012043);
|
|
25
|
+
testRoundtrip(0.0011239);
|
|
26
|
+
testRoundtrip(0.02341);
|
|
27
|
+
testRoundtrip(0.1812);
|
|
28
|
+
testRoundtrip(0.5123);
|
|
29
|
+
testRoundtrip(1.813);
|
|
30
|
+
testRoundtrip(2.5213);
|
|
31
|
+
testRoundtrip(16.430);
|
|
32
|
+
testRoundtrip(194.75);
|
|
33
|
+
testRoundtrip(1834.5678);
|
|
34
|
+
testRoundtrip(12093);
|
|
35
|
+
testRoundtrip(234091);
|
|
36
|
+
testRoundtrip(9582389);
|
|
37
|
+
testRoundtrip(190123900);
|
|
38
|
+
testRoundtrip(9230942914);
|
|
39
|
+
});
|
|
40
|
+
//# sourceMappingURL=price.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"price.test.js","sourceRoot":"","sources":["../../../src/tests/price.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEvC,IAAI,CAAC,gDAAgD,EAAE,GAAG,EAAE;IACxD,gDAAgD;IAChD,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;IACjD,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC/C,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;IAClD,MAA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;IACvB,aAAa,CAAC,MAAM,CAAC,CAAC;IACtB,aAAa,CAAC,MAAM,CAAC,CAAC;IACtB,aAAa,CAAC,KAAK,CAAC,CAAC;IACrB,aAAa,CAAC,MAAM,CAAC,CAAC;IACtB,aAAa,CAAC,MAAM,CAAC,CAAC;IACtB,aAAa,CAAC,MAAM,CAAC,CAAC;IACtB,aAAa,CAAC,SAAS,CAAC,CAAC;IACzB,aAAa,CAAC,KAAK,CAAC,CAAC;IACrB,aAAa,CAAC,MAAM,CAAC,CAAC;IACtB,aAAa,CAAC,OAAO,CAAC,CAAC;IACvB,aAAa,CAAC,SAAS,CAAC,CAAC;IACzB,aAAa,CAAC,UAAU,CAAC,CAAC;AAC9B,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Address } from "./Address";
|
|
2
|
+
/**
|
|
3
|
+
* 65-byte ECDSA signature components.
|
|
4
|
+
*/
|
|
5
|
+
export interface Signature65 {
|
|
6
|
+
r: string;
|
|
7
|
+
s: string;
|
|
8
|
+
recid: number;
|
|
9
|
+
signature: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Wallet account for signing transactions on the Warthog network.
|
|
13
|
+
* Uses secp256k1 elliptic curve for key management.
|
|
14
|
+
*/
|
|
15
|
+
export declare class Account {
|
|
16
|
+
readonly privateKeyHex: string;
|
|
17
|
+
readonly publicKeyHex: string;
|
|
18
|
+
readonly address: Address;
|
|
19
|
+
private constructor();
|
|
20
|
+
/**
|
|
21
|
+
* Generate a new random account with a fresh private key.
|
|
22
|
+
* @returns New Account with randomly generated keypair
|
|
23
|
+
*/
|
|
24
|
+
static fromRandom(): Account;
|
|
25
|
+
/**
|
|
26
|
+
* Load an account from an existing private key.
|
|
27
|
+
* @param hex - Private key as 64-character hex string
|
|
28
|
+
* @returns Account derived from the private key
|
|
29
|
+
*/
|
|
30
|
+
static fromPrivateKeyHex(hex: string): Account;
|
|
31
|
+
/**
|
|
32
|
+
* Derive account from an elliptic curve keypair.
|
|
33
|
+
* @param keyPair - EC keypair to derive from
|
|
34
|
+
* @returns Account with derived keys and address
|
|
35
|
+
*/
|
|
36
|
+
private static fromKeyPair;
|
|
37
|
+
/**
|
|
38
|
+
* Sign a hash for Warthog transaction
|
|
39
|
+
* @param hash - 32-byte hex string to sign
|
|
40
|
+
* @returns 65-byte signature (r + s + recid)
|
|
41
|
+
*/
|
|
42
|
+
sign(hash: string): Signature65;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=Account.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Account.d.ts","sourceRoot":"","sources":["../../../src/types/Account.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC;;GAEG;AACH,MAAM,WAAW,WAAW;IACxB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,qBAAa,OAAO;IAChB,SAAgB,aAAa,EAAE,MAAM,CAAC;IACtC,SAAgB,YAAY,EAAE,MAAM,CAAC;IACrC,SAAgB,OAAO,EAAE,OAAO,CAAC;IAEjC,OAAO;IAMP;;;OAGG;WACW,UAAU,IAAI,OAAO;IAKnC;;;;OAIG;WACW,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAKrD;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,WAAW;IAqB1B;;;;OAIG;IACI,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW;CAezC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import pkg from "elliptic";
|
|
2
|
+
import { ethers } from "ethers";
|
|
3
|
+
import { Address } from "./Address";
|
|
4
|
+
const { ec: EC } = pkg;
|
|
5
|
+
const ecInstance = new EC("secp256k1");
|
|
6
|
+
/**
|
|
7
|
+
* Wallet account for signing transactions on the Warthog network.
|
|
8
|
+
* Uses secp256k1 elliptic curve for key management.
|
|
9
|
+
*/
|
|
10
|
+
export class Account {
|
|
11
|
+
constructor(privateKeyHex, publicKeyHex, address) {
|
|
12
|
+
this.privateKeyHex = privateKeyHex;
|
|
13
|
+
this.publicKeyHex = publicKeyHex;
|
|
14
|
+
this.address = address;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Generate a new random account with a fresh private key.
|
|
18
|
+
* @returns New Account with randomly generated keypair
|
|
19
|
+
*/
|
|
20
|
+
static fromRandom() {
|
|
21
|
+
const keyPair = ecInstance.genKeyPair();
|
|
22
|
+
return Account.fromKeyPair(keyPair);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Load an account from an existing private key.
|
|
26
|
+
* @param hex - Private key as 64-character hex string
|
|
27
|
+
* @returns Account derived from the private key
|
|
28
|
+
*/
|
|
29
|
+
static fromPrivateKeyHex(hex) {
|
|
30
|
+
const keyPair = ecInstance.keyFromPrivate(hex, "hex");
|
|
31
|
+
return Account.fromKeyPair(keyPair);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Derive account from an elliptic curve keypair.
|
|
35
|
+
* @param keyPair - EC keypair to derive from
|
|
36
|
+
* @returns Account with derived keys and address
|
|
37
|
+
*/
|
|
38
|
+
static fromKeyPair(keyPair) {
|
|
39
|
+
let privateKeyHex = keyPair.getPrivate().toString("hex");
|
|
40
|
+
while (privateKeyHex.length < 64) {
|
|
41
|
+
privateKeyHex = "0" + privateKeyHex;
|
|
42
|
+
}
|
|
43
|
+
const publicKeyHex = keyPair.getPublic().encodeCompressed("hex");
|
|
44
|
+
const publicKeyBuffer = Buffer.from(publicKeyHex, "hex");
|
|
45
|
+
const sha256Hex = ethers.sha256(publicKeyBuffer);
|
|
46
|
+
const sha256Hash = Buffer.from(sha256Hex.slice(2), "hex");
|
|
47
|
+
const ripemd160Hex = ethers.ripemd160(sha256Hash);
|
|
48
|
+
const ripemd160Hash = Buffer.from(ripemd160Hex.slice(2), "hex");
|
|
49
|
+
const checksumHex = ethers.sha256(ripemd160Hash);
|
|
50
|
+
const checksum = Buffer.from(checksumHex.slice(2), "hex").slice(0, 4);
|
|
51
|
+
const addressBuffer = Buffer.concat([ripemd160Hash, checksum]);
|
|
52
|
+
const addressHex = addressBuffer.toString("hex");
|
|
53
|
+
return new Account(privateKeyHex, publicKeyHex, Address.fromHex(addressHex));
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Sign a hash for Warthog transaction
|
|
57
|
+
* @param hash - 32-byte hex string to sign
|
|
58
|
+
* @returns 65-byte signature (r + s + recid)
|
|
59
|
+
*/
|
|
60
|
+
sign(hash) {
|
|
61
|
+
const keyPair = ecInstance.keyFromPrivate(this.privateKeyHex, "hex");
|
|
62
|
+
const signature = ecInstance.sign(Buffer.from(hash, "hex"), keyPair, { canonical: true });
|
|
63
|
+
const r = signature.r.toString(16).padStart(64, "0");
|
|
64
|
+
const s = signature.s.toString(16).padStart(64, "0");
|
|
65
|
+
const recid = signature.recoveryParam ?? 0;
|
|
66
|
+
return {
|
|
67
|
+
r,
|
|
68
|
+
s,
|
|
69
|
+
recid,
|
|
70
|
+
signature: r + s + recid.toString(16).padStart(2, "0"),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=Account.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Account.js","sourceRoot":"","sources":["../../../src/types/Account.ts"],"names":[],"mappings":"AACA,OAAO,GAAG,MAAM,UAAU,CAAC;AAC3B,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,GAAG,CAAC;AACvB,MAAM,UAAU,GAAG,IAAI,EAAE,CAAC,WAAW,CAAC,CAAC;AAYvC;;;GAGG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AS,EAAE,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC;SACzD,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Warthog address with SHA-256 checksum validation.
|
|
3
|
+
* Addresses are 20 bytes (40 hex chars) with a 4-byte checksum (8 hex chars),
|
|
4
|
+
* totaling 48 hex characters.
|
|
5
|
+
*/
|
|
6
|
+
export declare class Address {
|
|
7
|
+
readonly hex: string;
|
|
8
|
+
private constructor();
|
|
9
|
+
/**
|
|
10
|
+
* Parse and validate a 48-character hex address with checksum.
|
|
11
|
+
* @param hex - 48-character hex string (20 bytes payload + 4 bytes checksum)
|
|
12
|
+
* @returns Address instance if valid, null otherwise
|
|
13
|
+
*/
|
|
14
|
+
static fromHex(hex: string): Address | null;
|
|
15
|
+
/**
|
|
16
|
+
* Create address from raw 40-character hex (20 bytes).
|
|
17
|
+
* Computes and appends SHA-256 checksum.
|
|
18
|
+
* @param raw - 40-character hex string (20 bytes, no checksum)
|
|
19
|
+
* @returns Address instance if valid, null otherwise
|
|
20
|
+
*/
|
|
21
|
+
static fromRaw(raw: string): Address | null;
|
|
22
|
+
static validate(address: string): boolean;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=Address.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Address.d.ts","sourceRoot":"","sources":["../../../src/types/Address.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,qBAAa,OAAO;aACoB,GAAG,EAAE,MAAM;IAA/C,OAAO;IAEP;;;;OAIG;WACW,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI;IAuBlD;;;;;OAKG;WACW,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI;WAiBpC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;CAGnD"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ethers } from "ethers";
|
|
2
|
+
/**
|
|
3
|
+
* Warthog address with SHA-256 checksum validation.
|
|
4
|
+
* Addresses are 20 bytes (40 hex chars) with a 4-byte checksum (8 hex chars),
|
|
5
|
+
* totaling 48 hex characters.
|
|
6
|
+
*/
|
|
7
|
+
export class Address {
|
|
8
|
+
constructor(hex) {
|
|
9
|
+
this.hex = hex;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Parse and validate a 48-character hex address with checksum.
|
|
13
|
+
* @param hex - 48-character hex string (20 bytes payload + 4 bytes checksum)
|
|
14
|
+
* @returns Address instance if valid, null otherwise
|
|
15
|
+
*/
|
|
16
|
+
static fromHex(hex) {
|
|
17
|
+
if (hex.length !== 48) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const addressBuffer = Buffer.from(hex, "hex");
|
|
21
|
+
if (addressBuffer.length !== 24) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
const payload = addressBuffer.slice(0, 20);
|
|
25
|
+
const checksum = addressBuffer.slice(20, 24);
|
|
26
|
+
const expectedChecksumHex = ethers.sha256(payload);
|
|
27
|
+
const expectedChecksum = Buffer.from(expectedChecksumHex.slice(2), "hex").slice(0, 4);
|
|
28
|
+
if (!checksum.equals(expectedChecksum)) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
return new Address(hex);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Create address from raw 40-character hex (20 bytes).
|
|
35
|
+
* Computes and appends SHA-256 checksum.
|
|
36
|
+
* @param raw - 40-character hex string (20 bytes, no checksum)
|
|
37
|
+
* @returns Address instance if valid, null otherwise
|
|
38
|
+
*/
|
|
39
|
+
static fromRaw(raw) {
|
|
40
|
+
if (raw.length !== 40) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const rawBuffer = Buffer.from(raw, "hex");
|
|
44
|
+
if (rawBuffer.length !== 20) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
const checksumHex = ethers.sha256(rawBuffer);
|
|
48
|
+
const checksum = Buffer.from(checksumHex.slice(2), "hex").slice(0, 4);
|
|
49
|
+
const addressBuffer = Buffer.concat([rawBuffer, checksum]);
|
|
50
|
+
return new Address(addressBuffer.toString("hex"));
|
|
51
|
+
}
|
|
52
|
+
static validate(address) {
|
|
53
|
+
return Address.fromHex(address) !== null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=Address.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Address.js","sourceRoot":"","sources":["../../../src/types/Address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC;;;;GAIG;AACH,MAAM,OAAO,OAAO;IAChB,YAAoC,GAAW;QAAX,QAAG,GAAH,GAAG,CAAQ;IAAG,CAAC;IAEnD;;;;OAIG;IACI,MAAM,CAAC,OAAO,CAAC,GAAW;QAC7B,IAAI,GAAG,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;YACpB,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC9C,IAAI,aAAa,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;YAC9B,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,MAAM,OAAO,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC3C,MAAM,QAAQ,GAAG,aAAa,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QAE7C,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACnD,MAAM,gBAAgB,GAAG,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAEtF,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,gBAAgB,CAAC,EAAE,CAAC;YACrC,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,OAAO,CAAC,GAAW;QAC7B,IAAI,GAAG,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;YACpB,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC1C,IAAI,SAAS,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;YAC1B,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAC7C,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACtE,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC;QAE3D,OAAO,IAAI,OAAO,CAAC,aAAa,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;IACtD,CAAC;IAEM,MAAM,CAAC,QAAQ,CAAC,OAAe;QAClC,OAAO,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC;IAC7C,CAAC;CACJ"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { TransactionContext } from './TransactionContext';
|
|
2
|
+
import type { TransactionJson } from './TransactionContext';
|
|
3
|
+
import { NonceId } from './NonceId';
|
|
4
|
+
import { RoundedFee } from './Funds';
|
|
5
|
+
/**
|
|
6
|
+
* Known Warthog network nodes.
|
|
7
|
+
*/
|
|
8
|
+
export declare const KNOWN_NODES: readonly ["http://65.87.7.86:3001", "http://185.209.228.16:3001", "http://89.117.150.162:3001", "http://62.72.44.89:3001", "http://217.182.64.43:3001", "https://node.wartscan.io", "http://dev.node-s.com:3001"];
|
|
9
|
+
/**
|
|
10
|
+
* Type representing a known node URL.
|
|
11
|
+
*/
|
|
12
|
+
export type NodeUrl = typeof KNOWN_NODES[number];
|
|
13
|
+
/**
|
|
14
|
+
* Successful API response with data.
|
|
15
|
+
*/
|
|
16
|
+
export type ApiSuccess<T> = {
|
|
17
|
+
success: true;
|
|
18
|
+
data: T;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Error response from API.
|
|
22
|
+
*/
|
|
23
|
+
export type ApiError = {
|
|
24
|
+
success: false;
|
|
25
|
+
code: number;
|
|
26
|
+
error: string;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Result type for API calls.
|
|
30
|
+
*/
|
|
31
|
+
export type ApiResult<T> = ApiSuccess<T> | ApiError;
|
|
32
|
+
/**
|
|
33
|
+
* Chain head data containing pin information.
|
|
34
|
+
*/
|
|
35
|
+
export interface ChainHeadData {
|
|
36
|
+
pinHash: string;
|
|
37
|
+
pinHeight: number;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Data returned after transaction submission.
|
|
41
|
+
*/
|
|
42
|
+
export interface SubmitTransactionData {
|
|
43
|
+
txHash: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Options for HTTP requests.
|
|
47
|
+
*/
|
|
48
|
+
export interface RequestOptions {
|
|
49
|
+
method?: 'GET' | 'POST';
|
|
50
|
+
body?: unknown;
|
|
51
|
+
queryParams?: Record<string, string | number>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Client for communicating with Warthog nodes.
|
|
55
|
+
*/
|
|
56
|
+
export declare class WarthogApi {
|
|
57
|
+
readonly baseUrl: string;
|
|
58
|
+
/**
|
|
59
|
+
* Create a new API client.
|
|
60
|
+
* @param baseUrl - Base URL of the Warthog node
|
|
61
|
+
*/
|
|
62
|
+
constructor(baseUrl: string);
|
|
63
|
+
/**
|
|
64
|
+
* Make an HTTP request to the API.
|
|
65
|
+
* @param path - API endpoint path
|
|
66
|
+
* @param options - Request options
|
|
67
|
+
* @returns API result
|
|
68
|
+
*/
|
|
69
|
+
private request;
|
|
70
|
+
/**
|
|
71
|
+
* Get the current chain head (latest pinned block).
|
|
72
|
+
* @returns Chain head data with pin hash and height
|
|
73
|
+
*/
|
|
74
|
+
getChainHead(): Promise<ApiResult<ChainHeadData>>;
|
|
75
|
+
/**
|
|
76
|
+
* Submit a signed transaction to the API.
|
|
77
|
+
* @param tx - Signed transaction JSON from TransactionContext
|
|
78
|
+
* @returns Transaction hash if successful
|
|
79
|
+
*/
|
|
80
|
+
submitTransaction(tx: TransactionJson): Promise<ApiResult<SubmitTransactionData>>;
|
|
81
|
+
/**
|
|
82
|
+
* Create a transaction context for building transactions.
|
|
83
|
+
* Fetches the current chain head to get the pin hash and height.
|
|
84
|
+
* @param fee - Transaction fee
|
|
85
|
+
* @param nonceId - Unique nonce for the transaction
|
|
86
|
+
* @returns TransactionContext ready for building transactions
|
|
87
|
+
*/
|
|
88
|
+
createTransactionContext(fee: RoundedFee, nonceId: NonceId): Promise<TransactionContext>;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=Api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Api.d.ts","sourceRoot":"","sources":["../../../src/types/Api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC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;;;;OAMG;IACG,wBAAwB,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAQjG"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { TransactionContext } from './TransactionContext';
|
|
2
|
+
import { NonceId } from './NonceId';
|
|
3
|
+
import { RoundedFee } from './Funds';
|
|
4
|
+
/**
|
|
5
|
+
* Known Warthog network nodes.
|
|
6
|
+
*/
|
|
7
|
+
export const KNOWN_NODES = [
|
|
8
|
+
'http://65.87.7.86:3001',
|
|
9
|
+
'http://185.209.228.16:3001',
|
|
10
|
+
'http://89.117.150.162:3001',
|
|
11
|
+
'http://62.72.44.89:3001',
|
|
12
|
+
'http://217.182.64.43:3001',
|
|
13
|
+
'https://node.wartscan.io',
|
|
14
|
+
'http://dev.node-s.com:3001',
|
|
15
|
+
];
|
|
16
|
+
/**
|
|
17
|
+
* Client for communicating with Warthog nodes.
|
|
18
|
+
*/
|
|
19
|
+
export class WarthogApi {
|
|
20
|
+
/**
|
|
21
|
+
* Create a new API client.
|
|
22
|
+
* @param baseUrl - Base URL of the Warthog node
|
|
23
|
+
*/
|
|
24
|
+
constructor(baseUrl) {
|
|
25
|
+
this.baseUrl = baseUrl;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Make an HTTP request to the API.
|
|
29
|
+
* @param path - API endpoint path
|
|
30
|
+
* @param options - Request options
|
|
31
|
+
* @returns API result
|
|
32
|
+
*/
|
|
33
|
+
async request(path, options) {
|
|
34
|
+
let url = `${this.baseUrl}${path}`;
|
|
35
|
+
if (options?.queryParams) {
|
|
36
|
+
const params = new URLSearchParams();
|
|
37
|
+
for (const [key, value] of Object.entries(options.queryParams)) {
|
|
38
|
+
params.append(key, String(value));
|
|
39
|
+
}
|
|
40
|
+
url += `?${params.toString()}`;
|
|
41
|
+
}
|
|
42
|
+
const replacer = (_key, value) => {
|
|
43
|
+
if (typeof value === 'bigint') {
|
|
44
|
+
return Number(value);
|
|
45
|
+
}
|
|
46
|
+
return value;
|
|
47
|
+
};
|
|
48
|
+
const body = options?.body ? JSON.stringify(options.body, replacer) : undefined;
|
|
49
|
+
const response = await fetch(url, {
|
|
50
|
+
method: options?.method || 'GET',
|
|
51
|
+
headers: { 'Content-Type': 'application/json' },
|
|
52
|
+
body,
|
|
53
|
+
});
|
|
54
|
+
const text = await response.text();
|
|
55
|
+
const json = JSON.parse(text);
|
|
56
|
+
if (json.code !== 0) {
|
|
57
|
+
return {
|
|
58
|
+
success: false,
|
|
59
|
+
code: json.code,
|
|
60
|
+
error: json.error || 'Unknown error',
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return { success: true, data: json.data };
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get the current chain head (latest pinned block).
|
|
67
|
+
* @returns Chain head data with pin hash and height
|
|
68
|
+
*/
|
|
69
|
+
async getChainHead() {
|
|
70
|
+
return this.request('/chain/head');
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Submit a signed transaction to the API.
|
|
74
|
+
* @param tx - Signed transaction JSON from TransactionContext
|
|
75
|
+
* @returns Transaction hash if successful
|
|
76
|
+
*/
|
|
77
|
+
async submitTransaction(tx) {
|
|
78
|
+
return this.request('/transaction/add', {
|
|
79
|
+
method: 'POST',
|
|
80
|
+
body: tx,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Create a transaction context for building transactions.
|
|
85
|
+
* Fetches the current chain head to get the pin hash and height.
|
|
86
|
+
* @param fee - Transaction fee
|
|
87
|
+
* @param nonceId - Unique nonce for the transaction
|
|
88
|
+
* @returns TransactionContext ready for building transactions
|
|
89
|
+
*/
|
|
90
|
+
async createTransactionContext(fee, nonceId) {
|
|
91
|
+
const headResult = await this.getChainHead();
|
|
92
|
+
if (!headResult.success) {
|
|
93
|
+
throw new Error(headResult.error);
|
|
94
|
+
}
|
|
95
|
+
const { pinHash, pinHeight } = headResult.data;
|
|
96
|
+
return new TransactionContext({ pinHash, pinHeight }, fee, nonceId);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=Api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Api.js","sourceRoot":"","sources":["../../../src/types/Api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACvB,wBAAwB;IACxB,4BAA4B;IAC5B,4BAA4B;IAC5B,yBAAyB;IACzB,2BAA2B;IAC3B,0BAA0B;IAC1B,4BAA4B;CACtB,CAAC;AAqDX;;GAEG;AACH,MAAM,OAAO,UAAU;IACnB;;;OAGG;IACH,YAA4B,OAAe;QAAf,YAAO,GAAP,OAAO,CAAQ;IAAG,CAAC;IAE/C;;;;;OAKG;IACK,KAAK,CAAC,OAAO,CAAI,IAAY,EAAE,OAAwB;QAC3D,IAAI,GAAG,GAAG,GAAG,IAAI,CAAC,OAAO,GAAG,IAAI,EAAE,CAAC;QAEnC,IAAI,OAAO,EAAE,WAAW,EAAE,CAAC;YACvB,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;YACrC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;gBAC7D,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;YACtC,CAAC;YACD,GAAG,IAAI,IAAI,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC;QACnC,CAAC;QAED,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAE,KAAc,EAAW,EAAE;YACvD,IAA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e,EAAE,OAAgB;QAC5D,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;QAC7C,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QACtC,CAAC;QACD,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,UAAU,CAAC,IAAI,CAAC;QAC/C,OAAO,IAAI,kBAAkB,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IACxE,CAAC;CACJ"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
export declare const MAX_U64 = 18446744073709551615n;
|
|
2
|
+
/**
|
|
3
|
+
* Represents token's number of decimal place).
|
|
4
|
+
* Valid range: 0-18. WART uses 8 decimal places.
|
|
5
|
+
*/
|
|
6
|
+
export declare class TokenDecimals {
|
|
7
|
+
readonly decimals: number;
|
|
8
|
+
/** Pre-configured WART decimals (8 decimals) */
|
|
9
|
+
static readonly WART: TokenDecimals;
|
|
10
|
+
/** Pre-configured Liquidity decimals (8 decimals) */
|
|
11
|
+
static readonly LIQUIDITY: TokenDecimals;
|
|
12
|
+
/**
|
|
13
|
+
* Create a TokenDecimals instance.
|
|
14
|
+
* @param decimals - Number of decimal places (0-18)
|
|
15
|
+
* @throws Error if decimals is out of range
|
|
16
|
+
*/
|
|
17
|
+
constructor(decimals: number);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Represents a parsed decimal string as a 64-bit integer with decimal place info.
|
|
21
|
+
* Used internally for parsing currency strings.
|
|
22
|
+
*/
|
|
23
|
+
export declare class ParsedFunds {
|
|
24
|
+
val: bigint;
|
|
25
|
+
decimalPlaces: number;
|
|
26
|
+
constructor(val: bigint, decimalPlaces: number);
|
|
27
|
+
/**
|
|
28
|
+
* Parse a decimal string into a ParsedFunds.
|
|
29
|
+
* @param s - Decimal string (e.g., "123.45")
|
|
30
|
+
* @returns ParsedFunds or null if invalid
|
|
31
|
+
*/
|
|
32
|
+
static parse(s: string): ParsedFunds | null;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Represents token amounts with specific number of decimals.
|
|
36
|
+
*/
|
|
37
|
+
export declare class Funds {
|
|
38
|
+
amount: bigint;
|
|
39
|
+
private constructor();
|
|
40
|
+
/**
|
|
41
|
+
* Parse a decimal string to Funds.
|
|
42
|
+
* @param string - Decimal string (e.g., "123.45")
|
|
43
|
+
* @param decimals - Token decimals
|
|
44
|
+
* @returns Funds or null if invalid
|
|
45
|
+
*/
|
|
46
|
+
static parse(string: string, decimals: TokenDecimals): Funds | null;
|
|
47
|
+
/**
|
|
48
|
+
* Convert ParsedFunds to Funds with specific number of decimals.
|
|
49
|
+
* @param fd - Parsed funds
|
|
50
|
+
* @param decimals - Token decimals
|
|
51
|
+
* @returns Funds or null if invalid
|
|
52
|
+
*/
|
|
53
|
+
static fromParsedFunds(fd: ParsedFunds, decimals: TokenDecimals): Funds | null;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Represents Warthog's native token (WART) with 8 decimal places.
|
|
57
|
+
*/
|
|
58
|
+
export declare class Wart {
|
|
59
|
+
/** Amount in E8 (1 WART = 100,000,000 E8) */
|
|
60
|
+
E8: bigint;
|
|
61
|
+
private constructor();
|
|
62
|
+
/**
|
|
63
|
+
* Parse a decimal string to Wart.
|
|
64
|
+
* @param string - Decimal string (e.g., "1.5")
|
|
65
|
+
* @returns Wart or null if invalid
|
|
66
|
+
*/
|
|
67
|
+
static parse(string: string): Wart | null;
|
|
68
|
+
/**
|
|
69
|
+
* Convert ParsedFunds to Wart.
|
|
70
|
+
* @param fd - Parsed funds
|
|
71
|
+
* @returns Wart or null if invalid
|
|
72
|
+
*/
|
|
73
|
+
static fromParsedFunds(fd: ParsedFunds): Wart | null;
|
|
74
|
+
/**
|
|
75
|
+
* Create Wart from E8 value.
|
|
76
|
+
* @param E8 - Amount in E8 (1 WART = 100,000,000 E8)
|
|
77
|
+
* @returns Wart or null if invalid (exceeds MAX_U64)
|
|
78
|
+
*/
|
|
79
|
+
static fromE8(E8: bigint): Wart | null;
|
|
80
|
+
/**
|
|
81
|
+
* Convert to rounded fee.
|
|
82
|
+
* @param ceil - If true, round up; otherwise round down
|
|
83
|
+
* @returns RoundedFee
|
|
84
|
+
*/
|
|
85
|
+
roundedFee(ceil: boolean): RoundedFee;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Represents liquidity pool tokens with 8 decimal places.
|
|
89
|
+
* Used for liquidity deposit/withdrawal transactions.
|
|
90
|
+
*/
|
|
91
|
+
export declare class Liquidity {
|
|
92
|
+
/** Amount in E8 (1 liquidity unit = 100,000,000 E8) */
|
|
93
|
+
E8: bigint;
|
|
94
|
+
private constructor();
|
|
95
|
+
/**
|
|
96
|
+
* Parse a decimal string to Liquidity.
|
|
97
|
+
* @param string - Decimal string (e.g., "1.5")
|
|
98
|
+
* @returns Liquidity or null if invalid
|
|
99
|
+
*/
|
|
100
|
+
static parse(string: string): Liquidity | null;
|
|
101
|
+
/**
|
|
102
|
+
* Convert ParsedFunds to Liquidity.
|
|
103
|
+
* @param fd - Parsed funds
|
|
104
|
+
* @returns Liquidity or null if invalid
|
|
105
|
+
*/
|
|
106
|
+
static fromParsedFunds(fd: ParsedFunds): Liquidity | null;
|
|
107
|
+
/**
|
|
108
|
+
* Create Liquidity from E8 value.
|
|
109
|
+
* @param E8 - Amount in E8 (1 liquidity = 100,000,000 E8)
|
|
110
|
+
* @returns Liquidity or null if invalid (exceeds MAX_U64)
|
|
111
|
+
*/
|
|
112
|
+
static fromE8(E8: bigint): Liquidity | null;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Transaction fee in rounded WART format.
|
|
116
|
+
*
|
|
117
|
+
* This is NOT the 16-bit compact representation itself. Instead, it is the result of:
|
|
118
|
+
* 1. Converting WART to 16-bit compact format (CompactFee)
|
|
119
|
+
* 2. Converting back to WART scale
|
|
120
|
+
*
|
|
121
|
+
* This is a lossy operation - the original WART value cannot be restored from RoundedFee.
|
|
122
|
+
* Warthog nodes require rounded values on the 64-bit WART scale in API calls, not the
|
|
123
|
+
* raw 16-bit compact representation.
|
|
124
|
+
*/
|
|
125
|
+
export declare class RoundedFee {
|
|
126
|
+
readonly E8: bigint;
|
|
127
|
+
private constructor();
|
|
128
|
+
/**
|
|
129
|
+
* Create RoundedFee from Wart.
|
|
130
|
+
* @param wart - Wart amount
|
|
131
|
+
* @param ceil - If true, round up; otherwise round down
|
|
132
|
+
* @returns RoundedFee
|
|
133
|
+
*/
|
|
134
|
+
static fromWart(wart: Wart, ceil: boolean): RoundedFee;
|
|
135
|
+
/**
|
|
136
|
+
* Create RoundedFee from E8 value.
|
|
137
|
+
* @param E8 - Fee in E8
|
|
138
|
+
* @param ceil - If true, round up; otherwise round down
|
|
139
|
+
* @returns RoundedFee or null if invalid
|
|
140
|
+
*/
|
|
141
|
+
static fromE8(E8: bigint, ceil: boolean): RoundedFee | null;
|
|
142
|
+
/**
|
|
143
|
+
* Get minimum possible fee (0.00000001 WART = 1 E8).
|
|
144
|
+
* @returns Minimum RoundedFee
|
|
145
|
+
*/
|
|
146
|
+
static min(): RoundedFee;
|
|
147
|
+
/**
|
|
148
|
+
* Convert to Wart.
|
|
149
|
+
* @returns Wart representation
|
|
150
|
+
*/
|
|
151
|
+
toWart(): Wart;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Warthog's internal 16-bit compact fee representation.
|
|
155
|
+
* Used for compact storage and transmission of transaction fees within the protocol.
|
|
156
|
+
* Note: This is NOT used in transaction submission API - use RoundedFee instead.
|
|
157
|
+
*/
|
|
158
|
+
export declare class CompactFee {
|
|
159
|
+
exponent: number;
|
|
160
|
+
mantissa: number;
|
|
161
|
+
private constructor();
|
|
162
|
+
/**
|
|
163
|
+
* Create CompactFee from Wart amount.
|
|
164
|
+
* @param wart - Wart amount
|
|
165
|
+
* @param ceil - If true, round up; otherwise round down
|
|
166
|
+
* @returns CompactFee
|
|
167
|
+
*/
|
|
168
|
+
static fromWart(wart: Wart, ceil: boolean): CompactFee;
|
|
169
|
+
/**
|
|
170
|
+
* Convert CompactFee to Wart.
|
|
171
|
+
* @returns Wart representation
|
|
172
|
+
*/
|
|
173
|
+
toWart(): Wart;
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=Funds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Funds.d.ts","sourceRoot":"","sources":["../../../src/types/Funds.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,wBAAsB,CAAC;AAE3C;;;GAGG;AACH,qBAAa,aAAa;aAWM,QAAQ,EAAE,MAAM;IAV5C,gDAAgD;IAChD,gBAAuB,IAAI,gBAAwB;IACnD,qDAAqD;IACrD,gBAAuB,SAAS,gBAAwB;IAExD;;;;OAIG;gBACyB,QAAQ,EAAE,MAAM;CAK/C;AAED;;;GAGG;AACH,qBAAa,WAAW;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,aAAa,EAAE,MAAM,CAAC;gBAEV,GAAG,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM;IAK9C;;;;OAIG;WACW,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI;CAsCrD;AA0BD;;GAEG;AACH,qBAAa,KAAK;IACd,MAAM,EAAE,MAAM,CAAC;IAEf,OAAO;IAIP;;;;;OAKG;WACW,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,GAAG,KAAK,GAAG,IAAI;IAM1E;;;;;OAKG;WACW,eAAe,CAAC,EAAE,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,GAAG,KAAK,GAAG,IAAI;CAKxF;AAED;;GAEG;AACH,qBAAa,IAAI;IACb,6CAA6C;IAC7C,EAAE,EAAE,MAAM,CAAC;IAEX,OAAO;IAIP;;;;OAIG;WACW,KA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