Skip to content

Commit 8692aa2

Browse files
committed
Migrate suins to sdk-v2
1 parent b7a6ae4 commit 8692aa2

File tree

116 files changed

+12461
-349
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+12461
-349
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
'@mysten/suins': major
3+
---
4+
5+
Update SuinsClient to use ClientWithCoreApi for transport-agnostic client support (JSON-RPC, GraphQL, gRPC).
6+
7+
**Breaking changes:**
8+
9+
- `SuinsClient` now requires a client implementing `ClientWithCoreApi` instead of `SuiClient`
10+
- Package ID extraction now correctly uses `upgrade_cap.package` from state objects instead of object type
11+
12+
**Migration:**
13+
14+
```diff
15+
- import { SuiClient, getFullnodeUrl } from '@mysten/sui/client';
16+
+ import { SuiJsonRpcClient, getJsonRpcFullnodeUrl } from '@mysten/sui/jsonRpc';
17+
import { SuinsClient } from '@mysten/suins';
18+
19+
- const suiClient = new SuiClient({ url: getFullnodeUrl('mainnet') });
20+
+ const suiClient = new SuiJsonRpcClient({
21+
+ url: getJsonRpcFullnodeUrl('mainnet'),
22+
+ network: 'mainnet',
23+
+ });
24+
25+
const suinsClient = new SuinsClient({
26+
client: suiClient,
27+
network: 'mainnet',
28+
});
29+
```
30+
31+
This change allows SuinsClient to work with any Sui client implementation (JSON-RPC, GraphQL, or gRPC).

packages/docs/content/sui/migrations/sui-2.0.mdx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,3 +387,51 @@ If you were using the plugin with `@mysten/mvr-static`:
387387

388388
The client will now automatically resolve `.move` names in transactions using the configured
389389
overrides or by querying the MVR API if no override is provided.
390+
391+
## @mysten/suins: ClientWithCoreApi Support
392+
393+
The `@mysten/suins` package now uses the transport-agnostic `ClientWithCoreApi` interface, allowing
394+
it to work with any Sui client implementation (JSON-RPC, GraphQL, or gRPC).
395+
396+
**Breaking changes:**
397+
398+
- `SuinsClient` now requires a client implementing `ClientWithCoreApi` instead of `SuiClient`
399+
- Internal package ID resolution now correctly extracts `upgrade_cap.package` from state objects
400+
401+
**Migration:**
402+
403+
Update your imports and client initialization:
404+
405+
```diff
406+
- import { SuiClient, getFullnodeUrl } from '@mysten/sui/client';
407+
+ import { SuiJsonRpcClient, getJsonRpcFullnodeUrl } from '@mysten/sui/jsonRpc';
408+
import { SuinsClient } from '@mysten/suins';
409+
410+
- const suiClient = new SuiClient({ url: getFullnodeUrl('mainnet') });
411+
+ const suiClient = new SuiJsonRpcClient({
412+
+ url: getJsonRpcFullnodeUrl('mainnet'),
413+
+ network: 'mainnet',
414+
+ });
415+
416+
const suinsClient = new SuinsClient({
417+
client: suiClient,
418+
network: 'mainnet',
419+
});
420+
```
421+
422+
You can also use GraphQL or gRPC clients:
423+
424+
```ts
425+
import { SuiGraphQLClient } from '@mysten/sui/graphql';
426+
import { SuinsClient } from '@mysten/suins';
427+
428+
const graphqlClient = new SuiGraphQLClient({
429+
url: 'https://sui-mainnet.mystenlabs.com/graphql',
430+
network: 'mainnet',
431+
});
432+
433+
const suinsClient = new SuinsClient({
434+
client: graphqlClient,
435+
network: 'mainnet',
436+
});
437+
```

packages/sui/src/client/core.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { normalizeStructTag, parseStructTag, SUI_ADDRESS_LENGTH } from '../utils
88
import { BaseClient } from './client.js';
99
import type { ClientWithExtensions, SuiClientTypes } from './types.js';
1010
import { MvrClient } from './mvr.js';
11+
import { bcs } from '../bcs/index.js';
1112

