Skip to content

Commit

Permalink
Feat(SMA-597): Supported Tokens method (#425)
Browse files Browse the repository at this point in the history
* Resolved SMA-597

* lint:fix
  • Loading branch information
joepegler authored Feb 26, 2024
1 parent 8b9fb5d commit 6d2fb27
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
46 changes: 46 additions & 0 deletions packages/account/src/BiconomySmartAccountV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import {
PaymasterUserOperationDto,
SimulationType,
BalancePayload,
SupportedToken,
} from "./utils/Types.js";
import {
ADDRESS_RESOLVER_ADDRESS,
Expand Down Expand Up @@ -714,6 +715,51 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {
return this.getPaymasterFeeQuotesOrData(userOp, buildUseropDto.paymasterServiceData);
}

/**
*
* @description This function will return an array of supported tokens from the erc20 paymaster associated with the Smart Account
* @returns Promise<{@link SupportedToken}>
*
* @example
* import { createClient } from "viem"
* import { createSmartAccountClient } from "@biconomy/account"
* import { createWalletClient, http } from "viem";
* import { polygonMumbai } from "viem/chains";
*
* const signer = createWalletClient({
* account,
* chain: polygonMumbai,
* transport: http(),
* });
*
* const smartAccount = await createSmartAccountClient({ signer, bundlerUrl, biconomyPaymasterApiKey }); // Retrieve bundler url from dasboard
* const tokens = await smartAccount.getSupportedTokens();
*
* // [
* // {
* // symbol: "USDC",
* // tokenAddress: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
* // decimal: 6,
* // logoUrl: "https://assets.coingecko.com/coins/images/279/large/usd-coin.png?1595353707",
* // premiumPercentage: 0.1,
* // }
* // ]
*
*/
public async getSupportedTokens(): Promise<SupportedToken[]> {
const feeQuotesResponse = await this.getTokenFees(
{
data: "0x",
value: BigInt(0),
to: await this.getAccountAddress(),
},
{
paymasterServiceData: { mode: PaymasterMode.ERC20 },
},
);
return (feeQuotesResponse?.feeQuotes ?? []).map(({ maxGasFee: _, maxGasFeeUSD: __, validUntil: ___, usdPayment: ____, ...rest }) => rest);
}

/**
*
* @param userOp
Expand Down
2 changes: 2 additions & 0 deletions packages/account/src/utils/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,5 @@ export type ValueOrData = RequireAtLeastOne<
export type Transaction = {
to: string;
} & ValueOrData;

export type SupportedToken = Omit<PaymasterFeeQuote, "maxGasFeeUSD" | "usdPayment" | "maxGasFee" | "validUntil">;
23 changes: 23 additions & 0 deletions packages/account/tests/account.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,29 @@ describe("Account Tests", () => {
expect(ecdsaOwnershipModule).toBe(smartAccount.activeValidationModule.getAddress());
});

it("should get supported tokens from the paymaster", async () => {
const {
whale: { viemWallet: signer },
bundlerUrl,
biconomyPaymasterApiKey,
} = mumbai;

const smartAccount = await createSmartAccountClient({
signer,
biconomyPaymasterApiKey,
bundlerUrl,
});

const tokens = await smartAccount.getSupportedTokens();

expect(tokens.length).toBeGreaterThan(0);
expect(tokens[0]).toHaveProperty("tokenAddress");
expect(tokens[0]).toHaveProperty("symbol");
expect(tokens[0]).toHaveProperty("decimal");
expect(tokens[0]).toHaveProperty("premiumPercentage");
expect(tokens[0]).toHaveProperty("logoUrl");
}, 60000);

it("should fetch balances for smartAccount", async () => {
const usdt = "0xda5289fcaaf71d52a80a254da614a192b693e977";
const {
Expand Down
1 change: 1 addition & 0 deletions packages/paymaster/src/utils/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export type PaymasterFeeQuote = {
/** maxGasFee: in dollars */
maxGasFeeUSD?: number;
usdPayment?: number;
/** The premium paid on the token */
premiumPercentage: number;
/** validUntil: Unix timestamp */
validUntil?: number;
Expand Down

0 comments on commit 6d2fb27

Please sign in to comment.