Skip to content

Commit

Permalink
Implement minting cap (#471)
Browse files Browse the repository at this point in the history
  • Loading branch information
tifrel authored Feb 13, 2024
1 parent 195edf6 commit a1fea80
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/sdk/src/batchChangeCreators/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[//]: # `{ "title": "batchChangeCreators", "order": 0.17 }`
[//]: # `{ "title": "batchChangeCreators", "order": 0.18 }`

# Batch change creators

Expand Down
3 changes: 2 additions & 1 deletion packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export * from './mint/mint';
export * from './delist/delist';
export * from './setSplits/setSplits';
export * from './transferContractOwnership/transferContractOwnership';
// export * from './ftDepositStorage/ftDepositStorage'; // TODO:
export * from './setMintingCap/setMintingCap';
export * from './ftDepositStorage/ftDepositStorage'; // TODO:
export { mbjs } from './config/config';
export * from './types';
58 changes: 58 additions & 0 deletions packages/sdk/src/setMintingCap/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[//]: # `{ "title": "depositStorage", "order": 0.19 }`

# Set a minting cap

Sets a minting cap on this smart contract. This will restrict minting on the smart contract to the specified number of tokens. This is a commitment not to create more tokens in the future, introducing rarity. Once a minting cap has been set, it cannot be changed, and it cannot be removed.

The `contractAddress` can be supplied as an argument or through the `TOKEN_CONTRACT` environment variable.

**As with all new SDK api methods, this call should be wrapped in [execute](../#execute) and passed a signing method**

This is only available on Mintbase v2 smart contracts.

## setMintingCap(args: SetMintingCapArgs): NearContractCall

`setMintingCap` takes a single argument of type `SetMintingCapArgs`

```typescript
export type SetMintingCapArgs = {
//accountId of the smart contract for which the minting cap is to be changed
contractAddress?: string;
//the cap that will be put in pluce
mintingCap: number;
}
```
## React example
Example usage of deployContract method in a hypothetical React component:
{% code title="DepositStorageComponent.ts" overflow="wrap" lineNumbers="true" %}
```typescript
import { useState } from 'react';
import { useWallet } from '@mintbase-js/react';
import { execute, setMintingCap, SetMintingCapArgs } from '@mintbase-js/sdk';


export const SetMintingCapComponent = ({ contractAddress, mintingCap }:SetMintingCapArgs):JSX.Element => {
const { selector } = useWallet();

const handleSetMintingCap = async (): Promise<void> => {
const wallet = await selector.wallet();

await execute(
{wallet},
setMintingCap({ contractAddress, mintingCap })
);
}

return (
<div>
<button onClick={handleSetMintingCap}>
Set minting cap for {contractAddress} to {mintinCap}
</button>
</div>
);
};
```
{% endcode %}
31 changes: 31 additions & 0 deletions packages/sdk/src/setMintingCap/setMintingCap.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { mbjs } from '../config/config';
import { GAS, ONE_YOCTO } from '../constants';
import { TOKEN_METHOD_NAMES } from '../types';
import { setMintingCap } from './setMintingCap';


describe('set minting cap unit tests', () => {
const contractAddress = `test.${mbjs.keys.mbContractV2}`;

test('set minting cap', () => {
const args = setMintingCap({
contractAddress,
mintingCap: 1234,
});

expect(args).toEqual({
contractAddress,
methodName: TOKEN_METHOD_NAMES.SET_MINTING_CAP,
args: { minting_cap: 1234 },
deposit: ONE_YOCTO,
gas: GAS,
});
});

test('cannot set minting cap for v1 contracts', () => {
expect(() => setMintingCap({
contractAddress: `test.${mbjs.keys.mbContract}`,
mintingCap: 1234,
})).toThrow();
});
});
28 changes: 28 additions & 0 deletions packages/sdk/src/setMintingCap/setMintingCap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { mbjs } from '../config/config';
import { GAS, ONE_YOCTO } from '../constants';
import { SetMintingCapArgs, NearContractCall, TOKEN_METHOD_NAMES } from '../types';
import { isStoreV2 } from '../utils';
import { ERROR_MESSAGES } from '../errorMessages';


/**
* Deposits 0.01 * listAmount of near to the market contract to be consumed for listing purposes
* @param args {@link SetMintingCapArgs}
* @returns contract call to be passed to @mintbase-js/sdk execute method
*/
export const setMintingCap = (args: SetMintingCapArgs): NearContractCall<{}> => {

const { contractAddress = mbjs.keys.contractAddress, mintingCap } = args;

if (!isStoreV2(contractAddress)) {
throw new Error(ERROR_MESSAGES.ONLY_V2);
}

return {
contractAddress,
args: { minting_cap: mintingCap },
methodName: TOKEN_METHOD_NAMES.SET_MINTING_CAP,
deposit: ONE_YOCTO,
gas: GAS,
};
};
8 changes: 7 additions & 1 deletion packages/sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export enum TOKEN_METHOD_NAMES {
BATCH_CHANGE_CREATORS = 'batch_change_creators',
TOKEN_ACCOUNT_REVOKE = 'nft_revoke',
TOKEN_ACCOUNT_REVOKE_ALL = 'nft_revoke_all',
SET_SPLITS = 'set_split_owners'
SET_SPLITS = 'set_split_owners',
SET_MINTING_CAP = 'set_minting_cap'
}

export enum MARKET_METHOD_NAMES {
Expand Down Expand Up @@ -316,6 +317,11 @@ export type FtDepositStorageArgs = {
accountId?: string;
};

export type SetMintingCapArgs = {
contractAddress?: string;
mintingCap: number;
}

export declare type TxnOptionalSignerId = Optional<Transaction, 'signerId'>;

export interface MinterArgsResponse {
Expand Down

0 comments on commit a1fea80

Please sign in to comment.