Skip to content

Commit 74fb5c7

Browse files
committed
add transform_to xml attribute
1 parent e5de090 commit 74fb5c7

File tree

5 files changed

+54
-12
lines changed

5 files changed

+54
-12
lines changed

abi/inspect_test.go

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,40 @@ func Test_contractInspector_InspectContract(t *testing.T) {
231231
WalletVesting,
232232
},
233233
},
234+
{
235+
name: "stonfi v2",
236+
account: "0:8649cad97b5c5bc96a960ef748ea6ccff8601c01616fe995ee6893ae4aa7a6c6",
237+
code: "b5ee9c7201010101002300084202a9338ecd624ca15d37e4a8d9bf677ddc9b84f0e98f05f2fb84c7afe332a281b4",
238+
data: "b5ee9c720101040100d7000149301bc3bb69e12b82156e4fb859fa31b951d2d995caa1e5f97c6631f5c520727f90002800150102c980125c28235ca8d125e676591513d520721b1fe99f7722f4c87723ce7ee0dfb73a300248b589f5f63b6f4039388ef6c31529dbb9787d195ce86bd105e15fe8f88fa47e00491060c0d367f56688dbdc7b109c6f8ddce6415b769330e97afd7710259f7d90400203084202c00836440d084e44fb94316132ac5a21417ef4f429ee09b5560b5678b334c3e8084202c95a2ed22ab516f77f9d4898dc4578e72f18a2448e8f6832334b0b4bf501bc79",
239+
hasLibrary: true,
240+
want: []ContractInterface{
241+
JettonMaster, StonfiPoolV2,
242+
},
243+
},
244+
{
245+
name: "stonfi stableswap",
246+
account: "0:52518e14586245029b342b01d8e2da4e1aacd4e350d9872ad3f0ebb20165ad9d",
247+
code: "b5ee9c72010101010023000842023c882eb9ede6be2459b2d2e469680af9f8e48ab16ec0726f0d07b0e5686be718",
248+
data: "b5ee9c720101040100f800018c301d59a3a8c17b01e8a10c6375b03be1eff87dda2b29c23d22bd483fe400000000000000000000000000000000000000000000000000000000000000000000000001000000640102c9800a46afff33251480ab6dab42434437a3fe464a9dbe5f525f9642ab4d2ef6eac89001466aa0b3a89e00a1dd7ccf9e8a225962fc32536722c3351274978f9861d9e8ee0029ee48e6b746e6db45008d68a4de088ac64064b6fcbb98f3a46f9583bb409e2a400203084202c00836440d084e44fb94316132ac5a21417ef4f429ee09b5560b5678b334c3e8084202c3b3ef256ddc9bd4e35db3e3863c048b18465c9f403f1d5a2b559395e11cfee6",
249+
hasLibrary: true,
250+
want: []ContractInterface{
251+
JettonMaster, StonfiPoolV2,
252+
},
253+
},
254+
{
255+
name: "stonfi weighted stableswap",
256+
account: "0:05ea635b2a168cadfca174d72b12744a5b57d70378e6912e8a33b6b39bd3ee9d",
257+
code: "b5ee9c72010101010023000842029e5038ab735973d5450fae1a14e7707b332dcd8e744f5dbb3b6a0d994d400c59",
258+
data: "b5ee9c720102050100012700023f2eb83040934b00e0b0fd70b83205d77620ca9a0ce7c76e20601218e800080003010200a30000000000000002b5e3af16b18800000000000000000000111c7ef7a00e8000000000000000000003782dace9d900008000000000000000000000000000000000000000000000000000000000000000001002c98000cafb7e1aeb694b6c81c13012e24c43b95cf99bd3c84fb900ee31e9b144096fb0001aa0db2d3fc8f1224da5badf8994c74a05048d50963e42b0d8d71fe2b849569a0003770d21f96c46cd550df24da7d76c88d13cbed0cc691d4e91c69706ae47137bc00304084202c00836440d084e44fb94316132ac5a21417ef4f429ee09b5560b5678b334c3e8084202e398c874e2bb0017b7447c3cbc534ca368d96533c1b120101d4c8c097d12c6e3",
259+
hasLibrary: true,
260+
want: []ContractInterface{
261+
JettonMaster, StonfiPoolV2,
262+
},
263+
},
264+
}
265+
cli, err := liteapi.NewClient(liteapi.Mainnet())
266+
if err != nil {
267+
t.Fatalf("failed to create liteapi client: %v", err)
234268
}
235269
for _, tt := range tests {
236270
t.Run(tt.name, func(t *testing.T) {
@@ -243,10 +277,6 @@ func Test_contractInspector_InspectContract(t *testing.T) {
243277
if tt.emulatorConfig == nil {
244278
emulatorConfig = mainnetConfig[0]
245279
}
246-
cli, err := liteapi.NewClient(liteapi.Testnet())
247-
if err != nil {
248-
t.Fatalf("failed to create liteapi client: %v", err)
249-
}
250280
ci := NewContractInspector(InspectWithLibraryResolver(cli))
251281
emulator, err := tvm.NewEmulator(codeCell[0], dataCell[0], emulatorConfig, tvm.WithLazyC7Optimization(), tvm.WithLibraryResolver(cli), tvm.WithIgnoreLibraryCells(true))
252282
if err != nil {

abi/interfaces.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,13 +1241,13 @@ var contractInterfacesOrder = []InterfaceDescription{
12411241
},
12421242
},
12431243
{
1244-
Name: StonfiPoolV2Stableswap,
1244+
Name: StonfiPoolV2,
12451245
Results: []string{
12461246
"GetPoolData_StonfiV2StableswapResult",
12471247
},
12481248
},
12491249
{
1250-
Name: StonfiPoolV2WeightedStableswap,
1250+
Name: StonfiPoolV2,
12511251
Results: []string{
12521252
"GetPoolData_StonfiV2WeightedStableswapResult",
12531253
},

abi/parser/generator.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,11 +604,13 @@ func (g *Generator) RenderInvocationOrderList(simpleMethods []string) (string, e
604604
InterfaceOrder []interfaceDescription
605605
KnownHashes map[string]interfaceDescription
606606
Inheritance map[string]string
607+
TransformTo map[string]string
607608
IntMsgs, ExtInMsgs, ExtOutMsgs map[string][]string
608609
}{
609610
Interfaces: map[string]string{},
610611
KnownHashes: map[string]interfaceDescription{},
611612
Inheritance: map[string]string{},
613+
TransformTo: map[string]string{},
612614
IntMsgs: map[string][]string{},
613615
ExtInMsgs: map[string][]string{},
614616
ExtOutMsgs: map[string][]string{},
@@ -633,6 +635,7 @@ func (g *Generator) RenderInvocationOrderList(simpleMethods []string) (string, e
633635
descriptions[invokeFnName] = desc
634636
}
635637

638+
transformTo := map[string]string{}
636639
inheritance := map[string]string{} // interface name -> parent interface
637640
methodsByIface := map[string]map[string]string{} // interface name -> method name -> result name
638641

@@ -642,6 +645,9 @@ func (g *Generator) RenderInvocationOrderList(simpleMethods []string) (string, e
642645
if iface.Inherits != "" {
643646
inheritance[ifaceName] = utils.ToCamelCase(iface.Inherits)
644647
}
648+
if iface.TransformTo != "" {
649+
transformTo[ifaceName] = utils.ToCamelCase(iface.TransformTo)
650+
}
645651
for _, method := range iface.Methods {
646652
if !slices.Contains(simpleMethods, method.Name) {
647653
continue
@@ -657,6 +663,7 @@ func (g *Generator) RenderInvocationOrderList(simpleMethods []string) (string, e
657663
methodsByIface[ifaceName][methodName] = resultName
658664
}
659665
}
666+
context.TransformTo = transformTo
660667
context.Inheritance = inheritance
661668

662669
for _, iface := range g.abi.Interfaces {
@@ -669,8 +676,12 @@ func (g *Generator) RenderInvocationOrderList(simpleMethods []string) (string, e
669676
ifaceMethods[methodName] = resultName
670677
}
671678
}
679+
ifaceDescrName := ifaceName
680+
if transformToName, ok := context.TransformTo[ifaceName]; ok {
681+
ifaceDescrName = transformToName
682+
}
672683
description := interfaceDescription{
673-
Name: ifaceName,
684+
Name: ifaceDescrName,
674685
}
675686
methodNames := maps.Keys(ifaceMethods)
676687
sort.Strings(methodNames)

abi/parser/parser.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ type Interface struct {
3131
Internals []InterfaceMessage `xml:"internal"`
3232
Externals []InterfaceMessage `xml:"ext_out"`
3333
} `xml:"msg_out"`
34-
CodeHashes []string `xml:"code_hash"`
35-
Inherits string `xml:"inherits,attr"`
36-
Errors []struct {
34+
CodeHashes []string `xml:"code_hash"`
35+
Inherits string `xml:"inherits,attr"`
36+
TransformTo string `xml:"transform_to,attr"`
37+
Errors []struct {
3738
Text string `xml:",chardata"`
3839
Code int `xml:"code,attr"`
3940
} `xml:"error"`

abi/schemas/ston-fi.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<internal name="stonfi_cb_add_liquidity_v2"/>
1818
</msg_in>
1919
</interface>
20-
<interface name="stonfi_pool_v2_stableswap">
20+
<interface name="stonfi_pool_v2_stableswap" transform_to="stonfi_pool_v2">
2121
<get_method name="get_pool_data" version="stonfi_v2_stableswap"/>
2222
<get_method name="get_lp_account_address" version="stonfi"/>
2323
<msg_in>
@@ -28,7 +28,7 @@
2828
<internal name="stonfi_cb_add_liquidity_v2"/>
2929
</msg_in>
3030
</interface>
31-
<interface name="stonfi_pool_v2_weighted_stableswap">
31+
<interface name="stonfi_pool_v2_weighted_stableswap" transform_to="stonfi_pool_v2">
3232
<get_method name="get_pool_data" version="stonfi_v2_weighted_stableswap"/>
3333
<get_method name="get_lp_account_address" version="stonfi"/>
3434
<msg_in>

0 commit comments

Comments
 (0)