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

migrate: swaps #468

Merged
merged 2 commits into from
Dec 13, 2024
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
42 changes: 42 additions & 0 deletions chain-api/src/types/TokenSwapFill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) Gala Games Inc. All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import BigNumber from "bignumber.js";
import { Exclude } from "class-transformer";
import { IsNotEmpty, IsPositive } from "class-validator";

import { ChainKey } from "../utils";
import { BigNumberIsPositive, BigNumberProperty, IsUserAlias } from "../validators";
import { ChainObject } from "./ChainObject";

export class TokenSwapFill extends ChainObject {
@Exclude()
public static INDEX_KEY = "GCTSF";

@ChainKey({ position: 0 })
@IsNotEmpty()
public swapRequestId: string;

@ChainKey({ position: 1 })
@IsUserAlias()
public filledBy: string;

@ChainKey({ position: 2 })
@IsPositive()
public created: number;

@BigNumberIsPositive()
@BigNumberProperty()
public uses: BigNumber;
}
55 changes: 55 additions & 0 deletions chain-api/src/types/TokenSwapRequestInstanceOffered.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) Gala Games Inc. All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import BigNumber from "bignumber.js";
import { Exclude } from "class-transformer";
import { IsNotEmpty } from "class-validator";

import { ChainKey } from "../utils";
import { BigNumberIsInteger, BigNumberIsNotNegative, BigNumberProperty } from "../validators";
import { ChainObject } from "./ChainObject";

// index class added in long after initial implementation to faciliate targeted query of TokenSwapRequests
// query by TokenClass / TokenInstance keys, get swapRequestId properties for FillTokenSwap calls
// As a user, I want to see all offers for TokenClass foo, so that I can buy one
export class TokenSwapRequestInstanceOffered extends ChainObject {
@Exclude()
public static INDEX_KEY = "GCTSRIO";

@ChainKey({ position: 0 })
@IsNotEmpty()
public collection: string;

@ChainKey({ position: 1 })
public category: string;

@ChainKey({ position: 2 })
@IsNotEmpty()
public type: string;

@ChainKey({ position: 3 })
@IsNotEmpty()
public additionalKey: string;

@ChainKey({ position: 4 })
@IsNotEmpty()
@BigNumberIsInteger()
@BigNumberIsNotNegative()
@BigNumberProperty()
public instance: BigNumber;

@ChainKey({ position: 5 })
@IsNotEmpty()
public swapRequestId: string;
}
55 changes: 55 additions & 0 deletions chain-api/src/types/TokenSwapRequestInstanceWanted.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) Gala Games Inc. All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import BigNumber from "bignumber.js";
import { Exclude } from "class-transformer";
import { IsNotEmpty } from "class-validator";

import { ChainKey } from "../utils";
import { BigNumberIsInteger, BigNumberIsNotNegative, BigNumberProperty } from "../validators";
import { ChainObject } from "./ChainObject";

// index class added in long after initial implementation to faciliate targeted query of TokenSwapRequests
// query by TokenClass / TokenInstance keys, get swapRequestId properties for FillTokenSwap calls
// As a user, I want to see all swaps that want TokenClass foo, so that I can trade/sell one
export class TokenSwapRequestInstanceWanted extends ChainObject {
@Exclude()
public static INDEX_KEY = "GCTSRIW";

@ChainKey({ position: 0 })
@IsNotEmpty()
public collection: string;

@ChainKey({ position: 1 })
public category: string;

@ChainKey({ position: 2 })
@IsNotEmpty()
public type: string;

@ChainKey({ position: 3 })
@IsNotEmpty()
public additionalKey: string;

@ChainKey({ position: 4 })
@IsNotEmpty()
@BigNumberIsInteger()
@BigNumberIsNotNegative()
@BigNumberProperty()
public instance: BigNumber;

@ChainKey({ position: 5 })
@IsNotEmpty()
public swapRequestId: string;
}
36 changes: 36 additions & 0 deletions chain-api/src/types/TokenSwapRequestOfferedBy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) Gala Games Inc. All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Exclude } from "class-transformer";
import { IsNotEmpty } from "class-validator";

import { ChainKey } from "../utils";
import { IsUserAlias } from "../validators";
import { ChainObject } from "./ChainObject";

// index class added in long after initial implementation to faciliate targeted query of TokenSwapRequests
// query by owner keys, get swapRequestId properties for FillTokenSwap calls
// As a user, I want to see a list of all my offers, so I can optionally close/cancel/terminate one or more
export class TokenSwapRequestOfferedBy extends ChainObject {
@Exclude()
public static INDEX_KEY = "GCTSROB";

@ChainKey({ position: 0 })
@IsUserAlias()
public offeredBy: string;

@ChainKey({ position: 1 })
@IsNotEmpty()
public swapRequestId: string;
}
35 changes: 35 additions & 0 deletions chain-api/src/types/TokenSwapRequestOfferedTo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) Gala Games Inc. All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Exclude } from "class-transformer";
import { IsNotEmpty } from "class-validator";

import { ChainKey } from "../utils";
import { ChainObject } from "./ChainObject";

