@amadeus-protocol/sdk 1.0.8 → 1.1.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/dist/api/chain.d.ts +144 -117
- package/dist/api/chain.d.ts.map +1 -1
- package/dist/api/chain.js +175 -146
- package/dist/api/chain.js.map +1 -1
- package/dist/api/contract.d.ts +78 -60
- package/dist/api/contract.d.ts.map +1 -1
- package/dist/api/contract.js +102 -75
- package/dist/api/contract.js.map +1 -1
- package/dist/api/epoch.d.ts +65 -66
- package/dist/api/epoch.d.ts.map +1 -1
- package/dist/api/epoch.js +90 -98
- package/dist/api/epoch.js.map +1 -1
- package/dist/api/peer.d.ts +77 -78
- package/dist/api/peer.d.ts.map +1 -1
- package/dist/api/peer.js +93 -94
- package/dist/api/peer.js.map +1 -1
- package/dist/api/proof.d.ts +44 -23
- package/dist/api/proof.d.ts.map +1 -1
- package/dist/api/proof.js +56 -29
- package/dist/api/proof.js.map +1 -1
- package/dist/api/transaction.d.ts +68 -69
- package/dist/api/transaction.d.ts.map +1 -1
- package/dist/api/transaction.js +84 -84
- package/dist/api/transaction.js.map +1 -1
- package/dist/api/wallet.d.ts +36 -37
- package/dist/api/wallet.d.ts.map +1 -1
- package/dist/api/wallet.js +47 -50
- package/dist/api/wallet.js.map +1 -1
- package/dist/client.d.ts +66 -68
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +231 -276
- package/dist/client.js.map +1 -1
- package/dist/constants.d.ts +13 -10
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +49 -45
- package/dist/constants.js.map +1 -1
- package/dist/contract-state.d.ts +6 -3
- package/dist/contract-state.d.ts.map +1 -1
- package/dist/contract-state.js +88 -106
- package/dist/contract-state.js.map +1 -1
- package/dist/contracts/abi-types.d.ts +32 -32
- package/dist/contracts/abi-types.d.ts.map +1 -1
- package/dist/contracts/coin.d.ts +13 -20
- package/dist/contracts/coin.d.ts.map +1 -1
- package/dist/contracts/coin.js +42 -38
- package/dist/contracts/coin.js.map +1 -1
- package/dist/contracts/contract-call.d.ts +14 -16
- package/dist/contracts/contract-call.d.ts.map +1 -1
- package/dist/contracts/contract-call.js +45 -54
- package/dist/contracts/contract-call.js.map +1 -1
- package/dist/contracts/contract.d.ts +24 -55
- package/dist/contracts/contract.d.ts.map +1 -1
- package/dist/contracts/contract.js +63 -101
- package/dist/contracts/contract.js.map +1 -1
- package/dist/contracts/lockup/abi.d.ts +54 -51
- package/dist/contracts/lockup/abi.d.ts.map +1 -1
- package/dist/contracts/lockup/abi.js +65 -74
- package/dist/contracts/lockup/abi.js.map +1 -1
- package/dist/contracts/lockup/helpers.d.ts +22 -18
- package/dist/contracts/lockup/helpers.d.ts.map +1 -1
- package/dist/contracts/lockup/helpers.js +44 -47
- package/dist/contracts/lockup/helpers.js.map +1 -1
- package/dist/contracts/lockup/parsers.d.ts +7 -3
- package/dist/contracts/lockup/parsers.d.ts.map +1 -1
- package/dist/contracts/lockup/parsers.js +51 -55
- package/dist/contracts/lockup/parsers.js.map +1 -1
- package/dist/contracts/lockup/storage-keys.d.ts +5 -2
- package/dist/contracts/lockup/storage-keys.d.ts.map +1 -1
- package/dist/contracts/lockup/storage-keys.js +54 -70
- package/dist/contracts/lockup/storage-keys.js.map +1 -1
- package/dist/contracts/lockup/types.d.ts +73 -70
- package/dist/contracts/lockup/types.d.ts.map +1 -1
- package/dist/contracts/lockup-prime/abi.d.ts +328 -325
- package/dist/contracts/lockup-prime/abi.d.ts.map +1 -1
- package/dist/contracts/lockup-prime/abi.js +397 -417
- package/dist/contracts/lockup-prime/abi.js.map +1 -1
- package/dist/contracts/lockup-prime/helpers.d.ts +35 -31
- package/dist/contracts/lockup-prime/helpers.d.ts.map +1 -1
- package/dist/contracts/lockup-prime/helpers.js +131 -137
- package/dist/contracts/lockup-prime/helpers.js.map +1 -1
- package/dist/contracts/lockup-prime/parsers.d.ts +9 -5
- package/dist/contracts/lockup-prime/parsers.d.ts.map +1 -1
- package/dist/contracts/lockup-prime/parsers.js +61 -61
- package/dist/contracts/lockup-prime/parsers.js.map +1 -1
- package/dist/contracts/lockup-prime/storage-keys.d.ts +7 -4
- package/dist/contracts/lockup-prime/storage-keys.d.ts.map +1 -1
- package/dist/contracts/lockup-prime/storage-keys.js +64 -80
- package/dist/contracts/lockup-prime/storage-keys.js.map +1 -1
- package/dist/contracts/lockup-prime/types.d.ts +92 -89
- package/dist/contracts/lockup-prime/types.d.ts.map +1 -1
- package/dist/contracts/lockup-prime/types.js +12 -13
- package/dist/contracts/lockup-prime/types.js.map +1 -1
- package/dist/contracts/nft/abi.d.ts +104 -0
- package/dist/contracts/nft/abi.d.ts.map +1 -0
- package/dist/contracts/nft/abi.js +135 -0
- package/dist/contracts/nft/abi.js.map +1 -0
- package/dist/contracts/nft/helpers.d.ts +21 -0
- package/dist/contracts/nft/helpers.d.ts.map +1 -0
- package/dist/contracts/nft/helpers.js +61 -0
- package/dist/contracts/nft/helpers.js.map +1 -0
- package/dist/contracts/nft/types.d.ts +47 -0
- package/dist/contracts/nft/types.d.ts.map +1 -0
- package/dist/conversion.d.ts +5 -2
- package/dist/conversion.d.ts.map +1 -1
- package/dist/conversion.js +45 -50
- package/dist/conversion.js.map +1 -1
- package/dist/crypto.d.ts +14 -16
- package/dist/crypto.d.ts.map +1 -1
- package/dist/crypto.js +121 -140
- package/dist/crypto.js.map +1 -1
- package/dist/encoding.d.ts +11 -8
- package/dist/encoding.d.ts.map +1 -1
- package/dist/encoding.js +123 -144
- package/dist/encoding.js.map +1 -1
- package/dist/encryption.d.ts +15 -12
- package/dist/encryption.d.ts.map +1 -1
- package/dist/encryption.js +119 -117
- package/dist/encryption.js.map +1 -1
- package/dist/explorer.d.ts +10 -7
- package/dist/explorer.d.ts.map +1 -1
- package/dist/explorer.js +51 -48
- package/dist/explorer.js.map +1 -1
- package/dist/formatters.d.ts +8 -5
- package/dist/formatters.d.ts.map +1 -1
- package/dist/formatters.js +67 -68
- package/dist/formatters.js.map +1 -1
- package/dist/index.d.ts +42 -55
- package/dist/index.js +39 -55
- package/dist/mnemonic.d.ts +12 -9
- package/dist/mnemonic.d.ts.map +1 -1
- package/dist/mnemonic.js +105 -114
- package/dist/mnemonic.js.map +1 -1
- package/dist/networks.d.ts +14 -17
- package/dist/networks.d.ts.map +1 -1
- package/dist/networks.js +40 -36
- package/dist/networks.js.map +1 -1
- package/dist/schemas.js +75 -79
- package/dist/schemas.js.map +1 -1
- package/dist/sdk.d.ts +69 -65
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +126 -117
- package/dist/sdk.js.map +1 -1
- package/dist/serialization.d.ts +8 -18
- package/dist/serialization.d.ts.map +1 -1
- package/dist/serialization.js +207 -260
- package/dist/serialization.js.map +1 -1
- package/dist/signing.js +67 -67
- package/dist/signing.js.map +1 -1
- package/dist/transaction-builder.d.ts +175 -184
- package/dist/transaction-builder.d.ts.map +1 -1
- package/dist/transaction-builder.js +295 -344
- package/dist/transaction-builder.js.map +1 -1
- package/dist/transaction-errors.d.ts +10 -12
- package/dist/transaction-errors.d.ts.map +1 -1
- package/dist/transaction-errors.js +145 -166
- package/dist/transaction-errors.js.map +1 -1
- package/dist/types.d.ts +530 -450
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +169 -183
- package/dist/types.js.map +1 -1
- package/dist/validation.d.ts +24 -26
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +194 -192
- package/dist/validation.js.map +1 -1
- package/package.json +4 -3
- package/dist/api/index.d.ts +0 -8
- package/dist/api/index.d.ts.map +0 -1
- package/dist/api/index.js +0 -8
- package/dist/api/index.js.map +0 -1
- package/dist/contracts/abi-types.js +0 -8
- package/dist/contracts/abi-types.js.map +0 -1
- package/dist/contracts/index.d.ts +0 -7
- package/dist/contracts/index.d.ts.map +0 -1
- package/dist/contracts/index.js +0 -7
- package/dist/contracts/index.js.map +0 -1
- package/dist/contracts/lockup/calls.d.ts +0 -23
- package/dist/contracts/lockup/calls.d.ts.map +0 -1
- package/dist/contracts/lockup/calls.js +0 -25
- package/dist/contracts/lockup/calls.js.map +0 -1
- package/dist/contracts/lockup/index.d.ts +0 -6
- package/dist/contracts/lockup/index.d.ts.map +0 -1
- package/dist/contracts/lockup/index.js +0 -6
- package/dist/contracts/lockup/index.js.map +0 -1
- package/dist/contracts/lockup/types.js +0 -7
- package/dist/contracts/lockup/types.js.map +0 -1
- package/dist/contracts/lockup-prime/calls.d.ts +0 -53
- package/dist/contracts/lockup-prime/calls.d.ts.map +0 -1
- package/dist/contracts/lockup-prime/calls.js +0 -60
- package/dist/contracts/lockup-prime/calls.js.map +0 -1
- package/dist/contracts/lockup-prime/index.d.ts +0 -6
- package/dist/contracts/lockup-prime/index.d.ts.map +0 -1
- package/dist/contracts/lockup-prime/index.js +0 -6
- package/dist/contracts/lockup-prime/index.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/schemas.d.ts +0 -67
- package/dist/schemas.d.ts.map +0 -1
- package/dist/signing.d.ts +0 -39
- package/dist/signing.d.ts.map +0 -1
package/dist/constants.js
CHANGED
|
@@ -1,46 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
1
|
+
//#region src/constants.ts
|
|
2
|
+
/**
|
|
3
|
+
* Amadeus Protocol Constants
|
|
4
|
+
*
|
|
5
|
+
* This module contains all protocol-level constants used throughout the SDK.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* SDK version
|
|
9
|
+
*/
|
|
10
|
+
const SDK_VERSION = "1.0.0";
|
|
11
|
+
/**
|
|
12
|
+
* Byte length of an Amadeus public key (BLS12-381 public key)
|
|
13
|
+
*/
|
|
14
|
+
const AMADEUS_PUBLIC_KEY_BYTE_LENGTH = 48;
|
|
15
|
+
/**
|
|
16
|
+
* Byte length of an Amadeus seed (private key seed)
|
|
17
|
+
*/
|
|
18
|
+
const AMADEUS_SEED_BYTE_LENGTH = 64;
|
|
19
|
+
/**
|
|
20
|
+
* Number of decimal places for AMA token
|
|
21
|
+
*/
|
|
22
|
+
const AMA_TOKEN_DECIMALS = 9;
|
|
23
|
+
/**
|
|
24
|
+
* Multiplier for converting between atomic units and AMA tokens
|
|
25
|
+
*/
|
|
26
|
+
const AMA_TOKEN_DECIMALS_MULTIPLIER = 10 ** 9;
|
|
27
|
+
/**
|
|
28
|
+
* Minimum transferable amount in AMA (1 atomic unit)
|
|
29
|
+
*/
|
|
30
|
+
const MIN_TRANSFERABLE_AMOUNT = 1 / AMA_TOKEN_DECIMALS_MULTIPLIER;
|
|
31
|
+
/**
|
|
32
|
+
* Flat network transfer fee in AMA for standard transfers
|
|
33
|
+
*/
|
|
34
|
+
const AMA_TRANSFER_FEE = .02;
|
|
35
|
+
/**
|
|
36
|
+
* Default explorer URL
|
|
37
|
+
*/
|
|
38
|
+
const EXPLORER_URL = "https://explorer.ama.one";
|
|
39
|
+
/**
|
|
40
|
+
* Default node API URL
|
|
41
|
+
*/
|
|
42
|
+
const NODE_API_URL = "https://mainnet-rpc.ama.one/api";
|
|
43
|
+
/**
|
|
44
|
+
* Default request timeout in milliseconds
|
|
45
|
+
*/
|
|
46
|
+
const DEFAULT_TIMEOUT = 3e4;
|
|
47
|
+
//#endregion
|
|
48
|
+
export { AMADEUS_PUBLIC_KEY_BYTE_LENGTH, AMADEUS_SEED_BYTE_LENGTH, AMA_TOKEN_DECIMALS, AMA_TOKEN_DECIMALS_MULTIPLIER, AMA_TRANSFER_FEE, DEFAULT_TIMEOUT, EXPLORER_URL, MIN_TRANSFERABLE_AMOUNT, NODE_API_URL, SDK_VERSION };
|
|
49
|
+
|
|
46
50
|
//# sourceMappingURL=constants.js.map
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","
|
|
1
|
+
{"version":3,"file":"constants.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["/**\n * Amadeus Protocol Constants\n *\n * This module contains all protocol-level constants used throughout the SDK.\n */\n\n/**\n * SDK version\n */\nexport const SDK_VERSION = '1.0.0'\n\n/**\n * Byte length of an Amadeus public key (BLS12-381 public key)\n */\nexport const AMADEUS_PUBLIC_KEY_BYTE_LENGTH = 48\n\n/**\n * Byte length of an Amadeus seed (private key seed)\n */\nexport const AMADEUS_SEED_BYTE_LENGTH = 64\n\n/**\n * Number of decimal places for AMA token\n */\nexport const AMA_TOKEN_DECIMALS = 9\n\n/**\n * Multiplier for converting between atomic units and AMA tokens\n */\nexport const AMA_TOKEN_DECIMALS_MULTIPLIER = 10 ** AMA_TOKEN_DECIMALS\n\n/**\n * Minimum transferable amount in AMA (1 atomic unit)\n */\nexport const MIN_TRANSFERABLE_AMOUNT = 1 / AMA_TOKEN_DECIMALS_MULTIPLIER\n\n/**\n * Flat network transfer fee in AMA for standard transfers\n */\nexport const AMA_TRANSFER_FEE = 0.02\n\n/**\n * Default explorer URL\n */\nexport const EXPLORER_URL = 'https://explorer.ama.one'\n\n/**\n * Default node API URL\n */\nexport const NODE_API_URL = 'https://mainnet-rpc.ama.one/api'\n\n/**\n * Default request timeout in milliseconds\n */\nexport const DEFAULT_TIMEOUT = 30000\n"],"mappings":";;;;;;;;;AASA,MAAa,cAAc;;;;AAK3B,MAAa,iCAAiC;;;;AAK9C,MAAa,2BAA2B;;;;AAKxC,MAAa,qBAAqB;;;;AAKlC,MAAa,gCAAgC,MAAA;;;;AAK7C,MAAa,0BAA0B,IAAI;;;;AAK3C,MAAa,mBAAmB;;;;AAKhC,MAAa,eAAe;;;;AAK5B,MAAa,eAAe;;;;AAK5B,MAAa,kBAAkB"}
|
package/dist/contract-state.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/contract-state.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Contract State Utilities
|
|
3
4
|
*
|
|
@@ -21,7 +22,7 @@
|
|
|
21
22
|
* // entries: [["base64key", "base64value"], ...]
|
|
22
23
|
* ```
|
|
23
24
|
*/
|
|
24
|
-
|
|
25
|
+
declare function decodeContractStateToBase64(bytes: Uint8Array | ArrayBuffer): Array<[string, string]>;
|
|
25
26
|
/**
|
|
26
27
|
* Parse a contract state value as a number.
|
|
27
28
|
*
|
|
@@ -42,7 +43,7 @@ export declare function decodeContractStateToBase64(bytes: Uint8Array | ArrayBuf
|
|
|
42
43
|
* parseStateNumber(null) // 0
|
|
43
44
|
* ```
|
|
44
45
|
*/
|
|
45
|
-
|
|
46
|
+
declare function parseStateNumber(value: string | number | Uint8Array | null | undefined): number;
|
|
46
47
|
/**
|
|
47
48
|
* Parse a contract state value as a string.
|
|
48
49
|
*
|
|
@@ -55,5 +56,7 @@ export declare function parseStateNumber(value: string | number | Uint8Array | n
|
|
|
55
56
|
* @param value - Raw contract state value
|
|
56
57
|
* @returns Parsed string or null
|
|
57
58
|
*/
|
|
58
|
-
|
|
59
|
+
declare function parseStateString(value: string | number | Uint8Array | null | undefined): string | null;
|
|
60
|
+
//#endregion
|
|
61
|
+
export { decodeContractStateToBase64, parseStateNumber, parseStateString };
|
|
59
62
|
//# sourceMappingURL=contract-state.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract-state.d.ts","
|
|
1
|
+
{"version":3,"file":"contract-state.d.ts","names":[],"sources":["../src/contract-state.ts"],"mappings":";;AA2BA;;;;;;;;;;;;;;AA6BA;;;;;AAyBA;;;iBAtDgB,2BAAA,CACf,KAAA,EAAO,UAAA,GAAa,WAAA,GAClB,KAAA;;;;;;;;;;;;;;;;;;;;;iBA2Ba,gBAAA,CAAiB,KAAA,oBAAyB,UAAA;;;;;;;;;;;;;iBAyB1C,gBAAA,CACf,KAAA,oBAAyB,UAAA"}
|
package/dist/contract-state.js
CHANGED
|
@@ -1,117 +1,99 @@
|
|
|
1
|
+
import { decodeContractState } from "./serialization.js";
|
|
2
|
+
import { uint8ArrayToBase64 } from "./encoding.js";
|
|
3
|
+
//#region src/contract-state.ts
|
|
1
4
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import { uint8ArrayToBase64 } from './encoding';
|
|
9
|
-
import { decodeContractState } from './serialization';
|
|
5
|
+
* Contract State Utilities
|
|
6
|
+
*
|
|
7
|
+
* Provides functions for parsing contract state values returned by the Amadeus chain.
|
|
8
|
+
* Contract state values are stored as binary (Uint8Array) and need to be decoded
|
|
9
|
+
* into usable types (numbers, strings, etc.).
|
|
10
|
+
*/
|
|
10
11
|
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return pairs
|
|
29
|
-
.filter(([key, value]) => key.length > 0 && value.length > 0)
|
|
30
|
-
.map(([key, value]) => [uint8ArrayToBase64(key), uint8ArrayToBase64(value)]);
|
|
12
|
+
* Decode VecPack-encoded contract state and convert keys/values to Base64 strings.
|
|
13
|
+
*
|
|
14
|
+
* Useful for serializing decoded contract state for Redux or other stores
|
|
15
|
+
* that require JSON-serializable values.
|
|
16
|
+
*
|
|
17
|
+
* @param bytes - VecPack-encoded bytes (Uint8Array or ArrayBuffer)
|
|
18
|
+
* @returns Array of [key, value] tuples as Base64 strings
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* const buffer = await response.arrayBuffer()
|
|
23
|
+
* const entries = decodeContractStateToBase64(buffer)
|
|
24
|
+
* // entries: [["base64key", "base64value"], ...]
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
function decodeContractStateToBase64(bytes) {
|
|
28
|
+
return decodeContractState(bytes).filter(([key, value]) => key.length > 0 && value.length > 0).map(([key, value]) => [uint8ArrayToBase64(key), uint8ArrayToBase64(value)]);
|
|
31
29
|
}
|
|
32
30
|
/**
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (value instanceof Uint8Array) {
|
|
62
|
-
return decodeUint8ArrayAsNumber(value);
|
|
63
|
-
}
|
|
64
|
-
return 0;
|
|
31
|
+
* Parse a contract state value as a number.
|
|
32
|
+
*
|
|
33
|
+
* Handles multiple input types:
|
|
34
|
+
* - `number` — returned directly
|
|
35
|
+
* - `string` — parsed as integer
|
|
36
|
+
* - `Uint8Array` — first tries UTF-8 digit string, then little-endian binary
|
|
37
|
+
* - `null`/`undefined` — returns 0
|
|
38
|
+
*
|
|
39
|
+
* @param value - Raw contract state value
|
|
40
|
+
* @returns Parsed number (0 if unparseable)
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* parseStateNumber(new TextEncoder().encode('42')) // 42
|
|
45
|
+
* parseStateNumber(new Uint8Array([0x2a, 0x00])) // 42 (little-endian)
|
|
46
|
+
* parseStateNumber('100') // 100
|
|
47
|
+
* parseStateNumber(null) // 0
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
function parseStateNumber(value) {
|
|
51
|
+
if (value === null || value === void 0) return 0;
|
|
52
|
+
if (typeof value === "number") return Number.isInteger(value) && value >= 0 ? value : 0;
|
|
53
|
+
if (typeof value === "string") {
|
|
54
|
+
const parsed = parseInt(value, 10);
|
|
55
|
+
return isNaN(parsed) || parsed < 0 ? 0 : parsed;
|
|
56
|
+
}
|
|
57
|
+
if (value instanceof Uint8Array) return decodeUint8ArrayAsNumber(value);
|
|
58
|
+
return 0;
|
|
65
59
|
}
|
|
66
60
|
/**
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return value.toString();
|
|
85
|
-
if (value instanceof Uint8Array) {
|
|
86
|
-
return new TextDecoder().decode(value);
|
|
87
|
-
}
|
|
88
|
-
return null;
|
|
61
|
+
* Parse a contract state value as a string.
|
|
62
|
+
*
|
|
63
|
+
* Handles multiple input types:
|
|
64
|
+
* - `string` — returned directly
|
|
65
|
+
* - `number` — converted to string
|
|
66
|
+
* - `Uint8Array` — decoded as UTF-8
|
|
67
|
+
* - `null`/`undefined` — returns null
|
|
68
|
+
*
|
|
69
|
+
* @param value - Raw contract state value
|
|
70
|
+
* @returns Parsed string or null
|
|
71
|
+
*/
|
|
72
|
+
function parseStateString(value) {
|
|
73
|
+
if (value === null || value === void 0) return null;
|
|
74
|
+
if (typeof value === "string") return value;
|
|
75
|
+
if (typeof value === "number") return value.toString();
|
|
76
|
+
if (value instanceof Uint8Array) return new TextDecoder().decode(value);
|
|
77
|
+
return null;
|
|
89
78
|
}
|
|
90
79
|
/**
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
80
|
+
* Decode a Uint8Array contract state value as a number.
|
|
81
|
+
* Tries UTF-8 digit string first, falls back to little-endian binary.
|
|
82
|
+
*/
|
|
94
83
|
function decodeUint8ArrayAsNumber(value) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
// Fallthrough to binary parsing
|
|
107
|
-
}
|
|
108
|
-
// Fallback: parse as little-endian integer (u32/u64)
|
|
109
|
-
let result = 0n;
|
|
110
|
-
const bytesToRead = Math.min(value.length, 8);
|
|
111
|
-
for (let i = 0; i < bytesToRead; i++) {
|
|
112
|
-
result |= BigInt(value[i]) << BigInt(i * 8);
|
|
113
|
-
}
|
|
114
|
-
const asNumber = Number(result);
|
|
115
|
-
return Number.isSafeInteger(asNumber) ? asNumber : 0;
|
|
84
|
+
if (!value.length) return 0;
|
|
85
|
+
try {
|
|
86
|
+
const str = new TextDecoder().decode(value);
|
|
87
|
+
const parsed = parseInt(str, 10);
|
|
88
|
+
if (!isNaN(parsed)) return parsed;
|
|
89
|
+
} catch {}
|
|
90
|
+
let result = 0n;
|
|
91
|
+
const bytesToRead = Math.min(value.length, 8);
|
|
92
|
+
for (let i = 0; i < bytesToRead; i++) result |= BigInt(value[i]) << BigInt(i * 8);
|
|
93
|
+
const asNumber = Number(result);
|
|
94
|
+
return Number.isSafeInteger(asNumber) ? asNumber : 0;
|
|
116
95
|
}
|
|
96
|
+
//#endregion
|
|
97
|
+
export { decodeContractStateToBase64, parseStateNumber, parseStateString };
|
|
98
|
+
|
|
117
99
|
//# sourceMappingURL=contract-state.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract-state.js","
|
|
1
|
+
{"version":3,"file":"contract-state.js","names":[],"sources":["../src/contract-state.ts"],"sourcesContent":["/**\n * Contract State Utilities\n *\n * Provides functions for parsing contract state values returned by the Amadeus chain.\n * Contract state values are stored as binary (Uint8Array) and need to be decoded\n * into usable types (numbers, strings, etc.).\n */\n\nimport { uint8ArrayToBase64 } from './encoding'\nimport { decodeContractState } from './serialization'\n\n/**\n * Decode VecPack-encoded contract state and convert keys/values to Base64 strings.\n *\n * Useful for serializing decoded contract state for Redux or other stores\n * that require JSON-serializable values.\n *\n * @param bytes - VecPack-encoded bytes (Uint8Array or ArrayBuffer)\n * @returns Array of [key, value] tuples as Base64 strings\n *\n * @example\n * ```ts\n * const buffer = await response.arrayBuffer()\n * const entries = decodeContractStateToBase64(buffer)\n * // entries: [[\"base64key\", \"base64value\"], ...]\n * ```\n */\nexport function decodeContractStateToBase64(\n\tbytes: Uint8Array | ArrayBuffer\n): Array<[string, string]> {\n\tconst pairs = decodeContractState(bytes)\n\treturn pairs\n\t\t.filter(([key, value]) => key.length > 0 && value.length > 0)\n\t\t.map(([key, value]) => [uint8ArrayToBase64(key), uint8ArrayToBase64(value)])\n}\n\n/**\n * Parse a contract state value as a number.\n *\n * Handles multiple input types:\n * - `number` — returned directly\n * - `string` — parsed as integer\n * - `Uint8Array` — first tries UTF-8 digit string, then little-endian binary\n * - `null`/`undefined` — returns 0\n *\n * @param value - Raw contract state value\n * @returns Parsed number (0 if unparseable)\n *\n * @example\n * ```ts\n * parseStateNumber(new TextEncoder().encode('42')) // 42\n * parseStateNumber(new Uint8Array([0x2a, 0x00])) // 42 (little-endian)\n * parseStateNumber('100') // 100\n * parseStateNumber(null) // 0\n * ```\n */\nexport function parseStateNumber(value: string | number | Uint8Array | null | undefined): number {\n\tif (value === null || value === undefined) return 0\n\tif (typeof value === 'number') return Number.isInteger(value) && value >= 0 ? value : 0\n\tif (typeof value === 'string') {\n\t\tconst parsed = parseInt(value, 10)\n\t\treturn isNaN(parsed) || parsed < 0 ? 0 : parsed\n\t}\n\tif (value instanceof Uint8Array) {\n\t\treturn decodeUint8ArrayAsNumber(value)\n\t}\n\treturn 0\n}\n\n/**\n * Parse a contract state value as a string.\n *\n * Handles multiple input types:\n * - `string` — returned directly\n * - `number` — converted to string\n * - `Uint8Array` — decoded as UTF-8\n * - `null`/`undefined` — returns null\n *\n * @param value - Raw contract state value\n * @returns Parsed string or null\n */\nexport function parseStateString(\n\tvalue: string | number | Uint8Array | null | undefined\n): string | null {\n\tif (value === null || value === undefined) return null\n\tif (typeof value === 'string') return value\n\tif (typeof value === 'number') return value.toString()\n\tif (value instanceof Uint8Array) {\n\t\treturn new TextDecoder().decode(value)\n\t}\n\treturn null\n}\n\n/**\n * Decode a Uint8Array contract state value as a number.\n * Tries UTF-8 digit string first, falls back to little-endian binary.\n */\nfunction decodeUint8ArrayAsNumber(value: Uint8Array): number {\n\tif (!value.length) return 0\n\n\t// First try to interpret as UTF-8 digits\n\ttry {\n\t\tconst str = new TextDecoder().decode(value)\n\t\tconst parsed = parseInt(str, 10)\n\t\tif (!isNaN(parsed)) {\n\t\t\treturn parsed\n\t\t}\n\t} catch {\n\t\t// Fallthrough to binary parsing\n\t}\n\n\t// Fallback: parse as little-endian integer (u32/u64)\n\tlet result = 0n\n\tconst bytesToRead = Math.min(value.length, 8)\n\tfor (let i = 0; i < bytesToRead; i++) {\n\t\tresult |= BigInt(value[i]!) << BigInt(i * 8)\n\t}\n\n\tconst asNumber = Number(result)\n\treturn Number.isSafeInteger(asNumber) ? asNumber : 0\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAgB,4BACf,OAC0B;CAE1B,OADc,oBAAoB,MACtB,CACV,QAAQ,CAAC,KAAK,WAAW,IAAI,SAAS,KAAK,MAAM,SAAS,EAAE,CAC5D,KAAK,CAAC,KAAK,WAAW,CAAC,mBAAmB,IAAI,EAAE,mBAAmB,MAAM,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;AAuB9E,SAAgB,iBAAiB,OAAgE;CAChG,IAAI,UAAU,QAAQ,UAAU,KAAA,GAAW,OAAO;CAClD,IAAI,OAAO,UAAU,UAAU,OAAO,OAAO,UAAU,MAAM,IAAI,SAAS,IAAI,QAAQ;CACtF,IAAI,OAAO,UAAU,UAAU;EAC9B,MAAM,SAAS,SAAS,OAAO,GAAG;EAClC,OAAO,MAAM,OAAO,IAAI,SAAS,IAAI,IAAI;;CAE1C,IAAI,iBAAiB,YACpB,OAAO,yBAAyB,MAAM;CAEvC,OAAO;;;;;;;;;;;;;;AAeR,SAAgB,iBACf,OACgB;CAChB,IAAI,UAAU,QAAQ,UAAU,KAAA,GAAW,OAAO;CAClD,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,IAAI,OAAO,UAAU,UAAU,OAAO,MAAM,UAAU;CACtD,IAAI,iBAAiB,YACpB,OAAO,IAAI,aAAa,CAAC,OAAO,MAAM;CAEvC,OAAO;;;;;;AAOR,SAAS,yBAAyB,OAA2B;CAC5D,IAAI,CAAC,MAAM,QAAQ,OAAO;CAG1B,IAAI;EACH,MAAM,MAAM,IAAI,aAAa,CAAC,OAAO,MAAM;EAC3C,MAAM,SAAS,SAAS,KAAK,GAAG;EAChC,IAAI,CAAC,MAAM,OAAO,EACjB,OAAO;SAED;CAKR,IAAI,SAAS;CACb,MAAM,cAAc,KAAK,IAAI,MAAM,QAAQ,EAAE;CAC7C,KAAK,IAAI,IAAI,GAAG,IAAI,aAAa,KAChC,UAAU,OAAO,MAAM,GAAI,IAAI,OAAO,IAAI,EAAE;CAG7C,MAAM,WAAW,OAAO,OAAO;CAC/B,OAAO,OAAO,cAAc,SAAS,GAAG,WAAW"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/contracts/abi-types.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Generic ABI Type Extractors
|
|
3
4
|
*
|
|
@@ -7,39 +8,39 @@
|
|
|
7
8
|
/**
|
|
8
9
|
* Shape of an ABI function input
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
interface AbiInput {
|
|
12
|
+
readonly name: string;
|
|
13
|
+
readonly type: string;
|
|
14
|
+
readonly description?: string;
|
|
15
|
+
readonly validation?: {
|
|
16
|
+
readonly min?: string;
|
|
17
|
+
readonly max?: string;
|
|
18
|
+
readonly type?: string;
|
|
19
|
+
};
|
|
20
|
+
readonly enum?: readonly string[];
|
|
20
21
|
}
|
|
21
22
|
/**
|
|
22
23
|
* Shape of an ABI function entry
|
|
23
24
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
interface AbiFunction {
|
|
26
|
+
readonly type: 'function';
|
|
27
|
+
readonly name: string;
|
|
28
|
+
readonly inputs: readonly AbiInput[];
|
|
29
|
+
readonly outputs: readonly unknown[];
|
|
30
|
+
readonly stateMutability: string;
|
|
31
|
+
readonly description?: string;
|
|
32
|
+
readonly requirements?: readonly string[];
|
|
33
|
+
readonly storage?: unknown;
|
|
33
34
|
}
|
|
34
35
|
/**
|
|
35
36
|
* Shape of any ABI definition (contractName, abi[], errors[], storage)
|
|
36
37
|
*/
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
interface AbiDefinition {
|
|
39
|
+
readonly contractName: string;
|
|
40
|
+
readonly contractVersion?: string;
|
|
41
|
+
readonly abi: readonly AbiFunction[];
|
|
42
|
+
readonly errors?: readonly unknown[];
|
|
43
|
+
readonly storage?: unknown;
|
|
43
44
|
}
|
|
44
45
|
/**
|
|
45
46
|
* Extract the literal contract name from an ABI definition
|
|
@@ -50,7 +51,7 @@ export interface AbiDefinition {
|
|
|
50
51
|
* // => 'LockupPrime'
|
|
51
52
|
* ```
|
|
52
53
|
*/
|
|
53
|
-
|
|
54
|
+
type ExtractContractName<T extends AbiDefinition> = T['contractName'];
|
|
54
55
|
/**
|
|
55
56
|
* Extract a union of all function names from an ABI definition
|
|
56
57
|
*
|
|
@@ -60,12 +61,12 @@ export type ExtractContractName<T extends AbiDefinition> = T['contractName'];
|
|
|
60
61
|
* // => 'lock' | 'unlock' | 'daily_checkin'
|
|
61
62
|
* ```
|
|
62
63
|
*/
|
|
63
|
-
|
|
64
|
+
type ExtractFunctionNames<T extends AbiDefinition> = T['abi'][number]['name'];
|
|
64
65
|
/**
|
|
65
66
|
* Find a specific function entry in the ABI by name
|
|
66
67
|
*/
|
|
67
68
|
type FindFunction<TAbi extends AbiDefinition, TFn extends string> = Extract<TAbi['abi'][number], {
|
|
68
|
-
|
|
69
|
+
readonly name: TFn;
|
|
69
70
|
}>;
|
|
70
71
|
/**
|
|
71
72
|
* Extract the inputs array for a specific function
|
|
@@ -80,8 +81,7 @@ type FunctionInputs<TAbi extends AbiDefinition, TFn extends string> = FindFuncti
|
|
|
80
81
|
* // => { amount: string; tier: string }
|
|
81
82
|
* ```
|
|
82
83
|
*/
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
};
|
|
86
|
-
export {};
|
|
84
|
+
type FunctionParams<TAbi extends AbiDefinition, TFn extends string> = { [K in FunctionInputs<TAbi, TFn>[number] as K['name']]: string };
|
|
85
|
+
//#endregion
|
|
86
|
+
export { AbiDefinition, AbiFunction, AbiInput, ExtractContractName, ExtractFunctionNames, FunctionParams };
|
|
87
87
|
//# sourceMappingURL=abi-types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abi-types.d.ts","
|
|
1
|
+
{"version":3,"file":"abi-types.d.ts","names":[],"sources":["../../src/contracts/abi-types.ts"],"mappings":";;AAUA;;;;;;;;UAAiB,QAAA;EAAA,SACP,IAAA;EAAA,SACA,IAAA;EAAA,SACA,WAAA;EAAA,SACA,UAAA;IAAA,SACC,GAAA;IAAA,SACA,GAAA;IAAA,SACA,IAAA;EAAA;EAAA,SAED,IAAA;AAAA;;;;UAMO,WAAA;EAAA,SACP,IAAA;EAAA,SACA,IAAA;EAAA,SACA,MAAA,WAAiB,QAAA;EAAA,SACjB,OAAA;EAAA,SACA,eAAA;EAAA,SACA,WAAA;EAAA,SACA,YAAA;EAAA,SACA,OAAA;AAAA;;;;UAMO,aAAA;EAAA,SACP,YAAA;EAAA,SACA,eAAA;EAAA,SACA,GAAA,WAAc,WAAA;EAAA,SACd,MAAA;EAAA,SACA,OAAA;AAAA;;;;;;;;;AAuBV;KAXY,mBAAA,WAA8B,aAAA,IAAiB,CAAA;;;;;;;;AAWyB;;KAAxE,oBAAA,WAA+B,aAAA,IAAiB,CAAA;;;;KAKvD,YAAA,cAA0B,aAAA,wBAAqC,OAAA,CACnE,IAAA;EAAA,SACW,IAAA,EAAM,GAAA;AAAA;;;;KAMb,cAAA,cAA4B,aAAA,wBAAqC,YAAA,CACrE,IAAA,EACA,GAAA;;;;;;AARoB;;;;KAoBT,cAAA,cAA4B,aAAA,gCACjC,cAAA,CAAe,IAAA,EAAM,GAAA,aAAgB,CAAA"}
|
package/dist/contracts/coin.d.ts
CHANGED
|
@@ -1,25 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* The Coin contract is a built-in native contract with no WASM ABI file.
|
|
5
|
-
* It differs from WASM contracts:
|
|
6
|
-
* - First arg (recipient) is raw binary Uint8Array from fromBase58(), not a UTF-8 string
|
|
7
|
-
* - Amount requires toAtomicAma() conversion
|
|
8
|
-
*
|
|
9
|
-
* This module provides a dedicated builder that handles these special encodings
|
|
10
|
-
* while returning a standard ContractCall for uniform consumption by TransactionBuilder.
|
|
11
|
-
*/
|
|
12
|
-
import type { ContractCall } from './contract-call';
|
|
1
|
+
import { ContractCall } from "./contract-call.js";
|
|
2
|
+
|
|
3
|
+
//#region src/contracts/coin.d.ts
|
|
13
4
|
/**
|
|
14
5
|
* Parameters for building a Coin transfer call
|
|
15
6
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
7
|
+
interface CoinTransferParams {
|
|
8
|
+
/** Base58-encoded recipient address */
|
|
9
|
+
recipient: string;
|
|
10
|
+
/** Amount in human-readable units (e.g. 10.5 AMA) */
|
|
11
|
+
amount: number | string;
|
|
12
|
+
/** Token symbol (e.g. 'AMA') */
|
|
13
|
+
symbol: string;
|
|
23
14
|
}
|
|
24
15
|
/**
|
|
25
16
|
* Build a Coin transfer ContractCall.
|
|
@@ -38,5 +29,7 @@ export interface CoinTransferParams {
|
|
|
38
29
|
* TransactionBuilder.signCall(privateKey, call)
|
|
39
30
|
* ```
|
|
40
31
|
*/
|
|
41
|
-
|
|
32
|
+
declare function buildCoinTransfer(params: CoinTransferParams): ContractCall;
|
|
33
|
+
//#endregion
|
|
34
|
+
export { CoinTransferParams, buildCoinTransfer };
|
|
42
35
|
//# sourceMappingURL=coin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coin.d.ts","
|
|
1
|
+
{"version":3,"file":"coin.d.ts","names":[],"sources":["../../src/contracts/coin.ts"],"mappings":";;;AA6CA;;;AAAA,UA1BiB,kBAAA;EA0ByB;EAxBzC,SAAA;EAwB8D;EAtB9D,MAAA;EAsB0E;EApB1E,MAAA;AAAA;;;;;;;;;;;;;;;;;;iBAoBe,iBAAA,CAAkB,MAAA,EAAQ,kBAAA,GAAqB,YAAA"}
|
package/dist/contracts/coin.js
CHANGED
|
@@ -1,42 +1,46 @@
|
|
|
1
|
+
import { fromBase58 } from "../encoding.js";
|
|
2
|
+
import { toAtomicAma } from "../conversion.js";
|
|
3
|
+
//#region src/contracts/coin.ts
|
|
1
4
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import { toAtomicAma } from '../conversion';
|
|
13
|
-
import { fromBase58 } from '../encoding';
|
|
5
|
+
* Coin Contract (Special Case)
|
|
6
|
+
*
|
|
7
|
+
* The Coin contract is a built-in native contract with no WASM ABI file.
|
|
8
|
+
* It differs from WASM contracts:
|
|
9
|
+
* - First arg (recipient) is raw binary Uint8Array from fromBase58(), not a UTF-8 string
|
|
10
|
+
* - Amount requires toAtomicAma() conversion
|
|
11
|
+
*
|
|
12
|
+
* This module provides a dedicated builder that handles these special encodings
|
|
13
|
+
* while returning a standard ContractCall for uniform consumption by TransactionBuilder.
|
|
14
|
+
*/
|
|
14
15
|
/**
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
16
|
+
* Build a Coin transfer ContractCall.
|
|
17
|
+
*
|
|
18
|
+
* Handles the special encoding requirements of the Coin contract:
|
|
19
|
+
* - recipient is decoded from Base58 to raw Uint8Array
|
|
20
|
+
* - amount is converted to atomic units via toAtomicAma()
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* const call = buildCoinTransfer({
|
|
25
|
+
* recipient: '5Kd3N...',
|
|
26
|
+
* amount: 10.5,
|
|
27
|
+
* symbol: 'AMA'
|
|
28
|
+
* })
|
|
29
|
+
* TransactionBuilder.signCall(privateKey, call)
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
function buildCoinTransfer(params) {
|
|
33
|
+
return {
|
|
34
|
+
contract: "Coin",
|
|
35
|
+
method: "transfer",
|
|
36
|
+
args: [
|
|
37
|
+
fromBase58(params.recipient),
|
|
38
|
+
toAtomicAma(params.amount).toString(),
|
|
39
|
+
params.symbol
|
|
40
|
+
]
|
|
41
|
+
};
|
|
41
42
|
}
|
|
43
|
+
//#endregion
|
|
44
|
+
export { buildCoinTransfer };
|
|
45
|
+
|
|
42
46
|
//# sourceMappingURL=coin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coin.js","
|
|
1
|
+
{"version":3,"file":"coin.js","names":[],"sources":["../../src/contracts/coin.ts"],"sourcesContent":["/**\n * Coin Contract (Special Case)\n *\n * The Coin contract is a built-in native contract with no WASM ABI file.\n * It differs from WASM contracts:\n * - First arg (recipient) is raw binary Uint8Array from fromBase58(), not a UTF-8 string\n * - Amount requires toAtomicAma() conversion\n *\n * This module provides a dedicated builder that handles these special encodings\n * while returning a standard ContractCall for uniform consumption by TransactionBuilder.\n */\n\nimport { toAtomicAma } from '../conversion'\nimport { fromBase58 } from '../encoding'\nimport type { ContractCall } from './contract-call'\n\n/**\n * Parameters for building a Coin transfer call\n */\nexport interface CoinTransferParams {\n\t/** Base58-encoded recipient address */\n\trecipient: string\n\t/** Amount in human-readable units (e.g. 10.5 AMA) */\n\tamount: number | string\n\t/** Token symbol (e.g. 'AMA') */\n\tsymbol: string\n}\n\n/**\n * Build a Coin transfer ContractCall.\n *\n * Handles the special encoding requirements of the Coin contract:\n * - recipient is decoded from Base58 to raw Uint8Array\n * - amount is converted to atomic units via toAtomicAma()\n *\n * @example\n * ```ts\n * const call = buildCoinTransfer({\n * recipient: '5Kd3N...',\n * amount: 10.5,\n * symbol: 'AMA'\n * })\n * TransactionBuilder.signCall(privateKey, call)\n * ```\n */\nexport function buildCoinTransfer(params: CoinTransferParams): ContractCall {\n\treturn {\n\t\tcontract: 'Coin',\n\t\tmethod: 'transfer',\n\t\targs: [fromBase58(params.recipient), toAtomicAma(params.amount).toString(), params.symbol]\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,SAAgB,kBAAkB,QAA0C;CAC3E,OAAO;EACN,UAAU;EACV,QAAQ;EACR,MAAM;GAAC,WAAW,OAAO,UAAU;GAAE,YAAY,OAAO,OAAO,CAAC,UAAU;GAAE,OAAO;GAAO;EAC1F"}
|