@mysten/zksend
Advanced tools
Comparing version 0.0.0-experimental-20240110152546 to 0.0.0-experimental-20240111220418
# @mysten/zksend | ||
## 0.0.0-experimental-20240110152546 | ||
## 0.0.0-experimental-20240111220418 | ||
@@ -14,4 +14,8 @@ ### Minor Changes | ||
- c6b3066069: Improve zkSend error messages | ||
- 9a14e61db4: Add gas estimation for creating zksend links | ||
- f041b10b9f: Allow origin to be set when registering zksend wallet" | ||
- c1f6cfff47: Fix import paths | ||
- Updated dependencies [9a14e61db4] | ||
- @mysten/sui.js@0.0.0-experimental-20240111220418 | ||
- @mysten/wallet-standard@0.0.0-experimental-20240111220418 | ||
@@ -18,0 +22,0 @@ ## 0.1.1 |
import { SuiClient } from '@mysten/sui.js/client'; | ||
import type { Keypair } from '@mysten/sui.js/cryptography'; | ||
import type { Keypair, Signer } from '@mysten/sui.js/cryptography'; | ||
import type { TransactionObjectInput } from '@mysten/sui.js/transactions'; | ||
@@ -10,2 +10,4 @@ import { TransactionBlock } from '@mysten/sui.js/transactions'; | ||
keypair?: Keypair; | ||
client?: SuiClient; | ||
sender: string; | ||
} | ||
@@ -16,14 +18,20 @@ export interface ZkSendLinkOptions { | ||
} | ||
interface CreateZkSendLinkOptions { | ||
transactionBlock?: TransactionBlock; | ||
calculateGas?: (options: { | ||
mist: bigint; | ||
objects: TransactionObjectInput[]; | ||
gasEstimateFromDryRun: bigint; | ||
}) => Promise<bigint> | bigint; | ||
} | ||
export declare class ZkSendLinkBuilder { | ||
#private; | ||
constructor({ host, path, keypair, }?: ZkSendLinkBuilderOptions); | ||
constructor({ host, path, keypair, client, sender, }: ZkSendLinkBuilderOptions); | ||
addClaimableMist(amount: bigint): void; | ||
addClaimableObject(id: TransactionObjectInput): void; | ||
getLink(): string; | ||
addGasForClaim(getAmount?: (options: { | ||
mist: bigint; | ||
objects: TransactionObjectInput[]; | ||
estimatedFee: bigint; | ||
}) => Promise<bigint> | bigint): Promise<void>; | ||
createSendTransaction(): TransactionBlock; | ||
create({ signer, ...options }: CreateZkSendLinkOptions & { | ||
signer: Signer; | ||
}): Promise<import("@mysten/sui.js/client").SuiTransactionBlockResponse>; | ||
createSendTransaction({ transactionBlock: txb, calculateGas, }?: CreateZkSendLinkOptions): Promise<TransactionBlock>; | ||
} | ||
@@ -66,1 +74,2 @@ export interface ZkSendLinkOptions { | ||
} | ||
export {}; |
@@ -51,3 +51,3 @@ "use strict"; | ||
var import_utils = require("@mysten/sui.js/utils"); | ||
var _host, _path, _keypair, _objects, _mist, _gasFee, _estimateClaimGasFee, estimateClaimGasFee_fn, _client, _keypair2, _initiallyOwnedObjects, _ownedBalances, _ownedObjects, _loadOwnedObjects, loadOwnedObjects_fn, _loadOwnedBalances, loadOwnedBalances_fn, _loadInitialTransactionData, loadInitialTransactionData_fn; | ||
var _host, _path, _keypair, _client, _objects, _mist, _sender, _estimateClaimGasFee, estimateClaimGasFee_fn, _client2, _keypair2, _initiallyOwnedObjects, _ownedObjects, _gasCoin, _creatorAddress, _loadOwnedObjects, loadOwnedObjects_fn, _loadInitialTransactionData, loadInitialTransactionData_fn; | ||
const DEFAULT_ZK_SEND_LINK_OPTIONS = { | ||
@@ -58,3 +58,4 @@ host: "https://zksend.com", | ||
}; | ||
const SUI_COIN_TYPE = (0, import_utils.normalizeStructTag)("0x2::coin::Coin<0x2::sui::SUI>"); | ||
const SUI_COIN_TYPE = (0, import_utils.normalizeStructTag)(import_utils.SUI_TYPE_ARG); | ||
const SUI_COIN_OBJECT_TYPE = (0, import_utils.normalizeStructTag)("0x2::coin::Coin<0x2::sui::SUI>"); | ||
class ZkSendLinkBuilder { | ||
@@ -64,4 +65,6 @@ constructor({ | ||
path = DEFAULT_ZK_SEND_LINK_OPTIONS.path, | ||
keypair = new import_ed25519.Ed25519Keypair() | ||
} = {}) { | ||
keypair = new import_ed25519.Ed25519Keypair(), | ||
client = DEFAULT_ZK_SEND_LINK_OPTIONS.client, | ||
sender | ||
}) { | ||
__privateAdd(this, _estimateClaimGasFee); | ||
@@ -71,8 +74,11 @@ __privateAdd(this, _host, void 0); | ||
__privateAdd(this, _keypair, void 0); | ||
__privateAdd(this, _client, void 0); | ||
__privateAdd(this, _objects, /* @__PURE__ */ new Set()); | ||
__privateAdd(this, _mist, 0n); | ||
__privateAdd(this, _gasFee, 0n); | ||
__privateAdd(this, _sender, void 0); | ||
__privateSet(this, _host, host); | ||
__privateSet(this, _path, path); | ||
__privateSet(this, _keypair, keypair); | ||
__privateSet(this, _client, client); | ||
__privateSet(this, _sender, (0, import_utils.normalizeSuiAddress)(sender)); | ||
} | ||
@@ -91,18 +97,33 @@ addClaimableMist(amount) { | ||
} | ||
async addGasForClaim(getAmount) { | ||
const estimatedFee = await __privateMethod(this, _estimateClaimGasFee, estimateClaimGasFee_fn).call(this); | ||
__privateSet(this, _gasFee, getAmount ? await getAmount({ | ||
async create({ | ||
signer, | ||
...options | ||
}) { | ||
const txb = await this.createSendTransaction(options); | ||
return __privateGet(this, _client).signAndExecuteTransactionBlock({ | ||
transactionBlock: await txb.build({ client: __privateGet(this, _client) }), | ||
signer | ||
}); | ||
} | ||
async createSendTransaction({ | ||
transactionBlock: txb = new import_transactions.TransactionBlock(), | ||
calculateGas | ||
} = {}) { | ||
const gasEstimateFromDryRun = await __privateMethod(this, _estimateClaimGasFee, estimateClaimGasFee_fn).call(this); | ||
const baseGasAmount = calculateGas ? await calculateGas({ | ||
mist: __privateGet(this, _mist), | ||
objects: [...__privateGet(this, _objects)], | ||
estimatedFee | ||
}) : estimatedFee); | ||
} | ||
createSendTransaction() { | ||
const txb = new import_transactions.TransactionBlock(); | ||
gasEstimateFromDryRun | ||
}) : gasEstimateFromDryRun * 2n; | ||
const gasWithBuffer = baseGasAmount + 1013n; | ||
const roundedGasAmount = gasWithBuffer - gasWithBuffer % 1000n - 13n; | ||
const address = __privateGet(this, _keypair).toSuiAddress(); | ||
const objectsToTransfer = [...__privateGet(this, _objects)].map((id) => txb.object(id)); | ||
const totalMist = __privateGet(this, _mist) + __privateGet(this, _gasFee); | ||
if (totalMist) { | ||
const [coin] = txb.splitCoins(txb.gas, [totalMist]); | ||
objectsToTransfer.push(coin); | ||
txb.setSenderIfNotSet(__privateGet(this, _sender)); | ||
if (__privateGet(this, _mist)) { | ||
const [gas, sui] = txb.splitCoins(txb.gas, [roundedGasAmount, __privateGet(this, _mist)]); | ||
objectsToTransfer.push(gas, sui); | ||
} else { | ||
const [gas] = txb.splitCoins(txb.gas, [roundedGasAmount]); | ||
objectsToTransfer.push(gas); | ||
} | ||
@@ -116,8 +137,33 @@ txb.transferObjects(objectsToTransfer, address); | ||
_keypair = new WeakMap(); | ||
_client = new WeakMap(); | ||
_objects = new WeakMap(); | ||
_mist = new WeakMap(); | ||
_gasFee = new WeakMap(); | ||
_sender = new WeakMap(); | ||
_estimateClaimGasFee = new WeakSet(); | ||
estimateClaimGasFee_fn = function() { | ||
return Promise.resolve(0n); | ||
estimateClaimGasFee_fn = async function() { | ||
const txb = new import_transactions.TransactionBlock(); | ||
txb.setSender(__privateGet(this, _sender)); | ||
txb.setGasPayment([]); | ||
if (__privateGet(this, _mist)) { | ||
const allCoins = await __privateGet(this, _client).getCoins({ | ||
owner: __privateGet(this, _sender), | ||
coinType: SUI_COIN_TYPE, | ||
limit: 1 | ||
}); | ||
if (!allCoins.data.length) { | ||
throw new Error("Sending account does not contain any Sui"); | ||
} | ||
txb.transferObjects( | ||
[txb.object(allCoins.data[0].coinObjectId)], | ||
__privateGet(this, _keypair).toSuiAddress() | ||
); | ||
} | ||
txb.transferObjects( | ||
[...__privateGet(this, _objects)].map((id) => txb.object(id)), | ||
__privateGet(this, _keypair).toSuiAddress() | ||
); | ||
const result = await __privateGet(this, _client).dryRunTransactionBlock({ | ||
transactionBlock: await txb.build({ client: __privateGet(this, _client) }) | ||
}); | ||
return BigInt(result.effects.gasUsed.computationCost) + BigInt(result.effects.gasUsed.storageCost) - BigInt(result.effects.gasUsed.storageRebate); | ||
}; | ||
@@ -130,10 +176,10 @@ const _ZkSendLink = class { | ||
__privateAdd(this, _loadOwnedObjects); | ||
__privateAdd(this, _loadOwnedBalances); | ||
__privateAdd(this, _loadInitialTransactionData); | ||
__privateAdd(this, _client, void 0); | ||
__privateAdd(this, _client2, void 0); | ||
__privateAdd(this, _keypair2, void 0); | ||
__privateAdd(this, _initiallyOwnedObjects, /* @__PURE__ */ new Set()); | ||
__privateAdd(this, _ownedBalances, /* @__PURE__ */ new Map()); | ||
__privateAdd(this, _ownedObjects, []); | ||
__privateSet(this, _client, client); | ||
__privateAdd(this, _gasCoin, void 0); | ||
__privateAdd(this, _creatorAddress, void 0); | ||
__privateSet(this, _client2, client); | ||
__privateSet(this, _keypair2, keypair); | ||
@@ -152,7 +198,3 @@ } | ||
async loadOwnedData() { | ||
await Promise.all([ | ||
__privateMethod(this, _loadInitialTransactionData, loadInitialTransactionData_fn).call(this), | ||
__privateMethod(this, _loadOwnedObjects, loadOwnedObjects_fn).call(this), | ||
__privateMethod(this, _loadOwnedBalances, loadOwnedBalances_fn).call(this) | ||
]); | ||
await Promise.all([__privateMethod(this, _loadInitialTransactionData, loadInitialTransactionData_fn).call(this), __privateMethod(this, _loadOwnedObjects, loadOwnedObjects_fn).call(this)]); | ||
} | ||
@@ -162,4 +204,4 @@ async listClaimableAssets(address, options) { | ||
const txb = this.createClaimTransaction(normalizedAddress, options); | ||
const dryRun = await __privateGet(this, _client).dryRunTransactionBlock({ | ||
transactionBlock: await txb.build({ client: __privateGet(this, _client) }) | ||
const dryRun = await __privateGet(this, _client2).dryRunTransactionBlock({ | ||
transactionBlock: await txb.build({ client: __privateGet(this, _client2) }) | ||
}); | ||
@@ -190,3 +232,3 @@ const balances = []; | ||
async claimAssets(address, options) { | ||
return __privateGet(this, _client).signAndExecuteTransactionBlock({ | ||
return __privateGet(this, _client2).signAndExecuteTransactionBlock({ | ||
transactionBlock: await this.createClaimTransaction(address, options), | ||
@@ -204,3 +246,7 @@ signer: __privateGet(this, _keypair2) | ||
const objectsToTransfer = __privateGet(this, _ownedObjects).filter((object) => { | ||
if (object.type === SUI_COIN_TYPE) { | ||
if (__privateGet(this, _gasCoin)) { | ||
if (object.objectId === __privateGet(this, _gasCoin).coinObjectId) { | ||
return false; | ||
} | ||
} else if (object.type === SUI_COIN_OBJECT_TYPE) { | ||
return false; | ||
@@ -216,3 +262,5 @@ } | ||
}).map((object) => txb.object(object.objectId)); | ||
if (claimAll || options?.coinTypes?.includes(SUI_COIN_TYPE)) { | ||
if (__privateGet(this, _gasCoin) && __privateGet(this, _creatorAddress)) { | ||
txb.transferObjects([txb.gas], __privateGet(this, _creatorAddress)); | ||
} else if (claimAll || options?.coinTypes?.includes(SUI_COIN_TYPE)) { | ||
objectsToTransfer.push(txb.gas); | ||
@@ -225,7 +273,8 @@ } | ||
let ZkSendLink = _ZkSendLink; | ||
_client = new WeakMap(); | ||
_client2 = new WeakMap(); | ||
_keypair2 = new WeakMap(); | ||
_initiallyOwnedObjects = new WeakMap(); | ||
_ownedBalances = new WeakMap(); | ||
_ownedObjects = new WeakMap(); | ||
_gasCoin = new WeakMap(); | ||
_creatorAddress = new WeakMap(); | ||
_loadOwnedObjects = new WeakSet(); | ||
@@ -236,3 +285,3 @@ loadOwnedObjects_fn = async function() { | ||
do { | ||
const ownedObjects = await __privateGet(this, _client).getOwnedObjects({ | ||
const ownedObjects = await __privateGet(this, _client2).getOwnedObjects({ | ||
cursor: nextCursor, | ||
@@ -257,15 +306,5 @@ owner: __privateGet(this, _keypair2).toSuiAddress(), | ||
}; | ||
_loadOwnedBalances = new WeakSet(); | ||
loadOwnedBalances_fn = async function() { | ||
__privateSet(this, _ownedBalances, /* @__PURE__ */ new Map()); | ||
const balances = await __privateGet(this, _client).getAllBalances({ | ||
owner: __privateGet(this, _keypair2).toSuiAddress() | ||
}); | ||
for (const balance of balances) { | ||
__privateGet(this, _ownedBalances).set((0, import_utils.normalizeStructTag)(balance.coinType), BigInt(balance.totalBalance)); | ||
} | ||
}; | ||
_loadInitialTransactionData = new WeakSet(); | ||
loadInitialTransactionData_fn = async function() { | ||
const result = await __privateGet(this, _client).queryTransactionBlocks({ | ||
const result = await __privateGet(this, _client2).queryTransactionBlocks({ | ||
limit: 1, | ||
@@ -277,3 +316,4 @@ order: "ascending", | ||
options: { | ||
showObjectChanges: true | ||
showObjectChanges: true, | ||
showInput: true | ||
} | ||
@@ -287,2 +327,3 @@ }); | ||
}); | ||
__privateSet(this, _creatorAddress, result.data[0]?.transaction?.data.sender); | ||
}; | ||
@@ -289,0 +330,0 @@ function ownedAfterChange(objectChange, address) { |
import { SuiClient } from '@mysten/sui.js/client'; | ||
import type { Keypair } from '@mysten/sui.js/cryptography'; | ||
import type { Keypair, Signer } from '@mysten/sui.js/cryptography'; | ||
import type { TransactionObjectInput } from '@mysten/sui.js/transactions'; | ||
@@ -10,2 +10,4 @@ import { TransactionBlock } from '@mysten/sui.js/transactions'; | ||
keypair?: Keypair; | ||
client?: SuiClient; | ||
sender: string; | ||
} | ||
@@ -16,14 +18,20 @@ export interface ZkSendLinkOptions { | ||
} | ||
interface CreateZkSendLinkOptions { | ||
transactionBlock?: TransactionBlock; | ||
calculateGas?: (options: { | ||
mist: bigint; | ||
objects: TransactionObjectInput[]; | ||
gasEstimateFromDryRun: bigint; | ||
}) => Promise<bigint> | bigint; | ||
} | ||
export declare class ZkSendLinkBuilder { | ||
#private; | ||
constructor({ host, path, keypair, }?: ZkSendLinkBuilderOptions); | ||
constructor({ host, path, keypair, client, sender, }: ZkSendLinkBuilderOptions); | ||
addClaimableMist(amount: bigint): void; | ||
addClaimableObject(id: TransactionObjectInput): void; | ||
getLink(): string; | ||
addGasForClaim(getAmount?: (options: { | ||
mist: bigint; | ||
objects: TransactionObjectInput[]; | ||
estimatedFee: bigint; | ||
}) => Promise<bigint> | bigint): Promise<void>; | ||
createSendTransaction(): TransactionBlock; | ||
create({ signer, ...options }: CreateZkSendLinkOptions & { | ||
signer: Signer; | ||
}): Promise<import("@mysten/sui.js/client").SuiTransactionBlockResponse>; | ||
createSendTransaction({ transactionBlock: txb, calculateGas, }?: CreateZkSendLinkOptions): Promise<TransactionBlock>; | ||
} | ||
@@ -66,1 +74,2 @@ export interface ZkSendLinkOptions { | ||
} | ||
export {}; |
@@ -23,3 +23,3 @@ var __accessCheck = (obj, member, msg) => { | ||
}; | ||
var _host, _path, _keypair, _objects, _mist, _gasFee, _estimateClaimGasFee, estimateClaimGasFee_fn, _client, _keypair2, _initiallyOwnedObjects, _ownedBalances, _ownedObjects, _loadOwnedObjects, loadOwnedObjects_fn, _loadOwnedBalances, loadOwnedBalances_fn, _loadInitialTransactionData, loadInitialTransactionData_fn; | ||
var _host, _path, _keypair, _client, _objects, _mist, _sender, _estimateClaimGasFee, estimateClaimGasFee_fn, _client2, _keypair2, _initiallyOwnedObjects, _ownedObjects, _gasCoin, _creatorAddress, _loadOwnedObjects, loadOwnedObjects_fn, _loadInitialTransactionData, loadInitialTransactionData_fn; | ||
import { getFullnodeUrl, SuiClient } from "@mysten/sui.js/client"; | ||
@@ -33,3 +33,4 @@ import { Ed25519Keypair } from "@mysten/sui.js/keypairs/ed25519"; | ||
normalizeSuiObjectId, | ||
parseStructTag | ||
parseStructTag, | ||
SUI_TYPE_ARG | ||
} from "@mysten/sui.js/utils"; | ||
@@ -41,3 +42,4 @@ const DEFAULT_ZK_SEND_LINK_OPTIONS = { | ||
}; | ||
const SUI_COIN_TYPE = normalizeStructTag("0x2::coin::Coin<0x2::sui::SUI>"); | ||
const SUI_COIN_TYPE = normalizeStructTag(SUI_TYPE_ARG); | ||
const SUI_COIN_OBJECT_TYPE = normalizeStructTag("0x2::coin::Coin<0x2::sui::SUI>"); | ||
class ZkSendLinkBuilder { | ||
@@ -47,4 +49,6 @@ constructor({ | ||
path = DEFAULT_ZK_SEND_LINK_OPTIONS.path, | ||
keypair = new Ed25519Keypair() | ||
} = {}) { | ||
keypair = new Ed25519Keypair(), | ||
client = DEFAULT_ZK_SEND_LINK_OPTIONS.client, | ||
sender | ||
}) { | ||
__privateAdd(this, _estimateClaimGasFee); | ||
@@ -54,8 +58,11 @@ __privateAdd(this, _host, void 0); | ||
__privateAdd(this, _keypair, void 0); | ||
__privateAdd(this, _client, void 0); | ||
__privateAdd(this, _objects, /* @__PURE__ */ new Set()); | ||
__privateAdd(this, _mist, 0n); | ||
__privateAdd(this, _gasFee, 0n); | ||
__privateAdd(this, _sender, void 0); | ||
__privateSet(this, _host, host); | ||
__privateSet(this, _path, path); | ||
__privateSet(this, _keypair, keypair); | ||
__privateSet(this, _client, client); | ||
__privateSet(this, _sender, normalizeSuiAddress(sender)); | ||
} | ||
@@ -74,18 +81,33 @@ addClaimableMist(amount) { | ||
} | ||
async addGasForClaim(getAmount) { | ||
const estimatedFee = await __privateMethod(this, _estimateClaimGasFee, estimateClaimGasFee_fn).call(this); | ||
__privateSet(this, _gasFee, getAmount ? await getAmount({ | ||
async create({ | ||
signer, | ||
...options | ||
}) { | ||
const txb = await this.createSendTransaction(options); | ||
return __privateGet(this, _client).signAndExecuteTransactionBlock({ | ||
transactionBlock: await txb.build({ client: __privateGet(this, _client) }), | ||
signer | ||
}); | ||
} | ||
async createSendTransaction({ | ||
transactionBlock: txb = new TransactionBlock(), | ||
calculateGas | ||
} = {}) { | ||
const gasEstimateFromDryRun = await __privateMethod(this, _estimateClaimGasFee, estimateClaimGasFee_fn).call(this); | ||
const baseGasAmount = calculateGas ? await calculateGas({ | ||
mist: __privateGet(this, _mist), | ||
objects: [...__privateGet(this, _objects)], | ||
estimatedFee | ||
}) : estimatedFee); | ||
} | ||
createSendTransaction() { | ||
const txb = new TransactionBlock(); | ||
gasEstimateFromDryRun | ||
}) : gasEstimateFromDryRun * 2n; | ||
const gasWithBuffer = baseGasAmount + 1013n; | ||
const roundedGasAmount = gasWithBuffer - gasWithBuffer % 1000n - 13n; | ||
const address = __privateGet(this, _keypair).toSuiAddress(); | ||
const objectsToTransfer = [...__privateGet(this, _objects)].map((id) => txb.object(id)); | ||
const totalMist = __privateGet(this, _mist) + __privateGet(this, _gasFee); | ||
if (totalMist) { | ||
const [coin] = txb.splitCoins(txb.gas, [totalMist]); | ||
objectsToTransfer.push(coin); | ||
txb.setSenderIfNotSet(__privateGet(this, _sender)); | ||
if (__privateGet(this, _mist)) { | ||
const [gas, sui] = txb.splitCoins(txb.gas, [roundedGasAmount, __privateGet(this, _mist)]); | ||
objectsToTransfer.push(gas, sui); | ||
} else { | ||
const [gas] = txb.splitCoins(txb.gas, [roundedGasAmount]); | ||
objectsToTransfer.push(gas); | ||
} | ||
@@ -99,8 +121,33 @@ txb.transferObjects(objectsToTransfer, address); | ||
_keypair = new WeakMap(); | ||
_client = new WeakMap(); | ||
_objects = new WeakMap(); | ||
_mist = new WeakMap(); | ||
_gasFee = new WeakMap(); | ||
_sender = new WeakMap(); | ||
_estimateClaimGasFee = new WeakSet(); | ||
estimateClaimGasFee_fn = function() { | ||
return Promise.resolve(0n); | ||
estimateClaimGasFee_fn = async function() { | ||
const txb = new TransactionBlock(); | ||
txb.setSender(__privateGet(this, _sender)); | ||
txb.setGasPayment([]); | ||
if (__privateGet(this, _mist)) { | ||
const allCoins = await __privateGet(this, _client).getCoins({ | ||
owner: __privateGet(this, _sender), | ||
coinType: SUI_COIN_TYPE, | ||
limit: 1 | ||
}); | ||
if (!allCoins.data.length) { | ||
throw new Error("Sending account does not contain any Sui"); | ||
} | ||
txb.transferObjects( | ||
[txb.object(allCoins.data[0].coinObjectId)], | ||
__privateGet(this, _keypair).toSuiAddress() | ||
); | ||
} | ||
txb.transferObjects( | ||
[...__privateGet(this, _objects)].map((id) => txb.object(id)), | ||
__privateGet(this, _keypair).toSuiAddress() | ||
); | ||
const result = await __privateGet(this, _client).dryRunTransactionBlock({ | ||
transactionBlock: await txb.build({ client: __privateGet(this, _client) }) | ||
}); | ||
return BigInt(result.effects.gasUsed.computationCost) + BigInt(result.effects.gasUsed.storageCost) - BigInt(result.effects.gasUsed.storageRebate); | ||
}; | ||
@@ -113,10 +160,10 @@ const _ZkSendLink = class { | ||
__privateAdd(this, _loadOwnedObjects); | ||
__privateAdd(this, _loadOwnedBalances); | ||
__privateAdd(this, _loadInitialTransactionData); | ||
__privateAdd(this, _client, void 0); | ||
__privateAdd(this, _client2, void 0); | ||
__privateAdd(this, _keypair2, void 0); | ||
__privateAdd(this, _initiallyOwnedObjects, /* @__PURE__ */ new Set()); | ||
__privateAdd(this, _ownedBalances, /* @__PURE__ */ new Map()); | ||
__privateAdd(this, _ownedObjects, []); | ||
__privateSet(this, _client, client); | ||
__privateAdd(this, _gasCoin, void 0); | ||
__privateAdd(this, _creatorAddress, void 0); | ||
__privateSet(this, _client2, client); | ||
__privateSet(this, _keypair2, keypair); | ||
@@ -135,7 +182,3 @@ } | ||
async loadOwnedData() { | ||
await Promise.all([ | ||
__privateMethod(this, _loadInitialTransactionData, loadInitialTransactionData_fn).call(this), | ||
__privateMethod(this, _loadOwnedObjects, loadOwnedObjects_fn).call(this), | ||
__privateMethod(this, _loadOwnedBalances, loadOwnedBalances_fn).call(this) | ||
]); | ||
await Promise.all([__privateMethod(this, _loadInitialTransactionData, loadInitialTransactionData_fn).call(this), __privateMethod(this, _loadOwnedObjects, loadOwnedObjects_fn).call(this)]); | ||
} | ||
@@ -145,4 +188,4 @@ async listClaimableAssets(address, options) { | ||
const txb = this.createClaimTransaction(normalizedAddress, options); | ||
const dryRun = await __privateGet(this, _client).dryRunTransactionBlock({ | ||
transactionBlock: await txb.build({ client: __privateGet(this, _client) }) | ||
const dryRun = await __privateGet(this, _client2).dryRunTransactionBlock({ | ||
transactionBlock: await txb.build({ client: __privateGet(this, _client2) }) | ||
}); | ||
@@ -173,3 +216,3 @@ const balances = []; | ||
async claimAssets(address, options) { | ||
return __privateGet(this, _client).signAndExecuteTransactionBlock({ | ||
return __privateGet(this, _client2).signAndExecuteTransactionBlock({ | ||
transactionBlock: await this.createClaimTransaction(address, options), | ||
@@ -187,3 +230,7 @@ signer: __privateGet(this, _keypair2) | ||
const objectsToTransfer = __privateGet(this, _ownedObjects).filter((object) => { | ||
if (object.type === SUI_COIN_TYPE) { | ||
if (__privateGet(this, _gasCoin)) { | ||
if (object.objectId === __privateGet(this, _gasCoin).coinObjectId) { | ||
return false; | ||
} | ||
} else if (object.type === SUI_COIN_OBJECT_TYPE) { | ||
return false; | ||
@@ -199,3 +246,5 @@ } | ||
}).map((object) => txb.object(object.objectId)); | ||
if (claimAll || options?.coinTypes?.includes(SUI_COIN_TYPE)) { | ||
if (__privateGet(this, _gasCoin) && __privateGet(this, _creatorAddress)) { | ||
txb.transferObjects([txb.gas], __privateGet(this, _creatorAddress)); | ||
} else if (claimAll || options?.coinTypes?.includes(SUI_COIN_TYPE)) { | ||
objectsToTransfer.push(txb.gas); | ||
@@ -208,7 +257,8 @@ } | ||
let ZkSendLink = _ZkSendLink; | ||
_client = new WeakMap(); | ||
_client2 = new WeakMap(); | ||
_keypair2 = new WeakMap(); | ||
_initiallyOwnedObjects = new WeakMap(); | ||
_ownedBalances = new WeakMap(); | ||
_ownedObjects = new WeakMap(); | ||
_gasCoin = new WeakMap(); | ||
_creatorAddress = new WeakMap(); | ||
_loadOwnedObjects = new WeakSet(); | ||
@@ -219,3 +269,3 @@ loadOwnedObjects_fn = async function() { | ||
do { | ||
const ownedObjects = await __privateGet(this, _client).getOwnedObjects({ | ||
const ownedObjects = await __privateGet(this, _client2).getOwnedObjects({ | ||
cursor: nextCursor, | ||
@@ -240,15 +290,5 @@ owner: __privateGet(this, _keypair2).toSuiAddress(), | ||
}; | ||
_loadOwnedBalances = new WeakSet(); | ||
loadOwnedBalances_fn = async function() { | ||
__privateSet(this, _ownedBalances, /* @__PURE__ */ new Map()); | ||
const balances = await __privateGet(this, _client).getAllBalances({ | ||
owner: __privateGet(this, _keypair2).toSuiAddress() | ||
}); | ||
for (const balance of balances) { | ||
__privateGet(this, _ownedBalances).set(normalizeStructTag(balance.coinType), BigInt(balance.totalBalance)); | ||
} | ||
}; | ||
_loadInitialTransactionData = new WeakSet(); | ||
loadInitialTransactionData_fn = async function() { | ||
const result = await __privateGet(this, _client).queryTransactionBlocks({ | ||
const result = await __privateGet(this, _client2).queryTransactionBlocks({ | ||
limit: 1, | ||
@@ -260,3 +300,4 @@ order: "ascending", | ||
options: { | ||
showObjectChanges: true | ||
showObjectChanges: true, | ||
showInput: true | ||
} | ||
@@ -270,2 +311,3 @@ }); | ||
}); | ||
__privateSet(this, _creatorAddress, result.data[0]?.transaction?.data.sender); | ||
}; | ||
@@ -272,0 +314,0 @@ function ownedAfterChange(objectChange, address) { |
{ | ||
"name": "@mysten/zksend", | ||
"version": "0.0.0-experimental-20240110152546", | ||
"version": "0.0.0-experimental-20240111220418", | ||
"description": "TODO: Write Description", | ||
@@ -40,4 +40,4 @@ "license": "Apache-2.0", | ||
"valibot": "^0.25.0", | ||
"@mysten/sui.js": "0.49.1", | ||
"@mysten/wallet-standard": "0.10.1" | ||
"@mysten/sui.js": "0.0.0-experimental-20240111220418", | ||
"@mysten/wallet-standard": "0.0.0-experimental-20240111220418" | ||
}, | ||
@@ -44,0 +44,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
281763
2196
+ Added@mysten/sui.js@0.0.0-experimental-20240111220418(transitive)
+ Added@mysten/wallet-standard@0.0.0-experimental-20240111220418(transitive)
- Removed@mysten/sui.js@0.49.1(transitive)
- Removed@mysten/wallet-standard@0.10.1(transitive)
Updated@mysten/wallet-standard@0.0.0-experimental-20240111220418