1213
export type ClientWithCoreApi = ClientWithExtensions<{
1314
core: CoreClient;
@@ -163,6 +164,34 @@ export abstract class CoreClient extends BaseClient implements SuiClientTypes.Tr
163164
};
164165
}
165166

167+
async getDynamicObjectField<Include extends SuiClientTypes.ObjectInclude = object>(
168+
options: SuiClientTypes.GetDynamicObjectFieldOptions<Include>,
169+
): Promise<SuiClientTypes.GetDynamicObjectFieldResponse<Include>> {
170+
const resolvedNameType = (
171+
await this.core.mvr.resolveType({
172+
type: options.name.type,
173+
})
174+
).type;
175+
const wrappedType = `0x2::dynamic_object_field::Wrapper<${resolvedNameType}>`;
176+
177+
const { dynamicField } = await this.getDynamicField({
178+
parentId: options.parentId,
179+
name: {
180+
type: wrappedType,
181+
bcs: options.name.bcs,
182+
},
183+
signal: options.signal,
184+
});
185+
186+
const { object } = await this.getObject({
187+
objectId: bcs.Address.parse(dynamicField.value.bcs),
188+
signal: options.signal,
189+
include: options.include,
190+
});
191+
192+
return { object };
193+
}
194+
166195
async waitForTransaction<Include extends SuiClientTypes.TransactionInclude = object>({
167196
signal,
168197
timeout = 60 * 1000,

packages/sui/src/client/types.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,18 @@ export namespace SuiClientTypes {
166166
};
167167
}
168168

169+
export interface GetDynamicObjectFieldOptions<
170+
Include extends ObjectInclude = {},
171+
> extends CoreClientMethodOptions {
172+
parentId: string;
173+
name: DynamicFieldName;
174+
include?: Include;
175+
}
176+
177+
export interface GetDynamicObjectFieldResponse<out Include extends ObjectInclude = {}> {
178+
object: Object<Include>;
179+
}
180+
169181
export interface DynamicFieldName {
170182
type: string;
171183
bcs: Uint8Array;

packages/suins/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"src"
2828
],
2929
"scripts": {
30+
"codegen": "sui-ts-codegen generate && pnpm lint:fix",
3031
"clean": "rm -rf tsconfig.tsbuildinfo ./dist",
3132
"build": "build-package",
3233
"prettier:check": "prettier -c --ignore-unknown .",
@@ -47,6 +48,7 @@
4748
},
4849
"devDependencies": {
4950
"@mysten/build-scripts": "workspace:*",
51+
"@mysten/codegen": "workspace:*",
5052
"@types/tmp": "^0.2.6",
5153
"ts-retry-promise": "^0.8.1",
5254
"typescript": "^5.9.3",
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/**************************************************************
2+
* THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *
3+
**************************************************************/
4+
import { MoveStruct, normalizeMoveArguments, type RawTransactionArgument } from '../utils/index.js';
5+
import { bcs } from '@mysten/sui/bcs';
6+
import { type Transaction } from '@mysten/sui/transactions';
7+
import * as price_info from './price_info.js';
8+
const $moduleName =
9+
'0xabf837e98c26087cba0883c0a7a28326b1fa3c5e1e2c5abdb486f9e8f594c837::batch_price_attestation';
10+
export const Header = new MoveStruct({
11+
name: `${$moduleName}::Header`,
12+
fields: {
13+
magic: bcs.u64(),
14+
version_major: bcs.u64(),
15+
version_minor: bcs.u64(),
16+
header_size: bcs.u64(),
17+
payload_id: bcs.u8(),
18+
},
19+
});
20+
export const BatchPriceAttestation = new MoveStruct({
21+
name: `${$moduleName}::BatchPriceAttestation`,
22+
fields: {
23+
header: Header,
24+
attestation_size: bcs.u64(),
25+
attestation_count: bcs.u64(),
26+
price_infos: bcs.vector(price_info.PriceInfo),
27+
},
28+
});
29+
export interface DestroyOptions {
30+
package?: string;
31+
arguments: [RawTransactionArgument<string>];
32+
}
33+
export function destroy(options: DestroyOptions) {
34+
const packageAddress =
35+
options.package ?? '0xabf837e98c26087cba0883c0a7a28326b1fa3c5e1e2c5abdb486f9e8f594c837';
36+
const argumentsTypes = [
37+
`${packageAddress}::batch_price_attestation::BatchPriceAttestation`,
38+
] satisfies string[];
39+
return (tx: Transaction) =>
40+
tx.moveCall({
41+
package: packageAddress,
42+
module: 'batch_price_attestation',
43+
function: 'destroy',
44+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
45+
});
46+
}
47+
export interface GetAttestationCountOptions {
48+
package?: string;
49+
arguments: [RawTransactionArgument<string>];
50+
}
51+
export function getAttestationCount(options: GetAttestationCountOptions) {
52+
const packageAddress =
53+
options.package ?? '0xabf837e98c26087cba0883c0a7a28326b1fa3c5e1e2c5abdb486f9e8f594c837';
54+
const argumentsTypes = [
55+
`${packageAddress}::batch_price_attestation::BatchPriceAttestation`,
56+
] satisfies string[];
57+
return (tx: Transaction) =>
58+
tx.moveCall({
59+
package: packageAddress,
60+
module: 'batch_price_attestation',
61+
function: 'get_attestation_count',
62+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
63+
});
64+
}
65+
export interface GetPriceInfoOptions {
66+
package?: string;
67+
arguments: [RawTransactionArgument<string>, RawTransactionArgument<number | bigint>];
68+
}
69+
export function getPriceInfo(options: GetPriceInfoOptions) {
70+
const packageAddress =
71+
options.package ?? '0xabf837e98c26087cba0883c0a7a28326b1fa3c5e1e2c5abdb486f9e8f594c837';
72+
const argumentsTypes = [
73+
`${packageAddress}::batch_price_attestation::BatchPriceAttestation`,
74+
'u64',
75+
] satisfies string[];
76+
return (tx: Transaction) =>
77+
tx.moveCall({
78+
package: packageAddress,
79+
module: 'batch_price_attestation',
80+
function: 'get_price_info',
81+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
82+
});
83+
}
84+
export interface DeserializeOptions {
85+
package?: string;
86+
arguments: [RawTransactionArgument<number[]>];
87+
}
88+
export function deserialize(options: DeserializeOptions) {
89+
const packageAddress =
90+
options.package ?? '0xabf837e98c26087cba0883c0a7a28326b1fa3c5e1e2c5abdb486f9e8f594c837';
91+
const argumentsTypes = [
92+
'vector<u8>',
93+
'0x0000000000000000000000000000000000000000000000000000000000000002::clock::Clock',
94+
] satisfies string[];
95+
return (tx: Transaction) =>
96+
tx.moveCall({
97+
package: packageAddress,
98+
module: 'batch_price_attestation',
99+
function: 'deserialize',
100+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
101+
});
102+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**************************************************************
2+
* THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *
3+
**************************************************************/
4+
import { MoveStruct, normalizeMoveArguments, type RawTransactionArgument } from '../utils/index.js';
5+
import { bcs } from '@mysten/sui/bcs';
6+
import { type Transaction } from '@mysten/sui/transactions';
7+
import * as bytes32 from './deps/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/bytes32.js';
8+
const $moduleName =
9+
'0xabf837e98c26087cba0883c0a7a28326b1fa3c5e1e2c5abdb486f9e8f594c837::contract_upgrade';
10+
export const ContractUpgraded = new MoveStruct({
11+
name: `${$moduleName}::ContractUpgraded`,
12+
fields: {
13+
old_contract: bcs.Address,
14+
new_contract: bcs.Address,
15+
},
16+
});
17+
export const UpgradeContract = new MoveStruct({
18+
name: `${$moduleName}::UpgradeContract`,
19+
fields: {
20+
digest: bytes32.Bytes32,
21+
},
22+
});
23+
export interface AuthorizeUpgradeOptions {
24+
package?: string;
25+
arguments: [RawTransactionArgument<string>, RawTransactionArgument<string>];
26+
}
27+
export function authorizeUpgrade(options: AuthorizeUpgradeOptions) {
28+
const packageAddress =
29+
options.package ?? '0xabf837e98c26087cba0883c0a7a28326b1fa3c5e1e2c5abdb486f9e8f594c837';
30+
const argumentsTypes = [
31+
`${packageAddress}::state::State`,
32+
`${packageAddress}::governance::WormholeVAAVerificationReceipt`,
33+
] satisfies string[];
34+
return (tx: Transaction) =>
35+
tx.moveCall({
36+
package: packageAddress,
37+
module: 'contract_upgrade',
38+
function: 'authorize_upgrade',
39+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
40+
});
41+
}
42+
export interface CommitUpgradeOptions {
43+
package?: string;
44+
arguments: [RawTransactionArgument<string>, RawTransactionArgument<string>];
45+
}
46+
export function commitUpgrade(options: CommitUpgradeOptions) {
47+
const packageAddress =
48+
options.package ?? '0xabf837e98c26087cba0883c0a7a28326b1fa3c5e1e2c5abdb486f9e8f594c837';
49+
const argumentsTypes = [
50+
`${packageAddress}::state::State`,
51+
'0x0000000000000000000000000000000000000000000000000000000000000002::package::UpgradeReceipt',
52+
] satisfies string[];
53+
return (tx: Transaction) =>
54+
tx.moveCall({
55+
package: packageAddress,
56+
module: 'contract_upgrade',
57+
function: 'commit_upgrade',
58+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
59+
});
60+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**************************************************************
2+
* THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *
3+
**************************************************************/
4+
import { MoveStruct, normalizeMoveArguments, type RawTransactionArgument } from '../utils/index.js';
5+
import { bcs } from '@mysten/sui/bcs';
6+
import { type Transaction } from '@mysten/sui/transactions';
7+
import * as external_address from './deps/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/external_address.js';
8+
const $moduleName =
9+
'0xabf837e98c26087cba0883c0a7a28326b1fa3c5e1e2c5abdb486f9e8f594c837::data_source';
10+
export const DataSource = new MoveStruct({
11+
name: `${$moduleName}::DataSource`,
12+
fields: {
13+
emitter_chain: bcs.u64(),
14+
emitter_address: external_address.ExternalAddress,
15+
},
16+
});
17+
export interface ContainsOptions {
18+
package?: string;
19+
arguments: [RawTransactionArgument<string>, RawTransactionArgument<string>];
20+
}
21+
export function contains(options: ContainsOptions) {
22+
const packageAddress =
23+
options.package ?? '0xabf837e98c26087cba0883c0a7a28326b1fa3c5e1e2c5abdb486f9e8f594c837';
24+
const argumentsTypes = [
25+
'0x0000000000000000000000000000000000000000000000000000000000000002::object::UID',
26+
`${packageAddress}::data_source::DataSource`,
27+
] satisfies string[];
28+
return (tx: Transaction) =>
29+
tx.moveCall({
30+
package: packageAddress,
31+
module: 'data_source',
32+
function: 'contains',
33+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
34+
});
35+
}
36+
export interface EmitterChainOptions {
37+
package?: string;
38+
arguments: [RawTransactionArgument<string>];
39+
}
40+
export function emitterChain(options: EmitterChainOptions) {
41+
const packageAddress =
42+
options.package ?? '0xabf837e98c26087cba0883c0a7a28326b1fa3c5e1e2c5abdb486f9e8f594c837';
43+
const argumentsTypes = [`${packageAddress}::data_source::DataSource`] satisfies string[];
44+
return (tx: Transaction) =>
45+
tx.moveCall({
46+
package: packageAddress,
47+
module: 'data_source',
48+
function: 'emitter_chain',
49+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
50+
});
51+
}
52+
export interface EmitterAddressOptions {
53+
package?: string;
54+
arguments: [RawTransactionArgument<string>];
55+
}
56+
export function emitterAddress(options: EmitterAddressOptions) {
57+
const packageAddress =
58+
options.package ?? '0xabf837e98c26087cba0883c0a7a28326b1fa3c5e1e2c5abdb486f9e8f594c837';
59+
const argumentsTypes = [`${packageAddress}::data_source::DataSource`] satisfies string[];
60+
return (tx: Transaction) =>
61+
tx.moveCall({
62+
package: packageAddress,
63+
module: 'data_source',
64+
function: 'emitter_address',
65+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
66+
});
67+
}

0 commit comments

Comments
 (0)