Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions packages/blue-sdk-viem/contracts/GetToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,31 @@ contract GetToken {

if (isWstEth) res.stEthPerWstEth = IWstEth(address(token)).stEthPerToken();

try IERC20Permit(address(token)).eip712Domain() returns (Eip5267Domain memory eip5267Domain) {
// Work around a Solidity via-IR decoding regression hit by valid EIP-5267 domains
// such as Treehouse ETH (tETH) on mainnet. Decoding the raw returndata locally avoids
// the deployless helper revert while preserving the same returned shape.
(bool success, bytes memory returnData) = address(token).staticcall(abi.encodeCall(IERC20Permit.eip712Domain, ()));
if (success) {
(
bytes1 fields,
string memory name,
string memory version,
uint256 chainId,
address verifyingContract,
bytes32 salt,
uint256[] memory extensions
) = abi.decode(returnData, (bytes1, string, string, uint256, address, bytes32, uint256[]));

res.hasEip5267Domain = true;
res.eip5267Domain = eip5267Domain;
} catch {}
res.eip5267Domain = Eip5267Domain({
fields: fields,
name: name,
version: version,
chainId: chainId,
verifyingContract: verifyingContract,
salt: salt,
extensions: extensions
});
}
}
}
2 changes: 1 addition & 1 deletion packages/blue-sdk-viem/src/queries/GetToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@ export const abi = [
] as const;

export const code =
"0x60808060405234601557610635908161001a8239f35b5f80fdfe6080806040526004361015610012575f80fd5b5f3560e01c63287861f914610025575f80fd5b346103fb5760403660031901126103fb576004356001600160a01b03811691908290036103fb576024359182151583036103fb57610100820182811067ffffffffffffffff8211176103ff576040525f825260208201905f8252604083016060815260608401905f825260808501906060825260a08601945f865260c08701946040516100b181610542565b5f815260606020820152606060408201525f60608201525f60808201525f60a0820152606060c0820152865260e08801985f8a526040516306fdde0360e01b81525f81600481865afa5f9181610502575b506104f6575b506040516395d89b4160e01b81525f81600481865afa5f91816104d2575b506104c6575b5060405163313ce56760e01b8152602081600481865afa5f9181610488575b5061047d575b50610413575b5f600491604051928380926342580cb760e11b82525afa5f918161029b575b50916101ce959493916101b39361028f575b506040519860208a525160208a0152511515604089015251610100606089015261012088019061051e565b91511515608087015251858203601f190160a087015261051e565b915160c08401525192601f198383030160e084015260ff60f81b845116825260c061021d61020b602087015160e0602087015260e086019061051e565b6040870151858203604087015261051e565b946060810151606085015260018060a01b03608082015116608085015260a081015160a085015201519160c08186039101526020808351958681520192015f945b8086106102775750508293505115156101008301520390f35b9092602080600192865181520194019501949061025e565b60018b5287525f610188565b9091503d805f833e6102ad818361055e565b8101906020818303126103fb5780519067ffffffffffffffff82116103fb57019060e0828203126103fb57604051916102e583610542565b80516001600160f81b0319811681036103fb578352602081015167ffffffffffffffff81116103fb578261031a918301610580565b6020840152604081015167ffffffffffffffff81116103fb578261033f918301610580565b60408401526060818101519084015260808101516001600160a01b03811681036103fb57608084015260a081015160a084015260c08101519067ffffffffffffffff82116103fb57019080601f830112156103fb5781519167ffffffffffffffff83116103ff578260051b90604051936103bc602084018661055e565b84526020808501928201019283116103fb57602001905b8282106103eb5750505060c0820152906101b3610176565b81518152602091820191016103d3565b5f80fd5b634e487b7160e01b5f52604160045260245ffd5b6040516301afd7c160e11b8152602081600481855afa908115610472575f9161043f575b508752610157565b90506020813d60201161046a575b8161045a6020938361055e565b810103126103fb57516004610437565b3d915061044d565b6040513d5f823e3d90fd5b60ff1689525f610151565b9091506020813d6020116104be575b816104a46020938361055e565b810103126103fb575160ff811681036103fb57905f61014b565b3d9150610497565b6001845284525f61012c565b6104ef9192503d805f833e6104e7818361055e565b8101906105d6565b905f610126565b6001875285525f610108565b6105179192503d805f833e6104e7818361055e565b905f610102565b805180835260209291819084018484015e5f828201840152601f01601f1916010190565b60e0810190811067ffffffffffffffff8211176103ff57604052565b90601f8019910116810190811067ffffffffffffffff8211176103ff57604052565b81601f820112156103fb5780519067ffffffffffffffff82116103ff57604051926105b5601f8401601f19166020018561055e565b828452602083830101116103fb57815f9260208093018386015e8301015290565b906020828203126103fb57815167ffffffffffffffff81116103fb576105fc9201610580565b9056fea2646970667358221220389a149f2e0bd6ff1dee73cba200ac22d6611d304a114c8d87d33392f9d891a264736f6c634300081b0033";
"0x60808060405234601557610678908161001a8239f35b5f80fdfe60806040526004361015610011575f80fd5b5f3560e01c63287861f914610024575f80fd5b34610423576040366003190112610423576004356001600160a01b038116908190036104235760243580151581036104235761018060408190525f608081905260a0819052606060c081905260e0829052610100526101205261008681610579565b5f815260606020820152606060408201525f60608201525f60808201525f60a0820152606060c082015260c0608001525f60e0608001526040516306fdde0360e01b81525f81600481865afa5f9181610539575b5061052a575b506040516395d89b4160e01b81525f81600481865afa5f9181610506575b506104f8575b5060405163313ce56760e01b8152602081600481865afa5f91816104ba575b506104ae575b50610443575b5f809160405160208101906342580cb760e11b825260048152610153602482610595565b51915afa3d1561043b573d90610168826105b7565b916101766040519384610595565b82523d5f602084013e5b6102ac575b5060405160208152608051602082015260206080015115156040820152806101e16101c26040608001516101006060850152610120840190610555565b60e0511515608084015261010051838203601f190160a0850152610555565b60a06080015160c083015260c060800151601f198383030160e084015260ff60f81b815116825260c0610238610226602084015160e0602087015260e0860190610555565b60408401518582036040870152610555565b916060810151606085015260018060a01b03608082015116608085015260a081015160a085015201519160c0818303910152602080835192838152019201905f5b818110610293575050610160511515610100840152500390f35b8251845285945060209384019390920191600101610279565b8051810160e08260208301920312610423576020820151916001600160f81b03198316830361042357604081015167ffffffffffffffff8111610423578260206102f8928401016105d3565b606082015167ffffffffffffffff81116104235783602061031b928501016105d3565b608083015160a0840151929091906001600160a01b03841684036104235760c08501519460e08101519667ffffffffffffffff88116104235780603f89840101121561042357602088830101519767ffffffffffffffff8911610427578860051b906040519961038e602084018c610595565b8a5260208a0192604085830184010111610423579091604082850101925b6040858401820101841061041057505060016101605250506040519790506103d388610579565b6001600160f81b03191687526020870152604086015260608501526001600160a01b0316608084015260a083015260c0820152610140525f610185565b83518252602093840193909101906103ac565b5f80fd5b634e487b7160e01b5f52604160045260245ffd5b606090610180565b6040516301afd7c160e11b8152602081600481855afa9081156104a3575f91610471575b506101205261012f565b90506020813d60201161049b575b8161048c60209383610595565b8101031261042357515f610467565b3d915061047f565b6040513d5f823e3d90fd5b60ff166080525f610129565b9091506020813d6020116104f0575b816104d660209383610595565b81010312610423575160ff8116810361042357905f610123565b3d91506104c9565b600160a05260c0525f610104565b6105239192503d805f833e61051b8183610595565b810190610619565b905f6100fe565b600160e052610100525f6100e0565b61054e9192503d805f833e61051b8183610595565b905f6100da565b805180835260209291819084018484015e5f828201840152601f01601f1916010190565b60e0810190811067ffffffffffffffff82111761042757604052565b90601f8019910116810190811067ffffffffffffffff82111761042757604052565b67ffffffffffffffff811161042757601f01601f191660200190565b81601f82011215610423578051906105ea826105b7565b926105f86040519485610595565b8284526020838301011161042357815f9260208093018386015e8301015290565b9060208282031261042357815167ffffffffffffffff81116104235761063f92016105d3565b9056fea2646970667358221220b4e8811f0313f73bfe153737511a5605bbae33eca82a29b5c3eab7c3f0d01f8264736f6c634300081b0033";
38 changes: 35 additions & 3 deletions packages/blue-sdk-viem/test/Token.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect } from "vitest";
import { test } from "./setup.js";
import { test, testTreehouseEth } from "./setup.js";

