Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs/move MintToken.sol from wiki #3471

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions packages/evm/evmtest/wiki_how_tos/MintToken.abi
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[
{
"inputs": [
{
"internalType": "string",
"name": "_tokenName",
"type": "string"
},
{
"internalType": "string",
"name": "_tokenSymbol",
"type": "string"
},
{
"internalType": "uint8",
"name": "_tokenDecimals",
"type": "uint8"
},
{
"internalType": "uint256",
"name": "_maximumSupply",
"type": "uint256"
},
{
"internalType": "uint64",
"name": "_storageDeposit",
"type": "uint64"
}
],
"stateMutability": "payable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint32",
"name": "foundrySN",
"type": "uint32"
}
],
"name": "MintedToken",
"type": "event"
}
]
1 change: 1 addition & 0 deletions packages/evm/evmtest/wiki_how_tos/MintToken.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
60806040526040516109f33803806109f3833981810160405281019061002591906103bf565b64e8d4a5100081610036919061049b565b67ffffffffffffffff163414610081576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161007890610557565b60405180910390fd5b6100896101a2565b81815f019067ffffffffffffffff16908167ffffffffffffffff16815250505f60405180606001604052805f81526020015f81526020018581525090505f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16634af8bc5289898986886040518663ffffffff1660e01b815260040161011c9594939291906108b7565b6020604051808303815f875af1158015610138573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061015c9190610956565b90507fa9b6ab28bbd5c8278288d0c15a1384d0e91e4d0cbaca2f686ecdd85ecc796a928160405161018d9190610990565b60405180910390a150505050505050506109a9565b60405180606001604052805f67ffffffffffffffff16815260200160608152602001606081525090565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b61022b826101e5565b810181811067ffffffffffffffff8211171561024a576102496101f5565b5b80604052505050565b5f61025c6101cc565b90506102688282610222565b919050565b5f67ffffffffffffffff821115610287576102866101f5565b5b610290826101e5565b9050602081019050919050565b8281835e5f83830152505050565b5f6102bd6102b88461026d565b610253565b9050828152602081018484840111156102d9576102d86101e1565b5b6102e484828561029d565b509392505050565b5f82601f830112610300576102ff6101dd565b5b81516103108482602086016102ab565b91505092915050565b5f60ff82169050919050565b61032e81610319565b8114610338575f80fd5b50565b5f8151905061034981610325565b92915050565b5f819050919050565b6103618161034f565b811461036b575f80fd5b50565b5f8151905061037c81610358565b92915050565b5f67ffffffffffffffff82169050919050565b61039e81610382565b81146103a8575f80fd5b50565b5f815190506103b981610395565b92915050565b5f805f805f60a086880312156103d8576103d76101d5565b5b5f86015167ffffffffffffffff8111156103f5576103f46101d9565b5b610401888289016102ec565b955050602086015167ffffffffffffffff811115610422576104216101d9565b5b61042e888289016102ec565b945050604061043f8882890161033b565b93505060606104508882890161036e565b9250506080610461888289016103ab565b9150509295509295909350565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f6104a582610382565b91506104b083610382565b92508282026104be81610382565b91508082146104d0576104cf61046e565b5b5092915050565b5f82825260208201905092915050565b7f506c656173652073656e642065786163742066756e647320746f2070617920665f8201527f6f722073746f72616765206465706f7369740000000000000000000000000000602082015250565b5f6105416032836104d7565b915061054c826104e7565b604082019050919050565b5f6020820190508181035f83015261056e81610535565b9050919050565b5f81519050919050565b5f61058982610575565b61059381856104d7565b93506105a381856020860161029d565b6105ac816101e5565b840191505092915050565b6105c081610319565b82525050565b6105cf8161034f565b82525050565b606082015f8201516105e95f8501826105c6565b5060208201516105fc60208501826105c6565b50604082015161060f60408501826105c6565b50505050565b61061e81610382565b82525050565b5f81519050919050565b5f82825260208201905092915050565b5f819050602082019050919050565b5f81519050919050565b5f82825260208201905092915050565b5f6106718261064d565b61067b8185610657565b935061068b81856020860161029d565b610694816101e5565b840191505092915050565b5f602083015f8301518482035f8601526106b98282610667565b9150508091505092915050565b5f604083015f8301518482035f8601526106e0828261069f565b91505060208301516106f560208601826105c6565b508091505092915050565b5f61070b83836106c6565b905092915050565b5f602082019050919050565b5f61072982610624565b610733818561062e565b9350836020820285016107458561063e565b805f5b8581101561078057848403895281516107618582610700565b945061076c83610713565b925060208a01995050600181019050610748565b50829750879550505050505092915050565b5f81519050919050565b5f82825260208201905092915050565b5f819050602082019050919050565b5f819050919050565b5f6107ce826107bb565b9050919050565b6107de816107c4565b82525050565b5f6107ef83836107d5565b60208301905092915050565b5f602082019050919050565b5f61081182610792565b61081b818561079c565b9350610826836107ac565b805f5b8381101561085657815161083d88826107e4565b9750610848836107fb565b925050600181019050610829565b5085935050505092915050565b5f606083015f8301516108785f860182610615565b5060208301518482036020860152610890828261071f565b915050604083015184820360408601526108aa8282610807565b9150508091505092915050565b5f60e0820190508181035f8301526108cf818861057f565b905081810360208301526108e3818761057f565b90506108f260408301866105b7565b6108ff60608301856105d5565b81810360c08301526109118184610863565b90509695505050505050565b5f63ffffffff82169050919050565b6109358161091d565b811461093f575f80fd5b50565b5f815190506109508161092c565b92915050565b5f6020828403121561096b5761096a6101d5565b5b5f61097884828501610942565b91505092915050565b61098a8161091d565b82525050565b5f6020820190506109a35f830184610981565b92915050565b603e806109b55f395ff3fe60806040525f80fdfea2646970667358221220a94445fe81b7c118ef4aeb551b4c59147d7af5b25f7cf45d38e31f19c2065cb564736f6c634300081a0033
39 changes: 39 additions & 0 deletions packages/evm/evmtest/wiki_how_tos/MintToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "@iscmagic/ISC.sol";

