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

CU-86drvz6jc Swap Multi Invoke - Implement routes definitions to Swap… #90

Merged
merged 1 commit into from
Aug 20, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/blockchain-service",
"comment": "Fixing list swappable tokens",
"type": "patch"
}
],
"packageName": "@cityofzion/blockchain-service"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/bs-neo3",
"comment": "Fixing swappable tokens list",
"type": "patch"
}
],
"packageName": "@cityofzion/bs-neo3"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/bs-neo3",
"comment": "Fixing list swappable tokens",
"type": "patch"
}
],
"packageName": "@cityofzion/bs-neo3"
}
2 changes: 1 addition & 1 deletion packages/blockchain-service/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ export interface SwapService<AvailableNetworkIds extends string> {
startListeningBlockGeneration(): void
stopListeningBlockGeneration(): void

listSwappableTokens(network: Network<AvailableNetworkIds>): PoolGraph
listSwappableTokensSymbol(network: Network<AvailableNetworkIds>): string[]

swap(isLedger?: boolean): void
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { BSNeo3Helper } from '../../../helpers/BSNeo3Helper'
import { RPCBDSNeo3 } from '../../../services/blockchain-data/RpcBDSNeo3'
import { RpcBDSNeo3 } from '../../../services/blockchain-data/RpcBDSNeo3'

const network = BSNeo3Helper.TESTNET_NETWORKS[0]
const tokens = BSNeo3Helper.getTokens(network)

const GAS = tokens.find(token => token.symbol === 'GAS')!

let rpcBDSNeo3: RPCBDSNeo3
let rpcBDSNeo3: RpcBDSNeo3

describe('RpcBDSNeo3', () => {
beforeEach(() => {
rpcBDSNeo3 = new RPCBDSNeo3(network, GAS, GAS, tokens)
rpcBDSNeo3 = new RpcBDSNeo3(network, GAS, GAS, tokens)
})

it('Should be able to get transaction', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from '@cityofzion/blockchain-service'
import { FlamingoSwapConstants } from '../../../constants/FlamingoSwapConstants'
import { BSNeo3Helper, BSNeo3NetworkId } from '../../../helpers/BSNeo3Helper'
import { NeonDappKitLedgerServiceNeo3 } from '../../../services/ledger/NeonDappKitLedgerServiceNeo3'
import { FlamingoSwapServiceNeo3 } from '../../../services/swap/FlamingoSwapServiceNeo3'

let flamingoSwapServiceNeo3: FlamingoSwapServiceNeo3
Expand All @@ -16,7 +17,7 @@ let network: Network<BSNeo3NetworkId>
describe('FlamingoSwapServiceNeo3', () => {
beforeEach(() => {
network = BSNeo3Helper.DEFAULT_NETWORK
flamingoSwapServiceNeo3 = new FlamingoSwapServiceNeo3(network)
flamingoSwapServiceNeo3 = new FlamingoSwapServiceNeo3(network, new NeonDappKitLedgerServiceNeo3())
})

it('Should be able to build swap invocation args with type "swapTokenToUse" - GAS to SWTH', async () => {
Expand Down
150 changes: 0 additions & 150 deletions packages/bs-neo3/src/constants/FlamingoSwapConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ export class FlamingoSwapConstants {
hash: '0x5b53998b399d10cd25727269e865acc785ef5c1a',
name: 'FLM',
},
FLUND: {
symbol: 'FLUND',
decimals: 8,
hash: '0x3d0085f442ead25ff3a7507c8eaa27cc8623a6be',
name: 'FLUND',
},
TIPS: {
symbol: 'TIPS',
decimals: 8,
Expand Down Expand Up @@ -160,81 +154,6 @@ export class FlamingoSwapConstants {
hash: '0x1883231a31dc912805cc08a281d4c268c4cac345',
name: 'fBNB',
},
// ============ Ethereum Assets ============ //
WETH: {
symbol: 'WETH',
decimals: 18,
hash: '0xb603cea165119701b58d56d10d2060fbfb3efad8',
name: 'WETH',
},
WBTC: {
symbol: 'WBTC',
decimals: 8,
hash: '0x557563dc4ed3fd256eba55b9622f53331ab97c2f',
name: 'WBTC',
},
USDT: {
symbol: 'USDT',
decimals: 6,
hash: '0xad3f96ae966ad60347f31845b7e4b333104c52fb',
name: 'USDT',
},
xWETH: {
symbol: 'xWETH',
decimals: 18,
hash: '0xd38fc89febb12e5d32faa72e07d486a268b9c63a',
name: 'xWETH',
},
xWBTC: {
symbol: 'xWBTC',
decimals: 8,
hash: '0x447b931cc604a30dc16c49002f35a7aab7888b78',
name: 'xWBTC',
},
xUSDT: {
symbol: 'xUSDT',
decimals: 6,
hash: '0xf15b5430321f4e51f5f534cedada7fbb78fa6680',
name: 'xUSDT',
},
// ============ Ontology Assets ============ //
ONTd: {
symbol: 'ONTd',
decimals: 9,
hash: '0x869951e3397550e800d5faf579857cdb637a0051',
name: 'ONTd',
},
// ============ BSC Assets ============ //
CAKE: {
symbol: 'CAKE',
decimals: 18,
hash: '0x778140d3A1e0024Be11e723a8af2C4d521feBA4f',
name: 'CAKE',
},
BNB: {
symbol: 'BNB',
decimals: 18,
hash: '0x0000000000000000000000000000000000000000',
name: 'BNB',
},
xfCAKE: {
symbol: 'xfCAKE',
decimals: 18,
hash: '0x64A647dC1634d164896D7146f7Ad314665DFeB18',
name: 'xfCAKE',
},
bNUDES: {
symbol: 'bNUDES',
decimals: 8,
hash: '0xeA5143686D0edb60dcE657CeDA8367a92a2Bff58',
name: 'bNUDES',
},
FUSD: {
symbol: 'FUSD',
decimals: 8,
hash: '0xcdaddd3e196bb1c1978364dd78b8cec5d4753f58',
name: 'FUSD',
},
} as const

static readonly MAINNET_FLAMINGO_SWAP_TOKENS: FlamingoSwapTokens = {
Expand All @@ -245,12 +164,6 @@ export class FlamingoSwapConstants {
hash: '0xf0151f528127558851b39c2cd8aa47da7418ab28',
name: 'FLM',
},
FLUND: {
symbol: 'FLUND',
decimals: 8,
hash: '0xa9603a59e21d29e37ac39cf1b5f5abf5006b22a3',
name: 'FLUND',
},
TIPS: {
symbol: 'TIPS',
decimals: 8,
Expand Down Expand Up @@ -377,69 +290,6 @@ export class FlamingoSwapConstants {
hash: '0xb56f0fba45cc57a948b342186274dfd863996bb3',
name: 'fBNB',
},
// ============ Ethereum Assets ============ //
WETH: {
symbol: 'WETH',
decimals: 18,
hash: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
name: 'WETH',
},
WBTC: {
symbol: 'WBTC',
decimals: 8,
hash: '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599',
name: 'WBTC',
},
USDT: {
symbol: 'USDT',
decimals: 6,
hash: '0xdac17f958d2ee523a2206206994597c13d831ec7',
name: 'USDT',
},
xWETH: {
symbol: 'xWETH',
decimals: 18,
hash: '0x46b2E0224efb03D43eba88AB5A1995480e6A76b6',
name: 'xWETH',
},
xWBTC: {
symbol: 'xWBTC',
decimals: 8,
hash: '0xebd0e8988ac25a793dc27368f96a5a72e34efcd7',
name: 'xWBTC',
},
xUSDT: {
symbol: 'xUSDT',
decimals: 6,
hash: '0xa93727e8661d4f82cfd50f7d8fd3f38ec8493b84',
name: 'xUSDT',
},
// ============ Ontology Assets ============ //
ONTd: {
symbol: 'ONTd',
decimals: 9,
hash: '33ae7eae016193ba0fe238b223623bc78faac158',
name: 'ONTd',
},
WING: {
symbol: 'WING',
decimals: 9,
hash: '00c59fcd27a562d6397883eab1f2fff56e58ef80',
name: 'WING',
},
// ============ BSC Assets ============ //
CAKE: {
symbol: 'CAKE',
decimals: 18,
hash: '0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82',
name: 'CAKE',
},
xfCAKE: {
symbol: 'xfCAKE',
decimals: 18,
hash: '0xD05923B7E0c86f31A4a6dFA4d5bbF191AbEe6Ab2',
name: 'xfCAKE',
},
} as const

static readonly FLAMINGO_SWAP_TOKENS: Record<BSNeo3NetworkId, FlamingoSwapTokens> = {
Expand Down
4 changes: 2 additions & 2 deletions packages/bs-neo3/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ export * from './BSNeo3'
export * from './builder/invocation/FlamingoSwapInvocationBuilderNeo3'
export * from './builder/invocation/NeonDappKitInvocationBuilderNeo3'

export * from './constants/FlamingoSwapConstants'

export * from './helpers/BSNeo3Helper'
export * from './helpers/FlamingoSwapHelper'

export * from './constants/FlamingoSwapConstants'

export * from './services/blockchain-data/DoraBDSNeo3'
export * from './services/blockchain-data/RpcBDSNeo3'
export * from './services/exchange-data/FlamingoEDSNeo3'
Expand Down
5 changes: 2 additions & 3 deletions packages/bs-neo3/src/services/swap/FlamingoSwapServiceNeo3.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
Account,
Network,
PoolGraph,
SwapRoute,
SwapService,
SwapServiceEvents,
Expand Down Expand Up @@ -95,8 +94,8 @@ export class FlamingoSwapServiceNeo3 implements SwapService<BSNeo3NetworkId> {
}
}

listSwappableTokens(network: Network<BSNeo3NetworkId>): PoolGraph {
return FlamingoSwapRouteHandler.createPoolGraph(network)
listSwappableTokensSymbol(network: Network<BSNeo3NetworkId>): string[] {
return Object.keys(FlamingoSwapRouteHandler.createPoolGraph(network))
}

async swap(isLedger?: boolean): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,29 +66,30 @@ export class FlamingoSwapRouteHandler {
}

static createPoolGraph(network: Network<BSNeo3NetworkId>): PoolGraph {
const poolGraph: PoolGraph = {}

const pools = FlamingoSwapHelper.getFlamingoSwapPools(network)
const tokens = FlamingoSwapHelper.getFlamingoSwapTokens(network)

const { NEO, bNEO } = tokens

const poolGraph: PoolGraph = {}

// Initialize poolGraph with empty arrays
Object.values(tokens).forEach(token => {
poolGraph[token.symbol] = []
Object.keys(tokens).forEach(tokenSymbol => {
poolGraph[tokenSymbol] = []
})

// Add edges to poolGraph
Object.values(pools).forEach(pool => {
const tokenA = pool.tokens[0].symbol
const tokenB = pool.tokens[1].symbol
poolGraph[tokenA].push(tokenB)
poolGraph[tokenB].push(tokenA)
const tokenASymbol = pool.tokens[0].symbol
const tokenBSymbol = pool.tokens[1].symbol

poolGraph[tokenASymbol].push(tokenBSymbol)
poolGraph[tokenBSymbol].push(tokenASymbol)
})

// Remove duplicates from poolGraph
Object.keys(poolGraph).forEach(tokenSymbol => {
poolGraph[tokenSymbol] = [...new Set(poolGraph[tokenSymbol])]
Object.keys(tokens).forEach(tokenSymbol => {
poolGraph[tokenSymbol] = Array.from(new Set(poolGraph[tokenSymbol]))
})

// Include NEO to the poolGraph
Expand Down
Loading