2021-06-29 04:55:44 -07:00
package vaa
import (
"bytes"
"encoding/binary"
2023-05-12 03:11:21 -07:00
"fmt"
2022-06-21 12:18:16 -07:00
2021-06-29 04:55:44 -07:00
"github.com/ethereum/go-ethereum/common"
2023-02-14 10:01:15 -08:00
"github.com/holiman/uint256"
2021-06-29 04:55:44 -07:00
)
// CoreModule is the identifier of the Core module (which is used for governance messages)
var CoreModule = [ ] byte { 00 , 00 , 00 , 00 , 00 , 00 , 00 , 00 , 00 , 00 , 00 , 00 , 00 , 00 , 00 , 00 , 00 , 00 , 00 , 00 , 00 , 00 , 00 , 00 , 00 , 00 , 00 , 00 , 0x43 , 0x6f , 0x72 , 0x65 }
2022-12-07 09:20:11 -08:00
// WasmdModule is the identifier of the Wormchain Wasmd module (which is used for governance messages)
var WasmdModule = [ 32 ] byte { 00 , 00 , 00 , 00 , 00 , 00 , 00 , 00 , 00 , 00 , 00 , 00 , 00 , 00 , 00 , 00 , 00 , 00 , 00 , 00 , 00 , 0x57 , 0x61 , 0x73 , 0x6D , 0x64 , 0x4D , 0x6F , 0x64 , 0x75 , 0x6C , 0x65 }
var WasmdModuleStr = string ( WasmdModule [ : ] )
2023-08-14 07:49:02 -07:00
// GatewayModule is the identifier of the Gateway module (which is used for general Gateway-related governance messages)
var GatewayModule = [ 32 ] byte {
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
0x00 , 0x00 , 0x00 , 0x47 , 0x61 , 0x74 , 0x65 , 0x77 , 0x61 , 0x79 , 0x4d , 0x6f , 0x64 , 0x75 , 0x6c , 0x65 ,
}
var GatewayModuleStr = string ( GatewayModule [ : ] )
2023-03-06 11:23:48 -08:00
// CircleIntegrationModule is the identifier of the Circle Integration module (which is used for governance messages).
// It is the hex representation of "CircleIntegration" left padded with zeroes.
var CircleIntegrationModule = [ 32 ] byte {
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x43 ,
0x69 , 0x72 , 0x63 , 0x6c , 0x65 , 0x49 , 0x6e , 0x74 , 0x65 , 0x67 , 0x72 , 0x61 , 0x74 , 0x69 , 0x6f , 0x6e ,
}
var CircleIntegrationModuleStr = string ( CircleIntegrationModule [ : ] )
2023-08-14 07:49:02 -07:00
// IbcReceiverModule is the identifier of the Wormchain ibc_receiver contract module (which is used for governance messages)
2023-05-12 03:11:21 -07:00
// It is the hex representation of "IbcReceiver" left padded with zeroes.
var IbcReceiverModule = [ 32 ] byte {
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x49 , 0x62 , 0x63 , 0x52 , 0x65 , 0x63 , 0x65 , 0x69 , 0x76 , 0x65 , 0x72 ,
}
var IbcReceiverModuleStr = string ( IbcReceiverModule [ : ] )
2023-08-14 07:49:02 -07:00
// IbcTranslatorModule is the identifier of the Wormchain ibc_receiver contract module (which is used for governance messages)
// It is the hex representation of "IbcTranslator" left padded with zeroes.
var IbcTranslatorModule = [ 32 ] byte {
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
0x00 , 0x00 , 0x00 , 0x49 , 0x62 , 0x63 , 0x54 , 0x72 , 0x61 , 0x6e , 0x73 , 0x6c , 0x61 , 0x74 , 0x6f , 0x72 ,
}
var IbcTranslatorModuleStr = string ( IbcTranslatorModule [ : ] )
2023-06-14 07:27:00 -07:00
// WormholeRelayerModule is the identifier of the Wormhole Relayer module (which is used for governance messages).
// It is the hex representation of "WormholeRelayer" left padded with zeroes.
var WormholeRelayerModule = [ 32 ] byte {
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
0x00 , 0x57 , 0x6f , 0x72 , 0x6d , 0x68 , 0x6f , 0x6c , 0x65 , 0x52 , 0x65 , 0x6c , 0x61 , 0x79 , 0x65 , 0x72 ,
}
var WormholeRelayerModuleStr = string ( WormholeRelayerModule [ : ] )
2022-12-07 09:20:11 -08:00
type GovernanceAction uint8
var (
2023-03-17 11:38:44 -07:00
// Wormhole core governance actions
// See e.g. GovernanceStructs.sol for semantic meaning of these
ActionContractUpgrade GovernanceAction = 1
ActionGuardianSetUpdate GovernanceAction = 2
ActionCoreSetMessageFee GovernanceAction = 3
ActionCoreTransferFees GovernanceAction = 4
ActionCoreRecoverChainId GovernanceAction = 5
2022-12-07 09:20:11 -08:00
2023-08-14 07:49:02 -07:00
// Wormchain cosmwasm/middleware governance actions
2023-08-07 11:18:40 -07:00
ActionStoreCode GovernanceAction = 1
ActionInstantiateContract GovernanceAction = 2
ActionMigrateContract GovernanceAction = 3
ActionAddWasmInstantiateAllowlist GovernanceAction = 4
ActionDeleteWasmInstantiateAllowlist GovernanceAction = 5
2023-02-13 16:40:11 -08:00
2023-08-14 07:49:02 -07:00
// Gateway governance actions
2023-08-16 17:24:57 -07:00
ActionScheduleUpgrade GovernanceAction = 1
ActionCancelUpgrade GovernanceAction = 2
ActionSetIbcComposabilityMwContract GovernanceAction = 3
2023-08-14 07:49:02 -07:00
2023-03-13 17:30:15 -07:00
// Accountant goverance actions
ActionModifyBalance GovernanceAction = 1
2023-02-13 16:40:11 -08:00
// Wormhole tokenbridge governance actions
2023-03-17 11:38:44 -07:00
ActionRegisterChain GovernanceAction = 1
ActionUpgradeTokenBridge GovernanceAction = 2
ActionTokenBridgeRecoverChainId GovernanceAction = 3
2023-03-06 11:23:48 -08:00
// Circle Integration governance actions
CircleIntegrationActionUpdateWormholeFinality GovernanceAction = 1
CircleIntegrationActionRegisterEmitterAndDomain GovernanceAction = 2
CircleIntegrationActionUpgradeContractImplementation GovernanceAction = 3
2023-05-12 03:11:21 -07:00
// Ibc Receiver governance actions
IbcReceiverActionUpdateChannelChain GovernanceAction = 1
2023-06-14 07:27:00 -07:00
2023-08-14 07:49:02 -07:00
// Ibc Translator governance actions
IbcTranslatorActionUpdateChannelChain GovernanceAction = 1
2023-06-14 07:27:00 -07:00
// Wormhole relayer governance actions
WormholeRelayerSetDefaultDeliveryProvider GovernanceAction = 3
2022-12-07 09:20:11 -08:00
)
2021-06-29 04:55:44 -07:00
type (
// BodyContractUpgrade is a governance message to perform a contract upgrade of the core module
BodyContractUpgrade struct {
ChainID ChainID
NewContract Address
}
// BodyGuardianSetUpdate is a governance message to set a new guardian set
BodyGuardianSetUpdate struct {
Keys [ ] common . Address
NewIndex uint32
}
2021-09-30 07:58:54 -07:00
2021-09-30 11:57:44 -07:00
// BodyTokenBridgeRegisterChain is a governance message to register a chain on the token bridge
BodyTokenBridgeRegisterChain struct {
2021-10-01 03:26:05 -07:00
Module string
2021-09-30 07:58:54 -07:00
ChainID ChainID
EmitterAddress Address
}
node: add BridgeUpgradeContract governance VAA
Example VAA produced by the template:
(*vaa.VAA)(0xc0004f4510)({
Version: (uint8) 1,
GuardianSetIndex: (uint32) 0,
Signatures: ([]*vaa.Signature) (len=1 cap=1) {
(*vaa.Signature)(0xc0003b0370)({
Index: (uint8) 0,
Signature: (vaa.SignatureData) (len=65 cap=65) 0f97ec9093c21ccc4ce544898ed5c21b66ab4c90be894642fbb43474ed9fb48a26d6e12f3397b9fdab160fee64e797d26599a2a9d81a4bf4bc98970b5fa5122501
})
},
Timestamp: (time.Time) 1970-01-01 00:00:00 +0000 UTC,
Nonce: (uint32) 1375049878,
Sequence: (uint64) 3557202656914991802,
ConsistencyLevel: (uint8) 32,
EmitterChain: (vaa.ChainID) solana,
EmitterAddress: (vaa.Address) (len=32 cap=32) 0000000000000000000000000000000000000000000000000000000000000004,
Payload: ([]uint8) (len=67 cap=1000) {
00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000010 00 00 00 00 00 54 6f 6b 65 6e 42 72 69 64 67 65 |.....TokenBridge|
00000020 02 00 05 00 00 00 00 00 00 00 00 00 00 00 00 02 |................|
00000030 90 fb 16 72 08 af 45 5b b1 37 78 01 63 b7 b7 a9 |...r..E[.7x.c...|
00000040 a1 0c 16 |...|
}
})
Change-Id: Ibe95db01e1bc0a9c36e1be06920a389db886fdd1
2021-10-08 10:41:43 -07:00
// BodyTokenBridgeUpgradeContract is a governance message to upgrade the token bridge.
BodyTokenBridgeUpgradeContract struct {
Module string
TargetChainID ChainID
NewContract Address
}
2022-12-06 11:10:32 -08:00
2023-02-13 16:40:11 -08:00
// BodyTokenBridgeModifyBalance is a governance message to modify accountant balances for the tokenbridge.
2023-03-13 17:30:15 -07:00
BodyAccountantModifyBalance struct {
2023-02-13 16:40:11 -08:00
Module string
TargetChainID ChainID
Sequence uint64
ChainId ChainID
TokenChain ChainID
TokenAddress Address
Kind uint8
2023-02-14 10:01:15 -08:00
Amount * uint256 . Int
2023-02-13 16:40:11 -08:00
Reason string
}
2022-12-06 11:10:32 -08:00
// BodyWormchainStoreCode is a governance message to upload a new cosmwasm contract to wormchain
BodyWormchainStoreCode struct {
WasmHash [ 32 ] byte
}
// BodyWormchainInstantiateContract is a governance message to instantiate a cosmwasm contract on wormchain
BodyWormchainInstantiateContract struct {
InstantiationParamsHash [ 32 ] byte
}
2023-02-02 10:49:52 -08:00
// BodyWormchainInstantiateContract is a governance message to migrate a cosmwasm contract on wormchain
BodyWormchainMigrateContract struct {
MigrationParamsHash [ 32 ] byte
}
2023-03-06 11:23:48 -08:00
2023-08-07 11:18:40 -07:00
// BodyWormchainAllowlistInstantiateContract is a governance message to allowlist a specific contract address to instantiate a specific wasm code id.
BodyWormchainWasmAllowlistInstantiate struct {
ContractAddr [ 32 ] byte
CodeId uint64
}
2023-08-16 17:24:57 -07:00
// BodyGatewayScheduleUpgrade is a governance message to schedule an upgrade on Gateway
BodyGatewayScheduleUpgrade struct {
Name string
Height uint64
}
2023-08-14 17:37:50 -07:00
// BodyGatewayIbcComposabilityMwContract is a governance message to set a specific contract (i.e. IBC Translator) for the ibc composability middleware to use
BodyGatewayIbcComposabilityMwContract struct {
2023-08-14 07:49:02 -07:00
ContractAddr [ 32 ] byte
}
2023-03-06 11:23:48 -08:00
// BodyCircleIntegrationUpdateWormholeFinality is a governance message to update the wormhole finality for Circle Integration.
BodyCircleIntegrationUpdateWormholeFinality struct {
2023-03-16 07:13:50 -07:00
TargetChainID ChainID
Finality uint8
2023-03-06 11:23:48 -08:00
}
// BodyCircleIntegrationRegisterEmitterAndDomain is a governance message to register an emitter and domain for Circle Integration.
BodyCircleIntegrationRegisterEmitterAndDomain struct {
2023-03-16 07:13:50 -07:00
TargetChainID ChainID
2023-03-06 11:23:48 -08:00
ForeignEmitterChainId ChainID
ForeignEmitterAddress [ 32 ] byte
CircleDomain uint32
}
// BodyCircleIntegrationUpgradeContractImplementation is a governance message to upgrade the contract implementation for Circle Integration.
BodyCircleIntegrationUpgradeContractImplementation struct {
2023-03-16 07:13:50 -07:00
TargetChainID ChainID
2023-03-06 11:23:48 -08:00
NewImplementationAddress [ 32 ] byte
}
2023-05-12 03:11:21 -07:00
2023-08-14 07:49:02 -07:00
// BodyIbcUpdateChannelChain is a governance message to update the ibc channel_id -> chain_id mapping in either of the ibc_receiver or ibc_translator contracts
BodyIbcUpdateChannelChain struct {
2023-05-12 03:11:21 -07:00
// The chain that this governance VAA should be redeemed on
TargetChainId ChainID
// This should follow the IBC channel identifier standard: https://github.com/cosmos/ibc/tree/main/spec/core/ics-024-host-requirements#paths-identifiers-separators
// If the identifier string is shorter than 64 bytes, the correct number of 0x00 bytes should be prepended.
ChannelId [ 64 ] byte
ChainId ChainID
}
2023-06-14 07:27:00 -07:00
// BodyWormholeRelayerSetDefaultDeliveryProvider is a governance message to set the default relay provider for the Wormhole Relayer.
BodyWormholeRelayerSetDefaultDeliveryProvider struct {
ChainID ChainID
NewDefaultDeliveryProviderAddress Address
}
2021-06-29 04:55:44 -07:00
)
func ( b BodyContractUpgrade ) Serialize ( ) [ ] byte {
buf := new ( bytes . Buffer )
// Module
buf . Write ( CoreModule )
// Action
2022-12-07 09:20:11 -08:00
MustWrite ( buf , binary . BigEndian , ActionContractUpgrade )
2021-06-29 04:55:44 -07:00
// ChainID
MustWrite ( buf , binary . BigEndian , uint16 ( b . ChainID ) )
buf . Write ( b . NewContract [ : ] )
return buf . Bytes ( )
}
func ( b BodyGuardianSetUpdate ) Serialize ( ) [ ] byte {
buf := new ( bytes . Buffer )
// Module
buf . Write ( CoreModule )
// Action
2022-12-07 09:20:11 -08:00
MustWrite ( buf , binary . BigEndian , ActionGuardianSetUpdate )
2021-06-29 04:55:44 -07:00
// ChainID - 0 for universal
MustWrite ( buf , binary . BigEndian , uint16 ( 0 ) )
MustWrite ( buf , binary . BigEndian , b . NewIndex )
MustWrite ( buf , binary . BigEndian , uint8 ( len ( b . Keys ) ) )
for _ , k := range b . Keys {
buf . Write ( k [ : ] )
}
return buf . Bytes ( )
}
2021-09-30 07:58:54 -07:00
2021-09-30 11:57:44 -07:00
func ( r BodyTokenBridgeRegisterChain ) Serialize ( ) [ ] byte {
2022-12-12 11:58:38 -08:00
payload := & bytes . Buffer { }
MustWrite ( payload , binary . BigEndian , r . ChainID )
payload . Write ( r . EmitterAddress [ : ] )
// target chain 0 = universal
2023-02-13 16:40:11 -08:00
return serializeBridgeGovernanceVaa ( r . Module , ActionRegisterChain , 0 , payload . Bytes ( ) )
2022-12-06 11:10:32 -08:00
}
2021-10-01 03:26:05 -07:00
2022-12-06 11:10:32 -08:00
func ( r BodyTokenBridgeUpgradeContract ) Serialize ( ) [ ] byte {
2023-02-13 16:40:11 -08:00
return serializeBridgeGovernanceVaa ( r . Module , ActionUpgradeTokenBridge , r . TargetChainID , r . NewContract [ : ] )
}
2023-03-13 17:30:15 -07:00
func ( r BodyAccountantModifyBalance ) Serialize ( ) [ ] byte {
2023-02-13 16:40:11 -08:00
payload := & bytes . Buffer { }
MustWrite ( payload , binary . BigEndian , r . Sequence )
MustWrite ( payload , binary . BigEndian , r . ChainId )
MustWrite ( payload , binary . BigEndian , r . TokenChain )
payload . Write ( r . TokenAddress [ : ] )
payload . WriteByte ( r . Kind )
2023-02-14 10:01:15 -08:00
amount_bytes := r . Amount . Bytes32 ( )
payload . Write ( amount_bytes [ : ] )
2023-02-13 16:40:11 -08:00
reason := make ( [ ] byte , 32 )
// truncate or pad "reason"
2023-02-15 07:10:40 -08:00
count := copy ( reason , r . Reason )
for i := range reason [ count : ] {
reason [ i ] = ' '
2023-02-13 16:40:11 -08:00
}
payload . Write ( reason )
return serializeBridgeGovernanceVaa ( r . Module , ActionModifyBalance , r . TargetChainID , payload . Bytes ( ) )
2022-12-06 11:10:32 -08:00
}
2021-09-30 07:58:54 -07:00
2022-12-06 11:10:32 -08:00
func ( r BodyWormchainStoreCode ) Serialize ( ) [ ] byte {
2022-12-12 11:58:38 -08:00
return serializeBridgeGovernanceVaa ( WasmdModuleStr , ActionStoreCode , ChainIDWormchain , r . WasmHash [ : ] )
2022-12-06 11:10:32 -08:00
}
2021-09-30 07:58:54 -07:00
2022-12-06 11:10:32 -08:00
func ( r BodyWormchainInstantiateContract ) Serialize ( ) [ ] byte {
2022-12-12 11:58:38 -08:00
return serializeBridgeGovernanceVaa ( WasmdModuleStr , ActionInstantiateContract , ChainIDWormchain , r . InstantiationParamsHash [ : ] )
2021-09-30 07:58:54 -07:00
}
node: add BridgeUpgradeContract governance VAA
Example VAA produced by the template:
(*vaa.VAA)(0xc0004f4510)({
Version: (uint8) 1,
GuardianSetIndex: (uint32) 0,
Signatures: ([]*vaa.Signature) (len=1 cap=1) {
(*vaa.Signature)(0xc0003b0370)({
Index: (uint8) 0,
Signature: (vaa.SignatureData) (len=65 cap=65) 0f97ec9093c21ccc4ce544898ed5c21b66ab4c90be894642fbb43474ed9fb48a26d6e12f3397b9fdab160fee64e797d26599a2a9d81a4bf4bc98970b5fa5122501
})
},
Timestamp: (time.Time) 1970-01-01 00:00:00 +0000 UTC,
Nonce: (uint32) 1375049878,
Sequence: (uint64) 3557202656914991802,
ConsistencyLevel: (uint8) 32,
EmitterChain: (vaa.ChainID) solana,
EmitterAddress: (vaa.Address) (len=32 cap=32) 0000000000000000000000000000000000000000000000000000000000000004,
Payload: ([]uint8) (len=67 cap=1000) {
00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000010 00 00 00 00 00 54 6f 6b 65 6e 42 72 69 64 67 65 |.....TokenBridge|
00000020 02 00 05 00 00 00 00 00 00 00 00 00 00 00 00 02 |................|
00000030 90 fb 16 72 08 af 45 5b b1 37 78 01 63 b7 b7 a9 |...r..E[.7x.c...|
00000040 a1 0c 16 |...|
}
})
Change-Id: Ibe95db01e1bc0a9c36e1be06920a389db886fdd1
2021-10-08 10:41:43 -07:00
2023-02-02 10:49:52 -08:00
func ( r BodyWormchainMigrateContract ) Serialize ( ) [ ] byte {
return serializeBridgeGovernanceVaa ( WasmdModuleStr , ActionMigrateContract , ChainIDWormchain , r . MigrationParamsHash [ : ] )
}
2023-08-07 11:18:40 -07:00
func ( r BodyWormchainWasmAllowlistInstantiate ) Serialize ( action GovernanceAction ) [ ] byte {
payload := & bytes . Buffer { }
payload . Write ( r . ContractAddr [ : ] )
MustWrite ( payload , binary . BigEndian , r . CodeId )
return serializeBridgeGovernanceVaa ( WasmdModuleStr , action , ChainIDWormchain , payload . Bytes ( ) )
}
func ( r * BodyWormchainWasmAllowlistInstantiate ) Deserialize ( bz [ ] byte ) {
if len ( bz ) != 40 {
panic ( "incorrect payload length" )
}
var contractAddr [ 32 ] byte
copy ( contractAddr [ : ] , bz [ 0 : 32 ] )
codeId := binary . BigEndian . Uint64 ( bz [ 32 : 40 ] )
r . ContractAddr = contractAddr
r . CodeId = codeId
}
2023-08-14 17:37:50 -07:00
func ( r BodyGatewayIbcComposabilityMwContract ) Serialize ( ) [ ] byte {
2023-08-14 07:49:02 -07:00
payload := & bytes . Buffer { }
payload . Write ( r . ContractAddr [ : ] )
return serializeBridgeGovernanceVaa ( GatewayModuleStr , ActionSetIbcComposabilityMwContract , ChainIDWormchain , payload . Bytes ( ) )
}
2023-08-14 17:37:50 -07:00
func ( r * BodyGatewayIbcComposabilityMwContract ) Deserialize ( bz [ ] byte ) {
2023-08-14 07:49:02 -07:00
if len ( bz ) != 32 {
panic ( "incorrect payload length" )
}
var contractAddr [ 32 ] byte
copy ( contractAddr [ : ] , bz [ 0 : 32 ] )
r . ContractAddr = contractAddr
}
2023-08-16 17:24:57 -07:00
func ( r BodyGatewayScheduleUpgrade ) Serialize ( ) [ ] byte {
payload := & bytes . Buffer { }
payload . Write ( [ ] byte ( r . Name ) )
MustWrite ( payload , binary . BigEndian , r . Height )
return serializeBridgeGovernanceVaa ( GatewayModuleStr , ActionScheduleUpgrade , ChainIDWormchain , payload . Bytes ( ) )
}
func ( r * BodyGatewayScheduleUpgrade ) Deserialize ( bz [ ] byte ) {
r . Name = string ( bz [ 0 : len ( bz ) - 8 ] )
r . Height = binary . BigEndian . Uint64 ( bz [ len ( bz ) - 8 : ] )
}
2023-03-06 11:23:48 -08:00
func ( r BodyCircleIntegrationUpdateWormholeFinality ) Serialize ( ) [ ] byte {
2023-03-16 07:13:50 -07:00
return serializeBridgeGovernanceVaa ( CircleIntegrationModuleStr , CircleIntegrationActionUpdateWormholeFinality , r . TargetChainID , [ ] byte { r . Finality } )
2023-03-06 11:23:48 -08:00
}
func ( r BodyCircleIntegrationRegisterEmitterAndDomain ) Serialize ( ) [ ] byte {
payload := & bytes . Buffer { }
MustWrite ( payload , binary . BigEndian , r . ForeignEmitterChainId )
payload . Write ( r . ForeignEmitterAddress [ : ] )
MustWrite ( payload , binary . BigEndian , r . CircleDomain )
2023-03-16 07:13:50 -07:00
return serializeBridgeGovernanceVaa ( CircleIntegrationModuleStr , CircleIntegrationActionRegisterEmitterAndDomain , r . TargetChainID , payload . Bytes ( ) )
2023-03-06 11:23:48 -08:00
}
func ( r BodyCircleIntegrationUpgradeContractImplementation ) Serialize ( ) [ ] byte {
payload := & bytes . Buffer { }
payload . Write ( r . NewImplementationAddress [ : ] )
2023-03-16 07:13:50 -07:00
return serializeBridgeGovernanceVaa ( CircleIntegrationModuleStr , CircleIntegrationActionUpgradeContractImplementation , r . TargetChainID , payload . Bytes ( ) )
2023-03-06 11:23:48 -08:00
}
2023-08-14 07:49:02 -07:00
func ( r BodyIbcUpdateChannelChain ) Serialize ( module string ) [ ] byte {
if module != IbcReceiverModuleStr && module != IbcTranslatorModuleStr {
panic ( "module for BodyIbcUpdateChannelChain must be either IbcReceiver or IbcTranslator" )
}
2023-05-12 03:11:21 -07:00
payload := & bytes . Buffer { }
payload . Write ( r . ChannelId [ : ] )
MustWrite ( payload , binary . BigEndian , r . ChainId )
2023-08-14 07:49:02 -07:00
return serializeBridgeGovernanceVaa ( module , IbcReceiverActionUpdateChannelChain , r . TargetChainId , payload . Bytes ( ) )
2023-05-12 03:11:21 -07:00
}
node: add BridgeUpgradeContract governance VAA
Example VAA produced by the template:
(*vaa.VAA)(0xc0004f4510)({
Version: (uint8) 1,
GuardianSetIndex: (uint32) 0,
Signatures: ([]*vaa.Signature) (len=1 cap=1) {
(*vaa.Signature)(0xc0003b0370)({
Index: (uint8) 0,
Signature: (vaa.SignatureData) (len=65 cap=65) 0f97ec9093c21ccc4ce544898ed5c21b66ab4c90be894642fbb43474ed9fb48a26d6e12f3397b9fdab160fee64e797d26599a2a9d81a4bf4bc98970b5fa5122501
})
},
Timestamp: (time.Time) 1970-01-01 00:00:00 +0000 UTC,
Nonce: (uint32) 1375049878,
Sequence: (uint64) 3557202656914991802,
ConsistencyLevel: (uint8) 32,
EmitterChain: (vaa.ChainID) solana,
EmitterAddress: (vaa.Address) (len=32 cap=32) 0000000000000000000000000000000000000000000000000000000000000004,
Payload: ([]uint8) (len=67 cap=1000) {
00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000010 00 00 00 00 00 54 6f 6b 65 6e 42 72 69 64 67 65 |.....TokenBridge|
00000020 02 00 05 00 00 00 00 00 00 00 00 00 00 00 00 02 |................|
00000030 90 fb 16 72 08 af 45 5b b1 37 78 01 63 b7 b7 a9 |...r..E[.7x.c...|
00000040 a1 0c 16 |...|
}
})
Change-Id: Ibe95db01e1bc0a9c36e1be06920a389db886fdd1
2021-10-08 10:41:43 -07:00
2023-06-14 07:27:00 -07:00
func ( r BodyWormholeRelayerSetDefaultDeliveryProvider ) Serialize ( ) [ ] byte {
payload := & bytes . Buffer { }
payload . Write ( r . NewDefaultDeliveryProviderAddress [ : ] )
return serializeBridgeGovernanceVaa ( WormholeRelayerModuleStr , WormholeRelayerSetDefaultDeliveryProvider , r . ChainID , payload . Bytes ( ) )
}
2023-08-14 17:37:50 -07:00
func EmptyPayloadVaa ( module string , actionId GovernanceAction , chainId ChainID ) [ ] byte {
return serializeBridgeGovernanceVaa ( module , actionId , chainId , [ ] byte { } )
}
2023-05-12 03:11:21 -07:00
func serializeBridgeGovernanceVaa ( module string , actionId GovernanceAction , chainId ChainID , payload [ ] byte ) [ ] byte {
buf := LeftPadBytes ( module , 32 )
node: add BridgeUpgradeContract governance VAA
Example VAA produced by the template:
(*vaa.VAA)(0xc0004f4510)({
Version: (uint8) 1,
GuardianSetIndex: (uint32) 0,
Signatures: ([]*vaa.Signature) (len=1 cap=1) {
(*vaa.Signature)(0xc0003b0370)({
Index: (uint8) 0,
Signature: (vaa.SignatureData) (len=65 cap=65) 0f97ec9093c21ccc4ce544898ed5c21b66ab4c90be894642fbb43474ed9fb48a26d6e12f3397b9fdab160fee64e797d26599a2a9d81a4bf4bc98970b5fa5122501
})
},
Timestamp: (time.Time) 1970-01-01 00:00:00 +0000 UTC,
Nonce: (uint32) 1375049878,
Sequence: (uint64) 3557202656914991802,
ConsistencyLevel: (uint8) 32,
EmitterChain: (vaa.ChainID) solana,
EmitterAddress: (vaa.Address) (len=32 cap=32) 0000000000000000000000000000000000000000000000000000000000000004,
Payload: ([]uint8) (len=67 cap=1000) {
00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000010 00 00 00 00 00 54 6f 6b 65 6e 42 72 69 64 67 65 |.....TokenBridge|
00000020 02 00 05 00 00 00 00 00 00 00 00 00 00 00 00 02 |................|
00000030 90 fb 16 72 08 af 45 5b b1 37 78 01 63 b7 b7 a9 |...r..E[.7x.c...|
00000040 a1 0c 16 |...|
}
})
Change-Id: Ibe95db01e1bc0a9c36e1be06920a389db886fdd1
2021-10-08 10:41:43 -07:00
// Write action ID
2022-12-06 11:10:32 -08:00
MustWrite ( buf , binary . BigEndian , actionId )
node: add BridgeUpgradeContract governance VAA
Example VAA produced by the template:
(*vaa.VAA)(0xc0004f4510)({
Version: (uint8) 1,
GuardianSetIndex: (uint32) 0,
Signatures: ([]*vaa.Signature) (len=1 cap=1) {
(*vaa.Signature)(0xc0003b0370)({
Index: (uint8) 0,
Signature: (vaa.SignatureData) (len=65 cap=65) 0f97ec9093c21ccc4ce544898ed5c21b66ab4c90be894642fbb43474ed9fb48a26d6e12f3397b9fdab160fee64e797d26599a2a9d81a4bf4bc98970b5fa5122501
})
},
Timestamp: (time.Time) 1970-01-01 00:00:00 +0000 UTC,
Nonce: (uint32) 1375049878,
Sequence: (uint64) 3557202656914991802,
ConsistencyLevel: (uint8) 32,
EmitterChain: (vaa.ChainID) solana,
EmitterAddress: (vaa.Address) (len=32 cap=32) 0000000000000000000000000000000000000000000000000000000000000004,
Payload: ([]uint8) (len=67 cap=1000) {
00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000010 00 00 00 00 00 54 6f 6b 65 6e 42 72 69 64 67 65 |.....TokenBridge|
00000020 02 00 05 00 00 00 00 00 00 00 00 00 00 00 00 02 |................|
00000030 90 fb 16 72 08 af 45 5b b1 37 78 01 63 b7 b7 a9 |...r..E[.7x.c...|
00000040 a1 0c 16 |...|
}
})
Change-Id: Ibe95db01e1bc0a9c36e1be06920a389db886fdd1
2021-10-08 10:41:43 -07:00
// Write target chain
2022-12-06 11:10:32 -08:00
MustWrite ( buf , binary . BigEndian , chainId )
node: add BridgeUpgradeContract governance VAA
Example VAA produced by the template:
(*vaa.VAA)(0xc0004f4510)({
Version: (uint8) 1,
GuardianSetIndex: (uint32) 0,
Signatures: ([]*vaa.Signature) (len=1 cap=1) {
(*vaa.Signature)(0xc0003b0370)({
Index: (uint8) 0,
Signature: (vaa.SignatureData) (len=65 cap=65) 0f97ec9093c21ccc4ce544898ed5c21b66ab4c90be894642fbb43474ed9fb48a26d6e12f3397b9fdab160fee64e797d26599a2a9d81a4bf4bc98970b5fa5122501
})
},
Timestamp: (time.Time) 1970-01-01 00:00:00 +0000 UTC,
Nonce: (uint32) 1375049878,
Sequence: (uint64) 3557202656914991802,
ConsistencyLevel: (uint8) 32,
EmitterChain: (vaa.ChainID) solana,
EmitterAddress: (vaa.Address) (len=32 cap=32) 0000000000000000000000000000000000000000000000000000000000000004,
Payload: ([]uint8) (len=67 cap=1000) {
00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000010 00 00 00 00 00 54 6f 6b 65 6e 42 72 69 64 67 65 |.....TokenBridge|
00000020 02 00 05 00 00 00 00 00 00 00 00 00 00 00 00 02 |................|
00000030 90 fb 16 72 08 af 45 5b b1 37 78 01 63 b7 b7 a9 |...r..E[.7x.c...|
00000040 a1 0c 16 |...|
}
})
Change-Id: Ibe95db01e1bc0a9c36e1be06920a389db886fdd1
2021-10-08 10:41:43 -07:00
// Write emitter address of chain to be registered
2022-12-06 11:10:32 -08:00
buf . Write ( payload [ : ] )
node: add BridgeUpgradeContract governance VAA
Example VAA produced by the template:
(*vaa.VAA)(0xc0004f4510)({
Version: (uint8) 1,
GuardianSetIndex: (uint32) 0,
Signatures: ([]*vaa.Signature) (len=1 cap=1) {
(*vaa.Signature)(0xc0003b0370)({
Index: (uint8) 0,
Signature: (vaa.SignatureData) (len=65 cap=65) 0f97ec9093c21ccc4ce544898ed5c21b66ab4c90be894642fbb43474ed9fb48a26d6e12f3397b9fdab160fee64e797d26599a2a9d81a4bf4bc98970b5fa5122501
})
},
Timestamp: (time.Time) 1970-01-01 00:00:00 +0000 UTC,
Nonce: (uint32) 1375049878,
Sequence: (uint64) 3557202656914991802,
ConsistencyLevel: (uint8) 32,
EmitterChain: (vaa.ChainID) solana,
EmitterAddress: (vaa.Address) (len=32 cap=32) 0000000000000000000000000000000000000000000000000000000000000004,
Payload: ([]uint8) (len=67 cap=1000) {
00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000010 00 00 00 00 00 54 6f 6b 65 6e 42 72 69 64 67 65 |.....TokenBridge|
00000020 02 00 05 00 00 00 00 00 00 00 00 00 00 00 00 02 |................|
00000030 90 fb 16 72 08 af 45 5b b1 37 78 01 63 b7 b7 a9 |...r..E[.7x.c...|
00000040 a1 0c 16 |...|
}
})
Change-Id: Ibe95db01e1bc0a9c36e1be06920a389db886fdd1
2021-10-08 10:41:43 -07:00
return buf . Bytes ( )
}
2023-05-12 03:11:21 -07:00
func LeftPadIbcChannelId ( channelId string ) [ 64 ] byte {
channelIdBuf := LeftPadBytes ( channelId , 64 )
var channelIdIdLeftPadded [ 64 ] byte
copy ( channelIdIdLeftPadded [ : ] , channelIdBuf . Bytes ( ) )
return channelIdIdLeftPadded
}
// Prepends 0x00 bytes to the payload buffer, up to a size of `length`
func LeftPadBytes ( payload string , length int ) * bytes . Buffer {
if length < 0 {
panic ( "cannot prepend bytes to a negative length buffer" )
}
if len ( payload ) > length {
panic ( fmt . Sprintf ( "payload longer than %d bytes" , length ) )
}
buf := & bytes . Buffer { }
// Prepend correct number of 0x00 bytes to the payload slice
for i := 0 ; i < ( length - len ( payload ) ) ; i ++ {
buf . WriteByte ( 0x00 )
}
// add the payload slice
buf . Write ( [ ] byte ( payload ) )
return buf
}