I find myself developing a Gnosis Safe module that is designed to do a pretty simple thing: determine the amount of USDC in a Safe and mint that amount of USDC collateral tokens in a lending protocol like Compound.
The mint
function in the contract, which must be enabled as a Gnosis Safe module first, checks the available balance of USDC in the Safe, then calls execTransactionFromModule
on the Safe 2 separate times: (Example tx)
- The first call to
approve
on the USDC contract, which succeeds - The second call to
mint
on the Compound CToken contract, which succeeds in a Foundry fork test, but fails on the Moonriver network where I am testing this.
Any idea why this is failing silently, or what I might be doing wrong? It's super strange that the fork test succeeds, while the on chain transaction fails... Thanks in advance for any help you can give.
In case you wanted to run the same Foundry fork test yourself, you could simply use this config in foundry.toml
:
[rpc_endpoints]
moonriver = "https://rpc.api.moonriver.moonbeam.network"
And use this test file testVault.t.sol
, typing forge test -vvvv
:
// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;
import "forge-std/Test.sol";
interface IVault{
function mint(address token) external;
}
contract LukeTest is Test {
uint FORK_BLOCK = 4_202_447;
address sender = 0x354804005a80e5f87cf43beD9Bd4fCc6512Be98c;
IVault vault = IVault(0x12eD901165266CF0fC9972A1e644dB5eE83523c8);
function setUp() public {
uint forkId = vm.createSelectFork("moonriver", FORK_BLOCK);
}
function testLukeVault() public {
vm.prank(sender);
vault.mint(0xE3F5a90F9cb311505cd691a46596599aA1A0AD7D);
}
}
Here's the output of the fork test, which shows it's working fine:
Running 1 test for test/testVault.t.sol:LukeTest
[PASS] testLukeVault() (gas: 227389)
Traces:
[227389] LukeTest::testLukeVault()
├─ [0] VM::prank(0x354804005a80e5f87cf43beD9Bd4fCc6512Be98c)
│ └─ ← ()
├─ [217282] 0x12eD901165266CF0fC9972A1e644dB5eE83523c8::mint(0xE3F5a90F9cb311505cd691a46596599aA1A0AD7D)
│ ├─ [2641] 0xE3F5a90F9cb311505cd691a46596599aA1A0AD7D::balanceOf(0xE6F8E7abe4945ff47e75fBAe2aE9bBaAfD59aE0D) [staticcall]
│ │ └─ ← 0x0000000000000000000000000000000000000000000000000000000005f5e132
│ ├─ [18038] 0xE6F8E7abe4945ff47e75fBAe2aE9bBaAfD59aE0D::execTransactionFromModule(0xE3F5a90F9cb311505cd691a46596599aA1A0AD7D, 0, 0x095ea7b3000000000000000000000000d0670aee3698f66e2d4daf071eb9c690d978bfa80000000000000000000000000000000000000000000000000000000005f5e132, 0)
│ │ ├─ [13165] 0x3E5c63644E683549055b9Be8653de26E0B4CD36E::execTransactionFromModule(0xE3F5a90F9cb311505cd691a46596599aA1A0AD7D, 0, 0x095ea7b3000000000000000000000000d0670aee3698f66e2d4daf071eb9c690d978bfa80000000000000000000000000000000000000000000000000000000005f5e132, 0) [delegatecall]
│ │ │ ├─ emit SafeModuleTransaction(: 0x12eD901165266CF0fC9972A1e644dB5eE83523c8, : 0xE3F5a90F9cb311505cd691a46596599aA1A0AD7D, : 0, : 0x095ea7b3000000000000000000000000d0670aee3698f66e2d4daf071eb9c690d978bfa80000000000000000000000000000000000000000000000000000000005f5e132, : 0)
│ │ │ ├─ [4767] 0xE3F5a90F9cb311505cd691a46596599aA1A0AD7D::approve(0xd0670AEe3698F66e2D4dAf071EB9c690d978BFA8, 100000050)
│ │ │ │ ├─ emit Approval(param0: 0xE6F8E7abe4945ff47e75fBAe2aE9bBaAfD59aE0D, param1: 0xd0670AEe3698F66e2D4dAf071EB9c690d978BFA8, param2: 100000050)
│ │ │ │ └─ ← 0x0000000000000000000000000000000000000000000000000000000000000001
│ │ │ ├─ emit ExecutionFromModuleSuccess(param0: 0x12eD901165266CF0fC9972A1e644dB5eE83523c8)
│ │ │ └─ ← 0x0000000000000000000000000000000000000000000000000000000000000001
│ │ └─ ← 0x0000000000000000000000000000000000000000000000000000000000000001
│ ├─ emit Approved(token: 0xE3F5a90F9cb311505cd691a46596599aA1A0AD7D, spender: 0xd0670AEe3698F66e2D4dAf071EB9c690d978BFA8, amount: 100000050)
│ ├─ [178032] 0xE6F8E7abe4945ff47e75fBAe2aE9bBaAfD59aE0D::execTransactionFromModule(0xd0670AEe3698F66e2D4dAf071EB9c690d978BFA8, 0, 0xa0712d680000000000000000000000000000000000000000000000000000000005f5e132, 0)
│ │ ├─ [177665] 0x3E5c63644E683549055b9Be8653de26E0B4CD36E::execTransactionFromModule(0xd0670AEe3698F66e2D4dAf071EB9c690d978BFA8, 0, 0xa0712d680000000000000000000000000000000000000000000000000000000005f5e132, 0) [delegatecall]
│ │ │ ├─ emit SafeModuleTransaction(: 0x12eD901165266CF0fC9972A1e644dB5eE83523c8, : 0xd0670AEe3698F66e2D4dAf071EB9c690d978BFA8, : 0, : 0xa0712d680000000000000000000000000000000000000000000000000000000005f5e132, : 0)
│ │ │ ├─ [169107] 0xd0670AEe3698F66e2D4dAf071EB9c690d978BFA8::mint(100000050)
│ │ │ │ ├─ [163247] 0x45d17FE87e65064b2e85F91A9FF3aD0C7B6Cf75d::mint(100000050) [delegatecall]
│ │ │ │ │ ├─ [2641] 0xE3F5a90F9cb311505cd691a46596599aA1A0AD7D::balanceOf(0xd0670AEe3698F66e2D4dAf071EB9c690d978BFA8) [staticcall]
│ │ │ │ │ │ └─ ← 0x000000000000000000000000000000000000000000000000000002b5effd2c47
│ │ │ │ │ ├─ [7780] 0x4393277B02ef3cA293990A772B7160a8c76F2443::getBorrowRate(2980438682695, 6061107586381, 299100976181) [staticcall]
│ │ │ │ │ │ └─ ← 0x000000000000000000000000000000000000000000000000000000004184aed2
│ │ │ │ │ ├─ emit AccrueInterest(: 2980438682695, : 86945071, : 1079641637619069488, : 6061194531452)
│ │ │ │ │ ├─ [69925] 0x0b7a0EAA884849c6Af7a129e899536dDDcA4905E::mintAllowed(0xd0670AEe3698F66e2D4dAf071EB9c690d978BFA8, 0xE6F8E7abe4945ff47e75fBAe2aE9bBaAfD59aE0D, 100000050)
│ │ │ │ │ │ ├─ [64745] 0x8529ea4DBDcA738aA928d682ea9c1382Bf2Ff098::mintAllowed(0xd0670AEe3698F66e2D4dAf071EB9c690d978BFA8, 0xE6F8E7abe4945ff47e75fBAe2aE9bBaAfD59aE0D, 100000050) [delegatecall]
│ │ │ │ │ │ │ ├─ [2367] 0xd0670AEe3698F66e2D4dAf071EB9c690d978BFA8::totalSupply() [staticcall]
│ │ │ │ │ │ │ │ └─ ← 0x0000000000000000000000000000000000000000000000000096ed091d9d5646
│ │ │ │ │ │ │ ├─ [6661] 0xd0670AEe3698F66e2D4dAf071EB9c690d978BFA8::balanceOf(0xE6F8E7abe4945ff47e75fBAe2aE9bBaAfD59aE0D) [staticcall]
│ │ │ │ │ │ │ │ ├─ [4232] 0xd0670AEe3698F66e2D4dAf071EB9c690d978BFA8::delegateToImplementation(0x70a08231000000000000000000000000e6f8e7abe4945ff47e75fbae2ae9bbaafd59ae0d) [staticcall]
│ │ │ │ │ │ │ │ │ ├─ [2575] 0x45d17FE87e65064b2e85F91A9FF3aD0C7B6Cf75d::balanceOf(0xE6F8E7abe4945ff47e75fBAe2aE9bBaAfD59aE0D) [delegatecall]
│ │ │ │ │ │ │ │ │ │ └─ ← 0x0000000000000000000000000000000000000000000000000000000000000000
│ │ │ │ │ │ │ │ │ └─ ← 0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000
│ │ │ │ │ │ │ │ └─ ← 0x0000000000000000000000000000000000000000000000000000000000000000
│ │ │ │ │ │ │ ├─ emit topic 0: 0xaccd035d02c456be35306aecd5a5fe62320713dde09ccd68b0a5e8ed93039999
│ │ │ │ │ │ │ │ topic 1: 0x0000000000000000000000000000000000000000000000000000000000000000
│ │ │ │ │ │ │ │ topic 2: 0x000000000000000000000000d0670aee3698f66e2d4daf071eb9c690d978bfa8
│ │ │ │ │ │ │ │ topic 3: 0x000000000000000000000000e6f8e7abe4945ff47e75fbae2ae9bbaafd59ae0d
│ │ │ │ │ │ │ │ data: 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008c63fd48a09c1688a630db84e2dc1f1d3a71b
│ │ │ │ │ │ │ ├─ [367] 0xd0670AEe3698F66e2D4dAf071EB9c690d978BFA8::totalSupply() [staticcall]
│ │ │ │ │ │ │ │ └─ ← 0x0000000000000000000000000000000000000000000000000096ed091d9d5646
│ │ │ │ │ │ │ ├─ [4661] 0xd0670AEe3698F66e2D4dAf071EB9c690d978BFA8::balanceOf(0xE6F8E7abe4945ff47e75fBAe2aE9bBaAfD59aE0D) [staticcall]
│ │ │ │ │ │ │ │ ├─ [2232] 0xd0670AEe3698F66e2D4dAf071EB9c690d978BFA8::delegateToImplementation(0x70a08231000000000000000000000000e6f8e7abe4945ff47e75fbae2ae9bbaafd59ae0d) [staticcall]
│ │ │ │ │ │ │ │ │ ├─ [575] 0x45d17FE87e65064b2e85F91A9FF3aD0C7B6Cf75d::balanceOf(0xE6F8E7abe4945ff47e75fBAe2aE9bBaAfD59aE0D) [delegatecall]
│ │ │ │ │ │ │ │ │ │ └─ ← 0x0000000000000000000000000000000000000000000000000000000000000000
│ │ │ │ │ │ │ │ │ └─ ← 0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000
│ │ │ │ │ │ │ │ └─ ← 0x0000000000000000000000000000000000000000000000000000000000000000
│ │ │ │ │ │ │ ├─ emit topic 0: 0xaccd035d02c456be35306aecd5a5fe62320713dde09ccd68b0a5e8ed93039999
│ │ │ │ │ │ │ │ topic 1: 0x0000000000000000000000000000000000000000000000000000000000000001
│ │ │ │ │ │ │ │ topic 2: 0x000000000000000000000000d0670aee3698f66e2d4daf071eb9c690d978bfa8
│ │ │ │ │ │ │ │ topic 3: 0x000000000000000000000000e6f8e7abe4945ff47e75fbae2ae9bbaafd59ae0d
│ │ │ │ │ │ │ │ data: 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000056b605ffb6c069653c90d5291ba633018ec
│ │ │ │ │ │ │ └─ ← 0x0000000000000000000000000000000000000000000000000000000000000000
│ │ │ │ │ │ └─ ← 0x0000000000000000000000000000000000000000000000000000000000000000
│ │ │ │ │ ├─ [641] 0xE3F5a90F9cb311505cd691a46596599aA1A0AD7D::balanceOf(0xd0670AEe3698F66e2D4dAf071EB9c690d978BFA8) [staticcall]
│ │ │ │ │ │ └─ ← 0x000000000000000000000000000000000000000000000000000002b5effd2c47
│ │ │ │ │ ├─ [641] 0xE3F5a90F9cb311505cd691a46596599aA1A0AD7D::balanceOf(0xd0670AEe3698F66e2D4dAf071EB9c690d978BFA8) [staticcall]
│ │ │ │ │ │ └─ ← 0x000000000000000000000000000000000000000000000000000002b5effd2c47
│ │ │ │ │ ├─ [11476] 0xE3F5a90F9cb311505cd691a46596599aA1A0AD7D::transferFrom(0xE6F8E7abe4945ff47e75fBAe2aE9bBaAfD59aE0D, 0xd0670AEe3698F66e2D4dAf071EB9c690d978BFA8, 100000050)
│ │ │ │ │ │ ├─ emit Approval(param0: 0xE6F8E7abe4945ff47e75fBAe2aE9bBaAfD59aE0D, param1: 0xd0670AEe3698F66e2D4dAf071EB9c690d978BFA8, param2: 0)
│ │ │ │ │ │ ├─ emit Transfer(param0: 0xE6F8E7abe4945ff47e75fBAe2aE9bBaAfD59aE0D, param1: 0xd0670AEe3698F66e2D4dAf071EB9c690d978BFA8, param2: 100000050)
│ │ │ │ │ │ └─ ← 0x0000000000000000000000000000000000000000000000000000000000000001
│ │ │ │ │ ├─ [641] 0xE3F5a90F9cb311505cd691a46596599aA1A0AD7D::balanceOf(0xd0670AEe3698F66e2D4dAf071EB9c690d978BFA8) [staticcall]
│ │ │ │ │ │ └─ ← 0x000000000000000000000000000000000000000000000000000002b5f5f30d79
│ │ │ │ │ ├─ emit Mint(: 0xE6F8E7abe4945ff47e75fBAe2aE9bBaAfD59aE0D, : 100000050, : 485922766670)
│ │ │ │ │ ├─ emit Transfer(param0: 0xd0670AEe3698F66e2D4dAf071EB9c690d978BFA8, param1: 0xE6F8E7abe4945ff47e75fBAe2aE9bBaAfD59aE0D, param2: 485922766670)
│ │ │ │ │ └─ ← 0x0000000000000000000000000000000000000000000000000000000000000000
│ │ │ │ └─ ← 0x0000000000000000000000000000000000000000000000000000000000000000
│ │ │ ├─ emit ExecutionFromModuleSuccess(param0: 0x12eD901165266CF0fC9972A1e644dB5eE83523c8)
│ │ │ └─ ← 0x0000000000000000000000000000000000000000000000000000000000000001
│ │ └─ ← 0x0000000000000000000000000000000000000000000000000000000000000001
│ ├─ emit Minted(token: 0xE3F5a90F9cb311505cd691a46596599aA1A0AD7D, amount: 100000050)
│ └─ ← ()
└─ ← ()
Test result: ok. 1 passed; 0 failed; finished in 9.02s