Skip to content

Commit

Permalink
Bump erc20_payment_lib
Browse files Browse the repository at this point in the history
* Handle NoToken status property.
* Respect payment deadlines.
* Copy config over from erc20_payment_lib.
  • Loading branch information
kamirr committed Oct 31, 2023
1 parent 0531aa5 commit 0d6cf92
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 23 deletions.
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ members = [
# diesel 1.4.* supports up to 0.23.0, but sqlx 0.5.9 requires 0.22.0
# sqlx 0.5.10 need 0.23.2, so 0.5.9 is last version possible
libsqlite3-sys = { version = "0.26.0", features = ["bundled"] }
#erc20_payment_lib = { git = "https://github.com/golemfactory/erc20_payment_lib", rev = "f75d7a6819c64c1701c38e6551d29f15bb16e164" }
erc20_payment_lib = { git = "https://github.com/golemfactory/erc20_payment_lib", rev = "d563a99d3a7f9762463ca7ccad133b8ca1f27b51" }
#erc20_payment_lib = { path = "../../payments/erc20_payment_lib/crates/erc20_payment_lib" }
erc20_payment_lib = { version = "=0.3.1" }
#erc20_payment_lib = { version = "=0.3.1" }
rand = "0.8.5"
url = "2.3.1"
trust-dns-resolver = "0.22"
Expand Down
59 changes: 44 additions & 15 deletions core/payment-driver/erc20next/config-payments.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,59 @@ process-interval-after-send = 30
process-interval-after-error = 25
# report alive interval (in seconds) is to set how often we want to report that we are alive
# minimum 1 second, maximum is capped by gather-interval
report-alive-interval = 30
report-alive-interval = 10
# gather interval (in seconds) is to set how often payments are gathered
# minimum 1 second, no maximum limit
gather-interval = 60
# gather payments on payment driver start (otherwise wait for first gather-interval)
gather-at-start = true
automatic-recover = false
# set to true to not respect deadlines attached to payments
ignore-deadlines = false

[chain.rinkeby]
chain-name = "Rinkeby"
chain-id = 4
rpc-endpoints = ["http://geth.testnet.golem.network:55555"]
currency-symbol = "tETH"
priority-fee = 1.5111
max-fee-per-gas = 500.0
gas-left-warning-limit = 1000000
transaction-timeout = 100
token = { address = "0xd94e3DC39d4Cad1DAd634e7eb585A57A19dC7EFE", symbol = "tGLM", max-at-once = 10 }
confirmation-blocks = 1
block-explorer-url = "https://rinkeby.etherscan.io"

[chain.goerli]
chain-name = "Goerli"
chain-id = 5
rpc-endpoints = [
"https://ethereum-goerli-rpc.allthatnode.com",
rpc-endpoints = ["https://ethereum-goerli-rpc.allthatnode.com",
"https://rpc.goerli.mudit.blog",
"https://rpc.slock.it/goerli",
"https://rpc.ankr.com/eth_goerli",
]
"https://www.ethercluster.com/goerli",
"https://rpc.ankr.com/eth_goerli"]
currency-symbol = "tETH"
priority-fee = 1.5111
max-fee-per-gas = 10.0
max-fee-per-gas = 500.0
gas-left-warning-limit = 1000000
transaction-timeout = 100
token = { address = "0x33af15c79d64b85ba14aaffaa4577949104b22e8", symbol = "tGLM" }
# multi-contract = { address = "0x7777784f803a7bf1d7f115f849d29ce5706da64a", max-at-once = 10 }
multi-contract = { address = "0x7777784f803a7bf1d7f115f849d29ce5706da64a", max-at-once = 10 }
confirmation-blocks = 1
block-explorer-url = "https://goerli.etherscan.io"

[chain.mumbai]
chain-name = "Mumbai testnet"
chain-id = 80001
rpc-endpoints = [
"https://rpc-mumbai.maticvigil.com/v1/fd04db1066cae0f44d3461ae6d6a7cbbdd46e4a5",
]
rpc-endpoints = ["https://rpc-mumbai.maticvigil.com/v1/fd04db1066cae0f44d3461ae6d6a7cbbdd46e4a5"]
# rpc-endpoints = ["http://127.0.0.1:8545"]
currency-symbol = "tMATIC"
priority-fee = 1.5111
max-fee-per-gas = 500.0
priority-fee = 1.0
max-fee-per-gas = 14.0
gas-left-warning-limit = 1000000
transaction-timeout = 100
transaction-timeout = 60
token = { address = "0x2036807B0B3aaf5b1858EE822D0e111fDdac7018", symbol = "tGLM" }
# multi-contract = { address = "0x800010D7d0d315DCA795110ecCf0127cBd76b89f", max-at-once = 10 }
multi-contract = { address = "0x800010D7d0d315DCA795110ecCf0127cBd76b89f", max-at-once = 10 }
confirmation-blocks = 1
block-explorer-url = "https://mumbai.polygonscan.com"

Expand All @@ -62,7 +75,23 @@ priority-fee = 30.111
max-fee-per-gas = 500.0
gas-left-warning-limit = 1000000
transaction-timeout = 100
token = { address = "0x2036807B0B3aaf5b1858EE822D0e111fDdac7018", symbol = "tGLM" }
token = { address = "0x0B220b82F3eA3B7F6d9A1D8ab58930C064A2b5Bf", symbol = "GLM" }
# multi-contract = { address = "0x50100d4faf5f3b09987dea36dc2eddd57a3e561b", max-at-once = 10 }
confirmation-blocks = 1
block-explorer-url = "https://polygonscan.com"

[chain.dev]
chain-name = "Golem testnet"
chain-id = 987789
rpc-endpoints = ["http://145.239.69.80:8546/web3/erc20"]
currency-symbol = "tETH"
priority-fee = 1.1
max-fee-per-gas = 500.0
gas-left-warning-limit = 1000000
transaction-timeout = 100
token = { address = "0xEC9F23c207018A444f9351dF3D7937f609870667", symbol = "tGLM" }
multi-contract = { address = "0xBCfe9736A4f5bF2E43620061fF3001eA0D003c0F", max-at-once = 10 }
confirmation-blocks = 1
faucet-eth-amount = 10.0
faucet-glm-amount = 20.0
block-explorer-url = "http://145.239.69.80:4000"
36 changes: 32 additions & 4 deletions core/payment-driver/erc20next/src/driver.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use chrono::{DateTime, Duration, Utc};
/*
Erc20Driver to handle payments on the erc20next network.
Expand Down Expand Up @@ -88,6 +89,7 @@ impl Erc20NextDriver {
to: &str,
amount: &BigDecimal,
network: &str,
deadline: Option<DateTime<Utc>>,
) -> Result<String, GenericError> {
self.is_account_active(sender).await?;
let sender = H160::from_str(sender)
Expand All @@ -106,6 +108,7 @@ impl Erc20NextDriver {
TransferType::Token,
amount,
&payment_id,
deadline,
)
.await
.map_err(|err| GenericError::new(format!("Error when inserting transfer {err:?}")))?;
Expand Down Expand Up @@ -361,8 +364,14 @@ impl PaymentDriver for Erc20NextDriver {
.network
.ok_or(GenericError::new("Network not specified".to_string()))?;

self.do_transfer(&msg.sender, &msg.to, &msg.amount, &network)
.await
self.do_transfer(
&msg.sender,
&msg.to,
&msg.amount,
&network,
Some(Utc::now()),
)
.await
}

async fn schedule_payment(
Expand All @@ -379,8 +388,16 @@ impl PaymentDriver for Erc20NextDriver {
msg.platform()
)))?;

self.do_transfer(&msg.sender(), &msg.recipient(), &msg.amount(), network)
.await
let transfer_margin = Duration::minutes(2);

self.do_transfer(
&msg.sender(),
&msg.recipient(),
&msg.amount(),
network,
Some(msg.due_date() - transfer_margin),
)
.await
}

async fn verify_payment(
Expand Down Expand Up @@ -520,6 +537,17 @@ impl PaymentDriver for Erc20NextDriver {
needed_gas_est: missing_gas.unwrap_or_default().to_string(),
})
}
LibStatusProperty::NoToken {
chain_id,
missing_token,
} => {
let network = chain_id_to_net(chain_id);
network_filter(&network).then(|| DriverStatusProperty::InsufficientToken {
driver: DRIVER_NAME.into(),
network,
needed_token_est: missing_token.unwrap_or_default().to_string(),
})
}
})
.collect())
}
Expand Down

0 comments on commit 0d6cf92

Please sign in to comment.