// index class added in long after initial implementation to faciliate targeted query of TokenSwapRequests
// query by offeredTo keys, get swapRequestId properties for FillTokenSwap calls
// As a user, I want to see a list anything offered to me, so I can optionally accept/fill the token swap
export class TokenSwapRequestOfferedTo extends ChainObject {
@Exclude()
public static INDEX_KEY = "GCTSROT";

@ChainKey({ position: 0 })
@IsNotEmpty()
public offeredTo: string;

@ChainKey({ position: 1 })
@IsNotEmpty()
public swapRequestId: string;
}
6 changes: 6 additions & 0 deletions chain-api/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,11 @@ export * from "./TokenMintConfiguration";
export * from "./TokenMintFulfillment";
export * from "./TokenMintRequest";
export * from "./TokenBurnCounter";
export * from "./TokenSwapFill";
export * from "./TokenSwapRequest";
export * from "./TokenSwapRequestInstanceOffered";
export * from "./TokenSwapRequestInstanceWanted";
export * from "./TokenSwapRequestOfferedBy";
export * from "./TokenSwapRequestOfferedTo";
export * from "./UserAlias";
export * from "./UserRef";
18 changes: 9 additions & 9 deletions chain-api/src/types/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ import { ChainObject } from "./ChainObject";
import { TokenInstanceQuantity } from "./TokenInstance";
import { TokenSwapRequest } from "./TokenSwapRequest";
import { UserRef } from "./UserRef";
import { ChainCallDTO } from "./dtos";
import { ChainCallDTO, SubmitCallDTO } from "./dtos";

@JSONSchema({
description:
"Defines a swap request to be created, i.e. a request when a requester " +
"offers some tokens to another user in exchange of another tokens."
})
export class RequestTokenSwapDto extends ChainCallDTO {
export class RequestTokenSwapDto extends SubmitCallDTO {
static DEFAULT_EXPIRES = 0;

@JSONSchema({
Expand Down Expand Up @@ -140,7 +140,7 @@ export class ExpectedTokenSwap extends ChainCallDTO {
@JSONSchema({
description: "Defines a swap fill object, i.e. a response of another user for a swap request."
})
export class FillTokenSwapDto extends ChainCallDTO {
export class FillTokenSwapDto extends SubmitCallDTO {
public static DEFAULT_USES = new BigNumber(1);

@JSONSchema({
Expand Down Expand Up @@ -181,7 +181,7 @@ export class FillTokenSwapDto extends ChainCallDTO {
description:
"Fill multiple swaps in a single transaction, potentially swaps offered by many different users."
})
export class BatchFillTokenSwapDto extends ChainCallDTO {
export class BatchFillTokenSwapDto extends SubmitCallDTO {
static MAX_ARR_SIZE = 1000;

@JSONSchema({
Expand All @@ -194,7 +194,7 @@ export class BatchFillTokenSwapDto extends ChainCallDTO {
swapDtos: Array<FillTokenSwapDto>;
}

export class TerminateTokenSwapDto extends ChainCallDTO {
export class TerminateTokenSwapDto extends SubmitCallDTO {
@JSONSchema({
description: "Swap request ID to be terminated."
})
Expand Down Expand Up @@ -336,7 +336,7 @@ export class FetchTokenSwapsWithPaginationResponse extends ChainCallDTO {
"which were added to support fine-grained querying of TokenSwapRequests by client applications. " +
"The provided swapRequestIds will be looked up on chain, then their corresponding index Chain objects will be queried and written if necessary."
})
export class EnsureTokenSwapIndexingDto extends ChainCallDTO {
export class EnsureTokenSwapIndexingDto extends SubmitCallDTO {
@ArrayNotEmpty()
swapRequestIds: string[];
}
Expand All @@ -345,7 +345,7 @@ export class EnsureTokenSwapIndexingDto extends ChainCallDTO {
description:
"Response DTO for a EnsureTokenSwapIndexing request. If any writes were made, they will be provided in the writes array and noOp will be true."
})
export class EnsureTokenSwapIndexingResponse extends ChainCallDTO {
export class EnsureTokenSwapIndexingResponse extends SubmitCallDTO {
@IsBoolean()
noOp: boolean;

Expand All @@ -357,7 +357,7 @@ export class EnsureTokenSwapIndexingResponse extends ChainCallDTO {
description:
"Request DTO for CleanTokenSwaps. Optionally, provide a list of ChainKeys to specifically clean/delete from world state. "
})
export class CleanTokenSwapsDto extends ChainCallDTO {
export class CleanTokenSwapsDto extends SubmitCallDTO {
@IsOptional()
@ArrayNotEmpty()
swapRequestIds?: string[];
Expand All @@ -367,7 +367,7 @@ export class CleanTokenSwapsDto extends ChainCallDTO {
description:
"Response DTO for a CleanTokenSwaps request. If any deletes occurred, they will be provided in the deletes array."
})
export class CleanTokenSwapsResponse extends ChainCallDTO {
export class CleanTokenSwapsResponse extends SubmitCallDTO {
@ArrayMinSize(0)
deletes: TokenSwapRequest[];
}
Loading
Loading