Skip to content

Commit 60844db

Browse files
authored
Merge pull request #186 from Gearbox-protocol/attach-test-suite
feat: attach test suite
2 parents 8e55643 + b22efe3 commit 60844db

16 files changed

+479
-12
lines changed

.gitignore

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ dist/
88
**/*.generated.*
99
**/generated/
1010

11-
# Ignores development broadcast logs
12-
!/broadcast
13-
/broadcast/*/31337/
14-
/broadcast/**/dry-run/
11+
# Broadcast logs
12+
/broadcast
1513

1614
# Docs
1715
docs/

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@
1313
[submodule "lib/@1inch/farming"]
1414
path = lib/@1inch/farming
1515
url = https://github.com/1inch/farming
16+
[submodule "lib/@gearbox-protocol/permissionless"]
17+
path = lib/@gearbox-protocol/permissionless
18+
url = https://github.com/Gearbox-protocol/permissionless
19+
branch = attach-test-base
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.23;
3+
4+
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
5+
6+
import {ICreditFacadeV3, MultiCall} from "@gearbox-protocol/core-v3/contracts/interfaces/ICreditFacadeV3.sol";
7+
import {ICreditManagerV3} from "@gearbox-protocol/core-v3/contracts/interfaces/ICreditManagerV3.sol";
8+
9+
import {ConstantPriceFeed} from "@gearbox-protocol/oracles-v3/contracts/oracles/ConstantPriceFeed.sol";
10+
11+
import {AttachTestBase} from "@gearbox-protocol/permissionless/contracts/test/suite/AttachTestBase.sol";
12+
13+
abstract contract IntegrationsAttachTestBase is AttachTestBase {
14+
address zeroPriceFeed;
15+
address onePriceFeed;
16+
17+
address underlying;
18+
address pool;
19+
address creditManager;
20+
address creditFacade;
21+
22+
address user;
23+
address creditAccount;
24+
25+
function _setUp() internal {
26+
// NOTE: even though we compile our contracts under Shanghai EVM version,
27+
// more recent one might be needed to interact with third-party contracts
28+
vm.setEvmVersion("osaka");
29+
30+
_attachCore();
31+
32+
zeroPriceFeed = priceFeedStore.zeroPriceFeed();
33+
if (bytecodeRepository.getAllowedBytecodeHash("PRICE_FEED::CONSTANT", 3_10) == 0) {
34+
// NOTE: this would fail on deployment if we bump `ConstantPriceFeed` to v3.1.1 in the oracles repo,
35+
// but we assume that in this case v3.1.0 would already be uploaded to the bytecode repository
36+
_uploadContract("PRICE_FEED::CONSTANT", 3_10, type(ConstantPriceFeed).creationCode);
37+
}
38+
onePriceFeed = _deploy("PRICE_FEED::CONSTANT", 3_10, abi.encode(1e8, "$1 price feed"));
39+
_addPriceFeed(onePriceFeed, 0, "$1 price feed");
40+
41+
_attachMarketConfigurator();
42+
43+
underlying = address(new ERC20("Mock Token", "MOCK"));
44+
_allowPriceFeed(underlying, onePriceFeed);
45+
pool = _createMockMarket(underlying, onePriceFeed);
46+
creditManager = _createMockCreditSuite({pool: pool, minDebt: 1e18, maxDebt: 1e18, debtLimit: 0});
47+
creditFacade = ICreditManagerV3(creditManager).creditFacade();
48+
49+
user = makeAddr("user");
50+
creditAccount = ICreditFacadeV3(creditFacade).openCreditAccount(user, new MultiCall[](0), 0);
51+
}
52+
53+
// ----------------------- //
54+
// CONFIGURATION FUNCTIONS //
55+
// ----------------------- //
56+
57+
function _addToken(address token) internal {
58+
_allowPriceFeed(token, zeroPriceFeed);
59+
_addToken(
60+
pool,
61+
TokenConfig({
62+
token: token, priceFeed: zeroPriceFeed, reservePriceFeed: address(0), quotaLimit: 0, quotaRate: 0
63+
})
64+
);
65+
_addCollateralToken(creditManager, token, 0);
66+
}
67+
68+
function _getAdapterFor(address targetContract) internal view returns (address) {
69+
return ICreditManagerV3(creditManager).contractToAdapter(targetContract);
70+
}
71+
72+
// -------------- //
73+
// USER FUNCTIONS //
74+
// -------------- //
75+
76+
function _multicall(MultiCall[] memory calls) internal {
77+
vm.prank(user);
78+
ICreditFacadeV3(creditFacade).multicall(creditAccount, calls);
79+
}
80+
81+
function _multicall(MultiCall memory call0) internal {
82+
MultiCall[] memory calls = new MultiCall[](1);
83+
calls[0] = call0;
84+
_multicall(calls);
85+
}
86+
87+
function _multicall(MultiCall memory call0, MultiCall memory call1) internal {
88+
MultiCall[] memory calls = new MultiCall[](2);
89+
calls[0] = call0;
90+
calls[1] = call1;
91+
_multicall(calls);
92+
}
93+
94+
function _multicall(MultiCall memory call0, MultiCall memory call1, MultiCall memory call2) internal {
95+
MultiCall[] memory calls = new MultiCall[](3);
96+
calls[0] = call0;
97+
calls[1] = call1;
98+
calls[2] = call2;
99+
_multicall(calls);
100+
}
101+
102+
function _multicall(MultiCall memory call0, MultiCall memory call1, MultiCall memory call2, MultiCall memory call3)
103+
internal
104+
{
105+
MultiCall[] memory calls = new MultiCall[](4);
106+
calls[0] = call0;
107+
calls[1] = call1;
108+
calls[2] = call2;
109+
calls[3] = call3;
110+
_multicall(calls);
111+
}
112+
113+
function _multicall(
114+
MultiCall memory call0,
115+
MultiCall memory call1,
116+
MultiCall memory call2,
117+
MultiCall memory call3,
118+
MultiCall memory call4
119+
) internal {
120+
MultiCall[] memory calls = new MultiCall[](5);
121+
calls[0] = call0;
122+
calls[1] = call1;
123+
calls[2] = call2;
124+
calls[3] = call3;
125+
calls[4] = call4;
126+
_multicall(calls);
127+
}
128+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.23;
3+
4+
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
5+
6+
import {MultiCall} from "@gearbox-protocol/core-v3/contracts/interfaces/ICreditFacadeV3.sol";
7+
8+
import {UpshiftVaultAdapter} from "../../../adapters/upshift/UpshiftVaultAdapter.sol";
9+
import {UpshiftVaultGateway} from "../../../helpers/upshift/UpshiftVaultGateway.sol";
10+
import {UpshiftVaultWithdrawalPhantomToken} from "../../../helpers/upshift/UpshiftVaultWithdrawalPhantomToken.sol";
11+
12+
import {IERC4626Adapter} from "../../../interfaces/erc4626/IERC4626Adapter.sol";
13+
import {IUpshiftVaultAdapter} from "../../../interfaces/upshift/IUpshiftVaultAdapter.sol";
14+
15+
import {IntegrationsAttachTestBase} from "../IntegrationsAttachTestBase.sol";
16+
17+
contract UpshiftAttachTest is IntegrationsAttachTestBase {
18+
address constant tBTC = 0x18084fbA666a33d37592fA2633fD49a74DD93a88;
19+
address constant uptBTC = 0x8AcA0841993ef4C87244d519166e767f49362C21;
20+
21+
address uptBTCGateway;
22+
address wduptBTC;
23+
24+
function setUp() public {
25+
super._setUp();
26+
27+
vm.skip(block.chainid != 1, "Not Ethereum mainnet");
28+
29+
_uploadContract("ADAPTER::UPSHIFT_VAULT", 3_11, type(UpshiftVaultAdapter).creationCode);
30+
_uploadContract("GATEWAY::UPSHIFT_VAULT", 3_11, type(UpshiftVaultGateway).creationCode);
31+
_uploadContract("PHANTOM_TOKEN::UPSHIFT_WITHDRAW", 3_10, type(UpshiftVaultWithdrawalPhantomToken).creationCode);
32+
33+
uptBTCGateway = _deploy("GATEWAY::UPSHIFT_VAULT", 3_10, abi.encode(uptBTC));
34+
wduptBTC = _deploy("PHANTOM_TOKEN::UPSHIFT_WITHDRAW", 3_10, abi.encode(uptBTC, uptBTCGateway));
35+
36+
_addToken(tBTC);
37+
_addToken(uptBTC);
38+
_addToken(wduptBTC);
39+
40+
_allowAdapter(creditManager, "UPSHIFT_VAULT", abi.encode(creditManager, uptBTCGateway, wduptBTC));
41+
}
42+
43+
function test_upshift() public {}
44+
}

foundry.lock

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@
1313
},
1414
"lib/@gearbox-protocol/oracles-v3": {
1515
"tag": {
16-
"name": "v1.14.0",
17-
"rev": "78ad827ab9329f2c1d884672120fb61ca9fb67ec"
16+
"name": "v1.15.1",
17+
"rev": "69c12f58da99281f03ac2c650c0793ba7c30ae38"
18+
}
19+
},
20+
"lib/@gearbox-protocol/permissionless": {
21+
"branch": {
22+
"name": "attach-test-base",
23+
"rev": "dae649ab8e10d11d24d4575a90365de1d0408a3b"
1824
}
1925
},
2026
"lib/@gearbox-protocol/sdk-gov": {

foundry.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ evm_version = 'shanghai'
77
optimizer_runs = 1000
88
bytecode_hash = 'none'
99

10-
# See more config options https://github.com/gakonst/foundry/tree/master/config
11-
block_number = 120000
12-
block_timestamp = 1640000000
10+
block_number = 120000
11+
block_timestamp = 1640000000
1312
gas_limit = 9223372036854775807 # the gas limit in tests
1413
block_base_fee_per_gas = 100
1514
fs_permissions = [{ access = "read-write", path = "./"}]
1615
ffi=true
16+
17+
[lint]
18+
lint_on_build = false

lib/@gearbox-protocol/oracles-v3

Submodule oracles-v3 updated 84 files
Submodule permissionless added at dae649a

remappings.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
forge-std/=lib/@gearbox-protocol/core-v3/lib/forge-std/src/
1+
forge-std/=lib/@gearbox-protocol/permissionless/lib/forge-std/src/
22
@1inch/=lib/@1inch/
3-
@openzeppelin/=lib/@gearbox-protocol/core-v3/lib/@openzeppelin/
3+
@openzeppelin/=lib/@gearbox-protocol/permissionless/lib/@openzeppelin/
44
@gearbox-protocol=lib/@gearbox-protocol/
55
@redstone-finance=node_modules/@redstone-finance/
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.23;
3+
4+
import {Bytecode} from "@gearbox-protocol/permissionless/contracts/interfaces/Types.sol";
5+
import {UploadBytecode} from "@gearbox-protocol/permissionless/script/UploadBytecode.sol";
6+
7+
import {ConvexV1BaseRewardPoolAdapter} from "../../contracts/adapters/convex/ConvexV1_BaseRewardPool.sol";
8+
import {ERC4626Adapter} from "../../contracts/adapters/erc4626/ERC4626Adapter.sol";
9+
import {UpshiftVaultAdapter} from "../../contracts/adapters/upshift/UpshiftVaultAdapter.sol";
10+
import {UpshiftVaultGateway} from "../../contracts/helpers/upshift/UpshiftVaultGateway.sol";
11+
import {
12+
UpshiftVaultWithdrawalPhantomToken
13+
} from "../../contracts/helpers/upshift/UpshiftVaultWithdrawalPhantomToken.sol";
14+
import {ERC4626Zapper} from "../../contracts/zappers/ERC4626Zapper.sol";
15+
import {StakedERC4626Zapper} from "../../contracts/zappers/StakedERC4626Zapper.sol";
16+
17+
contract Upload_2025_07_29_Integrations is UploadBytecode {
18+
function _getContracts() internal pure override returns (Bytecode[] memory bytecodes) {
19+
bytecodes = new Bytecode[](7);
20+
bytecodes[0].contractType = "ADAPTER::CVX_V1_BASE_REWARD_POOL";
21+
bytecodes[0].version = 3_11;
22+
bytecodes[0].initCode = type(ConvexV1BaseRewardPoolAdapter).creationCode;
23+
bytecodes[0].source =
24+
"https://github.com/Gearbox-protocol/integrations-v3/blob/883aad9cffe8ea77258f806b6ebbf34a013d9348/contracts/adapters/convex/ConvexV1_BaseRewardPool.sol";
25+
26+
bytecodes[1].contractType = "ADAPTER::ERC4626_VAULT";
27+
bytecodes[1].version = 3_12;
28+
bytecodes[1].initCode = type(ERC4626Adapter).creationCode;
29+
bytecodes[1].source =
30+
"https://github.com/Gearbox-protocol/integrations-v3/blob/883aad9cffe8ea77258f806b6ebbf34a013d9348/contracts/adapters/erc4626/ERC4626Adapter.sol";
31+
32+
bytecodes[2].contractType = "ADAPTER::UPSHIFT_VAULT";
33+
bytecodes[2].version = 3_10;
34+
bytecodes[2].initCode = type(UpshiftVaultAdapter).creationCode;
35+
bytecodes[2].source =
36+
"https://github.com/Gearbox-protocol/integrations-v3/blob/883aad9cffe8ea77258f806b6ebbf34a013d9348/contracts/adapters/upshift/UpshiftVaultAdapter.sol";
37+
38+
bytecodes[3].contractType = "GATEWAY::UPSHIFT_VAULT";
39+
bytecodes[3].version = 3_10;
40+
bytecodes[3].initCode = type(UpshiftVaultGateway).creationCode;
41+
bytecodes[3].source =
42+
"https://github.com/Gearbox-protocol/integrations-v3/blob/883aad9cffe8ea77258f806b6ebbf34a013d9348/contracts/helpers/upshift/UpshiftVaultGateway.sol";
43+
44+
bytecodes[4].contractType = "PHANTOM_TOKEN::UPSHIFT_WITHDRAW";
45+
bytecodes[4].version = 3_10;
46+
bytecodes[4].initCode = type(UpshiftVaultWithdrawalPhantomToken).creationCode;
47+
bytecodes[4].source =
48+
"https://github.com/Gearbox-protocol/integrations-v3/blob/883aad9cffe8ea77258f806b6ebbf34a013d9348/contracts/helpers/upshift/UpshiftVaultWithdrawalPhantomToken.sol";
49+
50+
bytecodes[5].contractType = "ZAPPER::ERC4626";
51+
bytecodes[5].version = 3_10;
52+
bytecodes[5].initCode = type(ERC4626Zapper).creationCode;
53+
bytecodes[5].source =
54+
"https://github.com/Gearbox-protocol/integrations-v3/blob/883aad9cffe8ea77258f806b6ebbf34a013d9348/contracts/zappers/ERC4626Zapper.sol";
55+
56+
bytecodes[6].contractType = "ZAPPER::STAKED_ERC4626";
57+
bytecodes[6].version = 3_10;
58+
bytecodes[6].initCode = type(StakedERC4626Zapper).creationCode;
59+
bytecodes[6].source =
60+
"https://github.com/Gearbox-protocol/integrations-v3/blob/883aad9cffe8ea77258f806b6ebbf34a013d9348/contracts/zappers/StakedERC4626Zapper.sol";
61+
}
62+
}

0 commit comments

Comments
 (0)