Skip to content

Commit

Permalink
v3 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sluder committed Aug 9, 2024
2 parents 642e07e + a78ac02 commit 3c965f0
Show file tree
Hide file tree
Showing 19 changed files with 588 additions and 104 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
All notable changes to Dexter will be documented in this file.

## [UNRELEASED]
- SundaeSwap v3 implementation
- SundaeSwap v3 integration

## [v5.3.0]
- Minswap v2 integration

## [v5.2.0]
- Add `withMinimumReceive(minReceive: bigint)` to SwapRequest
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<p align="center">Customizable Typescript SDK for interacting with Cardano DEXs.</p>
<img src="https://raw.githubusercontent.com/IndigoProtocol/dexter/master/src/dex/logo/sundaeswap.png" width="30" />
<img src="https://raw.githubusercontent.com/IndigoProtocol/dexter/master/src/dex/logo/minswap.png" width="30" />
<img src="https://raw.githubusercontent.com/IndigoProtocol/dexter/master/src/dex/logo/minswapv2.png" width="30" />
<img src="https://raw.githubusercontent.com/IndigoProtocol/dexter/master/src/dex/logo/muesliswap.png" width="30" />
<img src="https://raw.githubusercontent.com/IndigoProtocol/dexter/master/src/dex/logo/wingriders.png" width="30" />
<img src="https://raw.githubusercontent.com/IndigoProtocol/dexter/master/src/dex/logo/vyfinance.png" width="30" />
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@indigo-labs/dexter",
"version": "5.2.0",
"version": "5.3.0",
"license": "MIT",
"author": "Zachary Sluder",
"keywords": [
Expand Down
7 changes: 6 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ export enum DatumParameterKey {
* Generics.
*/
Action = 'Action',
CancelDatum = 'CancelDatum',
TokenPolicyId = 'TokenPolicyId',
TokenAssetName = 'TokenAssetName',
ReserveA = 'ReserveA',
ReserveB = 'ReserveB',
CancelDatum = 'CancelDatum',

/**
* Swap/wallet info.
Expand All @@ -27,6 +29,7 @@ export enum DatumParameterKey {
MinReceive = 'MinReceive',
Expiration = 'Expiration',
AllowPartialFill = 'AllowPartialFill',
Direction = 'Direction',

/**
* Trading fees.
Expand All @@ -35,6 +38,8 @@ export enum DatumParameterKey {
BatcherFee = 'BatcherFee',
DepositFee = 'DepositFee',
ScooperFee = 'ScooperFee',
BaseFee = 'BaseFee',
FeeSharingNumerator = 'FeeSharingNumerator',
OpeningFee = 'OpeningFee',
FinalFee = 'FinalFee',
FeesFinalized = 'FeesFinalized',
Expand Down
6 changes: 3 additions & 3 deletions src/definition-builder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DatumParameters, DefinitionConstr, DefinitionField } from './types';
import { datumJsonToCbor } from 'lucid-cardano';
import { DatumParameterKey } from './constants';
import _ from 'lodash';
import { datumJsonToCbor } from '@app/utils';

export class DefinitionBuilder {
private _definition: DefinitionConstr;
Expand Down Expand Up @@ -103,8 +103,6 @@ export class DefinitionBuilder {
field.bytes = parameterValue;
}

// Key Value Pairs.
// { bytes: "SwapInTokenPolicyId" }, { bytes: "SwapInTokenAssetName" },
if (Array.isArray(field) && field.every((item) => typeof item === 'object' && Object.keys(item).length === 1)) {
field.forEach((value) => {
return this.applyParameters(value, mappedParameters);
Expand All @@ -118,6 +116,8 @@ export class DefinitionBuilder {
* Recursively pull parameters from datum using definition template.
*/
private extractParameters(definedDefinition: DefinitionField, templateDefinition: DefinitionField, foundParameters: DatumParameters = {}): DatumParameters {
if (! templateDefinition) return foundParameters;

if (templateDefinition instanceof Function) {
templateDefinition(definedDefinition, foundParameters);

Expand Down
81 changes: 6 additions & 75 deletions src/dex/api/sundaeswap-v3-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,80 +31,11 @@ export class SundaeSwapV3Api extends BaseApi {
const assetBId: string = (assetB && assetB !== 'lovelace')
? assetB.identifier('.')
: 'ada.lovelace';
const assets: string[] = [assetAId, assetBId].sort();
const assets: string[] = [assetAId, assetBId];

return await this.api.post('', {
operationName: 'fetchPoolByAssets',
query: `
query fetchPoolByAssets($assets: [ID!]!) {
pools {
byAssets(assets: $assets) {
...PoolBrambleFragment
}
}
}
fragment PoolBrambleFragment on Pool {
id
assetA {
...AssetBrambleFragment
}
assetB {
...AssetBrambleFragment
}
assetLP {
...AssetBrambleFragment
}
feesFinalized {
slot
}
marketOpen {
slot
}
openingFee
finalFee
current {
quantityA {
quantity
}
quantityB {
quantity
}
quantityLP {
quantity
}
tvl {
quantity
}
}
version
}
fragment AssetBrambleFragment on Asset {
id
policyId
description
dateListed {
format
}
decimals
ticker
name
logo
assetName
metadata {
... on OnChainLabel20 {
__typename
}
... on OnChainLabel721 {
__typename
}
... on CardanoTokenRegistry {
__typename
}
}
}
`,
operationName: 'fetchPoolsByPair',
query: `query fetchPoolsByPair($assetA: ID!, $assetB: ID!) {\n pools {\n byPair(assetA: $assetA, assetB: $assetB) {\n ...PoolBrambleFragment\n }\n }\n}\n\nfragment PoolBrambleFragment on Pool {\n id\n assetA {\n ...AssetBrambleFragment\n }\n assetB {\n ...AssetBrambleFragment\n }\n assetLP {\n ...AssetBrambleFragment\n }\n feesFinalized {\n slot\n }\n marketOpen {\n slot\n }\n askFee\n bidFee\n feeManagerId\n current {\n quantityA {\n quantity\n }\n quantityB {\n quantity\n }\n quantityLP {\n quantity\n }\n tvl {\n quantity\n }\n }\n version\n}\n\nfragment AssetBrambleFragment on Asset {\n id\n policyId\n description\n dateListed {\n format\n }\n decimals\n ticker\n name\n logo\n assetName\n metadata {\n ... on OnChainLabel20 {\n __typename\n }\n ... on OnChainLabel721 {\n __typename\n }\n ... on CardanoTokenRegistry {\n __typename\n }\n }\n}`,
variables: {
assetA: assets[0],
assetB: assets[1],
Expand All @@ -123,16 +54,16 @@ export class SundaeSwapV3Api extends BaseApi {
pool.assetB.id === 'ada.lovelace'
? 'lovelace'
: Asset.fromIdentifier(pool.assetB.id, pool.assetB.decimals),
BigInt(pool.current.quantityA),
BigInt(pool.current.quantityB),
BigInt(pool.current.quantityA.quantity),
BigInt(pool.current.quantityB.quantity),
this.dex.poolAddress,
'',
'',
);

liquidityPool.identifier = pool.id;
liquidityPool.lpToken = Asset.fromIdentifier(pool.assetLP.id);
liquidityPool.poolFeePercent = Number((pool.openingFee[0] / pool.openingFee[1]) * 100);
liquidityPool.poolFeePercent = Number((pool.bidFee[0] / pool.bidFee[1]) * 100);
liquidityPool.totalLpTokens = BigInt(pool.current.quantityLP.quantity);

return liquidityPool;
Expand Down
130 changes: 130 additions & 0 deletions src/dex/definitions/minswap-v2/order.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import { DatumParameterKey } from '@app/constants';

/**
* https://github.com/minswap/minswap-dex-v2/blob/main/src/types/order.ts
*/
export default {
constructor: 0,
fields: [
{
constructor: 0,
fields: [
{
bytes: DatumParameterKey.SenderPubKeyHash,
}
]
},
{
constructor: 0,
fields: [
{
constructor: 0,
fields: [
{
bytes: DatumParameterKey.SenderPubKeyHash,
}
]
},
{
constructor: 0,
fields: [
{
constructor: 0,
fields: [
{
constructor: 0,
fields: [
{
bytes: DatumParameterKey.SenderStakingKeyHash,
}
]
}
]
}
]
}
]
},
{
constructor: 0,
fields: []
},
{
constructor: 0,
fields: [
{
constructor: 0,
fields: [
{
bytes: DatumParameterKey.SenderPubKeyHash,
}
]
},
{
constructor: 0,
fields: [
{
constructor: 0,
fields: [
{
constructor: 0,
fields: [
{
bytes: DatumParameterKey.SenderPubKeyHash,
}
]
}
]
}
]
}
]
},
{
constructor: 0,
fields: []
},
{
constructor: 0,
fields: [
{
bytes: DatumParameterKey.LpTokenPolicyId
},
{
bytes: DatumParameterKey.LpTokenAssetName
}
]
},
{
constructor: 0,
fields: [
{
constructor: DatumParameterKey.Direction,
fields: []
},
{
constructor: 0,
fields: [
{
int: DatumParameterKey.SwapInAmount
}
]
},
{
int: DatumParameterKey.MinReceive
},
{
constructor: 0,
fields: []
}
]
},
{
int: DatumParameterKey.BatcherFee
},
{
constructor: 1,
fields: []
}
]
}
59 changes: 59 additions & 0 deletions src/dex/definitions/minswap-v2/pool.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { DatumParameterKey } from '@app/constants';
import { DatumParameters, DefinitionField } from '@app/types';

/**
* https://github.com/minswap/minswap-dex-v2/blob/main/src/types/pool.ts
*/
export default {
constructor: 0,
fields: [
{
constructor: 0,
fields: [
(field: DefinitionField, parameters: DatumParameters, shouldExtract: boolean = true) => {
return;
},
]
},
{
constructor: 0,
fields: [
{
bytes: DatumParameterKey.PoolAssetAPolicyId
},
{
bytes: DatumParameterKey.PoolAssetAAssetName
}
]
},
{
constructor: 0,
fields: [
{
bytes: DatumParameterKey.PoolAssetBPolicyId
},
{
bytes: DatumParameterKey.PoolAssetBAssetName
}
]
},
{
int: DatumParameterKey.TotalLpTokens
},
{
int: DatumParameterKey.ReserveA
},
{
int: DatumParameterKey.ReserveB
},
{
int: DatumParameterKey.BaseFee
},
{
int: DatumParameterKey.FeeSharingNumerator
},
(field: DefinitionField, parameters: DatumParameters, shouldExtract: boolean = true) => {
return;
},
]
}
2 changes: 1 addition & 1 deletion src/dex/definitions/minswap/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default {
constructor: 0,
fields: [
{
bytes: DatumParameterKey.SenderStakingKeyHash,
bytes: DatumParameterKey.SenderPubKeyHash,
}
]
}
Expand Down
Binary file added src/dex/logo/minswapv2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 3c965f0

Please sign in to comment.