@dynamic-labs-sdk/sui 0.14.0 → 0.16.1
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/{addSuiWalletStandardExtension-ZDoIysQf.esm.js → addSuiWalletStandardExtension-BR31_Kda.esm.js} +4 -2
- package/dist/addSuiWalletStandardExtension-BR31_Kda.esm.js.map +1 -0
- package/dist/{addSuiWalletStandardExtension-Cv7bEwTp.cjs.js → addSuiWalletStandardExtension-DbOm408I.cjs.js} +5 -3
- package/dist/addSuiWalletStandardExtension-DbOm408I.cjs.js.map +1 -0
- package/dist/{addWaasSuiExtension-BSgmwZos.esm.js → addWaasSuiExtension-C2JMpaJ9.esm.js} +4 -2
- package/dist/addWaasSuiExtension-C2JMpaJ9.esm.js.map +1 -0
- package/dist/{addWaasSuiExtension-ist4SCEt.cjs.js → addWaasSuiExtension-CpJzJg43.cjs.js} +5 -3
- package/dist/addWaasSuiExtension-CpJzJg43.cjs.js.map +1 -0
- package/dist/checkoutTransaction.types.d.ts +6 -0
- package/dist/checkoutTransaction.types.d.ts.map +1 -0
- package/dist/index.cjs.js +11 -78
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +4 -71
- package/dist/index.esm.js.map +1 -1
- package/dist/suiTransferAmount-B8h2ZTJQ.esm.js +182 -0
- package/dist/suiTransferAmount-B8h2ZTJQ.esm.js.map +1 -0
- package/dist/suiTransferAmount-CBJCfAnc.cjs.js +241 -0
- package/dist/suiTransferAmount-CBJCfAnc.cjs.js.map +1 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/utils/suiExecuteCheckoutTransaction/index.d.ts +2 -0
- package/dist/utils/suiExecuteCheckoutTransaction/index.d.ts.map +1 -0
- package/dist/utils/suiExecuteCheckoutTransaction/suiExecuteCheckoutTransaction.d.ts +19 -0
- package/dist/utils/suiExecuteCheckoutTransaction/suiExecuteCheckoutTransaction.d.ts.map +1 -0
- package/dist/utils/suiTransferAmount/index.d.ts +2 -0
- package/dist/utils/suiTransferAmount/index.d.ts.map +1 -0
- package/dist/utils/suiTransferAmount/suiTransferAmount.d.ts +12 -0
- package/dist/utils/suiTransferAmount/suiTransferAmount.d.ts.map +1 -0
- package/dist/waas/utils/createWalletProviderForWaasSui/createWalletProviderForWaasSui.d.ts.map +1 -1
- package/dist/waas.cjs.js +3 -3
- package/dist/waas.cjs.js.map +1 -1
- package/dist/waas.esm.js +2 -2
- package/dist/walletStandard/utils/createWalletProviderFromSuiStandardWallet/createWalletProviderFromSuiStandardWallet.d.ts.map +1 -1
- package/dist/walletStandard.cjs.js +3 -3
- package/dist/walletStandard.cjs.js.map +1 -1
- package/dist/walletStandard.esm.js +2 -2
- package/package.json +4 -4
- package/dist/addSuiWalletStandardExtension-Cv7bEwTp.cjs.js.map +0 -1
- package/dist/addSuiWalletStandardExtension-ZDoIysQf.esm.js.map +0 -1
- package/dist/addWaasSuiExtension-BSgmwZos.esm.js.map +0 -1
- package/dist/addWaasSuiExtension-ist4SCEt.cjs.js.map +0 -1
- package/dist/registerSuiNetworkProviderBuilder-BrZT9Z_o.cjs.js +0 -61
- package/dist/registerSuiNetworkProviderBuilder-BrZT9Z_o.cjs.js.map +0 -1
- package/dist/registerSuiNetworkProviderBuilder-Byjt5yK6.esm.js +0 -44
- package/dist/registerSuiNetworkProviderBuilder-Byjt5yK6.esm.js.map +0 -1
package/dist/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","names":["getDefaultClient","getDefaultClient","getDefaultClient","getDefaultClient","packageName","packageVersion"],"sources":["../src/addSuiExtension/addSuiExtension.ts","../src/errors/NotSuiProviderError/NotSuiProviderError.ts","../src/isSuiWalletProvider/isSuiWalletProvider.ts","../src/getSuiClient/getSuiClient.ts","../src/isSuiNetworkProvider/isSuiNetworkProvider.ts","../src/isSuiWalletAccount/isSuiWalletAccount.ts","../src/signAndExecuteTransaction/signAndExecuteTransaction.ts","../src/signAndExecuteTransactionBlock/signAndExecuteTransactionBlock.ts","../src/signTransaction/signTransaction.ts","../src/signTransactionBlock/signTransactionBlock.ts","../src/exports/index.ts"],"sourcesContent":["import { getDefaultClient } from '@dynamic-labs-sdk/client/core';\n\nimport { addWaasSuiExtension } from '../waas/addWaasSuiExtension';\nimport { addSuiWalletStandardExtension } from '../walletStandard/addSuiWalletStandardExtension';\n\n/**\n * Adds the Sui extension to the Dynamic client.\n *\n * This is a convenience function that adds both the Sui Wallet Standard extension\n * and the Dynamic WaaS Sui extension, enabling support for all Sui wallet types\n * including standard wallets and embedded wallets managed by Dynamic's infrastructure.\n *\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n */\nexport const addSuiExtension = (client = getDefaultClient()): void => {\n addSuiWalletStandardExtension(client);\n addWaasSuiExtension(client);\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 type { WalletProvider } from '@dynamic-labs-sdk/client/core';\n\nimport type { SuiWalletProvider } from '../SuiWalletProvider.types';\n\nexport const isSuiWalletProvider = (\n provider: WalletProvider\n): provider is SuiWalletProvider => {\n return provider.chain === 'SUI';\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 */\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 type { NetworkProvider } from '@dynamic-labs-sdk/client';\n\nimport type { SuiNetworkProvider } from '../SuiNetworkProvider.types';\n\n/**\n * Type guard function to check if a network provider is a Sui network provider.\n *\n * @param networkProvider - The network provider to check.\n * @returns True if the network provider is a Sui network provider, false otherwise.\n */\nexport const isSuiNetworkProvider = (\n networkProvider: NetworkProvider\n): networkProvider is SuiNetworkProvider => networkProvider.chain === 'SUI';\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 */\nexport const isSuiWalletAccount = (\n walletAccount: WalletAccount\n): walletAccount is SuiWalletAccount => walletAccount.chain === 'SUI';\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 */\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 { getDefaultClient } from '@dynamic-labs-sdk/client';\nimport {\n MethodNotImplementedError,\n getWalletProviderFromWalletAccount,\n} 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 {\n SuiExecuteTransactionRequestType,\n SuiSignAndExecuteTransactionBlockResult,\n SuiTransactionBlockResponseOptions,\n} from '../SuiWalletProvider.types';\n\ntype SignAndExecuteTransactionBlockParams = {\n options?: SuiTransactionBlockResponseOptions;\n requestType?: SuiExecuteTransactionRequestType;\n transactionBlock: Transaction;\n walletAccount: SuiWalletAccount;\n};\n\n/**\n * @deprecated Use signAndExecuteTransaction instead\n *\n * Signs and executes a Sui transaction block\n *\n * @param params.transactionBlock - The transaction block to sign and execute\n * @param params.walletAccount - The wallet account to sign the transaction with\n * @param [params.options] - The fields to return in the execution response (e.g., transaction, effects, events, etc).\n * By default, only the transaction digest will be returned.\n * @param [params.requestType] - The request type to use for the transaction execution\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns An object containing signature result\n */\nexport const signAndExecuteTransactionBlock = async (\n {\n walletAccount,\n transactionBlock,\n options,\n requestType,\n }: SignAndExecuteTransactionBlockParams,\n client = getDefaultClient()\n): Promise<SuiSignAndExecuteTransactionBlockResult> => {\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 if (!provider.signAndExecuteTransactionBlock) {\n throw new MethodNotImplementedError('signAndExecuteTransactionBlock');\n }\n\n transactionBlock.setSender(walletAccount.address);\n\n return provider.signAndExecuteTransactionBlock({\n options,\n requestType,\n transactionBlock,\n walletAccount,\n });\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 { SuiSignTransactionResult } from '../SuiWalletProvider.types';\n\ntype SignTransactionParams = {\n transaction: Transaction;\n walletAccount: SuiWalletAccount;\n};\n\n/**\n * Signs a Sui transaction\n * @param params.transaction - The transaction to sign\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 */\nexport const signTransaction = async (\n { walletAccount, transaction }: SignTransactionParams,\n client = getDefaultClient()\n): Promise<SuiSignTransactionResult> => {\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.signTransaction({ transaction, walletAccount });\n};\n","import { getDefaultClient } from '@dynamic-labs-sdk/client';\nimport {\n MethodNotImplementedError,\n getWalletProviderFromWalletAccount,\n} 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 { SuiSignTransactionBlockResult } from '../SuiWalletProvider.types';\n\ntype SignTransactionBlockParams = {\n transactionBlock: Transaction;\n walletAccount: SuiWalletAccount;\n};\n\n/**\n * @deprecated Use signTransaction instead\n *\n * Signs a Sui transaction block\n *\n * @param params.transactionBlock - The transaction block to sign\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 block bytes\n */\nexport const signTransactionBlock = async (\n { walletAccount, transactionBlock }: SignTransactionBlockParams,\n client = getDefaultClient()\n): Promise<SuiSignTransactionBlockResult> => {\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 if (!provider.signTransactionBlock) {\n throw new MethodNotImplementedError('signTransactionBlock');\n }\n\n return provider.signTransactionBlock({ transactionBlock, walletAccount });\n};\n","import { assertPackageVersion } from '@dynamic-labs-sdk/assert-package-version';\n\nimport {\n name as packageName,\n version as packageVersion,\n} from '../../package.json';\nassertPackageVersion(packageName, packageVersion);\n\nexport { addSuiExtension } from '../addSuiExtension';\nexport { NotSuiProviderError } from '../errors/NotSuiProviderError';\nexport { getSuiClient } from '../getSuiClient';\nexport { isSuiNetworkProvider } from '../isSuiNetworkProvider';\nexport { isSuiWalletAccount } from '../isSuiWalletAccount';\nexport { signAndExecuteTransaction } from '../signAndExecuteTransaction';\nexport { signAndExecuteTransactionBlock } from '../signAndExecuteTransactionBlock';\nexport { signTransaction } from '../signTransaction';\nexport { signTransactionBlock } from '../signTransactionBlock';\nexport type { SuiNetworkProvider } from '../SuiNetworkProvider.types';\nexport type { SuiWalletAccount } from '../SuiWalletAccount.types';\nexport type {\n SuiClient,\n SuiExecuteTransactionRequestType,\n SuiSignAndExecuteTransactionBlockResult,\n SuiSignAndExecuteTransactionResult,\n SuiSignTransactionBlockResult,\n SuiSignTransactionResult,\n SuiTransactionB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AAS,KAAK,CAAC;AAG9D,KAAI,CAAC,SAAS,+BACZ,OAAM,IAAI,0BAA0B,iCAAiC;AAGvE,kBAAiB,UAAU,cAAc,QAAQ;AAEjD,QAAO,SAAS,+BAA+B;EAC7C;EACA;EACA;EACA;EACD,CAAC;;;;;;;;;;;;AC9CJ,MAAa,kBAAkB,OAC7B,EAAE,eAAe,eACjB,SAASC,oBAAkB,KACW;CACtC,MAAM,WAAW,mCACf,EACE,eACD,EACD,OACD;AAED,KAAI,CAAC,oBAAoB,SAAS,CAChC,OAAM,IAAI,oBAAoB,EAAE,aAAa,SAAS,KAAK,CAAC;AAG9D,QAAO,SAAS,gBAAgB;EAAE;EAAa;EAAe,CAAC;;;;;;;;;;;;;;;ACTjE,MAAa,uBAAuB,OAClC,EAAE,eAAe,oBACjB,SAASC,oBAAkB,KACgB;CAC3C,MAAM,WAAW,mCACf,EACE,eACD,EACD,OACD;AAED,KAAI,CAAC,oBAAoB,SAAS,CAChC,OAAM,IAAI,oBAAoB,EAAE,aAAa,SAAS,KAAK,CAAC;AAG9D,KAAI,CAAC,SAAS,qBACZ,OAAM,IAAI,0BAA0B,uBAAuB;AAG7D,QAAO,SAAS,qBAAqB;EAAE;EAAkB;EAAe,CAAC;;;;;ACxC3E,qBAAqBC,MAAaC,QAAe"}
|
|
1
|
+
{"version":3,"file":"index.esm.js","names":["getDefaultClient","getDefaultClient","getDefaultClient","packageName","packageVersion"],"sources":["../src/addSuiExtension/addSuiExtension.ts","../src/isSuiNetworkProvider/isSuiNetworkProvider.ts","../src/signAndExecuteTransactionBlock/signAndExecuteTransactionBlock.ts","../src/signTransaction/signTransaction.ts","../src/signTransactionBlock/signTransactionBlock.ts","../src/exports/index.ts"],"sourcesContent":["import { getDefaultClient } from '@dynamic-labs-sdk/client/core';\n\nimport { addWaasSuiExtension } from '../waas/addWaasSuiExtension';\nimport { addSuiWalletStandardExtension } from '../walletStandard/addSuiWalletStandardExtension';\n\n/**\n * Adds the Sui extension to the Dynamic client.\n *\n * This is a convenience function that adds both the Sui Wallet Standard extension\n * and the Dynamic WaaS Sui extension, enabling support for all Sui wallet types\n * including standard wallets and embedded wallets managed by Dynamic's infrastructure.\n *\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n */\nexport const addSuiExtension = (client = getDefaultClient()): void => {\n addSuiWalletStandardExtension(client);\n addWaasSuiExtension(client);\n};\n","import type { NetworkProvider } from '@dynamic-labs-sdk/client';\n\nimport type { SuiNetworkProvider } from '../SuiNetworkProvider.types';\n\n/**\n * Type guard function to check if a network provider is a Sui network provider.\n *\n * @param networkProvider - The network provider to check.\n * @returns True if the network provider is a Sui network provider, false otherwise.\n */\nexport const isSuiNetworkProvider = (\n networkProvider: NetworkProvider\n): networkProvider is SuiNetworkProvider => networkProvider.chain === 'SUI';\n","import { getDefaultClient } from '@dynamic-labs-sdk/client';\nimport {\n MethodNotImplementedError,\n getWalletProviderFromWalletAccount,\n} 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 {\n SuiExecuteTransactionRequestType,\n SuiSignAndExecuteTransactionBlockResult,\n SuiTransactionBlockResponseOptions,\n} from '../SuiWalletProvider.types';\n\ntype SignAndExecuteTransactionBlockParams = {\n options?: SuiTransactionBlockResponseOptions;\n requestType?: SuiExecuteTransactionRequestType;\n transactionBlock: Transaction;\n walletAccount: SuiWalletAccount;\n};\n\n/**\n * @deprecated Use signAndExecuteTransaction instead\n *\n * Signs and executes a Sui transaction block\n *\n * @param params.transactionBlock - The transaction block to sign and execute\n * @param params.walletAccount - The wallet account to sign the transaction with\n * @param [params.options] - The fields to return in the execution response (e.g., transaction, effects, events, etc).\n * By default, only the transaction digest will be returned.\n * @param [params.requestType] - The request type to use for the transaction execution\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns An object containing signature result\n */\nexport const signAndExecuteTransactionBlock = async (\n {\n walletAccount,\n transactionBlock,\n options,\n requestType,\n }: SignAndExecuteTransactionBlockParams,\n client = getDefaultClient()\n): Promise<SuiSignAndExecuteTransactionBlockResult> => {\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 if (!provider.signAndExecuteTransactionBlock) {\n throw new MethodNotImplementedError('signAndExecuteTransactionBlock');\n }\n\n transactionBlock.setSender(walletAccount.address);\n\n return provider.signAndExecuteTransactionBlock({\n options,\n requestType,\n transactionBlock,\n walletAccount,\n });\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 { SuiSignTransactionResult } from '../SuiWalletProvider.types';\n\ntype SignTransactionParams = {\n transaction: Transaction;\n walletAccount: SuiWalletAccount;\n};\n\n/**\n * Signs a Sui transaction\n * @param params.transaction - The transaction to sign\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 */\nexport const signTransaction = async (\n { walletAccount, transaction }: SignTransactionParams,\n client = getDefaultClient()\n): Promise<SuiSignTransactionResult> => {\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.signTransaction({ transaction, walletAccount });\n};\n","import { getDefaultClient } from '@dynamic-labs-sdk/client';\nimport {\n MethodNotImplementedError,\n getWalletProviderFromWalletAccount,\n} 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 { SuiSignTransactionBlockResult } from '../SuiWalletProvider.types';\n\ntype SignTransactionBlockParams = {\n transactionBlock: Transaction;\n walletAccount: SuiWalletAccount;\n};\n\n/**\n * @deprecated Use signTransaction instead\n *\n * Signs a Sui transaction block\n *\n * @param params.transactionBlock - The transaction block to sign\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 block bytes\n */\nexport const signTransactionBlock = async (\n { walletAccount, transactionBlock }: SignTransactionBlockParams,\n client = getDefaultClient()\n): Promise<SuiSignTransactionBlockResult> => {\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 if (!provider.signTransactionBlock) {\n throw new MethodNotImplementedError('signTransactionBlock');\n }\n\n return provider.signTransactionBlock({ transactionBlock, walletAccount });\n};\n","import { assertPackageVersion } from '@dynamic-labs-sdk/assert-package-version';\n\nimport {\n name as packageName,\n version as packageVersion,\n} from '../../package.json';\nassertPackageVersion(packageName, packageVersion);\n\nexport { addSuiExtension } from '../addSuiExtension';\nexport { NotSuiProviderError } from '../errors/NotSuiProviderError';\nexport { getSuiClient } from '../getSuiClient';\nexport { isSuiNetworkProvider } from '../isSuiNetworkProvider';\nexport { isSuiWalletAccount } from '../isSuiWalletAccount';\nexport { signAndExecuteTransaction } from '../signAndExecuteTransaction';\nexport { signAndExecuteTransactionBlock } from '../signAndExecuteTransactionBlock';\nexport { signTransaction } from '../signTransaction';\nexport { signTransactionBlock } from '../signTransactionBlock';\nexport type { SuiNetworkProvider } from '../SuiNetworkProvider.types';\nexport type { SuiWalletAccount } from '../SuiWalletAccount.types';\nexport type {\n SuiClient,\n SuiExecuteTransactionRequestType,\n SuiSignAndExecuteTransactionBlockResult,\n SuiSignAndExecuteTransactionResult,\n SuiSignTransactionBlockResult,\n SuiSignTransactionResult,\n SuiTransactionBlockResponseOptions,\n} from '../SuiWalletProvider.types';\n"],"mappings":";;;;;;;;;;;;;;;;;AAcA,MAAa,mBAAmB,SAAS,kBAAkB,KAAW;AACpE,+BAA8B,OAAO;AACrC,qBAAoB,OAAO;;;;;;;;;;;ACN7B,MAAa,wBACX,oBAC0C,gBAAgB,UAAU;;;;;;;;;;;;;;;;;ACwBtE,MAAa,iCAAiC,OAC5C,EACE,eACA,kBACA,SACA,eAEF,SAASA,oBAAkB,KAC0B;CACrD,MAAM,WAAW,mCACf,EACE,eACD,EACD,OACD;AAED,KAAI,CAAC,oBAAoB,SAAS,CAChC,OAAM,IAAI,oBAAoB,EAAE,aAAa,SAAS,KAAK,CAAC;AAG9D,KAAI,CAAC,SAAS,+BACZ,OAAM,IAAI,0BAA0B,iCAAiC;AAGvE,kBAAiB,UAAU,cAAc,QAAQ;AAEjD,QAAO,SAAS,+BAA+B;EAC7C;EACA;EACA;EACA;EACD,CAAC;;;;;;;;;;;;AC9CJ,MAAa,kBAAkB,OAC7B,EAAE,eAAe,eACjB,SAASC,oBAAkB,KACW;CACtC,MAAM,WAAW,mCACf,EACE,eACD,EACD,OACD;AAED,KAAI,CAAC,oBAAoB,SAAS,CAChC,OAAM,IAAI,oBAAoB,EAAE,aAAa,SAAS,KAAK,CAAC;AAG9D,QAAO,SAAS,gBAAgB;EAAE;EAAa;EAAe,CAAC;;;;;;;;;;;;;;;ACTjE,MAAa,uBAAuB,OAClC,EAAE,eAAe,oBACjB,SAASC,oBAAkB,KACgB;CAC3C,MAAM,WAAW,mCACf,EACE,eACD,EACD,OACD;AAED,KAAI,CAAC,oBAAoB,SAAS,CAChC,OAAM,IAAI,oBAAoB,EAAE,aAAa,SAAS,KAAK,CAAC;AAG9D,KAAI,CAAC,SAAS,qBACZ,OAAM,IAAI,0BAA0B,uBAAuB;AAG7D,QAAO,SAAS,qBAAqB;EAAE;EAAkB;EAAe,CAAC;;;;;ACxC3E,qBAAqBC,MAAaC,QAAe"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { createBaseNetworkProvider, getDefaultClient, getNetworkProviderBuilderRegistry, getWalletProviderFromWalletAccount, parseAmountToSmallestUnit } from "@dynamic-labs-sdk/client/core";
|
|
2
|
+
import { SuiClient } from "@mysten/sui/client";
|
|
3
|
+
import { MIST_PER_SUI } from "@mysten/sui/utils";
|
|
4
|
+
import { BaseError, InvalidParamError, getDefaultClient as getDefaultClient$1 } from "@dynamic-labs-sdk/client";
|
|
5
|
+
import { Transaction } from "@mysten/sui/transactions";
|
|
6
|
+
|
|
7
|
+
//#region package.json
|
|
8
|
+
var name = "@dynamic-labs-sdk/sui";
|
|
9
|
+
var version = "0.16.1";
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/utils/fetchSuiBalance/fetchSuiBalance.ts
|
|
13
|
+
const fetchSuiBalance = async ({ address, networkData }) => {
|
|
14
|
+
const balanceInMist = await new SuiClient({ url: networkData.rpcUrls.http[0] }).getBalance({ owner: address });
|
|
15
|
+
const balance = Number(balanceInMist.totalBalance) / Number(MIST_PER_SUI);
|
|
16
|
+
if (Number.isNaN(balance)) return null;
|
|
17
|
+
return balance.toString();
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/utils/createSuiNetworkProvider/createSuiNetworkProvider.ts
|
|
22
|
+
const createSuiNetworkProvider = (networkData) => ({
|
|
23
|
+
...createBaseNetworkProvider("SUI", networkData),
|
|
24
|
+
getBalance: async ({ address }) => ({ balance: await fetchSuiBalance({
|
|
25
|
+
address,
|
|
26
|
+
networkData
|
|
27
|
+
}) })
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/registerSuiNetworkProviderBuilder/registerSuiNetworkProviderBuilder.ts
|
|
32
|
+
const registerSuiNetworkProviderBuilder = (client) => {
|
|
33
|
+
const networkProviderBuilderRegistry = getNetworkProviderBuilderRegistry(client);
|
|
34
|
+
/**
|
|
35
|
+
* If the Sui network provider builder is already registered, return.
|
|
36
|
+
*/
|
|
37
|
+
if (networkProviderBuilderRegistry.get().get("SUI")) return;
|
|
38
|
+
networkProviderBuilderRegistry.register({
|
|
39
|
+
builder: createSuiNetworkProvider,
|
|
40
|
+
chain: "SUI"
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/isSuiWalletAccount/isSuiWalletAccount.ts
|
|
46
|
+
/**
|
|
47
|
+
* Type guard function to check if a wallet account is a Sui wallet account.
|
|
48
|
+
*
|
|
49
|
+
* @param walletAccount - The wallet account to check.
|
|
50
|
+
* @returns True if the wallet account is a Sui wallet account, false otherwise.
|
|
51
|
+
*/
|
|
52
|
+
const isSuiWalletAccount = (walletAccount) => walletAccount.chain === "SUI";
|
|
53
|
+
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/isSuiWalletProvider/isSuiWalletProvider.ts
|
|
56
|
+
const isSuiWalletProvider = (provider) => {
|
|
57
|
+
return provider.chain === "SUI";
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/utils/suiExecuteCheckoutTransaction/suiExecuteCheckoutTransaction.ts
|
|
62
|
+
/**
|
|
63
|
+
* Executes a Sui checkout transaction by deserializing the base64-encoded
|
|
64
|
+
* BCS transaction and sending it via the wallet provider's signAndExecuteTransaction.
|
|
65
|
+
*
|
|
66
|
+
* 1. Validates that the wallet account is a Sui wallet account
|
|
67
|
+
* 2. Extracts and validates the serialized transaction from the signing payload
|
|
68
|
+
* 3. Deserializes the transaction using Transaction.from()
|
|
69
|
+
* 4. Signs and executes via the Sui wallet provider
|
|
70
|
+
*
|
|
71
|
+
* @param params.signingPayload - The signing payload containing `serializedTransaction`.
|
|
72
|
+
* @param params.walletAccount - The wallet account used to sign and execute the transaction.
|
|
73
|
+
* @param params.onStepChange - Optional callback invoked with `'transaction'` when the execution step begins.
|
|
74
|
+
* @param client - The Dynamic client instance.
|
|
75
|
+
* @returns The transaction hash (digest).
|
|
76
|
+
*/
|
|
77
|
+
const suiExecuteCheckoutTransaction = async ({ onStepChange, signingPayload, walletAccount }, client) => {
|
|
78
|
+
const walletProvider = getWalletProviderFromWalletAccount({ walletAccount }, client);
|
|
79
|
+
if (!isSuiWalletAccount(walletAccount) || !isSuiWalletProvider(walletProvider)) throw new InvalidParamError("Wallet account is not a Sui wallet account");
|
|
80
|
+
const suiPayload = signingPayload;
|
|
81
|
+
if (!suiPayload.serializedTransaction?.serializedTransaction) throw new InvalidParamError("Signing payload is missing serialized transaction data");
|
|
82
|
+
const { serializedTransaction: serializedTransactionStr } = suiPayload.serializedTransaction;
|
|
83
|
+
const transaction = Transaction.from(serializedTransactionStr);
|
|
84
|
+
onStepChange?.("transaction");
|
|
85
|
+
return { transactionHash: (await walletProvider.signAndExecuteTransaction({
|
|
86
|
+
transaction,
|
|
87
|
+
walletAccount
|
|
88
|
+
})).digest };
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/errors/NotSuiProviderError/NotSuiProviderError.ts
|
|
93
|
+
var NotSuiProviderError = class extends BaseError {
|
|
94
|
+
providerKey;
|
|
95
|
+
constructor(params) {
|
|
96
|
+
super({
|
|
97
|
+
cause: null,
|
|
98
|
+
code: "not_sui_provider_error",
|
|
99
|
+
docsUrl: null,
|
|
100
|
+
name: "NotSuiProviderError",
|
|
101
|
+
shortMessage: "Provider is not a Sui wallet provider"
|
|
102
|
+
});
|
|
103
|
+
this.providerKey = params.providerKey;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region src/getSuiClient/getSuiClient.ts
|
|
109
|
+
/**
|
|
110
|
+
* Retrieves a SuiClient from a wallet account.
|
|
111
|
+
*
|
|
112
|
+
* @param params.walletAccount - The wallet account to get the SuiClient for.
|
|
113
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
114
|
+
* @returns A promise that resolves to a SuiClient instance
|
|
115
|
+
* @throws NotSuiProviderError If the wallet account's provider is not a SUI provider
|
|
116
|
+
*/
|
|
117
|
+
const getSuiClient = async ({ walletAccount }, client = getDefaultClient()) => {
|
|
118
|
+
const provider = getWalletProviderFromWalletAccount({ walletAccount }, client);
|
|
119
|
+
if (!isSuiWalletProvider(provider)) throw new NotSuiProviderError({ providerKey: provider.key });
|
|
120
|
+
return provider.getSuiClient({ walletAccount });
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
//#endregion
|
|
124
|
+
//#region src/signAndExecuteTransaction/signAndExecuteTransaction.ts
|
|
125
|
+
/**
|
|
126
|
+
* Signs and executes a Sui transaction
|
|
127
|
+
* @param params.transaction - The transaction to sign and execute
|
|
128
|
+
* @param params.walletAccount - The wallet account to sign the transaction with
|
|
129
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
130
|
+
* @returns An object containing the signature and transaction bytes
|
|
131
|
+
*/
|
|
132
|
+
const signAndExecuteTransaction = async ({ walletAccount, transaction }, client = getDefaultClient$1()) => {
|
|
133
|
+
const provider = getWalletProviderFromWalletAccount({ walletAccount }, client);
|
|
134
|
+
if (!isSuiWalletProvider(provider)) throw new NotSuiProviderError({ providerKey: provider.key });
|
|
135
|
+
transaction.setSender(walletAccount.address);
|
|
136
|
+
return provider.signAndExecuteTransaction({
|
|
137
|
+
transaction,
|
|
138
|
+
walletAccount
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
//#endregion
|
|
143
|
+
//#region src/utils/suiTransferAmount/suiTransferAmount.ts
|
|
144
|
+
const SUI_DECIMALS = 9;
|
|
145
|
+
/**
|
|
146
|
+
* Transfers native SUI or a SUI token from one wallet to another.
|
|
147
|
+
*
|
|
148
|
+
* For native SUI, converts the human-readable amount string to MIST (9 decimals).
|
|
149
|
+
* For tokens, fetches the user's coins of that type and splits from them.
|
|
150
|
+
*/
|
|
151
|
+
const suiTransferAmount = async ({ amount, recipient, token, walletAccount }, client) => {
|
|
152
|
+
if (!isSuiWalletAccount(walletAccount)) throw new InvalidParamError("Wallet account is not a SUI wallet account");
|
|
153
|
+
const transaction = new Transaction();
|
|
154
|
+
if (token?.address) {
|
|
155
|
+
const { data: coins } = await (await getSuiClient({ walletAccount }, client)).getCoins({
|
|
156
|
+
coinType: token.address,
|
|
157
|
+
owner: walletAccount.address
|
|
158
|
+
});
|
|
159
|
+
if (coins.length === 0) throw new InvalidParamError("Token not found");
|
|
160
|
+
const smallestUnit = parseAmountToSmallestUnit({
|
|
161
|
+
amount,
|
|
162
|
+
decimals: token.decimals
|
|
163
|
+
});
|
|
164
|
+
const [coin] = transaction.splitCoins(coins[0].coinObjectId, [smallestUnit]);
|
|
165
|
+
transaction.transferObjects([coin], recipient);
|
|
166
|
+
} else {
|
|
167
|
+
const mist = parseAmountToSmallestUnit({
|
|
168
|
+
amount,
|
|
169
|
+
decimals: SUI_DECIMALS
|
|
170
|
+
});
|
|
171
|
+
const [coin] = transaction.splitCoins(transaction.gas, [mist]);
|
|
172
|
+
transaction.transferObjects([coin], recipient);
|
|
173
|
+
}
|
|
174
|
+
return { transactionHash: (await signAndExecuteTransaction({
|
|
175
|
+
transaction,
|
|
176
|
+
walletAccount
|
|
177
|
+
}, client)).digest };
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
//#endregion
|
|
181
|
+
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-B8h2ZTJQ.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"suiTransferAmount-B8h2ZTJQ.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\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\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\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 */\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\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 */\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 */\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 */\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 */\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":";;;;;;;;;;;;ACIA,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,GA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B,CAAC,KAAK,EAAE,UAAU;;AAQhD,QAAO,EAAE,kBALM,MAAM,0BACnB;EAAE;EAAa;EAAe,EAC9B,OACD,EAEgC,QAAQ"}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
let _dynamic_labs_sdk_client_core = require("@dynamic-labs-sdk/client/core");
|
|
2
|
+
let _mysten_sui_client = require("@mysten/sui/client");
|
|
3
|
+
let _mysten_sui_utils = require("@mysten/sui/utils");
|
|
4
|
+
let _dynamic_labs_sdk_client = require("@dynamic-labs-sdk/client");
|
|
5
|
+
let _mysten_sui_transactions = require("@mysten/sui/transactions");
|
|
6
|
+
|
|
7
|
+
//#region package.json
|
|
8
|
+
var name = "@dynamic-labs-sdk/sui";
|
|
9
|
+
var version = "0.16.1";
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/utils/fetchSuiBalance/fetchSuiBalance.ts
|
|
13
|
+
const fetchSuiBalance = async ({ address, networkData }) => {
|
|
14
|
+
const balanceInMist = await new _mysten_sui_client.SuiClient({ url: networkData.rpcUrls.http[0] }).getBalance({ owner: address });
|
|
15
|
+
const balance = Number(balanceInMist.totalBalance) / Number(_mysten_sui_utils.MIST_PER_SUI);
|
|
16
|
+
if (Number.isNaN(balance)) return null;
|
|
17
|
+
return balance.toString();
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/utils/createSuiNetworkProvider/createSuiNetworkProvider.ts
|
|
22
|
+
const createSuiNetworkProvider = (networkData) => ({
|
|
23
|
+
...(0, _dynamic_labs_sdk_client_core.createBaseNetworkProvider)("SUI", networkData),
|
|
24
|
+
getBalance: async ({ address }) => ({ balance: await fetchSuiBalance({
|
|
25
|
+
address,
|
|
26
|
+
networkData
|
|
27
|
+
}) })
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/registerSuiNetworkProviderBuilder/registerSuiNetworkProviderBuilder.ts
|
|
32
|
+
const registerSuiNetworkProviderBuilder = (client) => {
|
|
33
|
+
const networkProviderBuilderRegistry = (0, _dynamic_labs_sdk_client_core.getNetworkProviderBuilderRegistry)(client);
|
|
34
|
+
/**
|
|
35
|
+
* If the Sui network provider builder is already registered, return.
|
|
36
|
+
*/
|
|
37
|
+
if (networkProviderBuilderRegistry.get().get("SUI")) return;
|
|
38
|
+
networkProviderBuilderRegistry.register({
|
|
39
|
+
builder: createSuiNetworkProvider,
|
|
40
|
+
chain: "SUI"
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/isSuiWalletAccount/isSuiWalletAccount.ts
|
|
46
|
+
/**
|
|
47
|
+
* Type guard function to check if a wallet account is a Sui wallet account.
|
|
48
|
+
*
|
|
49
|
+
* @param walletAccount - The wallet account to check.
|
|
50
|
+
* @returns True if the wallet account is a Sui wallet account, false otherwise.
|
|
51
|
+
*/
|
|
52
|
+
const isSuiWalletAccount = (walletAccount) => walletAccount.chain === "SUI";
|
|
53
|
+
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/isSuiWalletProvider/isSuiWalletProvider.ts
|
|
56
|
+
const isSuiWalletProvider = (provider) => {
|
|
57
|
+
return provider.chain === "SUI";
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/utils/suiExecuteCheckoutTransaction/suiExecuteCheckoutTransaction.ts
|
|
62
|
+
/**
|
|
63
|
+
* Executes a Sui checkout transaction by deserializing the base64-encoded
|
|
64
|
+
* BCS transaction and sending it via the wallet provider's signAndExecuteTransaction.
|
|
65
|
+
*
|
|
66
|
+
* 1. Validates that the wallet account is a Sui wallet account
|
|
67
|
+
* 2. Extracts and validates the serialized transaction from the signing payload
|
|
68
|
+
* 3. Deserializes the transaction using Transaction.from()
|
|
69
|
+
* 4. Signs and executes via the Sui wallet provider
|
|
70
|
+
*
|
|
71
|
+
* @param params.signingPayload - The signing payload containing `serializedTransaction`.
|
|
72
|
+
* @param params.walletAccount - The wallet account used to sign and execute the transaction.
|
|
73
|
+
* @param params.onStepChange - Optional callback invoked with `'transaction'` when the execution step begins.
|
|
74
|
+
* @param client - The Dynamic client instance.
|
|
75
|
+
* @returns The transaction hash (digest).
|
|
76
|
+
*/
|
|
77
|
+
const suiExecuteCheckoutTransaction = async ({ onStepChange, signingPayload, walletAccount }, client) => {
|
|
78
|
+
const walletProvider = (0, _dynamic_labs_sdk_client_core.getWalletProviderFromWalletAccount)({ walletAccount }, client);
|
|
79
|
+
if (!isSuiWalletAccount(walletAccount) || !isSuiWalletProvider(walletProvider)) throw new _dynamic_labs_sdk_client.InvalidParamError("Wallet account is not a Sui wallet account");
|
|
80
|
+
const suiPayload = signingPayload;
|
|
81
|
+
if (!suiPayload.serializedTransaction?.serializedTransaction) throw new _dynamic_labs_sdk_client.InvalidParamError("Signing payload is missing serialized transaction data");
|
|
82
|
+
const { serializedTransaction: serializedTransactionStr } = suiPayload.serializedTransaction;
|
|
83
|
+
const transaction = _mysten_sui_transactions.Transaction.from(serializedTransactionStr);
|
|
84
|
+
onStepChange?.("transaction");
|
|
85
|
+
return { transactionHash: (await walletProvider.signAndExecuteTransaction({
|
|
86
|
+
transaction,
|
|
87
|
+
walletAccount
|
|
88
|
+
})).digest };
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/errors/NotSuiProviderError/NotSuiProviderError.ts
|
|
93
|
+
var NotSuiProviderError = class extends _dynamic_labs_sdk_client.BaseError {
|
|
94
|
+
providerKey;
|
|
95
|
+
constructor(params) {
|
|
96
|
+
super({
|
|
97
|
+
cause: null,
|
|
98
|
+
code: "not_sui_provider_error",
|
|
99
|
+
docsUrl: null,
|
|
100
|
+
name: "NotSuiProviderError",
|
|
101
|
+
shortMessage: "Provider is not a Sui wallet provider"
|
|
102
|
+
});
|
|
103
|
+
this.providerKey = params.providerKey;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region src/getSuiClient/getSuiClient.ts
|
|
109
|
+
/**
|
|
110
|
+
* Retrieves a SuiClient from a wallet account.
|
|
111
|
+
*
|
|
112
|
+
* @param params.walletAccount - The wallet account to get the SuiClient for.
|
|
113
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
114
|
+
* @returns A promise that resolves to a SuiClient instance
|
|
115
|
+
* @throws NotSuiProviderError If the wallet account's provider is not a SUI provider
|
|
116
|
+
*/
|
|
117
|
+
const getSuiClient = async ({ walletAccount }, client = (0, _dynamic_labs_sdk_client_core.getDefaultClient)()) => {
|
|
118
|
+
const provider = (0, _dynamic_labs_sdk_client_core.getWalletProviderFromWalletAccount)({ walletAccount }, client);
|
|
119
|
+
if (!isSuiWalletProvider(provider)) throw new NotSuiProviderError({ providerKey: provider.key });
|
|
120
|
+
return provider.getSuiClient({ walletAccount });
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
//#endregion
|
|
124
|
+
//#region src/signAndExecuteTransaction/signAndExecuteTransaction.ts
|
|
125
|
+
/**
|
|
126
|
+
* Signs and executes a Sui transaction
|
|
127
|
+
* @param params.transaction - The transaction to sign and execute
|
|
128
|
+
* @param params.walletAccount - The wallet account to sign the transaction with
|
|
129
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
130
|
+
* @returns An object containing the signature and transaction bytes
|
|
131
|
+
*/
|
|
132
|
+
const signAndExecuteTransaction = async ({ walletAccount, transaction }, client = (0, _dynamic_labs_sdk_client.getDefaultClient)()) => {
|
|
133
|
+
const provider = (0, _dynamic_labs_sdk_client_core.getWalletProviderFromWalletAccount)({ walletAccount }, client);
|
|
134
|
+
if (!isSuiWalletProvider(provider)) throw new NotSuiProviderError({ providerKey: provider.key });
|
|
135
|
+
transaction.setSender(walletAccount.address);
|
|
136
|
+
return provider.signAndExecuteTransaction({
|
|
137
|
+
transaction,
|
|
138
|
+
walletAccount
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
//#endregion
|
|
143
|
+
//#region src/utils/suiTransferAmount/suiTransferAmount.ts
|
|
144
|
+
const SUI_DECIMALS = 9;
|
|
145
|
+
/**
|
|
146
|
+
* Transfers native SUI or a SUI token from one wallet to another.
|
|
147
|
+
*
|
|
148
|
+
* For native SUI, converts the human-readable amount string to MIST (9 decimals).
|
|
149
|
+
* For tokens, fetches the user's coins of that type and splits from them.
|
|
150
|
+
*/
|
|
151
|
+
const suiTransferAmount = async ({ amount, recipient, token, walletAccount }, client) => {
|
|
152
|
+
if (!isSuiWalletAccount(walletAccount)) throw new _dynamic_labs_sdk_client.InvalidParamError("Wallet account is not a SUI wallet account");
|
|
153
|
+
const transaction = new _mysten_sui_transactions.Transaction();
|
|
154
|
+
if (token?.address) {
|
|
155
|
+
const { data: coins } = await (await getSuiClient({ walletAccount }, client)).getCoins({
|
|
156
|
+
coinType: token.address,
|
|
157
|
+
owner: walletAccount.address
|
|
158
|
+
});
|
|
159
|
+
if (coins.length === 0) throw new _dynamic_labs_sdk_client.InvalidParamError("Token not found");
|
|
160
|
+
const smallestUnit = (0, _dynamic_labs_sdk_client_core.parseAmountToSmallestUnit)({
|
|
161
|
+
amount,
|
|
162
|
+
decimals: token.decimals
|
|
163
|
+
});
|
|
164
|
+
const [coin] = transaction.splitCoins(coins[0].coinObjectId, [smallestUnit]);
|
|
165
|
+
transaction.transferObjects([coin], recipient);
|
|
166
|
+
} else {
|
|
167
|
+
const mist = (0, _dynamic_labs_sdk_client_core.parseAmountToSmallestUnit)({
|
|
168
|
+
amount,
|
|
169
|
+
decimals: SUI_DECIMALS
|
|
170
|
+
});
|
|
171
|
+
const [coin] = transaction.splitCoins(transaction.gas, [mist]);
|
|
172
|
+
transaction.transferObjects([coin], recipient);
|
|
173
|
+
}
|
|
174
|
+
return { transactionHash: (await signAndExecuteTransaction({
|
|
175
|
+
transaction,
|
|
176
|
+
walletAccount
|
|
177
|
+
}, client)).digest };
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
//#endregion
|
|
181
|
+
Object.defineProperty(exports, 'NotSuiProviderError', {
|
|
182
|
+
enumerable: true,
|
|
183
|
+
get: function () {
|
|
184
|
+
return NotSuiProviderError;
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
Object.defineProperty(exports, 'getSuiClient', {
|
|
188
|
+
enumerable: true,
|
|
189
|
+
get: function () {
|
|
190
|
+
return getSuiClient;
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
Object.defineProperty(exports, 'isSuiWalletAccount', {
|
|
194
|
+
enumerable: true,
|
|
195
|
+
get: function () {
|
|
196
|
+
return isSuiWalletAccount;
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
Object.defineProperty(exports, 'isSuiWalletProvider', {
|
|
200
|
+
enumerable: true,
|
|
201
|
+
get: function () {
|
|
202
|
+
return isSuiWalletProvider;
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
Object.defineProperty(exports, 'name', {
|
|
206
|
+
enumerable: true,
|
|
207
|
+
get: function () {
|
|
208
|
+
return name;
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
Object.defineProperty(exports, 'registerSuiNetworkProviderBuilder', {
|
|
212
|
+
enumerable: true,
|
|
213
|
+
get: function () {
|
|
214
|
+
return registerSuiNetworkProviderBuilder;
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
Object.defineProperty(exports, 'signAndExecuteTransaction', {
|
|
218
|
+
enumerable: true,
|
|
219
|
+
get: function () {
|
|
220
|
+
return signAndExecuteTransaction;
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
Object.defineProperty(exports, 'suiExecuteCheckoutTransaction', {
|
|
224
|
+
enumerable: true,
|
|
225
|
+
get: function () {
|
|
226
|
+
return suiExecuteCheckoutTransaction;
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
Object.defineProperty(exports, 'suiTransferAmount', {
|
|
230
|
+
enumerable: true,
|
|
231
|
+
get: function () {
|
|
232
|
+
return suiTransferAmount;
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
Object.defineProperty(exports, 'version', {
|
|
236
|
+
enumerable: true,
|
|
237
|
+
get: function () {
|
|
238
|
+
return version;
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
//# sourceMappingURL=suiTransferAmount-CBJCfAnc.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"suiTransferAmount-CBJCfAnc.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\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\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\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 */\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\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 */\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 */\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 */\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 */\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":";;;;;;;;;;;;ACIA,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,MAAa,qCACX,WACS;CACT,MAAM,sGAC8B,OAAO;;;;AAK3C,KAAI,+BAA+B,KAAK,CAAC,IAAI,MAAM,CACjD;AAGF,gCAA+B,SAAS;EACtC,SAAS;EACT,OAAO;EACR,CAAC;;;;;;;;;;;ACXJ,MAAa,sBACX,kBACsC,cAAc,UAAU;;;;ACRhE,MAAa,uBACX,aACkC;AAClC,QAAO,SAAS,UAAU;;;;;;;;;;;;;;;;;;;;ACuB5B,MAAa,gCAAgC,OAC3C,EACE,cACA,gBACA,iBAEF,WAC8C;CAC9C,MAAM,uFACJ,EAAE,eAAe,EACjB,OACD;AAED,KACE,CAAC,mBAAmB,cAAc,IAClC,CAAC,oBAAoB,eAAe,CAEpC,OAAM,IAAIC,2CACR,6CACD;CAGH,MAAM,aAAa;AAEnB,KAAI,CAAC,WAAW,uBAAuB,sBACrC,OAAM,IAAIA,2CACR,yDACD;CAGH,MAAM,EAAE,uBAAuB,6BAC7B,WAAW;CAEb,MAAM,cAAcC,qCAAY,KAAK,yBAAyB;AAE9D,gBAAe,cAAc;AAO7B,QAAO,EAAE,kBALM,M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