Skip to content

Commit

Permalink
Deprecate contract clients; export Typescript ABIs for interacting wi…
Browse files Browse the repository at this point in the history
…th deployed preset contracts (#213)

* add deprecation notice

* add typescript abis

* export abis

* add ImmutableERC1155

* update readme
  • Loading branch information
allan-almeida-imtbl authored May 14, 2024
1 parent 9295f9e commit 44835a6
Show file tree
Hide file tree
Showing 14 changed files with 3,227 additions and 25 deletions.
211 changes: 211 additions & 0 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
AllowlistERC721TransferApprovals:testBlockTransferForNoneOALAddr() (gas: 107740)
AllowlistERC721TransferApprovals:testBlockTransferForNoneOALAddr() (gas: 108284)
AllowlistERC721TransferApprovals:testBlockTransferForNoneOALWallet() (gas: 1188716)
AllowlistERC721TransferApprovals:testBlockTransferForNoneOALWallet() (gas: 1189260)
AllowlistERC721TransferApprovals:testBlockTransferFromNoneOALAddress() (gas: 108100)
AllowlistERC721TransferApprovals:testBlockTransferFromNoneOALAddress() (gas: 108602)
AllowlistERC721TransferApprovals:testDeployment() (gas: 10009)
AllowlistERC721TransferApprovals:testDeployment() (gas: 9965)
AllowlistERC721TransferApprovals:testDisguisedEOAApprovalTransfer() (gas: 278297)
AllowlistERC721TransferApprovals:testDisguisedEOAApprovalTransfer() (gas: 278946)
AllowlistERC721TransferApprovals:testOnReceiveTransferFrom() (gas: 258431)
AllowlistERC721TransferApprovals:testOnReceiveTransferFrom() (gas: 258937)
AllowlistERC721TransferApprovals:testShouldApproveAddrInOAL() (gas: 217133)
AllowlistERC721TransferApprovals:testShouldApproveAddrInOAL() (gas: 218414)
AllowlistERC721TransferApprovals:testShouldApproveEOA() (gas: 171898)
AllowlistERC721TransferApprovals:testShouldApproveEOA() (gas: 173179)
AllowlistERC721TransferApprovals:testShouldApproveWalletInOAL() (gas: 1325303)
AllowlistERC721TransferApprovals:testShouldApproveWalletInOAL() (gas: 1326606)
AllowlistERC721TransferApprovals:testShouldNotAllowApproveFromNoneOALContract() (gas: 107378)
AllowlistERC721TransferApprovals:testShouldNotAllowApproveFromNoneOALContract() (gas: 107679)
AllowlistERC721TransferApprovals:testShouldNotApproveNoneOALSCW() (gas: 1232905)
AllowlistERC721TransferApprovals:testShouldNotApproveNoneOALSCW() (gas: 1233322)
AllowlistERC721TransferApprovals:testTransferBetweenEOAs() (gas: 129660)
AllowlistERC721TransferApprovals:testTransferBetweenEOAs() (gas: 130368)
AllowlistERC721TransferApprovals:testTransferBetweenSCWInOAL() (gas: 2263192)
AllowlistERC721TransferApprovals:testTransferBetweenSCWInOAL() (gas: 2263925)
AllowlistERC721TransferApprovals:testTransferToAddrInOAL() (gas: 166790)
AllowlistERC721TransferApprovals:testTransferToAddrInOAL() (gas: 167523)
AllowlistERC721TransferApprovals:testTransferToWalletInOAL() (gas: 1273627)
AllowlistERC721TransferApprovals:testTransferToWalletInOAL() (gas: 1274360)
ChainlinkControlTests:testConfigureRequests() (gas: 29757)
ChainlinkControlTests:testConfigureRequestsBadAuth() (gas: 40354)
ChainlinkControlTests:testInit() (gas: 1504756)
ChainlinkControlTests:testRoleAdmin() (gas: 92292)
ChainlinkControlTests:testRoleAdminBadAuth() (gas: 44062)
ChainlinkCoverageFakeTests:testFixMockCoordinatorCoverage() (gas: 467341)
ChainlinkCoverageFakeTests:testInit() (gas: 1504919)
ChainlinkCoverageFakeTests:testV2BaseChecksCoverage() (gas: 462646)
ChainlinkInitTests:testInit() (gas: 1504788)
ChainlinkIntegrationTests:testBadFulfilment() (gas: 29985)
ChainlinkIntegrationTests:testEndToEnd() (gas: 586008)
ChainlinkIntegrationTests:testHackFulfilment() (gas: 455339)
ChainlinkIntegrationTests:testInit() (gas: 1504757)
ChainlinkIntegrationTests:testRequestRandom() (gas: 57273)
ChainlinkIntegrationTests:testRequestTooEarly() (gas: 25782)
ChainlinkIntegrationTests:testTwoRequests() (gas: 85823)
ChainlinkOperationalTests:testBadFulfilment() (gas: 29985)
ChainlinkOperationalTests:testHackFulfilment() (gas: 455306)
ChainlinkOperationalTests:testInit() (gas: 1504757)
ChainlinkOperationalTests:testRequestRandom() (gas: 57192)
ChainlinkOperationalTests:testRequestTooEarly() (gas: 25782)
ChainlinkOperationalTests:testTwoRequests() (gas: 85823)
ControlRandomSeedProviderTest:testAddOffchainRandomConsumer() (gas: 45704)
ControlRandomSeedProviderTest:testAddOffchainRandomConsumerBadAuth() (gas: 53368)
ControlRandomSeedProviderTest:testGetRandomSeedInitRandao() (gas: 48442)
ControlRandomSeedProviderTest:testGetRandomSeedInitTraditional() (gas: 48473)
ControlRandomSeedProviderTest:testGetRandomSeedNoOffchainSource() (gas: 16333)
ControlRandomSeedProviderTest:testGetRandomSeedNotGenRandao() (gas: 51080)
ControlRandomSeedProviderTest:testGetRandomSeedNotGenTraditional() (gas: 51134)
ControlRandomSeedProviderTest:testInit() (gas: 2108843)
ControlRandomSeedProviderTest:testNoDowngrade() (gas: 3244256)
ControlRandomSeedProviderTest:testNoUpgrade() (gas: 18457)
ControlRandomSeedProviderTest:testReinit() (gas: 22783)
ControlRandomSeedProviderTest:testRemoveOffchainRandomConsumer() (gas: 35268)
ControlRandomSeedProviderTest:testRemoveOffchainRandomConsumerBadAuth() (gas: 76371)
ControlRandomSeedProviderTest:testRoleAdmin() (gas: 97806)
ControlRandomSeedProviderTest:testRoleAdminBadAuth() (gas: 49175)
ControlRandomSeedProviderTest:testSetOffchainRandomSource() (gas: 26989)
ControlRandomSeedProviderTest:testSetOffchainRandomSourceBadAuth() (gas: 45324)
ControlRandomSeedProviderTest:testSetRanDaoAvailable() (gas: 27553)
ControlRandomSeedProviderTest:testSetRanDaoAvailableBadAuth() (gas: 49941)
ControlRandomSeedProviderTest:testUpgrade() (gas: 1649333)
ControlRandomSeedProviderTest:testUpgradeBadAuth() (gas: 1641725)
ControlRandomSeedProviderTest:testV2NoDowngrade() (gas: 1623397)
ImmutableERC1155Costs:test_Mint100To1() (gas: 62009)
ImmutableERC1155Costs:test_Mint10To5() (gas: 61922)
ImmutableERC1155Costs:test_Mint1To5() (gas: 61944)
ImmutableERC1155Costs:test_Mint5To5() (gas: 61899)
ImmutableERC1155Test:test_AdminRoleCanSetBaseURI() (gas: 27117)
ImmutableERC1155Test:test_AdminRoleCanSetContractURI() (gas: 21743)
ImmutableERC1155Test:test_ApprovedOperatorBatchTransferFrom() (gas: 215975)
ImmutableERC1155Test:test_ApprovedOperatorTransferFrom() (gas: 154849)
ImmutableERC1155Test:test_ApprovedSCWOperatorBatchTransferFromToApprovedReceiver() (gas: 263256)
ImmutableERC1155Test:test_ApprovedSCWOperatorTransferFrom() (gas: 194435)
ImmutableERC1155Test:test_ApprovedSCWOperatorTransferFromToApprovedReceiver() (gas: 197709)
ImmutableERC1155Test:test_ApprovedSCWOperatorTransferFromToUnApprovedReceiver() (gas: 195278)
ImmutableERC1155Test:test_BatchBurn() (gas: 133999)
ImmutableERC1155Test:test_Burn() (gas: 54997)
ImmutableERC1155Test:test_DeploymentAllowlistShouldGiveAdminToOwner() (gas: 16303)
ImmutableERC1155Test:test_DeploymentShouldSetAdminRoleToOwner() (gas: 10872)
ImmutableERC1155Test:test_DeploymentShouldSetAllowlistToProxy() (gas: 9855)
ImmutableERC1155Test:test_DeploymentShouldSetBaseURI() (gas: 9693)
ImmutableERC1155Test:test_DeploymentShouldSetContractURI() (gas: 9663)
ImmutableERC1155Test:test_MinterRoleCanBatchMint() (gas: 161400)
ImmutableERC1155Test:test_MinterRoleCanMint() (gas: 63382)
ImmutableERC1155Test:test_PermitRevertsWhenDeadlineExceeded() (gas: 25751)
ImmutableERC1155Test:test_PermitRevertsWhenInvalidNonce() (gas: 56265)
ImmutableERC1155Test:test_PermitRevertsWhenInvalidSigner() (gas: 56222)
ImmutableERC1155Test:test_PermitSuccess() (gas: 82929)
ImmutableERC1155Test:test_RevertIfNonAdminAttemptsToSetBaseURI() (gas: 43856)
ImmutableERC1155Test:test_RevertIfNonAdminAttemptsToSetContractURI() (gas: 43843)
ImmutableERC1155Test:test_UnapprovedSCWOperatorTransferFrom() (gas: 89255)
ImmutableERC1155Test:test_giveMinterRole() (gas: 24714)
ImmutableERC20FixedSupplyNoBurnTest:testChangeOwner() (gas: 19980)
ImmutableERC20FixedSupplyNoBurnTest:testInit() (gas: 38921)
ImmutableERC20FixedSupplyNoBurnTest:testRenounceOwnerBlocked() (gas: 11134)
ImmutableERC20Test:testBurn() (gas: 49360)
ImmutableERC20Test:testCanOnlyMintUpToMaxSupply() (gas: 67222)
ImmutableERC20Test:testChangeOwner() (gas: 20209)
ImmutableERC20Test:testInit() (gas: 38556)
ImmutableERC20Test:testMint() (gas: 62348)
ImmutableERC20Test:testOnlyMinterCanMint() (gas: 44635)
ImmutableERC20Test:testRenounceOwnerBlocked() (gas: 11332)
OperationalRandomSeedProviderTest:testGetRandomSeedInitRandao() (gas: 48462)
OperationalRandomSeedProviderTest:testGetRandomSeedInitTraditional() (gas: 48526)
OperationalRandomSeedProviderTest:testGetRandomSeedNoOffchainSource() (gas: 16323)
OperationalRandomSeedProviderTest:testGetRandomSeedNotGenRandao() (gas: 51147)
OperationalRandomSeedProviderTest:testGetRandomSeedNotGenTraditional() (gas: 51212)
OperationalRandomSeedProviderTest:testInit() (gas: 2108881)
OperationalRandomSeedProviderTest:testOffchainNextBlock() (gas: 138600)
OperationalRandomSeedProviderTest:testOffchainNotReady() (gas: 112897)
OperationalRandomSeedProviderTest:testOffchainTwoInOneBlock() (gas: 110631)
OperationalRandomSeedProviderTest:testRanDaoDelayedFulfilment() (gas: 134110)
OperationalRandomSeedProviderTest:testRanDaoNextBlock() (gas: 81550)
OperationalRandomSeedProviderTest:testRanDaoTwoInOneBlock() (gas: 51746)
OperationalRandomSeedProviderTest:testReinit() (gas: 22728)
OperationalRandomSeedProviderTest:testTradDelayedFulfilment() (gas: 134448)
OperationalRandomSeedProviderTest:testTradNextBlock() (gas: 80391)
OperationalRandomSeedProviderTest:testTradTwoInOneBlock() (gas: 51786)
OperatorAllowlistTest:testDeployment() (gas: 39610)
OperatorAllowlistTest:testFailedUpgradeNoPerms() (gas: 1554749)
OperatorAllowlistTest:testShouldAddAndRemoveAnAddressOfAMarketPlaceAndRemoveItFromAllowlist() (gas: 41761)
OperatorAllowlistTest:testShouldAddAndRemoveSmartContractWalletBytecodeFromAllowlist() (gas: 1155323)
OperatorAllowlistTest:testShouldLimitAllowlistAddAndRemoveFunctionality() (gas: 163547)
OperatorAllowlistTest:testShouldNotAllowlistSCWWithSameBytecodeButDifferentImplementationAddress() (gas: 2112028)
OperatorAllowlistTest:testShouldSupportIOperatorAllowlistInterface() (gas: 10631)
OperatorAllowlistTest:testUpgradeToV2() (gas: 1582052)
PaymentSplitterTest:testAddErc20() (gas: 1188176)
PaymentSplitterTest:testCalculateReleasableAmount() (gas: 203086)
PaymentSplitterTest:testDeployRoles() (gas: 22859)
PaymentSplitterTest:testGrantReleaseFundsRole() (gas: 93633)
PaymentSplitterTest:testInvalidPermissions() (gas: 174248)
PaymentSplitterTest:testPayeeAdded() (gas: 20067)
PaymentSplitterTest:testReceiveNativeTokenEvent() (gas: 18262)
PaymentSplitterTest:testReleaseERC20sOverridePayees() (gas: 439241)
PaymentSplitterTest:testReleaseERC20sSimple() (gas: 291122)
PaymentSplitterTest:testReleaseNativeFundsOverridePayees() (gas: 275290)
PaymentSplitterTest:testReleaseNativeTokenFundsSimple() (gas: 147191)
PaymentSplitterTest:testSharesAdded() (gas: 24243)
PaymentSplitterTest:testTokensAdded() (gas: 22613)
RegistrationV4Test:testCompleteWithdrawalAll_WhenUserIsRegistered() (gas: 111955)
RegistrationV4Test:testCompleteWithdrawalAll_WhenUserIsRegisteredAndHasEthKeyBalanceOnly() (gas: 93416)
RegistrationV4Test:testCompleteWithdrawalAll_WhenUserIsRegisteredAndHasStarkKeyBalanceOnly() (gas: 91345)
RegistrationV4Test:testCompleteWithdrawalV4_WhenUserIsNotRegistered() (gas: 87145)
RegistrationV4Test:testGetVersion() (gas: 10650)
RegistrationV4Test:testRegisterAndCompleteWithdrawalAll_WhenUserIsNotRegistered() (gas: 114413)
RegistrationV4Test:testRegisterAndCompleteWithdrawalAll_WhenUserIsRegistered() (gas: 115075)
RegistrationV4Test:testRegisterAndWithdrawalNFT_WhenUserIsNotRegistered() (gas: 1733099)
RegistrationV4Test:testRegisterAndWithdrawalNFT_WhenUserIsRegistered() (gas: 1733990)
RegistrationV4Test:testRegisterWithdrawalAndMintNFT_WhenUserIsNotRegistered() (gas: 1723044)
RegistrationV4Test:testRegister_WhenUserIsNotRegistered() (gas: 44713)
RegistrationV4Test:testShouldFailWithdrawalAll_WhenUserDoesNotHaveFundsToWithdraw() (gas: 52900)
RegistrationV4Test:testShouldFailWithdrawalAll_WhenUserIsNotRegistered() (gas: 93525)
SingleGameRandomValuesTest:testFirstValue() (gas: 121607)
SingleGameRandomValuesTest:testFirstValues() (gas: 116110)
SingleGameRandomValuesTest:testInit() (gas: 13182)
SingleGameRandomValuesTest:testMultiFetch() (gas: 118704)
SingleGameRandomValuesTest:testMultipleGames() (gas: 567246)
SingleGameRandomValuesTest:testNoValues() (gas: 8848)
SingleGameRandomValuesTest:testSecondValue() (gas: 188944)
SingleGameRandomValuesTest:testSecondValues() (gas: 159172)
SupraControlTests:testInit() (gas: 1383940)
SupraControlTests:testRoleAdmin() (gas: 92386)
SupraControlTests:testRoleAdminBadAuth() (gas: 44170)
SupraControlTests:testSetSubscription() (gas: 21583)
SupraControlTests:testSetSubscriptionBadAuth() (gas: 40305)
SupraCoverageFakeTests:testFixMockCoordinatorCoverage() (gas: 411486)
SupraCoverageFakeTests:testInit() (gas: 1383863)
SupraInitTests:testInit() (gas: 1383951)
SupraIntegrationTests:testBadFulfilment() (gas: 27869)
SupraIntegrationTests:testEndToEnd() (gas: 583888)
SupraIntegrationTests:testHackFulfilment() (gas: 423998)
SupraIntegrationTests:testInit() (gas: 1383955)
SupraIntegrationTests:testRequestRandom() (gas: 55131)
SupraIntegrationTests:testRequestTooEarly() (gas: 23855)
SupraIntegrationTests:testTwoRequests() (gas: 83473)
SupraOperationalTests:testBadFulfilment() (gas: 27869)
SupraOperationalTests:testHackFulfilment() (gas: 423931)
SupraOperationalTests:testInit() (gas: 1383955)
SupraOperationalTests:testRequestRandom() (gas: 55072)
SupraOperationalTests:testRequestTooEarly() (gas: 23877)
SupraOperationalTests:testTwoRequests() (gas: 83495)
SwitchingRandomSeedProviderTest:testGetRandomSeedInitRandao() (gas: 48462)
SwitchingRandomSeedProviderTest:testGetRandomSeedInitTraditional() (gas: 48526)
SwitchingRandomSeedProviderTest:testGetRandomSeedNoOffchainSource() (gas: 16323)
SwitchingRandomSeedProviderTest:testGetRandomSeedNotGenRandao() (gas: 51147)
SwitchingRandomSeedProviderTest:testGetRandomSeedNotGenTraditional() (gas: 51168)
SwitchingRandomSeedProviderTest:testInit() (gas: 2108881)
SwitchingRandomSeedProviderTest:testReinit() (gas: 22728)
SwitchingRandomSeedProviderTest:testSwitchOffchainOffchain() (gas: 174831)
SwitchingRandomSeedProviderTest:testSwitchOffchainOnchain() (gas: 197469)
SwitchingRandomSeedProviderTest:testSwitchRanDaoOffchain() (gas: 198644)
SwitchingRandomSeedProviderTest:testSwitchTraditionalOffchain() (gas: 198836)
UninitializedRandomSeedProviderTest:testGetRandomSeedInitRandao() (gas: 48398)
UninitializedRandomSeedProviderTest:testGetRandomSeedInitTraditional() (gas: 48451)
UninitializedRandomSeedProviderTest:testGetRandomSeedNoOffchainSource() (gas: 16256)
UninitializedRandomSeedProviderTest:testGetRandomSeedNotGenRandao() (gas: 51025)
UninitializedRandomSeedProviderTest:testGetRandomSeedNotGenTraditional() (gas: 51079)
UninitializedRandomSeedProviderTest:testInit() (gas: 2108733)
UninitializedRandomSeedProviderTest:testReinit() (gas: 22706)
UninitializedRandomValuesTest:testInit() (gas: 13136)
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/clients @immutable/assets
/abi @immutable/assets

/contracts/allowlist @immutable/assets
/contracts/token @immutable/assets
Expand Down
67 changes: 49 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ Immutable Contracts is a library of smart contracts targeted at developers who w

- Token presets, e.g. ERC721

- [ImmutableERC721](./contracts/token/erc721/preset/ImmutableERC721.sol)
- [ImmutableERC721MintByID](./contracts/token/erc721/preset/ImmutableERC721MintByID.sol)
- [ImmutableERC1155](./contracts/token/erc1155/preset/ImmutableERC1155.sol)
- [ImmutableERC20MinterBurnerPermit](./contracts/token/erc20/preset/ImmutableERC20MinterBurnerPermit.sol)
- [ImmutableERC20FixedSupplyNoBurn](./contracts/token/erc20/preset/ImmutableERC20FixedSupplyNoBurn.sol)
- [ImmutableERC721](./contracts/token/erc721/preset/ImmutableERC721.sol)
- [ImmutableERC721MintByID](./contracts/token/erc721/preset/ImmutableERC721MintByID.sol)
- [ImmutableERC1155](./contracts/token/erc1155/preset/ImmutableERC1155.sol)
- [ImmutableERC20MinterBurnerPermit](./contracts/token/erc20/preset/ImmutableERC20MinterBurnerPermit.sol)
- [ImmutableERC20FixedSupplyNoBurn](./contracts/token/erc20/preset/ImmutableERC20FixedSupplyNoBurn.sol)

- Bridging contracts

Expand Down Expand Up @@ -65,24 +65,55 @@ contract MyERC721 is ImmutableERC721 {
}
```

#### SDK client
#### Typescript ABIs

`contracts` comes with a Typescript SDK client that can be used to interface with Immutable preset contracts:
`contracts` comes with importable Typescript ABIs that can be used to generate a contract client in conjunction with libraries such as `viem` or `wagmi`, so that you can
interact with deployed preset contracts.

- ImmutableERC721
- ImmutableERC721MintByID
The following Typescript ABIs are available:

To import and use the ImmutableERC721 contract client:
- `ImmutableERC721Abi`
- `ImmutableERC721MintByIdAbi`
- `ImmutableERC1155Abi`

```typescript
import { ERC721Client } from "@imtbl/contracts";

const contractAddress = YOUR_CONTRACT_ADDRESS;
An example of how to create and use a contract client in order to interact with a deployed `ImmutableERC721`:

const client = new ERC721Client(contractAddress);

const mintTransaction = await client.populateMint(receiver, 1);
const tx = await signer.sendTransaction(mintTransaction);
```typescript
import { getContract, http, createWalletClient, defineChain } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { ImmutableERC721MintByIdAbi } from "@imtbl/contracts";

const PRIVATE_KEY = "YOUR_PRIVATE_KEY"; // should be read from environment variable
const CONTRACT_ADDRESS = "YOUR_CONTRACT_ADDRESS"; // should be of type `0x${string}`
const RECIPIENT = "ACCOUNT_ADDRESS"; // should be of type `0x${string}`
const TOKEN_ID = BigInt(1);

const immutableTestnet = defineChain({
id: 13473,
name: "imtbl-zkevm-testnet",
nativeCurrency: { name: "IMX", symbol: "IMX", decimals: 18 },
rpcUrls: {
default: {
http: ["https://rpc.testnet.immutable.com"],
},
},
});

const walletClient = createWalletClient({
chain: immutableTestnet,
transport: http(),
account: privateKeyToAccount(`0x${PRIVATE_KEY}`),
});

// Bound contract instance
const contract = getContract({
address: CONTRACT_ADDRESS,
abi: ImmutableERC721MintByIdAbi,
client: walletClient,
});

const txHash = await contract.write.mint([recipient, tokenId]);
console.log(`txHash: ${txHash}`);
```

## Build and Test
Expand Down
20 changes: 20 additions & 0 deletions abi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Typescript ABIs

The `contracts` repo exports Typescript ABIs for customers to generate their own contract clients using modern libraries such as `abitype`, `viem` and `wagmi`, for interacting with deployed preset contracts.

## Adding a new Typescript ABI

Typescript ABIs are generated using `@wagmi/cli` and `foundry` build files:

- `@wagmi/cli` configuration can be found in file `wagmi.config.ts`
- `foundry` build files are available in this repo once built at folder `foundry-out`

To add a new Typescript ABI:

- Ensure the JSON ABI is available in folder `foundry-out`
- Update the configuration in `wagmi.config.ts` to add the ABI to the `contracts` array
- Run command `yarn wagmi generate` from the root of the folder
- Ensure the new Typescript ABI is available in `abi/generated.ts`
- Update `abi/index.ts` to rename and export Typescript ABI

The next published version will contain the new Typescript ABI.
Loading

0 comments on commit 44835a6

Please sign in to comment.