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

Add Ergo chain & Spectrum connector #346

Open
wants to merge 190 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
190 commits
Select commit Hold shift + click to select a range
e6edfde
initial ergo chain
hirotadashi May 30, 2024
50f583c
other ergo class functions implemented
hirotadashi Jun 1, 2024
e68d813
update [ergo]: format the codes
ahmadyazdanii Jun 4, 2024
3eee1ca
update [ergo]: refactor dex service
ahmadyazdanii Jun 4, 2024
3a4ec61
getting ammpool for ergo chain
hirotadashi Jun 4, 2024
9ff33c1
refactor [ergo]: refactor all functions & types & interfaces
ahmadyazdanii Jun 4, 2024
9039419
Merge branch 'initial-ergo-chain' of github.com:Microflow-xyz/gateway…
ahmadyazdanii Jun 4, 2024
08bebf8
update [ergo]: refactor pool class
ahmadyazdanii Jun 4, 2024
4f5d120
Merge pull request #5 from Microflow-xyz/initial-ergo-chain
hirotadashi Jun 4, 2024
d77bc69
add[test]: add unit tests for ergo.config file
satiparpar Jun 5, 2024
6ac3d19
Merge branch 'initial-ergo-chain' of https://github.com/Microflow-xyz…
satiparpar Jun 8, 2024
7262861
add[unit-test]: Implement unit tests for "request" and "getTokens" me…
satiparpar Jun 8, 2024
27d4126
update [unit-test]: update unit tests for "getErgoConfig" function, b…
satiparpar Jun 9, 2024
5463f9d
add [unit-test]: Implement unit tests for "NodeService" => "request" …
satiparpar Jun 9, 2024
369fed6
add [unit-test]: Implement unit tests for "NodeService" => "getNetwor…
satiparpar Jun 9, 2024
3c107c5
update [ergo]: add dex service components doc
ahmadyazdanii Jun 9, 2024
ce08b27
update [ergo]: add ergo config docs
ahmadyazdanii Jun 9, 2024
8e73760
add prover interface
hirotadashi Jun 10, 2024
4b529d2
Merge branch 'initial-ergo-chain' of github.com:Microflow-xyz/gateway…
hirotadashi Jun 10, 2024
d72bd93
update [ergo]: update document of ergo file
ahmadyazdanii Jun 10, 2024
1546a0e
update [ergo]: add node documentation
ahmadyazdanii Jun 10, 2024
aa55e8a
Merge branch 'initial-ergo-chain' of https://github.com/Microflow-xyz…
satiparpar Jun 10, 2024
568a829
update [unit-test]: update ergo.config.test based on new implementations
satiparpar Jun 10, 2024
5401468
add [unit-test]: add unit tests for ergo.config file
satiparpar Jun 11, 2024
0da881d
add [unit-test]: Implement unit tests for "DexService" => "request" m…
satiparpar Jun 11, 2024
1a98f94
add [unit-test]: Implement unit tests for "DexService" => "getTokens"…
satiparpar Jun 11, 2024
5769f82
add [unit-test]: Implement unit tests for "NodeService" => "request" …
satiparpar Jun 12, 2024
847e1c8
add [unit-test]: Implement unit tests for "NodeService" => "getNetwor…
satiparpar Jun 12, 2024
e4d58dc
add [unit-test]: Implement unit tests for "Ergo" => verify initializa…
satiparpar Jun 13, 2024
9de3c3e
add [unit-test]: Implement unit tests for "Ergo" => verify initializa…
satiparpar Jun 14, 2024
8f2c466
add [unit-test]: Implement unit tests for "Ergo" => "node", "network"…
satiparpar Jun 14, 2024
7e63a86
add [unit-test]: Implement unit tests for "Ergo" => "getInstance" and…
satiparpar Jun 15, 2024
9cd9920
add [unit-test]: Implement unit tests for "Ergo" => "getCurrentBlockN…
satiparpar Jun 15, 2024
9c8f807
add [unit-test]: Implement unit tests for "Ergo" => "getAccountFromSe…
satiparpar Jun 16, 2024
1f61248
add [unit-test]: Implement unit tests for "Ergo" => "encrypt" and "de…
satiparpar Jun 16, 2024
f6db7b7
add [unit-test]: Implement unit tests for "Ergo" => "getAssetBalance"…
satiparpar Jun 17, 2024
02ea6d1
fix [ergo]: fix tokenId to get string and update the related interface
satiparpar Jun 18, 2024
a7fb064
Merge pull request #13 from Microflow-xyz/fix/loadAssets
hirotadashi Jun 18, 2024
c5f31f2
Merge pull request #6 from Microflow-xyz/feature/code-doc
hirotadashi Jun 18, 2024
6b45589
add [unit-test]: Implement unit tests for "Ergo" => "getAssetData", "…
satiparpar Jun 19, 2024
6eaa8cb
update [unit-test]: delete wrong unit test files
satiparpar Jun 19, 2024
d1ca93d
Resolved #9
hirotadashi Jun 19, 2024
4e5b93c
Merge branch 'feature/estimate'
hirotadashi Jun 20, 2024
8e93791
Merge branch 'initial-ergo-chain'
hirotadashi Jun 20, 2024
c6ad32f
fix load pool bugs
hirotadashi Jun 20, 2024
d79fc95
Merge branch 'fix/loadPool' into feature/estimate
hirotadashi Jun 20, 2024
aec0fdd
some related bugs fixed
hirotadashi Jun 21, 2024
9095dae
some related bugs fixed
hirotadashi Jun 21, 2024
8443472
update [commet]: update comments of unit tests
satiparpar Jun 21, 2024
c75d456
Merge pull request #8 from Microflow-xyz/initial-ergo-chain
ahmadyazdanii Jun 22, 2024
2b9da50
Merge pull request #14 from Microflow-xyz/feature/estimate
ahmadyazdanii Jun 22, 2024
bb561a6
Merge pull request #7 from Microflow-xyz/feature/unit-test
ahmadyazdanii Jun 22, 2024
8b18452
update [packages]: change ergo-sdk and ergo-dex-sdk packages
ahmadyazdanii Jun 23, 2024
f9b49e7
Merge pull request #15 from Microflow-xyz/feature/packages
ahmadyazdanii Jun 23, 2024
5245acf
Solved #21
hirotadashi Jun 24, 2024
ce3f914
Solved #21
hirotadashi Jun 24, 2024
84b12e5
Solved #17
hirotadashi Jun 24, 2024
6694dd5
Solved #16
hirotadashi Jun 24, 2024
fde4f63
pool, balances, getTokens added to the controller
hirotadashi Jun 24, 2024
fbf9099
added transfer to controller
hirotadashi Jun 24, 2024
d445eb2
Merge pull request #26 from Microflow-xyz/fix/wallet
ahmadyazdanii Jun 25, 2024
897c09a
Merge pull request #27 from Microflow-xyz/fix/network-check
ahmadyazdanii Jun 25, 2024
d3fb5f1
Merge pull request #28 from Microflow-xyz/fix/getAssetBalance
ahmadyazdanii Jun 25, 2024
efca406
Merge branch 'feature/controller'
hirotadashi Jun 25, 2024
c4a2530
Merge pull request #29 from Microflow-xyz/feature/controller
ahmadyazdanii Jun 25, 2024
873fc64
solved #31
hirotadashi Jun 25, 2024
e4ac052
Merge pull request #32 from Microflow-xyz/fix/bigint
satiparpar Jun 26, 2024
c2139dd
update [unit-test]: Update unit tests based on new changes
satiparpar Jun 26, 2024
88503e1
update [ergo]: update config files
ahmadyazdanii Jun 26, 2024
ebdbc43
update [ergo]: cleanup ergo requests interfaces
ahmadyazdanii Jun 26, 2024
7de6cf3
update [ergo]: general cleanup
ahmadyazdanii Jun 26, 2024
9d3b1f6
update [ergo]: connect ergo to the chain router
ahmadyazdanii Jun 26, 2024
5f51062
config file fixed
hirotadashi Jun 26, 2024
aed0771
poll added to controller
hirotadashi Jun 26, 2024
60c8f4e
config file fixed
hirotadashi Jun 27, 2024
2092f60
Merge pull request #36 from Microflow-xyz/feature/poll
ahmadyazdanii Jun 27, 2024
00ff115
Merge pull request #35 from Microflow-xyz/feature/cleanup
ahmadyazdanii Jun 27, 2024
14acaea
swap gets 1 amount instead of 2
hirotadashi Jun 27, 2024
e31473d
swap gets 1 amount instead of 2
hirotadashi Jun 27, 2024
bff0e33
tslint errors fixed
hirotadashi Jun 27, 2024
0679c7a
tslint errors fixed
hirotadashi Jun 27, 2024
f7e9d8f
Merge pull request #39 from Microflow-xyz/fix/swap
ahmadyazdanii Jun 28, 2024
4546351
new [spectrum]: add spectrum connector's config
ahmadyazdanii Jun 28, 2024
1b3512d
change inputs for estimate and swap
hirotadashi Jun 30, 2024
fbe845e
new [spectrum]: add basics and connection of spectrum
ahmadyazdanii Jul 1, 2024
4a75f42
Merge pull request #41 from Microflow-xyz/feature/proper-input
ahmadyazdanii Jul 1, 2024
6da7f40
Merge branch 'main' into feature/connector
ahmadyazdanii Jul 1, 2024
7b31b01
update [ergo]: convert slippage to optional prop
ahmadyazdanii Jul 1, 2024
3d7accd
update [spectrum]: add 3 main functions
ahmadyazdanii Jul 1, 2024
cc001c4
Merge pull request #42 from Microflow-xyz/feature/connector
ahmadyazdanii Jul 1, 2024
24fbb22
Merge pull request #33 from Microflow-xyz/feature/unit-test
satiparpar Jul 2, 2024
239e21e
fix[ chain ]: Update configs to connect HummingBot to ergo
satiparpar Jul 2, 2024
c3fd41e
update[wallet.routs]: delete useless logs
satiparpar Jul 2, 2024
15609c2
fix [spectrum]: add some configurations
ahmadyazdanii Jul 3, 2024
a2cc0bc
change all bigint to bignumber as possible
hirotadashi Jul 5, 2024
3629a29
amm connector added
hirotadashi Jul 5, 2024
768e52c
balance fixed
hirotadashi Jul 5, 2024
927f4e5
Merge pull request #43 from Microflow-xyz/fix/amm
ahmadyazdanii Jul 5, 2024
5ef6780
[fix]: fix sum of assets for each tokenId
satiparpar Jul 6, 2024
1ef7fdf
Merge pull request #44 from Microflow-xyz/fix/getBalance-assets-sum
hirotadashi Jul 6, 2024
ff288fc
balance fixed
hirotadashi Jul 6, 2024
3576b8b
tokens decimal applied to balance values
hirotadashi Jul 6, 2024
9a93b29
[fix]: fix route to get each asset name
satiparpar Jul 7, 2024
739e5cd
Merge pull request #45 from Microflow-xyz/fix/Pool-constructor
hirotadashi Jul 8, 2024
90e9b81
update [unit-test]: update unit tests for "Ergo" based on new network…
satiparpar Jul 10, 2024
a6ae230
add [unit-test]: Implement unit tests for "ergo.utils" => "getBaseInp…
satiparpar Jul 10, 2024
aa38f6d
add [unit-test]: Implement unit tests for "ergo.utils" => "getInputs"…
satiparpar Jul 11, 2024
684ee19
add [unit-test]: Implement unit tests for "ergo.utils" => "getTxCont…
satiparpar Jul 11, 2024
5ddea9c
add [unit-test]: Implement unit tests for "Ergo" => "getAccountFromMn…
satiparpar Jul 11, 2024
a5ea3b7
add & update [unit-test]: Implement unit tests for "Ergo" => "getBala…
satiparpar Jul 11, 2024
6746705
add [unit-test]: Implement unit tests for "Ergo" => "loadPool" method
satiparpar Jul 11, 2024
6a2bd89
fix [ergo]: convert token symbol to id before asking from pool
ahmadyazdanii Jul 12, 2024
27a7ee1
Merge branch 'main' of github.com:Microflow-xyz/gateway
ahmadyazdanii Jul 12, 2024
b7a307a
add [unit-test]: Implement unit tests for "Ergo" => "swap" method : c…
satiparpar Jul 13, 2024
93584e0
Merge branch 'main' of https://github.com/Microflow-xyz/gateway into …
satiparpar Jul 13, 2024
0a2ade2
add [unit-test]: Implement unit tests for "Ergo" => "swap" method
satiparpar Jul 13, 2024
e1769d4
add [unit-test]: Implement unit tests for "Ergo" => "estimate" method
satiparpar Jul 13, 2024
5290ae3
fix [getPoolByToken]: fix the error message to send correct token sym…
satiparpar Jul 13, 2024
751d00f
Merge pull request #47 from Microflow-xyz/fix/getPoolByToken
hirotadashi Jul 13, 2024
9599767
decimals considered for swap and estimate
hirotadashi Jul 13, 2024
8b7d808
add [unit-test]: Implement unit tests for "Ergo" => "getPool", "getPo…
satiparpar Jul 14, 2024
c1ed799
update [unit-test]: update unit tests for ergo.config based on new up…
satiparpar Jul 14, 2024
44f77c3
add [unit-test]: Implement unit tests for "NodeService" => "chainSlic…
satiparpar Jul 14, 2024
9182022
add [unit-test]: Implement unit tests for "NodeService" => "postTrans…
satiparpar Jul 14, 2024
bc31931
Merge branch 'main' of https://github.com/Microflow-xyz/gateway into …
satiparpar Jul 14, 2024
bc94d4d
update [log]: remove useless logs
satiparpar Jul 14, 2024
397ceca
update [unit-test]: update unit tests for Ergo based on new updates
satiparpar Jul 15, 2024
4e0adde
update [unit-test]: move unit test files to test-bronze
satiparpar Jul 15, 2024
6c0f09c
some bugs fixed
hirotadashi Jul 16, 2024
7b86058
Merge branch 'main' of github.com:Microflow-xyz/gateway
hirotadashi Jul 16, 2024
7872156
ergo interface fixed
hirotadashi Jul 16, 2024
f41a1c5
ergo interface fixed
hirotadashi Jul 16, 2024
08c1719
ergo interface fixed
hirotadashi Jul 16, 2024
7c0d7aa
bug fixed
hirotadashi Jul 18, 2024
c7b7faa
bug fixed
hirotadashi Jul 18, 2024
b3d7322
bug fixed
hirotadashi Jul 18, 2024
8231d4c
BUY change to SELL
hirotadashi Jul 18, 2024
02a0846
usdt changed to sigusd
hirotadashi Jul 18, 2024
e3cc09f
max expected amount for multiple pool
hirotadashi Jul 19, 2024
8774431
Merge branch 'main' of https://github.com/pattern-tech/gateway into f…
satiparpar Jul 19, 2024
c4c535d
add [unit-test]: Implement unit tests for ErgoController => "pool" me…
satiparpar Jul 19, 2024
d29fc34
fix [ ErgoController ]: fix wrong call on ergo.ready method
satiparpar Jul 19, 2024
815cca2
Merge pull request #48 from pattern-tech/fix/ErgoController-pool
satiparpar Jul 19, 2024
f056365
fix [ ErgoController ]: fix ergo.ready call
satiparpar Jul 19, 2024
077c3d3
Merge branch 'main' of https://github.com/pattern-tech/gateway into f…
satiparpar Jul 19, 2024
6ac88b9
add [unit-test]: Implement unit tests for ErgoController => "pool" & …
satiparpar Jul 20, 2024
0224995
add [unit-test]: Implement unit tests for ErgoController => "getToke…
satiparpar Jul 21, 2024
ce0044a
add [unit-test]: Implement unit tests for ErgoController => "allowan…
satiparpar Jul 21, 2024
f7cc479
update [unit-test]: update unit tests based on new updates for Ergo =…
satiparpar Jul 22, 2024
e9f7f23
bug fixed
hirotadashi Jul 22, 2024
dbf5d36
Merge branch 'main' of github.com:Microflow-xyz/gateway
hirotadashi Jul 22, 2024
f66b1a2
expected amount is now greater that prev
hirotadashi Jul 22, 2024
da7b639
Merge branch 'main' of https://github.com/pattern-tech/gateway into f…
satiparpar Jul 23, 2024
41c2da8
bug fixed
hirotadashi Jul 23, 2024
32ca0e3
Merge branch 'main' of https://github.com/pattern-tech/gateway into f…
satiparpar Jul 24, 2024
6964125
update [unit-test]: update unit tests based on new updates for Ergo =…
satiparpar Jul 24, 2024
c7ecc01
update [unit-test]: update unit tests based on new updates for Ergo =…
satiparpar Jul 24, 2024
a71755a
update [unit-test]: update unit tests based on new updates for Ergo =…
satiparpar Jul 24, 2024
624d63b
add [unit-test]: Implement unit tests for "Ergo" => "getAccountFromAd…
satiparpar Jul 24, 2024
e40e75e
update [unit-test]: update unit tests based on new updates for NodeS…
satiparpar Jul 24, 2024
68995cf
add [unit-test]: Implement unit tests for "Spectrum" => "getInstance"…
satiparpar Jul 25, 2024
c905be5
add [unit-test]: Implement unit tests for "Spectrum" => "getTokenByA…
satiparpar Jul 25, 2024
52c063f
add [unit-test]: Implement unit tests for "Spectrum" => "ready", "ga…
satiparpar Jul 25, 2024
f4a6ab2
add [unit-test]: Implement unit tests for "SpectrumConfig"
satiparpar Jul 25, 2024
16bb491
add [unit-test]: Implement unit tests for "WalletProver"
satiparpar Jul 26, 2024
c92ca00
cleanUp [ unit-test ]: Ergo unit tests cleaned up
satiparpar Jul 26, 2024
c7a7ccd
final bug fixed
hirotadashi Jul 27, 2024
ff44c71
Merge branch 'main' of https://github.com/pattern-tech/gateway into f…
satiparpar Jul 28, 2024
cc9cfee
update [unit-test]: update unit tests for loadAssets method
satiparpar Jul 29, 2024
57ea57e
ergo class refactored
hirotadashi Jul 30, 2024
665aa39
priceToken problem fixed
hirotadashi Jul 31, 2024
ecdb6ed
fix [unit-test]: fix ergoController to have been called correctly
satiparpar Aug 2, 2024
9c4a5b9
Merge pull request #46 from pattern-tech/feature/unit-test
satiparpar Aug 2, 2024
446b8da
Merge branch 'refactor'
hirotadashi Aug 2, 2024
04fcd51
Merge branch 'refactor'
hirotadashi Aug 2, 2024
0f55fa5
update [unit-test]: useless logs removed & useless if removed in Ergo
satiparpar Aug 2, 2024
eef41e3
Merge branch 'main' of github.com:hummingbot/gateway
ahmadyazdanii Aug 3, 2024
850e451
Merge pull request #348 from hummingbot/development
nikspz Aug 15, 2024
481e895
Merge pull request #349 from hummingbot/development
nikspz Aug 16, 2024
48b009c
fix-gw-staging-version-to-2.0.1
nikspz Aug 26, 2024
e16f632
Update app.ts
nikspz Aug 26, 2024
14ef261
Merge branch 'staging' into fix-gw-staging-version-to-2.0.1
nikspz Aug 26, 2024
4f89eb7
Merge pull request #353 from hummingbot/fix-gw-staging-version-to-2.0.1
nikspz Aug 26, 2024
8153070
Merge pull request #352 from hummingbot/staging
nikspz Aug 28, 2024
e96637a
Merge branch 'staging' into staging-update-to-2.0.2
nikspz Oct 24, 2024
f0392e9
Merge pull request #364 from hummingbot/staging-update-to-2.0.2
nikspz Oct 24, 2024
d0824a2
change version from 2.0.2 to 2.1.0
Oct 28, 2024
e697923
Merge pull request #366 from hummingbot/update-version-2.1.0
rapcmia Oct 28, 2024
240b51c
Merge pull request #365 from hummingbot/staging
rapcmia Oct 28, 2024
1fb1a5a
Merge remote-tracking branch 'upstream/main'
satiparpar Dec 2, 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
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hummingbot-gateway",
"version": "dev-2.0.2",
"version": "2.1.0",
"description": "Middleware that helps Hummingbot clients access standardized DEX API endpoints on different blockchain networks",
"main": "index.js",
"license": "Apache-2.0",
Expand Down Expand Up @@ -38,6 +38,8 @@
"@ethersproject/networks": "5.7.0",
"@ethersproject/providers": "5.7.0",
"@ethersproject/solidity": "5.7.0",
"@fleet-sdk/common": "^0.3.4",
"@fleet-sdk/core": "^0.5.0",
"@harmony-js/core": "^0.1.57",
"@harmony-js/utils": "^0.1.56",
"@improbable-eng/grpc-web": "^0.13.0",
Expand All @@ -51,6 +53,9 @@
"@pancakeswap/v3-periphery": "^1.0.2",
"@pancakeswap/v3-sdk": "^3.7.0",
"@pangolindex/sdk": "^1.1.0",
"@patternglobal/ergo-dex-sdk": "^1.0.1",
"@patternglobal/ergo-sdk": "^1.0.0",
"@perp/sdk-curie": "^1.16.0",
"@sushiswap/sdk": "^5.0.0-canary.116",
"@taquito/rpc": "^17.0.0",
"@taquito/signer": "^17.0.0",
Expand Down Expand Up @@ -80,6 +85,7 @@
"coinalpha-ref-sdk": "1.1.0",
"dayjs": "^1.10.6",
"decimal.js-light": "^2.5.1",
"ergo-lib-wasm-nodejs": "^0.22.0",
"ethers": "^5.6.2",
"ethers-xdc": "file:./vendor/ethers-xdc",
"express": "^4.17.1",
Expand Down Expand Up @@ -167,4 +173,4 @@
"resolutions": {
"web3-utils": "1.7.3"
}
}
}
104 changes: 63 additions & 41 deletions src/amm/amm.controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,24 @@ 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 { Spectrum } from '../connectors/spectrum/spectrum';
import { Ergo } from '../chains/ergo/ergo';

