Skip to content

Commit 2ea58d0

Browse files
committed
feat(fetcher): adapt to new Holding class
1 parent 7094c49 commit 2ea58d0

File tree

17 files changed

+373
-1101
lines changed

17 files changed

+373
-1101
lines changed

packages/blue-sdk-ethers/src/fetch/Holding.ts

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
ERC20_ALLOWANCE_RECIPIENTS,
1515
Holding,
1616
NATIVE_ADDRESS,
17-
PERMIT2_ALLOWANCE_RECIPIENTS,
1817
getChainAddresses,
1918
permissionedBackedTokens,
2019
permissionedWrapperTokens,
@@ -41,16 +40,11 @@ export async function fetchHolding(
4140
erc20Allowances: fromEntries(
4241
ERC20_ALLOWANCE_RECIPIENTS.map((label) => [label, MaxUint256]),
4342
),
44-
permit2Allowances: fromEntries(
45-
PERMIT2_ALLOWANCE_RECIPIENTS.map((label) => [
46-
label,
47-
{
48-
amount: 0n,
49-
expiration: 0n,
50-
nonce: 0n,
51-
},
52-
]),
53-
),
43+
permit2BundlerAllowance: {
44+
amount: 0n,
45+
expiration: 0n,
46+
nonce: 0n,
47+
},
5448
balance: await runner.provider.getBalance(user, overrides.blockTag),
5549
});
5650

