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/carbondefi #256

Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0bea44e
Initial commit
tiagofilipenunes Nov 26, 2023
f7dc80b
Update carbon CLOB
tiagofilipenunes Dec 4, 2023
2300b05
Add carbon AMM connector and tests
tiagofilipenunes Dec 6, 2023
7450339
Add carbon-sdk
tiagofilipenunes Dec 6, 2023
81cfb48
Update imports to use @bancor/carbon-sdk
tiagofilipenunes Dec 6, 2023
9256a97
Remove trailling slash
tiagofilipenunes Dec 7, 2023
474eb52
Fix carbon schema
tiagofilipenunes Dec 7, 2023
158719d
Update tests against new SDK version
tiagofilipenunes Dec 7, 2023
6ff1a0a
Improve test coverage and fix bugs
tiagofilipenunes Dec 8, 2023
3135bcc
Rename carbonAMM and fix carbonCLOB balance
tiagofilipenunes Dec 14, 2023
651f201
Update Carbon SDK
tiagofilipenunes Dec 18, 2023
9bf62fc
Update yarn.lock
tiagofilipenunes Dec 18, 2023
91cace4
Merge branch 'main' into tiagofilipenunes-feat/carbondefi
tiagofilipenunes Dec 18, 2023
76d183b
Change name in Carbon AMM test
tiagofilipenunes Dec 19, 2023
d1c5a25
Add carbon-sdk import paths to jest config (jestjs/jest#12270)
tiagofilipenunes Dec 19, 2023
4633fe0
Clean-up Carbon CLOB tests
tiagofilipenunes Dec 19, 2023
083d467
Clean-up Carbon AMM tests
tiagofilipenunes Dec 19, 2023
7ee79ae
Clean-up constructors
tiagofilipenunes Dec 20, 2023
5ae7294
Update balances to remove decimals and count from multiple user strat…
tiagofilipenunes Dec 22, 2023
a2ffd6e
Add test to balances endpoint
tiagofilipenunes Dec 22, 2023
ef04db2
Merge branch 'main' into tiagofilipenunes-feat/carbondefi
tiagofilipenunes Jan 9, 2024
2b96eee
Move tests to test-bronze folder
tiagofilipenunes Jan 9, 2024
c4cc494
Add ETH tests
tiagofilipenunes Jan 9, 2024
b249d5b
Add native token to getTokenByAddress
tiagofilipenunes Jan 9, 2024
143ea6b
Add carbon controllers
tiagofilipenunes Jan 9, 2024
b464c89
Add carbon controllers to amm controllers
tiagofilipenunes Jan 9, 2024
98102fe
Remove CarbonCLOB
tiagofilipenunes Jan 9, 2024
695facb
Merge branch 'development' into tiagofilipenunes-feat/carbondefi
tiagofilipenunes Feb 1, 2024
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
9 changes: 9 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ module.exports = {
globalTeardown: '<rootDir>/test/teardown.ts',
moduleNameMapper: {
eccrypto: '<rootDir>/test/mock/eccrypto-mock.js',
// Add carbon sdk subpath imports that are unsupported until jest v29.4.0
'@bancor/carbon-sdk/strategy-management':
'<rootDir>/node_modules/@bancor/carbon-sdk/dist/strategy-management/index.cjs',
'@bancor/carbon-sdk/utils':
'<rootDir>/node_modules/@bancor/carbon-sdk/dist/utils/index.cjs',
'@bancor/carbon-sdk/contracts-api':
'<rootDir>/node_modules/@bancor/carbon-sdk/dist/contracts-api/index.cjs',
'@bancor/carbon-sdk/chain-cache':
'<rootDir>/node_modules/@bancor/carbon-sdk/dist/chain-cache/index.cjs',
},
testPathIgnorePatterns: ['/node_modules/', 'test-helpers'],
};
3 changes: 2 additions & 1 deletion 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": {
"@bancor/carbon-sdk": "^0.0.93-DEV",
"@cosmjs/proto-signing": "^0.31.1",
"@cosmjs/stargate": "^0.31.1",
"@crocswap/sdk": "^2.4.5",
Expand Down Expand Up @@ -153,4 +154,4 @@
"resolutions": {
"web3-utils": "1.7.3"
}
}
}
6 changes: 6 additions & 0 deletions src/chains/ethereum/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Perp } from '../../connectors/perp/perp';
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';

// MKR does not match the ERC20 perfectly so we need to use a separate ABI.
const MKR_ADDRESS = '0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2';
Expand Down Expand Up @@ -188,6 +189,11 @@ export class Ethereum extends EthereumBase implements Ethereumish {
);
} else if (reqSpender === 'uniswapLP') {
spender = UniswapConfig.config.uniswapV3NftManagerAddress(this._chain);
} else if (reqSpender === 'carbon' || reqSpender === 'carbonamm') {
spender = CarbonConfig.config.carbonContractsConfig(
'ethereum',
this._chain
).carbonControllerAddress;
} else if (reqSpender === 'perp') {
const perp = Perp.getInstance(this._chain, 'optimism');
if (!perp.ready()) {
Expand Down
2 changes: 2 additions & 0 deletions src/chains/ethereum/ethereum.validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export const validateSpender: Validator = mkValidator(
val === 'pancakeswap' ||
val === 'xsswap' ||
val === 'curve' ||
val === 'carbon' ||
val === 'carbonamm' ||
isAddress(val))
);

Expand Down
60 changes: 60 additions & 0 deletions src/connectors/carbon/carbon.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { ContractsConfig } from '@bancor/carbon-sdk/contracts-api';
import { MatchType } from '@bancor/carbon-sdk';
import { AvailableNetworks } from '../../services/config-manager-types';
import { ConfigManagerV2 } from '../../services/config-manager-v2';

export namespace CarbonConfig {
export interface NetworkConfig {
allowedSlippage: string;
gasLimitEstimate: number;
ttl: number;
tradingTypes: (type: string) => Array<string>;
chainType: string;
matchType: MatchType;
availableNetworks: Array<AvailableNetworks>;
carbonContractsConfig: (
chain: string,
network: string
) => Required<ContractsConfig>;
}

export const config: NetworkConfig = {
allowedSlippage: ConfigManagerV2.getInstance().get(
`carbon.allowedSlippage`
),
gasLimitEstimate: ConfigManagerV2.getInstance().get(
`carbon.gasLimitEstimate`
),
ttl: ConfigManagerV2.getInstance().get(`carbon.ttl`),
tradingTypes: (type: string) => {
return type === 'swap' ? ['AMM'] : ['CLOB_SPOT'];
},
chainType: 'EVM',
matchType: MatchType.Fast,
availableNetworks: [
{
chain: 'ethereum',
networks: Object.keys(
ConfigManagerV2.getInstance().get('carbon.contractAddresses.ethereum')
).filter((network) =>
Object.keys(
ConfigManagerV2.getInstance().get('ethereum.networks')
).includes(network)
),
},
],
carbonContractsConfig: (chain: string, network: string) => {
return {
carbonControllerAddress: ConfigManagerV2.getInstance().get(
`carbon.contractAddresses.${chain}.${network}.carbonControllerAddress`
),
multiCallAddress: ConfigManagerV2.getInstance().get(
`carbon.contractAddresses.${chain}.${network}.multiCallAddress`
),
voucherAddress: ConfigManagerV2.getInstance().get(
`carbon.contractAddresses.${chain}.${network}.voucherAddress`
),
};
},
};
}
Loading