Skip to content

Commit 3101170

Browse files
authored
Function closures for CCIP token pool hooks (#320)
* Dynamic dispatch support for CCIP Receiver contracts * Use Function closures for token pool lock/burn release/mint hooks * Update CCIP to handle v1 and v2 ccip receiver registration dispatch * Add V1 V2 Compatibility tests using function closures * Formatting move files * Multiple token transfer test * Remove duplicate onramp call check, slight refactor * Clean up register pool, refactor * Add PTT CCIP Receiver * Remove `_proof` in V2 CCIP Receiver registry * Add missing deployer address in ccip dummy receiver bindings * PTT receiver to be consistent with dummy receiver * Remove proof from pool registration. * receiver_registered_v2_events rename * Add persistent callbacks
1 parent 3b906fb commit 3101170

44 files changed

Lines changed: 5789 additions & 162 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bindings/ccip/receiver_registry/receiver_registry.go

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

bindings/ccip/token_admin_registry/token_admin_registry.go

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

bindings/ccip_dummy_receiver/ccip_dummy_receiver.go

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/smartcontractkit/chainlink-aptos/bindings/bind"
88
module_dummy_receiver "github.com/smartcontractkit/chainlink-aptos/bindings/ccip_dummy_receiver/dummy_receiver"
9+
module_ptt_dummy_receiver "github.com/smartcontractkit/chainlink-aptos/bindings/ccip_dummy_receiver/ptt_dummy_receiver"
910
"github.com/smartcontractkit/chainlink-aptos/bindings/compile"
1011
"github.com/smartcontractkit/chainlink-aptos/contracts"
1112
)
@@ -14,14 +15,16 @@ type CCIPDummyReceiver interface {
1415
Address() aptos.AccountAddress
1516

1617
DummyReceiver() module_dummy_receiver.DummyReceiverInterface
18+
PTTDummyReceiver() module_ptt_dummy_receiver.PttDummyReceiverInterface
1719
}
1820

1921
var _ CCIPDummyReceiver = CCIPDummyReceiverContract{}
2022

2123
type CCIPDummyReceiverContract struct {
2224
address aptos.AccountAddress
2325

24-
dummyReceiver module_dummy_receiver.DummyReceiverInterface
26+
dummyReceiver module_dummy_receiver.DummyReceiverInterface
27+
pttDummyReceiver module_ptt_dummy_receiver.PttDummyReceiverInterface
2528
}
2629

2730
func (C CCIPDummyReceiverContract) Address() aptos.AccountAddress {
@@ -32,30 +35,44 @@ func (C CCIPDummyReceiverContract) DummyReceiver() module_dummy_receiver.DummyRe
3235
return C.dummyReceiver
3336
}
3437

38+
func (C CCIPDummyReceiverContract) PTTDummyReceiver() module_ptt_dummy_receiver.PttDummyReceiverInterface {
39+
return C.pttDummyReceiver
40+
}
41+
3542
var FunctionInfo = bind.MustParseFunctionInfo(
3643
module_dummy_receiver.FunctionInfo,
44+
module_ptt_dummy_receiver.FunctionInfo,
3745
)
3846

