Skip to content

Commit

Permalink
Merge pull request #65 from dojoengine/erc-tokens
Browse files Browse the repository at this point in the history
feat: erc tokens integration
  • Loading branch information
Larkooo authored Nov 20, 2024
2 parents f015fbe + c64a1fb commit dc0eee6
Show file tree
Hide file tree
Showing 9 changed files with 1,279 additions and 752 deletions.
1,628 changes: 903 additions & 725 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ version = "1.0.0-rc.2"
crate-type = ["cdylib", "rlib", "staticlib"]

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
dojo-world = { git = "https://github.com/dojoengine/dojo", tag = "v1.0.0-rc.0", features = [
dojo-world = { git = "https://github.com/dojoengine/dojo", rev = "d00547", features = [
"metadata",
] }

[dependencies]
dojo-types = { git = "https://github.com/dojoengine/dojo", tag = "v1.0.0-rc.0" }
torii-client = { git = "https://github.com/dojoengine/dojo", tag = "v1.0.0-rc.0" }
dojo-types = { git = "https://github.com/dojoengine/dojo", rev = "d00547" }
torii-client = { git = "https://github.com/dojoengine/dojo", rev = "d00547" }
torii-grpc = { git = "https://github.com/dojoengine/dojo", features = [
"client",
], tag = "v1.0.0-rc.0" }
torii-relay = { git = "https://github.com/dojoengine/dojo", tag = "v1.0.0-rc.0" }
], rev = "d00547" }
torii-relay = { git = "https://github.com/dojoengine/dojo", rev = "d00547" }

starknet = "0.12.0"
starknet-crypto = "0.7.2"
Expand All @@ -38,7 +38,7 @@ cainome = { git = "https://github.com/cartridge-gg/cainome", tag = "v0.3.2" }

