Skip to content

Commit

Permalink
Merge pull request #578 from balancer/fix-permit-helper-owner
Browse files Browse the repository at this point in the history
Fix PermitHelper owner to support viem Account as input
  • Loading branch information
brunoguerios authored Jan 29, 2025
2 parents 38e93f5 + da7dc97 commit bcd8652
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .changeset/fluffy-brooms-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@balancer/sdk": patch
---

Fix PermitHelper owner to support viem Account as input
41 changes: 21 additions & 20 deletions src/entities/permitHelper/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Account, Address, Hex } from 'viem';

import { weightedPoolAbi_V3 } from '@/abi';
import { Hex } from '@/types';
import {
BALANCER_COMPOSITE_LIQUIDITY_ROUTER,
BALANCER_ROUTER,
Expand Down Expand Up @@ -36,19 +37,17 @@ export class PermitHelper {
static signRemoveLiquidityApproval = async (
input: RemoveLiquidityBaseBuildCallInput & {
client: PublicWalletClient;
owner: Hex;
owner: Hex | Account;
nonce?: bigint;
deadline?: bigint;
},
): Promise<Permit> => {
const amounts = getAmountsCall(input);
const _owner =
typeof input.owner === 'string' ? input.owner : input.owner.address;
const nonce =
input.nonce ??
(await getNonce(
input.client,
input.bptIn.token.address,
input.owner,
));
(await getNonce(input.client, input.bptIn.token.address, _owner));
const { permitApproval, permitSignature } = await signPermit(
input.client,
input.bptIn.token.address,
Expand All @@ -65,16 +64,18 @@ export class PermitHelper {
bptAmountIn: TokenAmount;
chainId: ChainId;
client: PublicWalletClient;
owner: Hex;
owner: Hex | Account;
nonce?: bigint;
deadline?: bigint;
}): Promise<Permit> => {
const _owner =
typeof input.owner === 'string' ? input.owner : input.owner.address;
const nonce =
input.nonce ??
(await getNonce(
input.client,
input.bptAmountIn.token.address,
input.owner,
_owner,
));
const { permitApproval, permitSignature } = await signPermit(
input.client,
Expand All @@ -91,19 +92,17 @@ export class PermitHelper {
static signRemoveLiquidityBoostedApproval = async (
input: RemoveLiquidityBaseBuildCallInput & {
client: PublicWalletClient;
owner: Hex;
owner: Hex | Account;
nonce?: bigint;
deadline?: bigint;
},
): Promise<Permit> => {
const amounts = getAmountsCall(input);
const _owner =
typeof input.owner === 'string' ? input.owner : input.owner.address;
const nonce =
input.nonce ??
(await getNonce(
input.client,
input.bptIn.token.address,
input.owner,
));
(await getNonce(input.client, input.bptIn.token.address, _owner));
const { permitApproval, permitSignature } = await signPermit(
input.client,
input.bptIn.token.address,
Expand All @@ -124,9 +123,9 @@ export class PermitHelper {
*/
const signPermit = async (
client: PublicWalletClient,
token: Hex,
owner: Hex,
spender: Hex,
token: Address,
owner: Address | Account,
spender: Address,
nonce: bigint,
amount = MAX_UINT256,
deadline = MAX_UINT256,
Expand All @@ -144,8 +143,10 @@ const signPermit = async (
],
};

const _owner = typeof owner === 'string' ? owner : owner.address;

const message = {
owner,
owner: _owner,
spender,
value: amount,
nonce,
Expand All @@ -162,7 +163,7 @@ const signPermit = async (
});
const permitApproval = {
token,
owner,
owner: _owner,
spender,
amount,
nonce,
Expand Down

0 comments on commit bcd8652

Please sign in to comment.