Skip to content

Commit

Permalink
Merge branch 'develop' into feat/dapp-be-connect
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljscript committed Apr 19, 2024
2 parents cbcc305 + 23b0639 commit 93dd264
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion apps/wallet-mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
"@yoroi/resolver": "2.0.4",
"@yoroi/setup-wallet": "1.0.0",
"@yoroi/staking": "1.5.1",
"@yoroi/swap": "1.5.2",
"@yoroi/swap": "1.5.3",
"@yoroi/theme": "^1.0.0",
"@yoroi/transfer": "1.0.0",
"add": "2.0.6",
Expand Down
3 changes: 1 addition & 2 deletions packages/swap/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@yoroi/swap",
"version": "1.5.2",
"version": "1.5.3",
"description": "The Swap package of Yoroi SDK",
"keywords": [
"yoroi",
Expand Down Expand Up @@ -138,7 +138,6 @@
"@yoroi/api": "1.5.1",
"@yoroi/common": "1.5.2",
"@yoroi/types": "1.5.4"

},
"devDependencies": {
"@commitlint/config-conventional": "^17.0.2",
Expand Down
2 changes: 2 additions & 0 deletions packages/swap/src/adapters/openswap-api/api.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const getCompletedOrders: Array<Swap.CompletedOrder> = [
tokenId:
'c04f4200502a998e9eebafac0291a1f38008de3fe146d136946d8f4b.415247454e54',
},
provider: 'minswap',
placedAt: 1631635254000,
},
]

Expand Down
4 changes: 2 additions & 2 deletions packages/swap/src/adapters/openswap-api/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const SWAP_API_ENDPOINTS = {
getPoolsPair: 'https://onchain2.muesliswap.com/pools/pair',
getLiquidityPools: 'https://api.muesliswap.com/liquidity/pools',
getOrders: 'https://onchain2.muesliswap.com/orders/all/',
getCompletedOrders: 'https://api.muesliswap.com/orders/v2',
getCompletedOrders: 'https://api.muesliswap.com/orders/v3/history',
getTokenPairs: 'https://api.muesliswap.com/list',
getTokens: 'https://api.muesliswap.com/token-list',
constructSwapDatum: 'https://aggregator.muesliswap.com/constructSwapDatum',
Expand All @@ -18,7 +18,7 @@ export const SWAP_API_ENDPOINTS = {
getPoolsPair: 'https://preprod.pools.muesliswap.com/pools/pair',
getLiquidityPools: 'https://preprod.api.muesliswap.com/liquidity/pools',
getOrders: 'https://preprod.pools.muesliswap.com/orders/all/',
getCompletedOrders: 'https://api.muesliswap.com/orders/v2',
getCompletedOrders: 'https://preprod.api.muesliswap.com/orders/v3/history',
getTokenPairs: 'https://preprod.api.muesliswap.com/list',
getTokens: 'https://preprod.api.muesliswap.com/token-list',
constructSwapDatum:
Expand Down
3 changes: 1 addition & 2 deletions packages/swap/src/adapters/openswap-api/openswap.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ const getCompletedOrders: CompletedOrder[] = [
attachedLvl: 'someAttachedLvl',
scriptVersion: 'v1',
pubKeyHash: 'somePubKeyHash',
feeField: 10,
dex: 'minswap',
},
]

Expand Down Expand Up @@ -403,7 +403,6 @@ const getOpenOrders: OpenOrder[] = [
// ],
utxo: '1e977694e2413bd0e6105303bb44da60530cafe49b864dde8f8902b021ed86ba#0',
provider: 'muesliswap_v4',
// feeField: '2650000',
// allowPartial: true,
owner:
'addr1qxxvt9rzpdxxysmqp50d7f5a3gdescgrejsu7zsdxqjy8yun4cngaq46gr8c9qyz4td9ddajzqhjnrqvfh0gspzv9xnsmq6nqx',
Expand Down
6 changes: 1 addition & 5 deletions packages/swap/src/adapters/openswap-api/orders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ export async function getCompletedOrders(
const response = await client.get<CompletedOrderResponse>(apiUrl, {
params: {
'stake-key-hash': stakeKeyHash,
'canceled': 'n',
'open': 'n',
'matched': 'y',
'v2_only': 'y',
},
})

Expand All @@ -114,5 +110,5 @@ export async function getCompletedOrders(
})
}

return response.data.filter((order) => order.status === 'matched')
return response.data
}
2 changes: 1 addition & 1 deletion packages/swap/src/adapters/openswap-api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export type CompletedOrder = {
attachedLvl: string
scriptVersion: string
pubKeyHash: string
feeField: number
dex: Provider
}
export type CompletedOrderResponse = CompletedOrder[]

Expand Down
10 changes: 10 additions & 0 deletions packages/swap/src/helpers/transformers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ describe('asYoroiCompletedOrder', () => {
)

expect(result).toEqual<Swap.CompletedOrder>(apiMocks.getCompletedOrders[0]!)

const missingDex = {...openswapMocks.getCompletedOrders[0]!}
missingDex.dex = undefined as any
const defaultedProviderToMuesliswap = {
...apiMocks.getCompletedOrders[0]!,
provider: 'muesliswap' as Swap.PoolProvider,
}

const result2 = transformers.asYoroiCompletedOrder(missingDex)
expect(result2).toEqual<Swap.CompletedOrder>(defaultedProviderToMuesliswap)
})
})

Expand Down
7 changes: 5 additions & 2 deletions packages/swap/src/helpers/transformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ export const transformersMaker = (
}

const asYoroiCompletedOrder = (openswapOrder: CompletedOrder) => {
const {txHash, fromAmount, fromToken, toAmount, toToken} = openswapOrder
const {txHash, fromAmount, fromToken, toAmount, toToken, placedAt, dex} =
openswapOrder
const from = {
amount: fromAmount,
token: `${fromToken.address.policyId}.${fromToken.address.name}`,
Expand All @@ -93,9 +94,11 @@ export const transformersMaker = (
}

return {
txHash: txHash,
txHash,
from: asYoroiAmount(from),
to: asYoroiAmount(to),
placedAt: placedAt * 1000,
provider: dex ?? 'muesliswap',
} as const
}

Expand Down
2 changes: 2 additions & 0 deletions packages/types/src/swap/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ export type SwapCompletedOrder = {
from: BalanceAmount
to: BalanceAmount
txHash: string
provider: SwapPoolProvider
placedAt: number
}

0 comments on commit 93dd264

Please sign in to comment.