-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from Supercolony-net/feature/psp22-extensions
Feature/psp22 extensions
- Loading branch information
Showing
114 changed files
with
2,456 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
use super::{ | ||
AccessControlError, | ||
OwnableError, | ||
PSP22Error, | ||
PSP22ReceiverError, | ||
PausableError, | ||
ReentrancyGuardError, | ||
}; | ||
use ink_prelude::string::String; | ||
|
||
#[derive(Debug, PartialEq, Eq, scale::Encode, scale::Decode)] | ||
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] | ||
pub enum FlashBorrowerError { | ||
FlashloanRejected(String), | ||
} | ||
|
||
impl From<OwnableError> for FlashBorrowerError { | ||
fn from(ownable: OwnableError) -> Self { | ||
match ownable { | ||
OwnableError::CallerIsNotOwner => { | ||
FlashBorrowerError::FlashloanRejected(String::from("O::CallerIsNotOwner")) | ||
} | ||
OwnableError::NewOwnerIsZero => FlashBorrowerError::FlashloanRejected(String::from("O::NewOwnerIsZero")), | ||
} | ||
} | ||
} | ||
|
||
impl From<AccessControlError> for FlashBorrowerError { | ||
fn from(access: AccessControlError) -> Self { | ||
match access { | ||
AccessControlError::MissingRole => FlashBorrowerError::FlashloanRejected(String::from("AC::MissingRole")), | ||
AccessControlError::RoleRedundant => { | ||
FlashBorrowerError::FlashloanRejected(String::from("AC::RoleRedundant")) | ||
} | ||
AccessControlError::InvalidCaller => { | ||
FlashBorrowerError::FlashloanRejected(String::from("AC::InvalidCaller")) | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl From<PausableError> for FlashBorrowerError { | ||
fn from(pausable: PausableError) -> Self { | ||
match pausable { | ||
PausableError::Paused => FlashBorrowerError::FlashloanRejected(String::from("P::Paused")), | ||
PausableError::NotPaused => FlashBorrowerError::FlashloanRejected(String::from("P::NotPaused")), | ||
} | ||
} | ||
} | ||
|
||
impl From<ReentrancyGuardError> for FlashBorrowerError { | ||
fn from(guard: ReentrancyGuardError) -> Self { | ||
match guard { | ||
ReentrancyGuardError::ReentrantCall => { | ||
FlashBorrowerError::FlashloanRejected(String::from("RG::ReentrantCall")) | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl From<PSP22ReceiverError> for FlashBorrowerError { | ||
fn from(error: PSP22ReceiverError) -> Self { | ||
match error { | ||
PSP22ReceiverError::TransferRejected(message) => FlashBorrowerError::FlashloanRejected(message), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, PartialEq, Eq, scale::Encode, scale::Decode)] | ||
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] | ||
pub enum FlashLenderError { | ||
Custom(String), | ||
/// Returned if we our flashlendner does not support lending of this token | ||
WrongTokenAddress, | ||
/// Returned if the contract does not have enough allowance to transfer borrowed amount and fees | ||
AllowanceDoesNotAllowRefund, | ||
/// Callee contract rejected the flashloan | ||
BorrowerRejected(String), | ||
} | ||
|
||
impl From<PSP22Error> for FlashLenderError { | ||
fn from(error: PSP22Error) -> Self { | ||
match error { | ||
PSP22Error::Custom(message) => FlashLenderError::Custom(message), | ||
PSP22Error::InsufficientBalance => FlashLenderError::Custom(String::from("PSP22: Insufficient Balance")), | ||
PSP22Error::InsufficientAllowance => { | ||
FlashLenderError::Custom(String::from("PSP22: Insufficient Allowance")) | ||
} | ||
PSP22Error::ZeroRecipientAddress => FlashLenderError::Custom(String::from("PSP22: Zero Recipient Address")), | ||
PSP22Error::ZeroSenderAddress => FlashLenderError::Custom(String::from("PSP22: Zero Sender Address")), | ||
PSP22Error::SafeTransferCheckFailed(message) => FlashLenderError::Custom(message), | ||
} | ||
} | ||
} | ||
|
||
impl From<FlashBorrowerError> for FlashLenderError { | ||
fn from(error: FlashBorrowerError) -> Self { | ||
match error { | ||
FlashBorrowerError::FlashloanRejected(message) => FlashLenderError::BorrowerRejected(message), | ||
} | ||
} | ||
} | ||
|
||
impl From<OwnableError> for FlashLenderError { | ||
fn from(ownable: OwnableError) -> Self { | ||
match ownable { | ||
OwnableError::CallerIsNotOwner => FlashLenderError::Custom(String::from("O::CallerIsNotOwner")), | ||
OwnableError::NewOwnerIsZero => FlashLenderError::Custom(String::from("O::NewOwnerIsZero")), | ||
} | ||
} | ||
} | ||
|
||
impl From<AccessControlError> for FlashLenderError { | ||
fn from(access: AccessControlError) -> Self { | ||
match access { | ||
AccessControlError::MissingRole => FlashLenderError::Custom(String::from("AC::MissingRole")), | ||
AccessControlError::RoleRedundant => FlashLenderError::Custom(String::from("AC::RoleRedundant")), | ||
AccessControlError::InvalidCaller => FlashLenderError::Custom(String::from("AC::InvalidCaller")), | ||
} | ||
} | ||
} | ||
|
||
impl From<PausableError> for FlashLenderError { | ||
fn from(pausable: PausableError) -> Self { | ||
match pausable { | ||
PausableError::Paused => FlashLenderError::Custom(String::from("P::Paused")), | ||
PausableError::NotPaused => FlashLenderError::Custom(String::from("P::NotPaused")), | ||
} | ||
} | ||
} | ||
|
||
impl From<ReentrancyGuardError> for FlashLenderError { | ||
fn from(guard: ReentrancyGuardError) -> Self { | ||
match guard { | ||
ReentrancyGuardError::ReentrantCall => FlashLenderError::Custom(String::from("RG::ReentrantCall")), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.