39-
func Compile(address aptos.AccountAddress, ccipAddress aptos.AccountAddress, mcmsAddress aptos.AccountAddress) (compile.CompiledPackage, error) {
47+
func Compile(address aptos.AccountAddress, ccipAddress aptos.AccountAddress, mcmsAddress aptos.AccountAddress, deployer aptos.AccountAddress) (compile.CompiledPackage, error) {
4048
namedAddresses := map[string]aptos.AccountAddress{
4149
"ccip_dummy_receiver": address,
4250
"ccip": ccipAddress,
4351
"mcms": mcmsAddress,
4452
"mcms_register_entrypoints": aptos.AccountZero,
53+
"deployer": deployer,
4554
}
4655
// Compile using CLI
4756
return compile.CompilePackage(contracts.CCIPDummyReceiver, namedAddresses)
4857
}
4958

5059
func Bind(address aptos.AccountAddress, client aptos.AptosRpcClient) CCIPDummyReceiver {
5160
return CCIPDummyReceiverContract{
52-
address: address,
53-
dummyReceiver: module_dummy_receiver.NewDummyReceiver(address, client),
61+
address: address,
62+
dummyReceiver: module_dummy_receiver.NewDummyReceiver(address, client),
63+
pttDummyReceiver: module_ptt_dummy_receiver.NewPttDummyReceiver(address, client),
5464
}
5565
}
5666

67+
const (
68+
DefaultSeed = "chainlink_ccip_dummy_receiver"
69+
)
70+
5771
// DeployToObject deploys the dummmy receiver contract to a new named object.
5872
// The resulting address will be calculated using the deployer's account address and the next sequence number
73+
//
74+
// NOTE: This deployment method will NOT work with ptt_dummy_receiver module as it requires resource account.
75+
// Use DeployToResourceAccount if you need PTT functionality.
5976
func DeployToObject(
6077
auth aptos.TransactionSigner,
6178
client aptos.AptosRpcClient,
@@ -66,10 +83,38 @@ func DeployToObject(
6683
"ccip": ccipAddress,
6784
"mcms": mcmsAddress,
6885
"mcms_register_entrypoints": aptos.AccountZero,
86+
"deployer": auth.AccountAddress(), // Required for compilation, but ptt_dummy_receiver won't work with object deployment
6987
}
7088
address, tx, err := bind.DeployPackageToObject(auth, client, contracts.CCIPDummyReceiver, namedAddresses)
7189
if err != nil {
7290
return aptos.AccountAddress{}, nil, nil, err
7391
}
7492
return address, tx, Bind(address, client), nil
7593
}
94+
95+
// DeployToResourceAccount deploys the dummy receiver contract to a new resource account.
96+
// The address of that resource account is determined by the deployer account + an optional seed.
97+
// If no seed is provided, the default seed DefaultSeed is used.
98+
func DeployToResourceAccount(
99+
auth aptos.TransactionSigner,
100+
client aptos.AptosRpcClient,
101+
ccipAddress,
102+
mcmsAddress aptos.AccountAddress,
103+
seed ...string,
104+
) (aptos.AccountAddress, *api.PendingTransaction, CCIPDummyReceiver, error) {
105+
dummyReceiverSeed := DefaultSeed
106+
if len(seed) > 0 {
107+
dummyReceiverSeed = seed[0]
108+
}
109+
namedAddresses := map[string]aptos.AccountAddress{
110+
"ccip": ccipAddress,
111+
"mcms": mcmsAddress,
112+
"mcms_register_entrypoints": aptos.AccountZero,
113+
"deployer": auth.AccountAddress(), // Origin account where Container is stored
114+
}
115+
address, tx, err := bind.DeployPackageToResourceAccount(auth, client, contracts.CCIPDummyReceiver, dummyReceiverSeed, namedAddresses)
116+
if err != nil {
117+
return aptos.AccountAddress{}, nil, nil, err
118+
}
119+
return address, tx, Bind(address, client), nil
120+
}

bindings/ccip_dummy_receiver/ccip_dummy_receiver_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
func TestCompile(t *testing.T) {
1111
t.Parallel()
12-
output, err := Compile(aptos.AccountOne, aptos.AccountOne, aptos.AccountThree)
12+
output, err := Compile(aptos.AccountOne, aptos.AccountOne, aptos.AccountThree, aptos.AccountFour)
1313
require.NoError(t, err)
1414
require.NotZero(t, output.Metadata, "Compilation resulted in no metadata")
1515
require.NotZero(t, output.Bytecode, "Compilation resulted in no bytecode")

bindings/ccip_dummy_receiver/dummy_receiver/dummy_receiver.go

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

0 commit comments

Comments
 (0)