Skip to content

Commit ecab97c

Browse files
committed
Update Trails to use TrailsUtils configuration
1 parent eedaece commit ecab97c

11 files changed

Lines changed: 1613 additions & 161 deletions

File tree

contracts/artifacts/trails-contracts/TrailsUtils.sol/TrailsUtils.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

contracts/contracts.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
seqsale721v0 "github.com/0xsequence/go-sequence/contracts/gen/seq_sale/erc721v0"
1919
"github.com/0xsequence/go-sequence/contracts/gen/supply"
2020
"github.com/0xsequence/go-sequence/contracts/gen/tokens"
21+
trailsutils "github.com/0xsequence/go-sequence/contracts/gen/trailsutils"
2122
v1Factory "github.com/0xsequence/go-sequence/contracts/gen/v1/walletfactory"
2223
v1Estimator "github.com/0xsequence/go-sequence/contracts/gen/v1/walletgasestimator"
2324
v1Guest "github.com/0xsequence/go-sequence/contracts/gen/v1/walletguest"
@@ -43,6 +44,7 @@ var GasEstimator,
4344
IERC1271,
4445
ISapient,
4546
ISapientCompact,
47+
TrailsUtils,
4648
ERC20Mock,
4749
IERC20,
4850
IERC721,
@@ -131,6 +133,7 @@ func init() {
131133
IERC1271 = artifact("IERC1271", ierc1271.IERC1271ABI, "")
132134
ISapient = artifact("ISapient", isapient.ISapientABI, "")
133135
ISapientCompact = artifact("ISapientCompact", isapient.ISapientCompactABI, "")
136+
TrailsUtils = artifact("TRAILS_UTILS", trailsutils.TrailsUtilsABI, trailsutils.TrailsUtilsBin)
134137

135138
IERC20 = artifact("IERC20", tokens.IERC20ABI, "")
136139
IERC721 = artifact("IERC721", tokens.IERC721ABI, "")

contracts/gen/gen.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@
7676
//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
7777
//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
7878

79+
//
80+
// trails
81+
//
82+
//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
83+
7984
//
8085
// sequence marketplace
8186
//

contracts/gen/trailsutils/trails_utils.gen.go

Lines changed: 1340 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.work.sum

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

intent_config.go

Lines changed: 31 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,15 @@ func CreateAnyAddressSubdigestTree(calls []*v3.CallsPayload) ([]v3.WalletConfigT
188188

189189
// `CreateIntentTree` creates a tree from a list of intent operations and a main signer address.
190190
func CreateIntentTree(mainSigner common.Address, calls []*v3.CallsPayload, sapientSignerLeafNode v3.WalletConfigTree) (*v3.WalletConfigTree, error) {
191-
// Create the subdigest leaves from the batched transactions.
192-
leaves, err := CreateAnyAddressSubdigestTree(calls)
193-
if err != nil {
194-
return nil, err
191+
var leaves []v3.WalletConfigTree
192+
193+
if len(calls) > 0 {
194+
// Create the subdigest leaves from the batched transactions.
195+
subdigestLeaves, err := CreateAnyAddressSubdigestTree(calls)
196+
if err != nil {
197+
return nil, err
198+
}
199+
leaves = append(leaves, subdigestLeaves...)
195200
}
196201

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

213+
if len(leaves) == 0 {
214+
return nil, fmt.Errorf("no leaves to create tree from")
215+
}
216+
208217
// If the length of the leaves is 1
209218
if len(leaves) == 1 {
210219
tree := v3.WalletConfigTreeNodes(mainSignerLeaf, leaves[0])
@@ -221,7 +230,7 @@ func CreateIntentTree(mainSigner common.Address, calls []*v3.CallsPayload, sapie
221230
}
222231

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

238247
return config, nil
239248
}
240249

250+
type SignerSignature struct {
251+
Address common.Address
252+
Signature []byte
253+
Type core.SignerSignatureType
254+
}
255+
241256
// `GetIntentConfigurationSignature` creates a signature for the intent configuration that can be used to bypass chain ID validation.
242-
// The signature is based on the transaction bundle digests only.
257+
// `SignerSignatures` can be nil when executing a preapproved static payload.
243258
func GetIntentConfigurationSignature(
244-
mainSigner common.Address,
245-
calls []*v3.CallsPayload,
259+
ctx context.Context,
260+
config *v3.WalletConfig,
261+
signerSignatures []*SignerSignature,
246262
) ([]byte, error) {
247-
// Default case without any sapient signer
248-
config, err := CreateIntentConfiguration(mainSigner, calls, nil)
249-
if err != nil {
250-
return nil, err
251-
}
252-
253263
// spew.Dump(config)
254264
// spew.Dump(config.Tree)
255265

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

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

302315
return data, nil
303316
}
304-
305-
// // replaceSapientSignerWithNodeInConfigTree recursively traverses the WalletConfigTree.
306-
// func replaceSapientSignerWithNodeInConfigTree(tree v3.WalletConfigTree) v3.WalletConfigTree {
307-
// if tree == nil {
308-
// return nil
309-
// }
310-
311-
// switch node := tree.(type) {
312-
// case *v3.WalletConfigTreeNode:
313-
// // Recursively call on left and right children
314-
// left := replaceSapientSignerWithNodeInConfigTree(node.Left)
315-
// right := replaceSapientSignerWithNodeInConfigTree(node.Right)
316-
317-
// if left == node.Left && right == node.Right {
318-
// return node
319-
// }
320-
// return &v3.WalletConfigTreeNode{Left: left, Right: right}
321-
322-
// case *v3.WalletConfigTreeNestedLeaf:
323-
// // Recursively call on the inner tree
324-
// innerTree := replaceSapientSignerWithNodeInConfigTree(node.Tree)
325-
326-
// if innerTree == node.Tree { // Check for pointer equality
327-
// return node // No change, return original
328-
// }
329-
// return &v3.WalletConfigTreeNestedLeaf{
330-
// Weight: node.Weight,
331-
// Threshold: node.Threshold,
332-
// Tree: innerTree,
333-
// }
334-
335-
// case *v3.WalletConfigTreeSapientSignerLeaf:
336-
// // This is the target node type to replace
337-
// return &v3.WalletConfigTreeNodeLeaf{Node: node.ImageHash()}
338-
339-
// default:
340-
// return tree
341-
// }
342-
// }

0 commit comments

Comments
 (0)