@@ -61,7 +55,7 @@ export async function fetchHolding(
6155
const [
6256
balance,
6357
erc20Allowances,
64-
permit2Allowances,
58+
permit2BundlerAllowance,
6559
erc2612Nonce,
6660
whitelistControllerAggregator,
6761
hasErc20WrapperPermission,
@@ -76,21 +70,7 @@ export async function fetchHolding(
7670
] as const,
7771
),
7872
),
79-
Promise.all(
80-
PERMIT2_ALLOWANCE_RECIPIENTS.map(
81-
async (label) =>
82-
[
83-
label,
84-
await permit2
85-
.allowance(user, token, chainAddresses[label], overrides)
86-
.then(({ amount, nonce, expiration }) => ({
87-
amount,
88-
expiration,
89-
nonce,
90-
})),
91-
] as const,
92-
),
93-
),
73+
permit2.allowance(user, token, chainAddresses.bundler, overrides),
9474
erc2612.nonces(user, overrides).catch(() => undefined),
9575
permissionedBackedTokens[chainId].has(token)
9676
? WrappedBackedToken__factory.connect(
@@ -107,7 +87,7 @@ export async function fetchHolding(
10787
user,
10888
token,
10989
erc20Allowances: fromEntries(erc20Allowances),
110-
permit2Allowances: fromEntries(permit2Allowances),
90+
permit2BundlerAllowance,
11191
erc2612Nonce,
11292
balance,
11393
canTransfer: hasErc20WrapperPermission,

packages/blue-sdk-ethers/test/e2e/Holding.test.ts

Lines changed: 16 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,10 @@ describe("augment/Holding", async () => {
2424
permit2: 3n,
2525
bundler: 2n,
2626
},
27-
permit2Allowances: {
28-
morpho: {
29-
amount: 4n,
30-
expiration: MathLib.MAX_UINT_48 - 1n,
31-
nonce: 0n,
32-
},
33-
bundler: {
34-
amount: 7n,
35-
expiration: MathLib.MAX_UINT_48 - 2n,
36-
nonce: 0n,
37-
},
27+
permit2BundlerAllowance: {
28+
amount: 7n,
29+
expiration: MathLib.MAX_UINT_48 - 2n,
30+
nonce: 0n,
3831
},
3932
balance: 10n * MathLib.WAD,
4033
canTransfer: true,
@@ -56,26 +49,15 @@ describe("augment/Holding", async () => {
5649
address: wNative,
5750
args: [permit2, expectedData.erc20Allowances.permit2],
5851
});
59-
await client.writeContract({
60-
address: permit2,
61-
abi: permit2Abi,
62-
functionName: "approve",
63-
args: [
64-
wNative,
65-
morpho,
66-
expectedData.permit2Allowances.morpho.amount,
67-
Number(expectedData.permit2Allowances.morpho.expiration),
68-
],
69-
});
7052
await client.writeContract({
7153
address: permit2,
7254
abi: permit2Abi,
7355
functionName: "approve",
7456
args: [
7557
wNative,
7658
bundler,
77-
expectedData.permit2Allowances.bundler.amount,
78-
Number(expectedData.permit2Allowances.bundler.expiration),
59+
expectedData.permit2BundlerAllowance.amount,
60+
Number(expectedData.permit2BundlerAllowance.expiration),
7961
],
8062
});
8163

@@ -95,17 +77,10 @@ describe("augment/Holding", async () => {
9577
permit2: maxUint256,
9678
bundler: maxUint256,
9779
},
98-
permit2Allowances: {
99-
morpho: {
100-
amount: 0n,
101-
expiration: 0n,
102-
nonce: 0n,
103-
},
104-
bundler: {
105-
amount: 0n,
106-
expiration: 0n,
107-
nonce: 0n,
108-
},
80+
permit2BundlerAllowance: {
81+
amount: 0n,
82+
expiration: 0n,
83+
nonce: 0n,
10984
},
11085
balance: 10000000000000000000000n,
11186
canTransfer: undefined,
@@ -125,17 +100,10 @@ describe("augment/Holding", async () => {
125100
permit2: 5n,
126101
bundler: 4n,
127102
},
128-
permit2Allowances: {
129-
morpho: {
130-
amount: 9n,
131-
expiration: MathLib.MAX_UINT_48 - 2n,
132-
nonce: 0n,
133-
},
134-
bundler: {
135-
amount: 8n,
136-
expiration: MathLib.MAX_UINT_48 - 7n,
137-
nonce: 0n,
138-
},
103+
permit2BundlerAllowance: {
104+
amount: 8n,
105+
expiration: MathLib.MAX_UINT_48 - 7n,
106+
nonce: 0n,
139107
},
140108
balance: 2853958n,
141109
erc2612Nonce: 0n,
@@ -158,26 +126,15 @@ describe("augment/Holding", async () => {
158126
address: wbC3M,
159127
args: [permit2, expectedData.erc20Allowances.permit2],
160128
});
161-
await client.writeContract({
162-
address: permit2,
163-
abi: permit2Abi,
164-
functionName: "approve",
165-
args: [
166-
wbC3M,
167-
morpho,
168-
expectedData.permit2Allowances.morpho.amount,
169-
Number(expectedData.permit2Allowances.morpho.expiration),
170-
],
171-
});
172129
await client.writeContract({
173130
address: permit2,
174131
abi: permit2Abi,
175132
functionName: "approve",
176133
args: [
177134
wbC3M,
178135
bundler,
179-
expectedData.permit2Allowances.bundler.amount,
180-
Number(expectedData.permit2Allowances.bundler.expiration),
136+
expectedData.permit2BundlerAllowance.amount,
137+
Number(expectedData.permit2BundlerAllowance.expiration),
181138
],
182139
});
183140

packages/blue-sdk-viem/contracts/GetHolding.sol

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ struct ERC20Allowances {
1313
uint256 bundler;
1414
}
1515

16-
struct Permit2Allowances {
17-
Permit2Allowance morpho;
18-
Permit2Allowance bundler;
19-
}
20-
2116
enum OptionalBoolean {
2217
Undefined,
2318
False,
@@ -27,7 +22,7 @@ enum OptionalBoolean {
2722
struct HoldingResponse {
2823
uint256 balance;
2924
ERC20Allowances erc20Allowances;
30-
Permit2Allowances permit2Allowances;
25+
Permit2Allowance permit2BundlerAllowance;
3126
bool isErc2612;
3227
uint256 erc2612Nonce;
3328
OptionalBoolean canTransfer;
@@ -49,10 +44,7 @@ contract GetHolding {
4944
permit2: token.allowance(account, address(permit2)),
5045
bundler: token.allowance(account, bundler)
5146
});
52-
res.permit2Allowances = Permit2Allowances({
53-
morpho: permit2.allowance(account, address(token), morpho),
54-
bundler: permit2.allowance(account, address(token), bundler)
55-
});
47+
res.permit2BundlerAllowance = permit2.allowance(account, address(token), bundler);
5648

5749
try token.nonces(account) returns (uint256 nonce) {
5850
res.isErc2612 = true;

packages/blue-sdk-viem/src/fetch/Holding.ts

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
ERC20_ALLOWANCE_RECIPIENTS,
44
Holding,
55
NATIVE_ADDRESS,
6-
PERMIT2_ALLOWANCE_RECIPIENTS,
76
addresses,
87
getChainAddresses,
98
permissionedBackedTokens,
@@ -42,16 +41,11 @@ export async function fetchHolding(
4241
erc20Allowances: fromEntries(
4342
ERC20_ALLOWANCE_RECIPIENTS.map((label) => [label, maxUint256]),
4443
),
45-
permit2Allowances: fromEntries(
46-
PERMIT2_ALLOWANCE_RECIPIENTS.map((label) => [
47-
label,
48-
{
49-
amount: 0n,
50-
expiration: 0n,
51-
nonce: 0n,
52-
},
53-
]),
54-
),
44+
permit2BundlerAllowance: {
45+
amount: 0n,
46+
expiration: 0n,
47+
nonce: 0n,
48+
},
5549
balance: await getBalance(client, {
5650
// biome-ignore lint/suspicious/noExplicitAny: flattened union type
5751
...(parameters as any),
@@ -64,8 +58,11 @@ export async function fetchHolding(
6458
try {
6559
const {
6660
balance,
67-
erc20Allowances,
68-
permit2Allowances,
61+
erc20Allowances: {
62+
bundler: generalAdapter1Erc20Allowance,
63+
...erc20Allowances
64+
},
65+
permit2BundlerAllowance,
6966
isErc2612,
7067
erc2612Nonce,
7168
canTransfer,
@@ -88,8 +85,11 @@ export async function fetchHolding(
8885
return new Holding({
8986
user,
9087
token,
91-
erc20Allowances,
92-
permit2Allowances,
88+
erc20Allowances: {
89+
bundler: generalAdapter1Erc20Allowance,
90+
...erc20Allowances,
91+
},
92+
permit2BundlerAllowance,
9393
erc2612Nonce: isErc2612 ? erc2612Nonce : undefined,
9494
balance,
9595
canTransfer: optionalBoolean[canTransfer],
@@ -104,7 +104,7 @@ export async function fetchHolding(
104104
const [
105105
balance,
106106
erc20Allowances,
107-
permit2Allowances,
107+
permit2BundlerAllowance,
108108
erc2612Nonce,
109109
whitelistControllerAggregator,
110110
hasErc20WrapperPermission,
@@ -131,25 +131,17 @@ export async function fetchHolding(
131131
] as const,
132132
),
133133
),
134-
Promise.all(
135-
PERMIT2_ALLOWANCE_RECIPIENTS.map(
136-
async (label) =>
137-
[
138-
label,
139-
await readContract(client, {
140-
...parameters,
141-
abi: permit2Abi,
142-
address: chainAddresses.permit2,
143-
functionName: "allowance",
144-
args: [user, token, chainAddresses[label]],
145-
}).then(([amount, expiration, nonce]) => ({
146-
amount,
147-
expiration: BigInt(expiration),
148-
nonce: BigInt(nonce),
149-
})),
150-
] as const,
151-
),
152-
),
134+
readContract(client, {
135+
...parameters,
136+
abi: permit2Abi,
137+
address: chainAddresses.permit2,
138+
functionName: "allowance",
139+
args: [user, token, chainAddresses.bundler],
140+
}).then(([amount, expiration, nonce]) => ({
141+
amount,
142+
expiration: BigInt(expiration),
143+
nonce: BigInt(nonce),
144+
})),
153145
readContract(client, {
154146
...parameters,
155147
abi: erc2612Abi,
@@ -178,7 +170,7 @@ export async function fetchHolding(
178170
user,
179171
token,
180172
erc20Allowances: fromEntries(erc20Allowances),
181-
permit2Allowances: fromEntries(permit2Allowances),
173+
permit2BundlerAllowance,
182174
erc2612Nonce,
183175
balance,
184176
canTransfer: hasErc20WrapperPermission,

0 commit comments

Comments
 (0)