Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Token Transfer Processor - Derive classic events from operation and operation results #5609

Merged
merged 87 commits into from
Mar 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
291c0b6
Initial boiler plate commit for token transfer processor
karthikiyer56 Feb 19, 2025
b27d886
Add support for feeEvent
karthikiyer56 Feb 19, 2025
f76543a
Add support for createAccount and accountMerge
karthikiyer56 Feb 19, 2025
b97f95c
Add support for simple payment
karthikiyer56 Feb 20, 2025
571679c
Add unit tests for createAccount, mergeAccount, simple Payment
karthikiyer56 Feb 20, 2025
eb92532
refactor unit tests
karthikiyer56 Feb 21, 2025
5aebc69
Add logic for ManageBuyOffer, ManageSellOffer, CreatePassiveSellOffer…
karthikiyer56 Feb 21, 2025
00cead5
Add comments to explain sellerId in manageBuy/Sell operations
karthikiyer56 Feb 21, 2025
a858f64
Remove the incorreectly named FeeAccount receiver function from trans…
karthikiyer56 Feb 21, 2025
30472ff
Update the way we generate the fee event
karthikiyer56 Feb 21, 2025
8e7f358
rework code and add fixtures for all manageOffer operations and scena…
karthikiyer56 Feb 22, 2025
3e731c5
Make the assertion on the equality of proto expected vs actual events…
karthikiyer56 Feb 22, 2025
e52beb3
rework some test code
karthikiyer56 Feb 22, 2025
088ca7e
rework some anonymous functions in test cases
karthikiyer56 Feb 22, 2025
d6969b2
Add unit test for feeEvent
karthikiyer56 Feb 22, 2025
816e550
Unit test cleanup
karthikiyer56 Feb 23, 2025
ab52fd5
Make mintOrBurnOrTransferEvent function take an address wrapper inste…
karthikiyer56 Feb 25, 2025
0d22648
Add code for path payment and liquidity pool operations
karthikiyer56 Feb 26, 2025
bcb7c8d
Refactor some code and unit tests
karthikiyer56 Feb 26, 2025
7c35bd9
add code for createClaimableBalance
karthikiyer56 Feb 26, 2025
e4d2df9
Add support for claim claimable balance
karthikiyer56 Feb 26, 2025
c4306bd
Add support for clawback and clawback claimable balance operation
karthikiyer56 Feb 26, 2025
eb9aea1
Add unit tests for liquidity pool deposit and withdraw operations
karthikiyer56 Feb 26, 2025
091a588
Rework test fixtures
karthikiyer56 Feb 27, 2025
199fb13
Partially done path payment unit tests
karthikiyer56 Feb 27, 2025
ca558a4
Complete tests for path payment
karthikiyer56 Feb 27, 2025
205745a
fix test name
karthikiyer56 Feb 27, 2025
3f21336
return false
karthikiyer56 Feb 27, 2025
e5d6cd1
Add unit tests for clawback event. also refactor code
karthikiyer56 Feb 27, 2025
895c416
Add unit test for clawback claimable balance
karthikiyer56 Feb 27, 2025
9dbe785
Add test for claim claimable balance operation
karthikiyer56 Feb 27, 2025
ce666c4
rework code for finding liquidity pool details and claimable balance …
karthikiyer56 Feb 28, 2025
ecab46d
logic for allowTrust and setTrustlineFlags operations. These areeasil…
karthikiyer56 Mar 1, 2025
5313f59
Ignore the changes in this file for now. this is just a sample test c…
karthikiyer56 Mar 1, 2025
aa13ae9
undo changes to xdr/claimable_balance.go
karthikiyer56 Mar 1, 2025
0f87a2b
Fix bug in the way comparision was happening to find out which LP cre…
karthikiyer56 Mar 1, 2025
551eea5
More working changes to integration test. Made the setTrustline flags…
karthikiyer56 Mar 1, 2025
f3126a8
ensure that the LP delta is always positive
karthikiyer56 Mar 1, 2025
77304e9
add one more test for burn event from trustline revocation
karthikiyer56 Mar 1, 2025
6a6e9af
sample test cases for revoke trustline case and some code cleanup
karthikiyer56 Mar 3, 2025
a5a2583
working test for account
karthikiyer56 Mar 3, 2025
f80473a
pull out the integration test into its own file
karthikiyer56 Mar 3, 2025
7f5c233
Add extensive unit tests for revoke trustline case. Rework code to ad…
karthikiyer56 Mar 4, 2025
a4a9e24
Rename function to indicate that the events are derived from operatio…
karthikiyer56 Mar 4, 2025
d444f9d
correct the comments
karthikiyer56 Mar 4, 2025
d80df72
ensure that CB entries show up in the changes for claim Cb and clawba…
karthikiyer56 Mar 4, 2025
98be669
Rework integration tests
karthikiyer56 Mar 6, 2025
9a8ffd0
Make the integration test work
karthikiyer56 Mar 13, 2025
8ee667d
Completely redo the way we have been doing addresses so far
karthikiyer56 Mar 13, 2025
a70291f
Fix the way protoAsset is generated. Specifically trim the extra null…
karthikiyer56 Mar 14, 2025
d8c8243
Merge remote-tracking branch 'origin/master' into karthik/ttp-classic…
karthikiyer56 Mar 14, 2025
96b4364
Remove the CbId generation from LpId from support/converts into the t…
karthikiyer56 Mar 14, 2025
5a2cec6
Refactor the code for generation of CbIds from LP revocation to be mo…
karthikiyer56 Mar 14, 2025
c87c0ba
Remove unused code
karthikiyer56 Mar 14, 2025
756900b
Equals function for asset check
karthikiyer56 Mar 14, 2025
365c859
Check for return from feeCharged
karthikiyer56 Mar 14, 2025
19a1a09
Add comments
karthikiyer56 Mar 15, 2025
8d9bc73
Add support for verification
karthikiyer56 Mar 16, 2025
32040a5
Add sample example for using ttp
karthikiyer56 Mar 16, 2025
a16bf55
Add error check in mintOrBurnOrTransferEvent function
karthikiyer56 Mar 16, 2025
b9cf9c3
Updates to verify_events code
karthikiyer56 Mar 16, 2025
25d4a8f
go mod tidy
karthikiyer56 Mar 16, 2025
d26028c
Redo address proto again
karthikiyer56 Mar 16, 2025
154c3db
Make updates to calculate real amount
karthikiyer56 Mar 16, 2025
fb6562f
go mod tidy
karthikiyer56 Mar 16, 2025
ecbd075
fix verify
karthikiyer56 Mar 16, 2025
b565b80
fix example to print to file
karthikiyer56 Mar 16, 2025
2f12fe0
staticcheck
karthikiyer56 Mar 16, 2025
af7c27d
Add comments in address.proto
karthikiyer56 Mar 16, 2025
a978396
Refactor verify_events to make it simpler and address code review com…
karthikiyer56 Mar 16, 2025
83aa2d6
Add transaction index to event meta
karthikiyer56 Mar 16, 2025
e50dfee
Make ttp to be a structure and make em receiver functions. Also refac…
karthikiyer56 Mar 17, 2025
0e69632
remove code
karthikiyer56 Mar 17, 2025
6da06f1
Major rework of code. Made Addresses as strings and included contract…
karthikiyer56 Mar 18, 2025
b06f164
rename processor name
karthikiyer56 Mar 18, 2025
2e759c0
Address code review comments and rename functions to be more appropriate
karthikiyer56 Mar 18, 2025
5c18ce3
add code for reconciliation. Pending unit tests
karthikiyer56 Mar 18, 2025
09121e3
Fix check for protocol version
karthikiyer56 Mar 18, 2025
1b0727b
Refactor reconciliaton logic to generate only one event and re-order …
karthikiyer56 Mar 18, 2025
a4e64ca
Add unit tests for xlm reconciliation logic
karthikiyer56 Mar 20, 2025
1e39fd4
Add logic for inflation operation
karthikiyer56 Mar 21, 2025
41c999a
Remove printF
karthikiyer56 Mar 21, 2025
76055e0
Rework the verification logic to throw an error instead of a boolean …
karthikiyer56 Mar 21, 2025
e13f624
remove unsued code
karthikiyer56 Mar 21, 2025
2dbe812
Merge remote-tracking branch 'origin/master' into karthik/ttp-classic…
karthikiyer56 Mar 21, 2025
1e129dd
Move asset into each of mint/burn/transfer events
karthikiyer56 Mar 21, 2025
9207666
Fix numbering of oneOf in event proto
karthikiyer56 Mar 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions amount/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ func ParseInt64(v string) (int64, error) {
return i, nil
}

