Skip to content

Commit bedc79e

Browse files
authored
Merge pull request #5 from xdecentralix/gyroscope-eclps
Gyroscope eclps
2 parents 89c58e4 + af0431e commit bedc79e

File tree

59 files changed

+13534
-51
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+13534
-51
lines changed

crates/contracts/artifacts/BalancerV2GyroECLPPool.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

crates/contracts/artifacts/BalancerV2GyroECLPPoolFactory.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

crates/contracts/artifacts/BalancerV3GyroECLPPool.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

crates/contracts/artifacts/BalancerV3GyroECLPPoolFactory.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

crates/contracts/build.rs

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,65 @@ fn main() {
913913
},
914914
)
915915
});
916+
generate_contract_with_config("BalancerV2GyroECLPPoolFactory", |builder| {
917+
builder
918+
.add_network(
919+
MAINNET,
920+
Network {
921+
address: addr("0x412a5b2e7a678471985542757a6855847d4931d5"),
922+
// <https://etherscan.io/tx/0xa198beb9b3373d3a58e9c788ca6dc580b3b72b386b2cd2a77174a45aa3d1c900>
923+
deployment_information: Some(DeploymentInformation::BlockNumber(17672894)),
924+
},
925+
)
926+
.add_network(
927+
OPTIMISM,
928+
Network {
929+
address: addr("0x9b683cA24B0e013512E2566b68704dBe9677413c"),
930+
// <https://optimistic.etherscan.io/tx/0x3520639344dac880436e16fcaf5ea7c0f6d5ba1f14ea463085f00dd98464c5cc>
931+
deployment_information: Some(DeploymentInformation::BlockNumber(97253023)),
932+
},
933+
)
934+
.add_network(
935+
ARBITRUM_ONE,
936+
Network {
937+
address: addr("0xdCA5f1F0d7994A32BC511e7dbA0259946653Eaf6"),
938+
// <https://arbiscan.io/tx/0x6380d67d8a44b0f5df9e32e00fe30bf2cb252ea0f688a604f66ed09582b70ac8>
939+
deployment_information: Some(DeploymentInformation::BlockNumber(124858976)),
940+
},
941+
)
942+
.add_network(
943+
BASE,
944+
Network {
945+
address: addr("0x15e86Be6084C6A5a8c17732D398dFbC2Ec574CEC"),
946+
// <https://basescan.org/tx/0xe0ae587a5156908b4a2196edba18fa8b9cd9c2061e276316698020d9ccaeec74>
947+
deployment_information: Some(DeploymentInformation::BlockNumber(12940659)),
948+
},
949+
)
950+
.add_network(
951+
POLYGON,
952+
Network {
953+
address: addr("0x1a79A24Db0F73e9087205287761fC9C5C305926b"),
954+
// <https://polygonscan.com/tx/0x67c4169944411128d14bddbeb3ea19051e443c81d78b37467bd63ef56bcb983c>
955+
deployment_information: Some(DeploymentInformation::BlockNumber(41209677)),
956+
},
957+
)
958+
.add_network(
959+
GNOSIS,
960+
Network {
961+
address: addr("0x5d3Be8aaE57bf0D1986Ff7766cC9607B6cC99b89"),
962+
// <https://gnosisscan.io/tx/0x3add81de7eeb3231ef286a6a87d8235898f831a8aade3e68b5077ceb95f73aba>
963+
deployment_information: Some(DeploymentInformation::BlockNumber(33759936)),
964+
},
965+
)
966+
.add_network(
967+
AVALANCHE,
968+
Network {
969+
address: addr("0x41E9ac0bfed353c2dE21a980dA0EbB8A464D946A"),
970+
// <https://snowscan.xyz/tx/0xbd4f1675aaa2f52a0b15d5b842438393fc218b341c4154adca8d03b279b7675b>
971+
deployment_information: Some(DeploymentInformation::BlockNumber(50484541)),
972+
},
973+
)
974+
});
916975
generate_contract("BalancerV2WeightedPool");
917976
generate_contract_with_config("BalancerV2StablePool", |builder| {
918977
builder.add_method_alias(
@@ -923,6 +982,7 @@ fn main() {
923982
});
924983
generate_contract("BalancerV2LiquidityBootstrappingPool");
925984
generate_contract("BalancerV2ComposableStablePool");
985+
generate_contract("BalancerV2GyroECLPPool");
926986

927987
// Balancer V3 contracts
928988
generate_contract_with_config("BalancerV3Vault", |builder| {
@@ -1204,9 +1264,69 @@ fn main() {
12041264
},
12051265
)
12061266
});
1267+
generate_contract_with_config("BalancerV3GyroECLPPoolFactory", |builder| {
1268+
builder
1269+
.add_network(
1270+
ARBITRUM_ONE,
1271+
Network {
1272+
address: addr("0x88ED12A90142fDBFe2a28f7d5b48927254C7e760"),
1273+
// <https://arbiscan.io/tx/0x4d698081792d9437c064c3ce0509ca126f149027a3174e7aa6ebbd351f7bcd80>
1274+
deployment_information: Some(DeploymentInformation::BlockNumber(315658096)),
1275+
},
1276+
)
1277+
.add_network(
1278+
AVALANCHE,
1279+
Network {
1280+
address: addr("0x268E2EE1413D768b6e2dc3F5a4ddc9Ae03d9AF42"),
1281+
// <https://snowscan.xyz/tx/0x147f2acd80d5417dfe3004ab9f90e5c9ad6f4067e1c6993231d050c6efb0ee46>
1282+
deployment_information: Some(DeploymentInformation::BlockNumber(59965989)),
1283+
},
1284+
)
1285+
.add_network(
1286+
BASE,
1287+
Network {
1288+
address: addr("0x5F6848976C2914403B425F18B589A65772F082E3"),
1289+
// <https://basescan.org/tx/0xe99692e0c80903e7b875cbb76a77febf86c10e054d3d98f1f886366101c33a22>
1290+
deployment_information: Some(DeploymentInformation::BlockNumber(27590349)),
1291+
},
1292+
)
1293+
.add_network(
1294+
GNOSIS,
1295+
Network {
1296+
address: addr("0xEa924b45a3fcDAAdf4E5cFB1665823B8F8F2039B"),
1297+
// <https://gnosisscan.io/tx/0xfb731a5912f589b4123d32d6fa9a8817012760d8056e336dd4ecdc719f9e1892>
1298+
deployment_information: Some(DeploymentInformation::BlockNumber(39033094)),
1299+
},
1300+
)
1301+
.add_network(
1302+
MAINNET,
1303+
Network {
1304+
address: addr("0xE9B0a3bc48178D7FE2F5453C8bc1415d73F966d0"),
1305+
// <https://etherscan.io/tx/0x795e515da7dfd9b5f6c62fe95efe9c87063f68592805021154ff5ae870b57a09>
1306+
deployment_information: Some(DeploymentInformation::BlockNumber(22046343)),
1307+
},
1308+
)
1309+
.add_network(
1310+
OPTIMISM,
1311+
Network {
1312+
address: addr("0x22625eEDd92c81a219A83e1dc48f88d54786B017"),
1313+
// <https://optimistic.etherscan.io/tx/0xeac4f4560a14aadb9ad0bece9884f3e527aa92d3fc35f67e380c2f20103ce696>
1314+
deployment_information: Some(DeploymentInformation::BlockNumber(133969692)),
1315+
},
1316+
)
1317+
.add_network(
1318+
SEPOLIA,
1319+
Network {
1320+
address: addr("0x589cA6855C348d831b394676c25B125BcdC7F8ce"),
1321+
// <https://sepolia.etherscan.io/tx/0xb9431fb3bec8a3a2320f63b1da9d96e62bd152b8fff4634cd92e0e3530f32783>
1322+
deployment_information: Some(DeploymentInformation::BlockNumber(7901684)),
1323+
},
1324+
)
1325+
});
12071326

12081327
generate_contract("BalancerV3WeightedPool");
12091328
generate_contract("BalancerV3StablePool");
1329+
generate_contract("BalancerV3GyroECLPPool");
12101330
generate_contract("IRateProvider");
12111331

12121332
generate_contract_with_config("BaoswapRouter", |builder| {

crates/contracts/src/bin/vendor.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ fn run() -> Result<()> {
9191
"BalancerV2NoProtocolFeeLiquidityBootstrappingPoolFactory",
9292
"balancer/balancer-deployments/48cb2fcbf17769f09c4ed905613b04db7707cfde/v2/tasks/20211202-no-protocol-fee-lbp/artifact/NoProtocolFeeLiquidityBootstrappingPoolFactory.json",
9393
)?
94+
.github(
95+
"BalancerV2GyroECLPPoolFactory",
96+
"gyrostable/gyro-pools/8e83ed6946e77cb8f438d1ce3ae615f490c27f4e/build/deployments/1/0xA87217d855EDad15d63255DB176B810b0325BDa2.json",
97+
)?
9498
.github(
9599
"BalancerV2LiquidityBootstrappingPool",
96100
"balancer-labs/balancer-v2-monorepo/7a643349a5ef4511234b19a33e3f18d30770cb66/pkg/deployments/tasks/20210721-liquidity-bootstrapping-pool/abi/LiquidityBootstrappingPool.json",
@@ -106,6 +110,10 @@ fn run() -> Result<()> {
106110
.github(
107111
"BalancerV2ComposableStablePool",
108112
"balancer/balancer-deployments/48cb2fcbf17769f09c4ed905613b04db7707cfde/v2/deprecated/20230206-composable-stable-pool-v3/artifact/ComposableStablePool.json",
113+
)?
114+
.github(
115+
"BalancerV2GyroECLPPool",
116+
"gyrostable/gyro-pools/8e83ed6946e77cb8f438d1ce3ae615f490c27f4e/build/deployments/1/0x767CB26E38beBddfd857d4Ad426d8ff5Bc0fAc2f.json",
109117
)?;
110118

111119
// Balancer V2 contracts - ABI Only
@@ -123,7 +131,7 @@ fn run() -> Result<()> {
123131
// Balancer V3 contracts - Full
124132
vendor
125133
.full()
126-
// A bit of a hack: We use the VaultExtension ABI for the Vault contract to get all the methods due to the proxy pattern
134+
// We use the VaultExtension ABI for the Vault contract to get all the methods due to the proxy pattern
127135
.github(
128136
"BalancerV3Vault",
129137
"balancer/balancer-deployments/48cb2fcbf17769f09c4ed905613b04db7707cfde/v3/tasks/20241204-v3-vault/artifact/VaultExtension.json",
@@ -143,6 +151,10 @@ fn run() -> Result<()> {
143151
.github(
144152
"BalancerV3StablePoolFactoryV2",
145153
"balancer/balancer-deployments/48cb2fcbf17769f09c4ed905613b04db7707cfde/v3/tasks/20250324-v3-stable-pool-v2/artifact/StablePoolFactory.json",
154+
)?
155+
.github(
156+
"BalancerV3GyroECLPPoolFactory",
157+
"balancer/balancer-deployments/7a16f4463fb33d5f8c63118b6427b73fdb727cfc/v3/tasks/20250124-v3-gyro-eclp/artifact/GyroECLPPoolFactory.json",
146158
)?;
147159

148160
// Balancer V3 contracts - ABI Only
@@ -155,6 +167,10 @@ fn run() -> Result<()> {
155167
.github(
156168
"BalancerV3StablePool",
157169
"balancer/balancer-deployments/48cb2fcbf17769f09c4ed905613b04db7707cfde/v3/deprecated/20241205-v3-stable-pool/artifact/StablePool.json",
170+
)?
171+
.github(
172+
"BalancerV3GyroECLPPool",
173+
"balancer/balancer-deployments/7a16f4463fb33d5f8c63118b6427b73fdb727cfc/v3/tasks/20250124-v3-gyro-eclp/artifact/GyroECLPPool.json",
158174
)?;
159175

160176
// CowSwap contracts - Full

crates/contracts/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ include_contracts! {
5959
BalancerV2ComposableStablePoolFactoryV4;
6060
BalancerV2ComposableStablePoolFactoryV5;
6161
BalancerV2ComposableStablePoolFactoryV6;
62+
BalancerV2GyroECLPPool;
63+
BalancerV2GyroECLPPoolFactory;
6264
BalancerV2LiquidityBootstrappingPool;
6365
BalancerV2LiquidityBootstrappingPoolFactory;
6466
BalancerV2NoProtocolFeeLiquidityBootstrappingPoolFactory;
@@ -77,6 +79,8 @@ include_contracts! {
7779
BalancerV3StablePool;
7880
BalancerV3StablePoolFactory;
7981
BalancerV3StablePoolFactoryV2;
82+
BalancerV3GyroECLPPool;
83+
BalancerV3GyroECLPPoolFactory;
8084
BaoswapRouter;
8185
CowAmm;
8286
CowAmmConstantProductFactory;
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
use {
2+
crate::{
3+
boundary::Result,
4+
domain::{
5+
eth,
6+
liquidity::{self, balancer},
7+
},
8+
},
9+
shared::sources::balancer_v2::pool_fetching::GyroEPoolVersion,
10+
solver::liquidity::{GyroEPoolOrder, balancer_v2},
11+
};
12+
13+
/// Median gas used per BalancerSwapGivenOutInteraction.
14+
// estimated with https://dune.com/queries/639857
15+
const GAS_PER_SWAP: u64 = 88_892;
16+
17+
pub fn to_domain(id: liquidity::Id, pool: GyroEPoolOrder) -> Result<liquidity::Liquidity> {
18+
Ok(liquidity::Liquidity {
19+
id,
20+
gas: GAS_PER_SWAP.into(),
21+
kind: liquidity::Kind::BalancerV2GyroE(balancer::v2::gyro_e::Pool {
22+
vault: vault(&pool),
23+
id: pool_id(&pool),
24+
reserves: balancer::v2::gyro_e::Reserves::try_new(
25+
pool.reserves
26+
.into_iter()
27+
.map(|(token, reserve)| {
28+
Ok(balancer::v2::gyro_e::Reserve {
29+
asset: eth::Asset {
30+
token: token.into(),
31+
amount: reserve.balance.into(),
32+
},
33+
scale: balancer::v2::ScalingFactor::from_raw(
34+
reserve.scaling_factor.as_uint256(),
35+
)?,
36+
})
37+
})
38+
.collect::<Result<_>>()?,
39+
)?,
40+
fee: balancer::v2::Fee::from_raw(pool.fee.as_uint256()),
41+
version: match pool.version {
42+
GyroEPoolVersion::V1 => balancer::v2::gyro_e::Version::V1,
43+
},
44+
// Convert Gyroscope E-CLP static parameters from SBfp to SignedFixedPoint
45+
params_alpha: balancer::v2::gyro_e::SignedFixedPoint::from_raw(
46+
pool.params_alpha.as_i256(),
47+
),
48+
params_beta: balancer::v2::gyro_e::SignedFixedPoint::from_raw(
49+
pool.params_beta.as_i256(),
50+
),
51+
params_c: balancer::v2::gyro_e::SignedFixedPoint::from_raw(pool.params_c.as_i256()),
52+
params_s: balancer::v2::gyro_e::SignedFixedPoint::from_raw(pool.params_s.as_i256()),
53+
params_lambda: balancer::v2::gyro_e::SignedFixedPoint::from_raw(
54+
pool.params_lambda.as_i256(),
55+
),
56+
tau_alpha_x: balancer::v2::gyro_e::SignedFixedPoint::from_raw(
57+
pool.tau_alpha_x.as_i256(),
58+
),
59+
tau_alpha_y: balancer::v2::gyro_e::SignedFixedPoint::from_raw(
60+
pool.tau_alpha_y.as_i256(),
61+
),
62+
tau_beta_x: balancer::v2::gyro_e::SignedFixedPoint::from_raw(pool.tau_beta_x.as_i256()),
63+
tau_beta_y: balancer::v2::gyro_e::SignedFixedPoint::from_raw(pool.tau_beta_y.as_i256()),
64+
u: balancer::v2::gyro_e::SignedFixedPoint::from_raw(pool.u.as_i256()),
65+
v: balancer::v2::gyro_e::SignedFixedPoint::from_raw(pool.v.as_i256()),
66+
w: balancer::v2::gyro_e::SignedFixedPoint::from_raw(pool.w.as_i256()),
67+
z: balancer::v2::gyro_e::SignedFixedPoint::from_raw(pool.z.as_i256()),
68+
d_sq: balancer::v2::gyro_e::SignedFixedPoint::from_raw(pool.d_sq.as_i256()),
69+
}),
70+
})
71+
}
72+
73+
fn vault(pool: &GyroEPoolOrder) -> eth::ContractAddress {
74+
pool.settlement_handling
75+
.as_any()
76+
.downcast_ref::<balancer_v2::SettlementHandler>()
77+
.expect("downcast balancer settlement handler")
78+
.vault()
79+
.address()
80+
.into()
81+
}
82+
83+
fn pool_id(pool: &GyroEPoolOrder) -> balancer::v2::Id {
84+
pool.settlement_handling
85+
.as_any()
86+
.downcast_ref::<balancer_v2::SettlementHandler>()
87+
.expect("downcast balancer settlement handler")
88+
.pool_id()
89+
.into()
90+
}
91+
92+
pub fn to_interaction(
93+
pool: &liquidity::balancer::v2::gyro_e::Pool,
94+
input: &liquidity::MaxInput,
95+
output: &liquidity::ExactOutput,
96+
receiver: &eth::Address,
97+
) -> eth::Interaction {
98+
super::to_interaction(
99+
&super::Pool {
100+
vault: pool.vault,
101+
id: pool.id,
102+
},
103+
input,
104+
output,
105+
receiver,
106+
)
107+
}

crates/driver/src/boundary/liquidity/balancer/v2/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use {
1111
chain::Chain,
1212
contracts::{
1313
BalancerV2ComposableStablePoolFactory,
14+
BalancerV2GyroECLPPoolFactory,
1415
BalancerV2LiquidityBootstrappingPoolFactory,
1516
BalancerV2StablePoolFactoryV2,
1617
BalancerV2Vault,
@@ -37,6 +38,7 @@ use {
3738
std::sync::Arc,
3839
};
3940

41+
pub mod gyro_e;
4042
pub mod stable;
4143
pub mod weighted;
4244

@@ -188,6 +190,18 @@ async fn init_liquidity(
188190
)
189191
})
190192
.collect::<Vec<_>>(),
193+
config
194+
.gyro_e
195+
.iter()
196+
.map(|&factory| {
197+
(
198+
BalancerFactoryKind::GyroE,
199+
BalancerV2GyroECLPPoolFactory::at(&web3, factory.into())
200+
.raw_instance()
201+
.clone(),
202+
)
203+
})
204+
.collect::<Vec<_>>(),
191205
]
192206
.into_iter()
193207
.flatten()

0 commit comments

Comments
 (0)