Skip to content

Commit

Permalink
Initial migration of fees code from internal codebase to public sdk (#…
Browse files Browse the repository at this point in the history
…365)

* Migrate Fees code to public SDK

Includes all fee-related code and supporting oracle code.
Supporting types defined for bridging and swaps have been included,
but chaincode methods and other code for these features will
be migrated later.

* chore: lint

* fix: move GalaChainFeeContract to break circular dependency

* test: initial fees migration from internal to public sdk

* fix: chaincode-template unit test snapshot

* fix: remove older bridge ids/dtos in process of rework

* code review feedback, bridge out fee multiplier, bridge out nfts

* pull request feedback

* add GalaChainFeeContract to chaincode-template e2e

* fix snapshot, postpone fee contract migration

* fix: fees exports

* fix decimal precision for bridge surge pricing, start typedoc defs
sentientforest authored Oct 4, 2024
1 parent 4eabcdc commit 911a49d
Showing 69 changed files with 9,995 additions and 1,082 deletions.
17 changes: 17 additions & 0 deletions chain-api/src/types/ChainId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* 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.
*/
export enum ChainId {
Ethereum = 2
}
49 changes: 49 additions & 0 deletions chain-api/src/types/FeeAuthorization.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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 { IsNotEmpty } from "class-validator";

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

export class FeeAuthorization extends ChainObject {
public static INDEX_KEY = "GCFA";

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

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

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

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

@ChainKey({ position: 4 })
@IsNotEmpty()
public txId: string;

@IsNotEmpty()
@BigNumberIsNotNegative()
@BigNumberProperty()
public quantity: BigNumber;
}
68 changes: 68 additions & 0 deletions chain-api/src/types/FeeBalanceCreditReceipt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* 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 { IsNotEmpty, IsString } from "class-validator";

import { ChainKey } from "../utils";
import { BigNumberIsNotNegative, BigNumberProperty, EnumProperty, IsUserAlias } from "../validators";
import { ChainObject } from "./ChainObject";
import { FeeReceiptStatus } from "./FeeReceiptStatus";

export class FeeBalanceCreditReceipt extends ChainObject {
public static INDEX_KEY = "GCCR"; // CR = Credit Receipt

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

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

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

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

@ChainKey({ position: 4 })
@IsString()
@IsNotEmpty()
public minutes: string;

@ChainKey({ position: 5 })
@IsString()
@IsNotEmpty()
public seconds: string;

@ChainKey({ position: 6 })
@IsUserAlias()
public creditToUser: string;

@ChainKey({ position: 7 })
@IsNotEmpty()
public txId: string;

@IsNotEmpty()
@BigNumberIsNotNegative()
@BigNumberProperty()
public quantity: BigNumber;

@EnumProperty(FeeReceiptStatus)
public status: FeeReceiptStatus;
}
62 changes: 62 additions & 0 deletions chain-api/src/types/FeeChannelPaymentReceipt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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 { IsNotEmpty, IsString } from "class-validator";

import { ChainKey } from "../utils";
import { BigNumberIsNotNegative, BigNumberProperty, EnumProperty, IsUserAlias } from "../validators";
import { ChainObject } from "./ChainObject";
import { FeeReceiptStatus } from "./FeeReceiptStatus";

// Channel receipt. Indexed time-first, lookup by distribution period.
export class FeeChannelPaymentReceipt extends ChainObject {
public static INDEX_KEY = "GCFR"; // FR = Fee Receipt

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

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

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

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

@ChainKey({ position: 4 })
@IsUserAlias()
public paidByUser: string;

// todo: consider adding hours and minutes
// to the index as additional chain keys

@ChainKey({ position: 5 })
@IsNotEmpty()
public txId: string;

@IsNotEmpty()
@BigNumberIsNotNegative()
@BigNumberProperty()
public quantity: BigNumber;

@EnumProperty(FeeReceiptStatus)
public status: FeeReceiptStatus;
}
72 changes: 72 additions & 0 deletions chain-api/src/types/FeeCodeDefinition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* 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 { IsBoolean, IsNotEmpty, IsNumber, IsOptional, IsString } from "class-validator";

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

export enum FeeAccelerationRateType {
CuratorDefined = 0,
// optional? todo: define mathematically increasing fee schedules
Additive = 1,
Multiplicative = 2,
Exponential = 3,
Logarithmic = 4,
Custom = 5
}

export class FeeCodeDefinition extends ChainObject {
public static INDEX_KEY = "GCFD";
public static DECIMAL_PRECISION = 8;

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

@ChainKey({ position: 1 })
@BigNumberIsNotNegative()
@BigNumberIsInteger()
@BigNumberProperty()
public feeThresholdUses: BigNumber;

@IsNumber()
public feeThresholdTimePeriod: number;

@BigNumberIsNotNegative()
@BigNumberProperty()
public baseQuantity: BigNumber;

@BigNumberIsNotNegative()
@BigNumberProperty()
public maxQuantity: BigNumber;

@IsOptional()
@BigNumberIsNotNegative()
@BigNumberProperty()
public maxUses?: BigNumber;

@EnumProperty(FeeAccelerationRateType)
public feeAccelerationRateType: FeeAccelerationRateType;

@BigNumberProperty()
public feeAccelerationRate: BigNumber;

@IsOptional()
@IsBoolean()
public isCrossChannel?: boolean;
}
Loading

0 comments on commit 911a49d

Please sign in to comment.