@locuschain/lib 0.2.8 → 0.2.10

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.
@@ -11,6 +11,12 @@ export type GetContractArgs = {
11
11
  address: Address;
12
12
  abi: InterfaceAbi;
13
13
  client: Client;
14
+ /**
15
+ * 컨트랙트(=subId)가 속한 VME id. 신규 VME 모델의 debug_viewVme 가 컨트랙트를
16
+ * 찾으려면 반드시 필요하다 (필수). 컨트랙트는 하나의 VME 에 속하므로 핸들의
17
+ * 불변 속성 — read 호출마다 받지 않고 생성 시 1회 지정한다.
18
+ */
19
+ vmeId: string;
14
20
  };
15
21
  export type ContractReadFn = (args?: readonly unknown[], opts?: ReadCallOptions) => Promise<unknown>;
16
22
  export type ContractInstance = {
@@ -19,15 +25,19 @@ export type ContractInstance = {
19
25
  read: Record<string, ContractReadFn>;
20
26
  };
21
27
  /**
22
- * Locus 의 debug_viewContract RPC 위에 viem 스타일 컨트랙트 핸들을 만든다.
28
+ * Locus 의 debug_viewVme RPC 위에 viem 스타일 컨트랙트 핸들을 만든다.
23
29
  * `read.<fn>` 은 ethers(v5) 의 Interface 로 호출을 인코딩하고, 결과 바이트를
24
- * convertHexToData 로 Locus `func` 필드에 담아 보낸 뒤, 응답 hex 를
30
+ * convertHexToData 로 Locus `callData` 필드에 담아 보낸 뒤, 응답 hex 를
25
31
  * Interface.decodeFunctionResult 로 다시 디코딩한다.
26
32
  *
33
+ * 신규 VME 모델: 컨트랙트는 (vmeId, subId) 로 식별된다. `address` 가 subId 이고
34
+ * `vmeId` 는 read 호출 시 ReadCallOptions 로 받는다 (필수). RPC ParamsCallVme 의
35
+ * vmeId/subId 와 1:1 대응.
36
+ *
27
37
  * write 메서드는 이번 단계에서는 의도적으로 빠져 있다. 상태를 바꾸는 호출
28
38
  * 은 생성된 wallet action 을 직접 사용한다:
29
39
  *
30
- * import { callContract } from '@locuschain/lib/autogen';
31
- * await wallet.extend(debugWalletActions).callContract({ ... });
40
+ * import { callVme } from '@locuschain/lib/autogen';
41
+ * await wallet.extend(debugWalletActions).callVme({ ... });
32
42
  */
33
43
  export declare function getContract(args: GetContractArgs): ContractInstance;
@@ -11,6 +11,12 @@ export type GetContractArgs = {
11
11
  address: Address;
12
12
  abi: InterfaceAbi;
13
13
  client: Client;
14
+ /**
15
+ * 컨트랙트(=subId)가 속한 VME id. 신규 VME 모델의 debug_viewVme 가 컨트랙트를
16
+ * 찾으려면 반드시 필요하다 (필수). 컨트랙트는 하나의 VME 에 속하므로 핸들의
17
+ * 불변 속성 — read 호출마다 받지 않고 생성 시 1회 지정한다.
18
+ */
19
+ vmeId: string;
14
20
  };
15
21
  export type ContractReadFn = (args?: readonly unknown[], opts?: ReadCallOptions) => Promise<unknown>;
16
22
  export type ContractInstance = {
@@ -19,15 +25,19 @@ export type ContractInstance = {
19
25
  read: Record<string, ContractReadFn>;
20
26
  };
21
27
  /**
22
- * Locus 의 debug_viewContract RPC 위에 viem 스타일 컨트랙트 핸들을 만든다.
28
+ * Locus 의 debug_viewVme RPC 위에 viem 스타일 컨트랙트 핸들을 만든다.
23
29
  * `read.<fn>` 은 ethers(v5) 의 Interface 로 호출을 인코딩하고, 결과 바이트를
24
- * convertHexToData 로 Locus `func` 필드에 담아 보낸 뒤, 응답 hex 를
30
+ * convertHexToData 로 Locus `callData` 필드에 담아 보낸 뒤, 응답 hex 를
25
31
  * Interface.decodeFunctionResult 로 다시 디코딩한다.
26
32
  *
33
+ * 신규 VME 모델: 컨트랙트는 (vmeId, subId) 로 식별된다. `address` 가 subId 이고
34
+ * `vmeId` 는 read 호출 시 ReadCallOptions 로 받는다 (필수). RPC ParamsCallVme 의
35
+ * vmeId/subId 와 1:1 대응.
36
+ *
27
37
  * write 메서드는 이번 단계에서는 의도적으로 빠져 있다. 상태를 바꾸는 호출
28
38
  * 은 생성된 wallet action 을 직접 사용한다:
29
39
  *
30
- * import { callContract } from '@locuschain/lib/autogen';
31
- * await wallet.extend(debugWalletActions).callContract({ ... });
40
+ * import { callVme } from '@locuschain/lib/autogen';
41
+ * await wallet.extend(debugWalletActions).callVme({ ... });
32
42
  */
33
43
  export declare function getContract(args: GetContractArgs): ContractInstance;
@@ -1,19 +1,26 @@
1
1
  define(['exports', '../chunks/tslib.es6-D29rxPkW', '../chunks/ethers.esm.min-wXex1HuX', '../chunks/wasm-gROtmFm6', '../chunks/lclib-Bv86gksL'], (function (exports, tslib_es6, ethers_esm_min, wasm, lclib) { 'use strict';
2
2
 
3
3
  /**
4
- * Locus 의 debug_viewContract RPC 위에 viem 스타일 컨트랙트 핸들을 만든다.
4
+ * Locus 의 debug_viewVme RPC 위에 viem 스타일 컨트랙트 핸들을 만든다.
5
5
  * `read.<fn>` 은 ethers(v5) 의 Interface 로 호출을 인코딩하고, 결과 바이트를
6
- * convertHexToData 로 Locus `func` 필드에 담아 보낸 뒤, 응답 hex 를
6
+ * convertHexToData 로 Locus `callData` 필드에 담아 보낸 뒤, 응답 hex 를
7
7
  * Interface.decodeFunctionResult 로 다시 디코딩한다.
8
8
  *
9
+ * 신규 VME 모델: 컨트랙트는 (vmeId, subId) 로 식별된다. `address` 가 subId 이고
10
+ * `vmeId` 는 read 호출 시 ReadCallOptions 로 받는다 (필수). RPC ParamsCallVme 의
11
+ * vmeId/subId 와 1:1 대응.
12
+ *
9
13
  * write 메서드는 이번 단계에서는 의도적으로 빠져 있다. 상태를 바꾸는 호출
10
14
  * 은 생성된 wallet action 을 직접 사용한다:
11
15
  *
12
- * import { callContract } from '@locuschain/lib/autogen';
13
- * await wallet.extend(debugWalletActions).callContract({ ... });
16
+ * import { callVme } from '@locuschain/lib/autogen';
17
+ * await wallet.extend(debugWalletActions).callVme({ ... });
14
18
  */
15
19
  function getContract(args) {
16
- const { address, abi, client } = args;
20
+ const { address, abi, client, vmeId } = args;
21
+ if (!vmeId) {
22
+ throw new Error('getContract: vmeId is required');
23
+ }
17
24
  const iface = new ethers_esm_min.ethers.utils.Interface(abi);
18
25
  const read = {};
19
26
  for (const item of normalizeAbi(abi)) {
@@ -29,24 +36,34 @@ define(['exports', '../chunks/tslib.es6-D29rxPkW', '../chunks/ethers.esm.min-wXe
29
36
  function makeRead(name) {
30
37
  return (...args_1) => tslib_es6.__awaiter(this, [...args_1], void 0, function* (callArgs = [], opts = {}) {
31
38
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
32
- const encoded = iface.encodeFunctionData(name, [...callArgs]);
39
+ // address 타입 인자는 Locus base32 주소를 hex 로 변환해야 ethers 가 인코딩한다.
40
+ const fragment = iface.getFunction(name);
41
+ const encodeArgs = callArgs.map((arg, i) => {
42
+ const input = fragment.inputs[i];
43
+ if ((input === null || input === void 0 ? void 0 : input.type) === 'address' && typeof arg === 'string' && !arg.startsWith('0x')) {
44
+ const hex = wasm.convertAddressToHex(arg);
45
+ return hex != null ? '0x' + hex : arg;
46
+ }
47
+ return arg;
48
+ });
49
+ const encoded = iface.encodeFunctionData(name, encodeArgs);
33
50
  const noPrefix = encoded.startsWith('0x') ? encoded.slice(2) : encoded;
34
- const funcField = wasm.convertHexToData(noPrefix);
51
+ const callData = wasm.convertHexToData(noPrefix);
35
52
  const caller = (_c = (_a = opts.caller) !== null && _a !== void 0 ? _a : (_b = client.account) === null || _b === void 0 ? void 0 : _b.address) !== null && _c !== void 0 ? _c : address;
36
53
  const rpcResult = yield client.request({
37
- method: 'debug_viewContract',
54
+ method: 'debug_viewVme',
38
55
  params: [
39
56
  {
40
57
  callerAccount: caller,
41
- contractAccount: address,
58
+ vmeId,
59
+ subId: address,
42
60
  amount: (_d = opts.amount) !== null && _d !== void 0 ? _d : '0',
43
61
  fuelLimit: (_e = opts.fuelLimit) !== null && _e !== void 0 ? _e : '0',
44
62
  tokenAmounts: [],
45
- func: funcField,
46
- argData: '',
47
- feeType: 0,
63
+ callData,
48
64
  sign: '',
49
65
  signedHeight: 0,
66
+ feeType: 0,
50
67
  },
51
68
  ],
52
69
  });
@@ -6,19 +6,26 @@ var wasm = require('../chunks/wasm-dbtq7eri.cjs');
6
6
  require('../chunks/lclib-rGyKpClJ.cjs');
7
7
 
8
8
  /**
9
- * Locus 의 debug_viewContract RPC 위에 viem 스타일 컨트랙트 핸들을 만든다.
9
+ * Locus 의 debug_viewVme RPC 위에 viem 스타일 컨트랙트 핸들을 만든다.
10
10
  * `read.<fn>` 은 ethers(v5) 의 Interface 로 호출을 인코딩하고, 결과 바이트를
11
- * convertHexToData 로 Locus `func` 필드에 담아 보낸 뒤, 응답 hex 를
11
+ * convertHexToData 로 Locus `callData` 필드에 담아 보낸 뒤, 응답 hex 를
12
12
  * Interface.decodeFunctionResult 로 다시 디코딩한다.
13
13
  *
14
+ * 신규 VME 모델: 컨트랙트는 (vmeId, subId) 로 식별된다. `address` 가 subId 이고
15
+ * `vmeId` 는 read 호출 시 ReadCallOptions 로 받는다 (필수). RPC ParamsCallVme 의
16
+ * vmeId/subId 와 1:1 대응.
17
+ *
14
18
  * write 메서드는 이번 단계에서는 의도적으로 빠져 있다. 상태를 바꾸는 호출
15
19
  * 은 생성된 wallet action 을 직접 사용한다:
16
20
  *
17
- * import { callContract } from '@locuschain/lib/autogen';
18
- * await wallet.extend(debugWalletActions).callContract({ ... });
21
+ * import { callVme } from '@locuschain/lib/autogen';
22
+ * await wallet.extend(debugWalletActions).callVme({ ... });
19
23
  */
20
24
  function getContract(args) {
21
- const { address, abi, client } = args;
25
+ const { address, abi, client, vmeId } = args;
26
+ if (!vmeId) {
27
+ throw new Error('getContract: vmeId is required');
28
+ }
22
29
  const iface = new ethers_esm_min.ethers.utils.Interface(abi);
23
30
  const read = {};
24
31
  for (const item of normalizeAbi(abi)) {
@@ -34,24 +41,34 @@ function getContract(args) {
34
41
  function makeRead(name) {
35
42
  return (...args_1) => tslib_es6.__awaiter(this, [...args_1], void 0, function* (callArgs = [], opts = {}) {
36
43
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
37
- const encoded = iface.encodeFunctionData(name, [...callArgs]);
44
+ // address 타입 인자는 Locus base32 주소를 hex 로 변환해야 ethers 가 인코딩한다.
45
+ const fragment = iface.getFunction(name);
46
+ const encodeArgs = callArgs.map((arg, i) => {
47
+ const input = fragment.inputs[i];
48
+ if ((input === null || input === void 0 ? void 0 : input.type) === 'address' && typeof arg === 'string' && !arg.startsWith('0x')) {
49
+ const hex = wasm.convertAddressToHex(arg);
50
+ return hex != null ? '0x' + hex : arg;
51
+ }
52
+ return arg;
53
+ });
54
+ const encoded = iface.encodeFunctionData(name, encodeArgs);
38
55
  const noPrefix = encoded.startsWith('0x') ? encoded.slice(2) : encoded;
39
- const funcField = wasm.convertHexToData(noPrefix);
56
+ const callData = wasm.convertHexToData(noPrefix);
40
57
  const caller = (_c = (_a = opts.caller) !== null && _a !== void 0 ? _a : (_b = client.account) === null || _b === void 0 ? void 0 : _b.address) !== null && _c !== void 0 ? _c : address;
41
58
  const rpcResult = yield client.request({
42
- method: 'debug_viewContract',
59
+ method: 'debug_viewVme',
43
60
  params: [
44
61
  {
45
62
  callerAccount: caller,
46
- contractAccount: address,
63
+ vmeId,
64
+ subId: address,
47
65
  amount: (_d = opts.amount) !== null && _d !== void 0 ? _d : '0',
48
66
  fuelLimit: (_e = opts.fuelLimit) !== null && _e !== void 0 ? _e : '0',
49
67
  tokenAmounts: [],
50
- func: funcField,
51
- argData: '',
52
- feeType: 0,
68
+ callData,
53
69
  sign: '',
54
70
  signedHeight: 0,
71
+ feeType: 0,
55
72
  },
56
73
  ],
57
74
  });
@@ -1,22 +1,29 @@
1
1
  import { _ as __awaiter } from '../chunks/tslib.es6-WQS2tr1v.js';
2
2
  import { e as ethers } from '../chunks/ethers.esm.min-CiOJmj8w.js';
3
- import { r as convertHexToData, n as convertDataToHex } from '../chunks/wasm-CU215LGW.js';
3
+ import { f as convertAddressToHex, r as convertHexToData, n as convertDataToHex } from '../chunks/wasm-CU215LGW.js';
4
4
  import '../chunks/lclib-j2x9RvDY.js';
5
5
 
6
6
  /**
7
- * Locus 의 debug_viewContract RPC 위에 viem 스타일 컨트랙트 핸들을 만든다.
7
+ * Locus 의 debug_viewVme RPC 위에 viem 스타일 컨트랙트 핸들을 만든다.
8
8
  * `read.<fn>` 은 ethers(v5) 의 Interface 로 호출을 인코딩하고, 결과 바이트를
9
- * convertHexToData 로 Locus `func` 필드에 담아 보낸 뒤, 응답 hex 를
9
+ * convertHexToData 로 Locus `callData` 필드에 담아 보낸 뒤, 응답 hex 를
10
10
  * Interface.decodeFunctionResult 로 다시 디코딩한다.
11
11
  *
12
+ * 신규 VME 모델: 컨트랙트는 (vmeId, subId) 로 식별된다. `address` 가 subId 이고
13
+ * `vmeId` 는 read 호출 시 ReadCallOptions 로 받는다 (필수). RPC ParamsCallVme 의
14
+ * vmeId/subId 와 1:1 대응.
15
+ *
12
16
  * write 메서드는 이번 단계에서는 의도적으로 빠져 있다. 상태를 바꾸는 호출
13
17
  * 은 생성된 wallet action 을 직접 사용한다:
14
18
  *
15
- * import { callContract } from '@locuschain/lib/autogen';
16
- * await wallet.extend(debugWalletActions).callContract({ ... });
19
+ * import { callVme } from '@locuschain/lib/autogen';
20
+ * await wallet.extend(debugWalletActions).callVme({ ... });
17
21
  */
18
22
  function getContract(args) {
19
- const { address, abi, client } = args;
23
+ const { address, abi, client, vmeId } = args;
24
+ if (!vmeId) {
25
+ throw new Error('getContract: vmeId is required');
26
+ }
20
27
  const iface = new ethers.utils.Interface(abi);
21
28
  const read = {};
22
29
  for (const item of normalizeAbi(abi)) {
@@ -32,24 +39,34 @@ function getContract(args) {
32
39
  function makeRead(name) {
33
40
  return (...args_1) => __awaiter(this, [...args_1], void 0, function* (callArgs = [], opts = {}) {
34
41
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
35
- const encoded = iface.encodeFunctionData(name, [...callArgs]);
42
+ // address 타입 인자는 Locus base32 주소를 hex 로 변환해야 ethers 가 인코딩한다.
43
+ const fragment = iface.getFunction(name);
44
+ const encodeArgs = callArgs.map((arg, i) => {
45
+ const input = fragment.inputs[i];
46
+ if ((input === null || input === void 0 ? void 0 : input.type) === 'address' && typeof arg === 'string' && !arg.startsWith('0x')) {
47
+ const hex = convertAddressToHex(arg);
48
+ return hex != null ? '0x' + hex : arg;
49
+ }
50
+ return arg;
51
+ });
52
+ const encoded = iface.encodeFunctionData(name, encodeArgs);
36
53
  const noPrefix = encoded.startsWith('0x') ? encoded.slice(2) : encoded;
37
- const funcField = convertHexToData(noPrefix);
54
+ const callData = convertHexToData(noPrefix);
38
55
  const caller = (_c = (_a = opts.caller) !== null && _a !== void 0 ? _a : (_b = client.account) === null || _b === void 0 ? void 0 : _b.address) !== null && _c !== void 0 ? _c : address;
39
56
  const rpcResult = yield client.request({
40
- method: 'debug_viewContract',
57
+ method: 'debug_viewVme',
41
58
  params: [
42
59
  {
43
60
  callerAccount: caller,
44
- contractAccount: address,
61
+ vmeId,
62
+ subId: address,
45
63
  amount: (_d = opts.amount) !== null && _d !== void 0 ? _d : '0',
46
64
  fuelLimit: (_e = opts.fuelLimit) !== null && _e !== void 0 ? _e : '0',
47
65
  tokenAmounts: [],
48
- func: funcField,
49
- argData: '',
50
- feeType: 0,
66
+ callData,
51
67
  sign: '',
52
68
  signedHeight: 0,
69
+ feeType: 0,
53
70
  },
54
71
  ],
55
72
  });
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@locuschain/lib",
3
- "version": "0.2.8",
3
+ "version": "0.2.10",
4
4
  "type": "module",
5
5
  "author": "bloomtechnology",
6
6
  "license": "MIT",
7
7
  "description": "",
8
8
  "engines": {
9
- "node": "~22.19.0"
9
+ "node": ">=20.0.0"
10
10
  },
11
11
  "main": "./dist/index.cjs.cjs",
12
12
  "module": "./dist/index.amd.js",
@@ -107,6 +107,43 @@
107
107
  "require": "./dist/webpack-plugin/index.cjs.cjs"
108
108
  }
109
109
  },
110
+ "typesVersions": {
111
+ "*": {
112
+ "clients": [
113
+ "./dist/clients/index.d.cts"
114
+ ],
115
+ "transports": [
116
+ "./dist/transports/index.d.cts"
117
+ ],
118
+ "accounts": [
119
+ "./dist/accounts/index.d.cts"
120
+ ],
121
+ "errors": [
122
+ "./dist/errors/index.d.cts"
123
+ ],
124
+ "contracts": [
125
+ "./dist/contracts/index.d.cts"
126
+ ],
127
+ "autogen": [
128
+ "./dist/autogen/index.d.cts"
129
+ ],
130
+ "utils": [
131
+ "./dist/utils/index.d.cts"
132
+ ],
133
+ "types": [
134
+ "./dist/types/index.d.cts"
135
+ ],
136
+ "constant": [
137
+ "./dist/constant/index.d.cts"
138
+ ],
139
+ "vite-plugin": [
140
+ "./dist/vite-plugin/index.d.cts"
141
+ ],
142
+ "webpack-plugin": [
143
+ "./dist/webpack-plugin/index.d.cts"
144
+ ]
145
+ }
146
+ },
110
147
  "files": [
111
148
  "./dist"
112
149
  ],