@unconfirmed/effect-sui 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/README.md +10 -2
- package/dist/Address.d.ts +18 -0
- package/dist/Address.d.ts.map +1 -0
- package/dist/Address.js +33 -0
- package/dist/Address.js.map +1 -0
- package/dist/AddressAlias.d.ts +107 -0
- package/dist/AddressAlias.d.ts.map +1 -0
- package/dist/AddressAlias.js +104 -0
- package/dist/AddressAlias.js.map +1 -0
- package/dist/Bip32.d.ts +6 -0
- package/dist/Bip32.d.ts.map +1 -0
- package/dist/Bip32.js +34 -0
- package/dist/Bip32.js.map +1 -0
- package/dist/Chain.d.ts +23 -0
- package/dist/Chain.d.ts.map +1 -0
- package/dist/Chain.js +7 -0
- package/dist/Chain.js.map +1 -0
- package/dist/CheckpointData.d.ts +74 -0
- package/dist/CheckpointData.d.ts.map +1 -0
- package/dist/CheckpointData.js +48 -0
- package/dist/CheckpointData.js.map +1 -0
- package/dist/Checkpoints.d.ts +23 -0
- package/dist/Checkpoints.d.ts.map +1 -0
- package/dist/Checkpoints.js +7 -0
- package/dist/Checkpoints.js.map +1 -0
- package/dist/CoinReservation.d.ts +18 -0
- package/dist/CoinReservation.d.ts.map +1 -0
- package/dist/CoinReservation.js +58 -0
- package/dist/CoinReservation.js.map +1 -0
- package/dist/Coins.d.ts +42 -0
- package/dist/Coins.d.ts.map +1 -0
- package/dist/Coins.js +49 -0
- package/dist/Coins.js.map +1 -0
- package/dist/DynamicFields.d.ts +115 -0
- package/dist/DynamicFields.d.ts.map +1 -0
- package/dist/DynamicFields.js +101 -0
- package/dist/DynamicFields.js.map +1 -0
- package/dist/Ecdsa.d.ts +39 -0
- package/dist/Ecdsa.d.ts.map +1 -0
- package/dist/Ecdsa.js +76 -0
- package/dist/Ecdsa.js.map +1 -0
- package/dist/Ed25519.d.ts +22 -0
- package/dist/Ed25519.d.ts.map +1 -0
- package/dist/Ed25519.js +77 -0
- package/dist/Ed25519.js.map +1 -0
- package/dist/Events.d.ts +105 -0
- package/dist/Events.d.ts.map +1 -0
- package/dist/Events.js +51 -0
- package/dist/Events.js.map +1 -0
- package/dist/Hash.d.ts +16 -0
- package/dist/Hash.d.ts.map +1 -0
- package/dist/Hash.js +32 -0
- package/dist/Hash.js.map +1 -0
- package/dist/MlDsa65.d.ts +17 -0
- package/dist/MlDsa65.d.ts.map +1 -0
- package/dist/MlDsa65.js +84 -0
- package/dist/MlDsa65.js.map +1 -0
- package/dist/Mnemonic.d.ts +20 -0
- package/dist/Mnemonic.d.ts.map +1 -0
- package/dist/Mnemonic.js +71 -0
- package/dist/Mnemonic.js.map +1 -0
- package/dist/Move.d.ts +261 -0
- package/dist/Move.d.ts.map +1 -0
- package/dist/Move.js +232 -0
- package/dist/Move.js.map +1 -0
- package/dist/MultiSig.d.ts +106 -0
- package/dist/MultiSig.d.ts.map +1 -0
- package/dist/MultiSig.js +254 -0
- package/dist/MultiSig.js.map +1 -0
- package/dist/Objects.d.ts +95 -0
- package/dist/Objects.d.ts.map +1 -0
- package/dist/Objects.js +57 -0
- package/dist/Objects.js.map +1 -0
- package/dist/Packages.d.ts +49 -0
- package/dist/Packages.d.ts.map +1 -0
- package/dist/Packages.js +16 -0
- package/dist/Packages.js.map +1 -0
- package/dist/Passkey.d.ts +11 -0
- package/dist/Passkey.d.ts.map +1 -0
- package/dist/Passkey.js +11 -0
- package/dist/Passkey.js.map +1 -0
- package/dist/PrivateKey.d.ts +39 -0
- package/dist/PrivateKey.d.ts.map +1 -0
- package/dist/PrivateKey.js +118 -0
- package/dist/PrivateKey.js.map +1 -0
- package/dist/Ptb.d.ts +413 -0
- package/dist/Ptb.d.ts.map +1 -0
- package/dist/Ptb.js +338 -0
- package/dist/Ptb.js.map +1 -0
- package/dist/Resolve.d.ts +502 -0
- package/dist/Resolve.d.ts.map +1 -0
- package/dist/Resolve.js +1188 -0
- package/dist/Resolve.js.map +1 -0
- package/dist/RpcError.d.ts +19 -0
- package/dist/RpcError.d.ts.map +1 -0
- package/dist/RpcError.js +37 -0
- package/dist/RpcError.js.map +1 -0
- package/dist/Secp256k1.d.ts +11 -0
- package/dist/Secp256k1.d.ts.map +1 -0
- package/dist/Secp256k1.js +23 -0
- package/dist/Secp256k1.js.map +1 -0
- package/dist/Secp256r1.d.ts +11 -0
- package/dist/Secp256r1.d.ts.map +1 -0
- package/dist/Secp256r1.js +23 -0
- package/dist/Secp256r1.js.map +1 -0
- package/dist/SignatureScheme.d.ts +103 -0
- package/dist/SignatureScheme.d.ts.map +1 -0
- package/dist/SignatureScheme.js +93 -0
- package/dist/SignatureScheme.js.map +1 -0
- package/dist/Signer.d.ts +54 -0
- package/dist/Signer.d.ts.map +1 -0
- package/dist/Signer.js +31 -0
- package/dist/Signer.js.map +1 -0
- package/dist/Testing.d.ts +171 -0
- package/dist/Testing.d.ts.map +1 -0
- package/dist/Testing.js +531 -0
- package/dist/Testing.js.map +1 -0
- package/dist/TransactionData.d.ts +3218 -0
- package/dist/TransactionData.d.ts.map +1 -0
- package/dist/TransactionData.js +105 -0
- package/dist/TransactionData.js.map +1 -0
- package/dist/TransactionJson.d.ts +1544 -0
- package/dist/TransactionJson.d.ts.map +1 -0
- package/dist/TransactionJson.js +926 -0
- package/dist/TransactionJson.js.map +1 -0
- package/dist/Transactions.d.ts +181 -0
- package/dist/Transactions.d.ts.map +1 -0
- package/dist/Transactions.js +49 -0
- package/dist/Transactions.js.map +1 -0
- package/dist/Tx.d.ts +1419 -0
- package/dist/Tx.d.ts.map +1 -0
- package/dist/Tx.js +266 -0
- package/dist/Tx.js.map +1 -0
- package/dist/TypeTag.d.ts +42 -0
- package/dist/TypeTag.d.ts.map +1 -0
- package/dist/TypeTag.js +110 -0
- package/dist/TypeTag.js.map +1 -0
- package/dist/Verify.d.ts +23 -0
- package/dist/Verify.d.ts.map +1 -0
- package/dist/Verify.js +29 -0
- package/dist/Verify.js.map +1 -0
- package/dist/enoki/EnokiClient.d.ts +184 -0
- package/dist/enoki/EnokiClient.d.ts.map +1 -0
- package/dist/enoki/EnokiClient.js +105 -0
- package/dist/enoki/EnokiClient.js.map +1 -0
- package/dist/enoki/EnokiHttp.d.ts +33 -0
- package/dist/enoki/EnokiHttp.d.ts.map +1 -0
- package/dist/enoki/EnokiHttp.js +160 -0
- package/dist/enoki/EnokiHttp.js.map +1 -0
- package/dist/enoki/Sponsor.d.ts +119 -0
- package/dist/enoki/Sponsor.d.ts.map +1 -0
- package/dist/enoki/Sponsor.js +170 -0
- package/dist/enoki/Sponsor.js.map +1 -0
- package/dist/enoki/ZkLoginFlow.d.ts +84 -0
- package/dist/enoki/ZkLoginFlow.d.ts.map +1 -0
- package/dist/enoki/ZkLoginFlow.js +138 -0
- package/dist/enoki/ZkLoginFlow.js.map +1 -0
- package/dist/enoki/index.d.ts +9 -0
- package/dist/enoki/index.d.ts.map +1 -0
- package/dist/enoki/index.js +9 -0
- package/dist/enoki/index.js.map +1 -0
- package/dist/graphql/ChainGraphQL.d.ts +35 -0
- package/dist/graphql/ChainGraphQL.d.ts.map +1 -0
- package/dist/graphql/ChainGraphQL.js +62 -0
- package/dist/graphql/ChainGraphQL.js.map +1 -0
- package/dist/graphql/CheckpointDataGraphQL.d.ts +785 -0
- package/dist/graphql/CheckpointDataGraphQL.d.ts.map +1 -0
- package/dist/graphql/CheckpointDataGraphQL.js +157 -0
- package/dist/graphql/CheckpointDataGraphQL.js.map +1 -0
- package/dist/graphql/CheckpointsGraphQL.d.ts +91 -0
- package/dist/graphql/CheckpointsGraphQL.d.ts.map +1 -0
- package/dist/graphql/CheckpointsGraphQL.js +80 -0
- package/dist/graphql/CheckpointsGraphQL.js.map +1 -0
- package/dist/graphql/CoinsGraphQL.d.ts +81 -0
- package/dist/graphql/CoinsGraphQL.d.ts.map +1 -0
- package/dist/graphql/CoinsGraphQL.js +63 -0
- package/dist/graphql/CoinsGraphQL.js.map +1 -0
- package/dist/graphql/DynamicFieldsGraphQL.d.ts +94 -0
- package/dist/graphql/DynamicFieldsGraphQL.d.ts.map +1 -0
- package/dist/graphql/DynamicFieldsGraphQL.js +126 -0
- package/dist/graphql/DynamicFieldsGraphQL.js.map +1 -0
- package/dist/graphql/EventsGraphQL.d.ts +266 -0
- package/dist/graphql/EventsGraphQL.d.ts.map +1 -0
- package/dist/graphql/EventsGraphQL.js +249 -0
- package/dist/graphql/EventsGraphQL.js.map +1 -0
- package/dist/graphql/ObjectsGraphQL.d.ts +130 -0
- package/dist/graphql/ObjectsGraphQL.d.ts.map +1 -0
- package/dist/graphql/ObjectsGraphQL.js +79 -0
- package/dist/graphql/ObjectsGraphQL.js.map +1 -0
- package/dist/graphql/PackagesGraphQL.d.ts +82 -0
- package/dist/graphql/PackagesGraphQL.d.ts.map +1 -0
- package/dist/graphql/PackagesGraphQL.js +145 -0
- package/dist/graphql/PackagesGraphQL.js.map +1 -0
- package/dist/graphql/SuiGraphQL.d.ts +37 -0
- package/dist/graphql/SuiGraphQL.d.ts.map +1 -0
- package/dist/graphql/SuiGraphQL.js +47 -0
- package/dist/graphql/SuiGraphQL.js.map +1 -0
- package/dist/graphql/TransactionsGraphQL.d.ts +1309 -0
- package/dist/graphql/TransactionsGraphQL.d.ts.map +1 -0
- package/dist/graphql/TransactionsGraphQL.js +206 -0
- package/dist/graphql/TransactionsGraphQL.js.map +1 -0
- package/dist/graphql/convert.d.ts +505 -0
- package/dist/graphql/convert.d.ts.map +1 -0
- package/dist/graphql/convert.js +384 -0
- package/dist/graphql/convert.js.map +1 -0
- package/dist/graphql/index.d.ts +41 -0
- package/dist/graphql/index.d.ts.map +1 -0
- package/dist/graphql/index.js +20 -0
- package/dist/graphql/index.js.map +1 -0
- package/dist/graphql/merge.d.ts +8 -0
- package/dist/graphql/merge.d.ts.map +1 -0
- package/dist/graphql/merge.js +55 -0
- package/dist/graphql/merge.js.map +1 -0
- package/dist/graphql/paging.d.ts +219 -0
- package/dist/graphql/paging.d.ts.map +1 -0
- package/dist/graphql/paging.js +74 -0
- package/dist/graphql/paging.js.map +1 -0
- package/dist/graphql/subscription.d.ts +27 -0
- package/dist/graphql/subscription.d.ts.map +1 -0
- package/dist/graphql/subscription.js +47 -0
- package/dist/graphql/subscription.js.map +1 -0
- package/dist/graphql/tip.d.ts +31 -0
- package/dist/graphql/tip.d.ts.map +1 -0
- package/dist/graphql/tip.js +29 -0
- package/dist/graphql/tip.js.map +1 -0
- package/dist/grpc/ChainGrpc.d.ts +11 -0
- package/dist/grpc/ChainGrpc.d.ts.map +1 -0
- package/dist/grpc/ChainGrpc.js +40 -0
- package/dist/grpc/ChainGrpc.js.map +1 -0
- package/dist/grpc/CheckpointDataGrpc.d.ts +6 -0
- package/dist/grpc/CheckpointDataGrpc.d.ts.map +1 -0
- package/dist/grpc/CheckpointDataGrpc.js +27 -0
- package/dist/grpc/CheckpointDataGrpc.js.map +1 -0
- package/dist/grpc/CheckpointsGrpc.d.ts +6 -0
- package/dist/grpc/CheckpointsGrpc.d.ts.map +1 -0
- package/dist/grpc/CheckpointsGrpc.js +25 -0
- package/dist/grpc/CheckpointsGrpc.js.map +1 -0
- package/dist/grpc/CoinsGrpc.d.ts +7 -0
- package/dist/grpc/CoinsGrpc.d.ts.map +1 -0
- package/dist/grpc/CoinsGrpc.js +34 -0
- package/dist/grpc/CoinsGrpc.js.map +1 -0
- package/dist/grpc/DynamicFieldsGrpc.d.ts +11 -0
- package/dist/grpc/DynamicFieldsGrpc.d.ts.map +1 -0
- package/dist/grpc/DynamicFieldsGrpc.js +91 -0
- package/dist/grpc/DynamicFieldsGrpc.js.map +1 -0
- package/dist/grpc/EventsGrpc.d.ts +13 -0
- package/dist/grpc/EventsGrpc.d.ts.map +1 -0
- package/dist/grpc/EventsGrpc.js +88 -0
- package/dist/grpc/EventsGrpc.js.map +1 -0
- package/dist/grpc/GrpcWeb.d.ts +71 -0
- package/dist/grpc/GrpcWeb.d.ts.map +1 -0
- package/dist/grpc/GrpcWeb.js +243 -0
- package/dist/grpc/GrpcWeb.js.map +1 -0
- package/dist/grpc/ObjectsGrpc.d.ts +10 -0
- package/dist/grpc/ObjectsGrpc.d.ts.map +1 -0
- package/dist/grpc/ObjectsGrpc.js +72 -0
- package/dist/grpc/ObjectsGrpc.js.map +1 -0
- package/dist/grpc/PackagesGrpc.d.ts +9 -0
- package/dist/grpc/PackagesGrpc.d.ts.map +1 -0
- package/dist/grpc/PackagesGrpc.js +78 -0
- package/dist/grpc/PackagesGrpc.js.map +1 -0
- package/dist/grpc/Rpc.d.ts +46 -0
- package/dist/grpc/Rpc.d.ts.map +1 -0
- package/dist/grpc/Rpc.js +111 -0
- package/dist/grpc/Rpc.js.map +1 -0
- package/dist/grpc/TransactionsGrpc.d.ts +6 -0
- package/dist/grpc/TransactionsGrpc.d.ts.map +1 -0
- package/dist/grpc/TransactionsGrpc.js +56 -0
- package/dist/grpc/TransactionsGrpc.js.map +1 -0
- package/dist/grpc/cache.d.ts +7 -0
- package/dist/grpc/cache.d.ts.map +1 -0
- package/dist/grpc/cache.js +55 -0
- package/dist/grpc/cache.js.map +1 -0
- package/dist/grpc/convert.d.ts +43 -0
- package/dist/grpc/convert.d.ts.map +1 -0
- package/dist/grpc/convert.js +198 -0
- package/dist/grpc/convert.js.map +1 -0
- package/dist/grpc/generated/lean.d.ts +36 -0
- package/dist/grpc/generated/lean.d.ts.map +1 -0
- package/dist/grpc/generated/lean.js +205 -0
- package/dist/grpc/generated/lean.js.map +1 -0
- package/dist/grpc/generated/proto.d.ts +2000 -0
- package/dist/grpc/generated/proto.d.ts.map +1 -0
- package/dist/grpc/generated/proto.js +356 -0
- package/dist/grpc/generated/proto.js.map +1 -0
- package/dist/grpc/generated/rpc.d.ts +62 -0
- package/dist/grpc/generated/rpc.d.ts.map +1 -0
- package/dist/grpc/generated/rpc.js +324 -0
- package/dist/grpc/generated/rpc.js.map +1 -0
- package/dist/grpc/index.d.ts +58 -0
- package/dist/grpc/index.d.ts.map +1 -0
- package/dist/grpc/index.js +43 -0
- package/dist/grpc/index.js.map +1 -0
- package/dist/grpc/scan.d.ts +79 -0
- package/dist/grpc/scan.d.ts.map +1 -0
- package/dist/grpc/scan.js +126 -0
- package/dist/grpc/scan.js.map +1 -0
- package/dist/grpc/transaction.d.ts +9 -0
- package/dist/grpc/transaction.d.ts.map +1 -0
- package/dist/grpc/transaction.js +168 -0
- package/dist/grpc/transaction.js.map +1 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/allowances.d.ts +18 -0
- package/dist/internal/allowances.d.ts.map +1 -0
- package/dist/internal/allowances.js +194 -0
- package/dist/internal/allowances.js.map +1 -0
- package/dist/internal/mnemonic.d.ts +53 -0
- package/dist/internal/mnemonic.d.ts.map +1 -0
- package/dist/internal/mnemonic.js +66 -0
- package/dist/internal/mnemonic.js.map +1 -0
- package/dist/internal/passkey/BrowserProvider.d.ts +10 -0
- package/dist/internal/passkey/BrowserProvider.d.ts.map +1 -0
- package/dist/internal/passkey/BrowserProvider.js +101 -0
- package/dist/internal/passkey/BrowserProvider.js.map +1 -0
- package/dist/internal/passkey/Passkey.d.ts +104 -0
- package/dist/internal/passkey/Passkey.d.ts.map +1 -0
- package/dist/internal/passkey/Passkey.js +333 -0
- package/dist/internal/passkey/Passkey.js.map +1 -0
- package/dist/internal/passkey/SoftwareProvider.d.ts +23 -0
- package/dist/internal/passkey/SoftwareProvider.d.ts.map +1 -0
- package/dist/internal/passkey/SoftwareProvider.js +61 -0
- package/dist/internal/passkey/SoftwareProvider.js.map +1 -0
- package/dist/lifecycle/Evidence.d.ts +62 -0
- package/dist/lifecycle/Evidence.d.ts.map +1 -0
- package/dist/lifecycle/Evidence.js +30 -0
- package/dist/lifecycle/Evidence.js.map +1 -0
- package/dist/lifecycle/EvidenceGraphQL.d.ts +59 -0
- package/dist/lifecycle/EvidenceGraphQL.d.ts.map +1 -0
- package/dist/lifecycle/EvidenceGraphQL.js +53 -0
- package/dist/lifecycle/EvidenceGraphQL.js.map +1 -0
- package/dist/lifecycle/EvidenceGrpc.d.ts +4 -0
- package/dist/lifecycle/EvidenceGrpc.d.ts.map +1 -0
- package/dist/lifecycle/EvidenceGrpc.js +37 -0
- package/dist/lifecycle/EvidenceGrpc.js.map +1 -0
- package/dist/lifecycle/Journal.d.ts +69 -0
- package/dist/lifecycle/Journal.d.ts.map +1 -0
- package/dist/lifecycle/Journal.js +70 -0
- package/dist/lifecycle/Journal.js.map +1 -0
- package/dist/lifecycle/JournalEntry.d.ts +67 -0
- package/dist/lifecycle/JournalEntry.d.ts.map +1 -0
- package/dist/lifecycle/JournalEntry.js +45 -0
- package/dist/lifecycle/JournalEntry.js.map +1 -0
- package/dist/lifecycle/JournalKeyValueStore.d.ts +30 -0
- package/dist/lifecycle/JournalKeyValueStore.d.ts.map +1 -0
- package/dist/lifecycle/JournalKeyValueStore.js +217 -0
- package/dist/lifecycle/JournalKeyValueStore.js.map +1 -0
- package/dist/lifecycle/KeyValueStoreIndexedDb.d.ts +54 -0
- package/dist/lifecycle/KeyValueStoreIndexedDb.d.ts.map +1 -0
- package/dist/lifecycle/KeyValueStoreIndexedDb.js +321 -0
- package/dist/lifecycle/KeyValueStoreIndexedDb.js.map +1 -0
- package/dist/lifecycle/KeyValueStoreOpfs.d.ts +65 -0
- package/dist/lifecycle/KeyValueStoreOpfs.d.ts.map +1 -0
- package/dist/lifecycle/KeyValueStoreOpfs.js +207 -0
- package/dist/lifecycle/KeyValueStoreOpfs.js.map +1 -0
- package/dist/lifecycle/Lifecycle.d.ts +416 -0
- package/dist/lifecycle/Lifecycle.d.ts.map +1 -0
- package/dist/lifecycle/Lifecycle.js +666 -0
- package/dist/lifecycle/Lifecycle.js.map +1 -0
- package/dist/lifecycle/Outcome.d.ts +132 -0
- package/dist/lifecycle/Outcome.d.ts.map +1 -0
- package/dist/lifecycle/Outcome.js +106 -0
- package/dist/lifecycle/Outcome.js.map +1 -0
- package/dist/lifecycle/SenderLock.d.ts +37 -0
- package/dist/lifecycle/SenderLock.d.ts.map +1 -0
- package/dist/lifecycle/SenderLock.js +57 -0
- package/dist/lifecycle/SenderLock.js.map +1 -0
- package/dist/lifecycle/SenderLockWebLocks.d.ts +37 -0
- package/dist/lifecycle/SenderLockWebLocks.d.ts.map +1 -0
- package/dist/lifecycle/SenderLockWebLocks.js +100 -0
- package/dist/lifecycle/SenderLockWebLocks.js.map +1 -0
- package/dist/lifecycle/SignedTransaction.d.ts +55 -0
- package/dist/lifecycle/SignedTransaction.d.ts.map +1 -0
- package/dist/lifecycle/SignedTransaction.js +109 -0
- package/dist/lifecycle/SignedTransaction.js.map +1 -0
- package/dist/lifecycle/SubmitConfig.d.ts +44 -0
- package/dist/lifecycle/SubmitConfig.d.ts.map +1 -0
- package/dist/lifecycle/SubmitConfig.js +39 -0
- package/dist/lifecycle/SubmitConfig.js.map +1 -0
- package/dist/lifecycle/index.d.ts +13 -0
- package/dist/lifecycle/index.d.ts.map +1 -0
- package/dist/lifecycle/index.js +13 -0
- package/dist/lifecycle/index.js.map +1 -0
- package/dist/wallet/Connection.d.ts +119 -0
- package/dist/wallet/Connection.d.ts.map +1 -0
- package/dist/wallet/Connection.js +197 -0
- package/dist/wallet/Connection.js.map +1 -0
- package/dist/wallet/Features.d.ts +91 -0
- package/dist/wallet/Features.d.ts.map +1 -0
- package/dist/wallet/Features.js +14 -0
- package/dist/wallet/Features.js.map +1 -0
- package/dist/wallet/Wallet.d.ts +151 -0
- package/dist/wallet/Wallet.d.ts.map +1 -0
- package/dist/wallet/Wallet.js +399 -0
- package/dist/wallet/Wallet.js.map +1 -0
- package/dist/wallet/index.d.ts +7 -0
- package/dist/wallet/index.d.ts.map +1 -0
- package/dist/wallet/index.js +7 -0
- package/dist/wallet/index.js.map +1 -0
- package/dist/zklogin/AddressSeed.d.ts +40 -0
- package/dist/zklogin/AddressSeed.d.ts.map +1 -0
- package/dist/zklogin/AddressSeed.js +91 -0
- package/dist/zklogin/AddressSeed.js.map +1 -0
- package/dist/zklogin/Errors.d.ts +24 -0
- package/dist/zklogin/Errors.d.ts.map +1 -0
- package/dist/zklogin/Errors.js +25 -0
- package/dist/zklogin/Errors.js.map +1 -0
- package/dist/zklogin/Jwt.d.ts +51 -0
- package/dist/zklogin/Jwt.d.ts.map +1 -0
- package/dist/zklogin/Jwt.js +159 -0
- package/dist/zklogin/Jwt.js.map +1 -0
- package/dist/zklogin/Nonce.d.ts +9 -0
- package/dist/zklogin/Nonce.d.ts.map +1 -0
- package/dist/zklogin/Nonce.js +34 -0
- package/dist/zklogin/Nonce.js.map +1 -0
- package/dist/zklogin/Poseidon.d.ts +24 -0
- package/dist/zklogin/Poseidon.d.ts.map +1 -0
- package/dist/zklogin/Poseidon.js +54 -0
- package/dist/zklogin/Poseidon.js.map +1 -0
- package/dist/zklogin/PublicIdentifier.d.ts +49 -0
- package/dist/zklogin/PublicIdentifier.d.ts.map +1 -0
- package/dist/zklogin/PublicIdentifier.js +90 -0
- package/dist/zklogin/PublicIdentifier.js.map +1 -0
- package/dist/zklogin/Signature.d.ts +55 -0
- package/dist/zklogin/Signature.d.ts.map +1 -0
- package/dist/zklogin/Signature.js +70 -0
- package/dist/zklogin/Signature.js.map +1 -0
- package/dist/zklogin/ZkLogin.d.ts +41 -0
- package/dist/zklogin/ZkLogin.d.ts.map +1 -0
- package/dist/zklogin/ZkLogin.js +87 -0
- package/dist/zklogin/ZkLogin.js.map +1 -0
- package/dist/zklogin/ZkLoginAddress.d.ts +30 -0
- package/dist/zklogin/ZkLoginAddress.d.ts.map +1 -0
- package/dist/zklogin/ZkLoginAddress.js +31 -0
- package/dist/zklogin/ZkLoginAddress.js.map +1 -0
- package/dist/zklogin/ZkLoginVerifier.d.ts +37 -0
- package/dist/zklogin/ZkLoginVerifier.d.ts.map +1 -0
- package/dist/zklogin/ZkLoginVerifier.js +4 -0
- package/dist/zklogin/ZkLoginVerifier.js.map +1 -0
- package/dist/zklogin/ZkLoginVerifierGrpc.d.ts +12 -0
- package/dist/zklogin/ZkLoginVerifierGrpc.d.ts.map +1 -0
- package/dist/zklogin/ZkLoginVerifierGrpc.js +53 -0
- package/dist/zklogin/ZkLoginVerifierGrpc.js.map +1 -0
- package/dist/zklogin/index.d.ts +17 -0
- package/dist/zklogin/index.d.ts.map +1 -0
- package/dist/zklogin/index.js +17 -0
- package/dist/zklogin/index.js.map +1 -0
- package/dist/zklogin/internal/parse.d.ts +9 -0
- package/dist/zklogin/internal/parse.d.ts.map +1 -0
- package/dist/zklogin/internal/parse.js +33 -0
- package/dist/zklogin/internal/parse.js.map +1 -0
- package/dist/zklogin/internal/poseidon.d.ts +21 -0
- package/dist/zklogin/internal/poseidon.d.ts.map +1 -0
- package/dist/zklogin/internal/poseidon.js +40 -0
- package/dist/zklogin/internal/poseidon.js.map +1 -0
- package/package.json +69 -4
- package/src/Address.ts +45 -0
- package/src/AddressAlias.ts +160 -0
- package/src/Bip32.ts +37 -0
- package/src/Chain.ts +21 -0
- package/src/CheckpointData.ts +106 -0
- package/src/Checkpoints.ts +18 -0
- package/src/CoinReservation.ts +65 -0
- package/src/Coins.ts +86 -0
- package/src/DynamicFields.ts +179 -0
- package/src/Ecdsa.ts +103 -0
- package/src/Ed25519.ts +84 -0
- package/src/Events.ts +133 -0
- package/src/Hash.ts +39 -0
- package/src/MlDsa65.ts +92 -0
- package/src/Mnemonic.ts +109 -0
- package/src/Move.ts +440 -0
- package/src/MultiSig.ts +320 -0
- package/src/Objects.ts +112 -0
- package/src/Packages.ts +52 -0
- package/src/Passkey.ts +10 -0
- package/src/PrivateKey.ts +138 -0
- package/src/Ptb.ts +579 -0
- package/src/Resolve.ts +1367 -0
- package/src/RpcError.ts +41 -0
- package/src/Secp256k1.ts +29 -0
- package/src/Secp256r1.ts +29 -0
- package/src/SignatureScheme.ts +166 -0
- package/src/Signer.ts +62 -0
- package/src/Testing.ts +830 -0
- package/src/TransactionData.ts +134 -0
- package/src/TransactionJson.ts +1002 -0
- package/src/Transactions.ts +211 -0
- package/src/Tx.ts +367 -0
- package/src/TypeTag.ts +123 -0
- package/src/Verify.ts +42 -0
- package/src/enoki/EnokiClient.ts +204 -0
- package/src/enoki/EnokiHttp.ts +222 -0
- package/src/enoki/Sponsor.ts +280 -0
- package/src/enoki/ZkLoginFlow.ts +176 -0
- package/src/enoki/index.ts +8 -0
- package/src/graphql/ChainGraphQL.ts +76 -0
- package/src/graphql/CheckpointDataGraphQL.ts +191 -0
- package/src/graphql/CheckpointsGraphQL.ts +96 -0
- package/src/graphql/CoinsGraphQL.ts +85 -0
- package/src/graphql/DynamicFieldsGraphQL.ts +167 -0
- package/src/graphql/EventsGraphQL.ts +301 -0
- package/src/graphql/ObjectsGraphQL.ts +112 -0
- package/src/graphql/PackagesGraphQL.ts +173 -0
- package/src/graphql/SuiGraphQL.ts +77 -0
- package/src/graphql/TransactionsGraphQL.ts +292 -0
- package/src/graphql/convert.ts +450 -0
- package/src/graphql/index.ts +74 -0
- package/src/graphql/merge.ts +62 -0
- package/src/graphql/paging.ts +110 -0
- package/src/graphql/subscription.ts +58 -0
- package/src/graphql/tip.ts +38 -0
- package/src/grpc/ChainGrpc.ts +51 -0
- package/src/grpc/CheckpointDataGrpc.ts +47 -0
- package/src/grpc/CheckpointsGrpc.ts +37 -0
- package/src/grpc/CoinsGrpc.ts +50 -0
- package/src/grpc/DynamicFieldsGrpc.ts +128 -0
- package/src/grpc/EventsGrpc.ts +101 -0
- package/src/grpc/GrpcWeb.ts +343 -0
- package/src/grpc/ObjectsGrpc.ts +95 -0
- package/src/grpc/PackagesGrpc.ts +98 -0
- package/src/grpc/Rpc.ts +156 -0
- package/src/grpc/TransactionsGrpc.ts +88 -0
- package/src/grpc/cache.ts +68 -0
- package/src/grpc/convert.ts +227 -0
- package/src/grpc/generated/lean.ts +276 -0
- package/src/grpc/generated/proto.ts +2130 -0
- package/src/grpc/generated/rpc.ts +417 -0
- package/src/grpc/index.ts +97 -0
- package/src/grpc/scan.ts +183 -0
- package/src/grpc/transaction.ts +182 -0
- package/src/index.ts +35 -0
- package/src/internal/allowances.ts +238 -0
- package/src/internal/mnemonic.ts +99 -0
- package/src/internal/passkey/BrowserProvider.ts +131 -0
- package/src/internal/passkey/Passkey.ts +408 -0
- package/src/internal/passkey/SoftwareProvider.ts +90 -0
- package/src/lifecycle/Evidence.ts +85 -0
- package/src/lifecycle/EvidenceGraphQL.ts +67 -0
- package/src/lifecycle/EvidenceGrpc.ts +47 -0
- package/src/lifecycle/Journal.ts +117 -0
- package/src/lifecycle/JournalEntry.ts +68 -0
- package/src/lifecycle/JournalKeyValueStore.ts +276 -0
- package/src/lifecycle/KeyValueStoreIndexedDb.ts +361 -0
- package/src/lifecycle/KeyValueStoreOpfs.ts +230 -0
- package/src/lifecycle/Lifecycle.ts +990 -0
- package/src/lifecycle/Outcome.ts +130 -0
- package/src/lifecycle/SenderLock.ts +73 -0
- package/src/lifecycle/SenderLockWebLocks.ts +136 -0
- package/src/lifecycle/SignedTransaction.ts +133 -0
- package/src/lifecycle/SubmitConfig.ts +77 -0
- package/src/lifecycle/index.ts +12 -0
- package/src/wallet/Connection.ts +323 -0
- package/src/wallet/Features.ts +114 -0
- package/src/wallet/Wallet.ts +550 -0
- package/src/wallet/index.ts +6 -0
- package/src/zklogin/AddressSeed.ts +130 -0
- package/src/zklogin/Errors.ts +27 -0
- package/src/zklogin/Jwt.ts +186 -0
- package/src/zklogin/Nonce.ts +46 -0
- package/src/zklogin/Poseidon.ts +62 -0
- package/src/zklogin/PublicIdentifier.ts +111 -0
- package/src/zklogin/Signature.ts +88 -0
- package/src/zklogin/ZkLogin.ts +145 -0
- package/src/zklogin/ZkLoginAddress.ts +72 -0
- package/src/zklogin/ZkLoginVerifier.ts +37 -0
- package/src/zklogin/ZkLoginVerifierGrpc.ts +66 -0
- package/src/zklogin/index.ts +16 -0
- package/src/zklogin/internal/parse.ts +30 -0
- package/src/zklogin/internal/poseidon.ts +47 -0
package/src/Resolve.ts
ADDED
|
@@ -0,0 +1,1367 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turning a `Draft` into `TransactionData`, as a pipeline of small steps.
|
|
3
|
+
*
|
|
4
|
+
* Each step is `Plan -> Effect<Plan, E, R>`: it fills in one thing and states
|
|
5
|
+
* exactly which capability it needs. `Tx.resolve` runs the default pipeline;
|
|
6
|
+
* anything else (a sponsor setting gas, a custom coin picker, a policy check
|
|
7
|
+
* that rejects some Move calls) is one more step in the `pipe`.
|
|
8
|
+
*
|
|
9
|
+
* inputs Objects | Packages object refs, shared mutability, Receiving
|
|
10
|
+
* balances Coins | Objects `Ptb.coin` / `Ptb.balance` from address balance or coins,
|
|
11
|
+
* or under an allowance (checked against the allowance)
|
|
12
|
+
* gasPrice Chain reference gas price
|
|
13
|
+
* budget Transactions | Chain dry run with a placeholder payment
|
|
14
|
+
* payment (strategy) `auto` (default): address balance, else coins;
|
|
15
|
+
* or `addressBalance`, `coins`, `fixed(refs)`
|
|
16
|
+
*
|
|
17
|
+
* Or on the node: `server` completes object inputs, gas price, budget and
|
|
18
|
+
* payment in one simulation (`Transactions.resolve`) and verifies the answer
|
|
19
|
+
* (`verifyResolution`). It runs after `balances` and replaces `inputs`
|
|
20
|
+
* through payment.
|
|
21
|
+
*/
|
|
22
|
+
import * as Effect from "effect/Effect"
|
|
23
|
+
import * as Option from "effect/Option"
|
|
24
|
+
import * as Schema from "effect/Schema"
|
|
25
|
+
import * as Stream from "effect/Stream"
|
|
26
|
+
import * as Bcs from "@unconfirmed/effect-bcs/Bcs"
|
|
27
|
+
import { type Address, normalize } from "./Address.ts"
|
|
28
|
+
import { Chain, type ChainInfo } from "./Chain.ts"
|
|
29
|
+
import { type Balance, type Coin, Coins } from "./Coins.ts"
|
|
30
|
+
import type { ObjectNotFound } from "./Objects.ts"
|
|
31
|
+
import { Objects, type SuiObject } from "./Objects.ts"
|
|
32
|
+
import type { MoveFunction } from "./Packages.ts"
|
|
33
|
+
import { Packages } from "./Packages.ts"
|
|
34
|
+
import * as CoinReservation from "./CoinReservation.ts"
|
|
35
|
+
import type { AllowanceIntent, BalanceIntent, Command, Draft, Input } from "./Ptb.ts"
|
|
36
|
+
import type { RpcError } from "./RpcError.ts"
|
|
37
|
+
import * as T from "./TransactionData.ts"
|
|
38
|
+
import { type Effects, type Status, Transactions, type UnresolvedTransaction } from "./Transactions.ts"
|
|
39
|
+
import * as TypeTag from "./TypeTag.ts"
|
|
40
|
+
|
|
41
|
+
export interface Plan {
|
|
42
|
+
readonly sender: Address
|
|
43
|
+
readonly draft: Draft
|
|
44
|
+
readonly gasOwner?: Address
|
|
45
|
+
readonly gasPrice?: bigint
|
|
46
|
+
readonly gasBudget?: bigint
|
|
47
|
+
readonly gasPayment?: ReadonlyArray<T.ObjectRef>
|
|
48
|
+
readonly expiration?: T.TransactionExpiration
|
|
49
|
+
/** The highest budget to accept: `Resolve.server` refuses a node's budget above it (default 50 SUI), `Tx.resolve` any. */
|
|
50
|
+
readonly maxGasBudget?: bigint
|
|
51
|
+
/** Reads made up front by `Resolve.prefetch`; later steps use them instead of asking again. */
|
|
52
|
+
readonly prefetched?: Prefetched
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** What `Resolve.prefetch` read, all at once, before the steps that need it. */
|
|
56
|
+
export interface Prefetched {
|
|
57
|
+
/** Absent when nothing in the plan needed it (budget and expiration given, custom payment). */
|
|
58
|
+
readonly chain?: ChainInfo
|
|
59
|
+
/** Whose SUI `gasBalance` and `gasCoins` are (a step ignores them for anyone else). */
|
|
60
|
+
readonly owner: Address
|
|
61
|
+
readonly gasBalance?: Balance
|
|
62
|
+
/** The owner's SUI coins in listing order: every one when fewer than a page, else the first page. */
|
|
63
|
+
readonly gasCoins?: ReadonlyArray<Coin>
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export class Incomplete extends /* @__PURE__ */ Schema.TaggedError<Incomplete>()("Incomplete", {
|
|
67
|
+
missing: Schema.String
|
|
68
|
+
}) {
|
|
69
|
+
override get message(): string {
|
|
70
|
+
return `missing ${this.missing}`
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The plan can't become valid transaction data (an invalid address, too many inputs, a reference to a later result, ...). */
|
|
75
|
+
export class InvalidTransaction extends /* @__PURE__ */ Schema.TaggedError<InvalidTransaction>()("InvalidTransaction", {
|
|
76
|
+
reason: Schema.String
|
|
77
|
+
}) {
|
|
78
|
+
override get message(): string {
|
|
79
|
+
return this.reason
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* A Move abort as the node reports it, from its structured error (not the
|
|
85
|
+
* description text). The same field (`abort`) on `GasEstimationFailed`,
|
|
86
|
+
* `Tx.SimulationFailed` and `Tx.ExecutionFailed`, so a caller matches one
|
|
87
|
+
* shape wherever the abort surfaced. Location fields are present when the
|
|
88
|
+
* transport reports them (gRPC and GraphQL do).
|
|
89
|
+
*/
|
|
90
|
+
export const MoveAbort = /* @__PURE__ */ Schema.Struct({
|
|
91
|
+
/**
|
|
92
|
+
* The abort code: for a clever error (`#[error(code = N)] const E: vector<u8> = ...`)
|
|
93
|
+
* the code it declares, otherwise the u64 the chain aborted with (for a clever
|
|
94
|
+
* error without a code, its encoded u64). gRPC and GraphQL agree on it. Match
|
|
95
|
+
* a clever error by `constant`.
|
|
96
|
+
*/
|
|
97
|
+
code: Schema.BigInt,
|
|
98
|
+
/** The aborting module's package. */
|
|
99
|
+
package: /* @__PURE__ */ Schema.optionalKey(Schema.String),
|
|
100
|
+
module: /* @__PURE__ */ Schema.optionalKey(Schema.String),
|
|
101
|
+
function: /* @__PURE__ */ Schema.optionalKey(Schema.String),
|
|
102
|
+
/** The bytecode offset of the abort in `function`. */
|
|
103
|
+
instruction: /* @__PURE__ */ Schema.optionalKey(Schema.Number),
|
|
104
|
+
/** A clever error's constant (`EAliasAlreadyExists`). */
|
|
105
|
+
constant: /* @__PURE__ */ Schema.optionalKey(Schema.String),
|
|
106
|
+
/** A clever error's source line. */
|
|
107
|
+
line: /* @__PURE__ */ Schema.optionalKey(Schema.Number),
|
|
108
|
+
/** A clever error's value, rendered as text by the node. */
|
|
109
|
+
rendered: /* @__PURE__ */ Schema.optionalKey(Schema.String)
|
|
110
|
+
})
|
|
111
|
+
export type MoveAbort = typeof MoveAbort.Type
|
|
112
|
+
|
|
113
|
+
/** The fields every failed-execution error shares: the node's description, the failing command, the Move abort. */
|
|
114
|
+
export const FailureFields = {
|
|
115
|
+
/** The node's description of the failure (free text; match on `command` and `abort` instead). */
|
|
116
|
+
description: Schema.String,
|
|
117
|
+
command: /* @__PURE__ */ Schema.optionalKey(Schema.Number),
|
|
118
|
+
abort: /* @__PURE__ */ Schema.optionalKey(MoveAbort)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** `<description> in command N, abort code C at 0x…::module::function`. */
|
|
122
|
+
export const describeFailure = (f: { readonly description: string; readonly command?: number; readonly abort?: MoveAbort }) => {
|
|
123
|
+
const a = f.abort
|
|
124
|
+
const at = a?.module === undefined ? "" : ` at ${a.package ?? "?"}::${a.module}${a.function === undefined ? "" : `::${a.function}`}`
|
|
125
|
+
return `${f.description}${f.command === undefined ? "" : ` in command ${f.command}`}${a === undefined ? "" : `, abort code ${a.code}${at}`}`
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** The budget dry run (or the node's resolving simulation) failed: the transaction would fail on chain as it stands. */
|
|
129
|
+
export class GasEstimationFailed extends /* @__PURE__ */ Schema.TaggedError<GasEstimationFailed>()("GasEstimationFailed", FailureFields) {
|
|
130
|
+
override get message(): string {
|
|
131
|
+
return `gas estimation failed: ${describeFailure(this)}`
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* The node's resolution (`Resolve.server`) failed verification: it changed
|
|
137
|
+
* something it must not (sender, gas owner, commands, an input it was given),
|
|
138
|
+
* or picked something it may not (another object, a weaker shared-object
|
|
139
|
+
* mutability, gas coins the gas owner doesn't own, an unbounded validity).
|
|
140
|
+
* Nothing was signed.
|
|
141
|
+
*/
|
|
142
|
+
export class ResolutionRejected extends /* @__PURE__ */ Schema.TaggedError<ResolutionRejected>()("ResolutionRejected", {
|
|
143
|
+
reason: Schema.String
|
|
144
|
+
}) {
|
|
145
|
+
override get message(): string {
|
|
146
|
+
return `refused the node's resolution: ${this.reason}`
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** The resolved budget is above the caller's `maxGasBudget`. */
|
|
151
|
+
export class GasBudgetExceeded extends /* @__PURE__ */ Schema.TaggedError<GasBudgetExceeded>()("GasBudgetExceeded", {
|
|
152
|
+
budget: Schema.BigInt,
|
|
153
|
+
max: Schema.BigInt
|
|
154
|
+
}) {
|
|
155
|
+
override get message(): string {
|
|
156
|
+
return `gas budget ${this.budget} is above the maximum ${this.max}`
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* The gas owner's SUI can't pay. `required` is the budget, plus, when commands
|
|
162
|
+
* spend from the gas coin, the amounts they split off it.
|
|
163
|
+
*/
|
|
164
|
+
export class InsufficientGas extends /* @__PURE__ */ Schema.TaggedError<InsufficientGas>()("InsufficientGas", {
|
|
165
|
+
owner: Schema.String,
|
|
166
|
+
required: Schema.BigInt,
|
|
167
|
+
available: Schema.BigInt
|
|
168
|
+
}) {
|
|
169
|
+
override get message(): string {
|
|
170
|
+
return `${this.owner} has ${this.available} MIST for gas, needs ${this.required}`
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export class InsufficientBalance extends /* @__PURE__ */ Schema.TaggedError<InsufficientBalance>()("InsufficientBalance", {
|
|
175
|
+
owner: Schema.String,
|
|
176
|
+
coinType: Schema.String,
|
|
177
|
+
required: Schema.BigInt,
|
|
178
|
+
available: Schema.BigInt
|
|
179
|
+
}) {
|
|
180
|
+
override get message(): string {
|
|
181
|
+
return `${this.owner} has ${this.available} of ${this.coinType}, needs ${this.required}`
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export class InvalidBalanceIntent extends /* @__PURE__ */ Schema.TaggedError<InvalidBalanceIntent>()("InvalidBalanceIntent", {
|
|
186
|
+
reason: Schema.String
|
|
187
|
+
}) {
|
|
188
|
+
override get message(): string {
|
|
189
|
+
return this.reason
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** No object with the allowance's id. */
|
|
194
|
+
export class AllowanceNotFound extends /* @__PURE__ */ Schema.TaggedError<AllowanceNotFound>()("AllowanceNotFound", {
|
|
195
|
+
allowance: Schema.String
|
|
196
|
+
}) {
|
|
197
|
+
override get message(): string {
|
|
198
|
+
return `allowance ${this.allowance} not found`
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** The object isn't a shared `Allowance<Balance<T>>` for the intent's coin type, or its funder isn't the one the caller named. */
|
|
203
|
+
export class InvalidAllowance extends /* @__PURE__ */ Schema.TaggedError<InvalidAllowance>()("InvalidAllowance", {
|
|
204
|
+
allowance: Schema.String,
|
|
205
|
+
reason: Schema.String
|
|
206
|
+
}) {
|
|
207
|
+
override get message(): string {
|
|
208
|
+
return `allowance ${this.allowance}: ${this.reason}`
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* The permit doesn't fit the allowance: an app-bound allowance spent without a
|
|
214
|
+
* `SpendPermit`, a permit for another app, or a permit for an allowance that
|
|
215
|
+
* isn't app-bound. `null` means "no app".
|
|
216
|
+
*/
|
|
217
|
+
export class AllowanceAppMismatch extends /* @__PURE__ */ Schema.TaggedError<AllowanceAppMismatch>()("AllowanceAppMismatch", {
|
|
218
|
+
allowance: Schema.String,
|
|
219
|
+
allowanceApp: Schema.NullOr(Schema.String),
|
|
220
|
+
permitApp: Schema.NullOr(Schema.String)
|
|
221
|
+
}) {
|
|
222
|
+
override get message(): string {
|
|
223
|
+
return `allowance ${this.allowance} is for app ${this.allowanceApp ?? "none"}, permit is for ${this.permitApp ?? "none"}`
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** The sender isn't the allowance's spender (`null`: the allowance has none, so nobody can spend). */
|
|
228
|
+
export class AllowanceSpenderMismatch extends /* @__PURE__ */ Schema.TaggedError<AllowanceSpenderMismatch>()("AllowanceSpenderMismatch", {
|
|
229
|
+
allowance: Schema.String,
|
|
230
|
+
spender: Schema.NullOr(Schema.String),
|
|
231
|
+
sender: Schema.String
|
|
232
|
+
}) {
|
|
233
|
+
override get message(): string {
|
|
234
|
+
return `allowance ${this.allowance} spender is ${this.spender ?? "none"}, sender is ${this.sender}`
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** The allowance's start time (inclusive) is after the chain clock. */
|
|
239
|
+
export class AllowanceNotStarted extends /* @__PURE__ */ Schema.TaggedError<AllowanceNotStarted>()("AllowanceNotStarted", {
|
|
240
|
+
allowance: Schema.String,
|
|
241
|
+
startTimestampMs: Schema.BigInt,
|
|
242
|
+
nowMs: Schema.BigInt
|
|
243
|
+
}) {
|
|
244
|
+
override get message(): string {
|
|
245
|
+
return `allowance ${this.allowance} starts at ${this.startTimestampMs} ms, now ${this.nowMs}`
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** The allowance's expiration (exclusive) has passed on the chain clock. */
|
|
250
|
+
export class AllowanceExpired extends /* @__PURE__ */ Schema.TaggedError<AllowanceExpired>()("AllowanceExpired", {
|
|
251
|
+
allowance: Schema.String,
|
|
252
|
+
expirationTimestampMs: Schema.BigInt,
|
|
253
|
+
nowMs: Schema.BigInt
|
|
254
|
+
}) {
|
|
255
|
+
override get message(): string {
|
|
256
|
+
return `allowance ${this.allowance} expired at ${this.expirationTimestampMs} ms, now ${this.nowMs}`
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** The transaction's spends would exceed the allowance's lifetime cap or its current rate-limit window. */
|
|
261
|
+
export class InsufficientAllowance extends /* @__PURE__ */ Schema.TaggedError<InsufficientAllowance>()("InsufficientAllowance", {
|
|
262
|
+
allowance: Schema.String,
|
|
263
|
+
coinType: Schema.String,
|
|
264
|
+
limit: Schema.Literals(["lifetime", "rate"]),
|
|
265
|
+
required: Schema.BigInt,
|
|
266
|
+
available: Schema.BigInt
|
|
267
|
+
}) {
|
|
268
|
+
override get message(): string {
|
|
269
|
+
return `allowance ${this.allowance} ${this.limit} limit has ${this.available} of ${this.coinType}, needs ${this.required}`
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** Everything allowance resolution can refuse before signing. */
|
|
274
|
+
export type AllowanceError =
|
|
275
|
+
| AllowanceNotFound
|
|
276
|
+
| InvalidAllowance
|
|
277
|
+
| AllowanceAppMismatch
|
|
278
|
+
| AllowanceSpenderMismatch
|
|
279
|
+
| AllowanceNotStarted
|
|
280
|
+
| AllowanceExpired
|
|
281
|
+
| InsufficientAllowance
|
|
282
|
+
|
|
283
|
+
// -----------------------------------------------------------------------------
|
|
284
|
+
// inputs
|
|
285
|
+
// -----------------------------------------------------------------------------
|
|
286
|
+
|
|
287
|
+
const TX_CONTEXT = "0x0000000000000000000000000000000000000000000000000000000000000002::tx_context::TxContext"
|
|
288
|
+
const RECEIVING = "0x0000000000000000000000000000000000000000000000000000000000000002::transfer::Receiving"
|
|
289
|
+
|
|
290
|
+
interface Usage {
|
|
291
|
+
readonly mutable: boolean
|
|
292
|
+
readonly receiving: boolean
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/** How each input is used: from commands, and from the called functions' parameter references. */
|
|
296
|
+
const usages = (draft: Draft, functions: ReadonlyMap<number, MoveFunction>) => {
|
|
297
|
+
const out = new Map<number, Usage>()
|
|
298
|
+
const mark = (arg: T.Argument, mutable: boolean, receiving = false) => {
|
|
299
|
+
if (arg._tag !== "Input") return
|
|
300
|
+
const u = out.get(arg.value)
|
|
301
|
+
out.set(arg.value, { mutable: (u?.mutable ?? false) || mutable, receiving: (u?.receiving ?? false) || receiving })
|
|
302
|
+
}
|
|
303
|
+
draft.commands.forEach((c, i) => {
|
|
304
|
+
switch (c._tag) {
|
|
305
|
+
case "MoveCall": {
|
|
306
|
+
const params = (functions.get(i)?.parameters ?? []).filter((p) => p.typeName !== TX_CONTEXT)
|
|
307
|
+
c.arguments.forEach((a, j) => {
|
|
308
|
+
const p = params[j]
|
|
309
|
+
mark(a, p === undefined || p.reference !== "Immutable", p?.typeName === RECEIVING)
|
|
310
|
+
})
|
|
311
|
+
return
|
|
312
|
+
}
|
|
313
|
+
case "TransferObjects":
|
|
314
|
+
return c.objects.forEach((a) => mark(a, true))
|
|
315
|
+
case "SplitCoins":
|
|
316
|
+
return mark(c.coin, true)
|
|
317
|
+
case "MergeCoins":
|
|
318
|
+
return [c.destination, ...c.sources].forEach((a) => mark(a, true))
|
|
319
|
+
case "MakeMoveVec":
|
|
320
|
+
return c.elements.forEach((a) => mark(a, true))
|
|
321
|
+
case "AllowanceIntent":
|
|
322
|
+
mark(c.allowance, true)
|
|
323
|
+
mark(c.clock, false)
|
|
324
|
+
if (c.permit) mark(c.permit, true)
|
|
325
|
+
return
|
|
326
|
+
default:
|
|
327
|
+
return
|
|
328
|
+
}
|
|
329
|
+
})
|
|
330
|
+
return out
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
const objectArg = (o: SuiObject, usage: Usage | undefined, forced: boolean | undefined): T.ObjectArg | InvalidTransaction => {
|
|
334
|
+
if (o.owner._tag === "Unknown") {
|
|
335
|
+
return new InvalidTransaction({ reason: `object ${o.objectId} has an owner kind (${o.owner.kind}) this SDK can't use as an input` })
|
|
336
|
+
}
|
|
337
|
+
if (o.owner._tag === "Shared" || o.owner._tag === "ConsensusAddressOwner") {
|
|
338
|
+
const mutable = forced ?? usage?.mutable ?? true
|
|
339
|
+
return {
|
|
340
|
+
_tag: "SharedObject",
|
|
341
|
+
objectId: o.objectId,
|
|
342
|
+
initialSharedVersion: o.owner._tag === "Shared" ? o.owner.initialSharedVersion : o.owner.startVersion,
|
|
343
|
+
mutability: { _tag: mutable ? "Mutable" : "Immutable" }
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
const ref = { objectId: o.objectId, version: o.version, digest: o.digest }
|
|
347
|
+
return usage?.receiving ? { _tag: "Receiving", ...ref } : { _tag: "ImmOrOwnedObject", ...ref }
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* The signatures of the Move calls that take one of the `pending` inputs, by
|
|
352
|
+
* command index: one `getFunction` per target, all at once.
|
|
353
|
+
*/
|
|
354
|
+
const functionsFor = (draft: Draft, pending: ReadonlySet<number>): Effect.Effect<Map<number, MoveFunction>, RpcError, Packages> => {
|
|
355
|
+
const targetOf = (c: Extract<Command, { _tag: "MoveCall" }>) => `${c.package}::${c.module}::${c.function}`
|
|
356
|
+
const calls = draft.commands.flatMap((c, index) =>
|
|
357
|
+
c._tag === "MoveCall" && c.arguments.some((a) => a._tag === "Input" && pending.has(a.value)) ? [{ c, index }] : []
|
|
358
|
+
)
|
|
359
|
+
if (calls.length === 0) return Effect.succeed(new Map())
|
|
360
|
+
const targets = new Map(calls.map(({ c }) => [targetOf(c), c] as const))
|
|
361
|
+
return Effect.flatMap(Effect.service(Packages), (packages) =>
|
|
362
|
+
Effect.map(
|
|
363
|
+
Effect.forEach(targets, ([key, c]) => Effect.map(packages.getFunction(c), (f) => [key, f] as const), { concurrency: "unbounded" }),
|
|
364
|
+
(signatures) => {
|
|
365
|
+
const byTarget = new Map(signatures)
|
|
366
|
+
return new Map(calls.map(({ c, index }) => [index, byTarget.get(targetOf(c))!] as const))
|
|
367
|
+
}
|
|
368
|
+
))
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/** Inputs that allowance intents spend from: `Resolve.balances` reads and resolves those itself. */
|
|
372
|
+
const allowanceInputs = (draft: Draft) =>
|
|
373
|
+
new Set(draft.commands.flatMap((c) => (c._tag === "AllowanceIntent" && c.allowance._tag === "Input" ? [c.allowance.value] : [])))
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Resolve object inputs. All lookups run at once; the `Objects` and
|
|
377
|
+
* `Packages` implementations batch and cache them. Signatures are read only
|
|
378
|
+
* for Move calls that take an unresolved object, once per target. Allowance
|
|
379
|
+
* objects are left for `Resolve.balances`, which reads their contents anyway.
|
|
380
|
+
*/
|
|
381
|
+
export const inputs = (plan: Plan): Effect.Effect<Plan, ObjectNotFound | RpcError | InvalidTransaction, Objects | Packages> =>
|
|
382
|
+
Effect.gen(function*() {
|
|
383
|
+
const skip = allowanceInputs(plan.draft)
|
|
384
|
+
const unresolved = plan.draft.inputs.flatMap((input, index) =>
|
|
385
|
+
input._tag === "UnresolvedObject" && !skip.has(index) ? [{ input, index }] : []
|
|
386
|
+
)
|
|
387
|
+
if (unresolved.length === 0) return plan
|
|
388
|
+
const objects = yield* Objects
|
|
389
|
+
const [resolved, functions] = yield* Effect.all([
|
|
390
|
+
Effect.forEach(unresolved, ({ input }) => objects.get(input.objectId), { concurrency: "unbounded" }),
|
|
391
|
+
functionsFor(plan.draft, new Set(unresolved.map(({ index }) => index)))
|
|
392
|
+
], { concurrency: "unbounded" })
|
|
393
|
+
const use = usages(plan.draft, functions)
|
|
394
|
+
const next = [...plan.draft.inputs]
|
|
395
|
+
for (const [i, { input, index }] of unresolved.entries()) {
|
|
396
|
+
const arg = objectArg(resolved[i]!, use.get(index), input.mutable)
|
|
397
|
+
if (arg instanceof InvalidTransaction) return yield* arg
|
|
398
|
+
next[index] = { _tag: "Object", value: arg }
|
|
399
|
+
}
|
|
400
|
+
return { ...plan, draft: { ...plan.draft, inputs: next } }
|
|
401
|
+
})
|
|
402
|
+
|
|
403
|
+
// -----------------------------------------------------------------------------
|
|
404
|
+
// balances (coin / balance intents)
|
|
405
|
+
// -----------------------------------------------------------------------------
|
|
406
|
+
|
|
407
|
+
/** Every argument a command reads. */
|
|
408
|
+
export const argumentsOf = (c: Command): ReadonlyArray<T.Argument> => {
|
|
409
|
+
switch (c._tag) {
|
|
410
|
+
case "MoveCall":
|
|
411
|
+
return c.arguments
|
|
412
|
+
case "TransferObjects":
|
|
413
|
+
return [...c.objects, c.address]
|
|
414
|
+
case "SplitCoins":
|
|
415
|
+
return [c.coin, ...c.amounts]
|
|
416
|
+
case "MergeCoins":
|
|
417
|
+
return [c.destination, ...c.sources]
|
|
418
|
+
case "MakeMoveVec":
|
|
419
|
+
return c.elements
|
|
420
|
+
case "Upgrade":
|
|
421
|
+
return [c.ticket]
|
|
422
|
+
case "AllowanceIntent":
|
|
423
|
+
return c.permit ? [c.allowance, c.clock, c.permit] : [c.allowance, c.clock]
|
|
424
|
+
default:
|
|
425
|
+
return []
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
export function mapArguments(c: T.Command, f: (a: T.Argument) => T.Argument): T.Command
|
|
430
|
+
export function mapArguments(c: Command, f: (a: T.Argument) => T.Argument): Command
|
|
431
|
+
export function mapArguments(c: Command, f: (a: T.Argument) => T.Argument): Command {
|
|
432
|
+
switch (c._tag) {
|
|
433
|
+
case "MoveCall":
|
|
434
|
+
return { ...c, arguments: c.arguments.map(f) }
|
|
435
|
+
case "TransferObjects":
|
|
436
|
+
return { ...c, objects: c.objects.map(f), address: f(c.address) }
|
|
437
|
+
case "SplitCoins":
|
|
438
|
+
return { ...c, coin: f(c.coin), amounts: c.amounts.map(f) }
|
|
439
|
+
case "MergeCoins":
|
|
440
|
+
return { ...c, destination: f(c.destination), sources: c.sources.map(f) }
|
|
441
|
+
case "MakeMoveVec":
|
|
442
|
+
return { ...c, elements: c.elements.map(f) }
|
|
443
|
+
case "Upgrade":
|
|
444
|
+
return { ...c, ticket: f(c.ticket) }
|
|
445
|
+
case "AllowanceIntent":
|
|
446
|
+
return { ...c, allowance: f(c.allowance), clock: f(c.clock), ...(c.permit && { permit: f(c.permit) }) }
|
|
447
|
+
default:
|
|
448
|
+
return c
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
const encodeU64 = /* @__PURE__ */ Bcs.encodeSync(Bcs.u64)
|
|
453
|
+
const encodeAddress = /* @__PURE__ */ Bcs.encodeSync(Bcs.Address)
|
|
454
|
+
const GAS = "gas"
|
|
455
|
+
|
|
456
|
+
/** @internal */
|
|
457
|
+
export const moveCall = (
|
|
458
|
+
target: string,
|
|
459
|
+
typeArguments: string | ReadonlyArray<string>,
|
|
460
|
+
args: ReadonlyArray<T.Argument>
|
|
461
|
+
): T.Command => {
|
|
462
|
+
const [pkg, module, fn] = target.split("::") as [string, string, string]
|
|
463
|
+
return {
|
|
464
|
+
_tag: "MoveCall",
|
|
465
|
+
package: normalize(pkg),
|
|
466
|
+
module,
|
|
467
|
+
function: fn,
|
|
468
|
+
typeArguments: (typeof typeArguments === "string" ? [typeArguments] : typeArguments).map(TypeTag.parse),
|
|
469
|
+
arguments: args
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/** Where a command's results go after a rewrite: the same shape at a new position. */
|
|
474
|
+
/** @internal */
|
|
475
|
+
export const movedTo = (at: number) => (n: number | undefined): T.Argument =>
|
|
476
|
+
n === undefined ? { _tag: "Result", value: at } : { _tag: "NestedResult", value: [at, n] }
|
|
477
|
+
|
|
478
|
+
/** A draft the intent rewrite can't map; thrown inside the rewrite and turned into `InvalidBalanceIntent`. */
|
|
479
|
+
class RewriteError {
|
|
480
|
+
constructor(readonly reason: string) {}
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/** An intent's single result, which is all a `Result` or `NestedResult(_, 0)` of it can mean. */
|
|
484
|
+
/** @internal */
|
|
485
|
+
export const singleResult = (index: number, r: T.Argument) => (n: number | undefined): T.Argument => {
|
|
486
|
+
if (n === undefined || n === 0) return r
|
|
487
|
+
throw new RewriteError(`a coin/balance intent has a single result; NestedResult(${index}, ${n}) is invalid`)
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/** Map a result reference through the rewrite so far; a reference to a command not yet seen is invalid. */
|
|
491
|
+
/** @internal */
|
|
492
|
+
export const remapWith = (results: ReadonlyMap<number, (nested: number | undefined) => T.Argument>) => (a: T.Argument): T.Argument => {
|
|
493
|
+
if (a._tag !== "Result" && a._tag !== "NestedResult") return a
|
|
494
|
+
const index = a._tag === "Result" ? a.value : a.value[0]
|
|
495
|
+
const to = results.get(index)
|
|
496
|
+
if (to === undefined) throw new RewriteError(`command result ${index} is used before (or by) the command that makes it`)
|
|
497
|
+
return to(a._tag === "Result" ? undefined : a.value[1])
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/** Run a rewrite; its `RewriteError` becomes `InvalidBalanceIntent`. */
|
|
501
|
+
/** @internal */
|
|
502
|
+
export const rewrite = <A>(f: () => A): Effect.Effect<A, InvalidBalanceIntent> =>
|
|
503
|
+
Effect.try({
|
|
504
|
+
try: f,
|
|
505
|
+
catch: (e) => {
|
|
506
|
+
if (e instanceof RewriteError) return new InvalidBalanceIntent({ reason: e.reason })
|
|
507
|
+
throw e
|
|
508
|
+
}
|
|
509
|
+
})
|
|
510
|
+
|
|
511
|
+
// -----------------------------------------------------------------------------
|
|
512
|
+
// allowances (coin / balance intents under an allowance)
|
|
513
|
+
// -----------------------------------------------------------------------------
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Resolve allowance intents (`Ptb.coin({ allowance })` / `Ptb.balance({ allowance })`)
|
|
517
|
+
* as `@mysten/sui`'s `AllowanceBalance` resolver does: each becomes a
|
|
518
|
+
* `SenderAllowance` withdrawal from the funder, `allowance::balance_spend`
|
|
519
|
+
* (or `app_balance_spend<T, A>` with the permit) and, for a coin,
|
|
520
|
+
* `coin::from_balance`. The allowance input becomes a mutable shared object.
|
|
521
|
+
*
|
|
522
|
+
* Before that it reads each allowance (and, if its settings are time-bound or
|
|
523
|
+
* windowed, the clock) and refuses what the chain would abort: the wrong type
|
|
524
|
+
* or funder, a missing or wrong permit, a sender that isn't the spender, a
|
|
525
|
+
* spend outside the start/expiration window, beyond the lifetime cap or the
|
|
526
|
+
* current rate-limit window, or more than the funder's address balance holds.
|
|
527
|
+
*
|
|
528
|
+
* `Resolve.balances` runs this first; it's exported for hand-built pipelines.
|
|
529
|
+
*/
|
|
530
|
+
export const allowances = (
|
|
531
|
+
plan: Plan
|
|
532
|
+
): Effect.Effect<Plan, AllowanceError | InsufficientBalance | InvalidBalanceIntent | RpcError, Objects | Coins> => {
|
|
533
|
+
// The resolver travels with the intent, so programs without allowance intents don't link it.
|
|
534
|
+
const intent = plan.draft.commands.find((c): c is AllowanceIntent => c._tag === "AllowanceIntent")
|
|
535
|
+
return intent === undefined ? Effect.succeed(plan) : intent.resolve(plan)
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
const senderWithdrawal = (amount: bigint, coinType: string): T.CallArg => ({
|
|
540
|
+
_tag: "FundsWithdrawal",
|
|
541
|
+
reservation: { _tag: "MaxAmountU64", value: amount },
|
|
542
|
+
typeArg: { _tag: "Balance", value: TypeTag.parse(coinType) },
|
|
543
|
+
withdrawFrom: { _tag: "Sender" }
|
|
544
|
+
})
|
|
545
|
+
|
|
546
|
+
interface TypePlan {
|
|
547
|
+
/** Normalized coin type, `T`. */
|
|
548
|
+
readonly coinType: string
|
|
549
|
+
readonly intents: Array<BalanceIntent>
|
|
550
|
+
total: bigint
|
|
551
|
+
/** The sender's address balance of this type, minus existing withdrawals. */
|
|
552
|
+
addressBalance: bigint
|
|
553
|
+
coins: Array<T.ObjectRef>
|
|
554
|
+
coinTotal: bigint
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* Source every `Ptb.coin` / `Ptb.balance` intent, replacing each with real
|
|
559
|
+
* commands (and remapping every later result reference), as `@mysten/sui`'s
|
|
560
|
+
* `coinWithBalance` resolver does:
|
|
561
|
+
*
|
|
562
|
+
* - all intents of a type are `balance` and the address balance covers them:
|
|
563
|
+
* one `balance::redeem_funds` per intent, no coins touched;
|
|
564
|
+
* - otherwise one source coin per type — `coin::redeem_funds` of the whole
|
|
565
|
+
* amount when the address balance covers it, else the gas coin (SUI with
|
|
566
|
+
* `useGasCoin`), else owned coins topped up from the address balance — then
|
|
567
|
+
* a single `SplitCoins` for all intents of that type, `coin::into_balance`
|
|
568
|
+
* for balance intents, and the remainder sent back to the sender's address
|
|
569
|
+
* balance (or a zero coin destroyed).
|
|
570
|
+
*
|
|
571
|
+
* Allowance intents (`Ptb.coin({ allowance })`) are resolved first, by
|
|
572
|
+
* `Resolve.allowances`, as `@mysten/sui` resolves `AllowanceBalance` before
|
|
573
|
+
* `CoinWithBalance`; the `Objects` requirement is only used for those.
|
|
574
|
+
*
|
|
575
|
+
* Run it after `Resolve.inputs` (so coins already used as inputs are skipped)
|
|
576
|
+
* and before the gas steps.
|
|
577
|
+
*/
|
|
578
|
+
export const balances = (
|
|
579
|
+
plan: Plan
|
|
580
|
+
): Effect.Effect<Plan, RpcError | InsufficientBalance | InvalidBalanceIntent | AllowanceError, Coins | Objects> =>
|
|
581
|
+
Effect.flatMap(allowances(plan), coinIntents)
|
|
582
|
+
|
|
583
|
+
const coinIntents = (
|
|
584
|
+
plan: Plan
|
|
585
|
+
): Effect.Effect<Plan, RpcError | InsufficientBalance | InvalidBalanceIntent, Coins> =>
|
|
586
|
+
Effect.gen(function*() {
|
|
587
|
+
if (!plan.draft.commands.some((c) => c._tag === "BalanceIntent")) return plan
|
|
588
|
+
const coinsService = yield* Coins
|
|
589
|
+
|
|
590
|
+
// Group non-zero intents by source key ("gas" = SUI that may use the gas coin).
|
|
591
|
+
const types = new Map<string, TypePlan>()
|
|
592
|
+
for (const c of plan.draft.commands) {
|
|
593
|
+
if (c._tag !== "BalanceIntent" || c.amount === 0n) continue
|
|
594
|
+
const key = c.coinType === TypeTag.SUI && c.useGasCoin ? GAS : c.coinType
|
|
595
|
+
let t = types.get(key)
|
|
596
|
+
if (!t) types.set(key, t = { coinType: c.coinType, intents: [], total: 0n, addressBalance: 0n, coins: [], coinTotal: 0n })
|
|
597
|
+
t.intents.push(c)
|
|
598
|
+
t.total += c.amount
|
|
599
|
+
}
|
|
600
|
+
if (types.has(GAS) && types.has(TypeTag.SUI)) {
|
|
601
|
+
return yield* new InvalidBalanceIntent({
|
|
602
|
+
reason: "SUI intents that may use the gas coin can't be mixed with ones that don't (useGasCoin: false)"
|
|
603
|
+
})
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
// What the sender has, per type (all types at once). Coins already taken
|
|
607
|
+
// as inputs (resolved, or left for the node) are not picked again.
|
|
608
|
+
const used = new Set(plan.draft.inputs.flatMap((i) =>
|
|
609
|
+
i._tag === "Object" ? [i.value.objectId] : i._tag === "UnresolvedObject" ? [i.objectId] : []
|
|
610
|
+
))
|
|
611
|
+
yield* Effect.forEach([...types], ([key, t]) =>
|
|
612
|
+
Effect.gen(function*() {
|
|
613
|
+
const balance = yield* balanceOf(plan, coinsService, plan.sender, t.coinType)
|
|
614
|
+
const reserved = reservedBy(plan, plan.sender, t.coinType)
|
|
615
|
+
const ab = balance.addressBalance - reserved
|
|
616
|
+
if (ab < 0n) {
|
|
617
|
+
return yield* new InsufficientBalance({ owner: plan.sender, coinType: t.coinType, required: reserved, available: balance.addressBalance })
|
|
618
|
+
}
|
|
619
|
+
t.addressBalance = ab
|
|
620
|
+
// The gas coin holds the sender's coins and (through a reservation) its
|
|
621
|
+
// address balance, so the gas path needs the same total as the others.
|
|
622
|
+
if (balance.total - reserved < t.total) {
|
|
623
|
+
return yield* new InsufficientBalance({ owner: plan.sender, coinType: t.coinType, required: t.total, available: balance.total - reserved })
|
|
624
|
+
}
|
|
625
|
+
if (key === GAS || ab >= t.total) return
|
|
626
|
+
// Owned coins, topped up from the address balance.
|
|
627
|
+
const needFromCoins = t.total - ab
|
|
628
|
+
const picked = yield* coinsOf(plan, coinsService, plan.sender, t.coinType).pipe(
|
|
629
|
+
Stream.filter((coin) => !used.has(coin.ref.objectId)),
|
|
630
|
+
Stream.scan((): { total: bigint; refs: Array<T.ObjectRef> } => ({ total: 0n, refs: [] }), (acc, coin) => ({
|
|
631
|
+
total: acc.total + coin.balance,
|
|
632
|
+
refs: [...acc.refs, coin.ref]
|
|
633
|
+
})),
|
|
634
|
+
Stream.takeUntil((acc) => acc.total >= needFromCoins),
|
|
635
|
+
Stream.runLast
|
|
636
|
+
)
|
|
637
|
+
const got = Option.getOrElse(picked, () => ({ total: 0n, refs: [] as Array<T.ObjectRef> }))
|
|
638
|
+
if (got.total + ab < t.total) {
|
|
639
|
+
return yield* new InsufficientBalance({ owner: plan.sender, coinType: t.coinType, required: t.total, available: got.total + ab })
|
|
640
|
+
}
|
|
641
|
+
t.coins = got.refs
|
|
642
|
+
t.coinTotal = got.total
|
|
643
|
+
}), { concurrency: "unbounded", discard: true })
|
|
644
|
+
|
|
645
|
+
// Rewrite the command list.
|
|
646
|
+
const inputs: Array<Input> = [...plan.draft.inputs]
|
|
647
|
+
const addInput = (arg: T.CallArg): T.Argument => {
|
|
648
|
+
inputs.push(arg)
|
|
649
|
+
return { _tag: "Input", value: inputs.length - 1 }
|
|
650
|
+
}
|
|
651
|
+
const out: Array<Command> = []
|
|
652
|
+
const results = new Map<number, (nested: number | undefined) => T.Argument>()
|
|
653
|
+
const remap = remapWith(results)
|
|
654
|
+
const pending = new Map<string, Array<T.Argument>>()
|
|
655
|
+
|
|
656
|
+
yield* rewrite(() => {
|
|
657
|
+
for (const [index, c] of plan.draft.commands.entries()) {
|
|
658
|
+
if (c._tag !== "BalanceIntent") {
|
|
659
|
+
const at = out.length
|
|
660
|
+
out.push(mapArguments(c, remap))
|
|
661
|
+
results.set(index, (n) => (n === undefined ? { _tag: "Result", value: at } : { _tag: "NestedResult", value: [at, n] }))
|
|
662
|
+
continue
|
|
663
|
+
}
|
|
664
|
+
if (c.amount === 0n) {
|
|
665
|
+
const at = out.length
|
|
666
|
+
out.push(moveCall(c.output === "balance" ? "0x2::balance::zero" : "0x2::coin::zero", c.coinType, []))
|
|
667
|
+
results.set(index, (n) => (n === undefined ? { _tag: "Result", value: at } : { _tag: "NestedResult", value: [at, n] }))
|
|
668
|
+
continue
|
|
669
|
+
}
|
|
670
|
+
const key = c.coinType === TypeTag.SUI && c.useGasCoin ? GAS : c.coinType
|
|
671
|
+
const t = types.get(key)!
|
|
672
|
+
let result: T.Argument
|
|
673
|
+
|
|
674
|
+
if (t.intents.every((i) => i.output === "balance") && t.addressBalance >= t.total) {
|
|
675
|
+
out.push(moveCall("0x2::balance::redeem_funds", t.coinType, [addInput(senderWithdrawal(c.amount, t.coinType))]))
|
|
676
|
+
result = { _tag: "NestedResult", value: [out.length - 1, 0] }
|
|
677
|
+
} else {
|
|
678
|
+
if (!pending.has(key)) {
|
|
679
|
+
const sources: Array<T.Argument> = []
|
|
680
|
+
let fromAddressBalance = false
|
|
681
|
+
let exact = false
|
|
682
|
+
if (t.addressBalance >= t.total) {
|
|
683
|
+
fromAddressBalance = true
|
|
684
|
+
out.push(moveCall("0x2::coin::redeem_funds", t.coinType, [addInput(senderWithdrawal(t.total, t.coinType))]))
|
|
685
|
+
sources.push({ _tag: "Result", value: out.length - 1 })
|
|
686
|
+
} else if (key === GAS) {
|
|
687
|
+
sources.push({ _tag: "GasCoin" })
|
|
688
|
+
} else {
|
|
689
|
+
const topUp = t.total > t.coinTotal ? t.total - t.coinTotal : 0n
|
|
690
|
+
exact = t.coinTotal + topUp === t.total
|
|
691
|
+
for (const ref of t.coins) sources.push(addInput({ _tag: "Object", value: { _tag: "ImmOrOwnedObject", ...ref } }))
|
|
692
|
+
if (topUp > 0n) {
|
|
693
|
+
fromAddressBalance = true
|
|
694
|
+
out.push(moveCall("0x2::coin::redeem_funds", t.coinType, [addInput(senderWithdrawal(topUp, t.coinType))]))
|
|
695
|
+
sources.push({ _tag: "Result", value: out.length - 1 })
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
const base = sources[0]!
|
|
699
|
+
const rest = sources.slice(1)
|
|
700
|
+
for (let i = 0; i < rest.length; i += 500) out.push({ _tag: "MergeCoins", destination: base, sources: rest.slice(i, i + 500) })
|
|
701
|
+
|
|
702
|
+
const split = out.length
|
|
703
|
+
out.push({ _tag: "SplitCoins", coin: base, amounts: t.intents.map((i) => addInput({ _tag: "Pure", bytes: encodeU64(i.amount) })) })
|
|
704
|
+
const typeResults: Array<T.Argument> = []
|
|
705
|
+
t.intents.forEach((i, n) => {
|
|
706
|
+
const piece: T.Argument = { _tag: "NestedResult", value: [split, n] }
|
|
707
|
+
if (i.output === "balance") {
|
|
708
|
+
out.push(moveCall("0x2::coin::into_balance", t.coinType, [piece]))
|
|
709
|
+
typeResults.push({ _tag: "NestedResult", value: [out.length - 1, 0] })
|
|
710
|
+
} else {
|
|
711
|
+
typeResults.push(piece)
|
|
712
|
+
}
|
|
713
|
+
})
|
|
714
|
+
|
|
715
|
+
// The remainder: back to the sender's address balance, or a zero coin destroyed.
|
|
716
|
+
// A split from the gas coin leaves its remainder in the gas coin.
|
|
717
|
+
if (key !== GAS || fromAddressBalance) {
|
|
718
|
+
if (t.intents.some((i) => i.output === "balance") || fromAddressBalance) {
|
|
719
|
+
out.push(moveCall("0x2::coin::send_funds", t.coinType, [base, addInput({ _tag: "Pure", bytes: encodeAddress(plan.sender) })]))
|
|
720
|
+
} else if (exact) {
|
|
721
|
+
out.push(moveCall("0x2::coin::destroy_zero", t.coinType, [base]))
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
pending.set(key, typeResults)
|
|
725
|
+
}
|
|
726
|
+
result = pending.get(key)!.shift()!
|
|
727
|
+
}
|
|
728
|
+
results.set(index, singleResult(index, result))
|
|
729
|
+
}
|
|
730
|
+
})
|
|
731
|
+
|
|
732
|
+
return { ...plan, draft: { inputs, commands: out } }
|
|
733
|
+
})
|
|
734
|
+
|
|
735
|
+
// -----------------------------------------------------------------------------
|
|
736
|
+
// gas
|
|
737
|
+
// -----------------------------------------------------------------------------
|
|
738
|
+
|
|
739
|
+
/** How many of the gas owner's SUI coins `prefetch` lists (one page of the gRPC listing). */
|
|
740
|
+
const PREFETCH_COINS = 100
|
|
741
|
+
|
|
742
|
+
/**
|
|
743
|
+
* Everything the default pipeline reads whatever the transaction is, in one
|
|
744
|
+
* round trip: the reference gas price (unless set), chain info (for the dry
|
|
745
|
+
* run's `ValidDuring`, a coin reservation or an address-balance expiration)
|
|
746
|
+
* and, unless `payment: false`, the gas owner's SUI balance and first page of
|
|
747
|
+
* SUI coins. `Tx.resolve` runs it alongside `Resolve.inputs`; later steps use
|
|
748
|
+
* what it read instead of asking again (as `@mysten/sui` does with one
|
|
749
|
+
* `Promise.all`).
|
|
750
|
+
*/
|
|
751
|
+
export const prefetch = (
|
|
752
|
+
plan: Plan,
|
|
753
|
+
options?: { readonly payment?: boolean }
|
|
754
|
+
): Effect.Effect<Plan, RpcError, Chain | Coins> =>
|
|
755
|
+
Effect.gen(function*() {
|
|
756
|
+
const chain = Effect.service(Chain)
|
|
757
|
+
const coins = Effect.service(Coins)
|
|
758
|
+
const owner = plan.gasOwner ?? plan.sender
|
|
759
|
+
const payment = options?.payment !== false && plan.gasPayment === undefined
|
|
760
|
+
const [gasPrice, info, gasBalance, gasCoins] = yield* Effect.all([
|
|
761
|
+
plan.gasPrice !== undefined ? Effect.succeed(plan.gasPrice) : Effect.flatMap(chain, (c) => c.referenceGasPrice),
|
|
762
|
+
payment || (plan.gasBudget === undefined && plan.expiration === undefined)
|
|
763
|
+
? Effect.flatMap(chain, (c) => c.info)
|
|
764
|
+
: Effect.succeed(undefined),
|
|
765
|
+
payment ? Effect.flatMap(coins, (c) => c.getBalance(owner, TypeTag.SUI)) : Effect.succeed(undefined),
|
|
766
|
+
payment
|
|
767
|
+
? Effect.flatMap(coins, (c) => Stream.runCollect(Stream.take(c.list(owner, TypeTag.SUI), PREFETCH_COINS)))
|
|
768
|
+
: Effect.succeed(undefined)
|
|
769
|
+
], { concurrency: "unbounded" })
|
|
770
|
+
return {
|
|
771
|
+
...plan,
|
|
772
|
+
gasPrice,
|
|
773
|
+
prefetched: {
|
|
774
|
+
...(info !== undefined && { chain: info }),
|
|
775
|
+
owner,
|
|
776
|
+
...(gasBalance !== undefined && { gasBalance }),
|
|
777
|
+
...(gasCoins !== undefined && { gasCoins })
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
})
|
|
781
|
+
|
|
782
|
+
/** `owner`'s balance of `coinType`: the prefetched SUI balance when the plan has it, else read. */
|
|
783
|
+
const balanceOf = (plan: Plan, coins: Coins["Service"], owner: Address, coinType: string): Effect.Effect<Balance, RpcError> => {
|
|
784
|
+
const pre = plan.prefetched
|
|
785
|
+
return coinType === TypeTag.SUI && pre?.owner === owner && pre.gasBalance !== undefined
|
|
786
|
+
? Effect.succeed(pre.gasBalance)
|
|
787
|
+
: coins.getBalance(owner, coinType)
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
/** `owner`'s coins of `coinType`: the prefetched SUI coins when they are all of them, else listed. */
|
|
791
|
+
const coinsOf = (plan: Plan, coins: Coins["Service"], owner: Address, coinType: string): Stream.Stream<Coin, RpcError> => {
|
|
792
|
+
const pre = plan.prefetched
|
|
793
|
+
return coinType === TypeTag.SUI && pre?.owner === owner && pre.gasCoins !== undefined && pre.gasCoins.length < PREFETCH_COINS
|
|
794
|
+
? Stream.fromIterable(pre.gasCoins)
|
|
795
|
+
: coins.list(owner, coinType)
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
const chainInfo = (plan: Plan): Effect.Effect<ChainInfo, RpcError, Chain> =>
|
|
799
|
+
plan.prefetched?.chain !== undefined ? Effect.succeed(plan.prefetched.chain) : Effect.flatMap(Effect.service(Chain), (c) => c.info)
|
|
800
|
+
|
|
801
|
+
export const gasPrice = (plan: Plan): Effect.Effect<Plan, RpcError, Chain> =>
|
|
802
|
+
plan.gasPrice !== undefined
|
|
803
|
+
? Effect.succeed(plan)
|
|
804
|
+
: Effect.map(Effect.flatMap(Effect.service(Chain), (c) => c.referenceGasPrice), (gasPrice) => ({ ...plan, gasPrice }))
|
|
805
|
+
|
|
806
|
+
const validDuringFor = (info: ChainInfo): T.TransactionExpiration => ({
|
|
807
|
+
_tag: "ValidDuring",
|
|
808
|
+
minEpoch: Option.some(info.epoch),
|
|
809
|
+
maxEpoch: Option.some(info.epoch + 1n),
|
|
810
|
+
minTimestamp: Option.none(),
|
|
811
|
+
maxTimestamp: Option.none(),
|
|
812
|
+
chain: info.chainId,
|
|
813
|
+
nonce: crypto.getRandomValues(new Uint32Array(1))[0]!
|
|
814
|
+
})
|
|
815
|
+
|
|
816
|
+
/** A `ValidDuring` expiration for this epoch and the next: the replay protection address-balance gas needs. */
|
|
817
|
+
export const validDuring = /* @__PURE__ */ Effect.fn("Resolve.validDuring")(function*() {
|
|
818
|
+
return validDuringFor(yield* Effect.flatMap(Effect.service(Chain), (c) => c.info))
|
|
819
|
+
})
|
|
820
|
+
|
|
821
|
+
const MAX_BUDGET = 50_000_000_000n
|
|
822
|
+
const GAS_SAFE_OVERHEAD = 1000n
|
|
823
|
+
|
|
824
|
+
const programmable = (draft: Draft) =>
|
|
825
|
+
Effect.suspend(() =>
|
|
826
|
+
draft.commands.some((c) => c._tag === "BalanceIntent" || c._tag === "AllowanceIntent")
|
|
827
|
+
? Effect.fail(new Incomplete({ missing: "coin/balance intents (run Resolve.balances)" }))
|
|
828
|
+
: draft.inputs.some((i) => i._tag === "UnresolvedObject")
|
|
829
|
+
? Effect.fail(new Incomplete({ missing: "object inputs (run Resolve.inputs)" }))
|
|
830
|
+
: Effect.succeed<T.TransactionKind>({
|
|
831
|
+
_tag: "ProgrammableTransaction",
|
|
832
|
+
inputs: draft.inputs as ReadonlyArray<T.CallArg>,
|
|
833
|
+
commands: draft.commands as ReadonlyArray<T.Command>
|
|
834
|
+
})
|
|
835
|
+
)
|
|
836
|
+
|
|
837
|
+
/** Commands may only use results of earlier commands, and inputs that exist. */
|
|
838
|
+
export const checkReferences = (kind: T.TransactionKind): InvalidTransaction | undefined => {
|
|
839
|
+
if (kind._tag !== "ProgrammableTransaction") return undefined
|
|
840
|
+
for (const [i, c] of kind.commands.entries()) {
|
|
841
|
+
for (const a of argumentsOf(c)) {
|
|
842
|
+
const r = a._tag === "Result" ? a.value : a._tag === "NestedResult" ? a.value[0] : undefined
|
|
843
|
+
if (r !== undefined && r >= i) return new InvalidTransaction({ reason: `command ${i} uses the result of command ${r}` })
|
|
844
|
+
if (a._tag === "Input" && a.value >= kind.inputs.length) return new InvalidTransaction({ reason: `command ${i} uses input ${a.value}, which doesn't exist` })
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
return undefined
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
/** BCS bytes of transaction data; data that can't be encoded (bad address, too many inputs) is `InvalidTransaction`. */
|
|
851
|
+
export const encode = (data: T.TransactionData): Effect.Effect<Uint8Array, InvalidTransaction> =>
|
|
852
|
+
Effect.suspend(() => {
|
|
853
|
+
const bad = checkReferences(data.kind)
|
|
854
|
+
if (bad) return Effect.fail(bad)
|
|
855
|
+
return Effect.try({
|
|
856
|
+
try: () => T.encode(data),
|
|
857
|
+
catch: (e) => new InvalidTransaction({ reason: e instanceof Error ? e.message : String(e) })
|
|
858
|
+
})
|
|
859
|
+
})
|
|
860
|
+
|
|
861
|
+
const encodeTransactionKind = /* @__PURE__ */ Bcs.encodeSync(T.TransactionKind)
|
|
862
|
+
|
|
863
|
+
/** BCS bytes of a transaction kind (`Ptb.buildKind`), checked like `encode`. */
|
|
864
|
+
export const encodeKind = (kind: T.TransactionKind): Effect.Effect<Uint8Array, InvalidTransaction> =>
|
|
865
|
+
Effect.suspend(() => {
|
|
866
|
+
const bad = checkReferences(kind)
|
|
867
|
+
if (bad) return Effect.fail(bad)
|
|
868
|
+
return Effect.try({
|
|
869
|
+
try: () => encodeTransactionKind(kind),
|
|
870
|
+
catch: (e) => new InvalidTransaction({ reason: e instanceof Error ? e.message : String(e) })
|
|
871
|
+
})
|
|
872
|
+
})
|
|
873
|
+
|
|
874
|
+
/** A failure status's Move abort, when it is one. */
|
|
875
|
+
export const abortOf = (status: Extract<Status, { _tag: "Failure" }>): MoveAbort | undefined => {
|
|
876
|
+
if (status.abortCode === undefined) return undefined
|
|
877
|
+
const loc = status.location
|
|
878
|
+
const clever = status.cleverError
|
|
879
|
+
return {
|
|
880
|
+
// A clever error's own code when it declares one, as GraphQL reports it; else the u64 the chain aborted with.
|
|
881
|
+
code: clever?.errorCode ?? status.abortCode,
|
|
882
|
+
...(loc !== undefined && { package: loc.package, module: loc.module }),
|
|
883
|
+
...(loc?.function !== undefined && { function: loc.function }),
|
|
884
|
+
...(loc?.instruction !== undefined && { instruction: loc.instruction }),
|
|
885
|
+
...(clever?.constantName !== undefined && { constant: clever.constantName }),
|
|
886
|
+
...(clever?.lineNumber !== undefined && { line: Number(clever.lineNumber) }),
|
|
887
|
+
...(clever?.rendered !== undefined && { rendered: clever.rendered })
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
/** A failure status's fields (`FailureFields`), for the errors that report one. */
|
|
892
|
+
export const failureFields = (status: Extract<Status, { _tag: "Failure" }>) => {
|
|
893
|
+
const abort = abortOf(status)
|
|
894
|
+
return {
|
|
895
|
+
description: status.description,
|
|
896
|
+
...(status.command !== undefined && { command: status.command }),
|
|
897
|
+
...(abort !== undefined && { abort })
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
/**
|
|
902
|
+
* Estimate the budget with a dry run: maximum budget, empty payment and a
|
|
903
|
+
* `ValidDuring` expiration, so the node mocks the gas coin and the estimate
|
|
904
|
+
* does not depend on which coins pay.
|
|
905
|
+
*/
|
|
906
|
+
export const budget = (
|
|
907
|
+
plan: Plan
|
|
908
|
+
): Effect.Effect<Plan, RpcError | GasEstimationFailed | Incomplete | InvalidTransaction, Transactions | Chain> =>
|
|
909
|
+
plan.gasBudget !== undefined
|
|
910
|
+
? Effect.succeed(plan)
|
|
911
|
+
: Effect.gen(function*() {
|
|
912
|
+
const price = plan.gasPrice ?? (yield* Effect.flatMap(Effect.service(Chain), (c) => c.referenceGasPrice))
|
|
913
|
+
const kind = yield* programmable(plan.draft)
|
|
914
|
+
const dryRun = yield* encode({
|
|
915
|
+
_tag: "V1",
|
|
916
|
+
kind,
|
|
917
|
+
sender: plan.sender,
|
|
918
|
+
gasData: { payment: [], owner: plan.gasOwner ?? plan.sender, price, budget: MAX_BUDGET },
|
|
919
|
+
expiration: plan.expiration ?? validDuringFor(yield* chainInfo(plan))
|
|
920
|
+
})
|
|
921
|
+
const sim = yield* Effect.flatMap(Effect.service(Transactions), (t) => t.simulate(dryRun))
|
|
922
|
+
if (sim.effects.status._tag === "Failure") return yield* new GasEstimationFailed(failureFields(sim.effects.status))
|
|
923
|
+
const g = sim.effects.gasUsed
|
|
924
|
+
const base = g.computationCost + GAS_SAFE_OVERHEAD * price
|
|
925
|
+
const total = base + g.storageCost - g.storageRebate
|
|
926
|
+
return { ...plan, gasPrice: price, gasBudget: total > base ? total : base }
|
|
927
|
+
})
|
|
928
|
+
|
|
929
|
+
/** How gas is paid. A strategy is just a step. */
|
|
930
|
+
export type PaymentStrategy<E = never, R = never> = (plan: Plan) => Effect.Effect<Plan, E, R>
|
|
931
|
+
|
|
932
|
+
/** The errors and requirements of the built-in strategies (`auto`, `addressBalance`, `coins`). */
|
|
933
|
+
export type DefaultPaymentError = RpcError | InsufficientGas | Incomplete
|
|
934
|
+
export type DefaultPaymentServices = Chain | Coins
|
|
935
|
+
|
|
936
|
+
/** Does any command take the gas coin as an argument? */
|
|
937
|
+
export const usesGasCoin = (draft: Draft): boolean =>
|
|
938
|
+
draft.commands.some((c) => argumentsOf(c).some((a) => a._tag === "GasCoin"))
|
|
939
|
+
|
|
940
|
+
const decodeU64 = (bytes: Uint8Array): bigint | undefined =>
|
|
941
|
+
bytes.length === 8 ? new DataView(bytes.buffer, bytes.byteOffset, 8).getBigUint64(0, true) : undefined
|
|
942
|
+
|
|
943
|
+
/**
|
|
944
|
+
* What commands split off the gas coin, as far as the draft says: the pure
|
|
945
|
+
* amounts of every `SplitCoins(GasCoin, ...)`. Other uses (a Move call taking
|
|
946
|
+
* the gas coin, an amount computed on chain) can't be known before execution.
|
|
947
|
+
*/
|
|
948
|
+
export const gasCoinSpend = (draft: Draft): bigint => {
|
|
949
|
+
let total = 0n
|
|
950
|
+
for (const c of draft.commands) {
|
|
951
|
+
if (c._tag !== "SplitCoins" || c.coin._tag !== "GasCoin") continue
|
|
952
|
+
for (const a of c.amounts) {
|
|
953
|
+
const input = a._tag === "Input" ? draft.inputs[a.value] : undefined
|
|
954
|
+
if (input?._tag === "Pure") total += decodeU64(input.bytes) ?? 0n
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
return total
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
/** Who a withdrawal input draws from. */
|
|
961
|
+
const withdrawalOwner = (w: T.FundsWithdrawal, plan: Plan): Address =>
|
|
962
|
+
w.withdrawFrom._tag === "SenderAllowance"
|
|
963
|
+
? w.withdrawFrom.funder
|
|
964
|
+
: w.withdrawFrom._tag === "Sender"
|
|
965
|
+
? plan.sender
|
|
966
|
+
: plan.gasOwner ?? plan.sender
|
|
967
|
+
|
|
968
|
+
/** The `coinType` amounts that the transaction's withdrawal inputs reserve from `owner`'s address balance. */
|
|
969
|
+
export const reservedBy = (plan: Plan, owner: Address, coinType: string): bigint => {
|
|
970
|
+
let total = 0n
|
|
971
|
+
for (const input of plan.draft.inputs) {
|
|
972
|
+
if (input._tag !== "FundsWithdrawal") continue
|
|
973
|
+
if (withdrawalOwner(input, plan) !== owner) continue
|
|
974
|
+
if (TypeTag.format(input.typeArg.value) !== coinType) continue
|
|
975
|
+
total += input.reservation.value
|
|
976
|
+
}
|
|
977
|
+
return total
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
/**
|
|
981
|
+
* Address-balance gas needs replay protection: a `ValidDuring` window is set
|
|
982
|
+
* when the caller gave no expiration. An explicit one is kept as given, as
|
|
983
|
+
* `@mysten/sui` does (validators refuse `None`/`Epoch` with an empty payment,
|
|
984
|
+
* which is a visible failure rather than a silently widened validity).
|
|
985
|
+
*/
|
|
986
|
+
const keepExpiration = (plan: Plan) =>
|
|
987
|
+
plan.expiration !== undefined ? Effect.succeed(plan.expiration) : Effect.map(chainInfo(plan), validDuringFor)
|
|
988
|
+
|
|
989
|
+
const needBudget = (plan: Plan) =>
|
|
990
|
+
plan.gasBudget === undefined
|
|
991
|
+
? Effect.fail(new Incomplete({ missing: "gas budget (run Resolve.budget first)" }))
|
|
992
|
+
: Effect.succeed(plan.gasBudget)
|
|
993
|
+
|
|
994
|
+
/** A reservation ref for whatever the owner's SUI address balance holds beyond the transaction's own withdrawals. */
|
|
995
|
+
const reservation = (plan: Plan, owner: Address, available: bigint) =>
|
|
996
|
+
Effect.map(chainInfo(plan), (info) => CoinReservation.make({ reserved: available, owner, chainId: info.chainId, epoch: info.epoch }))
|
|
997
|
+
|
|
998
|
+
const gasBalance = (plan: Plan, owner: Address) =>
|
|
999
|
+
Effect.flatMap(Effect.service(Coins), (c) => balanceOf(plan, c, owner, TypeTag.SUI))
|
|
1000
|
+
|
|
1001
|
+
/**
|
|
1002
|
+
* Pay entirely from the gas owner's SUI address balance, or fail with
|
|
1003
|
+
* `InsufficientGas` before anything is signed. No coin is touched: the payment
|
|
1004
|
+
* is empty with a `ValidDuring` expiration, or, when the transaction uses the
|
|
1005
|
+
* gas coin, a single coin reservation that funds it from the balance (which
|
|
1006
|
+
* must then also cover what commands split off the gas coin).
|
|
1007
|
+
*/
|
|
1008
|
+
export const addressBalance: PaymentStrategy<DefaultPaymentError, DefaultPaymentServices> = (plan) =>
|
|
1009
|
+
Effect.gen(function*() {
|
|
1010
|
+
if (plan.gasPayment !== undefined) return plan
|
|
1011
|
+
const budget = yield* needBudget(plan)
|
|
1012
|
+
const owner = plan.gasOwner ?? plan.sender
|
|
1013
|
+
const balance = yield* gasBalance(plan, owner)
|
|
1014
|
+
const available = balance.addressBalance - reservedBy(plan, owner, TypeTag.SUI)
|
|
1015
|
+
const gasCoin = usesGasCoin(plan.draft)
|
|
1016
|
+
const required = budget + (gasCoin ? gasCoinSpend(plan.draft) : 0n)
|
|
1017
|
+
if (available < required) return yield* new InsufficientGas({ owner, required, available: available < 0n ? 0n : available })
|
|
1018
|
+
if (gasCoin) return { ...plan, gasPayment: [yield* reservation(plan, owner, available)] }
|
|
1019
|
+
return { ...plan, gasPayment: [], expiration: yield* keepExpiration(plan) }
|
|
1020
|
+
})
|
|
1021
|
+
|
|
1022
|
+
/** SUI coins of `owner` not already used as inputs, in listing order, until they reach `target` or `limit` coins (`target` undefined: all of them, up to `limit`). */
|
|
1023
|
+
const pickCoins = (plan: Plan, owner: Address, target: bigint | undefined, limit: number) =>
|
|
1024
|
+
Effect.gen(function*() {
|
|
1025
|
+
const used = new Set(plan.draft.inputs.flatMap((i) => (i._tag === "Object" ? [i.value.objectId] : [])))
|
|
1026
|
+
const picked = yield* Effect.flatMap(Effect.service(Coins), (c) =>
|
|
1027
|
+
coinsOf(plan, c, owner, TypeTag.SUI).pipe(
|
|
1028
|
+
Stream.filter((coin) => !used.has(coin.ref.objectId)),
|
|
1029
|
+
Stream.scan((): { total: bigint; refs: Array<T.ObjectRef> } => ({ total: 0n, refs: [] }), (acc, coin) => ({
|
|
1030
|
+
total: acc.total + coin.balance,
|
|
1031
|
+
refs: [...acc.refs, coin.ref]
|
|
1032
|
+
})),
|
|
1033
|
+
Stream.takeUntil((acc) => (target !== undefined && acc.total >= target) || acc.refs.length >= limit),
|
|
1034
|
+
Stream.runLast
|
|
1035
|
+
))
|
|
1036
|
+
return Option.getOrElse(picked, () => ({ total: 0n, refs: [] as Array<T.ObjectRef> }))
|
|
1037
|
+
})
|
|
1038
|
+
|
|
1039
|
+
/**
|
|
1040
|
+
* Payment when commands spend from the gas coin: every SUI coin of the owner
|
|
1041
|
+
* not used as an input (up to the 256-object limit, one taken by a reservation
|
|
1042
|
+
* of the address balance when it holds any), as `@mysten/sui` does, so the gas
|
|
1043
|
+
* coin holds everything the owner has. Fails with `InsufficientGas` when that
|
|
1044
|
+
* is less than the budget plus the amounts split off the gas coin.
|
|
1045
|
+
*/
|
|
1046
|
+
const payWithGasCoin = (plan: Plan, owner: Address, budget: bigint, available: bigint) =>
|
|
1047
|
+
Effect.gen(function*() {
|
|
1048
|
+
const fromBalance = available > 0n ? available : 0n
|
|
1049
|
+
const limit = fromBalance > 0n ? MAX_GAS_OBJECTS - 1 : MAX_GAS_OBJECTS
|
|
1050
|
+
const required = budget + gasCoinSpend(plan.draft)
|
|
1051
|
+
// The prefetched first page, when it already covers what the gas coin must
|
|
1052
|
+
// hold (as `@mysten/sui` uses its first page); otherwise every coin, listed.
|
|
1053
|
+
const used = new Set(plan.draft.inputs.flatMap((i) => (i._tag === "Object" ? [i.value.objectId] : [])))
|
|
1054
|
+
const page = plan.prefetched?.owner === owner ? plan.prefetched.gasCoins?.filter((c) => !used.has(c.ref.objectId)).slice(0, limit) : undefined
|
|
1055
|
+
const pageTotal = page?.reduce((s, c) => s + c.balance, 0n) ?? 0n
|
|
1056
|
+
const coins = page !== undefined && page.length > 0 && pageTotal + fromBalance >= required
|
|
1057
|
+
? { total: pageTotal, refs: page.map((c) => c.ref) }
|
|
1058
|
+
: yield* pickCoins(plan, owner, undefined, limit)
|
|
1059
|
+
const total = coins.total + fromBalance
|
|
1060
|
+
if (total < required || (fromBalance === 0n && coins.refs.length === 0)) {
|
|
1061
|
+
return yield* new InsufficientGas({ owner, required, available: total })
|
|
1062
|
+
}
|
|
1063
|
+
const refs = fromBalance > 0n ? [yield* reservation(plan, owner, fromBalance), ...coins.refs] : coins.refs
|
|
1064
|
+
return { ...plan, gasPayment: refs }
|
|
1065
|
+
})
|
|
1066
|
+
|
|
1067
|
+
const MAX_GAS_OBJECTS = 256
|
|
1068
|
+
|
|
1069
|
+
/**
|
|
1070
|
+
* The recommended default, matching `@mysten/sui`: pay from the address
|
|
1071
|
+
* balance when it covers the budget (plus the transaction's own SUI
|
|
1072
|
+
* withdrawals) and the gas coin isn't used. When commands use the gas coin,
|
|
1073
|
+
* pay with every SUI coin, plus a coin reservation of the address balance, so
|
|
1074
|
+
* the gas coin can cover what they spend. Otherwise pay with SUI coins up to
|
|
1075
|
+
* the budget. Fails with `InsufficientGas` when none of that covers it.
|
|
1076
|
+
*/
|
|
1077
|
+
export const auto: PaymentStrategy<DefaultPaymentError, DefaultPaymentServices> = (plan) =>
|
|
1078
|
+
Effect.gen(function*() {
|
|
1079
|
+
if (plan.gasPayment !== undefined) return plan
|
|
1080
|
+
const budget = yield* needBudget(plan)
|
|
1081
|
+
const owner = plan.gasOwner ?? plan.sender
|
|
1082
|
+
const gasCoin = usesGasCoin(plan.draft)
|
|
1083
|
+
const balance = yield* gasBalance(plan, owner)
|
|
1084
|
+
const available = balance.addressBalance - reservedBy(plan, owner, TypeTag.SUI)
|
|
1085
|
+
|
|
1086
|
+
if (budget === 0n || (!gasCoin && available >= budget)) {
|
|
1087
|
+
return { ...plan, gasPayment: [], expiration: yield* keepExpiration(plan) }
|
|
1088
|
+
}
|
|
1089
|
+
if (gasCoin) return yield* payWithGasCoin(plan, owner, budget, available)
|
|
1090
|
+
const coins = yield* pickCoins(plan, owner, budget, MAX_GAS_OBJECTS)
|
|
1091
|
+
if (coins.total < budget) {
|
|
1092
|
+
return yield* new InsufficientGas({ owner, required: budget, available: coins.total + (available > 0n ? available : 0n) })
|
|
1093
|
+
}
|
|
1094
|
+
return { ...plan, gasPayment: coins.refs }
|
|
1095
|
+
})
|
|
1096
|
+
|
|
1097
|
+
/**
|
|
1098
|
+
* An empty payment with a `ValidDuring` expiration and no balance check: for
|
|
1099
|
+
* simulation (`checks: false`) and for bytes whose payer will be funded
|
|
1100
|
+
* before they're submitted. Executing it without a funded address balance
|
|
1101
|
+
* fails at the node.
|
|
1102
|
+
*/
|
|
1103
|
+
export const unchecked: PaymentStrategy<RpcError, Chain> = (plan) =>
|
|
1104
|
+
plan.gasPayment !== undefined
|
|
1105
|
+
? Effect.succeed(plan)
|
|
1106
|
+
: Effect.map(keepExpiration(plan), (expiration) => ({ ...plan, gasPayment: [], expiration }))
|
|
1107
|
+
|
|
1108
|
+
/** A strategy that pays with exactly `payment` (what `fixed` returns); `Tx.resolve` can hand it to the node. */
|
|
1109
|
+
export interface FixedPayment extends PaymentStrategy {
|
|
1110
|
+
readonly payment: ReadonlyArray<T.ObjectRef>
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
/** Pay with exactly these coins. */
|
|
1114
|
+
export const fixed = (payment: ReadonlyArray<T.ObjectRef>): FixedPayment =>
|
|
1115
|
+
Object.assign((plan: Plan) => Effect.succeed({ ...plan, gasPayment: payment }), { payment })
|
|
1116
|
+
|
|
1117
|
+
/**
|
|
1118
|
+
* Pay with SUI coins owned by the gas owner (at most 256): until they cover the
|
|
1119
|
+
* budget, or, when commands use the gas coin, all of them (which must cover the
|
|
1120
|
+
* budget plus what is split off the gas coin).
|
|
1121
|
+
*/
|
|
1122
|
+
export const coins: PaymentStrategy<RpcError | InsufficientGas | Incomplete, Coins> = (plan) =>
|
|
1123
|
+
Effect.gen(function*() {
|
|
1124
|
+
if (plan.gasPayment !== undefined) return plan
|
|
1125
|
+
if (plan.gasBudget === undefined) return yield* new Incomplete({ missing: "gas budget (run Resolve.budget first)" })
|
|
1126
|
+
const owner = plan.gasOwner ?? plan.sender
|
|
1127
|
+
const budget = plan.gasBudget
|
|
1128
|
+
const gasCoin = usesGasCoin(plan.draft)
|
|
1129
|
+
const required = budget + (gasCoin ? gasCoinSpend(plan.draft) : 0n)
|
|
1130
|
+
const best = yield* pickCoins(plan, owner, gasCoin ? undefined : budget, MAX_GAS_OBJECTS)
|
|
1131
|
+
if (best.total < required || (gasCoin && best.refs.length === 0)) return yield* new InsufficientGas({ owner, required, available: best.total })
|
|
1132
|
+
return { ...plan, gasPayment: best.refs }
|
|
1133
|
+
})
|
|
1134
|
+
|
|
1135
|
+
// -----------------------------------------------------------------------------
|
|
1136
|
+
// server (one simulation on the node, verified)
|
|
1137
|
+
// -----------------------------------------------------------------------------
|
|
1138
|
+
|
|
1139
|
+
const encodeCommands = /* @__PURE__ */ Bcs.encodeSync(Bcs.vector(T.Command))
|
|
1140
|
+
const encodeCallArg = /* @__PURE__ */ Bcs.encodeSync(T.CallArg)
|
|
1141
|
+
const encodeRefs = /* @__PURE__ */ Bcs.encodeSync(Bcs.vector(T.ObjectRef))
|
|
1142
|
+
const encodeExpiration = /* @__PURE__ */ Bcs.encodeSync(T.TransactionExpiration)
|
|
1143
|
+
|
|
1144
|
+
const sameBytes = (a: Uint8Array, b: Uint8Array) => a.length === b.length && a.every((x, i) => x === b[i])
|
|
1145
|
+
|
|
1146
|
+
const hasIntents = (draft: Draft) => draft.commands.some((c) => c._tag === "BalanceIntent" || c._tag === "AllowanceIntent")
|
|
1147
|
+
|
|
1148
|
+
/** Is the reservation ref `ref` one for `owner`'s SUI address balance on the chain `chainId`? */
|
|
1149
|
+
const reservationFor = (ref: T.ObjectRef, owner: Address, chainId: string): boolean => {
|
|
1150
|
+
try {
|
|
1151
|
+
return CoinReservation.make({ reserved: 0n, owner, chainId, epoch: 0n }).objectId === ref.objectId
|
|
1152
|
+
} catch {
|
|
1153
|
+
return false
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
/**
|
|
1158
|
+
* Check the node's completed transaction against the plan it was asked to
|
|
1159
|
+
* complete (`Resolve.server` runs this; exported for tests and custom flows).
|
|
1160
|
+
*
|
|
1161
|
+
* - sender and gas owner unchanged; commands byte-for-byte unchanged;
|
|
1162
|
+
* - every input the plan had resolved unchanged; every unresolved one an
|
|
1163
|
+
* object with the id asked for: a shared object at least as mutable as the
|
|
1164
|
+
* commands need (forced mutability exactly as forced), `Receiving` exactly
|
|
1165
|
+
* where a called function takes `Receiving<T>`;
|
|
1166
|
+
* - gas price, budget, payment and expiration exactly as given when given;
|
|
1167
|
+
* otherwise a positive price, a budget within `maxGasBudget` (default: the
|
|
1168
|
+
* protocol maximum, 50 SUI), payment coins the simulation shows the gas
|
|
1169
|
+
* owner owned at those versions (or reservations of the gas owner's address
|
|
1170
|
+
* balance), no input doubling as gas, and no expiration or a `ValidDuring`
|
|
1171
|
+
* of at most two epochs around the simulated one.
|
|
1172
|
+
*
|
|
1173
|
+
* `functions` are the signatures of the Move calls taking an unresolved
|
|
1174
|
+
* object, by command index (as `Resolve.inputs` reads them).
|
|
1175
|
+
*/
|
|
1176
|
+
export const verifyResolution = (
|
|
1177
|
+
plan: Plan,
|
|
1178
|
+
data: T.TransactionData,
|
|
1179
|
+
effects: Effects,
|
|
1180
|
+
functions: ReadonlyMap<number, MoveFunction>,
|
|
1181
|
+
epoch?: bigint
|
|
1182
|
+
): ResolutionRejected | undefined => {
|
|
1183
|
+
const refuse = (reason: string) => new ResolutionRejected({ reason })
|
|
1184
|
+
const gasOwner = plan.gasOwner ?? plan.sender
|
|
1185
|
+
if (data.sender !== plan.sender) return refuse(`sender changed to ${data.sender}`)
|
|
1186
|
+
if (data.gasData.owner !== gasOwner) return refuse(`gas owner changed to ${data.gasData.owner}`)
|
|
1187
|
+
const kind = data.kind
|
|
1188
|
+
const ours = plan.draft.commands as ReadonlyArray<T.Command>
|
|
1189
|
+
if (!sameBytes(encodeCommands(kind.commands), encodeCommands(ours))) return refuse("the commands changed")
|
|
1190
|
+
if (kind.inputs.length !== plan.draft.inputs.length) {
|
|
1191
|
+
return refuse(`${kind.inputs.length} inputs for ${plan.draft.inputs.length}`)
|
|
1192
|
+
}
|
|
1193
|
+
const use = usages(plan.draft, functions)
|
|
1194
|
+
const objectIds = new Set<string>()
|
|
1195
|
+
for (const [i, asked] of plan.draft.inputs.entries()) {
|
|
1196
|
+
const got = kind.inputs[i]!
|
|
1197
|
+
if (got._tag === "Object") objectIds.add(got.value.objectId)
|
|
1198
|
+
if (asked._tag !== "UnresolvedObject") {
|
|
1199
|
+
if (!sameBytes(encodeCallArg(got), encodeCallArg(asked))) return refuse(`input ${i} changed`)
|
|
1200
|
+
continue
|
|
1201
|
+
}
|
|
1202
|
+
if (got._tag !== "Object" || got.value.objectId !== asked.objectId) {
|
|
1203
|
+
return refuse(`input ${i} is not object ${asked.objectId}`)
|
|
1204
|
+
}
|
|
1205
|
+
const usage = use.get(i)
|
|
1206
|
+
const o = got.value
|
|
1207
|
+
switch (o._tag) {
|
|
1208
|
+
case "SharedObject": {
|
|
1209
|
+
if (usage?.receiving) return refuse(`input ${i} must be Receiving, got a shared object`)
|
|
1210
|
+
const m = o.mutability._tag
|
|
1211
|
+
if (asked.mutable !== undefined) {
|
|
1212
|
+
if (m !== (asked.mutable ? "Mutable" : "Immutable")) {
|
|
1213
|
+
return refuse(`input ${i} was forced ${asked.mutable ? "mutable" : "immutable"}, got ${m}`)
|
|
1214
|
+
}
|
|
1215
|
+
} else if ((usage?.mutable ?? true) && m !== "Mutable") {
|
|
1216
|
+
return refuse(`input ${i} (shared ${o.objectId}) must be Mutable for its commands, got ${m}`)
|
|
1217
|
+
}
|
|
1218
|
+
break
|
|
1219
|
+
}
|
|
1220
|
+
case "Receiving":
|
|
1221
|
+
if (!usage?.receiving) return refuse(`input ${i} is Receiving, but no command receives it`)
|
|
1222
|
+
break
|
|
1223
|
+
case "ImmOrOwnedObject":
|
|
1224
|
+
if (usage?.receiving) return refuse(`input ${i} must be Receiving, got an owned object`)
|
|
1225
|
+
break
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
const gas = data.gasData
|
|
1230
|
+
if (plan.gasPrice !== undefined ? gas.price !== plan.gasPrice : gas.price <= 0n) return refuse(`gas price ${gas.price}`)
|
|
1231
|
+
const maxBudget = plan.maxGasBudget ?? MAX_BUDGET
|
|
1232
|
+
if (plan.gasBudget !== undefined) {
|
|
1233
|
+
if (gas.budget !== plan.gasBudget) return refuse(`gas budget changed to ${gas.budget}`)
|
|
1234
|
+
} else if (gas.budget > maxBudget) {
|
|
1235
|
+
return refuse(`gas budget ${gas.budget} is above ${maxBudget}`)
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
const e = data.expiration
|
|
1239
|
+
if (plan.expiration !== undefined) {
|
|
1240
|
+
if (!sameBytes(encodeExpiration(e), encodeExpiration(plan.expiration))) return refuse("the expiration changed")
|
|
1241
|
+
} else if (e._tag !== "None") {
|
|
1242
|
+
if (e._tag !== "ValidDuring") return refuse(`expiration ${e._tag} where none was asked for`)
|
|
1243
|
+
const v = e
|
|
1244
|
+
const bounded = Option.isSome(v.minEpoch) && Option.isSome(v.maxEpoch) && Option.isNone(v.minTimestamp) &&
|
|
1245
|
+
Option.isNone(v.maxTimestamp) && v.maxEpoch.value >= v.minEpoch.value && v.maxEpoch.value - v.minEpoch.value <= 1n &&
|
|
1246
|
+
(epoch === undefined || (v.minEpoch.value <= epoch && epoch <= v.maxEpoch.value))
|
|
1247
|
+
if (!bounded) return refuse("the expiration is not a ValidDuring window of at most two epochs around the simulated one")
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
if (plan.gasPayment !== undefined) {
|
|
1251
|
+
return sameBytes(encodeRefs(gas.payment), encodeRefs(plan.gasPayment)) ? undefined : refuse("the gas payment changed")
|
|
1252
|
+
}
|
|
1253
|
+
const chainId = e._tag === "ValidDuring" || e._tag === "Validity" ? e.chain : undefined
|
|
1254
|
+
const seen = new Set<string>()
|
|
1255
|
+
for (const ref of gas.payment) {
|
|
1256
|
+
if (seen.has(ref.objectId)) return refuse(`gas object ${ref.objectId} appears twice`)
|
|
1257
|
+
seen.add(ref.objectId)
|
|
1258
|
+
if (objectIds.has(ref.objectId)) return refuse(`gas object ${ref.objectId} is also an input`)
|
|
1259
|
+
if (CoinReservation.isReservation(ref)) {
|
|
1260
|
+
if (ref.version !== 0n || chainId === undefined || !reservationFor(ref, gasOwner, chainId)) {
|
|
1261
|
+
return refuse(`gas reservation ${ref.objectId} is not one of ${gasOwner}'s address balance`)
|
|
1262
|
+
}
|
|
1263
|
+
continue
|
|
1264
|
+
}
|
|
1265
|
+
const c = effects.changedObjects.find((x) => x.objectId === ref.objectId)
|
|
1266
|
+
const owner = c?.inputOwner
|
|
1267
|
+
if (
|
|
1268
|
+
c === undefined || c.inputVersion !== ref.version || c.inputDigest !== ref.digest ||
|
|
1269
|
+
owner?._tag !== "AddressOwner" || owner.address !== gasOwner
|
|
1270
|
+
) {
|
|
1271
|
+
return refuse(`gas coin ${ref.objectId} is not owned by ${gasOwner} at version ${ref.version}`)
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
return undefined
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
/** The plan as a request to the node: unresolved objects by id, gas fields only where fixed. */
|
|
1278
|
+
const unresolvedOf = (plan: Plan): UnresolvedTransaction => ({
|
|
1279
|
+
sender: plan.sender,
|
|
1280
|
+
gasOwner: plan.gasOwner ?? plan.sender,
|
|
1281
|
+
inputs: plan.draft.inputs as UnresolvedTransaction["inputs"],
|
|
1282
|
+
commands: plan.draft.commands as ReadonlyArray<T.Command>,
|
|
1283
|
+
...(plan.gasPrice !== undefined && { gasPrice: plan.gasPrice }),
|
|
1284
|
+
...(plan.gasBudget !== undefined && { gasBudget: plan.gasBudget }),
|
|
1285
|
+
...(plan.gasPayment !== undefined && { gasPayment: plan.gasPayment }),
|
|
1286
|
+
...(plan.expiration !== undefined && { expiration: plan.expiration })
|
|
1287
|
+
})
|
|
1288
|
+
|
|
1289
|
+
/**
|
|
1290
|
+
* Complete the plan on the node in one simulation (`Transactions.resolve`,
|
|
1291
|
+
* checks and gas selection on), as `@mysten/sui`'s gRPC and GraphQL clients
|
|
1292
|
+
* do: object versions and shared-object mutability, gas price, budget and
|
|
1293
|
+
* payment (from coins or the address balance, with a `ValidDuring` expiration
|
|
1294
|
+
* then), keeping whatever the plan already fixed. The signatures of the Move
|
|
1295
|
+
* calls taking an unresolved object are read at the same time (cached by
|
|
1296
|
+
* `Packages`), and the answer is checked by `verifyResolution` before use.
|
|
1297
|
+
*
|
|
1298
|
+
* Run `Resolve.balances` first (coin/balance intents stay client-side), then
|
|
1299
|
+
* `finish`. A simulated failure is `GasEstimationFailed`; a transport without
|
|
1300
|
+
* `resolve` is `Incomplete`.
|
|
1301
|
+
*/
|
|
1302
|
+
export const server = (
|
|
1303
|
+
plan: Plan
|
|
1304
|
+
): Effect.Effect<
|
|
1305
|
+
Plan,
|
|
1306
|
+
RpcError | GasEstimationFailed | Incomplete | InvalidTransaction | ResolutionRejected,
|
|
1307
|
+
Transactions | Packages
|
|
1308
|
+
> =>
|
|
1309
|
+
Effect.gen(function*() {
|
|
1310
|
+
if (hasIntents(plan.draft)) return yield* new Incomplete({ missing: "coin/balance intents (run Resolve.balances)" })
|
|
1311
|
+
const transactions = yield* Transactions
|
|
1312
|
+
if (transactions.resolve === undefined) {
|
|
1313
|
+
return yield* new Incomplete({ missing: "server-side resolution (this Transactions transport has no resolve)" })
|
|
1314
|
+
}
|
|
1315
|
+
const bad = checkReferences({
|
|
1316
|
+
_tag: "ProgrammableTransaction",
|
|
1317
|
+
inputs: plan.draft.inputs as ReadonlyArray<T.CallArg>,
|
|
1318
|
+
commands: plan.draft.commands as ReadonlyArray<T.Command>
|
|
1319
|
+
})
|
|
1320
|
+
if (bad) return yield* bad
|
|
1321
|
+
const pending = new Set(plan.draft.inputs.flatMap((input, i) => (input._tag === "UnresolvedObject" ? [i] : [])))
|
|
1322
|
+
const [resolution, functions] = yield* Effect.all([
|
|
1323
|
+
transactions.resolve(unresolvedOf(plan)),
|
|
1324
|
+
functionsFor(plan.draft, pending)
|
|
1325
|
+
], { concurrency: "unbounded" })
|
|
1326
|
+
if (resolution.effects.status._tag === "Failure") return yield* new GasEstimationFailed(failureFields(resolution.effects.status))
|
|
1327
|
+
const decoded = T.decode(resolution.transaction)
|
|
1328
|
+
if (decoded._tag === "Failure") return yield* new ResolutionRejected({ reason: `not TransactionData: ${decoded.failure.message}` })
|
|
1329
|
+
const data = decoded.success
|
|
1330
|
+
const refused = verifyResolution(plan, data, resolution.effects, functions, resolution.epoch)
|
|
1331
|
+
if (refused) return yield* refused
|
|
1332
|
+
return {
|
|
1333
|
+
...plan,
|
|
1334
|
+
draft: { inputs: data.kind.inputs, commands: plan.draft.commands },
|
|
1335
|
+
gasPrice: data.gasData.price,
|
|
1336
|
+
gasBudget: data.gasData.budget,
|
|
1337
|
+
gasPayment: data.gasData.payment,
|
|
1338
|
+
...(data.expiration._tag !== "None" || plan.expiration !== undefined ? { expiration: data.expiration } : {})
|
|
1339
|
+
}
|
|
1340
|
+
}).pipe(Effect.withSpan("Resolve.server"))
|
|
1341
|
+
|
|
1342
|
+
// -----------------------------------------------------------------------------
|
|
1343
|
+
// finish
|
|
1344
|
+
// -----------------------------------------------------------------------------
|
|
1345
|
+
|
|
1346
|
+
/** The final `TransactionData`; fails with `InvalidTransaction` if it can't be encoded as it stands. */
|
|
1347
|
+
export const finish = (plan: Plan): Effect.Effect<T.TransactionData, Incomplete | InvalidTransaction> =>
|
|
1348
|
+
Effect.gen(function*() {
|
|
1349
|
+
const kind = yield* programmable(plan.draft)
|
|
1350
|
+
if (plan.gasPrice === undefined) return yield* new Incomplete({ missing: "gas price" })
|
|
1351
|
+
if (plan.gasBudget === undefined) return yield* new Incomplete({ missing: "gas budget" })
|
|
1352
|
+
if (plan.gasPayment === undefined) return yield* new Incomplete({ missing: "gas payment" })
|
|
1353
|
+
const data: T.TransactionData = {
|
|
1354
|
+
_tag: "V1",
|
|
1355
|
+
kind,
|
|
1356
|
+
sender: plan.sender,
|
|
1357
|
+
gasData: {
|
|
1358
|
+
payment: plan.gasPayment,
|
|
1359
|
+
owner: plan.gasOwner ?? plan.sender,
|
|
1360
|
+
price: plan.gasPrice,
|
|
1361
|
+
budget: plan.gasBudget
|
|
1362
|
+
},
|
|
1363
|
+
expiration: plan.expiration ?? { _tag: "None" }
|
|
1364
|
+
}
|
|
1365
|
+
yield* encode(data)
|
|
1366
|
+
return data
|
|
1367
|
+
})
|