-
Notifications
You must be signed in to change notification settings - Fork 20
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
TeddySwap Integration #69
Merged
Merged
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c4a298d
TeddySwap init
Sluder a5da781
Init tests
Sluder 78f455f
Merge branch 'master' of github.com:IndigoProtocol/dexter into sluder…
Sluder 9c096fe
TeddySwap formulas; Fix tests; Add nullable SKH
Sluder 7930518
TeddySwap API
Sluder 4ed20d8
Cleanup
Sluder 0a0e678
LP token
Sluder 2e1835f
Merge & reject if no LP token
Sluder 57ec5f1
TeddySwap Finalize
Sluder 535092d
Remove log
Sluder a722128
Inline datum support
Sluder 49f27ba
Formula fix & pool NFT
Sluder 02081fb
NFT fix
Sluder b619a9a
Bigint cast
Sluder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { BaseApi } from './base-api'; | ||
import { Asset, Token } from '../models/asset'; | ||
import { LiquidityPool } from '../models/liquidity-pool'; | ||
import axios, { AxiosInstance } from 'axios'; | ||
import { RequestConfig } from '@app/types'; | ||
import { appendSlash, tokensMatch } from '@app/utils'; | ||
import { TeddySwap } from '@dex/teddyswap'; | ||
|
||
export class TeddyswapApi extends BaseApi { | ||
|
||
protected readonly api: AxiosInstance; | ||
protected readonly dex: TeddySwap; | ||
|
||
constructor(dex: TeddySwap, requestConfig: RequestConfig) { | ||
super(); | ||
|
||
this.dex = dex; | ||
this.api = axios.create({ | ||
timeout: requestConfig.timeout, | ||
baseURL: `${appendSlash(requestConfig.proxyUrl)}https://analytics.teddyswap.org/v1`, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
} | ||
}); | ||
} | ||
|
||
liquidityPools(assetA: Token, assetB?: Token): Promise<LiquidityPool[]> { | ||
return this.api.get('/front/pools', ).then((response: any) => { | ||
return response.data.map((poolResponse: any) => { | ||
const tokenA: Token = poolResponse.lockedX.asset.currencySymbol !== '' | ||
? new Asset(poolResponse.lockedX.asset.currencySymbol, Buffer.from(poolResponse.lockedX.asset.tokenName, 'utf8').toString('hex')) | ||
: 'lovelace'; | ||
const tokenB: Token = poolResponse.lockedY.asset.currencySymbol !== '' | ||
? new Asset(poolResponse.lockedY.asset.currencySymbol, Buffer.from(poolResponse.lockedY.asset.tokenName, 'utf8').toString('hex')) | ||
: 'lovelace'; | ||
|
||
if (! tokensMatch(tokenA, assetA) || (assetB && ! tokensMatch(tokenB, assetB))) { | ||
return undefined; | ||
} | ||
|
||
let liquidityPool: LiquidityPool = new LiquidityPool( | ||
TeddySwap.identifier, | ||
tokenA, | ||
tokenB, | ||
BigInt(poolResponse.lockedX.amount), | ||
BigInt(poolResponse.lockedY.amount), | ||
'', // Not supplied | ||
this.dex.orderAddress, | ||
this.dex.orderAddress, | ||
); | ||
|
||
liquidityPool.lpToken = new Asset(poolResponse.lockedLQ.asset.currencySymbol, Buffer.from(poolResponse.lockedLQ.asset.tokenName, 'utf8').toString('hex')); | ||
liquidityPool.poolFeePercent = (1 - (poolResponse.poolFeeNum / poolResponse.poolFeeDenum)) * 10; | ||
liquidityPool.identifier = liquidityPool.lpToken.identifier(); | ||
|
||
return liquidityPool; | ||
}).filter((pool: LiquidityPool | undefined) => pool !== undefined) as LiquidityPool[]; | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { DatumParameterKey } from '@app/constants'; | ||
import { DatumParameters, DefinitionField } from '@app/types'; | ||
|
||
export default { | ||
constructor: 0, | ||
fields: [ | ||
{ | ||
constructor: 0, | ||
fields: [ | ||
{ | ||
bytes: DatumParameterKey.SwapInTokenPolicyId | ||
}, | ||
{ | ||
bytes: DatumParameterKey.SwapInTokenAssetName | ||
} | ||
], | ||
}, | ||
{ | ||
constructor: 0, | ||
fields: [ | ||
{ | ||
bytes: DatumParameterKey.SwapOutTokenPolicyId | ||
}, | ||
{ | ||
bytes: DatumParameterKey.SwapOutTokenAssetName | ||
} | ||
], | ||
}, | ||
{ | ||
constructor: 0, | ||
fields: [ | ||
{ | ||
bytes: DatumParameterKey.TokenPolicyId // Pool NFT | ||
}, | ||
{ | ||
bytes: DatumParameterKey.TokenAssetName | ||
} | ||
], | ||
}, | ||
{ | ||
int: DatumParameterKey.LpFee | ||
}, | ||
{ | ||
int: DatumParameterKey.LpFeeNumerator // Execution fee numerator | ||
}, | ||
{ | ||
int: DatumParameterKey.LpFeeDenominator // Execution fee denominator | ||
}, | ||
{ | ||
bytes: DatumParameterKey.SenderPubKeyHash | ||
}, | ||
(field: DefinitionField, parameters: DatumParameters, shouldExtract: boolean = true) => { | ||
if (! shouldExtract) { | ||
const stakeKeyHash: string = parameters[DatumParameterKey.SenderStakingKeyHash] as string ?? null; | ||
|
||
if (! stakeKeyHash) return; | ||
|
||
return { | ||
constructor: 0, | ||
fields: [ | ||
{ | ||
bytes: stakeKeyHash, | ||
} | ||
], | ||
}; | ||
} | ||
|
||
if ('fields' in field) { | ||
if (field.constructor === 1) return; | ||
|
||
if (field.fields.length > 0 && 'bytes' in field.fields[0]) { | ||
parameters[DatumParameterKey.SenderStakingKeyHash] = field.fields[0].bytes; | ||
} | ||
} | ||
|
||
return; | ||
}, | ||
{ | ||
int: DatumParameterKey.SwapInAmount | ||
}, | ||
{ | ||
int: DatumParameterKey.MinReceive | ||
} | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { DatumParameterKey } from '@app/constants'; | ||
|
||
export default { | ||
constructor: 0, | ||
fields: [ | ||
{ | ||
constructor: 0, | ||
fields: [ | ||
{ | ||
bytes: DatumParameterKey.TokenPolicyId // Pool NFT | ||
}, | ||
{ | ||
bytes: DatumParameterKey.TokenAssetName | ||
} | ||
] | ||
}, | ||
{ | ||
constructor: 0, | ||
fields: [ | ||
{ | ||
bytes: DatumParameterKey.PoolAssetAPolicyId | ||
}, | ||
{ | ||
bytes: DatumParameterKey.PoolAssetAAssetName | ||
} | ||
] | ||
}, | ||
{ | ||
constructor: 0, | ||
fields: [ | ||
{ | ||
bytes: DatumParameterKey.PoolAssetBPolicyId | ||
}, | ||
{ | ||
bytes: DatumParameterKey.PoolAssetBAssetName | ||
} | ||
] | ||
}, | ||
{ | ||
constructor: 0, | ||
fields: [ | ||
{ | ||
bytes: DatumParameterKey.LpTokenPolicyId | ||
}, | ||
{ | ||
bytes: DatumParameterKey.LpTokenAssetName | ||
} | ||
] | ||
}, | ||
{ | ||
int: DatumParameterKey.LpFee | ||
}, | ||
[ | ||
{ | ||
bytes: DatumParameterKey.StakeAdminPolicy | ||
} | ||
], | ||
{ | ||
int: DatumParameterKey.LqBound | ||
} | ||
] | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -210,6 +210,7 @@ export class Minswap extends BaseDex { | |
}, | ||
], | ||
datum: datumBuilder.getCbor(), | ||
isInlineDatum: false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice approach! |
||
spendUtxos: spendUtxos, | ||
} | ||
) | ||
|
@@ -230,6 +231,7 @@ export class Minswap extends BaseDex { | |
address: returnAddress, | ||
addressType: AddressType.Base, | ||
assetBalances: relevantUtxo.assetBalances, | ||
isInlineDatum: false, | ||
spendUtxos: [relevantUtxo], | ||
} | ||
]; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adds support for datum mappings to include dynamic pulling/pushing of parameters. One example would be an order datum not including a stake key, which will result in a different datum. Not all DEXs support this atm, but will push a fix after this PR is in