@@ -35,9 +35,9 @@ import {
35
35
coalesceModuleAddress ,
36
36
isValidAptosType ,
37
37
} from "@wormhole-foundation/sdk-aptos" ;
38
- import type { AptosClient , Types } from "aptos" ;
39
38
import { serializeForeignAddressSeeds } from "./foreignAddress.js" ;
40
39
import type { OriginInfo , TokenBridgeState } from "./types.js" ;
40
+ import { Aptos , InputGenerateTransactionPayloadData } from "@aptos-labs/ts-sdk" ;
41
41
42
42
export class AptosTokenBridge < N extends Network , C extends AptosChains >
43
43
implements TokenBridge < N , C >
@@ -48,7 +48,7 @@ export class AptosTokenBridge<N extends Network, C extends AptosChains>
48
48
constructor (
49
49
readonly network : N ,
50
50
readonly chain : C ,
51
- readonly connection : AptosClient ,
51
+ readonly connection : Aptos ,
52
52
readonly contracts : Contracts ,
53
53
) {
54
54
this . chainId = toChainId ( chain ) ;
@@ -60,7 +60,7 @@ export class AptosTokenBridge<N extends Network, C extends AptosChains>
60
60
}
61
61
62
62
static async fromRpc < N extends Network > (
63
- connection : AptosClient ,
63
+ connection : Aptos ,
64
64
config : ChainsConfig < N , AptosPlatformType > ,
65
65
) : Promise < AptosTokenBridge < N , AptosChains > > {
66
66
const [ network , chain ] = await AptosPlatform . chainFromRpc ( connection ) ;
@@ -81,14 +81,11 @@ export class AptosTokenBridge<N extends Network, C extends AptosChains>
81
81
82
82
async getOriginalAsset ( token : AnyAptosAddress ) : Promise < TokenId > {
83
83
const fqt = token . toString ( ) . split ( APTOS_SEPARATOR ) ;
84
- let originInfo : OriginInfo | undefined ;
85
84
86
- originInfo = (
87
- await this . connection . getAccountResource (
88
- fqt [ 0 ] ! ,
89
- `${ this . tokenBridgeAddress } ::state::OriginInfo` ,
90
- )
91
- ) . data as OriginInfo ;
85
+ const originInfo = await this . connection . getAccountResource < OriginInfo > ( {
86
+ accountAddress : fqt [ 0 ] ! ,
87
+ resourceType : `${ this . tokenBridgeAddress } ::state::OriginInfo` ,
88
+ } ) ;
92
89
93
90
if ( ! originInfo ) throw ErrNotWrapped ( token . toString ( ) ) ;
94
91
@@ -131,32 +128,33 @@ export class AptosTokenBridge<N extends Network, C extends AptosChains>
131
128
if ( ! assetFullyQualifiedType ) throw new Error ( "Invalid asset address." ) ;
132
129
133
130
// check to see if we can get origin info from asset address
134
- await this . connection . getAccountResource (
135
- coalesceModuleAddress ( assetFullyQualifiedType ) ,
136
- `${ this . tokenBridgeAddress } ::state::OriginInfo` ,
137
- ) ;
131
+ await this . connection . getAccountResource ( {
132
+ accountAddress : coalesceModuleAddress ( assetFullyQualifiedType ) ,
133
+ resourceType : `${ this . tokenBridgeAddress } ::state::OriginInfo` ,
134
+ } ) ;
138
135
139
136
// if successful, we can just return the computed address
140
137
return toNative ( this . chain , assetFullyQualifiedType ) ;
141
138
}
142
139
143
140
async isTransferCompleted ( vaa : TokenBridge . TransferVAA ) : Promise < boolean > {
144
- const state = (
145
- await this . connection . getAccountResource (
146
- this . tokenBridgeAddress ,
147
- `${ this . tokenBridgeAddress } ::state::State` ,
148
- )
149
- ) . data as TokenBridgeState ;
141
+ const state = await this . connection . getAccountResource < TokenBridgeState > ( {
142
+ accountAddress : this . tokenBridgeAddress ,
143
+ resourceType : `${ this . tokenBridgeAddress } ::state::State` ,
144
+ } ) ;
150
145
151
146
const handle = state . consumed_vaas . elems . handle ;
152
147
153
148
// check if vaa hash is in consumed_vaas
154
149
try {
155
150
// when accessing Set<T>, key is type T and value is 0
156
- await this . connection . getTableItem ( handle , {
157
- key_type : "vector<u8>" ,
158
- value_type : "u8" ,
159
- key : `0x${ Buffer . from ( keccak256 ( vaa . hash ) ) . toString ( "hex" ) } ` ,
151
+ await this . connection . getTableItem ( {
152
+ handle,
153
+ data : {
154
+ key_type : "vector<u8>" ,
155
+ value_type : "u8" ,
156
+ key : `0x${ Buffer . from ( keccak256 ( vaa . hash ) ) . toString ( "hex" ) } ` ,
157
+ } ,
160
158
} ) ;
161
159
return true ;
162
160
} catch {
@@ -179,8 +177,8 @@ export class AptosTokenBridge<N extends Network, C extends AptosChains>
179
177
yield this . createUnsignedTx (
180
178
{
181
179
function : `${ this . tokenBridgeAddress } ::attest_token::attest_token_entry` ,
182
- type_arguments : [ assetType ] ,
183
- arguments : [ ] ,
180
+ typeArguments : [ assetType ] ,
181
+ functionArguments : [ ] ,
184
182
} ,
185
183
"Aptos.AttestToken" ,
186
184
) ;
@@ -193,8 +191,8 @@ export class AptosTokenBridge<N extends Network, C extends AptosChains>
193
191
yield this . createUnsignedTx (
194
192
{
195
193
function : `${ this . tokenBridgeAddress } ::wrapped::create_wrapped_coin_type` ,
196
- type_arguments : [ ] ,
197
- arguments : [ serialize ( vaa ) ] ,
194
+ typeArguments : [ ] ,
195
+ functionArguments : [ serialize ( vaa ) ] ,
198
196
} ,
199
197
"Aptos.CreateWrappedCoinType" ,
200
198
) ;
@@ -205,8 +203,8 @@ export class AptosTokenBridge<N extends Network, C extends AptosChains>
205
203
yield this . createUnsignedTx (
206
204
{
207
205
function : `${ this . tokenBridgeAddress } ::wrapped::create_wrapped_coin` ,
208
- type_arguments : [ assetType ] ,
209
- arguments : [ serialize ( vaa ) ] ,
206
+ typeArguments : [ assetType ] ,
207
+ functionArguments : [ serialize ( vaa ) ] ,
210
208
} ,
211
209
"Aptos.CreateWrappedCoin" ,
212
210
) ;
@@ -230,17 +228,17 @@ export class AptosTokenBridge<N extends Network, C extends AptosChains>
230
228
yield this . createUnsignedTx (
231
229
{
232
230
function : `${ this . tokenBridgeAddress } ::transfer_tokens::transfer_tokens_with_payload_entry` ,
233
- type_arguments : [ fullyQualifiedType ] ,
234
- arguments : [ amount , dstChain , dstAddress , nonce , payload ] ,
231
+ typeArguments : [ fullyQualifiedType ] ,
232
+ functionArguments : [ amount , dstChain , dstAddress , nonce , payload ] ,
235
233
} ,
236
234
"Aptos.TransferTokensWithPayload" ,
237
235
) ;
238
236
} else {
239
237
yield this . createUnsignedTx (
240
238
{
241
239
function : `${ this . tokenBridgeAddress } ::transfer_tokens::transfer_tokens_entry` ,
242
- type_arguments : [ fullyQualifiedType ] ,
243
- arguments : [ amount , dstChain , dstAddress , fee , nonce ] ,
240
+ typeArguments : [ fullyQualifiedType ] ,
241
+ functionArguments : [ amount , dstChain , dstAddress , fee , nonce ] ,
244
242
} ,
245
243
"Aptos.TransferTokens" ,
246
244
) ;
@@ -262,8 +260,8 @@ export class AptosTokenBridge<N extends Network, C extends AptosChains>
262
260
yield this . createUnsignedTx (
263
261
{
264
262
function : `${ this . tokenBridgeAddress } ::complete_transfer::submit_vaa_and_register_entry` ,
265
- type_arguments : [ assetType ] ,
266
- arguments : [ serialize ( vaa ) ] ,
263
+ typeArguments : [ assetType ] ,
264
+ functionArguments : [ serialize ( vaa ) ] ,
267
265
} ,
268
266
"Aptos.CompleteTransfer" ,
269
267
) ;
@@ -296,19 +294,20 @@ export class AptosTokenBridge<N extends Network, C extends AptosChains>
296
294
async getTypeFromExternalAddress ( address : string ) : Promise < string | null > {
297
295
try {
298
296
// get handle
299
- const state = (
300
- await this . connection . getAccountResource (
301
- this . tokenBridgeAddress ,
302
- `${ this . tokenBridgeAddress } ::state::State` ,
303
- )
304
- ) . data as TokenBridgeState ;
297
+ const state = await this . connection . getAccountResource < TokenBridgeState > ( {
298
+ accountAddress : this . tokenBridgeAddress ,
299
+ resourceType : `${ this . tokenBridgeAddress } ::state::State` ,
300
+ } ) ;
305
301
const { handle } = state . native_infos ;
306
302
307
303
// get type info
308
- const typeInfo = await this . connection . getTableItem ( handle , {
309
- key_type : `${ this . tokenBridgeAddress } ::token_hash::TokenHash` ,
310
- value_type : "0x1::type_info::TypeInfo" ,
311
- key : { hash : address } ,
304
+ const typeInfo : any = await this . connection . getTableItem ( {
305
+ handle,
306
+ data : {
307
+ key_type : `${ this . tokenBridgeAddress } ::token_hash::TokenHash` ,
308
+ value_type : "0x1::type_info::TypeInfo" ,
309
+ key : { hash : address } ,
310
+ } ,
312
311
} ) ;
313
312
314
313
return typeInfo
@@ -346,7 +345,7 @@ export class AptosTokenBridge<N extends Network, C extends AptosChains>
346
345
}
347
346
348
347
private createUnsignedTx (
349
- txReq : Types . EntryFunctionPayload ,
348
+ txReq : InputGenerateTransactionPayloadData ,
350
349
description : string ,
351
350
parallelizable : boolean = false ,
352
351
) : AptosUnsignedTransaction < N , C > {
0 commit comments