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

solana #363

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
"test:scripts": "jest -i --verbose ./test-scripts/*.test.ts"
},
"dependencies": {
"@cosmjs/amino": "^0.32.2",
"@balancer-labs/sdk": "^1.1.5",
"@bancor/carbon-sdk": "^0.0.93-DEV",
"@cosmjs/amino": "^0.32.2",
"@cosmjs/proto-signing": "^0.31.1",
"@cosmjs/stargate": "^0.31.1",
"@cosmjs/tendermint-rpc": "^0.32.2",
Expand All @@ -50,6 +50,7 @@
"@pancakeswap/v3-sdk": "^3.7.0",
"@pangolindex/sdk": "^1.1.0",
"@perp/sdk-curie": "^1.16.0",
"@solana/spl-token": "^0.4.8",
"@sushiswap/sdk": "^5.0.0-canary.116",
"@taquito/rpc": "^17.0.0",
"@taquito/signer": "^17.0.0",
Expand All @@ -73,12 +74,14 @@
"app-root-path": "^3.0.0",
"axios": "^1.6.0",
"big.js": "6.1.1",
"bip39": "^3.1.0",
"bn.js": "^5.2.1",
"body-parser": "^1.19.0",
"chalk": "^4.1.0",
"coinalpha-ref-sdk": "1.1.0",
"dayjs": "^1.10.6",
"decimal.js-light": "^2.5.1",
"ed25519-hd-key": "^1.3.0",
"ethers": "^5.6.2",
"ethers-xdc": "file:./vendor/ethers-xdc",
"express": "^4.17.1",
Expand Down Expand Up @@ -117,7 +120,7 @@
"@babel/runtime": "^7.0",
"@connectis/diff-test-coverage": "^1.5.1",
"@improbable-eng/grpc-web": "^0.13.0",
"@solana/web3.js": "^1.58.0",
"@solana/web3.js": "^1.95.3",
"@types/app-root-path": "^1.2.4",
"@types/big.js": "^6.1.3",
"@types/bs58": "^4.0.1",
Expand All @@ -138,7 +141,7 @@
"@types/ws": "^8.5.3",
"@typescript-eslint/eslint-plugin": "^7.0.2",
"@typescript-eslint/parser": "^7.0.2",
"bs58": "^4.0.1",
"bs58": "^6.0.0",
"copyfiles": "^2.4.1",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
Expand Down
123 changes: 74 additions & 49 deletions src/amm/amm.controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,31 @@ import { Tinyman } from '../connectors/tinyman/tinyman';
import { Plenty } from '../connectors/plenty/plenty';
import { Osmosis } from '../chains/osmosis/osmosis';
import { Carbonamm } from '../connectors/carbon/carbonAMM';
import { Solana } from '../chains/solana/solana';
import { Jupiter } from '../connectors/jupiterswap/jupiter';
import {
jupiterPrice,
jupiterTrade,
} from '../connectors/jupiterswap/jupiter.controller';

export async function price(req: PriceRequest): Promise<PriceResponse> {
const chain = await getInitializedChain<
Algorand | Ethereumish | Nearish | Tezosish | Osmosis
Algorand | Ethereumish | Nearish | Tezosish | Osmosis | Solana
>(req.chain, req.network);
if (chain instanceof Osmosis){
if (chain instanceof Osmosis) {
return chain.controller.price(chain as unknown as Osmosis, req);
}

const connector: Uniswapish | RefAMMish | Tinyman | Plenty =
await getConnector<Uniswapish | RefAMMish | Tinyman | Plenty>(
const connector: Uniswapish | RefAMMish | Tinyman | Plenty | Jupiter =
await getConnector<Uniswapish | RefAMMish | Tinyman | Plenty | Jupiter>(
req.chain,
req.network,
req.connector
req.connector,
);

if (connector instanceof Plenty) {
if (connector instanceof Jupiter) {
return jupiterPrice(<Solana>chain, connector, req);
} else if (connector instanceof Plenty) {
return plentyPrice(<Tezosish>chain, connector, req);
} else if (connector instanceof Carbonamm) {
return carbonPrice(<Ethereumish>chain, connector, req);
Expand All @@ -114,20 +122,22 @@ export async function price(req: PriceRequest): Promise<PriceResponse> {

export async function trade(req: TradeRequest): Promise<TradeResponse> {
const chain = await getInitializedChain<
Algorand | Ethereumish | Nearish | Tezosish | Osmosis
Algorand | Ethereumish | Nearish | Tezosish | Osmosis | Solana
>(req.chain, req.network);
if (chain instanceof Osmosis){
if (chain instanceof Osmosis) {
return chain.controller.trade(chain as unknown as Osmosis, req);
}

const connector: Uniswapish | RefAMMish | Tinyman | Plenty =
await getConnector<Uniswapish | RefAMMish | Tinyman | Plenty>(
const connector: Uniswapish | RefAMMish | Tinyman | Plenty | Jupiter =
await getConnector<Uniswapish | RefAMMish | Tinyman | Plenty | Jupiter>(
req.chain,
req.network,
req.connector
req.connector,
);

if (connector instanceof Plenty) {
if (connector instanceof Jupiter) {
return jupiterTrade(<Solana>chain, connector, req);
} else if (connector instanceof Plenty) {
return plentyTrade(<Tezosish>chain, connector, req);
} else if (connector instanceof Carbonamm) {
return carbonTrade(<Ethereumish>chain, connector, req);
Expand All @@ -142,97 +152,112 @@ export async function trade(req: TradeRequest): Promise<TradeResponse> {
}

export async function addLiquidity(
req: AddLiquidityRequest
req: AddLiquidityRequest,
): Promise<AddLiquidityResponse> {
const chain = await getInitializedChain<Ethereumish | Osmosis>(req.chain, req.network);
if (chain instanceof Osmosis){
const chain = await getInitializedChain<Ethereumish | Osmosis>(
req.chain,
req.network,
);
if (chain instanceof Osmosis) {
return chain.controller.addLiquidity(chain as unknown as Osmosis, req);
}
const connector: UniswapLPish = await getConnector<UniswapLPish>(
req.chain,
req.network,
req.connector
req.connector,
);

return uniswapV3AddLiquidity(chain, connector, req);
}

export async function reduceLiquidity(
req: RemoveLiquidityRequest
req: RemoveLiquidityRequest,
): Promise<RemoveLiquidityResponse> {
const chain = await getInitializedChain<Ethereumish | Osmosis>(req.chain, req.network);
if (chain instanceof Osmosis){
const chain = await getInitializedChain<Ethereumish | Osmosis>(
req.chain,
req.network,
);
if (chain instanceof Osmosis) {
return chain.controller.removeLiquidity(chain as unknown as Osmosis, req);
}
const connector: UniswapLPish = await getConnector<UniswapLPish>(
req.chain,
req.network,
req.connector
req.connector,
);

return uniswapV3RemoveLiquidity(chain, connector, req);
}

export async function collectFees(
req: CollectEarnedFeesRequest
req: CollectEarnedFeesRequest,
): Promise<RemoveLiquidityResponse> {
const chain = await getInitializedChain<Ethereumish | Osmosis>(req.chain, req.network);
if (chain instanceof Osmosis){
const chain = await getInitializedChain<Ethereumish | Osmosis>(
req.chain,
req.network,
);
if (chain instanceof Osmosis) {
return chain.controller.collectFees(chain as unknown as Osmosis, req);
}
const connector: UniswapLPish = await getConnector<UniswapLPish>(
req.chain,
req.network,
req.connector
req.connector,
);
return uniswapV3CollectEarnedFees(chain, connector, req);
}

export async function positionInfo(
req: PositionRequest
req: PositionRequest,
): Promise<PositionResponse> {
const chain = await getInitializedChain<Ethereumish | Osmosis>(req.chain, req.network);
if (chain instanceof Osmosis){
const chain = await getInitializedChain<Ethereumish | Osmosis>(
req.chain,
req.network,
);
if (chain instanceof Osmosis) {
return chain.controller.poolPositions(chain as unknown as Osmosis, req);
}
const connector: UniswapLPish = await getConnector<UniswapLPish>(
req.chain,
req.network,
req.connector
req.connector,
);
return uniswapV3PositionInfo(chain, connector, req);
}

export async function poolPrice(
req: PoolPriceRequest
req: PoolPriceRequest,
): Promise<PoolPriceResponse> {
const chain = await getInitializedChain<Ethereumish | Osmosis>(req.chain, req.network);
if (chain instanceof Osmosis){
const chain = await getInitializedChain<Ethereumish | Osmosis>(
req.chain,
req.network,
);
if (chain instanceof Osmosis) {
return chain.controller.poolPrice(chain as unknown as Osmosis, req);
}
const connector: UniswapLPish = await getConnector<UniswapLPish>(
req.chain,
req.network,
req.connector
req.connector,
);
return uniswapV3PoolPrice(chain, connector, req);
}

export async function estimateGas(
req: NetworkSelectionRequest
req: NetworkSelectionRequest,
): Promise<EstimateGasResponse> {
const chain = await getInitializedChain<
Algorand | Ethereumish | Nearish | Tezosish | Osmosis
>(req.chain, req.network);
if (chain instanceof Osmosis){
if (chain instanceof Osmosis) {
return chain.controller.estimateGas(chain as unknown as Osmosis);
}

const connector: Uniswapish | RefAMMish | Tinyman | Plenty =
await getConnector<Uniswapish | RefAMMish | Plenty>(
req.chain,
req.network,
req.connector
req.connector,
);

if (connector instanceof Plenty) {
Expand All @@ -251,46 +276,46 @@ export async function estimateGas(

// perp
export async function perpMarketPrices(
req: PriceRequest
req: PriceRequest,
): Promise<PerpPricesResponse> {
const chain = await getInitializedChain<Ethereumish>(req.chain, req.network);
const connector: Perpish = await getConnector<Perpish>(
req.chain,
req.network,
req.connector
req.connector,
);
return perpPriceData(chain, connector, req);
}

export async function perpOrder(
req: PerpCreateTakerRequest,
isOpen: boolean
isOpen: boolean,
): Promise<PerpCreateTakerResponse> {
const chain = await getInitializedChain<Ethereumish>(req.chain, req.network);
const connector: Perpish = await getConnector<Perpish>(
req.chain,
req.network,
req.connector,
req.address
req.address,
);
return createTakerOrder(chain, connector, req, isOpen);
}

export async function perpPosition(
req: PerpPositionRequest
req: PerpPositionRequest,
): Promise<PerpPositionResponse> {
const chain = await getInitializedChain<Ethereumish>(req.chain, req.network);
const connector: Perpish = await getConnector<Perpish>(
req.chain,
req.network,
req.connector,
req.address
req.address,
);
return getPosition(chain, connector, req);
}

export async function perpBalance(
req: PerpBalanceRequest
req: PerpBalanceRequest,
): Promise<PerpBalanceResponse> {
const chain = await getInitializedChain(req.chain, req.network);
const connector: Perpish = <Perpish>(
Expand All @@ -300,37 +325,37 @@ export async function perpBalance(
}

export async function perpPairs(
req: NetworkSelectionRequest
req: NetworkSelectionRequest,
): Promise<PerpAvailablePairsResponse> {
const chain = await getInitializedChain<Ethereumish>(req.chain, req.network);
const connector: Perpish = await getConnector<Perpish>(
req.chain,
req.network,
req.connector
req.connector,
);
return getAvailablePairs(chain, connector);
}

export async function getMarketStatus(
req: PerpMarketRequest
req: PerpMarketRequest,
): Promise<PerpMarketResponse> {
const chain = await getInitializedChain<Ethereumish>(req.chain, req.network);
const connector: Perpish = await getConnector<Perpish>(
req.chain,
req.network,
req.connector
req.connector,
);
return checkMarketStatus(chain, connector, req);
}

export async function estimatePerpGas(
req: NetworkSelectionRequest
req: NetworkSelectionRequest,
): Promise<EstimateGasResponse> {
const chain = await getInitializedChain<Ethereumish>(req.chain, req.network);
const connector: Perpish = await getConnector<Perpish>(
req.chain,
req.network,
req.connector
req.connector,
);
return perpEstimateGas(chain, connector);
}
Loading