@weblock-wallet/sdk 0.1.41 → 0.1.43

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.cjs CHANGED
@@ -104151,18 +104151,6 @@ var ERC20_ABI = [
104151
104151
  "function decimals() view returns (uint8)",
104152
104152
  "function symbol() view returns (string)"
104153
104153
  ];
104154
- var hexToBigInt = (hex) => BigInt(hex);
104155
- var pow10 = (d4) => [...Array(d4)].reduce((n5) => n5 * 10n, 1n);
104156
- var ERC20_ABI_MIN = [
104157
- "function decimals() view returns (uint8)",
104158
- "function symbol() view returns (string)",
104159
- "function approve(address spender, uint256 amount) returns (bool)",
104160
- "function transfer(address to, uint256 amount) returns (bool)",
104161
- "function allowance(address owner, address spender) view returns (uint256)"
104162
- ];
104163
- var RBT_ABI_MIN = ["function mint(address to, uint256 amount)"];
104164
- var erc20Iface = new import_ethers2.Interface(ERC20_ABI_MIN);
104165
- var rbtIface = new import_ethers2.Interface(RBT_ABI_MIN);
104166
104154
  var WalletService = class {
104167
104155
  constructor(walletClient, rpcClient, orgHost, networkService) {
104168
104156
  this.walletClient = walletClient;
@@ -104417,24 +104405,6 @@ var WalletService = class {
104417
104405
  symbol
104418
104406
  };
104419
104407
  }
104420
- /** "123.45" → wei(BigInt) */
104421
- humanToRaw(amount, decimals) {
104422
- const [intStr, fracStrRaw = ""] = amount.split(".");
104423
- const fracStr = fracStrRaw.padEnd(decimals, "0").slice(0, decimals);
104424
- return BigInt(intStr || "0") * pow10(decimals) + BigInt(fracStr || "0");
104425
- }
104426
- /** on-chain ERC20 decimals 조회 */
104427
- async fetchErc20Decimals(call, token, chainId) {
104428
- const data = erc20Iface.encodeFunctionData("decimals", []);
104429
- const res = await call({ to: token, data }, "latest", chainId);
104430
- return parseInt(res, 16);
104431
- }
104432
- /** allowance 조회 */
104433
- async fetchAllowance(call, token, owner, spender, chainId) {
104434
- const data = erc20Iface.encodeFunctionData("allowance", [owner, spender]);
104435
- const res = await call({ to: token, data }, "latest", chainId);
104436
- return hexToBigInt(res);
104437
- }
104438
104408
  async getTransactionCount(address, chainId) {
104439
104409
  const response = await this.rpcClient.sendRpc({
104440
104410
  chainId,
@@ -106022,9 +105992,6 @@ var InternalCoreImpl = class {
106022
105992
  retrieveWallet: (password) => this.walletService.retrieveWallet(password),
106023
105993
  getBalance: (address, chainId) => this.walletService.getBalance(address, chainId),
106024
105994
  getTokenBalance: (tokenAddress, walletAddress, chainId) => this.walletService.getTokenBalance(tokenAddress, walletAddress, chainId),
106025
- humanToRaw: (amount, decimals) => this.walletService.humanToRaw(amount, decimals),
106026
- fetchErc20Decimals: (call, token, chainId) => this.walletService.fetchErc20Decimals(call, token, chainId),
106027
- fetchAllowance: (call, token, owner, spender, chainId) => this.walletService.fetchAllowance(call, token, owner, spender, chainId),
106028
105995
  sendTransaction: (params) => this.walletService.sendTransaction(params),
106029
105996
  getTransactionCount: (address, chainId) => this.walletService.getTransactionCount(address, chainId),
106030
105997
  getBlockNumber: (chainId) => this.walletService.getBlockNumber(chainId),
@@ -106153,19 +106120,6 @@ var UserModule = class {
106153
106120
  };
106154
106121
 
106155
106122
  // src/modules/wallet.ts
106156
- var import_ethers4 = require("ethers");
106157
- var bigIntToHex = (v5) => "0x" + v5.toString(16);
106158
- var pow102 = (d4) => [...Array(d4)].reduce((n5) => n5 * 10n, 1n);
106159
- var ERC20_ABI_MIN2 = [
106160
- "function decimals() view returns (uint8)",
106161
- "function symbol() view returns (string)",
106162
- "function approve(address spender, uint256 amount) returns (bool)",
106163
- "function transfer(address to, uint256 amount) returns (bool)",
106164
- "function allowance(address owner, address spender) view returns (uint256)"
106165
- ];
106166
- var RBT_ABI_MIN2 = ["function mint(address to, uint256 amount)"];
106167
- var erc20Iface2 = new import_ethers4.Interface(ERC20_ABI_MIN2);
106168
- var rbtIface2 = new import_ethers4.Interface(RBT_ABI_MIN2);
106169
106123
  var WalletModule = class {
106170
106124
  constructor(options, core) {
106171
106125
  this.options = options;
@@ -106213,30 +106167,6 @@ var WalletModule = class {
106213
106167
  network.chainId
106214
106168
  );
106215
106169
  console.log("\uB124\uC774\uD2F0\uBE0C \uCF54\uC778 \uC794\uC561:", nativeBalance);
106216
- const rbtBalance = await this.core.wallet.getTokenBalance(
106217
- "0xB10536cC40Cb6E6415f70d3a4C1AF7Fa638AE829",
106218
- address,
106219
- network.chainId
106220
- );
106221
- console.log("RBT \uC794\uC561:", rbtBalance);
106222
- const usdrBalance = await this.core.wallet.getTokenBalance(
106223
- "0x8d335fe5B30e27F2B21F057a4766cf4BB8c30785",
106224
- address,
106225
- network.chainId
106226
- );
106227
- console.log("USDR \uC794\uC561:", usdrBalance);
106228
- const wftBalance = await this.core.wallet.getTokenBalance(
106229
- "0x6fa62Eda03956ef4E54f3C8597E8c3f3bE40A45B",
106230
- address,
106231
- network.chainId
106232
- );
106233
- console.log("WFT \uC794\uC561:", wftBalance);
106234
- const usdtBalance = await this.core.wallet.getTokenBalance(
106235
- "0xfF54B9ebe777f528E64C74bc95c68433B7546038",
106236
- address,
106237
- network.chainId
106238
- );
106239
- console.log("USDT \uC794\uC561:", usdtBalance);
106240
106170
  console.log("5. \uCD5C\uADFC \uD2B8\uB79C\uC7AD\uC158 \uC870\uD68C \uC2DC\uC791");
106241
106171
  const latestTransaction = await this.core.wallet.getLatestTransaction(
106242
106172
  address,
@@ -106256,38 +106186,38 @@ var WalletModule = class {
106256
106186
  decimals: 18
106257
106187
  },
106258
106188
  tokens: [
106259
- {
106260
- symbol: rbtBalance.symbol,
106261
- name: "Real-estate Backed Token",
106262
- address: "0xB10536cC40Cb6E6415f70d3a4C1AF7Fa638AE829",
106263
- balance: rbtBalance,
106264
- decimals: rbtBalance.decimals,
106265
- totalSupply: rbtBalance
106266
- },
106267
- {
106268
- symbol: usdrBalance.symbol,
106269
- name: "USD Real-estate",
106270
- address: "0x8d335fe5B30e27F2B21F057a4766cf4BB8c30785",
106271
- balance: usdrBalance,
106272
- decimals: usdrBalance.decimals,
106273
- totalSupply: usdrBalance
106274
- },
106275
- {
106276
- symbol: wftBalance.symbol,
106277
- name: "WeBlock Foundation Token",
106278
- address: "0x6fa62Eda03956ef4E54f3C8597E8c3f3bE40A45B",
106279
- balance: wftBalance,
106280
- decimals: wftBalance.decimals,
106281
- totalSupply: wftBalance
106282
- },
106283
- {
106284
- symbol: usdtBalance.symbol,
106285
- name: "USD Tether",
106286
- address: "0xfF54B9ebe777f528E64C74bc95c68433B7546038",
106287
- balance: usdtBalance,
106288
- decimals: usdtBalance.decimals,
106289
- totalSupply: usdtBalance
106290
- }
106189
+ // {
106190
+ // symbol: rbtBalance.symbol,
106191
+ // name: 'Real-estate Backed Token',
106192
+ // address: '0xB10536cC40Cb6E6415f70d3a4C1AF7Fa638AE829',
106193
+ // balance: rbtBalance,
106194
+ // decimals: rbtBalance.decimals,
106195
+ // totalSupply: rbtBalance,
106196
+ // },
106197
+ // {
106198
+ // symbol: usdrBalance.symbol,
106199
+ // name: 'USD Real-estate',
106200
+ // address: '0x8d335fe5B30e27F2B21F057a4766cf4BB8c30785',
106201
+ // balance: usdrBalance,
106202
+ // decimals: usdrBalance.decimals,
106203
+ // totalSupply: usdrBalance,
106204
+ // },
106205
+ // {
106206
+ // symbol: wftBalance.symbol,
106207
+ // name: 'WeBlock Foundation Token',
106208
+ // address: '0x6fa62Eda03956ef4E54f3C8597E8c3f3bE40A45B',
106209
+ // balance: wftBalance,
106210
+ // decimals: wftBalance.decimals,
106211
+ // totalSupply: wftBalance,
106212
+ // },
106213
+ // {
106214
+ // symbol: usdtBalance.symbol,
106215
+ // name: 'USD Tether',
106216
+ // address: '0xfF54B9ebe777f528E64C74bc95c68433B7546038',
106217
+ // balance: usdtBalance,
106218
+ // decimals: usdtBalance.decimals,
106219
+ // totalSupply: usdtBalance,
106220
+ // },
106291
106221
  ],
106292
106222
  nfts: [],
106293
106223
  securities: []
@@ -106305,142 +106235,6 @@ var WalletModule = class {
106305
106235
  );
106306
106236
  }
106307
106237
  }
106308
- /**
106309
- * USDT 10개당 1 RBT 민트 규칙으로 투자 실행
106310
- * mode: 'direct' → caller가 MINTER_ROLE을 가진 어드민 지갑일 때 바로 RBT.mint 실행
106311
- * mode: 'backend' → USDT를 트레저리로 보낸 뒤, 백엔드가 민팅하도록 payload 반환
106312
- */
106313
- async investUsdtForRbt10to1(opts) {
106314
- const { usdtAddress, rbtAddress, treasuryAddress, amountUsdt, chainId } = opts;
106315
- const mode = opts.mode ?? "backend";
106316
- const isLoggedIn = await this.core.auth.isLoggedIn();
106317
- if (!isLoggedIn)
106318
- throw new SDKError("\uB85C\uADF8\uC778\uC774 \uD544\uC694\uD569\uB2C8\uB2E4", "NOT_LOGGED_IN" /* NOT_LOGGED_IN */);
106319
- const from = await this.core.wallet.getAddress();
106320
- if (!from)
106321
- throw new SDKError("\uC9C0\uAC11 \uC8FC\uC18C \uC5C6\uC74C", "WALLET_NOT_FOUND" /* WALLET_NOT_FOUND */);
106322
- const network = await this.core.network.getCurrentNetwork();
106323
- if (!network || network.chainId !== chainId) {
106324
- await this.core.network.switchNetwork(chainId.toString());
106325
- }
106326
- const usdtDecimals = await this.core.wallet.fetchErc20Decimals(
106327
- this.call.bind(this),
106328
- usdtAddress,
106329
- chainId
106330
- );
106331
- const rbtDecimals = await this.core.wallet.fetchErc20Decimals(
106332
- this.call.bind(this),
106333
- rbtAddress,
106334
- chainId
106335
- );
106336
- const usdtRaw = this.core.wallet.humanToRaw(amountUsdt, usdtDecimals);
106337
- if (rbtDecimals < usdtDecimals) {
106338
- throw new SDKError(
106339
- "RBT decimals < USDT decimals\uB294 \uC9C0\uC6D0\uD558\uC9C0 \uC54A\uC74C",
106340
- "INVALID_PARAMS" /* INVALID_PARAMS */
106341
- );
106342
- }
106343
- const scale = pow102(rbtDecimals - usdtDecimals);
106344
- const rbtRaw = usdtRaw * scale / 10n;
106345
- const rbtAmountRawHex = bigIntToHex(rbtRaw);
106346
- let usdtApproveTxHash;
106347
- const allowance = await this.core.wallet.fetchAllowance(
106348
- this.call.bind(this),
106349
- usdtAddress,
106350
- from,
106351
- treasuryAddress,
106352
- chainId
106353
- );
106354
- if (allowance < usdtRaw) {
106355
- const approveData = erc20Iface2.encodeFunctionData("approve", [
106356
- treasuryAddress,
106357
- bigIntToHex(usdtRaw)
106358
- ]);
106359
- const gasLimit = await this.estimateGas(
106360
- { from, to: usdtAddress, data: approveData, value: "0x0" },
106361
- chainId
106362
- ).catch(() => void 0);
106363
- usdtApproveTxHash = await this.core.wallet.sendTransaction({
106364
- to: usdtAddress,
106365
- data: approveData,
106366
- value: "0x0",
106367
- chainId
106368
- });
106369
- }
106370
- const transferData = erc20Iface2.encodeFunctionData("transfer", [
106371
- treasuryAddress,
106372
- bigIntToHex(usdtRaw)
106373
- ]);
106374
- const transferGas = await this.estimateGas(
106375
- { from, to: usdtAddress, data: transferData, value: "0x0" },
106376
- chainId
106377
- ).catch(() => void 0);
106378
- const usdtTransferTxHash = await this.core.wallet.sendTransaction({
106379
- to: usdtAddress,
106380
- data: transferData,
106381
- value: "0x0",
106382
- chainId
106383
- });
106384
- const to = opts.recipient || from;
106385
- if (mode === "direct") {
106386
- const mintData = rbtIface2.encodeFunctionData("mint", [
106387
- to,
106388
- rbtAmountRawHex
106389
- ]);
106390
- const mintGas = await this.estimateGas(
106391
- { from, to: rbtAddress, data: mintData, value: "0x0" },
106392
- chainId
106393
- ).catch(() => void 0);
106394
- const rbtMintTxHash = await this.core.wallet.sendTransaction({
106395
- to: rbtAddress,
106396
- data: mintData,
106397
- value: "0x0",
106398
- chainId
106399
- });
106400
- return {
106401
- usdtApproveTxHash,
106402
- usdtTransferTxHash,
106403
- rbtMintTxHash,
106404
- rbtAmountRaw: rbtAmountRawHex,
106405
- rbtAmountHuman: `${(Number(rbtRaw) / Number(pow102(rbtDecimals))).toString()}`,
106406
- note: "direct: \uD638\uCD9C \uC9C0\uAC11\uC774 MINTER_ROLE\uC744 \uBCF4\uC720\uD558\uBBC0\uB85C \uC628\uCCB4\uC778\uC5D0\uC11C \uC989\uC2DC RBT mint \uC644\uB8CC"
106407
- };
106408
- }
106409
- return {
106410
- usdtApproveTxHash,
106411
- usdtTransferTxHash,
106412
- rbtAmountRaw: rbtAmountRawHex,
106413
- rbtAmountHuman: `${(Number(rbtRaw) / Number(pow102(rbtDecimals))).toString()}`,
106414
- note: "backend: USDT \uC785\uAE08 \uC644\uB8CC. \uBC31\uC5D4\uB4DC(\uBBFC\uD130 \uD0A4 \uBCF4\uC720)\uAC00 RBT.mint(to, amount) \uD638\uCD9C \uD544\uC694"
106415
- };
106416
- }
106417
- /**
106418
- * (옵션) RBT 민트를 단독으로 호출하는 유틸
106419
- * - 호출 지갑이 MINTER_ROLE을 보유해야 성공
106420
- */
106421
- async mintRbtDirect(opts) {
106422
- const { rbtAddress, to, amountRbtHuman, chainId } = opts;
106423
- const from = await this.core.wallet.getAddress();
106424
- if (!from)
106425
- throw new SDKError("\uC9C0\uAC11 \uC8FC\uC18C \uC5C6\uC74C", "WALLET_NOT_FOUND" /* WALLET_NOT_FOUND */);
106426
- const rbtDecimals = await this.core.wallet.fetchErc20Decimals(
106427
- this.call.bind(this),
106428
- rbtAddress,
106429
- chainId
106430
- );
106431
- const rbtRaw = this.core.wallet.humanToRaw(amountRbtHuman, rbtDecimals);
106432
- const data = rbtIface2.encodeFunctionData("mint", [to, bigIntToHex(rbtRaw)]);
106433
- const gasLimit = await this.estimateGas(
106434
- { from, to: rbtAddress, data, value: "0x0" },
106435
- chainId
106436
- ).catch(() => void 0);
106437
- return this.core.wallet.sendTransaction({
106438
- to: rbtAddress,
106439
- data,
106440
- value: "0x0",
106441
- chainId
106442
- });
106443
- }
106444
106238
  async getBalance(address, chainId) {
106445
106239
  return this.core.wallet.getBalance(address, chainId);
106446
106240
  }
@@ -106623,9 +106417,6 @@ var WeBlockSDK = class {
106623
106417
  getBalance: (address, chainId) => {
106624
106418
  return this.walletModule.getBalance(address, chainId);
106625
106419
  },
106626
- investUsdtForRbt10to1: async (opts) => {
106627
- return this.walletModule.investUsdtForRbt10to1(opts);
106628
- },
106629
106420
  getTransactionCount: (address, chainId) => {
106630
106421
  return this.walletModule.getTransactionCount(address, chainId);
106631
106422
  },