@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.d.cts CHANGED
@@ -426,22 +426,6 @@ declare class WeBlockSDK {
426
426
  onWalletUpdate: (callback: (wallet: WalletInfo) => void) => (() => void);
427
427
  onTransactionUpdate: (callback: (tx: Transaction | undefined) => void) => (() => void);
428
428
  getBalance: (address: string, chainId: number) => Promise<TokenBalance>;
429
- investUsdtForRbt10to1: (opts: {
430
- usdtAddress: string;
431
- rbtAddress: string;
432
- treasuryAddress: string;
433
- amountUsdt: string;
434
- chainId: number;
435
- recipient?: string;
436
- mode?: "direct" | "backend";
437
- }) => Promise<{
438
- usdtApproveTxHash?: string;
439
- usdtTransferTxHash: string;
440
- rbtMintTxHash?: string;
441
- rbtAmountRaw: string;
442
- rbtAmountHuman: string;
443
- note: string;
444
- }>;
445
429
  getTransactionCount: (address: string, chainId: number) => Promise<number>;
446
430
  getBlockNumber: (chainId: number) => Promise<number>;
447
431
  sendRawTransaction: (signedTx: string, chainId: number) => Promise<string>;
package/dist/index.d.ts CHANGED
@@ -426,22 +426,6 @@ declare class WeBlockSDK {
426
426
  onWalletUpdate: (callback: (wallet: WalletInfo) => void) => (() => void);
427
427
  onTransactionUpdate: (callback: (tx: Transaction | undefined) => void) => (() => void);
428
428
  getBalance: (address: string, chainId: number) => Promise<TokenBalance>;
429
- investUsdtForRbt10to1: (opts: {
430
- usdtAddress: string;
431
- rbtAddress: string;
432
- treasuryAddress: string;
433
- amountUsdt: string;
434
- chainId: number;
435
- recipient?: string;
436
- mode?: "direct" | "backend";
437
- }) => Promise<{
438
- usdtApproveTxHash?: string;
439
- usdtTransferTxHash: string;
440
- rbtMintTxHash?: string;
441
- rbtAmountRaw: string;
442
- rbtAmountHuman: string;
443
- note: string;
444
- }>;
445
429
  getTransactionCount: (address: string, chainId: number) => Promise<number>;
446
430
  getBlockNumber: (chainId: number) => Promise<number>;
447
431
  sendRawTransaction: (signedTx: string, chainId: number) => Promise<string>;
package/dist/index.js CHANGED
@@ -104106,18 +104106,6 @@ var ERC20_ABI = [
104106
104106
  "function decimals() view returns (uint8)",
104107
104107
  "function symbol() view returns (string)"
104108
104108
  ];
104109
- var hexToBigInt = (hex) => BigInt(hex);
104110
- var pow10 = (d4) => [...Array(d4)].reduce((n5) => n5 * 10n, 1n);
104111
- var ERC20_ABI_MIN = [
104112
- "function decimals() view returns (uint8)",
104113
- "function symbol() view returns (string)",
104114
- "function approve(address spender, uint256 amount) returns (bool)",
104115
- "function transfer(address to, uint256 amount) returns (bool)",
104116
- "function allowance(address owner, address spender) view returns (uint256)"
104117
- ];
104118
- var RBT_ABI_MIN = ["function mint(address to, uint256 amount)"];
104119
- var erc20Iface = new Interface(ERC20_ABI_MIN);
104120
- var rbtIface = new Interface(RBT_ABI_MIN);
104121
104109
  var WalletService = class {
104122
104110
  constructor(walletClient, rpcClient, orgHost, networkService) {
104123
104111
  this.walletClient = walletClient;
@@ -104372,24 +104360,6 @@ var WalletService = class {
104372
104360
  symbol
104373
104361
  };
104374
104362
  }
104375
- /** "123.45" → wei(BigInt) */
104376
- humanToRaw(amount, decimals) {
104377
- const [intStr, fracStrRaw = ""] = amount.split(".");
104378
- const fracStr = fracStrRaw.padEnd(decimals, "0").slice(0, decimals);
104379
- return BigInt(intStr || "0") * pow10(decimals) + BigInt(fracStr || "0");
104380
- }
104381
- /** on-chain ERC20 decimals 조회 */
104382
- async fetchErc20Decimals(call, token, chainId) {
104383
- const data = erc20Iface.encodeFunctionData("decimals", []);
104384
- const res = await call({ to: token, data }, "latest", chainId);
104385
- return parseInt(res, 16);
104386
- }
104387
- /** allowance 조회 */
104388
- async fetchAllowance(call, token, owner, spender, chainId) {
104389
- const data = erc20Iface.encodeFunctionData("allowance", [owner, spender]);
104390
- const res = await call({ to: token, data }, "latest", chainId);
104391
- return hexToBigInt(res);
104392
- }
104393
104363
  async getTransactionCount(address, chainId) {
104394
104364
  const response = await this.rpcClient.sendRpc({
104395
104365
  chainId,
@@ -105981,9 +105951,6 @@ var InternalCoreImpl = class {
105981
105951
  retrieveWallet: (password) => this.walletService.retrieveWallet(password),
105982
105952
  getBalance: (address, chainId) => this.walletService.getBalance(address, chainId),
105983
105953
  getTokenBalance: (tokenAddress, walletAddress, chainId) => this.walletService.getTokenBalance(tokenAddress, walletAddress, chainId),
105984
- humanToRaw: (amount, decimals) => this.walletService.humanToRaw(amount, decimals),
105985
- fetchErc20Decimals: (call, token, chainId) => this.walletService.fetchErc20Decimals(call, token, chainId),
105986
- fetchAllowance: (call, token, owner, spender, chainId) => this.walletService.fetchAllowance(call, token, owner, spender, chainId),
105987
105954
  sendTransaction: (params) => this.walletService.sendTransaction(params),
105988
105955
  getTransactionCount: (address, chainId) => this.walletService.getTransactionCount(address, chainId),
105989
105956
  getBlockNumber: (chainId) => this.walletService.getBlockNumber(chainId),
@@ -106112,19 +106079,6 @@ var UserModule = class {
106112
106079
  };
106113
106080
 
106114
106081
  // src/modules/wallet.ts
106115
- import { Interface as Interface3 } from "ethers";
106116
- var bigIntToHex = (v5) => "0x" + v5.toString(16);
106117
- var pow102 = (d4) => [...Array(d4)].reduce((n5) => n5 * 10n, 1n);
106118
- var ERC20_ABI_MIN2 = [
106119
- "function decimals() view returns (uint8)",
106120
- "function symbol() view returns (string)",
106121
- "function approve(address spender, uint256 amount) returns (bool)",
106122
- "function transfer(address to, uint256 amount) returns (bool)",
106123
- "function allowance(address owner, address spender) view returns (uint256)"
106124
- ];
106125
- var RBT_ABI_MIN2 = ["function mint(address to, uint256 amount)"];
106126
- var erc20Iface2 = new Interface3(ERC20_ABI_MIN2);
106127
- var rbtIface2 = new Interface3(RBT_ABI_MIN2);
106128
106082
  var WalletModule = class {
106129
106083
  constructor(options, core) {
106130
106084
  this.options = options;
@@ -106172,30 +106126,6 @@ var WalletModule = class {
106172
106126
  network.chainId
106173
106127
  );
106174
106128
  console.log("\uB124\uC774\uD2F0\uBE0C \uCF54\uC778 \uC794\uC561:", nativeBalance);
106175
- const rbtBalance = await this.core.wallet.getTokenBalance(
106176
- "0xB10536cC40Cb6E6415f70d3a4C1AF7Fa638AE829",
106177
- address,
106178
- network.chainId
106179
- );
106180
- console.log("RBT \uC794\uC561:", rbtBalance);
106181
- const usdrBalance = await this.core.wallet.getTokenBalance(
106182
- "0x8d335fe5B30e27F2B21F057a4766cf4BB8c30785",
106183
- address,
106184
- network.chainId
106185
- );
106186
- console.log("USDR \uC794\uC561:", usdrBalance);
106187
- const wftBalance = await this.core.wallet.getTokenBalance(
106188
- "0x6fa62Eda03956ef4E54f3C8597E8c3f3bE40A45B",
106189
- address,
106190
- network.chainId
106191
- );
106192
- console.log("WFT \uC794\uC561:", wftBalance);
106193
- const usdtBalance = await this.core.wallet.getTokenBalance(
106194
- "0xfF54B9ebe777f528E64C74bc95c68433B7546038",
106195
- address,
106196
- network.chainId
106197
- );
106198
- console.log("USDT \uC794\uC561:", usdtBalance);
106199
106129
  console.log("5. \uCD5C\uADFC \uD2B8\uB79C\uC7AD\uC158 \uC870\uD68C \uC2DC\uC791");
106200
106130
  const latestTransaction = await this.core.wallet.getLatestTransaction(
106201
106131
  address,
@@ -106215,38 +106145,38 @@ var WalletModule = class {
106215
106145
  decimals: 18
106216
106146
  },
106217
106147
  tokens: [
106218
- {
106219
- symbol: rbtBalance.symbol,
106220
- name: "Real-estate Backed Token",
106221
- address: "0xB10536cC40Cb6E6415f70d3a4C1AF7Fa638AE829",
106222
- balance: rbtBalance,
106223
- decimals: rbtBalance.decimals,
106224
- totalSupply: rbtBalance
106225
- },
106226
- {
106227
- symbol: usdrBalance.symbol,
106228
- name: "USD Real-estate",
106229
- address: "0x8d335fe5B30e27F2B21F057a4766cf4BB8c30785",
106230
- balance: usdrBalance,
106231
- decimals: usdrBalance.decimals,
106232
- totalSupply: usdrBalance
106233
- },
106234
- {
106235
- symbol: wftBalance.symbol,
106236
- name: "WeBlock Foundation Token",
106237
- address: "0x6fa62Eda03956ef4E54f3C8597E8c3f3bE40A45B",
106238
- balance: wftBalance,
106239
- decimals: wftBalance.decimals,
106240
- totalSupply: wftBalance
106241
- },
106242
- {
106243
- symbol: usdtBalance.symbol,
106244
- name: "USD Tether",
106245
- address: "0xfF54B9ebe777f528E64C74bc95c68433B7546038",
106246
- balance: usdtBalance,
106247
- decimals: usdtBalance.decimals,
106248
- totalSupply: usdtBalance
106249
- }
106148
+ // {
106149
+ // symbol: rbtBalance.symbol,
106150
+ // name: 'Real-estate Backed Token',
106151
+ // address: '0xB10536cC40Cb6E6415f70d3a4C1AF7Fa638AE829',
106152
+ // balance: rbtBalance,
106153
+ // decimals: rbtBalance.decimals,
106154
+ // totalSupply: rbtBalance,
106155
+ // },
106156
+ // {
106157
+ // symbol: usdrBalance.symbol,
106158
+ // name: 'USD Real-estate',
106159
+ // address: '0x8d335fe5B30e27F2B21F057a4766cf4BB8c30785',
106160
+ // balance: usdrBalance,
106161
+ // decimals: usdrBalance.decimals,
106162
+ // totalSupply: usdrBalance,
106163
+ // },
106164
+ // {
106165
+ // symbol: wftBalance.symbol,
106166
+ // name: 'WeBlock Foundation Token',
106167
+ // address: '0x6fa62Eda03956ef4E54f3C8597E8c3f3bE40A45B',
106168
+ // balance: wftBalance,
106169
+ // decimals: wftBalance.decimals,
106170
+ // totalSupply: wftBalance,
106171
+ // },
106172
+ // {
106173
+ // symbol: usdtBalance.symbol,
106174
+ // name: 'USD Tether',
106175
+ // address: '0xfF54B9ebe777f528E64C74bc95c68433B7546038',
106176
+ // balance: usdtBalance,
106177
+ // decimals: usdtBalance.decimals,
106178
+ // totalSupply: usdtBalance,
106179
+ // },
106250
106180
  ],
106251
106181
  nfts: [],
106252
106182
  securities: []
@@ -106264,142 +106194,6 @@ var WalletModule = class {
106264
106194
  );
106265
106195
  }
106266
106196
  }
106267
- /**
106268
- * USDT 10개당 1 RBT 민트 규칙으로 투자 실행
106269
- * mode: 'direct' → caller가 MINTER_ROLE을 가진 어드민 지갑일 때 바로 RBT.mint 실행
106270
- * mode: 'backend' → USDT를 트레저리로 보낸 뒤, 백엔드가 민팅하도록 payload 반환
106271
- */
106272
- async investUsdtForRbt10to1(opts) {
106273
- const { usdtAddress, rbtAddress, treasuryAddress, amountUsdt, chainId } = opts;
106274
- const mode = opts.mode ?? "backend";
106275
- const isLoggedIn = await this.core.auth.isLoggedIn();
106276
- if (!isLoggedIn)
106277
- throw new SDKError("\uB85C\uADF8\uC778\uC774 \uD544\uC694\uD569\uB2C8\uB2E4", "NOT_LOGGED_IN" /* NOT_LOGGED_IN */);
106278
- const from = await this.core.wallet.getAddress();
106279
- if (!from)
106280
- throw new SDKError("\uC9C0\uAC11 \uC8FC\uC18C \uC5C6\uC74C", "WALLET_NOT_FOUND" /* WALLET_NOT_FOUND */);
106281
- const network = await this.core.network.getCurrentNetwork();
106282
- if (!network || network.chainId !== chainId) {
106283
- await this.core.network.switchNetwork(chainId.toString());
106284
- }
106285
- const usdtDecimals = await this.core.wallet.fetchErc20Decimals(
106286
- this.call.bind(this),
106287
- usdtAddress,
106288
- chainId
106289
- );
106290
- const rbtDecimals = await this.core.wallet.fetchErc20Decimals(
106291
- this.call.bind(this),
106292
- rbtAddress,
106293
- chainId
106294
- );
106295
- const usdtRaw = this.core.wallet.humanToRaw(amountUsdt, usdtDecimals);
106296
- if (rbtDecimals < usdtDecimals) {
106297
- throw new SDKError(
106298
- "RBT decimals < USDT decimals\uB294 \uC9C0\uC6D0\uD558\uC9C0 \uC54A\uC74C",
106299
- "INVALID_PARAMS" /* INVALID_PARAMS */
106300
- );
106301
- }
106302
- const scale = pow102(rbtDecimals - usdtDecimals);
106303
- const rbtRaw = usdtRaw * scale / 10n;
106304
- const rbtAmountRawHex = bigIntToHex(rbtRaw);
106305
- let usdtApproveTxHash;
106306
- const allowance = await this.core.wallet.fetchAllowance(
106307
- this.call.bind(this),
106308
- usdtAddress,
106309
- from,
106310
- treasuryAddress,
106311
- chainId
106312
- );
106313
- if (allowance < usdtRaw) {
106314
- const approveData = erc20Iface2.encodeFunctionData("approve", [
106315
- treasuryAddress,
106316
- bigIntToHex(usdtRaw)
106317
- ]);
106318
- const gasLimit = await this.estimateGas(
106319
- { from, to: usdtAddress, data: approveData, value: "0x0" },
106320
- chainId
106321
- ).catch(() => void 0);
106322
- usdtApproveTxHash = await this.core.wallet.sendTransaction({
106323
- to: usdtAddress,
106324
- data: approveData,
106325
- value: "0x0",
106326
- chainId
106327
- });
106328
- }
106329
- const transferData = erc20Iface2.encodeFunctionData("transfer", [
106330
- treasuryAddress,
106331
- bigIntToHex(usdtRaw)
106332
- ]);
106333
- const transferGas = await this.estimateGas(
106334
- { from, to: usdtAddress, data: transferData, value: "0x0" },
106335
- chainId
106336
- ).catch(() => void 0);
106337
- const usdtTransferTxHash = await this.core.wallet.sendTransaction({
106338
- to: usdtAddress,
106339
- data: transferData,
106340
- value: "0x0",
106341
- chainId
106342
- });
106343
- const to = opts.recipient || from;
106344
- if (mode === "direct") {
106345
- const mintData = rbtIface2.encodeFunctionData("mint", [
106346
- to,
106347
- rbtAmountRawHex
106348
- ]);
106349
- const mintGas = await this.estimateGas(
106350
- { from, to: rbtAddress, data: mintData, value: "0x0" },
106351
- chainId
106352
- ).catch(() => void 0);
106353
- const rbtMintTxHash = await this.core.wallet.sendTransaction({
106354
- to: rbtAddress,
106355
- data: mintData,
106356
- value: "0x0",
106357
- chainId
106358
- });
106359
- return {
106360
- usdtApproveTxHash,
106361
- usdtTransferTxHash,
106362
- rbtMintTxHash,
106363
- rbtAmountRaw: rbtAmountRawHex,
106364
- rbtAmountHuman: `${(Number(rbtRaw) / Number(pow102(rbtDecimals))).toString()}`,
106365
- 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"
106366
- };
106367
- }
106368
- return {
106369
- usdtApproveTxHash,
106370
- usdtTransferTxHash,
106371
- rbtAmountRaw: rbtAmountRawHex,
106372
- rbtAmountHuman: `${(Number(rbtRaw) / Number(pow102(rbtDecimals))).toString()}`,
106373
- note: "backend: USDT \uC785\uAE08 \uC644\uB8CC. \uBC31\uC5D4\uB4DC(\uBBFC\uD130 \uD0A4 \uBCF4\uC720)\uAC00 RBT.mint(to, amount) \uD638\uCD9C \uD544\uC694"
106374
- };
106375
- }
106376
- /**
106377
- * (옵션) RBT 민트를 단독으로 호출하는 유틸
106378
- * - 호출 지갑이 MINTER_ROLE을 보유해야 성공
106379
- */
106380
- async mintRbtDirect(opts) {
106381
- const { rbtAddress, to, amountRbtHuman, chainId } = opts;
106382
- const from = await this.core.wallet.getAddress();
106383
- if (!from)
106384
- throw new SDKError("\uC9C0\uAC11 \uC8FC\uC18C \uC5C6\uC74C", "WALLET_NOT_FOUND" /* WALLET_NOT_FOUND */);
106385
- const rbtDecimals = await this.core.wallet.fetchErc20Decimals(
106386
- this.call.bind(this),
106387
- rbtAddress,
106388
- chainId
106389
- );
106390
- const rbtRaw = this.core.wallet.humanToRaw(amountRbtHuman, rbtDecimals);
106391
- const data = rbtIface2.encodeFunctionData("mint", [to, bigIntToHex(rbtRaw)]);
106392
- const gasLimit = await this.estimateGas(
106393
- { from, to: rbtAddress, data, value: "0x0" },
106394
- chainId
106395
- ).catch(() => void 0);
106396
- return this.core.wallet.sendTransaction({
106397
- to: rbtAddress,
106398
- data,
106399
- value: "0x0",
106400
- chainId
106401
- });
106402
- }
106403
106197
  async getBalance(address, chainId) {
106404
106198
  return this.core.wallet.getBalance(address, chainId);
106405
106199
  }
@@ -106582,9 +106376,6 @@ var WeBlockSDK = class {
106582
106376
  getBalance: (address, chainId) => {
106583
106377
  return this.walletModule.getBalance(address, chainId);
106584
106378
  },
106585
- investUsdtForRbt10to1: async (opts) => {
106586
- return this.walletModule.investUsdtForRbt10to1(opts);
106587
- },
106588
106379
  getTransactionCount: (address, chainId) => {
106589
106380
  return this.walletModule.getTransactionCount(address, chainId);
106590
106381
  },