Skip to content

Commit

Permalink
update backend api doc & mpc & getbalance
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLastHobbit committed Jun 24, 2024
1 parent 623a06d commit c9a1022
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 3,397 deletions.
2 changes: 1 addition & 1 deletion cache/solidity-files-cache.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions frontend/wallet/src/components/Register.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ function Register() {
console.log("walletAddress:", walletAddress);

const initCode = await createAccount(wallet.address, salt, commitment);
const _accountGasLimits = encodeGas(100000, 200000);
const _gasFees = encodeGas(100000, 200000);
const _accountGasLimits = encodeGas(1000000, 2000000);
const _gasFees = encodeGas(1000000, 2000000);

const puo = await createPackedUserOperation(walletAddress, initCode, "", _accountGasLimits, 1000000, _gasFees, "", "0x");
console.log("puo:", puo);
Expand Down
67 changes: 55 additions & 12 deletions frontend/wallet/src/util/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ export async function createWallet() {

// 创建钱包所需要的initcode
export async function createAccount(owner, salt, emailcommitment) {
let initCode =
FACTORY_ADDRESS +
factory.interface
.encodeFunctionData("createAccount", [
owner,
salt,
emailcommitment
])
.slice(2);
console.log("owner:",owner);
const encodedFunctionData = factory.interface.encodeFunctionData("createAccount", [
owner,
salt,
emailcommitment
]);
console.log("encodedFunctionData: " + encodedFunctionData);
// 将地址和函数编码数据合并
const initCode = ethers.utils.hexConcat([FACTORY_ADDRESS, encodedFunctionData]);
console.log("initCode: " + initCode);
return initCode;
}
Expand Down Expand Up @@ -153,9 +153,52 @@ const packedUserOperation = {
signature: '' // 签名
};

// export async function getWalletBalance(wallet,address) {
// return wallet.getBalance(address);
// }
export async function getERC20Balance(walletAddress, tokenAddress) {
try {
// ERC20 代币的 ABI(只包含我们需要的 balanceOf 函数)
const minABI = [
{
"constant":true,
"inputs":[{"name":"_owner","type":"address"}],
"name":"balanceOf",
"outputs":[{"name":"balance","type":"uint256"}],
"type":"function"
}
];

// 创建合约实例
const contract = new ethers.Contract(tokenAddress, minABI, provider);

// 调用 balanceOf 函数
const balance = await contract.balanceOf(walletAddress);

// 获取代币的小数位数
const decimals = await contract.decimals();

// 将余额转换为易读格式
const formattedBalance = ethers.utils.formatUnits(balance, decimals);

return formattedBalance;
} catch (error) {
console.error('Error fetching ERC20 balance:', error);
throw error;
}
}

export async function getETHBalance(walletAddress) {
try {
// 获取余额(返回值是 BigNumber 类型)
const balanceWei = await provider.getBalance(walletAddress);

// 将余额从 Wei 转换为 ETH,并格式化为字符串
const balanceEth = ethers.utils.formatEther(balanceWei);

return balanceEth;
} catch (error) {
console.error('Error fetching ETH balance:', error);
throw error;
}
}



Expand Down
3 changes: 3 additions & 0 deletions lib/account-abstraction/contracts/core/EntryPoint.sol
Original file line number Diff line number Diff line change
Expand Up @@ -442,11 +442,14 @@ contract EntryPoint is IEntryPoint, StakeManager, NonceManager, ReentrancyGuard,
) internal {
if (initCode.length != 0) {
address sender = opInfo.mUserOp.sender;

if (sender.code.length != 0)
revert FailedOp(opIndex, "AA10 sender already constructed");
address sender1 = senderCreator().createSender{
gas: opInfo.mUserOp.verificationGasLimit
}(initCode);
console.log("sender1:",sender1);
console.log("sender:",sender);
if (sender1 == address(0))
revert FailedOp(opIndex, "AA13 initCode failed or OOG");
if (sender1 != sender)
Expand Down
2 changes: 1 addition & 1 deletion out/EntryPoint.sol/EntryPoint.json

Large diffs are not rendered by default.

Loading

0 comments on commit c9a1022

Please sign in to comment.