forked from sphinx-labs/sphinx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Support for Mapping Types (sphinx-labs#149)
* parent 4262614 author Ryan Pate <ryantpate97@gmail.com> 1667458967 -0700 committer Ryan Pate <ryantpate97@gmail.com> 1667689541 -0700 Add support for mapping types * add support for 0x prefixed bytes Co-authored-by: sam-goldman <106038229+sam-goldman@users.noreply.github.com>
- Loading branch information
1 parent
b760077
commit 5e74723
Showing
9 changed files
with
438 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@chugsplash/core': patch | ||
'@chugsplash/plugins': patch | ||
--- | ||
|
||
Add support for mappings |
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 |
---|---|---|
@@ -1,2 +1,6 @@ | ||
dist/ | ||
.env | ||
.deployed | ||
artifacts | ||
cache | ||
deployments |
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,84 @@ | ||
import { ChugSplashConfig } from '@chugsplash/core' | ||
|
||
const config: ChugSplashConfig = { | ||
// Configuration options for the project: | ||
options: { | ||
projectName: 'My First Project', | ||
projectOwner: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', | ||
}, | ||
// Below, we define all of the contracts in the deployment along with their state variables. | ||
contracts: { | ||
// First contract config: | ||
FirstSimpleStorage: { | ||
contract: 'SimpleStorage', | ||
variables: { | ||
testInt: 1, | ||
number: 1, | ||
stored: true, | ||
storageName: 'First', | ||
testStruct: { | ||
a: 1, | ||
b: 2, | ||
c: 3, | ||
}, | ||
strTest: { | ||
string: 'test', | ||
}, | ||
uintTest: { | ||
uint: 1234, | ||
}, | ||
boolTest: { | ||
bool: true, | ||
}, | ||
addressTest: { | ||
address: '0x1111111111111111111111111111111111111111', | ||
}, | ||
structTest: { | ||
test: { | ||
a: 1, | ||
b: 2, | ||
c: 3, | ||
}, | ||
}, | ||
uintStrTest: { | ||
1: 'test', | ||
}, | ||
intStrTest: { | ||
1: 'test', | ||
}, | ||
int8StrTest: { | ||
1: 'test', | ||
}, | ||
int128StrTest: { | ||
1: 'test', | ||
}, | ||
uint8StrTest: { | ||
1: 'test', | ||
}, | ||
uint128StrTest: { | ||
1: 'test', | ||
}, | ||
addressStrTest: { | ||
'0x1111111111111111111111111111111111111111': 'test', | ||
}, | ||
bytesStrTest: { | ||
'0xabcd': 'test', | ||
}, | ||
nestedMappingTest: { | ||
test: { | ||
test: 'success', | ||
}, | ||
}, | ||
multiNestedMapping: { | ||
1: { | ||
test: { | ||
'0x1111111111111111111111111111111111111111': 2, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
export default config |
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,103 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.9; | ||
|
||
contract SimpleStorage { | ||
struct S { uint16 a; uint16 b; uint256 c; } | ||
int internal testInt; | ||
uint8 internal number; | ||
bool internal stored; | ||
string internal storageName; | ||
S testStruct; | ||
mapping(string => string) public strTest; | ||
mapping(string => uint) public uintTest; | ||
mapping(string => bool) public boolTest; | ||
mapping(string => address) public addressTest; | ||
|
||
mapping(uint => string) public uintStrTest; | ||
mapping(int => string) public intStrTest; | ||
mapping(int8 => string) public int8StrTest; | ||
mapping(int128 => string) public int128StrTest; | ||
mapping(uint8 => string) public uint8StrTest; | ||
mapping(uint128 => string) public uint128StrTest; | ||
mapping(address => string) public addressStrTest; | ||
mapping(bytes => string) public bytesStrTest; | ||
mapping(string => S) structTest; | ||
mapping(string => mapping(string => string)) public nestedMappingTest; | ||
mapping(uint8 => mapping(string => mapping(address => uint))) public multiNestedMapping; | ||
|
||
function getNumber() external view returns (uint8) { | ||
return number; | ||
} | ||
|
||
function isStored() external view returns (bool) { | ||
return stored; | ||
} | ||
|
||
function getStorageName() external view returns (string memory) { | ||
return storageName; | ||
} | ||
|
||
function getStruct() external view returns (S memory) { | ||
return testStruct; | ||
} | ||
|
||
function getStringTestMappingValue(string memory key) external view returns (string memory) { | ||
return strTest[key]; | ||
} | ||
|
||
function getIntTestMappingValue(string memory key) external view returns (uint) { | ||
return uintTest[key]; | ||
} | ||
|
||
function getBoolTestMappingValue(string memory key) external view returns (bool) { | ||
return boolTest[key]; | ||
} | ||
|
||
function getAddressTestMappingValue(string memory key) external view returns (address) { | ||
return addressTest[key]; | ||
} | ||
|
||
function getStructTestMappingValue(string memory key) external view returns (S memory) { | ||
return structTest[key]; | ||
} | ||
|
||
function getUintStringTestMappingValue(uint key) external view returns (string memory) { | ||
return uintStrTest[key]; | ||
} | ||
|
||
function getIntStringTestMappingValue(int key) external view returns (string memory) { | ||
return intStrTest[key]; | ||
} | ||
|
||
function getInt8StringTestMappingValue(int8 key) external view returns (string memory) { | ||
return int8StrTest[key]; | ||
} | ||
|
||
function getInt128StringTestMappingValue(int128 key) external view returns (string memory) { | ||
return int128StrTest[key]; | ||
} | ||
|
||
function getUint8StringTestMappingValue(uint8 key) external view returns (string memory) { | ||
return uint8StrTest[key]; | ||
} | ||
|
||
function getUint128StringTestMappingValue(uint128 key) external view returns (string memory) { | ||
return uint128StrTest[key]; | ||
} | ||
|
||
function getAddressStringTestMappingValue(address key) external view returns (string memory) { | ||
return addressStrTest[key]; | ||
} | ||
|
||
function getBytesStringTestMappingValue(bytes memory key) external view returns (string memory) { | ||
return bytesStrTest[key]; | ||
} | ||
|
||
function getNestedTestMappingValue(string memory keyOne, string memory keyTwo) external view returns (string memory) { | ||
return nestedMappingTest[keyOne][keyTwo]; | ||
} | ||
|
||
function getMultiNestedMappingTestMappingValue(uint8 keyOne, string memory keyTwo, address keyThree) external view returns (uint) { | ||
return multiNestedMapping[keyOne][keyTwo][keyThree]; | ||
} | ||
} |
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,56 @@ | ||
import { HardhatUserConfig } from 'hardhat/types' | ||
import * as dotenv from 'dotenv' | ||
|
||
// Hardhat plugins | ||
import '@nomiclabs/hardhat-ethers' | ||
import './dist' | ||
|
||
// Load environment variables from .env | ||
dotenv.config() | ||
|
||
const accounts = process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : [] | ||
|
||
const config: HardhatUserConfig = { | ||
solidity: { | ||
version: '0.8.15', | ||
settings: { | ||
outputSelection: { | ||
'*': { | ||
'*': ['storageLayout'], | ||
}, | ||
}, | ||
}, | ||
}, | ||
networks: { | ||
localhost: { | ||
url: 'http://localhost:8545', | ||
}, | ||
goerli: { | ||
chainId: 5, | ||
url: `https://goerli.infura.io/v3/${process.env.INFURA_API_KEY}`, | ||
accounts, | ||
}, | ||
'optimism-goerli': { | ||
chainId: 420, | ||
url: `https://optimism-goerli.infura.io/v3/${process.env.INFURA_API_KEY}`, | ||
accounts, | ||
}, | ||
optimism: { | ||
chainId: 10, | ||
url: `https://optimism-mainnet.infura.io/v3/${process.env.INFURA_API_KEY}`, | ||
accounts, | ||
}, | ||
arbitrum: { | ||
chainId: 42161, | ||
url: 'https://arb1.arbitrum.io/rpc', | ||
accounts, | ||
}, | ||
'arbitrum-goerli': { | ||
chainId: 421613, | ||
url: 'https://goerli-rollup.arbitrum.io/rpc', | ||
accounts, | ||
}, | ||
}, | ||
} | ||
|
||
export default config |
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
Oops, something went wrong.