@weblock-wallet/sdk 0.1.50 → 0.1.52

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/dist/index.js CHANGED
@@ -104971,21 +104971,19 @@ var UserClient = class {
104971
104971
  * - { coin: CoinResponse }
104972
104972
  * - { data: CoinResponse }
104973
104973
  */
104974
- // UserClient 클래스 내부의 registerToken()을 아래로 교체
104975
104974
  async registerToken(req) {
104976
- const blockchainId = req.blockchainId ?? req.networkId;
104977
- const contractAddress = String(
104978
- req.contractAddress ?? req.tokenAddress ?? req.address ?? ""
104979
- ).trim().toLowerCase();
104975
+ const blockchainId = req.blockchainId;
104976
+ const contractAddress = this.normalizeAddress(req.contractAddress);
104980
104977
  const name2 = req.name;
104981
104978
  const symbol = req.symbol;
104982
104979
  const decimals = req.decimals;
104983
104980
  const candidates = [
104984
- // 1) 주소만 받는 케이스
104981
+ // 1) 최신 스펙으로 바뀌며 "주소만" 받는 경우
104985
104982
  { blockchainId, contractAddress },
104983
+ // 2) 필드명이 tokenAddress / address로 바뀐 경우
104986
104984
  { blockchainId, tokenAddress: contractAddress },
104987
104985
  { blockchainId, address: contractAddress },
104988
- // 2) 메타까지 받는 케이스
104986
+ // 3) 스펙(메타 포함) 유지/필요한 경우
104989
104987
  ...name2 && symbol && typeof decimals === "number" ? [
104990
104988
  { blockchainId, contractAddress, name: name2, symbol, decimals },
104991
104989
  {
@@ -104997,29 +104995,45 @@ var UserClient = class {
104997
104995
  },
104998
104996
  { blockchainId, address: contractAddress, name: name2, symbol, decimals }
104999
104997
  ] : [],
105000
- // 3) 파라미터명이 networkId로 바뀐 케이스
105001
- { networkId: blockchainId, contractAddress },
105002
- ...name2 && symbol && typeof decimals === "number" ? [{ networkId: blockchainId, contractAddress, name: name2, symbol, decimals }] : []
104998
+ // 4) blockchainId가 networkId로 바뀐 경우
104999
+ ...name2 && symbol && typeof decimals === "number" ? [
105000
+ {
105001
+ networkId: blockchainId,
105002
+ contractAddress,
105003
+ name: name2,
105004
+ symbol,
105005
+ decimals
105006
+ },
105007
+ {
105008
+ networkId: blockchainId,
105009
+ tokenAddress: contractAddress,
105010
+ name: name2,
105011
+ symbol,
105012
+ decimals
105013
+ }
105014
+ ] : [{ networkId: blockchainId, contractAddress }]
105003
105015
  ];
105004
105016
  let lastError = null;
105005
105017
  for (const body of candidates) {
105006
105018
  try {
105007
- const res = await this.postAuthed(
105008
- "/v1/users/register-token",
105019
+ const res = await this.client.post(
105020
+ `${this.baseUrl}/register-token`,
105009
105021
  body
105010
105022
  );
105011
- const coin = res?.coin ?? res?.data ?? res;
105012
- if (coin?.contractAddress) {
105013
- return {
105014
- ...coin,
105015
- contractAddress: String(coin.contractAddress).trim().toLowerCase(),
105016
- decimals: typeof coin.decimals === "number" ? coin.decimals : Number(coin.decimals)
105017
- };
105023
+ const coin = this.unwrapCoin(res);
105024
+ if (!coin?.contractAddress) {
105025
+ continue;
105018
105026
  }
105027
+ return {
105028
+ ...coin,
105029
+ contractAddress: this.normalizeAddress(coin.contractAddress),
105030
+ decimals: Number(coin.decimals)
105031
+ };
105019
105032
  } catch (e7) {
105020
105033
  lastError = e7;
105021
- const status = e7?.status ?? e7?.response?.status ?? e7?.cause?.status ?? e7?.cause?.response?.status;
105022
- if (status === 400 || status === 409 || status === 422) continue;
105034
+ const status = this.extractStatus(e7);
105035
+ if (status === 400 || status === 422) continue;
105036
+ if (status === 409) continue;
105023
105037
  throw e7;
105024
105038
  }
105025
105039
  }
@@ -105043,32 +105057,6 @@ var UserClient = class {
105043
105057
  { needsAccessToken: true }
105044
105058
  );
105045
105059
  }
105046
- // UserClient 클래스 내부에 추가
105047
- async postAuthed(path, body) {
105048
- const httpAny = this.client;
105049
- const headers = (typeof httpAny.getAuthHeaders === "function" ? await httpAny.getAuthHeaders() : typeof httpAny.getHeaders === "function" ? await httpAny.getHeaders() : void 0) ?? void 0;
105050
- const attempts = [];
105051
- if (typeof httpAny.post === "function") {
105052
- attempts.push(() => httpAny.post(path, body, headers));
105053
- attempts.push(() => httpAny.post(path, body, { headers }));
105054
- attempts.push(() => httpAny.post(path, body));
105055
- }
105056
- if (typeof httpAny.request === "function") {
105057
- attempts.push(
105058
- () => httpAny.request({ method: "POST", path, body, headers })
105059
- );
105060
- attempts.push(() => httpAny.request("POST", path, body, headers));
105061
- }
105062
- let lastError = null;
105063
- for (const fn of attempts) {
105064
- try {
105065
- return await fn();
105066
- } catch (e7) {
105067
- lastError = e7;
105068
- }
105069
- }
105070
- throw lastError ?? new Error(`POST ${path} failed`);
105071
- }
105072
105060
  };
105073
105061
 
105074
105062
  // src/clients/api/wallets.ts
@@ -106195,17 +106183,14 @@ var AssetService = class extends EventEmitter {
106195
106183
  params.spender,
106196
106184
  params.amount
106197
106185
  ]);
106198
- const response = await this.rpcClient.sendRpc({
106199
- chainId,
106200
- method: "eth_sendRawTransaction" /* ETH_SEND_RAW_TRANSACTION */,
106201
- params: [
106202
- {
106203
- to: params.tokenAddress,
106204
- data
106205
- }
106206
- ]
106186
+ const txHash = await this.walletService.sendTransaction({
106187
+ to: params.tokenAddress,
106188
+ value: "0",
106189
+ data,
106190
+ chainId
106207
106191
  });
106208
- return response.result;
106192
+ this.trackTransaction(txHash, chainId);
106193
+ return txHash;
106209
106194
  } catch (error) {
106210
106195
  throw new SDKError(
106211
106196
  "Failed to approve token",
@@ -106288,6 +106273,402 @@ var AssetService = class extends EventEmitter {
106288
106273
  // }
106289
106274
  };
106290
106275
 
106276
+ // src/core/services/investment.ts
106277
+ import { Interface as Interface3 } from "ethers";
106278
+
106279
+ // src/contract/weblock.ts
106280
+ var RBT_PRIMARY_SALE_ROUTER_ABI = [
106281
+ {
106282
+ inputs: [{ name: "offeringId", type: "uint256" }],
106283
+ name: "offerings",
106284
+ outputs: [
106285
+ { name: "asset", type: "address" },
106286
+ { name: "seriesId", type: "uint256" },
106287
+ { name: "unitPrice", type: "uint256" },
106288
+ { name: "remainingUnits", type: "uint256" },
106289
+ { name: "startAt", type: "uint64" },
106290
+ { name: "endAt", type: "uint64" },
106291
+ { name: "treasury", type: "address" },
106292
+ { name: "enabled", type: "bool" }
106293
+ ],
106294
+ stateMutability: "view",
106295
+ type: "function"
106296
+ },
106297
+ {
106298
+ inputs: [
106299
+ { name: "offeringId", type: "uint256" },
106300
+ { name: "units", type: "uint256" },
106301
+ { name: "maxCost", type: "uint256" }
106302
+ ],
106303
+ name: "buy",
106304
+ outputs: [],
106305
+ stateMutability: "nonpayable",
106306
+ type: "function"
106307
+ }
106308
+ ];
106309
+ var RBT_PROPERTY_TOKEN_ABI = [
106310
+ {
106311
+ inputs: [
106312
+ { name: "account", type: "address" },
106313
+ { name: "id", type: "uint256" }
106314
+ ],
106315
+ name: "balanceOf",
106316
+ outputs: [{ name: "", type: "uint256" }],
106317
+ stateMutability: "view",
106318
+ type: "function"
106319
+ },
106320
+ {
106321
+ inputs: [{ name: "tokenId", type: "uint256" }],
106322
+ name: "claim",
106323
+ outputs: [],
106324
+ stateMutability: "nonpayable",
106325
+ type: "function"
106326
+ },
106327
+ {
106328
+ inputs: [
106329
+ { name: "tokenId", type: "uint256" },
106330
+ { name: "account", type: "address" }
106331
+ ],
106332
+ name: "claimable",
106333
+ outputs: [{ name: "", type: "uint256" }],
106334
+ stateMutability: "view",
106335
+ type: "function"
106336
+ }
106337
+ ];
106338
+
106339
+ // src/core/services/investment.ts
106340
+ var MAX_UINT256 = 2n ** 256n - 1n;
106341
+ var InvestmentService = class extends EventEmitter {
106342
+ constructor(rpcClient, walletService, networkService) {
106343
+ super();
106344
+ this.rpcClient = rpcClient;
106345
+ this.walletService = walletService;
106346
+ this.networkService = networkService;
106347
+ this.chainIdCache = /* @__PURE__ */ new Map();
106348
+ this.erc20Interface = new Interface3(ERC20_ABI2);
106349
+ this.saleInterface = new Interface3(RBT_PRIMARY_SALE_ROUTER_ABI);
106350
+ this.rbtInterface = new Interface3(RBT_PROPERTY_TOKEN_ABI);
106351
+ }
106352
+ assertHexAddress(addr, field) {
106353
+ const a5 = (addr ?? "").trim();
106354
+ if (!a5.startsWith("0x") || a5.length !== 42) {
106355
+ throw new SDKError(`Invalid ${field}`, "INVALID_PARAMS" /* INVALID_PARAMS */);
106356
+ }
106357
+ }
106358
+ toBigInt(v5, field) {
106359
+ try {
106360
+ if (typeof v5 === "bigint") return v5;
106361
+ if (typeof v5 === "number") {
106362
+ if (!Number.isFinite(v5) || v5 < 0) throw new Error("invalid number");
106363
+ return BigInt(v5);
106364
+ }
106365
+ const s5 = (v5 ?? "").toString().trim();
106366
+ if (!s5) throw new Error("empty");
106367
+ return BigInt(s5);
106368
+ } catch {
106369
+ throw new SDKError(`Invalid ${field}`, "INVALID_PARAMS" /* INVALID_PARAMS */);
106370
+ }
106371
+ }
106372
+ /**
106373
+ * Resolve `networkId` (wallet backend blockchainId UUID) or chainId string -> EVM chainId
106374
+ */
106375
+ async resolveChainId(networkId) {
106376
+ const trimmed = (networkId ?? "").trim();
106377
+ const cached = this.chainIdCache.get(trimmed);
106378
+ if (cached) return cached;
106379
+ const numeric = Number(trimmed);
106380
+ if (!Number.isNaN(numeric) && Number.isFinite(numeric) && numeric > 0) {
106381
+ this.chainIdCache.set(trimmed, numeric);
106382
+ return numeric;
106383
+ }
106384
+ try {
106385
+ const current = await this.networkService.getCurrentNetwork();
106386
+ if (current && current.id === trimmed) {
106387
+ this.chainIdCache.set(trimmed, current.chainId);
106388
+ return current.chainId;
106389
+ }
106390
+ if (current && String(current.chainId) === trimmed) {
106391
+ this.chainIdCache.set(trimmed, current.chainId);
106392
+ return current.chainId;
106393
+ }
106394
+ } catch {
106395
+ }
106396
+ const networks = await this.networkService.getRegisteredNetworks();
106397
+ const found = networks.find((n5) => n5.id === trimmed);
106398
+ if (found) {
106399
+ this.chainIdCache.set(trimmed, found.chainId);
106400
+ return found.chainId;
106401
+ }
106402
+ const foundByChainId = networks.find((n5) => String(n5.chainId) === trimmed);
106403
+ if (foundByChainId) {
106404
+ this.chainIdCache.set(trimmed, foundByChainId.chainId);
106405
+ return foundByChainId.chainId;
106406
+ }
106407
+ throw new SDKError("Invalid network", "INVALID_NETWORK" /* INVALID_NETWORK */);
106408
+ }
106409
+ async ethCall(chainId, to, data) {
106410
+ const res = await this.rpcClient.sendRpc({
106411
+ chainId,
106412
+ method: "eth_call" /* ETH_CALL */,
106413
+ params: [{ to, data }, "latest"]
106414
+ });
106415
+ if (res.error) {
106416
+ throw new SDKError(
106417
+ `ETH_CALL failed: ${res.error.message}`,
106418
+ "REQUEST_FAILED" /* REQUEST_FAILED */,
106419
+ res.error
106420
+ );
106421
+ }
106422
+ if (res.result === void 0) {
106423
+ throw new SDKError(
106424
+ "ETH_CALL returned empty result",
106425
+ "REQUEST_FAILED" /* REQUEST_FAILED */
106426
+ );
106427
+ }
106428
+ return res.result;
106429
+ }
106430
+ decodeU256(resultHex, method) {
106431
+ const decoded = this.erc20Interface.decodeFunctionResult(
106432
+ method,
106433
+ resultHex
106434
+ );
106435
+ return BigInt(decoded[0].toString());
106436
+ }
106437
+ async getOffering(params) {
106438
+ this.assertHexAddress(params.saleRouterAddress, "saleRouterAddress");
106439
+ const chainId = await this.resolveChainId(params.networkId);
106440
+ const offeringId = this.toBigInt(params.offeringId, "offeringId");
106441
+ const data = this.saleInterface.encodeFunctionData("offerings", [
106442
+ offeringId
106443
+ ]);
106444
+ const result = await this.ethCall(chainId, params.saleRouterAddress, data);
106445
+ const decoded = this.saleInterface.decodeFunctionResult("offerings", result);
106446
+ const asset = decoded[0];
106447
+ const seriesId = BigInt(decoded[1].toString());
106448
+ const unitPrice = BigInt(decoded[2].toString());
106449
+ const remainingUnits = BigInt(decoded[3].toString());
106450
+ const startAt = BigInt(decoded[4].toString());
106451
+ const endAt = BigInt(decoded[5].toString());
106452
+ const treasury = decoded[6];
106453
+ const enabled = Boolean(decoded[7]);
106454
+ return {
106455
+ asset,
106456
+ seriesId,
106457
+ unitPrice,
106458
+ remainingUnits,
106459
+ startAt,
106460
+ endAt,
106461
+ treasury,
106462
+ enabled
106463
+ };
106464
+ }
106465
+ /**
106466
+ * USDR로 투자 (approve 필요. autoApprove 옵션 제공)
106467
+ * - Router.buy(offeringId, units, maxCost) 호출
106468
+ */
106469
+ async investRbtWithUsdr(params) {
106470
+ this.assertHexAddress(params.usdrAddress, "usdrAddress");
106471
+ this.assertHexAddress(params.saleRouterAddress, "saleRouterAddress");
106472
+ const chainId = await this.resolveChainId(params.networkId);
106473
+ const offeringId = this.toBigInt(params.offeringId, "offeringId");
106474
+ const units = this.toBigInt(params.units, "units");
106475
+ if (units <= 0n) {
106476
+ throw new SDKError("Invalid units", "INVALID_PARAMS" /* INVALID_PARAMS */);
106477
+ }
106478
+ const offering = await this.getOffering({
106479
+ networkId: params.networkId,
106480
+ saleRouterAddress: params.saleRouterAddress,
106481
+ offeringId
106482
+ });
106483
+ if (!offering.enabled) {
106484
+ throw new SDKError("Offering is disabled", "REQUEST_FAILED" /* REQUEST_FAILED */);
106485
+ }
106486
+ const cost = units * offering.unitPrice;
106487
+ const maxCost = params.maxCostWei != null ? this.toBigInt(params.maxCostWei, "maxCostWei") : cost;
106488
+ if (maxCost < cost) {
106489
+ throw new SDKError(
106490
+ "maxCostWei is less than required cost",
106491
+ "INVALID_PARAMS" /* INVALID_PARAMS */
106492
+ );
106493
+ }
106494
+ const buyer = await this.walletService.getAddress();
106495
+ let approvalTxHash;
106496
+ const autoApprove = params.autoApprove ?? true;
106497
+ const approveMax = params.approveMax ?? true;
106498
+ const waitForApprovalReceipt = params.waitForApprovalReceipt ?? true;
106499
+ if (autoApprove) {
106500
+ const allowanceData = this.erc20Interface.encodeFunctionData(
106501
+ "allowance",
106502
+ [buyer, params.saleRouterAddress]
106503
+ );
106504
+ const allowanceHex = await this.ethCall(
106505
+ chainId,
106506
+ params.usdrAddress,
106507
+ allowanceData
106508
+ );
106509
+ const allowanceDecoded = this.erc20Interface.decodeFunctionResult(
106510
+ "allowance",
106511
+ allowanceHex
106512
+ );
106513
+ const allowance = BigInt(allowanceDecoded[0].toString());
106514
+ if (allowance < cost) {
106515
+ const approveAmount = approveMax ? MAX_UINT256 : cost;
106516
+ const approveData = this.erc20Interface.encodeFunctionData("approve", [
106517
+ params.saleRouterAddress,
106518
+ approveAmount.toString()
106519
+ ]);
106520
+ approvalTxHash = await this.walletService.sendTransaction({
106521
+ to: params.usdrAddress,
106522
+ value: "0",
106523
+ data: approveData,
106524
+ chainId,
106525
+ gasLimit: params.gasLimitApprove
106526
+ });
106527
+ this.trackTransaction(approvalTxHash, chainId);
106528
+ if (waitForApprovalReceipt) {
106529
+ const ok = await this.waitForSuccessReceipt(approvalTxHash, chainId);
106530
+ if (!ok) {
106531
+ throw new SDKError(
106532
+ "Approve transaction failed",
106533
+ "TRANSACTION_FAILED" /* TRANSACTION_FAILED */
106534
+ );
106535
+ }
106536
+ }
106537
+ }
106538
+ }
106539
+ const buyData = this.saleInterface.encodeFunctionData("buy", [
106540
+ offeringId,
106541
+ units,
106542
+ maxCost
106543
+ ]);
106544
+ const purchaseTxHash = await this.walletService.sendTransaction({
106545
+ to: params.saleRouterAddress,
106546
+ value: "0",
106547
+ data: buyData,
106548
+ chainId,
106549
+ gasLimit: params.gasLimitBuy
106550
+ });
106551
+ this.trackTransaction(purchaseTxHash, chainId);
106552
+ return {
106553
+ offering,
106554
+ costWei: cost.toString(),
106555
+ approvalTxHash,
106556
+ purchaseTxHash
106557
+ };
106558
+ }
106559
+ /**
106560
+ * RBT 수익(이자) claim
106561
+ * - RBTPropertyToken.claim(seriesId)
106562
+ */
106563
+ async claimRbtRevenue(params) {
106564
+ this.assertHexAddress(params.rbtAssetAddress, "rbtAssetAddress");
106565
+ const chainId = await this.resolveChainId(params.networkId);
106566
+ const seriesId = this.toBigInt(params.seriesId, "seriesId");
106567
+ const claimData = this.rbtInterface.encodeFunctionData("claim", [seriesId]);
106568
+ const txHash = await this.walletService.sendTransaction({
106569
+ to: params.rbtAssetAddress,
106570
+ value: "0",
106571
+ data: claimData,
106572
+ chainId,
106573
+ gasLimit: params.gasLimit
106574
+ });
106575
+ this.trackTransaction(txHash, chainId);
106576
+ return { txHash };
106577
+ }
106578
+ /**
106579
+ * claimable 조회 (eth_call)
106580
+ */
106581
+ async getClaimable(params) {
106582
+ this.assertHexAddress(params.rbtAssetAddress, "rbtAssetAddress");
106583
+ const chainId = await this.resolveChainId(params.networkId);
106584
+ const seriesId = this.toBigInt(params.seriesId, "seriesId");
106585
+ const account = params.account ?? await this.walletService.getAddress();
106586
+ this.assertHexAddress(account, "account");
106587
+ const data = this.rbtInterface.encodeFunctionData("claimable", [
106588
+ seriesId,
106589
+ account
106590
+ ]);
106591
+ const result = await this.ethCall(chainId, params.rbtAssetAddress, data);
106592
+ const decoded = this.rbtInterface.decodeFunctionResult("claimable", result);
106593
+ return BigInt(decoded[0].toString()).toString();
106594
+ }
106595
+ /**
106596
+ * RBT balanceOf 조회 (eth_call)
106597
+ */
106598
+ async getRbtBalance(params) {
106599
+ this.assertHexAddress(params.rbtAssetAddress, "rbtAssetAddress");
106600
+ const chainId = await this.resolveChainId(params.networkId);
106601
+ const seriesId = this.toBigInt(params.seriesId, "seriesId");
106602
+ const account = params.account ?? await this.walletService.getAddress();
106603
+ this.assertHexAddress(account, "account");
106604
+ const data = this.rbtInterface.encodeFunctionData("balanceOf", [
106605
+ account,
106606
+ seriesId
106607
+ ]);
106608
+ const result = await this.ethCall(chainId, params.rbtAssetAddress, data);
106609
+ const decoded = this.rbtInterface.decodeFunctionResult("balanceOf", result);
106610
+ return BigInt(decoded[0].toString()).toString();
106611
+ }
106612
+ async waitForSuccessReceipt(txHash, chainId) {
106613
+ let retryCount = 0;
106614
+ const MAX_RETRIES = 20;
106615
+ while (retryCount < MAX_RETRIES) {
106616
+ const res = await this.rpcClient.sendRpc({
106617
+ chainId,
106618
+ method: "eth_getTransactionReceipt" /* ETH_GET_TRANSACTION_RECEIPT */,
106619
+ params: [txHash]
106620
+ });
106621
+ if (res.result) {
106622
+ return res.result.status === "0x1";
106623
+ }
106624
+ retryCount++;
106625
+ await new Promise((r5) => setTimeout$1(r5, 3e3));
106626
+ }
106627
+ return false;
106628
+ }
106629
+ trackTransaction(txHash, chainId) {
106630
+ let retryCount = 0;
106631
+ const MAX_RETRIES = 20;
106632
+ const checkStatus = async () => {
106633
+ try {
106634
+ const response = await this.rpcClient.sendRpc({
106635
+ chainId,
106636
+ method: "eth_getTransactionReceipt" /* ETH_GET_TRANSACTION_RECEIPT */,
106637
+ params: [txHash]
106638
+ });
106639
+ if (response.result) {
106640
+ const status = response.result.status === "0x1" ? "SUCCESS" /* SUCCESS */ : "FAILED" /* FAILED */;
106641
+ this.emit("transactionStatusChanged", {
106642
+ hash: txHash,
106643
+ status,
106644
+ timestamp: Date.now()
106645
+ });
106646
+ return;
106647
+ }
106648
+ retryCount++;
106649
+ if (retryCount < MAX_RETRIES) {
106650
+ setTimeout$1(checkStatus, 3e3);
106651
+ } else {
106652
+ this.emit("transactionStatusChanged", {
106653
+ hash: txHash,
106654
+ status: "FAILED" /* FAILED */,
106655
+ timestamp: Date.now(),
106656
+ error: "Transaction timeout"
106657
+ });
106658
+ }
106659
+ } catch (error) {
106660
+ this.emit("transactionStatusChanged", {
106661
+ hash: txHash,
106662
+ status: "FAILED" /* FAILED */,
106663
+ timestamp: Date.now(),
106664
+ error: error instanceof Error ? error.message : "Unknown error"
106665
+ });
106666
+ }
106667
+ };
106668
+ checkStatus();
106669
+ }
106670
+ };
106671
+
106291
106672
  // src/core/internal.ts
106292
106673
  var InternalCoreImpl = class {
106293
106674
  constructor(options) {
@@ -106329,16 +106710,7 @@ var InternalCoreImpl = class {
106329
106710
  getTokenBalance: (params) => this.assetService.getTokenBalance(params),
106330
106711
  approveToken: (params) => this.assetService.approveToken(params),
106331
106712
  getAllowance: (params) => this.assetService.getAllowance(params),
106332
- // getTokenInfo: (params: TokenInfoParams) =>
106333
- // this.assetService.getTokenInfo(params),
106334
106713
  addNFTCollection: (params) => this.assetService.addNFTCollection(params),
106335
- // checkSecurityTokenCompliance: (params: {
106336
- // networkId: string
106337
- // tokenAddress: string
106338
- // from: string
106339
- // to: string
106340
- // amount: string
106341
- // }) => this.assetService.checkSecurityTokenCompliance(params),
106342
106714
  on: (event, listener) => this.assetService.on(event, listener),
106343
106715
  off: (event, listener) => this.assetService.off(event, listener),
106344
106716
  getTokenInfo: (params) => this.assetService.getTokenInfo(params),
@@ -106346,6 +106718,15 @@ var InternalCoreImpl = class {
106346
106718
  getTokenFullInfo: (params) => this.assetService.getTokenFullInfo(params),
106347
106719
  getRegisteredCoins: (networkId) => this.assetService.getRegisteredCoins(networkId)
106348
106720
  };
106721
+ this.investment = {
106722
+ getOffering: (params) => this.investmentService.getOffering(params),
106723
+ investRbtWithUsdr: (params) => this.investmentService.investRbtWithUsdr(params),
106724
+ claimRbtRevenue: (params) => this.investmentService.claimRbtRevenue(params),
106725
+ getClaimable: (params) => this.investmentService.getClaimable(params),
106726
+ getRbtBalance: (params) => this.investmentService.getRbtBalance(params),
106727
+ on: (event, listener) => this.investmentService.on(event, listener),
106728
+ off: (event, listener) => this.investmentService.off(event, listener)
106729
+ };
106349
106730
  const httpClient = new HttpClient(options);
106350
106731
  const firebase = new FirebaseAuth(options);
106351
106732
  const userClient = new UserClient(httpClient);
@@ -106371,6 +106752,11 @@ var InternalCoreImpl = class {
106371
106752
  userClient,
106372
106753
  options.orgHost
106373
106754
  );
106755
+ this.investmentService = new InvestmentService(
106756
+ rpcClient,
106757
+ this.walletService,
106758
+ this.networkService
106759
+ );
106374
106760
  }
106375
106761
  };
106376
106762
 
@@ -106646,6 +107032,35 @@ var AssetModule = class {
106646
107032
  }
106647
107033
  };
106648
107034
 
107035
+ // src/modules/Investment.ts
107036
+ var InvestmentModule = class {
107037
+ constructor(options, core) {
107038
+ this.options = options;
107039
+ this.core = core;
107040
+ }
107041
+ getOffering(params) {
107042
+ return this.core.investment.getOffering(params);
107043
+ }
107044
+ investRbtWithUsdr(params) {
107045
+ return this.core.investment.investRbtWithUsdr(params);
107046
+ }
107047
+ claimRbtRevenue(params) {
107048
+ return this.core.investment.claimRbtRevenue(params);
107049
+ }
107050
+ getClaimable(params) {
107051
+ return this.core.investment.getClaimable(params);
107052
+ }
107053
+ getRbtBalance(params) {
107054
+ return this.core.investment.getRbtBalance(params);
107055
+ }
107056
+ on(event, listener) {
107057
+ this.core.investment.on(event, listener);
107058
+ }
107059
+ off(event, listener) {
107060
+ this.core.investment.off(event, listener);
107061
+ }
107062
+ };
107063
+
106649
107064
  // src/utils/network.ts
106650
107065
  var KNOWN_NETWORKS = {
106651
107066
  1: {
@@ -106713,92 +107128,178 @@ var WeBlockSDK = class {
106713
107128
  this.initialized = false;
106714
107129
  this.user = {
106715
107130
  signIn: async (provider) => {
107131
+ this.ensureInitialized();
106716
107132
  return this.userModule.signIn(provider);
106717
107133
  },
106718
107134
  createWallet: async (password) => {
107135
+ this.ensureInitialized();
106719
107136
  return this.userModule.createWallet(password);
106720
107137
  },
106721
107138
  retrieveWallet: async (password) => {
107139
+ this.ensureInitialized();
106722
107140
  return this.userModule.retrieveWallet(password);
106723
107141
  },
106724
107142
  /**
106725
107143
  * ✅ 추가: PIN reset API 노출
106726
107144
  */
106727
107145
  resetPin: async (newPassword) => {
107146
+ this.ensureInitialized();
106728
107147
  return this.userModule.resetPin(newPassword);
106729
107148
  },
106730
107149
  signOut: async () => {
107150
+ this.ensureInitialized();
106731
107151
  return this.userModule.signOut();
106732
107152
  }
106733
107153
  };
106734
107154
  this.wallet = {
106735
107155
  getInfo: async () => {
107156
+ this.ensureInitialized();
106736
107157
  return this.walletModule.getInfo();
106737
107158
  },
106738
107159
  onWalletUpdate: (callback) => {
107160
+ this.ensureInitialized();
106739
107161
  return this.walletModule.onWalletUpdate(callback);
106740
107162
  },
106741
107163
  onTransactionUpdate: (callback) => {
107164
+ this.ensureInitialized();
106742
107165
  return this.walletModule.onTransactionUpdate(callback);
106743
107166
  },
106744
107167
  getBalance: (address, chainId) => {
107168
+ this.ensureInitialized();
106745
107169
  return this.walletModule.getBalance(address, chainId);
106746
107170
  },
106747
107171
  getTransactionCount: (address, chainId) => {
107172
+ this.ensureInitialized();
106748
107173
  return this.walletModule.getTransactionCount(address, chainId);
106749
107174
  },
106750
107175
  getBlockNumber: (chainId) => {
107176
+ this.ensureInitialized();
106751
107177
  return this.walletModule.getBlockNumber(chainId);
106752
107178
  },
106753
107179
  sendRawTransaction: (signedTx, chainId) => {
107180
+ this.ensureInitialized();
106754
107181
  return this.walletModule.sendRawTransaction(signedTx, chainId);
106755
107182
  },
106756
107183
  getTransactionReceipt: (txHash, chainId) => {
107184
+ this.ensureInitialized();
106757
107185
  return this.walletModule.getTransactionReceipt(txHash, chainId);
106758
107186
  },
106759
107187
  getTransaction: (txHash, chainId) => {
107188
+ this.ensureInitialized();
106760
107189
  return this.walletModule.getTransaction(txHash, chainId);
106761
107190
  },
106762
107191
  estimateGas: (txParams, chainId) => {
107192
+ this.ensureInitialized();
106763
107193
  return this.walletModule.estimateGas(txParams, chainId);
106764
107194
  },
106765
107195
  getGasPrice: (chainId) => {
107196
+ this.ensureInitialized();
106766
107197
  return this.walletModule.getGasPrice(chainId);
106767
107198
  },
106768
107199
  call: (txParams, blockParam, chainId) => {
107200
+ this.ensureInitialized();
106769
107201
  return this.walletModule.call(txParams, blockParam, chainId);
106770
107202
  }
106771
107203
  };
106772
107204
  this.network = {
106773
- getAvailableNetworks: () => this.networkModule.getAvailableNetworks(),
106774
- addNetwork: (request) => this.networkModule.addNetwork(request),
106775
- switchNetwork: (networkId) => this.networkModule.switchNetwork(networkId),
106776
- getCurrentNetwork: () => this.networkModule.getCurrentNetwork()
107205
+ getAvailableNetworks: () => {
107206
+ this.ensureInitialized();
107207
+ return this.networkModule.getAvailableNetworks();
107208
+ },
107209
+ addNetwork: (request) => {
107210
+ this.ensureInitialized();
107211
+ return this.networkModule.addNetwork(request);
107212
+ },
107213
+ switchNetwork: (networkId) => {
107214
+ this.ensureInitialized();
107215
+ return this.networkModule.switchNetwork(networkId);
107216
+ },
107217
+ getCurrentNetwork: () => {
107218
+ this.ensureInitialized();
107219
+ return this.networkModule.getCurrentNetwork();
107220
+ }
106777
107221
  };
106778
107222
  this.asset = {
106779
107223
  transfer: async (params) => {
107224
+ this.ensureInitialized();
106780
107225
  return this.assetModule.transfer(params);
106781
107226
  },
106782
107227
  addToken: async (params) => {
107228
+ this.ensureInitialized();
106783
107229
  return this.assetModule.addToken(params);
106784
107230
  },
106785
107231
  addNFTCollection: async (params) => {
107232
+ this.ensureInitialized();
106786
107233
  return this.assetModule.addNFTCollection(params);
106787
107234
  },
106788
107235
  on: (event, listener) => {
107236
+ this.ensureInitialized();
106789
107237
  this.assetModule.on(event, listener);
106790
107238
  },
106791
107239
  off: (event, listener) => {
107240
+ this.ensureInitialized();
106792
107241
  this.assetModule.off(event, listener);
106793
107242
  },
106794
107243
  getTokenInfo: async (params) => {
107244
+ this.ensureInitialized();
106795
107245
  return this.assetModule.getTokenInfo(params);
106796
107246
  },
106797
107247
  registerToken: async (params) => {
107248
+ this.ensureInitialized();
106798
107249
  return this.assetModule.registerToken(params);
106799
107250
  },
106800
107251
  getTokenFullInfo: async (params) => {
107252
+ this.ensureInitialized();
106801
107253
  return this.assetModule.getTokenFullInfo(params);
107254
+ },
107255
+ /**
107256
+ * ✅ ERC20 잔액 조회 (주의: 현재 AssetModule 구현은 raw balance string을 반환)
107257
+ * - TokenBalance(객체)가 아니라 string(wei) 입니다.
107258
+ */
107259
+ getTokenBalance: async (params) => {
107260
+ this.ensureInitialized();
107261
+ return this.assetModule.getTokenBalance(params);
107262
+ },
107263
+ approveToken: async (params) => {
107264
+ this.ensureInitialized();
107265
+ return this.assetModule.approveToken(params);
107266
+ },
107267
+ getAllowance: async (params) => {
107268
+ this.ensureInitialized();
107269
+ return this.assetModule.getAllowance(params);
107270
+ }
107271
+ };
107272
+ /**
107273
+ * ✅ NEW: Investment API Surface
107274
+ */
107275
+ this.invest = {
107276
+ getOffering: async (params) => {
107277
+ this.ensureInitialized();
107278
+ return this.investmentModule.getOffering(params);
107279
+ },
107280
+ investRbtWithUsdr: async (params) => {
107281
+ this.ensureInitialized();
107282
+ return this.investmentModule.investRbtWithUsdr(params);
107283
+ },
107284
+ claimRbtRevenue: async (params) => {
107285
+ this.ensureInitialized();
107286
+ return this.investmentModule.claimRbtRevenue(params);
107287
+ },
107288
+ getClaimable: async (params) => {
107289
+ this.ensureInitialized();
107290
+ return this.investmentModule.getClaimable(params);
107291
+ },
107292
+ getRbtBalance: async (params) => {
107293
+ this.ensureInitialized();
107294
+ return this.investmentModule.getRbtBalance(params);
107295
+ },
107296
+ on: (event, listener) => {
107297
+ this.ensureInitialized();
107298
+ this.investmentModule.on(event, listener);
107299
+ },
107300
+ off: (event, listener) => {
107301
+ this.ensureInitialized();
107302
+ this.investmentModule.off(event, listener);
106802
107303
  }
106803
107304
  };
106804
107305
  this.validateOptions(options);
@@ -106808,6 +107309,7 @@ var WeBlockSDK = class {
106808
107309
  this.userModule = new UserModule(options, internalCore, this.walletModule);
106809
107310
  this.assetModule = new AssetModule(options, internalCore);
106810
107311
  this.networkModule = new NetworkModule(options, internalCore);
107312
+ this.investmentModule = new InvestmentModule(options, internalCore);
106811
107313
  this.initialized = true;
106812
107314
  console.info("WeBlock SDK initialized successfully");
106813
107315
  }
@@ -106816,13 +107318,15 @@ var WeBlockSDK = class {
106816
107318
  if (!["local", "dev", "stage", "prod"].includes(environment)) {
106817
107319
  throw new SDKError("Invalid environment", "INVALID_CONFIG" /* INVALID_CONFIG */);
106818
107320
  }
106819
- if (!apiKey)
107321
+ if (!apiKey) {
106820
107322
  throw new SDKError("API key is required", "INVALID_CONFIG" /* INVALID_CONFIG */);
106821
- if (!orgHost)
107323
+ }
107324
+ if (!orgHost) {
106822
107325
  throw new SDKError(
106823
107326
  "Organization host is required",
106824
107327
  "INVALID_CONFIG" /* INVALID_CONFIG */
106825
107328
  );
107329
+ }
106826
107330
  }
106827
107331
  ensureInitialized() {
106828
107332
  if (!this.initialized) {