Skip to content

Commit 1cb5caf

Browse files
Asset Type simplification
1 parent a03c7b0 commit 1cb5caf

File tree

70 files changed

+295
-410
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+295
-410
lines changed

packages/cactus-plugin-satp-hermes/src/main/json/openapi-blo-bundled.json

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,8 @@
141141
"tokenType": {
142142
"type": "string",
143143
"enum": [
144-
"ERC20",
145-
"ERC721",
146-
"ERC1155",
147-
"NONSTANDARD_FUNGIBLE",
148-
"NONSTANDARD_NONFUNGIBLE"
144+
"FUNGIBLE",
145+
"NONFUNGIBLE"
149146
],
150147
"description": "The type of token."
151148
},
@@ -217,11 +214,8 @@
217214
"tokenType": {
218215
"type": "string",
219216
"enum": [
220-
"ERC20",
221-
"ERC721",
222-
"ERC1155",
223-
"NONSTANDARD_FUNGIBLE",
224-
"NONSTANDARD_NONFUNGIBLE"
217+
"FUNGIBLE",
218+
"NONFUNGIBLE"
225219
],
226220
"description": "The type of token."
227221
},
@@ -2641,11 +2635,8 @@
26412635
"schema": {
26422636
"type": "string",
26432637
"enum": [
2644-
"ERC20",
2645-
"ERC721",
2646-
"ERC1155",
2647-
"NONSTANDARD_FUNGIBLE",
2648-
"NONSTANDARD_NONFUNGIBLE"
2638+
"FUNGIBLE",
2639+
"NONFUNGIBLE"
26492640
],
26502641
"description": "The type of token."
26512642
},
@@ -4587,11 +4578,8 @@
45874578
"tokenType": {
45884579
"type": "string",
45894580
"enum": [
4590-
"ERC20",
4591-
"ERC721",
4592-
"ERC1155",
4593-
"NONSTANDARD_FUNGIBLE",
4594-
"NONSTANDARD_NONFUNGIBLE"
4581+
"FUNGIBLE",
4582+
"NONFUNGIBLE"
45954583
],
45964584
"description": "The type of token."
45974585
},
@@ -4681,11 +4669,8 @@
46814669
"tokenType": {
46824670
"type": "string",
46834671
"enum": [
4684-
"ERC20",
4685-
"ERC721",
4686-
"ERC1155",
4687-
"NONSTANDARD_FUNGIBLE",
4688-
"NONSTANDARD_NONFUNGIBLE"
4672+
"FUNGIBLE",
4673+
"NONFUNGIBLE"
46894674
],
46904675
"description": "The type of token."
46914676
},
@@ -4757,11 +4742,8 @@
47574742
"tokenType": {
47584743
"type": "string",
47594744
"enum": [
4760-
"ERC20",
4761-
"ERC721",
4762-
"ERC1155",
4763-
"NONSTANDARD_FUNGIBLE",
4764-
"NONSTANDARD_NONFUNGIBLE"
4745+
"FUNGIBLE",
4746+
"NONFUNGIBLE"
47654747
],
47664748
"description": "The type of token."
47674749
},
@@ -8261,11 +8243,8 @@
82618243
"tokenType": {
82628244
"type": "string",
82638245
"enum": [
8264-
"ERC20",
8265-
"ERC721",
8266-
"ERC1155",
8267-
"NONSTANDARD_FUNGIBLE",
8268-
"NONSTANDARD_NONFUNGIBLE"
8246+
"FUNGIBLE",
8247+
"NONFUNGIBLE"
82698248
],
82708249
"description": "The type of token."
82718250
}
@@ -10024,11 +10003,8 @@
1002410003
"TokenType": {
1002510004
"type": "string",
1002610005
"enum": [
10027-
"ERC20",
10028-
"ERC721",
10029-
"ERC1155",
10030-
"NONSTANDARD_FUNGIBLE",
10031-
"NONSTANDARD_NONFUNGIBLE"
10006+
"FUNGIBLE",
10007+
"NONFUNGIBLE"
1003210008
],
1003310009
"description": "The type of token."
1003410010
},

