Skip to content

Commit 6a258fe

Browse files
authored
Merge branch 'main' into feat/increase_difficulty
2 parents 0e6ab91 + fcf3f37 commit 6a258fe

File tree

6 files changed

+38
-2
lines changed

6 files changed

+38
-2
lines changed

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "2.2.8"
2+
".": "2.3.0"
33
}

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## [2.3.0](https://github.com/Lilypad-Tech/lilypad/compare/v2.2.8...v2.3.0) (2024-08-25)
4+
5+
6+
### Features
7+
8+
* Add ETH Balance Check on RP Matching ([#298](https://github.com/Lilypad-Tech/lilypad/issues/298)) ([561a64a](https://github.com/Lilypad-Tech/lilypad/commit/561a64acbc007a210abea3aac2d216955fb3c6c9))
9+
310
## [2.2.8](https://github.com/Lilypad-Tech/lilypad/compare/v2.2.7...v2.2.8) (2024-08-16)
411

512

pkg/data/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ type ResourceOffer struct {
132132
ID string `json:"id"`
133133
// this is basically a nonce so we don't have one ID pointing at multiple offers
134134
CreatedAt int `json:"created_at"`
135-
// the address of the job creator
135+
// the address of the resource provider
136136
ResourceProvider string `json:"resource_provider"`
137137
// allows a resource provider to manage multiple offers
138138
// that are essentially the same

pkg/solver/controller.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,18 @@ func (controller *SolverController) addResourceOffer(resourceOffer data.Resource
321321
}
322322
resourceOffer.ID = id
323323

324+
// Check the resource provider's ETH balance
325+
balance, err := controller.web3SDK.GetBalance(resourceOffer.ResourceProvider)
326+
if err != nil {
327+
return nil, fmt.Errorf("failed to retrieve ETH balance for resource provider: %v", err)
328+
}
329+
// Convert InstructionPrice from ETH to Wei
330+
requiredBalanceWei := web3.EtherToWei(float64(resourceOffer.DefaultPricing.InstructionPrice))
331+
// If the balance is less than the required balance, don't add the resource offer
332+
if balance.Cmp(requiredBalanceWei) < 0 {
333+
return nil, err
334+
}
335+
324336
controller.log.Info("add resource offer", resourceOffer)
325337

326338
metricsDashboard.TrackNodeInfo(resourceOffer)

pkg/web3/sdk.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,16 @@ func (sdk *Web3SDK) WaitTx(ctx context.Context, tx *types.Transaction) (*types.R
246246
func (sdk *Web3SDK) GetAddress() common.Address {
247247
return crypto.PubkeyToAddress(GetPublicKey(sdk.PrivateKey))
248248
}
249+
250+
func (sdk *Web3SDK) GetBalance(address string) (*big.Int, error) {
251+
// Convert the string address to common.Address
252+
ethAddress := common.HexToAddress(address)
253+
254+
// Get the balance using the converted address
255+
balance, err := sdk.Client.BalanceAt(context.Background(), ethAddress, nil)
256+
if err != nil {
257+
log.Error().Msgf("error for GetBalance: %s", err.Error())
258+
return nil, err
259+
}
260+
return balance, nil
261+
}

pkg/web3/utils.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ func EtherToWeiUint64(etherAmount float64) uint64 {
5454
wei := EtherToWei(etherAmount)
5555
return wei.Uint64()
5656
}
57+
func WeiToEther(wei *big.Int) *big.Float {
58+
ethValue := new(big.Float).Quo(new(big.Float).SetInt(wei), big.NewFloat(1e18))
59+
return ethValue
60+
}
5761

5862
func ConvertStringToBigInt(st string) big.Int {
5963
bigInt, _ := big.NewInt(0).SetString(st, 10)

0 commit comments

Comments
 (0)