Skip to content

Commit

Permalink
feat: support stake transactions (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
kallydev authored Jan 19, 2024
1 parent 01a52ba commit 91debe9
Show file tree
Hide file tree
Showing 20 changed files with 6,212 additions and 1,001 deletions.
1,742 changes: 1,482 additions & 260 deletions contract/l2/abi/Chips.abi

Large diffs are not rendered by default.

143 changes: 20 additions & 123 deletions contract/l2/abi/Staking.abi
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
[
{
"inputs": [
{
"internalType": "address",
"name": "token",
"type": "address"
},
{
"internalType": "address",
"name": "treasury",
Expand Down Expand Up @@ -66,28 +61,6 @@
"name": "AccessControlUnauthorizedAccount",
"type": "error"
},
{
"inputs": [
{
"internalType": "address",
"name": "target",
"type": "address"
}
],
"name": "AddressEmptyCode",
"type": "error"
},
{
"inputs": [
{
"internalType": "address",
"name": "account",
"type": "address"
}
],
"name": "AddressInsufficientBalance",
"type": "error"
},
{
"inputs": [],
"name": "AlreadyClaimed",
Expand Down Expand Up @@ -210,7 +183,7 @@
},
{
"inputs": [],
"name": "FailedInnerCall",
"name": "InsufficientValue",
"type": "error"
},
{
Expand Down Expand Up @@ -308,19 +281,13 @@
"type": "error"
},
{
"inputs": [
{
"internalType": "address",
"name": "token",
"type": "address"
}
],
"name": "SafeERC20FailedOperation",
"inputs": [],
"name": "TaxRateBasisPointsTooLarge",
"type": "error"
},
{
"inputs": [],
"name": "TaxRateBasisPointsTooLarge",
"name": "TransferFailed",
"type": "error"
},
{
Expand Down Expand Up @@ -744,6 +711,12 @@
"name": "requestId",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "unstakeAmount",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256[]",
Expand Down Expand Up @@ -909,19 +882,6 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "TOKEN",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "TREASURY",
Expand Down Expand Up @@ -989,11 +949,6 @@
},
{
"inputs": [
{
"internalType": "address",
"name": "to",
"type": "address"
},
{
"internalType": "string",
"name": "name",
Expand All @@ -1017,40 +972,7 @@
],
"name": "createNode",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "string",
"name": "name",
"type": "string"
},
{
"internalType": "string",
"name": "description",
"type": "string"
},
{
"internalType": "uint64",
"name": "taxRateBasisPoints",
"type": "uint64"
},
{
"internalType": "bool",
"name": "publicGood",
"type": "bool"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "createNodeAndDeposit",
"outputs": [],
"stateMutability": "nonpayable",
"stateMutability": "payable",
"type": "function"
},
{
Expand Down Expand Up @@ -1080,16 +1002,10 @@
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"inputs": [],
"name": "deposit",
"outputs": [],
"stateMutability": "nonpayable",
"stateMutability": "payable",
"type": "function"
},
{
Expand Down Expand Up @@ -1127,7 +1043,7 @@
],
"name": "distributeRewards",
"outputs": [],
"stateMutability": "nonpayable",
"stateMutability": "payable",
"type": "function"
},
{
Expand Down Expand Up @@ -1857,11 +1773,6 @@
"internalType": "address",
"name": "nodeAddr",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "stake",
Expand All @@ -1877,7 +1788,7 @@
"type": "uint256"
}
],
"stateMutability": "nonpayable",
"stateMutability": "payable",
"type": "function"
},
{
Expand All @@ -1886,11 +1797,6 @@
"internalType": "address",
"name": "nodeAddr",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "stakeToPublicPool",
Expand All @@ -1906,20 +1812,7 @@
"type": "uint256"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "stakingToken",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"stateMutability": "payable",
"type": "function"
},
{
Expand Down Expand Up @@ -1954,5 +1847,9 @@
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"stateMutability": "payable",
"type": "receive"
}
]
2 changes: 1 addition & 1 deletion contract/l2/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (

EventHashStakingDeposited = crypto.Keccak256Hash([]byte("Deposited(address,uint256)"))
EventHashStakingStaked = crypto.Keccak256Hash([]byte("Staked(address,address,uint256,uint256,uint256)"))
EventHashStakingUnstakeRequested = crypto.Keccak256Hash([]byte("UnstakeRequested(address,address,uint256,uint256[])"))
EventHashStakingUnstakeRequested = crypto.Keccak256Hash([]byte("UnstakeRequested(address,address,uint256,uint256,uint256[])"))
EventHashStakingUnstakeClaimed = crypto.Keccak256Hash([]byte("UnstakeClaimed(uint256,address,address,uint256)"))
EventHashStakingWithdrawRequested = crypto.Keccak256Hash([]byte("WithdrawRequested(address,uint256,uint256)"))
EventHashStakingWithdrawalClaimed = crypto.Keccak256Hash([]byte("WithdrawalClaimed(uint256 indexed requestId)"))
Expand Down
4,163 changes: 3,713 additions & 450 deletions contract/l2/contract_chips.go

Large diffs are not rendered by default.

231 changes: 85 additions & 146 deletions contract/l2/contract_staking.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion deploy/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ database:

rss3_chain:
endpoint_l1: https://rpc.ankr.com/eth_sepolia
endpoint_l2: https://rpc.testnet.rss3.dev
endpoint_l2: https://rpc.testnet.rss3.io
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/ethereum/go-ethereum v1.13.10
github.com/go-playground/validator/v10 v10.16.0
github.com/labstack/echo/v4 v4.11.4
github.com/lib/pq v1.10.9
github.com/naturalselectionlabs/rss3-node v0.0.0-20240108094705-95832810ba63
github.com/orlangure/gnomock v0.30.0
github.com/pressly/goose/v3 v3.17.0
Expand Down Expand Up @@ -77,7 +78,6 @@ require (
github.com/kr/text v0.2.0 // indirect
github.com/labstack/gommon v0.4.2 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
Expand Down
8 changes: 8 additions & 0 deletions internal/database/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ type Client interface {

FindStakeStaker(ctx context.Context, user, node common.Address) (*schema.StakeStaker, error)
SaveStakeStaker(ctx context.Context, stakeStaker *schema.StakeStaker) error
FindStakeTransaction(ctx context.Context, id common.Hash) (*schema.StakeTransaction, error)
FindStakeTransactions(ctx context.Context) ([]*schema.StakeTransaction, error)
FindStakeTransactionsByUser(ctx context.Context, address common.Address) ([]*schema.StakeTransaction, error)
FindStakeTransactionsByNode(ctx context.Context, address common.Address) ([]*schema.StakeTransaction, error)
FindStakeEventsByID(ctx context.Context, id common.Hash) ([]*schema.StakeEvent, error)
FindStakeEventsByIDs(ctx context.Context, ids []common.Hash) ([]*schema.StakeEvent, error)
SaveStakeTransaction(ctx context.Context, stakeTransaction *schema.StakeTransaction) error
SaveStakeEvent(ctx context.Context, stakeEvent *schema.StakeEvent) error
}

type Session interface {
Expand Down
8 changes: 4 additions & 4 deletions internal/database/dialer/cockroachdb/client_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (c *client) FindBridgeTransactions(ctx context.Context) ([]*schema.BridgeTr
var rows []table.BridgeTransaction

if err := c.database.WithContext(ctx).Find(&rows).Error; err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return nil, fmt.Errorf("fin bridge transactions: %w", err)
return nil, fmt.Errorf("find bridge transactions: %w", err)
}

results := make([]*schema.BridgeTransaction, 0, len(rows))
Expand All @@ -52,7 +52,7 @@ func (c *client) FindBridgeTransactionsByAddress(ctx context.Context, address co
var rows []table.BridgeTransaction

if err := c.database.WithContext(ctx).Distinct("*").Where("sender = ? OR receiver = ?", address.String(), address.String()).Find(&rows).Error; err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return nil, fmt.Errorf("fin bridge transactions: %w", err)
return nil, fmt.Errorf("find bridge transactions: %w", err)
}

results := make([]*schema.BridgeTransaction, 0, len(rows))
Expand All @@ -77,7 +77,7 @@ func (c *client) FindBridgeEventsByID(ctx context.Context, id common.Hash) (*sch
return nil, database.ErrorRowNotFound
}

return nil, fmt.Errorf("fin bridge event: %w", err)
return nil, fmt.Errorf("find bridge event: %w", err)
}

return row.Export()
Expand All @@ -91,7 +91,7 @@ func (c *client) FindBridgeEventsByIDs(ctx context.Context, ids []common.Hash) (
})

if err := c.database.WithContext(ctx).Where("id IN ?", transactionIDs).Find(&rows).Error; err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return nil, fmt.Errorf("fin bridge event: %w", err)
return nil, fmt.Errorf("find bridge event: %w", err)
}

results := make([]*schema.BridgeEvent, 0, len(rows))
Expand Down
Loading

0 comments on commit 91debe9

Please sign in to comment.