@dynamic-labs-sdk/sui 0.17.4 → 0.18.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/addSuiExtension/addSuiExtension.d.ts +1 -0
- package/dist/addSuiExtension/addSuiExtension.d.ts.map +1 -1
- package/dist/{addSuiWalletStandardExtension-CY4Oy8n9.cjs.js → addSuiWalletStandardExtension-BbYavi_8.cjs.js} +4 -2
- package/dist/addSuiWalletStandardExtension-BbYavi_8.cjs.js.map +1 -0
- package/dist/{addSuiWalletStandardExtension-DQsQYqI2.esm.js → addSuiWalletStandardExtension-gK5Q0m0_.esm.js} +4 -2
- package/dist/addSuiWalletStandardExtension-gK5Q0m0_.esm.js.map +1 -0
- package/dist/{addWaasSuiExtension-DPXZoCuF.cjs.js → addWaasSuiExtension-CwQ0nwyL.cjs.js} +4 -2
- package/dist/addWaasSuiExtension-CwQ0nwyL.cjs.js.map +1 -0
- package/dist/{addWaasSuiExtension-BlF_QRjF.esm.js → addWaasSuiExtension-Da_JPVtH.esm.js} +4 -2
- package/dist/addWaasSuiExtension-Da_JPVtH.esm.js.map +1 -0
- package/dist/getSuiClient/getSuiClient.d.ts +1 -0
- package/dist/getSuiClient/getSuiClient.d.ts.map +1 -1
- package/dist/index.cjs.js +8 -3
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +8 -3
- package/dist/index.esm.js.map +1 -1
- package/dist/isSuiNetworkProvider/isSuiNetworkProvider.d.ts +1 -0
- package/dist/isSuiNetworkProvider/isSuiNetworkProvider.d.ts.map +1 -1
- package/dist/isSuiWalletAccount/isSuiWalletAccount.d.ts +1 -0
- package/dist/isSuiWalletAccount/isSuiWalletAccount.d.ts.map +1 -1
- package/dist/isSuiWalletProvider/isSuiWalletProvider.d.ts +1 -0
- package/dist/isSuiWalletProvider/isSuiWalletProvider.d.ts.map +1 -1
- package/dist/registerSuiNetworkProviderBuilder/registerSuiNetworkProviderBuilder.d.ts +1 -0
- package/dist/registerSuiNetworkProviderBuilder/registerSuiNetworkProviderBuilder.d.ts.map +1 -1
- package/dist/signAndExecuteTransaction/signAndExecuteTransaction.d.ts +1 -0
- package/dist/signAndExecuteTransaction/signAndExecuteTransaction.d.ts.map +1 -1
- package/dist/signAndExecuteTransactionBlock/signAndExecuteTransactionBlock.d.ts +1 -0
- package/dist/signAndExecuteTransactionBlock/signAndExecuteTransactionBlock.d.ts.map +1 -1
- package/dist/signTransaction/signTransaction.d.ts +1 -0
- package/dist/signTransaction/signTransaction.d.ts.map +1 -1
- package/dist/signTransactionBlock/signTransactionBlock.d.ts +1 -0
- package/dist/signTransactionBlock/signTransactionBlock.d.ts.map +1 -1
- package/dist/{suiTransferAmount-6Ar3rw_C.esm.js → suiTransferAmount-CvuWrayy.esm.js} +11 -2
- package/dist/suiTransferAmount-CvuWrayy.esm.js.map +1 -0
- package/dist/{suiTransferAmount-BfmmXjZO.cjs.js → suiTransferAmount-CzH2HhdB.cjs.js} +11 -2
- package/dist/suiTransferAmount-CzH2HhdB.cjs.js.map +1 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/utils/createSuiNetworkProvider/createSuiNetworkProvider.d.ts +1 -0
- package/dist/utils/createSuiNetworkProvider/createSuiNetworkProvider.d.ts.map +1 -1
- package/dist/utils/fetchSuiBalance/fetchSuiBalance.d.ts +1 -0
- package/dist/utils/fetchSuiBalance/fetchSuiBalance.d.ts.map +1 -1
- package/dist/utils/suiExecuteCheckoutTransaction/suiExecuteCheckoutTransaction.d.ts +1 -0
- package/dist/utils/suiExecuteCheckoutTransaction/suiExecuteCheckoutTransaction.d.ts.map +1 -1
- package/dist/utils/suiTransferAmount/suiTransferAmount.d.ts +1 -0
- package/dist/utils/suiTransferAmount/suiTransferAmount.d.ts.map +1 -1
- package/dist/waas/addWaasSuiExtension/addWaasSuiExtension.d.ts +1 -0
- package/dist/waas/addWaasSuiExtension/addWaasSuiExtension.d.ts.map +1 -1
- package/dist/waas/utils/createWalletProviderForWaasSui/createWalletProviderForWaasSui.d.ts +1 -0
- package/dist/waas/utils/createWalletProviderForWaasSui/createWalletProviderForWaasSui.d.ts.map +1 -1
- package/dist/waas.cjs.js +2 -2
- package/dist/waas.esm.js +2 -2
- package/dist/walletStandard/addSuiWalletStandardExtension/addSuiWalletStandardExtension.d.ts +1 -0
- package/dist/walletStandard/addSuiWalletStandardExtension/addSuiWalletStandardExtension.d.ts.map +1 -1
- package/dist/walletStandard/utils/createWalletProviderFromSuiStandardWallet/createWalletProviderFromSuiStandardWallet.d.ts +1 -0
- package/dist/walletStandard/utils/createWalletProviderFromSuiStandardWallet/createWalletProviderFromSuiStandardWallet.d.ts.map +1 -1
- package/dist/walletStandard.cjs.js +2 -2
- package/dist/walletStandard.esm.js +2 -2
- package/package.json +4 -4
- package/dist/addSuiWalletStandardExtension-CY4Oy8n9.cjs.js.map +0 -1
- package/dist/addSuiWalletStandardExtension-DQsQYqI2.esm.js.map +0 -1
- package/dist/addWaasSuiExtension-BlF_QRjF.esm.js.map +0 -1
- package/dist/addWaasSuiExtension-DPXZoCuF.cjs.js.map +0 -1
- package/dist/suiTransferAmount-6Ar3rw_C.esm.js.map +0 -1
- package/dist/suiTransferAmount-BfmmXjZO.cjs.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signTransactionBlock.d.ts","sourceRoot":"","sources":["../../src/signTransactionBlock/signTransactionBlock.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAI5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,4BAA4B,CAAC;AAEhF,KAAK,0BAA0B,GAAG;IAChC,gBAAgB,EAAE,WAAW,CAAC;IAC9B,aAAa,EAAE,gBAAgB,CAAC;CACjC,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"signTransactionBlock.d.ts","sourceRoot":"","sources":["../../src/signTransactionBlock/signTransactionBlock.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAI5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,4BAA4B,CAAC;AAEhF,KAAK,0BAA0B,GAAG;IAChC,gBAAgB,EAAE,WAAW,CAAC;IAC9B,aAAa,EAAE,gBAAgB,CAAC;CACjC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,oBAAoB,wCACM,0BAA0B,gEAE9D,OAAO,CAAC,6BAA6B,CAiBvC,CAAC"}
|
|
@@ -6,10 +6,11 @@ import { Transaction } from "@mysten/sui/transactions";
|
|
|
6
6
|
|
|
7
7
|
//#region package.json
|
|
8
8
|
var name = "@dynamic-labs-sdk/sui";
|
|
9
|
-
var version = "0.
|
|
9
|
+
var version = "0.18.0";
|
|
10
10
|
|
|
11
11
|
//#endregion
|
|
12
12
|
//#region src/utils/fetchSuiBalance/fetchSuiBalance.ts
|
|
13
|
+
/** @not-instrumented */
|
|
13
14
|
const fetchSuiBalance = async ({ address, networkData }) => {
|
|
14
15
|
const balanceInMist = await new SuiClient({ url: networkData.rpcUrls.http[0] }).getBalance({ owner: address });
|
|
15
16
|
const balance = Number(balanceInMist.totalBalance) / Number(MIST_PER_SUI);
|
|
@@ -19,6 +20,7 @@ const fetchSuiBalance = async ({ address, networkData }) => {
|
|
|
19
20
|
|
|
20
21
|
//#endregion
|
|
21
22
|
//#region src/utils/createSuiNetworkProvider/createSuiNetworkProvider.ts
|
|
23
|
+
/** @not-instrumented */
|
|
22
24
|
const createSuiNetworkProvider = (networkData) => ({
|
|
23
25
|
...createBaseNetworkProvider("SUI", networkData),
|
|
24
26
|
getBalance: async ({ address }) => ({ balance: await fetchSuiBalance({
|
|
@@ -29,6 +31,7 @@ const createSuiNetworkProvider = (networkData) => ({
|
|
|
29
31
|
|
|
30
32
|
//#endregion
|
|
31
33
|
//#region src/registerSuiNetworkProviderBuilder/registerSuiNetworkProviderBuilder.ts
|
|
34
|
+
/** @not-instrumented */
|
|
32
35
|
const registerSuiNetworkProviderBuilder = (client) => {
|
|
33
36
|
const networkProviderBuilderRegistry = getNetworkProviderBuilderRegistry(client);
|
|
34
37
|
/**
|
|
@@ -48,11 +51,13 @@ const registerSuiNetworkProviderBuilder = (client) => {
|
|
|
48
51
|
*
|
|
49
52
|
* @param walletAccount - The wallet account to check.
|
|
50
53
|
* @returns True if the wallet account is a Sui wallet account, false otherwise.
|
|
54
|
+
* @not-instrumented
|
|
51
55
|
*/
|
|
52
56
|
const isSuiWalletAccount = (walletAccount) => walletAccount.chain === "SUI";
|
|
53
57
|
|
|
54
58
|
//#endregion
|
|
55
59
|
//#region src/isSuiWalletProvider/isSuiWalletProvider.ts
|
|
60
|
+
/** @not-instrumented */
|
|
56
61
|
const isSuiWalletProvider = (provider) => {
|
|
57
62
|
return provider.chain === "SUI";
|
|
58
63
|
};
|
|
@@ -73,6 +78,7 @@ const isSuiWalletProvider = (provider) => {
|
|
|
73
78
|
* @param params.onStepChange - Optional callback invoked with `'transaction'` when the execution step begins.
|
|
74
79
|
* @param client - The Dynamic client instance.
|
|
75
80
|
* @returns The transaction hash (digest).
|
|
81
|
+
* @not-instrumented
|
|
76
82
|
*/
|
|
77
83
|
const suiExecuteCheckoutTransaction = async ({ onStepChange, signingPayload, walletAccount }, client) => {
|
|
78
84
|
const walletProvider = getWalletProviderFromWalletAccount({ walletAccount }, client);
|
|
@@ -113,6 +119,7 @@ var NotSuiProviderError = class extends BaseError {
|
|
|
113
119
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
114
120
|
* @returns A promise that resolves to a SuiClient instance
|
|
115
121
|
* @throws NotSuiProviderError If the wallet account's provider is not a SUI provider
|
|
122
|
+
* @not-instrumented
|
|
116
123
|
*/
|
|
117
124
|
const getSuiClient = async ({ walletAccount }, client = getDefaultClient()) => {
|
|
118
125
|
const provider = getWalletProviderFromWalletAccount({ walletAccount }, client);
|
|
@@ -128,6 +135,7 @@ const getSuiClient = async ({ walletAccount }, client = getDefaultClient()) => {
|
|
|
128
135
|
* @param params.walletAccount - The wallet account to sign the transaction with
|
|
129
136
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
130
137
|
* @returns An object containing the signature and transaction bytes
|
|
138
|
+
* @not-instrumented
|
|
131
139
|
*/
|
|
132
140
|
const signAndExecuteTransaction = async ({ walletAccount, transaction }, client = getDefaultClient$1()) => {
|
|
133
141
|
const provider = getWalletProviderFromWalletAccount({ walletAccount }, client);
|
|
@@ -147,6 +155,7 @@ const SUI_DECIMALS = 9;
|
|
|
147
155
|
*
|
|
148
156
|
* For native SUI, converts the human-readable amount string to MIST (9 decimals).
|
|
149
157
|
* For tokens, fetches the user's coins of that type and splits from them.
|
|
158
|
+
* @not-instrumented
|
|
150
159
|
*/
|
|
151
160
|
const suiTransferAmount = async ({ amount, recipient, token, walletAccount }, client) => {
|
|
152
161
|
if (!isSuiWalletAccount(walletAccount)) throw new InvalidParamError("Wallet account is not a SUI wallet account");
|
|
@@ -179,4 +188,4 @@ const suiTransferAmount = async ({ amount, recipient, token, walletAccount }, cl
|
|
|
179
188
|
|
|
180
189
|
//#endregion
|
|
181
190
|
export { suiExecuteCheckoutTransaction as a, registerSuiNetworkProviderBuilder as c, NotSuiProviderError as i, name as l, signAndExecuteTransaction as n, isSuiWalletProvider as o, getSuiClient as r, isSuiWalletAccount as s, suiTransferAmount as t, version as u };
|
|
182
|
-
//# sourceMappingURL=suiTransferAmount-
|
|
191
|
+
//# sourceMappingURL=suiTransferAmount-CvuWrayy.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"suiTransferAmount-CvuWrayy.esm.js","names":["getDefaultClient"],"sources":["../package.json","../src/utils/fetchSuiBalance/fetchSuiBalance.ts","../src/utils/createSuiNetworkProvider/createSuiNetworkProvider.ts","../src/registerSuiNetworkProviderBuilder/registerSuiNetworkProviderBuilder.ts","../src/isSuiWalletAccount/isSuiWalletAccount.ts","../src/isSuiWalletProvider/isSuiWalletProvider.ts","../src/utils/suiExecuteCheckoutTransaction/suiExecuteCheckoutTransaction.ts","../src/errors/NotSuiProviderError/NotSuiProviderError.ts","../src/getSuiClient/getSuiClient.ts","../src/signAndExecuteTransaction/signAndExecuteTransaction.ts","../src/utils/suiTransferAmount/suiTransferAmount.ts"],"sourcesContent":["","import type { NetworkData } from '@dynamic-labs-sdk/client';\nimport { SuiClient } from '@mysten/sui/client';\nimport { MIST_PER_SUI } from '@mysten/sui/utils';\n\n/** @not-instrumented */\nexport const fetchSuiBalance = async ({\n address,\n networkData,\n}: {\n address: string;\n networkData: NetworkData;\n}): Promise<string | null> => {\n // Create a SuiClient using the provided RPC URL.\n const suiClient = new SuiClient({\n url: networkData.rpcUrls.http[0],\n });\n\n const balanceInMist = await suiClient.getBalance({\n owner: address,\n });\n\n // Balance comes back as MIST, 1 SUI = 1e9 MIST\n const balance = Number(balanceInMist.totalBalance) / Number(MIST_PER_SUI);\n\n if (Number.isNaN(balance)) {\n return null;\n }\n\n return balance.toString();\n};\n","import type { NetworkData } from '@dynamic-labs-sdk/client';\nimport { createBaseNetworkProvider } from '@dynamic-labs-sdk/client/core';\n\nimport type { SuiNetworkProvider } from '../../SuiNetworkProvider.types';\nimport { fetchSuiBalance } from '../fetchSuiBalance';\n\n/** @not-instrumented */\nexport const createSuiNetworkProvider = (\n networkData: NetworkData\n): SuiNetworkProvider => ({\n ...createBaseNetworkProvider('SUI', networkData),\n getBalance: async ({ address }) => ({\n balance: await fetchSuiBalance({\n address,\n networkData,\n }),\n }),\n});\n","import type { DynamicClient } from '@dynamic-labs-sdk/client';\nimport { getNetworkProviderBuilderRegistry } from '@dynamic-labs-sdk/client/core';\n\nimport { createSuiNetworkProvider } from '../utils/createSuiNetworkProvider';\n\n/** @not-instrumented */\nexport const registerSuiNetworkProviderBuilder = (\n client: DynamicClient\n): void => {\n const networkProviderBuilderRegistry =\n getNetworkProviderBuilderRegistry(client);\n\n /**\n * If the Sui network provider builder is already registered, return.\n */\n if (networkProviderBuilderRegistry.get().get('SUI')) {\n return;\n }\n\n networkProviderBuilderRegistry.register({\n builder: createSuiNetworkProvider,\n chain: 'SUI',\n });\n};\n","import type { WalletAccount } from '@dynamic-labs-sdk/client';\n\nimport type { SuiWalletAccount } from '../SuiWalletAccount.types';\n\n/**\n * Type guard function to check if a wallet account is a Sui wallet account.\n *\n * @param walletAccount - The wallet account to check.\n * @returns True if the wallet account is a Sui wallet account, false otherwise.\n * @not-instrumented\n */\nexport const isSuiWalletAccount = (\n walletAccount: WalletAccount\n): walletAccount is SuiWalletAccount => walletAccount.chain === 'SUI';\n","import type { WalletProvider } from '@dynamic-labs-sdk/client/core';\n\nimport type { SuiWalletProvider } from '../SuiWalletProvider.types';\n\n/** @not-instrumented */\nexport const isSuiWalletProvider = (\n provider: WalletProvider\n): provider is SuiWalletProvider => {\n return provider.chain === 'SUI';\n};\n","import {\n type DynamicClient,\n InvalidParamError,\n} from '@dynamic-labs-sdk/client';\nimport type {\n ExecuteCheckoutTransactionParams,\n ExecuteCheckoutTransactionResult,\n} from '@dynamic-labs-sdk/client/core';\nimport { getWalletProviderFromWalletAccount } from '@dynamic-labs-sdk/client/core';\nimport { Transaction } from '@mysten/sui/transactions';\n\nimport type { SuiSigningPayload } from '../../checkoutTransaction.types';\nimport { isSuiWalletAccount } from '../../isSuiWalletAccount';\nimport { isSuiWalletProvider } from '../../isSuiWalletProvider';\n\n/**\n * Executes a Sui checkout transaction by deserializing the base64-encoded\n * BCS transaction and sending it via the wallet provider's signAndExecuteTransaction.\n *\n * 1. Validates that the wallet account is a Sui wallet account\n * 2. Extracts and validates the serialized transaction from the signing payload\n * 3. Deserializes the transaction using Transaction.from()\n * 4. Signs and executes via the Sui wallet provider\n *\n * @param params.signingPayload - The signing payload containing `serializedTransaction`.\n * @param params.walletAccount - The wallet account used to sign and execute the transaction.\n * @param params.onStepChange - Optional callback invoked with `'transaction'` when the execution step begins.\n * @param client - The Dynamic client instance.\n * @returns The transaction hash (digest).\n * @not-instrumented\n */\nexport const suiExecuteCheckoutTransaction = async (\n {\n onStepChange,\n signingPayload,\n walletAccount,\n }: ExecuteCheckoutTransactionParams,\n client: DynamicClient\n): Promise<ExecuteCheckoutTransactionResult> => {\n const walletProvider = getWalletProviderFromWalletAccount(\n { walletAccount },\n client\n );\n\n if (\n !isSuiWalletAccount(walletAccount) ||\n !isSuiWalletProvider(walletProvider)\n ) {\n throw new InvalidParamError(\n 'Wallet account is not a Sui wallet account'\n );\n }\n\n const suiPayload = signingPayload as SuiSigningPayload;\n\n if (!suiPayload.serializedTransaction?.serializedTransaction) {\n throw new InvalidParamError(\n 'Signing payload is missing serialized transaction data'\n );\n }\n\n const { serializedTransaction: serializedTransactionStr } =\n suiPayload.serializedTransaction;\n\n const transaction = Transaction.from(serializedTransactionStr);\n\n onStepChange?.('transaction');\n\n const result = await walletProvider.signAndExecuteTransaction({\n transaction,\n walletAccount,\n });\n\n return { transactionHash: result.digest };\n};\n","import { BaseError } from '@dynamic-labs-sdk/client';\n\nexport class NotSuiProviderError extends BaseError {\n public readonly providerKey: string;\n\n constructor(params: { providerKey: string }) {\n super({\n cause: null,\n code: 'not_sui_provider_error',\n docsUrl: null,\n name: 'NotSuiProviderError',\n shortMessage: 'Provider is not a Sui wallet provider',\n });\n\n this.providerKey = params.providerKey;\n }\n}\n","import {\n getDefaultClient,\n getWalletProviderFromWalletAccount,\n} from '@dynamic-labs-sdk/client/core';\n\nimport { NotSuiProviderError } from '../errors/NotSuiProviderError';\nimport { isSuiWalletProvider } from '../isSuiWalletProvider';\nimport type { SuiWalletAccount } from '../SuiWalletAccount.types';\n\ntype GetSuiClientParams = {\n walletAccount: SuiWalletAccount;\n};\n\n/**\n * Retrieves a SuiClient from a wallet account.\n *\n * @param params.walletAccount - The wallet account to get the SuiClient for.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A promise that resolves to a SuiClient instance\n * @throws NotSuiProviderError If the wallet account's provider is not a SUI provider\n * @not-instrumented\n */\nexport const getSuiClient = async (\n { walletAccount }: GetSuiClientParams,\n client = getDefaultClient()\n) => {\n const provider = getWalletProviderFromWalletAccount(\n {\n walletAccount,\n },\n client\n );\n\n if (!isSuiWalletProvider(provider)) {\n throw new NotSuiProviderError({ providerKey: provider.key });\n }\n\n return provider.getSuiClient({ walletAccount });\n};\n","import { getDefaultClient } from '@dynamic-labs-sdk/client';\nimport { getWalletProviderFromWalletAccount } from '@dynamic-labs-sdk/client/core';\nimport type { Transaction } from '@mysten/sui/transactions';\n\nimport { NotSuiProviderError } from '../errors/NotSuiProviderError';\nimport { isSuiWalletProvider } from '../isSuiWalletProvider';\nimport type { SuiWalletAccount } from '../SuiWalletAccount.types';\nimport type { SuiSignAndExecuteTransactionResult } from '../SuiWalletProvider.types';\n\ntype SignAndExecuteTransactionParams = {\n transaction: Transaction;\n walletAccount: SuiWalletAccount;\n};\n\n/**\n * Signs and executes a Sui transaction\n * @param params.transaction - The transaction to sign and execute\n * @param params.walletAccount - The wallet account to sign the transaction with\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns An object containing the signature and transaction bytes\n * @not-instrumented\n */\nexport const signAndExecuteTransaction = async (\n { walletAccount, transaction }: SignAndExecuteTransactionParams,\n client = getDefaultClient()\n): Promise<SuiSignAndExecuteTransactionResult> => {\n const provider = getWalletProviderFromWalletAccount(\n {\n walletAccount,\n },\n client\n );\n\n if (!isSuiWalletProvider(provider)) {\n throw new NotSuiProviderError({ providerKey: provider.key });\n }\n\n transaction.setSender(walletAccount.address);\n\n return provider.signAndExecuteTransaction({ transaction, walletAccount });\n};\n","import type { DynamicClient } from '@dynamic-labs-sdk/client';\nimport { InvalidParamError } from '@dynamic-labs-sdk/client';\nimport {\n type TransferAmountParams,\n parseAmountToSmallestUnit,\n} from '@dynamic-labs-sdk/client/core';\nimport { Transaction } from '@mysten/sui/transactions';\n\nimport { getSuiClient } from '../../getSuiClient';\nimport { isSuiWalletAccount } from '../../isSuiWalletAccount';\nimport { signAndExecuteTransaction } from '../../signAndExecuteTransaction';\n\nconst SUI_DECIMALS = 9;\n\n/**\n * Transfers native SUI or a SUI token from one wallet to another.\n *\n * For native SUI, converts the human-readable amount string to MIST (9 decimals).\n * For tokens, fetches the user's coins of that type and splits from them.\n * @not-instrumented\n */\nexport const suiTransferAmount = async (\n { amount, recipient, token, walletAccount }: TransferAmountParams,\n client: DynamicClient\n): Promise<{ transactionHash: string }> => {\n if (!isSuiWalletAccount(walletAccount)) {\n throw new InvalidParamError('Wallet account is not a SUI wallet account');\n }\n\n const transaction = new Transaction();\n\n if (token?.address) {\n const suiClient = await getSuiClient({ walletAccount }, client);\n\n const { data: coins } = await suiClient.getCoins({\n coinType: token.address,\n owner: walletAccount.address,\n });\n\n if (coins.length === 0) {\n throw new InvalidParamError('Token not found');\n }\n\n const smallestUnit = parseAmountToSmallestUnit({\n amount,\n decimals: token.decimals,\n });\n\n const [coin] = transaction.splitCoins(coins[0].coinObjectId, [\n smallestUnit,\n ]);\n transaction.transferObjects([coin], recipient);\n } else {\n const mist = parseAmountToSmallestUnit({\n amount,\n decimals: SUI_DECIMALS,\n });\n\n const [coin] = transaction.splitCoins(transaction.gas, [mist]);\n transaction.transferObjects([coin], recipient);\n }\n\n const result = await signAndExecuteTransaction(\n { transaction, walletAccount },\n client\n );\n\n return { transactionHash: result.digest };\n};\n"],"mappings":";;;;;;;;;;;;;ACKA,MAAa,kBAAkB,OAAO,EACpC,SACA,kBAI4B;CAM5B,MAAM,gBAAgB,MAJJ,IAAI,UAAU,EAC9B,KAAK,YAAY,QAAQ,KAAK,IAC/B,CAAC,CAEoC,WAAW,EAC/C,OAAO,SACR,CAAC;CAGF,MAAM,UAAU,OAAO,cAAc,aAAa,GAAG,OAAO,aAAa;AAEzE,KAAI,OAAO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U;;AAQhD,QAAO,EAAE,kBALM,MAAM,0BACnB;EAAE;EAAa;EAAe,EAC9B,OACD,EAEgC,QAAQ"}
|
|
@@ -6,10 +6,11 @@ let _mysten_sui_transactions = require("@mysten/sui/transactions");
|
|
|
6
6
|
|
|
7
7
|
//#region package.json
|
|
8
8
|
var name = "@dynamic-labs-sdk/sui";
|
|
9
|
-
var version = "0.
|
|
9
|
+
var version = "0.18.0";
|
|
10
10
|
|
|
11
11
|
//#endregion
|
|
12
12
|
//#region src/utils/fetchSuiBalance/fetchSuiBalance.ts
|
|
13
|
+
/** @not-instrumented */
|
|
13
14
|
const fetchSuiBalance = async ({ address, networkData }) => {
|
|
14
15
|
const balanceInMist = await new _mysten_sui_client.SuiClient({ url: networkData.rpcUrls.http[0] }).getBalance({ owner: address });
|
|
15
16
|
const balance = Number(balanceInMist.totalBalance) / Number(_mysten_sui_utils.MIST_PER_SUI);
|
|
@@ -19,6 +20,7 @@ const fetchSuiBalance = async ({ address, networkData }) => {
|
|
|
19
20
|
|
|
20
21
|
//#endregion
|
|
21
22
|
//#region src/utils/createSuiNetworkProvider/createSuiNetworkProvider.ts
|
|
23
|
+
/** @not-instrumented */
|
|
22
24
|
const createSuiNetworkProvider = (networkData) => ({
|
|
23
25
|
...(0, _dynamic_labs_sdk_client_core.createBaseNetworkProvider)("SUI", networkData),
|
|
24
26
|
getBalance: async ({ address }) => ({ balance: await fetchSuiBalance({
|
|
@@ -29,6 +31,7 @@ const createSuiNetworkProvider = (networkData) => ({
|
|
|
29
31
|
|
|
30
32
|
//#endregion
|
|
31
33
|
//#region src/registerSuiNetworkProviderBuilder/registerSuiNetworkProviderBuilder.ts
|
|
34
|
+
/** @not-instrumented */
|
|
32
35
|
const registerSuiNetworkProviderBuilder = (client) => {
|
|
33
36
|
const networkProviderBuilderRegistry = (0, _dynamic_labs_sdk_client_core.getNetworkProviderBuilderRegistry)(client);
|
|
34
37
|
/**
|
|
@@ -48,11 +51,13 @@ const registerSuiNetworkProviderBuilder = (client) => {
|
|
|
48
51
|
*
|
|
49
52
|
* @param walletAccount - The wallet account to check.
|
|
50
53
|
* @returns True if the wallet account is a Sui wallet account, false otherwise.
|
|
54
|
+
* @not-instrumented
|
|
51
55
|
*/
|
|
52
56
|
const isSuiWalletAccount = (walletAccount) => walletAccount.chain === "SUI";
|
|
53
57
|
|
|
54
58
|
//#endregion
|
|
55
59
|
//#region src/isSuiWalletProvider/isSuiWalletProvider.ts
|
|
60
|
+
/** @not-instrumented */
|
|
56
61
|
const isSuiWalletProvider = (provider) => {
|
|
57
62
|
return provider.chain === "SUI";
|
|
58
63
|
};
|
|
@@ -73,6 +78,7 @@ const isSuiWalletProvider = (provider) => {
|
|
|
73
78
|
* @param params.onStepChange - Optional callback invoked with `'transaction'` when the execution step begins.
|
|
74
79
|
* @param client - The Dynamic client instance.
|
|
75
80
|
* @returns The transaction hash (digest).
|
|
81
|
+
* @not-instrumented
|
|
76
82
|
*/
|
|
77
83
|
const suiExecuteCheckoutTransaction = async ({ onStepChange, signingPayload, walletAccount }, client) => {
|
|
78
84
|
const walletProvider = (0, _dynamic_labs_sdk_client_core.getWalletProviderFromWalletAccount)({ walletAccount }, client);
|
|
@@ -113,6 +119,7 @@ var NotSuiProviderError = class extends _dynamic_labs_sdk_client.BaseError {
|
|
|
113
119
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
114
120
|
* @returns A promise that resolves to a SuiClient instance
|
|
115
121
|
* @throws NotSuiProviderError If the wallet account's provider is not a SUI provider
|
|
122
|
+
* @not-instrumented
|
|
116
123
|
*/
|
|
117
124
|
const getSuiClient = async ({ walletAccount }, client = (0, _dynamic_labs_sdk_client_core.getDefaultClient)()) => {
|
|
118
125
|
const provider = (0, _dynamic_labs_sdk_client_core.getWalletProviderFromWalletAccount)({ walletAccount }, client);
|
|
@@ -128,6 +135,7 @@ const getSuiClient = async ({ walletAccount }, client = (0, _dynamic_labs_sdk_cl
|
|
|
128
135
|
* @param params.walletAccount - The wallet account to sign the transaction with
|
|
129
136
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
130
137
|
* @returns An object containing the signature and transaction bytes
|
|
138
|
+
* @not-instrumented
|
|
131
139
|
*/
|
|
132
140
|
const signAndExecuteTransaction = async ({ walletAccount, transaction }, client = (0, _dynamic_labs_sdk_client.getDefaultClient)()) => {
|
|
133
141
|
const provider = (0, _dynamic_labs_sdk_client_core.getWalletProviderFromWalletAccount)({ walletAccount }, client);
|
|
@@ -147,6 +155,7 @@ const SUI_DECIMALS = 9;
|
|
|
147
155
|
*
|
|
148
156
|
* For native SUI, converts the human-readable amount string to MIST (9 decimals).
|
|
149
157
|
* For tokens, fetches the user's coins of that type and splits from them.
|
|
158
|
+
* @not-instrumented
|
|
150
159
|
*/
|
|
151
160
|
const suiTransferAmount = async ({ amount, recipient, token, walletAccount }, client) => {
|
|
152
161
|
if (!isSuiWalletAccount(walletAccount)) throw new _dynamic_labs_sdk_client.InvalidParamError("Wallet account is not a SUI wallet account");
|
|
@@ -238,4 +247,4 @@ Object.defineProperty(exports, 'version', {
|
|
|
238
247
|
return version;
|
|
239
248
|
}
|
|
240
249
|
});
|
|
241
|
-
//# sourceMappingURL=suiTransferAmount-
|
|
250
|
+
//# sourceMappingURL=suiTransferAmount-CzH2HhdB.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"suiTransferAmount-CzH2HhdB.cjs.js","names":["SuiClient","MIST_PER_SUI","InvalidParamError","Transaction","BaseError","InvalidParamError","Transaction"],"sources":["../package.json","../src/utils/fetchSuiBalance/fetchSuiBalance.ts","../src/utils/createSuiNetworkProvider/createSuiNetworkProvider.ts","../src/registerSuiNetworkProviderBuilder/registerSuiNetworkProviderBuilder.ts","../src/isSuiWalletAccount/isSuiWalletAccount.ts","../src/isSuiWalletProvider/isSuiWalletProvider.ts","../src/utils/suiExecuteCheckoutTransaction/suiExecuteCheckoutTransaction.ts","../src/errors/NotSuiProviderError/NotSuiProviderError.ts","../src/getSuiClient/getSuiClient.ts","../src/signAndExecuteTransaction/signAndExecuteTransaction.ts","../src/utils/suiTransferAmount/suiTransferAmount.ts"],"sourcesContent":["","import type { NetworkData } from '@dynamic-labs-sdk/client';\nimport { SuiClient } from '@mysten/sui/client';\nimport { MIST_PER_SUI } from '@mysten/sui/utils';\n\n/** @not-instrumented */\nexport const fetchSuiBalance = async ({\n address,\n networkData,\n}: {\n address: string;\n networkData: NetworkData;\n}): Promise<string | null> => {\n // Create a SuiClient using the provided RPC URL.\n const suiClient = new SuiClient({\n url: networkData.rpcUrls.http[0],\n });\n\n const balanceInMist = await suiClient.getBalance({\n owner: address,\n });\n\n // Balance comes back as MIST, 1 SUI = 1e9 MIST\n const balance = Number(balanceInMist.totalBalance) / Number(MIST_PER_SUI);\n\n if (Number.isNaN(balance)) {\n return null;\n }\n\n return balance.toString();\n};\n","import type { NetworkData } from '@dynamic-labs-sdk/client';\nimport { createBaseNetworkProvider } from '@dynamic-labs-sdk/client/core';\n\nimport type { SuiNetworkProvider } from '../../SuiNetworkProvider.types';\nimport { fetchSuiBalance } from '../fetchSuiBalance';\n\n/** @not-instrumented */\nexport const createSuiNetworkProvider = (\n networkData: NetworkData\n): SuiNetworkProvider => ({\n ...createBaseNetworkProvider('SUI', networkData),\n getBalance: async ({ address }) => ({\n balance: await fetchSuiBalance({\n address,\n networkData,\n }),\n }),\n});\n","import type { DynamicClient } from '@dynamic-labs-sdk/client';\nimport { getNetworkProviderBuilderRegistry } from '@dynamic-labs-sdk/client/core';\n\nimport { createSuiNetworkProvider } from '../utils/createSuiNetworkProvider';\n\n/** @not-instrumented */\nexport const registerSuiNetworkProviderBuilder = (\n client: DynamicClient\n): void => {\n const networkProviderBuilderRegistry =\n getNetworkProviderBuilderRegistry(client);\n\n /**\n * If the Sui network provider builder is already registered, return.\n */\n if (networkProviderBuilderRegistry.get().get('SUI')) {\n return;\n }\n\n networkProviderBuilderRegistry.register({\n builder: createSuiNetworkProvider,\n chain: 'SUI',\n });\n};\n","import type { WalletAccount } from '@dynamic-labs-sdk/client';\n\nimport type { SuiWalletAccount } from '../SuiWalletAccount.types';\n\n/**\n * Type guard function to check if a wallet account is a Sui wallet account.\n *\n * @param walletAccount - The wallet account to check.\n * @returns True if the wallet account is a Sui wallet account, false otherwise.\n * @not-instrumented\n */\nexport const isSuiWalletAccount = (\n walletAccount: WalletAccount\n): walletAccount is SuiWalletAccount => walletAccount.chain === 'SUI';\n","import type { WalletProvider } from '@dynamic-labs-sdk/client/core';\n\nimport type { SuiWalletProvider } from '../SuiWalletProvider.types';\n\n/** @not-instrumented */\nexport const isSuiWalletProvider = (\n provider: WalletProvider\n): provider is SuiWalletProvider => {\n return provider.chain === 'SUI';\n};\n","import {\n type DynamicClient,\n InvalidParamError,\n} from '@dynamic-labs-sdk/client';\nimport type {\n ExecuteCheckoutTransactionParams,\n ExecuteCheckoutTransactionResult,\n} from '@dynamic-labs-sdk/client/core';\nimport { getWalletProviderFromWalletAccount } from '@dynamic-labs-sdk/client/core';\nimport { Transaction } from '@mysten/sui/transactions';\n\nimport type { SuiSigningPayload } from '../../checkoutTransaction.types';\nimport { isSuiWalletAccount } from '../../isSuiWalletAccount';\nimport { isSuiWalletProvider } from '../../isSuiWalletProvider';\n\n/**\n * Executes a Sui checkout transaction by deserializing the base64-encoded\n * BCS transaction and sending it via the wallet provider's signAndExecuteTransaction.\n *\n * 1. Validates that the wallet account is a Sui wallet account\n * 2. Extracts and validates the serialized transaction from the signing payload\n * 3. Deserializes the transaction using Transaction.from()\n * 4. Signs and executes via the Sui wallet provider\n *\n * @param params.signingPayload - The signing payload containing `serializedTransaction`.\n * @param params.walletAccount - The wallet account used to sign and execute the transaction.\n * @param params.onStepChange - Optional callback invoked with `'transaction'` when the execution step begins.\n * @param client - The Dynamic client instance.\n * @returns The transaction hash (digest).\n * @not-instrumented\n */\nexport const suiExecuteCheckoutTransaction = async (\n {\n onStepChange,\n signingPayload,\n walletAccount,\n }: ExecuteCheckoutTransactionParams,\n client: DynamicClient\n): Promise<ExecuteCheckoutTransactionResult> => {\n const walletProvider = getWalletProviderFromWalletAccount(\n { walletAccount },\n client\n );\n\n if (\n !isSuiWalletAccount(walletAccount) ||\n !isSuiWalletProvider(walletProvider)\n ) {\n throw new InvalidParamError(\n 'Wallet account is not a Sui wallet account'\n );\n }\n\n const suiPayload = signingPayload as SuiSigningPayload;\n\n if (!suiPayload.serializedTransaction?.serializedTransaction) {\n throw new InvalidParamError(\n 'Signing payload is missing serialized transaction data'\n );\n }\n\n const { serializedTransaction: serializedTransactionStr } =\n suiPayload.serializedTransaction;\n\n const transaction = Transaction.from(serializedTransactionStr);\n\n onStepChange?.('transaction');\n\n const result = await walletProvider.signAndExecuteTransaction({\n transaction,\n walletAccount,\n });\n\n return { transactionHash: result.digest };\n};\n","import { BaseError } from '@dynamic-labs-sdk/client';\n\nexport class NotSuiProviderError extends BaseError {\n public readonly providerKey: string;\n\n constructor(params: { providerKey: string }) {\n super({\n cause: null,\n code: 'not_sui_provider_error',\n docsUrl: null,\n name: 'NotSuiProviderError',\n shortMessage: 'Provider is not a Sui wallet provider',\n });\n\n this.providerKey = params.providerKey;\n }\n}\n","import {\n getDefaultClient,\n getWalletProviderFromWalletAccount,\n} from '@dynamic-labs-sdk/client/core';\n\nimport { NotSuiProviderError } from '../errors/NotSuiProviderError';\nimport { isSuiWalletProvider } from '../isSuiWalletProvider';\nimport type { SuiWalletAccount } from '../SuiWalletAccount.types';\n\ntype GetSuiClientParams = {\n walletAccount: SuiWalletAccount;\n};\n\n/**\n * Retrieves a SuiClient from a wallet account.\n *\n * @param params.walletAccount - The wallet account to get the SuiClient for.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A promise that resolves to a SuiClient instance\n * @throws NotSuiProviderError If the wallet account's provider is not a SUI provider\n * @not-instrumented\n */\nexport const getSuiClient = async (\n { walletAccount }: GetSuiClientParams,\n client = getDefaultClient()\n) => {\n const provider = getWalletProviderFromWalletAccount(\n {\n walletAccount,\n },\n client\n );\n\n if (!isSuiWalletProvider(provider)) {\n throw new NotSuiProviderError({ providerKey: provider.key });\n }\n\n return provider.getSuiClient({ walletAccount });\n};\n","import { getDefaultClient } from '@dynamic-labs-sdk/client';\nimport { getWalletProviderFromWalletAccount } from '@dynamic-labs-sdk/client/core';\nimport type { Transaction } from '@mysten/sui/transactions';\n\nimport { NotSuiProviderError } from '../errors/NotSuiProviderError';\nimport { isSuiWalletProvider } from '../isSuiWalletProvider';\nimport type { SuiWalletAccount } from '../SuiWalletAccount.types';\nimport type { SuiSignAndExecuteTransactionResult } from '../SuiWalletProvider.types';\n\ntype SignAndExecuteTransactionParams = {\n transaction: Transaction;\n walletAccount: SuiWalletAccount;\n};\n\n/**\n * Signs and executes a Sui transaction\n * @param params.transaction - The transaction to sign and execute\n * @param params.walletAccount - The wallet account to sign the transaction with\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns An object containing the signature and transaction bytes\n * @not-instrumented\n */\nexport const signAndExecuteTransaction = async (\n { walletAccount, transaction }: SignAndExecuteTransactionParams,\n client = getDefaultClient()\n): Promise<SuiSignAndExecuteTransactionResult> => {\n const provider = getWalletProviderFromWalletAccount(\n {\n walletAccount,\n },\n client\n );\n\n if (!isSuiWalletProvider(provider)) {\n throw new NotSuiProviderError({ providerKey: provider.key });\n }\n\n transaction.setSender(walletAccount.address);\n\n return provider.signAndExecuteTransaction({ transaction, walletAccount });\n};\n","import type { DynamicClient } from '@dynamic-labs-sdk/client';\nimport { InvalidParamError } from '@dynamic-labs-sdk/client';\nimport {\n type TransferAmountParams,\n parseAmountToSmallestUnit,\n} from '@dynamic-labs-sdk/client/core';\nimport { Transaction } from '@mysten/sui/transactions';\n\nimport { getSuiClient } from '../../getSuiClient';\nimport { isSuiWalletAccount } from '../../isSuiWalletAccount';\nimport { signAndExecuteTransaction } from '../../signAndExecuteTransaction';\n\nconst SUI_DECIMALS = 9;\n\n/**\n * Transfers native SUI or a SUI token from one wallet to another.\n *\n * For native SUI, converts the human-readable amount string to MIST (9 decimals).\n * For tokens, fetches the user's coins of that type and splits from them.\n * @not-instrumented\n */\nexport const suiTransferAmount = async (\n { amount, recipient, token, walletAccount }: TransferAmountParams,\n client: DynamicClient\n): Promise<{ transactionHash: string }> => {\n if (!isSuiWalletAccount(walletAccount)) {\n throw new InvalidParamError('Wallet account is not a SUI wallet account');\n }\n\n const transaction = new Transaction();\n\n if (token?.address) {\n const suiClient = await getSuiClient({ walletAccount }, client);\n\n const { data: coins } = await suiClient.getCoins({\n coinType: token.address,\n owner: walletAccount.address,\n });\n\n if (coins.length === 0) {\n throw new InvalidParamError('Token not found');\n }\n\n const smallestUnit = parseAmountToSmallestUnit({\n amount,\n decimals: token.decimals,\n });\n\n const [coin] = transaction.splitCoins(coins[0].coinObjectId, [\n smallestUnit,\n ]);\n transaction.transferObjects([coin], recipient);\n } else {\n const mist = parseAmountToSmallestUnit({\n amount,\n decimals: SUI_DECIMALS,\n });\n\n const [coin] = transaction.splitCoins(transaction.gas, [mist]);\n transaction.transferObjects([coin], recipient);\n }\n\n const result = await signAndExecuteTransaction(\n { transaction, walletAccount },\n client\n );\n\n return { transactionHash: result.digest };\n};\n"],"mappings":";;;;;;;;;;;;;ACKA,MAAa,kBAAkB,OAAO,EACpC,SACA,kBAI4B;CAM5B,MAAM,gBAAgB,MAJJ,IAAIA,6BAAU,EAC9B,KAAK,YAAY,QAAQ,KAAK,IAC/B,CAAC,CAEoC,WAAW,EAC/C,OAAO,SACR,CAAC;CAGF,MAAM,UAAU,OAAO,cAAc,aAAa,GAAG,OAAOC,+BAAa;AAEzE,KAAI,OAAO,MAAM,QAAQ,CACvB,QAAO;AAGT,QAAO,QAAQ,UAAU;;;;;;ACrB3B,MAAa,4BACX,iBACwB;CACxB,gEAA6B,OAAO,YAAY;CAChD,YAAY,OAAO,EAAE,eAAe,EAClC,SAAS,MAAM,gBAAgB;EAC7B;EACA;EACD,CAAC,EACH;CACF;;;;;ACXD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