@haneullabs/zksend 0.1.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 +1084 -0
- package/README.md +1 -0
- package/dist/cjs/index.d.ts +7 -0
- package/dist/cjs/index.js +38 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/index.test.d.ts +4 -0
- package/dist/cjs/links/builder.d.ts +55 -0
- package/dist/cjs/links/builder.js +361 -0
- package/dist/cjs/links/builder.js.map +7 -0
- package/dist/cjs/links/claim.d.ts +57 -0
- package/dist/cjs/links/claim.js +573 -0
- package/dist/cjs/links/claim.js.map +7 -0
- package/dist/cjs/links/get-sent-transactions.d.ts +25 -0
- package/dist/cjs/links/get-sent-transactions.js +134 -0
- package/dist/cjs/links/get-sent-transactions.js.map +7 -0
- package/dist/cjs/links/list-created-links.d.ts +24 -0
- package/dist/cjs/links/list-created-links.js +124 -0
- package/dist/cjs/links/list-created-links.js.map +7 -0
- package/dist/cjs/links/utils.d.ts +34 -0
- package/dist/cjs/links/utils.js +132 -0
- package/dist/cjs/links/utils.js.map +7 -0
- package/dist/cjs/links/zk-bag.d.ts +72 -0
- package/dist/cjs/links/zk-bag.js +145 -0
- package/dist/cjs/links/zk-bag.js.map +7 -0
- package/dist/cjs/package.json +5 -0
- package/dist/esm/index.d.ts +7 -0
- package/dist/esm/index.js +20 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/index.test.d.ts +4 -0
- package/dist/esm/links/builder.d.ts +55 -0
- package/dist/esm/links/builder.js +341 -0
- package/dist/esm/links/builder.js.map +7 -0
- package/dist/esm/links/claim.d.ts +57 -0
- package/dist/esm/links/claim.js +561 -0
- package/dist/esm/links/claim.js.map +7 -0
- package/dist/esm/links/get-sent-transactions.d.ts +25 -0
- package/dist/esm/links/get-sent-transactions.js +114 -0
- package/dist/esm/links/get-sent-transactions.js.map +7 -0
- package/dist/esm/links/list-created-links.d.ts +24 -0
- package/dist/esm/links/list-created-links.js +104 -0
- package/dist/esm/links/list-created-links.js.map +7 -0
- package/dist/esm/links/utils.d.ts +34 -0
- package/dist/esm/links/utils.js +112 -0
- package/dist/esm/links/utils.js.map +7 -0
- package/dist/esm/links/zk-bag.d.ts +72 -0
- package/dist/esm/links/zk-bag.js +125 -0
- package/dist/esm/links/zk-bag.js.map +7 -0
- package/dist/esm/package.json +5 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/experimental/unified-adapter/package.json +6 -0
- package/package.json +60 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var get_sent_transactions_exports = {};
|
|
20
|
+
__export(get_sent_transactions_exports, {
|
|
21
|
+
getSentTransactionsWithLinks: () => getSentTransactionsWithLinks
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(get_sent_transactions_exports);
|
|
24
|
+
var import_client = require("@haneullabs/haneul/client");
|
|
25
|
+
var import_utils = require("@haneullabs/haneul/utils");
|
|
26
|
+
var import_claim = require("./claim.js");
|
|
27
|
+
var import_zk_bag = require("./zk-bag.js");
|
|
28
|
+
async function getSentTransactionsWithLinks({
|
|
29
|
+
address,
|
|
30
|
+
cursor,
|
|
31
|
+
limit = 10,
|
|
32
|
+
network = "mainnet",
|
|
33
|
+
contract = (0, import_zk_bag.getContractIds)(network),
|
|
34
|
+
client = new import_client.HaneulClient({ url: (0, import_client.getFullnodeUrl)(network) }),
|
|
35
|
+
loadAssets = true,
|
|
36
|
+
loadClaimedAssets = false,
|
|
37
|
+
options,
|
|
38
|
+
...linkOptions
|
|
39
|
+
}) {
|
|
40
|
+
const packageId = (0, import_utils.normalizeHaneulAddress)(contract.packageId);
|
|
41
|
+
const page = await client.queryTransactionBlocks({
|
|
42
|
+
filter: {
|
|
43
|
+
FromAddress: address
|
|
44
|
+
},
|
|
45
|
+
order: "descending",
|
|
46
|
+
cursor,
|
|
47
|
+
limit,
|
|
48
|
+
options: {
|
|
49
|
+
// Allow these to be explicitly overridden:
|
|
50
|
+
showObjectChanges: loadAssets,
|
|
51
|
+
showBalanceChanges: loadAssets,
|
|
52
|
+
...options,
|
|
53
|
+
// This is required to do filtering:
|
|
54
|
+
showInput: true
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
const data = await Promise.all(
|
|
58
|
+
page.data.map(async (res) => {
|
|
59
|
+
const transaction = res.transaction?.data.transaction;
|
|
60
|
+
if (transaction?.kind !== "ProgrammableTransaction") {
|
|
61
|
+
throw new Error("Invalid transaction");
|
|
62
|
+
}
|
|
63
|
+
const newLinks = await Promise.all(
|
|
64
|
+
transaction.transactions.filter(
|
|
65
|
+
(tx) => "MoveCall" in tx ? tx.MoveCall.package === packageId && tx.MoveCall.module === "zk_bag" && tx.MoveCall.function === "new" : false
|
|
66
|
+
).map(async (tx) => {
|
|
67
|
+
if (!("MoveCall" in tx)) {
|
|
68
|
+
throw new Error("Expected MoveCall");
|
|
69
|
+
}
|
|
70
|
+
const addressArg = tx.MoveCall.arguments?.[1];
|
|
71
|
+
if (!addressArg || typeof addressArg !== "object" || !("Input" in addressArg)) {
|
|
72
|
+
throw new Error("Invalid address argument");
|
|
73
|
+
}
|
|
74
|
+
const input = transaction.inputs[addressArg.Input];
|
|
75
|
+
if (input.type !== "pure") {
|
|
76
|
+
throw new Error("Expected Address input to be a Pure value");
|
|
77
|
+
}
|
|
78
|
+
const address2 = (0, import_utils.normalizeHaneulAddress)(input.value);
|
|
79
|
+
const link = new import_claim.ZkSendLink({
|
|
80
|
+
network,
|
|
81
|
+
address: address2,
|
|
82
|
+
contract,
|
|
83
|
+
isContractLink: true,
|
|
84
|
+
client,
|
|
85
|
+
...linkOptions
|
|
86
|
+
});
|
|
87
|
+
await link.loadAssets({
|
|
88
|
+
transaction: res,
|
|
89
|
+
loadAssets,
|
|
90
|
+
loadClaimedAssets
|
|
91
|
+
});
|
|
92
|
+
return link;
|
|
93
|
+
})
|
|
94
|
+
);
|
|
95
|
+
const regeneratedLinks = await Promise.all(
|
|
96
|
+
transaction.transactions.filter(
|
|
97
|
+
(tx) => "MoveCall" in tx ? tx.MoveCall.package === packageId && tx.MoveCall.module === "zk_bag" && tx.MoveCall.function === "update_receiver" : false
|
|
98
|
+
).map(async (tx) => {
|
|
99
|
+
if (!("MoveCall" in tx)) {
|
|
100
|
+
throw new Error("Expected MoveCall");
|
|
101
|
+
}
|
|
102
|
+
const addressArg = tx.MoveCall.arguments?.[2];
|
|
103
|
+
if (!addressArg || typeof addressArg !== "object" || !("Input" in addressArg)) {
|
|
104
|
+
throw new Error("Invalid address argument");
|
|
105
|
+
}
|
|
106
|
+
const input = transaction.inputs[addressArg.Input];
|
|
107
|
+
if (input.type !== "pure") {
|
|
108
|
+
throw new Error("Expected Address input to be a Pure value");
|
|
109
|
+
}
|
|
110
|
+
const address2 = (0, import_utils.normalizeHaneulAddress)(input.value);
|
|
111
|
+
const link = new import_claim.ZkSendLink({
|
|
112
|
+
network,
|
|
113
|
+
address: address2,
|
|
114
|
+
contract,
|
|
115
|
+
isContractLink: true,
|
|
116
|
+
...linkOptions
|
|
117
|
+
});
|
|
118
|
+
await link.loadAssets({ loadAssets, loadClaimedAssets });
|
|
119
|
+
return link;
|
|
120
|
+
})
|
|
121
|
+
);
|
|
122
|
+
return {
|
|
123
|
+
transaction: res,
|
|
124
|
+
links: [...newLinks, ...regeneratedLinks]
|
|
125
|
+
};
|
|
126
|
+
})
|
|
127
|
+
);
|
|
128
|
+
return {
|
|
129
|
+
data,
|
|
130
|
+
nextCursor: page.nextCursor,
|
|
131
|
+
hasNextPage: page.hasNextPage
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=get-sent-transactions.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/links/get-sent-transactions.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { HaneulTransactionBlockResponseOptions } from '@haneullabs/haneul/client';\nimport { getFullnodeUrl, HaneulClient } from '@haneullabs/haneul/client';\nimport { normalizeHaneulAddress } from '@haneullabs/haneul/utils';\n\nimport { ZkSendLink } from './claim.js';\nimport { getContractIds } from './zk-bag.js';\nimport type { ZkBagContractOptions } from './zk-bag.js';\n\nexport async function getSentTransactionsWithLinks({\n\taddress,\n\tcursor,\n\tlimit = 10,\n\tnetwork = 'mainnet',\n\tcontract = getContractIds(network),\n\tclient = new HaneulClient({ url: getFullnodeUrl(network) }),\n\tloadAssets = true,\n\tloadClaimedAssets = false,\n\toptions,\n\t...linkOptions\n}: {\n\taddress: string;\n\tcontract?: ZkBagContractOptions;\n\tcursor?: string;\n\tlimit?: number;\n\tnetwork?: 'mainnet' | 'testnet';\n\tloadAssets?: boolean;\n\tloadClaimedAssets?: boolean;\n\n\t// Link options:\n\thost?: string;\n\tpath?: string;\n\tclaimApi?: string;\n\tclient?: HaneulClient;\n\toptions?: HaneulTransactionBlockResponseOptions;\n}) {\n\tconst packageId = normalizeHaneulAddress(contract.packageId);\n\n\tconst page = await client.queryTransactionBlocks({\n\t\tfilter: {\n\t\t\tFromAddress: address,\n\t\t},\n\t\torder: 'descending',\n\t\tcursor,\n\t\tlimit,\n\t\toptions: {\n\t\t\t// Allow these to be explicitly overridden:\n\t\t\tshowObjectChanges: loadAssets,\n\t\t\tshowBalanceChanges: loadAssets,\n\n\t\t\t...options,\n\n\t\t\t// This is required to do filtering:\n\t\t\tshowInput: true,\n\t\t},\n\t});\n\n\tconst data = await Promise.all(\n\t\tpage.data.map(async (res) => {\n\t\t\tconst transaction = res.transaction?.data.transaction;\n\t\t\tif (transaction?.kind !== 'ProgrammableTransaction') {\n\t\t\t\tthrow new Error('Invalid transaction');\n\t\t\t}\n\n\t\t\tconst newLinks = await Promise.all(\n\t\t\t\ttransaction.transactions\n\t\t\t\t\t.filter((tx) =>\n\t\t\t\t\t\t'MoveCall' in tx\n\t\t\t\t\t\t\t? tx.MoveCall.package === packageId &&\n\t\t\t\t\t\t\t\ttx.MoveCall.module === 'zk_bag' &&\n\t\t\t\t\t\t\t\ttx.MoveCall.function === 'new'\n\t\t\t\t\t\t\t: false,\n\t\t\t\t\t)\n\t\t\t\t\t.map(async (tx) => {\n\t\t\t\t\t\tif (!('MoveCall' in tx)) {\n\t\t\t\t\t\t\tthrow new Error('Expected MoveCall');\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst addressArg = tx.MoveCall.arguments?.[1];\n\n\t\t\t\t\t\tif (!addressArg || typeof addressArg !== 'object' || !('Input' in addressArg)) {\n\t\t\t\t\t\t\tthrow new Error('Invalid address argument');\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst input = transaction.inputs[addressArg.Input];\n\n\t\t\t\t\t\tif (input.type !== 'pure') {\n\t\t\t\t\t\t\tthrow new Error('Expected Address input to be a Pure value');\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst address = normalizeHaneulAddress(input.value as string);\n\n\t\t\t\t\t\tconst link = new ZkSendLink({\n\t\t\t\t\t\t\tnetwork,\n\t\t\t\t\t\t\taddress,\n\t\t\t\t\t\t\tcontract,\n\t\t\t\t\t\t\tisContractLink: true,\n\t\t\t\t\t\t\tclient,\n\t\t\t\t\t\t\t...linkOptions,\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tawait link.loadAssets({\n\t\t\t\t\t\t\ttransaction: res,\n\t\t\t\t\t\t\tloadAssets,\n\t\t\t\t\t\t\tloadClaimedAssets,\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\treturn link;\n\t\t\t\t\t}),\n\t\t\t);\n\n\t\t\tconst regeneratedLinks = await Promise.all(\n\t\t\t\ttransaction.transactions\n\t\t\t\t\t.filter((tx) =>\n\t\t\t\t\t\t'MoveCall' in tx\n\t\t\t\t\t\t\t? tx.MoveCall.package === packageId &&\n\t\t\t\t\t\t\t\ttx.MoveCall.module === 'zk_bag' &&\n\t\t\t\t\t\t\t\ttx.MoveCall.function === 'update_receiver'\n\t\t\t\t\t\t\t: false,\n\t\t\t\t\t)\n\t\t\t\t\t.map(async (tx) => {\n\t\t\t\t\t\tif (!('MoveCall' in tx)) {\n\t\t\t\t\t\t\tthrow new Error('Expected MoveCall');\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst addressArg = tx.MoveCall.arguments?.[2];\n\n\t\t\t\t\t\tif (!addressArg || typeof addressArg !== 'object' || !('Input' in addressArg)) {\n\t\t\t\t\t\t\tthrow new Error('Invalid address argument');\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst input = transaction.inputs[addressArg.Input];\n\n\t\t\t\t\t\tif (input.type !== 'pure') {\n\t\t\t\t\t\t\tthrow new Error('Expected Address input to be a Pure value');\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst address = normalizeHaneulAddress(input.value as string);\n\n\t\t\t\t\t\tconst link = new ZkSendLink({\n\t\t\t\t\t\t\tnetwork,\n\t\t\t\t\t\t\taddress,\n\t\t\t\t\t\t\tcontract,\n\t\t\t\t\t\t\tisContractLink: true,\n\t\t\t\t\t\t\t...linkOptions,\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tawait link.loadAssets({ loadAssets, loadClaimedAssets });\n\n\t\t\t\t\t\treturn link;\n\t\t\t\t\t}),\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\ttransaction: res,\n\t\t\t\tlinks: [...newLinks, ...regeneratedLinks],\n\t\t\t};\n\t\t}),\n\t);\n\n\treturn {\n\t\tdata,\n\t\tnextCursor: page.nextCursor,\n\t\thasNextPage: page.hasNextPage,\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,oBAA6C;AAC7C,mBAAuC;AAEvC,mBAA2B;AAC3B,oBAA+B;AAG/B,eAAsB,6BAA6B;AAAA,EAClD;AAAA,EACA;AAAA,EACA,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,eAAW,8BAAe,OAAO;AAAA,EACjC,SAAS,IAAI,2BAAa,EAAE,SAAK,8BAAe,OAAO,EAAE,CAAC;AAAA,EAC1D,aAAa;AAAA,EACb,oBAAoB;AAAA,EACpB;AAAA,EACA,GAAG;AACJ,GAeG;AACF,QAAM,gBAAY,qCAAuB,SAAS,SAAS;AAE3D,QAAM,OAAO,MAAM,OAAO,uBAAuB;AAAA,IAChD,QAAQ;AAAA,MACP,aAAa;AAAA,IACd;AAAA,IACA,OAAO;AAAA,IACP;AAAA,IACA;AAAA,IACA,SAAS;AAAA;AAAA,MAER,mBAAmB;AAAA,MACnB,oBAAoB;AAAA,MAEpB,GAAG;AAAA;AAAA,MAGH,WAAW;AAAA,IACZ;AAAA,EACD,CAAC;AAED,QAAM,OAAO,MAAM,QAAQ;AAAA,IAC1B,KAAK,KAAK,IAAI,OAAO,QAAQ;AAC5B,YAAM,cAAc,IAAI,aAAa,KAAK;AAC1C,UAAI,aAAa,S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5C,cAAI,CAAC,cAAc,OAAO,eAAe,YAAY,EAAE,WAAW,aAAa;AAC9E,kBAAM,IAAI,MAAM,0BAA0B;AAAA,UAC3C;AAEA,gBAAM,QAAQ,YAAY,OAAO,WAAW,KAAK;AAEjD,cAAI,MAAM,SAAS,QAAQ;AAC1B,kBAAM,IAAI,MAAM,2CAA2C;AAAA,UAC5D;AAEA,gBAAMA,eAAU,qCAAuB,MAAM,KAAe;AAE5D,gBAAM,OAAO,IAAI,wBAAW;AAAA,YAC3B;AAAA,YACA,SAAAA;AAAA,YACA;AAAA,YACA,gBAAgB;AAAA,YAChB,GAAG;AAAA,UACJ,CAAC;AAED,gBAAM,KAAK,WAAW,EAAE,YAAY,kBAAkB,CAAC;AAEvD,iBAAO;AAAA,QACR,CAAC;AAAA,MACH;AAEA,aAAO;AAAA,QACN,aAAa;AAAA,QACb,OAAO,CAAC,GAAG,UAAU,GAAG,gBAAgB;AAAA,MACzC;AAAA,IACD,CAAC;AAAA,EACF;AAEA,SAAO;AAAA,IACN;AAAA,IACA,YAAY,KAAK;AAAA,IACjB,aAAa,KAAK;AAAA,EACnB;AACD;",
|
|
6
|
+
"names": ["address"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { HaneulClient } from '@haneullabs/haneul/client';
|
|
2
|
+
import { ZkSendLink } from './claim.js';
|
|
3
|
+
import type { ZkBagContractOptions } from './zk-bag.js';
|
|
4
|
+
export declare function listCreatedLinks({ address, cursor, network, contract, fetch: fetchFn, ...linkOptions }: {
|
|
5
|
+
address: string;
|
|
6
|
+
contract?: ZkBagContractOptions;
|
|
7
|
+
cursor?: string;
|
|
8
|
+
network?: 'mainnet' | 'testnet';
|
|
9
|
+
host?: string;
|
|
10
|
+
path?: string;
|
|
11
|
+
claimApi?: string;
|
|
12
|
+
client?: HaneulClient;
|
|
13
|
+
fetch?: typeof fetch;
|
|
14
|
+
}): Promise<{
|
|
15
|
+
cursor: string | null;
|
|
16
|
+
hasNextPage: boolean;
|
|
17
|
+
links: {
|
|
18
|
+
link: ZkSendLink;
|
|
19
|
+
claimed: boolean;
|
|
20
|
+
assets: import("./utils.js").LinkAssets;
|
|
21
|
+
digest: string;
|
|
22
|
+
createdAt: string;
|
|
23
|
+
}[];
|
|
24
|
+
}>;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var list_created_links_exports = {};
|
|
20
|
+
__export(list_created_links_exports, {
|
|
21
|
+
listCreatedLinks: () => listCreatedLinks
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(list_created_links_exports);
|
|
24
|
+
var import_bcs = require("@haneullabs/haneul/bcs");
|
|
25
|
+
var import_graphql = require("@haneullabs/haneul/graphql");
|
|
26
|
+
var import_latest = require("@haneullabs/haneul/graphql/schemas/latest");
|
|
27
|
+
var import_utils = require("@haneullabs/haneul/utils");
|
|
28
|
+
var import_claim = require("./claim.js");
|
|
29
|
+
var import_zk_bag = require("./zk-bag.js");
|
|
30
|
+
const ListCreatedLinksQuery = (0, import_latest.graphql)(`
|
|
31
|
+
query listCreatedLinks($address: HaneulAddress!, $function: String!, $cursor: String) {
|
|
32
|
+
transactions(
|
|
33
|
+
last: 10
|
|
34
|
+
before: $cursor
|
|
35
|
+
filter: { sentAddress: $address, function: $function }
|
|
36
|
+
) {
|
|
37
|
+
pageInfo {
|
|
38
|
+
startCursor
|
|
39
|
+
hasPreviousPage
|
|
40
|
+
}
|
|
41
|
+
nodes {
|
|
42
|
+
effects {
|
|
43
|
+
timestamp
|
|
44
|
+
}
|
|
45
|
+
digest
|
|
46
|
+
transactionBcs
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
`);
|
|
51
|
+
async function listCreatedLinks({
|
|
52
|
+
address,
|
|
53
|
+
cursor,
|
|
54
|
+
network,
|
|
55
|
+
contract = (0, import_zk_bag.getContractIds)(network),
|
|
56
|
+
fetch: fetchFn,
|
|
57
|
+
...linkOptions
|
|
58
|
+
}) {
|
|
59
|
+
const gqlClient = new import_graphql.HaneulGraphQLClient({
|
|
60
|
+
url: network === "testnet" ? "https://graphql.testnet.haneul.io/graphql" : "https://graphql.mainnet.haneul.io/graphql",
|
|
61
|
+
fetch: fetchFn
|
|
62
|
+
});
|
|
63
|
+
const packageId = (0, import_utils.normalizeHaneulAddress)(contract.packageId);
|
|
64
|
+
const page = await gqlClient.query({
|
|
65
|
+
query: ListCreatedLinksQuery,
|
|
66
|
+
variables: {
|
|
67
|
+
address,
|
|
68
|
+
cursor,
|
|
69
|
+
function: `${packageId}::zk_bag::new`
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
const transactions = page.data?.transactions;
|
|
73
|
+
if (!transactions || page.errors?.length) {
|
|
74
|
+
throw new Error("Failed to load created links");
|
|
75
|
+
}
|
|
76
|
+
const links = (await Promise.all(
|
|
77
|
+
transactions.nodes.map(async (node) => {
|
|
78
|
+
if (!node.transactionBcs) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
const kind = import_bcs.bcs.TransactionData.parse((0, import_utils.fromBase64)(node.transactionBcs)).V1.kind;
|
|
82
|
+
if (!kind?.ProgrammableTransaction) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
const { inputs, commands } = kind.ProgrammableTransaction;
|
|
86
|
+
const fn = commands.find(
|
|
87
|
+
(command) => command.MoveCall?.package === packageId && command.MoveCall.module === "zk_bag" && command.MoveCall.function === "new"
|
|
88
|
+
);
|
|
89
|
+
if (!fn?.MoveCall) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
const addressArg = fn.MoveCall.arguments[1];
|
|
93
|
+
if (addressArg.$kind !== "Input") {
|
|
94
|
+
throw new Error("Invalid address argument");
|
|
95
|
+
}
|
|
96
|
+
const input = inputs[addressArg.Input];
|
|
97
|
+
if (!input.Pure) {
|
|
98
|
+
throw new Error("Expected Address input to be a Pure value");
|
|
99
|
+
}
|
|
100
|
+
const address2 = import_bcs.bcs.Address.fromBase64(input.Pure.bytes);
|
|
101
|
+
const link = new import_claim.ZkSendLink({
|
|
102
|
+
network,
|
|
103
|
+
address: address2,
|
|
104
|
+
contract,
|
|
105
|
+
isContractLink: true,
|
|
106
|
+
...linkOptions
|
|
107
|
+
});
|
|
108
|
+
await link.loadAssets();
|
|
109
|
+
return {
|
|
110
|
+
link,
|
|
111
|
+
claimed: !!link.claimed,
|
|
112
|
+
assets: link.assets,
|
|
113
|
+
digest: node.digest,
|
|
114
|
+
createdAt: node.effects?.timestamp
|
|
115
|
+
};
|
|
116
|
+
})
|
|
117
|
+
)).reverse();
|
|
118
|
+
return {
|
|
119
|
+
cursor: transactions.pageInfo.startCursor,
|
|
120
|
+
hasNextPage: transactions.pageInfo.hasPreviousPage,
|
|
121
|
+
links: links.filter((link) => link !== null)
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=list-created-links.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/links/list-created-links.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { bcs } from '@haneullabs/haneul/bcs';\nimport type { HaneulClient } from '@haneullabs/haneul/client';\nimport { HaneulGraphQLClient } from '@haneullabs/haneul/graphql';\nimport { graphql } from '@haneullabs/haneul/graphql/schemas/latest';\nimport { fromBase64, normalizeHaneulAddress } from '@haneullabs/haneul/utils';\n\nimport { ZkSendLink } from './claim.js';\nimport type { ZkBagContractOptions } from './zk-bag.js';\nimport { getContractIds } from './zk-bag.js';\n\nconst ListCreatedLinksQuery = graphql(`\n\tquery listCreatedLinks($address: HaneulAddress!, $function: String!, $cursor: String) {\n\t\ttransactions(\n\t\t\tlast: 10\n\t\t\tbefore: $cursor\n\t\t\tfilter: { sentAddress: $address, function: $function }\n\t\t) {\n\t\t\tpageInfo {\n\t\t\t\tstartCursor\n\t\t\t\thasPreviousPage\n\t\t\t}\n\t\t\tnodes {\n\t\t\t\teffects {\n\t\t\t\t\ttimestamp\n\t\t\t\t}\n\t\t\t\tdigest\n\t\t\t\ttransactionBcs\n\t\t\t}\n\t\t}\n\t}\n`);\n\nexport async function listCreatedLinks({\n\taddress,\n\tcursor,\n\tnetwork,\n\tcontract = getContractIds(network),\n\tfetch: fetchFn,\n\t...linkOptions\n}: {\n\taddress: string;\n\tcontract?: ZkBagContractOptions;\n\tcursor?: string;\n\tnetwork?: 'mainnet' | 'testnet';\n\n\t// Link options:\n\thost?: string;\n\tpath?: string;\n\tclaimApi?: string;\n\tclient?: HaneulClient;\n\tfetch?: typeof fetch;\n}) {\n\tconst gqlClient = new HaneulGraphQLClient({\n\t\turl:\n\t\t\tnetwork === 'testnet'\n\t\t\t\t? 'https://graphql.testnet.haneul.io/graphql'\n\t\t\t\t: 'https://graphql.mainnet.haneul.io/graphql',\n\t\tfetch: fetchFn,\n\t});\n\n\tconst packageId = normalizeHaneulAddress(contract.packageId);\n\n\tconst page = await gqlClient.query({\n\t\tquery: ListCreatedLinksQuery,\n\t\tvariables: {\n\t\t\taddress,\n\t\t\tcursor,\n\t\t\tfunction: `${packageId}::zk_bag::new`,\n\t\t},\n\t});\n\n\tconst transactions = page.data?.transactions;\n\n\tif (!transactions || page.errors?.length) {\n\t\tthrow new Error('Failed to load created links');\n\t}\n\n\tconst links = (\n\t\tawait Promise.all(\n\t\t\ttransactions.nodes.map(async (node) => {\n\t\t\t\tif (!node.transactionBcs) {\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\n\t\t\t\tconst kind = bcs.TransactionData.parse(fromBase64(node.transactionBcs)).V1.kind;\n\n\t\t\t\tif (!kind?.ProgrammableTransaction) {\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\n\t\t\t\tconst { inputs, commands } = kind.ProgrammableTransaction;\n\n\t\t\t\tconst fn = commands.find(\n\t\t\t\t\t(command) =>\n\t\t\t\t\t\tcommand.MoveCall?.package === packageId &&\n\t\t\t\t\t\tcommand.MoveCall.module === 'zk_bag' &&\n\t\t\t\t\t\tcommand.MoveCall.function === 'new',\n\t\t\t\t);\n\n\t\t\t\tif (!fn?.MoveCall) {\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\n\t\t\t\tconst addressArg = fn.MoveCall.arguments[1];\n\n\t\t\t\tif (addressArg.$kind !== 'Input') {\n\t\t\t\t\tthrow new Error('Invalid address argument');\n\t\t\t\t}\n\n\t\t\t\tconst input = inputs[addressArg.Input];\n\n\t\t\t\tif (!input.Pure) {\n\t\t\t\t\tthrow new Error('Expected Address input to be a Pure value');\n\t\t\t\t}\n\n\t\t\t\tconst address = bcs.Address.fromBase64(input.Pure.bytes);\n\n\t\t\t\tconst link = new ZkSendLink({\n\t\t\t\t\tnetwork,\n\t\t\t\t\taddress,\n\t\t\t\t\tcontract,\n\t\t\t\t\tisContractLink: true,\n\t\t\t\t\t...linkOptions,\n\t\t\t\t});\n\n\t\t\t\tawait link.loadAssets();\n\n\t\t\t\treturn {\n\t\t\t\t\tlink,\n\t\t\t\t\tclaimed: !!link.claimed,\n\t\t\t\t\tassets: link.assets!,\n\t\t\t\t\tdigest: node.digest,\n\t\t\t\t\tcreatedAt: node.effects?.timestamp!,\n\t\t\t\t};\n\t\t\t}),\n\t\t)\n\t).reverse();\n\n\treturn {\n\t\tcursor: transactions.pageInfo.startCursor,\n\t\thasNextPage: transactions.pageInfo.hasPreviousPage,\n\t\tlinks: links.filter((link): link is NonNullable<typeof link> => link !== null),\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAoB;AAEpB,qBAAoC;AACpC,oBAAwB;AACxB,mBAAmD;AAEnD,mBAA2B;AAE3B,oBAA+B;AAE/B,MAAM,4BAAwB,uBAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAoBrC;AAED,eAAsB,iBAAiB;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA,eAAW,8BAAe,OAAO;AAAA,EACjC,OAAO;AAAA,EACP,GAAG;AACJ,GAYG;AACF,QAAM,YAAY,IAAI,mCAAoB;AAAA,IACzC,KACC,YAAY,YACT,8CACA;AAAA,IACJ,OAAO;AAAA,EACR,CAAC;AAED,QAAM,gBAAY,qCAAuB,SAAS,SAAS;AAE3D,QAAM,OAAO,MAAM,UAAU,MAAM;AAAA,IAClC,OAAO;AAAA,IACP,WAAW;AAAA,MACV;AAAA,MACA;AAAA,MACA,UAAU,GAAG,SAAS;AAAA,IACvB;AAAA,EACD,CAAC;AAED,QAAM,eAAe,KAAK,MAAM;AAEhC,MAAI,CAAC,gBAAgB,KAAK,QAAQ,QAAQ;AACzC,UAAM,IAAI,MAAM,8BAA8B;AAAA,EAC/C;AAEA,QAAM,SACL,MAA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EAC9E;AACD;",
|
|
6
|
+
"names": ["address"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ObjectOwner, HaneulObjectChange, HaneulTransactionBlockResponse } from '@haneullabs/haneul/client';
|
|
2
|
+
import type { Transaction } from '@haneullabs/haneul/transactions';
|
|
3
|
+
export interface LinkAssets {
|
|
4
|
+
balances: {
|
|
5
|
+
coinType: string;
|
|
6
|
+
amount: bigint;
|
|
7
|
+
}[];
|
|
8
|
+
nfts: {
|
|
9
|
+
objectId: string;
|
|
10
|
+
type: string;
|
|
11
|
+
version: string;
|
|
12
|
+
digest: string;
|
|
13
|
+
}[];
|
|
14
|
+
coins: {
|
|
15
|
+
objectId: string;
|
|
16
|
+
type: string;
|
|
17
|
+
version: string;
|
|
18
|
+
digest: string;
|
|
19
|
+
}[];
|
|
20
|
+
}
|
|
21
|
+
export declare function isClaimTransaction(tx: Transaction, options: {
|
|
22
|
+
packageId: string;
|
|
23
|
+
}): boolean;
|
|
24
|
+
export declare function getAssetsFromTransaction({ transaction, address, isSent, }: {
|
|
25
|
+
transaction: HaneulTransactionBlockResponse;
|
|
26
|
+
address: string;
|
|
27
|
+
isSent: boolean;
|
|
28
|
+
}): LinkAssets;
|
|
29
|
+
export declare function ownedAfterChange(objectChange: HaneulObjectChange, address: string): objectChange is Extract<HaneulObjectChange, {
|
|
30
|
+
type: 'created' | 'transferred' | 'mutated';
|
|
31
|
+
}>;
|
|
32
|
+
export declare function isOwner(owner: ObjectOwner, address: string): owner is {
|
|
33
|
+
AddressOwner: string;
|
|
34
|
+
};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var utils_exports = {};
|
|
20
|
+
__export(utils_exports, {
|
|
21
|
+
getAssetsFromTransaction: () => getAssetsFromTransaction,
|
|
22
|
+
isClaimTransaction: () => isClaimTransaction,
|
|
23
|
+
isOwner: () => isOwner,
|
|
24
|
+
ownedAfterChange: () => ownedAfterChange
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(utils_exports);
|
|
27
|
+
var import_utils = require("@haneullabs/haneul/utils");
|
|
28
|
+
function isClaimTransaction(tx, options) {
|
|
29
|
+
let transfers = 0;
|
|
30
|
+
for (const command of tx.getData().commands) {
|
|
31
|
+
switch (command.$kind) {
|
|
32
|
+
case "TransferObjects":
|
|
33
|
+
if (!command.TransferObjects.objects.every(
|
|
34
|
+
(o) => o.$kind === "Result" || o.$kind === "NestedResult"
|
|
35
|
+
)) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
transfers++;
|
|
39
|
+
break;
|
|
40
|
+
case "MoveCall":
|
|
41
|
+
if (command.MoveCall.package !== options.packageId) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
if (command.MoveCall.module !== "zk_bag") {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
const fn = command.MoveCall.function;
|
|
48
|
+
if (fn !== "init_claim" && fn !== "reclaim" && fn !== "claim" && fn !== "finalize") {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
break;
|
|
52
|
+
default:
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return transfers === 1;
|
|
57
|
+
}
|
|
58
|
+
function getAssetsFromTransaction({
|
|
59
|
+
transaction,
|
|
60
|
+
address,
|
|
61
|
+
isSent
|
|
62
|
+
}) {
|
|
63
|
+
const normalizedAddress = (0, import_utils.normalizeHaneulAddress)(address);
|
|
64
|
+
const balances = [];
|
|
65
|
+
const nfts = [];
|
|
66
|
+
const coins = [];
|
|
67
|
+
transaction.balanceChanges?.forEach((change) => {
|
|
68
|
+
const validAmountChange = isSent ? BigInt(change.amount) < 0n : BigInt(change.amount) > 0n;
|
|
69
|
+
if (validAmountChange && isOwner(change.owner, normalizedAddress)) {
|
|
70
|
+
balances.push({
|
|
71
|
+
coinType: (0, import_utils.normalizeStructTag)(change.coinType),
|
|
72
|
+
amount: BigInt(change.amount)
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
transaction.objectChanges?.forEach((change) => {
|
|
77
|
+
if (!isObjectOwner(change, normalizedAddress, isSent)) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if ("objectType" in change) {
|
|
81
|
+
const type = (0, import_utils.parseStructTag)(change.objectType);
|
|
82
|
+
if (type.address === (0, import_utils.normalizeHaneulAddress)("0x2") && type.module === "coin" && type.name === "Coin") {
|
|
83
|
+
if (change.type === "created" || change.type === "transferred" || change.type === "mutated") {
|
|
84
|
+
coins.push({
|
|
85
|
+
...change,
|
|
86
|
+
type: change.objectType
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (isObjectOwner(change, normalizedAddress, isSent) && (change.type === "created" || change.type === "transferred" || change.type === "mutated")) {
|
|
93
|
+
nfts.push({
|
|
94
|
+
objectId: change.objectId,
|
|
95
|
+
type: change.objectType,
|
|
96
|
+
version: change.version,
|
|
97
|
+
digest: change.digest
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
return {
|
|
102
|
+
balances,
|
|
103
|
+
nfts,
|
|
104
|
+
coins
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function getObjectOwnerFromObjectChange(objectChange, isSent) {
|
|
108
|
+
if (isSent) {
|
|
109
|
+
return "owner" in objectChange ? objectChange.owner : null;
|
|
110
|
+
}
|
|
111
|
+
return "recipient" in objectChange ? objectChange.recipient : null;
|
|
112
|
+
}
|
|
113
|
+
function isObjectOwner(objectChange, address, isSent) {
|
|
114
|
+
const owner = getObjectOwnerFromObjectChange(objectChange, isSent);
|
|
115
|
+
if (isSent) {
|
|
116
|
+
return owner && typeof owner === "object" && "AddressOwner" in owner;
|
|
117
|
+
}
|
|
118
|
+
return ownedAfterChange(objectChange, address);
|
|
119
|
+
}
|
|
120
|
+
function ownedAfterChange(objectChange, address) {
|
|
121
|
+
if (objectChange.type === "transferred" && isOwner(objectChange.recipient, address)) {
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
if ((objectChange.type === "created" || objectChange.type === "mutated") && isOwner(objectChange.owner, address)) {
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
function isOwner(owner, address) {
|
|
130
|
+
return owner && typeof owner === "object" && "AddressOwner" in owner && (0, import_utils.normalizeHaneulAddress)(owner.AddressOwner) === address;
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/links/utils.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { ObjectOwner, HaneulObjectChange, HaneulTransactionBlockResponse } from '@haneullabs/haneul/client';\nimport type { Transaction } from '@haneullabs/haneul/transactions';\nimport { normalizeStructTag, normalizeHaneulAddress, parseStructTag } from '@haneullabs/haneul/utils';\n\nexport interface LinkAssets {\n\tbalances: {\n\t\tcoinType: string;\n\t\tamount: bigint;\n\t}[];\n\n\tnfts: {\n\t\tobjectId: string;\n\t\ttype: string;\n\t\tversion: string;\n\t\tdigest: string;\n\t}[];\n\n\tcoins: {\n\t\tobjectId: string;\n\t\ttype: string;\n\t\tversion: string;\n\t\tdigest: string;\n\t}[];\n}\n\nexport function isClaimTransaction(\n\ttx: Transaction,\n\toptions: {\n\t\tpackageId: string;\n\t},\n) {\n\tlet transfers = 0;\n\n\tfor (const command of tx.getData().commands) {\n\t\tswitch (command.$kind) {\n\t\t\tcase 'TransferObjects':\n\t\t\t\t// Ensure that we are only transferring results of a claim\n\t\t\t\tif (\n\t\t\t\t\t!command.TransferObjects.objects.every(\n\t\t\t\t\t\t(o) => o.$kind === 'Result' || o.$kind === 'NestedResult',\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\ttransfers++;\n\t\t\t\tbreak;\n\t\t\tcase 'MoveCall':\n\t\t\t\tif (command.MoveCall.package !== options.packageId) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\tif (command.MoveCall.module !== 'zk_bag') {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tconst fn = command.MoveCall.function;\n\t\t\t\tif (fn !== 'init_claim' && fn !== 'reclaim' && fn !== 'claim' && fn !== 'finalize') {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\treturn false;\n\t\t}\n\t}\n\n\treturn transfers === 1;\n}\n\nexport function getAssetsFromTransaction({\n\ttransaction,\n\taddress,\n\tisSent,\n}: {\n\ttransaction: HaneulTransactionBlockResponse;\n\taddress: string;\n\tisSent: boolean;\n}): LinkAssets {\n\tconst normalizedAddress = normalizeHaneulAddress(address);\n\tconst balances: {\n\t\tcoinType: string;\n\t\tamount: bigint;\n\t}[] = [];\n\n\tconst nfts: {\n\t\tobjectId: string;\n\t\ttype: string;\n\t\tversion: string;\n\t\tdigest: string;\n\t}[] = [];\n\n\tconst coins: {\n\t\tobjectId: string;\n\t\ttype: string;\n\t\tversion: string;\n\t\tdigest: string;\n\t}[] = [];\n\n\ttransaction.balanceChanges?.forEach((change) => {\n\t\tconst validAmountChange = isSent ? BigInt(change.amount) < 0n : BigInt(change.amount) > 0n;\n\t\tif (validAmountChange && isOwner(change.owner, normalizedAddress)) {\n\t\t\tbalances.push({\n\t\t\t\tcoinType: normalizeStructTag(change.coinType),\n\t\t\t\tamount: BigInt(change.amount),\n\t\t\t});\n\t\t}\n\t});\n\n\ttransaction.objectChanges?.forEach((change) => {\n\t\tif (!isObjectOwner(change, normalizedAddress, isSent)) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ('objectType' in change) {\n\t\t\tconst type = parseStructTag(change.objectType);\n\n\t\t\tif (\n\t\t\t\ttype.address === normalizeHaneulAddress('0x2') &&\n\t\t\t\ttype.module === 'coin' &&\n\t\t\t\ttype.name === 'Coin'\n\t\t\t) {\n\t\t\t\tif (\n\t\t\t\t\tchange.type === 'created' ||\n\t\t\t\t\tchange.type === 'transferred' ||\n\t\t\t\t\tchange.type === 'mutated'\n\t\t\t\t) {\n\t\t\t\t\tcoins.push({\n\t\t\t\t\t\t...change,\n\t\t\t\t\t\ttype: change.objectType,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tif (\n\t\t\tisObjectOwner(change, normalizedAddress, isSent) &&\n\t\t\t(change.type === 'created' || change.type === 'transferred' || change.type === 'mutated')\n\t\t) {\n\t\t\tnfts.push({\n\t\t\t\tobjectId: change.objectId,\n\t\t\t\ttype: change.objectType,\n\t\t\t\tversion: change.version,\n\t\t\t\tdigest: change.digest,\n\t\t\t});\n\t\t}\n\t});\n\n\treturn {\n\t\tbalances,\n\t\tnfts,\n\t\tcoins,\n\t};\n}\n\nfunction getObjectOwnerFromObjectChange(objectChange: HaneulObjectChange, isSent: boolean) {\n\tif (isSent) {\n\t\treturn 'owner' in objectChange ? objectChange.owner : null;\n\t}\n\n\treturn 'recipient' in objectChange ? objectChange.recipient : null;\n}\n\nfunction isObjectOwner(objectChange: HaneulObjectChange, address: string, isSent: boolean) {\n\tconst owner = getObjectOwnerFromObjectChange(objectChange, isSent);\n\n\tif (isSent) {\n\t\treturn owner && typeof owner === 'object' && 'AddressOwner' in owner;\n\t}\n\n\treturn ownedAfterChange(objectChange, address);\n}\n\nexport function ownedAfterChange(\n\tobjectChange: HaneulObjectChange,\n\taddress: string,\n): objectChange is Extract<HaneulObjectChange, { type: 'created' | 'transferred' | 'mutated' }> {\n\tif (objectChange.type === 'transferred' && isOwner(objectChange.recipient, address)) {\n\t\treturn true;\n\t}\n\n\tif (\n\t\t(objectChange.type === 'created' || objectChange.type === 'mutated') &&\n\t\tisOwner(objectChange.owner, address)\n\t) {\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n\nexport function isOwner(owner: ObjectOwner, address: string): owner is { AddressOwner: string } {\n\treturn (\n\t\towner &&\n\t\ttypeof owner === 'object' &&\n\t\t'AddressOwner' in owner &&\n\t\tnormalizeHaneulAddress(owner.AddressOwner) === address\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,mBAA2E;AAuBpE,SAAS,mBACf,IACA,SAGC;AACD,MAAI,YAAY;AAEhB,aAAW,WAAW,GAAG,QAAQ,EAAE,UAAU;AAC5C,YAAQ,QAAQ,OAAO;AAAA,MACtB,KAAK;AAEJ,YACC,CAAC,QAAQ,gBAAgB,QAAQ;AAAA,UAChC,CAAC,MAAM,EAAE,UAAU,YAAY,EAAE,UAAU;AAAA,QAC5C,GACC;AACD,iBAAO;AAAA,Q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AAA,QACF;AACA;AAAA,MACD;AAAA,IACD;AAEA,QACC,cAAc,QAAQ,mBAAmB,MAAM,MAC9C,OAAO,SAAS,aAAa,OAAO,SAAS,iBAAiB,OAAO,SAAS,YAC9E;AACD,WAAK,KAAK;AAAA,QACT,UAAU,OAAO;AAAA,QACjB,MAAM,OAAO;AAAA,QACb,SAAS,OAAO;AAAA,QAChB,QAAQ,OAAO;AAAA,MAChB,CAAC;AAAA,IACF;AAAA,EACD,CAAC;AAED,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AAEA,SAAS,+BAA+B,cAAkC,QAAiB;AAC1F,MAAI,QAAQ;AACX,WAAO,WAAW,eAAe,aAAa,QAAQ;AAAA,EACvD;AAEA,SAAO,eAAe,eAAe,aAAa,YAAY;AAC/D;AAEA,SAAS,cAAc,cAAkC,SAAiB,QAAiB;AAC1F,QAAM,QAAQ,+BAA+B,cAAc,MAAM;AAEjE,MAAI,QAAQ;AACX,WAAO,SAAS,OAAO,UAAU,YAAY,kBAAkB;AAAA,EAChE;AAEA,SAAO,iBAAiB,cAAc,OAAO;AAC9C;AAEO,SAAS,iBACf,cACA,SAC+F;AAC/F,MAAI,aAAa,SAAS,iBAAiB,QAAQ,aAAa,WAAW,OAAO,GAAG;AACpF,WAAO;AAAA,EACR;AAEA,OACE,aAAa,SAAS,aAAa,aAAa,SAAS,cAC1D,QAAQ,aAAa,OAAO,OAAO,GAClC;AACD,WAAO;AAAA,EACR;AAEA,SAAO;AACR;AAEO,SAAS,QAAQ,OAAoB,SAAoD;AAC/F,SACC,SACA,OAAO,UAAU,YACjB,kBAAkB,aAClB,qCAAuB,MAAM,YAAY,MAAM;AAEjD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { Argument, Transaction, TransactionObjectArgument } from '@haneullabs/haneul/transactions';
|
|
2
|
+
export interface ZkBagContractOptions {
|
|
3
|
+
packageId: string;
|
|
4
|
+
bagStoreId: string;
|
|
5
|
+
bagStoreTableId: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const TESTNET_CONTRACT_IDS: ZkBagContractOptions;
|
|
8
|
+
export declare const MAINNET_CONTRACT_IDS: ZkBagContractOptions;
|
|
9
|
+
export declare function getContractIds(network?: 'mainnet' | 'testnet'): ZkBagContractOptions;
|
|
10
|
+
export declare class ZkBag<IDs> {
|
|
11
|
+
#private;
|
|
12
|
+
ids: IDs;
|
|
13
|
+
constructor(packageAddress: string, ids: IDs);
|
|
14
|
+
new({ arguments: [store, receiver], }: {
|
|
15
|
+
arguments: [store: TransactionObjectArgument | string, receiver: Argument | string];
|
|
16
|
+
}): (tx: Transaction) => void;
|
|
17
|
+
add({ arguments: [store, receiver, item], typeArguments, }: {
|
|
18
|
+
arguments: [
|
|
19
|
+
store: TransactionObjectArgument | string,
|
|
20
|
+
receiver: Argument | string,
|
|
21
|
+
item: TransactionObjectArgument | string
|
|
22
|
+
];
|
|
23
|
+
typeArguments: [string];
|
|
24
|
+
}): (tx: Transaction) => Extract<Argument, {
|
|
25
|
+
$kind: 'Result';
|
|
26
|
+
}>;
|
|
27
|
+
init_claim({ arguments: [store] }: {
|
|
28
|
+
arguments: [store: TransactionObjectArgument | string];
|
|
29
|
+
}): (tx: Transaction) => readonly [{
|
|
30
|
+
$kind: "NestedResult";
|
|
31
|
+
NestedResult: [number, number];
|
|
32
|
+
}, {
|
|
33
|
+
$kind: "NestedResult";
|
|
34
|
+
NestedResult: [number, number];
|
|
35
|
+
}];
|
|
36
|
+
reclaim({ arguments: [store, receiver], }: {
|
|
37
|
+
arguments: [store: TransactionObjectArgument | string, receiver: Argument | string];
|
|
38
|
+
}): (tx: Transaction) => readonly [{
|
|
39
|
+
$kind: "NestedResult";
|
|
40
|
+
NestedResult: [number, number];
|
|
41
|
+
}, {
|
|
42
|
+
$kind: "NestedResult";
|
|
43
|
+
NestedResult: [number, number];
|
|
44
|
+
}];
|
|
45
|
+
claim({ arguments: [bag, claim, id], typeArguments, }: {
|
|
46
|
+
arguments: [
|
|
47
|
+
bag: TransactionObjectArgument | string,
|
|
48
|
+
claim: Extract<Argument, {
|
|
49
|
+
$kind: 'NestedResult';
|
|
50
|
+
}>,
|
|
51
|
+
id: TransactionObjectArgument | string
|
|
52
|
+
];
|
|
53
|
+
typeArguments: [string];
|
|
54
|
+
}): (tx: Transaction) => Extract<Argument, {
|
|
55
|
+
$kind: 'Result';
|
|
56
|
+
}>;
|
|
57
|
+
finalize({ arguments: [bag, claim], }: {
|
|
58
|
+
arguments: [
|
|
59
|
+
bag: TransactionObjectArgument | string,
|
|
60
|
+
claim: Extract<Argument, {
|
|
61
|
+
$kind: 'NestedResult';
|
|
62
|
+
}>
|
|
63
|
+
];
|
|
64
|
+
}): (tx: Transaction) => void;
|
|
65
|
+
update_receiver({ arguments: [bag, from, to], }: {
|
|
66
|
+
arguments: [
|
|
67
|
+
bag: TransactionObjectArgument | string,
|
|
68
|
+
from: Argument | string,
|
|
69
|
+
to: Argument | string
|
|
70
|
+
];
|
|
71
|
+
}): (tx: Transaction) => void;
|
|
72
|
+
}
|