Skip to content

Commit

Permalink
feat: add custodialregistrationproxy
Browse files Browse the repository at this point in the history
  • Loading branch information
kamikazechaser committed Sep 25, 2024
1 parent b47af43 commit 67819d3
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Supported Smart Contracts:
- [x] GiftableERC20
- [x] AccountsIndex
- [x] ContractsRegistry
- [x] CustodialRegistrationProxy

_Note:_ All smart contracts are compiled with `v0.8.25, Istanbul hard fork` unless otherwise stated.

Expand Down
57 changes: 57 additions & 0 deletions internal/container/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func (c *Container) RegisterPublishCommands() []*cli.Command {
c.accountsIndex(),
c.erc20(),
c.contractsRegistry(),
c.custodialRegistrationProxy(),
}
}

Expand Down Expand Up @@ -479,6 +480,62 @@ func (c *Container) contractsRegistry() *cli.Command {
}
}

func (c *Container) custodialRegistrationProxy() *cli.Command {
return &cli.Command{
Name: "custodial-registration-proxy",
Aliases: []string{"custodial"},
Usage: "Publish the custodial registration proxy smart contract",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "eth-faucet-address",
Aliases: []string{"gas-faucet", "faucet"},
Usage: "The gas faucet address",
Required: true,
},
&cli.StringFlag{
Name: "accounts-index-address",
Aliases: []string{"user-index"},
Usage: "The accounts index address",
Required: true,
},
&cli.StringFlag{
Name: "training-token",
Aliases: []string{"training-voucher"},
Usage: "Optional training token address",
Value: ethutils.ZeroAddress.Hex(),
Required: false,
},
&cli.StringFlag{
Name: "system-account-address",
Aliases: []string{"system-account"},
Usage: "The system account address",
Required: true,
},
},
Action: func(cCtx *cli.Context) error {
contract := contract.NewCustodialRegistrationProxy(contract.CustodialRegistrationProxyArgs{
EthFaucetAddress: ethutils.HexToAddress(cCtx.String("eth-faucet-address")),
AccountsIndexAddress: ethutils.HexToAddress(cCtx.String("accounts-index-address")),
TrainingTokenAddress: ethutils.HexToAddress(cCtx.String("training-token")),
SystemAccountAddress: ethutils.HexToAddress(cCtx.String("system-account-address")),
})
bytecode, err := contract.Bytecode()
if err != nil {
return err
}
c.logInitStage(contract)

resp, err := c.SendContractPublishTx(cCtx, bytecode, contract.MaxGasLimit())
if err != nil {
return err
}
c.logPublishedStage(contract, resp)

return nil
},
}
}

func (c *Container) logInitStage(contract contract.Contract) {
c.Logg.Info(fmt.Sprintf("publishing %s contract", contract.Name()),
"version", contract.Version(),
Expand Down
19 changes: 19 additions & 0 deletions pkg/contract/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/grassrootseconomics/ge-publish/pkg/accountsindex"
"github.com/grassrootseconomics/ge-publish/pkg/contractsregistry"
"github.com/grassrootseconomics/ge-publish/pkg/custodialregistrationproxy"
"github.com/grassrootseconomics/ge-publish/pkg/decimalquote"
"github.com/grassrootseconomics/ge-publish/pkg/erc20"
"github.com/grassrootseconomics/ge-publish/pkg/erc20demurrage"
Expand Down Expand Up @@ -67,6 +68,13 @@ type (
Decimals uint8
ExpiryTimestamp *big.Int
}

CustodialRegistrationProxyArgs struct {
EthFaucetAddress common.Address
AccountsIndexAddress common.Address
TrainingTokenAddress common.Address
SystemAccountAddress common.Address
}
)

func NewDecimalQuote() Contract {
Expand Down Expand Up @@ -169,3 +177,14 @@ func NewContractsRegistry(identifiers []string) Contract {
},
}
}

