Skip to content

Commit e80dead

Browse files
committed
normalize some constants (#753)
1 parent d87ee6b commit e80dead

File tree

8 files changed

+46
-23
lines changed

8 files changed

+46
-23
lines changed

packages/kiosk/src/query/transfer-policy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import type { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
5-
import { fromBase64, isValidSuiAddress } from '@mysten/sui/utils';
5+
import { fromBase64, isValidSuiAddress, SUI_FRAMEWORK_ADDRESS } from '@mysten/sui/utils';
66

77
import '../bcs.js';
88

@@ -114,7 +114,7 @@ export async function queryOwnedTransferPolicies(
114114
{
115115
MoveModule: {
116116
module: 'transfer_policy',
117-
package: '0x2',
117+
package: SUI_FRAMEWORK_ADDRESS,
118118
},
119119
},
120120
],

packages/kiosk/src/types/kiosk.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ import type { TransactionArgument } from '@mysten/sui/transactions';
1010

1111
import type { ObjectArgument } from './index.js';
1212

13+
import { SUI_FRAMEWORK_ADDRESS } from '@mysten/sui/utils';
14+
1315
/** The Kiosk module. */
14-
export const KIOSK_MODULE = '0x2::kiosk';
16+
export const KIOSK_MODULE = `${SUI_FRAMEWORK_ADDRESS}::kiosk`;
1517

1618
/** The Kiosk type. */
1719
export const KIOSK_TYPE = `${KIOSK_MODULE}::Kiosk`;

packages/kiosk/src/types/transfer-policy.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import type { Transaction, TransactionObjectArgument } from '@mysten/sui/transac
77
import type { KioskClient } from '../client/kiosk-client.js';
88
import type { ObjectArgument } from './index.js';
99

10+
import { SUI_FRAMEWORK_ADDRESS } from '@mysten/sui/utils';
11+
1012
/** The Transfer Policy module. */
11-
export const TRANSFER_POLICY_MODULE = '0x2::transfer_policy';
13+
export const TRANSFER_POLICY_MODULE = `${SUI_FRAMEWORK_ADDRESS}::transfer_policy`;
1214

1315
/** Name of the event emitted when a TransferPolicy for T is created. */
1416
export const TRANSFER_POLICY_CREATED_EVENT = `${TRANSFER_POLICY_MODULE}::TransferPolicyCreated`;

packages/sui/src/jsonRpc/json-rpc-resolver.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33

44
import { parse } from 'valibot';
55

6-
import { normalizeSuiAddress, normalizeSuiObjectId, SUI_TYPE_ARG } from '../utils/index.js';
6+
import {
7+
normalizeSuiAddress,
8+
normalizeSuiObjectId,
9+
SUI_FRAMEWORK_ADDRESS,
10+
SUI_TYPE_ARG,
11+
} from '../utils/index.js';
712
import { ObjectRefSchema } from '../transactions/data/internal.js';
813
import type { CallArg, Command, OpenMoveTypeSignature } from '../transactions/data/internal.js';
914
import { Inputs } from '../transactions/Inputs.js';
@@ -413,7 +418,7 @@ function isReceivingType(type: OpenMoveTypeSignature): boolean {
413418
}
414419

415420
return (
416-
type.body.datatype.package === '0x2' &&
421+
normalizeSuiAddress(type.body.datatype.package) === SUI_FRAMEWORK_ADDRESS &&
417422
type.body.datatype.module === 'transfer' &&
418423
type.body.datatype.type === 'Receiving'
419424
);

packages/sui/src/transactions/object.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33

44
import type { Transaction, TransactionObjectInput } from './Transaction.js';
55
import { Inputs } from './Inputs.js';
6+
import {
7+
MOVE_STDLIB_ADDRESS,
8+
SUI_CLOCK_OBJECT_ID,
9+
SUI_DENY_LIST_OBJECT_ID,
10+
SUI_RANDOM_OBJECT_ID,
11+
SUI_SYSTEM_STATE_OBJECT_ID,
12+
} from '../utils/index.js';
613

714
export function createObjectMethods<T>(makeObject: (value: TransactionObjectInput) => T) {
815
function object(value: TransactionObjectInput) {
@@ -15,7 +22,7 @@ export function createObjectMethods<T>(makeObject: (value: TransactionObjectInpu
1522
if (mutable !== undefined) {
1623
return object(
1724
Inputs.SharedObjectRef({
18-
objectId: '0x5',
25+
objectId: SUI_SYSTEM_STATE_OBJECT_ID,
1926
initialSharedVersion: 1,
2027
mutable,
2128
}),
@@ -25,15 +32,15 @@ export function createObjectMethods<T>(makeObject: (value: TransactionObjectInpu
2532
return object({
2633
$kind: 'UnresolvedObject',
2734
UnresolvedObject: {
28-
objectId: '0x5',
35+
objectId: SUI_SYSTEM_STATE_OBJECT_ID,
2936
initialSharedVersion: 1,
3037
},
3138
});
3239
};
3340
object.clock = () =>
3441
object(
3542
Inputs.SharedObjectRef({
36-
objectId: '0x6',
43+
objectId: SUI_CLOCK_OBJECT_ID,
3744
initialSharedVersion: 1,
3845
mutable: false,
3946
}),
@@ -42,15 +49,15 @@ export function createObjectMethods<T>(makeObject: (value: TransactionObjectInpu
4249
object({
4350
$kind: 'UnresolvedObject',
4451
UnresolvedObject: {
45-
objectId: '0x8',
52+
objectId: SUI_RANDOM_OBJECT_ID,
4653
mutable: false,
4754
},
4855
});
4956
object.denyList = (options?: { mutable?: boolean }) => {
5057
return object({
5158
$kind: 'UnresolvedObject',
5259
UnresolvedObject: {
53-
objectId: '0x403',
60+
objectId: SUI_DENY_LIST_OBJECT_ID,
5461
mutable: options?.mutable,
5562
},
5663
});
@@ -60,7 +67,7 @@ export function createObjectMethods<T>(makeObject: (value: TransactionObjectInpu
6067
(tx: Transaction) =>
6168
tx.moveCall({
6269
typeArguments: [type],
63-
target: `0x1::option::${value === null ? 'none' : 'some'}`,
70+
target: `${MOVE_STDLIB_ADDRESS}::option::${value === null ? 'none' : 'some'}`,
6471
arguments: value === null ? [] : [tx.object(value)],
6572
});
6673

packages/sui/src/transactions/serializer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function isTxContext(param: OpenMoveTypeSignature): boolean {
2727

2828
return (
2929
!!struct &&
30-
normalizeSuiAddress(struct.package) === normalizeSuiAddress('0x2') &&
30+
normalizeSuiAddress(struct.package) === SUI_FRAMEWORK_ADDRESS &&
3131
struct.module === 'tx_context' &&
3232
struct.type === 'TxContext'
3333
);
@@ -72,7 +72,7 @@ export function getPureBcsSchema(typeSignature: OpenMoveTypeSignatureBody): BcsT
7272
if ('datatype' in typeSignature) {
7373
const pkg = normalizeSuiAddress(typeSignature.datatype.package);
7474

75-
if (pkg === normalizeSuiAddress(MOVE_STDLIB_ADDRESS)) {
75+
if (pkg === MOVE_STDLIB_ADDRESS) {
7676
if (
7777
typeSignature.datatype.module === STD_ASCII_MODULE_NAME &&
7878
typeSignature.datatype.type === STD_ASCII_STRUCT_NAME
@@ -97,7 +97,7 @@ export function getPureBcsSchema(typeSignature: OpenMoveTypeSignatureBody): BcsT
9797
}
9898

9999
if (
100-
pkg === normalizeSuiAddress(SUI_FRAMEWORK_ADDRESS) &&
100+
pkg === SUI_FRAMEWORK_ADDRESS &&
101101
typeSignature.datatype.module === OBJECT_MODULE_NAME &&
102102
typeSignature.datatype.type === ID_STRUCT_NAME
103103
) {
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
// Copyright (c) Mysten Labs, Inc.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
import { normalizeSuiObjectId } from './sui-types.js';
5-
64
export const SUI_DECIMALS = 9;
75
export const MIST_PER_SUI = BigInt(1000000000);
86

9-
export const MOVE_STDLIB_ADDRESS = '0x1';
10-
export const SUI_FRAMEWORK_ADDRESS = '0x2';
11-
export const SUI_SYSTEM_ADDRESS = '0x3';
12-
export const SUI_CLOCK_OBJECT_ID = normalizeSuiObjectId('0x6');
7+
export const MOVE_STDLIB_ADDRESS =
8+
'0x0000000000000000000000000000000000000000000000000000000000000001';
9+
export const SUI_FRAMEWORK_ADDRESS =
10+
'0x0000000000000000000000000000000000000000000000000000000000000002';
11+
export const SUI_SYSTEM_ADDRESS =
12+
'0x0000000000000000000000000000000000000000000000000000000000000003';
13+
export const SUI_CLOCK_OBJECT_ID =
14+
'0x0000000000000000000000000000000000000000000000000000000000000006';
1315
export const SUI_SYSTEM_MODULE_NAME = 'sui_system';
1416
export const SUI_TYPE_ARG = `${SUI_FRAMEWORK_ADDRESS}::sui::SUI`;
15-
export const SUI_SYSTEM_STATE_OBJECT_ID: string = normalizeSuiObjectId('0x5');
16-
export const SUI_RANDOM_OBJECT_ID = normalizeSuiObjectId('0x8');
17+
export const SUI_SYSTEM_STATE_OBJECT_ID =
18+
'0x0000000000000000000000000000000000000000000000000000000000000005';
19+
export const SUI_RANDOM_OBJECT_ID =
20+
'0x0000000000000000000000000000000000000000000000000000000000000008';
21+
export const SUI_DENY_LIST_OBJECT_ID =
22+
'0x0000000000000000000000000000000000000000000000000000000000000403';

packages/sui/src/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export {
2727
SUI_TYPE_ARG,
2828
SUI_SYSTEM_STATE_OBJECT_ID,
2929
SUI_RANDOM_OBJECT_ID,
30+
SUI_DENY_LIST_OBJECT_ID,
3031
} from './constants.js';
3132

3233
export { isValidNamedPackage, isValidNamedType } from './move-registry.js';

0 commit comments

Comments
 (0)