packages/cactus-plugin-satp-hermes/src/main/proto/cacti/satp/v02/common/message.proto

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,8 @@ message WrapAssertionClaim {
277277

278278
enum TokenType {
279279
TOKEN_TYPE_UNSPECIFIED = 0;
280-
TOKEN_TYPE_ERC20 = 1;
281-
TOKEN_TYPE_ERC721 = 2;
282-
TOKEN_TYPE_ERC1155 = 3;
283-
TOKEN_TYPE_NONSTANDARD_FUNGIBLE = 4;
284-
TOKEN_TYPE_NONSTANDARD_NONFUNGIBLE = 5;
280+
TOKEN_TYPE_FUNGIBLE = 1;
281+
TOKEN_TYPE_NONFUNGIBLE = 2;
285282
}
286283

287284
message Asset {

packages/cactus-plugin-satp-hermes/src/main/solidity/contracts/SATPWrapperContract.sol

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
99
/**
1010
* @dev Enum for the supported token types.
1111
*/
12-
enum TokenType { UNSPECIFIED, ERC20, ERC721, ERC1155, NONSTANDARD_FUNGIBLE, NONSTANDARD_NONFUNGIBLE } //TODO: FIX THIS ENUM TO BE THE SAME OF THE BRIDGE
12+
enum TokenType { UNSPECIFIED, FUNGIBLE, NONFUNGIBLE } //TODO: FIX THIS ENUM TO BE THE SAME OF THE BRIDGE
1313
/**
1414
* @dev Enum for the supported interaction types.
1515
*/
@@ -167,12 +167,12 @@ contract SATPWrapperContract is Ownable, ITraceableContract, IERC721Receiver{
167167
revert TokenNotAvailable(tokenId);
168168
}
169169
TokenType tt = tokens[tokenId].tokenType;
170-
if(tt == TokenType.NONSTANDARD_FUNGIBLE || tt == TokenType.ERC20) {
170+
if(tt == TokenType.FUNGIBLE) {
171171
if(tokens[tokenId].amount > 0) {
172172
revert TokenLocked(tokenId);
173173
}
174174
}
175-
else if(tt == TokenType.NONSTANDARD_NONFUNGIBLE || tt == TokenType.ERC721) {
175+
else if(tt == TokenType.NONFUNGIBLE) {
176176
if(tokens[tokenId].amount != 0) {
177177
revert TokenLocked(tokenId);
178178
}
@@ -201,11 +201,11 @@ contract SATPWrapperContract is Ownable, ITraceableContract, IERC721Receiver{
201201

202202
if(lockSuccess) {
203203
TokenType tt = tokens[tokenId].tokenType;
204-
if (tt == TokenType.ERC20 || tt == TokenType.NONSTANDARD_FUNGIBLE) {
204+
if (tt == TokenType.FUNGIBLE) {
205205
// The locked amount is added to the amount of the token struct
206206
tokens[tokenId].amount += assetAttribute;
207207
}
208-
else if (tt == TokenType.ERC721 || tt == TokenType.NONSTANDARD_NONFUNGIBLE) {
208+
else if (tt == TokenType.NONFUNGIBLE) {
209209
// When dealing with non-fungible tokens, the "amount" is interpreted as the token unique descriptor.
210210
if(tokens[tokenId].amount != 0) {
211211
revert TokenAlreadyLocked(tokenId);
@@ -232,7 +232,7 @@ contract SATPWrapperContract is Ownable, ITraceableContract, IERC721Receiver{
232232
revert TokenNotAvailable(tokenId);
233233
}
234234
TokenType tt = tokens[tokenId].tokenType;
235-
if (tt == TokenType.ERC20 || tt == TokenType.NONSTANDARD_FUNGIBLE) {
235+
if (tt == TokenType.FUNGIBLE) {
236236
if(tokens[tokenId].amount < assetAttribute) {
237237
revert InsuficientAmountLocked(tokenId, assetAttribute);
238238
}
@@ -241,7 +241,7 @@ contract SATPWrapperContract is Ownable, ITraceableContract, IERC721Receiver{
241241
emit Unlock(tokenId, assetAttribute);
242242
return true;
243243
}
244-
else if (tt == TokenType.ERC721 || tt == TokenType.NONSTANDARD_NONFUNGIBLE) {
244+
else if (tt == TokenType.NONFUNGIBLE) {
245245
// The provided value to unlock should be equal to what is stored logically as the unique descriptor of the NFT.
246246
require(tokens[tokenId].amount != 0, "Trying to Unlock an asset that is not locked");
247247
require(tokens[tokenId].amount == assetAttribute, "Unlocking NFT cannot be done due to wrong uniqueDescriptor");
@@ -280,7 +280,7 @@ contract SATPWrapperContract is Ownable, ITraceableContract, IERC721Receiver{
280280
*/
281281
function burn(string memory tokenId, uint256 assetAttribute) external onlyOwner returns (bool success) {
282282
TokenType tt = tokens[tokenId].tokenType;
283-
if (tt == TokenType.ERC20 || tt == TokenType.NONSTANDARD_FUNGIBLE) {
283+
if (tt == TokenType.FUNGIBLE) {
284284
require(tokens[tokenId].amount >= assetAttribute, "burn asset asset is not locked");
285285

286286
require(interact(tokenId, InteractionType.BURN, assetAttribute), "burn asset call failed");
@@ -290,7 +290,7 @@ contract SATPWrapperContract is Ownable, ITraceableContract, IERC721Receiver{
290290
emit Burn(tokenId, assetAttribute);
291291
return true;
292292
}
293-
else if (tt == TokenType.ERC721 || tt == TokenType.NONSTANDARD_NONFUNGIBLE) {
293+
else if (tt == TokenType.NONFUNGIBLE) {
294294
require(tokens[tokenId].amount != 0, "Burning unminted asset");
295295

296296
require(tokens[tokenId].amount == assetAttribute, "Burning NFT failed due to wrong uniqueDescriptor");
@@ -315,7 +315,7 @@ contract SATPWrapperContract is Ownable, ITraceableContract, IERC721Receiver{
315315
*/
316316
function assign(string memory tokenId, address receiver_account, uint256 assetAttribute) external onlyOwner returns (bool success) {
317317
TokenType tt = tokens[tokenId].tokenType;
318-
if (tt == TokenType.ERC20 || tt == TokenType.NONSTANDARD_FUNGIBLE) {
318+
if (tt == TokenType.FUNGIBLE) {
319319
require(tokens[tokenId].amount >= assetAttribute, "assign asset asset is not locked");
320320

321321
require(interact(tokenId, InteractionType.ASSIGN, assetAttribute, receiver_account), "assign asset call failed");
@@ -325,7 +325,7 @@ contract SATPWrapperContract is Ownable, ITraceableContract, IERC721Receiver{
325325
emit Assign(tokenId, receiver_account, assetAttribute);
326326
return true;
327327
}
328-
else if (tt == TokenType.ERC721 || tt == TokenType.NONSTANDARD_NONFUNGIBLE) {
328+
else if (tt == TokenType.NONFUNGIBLE) {
329329
require(tokens[tokenId].amount == assetAttribute, "Assign nft - asset is not locked");
330330

331331
require(interact(tokenId, InteractionType.ASSIGN, assetAttribute, receiver_account), "assign nft call failed");

packages/cactus-plugin-satp-hermes/src/main/solidity/generated/SATPWrapperContract.sol/SATPWrapperContract.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

packages/cactus-plugin-satp-hermes/src/main/typescript/core/satp-utils.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ export function buildAndCheckAsset(
6161
let token: Asset;
6262

6363
switch (sessionAsset.tokenType) {
64-
case TokenType.ERC20:
65-
case TokenType.NONSTANDARD_FUNGIBLE:
64+
case TokenType.FUNGIBLE:
6665
token = protoToAsset(sessionAsset, networkId) as Asset;
6766
if (token.id == undefined) {
6867
throw new TokenIdMissingError(fnTag);
@@ -77,8 +76,7 @@ export function buildAndCheckAsset(
7776
`${fnTag}, ${protocolStep} Asset ID: ${token.id} amount: ${token.amount}`,
7877
);
7978
return { token: token, networkId: networkId } as SessionAssetBuildData;
80-
case TokenType.ERC721:
81-
case TokenType.NONSTANDARD_NONFUNGIBLE:
79+
case TokenType.NONFUNGIBLE:
8280
token = protoToAsset(sessionAsset, networkId) as Asset;
8381
if (token.id == undefined) {
8482
throw new TokenIdMissingError(fnTag);

packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/client/stage0-client-service.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,7 @@ export class Stage0ClientService extends SATPService {
461461
let token: FungibleAsset | NonFungibleAsset;
462462

463463
switch (sessionData.senderAsset.tokenType) {
464-
case TokenType.ERC20:
465-
case TokenType.NONSTANDARD_FUNGIBLE:
464+
case TokenType.FUNGIBLE:
466465
this.Log.debug(`${fnTag}, Sender Asset is a fungible token`);
467466
token = protoToAsset(
468467
sessionData.senderAsset,
@@ -480,8 +479,7 @@ export class Stage0ClientService extends SATPService {
480479
`${fnTag}, Wrap Asset ID: ${token.id} amount: ${(token as FungibleAsset).amount.toString()}`,
481480
);
482481
break;
483-
case TokenType.ERC721:
484-
case TokenType.NONSTANDARD_NONFUNGIBLE:
482+
case TokenType.NONFUNGIBLE:
485483
this.Log.debug(`${fnTag}, Sender Asset is a non fungible token`);
486484
token = protoToAsset(
487485
sessionData.senderAsset,

packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/service-utils.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,13 @@ export function assetToProto(asset: Asset, networkId: NetworkId): ProtoAsset {
3232
case LedgerType.Besu2X:
3333
case LedgerType.Ethereum:
3434
switch (asset.type) {
35-
case TokenType.ERC20:
36-
case TokenType.NONSTANDARD_FUNGIBLE:
35+
case TokenType.FUNGIBLE:
3736
protoAsset.amount = BigInt((asset as EvmFungibleAsset).amount);
3837
protoAsset.contractAddress = (
3938
asset as EvmFungibleAsset
4039
).contractAddress;
4140
break;
42-
case TokenType.ERC721:
43-
case TokenType.NONSTANDARD_NONFUNGIBLE:
41+
case TokenType.NONFUNGIBLE:
4442
protoAsset.amount = BigInt(
4543
(asset as EvmNonFungibleAsset).uniqueDescriptor,
4644
);
@@ -72,15 +70,9 @@ export function protoToAsset(asset: ProtoAsset, networkId: NetworkId): Asset {
7270
contractName: asset.contractName,
7371
network: networkId,
7472
};
75-
if (
76-
asset.tokenType == TokenType.ERC20 ||
77-
asset.tokenType == TokenType.NONSTANDARD_FUNGIBLE
78-
) {
73+
if (asset.tokenType == TokenType.FUNGIBLE) {
7974
(assetObj as FungibleAsset).amount = Number(asset.amount) as Amount;
80-
} else if (
81-
asset.tokenType == TokenType.ERC721 ||
82-
asset.tokenType == TokenType.NONSTANDARD_NONFUNGIBLE
83-
) {
75+
} else if (asset.tokenType == TokenType.NONFUNGIBLE) {
8476
(assetObj as NonFungibleAsset).uniqueDescriptor = Number(
8577
asset.amount,
8678
) as UniqueTokenID;

packages/cactus-plugin-satp-hermes/src/main/typescript/cross-chain-mechanisms/bridge/leafs/besu-leaf.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,8 @@ export class BesuLeaf
318318
`${fnTag}, Getting Approve Address for asset type: ${getEnumKeyByValue(TokenType, assetType)}`,
319319
);
320320
switch (assetType) {
321-
case TokenType.ERC20:
322-
case TokenType.NONSTANDARD_FUNGIBLE:
323-
case TokenType.ERC721:
324-
case TokenType.NONSTANDARD_NONFUNGIBLE:
321+
case TokenType.FUNGIBLE:
322+
case TokenType.NONFUNGIBLE:
325323
if (!this.wrapperContractAddress) {
326324
throw new ApproveAddressError(
327325
`${fnTag}, Wrapper Contract Address not available for approving address`,
@@ -518,10 +516,8 @@ export class BesuLeaf
518516
);
519517

520518
switch (asset.type) {
521-
case TokenType.ERC20:
522-
case TokenType.NONSTANDARD_FUNGIBLE:
523-
case TokenType.ERC721:
524-
case TokenType.NONSTANDARD_NONFUNGIBLE:
519+
case TokenType.FUNGIBLE:
520+
case TokenType.NONFUNGIBLE:
525521
if (!this.wrapperContractName || !this.wrapperContractAddress) {
526522
throw new WrapperContractError(
527523
`${fnTag}, Wrapper Contract not deployed`,
@@ -984,8 +980,7 @@ export class BesuLeaf
984980
this.log.info(token);
985981

986982
switch (Number(token.tokenType)) {
987-
case TokenType.ERC20:
988-
case TokenType.NONSTANDARD_FUNGIBLE:
983+
case TokenType.FUNGIBLE:
989984
return {
990985
contractName: token.contractName,
991986
id: token.tokenId,
@@ -996,8 +991,7 @@ export class BesuLeaf
996991
amount: Number(token.amount) as Amount,
997992
network: this.networkIdentification,
998993
} as EvmFungibleAsset;
999-
case TokenType.ERC721:
1000-
case TokenType.NONSTANDARD_NONFUNGIBLE:
994+
case TokenType.NONFUNGIBLE:
1001995
return {
1002996
contractName: token.contractName,
1003997
id: token.tokenId,

packages/cactus-plugin-satp-hermes/src/main/typescript/cross-chain-mechanisms/bridge/leafs/ethereum-leaf.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,8 @@ export class EthereumLeaf
303303
`${fnTag}, Getting Approve Address for asset type: ${getEnumKeyByValue(TokenType, assetType)}`,
304304
);
305305
switch (assetType) {
306-
case TokenType.ERC20:
307-
case TokenType.NONSTANDARD_FUNGIBLE:
308-
case TokenType.ERC721:
309-
case TokenType.NONSTANDARD_NONFUNGIBLE:
306+
case TokenType.FUNGIBLE:
307+
case TokenType.NONFUNGIBLE:
310308
if (!this.wrapperContractAddress) {
311309
throw new ApproveAddressError(
312310
`${fnTag}, Wrapper Contract Address not available for approving address`,
@@ -503,10 +501,8 @@ export class EthereumLeaf
503501
);
504502

505503
switch (asset.type) {
506-
case TokenType.ERC20:
507-
case TokenType.ERC721:
508-
case TokenType.NONSTANDARD_FUNGIBLE:
509-
case TokenType.NONSTANDARD_NONFUNGIBLE:
504+
case TokenType.FUNGIBLE:
505+
case TokenType.NONFUNGIBLE:
510506
if (!this.wrapperContractName || !this.wrapperContractAddress) {
511507
throw new WrapperContractError(
512508
`${fnTag}, Wrapper Contract not deployed`,
@@ -1015,8 +1011,7 @@ export class EthereumLeaf
10151011
const token = response.callOutput as TokenResponse;
10161012

10171013
switch (Number(token.tokenType)) {
1018-
case TokenType.ERC20:
1019-
case TokenType.NONSTANDARD_FUNGIBLE:
1014+
case TokenType.FUNGIBLE:
10201015
this.log.debug("Returning Fungible Asset");
10211016
return {
10221017
contractName: token.contractName,
@@ -1028,8 +1023,7 @@ export class EthereumLeaf
10281023
amount: Number(token.amount) as Amount,
10291024
network: this.networkIdentification,
10301025
} as EvmFungibleAsset;
1031-
case TokenType.ERC721:
1032-
case TokenType.NONSTANDARD_NONFUNGIBLE:
1026+
case TokenType.NONFUNGIBLE:
10331027
this.log.debug("Returning Non Fungible Asset");
10341028
return {
10351029
contractName: token.contractName,

0 commit comments

Comments
 (0)