-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
127 additions
and
3 deletions.
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
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,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 %} |
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,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(); | ||
}); | ||
}); |
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,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, | ||
}; | ||
}; |
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