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: GATE -> CTC Swap #1256

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
5338657
moving workstations
zacharyfrederick Aug 7, 2023
d1cab19
base functionality
Aug 8, 2023
699f6d4
initial functionality implemented
Aug 9, 2023
0c32732
added test to ensure that faucet is set in extrinsic
Aug 9, 2023
2423c64
made changes to have GATE swap event the same event types as collect …
Aug 14, 2023
4b6c826
updated e2e test and removed dead code/files
Aug 14, 2023
d5584ab
removed unused errors and updated documentation comments
Aug 15, 2023
d2b5587
rebased with dev and rebuilt credicoint-js
Aug 15, 2023
cfa480a
removed more dead code and fixed failing tests
Aug 15, 2023
e35f249
updated failing e2e tests
Aug 15, 2023
2029e08
added some eslint ignore magic
Aug 15, 2023
8d8a409
added benchmarks
Aug 15, 2023
90894b5
more formatting changes
Aug 15, 2023
7a3271d
appease clippy
Aug 15, 2023
b2a719d
please clippy I'm so tired
Aug 15, 2023
ec5d16f
updated version.rs
Aug 15, 2023
961c5b9
changed collect coins test to accept a previously registered address …
Aug 16, 2023
afd1070
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 16, 2023
3bb87e0
renamed gate token env variable and updated deployGATEToken to option…
Aug 16, 2023
7589fe3
removed GluwaGateToken.dbg.json
Aug 16, 2023
92d6b54
changed global setup to reuse existing addresses and reverted previou…
Aug 16, 2023
06b257e
changed gate token test to only run if executing setup authority
Aug 16, 2023
8dfe0bf
removed unnecessary test file set-burn-gate-contract.test.ts
Aug 16, 2023
9889c08
removed unnecessary imports
Aug 16, 2023
f6ffd1c
fixed failing gate-token test
Aug 16, 2023
d4e57e8
formatting changes
Aug 16, 2023
5a4bb68
added unit test to ensure successful operation of set_burn_gate_fauce…
Aug 18, 2023
601d796
appease clippy
Aug 18, 2023
264a315
added initial weights from macbook
Aug 18, 2023
f79b627
updated pallets/creditcoin/src/weights.rs to fix build issues
Aug 21, 2023
494dfb0
created initial v8 migration
Aug 21, 2023
a7d3308
removed unused imports from migration file
Aug 21, 2023
0b7c9d9
updated v8 migrations file to fix build issues
Aug 21, 2023
4484a34
updated storage version in creditcoin/src/lib.rs
Aug 21, 2023
4ed7cc5
updated imports for v8 migration
Aug 21, 2023
c39c7d4
appease clippy
Aug 21, 2023
b4f6d40
updated post_upgrade version check
Aug 21, 2023
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
26 changes: 13 additions & 13 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ members = [
resolver = "2"

[workspace.package]
version = '2.226.1'
version = '2.227.0'
authors = ['Gluwa Inc.', 'Nathan Whitaker <nathan.whitaker@gluwa.com>']
edition = '2021'
license = 'Unlicense'
Expand Down
2 changes: 1 addition & 1 deletion creditcoin-js/creditcoin.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions creditcoin-js/src/extrinsics/extrinsics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ import {
TransferId,
ExternalAddress,
OwnershipProof,
CollectCoinsContract,
} from '../model';
import { KeyringPair } from '@polkadot/keyring/types';
import { lockDealOrderAsync } from './lock-deal-order';
import { closeDealOrderAsync } from './close-deal-order';
import { exemptLoanAsync } from './exempt';
import { requestCollectCoinsAsync } from './request-collect-coins';
import { registerAddressV2Async } from './register-address-v2';
import { requestCollectCoinvsV2Async } from './request-collect-coins-v2';

export const extrinsics = (api: ApiPromise) => {
const registerAddress = (
Expand Down Expand Up @@ -119,6 +121,9 @@ export const extrinsics = (api: ApiPromise) => {
signer: KeyringPair,
) => registerAddressV2Async(api, externalAddress, blockchain, ownershipProof, signer);

const requestCollectCoinsV2 = (contract: CollectCoinsContract, signer: KeyringPair) =>
requestCollectCoinvsV2Async(api, contract, signer);

return {
registerAddress,
registerAddressV2,
Expand All @@ -134,5 +139,6 @@ export const extrinsics = (api: ApiPromise) => {
closeDealOrder,
exemptLoan,
requestCollectCoins,
requestCollectCoinsV2,
};
};
64 changes: 64 additions & 0 deletions creditcoin-js/src/extrinsics/request-collect-coins-v2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { ApiPromise, SubmittableResult } from '@polkadot/api';
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 { CollectCoinsEvent, createCollectCoinsRegisteredEvent } from './request-collect-coins';

export const createTokenContract = (
api: ApiPromise,
contract: CollectCoinsContract,
): PalletCreditcoinCollectCoinsTokenContract => {
const toType = () => {
switch (contract.kind) {
case 'GCRE':
// eslint-disable-next-line @typescript-eslint/naming-convention
return { GCRE: [contract.evmAddress, contract.txHash] };
case 'GATE':
// eslint-disable-next-line @typescript-eslint/naming-convention
return { GATE: [contract.evmAddress, contract.txHash] };
}
};

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

// eslint-disable-next-line @typescript-eslint/naming-convention
export const GATEContract = (evmAddress: ExternalAddress, txHash: string): CollectCoinsContract => {
return { kind: 'GATE', evmAddress, txHash };
};

// eslint-disable-next-line @typescript-eslint/naming-convention
export const GCREContract = (evmAddress: ExternalAddress, txHash: string): CollectCoinsContract => {
return { kind: 'GCRE', evmAddress, txHash };
};

export const requestCollectCoinsV2 = async (
api: ApiPromise,
contract: CollectCoinsContract,
signer: KeyringPair,
onSuccess: TxCallback,
onFail: TxFailureCallback,
) => {
const formattedContract = createTokenContract(api, contract);

const unsubscribe: () => void = await api.tx.creditcoin
.requestCollectCoinsV2(formattedContract)
.signAndSend(signer, { nonce: -1 }, (result) => handleTransaction(api, unsubscribe, result, onSuccess, onFail));
};

export const requestCollectCoinvsV2Async = async (
api: ApiPromise,
contract: CollectCoinsContract,
signer: KeyringPair,
) => {
return new Promise<CollectCoinsEvent>((resolve, reject) => {
const onSuccess = (result: SubmittableResult) =>
resolve(createCollectCoinsRegisteredEvent(api, result, 'CollectCoinsRegistered'));

requestCollectCoinsV2(api, contract, signer, onSuccess, reject).catch((reason) => {
reject(reason);
});
});
};
2 changes: 1 addition & 1 deletion creditcoin-js/src/extrinsics/request-collect-coins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const persistedCollectCoins = (api: ApiPromise, collectedCoinsId: CollectedCoins
);
};

const createCollectCoinsRegisteredEvent = (
export const createCollectCoinsRegisteredEvent = (
api: ApiPromise,
result: SubmittableResult,
kind: CollectCoinsEventKind,
Expand Down
2 changes: 2 additions & 0 deletions creditcoin-js/src/interfaces/augment-api-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ declare module '@polkadot/api-base/types/errors' {
* The bid order has expired and is no longer valid.
**/
BidOrderExpired: AugmentedError<ApiType>;
BurnGATEFaucetNotSet: AugmentedError<ApiType>;
BurnGATEInsufficientFaucetBalance: AugmentedError<ApiType>;
/**
* The coin collection has already been registered.
**/
Expand Down
12 changes: 10 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 @@ -333,9 +333,17 @@ declare module '@polkadot/api-base/types/storage' {
[u32, H256]
> &
QueryableStorageEntry<ApiType, [u32, H256]>;
burnGATEConract: AugmentedQuery<
ApiType,
() => Observable<PalletCreditcoinOcwTasksCollectCoinsDeployedContract>,
[]
> &
QueryableStorageEntry<ApiType, []>;
burnGATEFaucetAddress: AugmentedQuery<ApiType, () => Observable<Option<AccountId32>>, []> &
QueryableStorageEntry<ApiType, []>;
collectCoinsContract: AugmentedQuery<
ApiType,
() => Observable<PalletCreditcoinOcwTasksCollectCoinsGCreContract>,
() => Observable<PalletCreditcoinOcwTasksCollectCoinsDeployedContract>,
[]
> &
QueryableStorageEntry<ApiType, []>;
Expand Down
33 changes: 30 additions & 3 deletions creditcoin-js/src/interfaces/augment-api-tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ import type {
PalletCreditcoinAskOrderId,
PalletCreditcoinBidOrderId,
PalletCreditcoinBlockchain,
PalletCreditcoinCollectCoinsTokenContract,
PalletCreditcoinDealOrderId,
PalletCreditcoinLoanTerms,
PalletCreditcoinOcwErrorsVerificationFailureCause,
PalletCreditcoinOcwTasksCollectCoinsGCreContract,
PalletCreditcoinOcwTasksCollectCoinsDeployedContract,
PalletCreditcoinOfferId,
PalletCreditcoinOwnershipProof,
PalletCreditcoinTaskId,
Expand Down Expand Up @@ -417,6 +418,7 @@ declare module '@polkadot/api-base/types/submittable' {
| 'InvalidAddress'
| 'UnsupportedMethod'
| 'TransactionNotFound'
| 'InsufficientFaucetBalance'
| number
| Uint8Array,
) => SubmittableExtrinsic<ApiType>,
Expand Down Expand Up @@ -570,15 +572,40 @@ declare module '@polkadot/api-base/types/submittable' {
) => SubmittableExtrinsic<ApiType>,
[Bytes, Bytes]
>;
requestCollectCoinsV2: AugmentedSubmittable<
(
contract:
| PalletCreditcoinCollectCoinsTokenContract
| { GCRE: any }
| { GATE: any }
| string
| Uint8Array,
) => SubmittableExtrinsic<ApiType>,
[PalletCreditcoinCollectCoinsTokenContract]
>;
setBurnGateContract: AugmentedSubmittable<
(
contract:
| PalletCreditcoinOcwTasksCollectCoinsDeployedContract
| { address?: any; chain?: any }
| string
| Uint8Array,
) => SubmittableExtrinsic<ApiType>,
[PalletCreditcoinOcwTasksCollectCoinsDeployedContract]
>;
setBurnGateFaucetAddress: AugmentedSubmittable<
(address: AccountId32 | string | Uint8Array) => SubmittableExtrinsic<ApiType>,
[AccountId32]
>;
setCollectCoinsContract: AugmentedSubmittable<
(
contract:
| PalletCreditcoinOcwTasksCollectCoinsGCreContract
| PalletCreditcoinOcwTasksCollectCoinsDeployedContract
| { address?: any; chain?: any }
| string
| Uint8Array,
) => SubmittableExtrinsic<ApiType>,
[PalletCreditcoinOcwTasksCollectCoinsGCreContract]
[PalletCreditcoinOcwTasksCollectCoinsDeployedContract]
>;
/**
* Generic tx
Expand Down
Loading
Loading