Skip to content

Commit 681fc65

Browse files
committed
migrate to vft manager
1 parent 00b0ca2 commit 681fc65

File tree

11 files changed

+299
-280
lines changed

11 files changed

+299
-280
lines changed

frontend/src/consts/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { FUNGIBLE_TOKEN_ABI } from './abi';
22
import { VARA_NODE_ADDRESS, ETH_NODE_ADDRESS, ETH_CHAIN_ID, BRIDGING_PAYMENT_CONTRACT_ADDRESS } from './env';
33
import { ROUTE } from './routing';
4-
import { BridgingPaymentProgram, VftGatewayProgram, VftProgram } from './sails';
4+
import { BridgingPaymentProgram, VftManagerProgram, VftProgram } from './sails';
55

66
export {
77
FUNGIBLE_TOKEN_ABI,
@@ -11,6 +11,6 @@ export {
1111
BRIDGING_PAYMENT_CONTRACT_ADDRESS,
1212
ROUTE,
1313
BridgingPaymentProgram,
14-
VftGatewayProgram,
14+
VftManagerProgram,
1515
VftProgram,
1616
};

frontend/src/consts/sails/bridging-payment.ts

Lines changed: 21 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,36 @@
11
/* eslint-disable @typescript-eslint/no-floating-promises */
22
/* eslint-disable @typescript-eslint/no-explicit-any */
3-
43
import { GearApi, decodeAddress } from '@gear-js/api';
54
import { TypeRegistry } from '@polkadot/types';
6-
import {
7-
ActorId,
8-
H160,
9-
TransactionBuilder,
10-
MessageId,
11-
getServiceNamePrefix,
12-
getFnNamePrefix,
13-
ZERO_ADDRESS,
14-
} from 'sails-js';
5+
import { TransactionBuilder, H160, ActorId, getServiceNamePrefix, getFnNamePrefix, ZERO_ADDRESS } from 'sails-js';
156

167
export interface InitConfig {
178
admin_address: ActorId;
18-
vft_gateway_address: ActorId;
9+
vft_manager_address: ActorId;
1910
config: Config;
2011
}
2112

2213
export interface Config {
2314
fee: number | string | bigint;
2415
gas_for_reply_deposit: number | string | bigint;
25-
gas_to_send_request_to_gateway: number | string | bigint;
26-
gas_to_transfer_tokens: number | string | bigint;
16+
gas_to_send_request_to_vft_manager: number | string | bigint;
2717
reply_timeout: number;
28-
gas_for_request_to_gateway_msg: number | string | bigint;
29-
}
30-
31-
export interface MessageInfo {
32-
status: MessageStatus;
33-
details: TransactionDetails;
18+
gas_for_request_to_vft_manager_msg: number | string | bigint;
3419
}
3520

36-
export type MessageStatus =
37-
| { sendingMessageToTransferTokens: null }
38-
| { tokenTransferCompleted: boolean }
39-
| { waitingReplyFromTokenTransfer: null }
40-
| { sendingMessageToGateway: null }
41-
| { gatewayMessageProcessingCompleted: [number | string | bigint, H160] }
42-
| { waitingReplyFromGateway: null }
43-
| { messageToGatewayStep: null }
44-
| { returnTokensBackStep: null }
45-
| { sendingMessageToTransferTokensBack: null }
46-
| { waitingReplyFromTokenTransferBack: null }
47-
| { tokenTransferBackCompleted: null }
48-
| { messageProcessedWithSuccess: [number | string | bigint, H160] };
49-
50-
export type TransactionDetails =
51-
| { transfer: { sender: ActorId; receiver: ActorId; amount: number | string | bigint; token_id: ActorId } }
52-
| {
53-
sendMessageToGateway: {
54-
sender: ActorId;
55-
vara_token_id: ActorId;
56-
amount: number | string | bigint;
57-
receiver: H160;
58-
attached_value: number | string | bigint;
59-
};
60-
};
61-
6221
export class Program {
6322
public readonly registry: TypeRegistry;
6423
public readonly bridgingPayment: BridgingPayment;
6524

6625
constructor(public api: GearApi, public programId?: `0x${string}`) {
6726
const types: Record<string, any> = {
68-
InitConfig: { admin_address: '[u8;32]', vft_gateway_address: '[u8;32]', config: 'Config' },
27+
InitConfig: { admin_address: '[u8;32]', vft_manager_address: '[u8;32]', config: 'Config' },
6928
Config: {
7029
fee: 'u128',
7130
gas_for_reply_deposit: 'u64',
72-
gas_to_send_request_to_gateway: 'u64',
73-
gas_to_transfer_tokens: 'u64',
31+
gas_to_send_request_to_vft_manager: 'u64',
7432
reply_timeout: 'u32',
75-
gas_for_request_to_gateway_msg: 'u64',
76-
},
77-
MessageInfo: { status: 'MessageStatus', details: 'TransactionDetails' },
78-
MessageStatus: {
79-
_enum: {
80-
SendingMessageToTransferTokens: 'Null',
81-
TokenTransferCompleted: 'bool',
82-
WaitingReplyFromTokenTransfer: 'Null',
83-
SendingMessageToGateway: 'Null',
84-
GatewayMessageProcessingCompleted: '(U256, H160)',
85-
WaitingReplyFromGateway: 'Null',
86-
MessageToGatewayStep: 'Null',
87-
ReturnTokensBackStep: 'Null',
88-
SendingMessageToTransferTokensBack: 'Null',
89-
WaitingReplyFromTokenTransferBack: 'Null',
90-
TokenTransferBackCompleted: 'Null',
91-
MessageProcessedWithSuccess: '(U256, H160)',
92-
},
93-
},
94-
TransactionDetails: {
95-
_enum: {
96-
Transfer: { sender: '[u8;32]', receiver: '[u8;32]', amount: 'U256', token_id: '[u8;32]' },
97-
SendMessageToGateway: {
98-
sender: '[u8;32]',
99-
vara_token_id: '[u8;32]',
100-
amount: 'U256',
101-
receiver: 'H160',
102-
attached_value: 'u128',
103-
},
104-
},
33+
gas_for_request_to_vft_manager_msg: 'u64',
10534
},
10635
};
10736

@@ -146,14 +75,18 @@ export class Program {
14675
export class BridgingPayment {
14776
constructor(private _program: Program) {}
14877

149-
public continueTransaction(msg_id: MessageId): TransactionBuilder<null> {
78+
public makeRequest(
79+
amount: number | string | bigint,
80+
receiver: H160,
81+
vara_token_id: ActorId,
82+
): TransactionBuilder<null> {
15083
if (!this._program.programId) throw new Error('Program ID is not set');
15184
return new TransactionBuilder<null>(
15285
this._program.api,
15386
this._program.registry,
15487
'send_message',
155-
['BridgingPayment', 'ContinueTransaction', msg_id],
156-
'(String, String, [u8;32])',
88+
['BridgingPayment', 'MakeRequest', amount, receiver, vara_token_id],
89+
'(String, String, U256, H160, [u8;32])',
15790
'Null',
15891
this._program.programId,
15992
);
@@ -172,31 +105,14 @@ export class BridgingPayment {
172105
);
173106
}
174107

175-
public requestToGateway(
176-
amount: number | string | bigint,
177-
receiver: H160,
178-
vara_token_id: ActorId,
179-
): TransactionBuilder<null> {
180-
if (!this._program.programId) throw new Error('Program ID is not set');
181-
return new TransactionBuilder<null>(
182-
this._program.api,
183-
this._program.registry,
184-
'send_message',
185-
['BridgingPayment', 'RequestToGateway', amount, receiver, vara_token_id],
186-
'(String, String, U256, H160, [u8;32])',
187-
'Null',
188-
this._program.programId,
189-
);
190-
}
191-
192-
public returnTokens(msg_id: MessageId): TransactionBuilder<null> {
108+
public setConfig(config: Config): TransactionBuilder<null> {
193109
if (!this._program.programId) throw new Error('Program ID is not set');
194110
return new TransactionBuilder<null>(
195111
this._program.api,
196112
this._program.registry,
197113
'send_message',
198-
['BridgingPayment', 'ReturnTokens', msg_id],
199-
'(String, String, [u8;32])',
114+
['BridgingPayment', 'SetConfig', config],
115+
'(String, String, Config)',
200116
'Null',
201117
this._program.programId,
202118
);
@@ -215,42 +131,13 @@ export class BridgingPayment {
215131
);
216132
}
217133

218-
public updateConfig(
219-
fee: number | string | bigint | null,
220-
gas_for_reply_deposit: number | string | bigint | null,
221-
gas_to_send_request_to_gateway: number | string | bigint | null,
222-
gas_to_transfer_tokens: number | string | bigint | null,
223-
reply_timeout: number | null,
224-
gas_for_request_to_gateway_msg: number | string | bigint | null,
225-
): TransactionBuilder<null> {
134+
public updateVftManagerAddress(new_vft_manager_address: ActorId): TransactionBuilder<null> {
226135
if (!this._program.programId) throw new Error('Program ID is not set');
227136
return new TransactionBuilder<null>(
228137
this._program.api,
229138
this._program.registry,
230139
'send_message',
231-
[
232-
'BridgingPayment',
233-
'UpdateConfig',
234-
fee,
235-
gas_for_reply_deposit,
236-
gas_to_send_request_to_gateway,
237-
gas_to_transfer_tokens,
238-
reply_timeout,
239-
gas_for_request_to_gateway_msg,
240-
],
241-
'(String, String, Option<u128>, Option<u64>, Option<u64>, Option<u64>, Option<u32>, Option<u64>)',
242-
'Null',
243-
this._program.programId,
244-
);
245-
}
246-
247-
public updateVftGatewayAddress(new_vft_gateway_address: ActorId): TransactionBuilder<null> {
248-
if (!this._program.programId) throw new Error('Program ID is not set');
249-
return new TransactionBuilder<null>(
250-
this._program.api,
251-
this._program.registry,
252-
'send_message',
253-
['BridgingPayment', 'UpdateVftGatewayAddress', new_vft_gateway_address],
140+
['BridgingPayment', 'UpdateVftManagerAddress', new_vft_manager_address],
254141
'(String, String, [u8;32])',
255142
'Null',
256143
this._program.programId,
@@ -295,34 +182,13 @@ export class BridgingPayment {
295182
return result[2].toJSON() as unknown as Config;
296183
}
297184

298-
public async msgTrackerState(
299-
originAddress?: string,
300-
value?: number | string | bigint,
301-
atBlock?: `0x${string}`,
302-
): Promise<Array<[MessageId, MessageInfo]>> {
303-
const payload = this._program.registry
304-
.createType('(String, String)', ['BridgingPayment', 'MsgTrackerState'])
305-
.toHex();
306-
const reply = await this._program.api.message.calculateReply({
307-
destination: this._program.programId!,
308-
origin: originAddress ? decodeAddress(originAddress) : ZERO_ADDRESS,
309-
payload,
310-
value: value || 0,
311-
gasLimit: this._program.api.blockGasLimit.toBigInt(),
312-
at: atBlock,
313-
});
314-
if (!reply.code.isSuccess) throw new Error(this._program.registry.createType('String', reply.payload).toString());
315-
const result = this._program.registry.createType('(String, String, Vec<([u8;32], MessageInfo)>)', reply.payload);
316-
return result[2].toJSON() as unknown as Array<[MessageId, MessageInfo]>;
317-
}
318-
319-
public async vftGatewayAddress(
185+
public async vftManagerAddress(
320186
originAddress?: string,
321187
value?: number | string | bigint,
322188
atBlock?: `0x${string}`,
323189
): Promise<ActorId> {
324190
const payload = this._program.registry
325-
.createType('(String, String)', ['BridgingPayment', 'VftGatewayAddress'])
191+
.createType('(String, String)', ['BridgingPayment', 'VftManagerAddress'])
326192
.toHex();
327193
const reply = await this._program.api.message.calculateReply({
328194
destination: this._program.programId!,

frontend/src/consts/sails/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Program as BridgingPaymentProgram } from './bridging-payment';
22
import { Program as VftProgram } from './extended_vft';
3-
import { Program as VftGatewayProgram } from './vft-gateway';
3+
import { Program as VftManagerProgram } from './vft-manager';
44

5-
export { BridgingPaymentProgram, VftGatewayProgram, VftProgram };
5+
export { BridgingPaymentProgram, VftManagerProgram, VftProgram };

0 commit comments

Comments
 (0)