func NewCustodialRegistrationProxy(args CustodialRegistrationProxyArgs) Contract {
return &custodialregistrationproxy.CustodialRegistrationProxy{
Constructor: []any{
args.EthFaucetAddress,
args.AccountsIndexAddress,
args.TrainingTokenAddress,
args.SystemAccountAddress,
},
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
608060405234801561001057600080fd5b50604051610bc6380380610bc6833981810160405281019061003291906101e2565b336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555080600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555083600260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555082600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555081600460006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050505050610249565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006101af82610184565b9050919050565b6101bf816101a4565b81146101ca57600080fd5b50565b6000815190506101dc816101b6565b92915050565b600080600080608085870312156101fc576101fb61017f565b5b600061020a878288016101cd565b945050602061021b878288016101cd565b935050604061022c878288016101cd565b925050606061023d878288016101cd565b91505092959194509250565b61096e806102586000396000f3fe608060405234801561001057600080fd5b50600436106100925760003560e01c80638da5cb5b116100665780638da5cb5b1461010d578063b2f5ae4b1461012b578063becf2e3614610149578063e2af398014610165578063f5a1f5b41461018357610092565b80628c03371461009757806317603379146100b557806329db660b146100d35780634420e486146100f1575b600080fd5b61009f61019f565b6040516100ac91906106f0565b60405180910390f35b6100bd6101c5565b6040516100ca919061072c565b60405180910390f35b6100db6101eb565b6040516100e89190610768565b60405180910390f35b61010b600480360381019061010691906107c6565b610211565b005b6101156104e9565b6040516101229190610802565b60405180910390f35b61013361050d565b6040516101409190610836565b60405180910390f35b610163600480360381019061015e91906107c6565b610514565b005b61016d6105b0565b60405161017a9190610802565b60405180910390f35b61019d600480360381019061019891906107c6565b6105d6565b005b600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614806102b85750600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16145b6102c157600080fd5b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16630a3b0a4f826040518263ffffffff1660e01b815260040161031c9190610802565b6020604051808303816000875af115801561033b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061035f9190610889565b50600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166363e4bff4826040518263ffffffff1660e01b81526004016103bb9190610802565b6020604051808303816000875af11580156103da573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103fe91906108e2565b50600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663449a52f882624c4b406040518363ffffffff1660e01b815260040161045f92919061090f565b6020604051808303816000875af115801561047e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104a29190610889565b508073ffffffffffffffffffffffffffffffffffffffff167f894e56e1dac400b4475c83d8af0f0aa44de17c62764bd82f6e768a504e24246160405160405180910390a250565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b624c4b4081565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461056c57600080fd5b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461062e57600080fd5b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b60006106b66106b16106ac84610671565b610691565b610671565b9050919050565b60006106c88261069b565b9050919050565b60006106da826106bd565b9050919050565b6106ea816106cf565b82525050565b600060208201905061070560008301846106e1565b92915050565b6000610716826106bd565b9050919050565b6107268161070b565b82525050565b6000602082019050610741600083018461071d565b92915050565b6000610752826106bd565b9050919050565b61076281610747565b82525050565b600060208201905061077d6000830184610759565b92915050565b600080fd5b600061079382610671565b9050919050565b6107a381610788565b81146107ae57600080fd5b50565b6000813590506107c08161079a565b92915050565b6000602082840312156107dc576107db610783565b5b60006107ea848285016107b1565b91505092915050565b6107fc81610788565b82525050565b600060208201905061081760008301846107f3565b92915050565b6000819050919050565b6108308161081d565b82525050565b600060208201905061084b6000830184610827565b92915050565b60008115159050919050565b61086681610851565b811461087157600080fd5b50565b6000815190506108838161085d565b92915050565b60006020828403121561089f5761089e610783565b5b60006108ad84828501610874565b91505092915050565b6108bf8161081d565b81146108ca57600080fd5b50565b6000815190506108dc816108b6565b92915050565b6000602082840312156108f8576108f7610783565b5b6000610906848285016108cd565b91505092915050565b600060408201905061092460008301856107f3565b6109316020830184610827565b939250505056fea26469706673582212204725c97f174fc1591845527548658d0dbd5bc9cd62892c93a8efc607d09c7ad064736f6c63430008190033
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"inputs":[{"internalType":"address","name":"_ethFaucetAddress","type":"address"},{"internalType":"address","name":"_custodialAccountIndexAddress","type":"address"},{"internalType":"address","name":"_trainingVoucherAddress","type":"address"},{"internalType":"address","name":"_systemAccount","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"subject","type":"address"}],"name":"NewRegistration","type":"event"},{"inputs":[],"name":"CustodialAccountIndex","outputs":[{"internalType":"contract ICustodialAccountIndex","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"EthFaucet","outputs":[{"internalType":"contract IEthFaucet","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TrainingVoucher","outputs":[{"internalType":"contract IDemurrageTokenSingleNocap","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_subject","type":"address"}],"name":"register","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_newOwner","type":"address"}],"name":"setNewOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_newSystemAccount","type":"address"}],"name":"setNewSystemAccount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"systemAccount","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"trainingVoucerGiftAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]
68 changes: 68 additions & 0 deletions pkg/custodialregistrationproxy/custodialregistrationproxy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package custodialregistrationproxy

import (
_ "embed"

"github.com/grassrootseconomics/ethutils"
"github.com/grassrootseconomics/ge-publish/pkg/util"
)

type (
CustodialRegistrationProxy struct {
Constructor []any
}
)

const (
name = "CustodialRegistrationProxy"
version = "v0.1.0"
license = "AGPL-3.0"
source = "https://github.com/grassrootseconomics/custodial-registration-proxy/tree/master/solidity"
solidityVersion = "0.8.25+commit.b61c2a91"
evmFork = "istanbul"

gasLimit = 2_000_000
)

var (
//go:embed CustodialRegistrationProxy.bin
bin string
//go:embed CustodialRegistrationProxy.json
abi string
)

func (c *CustodialRegistrationProxy) Name() string {
return name
}

func (c *CustodialRegistrationProxy) Version() string {
return version
}

func (c *CustodialRegistrationProxy) License() string {
return license
}

func (c *CustodialRegistrationProxy) Source() string {
return source
}

func (c *CustodialRegistrationProxy) SolidityVersion() string {
return solidityVersion
}

func (c *CustodialRegistrationProxy) EVMFork() string {
return evmFork
}

func (c *CustodialRegistrationProxy) ConstructorArgs() []string {
return util.DumpConstructorArgs(c.Constructor)
}

func (c *CustodialRegistrationProxy) Bytecode() ([]byte, error) {
return ethutils.PrepareContractBytecodeData(bin, abi, c.Constructor)
}

func (c *CustodialRegistrationProxy) MaxGasLimit() uint64 {
return gasLimit
}

0 comments on commit 67819d3

Please sign in to comment.