@weblock-wallet/sdk 0.1.41 → 0.1.42
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 +0 -185
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -16
- package/dist/index.d.ts +0 -16
- package/dist/index.js +0 -185
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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;
|
|
@@ -106305,142 +106259,6 @@ var WalletModule = class {
|
|
|
106305
106259
|
);
|
|
106306
106260
|
}
|
|
106307
106261
|
}
|
|
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
106262
|
async getBalance(address, chainId) {
|
|
106445
106263
|
return this.core.wallet.getBalance(address, chainId);
|
|
106446
106264
|
}
|
|
@@ -106623,9 +106441,6 @@ var WeBlockSDK = class {
|
|
|
106623
106441
|
getBalance: (address, chainId) => {
|
|
106624
106442
|
return this.walletModule.getBalance(address, chainId);
|
|
106625
106443
|
},
|
|
106626
|
-
investUsdtForRbt10to1: async (opts) => {
|
|
106627
|
-
return this.walletModule.investUsdtForRbt10to1(opts);
|
|
106628
|
-
},
|
|
106629
106444
|
getTransactionCount: (address, chainId) => {
|
|
106630
106445
|
return this.walletModule.getTransactionCount(address, chainId);
|
|
106631
106446
|
},
|