Skip to content

Commit

Permalink
feat: update AMMV3 components and hooks for improved functionality an…
Browse files Browse the repository at this point in the history
…d styling, including new ClaimButton and useV3PositionFees hook
  • Loading branch information
yrjkqq committed Nov 28, 2024
1 parent 1e3f053 commit a29de47
Show file tree
Hide file tree
Showing 13 changed files with 521 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ export const Primary = (props: any) => {
chainId: 11155111,
// chainId: 1,
}}
feeAmount={500}
// feeAmount={500}
// tokenId={'25235'}
feeAmount={10000}
tokenId={'26887'}
onClose={() => window.alert('onClose')}
/>
Expand Down
97 changes: 60 additions & 37 deletions packages/dodoex-api/src/services/ammv3/AMMV3Api.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { BigNumber as BigNumberE } from '@ethersproject/bignumber';
import BigNumber from 'bignumber.js';
import { ChainId, contractConfig } from '../../chainConfig';
import ContractRequests, {
CONTRACT_QUERY_KEY,
ContractRequestsConfig,
} from '../../helper/ContractRequests';
import { ABIName } from '../../helper/ContractRequests/abi/abiName';
import { encodeFunctionData } from '../../helper/ContractRequests/encode';
import { AllV3TicksDocument } from './queries';
import { poolUtils } from '../pool/poolUtils';
import { AllV3TicksDocument } from './queries';

export interface AMMV3ApiProps {
contractRequests?: ContractRequests;
Expand All @@ -34,40 +33,7 @@ export class AMMV3Api {

static utils = poolUtils;

static encode = {
async addDVMLiquidityABI(
chainId: number,
dvmAddress: string,
baseInAmount: string,
quoteInAmount: string,
baseMinAmount: string,
quoteMinAmount: string,
flag: number,
deadline: number,
) {
if (!baseMinAmount || baseMinAmount === '0') {
throw new Error('Invalid baseMinAmount');
}
const { DODO_PROXY } = contractConfig[chainId as ChainId];
const data = await encodeFunctionData(
ABIName.dodoProxyV2,
'addDVMLiquidity',
[
dvmAddress,
baseInAmount,
quoteInAmount,
baseMinAmount,
quoteMinAmount,
flag,
deadline,
],
);
return {
to: DODO_PROXY,
data,
};
},
};
static encode = {};

getPositions(
chainId: number | undefined,
Expand Down Expand Up @@ -98,6 +64,30 @@ export class AMMV3Api {
};
}

getOwner(
chainId: number | undefined,
contractAddress: string | undefined,
tokenId: string,
) {
return {
queryKey: [CONTRACT_QUERY_KEY, 'ammv3', 'getOwner', ...arguments],
enabled: !!chainId && !!contractAddress,
queryFn: async () => {
if (!chainId || !contractAddress) {
return null;
}

const result = await this.contractRequests.batchCallQuery(chainId, {
abiName: ABIName.NonfungiblePositionManager,
contractAddress,
method: 'ownerOf',
params: [tokenId],
});
return result;
},
};
}

getBalanceOf(
chainId: number | undefined,
contractAddress: string | undefined,
Expand Down Expand Up @@ -203,4 +193,37 @@ export class AMMV3Api {
},
};
}

getCollect(
chainId: number | undefined,
contractAddress: string | undefined,
tokenId: string,
recipient: string,
) {
return {
queryKey: [CONTRACT_QUERY_KEY, 'ammv3', 'getCollect', ...arguments],
enabled: !!chainId || !!contractAddress,
queryFn: async () => {
if (!chainId || !contractAddress || !tokenId || !recipient) {
return null;
}
const MAX_UINT128 = BigNumberE.from(2).pow(128).sub(1);
const result = await this.contractRequests.callQuery(chainId, {
abiName: ABIName.NonfungiblePositionManager,
contractAddress,
method: 'collect',
params: [
{
tokenId,
recipient, // some tokens might fail if transferred to address(0)
amount0Max: MAX_UINT128,
amount1Max: MAX_UINT128,
},
{ from: recipient }, // need to simulate the call as the owner
],
});
return result;
},
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ function RewardCard({
xmlns="http://www.w3.org/2000/svg"
>
<path
fill-rule="evenodd"
clip-rule="evenodd"
fillRule="evenodd"
clipRule="evenodd"
d="M9.66659 2H6.33325L5.66659 2.66667H3.33325V4H12.6666V2.66667H10.3333L9.66659 2ZM10.6666 6V12.6667H5.33325V6H10.6666ZM3.99992 4.66667H11.9999V12.6667C11.9999 13.4 11.3999 14 10.6666 14H5.33325C4.59992 14 3.99992 13.4 3.99992 12.6667V4.66667Z"
fill={theme.palette.error.main}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export function ClaimTips() {
xmlns="http://www.w3.org/2000/svg"
>
<path
fill-rule="evenodd"
clip-rule="evenodd"
fillRule="evenodd"
clipRule="evenodd"
d="M9.20379 1.80945L4.81274 1.79788L1.69961 4.89464L1.68804 9.28569L4.7848 12.3988L9.17585 12.4104L12.289 9.31363L12.3006 4.92258L9.20379 1.80945ZM13.4685 4.44241L9.69012 0.644062L4.33257 0.629942L0.534222 4.40832L0.520101 9.76587L4.29848 13.5642L9.65602 13.5783L13.4544 9.79996L13.4685 4.44241Z"
fill="currentColor"
/>
Expand Down
Loading

0 comments on commit a29de47

Please sign in to comment.