import {
ChainId,
Expand Down Expand Up @@ -65,7 +65,9 @@ describe("augment/Token", () => {
expect(value).toStrictEqual(expectedData);
});

test("should fetch token data with eip5267Domain", async ({ client }) => {
test("should fetch token data with eip5267Domain using deployless reads", async ({
client,
}) => {
const steakUSDC = "0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB";
const expectedData = new Token({
address: steakUSDC,
Expand All @@ -83,8 +85,38 @@ describe("augment/Token", () => {
}),
});

const value = await Token.fetch(expectedData.address, client);
const value = await Token.fetch(expectedData.address, client, {
deployless: "force",
});

expect(value).toStrictEqual(expectedData);
});

testTreehouseEth(
"should fetch Treehouse ETH data with eip5267Domain using deployless reads",
async ({ client }) => {
const treehouseEth = "0xD11c452fc99cF405034ee446803b6F6c1F6d5ED8";
const expectedData = new Token({
address: treehouseEth,
decimals: 18,
symbol: "tETH",
name: "Treehouse ETH",
eip5267Domain: new Eip5267Domain({
fields: "0x0f",
name: "Treehouse ETH",
version: "1",
chainId: 1n,
verifyingContract: treehouseEth,
salt: zeroHash,
extensions: [],
}),
});

const value = await Token.fetch(expectedData.address, client, {
deployless: "force",
});

expect(value).toStrictEqual(expectedData);
},
);
});
8 changes: 8 additions & 0 deletions packages/blue-sdk-viem/test/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ export const test2 = createViemTest(mainnet, {
forkBlockNumber: 21_595_000,
});

/**
* This test will run on `mainnet` forked at block `24,671,815`.
*/
export const testTreehouseEth = createViemTest(mainnet, {
forkUrl: process.env.MAINNET_RPC_URL,
forkBlockNumber: 24_671_815,
});

/**
* This test will run on `mainnet` forked at block `21,950,00`.
*/
Expand Down
Loading