Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSUB-518: follow up - renamed TokenContract->BurnDetail and GATEFaucetAddress->GATEFaucetAc… #1333

Merged
merged 3 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion creditcoin-js/creditcoin.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions creditcoin-js/src/extrinsics/request-collect-coins-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { ExternalAddress, CollectCoinsContract } from '../model';
import { KeyringPair } from '@polkadot/keyring/types';
import { handleTransaction } from './common';
import { TxCallback, TxFailureCallback } from '..';
import { PalletCreditcoinCollectCoinsTokenContract } from '@polkadot/types/lookup';
import { PalletCreditcoinCollectCoinsBurnDetails } from '@polkadot/types/lookup';
import { CollectCoinsEvent, createCollectCoinsRegisteredEvent } from './request-collect-coins';

export const createTokenContract = (
api: ApiPromise,
contract: CollectCoinsContract,
): PalletCreditcoinCollectCoinsTokenContract => {
): PalletCreditcoinCollectCoinsBurnDetails => {
const toType = () => {
switch (contract.kind) {
case 'GCRE':
Expand All @@ -21,7 +21,7 @@ export const createTokenContract = (
}
};

return api.createType('PalletCreditcoinCollectCoinsTokenContract', toType());
return api.createType('PalletCreditcoinCollectCoinsBurnDetails', toType());
};

// eslint-disable-next-line @typescript-eslint/naming-convention
Expand Down
2 changes: 1 addition & 1 deletion creditcoin-js/src/interfaces/augment-api-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ declare module '@polkadot/api-base/types/errors' {
**/
BidOrderExpired: AugmentedError<ApiType>;
/**
* The onchain faucet address for the GATE swap mechanism has not been set using the set_burn_gate_faucet_address extrinsic
* The onchain faucet address for the GATE swap mechanism has not been set using the set_gate_faucet_address extrinsic
**/
BurnGATEFaucetNotSet: AugmentedError<ApiType>;
/**
Expand Down
2 changes: 1 addition & 1 deletion creditcoin-js/src/interfaces/augment-api-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ declare module '@polkadot/api-base/types/storage' {
[]
> &
QueryableStorageEntry<ApiType, []>;
gateFaucetAddress: AugmentedQuery<ApiType, () => Observable<Option<AccountId32>>, []> &
gateFaucetAccount: AugmentedQuery<ApiType, () => Observable<Option<AccountId32>>, []> &
QueryableStorageEntry<ApiType, []>;
legacyBalanceKeeper: AugmentedQuery<ApiType, () => Observable<Option<AccountId32>>, []> &
QueryableStorageEntry<ApiType, []>;
Expand Down
6 changes: 3 additions & 3 deletions creditcoin-js/src/interfaces/augment-api-tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import type {
PalletCreditcoinAskOrderId,
PalletCreditcoinBidOrderId,
PalletCreditcoinBlockchain,
PalletCreditcoinCollectCoinsTokenContract,
PalletCreditcoinCollectCoinsBurnDetails,
PalletCreditcoinDealOrderId,
PalletCreditcoinLoanTerms,
PalletCreditcoinOcwErrorsVerificationFailureCause,
Expand Down Expand Up @@ -574,13 +574,13 @@ declare module '@polkadot/api-base/types/submittable' {
requestCollectCoinsV2: AugmentedSubmittable<
(
contract:
| PalletCreditcoinCollectCoinsTokenContract
| PalletCreditcoinCollectCoinsBurnDetails
| { GCRE: any }
| { GATE: any }
| string
| Uint8Array,
) => SubmittableExtrinsic<ApiType>,
[PalletCreditcoinCollectCoinsTokenContract]
[PalletCreditcoinCollectCoinsBurnDetails]
>;
setCollectCoinsContract: AugmentedSubmittable<
(
Expand Down
6 changes: 3 additions & 3 deletions creditcoin-js/src/interfaces/lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1877,7 +1877,7 @@ export default {
address: 'AccountId32',
},
request_collect_coins_v2: {
contract: 'PalletCreditcoinCollectCoinsTokenContract',
contract: 'PalletCreditcoinCollectCoinsBurnDetails',
},
},
},
Expand Down Expand Up @@ -1937,9 +1937,9 @@ export default {
},
},
/**
* Lookup269: pallet_creditcoin::types::collect_coins::TokenContract
* Lookup269: pallet_creditcoin::types::collect_coins::BurnDetails
**/
PalletCreditcoinCollectCoinsTokenContract: {
PalletCreditcoinCollectCoinsBurnDetails: {
_enum: {
GCRE: '(Bytes,Bytes)',
GATE: '(Bytes,Bytes)',
Expand Down
4 changes: 2 additions & 2 deletions creditcoin-js/src/interfaces/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ import type {
PalletCreditcoinBidOrderId,
PalletCreditcoinBlockchain,
PalletCreditcoinCall,
PalletCreditcoinCollectCoinsBurnDetails,
PalletCreditcoinCollectCoinsCollectedCoins,
PalletCreditcoinCollectCoinsContractType,
PalletCreditcoinCollectCoinsTokenContract,
PalletCreditcoinCollectCoinsUnverifiedCollectedCoins,
PalletCreditcoinDealOrder,
PalletCreditcoinDealOrderId,
Expand Down Expand Up @@ -278,9 +278,9 @@ declare module '@polkadot/types/types/registry' {
PalletCreditcoinBidOrderId: PalletCreditcoinBidOrderId;
PalletCreditcoinBlockchain: PalletCreditcoinBlockchain;
PalletCreditcoinCall: PalletCreditcoinCall;
PalletCreditcoinCollectCoinsBurnDetails: PalletCreditcoinCollectCoinsBurnDetails;
PalletCreditcoinCollectCoinsCollectedCoins: PalletCreditcoinCollectCoinsCollectedCoins;
PalletCreditcoinCollectCoinsContractType: PalletCreditcoinCollectCoinsContractType;
PalletCreditcoinCollectCoinsTokenContract: PalletCreditcoinCollectCoinsTokenContract;
PalletCreditcoinCollectCoinsUnverifiedCollectedCoins: PalletCreditcoinCollectCoinsUnverifiedCollectedCoins;
PalletCreditcoinDealOrder: PalletCreditcoinDealOrder;
PalletCreditcoinDealOrderId: PalletCreditcoinDealOrderId;
Expand Down
6 changes: 3 additions & 3 deletions creditcoin-js/src/interfaces/types-lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2142,7 +2142,7 @@ declare module '@polkadot/types/lookup' {
} & Struct;
readonly isRequestCollectCoinsV2: boolean;
readonly asRequestCollectCoinsV2: {
readonly contract: PalletCreditcoinCollectCoinsTokenContract;
readonly contract: PalletCreditcoinCollectCoinsBurnDetails;
} & Struct;
readonly type:
| 'ClaimLegacyWallet'
Expand Down Expand Up @@ -2225,8 +2225,8 @@ declare module '@polkadot/types/lookup' {
readonly type: 'PersonalSign' | 'EthSign';
}

/** @name PalletCreditcoinCollectCoinsTokenContract (269) */
interface PalletCreditcoinCollectCoinsTokenContract extends Enum {
/** @name PalletCreditcoinCollectCoinsBurnDetails (269) */
interface PalletCreditcoinCollectCoinsBurnDetails extends Enum {
readonly isGcre: boolean;
readonly asGcre: ITuple<[Bytes, Bytes]>;
readonly isGate: boolean;
Expand Down
4 changes: 2 additions & 2 deletions pallets/creditcoin/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::ocw::errors::VerificationFailureCause as Cause;
use crate::ocw::tasks::collect_coins::testing_constants::CHAIN;
use crate::Pallet as Creditcoin;
use crate::{
types::{Blockchain, ContractType, OwnershipProof, TokenContract},
types::{Blockchain, BurnDetails, ContractType, OwnershipProof},
Duration,
};
use crate::{AskOrderId, InterestRate, InterestType, LoanTerms};
Expand Down Expand Up @@ -370,7 +370,7 @@ benchmarks! {
.as_bytes()
.into_bounded();

let contract = TokenContract::GCRE(address.value, tx_id);
let contract = BurnDetails::GCRE(address.value, tx_id);
}: _( RawOrigin::Signed(collector), contract)
}

Expand Down
29 changes: 13 additions & 16 deletions pallets/creditcoin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ mod types;
use ocw::tasks::collect_coins::DeployedContract;
pub use types::{
loan_terms, Address, AddressId, AskOrder, AskOrderId, AskTerms, BidOrder, BidOrderId, BidTerms,
Blockchain, CollectedCoinsId, CollectedCoinsStruct, ContractType, DealOrder, DealOrderId,
Duration, ExternalAddress, ExternalAmount, ExternalTxId, Guid, InterestRate, InterestType,
LegacySighash, LoanTerms, Offer, OfferId, OrderId, RatePerPeriod, Task, TaskId, TaskOutput,
TokenContract, Transfer, TransferId, TransferKind, UnverifiedCollectedCoins,
UnverifiedTransfer,
Blockchain, BurnDetails, CollectedCoinsId, CollectedCoinsStruct, ContractType, DealOrder,
DealOrderId, Duration, ExternalAddress, ExternalAmount, ExternalTxId, Guid, InterestRate,
InterestType, LegacySighash, LoanTerms, Offer, OfferId, OrderId, RatePerPeriod, Task, TaskId,
TaskOutput, Transfer, TransferId, TransferKind, UnverifiedCollectedCoins, UnverifiedTransfer,
};

pub(crate) use types::{DoubleMapExt, Id};
Expand Down Expand Up @@ -240,8 +239,8 @@ pub mod pallet {
pub type GATEContract<T: Config> = StorageValue<_, DeployedContract, ValueQuery>;

#[pallet::storage]
#[pallet::getter(fn gate_faucet_address)]
pub type GATEFaucetAddress<T: Config> = StorageValue<_, T::AccountId, OptionQuery>;
#[pallet::getter(fn gate_faucet_account)]
pub type GATEFaucetAccount<T: Config> = StorageValue<_, T::AccountId, OptionQuery>;

#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
Expand Down Expand Up @@ -523,7 +522,7 @@ pub mod pallet {
/// An unsupported blockchain was specified to register_address_v2
UnsupportedBlockchain,

/// The onchain faucet address for the GATE swap mechanism has not been set using the set_burn_gate_faucet_address extrinsic
/// The onchain faucet address for the GATE swap mechanism has not been set using the set_gate_faucet_address extrinsic
BurnGATEFaucetNotSet,

/// The faucet has insufficient funds to complete this swap, please retry when the faucet has been reloaded
Expand Down Expand Up @@ -1281,7 +1280,7 @@ pub mod pallet {
)
},
ContractType::GATE => {
let faucet_address = Self::gate_faucet_address()
let faucet_address = Self::gate_faucet_account()
.ok_or(Error::<T>::BurnGATEFaucetNotSet)?;

let dest = Self::addresses(&collected_coins.to)
Expand Down Expand Up @@ -1477,21 +1476,19 @@ pub mod pallet {
Ok(())
}

#[transactional]
#[pallet::call_index(24)]
#[pallet::weight(<T as Config>::WeightInfo::set_gate_faucet())]
pub fn set_gate_faucet(origin: OriginFor<T>, address: T::AccountId) -> DispatchResult {
ensure_root(origin)?;
GATEFaucetAddress::<T>::put(address);
GATEFaucetAccount::<T>::put(address);
Ok(())
}

#[transactional]
#[pallet::call_index(25)]
#[pallet::weight(<T as Config>::WeightInfo::request_collect_coins_v2())]
pub fn request_collect_coins_v2(
origin: OriginFor<T>,
contract: TokenContract,
contract: BurnDetails,
) -> DispatchResult {
let who = ensure_signed(origin)?;
let contract_type;
Expand All @@ -1500,18 +1497,18 @@ pub mod pallet {
let evm_address;

match contract {
TokenContract::GCRE(ext_addr, tx_hash) => {
BurnDetails::GCRE(ext_addr, tx_hash) => {
deployed_contract = Self::collect_coins_contract();
contract_type = ContractType::GCRE;
tx_id = tx_hash;
evm_address = ext_addr;
},
TokenContract::GATE(ext_addr, tx_hash) => {
BurnDetails::GATE(ext_addr, tx_hash) => {
deployed_contract = Self::gate_contract();
contract_type = ContractType::GATE;
tx_id = tx_hash;
evm_address = ext_addr;
Self::gate_faucet_address().ok_or(Error::<T>::BurnGATEFaucetNotSet)?;
Self::gate_faucet_account().ok_or(Error::<T>::BurnGATEFaucetNotSet)?;
},
}

Expand Down
25 changes: 12 additions & 13 deletions pallets/creditcoin/src/ocw/tasks/collect_coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
types::{Blockchain, ContractType, UnverifiedCollectedCoins},
ExternalAddress, ExternalAmount,
};
use core::{default::Default, ops::Div};
use core::default::Default;
use ethabi::{Function, Param, ParamType, StateMutability, Token};
use ethereum_types::U64;
use frame_support::{ensure, RuntimeDebug};
Expand Down Expand Up @@ -137,7 +137,7 @@ impl<T: CreditcoinConfig> Pallet<T> {

// GATE -> CTC is swapped 2:1
if *contract_type == ContractType::GATE {
amount = amount.div(sp_core::U256::from_dec_str("2").unwrap());
amount /= 2;
}

let amount = amount.saturated_into::<u128>().saturated_into::<T::Balance>();
Expand Down Expand Up @@ -237,7 +237,7 @@ pub(crate) mod tests {
};
use crate::tests::generate_address_with_proof;
use crate::types::{AddressId, CollectedCoinsId, CollectedCoinsStruct};
use crate::{ocw::rpc::JsonRpcResponse, ExternalAddress, ExternalTxId, TokenContract};
use crate::{ocw::rpc::JsonRpcResponse, BurnDetails, ExternalAddress, ExternalTxId};
use crate::{Pallet as Creditcoin, Task};
use alloc::sync::Arc;
use assert_matches::assert_matches;
Expand Down Expand Up @@ -716,7 +716,7 @@ pub(crate) mod tests {
);

// trying the same with v2
let contract = TokenContract::GCRE(addr, TX_HASH.hex_to_address());
let contract = BurnDetails::GCRE(addr, TX_HASH.hex_to_address());
assert_noop!(
Creditcoin::<Test>::request_collect_coins_v2(RuntimeOrigin::signed(acc), contract,),
crate::Error::<Test>::CollectCoinsAlreadyRegistered
Expand Down Expand Up @@ -776,7 +776,7 @@ pub(crate) mod tests {
assert!(Creditcoin::<Test>::collected_coins(collected_coins_id).is_none());

// trying the same with v2
let contract = TokenContract::GCRE(addr, TX_HASH.hex_to_address());
let contract = BurnDetails::GCRE(addr, TX_HASH.hex_to_address());
assert_noop!(
Creditcoin::<Test>::request_collect_coins_v2(
RuntimeOrigin::signed(acc),
Expand All @@ -803,7 +803,7 @@ pub(crate) mod tests {
);

// trying the same with v2
let contract = TokenContract::GCRE(addr, TX_HASH.hex_to_address());
let contract = BurnDetails::GCRE(addr, TX_HASH.hex_to_address());
assert_noop!(
Creditcoin::<Test>::request_collect_coins_v2(RuntimeOrigin::signed(acc), contract,),
crate::Error::<Test>::NonExistentAddress
Expand Down Expand Up @@ -835,7 +835,7 @@ pub(crate) mod tests {
);

// trying the same with v2
let contract = TokenContract::GCRE(addr, TX_HASH.hex_to_address());
let contract = BurnDetails::GCRE(addr, TX_HASH.hex_to_address());
assert_noop!(
Creditcoin::<Test>::request_collect_coins_v2(
RuntimeOrigin::signed(molly),
Expand Down Expand Up @@ -935,7 +935,7 @@ pub(crate) mod tests {
sign
));

let contract = TokenContract::GCRE(addr.clone(), TX_HASH.hex_to_address());
let contract = BurnDetails::GCRE(addr.clone(), TX_HASH.hex_to_address());
assert_ok!(Creditcoin::<Test>::request_collect_coins_v2(
RuntimeOrigin::signed(acc),
contract,
Expand Down Expand Up @@ -1041,7 +1041,7 @@ pub(crate) mod tests {
assert!(!TaskScheduler::is_scheduled(&deadline, &collected_coins_id));

// trying the same with v2
let contract = TokenContract::GCRE(addr, TX_HASH.hex_to_address());
let contract = BurnDetails::GCRE(addr, TX_HASH.hex_to_address());
assert_ok!(Creditcoin::<Test>::request_collect_coins_v2(
RuntimeOrigin::signed(acc),
contract,
Expand Down Expand Up @@ -1296,7 +1296,6 @@ pub(crate) mod tests {
#[test]
fn collect_coins_v2_gate_token_persist_is_submitted_and_amount_is_2_to_1() {
let mut ext = ExtBuilder::default();
ext.generate_authority();
let acct_pubkey = ext.generate_authority();
let auth = AccountId::from(acct_pubkey.into_account().0);
ext.build_offchain_and_execute_with_state(|state, pool| {
Expand All @@ -1317,7 +1316,7 @@ pub(crate) mod tests {
sign
));

let gate_contract = crate::TokenContract::GATE(addr.clone(), TX_HASH.hex_to_address());
let gate_contract = crate::BurnDetails::GATE(addr.clone(), TX_HASH.hex_to_address());

assert_ok!(Creditcoin::<Test>::request_collect_coins_v2(
RuntimeOrigin::signed(acc),
Expand Down Expand Up @@ -1361,7 +1360,7 @@ pub(crate) mod tests {

let external_addr = ExternalAddress::default();
let tx_id = ExternalTxId::default();
let contract = TokenContract::GATE(external_addr, tx_id);
let contract = BurnDetails::GATE(external_addr, tx_id);

assert_noop!(
Creditcoin::<Test>::request_collect_coins_v2(RuntimeOrigin::none(), contract),
Expand All @@ -1378,7 +1377,7 @@ pub(crate) mod tests {
let who = AccountId::new([0; 32]);
let external_addr = ExternalAddress::default();
let tx_id = ExternalTxId::default();
let contract = TokenContract::GATE(external_addr, tx_id);
let contract = BurnDetails::GATE(external_addr, tx_id);

assert_noop!(
Creditcoin::<Test>::request_collect_coins_v2(RuntimeOrigin::signed(who), contract),
Expand Down
6 changes: 3 additions & 3 deletions pallets/creditcoin/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3303,10 +3303,10 @@ fn set_gate_faucet_passes_and_storage_is_updated() {
ExtBuilder::default().build_and_execute(|| {
let addr: AccountId = AccountId::new([0; 32]);

assert!(Creditcoin::gate_faucet_address().is_none());
assert!(Creditcoin::gate_faucet_account().is_none());
assert_ok!(Creditcoin::set_gate_faucet(RawOrigin::Root.into(), addr.clone()));

let faucet_addr: Option<AccountId32> = Creditcoin::gate_faucet_address();
let faucet_addr: Option<AccountId32> = Creditcoin::gate_faucet_account();

assert!(faucet_addr.is_some());
assert_eq!(faucet_addr.unwrap(), addr)
Expand All @@ -3316,7 +3316,7 @@ fn set_gate_faucet_passes_and_storage_is_updated() {
#[test]
fn gate_faucet_account_storage_should_return_none_when_not_set() {
ExtBuilder::default().build_and_execute(|| {
let gate_faucet = Creditcoin::gate_faucet_address();
let gate_faucet = Creditcoin::gate_faucet_account();

assert!(gate_faucet.is_none());
});
Expand Down
2 changes: 1 addition & 1 deletion pallets/creditcoin/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub use collect_coins::{
pub use loan_terms::*;
pub use transfer::*;

pub use collect_coins::{ContractType, TokenContract};
pub use collect_coins::{BurnDetails, ContractType};

use crate::ocw::tasks::collect_coins::DeployedContract;
use crate::ocw::VerificationFailureCause;
Expand Down
2 changes: 1 addition & 1 deletion pallets/creditcoin/src/types/collect_coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ where

#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
#[allow(clippy::upper_case_acronyms)]
pub enum TokenContract {
pub enum BurnDetails {
GCRE(ExternalAddress, ExternalTxId),
GATE(ExternalAddress, ExternalTxId),
}
Expand Down