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/ QuipuSwap connector for Tezos chain #252

Merged
merged 16 commits into from
Jan 10, 2024
Merged
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
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"@injectivelabs/sdk-ts": "^1.10.58",
"@pancakeswap/sdk": "^4.0.0",
"@pancakeswap/smart-router": "^4.2.1",
"@pancakeswap/tokens": "^0.1.6",
"@pancakeswap/swap-sdk-core": "^1.0.0",
"@pancakeswap/tokens": "^0.1.6",
"@pancakeswap/v3-core": "^1.0.2",
"@pancakeswap/v3-periphery": "^1.0.2",
"@pancakeswap/v3-sdk": "^3.7.0",
Expand Down Expand Up @@ -93,7 +93,9 @@
"near-api-js": "1.0.0",
"promise-retry": "^2.0.1",
"quickswap-sdk": "^3.0.8",
"quipuswap-v3-sdk": "^0.0.7",
"swagger-ui-express": "^4.1.6",
"swap-router-sdk": "^1.21.1",
"tslib": "^2.3.1",
"uuid": "^8.3.2",
"vvs-sdk": "^2.4.0",
Expand Down
24 changes: 18 additions & 6 deletions src/amm/amm.controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ import {
trade as plentyTrade,
estimateGas as plentyEstimateGas,
} from '../connectors/plenty/plenty.controllers';
import {
price as quipuPrice,
trade as quipuTrade,
estimateGas as quipuEstimateGas,
} from '../connectors/quipuswap/quipuswap.controllers';
import {
getInitializedChain,
getConnector,
Expand All @@ -75,20 +80,23 @@ import {
import { Algorand } from '../chains/algorand/algorand';
import { Tinyman } from '../connectors/tinyman/tinyman';
import { Plenty } from '../connectors/plenty/plenty';
import { QuipuSwap } from '../connectors/quipuswap/quipuswap';

export async function price(req: PriceRequest): Promise<PriceResponse> {
const chain = await getInitializedChain<
Algorand | Ethereumish | Nearish | Tezosish
>(req.chain, req.network);
const connector: Uniswapish | RefAMMish | Tinyman | Plenty =
await getConnector<Uniswapish | RefAMMish | Tinyman | Plenty>(
const connector: Uniswapish | RefAMMish | Tinyman | Plenty | QuipuSwap =
fengtality marked this conversation as resolved.
Show resolved Hide resolved
await getConnector<Uniswapish | RefAMMish | Tinyman | Plenty | QuipuSwap>(
req.chain,
req.network,
req.connector
);

if (connector instanceof Plenty) {
return plentyPrice(<Tezosish>chain, connector, req);
} else if (connector instanceof QuipuSwap) {
return quipuPrice(<Tezosish>chain, connector, req);
} else if ('routerAbi' in connector) {
// we currently use the presence of routerAbi to distinguish Uniswapish from RefAMMish
return uniswapPrice(<Ethereumish>chain, connector, req);
Expand All @@ -103,15 +111,17 @@ export async function trade(req: TradeRequest): Promise<TradeResponse> {
const chain = await getInitializedChain<
Algorand | Ethereumish | Nearish | Tezosish
>(req.chain, req.network);
const connector: Uniswapish | RefAMMish | Tinyman | Plenty =
await getConnector<Uniswapish | RefAMMish | Tinyman | Plenty>(
const connector: Uniswapish | RefAMMish | Tinyman | Plenty | QuipuSwap =
await getConnector<Uniswapish | RefAMMish | Tinyman | Plenty | QuipuSwap>(
req.chain,
req.network,
req.connector
);

if (connector instanceof Plenty) {
return plentyTrade(<Tezosish>chain, connector, req);
} else if (connector instanceof QuipuSwap) {
return quipuTrade(<Tezosish>chain, connector, req);
} else if ('routerAbi' in connector) {
// we currently use the presence of routerAbi to distinguish Uniswapish from RefAMMish
return uniswapTrade(<Ethereumish>chain, connector, req);
Expand Down Expand Up @@ -190,15 +200,17 @@ export async function estimateGas(
const chain = await getInitializedChain<
Algorand | Ethereumish | Nearish | Tezosish
>(req.chain, req.network);
const connector: Uniswapish | RefAMMish | Tinyman | Plenty =
await getConnector<Uniswapish | RefAMMish | Plenty>(
const connector: Uniswapish | RefAMMish | Tinyman | Plenty | QuipuSwap =
await getConnector<Uniswapish | RefAMMish | Plenty | QuipuSwap>(
req.chain,
req.network,
req.connector
);

if (connector instanceof Plenty) {
return plentyEstimateGas(<Tezosish>chain, connector);
} else if (connector instanceof QuipuSwap) {
return quipuEstimateGas(<Tezosish>chain, connector);
} else if ('routerAbi' in connector) {
// we currently use the presence of routerAbi to distinguish Uniswapish from RefAMMish
return uniswapEstimateGas(<Ethereumish>chain, connector);
Expand Down
3 changes: 3 additions & 0 deletions src/chains/tezos/tezos.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ export class TezosBase {
if (spender === 'plenty') {
// plenty doesn't need an allowance
return { value: constants.MaxUint256, decimals: tokenDecimals };
} else if (spender === 'quipuswap') {
// quipuswap doesn't need an allowance
return { value: constants.MaxUint256, decimals: tokenDecimals };
}

let value = BigNumber.from(0);
Expand Down
7 changes: 7 additions & 0 deletions src/connectors/connectors.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { CurveConfig } from './curve/curveswap.config';
import { PlentyConfig } from './plenty/plenty.config';
import { XRPLCLOBConfig } from './xrpl/xrpl.clob.config';
import { KujiraConfig } from './kujira/kujira.config';
import { QuipuswapConfig } from './quipuswap/quipuswap.config';

export namespace ConnectorsRoutes {
export const router = Router();
Expand Down Expand Up @@ -162,6 +163,12 @@ export namespace ConnectorsRoutes {
'Enter your kujira account number (input 0 if unsure) >>> ',
},
},
{
name: 'quipuswap',
trading_type: QuipuswapConfig.config.tradingTypes,
chain_type: QuipuswapConfig.config.chainType,
available_networks: QuipuswapConfig.config.availableNetworks,
}
],
});
})
Expand Down
31 changes: 31 additions & 0 deletions src/connectors/quipuswap/quipuswap.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { ConfigManagerV2 } from '../../services/config-manager-v2';
import { AvailableNetworks } from '../../services/config-manager-types';

export namespace QuipuswapConfig {
export interface NetworkConfig {
allowedSlippage: string;
gasLimitEstimate: number;
apiUrl: (network: string) => string;
tradingTypes: Array<string>;
availableNetworks: Array<AvailableNetworks>;
chainType: string;
}

export const config: NetworkConfig = {
allowedSlippage: ConfigManagerV2.getInstance().get(
'quipuswap.allowedSlippage'
),
gasLimitEstimate: ConfigManagerV2.getInstance().get(
'quipuswap.gasLimitEstimate'
),
apiUrl: (network: string) =>
ConfigManagerV2.getInstance().get(
'quipuswap.network.' + network + '.apiUrl'
),
tradingTypes: ['AMM'],
chainType: 'TEZOS',
availableNetworks: [
{ chain: 'tezos', networks: ['mainnet'] },
],
};
}
Loading
Loading