@ckb-ccc/udt 0.1.24 → 0.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckb-ccc/udt",
3
- "version": "0.1.24",
3
+ "version": "0.2.0",
4
4
  "description": "UDT",
5
5
  "author": "Alive24 <xct24@live.com>",
6
6
  "license": "MIT",
@@ -11,40 +11,41 @@
11
11
  "url": "git://github.com/ckb-devrel/ccc.git"
12
12
  },
13
13
  "main": "./dist.commonjs/index.js",
14
- "module": "./dist/index.js",
14
+ "module": "./dist/index.mjs",
15
15
  "exports": {
16
16
  ".": {
17
- "import": "./dist/index.js",
18
- "default": "./dist.commonjs/index.js"
17
+ "import": "./dist/index.mjs",
18
+ "require": "./dist.commonjs/index.js"
19
19
  },
20
- "./advanced": {
21
- "import": "./dist/advanced.js",
22
- "default": "./dist.commonjs/advanced.js"
23
- }
20
+ "./barrel": {
21
+ "import": "./dist/barrel.mjs",
22
+ "require": "./dist.commonjs/barrel.js"
23
+ },
24
+ "./package.json": "./package.json"
24
25
  },
25
26
  "devDependencies": {
26
- "@eslint/js": "^9.34.0",
27
- "@types/node": "^24.3.0",
28
- "copyfiles": "^2.4.1",
29
- "eslint": "^9.34.0",
27
+ "@eslint/js": "^10.0.1",
28
+ "@types/node": "^26.0.0",
29
+ "eslint": "^10.5.0",
30
30
  "eslint-config-prettier": "^10.1.8",
31
- "eslint-plugin-prettier": "^5.5.4",
32
- "prettier": "^3.6.2",
33
- "prettier-plugin-organize-imports": "^4.2.0",
34
- "rimraf": "^6.0.1",
35
- "typescript": "^5.9.2",
36
- "typescript-eslint": "^8.41.0"
31
+ "eslint-plugin-prettier": "^5.5.6",
32
+ "prettier": "^3.8.4",
33
+ "prettier-plugin-organize-imports": "^4.3.0",
34
+ "typescript": "^6.0.3",
35
+ "typescript-eslint": "^8.61.1"
37
36
  },
38
37
  "publishConfig": {
39
38
  "access": "public"
40
39
  },
41
40
  "dependencies": {
42
- "@ckb-ccc/core": "1.12.5",
43
- "@ckb-ccc/ssri": "0.2.22"
41
+ "tsdown": "^0.22.3",
42
+ "@ckb-ccc/ssri": "0.3.0",
43
+ "@ckb-ccc/core": "1.14.0"
44
44
  },
45
+ "types": "./dist.commonjs/index.d.ts",
45
46
  "scripts": {
46
47
  "test": "jest",
47
- "build": "rimraf ./dist && rimraf ./dist.commonjs && tsc && tsc --project tsconfig.commonjs.json && copyfiles -u 2 misc/basedirs/**/* .",
48
+ "build": "tsdown",
48
49
  "lint": "eslint ./src",
49
50
  "format": "prettier --write . && eslint --fix ./src"
50
51
  }
