diff --git a/examples/main.ts b/examples/main.ts index b0e95b8..721d22a 100644 --- a/examples/main.ts +++ b/examples/main.ts @@ -1,6 +1,6 @@ import { createWalletClient, http } from "viem"; -import { getEmptyBytes, getRandomBytes } from "../src/common/utils/bytes.js"; +import { getRandomBytes } from "../src/common/utils/bytes.js"; import { NetworkType, FolksCore, @@ -23,7 +23,6 @@ async function main() { FolksCore.setNetwork(NetworkType.TESTNET); const accountId: AccountId = getRandomBytes(BYTES32_LENGTH) as AccountId; - const refAccountId: AccountId = getEmptyBytes(BYTES32_LENGTH) as AccountId; // read const accountInfo = await FolksAccount.read.accountInfo(accountId); @@ -46,12 +45,10 @@ async function main() { const prepareCreateAccountCall = await FolksAccount.prepare.createAccount( accountId, - refAccountId, adapters, ); const createAccountCallRes = await FolksAccount.write.createAccount( accountId, - refAccountId, prepareCreateAccountCall, ); diff --git a/src/common/constants/lending.ts b/src/common/constants/lending.ts new file mode 100644 index 0000000..01d7c02 --- /dev/null +++ b/src/common/constants/lending.ts @@ -0,0 +1,3 @@ +import { getAccountIdBytes } from "../utils/bytes.js"; + +export const NULL_ACCOUNT_ID = getAccountIdBytes(""); diff --git a/src/common/utils/bytes.ts b/src/common/utils/bytes.ts index c14a2e3..5cdce3a 100644 --- a/src/common/utils/bytes.ts +++ b/src/common/utils/bytes.ts @@ -2,14 +2,17 @@ import { bytesToHex, pad, toHex } from "viem"; import { BYTES32_LENGTH } from "../constants/bytes.js"; +import type { AccountId } from "../types/lending.js"; import type { Hex } from "viem"; export function getEmptyBytes(length: number): string { return pad("0x", { size: length }); } -export function getAccountIdBytes(accountId: string): Hex { - return pad(toHex(Buffer.from(accountId)), { size: BYTES32_LENGTH }); +export function getAccountIdBytes(accountId: string): AccountId { + return pad(toHex(Buffer.from(accountId)), { + size: BYTES32_LENGTH, + }) as AccountId; } export function convertNumberToBytes( diff --git a/src/xchain/modules/folks-account.ts b/src/xchain/modules/folks-account.ts index bc5461e..4cd05b2 100644 --- a/src/xchain/modules/folks-account.ts +++ b/src/xchain/modules/folks-account.ts @@ -1,6 +1,7 @@ import { FolksHubAccount } from "../../chains/evm/hub/modules/index.js"; import { getHubChain } from "../../chains/evm/hub/utils/chain.js"; import { FolksEvmAccount } from "../../chains/evm/spoke/modules/index.js"; +import { NULL_ACCOUNT_ID } from "../../common/constants/lending.js"; import { ChainType } from "../../common/types/chain.js"; import { Action } from "../../common/types/message.js"; import { assertAdapterSupportsDataMessage } from "../../common/utils/adapter.js"; @@ -42,8 +43,8 @@ import type { export const prepare = { async createAccount( accountId: AccountId, - refAccountId: AccountId, adapters: MessageAdapters, + refAccountId: AccountId = NULL_ACCOUNT_ID, ) { const folksChain = FolksCore.getSelectedFolksChain(); @@ -110,8 +111,8 @@ export const prepare = { accountId: AccountId, folksChainIdToInvite: FolksChainId, addressToInvite: GenericAddress, - refAccountId: AccountId, adapters: MessageAdapters, + refAccountId: AccountId = NULL_ACCOUNT_ID, ) { const folksChain = FolksCore.getSelectedFolksChain(); @@ -313,8 +314,8 @@ export const prepare = { export const write = { async createAccount( accountId: AccountId, - refAccountId: AccountId, prepareCall: PrepareCreateAccountCall, + refAccountId: AccountId = NULL_ACCOUNT_ID, ) { const folksChain = FolksCore.getSelectedFolksChain(); @@ -338,8 +339,8 @@ export const write = { accountId: AccountId, folksChainIdToInvite: FolksChainId, addressToInvite: GenericAddress, - refAccountId: AccountId, prepareCall: PrepareInviteAddressCall, + refAccountId: AccountId = NULL_ACCOUNT_ID, ) { const folksChain = FolksCore.getSelectedFolksChain();