@mysten/zksend 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/cjs/channel/events.d.ts +27 -27
- package/dist/cjs/channel/index.d.ts +1 -1
- package/dist/cjs/index.d.ts +4 -2
- package/dist/cjs/index.js +6 -1
- package/dist/cjs/index.js.map +3 -3
- package/dist/cjs/links/builder.d.ts +13 -2
- package/dist/cjs/links/builder.js +130 -42
- package/dist/cjs/links/builder.js.map +2 -2
- package/dist/cjs/links/claim.d.ts +13 -47
- package/dist/cjs/links/claim.js +176 -150
- package/dist/cjs/links/claim.js.map +3 -3
- package/dist/cjs/links/list-created-links.d.ts +22 -0
- package/dist/cjs/links/list-created-links.js +145 -0
- package/dist/cjs/links/list-created-links.js.map +7 -0
- package/dist/cjs/links/utils.d.ts +32 -15
- package/dist/cjs/links/utils.js +86 -100
- package/dist/cjs/links/utils.js.map +3 -3
- package/dist/cjs/links/zk-bag.d.ts +1 -0
- package/dist/cjs/links/zk-bag.js +6 -0
- package/dist/cjs/links/zk-bag.js.map +2 -2
- package/dist/esm/channel/events.d.ts +27 -27
- package/dist/esm/channel/index.d.ts +1 -1
- package/dist/esm/index.d.ts +4 -2
- package/dist/esm/index.js +7 -2
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/links/builder.d.ts +13 -2
- package/dist/esm/links/builder.js +131 -43
- package/dist/esm/links/builder.js.map +2 -2
- package/dist/esm/links/claim.d.ts +13 -47
- package/dist/esm/links/claim.js +174 -148
- package/dist/esm/links/claim.js.map +2 -2
- package/dist/esm/links/list-created-links.d.ts +22 -0
- package/dist/esm/links/list-created-links.js +125 -0
- package/dist/esm/links/list-created-links.js.map +7 -0
- package/dist/esm/links/utils.d.ts +32 -15
- package/dist/esm/links/utils.js +87 -101
- package/dist/esm/links/utils.js.map +3 -3
- package/dist/esm/links/zk-bag.d.ts +1 -0
- package/dist/esm/links/zk-bag.js +6 -0
- package/dist/esm/links/zk-bag.js.map +2 -2
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/cjs/links/claim.js
CHANGED
|
@@ -43,13 +43,15 @@ __export(claim_exports, {
|
|
|
43
43
|
ZkSendLink: () => ZkSendLink
|
|
44
44
|
});
|
|
45
45
|
module.exports = __toCommonJS(claim_exports);
|
|
46
|
+
var import_bcs = require("@mysten/sui.js/bcs");
|
|
46
47
|
var import_client = require("@mysten/sui.js/client");
|
|
47
48
|
var import_ed25519 = require("@mysten/sui.js/keypairs/ed25519");
|
|
48
49
|
var import_transactions = require("@mysten/sui.js/transactions");
|
|
49
50
|
var import_utils = require("@mysten/sui.js/utils");
|
|
50
51
|
var import_builder = require("./builder.js");
|
|
52
|
+
var import_utils2 = require("./utils.js");
|
|
51
53
|
var import_zk_bag = require("./zk-bag.js");
|
|
52
|
-
var _client,
|
|
54
|
+
var _client, _contract, _claimApi, _network, _host, _path, _gasCoin, _hasSui, _ownedObjects, _loadBag, loadBag_fn, _loadClaimedAssets, loadClaimedAssets_fn, _createSponsoredTransactionBlock, createSponsoredTransactionBlock_fn, _executeSponsoredTransactionBlock, executeSponsoredTransactionBlock_fn, _fetch, fetch_fn, _listNonContractClaimableAssets, listNonContractClaimableAssets_fn, _createNonContractClaimTransaction, createNonContractClaimTransaction_fn, _loadOwnedObjects, loadOwnedObjects_fn;
|
|
53
55
|
const DEFAULT_ZK_SEND_LINK_OPTIONS = {
|
|
54
56
|
host: "https://zksend.com",
|
|
55
57
|
path: "/claim",
|
|
@@ -64,40 +66,36 @@ const _ZkSendLink = class {
|
|
|
64
66
|
claimApi = DEFAULT_ZK_SEND_LINK_OPTIONS.claimApi,
|
|
65
67
|
client = new import_client.SuiClient({ url: (0, import_client.getFullnodeUrl)(network) }),
|
|
66
68
|
keypair,
|
|
67
|
-
contract,
|
|
69
|
+
contract = network === "mainnet" ? import_zk_bag.MAINNET_CONTRACT_IDS : null,
|
|
68
70
|
address,
|
|
69
71
|
host,
|
|
70
72
|
path,
|
|
71
73
|
isContractLink
|
|
72
74
|
}) {
|
|
73
75
|
__privateAdd(this, _loadBag);
|
|
76
|
+
__privateAdd(this, _loadClaimedAssets);
|
|
74
77
|
__privateAdd(this, _createSponsoredTransactionBlock);
|
|
75
78
|
__privateAdd(this, _executeSponsoredTransactionBlock);
|
|
76
79
|
__privateAdd(this, _fetch);
|
|
77
80
|
__privateAdd(this, _listNonContractClaimableAssets);
|
|
78
81
|
__privateAdd(this, _createNonContractClaimTransaction);
|
|
79
82
|
__privateAdd(this, _loadOwnedObjects);
|
|
80
|
-
__privateAdd(this, _loadInitialTransactionData);
|
|
81
83
|
__privateAdd(this, _client, void 0);
|
|
82
|
-
__privateAdd(this, _address, void 0);
|
|
83
|
-
__privateAdd(this, _keypair, void 0);
|
|
84
|
-
__privateAdd(this, _initiallyOwnedObjects, /* @__PURE__ */ new Set());
|
|
85
|
-
__privateAdd(this, _ownedObjects, []);
|
|
86
|
-
__privateAdd(this, _bagObjects, null);
|
|
87
|
-
__privateAdd(this, _gasCoin, void 0);
|
|
88
|
-
__privateAdd(this, _hasSui, false);
|
|
89
|
-
__privateAdd(this, _creatorAddress, void 0);
|
|
90
84
|
__privateAdd(this, _contract, void 0);
|
|
91
85
|
__privateAdd(this, _claimApi, void 0);
|
|
92
86
|
__privateAdd(this, _network, void 0);
|
|
93
87
|
__privateAdd(this, _host, void 0);
|
|
94
88
|
__privateAdd(this, _path, void 0);
|
|
89
|
+
// State for non-contract based links
|
|
90
|
+
__privateAdd(this, _gasCoin, void 0);
|
|
91
|
+
__privateAdd(this, _hasSui, false);
|
|
92
|
+
__privateAdd(this, _ownedObjects, []);
|
|
95
93
|
if (!keypair && !address) {
|
|
96
94
|
throw new Error("Either keypair or address must be provided");
|
|
97
95
|
}
|
|
98
96
|
__privateSet(this, _client, client);
|
|
99
|
-
|
|
100
|
-
|
|
97
|
+
this.keypair = keypair;
|
|
98
|
+
this.address = address ?? keypair.toSuiAddress();
|
|
101
99
|
__privateSet(this, _claimApi, claimApi);
|
|
102
100
|
__privateSet(this, _network, network);
|
|
103
101
|
__privateSet(this, _host, host);
|
|
@@ -109,25 +107,18 @@ const _ZkSendLink = class {
|
|
|
109
107
|
__privateSet(this, _contract, new import_zk_bag.ZkBag(contract.packageId, contract));
|
|
110
108
|
}
|
|
111
109
|
}
|
|
112
|
-
static async fromUrl(url, {
|
|
113
|
-
contract,
|
|
114
|
-
...options
|
|
115
|
-
} = {}) {
|
|
110
|
+
static async fromUrl(url, options = {}) {
|
|
116
111
|
const parsed = new URL(url);
|
|
117
112
|
const isContractLink = parsed.hash.startsWith("#$");
|
|
118
113
|
let link;
|
|
119
114
|
if (isContractLink) {
|
|
120
|
-
if (!contract) {
|
|
121
|
-
throw new Error("Contract options are required for contract based links");
|
|
122
|
-
}
|
|
123
115
|
const keypair = import_ed25519.Ed25519Keypair.fromSecretKey((0, import_utils.fromB64)(parsed.hash.slice(2)));
|
|
124
116
|
link = new _ZkSendLink({
|
|
125
117
|
...options,
|
|
126
118
|
keypair,
|
|
127
119
|
host: `${parsed.protocol}//${parsed.host}`,
|
|
128
120
|
path: parsed.pathname,
|
|
129
|
-
isContractLink: true
|
|
130
|
-
contract
|
|
121
|
+
isContractLink: true
|
|
131
122
|
});
|
|
132
123
|
} else {
|
|
133
124
|
const keypair = import_ed25519.Ed25519Keypair.fromSecretKey(
|
|
@@ -141,7 +132,7 @@ const _ZkSendLink = class {
|
|
|
141
132
|
isContractLink: false
|
|
142
133
|
});
|
|
143
134
|
}
|
|
144
|
-
await link.
|
|
135
|
+
await link.loadAssets();
|
|
145
136
|
return link;
|
|
146
137
|
}
|
|
147
138
|
static async fromAddress(address, options) {
|
|
@@ -150,83 +141,53 @@ const _ZkSendLink = class {
|
|
|
150
141
|
address,
|
|
151
142
|
isContractLink: true
|
|
152
143
|
});
|
|
153
|
-
await link.
|
|
144
|
+
await link.loadAssets();
|
|
154
145
|
return link;
|
|
155
146
|
}
|
|
156
|
-
async
|
|
147
|
+
async loadAssets() {
|
|
157
148
|
if (__privateGet(this, _contract)) {
|
|
158
149
|
await __privateMethod(this, _loadBag, loadBag_fn).call(this);
|
|
159
150
|
} else {
|
|
160
|
-
await
|
|
151
|
+
await __privateMethod(this, _loadOwnedObjects, loadOwnedObjects_fn).call(this);
|
|
161
152
|
}
|
|
162
153
|
}
|
|
163
|
-
async
|
|
164
|
-
if (!
|
|
165
|
-
return __privateMethod(this, _listNonContractClaimableAssets, listNonContractClaimableAssets_fn).call(this, address, options);
|
|
166
|
-
}
|
|
167
|
-
const coins = [];
|
|
168
|
-
const nfts = [];
|
|
169
|
-
for (const object of __privateGet(this, _bagObjects) ?? []) {
|
|
170
|
-
const type = (0, import_utils.parseStructTag)(object.type);
|
|
171
|
-
if (type.address === (0, import_utils.normalizeSuiAddress)("0x2") && type.module === "coin" && type.name === "Coin") {
|
|
172
|
-
coins.push(object);
|
|
173
|
-
} else {
|
|
174
|
-
nfts.push(object);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
const balances = /* @__PURE__ */ new Map();
|
|
178
|
-
coins.forEach((coin) => {
|
|
179
|
-
if (coin.content?.dataType !== "moveObject") {
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
const amount = BigInt(coin.content.fields.balance);
|
|
183
|
-
const coinType = (0, import_utils.normalizeStructTag)((0, import_utils.parseStructTag)(coin.content.type).typeParams[0]);
|
|
184
|
-
if (!balances.has(coinType)) {
|
|
185
|
-
balances.set(coinType, { coinType, amount });
|
|
186
|
-
} else {
|
|
187
|
-
balances.get(coinType).amount += amount;
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
return {
|
|
191
|
-
balances: [...balances.values()],
|
|
192
|
-
nfts,
|
|
193
|
-
coins
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
async claimAssets(address, options) {
|
|
197
|
-
if (!__privateGet(this, _keypair)) {
|
|
154
|
+
async claimAssets(address) {
|
|
155
|
+
if (!this.keypair) {
|
|
198
156
|
throw new Error("Cannot claim assets without links keypair");
|
|
199
157
|
}
|
|
200
|
-
|
|
201
|
-
|
|
158
|
+
if (this.claimed) {
|
|
159
|
+
throw new Error("Assets have already been claimed");
|
|
160
|
+
}
|
|
161
|
+
if (!__privateGet(this, _contract)) {
|
|
202
162
|
return __privateGet(this, _client).signAndExecuteTransactionBlock({
|
|
203
|
-
transactionBlock:
|
|
204
|
-
signer:
|
|
163
|
+
transactionBlock: this.createClaimTransaction(address),
|
|
164
|
+
signer: this.keypair
|
|
205
165
|
});
|
|
206
166
|
}
|
|
207
|
-
|
|
167
|
+
if (!this.assets) {
|
|
168
|
+
await __privateMethod(this, _loadBag, loadBag_fn).call(this);
|
|
169
|
+
}
|
|
170
|
+
const txb = this.createClaimTransaction(address);
|
|
171
|
+
const { digest } = await __privateMethod(this, _executeSponsoredTransactionBlock, executeSponsoredTransactionBlock_fn).call(this, await __privateMethod(this, _createSponsoredTransactionBlock, createSponsoredTransactionBlock_fn).call(this, txb, address, this.keypair.toSuiAddress()), this.keypair);
|
|
208
172
|
return __privateGet(this, _client).waitForTransactionBlock({ digest });
|
|
209
173
|
}
|
|
210
174
|
createClaimTransaction(address, {
|
|
211
|
-
reclaim
|
|
212
|
-
...options
|
|
175
|
+
reclaim
|
|
213
176
|
} = {}) {
|
|
214
177
|
if (!__privateGet(this, _contract)) {
|
|
215
|
-
return __privateMethod(this, _createNonContractClaimTransaction, createNonContractClaimTransaction_fn).call(this, address
|
|
178
|
+
return __privateMethod(this, _createNonContractClaimTransaction, createNonContractClaimTransaction_fn).call(this, address);
|
|
216
179
|
}
|
|
217
|
-
if (
|
|
218
|
-
throw new Error("Filtering claims is not supported for contract based links");
|
|
219
|
-
}
|
|
220
|
-
if (!__privateGet(this, _keypair) && !reclaim) {
|
|
180
|
+
if (!this.keypair && !reclaim) {
|
|
221
181
|
throw new Error("Cannot claim assets without the links keypair");
|
|
222
182
|
}
|
|
223
183
|
const txb = new import_transactions.TransactionBlock();
|
|
224
|
-
const sender = reclaim ? address :
|
|
184
|
+
const sender = reclaim ? address : this.keypair.toSuiAddress();
|
|
225
185
|
txb.setSender(sender);
|
|
226
186
|
const store = txb.object(__privateGet(this, _contract).ids.bagStoreId);
|
|
227
|
-
const [bag, proof] = reclaim ? __privateGet(this, _contract).reclaim(txb, { arguments: [store,
|
|
187
|
+
const [bag, proof] = reclaim ? __privateGet(this, _contract).reclaim(txb, { arguments: [store, this.address] }) : __privateGet(this, _contract).init_claim(txb, { arguments: [store] });
|
|
228
188
|
const objectsToTransfer = [];
|
|
229
|
-
|
|
189
|
+
const objects = [...this.assets?.coins ?? [], ...this.assets?.nfts ?? []];
|
|
190
|
+
for (const object of objects) {
|
|
230
191
|
objectsToTransfer.push(
|
|
231
192
|
__privateGet(this, _contract).claim(txb, {
|
|
232
193
|
arguments: [
|
|
@@ -249,7 +210,13 @@ const _ZkSendLink = class {
|
|
|
249
210
|
return txb;
|
|
250
211
|
}
|
|
251
212
|
async createRegenerateTransaction(sender, options = {}) {
|
|
252
|
-
if (!
|
|
213
|
+
if (!this.assets) {
|
|
214
|
+
await __privateMethod(this, _loadBag, loadBag_fn).call(this);
|
|
215
|
+
}
|
|
216
|
+
if (this.claimed) {
|
|
217
|
+
throw new Error("Assets have already been claimed");
|
|
218
|
+
}
|
|
219
|
+
if (!__privateGet(this, _contract)) {
|
|
253
220
|
throw new Error("Regenerating non-contract based links is not supported");
|
|
254
221
|
}
|
|
255
222
|
const txb = new import_transactions.TransactionBlock();
|
|
@@ -266,7 +233,7 @@ const _ZkSendLink = class {
|
|
|
266
233
|
keypair: newLinkKp
|
|
267
234
|
});
|
|
268
235
|
const to = txb.pure.address(newLinkKp.toSuiAddress());
|
|
269
|
-
__privateGet(this, _contract).update_receiver(txb, { arguments: [store,
|
|
236
|
+
__privateGet(this, _contract).update_receiver(txb, { arguments: [store, this.address, to] });
|
|
270
237
|
return {
|
|
271
238
|
url: newLink.getLink(),
|
|
272
239
|
transactionBlock: txb
|
|
@@ -275,35 +242,40 @@ const _ZkSendLink = class {
|
|
|
275
242
|
};
|
|
276
243
|
let ZkSendLink = _ZkSendLink;
|
|
277
244
|
_client = new WeakMap();
|
|
278
|
-
_address = new WeakMap();
|
|
279
|
-
_keypair = new WeakMap();
|
|
280
|
-
_initiallyOwnedObjects = new WeakMap();
|
|
281
|
-
_ownedObjects = new WeakMap();
|
|
282
|
-
_bagObjects = new WeakMap();
|
|
283
|
-
_gasCoin = new WeakMap();
|
|
284
|
-
_hasSui = new WeakMap();
|
|
285
|
-
_creatorAddress = new WeakMap();
|
|
286
245
|
_contract = new WeakMap();
|
|
287
246
|
_claimApi = new WeakMap();
|
|
288
247
|
_network = new WeakMap();
|
|
289
248
|
_host = new WeakMap();
|
|
290
249
|
_path = new WeakMap();
|
|
250
|
+
_gasCoin = new WeakMap();
|
|
251
|
+
_hasSui = new WeakMap();
|
|
252
|
+
_ownedObjects = new WeakMap();
|
|
291
253
|
_loadBag = new WeakSet();
|
|
292
254
|
loadBag_fn = async function() {
|
|
293
255
|
if (!__privateGet(this, _contract)) {
|
|
294
256
|
return;
|
|
295
257
|
}
|
|
258
|
+
this.assets = {
|
|
259
|
+
balances: [],
|
|
260
|
+
nfts: [],
|
|
261
|
+
coins: []
|
|
262
|
+
};
|
|
296
263
|
const bagField = await __privateGet(this, _client).getDynamicFieldObject({
|
|
297
264
|
parentId: __privateGet(this, _contract).ids.bagStoreTableId,
|
|
298
265
|
name: {
|
|
299
266
|
type: "address",
|
|
300
|
-
value:
|
|
267
|
+
value: this.address
|
|
301
268
|
}
|
|
302
269
|
});
|
|
303
270
|
if (!bagField.data) {
|
|
271
|
+
this.claimed = true;
|
|
272
|
+
await __privateMethod(this, _loadClaimedAssets, loadClaimedAssets_fn).call(this);
|
|
304
273
|
return;
|
|
274
|
+
} else {
|
|
275
|
+
this.claimed = false;
|
|
305
276
|
}
|
|
306
277
|
const itemIds = bagField.data?.content?.fields?.value?.fields?.item_ids.fields.contents;
|
|
278
|
+
this.creatorAddress = bagField.data?.content?.fields?.value?.fields?.owner;
|
|
307
279
|
if (!itemIds) {
|
|
308
280
|
throw new Error("Invalid bag field");
|
|
309
281
|
}
|
|
@@ -314,18 +286,81 @@ loadBag_fn = async function() {
|
|
|
314
286
|
showContent: true
|
|
315
287
|
}
|
|
316
288
|
});
|
|
317
|
-
|
|
318
|
-
|
|
289
|
+
const balances = /* @__PURE__ */ new Map();
|
|
290
|
+
objectsResponse.forEach((object, i) => {
|
|
291
|
+
if (!object.data || !object.data.type) {
|
|
319
292
|
throw new Error(`Failed to load claimable object ${itemIds[i]}`);
|
|
320
293
|
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
294
|
+
const type = (0, import_utils.parseStructTag)((0, import_utils.normalizeStructTag)(object.data.type));
|
|
295
|
+
if (type.address === (0, import_utils.normalizeSuiAddress)("0x2") && type.module === "coin" && type.name === "Coin") {
|
|
296
|
+
this.assets.coins.push({
|
|
297
|
+
objectId: object.data.objectId,
|
|
298
|
+
type: object.data.type,
|
|
299
|
+
version: object.data.version,
|
|
300
|
+
digest: object.data.digest
|
|
301
|
+
});
|
|
302
|
+
if (object.data.content?.dataType === "moveObject") {
|
|
303
|
+
const amount = BigInt(object.data.content.fields.balance);
|
|
304
|
+
const coinType = (0, import_utils.normalizeStructTag)(
|
|
305
|
+
(0, import_utils.parseStructTag)(object.data.content.type).typeParams[0]
|
|
306
|
+
);
|
|
307
|
+
if (!balances.has(coinType)) {
|
|
308
|
+
balances.set(coinType, { coinType, amount });
|
|
309
|
+
} else {
|
|
310
|
+
balances.get(coinType).amount += amount;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
} else {
|
|
314
|
+
this.assets.nfts.push({
|
|
315
|
+
objectId: object.data.objectId,
|
|
316
|
+
type: object.data.type,
|
|
317
|
+
version: object.data.version,
|
|
318
|
+
digest: object.data.digest
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
this.assets.balances = [...balances.values()];
|
|
323
|
+
};
|
|
324
|
+
_loadClaimedAssets = new WeakSet();
|
|
325
|
+
loadClaimedAssets_fn = async function() {
|
|
326
|
+
const result = await __privateGet(this, _client).queryTransactionBlocks({
|
|
327
|
+
limit: 1,
|
|
328
|
+
filter: {
|
|
329
|
+
FromAddress: this.address
|
|
330
|
+
},
|
|
331
|
+
options: {
|
|
332
|
+
showObjectChanges: true,
|
|
333
|
+
showBalanceChanges: true,
|
|
334
|
+
showInput: true
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
if (!result?.data[0]) {
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
const [txb] = result.data;
|
|
341
|
+
if (txb.transaction?.data.transaction.kind !== "ProgrammableTransaction") {
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
const transfer = txb.transaction.data.transaction.transactions.findLast(
|
|
345
|
+
(tx) => "TransferObjects" in tx
|
|
346
|
+
);
|
|
347
|
+
if (!transfer) {
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
const receiverArg = transfer.TransferObjects[1];
|
|
351
|
+
if (!(typeof receiverArg === "object" && "Input" in receiverArg)) {
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
const input = txb.transaction.data.transaction.inputs[receiverArg.Input];
|
|
355
|
+
if (input.type !== "pure") {
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
const receiver = typeof input.value === "string" ? input.value : import_bcs.bcs.Address.parse(new Uint8Array(input.value.Pure));
|
|
359
|
+
this.assets = (0, import_utils2.getAssetsFromTxnBlock)({
|
|
360
|
+
transactionBlock: txb,
|
|
361
|
+
address: receiver,
|
|
362
|
+
isSent: false
|
|
363
|
+
});
|
|
329
364
|
};
|
|
330
365
|
_createSponsoredTransactionBlock = new WeakSet();
|
|
331
366
|
createSponsoredTransactionBlock_fn = async function(txb, claimer, sender) {
|
|
@@ -377,20 +412,28 @@ fetch_fn = async function(path, init) {
|
|
|
377
412
|
return data;
|
|
378
413
|
};
|
|
379
414
|
_listNonContractClaimableAssets = new WeakSet();
|
|
380
|
-
listNonContractClaimableAssets_fn = async function(
|
|
415
|
+
listNonContractClaimableAssets_fn = async function() {
|
|
416
|
+
const balances = [];
|
|
417
|
+
const nfts = [];
|
|
418
|
+
const coins = [];
|
|
419
|
+
if (__privateGet(this, _ownedObjects).length === 0 && !__privateGet(this, _hasSui)) {
|
|
420
|
+
return {
|
|
421
|
+
balances,
|
|
422
|
+
nfts,
|
|
423
|
+
coins
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
const address = new import_ed25519.Ed25519Keypair().toSuiAddress();
|
|
381
427
|
const normalizedAddress = (0, import_utils.normalizeSuiAddress)(address);
|
|
382
|
-
const txb = this.createClaimTransaction(normalizedAddress
|
|
428
|
+
const txb = this.createClaimTransaction(normalizedAddress);
|
|
383
429
|
if (__privateGet(this, _gasCoin) || !__privateGet(this, _hasSui)) {
|
|
384
430
|
txb.setGasPayment([]);
|
|
385
431
|
}
|
|
386
432
|
const dryRun = await __privateGet(this, _client).dryRunTransactionBlock({
|
|
387
433
|
transactionBlock: await txb.build({ client: __privateGet(this, _client) })
|
|
388
434
|
});
|
|
389
|
-
const balances = [];
|
|
390
|
-
const nfts = [];
|
|
391
|
-
const coins = [];
|
|
392
435
|
dryRun.balanceChanges.forEach((balanceChange) => {
|
|
393
|
-
if (BigInt(balanceChange.amount) > 0n && isOwner(balanceChange.owner, normalizedAddress)) {
|
|
436
|
+
if (BigInt(balanceChange.amount) > 0n && (0, import_utils2.isOwner)(balanceChange.owner, normalizedAddress)) {
|
|
394
437
|
balances.push({
|
|
395
438
|
coinType: (0, import_utils.normalizeStructTag)(balanceChange.coinType),
|
|
396
439
|
amount: BigInt(balanceChange.amount)
|
|
@@ -401,13 +444,13 @@ listNonContractClaimableAssets_fn = async function(address, options) {
|
|
|
401
444
|
if ("objectType" in objectChange) {
|
|
402
445
|
const type = (0, import_utils.parseStructTag)(objectChange.objectType);
|
|
403
446
|
if (type.address === (0, import_utils.normalizeSuiAddress)("0x2") && type.module === "coin" && type.name === "Coin") {
|
|
404
|
-
if (ownedAfterChange(objectChange, normalizedAddress)) {
|
|
447
|
+
if ((0, import_utils2.ownedAfterChange)(objectChange, normalizedAddress)) {
|
|
405
448
|
coins.push(objectChange);
|
|
406
449
|
}
|
|
407
450
|
return;
|
|
408
451
|
}
|
|
409
452
|
}
|
|
410
|
-
if (ownedAfterChange(objectChange, normalizedAddress)) {
|
|
453
|
+
if ((0, import_utils2.ownedAfterChange)(objectChange, normalizedAddress)) {
|
|
411
454
|
nfts.push(objectChange);
|
|
412
455
|
}
|
|
413
456
|
});
|
|
@@ -418,16 +461,12 @@ listNonContractClaimableAssets_fn = async function(address, options) {
|
|
|
418
461
|
};
|
|
419
462
|
};
|
|
420
463
|
_createNonContractClaimTransaction = new WeakSet();
|
|
421
|
-
createNonContractClaimTransaction_fn = function(address
|
|
422
|
-
if (!
|
|
464
|
+
createNonContractClaimTransaction_fn = function(address) {
|
|
465
|
+
if (!this.keypair) {
|
|
423
466
|
throw new Error("Cannot claim assets without the links keypair");
|
|
424
467
|
}
|
|
425
|
-
const claimAll = !options?.coinTypes && !options?.objects;
|
|
426
468
|
const txb = new import_transactions.TransactionBlock();
|
|
427
|
-
txb.setSender(
|
|
428
|
-
const coinTypes = new Set(
|
|
429
|
-
options?.coinTypes?.map((type) => (0, import_utils.normalizeStructTag)(`0x2::coin::Coin<${type}>`)) ?? []
|
|
430
|
-
);
|
|
469
|
+
txb.setSender(this.keypair.toSuiAddress());
|
|
431
470
|
const objectsToTransfer = __privateGet(this, _ownedObjects).filter((object) => {
|
|
432
471
|
if (__privateGet(this, _gasCoin)) {
|
|
433
472
|
if (object.objectId === __privateGet(this, _gasCoin).coinObjectId) {
|
|
@@ -436,17 +475,11 @@ createNonContractClaimTransaction_fn = function(address, options) {
|
|
|
436
475
|
} else if (object.type === SUI_COIN_OBJECT_TYPE) {
|
|
437
476
|
return false;
|
|
438
477
|
}
|
|
439
|
-
|
|
440
|
-
return true;
|
|
441
|
-
}
|
|
442
|
-
if (!options?.claimObjectsAddedAfterCreation && !__privateGet(this, _initiallyOwnedObjects).has(object.objectId)) {
|
|
443
|
-
return false;
|
|
444
|
-
}
|
|
445
|
-
return claimAll;
|
|
478
|
+
return true;
|
|
446
479
|
}).map((object) => txb.object(object.objectId));
|
|
447
|
-
if (__privateGet(this, _gasCoin) &&
|
|
448
|
-
txb.transferObjects([txb.gas],
|
|
449
|
-
} else
|
|
480
|
+
if (__privateGet(this, _gasCoin) && this.creatorAddress) {
|
|
481
|
+
txb.transferObjects([txb.gas], this.creatorAddress);
|
|
482
|
+
} else {
|
|
450
483
|
objectsToTransfer.push(txb.gas);
|
|
451
484
|
}
|
|
452
485
|
if (objectsToTransfer.length > 0) {
|
|
@@ -456,14 +489,19 @@ createNonContractClaimTransaction_fn = function(address, options) {
|
|
|
456
489
|
};
|
|
457
490
|
_loadOwnedObjects = new WeakSet();
|
|
458
491
|
loadOwnedObjects_fn = async function() {
|
|
459
|
-
|
|
492
|
+
this.assets = {
|
|
493
|
+
nfts: [],
|
|
494
|
+
balances: [],
|
|
495
|
+
coins: []
|
|
496
|
+
};
|
|
460
497
|
let nextCursor;
|
|
461
498
|
do {
|
|
462
499
|
const ownedObjects = await __privateGet(this, _client).getOwnedObjects({
|
|
463
500
|
cursor: nextCursor,
|
|
464
|
-
owner:
|
|
501
|
+
owner: this.address,
|
|
465
502
|
options: {
|
|
466
|
-
showType: true
|
|
503
|
+
showType: true,
|
|
504
|
+
showContent: true
|
|
467
505
|
}
|
|
468
506
|
});
|
|
469
507
|
nextCursor = ownedObjects.hasNextPage ? ownedObjects.nextCursor : null;
|
|
@@ -480,41 +518,29 @@ loadOwnedObjects_fn = async function() {
|
|
|
480
518
|
} while (nextCursor);
|
|
481
519
|
const coins = await __privateGet(this, _client).getCoins({
|
|
482
520
|
coinType: SUI_COIN_TYPE,
|
|
483
|
-
owner:
|
|
521
|
+
owner: this.address
|
|
484
522
|
});
|
|
485
523
|
__privateSet(this, _hasSui, coins.data.length > 0);
|
|
486
524
|
__privateSet(this, _gasCoin, coins.data.find((coin) => BigInt(coin.balance) % 1000n === 987n));
|
|
487
|
-
};
|
|
488
|
-
_loadInitialTransactionData = new WeakSet();
|
|
489
|
-
loadInitialTransactionData_fn = async function() {
|
|
490
525
|
const result = await __privateGet(this, _client).queryTransactionBlocks({
|
|
491
526
|
limit: 1,
|
|
492
527
|
order: "ascending",
|
|
493
528
|
filter: {
|
|
494
|
-
ToAddress:
|
|
529
|
+
ToAddress: this.address
|
|
495
530
|
},
|
|
496
531
|
options: {
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
});
|
|
501
|
-
result.data[0]?.objectChanges?.forEach((objectChange) => {
|
|
502
|
-
if (ownedAfterChange(objectChange, __privateGet(this, _address))) {
|
|
503
|
-
__privateGet(this, _initiallyOwnedObjects).add((0, import_utils.normalizeSuiObjectId)(objectChange.objectId));
|
|
532
|
+
showInput: true,
|
|
533
|
+
showBalanceChanges: true,
|
|
534
|
+
showObjectChanges: true
|
|
504
535
|
}
|
|
505
536
|
});
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
537
|
+
this.creatorAddress = result.data[0]?.transaction?.data.sender;
|
|
538
|
+
if (__privateGet(this, _hasSui) || __privateGet(this, _ownedObjects).length > 0) {
|
|
539
|
+
this.claimed = false;
|
|
540
|
+
this.assets = await __privateMethod(this, _listNonContractClaimableAssets, listNonContractClaimableAssets_fn).call(this);
|
|
541
|
+
} else if (result.data[0]) {
|
|
542
|
+
this.claimed = true;
|
|
543
|
+
await __privateMethod(this, _loadClaimedAssets, loadClaimedAssets_fn).call(this);
|
|
511
544
|
}
|
|
512
|
-
|
|
513
|
-
return true;
|
|
514
|
-
}
|
|
515
|
-
return false;
|
|
516
|
-
}
|
|
517
|
-
function isOwner(owner, address) {
|
|
518
|
-
return owner && typeof owner === "object" && "AddressOwner" in owner && (0, import_utils.normalizeSuiAddress)(owner.AddressOwner) === address;
|
|
519
|
-
}
|
|
545
|
+
};
|
|
520
546
|
//# sourceMappingURL=claim.js.map
|