Skip to content

Commit

Permalink
Merge pull request #417 from balancer/viem-client-type
Browse files Browse the repository at this point in the history
Export PublicWalletClient
  • Loading branch information
agualis authored Sep 24, 2024
2 parents 1d6af52 + 2d5928a commit 0e0f81d
Show file tree
Hide file tree
Showing 19 changed files with 87 additions and 98 deletions.
5 changes: 5 additions & 0 deletions .changeset/selfish-baboons-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@balancer/sdk": patch
---

Exposes PublicWalletClient type
11 changes: 8 additions & 3 deletions src/entities/permit2Helper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import {
Permit2Batch,
PermitDetails,
} from './allowanceTransfer';
import { BALANCER_BATCH_ROUTER, BALANCER_ROUTER, PERMIT2 } from '@/utils';
import {
BALANCER_BATCH_ROUTER,
BALANCER_ROUTER,
PERMIT2,
PublicWalletClient,
} from '@/utils';
import {
MaxAllowanceExpiration,
MaxAllowanceTransferAmount,
Expand Down Expand Up @@ -33,7 +38,7 @@ export type Permit2 = {
export class Permit2Helper {
static async signAddLiquidityApproval(
input: AddLiquidityBaseBuildCallInput & {
client: Client & WalletActions & PublicActions;
client: PublicWalletClient;
owner: Address;
nonces?: number[];
expirations?: number[];
Expand Down Expand Up @@ -71,7 +76,7 @@ export class Permit2Helper {

static async signSwapApproval(
input: SwapBuildCallInputBase & {
client: Client & WalletActions & PublicActions;
client: PublicWalletClient;
owner: Address;
nonce?: number;
expiration?: number;
Expand Down
5 changes: 2 additions & 3 deletions src/entities/permitHelper/helper.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Client, PublicActions, WalletActions } from 'viem';

import { Address } from '@/types';
import { PublicWalletClient } from '@/utils';

export const getNonce = async (
client: Client & WalletActions & PublicActions,
client: PublicWalletClient,
token: Address,
owner: Address,
) => {
Expand Down
13 changes: 4 additions & 9 deletions src/entities/permitHelper/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Client, PublicActions, WalletActions } from 'viem';

import { weightedPoolAbi_V3 } from '@/abi';
import { Hex } from '@/types';
import { BALANCER_ROUTER, MAX_UINT256 } from '@/utils';
import { BALANCER_ROUTER, MAX_UINT256, PublicWalletClient } from '@/utils';
import { getNonce } from './helper';
import { RemoveLiquidityBaseBuildCallInput } from '../removeLiquidity/types';
import { getAmountsCall } from '../removeLiquidity/helper';
Expand Down Expand Up @@ -30,7 +28,7 @@ export type Permit = {
export class PermitHelper {
static signRemoveLiquidityApproval = async (
input: RemoveLiquidityBaseBuildCallInput & {
client: Client & WalletActions & PublicActions;
client: PublicWalletClient;
owner: Hex;
nonce?: bigint;
deadline?: bigint;
Expand Down Expand Up @@ -63,7 +61,7 @@ export class PermitHelper {
* @param { Client & WalletActions & PublicActions } client - Wallet client to invoke for signing the permit message
*/
const signPermit = async (
client: Client & WalletActions & PublicActions,
client: PublicWalletClient,
token: Hex,
owner: Hex,
spender: Hex,
Expand Down Expand Up @@ -111,10 +109,7 @@ const signPermit = async (
return { permitApproval, permitSignature };
};

const getDomain = async (
client: Client & WalletActions & PublicActions,
token: Hex,
) => {
const getDomain = async (client: PublicWalletClient, token: Hex) => {
const [, name, version, chainId, verifyingContract, , ,] =
await client.readContract({
abi: weightedPoolAbi_V3,
Expand Down
24 changes: 8 additions & 16 deletions src/entities/relayer/authorization.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
import {
Client,
concat,
pad,
parseSignature,
PublicActions,
toHex,
WalletActions,
} from 'viem';
import { MAX_UINT256, VAULT } from '../../utils';
import { concat, pad, parseSignature, toHex } from 'viem';
import { MAX_UINT256, VAULT, PublicWalletClient } from '../../utils';
import { Address, Hex } from '../../types';
import { vaultV2Abi } from '../../abi';

Expand Down Expand Up @@ -47,7 +39,7 @@ export class RelayerAuthorization {
};

static signJoinAuthorization = (
client: Client & WalletActions & PublicActions,
client: PublicWalletClient,
signerAddress: Address,
allowedSender: Address,
allowedCalldata: Hex,
Expand All @@ -65,7 +57,7 @@ export class RelayerAuthorization {
);

static signExitAuthorization = (
client: Client & WalletActions & PublicActions,
client: PublicWalletClient,
signerAddress: Address,
allowedSender: Address,
allowedCalldata: Hex,
Expand All @@ -83,7 +75,7 @@ export class RelayerAuthorization {
);

static signSwapAuthorization = (
client: Client & WalletActions & PublicActions,
client: PublicWalletClient,
signerAddress: Address,
allowedSender: Address,
allowedCalldata: Hex,
Expand All @@ -101,7 +93,7 @@ export class RelayerAuthorization {
);

static signBatchSwapAuthorization = (
client: Client & WalletActions & PublicActions,
client: PublicWalletClient,
signerAddress: Address,
allowedSender: Address,
allowedCalldata: Hex,
Expand All @@ -119,7 +111,7 @@ export class RelayerAuthorization {
);

static signSetRelayerApprovalAuthorization = (
client: Client & WalletActions & PublicActions,
client: PublicWalletClient,
signerAddress: Address,
allowedSender: Address,
allowedCalldata: Hex,
Expand All @@ -138,7 +130,7 @@ export class RelayerAuthorization {

static signAuthorizationFor = async (
type: RelayerAction,
client: Client & WalletActions & PublicActions,
client: PublicWalletClient,
signerAddress: Address,
allowedSender: Address,
allowedCalldata: Hex,
Expand Down
7 changes: 2 additions & 5 deletions src/entities/relayer/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import {
Client,
concat,
encodeFunctionData,
hexToBigInt,
pad,
PublicActions,
slice,
toHex,
WalletActions,
} from 'viem';
import { Address, Hex } from '../../types';
import { batchRelayerLibraryAbi } from '../../abi/batchRelayerLibrary';
import { RelayerAuthorization } from './authorization';
import { vaultV2Abi } from '../../abi';
import { MAX_UINT256 } from '../../utils';
import { MAX_UINT256, PublicWalletClient } from '../../utils';

export class Relayer {
static CHAINED_REFERENCE_TEMP_PREFIX = '0xba10' as Hex; // Temporary reference: it is deleted after a read.
Expand Down Expand Up @@ -57,7 +54,7 @@ export class Relayer {
static signRelayerApproval = async (
relayerAddress: Address,
signerAddress: Address,
client: Client & WalletActions & PublicActions,
client: PublicWalletClient,
): Promise<Hex> => {
const approval = encodeFunctionData({
abi: vaultV2Abi,
Expand Down
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from './math';
export * from './pool';
export * from './poolTypeMapper';
export * from './sortByAddress';
export * from './types';
3 changes: 3 additions & 0 deletions src/utils/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { PublicActions, WalletClient } from 'viem';

export type PublicWalletClient = WalletClient & PublicActions;
6 changes: 2 additions & 4 deletions test/entities/swaps/v2/swapV2.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import {
parseEther,
publicActions,
walletActions,
Client,
PublicActions,
TestActions,
WalletActions,
} from 'viem';
import {
CHAINS,
Expand All @@ -23,6 +20,7 @@ import {
ExactOutQueryOutput,
VAULT,
Path,
PublicWalletClient,
} from '@/index';

import { ANVIL_NETWORKS, startFork } from 'test/anvil/anvil-global-setup';
Expand All @@ -44,7 +42,7 @@ const WETH = TOKENS[chainId].WETH;
const vault = VAULT[chainId];

describe('SwapV2', () => {
let client: Client & PublicActions & TestActions & WalletActions;
let client: PublicWalletClient & TestActions;
let testAddress: Address;
const pathBalWeth: Path = {
protocolVersion: 2,
Expand Down
6 changes: 2 additions & 4 deletions test/entities/swaps/v3/swapV3.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import {
parseEther,
publicActions,
walletActions,
Client,
PublicActions,
TestActions,
WalletActions,
Hex,
} from 'viem';
import {
Expand All @@ -25,6 +22,7 @@ import {
BALANCER_ROUTER,
BALANCER_BATCH_ROUTER,
PERMIT2,
PublicWalletClient,
} from '@/index';
import { Path } from '@/entities/swap/paths/types';

Expand Down Expand Up @@ -54,7 +52,7 @@ const stataUSDC = TOKENS[chainId].stataUSDC;
const stataDAI = TOKENS[chainId].stataDAI;

describe('SwapV3', () => {
let client: Client & PublicActions & TestActions & WalletActions;
let client: PublicWalletClient & TestActions;
let testAddress: Address;
let rpcUrl: string;
let snapshot: Hex;
Expand Down
24 changes: 12 additions & 12 deletions test/lib/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
PublicActions,
TestActions,
TransactionReceipt,
WalletActions,
concat,
encodeAbiParameters,
hexToBigInt,
Expand All @@ -26,6 +25,7 @@ import {
PERMIT2,
BALANCER_ROUTER,
BALANCER_BATCH_ROUTER,
PublicWalletClient,
} from '@/utils';

export type TxOutput = {
Expand All @@ -35,7 +35,7 @@ export type TxOutput = {
};

export const hasApprovedToken = async (
client: Client & PublicActions & WalletActions,
client: PublicWalletClient,
account: Address,
token: Address,
spender: Address,
Expand All @@ -53,7 +53,7 @@ export const hasApprovedToken = async (
};

export const hasApprovedTokenOnPermit2 = async (
client: Client & PublicActions & WalletActions,
client: PublicWalletClient,
account: Address,
token: Address,
spender: Address,
Expand All @@ -72,7 +72,7 @@ export const hasApprovedTokenOnPermit2 = async (
};

export const approveToken = async (
client: Client & PublicActions & WalletActions,
client: PublicWalletClient,
accountAddress: Address,
tokenAddress: Address,
protocolVersion: 2 | 3,
Expand Down Expand Up @@ -127,7 +127,7 @@ export const approveToken = async (
};

export const approveTokens = async (
client: Client & PublicActions & WalletActions,
client: PublicWalletClient,
accountAddress: Address,
tokens: Address[],
protocolVersion: 2 | 3,
Expand All @@ -146,7 +146,7 @@ export const approveTokens = async (
};

export const approveSpenderOnTokens = async (
client: Client & PublicActions & WalletActions,
client: PublicWalletClient,
accountAddress: Address,
tokens: Address[],
spender: Address,
Expand All @@ -167,7 +167,7 @@ export const approveSpenderOnTokens = async (
};

export const approveSpenderOnToken = async (
client: Client & PublicActions & WalletActions,
client: PublicWalletClient,
account: Address,
token: Address,
spender: Address,
Expand Down Expand Up @@ -205,7 +205,7 @@ export const approveSpenderOnToken = async (
};

export const approveSpenderOnPermit2 = async (
client: Client & PublicActions & WalletActions,
client: PublicWalletClient,
account: Address,
token: Address,
spender: Address,
Expand Down Expand Up @@ -287,7 +287,7 @@ export const getBalances = async (
*/
export async function sendTransactionGetBalances(
tokensForBalanceCheck: Address[],
client: Client & PublicActions & TestActions & WalletActions,
client: PublicWalletClient & TestActions,
clientAddress: Address,
to: Address,
data: Address,
Expand Down Expand Up @@ -488,7 +488,7 @@ export async function findTokenBalanceSlot(
* @param protocolVersion Balancer vault version
*/
export const forkSetup = async (
client: Client & PublicActions & TestActions & WalletActions,
client: PublicWalletClient & TestActions,
accountAddress: Address,
tokens: Address[],
slots: number[] | undefined,
Expand Down Expand Up @@ -530,7 +530,7 @@ export const forkSetup = async (
* @param isVyperMapping Whether the storage uses Vyper or Solidity mapping
*/
export const forkSetupCowAmm = async (
client: Client & PublicActions & TestActions & WalletActions,
client: PublicWalletClient & TestActions,
accountAddress: Address,
tokens: Address[],
slots: number[] | undefined,
Expand Down Expand Up @@ -564,7 +564,7 @@ export const forkSetupCowAmm = async (
export const getSlots = async (
slots: number[] | undefined,
tokens: Address[],
client: Client & PublicActions & TestActions & WalletActions,
client: PublicWalletClient & TestActions,
accountAddress: Address,
isVyperMapping: boolean[],
): Promise<number[]> => {
Expand Down
Loading

0 comments on commit 0e0f81d

Please sign in to comment.