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: Pt. 1 - introduced set_gate_contract #1275

Merged
merged 3 commits into from
Aug 25, 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.

10 changes: 8 additions & 2 deletions creditcoin-js/src/interfaces/augment-api-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import type {
PalletCreditcoinCollectCoinsCollectedCoins,
PalletCreditcoinDealOrder,
PalletCreditcoinLegacySighash,
PalletCreditcoinOcwTasksCollectCoinsGCreContract,
PalletCreditcoinOcwTasksCollectCoinsDeployedContract,
PalletCreditcoinOffer,
PalletCreditcoinTask,
PalletCreditcoinTransfer,
Expand Down Expand Up @@ -335,7 +335,7 @@ declare module '@polkadot/api-base/types/storage' {
QueryableStorageEntry<ApiType, [u32, H256]>;
collectCoinsContract: AugmentedQuery<
ApiType,
() => Observable<PalletCreditcoinOcwTasksCollectCoinsGCreContract>,
() => Observable<PalletCreditcoinOcwTasksCollectCoinsDeployedContract>,
[]
> &
QueryableStorageEntry<ApiType, []>;
Expand All @@ -354,6 +354,12 @@ declare module '@polkadot/api-base/types/storage' {
[u32, H256]
> &
QueryableStorageEntry<ApiType, [u32, H256]>;
gateConract: AugmentedQuery<
ApiType,
() => Observable<PalletCreditcoinOcwTasksCollectCoinsDeployedContract>,
[]
> &
QueryableStorageEntry<ApiType, []>;
legacyBalanceKeeper: AugmentedQuery<ApiType, () => Observable<Option<AccountId32>>, []> &
QueryableStorageEntry<ApiType, []>;
legacyWallets: AugmentedQuery<
Expand Down
20 changes: 17 additions & 3 deletions creditcoin-js/src/interfaces/augment-api-tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import type {
PalletCreditcoinDealOrderId,
PalletCreditcoinLoanTerms,
PalletCreditcoinOcwErrorsVerificationFailureCause,
PalletCreditcoinOcwTasksCollectCoinsGCreContract,
PalletCreditcoinOcwTasksCollectCoinsDeployedContract,
PalletCreditcoinOfferId,
PalletCreditcoinOwnershipProof,
PalletCreditcoinTaskId,
Expand Down Expand Up @@ -573,12 +573,26 @@ declare module '@polkadot/api-base/types/submittable' {
setCollectCoinsContract: AugmentedSubmittable<
(
contract:
| PalletCreditcoinOcwTasksCollectCoinsGCreContract
| PalletCreditcoinOcwTasksCollectCoinsDeployedContract
| { address?: any; chain?: any }
| string
| Uint8Array,
) => SubmittableExtrinsic<ApiType>,
[PalletCreditcoinOcwTasksCollectCoinsGCreContract]
[PalletCreditcoinOcwTasksCollectCoinsDeployedContract]
>;
/**
* Set the onchain details for the Gluwa GATE Contract, including its address and the blockchain where it is deployed.
* This extrinsic expects the caller to have root permissions.
**/
setGateContract: AugmentedSubmittable<
(
contract:
| PalletCreditcoinOcwTasksCollectCoinsDeployedContract
| { address?: any; chain?: any }
| string
| Uint8Array,
) => SubmittableExtrinsic<ApiType>,
[PalletCreditcoinOcwTasksCollectCoinsDeployedContract]
>;
/**
* Generic tx
Expand Down
11 changes: 7 additions & 4 deletions creditcoin-js/src/interfaces/lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,12 +469,12 @@ export default {
PalletCreditcoinCollectCoinsUnverifiedCollectedCoins: {
to: 'Bytes',
txId: 'Bytes',
contract: 'PalletCreditcoinOcwTasksCollectCoinsGCreContract',
contract: 'PalletCreditcoinOcwTasksCollectCoinsDeployedContract',
},
/**
* Lookup68: pallet_creditcoin::ocw::tasks::collect_coins::GCreContract
* Lookup68: pallet_creditcoin::ocw::tasks::collect_coins::DeployedContract
**/
PalletCreditcoinOcwTasksCollectCoinsGCreContract: {
PalletCreditcoinOcwTasksCollectCoinsDeployedContract: {
address: 'H160',
chain: 'PalletCreditcoinBlockchain',
},
Expand Down Expand Up @@ -1886,7 +1886,7 @@ export default {
},
__Unused19: 'Null',
set_collect_coins_contract: {
contract: 'PalletCreditcoinOcwTasksCollectCoinsGCreContract',
contract: 'PalletCreditcoinOcwTasksCollectCoinsDeployedContract',
},
remove_authority: {
who: 'AccountId32',
Expand All @@ -1896,6 +1896,9 @@ export default {
address: 'Bytes',
ownershipProof: 'PalletCreditcoinOwnershipProof',
},
set_gate_contract: {
contract: 'PalletCreditcoinOcwTasksCollectCoinsDeployedContract',
},
},
},
/**
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 @@ -75,7 +75,7 @@ import type {
PalletCreditcoinLoanTermsInterestRate,
PalletCreditcoinLoanTermsInterestType,
PalletCreditcoinOcwErrorsVerificationFailureCause,
PalletCreditcoinOcwTasksCollectCoinsGCreContract,
PalletCreditcoinOcwTasksCollectCoinsDeployedContract,
PalletCreditcoinOffer,
PalletCreditcoinOfferId,
PalletCreditcoinOrderId,
Expand Down Expand Up @@ -294,7 +294,7 @@ declare module '@polkadot/types/types/registry' {
PalletCreditcoinLoanTermsInterestRate: PalletCreditcoinLoanTermsInterestRate;
PalletCreditcoinLoanTermsInterestType: PalletCreditcoinLoanTermsInterestType;
PalletCreditcoinOcwErrorsVerificationFailureCause: PalletCreditcoinOcwErrorsVerificationFailureCause;
PalletCreditcoinOcwTasksCollectCoinsGCreContract: PalletCreditcoinOcwTasksCollectCoinsGCreContract;
PalletCreditcoinOcwTasksCollectCoinsDeployedContract: PalletCreditcoinOcwTasksCollectCoinsDeployedContract;
PalletCreditcoinOffer: PalletCreditcoinOffer;
PalletCreditcoinOfferId: PalletCreditcoinOfferId;
PalletCreditcoinOrderId: PalletCreditcoinOrderId;
Expand Down
15 changes: 10 additions & 5 deletions creditcoin-js/src/interfaces/types-lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -594,11 +594,11 @@ declare module '@polkadot/types/lookup' {
interface PalletCreditcoinCollectCoinsUnverifiedCollectedCoins extends Struct {
readonly to: Bytes;
readonly txId: Bytes;
readonly contract: PalletCreditcoinOcwTasksCollectCoinsGCreContract;
readonly contract: PalletCreditcoinOcwTasksCollectCoinsDeployedContract;
}

/** @name PalletCreditcoinOcwTasksCollectCoinsGCreContract (68) */
interface PalletCreditcoinOcwTasksCollectCoinsGCreContract extends Struct {
/** @name PalletCreditcoinOcwTasksCollectCoinsDeployedContract (68) */
interface PalletCreditcoinOcwTasksCollectCoinsDeployedContract extends Struct {
readonly address: H160;
readonly chain: PalletCreditcoinBlockchain;
}
Expand Down Expand Up @@ -2142,7 +2142,7 @@ declare module '@polkadot/types/lookup' {
} & Struct;
readonly isSetCollectCoinsContract: boolean;
readonly asSetCollectCoinsContract: {
readonly contract: PalletCreditcoinOcwTasksCollectCoinsGCreContract;
readonly contract: PalletCreditcoinOcwTasksCollectCoinsDeployedContract;
} & Struct;
readonly isRemoveAuthority: boolean;
readonly asRemoveAuthority: {
Expand All @@ -2154,6 +2154,10 @@ declare module '@polkadot/types/lookup' {
readonly address: Bytes;
readonly ownershipProof: PalletCreditcoinOwnershipProof;
} & Struct;
readonly isSetGateContract: boolean;
readonly asSetGateContract: {
readonly contract: PalletCreditcoinOcwTasksCollectCoinsDeployedContract;
} & Struct;
readonly type:
| 'ClaimLegacyWallet'
| 'RegisterAddress'
Expand All @@ -2174,7 +2178,8 @@ declare module '@polkadot/types/lookup' {
| 'AddAuthority'
| 'SetCollectCoinsContract'
| 'RemoveAuthority'
| 'RegisterAddressV2';
| 'RegisterAddressV2'
| 'SetGateContract';
}

/** @name SpCoreEcdsaPublic (264) */
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/src/test/collect-coins.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('CollectCoins', (): void => {
collector = (global as any).CREDITCOIN_CREATE_SIGNER(keyring, 'lender');

/* eslint-disable @typescript-eslint/naming-convention */
const contract = api.createType('PalletCreditcoinOcwTasksCollectCoinsGCreContract', {
const contract = api.createType('PalletCreditcoinOcwTasksCollectCoinsDeployedContract', {
address: (global as any).CREDITCOIN_CTC_CONTRACT_ADDRESS,
chain: blockchain,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('SetCollectCoinsContract', (): void => {
const { api } = ccApi;

/* eslint-disable @typescript-eslint/naming-convention */
const contract = api.createType('PalletCreditcoinOcwTasksCollectCoinsGCreContract', {
const contract = api.createType('PalletCreditcoinOcwTasksCollectCoinsDeployedContract', {
address: '0xa3EE21C306A700E682AbCdfe9BaA6A08F3820419',
chain: testingData.blockchain,
});
Expand Down
7 changes: 6 additions & 1 deletion pallets/creditcoin/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ benchmarks! {

set_collect_coins_contract {
let root = RawOrigin::Root;
let contract = GCreContract::default();
let contract = DeployedContract::default();
}: _(root, contract)

register_address_v2 {
Expand All @@ -348,6 +348,11 @@ benchmarks! {
let signature = ecdsa_sign(ktypeid, &pkey, &message).expect("ecdsa signature");
let proof = OwnershipProof::EthSign(signature);
}: _(RawOrigin::Signed(who), Blockchain::Ethereum, address, proof)

set_gate_contract {
let root = RawOrigin::Root;
let contract = DeployedContract::default();
}: _(root, contract)
}

//impl_benchmark_test_suite!(Creditcoin, crate::mock::new_test_ext(), crate::mock::Test);
Expand Down
25 changes: 22 additions & 3 deletions pallets/creditcoin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub mod migrations;
pub mod ocw;
mod types;

use ocw::tasks::collect_coins::GCreContract;
use ocw::tasks::collect_coins::DeployedContract;
pub use types::{
loan_terms, Address, AddressId, AskOrder, AskOrderId, AskTerms, BidOrder, BidOrderId, BidTerms,
Blockchain, CollectedCoinsId, CollectedCoinsStruct, DealOrder, DealOrderId, Duration,
Expand Down Expand Up @@ -144,6 +144,7 @@ pub mod pallet {
fn remove_authority() -> Weight;
fn set_collect_coins_contract() -> Weight;
fn register_address_v2() -> Weight;
fn set_gate_contract() -> Weight;
}

#[pallet::pallet]
Expand Down Expand Up @@ -229,7 +230,11 @@ pub mod pallet {

#[pallet::storage]
#[pallet::getter(fn collect_coins_contract)]
pub type CollectCoinsContract<T: Config> = StorageValue<_, GCreContract, ValueQuery>;
pub type CollectCoinsContract<T: Config> = StorageValue<_, DeployedContract, ValueQuery>;

#[pallet::storage]
#[pallet::getter(fn gate_contract)]
pub type GATEConract<T: Config> = StorageValue<_, DeployedContract, ValueQuery>;

#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
Expand Down Expand Up @@ -1323,7 +1328,7 @@ pub mod pallet {
#[pallet::weight(<T as Config>::WeightInfo::set_collect_coins_contract())]
pub fn set_collect_coins_contract(
origin: OriginFor<T>,
contract: GCreContract,
contract: DeployedContract,
) -> DispatchResult {
ensure_root(origin)?;
CollectCoinsContract::<T>::put(contract);
Expand Down Expand Up @@ -1401,5 +1406,19 @@ pub mod pallet {
},
}
}

/// Set the onchain details for the Gluwa GATE Contract, including its address and the blockchain where it is deployed.
/// This extrinsic expects the caller to have root permissions.
#[transactional]
#[pallet::call_index(23)]
#[pallet::weight(<T as Config>::WeightInfo::set_gate_contract())]
pub fn set_gate_contract(
origin: OriginFor<T>,
contract: DeployedContract,
) -> DispatchResult {
ensure_root(origin)?;
GATEConract::<T>::put(contract);
Ok(())
}
}
}
34 changes: 17 additions & 17 deletions pallets/creditcoin/src/ocw/tasks/collect_coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,25 @@ use sp_runtime::SaturatedConversion;
use sp_std::prelude::*;

#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
pub struct GCreContract {
pub struct DeployedContract {
pub address: sp_core::H160,
pub chain: Blockchain,
}

impl GCreContract {
impl DeployedContract {
const DEFAULT_CHAIN: Blockchain = Blockchain::Ethereum;
}

impl Default for GCreContract {
impl Default for DeployedContract {
fn default() -> Self {
let contract_chain: Blockchain = GCreContract::DEFAULT_CHAIN;
let contract_chain: Blockchain = DeployedContract::DEFAULT_CHAIN;
let contract_address: H160 =
sp_core::H160(hex!("a3EE21C306A700E682AbCdfe9BaA6A08F3820419"));
Self { address: contract_address, chain: contract_chain }
}
}

impl GCreContract {
impl DeployedContract {
///exchange has been deprecated, use burn instead
fn burn_vested_cc_abi() -> Function {
#[allow(deprecated)]
Expand Down Expand Up @@ -90,7 +90,7 @@ pub fn validate_collect_coins(
return Err(VerificationFailureCause::MissingSender.into());
}

let transfer_fn = GCreContract::burn_vested_cc_abi();
let transfer_fn = DeployedContract::burn_vested_cc_abi();
ensure!(!transaction.is_input_empty(), VerificationFailureCause::EmptyInput);

{
Expand Down Expand Up @@ -122,7 +122,7 @@ impl<T: CreditcoinConfig> Pallet<T> {
u_cc: &UnverifiedCollectedCoins,
) -> VerificationResult<T::Balance> {
log::debug!("verifying OCW Collect Coins");
let UnverifiedCollectedCoins { to, tx_id, contract: GCreContract { address, chain } } =
let UnverifiedCollectedCoins { to, tx_id, contract: DeployedContract { address, chain } } =
u_cc;
let rpc_url = &chain.rpc_url()?;
let tx = ocw::eth_get_transaction(tx_id, rpc_url)?;
Expand All @@ -139,9 +139,9 @@ impl<T: CreditcoinConfig> Pallet<T> {

#[cfg(any(test, feature = "runtime-benchmarks"))]
pub(crate) mod testing_constants {
use super::{Blockchain, GCreContract};
use super::{Blockchain, DeployedContract};

pub const CHAIN: Blockchain = GCreContract::DEFAULT_CHAIN;
pub const CHAIN: Blockchain = DeployedContract::DEFAULT_CHAIN;
}

#[cfg(test)]
Expand Down Expand Up @@ -200,7 +200,7 @@ pub(crate) mod tests {
});

pub(crate) static RPC_RESPONSE_AMOUNT: Lazy<sp_core::U256> = Lazy::new(|| {
let transfer_fn = GCreContract::burn_vested_cc_abi();
let transfer_fn = DeployedContract::burn_vested_cc_abi();

let inputs = transfer_fn.decode_input(&(INPUT.0)[4..]).unwrap();

Expand Down Expand Up @@ -282,7 +282,7 @@ pub(crate) mod tests {
receipt: EthTransactionReceipt { status: Some(1u64.into()), ..Default::default() },
transaction,
eth_tip: (base_height + ETH_CONFIRMATIONS),
contract_address: GCreContract::default().address,
contract_address: DeployedContract::default().address,
}
}
}
Expand Down Expand Up @@ -1008,7 +1008,7 @@ pub(crate) mod tests {
let acct_pubkey = ext.generate_authority();
let _auth = AccountId::from(acct_pubkey.into_account().0);
ext.build_and_execute(|| {
let contract = GCreContract {
let contract = DeployedContract {
address: sp_core::H160(hex!("aaaaabbbbbcccccdddddeeeeefffff08F3820419")),
chain: Blockchain::Rinkeby,
};
Expand All @@ -1018,7 +1018,7 @@ pub(crate) mod tests {
));
let from_storage = Creditcoin::<Test>::collect_coins_contract();
assert_eq!(contract, from_storage);
assert_ne!(from_storage, GCreContract::default());
assert_ne!(from_storage, DeployedContract::default());

let (acc, ..) = generate_address_with_proof("somebody");

Expand All @@ -1039,7 +1039,7 @@ pub(crate) mod tests {

#[test]
fn gcrecontract_value_query_is_default() {
let contract = GCreContract::default();
let contract = DeployedContract::default();
let ext = ExtBuilder::default();
ext.build_and_execute(|| {
let value_query = Creditcoin::<Test>::collect_coins_contract();
Expand Down Expand Up @@ -1093,7 +1093,7 @@ pub(crate) mod tests {
let cc = UnverifiedCollectedCoins {
to: addr,
tx_id: TX_HASH.hex_to_address(),
contract: GCreContract::default(),
contract: DeployedContract::default(),
};
assert_matches!(
Creditcoin::<Test>::verify_collect_coins_ocw(&cc),
Expand All @@ -1117,7 +1117,7 @@ pub(crate) mod tests {
let cc = UnverifiedCollectedCoins {
to: addr,
tx_id: TX_HASH.hex_to_address(),
contract: GCreContract::default(),
contract: DeployedContract::default(),
};

let id = TaskV2::<Test>::to_id(&cc);
Expand Down Expand Up @@ -1155,7 +1155,7 @@ pub(crate) mod tests {
let cc = UnverifiedCollectedCoins {
to: addr,
tx_id: TX_HASH.hex_to_address(),
contract: GCreContract::default(),
contract: DeployedContract::default(),
};

let id = TaskV2::<Test>::to_id(&cc);
Expand Down
Loading