Skip to content

Commit

Permalink
Merge pull request #280 from vic-en/feat/balancer
Browse files Browse the repository at this point in the history
feat/ balancer connector
  • Loading branch information
fengtality authored Jun 2, 2024
2 parents 23580e6 + 8384e51 commit 87a3d66
Show file tree
Hide file tree
Showing 20 changed files with 1,269 additions and 17 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
},
"dependencies": {
"@cosmjs/amino": "^0.32.2",
"@balancer-labs/sdk": "^1.1.5",
"@bancor/carbon-sdk": "^0.0.93-DEV",
"@cosmjs/proto-signing": "^0.31.1",
"@cosmjs/stargate": "^0.31.1",
Expand Down
3 changes: 3 additions & 0 deletions src/chains/avalanche/avalanche.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { SushiswapConfig } from '../../connectors/sushiswap/sushiswap.config';
import { ConfigManagerV2 } from '../../services/config-manager-v2';
import { EVMController } from '../ethereum/evm.controllers';
import { Curve } from '../../connectors/curve/curve';
import { BalancerConfig } from '../../connectors/balancer/balancer.config';

export class Avalanche extends EthereumBase implements Ethereumish {
private static _instances: { [name: string]: Avalanche };
Expand Down Expand Up @@ -101,6 +102,8 @@ export class Avalanche extends EthereumBase implements Ethereumish {
throw Error('Curve not ready');
}
spender = curve.router;
} else if (reqSpender === 'balancer') {
spender = BalancerConfig.config.routerAddress(this._chain);
} else {
spender = reqSpender;
}
Expand Down
1 change: 1 addition & 0 deletions src/chains/avalanche/avalanche.validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const validateSpender: Validator = mkValidator(
val === 'traderjoe' ||
val === 'openocean' ||
val === 'sushiswap' ||
val === 'balancer' ||
isAddress(val))
);

Expand Down
3 changes: 3 additions & 0 deletions src/chains/ethereum/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { SushiswapConfig } from '../../connectors/sushiswap/sushiswap.config';
import { OpenoceanConfig } from '../../connectors/openocean/openocean.config';
import { Curve } from '../../connectors/curve/curve';
import { CarbonConfig } from '../../connectors/carbon/carbon.config';
import { BalancerConfig } from '../../connectors/balancer/balancer.config';

// MKR does not match the ERC20 perfectly so we need to use a separate ABI.
const MKR_ADDRESS = '0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2';
Expand Down Expand Up @@ -217,6 +218,8 @@ export class Ethereum extends EthereumBase implements Ethereumish {
throw Error('Curve not ready');
}
spender = curve.router;
} else if (reqSpender === 'balancer') {
spender = BalancerConfig.config.routerAddress(this._chain);
} else {
spender = reqSpender;
}
Expand Down
1 change: 1 addition & 0 deletions src/chains/ethereum/ethereum.validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const validateSpender: Validator = mkValidator(
val === 'xsswap' ||
val === 'curve' ||
val === 'carbonamm' ||
val === 'balancer' ||
isAddress(val))
);

Expand Down
3 changes: 3 additions & 0 deletions src/chains/polygon/polygon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ConfigManagerV2 } from '../../services/config-manager-v2';
import { OpenoceanConfig } from '../../connectors/openocean/openocean.config';
import { EVMController } from '../ethereum/evm.controllers';
import { Curve } from '../../connectors/curve/curve';
import { BalancerConfig } from '../../connectors/balancer/balancer.config';

export class Polygon extends EthereumBase implements Ethereumish {
private static _instances: { [name: string]: Polygon };
Expand Down Expand Up @@ -94,6 +95,8 @@ export class Polygon extends EthereumBase implements Ethereumish {
throw Error('Curve not ready');
}
spender = curve.router;
} else if (reqSpender === 'balancer') {
spender = BalancerConfig.config.routerAddress(this._chain);
} else {
spender = reqSpender;
}
Expand Down
1 change: 1 addition & 0 deletions src/chains/polygon/polygon.validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const validateSpender: Validator = mkValidator(
val === 'sushi' ||
val === 'quickswap' ||
val === 'openocean' ||
val === 'balancer' ||
isAddress(val))
);

Expand Down
23 changes: 23 additions & 0 deletions src/connectors/balancer/balancer.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { buildConfig, NetworkConfig } from '../../network/network.utils';

export namespace BalancerConfig {
export const config: NetworkConfig = buildConfig(
'balancer',
['AMM'],
[
{
chain: 'avalanche',
networks: ['avalanche'],
},
{
chain: 'ethereum',
networks: ['mainnet', 'arbitrum', 'optimism'],
},
{
chain: 'polygon',
networks: ['mainnet'],
},
],
'EVM'
);
}
Loading

0 comments on commit 87a3d66

Please sign in to comment.