Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/balancer connector #130

Closed
Closed
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"test:scripts": "jest -i --verbose ./test-scripts/*.test.ts"
},
"dependencies": {
"@balancer-labs/sdk": "^1.1.2",
"@cosmjs/proto-signing": "^0.28.10",
"@cosmjs/stargate": "^0.28.13",
"@crocswap/sdk": "^2.4.5",
Expand Down
6 changes: 6 additions & 0 deletions src/chains/ethereum/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Perp } from '../../connectors/perp/perp';
import { SushiswapConfig } from '../../connectors/sushiswap/sushiswap.config';
import { OpenoceanConfig } from '../../connectors/openocean/openocean.config';
import { ZigZagConfig } from '../../connectors/zigzag/zigzag.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 @@ -196,6 +197,11 @@ export class Ethereum extends EthereumBase implements Ethereumish {
spender = OpenoceanConfig.config.routerAddress('ethereum', this._chain);
} else if (reqSpender === 'zigzag') {
spender = ZigZagConfig.config.contractAddress(this._chain);
} else if (reqSpender === 'balancer') {
spender = BalancerConfig.config.balancerV2VaultAddress(
this.chainName,
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 === 'pancakeswap' ||
val === 'xsswap' ||
val === 'zigzag' ||
val === 'balancer' ||
isAddress(val))
);

Expand Down
6 changes: 6 additions & 0 deletions src/chains/polygon/polygon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { UniswapConfig } from '../../connectors/uniswap/uniswap.config';
import { Ethereumish } from '../../services/common-interfaces';
import { ConfigManagerV2 } from '../../services/config-manager-v2';
import { OpenoceanConfig } from '../../connectors/openocean/openocean.config';
import { BalancerConfig } from '../../connectors/balancer/balancer.config';

export class Polygon extends EthereumBase implements Ethereumish {
private static _instances: { [name: string]: Polygon };
Expand Down Expand Up @@ -83,6 +84,11 @@ export class Polygon extends EthereumBase implements Ethereumish {
);
} else if (reqSpender === 'openocean') {
spender = OpenoceanConfig.config.routerAddress('polygon', this._chain);
} else if (reqSpender === 'balancer') {
spender = BalancerConfig.config.balancerV2VaultAddress(
this.chainName,
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
43 changes: 43 additions & 0 deletions src/connectors/balancer/balancer.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { ConfigManagerV2 } from '../../services/config-manager-v2';
import { AvailableNetworks } from '../../services/config-manager-types';

export namespace BalancerConfig {
export interface NetworkConfig {
allowedSlippage: string;
gasLimitEstimate: number;
ttl: number;
maximumHops: number;
balancerV2VaultAddress: (chain: string, network: string) => string;
tradingTypes: Array<string>;
chainType: string;
availableNetworks: Array<AvailableNetworks>;
}

export const config: NetworkConfig = {
allowedSlippage: ConfigManagerV2.getInstance().get(
'balancer.allowedSlippage'
),
gasLimitEstimate: ConfigManagerV2.getInstance().get(
'balancer.gasLimitEstimate'
),
ttl: ConfigManagerV2.getInstance().get('balancer.ttl'),
maximumHops: ConfigManagerV2.getInstance().get('balancer.maximumHops'),
balancerV2VaultAddress: (chain: string, network: string) =>
ConfigManagerV2.getInstance().get(
'balancer.contractAddresses.' +
chain +
'.' +
network +
'.balancerV2VaultAddress'
),
tradingTypes: ['AMM'],
chainType: 'EVM',
availableNetworks: [
{
chain: 'ethereum',
networks: ['mainnet', 'goerli', 'arbitrum_one'],
},
{ chain: 'polygon', networks: ['mainnet', 'mumbai'] },
],
};
}
Loading