Skip to content

Commit

Permalink
Align recently added features with SDK v2 conventions (#481)
Browse files Browse the repository at this point in the history
  • Loading branch information
dzikowski authored Feb 3, 2025
1 parent e36d2cd commit a2e3972
Show file tree
Hide file tree
Showing 40 changed files with 325 additions and 160 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ node_modules

# IDE - VSCode
.vscode/*
!.vscode/settings.json
.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# misc
/.sass-cache
/connect.lock
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"files.eol": "\n"
"files.eol": "\n"
}
2 changes: 1 addition & 1 deletion chain-api/src/types/ChainObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export abstract class ChainObject {
return instanceToPlain(this);
}

public copy(): typeof this {
public copy(): this {
// @ts-expect-error type conversion
return ChainObject.deserialize<typeof this>(this.constructor, this.toPlainObject());
}
Expand Down
7 changes: 5 additions & 2 deletions chain-api/src/types/UserProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { IsNotEmpty, IsString, ValidateIf } from "class-validator";
import { IsNotEmpty, IsOptional, IsString, ValidateIf } from "class-validator";
import { JSONSchema } from "class-validator-jsonschema";

import { IsUserAlias } from "../validators";
Expand Down Expand Up @@ -56,8 +56,11 @@ export class UserProfile extends ChainObject {
.sort()
.join(", ")}, but you can use arbitrary strings to define your own roles.`
})
@IsOptional()
@IsString({ each: true })
roles: string[];
roles?: string[];
}

export const UP_INDEX_KEY = "GCUP";

export type UserProfileWithRoles = UserProfile & { roles: string[] };
4 changes: 2 additions & 2 deletions chain-api/src/types/allowance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ export class GrantAllowanceDto extends SubmitCallDTO {
"DTO properties backwards-compatible with prior GrantAllowanceDto, with the " +
"exception that this implementation only supports AllowanceType.Mint."
})
export class HighThroughputGrantAllowanceDto extends ChainCallDTO {
export class HighThroughputGrantAllowanceDto extends SubmitCallDTO {
// todo: remove all these duplicated properties
// it seems something about our @GalaTransaction decorator does not pass through
// parent properties. Leaving this class empty with just the `extends GrantAllowanceDto`
Expand Down Expand Up @@ -371,7 +371,7 @@ export class HighThroughputGrantAllowanceDto extends ChainCallDTO {
description:
"Experimental: After submitting request to RequestMintAllowance, follow up with FulfillMintAllowance."
})
export class FulfillMintAllowanceDto extends ChainCallDTO {
export class FulfillMintAllowanceDto extends SubmitCallDTO {
static MAX_ARR_SIZE = 1000;

@ValidateNested({ each: true })
Expand Down
4 changes: 2 additions & 2 deletions chain-api/src/types/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import { JSONSchema } from "class-validator-jsonschema";
import { BigNumberIsPositive, BigNumberProperty, EnumProperty } from "../validators";
import { ChainId } from "./ChainId";
import { TokenInstance, TokenInstanceKey } from "./TokenInstance";
import { ChainCallDTO } from "./dtos";
import { SubmitCallDTO } from "./dtos";
import { OracleBridgeFeeAssertionDto } from "./oracle";

@JSONSchema({
description: "Contains properties of bridge request, i.e. a request to bridge token out from GalaChain."
})
export class RequestTokenBridgeOutDto extends ChainCallDTO {
export class RequestTokenBridgeOutDto extends SubmitCallDTO {
@JSONSchema({
description: "The type of the bridge."
})
Expand Down
2 changes: 1 addition & 1 deletion chain-api/src/types/burn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class BurnTokensDto extends SubmitCallDTO {
"Mints are executed under the identity of the calling user of this function. " +
"All operations occur in the same transaction, meaning either all succeed or none are written to chain."
})
export class BurnAndMintDto extends ChainCallDTO {
export class BurnAndMintDto extends SubmitCallDTO {
static MAX_ARR_SIZE = 1000;

@JSONSchema({
Expand Down
10 changes: 10 additions & 0 deletions chain-api/src/types/dtos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,16 @@ export class ChainCallDTO {
}

public sign(privateKey: string, useDer = false): void {
if (useDer) {
if (this.signing === SigningScheme.TON) {
throw new ValidationFailedError("TON signing scheme does not support DER signatures");
} else {
if (this.signerPublicKey === undefined && this.signerAddress === undefined) {
this.signerPublicKey = signatures.getPublicKey(privateKey);
}
}
}

if (this.signing === SigningScheme.TON) {
const keyBuffer = Buffer.from(privateKey, "base64");
this.signature = signatures.ton.getSignature(this, keyBuffer, this.prefix).toString("base64");
Expand Down
4 changes: 2 additions & 2 deletions chain-api/src/types/fee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ export class FetchFeeThresholdUsesWithPaginationResponse extends ChainCallDTO {
"Take an action on a set of provided chain keys, acquired from a fetch response. " +
"E.g. ResetFeeThresholds, SettleFeePaymentReceipts, etc."
})
export class ChainKeysDto extends ChainCallDTO {
export class ChainKeysDto extends SubmitCallDTO {
@JSONSchema({
description: "A list of composite keys to pass to getObjectsByKeys method."
})
Expand Down Expand Up @@ -924,7 +924,7 @@ export class SettleFeePaymentReceiptsResponse extends ChainCallDTO {
@JSONSchema({
description: "Define a FeeExemption for a specific user."
})
export class FeeExemptionDto extends ChainCallDTO {
export class FeeExemptionDto extends SubmitCallDTO {
@JSONSchema({
description: "The user / identity that should be exempt from fees."
})
Expand Down
20 changes: 17 additions & 3 deletions chain-api/src/types/mint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ export class FetchTokenSupplyResponse extends ChainCallDTO {
"such that ongoing high throughput mints/mint allowances are migrated " +
"to a correct running total."
})
export class PatchMintAllowanceRequestDto extends ChainCallDTO {
export class PatchMintAllowanceRequestDto extends SubmitCallDTO {
@JSONSchema({
description: "Token collection."
})
Expand Down Expand Up @@ -321,7 +321,7 @@ export class PatchMintAllowanceRequestDto extends ChainCallDTO {
"such that ongoing high throughput mints/mint allowances are migrated " +
"to a correct running total."
})
export class PatchMintRequestDto extends ChainCallDTO {
export class PatchMintRequestDto extends SubmitCallDTO {
@JSONSchema({
description: "Token collection."
})
Expand Down Expand Up @@ -357,7 +357,7 @@ export class PatchMintRequestDto extends ChainCallDTO {
@JSONSchema({
description: "DTO that describes a TokenMintConfiguration chain object."
})
export class TokenMintConfigurationDto extends ChainCallDTO {
export class TokenMintConfigurationDto extends SubmitCallDTO {
@JSONSchema({
description: "Token collection."
})
Expand Down Expand Up @@ -484,3 +484,17 @@ export class FetchTokenMintConfigurationsResponse extends ChainCallDTO {
@IsString()
bookmark: string;
}

export class DeleteTokenMintConfigurationDto extends SubmitCallDTO {
@IsNotEmpty()
public collection: string;

@IsNotEmpty()
public category: string;

@IsNotEmpty()
public type: string;

@IsDefined()
public additionalKey: string;
}
8 changes: 4 additions & 4 deletions chain-api/src/types/oracle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { plainToInstance } from "class-transformer";

import { ExternalToken } from "./OraclePriceAssertion";
import { TokenInstanceKey } from "./TokenInstance";
import { createValidDTO } from "./dtos";
import { createValidSubmitDTO } from "./dtos";
import { OraclePriceAssertionDto, OraclePriceCrossRateAssertionDto } from "./oracle";

describe("oracle.ts", () => {
Expand Down Expand Up @@ -54,7 +54,7 @@ describe("oracle.ts", () => {
}
};

const tonUsdPriceAssertion = await createValidDTO(OraclePriceAssertionDto, {
const tonUsdPriceAssertion = await createValidSubmitDTO(OraclePriceAssertionDto, {
oracle: mockOracle,
identity: mockOracleIdentity,
externalBaseToken: tonDetails,
Expand All @@ -63,7 +63,7 @@ describe("oracle.ts", () => {
timestamp: 0
});

const galaUsdPriceAssertion = await createValidDTO(OraclePriceAssertionDto, {
const galaUsdPriceAssertion = await createValidSubmitDTO(OraclePriceAssertionDto, {
oracle: mockOracle,
identity: mockOracleIdentity,
baseToken: galaTokenInstanceKey,
Expand All @@ -72,7 +72,7 @@ describe("oracle.ts", () => {
timestamp: 0
});

const mockAssertionDto = await createValidDTO(OraclePriceCrossRateAssertionDto, {
const mockAssertionDto = await createValidSubmitDTO(OraclePriceCrossRateAssertionDto, {
oracle: mockOracle,
identity: mockOracleIdentity,
baseTokenCrossRate: tonUsdPriceAssertion,
Expand Down
16 changes: 8 additions & 8 deletions chain-api/src/types/oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ import {
} from "class-validator";
import { JSONSchema } from "class-validator-jsonschema";

import { NotImplementedError, ValidationFailedError } from "../utils";
import { ValidationFailedError } from "../utils";
import { BigNumberProperty } from "../validators";
import { OracleDefinition } from "./OracleDefinition";
import { ExternalToken, OraclePriceAssertion } from "./OraclePriceAssertion";
import { OraclePriceCrossRateAssertion } from "./OraclePriceCrossRateAssertion";
import { TokenClassKey } from "./TokenClass";
import { TokenInstanceKey } from "./TokenInstance";
import { ChainCallDTO } from "./dtos";
import { ChainCallDTO, SubmitCallDTO } from "./dtos";

@JSONSchema({
description: "Save an Oracle definition on chain"
})
export class OracleDefinitionDto extends ChainCallDTO {
export class OracleDefinitionDto extends SubmitCallDTO {
@JSONSchema({
description: "Name of the oracle. Unique chain key."
})
Expand Down Expand Up @@ -123,7 +123,7 @@ export class FetchOracleDefinitionsResponse extends ChainCallDTO {
@JSONSchema({
description: "Price data for exchanging two tokens/currenices signed by an Authoritative Oracle"
})
export class OraclePriceAssertionDto extends ChainCallDTO {
export class OraclePriceAssertionDto extends SubmitCallDTO {
@JSONSchema({
description: "Name of the oracle defined on chain."
})
Expand Down Expand Up @@ -221,7 +221,7 @@ export class FetchOraclePriceAssertionsResponse extends ChainCallDTO {
@JSONSchema({
description: "Cross Rate Exchange price assertion. E.g. compare $GALA to $ETH via price in $USD for each."
})
export class OraclePriceCrossRateAssertionDto extends ChainCallDTO {
export class OraclePriceCrossRateAssertionDto extends SubmitCallDTO {
@JSONSchema({
description: "Name of the oracle defined on chain."
})
Expand Down Expand Up @@ -386,22 +386,22 @@ export class FetchOraclePriceCrossRateAssertionsResponse extends ChainCallDTO {
bookmark?: string;
}

export class DeleteOracleAssertionsDto extends ChainCallDTO {
export class DeleteOracleAssertionsDto extends SubmitCallDTO {
public static MAX_LIMIT = 1000;

@ArrayNotEmpty()
chainKeys: string[];
}

export class DeleteOracleDefinitionDto extends ChainCallDTO {
export class DeleteOracleDefinitionDto extends SubmitCallDTO {
@IsNotEmpty()
name: string;
}

@JSONSchema({
description: "Response with signed bridging fee data."
})
export class OracleBridgeFeeAssertionDto extends ChainCallDTO {
export class OracleBridgeFeeAssertionDto extends SubmitCallDTO {
@JSONSchema({
description: "Exchange Rate Price Assertion used to calculate Gas Fee"
})
Expand Down
1 change: 1 addition & 0 deletions chain-api/src/types/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ export class FillTokenSwapDto extends SubmitCallDTO {
})
@IsOptional()
@ValidateNested()
@Type(() => ExpectedTokenSwap)
public expectedTokenSwap?: ExpectedTokenSwap;

@JSONSchema({
Expand Down
11 changes: 7 additions & 4 deletions chain-cli/chaincode-template/src/token/GalaChainTokenContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,13 @@ export default class GalaChainTokenContract extends GalaContract {
in: FullAllowanceCheckDto,
out: FullAllowanceCheckResDto
})
public FullAllowanceCheck(
public async FullAllowanceCheck(
ctx: GalaChainContext,
dto: FullAllowanceCheckDto
): Promise<FullAllowanceCheckResDto> {
return fullAllowanceCheck(ctx, {
owner: dto.owner ?? ctx.callingUser,
grantedTo: dto.grantedTo ?? ctx.callingUser,
owner: dto.owner ? await resolveUserAlias(ctx, dto.owner) : ctx.callingUser,
grantedTo: dto.grantedTo ? await resolveUserAlias(ctx, dto.grantedTo) : ctx.callingUser,
allowanceType: dto.allowanceType ?? AllowanceType.Use,
collection: dto.collection,
category: dto.category,
Expand Down Expand Up @@ -290,7 +290,10 @@ export default class GalaChainTokenContract extends GalaContract {
// no signature verification
})
public async FulfillMint(ctx: GalaChainContext, dto: FulfillMintDto): Promise<TokenInstanceKey[]> {
return fulfillMintRequest(ctx, dto);
return fulfillMintRequest(ctx, {
...dto,
callingUser: ctx.callingUser
});
}

/**
Expand Down
4 changes: 3 additions & 1 deletion chain-client/src/api/ChainUserAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { UserAlias } from "@gala-chain/api";

import { ChainClient, ChainUser } from "../generic";

export interface ChainUserAPI {
privateKey: string;
identityKey: string;
identityKey: UserAlias;
publicKey: string;
ethAddress: string;
}
Expand Down
2 changes: 1 addition & 1 deletion chain-test/src/data/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface ChainUserWithRoles {
ethAddress: string;
publicKey: string;
privateKey: string;
roles: string[] | undefined;
roles: string[];
}

export function randomUser(
Expand Down
2 changes: 1 addition & 1 deletion chain-test/src/unit/fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class Fixture<Ctx extends TestGalaChainContext, T extends GalaContract<Ctx>> {
this.ctx.callingUserData = {
alias: user.identityKey,
ethAddress: user.ethAddress,
roles: user.roles ?? []
roles: user.roles
};
return this;
}
Expand Down
Loading

0 comments on commit a2e3972

Please sign in to comment.