contract MyToken {
event MintedToken(uint32 foundrySN);

constructor(
string memory _tokenName,
string memory _tokenSymbol,
uint8 _tokenDecimals,
uint256 _maximumSupply,
uint64 _storageDeposit
) payable {
require(
msg.value == _storageDeposit * (10 ** 12),
"Please send exact funds to pay for storage deposit"
);
ISCAssets memory allowance;
allowance.baseTokens = _storageDeposit;

NativeTokenScheme memory nativeTokenScheme = NativeTokenScheme({
mintedTokens: 0,
meltedTokens: 0,
maximumSupply: _maximumSupply
});

uint32 foundrySN = ISC.accounts.createNativeTokenFoundry(
_tokenName,
_tokenSymbol,
_tokenDecimals,
nativeTokenScheme,
allowance
);
emit MintedToken(foundrySN);
}
}
41 changes: 40 additions & 1 deletion packages/evm/evmtest/wiki_how_tos/how_tos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@ import (
"github.com/iotaledger/wasp/packages/vm/core/evm/evmtest"
)

//go:generate sh -c "solc --abi --bin --overwrite @iscmagic=`realpath ../../../vm/core/evm/iscmagic` GetBalance.sol -o ."
//go:generate sh -c "solc --abi --bin --overwrite @iscmagic=`realpath ../../../vm/core/evm/iscmagic` GetBalance.sol TakeAllowance.sol Allowance.sol -o ."
var (
//go:embed GetBalance.abi
GetBalanceContractABI string
//go:embed GetBalance.bin
GetBalanceContractBytecodeHex string
GetBalanceContractBytecode = common.FromHex(strings.TrimSpace(GetBalanceContractBytecodeHex))

//go:embed MintToken.abi
MintTokenContractABI string
//go:embed MintToken.bin
MintTokenContractBytecodeHex string
MintTokenContractBytecode = common.FromHex(strings.TrimSpace(MintTokenContractBytecodeHex))
)

func TestBaseBalance(t *testing.T) {
Expand Down Expand Up @@ -112,3 +118,36 @@ func TestAgentID(t *testing.T) {
instance.CallFnExpectEvent(nil, "GotAgentID", &agentID, "getAgentID")
assert.Equal(t, senderAgentID.Bytes(), agentID)
}

func TestMintNativeToken(t *testing.T) {
env := evmtest.InitEVMWithSolo(t, solo.New(t), true)
privateKey, _ := env.Chain.NewEthereumAccountWithL2Funds()

// Deploy the contract
var tokenDecimals uint8 = 6
maximumSupply := new(big.Int)
maximumSupply.SetString("100000", 10)
var storageDeposit uint64 = 3
multiplier := new(big.Int)
multiplier.Exp(big.NewInt(10), big.NewInt(12), nil) // 10^12

amount := new(big.Int).Mul(big.NewInt(int64(storageDeposit)), multiplier)
amountStr := amount.String()

value := new(big.Int)
value.SetString(amountStr, 10)

instance2, err := env.Chain.DeployEVMContract(
privateKey,
MintTokenContractABI,
MintTokenContractBytecode,
value,
"Test Token",
"TT",
tokenDecimals,
maximumSupply,
storageDeposit,
)

t.Log(instance2, err)
}
Loading