This documentation covers the implementation of vault repayment in the Zarban Stablecoin System. The SDK provides functionality for repaying existing vaults, handling transactions, and logging repayment details using Web3 and the Zarban API.
- Python 3.x
- Web3.py
- Zarban SDK
- Ethereum node access (RPC URL)
- Private key with sufficient funds
- Required Python packages:
pip install zarban
Converts a human-readable amount to its native blockchain format (wei).
Parameters:
amount (float)
: The amount to be converted
Returns:
str
: The amount in native blockchain format
Example:
native_amount = to_native(1.5)
Retrieves transaction steps for vault repayment.
Parameters:
api (service.StableCoinSystemApi)
: The API client instancewallet_address (str)
: User's wallet addressvault_id (int)
: The ID of the vault to be repaidamount (float)
: The repayment amount
Returns:
dict
: (number_of_steps, step_number, steps)
Waits for transaction confirmation.
Parameters:
w3
: Web3 instancetx_hash
: Transaction hashmax_wait_time
: Maximum wait time in secondscheck_interval
: Check interval in seconds
Returns:
- Transaction receipt or None
Saves transaction details to a JSON file.
Parameters:
tx
: Transaction objecttx_hash
: Transaction hash
# Configuration
HTTPS_RPC_URL = "your_ethereum_node_url"
PRIVATE_KEY = "your_private_key"
WALLET_ADDRESS = get_address_from_private_key(PRIVATE_KEY)
# Setup API client
cfg = service.Configuration(host="https://testapi.zarban.io")
api_client = ApiClient(cfg)
stable_coin_system_api = service.StableCoinSystemApi(api_client)
# Setup Web3
w3 = Web3(Web3.HTTPProvider(HTTPS_RPC_URL))
# Vault repayment parameters
VAULT_ID = 123 # Replace with your actual vault ID
REPAYMENT_AMOUNT = 500 # Replace with your actual repayment amount
# Repay vault
num_of_steps, step_number, steps = get_vault_tx_steps(
stable_coin_system_api,
WALLET_ADDRESS,
VAULT_ID,
REPAYMENT_AMOUNT
)
-
Initialization
- Set up API client and Web3 connection
- Configure vault repayment parameters
-
Transaction Steps
- Retrieve vault repayment steps
- Process each step sequentially
- Handle transaction signing and submission
-
Transaction Monitoring
- Wait for transaction confirmation
- Log transaction details
-
Result Verification
- Review transaction logs for successful repayment
try:
# Vault repayment code
except service.ApiException as e:
print(f"Response body: {beautify_json(e.body)}")
except Exception as e:
print(f"Unexpected error: {e}")
-
Security
- Never hardcode private keys
- Use environment variables for sensitive data
- Verify all transaction parameters before signing
-
Transaction Management
- Always wait for transaction confirmations
- Implement proper error handling
- Log all transactions for audit purposes
-
Gas Management
- Use appropriate gas limits
- Monitor gas prices
- Implement retry mechanisms for failed transactions
The system maintains a transaction log file (repay_transaction_log.json
) with the following information:
- Timestamp
- Transaction details
- Transaction hash
Example log entry:
{
"timestamp": "2024-03-13T10:00:00",
"tx": {
"from": "0x...",
"to": "0x...",
"value": "1000000000000000",
"gas": 200000
},
"tx_hash": "0x..."
}
-
Network Dependencies
- Requires stable network connection
- Dependent on Ethereum network status
- May be affected by network congestion
-
Resource Requirements
- Sufficient ETH for gas fees
- Valid API access
-
Transaction Timing
- Transaction confirmation times vary
- Maximum wait time configurable
- May require multiple steps
-
Connection Issues
if not w3.is_connected(): print(f"Failed to connect to {HTTPS_RPC_URL}") exit(1)
-
Transaction Failures
- Check gas prices and limits
- Verify account balance
- Confirm network status
-
API Errors
- Validate API credentials
- Check request parameters
- Review error responses
For additional support or bug reports, please contact the Zarban support team or refer to the API documentation.