Skip to content

Commit

Permalink
Implementation of 'Flow Cancel' modifications to Governor calculations (
Browse files Browse the repository at this point in the history
#3798)

Flow Cancel
A 'flow cancel' transfer occurs when all of the following are true:
    An emitter chain is governed by the Governor
    A transfer has a TargetChain equal to the emitter
    A transfer's Timestamp is within the usual 24 hour window used by the Governor
    The asset in the transfer has fields OriginChain and OriginAddress equal to an entry in the allow list
Example scenario
    A particular USDC implementation minted on Ethereum. It is allow-listed.
    A transfer of $1,000 of this asset is sent from Solana to Sui.
    Before the transfer, Sui's usage is $10,000.
    Before the transfer, Solana's usage is $0.
After the transfer is processed, Sui's new usage will be $9,000 (flow cancel) and Solana's new usage will be $1,000 (as usual).
  • Loading branch information
johnsaigle authored Jun 4, 2024
1 parent d1c8f53 commit 34ee3de
Show file tree
Hide file tree
Showing 8 changed files with 776 additions and 101 deletions.
13 changes: 9 additions & 4 deletions node/pkg/db/governor.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,15 @@ func (d *MockGovernorDB) GetChainGovernorData(logger *zap.Logger) (transfers []*
}

type Transfer struct {
Timestamp time.Time
Value uint64
OriginChain vaa.ChainID
OriginAddress vaa.Address
// This value is generated by the Governor. It is not read from the blockchain transaction. It represents the
// time at which it was observed and evaluated by the Governor.
Timestamp time.Time
// Notional USD value of the transfer
Value uint64
// Where the asset was minted
OriginChain vaa.ChainID
OriginAddress vaa.Address
// Where the transfer was emitted. Not necessarily equal to OriginChain
EmitterChain vaa.ChainID
EmitterAddress vaa.Address
MsgID string
Expand Down
17 changes: 11 additions & 6 deletions node/pkg/governor/devnet_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,25 @@ import (
"github.com/wormhole-foundation/wormhole/sdk/vaa"
)

func (gov *ChainGovernor) initDevnetConfig() ([]tokenConfigEntry, []chainConfigEntry) {
func (gov *ChainGovernor) initDevnetConfig() ([]tokenConfigEntry, []tokenConfigEntry, []chainConfigEntry) {
gov.logger.Info("setting up devnet config")

gov.dayLengthInMinutes = 5

tokens := []tokenConfigEntry{
tokenConfigEntry{chain: 1, addr: "069b8857feab8184fb687f634618c035dac439dc1aeb3b5598a0f00000000001", symbol: "SOL", coinGeckoId: "wrapped-solana", decimals: 8, price: 34.94}, // Addr: So11111111111111111111111111111111111111112, Notional: 4145006
tokenConfigEntry{chain: 2, addr: "000000000000000000000000DDb64fE46a91D46ee29420539FC25FD07c5FEa3E", symbol: "WETH", coinGeckoId: "weth", decimals: 8, price: 1174},
{chain: 1, addr: "069b8857feab8184fb687f634618c035dac439dc1aeb3b5598a0f00000000001", symbol: "SOL", coinGeckoId: "wrapped-solana", decimals: 8, price: 34.94}, // Addr: So11111111111111111111111111111111111111112, Notional: 4145006
{chain: 1, addr: "3b442cb3912157f13a933d0134282d032b5ffecd01a2dbf1b7790608df002ea7", symbol: "USDC", coinGeckoId: "usdc", decimals: 6, price: 1}, // Addr: 4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU, Notional: 1
{chain: 2, addr: "000000000000000000000000DDb64fE46a91D46ee29420539FC25FD07c5FEa3E", symbol: "WETH", coinGeckoId: "weth", decimals: 8, price: 1174},
}

flowCancelTokens := []tokenConfigEntry{
{chain: 1, addr: "3b442cb3912157f13a933d0134282d032b5ffecd01a2dbf1b7790608df002ea7", symbol: "USDC", coinGeckoId: "usdc", decimals: 6, price: 1}, // Addr: 4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU, Notional: 1
}

chains := []chainConfigEntry{
chainConfigEntry{emitterChainID: vaa.ChainIDSolana, dailyLimit: 100, bigTransactionSize: 75},
chainConfigEntry{emitterChainID: vaa.ChainIDEthereum, dailyLimit: 100000},
{emitterChainID: vaa.ChainIDSolana, dailyLimit: 100, bigTransactionSize: 75},
{emitterChainID: vaa.ChainIDEthereum, dailyLimit: 100000},
}

return tokens, chains
return tokens, flowCancelTokens, chains
}
24 changes: 24 additions & 0 deletions node/pkg/governor/flow_cancel_tokens.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package governor

// FlowCancelTokenList returns a list of `tokenConfigEntry`s representing tokens that can 'Flow Cancel'. This means that incoming transfers
// that use these tokens can reduce the 'daily usage' of the Governor configured for the destination chain.
// The list of tokens was generated by grepping the file `generated_mainnet_tokens.go` for "USDC", "USDT", and "DAI".
//
// Only tokens that are configured in the mainnet token list should be able to flow cancel. That is, if a token is
// present in this list but not in the mainnet token lists, it should not flow cancel.
//
// Note that the field `symbol` is unused. It is retained in this file only for convenience.
func FlowCancelTokenList() []tokenConfigEntry {
return []tokenConfigEntry{
// USDC variants
{chain: 2, addr: "000000000000000000000000bcca60bb61934080951369a648fb03df4f96263c", symbol: "aUSDC"},

// USDT variants
{chain: 1, addr: "b7db4e83eb727f1187bd7a50303f5b4e4e943503da8571ad6564a51131504792", symbol: ""},
{chain: 1, addr: "ce010e60afedb22717bd63192f54145a3f965a33bb82d2c7029eb2ce1e208264", symbol: "USDT"},
{chain: 2, addr: "000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec7", symbol: "USDT"},

// DAI variants
{chain: 2, addr: "0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f", symbol: "DAI"},
}
}
Loading

0 comments on commit 34ee3de

Please sign in to comment.