Wallet Controller

All chain interaction functions which are vault dependent

Functions

Create an instance
const wallet = new WalletController({
    baseUrl: 'http://localhost:8000',
    walletType: {
        embedded: true, // for external wallet it should be false
        suppportAa: boolean,
    }, 
    environment, // ENV // default is mainnet
    selectedChainName, // string // default is undefined
    sessionSignatures,
    currentAccount,
    customAuthMethod,
    accessToken,
    sentryDns,
    aa,
    selectedWallet,
} as TriaArgs);

export type ENV = 'testnet' | 'mainnet-staging' | 'mainnet';

export type AaDetails = {
  pimlicoApiKey?: string;
  isSponsored?: boolean;
  sponsorshipPolicyId?: string;
  accountType?: AaAccountType;
  sponsorshipPolicyIds?: ChainNameToPolicyId; // {"FUSE": "sp_id_fuse", "POLYGON": "sp_id_poly"}
};

export type AaAccountType = 'Simple' | 'Kernel' | 'Safe' | 'Biconomy';
Init
// This inits the signer elements in the wallet instance
// Should be done for all write interactions
await wallet.init()
Send Tokens ⛽️
send({
    payload,
    chain,
    gas,
    privateKey,
  }: {
    payload: Send;
    chain?: ChainData;
    gas?: Gas;
    privateKey?: string;
  }): Promise<TxnResponse>;
export interface TxnResponse {
  success: boolean;
  data?: {
    txnId: string;
    viewInExplorer: string;
    wait: Function;
  };
  message?: string;
}
export interface Send {
  fromTriaName: string;
  recipientTriaName: string;
  amount: number;
  tokenAddress?: string | number | Object;
}
// Example
const chainName = "ETHEREUM";
const payload = {
  fromTriaName: "dawn@tria",
  recipientTriaName: "kate@tria";
  amount: 0.1, // ETH
  tokenAddress: null;
};
const txn = keyring.send(chainName, payload)
  • internally we fetch the privateKey from the client storage, i.e., from decrypted vault

  • A check on the FE needs to made for the input & total balance. ( Input <= Total Balance)

    • you will get totalBalance values from getAllAssets

      • which will be used to show the assets in choose asset block

  • tokenAddress -> will be whatever you receive from getAllAssets in number, string, or Object

    • number -> assetId in Polkadot -> Statemint

    • Object -> in case of sui

Latest:

  • Same for new Lit infra gas abstraction integrations

  • Same for Solana old infra gas abstraction updates

Sign Message
signMessage({
    message,
    chain,
    privateKey,
  }: {
    message: string;
    chain?: ChainData;
    privateKey?: string;
  }): Promise<StringDataResponse> 
Approve ⛽️
 approve({
    payload,
    chain,
    privateKey,
    gas,
  }: {
    payload: Approve;
    chain?: ChainData;
    privateKey?: string;
    gas?: Gas;
  }): Promise<TxnResponse>;
export interface Approve {
  tokenAddress: string;
  amount: number;
  spender: string;
}
export interface TxnResponse {
  success: boolean;
  data?: {
    txnId: string;
    viewInExplorer: string;
    wait: Function;
  };
  message?: string;
}
Send NFT ⛽️
sendNFT({
    recipientTriaName,
    nftDetails,
    chain,
    privateKey,
    gas,
  }: {
    recipientTriaName: string;
    nftDetails: NFTDetails;
    chain: ChainData;
    privateKey?: string;
    gas?: Gas;
  }): Promise<TxnResponse>
export interface NFTDetails {
  type: string; // ERC721 or ERC1155 - in "interface" field from getNFTs
  tokenAddress: string; // nftInfo.contract_address
  tokenId: string; // nftInfo.token_id
  amount: number; // input in case of ERC1155, 1 in case of ERC721
}
export interface TxnResponse {
  success: boolean;
  data?: {
    txnId: string;
    viewInExplorer: string;
    wait: Function;
  };
  message?: string;
}

Latest:

  • Same for new Lit infra gas abstraction integrations

  • Same for Solana old infra gas abstraction updates

Call Contract ⛽️
callContract({
    contractDetails,
    chain,
    privateKey,
    gas,
  }: {
    contractDetails: ContractDetails;
    chain: ChainData;
    privateKey?: string;
    gas?: Gas;
  }): Promise<TxnResponse>
export interface ContractDetails {
  contractAddress: string;
  abi: Object[];
  functionName: string;
  args: [];
  value?: number; // specify native token amount to be transfered, eg. 1 (if 1 MATIC), 0 if no native token payment or erc20.
} 
Broadcast Transaction
broadcastTransaction({
    txnObject,
    userOperation,
    chain,
    privateKey,
  }: {
    txnObject?: Object;
    userOperation?: Object;
    chain?: ChainData;
    privateKey?: string;
  }): Promise<TxnResponse>
  • Use this when you have a userOp returned from FeeController response.

  • This userOp has to also include the gas cut txn on the same chain with some other token

  • No gas abstraction ❌ in this one, only gas abstraction possible if a batched userOp (with user's main txn + gas cut txn) is passed

Read Contract
readContract(
    contractDetails: ContractDetails,
    chainName?: string
  ): Promise<ReadContractResponse>;
export interface ReadContractResponse {
  success: boolean;
  data?: any;
  message?: string;
  error?: any;
}
Decrypt
decrypt({
    encryptedData,
    chain,
  }: {
    encryptedData: string;
    chain: ChainData;
  }): Promise<StringDataResponse>;
Encrypt
encrypt({
    data,
    version = "x25519-xsalsa20-poly1305",
    chain,
  }: {
    data: string;
    version: string;
    chain?: ChainData;
  }): Promise<StringDataResponse>

Types

Gas
export type Gas = {
  token?: { name: GasTokenType; address?: string; amount?: number };
};

export type GasTokenType = "USDC" | "USDT" | "TST";
ChainData
export type ChainData = {
  chainName?: string;
  customChain?: CustomChainData;
};

export type CustomChainData = {
  type: "EVM";
  chainId: number;
  rpcUrl: string;
  currencySymbol: string;
  currencyName?: string;
  chainName?: string;
  chainLogo?: string;
  explorerUrl?: string;
};

⛽️ Lit Infra Gas abstraction updates on same chain - @tria-sdk/web@6.5.0

  • If using the interaction functions directly it will batch both txns (main+gas/fee cut txn) in the same userOp and broadcast

  • If we are using broadcastTxn for the userOp received by FeeController - this userOp only includes the main user txn - on the basis of gas estimated for this txn - we get the gas token amount to cut for the gas cut txn details - we now have to estimate again after the gas token is selected - batch it with the main user txn and get the new userOp (with gas cut txn too) to broadcast.

    • or, use the main txn interaction functions (send, sendNft, ..) directly to with the gas amount

    • Ideal case, we preselect a gas token to cut, but we don't know the amount yet unless the first txn fee is estimated, so we have to create the new userOp in the 2nd time only anyways

⛽️ Solana Old Infra gas abstraction updates - @tria-sdk/web@4.2.27

  • only in, send

  • sendNft

  • rest is in SolanaWallet controller for signAndSendTransaction for any kind of transaction

Last updated