Skip to content
Open
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

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions contracts/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
seqsale721v0 "github.com/0xsequence/go-sequence/contracts/gen/seq_sale/erc721v0"
"github.com/0xsequence/go-sequence/contracts/gen/supply"
"github.com/0xsequence/go-sequence/contracts/gen/tokens"
trailsutils "github.com/0xsequence/go-sequence/contracts/gen/trailsutils"
v1Factory "github.com/0xsequence/go-sequence/contracts/gen/v1/walletfactory"
v1Estimator "github.com/0xsequence/go-sequence/contracts/gen/v1/walletgasestimator"
v1Guest "github.com/0xsequence/go-sequence/contracts/gen/v1/walletguest"
Expand All @@ -43,6 +44,7 @@ var GasEstimator,
IERC1271,
ISapient,
ISapientCompact,
TrailsUtils,
ERC20Mock,
IERC20,
IERC721,
Expand Down Expand Up @@ -131,6 +133,7 @@ func init() {
IERC1271 = artifact("IERC1271", ierc1271.IERC1271ABI, "")
ISapient = artifact("ISapient", isapient.ISapientABI, "")
ISapientCompact = artifact("ISapientCompact", isapient.ISapientCompactABI, "")
TrailsUtils = artifact("TRAILS_UTILS", trailsutils.TrailsUtilsABI, trailsutils.TrailsUtilsBin)

IERC20 = artifact("IERC20", tokens.IERC20ABI, "")
IERC721 = artifact("IERC721", tokens.IERC721ABI, "")
Expand Down
5 changes: 5 additions & 0 deletions contracts/gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@
//go:generate go run github.com/0xsequence/ethkit/cmd/ethkit abigen --pkg=isapient --type=ISapient --outFile=./isapient/isapient.gen.go --artifactsFile=../artifacts/wallet-contracts-v3/ISapient.sol/ISapient.json
//go:generate go run github.com/0xsequence/ethkit/cmd/ethkit abigen --pkg=isapient --type=ISapientCompact --outFile=./isapient/isapientcompact.gen.go --artifactsFile=../artifacts/wallet-contracts-v3/ISapient.sol/ISapientCompact.json

//
// trails
//
//go:generate go run github.com/0xsequence/ethkit/cmd/ethkit abigen --pkg=trailsutils --type=TrailsUtils --outFile=./trailsutils/trails_utils.gen.go --artifactsFile=../artifacts/trails-contracts/TrailsUtils.sol/TrailsUtils.json

//
// sequence marketplace
//
Expand Down
1,784 changes: 1,784 additions & 0 deletions contracts/gen/trailsutils/trails_utils.gen.go

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions go.work.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 31 additions & 57 deletions intent_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,15 @@ func CreateAnyAddressSubdigestTree(calls []*v3.CallsPayload) ([]v3.WalletConfigT

// `CreateIntentTree` creates a tree from a list of intent operations and a main signer address.
func CreateIntentTree(mainSigner common.Address, calls []*v3.CallsPayload, sapientSignerLeafNode v3.WalletConfigTree) (*v3.WalletConfigTree, error) {
// Create the subdigest leaves from the batched transactions.
leaves, err := CreateAnyAddressSubdigestTree(calls)
if err != nil {
return nil, err
var leaves []v3.WalletConfigTree

if len(calls) > 0 {
// Create the subdigest leaves from the batched transactions.
subdigestLeaves, err := CreateAnyAddressSubdigestTree(calls)
if err != nil {
return nil, err
}
leaves = append(leaves, subdigestLeaves...)
}

// If the sapient signer leaf is not nil, add it to the leaves.
Expand All @@ -205,6 +210,10 @@ func CreateIntentTree(mainSigner common.Address, calls []*v3.CallsPayload, sapie
Address: mainSigner,
}

if len(leaves) == 0 {
return nil, fmt.Errorf("no leaves to create tree from")
}

// If the length of the leaves is 1
if len(leaves) == 1 {
tree := v3.WalletConfigTreeNodes(mainSignerLeaf, leaves[0])
Expand All @@ -221,7 +230,7 @@ func CreateIntentTree(mainSigner common.Address, calls []*v3.CallsPayload, sapie
}

// `CreateIntentConfiguration` creates a wallet configuration where the intent's transaction batches are grouped into the initial subdigest.
func CreateIntentConfiguration(mainSigner common.Address, calls []*v3.CallsPayload, sapientSignerLeafNode v3.WalletConfigTree) (*v3.WalletConfig, error) {
func CreateIntentConfiguration(mainSigner common.Address, calls []*v3.CallsPayload, sapientSignerLeafNode v3.WalletConfigTree, checkpoint uint64) (*v3.WalletConfig, error) {
// Create the subdigest leaves from the batched transactions.
tree, err := CreateIntentTree(mainSigner, calls, sapientSignerLeafNode)
if err != nil {
Expand All @@ -231,37 +240,41 @@ func CreateIntentConfiguration(mainSigner common.Address, calls []*v3.CallsPaylo
// Construct the new wallet config using:
config := &v3.WalletConfig{
Threshold_: 1,
Checkpoint_: 0,
Checkpoint_: checkpoint,
Tree: *tree,
}

return config, nil
}

type SignerSignature struct {
Address common.Address
Signature []byte
Type core.SignerSignatureType
}

// `GetIntentConfigurationSignature` creates a signature for the intent configuration that can be used to bypass chain ID validation.
// The signature is based on the transaction bundle digests only.
// `SignerSignatures` can be nil when executing a preapproved static payload.
func GetIntentConfigurationSignature(
mainSigner common.Address,
calls []*v3.CallsPayload,
ctx context.Context,
config *v3.WalletConfig,
signerSignatures []*SignerSignature,
) ([]byte, error) {
// Default case without any sapient signer
config, err := CreateIntentConfiguration(mainSigner, calls, nil)
if err != nil {
return nil, err
}

// spew.Dump(config)
// spew.Dump(config.Tree)

signingFunc := func(ctx context.Context, signer core.Signer, _ []core.SignerSignature) (core.SignerSignatureType, []byte, error) {
// For mainSigner or other signers, we don't provide a signature here.
// This will result in an AddressLeaf or NodeLeaf in the signature tree.
for _, signerSignature := range signerSignatures {
if signer.Address == signerSignature.Address {
return signerSignature.Type, signerSignature.Signature, nil
}
}
return 0, nil, nil
}

// Build the signature using BuildNoChainIDSignature, which allows us to inject custom signatures via SigningFunction.
// Set validateSigningPower to false, as we are not necessarily providing signatures for all parts of the config.
sig, err := config.BuildRegularSignature(context.Background(), signingFunc, false)
sig, err := config.BuildRegularSignature(ctx, signingFunc, false)
if err != nil {
return nil, fmt.Errorf("failed to build regular signature: %w", err)
}
Expand Down Expand Up @@ -301,42 +314,3 @@ func GetIntentConfigurationSignature(

return data, nil
}

// // replaceSapientSignerWithNodeInConfigTree recursively traverses the WalletConfigTree.
// func replaceSapientSignerWithNodeInConfigTree(tree v3.WalletConfigTree) v3.WalletConfigTree {
// if tree == nil {
// return nil
// }

// switch node := tree.(type) {
// case *v3.WalletConfigTreeNode:
// // Recursively call on left and right children
// left := replaceSapientSignerWithNodeInConfigTree(node.Left)
// right := replaceSapientSignerWithNodeInConfigTree(node.Right)

// if left == node.Left && right == node.Right {
// return node
// }
// return &v3.WalletConfigTreeNode{Left: left, Right: right}

// case *v3.WalletConfigTreeNestedLeaf:
// // Recursively call on the inner tree
// innerTree := replaceSapientSignerWithNodeInConfigTree(node.Tree)

// if innerTree == node.Tree { // Check for pointer equality
// return node // No change, return original
// }
// return &v3.WalletConfigTreeNestedLeaf{
// Weight: node.Weight,
// Threshold: node.Threshold,
// Tree: innerTree,
// }

// case *v3.WalletConfigTreeSapientSignerLeaf:
// // This is the target node type to replace
// return &v3.WalletConfigTreeNodeLeaf{Node: node.ImageHash()}

// default:
// return tree
// }
// }
Loading
Loading