Skip to content

Commit

Permalink
fixed create pool
Browse files Browse the repository at this point in the history
  • Loading branch information
Ridel1e committed Feb 21, 2024
1 parent 0f53dc3 commit 4a67cef
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@sentry/react": "^6.16.1",
"@sentry/tracing": "^6.16.1",
"@spectrumlabs/analytics": "^1.1.9",
"@spectrumlabs/cardano-dex-sdk": "^0.1.302",
"@spectrumlabs/cardano-dex-sdk": "^0.1.304",
"@types/file-saver": "^2.0.5",
"@types/lodash": "^4.14.172",
"@types/numeral": "^2.0.2",
Expand Down
3 changes: 3 additions & 0 deletions src/applicationConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ interface NetworkConfig {
readonly lowBalanceGuide?: string;
readonly defaultTokenListUrl: string;
readonly lbspWhitelistUrl: string;
readonly daoPolicyUrl?: string;
readonly isCreatePoolAvailable: boolean;
readonly additionalTokenList?: DefaultTokenListItem[];
}
Expand Down Expand Up @@ -84,6 +85,7 @@ export const applicationConfig: ApplicationConfig = {
networksSettings: {
cardano_preview: {
name: 'cardano_preview',
daoPolicyUrl: 'https://meta.spectrum.fi/cardano/preprod/dao/data/',
defaultTokenListUrl: 'https://spectrum.fi/cardano-token-list.json',
lbspWhitelistUrl: 'https://spectrum.fi/lbsp_whitelist.json',
metadataUrl:
Expand All @@ -108,6 +110,7 @@ export const applicationConfig: ApplicationConfig = {
},
cardano: {
name: 'cardano',
daoPolicyUrl: 'https://meta.spectrum.fi/cardano/preprod/dao/data/',
additionalTokenList: [],
defaultTokenListUrl: 'https://spectrum.fi/cardano-token-list.json',
lbspWhitelistUrl: 'https://spectrum.fi/lbsp_whitelist.json',
Expand Down
40 changes: 36 additions & 4 deletions src/network/cardano/api/operations/createPool.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { FormGroup } from '@ergolabs/ui-kit';
import { t } from '@lingui/macro';
import {
AssetAmount,
AssetClass,
FullTxIn,
InputSelector,
PoolCreationTxInfo,
Expand All @@ -12,6 +13,7 @@ import {
import { AmmPoolType } from '@spectrumlabs/cardano-dex-sdk/build/main/amm/domain/ammPool';
import { NetworkParams } from '@spectrumlabs/cardano-dex-sdk/build/main/cardano/entities/env';
import { InputCollector } from '@spectrumlabs/cardano-dex-sdk/build/main/cardano/wallet/inputSelector';
import { encodeHex } from '@spectrumlabs/cardano-dex-sdk/build/main/utils/hex';
import { RustModule } from '@spectrumlabs/cardano-dex-sdk/build/main/utils/rustLoader';
import axios from 'axios';
import {
Expand Down Expand Up @@ -42,6 +44,7 @@ import { OperationValidator } from '../../../../components/OperationForm/Operati
import { normalizeAmountWithFee } from '../../../../pages/AddLiquidityOrCreatePool/common/utils';
import { CreatePoolFormModel } from '../../../../pages/CreatePool/CreatePoolFormModel';
import { CardanoSettings, settings$ } from '../../settings/settings';
import { cardanoNetworkData } from '../../utils/cardanoNetworkData.ts';
import { CreatePoolConfirmationInfo } from '../../widgets/CreatePoolConfirmationInfo/CreatePoolConfirmationInfo';
import { cardanoNetworkParams$ } from '../common/cardanoNetwork';
import { networkAsset } from '../networkAsset/networkAsset';
Expand All @@ -62,6 +65,20 @@ interface MintingMetadata {
readonly script: string;
}

const getDaoPolicy = (nftAsset: AssetClass): Observable<string | undefined> => {
return from(
axios
.post<{ curSymbol: string }>(cardanoNetworkData.daoPolicyUrl || '', {
nftCS: nftAsset.policyId,
nftTN: encodeHex(
RustModule.CardanoWasm.AssetName.from_hex(nftAsset.nameHex).name(),
),
})
.then((res) => res.data.curSymbol)
.catch(() => undefined),
);
};

const getTokenMetadata = (
utxo: FullTxIn,
name: string,
Expand Down Expand Up @@ -160,6 +177,19 @@ export const toCreatePoolTxCandidate = ({
utxo,
`${yAmount.asset.name}_${xAmount.asset.name || 'ADA'}_NFT`,
'1',
).pipe(
switchMap((nftData) => {
return getDaoPolicy(nftData[0].asset).pipe(
map(
(daoPolicy) =>
[nftData[0], nftData[1], daoPolicy] as [
AssetAmount,
MintingMetadata,
string,
],
),
);
}),
),
getTokenMetadata(
utxo,
Expand All @@ -171,11 +201,11 @@ export const toCreatePoolTxCandidate = ({
}),
switchMap(
([nftData, lqData, utxo]: [
[AssetAmount, MintingMetadata],
[AssetAmount, MintingMetadata, string],
[AssetAmount, MintingMetadata],
FullTxIn,
]) =>
transactionBuilder$.pipe(
]) => {
return transactionBuilder$.pipe(
switchMap((transactionBuilder) => {
return transactionBuilder.poolCreation({
x: new AssetAmount(x.asset.data, x.amount),
Expand All @@ -192,9 +222,11 @@ export const toCreatePoolTxCandidate = ({
collateralAmount: 4000000n,
pk: settings.ph!,
type: AmmPoolType.FEE_SWITCH,
daoPolicy: nftData[2],
});
}),
),
);
},
),
first(),
);
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3337,10 +3337,10 @@
dependencies:
"@amplitude/analytics-browser" "^1.9.0"

"@spectrumlabs/cardano-dex-sdk@^0.1.302":
version "0.1.302"
resolved "https://registry.yarnpkg.com/@spectrumlabs/cardano-dex-sdk/-/cardano-dex-sdk-0.1.302.tgz#ac2f66e3ad471c83fda57612b6632d77362a85c5"
integrity sha512-aIeDbshvfZlboBKHSUl6k8tF2rb6DtYiXtCxXkFq1Euo8zvG11HIep27gcoBjZrPM9OSwcrRlNrwQFZ0/KgLdw==
"@spectrumlabs/cardano-dex-sdk@^0.1.304":
version "0.1.304"
resolved "https://registry.yarnpkg.com/@spectrumlabs/cardano-dex-sdk/-/cardano-dex-sdk-0.1.304.tgz#5a0da7ea40ff6188a1241258a523095a20dd4b6a"
integrity sha512-QfCgYAXgZAJqo6utl9QKKgIZ5B0VTpMJ3StHGnsX79DYr2lEb2Hgc3lBhKqF99zFEWTZkGauWHPs+h7bFMXmeg==
dependencies:
"@emurgo/cardano-serialization-lib-browser" "^11.5.0"
axios "^0.21.1"
Expand Down

0 comments on commit 4a67cef

Please sign in to comment.