export async function price(req: PriceRequest): Promise<PriceResponse> {
const chain = await getInitializedChain<
Algorand | Ethereumish | Tezosish | Osmosis
Algorand | Ethereumish | Tezosish | Osmosis | Ergo
>(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 | Tinyman | Plenty =
await getConnector<Uniswapish | Tinyman | Plenty>(
req.chain,
req.network,
req.connector
);
const connector:
| Uniswapish
| Tinyman
| Plenty
| Spectrum = await getConnector<
Uniswapish | Tinyman | Plenty | Spectrum
>(req.chain, req.network, req.connector);

if (connector instanceof Plenty) {
return plentyPrice(<Tezosish>chain, connector, req);
Expand All @@ -78,128 +81,147 @@ export async function price(req: PriceRequest): Promise<PriceResponse> {
} else if ('routerAbi' in connector) {
// we currently use the presence of routerAbi to distinguish Uniswapish from RefAMMish
return uniswapPrice(<Ethereumish>chain, connector, req);
} else if (connector instanceof Spectrum) {
return connector.estimateTrade(req);
} else return tinymanPrice(chain as unknown as Algorand, connector, req);

}

export async function trade(req: TradeRequest): Promise<TradeResponse> {
const chain = await getInitializedChain<
Algorand | Ethereumish | Tezosish | Osmosis
Algorand | Ethereumish | Tezosish | Osmosis | Ergo
>(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 | Tinyman | Plenty =
await getConnector<Uniswapish | Tinyman | Plenty>(
req.chain,
req.network,
req.connector
);
const connector:
| Uniswapish
| Tinyman
| Plenty
| Spectrum = await getConnector<
Uniswapish | Tinyman | Plenty | Spectrum
>(req.chain, req.network, req.connector);

if (connector instanceof Plenty) {
return plentyTrade(<Tezosish>chain, connector, req);
} else if (connector instanceof Carbonamm) {
return carbonTrade(<Ethereumish>chain, connector, req);
} else if ('routerAbi' in connector) {
return uniswapTrade(<Ethereumish>chain, connector, req);
} else if (connector instanceof Spectrum) {
return connector.executeTrade(req);
} else {
return tinymanTrade(chain as unknown as Algorand, connector, req);
}
}

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 | 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 | Tinyman | Plenty =
await getConnector<Uniswapish | Tinyman | Plenty>(
req.chain,
req.network,
req.connector
req.connector,
);

if (connector instanceof Plenty) {
Expand Down
18 changes: 12 additions & 6 deletions src/amm/amm.requests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { CoinAndSymbol, SerializableExtendedPool as CosmosSerializableExtendedPool } from '../chains/osmosis/osmosis.types';
import {
CoinAndSymbol,
SerializableExtendedPool as CosmosSerializableExtendedPool,
} from '../chains/osmosis/osmosis.types';
// import { PerpPosition } from '../connectors/perp/perp';
import {
NetworkSelectionRequest,
PositionInfo as LPPositionInfo,
Expand Down Expand Up @@ -36,7 +40,7 @@ export interface PriceResponse {
export interface PoolPriceRequest extends NetworkSelectionRequest {
token0: string;
token1: string;
address?: string
address?: string;
fee?: string;
period?: number;
interval?: number;
Expand Down Expand Up @@ -68,6 +72,7 @@ export interface TradeRequest extends NetworkSelectionRequest {
maxPriorityFeePerGas?: string;
allowedSlippage?: string;
poolId?: string;
mnemonic?: string;
}

export interface TradeResponse {
Expand All @@ -81,8 +86,8 @@ export interface TradeResponse {
rawAmount: string;
finalAmountReceived_basetoken?: string; // Cosmos
expectedIn?: string;
expectedOut?: string; // Cosmos: expectedAmountReceived
expectedPrice?: string; // Cosmos
expectedOut?: string; // Cosmos: expectedAmountReceived
expectedPrice?: string; // Cosmos
price: string; // Cosmos: finalPrice
gasPrice: number;
gasPriceToken: string;
Expand All @@ -93,14 +98,15 @@ export interface TradeResponse {
txHash: string | any | undefined;
}

export interface AddLiquidityRequest extends NetworkSelectionRequest { // now also cosmos add swap position OR cosmos add LP position
export interface AddLiquidityRequest extends NetworkSelectionRequest {
// now also cosmos add swap position OR cosmos add LP position
address: string;
token0: string;
token1: string;
amount0: string;
amount1: string;
fee?: string;
lowerPrice?: string; // integer as string // COSMOS - using this != undefined then call addpositionLP(), else: addposition()
lowerPrice?: string; // integer as string // COSMOS - using this != undefined then call addpositionLP(), else: addposition()
upperPrice?: string; // integer as string
tokenId?: number; // COSMOS: poolId - will select one for you if not provided
nonce?: number;
Expand Down
2 changes: 1 addition & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export const startSwagger = async () => {

export const startGateway = async () => {
const port = ConfigManagerV2.getInstance().get('server.port');
const gateway_version="dev-2.0.2"
const gateway_version="2.1.0"
if (!ConfigManagerV2.getInstance().get('server.id')) {
ConfigManagerV2.getInstance().set(
'server.id',
Expand Down
42 changes: 42 additions & 0 deletions src/chains/ergo/dex.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import axios from 'axios';
import { DEXTokensResponse } from './interfaces/dex.interface';

/**
* This class allows you to access elements of a DEX
* @class
* @param {string} dexURL - The DEX's base URL
* @param {number} [timeout=5000] - Timeout
*/
export class DexService {
constructor(
private dexURL: string,
private timeout: number = 5000,
) {}

private async request<ResponseBlock = any>(
method: 'POST' | 'GET' | 'HEAD' = 'GET',
url: string,
headers?: Record<string, string>,
body?: Record<string, string>,
) {
const response = await axios<ResponseBlock>({
baseURL: this.dexURL,
url,
method,
headers: headers,
timeout: this.timeout,
...(method === 'POST' ? { body: body } : null),
});

return response.data;
}

/**
* This function allow you to get Ergo's token list from DEX
* @function
* @async
*/
async getTokens() {
return this.request<DEXTokensResponse>('GET', '/ergo-token-list.json');
}
}
Loading