# WASM
[target.'cfg(target_arch = "wasm32")'.dependencies]
dojo-world = { git = "https://github.com/dojoengine/dojo", tag = "v1.0.0-rc.0", features = [
dojo-world = { git = "https://github.com/dojoengine/dojo", rev = "d00547", features = [
] }
serde-wasm-bindgen = "0.6.3"
wasm-bindgen-futures = "0.4.39"
Expand Down
80 changes: 75 additions & 5 deletions dojo.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ typedef enum Primitive_Tag {
U32,
U64,
U128,
#if !defined(TARGET_POINTER_WIDTH_32)
U256,
#endif
#if defined(TARGET_POINTER_WIDTH_32)
U256,
#endif
Expand Down Expand Up @@ -139,11 +137,9 @@ typedef struct Primitive {
struct {
uint8_t u128[16];
};
#if !defined(TARGET_POINTER_WIDTH_32)
struct {
uint64_t u256[4];
};
#endif
#if defined(TARGET_POINTER_WIDTH_32)
struct {
uint32_t u256[8];
Expand Down Expand Up @@ -463,6 +459,69 @@ typedef struct Event {
struct FieldElement transaction_hash;
} Event;

typedef struct Token {
struct FieldElement contract_address;
const char *name;
const char *symbol;
uint8_t decimals;
const char *metadata;
} Token;

typedef struct CArrayToken {
struct Token *data;
uintptr_t data_len;
} CArrayToken;

typedef enum ResultCArrayToken_Tag {
OkCArrayToken,
ErrCArrayToken,
} ResultCArrayToken_Tag;

typedef struct ResultCArrayToken {
ResultCArrayToken_Tag tag;
union {
struct {
struct CArrayToken ok;
};
struct {
struct Error err;
};
};
} ResultCArrayToken;

typedef struct TokenBalance {
uint64_t balance[4];
#if defined(TARGET_POINTER_WIDTH_32)
uint32_t balance[8]
#endif
;
struct FieldElement account_address;
struct FieldElement contract_address;
const char *token_id;
} TokenBalance;

typedef struct CArrayTokenBalance {
struct TokenBalance *data;
uintptr_t data_len;
} CArrayTokenBalance;

typedef enum ResultCArrayTokenBalance_Tag {
OkCArrayTokenBalance,
ErrCArrayTokenBalance,
} ResultCArrayTokenBalance_Tag;

typedef struct ResultCArrayTokenBalance {
ResultCArrayTokenBalance_Tag tag;
union {
struct {
struct CArrayTokenBalance ok;
};
struct {
struct Error err;
};
};
} ResultCArrayTokenBalance;

typedef struct IndexerUpdate {
int64_t head;
int64_t tps;
Expand Down Expand Up @@ -627,7 +686,8 @@ void client_set_logger(struct ToriiClient *client, void (*logger)(const char*));
struct ResultCArrayu8 client_publish_message(struct ToriiClient *client,
const char *message,
const struct FieldElement *signature_felts,
uintptr_t signature_felts_len);
uintptr_t signature_felts_len,
bool is_session_signature);

struct ResultCArrayEntity client_entities(struct ToriiClient *client, const struct Query *query);

Expand Down Expand Up @@ -666,6 +726,16 @@ struct ResultSubscription client_on_starknet_event(struct ToriiClient *client,
uintptr_t clauses_len,
void (*callback)(struct Event));

struct ResultCArrayToken client_tokens(struct ToriiClient *client,
const struct FieldElement *contract_addresses,
uintptr_t contract_addresses_len);

struct ResultCArrayTokenBalance client_token_balances(struct ToriiClient *client,
const struct FieldElement *account_addresses,
uintptr_t account_addresses_len,
const struct FieldElement *contract_addresses,
uintptr_t contract_addresses_len);

struct ResultSubscription on_indexer_update(struct ToriiClient *client,
const struct FieldElement *contract_address,
void (*callback)(struct IndexerUpdate));
Expand Down
40 changes: 31 additions & 9 deletions dojo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ struct Primitive {
U32,
U64,
U128,
#if !defined(TARGET_POINTER_WIDTH_32)
U256,
#endif
#if defined(TARGET_POINTER_WIDTH_32)
U256,
#endif
Expand Down Expand Up @@ -161,11 +159,9 @@ struct Primitive {
uint8_t _0[16];
};

#if !defined(TARGET_POINTER_WIDTH_32)
struct U256_Body {
uint64_t _0[4];
};
#endif

#if defined(TARGET_POINTER_WIDTH_32)
struct U256_Body {
Expand Down Expand Up @@ -205,9 +201,7 @@ struct Primitive {
U32_Body u32;
U64_Body u64;
U128_Body u128;
#if !defined(TARGET_POINTER_WIDTH_32)
U256_Body u256;
#endif
#if defined(TARGET_POINTER_WIDTH_32)
U256_Body u256;
#endif
Expand Down Expand Up @@ -332,7 +326,6 @@ struct Primitive {
return tag == Tag::U128;
}

#if !defined(TARGET_POINTER_WIDTH_32)
static Primitive U256(const uint64_t (&_0)[4]) {
Primitive result;
for (int i = 0; i < 4; i++) {
Expand All @@ -345,7 +338,6 @@ struct Primitive {
bool IsU256() const {
return tag == Tag::U256;
}
#endif

#if defined(TARGET_POINTER_WIDTH_32)
static Primitive U256(const uint32_t (&_0)[8]) {
Expand Down Expand Up @@ -793,6 +785,25 @@ struct Event {
FieldElement transaction_hash;
};

struct Token {
FieldElement contract_address;
const char *name;
const char *symbol;
uint8_t decimals;
const char *metadata;
};

struct TokenBalance {
uint64_t balance[4];
#if defined(TARGET_POINTER_WIDTH_32)
uint32_t balance[8]
#endif
;
FieldElement account_address;
FieldElement contract_address;
const char *token_id;
};

struct IndexerUpdate {
int64_t head;
int64_t tps;
Expand Down Expand Up @@ -886,7 +897,8 @@ void client_set_logger(ToriiClient *client, void (*logger)(const char*));
Result<CArray<uint8_t>> client_publish_message(ToriiClient *client,
const char *message,
const FieldElement *signature_felts,
uintptr_t signature_felts_len);
uintptr_t signature_felts_len,
bool is_session_signature);

Result<CArray<Entity>> client_entities(ToriiClient *client, const Query *query);

Expand Down Expand Up @@ -923,6 +935,16 @@ Result<Subscription*> client_on_starknet_event(ToriiClient *client,
uintptr_t clauses_len,
void (*callback)(Event));

Result<CArray<Token>> client_tokens(ToriiClient *client,
const FieldElement *contract_addresses,
uintptr_t contract_addresses_len);

Result<CArray<TokenBalance>> client_token_balances(ToriiClient *client,
const FieldElement *account_addresses,
uintptr_t account_addresses_len,
const FieldElement *contract_addresses,
uintptr_t contract_addresses_len);

Result<Subscription*> on_indexer_update(ToriiClient *client,
const FieldElement *contract_address,
void (*callback)(IndexerUpdate));
Expand Down
53 changes: 52 additions & 1 deletion dojo.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,46 @@ cdef extern from *:
CArrayFieldElement data;
FieldElement transaction_hash;

cdef struct Token:
FieldElement contract_address;
const char *name;
const char *symbol;
uint8_t decimals;
const char *metadata;

cdef struct CArrayToken:
Token *data;
uintptr_t data_len;

cdef enum ResultCArrayToken_Tag:
OkCArrayToken,
ErrCArrayToken,

cdef struct ResultCArrayToken:
ResultCArrayToken_Tag tag;
CArrayToken ok;
Error err;

cdef struct TokenBalance:
uint64_t balance[4];
uint32_t balance[8];
FieldElement account_address;
FieldElement contract_address;
const char *token_id;

cdef struct CArrayTokenBalance:
TokenBalance *data;
uintptr_t data_len;

cdef enum ResultCArrayTokenBalance_Tag:
OkCArrayTokenBalance,
ErrCArrayTokenBalance,

cdef struct ResultCArrayTokenBalance:
ResultCArrayTokenBalance_Tag tag;
CArrayTokenBalance ok;
Error err;

cdef struct IndexerUpdate:
int64_t head;
int64_t tps;
Expand Down Expand Up @@ -393,7 +433,8 @@ cdef extern from *:
ResultCArrayu8 client_publish_message(ToriiClient *client,
const char *message,
const FieldElement *signature_felts,
uintptr_t signature_felts_len);
uintptr_t signature_felts_len,
bool is_session_signature);

ResultCArrayEntity client_entities(ToriiClient *client, const Query *query);

Expand Down Expand Up @@ -430,6 +471,16 @@ cdef extern from *:
uintptr_t clauses_len,
void (*callback)(Event));

ResultCArrayToken client_tokens(ToriiClient *client,
const FieldElement *contract_addresses,
uintptr_t contract_addresses_len);

ResultCArrayTokenBalance client_token_balances(ToriiClient *client,
const FieldElement *account_addresses,
uintptr_t account_addresses_len,
const FieldElement *contract_addresses,
uintptr_t contract_addresses_len);

ResultSubscription on_indexer_update(ToriiClient *client,
const FieldElement *contract_address,
void (*callback)(IndexerUpdate));
Expand Down
Loading

0 comments on commit dc0eee6

Please sign in to comment.