package/src/udt/index.ts CHANGED
@@ -17,14 +17,15 @@ export class Udt extends ssri.Trait {
17
17
 
18
18
  /**
19
19
  * Constructs a new UDT (User Defined Token) script instance.
20
- * By default it is a SSRI-compliant UDT. By providing `xudtType`, it is compatible with the legacy xUDT.
20
+ * By default it is a SSRI-compliant UDT.
21
21
  *
22
- * @param executor - The SSRI executor instance.
23
22
  * @param code - The script code cell of the UDT.
24
23
  * @param script - The type script of the UDT.
24
+ * @param config - Optional configuration for the UDT instance.
25
+ * @param config.executor - The SSRI executor instance. If provided, enables SSRI-based operations.
25
26
  * @example
26
27
  * ```typescript
27
- * const udt = new Udt(executor, code, script);
28
+ * const udt = new Udt(code, script, { executor });
28
29
  * ```
29
30
  */
30
31
  constructor(
@@ -41,6 +42,7 @@ export class Udt extends ssri.Trait {
41
42
  /**
42
43
  * Retrieves the human-readable name of the User Defined Token.
43
44
  *
45
+ * @param context - Optional SSRI context for script execution.
44
46
  * @returns A promise resolving to the token's name.
45
47
  */
46
48
  async name(
@@ -61,6 +63,7 @@ export class Udt extends ssri.Trait {
61
63
 
62
64
  /**
63
65
  * Retrieves the symbol of the UDT.
66
+ * @param context - Optional SSRI context for script execution.
64
67
  * @returns The symbol of the UDT.
65
68
  */
66
69
  async symbol(
@@ -86,6 +89,7 @@ export class Udt extends ssri.Trait {
86
89
 
87
90
  /**
88
91
  * Retrieves the decimals of the UDT.
92
+ * @param context - Optional SSRI context for script execution.
89
93
  * @returns The decimals of the UDT.
90
94
  */
91
95
  async decimals(
@@ -110,7 +114,8 @@ export class Udt extends ssri.Trait {
110
114
  }
111
115
 
112
116
  /**
113
- * Retrieves the icon of the UDT
117
+ * Retrieves the icon of the UDT.
118
+ * @param context - Optional SSRI context for script execution.
114
119
  * @returns The icon of the UDT.
115
120
  */
116
121
  async icon(
@@ -131,10 +136,11 @@ export class Udt extends ssri.Trait {
131
136
 
132
137
  /**
133
138
  * Transfers UDT to specified addresses.
134
- * @param tx - Transfer on the basis of an existing transaction to achieve combined actions. If not provided, a new transaction will be created.
139
+ * @param signer - The signer to use for the transaction.
135
140
  * @param transfers - The array of transfers.
136
141
  * @param transfers.to - The receiver of token.
137
142
  * @param transfers.amount - The amount of token to the receiver.
143
+ * @param tx - Transfer on the basis of an existing transaction to achieve combined actions. If not provided, a new transaction will be created.
138
144
  * @returns The transaction result.
139
145
  * @tag Mutation - This method represents a mutation of the onchain state and will return a transaction object.
140
146
  * @example
@@ -217,10 +223,11 @@ export class Udt extends ssri.Trait {
217
223
 
218
224
  /**
219
225
  * Mints new tokens to specified addresses. See the example in `transfer` as they are similar.
220
- * @param tx - Optional existing transaction to build upon
226
+ * @param signer - The signer to use for the transaction.
221
227
  * @param mints - Array of mints
222
228
  * @param mints.to - receiver of token
223
229
  * @param mints.amount - amount to the receiver
230
+ * @param tx - Optional existing transaction to build upon
224
231
  * @returns The transaction containing the mint operation
225
232
  * @tag Mutation - This method represents a mutation of the onchain state
226
233
  */
@@ -274,6 +281,13 @@ export class Udt extends ssri.Trait {
274
281
  return resTx;
275
282
  }
276
283
 
284
+ /**
285
+ * Completes a UDT transaction by adding change output to a specific lock script.
286
+ * @param txLike - The transaction to complete.
287
+ * @param signer - The signer to use for input selection.
288
+ * @param change - The lock script for the change output.
289
+ * @returns The completed transaction.
290
+ */
277
291
  async completeChangeToLock(
278
292
  txLike: ccc.TransactionLike,
279
293
  signer: ccc.Signer,
@@ -298,6 +312,12 @@ export class Udt extends ssri.Trait {
298
312
  return tx;
299
313
  }
300
314
 
315
+ /**
316
+ * Completes a UDT transaction by adding change output to the signer's address.
317
+ * @param tx - The transaction to complete.
318
+ * @param from - The signer to use for input selection and change address.
319
+ * @returns The completed transaction.
320
+ */
301
321
  async completeBy(tx: ccc.TransactionLike, from: ccc.Signer) {
302
322
  const { script } = await from.getRecommendedAddressObj();
303
323
 
@@ -19,9 +19,11 @@ export class UdtPausable extends Udt {
19
19
  }
20
20
 
21
21
  /**
22
- * Pauses the UDT for the specified lock hashes. Pausing/Unpause without lock hashes should take effect on the global level. Note that this method is only available if the pausable UDT uses external pause list.
23
- * @param {ccc.HexLike[]} lockHashes - The array of lock hashes to be paused.
24
- * @param {ccc.TransactionLike} tx - The transaction to be used.
22
+ * Pauses the UDT for the specified lock scripts. Pausing/Unpause without lock scripts should take effect on the global level. Note that this method is only available if the pausable UDT uses external pause list.
23
+ * @param signer - The signer to use for the transaction.
24
+ * @param locks - The array of lock scripts to be paused.
25
+ * @param tx - The transaction to be used.
26
+ * @param extraLockHashes - Additional lock hashes to be paused.
25
27
  * @returns The transaction result.
26
28
  * @tag Mutation - This method represents a mutation of the onchain state and will return a transaction to be sent.
27
29
  */
@@ -56,9 +58,11 @@ export class UdtPausable extends Udt {
56
58
  }
57
59
 
58
60
  /**
59
- * Unpauses the UDT for the specified lock hashes. Note that this method is only available if the pausable UDT uses external pause list.
61
+ * Unpauses the UDT for the specified lock scripts. Note that this method is only available if the pausable UDT uses external pause list.
62
+ * @param signer - The signer to use for the transaction.
63
+ * @param locks - The array of lock scripts to be unpaused.
60
64
  * @param tx - The transaction to be used.
61
- * @param lockHashes - The array of lock hashes to be unpaused.
65
+ * @param extraLockHashes - Additional lock hashes to be unpaused.
62
66
  * @returns The transaction result.
63
67
  * @tag Mutation - This method represents a mutation of the onchain state and will return a transaction to be sent.
64
68
  */
@@ -93,9 +97,10 @@ export class UdtPausable extends Udt {
93
97
  }
94
98
 
95
99
  /**
96
- * Checks if the UDT is paused for the specified lock hashes within a transaction. If not using external pause list, it can also be run on Code environment level.
97
- * @param lockHashes - The lock hashes to check.
98
- * @returns True if any of the lock hashes are paused, false otherwise.
100
+ * Checks if the UDT is paused for the specified lock scripts within a transaction. If not using external pause list, it can also be run on Code environment level.
101
+ * @param locks - The lock scripts to check.
102
+ * @param extraLockHashes - Additional lock hashes to check.
103
+ * @returns True if any of the lock scripts are paused, false otherwise.
99
104
  */
100
105
  async isPaused(
101
106
  locks: ccc.ScriptLike[],
@@ -0,0 +1,41 @@
1
+ import { defineConfig } from "tsdown";
2
+
3
+ const common = {
4
+ minify: true,
5
+ dts: true,
6
+ platform: "neutral" as const,
7
+ sourcemap: true,
8
+ exports: true,
9
+ };
10
+
11
+ const entry = {
12
+ index: "src/index.ts",
13
+ barrel: "src/barrel.ts",
14
+ } as const;
15
+
16
+ const bundleDeps: string[] = [];
17
+
18
+ export default defineConfig(
19
+ (
20
+ [
21
+ {
22
+ entry,
23
+ deps: {
24
+ onlyBundle: [] as string[],
25
+ },
26
+ format: "esm",
27
+ copy: "./misc/basedirs/dist/*",
28
+ },
29
+ {
30
+ entry,
31
+ deps: {
32
+ alwaysBundle: bundleDeps,
33
+ onlyBundle: bundleDeps,
34
+ },
35
+ format: "cjs",
36
+ outDir: "dist.commonjs",
37
+ copy: "./misc/basedirs/dist.commonjs/*",
38
+ },
39
+ ] as const
40
+ ).map((c) => ({ ...c, ...common })),
41
+ );
package/dist/barrel.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from "./udt/index.js";
2
- export * from "./udtPausable/index.js";
3
- //# sourceMappingURL=barrel.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"barrel.d.ts","sourceRoot":"","sources":["../src/barrel.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC"}
package/dist/barrel.js DELETED
@@ -1,2 +0,0 @@
1
- export * from "./udt/index.js";
2
- export * from "./udtPausable/index.js";
package/dist/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from "./barrel.js";
2
- export * as udt from "./barrel.js";
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC"}
package/dist/index.js DELETED
@@ -1,2 +0,0 @@
1
- export * from "./barrel.js";
2
- export * as udt from "./barrel.js";
@@ -1,108 +0,0 @@
1
- import { ccc } from "@ckb-ccc/core";
2
- import { ssri } from "@ckb-ccc/ssri";
3
- /**
4
- * Represents a User Defined Token (UDT) script compliant with the SSRI protocol.
5
- *
6
- * This class provides a comprehensive implementation for interacting with User Defined Tokens,
7
- * supporting various token operations such as querying metadata, checking balances, and performing transfers.
8
- * It supports both SSRI-compliant UDTs and legacy sUDT/xUDT standard tokens.
9
- *
10
- * @public
11
- * @category Blockchain
12
- * @category Token
13
- */
14
- export declare class Udt extends ssri.Trait {
15
- readonly script: ccc.Script;
16
- /**
17
- * Constructs a new UDT (User Defined Token) script instance.
18
- * By default it is a SSRI-compliant UDT. By providing `xudtType`, it is compatible with the legacy xUDT.
19
- *
20
- * @param executor - The SSRI executor instance.
21
- * @param code - The script code cell of the UDT.
22
- * @param script - The type script of the UDT.
23
- * @example
24
- * ```typescript
25
- * const udt = new Udt(executor, code, script);
26
- * ```
27
- */
28
- constructor(code: ccc.OutPointLike, script: ccc.ScriptLike, config?: {
29
- executor?: ssri.Executor | null;
30
- } | null);
31
- /**
32
- * Retrieves the human-readable name of the User Defined Token.
33
- *
34
- * @returns A promise resolving to the token's name.
35
- */
36
- name(context?: ssri.ContextScript): Promise<ssri.ExecutorResponse<string | undefined>>;
37
- /**
38
- * Retrieves the symbol of the UDT.
39
- * @returns The symbol of the UDT.
40
- */
41
- symbol(context?: ssri.ContextScript): Promise<ssri.ExecutorResponse<string | undefined>>;
42
- /**
43
- * Retrieves the decimals of the UDT.
44
- * @returns The decimals of the UDT.
45
- */
46
- decimals(context?: ssri.ContextScript): Promise<ssri.ExecutorResponse<ccc.Num | undefined>>;
47
- /**
48
- * Retrieves the icon of the UDT
49
- * @returns The icon of the UDT.
50
- */
51
- icon(context?: ssri.ContextScript): Promise<ssri.ExecutorResponse<string | undefined>>;
52
- /**
53
- * Transfers UDT to specified addresses.
54
- * @param tx - Transfer on the basis of an existing transaction to achieve combined actions. If not provided, a new transaction will be created.
55
- * @param transfers - The array of transfers.
56
- * @param transfers.to - The receiver of token.
57
- * @param transfers.amount - The amount of token to the receiver.
58
- * @returns The transaction result.
59
- * @tag Mutation - This method represents a mutation of the onchain state and will return a transaction object.
60
- * @example
61
- * ```typescript
62
- * const { script: change } = await signer.getRecommendedAddressObj();
63
- * const { script: to } = await ccc.Address.fromString(receiver, signer.client);
64
- *
65
- * const udt = new Udt(
66
- * {
67
- * txHash: "0x4e2e832e0b1e7b5994681b621b00c1e65f577ee4b440ef95fa07db9bb3d50269",
68
- * index: 0,
69
- * },
70
- * {
71
- * codeHash: "0xcc9dc33ef234e14bc788c43a4848556a5fb16401a04662fc55db9bb201987037",
72
- * hashType: "type",
73
- * args: "0x71fd1985b2971a9903e4d8ed0d59e6710166985217ca0681437883837b86162f"
74
- * },
75
- * );
76
- *
77
- * const { res: tx } = await udtTrait.transfer(
78
- * signer,
79
- * [{ to, amount: 100 }],
80
- * );
81
- *
82
- * const completedTx = udt.completeUdtBy(tx, signer);
83
- * await completedTx.completeInputsByCapacity(signer);
84
- * await completedTx.completeFeeBy(signer);
85
- * const transferTxHash = await signer.sendTransaction(completedTx);
86
- * ```
87
- */
88
- transfer(signer: ccc.Signer, transfers: {
89
- to: ccc.ScriptLike;
90
- amount: ccc.NumLike;
91
- }[], tx?: ccc.TransactionLike | null): Promise<ssri.ExecutorResponse<ccc.Transaction>>;
92
- /**
93
- * Mints new tokens to specified addresses. See the example in `transfer` as they are similar.
94
- * @param tx - Optional existing transaction to build upon
95
- * @param mints - Array of mints
96
- * @param mints.to - receiver of token
97
- * @param mints.amount - amount to the receiver
98
- * @returns The transaction containing the mint operation
99
- * @tag Mutation - This method represents a mutation of the onchain state
100
- */
101
- mint(signer: ccc.Signer, mints: {
102
- to: ccc.ScriptLike;
103
- amount: ccc.NumLike;
104
- }[], tx?: ccc.TransactionLike | null): Promise<ssri.ExecutorResponse<ccc.Transaction>>;
105
- completeChangeToLock(txLike: ccc.TransactionLike, signer: ccc.Signer, change: ccc.ScriptLike): Promise<ccc.Transaction>;
106
- completeBy(tx: ccc.TransactionLike, from: ccc.Signer): Promise<ccc.Transaction>;
107
- }
108
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/udt/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAErC;;;;;;;;;;GAUG;AACH,qBAAa,GAAI,SAAQ,IAAI,CAAC,KAAK;IACjC,SAAgB,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC;IAEnC;;;;;;;;;;;OAWG;gBAED,IAAI,EAAE,GAAG,CAAC,YAAY,EACtB,MAAM,EAAE,GAAG,CAAC,UAAU,EACtB,MAAM,CAAC,EAAE;QACP,QAAQ,CAAC,EAAE,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;KACjC,GAAG,IAAI;IAMV;;;;OAIG;IACG,IAAI,CACR,OAAO,CAAC,EAAE,IAAI,CAAC,aAAa,GAC3B,OAAO,CAAC,IAAI,CAAC,gBAAgB,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAcrD;;;OAGG;IACG,MAAM,CACV,OAAO,CAAC,EAAE,IAAI,CAAC,aAAa,GAC3B,OAAO,CAAC,IAAI,CAAC,gBA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index.js DELETED
@@ -1,222 +0,0 @@
1
- import { ccc } from "@ckb-ccc/core";
2
- import { ssri } from "@ckb-ccc/ssri";
3
- /**
4
- * Represents a User Defined Token (UDT) script compliant with the SSRI protocol.
5
- *
6
- * This class provides a comprehensive implementation for interacting with User Defined Tokens,
7
- * supporting various token operations such as querying metadata, checking balances, and performing transfers.
8
- * It supports both SSRI-compliant UDTs and legacy sUDT/xUDT standard tokens.
9
- *
10
- * @public
11
- * @category Blockchain
12
- * @category Token
13
- */
14
- export class Udt extends ssri.Trait {
15
- /**
16
- * Constructs a new UDT (User Defined Token) script instance.
17
- * By default it is a SSRI-compliant UDT. By providing `xudtType`, it is compatible with the legacy xUDT.
18
- *
19
- * @param executor - The SSRI executor instance.
20
- * @param code - The script code cell of the UDT.
21
- * @param script - The type script of the UDT.
22
- * @example
23
- * ```typescript
24
- * const udt = new Udt(executor, code, script);
25
- * ```
26
- */
27
- constructor(code, script, config) {
28
- super(code, config?.executor);
29
- this.script = ccc.Script.from(script);
30
- }
31
- /**
32
- * Retrieves the human-readable name of the User Defined Token.
33
- *
34
- * @returns A promise resolving to the token's name.
35
- */
36
- async name(context) {
37
- if (this.executor) {
38
- const res = await this.executor.runScriptTry(this.code, "UDT.name", [], {
39
- script: this.script,
40
- ...context,
41
- });
42
- if (res) {
43
- return res.map((res) => ccc.bytesTo(res, "utf8"));
44
- }
45
- }
46
- return ssri.ExecutorResponse.new(undefined);
47
- }
48
- /**
49
- * Retrieves the symbol of the UDT.
50
- * @returns The symbol of the UDT.
51
- */
52
- async symbol(context) {
53
- if (this.executor) {
54
- const res = await this.executor.runScriptTry(this.code, "UDT.symbol", [], {
55
- script: this.script,
56
- ...context,
57
- });
58
- if (res) {
59
- return res.map((res) => ccc.bytesTo(res, "utf8"));
60
- }
61
- }
62
- return ssri.ExecutorResponse.new(undefined);
63
- }
64
- /**
65
- * Retrieves the decimals of the UDT.
66
- * @returns The decimals of the UDT.
67
- */
68
- async decimals(context) {
69
- if (this.executor) {
70
- const res = await this.executor.runScriptTry(this.code, "UDT.decimals", [], {
71
- script: this.script,
72
- ...context,
73
- });
74
- if (res) {
75
- return res.map((res) => ccc.numFromBytes(res));
76
- }
77
- }
78
- return ssri.ExecutorResponse.new(undefined);
79
- }
80
- /**
81
- * Retrieves the icon of the UDT
82
- * @returns The icon of the UDT.
83
- */
84
- async icon(context) {
85
- if (this.executor) {
86
- const res = await this.executor.runScriptTry(this.code, "UDT.icon", [], {
87
- script: this.script,
88
- ...context,
89
- });
90
- if (res) {
91
- return res.map((res) => ccc.bytesTo(res, "utf8"));
92
- }
93
- }
94
- return ssri.ExecutorResponse.new(undefined);
95
- }
96
- /**
97
- * Transfers UDT to specified addresses.
98
- * @param tx - Transfer on the basis of an existing transaction to achieve combined actions. If not provided, a new transaction will be created.
99
- * @param transfers - The array of transfers.
100
- * @param transfers.to - The receiver of token.
101
- * @param transfers.amount - The amount of token to the receiver.
102
- * @returns The transaction result.
103
- * @tag Mutation - This method represents a mutation of the onchain state and will return a transaction object.
104
- * @example
105
- * ```typescript
106
- * const { script: change } = await signer.getRecommendedAddressObj();
107
- * const { script: to } = await ccc.Address.fromString(receiver, signer.client);
108
- *
109
- * const udt = new Udt(
110
- * {
111
- * txHash: "0x4e2e832e0b1e7b5994681b621b00c1e65f577ee4b440ef95fa07db9bb3d50269",
112
- * index: 0,
113
- * },
114
- * {
115
- * codeHash: "0xcc9dc33ef234e14bc788c43a4848556a5fb16401a04662fc55db9bb201987037",
116
- * hashType: "type",
117
- * args: "0x71fd1985b2971a9903e4d8ed0d59e6710166985217ca0681437883837b86162f"
118
- * },
119
- * );
120
- *
121
- * const { res: tx } = await udtTrait.transfer(
122
- * signer,
123
- * [{ to, amount: 100 }],
124
- * );
125
- *
126
- * const completedTx = udt.completeUdtBy(tx, signer);
127
- * await completedTx.completeInputsByCapacity(signer);
128
- * await completedTx.completeFeeBy(signer);
129
- * const transferTxHash = await signer.sendTransaction(completedTx);
130
- * ```
131
- */
132
- async transfer(signer, transfers, tx) {
133
- let resTx;
134
- if (this.executor) {
135
- const txReq = ccc.Transaction.from(tx ?? {});
136
- await txReq.completeInputsAtLeastOne(signer);
137
- const res = await this.executor.runScriptTry(this.code, "UDT.transfer", [
138
- txReq.toBytes(),
139
- ccc.ScriptVec.encode(transfers.map(({ to }) => to)),
140
- ccc.mol.Uint128Vec.encode(transfers.map(({ amount }) => amount)),
141
- ], {
142
- script: this.script,
143
- });
144
- if (res) {
145
- resTx = res.map((res) => ccc.Transaction.fromBytes(res));
146
- }
147
- }
148
- if (!resTx) {
149
- const transfer = ccc.Transaction.from(tx ?? {});
150
- for (const { to, amount } of transfers) {
151
- transfer.addOutput({
152
- lock: to,
153
- type: this.script,
154
- }, ccc.numLeToBytes(amount, 16));
155
- }
156
- resTx = ssri.ExecutorResponse.new(transfer);
157
- }
158
- resTx.res.addCellDeps({
159
- outPoint: this.code,
160
- depType: "code",
161
- });
162
- return resTx;
163
- }
164
- /**
165
- * Mints new tokens to specified addresses. See the example in `transfer` as they are similar.
166
- * @param tx - Optional existing transaction to build upon
167
- * @param mints - Array of mints
168
- * @param mints.to - receiver of token
169
- * @param mints.amount - amount to the receiver
170
- * @returns The transaction containing the mint operation
171
- * @tag Mutation - This method represents a mutation of the onchain state
172
- */
173
- async mint(signer, mints, tx) {
174
- let resTx;
175
- if (this.executor) {
176
- const txReq = ccc.Transaction.from(tx ?? {});
177
- await txReq.completeInputsAtLeastOne(signer);
178
- const res = await this.executor.runScriptTry(this.code, "UDT.mint", [
179
- txReq.toBytes(),
180
- ccc.ScriptVec.encode(mints.map(({ to }) => to)),
181
- ccc.mol.Uint128Vec.encode(mints.map(({ amount }) => amount)),
182
- ], {
183
- script: this.script,
184
- });
185
- if (res) {
186
- resTx = res.map((res) => ccc.Transaction.fromBytes(res));
187
- }
188
- }
189
- if (!resTx) {
190
- const mint = ccc.Transaction.from(tx ?? {});
191
- for (const { to, amount } of mints) {
192
- mint.addOutput({
193
- lock: to,
194
- type: this.script,
195
- }, ccc.numLeToBytes(amount, 16));
196
- }
197
- resTx = ssri.ExecutorResponse.new(mint);
198
- }
199
- resTx.res.addCellDeps({
200
- outPoint: this.code,
201
- depType: "code",
202
- });
203
- return resTx;
204
- }
205
- async completeChangeToLock(txLike, signer, change) {
206
- const tx = ccc.Transaction.from(txLike);
207
- await tx.completeInputsByUdt(signer, this.script);
208
- const balanceDiff = (await tx.getInputsUdtBalance(signer.client, this.script)) -
209
- tx.getOutputsUdtBalance(this.script);
210
- if (balanceDiff > ccc.Zero) {
211
- tx.addOutput({
212
- lock: change,
213
- type: this.script,
214
- }, ccc.numLeToBytes(balanceDiff, 16));
215
- }
216
- return tx;
217
- }
218
- async completeBy(tx, from) {
219
- const { script } = await from.getRecommendedAddressObj();
220
- return this.completeChangeToLock(tx, from, script);
221
- }
222
- }
@@ -1,41 +0,0 @@
1
- import { ccc } from "@ckb-ccc/core";
2
- import { ssri } from "@ckb-ccc/ssri";
3
- import { Udt } from "../udt/index.js";
4
- /**
5
- * Represents a UDT (User Defined Token) with pausable functionality.
6
- * @extends {Udt} This must be a SSRI UDT that does not fallback to xUDT.
7
- * @public
8
- */
9
- export declare class UdtPausable extends Udt {
10
- constructor(code: ccc.OutPointLike, script: ccc.ScriptLike, config: {
11
- executor: ssri.Executor;
12
- });
13
- /**
14
- * Pauses the UDT for the specified lock hashes. Pausing/Unpause without lock hashes should take effect on the global level. Note that this method is only available if the pausable UDT uses external pause list.
15
- * @param {ccc.HexLike[]} lockHashes - The array of lock hashes to be paused.
16
- * @param {ccc.TransactionLike} tx - The transaction to be used.
17
- * @returns The transaction result.
18
- * @tag Mutation - This method represents a mutation of the onchain state and will return a transaction to be sent.
19
- */
20
- pause(signer: ccc.Signer, locks: ccc.ScriptLike[], tx?: ccc.TransactionLike | null, extraLockHashes?: ccc.HexLike[] | null): Promise<ssri.ExecutorResponse<ccc.Transaction>>;
21
- /**
22
- * Unpauses the UDT for the specified lock hashes. Note that this method is only available if the pausable UDT uses external pause list.
23
- * @param tx - The transaction to be used.
24
- * @param lockHashes - The array of lock hashes to be unpaused.
25
- * @returns The transaction result.
26
- * @tag Mutation - This method represents a mutation of the onchain state and will return a transaction to be sent.
27
- */
28
- unpause(signer: ccc.Signer, locks: ccc.ScriptLike[], tx?: ccc.TransactionLike | null, extraLockHashes?: ccc.HexLike[] | null): Promise<ssri.ExecutorResponse<ccc.Transaction>>;
29
- /**
30
- * Checks if the UDT is paused for the specified lock hashes within a transaction. If not using external pause list, it can also be run on Code environment level.
31
- * @param lockHashes - The lock hashes to check.
32
- * @returns True if any of the lock hashes are paused, false otherwise.
33
- */
34
- isPaused(locks: ccc.ScriptLike[], extraLockHashes?: ccc.HexLike[] | null): Promise<ssri.ExecutorResponse<boolean[]>>;
35
- /**
36
- * Enumerates all paused lock hashes in UDTPausableData.
37
- * @returns The array of lock hashes.
38
- */
39
- enumeratePaused(offset?: ccc.Num, limit?: ccc.Num): Promise<ssri.ExecutorResponse<ccc.Hex[]>>;
40
- }
41
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/udtPausable/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAEtC;;;;GAIG;AACH,qBAAa,WAAY,SAAQ,GAAG;gBAEhC,IAAI,EAAE,GAAG,CAAC,YAAY,EACtB,MAAM,EAAE,GAAG,CAAC,UAAU,EACtB,MAAM,EAAE;QACN,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC;KACzB;IAKH;;;;;;OAMG;IACG,KAAK,CACT,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,KAAK,EAAE,GAAG,CAAC,UAAU,EAAE,EACvB,EAAE,CAAC,EAAE,GAAG,CAAC,eAAe,GAAG,IAAI,EAC/B,eAAe,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