// MustParseInt64Raw simply converts an string into a 64-bit signed integer
func MustParseInt64Raw(v string) int64 {
i, err := strconv.ParseInt(v, 10, 64)
if err != nil {
panic(err)
}
return i
}

// IntStringToAmount converts string integer value and converts it to stellar
// "amount". In other words, it divides the given string integer value by 10^7
// and returns the string representation of that number.
Expand Down Expand Up @@ -139,3 +148,17 @@ func StringFromInt64(v int64) string {
r.Quo(r, bigOne)
return r.FloatString(7)
}

// No conversion. Simply convert int64 to string. Useful to have this in one place, should the underlying implementation change
func String64Raw(v xdr.Int64) string {
return strconv.FormatInt(int64(v), 10)
}

func String128Raw(v xdr.Int128Parts) string {
// the upper half of the i128 always indicates its sign regardless of its
// value, just like a native signed type
val := big.NewInt(int64(v.Hi))
val.Lsh(val, 64).Add(val, new(big.Int).SetUint64(uint64(v.Lo)))

return val.String()
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ require (
github.com/gavv/monotime v0.0.0-20161010190848-47d58efa6955 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/go-cmp v0.7.0
github.com/google/go-querystring v0.0.0-20160401233042-9235644dd9e5 // indirect
github.com/googleapis/gax-go/v2 v2.12.4 // indirect
github.com/hashicorp/golang-lru v1.0.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/go-querystring v0.0.0-20160401233042-9235644dd9e5 h1:oERTZ1buOUYlpmKaqlO5fYmz8cZ1rYu5DieJzF4ZVmU=
github.com/google/go-querystring v0.0.0-20160401233042-9235644dd9e5/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/gopacket v1.1.20-0.20210429153827-3eaba0894325/go.mod h1:riddUzxTSBpJXk3qBHtYr4qOhFhT6k/1c0E3qkQjQpA=
Expand Down
206 changes: 0 additions & 206 deletions ingest/address/address.pb.go

This file was deleted.

53 changes: 49 additions & 4 deletions ingest/asset/asset.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,63 @@
package asset

import (
"github.com/stellar/go/xdr"
"strings"
)

// NewNativeAsset creates an Asset representing the native token (XLM).
func NewNativeAsset() *Asset {
return &Asset{AssetType: &Asset_Native{Native: true}}
}

// NewIssuedAsset creates an Asset with an asset code and issuer.
func NewIssuedAsset(assetCode, issuer string) *Asset {
func NewProtoAsset(asset xdr.Asset) *Asset {
if asset.IsNative() {
return NewNativeAsset()
}
return &Asset{
AssetType: &Asset_IssuedAsset{
IssuedAsset: &IssuedAsset{
AssetCode: assetCode,
Issuer: issuer,
// Need to trim the extra null characters from showing in the code when saving to assetCode
AssetCode: strings.TrimRight(asset.GetCode(), "\x00"),
Issuer: asset.GetIssuer(),
},
},
}
}

func (a *Asset) ToXdrAsset() xdr.Asset {
if a == nil {
panic("nil asset")
}
switch a := a.AssetType.(type) {
case *Asset_Native:
return xdr.MustNewNativeAsset()
case *Asset_IssuedAsset:
return xdr.MustNewCreditAsset(a.IssuedAsset.AssetCode, a.IssuedAsset.Issuer)
}
panic("unknown asset type")
}

func (a *Asset) Equals(other *Asset) bool {
// If both assets are the same type (native or issued asset)
if a.AssetType == nil || other.AssetType == nil {
return false
}

switch a := a.AssetType.(type) {
case *Asset_Native:
if b, ok := other.AssetType.(*Asset_Native); ok {
// Both assets are native; compare the native boolean value.
// Ideally i could simply be returning true here, but it is more idiomatic to check for the flag equality
return a.Native == b.Native
}
case *Asset_IssuedAsset:
if b, ok := other.AssetType.(*Asset_IssuedAsset); ok {
// Both assets are issued assets; compare their asset_code and issuer
return a.IssuedAsset.AssetCode == b.IssuedAsset.AssetCode &&
a.IssuedAsset.Issuer == b.IssuedAsset.Issuer
}
}

return false
}
34 changes: 21 additions & 13 deletions ingest/asset/asset_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package asset

import (
"github.com/stellar/go/xdr"
"github.com/stretchr/testify/assert"
"google.golang.org/protobuf/proto"
"testing"
)

var (
assetCode = "USDC"
issuer = "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN"
usdcAsset = xdr.MustNewCreditAsset(assetCode, issuer)
)

func TestNewNativeAsset(t *testing.T) {
nativeAsset := NewNativeAsset()

Expand All @@ -15,25 +22,26 @@ func TestNewNativeAsset(t *testing.T) {
assert.True(t, nativeAsset.GetNative(), "Native asset should have Native set to true")
}

func TestNewIssuedAsset(t *testing.T) {
assetCode := "USDC"
issuer := "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN"

issuedAsset := NewIssuedAsset(assetCode, issuer)
func TestNewProtoAsset(t *testing.T) {

assert.NotNil(t, issuedAsset, "Issued asset should not be nil")
assert.IsType(t, &Asset{}, issuedAsset, "Issued asset should be of type *Asset")
assert.IsType(t, &Asset_IssuedAsset{}, issuedAsset.AssetType, "AssetType should be *Asset_IssuedAsset")
usdcProtoAsset := NewProtoAsset(usdcAsset)

assert.NotNil(t, usdcProtoAsset, "asset should not be nil")
assert.IsType(t, &Asset{}, usdcProtoAsset, "asset should be of type *Asset")
assert.IsType(t, &Asset_IssuedAsset{}, usdcProtoAsset.AssetType, "AssetType should be *Asset_IssuedAsset")
// Check issued asset fields
assert.Equal(t, assetCode, issuedAsset.GetIssuedAsset().AssetCode, "Asset code should match")
assert.Equal(t, issuer, issuedAsset.GetIssuedAsset().Issuer, "Issuer should match")
assert.Equal(t, assetCode, usdcProtoAsset.GetIssuedAsset().AssetCode, "Asset code should match")
assert.Equal(t, issuer, usdcProtoAsset.GetIssuedAsset().Issuer, "Issuer should match")

xlmProtoAsset := NewProtoAsset(xdr.MustNewNativeAsset())
assert.NotNil(t, xlmProtoAsset, "asset should not be nil")
assert.IsType(t, &Asset{}, xlmProtoAsset, "asset should be of type *Asset")
assert.IsType(t, &Asset_Native{}, xlmProtoAsset.AssetType, "AssetType should be *Asset_Native")
assert.True(t, xlmProtoAsset.GetNative(), "Native asset should have Native set to true")
}

func TestAssetSerialization(t *testing.T) {
assetCode := "USDC"
issuer := "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN"
original := NewIssuedAsset(assetCode, issuer)
original := NewProtoAsset(usdcAsset)

serializedAsset, err := proto.Marshal(original)
assert.NoError(t, err, "Failed to marshal asset")
Expand Down
Loading
Loading