Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/bold-ram-dig.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@exactly/mobile": patch
---

♻️ flatten simulate-proposal api and batch contract reads
Comment thread
cruzdanilo marked this conversation as resolved.
5 changes: 5 additions & 0 deletions .changeset/tidy-geese-batch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@exactly/mobile": patch
---

♻️ replace proposal simulation with simulate blocks
11 changes: 9 additions & 2 deletions common/wagmi.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,12 @@ function chain(): Plugin {
content: `import { anvil, type Chain } from "viem/chains"
const chain = anvil as Chain
chain.rpcUrls.alchemy = chain.rpcUrls.default
chain.contracts = { multicall3: { address: "${optimism.contracts.multicall3.address}" } }
chain.blockExplorers = { default: { name: "Otterscan", url: "http://localhost:5100" } }
export default chain as Chain & { rpcUrls: { alchemy: { http: readonly [string] } } }`,
export default chain as Chain & {
contracts: { multicall3: { address: \`0x\${string}\` } }
rpcUrls: { alchemy: { http: readonly [string] } }
}`,
}),
};
}
Expand All @@ -185,7 +189,10 @@ export default chain as Chain & { rpcUrls: { alchemy: { http: readonly [string]
run: () => ({
content: `import { ${importName} } from "@account-kit/infra"
import { type Chain } from "viem/chains"
export default ${importName} as Chain & { rpcUrls: { alchemy: { http: readonly [string] } } }`,
export default ${importName} as Chain & {
contracts: { multicall3: { address: \`0x\${string}\` } }
rpcUrls: { alchemy: { http: readonly [string] } }
}`,
}),
Comment thread
cruzdanilo marked this conversation as resolved.
};
}
Expand Down
20 changes: 10 additions & 10 deletions contracts/.gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ExaAccountFactoryTest:testFuzz_createAccount_EOAOwners(uint256,address[63]) (runs: 256, μ: 5853309, ~: 5347535)
ExaAccountFactoryTest:test_deploy_deploysToSameAddress() (gas: 13989314)
ExaAccountFactoryTest:testFuzz_createAccount_EOAOwners(uint256,address[63]) (runs: 256, μ: 5857216, ~: 5360703)
ExaAccountFactoryTest:test_deploy_deploysToSameAddress() (gas: 14972464)
ExaPluginTest:testFork_claimAndVestEscrowedEXA_claimsAndVests() (gas: 38664724)
ExaPluginTest:testFork_collectCollateral_collects() (gas: 32167249)
ExaPluginTest:testFork_crossRepay_repays() (gas: 33988652)
Expand Down Expand Up @@ -212,14 +212,14 @@ IssuerCheckerTest:test_setPrevIssuerWindow_emits_PrevIssuerWindowSet() (gas: 526
IssuerCheckerTest:test_setPrevIssuerWindow_reverts_whenNotAdmin() (gas: 45548)
MockSwapperTest:test_swapExactAmountIn_swaps() (gas: 269807)
MockSwapperTest:test_swapExactAmountOut_swaps() (gas: 269803)
RedeployerTest:test_deployEXA_deploysAtSameAddress_onBase() (gas: 56250957)
RedeployerTest:test_deployExaFactory_deploysAtSameAddress_onEthereum() (gas: 273369114)
RedeployerTest:test_deployExaFactory_deploysAtSameAddress_onPolygon() (gas: 368043624)
RedeployerTest:test_deployExaFactory_deploysViaCreate3AtSameAddress_onPolygon() (gas: 45014545)
RedeployerTest:test_prepare_reverts_whenAdminIsDeployer() (gas: 28800535)
RedeployerTest:test_recoversNativeETHOnPolygon() (gas: 45185670)
RedeployerTest:test_run_reverts_whenAttackerUpgradesProxy() (gas: 38475794)
RedeployerTest:test_run_reverts_whenTargetNonceTooLow() (gas: 29265310)
RedeployerTest:test_deployEXA_deploysAtSameAddress_onBase() (gas: 56313588)
RedeployerTest:test_deployExaFactory_deploysAtSameAddress_onEthereum() (gas: 273433983)
RedeployerTest:test_deployExaFactory_deploysAtSameAddress_onPolygon() (gas: 368108493)
RedeployerTest:test_deployExaFactory_deploysViaCreate3AtSameAddress_onPolygon() (gas: 45079414)
RedeployerTest:test_prepare_reverts_whenAdminIsDeployer() (gas: 28865404)
RedeployerTest:test_recoversNativeETHOnPolygon() (gas: 45250539)
RedeployerTest:test_run_reverts_whenAttackerUpgradesProxy() (gas: 38540852)
RedeployerTest:test_run_reverts_whenTargetNonceTooLow() (gas: 29330179)
RefunderTest:test_refund_refunds() (gas: 263363)
RefunderTest:test_refund_reverts_whenExpired() (gas: 88359)
RefunderTest:test_refund_reverts_whenNotKeeper() (gas: 68861)
Expand Down
2 changes: 1 addition & 1 deletion contracts/script/ExaAccountFactory.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ contract DeployExaAccountFactory is BaseScript {
}

function getAddress() external returns (address) {
etchCreate3();
etchCanonical();
vm.etch(address(0), vm.getDeployedCode("ExaPlugin.sol:ExaPlugin"));
return CREATE3_FACTORY.getDeployed(acct("admin"), _salt(IPlugin(address(0))));
}
Comment thread
cruzdanilo marked this conversation as resolved.
Expand Down
19 changes: 14 additions & 5 deletions contracts/test/Fork.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,26 @@ abstract contract ForkTest is Test {
else if (block.chainid == 84_532) CREATE3_FACTORY = ICreate3Factory(0x9f275F6D25232FFf082082a53C62C6426c1cc94C);
else CREATE3_FACTORY = ICreate3Factory(0x93FEC2C00BfE902F733B57c5a6CeeD7CD1384AE1);
vm.label(address(CREATE3_FACTORY), "CREATE3Factory");
if (block.chainid == getChain("anvil").chainId) etchCreate3();
if (block.chainid == getChain("anvil").chainId) etchCanonical();
}

function etchCreate3() internal {
bytes memory code =
function etchCanonical() internal {
bytes memory create3Code =
hex"6080604052600436106100295760003560e01c806350f1c4641461002e578063cdcb760a14610077575b600080fd5b34801561003a57600080fd5b5061004e610049366004610489565b61008a565b60405173ffffffffffffffffffffffffffffffffffffffff909116815260200160405180910390f35b61004e6100853660046104fd565b6100ee565b6040517fffffffffffffffffffffffffffffffffffffffff000000000000000000000000606084901b166020820152603481018290526000906054016040516020818303038152906040528051906020012091506100e78261014c565b9392505050565b6040517fffffffffffffffffffffffffffffffffffffffff0000000000000000000000003360601b166020820152603481018390526000906054016040516020818303038152906040528051906020012092506100e78383346102b2565b604080518082018252601081527f67363d3d37363d34f03d5260086018f30000000000000000000000000000000060209182015290517fff00000000000000000000000000000000000000000000000000000000000000918101919091527fffffffffffffffffffffffffffffffffffffffff0000000000000000000000003060601b166021820152603581018290527f21c35dbe1b344a2488cf3321d6ce542f8e9f305544ff09e4993a62319a497c1f60558201526000908190610228906075015b6040516020818303038152906040528051906020012090565b6040517fd69400000000000000000000000000000000000000000000000000000000000060208201527fffffffffffffffffffffffffffffffffffffffff000000000000000000000000606083901b1660228201527f010000000000000000000000000000000000000000000000000000000000000060368201529091506100e79060370161020f565b6000806040518060400160405280601081526020017f67363d3d37363d34f03d5260086018f30000000000000000000000000000000081525090506000858251602084016000f5905073ffffffffffffffffffffffffffffffffffffffff811661037d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f4445504c4f594d454e545f4641494c454400000000000000000000000000000060448201526064015b60405180910390fd5b6103868661014c565b925060008173ffffffffffffffffffffffffffffffffffffffff1685876040516103b091906105d6565b60006040518083038185875af1925050503d80600081146103ed576040519150601f19603f3d011682016040523d82523d6000602084013e6103f2565b606091505b50509050808015610419575073ffffffffffffffffffffffffffffffffffffffff84163b15155b61047f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f494e495449414c495a4154494f4e5f4641494c454400000000000000000000006044820152606401610374565b5050509392505050565b6000806040838503121561049c57600080fd5b823573ffffffffffffffffffffffffffffffffffffffff811681146104c057600080fd5b946020939093013593505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000806040838503121561051057600080fd5b82359150602083013567ffffffffffffffff8082111561052f57600080fd5b818501915085601f83011261054357600080fd5b813581811115610555576105556104ce565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0908116603f0116810190838211818310171561059b5761059b6104ce565b816040528281528860208487010111156105b457600080fd5b8260208601602083013760006020848301015280955050505050509250929050565b6000825160005b818110156105f757602081860181015185830152016105dd565b50600092019182525091905056fea26469706673582212201ff95c2aafa102481fdd22c59ee7f98a92a9662a6566ab5e0498e8bb47a5f30c64736f6c63430008110033";
vm.etch(address(CREATE3_FACTORY), code);
vm.etch(address(CREATE3_FACTORY), create3Code);

bytes memory multicall3Code =
hex"6080604052600436106100f35760003560e01c80634d2301cc1161008a578063a8b0574e11610059578063a8b0574e1461025a578063bce38bd714610275578063c3077fa914610288578063ee82ac5e1461029b57600080fd5b80634d2301cc146101ec57806372425d9d1461022157806382ad56cb1461023457806386d516e81461024757600080fd5b80633408e470116100c65780633408e47014610191578063399542e9146101a45780633e64a696146101c657806342cbb15c146101d957600080fd5b80630f28c97d146100f8578063174dea711461011a578063252dba421461013a57806327e86d6e1461015b575b600080fd5b34801561010457600080fd5b50425b6040519081526020015b60405180910390f35b61012d610128366004610a85565b6102ba565b6040516101119190610bbe565b61014d610148366004610a85565b6104ef565b604051610111929190610bd8565b34801561016757600080fd5b50437fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0140610107565b34801561019d57600080fd5b5046610107565b6101b76101b2366004610c60565b610690565b60405161011193929190610cba565b3480156101d257600080fd5b5048610107565b3480156101e557600080fd5b5043610107565b3480156101f857600080fd5b50610107610207366004610ce2565b73ffffffffffffffffffffffffffffffffffffffff163190565b34801561022d57600080fd5b5044610107565b61012d610242366004610a85565b6106ab565b34801561025357600080fd5b5045610107565b34801561026657600080fd5b50604051418152602001610111565b61012d610283366004610c60565b61085a565b6101b7610296366004610a85565b610a1a565b3480156102a757600080fd5b506101076102b6366004610d18565b4090565b60606000828067ffffffffffffffff8111156102d8576102d8610d31565b60405190808252806020026020018201604052801561031e57816020015b6040805180820190915260008152606060208201528152602001906001900390816102f65790505b5092503660005b8281101561047757600085828151811061034157610341610d60565b6020026020010151905087878381811061035d5761035d610d60565b905060200281019061036f9190610d8f565b6040810135958601959093506103886020850185610ce2565b73ffffffffffffffffffffffffffffffffffffffff16816103ac6060870187610dcd565b6040516103ba929190610e32565b60006040518083038185875af1925050503d80600081146103f7576040519150601f19603f3d011682016040523d82523d6000602084013e6103fc565b606091505b50602080850191909152901515808452908501351761046d577f08c379a000000000000000000000000000000000000000000000000000000000600052602060045260176024527f4d756c746963616c6c333a2063616c6c206661696c656400000000000000000060445260846000fd5b5050600101610325565b508234146104e6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601a60248201527f4d756c746963616c6c333a2076616c7565206d69736d6174636800000000000060448201526064015b60405180910390fd5b50505092915050565b436060828067ffffffffffffffff81111561050c5761050c610d31565b60405190808252806020026020018201604052801561053f57816020015b606081526020019060019003908161052a5790505b5091503660005b8281101561068657600087878381811061056257610562610d60565b90506020028101906105749190610e42565b92506105836020840184610ce2565b73ffffffffffffffffffffffffffffffffffffffff166105a66020850185610dcd565b6040516105b4929190610e32565b6000604051808303816000865af19150503d80600081146105f1576040519150601f19603f3d011682016040523d82523d6000602084013e6105f6565b606091505b5086848151811061060957610609610d60565b602090810291909101015290508061067d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601760248201527f4d756c746963616c6c333a2063616c6c206661696c656400000000000000000060448201526064016104dd565b50600101610546565b5050509250929050565b43804060606106a086868661085a565b905093509350939050565b6060818067ffffffffffffffff8111156106c7576106c7610d31565b60405190808252806020026020018201604052801561070d57816020015b6040805180820190915260008152606060208201528152602001906001900390816106e55790505b5091503660005b828110156104e657600084828151811061073057610730610d60565b6020026020010151905086868381811061074c5761074c610d60565b905060200281019061075e9190610e76565b925061076d6020840184610ce2565b73ffffffffffffffffffffffffffffffffffffffff166107906040850185610dcd565b60405161079e929190610e32565b6000604051808303816000865af19150503d80600081146107db576040519150601f19603f3d011682016040523d82523d6000602084013e6107e0565b606091505b506020808401919091529015158083529084013517610851577f08c379a000000000000000000000000000000000000000000000000000000000600052602060045260176024527f4d756c746963616c6c333a2063616c6c206661696c656400000000000000000060445260646000fd5b50600101610714565b6060818067ffffffffffffffff81111561087657610876610d31565b6040519080825280602002602001820160405280156108bc57816020015b6040805180820190915260008152606060208201528152602001906001900390816108945790505b5091503660005b82811015610a105760008482815181106108df576108df610d60565b602002602001015190508686838181106108fb576108fb610d60565b905060200281019061090d9190610e42565b925061091c6020840184610ce2565b73ffffffffffffffffffffffffffffffffffffffff1661093f6020850185610dcd565b60405161094d929190610e32565b6000604051808303816000865af19150503d806000811461098a576040519150601f19603f3d011682016040523d82523d6000602084013e61098f565b606091505b506020830152151581528715610a07578051610a07576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601760248201527f4d756c746963616c6c333a2063616c6c206661696c656400000000000000000060448201526064016104dd565b506001016108c3565b5050509392505050565b6000806060610a2b60018686610690565b919790965090945092505050565b60008083601f840112610a4b57600080fd5b50813567ffffffffffffffff811115610a6357600080fd5b6020830191508360208260051b8501011115610a7e57600080fd5b9250929050565b60008060208385031215610a9857600080fd5b823567ffffffffffffffff811115610aaf57600080fd5b610abb85828601610a39565b90969095509350505050565b6000815180845260005b81811015610aed57602081850181015186830182015201610ad1565b81811115610aff576000602083870101525b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b600082825180855260208086019550808260051b84010181860160005b84811015610bb1578583037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe001895281518051151584528401516040858501819052610b9d81860183610ac7565b9a86019a9450505090830190600101610b4f565b5090979650505050505050565b602081526000610bd16020830184610b32565b9392505050565b600060408201848352602060408185015281855180845260608601915060608160051b870101935082870160005b82811015610c52577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa0888703018452610c40868351610ac7565b95509284019290840190600101610c06565b509398975050505050505050565b600080600060408486031215610c7557600080fd5b83358015158114610c8557600080fd5b9250602084013567ffffffffffffffff811115610ca157600080fd5b610cad86828701610a39565b9497909650939450505050565b838152826020820152606060408201526000610cd96060830184610b32565b95945050505050565b600060208284031215610cf457600080fd5b813573ffffffffffffffffffffffffffffffffffffffff81168114610bd157600080fd5b600060208284031215610d2a57600080fd5b5035919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600082357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81833603018112610dc357600080fd5b9190910192915050565b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe1843603018112610e0257600080fd5b83018035915067ffffffffffffffff821115610e1d57600080fd5b602001915036819003821315610a7e57600080fd5b8183823760009101908152919050565b600082357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc1833603018112610dc357600080fd5b600082357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa1833603018112610dc357600080fd";
vm.etch(MULTICALL3_ADDRESS, multicall3Code);
Comment thread
cruzdanilo marked this conversation as resolved.
Comment thread
cruzdanilo marked this conversation as resolved.

try vm.activeFork() {
vm.rpc(
"anvil_setCode",
string.concat('["', address(CREATE3_FACTORY).toHexString(), '","', code.toHexString(), '"]') // solhint-disable-line quotes
string.concat('["', address(CREATE3_FACTORY).toHexString(), '","', create3Code.toHexString(), '"]') // solhint-disable-line quotes
);
vm.rpc(
"anvil_setCode",
string.concat('["', MULTICALL3_ADDRESS.toHexString(), '","', multicall3Code.toHexString(), '"]') // solhint-disable-line quotes
);
} catch { } // solhint-disable-line no-empty-blocks
}
Expand Down
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"mload",
"modelcontextprotocol",
"moti",
"multicall",
"mysten",
"natspec",
"nfmelendez",
Expand Down
19 changes: 11 additions & 8 deletions src/components/pay/Repay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -282,31 +282,34 @@ export default function Repay() {
const maxAmountIn = route?.fromAmount ? pad(route.fromAmount, SLIPPAGE_DIVISOR) + 69n : undefined; // HACK try to avoid ZERO_SHARES on dust deposit

const {
propose: { data: repayPropose },
executeProposal: { error: repayExecuteProposalError, isPending: isSimulatingRepay },
request: repayPropose,
error: repayExecuteProposalError,
isPending: isSimulatingRepay,
} = useSimulateProposal({
account,
amount: maxRepay,
market: selectedAsset.address,
enabled: enableSimulations && mode === "repay" && positionAssets > 0n,
proposalType: ProposalType.RepayAtMaturity,
maturity,
positionAssets,
enabled: enableSimulations && mode === "repay" && positionAssets > 0n,
});

const {
propose: { data: crossRepayPropose },
executeProposal: { error: crossRepayExecuteProposalError, isPending: isSimulatingCrossRepay },
request: crossRepayPropose,
error: crossRepayExecuteProposalError,
isPending: isSimulatingCrossRepay,
} = useSimulateProposal({
account,
amount: maxAmountIn,
market: selectedAsset.address,
enabled: enableSimulations && mode === "crossRepay" && positionAssets > 0n,
proposalType: ProposalType.CrossRepayAtMaturity,
marketOut: marketUSDCAddress,
maturity,
positionAssets,
maxRepay,
route: route?.data,
enabled: enableSimulations && mode === "crossRepay" && positionAssets > 0n && !!route,
});

const {
Expand Down Expand Up @@ -378,15 +381,15 @@ export default function Repay() {
switch (mode) {
case "repay":
if (!repayPropose) throw new Error("no repay simulation");
mutate(repayPropose.request);
mutate(repayPropose);
break;
case "legacyRepay":
if (!legacyRepaySimulation) throw new Error("no legacy repay simulation");
mutate(legacyRepaySimulation.request);
break;
case "crossRepay":
if (!crossRepayPropose) throw new Error("no cross repay simulation");
mutate(crossRepayPropose.request);
mutate(crossRepayPropose);
break;
case "legacyCrossRepay":
if (!legacyCrossRepaySimulation) throw new Error("no legacy cross repay simulation");
Expand Down
Loading
Loading