Skip to content

Commit

Permalink
feat: create inventory position with vToken (#15)
Browse files Browse the repository at this point in the history
* feat: create inventory position with vToken

* fixup! feat: create inventory position with vToken
  • Loading branch information
jackmellis authored Dec 19, 2023
1 parent d84b8b3 commit 8d9a9df
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
3 changes: 2 additions & 1 deletion packages/react/src/trade/useApprove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ const useApprove = (opts?: UseTransactionOptions) => {
const {
provider,
signer,
network,
core: { approve },
} = useNftx();

return useTransaction(
(args: Args) => approve({ ...args, provider, signer }),
(args: Args) => approve({ ...args, provider, signer, network }),
{
description: 'Approve',
...opts,
Expand Down
32 changes: 30 additions & 2 deletions packages/trade/src/positions/createInventoryPosition.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
import { InventoryStaking } from '@nftx/abi';
import config from '@nftx/config';
import { INVENTORY_STAKING } from '@nftx/constants';
import { CreateInventoryPositionQuote, Provider, Signer } from '@nftx/types';
import {
CreateInventoryPositionQuote,
Permit2Quote,
Provider,
Signer,
} from '@nftx/types';
import { getChainConstant, getContract } from '@nftx/utils';

const createInventoryPosition = ({
provider,
quote: {
methodParameters: { nftAmounts, nftIds, userAddress, vaultId },
methodParameters: {
nftAmounts,
nftIds,
userAddress,
vaultId,
vToken,
usePermit2,
},
},
signer,
network = config.network,
permit2,
}: {
network?: number;
quote: Pick<CreateInventoryPositionQuote, 'methodParameters'>;
provider: Provider;
signer: Signer;
permit2?: Permit2Quote;
}) => {
const contract = getContract({
address: getChainConstant(INVENTORY_STAKING, network),
Expand All @@ -24,6 +38,20 @@ const createInventoryPosition = ({
signer,
});

// You can either dpeosit with vToken, or with NFTs
if (vToken) {
return contract.write.deposit({
args: [
BigInt(vaultId),
vToken,
userAddress,
(usePermit2 ? permit2?.permit2encoded : undefined) || '0x',
!!(usePermit2 && permit2),
true,
],
});
}

return contract.write.depositWithNFT({
args: [BigInt(vaultId), nftIds, nftAmounts, userAddress],
});
Expand Down
6 changes: 5 additions & 1 deletion packages/types/src/quotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,20 @@ export type WithdrawInventoryQuote = {

export type CreateInventoryPositionQuoteParams = {
vaultId: string;
tokenIds: [TokenId, number][] | TokenId[];
userAddress: Address;
vToken?: bigint;
usePermit2?: boolean;
tokenIds?: [TokenId, number][] | TokenId[];
};

export type CreateInventoryPositionQuote = {
methodParameters: {
vaultId: bigint;
nftIds: bigint[];
vToken: bigint;
nftAmounts: bigint[];
userAddress: Address;
usePermit2: boolean;
};
approveContracts: ApproveContract[];
};
Expand Down
2 changes: 0 additions & 2 deletions packages/types/src/vaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ export type Vault = {
shutdownDate: number;
/** The ETH price of 1 vToken (comes from vaultContract.vTokenToETH(WeiPerEther)) */
vTokenToEth: bigint;
// feeReceipts: Pick<VaultFeeReceipt, 'amount' | 'date' | 'transfers'>[];
// activity: Pick<VaultActivity, 'vaultAddress' | 'vaultId'>;
};

export type VaultActivityType =
Expand Down

0 comments on commit 8d9a9df

Please sign in to comment.