Skip to content

Commit

Permalink
Rename 'refund' with 'fee' (#52)
Browse files Browse the repository at this point in the history
* Rename refund with fee

* Update version

* Update hraphql schema
  • Loading branch information
jsidorenko authored Jun 13, 2021
1 parent 285776e commit 248d44d
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 61 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "etherspot",
"version": "1.4.4",
"version": "1.5.0",
"description": "Etherspot SDK",
"keywords": [
"ether",
Expand Down
13 changes: 9 additions & 4 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ type GatewayBatch {
data: [String!]!
estimatedGas: Int!
estimatedGasPrice: BigNumber!
feeAmount: BigNumber!
feeData: String!
feeToken: String
hash: String!
logs: [GatewayBatchLog!]!
nonce: Int!
Expand Down Expand Up @@ -183,6 +186,8 @@ type GatewayEstimatedBatch {
estimatedGas: Int!
estimatedGasPrice: BigNumber!
expiredAt: DateTime!
feeAmount: BigNumber!
feeTokenReceiver: String
refundAmount: BigNumber!
refundTokenPayee: String
signature: String!
Expand All @@ -191,7 +196,7 @@ type GatewayEstimatedBatch {
type GatewayEstimatedKnownOp {
estimatedGas: Int!
estimatedGasPrice: BigNumber!
refundAmount: BigNumber!
feeAmount: BigNumber!
}

type GatewaySender {
Expand Down Expand Up @@ -236,12 +241,12 @@ type Mutation {
createSessionCode(account: String!, chainId: Int): String!
deactivatePaymentHubBridge(acceptedChainId: Int!, acceptedToken: String, chainId: Int, hub: String!, token: String): PaymentHubBridge!
destroySession(chainId: Int): Boolean!
estimateGatewayBatch(account: String!, chainId: Int, data: [String!]!, nonce: Int!, refundToken: String, to: [String!]!): GatewayEstimatedBatch!
estimateGatewayKnownOp(account: String!, chainId: Int, op: GatewayKnownOps!, refundToken: String): GatewayEstimatedKnownOp!
estimateGatewayBatch(account: String!, chainId: Int, data: [String!]!, feeToken: String, nonce: Int!, refundToken: String, to: [String!]!): GatewayEstimatedBatch!
estimateGatewayKnownOp(account: String!, chainId: Int, feeToken: String, op: GatewayKnownOps!): GatewayEstimatedKnownOp!
p2pPaymentDepositWithdrawals(chainId: Int, limit: Int = 10, owner: String!, page: Int = 1, token: String): P2PPaymentDeposits!
reserveENSNode(address: String!, chainId: Int, name: String!): ENSNode!
signP2PPaymentChannel(chainId: Int, hash: String!, senderSignature: String!): P2PPaymentChannel!
submitGatewayBatch(account: String!, chainId: Int, data: [String!]!, estimatedGas: Int!, estimatedGasPrice: BigNumber!, estimationExpiredAt: DateTime!, estimationSignature: String!, nonce: Int!, refundAmount: BigNumber!, refundToken: String, senderSignature: String!, to: [String!]!): GatewayBatch!
submitGatewayBatch(account: String!, chainId: Int, data: [String!]!, estimatedGas: Int!, estimatedGasPrice: BigNumber!, estimationExpiredAt: DateTime!, estimationSignature: String!, feeAmount: BigNumber, feeToken: String, nonce: Int!, refundAmount: BigNumber, refundToken: String, senderSignature: String!, to: [String!]!): GatewayBatch!
syncAccount(chainId: Int): Account!
syncAccountMember(account: String!, chainId: Int): AccountMember!
syncP2PPaymentDeposits(chainId: Int, owner: String!, tokens: [String!] = []): P2PPaymentDeposits!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class PersonalAccountRegistryContract extends InternalContract {

encodeDeployAccount?(account: string): TransactionRequest;

encodeRefundAccountCall?(account: string, refundToken: string, refundAmount: BigNumberish): TransactionRequest;
encodeRefundAccountCall?(account: string, feeToken: string, feeAmount: BigNumberish): TransactionRequest;

encodeAddAccountOwner?(account: string, owner: string): TransactionRequest;

Expand Down
2 changes: 1 addition & 1 deletion src/sdk/dto/estimate-gateway-batch.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import { IsAddress } from './validators';
export class EstimateGatewayBatchDto {
@IsOptional()
@IsAddress()
refundToken?: string = null;
feeToken?: string = null;
}
2 changes: 1 addition & 1 deletion src/sdk/dto/estimate-gateway-known-op.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export class EstimateGatewayKnownOpDto {

@IsOptional()
@IsAddress()
refundToken?: string = null;
feeToken?: string = null;
}
4 changes: 2 additions & 2 deletions src/sdk/gateway/classes/gateway-estimated-batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { BigNumber } from 'ethers';

export class GatewayEstimatedBatch {
@TransformBigNumber()
refundAmount: BigNumber;
feeAmount: BigNumber;

refundTokenPayee: string;
feeTokenReceiver: string;

estimatedGas: number;

Expand Down
2 changes: 1 addition & 1 deletion src/sdk/gateway/classes/gateway-estimated-known-op.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BigNumber } from 'ethers';

export class GatewayEstimatedKnownOp {
@TransformBigNumber()
refundAmount: BigNumber;
feeAmount: BigNumber;

estimatedGas: number;

Expand Down
6 changes: 3 additions & 3 deletions src/sdk/gateway/classes/gateway-submitted-batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ export class GatewaySubmittedBatch {
@TransformBigNumber()
estimatedGasPrice: BigNumber;

refundToken: string;
feeToken: string;

@TransformBigNumber()
refundAmount: BigNumber;
feeAmount: BigNumber;

refundData: string;
feeData: string;

@Type(() => Date)
createdAt: Date;
Expand Down
78 changes: 39 additions & 39 deletions src/sdk/gateway/gateway.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class GatewayService extends Service {

private estimationOptions: {
nonce: number;
refundToken: string;
feeToken: string;
} = null;

get gatewayBatch(): GatewayBatch {
Expand Down Expand Up @@ -136,9 +136,9 @@ export class GatewayService extends Service {
senderSignature
estimatedGas
estimatedGasPrice
refundToken
refundAmount
refundData
feeToken
feeAmount
feeData
createdAt
updatedAt
}
Expand Down Expand Up @@ -192,9 +192,9 @@ export class GatewayService extends Service {
senderSignature
estimatedGas
estimatedGasPrice
refundToken
refundAmount
refundData
feeToken
feeAmount
feeData
createdAt
updatedAt
}
Expand All @@ -217,7 +217,7 @@ export class GatewayService extends Service {
return result;
}

async estimateGatewayBatch(refundToken: string): Promise<GatewayBatch> {
async estimateGatewayBatch(feeToken: string): Promise<GatewayBatch> {
if (!this.gatewayBatch) {
throw new Exception('Can not estimate empty batch');
}
Expand All @@ -239,18 +239,18 @@ export class GatewayService extends Service {
$nonce: Int!
$to: [String!]!
$data: [String!]!
$refundToken: String
$feeToken: String
) {
estimation: estimateGatewayBatch(
chainId: $chainId
account: $account
nonce: $nonce
to: $to
data: $data
refundToken: $refundToken
feeToken: $feeToken
) {
refundAmount
refundTokenPayee
feeAmount
feeTokenReceiver
estimatedGas
estimatedGasPrice
signature
Expand All @@ -268,14 +268,14 @@ export class GatewayService extends Service {
nonce,
to,
data,
refundToken,
feeToken,
},
},
);

this.estimationOptions = {
nonce,
refundToken,
feeToken,
};

this.gatewayBatch$.next({
Expand All @@ -286,7 +286,7 @@ export class GatewayService extends Service {
return this.gatewayBatch;
}

async estimateGatewayKnownOp(op: GatewayKnownOps, refundToken: string = null): Promise<GatewayEstimatedKnownOp> {
async estimateGatewayKnownOp(op: GatewayKnownOps, feeToken: string = null): Promise<GatewayEstimatedKnownOp> {
const { accountService, apiService } = this.services;

const account = accountService.accountAddress;
Expand All @@ -295,9 +295,9 @@ export class GatewayService extends Service {
result: GatewayEstimatedKnownOp;
}>(
gql`
mutation($chainId: Int, $account: String!, $op: GatewayKnownOps!, $refundToken: String) {
result: estimateGatewayKnownOp(chainId: $chainId, account: $account, op: $op, refundToken: $refundToken) {
refundAmount
mutation($chainId: Int, $account: String!, $op: GatewayKnownOps!, $feeToken: String) {
result: estimateGatewayKnownOp(chainId: $chainId, account: $account, op: $op, feeToken: $feeToken) {
feeAmount
estimatedGas
estimatedGasPrice
}
Expand All @@ -310,7 +310,7 @@ export class GatewayService extends Service {
variables: {
account,
op,
refundToken,
feeToken,
},
},
);
Expand All @@ -331,41 +331,41 @@ export class GatewayService extends Service {

const { to, data } = this.extractToAndData();
const {
refundTokenPayee,
refundAmount,
feeTokenReceiver,
feeAmount,
estimatedGas,
estimatedGasPrice,
expiredAt: estimationExpiredAt,
signature: estimationSignature,
} = estimation;

const { nonce, refundToken } = this.estimationOptions;
const { nonce, feeToken } = this.estimationOptions;

const { accountService, walletService, apiService } = this.services;
const { gatewayContract, personalAccountRegistryContract, erc20TokenContract } = this.internalContracts;

const account = accountService.accountAddress;

let refundTransactionRequest: TransactionRequest;
let feeTransactionRequest: TransactionRequest;

if (refundToken) {
const { data } = erc20TokenContract.encodeTransfer(refundTokenPayee, refundAmount);
if (feeToken) {
const { data } = erc20TokenContract.encodeTransfer(feeTokenReceiver, feeAmount);

refundTransactionRequest = personalAccountRegistryContract.encodeExecuteAccountTransaction(
feeTransactionRequest = personalAccountRegistryContract.encodeExecuteAccountTransaction(
account,
refundToken,
feeToken,
0,
data,
);
} else {
refundTransactionRequest = personalAccountRegistryContract.encodeRefundAccountCall(account, null, refundAmount);
feeTransactionRequest = personalAccountRegistryContract.encodeRefundAccountCall(account, null, feeAmount);
}

const messageHash = gatewayContract.hashDelegatedBatch(
account,
nonce,
[...to, refundTransactionRequest.to],
[...data, refundTransactionRequest.data],
[...to, feeTransactionRequest.to],
[...data, feeTransactionRequest.data],
);
const senderSignature = await walletService.signMessage(messageHash);

Expand All @@ -379,8 +379,8 @@ export class GatewayService extends Service {
$nonce: Int!
$to: [String!]!
$data: [String!]!
$refundToken: String
$refundAmount: BigNumber!
$feeToken: String
$feeAmount: BigNumber!
$senderSignature: String!
$estimatedGas: Int!
$estimatedGasPrice: BigNumber!
Expand All @@ -393,8 +393,8 @@ export class GatewayService extends Service {
nonce: $nonce
to: $to
data: $data
refundToken: $refundToken
refundAmount: $refundAmount
feeToken: $feeToken
feeAmount: $feeAmount
senderSignature: $senderSignature
estimatedGas: $estimatedGas
estimatedGasPrice: $estimatedGasPrice
Expand All @@ -420,9 +420,9 @@ export class GatewayService extends Service {
senderSignature
estimatedGas
estimatedGasPrice
refundToken
refundAmount
refundData
feeToken
feeAmount
feeData
createdAt
updatedAt
}
Expand All @@ -437,8 +437,8 @@ export class GatewayService extends Service {
nonce,
to,
data,
refundToken,
refundAmount,
feeToken,
feeAmount,
senderSignature,
estimatedGas,
estimatedGasPrice,
Expand Down
12 changes: 6 additions & 6 deletions src/sdk/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,15 +356,15 @@ export class Sdk {
* @return Promise<GatewayEstimatedKnownOp>
*/
async estimateGatewayKnownOp(dto: EstimateGatewayKnownOpDto): Promise<GatewayEstimatedKnownOp> {
const { op, refundToken } = await validateDto(dto, EstimateGatewayKnownOpDto, {
addressKeys: ['refundToken'],
const { op, feeToken } = await validateDto(dto, EstimateGatewayKnownOpDto, {
addressKeys: ['feeToken'],
});

await this.require({
session: true,
});

return this.services.gatewayService.estimateGatewayKnownOp(op, refundToken);
return this.services.gatewayService.estimateGatewayKnownOp(op, feeToken);
}

/**
Expand All @@ -373,16 +373,16 @@ export class Sdk {
* @return Promise<GatewayBatch>
*/
async estimateGatewayBatch(dto: EstimateGatewayBatchDto = {}): Promise<GatewayBatch> {
const { refundToken } = await validateDto(dto, EstimateGatewayBatchDto, {
addressKeys: ['refundToken'],
const { feeToken } = await validateDto(dto, EstimateGatewayBatchDto, {
addressKeys: ['feeToken'],
});

await this.require({
session: true,
contractAccount: true,
});

return this.services.gatewayService.estimateGatewayBatch(refundToken);
return this.services.gatewayService.estimateGatewayBatch(feeToken);
}

/**
Expand Down

0 comments on commit 248d44d

Please sign in to comment.