From ebcc12b685dcad81147af702fdadb58ebec149b5 Mon Sep 17 00:00:00 2001 From: hvthhien Date: Thu, 23 May 2024 15:54:34 +0700 Subject: [PATCH 01/12] update contract v4_2 --- contracts/feralfile-exhibition-v4/feralfile.go | 8 ++++++++ go.mod | 2 +- go.sum | 6 ++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/contracts/feralfile-exhibition-v4/feralfile.go b/contracts/feralfile-exhibition-v4/feralfile.go index cfb4b73..d1f84a1 100644 --- a/contracts/feralfile-exhibition-v4/feralfile.go +++ b/contracts/feralfile-exhibition-v4/feralfile.go @@ -206,6 +206,12 @@ func (c *FeralfileExhibitionV4Contract) Call( } return contract.SetAdvanceSetting(t, params[0].([]common.Address), params[1].([]*big.Int)) + case "updateTokenInformation": + if len(params) != 3 { + return nil, errors.New("Invalid parameters") + } + + return contract.UpdateTokenInformation(t, params[0].(*big.Int), params[1].(string), params[2].([]byte)) default: return nil, fmt.Errorf("unsupported method") } @@ -383,6 +389,8 @@ func (c *FeralfileExhibitionV4Contract) Parse( } return []interface{}{params.AdvanceAddresses, advanceAmounts}, nil + case "updateTokenInformation": + return []interface{}{}, nil default: return nil, fmt.Errorf("unsupported method") } diff --git a/go.mod b/go.mod index c5b18b2..ed226f5 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/bitmark-inc/account-vault-ethereum go 1.20 require ( - github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240420161158-7827629e2797 + github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240523090831-3bbdf4f223a1 github.com/ethereum/go-ethereum v1.13.10 github.com/miguelmota/go-ethereum-hdwallet v0.1.1 github.com/stretchr/testify v1.8.4 diff --git a/go.sum b/go.sum index f20b502..7b732d9 100644 --- a/go.sum +++ b/go.sum @@ -63,8 +63,10 @@ github.com/aws/smithy-go v1.1.0/go.mod h1:EzMw8dbp/YJL4A5/sbhGddag+NPT7q084agLbB github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= -github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240420161158-7827629e2797 h1:avNsve02bxwzXzHGbvxrd78MYSdRJmnVwj50HsqZQCc= -github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240420161158-7827629e2797/go.mod h1:shvtsuJyQJnByXKqf9n/jpjL4++FSJCFjXR/08iBnFY= +github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240523083611-11a8480de376 h1:+Whj98ezo1eSt8OWl7qnWNIKdp2Xd5zWAEw+hS1wUhk= +github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240523083611-11a8480de376/go.mod h1:shvtsuJyQJnByXKqf9n/jpjL4++FSJCFjXR/08iBnFY= +github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240523090831-3bbdf4f223a1 h1:DDUWcIvqkpMPCvJqUskpPCmbY1kdfNysjjU18zRym40= +github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240523090831-3bbdf4f223a1/go.mod h1:shvtsuJyQJnByXKqf9n/jpjL4++FSJCFjXR/08iBnFY= github.com/bits-and-blooms/bitset v1.10.0 h1:ePXTeiPEazB5+opbv5fr8umg2R/1NlzgDsyepwsSr88= github.com/bits-and-blooms/bitset v1.10.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c= From 00f469b8d15fd63f62545f6165fe39f45a762979 Mon Sep 17 00:00:00 2001 From: hvthhien Date: Fri, 24 May 2024 11:03:14 +0700 Subject: [PATCH 02/12] update contract v4_2 & feralfiletoken --- .../feralfile-exhibition-v4/feralfile.go | 8 - .../feralfile-exhibition-v4_2/feralfile.go | 412 ++++++++++++++++++ contracts/feralfile-token/feralfile.go | 162 +++++++ go.mod | 2 +- go.sum | 2 + 5 files changed, 577 insertions(+), 9 deletions(-) create mode 100644 contracts/feralfile-exhibition-v4_2/feralfile.go create mode 100644 contracts/feralfile-token/feralfile.go diff --git a/contracts/feralfile-exhibition-v4/feralfile.go b/contracts/feralfile-exhibition-v4/feralfile.go index d1f84a1..cfb4b73 100644 --- a/contracts/feralfile-exhibition-v4/feralfile.go +++ b/contracts/feralfile-exhibition-v4/feralfile.go @@ -206,12 +206,6 @@ func (c *FeralfileExhibitionV4Contract) Call( } return contract.SetAdvanceSetting(t, params[0].([]common.Address), params[1].([]*big.Int)) - case "updateTokenInformation": - if len(params) != 3 { - return nil, errors.New("Invalid parameters") - } - - return contract.UpdateTokenInformation(t, params[0].(*big.Int), params[1].(string), params[2].([]byte)) default: return nil, fmt.Errorf("unsupported method") } @@ -389,8 +383,6 @@ func (c *FeralfileExhibitionV4Contract) Parse( } return []interface{}{params.AdvanceAddresses, advanceAmounts}, nil - case "updateTokenInformation": - return []interface{}{}, nil default: return nil, fmt.Errorf("unsupported method") } diff --git a/contracts/feralfile-exhibition-v4_2/feralfile.go b/contracts/feralfile-exhibition-v4_2/feralfile.go new file mode 100644 index 0000000..2883b35 --- /dev/null +++ b/contracts/feralfile-exhibition-v4_2/feralfile.go @@ -0,0 +1,412 @@ +package feralfilev4_2 + +import ( + "encoding/hex" + "encoding/json" + "errors" + "fmt" + "math/big" + "strconv" + "strings" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/params" + + ethereum "github.com/bitmark-inc/account-vault-ethereum" + feralfilev4 "github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding/feralfile-exhibition-v4_2" +) + +type FeralfileExhibitionV4_2Contract struct { + contractAddress string +} + +func FeralfileExhibitionV4_2ContractFactory(contractAddress string) ethereum.Contract { + return &FeralfileExhibitionV4_2Contract{ + contractAddress: contractAddress, + } +} + +// Deploy deploys the smart contract to ethereum blockchain +func (c *FeralfileExhibitionV4_2Contract) Deploy( + wallet *ethereum.Wallet, + arguments json.RawMessage) (string, string, error) { + var params struct { + Name string `json:"name"` + Symbol string `json:"symbol"` + Signer common.Address `json:"signer"` + Vault common.Address `json:"vault"` + CostReceiver common.Address `json:"cost_receiver"` + ContractURI string `json:"contract_uri"` + IsBurnable bool `json:"is_burnable"` + IsBridgeable bool `json:"is_bridgeable"` + SeriesIDs []*big.Int `json:"series_ids"` + SeriesMaxSupplies []*big.Int `json:"series_max_supplies"` + } + + if err := json.Unmarshal(arguments, ¶ms); err != nil { + return "", "", err + } + + t, err := wallet.Transactor() + if err != nil { + return "", "", err + } + + address, tx, _, err := feralfilev4.DeployFeralfileExhibitionV42( + t, + wallet.RPCClient(), + params.Name, + params.Symbol, + params.IsBurnable, + params.IsBridgeable, + params.Signer, + params.Vault, + params.CostReceiver, + params.ContractURI, + params.SeriesIDs, + params.SeriesMaxSupplies, + ) + if err != nil { + return "", "", err + } + return address.String(), tx.Hash().String(), nil +} + +// Call is the entry function for account vault to interact with a smart contract. +func (c *FeralfileExhibitionV4_2Contract) Call( + wallet *ethereum.Wallet, + method, + fund string, + arguments json.RawMessage, + noSend bool, + gasLimit uint64, + gasPrice *int64, + nonce *uint64) (*types.Transaction, error) { + contractAddr := common.HexToAddress(c.contractAddress) + contract, err := feralfilev4.NewFeralfileExhibitionV42(contractAddr, wallet.RPCClient()) + if err != nil { + return nil, err + } + + t, err := wallet.Transactor() + if err != nil { + return nil, err + } + + t.NoSend = noSend + t.GasLimit = gasLimit + if gasPrice != nil && *gasPrice != 0 { + t.GasPrice = big.NewInt(*gasPrice * params.Wei) + } + + if nonce != nil { + t.Nonce = big.NewInt(int64(*nonce)) + } + + params, err := c.Parse(method, arguments) + if nil != err { + return nil, err + } + + switch method { + case "burnArtworks": + if len(params) != 1 { + return nil, errors.New("Invalid parameters") + } + + tokenIDs, ok := params[0].([]*big.Int) + if !ok { + return nil, errors.New("Invalid token burn parameters") + } + + return contract.BurnArtworks(t, tokenIDs) + case "mintArtworks": + if len(params) != 1 { + return nil, errors.New("Invalid parameters") + } + + mintData, ok := params[0].([]feralfilev4.FeralfileExhibitionV42MintDataWithIndex) + if !ok { + return nil, errors.New("Invalid token mint parameters") + } + + return contract.MintArtworksWithIndex(t, mintData) + case "setTokenBaseURI": + if len(params) != 1 { + return nil, errors.New("Invalid parameters") + } + + baseURI, ok := params[0].(string) + if !ok { + return nil, errors.New("Invalid token base URI") + } + + return contract.SetTokenBaseURI(t, baseURI) + case "startSale": + return contract.StartSale(t) + case "transferOwnership": + if len(params) != 1 { + return nil, errors.New("Invalid parameters") + } + + newOwner, ok := params[0].(common.Address) + if !ok { + return nil, errors.New("Invalid new owner") + } + + return contract.TransferOwnership(t, newOwner) + case "buyArtworks": + if len(params) != 4 { + return nil, errors.New("Invalid parameters") + } + + r, ok := params[0].([32]byte) + if !ok { + return nil, fmt.Errorf("invalid r") + } + + s, ok := params[1].([32]byte) + if !ok { + return nil, fmt.Errorf("invalid s") + } + + v, ok := params[2].(uint8) + if !ok { + return nil, fmt.Errorf("invalid v") + } + + saleData, ok := params[3].(feralfilev4.IFeralfileSaleDataSaleData) + if !ok { + return nil, fmt.Errorf("invalid sale data") + } + + return contract.BuyArtworks(t, r, s, v, saleData) + case "setApprovalForAll": + if len(params) != 2 { + return nil, errors.New("Invalid parameters") + } + + operator, ok := params[0].(common.Address) + if !ok { + return nil, errors.New("Invalid operator") + } + + approved, ok := params[1].(bool) + if !ok { + return nil, errors.New("Invalid approved") + } + + t.GasLimit = gasLimit + + return contract.SetApprovalForAll(t, operator, approved) + case "setAdvanceSetting": + if len(params) != 2 { + return nil, errors.New("Invalid parameters") + } + + return contract.SetAdvanceSetting(t, params[0].([]common.Address), params[1].([]*big.Int)) + case "updateTokenInformation": + if len(params) != 3 { + return nil, errors.New("Invalid parameters") + } + + return contract.UpdateTokenInformation(t, params[0].(*big.Int), params[1].(string), params[2].([]byte)) + default: + return nil, fmt.Errorf("unsupported method") + } +} + +func (c *FeralfileExhibitionV4_2Contract) Pack( + method string, + arguments json.RawMessage) ([]byte, error) { + abi, err := feralfilev4.FeralfileExhibitionV42MetaData.GetAbi() + if nil != err { + return nil, err + } + + parsedArgs, err := c.Parse(method, arguments) + if nil != err { + return nil, err + } + + return abi.Pack(method, parsedArgs...) +} + +func (c *FeralfileExhibitionV4_2Contract) Parse( + method string, + arguments json.RawMessage) ([]interface{}, error) { + switch method { + case "startSale": + return nil, nil + case "burnArtworks": + var params []ethereum.BigInt + if err := json.Unmarshal(arguments, ¶ms); err != nil { + return nil, err + } + if len(params) == 0 { + return nil, errors.New("Invalid token burn parameters") + } + + tokenIDs := make([]*big.Int, len(params)) + for i, v := range params { + tokenID := v.Int + tokenIDs[i] = &tokenID + } + + return []interface{}{tokenIDs}, nil + case "mintArtworks": + var params []struct { + SeriesID ethereum.BigInt `json:"series_id"` + TokenID ethereum.BigInt `json:"token_id"` + Owner common.Address `json:"owner"` + TokenIndex ethereum.BigInt `json:"token_index"` + } + if err := json.Unmarshal(arguments, ¶ms); err != nil { + return nil, err + } + if len(params) == 0 { + return nil, errors.New("Invalid token mint parameters") + } + + mintData := make([]feralfilev4.FeralfileExhibitionV42MintDataWithIndex, len(params)) + for i := 0; i < len(params); i++ { + mintData[i] = feralfilev4.FeralfileExhibitionV42MintDataWithIndex{ + SeriesId: ¶ms[i].SeriesID.Int, + TokenId: ¶ms[i].TokenID.Int, + Owner: params[i].Owner, + TokenIndex: ¶ms[i].TokenIndex.Int, + } + } + + return []interface{}{mintData}, nil + case "setTokenBaseURI": + baseURI := strings.Trim(string(arguments), "\"") + if baseURI == "" { + return nil, errors.New("Invalid token base URI") + } + return []interface{}{baseURI}, nil + case "transferOwnership": + var newOwner common.Address + if err := json.Unmarshal(arguments, &newOwner); err != nil { + return nil, err + } + return []interface{}{newOwner}, nil + case "setApprovalForAll": + var params struct { + Operator common.Address `json:"operator"` + Approved bool `json:"approved"` + } + if err := json.Unmarshal(arguments, ¶ms); err != nil { + return nil, err + } + + return []interface{}{params.Operator, params.Approved}, nil + case "buyArtworks": + var params struct { + SaleData struct { + Price ethereum.BigInt `json:"price"` + Cost ethereum.BigInt `json:"cost"` + ExpiryTime ethereum.BigInt `json:"expiryTime"` + Destination common.Address `json:"destination"` + TokenIds []ethereum.BigInt `json:"tokenIds"` + RevenueShares [][]struct { + Recipient common.Address `json:"recipient"` + Bps ethereum.BigInt `json:"bps"` + } `json:"revenueShares"` + PayByVaultContract bool `json:"payByVaultContract"` + } `json:"saleData"` + R string `json:"r"` + S string `json:"s"` + V string `json:"v"` + } + + if err := json.Unmarshal(arguments, ¶ms); err != nil { + return nil, err + } + + rVal, err := hex.DecodeString(strings.Replace(params.R, "0x", "", -1)) + if err != nil { + return nil, err + } + sVal, err := hex.DecodeString(strings.Replace(params.S, "0x", "", -1)) + if err != nil { + return nil, err + } + vVal, err := strconv.ParseUint(strings.Replace(params.V, "0x", "", -1), 16, 64) + if err != nil { + return nil, err + } + if len(rVal) != 32 || len(sVal) != 32 { + return nil, errors.New("required signature length is 32") + } + var r32Val [32]byte + var s32Val [32]byte + copy(r32Val[:], rVal) + copy(s32Val[:], sVal) + + tokenIDs := make([]*big.Int, 0) + for _, v := range params.SaleData.TokenIds { + tokenID := v.Int + tokenIDs = append(tokenIDs, &tokenID) + } + + revenueShares := make([][]feralfilev4.IFeralfileSaleDataRevenueShare, 0) + for _, v := range params.SaleData.RevenueShares { + revenueShare := make([]feralfilev4.IFeralfileSaleDataRevenueShare, 0) + for _, vv := range v { + bps := vv.Bps.Int + revenueShare = append(revenueShare, feralfilev4.IFeralfileSaleDataRevenueShare{ + Recipient: vv.Recipient, + Bps: &bps, + }) + } + revenueShares = append(revenueShares, revenueShare) + } + + saleData := feralfilev4.IFeralfileSaleDataSaleData{ + Price: ¶ms.SaleData.Price.Int, + Cost: ¶ms.SaleData.Cost.Int, + ExpiryTime: ¶ms.SaleData.ExpiryTime.Int, + Destination: params.SaleData.Destination, + TokenIds: tokenIDs, + RevenueShares: revenueShares, + PayByVaultContract: params.SaleData.PayByVaultContract, + } + + return []interface{}{r32Val, s32Val, uint8(vVal), saleData}, nil + case "setAdvanceSetting": + var params struct { + AdvanceAddresses []common.Address `json:"advance_addresses"` + AdvanceAmounts []ethereum.BigInt `json:"advance_amounts"` + } + if err := json.Unmarshal(arguments, ¶ms); err != nil { + return nil, err + } + + advanceAmounts := make([]*big.Int, len(params.AdvanceAmounts)) + for i, v := range params.AdvanceAmounts { + amount := v.Int // closure issue + advanceAmounts[i] = &amount + } + + return []interface{}{params.AdvanceAddresses, advanceAmounts}, nil + case "updateTokenInformation": + var params struct { + TokenID ethereum.BigInt `json:"token_id"` + ImageURI string `json:"image_uri"` + Paramters []byte `json:"parameters"` + } + if err := json.Unmarshal(arguments, ¶ms); err != nil { + return nil, err + } + + return []interface{}{params.TokenID.Int, params.ImageURI, params.Paramters}, nil + default: + return nil, fmt.Errorf("unsupported method") + } +} + +func init() { + ethereum.RegisterContract("FeralfileExhibitionV4_2", FeralfileExhibitionV4_2ContractFactory) +} diff --git a/contracts/feralfile-token/feralfile.go b/contracts/feralfile-token/feralfile.go new file mode 100644 index 0000000..ec4d209 --- /dev/null +++ b/contracts/feralfile-token/feralfile.go @@ -0,0 +1,162 @@ +package feralfiletoken + +import ( + "encoding/json" + "errors" + "fmt" + "math/big" + + ethereum "github.com/bitmark-inc/account-vault-ethereum" + feralfiletoken "github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding/feralfile-token" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/params" +) + +type FeralFileTokenContract struct { + contractAddress string +} + +func FeralFileTokenContractFactory(contractAddress string) ethereum.Contract { + return &FeralFileTokenContract{ + contractAddress: contractAddress, + } +} + +func (c *FeralFileTokenContract) Deploy( + wallet *ethereum.Wallet, + arguments json.RawMessage) (string, string, error) { + return "", "", errors.ErrUnsupported +} + +func (c *FeralFileTokenContract) Call( + wallet *ethereum.Wallet, + method, + fund string, + arguments json.RawMessage, + noSend bool, + gasLimit uint64, + gasPrice *int64, + nonce *uint64) (*types.Transaction, error) { + contractAddr := common.HexToAddress(c.contractAddress) + contract, err := feralfiletoken.NewFeralfileToken( + contractAddr, + wallet.RPCClient()) + if err != nil { + return nil, err + } + + t, err := wallet.Transactor() + if err != nil { + return nil, err + } + + t.NoSend = noSend + t.GasLimit = gasLimit + if gasPrice != nil && *gasPrice != 0 { + t.GasPrice = big.NewInt(*gasPrice * params.Wei) + } + + if nonce != nil { + t.Nonce = big.NewInt(int64(*nonce)) + } + + params, err := c.Parse(method, arguments) + if nil != err { + return nil, err + } + + switch method { + case "mint": + if len(params) != 2 { + return nil, fmt.Errorf("invalid parameters") + } + + owner, ok := params[0].(common.Address) + if !ok { + return nil, fmt.Errorf("invalid owner") + } + + amount, ok := params[1].(*big.Int) + if !ok { + return nil, fmt.Errorf("invalid amount") + } + + return contract.Mint(t, owner, amount) + case "batchMint": + if len(params) != 2 { + return nil, fmt.Errorf("invalid parameters") + } + + owners, ok := params[0].([]common.Address) + if !ok { + return nil, fmt.Errorf("invalid owners") + } + + amounts, ok := params[1].([]*big.Int) + if !ok { + return nil, fmt.Errorf("invalid amounts") + } + + return contract.BatchMint(t, owners, amounts) + } + + return nil, fmt.Errorf("unsupported method") +} + +func (c *FeralFileTokenContract) Pack( + method string, + arguments json.RawMessage) ([]byte, error) { + abi, err := feralfiletoken.FeralfileTokenMetaData.GetAbi() + if nil != err { + return nil, err + } + + parsedArgs, err := c.Parse(method, arguments) + if nil != err { + return nil, err + } + + return abi.Pack(method, parsedArgs...) +} + +func (c *FeralFileTokenContract) Parse( + method string, + arguments json.RawMessage) ([]interface{}, error) { + switch method { + case "mint": + var params struct { + Owner *common.Address `json:"owner"` + Amount *ethereum.BigInt `json:"amount"` + } + + if err := json.Unmarshal(arguments, ¶ms); err != nil { + return nil, err + } + + return []interface{}{¶ms.Owner, ¶ms.Amount.Int}, nil + case "batchMint": + var params struct { + Owners []common.Address `json:"owners"` + Amounts []*ethereum.BigInt `json:"amounts"` + } + + if err := json.Unmarshal(arguments, ¶ms); err != nil { + return nil, err + } + + amounts := make([]*big.Int, 0) + for _, a := range params.Amounts { + v := a.Int + amounts = append(amounts, &v) + } + + return []interface{}{params.Owners, amounts}, nil + default: + return nil, fmt.Errorf("unsupported method") + } +} + +func init() { + ethereum.RegisterContract("FeralfileToken", FeralFileTokenContractFactory) +} diff --git a/go.mod b/go.mod index ed226f5..0c66ca5 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/bitmark-inc/account-vault-ethereum go 1.20 require ( - github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240523090831-3bbdf4f223a1 + github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240524032905-a9cb9b876fba github.com/ethereum/go-ethereum v1.13.10 github.com/miguelmota/go-ethereum-hdwallet v0.1.1 github.com/stretchr/testify v1.8.4 diff --git a/go.sum b/go.sum index 7b732d9..9ab8548 100644 --- a/go.sum +++ b/go.sum @@ -67,6 +67,8 @@ github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-202 github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240523083611-11a8480de376/go.mod h1:shvtsuJyQJnByXKqf9n/jpjL4++FSJCFjXR/08iBnFY= github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240523090831-3bbdf4f223a1 h1:DDUWcIvqkpMPCvJqUskpPCmbY1kdfNysjjU18zRym40= github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240523090831-3bbdf4f223a1/go.mod h1:shvtsuJyQJnByXKqf9n/jpjL4++FSJCFjXR/08iBnFY= +github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240524032905-a9cb9b876fba h1:DK0sqy5xmj8E01Vayt5FSCaDefrBmLUc3uNTLgp9sMc= +github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240524032905-a9cb9b876fba/go.mod h1:shvtsuJyQJnByXKqf9n/jpjL4++FSJCFjXR/08iBnFY= github.com/bits-and-blooms/bitset v1.10.0 h1:ePXTeiPEazB5+opbv5fr8umg2R/1NlzgDsyepwsSr88= github.com/bits-and-blooms/bitset v1.10.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c= From 65296515ef56ca30c2e33721de3ee9e747e9c458 Mon Sep 17 00:00:00 2001 From: hvthhien Date: Fri, 24 May 2024 11:18:15 +0700 Subject: [PATCH 03/12] update deploy function for feralfiletoken --- contracts/feralfile-token/feralfile.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/contracts/feralfile-token/feralfile.go b/contracts/feralfile-token/feralfile.go index ec4d209..be41f13 100644 --- a/contracts/feralfile-token/feralfile.go +++ b/contracts/feralfile-token/feralfile.go @@ -2,7 +2,6 @@ package feralfiletoken import ( "encoding/json" - "errors" "fmt" "math/big" @@ -26,7 +25,25 @@ func FeralFileTokenContractFactory(contractAddress string) ethereum.Contract { func (c *FeralFileTokenContract) Deploy( wallet *ethereum.Wallet, arguments json.RawMessage) (string, string, error) { - return "", "", errors.ErrUnsupported + var params struct { + Name string `json:"name"` + Symbol string `json:"symbol"` + } + + if err := json.Unmarshal(arguments, ¶ms); err != nil { + return "", "", err + } + + t, err := wallet.Transactor() + if err != nil { + return "", "", err + } + + address, tx, _, err := feralfiletoken.DeployFeralfileToken(t, wallet.RPCClient(), params.Name, params.Symbol) + if err != nil { + return "", "", err + } + return address.String(), tx.Hash().String(), nil } func (c *FeralFileTokenContract) Call( From 873a90d2fbcc619a0aaf2ab1248bb204afdd1cd7 Mon Sep 17 00:00:00 2001 From: hvthhien Date: Fri, 24 May 2024 16:17:37 +0700 Subject: [PATCH 04/12] remove feralfile token --- contracts/feralfile-token/feralfile.go | 179 ------------------------- 1 file changed, 179 deletions(-) delete mode 100644 contracts/feralfile-token/feralfile.go diff --git a/contracts/feralfile-token/feralfile.go b/contracts/feralfile-token/feralfile.go deleted file mode 100644 index be41f13..0000000 --- a/contracts/feralfile-token/feralfile.go +++ /dev/null @@ -1,179 +0,0 @@ -package feralfiletoken - -import ( - "encoding/json" - "fmt" - "math/big" - - ethereum "github.com/bitmark-inc/account-vault-ethereum" - feralfiletoken "github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding/feralfile-token" - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/params" -) - -type FeralFileTokenContract struct { - contractAddress string -} - -func FeralFileTokenContractFactory(contractAddress string) ethereum.Contract { - return &FeralFileTokenContract{ - contractAddress: contractAddress, - } -} - -func (c *FeralFileTokenContract) Deploy( - wallet *ethereum.Wallet, - arguments json.RawMessage) (string, string, error) { - var params struct { - Name string `json:"name"` - Symbol string `json:"symbol"` - } - - if err := json.Unmarshal(arguments, ¶ms); err != nil { - return "", "", err - } - - t, err := wallet.Transactor() - if err != nil { - return "", "", err - } - - address, tx, _, err := feralfiletoken.DeployFeralfileToken(t, wallet.RPCClient(), params.Name, params.Symbol) - if err != nil { - return "", "", err - } - return address.String(), tx.Hash().String(), nil -} - -func (c *FeralFileTokenContract) Call( - wallet *ethereum.Wallet, - method, - fund string, - arguments json.RawMessage, - noSend bool, - gasLimit uint64, - gasPrice *int64, - nonce *uint64) (*types.Transaction, error) { - contractAddr := common.HexToAddress(c.contractAddress) - contract, err := feralfiletoken.NewFeralfileToken( - contractAddr, - wallet.RPCClient()) - if err != nil { - return nil, err - } - - t, err := wallet.Transactor() - if err != nil { - return nil, err - } - - t.NoSend = noSend - t.GasLimit = gasLimit - if gasPrice != nil && *gasPrice != 0 { - t.GasPrice = big.NewInt(*gasPrice * params.Wei) - } - - if nonce != nil { - t.Nonce = big.NewInt(int64(*nonce)) - } - - params, err := c.Parse(method, arguments) - if nil != err { - return nil, err - } - - switch method { - case "mint": - if len(params) != 2 { - return nil, fmt.Errorf("invalid parameters") - } - - owner, ok := params[0].(common.Address) - if !ok { - return nil, fmt.Errorf("invalid owner") - } - - amount, ok := params[1].(*big.Int) - if !ok { - return nil, fmt.Errorf("invalid amount") - } - - return contract.Mint(t, owner, amount) - case "batchMint": - if len(params) != 2 { - return nil, fmt.Errorf("invalid parameters") - } - - owners, ok := params[0].([]common.Address) - if !ok { - return nil, fmt.Errorf("invalid owners") - } - - amounts, ok := params[1].([]*big.Int) - if !ok { - return nil, fmt.Errorf("invalid amounts") - } - - return contract.BatchMint(t, owners, amounts) - } - - return nil, fmt.Errorf("unsupported method") -} - -func (c *FeralFileTokenContract) Pack( - method string, - arguments json.RawMessage) ([]byte, error) { - abi, err := feralfiletoken.FeralfileTokenMetaData.GetAbi() - if nil != err { - return nil, err - } - - parsedArgs, err := c.Parse(method, arguments) - if nil != err { - return nil, err - } - - return abi.Pack(method, parsedArgs...) -} - -func (c *FeralFileTokenContract) Parse( - method string, - arguments json.RawMessage) ([]interface{}, error) { - switch method { - case "mint": - var params struct { - Owner *common.Address `json:"owner"` - Amount *ethereum.BigInt `json:"amount"` - } - - if err := json.Unmarshal(arguments, ¶ms); err != nil { - return nil, err - } - - return []interface{}{¶ms.Owner, ¶ms.Amount.Int}, nil - case "batchMint": - var params struct { - Owners []common.Address `json:"owners"` - Amounts []*ethereum.BigInt `json:"amounts"` - } - - if err := json.Unmarshal(arguments, ¶ms); err != nil { - return nil, err - } - - amounts := make([]*big.Int, 0) - for _, a := range params.Amounts { - v := a.Int - amounts = append(amounts, &v) - } - - return []interface{}{params.Owners, amounts}, nil - default: - return nil, fmt.Errorf("unsupported method") - } -} - -func init() { - ethereum.RegisterContract("FeralfileToken", FeralFileTokenContractFactory) -} From e6da427afcf07b9915cc324b9933fbd0f25d239b Mon Sep 17 00:00:00 2001 From: hvthhien Date: Fri, 24 May 2024 18:18:06 +0700 Subject: [PATCH 05/12] update deps --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 0c66ca5..90861ad 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/bitmark-inc/account-vault-ethereum go 1.20 require ( - github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240524032905-a9cb9b876fba + github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240524095144-3bd3a71417e9 github.com/ethereum/go-ethereum v1.13.10 github.com/miguelmota/go-ethereum-hdwallet v0.1.1 github.com/stretchr/testify v1.8.4 diff --git a/go.sum b/go.sum index 9ab8548..8d2229e 100644 --- a/go.sum +++ b/go.sum @@ -69,6 +69,8 @@ github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-202 github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240523090831-3bbdf4f223a1/go.mod h1:shvtsuJyQJnByXKqf9n/jpjL4++FSJCFjXR/08iBnFY= github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240524032905-a9cb9b876fba h1:DK0sqy5xmj8E01Vayt5FSCaDefrBmLUc3uNTLgp9sMc= github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240524032905-a9cb9b876fba/go.mod h1:shvtsuJyQJnByXKqf9n/jpjL4++FSJCFjXR/08iBnFY= +github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240524095144-3bd3a71417e9 h1:GLVv5hYMmGwqQpJOasDz9kMhDyCpafKRK8J/khQs/fY= +github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240524095144-3bd3a71417e9/go.mod h1:shvtsuJyQJnByXKqf9n/jpjL4++FSJCFjXR/08iBnFY= github.com/bits-and-blooms/bitset v1.10.0 h1:ePXTeiPEazB5+opbv5fr8umg2R/1NlzgDsyepwsSr88= github.com/bits-and-blooms/bitset v1.10.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c= From 04e94e417ec8df1d65e1cd00d8755f6cc6502f1f Mon Sep 17 00:00:00 2001 From: hvthhien Date: Mon, 27 May 2024 09:51:24 +0700 Subject: [PATCH 06/12] update method mapping for pack --- contracts/feralfile-exhibition-v4_2/feralfile.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/contracts/feralfile-exhibition-v4_2/feralfile.go b/contracts/feralfile-exhibition-v4_2/feralfile.go index 2883b35..c43ffa7 100644 --- a/contracts/feralfile-exhibition-v4_2/feralfile.go +++ b/contracts/feralfile-exhibition-v4_2/feralfile.go @@ -230,7 +230,11 @@ func (c *FeralfileExhibitionV4_2Contract) Pack( return nil, err } - return abi.Pack(method, parsedArgs...) + mappedMethod := method + if method == "mintArtworks" { + mappedMethod = "mintArtworksWithIndex" + } + return abi.Pack(mappedMethod, parsedArgs...) } func (c *FeralfileExhibitionV4_2Contract) Parse( @@ -401,7 +405,7 @@ func (c *FeralfileExhibitionV4_2Contract) Parse( return nil, err } - return []interface{}{params.TokenID.Int, params.ImageURI, params.Paramters}, nil + return []interface{}{¶ms.TokenID.Int, params.ImageURI, params.Paramters}, nil default: return nil, fmt.Errorf("unsupported method") } From 6920e3a3487e13084353fd4175dc600d978c4cff Mon Sep 17 00:00:00 2001 From: hvthhien Date: Tue, 28 May 2024 15:14:46 +0700 Subject: [PATCH 07/12] update dependency --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 90861ad..b2c900c 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/bitmark-inc/account-vault-ethereum go 1.20 require ( - github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240524095144-3bd3a71417e9 + github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240528023335-544afe01e9f3 github.com/ethereum/go-ethereum v1.13.10 github.com/miguelmota/go-ethereum-hdwallet v0.1.1 github.com/stretchr/testify v1.8.4 diff --git a/go.sum b/go.sum index 8d2229e..96ee870 100644 --- a/go.sum +++ b/go.sum @@ -71,6 +71,8 @@ github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-202 github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240524032905-a9cb9b876fba/go.mod h1:shvtsuJyQJnByXKqf9n/jpjL4++FSJCFjXR/08iBnFY= github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240524095144-3bd3a71417e9 h1:GLVv5hYMmGwqQpJOasDz9kMhDyCpafKRK8J/khQs/fY= github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240524095144-3bd3a71417e9/go.mod h1:shvtsuJyQJnByXKqf9n/jpjL4++FSJCFjXR/08iBnFY= +github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240528023335-544afe01e9f3 h1:IrqDO0r3590aIVYOKlmE2OtSZRlhUGDSF4neCBFknaY= +github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240528023335-544afe01e9f3/go.mod h1:shvtsuJyQJnByXKqf9n/jpjL4++FSJCFjXR/08iBnFY= github.com/bits-and-blooms/bitset v1.10.0 h1:ePXTeiPEazB5+opbv5fr8umg2R/1NlzgDsyepwsSr88= github.com/bits-and-blooms/bitset v1.10.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c= From bc8c8abec8e2087d02cf55637d639c56f8d8f9e1 Mon Sep 17 00:00:00 2001 From: hvthhien Date: Wed, 29 May 2024 14:04:34 +0700 Subject: [PATCH 08/12] update contract v3_2 & deps --- contracts/feralfile-exhibition-v4_2/feralfile.go | 13 ++++++++----- go.mod | 2 +- go.sum | 12 ++---------- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/contracts/feralfile-exhibition-v4_2/feralfile.go b/contracts/feralfile-exhibition-v4_2/feralfile.go index c43ffa7..77c38a6 100644 --- a/contracts/feralfile-exhibition-v4_2/feralfile.go +++ b/contracts/feralfile-exhibition-v4_2/feralfile.go @@ -42,6 +42,7 @@ func (c *FeralfileExhibitionV4_2Contract) Deploy( IsBridgeable bool `json:"is_bridgeable"` SeriesIDs []*big.Int `json:"series_ids"` SeriesMaxSupplies []*big.Int `json:"series_max_supplies"` + ERC20Contract common.Address `json:"erc20_contract"` } if err := json.Unmarshal(arguments, ¶ms); err != nil { @@ -66,6 +67,7 @@ func (c *FeralfileExhibitionV4_2Contract) Deploy( params.ContractURI, params.SeriesIDs, params.SeriesMaxSupplies, + params.ERC20Contract, ) if err != nil { return "", "", err @@ -211,7 +213,7 @@ func (c *FeralfileExhibitionV4_2Contract) Call( return nil, errors.New("Invalid parameters") } - return contract.UpdateTokenInformation(t, params[0].(*big.Int), params[1].(string), params[2].([]byte)) + return contract.UpdateTokenInformation(t, params[0].(*big.Int), params[1].(string), params[2].([]byte), params[3].(*big.Int)) default: return nil, fmt.Errorf("unsupported method") } @@ -397,15 +399,16 @@ func (c *FeralfileExhibitionV4_2Contract) Parse( return []interface{}{params.AdvanceAddresses, advanceAmounts}, nil case "updateTokenInformation": var params struct { - TokenID ethereum.BigInt `json:"token_id"` - ImageURI string `json:"image_uri"` - Paramters []byte `json:"parameters"` + TokenID ethereum.BigInt `json:"token_id"` + ImageURI string `json:"image_uri"` + Paramters []byte `json:"parameters"` + CoinAmount ethereum.BigInt `json:"coin_amount"` } if err := json.Unmarshal(arguments, ¶ms); err != nil { return nil, err } - return []interface{}{¶ms.TokenID.Int, params.ImageURI, params.Paramters}, nil + return []interface{}{¶ms.TokenID.Int, params.ImageURI, params.Paramters, ¶ms.CoinAmount.Int}, nil default: return nil, fmt.Errorf("unsupported method") } diff --git a/go.mod b/go.mod index b2c900c..23ccdd1 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/bitmark-inc/account-vault-ethereum go 1.20 require ( - github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240528023335-544afe01e9f3 + github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240529042939-0b6972bb280b github.com/ethereum/go-ethereum v1.13.10 github.com/miguelmota/go-ethereum-hdwallet v0.1.1 github.com/stretchr/testify v1.8.4 diff --git a/go.sum b/go.sum index 96ee870..4edb89c 100644 --- a/go.sum +++ b/go.sum @@ -63,16 +63,8 @@ github.com/aws/smithy-go v1.1.0/go.mod h1:EzMw8dbp/YJL4A5/sbhGddag+NPT7q084agLbB github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= -github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240523083611-11a8480de376 h1:+Whj98ezo1eSt8OWl7qnWNIKdp2Xd5zWAEw+hS1wUhk= -github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240523083611-11a8480de376/go.mod h1:shvtsuJyQJnByXKqf9n/jpjL4++FSJCFjXR/08iBnFY= -github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240523090831-3bbdf4f223a1 h1:DDUWcIvqkpMPCvJqUskpPCmbY1kdfNysjjU18zRym40= -github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240523090831-3bbdf4f223a1/go.mod h1:shvtsuJyQJnByXKqf9n/jpjL4++FSJCFjXR/08iBnFY= -github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240524032905-a9cb9b876fba h1:DK0sqy5xmj8E01Vayt5FSCaDefrBmLUc3uNTLgp9sMc= -github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240524032905-a9cb9b876fba/go.mod h1:shvtsuJyQJnByXKqf9n/jpjL4++FSJCFjXR/08iBnFY= -github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240524095144-3bd3a71417e9 h1:GLVv5hYMmGwqQpJOasDz9kMhDyCpafKRK8J/khQs/fY= -github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240524095144-3bd3a71417e9/go.mod h1:shvtsuJyQJnByXKqf9n/jpjL4++FSJCFjXR/08iBnFY= -github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240528023335-544afe01e9f3 h1:IrqDO0r3590aIVYOKlmE2OtSZRlhUGDSF4neCBFknaY= -github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240528023335-544afe01e9f3/go.mod h1:shvtsuJyQJnByXKqf9n/jpjL4++FSJCFjXR/08iBnFY= +github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240529042939-0b6972bb280b h1:+8cGdcQknU4nX430a9qgBvgBH1oeUMsnD46ubszByx4= +github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240529042939-0b6972bb280b/go.mod h1:shvtsuJyQJnByXKqf9n/jpjL4++FSJCFjXR/08iBnFY= github.com/bits-and-blooms/bitset v1.10.0 h1:ePXTeiPEazB5+opbv5fr8umg2R/1NlzgDsyepwsSr88= github.com/bits-and-blooms/bitset v1.10.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c= From 613403211faa7537625455715687554782f6279f Mon Sep 17 00:00:00 2001 From: hvthhien Date: Fri, 31 May 2024 10:52:13 +0700 Subject: [PATCH 09/12] update parameters length --- contracts/feralfile-exhibition-v4_2/feralfile.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/feralfile-exhibition-v4_2/feralfile.go b/contracts/feralfile-exhibition-v4_2/feralfile.go index 77c38a6..383dd6e 100644 --- a/contracts/feralfile-exhibition-v4_2/feralfile.go +++ b/contracts/feralfile-exhibition-v4_2/feralfile.go @@ -209,7 +209,7 @@ func (c *FeralfileExhibitionV4_2Contract) Call( return contract.SetAdvanceSetting(t, params[0].([]common.Address), params[1].([]*big.Int)) case "updateTokenInformation": - if len(params) != 3 { + if len(params) != 4 { return nil, errors.New("Invalid parameters") } From d3edc085639d86ca60e2966c5ef7b74ca70a6d0c Mon Sep 17 00:00:00 2001 From: hvthhien Date: Thu, 6 Jun 2024 13:41:43 +0700 Subject: [PATCH 10/12] update buy artworks function --- .../feralfile-exhibition-v4_2/feralfile.go | 163 +++++++++++++----- go.mod | 2 +- go.sum | 4 +- 3 files changed, 119 insertions(+), 50 deletions(-) diff --git a/contracts/feralfile-exhibition-v4_2/feralfile.go b/contracts/feralfile-exhibition-v4_2/feralfile.go index 383dd6e..864641a 100644 --- a/contracts/feralfile-exhibition-v4_2/feralfile.go +++ b/contracts/feralfile-exhibition-v4_2/feralfile.go @@ -32,17 +32,17 @@ func (c *FeralfileExhibitionV4_2Contract) Deploy( wallet *ethereum.Wallet, arguments json.RawMessage) (string, string, error) { var params struct { - Name string `json:"name"` - Symbol string `json:"symbol"` - Signer common.Address `json:"signer"` - Vault common.Address `json:"vault"` - CostReceiver common.Address `json:"cost_receiver"` - ContractURI string `json:"contract_uri"` - IsBurnable bool `json:"is_burnable"` - IsBridgeable bool `json:"is_bridgeable"` - SeriesIDs []*big.Int `json:"series_ids"` - SeriesMaxSupplies []*big.Int `json:"series_max_supplies"` - ERC20Contract common.Address `json:"erc20_contract"` + Name string `json:"name"` + Symbol string `json:"symbol"` + Signer common.Address `json:"signer"` + Vault common.Address `json:"vault"` + CostReceiver common.Address `json:"cost_receiver"` + ContractURI string `json:"contract_uri"` + IsBurnable bool `json:"is_burnable"` + IsBridgeable bool `json:"is_bridgeable"` + SeriesIDs []*big.Int `json:"series_ids"` + SeriesMaxSupplies []*big.Int `json:"series_max_supplies"` + SeriesNextTokenIds []*big.Int `json:"series_next_token_ids"` } if err := json.Unmarshal(arguments, ¶ms); err != nil { @@ -67,7 +67,7 @@ func (c *FeralfileExhibitionV4_2Contract) Deploy( params.ContractURI, params.SeriesIDs, params.SeriesMaxSupplies, - params.ERC20Contract, + params.SeriesNextTokenIds, ) if err != nil { return "", "", err @@ -128,12 +128,12 @@ func (c *FeralfileExhibitionV4_2Contract) Call( return nil, errors.New("Invalid parameters") } - mintData, ok := params[0].([]feralfilev4.FeralfileExhibitionV42MintDataWithIndex) + mintData, ok := params[0].([]feralfilev4.FeralfileExhibitionV4MintData) if !ok { return nil, errors.New("Invalid token mint parameters") } - return contract.MintArtworksWithIndex(t, mintData) + return contract.MintArtworks(t, mintData) case "setTokenBaseURI": if len(params) != 1 { return nil, errors.New("Invalid parameters") @@ -184,6 +184,32 @@ func (c *FeralfileExhibitionV4_2Contract) Call( } return contract.BuyArtworks(t, r, s, v, saleData) + case "buyBulkArtworks": + if len(params) != 4 { + return nil, errors.New("Invalid parameters") + } + + r, ok := params[0].([32]byte) + if !ok { + return nil, fmt.Errorf("invalid r") + } + + s, ok := params[1].([32]byte) + if !ok { + return nil, fmt.Errorf("invalid s") + } + + v, ok := params[2].(uint8) + if !ok { + return nil, fmt.Errorf("invalid v") + } + + saleData, ok := params[3].(feralfilev4.IFeralfileSaleDataV2SaleDataV2) + if !ok { + return nil, fmt.Errorf("invalid sale data") + } + + return contract.BuyBulkArtworks(t, r, s, v, saleData) case "setApprovalForAll": if len(params) != 2 { return nil, errors.New("Invalid parameters") @@ -208,12 +234,6 @@ func (c *FeralfileExhibitionV4_2Contract) Call( } return contract.SetAdvanceSetting(t, params[0].([]common.Address), params[1].([]*big.Int)) - case "updateTokenInformation": - if len(params) != 4 { - return nil, errors.New("Invalid parameters") - } - - return contract.UpdateTokenInformation(t, params[0].(*big.Int), params[1].(string), params[2].([]byte), params[3].(*big.Int)) default: return nil, fmt.Errorf("unsupported method") } @@ -232,11 +252,7 @@ func (c *FeralfileExhibitionV4_2Contract) Pack( return nil, err } - mappedMethod := method - if method == "mintArtworks" { - mappedMethod = "mintArtworksWithIndex" - } - return abi.Pack(mappedMethod, parsedArgs...) + return abi.Pack(method, parsedArgs...) } func (c *FeralfileExhibitionV4_2Contract) Parse( @@ -263,10 +279,9 @@ func (c *FeralfileExhibitionV4_2Contract) Parse( return []interface{}{tokenIDs}, nil case "mintArtworks": var params []struct { - SeriesID ethereum.BigInt `json:"series_id"` - TokenID ethereum.BigInt `json:"token_id"` - Owner common.Address `json:"owner"` - TokenIndex ethereum.BigInt `json:"token_index"` + SeriesID ethereum.BigInt `json:"series_id"` + TokenID ethereum.BigInt `json:"token_id"` + Owner common.Address `json:"owner"` } if err := json.Unmarshal(arguments, ¶ms); err != nil { return nil, err @@ -275,13 +290,12 @@ func (c *FeralfileExhibitionV4_2Contract) Parse( return nil, errors.New("Invalid token mint parameters") } - mintData := make([]feralfilev4.FeralfileExhibitionV42MintDataWithIndex, len(params)) + mintData := make([]feralfilev4.FeralfileExhibitionV4MintData, len(params)) for i := 0; i < len(params); i++ { - mintData[i] = feralfilev4.FeralfileExhibitionV42MintDataWithIndex{ - SeriesId: ¶ms[i].SeriesID.Int, - TokenId: ¶ms[i].TokenID.Int, - Owner: params[i].Owner, - TokenIndex: ¶ms[i].TokenIndex.Int, + mintData[i] = feralfilev4.FeralfileExhibitionV4MintData{ + SeriesId: ¶ms[i].SeriesID.Int, + TokenId: ¶ms[i].TokenID.Int, + Owner: params[i].Owner, } } @@ -380,6 +394,73 @@ func (c *FeralfileExhibitionV4_2Contract) Parse( PayByVaultContract: params.SaleData.PayByVaultContract, } + return []interface{}{r32Val, s32Val, uint8(vVal), saleData}, nil + case "buyBulkArtworks": + var params struct { + SaleData struct { + Price ethereum.BigInt `json:"price"` + Cost ethereum.BigInt `json:"cost"` + ExpiryTime ethereum.BigInt `json:"expiryTime"` + Destination common.Address `json:"destination"` + Nonce ethereum.BigInt `json:"nonce"` + SeriesID ethereum.BigInt `json:"seriesId"` + Quantity uint16 `json:"quantity"` + RevenueShares []struct { + Recipient common.Address `json:"recipient"` + Bps ethereum.BigInt `json:"bps"` + } `json:"revenueShares"` + PayByVaultContract bool `json:"payByVaultContract"` + } `json:"saleData"` + R string `json:"r"` + S string `json:"s"` + V string `json:"v"` + } + + if err := json.Unmarshal(arguments, ¶ms); err != nil { + return nil, err + } + + rVal, err := hex.DecodeString(strings.Replace(params.R, "0x", "", -1)) + if err != nil { + return nil, err + } + sVal, err := hex.DecodeString(strings.Replace(params.S, "0x", "", -1)) + if err != nil { + return nil, err + } + vVal, err := strconv.ParseUint(strings.Replace(params.V, "0x", "", -1), 16, 64) + if err != nil { + return nil, err + } + if len(rVal) != 32 || len(sVal) != 32 { + return nil, errors.New("required signature length is 32") + } + var r32Val [32]byte + var s32Val [32]byte + copy(r32Val[:], rVal) + copy(s32Val[:], sVal) + + revenueShares := make([]feralfilev4.IFeralfileSaleDataRevenueShare, 0) + for _, v := range params.SaleData.RevenueShares { + bps := v.Bps.Int + revenueShares = append(revenueShares, feralfilev4.IFeralfileSaleDataRevenueShare{ + Recipient: v.Recipient, + Bps: &bps, + }) + } + + saleData := feralfilev4.IFeralfileSaleDataV2SaleDataV2{ + Price: ¶ms.SaleData.Price.Int, + Cost: ¶ms.SaleData.Cost.Int, + ExpiryTime: ¶ms.SaleData.ExpiryTime.Int, + Destination: params.SaleData.Destination, + Nonce: ¶ms.SaleData.Nonce.Int, + SeriesID: ¶ms.SaleData.SeriesID.Int, + Quantity: params.SaleData.Quantity, + RevenueShares: revenueShares, + PayByVaultContract: params.SaleData.PayByVaultContract, + } + return []interface{}{r32Val, s32Val, uint8(vVal), saleData}, nil case "setAdvanceSetting": var params struct { @@ -397,18 +478,6 @@ func (c *FeralfileExhibitionV4_2Contract) Parse( } return []interface{}{params.AdvanceAddresses, advanceAmounts}, nil - case "updateTokenInformation": - var params struct { - TokenID ethereum.BigInt `json:"token_id"` - ImageURI string `json:"image_uri"` - Paramters []byte `json:"parameters"` - CoinAmount ethereum.BigInt `json:"coin_amount"` - } - if err := json.Unmarshal(arguments, ¶ms); err != nil { - return nil, err - } - - return []interface{}{¶ms.TokenID.Int, params.ImageURI, params.Paramters, ¶ms.CoinAmount.Int}, nil default: return nil, fmt.Errorf("unsupported method") } diff --git a/go.mod b/go.mod index 23ccdd1..2f50f02 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/bitmark-inc/account-vault-ethereum go 1.20 require ( - github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240529042939-0b6972bb280b + github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240607014320-77c7b7083b21 github.com/ethereum/go-ethereum v1.13.10 github.com/miguelmota/go-ethereum-hdwallet v0.1.1 github.com/stretchr/testify v1.8.4 diff --git a/go.sum b/go.sum index 4edb89c..0f11c79 100644 --- a/go.sum +++ b/go.sum @@ -63,8 +63,8 @@ github.com/aws/smithy-go v1.1.0/go.mod h1:EzMw8dbp/YJL4A5/sbhGddag+NPT7q084agLbB github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= -github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240529042939-0b6972bb280b h1:+8cGdcQknU4nX430a9qgBvgBH1oeUMsnD46ubszByx4= -github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240529042939-0b6972bb280b/go.mod h1:shvtsuJyQJnByXKqf9n/jpjL4++FSJCFjXR/08iBnFY= +github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240607014320-77c7b7083b21 h1:XzdTNI5E5PUcMpSzZM72vbTSqHizH/TldfNiu76frII= +github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240607014320-77c7b7083b21/go.mod h1:shvtsuJyQJnByXKqf9n/jpjL4++FSJCFjXR/08iBnFY= github.com/bits-and-blooms/bitset v1.10.0 h1:ePXTeiPEazB5+opbv5fr8umg2R/1NlzgDsyepwsSr88= github.com/bits-and-blooms/bitset v1.10.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c= From ef0c53b3c3da7f99f083b9f666dad7d8a4de82c5 Mon Sep 17 00:00:00 2001 From: hvthhien Date: Mon, 17 Jun 2024 10:50:27 +0700 Subject: [PATCH 11/12] update deps --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 2f50f02..8ab3772 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/bitmark-inc/account-vault-ethereum go 1.20 require ( - github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240607014320-77c7b7083b21 + github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240614091658-dbebe04cccb7 github.com/ethereum/go-ethereum v1.13.10 github.com/miguelmota/go-ethereum-hdwallet v0.1.1 github.com/stretchr/testify v1.8.4 diff --git a/go.sum b/go.sum index 0f11c79..afe5ec6 100644 --- a/go.sum +++ b/go.sum @@ -63,8 +63,8 @@ github.com/aws/smithy-go v1.1.0/go.mod h1:EzMw8dbp/YJL4A5/sbhGddag+NPT7q084agLbB github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= -github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240607014320-77c7b7083b21 h1:XzdTNI5E5PUcMpSzZM72vbTSqHizH/TldfNiu76frII= -github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240607014320-77c7b7083b21/go.mod h1:shvtsuJyQJnByXKqf9n/jpjL4++FSJCFjXR/08iBnFY= +github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240614091658-dbebe04cccb7 h1:6tuC/1cXXRWopf8NSOOOvG6IGNSp6SHLMbvrYNoHx/k= +github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240614091658-dbebe04cccb7/go.mod h1:shvtsuJyQJnByXKqf9n/jpjL4++FSJCFjXR/08iBnFY= github.com/bits-and-blooms/bitset v1.10.0 h1:ePXTeiPEazB5+opbv5fr8umg2R/1NlzgDsyepwsSr88= github.com/bits-and-blooms/bitset v1.10.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c= From d02d0a43e523fb777e1bdcb3545ad06c9a959ade Mon Sep 17 00:00:00 2001 From: hvthhien Date: Mon, 17 Jun 2024 15:33:52 +0700 Subject: [PATCH 12/12] remove buy artwork func from v4_2 --- .../feralfile-exhibition-v4_2/feralfile.go | 99 ------------------- go.mod | 2 +- go.sum | 4 +- 3 files changed, 3 insertions(+), 102 deletions(-) diff --git a/contracts/feralfile-exhibition-v4_2/feralfile.go b/contracts/feralfile-exhibition-v4_2/feralfile.go index 864641a..eba34a4 100644 --- a/contracts/feralfile-exhibition-v4_2/feralfile.go +++ b/contracts/feralfile-exhibition-v4_2/feralfile.go @@ -158,32 +158,6 @@ func (c *FeralfileExhibitionV4_2Contract) Call( } return contract.TransferOwnership(t, newOwner) - case "buyArtworks": - if len(params) != 4 { - return nil, errors.New("Invalid parameters") - } - - r, ok := params[0].([32]byte) - if !ok { - return nil, fmt.Errorf("invalid r") - } - - s, ok := params[1].([32]byte) - if !ok { - return nil, fmt.Errorf("invalid s") - } - - v, ok := params[2].(uint8) - if !ok { - return nil, fmt.Errorf("invalid v") - } - - saleData, ok := params[3].(feralfilev4.IFeralfileSaleDataSaleData) - if !ok { - return nil, fmt.Errorf("invalid sale data") - } - - return contract.BuyArtworks(t, r, s, v, saleData) case "buyBulkArtworks": if len(params) != 4 { return nil, errors.New("Invalid parameters") @@ -322,79 +296,6 @@ func (c *FeralfileExhibitionV4_2Contract) Parse( } return []interface{}{params.Operator, params.Approved}, nil - case "buyArtworks": - var params struct { - SaleData struct { - Price ethereum.BigInt `json:"price"` - Cost ethereum.BigInt `json:"cost"` - ExpiryTime ethereum.BigInt `json:"expiryTime"` - Destination common.Address `json:"destination"` - TokenIds []ethereum.BigInt `json:"tokenIds"` - RevenueShares [][]struct { - Recipient common.Address `json:"recipient"` - Bps ethereum.BigInt `json:"bps"` - } `json:"revenueShares"` - PayByVaultContract bool `json:"payByVaultContract"` - } `json:"saleData"` - R string `json:"r"` - S string `json:"s"` - V string `json:"v"` - } - - if err := json.Unmarshal(arguments, ¶ms); err != nil { - return nil, err - } - - rVal, err := hex.DecodeString(strings.Replace(params.R, "0x", "", -1)) - if err != nil { - return nil, err - } - sVal, err := hex.DecodeString(strings.Replace(params.S, "0x", "", -1)) - if err != nil { - return nil, err - } - vVal, err := strconv.ParseUint(strings.Replace(params.V, "0x", "", -1), 16, 64) - if err != nil { - return nil, err - } - if len(rVal) != 32 || len(sVal) != 32 { - return nil, errors.New("required signature length is 32") - } - var r32Val [32]byte - var s32Val [32]byte - copy(r32Val[:], rVal) - copy(s32Val[:], sVal) - - tokenIDs := make([]*big.Int, 0) - for _, v := range params.SaleData.TokenIds { - tokenID := v.Int - tokenIDs = append(tokenIDs, &tokenID) - } - - revenueShares := make([][]feralfilev4.IFeralfileSaleDataRevenueShare, 0) - for _, v := range params.SaleData.RevenueShares { - revenueShare := make([]feralfilev4.IFeralfileSaleDataRevenueShare, 0) - for _, vv := range v { - bps := vv.Bps.Int - revenueShare = append(revenueShare, feralfilev4.IFeralfileSaleDataRevenueShare{ - Recipient: vv.Recipient, - Bps: &bps, - }) - } - revenueShares = append(revenueShares, revenueShare) - } - - saleData := feralfilev4.IFeralfileSaleDataSaleData{ - Price: ¶ms.SaleData.Price.Int, - Cost: ¶ms.SaleData.Cost.Int, - ExpiryTime: ¶ms.SaleData.ExpiryTime.Int, - Destination: params.SaleData.Destination, - TokenIds: tokenIDs, - RevenueShares: revenueShares, - PayByVaultContract: params.SaleData.PayByVaultContract, - } - - return []interface{}{r32Val, s32Val, uint8(vVal), saleData}, nil case "buyBulkArtworks": var params struct { SaleData struct { diff --git a/go.mod b/go.mod index 8ab3772..408b457 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/bitmark-inc/account-vault-ethereum go 1.20 require ( - github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240614091658-dbebe04cccb7 + github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240617045334-b5d26d3a3dec github.com/ethereum/go-ethereum v1.13.10 github.com/miguelmota/go-ethereum-hdwallet v0.1.1 github.com/stretchr/testify v1.8.4 diff --git a/go.sum b/go.sum index afe5ec6..737545b 100644 --- a/go.sum +++ b/go.sum @@ -63,8 +63,8 @@ github.com/aws/smithy-go v1.1.0/go.mod h1:EzMw8dbp/YJL4A5/sbhGddag+NPT7q084agLbB github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= -github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240614091658-dbebe04cccb7 h1:6tuC/1cXXRWopf8NSOOOvG6IGNSp6SHLMbvrYNoHx/k= -github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240614091658-dbebe04cccb7/go.mod h1:shvtsuJyQJnByXKqf9n/jpjL4++FSJCFjXR/08iBnFY= +github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240617045334-b5d26d3a3dec h1:XlRCTNovfqBGhXDVqsuiCLtSoDF4qQszXRdjimicw04= +github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240617045334-b5d26d3a3dec/go.mod h1:shvtsuJyQJnByXKqf9n/jpjL4++FSJCFjXR/08iBnFY= github.com/bits-and-blooms/bitset v1.10.0 h1:ePXTeiPEazB5+opbv5fr8umg2R/1NlzgDsyepwsSr88= github.com/bits-and-blooms/bitset v1.10.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c=