Skip to content

Commit 14d0287

Browse files
committed
Migrate suins to sdk-v2
1 parent f3d438b commit 14d0287

File tree

128 files changed

+6074
-914
lines changed

Some content is hidden

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

128 files changed

+6074
-914
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-v2/.prettierignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

packages/suins-v2/README.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/suins-v2/package.json

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)